home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Draw / ToolPalette.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-05  |  7.0 KB  |  275 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.         if (menu) {
  126.             for (i = kArrowTool; i <= kNumTools; ++i) SetItemMark(menu, i, noMark);
  127.             SetItemMark(menu, UnmapMItem(mToolPalette, cnum - rArrowIcon + 1),
  128.                         '0' + (*ctl)->contrlValue);
  129.         }
  130.     }
  131. }
  132.  
  133.  
  134.  
  135. /*****************************************************************************/
  136.  
  137.  
  138.  
  139. /* Draw the tool palette icons into the port.  If DTS.LIB..framework calls us, the
  140. ** port is already set, but we set it here so that we can call this function
  141. ** directly.  Calling it directly is desireable for certain operations, such
  142. ** as when the user clicks with a one-shot tool.  When this occurs, we revert
  143. ** back to the arrow tool.  Also, if a tool is permanently selected and the
  144. ** user clicks in a document but then doesn't grow out an object, we also revert
  145. ** to the arrow tool.  Another case is if the user selects a tool via the menu. */
  146.  
  147. #pragma segment ToolPalette
  148. static OSErr    ToolImageDocument(FileRecHndl frHndl)
  149. {
  150. #ifndef __MWERKS__
  151. #pragma unused (frHndl)
  152. #endif
  153.  
  154.     DoDrawControls((*frHndl)->fileState.window, false);
  155.     return(noErr);
  156. }
  157.  
  158.  
  159.  
  160. /*****************************************************************************/
  161. /*****************************************************************************/
  162.  
  163.  
  164.  
  165. #pragma segment ToolPalette
  166. Rect    PlaceToolWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo)
  167. {
  168. #ifndef __MWERKS__
  169. #pragma unused (relatedWindow, sizeInfo)
  170. #endif
  171.  
  172.     Rect    scnRct, cntRct;
  173.     short    dx, dy;
  174.  
  175.     scnRct = GetMainScreenRect();
  176.     cntRct = GetWindowContentRect(window);
  177.  
  178.     dx = cntRct.right  - cntRct.left;
  179.     dy = cntRct.bottom - cntRct.top;
  180.  
  181.     cntRct.right  = scnRct.right - 5;
  182.     cntRct.top    = scnRct.top   + 33;
  183.     cntRct.left   = cntRct.right - dx;
  184.     cntRct.bottom = cntRct.top + dy;
  185.  
  186.     MoveWindow(window, cntRct.left, cntRct.top, false);
  187.     return(cntRct);
  188. }
  189.  
  190.  
  191.  
  192. /*****************************************************************************/
  193.  
  194.  
  195.  
  196. /* Tool palette set tool function. */
  197.  
  198. #pragma segment ToolPalette
  199. void    SetPaletteTool(short tool)
  200. {
  201.     MenuHandle        menu;
  202.     WindowPtr        toolWind;
  203.     ControlHandle    ctl;
  204.     short            i;
  205.  
  206.     toolWind = GetNextWindow(nil, kToolFileType);
  207.     if (toolWind) BeginContent(toolWind);
  208.     else {
  209.         toolWind = GetNextWindow(nil, kDocFileType);
  210.         if (toolWind) BeginFrame(toolWind);
  211.     }
  212.     if (!toolWind) return;
  213.  
  214.     menu = GetMenuHandle(mToolPalette);
  215.     for (ctl = nil, i = 1; (ctl = CCIconNext(toolWind, ctl, 1, true)) != nil; ++i) {
  216.         if (Ctl2CNum(ctl) - rArrowIcon == tool) {
  217.             SetControlValue(ctl, 1);
  218.             if (menu) SetItemMark(menu, i, '1');
  219.         }
  220.         else {
  221.             SetControlValue(ctl, 0);
  222.             if (menu) SetItemMark(menu, i, noMark);
  223.         }
  224.     }
  225.  
  226.     EndContent(toolWind);        /* Or EndFrame -- interchangeable calls. */
  227. }
  228.  
  229.  
  230.  
  231. /*****************************************************************************/
  232.  
  233.  
  234.  
  235. #pragma segment ToolPalette
  236. short    GetTool(void)
  237. {
  238.     WindowPtr        toolWind;
  239.     ControlHandle    ctl;
  240.  
  241.                    toolWind = GetNextWindow(nil, kToolFileType);
  242.     if (!toolWind) toolWind = GetNextWindow(nil, kDocFileType);
  243.     if (!toolWind) return(0);
  244.  
  245.     for (ctl = nil; (ctl = CCIconNext(toolWind, ctl, 1, true)) != nil;)
  246.         if ((*ctl)->contrlValue) break;
  247.  
  248.     return(Ctl2CNum(ctl) - rArrowIcon);
  249. }
  250.  
  251.  
  252.  
  253. /*****************************************************************************/
  254.  
  255.  
  256.  
  257. #pragma segment ToolPalette
  258. Boolean    GetToolPersistence(void)
  259. {
  260.     WindowPtr        toolWind;
  261.     ControlHandle    ctl;
  262.  
  263.                    toolWind = GetNextWindow(nil, kToolFileType);
  264.     if (!toolWind) toolWind = GetNextWindow(nil, kDocFileType);
  265.     if (!toolWind) return(0);
  266.  
  267.     for (ctl = nil; (ctl = CCIconNext(toolWind, ctl, 1, true)) != nil;)
  268.         if ((*ctl)->contrlValue == 2) return(true);
  269.  
  270.     return(false);
  271. }
  272.  
  273.  
  274.  
  275.