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:
skalogryz
2009-08-18 05:21:51 +00:00
parent 140121f8ac
commit 3e63d8afaf
4 changed files with 94 additions and 50 deletions

View File

@ -50,6 +50,7 @@ type
iCount: ItemCount; var ioTypeAttributes: array of TXNTypeAttributes): Boolean; iCount: ItemCount; var ioTypeAttributes: array of TXNTypeAttributes): Boolean;
function SetTypeAttributes(iCount: ItemCount; const iTypeAttributes: array of TXNTypeAttributes; function SetTypeAttributes(iCount: ItemCount; const iTypeAttributes: array of TXNTypeAttributes;
StartOffset, EndOffset: Integer): Boolean; StartOffset, EndOffset: Integer): Boolean;
procedure InDelText(const text: WideString; replstart, repllength: Integer);
end; end;
{ TCarbonWSCustomRichMemo } { TCarbonWSCustomRichMemo }
@ -63,6 +64,7 @@ type
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer; class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer;
{Mask: TTextStyleMask;} const Params: TIntFontParams); override; {Mask: TTextStyleMask;} const Params: TIntFontParams); override;
class procedure SetHideSelection(const AWinControl: TWinControl; AHideSelection: Boolean); 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 LoadRichText(const AWinControl: TWinControl; Src: TStream): Boolean; override;
class function SaveRichText(const AWinControl: TWinControl; Dst: TStream): Boolean; override; class function SaveRichText(const AWinControl: TWinControl; Dst: TStream): Boolean; override;
end; end;
@ -193,6 +195,7 @@ begin
AttrSetColor(MacColor, Attr[AttrCount] ); AttrSetColor(MacColor, Attr[AttrCount] );
inc(AttrCount); inc(AttrCount);
//end; //end;
//if tsm_Name in ParamsMask then begin //if tsm_Name in ParamsMask then begin
AttrSetFontName(Params.Name, Attr[AttrCount] ); AttrSetFontName(Params.Name, Attr[AttrCount] );
@ -222,15 +225,6 @@ class function TCarbonWSCustomRichMemo.GetStyleRange(const AWinControl: TWinCont
TextStart: Integer; var RangeStart, RangeLen: Integer): Boolean; TextStart: Integer; var RangeStart, RangeLen: Integer): Boolean;
var var
edit : TCarbonRichEdit; 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; RngStart : TXNOffset;
RngEnd : TXNOffset; RngEnd : TXNOffset;
begin begin
@ -238,11 +232,11 @@ begin
edit := GetValidRichEdit(AWinControl); edit := GetValidRichEdit(AWinControl);
if not Assigned(edit) then Exit; 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 if Result then begin
RangeStart := RngStart; RangeStart := RngStart;
RangeLen := RngEnd - RngStart; RangeLen := RngEnd - RngStart;
end; end;
end; end;
@ -251,40 +245,41 @@ class function TCarbonWSCustomRichMemo.GetTextAttributes(const AWinControl: TWin
var var
edit : TCarbonRichEdit; edit : TCarbonRichEdit;
attr : array [0..2] of TXNTypeAttributes; attr : array [0..2] of TXNTypeAttributes;
sstart : Integer;
slen : Integer;
flags : TXNContinuousFlags; flags : TXNContinuousFlags;
astyle : ATSUStyle; astyle : ATSUStyle;
maccolor : RGBColor; maccolor : RGBColor;
oStart : TXNOffset;
oEnd : TXNOffset;
txobj : TXNObject;
begin begin
Result := false; Result := false;
edit := GetValidRichEdit(AWinControl); edit := GetValidRichEdit(AWinControl);
if not Assigned(edit) then Exit; if not Assigned(edit) then Exit;
edit.GetSelStart(sstart); txobj := HITextViewGetTXNObject(edit.Widget);
edit.GetSelLength(slen); if not Assigned(txobj) then Exit;
edit.SetSelStart(TextStart); TXNGetSelection(txobj, oStart, oEnd);
edit.SetSelLength(1); TXNSetSelection(txobj, TextStart, TextStart+1);
ATSUCreateStyle(astyle); ATSUCreateStyle(astyle);
AttrSetATSUStyle(astyle, attr[0]); AttrSetATSUStyle(astyle, attr[0]);
AttrSetStyle([], attr[1]); AttrSetStyle([], attr[1]);
FillChar(maccolor, sizeof(maccolor), 0);
AttrSetColor(maccolor, attr[2]); AttrSetColor(maccolor, attr[2]);
Result := edit.GetContinuousTypeAttributes(flags, 3, attr); Result := edit.GetContinuousTypeAttributes(flags, 3, attr);
Params.Name := GetATSUFontName(astyle); Params.Name := GetATSUFontName(astyle);
Params.Color := RGBColorToColor(maccolor); Params.Color := RGBColorToColor(maccolor);
// GetATSUFontColor(astyle);
//writeln('got color: ', IntToHex(Params.Color, 8)); //writeln('got color: ', IntToHex(Params.Color, 8));
Params.Style := GetATSUFontStyles(astyle) + QDStyleToFontStyle(attr[1].data.dataValue); Params.Style := GetATSUFontStyles(astyle) + QDStyleToFontStyle(attr[1].data.dataValue);
Params.Size := GetATSUFontSize(astyle); Params.Size := GetATSUFontSize(astyle);
ATSUDisposeStyle(astyle); ATSUDisposeStyle(astyle);
edit.SetSelStart(sstart); TXNSetSelection(txobj, oStart, oEnd);
edit.SetSelLength(slen);
end; end;
class procedure TCarbonWSCustomRichMemo.SetTextAttributes(const AWinControl: TWinControl; class procedure TCarbonWSCustomRichMemo.SetTextAttributes(const AWinControl: TWinControl;
@ -298,15 +293,24 @@ begin
memo := GetValidRichEdit(AWinControl); memo := GetValidRichEdit(AWinControl);
if not Assigned(memo) then Exit; 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); memo.SetTypeAttributes(Count, Attr, TextStart, TextStart+TextLen);
end; end;
class procedure TCarbonWSCustomRichMemo.SetHideSelection(const AWinControl: TWinControl; class procedure TCarbonWSCustomRichMemo.SetHideSelection(const AWinControl: TWinControl; AHideSelection: Boolean);
AHideSelection: Boolean);
begin 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; end;
function GetTempFileUniqueName(forcedir: Boolean=true): String; function GetTempFileUniqueName(forcedir: Boolean=true): String;
@ -332,7 +336,6 @@ var
fs : TFileStream; fs : TFileStream;
cf : CFStringRef; cf : CFStringRef;
url : CFURLRef; url : CFURLRef;
res : integer;
begin begin
Result := false; Result := false;
edit := GetValidRichEdit(AWinControl); edit := GetValidRichEdit(AWinControl);
@ -414,8 +417,6 @@ end;
function TCarbonRichEdit.GetContinuousTypeAttributes( function TCarbonRichEdit.GetContinuousTypeAttributes(
var oContinuousFlags: TXNContinuousFlags; iCount: ItemCount; var oContinuousFlags: TXNContinuousFlags; iCount: ItemCount;
var ioTypeAttributes: array of TXNTypeAttributes): Boolean; var ioTypeAttributes: array of TXNTypeAttributes): Boolean;
var
res : OSStatus;
begin begin
Result := TXNGetContinuousTypeAttributes(HITextViewGetTXNObject(Widget), Result := TXNGetContinuousTypeAttributes(HITextViewGetTXNObject(Widget),
oContinuousFlags, iCount, @ioTypeAttributes[0]) = noErr; oContinuousFlags, iCount, @ioTypeAttributes[0]) = noErr;
@ -429,6 +430,26 @@ begin
@iTypeAttributes[0], StartOffset, EndOffset) = noErr; @iTypeAttributes[0], StartOffset, EndOffset) = noErr;
end; 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;

View File

@ -51,6 +51,8 @@ type
procedure UpdateRichMemo; virtual; procedure UpdateRichMemo; virtual;
procedure SetHideSelection(AValue: Boolean); procedure SetHideSelection(AValue: Boolean);
function GetContStyleLength(TextStart: Integer): Integer; function GetContStyleLength(TextStart: Integer): Integer;
procedure SetSelText(const SelTextUTF8: string); override;
public public
procedure SetTextAttributes(TextStart, TextLen: Integer; const TextParams: TFontParams); virtual; procedure SetTextAttributes(TextStart, TextLen: Integer; const TextParams: TFontParams); virtual;
function GetTextAttributes(TextStart: Integer; var TextParams: TFontParams): Boolean; virtual; function GetTextAttributes(TextStart: Integer; var TextParams: TFontParams): Boolean; virtual;
@ -230,6 +232,22 @@ begin
if Result = 0 then Result := 1; if Result = 0 then Result := 1;
end; 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); procedure TCustomRichMemo.SetRangeColor(TextStart, TextLength: Integer; FontColor: TColor);
begin begin
SetRangeParams(TextStart, TextLength, [tmm_Color], '', 0, FontColor, [], []); SetRangeParams(TextStart, TextLength, [tmm_Color], '', 0, FontColor, [], []);

View File

@ -47,7 +47,7 @@
<ComponentName Value="Form1"/> <ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/> <UnitName Value="Unit1"/>
<CursorPos X="29" Y="125"/> <CursorPos X="44" Y="126"/>
<TopLine Value="123"/> <TopLine Value="123"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<UsageCount Value="70"/> <UsageCount Value="70"/>
@ -365,7 +365,7 @@
<UsageCount Value="9"/> <UsageCount Value="9"/>
</Unit44> </Unit44>
<Unit45> <Unit45>
<Filename Value="../../../../../Lazarus/lcl/stdctrls.pp"/> <Filename Value="../../../../../lazarus/lcl/stdctrls.pp"/>
<UnitName Value="StdCtrls"/> <UnitName Value="StdCtrls"/>
<CursorPos X="33" Y="677"/> <CursorPos X="33" Y="677"/>
<TopLine Value="662"/> <TopLine Value="662"/>
@ -381,7 +381,7 @@
<UsageCount Value="9"/> <UsageCount Value="9"/>
</Unit46> </Unit46>
<Unit47> <Unit47>
<Filename Value="../../../../../Lazarus/lcl/interfaces/win32/win32wsstdctrls.pp"/> <Filename Value="../../../../../lazarus/lcl/interfaces/win32/win32wsstdctrls.pp"/>
<UnitName Value="Win32WSStdCtrls"/> <UnitName Value="Win32WSStdCtrls"/>
<CursorPos X="26" Y="83"/> <CursorPos X="26" Y="83"/>
<TopLine Value="67"/> <TopLine Value="67"/>
@ -390,7 +390,7 @@
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit47> </Unit47>
<Unit48> <Unit48>
<Filename Value="../../../../../Lazarus/lcl/widgetset/wsstdctrls.pp"/> <Filename Value="../../../../../lazarus/lcl/widgetset/wsstdctrls.pp"/>
<UnitName Value="WSStdCtrls"/> <UnitName Value="WSStdCtrls"/>
<CursorPos X="36" Y="53"/> <CursorPos X="36" Y="53"/>
<TopLine Value="39"/> <TopLine Value="39"/>
@ -399,7 +399,7 @@
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit48> </Unit48>
<Unit49> <Unit49>
<Filename Value="../../../../../Lazarus/lcl/widgetset/wscontrols.pp"/> <Filename Value="../../../../../lazarus/lcl/widgetset/wscontrols.pp"/>
<UnitName Value="WSControls"/> <UnitName Value="WSControls"/>
<CursorPos X="30" Y="100"/> <CursorPos X="30" Y="100"/>
<TopLine Value="85"/> <TopLine Value="85"/>
@ -408,7 +408,7 @@
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit49> </Unit49>
<Unit50> <Unit50>
<Filename Value="../../../../../Lazarus/lcl/interfaces/win32/win32wscontrols.pp"/> <Filename Value="../../../../../lazarus/lcl/interfaces/win32/win32wscontrols.pp"/>
<UnitName Value="Win32WSControls"/> <UnitName Value="Win32WSControls"/>
<CursorPos X="1" Y="450"/> <CursorPos X="1" Y="450"/>
<TopLine Value="434"/> <TopLine Value="434"/>
@ -417,7 +417,7 @@
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit50> </Unit50>
<Unit51> <Unit51>
<Filename Value="../../../../../Lazarus/lcl/include/customlabel.inc"/> <Filename Value="../../../../../lazarus/lcl/include/customlabel.inc"/>
<CursorPos X="3" Y="229"/> <CursorPos X="3" Y="229"/>
<TopLine Value="227"/> <TopLine Value="227"/>
<EditorIndex Value="5"/> <EditorIndex Value="5"/>
@ -425,7 +425,7 @@
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit51> </Unit51>
<Unit52> <Unit52>
<Filename Value="../../../../../Lazarus/lcl/controls.pp"/> <Filename Value="../../../../../lazarus/lcl/controls.pp"/>
<UnitName Value="Controls"/> <UnitName Value="Controls"/>
<CursorPos X="24" Y="1784"/> <CursorPos X="24" Y="1784"/>
<TopLine Value="1769"/> <TopLine Value="1769"/>
@ -434,7 +434,7 @@
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit52> </Unit52>
<Unit53> <Unit53>
<Filename Value="../../../../../Lazarus/lcl/include/wincontrol.inc"/> <Filename Value="../../../../../lazarus/lcl/include/wincontrol.inc"/>
<CursorPos X="5" Y="4342"/> <CursorPos X="5" Y="4342"/>
<TopLine Value="4334"/> <TopLine Value="4334"/>
<EditorIndex Value="4"/> <EditorIndex Value="4"/>
@ -442,7 +442,7 @@
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit53> </Unit53>
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="28" HistoryIndex="27">
<Position1> <Position1>
<Filename Value="../../../../../Lazarus/lcl/interfaces/win32/win32wscontrols.pp"/> <Filename Value="../../../../../Lazarus/lcl/interfaces/win32/win32wscontrols.pp"/>
<Caret Line="29" Column="1" TopLine="29"/> <Caret Line="29" Column="1" TopLine="29"/>
@ -549,20 +549,12 @@
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="7" Column="13" TopLine="29"/> <Caret Line="1" Column="1" TopLine="1"/>
</Position27> </Position27>
<Position28> <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"/> <Filename Value="unit1.pas"/>
<Caret Line="22" Column="22" TopLine="22"/> <Caret Line="22" Column="22" TopLine="22"/>
</Position30> </Position28>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>
@ -570,6 +562,13 @@
<SearchPaths> <SearchPaths>
<IncludeFiles Value="$(ProjOutDir)/"/> <IncludeFiles Value="$(ProjOutDir)/"/>
</SearchPaths> </SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other> <Other>
<CompilerPath Value="$(CompPath)"/> <CompilerPath Value="$(CompPath)"/>
</Other> </Other>

View File

@ -48,7 +48,8 @@ type
class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer; class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
var Params: TIntFontParams): Boolean; virtual; var Params: TIntFontParams): Boolean; virtual;
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer; 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 procedure SetHideSelection(const AWinControl: TWinControl; AHideSelection: Boolean); virtual;
class function LoadRichText(const AWinControl: TWinControl; Source: TStream): Boolean; virtual; class function LoadRichText(const AWinControl: TWinControl; Source: TStream): Boolean; virtual;
class function SaveRichText(const AWinControl: TWinControl; Dest: 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 begin
end; 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); class procedure TWSCustomRichMemo.SetHideSelection(const AWinControl: TWinControl; AHideSelection: Boolean);
begin begin