home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / TransSkel 3.18 / Demos / Pascal Demos / DialogSkel / DialogSkel.p next >
Encoding:
Text File  |  1994-05-01  |  10.7 KB  |  312 lines  |  [TEXT/PJMM]

  1. { TransSkel DialogSkel application in Pascal }
  2.  
  3. { 11 Feb 94 Version 1.00, Paul DuBois }
  4.  
  5. program DialogSkel;
  6.  
  7.     uses
  8.         TransSkel;
  9.  
  10.     const
  11.  
  12.         normalHilite = 0;
  13.         dimHilite = 255;
  14.  
  15.         fileMenuID = skelAppleMenuID + 1;
  16.         editMenuID = fileMenuID + 1;
  17.  
  18.         mDlogRes = 1000;
  19.         aboutAlrtRes = 1001;
  20.         docWindRes = 1000;
  21.  
  22.         showDlog1 = 1;
  23.         showDlog2 = 2;
  24.         showDoc = 3;
  25.         closeWind = 4;
  26. { separator line }
  27.         quit = 6;
  28.  
  29.         undo = 1;
  30. { separator line }
  31.         cut = 3;
  32.         copy = 4;
  33.         paste = 5;
  34.         clear = 6;
  35.  
  36.         button1 = 1;
  37.         edit1 gnore := SkelDialog(dlog, @DlogFilter, @DlogSelect, @DlogClose, @DlogClobber);
  38.         DemoDialog := dlog;
  39.     end;
  40.  
  41.  
  42. {--------------------------------------------------------------------}
  43. { Document window setup and handler routines }
  44. {--------------------------------------------------------------------}
  45.  
  46.  
  47.     procedure DocUpdate (resized: Boolean);
  48.     begin
  49.     end;
  50.  
  51.  
  52.     procedure DocActivate (active: Boolean);
  53.     begin
  54.     end;
  55.  
  56.  
  57.     procedure DocClobber;
  58.     begin
  59.         HideWindow(docWind);
  60.         DisposeWindow(docWind);
  61.     end;
  62.  
  63.  
  64.     procedure DocWindow (h: Integer;
  65.                                     v: Integer);
  66.         var
  67.             ignore: Boolean;
  68.     begin
  69.         if (SkelQuery(skelQHasColorQD) <> 0) then
  70.             docWind := GetNewCWindow(docWindRes, nil, WindowPtr(-1))
  71.         else
  72.             docWind := GetNewWindow(docWindRes, nil, WindowPtr(-1));
  73.         ignore := SkelWindow(docWind, nil, nil, @DocUpdate, @DocActivate, nil, @DocClobber, nil, false);
  74.         MoveWindow(docWind, h, v, false);
  75.     end;
  76.  
  77.  
  78. {--------------------------------------------------------------------}
  79. { Menu handlers }
  80. {--------------------------------------------------------------------}
  81.  
  82.  
  83. { Handle selection of "About Button..." item from Apple menu }
  84.  
  85.     procedure DoAppleMenu (item: Integer);
  86.         var
  87.             ignore: Integer;
  88.     begin
  89.         ignore := SkelAlert(aboutAlrtRes, SkelDlogFilter(nil, true), skelPositionOnParentDevice);
  90.         SkelRmveDlogFilter;
  91.     end;
  92.  
  93.  
  94. { Process selection from File menu }
  95.  
  96.     procedure DoFileMenu (item: Integer);
  97.     begin
  98.         case item of
  99.             showDlog1: 
  100.                 begin
  101.                     SelectWindow(mDlog1);
  102.                     ShowWindow(mDlog1);
  103.                     SkelSetDlogCtlValue(mDlog2, check1, 1);
  104.                 end;
  105.             showDlog2: 
  106.                 begin
  107.                     SelectWindow(mDlog2);
  108.                     ShowWindow(mDlog2);
  109.                     SkelSetDlogCtlValue(mDlog1, check1, 1);
  110.                 end;
  111.             showDoc: 
  112.                 begin
  113.                     SelectWindow(docWind);
  114.                     ShowWindow(docWind);
  115.                 end;
  116.             closeWind: 
  117.                 SkelClose(FrontWindow);
  118.             quit: 
  119.                 SkelStopEventLoop;
  120.         end;
  121.     end;
  122.  
  123.  
  124.     procedure DoEditMenu (item: Integer);
  125.         var
  126.             dlog: DialogPtr;
  127.             ignore: Integer;
  128.     begin
  129.         if (SystemEdit(item - 1)) then    { if DA handled operation, return }
  130.             exit(DoEditMenu);
  131.  
  132. { if front window is document window, do nothing }
  133.         dlog := DialogPtr(FrontWindow);
  134.         if (WindowPeek(dlog)^.windowKind <> dialogKind) then
  135.             exit(DoEditMenu);
  136.         case item of
  137.             cut: 
  138.                 begin
  139.                     DlgCut(dlog);
  140.                     ignore := ZeroScrap;
  141.                     ignore := TEToScrap;
  142.                 end;
  143.             copy: 
  144.                 begin
  145.                     DlgCopy(dlog);
  146.                     ignore := ZeroScrap;
  147.                     ignore := TEToScrap;
  148.                 end;
  149.             paste: 
  150.                 begin
  151.                     ignore := TEFromScrap;
  152.                     DlgPaste(dlog);
  153.                 end;
  154.             clear: 
  155.                 DlgDelete(dlog);
  156.         end;
  157.     end;
  158.  
  159.  
  160. { Adjust menus when mouse click occurs in menu bar, }
  161. { before menus are shown. }
  162.  
  163.     procedure AdjustMenus;
  164.         var
  165.             w: WindowPtr;
  166.     begin
  167.         w := FrontWindow;
  168.         if (w = nil) then
  169.             DisableItem(fileMenu, closeWind)
  170.         else
  171.             EnableItem(fileMenu, closeWind);
  172.         if (w = docWind) then
  173.             begin
  174.                 DisableItem(editMenu, undo);
  175.                 DisableItem(editMenu, cut);
  176.                 DisableItem(editMenu, copy);
  177.                 DisableItem(editMenu, paste);
  178.                 DisableItem(editMenu, clear);
  179.             end
  180.         else
  181.             begin
  182.                 { modeless dialog or DA -- dim undo for dialogs }
  183.                 if (WindowPeek(w)^.windowKind = dialogKind) then
  184.                     DisableItem(editMenu, undo)
  185.                 else
  186.                     EnableItem(editMenu, undo);
  187.  
  188.                 EnableItem(editMenu, cut);
  189.                 EnableItem(editMenu, copy);
  190.                 EnableItem(editMenu, paste);
  191.                 EnableItem(editMenu, clear);
  192.             end;
  193.     end;
  194.  
  195.  
  196. {--------------------------------------------------------------------}
  197. { Suspend/resume handler }
  198. {--------------------------------------------------------------------}
  199.  
  200.  
  201.     procedure SuspendResume (inForeground: Boolean);
  202.         var
  203.             w: WindowPtr;
  204.             event: EventRecord;
  205.             ignore: Boolean;
  206.     begin
  207.         if (inForeground = false) then
  208.             begin
  209.                 hidden1 := false;
  210.                 hidden2 := false;
  211.                 if (WindowPeek(mDlog1)^.visible) then
  212.                     begin
  213.                         ShowHide(mDlog1, false);
  214.                         hidden1 := true;
  215.                     end;
  216.                 if (WindowPeek(mDlog2)^.visible) then
  217.                     begin
  218.                         ShowHide(mDlog2, false);
  219.                         hidden2 := true;
  220.                     end;
  221.                 w := FrontWindow;
  222.                 if (w <> nil) then
  223.                     begin
  224.                         HiliteWindow(w, false);
  225.                         SkelActivate(w, false);
  226.                     end;
  227.             end
  228.         else
  229.             begin
  230.                 w := FrontWindow;
  231.                 if (w <> nil) then
  232.                     HiliteWindow(w, false);
  233.                 if (hidden1) then
  234.                     ShowHide(mDlog1, true);
  235.                 if (hidden2) then
  236.                     ShowHide(mDlog2, true);
  237.                 w := FrontWindow;
  238.                 if (w <> nil) then
  239.                     begin
  240.                         HiliteWindow(w, true);
  241.                         SkelActivate(w, true);
  242.                     end;
  243.                 if (EventAvail(mDownMask, event)) then
  244.                     ignore := GetNextEvent(mDownMask, event);
  245.             end;
  246.     end;
  247.  
  248.  
  249. {--------------------------------------------------------------------}
  250. { Main program }
  251. {--------------------------------------------------------------------}
  252.  
  253.  
  254.     procedure Initialize;
  255.         var
  256.             ignore: Boolean;
  257.     begin
  258.         iconNum1 := 0;
  259.         iconNum2 := 0;
  260.  
  261.         SkelInit(nil);
  262.  
  263.         SkelSetSuspendResume(@SuspendResume);
  264.  
  265.         SkelApple('About DialogSkel…', @DoAppleMenu);
  266.  
  267.         fileMenu := NewMenu(fileMenuID, 'File');
  268.         AppendMenu(fileMenu, 'Show Dialog 1;Show Dialog 2;Show Doc Window');
  269.         AppendMenu(fileMenu, 'Close/W;(-;Quit/Q');
  270.         ignore := SkelMenu(fileMenu, @DoFileMenu, nil, false, false);
  271.  
  272.         editMenu := NewMenu(editMenuID, 'Edit');
  273.         AppendMenu(editMenu, '(Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear');
  274.         ignore := SkelMenu(editMenu, @DoEditMenu, nil, false, false);
  275.  
  276.         DrawMenuBar;
  277.         SkelSetMenuHook(@AdjustMenus);
  278.  
  279.         DocWindow(100, 125);
  280.  
  281.         mDlog1 := DemoDialog('Modeless Dialog 1', 50, 50);
  282.         mDlog2 := DemoDialog('Modeless Dialog 2', 150, 200);
  283.         SetWRefCon(mDlog1, LongInt(mDlog2));
  284.         SetWRefCon(mDlog2, LongInt(mDlog1));
  285.         SkelSetDlogStr(mDlog1, edit1, 'Modeless Dialog 2');
  286.         SkelSetDlogStr(mDlog2, edit1, 'Modeless Dialog 1');
  287.         SkelSetDlogProc(mDlog1, user1, @DrawIcon);
  288.         SkelSetDlogProc(mDlog2, user1, @DrawIcon);
  289.         SkelSetDlogRadioButtonSet(mDlog1, radio1, radio3, radio1);
  290.         SkelSetDlogRadioButtonSet(mDlog2, radio1, radio3, radio1);
  291.         SkelSetDlogCtlValue(mDlog1, check1, 1);
  292.         SkelSetDlogCtlValue(mDlog2, check1, 1);
  293.         SkelSetDlogCtlValue(mDlog1, check2, 1);
  294.         SkelSetDlogCtlValue(mDlog2, check2, 1);
  295.  
  296.         SelectWindow(docWind);
  297.         ShowWindow(docWind);
  298.         SkelDoEvents(activMask + updateMask);
  299.         SelectWindow(mDlog1);
  300.         ShowWindow(mDlog1);
  301.         SkelDoEvents(activMask + updateMask);
  302.         SelectWindow(mDlog2);
  303.         ShowWindow(mDlog2);
  304.         SkelDoEvents(activMask + updateMask);
  305.     end;
  306.  
  307.  
  308. begin
  309.     Initialize;
  310.     SkelEventLoop;
  311.     SkelCleanup;
  312. end.