Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / source / window / dockwin.cxx
blob273f6344cdfa8b205c4343556d72cd1da22fc762
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 .
21 #include <tools/time.hxx>
22 #include <tools/rc.h>
23 #include <vcl/event.hxx>
24 #include <vcl/floatwin.hxx>
25 #include <vcl/dockwin.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/timer.hxx>
28 #include <vcl/unowrap.hxx>
30 #include <svdata.hxx>
31 #include <window.h>
32 #include <brdwin.hxx>
33 #include <salframe.hxx>
37 // =======================================================================
39 #define DOCKWIN_FLOATSTYLES (WB_SIZEABLE | WB_MOVEABLE | WB_CLOSEABLE | WB_STANDALONE | WB_PINABLE | WB_ROLLABLE )
41 // =======================================================================
43 // -----------------------------------------------------------------------
45 class DockingWindow::ImplData
47 public:
48 ImplData();
49 ~ImplData();
51 Window* mpParent;
52 Size maMaxOutSize;
55 DockingWindow::ImplData::ImplData()
57 mpParent = NULL;
58 maMaxOutSize = Size( SHRT_MAX, SHRT_MAX );
61 DockingWindow::ImplData::~ImplData()
65 // -----------------------------------------------------------------------
67 class ImplDockFloatWin : public FloatingWindow
69 private:
70 DockingWindow* mpDockWin;
71 sal_uLong mnLastTicks;
72 Timer maDockTimer;
73 Point maDockPos;
74 Rectangle maDockRect;
75 bool mbInMove;
76 sal_uLong mnLastUserEvent;
78 DECL_LINK(DockingHdl, void *);
79 DECL_LINK(DockTimerHdl, void *);
80 public:
81 ImplDockFloatWin( Window* pParent, WinBits nWinBits,
82 DockingWindow* pDockingWin );
83 ~ImplDockFloatWin();
85 virtual void Move();
86 virtual void Resize();
87 virtual void TitleButtonClick( sal_uInt16 nButton );
88 virtual void Pin();
89 virtual void Roll();
90 virtual void PopupModeEnd();
91 virtual void Resizing( Size& rSize );
92 virtual sal_Bool Close();
94 sal_uLong GetLastTicks() const { return mnLastTicks; }
98 ImplDockFloatWin::ImplDockFloatWin( Window* pParent, WinBits nWinBits,
99 DockingWindow* pDockingWin ) :
100 FloatingWindow( pParent, nWinBits ),
101 mpDockWin( pDockingWin ),
102 mnLastTicks( Time::GetSystemTicks() ),
103 mbInMove( false ),
104 mnLastUserEvent( 0 )
106 // Daten vom DockingWindow uebernehmen
107 if ( pDockingWin )
109 SetSettings( pDockingWin->GetSettings() );
110 Enable( pDockingWin->IsEnabled(), sal_False );
111 EnableInput( pDockingWin->IsInputEnabled(), sal_False );
112 AlwaysEnableInput( pDockingWin->IsAlwaysEnableInput(), sal_False );
113 EnableAlwaysOnTop( pDockingWin->IsAlwaysOnTopEnabled() );
114 SetActivateMode( pDockingWin->GetActivateMode() );
117 SetBackground();
119 maDockTimer.SetTimeoutHdl( LINK( this, ImplDockFloatWin, DockTimerHdl ) );
120 maDockTimer.SetTimeout( 50 );
123 // -----------------------------------------------------------------------
125 ImplDockFloatWin::~ImplDockFloatWin()
127 if( mnLastUserEvent )
128 Application::RemoveUserEvent( mnLastUserEvent );
131 // -----------------------------------------------------------------------
133 IMPL_LINK_NOARG(ImplDockFloatWin, DockTimerHdl)
135 DBG_ASSERT( mpDockWin->IsFloatingMode(), "docktimer called but not floating" );
137 maDockTimer.Stop();
138 PointerState aState = GetPointerState();
140 if( aState.mnState & KEY_MOD1 )
142 // i43499 CTRL disables docking now
143 mpDockWin->GetParent()->ImplGetFrameWindow()->HideTracking();
144 mpDockWin->EndDocking( maDockRect, sal_True );
145 if( aState.mnState & ( MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT ) )
146 maDockTimer.Start();
148 else if( ! ( aState.mnState & ( MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT ) ) )
150 mpDockWin->GetParent()->ImplGetFrameWindow()->HideTracking();
151 mpDockWin->EndDocking( maDockRect, sal_False );
153 else
155 mpDockWin->GetParent()->ImplGetFrameWindow()->ShowTracking( maDockRect, SHOWTRACK_BIG | SHOWTRACK_WINDOW );
156 maDockTimer.Start();
159 return 0;
162 IMPL_LINK_NOARG(ImplDockFloatWin, DockingHdl)
164 PointerState aState = mpDockWin->GetParent()->GetPointerState();
166 mnLastUserEvent = 0;
167 if( mpDockWin->IsDockable() &&
168 (Time::GetSystemTicks() - mnLastTicks > 500) &&
169 ( aState.mnState & ( MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT ) ) &&
170 !(aState.mnState & KEY_MOD1) ) // i43499 CTRL disables docking now
172 maDockPos = Point( mpDockWin->GetParent()->AbsoluteScreenToOutputPixel( OutputToAbsoluteScreenPixel( Point() ) ) );
173 maDockPos = mpDockWin->GetParent()->OutputToScreenPixel( maDockPos ); // sfx expects screen coordinates
175 if( ! mpDockWin->IsDocking() )
176 mpDockWin->StartDocking();
177 maDockRect = Rectangle( maDockPos, mpDockWin->GetSizePixel() );
179 // mouse pos also in screen pixels
180 Point aMousePos = mpDockWin->GetParent()->OutputToScreenPixel( aState.maPos );
182 sal_Bool bFloatMode = mpDockWin->Docking( aMousePos, maDockRect );
183 if( ! bFloatMode )
185 mpDockWin->GetParent()->ImplGetFrameWindow()->ShowTracking( maDockRect, SHOWTRACK_OBJECT | SHOWTRACK_WINDOW );
186 DockTimerHdl( this );
188 else
190 mpDockWin->GetParent()->ImplGetFrameWindow()->HideTracking();
191 maDockTimer.Stop();
192 mpDockWin->EndDocking( maDockRect, sal_True );
195 mbInMove = false;
196 return 0;
198 // -----------------------------------------------------------------------
200 void ImplDockFloatWin::Move()
202 if( mbInMove )
203 return;
205 mbInMove = true;
206 FloatingWindow::Move();
207 mpDockWin->Move();
210 * note: the window should only dock if
211 * the user releases all mouse buttons. The real problem here
212 * is that we don't get mouse events (at least not on X)
213 * if the mouse is on the decoration. So we have to start an
214 * awkward timer based process that polls the modifier/buttons
215 * to see whether they are in the right condition shortly after the
216 * last Move message.
218 if( ! mnLastUserEvent )
219 mnLastUserEvent = Application::PostUserEvent( LINK( this, ImplDockFloatWin, DockingHdl ) );
222 // -----------------------------------------------------------------------
224 void ImplDockFloatWin::Resize()
226 FloatingWindow::Resize();
227 Size aSize( GetSizePixel() );
228 mpDockWin->ImplPosSizeWindow( 0, 0, aSize.Width(), aSize.Height(), WINDOW_POSSIZE_POSSIZE );
231 // -----------------------------------------------------------------------
233 void ImplDockFloatWin::TitleButtonClick( sal_uInt16 nButton )
235 FloatingWindow::TitleButtonClick( nButton );
236 mpDockWin->TitleButtonClick( nButton );
239 // -----------------------------------------------------------------------
241 void ImplDockFloatWin::Pin()
243 FloatingWindow::Pin();
244 mpDockWin->Pin();
247 // -----------------------------------------------------------------------
249 void ImplDockFloatWin::Roll()
251 FloatingWindow::Roll();
252 mpDockWin->Roll();
255 // -----------------------------------------------------------------------
257 void ImplDockFloatWin::PopupModeEnd()
259 FloatingWindow::PopupModeEnd();
260 mpDockWin->PopupModeEnd();
263 // -----------------------------------------------------------------------
265 void ImplDockFloatWin::Resizing( Size& rSize )
267 FloatingWindow::Resizing( rSize );
268 mpDockWin->Resizing( rSize );
271 // -----------------------------------------------------------------------
273 sal_Bool ImplDockFloatWin::Close()
275 return mpDockWin->Close();
278 // =======================================================================
280 sal_Bool DockingWindow::ImplStartDocking( const Point& rPos )
282 if ( !mbDockable )
283 return sal_False;
285 maMouseOff = rPos;
286 maMouseStart = maMouseOff;
287 mbDocking = sal_True;
288 mbLastFloatMode = IsFloatingMode();
289 mbStartFloat = mbLastFloatMode;
291 // FloatingBorder berechnen
292 FloatingWindow* pWin;
293 if ( mpFloatWin )
294 pWin = mpFloatWin;
295 else
296 pWin = new ImplDockFloatWin( mpImplData->mpParent, mnFloatBits, NULL );
297 pWin->GetBorder( mnDockLeft, mnDockTop, mnDockRight, mnDockBottom );
298 if ( !mpFloatWin )
299 delete pWin;
301 Point aPos = ImplOutputToFrame( Point() );
302 Size aSize = Window::GetOutputSizePixel();
303 mnTrackX = aPos.X();
304 mnTrackY = aPos.Y();
305 mnTrackWidth = aSize.Width();
306 mnTrackHeight = aSize.Height();
308 if ( mbLastFloatMode )
310 maMouseOff.X() += mnDockLeft;
311 maMouseOff.Y() += mnDockTop;
312 mnTrackX -= mnDockLeft;
313 mnTrackY -= mnDockTop;
314 mnTrackWidth += mnDockLeft+mnDockRight;
315 mnTrackHeight += mnDockTop+mnDockBottom;
318 if ( GetSettings().GetStyleSettings().GetDragFullOptions() & DRAGFULL_OPTION_DOCKING &&
319 !( mnFloatBits & ( WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) ) ) // no full drag when migrating to system window
320 mbDragFull = sal_True;
321 else
323 StartDocking();
324 mbDragFull = sal_False;
325 ImplUpdateAll();
326 ImplGetFrameWindow()->ImplUpdateAll();
329 StartTracking( STARTTRACK_KEYMOD );
330 return sal_True;
333 // =======================================================================
335 void DockingWindow::ImplInitDockingWindowData()
337 mpImplData = new ImplData;
338 mpWindowImpl->mbDockWin = sal_True;
340 mpFloatWin = NULL;
341 mbDockCanceled = sal_False;
342 mbDockPrevented = sal_False;
343 mbFloatPrevented = sal_False;
344 mbDocking = sal_False;
345 mbPined = sal_False;
346 mbRollUp = sal_False;
347 mbDockBtn = sal_False;
348 mbHideBtn = sal_False;
351 // -----------------------------------------------------------------------
353 void DockingWindow::ImplInit( Window* pParent, WinBits nStyle )
355 if ( !(nStyle & WB_NODIALOGCONTROL) )
356 nStyle |= WB_DIALOGCONTROL;
358 mpImplData->mpParent = pParent;
359 mbDockable = (nStyle & WB_DOCKABLE) != 0;
360 mnFloatBits = WB_BORDER | (nStyle & DOCKWIN_FLOATSTYLES);
361 nStyle &= ~(DOCKWIN_FLOATSTYLES | WB_BORDER);
362 if ( nStyle & WB_DOCKBORDER )
363 nStyle |= WB_BORDER;
365 Window::ImplInit( pParent, nStyle, NULL );
367 ImplInitSettings();
370 // -----------------------------------------------------------------------
372 void DockingWindow::ImplInitSettings()
374 // Hack, damit man auch DockingWindows ohne Hintergrund bauen kann
375 // und noch nicht alles umgestellt ist
376 if ( IsBackground() )
378 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
380 Color aColor;
381 if ( IsControlBackground() )
382 aColor = GetControlBackground();
383 else if ( Window::GetStyle() & WB_3DLOOK )
384 aColor = rStyleSettings.GetFaceColor();
385 else
386 aColor = rStyleSettings.GetWindowColor();
387 SetBackground( aColor );
391 // -----------------------------------------------------------------------
393 void DockingWindow::ImplLoadRes( const ResId& rResId )
395 Window::ImplLoadRes( rResId );
397 sal_uLong nMask = ReadLongRes();
399 if ( (RSC_DOCKINGWINDOW_XYMAPMODE | RSC_DOCKINGWINDOW_X |
400 RSC_DOCKINGWINDOW_Y) & nMask )
402 // Groessenangabe aus der Resource verwenden
403 Point aPos;
404 MapUnit ePosMap = MAP_PIXEL;
406 if ( RSC_DOCKINGWINDOW_XYMAPMODE & nMask )
407 ePosMap = (MapUnit)ReadLongRes();
409 if ( RSC_DOCKINGWINDOW_X & nMask )
411 aPos.X() = ReadShortRes();
412 aPos.X() = ImplLogicUnitToPixelX( aPos.X(), ePosMap );
415 if ( RSC_DOCKINGWINDOW_Y & nMask )
417 aPos.Y() = ReadShortRes();
418 aPos.Y() = ImplLogicUnitToPixelY( aPos.Y(), ePosMap );
421 SetFloatingPos( aPos );
424 if ( nMask & RSC_DOCKINGWINDOW_FLOATING )
426 if ( (sal_Bool)ReadShortRes() )
427 SetFloatingMode( sal_True );
431 // -----------------------------------------------------------------------
433 DockingWindow::DockingWindow( WindowType nType ) :
434 Window( nType )
436 ImplInitDockingWindowData();
439 // -----------------------------------------------------------------------
441 DockingWindow::DockingWindow( Window* pParent, WinBits nStyle ) :
442 Window( WINDOW_DOCKINGWINDOW )
444 ImplInitDockingWindowData();
445 ImplInit( pParent, nStyle );
448 // -----------------------------------------------------------------------
450 DockingWindow::DockingWindow( Window* pParent, const ResId& rResId ) :
451 Window( WINDOW_DOCKINGWINDOW )
453 ImplInitDockingWindowData();
454 rResId.SetRT( RSC_DOCKINGWINDOW );
455 WinBits nStyle = ImplInitRes( rResId );
456 ImplInit( pParent, nStyle );
457 ImplLoadRes( rResId );
459 if ( !(nStyle & WB_HIDE) )
460 Show();
463 // -----------------------------------------------------------------------
465 DockingWindow::~DockingWindow()
467 if ( IsFloatingMode() )
469 Show( sal_False, SHOW_NOFOCUSCHANGE );
470 SetFloatingMode( sal_False );
472 delete mpImplData;
475 // -----------------------------------------------------------------------
477 void DockingWindow::Tracking( const TrackingEvent& rTEvt )
479 if( GetDockingManager()->IsDockable( this ) ) // new docking interface
480 return Window::Tracking( rTEvt );
482 if ( mbDocking )
484 if ( rTEvt.IsTrackingEnded() )
486 mbDocking = sal_False;
487 if ( mbDragFull )
489 // Bei Abbruch alten Zustand wieder herstellen
490 if ( rTEvt.IsTrackingCanceled() )
492 StartDocking();
493 Rectangle aRect( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) );
494 EndDocking( aRect, mbStartFloat );
497 else
499 HideTracking();
500 if ( rTEvt.IsTrackingCanceled() )
502 mbDockCanceled = sal_True;
503 EndDocking( Rectangle( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) ), mbLastFloatMode );
504 mbDockCanceled = sal_False;
506 else
507 EndDocking( Rectangle( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) ), mbLastFloatMode );
510 // Docking nur bei nicht synthetischen MouseEvents
511 else if ( !rTEvt.GetMouseEvent().IsSynthetic() || rTEvt.GetMouseEvent().IsModifierChanged() )
513 Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
514 Point aFrameMousePos = ImplOutputToFrame( aMousePos );
515 Size aFrameSize = mpWindowImpl->mpFrameWindow->GetOutputSizePixel();
516 if ( aFrameMousePos.X() < 0 )
517 aFrameMousePos.X() = 0;
518 if ( aFrameMousePos.Y() < 0 )
519 aFrameMousePos.Y() = 0;
520 if ( aFrameMousePos.X() > aFrameSize.Width()-1 )
521 aFrameMousePos.X() = aFrameSize.Width()-1;
522 if ( aFrameMousePos.Y() > aFrameSize.Height()-1 )
523 aFrameMousePos.Y() = aFrameSize.Height()-1;
524 aMousePos = ImplFrameToOutput( aFrameMousePos );
525 aMousePos.X() -= maMouseOff.X();
526 aMousePos.Y() -= maMouseOff.Y();
527 Point aFramePos = ImplOutputToFrame( aMousePos );
528 Rectangle aTrackRect( aFramePos, Size( mnTrackWidth, mnTrackHeight ) );
529 Rectangle aCompRect = aTrackRect;
530 aFramePos.X() += maMouseOff.X();
531 aFramePos.Y() += maMouseOff.Y();
532 if ( mbDragFull )
533 StartDocking();
534 sal_Bool bFloatMode = Docking( aFramePos, aTrackRect );
535 mbDockPrevented = sal_False;
536 mbFloatPrevented = sal_False;
537 if ( mbLastFloatMode != bFloatMode )
539 if ( bFloatMode )
541 aTrackRect.Left() -= mnDockLeft;
542 aTrackRect.Top() -= mnDockTop;
543 aTrackRect.Right() += mnDockRight;
544 aTrackRect.Bottom() += mnDockBottom;
546 else
548 if ( aCompRect == aTrackRect )
550 aTrackRect.Left() += mnDockLeft;
551 aTrackRect.Top() += mnDockTop;
552 aTrackRect.Right() -= mnDockRight;
553 aTrackRect.Bottom() -= mnDockBottom;
556 mbLastFloatMode = bFloatMode;
558 if ( mbDragFull )
560 Point aPos;
561 Point aOldPos = OutputToScreenPixel( aPos );
562 EndDocking( aTrackRect, mbLastFloatMode );
563 // Wenn der Status bzw. die Position sich
564 // geaendert hat, dann neu ausgeben
565 if ( aOldPos != OutputToScreenPixel( aPos ) )
567 ImplUpdateAll();
568 ImplGetFrameWindow()->ImplUpdateAll();
570 // EndDocking( aTrackRect, mbLastFloatMode );
572 else
574 sal_uInt16 nTrackStyle;
575 if ( bFloatMode )
576 nTrackStyle = SHOWTRACK_BIG;
577 else
578 nTrackStyle = SHOWTRACK_OBJECT;
579 Rectangle aShowTrackRect = aTrackRect;
580 aShowTrackRect.SetPos( ImplFrameToOutput( aShowTrackRect.TopLeft() ) );
581 ShowTracking( aShowTrackRect, nTrackStyle );
583 // Maus-Offset neu berechnen, da Rechteck veraendert werden
584 // konnte
585 maMouseOff.X() = aFramePos.X() - aTrackRect.Left();
586 maMouseOff.Y() = aFramePos.Y() - aTrackRect.Top();
589 mnTrackX = aTrackRect.Left();
590 mnTrackY = aTrackRect.Top();
591 mnTrackWidth = aTrackRect.GetWidth();
592 mnTrackHeight = aTrackRect.GetHeight();
597 // -----------------------------------------------------------------------
599 long DockingWindow::Notify( NotifyEvent& rNEvt )
601 if( GetDockingManager()->IsDockable( this ) ) // new docking interface
602 return Window::Notify( rNEvt );
604 if ( mbDockable )
606 if ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
608 const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
609 if ( pMEvt->IsLeft() )
611 if ( pMEvt->IsMod1() && (pMEvt->GetClicks() == 2) )
613 SetFloatingMode( !IsFloatingMode() );
614 return sal_True;
616 else if ( pMEvt->GetClicks() == 1 )
618 // check if window is floating standalone (IsFloating())
619 // or only partially floating and still docked with one border
620 // ( !mpWindowImpl->mbFrame)
621 if( ! IsFloatingMode() || ! mpFloatWin->mpWindowImpl->mbFrame )
623 Point aPos = pMEvt->GetPosPixel();
624 Window* pWindow = rNEvt.GetWindow();
625 if ( pWindow != this )
627 aPos = pWindow->OutputToScreenPixel( aPos );
628 aPos = ScreenToOutputPixel( aPos );
630 ImplStartDocking( aPos );
632 return sal_True;
636 else if( rNEvt.GetType() == EVENT_KEYINPUT )
638 const KeyCode& rKey = rNEvt.GetKeyEvent()->GetKeyCode();
639 if( rKey.GetCode() == KEY_F10 && rKey.GetModifier() &&
640 rKey.IsShift() && rKey.IsMod1() )
642 SetFloatingMode( !IsFloatingMode() );
643 return sal_True;
648 return Window::Notify( rNEvt );
651 // -----------------------------------------------------------------------
653 void DockingWindow::StartDocking()
655 mbDocking = sal_True;
658 // -----------------------------------------------------------------------
660 sal_Bool DockingWindow::Docking( const Point&, Rectangle& )
662 return IsFloatingMode();
665 // -----------------------------------------------------------------------
667 void DockingWindow::EndDocking( const Rectangle& rRect, sal_Bool bFloatMode )
669 if ( !IsDockingCanceled() )
671 bool bShow = false;
672 if ( bFloatMode != IsFloatingMode() )
674 Show( sal_False, SHOW_NOFOCUSCHANGE );
675 SetFloatingMode( bFloatMode );
676 bShow = true;
677 if ( bFloatMode && mpFloatWin )
678 mpFloatWin->SetPosSizePixel( rRect.TopLeft(), rRect.GetSize() );
680 if ( !bFloatMode )
682 Point aPos = rRect.TopLeft();
683 aPos = GetParent()->ScreenToOutputPixel( aPos );
684 Window::SetPosSizePixel( aPos, rRect.GetSize() );
687 if ( bShow )
688 Show();
690 mbDocking = sal_False;
693 // -----------------------------------------------------------------------
695 sal_Bool DockingWindow::PrepareToggleFloatingMode()
697 return sal_True;
700 // -----------------------------------------------------------------------
702 sal_Bool DockingWindow::Close()
704 ImplDelData aDelData;
705 ImplAddDel( &aDelData );
706 ImplCallEventListeners( VCLEVENT_WINDOW_CLOSE );
707 if ( aDelData.IsDead() )
708 return sal_False;
709 ImplRemoveDel( &aDelData );
711 if ( mpWindowImpl->mxWindowPeer.is() && IsCreatedWithToolkit() )
712 return sal_False;
714 Show( sal_False, SHOW_NOFOCUSCHANGE );
715 return sal_True;
718 // -----------------------------------------------------------------------
720 void DockingWindow::ToggleFloatingMode()
724 // -----------------------------------------------------------------------
726 void DockingWindow::TitleButtonClick( sal_uInt16 )
730 // -----------------------------------------------------------------------
732 void DockingWindow::Pin()
736 // -----------------------------------------------------------------------
738 void DockingWindow::Roll()
742 // -----------------------------------------------------------------------
744 void DockingWindow::PopupModeEnd()
748 // -----------------------------------------------------------------------
750 void DockingWindow::Resizing( Size& )
754 // -----------------------------------------------------------------------
756 void DockingWindow::StateChanged( StateChangedType nType )
758 switch(nType)
760 case STATE_CHANGE_CONTROLBACKGROUND:
761 ImplInitSettings();
762 Invalidate();
763 break;
765 case STATE_CHANGE_STYLE:
766 mbDockable = (GetStyle() & WB_DOCKABLE) != 0;
767 break;
769 default:
770 break;
773 Window::StateChanged( nType );
776 // -----------------------------------------------------------------------
778 void DockingWindow::DataChanged( const DataChangedEvent& rDCEvt )
780 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
781 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
783 ImplInitSettings();
784 Invalidate();
786 else
787 Window::DataChanged( rDCEvt );
790 // -----------------------------------------------------------------------
792 void DockingWindow::SetFloatingMode( sal_Bool bFloatMode )
794 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
795 if( pWrapper )
797 pWrapper->SetFloatingMode( bFloatMode );
798 return;
800 if ( IsFloatingMode() != bFloatMode )
802 if ( PrepareToggleFloatingMode() ) // changes to floating mode can be vetoed
804 sal_Bool bVisible = IsVisible();
806 if ( bFloatMode )
808 Show( sal_False, SHOW_NOFOCUSCHANGE );
810 maDockPos = Window::GetPosPixel();
812 Window* pRealParent = mpWindowImpl->mpRealParent;
813 mpOldBorderWin = mpWindowImpl->mpBorderWindow;
815 ImplDockFloatWin* pWin =
816 new ImplDockFloatWin(
817 mpImplData->mpParent,
818 mnFloatBits & ( WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) ? mnFloatBits | WB_SYSTEMWINDOW : mnFloatBits,
819 this );
820 mpFloatWin = pWin;
821 mpWindowImpl->mpBorderWindow = NULL;
822 mpWindowImpl->mnLeftBorder = 0;
823 mpWindowImpl->mnTopBorder = 0;
824 mpWindowImpl->mnRightBorder = 0;
825 mpWindowImpl->mnBottomBorder = 0;
826 // Falls Parent zerstoert wird, muessen wir auch vom
827 // BorderWindow den Parent umsetzen
828 if ( mpOldBorderWin )
829 mpOldBorderWin->SetParent( pWin );
831 // #i123765# reset the buffered DropTargets when undocking, else it may not
832 // be correctly initialized
833 mpWindowImpl->mxDNDListenerContainer.clear();
835 SetParent( pWin );
836 SetPosPixel( Point() );
837 mpWindowImpl->mpBorderWindow = pWin;
838 pWin->mpWindowImpl->mpClientWindow = this;
839 mpWindowImpl->mpRealParent = pRealParent;
840 pWin->SetText( Window::GetText() );
841 pWin->SetOutputSizePixel( Window::GetSizePixel() );
842 pWin->SetPosPixel( maFloatPos );
843 // DockingDaten ans FloatingWindow weiterreichen
844 pWin->ShowTitleButton( TITLE_BUTTON_DOCKING, mbDockBtn );
845 pWin->ShowTitleButton( TITLE_BUTTON_HIDE, mbHideBtn );
846 pWin->SetPin( mbPined );
847 if ( mbRollUp )
848 pWin->RollUp();
849 else
850 pWin->RollDown();
851 pWin->SetRollUpOutputSizePixel( maRollUpOutSize );
852 pWin->SetMinOutputSizePixel( maMinOutSize );
853 pWin->SetMaxOutputSizePixel( mpImplData->maMaxOutSize );
855 ToggleFloatingMode();
857 if ( bVisible )
858 Show();
860 else
862 Show( sal_False, SHOW_NOFOCUSCHANGE );
864 // FloatingDaten wird im FloatingWindow speichern
865 maFloatPos = mpFloatWin->GetPosPixel();
866 mbDockBtn = mpFloatWin->IsTitleButtonVisible( TITLE_BUTTON_DOCKING );
867 mbHideBtn = mpFloatWin->IsTitleButtonVisible( TITLE_BUTTON_HIDE );
868 mbPined = mpFloatWin->IsPined();
869 mbRollUp = mpFloatWin->IsRollUp();
870 maRollUpOutSize = mpFloatWin->GetRollUpOutputSizePixel();
871 maMinOutSize = mpFloatWin->GetMinOutputSizePixel();
872 mpImplData->maMaxOutSize = mpFloatWin->GetMaxOutputSizePixel();
874 Window* pRealParent = mpWindowImpl->mpRealParent;
875 mpWindowImpl->mpBorderWindow = NULL;
876 if ( mpOldBorderWin )
878 SetParent( mpOldBorderWin );
879 ((ImplBorderWindow*)mpOldBorderWin)->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
880 mpOldBorderWin->Resize();
882 mpWindowImpl->mpBorderWindow = mpOldBorderWin;
883 SetParent( pRealParent );
884 mpWindowImpl->mpRealParent = pRealParent;
885 delete static_cast<ImplDockFloatWin*>(mpFloatWin);
886 mpFloatWin = NULL;
887 SetPosPixel( maDockPos );
889 ToggleFloatingMode();
891 if ( bVisible )
892 Show();
898 // -----------------------------------------------------------------------
900 void DockingWindow::SetFloatStyle( WinBits nStyle )
902 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
903 if( pWrapper )
905 pWrapper->SetFloatStyle( nStyle );
906 return;
909 mnFloatBits = nStyle;
912 // -----------------------------------------------------------------------
914 WinBits DockingWindow::GetFloatStyle() const
916 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
917 if( pWrapper )
919 return pWrapper->GetFloatStyle();
922 return mnFloatBits;
925 // -----------------------------------------------------------------------
927 void DockingWindow::setPosSizePixel( long nX, long nY,
928 long nWidth, long nHeight,
929 sal_uInt16 nFlags )
931 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
932 if( pWrapper )
934 if ( pWrapper->mpFloatWin )
935 pWrapper->mpFloatWin->setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
936 else
937 Window::setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
938 return;
941 if ( mpFloatWin )
942 mpFloatWin->setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
943 else
944 Window::setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
947 // -----------------------------------------------------------------------
949 Point DockingWindow::GetPosPixel() const
951 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
952 if( pWrapper )
954 if ( pWrapper->mpFloatWin )
955 return pWrapper->mpFloatWin->GetPosPixel();
956 else
957 return Window::GetPosPixel();
960 if ( mpFloatWin )
961 return mpFloatWin->GetPosPixel();
962 else
963 return Window::GetPosPixel();
966 // -----------------------------------------------------------------------
968 Size DockingWindow::GetSizePixel() const
970 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
971 if( pWrapper )
973 if ( pWrapper->mpFloatWin )
974 return pWrapper->mpFloatWin->GetSizePixel();
975 else
976 return Window::GetSizePixel();
979 if ( mpFloatWin )
980 return mpFloatWin->GetSizePixel();
981 else
982 return Window::GetSizePixel();
985 // -----------------------------------------------------------------------
987 void DockingWindow::SetOutputSizePixel( const Size& rNewSize )
989 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
990 if( pWrapper )
992 if ( pWrapper->mpFloatWin )
993 pWrapper->mpFloatWin->SetOutputSizePixel( rNewSize );
994 else
995 Window::SetOutputSizePixel( rNewSize );
996 return;
999 if ( mpFloatWin )
1000 mpFloatWin->SetOutputSizePixel( rNewSize );
1001 else
1002 Window::SetOutputSizePixel( rNewSize );
1005 // -----------------------------------------------------------------------
1007 Size DockingWindow::GetOutputSizePixel() const
1009 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
1010 if( pWrapper )
1012 if ( pWrapper->mpFloatWin )
1013 return pWrapper->mpFloatWin->GetOutputSizePixel();
1014 else
1015 return Window::GetOutputSizePixel();
1018 if ( mpFloatWin )
1019 return mpFloatWin->GetOutputSizePixel();
1020 else
1021 return Window::GetOutputSizePixel();
1024 Point DockingWindow::GetFloatingPos() const
1026 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
1027 if( pWrapper )
1029 if ( pWrapper->mpFloatWin )
1031 WindowStateData aData;
1032 aData.SetMask( WINDOWSTATE_MASK_POS );
1033 pWrapper->mpFloatWin->GetWindowStateData( aData );
1034 Point aPos( aData.GetX(), aData.GetY() );
1035 aPos = pWrapper->mpFloatWin->GetParent()->ImplGetFrameWindow()->AbsoluteScreenToOutputPixel( aPos );
1036 return aPos;
1038 else
1039 return maFloatPos;
1042 if ( mpFloatWin )
1044 WindowStateData aData;
1045 aData.SetMask( WINDOWSTATE_MASK_POS );
1046 mpFloatWin->GetWindowStateData( aData );
1047 Point aPos( aData.GetX(), aData.GetY() );
1048 aPos = mpFloatWin->GetParent()->ImplGetFrameWindow()->AbsoluteScreenToOutputPixel( aPos );
1049 return aPos;
1051 else
1052 return maFloatPos;
1055 sal_Bool DockingWindow::IsFloatingMode() const
1057 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
1058 if( pWrapper )
1059 return pWrapper->IsFloatingMode();
1060 else
1061 return (mpFloatWin != NULL);
1064 void DockingWindow::SetMaxOutputSizePixel( const Size& rSize )
1066 if ( mpFloatWin )
1067 mpFloatWin->SetMaxOutputSizePixel( rSize );
1068 mpImplData->maMaxOutSize = rSize;
1071 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */