merge the formfield patch from ooo-build
[ooovba.git] / basctl / source / dlged / dlgedobj.cxx
blob96df71969538c03b6cb5a9b1aaa038d8ca51ae56
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 const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac)
109 :SdrUnoObj(rModelName, rxSFac, sal_False)
110 ,bIsListening(sal_False)
111 ,pDlgEdForm( NULL )
113 DBG_CTOR(DlgEdObj, NULL);
116 //----------------------------------------------------------------------------
118 DlgEdObj::~DlgEdObj()
120 DBG_DTOR(DlgEdObj, NULL);
122 if ( isListening() )
123 EndListening();
126 //----------------------------------------------------------------------------
128 void DlgEdObj::SetPage(SdrPage* _pNewPage)
130 // now set the page
131 SdrUnoObj::SetPage(_pNewPage);
134 //----------------------------------------------------------------------------
136 namespace
138 /** returns the DlgEdForm which the given DlgEdObj belongs to
139 (which might in fact be the object itself)
141 Failure to obtain the form will be reported with an assertion in the non-product
142 version.
144 bool lcl_getDlgEdForm( DlgEdObj* _pObject, DlgEdForm*& _out_pDlgEdForm )
146 _out_pDlgEdForm = dynamic_cast< DlgEdForm* >( _pObject );
147 if ( !_out_pDlgEdForm )
148 _out_pDlgEdForm = _pObject->GetDlgEdForm();
149 DBG_ASSERT( _out_pDlgEdForm, "lcl_getDlgEdForm: no form!" );
150 return ( _out_pDlgEdForm != NULL );
154 //----------------------------------------------------------------------------
156 uno::Reference< awt::XControl > DlgEdObj::GetControl() const
158 const DlgEdForm* pForm = GetDlgEdForm();
159 const DlgEditor* pEditor = pForm ? pForm->GetDlgEditor() : NULL;
160 SdrView* pView = pEditor ? pEditor->GetView() : NULL;
161 Window* pWindow = pEditor ? pEditor->GetWindow() : NULL;
162 OSL_ENSURE( ( pView && pWindow ) || !pForm, "DlgEdObj::GetControl: no view or no window!" );
164 uno::Reference< awt::XControl > xControl;
165 if ( pView && pWindow )
166 xControl = GetUnoControl( *pView, *pWindow );
168 return xControl;
171 //----------------------------------------------------------------------------
173 bool DlgEdObj::TransformSdrToControlCoordinates(
174 sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
175 sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
177 // input position and size
178 Size aPos( nXIn, nYIn );
179 Size aSize( nWidthIn, nHeightIn );
181 // form position
182 DlgEdForm* pForm = NULL;
183 if ( !lcl_getDlgEdForm( this, pForm ) )
184 return false;
185 Rectangle aFormRect = pForm->GetSnapRect();
186 Size aFormPos( aFormRect.Left(), aFormRect.Top() );
188 // convert 100th_mm to pixel
189 OutputDevice* pDevice = Application::GetDefaultDevice();
190 DBG_ASSERT( pDevice, "DlgEdObj::TransformSdrToControlCoordinates: missing default device!" );
191 if ( !pDevice )
192 return false;
193 aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_100TH_MM ) );
194 aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_100TH_MM ) );
195 aFormPos = pDevice->LogicToPixel( aFormPos, MapMode( MAP_100TH_MM ) );
197 // subtract form position
198 aPos.Width() -= aFormPos.Width();
199 aPos.Height() -= aFormPos.Height();
201 // take window borders into account
202 Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
203 DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
204 if ( !xPSetForm.is() )
205 return false;
206 bool bDecoration = true;
207 xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
208 if( bDecoration )
210 awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
211 aPos.Width() -= aDeviceInfo.LeftInset;
212 aPos.Height() -= aDeviceInfo.TopInset;
215 // convert pixel to logic units
216 MapMode aConvMode = lcl_getMapModeForForm( pForm );
217 aPos = pDevice->PixelToLogic( aPos, aConvMode );
218 aSize = pDevice->PixelToLogic( aSize, aConvMode );
220 // set out parameters
221 nXOut = aPos.Width();
222 nYOut = aPos.Height();
223 nWidthOut = aSize.Width();
224 nHeightOut = aSize.Height();
226 return true;
229 //----------------------------------------------------------------------------
231 bool DlgEdObj::TransformSdrToFormCoordinates(
232 sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
233 sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
235 // input position and size
236 Size aPos( nXIn, nYIn );
237 Size aSize( nWidthIn, nHeightIn );
239 // convert 100th_mm to pixel
240 OutputDevice* pDevice = Application::GetDefaultDevice();
241 DBG_ASSERT( pDevice, "DlgEdObj::TransformSdrToFormCoordinates: missing default device!" );
242 if ( !pDevice )
243 return false;
244 aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_100TH_MM ) );
245 aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_100TH_MM ) );
247 // take window borders into account
248 DlgEdForm* pForm = NULL;
249 if ( !lcl_getDlgEdForm( this, pForm ) )
250 return false;
252 // take window borders into account
253 Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
254 DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
255 if ( !xPSetForm.is() )
256 return false;
257 bool bDecoration = true;
258 xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
259 if( bDecoration )
261 awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
262 aSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
263 aSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
265 MapMode aConvMode = lcl_getMapModeForForm( pForm );
266 // convert pixel to logic units
267 aPos = pDevice->PixelToLogic( aPos, aConvMode );
268 aSize = pDevice->PixelToLogic( aSize, aConvMode );
270 // set out parameters
271 nXOut = aPos.Width();
272 nYOut = aPos.Height();
273 nWidthOut = aSize.Width();
274 nHeightOut = aSize.Height();
276 return true;
279 //----------------------------------------------------------------------------
281 bool DlgEdObj::TransformControlToSdrCoordinates(
282 sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
283 sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
285 // input position and size
286 Size aPos( nXIn, nYIn );
287 Size aSize( nWidthIn, nHeightIn );
289 // form position
290 DlgEdForm* pForm = NULL;
291 if ( !lcl_getDlgEdForm( this, pForm ) )
292 return false;
294 Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
295 DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformControlToSdrCoordinates: no form property set!" );
296 if ( !xPSetForm.is() )
297 return false;
298 sal_Int32 nFormX = 0, nFormY = 0, nFormWidth, nFormHeight;
299 xPSetForm->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nFormX;
300 xPSetForm->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nFormY;
301 xPSetForm->getPropertyValue( DLGED_PROP_WIDTH ) >>= nFormWidth;
302 xPSetForm->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nFormHeight;
303 Size aFormPos( nFormX, nFormY );
305 // convert logic units to pixel
306 OutputDevice* pDevice = Application::GetDefaultDevice();
307 DBG_ASSERT( pDevice, "DlgEdObj::TransformControlToSdrCoordinates: missing default device!" );
308 if ( !pDevice )
309 return false;
310 MapMode aConvMode = lcl_getMapModeForForm( pForm );
311 aPos = pDevice->LogicToPixel( aPos, aConvMode );
312 aSize = pDevice->LogicToPixel( aSize, aConvMode );
313 aFormPos = pDevice->LogicToPixel( aFormPos, aConvMode );
315 // add form position
316 aPos.Width() += aFormPos.Width();
317 aPos.Height() += aFormPos.Height();
319 // take window borders into account
320 bool bDecoration = true;
321 xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
322 if( bDecoration )
324 awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
325 aPos.Width() += aDeviceInfo.LeftInset;
326 aPos.Height() += aDeviceInfo.TopInset;
329 // convert pixel to 100th_mm
330 aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_100TH_MM ) );
331 aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_100TH_MM ) );
333 // set out parameters
334 nXOut = aPos.Width();
335 nYOut = aPos.Height();
336 nWidthOut = aSize.Width();
337 nHeightOut = aSize.Height();
339 return true;
342 //----------------------------------------------------------------------------
344 bool DlgEdObj::TransformFormToSdrCoordinates(
345 sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
346 sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
348 // input position and size
349 Size aPos( nXIn, nYIn );
350 Size aSize( nWidthIn, nHeightIn );
352 // convert logic units to pixel
353 OutputDevice* pDevice = Application::GetDefaultDevice();
354 DBG_ASSERT( pDevice, "DlgEdObj::TransformFormToSdrCoordinates: missing default device!" );
355 if ( !pDevice )
356 return false;
358 // take window borders into account
359 DlgEdForm* pForm = NULL;
360 if ( !lcl_getDlgEdForm( this, pForm ) )
361 return false;
363 MapMode aConvMode = lcl_getMapModeForForm( pForm );
364 aPos = pDevice->LogicToPixel( aPos, aConvMode );
365 aSize = pDevice->LogicToPixel( aSize, aConvMode );
367 // take window borders into account
368 Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
369 DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
370 if ( !xPSetForm.is() )
371 return false;
372 bool bDecoration = true;
373 xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
374 if( bDecoration )
376 awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
377 aSize.Width() += aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
378 aSize.Height() += aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
381 // convert pixel to 100th_mm
382 aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_100TH_MM ) );
383 aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_100TH_MM ) );
385 // set out parameters
386 nXOut = aPos.Width();
387 nYOut = aPos.Height();
388 nWidthOut = aSize.Width();
389 nHeightOut = aSize.Height();
391 return true;
394 //----------------------------------------------------------------------------
396 void DlgEdObj::SetRectFromProps()
398 // get control position and size from properties
399 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
400 if ( xPSet.is() )
402 sal_Int32 nXIn = 0, nYIn = 0, nWidthIn = 0, nHeightIn = 0;
403 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nXIn;
404 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nYIn;
405 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidthIn;
406 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeightIn;
408 // transform coordinates
409 sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
410 if ( TransformControlToSdrCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
412 // set rectangle position and size
413 Point aPoint( nXOut, nYOut );
414 Size aSize( nWidthOut, nHeightOut );
415 SetSnapRect( Rectangle( aPoint, aSize ) );
420 //----------------------------------------------------------------------------
422 void DlgEdObj::SetPropsFromRect()
424 // get control position and size from rectangle
425 Rectangle aRect_ = GetSnapRect();
426 sal_Int32 nXIn = aRect_.Left();
427 sal_Int32 nYIn = aRect_.Top();
428 sal_Int32 nWidthIn = aRect_.GetWidth();
429 sal_Int32 nHeightIn = aRect_.GetHeight();
431 // transform coordinates
432 sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
433 if ( TransformSdrToControlCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
435 // set properties
436 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
437 if ( xPSet.is() )
439 Any aValue;
440 aValue <<= nXOut;
441 xPSet->setPropertyValue( DLGED_PROP_POSITIONX, aValue );
442 aValue <<= nYOut;
443 xPSet->setPropertyValue( DLGED_PROP_POSITIONY, aValue );
444 aValue <<= nWidthOut;
445 xPSet->setPropertyValue( DLGED_PROP_WIDTH, aValue );
446 aValue <<= nHeightOut;
447 xPSet->setPropertyValue( DLGED_PROP_HEIGHT, aValue );
452 //----------------------------------------------------------------------------
454 void DlgEdObj::PositionAndSizeChange( const beans::PropertyChangeEvent& evt )
456 DlgEdPage* pPage_ = 0;
457 if ( pDlgEdForm )
459 DlgEditor* pEditor = pDlgEdForm->GetDlgEditor();
460 if ( pEditor )
461 pPage_ = pEditor->GetPage();
463 DBG_ASSERT( pPage_, "DlgEdObj::PositionAndSizeChange: no page!" );
464 if ( pPage_ )
466 sal_Int32 nPageXIn = 0;
467 sal_Int32 nPageYIn = 0;
468 Size aPageSize = pPage_->GetSize();
469 sal_Int32 nPageWidthIn = aPageSize.Width();
470 sal_Int32 nPageHeightIn = aPageSize.Height();
471 sal_Int32 nPageX, nPageY, nPageWidth, nPageHeight;
472 if ( TransformSdrToControlCoordinates( nPageXIn, nPageYIn, nPageWidthIn, nPageHeightIn, nPageX, nPageY, nPageWidth, nPageHeight ) )
474 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
475 if ( xPSet.is() )
477 sal_Int32 nX = 0, nY = 0, nWidth = 0, nHeight = 0;
478 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nX;
479 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nY;
480 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidth;
481 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeight;
483 sal_Int32 nValue = 0;
484 evt.NewValue >>= nValue;
485 sal_Int32 nNewValue = nValue;
487 if ( evt.PropertyName == DLGED_PROP_POSITIONX )
489 if ( nNewValue + nWidth > nPageX + nPageWidth )
490 nNewValue = nPageX + nPageWidth - nWidth;
491 if ( nNewValue < nPageX )
492 nNewValue = nPageX;
494 else if ( evt.PropertyName == DLGED_PROP_POSITIONY )
496 if ( nNewValue + nHeight > nPageY + nPageHeight )
497 nNewValue = nPageY + nPageHeight - nHeight;
498 if ( nNewValue < nPageY )
499 nNewValue = nPageY;
501 else if ( evt.PropertyName == DLGED_PROP_WIDTH )
503 if ( nX + nNewValue > nPageX + nPageWidth )
504 nNewValue = nPageX + nPageWidth - nX;
505 if ( nNewValue < 1 )
506 nNewValue = 1;
508 else if ( evt.PropertyName == DLGED_PROP_HEIGHT )
510 if ( nY + nNewValue > nPageY + nPageHeight )
511 nNewValue = nPageY + nPageHeight - nY;
512 if ( nNewValue < 1 )
513 nNewValue = 1;
516 if ( nNewValue != nValue )
518 Any aNewValue;
519 aNewValue <<= nNewValue;
520 EndListening( sal_False );
521 xPSet->setPropertyValue( evt.PropertyName, aNewValue );
522 StartListening();
528 SetRectFromProps();
531 //----------------------------------------------------------------------------
533 void SAL_CALL DlgEdObj::NameChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException)
535 // get old name
536 ::rtl::OUString aOldName;
537 evt.OldValue >>= aOldName;
539 // get new name
540 ::rtl::OUString aNewName;
541 evt.NewValue >>= aNewName;
543 if ( !aNewName.equals(aOldName) )
545 Reference< container::XNameAccess > xNameAcc((GetDlgEdForm()->GetUnoControlModel()), UNO_QUERY);
546 if ( xNameAcc.is() && xNameAcc->hasByName(aOldName) )
548 if ( !xNameAcc->hasByName(aNewName) && aNewName.getLength() != 0 )
550 // remove the control by the old name and insert the control by the new name in the container
551 Reference< container::XNameContainer > xCont(xNameAcc, UNO_QUERY );
552 if ( xCont.is() )
554 Reference< awt::XControlModel > xCtrl(GetUnoControlModel(), UNO_QUERY);
555 Any aAny;
556 aAny <<= xCtrl;
557 xCont->removeByName( aOldName );
558 xCont->insertByName( aNewName , aAny );
560 DlgEditor* pEditor;
561 if ( ISA(DlgEdForm) )
562 pEditor = ((DlgEdForm*)this)->GetDlgEditor();
563 else
564 pEditor = GetDlgEdForm()->GetDlgEditor();
565 LocalizationMgr::renameControlResourceIDsForEditorObject( pEditor, aAny, aNewName );
568 else
570 // set old name property
571 EndListening(sal_False);
572 Reference< beans::XPropertySet > xPSet(GetUnoControlModel(), UNO_QUERY);
573 Any aName;
574 aName <<= aOldName;
575 xPSet->setPropertyValue( DLGED_PROP_NAME, aName );
576 StartListening();
582 //----------------------------------------------------------------------------
584 sal_Int32 DlgEdObj::GetStep() const
586 // get step property
587 sal_Int32 nStep = 0;
588 uno::Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), uno::UNO_QUERY );
589 if (xPSet.is())
591 xPSet->getPropertyValue( DLGED_PROP_STEP ) >>= nStep;
593 return nStep;
596 //----------------------------------------------------------------------------
598 void DlgEdObj::UpdateStep()
600 sal_Int32 nCurStep = GetDlgEdForm()->GetStep();
601 sal_Int32 nStep = GetStep();
603 SdrLayerAdmin& rLayerAdmin = GetModel()->GetLayerAdmin();
604 SdrLayerID nHiddenLayerId = rLayerAdmin.GetLayerID( String( RTL_CONSTASCII_USTRINGPARAM( "HiddenLayer" ) ), FALSE );
605 SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), sal_False );
607 if( nCurStep )
609 if ( nStep && (nStep != nCurStep) )
611 SetLayer( nHiddenLayerId );
613 else
615 SetLayer( nControlLayerId );
618 else
620 SetLayer( nControlLayerId );
624 //----------------------------------------------------------------------------
626 void DlgEdObj::TabIndexChange( const beans::PropertyChangeEvent& evt ) throw (RuntimeException)
628 DlgEdForm* pForm = GetDlgEdForm();
629 if ( pForm )
631 // stop listening with all children
632 ::std::vector<DlgEdObj*> aChildList = pForm->GetChilds();
633 ::std::vector<DlgEdObj*>::iterator aIter;
634 for ( aIter = aChildList.begin() ; aIter != aChildList.end() ; ++aIter )
636 (*aIter)->EndListening( sal_False );
639 Reference< container::XNameAccess > xNameAcc( pForm->GetUnoControlModel() , UNO_QUERY );
640 if ( xNameAcc.is() )
642 // get sequence of control names
643 Sequence< ::rtl::OUString > aNames = xNameAcc->getElementNames();
644 const ::rtl::OUString* pNames = aNames.getConstArray();
645 sal_Int32 nCtrls = aNames.getLength();
646 sal_Int16 i;
648 // create a map of tab indices and control names, sorted by tab index
649 IndexToNameMap aIndexToNameMap;
650 for ( i = 0; i < nCtrls; ++i )
652 // get control name
653 ::rtl::OUString aName( pNames[i] );
655 // get tab index
656 sal_Int16 nTabIndex = -1;
657 Any aCtrl = xNameAcc->getByName( aName );
658 Reference< beans::XPropertySet > xPSet;
659 aCtrl >>= xPSet;
660 if ( xPSet.is() && xPSet == Reference< beans::XPropertySet >( evt.Source, UNO_QUERY ) )
661 evt.OldValue >>= nTabIndex;
662 else if ( xPSet.is() )
663 xPSet->getPropertyValue( DLGED_PROP_TABINDEX ) >>= nTabIndex;
665 // insert into map
666 aIndexToNameMap.insert( IndexToNameMap::value_type( nTabIndex, aName ) );
669 // create a helper list of control names, sorted by tab index
670 ::std::vector< ::rtl::OUString > aNameList( aIndexToNameMap.size() );
671 ::std::transform(
672 aIndexToNameMap.begin(), aIndexToNameMap.end(),
673 aNameList.begin(),
674 ::std::select2nd< IndexToNameMap::value_type >( )
677 // check tab index
678 sal_Int16 nOldTabIndex = 0;
679 evt.OldValue >>= nOldTabIndex;
680 sal_Int16 nNewTabIndex = 0;
681 evt.NewValue >>= nNewTabIndex;
682 if ( nNewTabIndex < 0 )
683 nNewTabIndex = 0;
684 else if ( nNewTabIndex > nCtrls - 1 )
685 nNewTabIndex = sal::static_int_cast<sal_Int16>( nCtrls - 1 );
687 // reorder helper list
688 ::rtl::OUString aCtrlName = aNameList[nOldTabIndex];
689 aNameList.erase( aNameList.begin() + nOldTabIndex );
690 aNameList.insert( aNameList.begin() + nNewTabIndex , aCtrlName );
692 // set new tab indices
693 for ( i = 0; i < nCtrls; ++i )
695 Any aCtrl = xNameAcc->getByName( aNameList[i] );
696 Reference< beans::XPropertySet > xPSet;
697 aCtrl >>= xPSet;
698 if ( xPSet.is() )
700 Any aTabIndex;
701 aTabIndex <<= (sal_Int16) i;
702 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
706 // reorder objects in drawing page
707 GetModel()->GetPage(0)->SetObjectOrdNum( nOldTabIndex + 1, nNewTabIndex + 1 );
709 // #110559#
710 pForm->UpdateTabOrderAndGroups();
713 // start listening with all children
714 for ( aIter = aChildList.begin() ; aIter != aChildList.end() ; ++aIter )
716 (*aIter)->StartListening();
721 //----------------------------------------------------------------------------
723 sal_Bool DlgEdObj::supportsService( const sal_Char* _pServiceName ) const
725 sal_Bool bSupports = sal_False;
727 Reference< lang::XServiceInfo > xServiceInfo( GetUnoControlModel() , UNO_QUERY );
728 // TODO: cache xServiceInfo as member?
729 if ( xServiceInfo.is() )
730 bSupports = xServiceInfo->supportsService( ::rtl::OUString::createFromAscii( _pServiceName ) );
732 return bSupports;
735 //----------------------------------------------------------------------------
737 ::rtl::OUString DlgEdObj::GetDefaultName() const
739 sal_uInt16 nResId = 0;
740 ::rtl::OUString aDefaultName;
741 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
743 nResId = RID_STR_CLASS_DIALOG;
745 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
747 nResId = RID_STR_CLASS_BUTTON;
749 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
751 nResId = RID_STR_CLASS_RADIOBUTTON;
753 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
755 nResId = RID_STR_CLASS_CHECKBOX;
757 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
759 nResId = RID_STR_CLASS_LISTBOX;
761 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
763 nResId = RID_STR_CLASS_COMBOBOX;
765 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
767 nResId = RID_STR_CLASS_GROUPBOX;
769 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
771 nResId = RID_STR_CLASS_EDIT;
773 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
775 nResId = RID_STR_CLASS_FIXEDTEXT;
777 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
779 nResId = RID_STR_CLASS_IMAGECONTROL;
781 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
783 nResId = RID_STR_CLASS_PROGRESSBAR;
785 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
787 nResId = RID_STR_CLASS_SCROLLBAR;
789 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
791 nResId = RID_STR_CLASS_FIXEDLINE;
793 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
795 nResId = RID_STR_CLASS_DATEFIELD;
797 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
799 nResId = RID_STR_CLASS_TIMEFIELD;
801 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
803 nResId = RID_STR_CLASS_NUMERICFIELD;
805 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
807 nResId = RID_STR_CLASS_CURRENCYFIELD;
809 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
811 nResId = RID_STR_CLASS_FORMATTEDFIELD;
813 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
815 nResId = RID_STR_CLASS_PATTERNFIELD;
817 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
819 nResId = RID_STR_CLASS_FILECONTROL;
821 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
823 nResId = RID_STR_CLASS_TREECONTROL;
826 else
828 nResId = RID_STR_CLASS_CONTROL;
831 if (nResId)
833 aDefaultName = ::rtl::OUString( String(IDEResId(nResId)) );
836 return aDefaultName;
839 //----------------------------------------------------------------------------
841 ::rtl::OUString DlgEdObj::GetUniqueName() const
843 ::rtl::OUString aUniqueName;
844 uno::Reference< container::XNameAccess > xNameAcc((GetDlgEdForm()->GetUnoControlModel()), uno::UNO_QUERY);
846 if ( xNameAcc.is() )
848 sal_Int32 n = 0;
849 ::rtl::OUString aDefaultName = GetDefaultName();
853 aUniqueName = aDefaultName + ::rtl::OUString::valueOf(++n);
854 } while (xNameAcc->hasByName(aUniqueName));
857 return aUniqueName;
860 //----------------------------------------------------------------------------
862 sal_uInt32 DlgEdObj::GetObjInventor() const
864 return DlgInventor;
867 //----------------------------------------------------------------------------
869 sal_uInt16 DlgEdObj::GetObjIdentifier() const
871 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ))
873 return OBJ_DLG_DIALOG;
875 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ))
877 return OBJ_DLG_PUSHBUTTON;
879 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ))
881 return OBJ_DLG_RADIOBUTTON;
883 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ))
885 return OBJ_DLG_CHECKBOX;
887 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ))
889 return OBJ_DLG_LISTBOX;
891 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ))
893 return OBJ_DLG_COMBOBOX;
895 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ))
897 return OBJ_DLG_GROUPBOX;
899 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ))
901 return OBJ_DLG_EDIT;
903 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ))
905 return OBJ_DLG_FIXEDTEXT;
907 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ))
909 return OBJ_DLG_IMAGECONTROL;
911 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ))
913 return OBJ_DLG_PROGRESSBAR;
915 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ))
917 return OBJ_DLG_HSCROLLBAR;
919 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ))
921 return OBJ_DLG_HFIXEDLINE;
923 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ))
925 return OBJ_DLG_DATEFIELD;
927 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ))
929 return OBJ_DLG_TIMEFIELD;
931 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ))
933 return OBJ_DLG_NUMERICFIELD;
935 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ))
937 return OBJ_DLG_CURRENCYFIELD;
939 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ))
941 return OBJ_DLG_FORMATTEDFIELD;
943 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ))
945 return OBJ_DLG_PATTERNFIELD;
947 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ))
949 return OBJ_DLG_FILECONTROL;
951 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ))
953 return OBJ_DLG_TREECONTROL;
955 else
957 return OBJ_DLG_CONTROL;
961 //----------------------------------------------------------------------------
963 void DlgEdObj::clonedFrom(const DlgEdObj* _pSource)
965 // set parent form
966 pDlgEdForm = _pSource->pDlgEdForm;
968 // add child to parent form
969 pDlgEdForm->AddChild( this );
971 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
972 if ( xPSet.is() )
974 // set new name
975 ::rtl::OUString aOUniqueName( GetUniqueName() );
976 Any aUniqueName;
977 aUniqueName <<= aOUniqueName;
978 xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName );
980 Reference< container::XNameContainer > xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY );
981 if ( xCont.is() )
983 // set tabindex
984 Sequence< OUString > aNames = xCont->getElementNames();
985 Any aTabIndex;
986 aTabIndex <<= (sal_Int16) aNames.getLength();
987 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
989 // insert control model in dialog model
990 Reference< awt::XControlModel > xCtrl( xPSet , UNO_QUERY );
991 Any aCtrl;
992 aCtrl <<= xCtrl;
993 xCont->insertByName( aOUniqueName , aCtrl );
995 // #110559#
996 pDlgEdForm->UpdateTabOrderAndGroups();
1000 // start listening
1001 StartListening();
1004 //----------------------------------------------------------------------------
1006 SdrObject* DlgEdObj::Clone() const
1008 SdrObject* pReturn = SdrUnoObj::Clone();
1010 DlgEdObj* pDlgEdObj = PTR_CAST(DlgEdObj, pReturn);
1011 DBG_ASSERT( pDlgEdObj != NULL, "DlgEdObj::Clone: invalid clone!" );
1012 if ( pDlgEdObj )
1013 pDlgEdObj->clonedFrom( this );
1015 return pReturn;
1018 //----------------------------------------------------------------------------
1020 SdrObject* DlgEdObj::getFullDragClone() const
1022 // no need to really add the clone for dragging, it's a temporary
1023 // object
1024 SdrObject* pObj = new SdrUnoObj(String());
1025 *pObj = *((const SdrUnoObj*)this);
1027 return pObj;
1030 //----------------------------------------------------------------------------
1032 void DlgEdObj::operator= (const SdrObject& rObj)
1034 SdrUnoObj::operator= (rObj);
1037 //----------------------------------------------------------------------------
1039 void DlgEdObj::NbcMove( const Size& rSize )
1041 SdrUnoObj::NbcMove( rSize );
1043 // stop listening
1044 EndListening(sal_False);
1046 // set geometry properties
1047 SetPropsFromRect();
1049 // start listening
1050 StartListening();
1052 // dialog model changed
1053 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1056 //----------------------------------------------------------------------------
1058 void DlgEdObj::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1060 SdrUnoObj::NbcResize( rRef, xFract, yFract );
1062 // stop listening
1063 EndListening(sal_False);
1065 // set geometry properties
1066 SetPropsFromRect();
1068 // start listening
1069 StartListening();
1071 // dialog model changed
1072 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1075 //----------------------------------------------------------------------------
1077 FASTBOOL DlgEdObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1079 FASTBOOL bResult = SdrUnoObj::EndCreate(rStat, eCmd);
1081 SetDefaults();
1082 StartListening();
1084 return bResult;
1087 //----------------------------------------------------------------------------
1089 void DlgEdObj::SetDefaults()
1091 // set parent form
1092 pDlgEdForm = ((DlgEdPage*)GetPage())->GetDlgEdForm();
1094 if ( pDlgEdForm )
1096 // add child to parent form
1097 pDlgEdForm->AddChild( this );
1099 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
1100 if ( xPSet.is() )
1102 // get unique name
1103 ::rtl::OUString aOUniqueName( GetUniqueName() );
1105 // set name property
1106 Any aUniqueName;
1107 aUniqueName <<= aOUniqueName;
1108 xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName );
1110 // set labels
1111 if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) ||
1112 supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) ||
1113 supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) ||
1114 supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) ||
1115 supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
1117 xPSet->setPropertyValue( DLGED_PROP_LABEL, aUniqueName );
1120 // set number formats supplier for formatted field
1121 if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
1123 Reference< util::XNumberFormatsSupplier > xSupplier = GetDlgEdForm()->GetDlgEditor()->GetNumberFormatsSupplier();
1124 if ( xSupplier.is() )
1126 Any aSupplier;
1127 aSupplier <<= xSupplier;
1128 xPSet->setPropertyValue( DLGED_PROP_FORMATSSUPPLIER, aSupplier );
1132 // set geometry properties
1133 SetPropsFromRect();
1135 Reference< container::XNameContainer > xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY );
1136 if ( xCont.is() )
1138 // set tabindex
1139 Sequence< OUString > aNames = xCont->getElementNames();
1140 uno::Any aTabIndex;
1141 aTabIndex <<= (sal_Int16) aNames.getLength();
1142 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
1144 // set step
1145 Reference< beans::XPropertySet > xPSetForm( xCont, UNO_QUERY );
1146 if ( xPSetForm.is() )
1148 Any aStep = xPSetForm->getPropertyValue( DLGED_PROP_STEP );
1149 xPSet->setPropertyValue( DLGED_PROP_STEP, aStep );
1152 // insert control model in dialog model
1153 Reference< awt::XControlModel > xCtrl( xPSet , UNO_QUERY );
1154 Any aAny;
1155 aAny <<= xCtrl;
1156 xCont->insertByName( aOUniqueName , aAny );
1158 DlgEditor* pEditor;
1159 if ( ISA(DlgEdForm) )
1160 pEditor = ((DlgEdForm*)this)->GetDlgEditor();
1161 else
1162 pEditor = GetDlgEdForm()->GetDlgEditor();
1163 LocalizationMgr::setControlResourceIDsForNewEditorObject( pEditor, aAny, aOUniqueName );
1165 // #110559#
1166 pDlgEdForm->UpdateTabOrderAndGroups();
1170 // dialog model changed
1171 pDlgEdForm->GetDlgEditor()->SetDialogModelChanged( TRUE );
1175 //----------------------------------------------------------------------------
1177 IMPL_LINK(DlgEdObj, OnCreate, void*, EMPTYTAG)
1179 (void)EMPTYTAG;
1181 if (pTempView)
1182 pTempView->ObjectCreated(this);
1184 return 0;
1187 //----------------------------------------------------------------------------
1189 void DlgEdObj::StartListening()
1191 DBG_ASSERT(!isListening(), "DlgEdObj::StartListening: already listening!");
1193 if (!isListening())
1195 bIsListening = sal_True;
1197 // XPropertyChangeListener
1198 Reference< XPropertySet > xControlModel( GetUnoControlModel() , UNO_QUERY );
1199 if (!m_xPropertyChangeListener.is() && xControlModel.is())
1201 // create listener
1202 m_xPropertyChangeListener = static_cast< ::com::sun::star::beans::XPropertyChangeListener*>( new DlgEdPropListenerImpl( (DlgEdObj*)this ) );
1204 // register listener to properties
1205 xControlModel->addPropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener );
1208 // XContainerListener
1209 Reference< XScriptEventsSupplier > xEventsSupplier( GetUnoControlModel() , UNO_QUERY );
1210 if( !m_xContainerListener.is() && xEventsSupplier.is() )
1212 // create listener
1213 m_xContainerListener = static_cast< ::com::sun::star::container::XContainerListener*>( new DlgEdEvtContListenerImpl( (DlgEdObj*)this ) );
1215 // register listener to script event container
1216 Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents();
1217 DBG_ASSERT(xEventCont.is(), "DlgEdObj::StartListening: control model has no script event container!");
1218 Reference< XContainer > xCont( xEventCont , UNO_QUERY );
1219 if (xCont.is())
1220 xCont->addContainerListener( m_xContainerListener );
1225 //----------------------------------------------------------------------------
1227 void DlgEdObj::EndListening(sal_Bool bRemoveListener)
1229 DBG_ASSERT(isListening(), "DlgEdObj::EndListening: not listening currently!");
1231 if (isListening())
1233 bIsListening = sal_False;
1235 if (bRemoveListener)
1237 // XPropertyChangeListener
1238 Reference< XPropertySet > xControlModel(GetUnoControlModel(), UNO_QUERY);
1239 if ( m_xPropertyChangeListener.is() && xControlModel.is() )
1241 // remove listener
1242 xControlModel->removePropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener );
1244 m_xPropertyChangeListener.clear();
1246 // XContainerListener
1247 Reference< XScriptEventsSupplier > xEventsSupplier( GetUnoControlModel() , UNO_QUERY );
1248 if( m_xContainerListener.is() && xEventsSupplier.is() )
1250 // remove listener
1251 Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents();
1252 DBG_ASSERT(xEventCont.is(), "DlgEdObj::EndListening: control model has no script event container!");
1253 Reference< XContainer > xCont( xEventCont , UNO_QUERY );
1254 if (xCont.is())
1255 xCont->removeContainerListener( m_xContainerListener );
1257 m_xContainerListener.clear();
1262 //----------------------------------------------------------------------------
1264 void SAL_CALL DlgEdObj::_propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException)
1266 if (isListening())
1268 DlgEdForm* pRealDlgEdForm = dynamic_cast< DlgEdForm* >(this);
1269 if( pRealDlgEdForm == 0 )
1270 pRealDlgEdForm = GetDlgEdForm();
1272 DlgEditor* pDlgEditor = pRealDlgEdForm ? pRealDlgEdForm->GetDlgEditor() : 0;
1274 if( !pDlgEditor || pDlgEditor->isInPaint() )
1275 return;
1277 // dialog model changed
1278 pDlgEditor->SetDialogModelChanged(TRUE);
1280 // update position and size
1281 if ( evt.PropertyName == DLGED_PROP_POSITIONX || evt.PropertyName == DLGED_PROP_POSITIONY ||
1282 evt.PropertyName == DLGED_PROP_WIDTH || evt.PropertyName == DLGED_PROP_HEIGHT ||
1283 evt.PropertyName == DLGED_PROP_DECORATION )
1285 PositionAndSizeChange( evt );
1287 if ( evt.PropertyName == DLGED_PROP_DECORATION )
1289 if ( ISA(DlgEdForm) )
1290 ((DlgEdForm*)this)->GetDlgEditor()->ResetDialog();
1291 else
1292 GetDlgEdForm()->GetDlgEditor()->ResetDialog();
1295 // change name of control in dialog model
1296 else if ( evt.PropertyName == DLGED_PROP_NAME )
1298 if ( !ISA(DlgEdForm) )
1300 NameChange(evt);
1303 // update step
1304 else if ( evt.PropertyName == DLGED_PROP_STEP )
1306 UpdateStep();
1308 // change tabindex
1309 else if ( evt.PropertyName == DLGED_PROP_TABINDEX )
1311 if ( !ISA(DlgEdForm) )
1313 TabIndexChange(evt);
1319 //----------------------------------------------------------------------------
1321 void SAL_CALL DlgEdObj::_elementInserted(const ::com::sun::star::container::ContainerEvent& ) throw(::com::sun::star::uno::RuntimeException)
1323 if (isListening())
1325 // dialog model changed
1326 if ( ISA(DlgEdForm) )
1328 ((DlgEdForm*)this)->GetDlgEditor()->SetDialogModelChanged(TRUE);
1330 else
1332 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1337 //----------------------------------------------------------------------------
1339 void SAL_CALL DlgEdObj::_elementReplaced(const ::com::sun::star::container::ContainerEvent& ) throw(::com::sun::star::uno::RuntimeException)
1341 if (isListening())
1343 // dialog model changed
1344 if ( ISA(DlgEdForm) )
1346 ((DlgEdForm*)this)->GetDlgEditor()->SetDialogModelChanged(TRUE);
1348 else
1350 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1355 //----------------------------------------------------------------------------
1357 void SAL_CALL DlgEdObj::_elementRemoved(const ::com::sun::star::container::ContainerEvent& ) throw(::com::sun::star::uno::RuntimeException)
1359 if (isListening())
1361 // dialog model changed
1362 if ( ISA(DlgEdForm) )
1364 ((DlgEdForm*)this)->GetDlgEditor()->SetDialogModelChanged(TRUE);
1366 else
1368 GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(TRUE);
1373 //----------------------------------------------------------------------------
1375 void DlgEdObj::SetLayer(SdrLayerID nLayer)
1377 SdrLayerID nOldLayer = GetLayer();
1379 if ( nLayer != nOldLayer )
1381 SdrUnoObj::SetLayer( nLayer );
1383 DlgEdHint aHint( DLGED_HINT_LAYERCHANGED, this );
1384 GetDlgEdForm()->GetDlgEditor()->Broadcast( aHint );
1388 //----------------------------------------------------------------------------
1390 TYPEINIT1(DlgEdForm, DlgEdObj);
1391 DBG_NAME(DlgEdForm);
1393 //----------------------------------------------------------------------------
1395 DlgEdForm::DlgEdForm()
1396 :DlgEdObj()
1398 DBG_CTOR(DlgEdForm, NULL);
1401 //----------------------------------------------------------------------------
1403 DlgEdForm::~DlgEdForm()
1405 DBG_DTOR(DlgEdForm, NULL);
1408 //----------------------------------------------------------------------------
1410 void DlgEdForm::SetDlgEditor( DlgEditor* pEditor )
1412 pDlgEditor = pEditor;
1413 ImplInvalidateDeviceInfo();
1416 //----------------------------------------------------------------------------
1418 void DlgEdForm::ImplInvalidateDeviceInfo()
1420 mpDeviceInfo.reset();
1423 //----------------------------------------------------------------------------
1425 void DlgEdForm::SetRectFromProps()
1427 // get form position and size from properties
1428 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
1429 if ( xPSet.is() )
1431 sal_Int32 nXIn = 0, nYIn = 0, nWidthIn = 0, nHeightIn = 0;
1432 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nXIn;
1433 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nYIn;
1434 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidthIn;
1435 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeightIn;
1437 // transform coordinates
1438 sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
1439 if ( TransformFormToSdrCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
1441 // set rectangle position and size
1442 Point aPoint( nXOut, nYOut );
1443 Size aSize( nWidthOut, nHeightOut );
1444 SetSnapRect( Rectangle( aPoint, aSize ) );
1449 //----------------------------------------------------------------------------
1451 void DlgEdForm::SetPropsFromRect()
1453 // get form position and size from rectangle
1454 Rectangle aRect_ = GetSnapRect();
1455 sal_Int32 nXIn = aRect_.Left();
1456 sal_Int32 nYIn = aRect_.Top();
1457 sal_Int32 nWidthIn = aRect_.GetWidth();
1458 sal_Int32 nHeightIn = aRect_.GetHeight();
1460 // transform coordinates
1461 sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
1462 if ( TransformSdrToFormCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
1464 // set properties
1465 Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
1466 if ( xPSet.is() )
1468 Any aValue;
1469 aValue <<= nXOut;
1470 xPSet->setPropertyValue( DLGED_PROP_POSITIONX, aValue );
1471 aValue <<= nYOut;
1472 xPSet->setPropertyValue( DLGED_PROP_POSITIONY, aValue );
1473 aValue <<= nWidthOut;
1474 xPSet->setPropertyValue( DLGED_PROP_WIDTH, aValue );
1475 aValue <<= nHeightOut;
1476 xPSet->setPropertyValue( DLGED_PROP_HEIGHT, aValue );
1481 //----------------------------------------------------------------------------
1483 void DlgEdForm::AddChild( DlgEdObj* pDlgEdObj )
1485 pChilds.push_back( pDlgEdObj );
1488 //----------------------------------------------------------------------------
1490 void DlgEdForm::RemoveChild( DlgEdObj* pDlgEdObj )
1492 pChilds.erase( ::std::find( pChilds.begin() , pChilds.end() , pDlgEdObj ) );
1495 //----------------------------------------------------------------------------
1497 void DlgEdForm::PositionAndSizeChange( const beans::PropertyChangeEvent& evt )
1499 DlgEditor* pEditor = GetDlgEditor();
1500 DBG_ASSERT( pEditor, "DlgEdForm::PositionAndSizeChange: no dialog editor!" );
1501 if ( pEditor )
1503 DlgEdPage* pPage_ = pEditor->GetPage();
1504 DBG_ASSERT( pPage_, "DlgEdForm::PositionAndSizeChange: no page!" );
1505 if ( pPage_ )
1507 sal_Int32 nPageXIn = 0;
1508 sal_Int32 nPageYIn = 0;
1509 Size aPageSize = pPage_->GetSize();
1510 sal_Int32 nPageWidthIn = aPageSize.Width();
1511 sal_Int32 nPageHeightIn = aPageSize.Height();
1512 sal_Int32 nPageX, nPageY, nPageWidth, nPageHeight;
1513 if ( TransformSdrToFormCoordinates( nPageXIn, nPageYIn, nPageWidthIn, nPageHeightIn, nPageX, nPageY, nPageWidth, nPageHeight ) )
1515 Reference< beans::XPropertySet > xPSetForm( GetUnoControlModel(), UNO_QUERY );
1516 if ( xPSetForm.is() )
1518 sal_Int32 nValue = 0;
1519 evt.NewValue >>= nValue;
1520 sal_Int32 nNewValue = nValue;
1522 if ( evt.PropertyName == DLGED_PROP_POSITIONX )
1524 if ( nNewValue < nPageX )
1525 nNewValue = nPageX;
1527 else if ( evt.PropertyName == DLGED_PROP_POSITIONY )
1529 if ( nNewValue < nPageY )
1530 nNewValue = nPageY;
1532 else if ( evt.PropertyName == DLGED_PROP_WIDTH )
1534 if ( nNewValue < 1 )
1535 nNewValue = 1;
1537 else if ( evt.PropertyName == DLGED_PROP_HEIGHT )
1539 if ( nNewValue < 1 )
1540 nNewValue = 1;
1543 if ( nNewValue != nValue )
1545 Any aNewValue;
1546 aNewValue <<= nNewValue;
1547 EndListening( sal_False );
1548 xPSetForm->setPropertyValue( evt.PropertyName, aNewValue );
1549 StartListening();
1554 bool bAdjustedPageSize = pEditor->AdjustPageSize();
1555 SetRectFromProps();
1556 ::std::vector< DlgEdObj* >::iterator aIter;
1557 ::std::vector< DlgEdObj* > aChildList = ((DlgEdForm*)this)->GetChilds();
1559 if ( bAdjustedPageSize )
1561 pEditor->InitScrollBars();
1562 aPageSize = pPage_->GetSize();
1563 nPageWidthIn = aPageSize.Width();
1564 nPageHeightIn = aPageSize.Height();
1565 if ( TransformSdrToControlCoordinates( nPageXIn, nPageYIn, nPageWidthIn, nPageHeightIn, nPageX, nPageY, nPageWidth, nPageHeight ) )
1567 for ( aIter = aChildList.begin(); aIter != aChildList.end(); aIter++ )
1569 Reference< beans::XPropertySet > xPSet( (*aIter)->GetUnoControlModel(), UNO_QUERY );
1570 if ( xPSet.is() )
1572 sal_Int32 nX = 0, nY = 0, nWidth = 0, nHeight = 0;
1573 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nX;
1574 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nY;
1575 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidth;
1576 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeight;
1578 sal_Int32 nNewX = nX;
1579 if ( nX + nWidth > nPageX + nPageWidth )
1581 nNewX = nPageX + nPageWidth - nWidth;
1582 if ( nNewX < nPageX )
1583 nNewX = nPageX;
1585 if ( nNewX != nX )
1587 Any aValue;
1588 aValue <<= nNewX;
1589 EndListening( sal_False );
1590 xPSet->setPropertyValue( DLGED_PROP_POSITIONX, aValue );
1591 StartListening();
1594 sal_Int32 nNewY = nY;
1595 if ( nY + nHeight > nPageY + nPageHeight )
1597 nNewY = nPageY + nPageHeight - nHeight;
1598 if ( nNewY < nPageY )
1599 nNewY = nPageY;
1601 if ( nNewY != nY )
1603 Any aValue;
1604 aValue <<= nNewY;
1605 EndListening( sal_False );
1606 xPSet->setPropertyValue( DLGED_PROP_POSITIONY, aValue );
1607 StartListening();
1614 for ( aIter = aChildList.begin(); aIter != aChildList.end(); aIter++ )
1616 (*aIter)->SetRectFromProps();
1622 //----------------------------------------------------------------------------
1624 void DlgEdForm::UpdateStep()
1626 ULONG nObjCount;
1627 SdrPage* pSdrPage = GetPage();
1629 if ( pSdrPage && ( ( nObjCount = pSdrPage->GetObjCount() ) > 0 ) )
1631 for ( ULONG i = 0 ; i < nObjCount ; i++ )
1633 SdrObject* pObj = pSdrPage->GetObj(i);
1634 DlgEdObj* pDlgEdObj = PTR_CAST(DlgEdObj, pObj);
1635 if ( pDlgEdObj && !pDlgEdObj->ISA(DlgEdForm) )
1636 pDlgEdObj->UpdateStep();
1641 //----------------------------------------------------------------------------
1643 void DlgEdForm::UpdateTabIndices()
1645 // stop listening with all children
1646 ::std::vector<DlgEdObj*>::iterator aIter;
1647 for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; ++aIter )
1649 (*aIter)->EndListening( sal_False );
1652 Reference< ::com::sun::star::container::XNameAccess > xNameAcc( GetUnoControlModel() , UNO_QUERY );
1653 if ( xNameAcc.is() )
1655 // get sequence of control names
1656 Sequence< ::rtl::OUString > aNames = xNameAcc->getElementNames();
1657 const ::rtl::OUString* pNames = aNames.getConstArray();
1658 sal_Int32 nCtrls = aNames.getLength();
1660 // create a map of tab indices and control names, sorted by tab index
1661 IndexToNameMap aIndexToNameMap;
1662 for ( sal_Int16 i = 0; i < nCtrls; ++i )
1664 // get name
1665 ::rtl::OUString aName( pNames[i] );
1667 // get tab index
1668 sal_Int16 nTabIndex = -1;
1669 Any aCtrl = xNameAcc->getByName( aName );
1670 Reference< ::com::sun::star::beans::XPropertySet > xPSet;
1671 aCtrl >>= xPSet;
1672 if ( xPSet.is() )
1673 xPSet->getPropertyValue( DLGED_PROP_TABINDEX ) >>= nTabIndex;
1675 // insert into map
1676 aIndexToNameMap.insert( IndexToNameMap::value_type( nTabIndex, aName ) );
1679 // set new tab indices
1680 sal_Int16 nNewTabIndex = 0;
1681 for ( IndexToNameMap::iterator aIt = aIndexToNameMap.begin(); aIt != aIndexToNameMap.end(); ++aIt )
1683 Any aCtrl = xNameAcc->getByName( aIt->second );
1684 Reference< beans::XPropertySet > xPSet;
1685 aCtrl >>= xPSet;
1686 if ( xPSet.is() )
1688 Any aTabIndex;
1689 aTabIndex <<= (sal_Int16) nNewTabIndex++;
1690 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
1694 // #110559#
1695 UpdateTabOrderAndGroups();
1698 // start listening with all children
1699 for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; ++aIter )
1701 (*aIter)->StartListening();
1705 //----------------------------------------------------------------------------
1707 void DlgEdForm::UpdateTabOrder()
1709 // #110559#
1710 // When the tabindex of a control model changes, the dialog control is
1711 // notified about those changes. Due to #109067# (bad performance of
1712 // dialog editor) the dialog control doesn't activate the tab order
1713 // in design mode. When the dialog editor has reordered all
1714 // tabindices, this method allows to activate the taborder afterwards.
1716 Reference< awt::XUnoControlContainer > xCont( GetControl(), UNO_QUERY );
1717 if ( xCont.is() )
1719 Sequence< Reference< awt::XTabController > > aSeqTabCtrls = xCont->getTabControllers();
1720 const Reference< awt::XTabController >* pTabCtrls = aSeqTabCtrls.getConstArray();
1721 sal_Int32 nCount = aSeqTabCtrls.getLength();
1722 for ( sal_Int32 i = 0; i < nCount; ++i )
1723 pTabCtrls[i]->activateTabOrder();
1727 //----------------------------------------------------------------------------
1729 void DlgEdForm::UpdateGroups()
1731 // #110559#
1732 // The grouping of radio buttons in a dialog is done by vcl.
1733 // In the dialog editor we have two views (=controls) for one
1734 // radio button model. One control is owned by the dialog control,
1735 // but not visible in design mode. The other control is owned by
1736 // the drawing layer object. Whereas the grouping of the first
1737 // control is done by vcl, the grouping of the control in the
1738 // drawing layer has to be done here.
1740 Reference< awt::XTabControllerModel > xTabModel( GetUnoControlModel() , UNO_QUERY );
1741 if ( xTabModel.is() )
1743 // create a global list of controls that belong to the dialog
1744 ::std::vector<DlgEdObj*> aChildList = GetChilds();
1745 sal_uInt32 nSize = aChildList.size();
1746 Sequence< Reference< awt::XControl > > aSeqControls( nSize );
1747 for ( sal_uInt32 i = 0; i < nSize; ++i )
1748 aSeqControls.getArray()[i] = Reference< awt::XControl >( aChildList[i]->GetControl(), UNO_QUERY );
1750 sal_Int32 nGroupCount = xTabModel->getGroupCount();
1751 for ( sal_Int32 nGroup = 0; nGroup < nGroupCount; ++nGroup )
1753 // get a list of control models that belong to this group
1754 ::rtl::OUString aName;
1755 Sequence< Reference< awt::XControlModel > > aSeqModels;
1756 xTabModel->getGroup( nGroup, aSeqModels, aName );
1757 const Reference< awt::XControlModel >* pModels = aSeqModels.getConstArray();
1758 sal_Int32 nModelCount = aSeqModels.getLength();
1760 // create a list of peers that belong to this group
1761 Sequence< Reference< awt::XWindow > > aSeqPeers( nModelCount );
1762 for ( sal_Int32 nModel = 0; nModel < nModelCount; ++nModel )
1764 // for each control model find the corresponding control in the global list
1765 const Reference< awt::XControl >* pControls = aSeqControls.getConstArray();
1766 sal_Int32 nControlCount = aSeqControls.getLength();
1767 for ( sal_Int32 nControl = 0; nControl < nControlCount; ++nControl )
1769 const Reference< awt::XControl > xCtrl( pControls[nControl] );
1770 if ( xCtrl.is() )
1772 Reference< awt::XControlModel > xCtrlModel( xCtrl->getModel() );
1773 if ( (awt::XControlModel*)xCtrlModel.get() == (awt::XControlModel*)pModels[nModel].get() )
1775 // get the control peer and insert into the list of peers
1776 aSeqPeers.getArray()[ nModel ] = Reference< awt::XWindow >( xCtrl->getPeer(), UNO_QUERY );
1777 break;
1783 // set the group at the dialog peer
1784 Reference< awt::XControl > xDlg( GetControl(), UNO_QUERY );
1785 if ( xDlg.is() )
1787 Reference< awt::XVclContainerPeer > xDlgPeer( xDlg->getPeer(), UNO_QUERY );
1788 if ( xDlgPeer.is() )
1789 xDlgPeer->setGroup( aSeqPeers );
1795 //----------------------------------------------------------------------------
1797 void DlgEdForm::UpdateTabOrderAndGroups()
1799 UpdateTabOrder();
1800 UpdateGroups();
1803 //----------------------------------------------------------------------------
1805 void DlgEdForm::NbcMove( const Size& rSize )
1807 SdrUnoObj::NbcMove( rSize );
1809 // set geometry properties of form
1810 EndListening(sal_False);
1811 SetPropsFromRect();
1812 StartListening();
1814 // set geometry properties of all childs
1815 ::std::vector<DlgEdObj*>::iterator aIter;
1816 for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; aIter++ )
1818 (*aIter)->EndListening(sal_False);
1819 (*aIter)->SetPropsFromRect();
1820 (*aIter)->StartListening();
1823 // dialog model changed
1824 GetDlgEditor()->SetDialogModelChanged(TRUE);
1827 //----------------------------------------------------------------------------
1829 void DlgEdForm::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1831 SdrUnoObj::NbcResize( rRef, xFract, yFract );
1833 // set geometry properties of form
1834 EndListening(sal_False);
1835 SetPropsFromRect();
1836 StartListening();
1838 // set geometry properties of all childs
1839 ::std::vector<DlgEdObj*>::iterator aIter;
1840 for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; aIter++ )
1842 (*aIter)->EndListening(sal_False);
1843 (*aIter)->SetPropsFromRect();
1844 (*aIter)->StartListening();
1847 // dialog model changed
1848 GetDlgEditor()->SetDialogModelChanged(TRUE);
1851 //----------------------------------------------------------------------------
1853 FASTBOOL DlgEdForm::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1855 FASTBOOL bResult = SdrUnoObj::EndCreate(rStat, eCmd);
1857 // stop listening
1858 EndListening(sal_False);
1860 // set geometry properties
1861 SetPropsFromRect();
1863 // dialog model changed
1864 GetDlgEditor()->SetDialogModelChanged(TRUE);
1866 // start listening
1867 StartListening();
1869 return bResult;
1872 //----------------------------------------------------------------------------
1874 awt::DeviceInfo DlgEdForm::getDeviceInfo() const
1876 awt::DeviceInfo aDeviceInfo;
1878 DlgEditor* pEditor = GetDlgEditor();
1879 DBG_ASSERT( pEditor, "DlgEdForm::getDeviceInfo: no editor associated with the form object!" );
1880 if ( !pEditor )
1881 return aDeviceInfo;
1883 Window* pWindow = pEditor->GetWindow();
1884 DBG_ASSERT( pWindow, "DlgEdForm::getDeviceInfo: no window associated with the editor!" );
1885 if ( !pWindow )
1886 return aDeviceInfo;
1888 // obtain an XControl
1889 ::utl::SharedUNOComponent< awt::XControl > xDialogControl; // ensures auto-disposal, if needed
1890 xDialogControl.reset( GetControl(), ::utl::SharedUNOComponent< awt::XControl >::NoTakeOwnership );
1891 if ( !xDialogControl.is() )
1893 // don't create a temporary control all the time, this method here is called
1894 // way too often. Instead, use a cached DeviceInfo.
1895 // 2007-02-05 / i74065 / frank.schoenheit@sun.com
1896 if ( !!mpDeviceInfo )
1897 return *mpDeviceInfo;
1899 Reference< awt::XControlContainer > xEditorControlContainer( pEditor->GetWindowControlContainer() );
1900 xDialogControl.reset(
1901 GetTemporaryControlForWindow( *pWindow, xEditorControlContainer ),
1902 ::utl::SharedUNOComponent< awt::XControl >::TakeOwnership );
1905 Reference< awt::XDevice > xDialogDevice;
1906 if ( xDialogControl.is() )
1907 xDialogDevice.set( xDialogControl->getPeer(), UNO_QUERY );
1908 DBG_ASSERT( xDialogDevice.is(), "DlgEdForm::getDeviceInfo: no device!" );
1909 if ( xDialogDevice.is() )
1910 aDeviceInfo = xDialogDevice->getInfo();
1912 mpDeviceInfo.reset( aDeviceInfo );
1914 return aDeviceInfo;
1917 //----------------------------------------------------------------------------