home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-08 | 6.6 KB | 275 lines | [TEXT/CWIE] |
- {
- I don't remember where I found this, but it was an old MPW Pascal program which has
- been completely refurbished to run native in CW7.
-
- It primarily demonstrates the use of the dialog manager. The dialog it displays includes
- editable fields, pop-ups, pop-ups with submenus, pop-ups with editable text, pop-ups which
- display at a mouseDown location, disabling buttons, etc., etc...
-
- Original author unknown.
-
- Changes made 12/5/95 by Bill Catambay, catambay@aol.com
- }
-
- Program PopUpTest;
-
- USES
- QuickDraw, Types, Events, Menus, OSUtils, Fonts, Windows, Resources,
- ToolUtils, Sound, Palettes, Memory, Dialogs, Devices, Processes, TextEdit;
-
- const
- dialogID = 128;
- firstMenu = 2; {item numbers}
- secondMenu = 3;
- hideSecond = 4;
- disableControl = 5;
- disableMenu = 6;
- resetMenu = 7;
- speedLabel = 8;
- speedMenu = 10;
- ctlTitleMenu = 11;
- altCTitle = 12;
- invisibleMenu = 13;
- frameItem = 14;
- emptyMenu = 15;
- reportItem = 16;
-
- type
- popupPrivateData = record
- mHandle: MenuHandle;
- mID: Integer;
- end;
- popupPrivateDataPtr = ^popupPrivateData;
- popupPrivateDataHdl = ^popupPrivateDataPtr;
-
- var
- theDialog: DialogPtr;
- itemHit: Integer;
- i: Integer;
- theEvent: EventRecord;
- pt: Point;
-
- Procedure Initialize;
-
- VAR
- theWorld: SysEnvRec;
- error: OSErr;
-
- BEGIN
- error := SysEnvirons(1, theWorld);
- IF NOT theWorld.hasColorQD THEN
- BEGIN
- SysBeep (50);
- ExitToShell;
- END;
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(NIL);
- InitCursor;
- END; { Initialize }
-
-
- function GetControlHandle (item: Integer): ControlHandle;
-
- var
- kind: Integer;
- h: Handle;
- r: Rect;
-
- begin
- GetDialogItem(theDialog, item, kind, h, r);
- if BAND(kind, $FC) = ctrlItem then
- GetControlHandle := ControlHandle(h)
- else
- GetControlHandle := nil;
- end;
-
- Function FilterProc (dlg: DialogPtr; var evt: EventRecord; var itemHit: Integer): Boolean;
-
- begin
- FilterProc := False;
- theEvent := evt;
- end;
-
- procedure DrawFrame (theWindow: WindowPtr; itemNo: Integer);
-
- var
- itemType: Integer;
- itemHandle: Handle;
- itemRect: Rect;
-
- begin
- PenNormal;
- GetDialogItem(theWindow, itemNo, itemType, itemHandle, itemRect);
- FrameRect(itemRect);
- end;
-
- procedure ReportControl (theDialog: DialogPtr; item: Integer);
-
- var
- aString: Str255;
- value: Integer;
- hiByte: Integer;
- mString: Str255;
- loByte: Integer;
- iString: Str255;
- itemKind: Integer;
- itemHandle: Handle;
- itemRect: Rect;
- itemRgn: RgnHandle;
-
- begin
- NumToString(item, aString);
- value := GetControlValue(GetControlHandle(item));
- hiByte := BSR(value, 8);
- loByte := BAND(value, $FF);
- NumToString(hiByte, mString);
- NumToString(loByte, iString);
- ParamText(aString, mString, iString, '');
- GetDialogItem(theDialog, reportItem, itemKind, itemHandle, itemRect);
- itemRgn := NewRgn;
- RectRgn(itemRgn, itemRect);
- UpdateDialog(theDialog, itemRgn);
- DisposeRgn(itemRgn);
- end;
-
- procedure RecursiveGetMenu (menuH: MenuHandle);
-
- var
- i: Integer;
- cmd, mark: Char;
-
- begin
- if menuH <> nil then
- begin
- InsertMenu(menuH, -1);
- for i := 1 to CountMItems(menuH) do
- begin
- GetItemMark(menuH, i, mark);
- GetItemCmd(menuH, i, cmd);
- if cmd = CHR($1B) then
- RecursiveGetMenu(GetMenu(ORD(mark)));
- end;
- end;
- end;
-
- function GetDPopUpMenuID (item: Integer): integer;
-
- begin
- GetDPopUpMenuID := popupPrivateDataHdl(GetControlHandle(item)^^.contrlData)^^.mID;
- end;
-
- procedure GetDPopUpMenu (item: Integer);
-
- var
- menuID: Integer;
- menuH: MenuHandle;
-
- begin
- menuID := GetDPopUpMenuID(item);
- menuH := GetMenu(menuID);
- RecursiveGetMenu(menuH);
- end;
-
- Var
- DrawFrame_UPP: UserItemUPP;
- FilterProc_UPP: ModalFilterUPP;
- itemType: Integer;
- itemHandle: Handle;
- itemRect: Rect;
-
- begin
- initialize;
- DrawFrame_UPP := NewUserItemProc(@DrawFrame);
- FilterProc_UPP := NewModalFilterProc(@FilterProc);
- theDialog := GetNewDialog(dialogID, nil, POINTER(-1));
- SetPort(theDialog);
- GetDPopUpMenu(firstMenu);
- GetDPopUpMenu(secondMenu);
- GetDPopUpMenu(speedMenu);
- AppendMenu(GetMenu(GetDPopUpMenuID(speedMenu)), '123');
- AppendMenu(GetMenu(GetDPopUpMenuID(speedMenu)), '456');
- GetDPopUpMenu(ctlTitleMenu);
- GetDPopUpMenu(invisibleMenu);
- GetDPopUpMenu(emptyMenu);
- GetDialogItem(theDialog, frameitem, itemType, itemHandle, itemRect);
- SetDialogItem(theDialog, frameitem, itemType,Handle(Drawframe_UPP), itemRect);
- TextFont(geneva);
- TextSize(9);
- ShowWindow(theDialog);
- for i := 1 to 3 do
- if EventAvail(everyEvent, theEvent) then ;
- with DialogPeek(theDialog)^.textH^^ do
- begin
- txFont := theDialog^.txFont;
- txSize := theDialog^.txSize;
- end;
- repeat
- ModalDialog(FilterProc_UPP, itemHit);
- case itemHit of
- firstMenu,
- secondMenu,
- speedMenu,
- ctlTitleMenu,
- emptyMenu: ReportControl(theDialog, itemHit);
-
- frameItem: begin
- pt := theEvent.where;
- GlobalToLocal(pt);
- MoveControl(GetControlHandle(invisibleMenu), pt.h, pt.v);
- i := TrackControl(GetControlHandle(invisibleMenu), pt, POINTER(-1));
- ReportControl(theDialog, invisibleMenu);
- end;
-
- hideSecond: begin
- SetControlValue(GetControlHandle(hideSecond), 1 - GetControlValue(GetControlHandle(hideSecond)));
- if GetControlValue(GetControlHandle(hideSecond)) = 1 then
- HideControl(GetControlHandle(secondMenu))
- else
- ShowControl(GetControlHandle(secondMenu));
- end;
-
- disableControl:
- begin
- SetControlValue(GetControlHandle(disableControl), 1 - GetControlValue(GetControlHandle(disableControl)));
- if GetControlValue(GetControlHandle(disableControl)) = 1 then
- HiliteControl(GetControlHandle(secondMenu), 255)
- else
- HiliteControl(GetControlHandle(secondMenu), 0);
-
- if GetControlValue(GetControlHandle(disableControl)) = 1 then
- HiliteControl(GetControlHandle(speedMenu), 255)
- else
- HiliteControl(GetControlHandle(speedMenu), 0);
- end;
-
- disableMenu:begin
- SetControlValue(GetControlHandle(disableMenu), 1 - GetControlValue(GetControlHandle(disableMenu)));
- if GetControlValue(GetControlHandle(disableMenu)) = 1 then
- DisableItem(GetMenu(GetDPopUpMenuID(secondMenu)), 0)
- else
- EnableItem(GetMenu(GetDPopUpMenuID(secondMenu)), 0);
- Draw1Control(GetControlHandle(secondMenu)); {Control manager has to be informed…}
- end;
-
- resetMenu: begin
- SetControlValue(GetControlHandle(secondMenu), 3);
- ReportControl(theDialog, secondMenu);
- end;
-
- altCTitle: begin
- SetControlValue(GetControlHandle(altCTitle), 1 - GetControlValue(GetControlHandle(altCTitle)));
- if GetControlValue(GetControlHandle(altCTitle)) = 0 then
- SetControlTitle(GetControlHandle(ctlTitleMenu), 'T1:')
- else
- SetControlTitle(GetControlHandle(ctlTitleMenu), 'Alt T2:');
- end;
-
- otherwise ;
- {CASE} end;
- until ItemHit = OK;
- DisposeDialog(theDialog);
- end.