home *** CD-ROM | disk | FTP | other *** search
- unit DlogStuff; {this is a subset of my generic DlogStuff Unit}
- interface
- uses
- PrintTraps, Quickdraw, Picker, Palettes, globs;
-
- procedure DoMessage (mes0: str255; mes1: str255; mes2: str255; mes3: str255);
-
- procedure CenterDLOG (theDlog: DialogPtr);
- procedure DrawDefaultBtn (theItem: integer; thisDlog: DialogPtr);
- procedure ClickButton (Dptr: DialogPtr; ItemNo: integer);
-
- procedure PushRadioButton (theDlog: dialogPtr; item, first, last: integer);
- procedure CheckABox (theDlog: dialogPtr; ItemNum: integer; HighLite: boolean);
- procedure TrackScroll (theControl: ControlHandle; partCode: Integer);
-
- procedure WriteLabel (theStr: Str255; theRect: rect; toTheRight: boolean);
-
- function String2Int (theStr: str255): integer;
- function Int2String (theInt: integer): str255;
-
- implementation
-
-
- {======================================================================================= }
- {This procedure assumes that you have called New Dialog or GetNewDialog and}
- {the dialog is still invisible. Further, it assumes that the upper-left corner }
- {coordinates of the dialog are at 0,0, that the dialog's dimensions do not exceed}
- {that of the screen, and the there is a global value which delineates the height}
- {of the menu bar. If all of the preceeding is true, this procedure will center}
- {the dialog horizontally, and 1/3 of the way down from the bottom of the menu}
- {bar vertically. Note that vertical positioning does not take into account any of}
- {a dialog's structure region; it only centers on the 'draw-able' portRect.}
- procedure CenterDLOG; {(theDlog: DialogPtr)}
- var
- offSet: point;
- begin
- offSet.h := (ScreenBits.bounds.right - theDlog^.portRect.right) div 2;
- offSet.v := gdh^^.MenuHeight + (ScreenBits.bounds.bottom - theDlog^.portRect.bottom) div 3;
-
- MoveWindow(theDlog, offSet.h, offSet.v, true);
- end;
- {======================================================================================= }
- procedure DoMessage; {(mes0 : str255;mes1 : str255; mes2 : str255;mes3 : str255);}
- const
- MessageDialog = 258;
- var
- dialogP: DialogPtr;
- item: integer;
- begin
- ParamText(mes0, mes1, mes2, mes3);
- dialogP := GetNewDialog(MessageDialog, nil, pointer(-1));
- if dialogP = nil then
- begin
- SysBeep(5);
- ExitToShell;
- end;
- CenterDLOG(dialogP);
- ShowWindow(dialogP);
- InitCursor;
- ModalDialog(nil, item);
- DisposDialog(dialogP);
- end; {DoMessage}
-
-
- {======================================================================================= }
- procedure DrawDefaultBtn; {(theItem : integer; thisDlog : DialogPtr);}
- var
- OptType: Integer;
- OptBox: Rect;
- ItemHdl: Handle;
- oldDlog: DialogPtr;
-
- begin
- GetPort(oldDlog);
- SetPort(thisDlog);{ set window to current graf port }
- {Note: GetDItem gets info about dialogs}
- GetDItem(thisDlog, theItem, OptType, ItemHdl, OptBox); { get item location }
- Pensize(3, 3); { no wimpy outlines here }
- InsetRect(OptBox, -4, -4); { set rectangle around button }
- FrameRoundRect(OptBox, 16, 16); { draw the sucker! }
- PenSize(1, 1); { reset the PenSize}
- SetPort(oldDlog); { RESET to the original port}
- end; { of proc DrawDefaultBtn }
-
- {======================================================================================= }
- procedure ClickButton; {(Dptr : DialogPtr; ItemNo : integer);}
- { Inside Macintosh leaves out the fact that if you use a filter procedure }
- {in the ModalDialog call you need to simulate a clicking of the OK button when }
- {the return key is hit. This one of two possible techniques where we directly }
- {highlight and unhighlight the button. The other technique would be to add a }
- {mouse down event to the event queue in which the mouse coordinates are }
- {somewhere inside of the OK button. JWIND}
-
- var
- IType: integer;
- ButtonHandle: Handle;
- Box: rect;
- L: LongInt;
-
- begin
- GetDItem(Dptr, ItemNo, IType, ButtonHandle, Box);
- HiliteControl(ControlHandle(ButtonHandle), 253);
- Delay(8, L);
- HiliteControl(ControlHandle(ButtonHandle), 0);
- end; { ClickButton }
-
- {======================================================================================= }
- procedure PushRadioButton; {(theDlog : dialogPtr; item, first, last : integer)}
-
- var
- index: integer; {index through the loop}
- itemtype: integer; {the dialog items type}
- itemhandle: handle; {the dialog items handle}
- itemrect: rect; {the dialog items rect}
- itemcntlhand: controlhandle; {we convert the items handle to a cntl handle}
-
- begin
- for index := first to last do {do it for all items in the group}
- begin
- GetDItem(theDlog, index, itemtype, itemhandle, itemrect); {get the handle}
- itemcntlhand := controlhandle(itemhandle); {convert it to a cntl handle}
- if (index = item) then
- begin
- SetCtlValue(itemcntlhand, 1); {hilite the control}
- end
- else
- SetCtlValue(itemcntlhand, 0); {unlilite the control}
- end;
- end;
-
- {======================================================================================= }
- procedure CheckABox;{(theDlog:dialogPtr; ItemNum : integer;HighLite : boolean);}
- var
- itemtype: integer; {the dialog items type}
- itemhandle: handle; {the dialog items handle}
- itemrect: rect; {the dialog items rect}
- itemcntlhand: controlhandle; {we convert the items handle to a cntl handle}
-
- begin
- GetDItem(theDlog, ItemNum, itemtype, itemhandle, itemrect); {get the handle}
- itemcntlhand := controlhandle(itemhandle); {convert it to a cntl handle}
- if HighLite then
- begin
- SetCtlValue(itemcntlhand, 1); {hilite the control}
- end
- else
- begin
- SetCtlValue(itemcntlhand, 0); {unlilite the control}
- end;
- end;
-
- {======================================================================================= }
- procedure TrackScroll; {(theControl: ControlHandle; partCode: Integer)}
- var
- min, max, amount, startValue: Integer;
- up: Boolean;
- begin
- up := partcode in [inUpButton, inPageUp];
- min := GetCtlMin(theControl);
- max := GetCtlMax(theControl);
- startValue := GetCtlValue(theControl);
- if ((up and (startValue > min)) or ((not up) and (startValue < max))) and (partCode <> 0) then
- begin
- if up then
- amount := -1
- else
- amount := 1;
- if partCode in [inPageUp, inPagedown] then
- amount := round(amount * 2)
- else
- amount := round(amount * 1);
- SetCtlValue(theControl, amount + startValue);
- end;
- end; {of TrackScroll}
-
- {======================================================================================= }
- {write a label, to the right or left of a rectangle}
- procedure WriteLabel; {(theStr: Str255; theRect: rect; toTheRight: boolean);}
- const
- vertOff = 4;
- horizOff = 6;
- var
- aHandle: handle;
- aPt: point;
- begin
- with theRect do
- if ToTheRight then
- begin
- SetPt(aPt, right + horizOff, bottom - vertOff);
- left := right + 1;
- right := right + (StringWidth(theStr) + horizOff + 8);
- end
- else {it's to the left}
- begin
- SetPt(aPt, left - (horizOff + StringWidth(theStr)), bottom - vertOff);
- right := left - 4;
- left := left - (StringWidth(theStr) + horizOff + 8);
- end;{if ToTheRight…}
- EraseRect(theRect);
- MoveTo(aPt.h, aPt.v);
- WriteDraw(theStr);
- end;{WriteLabel}
-
- {======================================================================================= }
- function String2Int;{(theStr) : integer;}
- var
- aLongInt: longint;
- begin
- StringToNum(theStr, aLongInt);
- if aLongInt > maxInt then
- begin
- DoMessage('That number is too big.', 'It must be less than 32767', '', '');
- aLongInt := 0;
- end;
- String2Int := aLongInt;
- end;{String2Int}
-
- {======================================================================================= }
- function Int2String; {(theInt) : str255;}
- var
- aLongInt: longint;
- aStr: str255;
- begin
- aLongInt := theInt;
- NumToString(aLongInt, aStr);
- Int2String := aStr;
- end;{String2Int}
- end. {DlogStuff unit}