/Components/EhLib 4.2/Common/ToolCtrlsEh.pas
Pascal | 1897 lines | 1560 code | 183 blank | 154 comment | 174 complexity | 10995667b0549dc887a299b27712be12 MD5 | raw file
Possible License(s): AGPL-3.0
Large files files are truncated, but you can click here to view the full file
- {*******************************************************}
- { }
- { EhLib v4.2 }
- { Tool controls }
- { (Build 4.2.05) }
- { }
- { Copyright (c) 2001-2006 by Dmitry V. Bolshakov }
- { }
- {*******************************************************}
- {$I EhLib.Inc}
- {$IFDEF EH_LIB_VCL}
- unit ToolCtrlsEh {$IFDEF CIL} platform {$ENDIF};
- {$ELSE}
- unit QToolCtrlsEh;
- {$ENDIF}
- interface
- {$IFDEF EH_LIB_VCL}
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- {$IFDEF EH_LIB_5} Contnrs, ActnList, {$ENDIF}
- {$IFDEF EH_LIB_6} Variants, {$ENDIF}
- {$IFDEF CIL}
- EhLibVCLNET,
- {$ELSE}
- EhLibVCL,
- {$ENDIF}
- StdCtrls, Mask, Db, DBCtrls, Buttons, ExtCtrls, Menus, ComCtrls, CommCtrl,
- Imglist;
- {$ELSE}
- uses
- QGraphics, QControls, QForms, QDialogs, Variants, QStdCtrls, QMask,
- QDBCtrls, QButtons, QExtCtrls, QMenus, QComCtrls, QImglist,
- Db, SysUtils, Classes;
- {$ENDIF}
- const
- CM_IGNOREEDITDOWN = WM_USER + 102;
- type
- TLocateTextOptionEh = (ltoCaseInsensitiveEh, ltoAllFieldsEh, ltoMatchFormatEh, ltoIgnoteCurrentPosEh);
- TLocateTextOptionsEh = set of TLocateTextOptionEh;
- TLocateTextDirectionEh = (ltdUpEh, ltdDownEh, ltdAllEh);
- TLocateTextMatchingEh = (ltmAnyPartEh, ltmWholeEh, ltmFromBegingEh);
- TLocateTextTreeFindRangeEh = (lttInAllNodesEh, lttInExpandedNodesEh,
- lttInCurrentLevelEh, lttInCurrentNodeEh);
- IMemTableDataFieldValueListEh = interface
- ['{28F8194C-5FF3-42C4-87A6-8B3E06210FA6}']
- function GetValues: TStrings;
- end;
- IMemTableEh = interface
- ['{A8C3C87A-E556-4BDB-B8A7-5B33497D1624}']
- // property TreeViewMode: Boolean read GetTreeViewMode write SetTreeViewMode;
- function FetchRecords(Count: Integer): Integer;
- function GetInstantReadCurRowNum: Integer;
- function GetTreeNodeExpanded(RowNum: Integer): Boolean; overload;
- function GetTreeNodeExpanded: Boolean; overload;
- function GetTreeNodeHasChields: Boolean;
- function GetTreeNodeLevel: Integer;
- function GetPrevVisibleTreeNodeLevel: Integer;
- function GetNextVisibleTreeNodeLevel: Integer;
- function GetRecObject: TObject;
- function InstantReadIndexOfBookmark(Bookmark: TBookmarkStr): Integer;
- function InstantReadRowCount: Integer;
- function MemTableIsTreeList: Boolean;
- function ParentHasNextSibling(ParenLevel: Integer): Boolean;
- function SetToRec(Rec: TObject): Boolean;
- function SetTreeNodeExpanded(RowNum: Integer; Value: Boolean): Integer;
- function GetFieldValueList(FieldName: String): IMemTableDataFieldValueListEh;
- function MoveRecords(BookmarkList: TStrings; ToRecNo: Longint; TreeLevel: Integer; CheckOnly: Boolean): Boolean;
- procedure InstantReadEnter(RowNum: Integer);
- procedure InstantReadLeave;
- property InstantReadCurRowNum: Integer read GetInstantReadCurRowNum;
- // property TreeNodeCollapsed: Boolean read GetTreeNodeCollapsed write SetTreeNodeCollapsed;
- end;
- IComboEditEh = interface
- ['{B64255B5-386A-4524-8BC7-7F49DDB410F4}']
- procedure CloseUp(Accept: Boolean);
- end;
- TFieldsArrEh = array of TField;
- { Standard events }
- TButtonClickEventEh = procedure(Sender: TObject; var Handled: Boolean) of object;
- TButtonDownEventEh = procedure(Sender: TObject; TopButton: Boolean;
- var AutoRepeat: Boolean; var Handled: Boolean) of object;
- TCloseUpEventEh = procedure(Sender: TObject; Accept: Boolean) of object;
- TAcceptEventEh = procedure(Sender: TObject; var Accept: Boolean) of object;
- TNotInListEventEh = procedure(Sender: TObject; NewText: String;
- var RecheckInList: Boolean) of object;
- TUpdateDataEventEh = procedure(Sender: TObject; var Handled: Boolean) of object;
- { TBMListEh }
- TBMListEh = class
- private
- FCache: TBookmarkStr;
- FCacheFind: Boolean;
- FCacheIndex: Integer;
- FLinkActive:boolean;
- function GetCount: Integer;
- function GetCurrentRowSelected: Boolean;
- function GetItem(Index: Integer): TBookmarkStr;
- protected
- FList: TStringList;
- function Compare(const Item1, Item2: TBookmarkStr): Integer;
- function CurrentRow: TBookmarkStr;
- function GetDataSet:TDataSet; virtual; abstract;
- procedure Invalidate; virtual;
- procedure LinkActive(Value: Boolean);
- procedure RaiseBMListError(const S: string); virtual;
- procedure SetCurrentRowSelected(Value: Boolean); virtual;
- procedure StringsChanged(Sender: TObject); virtual;
- procedure UpdateState; virtual;
- public
- constructor Create;
- destructor Destroy; override;
- function Find(const Item: TBookmarkStr; var Index: Integer): Boolean;
- function IndexOf(const Item: TBookmarkStr): Integer;
- function Refresh: Boolean;
- procedure Clear; virtual;
- procedure Delete;
- procedure SelectAll;
- property Count: Integer read GetCount;
- property CurrentRowSelected: Boolean read GetCurrentRowSelected write SetCurrentRowSelected;
- property DataSet:TDataSet read GetDataSet;
- property Items[Index: Integer]: TBookmarkStr read GetItem; default;
- end;
- { TEditButtonControlEh }
- TEditButtonStyleEh = (ebsDropDownEh, ebsEllipsisEh, ebsGlyphEh, ebsUpDownEh,
- ebsPlusEh, ebsMinusEh);
- TEditButtonControlEh = class(TSpeedButton)
- private
- FActive: Boolean;
- FAlwaysDown: Boolean;
- FButtonNum: Integer;
- FNoDoClick: Boolean;
- FOnDown: TButtonDownEventEh;
- FStyle: TEditButtonStyleEh;
- FTimer: TTimer;
- function GetTimer: TTimer;
- procedure ResetTimer(Interval: Cardinal);
- procedure SetActive(const Value: Boolean);
- procedure SetAlwaysDown(const Value: Boolean);
- procedure SetStyle(const Value: TEditButtonStyleEh);
- procedure TimerEvent(Sender: TObject);
- procedure UpdateDownButtonNum(X, Y: Integer);
- protected
- 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 Paint; override;
- property Timer: TTimer read GetTimer;
- public
- procedure Click; override;
- procedure EditButtonDown(TopButton: Boolean; var AutoRepeat: Boolean);
- procedure SetState(NewState: TButtonState; IsActive: Boolean; ButtonNum: Integer);
- procedure SetWidthNoNotify(AWidth: Integer);
- property Active: Boolean read FActive write SetActive;
- property AlwaysDown: Boolean read FAlwaysDown write SetAlwaysDown;
- property Style: TEditButtonStyleEh read FStyle write SetStyle default ebsDropDownEh;
- property OnDown: TButtonDownEventEh read FOnDown write FOnDown;
- end;
- TSpeedButtonEh = class(TEditButtonControlEh)
- published
- property Active;
- property Style;
- end;
- TEditButtonControlLineRec = record
- ButtonLine: TShape;
- EditButtonControl: TEditButtonControlEh;
- end;
- TEditButtonControlList = array of TEditButtonControlLineRec;
- TEditButtonEh = class;
- TEditButtonActionLinkEh = class(TActionLink)
- protected
- FClient: TEditButtonEh;
- procedure AssignClient(AClient: TObject); override;
- function IsEnabledLinked: Boolean; override;
- function IsHintLinked: Boolean; override;
- function IsShortCutLinked: Boolean; override;
- function IsVisibleLinked: Boolean; override;
- procedure SetEnabled(Value: Boolean); override;
- procedure SetHint(const Value: string); override;
- procedure SetShortCut(Value: TShortCut); override;
- procedure SetVisible(Value: Boolean); override;
- end;
- TEditButtonActionLinkEhClass = class of TEditButtonActionLinkEh;
- { TEditButtonEh }
- TEditButtonEh = class(TCollectionItem)
- private
- FActionLink: TEditButtonActionLinkEh;
- FDropdownMenu: TPopupMenu;
- FEditControl: TWinControl;
- FEnabled: Boolean;
- FGlyph: TBitmap;
- FHint: String;
- FNumGlyphs: Integer;
- FOnButtonClick: TButtonClickEventEh;
- FOnButtonDown: TButtonDownEventEh;
- FOnChanged: TNotifyEvent;
- FShortCut: TShortCut;
- FStyle: TEditButtonStyleEh;
- FVisible: Boolean;
- FWidth: Integer;
- function GetAction: TBasicAction;
- function GetGlyph: TBitmap;
- function IsEnabledStored: Boolean;
- function IsHintStored: Boolean;
- function IsShortCutStored: Boolean;
- function IsVisibleStored: Boolean;
- procedure DoActionChange(Sender: TObject);
- procedure SetAction(const Value: TBasicAction);
- procedure SetEnabled(const Value: Boolean);
- procedure SetGlyph(const Value: TBitmap);
- procedure SetHint(const Value: String);
- procedure SetNumGlyphs(Value: Integer);
- procedure SetStyle(const Value: TEditButtonStyleEh);
- procedure SetVisible(const Value: Boolean);
- procedure SetWidth(const Value: Integer);
- protected
- function CreateEditButtonControl: TEditButtonControlEh; virtual;
- procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); dynamic;
- procedure Changed; overload;
- property ActionLink: TEditButtonActionLinkEh read FActionLink write FActionLink;
- public
- constructor Create(Collection: TCollection); overload; override;
- constructor Create(EditControl: TWinControl); reintroduce; overload;
- destructor Destroy; override;
- function GetActionLinkClass: TEditButtonActionLinkEhClass; dynamic;
- procedure Assign(Source: TPersistent); override;
- procedure Click(Sender: TObject; var Handled: Boolean); virtual;
- procedure InitiateAction; virtual;
- property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
- published
- property Action: TBasicAction read GetAction write SetAction;
- property DropdownMenu: TPopupMenu read FDropdownMenu write FDropdownMenu;
- property Enabled: Boolean read FEnabled write SetEnabled stored IsEnabledStored default True;
- property Glyph: TBitmap read GetGlyph write SetGlyph;
- property Hint: String read FHint write SetHint stored IsHintStored;
- property NumGlyphs: Integer read FNumGlyphs write SetNumGlyphs default 1;
- property ShortCut: TShortCut read FShortCut write FShortCut stored IsShortCutStored default scNone;
- //property ShortCut: TShortCut read FShortCut write FShortCut default 32808; //Menus.ShortCut(VK_DOWN, [ssAlt]);
- property Style: TEditButtonStyleEh read FStyle write SetStyle default ebsDropDownEh;
- property Visible: Boolean read FVisible write SetVisible stored IsVisibleStored default False;
- property Width: Integer read FWidth write SetWidth default 0;
- property OnClick: TButtonClickEventEh read FOnButtonClick write FOnButtonClick;
- property OnDown: TButtonDownEventEh read FOnButtonDown write FOnButtonDown;
- end;
- TEditButtonEhClass = class of TEditButtonEh;
- { TDropDownEditButtonEh }
- TDropDownEditButtonEh = class(TEditButtonEh)
- public
- constructor Create(Collection: TCollection); overload; override;
- constructor Create(EditControl: TWinControl); overload;
- published
- property ShortCut default 32808; //Menus.ShortCut(VK_DOWN, [ssAlt]);
- end;
- { TVisibleEditButtonEh }
- TVisibleEditButtonEh = class(TEditButtonEh)
- public
- constructor Create(Collection: TCollection); overload; override;
- constructor Create(EditControl: TWinControl); overload;
- published
- property ShortCut default 32808; //Menus.ShortCut(VK_DOWN, [ssAlt]);
- property Visible default True;
- end;
- { TEditButtonsEh }
- TEditButtonsEh = class(TCollection)
- private
- FOnChanged: TNotifyEvent;
- function GetEditButton(Index: Integer): TEditButtonEh;
- procedure SetEditButton(Index: Integer; Value: TEditButtonEh);
- protected
- FOwner: TPersistent;
- function GetOwner: TPersistent; override;
- procedure Update(Item: TCollectionItem); override;
- public
- constructor Create(Owner: TPersistent; EditButtonClass: TEditButtonEhClass);
- function Add: TEditButtonEh;
- property Items[Index: Integer]: TEditButtonEh read GetEditButton write SetEditButton; default;
- property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
- end;
- { TSpecRowEh }
- TSpecRowEh = class(TPersistent)
- private
- FCellsStrings: TStrings;
- FCellsText: String;
- FColor: TColor;
- FFont: TFont;
- FOnChanged: TNotifyEvent;
- FOwner: TPersistent;
- FSelected: Boolean;
- FShortCut: TShortCut;
- FShowIfNotInKeyList: Boolean;
- FUpdateCount: Integer;
- FValue: Variant;
- FVisible: Boolean;
- function GetCellText(Index: Integer): String;
- function GetColor: TColor;
- function GetFont: TFont;
- function IsColorStored: Boolean;
- function IsFontStored: Boolean;
- function IsValueStored: Boolean;
- procedure FontChanged(Sender: TObject);
- procedure SetCellsText(const Value: String);
- procedure SetColor(const Value: TColor);
- procedure SetFont(const Value: TFont);
- procedure SetShowIfNotInKeyList(const Value: Boolean);
- procedure SetValue(const Value: Variant);
- procedure SetVisible(const Value: Boolean);
- protected
- FColorAssigned: Boolean;
- FFontAssigned: Boolean;
- function GetOwner: TPersistent; override;
- procedure Changed;
- public
- constructor Create(Owner: TPersistent);
- destructor Destroy; override;
- function DefaultColor: TColor;
- function DefaultFont: TFont;
- function LocateKey(KeyValue: Variant): Boolean;
- procedure Assign(Source: TPersistent); override;
- procedure BeginUpdate;
- procedure EndUpdate;
- property CellText[Index: Integer]: String read GetCellText;
- property Selected: Boolean read FSelected write FSelected;
- property UpdateCount: Integer read FUpdateCount;
- property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
- published
- property CellsText: String read FCellsText write SetCellsText;
- property Color: TColor read GetColor write SetColor stored IsColorStored;
- property Font: TFont read GetFont write SetFont stored IsFontStored;
- property ShortCut: TShortCut read FShortCut write FShortCut default 32814; //Menus.ShortCut(VK_DOWN, [ssAlt]);
- property ShowIfNotInKeyList: Boolean read FShowIfNotInKeyList write SetShowIfNotInKeyList default True;
- property Value: Variant read FValue write SetValue stored IsValueStored;
- property Visible: Boolean read FVisible write SetVisible default False;
- end;
- { TSizeGripEh }
- TSizeGripPostion = (sgpTopLeft, sgpTopRight, sgpBottomRight, sgpBottomLeft);
- TSizeGripChangePosition = (sgcpToLeft, sgcpToRight, sgcpToTop, sgcpToBottom);
- TSizeGripEh = class(TCustomControl)
- private
- FInitScreenMousePos: TPoint;
- FInternalMove: Boolean;
- FOldMouseMovePos: TPoint;
- FParentRect: TRect;
- FParentResized: TNotifyEvent;
- FPosition: TSizeGripPostion;
- FTriangleWindow: Boolean;
- function GetVisible: Boolean;
- procedure SetPosition(const Value: TSizeGripPostion);
- procedure SetTriangleWindow(const Value: Boolean);
- procedure SetVisible(const Value: Boolean);
- procedure WMMove(var Message: TWMMove); message WM_MOVE;
- protected
- procedure CreateWnd; override;
- procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
- procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
- procedure Paint; override;
- procedure ParentResized; dynamic;
- public
- constructor Create(AOwner: TComponent); override;
- procedure ChangePosition(NewPosition: TSizeGripChangePosition);
- procedure UpdatePosition;
- procedure UpdateWindowRegion;
- property Position: TSizeGripPostion read FPosition write SetPosition default sgpBottomRight;
- property TriangleWindow: Boolean read FTriangleWindow write SetTriangleWindow default True;
- property Visible: Boolean read GetVisible write SetVisible;
- property OnParentResized: TNotifyEvent read FParentResized write FParentResized;
- end;
- const
- cm_SetSizeGripChangePosition = WM_USER + 100;
- { TPopupMonthCalendarEh }
- const
- CM_CLOSEUPEH = WM_USER + 101;
- type
- TPopupMonthCalendarEh = class(TMonthCalendar)
- private
- FBorderWidth: Integer;
- procedure CMCloseUpEh(var Message: TMessage); message CM_CLOSEUPEH;
- procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
- procedure CMWantSpecialKey(var Message: TCMWantSpecialKey); message CM_WANTSPECIALKEY;
- procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
- procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
- procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
- procedure WMNCPaint(var Message: TWMNCPaint); message WM_NCPAINT;
- protected
- function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
- function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
- function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
- function MsgSetDateTime(Value: TSystemTime): Boolean; override;
- procedure CreateParams(var Params: TCreateParams); override;
- procedure CreateWnd; override;
- procedure DrawBorder; virtual;
- procedure KeyDown(var Key: Word; Shift: TShiftState); override;
- procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
- procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
- procedure PostCloseUp(Accept: Boolean);
- procedure UpdateBorderWidth;
- public
- constructor Create(AOwner: TComponent); override;
- property Color;
- property Ctl3D;
- end;
- TListGetImageIndexEventEh = procedure(Sender: TObject; ItemIndex: Integer; var ImageIndex: Integer) of object;
- { TPopupListboxEh }
- TPopupListboxEh = class(TCustomListbox)
- private
- FBorderWidth: Integer;
- FImageList: TCustomImageList;
- FMousePos: TPoint;
- FRowCount: Integer;
- FSearchText: String;
- FSearchTickCount: Longint;
- FSizeGrip: TSizeGripEh;
- FSizeGripResized: Boolean;
- FOnGetImageIndex: TListGetImageIndexEventEh;
- FExtItems: TStrings;
- function CheckNewSize(var NewWidth, NewHeight: Integer): Boolean;
- function GetBorderSize: Integer;
- function GetExtItems: TStrings;
- procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
- procedure CMSetSizeGripChangePosition(var Message: TMessage); message cm_SetSizeGripChangePosition;
- procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
- procedure SetExtItems(Value: TStrings);
- procedure SetImageList(const Value: TCustomImageList);
- procedure SetRowCount(Value: Integer);
- procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
- procedure WMNCPaint(var Message: TWMNCPaint); message WM_NCPAINT;
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
- procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
- protected
- function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
- function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
- procedure CreateParams(var Params: TCreateParams); override;
- procedure CreateWnd; override;
- procedure DrawBorder; virtual;
- procedure DrawItem(Index: Integer; ARect: TRect; State: TOwnerDrawState); override;
- procedure KeyPress(var Key: Char); override;
- procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
- procedure UpdateBorderWidth;
- procedure SelfOnGetData(Control: TWinControl; Index: Integer; var Data: string); virtual;
- public
- constructor Create(Owner: TComponent); override;
- procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
- function CanFocus: Boolean; {$IFDEF EH_LIB_5} override; {$ENDIF}
- function GetTextHeight: Integer;
- property Color;
- property Ctl3D;
- property Font;
- property ImageList: TCustomImageList read FImageList write SetImageList;
- property IntegralHeight;
- property ItemHeight;
- property RowCount: Integer read FRowCount write SetRowCount;
- property ExtItems: TStrings read GetExtItems write SetExtItems;
- property SizeGrip: TSizeGripEh read FSizeGrip;
- property SizeGripResized: Boolean read FSizeGripResized write FSizeGripResized;
- property OnMouseUp;
- property OnGetImageIndex: TListGetImageIndexEventEh read FOnGetImageIndex write FOnGetImageIndex;
- end;
- { TMRUList }
- TFilterMRUItemEventEh = procedure (Sender: TObject; var Accept: Boolean) of object;
- TSetDropDownEventEh = procedure (Sender: TObject) of object;
- TSetCloseUpEventEh = procedure (Sender: TObject; Accept: Boolean) of object;
- TMRUListEh = class(TPersistent)
- private
- FActive: Boolean;
- FAutoAdd: Boolean;
- FCaseSensitive: Boolean;
- FItems: TStrings;
- FLimit: Integer;
- FOnActiveChanged: TNotifyEvent;
- FOnFilterItem: TFilterMRUItemEventEh;
- FOnSetCloseUpEvent: TSetCloseUpEventEh;
- FOnSetDropDown: TSetDropDownEventEh;
- FOwner: TPersistent;
- FRows: Integer;
- FWidth: Integer;
- FCancelIfKeyInQueue: Boolean;
- procedure SetActive(const Value: Boolean);
- procedure SetItems(const Value: TStrings);
- procedure SetLimit(const Value: Integer);
- procedure SetRows(const Value: Integer);
- protected
- FDroppedDown: Boolean;
- procedure UpdateLimit;
- public
- constructor Create(AOwner: TPersistent);
- destructor Destroy; override;
- procedure Add(s: String);
- procedure Assign(Source: TPersistent); override;
- procedure CloseUp(Accept: Boolean); virtual;
- procedure DropDown; virtual;
- function FilterItemsTo(FilteredItems: TStrings; MaskText: String): Boolean;
- property DroppedDown: Boolean read FDroppedDown write FDroppedDown;
- property Width: Integer read FWidth write FWidth;
- property OnActiveChanged: TNotifyEvent read FOnActiveChanged write FOnActiveChanged;
- property OnSetCloseUp: TSetCloseUpEventEh read FOnSetCloseUpEvent write FOnSetCloseUpEvent;
- property OnSetDropDown: TSetDropDownEventEh read FOnSetDropDown write FOnSetDropDown;
- property OnFilterItem: TFilterMRUItemEventEh read FOnFilterItem write FOnFilterItem;
- property CancelIfKeyInQueue: Boolean read FCancelIfKeyInQueue write FCancelIfKeyInQueue default True;
- published
- property AutoAdd: Boolean read FAutoAdd write FAutoAdd default True;
- property Active: Boolean read FActive write SetActive default False;
- property CaseSensitive: Boolean read FCaseSensitive write FCaseSensitive default False;
- property Items: TStrings read FItems write SetItems;
- property Limit: Integer read FLimit write SetLimit default 100;
- property Rows: Integer read FRows write SetRows default 7;
- end;
- { TMRUListboxEh }
- TMRUListboxEh = class(TPopupListboxEh)
- private
- FScrollBar: TScrollBar;
- FScrollBarLockMove: Boolean;
- procedure CMChanged(var Message: TCMChanged); message CM_CHANGED;
- procedure CMMouseWheel(var Message: TCMMouseWheel); message CM_MOUSEWHEEL;
- procedure CMSetSizeGripChangePosition(var Message: TMessage); message cm_SetSizeGripChangePosition;
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
- protected
- procedure CreateParams(var Params: TCreateParams); override;
- procedure ScrollBarScrolled(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
- procedure ScrollBarWindowProc(var Message: TMessage);
- public
- constructor Create(Owner: TComponent); override;
- procedure UpdateScrollBar;
- procedure UpdateScrollBarPos;
- property ParentCtl3D;
- property ScrollBar: TScrollBar read FScrollBar;
- property Sorted;
- property OnMouseUp;
- end;
- {$IFNDEF EH_LIB_5} // Delphi 4 doesn't have TObjectList but Delphi 8 required
- { TObjectList class }
- TObjectList = class(TList)
- private
- FOwnsObjects: Boolean;
- protected
- function GetItem(Index: Integer): TObject;
- procedure SetItem(Index: Integer; AObject: TObject);
- public
- constructor Create; overload;
- constructor Create(AOwnsObjects: Boolean); overload;
- function Add(AObject: TObject): Integer;
- function Remove(AObject: TObject): Integer;
- function IndexOf(AObject: TObject): Integer;
- function FindInstanceOf(AClass: TClass; AExact: Boolean = True; AStartAt: Integer = 0): Integer;
- procedure Insert(Index: Integer; AObject: TObject);
- property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects;
- property Items[Index: Integer]: TObject read GetItem write SetItem; default;
- end;
- {$ENDIF}
- {$IFNDEF EH_LIB_5}
- TStringListSortCompare = function(List: TStringList; Index1, Index2: Integer): Integer;
- {$ENDIF}
- TStringListEh = class(TStringList)
- {$IFNDEF EH_LIB_6}
- private
- FCaseSensitive: Boolean;
- function CompareStrings(const S1, S2: string): Integer;
- procedure SetCaseSensitive(const Value: Boolean);
- public
- {$IFNDEF EH_LIB_5}
- procedure CustomSort(Compare: TStringListSortCompare);
- procedure QuickSort(L, R: Integer; SCompare: TStringListSortCompare);
- {$ENDIF}
- procedure Sort; override;
- property CaseSensitive: Boolean read FCaseSensitive write SetCaseSensitive;
- {$ENDIF}
- end;
- { TDataLinkEh }
- {$IFDEF CIL}
- TDataEventEh = procedure (Event: TDataEvent; Info: TObject) of object;
- {$ELSE}
- TDataEventEh = procedure (Event: TDataEvent; Info: Longint) of object;
- {$ENDIF}
- TDataLinkEh = class(TDataLink)
- private
- FOnDataEvent: TDataEventEh;
- protected
- {$IFDEF CIL}
- procedure DataEvent(Event: TDataEvent; Info: TObject); virtual;
- {$ELSE}
- procedure DataEvent(Event: TDataEvent; Info: Integer); override;
- {$ENDIF}
- public
- property OnDataEvent: TDataEventEh read FOnDataEvent write FOnDataEvent;
- end;
- { TDatasetFieldValueListEh }
- TDatasetFieldValueListEh = class(TInterfacedObject, IMemTableDataFieldValueListEh)
- private
- FValues: TStringList;
- FDataObsoleted: Boolean;
- FFieldName: String;
- FDataLink: TDataLinkEh;
- FDataSource: TDataSource;
- function GetValues: TStrings;
- procedure SetFieldName(const Value: String);
- procedure SetDataSet(const Value: TDataSet);
- function GetDataSet: TDataSet;
- protected
- procedure RefreshValues;
- {$IFDEF CIL}
- procedure DataSetEvent(Event: TDataEvent; Info: TObject); virtual;
- {$ELSE}
- procedure DataSetEvent(Event: TDataEvent; Info: Integer); virtual;
- {$ENDIF}
- public
- constructor Create;
- destructor Destroy; override;
- property FieldName: String read FFieldName write SetFieldName;
- property DataSet: TDataSet read GetDataSet write SetDataSet;
- property Values: TStrings read GetValues;
- end;
- TLocateTextEventEh = function (Sender: TObject;
- const FieldName: string; const Text: String; Options: TLocateTextOptionsEh;
- Direction: TLocateTextDirectionEh; Matching: TLocateTextMatchingEh;
- TreeFindRange: TLocateTextTreeFindRangeEh): Boolean of object;
- TDrawButtonControlStyleEh = (bcsDropDownEh, bcsEllipsisEh, bcsUpDownEh,
- bcsCheckboxEh, bcsPlusEh, bcsMinusEh);
- TTreeElementEh = (tehMinusUpDown, tehMinusUp, tehMinusDown,
- tehPlusUpDown, tehPlusUp, tehPlusDown,
- tehCrossUpDown, tehCrossUp, tehCrossDown,
- tehVLine);
- procedure PaintButtonControlEh(DC: HDC; ARect: TRect; ParentColor: TColor;
- Style: TDrawButtonControlStyleEh; DownButton: Integer;
- Flat, Active, Enabled: Boolean; State: TCheckBoxState);
- function GetDefaultFlatButtonWidth: Integer;
- var
- FlatButtonWidth: Integer;
- type
- TFieldTypes = set of TFieldType;
- const
- ftNumberFieldTypes: TFieldTypes = [ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency,
- ftBCD{$IFDEF EH_LIB_6}, ftFMTBcd{$ENDIF}];
- procedure GetFieldsProperty(List: TList; DataSet: TDataSet;
- Control: TComponent; const FieldNames: String); overload;
- function GetFieldsProperty(DataSet: TDataSet; Control: TComponent;
- const FieldNames: String): TFieldsArrEh; overload;
- procedure DataSetSetFieldValues(DataSet: TDataSet; Fields: String; Value: Variant);
- function VarEquals(const V1, V2: Variant): Boolean;
- {$IFNDEF EH_LIB_6}
- type
- TVariantRelationship = (vrEqual, vrLessThan, vrGreaterThan, vrNotEqual);
- {$ENDIF}
- function DBVarCompareValue(const A, B: Variant): TVariantRelationship;
- var UseButtonsBitmapCache: Boolean = True;
- procedure ClearButtonsBitmapCache;
- procedure DrawImage(DC: HDC; ARect: TRect; Images: TCustomImageList;
- ImageIndex: Integer; Selected: Boolean);
- procedure DrawTreeElement(Canvas: TCanvas; ARect: TRect;
- TreeElement: TTreeElementEh; BackDot: Boolean; ScaleX, ScaleY: Double;
- RightToLeft: Boolean);
- function AlignDropDownWindowRect(MasterAbsRect: TRect; DropDownWin: TWinControl; Align: TDropDownAlign): TPoint;
- function AlignDropDownWindow(MasterWin, DropDownWin: TWinControl; Align: TDropDownAlign): TPoint;
- {$IFNDEF EH_LIB_5}
- function Supports(const Instance: IUnknown; const IID: TGUID; out Intf): Boolean; overload;
- function Supports(const Instance: TObject; const IID: TGUID; out Intf): Boolean; overload;
- {$ENDIF}
- var
- DefaultCheckBoxWidth, DefaultCheckBoxHeight: Integer;
- function AdjustCheckBoxRect(ClientRect: TRect; Alignment: TAlignment; Layout: TTextLayout): TRect;
- function IsDoubleClickMessage(OldPos, NewPos: TPoint; Interval: Longint): Boolean;
- function DefaultEditButtonHeight(EditButtonWidth: Integer; Flat: Boolean): Integer;
- function KillMouseUp(Control: TControl): Boolean; overload;
- function KillMouseUp(Control: TControl; Area: TRect): Boolean; overload;
- implementation
- uses DBConsts, Math,
- {$IFDEF EH_LIB_6} VDBConsts, Types, {$ENDIF}
- {$IFDEF EH_LIB_7} Themes, UxTheme, {$ENDIF}
- MultiMon;
- type
- TWinControlCracker = class(TWinControl) end;
- TControlCracker = class(TControl) end;
- {$IFNDEF EH_LIB_5}
- function Supports(const Instance: IUnknown; const IID: TGUID; out Intf): Boolean; overload;
- begin
- Result := (Instance <> nil) and (Instance.QueryInterface(IID, Intf) = 0);
- end;
- function Supports(const Instance: TObject; const IID: TGUID; out Intf): Boolean; overload;
- var
- LUnknown: IUnknown;
- begin
- Result := (Instance <> nil) and
- ((Instance.GetInterface(IUnknown, LUnknown) and Supports(LUnknown, IID, Intf)) or
- Instance.GetInterface(IID, Intf));
- end;
- {$ENDIF}
- function IsDoubleClickMessage(OldPos, NewPos: TPoint; Interval: Longint): Boolean;
- begin
- Result := (Interval <= Longint(GetDoubleClickTime)) and
- (Abs(OldPos.X - NewPos.X) <= GetSystemMetrics(SM_CXDOUBLECLK)) and
- (Abs(OldPos.Y - NewPos.Y) <= GetSystemMetrics(SM_CYDOUBLECLK));
- end;
- procedure GetCheckSize;
- begin
- with TBitmap.Create do
- try
- Handle := LoadBitmapEh(0, OBM_CHECKBOXES);
- DefaultCheckBoxWidth := Width div 4;
- DefaultCheckBoxHeight := Height div 3;
- finally
- Free;
- end;
- end;
- function AdjustCheckBoxRect(ClientRect: TRect; Alignment: TAlignment; Layout: TTextLayout): TRect;
- var
- CheckWidth, CheckHeight: Integer;
- begin
- if (ClientRect.Right - ClientRect.Left) > DefaultCheckBoxWidth
- then CheckWidth := DefaultCheckBoxWidth
- else CheckWidth := ClientRect.Right - ClientRect.Left;
- if (ClientRect.Bottom - ClientRect.Top) > DefaultCheckBoxHeight
- then CheckHeight := DefaultCheckBoxHeight
- else CheckHeight := ClientRect.Bottom - ClientRect.Top;
- Result := ClientRect;
- if (ClientRect.Right - ClientRect.Left) > DefaultCheckBoxWidth then
- case Alignment of
- taRightJustify: Result.Left := Result.Right - CheckWidth;
- taCenter: Result.Left := Result.Left + (ClientRect.Right - ClientRect.Left) shr 1 - CheckWidth shr 1;
- end;
- Result.Right := Result.Left + CheckWidth;
- if (ClientRect.Bottom - ClientRect.Top) > DefaultCheckBoxHeight then
- case Layout of
- tlBottom: Result.Top := Result.Bottom - CheckWidth;
- tlCenter: Result.Top := Result.Top + (ClientRect.Bottom - ClientRect.Top) shr 1 - CheckHeight shr 1;
- end;
- Result.Bottom := Result.Top + CheckHeight;
- end;
- procedure DrawCheck(DC: HDC; R: TRect; AState: TCheckBoxState; AEnabled, AFlat, ADown, AActive: Boolean);
- var
- DrawState, oldRgn: Integer;
- DrawRect: TRect;
- // OldBrushColor: TColor;
- // OldBrushStyle: TBrushStyle;
- // OldPenColor: TColor;
- Rgn, SaveRgn: HRgn;
- {$IFDEF EH_LIB_7}
- ElementDetails: TThemedElementDetails;
- {$ENDIF}
- // Brush,SaveBrush: HBRUSH;
- begin
- SaveRgn := 0;
- oldRgn := 0;
- DrawRect := R;
- with DrawRect do
- if (Right - Left) > (Bottom - Top) then
- begin
- Left := Left + ((Right - Left) - (Bottom - Top)) div 2;
- Right := Left + (Bottom - Top);
- end else if (Right - Left) < (Bottom - Top) then
- begin
- Top := Top + ((Bottom - Top) - (Right - Left)) div 2;
- Bottom := Top + (Right - Left);
- end;
- case AState of
- cbChecked:
- DrawState := DFCS_BUTTONCHECK or DFCS_CHECKED;
- cbUnchecked:
- DrawState := DFCS_BUTTONCHECK;
- else // cbGrayed
- DrawState := DFCS_BUTTON3STATE or DFCS_CHECKED;
- end;
- if not AEnabled then
- DrawState := DrawState or DFCS_INACTIVE;
- if ADown then
- DrawState := DrawState or DFCS_PUSHED;
- // with Canvas do
- // begin
- if AFlat then
- begin
- { Remember current clipping region }
- SaveRgn := CreateRectRgn(0, 0, 0, 0);
- oldRgn := GetClipRgn(DC, SaveRgn);
- { Clip 3d-style checkbox to prevent flicker }
- with DrawRect do
- Rgn := CreateRectRgn(Left + 1, Top + 1, Right - 1, Bottom - 1);
- SelectClipRgn(DC, Rgn);
- DeleteObject(Rgn);
- end;
- if AFlat then InflateRect(DrawRect, 1, 1);
- {$IFDEF EH_LIB_7}
- if ThemeServices.ThemesEnabled then
- begin
- case AState of
- cbChecked:
- if AEnabled then
- ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal)
- else
- ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxCheckedDisabled);
- cbUnchecked:
- if AEnabled then
- ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxUncheckedNormal)
- else
- ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxUncheckedDisabled)
- else // cbGrayed
- if AEnabled then
- ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxMixedNormal)
- else
- ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxMixedDisabled);
- end;
- ThemeServices.DrawElement(DC, ElementDetails, R);
- end
- else
- {$ENDIF}
- DrawFrameControl(DC, DrawRect, DFC_BUTTON, DrawState);
- if AFlat then
- begin
- //SelectClipRgn(Handle, SaveRgn);
- if oldRgn = 0 then
- SelectClipRgn(DC, 0)
- else
- SelectClipRgn(DC, SaveRgn);
- DeleteObject(SaveRgn);
- { Draw flat rectangle in-place of clipped 3d checkbox above }
- InflateRect(DrawRect, -1, -1);
- if AActive
- then FrameRect(DC, DrawRect, GetSysColorBrush(COLOR_BTNFACE))
- else FrameRect(DC, DrawRect, GetSysColorBrush(COLOR_BTNSHADOW));
- { Caller drow in flat mode
- InflateRect(DrawRect, 1, 1);
- if AActive
- then DrawEdge(DC, DrawRect, BDR_SUNKENOUTER, BF_RECT)
- else FrameRect(DC, DrawRect, GetCurrentObject(DC, OBJ_BRUSH));}
- end;
- // end;
- end;
- const
- DownFlags: array[Boolean] of Integer = (0, DFCS_PUSHED {? or DFCS_FLAT});
- FlatFlags: array[Boolean] of Integer = (0, DFCS_FLAT);
- EnabledFlags: array[Boolean] of Integer = (DFCS_INACTIVE, 0);
- IsDownFlags: array[Boolean] of Integer = (DFCS_SCROLLUP, DFCS_SCROLLDOWN);
- PressedFlags: array[Boolean] of Integer = (EDGE_RAISED, EDGE_SUNKEN);
- procedure DrawEllipsisButton(DC: HDC; ARect: TRect; Enabled, Active, Flat, Pressed: Boolean);
- var
- InterP, PWid, W, H: Integer;
- ElRect: TRect;
- Brush, SaveBrush: HBRUSH;
- {$IFDEF EH_LIB_7}
- Button: TThemedButton;
- ToolButton: TThemedToolBar;
- Details: TThemedElementDetails;
- {$ENDIF}
- begin
- ElRect := ARect;
- {$IFDEF EH_LIB_7}
- if ThemeServices.ThemesEnabled then
- begin
- if not Enabled then
- Button := tbPushButtonDisabled
- else
- if Pressed then
- Button := tbPushButtonPressed
- else
- if Active
- then Button := tbPushButtonHot
- else Button := tbPushButtonNormal;
- ToolButton := ttbToolbarDontCare;
- if Flat then
- begin
- case Button of
- tbPushButtonDisabled:
- Toolbutton := ttbButtonDisabled;
- tbPushButtonPressed:
- Toolbutton := ttbButtonPressed;
- tbPushButtonHot:
- Toolbutton := ttbButtonHot;
- tbPushButtonNormal:
- Toolbutton := ttbButtonNormal;
- end;
- end;
- if ToolButton = ttbToolbarDontCare then
- begin
- Details := ThemeServices.GetElementDetails(Button);
- ThemeServices.DrawElement(DC, Details, ARect);
- // ARect := ThemeServices.ContentRect(DC, Details, ARect);
- InflateRect(ElRect, -2, -2);
- end else
- begin
- Details := ThemeServices.GetElementDetails(ToolButton);
- ThemeServices.DrawElement(DC, Details, ARect);
- InflateRect(ElRect, -1, -1)
- // ARect := ThemeServices.ContentRect(DC, Details, ARect);
- end;
- end else
- {$ENDIF}
- begin
- Brush := GetSysColorBrush(COLOR_BTNFACE);
- if Flat then
- begin
- Windows.FillRect(DC, ElRect, Brush);
- InflateRect(ElRect, -1, -1)
- end else
- begin
- DrawEdge(DC, ElRect, PressedFlags[Pressed], BF_RECT or BF_MIDDLE);
- InflateRect(ElRect, -2, -2);
- //Windows.FillRect(DC, ElRect, Brush);
- end;
- end;
- InterP := 2;
- PWid := 2;
- W := ElRect.Right - ElRect.Left; //+ Ord(not Active and Flat);
- if W < 12 then InterP := 1;
- if W < 8 then PWid := 1;
- W := ElRect.Left + W div 2 - PWid div 2 + Ord(Pressed); //- Ord(not Active and Flat);
- H := ElRect.Top + (ElRect.Bottom - ElRect.Top) div 2 - PWid div 2 + Ord(Pressed);
- if not Enabled then
- begin
- Inc(W); Inc(H);
- Brush := GetSysColorBrush(COLOR_BTNHILIGHT);
- SaveBrush := SelectObject(DC, Brush);
- PatBlt(DC, W, H, PWid, PWid, PATCOPY);
- PatBlt(DC, W - InterP - PWid, H, PWid, PWid, PATCOPY);
- PatBlt(DC, W + InterP + PWid, H, PWid, PWid, PATCOPY);
- Dec(W); Dec(H);
- SelectObject(DC, SaveBrush);
- Brush := GetSysColorBrush(COLOR_BTNSHADOW);
- end else
- Brush := GetSysColorBrush(COLOR_BTNTEXT);
- SaveBrush := SelectObject(DC, Brush);
- PatBlt(DC, W, H, PWid, PWid, PATCOPY);
- PatBlt(DC, W - InterP - PWid, H, PWid, PWid, PATCOPY);
- PatBlt(DC, W + InterP + PWid, H, PWid, PWid, PATCOPY);
- SelectObject(DC, SaveBrush);
- end;
- procedure DrawPlusMinusButton(DC: HDC; ARect: TRect; Enabled, Active, Flat, Pressed, Plus: Boolean);
- var PWid, PHet, W, H, PlusInd, MinWH: Integer;
- ElRect: TRect;
- Brush, SaveBrush: HBRUSH;
- {$IFDEF EH_LIB_7}
- Button: TThemedButton;
- ToolButton: TThemedToolBar;
- Details: TThemedElementDetails;
- {$ENDIF}
- begin
- ElRect := ARect;
- {$IFDEF EH_LIB_7}
- if ThemeServices.ThemesEnabled then
- begin
- if not Enabled then
- Button := tbPushButtonDisabled
- else
- if Pressed then
- Button := tbPushButtonPressed
- else
- if Active
- then Button := tbPushButtonHot
- else Button := tbPushButtonNormal;
- ToolButton := ttbToolbarDontCare;
- if Flat then
- begin
- case Button of
- tbPushButtonDisabled:
- Toolbutton := ttbButtonDisabled;
- tbPushButtonPressed:
- Toolbutton := ttbButtonPressed;
- tbPushButtonHot:
- Toolbutton := ttbButtonHot;
- tbPushButtonNormal:
- Toolbutton := ttbButtonNormal;
- end;
- end;
- if ToolButton = ttbToolbarDontCare then
- begin
- Details := ThemeServices.GetElementDetails(Button);
- ThemeServices.DrawElement(DC, Details, ARect);
- // ARect := ThemeServices.ContentRect(DC, Details, ARect);
- InflateRect(ElRect, -2, -2);
- end else
- begin
- Details := ThemeServices.GetElementDetails(ToolButton);
- ThemeServices.DrawElement(DC, Details, ARect);
- InflateRect(ElRect, -1, -1)
- // ARect := ThemeServices.ContentRect(DC, Details, ARect);
- end;
- end else
- {$ENDIF}
- begin
- Brush := GetSysColorBrush(COLOR_BTNFACE);
- if Flat then
- begin
- Windows.FillRect(DC, ElRect, Brush);
- InflateRect(ElRect, -1, -1)
- end else
- begin
- DrawEdge(DC, ElRect, PressedFlags[Pressed], BF_RECT or BF_MIDDLE);
- InflateRect(ElRect, -2, -2);
- Windows.FillRect(DC, ElRect, Brush);
- end;
- end;
- MinWH := ElRect.Right - ElRect.Left; //+ Ord(not Active and Flat);
- if ElRect.Bottom - ElRect.Top < MinWH then
- MinWH := ElRect.Bottom - ElRect.Top;
- PWid := MinWH * 4 div 7;
- if PWid = 0 then PWid := 1;
- PHet := PWid div 3;
- if PHet = 0 then PHet := 1;
- if Flat then Dec(PWid);
- if PWid mod 2 <> MinWH mod 2 then Inc(PWid);
- if Plus and (PWid mod 2 <> PHet mod 2) then
- if (MinWH < 12) then Inc(PWid) else Dec(PWid);
- PlusInd := PWid div 2 - PHet div 2;
- W := ElRect.Left + (ElRect.Right - ElRect.Left - PWid) div 2; //- Ord(not Active and Flat);
- //if W * 2 + PWid > (ElRect.Right - ElRect.Left) then Dec(W);
- Inc(W, Ord(Pressed));
- H := ElRect.Top + (ElRect.Bottom - ElRect.Top - PHet) div 2 + Ord(Pressed);
- if not Enabled then
- begin
- Inc(W); Inc(H);
- Brush := GetSysColorBrush(COLOR_BTNHILIGHT);
- SaveBrush := SelectObject(DC, Brush);
- PatBlt(DC, W, H, PWid, PHet, PATCOPY);
- if Plus then PatBlt(DC, W + PlusInd, H - PlusInd, PHet, PWid, PATCOPY);
- Dec(W); Dec(H);
- SelectObject(DC, SaveBrush);
- Brush := GetSysColorBrush(COLOR_BTNSHADOW);
- end else
- Brush := GetSysColorBrush(COLOR_BTNTEXT);
- SaveBrush := SelectObject(DC, Brush);
- PatBlt(DC, W, H, PWid, PHet, PATCOPY);
- if Plus then PatBlt(DC, W + PlusInd, H - PlusInd, PHet, PWid, PATCOPY);
- SelectObject(DC, SaveBrush);
- end;
- procedure DrawDropDownButton(DC: HDC; ARect: TRect; Enabled, Flat, Active, Down: Boolean);
- var
- Flags: Integer;
- {$IFDEF EH_LIB_7}
- Details: TThemedElementDetails;
- {$ENDIF}
- // Rgn, SaveRgn: HRGN;
- // r: Integer;
- // IsClip: Boolean;
- begin
- {$IFDEF EH_LIB_7}
- if ThemeServices.ThemesEnabled then
- begin
- if not Enabled then
- Details := ThemeServices.GetElementDetails(tcDropDownButtonDisabled)
- else
- if Down then
- Details := ThemeServices.GetElementDetails(tcDropDownButtonPressed)
- else
- if Active
- then Details := ThemeServices.GetElementDetails(tcDropDownButtonHot)
- else Details := ThemeServices.GetElementDetails(tcDropDownButtonNormal);
- { with Details do
- GetThemeBackgroundRegion(ThemeServices.Theme[Element], DC, Part, State, ARect, Rgn);
- IsClip := False;
- SaveRgn := 0;
- r := 0;
- if Rgn <> 0 then
- begin
- IsClip := True;
- SaveRgn := CreateRectRgn(0, 0, 0, 0);
- r := GetClipRgn(DC, SaveRgn);
- SelectClipRgn(DC, Rgn);
- DeleteObject(Rgn);
- end;}
- ThemeServices.DrawElement(DC, Details, ARect);
- { if IsClip = True then
- begin
- if r = 0
- then SelectClipRgn(DC, 0)
- else SelectClipRgn(DC, SaveRgn);
- DeleteObject(SaveRgn);
- end;}
- end else
- {$ENDIF}
- begin
- Flags := DownFlags[Down] or FlatFlags[Flat] or EnabledFlags[Enabled];
- DrawFrameControl(DC, ARect, DFC_SCROLL, Flags or DFCS_SCROLLCOMBOBOX);
- end;
- end;
- procedure DrawUpDownButton(DC: HDC; ARect: TRect; Enabled, Flat, Active, Down, DownDirection: Boolean);
- var
- Flags: Integer;
- {$IFDEF EH_LIB_7}
- Details: TThemedElementDetails;
- {$ENDIF}
- begin
- {$IFDEF EH_LIB_7}
- if ThemeServices.ThemesEnabled then
- begin
- if DownDirection then
- if not Enabled then
- Details := ThemeServices.GetElementDetails(tsDownDisabled)
- else
- if Down then
- Details := ThemeServices.GetElementDetails(tsDownPressed)
- else
- if Active
- then Details := ThemeServices.GetElementDetails(tsDownHot)
- else Details := ThemeServices.GetElementDetails(tsDownNormal)
- else
- if not Enabled then
- Details := ThemeServices.GetElementDetails(tsUpDisabled)
- else
- if Down then
- Details := ThemeServices.GetElementDetails(tsUpPressed)
- else
- if Active
- then Details := ThemeServices.GetElementDetails(tsUpHot)
- else Details := ThemeServices.GetElementDetails(tsUpNormal);
- ThemeServices.DrawElement(DC, Details, ARect);
- end else
- {$ENDIF}
- begin
- Flags := DownFlags[Down] or FlatFlags[Flat] or EnabledFlags[Enabled];
- DrawFrameControl(DC, ARect, DFC_SCROLL, Flags or IsDownFlags[DownDirection]);
- end;
- end;
- procedure DrawOneButton(DC: HDC; Style: TDrawButtonControlStyleEh;
- ARect: TRect; Enabled, Flat, Active, Down, DownDirection: Boolean);
- var
- Rgn, SaveRgn: HRgn;
- r: Integer;
- IsClipRgn: Boolean;
- DRect: TRect;
- // Brush: HBRUSH;
- begin
- DRect := ARect;
- // LPtoDP(DC, DRect, 2);
- WindowsLPtoDP(DC, DRect);
- {$IFDEF EH_LIB_7}
- IsClipRgn := Flat and Active and not ThemeServices.ThemesEnabled;
- {$ELSE}
- IsClipRgn := Flat and Active;
- {$ENDIF}
- r := 0; SaveRgn := 0;
- if IsClipRgn then
- begin
- SaveRgn := CreateRectRgn(0, 0, 0, 0);
- r := GetClipRgn(DC, SaveRgn);
- with DRect do
- Rgn := CreateRectRgn(Left + 1, Top + 1, Right - 1, Bottom - 1);
- SelectClipRgn(DC, Rgn);
- DeleteObject(Rgn);
- end;
- if Flat {$IFDEF EH_LIB_7} and not ThemeServices.ThemesEnabled {$ENDIF} then
- if not Active {and not (Style=bcsUpDownEh)}
- then InflateRect(ARect, 2, 2)
- else InflateRect(ARect, 1, 1);
- case Style of
- bcsDropDownEh: DrawDropDownButton(DC, ARect, Enabled, Flat, Active, Down);
- bcsEllipsisEh: DrawEllipsisButton(DC, ARect, Enabled, Active, Flat, Down);
- bcsUpDownEh: DrawUpDownButton(DC, ARect, Enabled, Flat, Active, Down, DownDirection);
- bcsMinusEh, bcsPlusEh: DrawPlusMinusButton(DC, ARect, Enabled, Active, Flat, Down, bcsPlusEh = Style);
- end;
- if Flat then
- if not Active {and not (Style=bcsUpDownEh)}
- then InflateRect(ARect, -2, -2)
- else InflateRect(ARect, -1, -1);
- if IsClipRgn then
- begin
- if r = 0
- then SelectClipRgn(DC, 0)
- else SelectClipRgn(DC, SaveRgn);
- DeleteObject(SaveRgn);
- if Down
- then DrawEdge(DC, ARect, BDR_SUNKENOUTER, BF_RECT)
- else DrawEdge(DC, ARect, BDR_RAISEDINNER, BF_RECT)
- end;
- end;
- type
- PPoints = ^TPoints;
- TPoints = array[0..0] of TPoint;
- TButtonBitmapInfoEh = record
- Size: TPoint;
- BitmapType: TDrawButtonControlStyleEh;
- Flat: Boolean;
- Pressed: Boolean;
- Active: Boolean;
- Enabled: Boolean;
- DownDirect: Boolean;
- CheckState: TCheckBoxState;
- end;
- function CompareButtonBitmapInfo(Info1, Info2: TButtonBitmapInfoEh): Boolean;
- begin
- Result := (Info1.Size.X = Info2.Size.X) and (Info1.Size.Y = Info2.Size.Y)
- and (Info1.BitmapType = Info2.BitmapType)
- and (Info1.Flat = Info2.Flat)
- and (Info1.Pressed = Info2.Pressed)
- and (Info1.Active = Info2.Active)
- and (Info1.Enabled = Info2.Enabled)
- and (Info1.DownDirect = Info2.DownDirect)
- and (Info1.CheckState = Info2.CheckState);
- end;
- type
- { TButtonsBitmapCache }
- TButtonBitmapInfoBitmapEh = class(TObject)
- public
- BitmapInfo: TButtonBitmapInfoEh;
- Bitmap: TBitmap;
- end;
- // PButtonBitmapInfoBitmapEh = ^TButtonBitmapInfoBitmapEh;
- TButtonsBitmapCache = class(TObjectList)
- private
- function Get(Index: Integer): TButtonBitmapInfoBitmapEh;
- // procedure Put(Index: Integer; const Value: PButtonBitmapInfoBitmapEh);
- public
- constructor Create; overload;
- procedure Clear; override;
- function GetButtonBitmap(ButtonBitmapInfo: TButtonBitmapInfoEh): TBitmap;
- property Items[Index: Integer]: TButtonBitmapInfoBitmapEh read Get {write Put}; default;
- end;
- var ButtonsBitmapCache: TButtonsBitmapCache;
- procedure ClearButtonsBitmapCache;
- begin
- ButtonsBitmapCache.Clear;
- end;
- function RectSize(ARect: TRect): TSize;
- begin
- Result.cx := ARect.Right - ARect.Left;
- Result.cy := ARect.Bottom - ARect.Top;
- end;
- procedure PaintButtonControlEh(DC: HDC; ARect: TRect; ParentColor: TColor;
- Style: TDrawButtonControlStyleEh; DownButton: Integer;
- Flat, Active, Enabled: Boolean; State: TCheckBoxState);
- var
- Rgn, SaveRgn: HRgn;
- HalfRect, DRect: TRect;
- ASize: TSize;
- r: Integer;
- Brush: HBRUSH;
- IsClipRgn: Boolean;
- BitmapInfo: TButtonBitmapInfoEh;
- Bitmap: TBitmap;
- begin
- SaveRgn := 0; r := 0;
- // FillChar(BitmapInfo, Sizeof(BitmapInfo), #0);
- BitmapInfo.BitmapType := Style;
- BitmapInfo.Flat := Flat;
- if Style = bcsCheckboxEh then
- begin
- ASize := RectSize(ARect);
- if ASize.cx < ASize.cy then
- begin
- ARect.Top := ARect.Top + (ASize.cy - ASize.cx) div 2;
- ARect.Bottom := ARect.Bottom - (ASize.cy - ASize.cx) div 2 - (ASize.cy - ASize.cx) mod 2;
- end else if ASize.cx > ASize.cy then
- begin
- ARect.Left := ARect.Left + (ASize.cx - ASize.cy) div 2;
- ARect.Right := ARect.Right - (ASize.cx - ASize.cy) div 2 - (ASize.cx - ASize.cy) mod 2;
- end;
- if Flat then InflateRect(ARect, -1, -1);
- if UseButtonsBitmapCache then
- begin
- BitmapInfo.Size := Point(ARect.Right - ARect.Left, ARect.Bottom - ARect.Top);
- BitmapInfo.CheckState := State;
- BitmapInfo.Pressed := DownButton <> 0;
- BitmapInfo.Active := Active;
- BitmapInfo.Enabled := Enabled;
- Bitmap := ButtonsBitmapCache.GetButtonBitmap(BitmapInfo);
- StretchBlt(DC, ARect.Left, ARect.Top, ARect.Right - ARect.Left,
- ARect.Bottom - ARect.Top, Bitmap.Canvas.Handle, 0, 0,
- Bitmap.Width, Bitmap.Height, cmSrcCopy);
- end else
- DrawCheck(DC, ARect, State, Enabled, Flat, DownButton <> 0, Active);
- if Flat then
- begin
- InflateRect(ARect, 1, 1);
- if Active then
- DrawEdge(DC, ARect, BDR_SUNKENOUTER, BF_RECT)
- else
- begin
- // FrameRect(DC, ARect, GetCurrentObject(DC, OBJ_BRUSH));
- Brush := CreateSolidBrush(ColorToRGB(ParentColor));
- FrameRect(DC, ARect, Brush);
- DeleteObject(Brush);
- end;
- end;
- end else
- begin
- BitmapInfo.Active := Active;
- BitmapInfo.Enabled := Enabled;
- {$IFDEF EH_LIB_7}
- IsClipRgn := Flat and not Active and not ThemeServices.ThemesEnabled;
- {$ELSE}
- IsClipRgn := Flat and not Active;
- {$ENDIF}
- if IsClipRgn then
- begin
- DRect := ARect;
- WindowsLPtoDP(DC, DRect);
- InflateRect(ARect, -1, -1);
- if not UseButtons…
Large files files are truncated, but you can click here to view the full file