home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / DTS.Draw / ToolPalette.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  6.6 KB  |  260 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        ToolPalette.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This file contains the code for the document procedure pointers for the DTS.Draw
  20. ** tool palette document.  The tool palette document does very little, so most of
  21. ** the document procedure pointers are set to nil.  Imaging and clicking are the
  22. ** only two methods that we need to support. */
  23.  
  24.  
  25.  
  26. /*****************************************************************************/
  27.  
  28.  
  29.  
  30. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  31. #include "App.defs.h"        /* Get various application definitions.            */
  32. #include "App.protos.h"        /* Get the prototypes for the application.        */
  33.  
  34. #ifndef __ERRORS__
  35. #include <Errors.h>
  36. #endif
  37.  
  38. #ifndef __FONTS__
  39. #include <Fonts.h>
  40. #endif
  41.  
  42. #ifndef __RESOURCES__
  43. #include <Resources.h>
  44. #endif
  45.  
  46. #ifndef __TOOLUTILS__
  47. #include <ToolUtils.h>
  48. #endif
  49.  
  50. #ifndef __TREEOBJ2__
  51. #include "TreeObj2.h"
  52. #endif
  53.  
  54. #ifndef __UTILITIES__
  55. #include "Utilities.h"
  56. #endif
  57.  
  58.  
  59. /*****************************************************************************/
  60.  
  61.  
  62.  
  63. static void        ToolContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
  64. static OSErr    ToolImageDocument(FileRecHndl frHndl);
  65. static Rect        PlaceToolWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  66.  
  67.  
  68.  
  69. /*****************************************************************************/
  70. /*****************************************************************************/
  71.  
  72.  
  73.  
  74. /* Just imaging and clicking are handles by the tool palette. */
  75.  
  76. #pragma segment ToolPalette
  77. OSErr    ToolInitDocument(FileRecHndl frHndl)
  78. {
  79.     FileRecPtr    frPtr;
  80.  
  81.     frPtr = *frHndl;
  82.     frPtr->fileState.calcFrameRgnProc        = nil;
  83.     frPtr->fileState.contentClickProc        = ToolContentClick;
  84.     frPtr->fileState.contentKeyProc          = nil;
  85.     frPtr->fileState.drawFrameProc           = nil;
  86.     frPtr->fileState.freeDocumentProc        = nil;
  87.     frPtr->fileState.freeWindowProc          = nil;
  88.     frPtr->fileState.imageProc               = ToolImageDocument;
  89.     frPtr->fileState.readDocumentProc        = nil;
  90.     frPtr->fileState.readDocumentHeaderProc  = nil;
  91.     frPtr->fileState.resizeContentProc       = nil;
  92.     frPtr->fileState.scrollFrameProc         = nil;
  93.     frPtr->fileState.undoFixupProc           = nil;
  94.     frPtr->fileState.windowCursorProc        = nil;
  95.     frPtr->fileState.writeDocumentProc       = nil;
  96.     frPtr->fileState.writeDocumentHeaderProc = nil;
  97.  
  98.     return(noErr);
  99. }
  100.  
  101.  
  102.  
  103. /*****************************************************************************/
  104. /*****************************************************************************/
  105.  
  106.  
  107.  
  108. /* Find out which tool was clicked or double-clicked on. */
  109.  
  110. #pragma segment ToolPalette
  111. static void    ToolContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
  112. {
  113. #ifndef __MWERKS__
  114. #pragma unused (firstClick)
  115. #endif
  116.  
  117.     short            cnum;
  118.     ControlHandle    ctl;
  119.     MenuHandle        menu;
  120.     short            i;
  121.  
  122.     cnum = IsCtlEvent(window, event, &ctl, nil);
  123.     if (cnum) {
  124.         menu = GetMenuHandle(mToolPalette);
  125.         for (i = kArrowTool; i <= kNumTools; ++i) SetItemMark(menu, i, noMark);
  126.         SetItemMark(menu, UnmapMItem(mToolPalette, cnum - rArrowIcon + 1), '0' + (*ctl)->contrlValue);
  127.     }
  128. }
  129.  
  130.  
  131.  
  132. /*****************************************************************************/
  133.  
  134.  
  135.  
  136. /* Draw the tool palette icons into the port.  If DTS.LIB..framework calls us, the
  137. ** port is already set, but we set it here so that we can call this function
  138. ** directly.  Calling it directly is desireable for certain operations, such
  139. ** as when the user clicks with a one-shot tool.  When this occurs, we revert
  140. ** back to the arrow tool.  Also, if a tool is permanently selected and the
  141. ** user clicks in a document but then doesn't grow out an object, we also revert
  142. ** to the arrow tool.  Another case is if the user selects a tool via the menu. */
  143.  
  144. #pragma segment ToolPalette
  145. static OSErr    ToolImageDocument(FileRecHndl frHndl)
  146. {
  147. #ifndef __MWERKS__
  148. #pragma unused (frHndl)
  149. #endif
  150.  
  151.     DoDrawControls((*frHndl)->fileState.window, false);
  152.     return(noErr);
  153. }
  154.  
  155.  
  156.  
  157. /*****************************************************************************/
  158. /*****************************************************************************/
  159.  
  160.  
  161.  
  162. #pragma segment ToolPalette
  163. Rect    PlaceToolWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo)
  164. {
  165. #ifndef __MWERKS__
  166. #pragma unused (relatedWindow, sizeInfo)
  167. #endif
  168.  
  169.     Rect    scnRct, cntRct;
  170.     short    dx, dy;
  171.  
  172.     scnRct = GetMainScreenRect();
  173.     cntRct = GetWindowContentRect(window);
  174.  
  175.     dx = cntRct.right  - cntRct.left;
  176.     dy = cntRct.bottom - cntRct.top;
  177.  
  178.     cntRct.right  = scnRct.right - 5;
  179.     cntRct.top    = scnRct.top   + 33;
  180.     cntRct.left   = cntRct.right - dx;
  181.     cntRct.bottom = cntRct.top + dy;
  182.  
  183.     MoveWindow(window, cntRct.left, cntRct.top, false);
  184.     return(cntRct);
  185. }
  186.  
  187.  
  188.  
  189. /*****************************************************************************/
  190.  
  191.  
  192.  
  193. /* Tool palette set tool function. */
  194.  
  195. #pragma segment ToolPalette
  196. void    SetPaletteTool(short tool)
  197. {
  198.     MenuHandle        menu;
  199.     WindowPtr        toolWind;
  200.     ControlHandle    ctl;
  201.     short            i;
  202.  
  203.     if (!(toolWind = GetNextWindow(nil, kToolFileType))) return;
  204.  
  205.     menu = GetMenuHandle(mToolPalette);
  206.     for (ctl = nil, i = 1; (ctl = CCIconNext(toolWind, ctl, 1, true)) != nil; ++i) {
  207.         if (Ctl2CNum(ctl) - rArrowIcon == tool) {
  208.             SetControlValue(ctl, 1);
  209.             SetItemMark(menu, i, '1');
  210.         }
  211.         else {
  212.             SetControlValue(ctl, 0);
  213.             SetItemMark(menu, i, noMark);
  214.         }
  215.     }
  216. }
  217.  
  218.  
  219.  
  220. /*****************************************************************************/
  221.  
  222.  
  223.  
  224. #pragma segment ToolPalette
  225. short    GetTool(void)
  226. {
  227.     WindowPtr        toolWind;
  228.     ControlHandle    ctl;
  229.  
  230.     if (!(toolWind = GetNextWindow(nil, kToolFileType))) return(false);
  231.  
  232.     for (ctl = nil; (ctl = CCIconNext(toolWind, ctl, 1, true)) != nil;)
  233.         if ((*ctl)->contrlValue) break;
  234.  
  235.     return(Ctl2CNum(ctl) - rArrowIcon);
  236. }
  237.  
  238.  
  239.  
  240. /*****************************************************************************/
  241.  
  242.  
  243.  
  244. #pragma segment ToolPalette
  245. Boolean    GetToolPersistence(void)
  246. {
  247.     WindowPtr        toolWind;
  248.     ControlHandle    ctl;
  249.  
  250.     if (!(toolWind = GetNextWindow(nil, kToolFileType))) return(false);
  251.  
  252.     for (ctl = nil; (ctl = CCIconNext(toolWind, ctl, 1, true)) != nil;)
  253.         if ((*ctl)->contrlValue == 2) return(true);
  254.  
  255.     return(false);
  256. }
  257.  
  258.  
  259.  
  260.