1 | unit UCDManagerTabsPopup;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, Controls, SysUtils, ComCtrls, ExtCtrls, UCDCommon, UCDManager,
|
---|
9 | UCDManagerTabs, Forms, URectangle, UCDConjoinForm;
|
---|
10 |
|
---|
11 | type
|
---|
12 | { TCDAutoHide }
|
---|
13 |
|
---|
14 | TCDAutoHide = class
|
---|
15 | private
|
---|
16 | FDuration: Real;
|
---|
17 | FStepCount: Integer;
|
---|
18 | FTabPosition: TTabPosition;
|
---|
19 | ControlBounds: TRectangle;
|
---|
20 | HideBounds: TRectangle;
|
---|
21 | ShowBounds: TRectangle;
|
---|
22 | procedure SetDuration(const AValue: Real);
|
---|
23 | procedure SetStepCount(const AValue: Integer);
|
---|
24 | procedure UpdateBounds;
|
---|
25 | procedure UpdateTimerInterval;
|
---|
26 | public
|
---|
27 | Position: Real;
|
---|
28 | Direction: Integer;
|
---|
29 | Enable: Boolean;
|
---|
30 | Timer: TTimer;
|
---|
31 | Control: TControl;
|
---|
32 | ControlVisible: Boolean;
|
---|
33 | DoShow: Boolean;
|
---|
34 | procedure Hide;
|
---|
35 | procedure Show;
|
---|
36 | constructor Create;
|
---|
37 | destructor Destroy; override;
|
---|
38 | procedure TimerExecute(Sender: TObject);
|
---|
39 | property TabPosition: TTabPosition read FTabPosition write FTabPosition;
|
---|
40 | property Duration: Real read FDuration write SetDuration;
|
---|
41 | property StepCount: Integer read FStepCount write SetStepCount;
|
---|
42 | end;
|
---|
43 |
|
---|
44 | { TCDManagerTabsPopupItem }
|
---|
45 |
|
---|
46 | TCDManagerTabsPopupItem = class(TCDManagerTabsItem)
|
---|
47 | Hidden: Boolean;
|
---|
48 | constructor Create; override;
|
---|
49 | end;
|
---|
50 |
|
---|
51 | { TCDManagerTabsPopup }
|
---|
52 |
|
---|
53 | TCDManagerTabsPopup = class(TCDManagerTabs)
|
---|
54 | private
|
---|
55 | SplitterMouseDrag: Boolean;
|
---|
56 | SplitterMousePos: TPoint;
|
---|
57 | procedure PageControlResize(Sender: TObject);
|
---|
58 | procedure InsertControlNoUpdate(Control: TControl; InsertAt: TAlign); override;
|
---|
59 | procedure SplitterMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
60 | Shift: TShiftState; X, Y: Integer);
|
---|
61 | procedure SplitterMouseMove(Sender: TObject; Shift: TShiftState;
|
---|
62 | X, Y: Integer);
|
---|
63 | procedure SplitterMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
64 | Shift: TShiftState; X, Y: Integer);
|
---|
65 | procedure UpdatePopupFormBounds;
|
---|
66 | procedure TabControlChange(Sender: TObject); override;
|
---|
67 | procedure PopupFormMouseLeave(Sender: TObject);
|
---|
68 | public
|
---|
69 | AutoHideEnabled: Boolean;
|
---|
70 | AutoHide: TCDAutoHide;
|
---|
71 | PopupForm: TForm;
|
---|
72 | HeaderPanel: TCDPanelHeader;
|
---|
73 | Splitter: TPanel;
|
---|
74 | procedure RemoveControl(Control: TControl); override;
|
---|
75 | procedure SetHeaderPos(const AValue: THeaderPos); override;
|
---|
76 | procedure PinShowButtonClick(Sender: TObject);
|
---|
77 | procedure PinHideButtonClick(Sender: TObject);
|
---|
78 | constructor Create(ADockSite: TWinControl); override;
|
---|
79 | destructor Destroy; override;
|
---|
80 | end;
|
---|
81 |
|
---|
82 |
|
---|
83 | implementation
|
---|
84 |
|
---|
85 | uses
|
---|
86 | UCDClient, UCDManagerRegions;
|
---|
87 |
|
---|
88 | { TCDManagerTabsPopupItem }
|
---|
89 |
|
---|
90 | constructor TCDManagerTabsPopupItem.Create;
|
---|
91 | begin
|
---|
92 | inherited;
|
---|
93 | end;
|
---|
94 |
|
---|
95 | { TCDAutoHide }
|
---|
96 |
|
---|
97 | procedure TCDAutoHide.UpdateBounds;
|
---|
98 | begin
|
---|
99 | case TabPosition of
|
---|
100 | tpTop: begin
|
---|
101 | Control.SetBounds(ControlBounds.Left, ControlBounds.Top,
|
---|
102 | ControlBounds.Width, Round(ControlBounds.Height * Position));
|
---|
103 | end;
|
---|
104 | tpLeft: begin
|
---|
105 | Control.SetBounds(ControlBounds.Left, ControlBounds.Top,
|
---|
106 | Round(ControlBounds.Width * Position), ControlBounds.Height);
|
---|
107 | end;
|
---|
108 | tpRight: begin
|
---|
109 | Control.SetBounds(ControlBounds.Right -
|
---|
110 | Round(ControlBounds.Width * Position), ControlBounds.Top,
|
---|
111 | Round(ControlBounds.Width * Position), ControlBounds.Height);
|
---|
112 | end;
|
---|
113 | tpBottom: begin
|
---|
114 | Control.SetBounds(ControlBounds.Left,
|
---|
115 | ControlBounds.Bottom - Round(ControlBounds.Height * Position),
|
---|
116 | ControlBounds.Width, Round(ControlBounds.Height * Position));
|
---|
117 | end;
|
---|
118 | end;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TCDAutoHide.UpdateTimerInterval;
|
---|
122 | begin
|
---|
123 | Timer.Interval := Round(FDuration * 1000 / FStepCount);
|
---|
124 | end;
|
---|
125 |
|
---|
126 | procedure TCDAutoHide.SetDuration(const AValue: Real);
|
---|
127 | begin
|
---|
128 | if FDuration = AValue then Exit;
|
---|
129 | FDuration := AValue;
|
---|
130 | UpdateTimerInterval;
|
---|
131 | end;
|
---|
132 |
|
---|
133 | procedure TCDAutoHide.SetStepCount(const AValue: Integer);
|
---|
134 | begin
|
---|
135 | if FStepCount = AValue then Exit;
|
---|
136 | FStepCount := AValue;
|
---|
137 | UpdateTimerInterval;
|
---|
138 | end;
|
---|
139 |
|
---|
140 | procedure TCDAutoHide.Hide;
|
---|
141 | begin
|
---|
142 | HideBounds.AsTRect := Control.BoundsRect;
|
---|
143 | ControlBounds.Assign(HideBounds);
|
---|
144 | Control.Show;
|
---|
145 | Control.BringToFront;
|
---|
146 | Application.ProcessMessages;
|
---|
147 | Direction := -1;
|
---|
148 | Position := 1;
|
---|
149 | Timer.Enabled := True;
|
---|
150 | UpdateBounds;
|
---|
151 | end;
|
---|
152 |
|
---|
153 | procedure TCDAutoHide.Show;
|
---|
154 | begin
|
---|
155 | ShowBounds.AsTRect := Control.BoundsRect;
|
---|
156 | ControlBounds.Assign(HideBounds);
|
---|
157 | if Position > 0 then begin
|
---|
158 | DoShow := True;
|
---|
159 | Hide;
|
---|
160 | end else begin
|
---|
161 | //StartBounds := Bounds(0, 0, Control.UndockWidth, Control.UndockHeight);
|
---|
162 | Control.Show;
|
---|
163 | Control.BringToFront;
|
---|
164 | //Control.Align := alClient;
|
---|
165 | Direction := 1;
|
---|
166 | Position := 0;
|
---|
167 | Timer.Enabled := True;
|
---|
168 | UpdateBounds;
|
---|
169 | end;
|
---|
170 | end;
|
---|
171 |
|
---|
172 | constructor TCDAutoHide.Create;
|
---|
173 | begin
|
---|
174 | inherited;
|
---|
175 | ShowBounds := TRectangle.Create;
|
---|
176 | HideBounds := TRectangle.Create;
|
---|
177 | ControlBounds := TRectangle.Create;
|
---|
178 | Timer := TTimer.Create(nil);
|
---|
179 | Timer.Enabled := False;
|
---|
180 | Timer.OnTimer := TimerExecute;
|
---|
181 | StepCount := 10;
|
---|
182 | Duration := 0.05;
|
---|
183 | ShowBounds := TRectangle.Create;
|
---|
184 | end;
|
---|
185 |
|
---|
186 | destructor TCDAutoHide.Destroy;
|
---|
187 | begin
|
---|
188 | ShowBounds.Free;
|
---|
189 | HideBounds.Free;
|
---|
190 | ControlBounds.Free;
|
---|
191 | Timer.Free;
|
---|
192 | inherited Destroy;
|
---|
193 | end;
|
---|
194 |
|
---|
195 | procedure TCDAutoHide.TimerExecute(Sender: TObject);
|
---|
196 | begin
|
---|
197 | if Direction = 1 then begin
|
---|
198 | Position := Position + 1 / StepCount;
|
---|
199 | if Position > 1 then begin
|
---|
200 | Position := 1;
|
---|
201 | Timer.Enabled := False;
|
---|
202 | ControlVisible := True;
|
---|
203 | DoShow := False;
|
---|
204 | HideBounds.Assign(ShowBounds);
|
---|
205 | end;
|
---|
206 | end else
|
---|
207 | if Direction = -1 then begin
|
---|
208 | Position := Position - 1 / StepCount;
|
---|
209 | if Position < 0 then begin
|
---|
210 | Position := 0;
|
---|
211 | if DoShow then begin
|
---|
212 | Direction := 1;
|
---|
213 | ControlBounds.Assign(ShowBounds);
|
---|
214 | end else begin
|
---|
215 | Timer.Enabled := False;
|
---|
216 | ControlVisible := False;
|
---|
217 | end;
|
---|
218 | end;
|
---|
219 | end;
|
---|
220 | UpdateBounds;
|
---|
221 | end;
|
---|
222 |
|
---|
223 | { TCDManagerTabsPopup }
|
---|
224 |
|
---|
225 | procedure TCDManagerTabsPopup.PinShowButtonClick(Sender: TObject);
|
---|
226 | begin
|
---|
227 |
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TCDManagerTabsPopup.PinHideButtonClick(Sender: TObject);
|
---|
231 | begin
|
---|
232 |
|
---|
233 | end;
|
---|
234 |
|
---|
235 | procedure TCDManagerTabsPopup.TabControlChange(Sender: TObject);
|
---|
236 | var
|
---|
237 | Pos: TPoint;
|
---|
238 | C: TControl;
|
---|
239 | TopParent: TWinControl;
|
---|
240 | begin
|
---|
241 | inherited TabControlChange(Sender);
|
---|
242 | MouseDownSkip := True;
|
---|
243 |
|
---|
244 | if PageControl.TabIndex >= 0 then begin
|
---|
245 | C := TCDManagerTabsPopupItem(DockItems[PageControl.TabIndex]).Control;
|
---|
246 | C.Align := alClient;
|
---|
247 | C.Parent := HeaderPanel.ControlPanel;
|
---|
248 | HeaderPanel.Header.Control := C;
|
---|
249 | //AutoHide.Control.Align := alCustom;
|
---|
250 | //Pos := DockSite.ClientToScreen(Pos);
|
---|
251 | //AutoHide.Control.SetBounds(0, 0, 100, 100);
|
---|
252 | UpdatePopupFormBounds;
|
---|
253 | AutoHide.Show;
|
---|
254 | end;
|
---|
255 | end;
|
---|
256 |
|
---|
257 | procedure TCDManagerTabsPopup.PopupFormMouseLeave(Sender: TObject);
|
---|
258 | begin
|
---|
259 | if PopupForm.Visible then AutoHide.Hide;
|
---|
260 | end;
|
---|
261 |
|
---|
262 | procedure TCDManagerTabsPopup.RemoveControl(Control: TControl);
|
---|
263 | begin
|
---|
264 | if DockItems.Count <= 2 then
|
---|
265 | PageControl.OnResize := nil;
|
---|
266 | inherited;
|
---|
267 | end;
|
---|
268 |
|
---|
269 | constructor TCDManagerTabsPopup.Create(ADockSite: TWinControl);
|
---|
270 | var
|
---|
271 | I: Integer;
|
---|
272 | begin
|
---|
273 | inherited;
|
---|
274 | FDockStyle := dsPopupTabs;
|
---|
275 | PopupForm := TForm.Create(nil);
|
---|
276 | PopupForm.DockManager := TCDManagerRegions.Create(PopupForm);
|
---|
277 | PopupForm.Visible := True;
|
---|
278 | PopupForm.BorderStyle := bsNone;
|
---|
279 | PopupForm.OnMouseLeave := PopupFormMouseLeave;
|
---|
280 | HeaderPanel := TCDPanelHeader.Create(nil);
|
---|
281 | HeaderPanel.Parent := PopupForm;
|
---|
282 | HeaderPanel.Align := alClient;
|
---|
283 | HeaderPanel.Visible := True;
|
---|
284 | Splitter := TPanel.Create(nil);
|
---|
285 | Splitter.Visible := True;
|
---|
286 | Splitter.Parent := PopupForm;
|
---|
287 | Splitter.OnMouseDown := SplitterMouseDown;
|
---|
288 | Splitter.OnMouseMove := SplitterMouseMove;
|
---|
289 | Splitter.OnMouseUp := SplitterMouseUp;
|
---|
290 | AutoHide := TCDAutoHide.Create;
|
---|
291 | AutoHide.Control := PopupForm;
|
---|
292 | PageControl.OnResize := PageControlResize;
|
---|
293 | HeaderVisible := False;
|
---|
294 |
|
---|
295 | for I := 0 to DockItems.Count - 1 do begin
|
---|
296 | // if TCDManagerTabsPopupItem(DockItems[I]).Hidden then
|
---|
297 | // if
|
---|
298 | end;
|
---|
299 | HeaderPos := HeaderPos; // Reset position
|
---|
300 | end;
|
---|
301 |
|
---|
302 | destructor TCDManagerTabsPopup.Destroy;
|
---|
303 | begin
|
---|
304 | AutoHide.Free;
|
---|
305 | PopupForm.Free;
|
---|
306 | Splitter.Free;
|
---|
307 | HeaderPanel.Free;
|
---|
308 | inherited Destroy;
|
---|
309 | end;
|
---|
310 |
|
---|
311 | procedure TCDManagerTabsPopup.PageControlResize(Sender: TObject);
|
---|
312 | begin
|
---|
313 | UpdatePopupFormBounds;
|
---|
314 | end;
|
---|
315 |
|
---|
316 | procedure TCDManagerTabsPopup.InsertControlNoUpdate(Control: TControl; InsertAt: TAlign);
|
---|
317 | var
|
---|
318 | NewTabSheet: TTabSheet;
|
---|
319 | NewItem: TCDManagerTabsItem;
|
---|
320 | begin
|
---|
321 | //inherited;
|
---|
322 | begin
|
---|
323 | NewItem := TCDManagerTabsPopupItem.Create;
|
---|
324 | with NewItem do begin
|
---|
325 | Manager := Self;
|
---|
326 | end;
|
---|
327 | if (Control is TForm) and Assigned((Control as TForm).Icon) then
|
---|
328 | NewItem.IconImage.Picture.Assign((Control as TForm).Icon);
|
---|
329 |
|
---|
330 | NewItem.Control := TWinControl(Control);
|
---|
331 | Control.AddHandlerOnVisibleChanged(NewItem.VisibleChange);
|
---|
332 | //AControl.Parent := NewItem.ClientAreaPanel;
|
---|
333 | Control.Align := alClient;
|
---|
334 | if (InsertAt = alTop) or (InsertAt = alLeft) then
|
---|
335 | DockItems.Insert(0, NewItem)
|
---|
336 | else DockItems.Add(NewItem);
|
---|
337 | end;
|
---|
338 | end;
|
---|
339 |
|
---|
340 | procedure TCDManagerTabsPopup.SplitterMouseDown(Sender: TObject;
|
---|
341 | Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
---|
342 | begin
|
---|
343 | if Button = mbLeft then begin
|
---|
344 | SplitterMousePos := Point(X, Y);
|
---|
345 | SplitterMouseDrag := True;
|
---|
346 | end;
|
---|
347 | end;
|
---|
348 |
|
---|
349 | procedure TCDManagerTabsPopup.SplitterMouseMove(Sender: TObject; Shift: TShiftState;
|
---|
350 | X, Y: Integer);
|
---|
351 | begin
|
---|
352 | if SplitterMouseDrag then begin
|
---|
353 | case Splitter.Align of
|
---|
354 | alLeft: begin
|
---|
355 | PopupForm.SetBounds(PopupForm.Left + (X - SplitterMousePos.X),
|
---|
356 | PopupForm.Top, PopupForm.Width - (X - SplitterMousePos.X),
|
---|
357 | PopupForm.Height);
|
---|
358 | end;
|
---|
359 | alRight: begin
|
---|
360 | PopupForm.SetBounds(PopupForm.Left, PopupForm.Top,
|
---|
361 | PopupForm.Width + (X - SplitterMousePos.X), PopupForm.Height);
|
---|
362 | end;
|
---|
363 | alTop: begin
|
---|
364 | PopupForm.SetBounds(PopupForm.Left, PopupForm.Top + (Y - SplitterMousePos.Y),
|
---|
365 | PopupForm.Width, PopupForm.Height - (Y - SplitterMousePos.Y));
|
---|
366 | end;
|
---|
367 | alBottom: begin
|
---|
368 | PopupForm.SetBounds(PopupForm.Left, PopupForm.Top,
|
---|
369 | PopupForm.Width, PopupForm.Height + (Y - SplitterMousePos.Y));
|
---|
370 | end;
|
---|
371 | end;
|
---|
372 | end;
|
---|
373 | end;
|
---|
374 |
|
---|
375 | procedure TCDManagerTabsPopup.SplitterMouseUp(Sender: TObject;
|
---|
376 | Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
---|
377 | begin
|
---|
378 | SplitterMouseDrag := False;
|
---|
379 | end;
|
---|
380 |
|
---|
381 | procedure TCDManagerTabsPopup.UpdatePopupFormBounds;
|
---|
382 | var
|
---|
383 | Pos: TPoint;
|
---|
384 | C: TControl;
|
---|
385 | TopParent: TWinControl;
|
---|
386 | begin
|
---|
387 | if PageControl.TabIndex <> - 1 then begin
|
---|
388 | Pos := Point(PageControl.Left, PageControl.Top);
|
---|
389 | TopParent := DockSite;
|
---|
390 | while Assigned(TopParent.Parent) do begin
|
---|
391 | Pos.X := Pos.X + TopParent.Left;;
|
---|
392 | Pos.Y := Pos.Y + TopParent.Top;
|
---|
393 | TopParent := TopParent.Parent;
|
---|
394 | end;
|
---|
395 | PopupForm.Parent := TopParent;
|
---|
396 |
|
---|
397 | C := TCDManagerTabsPopupItem(DockItems[PageControl.TabIndex]).Control;
|
---|
398 | C.TBDockHeight := 100;
|
---|
399 | C.LRDockWidth := 100;
|
---|
400 | with AutoHide.Control do
|
---|
401 | case AutoHide.TabPosition of
|
---|
402 | tpTop: begin
|
---|
403 | SetBounds(Pos.X, Pos.Y + PageControl.Height,
|
---|
404 | PageControl.Width, C.TBDockHeight);
|
---|
405 | end;
|
---|
406 | tpLeft: begin
|
---|
407 | SetBounds(Pos.X + PageControl.Width, Pos.Y,
|
---|
408 | C.LRDockWidth, PageControl.Height);
|
---|
409 | end;
|
---|
410 | tpBottom: begin
|
---|
411 | SetBounds(Pos.X, Pos.Y - C.TBDockHeight,
|
---|
412 | PageControl.Width, C.TBDockHeight);
|
---|
413 | end;
|
---|
414 | tpRight: begin
|
---|
415 | SetBounds(Pos.X - C.LRDockWidth, Pos.Y,
|
---|
416 | C.LRDockWidth, PageControl.Height);
|
---|
417 | end;
|
---|
418 | end;
|
---|
419 | end;
|
---|
420 | end;
|
---|
421 |
|
---|
422 | procedure TCDManagerTabsPopup.SetHeaderPos(const AValue: THeaderPos);
|
---|
423 | const
|
---|
424 | SplitterSize: Integer = 4;
|
---|
425 | begin
|
---|
426 | inherited SetHeaderPos(AValue);
|
---|
427 | AutoHide.TabPosition := HeaderPosToTabPos(AValue);
|
---|
428 | with PageControl do
|
---|
429 | case AValue of
|
---|
430 | hpTop, hpAuto: begin
|
---|
431 | //Align := alTop;
|
---|
432 | //Height := 24;
|
---|
433 | Splitter.Align := alBottom;
|
---|
434 | Splitter.Height := SplitterSize;
|
---|
435 | Splitter.Cursor := crSizeNS;
|
---|
436 | end;
|
---|
437 | hpBottom: begin
|
---|
438 | //Align := alBottom;
|
---|
439 | //Height := 24;
|
---|
440 | Splitter.Align := alTop;
|
---|
441 | Splitter.Height := SplitterSize;
|
---|
442 | Splitter.Cursor := crSizeNS;
|
---|
443 | end;
|
---|
444 | hpLeft: begin
|
---|
445 | //Align := alLeft;
|
---|
446 | //Width := 24;
|
---|
447 | Splitter.Align := alRight;
|
---|
448 | Splitter.Width := SplitterSize;
|
---|
449 | Splitter.Cursor := crSizeWE;
|
---|
450 | end;
|
---|
451 | hpRight: begin
|
---|
452 | //Align := alRight;
|
---|
453 | //Width := 24;
|
---|
454 | Splitter.Align := alLeft;
|
---|
455 | Splitter.Width := SplitterSize;
|
---|
456 | Splitter.Cursor := crSizeWE;
|
---|
457 | end;
|
---|
458 | end;
|
---|
459 | end;
|
---|
460 |
|
---|
461 | end.
|
---|
462 |
|
---|