1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/menu.hxx>
24 #include <vcl/event.hxx>
25 #include <vcl/syswin.hxx>
26 #include <vcl/taskpanelist.hxx>
27 #include <vcl/unowrap.hxx>
29 #include <rtl/strbuf.hxx>
31 #include <salframe.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::lang
;
39 // =======================================================================
40 class SystemWindow::ImplData
46 TaskPaneList
* mpTaskPaneList
;
48 OUString maRepresentedURL
;
52 SystemWindow::ImplData::ImplData()
54 mpTaskPaneList
= NULL
;
55 maMaxOutSize
= Size( SHRT_MAX
, SHRT_MAX
);
58 SystemWindow::ImplData::~ImplData()
61 delete mpTaskPaneList
;
64 // =======================================================================
66 SystemWindow::SystemWindow( WindowType nType
) :
69 mpImplData
= new ImplData
;
70 mpWindowImpl
->mbSysWin
= sal_True
;
71 mpWindowImpl
->mnActivateMode
= ACTIVATE_MODE_GRABFOCUS
;
76 mbRollFunc
= sal_False
;
77 mbDockBtn
= sal_False
;
78 mbHideBtn
= sal_False
;
79 mbSysChild
= sal_False
;
80 mnMenuBarMode
= MENUBAR_MODE_NORMAL
;
84 SystemWindow::~SystemWindow()
90 // -----------------------------------------------------------------------
92 long SystemWindow::Notify( NotifyEvent
& rNEvt
)
94 // capture KeyEvents for menu handling
95 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
97 MenuBar
* pMBar
= mpMenuBar
;
98 if ( !pMBar
&& ( GetType() == WINDOW_FLOATINGWINDOW
) )
100 Window
* pWin
= ImplGetFrameWindow()->ImplGetWindow();
101 if( pWin
&& pWin
->IsSystemWindow() )
102 pMBar
= ((SystemWindow
*)pWin
)->GetMenuBar();
104 if ( pMBar
&& pMBar
->ImplHandleKeyEvent( *rNEvt
.GetKeyEvent(), sal_False
) )
108 return Window::Notify( rNEvt
);
111 // -----------------------------------------------------------------------
113 long SystemWindow::PreNotify( NotifyEvent
& rNEvt
)
115 // capture KeyEvents for taskpane cycling
116 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
118 if( rNEvt
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F6
&&
119 rNEvt
.GetKeyEvent()->GetKeyCode().IsMod1() &&
120 !rNEvt
.GetKeyEvent()->GetKeyCode().IsShift() )
122 // Ctrl-F6 goes directly to the document
123 GrabFocusToDocument();
128 TaskPaneList
*pTList
= mpImplData
->mpTaskPaneList
;
129 if( !pTList
&& ( GetType() == WINDOW_FLOATINGWINDOW
) )
131 Window
* pWin
= ImplGetFrameWindow()->ImplGetWindow();
132 if( pWin
&& pWin
->IsSystemWindow() )
133 pTList
= ((SystemWindow
*)pWin
)->mpImplData
->mpTaskPaneList
;
137 // search topmost system window which is the one to handle dialog/toolbar cycling
138 SystemWindow
*pSysWin
= this;
142 pWin
= pWin
->GetParent();
143 if( pWin
&& pWin
->IsSystemWindow() )
144 pSysWin
= (SystemWindow
*) pWin
;
146 pTList
= pSysWin
->mpImplData
->mpTaskPaneList
;
148 if( pTList
&& pTList
->HandleKeyEvent( *rNEvt
.GetKeyEvent() ) )
152 return Window::PreNotify( rNEvt
);
155 // -----------------------------------------------------------------------
157 TaskPaneList
* SystemWindow::GetTaskPaneList()
159 if( mpImplData
->mpTaskPaneList
)
160 return mpImplData
->mpTaskPaneList
;
163 mpImplData
->mpTaskPaneList
= new TaskPaneList();
164 MenuBar
* pMBar
= mpMenuBar
;
165 if ( !pMBar
&& ( GetType() == WINDOW_FLOATINGWINDOW
) )
167 Window
* pWin
= ImplGetFrameWindow()->ImplGetWindow();
168 if ( pWin
&& pWin
->IsSystemWindow() )
169 pMBar
= ((SystemWindow
*)pWin
)->GetMenuBar();
172 mpImplData
->mpTaskPaneList
->AddWindow( pMBar
->ImplGetWindow() );
173 return mpImplData
->mpTaskPaneList
;
177 // -----------------------------------------------------------------------
179 sal_Bool
SystemWindow::Close()
181 ImplDelData aDelData
;
182 ImplAddDel( &aDelData
);
183 ImplCallEventListeners( VCLEVENT_WINDOW_CLOSE
);
184 if ( aDelData
.IsDead() )
186 ImplRemoveDel( &aDelData
);
188 if ( mpWindowImpl
->mxWindowPeer
.is() && IsCreatedWithToolkit() )
191 // Is Window not closeable, ignore close
192 Window
* pBorderWin
= ImplGetBorderWindow();
195 nStyle
= pBorderWin
->GetStyle();
198 if ( !(nStyle
& WB_CLOSEABLE
) )
206 // -----------------------------------------------------------------------
208 void SystemWindow::TitleButtonClick( sal_uInt16
)
212 // -----------------------------------------------------------------------
214 void SystemWindow::Pin()
218 // -----------------------------------------------------------------------
220 void SystemWindow::Roll()
224 // -----------------------------------------------------------------------
226 void SystemWindow::Resizing( Size
& )
230 // -----------------------------------------------------------------------
232 void SystemWindow::SetRepresentedURL( const OUString
& i_rURL
)
234 bool bChanged
= (i_rURL
!= mpImplData
->maRepresentedURL
);
235 mpImplData
->maRepresentedURL
= i_rURL
;
236 if ( !mbSysChild
&& bChanged
)
238 const Window
* pWindow
= this;
239 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
240 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
242 if ( pWindow
->mpWindowImpl
->mbFrame
)
243 pWindow
->mpWindowImpl
->mpFrame
->SetRepresentedURL( i_rURL
);
247 // -----------------------------------------------------------------------
249 void SystemWindow::SetIcon( sal_uInt16 nIcon
)
251 if ( mnIcon
== nIcon
)
258 const Window
* pWindow
= this;
259 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
260 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
262 if ( pWindow
->mpWindowImpl
->mbFrame
)
263 pWindow
->mpWindowImpl
->mpFrame
->SetIcon( nIcon
);
267 // -----------------------------------------------------------------------
269 void SystemWindow::EnableSaveBackground( sal_Bool bSave
)
271 if( ImplGetSVData()->maWinData
.mbNoSaveBackground
)
274 Window
* pWindow
= this;
275 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
276 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
277 if ( pWindow
->mpWindowImpl
->mbOverlapWin
&& !pWindow
->mpWindowImpl
->mbFrame
)
279 pWindow
->mpWindowImpl
->mpOverlapData
->mbSaveBack
= bSave
;
281 pWindow
->ImplDeleteOverlapBackground();
285 // -----------------------------------------------------------------------
287 sal_Bool
SystemWindow::IsSaveBackgroundEnabled() const
289 const Window
* pWindow
= this;
290 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
291 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
292 if ( pWindow
->mpWindowImpl
->mpOverlapData
)
293 return pWindow
->mpWindowImpl
->mpOverlapData
->mbSaveBack
;
298 // -----------------------------------------------------------------------
300 void SystemWindow::ShowTitleButton( sal_uInt16 nButton
, sal_Bool bVisible
)
302 if ( nButton
== TITLE_BUTTON_DOCKING
)
304 if ( mbDockBtn
!= bVisible
)
306 mbDockBtn
= bVisible
;
307 if ( mpWindowImpl
->mpBorderWindow
)
308 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetDockButton( bVisible
);
311 else if ( nButton
== TITLE_BUTTON_HIDE
)
313 if ( mbHideBtn
!= bVisible
)
315 mbHideBtn
= bVisible
;
316 if ( mpWindowImpl
->mpBorderWindow
)
317 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetHideButton( bVisible
);
320 else if ( nButton
== TITLE_BUTTON_MENU
)
322 if ( mpWindowImpl
->mpBorderWindow
)
323 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetMenuButton( bVisible
);
329 // -----------------------------------------------------------------------
331 sal_Bool
SystemWindow::IsTitleButtonVisible( sal_uInt16 nButton
) const
333 if ( nButton
== TITLE_BUTTON_DOCKING
)
335 else /* if ( nButton == TITLE_BUTTON_HIDE ) */
339 // -----------------------------------------------------------------------
341 void SystemWindow::SetPin( sal_Bool bPin
)
343 if ( bPin
!= mbPined
)
346 if ( mpWindowImpl
->mpBorderWindow
)
347 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetPin( bPin
);
351 // -----------------------------------------------------------------------
353 void SystemWindow::RollUp()
357 maOrgSize
= GetOutputSizePixel();
358 mbRollFunc
= sal_True
;
359 Size aSize
= maRollUpOutSize
;
360 if ( !aSize
.Width() )
361 aSize
.Width() = GetOutputSizePixel().Width();
363 if ( mpWindowImpl
->mpBorderWindow
)
364 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetRollUp( sal_True
, aSize
);
366 SetOutputSizePixel( aSize
);
367 mbRollFunc
= sal_False
;
371 // -----------------------------------------------------------------------
373 void SystemWindow::RollDown()
377 mbRollUp
= sal_False
;
378 if ( mpWindowImpl
->mpBorderWindow
)
379 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetRollUp( sal_False
, maOrgSize
);
381 SetOutputSizePixel( maOrgSize
);
385 // -----------------------------------------------------------------------
387 void SystemWindow::SetMinOutputSizePixel( const Size
& rSize
)
389 maMinOutSize
= rSize
;
390 if ( mpWindowImpl
->mpBorderWindow
)
392 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetMinOutputSize( rSize
.Width(), rSize
.Height() );
393 if ( mpWindowImpl
->mpBorderWindow
->mpWindowImpl
->mbFrame
)
394 mpWindowImpl
->mpBorderWindow
->mpWindowImpl
->mpFrame
->SetMinClientSize( rSize
.Width(), rSize
.Height() );
396 else if ( mpWindowImpl
->mbFrame
)
397 mpWindowImpl
->mpFrame
->SetMinClientSize( rSize
.Width(), rSize
.Height() );
400 // -----------------------------------------------------------------------
402 void SystemWindow::SetMaxOutputSizePixel( const Size
& rSize
)
405 if( aSize
.Width() > SHRT_MAX
|| aSize
.Width() <= 0 )
406 aSize
.Width() = SHRT_MAX
;
407 if( aSize
.Height() > SHRT_MAX
|| aSize
.Height() <= 0 )
408 aSize
.Height() = SHRT_MAX
;
410 mpImplData
->maMaxOutSize
= aSize
;
411 if ( mpWindowImpl
->mpBorderWindow
)
413 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetMaxOutputSize( aSize
.Width(), aSize
.Height() );
414 if ( mpWindowImpl
->mpBorderWindow
->mpWindowImpl
->mbFrame
)
415 mpWindowImpl
->mpBorderWindow
->mpWindowImpl
->mpFrame
->SetMaxClientSize( aSize
.Width(), aSize
.Height() );
417 else if ( mpWindowImpl
->mbFrame
)
418 mpWindowImpl
->mpFrame
->SetMaxClientSize( aSize
.Width(), aSize
.Height() );
421 const Size
& SystemWindow::GetMaxOutputSizePixel() const
423 return mpImplData
->maMaxOutSize
;
425 // -----------------------------------------------------------------------
427 Size
SystemWindow::GetResizeOutputSizePixel() const
429 Size aSize
= GetOutputSizePixel();
430 if ( aSize
.Width() < maMinOutSize
.Width() )
431 aSize
.Width() = maMinOutSize
.Width();
432 if ( aSize
.Height() < maMinOutSize
.Height() )
433 aSize
.Height() = maMinOutSize
.Height();
437 // -----------------------------------------------------------------------
439 static void ImplWindowStateFromStr(WindowStateData
& rData
,
442 sal_uLong nValidMask
= 0;
443 sal_Int32 nIndex
= 0;
446 aTokenStr
= rStr
.getToken(0, ',', nIndex
);
447 if (!aTokenStr
.isEmpty())
449 rData
.SetX(aTokenStr
.toInt32());
450 if( rData
.GetX() > -16384 && rData
.GetX() < 16384 )
451 nValidMask
|= WINDOWSTATE_MASK_X
;
457 aTokenStr
= rStr
.getToken(0, ',', nIndex
);
458 if (!aTokenStr
.isEmpty())
460 rData
.SetY(aTokenStr
.toInt32());
461 if( rData
.GetY() > -16384 && rData
.GetY() < 16384 )
462 nValidMask
|= WINDOWSTATE_MASK_Y
;
468 aTokenStr
= rStr
.getToken(0, ',', nIndex
);
469 if (!aTokenStr
.isEmpty())
471 rData
.SetWidth(aTokenStr
.toInt32());
472 if( rData
.GetWidth() > 0 && rData
.GetWidth() < 16384 )
473 nValidMask
|= WINDOWSTATE_MASK_WIDTH
;
479 aTokenStr
= rStr
.getToken(0, ';', nIndex
);
480 if (!aTokenStr
.isEmpty())
482 rData
.SetHeight(aTokenStr
.toInt32());
483 if( rData
.GetHeight() > 0 && rData
.GetHeight() < 16384 )
484 nValidMask
|= WINDOWSTATE_MASK_HEIGHT
;
486 rData
.SetHeight( 0 );
489 rData
.SetHeight( 0 );
490 aTokenStr
= rStr
.getToken(0, ';', nIndex
);
491 if (!aTokenStr
.isEmpty())
493 // #94144# allow Minimize again, should be masked out when read from configuration
494 // 91625 - ignore Minimize
495 sal_uInt32 nState
= (sal_uInt32
)aTokenStr
.toInt32();
496 //nState &= ~(WINDOWSTATE_STATE_MINIMIZED);
497 rData
.SetState( nState
);
498 nValidMask
|= WINDOWSTATE_MASK_STATE
;
503 // read maximized pos/size
504 aTokenStr
= rStr
.getToken(0, ',', nIndex
);
505 if (!aTokenStr
.isEmpty())
507 rData
.SetMaximizedX(aTokenStr
.toInt32());
508 if( rData
.GetMaximizedX() > -16384 && rData
.GetMaximizedX() < 16384 )
509 nValidMask
|= WINDOWSTATE_MASK_MAXIMIZED_X
;
511 rData
.SetMaximizedX( 0 );
514 rData
.SetMaximizedX( 0 );
515 aTokenStr
= rStr
.getToken(0, ',', nIndex
);
516 if (!aTokenStr
.isEmpty())
518 rData
.SetMaximizedY(aTokenStr
.toInt32());
519 if( rData
.GetMaximizedY() > -16384 && rData
.GetMaximizedY() < 16384 )
520 nValidMask
|= WINDOWSTATE_MASK_MAXIMIZED_Y
;
522 rData
.SetMaximizedY( 0 );
525 rData
.SetMaximizedY( 0 );
526 aTokenStr
= rStr
.getToken(0, ',', nIndex
);
527 if (!aTokenStr
.isEmpty())
529 rData
.SetMaximizedWidth(aTokenStr
.toInt32());
530 if( rData
.GetMaximizedWidth() > 0 && rData
.GetMaximizedWidth() < 16384 )
531 nValidMask
|= WINDOWSTATE_MASK_MAXIMIZED_WIDTH
;
533 rData
.SetMaximizedWidth( 0 );
536 rData
.SetMaximizedWidth( 0 );
537 aTokenStr
= rStr
.getToken(0, ';', nIndex
);
538 if (!aTokenStr
.isEmpty())
540 rData
.SetMaximizedHeight(aTokenStr
.toInt32());
541 if( rData
.GetMaximizedHeight() > 0 && rData
.GetMaximizedHeight() < 16384 )
542 nValidMask
|= WINDOWSTATE_MASK_MAXIMIZED_HEIGHT
;
544 rData
.SetMaximizedHeight( 0 );
547 rData
.SetMaximizedHeight( 0 );
550 rData
.SetMask( nValidMask
);
553 // -----------------------------------------------------------------------
555 static OString
ImplWindowStateToStr(const WindowStateData
& rData
)
557 sal_uLong nValidMask
= rData
.GetMask();
561 OStringBuffer rStrBuf
;
563 if ( nValidMask
& WINDOWSTATE_MASK_X
)
564 rStrBuf
.append(static_cast<sal_Int32
>(rData
.GetX()));
566 if ( nValidMask
& WINDOWSTATE_MASK_Y
)
567 rStrBuf
.append(static_cast<sal_Int32
>(rData
.GetY()));
569 if ( nValidMask
& WINDOWSTATE_MASK_WIDTH
)
570 rStrBuf
.append(static_cast<sal_Int32
>(rData
.GetWidth()));
572 if ( nValidMask
& WINDOWSTATE_MASK_HEIGHT
)
573 rStrBuf
.append(static_cast<sal_Int32
>(rData
.GetHeight()));
574 rStrBuf
.append( ';' );
575 if ( nValidMask
& WINDOWSTATE_MASK_STATE
)
577 // #94144# allow Minimize again, should be masked out when read from configuration
578 // 91625 - ignore Minimize
579 sal_uInt32 nState
= rData
.GetState();
580 rStrBuf
.append(static_cast<sal_Int32
>(nState
));
583 if ( nValidMask
& WINDOWSTATE_MASK_MAXIMIZED_X
)
584 rStrBuf
.append(static_cast<sal_Int32
>(rData
.GetMaximizedX()));
586 if ( nValidMask
& WINDOWSTATE_MASK_MAXIMIZED_Y
)
587 rStrBuf
.append(static_cast<sal_Int32
>(rData
.GetMaximizedY()));
588 rStrBuf
.append( ',' );
589 if ( nValidMask
& WINDOWSTATE_MASK_MAXIMIZED_WIDTH
)
590 rStrBuf
.append(static_cast<sal_Int32
>(rData
.GetMaximizedWidth()));
592 if ( nValidMask
& WINDOWSTATE_MASK_MAXIMIZED_HEIGHT
)
593 rStrBuf
.append(static_cast<sal_Int32
>(rData
.GetMaximizedHeight()));
596 return rStrBuf
.makeStringAndClear();
599 // -----------------------------------------------------------------------
601 void SystemWindow::ImplMoveToScreen( long& io_rX
, long& io_rY
, long i_nWidth
, long i_nHeight
, Window
* i_pConfigureWin
)
603 Rectangle aScreenRect
;
604 if( !Application::IsUnifiedDisplay() )
605 aScreenRect
= Application::GetScreenPosSizePixel( GetScreenNumber() );
608 aScreenRect
= Application::GetScreenPosSizePixel( 0 );
609 for( unsigned int i
= 1; i
< Application::GetScreenCount(); i
++ )
610 aScreenRect
.Union( Application::GetScreenPosSizePixel( i
) );
612 // unfortunately most of the time width and height are not really known
620 if( io_rX
+ i_nWidth
< aScreenRect
.Left() )
623 io_rX
= aScreenRect
.Left();
625 // check right border
626 if( io_rX
> aScreenRect
.Right() - i_nWidth
)
629 io_rX
= aScreenRect
.Right() - i_nWidth
;
632 if( io_rY
+ i_nHeight
< aScreenRect
.Top() )
635 io_rY
= aScreenRect
.Top();
637 // check bottom border
638 if( io_rY
> aScreenRect
.Bottom() - i_nHeight
)
641 io_rY
= aScreenRect
.Bottom() - i_nHeight
;
643 Window
* pParent
= i_pConfigureWin
->GetParent();
644 if( bMove
&& pParent
)
646 // calculate absolute screen pos here, since that is what is contained in WindowState
647 Point
aParentAbsPos( pParent
->OutputToAbsoluteScreenPixel( Point(0,0) ) );
648 Size
aParentSizePixel( pParent
->GetOutputSizePixel() );
649 Point
aPos( (aParentSizePixel
.Width() - i_nWidth
) / 2,
650 (aParentSizePixel
.Height() - i_nHeight
) / 2 );
651 io_rX
= aParentAbsPos
.X() + aPos
.X();
652 io_rY
= aParentAbsPos
.Y() + aPos
.Y();
656 void SystemWindow::SetWindowStateData( const WindowStateData
& rData
)
658 sal_uLong nValidMask
= rData
.GetMask();
665 Window
* pWindow
= this;
666 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
667 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
669 if ( pWindow
->mpWindowImpl
->mbFrame
)
671 sal_uLong nState
= rData
.GetState();
672 SalFrameState aState
;
673 aState
.mnMask
= rData
.GetMask();
674 aState
.mnX
= rData
.GetX();
675 aState
.mnY
= rData
.GetY();
676 aState
.mnWidth
= rData
.GetWidth();
677 aState
.mnHeight
= rData
.GetHeight();
679 if( rData
.GetMask() & (WINDOWSTATE_MASK_WIDTH
|WINDOWSTATE_MASK_HEIGHT
) )
681 // #i43799# adjust window state sizes if a minimial output size was set
682 // otherwise the frame and the client might get different sizes
683 if( maMinOutSize
.Width() > aState
.mnWidth
)
684 aState
.mnWidth
= maMinOutSize
.Width();
685 if( maMinOutSize
.Height() > aState
.mnHeight
)
686 aState
.mnHeight
= maMinOutSize
.Height();
689 aState
.mnMaximizedX
= rData
.GetMaximizedX();
690 aState
.mnMaximizedY
= rData
.GetMaximizedY();
691 aState
.mnMaximizedWidth
= rData
.GetMaximizedWidth();
692 aState
.mnMaximizedHeight
= rData
.GetMaximizedHeight();
693 // #94144# allow Minimize again, should be masked out when read from configuration
694 // 91625 - ignore Minimize
695 //nState &= ~(WINDOWSTATE_STATE_MINIMIZED);
696 aState
.mnState
= nState
& WINDOWSTATE_STATE_SYSTEMMASK
;
698 // normalize window positions onto screen
699 ImplMoveToScreen( aState
.mnX
, aState
.mnY
, aState
.mnWidth
, aState
.mnHeight
, pWindow
);
700 ImplMoveToScreen( aState
.mnMaximizedX
, aState
.mnMaximizedY
, aState
.mnMaximizedWidth
, aState
.mnMaximizedHeight
, pWindow
);
702 // #96568# avoid having multiple frames at the same screen location
703 // do the check only if not maximized
704 if( !((rData
.GetMask() & WINDOWSTATE_MASK_STATE
) && (nState
& WINDOWSTATE_STATE_MAXIMIZED
)) )
705 if( rData
.GetMask() & (WINDOWSTATE_MASK_POS
|WINDOWSTATE_MASK_WIDTH
|WINDOWSTATE_MASK_HEIGHT
) )
707 Rectangle aDesktop
= GetDesktopRectPixel();
708 ImplSVData
*pSVData
= ImplGetSVData();
709 Window
*pWin
= pSVData
->maWinData
.mpFirstFrame
;
710 sal_Bool bWrapped
= sal_False
;
713 if( !pWin
->ImplIsRealParentPath( this ) && ( pWin
!= this ) &&
714 pWin
->ImplGetWindow()->IsTopWindow() && pWin
->mpWindowImpl
->mbReallyVisible
)
716 SalFrameGeometry g
= pWin
->mpWindowImpl
->mpFrame
->GetGeometry();
717 if( abs(g
.nX
-aState
.mnX
) < 2 && abs(g
.nY
-aState
.mnY
) < 5 )
719 long displacement
= g
.nTopDecoration
? g
.nTopDecoration
: 20;
720 if( (unsigned long) (aState
.mnX
+ displacement
+ aState
.mnWidth
+ g
.nRightDecoration
) > (unsigned long) aDesktop
.Right() ||
721 (unsigned long) (aState
.mnY
+ displacement
+ aState
.mnHeight
+ g
.nBottomDecoration
) > (unsigned long) aDesktop
.Bottom() )
723 // displacing would leave screen
724 aState
.mnX
= g
.nLeftDecoration
? g
.nLeftDecoration
: 10; // should result in (0,0)
725 aState
.mnY
= displacement
;
727 (unsigned long) (aState
.mnX
+ displacement
+ aState
.mnWidth
+ g
.nRightDecoration
) > (unsigned long) aDesktop
.Right() ||
728 (unsigned long) (aState
.mnY
+ displacement
+ aState
.mnHeight
+ g
.nBottomDecoration
) > (unsigned long) aDesktop
.Bottom() )
729 break; // further displacement not possible -> break
730 // avoid endless testing
736 aState
.mnX
+= displacement
;
737 aState
.mnY
+= displacement
;
739 pWin
= pSVData
->maWinData
.mpFirstFrame
; // check new pos again
742 pWin
= pWin
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
746 mpWindowImpl
->mpFrame
->SetWindowState( &aState
);
748 // do a synchronous resize for layout reasons
749 // but use rData only when the window is not to be maximized (#i38089#)
750 // otherwise we have no useful size information
751 if( (rData
.GetMask() & WINDOWSTATE_MASK_STATE
) && (nState
& WINDOWSTATE_STATE_MAXIMIZED
) )
753 // query maximized size from frame
754 SalFrameGeometry aGeometry
= mpWindowImpl
->mpFrame
->GetGeometry();
756 // but use it only if it is different from the restore size (rData)
757 // as currently only on windows the exact size of a maximized window
758 // can be computed without actually showing the window
759 if( aGeometry
.nWidth
!= rData
.GetWidth() || aGeometry
.nHeight
!= rData
.GetHeight() )
760 ImplHandleResize( pWindow
, aGeometry
.nWidth
, aGeometry
.nHeight
);
763 if( rData
.GetMask() & (WINDOWSTATE_MASK_WIDTH
|WINDOWSTATE_MASK_HEIGHT
) )
764 ImplHandleResize( pWindow
, aState
.mnWidth
, aState
.mnHeight
); // #i43799# use aState and not rData, see above
768 sal_uInt16 nPosSize
= 0;
769 if ( nValidMask
& WINDOWSTATE_MASK_X
)
770 nPosSize
|= WINDOW_POSSIZE_X
;
771 if ( nValidMask
& WINDOWSTATE_MASK_Y
)
772 nPosSize
|= WINDOW_POSSIZE_Y
;
773 if ( nValidMask
& WINDOWSTATE_MASK_WIDTH
)
774 nPosSize
|= WINDOW_POSSIZE_WIDTH
;
775 if ( nValidMask
& WINDOWSTATE_MASK_HEIGHT
)
776 nPosSize
|= WINDOW_POSSIZE_HEIGHT
;
781 long nX
= rData
.GetX();
782 long nY
= rData
.GetY();
783 long nWidth
= rData
.GetWidth();
784 long nHeight
= rData
.GetHeight();
785 const SalFrameGeometry
& rGeom
= pWindow
->mpWindowImpl
->mpFrame
->GetGeometry();
788 if( nX
+ nWidth
> (long) rGeom
.nWidth
)
789 nX
= rGeom
.nWidth
- nWidth
;
792 if( nY
+ nHeight
> (long) rGeom
.nHeight
)
793 nY
= rGeom
.nHeight
- nHeight
;
794 setPosSizePixel( nX
, nY
, nWidth
, nHeight
, nPosSize
);
795 maOrgSize
= Size( nWidth
, nHeight
);
797 // 91625 - ignore Minimize
798 if ( nValidMask
& WINDOWSTATE_MASK_STATE
)
800 sal_uLong nState
= rData
.GetState();
801 if ( nState
& WINDOWSTATE_STATE_ROLLUP
)
809 // -----------------------------------------------------------------------
811 void SystemWindow::GetWindowStateData( WindowStateData
& rData
) const
813 sal_uLong nValidMask
= rData
.GetMask();
820 const Window
* pWindow
= this;
821 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
822 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
824 if ( pWindow
->mpWindowImpl
->mbFrame
)
826 SalFrameState aState
;
827 aState
.mnMask
= 0xFFFFFFFF;
828 if ( mpWindowImpl
->mpFrame
->GetWindowState( &aState
) )
830 if ( nValidMask
& WINDOWSTATE_MASK_X
)
831 rData
.SetX( aState
.mnX
);
832 if ( nValidMask
& WINDOWSTATE_MASK_Y
)
833 rData
.SetY( aState
.mnY
);
834 if ( nValidMask
& WINDOWSTATE_MASK_WIDTH
)
835 rData
.SetWidth( aState
.mnWidth
);
836 if ( nValidMask
& WINDOWSTATE_MASK_HEIGHT
)
837 rData
.SetHeight( aState
.mnHeight
);
838 if ( aState
.mnMask
& WINDOWSTATE_MASK_MAXIMIZED_X
)
840 rData
.SetMaximizedX( aState
.mnMaximizedX
);
841 nValidMask
|= WINDOWSTATE_MASK_MAXIMIZED_X
;
843 if ( aState
.mnMask
& WINDOWSTATE_MASK_MAXIMIZED_Y
)
845 rData
.SetMaximizedY( aState
.mnMaximizedY
);
846 nValidMask
|= WINDOWSTATE_MASK_MAXIMIZED_Y
;
848 if ( aState
.mnMask
& WINDOWSTATE_MASK_MAXIMIZED_WIDTH
)
850 rData
.SetMaximizedWidth( aState
.mnMaximizedWidth
);
851 nValidMask
|= WINDOWSTATE_MASK_MAXIMIZED_WIDTH
;
853 if ( aState
.mnMask
& WINDOWSTATE_MASK_MAXIMIZED_HEIGHT
)
855 rData
.SetMaximizedHeight( aState
.mnMaximizedHeight
);
856 nValidMask
|= WINDOWSTATE_MASK_MAXIMIZED_HEIGHT
;
858 if ( nValidMask
& WINDOWSTATE_MASK_STATE
)
860 // #94144# allow Minimize again, should be masked out when read from configuration
861 // 91625 - ignore Minimize
862 if ( !(nValidMask
&WINDOWSTATE_MASK_MINIMIZED
) )
863 aState
.mnState
&= ~(WINDOWSTATE_STATE_MINIMIZED
);
864 rData
.SetState( aState
.mnState
);
866 rData
.SetMask( nValidMask
);
873 Point aPos
= GetPosPixel();
874 Size aSize
= GetSizePixel();
875 sal_uLong nState
= 0;
879 aSize
.Height() += maOrgSize
.Height();
880 nState
|= WINDOWSTATE_STATE_ROLLUP
;
883 if ( nValidMask
& WINDOWSTATE_MASK_X
)
884 rData
.SetX( aPos
.X() );
885 if ( nValidMask
& WINDOWSTATE_MASK_Y
)
886 rData
.SetY( aPos
.Y() );
887 if ( nValidMask
& WINDOWSTATE_MASK_WIDTH
)
888 rData
.SetWidth( aSize
.Width() );
889 if ( nValidMask
& WINDOWSTATE_MASK_HEIGHT
)
890 rData
.SetHeight( aSize
.Height() );
891 if ( nValidMask
& WINDOWSTATE_MASK_STATE
)
892 rData
.SetState( nState
);
896 // -----------------------------------------------------------------------
898 void SystemWindow::SetWindowState(const OString
& rStr
)
903 WindowStateData aData
;
904 ImplWindowStateFromStr( aData
, rStr
);
905 SetWindowStateData( aData
);
908 // -----------------------------------------------------------------------
910 OString
SystemWindow::GetWindowState( sal_uLong nMask
) const
912 WindowStateData aData
;
913 aData
.SetMask( nMask
);
914 GetWindowStateData( aData
);
916 return ImplWindowStateToStr(aData
);
919 // -----------------------------------------------------------------------
921 void SystemWindow::SetMenuBar( MenuBar
* pMenuBar
)
923 if ( mpMenuBar
!= pMenuBar
)
925 MenuBar
* pOldMenuBar
= mpMenuBar
;
926 Window
* pOldWindow
= NULL
;
927 Window
* pNewWindow
=NULL
;
928 mpMenuBar
= pMenuBar
;
930 if ( mpWindowImpl
->mpBorderWindow
&& (mpWindowImpl
->mpBorderWindow
->GetType() == WINDOW_BORDERWINDOW
) )
933 pOldWindow
= pOldMenuBar
->ImplGetWindow();
938 ImplCallEventListeners( VCLEVENT_WINDOW_MENUBARREMOVED
, (void*) pOldMenuBar
);
939 pOldWindow
->SetAccessible( ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>() );
943 DBG_ASSERT( !pMenuBar
->pWindow
, "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" );
944 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetMenuBarWindow( pNewWindow
= MenuBar::ImplCreate( mpWindowImpl
->mpBorderWindow
, pOldWindow
, pMenuBar
) );
945 ImplCallEventListeners( VCLEVENT_WINDOW_MENUBARADDED
, (void*) pMenuBar
);
948 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetMenuBarWindow( NULL
);
952 sal_Bool bDelete
= (pMenuBar
== 0) ? sal_True
: sal_False
;
953 if( bDelete
&& pOldWindow
)
955 if( mpImplData
->mpTaskPaneList
)
956 mpImplData
->mpTaskPaneList
->RemoveWindow( pOldWindow
);
958 MenuBar::ImplDestroy( pOldMenuBar
, bDelete
);
960 pOldWindow
= NULL
; // will be deleted in MenuBar::ImplDestroy,
967 pNewWindow
= pMenuBar
->ImplGetWindow();
969 pOldWindow
= pOldMenuBar
->ImplGetWindow();
972 // update taskpane list to make menubar accessible
973 if( mpImplData
->mpTaskPaneList
)
976 mpImplData
->mpTaskPaneList
->RemoveWindow( pOldWindow
);
978 mpImplData
->mpTaskPaneList
->AddWindow( pNewWindow
);
983 // -----------------------------------------------------------------------
985 void SystemWindow::SetMenuBarMode( sal_uInt16 nMode
)
987 if ( mnMenuBarMode
!= nMode
)
989 mnMenuBarMode
= nMode
;
990 if ( mpWindowImpl
->mpBorderWindow
&& (mpWindowImpl
->mpBorderWindow
->GetType() == WINDOW_BORDERWINDOW
) )
992 if ( nMode
== MENUBAR_MODE_HIDE
)
993 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetMenuBarMode( sal_True
);
995 ((ImplBorderWindow
*)mpWindowImpl
->mpBorderWindow
)->SetMenuBarMode( sal_False
);
1000 // -----------------------------------------------------------------------
1002 sal_Bool
SystemWindow::ImplIsInTaskPaneList( Window
* pWin
)
1004 if( mpImplData
&& mpImplData
->mpTaskPaneList
)
1005 return mpImplData
->mpTaskPaneList
->IsInList( pWin
);
1009 unsigned int SystemWindow::GetScreenNumber() const
1011 return mpWindowImpl
->mpFrame
->maGeometry
.nDisplayScreenNumber
;
1014 void SystemWindow::SetScreenNumber(unsigned int nDisplayScreen
)
1016 mpWindowImpl
->mpFrame
->SetScreenNumber( nDisplayScreen
);
1019 void SystemWindow::SetApplicationID(const OUString
&rApplicationID
)
1021 mpWindowImpl
->mpFrame
->SetApplicationID( rApplicationID
);
1024 void SystemWindow::SetCloseHdl(const Link
& rLink
)
1026 mpImplData
->maCloseHdl
= rLink
;
1029 const Link
& SystemWindow::GetCloseHdl() const
1031 return mpImplData
->maCloseHdl
;
1034 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */