1 | Unit HelpWindowUnit;
|
---|
2 |
|
---|
3 | // NewView - a new OS/2 Help Viewer
|
---|
4 | // Copyright 2003 Aaron Lawrence (aaronl at consultant dot com)
|
---|
5 | // This software is released under the Gnu Public License - see readme.txt
|
---|
6 |
|
---|
7 | Interface
|
---|
8 |
|
---|
9 | uses
|
---|
10 | Classes, Forms, Buttons, Graphics, Messages,
|
---|
11 | RichTextView,
|
---|
12 | HelpTopic, HelpWindowDimensions;
|
---|
13 |
|
---|
14 | type
|
---|
15 | THelpWindow = class;
|
---|
16 |
|
---|
17 | THelpWindowCloseEvent = procedure( Window: THelpWindow ) of Object;
|
---|
18 | THelpWindowCloseQueryEvent = procedure( Window: THelpWindow;
|
---|
19 | Var CanClose: boolean ) of Object;
|
---|
20 |
|
---|
21 | // A window containing a topic.
|
---|
22 | THelpWindow = class
|
---|
23 | protected
|
---|
24 | FForm: TForm;
|
---|
25 |
|
---|
26 | FView: TRichTextView;
|
---|
27 |
|
---|
28 | FImages: TImageList;
|
---|
29 |
|
---|
30 | FTopic: TTopic; // the topic being displayed
|
---|
31 | FGroup: longint; // IPF group number currently assigned
|
---|
32 | // Set by either topic's contents group index,
|
---|
33 | // OR by a link group index
|
---|
34 |
|
---|
35 | FChildWindows: TList; // Windows within this one. Rarely used. (e.g. OS2UG)
|
---|
36 | FDependentWindows: TList; // windows to close when this one closes
|
---|
37 | // NOT the same as child windows
|
---|
38 | // * Not yet implemented *
|
---|
39 | FRect: THelpWindowRect;
|
---|
40 |
|
---|
41 | FParentHelpWindow: THelpWindow;
|
---|
42 |
|
---|
43 | protected
|
---|
44 | FOnClose: THelpWindowCloseEvent;
|
---|
45 | FOnCloseQuery: THelpWindowCloseQueryEvent;
|
---|
46 | FOnDragOver: TDragOverEvent;
|
---|
47 | FOnDragDrop: TDragDropEvent;
|
---|
48 | FOnFontChange: TNotifyEvent;
|
---|
49 | FOnTab: TNotifyEvent;
|
---|
50 | FOnBackTab: TNotifyEvent;
|
---|
51 |
|
---|
52 | protected
|
---|
53 | procedure OnResize( Sender: TObject );
|
---|
54 |
|
---|
55 | function GetParent: TControl;
|
---|
56 | procedure SetParent( NewValue: TControl );
|
---|
57 |
|
---|
58 | procedure SetVisible( NewValue: boolean );
|
---|
59 | function GetVisible: boolean;
|
---|
60 |
|
---|
61 | procedure SetCaption( const NewValue: string );
|
---|
62 | function GetCaption: string;
|
---|
63 |
|
---|
64 | procedure OnFormClose( Sender: TObject;
|
---|
65 | Action: TCloseAction );
|
---|
66 | procedure OnFormCloseQuery( Sender: TObject;
|
---|
67 | Var CanClose: boolean );
|
---|
68 |
|
---|
69 | procedure OnDragOverView( Sender: TObject;
|
---|
70 | Source: TObject;
|
---|
71 | X ,Y: LongInt;
|
---|
72 | State: TDragState;
|
---|
73 | Var Accept: Boolean );
|
---|
74 | procedure OnDragDropToView( Sender: TObject;
|
---|
75 | Source: TObject;
|
---|
76 | X, Y: LongInt );
|
---|
77 | procedure OnViewFontChange( Sender: TObject );
|
---|
78 | procedure OnViewScan( Sender: TObject;
|
---|
79 | var KeyCode: TKeyCode );
|
---|
80 |
|
---|
81 | public
|
---|
82 |
|
---|
83 | constructor Create( ShowBorder: boolean );
|
---|
84 | destructor Destroy; override;
|
---|
85 |
|
---|
86 | procedure SetLayout;
|
---|
87 | procedure SetupRTView;
|
---|
88 |
|
---|
89 | function GetMaster: TControl;
|
---|
90 |
|
---|
91 | procedure BringToFront;
|
---|
92 |
|
---|
93 | procedure Show;
|
---|
94 |
|
---|
95 | property Caption: string read GetCaption write SetCaption;
|
---|
96 |
|
---|
97 | property Parent: TControl read GetParent write SetParent;
|
---|
98 | property Visible: boolean read GetVisible write SetVisible;
|
---|
99 |
|
---|
100 | property OnClose: THelpWindowCloseEvent read FOnClose write FOnClose;
|
---|
101 | property OnCloseQuery: THelpWindowCloseQueryEvent read FOnCloseQuery write FOnCloseQuery;
|
---|
102 |
|
---|
103 | property OnDragOver: TDragOverEvent read FOnDragOver write FOnDragOver;
|
---|
104 | property OnDragDrop: TDragDropEvent read FOnDragDrop write FOnDragDrop;
|
---|
105 |
|
---|
106 | property OnFontChange: TNotifyEvent read FOnFontChange write FOnFontChange;
|
---|
107 |
|
---|
108 | property OnTab: TNotifyEvent read FOnTab write FOnTab;
|
---|
109 | property OnBackTab: TNotifyEvent read FOnBackTab write FOnBackTab;
|
---|
110 |
|
---|
111 | property View: TRichTextView read FView;
|
---|
112 | property Images: TImageList read FImages;
|
---|
113 |
|
---|
114 | property Topic: TTopic read FTopic write FTopic;
|
---|
115 | property Group: longint read FGroup write FGroup;
|
---|
116 |
|
---|
117 | property ChildWindows: TList read FChildWindows;
|
---|
118 | property DependentWindows: TList read FDependentWindows;
|
---|
119 | property Rect: THelpWindowRect read FRect write FRect;
|
---|
120 |
|
---|
121 | property ParentHelpWindow: THelpWindow read FParentHelpWindow write FParentHelpWindow;
|
---|
122 |
|
---|
123 | public
|
---|
124 | Highlights: TList; // list of indexes into text of highlighted entries
|
---|
125 | end;
|
---|
126 |
|
---|
127 | var
|
---|
128 | g_TopicIcon: TIcon;
|
---|
129 |
|
---|
130 | Implementation
|
---|
131 |
|
---|
132 | uses
|
---|
133 | OS2Def, PmWin,
|
---|
134 | SysUtils,
|
---|
135 | Forms, ExtCtrls, StdCtrls,
|
---|
136 | ACLUtility,
|
---|
137 | RichTextStyleUnit, ControlsUtility,
|
---|
138 | SettingsUnit;
|
---|
139 |
|
---|
140 | {$R Images}
|
---|
141 |
|
---|
142 | constructor THelpWindow.Create( ShowBorder: boolean );
|
---|
143 | begin
|
---|
144 | inherited Create;
|
---|
145 |
|
---|
146 | FForm := nil;
|
---|
147 |
|
---|
148 | FView := TRichTextView.Create( nil );
|
---|
149 |
|
---|
150 | if ShowBorder then
|
---|
151 | begin
|
---|
152 | FForm := TForm.Create( nil );
|
---|
153 | FForm.Name := 'HelpWindowForm';
|
---|
154 | FForm.Visible := false;
|
---|
155 | FForm.FormStyle := fsMDIChild;
|
---|
156 | Exclude( FForm.BorderIcons, biMinimize );
|
---|
157 |
|
---|
158 | FForm.Tag := longint( self );
|
---|
159 |
|
---|
160 | FForm.Parent := Parent;
|
---|
161 |
|
---|
162 | FForm.OnClose := OnFormClose;
|
---|
163 | FForm.OnCloseQuery := OnFormCloseQuery;
|
---|
164 | FForm.OnResize := OnResize;
|
---|
165 |
|
---|
166 | FView.Parent := FForm;
|
---|
167 | FView.Align := alClient;
|
---|
168 |
|
---|
169 | FView.TabOrder := 0;
|
---|
170 | FView.Visible := true;
|
---|
171 | end
|
---|
172 | else
|
---|
173 | begin
|
---|
174 | FView.Parent := Parent;
|
---|
175 | FView.Visible := false;
|
---|
176 | end;
|
---|
177 |
|
---|
178 | FView.OnDragOver := OnDragOverView;
|
---|
179 | FView.OnDragDrop := OnDragDropToView;
|
---|
180 | FView.OnFontChange := OnViewFontChange;
|
---|
181 | FView.OnScan := OnViewScan;
|
---|
182 |
|
---|
183 | SetupRTView;
|
---|
184 |
|
---|
185 | FRect := THelpWindowRect.Create;
|
---|
186 |
|
---|
187 | FImages := TImageList.Create( Parent );
|
---|
188 |
|
---|
189 | FChildWindows := TList.Create;
|
---|
190 |
|
---|
191 | FDependentWindows := TList.Create;
|
---|
192 |
|
---|
193 | Highlights := TList.Create;
|
---|
194 | end;
|
---|
195 |
|
---|
196 | destructor THelpWindow.Destroy;
|
---|
197 | begin
|
---|
198 | FImages.Destroy;
|
---|
199 | DestroyListObjects( FChildWindows );
|
---|
200 | FChildWindows.Destroy;
|
---|
201 | FRect.Destroy;
|
---|
202 | FDependentWindows.Destroy;
|
---|
203 | FView.Destroy;
|
---|
204 | if FForm <> nil then
|
---|
205 | FForm.Destroy;
|
---|
206 | Highlights.Destroy;
|
---|
207 | inherited Destroy;
|
---|
208 | end;
|
---|
209 |
|
---|
210 | procedure THelpWindow.OnFormClose( Sender: TObject;
|
---|
211 | Action: TCloseAction );
|
---|
212 | begin
|
---|
213 | if Assigned( FOnClose ) then
|
---|
214 | FOnClose( self );
|
---|
215 | Action := caFree; // make form free itself and what it owns...
|
---|
216 | FForm := nil ;// so we don't destroy it in destructor
|
---|
217 | Destroy; // destroy ourselves
|
---|
218 | end;
|
---|
219 |
|
---|
220 | procedure THelpWindow.OnFormCloseQuery( Sender: TObject;
|
---|
221 | Var CanClose: boolean );
|
---|
222 | begin
|
---|
223 | if Assigned( FOnCloseQuery ) then
|
---|
224 | FOnCloseQuery( self, CanClose );
|
---|
225 | end;
|
---|
226 |
|
---|
227 | procedure THelpWindow.OnDragOverView( Sender: TObject;
|
---|
228 | Source: TObject;
|
---|
229 | X, Y: LongInt;
|
---|
230 | State: TDragState;
|
---|
231 | Var Accept: Boolean );
|
---|
232 |
|
---|
233 | begin
|
---|
234 | if Assigned( FOnDragOver ) then
|
---|
235 | FOnDragOver( Sender, Source, X, Y, State, Accept );
|
---|
236 | end;
|
---|
237 |
|
---|
238 | procedure THelpWindow.OnDragDropToView( Sender: TObject;
|
---|
239 | Source: TObject;
|
---|
240 | X, Y: LongInt );
|
---|
241 |
|
---|
242 | begin
|
---|
243 | if Assigned( FOnDragDrop ) then
|
---|
244 | FOnDragDrop( Sender, Source, X, Y );
|
---|
245 | end;
|
---|
246 |
|
---|
247 | procedure THelpWindow.OnViewFontChange( Sender: TObject );
|
---|
248 | begin
|
---|
249 | if Assigned( FOnFontChange ) then
|
---|
250 | FOnFontChange( Sender );
|
---|
251 | end;
|
---|
252 |
|
---|
253 | procedure THelpWindow.OnViewScan( Sender: TObject;
|
---|
254 | var KeyCode: TKeyCode );
|
---|
255 | begin
|
---|
256 | if KeyCode = kbTab then
|
---|
257 | begin
|
---|
258 | // see if view wants to handle
|
---|
259 | if FView.HighlightNextLink then
|
---|
260 | begin
|
---|
261 | KeyCode := kbNull;
|
---|
262 | end
|
---|
263 | else if FOnTab <> nil then
|
---|
264 | begin
|
---|
265 | KeyCode := kbNull;
|
---|
266 | FOnTab( self );
|
---|
267 | end;
|
---|
268 | end;
|
---|
269 |
|
---|
270 | if KeyCode = kbShiftTab then
|
---|
271 | begin
|
---|
272 | if FView.HighlightPreviousLink then
|
---|
273 | begin
|
---|
274 | KeyCode := kbNull;
|
---|
275 | end
|
---|
276 | else if FOnBackTab <> nil then
|
---|
277 | begin
|
---|
278 | KeyCode := kbNull;
|
---|
279 | FOnBackTab( self );
|
---|
280 | end;
|
---|
281 | end;
|
---|
282 | end;
|
---|
283 |
|
---|
284 | function THelpWindow.GetMaster: TControl;
|
---|
285 | begin
|
---|
286 | if FForm <> nil then
|
---|
287 | Result := FForm
|
---|
288 | else
|
---|
289 | Result := FView;
|
---|
290 | end;
|
---|
291 |
|
---|
292 | function THelpWindow.GetParent: TControl;
|
---|
293 | begin
|
---|
294 | Result := GetMaster.Parent;
|
---|
295 | end;
|
---|
296 |
|
---|
297 | procedure THelpWindow.SetParent( NewValue: TControl );
|
---|
298 | begin
|
---|
299 | GetMaster.Parent := NewValue;
|
---|
300 | end;
|
---|
301 |
|
---|
302 | procedure THelpWindow.SetVisible( NewValue: boolean );
|
---|
303 | begin
|
---|
304 | GetMaster.Visible := NewValue;
|
---|
305 | end;
|
---|
306 |
|
---|
307 | function THelpWindow.GetVisible: boolean;
|
---|
308 | begin
|
---|
309 | Result := GetMaster.Visible;
|
---|
310 | end;
|
---|
311 |
|
---|
312 | procedure THelpWindow.SetCaption( const NewValue: string );
|
---|
313 | begin
|
---|
314 | if Assigned( FForm ) then
|
---|
315 | FForm.Caption := NewValue;
|
---|
316 | end;
|
---|
317 |
|
---|
318 | function THelpWindow.GetCaption: string;
|
---|
319 | begin
|
---|
320 | if Assigned( FForm ) then
|
---|
321 | Result := FForm.Caption
|
---|
322 | else
|
---|
323 | Result := '';
|
---|
324 | end;
|
---|
325 |
|
---|
326 | procedure THelpWindow.BringToFront;
|
---|
327 | begin
|
---|
328 | GetMaster.BringToFront;
|
---|
329 | end;
|
---|
330 |
|
---|
331 | procedure THelpWindow.Show;
|
---|
332 | begin
|
---|
333 | GetMaster.Show;
|
---|
334 | if FForm <> nil then
|
---|
335 | FForm.Icon := g_TopicIcon;
|
---|
336 | end;
|
---|
337 |
|
---|
338 | // Setup the rich text control
|
---|
339 | procedure THelpWindow.SetupRTView;
|
---|
340 | begin
|
---|
341 | FView.UseDefaultMenu := false;
|
---|
342 | FView.Color := Settings.Colors[ TopicBackgroundColorIndex ];
|
---|
343 | FView.SmoothScroll := Settings.SmoothScrolling;
|
---|
344 |
|
---|
345 | with FView.RichTextSettings do
|
---|
346 | begin
|
---|
347 | BeginUpdate;
|
---|
348 | NormalFont := Settings.NormalFont;
|
---|
349 | FixedFont := Settings.FixedFont;
|
---|
350 | Margins := Forms.Rect( 5, 10, 5, 10 );
|
---|
351 | AtLeastOneWordBeforeWrap := true; // not sure
|
---|
352 | DefaultBackgroundColor := Settings.Colors[ TopicBackgroundColorIndex ];
|
---|
353 | DefaultColor := clBlack;
|
---|
354 | MarginSizeStyle := msAverageCharWidth;
|
---|
355 | EndUpdate;
|
---|
356 | end;
|
---|
357 | end;
|
---|
358 |
|
---|
359 | procedure THelpWindow.SetLayout;
|
---|
360 | var
|
---|
361 | X, Y: longint;
|
---|
362 | W, H: longint;
|
---|
363 | Maximize: boolean;
|
---|
364 | begin
|
---|
365 | // Position the window correctly.
|
---|
366 |
|
---|
367 | W:= FRect.Width * Parent.ClientWidth div 100;
|
---|
368 | H:= FRect.Height * Parent.ClientHeight div 100;
|
---|
369 |
|
---|
370 | if FRect.Left = XYPosCenter then
|
---|
371 | X:= Parent.ClientWidth div 2 - W div 2
|
---|
372 | else if FRect.Left = XPosRight then
|
---|
373 | X:= Parent.ClientWidth - W
|
---|
374 | else
|
---|
375 | X:= FRect.Left * Parent.ClientWidth div 100;
|
---|
376 |
|
---|
377 | if FRect.Bottom = XYPosCenter then
|
---|
378 | Y:= Parent.ClientHeight div 2 - H div 2
|
---|
379 | else if FRect.Bottom = YPosTop then
|
---|
380 | Y:= Parent.ClientHeight - H
|
---|
381 | else
|
---|
382 | Y:= FRect.Bottom * Parent.ClientHeight div 100;
|
---|
383 |
|
---|
384 | // If this window is set to use the whole screen (exactly)
|
---|
385 | // then we maximize it.
|
---|
386 | Maximize :=
|
---|
387 | ( X = 0 )
|
---|
388 | and ( y = 0 )
|
---|
389 | and ( FRect.Width = 100 )
|
---|
390 | and ( FRect.height = 100 );
|
---|
391 |
|
---|
392 | if FForm <> nil then
|
---|
393 | SmartSetWindowPos( FForm,
|
---|
394 | X, Y, W, H,
|
---|
395 | Maximize )
|
---|
396 | else
|
---|
397 | FView.SetWindowPos( X, Y, W, H );
|
---|
398 | end;
|
---|
399 |
|
---|
400 | procedure THelpWindow.OnResize( Sender: TObject );
|
---|
401 | var
|
---|
402 | Child: THelpWindow;
|
---|
403 | ChildIndex: longint;
|
---|
404 | begin
|
---|
405 | for ChildIndex := 0 to FChildWindows.Count - 1 do
|
---|
406 | begin
|
---|
407 | Child := FChildWindows[ ChildIndex ];
|
---|
408 | Child.SetLayout;
|
---|
409 | end;
|
---|
410 | end;
|
---|
411 |
|
---|
412 | Initialization
|
---|
413 |
|
---|
414 | // create topic icon global
|
---|
415 | g_TopicIcon := TIcon.Create;
|
---|
416 | // load icon from resource
|
---|
417 | g_TopicIcon.LoadFromResourceName( 'TopicIcon' );
|
---|
418 |
|
---|
419 | Finalization
|
---|
420 | g_TopicIcon.Destroy;
|
---|
421 |
|
---|
422 | End.
|
---|