You've already forked lazarus-ccr
fix for SelText clearing text formatting
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@935 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -50,6 +50,7 @@ type
|
||||
iCount: ItemCount; var ioTypeAttributes: array of TXNTypeAttributes): Boolean;
|
||||
function SetTypeAttributes(iCount: ItemCount; const iTypeAttributes: array of TXNTypeAttributes;
|
||||
StartOffset, EndOffset: Integer): Boolean;
|
||||
procedure InDelText(const text: WideString; replstart, repllength: Integer);
|
||||
end;
|
||||
|
||||
{ TCarbonWSCustomRichMemo }
|
||||
@ -63,6 +64,7 @@ type
|
||||
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||
{Mask: TTextStyleMask;} const Params: TIntFontParams); override;
|
||||
class procedure SetHideSelection(const AWinControl: TWinControl; AHideSelection: Boolean); override;
|
||||
class procedure InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer); override;
|
||||
class function LoadRichText(const AWinControl: TWinControl; Src: TStream): Boolean; override;
|
||||
class function SaveRichText(const AWinControl: TWinControl; Dst: TStream): Boolean; override;
|
||||
end;
|
||||
@ -193,6 +195,7 @@ begin
|
||||
AttrSetColor(MacColor, Attr[AttrCount] );
|
||||
inc(AttrCount);
|
||||
//end;
|
||||
|
||||
|
||||
//if tsm_Name in ParamsMask then begin
|
||||
AttrSetFontName(Params.Name, Attr[AttrCount] );
|
||||
@ -222,15 +225,6 @@ class function TCarbonWSCustomRichMemo.GetStyleRange(const AWinControl: TWinCont
|
||||
TextStart: Integer; var RangeStart, RangeLen: Integer): Boolean;
|
||||
var
|
||||
edit : TCarbonRichEdit;
|
||||
st, len : Integer;
|
||||
send : Integer;
|
||||
fndstyle : Boolean;
|
||||
wattr : array [0..1] of TXNTypeAttributes;
|
||||
attr : array [0..1] of TXNTypeAttributes;
|
||||
astyle : ATSUStyle;
|
||||
flags : TXNContinuousFlags;
|
||||
d : Integer;
|
||||
macrgb : RGBColor;
|
||||
RngStart : TXNOffset;
|
||||
RngEnd : TXNOffset;
|
||||
begin
|
||||
@ -238,11 +232,11 @@ begin
|
||||
edit := GetValidRichEdit(AWinControl);
|
||||
if not Assigned(edit) then Exit;
|
||||
|
||||
Result := edit.GetIndexedRunInfoFromRange(0, TextStart, TextStart+1, RngStart, RngEnd, nil, 0, nil);
|
||||
Result := edit.GetIndexedRunInfoFromRange(0, TextStart, TextStart, RngStart, RngEnd, nil, 0, nil);
|
||||
if Result then begin
|
||||
RangeStart := RngStart;
|
||||
RangeLen := RngEnd - RngStart;
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
@ -251,40 +245,41 @@ class function TCarbonWSCustomRichMemo.GetTextAttributes(const AWinControl: TWin
|
||||
var
|
||||
edit : TCarbonRichEdit;
|
||||
attr : array [0..2] of TXNTypeAttributes;
|
||||
sstart : Integer;
|
||||
slen : Integer;
|
||||
flags : TXNContinuousFlags;
|
||||
|
||||
astyle : ATSUStyle;
|
||||
maccolor : RGBColor;
|
||||
|
||||
oStart : TXNOffset;
|
||||
oEnd : TXNOffset;
|
||||
txobj : TXNObject;
|
||||
begin
|
||||
Result := false;
|
||||
edit := GetValidRichEdit(AWinControl);
|
||||
if not Assigned(edit) then Exit;
|
||||
|
||||
edit.GetSelStart(sstart);
|
||||
edit.GetSelLength(slen);
|
||||
|
||||
edit.SetSelStart(TextStart);
|
||||
edit.SetSelLength(1);
|
||||
|
||||
txobj := HITextViewGetTXNObject(edit.Widget);
|
||||
if not Assigned(txobj) then Exit;
|
||||
|
||||
TXNGetSelection(txobj, oStart, oEnd);
|
||||
TXNSetSelection(txobj, TextStart, TextStart+1);
|
||||
|
||||
ATSUCreateStyle(astyle);
|
||||
AttrSetATSUStyle(astyle, attr[0]);
|
||||
AttrSetStyle([], attr[1]);
|
||||
FillChar(maccolor, sizeof(maccolor), 0);
|
||||
AttrSetColor(maccolor, attr[2]);
|
||||
|
||||
Result := edit.GetContinuousTypeAttributes(flags, 3, attr);
|
||||
Params.Name := GetATSUFontName(astyle);
|
||||
Params.Color := RGBColorToColor(maccolor);
|
||||
// GetATSUFontColor(astyle);
|
||||
Params.Color := RGBColorToColor(maccolor);
|
||||
//writeln('got color: ', IntToHex(Params.Color, 8));
|
||||
Params.Style := GetATSUFontStyles(astyle) + QDStyleToFontStyle(attr[1].data.dataValue);
|
||||
Params.Size := GetATSUFontSize(astyle);
|
||||
|
||||
ATSUDisposeStyle(astyle);
|
||||
|
||||
edit.SetSelStart(sstart);
|
||||
edit.SetSelLength(slen);
|
||||
TXNSetSelection(txobj, oStart, oEnd);
|
||||
end;
|
||||
|
||||
class procedure TCarbonWSCustomRichMemo.SetTextAttributes(const AWinControl: TWinControl;
|
||||
@ -298,15 +293,24 @@ begin
|
||||
memo := GetValidRichEdit(AWinControl);
|
||||
if not Assigned(memo) then Exit;
|
||||
|
||||
ParamsToTXNAttribs({Mask,} Params, attr, Count, maccolor);
|
||||
ParamsToTXNAttribs(Params, attr, Count, maccolor);
|
||||
|
||||
writeln('setting attr, start = ', textstart, ', end = ', textStart + textLen, ' color = ', IntToHex(Params.Color,8));
|
||||
memo.SetTypeAttributes(Count, Attr, TextStart, TextStart+TextLen);
|
||||
end;
|
||||
|
||||
class procedure TCarbonWSCustomRichMemo.SetHideSelection(const AWinControl: TWinControl;
|
||||
AHideSelection: Boolean);
|
||||
class procedure TCarbonWSCustomRichMemo.SetHideSelection(const AWinControl: TWinControl; AHideSelection: Boolean);
|
||||
begin
|
||||
//todo:
|
||||
end;
|
||||
|
||||
class procedure TCarbonWSCustomRichMemo.InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer);
|
||||
var
|
||||
memo : TCarbonRichEdit;
|
||||
begin
|
||||
memo := GetValidRichEdit(AWinControl);
|
||||
if not Assigned(memo) then Exit;
|
||||
memo.InDelText(UTF8Decode(TextUTF8), DstStart, DstLen);
|
||||
end;
|
||||
|
||||
function GetTempFileUniqueName(forcedir: Boolean=true): String;
|
||||
@ -332,7 +336,6 @@ var
|
||||
fs : TFileStream;
|
||||
cf : CFStringRef;
|
||||
url : CFURLRef;
|
||||
res : integer;
|
||||
begin
|
||||
Result := false;
|
||||
edit := GetValidRichEdit(AWinControl);
|
||||
@ -414,8 +417,6 @@ end;
|
||||
function TCarbonRichEdit.GetContinuousTypeAttributes(
|
||||
var oContinuousFlags: TXNContinuousFlags; iCount: ItemCount;
|
||||
var ioTypeAttributes: array of TXNTypeAttributes): Boolean;
|
||||
var
|
||||
res : OSStatus;
|
||||
begin
|
||||
Result := TXNGetContinuousTypeAttributes(HITextViewGetTXNObject(Widget),
|
||||
oContinuousFlags, iCount, @ioTypeAttributes[0]) = noErr;
|
||||
@ -429,6 +430,26 @@ begin
|
||||
@iTypeAttributes[0], StartOffset, EndOffset) = noErr;
|
||||
end;
|
||||
|
||||
procedure TCarbonRichEdit.InDelText(const text: WideString; replstart, repllength: Integer);
|
||||
var
|
||||
data : UnivPtr;
|
||||
datasz : ByteCount;
|
||||
res : OSStatus;
|
||||
replend : Integer;
|
||||
begin
|
||||
if text = '' then begin
|
||||
data := nil;
|
||||
datasz := 0;
|
||||
end else begin
|
||||
data := @text[1];
|
||||
datasz := length(text)*2;
|
||||
end;
|
||||
if repllength < 0 then replend := kTXNEndOffset
|
||||
else replend := replstart+repllength;
|
||||
res := TXNSetData(HITextViewGetTXNObject(Widget), kTXNUnicodeTextData, data, datasz, replstart, replend);
|
||||
writeln('TXNSetData ', res);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -51,6 +51,8 @@ type
|
||||
procedure UpdateRichMemo; virtual;
|
||||
procedure SetHideSelection(AValue: Boolean);
|
||||
function GetContStyleLength(TextStart: Integer): Integer;
|
||||
|
||||
procedure SetSelText(const SelTextUTF8: string); override;
|
||||
public
|
||||
procedure SetTextAttributes(TextStart, TextLen: Integer; const TextParams: TFontParams); virtual;
|
||||
function GetTextAttributes(TextStart: Integer; var TextParams: TFontParams): Boolean; virtual;
|
||||
@ -230,6 +232,22 @@ begin
|
||||
if Result = 0 then Result := 1;
|
||||
end;
|
||||
|
||||
procedure TCustomRichMemo.SetSelText(const SelTextUTF8: string);
|
||||
var
|
||||
st : Integer;
|
||||
begin
|
||||
Lines.BeginUpdate;
|
||||
try
|
||||
st := SelStart;
|
||||
if HandleAllocated then
|
||||
TWSCustomRichMemoClass(WidgetSetClass).InDelText(Self, SelTextUTF8, SelStart, SelLength);
|
||||
SelStart := st;
|
||||
SelLength := length(UTF8Decode(SelTextUTF8));
|
||||
finally
|
||||
Lines.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomRichMemo.SetRangeColor(TextStart, TextLength: Integer; FontColor: TColor);
|
||||
begin
|
||||
SetRangeParams(TextStart, TextLength, [tmm_Color], '', 0, FontColor, [], []);
|
||||
|
@ -47,7 +47,7 @@
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="Unit1"/>
|
||||
<CursorPos X="29" Y="125"/>
|
||||
<CursorPos X="44" Y="126"/>
|
||||
<TopLine Value="123"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<UsageCount Value="70"/>
|
||||
@ -365,7 +365,7 @@
|
||||
<UsageCount Value="9"/>
|
||||
</Unit44>
|
||||
<Unit45>
|
||||
<Filename Value="../../../../../Lazarus/lcl/stdctrls.pp"/>
|
||||
<Filename Value="../../../../../lazarus/lcl/stdctrls.pp"/>
|
||||
<UnitName Value="StdCtrls"/>
|
||||
<CursorPos X="33" Y="677"/>
|
||||
<TopLine Value="662"/>
|
||||
@ -381,7 +381,7 @@
|
||||
<UsageCount Value="9"/>
|
||||
</Unit46>
|
||||
<Unit47>
|
||||
<Filename Value="../../../../../Lazarus/lcl/interfaces/win32/win32wsstdctrls.pp"/>
|
||||
<Filename Value="../../../../../lazarus/lcl/interfaces/win32/win32wsstdctrls.pp"/>
|
||||
<UnitName Value="Win32WSStdCtrls"/>
|
||||
<CursorPos X="26" Y="83"/>
|
||||
<TopLine Value="67"/>
|
||||
@ -390,7 +390,7 @@
|
||||
<Loaded Value="True"/>
|
||||
</Unit47>
|
||||
<Unit48>
|
||||
<Filename Value="../../../../../Lazarus/lcl/widgetset/wsstdctrls.pp"/>
|
||||
<Filename Value="../../../../../lazarus/lcl/widgetset/wsstdctrls.pp"/>
|
||||
<UnitName Value="WSStdCtrls"/>
|
||||
<CursorPos X="36" Y="53"/>
|
||||
<TopLine Value="39"/>
|
||||
@ -399,7 +399,7 @@
|
||||
<Loaded Value="True"/>
|
||||
</Unit48>
|
||||
<Unit49>
|
||||
<Filename Value="../../../../../Lazarus/lcl/widgetset/wscontrols.pp"/>
|
||||
<Filename Value="../../../../../lazarus/lcl/widgetset/wscontrols.pp"/>
|
||||
<UnitName Value="WSControls"/>
|
||||
<CursorPos X="30" Y="100"/>
|
||||
<TopLine Value="85"/>
|
||||
@ -408,7 +408,7 @@
|
||||
<Loaded Value="True"/>
|
||||
</Unit49>
|
||||
<Unit50>
|
||||
<Filename Value="../../../../../Lazarus/lcl/interfaces/win32/win32wscontrols.pp"/>
|
||||
<Filename Value="../../../../../lazarus/lcl/interfaces/win32/win32wscontrols.pp"/>
|
||||
<UnitName Value="Win32WSControls"/>
|
||||
<CursorPos X="1" Y="450"/>
|
||||
<TopLine Value="434"/>
|
||||
@ -417,7 +417,7 @@
|
||||
<Loaded Value="True"/>
|
||||
</Unit50>
|
||||
<Unit51>
|
||||
<Filename Value="../../../../../Lazarus/lcl/include/customlabel.inc"/>
|
||||
<Filename Value="../../../../../lazarus/lcl/include/customlabel.inc"/>
|
||||
<CursorPos X="3" Y="229"/>
|
||||
<TopLine Value="227"/>
|
||||
<EditorIndex Value="5"/>
|
||||
@ -425,7 +425,7 @@
|
||||
<Loaded Value="True"/>
|
||||
</Unit51>
|
||||
<Unit52>
|
||||
<Filename Value="../../../../../Lazarus/lcl/controls.pp"/>
|
||||
<Filename Value="../../../../../lazarus/lcl/controls.pp"/>
|
||||
<UnitName Value="Controls"/>
|
||||
<CursorPos X="24" Y="1784"/>
|
||||
<TopLine Value="1769"/>
|
||||
@ -434,7 +434,7 @@
|
||||
<Loaded Value="True"/>
|
||||
</Unit52>
|
||||
<Unit53>
|
||||
<Filename Value="../../../../../Lazarus/lcl/include/wincontrol.inc"/>
|
||||
<Filename Value="../../../../../lazarus/lcl/include/wincontrol.inc"/>
|
||||
<CursorPos X="5" Y="4342"/>
|
||||
<TopLine Value="4334"/>
|
||||
<EditorIndex Value="4"/>
|
||||
@ -442,7 +442,7 @@
|
||||
<Loaded Value="True"/>
|
||||
</Unit53>
|
||||
</Units>
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<JumpHistory Count="28" HistoryIndex="27">
|
||||
<Position1>
|
||||
<Filename Value="../../../../../Lazarus/lcl/interfaces/win32/win32wscontrols.pp"/>
|
||||
<Caret Line="29" Column="1" TopLine="29"/>
|
||||
@ -549,20 +549,12 @@
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="unit1.pas"/>
|
||||
<Caret Line="7" Column="13" TopLine="29"/>
|
||||
<Caret Line="1" Column="1" TopLine="1"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="unit1.pas"/>
|
||||
<Caret Line="1" Column="1" TopLine="1"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="unit1.pas"/>
|
||||
<Caret Line="23" Column="10" TopLine="30"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="unit1.pas"/>
|
||||
<Caret Line="22" Column="22" TopLine="22"/>
|
||||
</Position30>
|
||||
</Position28>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
@ -570,6 +562,13 @@
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)/"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
|
@ -48,7 +48,8 @@ type
|
||||
class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
|
||||
var Params: TIntFontParams): Boolean; virtual;
|
||||
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||
{Mask: TTextStyleMask;} const Params: TIntFontParams); virtual;
|
||||
const Params: TIntFontParams); virtual;
|
||||
class procedure InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer); virtual;
|
||||
class procedure SetHideSelection(const AWinControl: TWinControl; AHideSelection: Boolean); virtual;
|
||||
class function LoadRichText(const AWinControl: TWinControl; Source: TStream): Boolean; virtual;
|
||||
class function SaveRichText(const AWinControl: TWinControl; Dest: TStream): Boolean; virtual;
|
||||
@ -82,6 +83,11 @@ class procedure TWSCustomRichMemo.SetTextAttributes(const AWinControl: TWinContr
|
||||
begin
|
||||
end;
|
||||
|
||||
class procedure TWSCustomRichMemo.InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
class procedure TWSCustomRichMemo.SetHideSelection(const AWinControl: TWinControl; AHideSelection: Boolean);
|
||||
begin
|
||||
|
||||
|
Reference in New Issue
Block a user