home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Libraries / WASTE 1.1a4 / Demo Source / WEDemoIntf.p < prev    next >
Encoding:
Text File  |  1994-11-13  |  4.6 KB  |  218 lines  |  [TEXT/PJMM]

  1. unit DemoIntf;
  2.  
  3. { WASTE DEMO PROJECT: }
  4. { Global interface: constant, type and class declarations used in most other units }
  5.  
  6. { Copyright © 1993-1994 Merzwaren }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         WASTE;
  12.  
  13.     const
  14.  
  15. { WASTE demo signature }
  16.  
  17.         kAppSignature = 'OEDE';
  18.  
  19. { resource types, clipboard types and file types }
  20.  
  21.         kTypeDeskAccessory = 'DRVR';
  22.         kTypeFont = 'FONT';
  23.         kTypePicture = 'PICT';
  24.         kTypeSoup = 'SOUP';
  25.         kTypeStyles = 'styl';
  26.         kTypeText = 'TEXT';
  27.  
  28. { menu IDs }
  29.  
  30.         kMenuApple = 1;
  31.         kMenuFile = 2;
  32.         kMenuEdit = 3;
  33.         kMenuFont = 4;
  34.         kMenuSize = 5;
  35.         kMenuStyle = 6;
  36.         kMenuAlignment = 7;
  37.  
  38. { Apple menu items }
  39.  
  40.         kItemAbout = 1;
  41.  
  42. { File menu items }
  43.  
  44.         kItemNew = 1;
  45.         kItemOpen = 2;
  46.         kItemClose = 4;
  47.         kItemSave = 5;
  48.         kItemSaveAs = 6;
  49.         kItemPageSetup = 8;
  50.         kItemPrint = 9;
  51.         kItemQuit = 11;
  52.  
  53. { Edit menu items }
  54.  
  55.         kItemUndo = 1;
  56.         kItemCut = 3;
  57.         kItemCopy = 4;
  58.         kItemPaste = 5;
  59.         kItemClear = 6;
  60.         kItemSelectAll = 7;
  61.  
  62. { Size menu items }
  63.  
  64.         kItemLastSize = 6;
  65.         kItemSmaller = 8;
  66.         kItemLarger = 9;
  67.  
  68. { Style menu items }
  69.  
  70.         kItemPlainText = 1;
  71.         kItemBold = 2;
  72.         kItemItalic = 3;
  73.         kItemUnderline = 4;
  74.         kItemOutline = 5;
  75.         kItemShadow = 6;
  76.         kItemCondensed = 7;
  77.         kItemExtended = 8;
  78.  
  79. { Alignment menu items }
  80.  
  81.         kItemAlignLeft = 1;
  82.         kItemCenter = 2;
  83.         kItemAlignRight = 3;
  84.         kItemJustify = 4;
  85.  
  86. { Alert template resource IDs }
  87.  
  88.         kAlertNeedSys7 = 128;
  89.         kAlertAboutBox = 129;
  90.         kAlertGenError = 130;
  91.         kAlertSaveChanges = 131;
  92.  
  93. { String list resource IDs }
  94.  
  95.         kUndoStringsID = 128;
  96.         kClosingQuittingStringsID = 129;
  97.  
  98. { miscellaneous resource IDs }
  99.  
  100.         kMenuBarID = 128;
  101.         kWindowTemplateID = 128;
  102.         kScrollBarTemplateID = 128;
  103.         kPromptStringID = 128;
  104.  
  105. { virtual key codes for navigation keys found on extended keyboards }
  106.  
  107.         keyPgUp = $74;
  108.         keyPgDn = $79;
  109.         keyHome = $73;
  110.         keyEnd = $77;
  111.  
  112. { values for HiliteControl hiliteState parameter }
  113.  
  114.         kCtlActive = 0;                    { active control }
  115.         kCtlHilited = 1;                    { highlighted active control }
  116.         kCtlBackground = 254;        { inactive control in an inactive window }
  117.         kCtlInactive = 255;            { inactive control in the active window }
  118.  
  119. { other commonly used constants }
  120.  
  121.         kBarWidth = 16;                { width of a scroll bar }
  122.         kTitleHeight = 20;                { usual height of a window title bar }
  123.         kTextMargin = 3;                { indent of text rect from window port rect }
  124.         kScrollDelta = 11;                { pixels to scroll when the scroll bar arrow is clicked }
  125.  
  126.     type
  127.  
  128. { enumeration types used for closing a window and/or quitting the application }
  129.  
  130.         ClosingOption = (closingWindow, closingApplication);
  131.         SavingOption = (savingYes, savingNo, savingAsk);
  132.  
  133. { a ScrollBarPair is just a pair of control handles }
  134.  
  135.         ScrollBarPair = record
  136.                 case Integer of
  137.                     0: (
  138.                             v, h: ControlHandle;
  139.                     );
  140.                     1: (
  141.                             vh: array[VHSelect] of ControlHandle;
  142.                     );
  143.             end;  { ScrollBarPair }
  144.  
  145. { a DocumentRecord is a window record with additional fields }
  146.  
  147.         DocumentRecord = record
  148.                 window: WindowRecord;                    { the window }
  149.                 scrollBars: ScrollBarPair;                    { its scroll bars }
  150.                 hWE: WEHandle;                                { its WASTE instance }
  151.                 fileAlias: Handle;                                { alias to associated file }
  152.             end;  { DocumentRec }
  153.         DocumentPeek = ^DocumentRecord;
  154.  
  155.     var
  156.  
  157. { global variables }
  158.  
  159.         gHasColorQD: Boolean;            { TRUE if Color QuickDraw is available }
  160.         gHasDragAndDrop: Boolean;    { TRUE if the Drag Manager is available }
  161.         gHasTextServices: Boolean;    { TRUE if the Text Services Manager is available }
  162.         gExiting: Boolean;                    { set this variable to drop out of event loop and quit }
  163.  
  164. { general purpose utility routines }
  165.  
  166.     procedure ErrorAlert (err: OSErr);
  167.     procedure ForgetHandle (var h: univ Handle);
  168.     function NewHandleTemp (blockSize: Size;
  169.                                     var h: univ Handle): OSErr;
  170.  
  171. implementation
  172.     uses
  173.         DialogUtils;
  174.  
  175.     procedure ErrorAlert (err: OSErr);
  176.         var
  177.             errString: Str255;
  178.             alertResult: Integer;
  179.     begin
  180.         NumToString(err, errString);
  181.         ParamText(errString, '', '', '');
  182.         SetCursor(arrow);
  183.         alertResult := Alert(kAlertGenError, @DialogFilter);
  184.     end;  { ErrorAlert }
  185.  
  186.     procedure ForgetHandle (var h: univ Handle);
  187.         var
  188.             theHandle: Handle;
  189.     begin
  190.         theHandle := h;
  191.         if (theHandle <> nil) then
  192.             begin
  193.                 h := nil;
  194.                 DisposeHandle(theHandle);
  195.             end;
  196.     end;  { ForgetHandle }
  197.  
  198.     function NewHandleTemp (blockSize: Size;
  199.                                     var h: univ Handle): OSErr;
  200.  
  201. { allocate a new relocatable block from temporary memory or, }
  202. { if that fails, from the current heap }
  203.  
  204.     begin
  205.  
  206. { first try tapping temporary memory }
  207.         h := TempNewHandle(blockSize, NewHandleTemp);
  208.  
  209. { in case of failure, try with current heap }
  210.         if (h = nil) then
  211.             begin
  212.                 h := NewHandle(blockSize);
  213.                 NewHandleTemp := MemError;
  214.             end;
  215.  
  216.     end;  { NewHandleTemp }
  217.  
  218. end.