sync master with lastest vba changes
[ooovba.git] / basctl / source / dlged / dlgedobj.cxx
blob9c0b9321767408fb8276904d8d358ac071201960
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: dlgedobj.cxx,v $
10 * $Revision: 1.53 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
34 #include <vector>
35 #include <algorithm>
36 #include <dlgeddef.hxx>
37 #include "dlgedobj.hxx"
38 #include "dlged.hxx"
39 #include "dlgedmod.hxx"
40 #include "dlgedpage.hxx"
41 #include "dlgedview.hxx"
42 #include "dlgedlist.hxx"
43 #include <iderid.hxx>
44 #include <localizationmgr.hxx>
46 #ifndef _BASCTL_DLGRESID_HRC
47 #include <dlgresid.hrc>
48 #endif
49 #include <tools/resmgr.hxx>
50 #include <tools/shl.hxx>
51 #include <unotools/sharedunocomponent.hxx>
52 #include <com/sun/star/awt/XTabControllerModel.hpp>
53 #include <com/sun/star/awt/XUnoControlContainer.hpp>
54 #include <com/sun/star/awt/XVclContainerPeer.hpp>
55 #include <com/sun/star/awt/XWindow.hpp>
56 #include <com/sun/star/beans/XPropertySet.hpp>
57 #include <com/sun/star/beans/PropertyAttribute.hpp>
58 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
59 #include <com/sun/star/container/XContainer.hpp>
60 #include <com/sun/star/lang/XServiceInfo.hpp>
61 #include <comphelper/processfactory.hxx>
62 #include <comphelper/types.hxx>
63 #include <vcl/svapp.hxx>
65 #include <algorithm>
66 #include <functional>
68 using namespace ::com::sun::star;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::container;
72 using namespace ::com::sun::star::script;
73 using ::rtl::OUString;
76 TYPEINIT1(DlgEdObj, SdrUnoObj);
77 DBG_NAME(DlgEdObj);
79 //----------------------------------------------------------------------------
80 MapMode lcl_getMapModeForForm( DlgEdForm* pForm )
82 MapMode aMode( MAP_APPFONT ); //Default
83 try
85 uno::Reference< beans::XPropertySet > xProps( pForm ? pForm->GetUnoControlModel() : NULL, uno::UNO_QUERY_THROW );
86 sal_Bool bVBAForm = sal_False;
87 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("VBAForm") ) ) >>= bVBAForm;
88 if ( bVBAForm )
89 aMode = MapMode( MAP_100TH_MM );
91 catch ( Exception& )
94 return aMode;
97 DlgEdObj::DlgEdObj()
98 :SdrUnoObj(String(), sal_False)
99 ,bIsListening(sal_False)
100 ,pDlgEdForm( NULL )
102 DBG_CTOR(DlgEdObj, NULL);
105 //----------------------------------------------------------------------------
107 DlgEdObj::DlgEdObj(const ::rtl::OUString& rModelName)
108 :SdrUnoObj(rModelName, sal_False)
109 ,bIsListening(sal_False)
110 ,pDlgEdForm( NULL )
112 DBG_CTOR(DlgEdObj, NULL);
115 //----------------------------------------------------------------------------
117 DlgEdObj::DlgEdObj(const ::rtl::OUString& rModelName,
118 const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac)
119 :SdrUnoObj(rModelName, rxSFac, sal_False)
120 ,bIsListening(sal_False)
121 ,pDlgEdForm( NULL )
123 DBG_CTOR(DlgEdObj, NULL);
126 //----------------------------------------------------------------------------
128 DlgEdObj::~DlgEdObj()
130 DBG_DTOR(DlgEdObj, NULL);
132 if ( isListening() )
133 EndListening();
136 //----------------------------------------------------------------------------
138 void DlgEdObj::SetPage(SdrPage* _pNewPage)
140 // now set the page
141 SdrUnoObj::SetPage(_pNewPage);
144 //----------------------------------------------------------------------------
146 namespace
148 /** returns the DlgEdForm which the given DlgEdObj belongs to
149 (which might in fact be the object itself)
151 Failure to obtain the form will be reported with an assertion in the non-product
152 version.
154 bool lcl_getDlgEdForm( DlgEdObj* _pObject, DlgEdForm*& _out_pDlgEdForm )
156 _out_pDlgEdForm = dynamic_cast< DlgEdForm* >( _pObject );
157 if ( !_out_pDlgEdForm )
158 _out_pDlgEdForm = _pObject->GetDlgEdForm();
159 DBG_ASSERT( _out_pDlgEdForm, "lcl_getDlgEdForm: no form!" );
160 return ( _out_pDlgEdForm != NULL );
164 //----------------------------------------------------------------------------
166 uno::Reference< awt::XControl > DlgEdObj::GetControl() const
168 const DlgEdForm* pForm = GetDlgEdForm();
169 const DlgEditor* pEditor = pForm ? pForm->GetDlgEditor() : NULL;
170 SdrView* pView = pEditor ? pEditor->GetView() : NULL;
171 Window* pWindow = pEditor ? pEditor->GetWindow() : NULL;
172 OSL_ENSURE( ( pView && pWindow ) || !pForm, "DlgEdObj::GetControl: no view or no window!" );
174 uno::Reference< awt::XControl > xControl;
175 if ( pView && pWindow )
176 xControl = GetUnoControl( *pView, *pWindow );
178 return xControl;
181 //----------------------------------------------------------------------------
183 bool DlgEdObj::TransformSdrToControlCoordinates(
184 sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
185 sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
187 // input position and size
188 Size aPos( nXIn, nYIn );
189 Size aSize( nWidthIn, nHeightIn );
191 // form position
192 DlgEdForm* pForm = NULL;
193 if ( !lcl_getDlgEdForm( this, pForm ) )
194 return false;
195 Rectangle aFormRect = pForm->GetSnapRect();
196 Size aFormPos( aFormRect.Left(), aFormRect.Top() );
198 // convert 100th_mm to pixel
199 OutputDevice* pDevice = Application::GetDefaultDevice();
200 DBG_ASSERT( pDevice, "DlgEdObj::TransformSdrToControlCoordinates: missing default device!" );
201 if ( !pDevice )
202 return false;
203 aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_100TH_MM ) );
204 aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_100TH_MM ) );
205 aFormPos = pDevice->LogicToPixel( aFormPos, MapMode( MAP_100TH_MM ) );
207 // subtract form position
208 aPos.Width() -= aFormPos.Width();
209 aPos.Height() -= aFormPos.Height();
211 // take window borders into account
212 Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
213 DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
214 if ( !xPSetForm.is() )
215 return false;
216 bool bDecoration = true;
217 xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
218 if( bDecoration )
220 awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
221 aPos.Width() -= aDeviceInfo.LeftInset;
222 aPos.Height() -= aDeviceInfo.TopInset;
225 // convert pixel to logic units
226 MapMode aConvMode = lcl_getMapModeForForm( pForm );
227 aPos = pDevice->PixelToLogic( aPos, aConvMode );
228 aSize = pDevice->PixelToLogic( aSize, aConvMode );
230 // set out parameters
231 nXOut = aPos.Width();
232 nYOut = aPos.Height();
233 nWidthOut = aSize.Width();
234 nHeightOut = aSize.Height();
236 return true;
239 //----------------------------------------------------------------------------
241 bool DlgEdObj::TransformSdrToFormCoordinates(
242 sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
243 sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
245 // input position and size
246 Size aPos( nXIn, nYIn );
247 Size aSize( nWidthIn, nHeightIn );
249 // convert 100th_mm to pixel
250 OutputDevice* pDevice = Application::GetDefaultDevice();
251 DBG_ASSERT( pDevice, "DlgEdObj::TransformSdrToFormCoordinates: missing default device!" );
252 if ( !pDevice )
253 return false;
254 aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_100TH_MM ) );
255 aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_100TH_MM ) );
257 // take window borders into account
258 DlgEdForm* pForm = NULL;
259 if ( !lcl_getDlgEdForm( this, pForm ) )
260 return false;
262 // take window borders into account
263 Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
264 DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
265 if ( !xPSetForm.is() )
266 return false;
267 bool bDecoration = true;
268 xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
269 if( bDecoration )
271 awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
272 aSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
273 aSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
275 MapMode aConvMode = lcl_getMapModeForForm( pForm );
276 // convert pixel to logic units
277 aPos = pDevice->PixelToLogic( aPos, aConvMode );
278 aSize = pDevice->PixelToLogic( aSize, aConvMode );
280 // set out parameters
281 nXOut = aPos.Width();
282 nYOut = aPos.Height();
283 nWidthOut = aSize.Width();
284 nHeightOut = aSize.Height();
286 return true;
289 //----------------------------------------------------------------------------
291 bool DlgEdObj::TransformControlToSdrCoordinates(
292 sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
293 sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
295 // input position and size
296 Size aPos( nXIn, nYIn );
297 Size aSize( nWidthIn, nHeightIn );
299 // form position
300 DlgEdForm* pForm = NULL;
301 if ( !lcl_getDlgEdForm( this, pForm ) )
302 return false;
304 Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
305 DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformControlToSdrCoordinates: no form property set!" );
306 if ( !xPSetForm.is() )
307 return false;
308 sal_Int32 nFormX = 0, nFormY = 0, nFormWidth, nFormHeight;
309 xPSetForm->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nFormX;
310 xPSetForm->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nFormY;
311 xPSetForm->getPropertyValue( DLGED_PROP_WIDTH ) >>= nFormWidth;
312 xPSetForm->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nFormHeight;
313 Size aFormPos( nFormX, nFormY );
315 // convert logic units to pixel
316 OutputDevice* pDevice = Application::GetDefaultDevice();
317 DBG_ASSERT( pDevice, "DlgEdObj::TransformControlToSdrCoordinates: missing default device!" );
318 if ( !pDevice )
319 return false;
320 MapMode aConvMode = lcl_getMapModeForForm( pForm );
321 aPos = pDevice->LogicToPixel( aPos, aConvMode );
322 aSize = pDevice->LogicToPixel( aSize, aConvMode );
323 aFormPos = pDevice->LogicToPixel( aFormPos, aConvMode );
325 // add form position
326 aPos.Width() += aFormPos.Width();
327 aPos.Height() += aFormPos.Height();
329 // take window borders into account
330 bool bDecoration = true;
331 xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
332 if( bDecoration )
334 awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
335 aPos.Width() += aDeviceInfo.LeftInset;
336 aPos.Height() += aDeviceInfo.TopInset;
339 // convert pixel to 100th_mm
340 aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_100TH_MM ) );
341 aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_100TH_MM ) );
343 // set out parameters
344 nXOut = aPos.Width();
345 nYOut = aPos.Height();
346 nWidthOut = aSize.Width();
347 nHeightOut = aSize.Height();
349 return true;
352 //----------------------------------------------------------------------------
354 bool DlgEdObj::TransformFormToSdrCoordinates(
355 sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
356 sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
358 // input position and size
359 Size aPos( nXIn, nYIn );
360 Size aSize( nWidthIn, nHeightIn );
362 // convert logic units to pixel
363 OutputDevice* pDevice = Application::GetDefaultDevice();
364 DBG_ASSERT( pDevice, "DlgEdObj::TransformFormToSdrCoordinates: missing default device!" );
365 if ( !pDevice )
366 return false;
368 // take window borders into account
369 DlgEdForm* pForm = NULL;
370 if ( !lcl_getDlgEdForm( this, pForm ) )
371 return false;
373 MapMode aConvMode = lcl_getMapModeForForm( pForm );
374 aPos = pDevice->LogicToPixel( aPos, aConvMode );
375 aSize = pDevice->LogicToPixel( aSize, aConvMode );
377 // take window borders into account
378 Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
379 DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
380 if ( !xPSetForm.is() )
381 return false;
382 bool bDecoration = true;
383 xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
384 if( bDecoration )
386 awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
387 aSize.Width() += aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
388 aSize.Height() += aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
391 // convert pixel to 100th_mm
392 aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_100TH_MM ) );
393 aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_100TH_MM ) );
395 // set out parameters
396 nXOut = aPos.Width();
397 nYOut = aPos.Height();
398 nWidthOut = aSize.Width();
399 nHeightOut = aSize.Height();
401 return true;
404 //----------------------------------------------------------------------------
406 void DlgEdObj::SetRectFromProps()
408 // get control position and size from properties
409 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
410 if ( xPSet.is() )
412 sal_Int32 nXIn = 0, nYIn = 0, nWidthIn = 0, nHeightIn = 0;
413 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nXIn;
414 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nYIn;
415 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidthIn;
416 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeightIn;
418 // transform coordinates
419 sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
420 if ( TransformControlToSdrCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
422 // set rectangle position and size
423 Point aPoint( nXOut, nYOut );
424 Size aSize( nWidthOut, nHeightOut );
425 SetSnapRect( Rectangle( aPoint, aSize ) );
430 //----------------------------------------------------------------------------
432 void DlgEdObj::SetPropsFromRect()
434 // get control position and size from rectangle
435 Rectangle aRect_ = GetSnapRect();
436 sal_Int32 nXIn = aRect_.Left();
437 sal_Int32 nYIn = aRect_.Top();
438 sal_Int32 nWidthIn = aRect_.GetWidth();
439 sal_Int32 nHeightIn = aRect_.GetHeight();
441 // transform coordinates
442 sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
443 if ( TransformSdrToControlCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
445 // set properties
446 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
447 if ( xPSet.is() )
449 Any aValue;
450 aValue <<= nXOut;
451 xPSet->setPropertyValue( DLGED_PROP_POSITIONX, aValue );
452 aValue <<= nYOut;
453 xPSet->setPropertyValue( DLGED_PROP_POSITIONY, aValue );
454 aValue <<= nWidthOut;
455 xPSet->setPropertyValue( DLGED_PROP_WIDTH, aValue );
456 aValue <<= nHeightOut;
457 xPSet->setPropertyValue( DLGED_PROP_HEIGHT, aValue );
462 //----------------------------------------------------------------------------
464 void DlgEdObj::PositionAndSizeChange( const beans::PropertyChangeEvent& evt )
466 DlgEdPage* pPage_ = 0;
467 if ( pDlgEdForm )
469 DlgEditor* pEditor = pDlgEdForm->GetDlgEditor();
470 if ( pEditor )
471 pPage_ = pEditor->GetPage();
473 DBG_ASSERT( pPage_, "DlgEdObj::PositionAndSizeChange: no page!" );
474 if ( pPage_ )
476 sal_Int32 nPageXIn = 0;
477 sal_Int32 nPageYIn = 0;
478 Size aPageSize = pPage_->GetSize();
479 sal_Int32 nPageWidthIn = aPageSize.Width();
480 sal_Int32 nPageHeightIn = aPageSize.Height();
481 sal_Int32 nPageX, nPageY, nPageWidth, nPageHeight;
482 if ( TransformSdrToControlCoordinates( nPageXIn, nPageYIn, nPageWidthIn, nPageHeightIn, nPageX, nPageY, nPageWidth, nPageHeight ) )
484 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
485 if ( xPSet.is() )
487 sal_Int32 nX = 0, nY = 0, nWidth = 0, nHeight = 0;
488 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nX;
489 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nY;
490 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidth;
491 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeight;
493 sal_Int32 nValue = 0;
494 evt.NewValue >>= nValue;
495 sal_Int32 nNewValue = nValue;
497 if ( evt.PropertyName == DLGED_PROP_POSITIONX )
499 if ( nNewValue + nWidth > nPageX + nPageWidth )
500 nNewValue = nPageX + nPageWidth - nWidth;
501 if ( nNewValue < nPageX )
502 nNewValue = nPageX;
504 else if ( evt.PropertyName == DLGED_PROP_POSITIONY )
506 if ( nNewValue + nHeight > nPageY + nPageHeight )
507 nNewValue = nPageY + nPageHeight - nHeight;
508 if ( nNewValue < nPageY )
509 nNewValue = nPageY;
511 else if ( evt.PropertyName == DLGED_PROP_WIDTH )
513 if ( nX + nNewValue > nPageX + nPageWidth )
514 nNewValue = nPageX + nPageWidth - nX;
515 if ( nNewValue < 1 )
516 nNewValue = 1;
518 else if ( evt.PropertyName == DLGED_PROP_HEIGHT )
520 if ( nY + nNewValue > nPageY + nPageHeight )
521 nNewValue = nPageY + nPageHeight - nY;
522 if ( nNewValue < 1 )
523 nNewValue = 1;
526 if ( nNewValue != nValue )
528 Any aNewValue;
529 aNewValue <<= nNewValue;
530 EndListening( sal_False );
531 xPSet->setPropertyValue( evt.PropertyName, aNewValue );
532 StartListening();
538 SetRectFromProps();
541 //----------------------------------------------------------------------------
543 void SAL_CALL DlgEdObj::NameChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException)
545 // get old name
546 ::rtl::OUString aOldName;
547 evt.OldValue >>= aOldName;
549 // get new name
550 ::rtl::OUString aNewName;
551 evt.NewValue >>= aNewName;
553 if ( !aNewName.equals(aOldName) )
555 Reference< container::XNameAccess > xNameAcc((GetDlgEdForm()->GetUnoControlModel()), UNO_QUERY);
556 if ( xNameAcc.is() && xNameAcc->hasByName(aOldName) )
558 if ( !xNameAcc->hasByName(aNewName) && aNewName.getLength() != 0 )
560 // remove the control by the old name and insert the control by the new name in the container
561 Reference< container::XNameContainer > xCont(xNameAcc, UNO_QUERY );
562 if ( xCont.is() )
564 Reference< awt::XControlModel > xCtrl(GetUnoControlModel(), UNO_QUERY);
565 Any aAny;
566 aAny <<= xCtrl;
567 xCont->removeByName( aOldName );
568 xCont->insertByName( aNewName , aAny );
570 DlgEditor* pEditor;
571 if ( ISA(DlgEdForm) )
572 pEditor = ((DlgEdForm*)this)->GetDlgEditor();
573 else
574 pEditor = GetDlgEdForm()->GetDlgEditor();
575 LocalizationMgr::renameControlResourceIDsForEditorObject( pEditor, aAny, aNewName );
578 else
580 // set old name property
581 EndListening(sal_False);
582 Reference< beans::XPropertySet > xPSet(GetUnoControlModel(), UNO_QUERY);
583 Any aName;
584 aName <<= aOldName;
585 xPSet->setPropertyValue( DLGED_PROP_NAME, aName );
586 StartListening();
592 //----------------------------------------------------------------------------
594 sal_Int32 DlgEdObj::GetStep() const
596 // get step property
597 sal_Int32 nStep = 0;
598 uno::Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), uno::UNO_QUERY );
599 if (xPSet.is())
601 xPSet->getPropertyValue( DLGED_PROP_STEP ) >>= nStep;
603 return nStep;
606 //----------------------------------------------------------------------------
608 void DlgEdObj::UpdateStep()
610 sal_Int32 nCurStep = GetDlgEdForm()->GetStep();
611 sal_Int32 nStep = GetStep();
613 SdrLayerAdmin& rLayerAdmin = GetModel()->GetLayerAdmin();
614 SdrLayerID nHiddenLayerId = rLayerAdmin.GetLayerID( String( RTL_CONSTASCII_USTRINGPARAM( "HiddenLayer" ) ), FALSE );
615 SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), sal_False );
617 if( nCurStep )
619 if ( nStep && (nStep != nCurStep) )
621 SetLayer( nHiddenLayerId );
623 else
625 SetLayer( nControlLayerId );
628 else
630 SetLayer( nControlLayerId );
634 //----------------------------------------------------------------------------
636 void DlgEdObj::TabIndexChange( const beans::PropertyChangeEvent& evt ) throw (RuntimeException)
638 DlgEdForm* pForm = GetDlgEdForm();
639 if ( pForm )
641 // stop listening with all children
642 ::std::vector<DlgEdObj*> aChildList = pForm->GetChilds();
643 ::std::vector<DlgEdObj*>::iterator aIter;
644 for ( aIter = aChildList.begin() ; aIter != aChildList.end() ; ++aIter )
646 (*aIter)->EndListening( sal_False );
649 Reference< container::XNameAccess > xNameAcc( pForm->GetUnoControlModel() , UNO_QUERY );
650 if ( xNameAcc.is() )
652 // get sequence of control names
653 Sequence< ::rtl::OUString > aNames = xNameAcc->getElementNames();
654 const ::rtl::OUString* pNames = aNames.getConstArray();
655 sal_Int32 nCtrls = aNames.getLength();
656 sal_Int16 i;
658 // create a map of tab indices and control names, sorted by tab index
659 IndexToNameMap aIndexToNameMap;
660 for ( i = 0; i < nCtrls; ++i )
662 // get control name
663 ::rtl::OUString aName( pNames[i] );
665 // get tab index
666 sal_Int16 nTabIndex = -1;
667 Any aCtrl = xNameAcc->getByName( aName );
668 Reference< beans::XPropertySet > xPSet;
669 aCtrl >>= xPSet;
670 if ( xPSet.is() && xPSet == Reference< beans::XPropertySet >( evt.Source, UNO_QUERY ) )
671 evt.OldValue >>= nTabIndex;
672 else if ( xPSet.is() )
673 xPSet->getPropertyValue( DLGED_PROP_TABINDEX ) >>= nTabIndex;
675 // insert into map
676 aIndexToNameMap.insert( IndexToNameMap::value_type( nTabIndex, aName ) );
679 // create a helper list of control names, sorted by tab index
680 ::std::vector< ::rtl::OUString > aNameList( aIndexToNameMap.size() );
681 ::std::transform(
682 aIndexToNameMap.begin(), aIndexToNameMap.end(),
683 aNameList.begin(),
684 ::std::select2nd< IndexToNameMap::value_type >( )
687 // check tab index
688 sal_Int16 nOldTabIndex = 0;
689 evt.OldValue >>= nOldTabIndex;
690 sal_Int16 nNewTabIndex = 0;
691 evt.NewValue >>= nNewTabIndex;
692 if ( nNewTabIndex < 0 )
693 nNewTabIndex = 0;
694 else if ( nNewTabIndex > nCtrls - 1 )
695 nNewTabIndex = sal::static_int_cast<sal_Int16>( nCtrls - 1 );
697 // reorder helper list
698 ::rtl::OUString aCtrlName = aNameList[nOldTabIndex];
699 aNameList.erase( aNameList.begin() + nOldTabIndex );
700 aNameList.insert( aNameList.begin() + nNewTabIndex , aCtrlName );
702 // set new tab indices
703 for ( i = 0; i < nCtrls; ++i )
705 Any aCtrl = xNameAcc->getByName( aNameList[i] );
706 Reference< beans::XPropertySet > xPSet;
707 aCtrl >>= xPSet;
708 if ( xPSet.is() )
710 Any aTabIndex;
711 aTabIndex <<= (sal_Int16) i;
712 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
716 // reorder objects in drawing page
717 GetModel()->GetPage(0)->SetObjectOrdNum( nOldTabIndex + 1, nNewTabIndex + 1 );
719 // #110559#
720 pForm->UpdateTabOrderAndGroups();
723 // start listening with all children
724 for ( aIter = aChildList.begin() ; aIter != aChildList.end() ; ++aIter )
726 (*aIter)->StartListening();
731 //----------------------------------------------------------------------------
733 sal_Bool DlgEdObj::supportsService( const sal_Char* _pServiceName ) const
735 sal_Bool bSupports = sal_False;
737 Reference< lang::XServiceInfo > xServiceInfo( GetUnoControlModel() , UNO_QUERY );
738 // TODO: cache xServiceInfo as member?
739 if ( xServiceInfo.is() )
740 bSupports = xServiceInfo->supportsService( ::rtl::OUString::createFromAscii( _pServiceName ) );
742 return bSupports;
745 //----------------------------------------------------------------------------
747 ::rtl::OUString DlgEdObj::GetDefaultName() const
749 sal_uInt16 nResId = 0;
750 ::rtl::OUString aDefaultName;
751 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
753 nResId = RID_STR_CLASS_DIALOG;
755 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
757 nResId = RID_STR_CLASS_BUTTON;
759 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
761 nResId = RID_STR_CLASS_RADIOBUTTON;
763 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
765 nResId = RID_STR_CLASS_CHECKBOX;
767 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
769 nResId = RID_STR_CLASS_LISTBOX;
771 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
773 nResId = RID_STR_CLASS_COMBOBOX;
775 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
777 nResId = RID_STR_CLASS_GROUPBOX;
779 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
781 nResId = RID_STR_CLASS_EDIT;
783 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
785 nResId = RID_STR_CLASS_FIXEDTEXT;
787 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
789 nResId = RID_STR_CLASS_IMAGECONTROL;
791 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
793 nResId = RID_STR_CLASS_PROGRESSBAR;
795 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
797 nResId = RID_STR_CLASS_SCROLLBAR;
799 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
801 nResId = RID_STR_CLASS_FIXEDLINE;
803 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
805 nResId = RID_STR_CLASS_DATEFIELD;
807 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
809 nResId = RID_STR_CLASS_TIMEFIELD;
811 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
813 nResId = RID_STR_CLASS_NUMERICFIELD;
815 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
817 nResId = RID_STR_CLASS_CURRENCYFIELD;
819 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
821 nResId = RID_STR_CLASS_FORMATTEDFIELD;
823 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
825 nResId = RID_STR_CLASS_PATTERNFIELD;
827 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
829 nResId = RID_STR_CLASS_FILECONTROL;
831 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
833 nResId = RID_STR_CLASS_TREECONTROL;
836 else
838 nResId = RID_STR_CLASS_CONTROL;
841 if (nResId)
843 aDefaultName = ::rtl::OUString( String(IDEResId(nResId)) );
846 return aDefaultName;
849 //----------------------------------------------------------------------------
851 ::rtl::OUString DlgEdObj::GetUniqueName() const
853 ::rtl::OUString aUniqueName;
854 uno::Reference< container::XNameAccess > xNameAcc((GetDlgEdForm()->GetUnoControlModel()), uno::UNO_QUERY);
856 if ( xNameAcc.is() )
858 sal_Int32 n = 0;
859 ::rtl::OUString aDefaultName = GetDefaultName();
863 aUniqueName = aDefaultName + ::rtl::OUString::valueOf(++n);
864 } while (xNameAcc->hasByName(aUniqueName));
867 return aUniqueName;
870 //----------------------------------------------------------------------------
872 sal_uInt32 DlgEdObj::GetObjInventor() const
874 return DlgInventor;
877 //----------------------------------------------------------------------------
879 sal_uInt16 DlgEdObj::GetObjIdentifier() const
881 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ))
883 return OBJ_DLG_DIALOG;
885 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ))
887 return OBJ_DLG_PUSHBUTTON;
889 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ))
891 return OBJ_DLG_RADIOBUTTON;
893 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ))
895 return OBJ_DLG_CHECKBOX;
897 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ))
899 return OBJ_DLG_LISTBOX;
901 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ))
903 return OBJ_DLG_COMBOBOX;
905 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ))
907 return OBJ_DLG_GROUPBOX;
909 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ))
911 return OBJ_DLG_EDIT;
913 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ))
915 return OBJ_DLG_FIXEDTEXT;
917 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ))
919 return OBJ_DLG_IMAGECONTROL;
921 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ))
923 return OBJ_DLG_PROGRESSBAR;
925 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ))
927 return OBJ_DLG_HSCROLLBAR;
929 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ))
931 return OBJ_DLG_HFIXEDLINE;
933 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ))
935 return OBJ_DLG_DATEFIELD;
937 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ))
939 return OBJ_DLG_TIMEFIELD;
941 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ))
943 return OBJ_DLG_NUMERICFIELD;
945 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ))
947 return OBJ_DLG_CURRENCYFIELD;
949 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ))
951 return OBJ_DLG_FORMATTEDFIELD;
953 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ))
955 return OBJ_DLG_PATTERNFIELD;
957 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ))
959 return OBJ_DLG_FILECONTROL;
961 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ))
963 return OBJ_DLG_TREECONTROL;
965 else
967 return OBJ_DLG_CONTROL;
971 //----------------------------------------------------------------------------
973 void DlgEdObj::clonedFrom(const DlgEdObj* _pSource)
975 // set parent form
976 pDlgEdForm = _pSource->pDlgEdForm;
978 // add child to parent form
979 pDlgEdForm->AddChild( this );
981 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
982 if ( xPSet.is() )
984 // set new name
985 ::rtl::OUString aOUniqueName( GetUniqueName() );
986 Any aUniqueName;
987 aUniqueName <<= aOUniqueName;
988 xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName );
990 Reference< container::XNameContainer > xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY );
991 if ( xCont.is() )
993 // set tabindex
994 Sequence< OUString > aNames = xCont->getElementNames();
995 Any aTabIndex;
996 aTabIndex <<= (sal_Int16) aNames.getLength();
997 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
999 // insert control model in dialog model
1000 Reference< awt::XControlModel > xCtrl( xPSet , UNO_QUERY );
1001 Any aCtrl;
1002 aCtrl <<= xCtrl;
1003 xCont->insertByName( aOUniqueName , aCtrl );
1005 // #110559#
1006 pDlgEdForm->UpdateTabOrderAndGroups();
1010 // start listening
1011 StartListening();
1014 //----------------------------------------------------------------------------
1016 SdrObject* DlgEdObj::Clone() const
1018 SdrObject* pReturn = SdrUnoObj::Clone();
1020 DlgEdObj* pDlgEdObj = PTR_CAST(DlgEdObj, pReturn);
1021 DBG_ASSERT( pDlgEdObj != NULL, "DlgEdObj::Clone: invalid clone!" );
1022 if ( pDlgEdObj )
1023 pDlgEdObj->clonedFrom( this );
1025 return pReturn;
1028 //----------------------------------------------------------------------------
1030 SdrObject* DlgEdObj::getFullDragClone() const
1032 // no need to really add the clone for dragging, it's a temporary
1033 // object
1034 SdrObject* pObj = new SdrUnoObj(String());
1035 *pObj = *((const SdrUnoObj*)this);
1037 return pObj;
1040 //----------------------------------------------------------------------------
1042 void DlgEdObj::operator= (const SdrObject& rObj)
1044 SdrUnoObj::operator= (rObj);
1047 //----------------------------------------------------------------------------
1049 void DlgEdObj::NbcMove( const Size& rSize )
1051 SdrUnoObj::NbcMove( rSize );
1053 // stop listening
1054 EndListening(sal_False);
1056 // set geometry properties
1057 SetPropsFromRect();
1059 // start listening
1060 StartListening();
1062 // dialog model changed
1063 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1066 //----------------------------------------------------------------------------
1068 void DlgEdObj::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1070 SdrUnoObj::NbcResize( rRef, xFract, yFract );
1072 // stop listening
1073 EndListening(sal_False);
1075 // set geometry properties
1076 SetPropsFromRect();
1078 // start listening
1079 StartListening();
1081 // dialog model changed
1082 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1085 //----------------------------------------------------------------------------
1087 FASTBOOL DlgEdObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1089 FASTBOOL bResult = SdrUnoObj::EndCreate(rStat, eCmd);
1091 SetDefaults();
1092 StartListening();
1094 return bResult;
1097 //----------------------------------------------------------------------------
1099 void DlgEdObj::SetDefaults()
1101 // set parent form
1102 pDlgEdForm = ((DlgEdPage*)GetPage())->GetDlgEdForm();
1104 if ( pDlgEdForm )
1106 // add child to parent form
1107 pDlgEdForm->AddChild( this );
1109 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
1110 if ( xPSet.is() )
1112 // get unique name
1113 ::rtl::OUString aOUniqueName( GetUniqueName() );
1115 // set name property
1116 Any aUniqueName;
1117 aUniqueName <<= aOUniqueName;
1118 xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName );
1120 // set labels
1121 if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) ||
1122 supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) ||
1123 supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) ||
1124 supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) ||
1125 supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
1127 xPSet->setPropertyValue( DLGED_PROP_LABEL, aUniqueName );
1130 // set number formats supplier for formatted field
1131 if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
1133 Reference< util::XNumberFormatsSupplier > xSupplier = GetDlgEdForm()->GetDlgEditor()->GetNumberFormatsSupplier();
1134 if ( xSupplier.is() )
1136 Any aSupplier;
1137 aSupplier <<= xSupplier;
1138 xPSet->setPropertyValue( DLGED_PROP_FORMATSSUPPLIER, aSupplier );
1142 // set geometry properties
1143 SetPropsFromRect();
1145 Reference< container::XNameContainer > xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY );
1146 if ( xCont.is() )
1148 // set tabindex
1149 Sequence< OUString > aNames = xCont->getElementNames();
1150 uno::Any aTabIndex;
1151 aTabIndex <<= (sal_Int16) aNames.getLength();
1152 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
1154 // set step
1155 Reference< beans::XPropertySet > xPSetForm( xCont, UNO_QUERY );
1156 if ( xPSetForm.is() )
1158 Any aStep = xPSetForm->getPropertyValue( DLGED_PROP_STEP );
1159 xPSet->setPropertyValue( DLGED_PROP_STEP, aStep );
1162 // insert control model in dialog model
1163 Reference< awt::XControlModel > xCtrl( xPSet , UNO_QUERY );
1164 Any aAny;
1165 aAny <<= xCtrl;
1166 xCont->insertByName( aOUniqueName , aAny );
1168 DlgEditor* pEditor;
1169 if ( ISA(DlgEdForm) )
1170 pEditor = ((DlgEdForm*)this)->GetDlgEditor();
1171 else
1172 pEditor = GetDlgEdForm()->GetDlgEditor();
1173 LocalizationMgr::setControlResourceIDsForNewEditorObject( pEditor, aAny, aOUniqueName );
1175 // #110559#
1176 pDlgEdForm->UpdateTabOrderAndGroups();
1180 // dialog model changed
1181 pDlgEdForm->GetDlgEditor()->SetDialogModelChanged( TRUE );
1185 //----------------------------------------------------------------------------
1187 IMPL_LINK(DlgEdObj, OnCreate, void*, EMPTYTAG)
1189 (void)EMPTYTAG;
1191 if (pTempView)
1192 pTempView->ObjectCreated(this);
1194 return 0;
1197 //----------------------------------------------------------------------------
1199 void DlgEdObj::StartListening()
1201 DBG_ASSERT(!isListening(), "DlgEdObj::StartListening: already listening!");
1203 if (!isListening())
1205 bIsListening = sal_True;
1207 // XPropertyChangeListener
1208 Reference< XPropertySet > xControlModel( GetUnoControlModel() , UNO_QUERY );
1209 if (!m_xPropertyChangeListener.is() && xControlModel.is())
1211 // create listener
1212 m_xPropertyChangeListener = static_cast< ::com::sun::star::beans::XPropertyChangeListener*>( new DlgEdPropListenerImpl( (DlgEdObj*)this ) );
1214 // register listener to properties
1215 xControlModel->addPropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener );
1218 // XContainerListener
1219 Reference< XScriptEventsSupplier > xEventsSupplier( GetUnoControlModel() , UNO_QUERY );
1220 if( !m_xContainerListener.is() && xEventsSupplier.is() )
1222 // create listener
1223 m_xContainerListener = static_cast< ::com::sun::star::container::XContainerListener*>( new DlgEdEvtContListenerImpl( (DlgEdObj*)this ) );
1225 // register listener to script event container
1226 Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents();
1227 DBG_ASSERT(xEventCont.is(), "DlgEdObj::StartListening: control model has no script event container!");
1228 Reference< XContainer > xCont( xEventCont , UNO_QUERY );
1229 if (xCont.is())
1230 xCont->addContainerListener( m_xContainerListener );
1235 //----------------------------------------------------------------------------
1237 void DlgEdObj::EndListening(sal_Bool bRemoveListener)
1239 DBG_ASSERT(isListening(), "DlgEdObj::EndListening: not listening currently!");
1241 if (isListening())
1243 bIsListening = sal_False;
1245 if (bRemoveListener)
1247 // XPropertyChangeListener
1248 Reference< XPropertySet > xControlModel(GetUnoControlModel(), UNO_QUERY);
1249 if ( m_xPropertyChangeListener.is() && xControlModel.is() )
1251 // remove listener
1252 xControlModel->removePropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener );
1254 m_xPropertyChangeListener.clear();
1256 // XContainerListener
1257 Reference< XScriptEventsSupplier > xEventsSupplier( GetUnoControlModel() , UNO_QUERY );
1258 if( m_xContainerListener.is() && xEventsSupplier.is() )
1260 // remove listener
1261 Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents();
1262 DBG_ASSERT(xEventCont.is(), "DlgEdObj::EndListening: control model has no script event container!");
1263 Reference< XContainer > xCont( xEventCont , UNO_QUERY );
1264 if (xCont.is())
1265 xCont->removeContainerListener( m_xContainerListener );
1267 m_xContainerListener.clear();
1272 //----------------------------------------------------------------------------
1274 void SAL_CALL DlgEdObj::_propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException)
1276 if (isListening())
1278 DlgEdForm* pRealDlgEdForm = dynamic_cast< DlgEdForm* >(this);
1279 if( pRealDlgEdForm == 0 )
1280 pRealDlgEdForm = GetDlgEdForm();
1282 DlgEditor* pDlgEditor = pRealDlgEdForm ? pRealDlgEdForm->GetDlgEditor() : 0;
1284 if( !pDlgEditor || pDlgEditor->isInPaint() )
1285 return;
1287 // dialog model changed
1288 pDlgEditor->SetDialogModelChanged(TRUE);
1290 // update position and size
1291 if ( evt.PropertyName == DLGED_PROP_POSITIONX || evt.PropertyName == DLGED_PROP_POSITIONY ||
1292 evt.PropertyName == DLGED_PROP_WIDTH || evt.PropertyName == DLGED_PROP_HEIGHT ||
1293 evt.PropertyName == DLGED_PROP_DECORATION )
1295 PositionAndSizeChange( evt );
1297 if ( evt.PropertyName == DLGED_PROP_DECORATION )
1299 if ( ISA(DlgEdForm) )
1300 ((DlgEdForm*)this)->GetDlgEditor()->ResetDialog();
1301 else
1302 GetDlgEdForm()->GetDlgEditor()->ResetDialog();
1305 // change name of control in dialog model
1306 else if ( evt.PropertyName == DLGED_PROP_NAME )
1308 if ( !ISA(DlgEdForm) )
1310 NameChange(evt);
1313 // update step
1314 else if ( evt.PropertyName == DLGED_PROP_STEP )
1316 UpdateStep();
1318 // change tabindex
1319 else if ( evt.PropertyName == DLGED_PROP_TABINDEX )
1321 if ( !ISA(DlgEdForm) )
1323 TabIndexChange(evt);
1329 //----------------------------------------------------------------------------
1331 void SAL_CALL DlgEdObj::_elementInserted(const ::com::sun::star::container::ContainerEvent& ) throw(::com::sun::star::uno::RuntimeException)
1333 if (isListening())
1335 // dialog model changed
1336 if ( ISA(DlgEdForm) )
1338 ((DlgEdForm*)this)->GetDlgEditor()->SetDialogModelChanged(TRUE);
1340 else
1342 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1347 //----------------------------------------------------------------------------
1349 void SAL_CALL DlgEdObj::_elementReplaced(const ::com::sun::star::container::ContainerEvent& ) throw(::com::sun::star::uno::RuntimeException)
1351 if (isListening())
1353 // dialog model changed
1354 if ( ISA(DlgEdForm) )
1356 ((DlgEdForm*)this)->GetDlgEditor()->SetDialogModelChanged(TRUE);
1358 else
1360 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1365 //----------------------------------------------------------------------------
1367 void SAL_CALL DlgEdObj::_elementRemoved(const ::com::sun::star::container::ContainerEvent& ) throw(::com::sun::star::uno::RuntimeException)
1369 if (isListening())
1371 // dialog model changed
1372 if ( ISA(DlgEdForm) )
1374 ((DlgEdForm*)this)->GetDlgEditor()->SetDialogModelChanged(TRUE);
1376 else
1378 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1383 //----------------------------------------------------------------------------
1385 void DlgEdObj::SetLayer(SdrLayerID nLayer)
1387 SdrLayerID nOldLayer = GetLayer();
1389 if ( nLayer != nOldLayer )
1391 SdrUnoObj::SetLayer( nLayer );
1393 DlgEdHint aHint( DLGED_HINT_LAYERCHANGED, this );
1394 GetDlgEdForm()->GetDlgEditor()->Broadcast( aHint );
1398 //----------------------------------------------------------------------------
1400 SdrObject* DlgEdObj::CheckHit( const Point& rPnt, USHORT nTol,const SetOfByte* pSet ) const
1402 // #109994# fixed here, because the drawing layer doesn't handle objects
1403 // with a width or height of 0 in a proper way
1404 Rectangle aRect_( aOutRect );
1405 if ( aRect_.IsEmpty() )
1407 aRect_.Left() -= nTol;
1408 aRect_.Top() -= nTol;
1409 aRect_.Right() = ( aRect_.Right() == RECT_EMPTY ? aOutRect.Left() + nTol : aRect_.Right() + nTol );
1410 aRect_.Bottom() = ( aRect_.Bottom() == RECT_EMPTY ? aOutRect.Top() + nTol : aRect_.Bottom() + nTol );
1412 if ( aRect_.IsInside( rPnt ) )
1413 return (SdrObject*)this;
1414 else
1415 return 0;
1418 if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ))
1420 Rectangle aROuter = aOutRect;
1421 aROuter.Left() -= nTol;
1422 aROuter.Right() += nTol;
1423 aROuter.Top() -= nTol;
1424 aROuter.Bottom() += nTol;
1426 Rectangle aRInner = aOutRect;
1427 if( (aRInner.GetSize().Height() > (long)nTol*2) &&
1428 (aRInner.GetSize().Width() > (long)nTol*2) )
1430 aRInner.Left() += nTol;
1431 aRInner.Right() -= nTol;
1432 aRInner.Top() += nTol;
1433 aRInner.Bottom() -= nTol;
1436 if( aROuter.IsInside( rPnt ) && !aRInner.IsInside( rPnt ) )
1437 return (SdrObject*)this;
1438 else
1439 return 0;
1441 else
1442 return SdrUnoObj::CheckHit( rPnt, nTol, pSet );
1446 //----------------------------------------------------------------------------
1448 TYPEINIT1(DlgEdForm, DlgEdObj);
1449 DBG_NAME(DlgEdForm);
1451 //----------------------------------------------------------------------------
1453 DlgEdForm::DlgEdForm(const ::rtl::OUString& rModelName)
1454 :DlgEdObj(rModelName)
1456 DBG_CTOR(DlgEdForm, NULL);
1459 //----------------------------------------------------------------------------
1461 DlgEdForm::DlgEdForm(const ::rtl::OUString& rModelName,
1462 const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac)
1463 :DlgEdObj(rModelName, rxSFac)
1465 DBG_CTOR(DlgEdForm, NULL);
1468 //----------------------------------------------------------------------------
1470 DlgEdForm::DlgEdForm()
1471 :DlgEdObj()
1473 DBG_CTOR(DlgEdForm, NULL);
1476 //----------------------------------------------------------------------------
1478 DlgEdForm::~DlgEdForm()
1480 DBG_DTOR(DlgEdForm, NULL);
1483 //----------------------------------------------------------------------------
1485 void DlgEdForm::SetDlgEditor( DlgEditor* pEditor )
1487 pDlgEditor = pEditor;
1488 ImplInvalidateDeviceInfo();
1491 //----------------------------------------------------------------------------
1493 void DlgEdForm::ImplInvalidateDeviceInfo()
1495 mpDeviceInfo.reset();
1498 //----------------------------------------------------------------------------
1500 void DlgEdForm::SetRectFromProps()
1502 // get form position and size from properties
1503 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
1504 if ( xPSet.is() )
1506 sal_Int32 nXIn = 0, nYIn = 0, nWidthIn = 0, nHeightIn = 0;
1507 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nXIn;
1508 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nYIn;
1509 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidthIn;
1510 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeightIn;
1512 // transform coordinates
1513 sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
1514 if ( TransformFormToSdrCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
1516 // set rectangle position and size
1517 Point aPoint( nXOut, nYOut );
1518 Size aSize( nWidthOut, nHeightOut );
1519 SetSnapRect( Rectangle( aPoint, aSize ) );
1524 //----------------------------------------------------------------------------
1526 void DlgEdForm::SetPropsFromRect()
1528 // get form position and size from rectangle
1529 Rectangle aRect_ = GetSnapRect();
1530 sal_Int32 nXIn = aRect_.Left();
1531 sal_Int32 nYIn = aRect_.Top();
1532 sal_Int32 nWidthIn = aRect_.GetWidth();
1533 sal_Int32 nHeightIn = aRect_.GetHeight();
1535 // transform coordinates
1536 sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
1537 if ( TransformSdrToFormCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
1539 // set properties
1540 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
1541 if ( xPSet.is() )
1543 Any aValue;
1544 aValue <<= nXOut;
1545 xPSet->setPropertyValue( DLGED_PROP_POSITIONX, aValue );
1546 aValue <<= nYOut;
1547 xPSet->setPropertyValue( DLGED_PROP_POSITIONY, aValue );
1548 aValue <<= nWidthOut;
1549 xPSet->setPropertyValue( DLGED_PROP_WIDTH, aValue );
1550 aValue <<= nHeightOut;
1551 xPSet->setPropertyValue( DLGED_PROP_HEIGHT, aValue );
1556 //----------------------------------------------------------------------------
1558 void DlgEdForm::AddChild( DlgEdObj* pDlgEdObj )
1560 pChilds.push_back( pDlgEdObj );
1563 //----------------------------------------------------------------------------
1565 void DlgEdForm::RemoveChild( DlgEdObj* pDlgEdObj )
1567 pChilds.erase( ::std::find( pChilds.begin() , pChilds.end() , pDlgEdObj ) );
1570 //----------------------------------------------------------------------------
1572 void DlgEdForm::PositionAndSizeChange( const beans::PropertyChangeEvent& evt )
1574 DlgEditor* pEditor = GetDlgEditor();
1575 DBG_ASSERT( pEditor, "DlgEdForm::PositionAndSizeChange: no dialog editor!" );
1576 if ( pEditor )
1578 DlgEdPage* pPage_ = pEditor->GetPage();
1579 DBG_ASSERT( pPage_, "DlgEdForm::PositionAndSizeChange: no page!" );
1580 if ( pPage_ )
1582 sal_Int32 nPageXIn = 0;
1583 sal_Int32 nPageYIn = 0;
1584 Size aPageSize = pPage_->GetSize();
1585 sal_Int32 nPageWidthIn = aPageSize.Width();
1586 sal_Int32 nPageHeightIn = aPageSize.Height();
1587 sal_Int32 nPageX, nPageY, nPageWidth, nPageHeight;
1588 if ( TransformSdrToFormCoordinates( nPageXIn, nPageYIn, nPageWidthIn, nPageHeightIn, nPageX, nPageY, nPageWidth, nPageHeight ) )
1590 Reference< beans::XPropertySet > xPSetForm( GetUnoControlModel(), UNO_QUERY );
1591 if ( xPSetForm.is() )
1593 sal_Int32 nValue = 0;
1594 evt.NewValue >>= nValue;
1595 sal_Int32 nNewValue = nValue;
1597 if ( evt.PropertyName == DLGED_PROP_POSITIONX )
1599 if ( nNewValue < nPageX )
1600 nNewValue = nPageX;
1602 else if ( evt.PropertyName == DLGED_PROP_POSITIONY )
1604 if ( nNewValue < nPageY )
1605 nNewValue = nPageY;
1607 else if ( evt.PropertyName == DLGED_PROP_WIDTH )
1609 if ( nNewValue < 1 )
1610 nNewValue = 1;
1612 else if ( evt.PropertyName == DLGED_PROP_HEIGHT )
1614 if ( nNewValue < 1 )
1615 nNewValue = 1;
1618 if ( nNewValue != nValue )
1620 Any aNewValue;
1621 aNewValue <<= nNewValue;
1622 EndListening( sal_False );
1623 xPSetForm->setPropertyValue( evt.PropertyName, aNewValue );
1624 StartListening();
1629 bool bAdjustedPageSize = pEditor->AdjustPageSize();
1630 SetRectFromProps();
1631 ::std::vector< DlgEdObj* >::iterator aIter;
1632 ::std::vector< DlgEdObj* > aChildList = ((DlgEdForm*)this)->GetChilds();
1634 if ( bAdjustedPageSize )
1636 pEditor->InitScrollBars();
1637 aPageSize = pPage_->GetSize();
1638 nPageWidthIn = aPageSize.Width();
1639 nPageHeightIn = aPageSize.Height();
1640 if ( TransformSdrToControlCoordinates( nPageXIn, nPageYIn, nPageWidthIn, nPageHeightIn, nPageX, nPageY, nPageWidth, nPageHeight ) )
1642 for ( aIter = aChildList.begin(); aIter != aChildList.end(); aIter++ )
1644 Reference< beans::XPropertySet > xPSet( (*aIter)->GetUnoControlModel(), UNO_QUERY );
1645 if ( xPSet.is() )
1647 sal_Int32 nX = 0, nY = 0, nWidth = 0, nHeight = 0;
1648 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nX;
1649 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nY;
1650 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidth;
1651 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeight;
1653 sal_Int32 nNewX = nX;
1654 if ( nX + nWidth > nPageX + nPageWidth )
1656 nNewX = nPageX + nPageWidth - nWidth;
1657 if ( nNewX < nPageX )
1658 nNewX = nPageX;
1660 if ( nNewX != nX )
1662 Any aValue;
1663 aValue <<= nNewX;
1664 EndListening( sal_False );
1665 xPSet->setPropertyValue( DLGED_PROP_POSITIONX, aValue );
1666 StartListening();
1669 sal_Int32 nNewY = nY;
1670 if ( nY + nHeight > nPageY + nPageHeight )
1672 nNewY = nPageY + nPageHeight - nHeight;
1673 if ( nNewY < nPageY )
1674 nNewY = nPageY;
1676 if ( nNewY != nY )
1678 Any aValue;
1679 aValue <<= nNewY;
1680 EndListening( sal_False );
1681 xPSet->setPropertyValue( DLGED_PROP_POSITIONY, aValue );
1682 StartListening();
1689 for ( aIter = aChildList.begin(); aIter != aChildList.end(); aIter++ )
1691 (*aIter)->SetRectFromProps();
1697 //----------------------------------------------------------------------------
1699 void DlgEdForm::UpdateStep()
1701 ULONG nObjCount;
1702 SdrPage* pSdrPage = GetPage();
1704 if ( pSdrPage && ( ( nObjCount = pSdrPage->GetObjCount() ) > 0 ) )
1706 for ( ULONG i = 0 ; i < nObjCount ; i++ )
1708 SdrObject* pObj = pSdrPage->GetObj(i);
1709 DlgEdObj* pDlgEdObj = PTR_CAST(DlgEdObj, pObj);
1710 if ( pDlgEdObj && !pDlgEdObj->ISA(DlgEdForm) )
1711 pDlgEdObj->UpdateStep();
1716 //----------------------------------------------------------------------------
1718 void DlgEdForm::UpdateTabIndices()
1720 // stop listening with all children
1721 ::std::vector<DlgEdObj*>::iterator aIter;
1722 for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; ++aIter )
1724 (*aIter)->EndListening( sal_False );
1727 Reference< ::com::sun::star::container::XNameAccess > xNameAcc( GetUnoControlModel() , UNO_QUERY );
1728 if ( xNameAcc.is() )
1730 // get sequence of control names
1731 Sequence< ::rtl::OUString > aNames = xNameAcc->getElementNames();
1732 const ::rtl::OUString* pNames = aNames.getConstArray();
1733 sal_Int32 nCtrls = aNames.getLength();
1735 // create a map of tab indices and control names, sorted by tab index
1736 IndexToNameMap aIndexToNameMap;
1737 for ( sal_Int16 i = 0; i < nCtrls; ++i )
1739 // get name
1740 ::rtl::OUString aName( pNames[i] );
1742 // get tab index
1743 sal_Int16 nTabIndex = -1;
1744 Any aCtrl = xNameAcc->getByName( aName );
1745 Reference< ::com::sun::star::beans::XPropertySet > xPSet;
1746 aCtrl >>= xPSet;
1747 if ( xPSet.is() )
1748 xPSet->getPropertyValue( DLGED_PROP_TABINDEX ) >>= nTabIndex;
1750 // insert into map
1751 aIndexToNameMap.insert( IndexToNameMap::value_type( nTabIndex, aName ) );
1754 // set new tab indices
1755 sal_Int16 nNewTabIndex = 0;
1756 for ( IndexToNameMap::iterator aIt = aIndexToNameMap.begin(); aIt != aIndexToNameMap.end(); ++aIt )
1758 Any aCtrl = xNameAcc->getByName( aIt->second );
1759 Reference< beans::XPropertySet > xPSet;
1760 aCtrl >>= xPSet;
1761 if ( xPSet.is() )
1763 Any aTabIndex;
1764 aTabIndex <<= (sal_Int16) nNewTabIndex++;
1765 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
1769 // #110559#
1770 UpdateTabOrderAndGroups();
1773 // start listening with all children
1774 for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; ++aIter )
1776 (*aIter)->StartListening();
1780 //----------------------------------------------------------------------------
1782 void DlgEdForm::UpdateTabOrder()
1784 // #110559#
1785 // When the tabindex of a control model changes, the dialog control is
1786 // notified about those changes. Due to #109067# (bad performance of
1787 // dialog editor) the dialog control doesn't activate the tab order
1788 // in design mode. When the dialog editor has reordered all
1789 // tabindices, this method allows to activate the taborder afterwards.
1791 Reference< awt::XUnoControlContainer > xCont( GetControl(), UNO_QUERY );
1792 if ( xCont.is() )
1794 Sequence< Reference< awt::XTabController > > aSeqTabCtrls = xCont->getTabControllers();
1795 const Reference< awt::XTabController >* pTabCtrls = aSeqTabCtrls.getConstArray();
1796 sal_Int32 nCount = aSeqTabCtrls.getLength();
1797 for ( sal_Int32 i = 0; i < nCount; ++i )
1798 pTabCtrls[i]->activateTabOrder();
1802 //----------------------------------------------------------------------------
1804 void DlgEdForm::UpdateGroups()
1806 // #110559#
1807 // The grouping of radio buttons in a dialog is done by vcl.
1808 // In the dialog editor we have two views (=controls) for one
1809 // radio button model. One control is owned by the dialog control,
1810 // but not visible in design mode. The other control is owned by
1811 // the drawing layer object. Whereas the grouping of the first
1812 // control is done by vcl, the grouping of the control in the
1813 // drawing layer has to be done here.
1815 Reference< awt::XTabControllerModel > xTabModel( GetUnoControlModel() , UNO_QUERY );
1816 if ( xTabModel.is() )
1818 // create a global list of controls that belong to the dialog
1819 ::std::vector<DlgEdObj*> aChildList = GetChilds();
1820 sal_uInt32 nSize = aChildList.size();
1821 Sequence< Reference< awt::XControl > > aSeqControls( nSize );
1822 for ( sal_uInt32 i = 0; i < nSize; ++i )
1823 aSeqControls.getArray()[i] = Reference< awt::XControl >( aChildList[i]->GetControl(), UNO_QUERY );
1825 sal_Int32 nGroupCount = xTabModel->getGroupCount();
1826 for ( sal_Int32 nGroup = 0; nGroup < nGroupCount; ++nGroup )
1828 // get a list of control models that belong to this group
1829 ::rtl::OUString aName;
1830 Sequence< Reference< awt::XControlModel > > aSeqModels;
1831 xTabModel->getGroup( nGroup, aSeqModels, aName );
1832 const Reference< awt::XControlModel >* pModels = aSeqModels.getConstArray();
1833 sal_Int32 nModelCount = aSeqModels.getLength();
1835 // create a list of peers that belong to this group
1836 Sequence< Reference< awt::XWindow > > aSeqPeers( nModelCount );
1837 for ( sal_Int32 nModel = 0; nModel < nModelCount; ++nModel )
1839 // for each control model find the corresponding control in the global list
1840 const Reference< awt::XControl >* pControls = aSeqControls.getConstArray();
1841 sal_Int32 nControlCount = aSeqControls.getLength();
1842 for ( sal_Int32 nControl = 0; nControl < nControlCount; ++nControl )
1844 const Reference< awt::XControl > xCtrl( pControls[nControl] );
1845 if ( xCtrl.is() )
1847 Reference< awt::XControlModel > xCtrlModel( xCtrl->getModel() );
1848 if ( (awt::XControlModel*)xCtrlModel.get() == (awt::XControlModel*)pModels[nModel].get() )
1850 // get the control peer and insert into the list of peers
1851 aSeqPeers.getArray()[ nModel ] = Reference< awt::XWindow >( xCtrl->getPeer(), UNO_QUERY );
1852 break;
1858 // set the group at the dialog peer
1859 Reference< awt::XControl > xDlg( GetControl(), UNO_QUERY );
1860 if ( xDlg.is() )
1862 Reference< awt::XVclContainerPeer > xDlgPeer( xDlg->getPeer(), UNO_QUERY );
1863 if ( xDlgPeer.is() )
1864 xDlgPeer->setGroup( aSeqPeers );
1870 //----------------------------------------------------------------------------
1872 void DlgEdForm::UpdateTabOrderAndGroups()
1874 UpdateTabOrder();
1875 UpdateGroups();
1878 //----------------------------------------------------------------------------
1880 SdrObject* DlgEdForm::CheckHit( const Point& rPnt, USHORT nTol, const SetOfByte* ) const
1882 Rectangle aROuter = aOutRect;
1883 aROuter.Left() -= nTol;
1884 aROuter.Right() += nTol;
1885 aROuter.Top() -= nTol;
1886 aROuter.Bottom() += nTol;
1888 Rectangle aRInner = aOutRect;
1889 if( (aRInner.GetSize().Height() > (long)nTol*2) &&
1890 (aRInner.GetSize().Width() > (long)nTol*2) )
1892 aRInner.Left() += nTol;
1893 aRInner.Right() -= nTol;
1894 aRInner.Top() += nTol;
1895 aRInner.Bottom() -= nTol;
1898 if( aROuter.IsInside( rPnt ) && !aRInner.IsInside( rPnt ) )
1899 return (SdrObject*)this;
1900 else
1901 return 0;
1904 //----------------------------------------------------------------------------
1906 void DlgEdForm::NbcMove( const Size& rSize )
1908 SdrUnoObj::NbcMove( rSize );
1910 // set geometry properties of form
1911 EndListening(sal_False);
1912 SetPropsFromRect();
1913 StartListening();
1915 // set geometry properties of all childs
1916 ::std::vector<DlgEdObj*>::iterator aIter;
1917 for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; aIter++ )
1919 (*aIter)->EndListening(sal_False);
1920 (*aIter)->SetPropsFromRect();
1921 (*aIter)->StartListening();
1924 // dialog model changed
1925 GetDlgEditor()->SetDialogModelChanged(TRUE);
1928 //----------------------------------------------------------------------------
1930 void DlgEdForm::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1932 SdrUnoObj::NbcResize( rRef, xFract, yFract );
1934 // set geometry properties of form
1935 EndListening(sal_False);
1936 SetPropsFromRect();
1937 StartListening();
1939 // set geometry properties of all childs
1940 ::std::vector<DlgEdObj*>::iterator aIter;
1941 for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; aIter++ )
1943 (*aIter)->EndListening(sal_False);
1944 (*aIter)->SetPropsFromRect();
1945 (*aIter)->StartListening();
1948 // dialog model changed
1949 GetDlgEditor()->SetDialogModelChanged(TRUE);
1952 //----------------------------------------------------------------------------
1954 FASTBOOL DlgEdForm::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1956 FASTBOOL bResult = SdrUnoObj::EndCreate(rStat, eCmd);
1958 // stop listening
1959 EndListening(sal_False);
1961 // set geometry properties
1962 SetPropsFromRect();
1964 // dialog model changed
1965 GetDlgEditor()->SetDialogModelChanged(TRUE);
1967 // start listening
1968 StartListening();
1970 return bResult;
1973 //----------------------------------------------------------------------------
1975 awt::DeviceInfo DlgEdForm::getDeviceInfo() const
1977 awt::DeviceInfo aDeviceInfo;
1979 DlgEditor* pEditor = GetDlgEditor();
1980 DBG_ASSERT( pEditor, "DlgEdForm::getDeviceInfo: no editor associated with the form object!" );
1981 if ( !pEditor )
1982 return aDeviceInfo;
1984 Window* pWindow = pEditor->GetWindow();
1985 DBG_ASSERT( pWindow, "DlgEdForm::getDeviceInfo: no window associated with the editor!" );
1986 if ( !pWindow )
1987 return aDeviceInfo;
1989 // obtain an XControl
1990 ::utl::SharedUNOComponent< awt::XControl > xDialogControl; // ensures auto-disposal, if needed
1991 xDialogControl.reset( GetControl(), ::utl::SharedUNOComponent< awt::XControl >::NoTakeOwnership );
1992 if ( !xDialogControl.is() )
1994 // don't create a temporary control all the time, this method here is called
1995 // way too often. Instead, use a cached DeviceInfo.
1996 // 2007-02-05 / i74065 / frank.schoenheit@sun.com
1997 if ( !!mpDeviceInfo )
1998 return *mpDeviceInfo;
2000 Reference< awt::XControlContainer > xEditorControlContainer( pEditor->GetWindowControlContainer() );
2001 xDialogControl.reset(
2002 GetTemporaryControlForWindow( *pWindow, xEditorControlContainer ),
2003 ::utl::SharedUNOComponent< awt::XControl >::TakeOwnership );
2006 Reference< awt::XDevice > xDialogDevice;
2007 if ( xDialogControl.is() )
2008 xDialogDevice.set( xDialogControl->getPeer(), UNO_QUERY );
2009 DBG_ASSERT( xDialogDevice.is(), "DlgEdForm::getDeviceInfo: no device!" );
2010 if ( xDialogDevice.is() )
2011 aDeviceInfo = xDialogDevice->getInfo();
2013 mpDeviceInfo.reset( aDeviceInfo );
2015 return aDeviceInfo;
2018 //----------------------------------------------------------------------------