source: trunk/Packages/CoolDocking/Managers/UCDManagerTabsPopup.pas

Last change on this file was 73, checked in by chronos, 12 years ago
  • Modified: Packages are now stored as uncomporessed and are linked with relative path to project.
File size: 12.5 KB
Line 
1unit UCDManagerTabsPopup;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, Controls, SysUtils, ComCtrls, ExtCtrls, UCDCommon, UCDManager,
9 UCDManagerTabs, Forms, URectangle, UCDConjoinForm;
10
11type
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
83implementation
84
85uses
86 UCDClient, UCDManagerRegions;
87
88{ TCDManagerTabsPopupItem }
89
90constructor TCDManagerTabsPopupItem.Create;
91begin
92 inherited;
93end;
94
95{ TCDAutoHide }
96
97procedure TCDAutoHide.UpdateBounds;
98begin
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;
119end;
120
121procedure TCDAutoHide.UpdateTimerInterval;
122begin
123 Timer.Interval := Round(FDuration * 1000 / FStepCount);
124end;
125
126procedure TCDAutoHide.SetDuration(const AValue: Real);
127begin
128 if FDuration = AValue then Exit;
129 FDuration := AValue;
130 UpdateTimerInterval;
131end;
132
133procedure TCDAutoHide.SetStepCount(const AValue: Integer);
134begin
135 if FStepCount = AValue then Exit;
136 FStepCount := AValue;
137 UpdateTimerInterval;
138end;
139
140procedure TCDAutoHide.Hide;
141begin
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;
151end;
152
153procedure TCDAutoHide.Show;
154begin
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;
170end;
171
172constructor TCDAutoHide.Create;
173begin
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;
184end;
185
186destructor TCDAutoHide.Destroy;
187begin
188 ShowBounds.Free;
189 HideBounds.Free;
190 ControlBounds.Free;
191 Timer.Free;
192 inherited Destroy;
193end;
194
195procedure TCDAutoHide.TimerExecute(Sender: TObject);
196begin
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;
221end;
222
223{ TCDManagerTabsPopup }
224
225procedure TCDManagerTabsPopup.PinShowButtonClick(Sender: TObject);
226begin
227
228end;
229
230procedure TCDManagerTabsPopup.PinHideButtonClick(Sender: TObject);
231begin
232
233end;
234
235procedure TCDManagerTabsPopup.TabControlChange(Sender: TObject);
236var
237 Pos: TPoint;
238 C: TControl;
239 TopParent: TWinControl;
240begin
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;
255end;
256
257procedure TCDManagerTabsPopup.PopupFormMouseLeave(Sender: TObject);
258begin
259 if PopupForm.Visible then AutoHide.Hide;
260end;
261
262procedure TCDManagerTabsPopup.RemoveControl(Control: TControl);
263begin
264 if DockItems.Count <= 2 then
265 PageControl.OnResize := nil;
266 inherited;
267end;
268
269constructor TCDManagerTabsPopup.Create(ADockSite: TWinControl);
270var
271 I: Integer;
272begin
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
300end;
301
302destructor TCDManagerTabsPopup.Destroy;
303begin
304 AutoHide.Free;
305 PopupForm.Free;
306 Splitter.Free;
307 HeaderPanel.Free;
308 inherited Destroy;
309end;
310
311procedure TCDManagerTabsPopup.PageControlResize(Sender: TObject);
312begin
313 UpdatePopupFormBounds;
314end;
315
316procedure TCDManagerTabsPopup.InsertControlNoUpdate(Control: TControl; InsertAt: TAlign);
317var
318 NewTabSheet: TTabSheet;
319 NewItem: TCDManagerTabsItem;
320begin
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;
338end;
339
340procedure TCDManagerTabsPopup.SplitterMouseDown(Sender: TObject;
341 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
342begin
343 if Button = mbLeft then begin
344 SplitterMousePos := Point(X, Y);
345 SplitterMouseDrag := True;
346 end;
347end;
348
349procedure TCDManagerTabsPopup.SplitterMouseMove(Sender: TObject; Shift: TShiftState;
350 X, Y: Integer);
351begin
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;
373end;
374
375procedure TCDManagerTabsPopup.SplitterMouseUp(Sender: TObject;
376 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
377begin
378 SplitterMouseDrag := False;
379end;
380
381procedure TCDManagerTabsPopup.UpdatePopupFormBounds;
382var
383 Pos: TPoint;
384 C: TControl;
385 TopParent: TWinControl;
386begin
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;
420end;
421
422procedure TCDManagerTabsPopup.SetHeaderPos(const AValue: THeaderPos);
423const
424 SplitterSize: Integer = 4;
425begin
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;
459end;
460
461end.
462
Note: See TracBrowser for help on using the repository browser.