-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaxctrls.pas
3890 lines (3476 loc) · 110 KB
/
axctrls.pas
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{*******************************************************}
{ }
{ Delphi Visual Component Library }
{ ActiveX Controls Unit }
{ }
{ Copyright (c) 1997 Borland International }
{ }
{*******************************************************}
unit AxCtrls;
{$T-,H+,X+}
interface
uses
Windows, Messages, ActiveX, SysUtils, ComObj, Classes, Graphics,
Controls, Forms, Consts, ExtCtrls, StdVcl;
const
{ Delphi property page CLSIDs }
Class_DColorPropPage: TGUID = '{5CFF5D59-5946-11D0-BDEF-00A024D1875C}';
Class_DFontPropPage: TGUID = '{5CFF5D5B-5946-11D0-BDEF-00A024D1875C}';
Class_DPicturePropPage: TGUID = '{5CFF5D5A-5946-11D0-BDEF-00A024D1875C}';
Class_DStringPropPage: TGUID = '{F42D677E-754B-11D0-BDFB-00A024D1875C}';
type
TOleStream = class(TStream)
private
FStream: IStream;
public
constructor Create(const Stream: IStream);
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override;
function Seek(Offset: Longint; Origin: Word): Longint; override;
end;
TAggregatedObject = class
private
FController: Pointer;
function GetController: IUnknown;
protected
{ IUnknown }
function QueryInterface(const IID: TGUID; out Obj): Integer; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
public
constructor Create(const Controller: IUnknown);
property Controller: IUnknown read GetController;
end;
TContainedObject = class(TAggregatedObject, IUnknown)
protected
{ IUnknown }
function QueryInterface(const IID: TGUID; out Obj): Integer; virtual; stdcall;
end;
TConnectionPoints = class;
TConnectEvent = procedure (const Sink: IUnknown; Connecting: Boolean) of object;
TConnectionKind = (ckSingle, ckMulti);
TConnectionPoint = class(TContainedObject, IConnectionPoint)
private
FContainer: TConnectionPoints;
FIID: TGUID;
FSinkList: TList;
FOnConnect: TConnectEvent;
FSinkCount: Integer;
FKind: TConnectionKind;
function AddSink(const Sink: IUnknown): Integer;
procedure RemoveSink(Cookie: Longint);
protected
{ IConnectionPoint }
function GetConnectionInterface(out iid: TIID): HResult; stdcall;
function GetConnectionPointContainer(
out cpc: IConnectionPointContainer): HResult; stdcall;
function Advise(const unkSink: IUnknown; out dwCookie: Longint): HResult; stdcall;
function Unadvise(dwCookie: Longint): HResult; stdcall;
function EnumConnections(out enum: IEnumConnections): HResult; stdcall;
public
constructor Create(Container: TConnectionPoints;
const IID: TGUID; Kind: TConnectionKind; OnConnect: TConnectEvent);
destructor Destroy; override;
end;
TConnectionPoints = class(TAggregatedObject,
IConnectionPointContainer)
private
FConnectionPoints: TList;
protected
{ IConnectionPointContainer }
function EnumConnectionPoints(
out enum: IEnumConnectionPoints): HResult; stdcall;
function FindConnectionPoint(const iid: TIID;
out cp: IConnectionPoint): HResult; stdcall;
public
constructor Create(const Controller: IUnknown);
destructor Destroy; override;
function CreateConnectionPoint(const IID: TGUID; Kind: TConnectionKind;
OnConnect: TConnectEvent): TConnectionPoint;
end;
TDefinePropertyPage = procedure(const GUID: TGUID) of object;
TActiveXControlFactory = class;
IAmbientDispatch = dispinterface
['{00020400-0000-0000-C000-000000000046}']
property BackColor: Integer dispid DISPID_AMBIENT_BACKCOLOR;
property DisplayName: WideString dispid DISPID_AMBIENT_DISPLAYNAME;
property Font: IFontDisp dispid DISPID_AMBIENT_FONT;
property ForeColor: Integer dispid DISPID_AMBIENT_FORECOLOR;
property LocaleID: Integer dispid DISPID_AMBIENT_LOCALEID;
property MessageReflect: WordBool dispid DISPID_AMBIENT_MESSAGEREFLECT;
property ScaleUnits: WideString dispid DISPID_AMBIENT_SCALEUNITS;
property TextAlign: Smallint dispid DISPID_AMBIENT_TEXTALIGN;
property UserMode: WordBool dispid DISPID_AMBIENT_USERMODE;
property UIDead: WordBool dispid DISPID_AMBIENT_UIDEAD;
property ShowGrabHandles: WordBool dispid DISPID_AMBIENT_SHOWGRABHANDLES;
property ShowHatching: WordBool dispid DISPID_AMBIENT_SHOWHATCHING;
property DisplayAsDefault: WordBool dispid DISPID_AMBIENT_DISPLAYASDEFAULT;
property SupportsMnemonics: WordBool dispid DISPID_AMBIENT_SUPPORTSMNEMONICS;
property AutoClip: WordBool dispid DISPID_AMBIENT_AUTOCLIP;
end;
TActiveXControl = class(TAutoObject,
IPersistStreamInit,
IPersistStorage,
IOleObject,
IOleControl,
IOleInPlaceObject,
IOleInPlaceActiveObject,
IViewObject,
IViewObject2,
IPerPropertyBrowsing,
ISpecifyPropertyPages,
ISimpleFrameSite)
private
FControlFactory: TActiveXControlFactory;
FConnectionPoints: TConnectionPoints;
FEventSink: IUnknown;
FPropertySinks: TConnectionPoint;
FOleClientSite: IOleClientSite;
FOleControlSite: IOleControlSite;
FSimpleFrameSite: ISimpleFrameSite;
FAmbientDispatch: IAmbientDispatch;
FOleInPlaceSite: IOleInPlaceSite;
FOleInPlaceFrame: IOleInPlaceFrame;
FOleInPlaceUIWindow: IOleInPlaceUIWindow;
FOleAdviseHolder: IOleAdviseHolder;
FAdviseSink: IAdviseSink;
FAdviseFlags: Integer;
FControl: TWinControl;
FControlWndProc: TWndMethod;
FWinControl: TWinControl;
FIsDirty: Boolean;
FInPlaceActive: Boolean;
FUIActive: Boolean;
FEventsFrozen: Boolean;
function CreateAdviseHolder: HResult;
procedure EventConnect(const Sink: IUnknown; Connecting: Boolean);
function GetPropertyID(const PropertyName: WideString): Integer;
procedure RecreateWnd;
procedure ViewChanged;
protected
{ Renamed methods }
function IPersistStreamInit.Load = PersistStreamLoad;
function IPersistStreamInit.Save = PersistStreamSave;
function IPersistStorage.InitNew = PersistStorageInitNew;
function IPersistStorage.Load = PersistStorageLoad;
function IPersistStorage.Save = PersistStorageSave;
function IViewObject2.GetExtent = ViewObjectGetExtent;
{ IPersist }
function GetClassID(out classID: TCLSID): HResult; stdcall;
{ IPersistStreamInit }
function IsDirty: HResult; stdcall;
function PersistStreamLoad(const stm: IStream): HResult; stdcall;
function PersistStreamSave(const stm: IStream;
fClearDirty: BOOL): HResult; stdcall;
function GetSizeMax(out cbSize: Largeint): HResult; stdcall;
function InitNew: HResult; stdcall;
{ IPersistStorage }
function PersistStorageInitNew(const stg: IStorage): HResult; stdcall;
function PersistStorageLoad(const stg: IStorage): HResult; stdcall;
function PersistStorageSave(const stgSave: IStorage;
fSameAsLoad: BOOL): HResult; stdcall;
function SaveCompleted(const stgNew: IStorage): HResult; stdcall;
function HandsOffStorage: HResult; stdcall;
{ IOleObject }
function SetClientSite(const clientSite: IOleClientSite): HResult;
stdcall;
function GetClientSite(out clientSite: IOleClientSite): HResult;
stdcall;
function SetHostNames(szContainerApp: POleStr;
szContainerObj: POleStr): HResult; stdcall;
function Close(dwSaveOption: Longint): HResult; stdcall;
function SetMoniker(dwWhichMoniker: Longint; const mk: IMoniker): HResult;
stdcall;
function GetMoniker(dwAssign: Longint; dwWhichMoniker: Longint;
out mk: IMoniker): HResult; stdcall;
function InitFromData(const dataObject: IDataObject; fCreation: BOOL;
dwReserved: Longint): HResult; stdcall;
function GetClipboardData(dwReserved: Longint;
out dataObject: IDataObject): HResult; stdcall;
function DoVerb(iVerb: Longint; msg: PMsg; const activeSite: IOleClientSite;
lindex: Longint; hwndParent: HWND; const posRect: TRect): HResult;
stdcall;
function EnumVerbs(out enumOleVerb: IEnumOleVerb): HResult; stdcall;
function Update: HResult; stdcall;
function IsUpToDate: HResult; stdcall;
function GetUserClassID(out clsid: TCLSID): HResult; stdcall;
function GetUserType(dwFormOfType: Longint; out pszUserType: POleStr): HResult;
stdcall;
function SetExtent(dwDrawAspect: Longint; const size: TPoint): HResult;
stdcall;
function GetExtent(dwDrawAspect: Longint; out size: TPoint): HResult;
stdcall;
function Advise(const advSink: IAdviseSink; out dwConnection: Longint): HResult;
stdcall;
function Unadvise(dwConnection: Longint): HResult; stdcall;
function EnumAdvise(out enumAdvise: IEnumStatData): HResult; stdcall;
function GetMiscStatus(dwAspect: Longint; out dwStatus: Longint): HResult;
stdcall;
function SetColorScheme(const logpal: TLogPalette): HResult; stdcall;
{ IOleControl }
function GetControlInfo(var ci: TControlInfo): HResult; stdcall;
function OnMnemonic(msg: PMsg): HResult; stdcall;
function OnAmbientPropertyChange(dispid: TDispID): HResult; stdcall;
function FreezeEvents(bFreeze: BOOL): HResult; stdcall;
{ IOleWindow }
function GetWindow(out wnd: HWnd): HResult; stdcall;
function ContextSensitiveHelp(fEnterMode: BOOL): HResult; stdcall;
{ IOleInPlaceObject }
function InPlaceDeactivate: HResult; stdcall;
function UIDeactivate: HResult; stdcall;
function SetObjectRects(const rcPosRect: TRect;
const rcClipRect: TRect): HResult; stdcall;
function ReactivateAndUndo: HResult; stdcall;
{ IOleInPlaceActiveObject }
function TranslateAccelerator(var msg: TMsg): HResult; stdcall;
function OnFrameWindowActivate(fActivate: BOOL): HResult; stdcall;
function OnDocWindowActivate(fActivate: BOOL): HResult; stdcall;
function ResizeBorder(const rcBorder: TRect; const uiWindow: IOleInPlaceUIWindow;
fFrameWindow: BOOL): HResult; stdcall;
function EnableModeless(fEnable: BOOL): HResult; stdcall;
{ IViewObject }
function Draw(dwDrawAspect: Longint; lindex: Longint; pvAspect: Pointer;
ptd: PDVTargetDevice; hicTargetDev: HDC; hdcDraw: HDC;
prcBounds: PRect; prcWBounds: PRect; fnContinue: TContinueFunc;
dwContinue: Longint): HResult; stdcall;
function GetColorSet(dwDrawAspect: Longint; lindex: Longint;
pvAspect: Pointer; ptd: PDVTargetDevice; hicTargetDev: HDC;
out colorSet: PLogPalette): HResult; stdcall;
function Freeze(dwDrawAspect: Longint; lindex: Longint; pvAspect: Pointer;
out dwFreeze: Longint): HResult; stdcall;
function Unfreeze(dwFreeze: Longint): HResult; stdcall;
function SetAdvise(aspects: Longint; advf: Longint;
const advSink: IAdviseSink): HResult; stdcall;
function GetAdvise(pAspects: PLongint; pAdvf: PLONGINT;
out advSink: IAdviseSink): HResult; stdcall;
{ IViewObject2 }
function ViewObjectGetExtent(dwDrawAspect: Longint; lindex: Longint;
ptd: PDVTargetDevice; out size: TPoint): HResult; stdcall;
{ IPerPropertyBrowsing }
function GetDisplayString(dispid: TDispID; out bstr: WideString): HResult; stdcall;
function MapPropertyToPage(dispid: TDispID; out clsid: TCLSID): HResult; stdcall;
function GetPredefinedStrings(dispid: TDispID; out caStringsOut: TCAPOleStr;
out caCookiesOut: TCALongint): HResult; stdcall;
function GetPredefinedValue(dispid: TDispID; dwCookie: Longint;
out varOut: OleVariant): HResult; stdcall;
{ ISpecifyPropertyPages }
function GetPages(out pages: TCAGUID): HResult; stdcall;
{ ISimpleFrameSite }
function PreMessageFilter(wnd: HWnd; msg, wp, lp: Integer;
out res: Integer; out Cookie: Longint): HResult; stdcall;
function PostMessageFilter(wnd: HWnd; msg, wp, lp: Integer;
out res: Integer; Cookie: Longint): HResult; stdcall;
{ Standard properties }
function Get_BackColor: Integer; safecall;
function Get_Caption: WideString; safecall;
function Get_Enabled: WordBool; safecall;
function Get_Font: Font; safecall;
function Get_ForeColor: Integer; safecall;
function Get_HWnd: Integer; safecall;
function Get_TabStop: WordBool; safecall;
function Get_Text: WideString; safecall;
procedure Set_BackColor(Value: Integer); safecall;
procedure Set_Caption(const Value: WideString); safecall;
procedure Set_Enabled(Value: WordBool); safecall;
procedure Set_Font(const Value: Font); safecall;
procedure Set_ForeColor(Value: Integer); safecall;
procedure Set_TabStop(Value: WordBool); safecall;
procedure Set_Text(const Value: WideString); safecall;
{ Standard event handlers }
procedure StdClickEvent(Sender: TObject);
procedure StdDblClickEvent(Sender: TObject);
procedure StdKeyDownEvent(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StdKeyPressEvent(Sender: TObject; var Key: Char);
procedure StdKeyUpEvent(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StdMouseDownEvent(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure StdMouseMoveEvent(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure StdMouseUpEvent(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
{ Helper methods }
function InPlaceActivate(ActivateUI: Boolean): HResult;
procedure ShowPropertyDialog;
{ Overrideable methods }
procedure DefinePropertyPages(
DefinePropertyPage: TDefinePropertyPage); virtual;
procedure EventSinkChanged(const EventSink: IUnknown); virtual;
function GetPropertyString(DispID: Integer;
var S: string): Boolean; virtual;
function GetPropertyStrings(DispID: Integer;
Strings: TStrings): Boolean; virtual;
procedure GetPropertyValue(DispID, Cookie: Integer;
var Value: OleVariant); virtual;
procedure InitializeControl; virtual;
procedure LoadFromStream(const Stream: IStream); virtual;
procedure PerformVerb(Verb: Integer); virtual;
procedure SaveToStream(const Stream: IStream); virtual;
procedure WndProc(var Message: TMessage); virtual;
public
destructor Destroy; override;
procedure Initialize; override;
function ObjQueryInterface(const IID: TGUID; out Obj): Integer; override;
function PropRequestEdit(const PropertyName: WideString): Boolean;
procedure PropChanged(const PropertyName: WideString);
property Control: TWinControl read FControl;
end;
TActiveXControlClass = class of TActiveXControl;
TActiveXControlFactory = class(TAutoObjectFactory)
private
FWinControlClass: TWinControlClass;
FMiscStatus: Integer;
FToolboxBitmapID: Integer;
FEventTypeInfo: ITypeInfo;
FEventIID: TGUID;
FVerbs: TStringList;
FLicFileStrings: TStringList;
FLicenseFileRead: Boolean;
protected
function GetLicenseFileName: string; virtual;
function HasMachineLicense: Boolean; override;
public
constructor Create(ComServer: TComServerObject;
ActiveXControlClass: TActiveXControlClass;
WinControlClass: TWinControlClass; const ClassID: TGUID;
ToolboxBitmapID: Integer; const LicStr: string; MiscStatus: Integer);
destructor Destroy; override;
procedure AddVerb(Verb: Integer; const VerbName: string);
procedure UpdateRegistry(Register: Boolean); override;
property EventIID: TGUID read FEventIID;
property EventTypeInfo: ITypeInfo read FEventTypeInfo;
property MiscStatus: Integer read FMiscStatus;
property ToolboxBitmapID: Integer read FToolboxBitmapID;
property WinControlClass: TWinControlClass read FWinControlClass;
end;
{ ActiveFormControl }
TActiveFormControl = class(TActiveXControl, IVCLComObject)
protected
procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
procedure EventSinkChanged(const EventSink: IUnknown); override;
public
procedure FreeOnRelease;
procedure InitializeControl; override;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult;
override;
function ObjQueryInterface(const IID: TGUID; out Obj): Integer; override;
end;
{ ActiveForm }
TActiveFormBorderStyle = (afbNone, afbSingle, afbSunken, afbRaised);
TActiveForm = class(TCustomForm)
private
FAxBorderStyle: TActiveFormBorderStyle;
procedure SetAxBorderStyle(Value: TActiveFormBorderStyle);
protected
procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); virtual;
procedure CreateParams(var Params: TCreateParams); override;
procedure EventSinkChanged(const EventSink: IUnknown); virtual;
procedure Initialize; virtual;
public
constructor Create(AOwner: TComponent); override;
function WantChildKey(Child: TControl; var Message: TMessage): Boolean; override;
published
property ActiveControl;
property AutoScroll;
property AxBorderStyle: TActiveFormBorderStyle read FAxBorderStyle
write SetAxBorderStyle default afbSingle;
property Caption stored True;
property Color;
property Font;
property Height stored True;
property HorzScrollBar;
property KeyPreview;
property PixelsPerInch;
property PopupMenu;
property PrintScale;
property Scaled;
property ShowHint;
property VertScrollBar;
property Width stored True;
property OnActivate;
property OnClick;
property OnCreate;
property OnDblClick;
property OnDestroy;
property OnDeactivate;
property OnDragDrop;
property OnDragOver;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnPaint;
end;
TActiveFormClass = class of TActiveForm;
{ ActiveFormFactory }
TActiveFormFactory = class(TActiveXControlFactory)
public
function GetIntfEntry(Guid: TGUID): PInterfaceEntry; override;
end;
{ Property Page support }
TActiveXPropertyPage = class;
TPropertyPage = class(TCustomForm)
private
FActiveXPropertyPage: TActiveXPropertyPage;
FOleObject: Variant;
procedure CMChanged(var Msg: TCMChanged); message CM_CHANGED;
public
procedure Modified;
procedure UpdateObject; virtual;
procedure UpdatePropertyPage; virtual;
property OleObject: Variant read FOleObject;
procedure EnumCtlProps(PropType: TGUID; PropNames: TStrings);
published
property ActiveControl;
property AutoScroll;
property Caption;
property ClientHeight;
property ClientWidth;
property Ctl3D;
property Color;
property Enabled;
property Font;
property Height;
property HorzScrollBar;
property KeyPreview;
property PixelsPerInch;
property ParentFont;
property PopupMenu;
property PrintScale;
property Scaled;
property ShowHint;
property VertScrollBar;
property Visible;
property Width;
property OnActivate;
property OnClick;
property OnClose;
property OnCreate;
property OnDblClick;
property OnDestroy;
property OnDeactivate;
property OnDragDrop;
property OnDragOver;
property OnHide;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnPaint;
property OnResize;
property OnShow;
end;
TPropertyPageClass = class of TPropertyPage;
TActiveXPropertyPage = class(TComObject,
IPropertyPage,
IPropertyPage2)
private
FPropertyPage: TPropertyPage;
FPageSite: IPropertyPageSite;
FActive: Boolean;
FModified: Boolean;
procedure Modified;
protected
{ IPropertyPage }
function SetPageSite(const pageSite: IPropertyPageSite): HResult; stdcall;
function Activate(hwndParent: HWnd; const rc: TRect; bModal: BOOL): HResult;
stdcall;
function Deactivate: HResult; stdcall;
function GetPageInfo(out pageInfo: TPropPageInfo): HResult; stdcall;
function SetObjects(cObjects: Longint; pUnkList: PUnknownList): HResult; stdcall;
function Show(nCmdShow: Integer): HResult; stdcall;
function Move(const rect: TRect): HResult; stdcall;
function IsPageDirty: HResult; stdcall;
function Apply: HResult; stdcall;
function Help(pszHelpDir: POleStr): HResult; stdcall;
function TranslateAccelerator(msg: PMsg): HResult; stdcall;
{ IPropertyPage2 }
function EditProperty(dispid: TDispID): HResult; stdcall;
public
destructor Destroy; override;
procedure Initialize; override;
end;
TActiveXPropertyPageFactory = class(TComObjectFactory)
protected
function CreateComObject(const Controller: IUnknown): TComObject; override;
public
constructor Create(ComServer: TComServerObject;
PropertyPageClass: TPropertyPageClass; const ClassID: TGUID);
end;
{ Type adapter support }
TCustomAdapter = class(TInterfacedObject)
private
FOleObject: IUnknown;
FConnection: Longint;
FNotifier: IUnknown;
protected
Updating: Boolean;
procedure Changed; virtual;
procedure ConnectOleObject(OleObject: IUnknown);
procedure ReleaseOleObject;
procedure Update; virtual; abstract;
public
constructor Create;
destructor Destroy; override;
end;
TAdapterNotifier = class(TInterfacedObject,
IPropertyNotifySink)
private
FAdapter: TCustomAdapter;
protected
{ IPropertyNotifySink }
function OnChanged(dispid: TDispID): HResult; stdcall;
function OnRequestEdit(dispid: TDispID): HResult; stdcall;
public
constructor Create(Adapter: TCustomAdapter);
end;
IFontAccess = interface
['{CBA55CA0-0E57-11D0-BD2F-0020AF0E5B81}']
procedure GetOleFont(var OleFont: IFontDisp);
procedure SetOleFont(const OleFont: IFontDisp);
end;
TFontAdapter = class(TCustomAdapter,
IChangeNotifier,
IFontAccess)
private
FFont: TFont;
protected
{ IFontAccess }
procedure GetOleFont(var OleFont: IFontDisp);
procedure SetOleFont(const OleFont: IFontDisp);
procedure Changed; override;
procedure Update; override;
public
constructor Create(Font: TFont);
end;
IPictureAccess = interface
['{795D4D31-43D7-11D0-9E92-0020AF3D82DA}']
procedure GetOlePicture(var OlePicture: IPictureDisp);
procedure SetOlePicture(const OlePicture: IPictureDisp);
end;
TPictureAdapter = class(TCustomAdapter,
IChangeNotifier,
IPictureAccess)
private
FPicture: TPicture;
protected
{ IPictureAccess }
procedure GetOlePicture(var OlePicture: IPictureDisp);
procedure SetOlePicture(const OlePicture: IPictureDisp);
procedure Update; override;
public
constructor Create(Picture: TPicture);
end;
TOleGraphic = class(TGraphic)
private
FPicture: IPicture;
function GetMMHeight: Integer;
function GetMMWidth: Integer;
protected
procedure Changed(Sender: TObject); override;
procedure Draw(ACanvas: TCanvas; const Rect: TRect); override;
function GetEmpty: Boolean; override;
function GetHeight: Integer; override;
function GetPalette: HPALETTE; override;
function GetTransparent: Boolean; override;
function GetWidth: Integer; override;
procedure SetHeight(Value: Integer); override;
procedure SetPalette(Value: HPALETTE); override;
procedure SetWidth(Value: Integer); override;
public
procedure Assign(Source: TPersistent); override;
procedure LoadFromFile(const Filename: string); override;
procedure LoadFromStream(Stream: TStream); override;
procedure SaveToStream(Stream: TStream); override;
procedure LoadFromClipboardFormat(AFormat: Word; AData: THandle;
APalette: HPALETTE); override;
procedure SaveToClipboardFormat(var AFormat: Word; var AData: THandle;
var APalette: HPALETTE); override;
property MMHeight: Integer read GetMMHeight; // in .01 mm units
property MMWidth: Integer read GetMMWidth;
property Picture: IPicture read FPicture write FPicture;
end;
TStringsAdapter = class(TAutoIntfObject, IStrings, IStringsAdapter)
private
FStrings: TStrings;
protected
{ IStringsAdapter }
procedure ReferenceStrings(S: TStrings);
procedure ReleaseStrings;
{ IStrings }
function Get_ControlDefault(Index: Integer): OleVariant; safecall;
procedure Set_ControlDefault(Index: Integer; Value: OleVariant); safecall;
function Count: Integer; safecall;
function Get_Item(Index: Integer): OleVariant; safecall;
procedure Set_Item(Index: Integer; Value: OleVariant); safecall;
procedure Remove(Index: Integer); safecall;
procedure Clear; safecall;
function Add(Item: OleVariant): Integer; safecall;
function _NewEnum: IUnknown; safecall;
public
constructor Create(Strings: TStrings);
end;
procedure GetOleFont(Font: TFont; var OleFont: IFontDisp);
procedure SetOleFont(Font: TFont; const OleFont: IFontDisp);
procedure GetOlePicture(Picture: TPicture; var OlePicture: IPictureDisp);
procedure SetOlePicture(Picture: TPicture; const OlePicture: IPictureDisp);
procedure GetOleStrings(Strings: TStrings; var OleStrings: IStrings);
procedure SetOleStrings(Strings: TStrings; const OleStrings: IStrings);
implementation
const
OCM_BASE = $2000;
type
TWinControlAccess = class(TWinControl);
IStdEvents = dispinterface
['{00020400-0000-0000-C000-000000000046}']
procedure Click; dispid DISPID_CLICK;
procedure DblClick; dispid DISPID_DBLCLICK;
procedure KeyDown(var KeyCode: Smallint;
Shift: Smallint); dispid DISPID_KEYDOWN;
procedure KeyPress(var KeyAscii: Smallint); dispid DISPID_KEYPRESS;
procedure KeyUp(var KeyCode: Smallint;
Shift: Smallint); dispid DISPID_KEYDOWN;
procedure MouseDown(Button, Shift: Smallint;
X, Y: Integer); dispid DISPID_MOUSEDOWN;
procedure MouseMove(Button, Shift: Smallint;
X, Y: Integer); dispid DISPID_MOUSEMOVE;
procedure MouseUp(Button, Shift: Smallint;
X, Y: Integer); dispid DISPID_MOUSEUP;
end;
var
xParkingWindow: HWnd;
{ Dynamically load functions used in OLEPRO32.DLL }
function OleCreatePropertyFrame(hwndOwner: HWnd; x, y: Integer;
lpszCaption: POleStr; cObjects: Integer; pObjects: Pointer; cPages: Integer;
pPageCLSIDs: Pointer; lcid: TLCID; dwReserved: Longint;
pvReserved: Pointer): HResult; forward;
function OleCreateFontIndirect(const FontDesc: TFontDesc; const iid: TIID;
out vObject): HResult; forward;
function OleCreatePictureIndirect(const PictDesc: TPictDesc; const iid: TIID;
fOwn: BOOL; out vObject): HResult; forward;
function OleLoadPicture(stream: IStream; lSize: Longint; fRunmode: BOOL;
const iid: TIID; out vObject): HResult; forward;
function ParkingWindowProc(Wnd: HWND; Msg, wParam, lParam: Longint): Longint; stdcall;
var
ControlWnd: HWND;
begin
case Msg of
WM_COMPAREITEM, WM_DELETEITEM, WM_DRAWITEM, WM_MEASUREITEM, WM_COMMAND:
begin
case Msg of
WM_COMPAREITEM: ControlWnd := PCompareItemStruct(lParam).CtlID;
WM_DELETEITEM: ControlWnd := PDeleteItemStruct(lParam).CtlID;
WM_DRAWITEM: ControlWnd := PDrawItemStruct(lParam).CtlID;
WM_MEASUREITEM: ControlWnd := PMeasureItemStruct(lParam).CtlID;
WM_COMMAND: ControlWnd := HWND(lParam);
else
Result := 0;
Exit;
end;
Result := SendMessage(ControlWnd, OCM_BASE + Msg, wParam, lParam);
end;
else
Result := DefWindowProc(Wnd, Msg, WParam, LParam);
end;
end;
function ParkingWindow: HWnd;
var
TempClass: TWndClass;
begin
Result := xParkingWindow;
if Result <> 0 then Exit;
FillChar(TempClass, sizeof(TempClass), 0);
if not GetClassInfo(HInstance, 'DAXParkingWindow', TempClass) then
begin
TempClass.hInstance := HInstance;
TempClass.lpfnWndProc := @ParkingWindowProc;
TempClass.lpszClassName := 'DAXParkingWindow';
if Windows.RegisterClass(TempClass) = 0 then
raise EOutOfResources.Create(SWindowClass);
end;
xParkingWindow := CreateWindowEx(WS_EX_TOOLWINDOW, TempClass.lpszClassName, nil,
WS_POPUP, GetSystemMetrics(SM_CXSCREEN) div 2,
GetSystemMetrics(SM_CYSCREEN) div 2, 0, 0, 0, 0, HInstance, nil);
SetWindowPos(xParkingWindow, 0, 0, 0, 0, 0, SWP_NOACTIVATE or SWP_NOREDRAW
or SWP_NOZORDER or SWP_SHOWWINDOW);
Result := xParkingWindow;
end;
function HandleException: HResult;
var
E: TObject;
begin
E := ExceptObject;
if (E is EOleSysError) and (EOleSysError(E).ErrorCode < 0) then
Result := EOleSysError(E).ErrorCode else
Result := E_UNEXPECTED;
end;
procedure FreeObjects(List: TList);
var
I: Integer;
begin
for I := List.Count - 1 downto 0 do TObject(List[I]).Free;
end;
procedure FreeObjectList(List: TList);
begin
if List <> nil then
begin
FreeObjects(List);
List.Free;
end;
end;
function CoAllocMem(Size: Integer): Pointer;
begin
Result := CoTaskMemAlloc(Size);
if Result = nil then OleError(E_OUTOFMEMORY);
FillChar(Result^, Size, 0);
end;
procedure CoFreeMem(P: Pointer);
begin
if P <> nil then CoTaskMemFree(P);
end;
function CoAllocString(const S: string): POleStr;
var
W: WideString;
Size: Integer;
begin
W := S;
Size := (Length(W) + 1) * 2;
Result := CoAllocMem(Size);
Move(PWideChar(W)^, Result^, Size);
end;
{ Connect an IConnectionPoint interface }
procedure InterfaceConnect(const Source: IUnknown; const IID: TIID;
const Sink: IUnknown; var Connection: Longint);
var
CPC: IConnectionPointContainer;
CP: IConnectionPoint;
begin
Connection := 0;
if Source.QueryInterface(IConnectionPointContainer, CPC) >= 0 then
if CPC.FindConnectionPoint(IID, CP) >= 0 then
CP.Advise(Sink, Connection);
end;
{ Disconnect an IConnectionPoint interface }
procedure InterfaceDisconnect(const Source: IUnknown; const IID: TIID;
var Connection: Longint);
var
CPC: IConnectionPointContainer;
CP: IConnectionPoint;
begin
if Connection <> 0 then
if Source.QueryInterface(IConnectionPointContainer, CPC) >= 0 then
if CPC.FindConnectionPoint(IID, CP) >= 0 then
if CP.Unadvise(Connection) >= 0 then Connection := 0;
end;
function GetFontAccess(Font: TFont): IFontAccess;
begin
if Font.FontAdapter = nil then
Font.FontAdapter := TFontAdapter.Create(Font);
Result := Font.FontAdapter as IFontAccess;
end;
function GetPictureAccess(Picture: TPicture): IPictureAccess;
begin
if Picture.PictureAdapter = nil then
Picture.PictureAdapter := TPictureAdapter.Create(Picture);
Result := Picture.PictureAdapter as IPictureAccess;
end;
procedure GetOleFont(Font: TFont; var OleFont: IFontDisp);
begin
GetFontAccess(Font).GetOleFont(OleFont);
end;
procedure SetOleFont(Font: TFont; const OleFont: IFontDisp);
begin
GetFontAccess(Font).SetOleFont(OleFont);
end;
procedure GetOlePicture(Picture: TPicture; var OlePicture: IPictureDisp);
begin
GetPictureAccess(Picture).GetOlePicture(OlePicture);
end;
procedure SetOlePicture(Picture: TPicture; const OlePicture: IPictureDisp);
begin
GetPictureAccess(Picture).SetOlePicture(OlePicture);
end;
function GetKeyModifiers: Integer;
begin
Result := 0;
if GetKeyState(VK_SHIFT) < 0 then Result := 1;
if GetKeyState(VK_CONTROL) < 0 then Result := Result or 2;
if GetKeyState(VK_MENU) < 0 then Result := Result or 4;
end;
function GetEventShift(Shift: TShiftState): Integer;
const
ShiftMap: array[0..7] of Byte = (0, 1, 4, 5, 2, 3, 6, 7);
begin
Result := ShiftMap[Byte(Shift) and 7];
end;
function GetEventButton(Button: TMouseButton): Integer;
begin
Result := 1 shl Ord(Button);
end;
{ TOleStream }
constructor TOleStream.Create(const Stream: IStream);
begin
FStream := Stream;
end;
function TOleStream.Read(var Buffer; Count: Longint): Longint;
begin
OleCheck(FStream.Read(@Buffer, Count, @Result));
end;
function TOleStream.Seek(Offset: Longint; Origin: Word): Longint;
var
Pos: Largeint;
begin
OleCheck(FStream.Seek(Offset, Origin, Pos));
Result := Longint(Pos);
end;
function TOleStream.Write(const Buffer; Count: Longint): Longint;
begin
OleCheck(FStream.Write(@Buffer, Count, @Result));
end;
{ TAggregatedObject }
constructor TAggregatedObject.Create(const Controller: IUnknown);
begin
FController := Pointer(Controller);
end;
function TAggregatedObject.GetController: IUnknown;
begin
Result := IUnknown(FController);
end;
{ TAggregatedObject.IUnknown }
function TAggregatedObject.QueryInterface(const IID: TGUID; out Obj): Integer;
begin
Result := IUnknown(FController).QueryInterface(IID, Obj);
end;
function TAggregatedObject._AddRef: Integer;
begin
Result := IUnknown(FController)._AddRef;
end;
function TAggregatedObject._Release: Integer; stdcall;
begin
Result := IUnknown(FController)._Release;
end;
{ TContainedObject.IUnknown }
function TContainedObject.QueryInterface(const IID: TGUID; out Obj): Integer;
begin
if GetInterface(IID, Obj) then Result := S_OK else Result := E_NOINTERFACE;
end;
{ TEnumConnections }
type
TEnumConnections = class(TContainedObject, IEnumConnections)
private
FConnectionPoint: TConnectionPoint;
FIndex: Integer;
FCount: Integer;
protected
{ IEnumConnections }
function Next(celt: Longint; out elt; pceltFetched: PLongint): HResult; stdcall;
function Skip(celt: Longint): HResult; stdcall;
function Reset: HResult; stdcall;
function Clone(out enum: IEnumConnections): HResult; stdcall;
public
constructor Create(ConnectionPoint: TConnectionPoint; Index: Integer);
end;
constructor TEnumConnections.Create(ConnectionPoint: TConnectionPoint;
Index: Integer);
begin
inherited Create(ConnectionPoint.Controller);
FConnectionPoint := ConnectionPoint;
FIndex := Index;
FCount := ConnectionPoint.FSinkList.Count;
end;
{ TEnumConnections.IEnumConnections }
function TEnumConnections.Next(celt: Longint; out elt;
pceltFetched: PLongint): HResult;
type
TConnectDatas = array[0..1023] of TConnectData;
var
I: Integer;
P: Pointer;
begin
I := 0;
while (I < celt) and (FIndex < FCount) do
begin
P := FConnectionPoint.FSinkList[FIndex];
if P <> nil then
begin
Pointer(TConnectDatas(elt)[I].pUnk) := nil;
TConnectDatas(elt)[I].pUnk := IUnknown(P);
TConnectDatas(elt)[I].dwCookie := FIndex + 1;
Inc(I);
end;
Inc(FIndex);
end;
if pceltFetched <> nil then pceltFetched^ := I;