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
, Windows
, Messages
, DB
, DBCtrls
, Controls
, StdCtrls
,
20 TntClasses
, TntStdCtrls
, TntControls
, TntComCtrls
, TntExtCtrls
;
23 {TNT-WARN TPaintControl}
24 TTntPaintControl
= class
27 FClassName
: WideString
;
29 FObjectInstance
: Pointer;
30 FDefWindowProc
: Pointer;
31 FCtl3dButton
: Boolean;
32 function GetHandle
: HWnd
;
33 procedure SetCtl3DButton(Value
: Boolean);
34 procedure WndProc(var Message: TMessage
);
36 constructor Create(AOwner
: TWinControl
; const ClassName
: WideString
);
37 destructor Destroy
; override;
38 procedure DestroyHandle
;
39 property Ctl3DButton
: Boolean read FCtl3dButton write SetCtl3dButton
;
40 property Handle
: HWnd read GetHandle
;
45 TTntDBEdit
= class(TDBEdit
{TNT-ALLOW TDBEdit})
47 InheritedDataChange
: TNotifyEvent
;
48 FPasswordChar
: WideChar
;
49 procedure DataChange(Sender
: TObject
);
50 procedure UpdateData(Sender
: TObject
);
51 function GetHint
: WideString
;
52 procedure SetHint(const Value
: WideString
);
53 function IsHintStored
: Boolean;
54 procedure WMPaint(var Message: TWMPaint
); message WM_PAINT
;
55 function GetTextMargins
: TPoint
;
56 function GetPasswordChar
: WideChar
;
57 procedure SetPasswordChar(const Value
: WideChar
);
58 procedure CMEnter(var Message: TCMEnter
); message CM_ENTER
;
60 function GetSelStart
: Integer; reintroduce
; virtual;
61 procedure SetSelStart(const Value
: Integer); reintroduce
; virtual;
62 function GetSelLength
: Integer; reintroduce
; virtual;
63 procedure SetSelLength(const Value
: Integer); reintroduce
; virtual;
64 function GetSelText
: WideString
; reintroduce
;
65 procedure SetSelText(const Value
: WideString
);
66 function GetText
: WideString
;
67 procedure SetText(const Value
: WideString
);
69 procedure CreateWindowHandle(const Params
: TCreateParams
); override;
70 procedure CreateWnd
; override;
71 procedure DefineProperties(Filer
: TFiler
); override;
72 function GetActionLinkClass
: TControlActionLinkClass
; override;
73 procedure ActionChange(Sender
: TObject
; CheckDefaults
: Boolean); override;
75 constructor Create(AOwner
: TComponent
); override;
76 property SelText
: WideString read GetSelText write SetSelText
;
77 property SelStart
: Integer read GetSelStart write SetSelStart
;
78 property SelLength
: Integer read GetSelLength write SetSelLength
;
79 property Text: WideString read GetText write SetText
;
81 property Hint
: WideString read GetHint write SetHint stored IsHintStored
;
82 property PasswordChar
: WideChar read GetPasswordChar write SetPasswordChar default
#0;
86 TTntDBText
= class(TDBText
{TNT-ALLOW TDBText})
88 FDataLink
: TFieldDataLink
;
89 InheritedDataChange
: TNotifyEvent
;
90 function GetHint
: WideString
;
91 procedure SetHint(const Value
: WideString
);
92 function IsHintStored
: Boolean;
93 procedure CMHintShow(var Message: TMessage
); message CM_HINTSHOW
;
94 procedure CMDialogChar(var Message: TCMDialogChar
); message CM_DIALOGCHAR
;
95 function GetCaption
: TWideCaption
;
96 function IsCaptionStored
: Boolean;
97 procedure SetCaption(const Value
: TWideCaption
);
98 function GetFieldText
: WideString
;
99 procedure DataChange(Sender
: TObject
);
101 procedure DefineProperties(Filer
: TFiler
); override;
102 function GetLabelText
: WideString
; reintroduce
; virtual;
103 function GetActionLinkClass
: TControlActionLinkClass
; override;
104 procedure ActionChange(Sender
: TObject
; CheckDefaults
: Boolean); override;
105 procedure DoDrawText(var Rect
: TRect
; Flags
: Longint); override;
107 constructor Create(AOwner
: TComponent
); override;
108 destructor Destroy
; override;
109 property Caption
: TWideCaption read GetCaption write SetCaption stored IsCaptionStored
;
111 property Hint
: WideString read GetHint write SetHint stored IsHintStored
;
114 {TNT-WARN TDBComboBox}
115 TTntCustomDBComboBox
= class(TDBComboBox
{TNT-ALLOW TDBComboBox},
116 IWideCustomListControl
)
118 FDataLink
: TFieldDataLink
;
121 procedure UpdateData(Sender
: TObject
);
122 procedure EditingChange(Sender
: TObject
);
123 procedure CMEnter(var Message: TCMEnter
); message CM_ENTER
;
124 procedure SetReadOnly
;
125 function GetHint
: WideString
;
126 procedure SetHint(const Value
: WideString
);
127 function IsHintStored
: Boolean;
128 procedure WMChar(var Message: TWMChar
); message WM_CHAR
;
131 FSaveItems
: TTntStrings
;
132 FSaveItemIndex
: integer;
133 function GetItems
: TTntStrings
;
134 procedure SetItems(const Value
: TTntStrings
); reintroduce
;
135 function GetSelStart
: Integer;
136 procedure SetSelStart(const Value
: Integer);
137 function GetSelLength
: Integer;
138 procedure SetSelLength(const Value
: Integer);
139 function GetSelText
: WideString
;
140 procedure SetSelText(const Value
: WideString
);
141 function GetText
: WideString
;
142 procedure SetText(const Value
: WideString
);
144 procedure CNCommand(var Message: TWMCommand
); message CN_COMMAND
;
146 procedure DataChange(Sender
: TObject
);
147 function GetAutoComplete_UniqueMatchOnly
: Boolean; dynamic;
148 function GetAutoComplete_PreserveDataEntryCase
: Boolean; dynamic;
149 procedure DoEditCharMsg(var Message: TWMChar
); virtual;
150 function GetFieldValue
: Variant
; virtual;
151 procedure SetFieldValue(const Value
: Variant
); virtual;
152 function GetComboValue
: Variant
; virtual; abstract;
153 procedure SetComboValue(const Value
: Variant
); virtual; abstract;
154 {$IFDEF DELPHI_7} // fix for Delphi 7 only
155 function GetItemsClass
: TCustomComboBoxStringsClass
; override;
158 procedure CreateWindowHandle(const Params
: TCreateParams
); override;
159 procedure DefineProperties(Filer
: TFiler
); override;
160 function GetActionLinkClass
: TControlActionLinkClass
; override;
161 procedure ActionChange(Sender
: TObject
; CheckDefaults
: Boolean); override;
162 procedure CreateWnd
; override;
163 procedure DestroyWnd
; override;
164 procedure WndProc(var Message: TMessage
); override;
165 procedure ComboWndProc(var Message: TMessage
; ComboWnd
: HWnd
; ComboProc
: Pointer); override;
166 procedure KeyPress(var Key
: AnsiChar
); override;
168 constructor Create(AOwner
: TComponent
); override;
169 destructor Destroy
; override;
170 procedure CopySelection(Destination
: TCustomListControl
); override;
171 procedure AddItem(const Item
: WideString
; AObject
: TObject
); reintroduce
; virtual;
173 property SelText
: WideString read GetSelText write SetSelText
;
174 property SelStart
: Integer read GetSelStart write SetSelStart
;
175 property SelLength
: Integer read GetSelLength write SetSelLength
;
176 property Text: WideString read GetText write SetText
;
178 property Hint
: WideString read GetHint write SetHint stored IsHintStored
;
179 property Items
: TTntStrings read GetItems write SetItems
;
182 TTntDBComboBox
= class(TTntCustomDBComboBox
)
184 function GetFieldValue
: Variant
; override;
185 procedure SetFieldValue(const Value
: Variant
); override;
186 function GetComboValue
: Variant
; override;
187 procedure SetComboValue(const Value
: Variant
); override;
191 {TNT-WARN TDBCheckBox}
192 TTntDBCheckBox
= class(TDBCheckBox
{TNT-ALLOW TDBCheckBox})
194 function GetCaption
: TWideCaption
;
195 procedure SetCaption(const Value
: TWideCaption
);
196 function GetHint
: WideString
;
197 procedure SetHint(const Value
: WideString
);
198 function IsCaptionStored
: Boolean;
199 function IsHintStored
: Boolean;
201 procedure CreateWindowHandle(const Params
: TCreateParams
); override;
202 procedure DefineProperties(Filer
: TFiler
); override;
203 function GetActionLinkClass
: TControlActionLinkClass
; override;
204 procedure ActionChange(Sender
: TObject
; CheckDefaults
: Boolean); override;
205 procedure Toggle
; override;
207 property Caption
: TWideCaption read GetCaption write SetCaption stored IsCaptionStored
;
208 property Hint
: WideString read GetHint write SetHint stored IsHintStored
;
211 {TNT-WARN TDBRichEdit}
212 TTntDBRichEdit
= class(TTntCustomRichEdit
)
214 FDataLink
: TFieldDataLink
;
215 FAutoDisplay
: Boolean;
217 FMemoLoaded
: Boolean;
218 FDataSave
: AnsiString
;
219 procedure BeginEditing
;
220 procedure DataChange(Sender
: TObject
);
221 procedure EditingChange(Sender
: TObject
);
222 function GetDataField
: WideString
;
223 function GetDataSource
: TDataSource
;
224 function GetField
: TField
;
225 function GetReadOnly
: Boolean;
226 procedure SetDataField(const Value
: WideString
);
227 procedure SetDataSource(Value
: TDataSource
);
228 procedure SetReadOnly(Value
: Boolean);
229 procedure SetAutoDisplay(Value
: Boolean);
230 procedure SetFocused(Value
: Boolean);
231 procedure UpdateData(Sender
: TObject
);
232 procedure WMCut(var Message: TMessage
); message WM_CUT
;
233 procedure WMPaste(var Message: TMessage
); message WM_PASTE
;
234 procedure CMEnter(var Message: TCMEnter
); message CM_ENTER
;
235 procedure CMExit(var Message: TCMExit
); message CM_EXIT
;
236 procedure WMLButtonDblClk(var Message: TWMLButtonDblClk
); message WM_LBUTTONDBLCLK
;
237 procedure CMGetDataLink(var Message: TMessage
); message CM_GETDATALINK
;
238 procedure CNNotify(var Message: TWMNotify
); message CN_NOTIFY
;
240 procedure InternalLoadMemo
; dynamic;
241 procedure InternalSaveMemo
; dynamic;
243 procedure Change
; override;
244 procedure KeyDown(var Key
: Word; Shift
: TShiftState
); override;
245 procedure KeyPress(var Key
: AnsiChar
); override;
246 procedure Loaded
; override;
247 procedure Notification(AComponent
: TComponent
; Operation
: TOperation
); override;
249 constructor Create(AOwner
: TComponent
); override;
250 destructor Destroy
; override;
251 function ExecuteAction(Action
: TBasicAction
): Boolean; override;
252 procedure LoadMemo
; virtual;
253 function UpdateAction(Action
: TBasicAction
): Boolean; override;
254 function UseRightToLeftAlignment
: Boolean; override;
255 property Field
: TField read GetField
;
260 property AutoDisplay
: Boolean read FAutoDisplay write SetAutoDisplay default
True;
267 property BorderStyle
;
269 property Constraints
;
271 property DataField
: WideString read GetDataField write SetDataField
;
272 property DataSource
: TDataSource read GetDataSource write SetDataSource
;
278 property HideSelection
;
279 property HideScrollBars
;
283 property ParentBiDiMode
;
284 property ParentColor
;
285 property ParentCtl3D
;
287 property ParentShowHint
;
290 property ReadOnly
: Boolean read GetReadOnly write SetReadOnly default
False;
296 property WantReturns
;
301 property OnContextPopup
;
312 {$IFDEF COMPILER_9_UP}
313 property OnMouseActivate
;
315 property OnMouseDown
;
316 {$IFDEF COMPILER_10_UP}
317 property OnMouseEnter
;
318 property OnMouseLeave
;
320 property OnMouseMove
;
322 property OnResizeRequest
;
323 property OnSelectionChange
;
324 property OnProtectChange
;
325 property OnSaveClipboard
;
326 property OnStartDock
;
327 property OnStartDrag
;
332 TTntDBMemo
= class(TTntCustomMemo
)
334 FDataLink
: TFieldDataLink
;
335 FAutoDisplay
: Boolean;
337 FMemoLoaded
: Boolean;
338 FPaintControl
: TTntPaintControl
;
339 procedure DataChange(Sender
: TObject
);
340 procedure EditingChange(Sender
: TObject
);
341 function GetDataField
: WideString
;
342 function GetDataSource
: TDataSource
;
343 function GetField
: TField
;
344 function GetReadOnly
: Boolean;
345 procedure SetDataField(const Value
: WideString
);
346 procedure SetDataSource(Value
: TDataSource
);
347 procedure SetReadOnly(Value
: Boolean);
348 procedure SetAutoDisplay(Value
: Boolean);
349 procedure SetFocused(Value
: Boolean);
350 procedure UpdateData(Sender
: TObject
);
351 procedure WMCut(var Message: TMessage
); message WM_CUT
;
352 procedure WMPaste(var Message: TMessage
); message WM_PASTE
;
353 procedure WMUndo(var Message: TMessage
); message WM_UNDO
;
354 procedure CMEnter(var Message: TCMEnter
); message CM_ENTER
;
355 procedure CMExit(var Message: TCMExit
); message CM_EXIT
;
356 procedure WMLButtonDblClk(var Message: TWMLButtonDblClk
); message WM_LBUTTONDBLCLK
;
357 procedure WMPaint(var Message: TWMPaint
); message WM_PAINT
;
358 procedure CMGetDataLink(var Message: TMessage
); message CM_GETDATALINK
;
360 procedure Change
; override;
361 procedure KeyDown(var Key
: Word; Shift
: TShiftState
); override;
362 procedure KeyPress(var Key
: Char{TNT-ALLOW Char}); override;
363 procedure Loaded
; override;
364 procedure Notification(AComponent
: TComponent
;
365 Operation
: TOperation
); override;
366 procedure WndProc(var Message: TMessage
); override;
368 constructor Create(AOwner
: TComponent
); override;
369 destructor Destroy
; override;
370 function ExecuteAction(Action
: TBasicAction
): Boolean; override;
371 procedure LoadMemo
; virtual;
372 function UpdateAction(Action
: TBasicAction
): Boolean; override;
373 function UseRightToLeftAlignment
: Boolean; override;
374 property Field
: TField read GetField
;
379 property AutoDisplay
: Boolean read FAutoDisplay write SetAutoDisplay default
True;
386 property BorderStyle
;
388 property Constraints
;
390 property DataField
: WideString read GetDataField write SetDataField
;
391 property DataSource
: TDataSource read GetDataSource write SetDataSource
;
397 property HideSelection
;
401 property ParentBiDiMode
;
402 property ParentColor
;
403 property ParentCtl3D
;
405 property ParentShowHint
;
407 property ReadOnly
: Boolean read GetReadOnly write SetReadOnly default
False;
413 property WantReturns
;
418 property OnContextPopup
;
429 {$IFDEF COMPILER_9_UP}
430 property OnMouseActivate
;
432 property OnMouseDown
;
433 {$IFDEF COMPILER_10_UP}
434 property OnMouseEnter
;
435 property OnMouseLeave
;
437 property OnMouseMove
;
439 property OnStartDock
;
440 property OnStartDrag
;
445 TTntDBRadioGroup
= class(TTntCustomRadioGroup
)
447 FDataLink
: TFieldDataLink
;
449 FValues
: TTntStrings
;
450 FInSetValue
: Boolean;
451 FOnChange
: TNotifyEvent
;
452 procedure DataChange(Sender
: TObject
);
453 procedure UpdateData(Sender
: TObject
);
454 function GetDataField
: WideString
;
455 function GetDataSource
: TDataSource
;
456 function GetField
: TField
;
457 function GetReadOnly
: Boolean;
458 function GetButtonValue(Index
: Integer): WideString
;
459 procedure SetDataField(const Value
: WideString
);
460 procedure SetDataSource(Value
: TDataSource
);
461 procedure SetReadOnly(Value
: Boolean);
462 procedure SetValue(const Value
: WideString
);
463 procedure SetItems(Value
: TTntStrings
);
464 procedure SetValues(Value
: TTntStrings
);
465 procedure CMExit(var Message: TCMExit
); message CM_EXIT
;
466 procedure CMGetDataLink(var Message: TMessage
); message CM_GETDATALINK
;
468 procedure Change
; dynamic;
469 procedure Click
; override;
470 procedure KeyPress(var Key
: Char{TNT-ALLOW Char}); override;
471 function CanModify
: Boolean; override;
472 procedure Notification(AComponent
: TComponent
; Operation
: TOperation
); override;
473 property DataLink
: TFieldDataLink read FDataLink
;
475 constructor Create(AOwner
: TComponent
); override;
476 destructor Destroy
; override;
477 function ExecuteAction(Action
: TBasicAction
): Boolean; override;
478 function UpdateAction(Action
: TBasicAction
): Boolean; override;
479 function UseRightToLeftAlignment
: Boolean; override;
480 property Field
: TField read GetField
;
482 property Value
: WideString read FValue write SetValue
;
490 property Constraints
;
492 property DataField
: WideString read GetDataField write SetDataField
;
493 property DataSource
: TDataSource read GetDataSource write SetDataSource
;
499 property Items write SetItems
;
500 {$IFDEF COMPILER_7_UP}
501 property ParentBackground
;
503 property ParentBiDiMode
;
504 property ParentColor
;
505 property ParentCtl3D
;
507 property ParentShowHint
;
509 property ReadOnly
: Boolean read GetReadOnly write SetReadOnly default
False;
513 property Values
: TTntStrings read FValues write SetValues
;
515 property OnChange
: TNotifyEvent read FOnChange write FOnChange
;
517 property OnContextPopup
;
524 {$IFDEF COMPILER_10_UP}
525 property OnMouseEnter
;
526 property OnMouseLeave
;
528 property OnStartDock
;
529 property OnStartDrag
;
535 Forms
, SysUtils
, Graphics
, Variants
, TntDB
,
536 TntActnList
, TntGraphics
, TntSysUtils
, RichEdit
, Mask
;
538 function FieldIsBlobLike(Field
: TField
): Boolean;
541 if Assigned(Field
) then begin
543 or (Field
.DataType
in [Low(TBlobType
).. High(TBlobType
)]) then
545 else if (Field
is TWideStringField
{TNT-ALLOW TWideStringField})
546 and (Field
.Size
= MaxInt
) then
547 Result
:= True; { wide string field filling in for a blob field }
554 TAccessWinControl
= class(TWinControl
);
556 constructor TTntPaintControl
.Create(AOwner
: TWinControl
; const ClassName
: WideString
);
559 FClassName
:= ClassName
;
562 destructor TTntPaintControl
.Destroy
;
567 procedure TTntPaintControl
.DestroyHandle
;
569 if FHandle
<> 0 then DestroyWindow(FHandle
);
570 Classes
.FreeObjectInstance(FObjectInstance
);
572 FObjectInstance
:= nil;
575 function TTntPaintControl
.GetHandle
: HWnd
;
577 Params
: TCreateParams
;
581 FObjectInstance
:= Classes
.MakeObjectInstance(WndProc
);
582 TAccessWinControl(FOwner
).CreateParams(Params
);
583 Params
.Style
:= Params
.Style
and not (WS_HSCROLL
or WS_VSCROLL
);
584 if (not Win32PlatformIsUnicode
) then begin
586 FHandle
:= CreateWindowEx(ExStyle
, PAnsiChar(AnsiString(FClassName
)),
587 PAnsiChar(TAccessWinControl(FOwner
).Text), Style
or WS_VISIBLE
,
588 X
, Y
, Width
, Height
, Application
.Handle
, 0, HInstance
, nil);
589 FDefWindowProc
:= Pointer(GetWindowLong(FHandle
, GWL_WNDPROC
));
590 SetWindowLong(FHandle
, GWL_WNDPROC
, Integer(FObjectInstance
));
593 FHandle
:= CreateWindowExW(ExStyle
, PWideChar(FClassName
),
594 PWideChar(TntControl_GetText(FOwner
)), Style
or WS_VISIBLE
,
595 X
, Y
, Width
, Height
, Application
.Handle
, 0, HInstance
, nil);
596 FDefWindowProc
:= Pointer(GetWindowLongW(FHandle
, GWL_WNDPROC
));
597 SetWindowLongW(FHandle
, GWL_WNDPROC
, Integer(FObjectInstance
));
599 SendMessage(FHandle
, WM_SETFONT
, Integer(TAccessWinControl(FOwner
).Font
.Handle
), 1);
604 procedure TTntPaintControl
.SetCtl3DButton(Value
: Boolean);
606 if FHandle
<> 0 then DestroyHandle
;
607 FCtl3DButton
:= Value
;
610 procedure TTntPaintControl
.WndProc(var Message: TMessage
);
613 if (Msg
>= CN_CTLCOLORMSGBOX
) and (Msg
<= CN_CTLCOLORSTATIC
) then
614 Result
:= FOwner
.Perform(Msg
, WParam
, LParam
)
615 else if (not Win32PlatformIsUnicode
) then
616 Result
:= CallWindowProcA(FDefWindowProc
, FHandle
, Msg
, WParam
, LParam
)
618 Result
:= CallWindowProcW(FDefWindowProc
, FHandle
, Msg
, WParam
, LParam
);
621 { THackFieldDataLink }
623 THackFieldDataLink_D6_D7_D9
= class(TDataLink
)
626 FxxxFieldName
: string{TNT-ALLOW string};
627 FxxxControl
: TComponent
;
628 FxxxEditing
: Boolean;
632 {$IFDEF COMPILER_6} // verified against VCL source in Delphi 6 and BCB 6
633 THackFieldDataLink
= THackFieldDataLink_D6_D7_D9
;
635 {$IFDEF DELPHI_7} // verified against VCL source in Delphi 7
636 THackFieldDataLink
= THackFieldDataLink_D6_D7_D9
;
638 {$IFDEF DELPHI_9} // verified against VCL source in Delphi 9
639 THackFieldDataLink
= THackFieldDataLink_D6_D7_D9
;
641 {$IFDEF DELPHI_10} // verified against VCL source in Delphi 10
642 THackFieldDataLink
= class(TDataLink
)
645 FxxxFieldName
: WideString
;
646 FxxxControl
: TComponent
;
647 FxxxEditing
: Boolean;
655 THackDBEdit_D6_D7_D9
= class(TCustomMaskEdit
)
657 FDataLink
: TFieldDataLink
;
658 FCanvas
: TControlCanvas
;
659 FAlignment
: TAlignment
;
663 {$IFDEF COMPILER_6} // verified against VCL source in Delphi 6 and BCB 6
664 THackDBEdit
= THackDBEdit_D6_D7_D9
;
666 {$IFDEF DELPHI_7} // verified against VCL source in Delphi 7
667 THackDBEdit
= THackDBEdit_D6_D7_D9
;
669 {$IFDEF DELPHI_9} // verified against VCL source in Delphi 9
670 THackDBEdit
= THackDBEdit_D6_D7_D9
;
672 {$IFDEF DELPHI_10} // verified against VCL source in Delphi 10
673 THackDBEdit
= THackDBEdit_D6_D7_D9
;
676 constructor TTntDBEdit
.Create(AOwner
: TComponent
);
679 InheritedDataChange
:= THackDBEdit(Self
).FDataLink
.OnDataChange
;
680 THackDBEdit(Self
).FDataLink
.OnDataChange
:= DataChange
;
681 THackDBEdit(Self
).FDataLink
.OnUpdateData
:= UpdateData
;
684 procedure TTntDBEdit
.CreateWindowHandle(const Params
: TCreateParams
);
686 CreateUnicodeHandle(Self
, Params
, 'EDIT');
689 procedure TTntDBEdit
.CreateWnd
;
692 TntCustomEdit_AfterInherited_CreateWnd(Self
, FPasswordChar
);
695 procedure TTntDBEdit
.DefineProperties(Filer
: TFiler
);
698 TntPersistent_AfterInherited_DefineProperties(Filer
, Self
);
701 function TTntDBEdit
.GetSelStart
: Integer;
703 Result
:= TntCustomEdit_GetSelStart(Self
);
706 procedure TTntDBEdit
.SetSelStart(const Value
: Integer);
708 TntCustomEdit_SetSelStart(Self
, Value
);
711 function TTntDBEdit
.GetSelLength
: Integer;
713 Result
:= TntCustomEdit_GetSelLength(Self
);
716 procedure TTntDBEdit
.SetSelLength(const Value
: Integer);
718 TntCustomEdit_SetSelLength(Self
, Value
);
721 function TTntDBEdit
.GetSelText
: WideString
;
723 Result
:= TntCustomEdit_GetSelText(Self
);
726 procedure TTntDBEdit
.SetSelText(const Value
: WideString
);
728 TntCustomEdit_SetSelText(Self
, Value
);
731 function TTntDBEdit
.GetPasswordChar
: WideChar
;
733 Result
:= TntCustomEdit_GetPasswordChar(Self
, FPasswordChar
)
736 procedure TTntDBEdit
.SetPasswordChar(const Value
: WideChar
);
738 TntCustomEdit_SetPasswordChar(Self
, FPasswordChar
, Value
);
741 function TTntDBEdit
.GetText
: WideString
;
743 Result
:= TntControl_GetText(Self
);
746 procedure TTntDBEdit
.SetText(const Value
: WideString
);
748 TntControl_SetText(Self
, Value
);
751 procedure TTntDBEdit
.DataChange(Sender
: TObject
);
753 with THackDBEdit(Self
), Self
do begin
755 InheritedDataChange(Sender
)
757 if FAlignment
<> Field
.Alignment
then
759 EditText
:= ''; {forces update}
760 FAlignment
:= Field
.Alignment
;
762 EditMask
:= Field
.EditMask
;
763 if not (csDesigning
in ComponentState
) then
765 if (Field
.DataType
in [ftString
, ftWideString
]) and (MaxLength
= 0) then
766 MaxLength
:= Field
.Size
;
768 if FFocused
and FDataLink
.CanModify
then
769 Text := GetWideText(Field
)
772 Text := GetWideDisplayText(Field
);
773 if FDataLink
.Editing
and THackFieldDataLink(FDataLink
).FModified
then
780 procedure TTntDBEdit
.UpdateData(Sender
: TObject
);
783 SetWideText(Field
, Text);
786 procedure TTntDBEdit
.CMEnter(var Message: TCMEnter
);
788 SaveFarEast
: Boolean;
790 SaveFarEast
:= SysLocale
.FarEast
;
792 SysLocale
.FarEast
:= False;
793 inherited; // inherited tries to work around Win95 FarEast bug, but introduces others
795 SysLocale
.FarEast
:= SaveFarEast
;
799 function TTntDBEdit
.IsHintStored
: Boolean;
801 Result
:= TntControl_IsHintStored(Self
);
804 function TTntDBEdit
.GetHint
: WideString
;
806 Result
:= TntControl_GetHint(Self
)
809 procedure TTntDBEdit
.SetHint(const Value
: WideString
);
811 TntControl_SetHint(Self
, Value
);
814 procedure TTntDBEdit
.ActionChange(Sender
: TObject
; CheckDefaults
: Boolean);
816 TntControl_BeforeInherited_ActionChange(Self
, Sender
, CheckDefaults
);
820 function TTntDBEdit
.GetActionLinkClass
: TControlActionLinkClass
;
822 Result
:= TntControl_GetActionLinkClass(Self
, inherited GetActionLinkClass
);
825 procedure TTntDBEdit
.WMPaint(var Message: TWMPaint
);
827 AlignStyle
: array[Boolean, TAlignment
] of DWORD
=
828 ((WS_EX_LEFT
, WS_EX_RIGHT
, WS_EX_LEFT
),
829 (WS_EX_RIGHT
, WS_EX_LEFT
, WS_EX_LEFT
));
837 AAlignment
: TAlignment
;
840 with THackDBEdit(Self
), Self
do begin
841 AAlignment
:= FAlignment
;
842 if UseRightToLeftAlignment
then ChangeBiDiModeAlignment(AAlignment
);
843 if ((AAlignment
= taLeftJustify
) or FFocused
) and (not (csPaintCopy
in ControlState
))
844 or (not Win32PlatformIsUnicode
) then
849 { Since edit controls do not handle justification unless multi-line (and
850 then only poorly) we will draw right and center justify manually unless
851 the edit has the focus. }
852 if FCanvas
= nil then
854 FCanvas
:= TControlCanvas
.Create
;
855 FCanvas
.Control
:= Self
;
858 if DC
= 0 then DC
:= BeginPaint(Handle
, PS
);
859 FCanvas
.Handle
:= DC
;
861 FCanvas
.Font
:= Font
;
865 if not (NewStyleControls
and Ctl3D
) and (BorderStyle
= bsSingle
) then
867 Brush
.Color
:= clWindowFrame
;
869 InflateRect(R
, -1, -1);
871 Brush
.Color
:= Color
;
873 Font
.Color
:= clGrayText
;
874 if (csPaintCopy
in ControlState
) and (Field
<> nil) then
876 S
:= GetWideDisplayText(Field
);
879 S
:= Tnt_WideUpperCase(S
);
881 S
:= Tnt_WideLowerCase(S
);
884 S
:= Text { EditText? };
885 if PasswordChar
<> #0 then
886 for I
:= 1 to Length(S
) do S
[I
] := PasswordChar
;
887 _Margins
:= GetTextMargins
;
889 taLeftJustify
: ALeft
:= _Margins
.X
;
890 taRightJustify
: ALeft
:= ClientWidth
- WideCanvasTextWidth(FCanvas
, S
) - _Margins
.X
- 1;
892 ALeft
:= (ClientWidth
- WideCanvasTextWidth(FCanvas
, S
)) div 2;
894 if SysLocale
.MiddleEast
then UpdateTextFlags
;
895 WideCanvasTextRect(FCanvas
, R
, ALeft
, _Margins
.Y
, S
);
899 if Message.DC
= 0 then EndPaint(Handle
, PS
);
904 function TTntDBEdit
.GetTextMargins
: TPoint
;
909 SysMetrics
, Metrics
: TTextMetric
;
911 if NewStyleControls
then
913 if BorderStyle
= bsNone
then I
:= 0 else
914 if Ctl3D
then I
:= 1 else I
:= 2;
915 Result
.X
:= SendMessage(Handle
, EM_GETMARGINS
, 0, 0) and $0000FFFF + I
;
919 if BorderStyle
= bsNone
then I
:= 0 else
922 GetTextMetrics(DC
, SysMetrics
);
923 SaveFont
:= SelectObject(DC
, Font
.Handle
);
924 GetTextMetrics(DC
, Metrics
);
925 SelectObject(DC
, SaveFont
);
927 I
:= SysMetrics
.tmHeight
;
928 if I
> Metrics
.tmHeight
then I
:= Metrics
.tmHeight
;
938 constructor TTntDBText
.Create(AOwner
: TComponent
);
941 FDataLink
:= TDataLink(Perform(CM_GETDATALINK
, 0, 0)) as TFieldDataLink
;
942 InheritedDataChange
:= FDataLink
.OnDataChange
;
943 FDataLink
.OnDataChange
:= DataChange
;
946 destructor TTntDBText
.Destroy
;
952 procedure TTntDBText
.CMDialogChar(var Message: TCMDialogChar
);
954 TntLabel_CMDialogChar(Self
, Message, Caption
);
957 function TTntDBText
.IsCaptionStored
: Boolean;
959 Result
:= TntControl_IsCaptionStored(Self
)
962 function TTntDBText
.GetCaption
: TWideCaption
;
964 Result
:= TntControl_GetText(Self
);
967 procedure TTntDBText
.SetCaption(const Value
: TWideCaption
);
969 TntControl_SetText(Self
, Value
);
972 procedure TTntDBText
.DefineProperties(Filer
: TFiler
);
975 TntPersistent_AfterInherited_DefineProperties(Filer
, Self
);
978 function TTntDBText
.GetLabelText
: WideString
;
980 if csPaintCopy
in ControlState
then
981 Result
:= GetFieldText
986 procedure TTntDBText
.DoDrawText(var Rect
: TRect
; Flags
: Integer);
988 if not TntLabel_DoDrawText(Self
, Rect
, Flags
, GetLabelText
) then
992 function TTntDBText
.IsHintStored
: Boolean;
994 Result
:= TntControl_IsHintStored(Self
);
997 function TTntDBText
.GetHint
: WideString
;
999 Result
:= TntControl_GetHint(Self
)
1002 procedure TTntDBText
.SetHint(const Value
: WideString
);
1004 TntControl_SetHint(Self
, Value
);
1007 procedure TTntDBText
.CMHintShow(var Message: TMessage
);
1009 ProcessCMHintShowMsg(Message);
1013 procedure TTntDBText
.ActionChange(Sender
: TObject
; CheckDefaults
: Boolean);
1015 TntControl_BeforeInherited_ActionChange(Self
, Sender
, CheckDefaults
);
1019 function TTntDBText
.GetActionLinkClass
: TControlActionLinkClass
;
1021 Result
:= TntControl_GetActionLinkClass(Self
, inherited GetActionLinkClass
);
1024 function TTntDBText
.GetFieldText
: WideString
;
1026 if Field
<> nil then
1027 Result
:= GetWideDisplayText(Field
)
1029 if csDesigning
in ComponentState
then Result
:= Name
else Result
:= '';
1032 procedure TTntDBText
.DataChange(Sender
: TObject
);
1034 Caption
:= GetFieldText
;
1037 { TTntCustomDBComboBox }
1039 constructor TTntCustomDBComboBox
.Create(AOwner
: TComponent
);
1042 FItems
:= TTntComboBoxStrings
.Create
;
1043 TTntComboBoxStrings(FItems
).ComboBox
:= Self
;
1044 FDataLink
:= TDataLink(Perform(CM_GETDATALINK
, 0, 0)) as TFieldDataLink
;
1045 FDataLink
.OnDataChange
:= DataChange
;
1046 FDataLink
.OnUpdateData
:= UpdateData
;
1047 FDataLink
.OnEditingChange
:= EditingChange
;
1050 destructor TTntCustomDBComboBox
.Destroy
;
1053 FreeAndNil(FSaveItems
);
1058 procedure TTntCustomDBComboBox
.CreateWindowHandle(const Params
: TCreateParams
);
1060 CreateUnicodeHandle(Self
, Params
, 'COMBOBOX');
1063 procedure TTntCustomDBComboBox
.DefineProperties(Filer
: TFiler
);
1066 TntPersistent_AfterInherited_DefineProperties(Filer
, Self
);
1070 TAccessCustomComboBox
= class(TCustomComboBox
{TNT-ALLOW TCustomComboBox});
1072 procedure TTntCustomDBComboBox
.CreateWnd
;
1074 PreInheritedAnsiText
: AnsiString
;
1076 PreInheritedAnsiText
:= TAccessCustomComboBox(Self
).Text;
1078 TntCombo_AfterInherited_CreateWnd(Self
, Items
, FSaveItems
, FSaveItemIndex
, PreInheritedAnsiText
);
1081 procedure TTntCustomDBComboBox
.DestroyWnd
;
1083 SavedText
: WideString
;
1085 if not (csDestroyingHandle
in ControlState
) then begin { avoid recursion when parent is TToolBar and system font changes. }
1086 TntCombo_BeforeInherited_DestroyWnd(Self
, Items
, FSaveItems
, ItemIndex
, FSaveItemIndex
, SavedText
);
1088 TntControl_SetStoredText(Self
, SavedText
);
1092 procedure TTntCustomDBComboBox
.SetReadOnly
;
1094 if (Style
in [csDropDown
, csSimple
]) and HandleAllocated
then
1095 SendMessage(EditHandle
, EM_SETREADONLY
, Ord(not FDataLink
.CanModify
), 0);
1098 procedure TTntCustomDBComboBox
.EditingChange(Sender
: TObject
);
1103 procedure TTntCustomDBComboBox
.CMEnter(var Message: TCMEnter
);
1105 SaveFarEast
: Boolean;
1107 SaveFarEast
:= SysLocale
.FarEast
;
1109 SysLocale
.FarEast
:= False;
1110 inherited; // inherited tries to work around Win95 FarEast bug, but introduces others
1112 SysLocale
.FarEast
:= SaveFarEast
;
1116 procedure TTntCustomDBComboBox
.WndProc(var Message: TMessage
);
1118 if (not (csDesigning
in ComponentState
))
1119 and (Message.Msg
= CB_SHOWDROPDOWN
)
1120 and (Message.WParam
= 0)
1121 and (not FDataLink
.Editing
) then begin
1122 DataChange(Self
); {Restore text}
1123 Dispatch(Message); {Do NOT call inherited!}
1125 inherited WndProc(Message);
1128 procedure TTntCustomDBComboBox
.ComboWndProc(var Message: TMessage
; ComboWnd
: HWnd
; ComboProc
: Pointer);
1130 if not TntCombo_ComboWndProc(Self
, Message, ComboWnd
, ComboProc
, DoEditCharMsg
) then
1134 procedure TTntCustomDBComboBox
.KeyPress(var Key
: AnsiChar
);
1136 SaveAutoComplete
: Boolean;
1138 TntCombo_BeforeKeyPress(Self
, SaveAutoComplete
);
1142 TntCombo_AfterKeyPress(Self
, SaveAutoComplete
);
1146 procedure TTntCustomDBComboBox
.DoEditCharMsg(var Message: TWMChar
);
1148 TntCombo_AutoCompleteKeyPress(Self
, Items
, Message,
1149 GetAutoComplete_UniqueMatchOnly
, GetAutoComplete_PreserveDataEntryCase
);
1152 procedure TTntCustomDBComboBox
.WMChar(var Message: TWMChar
);
1154 TntCombo_AutoSearchKeyPress(Self
, Items
, Message, FFilter
, FLastTime
);
1158 function TTntCustomDBComboBox
.GetItems
: TTntStrings
;
1163 procedure TTntCustomDBComboBox
.SetItems(const Value
: TTntStrings
);
1165 FItems
.Assign(Value
);
1169 function TTntCustomDBComboBox
.GetSelStart
: Integer;
1171 Result
:= TntCombo_GetSelStart(Self
);
1174 procedure TTntCustomDBComboBox
.SetSelStart(const Value
: Integer);
1176 TntCombo_SetSelStart(Self
, Value
);
1179 function TTntCustomDBComboBox
.GetSelLength
: Integer;
1181 Result
:= TntCombo_GetSelLength(Self
);
1184 procedure TTntCustomDBComboBox
.SetSelLength(const Value
: Integer);
1186 TntCombo_SetSelLength(Self
, Value
);
1189 function TTntCustomDBComboBox
.GetSelText
: WideString
;
1191 Result
:= TntCombo_GetSelText(Self
);
1194 procedure TTntCustomDBComboBox
.SetSelText(const Value
: WideString
);
1196 TntCombo_SetSelText(Self
, Value
);
1199 function TTntCustomDBComboBox
.GetText
: WideString
;
1201 Result
:= TntControl_GetText(Self
);
1204 procedure TTntCustomDBComboBox
.SetText(const Value
: WideString
);
1206 TntControl_SetText(Self
, Value
);
1209 procedure TTntCustomDBComboBox
.CNCommand(var Message: TWMCommand
);
1211 if not TntCombo_CNCommand(Self
, Items
, Message) then
1215 function TTntCustomDBComboBox
.GetFieldValue
: Variant
;
1217 Result
:= Field
.Value
;
1220 procedure TTntCustomDBComboBox
.SetFieldValue(const Value
: Variant
);
1222 Field
.Value
:= Value
;
1225 procedure TTntCustomDBComboBox
.DataChange(Sender
: TObject
);
1227 if not (Style
= csSimple
) and DroppedDown
then Exit
;
1228 if Field
<> nil then
1229 SetComboValue(GetFieldValue
)
1231 if csDesigning
in ComponentState
then
1234 SetComboValue(Null
);
1237 procedure TTntCustomDBComboBox
.UpdateData(Sender
: TObject
);
1239 SetFieldValue(GetComboValue
);
1242 function TTntCustomDBComboBox
.GetAutoComplete_PreserveDataEntryCase
: Boolean;
1247 function TTntCustomDBComboBox
.GetAutoComplete_UniqueMatchOnly
: Boolean;
1252 function TTntCustomDBComboBox
.IsHintStored
: Boolean;
1254 Result
:= TntControl_IsHintStored(Self
);
1257 function TTntCustomDBComboBox
.GetHint
: WideString
;
1259 Result
:= TntControl_GetHint(Self
)
1262 procedure TTntCustomDBComboBox
.SetHint(const Value
: WideString
);
1264 TntControl_SetHint(Self
, Value
);
1267 procedure TTntCustomDBComboBox
.AddItem(const Item
: WideString
; AObject
: TObject
);
1269 TntComboBox_AddItem(Items
, Item
, AObject
);
1272 procedure TTntCustomDBComboBox
.CopySelection(Destination
: TCustomListControl
);
1274 TntComboBox_CopySelection(Items
, ItemIndex
, Destination
);
1277 procedure TTntCustomDBComboBox
.ActionChange(Sender
: TObject
; CheckDefaults
: Boolean);
1279 TntControl_BeforeInherited_ActionChange(Self
, Sender
, CheckDefaults
);
1283 function TTntCustomDBComboBox
.GetActionLinkClass
: TControlActionLinkClass
;
1285 Result
:= TntControl_GetActionLinkClass(Self
, inherited GetActionLinkClass
);
1288 {$IFDEF DELPHI_7} // fix for Delphi 7 only
1289 function TTntCustomDBComboBox
.GetItemsClass
: TCustomComboBoxStringsClass
;
1291 Result
:= TD7PatchedComboBoxStrings
;
1297 function TTntDBComboBox
.GetFieldValue
: Variant
;
1299 Result
:= GetWideText(Field
);
1302 procedure TTntDBComboBox
.SetFieldValue(const Value
: Variant
);
1304 SetWideText(Field
, Value
);
1307 procedure TTntDBComboBox
.SetComboValue(const Value
: Variant
);
1311 OldValue
: WideString
;
1312 NewValue
: WideString
;
1314 OldValue
:= VarToWideStr(GetComboValue
);
1315 NewValue
:= VarToWideStr(Value
);
1317 if NewValue
<> OldValue
then
1319 if Style
<> csDropDown
then
1321 Redraw
:= (Style
<> csSimple
) and HandleAllocated
;
1322 if Redraw
then Items
.BeginUpdate
;
1324 if NewValue
= '' then I
:= -1 else I
:= Items
.IndexOf(NewValue
);
1329 if I
>= 0 then Exit
;
1331 if Style
in [csDropDown
, csSimple
] then Text := NewValue
;
1335 function TTntDBComboBox
.GetComboValue
: Variant
;
1339 if Style
in [csDropDown
, csSimple
] then Result
:= Text else
1342 if I
< 0 then Result
:= '' else Result
:= Items
[I
];
1348 procedure TTntDBCheckBox
.CreateWindowHandle(const Params
: TCreateParams
);
1350 CreateUnicodeHandle(Self
, Params
, 'BUTTON');
1353 procedure TTntDBCheckBox
.DefineProperties(Filer
: TFiler
);
1356 TntPersistent_AfterInherited_DefineProperties(Filer
, Self
);
1359 function TTntDBCheckBox
.IsCaptionStored
: Boolean;
1361 Result
:= TntControl_IsCaptionStored(Self
);
1364 function TTntDBCheckBox
.GetCaption
: TWideCaption
;
1366 Result
:= TntControl_GetText(Self
)
1369 procedure TTntDBCheckBox
.SetCaption(const Value
: TWideCaption
);
1371 TntControl_SetText(Self
, Value
);
1374 function TTntDBCheckBox
.IsHintStored
: Boolean;
1376 Result
:= TntControl_IsHintStored(Self
);
1379 function TTntDBCheckBox
.GetHint
: WideString
;
1381 Result
:= TntControl_GetHint(Self
)
1384 procedure TTntDBCheckBox
.SetHint(const Value
: WideString
);
1386 TntControl_SetHint(Self
, Value
);
1389 procedure TTntDBCheckBox
.Toggle
;
1391 FDataLink
: TDataLink
;
1394 FDataLink
:= TDataLink(Perform(CM_GETDATALINK
, 0, 0)) as TFieldDataLink
;
1395 FDataLink
.UpdateRecord
;
1398 procedure TTntDBCheckBox
.ActionChange(Sender
: TObject
; CheckDefaults
: Boolean);
1400 TntControl_BeforeInherited_ActionChange(Self
, Sender
, CheckDefaults
);
1404 function TTntDBCheckBox
.GetActionLinkClass
: TControlActionLinkClass
;
1406 Result
:= TntControl_GetActionLinkClass(Self
, inherited GetActionLinkClass
);
1411 constructor TTntDBRichEdit
.Create(AOwner
: TComponent
);
1413 inherited Create(AOwner
);
1414 inherited ReadOnly
:= True;
1415 FAutoDisplay
:= True;
1416 FDataLink
:= TFieldDataLink
.Create
;
1417 FDataLink
.Control
:= Self
;
1418 FDataLink
.OnDataChange
:= DataChange
;
1419 FDataLink
.OnEditingChange
:= EditingChange
;
1420 FDataLink
.OnUpdateData
:= UpdateData
;
1423 destructor TTntDBRichEdit
.Destroy
;
1430 procedure TTntDBRichEdit
.Loaded
;
1433 if (csDesigning
in ComponentState
) then
1437 procedure TTntDBRichEdit
.Notification(AComponent
: TComponent
; Operation
: TOperation
);
1440 if (Operation
= opRemove
) and (FDataLink
<> nil) and
1441 (AComponent
= DataSource
) then DataSource
:= nil;
1444 function TTntDBRichEdit
.UseRightToLeftAlignment
: Boolean;
1446 Result
:= DBUseRightToLeftAlignment(Self
, Field
);
1449 procedure TTntDBRichEdit
.BeginEditing
;
1451 if not FDataLink
.Editing
then
1453 if FieldIsBlobLike(Field
) then
1454 FDataSave
:= Field
.AsString
{TNT-ALLOW AsString};
1461 procedure TTntDBRichEdit
.KeyDown(var Key
: Word; Shift
: TShiftState
);
1463 inherited KeyDown(Key
, Shift
);
1466 if (Key
= VK_DELETE
) or (Key
= VK_BACK
) or
1467 ((Key
= VK_INSERT
) and (ssShift
in Shift
)) or
1468 (((Key
= Ord('V')) or (Key
= Ord('X'))) and (ssCtrl
in Shift
)) then
1473 procedure TTntDBRichEdit
.KeyPress(var Key
: AnsiChar
);
1475 inherited KeyPress(Key
);
1478 if (Key
in [#32..#255]) and (Field
<> nil) and
1479 not Field
.IsValidChar(Key
) then
1485 ^H
, ^I
, ^J
, ^M
, ^V
, ^X
, #32..#255:
1492 if Key
= #13 then LoadMemo
;
1497 procedure TTntDBRichEdit
.Change
;
1501 FMemoLoaded
:= True;
1505 procedure TTntDBRichEdit
.CNNotify(var Message: TWMNotify
);
1508 if Message.NMHdr
^.code
= EN_PROTECTED
then
1509 Message.Result
:= 0 { allow the operation (otherwise the control might appear stuck) }
1512 function TTntDBRichEdit
.GetDataSource
: TDataSource
;
1514 Result
:= FDataLink
.DataSource
;
1517 procedure TTntDBRichEdit
.SetDataSource(Value
: TDataSource
);
1519 FDataLink
.DataSource
:= Value
;
1520 if Value
<> nil then Value
.FreeNotification(Self
);
1523 function TTntDBRichEdit
.GetDataField
: WideString
;
1525 Result
:= FDataLink
.FieldName
;
1528 procedure TTntDBRichEdit
.SetDataField(const Value
: WideString
);
1530 FDataLink
.FieldName
:= Value
;
1533 function TTntDBRichEdit
.GetReadOnly
: Boolean;
1535 Result
:= FDataLink
.ReadOnly
;
1538 procedure TTntDBRichEdit
.SetReadOnly(Value
: Boolean);
1540 FDataLink
.ReadOnly
:= Value
;
1543 function TTntDBRichEdit
.GetField
: TField
;
1545 Result
:= FDataLink
.Field
;
1548 procedure TTntDBRichEdit
.InternalLoadMemo
;
1550 Stream
: TStringStream
{TNT-ALLOW TStringStream};
1553 Text := GetAsWideString(Field
)
1555 Stream
:= TStringStream
{TNT-ALLOW TStringStream}.Create(Field
.AsString
{TNT-ALLOW AsString});
1557 Lines
.LoadFromStream(Stream
);
1564 procedure TTntDBRichEdit
.LoadMemo
;
1566 if not FMemoLoaded
and Assigned(Field
) and FieldIsBlobLike(Field
) then
1570 FMemoLoaded
:= True;
1572 { Rich Edit Load failure }
1573 on E
:EOutOfResources
do
1574 Lines
.Text := WideFormat('(%s)', [E
.Message]);
1576 EditingChange(Self
);
1580 procedure TTntDBRichEdit
.DataChange(Sender
: TObject
);
1582 if Field
<> nil then
1583 if FieldIsBlobLike(Field
) then
1585 if FAutoDisplay
or (FDataLink
.Editing
and FMemoLoaded
) then
1587 { Check if the data has changed since we read it the first time }
1588 if (FDataSave
<> '') and (FDataSave
= Field
.AsString
{TNT-ALLOW AsString}) then Exit
;
1589 FMemoLoaded
:= False;
1593 Text := WideFormat('(%s)', [Field
.DisplayName
]);
1594 FMemoLoaded
:= False;
1598 if FFocused
and FDataLink
.CanModify
then
1599 Text := GetWideText(Field
)
1601 Text := GetWideDisplayText(Field
);
1602 FMemoLoaded
:= True;
1606 if csDesigning
in ComponentState
then Text := Name
else Text := '';
1607 FMemoLoaded
:= False;
1609 if HandleAllocated
then
1610 RedrawWindow(Handle
, nil, 0, RDW_INVALIDATE
or RDW_ERASE
or RDW_FRAME
);
1613 procedure TTntDBRichEdit
.EditingChange(Sender
: TObject
);
1615 inherited ReadOnly
:= not (FDataLink
.Editing
and FMemoLoaded
);
1618 procedure TTntDBRichEdit
.InternalSaveMemo
;
1620 Stream
: TStringStream
{TNT-ALLOW TStringStream};
1623 SetAsWideString(Field
, Text)
1625 Stream
:= TStringStream
{TNT-ALLOW TStringStream}.Create('');
1627 Lines
.SaveToStream(Stream
);
1628 Field
.AsString
{TNT-ALLOW AsString} := Stream
.DataString
;
1635 procedure TTntDBRichEdit
.UpdateData(Sender
: TObject
);
1637 if FieldIsBlobLike(Field
) then
1640 SetAsWideString(Field
, Text);
1643 procedure TTntDBRichEdit
.SetFocused(Value
: Boolean);
1645 if FFocused
<> Value
then
1648 if not Assigned(Field
) or not FieldIsBlobLike(Field
) then
1653 procedure TTntDBRichEdit
.CMEnter(var Message: TCMEnter
);
1659 procedure TTntDBRichEdit
.CMExit(var Message: TCMExit
);
1662 FDataLink
.UpdateRecord
;
1671 procedure TTntDBRichEdit
.SetAutoDisplay(Value
: Boolean);
1673 if FAutoDisplay
<> Value
then
1675 FAutoDisplay
:= Value
;
1676 if Value
then LoadMemo
;
1680 procedure TTntDBRichEdit
.WMLButtonDblClk(var Message: TWMLButtonDblClk
);
1682 if not FMemoLoaded
then LoadMemo
else inherited;
1685 procedure TTntDBRichEdit
.WMCut(var Message: TMessage
);
1691 procedure TTntDBRichEdit
.WMPaste(var Message: TMessage
);
1697 procedure TTntDBRichEdit
.CMGetDataLink(var Message: TMessage
);
1699 Message.Result
:= Integer(FDataLink
);
1702 function TTntDBRichEdit
.ExecuteAction(Action
: TBasicAction
): Boolean;
1704 Result
:= inherited ExecuteAction(Action
) or (FDataLink
<> nil) and
1705 FDataLink
.ExecuteAction(Action
);
1708 function TTntDBRichEdit
.UpdateAction(Action
: TBasicAction
): Boolean;
1710 Result
:= inherited UpdateAction(Action
) or (FDataLink
<> nil) and
1711 FDataLink
.UpdateAction(Action
);
1716 constructor TTntDBMemo
.Create(AOwner
: TComponent
);
1718 inherited Create(AOwner
);
1719 inherited ReadOnly
:= True;
1720 ControlStyle
:= ControlStyle
+ [csReplicatable
];
1721 FAutoDisplay
:= True;
1722 FDataLink
:= TFieldDataLink
.Create
;
1723 FDataLink
.Control
:= Self
;
1724 FDataLink
.OnDataChange
:= DataChange
;
1725 FDataLink
.OnEditingChange
:= EditingChange
;
1726 FDataLink
.OnUpdateData
:= UpdateData
;
1727 FPaintControl
:= TTntPaintControl
.Create(Self
, 'EDIT');
1730 destructor TTntDBMemo
.Destroy
;
1738 procedure TTntDBMemo
.Loaded
;
1741 if (csDesigning
in ComponentState
) then DataChange(Self
);
1744 procedure TTntDBMemo
.Notification(AComponent
: TComponent
;
1745 Operation
: TOperation
);
1747 inherited Notification(AComponent
, Operation
);
1748 if (Operation
= opRemove
) and (FDataLink
<> nil) and
1749 (AComponent
= DataSource
) then DataSource
:= nil;
1752 function TTntDBMemo
.UseRightToLeftAlignment
: Boolean;
1754 Result
:= DBUseRightToLeftAlignment(Self
, Field
);
1757 procedure TTntDBMemo
.KeyDown(var Key
: Word; Shift
: TShiftState
);
1759 inherited KeyDown(Key
, Shift
);
1762 if (Key
= VK_DELETE
) or ((Key
= VK_INSERT
) and (ssShift
in Shift
)) then
1767 procedure TTntDBMemo
.KeyPress(var Key
: Char{TNT-ALLOW Char});
1769 inherited KeyPress(Key
);
1772 if (Key
in [#32..#255]) and (FDataLink
.Field
<> nil) and
1773 not FDataLink
.Field
.IsValidChar(Key
) then
1779 ^H
, ^I
, ^J
, ^M
, ^V
, ^X
, #32..#255:
1786 if Key
= #13 then LoadMemo
;
1791 procedure TTntDBMemo
.Change
;
1793 if FMemoLoaded
then FDataLink
.Modified
;
1794 FMemoLoaded
:= True;
1798 function TTntDBMemo
.GetDataSource
: TDataSource
;
1800 Result
:= FDataLink
.DataSource
;
1803 procedure TTntDBMemo
.SetDataSource(Value
: TDataSource
);
1805 if not (FDataLink
.DataSourceFixed
and (csLoading
in ComponentState
)) then
1806 FDataLink
.DataSource
:= Value
;
1807 if Value
<> nil then Value
.FreeNotification(Self
);
1810 function TTntDBMemo
.GetDataField
: WideString
;
1812 Result
:= FDataLink
.FieldName
;
1815 procedure TTntDBMemo
.SetDataField(const Value
: WideString
);
1817 FDataLink
.FieldName
:= Value
;
1820 function TTntDBMemo
.GetReadOnly
: Boolean;
1822 Result
:= FDataLink
.ReadOnly
;
1825 procedure TTntDBMemo
.SetReadOnly(Value
: Boolean);
1827 FDataLink
.ReadOnly
:= Value
;
1830 function TTntDBMemo
.GetField
: TField
;
1832 Result
:= FDataLink
.Field
;
1835 procedure TTntDBMemo
.LoadMemo
;
1837 if not FMemoLoaded
and Assigned(FDataLink
.Field
) and FieldIsBlobLike(FDataLink
.Field
) then
1840 Lines
.Text := GetAsWideString(FDataLink
.Field
);
1841 FMemoLoaded
:= True;
1844 on E
:EInvalidOperation
do
1845 Lines
.Text := WideFormat('(%s)', [E
.Message]);
1847 EditingChange(Self
);
1851 procedure TTntDBMemo
.DataChange(Sender
: TObject
);
1853 if FDataLink
.Field
<> nil then
1854 if FieldIsBlobLike(FDataLink
.Field
) then
1856 if FAutoDisplay
or (FDataLink
.Editing
and FMemoLoaded
) then
1858 FMemoLoaded
:= False;
1862 Text := WideFormat('(%s)', [FDataLink
.Field
.DisplayName
]);
1863 FMemoLoaded
:= False;
1864 EditingChange(Self
);
1868 if FFocused
and FDataLink
.CanModify
then
1869 Text := GetWideText(FDataLink
.Field
)
1871 Text := GetWideDisplayText(FDataLink
.Field
);
1872 FMemoLoaded
:= True;
1876 if csDesigning
in ComponentState
then Text := Name
else Text := '';
1877 FMemoLoaded
:= False;
1879 if HandleAllocated
then
1880 RedrawWindow(Handle
, nil, 0, RDW_INVALIDATE
or RDW_ERASE
or RDW_FRAME
);
1883 procedure TTntDBMemo
.EditingChange(Sender
: TObject
);
1885 inherited ReadOnly
:= not (FDataLink
.Editing
and FMemoLoaded
);
1888 procedure TTntDBMemo
.UpdateData(Sender
: TObject
);
1890 SetAsWideString(FDataLink
.Field
, Text);
1893 procedure TTntDBMemo
.SetFocused(Value
: Boolean);
1895 if FFocused
<> Value
then
1898 if not Assigned(FDataLink
.Field
) or not FieldIsBlobLike(FDataLink
.Field
) then
1903 procedure TTntDBMemo
.WndProc(var Message: TMessage
);
1906 if (Msg
= WM_CREATE
) or (Msg
= WM_WINDOWPOSCHANGED
) or
1907 (Msg
= CM_FONTCHANGED
) then FPaintControl
.DestroyHandle
;
1911 procedure TTntDBMemo
.CMEnter(var Message: TCMEnter
);
1917 procedure TTntDBMemo
.CMExit(var Message: TCMExit
);
1920 FDataLink
.UpdateRecord
;
1929 procedure TTntDBMemo
.SetAutoDisplay(Value
: Boolean);
1931 if FAutoDisplay
<> Value
then
1933 FAutoDisplay
:= Value
;
1934 if Value
then LoadMemo
;
1938 procedure TTntDBMemo
.WMLButtonDblClk(var Message: TWMLButtonDblClk
);
1940 if not FMemoLoaded
then LoadMemo
else inherited;
1943 procedure TTntDBMemo
.WMCut(var Message: TMessage
);
1949 procedure TTntDBMemo
.WMUndo(var Message: TMessage
);
1955 procedure TTntDBMemo
.WMPaste(var Message: TMessage
);
1961 procedure TTntDBMemo
.CMGetDataLink(var Message: TMessage
);
1963 Message.Result
:= Integer(FDataLink
);
1966 procedure TTntDBMemo
.WMPaint(var Message: TWMPaint
);
1970 if not (csPaintCopy
in ControlState
) then
1973 if FDataLink
.Field
<> nil then
1974 if FieldIsBlobLike(FDataLink
.Field
) then
1976 if FAutoDisplay
then
1977 S
:= TntAdjustLineBreaks(GetAsWideString(FDataLink
.Field
)) else
1978 S
:= WideFormat('(%s)', [FDataLink
.Field
.DisplayName
]);
1980 S
:= GetWideDisplayText(FDataLink
.Field
);
1981 if (not Win32PlatformIsUnicode
) then
1982 SendMessageA(FPaintControl
.Handle
, WM_SETTEXT
, 0, Integer(PAnsiChar(AnsiString(S
))))
1984 SendMessageW(FPaintControl
.Handle
, WM_SETTEXT
, 0, Integer(PWideChar(S
)));
1986 SendMessage(FPaintControl
.Handle
, WM_ERASEBKGND
, Integer(Message.DC
), 0);
1987 SendMessage(FPaintControl
.Handle
, WM_PAINT
, Integer(Message.DC
), 0);
1991 function TTntDBMemo
.ExecuteAction(Action
: TBasicAction
): Boolean;
1993 Result
:= inherited ExecuteAction(Action
) or (FDataLink
<> nil) and
1994 FDataLink
.ExecuteAction(Action
);
1997 function TTntDBMemo
.UpdateAction(Action
: TBasicAction
): Boolean;
1999 Result
:= inherited UpdateAction(Action
) or (FDataLink
<> nil) and
2000 FDataLink
.UpdateAction(Action
);
2003 { TTntDBRadioGroup }
2005 constructor TTntDBRadioGroup
.Create(AOwner
: TComponent
);
2007 inherited Create(AOwner
);
2008 FDataLink
:= TFieldDataLink
.Create
;
2009 FDataLink
.Control
:= Self
;
2010 FDataLink
.OnDataChange
:= DataChange
;
2011 FDataLink
.OnUpdateData
:= UpdateData
;
2012 FValues
:= TTntStringList
.Create
;
2015 destructor TTntDBRadioGroup
.Destroy
;
2023 procedure TTntDBRadioGroup
.Notification(AComponent
: TComponent
;
2024 Operation
: TOperation
);
2026 inherited Notification(AComponent
, Operation
);
2027 if (Operation
= opRemove
) and (FDataLink
<> nil) and
2028 (AComponent
= DataSource
) then DataSource
:= nil;
2031 function TTntDBRadioGroup
.UseRightToLeftAlignment
: Boolean;
2033 Result
:= inherited UseRightToLeftAlignment
;
2036 procedure TTntDBRadioGroup
.DataChange(Sender
: TObject
);
2038 if FDataLink
.Field
<> nil then
2039 Value
:= GetWideText(FDataLink
.Field
) else
2043 procedure TTntDBRadioGroup
.UpdateData(Sender
: TObject
);
2045 if FDataLink
.Field
<> nil then
2046 SetWideText(FDataLink
.Field
, Value
);
2049 function TTntDBRadioGroup
.GetDataSource
: TDataSource
;
2051 Result
:= FDataLink
.DataSource
;
2054 procedure TTntDBRadioGroup
.SetDataSource(Value
: TDataSource
);
2056 FDataLink
.DataSource
:= Value
;
2057 if Value
<> nil then Value
.FreeNotification(Self
);
2060 function TTntDBRadioGroup
.GetDataField
: WideString
;
2062 Result
:= FDataLink
.FieldName
;
2065 procedure TTntDBRadioGroup
.SetDataField(const Value
: WideString
);
2067 FDataLink
.FieldName
:= Value
;
2070 function TTntDBRadioGroup
.GetReadOnly
: Boolean;
2072 Result
:= FDataLink
.ReadOnly
;
2075 procedure TTntDBRadioGroup
.SetReadOnly(Value
: Boolean);
2077 FDataLink
.ReadOnly
:= Value
;
2080 function TTntDBRadioGroup
.GetField
: TField
;
2082 Result
:= FDataLink
.Field
;
2085 function TTntDBRadioGroup
.GetButtonValue(Index
: Integer): WideString
;
2087 if (Index
< FValues
.Count
) and (FValues
[Index
] <> '') then
2088 Result
:= FValues
[Index
]
2089 else if Index
< Items
.Count
then
2090 Result
:= Items
[Index
]
2095 procedure TTntDBRadioGroup
.SetValue(const Value
: WideString
);
2097 WasFocused
: Boolean;
2100 if FValue
<> Value
then
2102 FInSetValue
:= True;
2104 WasFocused
:= (ItemIndex
> -1) and (Buttons
[ItemIndex
].Focused
);
2106 for I
:= 0 to Items
.Count
- 1 do
2107 if Value
= GetButtonValue(I
) then
2113 // Move the focus rect along with the selected index
2115 Buttons
[ItemIndex
].SetFocus
;
2117 FInSetValue
:= False;
2124 procedure TTntDBRadioGroup
.CMExit(var Message: TCMExit
);
2127 FDataLink
.UpdateRecord
;
2129 if ItemIndex
>= 0 then
2130 (Controls
[ItemIndex
] as TTntRadioButton
).SetFocus
else
2131 (Controls
[0] as TTntRadioButton
).SetFocus
;
2137 procedure TTntDBRadioGroup
.CMGetDataLink(var Message: TMessage
);
2139 Message.Result
:= Integer(FDataLink
);
2142 procedure TTntDBRadioGroup
.Click
;
2144 if not FInSetValue
then
2147 if ItemIndex
>= 0 then Value
:= GetButtonValue(ItemIndex
);
2148 if FDataLink
.Editing
then FDataLink
.Modified
;
2152 procedure TTntDBRadioGroup
.SetItems(Value
: TTntStrings
);
2154 Items
.Assign(Value
);
2158 procedure TTntDBRadioGroup
.SetValues(Value
: TTntStrings
);
2160 FValues
.Assign(Value
);
2164 procedure TTntDBRadioGroup
.Change
;
2166 if Assigned(FOnChange
) then FOnChange(Self
);
2169 procedure TTntDBRadioGroup
.KeyPress(var Key
: Char{TNT-ALLOW Char});
2171 inherited KeyPress(Key
);
2173 #8, ' ': FDataLink
.Edit
;
2174 #27: FDataLink
.Reset
;
2178 function TTntDBRadioGroup
.CanModify
: Boolean;
2180 Result
:= FDataLink
.Edit
;
2183 function TTntDBRadioGroup
.ExecuteAction(Action
: TBasicAction
): Boolean;
2185 Result
:= inherited ExecuteAction(Action
) or (DataLink
<> nil) and
2186 DataLink
.ExecuteAction(Action
);
2189 function TTntDBRadioGroup
.UpdateAction(Action
: TBasicAction
): Boolean;
2191 Result
:= inherited UpdateAction(Action
) or (DataLink
<> nil) and
2192 DataLink
.UpdateAction(Action
);