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