1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <tools/time.hxx>
21 #include <sal/log.hxx>
22 #include <vcl/accel.hxx>
23 #include <vcl/event.hxx>
24 #include <vcl/floatwin.hxx>
25 #include <vcl/dockwin.hxx>
26 #include <vcl/layout.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/timer.hxx>
29 #include <vcl/idle.hxx>
30 #include <vcl/settings.hxx>
31
32 #include <svdata.hxx>
33 #include <window.h>
34 #include <brdwin.hxx>
35
36 #define DOCKWIN_FLOATSTYLES (WB_SIZEABLE | WB_MOVEABLE | WB_CLOSEABLE | WB_STANDALONE | WB_ROLLABLE )
37
38 class DockingWindow::ImplData
39 {
40 public:
41 ImplData();
42
43 VclPtr<vcl::Window> mpParent;
44 Size maMaxOutSize;
45 };
46
ImplData()47 DockingWindow::ImplData::ImplData()
48 {
49 mpParent = nullptr;
50 maMaxOutSize = Size( SHRT_MAX, SHRT_MAX );
51 }
52
53 class ImplDockFloatWin : public FloatingWindow
54 {
55 private:
56 VclPtr<DockingWindow> mpDockWin;
57 sal_uInt64 const mnLastTicks;
58 Idle maDockIdle;
59 Point maDockPos;
60 tools::Rectangle maDockRect;
61 bool mbInMove;
62 ImplSVEvent * mnLastUserEvent;
63
64 DECL_LINK(DockingHdl, void *, void);
65 DECL_LINK(DockTimerHdl, Timer *, void);
66 public:
67 ImplDockFloatWin( vcl::Window* pParent, WinBits nWinBits,
68 DockingWindow* pDockingWin );
69 virtual ~ImplDockFloatWin() override;
70 virtual void dispose() override;
71
72 virtual void Move() override;
73 virtual void Resize() override;
74 virtual void Resizing( Size& rSize ) override;
75 virtual bool Close() override;
76 };
77
ImplDockFloatWin(vcl::Window * pParent,WinBits nWinBits,DockingWindow * pDockingWin)78 ImplDockFloatWin::ImplDockFloatWin( vcl::Window* pParent, WinBits nWinBits,
79 DockingWindow* pDockingWin ) :
80 FloatingWindow( pParent, nWinBits ),
81 mpDockWin( pDockingWin ),
82 mnLastTicks( tools::Time::GetSystemTicks() ),
83 mbInMove( false ),
84 mnLastUserEvent( nullptr )
85 {
86 // copy settings of DockingWindow
87 if ( pDockingWin )
88 {
89 SetSettings( pDockingWin->GetSettings() );
90 Enable( pDockingWin->IsEnabled(), false );
91 EnableInput( pDockingWin->IsInputEnabled(), false );
92 AlwaysEnableInput( pDockingWin->IsAlwaysEnableInput(), false );
93 EnableAlwaysOnTop( pDockingWin->IsAlwaysOnTopEnabled() );
94 SetActivateMode( pDockingWin->GetActivateMode() );
95 }
96
97 SetBackground();
98
99 maDockIdle.SetInvokeHandler( LINK( this, ImplDockFloatWin, DockTimerHdl ) );
100 maDockIdle.SetPriority( TaskPriority::HIGH_IDLE );
101 maDockIdle.SetDebugName( "vcl::ImplDockFloatWin maDockIdle" );
102 }
103
~ImplDockFloatWin()104 ImplDockFloatWin::~ImplDockFloatWin()
105 {
106 disposeOnce();
107 }
108
dispose()109 void ImplDockFloatWin::dispose()
110 {
111 if( mnLastUserEvent )
112 Application::RemoveUserEvent( mnLastUserEvent );
113
114 disposeBuilder();
115
116 mpDockWin.clear();
117 FloatingWindow::dispose();
118 }
119
IMPL_LINK_NOARG(ImplDockFloatWin,DockTimerHdl,Timer *,void)120 IMPL_LINK_NOARG(ImplDockFloatWin, DockTimerHdl, Timer *, void)
121 {
122 SAL_WARN_IF( !mpDockWin->IsFloatingMode(), "vcl", "docktimer called but not floating" );
123
124 maDockIdle.Stop();
125 PointerState aState = GetPointerState();
126
127 if( aState.mnState & KEY_MOD1 )
128 {
129 // i43499 CTRL disables docking now
130 mpDockWin->GetParent()->ImplGetFrameWindow()->HideTracking();
131 mpDockWin->EndDocking( maDockRect, true );
132 if( aState.mnState & ( MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT ) )
133 maDockIdle.Start();
134 }
135 else if( ! ( aState.mnState & ( MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT ) ) )
136 {
137 mpDockWin->GetParent()->ImplGetFrameWindow()->HideTracking();
138 mpDockWin->EndDocking( maDockRect, false );
139 }
140 else
141 {
142 mpDockWin->GetParent()->ImplGetFrameWindow()->ShowTracking( maDockRect, ShowTrackFlags::Big | ShowTrackFlags::TrackWindow );
143 maDockIdle.Start();
144 }
145 }
146
IMPL_LINK_NOARG(ImplDockFloatWin,DockingHdl,void *,void)147 IMPL_LINK_NOARG(ImplDockFloatWin, DockingHdl, void*, void)
148 {
149 PointerState aState = mpDockWin->GetParent()->GetPointerState();
150
151 mnLastUserEvent = nullptr;
152 if( mpDockWin->IsDockable() &&
153 (tools::Time::GetSystemTicks() - mnLastTicks > 500) &&
154 ( aState.mnState & ( MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT ) ) &&
155 !(aState.mnState & KEY_MOD1) ) // i43499 CTRL disables docking now
156 {
157 maDockPos = mpDockWin->GetParent()->AbsoluteScreenToOutputPixel( OutputToAbsoluteScreenPixel( Point() ) );
158 maDockPos = mpDockWin->GetParent()->OutputToScreenPixel( maDockPos ); // sfx expects screen coordinates
159
160 if( ! mpDockWin->IsDocking() )
161 mpDockWin->StartDocking();
162 maDockRect = tools::Rectangle( maDockPos, mpDockWin->GetSizePixel() );
163
164 // mouse pos also in screen pixels
165 Point aMousePos = mpDockWin->GetParent()->OutputToScreenPixel( aState.maPos );
166
167 bool bFloatMode = mpDockWin->Docking( aMousePos, maDockRect );
168 if( ! bFloatMode )
169 {
170 mpDockWin->GetParent()->ImplGetFrameWindow()->ShowTracking( maDockRect, ShowTrackFlags::Object | ShowTrackFlags::TrackWindow );
171 DockTimerHdl( nullptr );
172 }
173 else
174 {
175 mpDockWin->GetParent()->ImplGetFrameWindow()->HideTracking();
176 maDockIdle.Stop();
177 mpDockWin->EndDocking( maDockRect, true );
178 }
179 }
180 mbInMove = false;
181 }
182
Move()183 void ImplDockFloatWin::Move()
184 {
185 if( mbInMove )
186 return;
187
188 mbInMove = true;
189 FloatingWindow::Move();
190 mpDockWin->Move();
191
192 /*
193 * note: the window should only dock if
194 * the user releases all mouse buttons. The real problem here
195 * is that we don't get mouse events (at least not on X)
196 * if the mouse is on the decoration. So we have to start an
197 * awkward timer based process that polls the modifier/buttons
198 * to see whether they are in the right condition shortly after the
199 * last Move message.
200 */
201 if( ! mnLastUserEvent )
202 mnLastUserEvent = Application::PostUserEvent( LINK( this, ImplDockFloatWin, DockingHdl ), nullptr, true );
203 }
204
Resize()205 void ImplDockFloatWin::Resize()
206 {
207 FloatingWindow::Resize();
208 Size aSize( GetSizePixel() );
209 mpDockWin->ImplPosSizeWindow( 0, 0, aSize.Width(), aSize.Height(), PosSizeFlags::PosSize );
210 }
211
Resizing(Size & rSize)212 void ImplDockFloatWin::Resizing( Size& rSize )
213 {
214 FloatingWindow::Resizing( rSize );
215 mpDockWin->Resizing( rSize );
216 }
217
Close()218 bool ImplDockFloatWin::Close()
219 {
220 return mpDockWin->Close();
221 }
222
ImplStartDocking(const Point & rPos)223 void DockingWindow::ImplStartDocking( const Point& rPos )
224 {
225 if ( !mbDockable )
226 return;
227
228 maMouseOff = rPos;
229 mbDocking = true;
230 mbLastFloatMode = IsFloatingMode();
231 mbStartFloat = mbLastFloatMode;
232
233 // calculate FloatingBorder
234 VclPtr<FloatingWindow> pWin;
235 if ( mpFloatWin )
236 pWin = mpFloatWin;
237 else
238 pWin = VclPtr<ImplDockFloatWin>::Create( mpImplData->mpParent, mnFloatBits, nullptr );
239 pWin->GetBorder( mnDockLeft, mnDockTop, mnDockRight, mnDockBottom );
240 if ( !mpFloatWin )
241 pWin.disposeAndClear();
242
243 Point aPos = ImplOutputToFrame( Point() );
244 Size aSize = Window::GetOutputSizePixel();
245 mnTrackX = aPos.X();
246 mnTrackY = aPos.Y();
247 mnTrackWidth = aSize.Width();
248 mnTrackHeight = aSize.Height();
249
250 if ( mbLastFloatMode )
251 {
252 maMouseOff.AdjustX(mnDockLeft );
253 maMouseOff.AdjustY(mnDockTop );
254 mnTrackX -= mnDockLeft;
255 mnTrackY -= mnDockTop;
256 mnTrackWidth += mnDockLeft+mnDockRight;
257 mnTrackHeight += mnDockTop+mnDockBottom;
258 }
259
260 if ( GetSettings().GetStyleSettings().GetDragFullOptions() & DragFullOptions::Docking &&
261 !( mnFloatBits & ( WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) ) ) // no full drag when migrating to system window
262 mbDragFull = true;
263 else
264 {
265 StartDocking();
266 mbDragFull = false;
267 ImplUpdateAll();
268 ImplGetFrameWindow()->ImplUpdateAll();
269 }
270
271 StartTracking( StartTrackingFlags::KeyMod );
272 }
273
ImplInitDockingWindowData()274 void DockingWindow::ImplInitDockingWindowData()
275 {
276 mpWindowImpl->mbDockWin = true;
277 mpFloatWin = nullptr;
278 mpOldBorderWin = nullptr;
279 mpImplData.reset(new ImplData);
280 mnTrackX = 0;
281 mnTrackY = 0;
282 mnTrackWidth = 0;
283 mnTrackHeight = 0;
284 mnDockLeft = 0;
285 mnDockTop = 0;
286 mnDockRight = 0;
287 mnDockBottom = 0;
288 mnFloatBits = 0;
289 mbDockCanceled = false;
290 mbDockable = false;
291 mbDocking = false;
292 mbDragFull = false;
293 mbLastFloatMode = false;
294 mbStartFloat = false;
295 mbRollUp = false;
296 mbDockBtn = false;
297 mbHideBtn = false;
298 mbIsDeferredInit = false;
299 mbIsCalculatingInitialLayoutSize = false;
300 mpDialogParent = nullptr;
301
302 //To-Do, reuse maResizeTimer
303 maLayoutIdle.SetPriority(TaskPriority::RESIZE);
304 maLayoutIdle.SetInvokeHandler( LINK( this, DockingWindow, ImplHandleLayoutTimerHdl ) );
305 maLayoutIdle.SetDebugName( "vcl::DockingWindow maLayoutIdle" );
306 }
307
ImplInit(vcl::Window * pParent,WinBits nStyle)308 void DockingWindow::ImplInit( vcl::Window* pParent, WinBits nStyle )
309 {
310 if ( !(nStyle & WB_NODIALOGCONTROL) )
311 nStyle |= WB_DIALOGCONTROL;
312
313 mpImplData->mpParent = pParent;
314 mbDockable = (nStyle & WB_DOCKABLE) != 0;
315 mnFloatBits = WB_BORDER | (nStyle & DOCKWIN_FLOATSTYLES);
316 nStyle &= ~(DOCKWIN_FLOATSTYLES | WB_BORDER);
317
318 Window::ImplInit( pParent, nStyle, nullptr );
319
320 ImplInitSettings();
321 }
322
ImplInitSettings()323 void DockingWindow::ImplInitSettings()
324 {
325 // Hack: to be able to build DockingWindows w/o background before switching
326 // TODO: Hack
327 if ( IsBackground() )
328 {
329 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
330
331 Color aColor;
332 if ( IsControlBackground() )
333 aColor = GetControlBackground();
334 else if ( Window::GetStyle() & WB_3DLOOK )
335 aColor = rStyleSettings.GetFaceColor();
336 else
337 aColor = rStyleSettings.GetWindowColor();
338 SetBackground( aColor );
339 }
340 }
341
DockingWindow(WindowType nType)342 DockingWindow::DockingWindow( WindowType nType ) :
343 Window(nType)
344 {
345 ImplInitDockingWindowData();
346 }
347
DockingWindow(vcl::Window * pParent,WinBits nStyle)348 DockingWindow::DockingWindow( vcl::Window* pParent, WinBits nStyle ) :
349 Window( WindowType::DOCKINGWINDOW )
350 {
351 ImplInitDockingWindowData();
352 ImplInit( pParent, nStyle );
353 }
354
355 //Find the real parent stashed in mpDialogParent.
doDeferredInit(WinBits nBits)356 void DockingWindow::doDeferredInit(WinBits nBits)
357 {
358 vcl::Window *pParent = mpDialogParent;
359 mpDialogParent = nullptr;
360 ImplInit(pParent, nBits);
361 mbIsDeferredInit = false;
362 }
363
loadUI(vcl::Window * pParent,const OString & rID,const OUString & rUIXMLDescription,const css::uno::Reference<css::frame::XFrame> & rFrame)364 void DockingWindow::loadUI(vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
365 const css::uno::Reference<css::frame::XFrame> &rFrame)
366 {
367 mbIsDeferredInit = true;
368 mpDialogParent = pParent; //should be unset in doDeferredInit
369 m_pUIBuilder.reset( new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID, rFrame) );
370 }
371
DockingWindow(vcl::Window * pParent,const OString & rID,const OUString & rUIXMLDescription,const css::uno::Reference<css::frame::XFrame> & rFrame)372 DockingWindow::DockingWindow(vcl::Window* pParent, const OString& rID,
373 const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame> &rFrame)
374 : Window(WindowType::DOCKINGWINDOW)
375 {
376 ImplInitDockingWindowData();
377
378 loadUI(pParent, rID, rUIXMLDescription, rFrame);
379 }
380
~DockingWindow()381 DockingWindow::~DockingWindow()
382 {
383 disposeOnce();
384 }
385
dispose()386 void DockingWindow::dispose()
387 {
388 if ( IsFloatingMode() )
389 {
390 Show( false, ShowFlags::NoFocusChange );
391 SetFloatingMode(false);
392 }
393 mpImplData.reset();
394 mpFloatWin.clear();
395 mpOldBorderWin.clear();
396 mpDialogParent.clear();
397 disposeBuilder();
398 Window::dispose();
399 }
400
Tracking(const TrackingEvent & rTEvt)401 void DockingWindow::Tracking( const TrackingEvent& rTEvt )
402 {
403 if( GetDockingManager()->IsDockable( this ) ) // new docking interface
404 return Window::Tracking( rTEvt );
405
406 if ( mbDocking )
407 {
408 if ( rTEvt.IsTrackingEnded() )
409 {
410 mbDocking = false;
411 if ( mbDragFull )
412 {
413 // reset old state on Cancel
414 if ( rTEvt.IsTrackingCanceled() )
415 {
416 StartDocking();
417 tools::Rectangle aRect( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) );
418 EndDocking( aRect, mbStartFloat );
419 }
420 }
421 else
422 {
423 HideTracking();
424 if ( rTEvt.IsTrackingCanceled() )
425 {
426 mbDockCanceled = true;
427 EndDocking( tools::Rectangle( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) ), mbLastFloatMode );
428 mbDockCanceled = false;
429 }
430 else
431 EndDocking( tools::Rectangle( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) ), mbLastFloatMode );
432 }
433 }
434 // dock only for non-synthetic MouseEvents
435 else if ( !rTEvt.GetMouseEvent().IsSynthetic() || rTEvt.GetMouseEvent().IsModifierChanged() )
436 {
437 Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
438 Point aFrameMousePos = ImplOutputToFrame( aMousePos );
439 Size aFrameSize = mpWindowImpl->mpFrameWindow->GetOutputSizePixel();
440 if ( aFrameMousePos.X() < 0 )
441 aFrameMousePos.setX( 0 );
442 if ( aFrameMousePos.Y() < 0 )
443 aFrameMousePos.setY( 0 );
444 if ( aFrameMousePos.X() > aFrameSize.Width()-1 )
445 aFrameMousePos.setX( aFrameSize.Width()-1 );
446 if ( aFrameMousePos.Y() > aFrameSize.Height()-1 )
447 aFrameMousePos.setY( aFrameSize.Height()-1 );
448 aMousePos = ImplFrameToOutput( aFrameMousePos );
449 aMousePos.AdjustX( -(maMouseOff.X()) );
450 aMousePos.AdjustY( -(maMouseOff.Y()) );
451 Point aFramePos = ImplOutputToFrame( aMousePos );
452 tools::Rectangle aTrackRect( aFramePos, Size( mnTrackWidth, mnTrackHeight ) );
453 tools::Rectangle aCompRect = aTrackRect;
454 aFramePos.AdjustX(maMouseOff.X() );
455 aFramePos.AdjustY(maMouseOff.Y() );
456 if ( mbDragFull )
457 StartDocking();
458 bool bFloatMode = Docking( aFramePos, aTrackRect );
459 if ( mbLastFloatMode != bFloatMode )
460 {
461 if ( bFloatMode )
462 {
463 aTrackRect.AdjustLeft( -mnDockLeft );
464 aTrackRect.AdjustTop( -mnDockTop );
465 aTrackRect.AdjustRight(mnDockRight );
466 aTrackRect.AdjustBottom(mnDockBottom );
467 }
468 else
469 {
470 if ( aCompRect == aTrackRect )
471 {
472 aTrackRect.AdjustLeft(mnDockLeft );
473 aTrackRect.AdjustTop(mnDockTop );
474 aTrackRect.AdjustRight( -mnDockRight );
475 aTrackRect.AdjustBottom( -mnDockBottom );
476 }
477 }
478 mbLastFloatMode = bFloatMode;
479 }
480 if ( mbDragFull )
481 {
482 Point aOldPos = OutputToScreenPixel( Point() );
483 EndDocking( aTrackRect, mbLastFloatMode );
484 // repaint if state or position has changed
485 if ( aOldPos != OutputToScreenPixel( Point() ) )
486 {
487 ImplUpdateAll();
488 ImplGetFrameWindow()->ImplUpdateAll();
489 }
490 // EndDocking( aTrackRect, mbLastFloatMode );
491 }
492 else
493 {
494 ShowTrackFlags nTrackStyle;
495 if ( bFloatMode )
496 nTrackStyle = ShowTrackFlags::Big;
497 else
498 nTrackStyle = ShowTrackFlags::Object;
499 tools::Rectangle aShowTrackRect = aTrackRect;
500 aShowTrackRect.SetPos( ImplFrameToOutput( aShowTrackRect.TopLeft() ) );
501 ShowTracking( aShowTrackRect, nTrackStyle );
502
503 // recalculate mouse offset, as the rectangle was changed
504 maMouseOff.setX( aFramePos.X() - aTrackRect.Left() );
505 maMouseOff.setY( aFramePos.Y() - aTrackRect.Top() );
506 }
507
508 mnTrackX = aTrackRect.Left();
509 mnTrackY = aTrackRect.Top();
510 mnTrackWidth = aTrackRect.GetWidth();
511 mnTrackHeight = aTrackRect.GetHeight();
512 }
513 }
514 }
515
EventNotify(NotifyEvent & rNEvt)516 bool DockingWindow::EventNotify( NotifyEvent& rNEvt )
517 {
518 if( GetDockingManager()->IsDockable( this ) ) // new docking interface
519 return Window::EventNotify( rNEvt );
520
521 if ( mbDockable )
522 {
523 const bool bDockingSupportCrippled = !StyleSettings::GetDockingFloatsSupported();
524
525 if ( rNEvt.GetType() == MouseNotifyEvent::MOUSEBUTTONDOWN )
526 {
527 const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
528 if ( pMEvt->IsLeft() )
529 {
530 if (!bDockingSupportCrippled && pMEvt->IsMod1() && (pMEvt->GetClicks() == 2) )
531 {
532 SetFloatingMode( !IsFloatingMode() );
533 if ( IsFloatingMode() )
534 ToTop( ToTopFlags::GrabFocusOnly );
535 return true;
536 }
537 else if ( pMEvt->GetClicks() == 1 )
538 {
539 // check if window is floating standalone (IsFloating())
540 // or only partially floating and still docked with one border
541 // ( !mpWindowImpl->mbFrame)
542 if( ! IsFloatingMode() || ! mpFloatWin->mpWindowImpl->mbFrame )
543 {
544 Point aPos = pMEvt->GetPosPixel();
545 vcl::Window* pWindow = rNEvt.GetWindow();
546 if ( pWindow != this )
547 {
548 aPos = pWindow->OutputToScreenPixel( aPos );
549 aPos = ScreenToOutputPixel( aPos );
550 }
551 ImplStartDocking( aPos );
552 }
553 return true;
554 }
555 }
556 }
557 else if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
558 {
559 const vcl::KeyCode& rKey = rNEvt.GetKeyEvent()->GetKeyCode();
560 if( rKey.GetCode() == KEY_F10 && rKey.GetModifier() &&
561 rKey.IsShift() && rKey.IsMod1() && !bDockingSupportCrippled )
562 {
563 SetFloatingMode( !IsFloatingMode() );
564 if ( IsFloatingMode() )
565 ToTop( ToTopFlags::GrabFocusOnly );
566 return true;
567 }
568 }
569 }
570
571 return Window::EventNotify( rNEvt );
572 }
573
StartDocking()574 void DockingWindow::StartDocking()
575 {
576 mbDocking = true;
577 }
578
Docking(const Point &,tools::Rectangle &)579 bool DockingWindow::Docking( const Point&, tools::Rectangle& )
580 {
581 return IsFloatingMode();
582 }
583
EndDocking(const tools::Rectangle & rRect,bool bFloatMode)584 void DockingWindow::EndDocking( const tools::Rectangle& rRect, bool bFloatMode )
585 {
586 bool bOrigDockCanceled = mbDockCanceled;
587 if (bFloatMode && !StyleSettings::GetDockingFloatsSupported())
588 mbDockCanceled = true;
589
590 if ( !IsDockingCanceled() )
591 {
592 if ( bFloatMode != IsFloatingMode() )
593 {
594 SetFloatingMode( bFloatMode );
595 if ( IsFloatingMode() )
596 ToTop( ToTopFlags::GrabFocusOnly );
597 if ( bFloatMode && mpFloatWin )
598 mpFloatWin->SetPosSizePixel( rRect.TopLeft(), rRect.GetSize() );
599 }
600 if ( !bFloatMode )
601 {
602 Point aPos = rRect.TopLeft();
603 aPos = GetParent()->ScreenToOutputPixel( aPos );
604 Window::SetPosSizePixel( aPos, rRect.GetSize() );
605 }
606 }
607 mbDocking = false;
608 mbDockCanceled = bOrigDockCanceled;
609 }
610
PrepareToggleFloatingMode()611 bool DockingWindow::PrepareToggleFloatingMode()
612 {
613 return true;
614 }
615
Close()616 bool DockingWindow::Close()
617 {
618 VclPtr<vcl::Window> xWindow = this;
619 CallEventListeners( VclEventId::WindowClose );
620 if ( xWindow->IsDisposed() )
621 return false;
622
623 if ( mpWindowImpl->mxWindowPeer.is() && IsCreatedWithToolkit() )
624 return false;
625
626 Show( false, ShowFlags::NoFocusChange );
627 return true;
628 }
629
ToggleFloatingMode()630 void DockingWindow::ToggleFloatingMode()
631 {
632 }
633
Resizing(Size &)634 void DockingWindow::Resizing( Size& )
635 {
636 }
637
DoInitialLayout()638 void DockingWindow::DoInitialLayout()
639 {
640 if (GetSettings().GetStyleSettings().GetAutoMnemonic())
641 Accelerator::GenerateAutoMnemonicsOnHierarchy(this);
642
643 if (isLayoutEnabled())
644 {
645 mbIsCalculatingInitialLayoutSize = true;
646 setDeferredProperties();
647 if (IsFloatingMode())
648 setOptimalLayoutSize();
649 mbIsCalculatingInitialLayoutSize = false;
650 }
651 }
652
StateChanged(StateChangedType nType)653 void DockingWindow::StateChanged( StateChangedType nType )
654 {
655 switch(nType)
656 {
657 case StateChangedType::InitShow:
658 DoInitialLayout();
659 break;
660
661 case StateChangedType::ControlBackground:
662 ImplInitSettings();
663 Invalidate();
664 break;
665
666 case StateChangedType::Style:
667 mbDockable = (GetStyle() & WB_DOCKABLE) != 0;
668 break;
669
670 default:
671 break;
672 }
673
674 Window::StateChanged( nType );
675 }
676
DataChanged(const DataChangedEvent & rDCEvt)677 void DockingWindow::DataChanged( const DataChangedEvent& rDCEvt )
678 {
679 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
680 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
681 {
682 ImplInitSettings();
683 Invalidate();
684 }
685 else
686 Window::DataChanged( rDCEvt );
687 }
688
SetFloatingMode(bool bFloatMode)689 void DockingWindow::SetFloatingMode( bool bFloatMode )
690 {
691 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
692 if( pWrapper )
693 {
694 pWrapper->SetFloatingMode( bFloatMode );
695 return;
696 }
697 if ( IsFloatingMode() != bFloatMode )
698 {
699 if ( PrepareToggleFloatingMode() ) // changes to floating mode can be vetoed
700 {
701 bool bVisible = IsVisible();
702
703 if ( bFloatMode )
704 {
705 // set deferred properties early, so border width will end up
706 // in our mpWindowImpl->mnBorderWidth, not in mpBorderWindow.
707 // (see its usage in setPosSizeOnContainee and GetOptimalSize.)
708 setDeferredProperties();
709
710 Show( false, ShowFlags::NoFocusChange );
711
712 maDockPos = Window::GetPosPixel();
713
714 vcl::Window* pRealParent = mpWindowImpl->mpRealParent;
715 mpOldBorderWin = mpWindowImpl->mpBorderWindow;
716
717 VclPtrInstance<ImplDockFloatWin> pWin(
718 mpImplData->mpParent,
719 mnFloatBits & ( WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) ? mnFloatBits | WB_SYSTEMWINDOW : mnFloatBits,
720 this );
721 mpFloatWin = pWin;
722 mpWindowImpl->mpBorderWindow = nullptr;
723 mpWindowImpl->mnLeftBorder = 0;
724 mpWindowImpl->mnTopBorder = 0;
725 mpWindowImpl->mnRightBorder = 0;
726 mpWindowImpl->mnBottomBorder = 0;
727 // if the parent gets destroyed, we also have to reset the parent of the BorderWindow
728 if ( mpOldBorderWin )
729 mpOldBorderWin->SetParent( pWin );
730
731 // #i123765# reset the buffered DropTargets when undocking, else it may not
732 // be correctly initialized
733 mpWindowImpl->mxDNDListenerContainer.clear();
734
735 SetParent( pWin );
736 SetPosPixel( Point() );
737 mpWindowImpl->mpBorderWindow = pWin;
738 pWin->mpWindowImpl->mpClientWindow = this;
739 mpWindowImpl->mpRealParent = pRealParent;
740 pWin->SetText( Window::GetText() );
741 Size aSize(Window::GetSizePixel());
742 pWin->SetOutputSizePixel(aSize);
743 pWin->SetPosPixel( maFloatPos );
744 // pass on DockingData to FloatingWindow
745 pWin->ShowTitleButton( TitleButton::Docking, mbDockBtn );
746 pWin->ShowTitleButton( TitleButton::Hide, mbHideBtn );
747 if ( mbRollUp )
748 pWin->RollUp();
749 else
750 pWin->RollDown();
751 pWin->SetRollUpOutputSizePixel( maRollUpOutSize );
752 pWin->SetMinOutputSizePixel( maMinOutSize );
753
754 pWin->SetMaxOutputSizePixel( mpImplData->maMaxOutSize );
755
756 ToggleFloatingMode();
757
758 if ( bVisible )
759 Show();
760 }
761 else
762 {
763 Show( false, ShowFlags::NoFocusChange );
764
765 // store FloatingData in FloatingWindow
766 maFloatPos = mpFloatWin->GetPosPixel();
767 mbDockBtn = mpFloatWin->IsTitleButtonVisible( TitleButton::Docking );
768 mbHideBtn = mpFloatWin->IsTitleButtonVisible( TitleButton::Hide );
769 mbRollUp = mpFloatWin->IsRollUp();
770 maRollUpOutSize = mpFloatWin->GetRollUpOutputSizePixel();
771 maMinOutSize = mpFloatWin->GetMinOutputSizePixel();
772 mpImplData->maMaxOutSize = mpFloatWin->GetMaxOutputSizePixel();
773
774 vcl::Window* pRealParent = mpWindowImpl->mpRealParent;
775 mpWindowImpl->mpBorderWindow = nullptr;
776 if ( mpOldBorderWin )
777 {
778 SetParent( mpOldBorderWin );
779 static_cast<ImplBorderWindow*>(mpOldBorderWin.get())->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
780 mpOldBorderWin->Resize();
781 }
782 mpWindowImpl->mpBorderWindow = mpOldBorderWin;
783 SetParent( pRealParent );
784 mpWindowImpl->mpRealParent = pRealParent;
785 mpFloatWin.disposeAndClear();
786 SetPosPixel( maDockPos );
787
788 ToggleFloatingMode();
789
790 if ( bVisible )
791 Show();
792 }
793 }
794 }
795 }
796
SetFloatStyle(WinBits nStyle)797 void DockingWindow::SetFloatStyle( WinBits nStyle )
798 {
799 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
800 if( pWrapper )
801 {
802 pWrapper->SetFloatStyle( nStyle );
803 return;
804 }
805
806 mnFloatBits = nStyle;
807 }
808
GetFloatStyle() const809 WinBits DockingWindow::GetFloatStyle() const
810 {
811 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
812 if( pWrapper )
813 {
814 return pWrapper->GetFloatStyle();
815 }
816
817 return mnFloatBits;
818 }
819
setPosSizePixel(long nX,long nY,long nWidth,long nHeight,PosSizeFlags nFlags)820 void DockingWindow::setPosSizePixel( long nX, long nY,
821 long nWidth, long nHeight,
822 PosSizeFlags nFlags )
823 {
824 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
825 if (pWrapper)
826 {
827 if (!pWrapper->mpFloatWin)
828 Window::setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
829 }
830 else
831 {
832 if (!mpFloatWin)
833 Window::setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
834 else
835 {
836 mpFloatWin->SetOutputSizePixel(Size(nWidth, nHeight));
837 mpFloatWin->SetPosPixel(Point(nX, nY));
838 }
839 }
840
841 if (::isLayoutEnabled(this))
842 setPosSizeOnContainee();
843 }
844
GetPosPixel() const845 Point DockingWindow::GetPosPixel() const
846 {
847 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
848 if( pWrapper )
849 {
850 if ( pWrapper->mpFloatWin )
851 return pWrapper->mpFloatWin->GetPosPixel();
852 else
853 return Window::GetPosPixel();
854 }
855
856 if ( mpFloatWin )
857 return mpFloatWin->GetPosPixel();
858 else
859 return Window::GetPosPixel();
860 }
861
GetSizePixel() const862 Size DockingWindow::GetSizePixel() const
863 {
864 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
865 if( pWrapper )
866 {
867 if ( pWrapper->mpFloatWin )
868 return pWrapper->mpFloatWin->GetSizePixel();
869 else
870 return Window::GetSizePixel();
871 }
872
873 if ( mpFloatWin )
874 return mpFloatWin->GetSizePixel();
875 else
876 return Window::GetSizePixel();
877 }
878
SetOutputSizePixel(const Size & rNewSize)879 void DockingWindow::SetOutputSizePixel( const Size& rNewSize )
880 {
881 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
882 if( pWrapper )
883 {
884 if ( pWrapper->mpFloatWin )
885 pWrapper->mpFloatWin->SetOutputSizePixel( rNewSize );
886 else
887 Window::SetOutputSizePixel( rNewSize );
888 return;
889 }
890
891 if ( mpFloatWin )
892 mpFloatWin->SetOutputSizePixel( rNewSize );
893 else
894 Window::SetOutputSizePixel( rNewSize );
895 }
896
GetOutputSizePixel() const897 Size DockingWindow::GetOutputSizePixel() const
898 {
899 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
900 if( pWrapper )
901 {
902 if ( pWrapper->mpFloatWin )
903 return pWrapper->mpFloatWin->GetOutputSizePixel();
904 else
905 return Window::GetOutputSizePixel();
906 }
907
908 if ( mpFloatWin )
909 return mpFloatWin->GetOutputSizePixel();
910 else
911 return Window::GetOutputSizePixel();
912 }
913
GetFloatingPos() const914 Point DockingWindow::GetFloatingPos() const
915 {
916 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
917 if( pWrapper )
918 {
919 if ( pWrapper->mpFloatWin )
920 {
921 WindowStateData aData;
922 aData.SetMask( WindowStateMask::Pos );
923 pWrapper->mpFloatWin->GetWindowStateData( aData );
924 Point aPos( aData.GetX(), aData.GetY() );
925 aPos = pWrapper->mpFloatWin->GetParent()->ImplGetFrameWindow()->AbsoluteScreenToOutputPixel( aPos );
926 return aPos;
927 }
928 else
929 return maFloatPos;
930 }
931
932 if ( mpFloatWin )
933 {
934 WindowStateData aData;
935 aData.SetMask( WindowStateMask::Pos );
936 mpFloatWin->GetWindowStateData( aData );
937 Point aPos( aData.GetX(), aData.GetY() );
938 aPos = mpFloatWin->GetParent()->ImplGetFrameWindow()->AbsoluteScreenToOutputPixel( aPos );
939 return aPos;
940 }
941 else
942 return maFloatPos;
943 }
944
IsFloatingMode() const945 bool DockingWindow::IsFloatingMode() const
946 {
947 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
948 if( pWrapper )
949 return pWrapper->IsFloatingMode();
950 else
951 return (mpFloatWin != nullptr);
952 }
953
SetMaxOutputSizePixel(const Size & rSize)954 void DockingWindow::SetMaxOutputSizePixel( const Size& rSize )
955 {
956 if ( mpFloatWin )
957 mpFloatWin->SetMaxOutputSizePixel( rSize );
958 mpImplData->maMaxOutSize = rSize;
959 }
960
SetText(const OUString & rStr)961 void DockingWindow::SetText(const OUString& rStr)
962 {
963 setDeferredProperties();
964 Window::SetText(rStr);
965 }
966
GetText() const967 OUString DockingWindow::GetText() const
968 {
969 const_cast<DockingWindow*>(this)->setDeferredProperties();
970 return Window::GetText();
971 }
972
isLayoutEnabled() const973 bool DockingWindow::isLayoutEnabled() const
974 {
975 //pre dtor called, and single child is a container => we're layout enabled
976 return mpImplData && ::isLayoutEnabled(this);
977 }
978
setOptimalLayoutSize()979 void DockingWindow::setOptimalLayoutSize()
980 {
981 maLayoutIdle.Stop();
982
983 //resize DockingWindow to fit requisition on initial show
984 Size aSize = get_preferred_size();
985
986 Size aMax(bestmaxFrameSizeForScreenSize(GetDesktopRectPixel().GetSize()));
987
988 aSize.setWidth( std::min(aMax.Width(), aSize.Width()) );
989 aSize.setHeight( std::min(aMax.Height(), aSize.Height()) );
990
991 SetMinOutputSizePixel(aSize);
992 setPosSizeOnContainee();
993 }
994
setPosSizeOnContainee()995 void DockingWindow::setPosSizeOnContainee()
996 {
997 Size aSize = GetOutputSizePixel();
998
999 // Don't make the border width accessible via get_border_width(),
1000 // otherwise the floating window will handle the border as well.
1001 sal_Int32 nBorderWidth = mpWindowImpl->mnBorderWidth;
1002
1003 aSize.AdjustWidth( -(2 * nBorderWidth) );
1004 aSize.AdjustHeight( -(2 * nBorderWidth) );
1005
1006 Window* pBox = GetWindow(GetWindowType::FirstChild);
1007 assert(pBox);
1008 VclContainer::setLayoutAllocation(*pBox, Point(nBorderWidth, nBorderWidth), aSize);
1009 }
1010
GetOptimalSize() const1011 Size DockingWindow::GetOptimalSize() const
1012 {
1013 if (!isLayoutEnabled())
1014 return Window::GetOptimalSize();
1015
1016 Size aSize = VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
1017
1018 // Don't make the border width accessible via get_border_width(),
1019 // otherwise the floating window will handle the border as well.
1020 sal_Int32 nBorderWidth = mpWindowImpl->mnBorderWidth;
1021
1022 aSize.AdjustHeight(2 * nBorderWidth );
1023 aSize.AdjustWidth(2 * nBorderWidth );
1024
1025 return aSize;
1026 }
1027
queue_resize(StateChangedType eReason)1028 void DockingWindow::queue_resize(StateChangedType eReason)
1029 {
1030 bool bTriggerLayout = true;
1031 if (maLayoutIdle.IsActive() || mbIsCalculatingInitialLayoutSize)
1032 {
1033 bTriggerLayout = false;
1034 }
1035 if (!isLayoutEnabled())
1036 {
1037 bTriggerLayout = false;
1038 }
1039 if (bTriggerLayout)
1040 {
1041 InvalidateSizeCache();
1042 maLayoutIdle.Start();
1043 }
1044 vcl::Window::queue_resize(eReason);
1045 }
1046
IMPL_LINK_NOARG(DockingWindow,ImplHandleLayoutTimerHdl,Timer *,void)1047 IMPL_LINK_NOARG(DockingWindow, ImplHandleLayoutTimerHdl, Timer*, void)
1048 {
1049 if (!isLayoutEnabled())
1050 {
1051 SAL_WARN("vcl.layout", "DockingWindow has become non-layout because extra children have been added directly to it.");
1052 return;
1053 }
1054 setPosSizeOnContainee();
1055 }
1056
1057 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1058