From ceaecc704b0ba3f61e7f26a6df67c0cb243b06c5 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Fri, 7 Dec 2012 14:26:39 +0000 Subject: [PATCH] LCL-CustomDrawn: Improves TEdit features support so that now we can already read data from a database with TDBEdit git-svn-id: trunk@39473 - --- lcl/customdrawncontrols.pas | 15 +++++ .../customdrawn/customdrawnwsstdctrls.pas | 58 ++++++++----------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/lcl/customdrawncontrols.pas b/lcl/customdrawncontrols.pas index 0c1096effa..1aee17b474 100644 --- a/lcl/customdrawncontrols.pas +++ b/lcl/customdrawncontrols.pas @@ -200,6 +200,7 @@ type FLines: TStrings; FOnChange: TNotifyEvent; FReadOnly: Boolean; + function GetCaretPos: TPoint; function GetLeftTextMargin: Integer; function GetMultiLine: Boolean; function GetRightTextMargin: Integer; @@ -207,6 +208,7 @@ type procedure DoDeleteSelection; procedure DoClearSelection; procedure DoManageVisibleTextStart; + procedure SetCaretPost(AValue: TPoint); procedure SetLeftTextMargin(AValue: Integer); procedure SetLines(AValue: TStrings); procedure SetMultiLine(AValue: Boolean); @@ -245,6 +247,7 @@ type function GetSelLength: Integer; procedure SetSelStartX(ANewX: Integer); procedure SetSelLength(ANewLength: Integer); + property CaretPos: TPoint read GetCaretPos write SetCaretPost; published property Align; property Anchors; @@ -1460,6 +1463,11 @@ begin Result := FEditState.LeftTextMargin; end; +function TCDEdit.GetCaretPos: TPoint; +begin + Result := FEditState.CaretPos; +end; + function TCDEdit.GetMultiLine: Boolean; begin Result := FEditState.MultiLine; @@ -1540,6 +1548,13 @@ begin FEditState.CaretPos.Y := Max(FEditState.CaretPos.Y, 0); end; +procedure TCDEdit.SetCaretPost(AValue: TPoint); +begin + FEditState.CaretPos.X := AValue.X; + FEditState.CaretPos.Y := AValue.Y; + Invalidate; +end; + // Result.X -> returns a zero-based position of the caret function TCDEdit.MousePosToCaretPos(X, Y: Integer): TPoint; var diff --git a/lcl/interfaces/customdrawn/customdrawnwsstdctrls.pas b/lcl/interfaces/customdrawn/customdrawnwsstdctrls.pas index 56ca9b7048..a6a8647ef3 100644 --- a/lcl/interfaces/customdrawn/customdrawnwsstdctrls.pas +++ b/lcl/interfaces/customdrawn/customdrawnwsstdctrls.pas @@ -190,13 +190,13 @@ type // TWSCustomEdit -{ class procedure SetAlignment(const ACustomEdit: TCustomEdit; const AAlignment: TAlignment); override; +// class procedure SetAlignment(const ACustomEdit: TCustomEdit; const AAlignment: TAlignment); override; class function GetCaretPos(const ACustomEdit: TCustomEdit): TPoint; override; - class function GetCanUndo(const ACustomEdit: TCustomEdit): Boolean; override; +// class function GetCanUndo(const ACustomEdit: TCustomEdit): Boolean; override; class procedure SetCaretPos(const ACustomEdit: TCustomEdit; const NewPos: TPoint); override; - class procedure SetEchoMode(const ACustomEdit: TCustomEdit; NewMode: TEchoMode); override; - class procedure SetMaxLength(const ACustomEdit: TCustomEdit; NewLength: integer); override; - class procedure SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); override;} +{ class procedure SetEchoMode(const ACustomEdit: TCustomEdit; NewMode: TEchoMode); override; + class procedure SetMaxLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;} + class procedure SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); override; class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override; class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override; class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override; @@ -1358,6 +1358,7 @@ begin lCDWinControl := TCDWinControl(AWinControl.Handle); if lCDWinControl.CDControl = nil then Exit; TCDIntfEdit(lCDWinControl.CDControl).Lines.Text := AText; + TCDIntfEdit(lCDWinControl.CDControl).Invalidate(); end; class procedure TCDWSCustomEdit.ShowHide(const AWinControl: TWinControl); @@ -1381,23 +1382,19 @@ begin if not WSCheckHandleAllocated(ACustomEdit, 'SetAlignment') then Exit; TQtLineEdit(ACustomEdit.Handle).setAlignment(AlignmentMap[AAlignment]); -end; +end;*) class function TCDWSCustomEdit.GetCaretPos(const ACustomEdit: TCustomEdit ): TPoint; var - Widget: TQtWidget; - QtEdit: IQtEdit; + lCDWinControl: TCDWinControl; begin - Result := Point(0,0); - if not WSCheckHandleAllocated(ACustomEdit, 'GetCaretPos') then - Exit; - Widget := TQtWidget(ACustomEdit.Handle); - if Supports(Widget, IQtEdit, QtEdit) then - Result.X := QtEdit.getCursorPosition; + lCDWinControl := TCDWinControl(ACustomEdit.Handle); + if lCDWinControl.CDControl = nil then Exit; + Result := TCDIntfEdit(lCDWinControl.CDControl).CaretPos; end; -class function TCDWSCustomEdit.GetCanUndo(const ACustomEdit: TCustomEdit): Boolean; +(*class function TCDWSCustomEdit.GetCanUndo(const ACustomEdit: TCustomEdit): Boolean; var Widget: TQtWidget; QtEdit: IQtEdit; @@ -1408,22 +1405,19 @@ begin Widget := TQtWidget(ACustomEdit.Handle); if Supports(Widget, IQtEdit, QtEdit) then Result := QtEdit.isUndoAvailable; -end; +end;*) class procedure TCDWSCustomEdit.SetCaretPos(const ACustomEdit: TCustomEdit; const NewPos: TPoint); var - Widget: TQtWidget; - QtEdit: IQtEdit; + lCDWinControl: TCDWinControl; begin - if not WSCheckHandleAllocated(ACustomEdit, 'SetCaretPos') then - Exit; - Widget := TQtWidget(ACustomEdit.Handle); - if Supports(Widget, IQtEdit, QtEdit) then - QtEdit.setCursorPosition(NewPos.X); + lCDWinControl := TCDWinControl(ACustomEdit.Handle); + if lCDWinControl.CDControl = nil then Exit; + TCDIntfEdit(lCDWinControl.CDControl).CaretPos := NewPos; end; -{------------------------------------------------------------------------------ +(*{------------------------------------------------------------------------------ Method: TCDWSCustomEdit.SetEchoMode Params: None Returns: Nothing @@ -1465,7 +1459,7 @@ begin if NewLength <> MaxLength then QtEdit.setMaxLength(NewLength); end; -end; +end;*) {------------------------------------------------------------------------------ Method: TCDWSCustomEdit.SetReadOnly @@ -1474,16 +1468,12 @@ end; ------------------------------------------------------------------------------} class procedure TCDWSCustomEdit.SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); var - Widget: TQtWidget; - QtEdit: IQtEdit; + lCDWinControl: TCDWinControl; begin - if not WSCheckHandleAllocated(ACustomEdit, 'SetReadOnly') then - Exit; - - Widget := TQtWidget(ACustomEdit.Handle); - if Supports(Widget, IQtEdit, QtEdit) then - QtEdit.setReadOnly(NewReadOnly); -end;*) + lCDWinControl := TCDWinControl(ACustomEdit.Handle); + if lCDWinControl.CDControl = nil then Exit; + TCDIntfEdit(lCDWinControl.CDControl).ReadOnly := NewReadOnly; +end; class function TCDWSCustomEdit.GetSelStart(const ACustomEdit: TCustomEdit): integer; var