home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: ToolPalette.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
- /* This file contains the code for the document procedure pointers for the DTS.Draw
- ** tool palette document. The tool palette document does very little, so most of
- ** the document procedure pointers are set to nil. Imaging and clicking are the
- ** only two methods that we need to support. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.defs.h" /* Get various application definitions. */
- #include "App.protos.h" /* Get the prototypes for the application. */
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __TREEOBJ2__
- #include "TreeObj2.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
- /*****************************************************************************/
-
-
-
- static void ToolContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
- static OSErr ToolImageDocument(FileRecHndl frHndl);
- static Rect PlaceToolWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Just imaging and clicking are handles by the tool palette. */
-
- #pragma segment ToolPalette
- OSErr ToolInitDocument(FileRecHndl frHndl)
- {
- FileRecPtr frPtr;
-
- frPtr = *frHndl;
- frPtr->fileState.calcFrameRgnProc = nil;
- frPtr->fileState.contentClickProc = ToolContentClick;
- frPtr->fileState.contentKeyProc = nil;
- frPtr->fileState.drawFrameProc = nil;
- frPtr->fileState.freeDocumentProc = nil;
- frPtr->fileState.freeWindowProc = nil;
- frPtr->fileState.imageProc = ToolImageDocument;
- frPtr->fileState.readDocumentProc = nil;
- frPtr->fileState.readDocumentHeaderProc = nil;
- frPtr->fileState.resizeContentProc = nil;
- frPtr->fileState.scrollFrameProc = nil;
- frPtr->fileState.undoFixupProc = nil;
- frPtr->fileState.windowCursorProc = nil;
- frPtr->fileState.writeDocumentProc = nil;
- frPtr->fileState.writeDocumentHeaderProc = nil;
-
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Find out which tool was clicked or double-clicked on. */
-
- #pragma segment ToolPalette
- static void ToolContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
- {
- #ifndef __MWERKS__
- #pragma unused (firstClick)
- #endif
-
- short cnum;
- ControlHandle ctl;
- MenuHandle menu;
- short i;
-
- cnum = IsCtlEvent(window, event, &ctl, nil);
- if (cnum) {
- menu = GetMenuHandle(mToolPalette);
- if (menu) {
- for (i = kArrowTool; i <= kNumTools; ++i) SetItemMark(menu, i, noMark);
- SetItemMark(menu, UnmapMItem(mToolPalette, cnum - rArrowIcon + 1),
- '0' + (*ctl)->contrlValue);
- }
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Draw the tool palette icons into the port. If DTS.LIB..framework calls us, the
- ** port is already set, but we set it here so that we can call this function
- ** directly. Calling it directly is desireable for certain operations, such
- ** as when the user clicks with a one-shot tool. When this occurs, we revert
- ** back to the arrow tool. Also, if a tool is permanently selected and the
- ** user clicks in a document but then doesn't grow out an object, we also revert
- ** to the arrow tool. Another case is if the user selects a tool via the menu. */
-
- #pragma segment ToolPalette
- static OSErr ToolImageDocument(FileRecHndl frHndl)
- {
- #ifndef __MWERKS__
- #pragma unused (frHndl)
- #endif
-
- DoDrawControls((*frHndl)->fileState.window, false);
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- #pragma segment ToolPalette
- Rect PlaceToolWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo)
- {
- #ifndef __MWERKS__
- #pragma unused (relatedWindow, sizeInfo)
- #endif
-
- Rect scnRct, cntRct;
- short dx, dy;
-
- scnRct = GetMainScreenRect();
- cntRct = GetWindowContentRect(window);
-
- dx = cntRct.right - cntRct.left;
- dy = cntRct.bottom - cntRct.top;
-
- cntRct.right = scnRct.right - 5;
- cntRct.top = scnRct.top + 33;
- cntRct.left = cntRct.right - dx;
- cntRct.bottom = cntRct.top + dy;
-
- MoveWindow(window, cntRct.left, cntRct.top, false);
- return(cntRct);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Tool palette set tool function. */
-
- #pragma segment ToolPalette
- void SetPaletteTool(short tool)
- {
- MenuHandle menu;
- WindowPtr toolWind;
- ControlHandle ctl;
- short i;
-
- toolWind = GetNextWindow(nil, kToolFileType);
- if (toolWind) BeginContent(toolWind);
- else {
- toolWind = GetNextWindow(nil, kDocFileType);
- if (toolWind) BeginFrame(toolWind);
- }
- if (!toolWind) return;
-
- menu = GetMenuHandle(mToolPalette);
- for (ctl = nil, i = 1; (ctl = CCIconNext(toolWind, ctl, 1, true)) != nil; ++i) {
- if (Ctl2CNum(ctl) - rArrowIcon == tool) {
- SetControlValue(ctl, 1);
- if (menu) SetItemMark(menu, i, '1');
- }
- else {
- SetControlValue(ctl, 0);
- if (menu) SetItemMark(menu, i, noMark);
- }
- }
-
- EndContent(toolWind); /* Or EndFrame -- interchangeable calls. */
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment ToolPalette
- short GetTool(void)
- {
- WindowPtr toolWind;
- ControlHandle ctl;
-
- toolWind = GetNextWindow(nil, kToolFileType);
- if (!toolWind) toolWind = GetNextWindow(nil, kDocFileType);
- if (!toolWind) return(0);
-
- for (ctl = nil; (ctl = CCIconNext(toolWind, ctl, 1, true)) != nil;)
- if ((*ctl)->contrlValue) break;
-
- return(Ctl2CNum(ctl) - rArrowIcon);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment ToolPalette
- Boolean GetToolPersistence(void)
- {
- WindowPtr toolWind;
- ControlHandle ctl;
-
- toolWind = GetNextWindow(nil, kToolFileType);
- if (!toolWind) toolWind = GetNextWindow(nil, kDocFileType);
- if (!toolWind) return(0);
-
- for (ctl = nil; (ctl = CCIconNext(toolWind, ctl, 1, true)) != nil;)
- if ((*ctl)->contrlValue == 2) return(true);
-
- return(false);
- }
-
-
-
-