12. StdProcess
Prev |  | Next

## 12. StdProcess

In Object I/O there are multiple interactive processes. Each process has its main window and works independently from the other processes.

Note: The interactive process isn't a thread. The multiple processes just denote multiple main windows.

The behaviour of the process is determined by document interface (see Section 4, “StdIOCommon” for definition of DocumentInterface type):

- SDI process can have just one window

- MDI process has one main window with multiple child windows

- NDI process can't have windows. It can work only with dialogs

The process is defined as type:

    data Process
            = forall ps . Process
                            DocumentInterface       -- The process document interface
                            ps                      -- The process private state
                            (ProcessInit ps)        -- The process initialisation
                            [ProcessAttribute ps]   -- The process attributes
    type    ProcessInit ps
            = GUI2Fun ps

    data    ProcessAttribute ps                  -- Default:
        = ProcessActivate   (GUI2Fun ps)        -- No action on activate
        | ProcessDeactivate (GUI2Fun ps)        -- No action on deactivate
        | ProcessClose      (GUI2Fun ps)        -- Process is closed
    --  Attributes for (M/S)DI process only:
        | ProcessOpenFiles  (ProcessOpenFilesFunction ps)    -- Request to open files
        | ProcessWindowPos  ItemPos              -- Platform dependent
        | ProcessWindowSize Size                 -- Platform dependent
        | ProcessWindowResize   (ProcessWindowResizeFunction ps) -- Platform dependent
        | ProcessToolbar    [ToolbarItem ps]         -- Process has no toolbar
     -- Attributes for MDI processes only:
        | ProcessNoWindowMenu                    -- Process has WindowMenu

    type    ProcessWindowResizeFunction ps
         =  Size                        -- Old ProcessWindow size
         -> Size                        -- New ProcessWindow size
         -> GUI2Fun ps

    type    ProcessOpenFilesFunction ps
         =  [String]                    -- The file names to open
         -> GUI2Fun ps

    data    ToolbarItem ps
        = ToolbarItem Bitmap (Maybe String) (ps -> GUI ps ps)
        | ToolbarSeparator

    class Processes pdef where
            startProcesses :: pdef -> IO ()
            openProcesses  :: pdef -> GUI ps ()

    instance Processes Process
    instance Processes pdef => Processes [pdef]

    startIO :: DocumentInterface -> ps -> ProcessInit ps -> [ProcessAttribute ps] -> IO ()

    closeProcess :: GUI2Fun ps

    getProcessWindowPos :: GUI ps Point2
    getProcessWindowSize :: GUI ps Size

Process attributes

`ProcessActivate`

  describes a callback function, which will be called each time the process is activated.

`ProcessDeactivate`

  describes a callback function, which will be called each time the process is deactivated.

`ProcessClose`

  describes a callback function, which will be called before the process is closed.

`ProcessOpenFiles`

  describes a callback function, which will be called when the user drags files from the Windows Explorer and drops them over the process window (for (M/S)DI processes only).

`ProcessWindowPos`

  defines the position in which the main process window will be created (for (M/S)DI processes only).

`ProcessWindowSize`

  defines the size of the main process window when it is created (for (M/S)DI processes only).

`ProcessWindowResize`

  describes the callback function which will be called when the user resizes the process window (for (M/S)DI processes only).

`ProcessToolbar`

  defines the process toolbar items (for (M/S)DI process only).

`ProcessNoWindowMenu`

  prevents the creation of a standard "Window" menu (for MDI processes only).

The processes can be created by `Processes` class. This allows the user to define his/her own process types instead of built-in types

`startIO`

  This is the standard way for a single processed applications to run.

      main = startIO SDI () init [ProcessClose closeProcess
              where
                      init :: GUI2Fun ps
                      init = ...

`closeProcess`

  closes the current process

`getProcessWindowPos`

  returns the system dependent position where the process window is created

`getProcessWindowSize`

  returns the system dependent size with which the process window will be created.

Prev |  | Next
11. StdBitmap | Home | 13. StdReceiver