/
JvExStdCtrls.pas
396 lines (308 loc) · 9.85 KB
/
JvExStdCtrls.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
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvExStdCtrls.pas, released on 2004-01-04
The Initial Developer of the Original Code is Andreas Hausladen [Andreas dott Hausladen att gmx dott de]
Portions created by Andreas Hausladen are Copyright (C) 2003 Andreas Hausladen.
All Rights Reserved.
Contributor(s): -
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.delphi-jedi.org
Known Issues:
-----------------------------------------------------------------------------}
// $Id$
unit JvExStdCtrls;
{$I jvcl.inc}
{MACROINCLUDE JvExControls.macros}
WARNINGHEADER
interface
uses
Windows, Messages, Types,
SysUtils, Classes, Graphics, Controls, Forms, StdCtrls,
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
JvTypes, JvThemes, JVCLVer, JvExControls;
type
WINCONTROL_DECL_DEFAULT(CustomGroupBox)
{$DEFINE HASAUTOSIZE}
CONTROL_DECL_DEFAULT(CustomLabel)
CONTROL_DECL_DEFAULT(Label)
{$UNDEF HASAUTOSIZE}
TJvExCustomEdit = class(TCustomEdit, IJvExControl)
EDITCONTROL_DECL
private
{$IFNDEF COMPILER12_UP}
FTextHint: string;
procedure SetTextHint(const Value: string);
{$ENDIF ~COMPILER12_UP}
function UserTextHint: Boolean;
protected
procedure DoSetTextHint(const Value: string); {$IFDEF COMPILER12_UP}override;{$ELSE}virtual;{$ENDIF}
procedure PaintWindow(DC: HDC); override;
procedure WMSetFocus(var Msg: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Msg: TWMKillFocus); message WM_KILLFOCUS;
{$IFNDEF COMPILER12_UP}
procedure CreateWnd; override;
property TextHint: string read FTextHint write SetTextHint;
{$ENDIF ~COMPILER12_UP}
end;
EDITCONTROL_DECL_DEFAULT(CustomMemo)
WINCONTROL_DECL_DEFAULT(CustomCombo)
TJvExCustomComboBox = class(TCustomComboBox, IJvExControl)
WINCONTROL_DECL
private
{$IFNDEF COMPILER12_UP}
FTextHint: string;
procedure SetTextHint(const Value: string);
{$ENDIF ~COMPILER12_UP}
function UserTextHint: Boolean;
function IsEditReadOnly: Boolean;
protected
procedure DoSetTextHint; {$IFDEF COMPILER12_UP}override;{$ELSE}virtual;{$ENDIF}
procedure ComboWndProc(var Message: TMessage; ComboWnd: HWND; ComboProc: Pointer); override;
{$IFNDEF COMPILER12_UP}
procedure CreateWnd; override;
property TextHint: string read FTextHint write SetTextHint;
{$ENDIF ~COMPILER12_UP}
end;
WINCONTROL_DECL_DEFAULT(ButtonControl)
WINCONTROL_DECL_DEFAULT(Button)
WINCONTROL_DECL_DEFAULT(CustomCheckBox)
WINCONTROL_DECL_DEFAULT(RadioButton)
WINCONTROL_DECL_DEFAULT(CustomListBox)
WINCONTROL_DECL_DEFAULT(ScrollBar)
WINCONTROL_DECL_DEFAULT(GroupBox)
WINCONTROL_DECL_DEFAULT(CheckBox)
WINCONTROL_DECL_DEFAULT(CustomStaticText)
WINCONTROL_DECL_DEFAULT(StaticText)
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL$';
Revision: '$Revision$';
Date: '$Date$';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
JclSysInfo;
{$IFNDEF COMPILER12_UP}
const
ECM_FIRST = $1500;
EM_SETCUEBANNER = ECM_FIRST + 1; // Set the cue banner with the lParam = LPCWSTR
CBM_FIRST = $1700;
CB_SETCUEBANNER = CBM_FIRST + 3;
type
UnicodeString = WideString;
{$ENDIF ~COMPILER12_UP}
WINCONTROL_IMPL_DEFAULT(CustomGroupBox)
{$DEFINE HASAUTOSIZE}
CONTROL_IMPL_DEFAULT(CustomLabel)
CONTROL_IMPL_DEFAULT(Label)
{$UNDEF HASAUTOSIZE}
BEGIN_EDITCONTROL_CONSTRUCTOR(CustomEdit)
if UserTextHint then
ControlState := ControlState + [csCustomPaint]; // needed for PaintWindow
END_CONSTRUCTOR
EDITCONTROL_IMPL(CustomEdit)
EDITCONTROL_WNDPROC(CustomEdit)
{$IFNDEF COMPILER12_UP}
procedure TJvExCustomEdit.SetTextHint(const Value: string);
begin
if FTextHint <> Value then
begin
FTextHint := Value;
if not (csLoading in ComponentState) then
DoSetTextHint(FTextHint);
end;
end;
procedure TJvExCustomEdit.CreateWnd;
begin
inherited CreateWnd;
DoSetTextHint(FTextHint);
end;
{$ENDIF ~COMPILER12_UP}
function TJvExCustomEdit.UserTextHint: Boolean;
begin
{$IFDEF JVCLThemesEnabled}
Result := not (JclCheckWinVersion(5, 1) and StyleServices.Enabled);
{$ELSE}
Result := True;
{$ENDIF JVCLThemesEnabled}
end;
procedure TJvExCustomEdit.DoSetTextHint(const Value: string);
begin
{$IFDEF COMPILER12_UP}
inherited DoSetTextHint(Value);
{$ELSE}
{$IFDEF JVCLThemesEnabled}
if JclCheckWinVersion(5, 1) and StyleServices.Enabled and HandleAllocated then
SendMessage(Handle, EM_SETCUEBANNER, WPARAM(0), LPARAM(PWideChar(UnicodeString(Value))));
{$ENDIF JVCLThemesEnabled}
{$ENDIF COMPILER12_UP}
if UserTextHint and HandleAllocated and
not Focused and Enabled and not ReadOnly and (Text = '') then
Invalidate;
end;
procedure TJvExCustomEdit.PaintWindow(DC: HDC);
var
R: TRect;
OldFont: HFONT;
OldTextColor: TColorRef;
begin
inherited PaintWindow(DC);
if UserTextHint and (TextHint <> '') and
Enabled and not ReadOnly and not Focused and (Text = '') then
begin
SendMessage(Handle, EM_GETRECT, 0, LPARAM(@R));
OldFont := SelectObject(DC, Font.Handle);
OldTextColor := SetTextColor(DC, ColorToRGB(clGrayText));
DrawText(DC, PChar(TextHint), Length(TextHint), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX);
SetTextColor(DC, OldTextColor);
SelectObject(DC, OldFont);
end;
end;
procedure TJvExCustomEdit.WMKillFocus(var Msg: TWMKillFocus);
begin
inherited;
if UserTextHint and (TextHint <> '') then
Invalidate;
end;
procedure TJvExCustomEdit.WMSetFocus(var Msg: TWMSetFocus);
begin
if UserTextHint and (TextHint <> '') then
Invalidate;
inherited;
end;
EDITCONTROL_IMPL_DEFAULT(CustomMemo)
WINCONTROL_IMPL_DEFAULT(CustomCombo)
BEGIN_WINCONTROL_CONSTRUCTOR(CustomComboBox)
if UserTextHint then
ControlState := ControlState + [csCustomPaint]; // needed for PaintWindow
END_CONSTRUCTOR
WINCONTROL_IMPL(CustomComboBox)
WINCONTROL_WNDPROC(CustomComboBox)
{$IFNDEF COMPILER12_UP}
procedure TJvExCustomComboBox.SetTextHint(const Value: string);
begin
if FTextHint <> Value then
begin
FTextHint := Value;
if not (csLoading in ComponentState) then
DoSetTextHint;
end;
end;
procedure TJvExCustomComboBox.CreateWnd;
begin
inherited CreateWnd;
DoSetTextHint;
end;
{$ENDIF ~COMPILER12_UP}
function TJvExCustomComboBox.UserTextHint: Boolean;
begin
{$IFDEF JVCLThemesEnabled}
Result := not (JclCheckWinVersion(5, 1) and StyleServices.Enabled);
{$ELSE}
Result := True;
{$ENDIF JVCLThemesEnabled}
end;
function TJvExCustomComboBox.IsEditReadOnly: Boolean;
begin
Result := HandleAllocated and (GetWindowLong(FEditHandle, GWL_STYLE) and ES_READONLY <> 0);
end;
procedure TJvExCustomComboBox.DoSetTextHint;
begin
{$IFDEF COMPILER12_UP}
inherited DoSetTextHint;
{$ELSE}
{$IFDEF JVCLThemesEnabled}
if StyleServices.Enabled and HandleAllocated then
begin
if JclCheckWinVersion(6, 0) then
SendMessage(Handle, CB_SETCUEBANNER, WPARAM(0), LPARAM(PWideChar(UnicodeString(FTextHint))))
else if JclCheckWinVersion(5, 1) then
SendMessage(FEditHandle, EM_SETCUEBANNER, WPARAM(0), LPARAM(PWideChar(UnicodeString(FTextHint))));
end;
{$ENDIF JVCLThemesEnabled}
{$ENDIF COMPILER12_UP}
if UserTextHint and HandleAllocated and
not Focused and Enabled and not IsEditReadOnly and (Text = '') then
Invalidate;
end;
procedure TJvExCustomComboBox.ComboWndProc(var Message: TMessage; ComboWnd: HWND; ComboProc: Pointer);
procedure EditPaintWindow(DC: HDC);
var
R: TRect;
OldFont: HFONT;
OldTextColor: TColorRef;
begin
if UserTextHint and (TextHint <> '') and
Enabled and not IsEditReadOnly and not Focused and (Text = '') then
begin
SendMessage(FEditHandle, EM_GETRECT, 0, LPARAM(@R));
OldFont := SelectObject(DC, Font.Handle);
OldTextColor := SetTextColor(DC, ColorToRGB(clGrayText));
DrawText(DC, PChar(TextHint), Length(TextHint), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX);
SetTextColor(DC, OldTextColor);
SelectObject(DC, OldFont);
end;
end;
var
DC: HDC;
PaintStruct: TPaintStruct;
begin
DC := 0;
try
if (ComboWnd = FEditHandle) and UserTextHint and (Message.Msg = WM_PAINT) then
begin
if TWMPaint(Message).DC = 0 then
begin
DC := BeginPaint(ComboWnd, PaintStruct);
TWMPaint(Message).DC := DC;
end;
end;
inherited ComboWndProc(Message, ComboWnd, ComboProc);
if ComboWnd = FEditHandle then
begin
case Message.Msg of
WM_PAINT:
EditPaintWindow(DC);
WM_PRINTCLIENT:
EditPaintWindow(HDC(Message.WParam));
WM_KILLFOCUS, WM_SETFOCUS:
if UserTextHint and (TextHint <> '') then
Invalidate;
end;
end;
finally
if DC <> 0 then
begin
EndPaint(ComboWnd, PaintStruct);
TWMPaint(Message).DC := 0;
end;
end;
end;
WINCONTROL_IMPL_DEFAULT(ButtonControl)
WINCONTROL_IMPL_DEFAULT(Button)
WINCONTROL_IMPL_DEFAULT(CustomCheckBox)
WINCONTROL_IMPL_DEFAULT(RadioButton)
WINCONTROL_IMPL_DEFAULT(CustomListBox)
WINCONTROL_IMPL_DEFAULT(ScrollBar)
WINCONTROL_IMPL_DEFAULT(GroupBox)
WINCONTROL_IMPL_DEFAULT(CheckBox)
WINCONTROL_IMPL_DEFAULT(CustomStaticText)
WINCONTROL_IMPL_DEFAULT(StaticText)
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.