Menu

[r660]: / trunk / Src / UDlgHelper.pas  Maximize  Restore  History

Download this file

723 lines (659 with data), 24.8 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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
{
* UDlgHelper.pas
*
* Implements "static" classes that help to manipulate dialog boxes.
*
* Originally named UDlgAligner.pas. Renamed as UDlgHelper.pas as at v1.1.
*
* $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 UDlgHelper.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2007-2009 Peter
* Johnson. All Rights Reserved.
*
* Contributor(s)
* NONE
*
* ***** END LICENSE BLOCK *****
}
unit UDlgHelper;
interface
uses
// Delphi
Classes, Windows,
// Project
UBaseObjects, UStructs;
type
{
TDlgHelper:
Static class that sets parent window of a dialog box.
}
TDlgHelper = class(TNoConstructObject)
public
class procedure SetDlgParent(const Dlg, Parent: TComponent);
{Sets parent of a dialog box to window associated with a parent component.
@param Dlg [in] Dialog box that will have parent set.
@param Parent [in] Control whose window handle is to be parent of Dlg.
If Parent is nil or isn't support either active form or main form are
used.
}
class procedure SetDlgParentToOwner(const Dlg: TComponent);
{Makes owner of a dialog box its parent.
@param Dlg [in] Dialog box whose parent is to be set to owner. If Dlg's
Owner is nil or not supported either active form or main form is used.
}
end;
{
TDlgAligner:
"Static" class that aligns dialog boxes over host windows.
}
TDlgAligner = class(TNoPublicConstructObject)
strict private
fDialog: IInterface; // Object representing window to be aligned
fHostWdw: IInterface; // Object representing host window for alignment
procedure GetDialogBounds(out DlgBounds: TRectEx);
{Gets bounding rectangle of dialog box to be aligned.
@param DlgBounds [out] Set to required bounding rectangle in screen
coordinates.
}
procedure OffsetDialog(var DlgBounds: TRectEx);
{Offsets a dialog's bounding rectangle according to whether host is a
dialog box or not.
@param DlgBounds [in/out] Current dialog bounds are passed in and offset
bounding rectangle passed out.
}
procedure FitToWorkArea(var DlgBounds: TRectEx);
{Ensures that a bounding rectangle of a dialog box fits within work area.
@param DlgBounds [in/out] Bounding rectangle to be adjusted is passed in
and may be modified if it does not fit work area.
}
procedure AdjustWindowPosition(const DlgBounds: TRectEx);
{Adjusts position (and optionally size) of dialog box being aligned
according to bounding rectangle.
@param DlgBounds [in] Required bounding rectangle of dialog box.
}
procedure DoAlign(const Dlg, Host: TComponent);
{Performs alignment of a window over a host window.
@param Dlg [in] Dialog box to be aligned. Must not be nil.
@param Host [in] Window over which window is to be aligned. May be nil.
}
public
class procedure Align(const Dlg, Host: TComponent);
{Aligns a dialog window over a host window. If host window is a dialog box
the window is offset from dialog's top left corner, otherwise the window
is "centered" over the host window. If host window is not supported either
active form or application's main form are used as host.
@param Dlg [in] Dialog box to be aligned. Must not be nil.
@param Host [in] Window over which window is to be aligned. May be nil.
}
class procedure AlignToOwner(const Dlg: TComponent);
{Aligns a dialog box window over window represented by dialog's Owner
property. If Owner window is a dialog box the dialog window is offset from
dialog's top left corner, otherwise the window is "centered" over the
owner window. If Owner does not have a suitable associated window either
active form or application's main form are used in place of owner.
@param Dlg [in] Dialog box to be aligned to its owner. Dlg must not be
nil but its owner may be.
}
end;
implementation
uses
// Delphi
SysUtils, Controls, Forms, Dialogs,
// Project
UExceptions;
type
{
IWindowInfo:
Abstraction of a window that provides information about the window.
}
IWindowInfo = interface(IInterface)
['{8E0F5AA6-88AC-4734-99C0-2253E7CF665A}']
function IsDialog: Boolean;
{Check if window is a dialog box.
@return True if dialog box, False if not.
}
function BoundsRect: TRectEx;
{Get bounding rectangle of window.
@return Required rectangle in screen co-ordinates.
}
function Handle: THandle;
{Get handle of window.
@return Required handle or 0 if no handle supported.
}
end;
{
IAlignableWindow:
Abstraction of a window that can be aligned above another window.
}
IAlignableWindow = interface(IInterface)
['{E65CAAEE-F782-4489-B2DF-2B8C4121825F}']
function BoundsRect: TRectEx;
{Get bounding rectangle of window.
@return Required rectangle in screen co-ordinates.
}
procedure AdjustWindow(const Bounds: TRectEx);
{Adjust window to have a new bounding rectangle.
@param Bounds [in] New bounds for window, in screen co-ordinates.
}
end;
{
TWindowInfoFactory:
Factory class that creates IWindowInfo instances from appropriate classes.
}
TWindowInfoFactory = class(TNoConstructObject)
public
class function Instance(const Host: TComponent): IWindowInfo;
{Creates a suitable IWindowInfo instance for a host component.
@param Host [in] Component for which we need IWindowInfo instance. Host
may be any TComponent. If it is not a TWinControl (including
TCustomForm) or a TCommonDialog then either current active form or
main form are used as host.
@return Required instance.
}
end;
{
TAlignableDialogFactory:
Factory class that creates IAlignableWindow instances from appropriate
classes.
}
TAlignableDialogFactory = class(TNoConstructObject)
public
class function Instance(const Dlg: TComponent): IAlignableWindow;
{Creates a suitable IAlignableWindow instance for a dialog box component.
@param Dlg [in] Dialog component for which we need IWindowInfo instance.
Dlg must be either a TCustomForm or a TCommonDialog.
@return Required instance.
@except EBug raised if Dlg is not one of required types.
}
end;
{
TFormWindow:
Class that implements IAlignableWindow and IWindowInfo interfaces for a
form. Provides information about and positions the form.
}
TFormWindow = class(TInterfacedObject,
IAlignableWindow, IWindowInfo
)
strict private
fForm: TCustomForm; // Reference to encapsulated form
protected
{ IAlignableWindow and IWindowInfo methods }
function BoundsRect: TRectEx;
{Get bounding rectangle of form.
@return Required rectangle in screen co-ordinates.
}
procedure AdjustWindow(const Bounds: TRectEx);
{Adjust form to have a new bounding rectangle. If form is a dialog box
then top left corner is moved to new position but size is not changed.
@param Bounds [in] New bounds for form, in screen co-ordinates.
}
function IsDialog: Boolean;
{Check if form is a dialog box.
@return True if dialog box, False if not.
}
function Handle: THandle;
{Get handle of form.
@return Required handle.
}
public
constructor Create(const Form: TCustomForm);
{Class constructor. Sets up object.
@param Form [in] Reference to form to be encapsulated.
}
end;
{
TWinControlWindow:
Class that implements IWindowInfo interface for a TWinControl and
descendants (except TCustomForm). Provides information about the control.
}
TWinControlWindow = class(TInterfacedObject,
IWindowInfo
)
strict private
fWinCtrl: TWinControl; // Reference to encapsulated control
protected
{ IWindowInfo methods }
function IsDialog: Boolean;
{Check if control is a dialog box.
@return False. Control never a dialog box.
}
function BoundsRect: TRectEx;
{Get bounding rectangle of control.
@return Required rectangle in screen co-ordinates.
}
function Handle: THandle;
{Get handle of window.
@return Required handle.
}
public
constructor Create(const WinCtrl: TWinControl);
{Class constructor. Sets up object.
@param WinCtrl [in] Control to be encapsulated. Must not be a
TCustomForm.
}
end;
{
TCommonDialogWindow:
Class that implements IAlignableWindow and IWindowInfo interfaces for a
common dialog box (except TOpenDialog). Provides information about and
positions the dialog.
}
TCommonDialogWindow = class(TInterfacedObject,
IWindowInfo, IAlignableWindow
)
strict protected
fDlg: TCommonDialog; // Reference to common dialog to be encapsulated
protected
{ IWindowInfo and IAlignableWindow methods }
function IsDialog: Boolean;
{Check if window is a dialog box.
@return True. Common dialogs are always dialogs.
}
function BoundsRect: TRectEx;
{Get bounding rectangle of common dialog
@return Required rectangle in screen co-ordinates.
}
procedure AdjustWindow(const Bounds: TRectEx);
{Adjust common dialog to have same top corner as bounding rectangle. Any
change of size is ignored.
@param Bounds [in] New bounds for control, in screen co-ordinates.
}
function Handle: THandle; virtual;
{Get dialog box's window handle.
@return Required window handle.
}
public
constructor Create(const Dlg: TCommonDialog);
{Class constructor. Sets up object.
@param Dlg [in] Reference to common dialog to be encapsulated. Must not
be called directly with a TOpenDialog.
}
end;
{
TOpenDialogWindow:
Class that implements IAlignableWindow and IWindowInfo interfaces for a
TOpenDialog. Provides information about and positions the dialog.
}
TOpenDialogWindow = class(TCommonDialogWindow,
IWindowInfo, IAlignableWindow
)
protected
{ IWindowInfo method }
function Handle: THandle; override;
{Get dialog box's window handle. Deals correctly with dialogas with
explorer hooks and/or customisation templates.
@return Required window handle.
}
public
constructor Create(const Dlg: TOpenDialog);
{Class constructor. Sets up object.
@param Dlg [in] Reference to open dialog to be encapsulated.
}
end;
{ TDlgHelper }
class procedure TDlgHelper.SetDlgParent(const Dlg, Parent: TComponent);
{Sets parent of a dialog box to window associated with a parent component.
@param Dlg [in] Dialog box that will have parent set.
@param Parent [in] Control whose window handle is to be parent of Dlg. If
Parent is nil or isn't support either active form or main form are used.
}
var
ParentWindow: IWindowInfo; // encapsulates parent window
DlgWindow: IWindowInfo; // encapsulates dialog box window
begin
Assert(Assigned(Dlg), ClassName + '.SetDlgParent: Dlg is nil');
DlgWindow := TWindowInfoFactory.Instance(Dlg);
ParentWindow := TWindowInfoFactory.Instance(Parent);
SetWindowLong(DlgWindow.Handle, GWL_HWNDPARENT, ParentWindow.Handle);
end;
class procedure TDlgHelper.SetDlgParentToOwner(const Dlg: TComponent);
{Makes owner of a dialog box its parent.
@param Dlg [in] Dialog box whose parent is to be set to owner. If Dlg's
Owner is nil or not supported either active form or main form is used.
}
begin
SetDlgParent(Dlg, Dlg.Owner);
end;
{ TDlgAligner }
procedure TDlgAligner.AdjustWindowPosition(const DlgBounds: TRectEx);
{Adjusts position (and optionally size) of dialog box being aligned according
to bounding rectangle.
@param DlgBounds [in] Required bounding rectangle of dialog box.
}
begin
(fDialog as IAlignableWindow).AdjustWindow(DlgBounds);
end;
class procedure TDlgAligner.Align(const Dlg, Host: TComponent);
{Aligns a dialog window over a host window. If host window is a dialog box the
window is offset from dialog's top left corner, otherwise the window is
"centered" over the host window. If host window is not supported either active
form or application's main form are used as host.
@param Dlg [in] Dialog box to be aligned. Must not be nil.
@param Host [in] Window over which window is to be aligned. May be nil.
}
begin
Assert(Assigned(Dlg), ClassName + '.Align: Dlg is nil');
with InternalCreate do
try
DoAlign(Dlg, Host);
finally
Free;
end;
end;
class procedure TDlgAligner.AlignToOwner(const Dlg: TComponent);
{Aligns a dialog box window over window represented by dialog's Owner
property. If Owner window is a dialog box the dialog window is offset from
dialog's top left corner, otherwise the window is "centered" over the owner
window. If Owner does not have a suitable associated window either active form
or application's main form are used in place of owner.
@param Dlg [in] Dialog box to be aligned to its owner. Dlg must not be nil
but its owner may be.
}
begin
Assert(Assigned(Dlg), ClassName + '.AlignToOwner: Dlg is nil');
Align(Dlg, Dlg.Owner);
end;
procedure TDlgAligner.DoAlign(const Dlg, Host: TComponent);
{Performs alignment of a window over a host window.
@param Dlg [in] Dialog box to be aligned. Must not be nil.
@param Host [in] Window over which window is to be aligned. May be nil.
}
var
DlgBounds: TRectEx; // bounding rectangle of dialog box
begin
Assert(Assigned(Dlg), ClassName + '.DoAlign: Dlg is nil');
// Encapsulate window and host window
fDialog := TAlignableDialogFactory.Instance(Dlg);
fHostWdw := TWindowInfoFactory.Instance(Host);
// Do the alignment
GetDialogBounds(DlgBounds);
OffsetDialog(DlgBounds);
FitToWorkArea(DlgBounds);
AdjustWindowPosition(DlgBounds);
end;
procedure TDlgAligner.FitToWorkArea(var DlgBounds: TRectEx);
{Ensures that a bounding rectangle of a dialog box fits within work area.
@param DlgBounds [in/out] Bounding rectangle to be adjusted is passed in and
may be modified if it does not fit work area.
}
var
WorkArea: TRectEx; // desktop work area
begin
WorkArea := Screen.MonitorFromRect(DlgBounds).WorkareaRect;
if DlgBounds.Right > WorkArea.Right then
DlgBounds.OffsetBy(WorkArea.Right - DlgBounds.Right, 0);
if DlgBounds.Left < WorkArea.Left then
DlgBounds.OffsetBy(WorkArea.Left - DlgBounds.Left, 0);
if DlgBounds.Bottom > WorkArea.Bottom then
DlgBounds.OffsetBy(0, WorkArea.Bottom - DlgBounds.Bottom);
if DlgBounds.Top < WorkArea.Top then
DlgBounds.OffsetBy(0, WorkArea.Top - DlgBounds.Top);
end;
procedure TDlgAligner.GetDialogBounds(out DlgBounds: TRectEx);
{Gets bounding rectangle of dialog box to be aligned.
@param DlgBounds [out] Set to required bounding rectangle in screen
coordinates.
}
begin
DlgBounds := (fDialog as IAlignableWindow).BoundsRect;
end;
procedure TDlgAligner.OffsetDialog(var DlgBounds: TRectEx);
{Offsets a dialog's bounding rectangle according to whether host is a dialog
box or not.
@param DlgBounds [in/out] Current dialog bounds are passed in and offset
bounding rectangle passed out.
}
const
// Offsets used when aligning over a dialog box
cDlgOffset: TPoint = (X: 40; Y: 40);
var
HostBounds: TRectEx; // bounding rectangle of AlignCtrl in screen co-ords
begin
HostBounds := (fHostWdw as IWindowInfo).BoundsRect;
if (fHostWdw as IWindowInfo).IsDialog then
// Aligning over dialog box: offset down and to left
DlgBounds.OffsetBy(
HostBounds.Left - DlgBounds.Left + cDlgOffset.X,
HostBounds.Top - DlgBounds.Top + cDlgOffset.Y
)
else
// Aligning over a main window: "centre" dialog over window
DlgBounds.OffsetBy(
HostBounds.Left - DlgBounds.Left +
(HostBounds.Width - DlgBounds.Width) div 2,
HostBounds.Top - DlgBounds.Top +
(HostBounds.Height - DlgBounds.Height) div 3
)
end;
{ TWindowInfoFactory }
class function TWindowInfoFactory.Instance(
const Host: TComponent): IWindowInfo;
{Creates a suitable IWindowInfo instance for a host component.
@param Host [in] Component for which we need IWindowInfo instance. Host may
be any TComponent. If it is not a TWinControl (including TCustomForm) or a
TCommonDialog then either current active form or main form are used as
host.
@return Required instance.
}
begin
Result := nil;
if Host is TCustomForm then
Result := TFormWindow.Create(Host as TCustomForm)
else if Host is TWinControl then
Result := TWinControlWindow.Create(Host as TWinControl)
else if Host is TOpenDialog then
Result := TOpenDialogWindow.Create(Host as TOpenDialog)
else if Host is TCommonDialog then
Result := TCommonDialogWindow.Create(Host as TCommonDialog);
if not Assigned(Result) then
begin
if Assigned(Screen.ActiveCustomForm) then
Result := TFormWindow.Create(Screen.ActiveCustomForm)
else if Assigned(Application.MainForm) then
Result := TFormWindow.Create(Application.MainForm)
end;
Assert(Assigned(Result), ClassName + '.Instance: Can''t create instance');
end;
{ TAlignableDialogFactory }
class function TAlignableDialogFactory.Instance(
const Dlg: TComponent): IAlignableWindow;
{Creates a suitable IAlignableWindow instance for a dialog box component.
@param Dlg [in] Dialog component for which we need IWindowInfo instance. Dlg
must be either a TCustomForm or a TCommonDialog.
@return Required instance.
@except EBug raised if Dlg is not one of required types.
}
begin
Assert(Assigned(Dlg), ClassName + '.Instance: Dlg is nil');
if Dlg is TCustomForm then
Result := TFormWindow.Create(Dlg as TCustomForm)
else if Dlg is TOpenDialog then
Result := TOpenDialogWindow.Create(Dlg as TOpenDialog)
else if Dlg is TCommonDialog then
Result := TCommonDialogWindow.Create(Dlg as TCommonDialog)
else
raise EBug.CreateFmt(
'%0:s.Instance: Unsupported WdwCtrl type %1:s', [ClassName, Dlg.ClassName]
);
end;
{ TFormWindow }
procedure TFormWindow.AdjustWindow(const Bounds: TRectEx);
{Adjust form to have a new bounding rectangle. If form is a dialog box then
top left corner is moved to new position but size is not changed.
@param Bounds [in] New bounds for form, in screen co-ordinates.
}
begin
if IsDialog then
fForm.SetBounds(Bounds.Left, Bounds.Top, fForm.Width, fForm.Height)
else
fForm.BoundsRect := Bounds;
end;
function TFormWindow.BoundsRect: TRectEx;
{Get bounding rectangle of form.
@return Required rectangle in screen co-ordinates.
}
begin
Result := fForm.BoundsRect;
end;
constructor TFormWindow.Create(const Form: TCustomForm);
{Class constructor. Sets up object.
@param Form [in] Reference to form to be encapsulated.
}
begin
Assert(Assigned(Form), ClassName + '.Create: Form is nil');
inherited Create;
fForm := Form;
end;
function TFormWindow.Handle: THandle;
{Gets handle of form.
@return Required handle.
}
begin
Result := fForm.Handle;
end;
function TFormWindow.IsDialog: Boolean;
{Check if form is a dialog box.
@return True if dialog box, False if not.
}
begin
Result := fForm.BorderStyle in [bsDialog, bsSizeToolWin, bsToolWindow];
end;
{ TCommonDialogWindow }
procedure TCommonDialogWindow.AdjustWindow(const Bounds: TRectEx);
{Adjust common dialog to have same top corner as bounding rectangle. Any
change of size is ignored.
@param Bounds [in] New bounds for control, in screen co-ordinates.
}
begin
SetWindowPos(
Handle, // window to position
0, // only required if setting z-order
Bounds.Left, Bounds.Top, // X and Y co-ords of window
0, 0, // only required if setting size of window
SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER // flags saying what to do
);
end;
function TCommonDialogWindow.BoundsRect: TRectEx;
{Get bounding rectangle of common dialog
@return Required rectangle in screen co-ordinates.
}
var
Rect: TRect; // bounding rectangle
begin
GetWindowRect(Handle, Rect);
Result := Rect;
end;
constructor TCommonDialogWindow.Create(const Dlg: TCommonDialog);
{Class constructor. Sets up object.
@param Dlg [in] Reference to common dialog to be encapsulated. Must not be
called directly with a TOpenDialog.
}
begin
Assert(Assigned(Dlg), ClassName + '.Create: Dlg is nil');
Assert((ClassType <> TCommonDialogWindow) or not (Dlg is TOpenDialog),
ClassName + '.Create: Dlg cannot be a TOpenDialog');
inherited Create;
fDlg := Dlg;
end;
function TCommonDialogWindow.Handle: THandle;
{Gets dialog box's window handle.
@return Required window handle.
}
begin
Result := fDlg.Handle;
end;
function TCommonDialogWindow.IsDialog: Boolean;
{Check if window is a dialog box.
@return True. Common dialogs are always dialogs!
}
begin
Result := True;
end;
{ TOpenDialogWindow }
constructor TOpenDialogWindow.Create(const Dlg: TOpenDialog);
{Class constructor. Sets up object.
@param Dlg [in] Reference to open dialog to be encapsulated.
}
begin
inherited Create(Dlg);
end;
function TOpenDialogWindow.Handle: THandle;
{Get dialog box's window handle. Deals correctly with dialogas with explorer
hooks and/or customisation templates.
@return Required window handle.
}
begin
if NewStyleControls and
not (ofOldStyleDialog in (fDlg as TOpenDialog).Options) then
// For explorer style dialogs with explorer hooks and / or customisation
// templates the main window handle is the parent of the handle returned
// from dialog's Handle property. Delphi always provides an explorer hook
// for new style dialog boxes, so we can assume we need the parent handle
Result := GetParent(inherited Handle)
else
Result := inherited Handle;
end;
{ TWinControlWindow }
function TWinControlWindow.BoundsRect: TRectEx;
{Get bounding rectangle of control.
@return Required rectangle in screen co-ordinates.
}
begin
if fWinCtrl.Parent = nil then
// No parent: bounds are already in screen coords
Result := fWinCtrl.BoundsRect
else
begin
// Parented control: bounds are relative to parent => map to screen coords
Result.TopLeft := fWinCtrl.ClientToScreen(
fWinCtrl.BoundsRect.TopLeft
);
Result.BottomRight := fWinCtrl.ClientToScreen(
fWinCtrl.BoundsRect.BottomRight
);
end;
end;
constructor TWinControlWindow.Create(const WinCtrl: TWinControl);
{Class constructor. Sets up object.
@param WinCtrl [in] Control to be encapsulated. Must not be a TCustomForm.
}
begin
Assert(Assigned(WinCtrl), ClassName + '.Create: WinCtrl is nil');
Assert(not (WinCtrl is TCustomForm),
ClassName + '.Create: WinCtrl cannot be a TCustomForm');
inherited Create;
fWinCtrl := WinCtrl;
end;
function TWinControlWindow.Handle: THandle;
{Gets handle of window.
@return Required handle.
}
begin
Result := fWinCtrl.Handle;
end;
function TWinControlWindow.IsDialog: Boolean;
{Check if control is a dialog box.
@return False. Control never a dialog box.
}
begin
Result := False;
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.