xref: /aoo41x/main/toolkit/source/awt/vclxdialog.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "vclxdialog.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/awt/SystemDependentXWindow.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/lang/SystemDependent.hpp>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <toolkit/awt/vclxmenu.hxx>
37*cdf0e10cSrcweir #include <toolkit/helper/macros.hxx>
38*cdf0e10cSrcweir #include <toolkit/helper/property.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #ifdef WNT
41*cdf0e10cSrcweir #include <tools/prewin.h>
42*cdf0e10cSrcweir #include <windows.h>
43*cdf0e10cSrcweir #include <tools/postwin.h>
44*cdf0e10cSrcweir #elif defined ( QUARTZ )
45*cdf0e10cSrcweir #include "premac.h"
46*cdf0e10cSrcweir #include <Cocoa/Cocoa.h>
47*cdf0e10cSrcweir #include "postmac.h"
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <vcl/dialog.hxx>
51*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
52*cdf0e10cSrcweir #include <vcl/svapp.hxx>
53*cdf0e10cSrcweir #include <vcl/sysdata.hxx>
54*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir #include "forward.hxx"
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir namespace layoutimpl
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir DBG_NAME( VCLXDialog )
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir VCLXDialog::VCLXDialog()
64*cdf0e10cSrcweir     : VCLXWindow()
65*cdf0e10cSrcweir     , VCLXTopWindow_Base( true )
66*cdf0e10cSrcweir     , VCLXDialog_Base()
67*cdf0e10cSrcweir     , Bin()
68*cdf0e10cSrcweir     , bRealized( false )
69*cdf0e10cSrcweir     , bResizeSafeguard( false )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir     DBG_CTOR( VCLXDialog, NULL );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir /*        mxLayoutUnit = uno::Reference< awt::XLayoutUnit >( new LayoutUnit() );
74*cdf0e10cSrcweir           assert(mxLayoutUnit.is());*/
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir VCLXDialog::~VCLXDialog()
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     DBG_DTOR( VCLXDialog, NULL );
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir vos::IMutex& VCLXDialog::GetMutexImpl()
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir     return VCLXWindow::GetMutex();
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir Window* VCLXDialog::GetWindowImpl()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir     return VCLXWindow::GetWindow();
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper& VCLXDialog::GetTopWindowListenersImpl()
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir     return GetTopWindowListeners();
95*cdf0e10cSrcweir }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir IMPLEMENT_2_FORWARD_XINTERFACE2( VCLXDialog, VCLXWindow, Bin, VCLXDialog_Base );
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXDialog, VCLXWindow, VCLXDialog_Base );
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir void SAL_CALL VCLXDialog::dispose() throw(::com::sun::star::uno::RuntimeException)
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir     {
104*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         ::com::sun::star::lang::EventObject aDisposeEvent;
107*cdf0e10cSrcweir         aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this);
108*cdf0e10cSrcweir //            maTabListeners.disposeAndClear( aDisposeEvent );
109*cdf0e10cSrcweir     }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     VCLXWindow::dispose();
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir void VCLXDialog::resizedCb()
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     queueResize();
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir void SAL_CALL VCLXDialog::allocateArea( const css::awt::Rectangle &rArea )
120*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     ::com::sun::star::awt::Size reqSize = Bin::getMinimumSize();
123*cdf0e10cSrcweir     reqSize.Height = getHeightForWidth( rArea.Width );
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     if ( !bRealized )
126*cdf0e10cSrcweir     {
127*cdf0e10cSrcweir         setPosSize( 0, 0, reqSize.Width, reqSize.Height, ::com::sun::star::awt::PosSize::SIZE );
128*cdf0e10cSrcweir         bRealized = true;
129*cdf0e10cSrcweir         setVisible( true );
130*cdf0e10cSrcweir     }
131*cdf0e10cSrcweir     else
132*cdf0e10cSrcweir     {
133*cdf0e10cSrcweir         ::com::sun::star::awt::Size curSize = getSize();
134*cdf0e10cSrcweir         if ( reqSize.Width > curSize.Width )
135*cdf0e10cSrcweir             setPosSize( 0, 0, reqSize.Width, 0, ::com::sun::star::awt::PosSize::WIDTH );
136*cdf0e10cSrcweir         if ( reqSize.Height > curSize.Height )
137*cdf0e10cSrcweir             setPosSize( 0, 0, 0, reqSize.Height, ::com::sun::star::awt::PosSize::HEIGHT );
138*cdf0e10cSrcweir     }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     ::com::sun::star::awt::Size size = getSize();
141*cdf0e10cSrcweir     maAllocation.Width = size.Width;
142*cdf0e10cSrcweir     maAllocation.Height = size.Height;
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir     Bin::allocateArea( maAllocation );
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir void VCLXDialog::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     ::vos::OClearableGuard aGuard( GetMutex() );
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     switch ( _rVclWindowEvent.GetId() )
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         case VCLEVENT_WINDOW_RESIZE:
154*cdf0e10cSrcweir             resizedCb();
155*cdf0e10cSrcweir         default:
156*cdf0e10cSrcweir             aGuard.clear();
157*cdf0e10cSrcweir             VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
158*cdf0e10cSrcweir             break;
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir void SAL_CALL VCLXDialog::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any &Value ) throw(::com::sun::star::uno::RuntimeException)
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     if ( GetWindow() )
167*cdf0e10cSrcweir     {
168*cdf0e10cSrcweir /*        sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
169*cdf0e10cSrcweir         switch ( nPropertyId )
170*cdf0e10cSrcweir         {
171*cdf0e10cSrcweir             default:
172*cdf0e10cSrcweir */
173*cdf0e10cSrcweir                 VCLXWindow::setProperty( PropertyName, Value );
174*cdf0e10cSrcweir /*        }
175*cdf0e10cSrcweir */
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL VCLXDialog::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir     ::com::sun::star::uno::Any aReturn;
184*cdf0e10cSrcweir     if ( GetWindow() )
185*cdf0e10cSrcweir     {
186*cdf0e10cSrcweir /*
187*cdf0e10cSrcweir         sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
188*cdf0e10cSrcweir         switch ( nPropertyId )
189*cdf0e10cSrcweir         {
190*cdf0e10cSrcweir             default:
191*cdf0e10cSrcweir */
192*cdf0e10cSrcweir                 aReturn = VCLXWindow::getProperty( PropertyName );
193*cdf0e10cSrcweir /*
194*cdf0e10cSrcweir         }
195*cdf0e10cSrcweir */
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir     return aReturn;
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir void VCLXDialog::setTitle( const ::rtl::OUString& Title ) throw(::com::sun::star::uno::RuntimeException)
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     Window* pWindow = GetWindow();
205*cdf0e10cSrcweir     if ( pWindow )
206*cdf0e10cSrcweir         pWindow->SetText( Title );
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir void VCLXDialog::setHelpId( const rtl::OUString& rId ) throw(::com::sun::star::uno::RuntimeException)
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     Window* pWindow = GetWindow();
214*cdf0e10cSrcweir     if ( pWindow )
215*cdf0e10cSrcweir         pWindow->SetHelpId( rtl::OUStringToOString( rId, RTL_TEXTENCODING_UTF8 ) );
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir ::rtl::OUString VCLXDialog::getTitle() throw(::com::sun::star::uno::RuntimeException)
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir     ::rtl::OUString aTitle;
223*cdf0e10cSrcweir     Window* pWindow = GetWindow();
224*cdf0e10cSrcweir     if ( pWindow )
225*cdf0e10cSrcweir         aTitle = pWindow->GetText();
226*cdf0e10cSrcweir     return aTitle;
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir sal_Int16 VCLXDialog::execute() throw(::com::sun::star::uno::RuntimeException)
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     sal_Int16 nRet = 0;
234*cdf0e10cSrcweir     if ( GetWindow() )
235*cdf0e10cSrcweir     {
236*cdf0e10cSrcweir         Dialog* pDlg = (Dialog*) GetWindow();
237*cdf0e10cSrcweir         Window* pParent = pDlg->GetWindow( WINDOW_PARENTOVERLAP );
238*cdf0e10cSrcweir         Window* pOldParent = NULL;
239*cdf0e10cSrcweir         if ( pParent && !pParent->IsReallyVisible() )
240*cdf0e10cSrcweir         {
241*cdf0e10cSrcweir             pOldParent = pDlg->GetParent();
242*cdf0e10cSrcweir             Window* pFrame = pDlg->GetWindow( WINDOW_FRAME );
243*cdf0e10cSrcweir             if ( pFrame != pDlg )
244*cdf0e10cSrcweir                 pDlg->SetParent( pFrame );
245*cdf0e10cSrcweir         }
246*cdf0e10cSrcweir         nRet = pDlg->Execute();
247*cdf0e10cSrcweir         if ( pOldParent )
248*cdf0e10cSrcweir             pDlg->SetParent( pOldParent );
249*cdf0e10cSrcweir     }
250*cdf0e10cSrcweir     return nRet;
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void VCLXDialog::endDialog( sal_Int32 nResult ) throw(::com::sun::star::uno::RuntimeException)
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir     if ( nResult == BUTTONID_HELP )
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir         // UGH: c&p button.cxx
260*cdf0e10cSrcweir         ::Window* pFocusWin = Application::GetFocusWindow();
261*cdf0e10cSrcweir         if ( !pFocusWin )
262*cdf0e10cSrcweir             pFocusWin = GetWindow();
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir         HelpEvent aEvt( pFocusWin->GetPointerPosPixel(), HELPMODE_CONTEXT );
265*cdf0e10cSrcweir         pFocusWin->RequestHelp( aEvt );
266*cdf0e10cSrcweir         return;
267*cdf0e10cSrcweir     }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir     Dialog* pDlg = (Dialog*) GetWindow();
270*cdf0e10cSrcweir     if ( pDlg )
271*cdf0e10cSrcweir         pDlg->EndDialog( nResult );
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir void VCLXDialog::endExecute() throw(::com::sun::star::uno::RuntimeException)
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     endDialog( 0 );
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir } // namespace layoutimpl
280