2 {*****************************************************************************}
4 { Tnt Delphi Unicode Controls }
5 { http://www.tntware.com/delphicontrols/unicode/ }
8 { Copyright (c) 2002-2007, Troy Wolbrink (troy.wolbrink@tntware.com) }
10 {*****************************************************************************}
14 {$INCLUDE TntCompilers.inc}
19 Classes
, Messages
, Windows
, Controls
, StdCtrls
, CheckLst
,
20 TntClasses
, TntControls
, TntStdCtrls
;
23 {TNT-WARN TCheckListBox}
24 TTntCheckListBox
= class(TCheckListBox
{TNT-ALLOW TCheckListBox}, IWideCustomListControl
)
27 FSaveItems
: TTntStrings
;
28 FSaveTopIndex
: Integer;
29 FSaveItemIndex
: Integer;
30 FSaved_ItemEnabled
: array of Boolean;
31 FSaved_State
: array of TCheckBoxState
;
32 FSaved_Header
: array of Boolean;
33 FOnData
: TLBGetWideDataEvent
;
34 procedure SetItems(const Value
: TTntStrings
);
35 function GetHint
: WideString
;
36 procedure SetHint(const Value
: WideString
);
37 function IsHintStored
: Boolean;
38 procedure LBGetText(var Message: TMessage
); message LB_GETTEXT
;
39 procedure LBGetTextLen(var Message: TMessage
); message LB_GETTEXTLEN
;
41 procedure CreateWindowHandle(const Params
: TCreateParams
); override;
42 procedure DefineProperties(Filer
: TFiler
); override;
43 function GetActionLinkClass
: TControlActionLinkClass
; override;
44 procedure ActionChange(Sender
: TObject
; CheckDefaults
: Boolean); override;
45 procedure CreateWnd
; override;
46 procedure DestroyWnd
; override;
47 procedure DrawItem(Index
: Integer; Rect
: TRect
; State
: TOwnerDrawState
); override;
49 constructor Create(AOwner
: TComponent
); override;
50 destructor Destroy
; override;
51 procedure CopySelection(Destination
: TCustomListControl
); override;
52 procedure AddItem(const Item
: WideString
; AObject
: TObject
); reintroduce
; virtual;
54 property Hint
: WideString read GetHint write SetHint stored IsHintStored
;
55 property Items
: TTntStrings read FItems write SetItems
;
56 property OnData
: TLBGetWideDataEvent read FOnData write FOnData
;
62 SysUtils
, Math
, TntActnList
;
66 constructor TTntCheckListBox
.Create(AOwner
: TComponent
);
69 FItems
:= TTntListBoxStrings
.Create
;
70 TTntListBoxStrings(FItems
).ListBox
:= Self
;
73 destructor TTntCheckListBox
.Destroy
;
79 procedure TTntCheckListBox
.CreateWindowHandle(const Params
: TCreateParams
);
81 CreateUnicodeHandle(Self
, Params
, 'LISTBOX');
84 procedure TTntCheckListBox
.DefineProperties(Filer
: TFiler
);
87 TntPersistent_AfterInherited_DefineProperties(Filer
, Self
);
90 procedure TTntCheckListBox
.CreateWnd
;
95 TntListBox_AfterInherited_CreateWnd(Self
, FSaveItems
, FItems
, FSaveTopIndex
, FSaveItemIndex
);
96 if Length(FSaved_ItemEnabled
) > 0 then begin
97 for i
:= 0 to Min(Items
.Count
- 1, High(FSaved_ItemEnabled
)) do begin
98 ItemEnabled
[i
] := FSaved_ItemEnabled
[i
];
99 State
[i
] := FSaved_State
[i
];
100 Header
[i
] := FSaved_Header
[i
];
102 SetLength(FSaved_ItemEnabled
, 0);
103 SetLength(FSaved_State
, 0);
104 SetLength(FSaved_Header
, 0);
108 procedure TTntCheckListBox
.DestroyWnd
;
112 SetLength(FSaved_ItemEnabled
, Items
.Count
);
113 SetLength(FSaved_State
, Items
.Count
);
114 SetLength(FSaved_Header
, Items
.Count
);
115 for i
:= 0 to Items
.Count
- 1 do begin
116 FSaved_ItemEnabled
[i
] := ItemEnabled
[i
];
117 FSaved_State
[i
] := State
[i
];
118 FSaved_Header
[i
] := Header
[i
];
120 TntListBox_BeforeInherited_DestroyWnd(Self
, FSaveItems
, FItems
, FSaveTopIndex
, FSaveItemIndex
);
124 procedure TTntCheckListBox
.SetItems(const Value
: TTntStrings
);
126 FItems
.Assign(Value
);
129 procedure TTntCheckListBox
.DrawItem(Index
: Integer; Rect
: TRect
; State
: TOwnerDrawState
);
132 if not Assigned(OnDrawItem
) then
133 TntListBox_DrawItem_Text(Self
, Items
, Index
, Rect
);
136 function TTntCheckListBox
.IsHintStored
: Boolean;
138 Result
:= TntControl_IsHintStored(Self
)
141 function TTntCheckListBox
.GetHint
: WideString
;
143 Result
:= TntControl_GetHint(Self
)
146 procedure TTntCheckListBox
.SetHint(const Value
: WideString
);
148 TntControl_SetHint(Self
, Value
);
151 procedure TTntCheckListBox
.AddItem(const Item
: WideString
; AObject
: TObject
);
153 TntListBox_AddItem(Items
, Item
, AObject
);
156 procedure TTntCheckListBox
.CopySelection(Destination
: TCustomListControl
);
158 TntListBox_CopySelection(Self
, Items
, Destination
);
161 procedure TTntCheckListBox
.ActionChange(Sender
: TObject
; CheckDefaults
: Boolean);
163 TntControl_BeforeInherited_ActionChange(Self
, Sender
, CheckDefaults
);
167 function TTntCheckListBox
.GetActionLinkClass
: TControlActionLinkClass
;
169 Result
:= TntControl_GetActionLinkClass(Self
, inherited GetActionLinkClass
);
172 procedure TTntCheckListBox
.LBGetText(var Message: TMessage
);
174 if not TntCustomListBox_LBGetText(Self
, OnData
, Message) then
178 procedure TTntCheckListBox
.LBGetTextLen(var Message: TMessage
);
180 if not TntCustomListBox_LBGetTextLen(Self
, OnData
, Message) then