home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.0 KB | 116 lines | [TEXT/KAHL] |
- //------------------------- © 1992-1995 by James G. Stout --------------------------
- // File : cdefSpinner.h
- // Date : 24 October 1992
- // Author : Jim Stout
- // :
- // Purpose : a "Spinner Control" CDEF that allows adjustment of a
- // : number via an up/down spinner - a "little arrow" control as
- // : described in the Inside Mac volume on human interface.
- // :
- // : ControlMin and Max are respected, as is the useWindFont variation.
- // : Inactive controls are drawn in the proper gray color or pattern.
- // :
- // : Normally, the control value will be incremented by 1. To change
- // : this, just set the refCon in your template or call to NewControl
- // : to the desired increment value.
- // :
- // : If the mouse held down in the control, it will "accelerate" and
- // : the control value will change by larger and larger increments.
- // : If the increment is 1, it will change by 1's from 1-50, then
- // : by 10's from 50-100, then by 100's.
- // :
- // : The default arrow type is like the ones in the Date & Time control
- // : panel. A variation code of 1 will give larger arrows, as in the
- // : Memory Control panel. A variation code of 2 will produce 3D arrows
- // : and variation code 4 can be used for horizontal arrows
- // :
- // : The control title will be drawn left justified, the up/down
- // : arrows will be drawn right justified, with the control value
- // : number drawn just to the left of the arrows.
- // :
- // : The minimum size for this control is 18 pixels x 11 pixels for
- // : small arrows or 25 pixels by 15 pixels for the larger (variation 1).
- // : Set to this size to use with an edit text control as discussed below.
- // : Set to these minima, the control title and value will not be drawn.
- // :
- // : This CDEF can be used in conjunction with a dialog edit text item.
- // : CDEFs cannot get keyDown events, so the trick here is to have the
- // : CDEF update the edit text item. To do this, set the HiWord of
- // : control refCon to a DITL editText item number to be updated. In
- // : this case, set the LoWord of the refCon to the desired increment.
- // :
- // : The calling program must take care of insuring that only digits
- // : are typed into the edit text. ALSO, when the user types new
- // : digits, the calling program must get the contents of the edit item,
- // : convert it to a number and call SetCtlValue to let the control
- // : know about the new value. Otherwise, the next click in the
- // : control will wipe out the typed value.
- // :
- // : use procID : 102 * 16 + varCode
- // : when calling NewControl() or in your resource template.
- //
- //----------------------------------------------------------------------------------
-
- #define ARROWHT 18 // the size of the little arrows
- #define ARROWID 11
- #define ARROWHT1 25 // the size of the big arrows
- #define ARROWID1 15
-
- //----------------------------------------------------------------------------------
- // variation codes
- //----------------------------------------------------------------------------------
- #define bigArrows 0x01
- #define ctl3D 0x02
- #define horizArrows 0x04
- #ifndef useWindFont
- #define useWindFont 0x08 // draw with window font instead of System font
- #endif
-
- //----------------------------------------------------------------------------------
- // partCodes
- //----------------------------------------------------------------------------------
-
- enum {
- ALL = 0,
- FRAME,
- UPARROW,
- DOWNARROW,
- TITLE,
- BASELINE,
- NUMPARTS
- };
-
- //----------------------------------------------------------------------------------
- // CDEF private data structure
- //----------------------------------------------------------------------------------
-
- typedef struct {
-
- // increment and DITL itemNum are passed into the control as
- // LoWord & HiWord of the control RefCon
-
- short increment; // initial, requested increment value
- short itemNum; // DITL editText item number for SetIText
- long userData; // user supplied data
- short currIncr; // current increment value
- short bumpit; // when == 1, bump increment up
- short qdVers; // QuickDraw version
- short pDepth; // pixel depth for control
- CGrafPtr offPort; // offscreen drawing port
- PolyHandle poly[3]; // for arrow frame & arrows
- }spinData,**hSpinData;
-
- //----------------------------------------------------------------------------------
- // Function prototypes
- //----------------------------------------------------------------------------------
-
- static void doInit (ControlHandle theControl, short varCode);
- static void doDisp (ControlHandle theControl);
- static long doTest (ControlHandle theControl, short varCode, long param);
- static void updateValue (ControlHandle theControl, short partCode);
- static void makePolys (ControlHandle theControl, short varCode);
- static void doDraw (ControlHandle theControl, short varCode);
- static void drawArrows (ControlHandle theControl, short varCode, short partCode,
- Boolean inactive, Boolean inColor);
- static void getRects (ControlHandle theControl, short varCode, Rect r1[]);
- static void accelerate (ControlHandle theControl);