File: dockedgrip.pas

package info (click to toggle)
lazarus 4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 275,760 kB
  • sloc: pascal: 2,341,904; xml: 509,420; makefile: 348,726; cpp: 93,608; sh: 3,387; java: 609; perl: 297; sql: 222; ansic: 137
file content (658 lines) | stat: -rw-r--r-- 19,504 bytes parent folder | download | duplicates (2)
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
{
 *****************************************************************************
  See the file COPYING.modifiedLGPL.txt, included in this distribution,
  for details about the license.
 *****************************************************************************

 Author: Michael W. Vogel

 Grips:                 1
                0 +-----+-----+ 2
                  |           |
                7 +           + 3
                  |           |
                6 +-----+-----+ 4
                        5

 ResizeGrips:  Only grips 3, 4, and 5 are used for sizing

 ResizeBars:         0     1
                  +-----+-----+
                7 |           | 2
                  +           +
                6 |           | 3
                  +-----+-----+
                     5     4
 Only bars 2, 3, 4, and 5 are used for sizing

 ResizeContainer is just a container for without any logic.
 Logic is added in ResizeControl

}

unit DockedGrip;

{$mode objfpc}{$H+}

interface

uses
  // RTL, FCL
  Classes, SysUtils, math,
  // LCL
  Controls, ExtCtrls, Graphics, Menus;

type

  { TGrip }

  TGrip = class(TPanel)
  private
    FActivated: Boolean;
    FShape: TShape;
    procedure SetActivated(AValue: Boolean);
  public
    constructor Create(TheOwner: TComponent); override;
  public
    property Activated: Boolean read FActivated write SetActivated;
  end;

  { TBar }

  TBar = class(TPanel)
  private
    FActivated: Boolean;
  public
    constructor Create(TheOwner: TComponent); override;
  public
    property Activated: Boolean read FActivated write FActivated;
  end;

  { TCustomGrips }

  TCustomGrips = class
  private const
    GRIP_SIZE = 8;
  private
    FGrip: array[0..7] of TGrip;
    FGripSize: Integer;
    FOnMouseDown: TMouseEvent;
    FOnMouseMove: TMouseMoveEvent;
    FOnMouseUp: TMouseEvent;
    FParent: TWinControl;
    function  GetGrip(AIndex: Integer): TGrip;
    function  GetPopupMenu: TPopupMenu;
    procedure InitGrip(AGrip: TGrip; ACursor: TCursor; Activated: Boolean);
    procedure SetOnMouseDown(AValue: TMouseEvent);
    procedure SetOnMouseMove(AValue: TMouseMoveEvent);
    procedure SetOnMouseUp(AValue: TMouseEvent);
    procedure SetParent(AValue: TWinControl);
    procedure SetPopupMenu(AValue: TPopupMenu);
  protected
    procedure InitGrips; virtual; abstract;
  public
    constructor Create;
    destructor Destroy; override;
    procedure BringToFront;
    procedure Hide;
    procedure SetBounds(ARect: TRect);
  public
    property GripSize: Integer read FGripSize;
    property GripTopLeft:      TGrip index 0 read GetGrip;
    property GripTopCenter:    TGrip index 1 read GetGrip;
    property GripTopRight:     TGrip index 2 read GetGrip;
    property GripCenterRight:  TGrip index 3 read GetGrip;
    property GripBottomRight:  TGrip index 4 read GetGrip;
    property GripBottomCenter: TGrip index 5 read GetGrip;
    property GripBottomLeft:   TGrip index 6 read GetGrip;
    property GripCenterLeft:   TGrip index 7 read GetGrip;
    property OnMouseDown: TMouseEvent read FOnMouseDown write SetOnMouseDown;
    property OnMouseMove: TMouseMoveEvent read FOnMouseMove write SetOnMouseMove;
    property OnMouseUp: TMouseEvent read FOnMouseUp write SetOnMouseUp;
    property Parent: TWinControl read FParent write SetParent;
    property PopupMenu: TPopupMenu read GetPopupMenu write SetPopupMenu;
  end;

  { TAnchorGrips }

  TAnchorGrips = class(TCustomGrips)
  private
    FBackGround: TWinControl;
    function  CalculateRect(AControl: TControl): TRect;
  protected
    procedure InitGrips; override;
  public
    procedure AdjustGrips(AControl: TControl);
  public
    property BackGround: TWinControl read FBackGround write FBackGround;
  end;

  { TResizeGrips }

  TResizeGrips = class(TCustomGrips)
  protected
    procedure InitGrips; override;
  end;

  { TResizeBars }

  TResizeBars = class
  private const
    BAR_SIZE = 8;
  private
    FBar: array[0..7] of TBar;
    FBarSize: Integer;
    FOnMouseDown: TMouseEvent;
    FOnMouseMove: TMouseMoveEvent;
    FOnMouseUp: TMouseEvent;
    FOnPaint: TNotifyEvent;
    FParent: TWinControl;
    function  GetBar(AIndex: Integer): TBar;
    function  GetPopupMenu: TPopupMenu;
    procedure InitBar(ABar: TBar; ACursor: TCursor; Activated: Boolean);
    procedure SetOnMouseDown(AValue: TMouseEvent);
    procedure SetOnMouseMove(AValue: TMouseMoveEvent);
    procedure SetOnMouseUp(AValue: TMouseEvent);
    procedure SetOnPaint(AValue: TNotifyEvent);
    procedure SetParent(AValue: TWinControl);
    procedure SetPopupMenu(AValue: TPopupMenu);
  protected
    procedure InitBars;
  public
    constructor Create;
    destructor Destroy; override;
    procedure SetBounds(ARect: TRect);
  public
    property BarSize: Integer read FBarSize;
    property BarTopLeft:     TBar index 0 read GetBar;
    property BarTopRight:    TBar index 1 read GetBar;
    property BarRightTop:    TBar index 2 read GetBar;
    property BarRightBottom: TBar index 3 read GetBar;
    property BarBottomRight: TBar index 4 read GetBar;
    property BarBottomLeft:  TBar index 5 read GetBar;
    property BarLeftBottom:  TBar index 6 read GetBar;
    property BarLeftTop:     TBar index 7 read GetBar;
    property OnMouseDown: TMouseEvent read FOnMouseDown write SetOnMouseDown;
    property OnMouseMove: TMouseMoveEvent read FOnMouseMove write SetOnMouseMove;
    property OnMouseUp: TMouseEvent read FOnMouseUp write SetOnMouseUp;
    property OnPaint: TNotifyEvent read FOnPaint write SetOnPaint;
    property Parent: TWinControl read FParent write SetParent;
    property PopupMenu: TPopupMenu read GetPopupMenu write SetPopupMenu;
  end;

  { TResizeFormContainer }

  TResizeFormContainer = class(TWinControl)
  protected
    procedure AlignControls(AControl: TControl; var RemainingClientRect: TRect); override;
  end;

  { TResizeContainer }

  TResizeContainer = class(TComponent)
  private
    FAnchorContainer: TWinControl;
    FBoundsRect: TRect;
    FFakeMenu: TCustomControl;
    FFormClient: TWinControl;
    FFormContainer: TResizeFormContainer;
    FParent: TWinControl;
    FResizeBars: TResizeBars;
    FResizeGrips: TResizeGrips;
  public
    constructor Create(AWinControl: TWinControl); reintroduce;
    destructor Destroy; override;
    function  IsHorzSizer(AObject: TObject): Boolean;
    function  IsVertSizer(AObject: TObject): Boolean;
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
  public
    property AnchorContainer: TWinControl read FAnchorContainer;
    property BoundsRect: TRect read FBoundsRect;
    property FakeMenu: TCustomControl read FFakeMenu;
    property FormClient: TWinControl read FFormClient;
    property FormContainer: TResizeFormContainer read FFormContainer;
    property Parent: TWinControl read FParent;
    property ResizeBars: TResizeBars read FResizeBars;
    property ResizeGrips: TResizeGrips read FResizeGrips;
  end;

implementation

{ TGrip }

procedure TGrip.SetActivated(AValue: Boolean);
begin
  if FActivated = AValue then Exit;
  FActivated := AValue;
  if AValue then
    FShape.Brush.Color := clBtnFace
  else
    FShape.Brush.Color := clGray;
end;

constructor TGrip.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  BevelOuter := bvNone;
  Color := clBlack;
  SetInitialBounds(0, 0, 8, 8);
  FActivated := False;

  FShape := TShape.Create(Self);
  FShape.Align := alClient;
  FShape.Brush.Color := clGray;
  FShape.Enabled := False;
  FShape.Parent := Self;
end;

{ TBar }

constructor TBar.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  BevelOuter := bvNone;
  Color := clWindow;
  SetInitialBounds(0, 0, 8, 8);
  FActivated := False;
end;

{ TCustomGrips }

function TCustomGrips.GetGrip(AIndex: Integer): TGrip;
begin
  Result := FGrip[AIndex];
end;

function TCustomGrips.GetPopupMenu: TPopupMenu;
begin
  Result := FGrip[0].PopupMenu;
end;

procedure TCustomGrips.InitGrip(AGrip: TGrip; ACursor: TCursor; Activated: Boolean);
begin
  AGrip.Parent := FParent;
  AGrip.Cursor := ACursor;
  AGrip.Activated := Activated;
end;

procedure TCustomGrips.SetOnMouseDown(AValue: TMouseEvent);
var
  i: Integer;
begin
  if FOnMouseDown = AValue then Exit;
  FOnMouseDown := AValue;
  for i := 0 to 7 do
    if FGrip[i].Activated then
      FGrip[i].OnMouseDown := AValue;
end;

procedure TCustomGrips.SetOnMouseMove(AValue: TMouseMoveEvent);
var
  i: Integer;
begin
  if FOnMouseMove = AValue then Exit;
  FOnMouseMove := AValue;
  for i := 0 to 7 do
    if FGrip[i].Activated then
      FGrip[i].OnMouseMove := AValue;
end;

procedure TCustomGrips.SetOnMouseUp(AValue: TMouseEvent);
var
  i: Integer;
begin
  if FOnMouseUp = AValue then Exit;
  FOnMouseUp := AValue;
  for i := 0 to 7 do
    if FGrip[i].Activated then
      FGrip[i].OnMouseUp := AValue;
end;

procedure TCustomGrips.SetParent(AValue: TWinControl);
var
  i: Integer;
begin
  if FParent = AValue then Exit;
  FParent := AValue;
  for i := 0 to 7 do
    FGrip[i].Parent := AValue;
end;

procedure TCustomGrips.SetPopupMenu(AValue: TPopupMenu);
var
  i: Integer;
begin
  if GetPopupMenu = AValue then Exit;
  for i := 0 to 7 do
    if FGrip[i].Activated then
      FGrip[i].PopupMenu := AValue;
end;

constructor TCustomGrips.Create;
var
  i: Integer;
begin
  FGripSize := ScaleX(GRIP_SIZE, 96);
  for i := 0 to 7 do
    FGrip[i] := TGrip.Create(nil);
  InitGrips;
end;

destructor TCustomGrips.Destroy;
var
  i: Integer;
begin
  for i := 7 downto 0 do
    FGrip[i].Free;
  inherited Destroy;
end;

procedure TCustomGrips.BringToFront;
var
  i: Integer;
begin
  for i := 0 to 7 do
  begin
    FGrip[i].Visible := True;
    FGrip[i].BringToFront;
  end;
end;

procedure TCustomGrips.Hide;
var
  i: Integer;
begin
  for i := 0 to 7 do
    FGrip[i].Visible := False;
end;

procedure TCustomGrips.SetBounds(ARect: TRect);
var
  LMiddleLeft, LMiddleTop: Integer;
begin
  if not Assigned(FParent) then Exit;
  LMiddleLeft := (ARect.Left + ARect.Right - GripSize) div 2;
  LMiddleTop := (ARect.Top + ARect.Bottom - GripSize) div 2;
  FGrip[0].SetBounds(ARect.Left, ARect.Top, GripSize, GripSize);
  FGrip[1].SetBounds(LMiddleLeft, ARect.Top, GripSize, GripSize);
  FGrip[2].SetBounds(ARect.Right - GripSize, ARect.Top, GripSize, GripSize);
  FGrip[3].SetBounds(ARect.Right - GripSize, LMiddleTop, GripSize, GripSize);
  FGrip[4].SetBounds(ARect.Right - GripSize, ARect.Bottom - GripSize, GripSize, GripSize);
  FGrip[5].SetBounds(LMiddleLeft, ARect.Bottom - GripSize, GripSize, GripSize);
  FGrip[6].SetBounds(ARect.Left, ARect.Bottom - GripSize, GripSize, GripSize);
  FGrip[7].SetBounds(ARect.Left, LMiddleTop, GripSize, GripSize);
end;

{ TAnchorGrips }

function TAnchorGrips.CalculateRect(AControl: TControl): TRect;
var
  LTopLeft, LBottomRight: TPoint;
  LGripOffset: Integer;
begin
  Result := Rect(0, 0, BackGround.Width, BackGround.Height);
  if not Assigned(AControl) then Exit;
  if AControl = BackGround then Exit;

  // grip in middle of rect border is default, if to small, use dynamic offset
  LGripOffset := Max(GripSize div 2, (GripSize * 10 - AControl.Width) div 10);
  LTopLeft.x := -LGripOffset;
  LBottomRight.x := AControl.Width + LGripOffset;

  LGripOffset := Max(GripSize div 2, (GripSize * 10 - AControl.Height) div 10);
  LTopLeft.y := -LGripOffset;
  LBottomRight.y := AControl.Height + LGripOffset;

  LTopLeft     := AControl.ClientToParent(LTopLeft, BackGround);
  LBottomRight := AControl.ClientToParent(LBottomRight, BackGround);
  LTopLeft.x := Max(LTopLeft.x, 0);
  LTopLeft.y := Max(LTopLeft.y, 0);
  LBottomRight.x := Min(LBottomRight.x, BackGround.Width);
  LBottomRight.y := Min(LBottomRight.y, BackGround.Height);
  Result := Rect(LTopLeft.x, LTopLeft.y, LBottomRight.x, LBottomRight.y);
end;

procedure TAnchorGrips.InitGrips;
begin
  // on mac there is no cursor for crNWSE ( https://bugs.freepascal.org/view.php?id=32194#c101876 )
  InitGrip(GripTopLeft,      {$IFDEF MACOS}crSizeAll{$ELSE}crSizeNWSE{$ENDIF}, True);
  InitGrip(GripTopCenter,    crSizeNS                                        , True);
  InitGrip(GripTopRight,     {$IFDEF MACOS}crSizeAll{$ELSE}crSizeNESW{$ENDIF}, True);
  InitGrip(GripCenterRight,  crSizeWE                                        , True);
  InitGrip(GripBottomRight,  {$IFDEF MACOS}crSizeAll{$ELSE}crSizeNWSE{$ENDIF}, True);
  InitGrip(GripBottomCenter, crSizeNS                                        , True);
  InitGrip(GripBottomLeft,   {$IFDEF MACOS}crSizeAll{$ELSE}crSizeNESW{$ENDIF}, True);
  InitGrip(GripCenterLeft,   crSizeWE                                        , True);
end;

procedure TAnchorGrips.AdjustGrips(AControl: TControl);
var
  LRect: TRect;
begin
  if not Assigned(AControl) then
  begin
    Hide;
    Exit;
  end;

  AControl.BringToFront;
  LRect := CalculateRect(AControl);
  SetBounds(LRect);
  BringToFront;
end;

{ TResizeGrips }

procedure TResizeGrips.InitGrips;
begin
  InitGrip(GripTopLeft,      crDefault                                       , False);
  InitGrip(GripTopCenter,    crDefault                                       , False);
  InitGrip(GripTopRight,     crDefault                                       , False);
  InitGrip(GripCenterRight,  crSizeWE                                        , True);
  InitGrip(GripBottomRight,  {$IFDEF MACOS}crSizeAll{$ELSE}crSizeNWSE{$ENDIF}, True);
  InitGrip(GripBottomCenter, crSizeNS                                        , True);
  InitGrip(GripBottomLeft,   crDefault                                       , False);
  InitGrip(GripCenterLeft,   crDefault                                       , False);
end;

{ TResizeBars }

function TResizeBars.GetBar(AIndex: Integer): TBar;
begin
  Result := FBar[AIndex];
end;

function TResizeBars.GetPopupMenu: TPopupMenu;
begin
  Result := FBar[0].PopupMenu;
end;

procedure TResizeBars.InitBar(ABar: TBar; ACursor: TCursor; Activated: Boolean);
begin
  ABar.Parent := FParent;
  ABar.Cursor := ACursor;
  ABar.Activated := Activated;
end;

procedure TResizeBars.SetOnMouseDown(AValue: TMouseEvent);
var
  i: Integer;
begin
  if FOnMouseDown = AValue then Exit;
  FOnMouseDown := AValue;
  for i := 0 to 7 do
    if FBar[i].Activated then
      FBar[i].OnMouseDown := AValue;
end;

procedure TResizeBars.SetOnMouseMove(AValue: TMouseMoveEvent);
var
  i: Integer;
begin
  if FOnMouseMove = AValue then Exit;
  FOnMouseMove := AValue;
  for i := 0 to 7 do
    if FBar[i].Activated then
      FBar[i].OnMouseMove := AValue;
end;

procedure TResizeBars.SetOnMouseUp(AValue: TMouseEvent);
var
  i: Integer;
begin
  if FOnMouseUp = AValue then Exit;
  FOnMouseUp := AValue;
  for i := 0 to 7 do
    if FBar[i].Activated then
      FBar[i].OnMouseUp := AValue;
end;

procedure TResizeBars.SetOnPaint(AValue: TNotifyEvent);
var
  i: Integer;
begin
  if FOnPaint = AValue then Exit;
  FOnPaint := AValue;
  for i := 0 to 7 do
    FBar[i].OnPaint := AValue;
end;

procedure TResizeBars.SetParent(AValue: TWinControl);
var
  i: Integer;
begin
  if FParent = AValue then Exit;
  FParent := AValue;
  for i := 0 to 7 do
    FBar[i].Parent := AValue;
end;

procedure TResizeBars.SetPopupMenu(AValue: TPopupMenu);
var
  i: Integer;
begin
  if GetPopupMenu = AValue then Exit;
  for i := 0 to 7 do
    if FBar[i].Activated then
      FBar[i].PopupMenu := AValue;
end;

procedure TResizeBars.InitBars;
begin
  InitBar(BarTopLeft,      crDefault, False);
  InitBar(BarTopRight,     crDefault, False);
  InitBar(BarRightTop,     crSizeWE,  True);
  InitBar(BarRightBottom,  crSizeWE,  True);
  InitBar(BarBottomRight,  crSizeNS,  True);
  InitBar(BarBottomLeft,   crSizeNS,  True);
  InitBar(BarLeftBottom,   crDefault, False);
  InitBar(BarLeftTop,      crDefault, False);
end;

constructor TResizeBars.Create;
var
  i: Integer;
begin
  FBarSize := ScaleX(BAR_SIZE, 96);
  for i := 0 to 7 do
    FBar[i] := TBar.Create(nil);
  InitBars;
end;

destructor TResizeBars.Destroy;
var
  i: Integer;
begin
  for i := 7 downto 0 do
    FBar[i].Free;
  inherited Destroy;
end;

procedure TResizeBars.SetBounds(ARect: TRect);
var
  LMiddleLeft, LMiddleTop: Integer;
begin
  if not Assigned(FParent) then Exit;
  LMiddleLeft := (ARect.Left + ARect.Right - BarSize) div 2;
  LMiddleTop := (ARect.Top + ARect.Bottom - BarSize) div 2;
  FBar[0].SetBounds(ARect.Left + BarSize, ARect.Top, LMiddleLeft - ARect.Left - BarSize, BarSize);
  FBar[1].SetBounds(LMiddleLeft + BarSize, ARect.Top, ARect.Right - LMiddleLeft - BarSize * 2, BarSize);
  FBar[2].SetBounds(ARect.Right - BarSize, ARect.Top + BarSize, BarSize, LMiddleTop - ARect.Top - BarSize);
  FBar[3].SetBounds(ARect.Right - BarSize, LMiddleTop + BarSize, BarSize, ARect.Bottom - LMiddleTop - BarSize * 2);
  FBar[4].SetBounds(LMiddleLeft + BarSize, ARect.Bottom - BarSize, ARect.Right - LMiddleLeft - BarSize * 2, BarSize);
  FBar[5].SetBounds(ARect.Left + BarSize, ARect.Bottom - BarSize, LMiddleLeft - ARect.Left - BarSize, BarSize);
  FBar[6].SetBounds(ARect.Left, LMiddleTop + BarSize, BarSize, ARect.Bottom - LMiddleTop - BarSize * 2);
  FBar[7].SetBounds(ARect.Left, ARect.Top + BarSize, BarSize, LMiddleTop - ARect.Top - BarSize);
end;

{ TResizeFormContainer }

procedure TResizeFormContainer.AlignControls(AControl: TControl; var RemainingClientRect: TRect);
begin
  // Do not align the form
end;

{ TResizeContainer }

constructor TResizeContainer.Create(AWinControl: TWinControl);
begin
  inherited Create(AWinControl);
  FParent := AWinControl;
  FBoundsRect := Rect(0, 0, 0, 0);

  FResizeGrips := TResizeGrips.Create;
  FResizeGrips.Parent := Parent;
  FResizeBars := TResizeBars.Create;
  FResizeBars.Parent := Parent;

  FFakeMenu := TCustomControl.Create(Parent);
  FFakeMenu.Height := 0;
  FFakeMenu.Parent := Parent;

  FFormClient := TWinControl.Create(Parent);
  FFormClient.ControlStyle:= FFormClient.ControlStyle + [csOpaque];
  FFormClient.Parent := Parent;

  FFormContainer := TResizeFormContainer.Create(FFormClient);
  FFormContainer.Parent := FFormClient;

  FAnchorContainer := TWinControl.Create(Parent);
  FAnchorContainer.Visible := False;
  FAnchorContainer.Parent := Parent;
end;

destructor TResizeContainer.Destroy;
begin
  FResizeBars.Free;
  FResizeGrips.Free;
  inherited Destroy;
end;

function TResizeContainer.IsHorzSizer(AObject: TObject): Boolean;
begin
  Result := (AObject = ResizeGrips.GripCenterRight) or
            (AObject = ResizeGrips.GripBottomRight) or
            (AObject = ResizeBars.BarRightTop) or
            (AObject = ResizeBars.BarRightBottom);
end;

function TResizeContainer.IsVertSizer(AObject: TObject): Boolean;
begin
  Result := (AObject = ResizeGrips.GripBottomCenter) or
            (AObject = ResizeGrips.GripBottomRight) or
            (AObject = ResizeBars.BarBottomLeft) or
            (AObject = ResizeBars.BarBottomRight);
end;

procedure TResizeContainer.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
  FBoundsRect := Rect(ALeft, ATop, ALeft + AWidth, ATop + AHeight);
  FResizeGrips.SetBounds(FBoundsRect);
  FResizeBars.SetBounds(FBoundsRect);
  FFakeMenu.SetBounds(ALeft + FResizeBars.BarSize, ATop + FResizeBars.BarSize, AWidth - FResizeBars.BarSize * 2, FFakeMenu.Height);
  FFormClient.SetBounds(ALeft + FResizeBars.BarSize, ATop + FResizeBars.BarSize + FFakeMenu.Height, AWidth - FResizeBars.BarSize * 2, AHeight - FResizeBars.BarSize * 2 - FFakeMenu.Height);
  FAnchorContainer.SetBounds(ALeft + FResizeBars.BarSize, ATop + FResizeBars.BarSize + FFakeMenu.Height, AWidth - FResizeBars.BarSize * 2, AHeight - FResizeBars.BarSize * 2 - FFakeMenu.Height);
end;

end.