xref: /trunk/main/toolkit/source/awt/vclxdialog.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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()
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 {
119     ::com::sun::star::awt::Size reqSize = Bin::getMinimumSize();
120     reqSize.Height = getHeightForWidth( rArea.Width );
121 
122     if ( !bRealized )
123     {
124         setPosSize( 0, 0, reqSize.Width, reqSize.Height, ::com::sun::star::awt::PosSize::SIZE );
125         bRealized = true;
126         setVisible( true );
127     }
128     else
129     {
130         ::com::sun::star::awt::Size curSize = getSize();
131         if ( reqSize.Width > curSize.Width )
132             setPosSize( 0, 0, reqSize.Width, 0, ::com::sun::star::awt::PosSize::WIDTH );
133         if ( reqSize.Height > curSize.Height )
134             setPosSize( 0, 0, 0, reqSize.Height, ::com::sun::star::awt::PosSize::HEIGHT );
135     }
136 
137     ::com::sun::star::awt::Size size = getSize();
138     maAllocation.Width = size.Width;
139     maAllocation.Height = size.Height;
140 
141     Bin::allocateArea( maAllocation );
142 }
143 
ProcessWindowEvent(const VclWindowEvent & _rVclWindowEvent)144 void VCLXDialog::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
145 {
146     ::vos::OClearableGuard aGuard( GetMutex() );
147 
148     switch ( _rVclWindowEvent.GetId() )
149     {
150         case VCLEVENT_WINDOW_RESIZE:
151             resizedCb();
152         default:
153             aGuard.clear();
154             VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
155             break;
156     }
157 }
158 
setProperty(const::rtl::OUString & PropertyName,const::com::sun::star::uno::Any & Value)159 void SAL_CALL VCLXDialog::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any &Value )
160 {
161     ::vos::OGuard aGuard( GetMutex() );
162 
163     if ( GetWindow() )
164     {
165 /*        sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
166         switch ( nPropertyId )
167         {
168             default:
169 */
170                 VCLXWindow::setProperty( PropertyName, Value );
171 /*        }
172 */
173     }
174 }
175 
getProperty(const::rtl::OUString & PropertyName)176 ::com::sun::star::uno::Any SAL_CALL VCLXDialog::getProperty( const ::rtl::OUString& PropertyName )
177 {
178     ::vos::OGuard aGuard( GetMutex() );
179 
180     ::com::sun::star::uno::Any aReturn;
181     if ( GetWindow() )
182     {
183 /*
184         sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
185         switch ( nPropertyId )
186         {
187             default:
188 */
189                 aReturn = VCLXWindow::getProperty( PropertyName );
190 /*
191         }
192 */
193     }
194     return aReturn;
195 }
196 
setTitle(const::rtl::OUString & Title)197 void VCLXDialog::setTitle( const ::rtl::OUString& Title )
198 {
199     ::vos::OGuard aGuard( GetMutex() );
200 
201     Window* pWindow = GetWindow();
202     if ( pWindow )
203         pWindow->SetText( Title );
204 }
205 
setHelpId(const rtl::OUString & rId)206 void VCLXDialog::setHelpId( const rtl::OUString& rId )
207 {
208     ::vos::OGuard aGuard( GetMutex() );
209 
210     Window* pWindow = GetWindow();
211     if ( pWindow )
212         pWindow->SetHelpId( rtl::OUStringToOString( rId, RTL_TEXTENCODING_UTF8 ) );
213 }
214 
getTitle()215 ::rtl::OUString VCLXDialog::getTitle()
216 {
217     ::vos::OGuard aGuard( GetMutex() );
218 
219     ::rtl::OUString aTitle;
220     Window* pWindow = GetWindow();
221     if ( pWindow )
222         aTitle = pWindow->GetText();
223     return aTitle;
224 }
225 
execute()226 sal_Int16 VCLXDialog::execute()
227 {
228     ::vos::OGuard aGuard( GetMutex() );
229 
230     sal_Int16 nRet = 0;
231     if ( GetWindow() )
232     {
233         Dialog* pDlg = (Dialog*) GetWindow();
234         Window* pParent = pDlg->GetWindow( WINDOW_PARENTOVERLAP );
235         Window* pOldParent = NULL;
236         if ( pParent && !pParent->IsReallyVisible() )
237         {
238             pOldParent = pDlg->GetParent();
239             Window* pFrame = pDlg->GetWindow( WINDOW_FRAME );
240             if ( pFrame != pDlg )
241                 pDlg->SetParent( pFrame );
242         }
243         nRet = pDlg->Execute();
244         if ( pOldParent )
245             pDlg->SetParent( pOldParent );
246     }
247     return nRet;
248 }
249 
endDialog(sal_Int32 nResult)250 void VCLXDialog::endDialog( sal_Int32 nResult )
251 {
252     ::vos::OGuard aGuard( GetMutex() );
253 
254     if ( nResult == BUTTONID_HELP )
255     {
256         // UGH: c&p button.cxx
257         ::Window* pFocusWin = Application::GetFocusWindow();
258         if ( !pFocusWin )
259             pFocusWin = GetWindow();
260 
261         HelpEvent aEvt( pFocusWin->GetPointerPosPixel(), HELPMODE_CONTEXT );
262         pFocusWin->RequestHelp( aEvt );
263         return;
264     }
265 
266     Dialog* pDlg = (Dialog*) GetWindow();
267     if ( pDlg )
268         pDlg->EndDialog( nResult );
269 }
270 
endExecute()271 void VCLXDialog::endExecute()
272 {
273     endDialog( 0 );
274 }
275 
276 } // namespace layoutimpl
277