1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "dlgeddef.hxx"
22 #include "dlgedlist.hxx"
23 #include "dlgedobj.hxx"
24 #include "dlgedpage.hxx"
25 #include "dlgedview.hxx"
27 #include "localizationmgr.hxx"
29 #include "dlgresid.hrc"
31 #include <com/sun/star/form/binding/XBindableValue.hpp>
32 #include <com/sun/star/form/binding/XValueBinding.hpp>
33 #include <com/sun/star/form/binding/XListEntrySink.hpp>
34 #include <com/sun/star/awt/XUnoControlContainer.hpp>
35 #include <com/sun/star/awt/XVclContainerPeer.hpp>
36 #include <com/sun/star/container/XContainer.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
39 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
40 #include <o3tl/compat_functional.hxx>
41 #include <unotools/sharedunocomponent.hxx>
42 #include <vcl/svapp.hxx>
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::container
;
51 using namespace ::com::sun::star::script
;
53 TYPEINIT1(DlgEdObj
, SdrUnoObj
);
55 DlgEditor
& DlgEdObj::GetDialogEditor ()
57 if (DlgEdForm
* pFormThis
= dynamic_cast<DlgEdForm
*>(this))
58 return pFormThis
->GetDlgEditor();
60 return pDlgEdForm
->GetDlgEditor();
64 :SdrUnoObj(OUString(), false)
70 DlgEdObj::DlgEdObj(const OUString
& rModelName
,
71 const com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
>& rxSFac
)
72 :SdrUnoObj(rModelName
, rxSFac
, false)
84 void DlgEdObj::SetPage(SdrPage
* _pNewPage
)
87 SdrUnoObj::SetPage(_pNewPage
);
92 /* returns the DlgEdForm which the given DlgEdObj belongs to
93 (which might in fact be the object itself)
95 Failure to obtain the form will be reported with an assertion in the non-product
98 bool lcl_getDlgEdForm( DlgEdObj
* _pObject
, DlgEdForm
*& _out_pDlgEdForm
)
100 _out_pDlgEdForm
= dynamic_cast< DlgEdForm
* >( _pObject
);
101 if ( !_out_pDlgEdForm
)
102 _out_pDlgEdForm
= _pObject
->GetDlgEdForm();
103 DBG_ASSERT( _out_pDlgEdForm
, "lcl_getDlgEdForm: no form!" );
104 return ( _out_pDlgEdForm
!= NULL
);
108 uno::Reference
< awt::XControl
> DlgEdObj::GetControl() const
110 uno::Reference
< awt::XControl
> xControl
;
111 if (DlgEdForm
const* pForm
= GetDlgEdForm())
113 DlgEditor
const& rEditor
= pForm
->GetDlgEditor();
114 xControl
= GetUnoControl(rEditor
.GetView(), rEditor
.GetWindow());
119 bool DlgEdObj::TransformSdrToControlCoordinates(
120 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
121 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
123 // input position and size
124 Size
aPos( nXIn
, nYIn
);
125 Size
aSize( nWidthIn
, nHeightIn
);
128 DlgEdForm
* pForm
= NULL
;
129 if ( !lcl_getDlgEdForm( this, pForm
) )
131 Rectangle aFormRect
= pForm
->GetSnapRect();
132 Size
aFormPos( aFormRect
.Left(), aFormRect
.Top() );
134 // convert 100th_mm to pixel
135 OutputDevice
* pDevice
= Application::GetDefaultDevice();
136 DBG_ASSERT( pDevice
, "DlgEdObj::TransformSdrToControlCoordinates: missing default device!" );
139 aPos
= pDevice
->LogicToPixel( aPos
, MapMode( MAP_100TH_MM
) );
140 aSize
= pDevice
->LogicToPixel( aSize
, MapMode( MAP_100TH_MM
) );
141 aFormPos
= pDevice
->LogicToPixel( aFormPos
, MapMode( MAP_100TH_MM
) );
143 // subtract form position
144 aPos
.Width() -= aFormPos
.Width();
145 aPos
.Height() -= aFormPos
.Height();
147 // take window borders into account
148 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
149 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
150 if ( !xPSetForm
.is() )
152 bool bDecoration
= true;
153 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
156 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
157 aPos
.Width() -= aDeviceInfo
.LeftInset
;
158 aPos
.Height() -= aDeviceInfo
.TopInset
;
161 // convert pixel to logic units
162 aPos
= pDevice
->PixelToLogic( aPos
, MAP_APPFONT
);
163 aSize
= pDevice
->PixelToLogic( aSize
, MAP_APPFONT
);
165 // set out parameters
166 nXOut
= aPos
.Width();
167 nYOut
= aPos
.Height();
168 nWidthOut
= aSize
.Width();
169 nHeightOut
= aSize
.Height();
174 bool DlgEdObj::TransformSdrToFormCoordinates(
175 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
176 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
178 // input position and size
179 Size
aPos( nXIn
, nYIn
);
180 Size
aSize( nWidthIn
, nHeightIn
);
182 // convert 100th_mm to pixel
183 OutputDevice
* pDevice
= Application::GetDefaultDevice();
184 DBG_ASSERT( pDevice
, "DlgEdObj::TransformSdrToFormCoordinates: missing default device!" );
187 aPos
= pDevice
->LogicToPixel( aPos
, MapMode( MAP_100TH_MM
) );
188 aSize
= pDevice
->LogicToPixel( aSize
, MapMode( MAP_100TH_MM
) );
190 // take window borders into account
191 DlgEdForm
* pForm
= NULL
;
192 if ( !lcl_getDlgEdForm( this, pForm
) )
195 // take window borders into account
196 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
197 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
198 if ( !xPSetForm
.is() )
200 bool bDecoration
= true;
201 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
204 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
205 aSize
.Width() -= aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
;
206 aSize
.Height() -= aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
;
208 // convert pixel to logic units
209 aPos
= pDevice
->PixelToLogic( aPos
, MAP_APPFONT
);
210 aSize
= pDevice
->PixelToLogic( aSize
, MAP_APPFONT
);
212 // set out parameters
213 nXOut
= aPos
.Width();
214 nYOut
= aPos
.Height();
215 nWidthOut
= aSize
.Width();
216 nHeightOut
= aSize
.Height();
221 bool DlgEdObj::TransformControlToSdrCoordinates(
222 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
223 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
225 // input position and size
226 Size
aPos( nXIn
, nYIn
);
227 Size
aSize( nWidthIn
, nHeightIn
);
230 DlgEdForm
* pForm
= NULL
;
231 if ( !lcl_getDlgEdForm( this, pForm
) )
234 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
235 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformControlToSdrCoordinates: no form property set!" );
236 if ( !xPSetForm
.is() )
238 sal_Int32 nFormX
= 0, nFormY
= 0, nFormWidth
, nFormHeight
;
239 xPSetForm
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nFormX
;
240 xPSetForm
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nFormY
;
241 xPSetForm
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nFormWidth
;
242 xPSetForm
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nFormHeight
;
243 Size
aFormPos( nFormX
, nFormY
);
245 // convert logic units to pixel
246 OutputDevice
* pDevice
= Application::GetDefaultDevice();
247 DBG_ASSERT( pDevice
, "DlgEdObj::TransformControlToSdrCoordinates: missing default device!" );
250 aPos
= pDevice
->LogicToPixel( aPos
, MAP_APPFONT
);
251 aSize
= pDevice
->LogicToPixel( aSize
, MAP_APPFONT
);
252 aFormPos
= pDevice
->LogicToPixel( aFormPos
, MAP_APPFONT
);
255 aPos
.Width() += aFormPos
.Width();
256 aPos
.Height() += aFormPos
.Height();
258 // take window borders into account
259 bool bDecoration
= true;
260 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
263 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
264 aPos
.Width() += aDeviceInfo
.LeftInset
;
265 aPos
.Height() += aDeviceInfo
.TopInset
;
268 // convert pixel to 100th_mm
269 aPos
= pDevice
->PixelToLogic( aPos
, MapMode( MAP_100TH_MM
) );
270 aSize
= pDevice
->PixelToLogic( aSize
, MapMode( MAP_100TH_MM
) );
272 // set out parameters
273 nXOut
= aPos
.Width();
274 nYOut
= aPos
.Height();
275 nWidthOut
= aSize
.Width();
276 nHeightOut
= aSize
.Height();
281 bool DlgEdObj::TransformFormToSdrCoordinates(
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 // convert logic units to pixel
290 OutputDevice
* pDevice
= Application::GetDefaultDevice();
291 DBG_ASSERT( pDevice
, "DlgEdObj::TransformFormToSdrCoordinates: missing default device!" );
295 // take window borders into account
296 DlgEdForm
* pForm
= NULL
;
297 if ( !lcl_getDlgEdForm( this, pForm
) )
300 aPos
= pDevice
->LogicToPixel( aPos
, MAP_APPFONT
);
301 aSize
= pDevice
->LogicToPixel( aSize
, MAP_APPFONT
);
303 // take window borders into account
304 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
305 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
306 if ( !xPSetForm
.is() )
308 bool bDecoration
= true;
309 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
312 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
313 aSize
.Width() += aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
;
314 aSize
.Height() += aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
;
317 // convert pixel to 100th_mm
318 aPos
= pDevice
->PixelToLogic( aPos
, MapMode( MAP_100TH_MM
) );
319 aSize
= pDevice
->PixelToLogic( aSize
, MapMode( MAP_100TH_MM
) );
321 // set out parameters
322 nXOut
= aPos
.Width();
323 nYOut
= aPos
.Height();
324 nWidthOut
= aSize
.Width();
325 nHeightOut
= aSize
.Height();
330 void DlgEdObj::SetRectFromProps()
332 // get control position and size from properties
333 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
336 sal_Int32 nXIn
= 0, nYIn
= 0, nWidthIn
= 0, nHeightIn
= 0;
337 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nXIn
;
338 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nYIn
;
339 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidthIn
;
340 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeightIn
;
342 // transform coordinates
343 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
344 if ( TransformControlToSdrCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
346 // set rectangle position and size
347 Point
aPoint( nXOut
, nYOut
);
348 Size
aSize( nWidthOut
, nHeightOut
);
349 SetSnapRect( Rectangle( aPoint
, aSize
) );
354 void DlgEdObj::SetPropsFromRect()
356 // get control position and size from rectangle
357 Rectangle aRect_
= GetSnapRect();
358 sal_Int32 nXIn
= aRect_
.Left();
359 sal_Int32 nYIn
= aRect_
.Top();
360 sal_Int32 nWidthIn
= aRect_
.GetWidth();
361 sal_Int32 nHeightIn
= aRect_
.GetHeight();
363 // transform coordinates
364 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
365 if ( TransformSdrToControlCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
368 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
373 xPSet
->setPropertyValue( DLGED_PROP_POSITIONX
, aValue
);
375 xPSet
->setPropertyValue( DLGED_PROP_POSITIONY
, aValue
);
376 aValue
<<= nWidthOut
;
377 xPSet
->setPropertyValue( DLGED_PROP_WIDTH
, aValue
);
378 aValue
<<= nHeightOut
;
379 xPSet
->setPropertyValue( DLGED_PROP_HEIGHT
, aValue
);
384 void DlgEdObj::PositionAndSizeChange( const beans::PropertyChangeEvent
& evt
)
386 DBG_ASSERT( pDlgEdForm
, "DlgEdObj::PositionAndSizeChange: no form!" );
387 DlgEdPage
& rPage
= pDlgEdForm
->GetDlgEditor().GetPage();
389 sal_Int32 nPageXIn
= 0;
390 sal_Int32 nPageYIn
= 0;
391 Size aPageSize
= rPage
.GetSize();
392 sal_Int32 nPageWidthIn
= aPageSize
.Width();
393 sal_Int32 nPageHeightIn
= aPageSize
.Height();
394 sal_Int32 nPageX
, nPageY
, nPageWidth
, nPageHeight
;
395 if ( TransformSdrToControlCoordinates( nPageXIn
, nPageYIn
, nPageWidthIn
, nPageHeightIn
, nPageX
, nPageY
, nPageWidth
, nPageHeight
) )
397 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
400 sal_Int32 nX
= 0, nY
= 0, nWidth
= 0, nHeight
= 0;
401 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nX
;
402 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nY
;
403 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidth
;
404 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeight
;
406 sal_Int32 nValue
= 0;
407 evt
.NewValue
>>= nValue
;
408 sal_Int32 nNewValue
= nValue
;
410 if ( evt
.PropertyName
== DLGED_PROP_POSITIONX
)
412 if ( nNewValue
+ nWidth
> nPageX
+ nPageWidth
)
413 nNewValue
= nPageX
+ nPageWidth
- nWidth
;
414 if ( nNewValue
< nPageX
)
417 else if ( evt
.PropertyName
== DLGED_PROP_POSITIONY
)
419 if ( nNewValue
+ nHeight
> nPageY
+ nPageHeight
)
420 nNewValue
= nPageY
+ nPageHeight
- nHeight
;
421 if ( nNewValue
< nPageY
)
424 else if ( evt
.PropertyName
== DLGED_PROP_WIDTH
)
426 if ( nX
+ nNewValue
> nPageX
+ nPageWidth
)
427 nNewValue
= nPageX
+ nPageWidth
- nX
;
431 else if ( evt
.PropertyName
== DLGED_PROP_HEIGHT
)
433 if ( nY
+ nNewValue
> nPageY
+ nPageHeight
)
434 nNewValue
= nPageY
+ nPageHeight
- nY
;
439 if ( nNewValue
!= nValue
)
442 aNewValue
<<= nNewValue
;
443 EndListening( false );
444 xPSet
->setPropertyValue( evt
.PropertyName
, aNewValue
);
454 void SAL_CALL
DlgEdObj::NameChange( const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw (css::container::NoSuchElementException
, css::uno::RuntimeException
)
458 evt
.OldValue
>>= aOldName
;
462 evt
.NewValue
>>= aNewName
;
464 if ( !aNewName
.equals(aOldName
) )
466 Reference
< container::XNameAccess
> xNameAcc((GetDlgEdForm()->GetUnoControlModel()), UNO_QUERY
);
467 if ( xNameAcc
.is() && xNameAcc
->hasByName(aOldName
) )
469 if (!xNameAcc
->hasByName(aNewName
) && !aNewName
.isEmpty())
471 // remove the control by the old name and insert the control by the new name in the container
472 Reference
< container::XNameContainer
> xCont(xNameAcc
, UNO_QUERY
);
475 Reference
< awt::XControlModel
> xCtrl(GetUnoControlModel(), UNO_QUERY
);
478 xCont
->removeByName( aOldName
);
479 xCont
->insertByName( aNewName
, aAny
);
481 LocalizationMgr::renameControlResourceIDsForEditorObject(
482 &GetDialogEditor(), aAny
, aNewName
488 // set old name property
490 Reference
< beans::XPropertySet
> xPSet(GetUnoControlModel(), UNO_QUERY
);
493 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aName
);
500 sal_Int32
DlgEdObj::GetStep() const
504 uno::Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), uno::UNO_QUERY
);
507 xPSet
->getPropertyValue( DLGED_PROP_STEP
) >>= nStep
;
512 void DlgEdObj::UpdateStep()
514 sal_Int32 nCurStep
= GetDlgEdForm()->GetStep();
515 sal_Int32 nStep
= GetStep();
517 SdrLayerAdmin
& rLayerAdmin
= GetModel()->GetLayerAdmin();
518 SdrLayerID nHiddenLayerId
= rLayerAdmin
.GetLayerID( OUString( "HiddenLayer" ), false );
519 SdrLayerID nControlLayerId
= rLayerAdmin
.GetLayerID( rLayerAdmin
.GetControlLayerName(), false );
523 if ( nStep
&& (nStep
!= nCurStep
) )
525 SetLayer( nHiddenLayerId
);
529 SetLayer( nControlLayerId
);
534 SetLayer( nControlLayerId
);
538 void DlgEdObj::TabIndexChange( const beans::PropertyChangeEvent
& evt
) throw (RuntimeException
)
540 DlgEdForm
* pForm
= GetDlgEdForm();
543 // stop listening with all children
544 ::std::vector
<DlgEdObj
*> aChildList
= pForm
->GetChildren();
545 ::std::vector
<DlgEdObj
*>::iterator aIter
;
546 for ( aIter
= aChildList
.begin() ; aIter
!= aChildList
.end() ; ++aIter
)
548 (*aIter
)->EndListening( false );
551 Reference
< container::XNameAccess
> xNameAcc( pForm
->GetUnoControlModel() , UNO_QUERY
);
554 // get sequence of control names
555 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
556 const OUString
* pNames
= aNames
.getConstArray();
557 sal_Int32 nCtrls
= aNames
.getLength();
560 // create a map of tab indices and control names, sorted by tab index
561 IndexToNameMap aIndexToNameMap
;
562 for ( i
= 0; i
< nCtrls
; ++i
)
565 OUString
aName( pNames
[i
] );
568 sal_Int16 nTabIndex
= -1;
569 Any aCtrl
= xNameAcc
->getByName( aName
);
570 Reference
< beans::XPropertySet
> xPSet
;
572 if ( xPSet
.is() && xPSet
== Reference
< beans::XPropertySet
>( evt
.Source
, UNO_QUERY
) )
573 evt
.OldValue
>>= nTabIndex
;
574 else if ( xPSet
.is() )
575 xPSet
->getPropertyValue( DLGED_PROP_TABINDEX
) >>= nTabIndex
;
578 aIndexToNameMap
.insert( IndexToNameMap::value_type( nTabIndex
, aName
) );
581 // create a helper list of control names, sorted by tab index
582 ::std::vector
< OUString
> aNameList( aIndexToNameMap
.size() );
584 aIndexToNameMap
.begin(), aIndexToNameMap
.end(),
586 ::o3tl::select2nd
< IndexToNameMap::value_type
>( )
590 sal_Int16 nOldTabIndex
= 0;
591 evt
.OldValue
>>= nOldTabIndex
;
592 sal_Int16 nNewTabIndex
= 0;
593 evt
.NewValue
>>= nNewTabIndex
;
594 if ( nNewTabIndex
< 0 )
596 else if ( nNewTabIndex
> nCtrls
- 1 )
597 nNewTabIndex
= sal::static_int_cast
<sal_Int16
>( nCtrls
- 1 );
599 // reorder helper list
600 OUString aCtrlName
= aNameList
[nOldTabIndex
];
601 aNameList
.erase( aNameList
.begin() + nOldTabIndex
);
602 aNameList
.insert( aNameList
.begin() + nNewTabIndex
, aCtrlName
);
604 // set new tab indices
605 for ( i
= 0; i
< nCtrls
; ++i
)
607 Any aCtrl
= xNameAcc
->getByName( aNameList
[i
] );
608 Reference
< beans::XPropertySet
> xPSet
;
613 aTabIndex
<<= (sal_Int16
) i
;
614 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
618 // reorder objects in drawing page
619 GetModel()->GetPage(0)->SetObjectOrdNum( nOldTabIndex
+ 1, nNewTabIndex
+ 1 );
622 pForm
->UpdateTabOrderAndGroups();
625 // start listening with all children
626 for ( aIter
= aChildList
.begin() ; aIter
!= aChildList
.end() ; ++aIter
)
628 (*aIter
)->StartListening();
633 bool DlgEdObj::supportsService( OUString
const & serviceName
) const
635 bool bSupports
= false;
637 Reference
< lang::XServiceInfo
> xServiceInfo( GetUnoControlModel() , UNO_QUERY
);
638 // TODO: cache xServiceInfo as member?
639 if ( xServiceInfo
.is() )
640 bSupports
= xServiceInfo
->supportsService( serviceName
);
645 OUString
DlgEdObj::GetDefaultName() const
647 sal_uInt16 nResId
= 0;
648 OUString aDefaultName
;
649 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
651 nResId
= RID_STR_CLASS_DIALOG
;
653 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
655 nResId
= RID_STR_CLASS_BUTTON
;
657 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
659 nResId
= RID_STR_CLASS_RADIOBUTTON
;
661 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
663 nResId
= RID_STR_CLASS_CHECKBOX
;
665 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
667 nResId
= RID_STR_CLASS_LISTBOX
;
669 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
671 nResId
= RID_STR_CLASS_COMBOBOX
;
673 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
675 nResId
= RID_STR_CLASS_GROUPBOX
;
677 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
679 nResId
= RID_STR_CLASS_EDIT
;
681 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
683 nResId
= RID_STR_CLASS_FIXEDTEXT
;
685 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
687 nResId
= RID_STR_CLASS_IMAGECONTROL
;
689 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
691 nResId
= RID_STR_CLASS_PROGRESSBAR
;
693 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
695 nResId
= RID_STR_CLASS_SCROLLBAR
;
697 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
699 nResId
= RID_STR_CLASS_FIXEDLINE
;
701 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
703 nResId
= RID_STR_CLASS_DATEFIELD
;
705 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
707 nResId
= RID_STR_CLASS_TIMEFIELD
;
709 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
711 nResId
= RID_STR_CLASS_NUMERICFIELD
;
713 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
715 nResId
= RID_STR_CLASS_CURRENCYFIELD
;
717 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
719 nResId
= RID_STR_CLASS_FORMATTEDFIELD
;
721 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
723 nResId
= RID_STR_CLASS_PATTERNFIELD
;
725 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
727 nResId
= RID_STR_CLASS_FILECONTROL
;
729 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
731 nResId
= RID_STR_CLASS_TREECONTROL
;
733 else if ( supportsService( "com.sun.star.awt.UnoControlSpinButtonModel" ) )
735 nResId
= RID_STR_CLASS_SPINCONTROL
;
739 nResId
= RID_STR_CLASS_CONTROL
;
744 aDefaultName
= IDE_RESSTR(nResId
);
750 OUString
DlgEdObj::GetUniqueName() const
752 OUString aUniqueName
;
753 uno::Reference
< container::XNameAccess
> xNameAcc((GetDlgEdForm()->GetUnoControlModel()), uno::UNO_QUERY
);
758 OUString aDefaultName
= GetDefaultName();
762 aUniqueName
= aDefaultName
+ OUString::number(++n
);
763 } while (xNameAcc
->hasByName(aUniqueName
));
769 sal_uInt32
DlgEdObj::GetObjInventor() const
774 sal_uInt16
DlgEdObj::GetObjIdentifier() const
776 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ))
778 return OBJ_DLG_DIALOG
;
780 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ))
782 return OBJ_DLG_PUSHBUTTON
;
784 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ))
786 return OBJ_DLG_RADIOBUTTON
;
788 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ))
790 return OBJ_DLG_CHECKBOX
;
792 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ))
794 return OBJ_DLG_LISTBOX
;
796 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ))
798 return OBJ_DLG_COMBOBOX
;
800 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ))
802 return OBJ_DLG_GROUPBOX
;
804 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ))
808 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ))
810 return OBJ_DLG_FIXEDTEXT
;
812 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ))
814 return OBJ_DLG_IMAGECONTROL
;
816 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ))
818 return OBJ_DLG_PROGRESSBAR
;
820 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ))
822 return OBJ_DLG_HSCROLLBAR
;
824 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ))
826 return OBJ_DLG_HFIXEDLINE
;
828 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ))
830 return OBJ_DLG_DATEFIELD
;
832 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ))
834 return OBJ_DLG_TIMEFIELD
;
836 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ))
838 return OBJ_DLG_NUMERICFIELD
;
840 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ))
842 return OBJ_DLG_CURRENCYFIELD
;
844 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ))
846 return OBJ_DLG_FORMATTEDFIELD
;
848 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ))
850 return OBJ_DLG_PATTERNFIELD
;
852 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ))
854 return OBJ_DLG_FILECONTROL
;
856 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ))
858 return OBJ_DLG_TREECONTROL
;
862 return OBJ_DLG_CONTROL
;
866 void DlgEdObj::clonedFrom(const DlgEdObj
* _pSource
)
869 pDlgEdForm
= _pSource
->pDlgEdForm
;
871 // add child to parent form
872 pDlgEdForm
->AddChild( this );
874 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
878 OUString
aOUniqueName( GetUniqueName() );
880 aUniqueName
<<= aOUniqueName
;
881 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aUniqueName
);
883 Reference
< container::XNameContainer
> xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY
);
887 Sequence
< OUString
> aNames
= xCont
->getElementNames();
889 aTabIndex
<<= (sal_Int16
) aNames
.getLength();
890 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
892 // insert control model in dialog model
893 Reference
< awt::XControlModel
> xCtrl( xPSet
, UNO_QUERY
);
896 xCont
->insertByName( aOUniqueName
, aCtrl
);
899 pDlgEdForm
->UpdateTabOrderAndGroups();
907 DlgEdObj
* DlgEdObj::Clone() const
909 DlgEdObj
* pDlgEdObj
= CloneHelper
< DlgEdObj
>();
910 DBG_ASSERT( pDlgEdObj
!= NULL
, "DlgEdObj::Clone: invalid clone!" );
912 pDlgEdObj
->clonedFrom( this );
917 SdrObject
* DlgEdObj::getFullDragClone() const
919 // no need to really add the clone for dragging, it's a temporary
921 SdrObject
* pObj
= new SdrUnoObj(OUString());
922 *pObj
= *((const SdrUnoObj
*)this);
927 void DlgEdObj::NbcMove( const Size
& rSize
)
929 SdrUnoObj::NbcMove( rSize
);
934 // set geometry properties
940 // dialog model changed
941 GetDlgEdForm()->GetDlgEditor().SetDialogModelChanged(true);
944 void DlgEdObj::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
946 SdrUnoObj::NbcResize( rRef
, xFract
, yFract
);
951 // set geometry properties
957 // dialog model changed
958 GetDlgEdForm()->GetDlgEditor().SetDialogModelChanged(true);
961 bool DlgEdObj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
963 bool bResult
= SdrUnoObj::EndCreate(rStat
, eCmd
);
971 void DlgEdObj::SetDefaults()
974 pDlgEdForm
= static_cast<DlgEdPage
*>(GetPage())->GetDlgEdForm();
978 // add child to parent form
979 pDlgEdForm
->AddChild( this );
981 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
985 OUString
aOUniqueName( GetUniqueName() );
989 aUniqueName
<<= aOUniqueName
;
990 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aUniqueName
);
993 if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) ||
994 supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) ||
995 supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) ||
996 supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) ||
997 supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
999 xPSet
->setPropertyValue( DLGED_PROP_LABEL
, aUniqueName
);
1002 // set number formats supplier for formatted field
1003 if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
1005 Reference
< util::XNumberFormatsSupplier
> xSupplier
= GetDlgEdForm()->GetDlgEditor().GetNumberFormatsSupplier();
1006 if ( xSupplier
.is() )
1009 aSupplier
<<= xSupplier
;
1010 xPSet
->setPropertyValue( DLGED_PROP_FORMATSSUPPLIER
, aSupplier
);
1014 // set geometry properties
1017 Reference
< container::XNameContainer
> xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY
);
1021 Sequence
< OUString
> aNames
= xCont
->getElementNames();
1023 aTabIndex
<<= (sal_Int16
) aNames
.getLength();
1024 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
1027 Reference
< beans::XPropertySet
> xPSetForm( xCont
, UNO_QUERY
);
1028 if ( xPSetForm
.is() )
1030 Any aStep
= xPSetForm
->getPropertyValue( DLGED_PROP_STEP
);
1031 xPSet
->setPropertyValue( DLGED_PROP_STEP
, aStep
);
1034 // insert control model in dialog model
1035 Reference
< awt::XControlModel
> xCtrl( xPSet
, UNO_QUERY
);
1038 xCont
->insertByName( aOUniqueName
, aAny
);
1040 LocalizationMgr::setControlResourceIDsForNewEditorObject(
1041 &GetDialogEditor(), aAny
, aOUniqueName
1045 pDlgEdForm
->UpdateTabOrderAndGroups();
1049 // dialog model changed
1050 pDlgEdForm
->GetDlgEditor().SetDialogModelChanged(true);
1054 void DlgEdObj::StartListening()
1056 DBG_ASSERT(!isListening(), "DlgEdObj::StartListening: already listening!");
1060 bIsListening
= true;
1062 // XPropertyChangeListener
1063 Reference
< XPropertySet
> xControlModel( GetUnoControlModel() , UNO_QUERY
);
1064 if (!m_xPropertyChangeListener
.is() && xControlModel
.is())
1067 m_xPropertyChangeListener
= new DlgEdPropListenerImpl(*this);
1069 // register listener to properties
1070 xControlModel
->addPropertyChangeListener( OUString() , m_xPropertyChangeListener
);
1073 // XContainerListener
1074 Reference
< XScriptEventsSupplier
> xEventsSupplier( GetUnoControlModel() , UNO_QUERY
);
1075 if( !m_xContainerListener
.is() && xEventsSupplier
.is() )
1078 m_xContainerListener
= new DlgEdEvtContListenerImpl(*this);
1080 // register listener to script event container
1081 Reference
< XNameContainer
> xEventCont
= xEventsSupplier
->getEvents();
1082 DBG_ASSERT(xEventCont
.is(), "DlgEdObj::StartListening: control model has no script event container!");
1083 Reference
< XContainer
> xCont( xEventCont
, UNO_QUERY
);
1085 xCont
->addContainerListener( m_xContainerListener
);
1090 void DlgEdObj::EndListening(bool bRemoveListener
)
1092 DBG_ASSERT(isListening(), "DlgEdObj::EndListening: not listening currently!");
1096 bIsListening
= false;
1098 if (bRemoveListener
)
1100 // XPropertyChangeListener
1101 Reference
< XPropertySet
> xControlModel(GetUnoControlModel(), UNO_QUERY
);
1102 if ( m_xPropertyChangeListener
.is() && xControlModel
.is() )
1105 xControlModel
->removePropertyChangeListener( OUString() , m_xPropertyChangeListener
);
1107 m_xPropertyChangeListener
.clear();
1109 // XContainerListener
1110 Reference
< XScriptEventsSupplier
> xEventsSupplier( GetUnoControlModel() , UNO_QUERY
);
1111 if( m_xContainerListener
.is() && xEventsSupplier
.is() )
1114 Reference
< XNameContainer
> xEventCont
= xEventsSupplier
->getEvents();
1115 DBG_ASSERT(xEventCont
.is(), "DlgEdObj::EndListening: control model has no script event container!");
1116 Reference
< XContainer
> xCont( xEventCont
, UNO_QUERY
);
1118 xCont
->removeContainerListener( m_xContainerListener
);
1120 m_xContainerListener
.clear();
1125 void SAL_CALL
DlgEdObj::_propertyChange( const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw (css::uno::RuntimeException
, std::exception
)
1129 DlgEdForm
* pRealDlgEdForm
= dynamic_cast<DlgEdForm
*>(this);
1130 if (!pRealDlgEdForm
)
1131 pRealDlgEdForm
= GetDlgEdForm();
1132 if (!pRealDlgEdForm
)
1134 DlgEditor
& rDlgEditor
= pRealDlgEdForm
->GetDlgEditor();
1135 if (rDlgEditor
.isInPaint())
1138 // dialog model changed
1139 rDlgEditor
.SetDialogModelChanged(true);
1141 // update position and size
1142 if ( evt
.PropertyName
== DLGED_PROP_POSITIONX
|| evt
.PropertyName
== DLGED_PROP_POSITIONY
||
1143 evt
.PropertyName
== DLGED_PROP_WIDTH
|| evt
.PropertyName
== DLGED_PROP_HEIGHT
||
1144 evt
.PropertyName
== DLGED_PROP_DECORATION
)
1146 PositionAndSizeChange( evt
);
1148 if ( evt
.PropertyName
== DLGED_PROP_DECORATION
)
1149 GetDialogEditor().ResetDialog();
1151 // change name of control in dialog model
1152 else if ( evt
.PropertyName
== DLGED_PROP_NAME
)
1154 if (!dynamic_cast<DlgEdForm
*>(this))
1160 catch (container::NoSuchElementException
const& e
)
1162 throw lang::WrappedTargetRuntimeException("", nullptr,
1168 else if ( evt
.PropertyName
== DLGED_PROP_STEP
)
1173 else if ( evt
.PropertyName
== DLGED_PROP_TABINDEX
)
1175 if (!dynamic_cast<DlgEdForm
*>(this))
1176 TabIndexChange(evt
);
1181 void SAL_CALL
DlgEdObj::_elementInserted(const ::com::sun::star::container::ContainerEvent
& ) throw(::com::sun::star::uno::RuntimeException
)
1185 // dialog model changed
1186 GetDialogEditor().SetDialogModelChanged(true);
1190 void SAL_CALL
DlgEdObj::_elementReplaced(const ::com::sun::star::container::ContainerEvent
& ) throw(::com::sun::star::uno::RuntimeException
)
1194 // dialog model changed
1195 GetDialogEditor().SetDialogModelChanged(true);
1199 void SAL_CALL
DlgEdObj::_elementRemoved(const ::com::sun::star::container::ContainerEvent
& ) throw(::com::sun::star::uno::RuntimeException
)
1203 // dialog model changed
1204 GetDialogEditor().SetDialogModelChanged(true);
1208 void DlgEdObj::SetLayer(SdrLayerID nLayer
)
1210 SdrLayerID nOldLayer
= GetLayer();
1212 if ( nLayer
!= nOldLayer
)
1214 SdrUnoObj::SetLayer( nLayer
);
1216 DlgEdHint
aHint( DlgEdHint::LAYERCHANGED
, this );
1217 GetDlgEdForm()->GetDlgEditor().Broadcast( aHint
);
1221 TYPEINIT1(DlgEdForm
, DlgEdObj
);
1223 DlgEdForm::DlgEdForm (DlgEditor
& rDlgEditor_
) :
1224 rDlgEditor(rDlgEditor_
)
1228 DlgEdForm::~DlgEdForm()
1232 void DlgEdForm::SetRectFromProps()
1234 // get form position and size from properties
1235 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
1238 sal_Int32 nXIn
= 0, nYIn
= 0, nWidthIn
= 0, nHeightIn
= 0;
1239 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nXIn
;
1240 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nYIn
;
1241 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidthIn
;
1242 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeightIn
;
1244 // transform coordinates
1245 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
1246 if ( TransformFormToSdrCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
1248 // set rectangle position and size
1249 Point
aPoint( nXOut
, nYOut
);
1250 Size
aSize( nWidthOut
, nHeightOut
);
1251 SetSnapRect( Rectangle( aPoint
, aSize
) );
1256 void DlgEdForm::SetPropsFromRect()
1258 // get form position and size from rectangle
1259 Rectangle aRect_
= GetSnapRect();
1260 sal_Int32 nXIn
= aRect_
.Left();
1261 sal_Int32 nYIn
= aRect_
.Top();
1262 sal_Int32 nWidthIn
= aRect_
.GetWidth();
1263 sal_Int32 nHeightIn
= aRect_
.GetHeight();
1265 // transform coordinates
1266 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
1267 if ( TransformSdrToFormCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
1270 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
1275 xPSet
->setPropertyValue( DLGED_PROP_POSITIONX
, aValue
);
1277 xPSet
->setPropertyValue( DLGED_PROP_POSITIONY
, aValue
);
1278 aValue
<<= nWidthOut
;
1279 xPSet
->setPropertyValue( DLGED_PROP_WIDTH
, aValue
);
1280 aValue
<<= nHeightOut
;
1281 xPSet
->setPropertyValue( DLGED_PROP_HEIGHT
, aValue
);
1286 void DlgEdForm::AddChild( DlgEdObj
* pDlgEdObj
)
1288 pChildren
.push_back( pDlgEdObj
);
1291 void DlgEdForm::RemoveChild( DlgEdObj
* pDlgEdObj
)
1293 pChildren
.erase( ::std::find( pChildren
.begin() , pChildren
.end() , pDlgEdObj
) );
1296 void DlgEdForm::PositionAndSizeChange( const beans::PropertyChangeEvent
& evt
)
1298 DlgEditor
& rEditor
= GetDlgEditor();
1299 DlgEdPage
& rPage
= rEditor
.GetPage();
1301 sal_Int32 nPageXIn
= 0;
1302 sal_Int32 nPageYIn
= 0;
1303 Size aPageSize
= rPage
.GetSize();
1304 sal_Int32 nPageWidthIn
= aPageSize
.Width();
1305 sal_Int32 nPageHeightIn
= aPageSize
.Height();
1306 sal_Int32 nPageX
, nPageY
, nPageWidth
, nPageHeight
;
1307 if ( TransformSdrToFormCoordinates( nPageXIn
, nPageYIn
, nPageWidthIn
, nPageHeightIn
, nPageX
, nPageY
, nPageWidth
, nPageHeight
) )
1309 Reference
< beans::XPropertySet
> xPSetForm( GetUnoControlModel(), UNO_QUERY
);
1310 if ( xPSetForm
.is() )
1312 sal_Int32 nValue
= 0;
1313 evt
.NewValue
>>= nValue
;
1314 sal_Int32 nNewValue
= nValue
;
1316 if ( evt
.PropertyName
== DLGED_PROP_POSITIONX
)
1318 if ( nNewValue
< nPageX
)
1321 else if ( evt
.PropertyName
== DLGED_PROP_POSITIONY
)
1323 if ( nNewValue
< nPageY
)
1326 else if ( evt
.PropertyName
== DLGED_PROP_WIDTH
)
1328 if ( nNewValue
< 1 )
1331 else if ( evt
.PropertyName
== DLGED_PROP_HEIGHT
)
1333 if ( nNewValue
< 1 )
1337 if ( nNewValue
!= nValue
)
1340 aNewValue
<<= nNewValue
;
1341 EndListening( false );
1342 xPSetForm
->setPropertyValue( evt
.PropertyName
, aNewValue
);
1348 bool bAdjustedPageSize
= rEditor
.AdjustPageSize();
1350 std::vector
<DlgEdObj
*> const& aChildList
= GetChildren();
1351 std::vector
<DlgEdObj
*>::const_iterator aIter
;
1353 if ( bAdjustedPageSize
)
1355 rEditor
.InitScrollBars();
1356 aPageSize
= rPage
.GetSize();
1357 nPageWidthIn
= aPageSize
.Width();
1358 nPageHeightIn
= aPageSize
.Height();
1359 if ( TransformSdrToControlCoordinates( nPageXIn
, nPageYIn
, nPageWidthIn
, nPageHeightIn
, nPageX
, nPageY
, nPageWidth
, nPageHeight
) )
1361 for ( aIter
= aChildList
.begin(); aIter
!= aChildList
.end(); ++aIter
)
1363 Reference
< beans::XPropertySet
> xPSet( (*aIter
)->GetUnoControlModel(), UNO_QUERY
);
1366 sal_Int32 nX
= 0, nY
= 0, nWidth
= 0, nHeight
= 0;
1367 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nX
;
1368 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nY
;
1369 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidth
;
1370 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeight
;
1372 sal_Int32 nNewX
= nX
;
1373 if ( nX
+ nWidth
> nPageX
+ nPageWidth
)
1375 nNewX
= nPageX
+ nPageWidth
- nWidth
;
1376 if ( nNewX
< nPageX
)
1383 EndListening( false );
1384 xPSet
->setPropertyValue( DLGED_PROP_POSITIONX
, aValue
);
1388 sal_Int32 nNewY
= nY
;
1389 if ( nY
+ nHeight
> nPageY
+ nPageHeight
)
1391 nNewY
= nPageY
+ nPageHeight
- nHeight
;
1392 if ( nNewY
< nPageY
)
1399 EndListening( false );
1400 xPSet
->setPropertyValue( DLGED_PROP_POSITIONY
, aValue
);
1408 for ( aIter
= aChildList
.begin(); aIter
!= aChildList
.end(); ++aIter
)
1409 (*aIter
)->SetRectFromProps();
1412 void DlgEdForm::UpdateStep()
1414 SdrPage
* pSdrPage
= GetPage();
1418 const size_t nObjCount
= pSdrPage
->GetObjCount();
1419 for ( size_t i
= 0 ; i
< nObjCount
; i
++ )
1421 DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pSdrPage
->GetObj(i
));
1422 if (pDlgEdObj
&& !dynamic_cast<DlgEdForm
*>(pDlgEdObj
))
1423 pDlgEdObj
->UpdateStep();
1428 void DlgEdForm::UpdateTabIndices()
1430 // stop listening with all children
1431 ::std::vector
<DlgEdObj
*>::iterator aIter
;
1432 for ( aIter
= pChildren
.begin() ; aIter
!= pChildren
.end() ; ++aIter
)
1434 (*aIter
)->EndListening( false );
1437 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc( GetUnoControlModel() , UNO_QUERY
);
1438 if ( xNameAcc
.is() )
1440 // get sequence of control names
1441 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
1442 const OUString
* pNames
= aNames
.getConstArray();
1443 sal_Int32 nCtrls
= aNames
.getLength();
1445 // create a map of tab indices and control names, sorted by tab index
1446 IndexToNameMap aIndexToNameMap
;
1447 for ( sal_Int16 i
= 0; i
< nCtrls
; ++i
)
1450 OUString
aName( pNames
[i
] );
1453 sal_Int16 nTabIndex
= -1;
1454 Any aCtrl
= xNameAcc
->getByName( aName
);
1455 Reference
< ::com::sun::star::beans::XPropertySet
> xPSet
;
1458 xPSet
->getPropertyValue( DLGED_PROP_TABINDEX
) >>= nTabIndex
;
1461 aIndexToNameMap
.insert( IndexToNameMap::value_type( nTabIndex
, aName
) );
1464 // set new tab indices
1465 sal_Int16 nNewTabIndex
= 0;
1466 for ( IndexToNameMap::iterator aIt
= aIndexToNameMap
.begin(); aIt
!= aIndexToNameMap
.end(); ++aIt
)
1468 Any aCtrl
= xNameAcc
->getByName( aIt
->second
);
1469 Reference
< beans::XPropertySet
> xPSet
;
1474 aTabIndex
<<= (sal_Int16
) nNewTabIndex
++;
1475 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
1480 UpdateTabOrderAndGroups();
1483 // start listening with all children
1484 for ( aIter
= pChildren
.begin() ; aIter
!= pChildren
.end() ; ++aIter
)
1486 (*aIter
)->StartListening();
1490 void DlgEdForm::UpdateTabOrder()
1493 // When the tabindex of a control model changes, the dialog control is
1494 // notified about those changes. Due to #109067# (bad performance of
1495 // dialog editor) the dialog control doesn't activate the tab order
1496 // in design mode. When the dialog editor has reordered all
1497 // tabindices, this method allows to activate the taborder afterwards.
1499 Reference
< awt::XUnoControlContainer
> xCont( GetControl(), UNO_QUERY
);
1502 Sequence
< Reference
< awt::XTabController
> > aSeqTabCtrls
= xCont
->getTabControllers();
1503 const Reference
< awt::XTabController
>* pTabCtrls
= aSeqTabCtrls
.getConstArray();
1504 sal_Int32 nCount
= aSeqTabCtrls
.getLength();
1505 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
1506 pTabCtrls
[i
]->activateTabOrder();
1510 void DlgEdForm::UpdateGroups()
1513 // The grouping of radio buttons in a dialog is done by vcl.
1514 // In the dialog editor we have two views (=controls) for one
1515 // radio button model. One control is owned by the dialog control,
1516 // but not visible in design mode. The other control is owned by
1517 // the drawing layer object. Whereas the grouping of the first
1518 // control is done by vcl, the grouping of the control in the
1519 // drawing layer has to be done here.
1521 Reference
< awt::XTabControllerModel
> xTabModel( GetUnoControlModel() , UNO_QUERY
);
1522 if ( xTabModel
.is() )
1524 // create a global list of controls that belong to the dialog
1525 ::std::vector
<DlgEdObj
*> aChildList
= GetChildren();
1526 sal_uInt32 nSize
= aChildList
.size();
1527 Sequence
< Reference
< awt::XControl
> > aSeqControls( nSize
);
1528 for ( sal_uInt32 i
= 0; i
< nSize
; ++i
)
1529 aSeqControls
.getArray()[i
] = Reference
< awt::XControl
>( aChildList
[i
]->GetControl(), UNO_QUERY
);
1531 sal_Int32 nGroupCount
= xTabModel
->getGroupCount();
1532 for ( sal_Int32 nGroup
= 0; nGroup
< nGroupCount
; ++nGroup
)
1534 // get a list of control models that belong to this group
1536 Sequence
< Reference
< awt::XControlModel
> > aSeqModels
;
1537 xTabModel
->getGroup( nGroup
, aSeqModels
, aName
);
1538 const Reference
< awt::XControlModel
>* pModels
= aSeqModels
.getConstArray();
1539 sal_Int32 nModelCount
= aSeqModels
.getLength();
1541 // create a list of peers that belong to this group
1542 Sequence
< Reference
< awt::XWindow
> > aSeqPeers( nModelCount
);
1543 for ( sal_Int32 nModel
= 0; nModel
< nModelCount
; ++nModel
)
1545 // for each control model find the corresponding control in the global list
1546 const Reference
< awt::XControl
>* pControls
= aSeqControls
.getConstArray();
1547 sal_Int32 nControlCount
= aSeqControls
.getLength();
1548 for ( sal_Int32 nControl
= 0; nControl
< nControlCount
; ++nControl
)
1550 const Reference
< awt::XControl
> xCtrl( pControls
[nControl
] );
1553 Reference
< awt::XControlModel
> xCtrlModel( xCtrl
->getModel() );
1554 if ( (awt::XControlModel
*)xCtrlModel
.get() == (awt::XControlModel
*)pModels
[nModel
].get() )
1556 // get the control peer and insert into the list of peers
1557 aSeqPeers
.getArray()[ nModel
] = Reference
< awt::XWindow
>( xCtrl
->getPeer(), UNO_QUERY
);
1564 // set the group at the dialog peer
1565 Reference
< awt::XControl
> xDlg( GetControl(), UNO_QUERY
);
1568 Reference
< awt::XVclContainerPeer
> xDlgPeer( xDlg
->getPeer(), UNO_QUERY
);
1569 if ( xDlgPeer
.is() )
1570 xDlgPeer
->setGroup( aSeqPeers
);
1576 void DlgEdForm::UpdateTabOrderAndGroups()
1582 void DlgEdForm::NbcMove( const Size
& rSize
)
1584 SdrUnoObj::NbcMove( rSize
);
1586 // set geometry properties of form
1587 EndListening(false);
1591 // set geometry properties of all children
1592 ::std::vector
<DlgEdObj
*>::iterator aIter
;
1593 for ( aIter
= pChildren
.begin() ; aIter
!= pChildren
.end() ; ++aIter
)
1595 (*aIter
)->EndListening(false);
1596 (*aIter
)->SetPropsFromRect();
1597 (*aIter
)->StartListening();
1600 // dialog model changed
1601 GetDlgEditor().SetDialogModelChanged(true);
1604 void DlgEdForm::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
1606 SdrUnoObj::NbcResize( rRef
, xFract
, yFract
);
1608 // set geometry properties of form
1609 EndListening(false);
1613 // set geometry properties of all children
1614 ::std::vector
<DlgEdObj
*>::iterator aIter
;
1615 for ( aIter
= pChildren
.begin() ; aIter
!= pChildren
.end() ; ++aIter
)
1617 (*aIter
)->EndListening(false);
1618 (*aIter
)->SetPropsFromRect();
1619 (*aIter
)->StartListening();
1622 // dialog model changed
1623 GetDlgEditor().SetDialogModelChanged(true);
1626 bool DlgEdForm::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
1628 bool bResult
= SdrUnoObj::EndCreate(rStat
, eCmd
);
1631 EndListening(false);
1633 // set geometry properties
1636 // dialog model changed
1637 GetDlgEditor().SetDialogModelChanged(true);
1645 awt::DeviceInfo
DlgEdForm::getDeviceInfo() const
1647 awt::DeviceInfo aDeviceInfo
;
1649 DlgEditor
& rEditor
= GetDlgEditor();
1650 vcl::Window
& rWindow
= rEditor
.GetWindow();
1652 // obtain an XControl
1653 ::utl::SharedUNOComponent
< awt::XControl
> xDialogControl
; // ensures auto-disposal, if needed
1654 xDialogControl
.reset( GetControl(), ::utl::SharedUNOComponent
< awt::XControl
>::NoTakeOwnership
);
1655 if ( !xDialogControl
.is() )
1657 // don't create a temporary control all the time, this method here is called
1658 // way too often. Instead, use a cached DeviceInfo.
1660 if ( !!mpDeviceInfo
)
1661 return *mpDeviceInfo
;
1663 Reference
< awt::XControlContainer
> xEditorControlContainer( rEditor
.GetWindowControlContainer() );
1664 xDialogControl
.reset(
1665 GetTemporaryControlForWindow(rWindow
, xEditorControlContainer
),
1666 utl::SharedUNOComponent
< awt::XControl
>::TakeOwnership
1670 Reference
< awt::XDevice
> xDialogDevice
;
1671 if ( xDialogControl
.is() )
1672 xDialogDevice
.set( xDialogControl
->getPeer(), UNO_QUERY
);
1673 DBG_ASSERT( xDialogDevice
.is(), "DlgEdForm::getDeviceInfo: no device!" );
1674 if ( xDialogDevice
.is() )
1675 aDeviceInfo
= xDialogDevice
->getInfo();
1677 mpDeviceInfo
.reset( aDeviceInfo
);
1681 bool DlgEdObj::MakeDataAware( const Reference
< frame::XModel
>& xModel
)
1684 // Need to flesh this out, currently we will only support data-aware controls for calc
1685 // and only handle a subset of functionality e.g. linked-cell and cell range data source. Of course later
1686 // we need to disambiguate for writer ( and others ? ) and also support the generic form (db) bindings
1687 // we need some more work in xmlscript to be able to handle that
1688 Reference
< lang::XMultiServiceFactory
> xFac( xModel
, UNO_QUERY
);
1689 Reference
< form::binding::XBindableValue
> xBindable( GetUnoControlModel(), UNO_QUERY
);
1690 Reference
< form::binding::XListEntrySink
> xListEntrySink( GetUnoControlModel(), UNO_QUERY
);
1693 if ( xBindable
.is() )
1695 Reference
< form::binding::XValueBinding
> xBinding( xFac
->createInstance( "com.sun.star.table.CellValueBinding" ), UNO_QUERY
);
1696 xBindable
->setValueBinding( xBinding
);
1698 if ( xListEntrySink
.is() )
1700 Reference
< form::binding::XListEntrySource
> xSource( xFac
->createInstance( "com.sun.star.table.CellRangeListSource" ), UNO_QUERY
);
1701 xListEntrySink
->setListEntrySource( xSource
);
1703 if ( xListEntrySink
.is() || xBindable
.is() )
1708 } // namespace basctl
1710 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */