You've already forked lazarus-ccr
richmemo: paragraph alignment initialized
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3719 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
richmemo.pp
|
richmemo.pas
|
||||||
|
|
||||||
Author: Dmitry 'skalogryz' Boyarintsev
|
Author: Dmitry 'skalogryz' Boyarintsev
|
||||||
|
|
||||||
@ -29,14 +29,11 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
TFontParams = TIntFontParams;
|
TFontParams = WSRichMemo.TIntFontParams;
|
||||||
{TIntFontParams = record // declared at WSRichMemo
|
TParaAlignment = (paLeft, paRight, paCenter, paJustify);
|
||||||
Name : String;
|
TParaMetric = WSRichMemo.TIntParaMetric;
|
||||||
Size : Integer;
|
TParaNumStyle = WSRichMemo.TParaNumStyle;
|
||||||
Color : TColor;
|
TParaNumbering = WSRichMemo.TIntParaNumbering;
|
||||||
Style : TFontStyles;
|
|
||||||
end; }
|
|
||||||
|
|
||||||
|
|
||||||
TTextModifyMask = set of (tmm_Color, tmm_Name, tmm_Size, tmm_Styles);
|
TTextModifyMask = set of (tmm_Color, tmm_Name, tmm_Size, tmm_Styles);
|
||||||
|
|
||||||
@ -63,6 +60,9 @@ type
|
|||||||
function GetTextAttributes(TextStart: Integer; var TextParams: TFontParams): Boolean; virtual;
|
function GetTextAttributes(TextStart: Integer; var TextParams: TFontParams): Boolean; virtual;
|
||||||
function GetStyleRange(CharOfs: Integer; var RangeStart, RangeLen: Integer): Boolean; virtual;
|
function GetStyleRange(CharOfs: Integer; var RangeStart, RangeLen: Integer): Boolean; virtual;
|
||||||
|
|
||||||
|
function GetParaAllignment(TextStart: Integer; var AAlign: TParaAlignment): Boolean; virtual;
|
||||||
|
procedure SetParaAlignment(TextStart, TextLen: Integer; AAlign: TParaAlignment); virtual;
|
||||||
|
|
||||||
procedure SetTextAttributes(TextStart, TextLen: Integer; AFont: TFont);
|
procedure SetTextAttributes(TextStart, TextLen: Integer; AFont: TFont);
|
||||||
procedure SetRangeColor(TextStart, TextLength: Integer; FontColor: TColor);
|
procedure SetRangeColor(TextStart, TextLength: Integer; FontColor: TColor);
|
||||||
procedure SetRangeParams(TextStart, TextLength: Integer; ModifyMask: TTextModifyMask;
|
procedure SetRangeParams(TextStart, TextLength: Integer; ModifyMask: TTextModifyMask;
|
||||||
@ -142,6 +142,9 @@ var
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
const
|
||||||
|
ParaAlignCode : array [TParaAlignment] of Integer = (AL_LEFT, AL_RIGHT, AL_CENTER, AL_JUSTIFY);
|
||||||
|
|
||||||
function GetFontParams(styles: TFontStyles): TFontParams; overload;
|
function GetFontParams(styles: TFontStyles): TFontParams; overload;
|
||||||
begin
|
begin
|
||||||
Result := GetFontParams('', 0, 0, styles);
|
Result := GetFontParams('', 0, 0, styles);
|
||||||
@ -234,6 +237,32 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomRichMemo.GetParaAllignment(TextStart: Integer;
|
||||||
|
var AAlign: TParaAlignment): Boolean;
|
||||||
|
var
|
||||||
|
ac: Integer;
|
||||||
|
begin
|
||||||
|
Result := HandleAllocated and
|
||||||
|
TWSCustomRichMemoClass(WidgetSetClass).GetParaAlignment(Self, TextStart, ac);
|
||||||
|
if Result then begin
|
||||||
|
case ac of
|
||||||
|
AL_LEFT: AAlign:=paLeft;
|
||||||
|
AL_RIGHT: AAlign:=paRight;
|
||||||
|
AL_CENTER: AAlign:=paCenter;
|
||||||
|
AL_JUSTIFY: AAlign:=paJustify
|
||||||
|
else
|
||||||
|
AAlign:=paLeft;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomRichMemo.SetParaAlignment(TextStart, TextLen: Integer;
|
||||||
|
AAlign: TParaAlignment);
|
||||||
|
begin
|
||||||
|
if HandleAllocated then
|
||||||
|
TWSCustomRichMemoClass(WidgetSetClass).SetParaAlignment(Self, TextStart, TextLen, ParaAlignCode[AAlign]);
|
||||||
|
end;
|
||||||
|
|
||||||
function TCustomRichMemo.GetContStyleLength(TextStart: Integer): Integer;
|
function TCustomRichMemo.GetContStyleLength(TextStart: Integer): Integer;
|
||||||
var
|
var
|
||||||
ofs, len : Integer;
|
ofs, len : Integer;
|
||||||
|
@ -25,7 +25,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
// Win32 headers
|
// Win32 headers
|
||||||
Windows,
|
Windows, RichEdit,
|
||||||
// RTL headers
|
// RTL headers
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
// LCL headers
|
// LCL headers
|
||||||
@ -61,6 +61,13 @@ type
|
|||||||
class function LoadRichText(const AWinControl: TWinControl; Source: TStream): Boolean; override;
|
class function LoadRichText(const AWinControl: TWinControl; Source: TStream): Boolean; override;
|
||||||
class function SaveRichText(const AWinControl: TWinControl; Dst: TStream): Boolean; override;
|
class function SaveRichText(const AWinControl: TWinControl; Dst: TStream): Boolean; override;
|
||||||
|
|
||||||
|
class function GetParaAlignment(const AWinControl: TWinControl; TextStart: Integer;
|
||||||
|
var AAlign: Integer): Boolean; override;
|
||||||
|
class procedure SetParaAlignment(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
|
const AAlign: Integer); override;
|
||||||
|
|
||||||
|
class function GetParaMatrics(const AWinControl: TWinControl; TextStart: Integer;
|
||||||
|
var AMetrics: TIntParaMetric): Boolean; override;
|
||||||
class procedure InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer); override;
|
class procedure InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -330,6 +337,52 @@ begin
|
|||||||
Result := RichEditManager.SaveRichText(AWinControl.Handle, Dst);
|
Result := RichEditManager.SaveRichText(AWinControl.Handle, Dst);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TWin32WSCustomRichMemo.GetParaAlignment(
|
||||||
|
const AWinControl: TWinControl; TextStart: Integer; var AAlign: Integer
|
||||||
|
): Boolean;
|
||||||
|
var
|
||||||
|
para : PARAFORMAT2;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
if not Assigned(RichEditManager) or not Assigned(AWinControl) then Exit;
|
||||||
|
RichEditManager.GetPara2(AWinControl.Handle, TextStart, para);
|
||||||
|
case para.wAlignment of
|
||||||
|
PFA_CENTER: AAlign:=AL_CENTER;
|
||||||
|
PFA_RIGHT: AAlign:=AL_RIGHT;
|
||||||
|
PFA_JUSTIFY: AAlign:=AL_JUSTIFY;
|
||||||
|
else
|
||||||
|
AAlign:=AL_LEFT;
|
||||||
|
end;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TWin32WSCustomRichMemo.SetParaAlignment(
|
||||||
|
const AWinControl: TWinControl; TextStart, TextLen: Integer; const AAlign: Integer);
|
||||||
|
var
|
||||||
|
para : PARAFORMAT2;
|
||||||
|
const
|
||||||
|
WinPara : array [AL_LEFT..AL_JUSTIFY] of word = (PFA_LEFT, PFA_RIGHT, PFA_CENTER, PFA_JUSTIFY);
|
||||||
|
begin
|
||||||
|
if not Assigned(RichEditManager) or not Assigned(AWinControl)
|
||||||
|
or (AAlign<AL_LEFT) or (AAlign>AL_JUSTIFY) then Exit;
|
||||||
|
FillChar(para, sizeof(para), 0);
|
||||||
|
para.cbSize:=sizeof(para);
|
||||||
|
para.dwMask:=PFM_ALIGNMENT;
|
||||||
|
para.wAlignment:=WinPara[byte(AAlign)];
|
||||||
|
RichEditManager.SetPara2(AWinControl.Handle, TextStart, TextLen, para);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TWin32WSCustomRichMemo.GetParaMatrics(
|
||||||
|
const AWinControl: TWinControl; TextStart: Integer;
|
||||||
|
var AMetrics: TIntParaMetric): Boolean;
|
||||||
|
var
|
||||||
|
para : PARAFORMAT2;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
if not Assigned(RichEditManager) or not Assigned(AWinControl) then Exit;
|
||||||
|
RichEditManager.GetPara2(AWinControl.Handle, TextStart, para);
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TWin32WSCustomRichMemo.InDelText(const AWinControl:TWinControl;
|
class procedure TWin32WSCustomRichMemo.InDelText(const AWinControl:TWinControl;
|
||||||
const TextUTF8:String;DstStart,DstLen:Integer);
|
const TextUTF8:String;DstStart,DstLen:Integer);
|
||||||
begin
|
begin
|
||||||
|
@ -49,6 +49,8 @@ type
|
|||||||
class function LoadRichText(RichEditWnd: Handle; ASrc: TStream): Boolean; virtual;
|
class function LoadRichText(RichEditWnd: Handle; ASrc: TStream): Boolean; virtual;
|
||||||
class function SaveRichText(RichEditWnd: Handle; ADst: TStream): Boolean; virtual;
|
class function SaveRichText(RichEditWnd: Handle; ADst: TStream): Boolean; virtual;
|
||||||
class procedure SetText(RichEditWnd: Handle; const Text: WideString; TextStart, ReplaceLength: Integer); virtual;
|
class procedure SetText(RichEditWnd: Handle; const Text: WideString; TextStart, ReplaceLength: Integer); virtual;
|
||||||
|
class procedure GetPara2(RichEditWnd: Handle; TextStart: Integer; var para: PARAFORMAT2); virtual;
|
||||||
|
class procedure SetPara2(RichEditWnd: Handle; TextStart, TextLen: Integer; const para: PARAFORMAT2); virtual;
|
||||||
end;
|
end;
|
||||||
TRichManagerClass = class of TRichEditManager;
|
TRichManagerClass = class of TRichEditManager;
|
||||||
|
|
||||||
@ -398,5 +400,33 @@ begin
|
|||||||
SetSelection(RichEditWnd, s, l);
|
SetSelection(RichEditWnd, s, l);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class procedure TRichEditManager.GetPara2(RichEditWnd: Handle; TextStart: Integer;
|
||||||
|
var para: PARAFORMAT2);
|
||||||
|
var
|
||||||
|
s, l : Integer;
|
||||||
|
begin
|
||||||
|
GetSelection(RichEditWnd, s, l);
|
||||||
|
SetSelection(RichEditWnd, TextStart, 0);
|
||||||
|
|
||||||
|
FillChar(para, sizeof(para), 0);
|
||||||
|
para.cbSize:=sizeof(para);
|
||||||
|
SendMessagea(RichEditWnd, EM_GETPARAFORMAT, 0, LPARAM(@para));
|
||||||
|
|
||||||
|
SetSelection(RichEditWnd, s, l);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TRichEditManager.SetPara2(RichEditWnd: Handle;
|
||||||
|
TextStart, TextLen: Integer; const para: PARAFORMAT2);
|
||||||
|
var
|
||||||
|
s, l : Integer;
|
||||||
|
begin
|
||||||
|
GetSelection(RichEditWnd, s, l);
|
||||||
|
SetSelection(RichEditWnd, TextStart, TextLen);
|
||||||
|
|
||||||
|
SendMessagea(RichEditWnd, EM_SETPARAFORMAT, 0, LPARAM(@para));
|
||||||
|
|
||||||
|
SetSelection(RichEditWnd, s, l);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -39,6 +39,42 @@ type
|
|||||||
Style : TFontStyles;
|
Style : TFontStyles;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
const
|
||||||
|
AL_LEFT = 1;
|
||||||
|
AL_RIGHT = 2;
|
||||||
|
AL_CENTER = 3;
|
||||||
|
AL_JUSTIFY = 4;
|
||||||
|
|
||||||
|
type
|
||||||
|
TIntParaMetric = record
|
||||||
|
StartIndent : Double; // in points
|
||||||
|
RightIndent : Double; // in points
|
||||||
|
Offset : Double; // in points
|
||||||
|
SpaceBefore : Double; // in points
|
||||||
|
SpaceAfter : Double; // in points
|
||||||
|
LineSpacing : Double; // todo: ?
|
||||||
|
end;
|
||||||
|
|
||||||
|
TParaNumStyle = (pnNone, pnBullet, pnNumber, pnLowLetter
|
||||||
|
, pnLowRoman, pnUpLetter, pnUpRoman, pnCustomChar);
|
||||||
|
|
||||||
|
TIntParaNumbering = record
|
||||||
|
Numbering : TParaNumStyle;
|
||||||
|
NumCustom : WideChar;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TTabAlignment = (taLeft, taCenter, taRight, taDecimal, taWordBar);
|
||||||
|
|
||||||
|
TTabInfo = record
|
||||||
|
Offset : Double;
|
||||||
|
Align : TTabAlignment;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TIntParaTabs = record
|
||||||
|
Count : Integer;
|
||||||
|
Tabs : array of TTabInfo;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TWSCustomRichMemo }
|
{ TWSCustomRichMemo }
|
||||||
|
|
||||||
@ -56,7 +92,13 @@ type
|
|||||||
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;
|
||||||
const Params: TIntFontParams); virtual;
|
const Params: TIntFontParams); virtual;
|
||||||
class procedure InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer); virtual;
|
class function GetParaAlignment(const AWinControl: TWinControl; TextStart: Integer;
|
||||||
|
var AAlign: Integer): Boolean; virtual;
|
||||||
|
class procedure SetParaAlignment(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
|
const AAlign: Integer); virtual;
|
||||||
|
class function GetParaMatrics(const AWinControl: TWinControl; TextStart: Integer;
|
||||||
|
var AMetrics: TIntParaMetric): Boolean; virtual;
|
||||||
|
class procedure InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer); virtual;
|
||||||
class procedure SetHideSelection(const ACustomEdit: TCustomEdit; AHideSelection: Boolean); override;
|
class procedure SetHideSelection(const ACustomEdit: TCustomEdit; AHideSelection: Boolean); override;
|
||||||
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;
|
||||||
@ -105,6 +147,25 @@ class procedure TWSCustomRichMemo.SetTextAttributes(const AWinControl: TWinContr
|
|||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TWSCustomRichMemo.GetParaAlignment(
|
||||||
|
const AWinControl: TWinControl; TextStart: Integer; var AAlign: Integer
|
||||||
|
): Boolean;
|
||||||
|
begin
|
||||||
|
Result := false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TWSCustomRichMemo.SetParaAlignment(
|
||||||
|
const AWinControl: TWinControl; TextStart, TextLen: Integer; const AAlign: Integer);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TWSCustomRichMemo.GetParaMatrics(const AWinControl: TWinControl;
|
||||||
|
TextStart: Integer; var AMetrics: TIntParaMetric): Boolean;
|
||||||
|
begin
|
||||||
|
Result := false;
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TWSCustomRichMemo.InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer);
|
class procedure TWSCustomRichMemo.InDelText(const AWinControl: TWinControl; const TextUTF8: String; DstStart, DstLen: Integer);
|
||||||
begin
|
begin
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user