home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: PenSizeDialog.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 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. */
-
-
-
- /*****************************************************************************/
-
-
-
- #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 __TREEOBJ2__
- #include "TreeObj2.h"
- #endif
-
-
-
- extern short gPenHeight, gPenWidth, gCtlNum;
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Find out which tool was clicked or double-clicked on. */
-
- #pragma segment PENS
-
- static Boolean PenSizeFilter(TEHandle teHndl, EventRecord *event, short *handled);
- static Boolean PenSizeFilter(TEHandle teHndl, EventRecord *event, short *handled)
- {
- #ifndef __MWERKS__
- #pragma unused (teHndl, handled)
- #endif
-
- char key;
- short i;
-
- key = event->message & charCodeMask;
- i = event->modifiers & keyCodeMask;
- if (i & cmdKey) return(false);
- if (i & optionKey) return(false);
- if (key == 8) return(false);
- if (key == 9) return(false);
- if ((key >= 28) && (key <= 31)) return(false);
-
- if ((key < '0') || (key > '9')) return(true);
-
- return(false);
- }
-
- OSErr PENSInitContent(FileRecHndl frHndl, WindowPtr window)
- {
- OSErr err;
- TreeObjHndl root, cobj;
- ControlHandle ctl;
- TEHandle te;
- Handle txt;
- short penHeight, penWidth, ph, pw, i;
- Boolean gotSize;
- Str15 pstr;
-
- err = AddControlSet(window, (*frHndl)->fileState.sfType, kwStandardVis, 0, 0, nil);
- if (err) return(err);
-
- penHeight = gPenHeight; /* Assume that there are none selected. */
- penWidth = gPenWidth;
- gotSize = false;
-
- frHndl = GetNextDocument(window, kDocFileType);
- root = (*frHndl)->d.doc.root;
- for (i = (*root)->numChildren; i;) {
- cobj = GetChildHndl(root, --i);
- if (DoTreeObjMethod(cobj, GETSELECTMESSAGE, 0)) {
- if ((*cobj)->type < GROUPOBJ) {
- ph = mDerefCommon(cobj)->penHeight;
- pw = mDerefCommon(cobj)->penWidth;
- if (!gotSize) {
- gotSize = true;
- penHeight = ph;
- penWidth = pw;
- continue;
- }
- if (penHeight != ph) penHeight = -1;
- if (penWidth != pw) penWidth = -1;
- }
- }
- }
-
- pstr[0] = 0;
- if (!penHeight)
- ++penHeight;
- if (penHeight > -1)
- pcpydec(pstr, penHeight);
- txt = NewHandle(pstr[0]);
- BlockMove(pstr + 1, *txt, pstr[0]);
- CNum2Ctl(window, 100, &ctl);
- te = (TEHandle)GetControlReference(ctl);
- UseControlStyle(ctl);
- DisposeHandle(CTESwapText(te, txt, nil, true));
- TESetSelect(0, 32767, te);
- CTESetKeyFilter(te, PenSizeFilter);
-
- pstr[0] = 0;
- if (!penWidth)
- ++penWidth;
- if (penWidth > -1)
- pcpydec(pstr, penWidth);
- txt = NewHandle(pstr[0]);
- BlockMove(pstr + 1, *txt, pstr[0]);
- CNum2Ctl(window, 101, &ctl);
- te = (TEHandle)GetControlReference(ctl);
- DisposeHandle(CTESwapText(te, txt, nil, true));
- TESetSelect(0, 32767, te);
- CTESetKeyFilter(te, PenSizeFilter);
-
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment PENS
- OSErr PENSFreeWindow(FileRecHndl frHndl, WindowPtr window)
- {
- ControlHandle ctl;
- TEHandle te;
- Str15 pstr;
- short i;
- TreeObjHndl root, cobj;
- OSErr err;
-
- if (gCtlNum == -1) {
- CNum2Ctl(window, 100, &ctl);
- te = (TEHandle)GetControlReference(ctl);
- BlockMove(*((*te)->hText), pstr + 1, (pstr[0] = (*te)->teLength));
- gPenHeight = p2dec(pstr, nil);
- if (!gPenHeight)
- ++gPenHeight;
- CNum2Ctl(window, 101, &ctl);
- te = (TEHandle)GetControlReference(ctl);
- BlockMove(*((*te)->hText), pstr + 1, (pstr[0] = (*te)->teLength));
- gPenWidth = p2dec(pstr, nil);
- if (!gPenWidth)
- ++gPenWidth;
- frHndl = GetNextDocument(window, kDocFileType);
- root = (*frHndl)->d.doc.root;
- for (i = (*root)->numChildren; i;) {
- cobj = GetChildHndl(root, --i);
- if (DoTreeObjMethod(cobj, GETSELECTMESSAGE, 0)) {
- if ((*cobj)->type < GROUPOBJ) {
- err = ModifyChild(PENSIZE_EDIT, root, i, false);
- if (err) return(err);
- mDerefCommon(cobj)->penHeight = gPenHeight;
- mDerefCommon(cobj)->penWidth = gPenWidth;
- }
- }
- }
- HideWindow(window);
- DoImageDocument(frHndl);
- }
-
- return(noErr);
- }
-
-
-
-