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