home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-25 | 5.6 KB | 240 lines | [TEXT/CWIE] |
- unit MultiSkelHelp;
-
- interface
-
- uses
- Types, MixedMode, Memory, Resources, QuickDrawText, QuickDraw, Windows, Menus, Controls,
- TextEdit, TransSkel, MSkelGlobals;
-
- procedure HelpWindInit;
-
- implementation
-
- var
-
- teHelp: TEHandle;
- helpScroll: ControlHandle;
- helpLine: Integer;
- halfPage: Integer;
-
- trackProc: ControlActionUPP;
-
-
- procedure DoScroll (lDelta: Integer);
- var
- newLine: Integer;
- begin
- newLine := helpLine + lDelta;
- if (newLine < 0) then
- newLine := 0;
- if (newLine > GetControlMaximum(helpScroll)) then
- newLine := GetControlMaximum(helpScroll);
- SetControlValue(helpScroll, newLine);
- lDelta := (helpLine - newLine) * teHelp^^.lineHeight;
- TEScroll(0, lDelta, teHelp);
- helpLine := newLine;
- end;
-
-
- procedure TrackScroll (theScroll: ControlHandle;
- partCode: Integer);
- var
- lDelta: Integer;
- begin
- if (partCode = GetControlReference(theScroll)) then
- begin
- {$IFC OLDROUTINENAMES }
- case partCode of
- inUpButton:
- lDelta := -1;
- inDownButton:
- lDelta := 1;
- inPageUp:
- lDelta := -halfPage;
- inPageDown:
- lDelta := halfPage;
- end;
- {$ELSEC}
- case partCode of
- kControlUpButtonPart:
- lDelta := -1;
- kControlDownButtonPart:
- lDelta := 1;
- kControlPageUpPart:
- lDelta := -halfPage;
- kControlPageDownPart:
- lDelta := halfPage;
- end;
- {$ENDC}
- DoScroll(lDelta);
- end;
- end;
-
-
- procedure Mouse (pt: Point;
- t: LongInt;
- mods: Integer);
- var
- thePart: Integer;
- ignore: Integer;
- begin
- thePart := TestControl(helpScroll, pt);
- {$IFC OLDROUTINENAMES }
- if (thePart = inThumb) then
- {$ELSEC}
- if (thePart = kControlIndicatorPart) then
- {$ENDC}
- begin
- ignore := TrackControl(helpScroll, pt, nil);
- DoScroll(GetControlValue(helpScroll) - helpLine);
- end
- else if (thePart <> 0) then
- begin
- SetControlReference(helpScroll, thePart);
- ignore := TrackControl(helpScroll, pt, trackProc);
- end;
- end;
-
-
- procedure Update (resized: Boolean);
- var
- r: Rect;
- visLines: Integer;
- lHeight: Integer;
- topLines: Integer;
- nLines: Integer;
- scrollLines: Integer;
- begin
- r := helpWind^.portRect;
- EraseRect(r);
- if (resized) then
- begin
- r.left := r.left + 4;
- r.bottom := r.bottom - 2;
- r.top := r.top + 2;
- r.right := r.right - 19;
- teHelp^^.destRect.right := r.right;
- teHelp^^.viewRect := r;
- TECalText(teHelp);
- lHeight := teHelp^^.lineHeight;
- nLines := teHelp^^.nLines;
- visLines := (r.bottom - r.top) div lHeight;
- halfPage := visLines div 2;
- topLines := (r.top - teHelp^^.destRect.top) div lHeight;
- scrollLines := visLines - (nLines - topLines);
- if ((scrollLines > 0) and (topLines > 0)) then
- begin
- if (scrollLines > topLines) then
- scrollLines := topLines;
- TEScroll(0, scrollLines * lHeight, teHelp);
- end;
- scrollLines := nLines - visLines;
- helpLine := (r.top - teHelp^^.destRect.top) div lHeight;
- HideControl(helpScroll);
- r := helpWind^.portRect;
- r.left := r.right - 15;
- r.bottom := r.bottom - 14;
- r.top := r.top - 1;
- r.right := r.right + 1;
- SizeControl(helpScroll, r.right - r.left, r.bottom - r.top);
- MoveControl(helpScroll, r.left, r.top);
- if ((nLines - visLines) < 0) then
- SetControlMaximum(helpScroll, 0)
- else
- SetControlMaximum(helpScroll, nLines - visLines);
- SetControlValue(helpScroll, helpLine);
- ShowControl(helpScroll);
- end;
- DrawGrowBox(helpWind);
- DrawControls(helpWind);
- r := teHelp^^.viewRect;
- TEUpdate(r, teHelp);
- ValidRect(helpWind^.portRect);
- end;
-
-
- procedure Activate (active: Boolean);
- begin
- DrawGrowBox(helpWind);
- if (active) then
- begin
- DisableItem(editMenu, 0);
- if (GetControlMaximum(helpScroll) > 0) then
- HiliteControl(helpScroll, normalHilite)
- else
- HiliteControl(helpScroll, dimHilite);
- end
- else
- begin
- EnableItem(editMenu, 0);
- if (GetControlMaximum(helpScroll) > 0) then
- HiliteControl(helpScroll, dimHilite);
- end;
- DrawMenuBar;
- end;
-
-
- procedure Clobber;
- begin
- DisposeRoutineDescriptor (trackProc);
- TEDispose(teHelp);
- DisposeControl(helpScroll);
- DisposeWindow(helpWind);
- end;
-
-
- procedure HelpWindInit;
- var
- r: Rect;
- textHandle: Handle;
- visLines: Integer;
- scrollLines: Integer;
- ignore: Boolean;
- begin
- if (SkelQuery(skelQHasColorQD) <> 0) then
- helpWind := GetNewCWindow(helpWindRes, nil, WindowPtr(-1))
- else
- helpWind := GetNewWindow(helpWindRes, nil, WindowPtr(-1));
- if (helpWind = nil) then
- exit(HelpWindInit);
- ignore := SkelWindow(helpWind, @Mouse, nil, @Update, @Activate, nil, @Clobber, nil, false);
-
- TextFont(0);
- TextSize(0);
-
- r := helpWind^.portRect;
- r.left := r.left + 4;
- r.bottom := r.bottom - 2;
- r.top := r.top + 2;
- r.right := r.right - 19;
- teHelp := TENew(r, r);
- textHandle := GetResource('TEXT', helpTextRes);
- HLock(textHandle);
- TEInsert(textHandle^, GetHandleSize(textHandle), teHelp);
- HUnlock(textHandle);
- ReleaseResource(textHandle);
-
- visLines := (r.bottom - r.top) div teHelp^^.lineHeight;
- scrollLines := teHelp^^.nLines - visLines;
- halfPage := visLines div 2;
- helpLine := 0;
- r := helpWind^.portRect;
- r.left := r.right - 15;
- r.bottom := r.bottom - 14;
- r.top := r.top - 1;
- r.right := r.right + 1;
-
- helpScroll := NewControl(helpWind, r, '', true, helpLine, 0, scrollLines, scrollBarProc, 0);
-
- {
- Set up a variable to point to the scroll tracking procedure. For 68K code this
- is just a direct pointer to TrackScroll(). For PowerPC code it is a
- routine descriptor into which the address of TrackScroll() is stuffed.
- }
-
- trackProc := NewControlActionProc (@TrackScroll);
-
- ValidRect(helpWind^.portRect);
- end;
-
- end.