xref: /aoo42x/main/vcl/inc/vcl/dockwin.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SV_DOCKWIN_HXX
29 #define _SV_DOCKWIN_HXX
30 
31 #include <vcl/sv.h>
32 #include <vcl/dllapi.h>
33 #include <vcl/floatwin.hxx>
34 #include <vector>
35 
36 // data to be sent with docking events
37 struct DockingData
38 {
39     Point       maMousePos;     // in
40     Rectangle   maTrackRect;    // in/out
41     sal_Bool        mbFloating;     // out
42     sal_Bool        mbLivemode;     // in
43     sal_Bool        mbInteractive;  // in
44 
45     DockingData() {};
46     DockingData( const Point& rPt, const Rectangle& rRect, sal_Bool b) :
47         maMousePos( rPt ), maTrackRect( rRect ), mbFloating( b ), mbLivemode( sal_False ), mbInteractive( sal_True )
48         {};
49 };
50 
51 struct EndDockingData
52 {
53     Rectangle   maWindowRect;    // in
54     sal_Bool        mbFloating;      // in
55     sal_Bool        mbCancelled;     // in
56 
57     EndDockingData() {};
58     EndDockingData( const Rectangle& rRect, sal_Bool b, sal_Bool bCancelled ) :
59         maWindowRect( rRect ), mbFloating( b ), mbCancelled( bCancelled )
60         {};
61 };
62 
63 struct EndPopupModeData
64 {
65     Point       maFloatingPos;    // in
66     sal_Bool        mbTearoff;        // in
67 
68     EndPopupModeData() {};
69     EndPopupModeData( const Point& rPos, sal_Bool bTearoff ) :
70         maFloatingPos( rPos ), mbTearoff( bTearoff )
71         {};
72 };
73 
74 /** ImplDockingWindowWrapper
75  *
76  *  ImplDockingWindowWrapper obsoletes the DockingWindow class.
77  *  It is better because it can make a "normal window" dockable.
78  *  All DockingWindows should be converted the new class.
79  */
80 
81 class ImplDockingWindowWrapper
82 {
83     friend class Window;
84     friend class DockingManager;
85     friend class DockingWindow;
86 
87 private:
88 
89     // the original 'Docking'window
90     Window *mpDockingWindow;
91 
92     // the original DockingWindow members
93 	FloatingWindow* mpFloatWin;
94 	Window* 		mpOldBorderWin;
95 	Window* 		mpParent;
96 	Point			maFloatPos;
97 	Point			maDockPos;
98 	Point			maMouseOff;
99 	Point			maMouseStart;
100 	Size			maRollUpOutSize;
101 	Size			maMinOutSize;
102 	Size			maMaxOutSize;
103     Rectangle       maDragArea;
104 	long			mnTrackX;
105 	long			mnTrackY;
106 	long			mnTrackWidth;
107 	long			mnTrackHeight;
108 	sal_Int32		mnDockLeft;
109 	sal_Int32		mnDockTop;
110 	sal_Int32		mnDockRight;
111 	sal_Int32		mnDockBottom;
112 	WinBits 		mnFloatBits;
113 	sal_Bool			mbDockCanceled:1,
114 					mbFloatPrevented:1,
115 					mbDockable:1,
116 					mbDocking:1,
117 					mbDragFull:1,
118 					mbLastFloatMode:1,
119 					mbStartFloat:1,
120 					mbTrackDock:1,
121 					mbPined:1,
122 					mbRollUp:1,
123 					mbDockBtn:1,
124 					mbHideBtn:1,
125                     mbStartDockingEnabled:1,
126                     mbLocked:1;
127 
128 	void			ImplInitData();
129 
130 					DECL_LINK( PopupModeEnd, void* );
131     void            ImplEnableStartDocking( sal_Bool bEnable = sal_True )  { mbStartDockingEnabled = bEnable; }
132     sal_Bool            ImplStartDockingEnabled()               { return mbStartDockingEnabled; }
133 
134 public:
135     ImplDockingWindowWrapper( const Window *pWindow );
136     virtual ~ImplDockingWindowWrapper();
137 
138     Window*         GetWindow()     { return mpDockingWindow; }
139 	sal_Bool            ImplStartDocking( const Point& rPos );
140 
141     // those methods actually call the corresponding handlers
142 	void	        StartDocking( const Point& rPos, Rectangle& rRect );
143 	sal_Bool	        Docking( const Point& rPos, Rectangle& rRect );
144 	void	        EndDocking( const Rectangle& rRect, sal_Bool bFloatMode );
145 	sal_Bool	        PrepareToggleFloatingMode();
146 	void	        ToggleFloatingMode();
147 
148     void            SetDragArea( const Rectangle& rRect );
149     Rectangle       GetDragArea() const;
150 
151     void            Lock();
152     void            Unlock();
153     sal_Bool            IsLocked() const;
154 
155     void            StartPopupMode( ToolBox* pParentToolBox, sal_uLong nPopupModeFlags );
156     sal_Bool            IsInPopupMode() const;
157 
158 	void	        TitleButtonClick( sal_uInt16 nButton );
159 	void	        Pin();
160 	void	        Roll();
161 	void	        PopupModeEnd();
162 	void	        Resizing( Size& rSize );
163 	sal_Bool	        Close();
164 	void	        Tracking( const TrackingEvent& rTEvt );
165 	long	        Notify( NotifyEvent& rNEvt );
166 
167 	void			ShowTitleButton( sal_uInt16 nButton, sal_Bool bVisible = sal_True );
168 	sal_Bool			IsTitleButtonVisible( sal_uInt16 nButton ) const;
169 
170 	void			SetPin( sal_Bool bPin );
171 	sal_Bool			IsPined() const;
172 
173 	void			RollUp();
174 	void			RollDown();
175 	sal_Bool			IsRollUp() const;
176 
177 	void			SetRollUpOutputSizePixel( const Size& rSize );
178 	Size			GetRollUpOutputSizePixel() const;
179 
180 	void			SetMinOutputSizePixel( const Size& rSize );
181 	const Size& 	GetMinOutputSizePixel() const;
182 
183 	void			SetMaxOutputSizePixel( const Size& rSize );
184 	const Size& 	GetMaxOutputSizePixel() const;
185 
186     sal_Bool			IsDocking() const { return mbDocking; }
187     sal_Bool			IsDockable() const { return mbDockable; }
188 	sal_Bool			IsDockingCanceled() const { return mbDockCanceled; }
189 	sal_Bool			IsFloatingPrevented() const { return mbFloatPrevented; }
190 
191 	void			SetFloatingMode( sal_Bool bFloatMode = sal_False );
192 	sal_Bool			IsFloatingMode() const;
193 	FloatingWindow* GetFloatingWindow() const { return mpFloatWin; }
194 
195 	void			SetFloatingPos( const Point& rNewPos );
196 	Point			GetFloatingPos() const;
197 
198 	void			SetFloatStyle( WinBits nWinStyle );
199 	WinBits 		GetFloatStyle() const;
200 	void			SetTabStop();
201 
202 	virtual void	SetPosSizePixel( long nX, long nY,
203 									 long nWidth, long nHeight,
204 									 sal_uInt16 nFlags = WINDOW_POSSIZE_ALL );
205 	void			SetPosSizePixel( const Point& rNewPos,
206 									 const Size& rNewSize )
207 						{ mpDockingWindow->SetPosSizePixel( rNewPos, rNewSize ); }
208 	Point			GetPosPixel() const;
209 	Size			GetSizePixel() const;
210 	void			SetOutputSizePixel( const Size& rNewSize );
211 	Size			GetOutputSizePixel() const;
212 };
213 
214 class VCL_DLLPUBLIC DockingManager
215 {
216 protected:
217 	::std::vector<ImplDockingWindowWrapper *> mDockingWindows;
218 
219 public:
220     DockingManager();
221     ~DockingManager();
222 
223     void AddWindow( const Window *pWin );
224     void RemoveWindow( const Window *pWin );
225 
226     ImplDockingWindowWrapper*  GetDockingWindowWrapper( const Window *pWin );
227     sal_Bool IsDockable( const Window *pWin );
228 
229     sal_Bool IsFloating( const Window *pWin );
230     void SetFloatingMode( const Window *pWin, sal_Bool bFloating );
231 
232     void Lock( const Window *pWin );
233     void Unlock( const Window *pWin );
234     sal_Bool IsLocked( const Window *pWin );
235 
236     void    StartPopupMode( ToolBox *pParentToolBox, const Window *pWin );
237     void    StartPopupMode( ToolBox *pParentToolBox, const Window *pWin, sal_uLong nPopupModeFlags );
238 
239 	sal_Bool    IsInPopupMode( const Window *pWin );
240 	void	EndPopupMode( const Window *pWin );
241 
242     // required because those methods are not virtual in Window (!!!) and must
243     // be availbale from the toolkit
244 	void	    SetPosSizePixel( Window *pWin, long nX, long nY,
245 	                            long nWidth, long nHeight,
246 							    sal_uInt16 nFlags = WINDOW_POSSIZE_ALL );
247 	Rectangle   GetPosSizePixel( const Window *pWin );
248 };
249 
250 // -----------------
251 // - DockingWindow -
252 // -----------------
253 
254 class VCL_DLLPUBLIC DockingWindow : public Window
255 {
256     class   ImplData;
257 private:
258 	FloatingWindow* mpFloatWin;
259 	Window* 		mpOldBorderWin;
260     ImplData*       mpImplData;
261 	Point			maFloatPos;
262 	Point			maDockPos;
263 	Point			maMouseOff;
264 	Point			maMouseStart;
265 	Size			maRollUpOutSize;
266 	Size			maMinOutSize;
267 	long			mnTrackX;
268 	long			mnTrackY;
269 	long			mnTrackWidth;
270 	long			mnTrackHeight;
271 	sal_Int32			mnDockLeft;
272 	sal_Int32			mnDockTop;
273 	sal_Int32			mnDockRight;
274 	sal_Int32			mnDockBottom;
275 	WinBits 		mnFloatBits;
276 	sal_Bool			mbDockCanceled:1,
277 					mbDockPrevented:1,
278 					mbFloatPrevented:1,
279 					mbDockable:1,
280 					mbDocking:1,
281 					mbDragFull:1,
282 					mbLastFloatMode:1,
283 					mbStartFloat:1,
284 					mbTrackDock:1,
285 					mbPined:1,
286 					mbRollUp:1,
287 					mbDockBtn:1,
288 					mbHideBtn:1;
289 
290 //#if 0 // _SOLAR__PRIVATE
291 	SAL_DLLPRIVATE void    ImplInitDockingWindowData();
292 
293     // Copy assignment is forbidden and not implemented.
294 	SAL_DLLPRIVATE         DockingWindow (const DockingWindow &);
295 	SAL_DLLPRIVATE         DockingWindow & operator= (const DockingWindow &);
296 
297 protected:
298     using Window::ImplInit;
299 	SAL_DLLPRIVATE void    ImplInit( Window* pParent, WinBits nStyle );
300 	SAL_DLLPRIVATE void    ImplInitSettings();
301 	SAL_DLLPRIVATE void    ImplLoadRes( const ResId& rResId );
302 
303 public:
304 	SAL_DLLPRIVATE sal_Bool    ImplStartDocking( const Point& rPos );
305 //#endif
306 
307 protected:
308 					DockingWindow( WindowType nType );
309 
310 public:
311 					DockingWindow( Window* pParent, WinBits nStyle = WB_STDDOCKWIN );
312 					DockingWindow( Window* pParent, const ResId& rResId );
313 					~DockingWindow();
314 
315 	virtual void	StartDocking();
316 	virtual sal_Bool	Docking( const Point& rPos, Rectangle& rRect );
317 	virtual void	EndDocking( const Rectangle& rRect, sal_Bool bFloatMode );
318 	virtual sal_Bool	PrepareToggleFloatingMode();
319 	virtual void	ToggleFloatingMode();
320 
321 	virtual void	TitleButtonClick( sal_uInt16 nButton );
322 	virtual void	Pin();
323 	virtual void	Roll();
324 	virtual void	PopupModeEnd();
325 	virtual void	Resizing( Size& rSize );
326 	virtual sal_Bool	Close();
327 	virtual void	Tracking( const TrackingEvent& rTEvt );
328 	virtual long	Notify( NotifyEvent& rNEvt );
329 	virtual void	StateChanged( StateChangedType nType );
330 	virtual void	DataChanged( const DataChangedEvent& rDCEvt );
331 
332 	void			ShowTitleButton( sal_uInt16 nButton, sal_Bool bVisible = sal_True );
333 	sal_Bool			IsTitleButtonVisible( sal_uInt16 nButton ) const;
334 
335 	void			SetPin( sal_Bool bPin );
336 	sal_Bool			IsPined() const;
337 
338 	void			RollUp();
339 	void			RollDown();
340 	sal_Bool			IsRollUp() const;
341 
342 	void			SetRollUpOutputSizePixel( const Size& rSize );
343 	Size			GetRollUpOutputSizePixel() const;
344 
345 	void			SetMinOutputSizePixel( const Size& rSize );
346 	const Size& 	GetMinOutputSizePixel() const;
347 
348 	void			SetMaxOutputSizePixel( const Size& rSize );
349 	const Size& 	GetMaxOutputSizePixel() const;
350 
351     sal_Bool			IsDocking() const { return mbDocking; }
352     sal_Bool			IsDockable() const { return mbDockable; }
353 	sal_Bool			IsDockingCanceled() const { return mbDockCanceled; }
354 	sal_Bool			IsDockingPrevented() const { return mbDockPrevented; }
355 	sal_Bool			IsFloatingPrevented() const { return mbFloatPrevented; }
356 
357 	void			SetFloatingMode( sal_Bool bFloatMode = sal_False );
358 	sal_Bool			IsFloatingMode() const;
359 	FloatingWindow* GetFloatingWindow() const { return mpFloatWin; }
360 
361 	void			SetFloatingPos( const Point& rNewPos );
362 	Point			GetFloatingPos() const;
363 
364 	void			SetFloatStyle( WinBits nWinStyle );
365 	WinBits 		GetFloatStyle() const;
366 	void			SetTabStop();
367 
368 	virtual void	SetPosSizePixel( long nX, long nY,
369 									 long nWidth, long nHeight,
370 									 sal_uInt16 nFlags = WINDOW_POSSIZE_ALL );
371 	void			SetPosSizePixel( const Point& rNewPos,
372 									 const Size& rNewSize )
373 						{ Window::SetPosSizePixel( rNewPos, rNewSize ); }
374 	Point			GetPosPixel() const;
375 	Size			GetSizePixel() const;
376 	void			SetOutputSizePixel( const Size& rNewSize );
377 	Size			GetOutputSizePixel() const;
378 };
379 
380 inline void DockingWindow::SetPin( sal_Bool bPin )
381 {
382 	if ( mpFloatWin )
383 		mpFloatWin->SetPin( bPin );
384 	mbPined = bPin;
385 }
386 
387 inline sal_Bool DockingWindow::IsPined() const
388 {
389 	if ( mpFloatWin )
390 		return mpFloatWin->IsPined();
391 	return mbPined;
392 }
393 
394 inline void DockingWindow::RollUp()
395 {
396 	if ( mpFloatWin )
397 		mpFloatWin->RollUp();
398 	mbRollUp = sal_True;
399 }
400 
401 inline void DockingWindow::RollDown()
402 {
403 	if ( mpFloatWin )
404 		mpFloatWin->RollDown();
405 	mbRollUp = sal_False;
406 }
407 
408 inline sal_Bool DockingWindow::IsRollUp() const
409 {
410 	if ( mpFloatWin )
411 		return mpFloatWin->IsRollUp();
412 	return mbRollUp;
413 }
414 
415 inline void DockingWindow::SetRollUpOutputSizePixel( const Size& rSize )
416 {
417 	if ( mpFloatWin )
418 		mpFloatWin->SetRollUpOutputSizePixel( rSize );
419 	maRollUpOutSize = rSize;
420 }
421 
422 inline Size DockingWindow::GetRollUpOutputSizePixel() const
423 {
424 	if ( mpFloatWin )
425 		return mpFloatWin->GetRollUpOutputSizePixel();
426 	return maRollUpOutSize;
427 }
428 
429 inline void DockingWindow::SetMinOutputSizePixel( const Size& rSize )
430 {
431 	if ( mpFloatWin )
432 		mpFloatWin->SetMinOutputSizePixel( rSize );
433 	maMinOutSize = rSize;
434 }
435 
436 inline const Size& DockingWindow::GetMinOutputSizePixel() const
437 {
438 	if ( mpFloatWin )
439 		return mpFloatWin->GetMinOutputSizePixel();
440 	return maMinOutSize;
441 }
442 
443 inline void DockingWindow::SetFloatingPos( const Point& rNewPos )
444 {
445 	if ( mpFloatWin )
446 		mpFloatWin->SetPosPixel( rNewPos );
447 	else
448 		maFloatPos = rNewPos;
449 }
450 
451 
452 #endif	// _SV_DOCKWIN_HXX
453