Menu

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

Download this file

423 lines (392 with data), 15.1 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
{
* FrDetailView.pas
*
* Abstract base class for frames that display content in the detail pane.
* Implements functionality common to all detail frames.
*
* $Rev$
* $Date$
*
* ***** 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.
*
* Contributor(s)
* NONE
*
* ***** END LICENSE BLOCK *****
}
unit FrDetailView;
interface
uses
// Delphi
OleCtrls, SHDocVw, Classes, Controls, ExtCtrls, Windows, ActiveX,
// Project
FrBrowserBase, IntfFrameMgrs, IntfHTMLDocHostInfo, UCommandBars, 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
ICommandBarConfig // command bar configuration
)
strict private
fCurrentView: TViewItem; // Value of CurrentView property
fIsActivated: Boolean; // Value of Active property
fPopupMenuMgr: TWBPopupMenuMgr; // Managed browser related popup menus
fCommandBars: TCommandBarMgr; // Configures command bars (browser popups)
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.
}
{ ICommandBarConfig }
property CommandBars: TCommandBarMgr
read fCommandBars implements ICommandBarConfig;
{References aggregated object implementing ICommandBarConfig}
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, Menus,
// Project
IntfHiliter, UColours, UCSSUtils, UFontHelper, UHiliteAttrs, UHiliterCSS,
UUtils, UWBCommandBars;
{$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.
}
type
// Range of browser-related popup menu command ids
TWBMenuID = cDetailPopupMenuFirst..cDetailPopupMenuLast;
const
// Maps popup menu ids to command bar wrapper classes for assoicated menus. A
// nil entry indicates no menu or wrapper are required for that menu type.
cMenuWrapperClassMap: array[TWBMenuID] of TPopupMenuWrapperClass = (
TWBDefaultPopupMenuWrapper, // cDetailPopupMenuDefault
TWBPopupMenuWrapper, // cDetailPopupMenuImage
nil, // cDetailPopupMenuControl
nil, // cDetailPopupMenuTable
TWBPopupMenuWrapper, // cDetailPopupMenuTextSelect
TWBPopupMenuWrapper, // cDetailPopupMenuAnchor
nil // cDetailPopupMenuUnknown
);
var
CmdBarID: TCommandBarID; // loops through browser menu command ids
Menu: TPopupMenu; // references each required popup menu
WrapperCls: TPopupMenuWrapperClass; // class of required command bar wrapper
begin
inherited;
// Set up objects that manage browser pop-up menus and command bars
fPopupMenuMgr := TWBPopupMenuMgr.Create(Self); // frees itself
fCommandBars := TWBCommandBarMgr.Create(Self);
// Create required popup menus for use with browser control and add to command
// bar manager
for CmdBarID := cDetailPopupMenuFirst to cDetailPopupMenuLast do
begin
WrapperCls := cMenuWrapperClassMap[CmdBarID];
if Assigned(WrapperCls) then
begin
Menu := fPopupMenuMgr.AddMenu(CmdBarID);
fCommandBars.AddCommandBar(CmdBarID, WrapperCls.Create(Menu));
end;
end;
// Set pop-up menu handler for browser control
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(fCommandBars);
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
fPopupMenuMgr.Popup(MenuID, PopupPos, 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.