Update ooo320-m1
[ooovba.git] / toolkit / source / awt / vclxdialog.cxx
blob08283dce4ef7f8e189c6d1669676a6d0a2c49d60
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxdialog.cxx,v $
11 * $Revision: 1.5 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "vclxdialog.hxx"
34 #include <com/sun/star/awt/PosSize.hpp>
35 #include <com/sun/star/awt/SystemDependentXWindow.hpp>
36 #include <com/sun/star/lang/SystemDependent.hpp>
38 #include <cppuhelper/typeprovider.hxx>
40 #include <toolkit/awt/vclxmenu.hxx>
41 #include <toolkit/helper/macros.hxx>
42 #include <toolkit/helper/property.hxx>
44 #ifdef WNT
45 #include <tools/prewin.h>
46 #include <windows.h>
47 #include <tools/postwin.h>
48 #elif defined ( QUARTZ )
49 #include "premac.h"
50 #include <Cocoa/Cocoa.h>
51 #include "postmac.h"
52 #endif
54 #include <vcl/dialog.hxx>
55 #include <vcl/msgbox.hxx>
56 #include <vcl/svapp.hxx>
57 #include <vcl/sysdata.hxx>
58 #include <vcl/wrkwin.hxx>
60 #include "forward.hxx"
62 namespace layoutimpl
65 DBG_NAME( VCLXDialog )
67 VCLXDialog::VCLXDialog()
68 : VCLXWindow()
69 , VCLXDialog_Base()
70 , Bin()
71 , bRealized( false )
72 , bResizeSafeguard( false )
74 DBG_CTOR( VCLXDialog, NULL );
76 /* mxLayoutUnit = uno::Reference< awt::XLayoutUnit >( new LayoutUnit() );
77 assert(mxLayoutUnit.is());*/
80 VCLXDialog::~VCLXDialog()
82 DBG_DTOR( VCLXDialog, NULL );
85 vos::IMutex& VCLXDialog::GetMutexImpl()
87 return VCLXWindow::GetMutex();
90 Window* VCLXDialog::GetWindowImpl()
92 return VCLXWindow::GetWindow();
95 ::cppu::OInterfaceContainerHelper& VCLXDialog::GetTopWindowListenersImpl()
97 return GetTopWindowListeners();
100 IMPLEMENT_2_FORWARD_XINTERFACE2( VCLXDialog, VCLXWindow, Bin, VCLXDialog_Base );
102 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXDialog, VCLXWindow, VCLXDialog_Base );
104 void SAL_CALL VCLXDialog::dispose() throw(::com::sun::star::uno::RuntimeException)
107 ::vos::OGuard aGuard( GetMutex() );
109 ::com::sun::star::lang::EventObject aDisposeEvent;
110 aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this);
111 // maTabListeners.disposeAndClear( aDisposeEvent );
114 VCLXWindow::dispose();
117 void VCLXDialog::resizedCb()
119 queueResize();
122 void SAL_CALL VCLXDialog::allocateArea( const css::awt::Rectangle &rArea )
123 throw (css::uno::RuntimeException)
125 ::com::sun::star::awt::Size reqSize = Bin::getMinimumSize();
126 reqSize.Height = getHeightForWidth( rArea.Width );
128 if ( !bRealized )
130 setPosSize( 0, 0, reqSize.Width, reqSize.Height, ::com::sun::star::awt::PosSize::SIZE );
131 bRealized = true;
132 setVisible( true );
134 else
136 ::com::sun::star::awt::Size curSize = getSize();
137 if ( reqSize.Width > curSize.Width )
138 setPosSize( 0, 0, reqSize.Width, 0, ::com::sun::star::awt::PosSize::WIDTH );
139 if ( reqSize.Height > curSize.Height )
140 setPosSize( 0, 0, 0, reqSize.Height, ::com::sun::star::awt::PosSize::HEIGHT );
143 ::com::sun::star::awt::Size size = getSize();
144 maAllocation.Width = size.Width;
145 maAllocation.Height = size.Height;
147 Bin::allocateArea( maAllocation );
150 void VCLXDialog::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
152 ::vos::OClearableGuard aGuard( GetMutex() );
154 switch ( _rVclWindowEvent.GetId() )
156 case VCLEVENT_WINDOW_RESIZE:
157 resizedCb();
158 default:
159 aGuard.clear();
160 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
161 break;
165 void SAL_CALL VCLXDialog::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any &Value ) throw(::com::sun::star::uno::RuntimeException)
167 ::vos::OGuard aGuard( GetMutex() );
169 if ( GetWindow() )
171 /* sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
172 switch ( nPropertyId )
174 default:
176 VCLXWindow::setProperty( PropertyName, Value );
177 /* }
182 ::com::sun::star::uno::Any SAL_CALL VCLXDialog::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
184 ::vos::OGuard aGuard( GetMutex() );
186 ::com::sun::star::uno::Any aReturn;
187 if ( GetWindow() )
190 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
191 switch ( nPropertyId )
193 default:
195 aReturn = VCLXWindow::getProperty( PropertyName );
200 return aReturn;
203 void VCLXDialog::setTitle( const ::rtl::OUString& Title ) throw(::com::sun::star::uno::RuntimeException)
205 ::vos::OGuard aGuard( GetMutex() );
207 Window* pWindow = GetWindow();
208 if ( pWindow )
209 pWindow->SetText( Title );
212 void VCLXDialog::setHelpId( sal_Int32 id ) throw(::com::sun::star::uno::RuntimeException)
214 ::vos::OGuard aGuard( GetMutex() );
216 Window* pWindow = GetWindow();
217 if ( pWindow )
218 pWindow->SetHelpId( id );
221 ::rtl::OUString VCLXDialog::getTitle() throw(::com::sun::star::uno::RuntimeException)
223 ::vos::OGuard aGuard( GetMutex() );
225 ::rtl::OUString aTitle;
226 Window* pWindow = GetWindow();
227 if ( pWindow )
228 aTitle = pWindow->GetText();
229 return aTitle;
232 sal_Int16 VCLXDialog::execute() throw(::com::sun::star::uno::RuntimeException)
234 ::vos::OGuard aGuard( GetMutex() );
236 sal_Int16 nRet = 0;
237 if ( GetWindow() )
239 Dialog* pDlg = (Dialog*) GetWindow();
240 Window* pParent = pDlg->GetWindow( WINDOW_PARENTOVERLAP );
241 Window* pOldParent = NULL;
242 if ( pParent && !pParent->IsReallyVisible() )
244 pOldParent = pDlg->GetParent();
245 Window* pFrame = pDlg->GetWindow( WINDOW_FRAME );
246 if ( pFrame != pDlg )
247 pDlg->SetParent( pFrame );
249 nRet = pDlg->Execute();
250 if ( pOldParent )
251 pDlg->SetParent( pOldParent );
253 return nRet;
256 void VCLXDialog::endDialog( sal_Int32 nResult ) throw(::com::sun::star::uno::RuntimeException)
258 ::vos::OGuard aGuard( GetMutex() );
260 if ( nResult == BUTTONID_HELP )
262 // UGH: c&p button.cxx
263 ::Window* pFocusWin = Application::GetFocusWindow();
264 if ( !pFocusWin )
265 pFocusWin = GetWindow();
267 HelpEvent aEvt( pFocusWin->GetPointerPosPixel(), HELPMODE_CONTEXT );
268 pFocusWin->RequestHelp( aEvt );
269 return;
272 Dialog* pDlg = (Dialog*) GetWindow();
273 if ( pDlg )
274 pDlg->EndDialog( nResult );
277 void VCLXDialog::endExecute() throw(::com::sun::star::uno::RuntimeException)
279 endDialog( 0 );
282 } // namespace layoutimpl