home *** CD-ROM | disk | FTP | other *** search
- /*
- * TestControl.c
- */
-
- #define ok 1
-
- typedef struct {
- int jump;
- long add;
- } defRec, *defPtr, **defHdl;
-
- defHdl theDef;
- Boolean DialogExists();
- Handle GetItemHandle();
-
- pascal long PopupMenu();
-
- main()
- {
- short id, i;
- DialogPtr dlog;
-
- FlushEvents (everyEvent - diskMask, 0 );
- InitGraf (&thePort);
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (nil); /* no restart proc */
- InitCursor ();
-
- theDef = (defHdl)GetResource('CDEF', 130);
- (**theDef).jump = 0x4ef9;
- (**theDef).add = (long)PopupMenu;
-
- if(!DialogExists(256))
- {
- SysBeep(3);
- return;
- }
-
- dlog = GetNewDialog(256, NULL, (WindowPtr) -1);
-
- PositionDialog(dlog);
-
- SetItemValue(dlog, 2, 1);
-
- ShowWindow(dlog);
-
- do
- {
- ModalDialog(NULL, &id);
- if(id == 2)
- {
- SetItemValue(dlog, 2, !GetItemValue(dlog, 2));
- HiliteItem(dlog, 3, GetItemValue(dlog, 2) ? 0 : 255);
- i = Random() % 7;
- i = Abs(i); /* macros require separate lines sometimes */
- if (i==0) i=1;
- if (i==3) i=4;
- SetItemValue(dlog, 3, i);
- }
- } while(id > ok);
-
- DisposDialog(dlog);
- ReleaseResource(theDef);
- }
-
- Handle GetItemHandle(dlog, item, type, rect)
- DialogPtr dlog;
- int item;
- short *type;
- Rect *rect;
- {
- Rect r;
- short t;
- Handle hand;
-
- if(!rect)
- rect = &r;
- if(!type)
- type = &t;
- GetDItem(dlog, item, type, &hand, rect);
-
- return hand;
- }
-
- GetItemValue(dlog, item)
- DialogPtr dlog;
- int item;
- {
- return GetCtlValue((ControlHandle)GetItemHandle(dlog, item, NIL, NIL));
- }
-
- SetItemValue(dlog, item, value)
- DialogPtr dlog;
- int item;
- {
- SetCtlValue((ControlHandle)GetItemHandle(dlog, item, NIL, NIL), value);
- }
-
- HiliteItem(dlog, item, value)
- DialogPtr dlog;
- int item;
- int value;
- {
- Rect rect;
- short type;
- Handle hand;
-
- hand = GetItemHandle(dlog, item, &type, &rect);
-
- type &= ~itemDisable;
- if((type & ~3) == ctrlItem)
- HiliteControl((ControlHandle)hand, value);
- }
-
- PositionDialog(dptr)
- DialogPtr dptr;
- {
- GrafPtr wPort;
- int hPos, vPos;
- Rect wRect, dRect;
-
- GetWMgrPort(&wPort);
- wRect = wPort->portRect;
- wRect.top += GetMBarHeight();
- dRect = dptr->portRect;
- hPos = (wRect.left + wRect.right + dRect.left - dRect.right) / 2;
- if(hPos < (wRect.left + 3))
- hPos = wRect.left + 3;
- vPos = (2 * wRect.top + wRect.bottom + dRect.top - dRect.bottom) / 3;
- if(vPos < (wRect.top + 3))
- vPos = wRect.top + 3;
- MoveWindow(dptr, hPos, vPos, false);
- }
-
- Boolean DialogExists(id)
- short id;
- {
- DialogTHndl hand;
- if(!(hand = (DialogTHndl) GetResource('DLOG', id)))
- return 0 != 0;
- return GetResource('DITL', (*hand)->itemsID) != 0;
- }
-