mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-06 09:46:15 +02:00
qt intf: memo and edit Get/SetText from Giuliano Colla
git-svn-id: trunk@9248 -
This commit is contained in:
parent
a0a59b26c9
commit
f53bc8cfc6
@ -1690,6 +1690,7 @@ constructor TQtTextEdit.Create(const AWinControl: TWinControl;
|
|||||||
var
|
var
|
||||||
Parent: QWidgetH;
|
Parent: QWidgetH;
|
||||||
Str: WideString;
|
Str: WideString;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
// Initializes the properties
|
// Initializes the properties
|
||||||
LCLObject := AWinControl;
|
LCLObject := AWinControl;
|
||||||
@ -1699,12 +1700,17 @@ begin
|
|||||||
WriteLn('Calling QTextEdit_create');
|
WriteLn('Calling QTextEdit_create');
|
||||||
{$endif}
|
{$endif}
|
||||||
Parent := TQtWidget(AWinControl.Parent.Handle).Widget;
|
Parent := TQtWidget(AWinControl.Parent.Handle).Widget;
|
||||||
Str := WideString((AWinControl as TCustomMemo).Lines.Text);
|
Str := (AWinControl as TCustomMemo).Text;
|
||||||
Widget := QTextEdit_create(@Str, Parent);
|
Widget := QTextEdit_create(@Str, Parent);
|
||||||
|
|
||||||
// Sets it´ s initial properties
|
// Sets it´ s initial properties
|
||||||
QWidget_setGeometry(Widget, AWinControl.Left, AWinControl.Top,
|
QWidget_setGeometry(Widget, AWinControl.Left, AWinControl.Top,
|
||||||
AWinControl.Width, AWinControl.Height);
|
AWinControl.Width, AWinControl.Height);
|
||||||
|
QTextEdit_setReadOnly(QTextEditH(Widget),(AWinControl as TCustomMemo).ReadOnly);
|
||||||
|
if (AWinControl as TCustomMemo).WordWrap then
|
||||||
|
QTextEdit_setLineWrapMode(QTextEditH(Widget),QTextEditWidgetWidth)
|
||||||
|
else
|
||||||
|
QTextEdit_setLineWrapMode(QTextEditH(Widget),QTextEditNoWrap);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
@ -70,6 +70,9 @@ type
|
|||||||
class procedure SetSize(const AWinControl: TWinControl; const AWidth, AHeight: Integer); override;
|
class procedure SetSize(const AWinControl: TWinControl; const AWidth, AHeight: Integer); override;
|
||||||
class procedure ShowHide(const AWinControl: TWinControl); override; //TODO: rename to SetVisible(control, visible)
|
class procedure ShowHide(const AWinControl: TWinControl); override; //TODO: rename to SetVisible(control, visible)
|
||||||
|
|
||||||
|
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
|
||||||
|
class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
|
||||||
|
|
||||||
{ class procedure AddControl(const AControl: TControl); override;
|
{ class procedure AddControl(const AControl: TControl); override;
|
||||||
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
|
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
|
||||||
|
|
||||||
@ -239,6 +242,42 @@ begin
|
|||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TQtWSWinControl.GetText(const AWinControl: TWinControl; var AText: String): Boolean;
|
||||||
|
var
|
||||||
|
AString: WideString;
|
||||||
|
begin
|
||||||
|
Result := True;
|
||||||
|
if AWinControl = nil then exit;
|
||||||
|
|
||||||
|
if not AWinControl.HandleAllocated then exit;
|
||||||
|
case AWinControl.fCompStyle of
|
||||||
|
//csComboBox:
|
||||||
|
csEdit,csSpinedit:
|
||||||
|
QLineEdit_text(QLineEditH(TQtWidget(AWinControl.Handle).Widget),@AString);
|
||||||
|
csMemo:
|
||||||
|
QTextEdit_toPlainText(QTextEditH(TQtWidget(AWinControl.Handle).Widget),@AString);
|
||||||
|
else
|
||||||
|
Result := false;
|
||||||
|
end;
|
||||||
|
if Result then AText := AString;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TQtWSWinControl.SetText(const AWinControl: TWinControl; const AText: string);
|
||||||
|
var
|
||||||
|
AString: WideString;
|
||||||
|
begin
|
||||||
|
if AWinControl = nil then exit;
|
||||||
|
if not AWinControl.HandleAllocated then exit;
|
||||||
|
AString := AText;
|
||||||
|
case AWinControl.fCompStyle of
|
||||||
|
csEdit,csSpinedit:
|
||||||
|
QLineEdit_setText(QLineEditH(TQtWidget(AWinControl.Handle).Widget),@AString);
|
||||||
|
//csStaticText:
|
||||||
|
csMemo:
|
||||||
|
QTextEdit_append(QTextEditH(TQtWidget(AWinControl.Handle).Widget),@AString);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
|
@ -154,10 +154,10 @@ type
|
|||||||
const AParams: TCreateParams): HWND; override;
|
const AParams: TCreateParams): HWND; override;
|
||||||
class procedure DestroyHandle(const AWinControl: TWinControl); override;
|
class procedure DestroyHandle(const AWinControl: TWinControl); override;
|
||||||
public
|
public
|
||||||
// class procedure AppendText(const ACustomMemo: TCustomMemo; const AText: string); virtual;
|
class procedure AppendText(const ACustomMemo: TCustomMemo; const AText: string); override;
|
||||||
// class function GetStrings(const ACustomMemo: TCustomMemo): TStrings; virtual;
|
class function GetStrings(const ACustomMemo: TCustomMemo): TStrings; override;
|
||||||
// class procedure SetScrollbars(const ACustomMemo: TCustomMemo; const NewScrollbars: TScrollStyle); virtual;
|
// class procedure SetScrollbars(const ACustomMemo: TCustomMemo; const NewScrollbars: TScrollStyle); virtual;
|
||||||
// class procedure SetWordWrap(const ACustomMemo: TCustomMemo; const NewWordWrap: boolean); virtual;
|
class procedure SetWordWrap(const ACustomMemo: TCustomMemo; const NewWordWrap: boolean); override;
|
||||||
public
|
public
|
||||||
{ class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
|
{ class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
|
||||||
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
|
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
|
||||||
@ -166,8 +166,8 @@ type
|
|||||||
class procedure SetEchoMode(const ACustomEdit: TCustomEdit; NewMode: TEchoMode); override;
|
class procedure SetEchoMode(const ACustomEdit: TCustomEdit; NewMode: TEchoMode); override;
|
||||||
class procedure SetMaxLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
|
class procedure SetMaxLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
|
||||||
class procedure SetPasswordChar(const ACustomEdit: TCustomEdit; NewChar: char); override;
|
class procedure SetPasswordChar(const ACustomEdit: TCustomEdit; NewChar: char); override;
|
||||||
class procedure SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); override;
|
} class procedure SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); override;
|
||||||
class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override;
|
{ class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override;
|
||||||
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
|
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
|
||||||
|
|
||||||
class procedure GetPreferredSize(const AWinControl: TWinControl;
|
class procedure GetPreferredSize(const AWinControl: TWinControl;
|
||||||
@ -278,9 +278,16 @@ type
|
|||||||
public
|
public
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$DEFINE MEMOHEADER}
|
||||||
|
{$I qtmemostrings.inc}
|
||||||
|
{$UNDEF MEMOHEADER}
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses LMessages;
|
||||||
|
|
||||||
|
{$I qtmemostrings.inc}
|
||||||
|
|
||||||
{ TQtWSCustomMemo }
|
{ TQtWSCustomMemo }
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -294,7 +301,6 @@ var
|
|||||||
QtTextEdit: TQtTextEdit;
|
QtTextEdit: TQtTextEdit;
|
||||||
begin
|
begin
|
||||||
QtTextEdit := TQtTextEdit.Create(AWinControl, AParams);
|
QtTextEdit := TQtTextEdit.Create(AWinControl, AParams);
|
||||||
|
|
||||||
Result := THandle(QtTextEdit);
|
Result := THandle(QtTextEdit);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -308,7 +314,69 @@ begin
|
|||||||
TQtTextEdit(AWinControl.Handle).Free;
|
TQtTextEdit(AWinControl.Handle).Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TQtWSCustomEdit }
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Method: TQtWSCustomMemo.AppendText
|
||||||
|
Params: None
|
||||||
|
Returns: Nothing
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
class procedure TQtWSCustomMemo.AppendText(const ACustomMemo: TCustomMemo; const AText: string);
|
||||||
|
var
|
||||||
|
Astr: WideString;
|
||||||
|
begin
|
||||||
|
if Length(AText) = 0 then
|
||||||
|
exit;
|
||||||
|
Astr := WideString(AText);
|
||||||
|
//QTextEdit_append(QTextEditH(ACustomMemo.Handle),@Astr);
|
||||||
|
QTextEdit_append(QTextEditH(TQtWidget(ACustomMemo.Handle).Widget),@Astr);
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Method: TQtWSCustomMemo.GetStrings
|
||||||
|
Params: None
|
||||||
|
Returns: Memo Contents as TStrings
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
class function TQtWSCustomMemo.GetStrings(const ACustomMemo: TCustomMemo): TStrings;
|
||||||
|
var
|
||||||
|
TextEditH: QTextEditH;
|
||||||
|
begin
|
||||||
|
TextEditH := QTextEditH((TQtWidget(ACustomMemo.Handle).Widget)); // set to proper type
|
||||||
|
Result := TQtMemoStrings.Create(TextEditH,ACustomMemo);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Method: TQtWSCustomMemo.SetWordWrap
|
||||||
|
Params: NewWordWrap boolean
|
||||||
|
Returns: Nothing
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
class procedure TQtWSCustomMemo.SetWordWrap(const ACustomMemo: TCustomMemo; const NewWordWrap: boolean);
|
||||||
|
var
|
||||||
|
TextEditH: QTextEditH;
|
||||||
|
begin
|
||||||
|
TextEditH := QTextEditH((TQtWidget(ACustomMemo.Handle).Widget)); // set to proper type
|
||||||
|
if NewWordWrap then
|
||||||
|
QTextEdit_setLineWrapMode(TextEditH,QTextEditWidgetWidth)
|
||||||
|
else
|
||||||
|
QTextEdit_setLineWrapMode(TextEditH,QTextEditNoWrap);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Method: TQtWSCustomMemo.SetReadOnly
|
||||||
|
Params: NewReadOnly boolean
|
||||||
|
Returns: Nothing
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
class procedure TQtWSCustomMemo.SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean);
|
||||||
|
var
|
||||||
|
TextEditH: QTextEditH;
|
||||||
|
begin
|
||||||
|
TextEditH := QTextEditH((TQtWidget(ACustomEdit.Handle).Widget)); // set to proper type
|
||||||
|
QTextEdit_setReadOnly(TextEditH,NewReadOnly);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{{ TQtWSCustomEdit }
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TQtWSCustomEdit.CreateHandle
|
Method: TQtWSCustomEdit.CreateHandle
|
||||||
@ -721,4 +789,4 @@ initialization
|
|||||||
RegisterWSComponent(TCustomStaticText, TQtWSCustomStaticText);
|
RegisterWSComponent(TCustomStaticText, TQtWSCustomStaticText);
|
||||||
// RegisterWSComponent(TStaticText, TQtWSStaticText);
|
// RegisterWSComponent(TStaticText, TQtWSStaticText);
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user