source: branches/2.20_branch/NewView/HelpWindowUnit.pas@ 443

Last change on this file since 443 was 33, checked in by RBRi, 19 years ago

more uses cleanup

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