-
Notifications
You must be signed in to change notification settings - Fork 41
/
ES.Layouts.pas
354 lines (320 loc) · 10.2 KB
/
ES.Layouts.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
{******************************************************************************}
{ }
{ EsVclComponents/EsVclCore v4.6 }
{ errorsoft(c) 2009-2024 }
{ }
{ More beautiful things: errorsoft.org }
{ }
{ errorsoft@mail.ru | github.com/errorcalc | habrahabr.ru/user/error1024 }
{ You can write to me in the Telegram messenger: @errorsoft }
{ }
{ Star me github: github.com/errorcalc/FreeEsVclComponents }
{ }
{ You can order developing vcl/fmx components, }
{ please submit your requests to mail or telegram. }
{ }
{******************************************************************************}
unit ES.Layouts;
{$I EsDefines.inc}
{$SCOPEDENUMS ON}
interface
uses
Winapi.Messages, Vcl.Controls, System.Classes, System.Types, Vcl.Graphics, ES.BaseControls,
ES.CfxClasses;
type
TEsCustomLayout = class(TEsBaseLayout)
private
FLocked: Boolean;
procedure CMIsToolControl(var Message: TMessage); message CM_ISTOOLCONTROL;
protected
procedure CreateParams(var Params: TCreateParams); override;
property UseDockManager default True;
public
constructor Create(AOwner: TComponent); override;
property Color default clBtnFace;
property DockManager;
property IsDrawHelper default True;
property Locked: Boolean read FLocked write FLocked default False;
end;
TEsLayout = class(TEsCustomLayout)
published
property Align;
property Anchors;
property AutoSize;
property BiDiMode;
property BorderWidth;
property BufferedChildren;// TEsCustomControl
property Color;
property Constraints;
property Ctl3D;
property UseDockManager;
property DockSite;
property DoubleBuffered;
{$IFDEF VER360UP}
property DoubleBufferedMode;
{$ENDIF}
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property IsCachedBuffer;// TEsCustomControl
property IsCachedBackground;// TEsCustomControl
property IsDrawHelper;// TEsCustomControl
property IsOpaque;// TEsCustomControl
property IsFullSizeBuffer;// TEsCustomControl
property Locked;
property Padding;
property ParentBiDiMode;
property ParentBackground;
property ParentBufferedChildren;// TEsCustomControl
property ParentColor;
property ParentCtl3D;
property ParentDoubleBuffered;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Touch;
property Visible;
{$IFDEF VER240UP}
property StyleElements;
{$ENDIF}
{$IFDEF VER340UP}
property StyleName;
{$ENDIF}
property OnAlignInsertBefore;
property OnAlignPosition;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGesture;
property OnGetSiteInfo;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnResize;
property OnPaint;// TEsCustomControl
property OnPainting;// TEsCustomControl
property OnStartDock;
property OnStartDrag;
property OnUnDock;
end;
TEsPanel = class(TEsLayout)
private
FFrameWidth: TFrameWidth;
FFrameColor: TColor;
FFrameStyle: TFrameStyle;
FCaptionVisible: Boolean;
FCaptionVertLayout: TVertLayout;
FCaptionHorzLayout: THorzLayout;
FCaptionDistance: Integer;
procedure SetFrameColor(const Value: TColor);
procedure SetFrameStyle(const Value: TFrameStyle);
procedure SetFrameWidth(const Value: TFrameWidth);
procedure SetCaptionVisible(const Value: Boolean);
procedure SetCaptionHorzLayout(const Value: THorzLayout);
procedure SetCaptionVertLayout(const Value: TVertLayout);
procedure SetCaptionDistance(const Value: Integer);
protected
procedure Paint; override;
procedure AdjustClientRect(var Rect: TRect); override;
procedure AdjustContentRect(var Rect: TRect); override;
procedure UpdateText; override;
public
constructor Create(AOwner: TComponent); override;
published
property Caption;
property CaptionVertLayout: TVertLayout read FCaptionVertLayout write
SetCaptionVertLayout default TVertLayout.Center;
property CaptionHorzLayout: THorzLayout read FCaptionHorzLayout write
SetCaptionHorzLayout default THorzLayout.Center;
property CaptionVisible: Boolean read FCaptionVisible write SetCaptionVisible default True;
property CaptionDistance: Integer read FCaptionDistance write SetCaptionDistance default 2;
property BevelKind;
property BevelInner;
property BevelOuter;
property FrameStyle: TFrameStyle read FFrameStyle write SetFrameStyle default TExFrameStyle.Raised;
property FrameColor: TColor read FFrameColor write SetFrameColor default clBtnShadow;
property FrameWidth: TFrameWidth read FFrameWidth write SetFrameWidth default 1;
property IsDrawHelper default False;
end;
implementation
uses
Winapi.Windows, ES.ExGraphics, ES.Utils, Vcl.Themes;
procedure TEsCustomLayout.CMIsToolControl(var Message: TMessage);
begin
if not FLocked then
Message.Result := 1;
end;
constructor TEsCustomLayout.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
csSetCaption, csParentBackground, csDoubleClicks, csReplicatable, csPannable, csGestures];
Width := 185;
Height := 41;
UseDockManager := True;
IsDrawHelper := True;
end;
procedure TEsCustomLayout.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
// nope now
end;
{ TEsPanel }
procedure TEsPanel.AdjustClientRect(var Rect: TRect);
begin
inherited;
if FrameStyle <> TExFrameStyle.None then
begin
Rect.Inflate(-GetFrameWidth(FrameStyle, FrameWidth), -GetFrameWidth(FrameStyle, FrameWidth));
end;
end;
procedure TEsPanel.AdjustContentRect(var Rect: TRect);
begin
inherited;
if FrameStyle <> TExFrameStyle.None then
begin
Rect.Inflate(-GetFrameWidth(FrameStyle, FrameWidth), -GetFrameWidth(FrameStyle, FrameWidth));
end;
end;
constructor TEsPanel.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle - [csSetCaption];
FFrameColor := clBtnShadow;
FFrameWidth := 1;
FFrameStyle := TExFrameStyle.Raised;
FCaptionVertLayout := TVertLayout.Center;
FCaptionHorzLayout := THorzLayout.Center;
FCaptionDistance := 2;
FCaptionVisible := True;
IsDrawHelper := False;
end;
procedure TEsPanel.Paint;
const
HorzLayout: array[THorzLayout] of Integer = (DT_LEFT, DT_CENTER, DT_RIGHT);
VertLayout: array[TVertLayout] of Integer = (DT_TOP, DT_VCENTER, DT_BOTTOM);
var
TextFlags: Integer;
R: TRect;
begin
(* {$ifdef VER240UP}
if (seClient in Control.StyleElements) then
begin
FillBackground(Canvas.Handle);
end;
{$endif}*)
if FCaptionVisible then
begin
TextFlags := DT_SINGLELINE or HorzLayout[CaptionHorzLayout] or VertLayout[CaptionVertLayout];
TextFlags := DrawTextBiDiModeFlags(TextFlags);
R := ContentRect;
// fix text bounds
if CaptionVertLayout <> TVertLayout.Center then
if CaptionVertLayout = TVertLayout.Top then
R.Top := R.Top + CaptionDistance
else
R.Bottom := R.Bottom - CaptionDistance;
if CaptionHorzLayout <> THorzLayout.Center then
if CaptionHorzLayout = THorzLayout.Left then
R.Left := R.Left + CaptionDistance
else
R.Right := R.Right - CaptionDistance;
Canvas.Font := Font;
Canvas.Font.Color := FontColorToRgb(Font.Color, Self);
Canvas.Brush.Style := bsClear;
DrawText(Canvas.Handle, Caption, -1, R, TextFlags);
end;
if (csDesigning in ComponentState) and IsDrawHelper then
DrawControlHelper(Self, [hoPadding, hoClientRect], GetFrameWidth(FrameStyle, FrameWidth));
if FrameStyle <> TExFrameStyle.None then
DrawFrame(Canvas, Self, ClientRect, FrameStyle, FrameWidth,
FrameColor, clBtnHighlight, clBtnShadow, True);
end;
procedure TEsPanel.SetCaptionDistance(const Value: Integer);
begin
if (FCaptionDistance <> Value) and (Value >= 0) then
begin
FCaptionDistance := Value;
if FCaptionVisible then
Invalidate;
end;
end;
procedure TEsPanel.SetCaptionHorzLayout(const Value: THorzLayout);
begin
if FCaptionHorzLayout <> Value then
begin
FCaptionHorzLayout := Value;
if FCaptionVisible then
Invalidate;
end;
end;
procedure TEsPanel.SetCaptionVertLayout(const Value: TVertLayout);
begin
if FCaptionVertLayout <> Value then
begin
FCaptionVertLayout := Value;
if FCaptionVisible then
Invalidate;
end;
end;
procedure TEsPanel.SetFrameColor(const Value: TColor);
begin
if FFrameColor <> Value then
begin
FFrameColor := Value;
Invalidate;
end;
end;
procedure TEsPanel.SetFrameStyle(const Value: TFrameStyle);
begin
if FFrameStyle <> Value then
begin
FFrameStyle := Value;
Realign;
Invalidate;
end;
end;
procedure TEsPanel.SetFrameWidth(const Value: TFrameWidth);
begin
if FFrameWidth <> Value then
begin
FFrameWidth := Value;
Realign;
Invalidate;
end;
end;
procedure TEsPanel.SetCaptionVisible(const Value: Boolean);
begin
if FCaptionVisible <> Value then
begin
FCaptionVisible := Value;
Invalidate;
end;
end;
procedure TEsPanel.UpdateText;
begin
if FCaptionVisible then
Invalidate;
end;
end.