mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 09:59:23 +02:00
Qt: rewritten most of TQtMemoStrings, simplified TQtWSCustomMemo.Fixes issues #17933,#18063,#18067
git-svn-id: trunk@28509 -
This commit is contained in:
parent
f2608b3106
commit
28822fe6e8
@ -87,22 +87,20 @@ type
|
|||||||
|
|
||||||
TQtMemoStrings = class(TStrings)
|
TQtMemoStrings = class(TStrings)
|
||||||
private
|
private
|
||||||
FTextChangedHook : QTextEdit_hookH;
|
FTextChanged: Boolean; // Inform TQtMemoStrings about change in TextChange event
|
||||||
FTextChanged: Boolean; // StringList and QtTextEdit out of sync
|
|
||||||
FStringList: TStringList; // Holds the lines to show
|
FStringList: TStringList; // Holds the lines to show
|
||||||
FOwner: TWinControl; // Lazarus Control Owning MemoStrings
|
FOwner: TWinControl; // Lazarus Control Owning MemoStrings
|
||||||
FUpdating: Boolean; // We're changing Qt Widget
|
|
||||||
procedure InternalUpdate;
|
procedure InternalUpdate;
|
||||||
procedure ExternalUpdate(var Astr: WideString; AClear: Boolean = True);
|
procedure ExternalUpdate(var AStr: WideString;
|
||||||
procedure IsChanged; // OnChange triggered by program action
|
AClear, ABlockSignals: Boolean);
|
||||||
protected
|
protected
|
||||||
function getTextEdit: QTextEditH; // QtWidget handle
|
|
||||||
function GetTextStr: string; override;
|
function GetTextStr: string; override;
|
||||||
function GetCount: integer; override;
|
function GetCount: integer; override;
|
||||||
function Get(Index : Integer) : string; override;
|
function Get(Index : Integer) : string; override;
|
||||||
procedure Put(Index: Integer; const S: string); override;
|
procedure Put(Index: Integer; const S: string); override;
|
||||||
|
procedure SetTextStr(const Value: string); override;
|
||||||
public
|
public
|
||||||
constructor Create(TextEdit : QTextEditH; TheOwner: TWinControl);
|
constructor Create(TheOwner: TWinControl);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Assign(Source : TPersistent); override;
|
procedure Assign(Source : TPersistent); override;
|
||||||
procedure Clear; override;
|
procedure Clear; override;
|
||||||
@ -111,7 +109,7 @@ type
|
|||||||
procedure SetText(TheText: PChar); override;
|
procedure SetText(TheText: PChar); override;
|
||||||
public
|
public
|
||||||
property Owner: TWinControl read FOwner;
|
property Owner: TWinControl read FOwner;
|
||||||
procedure TextChangedHandler; cdecl;
|
property TextChanged: Boolean read FTextChanged write FTextChanged;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -128,69 +126,61 @@ implementation
|
|||||||
procedure TQtMemoStrings.InternalUpdate;
|
procedure TQtMemoStrings.InternalUpdate;
|
||||||
var
|
var
|
||||||
W: WideString;
|
W: WideString;
|
||||||
TextEdit: QTextEditH;
|
TextEdit: TQtTextEdit;
|
||||||
begin
|
begin
|
||||||
TextEdit := getTextEdit;
|
W := '';
|
||||||
if TextEdit <> nil then
|
if FOwner.HandleAllocated then
|
||||||
QTextEdit_toPlainText(TextEdit, @W); // get the memo content
|
begin
|
||||||
FStringList.Text := UTF16ToUTF8(W);
|
TextEdit := TQtTextEdit(FOwner.Handle);
|
||||||
|
W := TextEdit.getText;
|
||||||
|
end;
|
||||||
|
if W <> '' then
|
||||||
|
FStringList.Text := UTF16ToUTF8(W) + LineEnding
|
||||||
|
else
|
||||||
|
FStringList.Text := '';
|
||||||
FTextChanged := False;
|
FTextChanged := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Private Method: TQtMemoStrings.ExternalUpdate
|
Private Method: TQtMemoStrings.ExternalUpdate
|
||||||
Params: Astr: Text for Qt Widget; Clear: if we must clear first
|
Params: AStr: Text for Qt Widget; Clear: if we must clear first
|
||||||
|
ABlockSignals: block SignalTextChanged() so it does not send an
|
||||||
|
message to LCL.
|
||||||
Returns: Nothing
|
Returns: Nothing
|
||||||
|
|
||||||
Updates Qt Widget from text - If DelphiOnChange, generates OnChange Event
|
Updates Qt Widget from text - If DelphiOnChange, generates OnChange Event
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure TQtMemoStrings.ExternalUpdate(var Astr: WideString; AClear: Boolean = True);
|
procedure TQtMemoStrings.ExternalUpdate(var AStr: WideString;
|
||||||
|
AClear, ABlockSignals: Boolean);
|
||||||
var
|
var
|
||||||
W: WideString;
|
W: WideString;
|
||||||
TextEdit: QTextEditH;
|
TextEdit: TQtTextEdit;
|
||||||
|
B: Boolean;
|
||||||
begin
|
begin
|
||||||
FUpdating := True;
|
if not FOwner.HandleAllocated then
|
||||||
|
exit;
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
writeln('TQtMemoStrings.ExternalUpdate');
|
||||||
|
{$endif}
|
||||||
|
TextEdit := TQtTextEdit(FOwner.Handle);
|
||||||
|
if ABlockSignals then
|
||||||
|
TextEdit.BeginUpdate;
|
||||||
W := GetUtf8String(AStr);
|
W := GetUtf8String(AStr);
|
||||||
TextEdit := getTextEdit;
|
if AClear then
|
||||||
if TextEdit <> nil then
|
|
||||||
begin
|
begin
|
||||||
if AClear then
|
// never trigger changed signal when clearing text here.
|
||||||
begin
|
// we must clear text since QTextEdit can contain html text.
|
||||||
QTextEdit_clear(TextEdit);
|
TextEdit.BeginUpdate;
|
||||||
QTextEdit_setPlainText(TextEdit,@W);
|
TextEdit.ClearText;
|
||||||
end else
|
TextEdit.EndUpdate;
|
||||||
QTextEdit_append(TextEdit,@W);
|
TextEdit.setText(W);
|
||||||
|
end else
|
||||||
|
TextEdit.Append(W);
|
||||||
|
|
||||||
if QTextEdit_alignment(TextEdit) <> AlignmentMap[TCustomMemo(FOwner).Alignment] then
|
if TextEdit.getAlignment <> AlignmentMap[TCustomMemo(FOwner).Alignment] then
|
||||||
QTextEdit_setAlignment(TextEdit, AlignmentMap[TCustomMemo(FOwner).Alignment]);
|
TextEdit.setAlignment(AlignmentMap[TCustomMemo(FOwner).Alignment]);
|
||||||
end;
|
if ABlockSignals then
|
||||||
|
TextEdit.EndUpdate;
|
||||||
FUpdating := False;
|
|
||||||
IsChanged;
|
|
||||||
FUpdating := False;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
Private Method: TQtMemoStrings.IsChanged
|
|
||||||
Params: None
|
|
||||||
Returns: Nothing
|
|
||||||
|
|
||||||
Triggers the OnChange Event, with modified set to false
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
procedure TQtMemoStrings.IsChanged;
|
|
||||||
begin
|
|
||||||
if Assigned(FOwner) and Assigned((FOwner as TCustomMemo).OnChange) then
|
|
||||||
begin
|
|
||||||
(FOwner as TCustomMemo).Modified := False;
|
|
||||||
(FOwner as TCustomMemo).OnChange(FOwner);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TQtMemoStrings.getTextEdit: QTextEditH;
|
|
||||||
begin
|
|
||||||
Result := nil;
|
|
||||||
if FOwner.HandleAllocated then
|
|
||||||
Result := QTextEditH(TQtTextEdit(FOwner.Handle).Widget);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -201,9 +191,22 @@ end;
|
|||||||
Return the whole StringList content as a single string
|
Return the whole StringList content as a single string
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TQtMemoStrings.GetTextStr: string;
|
function TQtMemoStrings.GetTextStr: string;
|
||||||
|
var
|
||||||
|
TextLen: Integer;
|
||||||
begin
|
begin
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
WriteLn('TQtMemoStrings.GetTextStr');
|
||||||
|
{$endif}
|
||||||
if FTextChanged then InternalUpdate;
|
if FTextChanged then InternalUpdate;
|
||||||
Result := FStringList.Text;
|
Result := FStringList.Text;
|
||||||
|
|
||||||
|
// remove trailing line break
|
||||||
|
TextLen := Length(Result);
|
||||||
|
if (TextLen > 0) and (Result[TextLen] = #10) then
|
||||||
|
Dec(TextLen);
|
||||||
|
if (TextLen > 0) and (Result[TextLen] = #13) then
|
||||||
|
Dec(TextLen);
|
||||||
|
SetLength(Result, TextLen);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -215,6 +218,9 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TQtMemoStrings.GetCount: integer;
|
function TQtMemoStrings.GetCount: integer;
|
||||||
begin
|
begin
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
WriteLn('TQtMemoStrings.GetCount');
|
||||||
|
{$endif}
|
||||||
if FTextChanged then InternalUpdate;
|
if FTextChanged then InternalUpdate;
|
||||||
Result := FStringList.Count;
|
Result := FStringList.Count;
|
||||||
end;
|
end;
|
||||||
@ -228,20 +234,42 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TQtMemoStrings.Get(Index: Integer): string;
|
function TQtMemoStrings.Get(Index: Integer): string;
|
||||||
begin
|
begin
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
WriteLn('TQtMemoStrings.Get Index=',Index);
|
||||||
|
{$endif}
|
||||||
if FTextChanged then InternalUpdate;
|
if FTextChanged then InternalUpdate;
|
||||||
if Index < FStringList.Count then
|
if Index < FStringList.Count then
|
||||||
Result := FStringList.Strings[Index]
|
Result := FStringList.Strings[Index]
|
||||||
else Result := '';
|
else
|
||||||
|
Result := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TQtMemoStrings.Put(Index: Integer; const S: string);
|
procedure TQtMemoStrings.Put(Index: Integer; const S: string);
|
||||||
var
|
var
|
||||||
W: WideString;
|
W: WideString;
|
||||||
begin
|
begin
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
WriteLn('TQtMemoStrings.Put Index=',Index,' S=',S);
|
||||||
|
{$endif}
|
||||||
if FTextChanged then InternalUpdate;
|
if FTextChanged then InternalUpdate;
|
||||||
FStringList[Index] := S;
|
FStringList[Index] := S;
|
||||||
W := GetUTF8String(S);
|
W := GetUTF8String(S);
|
||||||
|
TQtTextEdit(FOwner.Handle).BeginUpdate;
|
||||||
TQtTextEdit(FOwner.Handle).setLineText(Index, W);
|
TQtTextEdit(FOwner.Handle).setLineText(Index, W);
|
||||||
|
TQtTextEdit(FOwner.Handle).EndUpdate;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TQtMemoStrings.SetTextStr(const Value: string);
|
||||||
|
var
|
||||||
|
W: WideString;
|
||||||
|
begin
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
WriteLn('TQtMemoStrings.SetTextStr Value=',Value);
|
||||||
|
{$endif}
|
||||||
|
inherited SetTextStr(Value);
|
||||||
|
FStringList.Text := Value;
|
||||||
|
W := FStringList.Text;
|
||||||
|
ExternalUpdate(W, True, False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -251,22 +279,15 @@ end;
|
|||||||
|
|
||||||
Constructor for the class.
|
Constructor for the class.
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
constructor TQtMemoStrings.Create(TextEdit: QTextEditH; TheOwner: TWinControl);
|
constructor TQtMemoStrings.Create(TheOwner: TWinControl);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
{$ifdef VerboseQt}
|
{$ifdef VerboseQt}
|
||||||
if (TextEdit = nil) then WriteLn('TQtMemoStrings.Create Unspecified TextEdit widget');
|
if (TheOwner = nil) then
|
||||||
if (TheOwner = nil) then WriteLn('TQtMemoStrings.Create Unspecified owner');
|
WriteLn('TQtMemoStrings.Create Unspecified owner');
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
FStringList := TStringList.Create;
|
FStringList := TStringList.Create;
|
||||||
QTextEdit_clear(TextEdit);
|
FOwner := TheOwner;
|
||||||
FOwner:=TheOwner;
|
|
||||||
// Callback Event
|
|
||||||
{Method := MemoChanged; }
|
|
||||||
FTextChangedHook := QTextEdit_hook_create(TextEdit);
|
|
||||||
QTextEdit_hook_hook_textChanged(FTextChangedHook, @TextChangedHandler);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -280,32 +301,9 @@ destructor TQtMemoStrings.Destroy;
|
|||||||
begin
|
begin
|
||||||
Clear;
|
Clear;
|
||||||
FStringList.Free;
|
FStringList.Free;
|
||||||
// don't destroy the widgets
|
|
||||||
if FTextChangedHook <> nil then
|
|
||||||
QTextEdit_hook_destroy(FTextChangedHook);
|
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
Method: TQtMemoStrings.TextChangedHandler
|
|
||||||
Params: None
|
|
||||||
Returns: Nothing
|
|
||||||
|
|
||||||
Signal handler for the TextChanged Signal.
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
procedure TQtMemoStrings.TextChangedHandler; cdecl;
|
|
||||||
var
|
|
||||||
Mess: TLMessage;
|
|
||||||
begin
|
|
||||||
if not FUpdating then
|
|
||||||
begin
|
|
||||||
FTextChanged := True;
|
|
||||||
FillChar(Mess, SizeOf(Mess), #0);
|
|
||||||
Mess.Msg := CM_TEXTCHANGED;
|
|
||||||
FOwner.Dispatch(TLMessage(Mess));
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TQtMemoStrings.Assign
|
Method: TQtMemoStrings.Assign
|
||||||
Params: None
|
Params: None
|
||||||
@ -317,15 +315,20 @@ procedure TQtMemoStrings.Assign(Source: TPersistent);
|
|||||||
var
|
var
|
||||||
W: WideString;
|
W: WideString;
|
||||||
begin
|
begin
|
||||||
if (Source=Self) or (Source=nil)
|
if (Source=Self) or (Source=nil) then
|
||||||
then
|
|
||||||
exit;
|
exit;
|
||||||
|
if not FOwner.HandleAllocated then
|
||||||
|
exit;
|
||||||
|
|
||||||
if Source is TStrings then
|
if Source is TStrings then
|
||||||
begin
|
begin
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
writeln('TQtMemoStrings.Assign - handle ? ', FOwner.HandleAllocated);
|
||||||
|
{$endif}
|
||||||
FStringList.Clear;
|
FStringList.Clear;
|
||||||
FStringList.Text := TStrings(Source).Text;
|
FStringList.Text := TStrings(Source).Text;
|
||||||
W := FStringList.Text;
|
W := FStringList.Text;
|
||||||
ExternalUpdate(W,True);
|
ExternalUpdate(W, True, False);
|
||||||
FTextChanged := False;
|
FTextChanged := False;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -340,20 +343,20 @@ end;
|
|||||||
Clears all.
|
Clears all.
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure TQtMemoStrings.Clear;
|
procedure TQtMemoStrings.Clear;
|
||||||
var
|
|
||||||
TextEdit: QTextEditH;
|
|
||||||
begin
|
begin
|
||||||
FUpdating := True;
|
|
||||||
FStringList.Clear;
|
FStringList.Clear;
|
||||||
TextEdit := getTextEdit;
|
if not (csDestroying in FOwner.ComponentState) and
|
||||||
if not (csDestroying in FOwner.ComponentState)
|
not (csFreeNotification in FOwner.ComponentState) and
|
||||||
and not (csFreeNotification in FOwner.ComponentState)
|
FOwner.HandleAllocated then
|
||||||
and (TextEdit <> nil) then
|
begin
|
||||||
QTextEdit_clear(TextEdit);
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
writeln('TQtMemoStrings.Clear');
|
||||||
FTextChanged := False;
|
{$endif}
|
||||||
FUpdating := False;
|
TQtTextEdit(FOwner.Handle).BeginUpdate;
|
||||||
IsChanged;
|
TQtTextEdit(FOwner.Handle).ClearText;
|
||||||
|
TQtTextEdit(FOwner.Handle).EndUpdate;
|
||||||
|
FTextChanged := False;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -368,8 +371,13 @@ begin
|
|||||||
if FTextChanged then InternalUpdate;
|
if FTextChanged then InternalUpdate;
|
||||||
if (Index >= 0) and (Index < FStringList.Count) then
|
if (Index >= 0) and (Index < FStringList.Count) then
|
||||||
begin
|
begin
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
writeln('TQtMemoStrings.Delete');
|
||||||
|
{$endif}
|
||||||
FStringList.Delete(Index);
|
FStringList.Delete(Index);
|
||||||
TQtTextEdit(FOwner.Handle).removeLine(Index);
|
TQtTextEdit(FOwner.Handle).BeginUpdate;
|
||||||
|
TQtTextEdit(FOwner.Handle).RemoveLine(Index);
|
||||||
|
TQtTextEdit(FOwner.Handle).EndUpdate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -386,6 +394,11 @@ var
|
|||||||
begin
|
begin
|
||||||
if FTextChanged then InternalUpdate;
|
if FTextChanged then InternalUpdate;
|
||||||
if Index < 0 then Index := 0;
|
if Index < 0 then Index := 0;
|
||||||
|
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
writeln('TQtMemoStrings.Insert Index=',Index);
|
||||||
|
{$endif}
|
||||||
|
|
||||||
if Index <= FStringList.Count then
|
if Index <= FStringList.Count then
|
||||||
begin
|
begin
|
||||||
FStringList.Insert(Index, S);
|
FStringList.Insert(Index, S);
|
||||||
@ -395,18 +408,22 @@ begin
|
|||||||
begin
|
begin
|
||||||
// workaround for qt richtext parser bug
|
// workaround for qt richtext parser bug
|
||||||
W := GetUTF8String(S);
|
W := GetUTF8String(S);
|
||||||
|
TQtTextEdit(FOwner.Handle).BeginUpdate;
|
||||||
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
|
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
|
||||||
|
TQtTextEdit(FOwner.Handle).EndUpdate;
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
// append is much faster in case when we add strings
|
// append is much faster in case when we add strings
|
||||||
W := S;
|
W := S;
|
||||||
ExternalUpdate(W, False);
|
ExternalUpdate(W, False, True);
|
||||||
FTextChanged := False;
|
FTextChanged := False;
|
||||||
end;
|
end;
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
W := GetUTF8String(S);
|
W := GetUTF8String(S);
|
||||||
|
TQtTextEdit(FOwner.Handle).BeginUpdate;
|
||||||
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
|
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
|
||||||
|
TQtTextEdit(FOwner.Handle).EndUpdate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -423,10 +440,13 @@ Var
|
|||||||
S: String;
|
S: String;
|
||||||
W: WideString;
|
W: WideString;
|
||||||
begin
|
begin
|
||||||
|
{$ifdef VerboseQtMemoStrings}
|
||||||
|
writeln('TQtMemoStrings.SetText');
|
||||||
|
{$endif}
|
||||||
S := StrPas(TheText);
|
S := StrPas(TheText);
|
||||||
FStringList.Text := S;
|
FStringList.Text := S;
|
||||||
W := S;
|
W := S;
|
||||||
ExternalUpdate(W,True);
|
ExternalUpdate(W, True, False);
|
||||||
FTextChanged := False;
|
FTextChanged := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -700,12 +700,14 @@ type
|
|||||||
private
|
private
|
||||||
FViewportEventHook: QObject_hookH;
|
FViewportEventHook: QObject_hookH;
|
||||||
FUndoAvailableHook: QTextEdit_hookH;
|
FUndoAvailableHook: QTextEdit_hookH;
|
||||||
|
FTextChangedHook: QTextEdit_hookH;
|
||||||
FUndoAvailable: Boolean;
|
FUndoAvailable: Boolean;
|
||||||
protected
|
protected
|
||||||
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
|
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
|
||||||
public
|
public
|
||||||
FList: TStrings;
|
FList: TStrings;
|
||||||
procedure append(AStr: WideString);
|
procedure Append(const AStr: WideString);
|
||||||
|
procedure ClearText;
|
||||||
function getAlignment: QtAlignment;
|
function getAlignment: QtAlignment;
|
||||||
function getBlockCount: Integer;
|
function getBlockCount: Integer;
|
||||||
function getCursorPosition: Integer;
|
function getCursorPosition: Integer;
|
||||||
@ -741,6 +743,7 @@ type
|
|||||||
function getContextMenuPolicy: QtContextMenuPolicy; override;
|
function getContextMenuPolicy: QtContextMenuPolicy; override;
|
||||||
procedure setContextMenuPolicy(const AValue: QtContextMenuPolicy); override;
|
procedure setContextMenuPolicy(const AValue: QtContextMenuPolicy); override;
|
||||||
procedure SignalUndoAvailable(b: Boolean); cdecl;
|
procedure SignalUndoAvailable(b: Boolean); cdecl;
|
||||||
|
procedure SignalTextChanged(); cdecl;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TQtTabBar }
|
{ TQtTabBar }
|
||||||
@ -1633,6 +1636,7 @@ uses
|
|||||||
LCLMessageGlue,
|
LCLMessageGlue,
|
||||||
qtCaret,
|
qtCaret,
|
||||||
qtproc,
|
qtproc,
|
||||||
|
qtprivate,
|
||||||
WSControls;
|
WSControls;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -6386,11 +6390,16 @@ begin
|
|||||||
QWidget_setAcceptDrops(Result, False);
|
QWidget_setAcceptDrops(Result, False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TQtTextEdit.append(AStr: WideString);
|
procedure TQtTextEdit.Append(const AStr: WideString);
|
||||||
begin
|
begin
|
||||||
QTextEdit_append(QTextEditH(Widget), @AStr);
|
QTextEdit_append(QTextEditH(Widget), @AStr);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TQtTextEdit.ClearText;
|
||||||
|
begin
|
||||||
|
QTextEdit_clear(QTextEditH(Widget));
|
||||||
|
end;
|
||||||
|
|
||||||
function TQtTextEdit.getAlignment: QtAlignment;
|
function TQtTextEdit.getAlignment: QtAlignment;
|
||||||
begin
|
begin
|
||||||
Result := QTextEdit_alignment(QTextEditH(Widget));
|
Result := QTextEdit_alignment(QTextEditH(Widget));
|
||||||
@ -6700,6 +6709,9 @@ begin
|
|||||||
FUndoAvailableHook := QTextEdit_hook_create(Widget);
|
FUndoAvailableHook := QTextEdit_hook_create(Widget);
|
||||||
QTextEdit_hook_hook_undoAvailable(FUndoAvailableHook, @SignalUndoAvailable);
|
QTextEdit_hook_hook_undoAvailable(FUndoAvailableHook, @SignalUndoAvailable);
|
||||||
|
|
||||||
|
FTextChangedHook := QTextEdit_hook_create(Widget);
|
||||||
|
QTextEdit_hook_hook_textChanged(FTextChangedHook, @SignalTextChanged);
|
||||||
|
|
||||||
FViewportEventHook := QObject_hook_create(viewportWidget);
|
FViewportEventHook := QObject_hook_create(viewportWidget);
|
||||||
QObject_hook_hook_events(FViewportEventHook, @viewportEventFilter);
|
QObject_hook_hook_events(FViewportEventHook, @viewportEventFilter);
|
||||||
|
|
||||||
@ -6707,6 +6719,12 @@ end;
|
|||||||
|
|
||||||
procedure TQtTextEdit.DetachEvents;
|
procedure TQtTextEdit.DetachEvents;
|
||||||
begin
|
begin
|
||||||
|
if FUndoAvailableHook <> nil then
|
||||||
|
QTextEdit_hook_destroy(FUndoAvailableHook);
|
||||||
|
|
||||||
|
if FTextChangedHook <> nil then
|
||||||
|
QTextEdit_hook_destroy(FTextChangedHook);
|
||||||
|
|
||||||
QObject_hook_destroy(FViewportEventHook);
|
QObject_hook_destroy(FViewportEventHook);
|
||||||
inherited DetachEvents;
|
inherited DetachEvents;
|
||||||
end;
|
end;
|
||||||
@ -6739,6 +6757,22 @@ begin
|
|||||||
FUndoAvailable := b;
|
FUndoAvailable := b;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TQtTextEdit.SignalTextChanged(); cdecl;
|
||||||
|
var
|
||||||
|
Mess: TLMessage;
|
||||||
|
begin
|
||||||
|
if (LCLObject = nil) or not GetVisible then
|
||||||
|
exit;
|
||||||
|
if Assigned(FList) then
|
||||||
|
TQtMemoStrings(FList).TextChanged := True;
|
||||||
|
if not InUpdate then
|
||||||
|
begin
|
||||||
|
FillChar(Mess, SizeOf(Mess), #0);
|
||||||
|
Mess.Msg := CM_TEXTCHANGED;
|
||||||
|
DeliverMessage(Mess);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TQtTabBar }
|
{ TQtTabBar }
|
||||||
|
|
||||||
procedure TQtTabBar.AttachEvents;
|
procedure TQtTabBar.AttachEvents;
|
||||||
|
@ -635,15 +635,17 @@ var
|
|||||||
QtTextEdit: TQtTextEdit;
|
QtTextEdit: TQtTextEdit;
|
||||||
begin
|
begin
|
||||||
QtTextEdit := TQtTextEdit.Create(AWinControl, AParams);
|
QtTextEdit := TQtTextEdit.Create(AWinControl, AParams);
|
||||||
QtTextEdit.AttachEvents;
|
QtTextEdit.ClearText;
|
||||||
QtTextEdit.setBorder(TCustomMemo(AWinControl).BorderStyle = bsSingle);
|
QtTextEdit.setBorder(TCustomMemo(AWinControl).BorderStyle = bsSingle);
|
||||||
QtTextEdit.setReadOnly(TCustomMemo(AWinControl).ReadOnly);
|
QtTextEdit.setReadOnly(TCustomMemo(AWinControl).ReadOnly);
|
||||||
QtTextEdit.setLineWrapMode(WordWrapMap[TCustomMemo(AWinControl).WordWrap]);
|
QtTextEdit.setLineWrapMode(WordWrapMap[TCustomMemo(AWinControl).WordWrap]);
|
||||||
// create our FList helper
|
// create our FList helper
|
||||||
QtTextEdit.FList := TQtMemoStrings.Create(QTextEditH(QtTextEdit.Widget), TCustomMemo(AWinControl));
|
QtTextEdit.FList := TQtMemoStrings.Create(TCustomMemo(AWinControl));
|
||||||
QtTextEdit.setScrollStyle(TCustomMemo(AWinControl).ScrollBars);
|
QtTextEdit.setScrollStyle(TCustomMemo(AWinControl).ScrollBars);
|
||||||
QtTextEdit.setTabChangesFocus(not TCustomMemo(AWinControl).WantTabs);
|
QtTextEdit.setTabChangesFocus(not TCustomMemo(AWinControl).WantTabs);
|
||||||
|
|
||||||
|
QtTextEdit.AttachEvents;
|
||||||
|
|
||||||
Result := TLCLIntfHandle(QtTextEdit);
|
Result := TLCLIntfHandle(QtTextEdit);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -659,7 +661,9 @@ begin
|
|||||||
if not WSCheckHandleAllocated(ACustomMemo, 'AppendText') or (Length(AText) = 0) then
|
if not WSCheckHandleAllocated(ACustomMemo, 'AppendText') or (Length(AText) = 0) then
|
||||||
Exit;
|
Exit;
|
||||||
AStr := GetUtf8String(AText);
|
AStr := GetUtf8String(AText);
|
||||||
TQtTextEdit(ACustomMemo.Handle).append(AStr);
|
TQtTextEdit(ACustomMemo.Handle).BeginUpdate;
|
||||||
|
TQtTextEdit(ACustomMemo.Handle).Append(AStr);
|
||||||
|
TQtTextEdit(ACustomMemo.Handle).EndUpdate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -668,16 +672,11 @@ end;
|
|||||||
Returns: Memo Contents as TStrings
|
Returns: Memo Contents as TStrings
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
class function TQtWSCustomMemo.GetStrings(const ACustomMemo: TCustomMemo): TStrings;
|
class function TQtWSCustomMemo.GetStrings(const ACustomMemo: TCustomMemo): TStrings;
|
||||||
var
|
|
||||||
TextEditH: QTextEditH;
|
|
||||||
begin
|
begin
|
||||||
if not WSCheckHandleAllocated(ACustomMemo, 'GetStrings') then
|
if not WSCheckHandleAllocated(ACustomMemo, 'GetStrings') then
|
||||||
Exit;
|
Exit;
|
||||||
if not Assigned(TQtTextEdit(ACustomMemo.Handle).FList) then
|
if not Assigned(TQtTextEdit(ACustomMemo.Handle).FList) then
|
||||||
begin
|
TQtTextEdit(ACustomMemo.Handle).FList := TQtMemoStrings.Create(ACustomMemo);
|
||||||
TextEditH := QTextEditH((TQtTextEdit(ACustomMemo.Handle).Widget)); // set to proper type
|
|
||||||
TQtTextEdit(ACustomMemo.Handle).FList := TQtMemoStrings.Create(TextEditH, ACustomMemo);
|
|
||||||
end;
|
|
||||||
|
|
||||||
Result := TQtTextEdit(ACustomMemo.Handle).FList;
|
Result := TQtTextEdit(ACustomMemo.Handle).FList;
|
||||||
end;
|
end;
|
||||||
@ -695,7 +694,6 @@ class procedure TQtWSCustomMemo.SetScrollbars(const ACustomMemo: TCustomMemo;
|
|||||||
begin
|
begin
|
||||||
if not WSCheckHandleAllocated(ACustomMemo, 'SetScrollBars') then
|
if not WSCheckHandleAllocated(ACustomMemo, 'SetScrollBars') then
|
||||||
Exit;
|
Exit;
|
||||||
|
|
||||||
TQtTextEdit(ACustomMemo.Handle).setScrollStyle(NewScrollBars);
|
TQtTextEdit(ACustomMemo.Handle).setScrollStyle(NewScrollBars);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user