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