Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / dockwin.hxx
blob156d0a0642bbbf39bae649ac6c979f9f34b2787b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_DOCKWIN_HXX
21 #define INCLUDED_VCL_DOCKWIN_HXX
23 #include <tools/solar.h>
24 #include <vcl/dllapi.h>
25 #include <vcl/builder.hxx>
26 #include <vcl/floatwin.hxx>
27 #include <vector>
29 // data to be sent with docking events
30 struct DockingData
32 Point maMousePos; // in
33 Rectangle maTrackRect; // in/out
34 bool mbFloating; // out
35 bool mbLivemode; // in
36 bool mbInteractive; // in
38 DockingData() {};
39 DockingData( const Point& rPt, const Rectangle& rRect, bool b) :
40 maMousePos( rPt ), maTrackRect( rRect ), mbFloating( b ), mbLivemode( false ), mbInteractive( true )
41 {};
44 struct EndDockingData
46 Rectangle maWindowRect; // in
47 bool mbFloating; // in
48 bool mbCancelled; // in
50 EndDockingData() {};
51 EndDockingData( const Rectangle& rRect, bool b, bool bCancelled ) :
52 maWindowRect( rRect ), mbFloating( b ), mbCancelled( bCancelled )
53 {};
56 struct EndPopupModeData
58 Point maFloatingPos; // in
59 bool mbTearoff; // in
61 EndPopupModeData() {};
62 EndPopupModeData( const Point& rPos, bool bTearoff ) :
63 maFloatingPos( rPos ), mbTearoff( bTearoff )
64 {};
67 /** ImplDockingWindowWrapper
69 * ImplDockingWindowWrapper obsoletes the DockingWindow class.
70 * It is better because it can make a "normal window" dockable.
71 * All DockingWindows should be converted the new class.
74 class ImplDockingWindowWrapper
76 friend class ::vcl::Window;
77 friend class DockingManager;
78 friend class DockingWindow;
80 private:
82 // the original 'Docking'window
83 VclPtr<vcl::Window> mpDockingWindow;
85 // the original DockingWindow members
86 VclPtr<FloatingWindow> mpFloatWin;
87 VclPtr<vcl::Window> mpOldBorderWin;
88 VclPtr<vcl::Window> mpParent;
89 Point maFloatPos;
90 Point maDockPos;
91 Point maMouseOff;
92 Point maMouseStart;
93 Size maRollUpOutSize;
94 Size maMinOutSize;
95 Size maMaxOutSize;
96 Rectangle maDragArea;
97 long mnTrackX;
98 long mnTrackY;
99 long mnTrackWidth;
100 long mnTrackHeight;
101 sal_Int32 mnDockLeft;
102 sal_Int32 mnDockTop;
103 sal_Int32 mnDockRight;
104 sal_Int32 mnDockBottom;
105 WinBits mnFloatBits;
106 bool mbDockCanceled:1,
107 mbFloatPrevented:1,
108 mbDockable:1,
109 mbDocking:1,
110 mbDragFull:1,
111 mbLastFloatMode:1,
112 mbStartFloat:1,
113 mbTrackDock:1,
114 mbPinned:1,
115 mbRollUp:1,
116 mbDockBtn:1,
117 mbHideBtn:1,
118 mbStartDockingEnabled:1,
119 mbLocked:1;
121 DECL_LINK( PopupModeEnd, void* );
122 void ImplEnableStartDocking( bool bEnable = true ) { mbStartDockingEnabled = bEnable; }
123 bool ImplStartDockingEnabled() { return mbStartDockingEnabled; }
125 public:
126 ImplDockingWindowWrapper( const vcl::Window *pWindow );
127 virtual ~ImplDockingWindowWrapper();
129 vcl::Window* GetWindow() { return mpDockingWindow; }
130 bool ImplStartDocking( const Point& rPos );
132 // those methods actually call the corresponding handlers
133 void StartDocking( const Point& rPos, Rectangle& rRect );
134 bool Docking( const Point& rPos, Rectangle& rRect );
135 void EndDocking( const Rectangle& rRect, bool bFloatMode );
136 bool PrepareToggleFloatingMode();
137 void ToggleFloatingMode();
139 void SetDragArea( const Rectangle& rRect );
140 Rectangle GetDragArea() const { return maDragArea;}
142 void Lock();
143 void Unlock();
144 bool IsLocked() const { return mbLocked;}
146 void StartPopupMode( ToolBox* pParentToolBox, FloatWinPopupFlags nPopupModeFlags );
147 bool IsInPopupMode() const;
149 void TitleButtonClick( TitleButton nButton );
150 void Resizing( Size& rSize );
151 void Tracking( const TrackingEvent& rTEvt );
152 long Notify( NotifyEvent& rNEvt );
154 void ShowTitleButton( TitleButton nButton, bool bVisible = true );
156 void SetMinOutputSizePixel( const Size& rSize );
158 void SetMaxOutputSizePixel( const Size& rSize );
160 bool IsDocking() const { return mbDocking; }
161 bool IsDockable() const { return mbDockable; }
162 bool IsDockingCanceled() const { return mbDockCanceled; }
163 bool IsFloatingPrevented() const { return mbFloatPrevented; }
165 void SetFloatingMode( bool bFloatMode = false );
166 bool IsFloatingMode() const;
167 FloatingWindow* GetFloatingWindow() const { return mpFloatWin; }
169 void SetFloatStyle( WinBits nWinStyle );
170 WinBits GetFloatStyle() const { return mnFloatBits;}
172 void setPosSizePixel( long nX, long nY,
173 long nWidth, long nHeight,
174 PosSizeFlags nFlags = PosSizeFlags::All );
175 void SetPosSizePixel( const Point& rNewPos,
176 const Size& rNewSize )
177 { mpDockingWindow->SetPosSizePixel( rNewPos, rNewSize ); }
178 Point GetPosPixel() const;
179 Size GetSizePixel() const;
182 class VCL_DLLPUBLIC DockingManager
184 protected:
185 ::std::vector<ImplDockingWindowWrapper *> mDockingWindows;
187 public:
188 DockingManager();
189 ~DockingManager();
191 void AddWindow( const vcl::Window *pWin );
192 void RemoveWindow( const vcl::Window *pWin );
194 ImplDockingWindowWrapper* GetDockingWindowWrapper( const vcl::Window *pWin );
195 bool IsDockable( const vcl::Window *pWin );
197 bool IsFloating( const vcl::Window *pWin );
198 void SetFloatingMode( const vcl::Window *pWin, bool bFloating );
200 void Lock( const vcl::Window *pWin );
201 void Unlock( const vcl::Window *pWin );
202 bool IsLocked( const vcl::Window *pWin );
204 void StartPopupMode( ToolBox *pParentToolBox, const vcl::Window *pWin );
205 void StartPopupMode( ToolBox *pParentToolBox, const vcl::Window *pWin, FloatWinPopupFlags nPopupModeFlags );
207 bool IsInPopupMode( const vcl::Window *pWin );
208 void EndPopupMode( const vcl::Window *pWin );
210 // required because those methods are not virtual in Window (!!!) and must
211 // be availbale from the toolkit
212 void SetPosSizePixel( vcl::Window *pWin, long nX, long nY,
213 long nWidth, long nHeight,
214 PosSizeFlags nFlags = PosSizeFlags::All );
215 Rectangle GetPosSizePixel( const vcl::Window *pWin );
219 // - DockingWindow -
222 class VCL_DLLPUBLIC DockingWindow
223 : public vcl::Window
224 , public VclBuilderContainer
226 class ImplData;
227 private:
228 VclPtr<FloatingWindow> mpFloatWin;
229 VclPtr<vcl::Window> mpOldBorderWin;
230 ImplData* mpImplData;
231 Point maFloatPos;
232 Point maDockPos;
233 Point maMouseOff;
234 Point maMouseStart;
235 Size maRollUpOutSize;
236 Size maMinOutSize;
237 long mnTrackX;
238 long mnTrackY;
239 long mnTrackWidth;
240 long mnTrackHeight;
241 sal_Int32 mnDockLeft;
242 sal_Int32 mnDockTop;
243 sal_Int32 mnDockRight;
244 sal_Int32 mnDockBottom;
245 WinBits mnFloatBits;
246 Idle maLayoutIdle;
247 bool mbDockCanceled:1,
248 mbDockPrevented:1,
249 mbFloatPrevented:1,
250 mbDockable:1,
251 mbDocking:1,
252 mbDragFull:1,
253 mbLastFloatMode:1,
254 mbStartFloat:1,
255 mbTrackDock:1,
256 mbPinned:1,
257 mbRollUp:1,
258 mbDockBtn:1,
259 mbHideBtn:1,
260 mbIsDefferedInit:1,
261 mbIsCalculatingInitialLayoutSize:1,
262 mbInitialLayoutDone:1;
264 VclPtr<vcl::Window> mpDialogParent;
266 SAL_DLLPRIVATE void ImplInitDockingWindowData();
267 SAL_DLLPRIVATE void setPosSizeOnContainee(Size aSize, Window &rBox);
268 DECL_DLLPRIVATE_LINK_TYPED( ImplHandleLayoutTimerHdl, Idle*, void );
270 DockingWindow (const DockingWindow &) SAL_DELETED_FUNCTION;
271 DockingWindow & operator= (const DockingWindow &) SAL_DELETED_FUNCTION;
273 protected:
274 using Window::ImplInit;
275 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
276 SAL_DLLPRIVATE void ImplInitSettings();
277 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
279 SAL_DLLPRIVATE void DoInitialLayout();
281 void loadUI(vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
282 const css::uno::Reference<css::frame::XFrame> &rFrame);
284 public:
285 bool isLayoutEnabled() const;
286 void setOptimalLayoutSize();
287 bool isCalculatingInitialLayoutSize() const { return mbIsCalculatingInitialLayoutSize; }
289 SAL_DLLPRIVATE bool ImplStartDocking( const Point& rPos );
290 SAL_DLLPRIVATE bool isDeferredInit() const { return mbIsDefferedInit; }
291 SAL_DLLPRIVATE bool hasPendingLayout() const { return maLayoutIdle.IsActive(); }
292 void doDeferredInit(WinBits nBits);
293 protected:
294 DockingWindow( WindowType nType );
296 public:
297 DockingWindow(vcl::Window* pParent, WinBits nStyle = WB_STDDOCKWIN);
298 DockingWindow(vcl::Window* pParent, const ResId& rResId);
299 DockingWindow(vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
300 const css::uno::Reference<css::frame::XFrame> &rFrame = css::uno::Reference<css::frame::XFrame>());
301 virtual ~DockingWindow();
302 virtual void dispose() SAL_OVERRIDE;
304 virtual void StartDocking();
305 virtual bool Docking( const Point& rPos, Rectangle& rRect );
306 virtual void EndDocking( const Rectangle& rRect, bool bFloatMode );
307 virtual bool PrepareToggleFloatingMode();
308 virtual void ToggleFloatingMode();
310 virtual void Resizing( Size& rSize );
311 virtual bool Close();
312 virtual void Tracking( const TrackingEvent& rTEvt ) SAL_OVERRIDE;
313 virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
314 virtual void StateChanged( StateChangedType nType ) SAL_OVERRIDE;
315 virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
317 void SetPin( bool bPin );
318 bool IsPinned() const;
320 void RollUp();
321 void RollDown();
322 bool IsRollUp() const;
324 void SetRollUpOutputSizePixel( const Size& rSize );
325 Size GetRollUpOutputSizePixel() const;
327 void SetMinOutputSizePixel( const Size& rSize );
328 const Size& GetMinOutputSizePixel() const;
330 void SetMaxOutputSizePixel( const Size& rSize );
332 bool IsDocking() const { return mbDocking; }
333 bool IsDockable() const { return mbDockable; }
334 bool IsDockingCanceled() const { return mbDockCanceled; }
335 bool IsDockingPrevented() const { return mbDockPrevented; }
336 bool IsFloatingPrevented() const { return mbFloatPrevented; }
338 void SetFloatingMode( bool bFloatMode = false );
339 bool IsFloatingMode() const;
340 FloatingWindow* GetFloatingWindow() const { return mpFloatWin; }
342 void SetFloatingPos( const Point& rNewPos );
343 Point GetFloatingPos() const;
345 void SetFloatStyle( WinBits nWinStyle );
346 WinBits GetFloatStyle() const;
348 virtual void setPosSizePixel( long nX, long nY,
349 long nWidth, long nHeight,
350 PosSizeFlags nFlags = PosSizeFlags::All ) SAL_OVERRIDE;
351 void SetPosSizePixel( const Point& rNewPos,
352 const Size& rNewSize ) SAL_OVERRIDE
353 { Window::SetPosSizePixel( rNewPos, rNewSize ); }
354 Point GetPosPixel() const SAL_OVERRIDE;
355 Size GetSizePixel() const SAL_OVERRIDE;
356 void SetOutputSizePixel( const Size& rNewSize ) SAL_OVERRIDE;
357 Size GetOutputSizePixel() const;
359 virtual void SetText( const OUString& rStr ) SAL_OVERRIDE;
360 virtual OUString GetText() const SAL_OVERRIDE;
361 virtual Size GetOptimalSize() const SAL_OVERRIDE;
362 virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) SAL_OVERRIDE;
365 inline void DockingWindow::SetPin( bool bPin )
367 if ( mpFloatWin )
368 mpFloatWin->SetPin( bPin );
369 mbPinned = bPin;
372 inline bool DockingWindow::IsPinned() const
374 if ( mpFloatWin )
375 return mpFloatWin->IsPinned();
376 return mbPinned;
379 inline void DockingWindow::RollUp()
381 if ( mpFloatWin )
382 mpFloatWin->RollUp();
383 mbRollUp = true;
386 inline void DockingWindow::RollDown()
388 if ( mpFloatWin )
389 mpFloatWin->RollDown();
390 mbRollUp = false;
393 inline bool DockingWindow::IsRollUp() const
395 if ( mpFloatWin )
396 return mpFloatWin->IsRollUp();
397 return mbRollUp;
400 inline void DockingWindow::SetRollUpOutputSizePixel( const Size& rSize )
402 if ( mpFloatWin )
403 mpFloatWin->SetRollUpOutputSizePixel( rSize );
404 maRollUpOutSize = rSize;
407 inline Size DockingWindow::GetRollUpOutputSizePixel() const
409 if ( mpFloatWin )
410 return mpFloatWin->GetRollUpOutputSizePixel();
411 return maRollUpOutSize;
414 inline void DockingWindow::SetMinOutputSizePixel( const Size& rSize )
416 if ( mpFloatWin )
417 mpFloatWin->SetMinOutputSizePixel( rSize );
418 maMinOutSize = rSize;
421 inline const Size& DockingWindow::GetMinOutputSizePixel() const
423 if ( mpFloatWin )
424 return mpFloatWin->GetMinOutputSizePixel();
425 return maMinOutSize;
428 inline void DockingWindow::SetFloatingPos( const Point& rNewPos )
430 if ( mpFloatWin )
431 mpFloatWin->SetPosPixel( rNewPos );
432 else
433 maFloatPos = rNewPos;
437 #endif // INCLUDED_VCL_DOCKWIN_HXX
439 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */