Menu

[r147]: / trunk / Src / FrDetailView.pas  Maximize  Restore  History

Download this file

473 lines (439 with data), 19.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
{
* FrDetailView.pas
*
* Abstract base class for frames that display content in the detail pane.
* Implements functionality common to all detail frames.
*
* v0.1 of 23 Feb 2005 - Original version based on code originally implemented
* in FrInfo and FrCompCheck units.
* v0.2 of 28 Jan 2006 - Prevented from setting browser's scroll bars to flat.
* Scroll bars are now displayed normally.
* v0.3 of 16 Apr 2006 - Removed ISetWBExternal interface and replaced with new
* IWBCustomiser interface to perform web browser
* customisation. Implemented IWBCustomiser's
* SetDragDropHandler method. SetExternalObj has been
* moved from ISetWBExternal to IWBCustomiser. Its
* implementation is unchanged.
* v1.0 of 24 May 2006 - Improved and corrected comments.
* - Removed unused unit reference.
* v1.1 of 24 Nov 2006 - Exposed private fActive field as protected Active
* property.
* v1.2 of 25 Nov 2006 - Added code that generates CSS default styles used by
* detail pane browser controls. This CSS is limited to
* colour and font styles that need to accord to system
* defaults or user preferences. Other CSS remains in
* style sheet embedded in resources.
* v1.3 of 03 Dec 2006 - Added support for IDHTMLHostInfo and
* IDetailViewHostInfo interfaces.
* - Added code to ensure that all documents displayed are
* scrolled to top.
* - Moved code that loads and dynamically updates pages
* from descendants to this class. DisplayCurViewItem was
* changed from abstract to virtual to do this.
* - Added new abstract GetPageKind method to get kind of
* page to load from sub classes.
* - Moved code that generates CSS for information pane's
* compiler table to FrInfo. Also deleted redundant CSS
* class from CSS builder.
* v1.4 of 17 Dec 2006 - Removed code that generates old .hilite CSS class
* since class no longer used.
* v1.5 of 04 Feb 2007 - Replaced redundant TDetailView class references with
* TViewItem.
* v1.6 of 09 Feb 2007 - Added new h2 class to dynamically generated CSS.
* v1.7 of 16 Feb 2007 - Revised to work with redefined display interfaces
* from IntfFrameMgrs. Implements various methods of
* these interfaces on behalf of descendant classes.
* - Added Display method previously implemented in
* immediate child classes.
* - Deleted unused Active property and renamed fActive
* field as fIsActivated.
* - Changed to use IDHTML.SupportsUpdating method to
* detect if a view supports DHTML updating rather than
* assuming only routine displays support this.
* - Added IPaneInfo and implemented its IsInteractive
* method.
* v1.8 of 17 Feb 2007 - Changed various methods that called methods on web
* browser control to instead call new methods of
* TWBUIMgr and THTMLDocHelper.
* - Changed TDetailViewFrame.HTMLDocument to call new
* UUtils.GetIntf routine to get required interface.
* - Removed redundant GetWebBrowser method.
* - Changed return type of TDetailViewFrame's HTMLDocument
* method to IDispatch.
* v1.9 of 13 May 2007 - Removed implementation of IClipboardMgr and
* ISelectionMgr since these are now implemented in base
* class.
* v1.10 of 01 Nov 2007 - Added support for IWBPopupMenuConfig and IWBPopupMenus
* via aggregated object.
* v1.11 of 05 Nov 2007 - Changed to use revised CSS builder classes.
* v1.12 of 10 Sep 2008 - Added definition of new CSS classes: .routinenameuser
* and .routinenamemain used to customise colour of
* routine name headings.
* v1.13 of 19 Jan 2009 - Changed to support interfaces from IntfHTMLDocHostInfo
* to replace those deleted from UDHTML.
* - Removed unused GetView method.
* - Changed how new pages are loaded into web borwser
* control. New page loader is used and loaded pages are
* no longer initialised dynamically.
* - Made private and protected sections strict.
* v1.14 of 23 May 2009 - Removed IDetailViewHostInfo from frame definition.
* - Changed to use revised parameter list of
* TDetailPageLoader.LoadPage.
* - Text used in frame now uses system content font.
* - Source code highlighting now uses user defined syntax
* highlighting except that font name and size always
* uses system mono font.
*
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is FrDetailView.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2005-2009 Peter
* Johnson. All Rights Reserved.
*
* ***** END LICENSE BLOCK *****
}
unit FrDetailView;
interface
uses
// Delphi
OleCtrls, SHDocVw, Classes, Controls, ExtCtrls, ActiveX, Windows,
// Project
FrBrowserBase, IntfFrameMgrs, IntfHTMLDocHostInfo, IntfWBPopupMenus,
UCSSBuilder, UDetailPageLoader, UView, UWBPopupMenus;
type
{
TDetailViewFrame:
Abstract base class for frames that display content in the detail pane.
Implements functionality common to all detail frames. It implements web
browser display manager, clipboard manager and selection manager interfaces.
It also manages the contained web browser control and provides an extension
to the browser's "external" object via its ISetWBExternal interface.
}
TDetailViewFrame = class(TBrowserBaseFrame,
IPaneInfo, // provides information about pane
IHTMLDocHostInfo, // info for use in HTML manipulation
IWBPopupMenus, IWBPopupMenuConfig // pop-up menu configuration & display
)
strict private
fCurrentView: TViewItem;
{Value of CurrentView property}
fIsActivated: Boolean;
{Value of Active property}
fPopupMenus: TWBPopupMenus;
{Object that implements IWBPopupMenus and IWBPopupMenuConfig on behalf of
this class}
procedure MoveToDocTop;
{Scrolls browser control to top. This method is used to ensure that newly
loaded documents are not partially scrolled.
}
procedure PopupMenuHandler(Sender: TObject; PopupPos: TPoint;
const MenuID: DWORD; var Handled: Boolean; const Obj: IDispatch);
{Handles web browser UI manager's OnMenuPopupEx event. Pops up relevant
menu if appropriate.
@param Sender [in] Not used.
@param PopupPos [in] Point at which menu is to be displayed.
@param MenuID [in] Identifies kinds of menu required.
@param Handled [in/out] Set to true to prevent browser control
displaying own menu.
@param Obj [in] Reference to HTML element at popup position.
}
protected // do not make strict
{ IClipboardMgr: Implemented in base class }
{ ISelectionMgr: Implemented in base class }
{ IPaneInfo }
function IsInteractive: Boolean;
{Checks if the pane is currently interactive with user.
@return True if pane is interactive, False if not.
}
{ IWBDisplayMgr }
procedure Activate;
{Activates the frame (when it is shown).
}
procedure Deactivate;
{Deactivates the frame (when it is hidden).
}
{ IViewItemDisplayMgr }
procedure Display(const View: TViewItem; const Force: Boolean = False);
{Displays compiler support information for a view item.
@param View [in] Information about view item to be displayed.
@param Force [in] Forces view item to be re-displayed even if not
changed.
}
{ IWBCustomiser }
procedure SetExternalObj(const Obj: IDispatch);
{Provides an object to be used to extend a web browser's external object.
@param Obj [in] External browser object extender.
}
procedure SetDragDropHandler(const Obj: IDropTarget);
{Provides an object to be used by web browser control to handle drag-drop
operations.
@param Obj [in] Drag-drop handler.
}
{ IHTMLDocHostInfo }
function HTMLDocument: IDispatch;
{Gets reference to IDispatch interface of HTML document loaded in browser
control.
@return Document reference.
}
{ IWBPopupMenuConfig and IWBPopupMenus }
property PopupMenus: TWBPopupMenus
read fPopupMenus implements IWBPopupMenus, IWBPopupMenuConfig;
{References aggregated object implementing IWBPopupMenuConfig and
IWBPopupMenus interfaces}
strict protected
function GetPageKind: TDetailPageKind; virtual; abstract;
{Gets kind of page to be loaded by DisplayCurViewItem.
@return Page kind.
}
procedure DisplayCurViewItem; virtual;
{Displays current view item. This method should not be called directly
in descendant classes. They should instead call UpdateDisplay which checks
if frame is active before calling this method.
}
procedure UpdateDisplay;
{Updates the display if active. Does nothing if display not active.
}
procedure BuildCSS(const CSSBuilder: TCSSBuilder); override;
{Generates CSS classes specific to HTML displayed in detail panes. This
CSS is added to that provided by parent class.
@param CSSBuilder [in] Object used to build the CSS code.
}
property CurrentView: TViewItem
read fCurrentView;
{Information about currently displayed view item}
public
constructor Create(AOwner: TComponent); override;
{Class constructor. Sets up detail view frame.
@param AOwner [in] Component that owns frame.
}
destructor Destroy; override;
{Class destructor. Tears down object.
}
end;
implementation
uses
// Delphi
SysUtils, Graphics,
// Project
IntfHiliter, UColours, UCSSUtils, UFontHelper, UHiliteAttrs, UHiliterCSS,
UUtils;
{$R *.dfm}
{ TDetailViewFrame }
procedure TDetailViewFrame.Activate;
{Activates the frame (when it is shown).
}
begin
if not fIsActivated then
begin
// We are going from inactive to active: draw display
fIsActivated := True;
UpdateDisplay;
end;
end;
procedure TDetailViewFrame.BuildCSS(const CSSBuilder: TCSSBuilder);
{Generates CSS classes specific to HTML displayed in detail panes. This CSS is
added to that provided by parent class.
@param CSSBuilder [in] Object used to build the CSS code.
}
var
HiliteAttrs: IHiliteAttrs; // syntax highlighter used to build CSS
CSSFont: TFont; // font used to set CSS properties
begin
// NOTE:
// We only set CSS properties that may need to use system colours or fonts
// that may be changed by user or changing program defaults. CSS that controls
// layout remains in a CSS file embedded in resources.
inherited;
CSSFont := TFont.Create;
try
// Set body style to use program's font and window colour
with CSSBuilder.AddSelector('body') do
begin
TFontHelper.SetContentFont(CSSFont, True);
AddProperty(CSSFontProps(CSSFont));
AddProperty(CSSBackgroundColorProp(clWindow));
end;
// Set table to use required font
with CSSBuilder.AddSelector('table') do
begin
TFontHelper.SetContentFont(CSSFont, True);
AddProperty(CSSFontProps(CSSFont));
AddProperty(CSSBackgroundColorProp(clBorder));
end;
// Set default table cell colour (must be different to table to get border)
with CSSBuilder.AddSelector('td') do
AddProperty(CSSBackgroundColorProp(clWindow));
// Sets H1 heading font size and border
with CSSBuilder.AddSelector('h1') do
begin
TFontHelper.SetContentFont(CSSFont, True);
CSSFont.Size := CSSFont.Size + 2;
CSSFont.Style := [fsBold];
AddProperty(CSSFontProps(CSSFont));
AddProperty(CSSBorderProp(cssBottom, 1, cbsSolid, clBorder));
end;
// Sets H2 heading font size and border
with CSSBuilder.AddSelector('h2') do
begin
TFontHelper.SetContentFont(CSSFont, True);
CSSFont.Assign(CSSFont);
CSSFont.Style := [fsBold];
AddProperty(CSSFontProps(CSSFont));
end;
// Style of box that appears around clickable options (or actions)
with CSSBuilder.AddSelector('.optionbox') do
AddProperty(CSSBorderProp(cssAll, 1, cbsSolid, clBorder));
with CSSBuilder.AddSelector('.userdb') do
AddProperty(CSSColorProp(clUserRoutine));
with CSSBuilder.AddSelector('.maindb') do
AddProperty(CSSColorProp(Self.Font.Color));
// Sets text styles and colours used by syntax highlighter
HiliteAttrs := THiliteAttrsFactory.CreateDisplayAttrs;
with THiliterCSS.Create(HiliteAttrs) do
try
BuildCSS(CSSBuilder);
finally
Free;
end;
// Adjust .pas-source class to use required background colour
with CSSBuilder.Selectors['.' + THiliterCSS.GetMainCSSClassName] do
AddProperty(CSSBackgroundColorProp(clSourceBg));
finally
FreeAndNil(CSSFont);
end;
end;
constructor TDetailViewFrame.Create(AOwner: TComponent);
{Class constructor. Sets up detail view frame.
@param AOwner [in] Component that owns frame.
}
begin
inherited;
// Set up popups menus object
fPopupMenus := TWBPopupMenus.Create(Self);
WBController.UIMgr.OnMenuPopupEx := PopupMenuHandler;
// Create object to store detailed info about current view item
fCurrentView := TViewItem.Create;
end;
procedure TDetailViewFrame.Deactivate;
{Deactivates the frame (when it is hidden).
}
begin
// Record that we are inactive
fIsActivated := False;
end;
destructor TDetailViewFrame.Destroy;
{Class destructor. Tears down object.
}
begin
FreeAndNil(fCurrentView);
FreeAndNil(fPopupMenus);
inherited;
end;
procedure TDetailViewFrame.Display(const View: TViewItem;
const Force: Boolean);
{Displays compiler support information for a view item.
@param View [in] Information about view item to be displayed.
@param Force [in] Forces view item to be re-displayed even if not
changed.
}
begin
if not CurrentView.IsEqual(View) or Force then
begin
// Record view item and display style
CurrentView.Assign(View);
// Redraw the display
UpdateDisplay;
end;
end;
procedure TDetailViewFrame.DisplayCurViewItem;
{Displays current view item. This method should not be called directly in
descendant classes. They should instead call UpdateDisplay which checks if
frame is active before calling this method.
}
begin
// Load the required page using page loader.
TDetailPageLoader.LoadPage(GetPageKind, CurrentView, WBController);
// Cancel any selection in browser control
WBController.UIMgr.ClearSelection;
end;
function TDetailViewFrame.HTMLDocument: IDispatch;
{Gets reference to IDispatch interface of HTML document loaded in browser
control.
@return Document reference.
}
begin
GetIntf(wbBrowser.Document, IDispatch, Result);
end;
function TDetailViewFrame.IsInteractive: Boolean;
{Checks if the pane is currently interactive with user.
@return True if pane is interactive, False if not.
}
begin
// This frame only contains a browser control. So, if frame is interactive
// if and only if browser control is active.
Result := IsBrowserActive;
end;
procedure TDetailViewFrame.MoveToDocTop;
{Scrolls browser control to top. This method is used to ensure that newly
loaded documents are not partially scrolled.
}
begin
WBController.UIMgr.ScrollTo(0, 0);
end;
procedure TDetailViewFrame.PopupMenuHandler(Sender: TObject;
PopupPos: TPoint; const MenuID: DWORD; var Handled: Boolean;
const Obj: IDispatch);
{Handles web browser UI manager's OnMenuPopupEx event. Pops up relevant menu
if appropriate.
@param Sender [in] Not used.
@param PopupPos [in] Point at which menu is to be displayed.
@param MenuID [in] Identifies kinds of menu required.
@param Handled [in/out] Set to true to prevent browser control displaying
own menu.
@param Obj [in] Reference to HTML element at popup position.
}
begin
(Self as IWBPopupMenus).Popup(PopupPos, TWBPopupMenuKind(MenuID), Obj);
Handled := True;
end;
procedure TDetailViewFrame.SetDragDropHandler(const Obj: IDropTarget);
{Provides an object to be used by web browser control to handle drag-drop
operations.
@param Obj [in] Drag-drop handler.
}
begin
WBController.UIMgr.DropTarget := Obj;
end;
procedure TDetailViewFrame.SetExternalObj(const Obj: IDispatch);
{Provides an object to be used to extend a web browser's external object.
@param Obj [in] External browser object extender.
}
begin
WBController.UIMgr.ExternScript := Obj;
end;
procedure TDetailViewFrame.UpdateDisplay;
{Updates the display if active. Does nothing if display not active.
}
begin
if fIsActivated then
begin
DisplayCurViewItem;
MoveToDocTop; // ensures top of newly loaded document is displayed
end;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.