xref: /trunk/main/basctl/source/dlged/dlgedobj.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basctl.hxx"
30 
31 #include <vector>
32 #include <algorithm>
33 #include <dlgeddef.hxx>
34 #include "dlgedobj.hxx"
35 #include "dlged.hxx"
36 #include "dlgedmod.hxx"
37 #include "dlgedpage.hxx"
38 #include "dlgedview.hxx"
39 #include "dlgedlist.hxx"
40 #include <iderid.hxx>
41 #include <localizationmgr.hxx>
42 
43 #ifndef _BASCTL_DLGRESID_HRC
44 #include <dlgresid.hrc>
45 #endif
46 #include <tools/resmgr.hxx>
47 #include <tools/shl.hxx>
48 #include <unotools/sharedunocomponent.hxx>
49 #include <com/sun/star/awt/XTabControllerModel.hpp>
50 #include <com/sun/star/awt/XUnoControlContainer.hpp>
51 #include <com/sun/star/awt/XVclContainerPeer.hpp>
52 #include <com/sun/star/awt/XWindow.hpp>
53 #include <com/sun/star/beans/XPropertySet.hpp>
54 #include <com/sun/star/beans/PropertyAttribute.hpp>
55 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
56 #include <com/sun/star/container/XContainer.hpp>
57 #include <com/sun/star/lang/XServiceInfo.hpp>
58 #include <comphelper/processfactory.hxx>
59 #include <comphelper/types.hxx>
60 #include <vcl/svapp.hxx>
61 
62 #include <algorithm>
63 #include <functional>
64 
65 using namespace ::com::sun::star;
66 using namespace ::com::sun::star::uno;
67 using namespace ::com::sun::star::beans;
68 using namespace ::com::sun::star::container;
69 using namespace ::com::sun::star::script;
70 using ::rtl::OUString;
71 
72 
73 TYPEINIT1(DlgEdObj, SdrUnoObj);
74 DBG_NAME(DlgEdObj);
75 
76 //----------------------------------------------------------------------------
77 
78 DlgEdObj::DlgEdObj()
79           :SdrUnoObj(String(), sal_False)
80           ,bIsListening(sal_False)
81           ,pDlgEdForm( NULL )
82 {
83     DBG_CTOR(DlgEdObj, NULL);
84 }
85 
86 //----------------------------------------------------------------------------
87 
88 DlgEdObj::DlgEdObj(const ::rtl::OUString& rModelName,
89                    const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac)
90           :SdrUnoObj(rModelName, rxSFac, sal_False)
91           ,bIsListening(sal_False)
92           ,pDlgEdForm( NULL )
93 {
94     DBG_CTOR(DlgEdObj, NULL);
95 }
96 
97 //----------------------------------------------------------------------------
98 
99 DlgEdObj::~DlgEdObj()
100 {
101     DBG_DTOR(DlgEdObj, NULL);
102 
103     if ( isListening() )
104         EndListening();
105 }
106 
107 //----------------------------------------------------------------------------
108 
109 void DlgEdObj::SetPage(SdrPage* _pNewPage)
110 {
111     // now set the page
112     SdrUnoObj::SetPage(_pNewPage);
113 }
114 
115 //----------------------------------------------------------------------------
116 
117 namespace
118 {
119     /** returns the DlgEdForm which the given DlgEdObj belongs to
120         (which might in fact be the object itself)
121 
122         Failure to obtain the form will be reported with an assertion in the non-product
123         version.
124      */
125     bool lcl_getDlgEdForm( DlgEdObj* _pObject, DlgEdForm*& _out_pDlgEdForm )
126     {
127         _out_pDlgEdForm = dynamic_cast< DlgEdForm* >( _pObject );
128         if ( !_out_pDlgEdForm )
129             _out_pDlgEdForm = _pObject->GetDlgEdForm();
130         DBG_ASSERT( _out_pDlgEdForm, "lcl_getDlgEdForm: no form!" );
131         return ( _out_pDlgEdForm != NULL );
132     }
133 }
134 
135 //----------------------------------------------------------------------------
136 
137 uno::Reference< awt::XControl > DlgEdObj::GetControl() const
138 {
139     const DlgEdForm* pForm = GetDlgEdForm();
140     const DlgEditor* pEditor = pForm ? pForm->GetDlgEditor() : NULL;
141     SdrView* pView = pEditor ? pEditor->GetView() : NULL;
142     Window* pWindow = pEditor ? pEditor->GetWindow() : NULL;
143     OSL_ENSURE( ( pView && pWindow ) || !pForm, "DlgEdObj::GetControl: no view or no window!" );
144 
145     uno::Reference< awt::XControl > xControl;
146     if ( pView && pWindow )
147         xControl = GetUnoControl( *pView, *pWindow );
148 
149     return xControl;
150 }
151 
152 //----------------------------------------------------------------------------
153 
154 bool DlgEdObj::TransformSdrToControlCoordinates(
155     sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
156     sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
157 {
158     // input position and size
159     Size aPos( nXIn, nYIn );
160     Size aSize( nWidthIn, nHeightIn );
161 
162     // form position
163     DlgEdForm* pForm = NULL;
164     if ( !lcl_getDlgEdForm( this, pForm ) )
165         return false;
166     Rectangle aFormRect = pForm->GetSnapRect();
167     Size aFormPos( aFormRect.Left(), aFormRect.Top() );
168 
169     // convert 100th_mm to pixel
170     OutputDevice* pDevice = Application::GetDefaultDevice();
171     DBG_ASSERT( pDevice, "DlgEdObj::TransformSdrToControlCoordinates: missing default device!" );
172     if ( !pDevice )
173         return false;
174     aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_100TH_MM ) );
175     aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_100TH_MM ) );
176     aFormPos = pDevice->LogicToPixel( aFormPos, MapMode( MAP_100TH_MM ) );
177 
178     // subtract form position
179     aPos.Width() -= aFormPos.Width();
180     aPos.Height() -= aFormPos.Height();
181 
182     // take window borders into account
183     Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
184     DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
185     if ( !xPSetForm.is() )
186         return false;
187     bool bDecoration = true;
188     xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
189     if( bDecoration )
190     {
191         awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
192         aPos.Width() -= aDeviceInfo.LeftInset;
193         aPos.Height() -= aDeviceInfo.TopInset;
194     }
195 
196     // convert pixel to logic units
197     aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_APPFONT ) );
198     aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_APPFONT ) );
199 
200     // set out parameters
201     nXOut = aPos.Width();
202     nYOut = aPos.Height();
203     nWidthOut = aSize.Width();
204     nHeightOut = aSize.Height();
205 
206     return true;
207 }
208 
209 //----------------------------------------------------------------------------
210 
211 bool DlgEdObj::TransformSdrToFormCoordinates(
212     sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
213     sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
214 {
215     // input position and size
216     Size aPos( nXIn, nYIn );
217     Size aSize( nWidthIn, nHeightIn );
218 
219     // convert 100th_mm to pixel
220     OutputDevice* pDevice = Application::GetDefaultDevice();
221     DBG_ASSERT( pDevice, "DlgEdObj::TransformSdrToFormCoordinates: missing default device!" );
222     if ( !pDevice )
223         return false;
224     aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_100TH_MM ) );
225     aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_100TH_MM ) );
226 
227     // take window borders into account
228     DlgEdForm* pForm = NULL;
229     if ( !lcl_getDlgEdForm( this, pForm ) )
230         return false;
231 
232     // take window borders into account
233     Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
234     DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
235     if ( !xPSetForm.is() )
236         return false;
237     bool bDecoration = true;
238     xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
239     if( bDecoration )
240     {
241         awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
242         aSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
243         aSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
244     }
245 
246     // convert pixel to logic units
247     aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_APPFONT ) );
248     aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_APPFONT ) );
249 
250     // set out parameters
251     nXOut = aPos.Width();
252     nYOut = aPos.Height();
253     nWidthOut = aSize.Width();
254     nHeightOut = aSize.Height();
255 
256     return true;
257 }
258 
259 //----------------------------------------------------------------------------
260 
261 bool DlgEdObj::TransformControlToSdrCoordinates(
262     sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
263     sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
264 {
265     // input position and size
266     Size aPos( nXIn, nYIn );
267     Size aSize( nWidthIn, nHeightIn );
268 
269     // form position
270     DlgEdForm* pForm = NULL;
271     if ( !lcl_getDlgEdForm( this, pForm ) )
272         return false;
273 
274     Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
275     DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformControlToSdrCoordinates: no form property set!" );
276     if ( !xPSetForm.is() )
277         return false;
278     sal_Int32 nFormX = 0, nFormY = 0, nFormWidth, nFormHeight;
279     xPSetForm->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nFormX;
280     xPSetForm->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nFormY;
281     xPSetForm->getPropertyValue( DLGED_PROP_WIDTH ) >>= nFormWidth;
282     xPSetForm->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nFormHeight;
283     Size aFormPos( nFormX, nFormY );
284 
285     // convert logic units to pixel
286     OutputDevice* pDevice = Application::GetDefaultDevice();
287     DBG_ASSERT( pDevice, "DlgEdObj::TransformControlToSdrCoordinates: missing default device!" );
288     if ( !pDevice )
289         return false;
290     aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_APPFONT ) );
291     aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_APPFONT ) );
292     aFormPos = pDevice->LogicToPixel( aFormPos, MapMode( MAP_APPFONT ) );
293 
294     // add form position
295     aPos.Width() += aFormPos.Width();
296     aPos.Height() += aFormPos.Height();
297 
298     // take window borders into account
299     bool bDecoration = true;
300     xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
301     if( bDecoration )
302     {
303         awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
304         aPos.Width() += aDeviceInfo.LeftInset;
305         aPos.Height() += aDeviceInfo.TopInset;
306     }
307 
308     // convert pixel to 100th_mm
309     aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_100TH_MM ) );
310     aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_100TH_MM ) );
311 
312     // set out parameters
313     nXOut = aPos.Width();
314     nYOut = aPos.Height();
315     nWidthOut = aSize.Width();
316     nHeightOut = aSize.Height();
317 
318     return true;
319 }
320 
321 //----------------------------------------------------------------------------
322 
323 bool DlgEdObj::TransformFormToSdrCoordinates(
324     sal_Int32 nXIn, sal_Int32 nYIn, sal_Int32 nWidthIn, sal_Int32 nHeightIn,
325     sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut )
326 {
327     // input position and size
328     Size aPos( nXIn, nYIn );
329     Size aSize( nWidthIn, nHeightIn );
330 
331     // convert logic units to pixel
332     OutputDevice* pDevice = Application::GetDefaultDevice();
333     DBG_ASSERT( pDevice, "DlgEdObj::TransformFormToSdrCoordinates: missing default device!" );
334     if ( !pDevice )
335         return false;
336     aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_APPFONT ) );
337     aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_APPFONT ) );
338 
339     // take window borders into account
340     DlgEdForm* pForm = NULL;
341     if ( !lcl_getDlgEdForm( this, pForm ) )
342         return false;
343 
344     // take window borders into account
345     Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
346     DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
347     if ( !xPSetForm.is() )
348         return false;
349     bool bDecoration = true;
350     xPSetForm->getPropertyValue( DLGED_PROP_DECORATION ) >>= bDecoration;
351     if( bDecoration )
352     {
353         awt::DeviceInfo aDeviceInfo = pForm->getDeviceInfo();
354         aSize.Width() += aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
355         aSize.Height() += aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
356     }
357 
358     // convert pixel to 100th_mm
359     aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_100TH_MM ) );
360     aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_100TH_MM ) );
361 
362     // set out parameters
363     nXOut = aPos.Width();
364     nYOut = aPos.Height();
365     nWidthOut = aSize.Width();
366     nHeightOut = aSize.Height();
367 
368     return true;
369 }
370 
371 //----------------------------------------------------------------------------
372 
373 void DlgEdObj::SetRectFromProps()
374 {
375     // get control position and size from properties
376     Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
377     if ( xPSet.is() )
378     {
379         sal_Int32 nXIn = 0, nYIn = 0, nWidthIn = 0, nHeightIn = 0;
380         xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nXIn;
381         xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nYIn;
382         xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidthIn;
383         xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeightIn;
384 
385         // transform coordinates
386         sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
387         if ( TransformControlToSdrCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
388         {
389             // set rectangle position and size
390             Point aPoint( nXOut, nYOut );
391             Size aSize( nWidthOut, nHeightOut );
392             SetSnapRect( Rectangle( aPoint, aSize ) );
393         }
394     }
395 }
396 
397 //----------------------------------------------------------------------------
398 
399 void DlgEdObj::SetPropsFromRect()
400 {
401     // get control position and size from rectangle
402     Rectangle aRect_ = GetSnapRect();
403     sal_Int32 nXIn = aRect_.Left();
404     sal_Int32 nYIn = aRect_.Top();
405     sal_Int32 nWidthIn = aRect_.GetWidth();
406     sal_Int32 nHeightIn = aRect_.GetHeight();
407 
408     // transform coordinates
409     sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
410     if ( TransformSdrToControlCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
411     {
412         // set properties
413         Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
414         if ( xPSet.is() )
415         {
416             Any aValue;
417             aValue <<= nXOut;
418             xPSet->setPropertyValue( DLGED_PROP_POSITIONX, aValue );
419             aValue <<= nYOut;
420             xPSet->setPropertyValue( DLGED_PROP_POSITIONY, aValue );
421             aValue <<= nWidthOut;
422             xPSet->setPropertyValue( DLGED_PROP_WIDTH, aValue );
423             aValue <<= nHeightOut;
424             xPSet->setPropertyValue( DLGED_PROP_HEIGHT, aValue );
425         }
426     }
427 }
428 
429 //----------------------------------------------------------------------------
430 
431 void DlgEdObj::PositionAndSizeChange( const beans::PropertyChangeEvent& evt )
432 {
433     DlgEdPage* pPage_ = 0;
434     if ( pDlgEdForm )
435     {
436         DlgEditor* pEditor = pDlgEdForm->GetDlgEditor();
437         if ( pEditor )
438             pPage_ = pEditor->GetPage();
439     }
440     DBG_ASSERT( pPage_, "DlgEdObj::PositionAndSizeChange: no page!" );
441     if ( pPage_ )
442     {
443         sal_Int32 nPageXIn = 0;
444         sal_Int32 nPageYIn = 0;
445         Size aPageSize = pPage_->GetSize();
446         sal_Int32 nPageWidthIn = aPageSize.Width();
447         sal_Int32 nPageHeightIn = aPageSize.Height();
448         sal_Int32 nPageX, nPageY, nPageWidth, nPageHeight;
449         if ( TransformSdrToControlCoordinates( nPageXIn, nPageYIn, nPageWidthIn, nPageHeightIn, nPageX, nPageY, nPageWidth, nPageHeight ) )
450         {
451             Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
452             if ( xPSet.is() )
453             {
454                 sal_Int32 nX = 0, nY = 0, nWidth = 0, nHeight = 0;
455                 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nX;
456                 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nY;
457                 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidth;
458                 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeight;
459 
460                 sal_Int32 nValue = 0;
461                 evt.NewValue >>= nValue;
462                 sal_Int32 nNewValue = nValue;
463 
464                 if ( evt.PropertyName == DLGED_PROP_POSITIONX )
465                 {
466                     if ( nNewValue + nWidth > nPageX + nPageWidth )
467                         nNewValue = nPageX + nPageWidth - nWidth;
468                     if ( nNewValue < nPageX )
469                         nNewValue = nPageX;
470                 }
471                 else if ( evt.PropertyName == DLGED_PROP_POSITIONY )
472                 {
473                     if ( nNewValue + nHeight > nPageY + nPageHeight )
474                         nNewValue = nPageY + nPageHeight - nHeight;
475                     if ( nNewValue < nPageY )
476                         nNewValue = nPageY;
477                 }
478                 else if ( evt.PropertyName == DLGED_PROP_WIDTH )
479                 {
480                     if ( nX + nNewValue > nPageX + nPageWidth )
481                         nNewValue = nPageX + nPageWidth - nX;
482                     if ( nNewValue < 1 )
483                         nNewValue = 1;
484                 }
485                 else if ( evt.PropertyName == DLGED_PROP_HEIGHT )
486                 {
487                     if ( nY + nNewValue > nPageY + nPageHeight )
488                         nNewValue = nPageY + nPageHeight - nY;
489                     if ( nNewValue < 1 )
490                         nNewValue = 1;
491                 }
492 
493                 if ( nNewValue != nValue )
494                 {
495                     Any aNewValue;
496                     aNewValue <<= nNewValue;
497                     EndListening( sal_False );
498                     xPSet->setPropertyValue( evt.PropertyName, aNewValue );
499                     StartListening();
500                 }
501             }
502         }
503     }
504 
505     SetRectFromProps();
506 }
507 
508 //----------------------------------------------------------------------------
509 
510 void SAL_CALL DlgEdObj::NameChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException)
511 {
512     // get old name
513     ::rtl::OUString aOldName;
514     evt.OldValue >>= aOldName;
515 
516     // get new name
517     ::rtl::OUString aNewName;
518     evt.NewValue >>= aNewName;
519 
520     if ( !aNewName.equals(aOldName) )
521     {
522         Reference< container::XNameAccess > xNameAcc((GetDlgEdForm()->GetUnoControlModel()), UNO_QUERY);
523         if ( xNameAcc.is() && xNameAcc->hasByName(aOldName) )
524         {
525             if ( !xNameAcc->hasByName(aNewName) && aNewName.getLength() != 0 )
526             {
527                 // remove the control by the old name and insert the control by the new name in the container
528                 Reference< container::XNameContainer > xCont(xNameAcc, UNO_QUERY );
529                 if ( xCont.is() )
530                 {
531                     Reference< awt::XControlModel > xCtrl(GetUnoControlModel(), UNO_QUERY);
532                     Any aAny;
533                     aAny <<= xCtrl;
534                     xCont->removeByName( aOldName );
535                     xCont->insertByName( aNewName , aAny );
536 
537                     DlgEditor* pEditor;
538                     if ( ISA(DlgEdForm) )
539                         pEditor = ((DlgEdForm*)this)->GetDlgEditor();
540                     else
541                         pEditor = GetDlgEdForm()->GetDlgEditor();
542                     LocalizationMgr::renameControlResourceIDsForEditorObject( pEditor, aAny, aNewName );
543                 }
544             }
545             else
546             {
547                 // set old name property
548                 EndListening(sal_False);
549                 Reference< beans::XPropertySet >  xPSet(GetUnoControlModel(), UNO_QUERY);
550                 Any aName;
551                 aName <<= aOldName;
552                 xPSet->setPropertyValue( DLGED_PROP_NAME, aName );
553                 StartListening();
554             }
555         }
556     }
557 }
558 
559 //----------------------------------------------------------------------------
560 
561 sal_Int32 DlgEdObj::GetStep() const
562 {
563     // get step property
564     sal_Int32 nStep = 0;
565     uno::Reference< beans::XPropertySet >  xPSet( GetUnoControlModel(), uno::UNO_QUERY );
566     if (xPSet.is())
567     {
568         xPSet->getPropertyValue( DLGED_PROP_STEP ) >>= nStep;
569     }
570     return nStep;
571 }
572 
573 //----------------------------------------------------------------------------
574 
575 void DlgEdObj::UpdateStep()
576 {
577     sal_Int32 nCurStep = GetDlgEdForm()->GetStep();
578     sal_Int32 nStep = GetStep();
579 
580     SdrLayerAdmin& rLayerAdmin = GetModel()->GetLayerAdmin();
581     SdrLayerID nHiddenLayerId   = rLayerAdmin.GetLayerID( String( RTL_CONSTASCII_USTRINGPARAM( "HiddenLayer" ) ), sal_False );
582     SdrLayerID nControlLayerId   = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), sal_False );
583 
584     if( nCurStep )
585     {
586         if ( nStep && (nStep != nCurStep) )
587         {
588             SetLayer( nHiddenLayerId );
589         }
590         else
591         {
592             SetLayer( nControlLayerId );
593         }
594     }
595     else
596     {
597         SetLayer( nControlLayerId );
598     }
599 }
600 
601 //----------------------------------------------------------------------------
602 
603 void DlgEdObj::TabIndexChange( const beans::PropertyChangeEvent& evt ) throw (RuntimeException)
604 {
605     DlgEdForm* pForm = GetDlgEdForm();
606     if ( pForm )
607     {
608         // stop listening with all children
609         ::std::vector<DlgEdObj*> aChildList = pForm->GetChilds();
610         ::std::vector<DlgEdObj*>::iterator aIter;
611         for ( aIter = aChildList.begin() ; aIter != aChildList.end() ; ++aIter )
612         {
613             (*aIter)->EndListening( sal_False );
614         }
615 
616         Reference< container::XNameAccess > xNameAcc( pForm->GetUnoControlModel() , UNO_QUERY );
617         if ( xNameAcc.is() )
618         {
619             // get sequence of control names
620             Sequence< ::rtl::OUString > aNames = xNameAcc->getElementNames();
621             const ::rtl::OUString* pNames = aNames.getConstArray();
622             sal_Int32 nCtrls = aNames.getLength();
623             sal_Int16 i;
624 
625             // create a map of tab indices and control names, sorted by tab index
626             IndexToNameMap aIndexToNameMap;
627             for ( i = 0; i < nCtrls; ++i )
628             {
629                 // get control name
630                 ::rtl::OUString aName( pNames[i] );
631 
632                 // get tab index
633                 sal_Int16 nTabIndex = -1;
634                 Any aCtrl = xNameAcc->getByName( aName );
635                 Reference< beans::XPropertySet > xPSet;
636                 aCtrl >>= xPSet;
637                 if ( xPSet.is() && xPSet == Reference< beans::XPropertySet >( evt.Source, UNO_QUERY ) )
638                     evt.OldValue >>= nTabIndex;
639                 else if ( xPSet.is() )
640                     xPSet->getPropertyValue( DLGED_PROP_TABINDEX ) >>= nTabIndex;
641 
642                 // insert into map
643                 aIndexToNameMap.insert( IndexToNameMap::value_type( nTabIndex, aName ) );
644             }
645 
646             // create a helper list of control names, sorted by tab index
647             ::std::vector< ::rtl::OUString > aNameList( aIndexToNameMap.size() );
648             ::std::transform(
649                     aIndexToNameMap.begin(), aIndexToNameMap.end(),
650                     aNameList.begin(),
651                     ::std::select2nd< IndexToNameMap::value_type >( )
652                 );
653 
654             // check tab index
655             sal_Int16 nOldTabIndex = 0;
656             evt.OldValue >>= nOldTabIndex;
657             sal_Int16 nNewTabIndex = 0;
658             evt.NewValue >>= nNewTabIndex;
659             if ( nNewTabIndex < 0 )
660                 nNewTabIndex = 0;
661             else if ( nNewTabIndex > nCtrls - 1 )
662                 nNewTabIndex = sal::static_int_cast<sal_Int16>( nCtrls - 1 );
663 
664             // reorder helper list
665             ::rtl::OUString aCtrlName = aNameList[nOldTabIndex];
666             aNameList.erase( aNameList.begin() + nOldTabIndex );
667             aNameList.insert( aNameList.begin() + nNewTabIndex , aCtrlName );
668 
669             // set new tab indices
670             for ( i = 0; i < nCtrls; ++i )
671             {
672                 Any aCtrl = xNameAcc->getByName( aNameList[i] );
673                 Reference< beans::XPropertySet > xPSet;
674                 aCtrl >>= xPSet;
675                 if ( xPSet.is() )
676                 {
677                     Any aTabIndex;
678                     aTabIndex <<= (sal_Int16) i;
679                     xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
680                 }
681             }
682 
683             // reorder objects in drawing page
684             GetModel()->GetPage(0)->SetObjectOrdNum( nOldTabIndex + 1, nNewTabIndex + 1 );
685 
686             // #110559#
687             pForm->UpdateTabOrderAndGroups();
688         }
689 
690         // start listening with all children
691         for ( aIter = aChildList.begin() ; aIter != aChildList.end() ; ++aIter )
692         {
693             (*aIter)->StartListening();
694         }
695     }
696 }
697 
698 //----------------------------------------------------------------------------
699 
700 sal_Bool DlgEdObj::supportsService( const sal_Char* _pServiceName ) const
701 {
702     sal_Bool bSupports = sal_False;
703 
704     Reference< lang::XServiceInfo > xServiceInfo( GetUnoControlModel() , UNO_QUERY );
705         // TODO: cache xServiceInfo as member?
706     if ( xServiceInfo.is() )
707         bSupports = xServiceInfo->supportsService( ::rtl::OUString::createFromAscii( _pServiceName ) );
708 
709     return bSupports;
710 }
711 
712 //----------------------------------------------------------------------------
713 
714 ::rtl::OUString DlgEdObj::GetDefaultName() const
715 {
716     sal_uInt16 nResId = 0;
717     ::rtl::OUString aDefaultName;
718     if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
719     {
720         nResId = RID_STR_CLASS_DIALOG;
721     }
722     else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
723     {
724         nResId = RID_STR_CLASS_BUTTON;
725     }
726     else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
727     {
728         nResId = RID_STR_CLASS_RADIOBUTTON;
729     }
730     else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
731     {
732         nResId = RID_STR_CLASS_CHECKBOX;
733     }
734     else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
735     {
736         nResId = RID_STR_CLASS_LISTBOX;
737     }
738     else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
739     {
740         nResId = RID_STR_CLASS_COMBOBOX;
741     }
742     else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
743     {
744         nResId = RID_STR_CLASS_GROUPBOX;
745     }
746     else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
747     {
748         nResId = RID_STR_CLASS_EDIT;
749     }
750     else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
751     {
752         nResId = RID_STR_CLASS_FIXEDTEXT;
753     }
754     else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
755     {
756         nResId = RID_STR_CLASS_IMAGECONTROL;
757     }
758     else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
759     {
760         nResId = RID_STR_CLASS_PROGRESSBAR;
761     }
762     else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
763     {
764         nResId = RID_STR_CLASS_SCROLLBAR;
765     }
766     else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
767     {
768         nResId = RID_STR_CLASS_FIXEDLINE;
769     }
770     else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
771     {
772         nResId = RID_STR_CLASS_DATEFIELD;
773     }
774     else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
775     {
776         nResId = RID_STR_CLASS_TIMEFIELD;
777     }
778     else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
779     {
780         nResId = RID_STR_CLASS_NUMERICFIELD;
781     }
782     else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
783     {
784         nResId = RID_STR_CLASS_CURRENCYFIELD;
785     }
786     else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
787     {
788         nResId = RID_STR_CLASS_FORMATTEDFIELD;
789     }
790     else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
791     {
792         nResId = RID_STR_CLASS_PATTERNFIELD;
793     }
794     else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
795     {
796         nResId = RID_STR_CLASS_FILECONTROL;
797     }
798     else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
799     {
800         nResId = RID_STR_CLASS_TREECONTROL;
801     }
802 
803     else
804     {
805         nResId = RID_STR_CLASS_CONTROL;
806     }
807 
808     if (nResId)
809     {
810         aDefaultName = ::rtl::OUString( String(IDEResId(nResId)) );
811     }
812 
813     return aDefaultName;
814 }
815 
816 //----------------------------------------------------------------------------
817 
818 ::rtl::OUString DlgEdObj::GetUniqueName() const
819 {
820     ::rtl::OUString aUniqueName;
821     uno::Reference< container::XNameAccess > xNameAcc((GetDlgEdForm()->GetUnoControlModel()), uno::UNO_QUERY);
822 
823     if ( xNameAcc.is() )
824     {
825         sal_Int32 n = 0;
826         ::rtl::OUString aDefaultName = GetDefaultName();
827 
828         do
829         {
830             aUniqueName = aDefaultName + ::rtl::OUString::valueOf(++n);
831         }   while (xNameAcc->hasByName(aUniqueName));
832     }
833 
834     return aUniqueName;
835 }
836 
837 //----------------------------------------------------------------------------
838 
839 sal_uInt32 DlgEdObj::GetObjInventor()   const
840 {
841     return DlgInventor;
842 }
843 
844 //----------------------------------------------------------------------------
845 
846 sal_uInt16 DlgEdObj::GetObjIdentifier() const
847 {
848     if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ))
849     {
850         return OBJ_DLG_DIALOG;
851     }
852     else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ))
853     {
854         return OBJ_DLG_PUSHBUTTON;
855     }
856     else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ))
857     {
858         return OBJ_DLG_RADIOBUTTON;
859     }
860     else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ))
861     {
862         return OBJ_DLG_CHECKBOX;
863     }
864     else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ))
865     {
866         return OBJ_DLG_LISTBOX;
867     }
868     else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ))
869     {
870         return OBJ_DLG_COMBOBOX;
871     }
872     else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ))
873     {
874         return OBJ_DLG_GROUPBOX;
875     }
876     else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ))
877     {
878         return OBJ_DLG_EDIT;
879     }
880     else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ))
881     {
882         return OBJ_DLG_FIXEDTEXT;
883     }
884     else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ))
885     {
886         return OBJ_DLG_IMAGECONTROL;
887     }
888     else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ))
889     {
890         return OBJ_DLG_PROGRESSBAR;
891     }
892     else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ))
893     {
894         return OBJ_DLG_HSCROLLBAR;
895     }
896     else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ))
897     {
898         return OBJ_DLG_HFIXEDLINE;
899     }
900     else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ))
901     {
902         return OBJ_DLG_DATEFIELD;
903     }
904     else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ))
905     {
906         return OBJ_DLG_TIMEFIELD;
907     }
908     else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ))
909     {
910         return OBJ_DLG_NUMERICFIELD;
911     }
912     else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ))
913     {
914         return OBJ_DLG_CURRENCYFIELD;
915     }
916     else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ))
917     {
918         return OBJ_DLG_FORMATTEDFIELD;
919     }
920     else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ))
921     {
922         return OBJ_DLG_PATTERNFIELD;
923     }
924     else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ))
925     {
926         return OBJ_DLG_FILECONTROL;
927     }
928     else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ))
929     {
930         return OBJ_DLG_TREECONTROL;
931     }
932     else
933     {
934         return OBJ_DLG_CONTROL;
935     }
936 }
937 
938 //----------------------------------------------------------------------------
939 
940 void DlgEdObj::clonedFrom(const DlgEdObj* _pSource)
941 {
942     // set parent form
943     pDlgEdForm = _pSource->pDlgEdForm;
944 
945     // add child to parent form
946     pDlgEdForm->AddChild( this );
947 
948     Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
949     if ( xPSet.is() )
950     {
951         // set new name
952         ::rtl::OUString aOUniqueName( GetUniqueName() );
953         Any aUniqueName;
954         aUniqueName <<= aOUniqueName;
955         xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName );
956 
957         Reference< container::XNameContainer > xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY );
958         if ( xCont.is() )
959         {
960             // set tabindex
961             Sequence< OUString > aNames = xCont->getElementNames();
962             Any aTabIndex;
963             aTabIndex <<= (sal_Int16) aNames.getLength();
964             xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
965 
966             // insert control model in dialog model
967             Reference< awt::XControlModel > xCtrl( xPSet , UNO_QUERY );
968             Any aCtrl;
969             aCtrl <<= xCtrl;
970             xCont->insertByName( aOUniqueName , aCtrl );
971 
972             // #110559#
973             pDlgEdForm->UpdateTabOrderAndGroups();
974         }
975     }
976 
977     // start listening
978     StartListening();
979 }
980 
981 //----------------------------------------------------------------------------
982 
983 SdrObject* DlgEdObj::Clone() const
984 {
985     SdrObject* pReturn = SdrUnoObj::Clone();
986 
987     DlgEdObj* pDlgEdObj = PTR_CAST(DlgEdObj, pReturn);
988     DBG_ASSERT( pDlgEdObj != NULL, "DlgEdObj::Clone: invalid clone!" );
989     if ( pDlgEdObj )
990         pDlgEdObj->clonedFrom( this );
991 
992     return pReturn;
993 }
994 
995 //----------------------------------------------------------------------------
996 
997 SdrObject* DlgEdObj::getFullDragClone() const
998 {
999     // no need to really add the clone for dragging, it's a temporary
1000     // object
1001     SdrObject* pObj = new SdrUnoObj(String());
1002     *pObj = *((const SdrUnoObj*)this);
1003 
1004     return pObj;
1005 }
1006 
1007 //----------------------------------------------------------------------------
1008 
1009 void DlgEdObj::operator= (const SdrObject& rObj)
1010 {
1011     SdrUnoObj::operator= (rObj);
1012 }
1013 
1014 //----------------------------------------------------------------------------
1015 
1016 void DlgEdObj::NbcMove( const Size& rSize )
1017 {
1018     SdrUnoObj::NbcMove( rSize );
1019 
1020     // stop listening
1021     EndListening(sal_False);
1022 
1023     // set geometry properties
1024     SetPropsFromRect();
1025 
1026     // start listening
1027     StartListening();
1028 
1029     // dialog model changed
1030     GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(sal_True);
1031 }
1032 
1033 //----------------------------------------------------------------------------
1034 
1035 void DlgEdObj::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1036 {
1037     SdrUnoObj::NbcResize( rRef, xFract, yFract );
1038 
1039     // stop listening
1040     EndListening(sal_False);
1041 
1042     // set geometry properties
1043     SetPropsFromRect();
1044 
1045     // start listening
1046     StartListening();
1047 
1048     // dialog model changed
1049     GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(sal_True);
1050 }
1051 
1052 //----------------------------------------------------------------------------
1053 
1054 FASTBOOL DlgEdObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1055 {
1056     FASTBOOL bResult = SdrUnoObj::EndCreate(rStat, eCmd);
1057 
1058     SetDefaults();
1059     StartListening();
1060 
1061     return bResult;
1062 }
1063 
1064 //----------------------------------------------------------------------------
1065 
1066 void DlgEdObj::SetDefaults()
1067 {
1068     // set parent form
1069     pDlgEdForm = ((DlgEdPage*)GetPage())->GetDlgEdForm();
1070 
1071     if ( pDlgEdForm )
1072     {
1073         // add child to parent form
1074         pDlgEdForm->AddChild( this );
1075 
1076         Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
1077         if ( xPSet.is() )
1078         {
1079             // get unique name
1080             ::rtl::OUString aOUniqueName( GetUniqueName() );
1081 
1082             // set name property
1083             Any aUniqueName;
1084             aUniqueName <<= aOUniqueName;
1085             xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName );
1086 
1087             // set labels
1088             if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) ||
1089                 supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) ||
1090                 supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) ||
1091                 supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) ||
1092                 supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
1093             {
1094                 xPSet->setPropertyValue( DLGED_PROP_LABEL, aUniqueName );
1095             }
1096 
1097             // set number formats supplier for formatted field
1098             if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
1099             {
1100                 Reference< util::XNumberFormatsSupplier > xSupplier = GetDlgEdForm()->GetDlgEditor()->GetNumberFormatsSupplier();
1101                 if ( xSupplier.is() )
1102                 {
1103                     Any aSupplier;
1104                     aSupplier <<= xSupplier;
1105                     xPSet->setPropertyValue( DLGED_PROP_FORMATSSUPPLIER, aSupplier );
1106                 }
1107             }
1108 
1109             // set geometry properties
1110             SetPropsFromRect();
1111 
1112             Reference< container::XNameContainer > xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY );
1113             if ( xCont.is() )
1114             {
1115                 // set tabindex
1116                 Sequence< OUString > aNames = xCont->getElementNames();
1117                 uno::Any aTabIndex;
1118                 aTabIndex <<= (sal_Int16) aNames.getLength();
1119                 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
1120 
1121                 // set step
1122                 Reference< beans::XPropertySet > xPSetForm( xCont, UNO_QUERY );
1123                 if ( xPSetForm.is() )
1124                 {
1125                     Any aStep = xPSetForm->getPropertyValue( DLGED_PROP_STEP );
1126                     xPSet->setPropertyValue( DLGED_PROP_STEP, aStep );
1127                 }
1128 
1129                 // insert control model in dialog model
1130                 Reference< awt::XControlModel > xCtrl( xPSet , UNO_QUERY );
1131                 Any aAny;
1132                 aAny <<= xCtrl;
1133                 xCont->insertByName( aOUniqueName , aAny );
1134 
1135                 DlgEditor* pEditor;
1136                 if ( ISA(DlgEdForm) )
1137                     pEditor = ((DlgEdForm*)this)->GetDlgEditor();
1138                 else
1139                     pEditor = GetDlgEdForm()->GetDlgEditor();
1140                 LocalizationMgr::setControlResourceIDsForNewEditorObject( pEditor, aAny, aOUniqueName );
1141 
1142                 // #110559#
1143                 pDlgEdForm->UpdateTabOrderAndGroups();
1144             }
1145         }
1146 
1147         // dialog model changed
1148         pDlgEdForm->GetDlgEditor()->SetDialogModelChanged( sal_True );
1149     }
1150 }
1151 
1152 //----------------------------------------------------------------------------
1153 
1154 IMPL_LINK(DlgEdObj, OnCreate, void*, EMPTYTAG)
1155 {
1156     (void)EMPTYTAG;
1157     /*
1158     if (pTempView)
1159         pTempView->ObjectCreated(this);
1160     */
1161     return 0;
1162 }
1163 
1164 //----------------------------------------------------------------------------
1165 
1166 void DlgEdObj::StartListening()
1167 {
1168     DBG_ASSERT(!isListening(), "DlgEdObj::StartListening: already listening!");
1169 
1170     if (!isListening())
1171     {
1172         bIsListening = sal_True;
1173 
1174         // XPropertyChangeListener
1175         Reference< XPropertySet > xControlModel( GetUnoControlModel() , UNO_QUERY );
1176         if (!m_xPropertyChangeListener.is() && xControlModel.is())
1177         {
1178             // create listener
1179             m_xPropertyChangeListener = static_cast< ::com::sun::star::beans::XPropertyChangeListener*>( new DlgEdPropListenerImpl( (DlgEdObj*)this ) );
1180 
1181             // register listener to properties
1182             xControlModel->addPropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener );
1183         }
1184 
1185         // XContainerListener
1186         Reference< XScriptEventsSupplier > xEventsSupplier( GetUnoControlModel() , UNO_QUERY );
1187         if( !m_xContainerListener.is() && xEventsSupplier.is() )
1188         {
1189             // create listener
1190             m_xContainerListener = static_cast< ::com::sun::star::container::XContainerListener*>( new DlgEdEvtContListenerImpl( (DlgEdObj*)this ) );
1191 
1192             // register listener to script event container
1193             Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents();
1194             DBG_ASSERT(xEventCont.is(), "DlgEdObj::StartListening: control model has no script event container!");
1195             Reference< XContainer > xCont( xEventCont , UNO_QUERY );
1196             if (xCont.is())
1197                 xCont->addContainerListener( m_xContainerListener );
1198         }
1199     }
1200 }
1201 
1202 //----------------------------------------------------------------------------
1203 
1204 void DlgEdObj::EndListening(sal_Bool bRemoveListener)
1205 {
1206     DBG_ASSERT(isListening(), "DlgEdObj::EndListening: not listening currently!");
1207 
1208     if (isListening())
1209     {
1210         bIsListening = sal_False;
1211 
1212         if (bRemoveListener)
1213         {
1214             // XPropertyChangeListener
1215             Reference< XPropertySet > xControlModel(GetUnoControlModel(), UNO_QUERY);
1216             if ( m_xPropertyChangeListener.is() && xControlModel.is() )
1217             {
1218                 // remove listener
1219                 xControlModel->removePropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener );
1220             }
1221             m_xPropertyChangeListener.clear();
1222 
1223             // XContainerListener
1224             Reference< XScriptEventsSupplier > xEventsSupplier( GetUnoControlModel() , UNO_QUERY );
1225             if( m_xContainerListener.is() && xEventsSupplier.is() )
1226             {
1227                 // remove listener
1228                 Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents();
1229                 DBG_ASSERT(xEventCont.is(), "DlgEdObj::EndListening: control model has no script event container!");
1230                 Reference< XContainer > xCont( xEventCont , UNO_QUERY );
1231                 if (xCont.is())
1232                     xCont->removeContainerListener( m_xContainerListener );
1233             }
1234             m_xContainerListener.clear();
1235         }
1236     }
1237 }
1238 
1239 //----------------------------------------------------------------------------
1240 
1241 void SAL_CALL DlgEdObj::_propertyChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException)
1242 {
1243     if (isListening())
1244     {
1245         DlgEdForm* pRealDlgEdForm = dynamic_cast< DlgEdForm* >(this);
1246         if( pRealDlgEdForm == 0 )
1247             pRealDlgEdForm = GetDlgEdForm();
1248 
1249         DlgEditor* pDlgEditor = pRealDlgEdForm ? pRealDlgEdForm->GetDlgEditor() : 0;
1250 
1251         if( !pDlgEditor || pDlgEditor->isInPaint() )
1252             return;
1253 
1254         // dialog model changed
1255         pDlgEditor->SetDialogModelChanged(sal_True);
1256 
1257         // update position and size
1258         if ( evt.PropertyName == DLGED_PROP_POSITIONX || evt.PropertyName == DLGED_PROP_POSITIONY ||
1259              evt.PropertyName == DLGED_PROP_WIDTH || evt.PropertyName == DLGED_PROP_HEIGHT ||
1260              evt.PropertyName == DLGED_PROP_DECORATION )
1261         {
1262             PositionAndSizeChange( evt );
1263 
1264             if ( evt.PropertyName == DLGED_PROP_DECORATION )
1265             {
1266                 if ( ISA(DlgEdForm) )
1267                     ((DlgEdForm*)this)->GetDlgEditor()->ResetDialog();
1268                 else
1269                     GetDlgEdForm()->GetDlgEditor()->ResetDialog();
1270             }
1271         }
1272         // change name of control in dialog model
1273         else if ( evt.PropertyName == DLGED_PROP_NAME )
1274         {
1275             if ( !ISA(DlgEdForm) )
1276             {
1277                 NameChange(evt);
1278             }
1279         }
1280         // update step
1281         else if ( evt.PropertyName == DLGED_PROP_STEP )
1282         {
1283             UpdateStep();
1284         }
1285         // change tabindex
1286         else if ( evt.PropertyName == DLGED_PROP_TABINDEX )
1287         {
1288             if ( !ISA(DlgEdForm) )
1289             {
1290                 TabIndexChange(evt);
1291             }
1292         }
1293     }
1294 }
1295 
1296 //----------------------------------------------------------------------------
1297 
1298 void SAL_CALL DlgEdObj::_elementInserted(const ::com::sun::star::container::ContainerEvent& ) throw(::com::sun::star::uno::RuntimeException)
1299 {
1300     if (isListening())
1301     {
1302         // dialog model changed
1303         if ( ISA(DlgEdForm) )
1304         {
1305             ((DlgEdForm*)this)->GetDlgEditor()->SetDialogModelChanged(sal_True);
1306         }
1307         else
1308         {
1309             GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(sal_True);
1310         }
1311     }
1312 }
1313 
1314 //----------------------------------------------------------------------------
1315 
1316 void SAL_CALL DlgEdObj::_elementReplaced(const ::com::sun::star::container::ContainerEvent& ) throw(::com::sun::star::uno::RuntimeException)
1317 {
1318     if (isListening())
1319     {
1320         // dialog model changed
1321         if ( ISA(DlgEdForm) )
1322         {
1323             ((DlgEdForm*)this)->GetDlgEditor()->SetDialogModelChanged(sal_True);
1324         }
1325         else
1326         {
1327             GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(sal_True);
1328         }
1329     }
1330 }
1331 
1332 //----------------------------------------------------------------------------
1333 
1334 void SAL_CALL DlgEdObj::_elementRemoved(const ::com::sun::star::container::ContainerEvent& ) throw(::com::sun::star::uno::RuntimeException)
1335 {
1336     if (isListening())
1337     {
1338         // dialog model changed
1339         if ( ISA(DlgEdForm) )
1340         {
1341             ((DlgEdForm*)this)->GetDlgEditor()->SetDialogModelChanged(sal_True);
1342         }
1343         else
1344         {
1345             GetDlgEdForm()->GetDlgEditor()->SetDialogModelChanged(sal_True);
1346         }
1347     }
1348 }
1349 
1350 //----------------------------------------------------------------------------
1351 
1352 void DlgEdObj::SetLayer(SdrLayerID nLayer)
1353 {
1354     SdrLayerID nOldLayer = GetLayer();
1355 
1356     if ( nLayer != nOldLayer )
1357     {
1358         SdrUnoObj::SetLayer( nLayer );
1359 
1360         DlgEdHint aHint( DLGED_HINT_LAYERCHANGED, this );
1361         GetDlgEdForm()->GetDlgEditor()->Broadcast( aHint );
1362     }
1363 }
1364 
1365 //----------------------------------------------------------------------------
1366 
1367 TYPEINIT1(DlgEdForm, DlgEdObj);
1368 DBG_NAME(DlgEdForm);
1369 
1370 //----------------------------------------------------------------------------
1371 
1372 DlgEdForm::DlgEdForm()
1373           :DlgEdObj()
1374 {
1375     DBG_CTOR(DlgEdForm, NULL);
1376 }
1377 
1378 //----------------------------------------------------------------------------
1379 
1380 DlgEdForm::~DlgEdForm()
1381 {
1382     DBG_DTOR(DlgEdForm, NULL);
1383 }
1384 
1385 //----------------------------------------------------------------------------
1386 
1387 void DlgEdForm::SetDlgEditor( DlgEditor* pEditor )
1388 {
1389     pDlgEditor = pEditor;
1390     ImplInvalidateDeviceInfo();
1391 }
1392 
1393 //----------------------------------------------------------------------------
1394 
1395 void DlgEdForm::ImplInvalidateDeviceInfo()
1396 {
1397     mpDeviceInfo.reset();
1398 }
1399 
1400 //----------------------------------------------------------------------------
1401 
1402 void DlgEdForm::SetRectFromProps()
1403 {
1404     // get form position and size from properties
1405     Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
1406     if ( xPSet.is() )
1407     {
1408         sal_Int32 nXIn = 0, nYIn = 0, nWidthIn = 0, nHeightIn = 0;
1409         xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nXIn;
1410         xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nYIn;
1411         xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidthIn;
1412         xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeightIn;
1413 
1414         // transform coordinates
1415         sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
1416         if ( TransformFormToSdrCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
1417         {
1418             // set rectangle position and size
1419             Point aPoint( nXOut, nYOut );
1420             Size aSize( nWidthOut, nHeightOut );
1421             SetSnapRect( Rectangle( aPoint, aSize ) );
1422         }
1423     }
1424 }
1425 
1426 //----------------------------------------------------------------------------
1427 
1428 void DlgEdForm::SetPropsFromRect()
1429 {
1430     // get form position and size from rectangle
1431     Rectangle aRect_ = GetSnapRect();
1432     sal_Int32 nXIn = aRect_.Left();
1433     sal_Int32 nYIn = aRect_.Top();
1434     sal_Int32 nWidthIn = aRect_.GetWidth();
1435     sal_Int32 nHeightIn = aRect_.GetHeight();
1436 
1437     // transform coordinates
1438     sal_Int32 nXOut, nYOut, nWidthOut, nHeightOut;
1439     if ( TransformSdrToFormCoordinates( nXIn, nYIn, nWidthIn, nHeightIn, nXOut, nYOut, nWidthOut, nHeightOut ) )
1440     {
1441         // set properties
1442         Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
1443         if ( xPSet.is() )
1444         {
1445             Any aValue;
1446             aValue <<= nXOut;
1447             xPSet->setPropertyValue( DLGED_PROP_POSITIONX, aValue );
1448             aValue <<= nYOut;
1449             xPSet->setPropertyValue( DLGED_PROP_POSITIONY, aValue );
1450             aValue <<= nWidthOut;
1451             xPSet->setPropertyValue( DLGED_PROP_WIDTH, aValue );
1452             aValue <<= nHeightOut;
1453             xPSet->setPropertyValue( DLGED_PROP_HEIGHT, aValue );
1454         }
1455     }
1456 }
1457 
1458 //----------------------------------------------------------------------------
1459 
1460 void DlgEdForm::AddChild( DlgEdObj* pDlgEdObj )
1461 {
1462     pChilds.push_back( pDlgEdObj );
1463 }
1464 
1465 //----------------------------------------------------------------------------
1466 
1467 void DlgEdForm::RemoveChild( DlgEdObj* pDlgEdObj )
1468 {
1469     pChilds.erase( ::std::find( pChilds.begin() , pChilds.end() , pDlgEdObj ) );
1470 }
1471 
1472 //----------------------------------------------------------------------------
1473 
1474 void DlgEdForm::PositionAndSizeChange( const beans::PropertyChangeEvent& evt )
1475 {
1476     DlgEditor* pEditor = GetDlgEditor();
1477     DBG_ASSERT( pEditor, "DlgEdForm::PositionAndSizeChange: no dialog editor!" );
1478     if ( pEditor )
1479     {
1480         DlgEdPage* pPage_ = pEditor->GetPage();
1481         DBG_ASSERT( pPage_, "DlgEdForm::PositionAndSizeChange: no page!" );
1482         if ( pPage_ )
1483         {
1484             sal_Int32 nPageXIn = 0;
1485             sal_Int32 nPageYIn = 0;
1486             Size aPageSize = pPage_->GetSize();
1487             sal_Int32 nPageWidthIn = aPageSize.Width();
1488             sal_Int32 nPageHeightIn = aPageSize.Height();
1489             sal_Int32 nPageX, nPageY, nPageWidth, nPageHeight;
1490             if ( TransformSdrToFormCoordinates( nPageXIn, nPageYIn, nPageWidthIn, nPageHeightIn, nPageX, nPageY, nPageWidth, nPageHeight ) )
1491             {
1492                 Reference< beans::XPropertySet > xPSetForm( GetUnoControlModel(), UNO_QUERY );
1493                 if ( xPSetForm.is() )
1494                 {
1495                     sal_Int32 nValue = 0;
1496                     evt.NewValue >>= nValue;
1497                     sal_Int32 nNewValue = nValue;
1498 
1499                     if ( evt.PropertyName == DLGED_PROP_POSITIONX )
1500                     {
1501                         if ( nNewValue < nPageX )
1502                             nNewValue = nPageX;
1503                     }
1504                     else if ( evt.PropertyName == DLGED_PROP_POSITIONY )
1505                     {
1506                         if ( nNewValue < nPageY )
1507                             nNewValue = nPageY;
1508                     }
1509                     else if ( evt.PropertyName == DLGED_PROP_WIDTH )
1510                     {
1511                         if ( nNewValue < 1 )
1512                             nNewValue = 1;
1513                     }
1514                     else if ( evt.PropertyName == DLGED_PROP_HEIGHT )
1515                     {
1516                         if ( nNewValue < 1 )
1517                             nNewValue = 1;
1518                     }
1519 
1520                     if ( nNewValue != nValue )
1521                     {
1522                         Any aNewValue;
1523                         aNewValue <<= nNewValue;
1524                         EndListening( sal_False );
1525                         xPSetForm->setPropertyValue( evt.PropertyName, aNewValue );
1526                         StartListening();
1527                     }
1528                 }
1529             }
1530 
1531             bool bAdjustedPageSize = pEditor->AdjustPageSize();
1532             SetRectFromProps();
1533             ::std::vector< DlgEdObj* >::iterator aIter;
1534             ::std::vector< DlgEdObj* > aChildList = ((DlgEdForm*)this)->GetChilds();
1535 
1536             if ( bAdjustedPageSize )
1537             {
1538                 pEditor->InitScrollBars();
1539                 aPageSize = pPage_->GetSize();
1540                 nPageWidthIn = aPageSize.Width();
1541                 nPageHeightIn = aPageSize.Height();
1542                 if ( TransformSdrToControlCoordinates( nPageXIn, nPageYIn, nPageWidthIn, nPageHeightIn, nPageX, nPageY, nPageWidth, nPageHeight ) )
1543                 {
1544                     for ( aIter = aChildList.begin(); aIter != aChildList.end(); aIter++ )
1545                     {
1546                         Reference< beans::XPropertySet > xPSet( (*aIter)->GetUnoControlModel(), UNO_QUERY );
1547                         if ( xPSet.is() )
1548                         {
1549                             sal_Int32 nX = 0, nY = 0, nWidth = 0, nHeight = 0;
1550                             xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nX;
1551                             xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nY;
1552                             xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidth;
1553                             xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeight;
1554 
1555                             sal_Int32 nNewX = nX;
1556                             if ( nX + nWidth > nPageX + nPageWidth )
1557                             {
1558                                 nNewX = nPageX + nPageWidth - nWidth;
1559                                 if ( nNewX < nPageX )
1560                                     nNewX = nPageX;
1561                             }
1562                             if ( nNewX != nX )
1563                             {
1564                                 Any aValue;
1565                                 aValue <<= nNewX;
1566                                 EndListening( sal_False );
1567                                 xPSet->setPropertyValue( DLGED_PROP_POSITIONX, aValue );
1568                                 StartListening();
1569                             }
1570 
1571                             sal_Int32 nNewY = nY;
1572                             if ( nY + nHeight > nPageY + nPageHeight )
1573                             {
1574                                 nNewY = nPageY + nPageHeight - nHeight;
1575                                 if ( nNewY < nPageY )
1576                                     nNewY = nPageY;
1577                             }
1578                             if ( nNewY != nY )
1579                             {
1580                                 Any aValue;
1581                                 aValue <<= nNewY;
1582                                 EndListening( sal_False );
1583                                 xPSet->setPropertyValue( DLGED_PROP_POSITIONY, aValue );
1584                                 StartListening();
1585                             }
1586                         }
1587                     }
1588                 }
1589             }
1590 
1591             for ( aIter = aChildList.begin(); aIter != aChildList.end(); aIter++ )
1592             {
1593                 (*aIter)->SetRectFromProps();
1594             }
1595         }
1596     }
1597 }
1598 
1599 //----------------------------------------------------------------------------
1600 
1601 void DlgEdForm::UpdateStep()
1602 {
1603     sal_uLong nObjCount;
1604     SdrPage* pSdrPage = GetPage();
1605 
1606     if ( pSdrPage && ( ( nObjCount = pSdrPage->GetObjCount() ) > 0 ) )
1607     {
1608         for ( sal_uLong i = 0 ; i < nObjCount ; i++ )
1609         {
1610             SdrObject* pObj = pSdrPage->GetObj(i);
1611             DlgEdObj* pDlgEdObj = PTR_CAST(DlgEdObj, pObj);
1612             if ( pDlgEdObj && !pDlgEdObj->ISA(DlgEdForm) )
1613                 pDlgEdObj->UpdateStep();
1614         }
1615     }
1616 }
1617 
1618 //----------------------------------------------------------------------------
1619 
1620 void DlgEdForm::UpdateTabIndices()
1621 {
1622     // stop listening with all children
1623     ::std::vector<DlgEdObj*>::iterator aIter;
1624     for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; ++aIter )
1625     {
1626         (*aIter)->EndListening( sal_False );
1627     }
1628 
1629     Reference< ::com::sun::star::container::XNameAccess > xNameAcc( GetUnoControlModel() , UNO_QUERY );
1630     if ( xNameAcc.is() )
1631     {
1632         // get sequence of control names
1633         Sequence< ::rtl::OUString > aNames = xNameAcc->getElementNames();
1634         const ::rtl::OUString* pNames = aNames.getConstArray();
1635         sal_Int32 nCtrls = aNames.getLength();
1636 
1637         // create a map of tab indices and control names, sorted by tab index
1638         IndexToNameMap aIndexToNameMap;
1639         for ( sal_Int16 i = 0; i < nCtrls; ++i )
1640         {
1641             // get name
1642             ::rtl::OUString aName( pNames[i] );
1643 
1644             // get tab index
1645             sal_Int16 nTabIndex = -1;
1646             Any aCtrl = xNameAcc->getByName( aName );
1647             Reference< ::com::sun::star::beans::XPropertySet > xPSet;
1648             aCtrl >>= xPSet;
1649             if ( xPSet.is() )
1650                 xPSet->getPropertyValue( DLGED_PROP_TABINDEX ) >>= nTabIndex;
1651 
1652             // insert into map
1653             aIndexToNameMap.insert( IndexToNameMap::value_type( nTabIndex, aName ) );
1654         }
1655 
1656         // set new tab indices
1657         sal_Int16 nNewTabIndex = 0;
1658         for ( IndexToNameMap::iterator aIt = aIndexToNameMap.begin(); aIt != aIndexToNameMap.end(); ++aIt )
1659         {
1660             Any aCtrl = xNameAcc->getByName( aIt->second );
1661             Reference< beans::XPropertySet > xPSet;
1662             aCtrl >>= xPSet;
1663             if ( xPSet.is() )
1664             {
1665                 Any aTabIndex;
1666                 aTabIndex <<= (sal_Int16) nNewTabIndex++;
1667                 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
1668             }
1669         }
1670 
1671         // #110559#
1672         UpdateTabOrderAndGroups();
1673     }
1674 
1675     // start listening with all children
1676     for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; ++aIter )
1677     {
1678         (*aIter)->StartListening();
1679     }
1680 }
1681 
1682 //----------------------------------------------------------------------------
1683 
1684 void DlgEdForm::UpdateTabOrder()
1685 {
1686     // #110559#
1687     // When the tabindex of a control model changes, the dialog control is
1688     // notified about those changes. Due to #109067# (bad performance of
1689     // dialog editor) the dialog control doesn't activate the tab order
1690     // in design mode. When the dialog editor has reordered all
1691     // tabindices, this method allows to activate the taborder afterwards.
1692 
1693     Reference< awt::XUnoControlContainer > xCont( GetControl(), UNO_QUERY );
1694     if ( xCont.is() )
1695     {
1696         Sequence< Reference< awt::XTabController > > aSeqTabCtrls = xCont->getTabControllers();
1697         const Reference< awt::XTabController >* pTabCtrls = aSeqTabCtrls.getConstArray();
1698         sal_Int32 nCount = aSeqTabCtrls.getLength();
1699         for ( sal_Int32 i = 0; i < nCount; ++i )
1700             pTabCtrls[i]->activateTabOrder();
1701     }
1702 }
1703 
1704 //----------------------------------------------------------------------------
1705 
1706 void DlgEdForm::UpdateGroups()
1707 {
1708     // #110559#
1709     // The grouping of radio buttons in a dialog is done by vcl.
1710     // In the dialog editor we have two views (=controls) for one
1711     // radio button model. One control is owned by the dialog control,
1712     // but not visible in design mode. The other control is owned by
1713     // the drawing layer object. Whereas the grouping of the first
1714     // control is done by vcl, the grouping of the control in the
1715     // drawing layer has to be done here.
1716 
1717     Reference< awt::XTabControllerModel > xTabModel( GetUnoControlModel() , UNO_QUERY );
1718     if ( xTabModel.is() )
1719     {
1720         // create a global list of controls that belong to the dialog
1721         ::std::vector<DlgEdObj*> aChildList = GetChilds();
1722         sal_uInt32 nSize = aChildList.size();
1723         Sequence< Reference< awt::XControl > > aSeqControls( nSize );
1724         for ( sal_uInt32 i = 0; i < nSize; ++i )
1725             aSeqControls.getArray()[i] = Reference< awt::XControl >( aChildList[i]->GetControl(), UNO_QUERY );
1726 
1727         sal_Int32 nGroupCount = xTabModel->getGroupCount();
1728         for ( sal_Int32 nGroup = 0; nGroup < nGroupCount; ++nGroup )
1729         {
1730             // get a list of control models that belong to this group
1731             ::rtl::OUString aName;
1732             Sequence< Reference< awt::XControlModel > > aSeqModels;
1733             xTabModel->getGroup( nGroup, aSeqModels, aName );
1734             const Reference< awt::XControlModel >* pModels = aSeqModels.getConstArray();
1735             sal_Int32 nModelCount = aSeqModels.getLength();
1736 
1737             // create a list of peers that belong to this group
1738             Sequence< Reference< awt::XWindow > > aSeqPeers( nModelCount );
1739             for ( sal_Int32 nModel = 0; nModel < nModelCount; ++nModel )
1740             {
1741                 // for each control model find the corresponding control in the global list
1742                 const Reference< awt::XControl >* pControls = aSeqControls.getConstArray();
1743                 sal_Int32 nControlCount = aSeqControls.getLength();
1744                 for ( sal_Int32 nControl = 0; nControl < nControlCount; ++nControl )
1745                 {
1746                     const Reference< awt::XControl > xCtrl( pControls[nControl] );
1747                     if ( xCtrl.is() )
1748                     {
1749                         Reference< awt::XControlModel > xCtrlModel( xCtrl->getModel() );
1750                         if ( (awt::XControlModel*)xCtrlModel.get() == (awt::XControlModel*)pModels[nModel].get() )
1751                         {
1752                             // get the control peer and insert into the list of peers
1753                             aSeqPeers.getArray()[ nModel ] = Reference< awt::XWindow >( xCtrl->getPeer(), UNO_QUERY );
1754                             break;
1755                         }
1756                     }
1757                 }
1758             }
1759 
1760             // set the group at the dialog peer
1761             Reference< awt::XControl > xDlg( GetControl(), UNO_QUERY );
1762             if ( xDlg.is() )
1763             {
1764                 Reference< awt::XVclContainerPeer > xDlgPeer( xDlg->getPeer(), UNO_QUERY );
1765                 if ( xDlgPeer.is() )
1766                     xDlgPeer->setGroup( aSeqPeers );
1767             }
1768         }
1769     }
1770 }
1771 
1772 //----------------------------------------------------------------------------
1773 
1774 void DlgEdForm::UpdateTabOrderAndGroups()
1775 {
1776     UpdateTabOrder();
1777     UpdateGroups();
1778 }
1779 
1780 //----------------------------------------------------------------------------
1781 
1782 void DlgEdForm::NbcMove( const Size& rSize )
1783 {
1784     SdrUnoObj::NbcMove( rSize );
1785 
1786     // set geometry properties of form
1787     EndListening(sal_False);
1788     SetPropsFromRect();
1789     StartListening();
1790 
1791     // set geometry properties of all childs
1792     ::std::vector<DlgEdObj*>::iterator aIter;
1793     for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; aIter++ )
1794     {
1795         (*aIter)->EndListening(sal_False);
1796         (*aIter)->SetPropsFromRect();
1797         (*aIter)->StartListening();
1798     }
1799 
1800     // dialog model changed
1801     GetDlgEditor()->SetDialogModelChanged(sal_True);
1802 }
1803 
1804 //----------------------------------------------------------------------------
1805 
1806 void DlgEdForm::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1807 {
1808     SdrUnoObj::NbcResize( rRef, xFract, yFract );
1809 
1810     // set geometry properties of form
1811     EndListening(sal_False);
1812     SetPropsFromRect();
1813     StartListening();
1814 
1815     // set geometry properties of all childs
1816     ::std::vector<DlgEdObj*>::iterator aIter;
1817     for ( aIter = pChilds.begin() ; aIter != pChilds.end() ; aIter++ )
1818     {
1819         (*aIter)->EndListening(sal_False);
1820         (*aIter)->SetPropsFromRect();
1821         (*aIter)->StartListening();
1822     }
1823 
1824     // dialog model changed
1825     GetDlgEditor()->SetDialogModelChanged(sal_True);
1826 }
1827 
1828 //----------------------------------------------------------------------------
1829 
1830 FASTBOOL DlgEdForm::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1831 {
1832     FASTBOOL bResult = SdrUnoObj::EndCreate(rStat, eCmd);
1833 
1834     // stop listening
1835     EndListening(sal_False);
1836 
1837     // set geometry properties
1838     SetPropsFromRect();
1839 
1840     // dialog model changed
1841     GetDlgEditor()->SetDialogModelChanged(sal_True);
1842 
1843     // start listening
1844     StartListening();
1845 
1846     return bResult;
1847 }
1848 
1849 //----------------------------------------------------------------------------
1850 
1851 awt::DeviceInfo DlgEdForm::getDeviceInfo() const
1852 {
1853     awt::DeviceInfo aDeviceInfo;
1854 
1855     DlgEditor* pEditor = GetDlgEditor();
1856     DBG_ASSERT( pEditor, "DlgEdForm::getDeviceInfo: no editor associated with the form object!" );
1857     if ( !pEditor )
1858         return aDeviceInfo;
1859 
1860     Window* pWindow = pEditor->GetWindow();
1861     DBG_ASSERT( pWindow, "DlgEdForm::getDeviceInfo: no window associated with the editor!" );
1862     if ( !pWindow )
1863         return aDeviceInfo;
1864 
1865     // obtain an XControl
1866     ::utl::SharedUNOComponent< awt::XControl > xDialogControl; // ensures auto-disposal, if needed
1867     xDialogControl.reset( GetControl(), ::utl::SharedUNOComponent< awt::XControl >::NoTakeOwnership );
1868     if ( !xDialogControl.is() )
1869     {
1870         // don't create a temporary control all the time, this method here is called
1871         // way too often. Instead, use a cached DeviceInfo.
1872         // 2007-02-05 / i74065 / frank.schoenheit@sun.com
1873         if ( !!mpDeviceInfo )
1874             return *mpDeviceInfo;
1875 
1876         Reference< awt::XControlContainer > xEditorControlContainer( pEditor->GetWindowControlContainer() );
1877         xDialogControl.reset(
1878             GetTemporaryControlForWindow( *pWindow, xEditorControlContainer ),
1879             ::utl::SharedUNOComponent< awt::XControl >::TakeOwnership );
1880     }
1881 
1882     Reference< awt::XDevice > xDialogDevice;
1883     if ( xDialogControl.is() )
1884         xDialogDevice.set( xDialogControl->getPeer(), UNO_QUERY );
1885     DBG_ASSERT( xDialogDevice.is(), "DlgEdForm::getDeviceInfo: no device!" );
1886     if ( xDialogDevice.is() )
1887         aDeviceInfo = xDialogDevice->getInfo();
1888 
1889     mpDeviceInfo.reset( aDeviceInfo );
1890 
1891     return aDeviceInfo;
1892 }
1893 
1894 //----------------------------------------------------------------------------
1895 
1896 
1897