ETHZ_Logo RAMSES_Logo_Right    RAMSES    RAMSES_Logo_Left Systems Ecology   

Example: LessSimple

Screen Dump


Source Code


MODULE LessSimple; (*A.Fischlin, Mai 86*)

  (**************************************************************)
  (*   Sample program module demonstrating the installation     *)
  (*   of menus, the window management, inclusive content       *)
  (*   restoration and some drawing within the window as        *)
  (*   supported by the "Dialog Machine"                        *)
  (**************************************************************)
  
                      
  FROM DMMenus IMPORT  Menu, Command, AccessStatus, Marking,
    InstallMenu, InstallCommand, InstallAliasChar, Separator,
    InstallSeparator, DisableCommand, EnableCommand, 
    ChangeCommandText;
                       
  FROM DMWindows IMPORT Window, WindowsDone, notExistingWindow,
    WindowKind, ScrollBars, CloseAttr, ZoomAttr, WFFixPoint, 
    WindowFrame, CreateWindow, SetRestoreProc, DummyRestoreProc,
    AutoRestoreProc, GetWindowFrame;

  FROM DMWindIO IMPORT SelectForOutput, Circle, Pattern;
                        
  FROM DMMaster IMPORT MouseHandlers, AddMouseHandler,
    AddSetupProc, RunDialogMachine;
    

  TYPE
    MachineStates = (myWindowDoesNotExist,
                     myWindowExistsButNoAutomaticUpdating,
                     myWindowExistsWithRestoreUpdating,
                     myWindowExistsWithAutoRestoreUpdating);


  VAR
    myMenu: Menu;
    makeWindow, drawCircle, ordUpdating, autoUpdating: Command;
    myWindow: Window; wf: WindowFrame;
    curDMState: MachineStates;


  PROCEDURE CircleRestoreProc(u: Window);
    VAR radius: INTEGER; filled: BOOLEAN; dummyPat: Pattern;
    PROCEDURE Minimum(x,y: CARDINAL): CARDINAL;
    BEGIN (*Minimum*)
      IF x < y THEN RETURN x ELSE RETURN y END
    END Minimum;
  BEGIN (*CircleRestoreProc*)
    GetWindowFrame(u,wf);
    radius:= Minimum(wf.h DIV 3,wf.w DIV 3);
    filled:= FALSE;
    Circle(wf.w DIV 2,wf.h DIV 2,radius,filled,dummyPat)
  END CircleRestoreProc;

  PROCEDURE DrawCircle;
  BEGIN
    SelectForOutput(myWindow);
    CircleRestoreProc(myWindow);
  END DrawCircle;



  CONST
    clRPStr = "Install your own restore procedure";
    auRPStr = "Install DM's automatic restoring mechanism (AutoRestoreProc)";
    rmClRPStr = "Remove your own restore procedure";
    rmAuRPStr = "Remove automatic restoring";

  PROCEDURE SetDMState(s: MachineStates);
  BEGIN
    CASE s OF
      myWindowDoesNotExist:
              myWindow:= notExistingWindow;
              EnableCommand(myMenu, makeWindow);
              DisableCommand(myMenu, drawCircle);
              DisableCommand(myMenu, ordUpdating);
              DisableCommand(myMenu, autoUpdating);
    | myWindowExistsButNoAutomaticUpdating:
              DisableCommand(myMenu, makeWindow);
              EnableCommand(myMenu, drawCircle);
              EnableCommand(myMenu, ordUpdating);
              EnableCommand(myMenu, autoUpdating);
              SetRestoreProc(myWindow,DummyRestoreProc);
              ChangeCommandText(myMenu,ordUpdating,clRPStr);
              ChangeCommandText(myMenu,autoUpdating,auRPStr);
    | myWindowExistsWithRestoreUpdating:
              DisableCommand(myMenu, makeWindow);
              DisableCommand(myMenu, drawCircle);
              EnableCommand(myMenu, ordUpdating);
              DisableCommand(myMenu, autoUpdating);
              SetRestoreProc(myWindow,CircleRestoreProc);
              ChangeCommandText(myMenu,ordUpdating,rmClRPStr);
              ChangeCommandText(myMenu,autoUpdating,rmAuRPStr);
    | myWindowExistsWithAutoRestoreUpdating:
              DisableCommand(myMenu, makeWindow);
              EnableCommand(myMenu, drawCircle);
              DisableCommand(myMenu, ordUpdating);
              EnableCommand(myMenu, autoUpdating);
              SetRestoreProc(myWindow,AutoRestoreProc);
              ChangeCommandText(myMenu,ordUpdating,rmClRPStr);
              ChangeCommandText(myMenu,autoUpdating,rmAuRPStr);
    END(*CASE*);
    curDMState:= s;
  END SetDMState;


  PROCEDURE MakeWindow;
  BEGIN
    wf.x:= 50; wf.y:= 50; wf.w:= 200; wf.h:= 200;
    CreateWindow(myWindow,
                 GrowOrShrinkOrDrag, WithoutScrollBars,
                 WithCloseBox, WithoutZoomBox, bottomLeft,
                 wf, "My Window", DummyRestoreProc);
    IF WindowsDone THEN
      SetDMState(myWindowExistsButNoAutomaticUpdating)
    END(*IF*);
  END MakeWindow;

  PROCEDURE EnableMenuIfWindowCloses(u: Window);
  BEGIN
    SetDMState(myWindowDoesNotExist);
  END EnableMenuIfWindowCloses;


  

  PROCEDURE ToggleUpdtInstallation;
  BEGIN
    IF curDMState = myWindowExistsButNoAutomaticUpdating THEN
      SetDMState(myWindowExistsWithRestoreUpdating);
    ELSIF curDMState = myWindowExistsWithRestoreUpdating THEN
      SetDMState(myWindowExistsButNoAutomaticUpdating);
    END(*IF*);
  END ToggleUpdtInstallation;
  
  PROCEDURE ToggleAutoUpdtInstallation;
  BEGIN
    IF curDMState = myWindowExistsButNoAutomaticUpdating THEN
      SetDMState(myWindowExistsWithAutoRestoreUpdating);
    ELSIF curDMState = myWindowExistsWithAutoRestoreUpdating THEN
      SetDMState(myWindowExistsButNoAutomaticUpdating);
    END(*IF*);
  END ToggleAutoUpdtInstallation;

  


  PROCEDURE SettingUp;
    (* Menus are now installed in the "Dialog Machine", since this 
    procedure will be called automatically after you have activated
    it by calling DMMaster.RunDialogMachine.  Any menu command texts
    etc. may now be changed the same way as during the ordinary 
    running of the "Dialog Machine" *)
  BEGIN
    SetDMState(myWindowDoesNotExist);
  END SettingUp;

  PROCEDURE DMInitialization;
    (* This procedure is called in order to install menus etc. into the
    "Dialog Machine" before it is actually activated by calling procedure
    DMMaster.RunDialogMachine *)
  BEGIN
    InstallMenu(myMenu,"Control",enabled);
    InstallCommand(myMenu, makeWindow,"Open Window", MakeWindow,
                   enabled, unchecked);
    InstallCommand(myMenu,drawCircle,"Draw Circle", DrawCircle,
                   disabled,unchecked);
    InstallAliasChar(myMenu, drawCircle,"D");
    InstallSeparator(myMenu,line);
    InstallCommand(myMenu,ordUpdating,clRPStr,
                   ToggleUpdtInstallation,disabled,unchecked);
    InstallCommand(myMenu,autoUpdating, auRPStr,
                   ToggleAutoUpdtInstallation,disabled,unchecked);
    AddSetupProc(SettingUp, 0);
    AddMouseHandler(CloseWindow,EnableMenuIfWindowCloses, 0);
  END DMInitialization;


BEGIN
  DMInitialization;
  RunDialogMachine
END LessSimple.

  RAMSES@env.ethz.ch Last modified 1/12/22 [Top of page]   

Modula-2 website ring
List all    |    <<  Prev    |    Next  >>    |    Join