home *** CD-ROM | disk | FTP | other *** search
- {*******************************************************}
- { }
- { Delphi Visual Component Library }
- { }
- { Copyright (c) 1995 Borland International }
- { }
- {*******************************************************}
-
- {$N+}
-
- unit VBXCtrl;
-
- interface
-
- uses Classes, Controls, Forms, Messages, Graphics, WinTypes, BIVBX,
- SysUtils;
-
- const
- VBXUpdateMsg: Word = 0;
-
- type
- EVBXError = class(Exception);
-
- TVBEnum = 0..255;
- TVBString = string[255];
- TBasicString = ^Word;
- TCString = ^Char;
- TVBControlRef = ^Byte;
- TVBInteger = -32768..32767;
- TVBLongint = $80000000..$7FFFFFFF;
- TVBPic = HPic;
- TVBXFlag = (vfProcessMnemonic, vfArrows, vfLoadMessage);
- TVBXFlags = set of TVBXFlag;
-
- TVBXControl = class(TWinControl)
- protected
- FVBXFile: PChar;
- FVBXClass: PChar;
- FVBXFlags: TVBXFlags;
-
- { Low-level property access }
- procedure GetArrayProp(aIndex, pIndex: Integer;
- var ElementStruct: TElementStruct);
- function GetBoolArrayProp(aIndex, pIndex: Integer): Boolean;
- function GetBoolProp(pIndex: Integer): Boolean;
- function GetBStringArrayProp(aIndex, pIndex: Integer): TVBString;
- function GetBStringProp(pIndex: Integer): TVBString;
- function GetColorArrayProp(aIndex, pIndex: Integer): TColor;
- function GetColorProp(pIndex: Integer): TColor;
- function GetEnumArrayProp(aIndex, pIndex: Integer): TVBEnum;
- function GetEnumProp(pIndex: Integer): TVBEnum;
- function GetIntArrayProp(aIndex, pIndex: Integer): TVBInteger;
- function GetIntProp(pIndex: Integer): TVBInteger;
- function GetLongArrayProp(aIndex, pIndex: Integer): TVBLongint;
- function GetLongProp(pIndex: Integer): TVBLongint;
- function GetPictureArrayProp(aIndex, pIndex: Integer): TVBPic;
- function GetPictureProp(pIndex: Integer): TVBPic;
- procedure GetProp(pIndex: Integer; var Value);
- function GetSingleArrayProp(aIndex, pIndex: Integer): Single;
- function GetSingleProp(pIndex: Integer): Single;
- function GetStringArrayProp(aIndex, pIndex: Integer): TVBString;
- function GetStringProp(pIndex: Integer): TVBString;
- procedure SetArrayProp(aIndex, pIndex: Integer;
- var ElementStruct: TElementStruct);
- procedure SetBoolArrayProp(aIndex, pIndex: Integer; Value: Boolean);
- procedure SetBoolProp(pIndex: Integer; Value: Boolean);
- procedure SetBStringArrayProp(aIndex, pIndex: Integer; const Value: TVBString);
- procedure SetBStringProp(pIndex: Integer; const Value: TVBString);
- procedure SetColorArrayProp(aIndex, pIndex: Integer; AColor: TColor);
- procedure SetColorProp(pIndex: Integer; AColor: TColor);
- procedure SetEnumArrayProp(aIndex, pIndex: Integer; Value: TVBEnum);
- procedure SetEnumProp(pIndex: Integer; Value: TVBEnum);
- procedure SetIntArrayProp(aIndex, pIndex: Integer; Value: TVBInteger);
- procedure SetIntProp(pIndex: Integer; Value: TVBInteger);
- procedure SetLongArrayProp(aIndex, pIndex: Integer; Value: TVBLongint);
- procedure SetPictureArrayProp(aIndex, pIndex: Integer; Value: TVBPic);
- procedure SetPictureProp(pIndex: Integer; Value: TVBPic);
- procedure SetProp(pIndex: Integer; Value: TVBLongint);
- procedure SetSingleArrayProp(aIndex, pIndex: Integer; Value: Single);
- procedure SetSingleProp(pIndex: Integer; Value: Single);
- procedure SetStringArrayProp(aIndex, pIndex: Integer; const Value: TVBString);
- procedure SetStringProp(pIndex: Integer; const Value: TVBString);
-
- { Low-level event method pointer dispatchers }
- procedure DispatchCustomEvent(const Event;
- var VBXEvent: TWMVBXFireEvent; eIndex: Integer);
- procedure DispatchKeyEvent(const Event: TKeyEvent;
- var VBXEvent: TWMVBXFireEvent);
- procedure DispatchKeyPressedEvent(const Event: TKeyPressEvent;
- var VBXEvent: TWMVBXFireEvent);
- procedure DispatchMouseEvent(const Event: TMouseEvent;
- var VBXEvent: TWMVBXFireEvent);
- procedure DispatchMouseMoveEvent(const Event: TMouseMoveEvent;
- var VBXEvent: TWMVBXFireEvent);
- procedure DispatchNotifyEvent(const Event: TNotifyEvent);
-
- { Event handler }
- procedure HandleVBXEvent(var Message: TWMVBXFireEvent); virtual;
-
- { Control updating }
- procedure CMVisibleChanged(var Message: TMessage); message CM_VISIBLECHANGED;
- procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
- procedure SetName(const NewName: TComponentName); override;
-
- { VBX control streaming }
- procedure DefineProperties(Filer: TFiler); override;
- procedure HandleBinaryProperty(const Name: string; Filer: TFiler; pIndex: Integer);
- procedure HandleProperty(const Name: string; Filer: TFiler; pIndex: Integer);
- procedure ReadHForm(Stream: TStream);
- procedure ReadState(Reader: TReader); override;
- procedure WriteHForm(Stream: TStream);
- procedure Loaded; override;
-
- { VBX Handle control }
- procedure AllocateControl;
- function VBXCreated: Boolean;
- procedure CreateWnd; override;
- procedure DestroyWindowHandle; override;
- procedure WndProc(var Message: TMessage); override;
-
- { Squelch VCL's processing of these events }
- procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer); override;
- procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
- procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer); override;
- procedure KeyDown(var Key: Word; Shift: TShiftState); override;
- procedure KeyUp(var Key: Word; Shift: TShiftState); override;
- procedure KeyPress(var Key: Char); override;
-
- procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
- procedure CMWantSpecialKey(var Message: TCMWantSpecialKey); message CM_WANTSPECIALKEY;
- procedure CNCtlColor(var Message: TWMCtlColor); message CN_CTLCOLOR;
- procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
- procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
- procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
-
- { List access methods - These will raise an exception if the underlying
- VBX control does not support them.
-
- AddItem - same as "form.control.AddItem item" in VB
- InsertItem - same as "form.control.AddItem item, index" in VB
- RemoveItem - same as "form.control.RemoveItem item" in VB
- Clear - same as "form.control.Clear" in VB
- }
- procedure AddItem(const Item: string);
- procedure InsertItem(Index: Integer; const Item: string);
- procedure RemoveItem(Index: Integer);
- procedure Clear;
-
- property Ctl: HCTL;
- property VBXFile: PChar;
- property VBXClass: PChar;
- end;
-
- procedure InitBIVBX;
- procedure TermBIVBX;
- function VBXButtonShiftToShift(VBXShift, VBXButton: Integer): TShiftState;
- function VBXButtonToButton(VBXButton: Integer): TMouseButton;
- function BStrPas(BasicStr: TBasicString): string;
- function BStrPCopy(const Str: string): TBasicString;
- procedure SetBStr(var BasicStr: TBasicString; const Str: string);
- function CStrPas(CStr: TCString): string;
-
- implementation
-