34
Classes, SysUtils, Types,
36
LMessages, Forms, Controls, LCLType, LCLProc, ExtCtrls, StdCtrls, Menus,
36
Forms, Controls, LCLType, LCLProc, ExtCtrls, StdCtrls,
79
78
procedure Assign(Source: TPersistent); override;
80
79
procedure Clear; override;
81
80
procedure Delete(Index: Integer); override;
81
procedure Move(CurIndex, NewIndex: Integer); override;
82
82
procedure Sort; override;
83
83
procedure Exchange(AIndex1, AIndex2: Integer); override;
92
92
FTextChanged: Boolean; // Inform TQtMemoStrings about change in TextChange event
93
93
FStringList: TStringList; // Holds the lines to show
94
FHasTrailingLineBreak: Boolean; // Indicates whether lines have trailing line break
94
95
FOwner: TWinControl; // Lazarus Control Owning MemoStrings
95
96
procedure InternalUpdate;
96
97
procedure ExternalUpdate(var AStr: WideString;
192
193
Result := FStringList.Text;
194
// remove trailing line break
195
TextLen := Length(Result);
196
if (TextLen > 0) and (Result[TextLen] = #10) then
198
if (TextLen > 0) and (Result[TextLen] = #13) then
200
SetLength(Result, TextLen);
195
// Since TStringList.Text automatically adds line break to the last line,
196
// we should remove it if original text does not contain it
197
if not FHasTrailingLineBreak then
199
TextLen := Length(Result);
200
if (TextLen > 0) and (Result[TextLen] = #10) then
202
if (TextLen > 0) and (Result[TextLen] = #13) then
204
SetLength(Result, TextLen);
203
208
procedure TQtMemoStrings.SetInternalText(const Value: string);
205
FStringList.Text := Value + LineEnding;
212
TextLen := Length(Value);
213
FHasTrailingLineBreak := (TextLen > 0) and (Value[TextLen] in [#13, #10]);
214
FStringList.Text := Value;
208
217
{------------------------------------------------------------------------------
402
412
procedure TQtMemoStrings.Insert(Index: integer; const S: string);
415
QtCursor: QTextCursorH;
418
function WorkaroundNeeded: Boolean;
424
HaveLt := System.Pos('<', S) > 0;
425
HaveGt := System.Pos('>', S) > 0;
426
Result := HaveLt or HaveGt;
406
430
if FTextChanged then InternalUpdate;
407
431
if Index < 0 then Index := 0;
413
437
if Index <= FStringList.Count then
415
439
FStringList.Insert(Index, S);
416
if TQtTextEdit(FOwner.Handle).getBlockCount - Index <= 1 then
440
if (TQtTextEdit(FOwner.Handle).getBlockCount - Index <= 1) then
418
if (UTF8Pos('<', S) > 0) or (UTF8Pos('>',S) > 0) then
442
// workaround for qt richtext parser bug. issues #17170 and #22715
443
if WorkaroundNeeded then
420
// workaround for qt richtext parser bug
421
445
W := GetUTF8String(S);
422
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
446
if (Index >= FStringList.Count - 1) then
447
TQtTextEdit(FOwner.Handle).appendLine(W)
449
TQtTextEdit(FOwner.Handle).insertLine(Index, W);
425
452
// append is much faster in case when we add strings
565
592
inherited Put(Index, S);
566
593
if Assigned(FWinControl) and (FWinControl.HandleAllocated) then
567
596
FOwner.setItemText(Index, S);
597
if FOwner is TQtCheckListBox then
599
FOwner.ItemFlags[Index] := FOwner.ItemFlags[Index] or QtItemIsUserCheckable;
600
if TQtCheckListBox(FOwner).AllowGrayed then
601
FOwner.ItemFlags[Index] := FOwner.ItemFlags[Index] or QtItemIsTristate
603
FOwner.ItemFlags[Index] := FOwner.ItemFlags[Index] and not QtItemIsTristate;
570
609
procedure TQtListStrings.InsertItem(Index: Integer; const S: string);
572
611
inherited InsertItem(Index, S);
573
612
if Assigned(FWinControl) and (FWinControl.HandleAllocated) then
574
615
FOwner.insertItem(Index, S);
616
if FOwner is TQtCheckListBox then
618
FOwner.ItemFlags[Index] := FOwner.ItemFlags[Index] or QtItemIsUserCheckable;
619
if TQtCheckListBox(FOwner).AllowGrayed then
620
FOwner.ItemFlags[Index] := FOwner.ItemFlags[Index] or QtItemIsTristate
622
FOwner.ItemFlags[Index] := FOwner.ItemFlags[Index] and not QtItemIsTristate;
577
628
procedure TQtListStrings.InsertItem(Index: Integer; const S: string; O: TObject);
579
630
inherited InsertItem(Index, S, O);
580
631
if Assigned(FWinControl) and (FWinControl.HandleAllocated) then
581
634
FOwner.insertItem(Index, S);
636
if FOwner is TQtCheckListBox then
638
FOwner.ItemFlags[Index] := FOwner.ItemFlags[Index] or QtItemIsUserCheckable;
639
if TQtCheckListBox(FOwner).AllowGrayed then
640
FOwner.ItemFlags[Index] := FOwner.ItemFlags[Index] or QtItemIsTristate
642
FOwner.ItemFlags[Index] := FOwner.ItemFlags[Index] and not QtItemIsTristate;
584
648
constructor TQtListStrings.Create(AWinControl: TWinControl;
598
662
procedure TQtListStrings.Assign(Source: TPersistent);
600
666
if Assigned(FWinControl) and (FWinControl.HandleAllocated) then
602
668
FOwner.BeginUpdate;
603
669
inherited Assign(Source);
670
if FOwner is TQtCheckListBox then
672
for i := 0 to TQtCheckListBox(FOwner).ItemCount - 1 do
674
FOwner.ItemFlags[i] := FOwner.ItemFlags[i] or QtItemIsUserCheckable;
675
if TQtCheckListBox(FOwner).AllowGrayed then
676
FOwner.ItemFlags[i] := FOwner.ItemFlags[i] or QtItemIsTristate
678
FOwner.ItemFlags[i] := FOwner.ItemFlags[i] and not QtItemIsTristate;
604
681
FOwner.EndUpdate;
622
699
inherited Delete(Index);
623
700
if Assigned(FWinControl) and (FWinControl.HandleAllocated) then
624
703
FOwner.removeItem(Index);
708
procedure TQtListStrings.Move(CurIndex, NewIndex: Integer);
710
CheckState: QtCheckState;
713
{move is calling delete, and then insert.
714
we must save our item checkstate and selection}
715
if Assigned(FWinControl) and (FWinControl.HandleAllocated) and
716
(FOwner is TQtCheckListBox) then
718
CheckState := TQtCheckListBox(FOwner).ItemCheckState[CurIndex];
719
Selected := TQtCheckListBox(FOwner).Selected[CurIndex];
722
inherited Move(CurIndex, NewIndex);
724
{return check state to newindex}
725
if Assigned(FWinControl) and (FWinControl.HandleAllocated) and
726
(FOwner is TQtCheckListBox) then
729
TQtCheckListBox(FOwner).ItemCheckState[NewIndex] := CheckState;
730
FOwner.Selected[NewIndex] := Selected;
627
735
procedure TQtListStrings.Sort;
632
740
if Assigned(FWinControl) and (FWinControl.HandleAllocated) then
634
743
for I := 0 to Count - 1 do
635
744
FOwner.setItemText(I, Strings[I]);
639
749
procedure TQtListStrings.Exchange(AIndex1, AIndex2: Integer);
641
753
inherited Exchange(AIndex1, AIndex2);
642
754
if Assigned(FWinControl) and (FWinControl.HandleAllocated) then
643
FOwner.exchangeItems(AIndex1, AIndex2);
756
ARow := FOwner.currentRow;
758
FOwner.ExchangeItems(AIndex1, AIndex2);
759
FOwner.setCurrentRow(ARow);