-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurichedit.pas
440 lines (371 loc) · 11.8 KB
/
urichedit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
//----------------------------------------
// Copyright © ying32. All Rights Reserved.
//
// Licensed under Lazarus.modifiedLGPL
//
//----------------------------------------
//----------------------------------------
// 用来兼容Delphi的TRichEdit
//----------------------------------------
unit uRichEdit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, RichMemo, richmemohelpers, Graphics;
type
TSearchType = TSearchOption;
TSearchTypes = TSearchOptions;
TAttributeType = (atSelected, atDefaultText);
TNumberingStyle = (nsNone, nsBullet);
TRichEdit = class;
{ TTextAttributes }
TTextAttributes = class(TPersistent)
private
FOwner: TRichMemo;
FType: TAttributeType;
function DoGetAttrs: TFontParams;
private
function GetCharset: TFontCharset;
function GetColor: TColor;
function GetHeight: Integer;
function GetName: string;
function GetPitch: TFontPitch;
function GetSize: Integer;
function GetStyle: TFontStyles;
procedure SetCharset(AValue: TFontCharset);
procedure SetColor(AValue: TColor);
procedure SetHeight(AValue: Integer);
procedure SetName(AValue: string);
procedure SetPitch(AValue: TFontPitch);
procedure SetSize(AValue: Integer);
procedure SetStyle(AValue: TFontStyles);
public
constructor Create(AOwner: TRichMemo; AType: TAttributeType);
procedure Assign(Source: TPersistent); override;
property Name: string read GetName write SetName;
property Pitch: TFontPitch read GetPitch write SetPitch;
property Charset: TFontCharset read GetCharset write SetCharset;
property Color: TColor read GetColor write SetColor;
property Size: Integer read GetSize write SetSize;
property Style: TFontStyles read GetStyle write SetStyle;
property Height: Integer read GetHeight write SetHeight;
end;
{ TParaAttributes }
TParaAttributes = class(TPersistent)
private
FOwner: TRichMemo;
function DoGetParaMetric: TParaMetric;
private
function GetAlignment: TAlignment;
function GetFirstIndent: Integer;
function GetLeftIndent: Integer;
function GetNumbering: TNumberingStyle;
function GetRightIndent: Integer;
function GetTab(Index: Byte): Longint;
function GetTabCount: Integer;
procedure SetAlignment(AValue: TAlignment);
procedure SetFirstIndent(AValue: Integer);
procedure SetLeftIndent(AValue: Integer);
procedure SetNumbering(AValue: TNumberingStyle);
procedure SetRightIndent(AValue: Integer);
procedure SetTab(Index: Byte; AValue: Longint);
procedure SetTabCount(AValue: Integer);
public
constructor Create(AOwner: TRichMemo);
procedure Assign(Source: TPersistent); override;
property Alignment: TAlignment read GetAlignment write SetAlignment;
property FirstIndent: Integer read GetFirstIndent write SetFirstIndent;
property LeftIndent: Integer read GetLeftIndent write SetLeftIndent;
property RightIndent: Integer read GetRightIndent write SetRightIndent;
property Numbering: TNumberingStyle read GetNumbering write SetNumbering;
property TabCount: Integer read GetTabCount write SetTabCount;
property Tab[Index: Byte]: Longint read GetTab write SetTab;
end;
{ TRichEdit }
TRichEdit = class(TRichMemo)
private
FDefAttributes: TTextAttributes;
FHideScrollBars: Boolean;
FParagraph: TParaAttributes;
FPlainText: Boolean;
FSelAttributes: TTextAttributes;
function GetZoom: Integer;
procedure SetDefAttributes(AValue: TTextAttributes);
procedure SetSelAttributes(AValue: TTextAttributes);
procedure SetZoom(AValue: Integer);
public
constructor Create(AOnwer: TComponent); override;
destructor Destroy; override;
function FindText(ASearchStr: string; AStartPos: Integer; ALength: Integer; AOptions: TSearchTypes): Integer;
property Zoom: Integer read GetZoom write SetZoom;
property HideScrollBars: Boolean read FHideScrollBars write FHideScrollBars;
property PlainText: Boolean read FPlainText write FPlainText;
property DefAttributes: TTextAttributes read FDefAttributes write SetDefAttributes;
property SelAttributes: TTextAttributes read FSelAttributes write SetSelAttributes;
property Paragraph: TParaAttributes read FParagraph write FParagraph;
public
property Align;
property Alignment;
property Anchors;
property BidiMode;
property BorderSpacing;
property BorderStyle;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property Lines;
property MaxLength;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEditingDone;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnLinkAction;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnSelectionChange;
property OnStartDrag;
property OnPrintAction;
property OnUTF8KeyPress;
property ParentBidiMode;
property ParentColor;
property ParentFont;
property PopupMenu;
property ParentShowHint;
property ReadOnly;
//property Rtf: string read GetRTF write SetRTF;
property ScrollBars;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property WantReturns;
property WantTabs;
property WordWrap;
//property ZoomFactor;
end;
implementation
procedure SafeFillChar(out x; ASize: SizeInt);
begin
FillChar(x, ASize, #0);
end;
{ TParaAttributes }
function TParaAttributes.DoGetParaMetric: TParaMetric;
begin
FillChar(Result, SizeOf(Result), #0);
FOwner.GetParaMetric(FOwner.SelStart, Result);
end;
function TParaAttributes.GetAlignment: TAlignment;
begin
Result := TAlignment(RichMemoHelpers.TParaAttributes(TObject(FOwner)).Alignment);
//Result := TAlignment(FOwner.GetParaAlignment(FOwner.SelStart));
end;
function TParaAttributes.GetFirstIndent: Integer;
begin
Result := RichMemoHelpers.TParaAttributes(TObject(FOwner)).FirstIndent;
//Result := Trunc(DoGetParaMetric.FirstLine);
end;
function TParaAttributes.GetLeftIndent: Integer;
begin
Result := RichMemoHelpers.TParaAttributes(TObject(FOwner)).LeftIndent;
end;
function TParaAttributes.GetNumbering: TNumberingStyle;
begin
Result := nsNone;
end;
function TParaAttributes.GetRightIndent: Integer;
begin
Result := RichMemoHelpers.TParaAttributes(TObject(FOwner)).RightIndent;
end;
function TParaAttributes.GetTab(Index: Byte): Longint;
begin
Result := RichMemoHelpers.TParaAttributes(TObject(FOwner)).Tab[Index];
end;
function TParaAttributes.GetTabCount: Integer;
begin
Result := RichMemoHelpers.TParaAttributes(TObject(FOwner)).TabCount;
end;
procedure TParaAttributes.SetAlignment(AValue: TAlignment);
begin
RichMemoHelpers.TParaAttributes(TObject(FOwner)).Alignment := RichMemoHelpers.TRichEditAlignment(AValue);
// TAlignment = (taLeftJustify, taRightJustify, taCenter);
end;
procedure TParaAttributes.SetFirstIndent(AValue: Integer);
begin
RichMemoHelpers.TParaAttributes(TObject(FOwner)).FirstIndent:=AValue;
end;
procedure TParaAttributes.SetLeftIndent(AValue: Integer);
begin
RichMemoHelpers.TParaAttributes(TObject(FOwner)).LeftIndent:=AValue;
end;
procedure TParaAttributes.SetNumbering(AValue: TNumberingStyle);
begin
end;
procedure TParaAttributes.SetRightIndent(AValue: Integer);
begin
RichMemoHelpers.TParaAttributes(TObject(FOwner)).RightIndent:=AValue;
end;
procedure TParaAttributes.SetTab(Index: Byte; AValue: Longint);
begin
RichMemoHelpers.TParaAttributes(TObject(FOwner)).Tab[Index] := AValue;
end;
procedure TParaAttributes.SetTabCount(AValue: Integer);
begin
RichMemoHelpers.TParaAttributes(TObject(FOwner)).TabCount:=AValue;
end;
constructor TParaAttributes.Create(AOwner: TRichMemo);
begin
inherited Create;
FOwner := AOwner;
end;
procedure TParaAttributes.Assign(Source: TPersistent);
begin
inherited Assign(Source);
end;
{ TTextAttributes }
function TTextAttributes.DoGetAttrs: TFontParams;
begin
SafeFillChar(Result, SizeOf(Result));
FOwner.GetTextAttributes(FOwner.SelStart, Result);
end;
function TTextAttributes.GetCharset: TFontCharset;
begin
Result := 0;
//if FType = atDefaultText then
//Result := FOwner.GetTextAttributes();
end;
function TTextAttributes.GetColor: TColor;
begin
Result := DoGetAttrs.Color;
end;
function TTextAttributes.GetHeight: Integer;
begin
Result := 0;
end;
function TTextAttributes.GetName: string;
begin
Result := DoGetAttrs.Name;
end;
function TTextAttributes.GetPitch: TFontPitch;
begin
Result := fpDefault;
end;
function TTextAttributes.GetSize: Integer;
begin
Result := DoGetAttrs.Size;
end;
function TTextAttributes.GetStyle: TFontStyles;
begin
Result := DoGetAttrs.Style;
end;
procedure TTextAttributes.SetCharset(AValue: TFontCharset);
begin
if FType = atDefaultText then
FOwner.SetTextAttributes(FOwner.SelStart, FOwner.SelLength, FOwner.Font)
end;
procedure TTextAttributes.SetColor(AValue: TColor);
begin
if FType = atDefaultText then
FOwner.SetTextAttributes(FOwner.SelStart, FOwner.SelLength, FOwner.Font)
else
FOwner.SetRangeColor(FOwner.SelStart, FOwner.SelLength, AValue);
end;
procedure TTextAttributes.SetHeight(AValue: Integer);
begin
if FType = atDefaultText then
FOwner.SetTextAttributes(FOwner.SelStart, FOwner.SelLength, FOwner.Font)
end;
procedure TTextAttributes.SetName(AValue: string);
begin
if FType = atDefaultText then
FOwner.SetTextAttributes(FOwner.SelStart, FOwner.SelLength, FOwner.Font)
else
FOwner.SetRangeParams(FOwner.SelStart, FOwner.SelLength, [tmm_Name], AValue, 0, 0, [], []);
end;
procedure TTextAttributes.SetPitch(AValue: TFontPitch);
begin
if FType = atDefaultText then
FOwner.SetTextAttributes(FOwner.SelStart, FOwner.SelLength, FOwner.Font)
end;
procedure TTextAttributes.SetSize(AValue: Integer);
begin
if FType = atDefaultText then
FOwner.SetTextAttributes(FOwner.SelStart, FOwner.SelLength, FOwner.Font)
else
FOwner.SetRangeParams(FOwner.SelStart, FOwner.SelLength, [tmm_Size], '', AValue, 0, [], []);
end;
procedure TTextAttributes.SetStyle(AValue: TFontStyles);
begin
if FType = atDefaultText then
FOwner.SetTextAttributes(FOwner.SelStart, FOwner.SelLength, FOwner.Font)
else
FOwner.SetRangeParams(FOwner.SelStart, FOwner.SelLength, [tmm_Styles], '', 0, 0, AValue, []);
end;
constructor TTextAttributes.Create(AOwner: TRichMemo; AType: TAttributeType);
begin
inherited Create;
FOwner := AOwner;
FType := AType;
end;
procedure TTextAttributes.Assign(Source: TPersistent);
begin
inherited Assign(Source);
end;
{ TRichEdit }
function TRichEdit.GetZoom: Integer;
begin
Result := Trunc(ZoomFactor);
end;
procedure TRichEdit.SetDefAttributes(AValue: TTextAttributes);
begin
if FDefAttributes=AValue then Exit;
FDefAttributes:=AValue;
end;
procedure TRichEdit.SetSelAttributes(AValue: TTextAttributes);
begin
if FSelAttributes=AValue then Exit;
FSelAttributes:=AValue;
end;
procedure TRichEdit.SetZoom(AValue: Integer);
begin
ZoomFactor := AValue;
end;
constructor TRichEdit.Create(AOnwer: TComponent);
begin
inherited Create(AOnwer);
FDefAttributes := TTextAttributes.Create(Self, atDefaultText);
FParagraph := TParaAttributes.Create(Self);
FSelAttributes := TTextAttributes.Create(Self, atSelected);
end;
destructor TRichEdit.Destroy;
begin
FSelAttributes.Free;
FParagraph.Free;
FDefAttributes.Free;
inherited Destroy;
end;
function TRichEdit.FindText(ASearchStr: string; AStartPos: Integer;
ALength: Integer; AOptions: TSearchTypes): Integer;
begin
Result := Search(ASearchStr, AStartPos, ALength, AOptions);
end;
end.