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 .
22 #include "dlgeddef.hxx"
23 #include "dlgedlist.hxx"
24 #include "dlgedobj.hxx"
25 #include "dlgedpage.hxx"
26 #include "dlgedview.hxx"
28 #include "localizationmgr.hxx"
30 #include "dlgresid.hrc"
32 #include <com/sun/star/form/binding/XBindableValue.hpp>
33 #include <com/sun/star/form/binding/XValueBinding.hpp>
34 #include <com/sun/star/form/binding/XListEntrySink.hpp>
35 #include <com/sun/star/awt/XUnoControlContainer.hpp>
36 #include <com/sun/star/awt/XVclContainerPeer.hpp>
37 #include <com/sun/star/container/XContainer.hpp>
38 #include <com/sun/star/lang/XServiceInfo.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
);
56 DlgEditor
& DlgEdObj::GetDialogEditor ()
58 if (DlgEdForm
* pFormThis
= dynamic_cast<DlgEdForm
*>(this))
59 return pFormThis
->GetDlgEditor();
61 return pDlgEdForm
->GetDlgEditor();
64 //----------------------------------------------------------------------------
67 :SdrUnoObj(String(), false)
71 DBG_CTOR(DlgEdObj
, NULL
);
74 //----------------------------------------------------------------------------
76 DlgEdObj::DlgEdObj(const OUString
& rModelName
,
77 const com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
>& rxSFac
)
78 :SdrUnoObj(rModelName
, rxSFac
, false)
82 DBG_CTOR(DlgEdObj
, NULL
);
85 //----------------------------------------------------------------------------
89 DBG_DTOR(DlgEdObj
, NULL
);
95 //----------------------------------------------------------------------------
97 void DlgEdObj::SetPage(SdrPage
* _pNewPage
)
100 SdrUnoObj::SetPage(_pNewPage
);
103 //----------------------------------------------------------------------------
107 /** returns the DlgEdForm which the given DlgEdObj belongs to
108 (which might in fact be the object itself)
110 Failure to obtain the form will be reported with an assertion in the non-product
113 bool lcl_getDlgEdForm( DlgEdObj
* _pObject
, DlgEdForm
*& _out_pDlgEdForm
)
115 _out_pDlgEdForm
= dynamic_cast< DlgEdForm
* >( _pObject
);
116 if ( !_out_pDlgEdForm
)
117 _out_pDlgEdForm
= _pObject
->GetDlgEdForm();
118 DBG_ASSERT( _out_pDlgEdForm
, "lcl_getDlgEdForm: no form!" );
119 return ( _out_pDlgEdForm
!= NULL
);
123 //----------------------------------------------------------------------------
125 uno::Reference
< awt::XControl
> DlgEdObj::GetControl() const
127 uno::Reference
< awt::XControl
> xControl
;
128 if (DlgEdForm
const* pForm
= GetDlgEdForm())
130 DlgEditor
const& rEditor
= pForm
->GetDlgEditor();
131 xControl
= GetUnoControl(rEditor
.GetView(), rEditor
.GetWindow());
136 //----------------------------------------------------------------------------
138 bool DlgEdObj::TransformSdrToControlCoordinates(
139 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
140 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
142 // input position and size
143 Size
aPos( nXIn
, nYIn
);
144 Size
aSize( nWidthIn
, nHeightIn
);
147 DlgEdForm
* pForm
= NULL
;
148 if ( !lcl_getDlgEdForm( this, pForm
) )
150 Rectangle aFormRect
= pForm
->GetSnapRect();
151 Size
aFormPos( aFormRect
.Left(), aFormRect
.Top() );
153 // convert 100th_mm to pixel
154 OutputDevice
* pDevice
= Application::GetDefaultDevice();
155 DBG_ASSERT( pDevice
, "DlgEdObj::TransformSdrToControlCoordinates: missing default device!" );
158 aPos
= pDevice
->LogicToPixel( aPos
, MapMode( MAP_100TH_MM
) );
159 aSize
= pDevice
->LogicToPixel( aSize
, MapMode( MAP_100TH_MM
) );
160 aFormPos
= pDevice
->LogicToPixel( aFormPos
, MapMode( MAP_100TH_MM
) );
162 // subtract form position
163 aPos
.Width() -= aFormPos
.Width();
164 aPos
.Height() -= aFormPos
.Height();
166 // take window borders into account
167 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
168 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
169 if ( !xPSetForm
.is() )
171 bool bDecoration
= true;
172 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
175 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
176 aPos
.Width() -= aDeviceInfo
.LeftInset
;
177 aPos
.Height() -= aDeviceInfo
.TopInset
;
180 // convert pixel to logic units
181 aPos
= pDevice
->PixelToLogic( aPos
, MAP_APPFONT
);
182 aSize
= pDevice
->PixelToLogic( aSize
, MAP_APPFONT
);
184 // set out parameters
185 nXOut
= aPos
.Width();
186 nYOut
= aPos
.Height();
187 nWidthOut
= aSize
.Width();
188 nHeightOut
= aSize
.Height();
193 //----------------------------------------------------------------------------
195 bool DlgEdObj::TransformSdrToFormCoordinates(
196 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
197 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
199 // input position and size
200 Size
aPos( nXIn
, nYIn
);
201 Size
aSize( nWidthIn
, nHeightIn
);
203 // convert 100th_mm to pixel
204 OutputDevice
* pDevice
= Application::GetDefaultDevice();
205 DBG_ASSERT( pDevice
, "DlgEdObj::TransformSdrToFormCoordinates: missing default device!" );
208 aPos
= pDevice
->LogicToPixel( aPos
, MapMode( MAP_100TH_MM
) );
209 aSize
= pDevice
->LogicToPixel( aSize
, MapMode( MAP_100TH_MM
) );
211 // take window borders into account
212 DlgEdForm
* pForm
= NULL
;
213 if ( !lcl_getDlgEdForm( this, pForm
) )
216 // take window borders into account
217 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
218 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
219 if ( !xPSetForm
.is() )
221 bool bDecoration
= true;
222 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
225 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
226 aSize
.Width() -= aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
;
227 aSize
.Height() -= aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
;
229 // convert pixel to logic units
230 aPos
= pDevice
->PixelToLogic( aPos
, MAP_APPFONT
);
231 aSize
= pDevice
->PixelToLogic( aSize
, MAP_APPFONT
);
233 // set out parameters
234 nXOut
= aPos
.Width();
235 nYOut
= aPos
.Height();
236 nWidthOut
= aSize
.Width();
237 nHeightOut
= aSize
.Height();
242 //----------------------------------------------------------------------------
244 bool DlgEdObj::TransformControlToSdrCoordinates(
245 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
246 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
248 // input position and size
249 Size
aPos( nXIn
, nYIn
);
250 Size
aSize( nWidthIn
, nHeightIn
);
253 DlgEdForm
* pForm
= NULL
;
254 if ( !lcl_getDlgEdForm( this, pForm
) )
257 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
258 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformControlToSdrCoordinates: no form property set!" );
259 if ( !xPSetForm
.is() )
261 sal_Int32 nFormX
= 0, nFormY
= 0, nFormWidth
, nFormHeight
;
262 xPSetForm
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nFormX
;
263 xPSetForm
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nFormY
;
264 xPSetForm
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nFormWidth
;
265 xPSetForm
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nFormHeight
;
266 Size
aFormPos( nFormX
, nFormY
);
268 // convert logic units to pixel
269 OutputDevice
* pDevice
= Application::GetDefaultDevice();
270 DBG_ASSERT( pDevice
, "DlgEdObj::TransformControlToSdrCoordinates: missing default device!" );
273 aPos
= pDevice
->LogicToPixel( aPos
, MAP_APPFONT
);
274 aSize
= pDevice
->LogicToPixel( aSize
, MAP_APPFONT
);
275 aFormPos
= pDevice
->LogicToPixel( aFormPos
, MAP_APPFONT
);
278 aPos
.Width() += aFormPos
.Width();
279 aPos
.Height() += aFormPos
.Height();
281 // take window borders into account
282 bool bDecoration
= true;
283 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
286 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
287 aPos
.Width() += aDeviceInfo
.LeftInset
;
288 aPos
.Height() += aDeviceInfo
.TopInset
;
291 // convert pixel to 100th_mm
292 aPos
= pDevice
->PixelToLogic( aPos
, MapMode( MAP_100TH_MM
) );
293 aSize
= pDevice
->PixelToLogic( aSize
, MapMode( MAP_100TH_MM
) );
295 // set out parameters
296 nXOut
= aPos
.Width();
297 nYOut
= aPos
.Height();
298 nWidthOut
= aSize
.Width();
299 nHeightOut
= aSize
.Height();
304 //----------------------------------------------------------------------------
306 bool DlgEdObj::TransformFormToSdrCoordinates(
307 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
308 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
310 // input position and size
311 Size
aPos( nXIn
, nYIn
);
312 Size
aSize( nWidthIn
, nHeightIn
);
314 // convert logic units to pixel
315 OutputDevice
* pDevice
= Application::GetDefaultDevice();
316 DBG_ASSERT( pDevice
, "DlgEdObj::TransformFormToSdrCoordinates: missing default device!" );
320 // take window borders into account
321 DlgEdForm
* pForm
= NULL
;
322 if ( !lcl_getDlgEdForm( this, pForm
) )
325 aPos
= pDevice
->LogicToPixel( aPos
, MAP_APPFONT
);
326 aSize
= pDevice
->LogicToPixel( aSize
, MAP_APPFONT
);
328 // take window borders into account
329 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
330 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
331 if ( !xPSetForm
.is() )
333 bool bDecoration
= true;
334 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
337 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
338 aSize
.Width() += aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
;
339 aSize
.Height() += aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
;
342 // convert pixel to 100th_mm
343 aPos
= pDevice
->PixelToLogic( aPos
, MapMode( MAP_100TH_MM
) );
344 aSize
= pDevice
->PixelToLogic( aSize
, MapMode( MAP_100TH_MM
) );
346 // set out parameters
347 nXOut
= aPos
.Width();
348 nYOut
= aPos
.Height();
349 nWidthOut
= aSize
.Width();
350 nHeightOut
= aSize
.Height();
355 //----------------------------------------------------------------------------
357 void DlgEdObj::SetRectFromProps()
359 // get control position and size from properties
360 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
363 sal_Int32 nXIn
= 0, nYIn
= 0, nWidthIn
= 0, nHeightIn
= 0;
364 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nXIn
;
365 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nYIn
;
366 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidthIn
;
367 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeightIn
;
369 // transform coordinates
370 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
371 if ( TransformControlToSdrCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
373 // set rectangle position and size
374 Point
aPoint( nXOut
, nYOut
);
375 Size
aSize( nWidthOut
, nHeightOut
);
376 SetSnapRect( Rectangle( aPoint
, aSize
) );
381 //----------------------------------------------------------------------------
383 void DlgEdObj::SetPropsFromRect()
385 // get control position and size from rectangle
386 Rectangle aRect_
= GetSnapRect();
387 sal_Int32 nXIn
= aRect_
.Left();
388 sal_Int32 nYIn
= aRect_
.Top();
389 sal_Int32 nWidthIn
= aRect_
.GetWidth();
390 sal_Int32 nHeightIn
= aRect_
.GetHeight();
392 // transform coordinates
393 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
394 if ( TransformSdrToControlCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
397 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
402 xPSet
->setPropertyValue( DLGED_PROP_POSITIONX
, aValue
);
404 xPSet
->setPropertyValue( DLGED_PROP_POSITIONY
, aValue
);
405 aValue
<<= nWidthOut
;
406 xPSet
->setPropertyValue( DLGED_PROP_WIDTH
, aValue
);
407 aValue
<<= nHeightOut
;
408 xPSet
->setPropertyValue( DLGED_PROP_HEIGHT
, aValue
);
413 //----------------------------------------------------------------------------
415 void DlgEdObj::PositionAndSizeChange( const beans::PropertyChangeEvent
& evt
)
417 DBG_ASSERT( pDlgEdForm
, "DlgEdObj::PositionAndSizeChange: no form!" );
418 DlgEdPage
& rPage
= pDlgEdForm
->GetDlgEditor().GetPage();
420 sal_Int32 nPageXIn
= 0;
421 sal_Int32 nPageYIn
= 0;
422 Size aPageSize
= rPage
.GetSize();
423 sal_Int32 nPageWidthIn
= aPageSize
.Width();
424 sal_Int32 nPageHeightIn
= aPageSize
.Height();
425 sal_Int32 nPageX
, nPageY
, nPageWidth
, nPageHeight
;
426 if ( TransformSdrToControlCoordinates( nPageXIn
, nPageYIn
, nPageWidthIn
, nPageHeightIn
, nPageX
, nPageY
, nPageWidth
, nPageHeight
) )
428 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
431 sal_Int32 nX
= 0, nY
= 0, nWidth
= 0, nHeight
= 0;
432 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nX
;
433 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nY
;
434 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidth
;
435 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeight
;
437 sal_Int32 nValue
= 0;
438 evt
.NewValue
>>= nValue
;
439 sal_Int32 nNewValue
= nValue
;
441 if ( evt
.PropertyName
== DLGED_PROP_POSITIONX
)
443 if ( nNewValue
+ nWidth
> nPageX
+ nPageWidth
)
444 nNewValue
= nPageX
+ nPageWidth
- nWidth
;
445 if ( nNewValue
< nPageX
)
448 else if ( evt
.PropertyName
== DLGED_PROP_POSITIONY
)
450 if ( nNewValue
+ nHeight
> nPageY
+ nPageHeight
)
451 nNewValue
= nPageY
+ nPageHeight
- nHeight
;
452 if ( nNewValue
< nPageY
)
455 else if ( evt
.PropertyName
== DLGED_PROP_WIDTH
)
457 if ( nX
+ nNewValue
> nPageX
+ nPageWidth
)
458 nNewValue
= nPageX
+ nPageWidth
- nX
;
462 else if ( evt
.PropertyName
== DLGED_PROP_HEIGHT
)
464 if ( nY
+ nNewValue
> nPageY
+ nPageHeight
)
465 nNewValue
= nPageY
+ nPageHeight
- nY
;
470 if ( nNewValue
!= nValue
)
473 aNewValue
<<= nNewValue
;
474 EndListening( false );
475 xPSet
->setPropertyValue( evt
.PropertyName
, aNewValue
);
485 //----------------------------------------------------------------------------
487 void SAL_CALL
DlgEdObj::NameChange( const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw( ::com::sun::star::uno::RuntimeException
)
491 evt
.OldValue
>>= aOldName
;
495 evt
.NewValue
>>= aNewName
;
497 if ( !aNewName
.equals(aOldName
) )
499 Reference
< container::XNameAccess
> xNameAcc((GetDlgEdForm()->GetUnoControlModel()), UNO_QUERY
);
500 if ( xNameAcc
.is() && xNameAcc
->hasByName(aOldName
) )
502 if ( !xNameAcc
->hasByName(aNewName
) && !aNewName
.isEmpty())
504 // remove the control by the old name and insert the control by the new name in the container
505 Reference
< container::XNameContainer
> xCont(xNameAcc
, UNO_QUERY
);
508 Reference
< awt::XControlModel
> xCtrl(GetUnoControlModel(), UNO_QUERY
);
511 xCont
->removeByName( aOldName
);
512 xCont
->insertByName( aNewName
, aAny
);
514 LocalizationMgr::renameControlResourceIDsForEditorObject(
515 &GetDialogEditor(), aAny
, aNewName
521 // set old name property
523 Reference
< beans::XPropertySet
> xPSet(GetUnoControlModel(), UNO_QUERY
);
526 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aName
);
533 //----------------------------------------------------------------------------
535 sal_Int32
DlgEdObj::GetStep() const
539 uno::Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), uno::UNO_QUERY
);
542 xPSet
->getPropertyValue( DLGED_PROP_STEP
) >>= nStep
;
547 //----------------------------------------------------------------------------
549 void DlgEdObj::UpdateStep()
551 sal_Int32 nCurStep
= GetDlgEdForm()->GetStep();
552 sal_Int32 nStep
= GetStep();
554 SdrLayerAdmin
& rLayerAdmin
= GetModel()->GetLayerAdmin();
555 SdrLayerID nHiddenLayerId
= rLayerAdmin
.GetLayerID( OUString( "HiddenLayer" ), false );
556 SdrLayerID nControlLayerId
= rLayerAdmin
.GetLayerID( rLayerAdmin
.GetControlLayerName(), false );
560 if ( nStep
&& (nStep
!= nCurStep
) )
562 SetLayer( nHiddenLayerId
);
566 SetLayer( nControlLayerId
);
571 SetLayer( nControlLayerId
);
575 //----------------------------------------------------------------------------
577 void DlgEdObj::TabIndexChange( const beans::PropertyChangeEvent
& evt
) throw (RuntimeException
)
579 DlgEdForm
* pForm
= GetDlgEdForm();
582 // stop listening with all children
583 ::std::vector
<DlgEdObj
*> aChildList
= pForm
->GetChildren();
584 ::std::vector
<DlgEdObj
*>::iterator aIter
;
585 for ( aIter
= aChildList
.begin() ; aIter
!= aChildList
.end() ; ++aIter
)
587 (*aIter
)->EndListening( false );
590 Reference
< container::XNameAccess
> xNameAcc( pForm
->GetUnoControlModel() , UNO_QUERY
);
593 // get sequence of control names
594 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
595 const OUString
* pNames
= aNames
.getConstArray();
596 sal_Int32 nCtrls
= aNames
.getLength();
599 // create a map of tab indices and control names, sorted by tab index
600 IndexToNameMap aIndexToNameMap
;
601 for ( i
= 0; i
< nCtrls
; ++i
)
604 OUString
aName( pNames
[i
] );
607 sal_Int16 nTabIndex
= -1;
608 Any aCtrl
= xNameAcc
->getByName( aName
);
609 Reference
< beans::XPropertySet
> xPSet
;
611 if ( xPSet
.is() && xPSet
== Reference
< beans::XPropertySet
>( evt
.Source
, UNO_QUERY
) )
612 evt
.OldValue
>>= nTabIndex
;
613 else if ( xPSet
.is() )
614 xPSet
->getPropertyValue( DLGED_PROP_TABINDEX
) >>= nTabIndex
;
617 aIndexToNameMap
.insert( IndexToNameMap::value_type( nTabIndex
, aName
) );
620 // create a helper list of control names, sorted by tab index
621 ::std::vector
< OUString
> aNameList( aIndexToNameMap
.size() );
623 aIndexToNameMap
.begin(), aIndexToNameMap
.end(),
625 ::o3tl::select2nd
< IndexToNameMap::value_type
>( )
629 sal_Int16 nOldTabIndex
= 0;
630 evt
.OldValue
>>= nOldTabIndex
;
631 sal_Int16 nNewTabIndex
= 0;
632 evt
.NewValue
>>= nNewTabIndex
;
633 if ( nNewTabIndex
< 0 )
635 else if ( nNewTabIndex
> nCtrls
- 1 )
636 nNewTabIndex
= sal::static_int_cast
<sal_Int16
>( nCtrls
- 1 );
638 // reorder helper list
639 OUString aCtrlName
= aNameList
[nOldTabIndex
];
640 aNameList
.erase( aNameList
.begin() + nOldTabIndex
);
641 aNameList
.insert( aNameList
.begin() + nNewTabIndex
, aCtrlName
);
643 // set new tab indices
644 for ( i
= 0; i
< nCtrls
; ++i
)
646 Any aCtrl
= xNameAcc
->getByName( aNameList
[i
] );
647 Reference
< beans::XPropertySet
> xPSet
;
652 aTabIndex
<<= (sal_Int16
) i
;
653 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
657 // reorder objects in drawing page
658 GetModel()->GetPage(0)->SetObjectOrdNum( nOldTabIndex
+ 1, nNewTabIndex
+ 1 );
661 pForm
->UpdateTabOrderAndGroups();
664 // start listening with all children
665 for ( aIter
= aChildList
.begin() ; aIter
!= aChildList
.end() ; ++aIter
)
667 (*aIter
)->StartListening();
672 //----------------------------------------------------------------------------
674 sal_Bool
DlgEdObj::supportsService( const sal_Char
* _pServiceName
) const
676 bool bSupports
= false;
678 Reference
< lang::XServiceInfo
> xServiceInfo( GetUnoControlModel() , UNO_QUERY
);
679 // TODO: cache xServiceInfo as member?
680 if ( xServiceInfo
.is() )
681 bSupports
= xServiceInfo
->supportsService( OUString::createFromAscii( _pServiceName
) );
686 //----------------------------------------------------------------------------
688 OUString
DlgEdObj::GetDefaultName() const
690 sal_uInt16 nResId
= 0;
691 OUString aDefaultName
;
692 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
694 nResId
= RID_STR_CLASS_DIALOG
;
696 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
698 nResId
= RID_STR_CLASS_BUTTON
;
700 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
702 nResId
= RID_STR_CLASS_RADIOBUTTON
;
704 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
706 nResId
= RID_STR_CLASS_CHECKBOX
;
708 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
710 nResId
= RID_STR_CLASS_LISTBOX
;
712 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
714 nResId
= RID_STR_CLASS_COMBOBOX
;
716 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
718 nResId
= RID_STR_CLASS_GROUPBOX
;
720 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
722 nResId
= RID_STR_CLASS_EDIT
;
724 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
726 nResId
= RID_STR_CLASS_FIXEDTEXT
;
728 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
730 nResId
= RID_STR_CLASS_IMAGECONTROL
;
732 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
734 nResId
= RID_STR_CLASS_PROGRESSBAR
;
736 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
738 nResId
= RID_STR_CLASS_SCROLLBAR
;
740 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
742 nResId
= RID_STR_CLASS_FIXEDLINE
;
744 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
746 nResId
= RID_STR_CLASS_DATEFIELD
;
748 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
750 nResId
= RID_STR_CLASS_TIMEFIELD
;
752 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
754 nResId
= RID_STR_CLASS_NUMERICFIELD
;
756 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
758 nResId
= RID_STR_CLASS_CURRENCYFIELD
;
760 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
762 nResId
= RID_STR_CLASS_FORMATTEDFIELD
;
764 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
766 nResId
= RID_STR_CLASS_PATTERNFIELD
;
768 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
770 nResId
= RID_STR_CLASS_FILECONTROL
;
772 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
774 nResId
= RID_STR_CLASS_TREECONTROL
;
776 else if ( supportsService( "com.sun.star.awt.UnoControlSpinButtonModel" ) )
778 nResId
= RID_STR_CLASS_SPINCONTROL
;
782 nResId
= RID_STR_CLASS_CONTROL
;
787 aDefaultName
= IDE_RESSTR(nResId
);
793 //----------------------------------------------------------------------------
795 OUString
DlgEdObj::GetUniqueName() const
797 OUString aUniqueName
;
798 uno::Reference
< container::XNameAccess
> xNameAcc((GetDlgEdForm()->GetUnoControlModel()), uno::UNO_QUERY
);
803 OUString aDefaultName
= GetDefaultName();
807 aUniqueName
= aDefaultName
+ OUString::valueOf(++n
);
808 } while (xNameAcc
->hasByName(aUniqueName
));
814 //----------------------------------------------------------------------------
816 sal_uInt32
DlgEdObj::GetObjInventor() const
821 //----------------------------------------------------------------------------
823 sal_uInt16
DlgEdObj::GetObjIdentifier() const
825 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ))
827 return OBJ_DLG_DIALOG
;
829 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ))
831 return OBJ_DLG_PUSHBUTTON
;
833 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ))
835 return OBJ_DLG_RADIOBUTTON
;
837 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ))
839 return OBJ_DLG_CHECKBOX
;
841 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ))
843 return OBJ_DLG_LISTBOX
;
845 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ))
847 return OBJ_DLG_COMBOBOX
;
849 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ))
851 return OBJ_DLG_GROUPBOX
;
853 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ))
857 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ))
859 return OBJ_DLG_FIXEDTEXT
;
861 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ))
863 return OBJ_DLG_IMAGECONTROL
;
865 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ))
867 return OBJ_DLG_PROGRESSBAR
;
869 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ))
871 return OBJ_DLG_HSCROLLBAR
;
873 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ))
875 return OBJ_DLG_HFIXEDLINE
;
877 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ))
879 return OBJ_DLG_DATEFIELD
;
881 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ))
883 return OBJ_DLG_TIMEFIELD
;
885 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ))
887 return OBJ_DLG_NUMERICFIELD
;
889 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ))
891 return OBJ_DLG_CURRENCYFIELD
;
893 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ))
895 return OBJ_DLG_FORMATTEDFIELD
;
897 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ))
899 return OBJ_DLG_PATTERNFIELD
;
901 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ))
903 return OBJ_DLG_FILECONTROL
;
905 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ))
907 return OBJ_DLG_TREECONTROL
;
911 return OBJ_DLG_CONTROL
;
915 //----------------------------------------------------------------------------
917 void DlgEdObj::clonedFrom(const DlgEdObj
* _pSource
)
920 pDlgEdForm
= _pSource
->pDlgEdForm
;
922 // add child to parent form
923 pDlgEdForm
->AddChild( this );
925 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
929 OUString
aOUniqueName( GetUniqueName() );
931 aUniqueName
<<= aOUniqueName
;
932 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aUniqueName
);
934 Reference
< container::XNameContainer
> xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY
);
938 Sequence
< OUString
> aNames
= xCont
->getElementNames();
940 aTabIndex
<<= (sal_Int16
) aNames
.getLength();
941 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
943 // insert control model in dialog model
944 Reference
< awt::XControlModel
> xCtrl( xPSet
, UNO_QUERY
);
947 xCont
->insertByName( aOUniqueName
, aCtrl
);
950 pDlgEdForm
->UpdateTabOrderAndGroups();
958 //----------------------------------------------------------------------------
960 DlgEdObj
* DlgEdObj::Clone() const
962 DlgEdObj
* pDlgEdObj
= CloneHelper
< DlgEdObj
>();
963 DBG_ASSERT( pDlgEdObj
!= NULL
, "DlgEdObj::Clone: invalid clone!" );
965 pDlgEdObj
->clonedFrom( this );
970 //----------------------------------------------------------------------------
972 SdrObject
* DlgEdObj::getFullDragClone() const
974 // no need to really add the clone for dragging, it's a temporary
976 SdrObject
* pObj
= new SdrUnoObj(String());
977 *pObj
= *((const SdrUnoObj
*)this);
982 //----------------------------------------------------------------------------
984 void DlgEdObj::NbcMove( const Size
& rSize
)
986 SdrUnoObj::NbcMove( rSize
);
991 // set geometry properties
997 // dialog model changed
998 GetDlgEdForm()->GetDlgEditor().SetDialogModelChanged(true);
1001 //----------------------------------------------------------------------------
1003 void DlgEdObj::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
1005 SdrUnoObj::NbcResize( rRef
, xFract
, yFract
);
1008 EndListening(false);
1010 // set geometry properties
1016 // dialog model changed
1017 GetDlgEdForm()->GetDlgEditor().SetDialogModelChanged(true);
1020 //----------------------------------------------------------------------------
1022 bool DlgEdObj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
1024 bool bResult
= SdrUnoObj::EndCreate(rStat
, eCmd
);
1032 //----------------------------------------------------------------------------
1034 void DlgEdObj::SetDefaults()
1037 pDlgEdForm
= ((DlgEdPage
*)GetPage())->GetDlgEdForm();
1041 // add child to parent form
1042 pDlgEdForm
->AddChild( this );
1044 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
1048 OUString
aOUniqueName( GetUniqueName() );
1050 // set name property
1052 aUniqueName
<<= aOUniqueName
;
1053 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aUniqueName
);
1056 if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) ||
1057 supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) ||
1058 supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) ||
1059 supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) ||
1060 supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
1062 xPSet
->setPropertyValue( DLGED_PROP_LABEL
, aUniqueName
);
1065 // set number formats supplier for formatted field
1066 if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
1068 Reference
< util::XNumberFormatsSupplier
> xSupplier
= GetDlgEdForm()->GetDlgEditor().GetNumberFormatsSupplier();
1069 if ( xSupplier
.is() )
1072 aSupplier
<<= xSupplier
;
1073 xPSet
->setPropertyValue( DLGED_PROP_FORMATSSUPPLIER
, aSupplier
);
1077 // set geometry properties
1080 Reference
< container::XNameContainer
> xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY
);
1084 Sequence
< OUString
> aNames
= xCont
->getElementNames();
1086 aTabIndex
<<= (sal_Int16
) aNames
.getLength();
1087 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
1090 Reference
< beans::XPropertySet
> xPSetForm( xCont
, UNO_QUERY
);
1091 if ( xPSetForm
.is() )
1093 Any aStep
= xPSetForm
->getPropertyValue( DLGED_PROP_STEP
);
1094 xPSet
->setPropertyValue( DLGED_PROP_STEP
, aStep
);
1097 // insert control model in dialog model
1098 Reference
< awt::XControlModel
> xCtrl( xPSet
, UNO_QUERY
);
1101 xCont
->insertByName( aOUniqueName
, aAny
);
1103 LocalizationMgr::setControlResourceIDsForNewEditorObject(
1104 &GetDialogEditor(), aAny
, aOUniqueName
1108 pDlgEdForm
->UpdateTabOrderAndGroups();
1112 // dialog model changed
1113 pDlgEdForm
->GetDlgEditor().SetDialogModelChanged(true);
1117 //----------------------------------------------------------------------------
1119 void DlgEdObj::StartListening()
1121 DBG_ASSERT(!isListening(), "DlgEdObj::StartListening: already listening!");
1125 bIsListening
= true;
1127 // XPropertyChangeListener
1128 Reference
< XPropertySet
> xControlModel( GetUnoControlModel() , UNO_QUERY
);
1129 if (!m_xPropertyChangeListener
.is() && xControlModel
.is())
1132 m_xPropertyChangeListener
= new DlgEdPropListenerImpl(*this);
1134 // register listener to properties
1135 xControlModel
->addPropertyChangeListener( OUString() , m_xPropertyChangeListener
);
1138 // XContainerListener
1139 Reference
< XScriptEventsSupplier
> xEventsSupplier( GetUnoControlModel() , UNO_QUERY
);
1140 if( !m_xContainerListener
.is() && xEventsSupplier
.is() )
1143 m_xContainerListener
= new DlgEdEvtContListenerImpl(*this);
1145 // register listener to script event container
1146 Reference
< XNameContainer
> xEventCont
= xEventsSupplier
->getEvents();
1147 DBG_ASSERT(xEventCont
.is(), "DlgEdObj::StartListening: control model has no script event container!");
1148 Reference
< XContainer
> xCont( xEventCont
, UNO_QUERY
);
1150 xCont
->addContainerListener( m_xContainerListener
);
1155 //----------------------------------------------------------------------------
1157 void DlgEdObj::EndListening(bool bRemoveListener
)
1159 DBG_ASSERT(isListening(), "DlgEdObj::EndListening: not listening currently!");
1163 bIsListening
= false;
1165 if (bRemoveListener
)
1167 // XPropertyChangeListener
1168 Reference
< XPropertySet
> xControlModel(GetUnoControlModel(), UNO_QUERY
);
1169 if ( m_xPropertyChangeListener
.is() && xControlModel
.is() )
1172 xControlModel
->removePropertyChangeListener( OUString() , m_xPropertyChangeListener
);
1174 m_xPropertyChangeListener
.clear();
1176 // XContainerListener
1177 Reference
< XScriptEventsSupplier
> xEventsSupplier( GetUnoControlModel() , UNO_QUERY
);
1178 if( m_xContainerListener
.is() && xEventsSupplier
.is() )
1181 Reference
< XNameContainer
> xEventCont
= xEventsSupplier
->getEvents();
1182 DBG_ASSERT(xEventCont
.is(), "DlgEdObj::EndListening: control model has no script event container!");
1183 Reference
< XContainer
> xCont( xEventCont
, UNO_QUERY
);
1185 xCont
->removeContainerListener( m_xContainerListener
);
1187 m_xContainerListener
.clear();
1192 //----------------------------------------------------------------------------
1194 void SAL_CALL
DlgEdObj::_propertyChange( const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw( ::com::sun::star::uno::RuntimeException
)
1198 DlgEdForm
* pRealDlgEdForm
= dynamic_cast<DlgEdForm
*>(this);
1199 if (!pRealDlgEdForm
)
1200 pRealDlgEdForm
= GetDlgEdForm();
1201 if (!pRealDlgEdForm
)
1203 DlgEditor
& rDlgEditor
= pRealDlgEdForm
->GetDlgEditor();
1204 if (rDlgEditor
.isInPaint())
1207 // dialog model changed
1208 rDlgEditor
.SetDialogModelChanged(true);
1210 // update position and size
1211 if ( evt
.PropertyName
== DLGED_PROP_POSITIONX
|| evt
.PropertyName
== DLGED_PROP_POSITIONY
||
1212 evt
.PropertyName
== DLGED_PROP_WIDTH
|| evt
.PropertyName
== DLGED_PROP_HEIGHT
||
1213 evt
.PropertyName
== DLGED_PROP_DECORATION
)
1215 PositionAndSizeChange( evt
);
1217 if ( evt
.PropertyName
== DLGED_PROP_DECORATION
)
1218 GetDialogEditor().ResetDialog();
1220 // change name of control in dialog model
1221 else if ( evt
.PropertyName
== DLGED_PROP_NAME
)
1223 if (!dynamic_cast<DlgEdForm
*>(this))
1227 else if ( evt
.PropertyName
== DLGED_PROP_STEP
)
1232 else if ( evt
.PropertyName
== DLGED_PROP_TABINDEX
)
1234 if (!dynamic_cast<DlgEdForm
*>(this))
1235 TabIndexChange(evt
);
1240 //----------------------------------------------------------------------------
1242 void SAL_CALL
DlgEdObj::_elementInserted(const ::com::sun::star::container::ContainerEvent
& ) throw(::com::sun::star::uno::RuntimeException
)
1246 // dialog model changed
1247 GetDialogEditor().SetDialogModelChanged(true);
1251 //----------------------------------------------------------------------------
1253 void SAL_CALL
DlgEdObj::_elementReplaced(const ::com::sun::star::container::ContainerEvent
& ) throw(::com::sun::star::uno::RuntimeException
)
1257 // dialog model changed
1258 GetDialogEditor().SetDialogModelChanged(true);
1262 //----------------------------------------------------------------------------
1264 void SAL_CALL
DlgEdObj::_elementRemoved(const ::com::sun::star::container::ContainerEvent
& ) throw(::com::sun::star::uno::RuntimeException
)
1268 // dialog model changed
1269 GetDialogEditor().SetDialogModelChanged(true);
1273 //----------------------------------------------------------------------------
1275 void DlgEdObj::SetLayer(SdrLayerID nLayer
)
1277 SdrLayerID nOldLayer
= GetLayer();
1279 if ( nLayer
!= nOldLayer
)
1281 SdrUnoObj::SetLayer( nLayer
);
1283 DlgEdHint
aHint( DlgEdHint::LAYERCHANGED
, this );
1284 GetDlgEdForm()->GetDlgEditor().Broadcast( aHint
);
1288 //----------------------------------------------------------------------------
1290 TYPEINIT1(DlgEdForm
, DlgEdObj
);
1291 DBG_NAME(DlgEdForm
);
1293 //----------------------------------------------------------------------------
1295 DlgEdForm::DlgEdForm (DlgEditor
& rDlgEditor_
) :
1296 rDlgEditor(rDlgEditor_
)
1298 DBG_CTOR(DlgEdForm
, NULL
);
1301 //----------------------------------------------------------------------------
1303 DlgEdForm::~DlgEdForm()
1305 DBG_DTOR(DlgEdForm
, NULL
);
1308 //----------------------------------------------------------------------------
1310 void DlgEdForm::SetRectFromProps()
1312 // get form position and size from properties
1313 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
1316 sal_Int32 nXIn
= 0, nYIn
= 0, nWidthIn
= 0, nHeightIn
= 0;
1317 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nXIn
;
1318 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nYIn
;
1319 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidthIn
;
1320 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeightIn
;
1322 // transform coordinates
1323 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
1324 if ( TransformFormToSdrCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
1326 // set rectangle position and size
1327 Point
aPoint( nXOut
, nYOut
);
1328 Size
aSize( nWidthOut
, nHeightOut
);
1329 SetSnapRect( Rectangle( aPoint
, aSize
) );
1334 //----------------------------------------------------------------------------
1336 void DlgEdForm::SetPropsFromRect()
1338 // get form position and size from rectangle
1339 Rectangle aRect_
= GetSnapRect();
1340 sal_Int32 nXIn
= aRect_
.Left();
1341 sal_Int32 nYIn
= aRect_
.Top();
1342 sal_Int32 nWidthIn
= aRect_
.GetWidth();
1343 sal_Int32 nHeightIn
= aRect_
.GetHeight();
1345 // transform coordinates
1346 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
1347 if ( TransformSdrToFormCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
1350 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
1355 xPSet
->setPropertyValue( DLGED_PROP_POSITIONX
, aValue
);
1357 xPSet
->setPropertyValue( DLGED_PROP_POSITIONY
, aValue
);
1358 aValue
<<= nWidthOut
;
1359 xPSet
->setPropertyValue( DLGED_PROP_WIDTH
, aValue
);
1360 aValue
<<= nHeightOut
;
1361 xPSet
->setPropertyValue( DLGED_PROP_HEIGHT
, aValue
);
1366 //----------------------------------------------------------------------------
1368 void DlgEdForm::AddChild( DlgEdObj
* pDlgEdObj
)
1370 pChildren
.push_back( pDlgEdObj
);
1373 //----------------------------------------------------------------------------
1375 void DlgEdForm::RemoveChild( DlgEdObj
* pDlgEdObj
)
1377 pChildren
.erase( ::std::find( pChildren
.begin() , pChildren
.end() , pDlgEdObj
) );
1380 //----------------------------------------------------------------------------
1382 void DlgEdForm::PositionAndSizeChange( const beans::PropertyChangeEvent
& evt
)
1384 DlgEditor
& rEditor
= GetDlgEditor();
1385 DlgEdPage
& rPage
= rEditor
.GetPage();
1387 sal_Int32 nPageXIn
= 0;
1388 sal_Int32 nPageYIn
= 0;
1389 Size aPageSize
= rPage
.GetSize();
1390 sal_Int32 nPageWidthIn
= aPageSize
.Width();
1391 sal_Int32 nPageHeightIn
= aPageSize
.Height();
1392 sal_Int32 nPageX
, nPageY
, nPageWidth
, nPageHeight
;
1393 if ( TransformSdrToFormCoordinates( nPageXIn
, nPageYIn
, nPageWidthIn
, nPageHeightIn
, nPageX
, nPageY
, nPageWidth
, nPageHeight
) )
1395 Reference
< beans::XPropertySet
> xPSetForm( GetUnoControlModel(), UNO_QUERY
);
1396 if ( xPSetForm
.is() )
1398 sal_Int32 nValue
= 0;
1399 evt
.NewValue
>>= nValue
;
1400 sal_Int32 nNewValue
= nValue
;
1402 if ( evt
.PropertyName
== DLGED_PROP_POSITIONX
)
1404 if ( nNewValue
< nPageX
)
1407 else if ( evt
.PropertyName
== DLGED_PROP_POSITIONY
)
1409 if ( nNewValue
< nPageY
)
1412 else if ( evt
.PropertyName
== DLGED_PROP_WIDTH
)
1414 if ( nNewValue
< 1 )
1417 else if ( evt
.PropertyName
== DLGED_PROP_HEIGHT
)
1419 if ( nNewValue
< 1 )
1423 if ( nNewValue
!= nValue
)
1426 aNewValue
<<= nNewValue
;
1427 EndListening( false );
1428 xPSetForm
->setPropertyValue( evt
.PropertyName
, aNewValue
);
1434 bool bAdjustedPageSize
= rEditor
.AdjustPageSize();
1436 std::vector
<DlgEdObj
*> const& aChildList
= ((DlgEdForm
*)this)->GetChildren();
1437 std::vector
<DlgEdObj
*>::const_iterator aIter
;
1439 if ( bAdjustedPageSize
)
1441 rEditor
.InitScrollBars();
1442 aPageSize
= rPage
.GetSize();
1443 nPageWidthIn
= aPageSize
.Width();
1444 nPageHeightIn
= aPageSize
.Height();
1445 if ( TransformSdrToControlCoordinates( nPageXIn
, nPageYIn
, nPageWidthIn
, nPageHeightIn
, nPageX
, nPageY
, nPageWidth
, nPageHeight
) )
1447 for ( aIter
= aChildList
.begin(); aIter
!= aChildList
.end(); ++aIter
)
1449 Reference
< beans::XPropertySet
> xPSet( (*aIter
)->GetUnoControlModel(), UNO_QUERY
);
1452 sal_Int32 nX
= 0, nY
= 0, nWidth
= 0, nHeight
= 0;
1453 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nX
;
1454 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nY
;
1455 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidth
;
1456 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeight
;
1458 sal_Int32 nNewX
= nX
;
1459 if ( nX
+ nWidth
> nPageX
+ nPageWidth
)
1461 nNewX
= nPageX
+ nPageWidth
- nWidth
;
1462 if ( nNewX
< nPageX
)
1469 EndListening( false );
1470 xPSet
->setPropertyValue( DLGED_PROP_POSITIONX
, aValue
);
1474 sal_Int32 nNewY
= nY
;
1475 if ( nY
+ nHeight
> nPageY
+ nPageHeight
)
1477 nNewY
= nPageY
+ nPageHeight
- nHeight
;
1478 if ( nNewY
< nPageY
)
1485 EndListening( false );
1486 xPSet
->setPropertyValue( DLGED_PROP_POSITIONY
, aValue
);
1494 for ( aIter
= aChildList
.begin(); aIter
!= aChildList
.end(); ++aIter
)
1495 (*aIter
)->SetRectFromProps();
1498 //----------------------------------------------------------------------------
1500 void DlgEdForm::UpdateStep()
1502 sal_uLong nObjCount
;
1503 SdrPage
* pSdrPage
= GetPage();
1505 if ( pSdrPage
&& ( ( nObjCount
= pSdrPage
->GetObjCount() ) > 0 ) )
1507 for ( sal_uLong i
= 0 ; i
< nObjCount
; i
++ )
1509 DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pSdrPage
->GetObj(i
));
1510 if (pDlgEdObj
&& !dynamic_cast<DlgEdForm
*>(pDlgEdObj
))
1511 pDlgEdObj
->UpdateStep();
1516 //----------------------------------------------------------------------------
1518 void DlgEdForm::UpdateTabIndices()
1520 // stop listening with all children
1521 ::std::vector
<DlgEdObj
*>::iterator aIter
;
1522 for ( aIter
= pChildren
.begin() ; aIter
!= pChildren
.end() ; ++aIter
)
1524 (*aIter
)->EndListening( false );
1527 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc( GetUnoControlModel() , UNO_QUERY
);
1528 if ( xNameAcc
.is() )
1530 // get sequence of control names
1531 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
1532 const OUString
* pNames
= aNames
.getConstArray();
1533 sal_Int32 nCtrls
= aNames
.getLength();
1535 // create a map of tab indices and control names, sorted by tab index
1536 IndexToNameMap aIndexToNameMap
;
1537 for ( sal_Int16 i
= 0; i
< nCtrls
; ++i
)
1540 OUString
aName( pNames
[i
] );
1543 sal_Int16 nTabIndex
= -1;
1544 Any aCtrl
= xNameAcc
->getByName( aName
);
1545 Reference
< ::com::sun::star::beans::XPropertySet
> xPSet
;
1548 xPSet
->getPropertyValue( DLGED_PROP_TABINDEX
) >>= nTabIndex
;
1551 aIndexToNameMap
.insert( IndexToNameMap::value_type( nTabIndex
, aName
) );
1554 // set new tab indices
1555 sal_Int16 nNewTabIndex
= 0;
1556 for ( IndexToNameMap::iterator aIt
= aIndexToNameMap
.begin(); aIt
!= aIndexToNameMap
.end(); ++aIt
)
1558 Any aCtrl
= xNameAcc
->getByName( aIt
->second
);
1559 Reference
< beans::XPropertySet
> xPSet
;
1564 aTabIndex
<<= (sal_Int16
) nNewTabIndex
++;
1565 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
1570 UpdateTabOrderAndGroups();
1573 // start listening with all children
1574 for ( aIter
= pChildren
.begin() ; aIter
!= pChildren
.end() ; ++aIter
)
1576 (*aIter
)->StartListening();
1580 //----------------------------------------------------------------------------
1582 void DlgEdForm::UpdateTabOrder()
1585 // When the tabindex of a control model changes, the dialog control is
1586 // notified about those changes. Due to #109067# (bad performance of
1587 // dialog editor) the dialog control doesn't activate the tab order
1588 // in design mode. When the dialog editor has reordered all
1589 // tabindices, this method allows to activate the taborder afterwards.
1591 Reference
< awt::XUnoControlContainer
> xCont( GetControl(), UNO_QUERY
);
1594 Sequence
< Reference
< awt::XTabController
> > aSeqTabCtrls
= xCont
->getTabControllers();
1595 const Reference
< awt::XTabController
>* pTabCtrls
= aSeqTabCtrls
.getConstArray();
1596 sal_Int32 nCount
= aSeqTabCtrls
.getLength();
1597 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
1598 pTabCtrls
[i
]->activateTabOrder();
1602 //----------------------------------------------------------------------------
1604 void DlgEdForm::UpdateGroups()
1607 // The grouping of radio buttons in a dialog is done by vcl.
1608 // In the dialog editor we have two views (=controls) for one
1609 // radio button model. One control is owned by the dialog control,
1610 // but not visible in design mode. The other control is owned by
1611 // the drawing layer object. Whereas the grouping of the first
1612 // control is done by vcl, the grouping of the control in the
1613 // drawing layer has to be done here.
1615 Reference
< awt::XTabControllerModel
> xTabModel( GetUnoControlModel() , UNO_QUERY
);
1616 if ( xTabModel
.is() )
1618 // create a global list of controls that belong to the dialog
1619 ::std::vector
<DlgEdObj
*> aChildList
= GetChildren();
1620 sal_uInt32 nSize
= aChildList
.size();
1621 Sequence
< Reference
< awt::XControl
> > aSeqControls( nSize
);
1622 for ( sal_uInt32 i
= 0; i
< nSize
; ++i
)
1623 aSeqControls
.getArray()[i
] = Reference
< awt::XControl
>( aChildList
[i
]->GetControl(), UNO_QUERY
);
1625 sal_Int32 nGroupCount
= xTabModel
->getGroupCount();
1626 for ( sal_Int32 nGroup
= 0; nGroup
< nGroupCount
; ++nGroup
)
1628 // get a list of control models that belong to this group
1630 Sequence
< Reference
< awt::XControlModel
> > aSeqModels
;
1631 xTabModel
->getGroup( nGroup
, aSeqModels
, aName
);
1632 const Reference
< awt::XControlModel
>* pModels
= aSeqModels
.getConstArray();
1633 sal_Int32 nModelCount
= aSeqModels
.getLength();
1635 // create a list of peers that belong to this group
1636 Sequence
< Reference
< awt::XWindow
> > aSeqPeers( nModelCount
);
1637 for ( sal_Int32 nModel
= 0; nModel
< nModelCount
; ++nModel
)
1639 // for each control model find the corresponding control in the global list
1640 const Reference
< awt::XControl
>* pControls
= aSeqControls
.getConstArray();
1641 sal_Int32 nControlCount
= aSeqControls
.getLength();
1642 for ( sal_Int32 nControl
= 0; nControl
< nControlCount
; ++nControl
)
1644 const Reference
< awt::XControl
> xCtrl( pControls
[nControl
] );
1647 Reference
< awt::XControlModel
> xCtrlModel( xCtrl
->getModel() );
1648 if ( (awt::XControlModel
*)xCtrlModel
.get() == (awt::XControlModel
*)pModels
[nModel
].get() )
1650 // get the control peer and insert into the list of peers
1651 aSeqPeers
.getArray()[ nModel
] = Reference
< awt::XWindow
>( xCtrl
->getPeer(), UNO_QUERY
);
1658 // set the group at the dialog peer
1659 Reference
< awt::XControl
> xDlg( GetControl(), UNO_QUERY
);
1662 Reference
< awt::XVclContainerPeer
> xDlgPeer( xDlg
->getPeer(), UNO_QUERY
);
1663 if ( xDlgPeer
.is() )
1664 xDlgPeer
->setGroup( aSeqPeers
);
1670 //----------------------------------------------------------------------------
1672 void DlgEdForm::UpdateTabOrderAndGroups()
1678 //----------------------------------------------------------------------------
1680 void DlgEdForm::NbcMove( const Size
& rSize
)
1682 SdrUnoObj::NbcMove( rSize
);
1684 // set geometry properties of form
1685 EndListening(false);
1689 // set geometry properties of all children
1690 ::std::vector
<DlgEdObj
*>::iterator aIter
;
1691 for ( aIter
= pChildren
.begin() ; aIter
!= pChildren
.end() ; ++aIter
)
1693 (*aIter
)->EndListening(false);
1694 (*aIter
)->SetPropsFromRect();
1695 (*aIter
)->StartListening();
1698 // dialog model changed
1699 GetDlgEditor().SetDialogModelChanged(true);
1702 //----------------------------------------------------------------------------
1704 void DlgEdForm::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
1706 SdrUnoObj::NbcResize( rRef
, xFract
, yFract
);
1708 // set geometry properties of form
1709 EndListening(false);
1713 // set geometry properties of all children
1714 ::std::vector
<DlgEdObj
*>::iterator aIter
;
1715 for ( aIter
= pChildren
.begin() ; aIter
!= pChildren
.end() ; ++aIter
)
1717 (*aIter
)->EndListening(false);
1718 (*aIter
)->SetPropsFromRect();
1719 (*aIter
)->StartListening();
1722 // dialog model changed
1723 GetDlgEditor().SetDialogModelChanged(true);
1726 //----------------------------------------------------------------------------
1728 bool DlgEdForm::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
1730 bool bResult
= SdrUnoObj::EndCreate(rStat
, eCmd
);
1733 EndListening(false);
1735 // set geometry properties
1738 // dialog model changed
1739 GetDlgEditor().SetDialogModelChanged(true);
1747 //----------------------------------------------------------------------------
1749 awt::DeviceInfo
DlgEdForm::getDeviceInfo() const
1751 awt::DeviceInfo aDeviceInfo
;
1753 DlgEditor
& rEditor
= GetDlgEditor();
1754 Window
& rWindow
= rEditor
.GetWindow();
1756 // obtain an XControl
1757 ::utl::SharedUNOComponent
< awt::XControl
> xDialogControl
; // ensures auto-disposal, if needed
1758 xDialogControl
.reset( GetControl(), ::utl::SharedUNOComponent
< awt::XControl
>::NoTakeOwnership
);
1759 if ( !xDialogControl
.is() )
1761 // don't create a temporary control all the time, this method here is called
1762 // way too often. Instead, use a cached DeviceInfo.
1764 if ( !!mpDeviceInfo
)
1765 return *mpDeviceInfo
;
1767 Reference
< awt::XControlContainer
> xEditorControlContainer( rEditor
.GetWindowControlContainer() );
1768 xDialogControl
.reset(
1769 GetTemporaryControlForWindow(rWindow
, xEditorControlContainer
),
1770 utl::SharedUNOComponent
< awt::XControl
>::TakeOwnership
1774 Reference
< awt::XDevice
> xDialogDevice
;
1775 if ( xDialogControl
.is() )
1776 xDialogDevice
.set( xDialogControl
->getPeer(), UNO_QUERY
);
1777 DBG_ASSERT( xDialogDevice
.is(), "DlgEdForm::getDeviceInfo: no device!" );
1778 if ( xDialogDevice
.is() )
1779 aDeviceInfo
= xDialogDevice
->getInfo();
1781 mpDeviceInfo
.reset( aDeviceInfo
);
1785 bool DlgEdObj::MakeDataAware( const Reference
< frame::XModel
>& xModel
)
1788 // Need to flesh this out, currently we will only support data-aware controls for calc
1789 // and only handle a subset of functionality e.g. linked-cell and cell range data source. Of course later
1790 // we need to disambiguate for writer ( and others ? ) and also support the generic form (db) bindings
1791 // we need some more work in xmlscript to be able to handle that
1792 Reference
< lang::XMultiServiceFactory
> xFac( xModel
, UNO_QUERY
);
1793 Reference
< form::binding::XBindableValue
> xBindable( GetUnoControlModel(), UNO_QUERY
);
1794 Reference
< form::binding::XListEntrySink
> xListEntrySink( GetUnoControlModel(), UNO_QUERY
);
1797 if ( xBindable
.is() )
1799 Reference
< form::binding::XValueBinding
> xBinding( xFac
->createInstance( "com.sun.star.table.CellValueBinding" ), UNO_QUERY
);
1800 xBindable
->setValueBinding( xBinding
);
1802 if ( xListEntrySink
.is() )
1804 Reference
< form::binding::XListEntrySource
> xSource( xFac
->createInstance( "com.sun.star.table.CellRangeListSource" ), UNO_QUERY
);
1805 xListEntrySink
->setListEntrySource( xSource
);
1807 if ( xListEntrySink
.is() || xBindable
.is() )
1812 //----------------------------------------------------------------------------
1814 } // namespace basctl
1816 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */