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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
26 #include <dlgeddef.hxx>
27 #include <dlgedlist.hxx>
28 #include <dlgedobj.hxx>
29 #include <dlgedpage.hxx>
30 #include <dlgedview.hxx>
31 #include <localizationmgr.hxx>
32 #include <strings.hxx>
34 #include <com/sun/star/beans/NamedValue.hpp>
35 #include <com/sun/star/form/binding/XBindableValue.hpp>
36 #include <com/sun/star/form/binding/XValueBinding.hpp>
37 #include <com/sun/star/form/binding/XListEntrySink.hpp>
38 #include <com/sun/star/awt/XUnoControlContainer.hpp>
39 #include <com/sun/star/awt/XVclContainerPeer.hpp>
40 #include <com/sun/star/container/XContainer.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
43 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
44 #include <com/sun/star/table/CellAddress.hpp>
45 #include <com/sun/star/table/CellRangeAddress.hpp>
46 #include <cppuhelper/exc_hlp.hxx>
47 #include <o3tl/functional.hxx>
48 #include <svx/svdpagv.hxx>
49 #include <unotools/sharedunocomponent.hxx>
50 #include <vcl/svapp.hxx>
51 #include <tools/debug.hxx>
56 using namespace ::com::sun::star
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::beans
;
59 using namespace ::com::sun::star::container
;
60 using namespace ::com::sun::star::script
;
63 DlgEditor
& DlgEdObj::GetDialogEditor ()
65 if (DlgEdForm
* pFormThis
= dynamic_cast<DlgEdForm
*>(this))
66 return pFormThis
->GetDlgEditor();
68 return pDlgEdForm
->GetDlgEditor();
71 DlgEdObj::DlgEdObj(SdrModel
& rSdrModel
)
72 : SdrUnoObj(rSdrModel
, OUString())
77 DlgEdObj::DlgEdObj(SdrModel
& rSdrModel
, DlgEdObj
const & rSource
)
78 : SdrUnoObj(rSdrModel
, rSource
)
82 pDlgEdForm
= rSource
.pDlgEdForm
;
84 // add child to parent form
85 pDlgEdForm
->AddChild( this );
87 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
91 OUString
aOUniqueName( GetUniqueName() );
93 aUniqueName
<<= aOUniqueName
;
94 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aUniqueName
);
96 Reference
< container::XNameContainer
> xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY
);
100 Sequence
< OUString
> aNames
= xCont
->getElementNames();
101 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, Any(static_cast<sal_Int16
>(aNames
.getLength())) );
103 // insert control model in dialog model
104 Reference
< awt::XControlModel
> xCtrl( xPSet
, UNO_QUERY
);
105 xCont
->insertByName( aOUniqueName
, Any(xCtrl
) );
107 pDlgEdForm
->UpdateTabOrderAndGroups();
117 const OUString
& rModelName
,
118 const css::uno::Reference
< css::lang::XMultiServiceFactory
>& rxSFac
)
119 : SdrUnoObj(rSdrModel
, rModelName
, rxSFac
)
124 DlgEdObj::~DlgEdObj()
132 /* returns the DlgEdForm which the given DlgEdObj belongs to
133 (which might in fact be the object itself)
135 Failure to obtain the form will be reported with an assertion in the non-product
138 bool lcl_getDlgEdForm( DlgEdObj
* _pObject
, DlgEdForm
*& _out_pDlgEdForm
)
140 _out_pDlgEdForm
= dynamic_cast< DlgEdForm
* >( _pObject
);
141 if ( !_out_pDlgEdForm
)
142 _out_pDlgEdForm
= _pObject
->GetDlgEdForm();
143 DBG_ASSERT( _out_pDlgEdForm
, "lcl_getDlgEdForm: no form!" );
144 return ( _out_pDlgEdForm
!= nullptr );
148 uno::Reference
< awt::XControl
> DlgEdObj::GetControl() const
150 uno::Reference
< awt::XControl
> xControl
;
151 if (DlgEdForm
const* pForm
= GetDlgEdForm())
153 DlgEditor
const& rEditor
= pForm
->GetDlgEditor();
154 xControl
= GetUnoControl(rEditor
.GetView(), *rEditor
.GetWindow().GetOutDev());
159 bool DlgEdObj::TransformSdrToControlCoordinates(
160 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
161 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
163 // input position and size
164 Size
aPos( nXIn
, nYIn
);
165 Size
aSize( nWidthIn
, nHeightIn
);
168 DlgEdForm
* pForm
= nullptr;
169 if ( !lcl_getDlgEdForm( this, pForm
) )
171 tools::Rectangle aFormRect
= pForm
->GetSnapRect();
172 Size
aFormPos( aFormRect
.Left(), aFormRect
.Top() );
174 // convert 100th_mm to pixel
175 OutputDevice
* pDevice
= Application::GetDefaultDevice();
176 DBG_ASSERT( pDevice
, "DlgEdObj::TransformSdrToControlCoordinates: missing default device!" );
179 aPos
= pDevice
->LogicToPixel( aPos
, MapMode( MapUnit::Map100thMM
) );
180 aSize
= pDevice
->LogicToPixel( aSize
, MapMode( MapUnit::Map100thMM
) );
181 aFormPos
= pDevice
->LogicToPixel( aFormPos
, MapMode( MapUnit::Map100thMM
) );
183 // subtract form position
184 aPos
.AdjustWidth( -(aFormPos
.Width()) );
185 aPos
.AdjustHeight( -(aFormPos
.Height()) );
187 // take window borders into account
188 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
189 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
190 if ( !xPSetForm
.is() )
192 bool bDecoration
= true;
193 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
196 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
197 aPos
.AdjustWidth( -(aDeviceInfo
.LeftInset
) );
198 aPos
.AdjustHeight( -(aDeviceInfo
.TopInset
) );
201 // convert pixel to logic units
202 aPos
= pDevice
->PixelToLogic(aPos
, MapMode(MapUnit::MapAppFont
));
203 aSize
= pDevice
->PixelToLogic(aSize
, MapMode(MapUnit::MapAppFont
));
205 // set out parameters
206 nXOut
= aPos
.Width();
207 nYOut
= aPos
.Height();
208 nWidthOut
= aSize
.Width();
209 nHeightOut
= aSize
.Height();
214 bool DlgEdObj::TransformSdrToFormCoordinates(
215 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
216 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
218 // input position and size
219 Size
aPos( nXIn
, nYIn
);
220 Size
aSize( nWidthIn
, nHeightIn
);
222 // convert 100th_mm to pixel
223 OutputDevice
* pDevice
= Application::GetDefaultDevice();
224 DBG_ASSERT( pDevice
, "DlgEdObj::TransformSdrToFormCoordinates: missing default device!" );
227 aPos
= pDevice
->LogicToPixel( aPos
, MapMode( MapUnit::Map100thMM
) );
228 aSize
= pDevice
->LogicToPixel( aSize
, MapMode( MapUnit::Map100thMM
) );
230 // take window borders into account
231 DlgEdForm
* pForm
= nullptr;
232 if ( !lcl_getDlgEdForm( this, pForm
) )
235 // take window borders into account
236 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
237 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
238 if ( !xPSetForm
.is() )
240 bool bDecoration
= true;
241 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
244 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
245 aSize
.AdjustWidth( -(aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
) );
246 aSize
.AdjustHeight( -(aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
) );
248 // convert pixel to logic units
249 aPos
= pDevice
->PixelToLogic(aPos
, MapMode(MapUnit::MapAppFont
));
250 aSize
= pDevice
->PixelToLogic(aSize
, MapMode(MapUnit::MapAppFont
));
252 // set out parameters
253 nXOut
= aPos
.Width();
254 nYOut
= aPos
.Height();
255 nWidthOut
= aSize
.Width();
256 nHeightOut
= aSize
.Height();
261 bool DlgEdObj::TransformControlToSdrCoordinates(
262 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
263 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
265 // input position and size
266 Size
aPos( nXIn
, nYIn
);
267 Size
aSize( nWidthIn
, nHeightIn
);
270 DlgEdForm
* pForm
= nullptr;
271 if ( !lcl_getDlgEdForm( this, pForm
) )
274 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
275 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformControlToSdrCoordinates: no form property set!" );
276 if ( !xPSetForm
.is() )
278 sal_Int32 nFormX
= 0, nFormY
= 0;
279 xPSetForm
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nFormX
;
280 xPSetForm
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nFormY
;
281 Size
aFormPos( nFormX
, nFormY
);
283 // convert logic units to pixel
284 OutputDevice
* pDevice
= Application::GetDefaultDevice();
285 DBG_ASSERT( pDevice
, "DlgEdObj::TransformControlToSdrCoordinates: missing default device!" );
288 aPos
= pDevice
->LogicToPixel(aPos
, MapMode(MapUnit::MapAppFont
));
289 aSize
= pDevice
->LogicToPixel(aSize
, MapMode(MapUnit::MapAppFont
));
290 aFormPos
= pDevice
->LogicToPixel(aFormPos
, MapMode(MapUnit::MapAppFont
));
293 aPos
.AdjustWidth(aFormPos
.Width() );
294 aPos
.AdjustHeight(aFormPos
.Height() );
296 // take window borders into account
297 bool bDecoration
= true;
298 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
301 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
302 aPos
.AdjustWidth(aDeviceInfo
.LeftInset
);
303 aPos
.AdjustHeight(aDeviceInfo
.TopInset
);
306 // convert pixel to 100th_mm
307 aPos
= pDevice
->PixelToLogic( aPos
, MapMode( MapUnit::Map100thMM
) );
308 aSize
= pDevice
->PixelToLogic( aSize
, MapMode( MapUnit::Map100thMM
) );
310 // set out parameters
311 nXOut
= aPos
.Width();
312 nYOut
= aPos
.Height();
313 nWidthOut
= aSize
.Width();
314 nHeightOut
= aSize
.Height();
319 bool DlgEdObj::TransformFormToSdrCoordinates(
320 sal_Int32 nXIn
, sal_Int32 nYIn
, sal_Int32 nWidthIn
, sal_Int32 nHeightIn
,
321 sal_Int32
& nXOut
, sal_Int32
& nYOut
, sal_Int32
& nWidthOut
, sal_Int32
& nHeightOut
)
323 // input position and size
324 Size
aPos( nXIn
, nYIn
);
325 Size
aSize( nWidthIn
, nHeightIn
);
327 // convert logic units to pixel
328 OutputDevice
* pDevice
= Application::GetDefaultDevice();
329 DBG_ASSERT( pDevice
, "DlgEdObj::TransformFormToSdrCoordinates: missing default device!" );
333 // take window borders into account
334 DlgEdForm
* pForm
= nullptr;
335 if ( !lcl_getDlgEdForm( this, pForm
) )
338 aPos
= pDevice
->LogicToPixel(aPos
, MapMode(MapUnit::MapAppFont
));
339 aSize
= pDevice
->LogicToPixel(aSize
, MapMode(MapUnit::MapAppFont
));
341 // take window borders into account
342 Reference
< beans::XPropertySet
> xPSetForm( pForm
->GetUnoControlModel(), UNO_QUERY
);
343 DBG_ASSERT( xPSetForm
.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
344 if ( !xPSetForm
.is() )
346 bool bDecoration
= true;
347 xPSetForm
->getPropertyValue( DLGED_PROP_DECORATION
) >>= bDecoration
;
350 awt::DeviceInfo aDeviceInfo
= pForm
->getDeviceInfo();
351 aSize
.AdjustWidth(aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
);
352 aSize
.AdjustHeight(aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
);
355 // convert pixel to 100th_mm
356 aPos
= pDevice
->PixelToLogic( aPos
, MapMode( MapUnit::Map100thMM
) );
357 aSize
= pDevice
->PixelToLogic( aSize
, MapMode( MapUnit::Map100thMM
) );
359 // set out parameters
360 nXOut
= aPos
.Width();
361 nYOut
= aPos
.Height();
362 nWidthOut
= aSize
.Width();
363 nHeightOut
= aSize
.Height();
368 void DlgEdObj::SetRectFromProps()
370 // get control position and size from properties
371 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
375 sal_Int32 nXIn
= 0, nYIn
= 0, nWidthIn
= 0, nHeightIn
= 0;
376 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nXIn
;
377 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nYIn
;
378 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidthIn
;
379 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeightIn
;
381 // transform coordinates
382 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
383 if ( TransformControlToSdrCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
385 // set rectangle position and size
386 Point
aPoint( nXOut
, nYOut
);
387 Size
aSize( nWidthOut
, nHeightOut
);
388 SetSnapRect( tools::Rectangle( aPoint
, aSize
) );
392 void DlgEdObj::SetPropsFromRect()
394 // get control position and size from rectangle
395 tools::Rectangle aRect_
= GetSnapRect();
396 sal_Int32 nXIn
= aRect_
.Left();
397 sal_Int32 nYIn
= aRect_
.Top();
398 sal_Int32 nWidthIn
= aRect_
.GetWidth();
399 sal_Int32 nHeightIn
= aRect_
.GetHeight();
401 // transform coordinates
402 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
403 if ( TransformSdrToControlCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
406 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
409 xPSet
->setPropertyValue( DLGED_PROP_POSITIONX
, Any(nXOut
) );
410 xPSet
->setPropertyValue( DLGED_PROP_POSITIONY
, Any(nYOut
) );
411 xPSet
->setPropertyValue( DLGED_PROP_WIDTH
, Any(nWidthOut
) );
412 xPSet
->setPropertyValue( DLGED_PROP_HEIGHT
, Any(nHeightOut
) );
417 void DlgEdObj::PositionAndSizeChange( const beans::PropertyChangeEvent
& evt
)
419 DBG_ASSERT( pDlgEdForm
, "DlgEdObj::PositionAndSizeChange: no form!" );
420 DlgEdPage
& rPage
= pDlgEdForm
->GetDlgEditor().GetPage();
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( 0/*nPageXIn*/, 0/*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
)
472 EndListening( false );
473 xPSet
->setPropertyValue( evt
.PropertyName
, Any(nNewValue
) );
483 void DlgEdObj::NameChange( const css::beans::PropertyChangeEvent
& evt
)
487 evt
.OldValue
>>= aOldName
;
491 evt
.NewValue
>>= aNewName
;
493 if ( aNewName
== aOldName
)
496 Reference
< container::XNameAccess
> xNameAcc((GetDlgEdForm()->GetUnoControlModel()), UNO_QUERY
);
497 if ( !(xNameAcc
.is() && xNameAcc
->hasByName(aOldName
)) )
500 if (!xNameAcc
->hasByName(aNewName
) && !aNewName
.isEmpty())
502 // remove the control by the old name and insert the control by the new name in the container
503 Reference
< container::XNameContainer
> xCont(xNameAcc
, UNO_QUERY
);
506 Reference
< awt::XControlModel
> xCtrl
= GetUnoControlModel();
509 xCont
->removeByName( aOldName
);
510 xCont
->insertByName( aNewName
, aAny
);
512 LocalizationMgr::renameControlResourceIDsForEditorObject(
513 &GetDialogEditor(), aAny
, aNewName
519 // set old name property
521 Reference
< beans::XPropertySet
> xPSet(GetUnoControlModel(), UNO_QUERY
);
522 xPSet
->setPropertyValue( DLGED_PROP_NAME
, Any(aOldName
) );
527 sal_Int32
DlgEdObj::GetStep() const
531 uno::Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), uno::UNO_QUERY
);
534 xPSet
->getPropertyValue( DLGED_PROP_STEP
) >>= nStep
;
539 void DlgEdObj::UpdateStep()
541 sal_Int32 nCurStep
= GetDlgEdForm()->GetStep();
542 sal_Int32 nStep
= GetStep();
544 SdrLayerAdmin
& rLayerAdmin(getSdrModelFromSdrObject().GetLayerAdmin());
545 SdrLayerID nHiddenLayerId
= rLayerAdmin
.GetLayerID( "HiddenLayer" );
546 SdrLayerID nControlLayerId
= rLayerAdmin
.GetLayerID( rLayerAdmin
.GetControlLayerName() );
550 if ( nStep
&& (nStep
!= nCurStep
) )
552 SetLayer( nHiddenLayerId
);
556 SetLayer( nControlLayerId
);
561 SetLayer( nControlLayerId
);
565 void DlgEdObj::TabIndexChange( const beans::PropertyChangeEvent
& evt
)
567 DlgEdForm
* pForm
= GetDlgEdForm();
571 // stop listening with all children
572 std::vector
<DlgEdObj
*> aChildList
= pForm
->GetChildren();
573 for (auto const& child
: aChildList
)
575 child
->EndListening( false );
578 Reference
< container::XNameAccess
> xNameAcc( pForm
->GetUnoControlModel() , UNO_QUERY
);
581 // get sequence of control names
582 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
583 const OUString
* pNames
= aNames
.getConstArray();
584 sal_Int32 nCtrls
= aNames
.getLength();
586 // create a map of tab indices and control names, sorted by tab index
587 IndexToNameMap aIndexToNameMap
;
588 for ( sal_Int32 i
= 0; i
< nCtrls
; ++i
)
591 OUString
aName( pNames
[i
] );
594 sal_Int16 nTabIndex
= -1;
595 Any aCtrl
= xNameAcc
->getByName( aName
);
596 Reference
< beans::XPropertySet
> xPSet
;
598 if ( xPSet
.is() && xPSet
== Reference
< beans::XPropertySet
>( evt
.Source
, UNO_QUERY
) )
599 evt
.OldValue
>>= nTabIndex
;
600 else if ( xPSet
.is() )
601 xPSet
->getPropertyValue( DLGED_PROP_TABINDEX
) >>= nTabIndex
;
604 aIndexToNameMap
.emplace( nTabIndex
, aName
);
607 // create a helper list of control names, sorted by tab index
608 std::vector
< OUString
> aNameList( aIndexToNameMap
.size() );
610 aIndexToNameMap
.begin(), aIndexToNameMap
.end(),
612 ::o3tl::select2nd
< IndexToNameMap::value_type
>( )
616 sal_Int16 nOldTabIndex
= 0;
617 evt
.OldValue
>>= nOldTabIndex
;
618 sal_Int16 nNewTabIndex
= 0;
619 evt
.NewValue
>>= nNewTabIndex
;
620 if ( nNewTabIndex
< 0 )
622 else if ( nNewTabIndex
> nCtrls
- 1 )
623 nNewTabIndex
= sal::static_int_cast
<sal_Int16
>( nCtrls
- 1 );
625 // reorder helper list
626 OUString aCtrlName
= aNameList
[nOldTabIndex
];
627 aNameList
.erase( aNameList
.begin() + nOldTabIndex
);
628 aNameList
.insert( aNameList
.begin() + nNewTabIndex
, aCtrlName
);
630 // set new tab indices
631 for ( sal_Int32 i
= 0; i
< nCtrls
; ++i
)
633 Any aCtrl
= xNameAcc
->getByName( aNameList
[i
] );
634 Reference
< beans::XPropertySet
> xPSet
;
638 assert(i
>= SAL_MIN_INT16
);
639 if (i
> SAL_MAX_INT16
)
641 SAL_WARN("basctl", "tab " << i
<< " > SAL_MAX_INT16");
644 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, Any(static_cast<sal_Int16
>(i
)) );
648 // reorder objects in drawing page
649 getSdrModelFromSdrObject().GetPage(0)->SetObjectOrdNum( nOldTabIndex
+ 1, nNewTabIndex
+ 1 );
651 pForm
->UpdateTabOrderAndGroups();
654 // start listening with all children
655 for (auto const& child
: aChildList
)
657 child
->StartListening();
661 bool DlgEdObj::supportsService( OUString
const & serviceName
) const
663 bool bSupports
= false;
665 Reference
< lang::XServiceInfo
> xServiceInfo( GetUnoControlModel() , UNO_QUERY
);
666 // TODO: cache xServiceInfo as member?
667 if ( xServiceInfo
.is() )
668 bSupports
= xServiceInfo
->supportsService( serviceName
);
673 OUString
DlgEdObj::GetDefaultName() const
676 OUString aDefaultName
;
677 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
679 sResId
= RID_STR_CLASS_DIALOG
;
681 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
683 sResId
= RID_STR_CLASS_BUTTON
;
685 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
687 sResId
= RID_STR_CLASS_RADIOBUTTON
;
689 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
691 sResId
= RID_STR_CLASS_CHECKBOX
;
693 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
695 sResId
= RID_STR_CLASS_LISTBOX
;
697 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
699 sResId
= RID_STR_CLASS_COMBOBOX
;
701 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
703 sResId
= RID_STR_CLASS_GROUPBOX
;
705 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
707 sResId
= RID_STR_CLASS_EDIT
;
709 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
711 sResId
= RID_STR_CLASS_FIXEDTEXT
;
713 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
715 sResId
= RID_STR_CLASS_IMAGECONTROL
;
717 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
719 sResId
= RID_STR_CLASS_PROGRESSBAR
;
721 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
723 sResId
= RID_STR_CLASS_SCROLLBAR
;
725 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
727 sResId
= RID_STR_CLASS_FIXEDLINE
;
729 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
731 sResId
= RID_STR_CLASS_DATEFIELD
;
733 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
735 sResId
= RID_STR_CLASS_TIMEFIELD
;
737 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
739 sResId
= RID_STR_CLASS_NUMERICFIELD
;
741 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
743 sResId
= RID_STR_CLASS_CURRENCYFIELD
;
745 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
747 sResId
= RID_STR_CLASS_FORMATTEDFIELD
;
749 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
751 sResId
= RID_STR_CLASS_PATTERNFIELD
;
753 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
755 sResId
= RID_STR_CLASS_FILECONTROL
;
757 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
759 sResId
= RID_STR_CLASS_TREECONTROL
;
761 else if ( supportsService( "com.sun.star.awt.grid.UnoControlGridModel" ) )
763 sResId
= RID_STR_CLASS_GRIDCONTROL
;
765 else if ( supportsService( "com.sun.star.awt.UnoControlFixedHyperlinkModel" ) )
767 sResId
= RID_STR_CLASS_HYPERLINKCONTROL
;
769 else if ( supportsService( "com.sun.star.awt.UnoControlSpinButtonModel" ) )
771 sResId
= RID_STR_CLASS_SPINCONTROL
;
775 sResId
= RID_STR_CLASS_CONTROL
;
778 if (!sResId
.isEmpty())
779 aDefaultName
= sResId
;
784 OUString
DlgEdObj::GetUniqueName() const
786 OUString aUniqueName
;
787 uno::Reference
< container::XNameAccess
> xNameAcc((GetDlgEdForm()->GetUnoControlModel()), uno::UNO_QUERY
);
792 OUString aDefaultName
= GetDefaultName();
796 aUniqueName
= aDefaultName
+ OUString::number(++n
);
797 } while (xNameAcc
->hasByName(aUniqueName
));
803 SdrInventor
DlgEdObj::GetObjInventor() const
805 return SdrInventor::BasicDialog
;
808 SdrObjKind
DlgEdObj::GetObjIdentifier() const
810 if ( supportsService( "com.sun.star.awt.UnoControlDialogModel" ))
812 return SdrObjKind::BasicDialogDialog
;
814 else if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ))
816 return SdrObjKind::BasicDialogPushButton
;
818 else if ( supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ))
820 return SdrObjKind::BasicDialogRadioButton
;
822 else if ( supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ))
824 return SdrObjKind::BasicDialogCheckbox
;
826 else if ( supportsService( "com.sun.star.awt.UnoControlListBoxModel" ))
828 return SdrObjKind::BasicDialogListbox
;
830 else if ( supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ))
832 return SdrObjKind::BasicDialogCombobox
;
834 else if ( supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ))
836 return SdrObjKind::BasicDialogGroupBox
;
838 else if ( supportsService( "com.sun.star.awt.UnoControlEditModel" ))
840 return SdrObjKind::BasicDialogEdit
;
842 else if ( supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ))
844 return SdrObjKind::BasicDialogFixedText
;
846 else if ( supportsService( "com.sun.star.awt.UnoControlImageControlModel" ))
848 return SdrObjKind::BasicDialogImageControl
;
850 else if ( supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ))
852 return SdrObjKind::BasicDialogProgressbar
;
854 else if ( supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ))
856 return SdrObjKind::BasicDialogHorizontalScrollbar
;
858 else if ( supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ))
860 return SdrObjKind::BasicDialogHorizontalFixedLine
;
862 else if ( supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ))
864 return SdrObjKind::BasicDialogDateField
;
866 else if ( supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ))
868 return SdrObjKind::BasicDialogTimeField
;
870 else if ( supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ))
872 return SdrObjKind::BasicDialogNumericField
;
874 else if ( supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ))
876 return SdrObjKind::BasicDialogCurencyField
;
878 else if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ))
880 return SdrObjKind::BasicDialogFormattedField
;
882 else if ( supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ))
884 return SdrObjKind::BasicDialogPatternField
;
886 else if ( supportsService( "com.sun.star.awt.UnoControlFileControlModel" ))
888 return SdrObjKind::BasicDialogFileControl
;
890 else if ( supportsService( "com.sun.star.awt.tree.TreeControlModel" ))
892 return SdrObjKind::BasicDialogTreeControl
;
894 else if ( supportsService( "com.sun.star.awt.grid.UnoControlGridModel" ))
896 return SdrObjKind::BasicDialogGridControl
;
898 else if ( supportsService( "com.sun.star.awt.UnoControlFixedHyperlinkModel" ))
900 return SdrObjKind::BasicDialogHyperlinkControl
;
904 return SdrObjKind::BasicDialogControl
;
908 rtl::Reference
<SdrObject
> DlgEdObj::CloneSdrObject(SdrModel
& rTargetModel
) const
910 return new DlgEdObj(rTargetModel
, *this);
913 rtl::Reference
<SdrObject
> DlgEdObj::getFullDragClone() const
915 // no need to really add the clone for dragging, it's a temporary
917 return rtl::Reference
<SdrObject
>(new SdrUnoObj(getSdrModelFromSdrObject(), *this));
920 void DlgEdObj::NbcMove( const Size
& rSize
)
922 SdrUnoObj::NbcMove( rSize
);
927 // set geometry properties
933 // dialog model changed
934 GetDlgEdForm()->GetDlgEditor().SetDialogModelChanged();
937 void DlgEdObj::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
939 SdrUnoObj::NbcResize( rRef
, xFract
, yFract
);
944 // set geometry properties
950 // dialog model changed
951 GetDlgEdForm()->GetDlgEditor().SetDialogModelChanged();
954 bool DlgEdObj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
956 bool bResult
= SdrUnoObj::EndCreate(rStat
, eCmd
);
958 // tdf#120674 after interactive creation, the SdrObject (this) has no SdrPage yet
959 // due to not being inserted. Usually this should be handled in a ::handlePageChange
960 // implementation. For historical reasons, the SdrPage (which is the DlgEdPage) was
961 // already set. For now, get it from the SdrDragStat and use it to access and set
962 // the local pDlgEdForm
963 if(!pDlgEdForm
&& nullptr != rStat
.GetPageView())
965 const DlgEdPage
* pDlgEdPage(dynamic_cast<const DlgEdPage
*>(rStat
.GetPageView()->GetPage()));
967 if(nullptr != pDlgEdPage
)
970 pDlgEdForm
= pDlgEdPage
->GetDlgEdForm();
980 void DlgEdObj::SetDefaults()
985 // add child to parent form
986 pDlgEdForm
->AddChild( this );
988 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
992 OUString
aOUniqueName( GetUniqueName() );
995 xPSet
->setPropertyValue( DLGED_PROP_NAME
, Any(aOUniqueName
) );
998 if ( supportsService( "com.sun.star.awt.UnoControlButtonModel" ) ||
999 supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) ||
1000 supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) ||
1001 supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) ||
1002 supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
1004 xPSet
->setPropertyValue( DLGED_PROP_LABEL
, Any(aOUniqueName
) );
1007 // set number formats supplier for formatted field
1008 if ( supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
1010 Reference
< util::XNumberFormatsSupplier
> xSupplier
= GetDlgEdForm()->GetDlgEditor().GetNumberFormatsSupplier();
1011 if ( xSupplier
.is() )
1013 xPSet
->setPropertyValue( DLGED_PROP_FORMATSSUPPLIER
, Any(xSupplier
) );
1017 // set geometry properties
1020 Reference
< container::XNameContainer
> xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY
);
1024 Sequence
< OUString
> aNames
= xCont
->getElementNames();
1026 aTabIndex
<<= static_cast<sal_Int16
>(aNames
.getLength());
1027 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
1030 Reference
< beans::XPropertySet
> xPSetForm( xCont
, UNO_QUERY
);
1031 if ( xPSetForm
.is() )
1033 Any aStep
= xPSetForm
->getPropertyValue( DLGED_PROP_STEP
);
1034 xPSet
->setPropertyValue( DLGED_PROP_STEP
, aStep
);
1037 // insert control model in dialog model
1038 Reference
< awt::XControlModel
> xCtrl( xPSet
, UNO_QUERY
);
1041 xCont
->insertByName( aOUniqueName
, aAny
);
1043 LocalizationMgr::setControlResourceIDsForNewEditorObject(
1044 &GetDialogEditor(), aAny
, aOUniqueName
1047 pDlgEdForm
->UpdateTabOrderAndGroups();
1051 // dialog model changed
1052 pDlgEdForm
->GetDlgEditor().SetDialogModelChanged();
1055 void DlgEdObj::StartListening()
1057 DBG_ASSERT(!isListening(), "DlgEdObj::StartListening: already listening!");
1062 bIsListening
= true;
1064 // XPropertyChangeListener
1065 Reference
< XPropertySet
> xControlModel( GetUnoControlModel() , UNO_QUERY
);
1066 if (!m_xPropertyChangeListener
.is() && xControlModel
.is())
1069 m_xPropertyChangeListener
= new DlgEdPropListenerImpl(*this);
1071 // register listener to properties
1072 xControlModel
->addPropertyChangeListener( OUString() , m_xPropertyChangeListener
);
1075 // XContainerListener
1076 Reference
< XScriptEventsSupplier
> xEventsSupplier( GetUnoControlModel() , UNO_QUERY
);
1077 if( !m_xContainerListener
.is() && xEventsSupplier
.is() )
1080 m_xContainerListener
= new DlgEdEvtContListenerImpl(*this);
1082 // register listener to script event container
1083 Reference
< XNameContainer
> xEventCont
= xEventsSupplier
->getEvents();
1084 DBG_ASSERT(xEventCont
.is(), "DlgEdObj::StartListening: control model has no script event container!");
1085 Reference
< XContainer
> xCont( xEventCont
, UNO_QUERY
);
1087 xCont
->addContainerListener( m_xContainerListener
);
1091 void DlgEdObj::EndListening(bool bRemoveListener
)
1093 DBG_ASSERT(isListening(), "DlgEdObj::EndListening: not listening currently!");
1098 bIsListening
= false;
1100 if (!bRemoveListener
)
1103 // XPropertyChangeListener
1104 Reference
< XPropertySet
> xControlModel(GetUnoControlModel(), UNO_QUERY
);
1105 if ( m_xPropertyChangeListener
.is() && xControlModel
.is() )
1108 xControlModel
->removePropertyChangeListener( OUString() , m_xPropertyChangeListener
);
1110 m_xPropertyChangeListener
.clear();
1112 // XContainerListener
1113 Reference
< XScriptEventsSupplier
> xEventsSupplier( GetUnoControlModel() , UNO_QUERY
);
1114 if( m_xContainerListener
.is() && xEventsSupplier
.is() )
1117 Reference
< XNameContainer
> xEventCont
= xEventsSupplier
->getEvents();
1118 DBG_ASSERT(xEventCont
.is(), "DlgEdObj::EndListening: control model has no script event container!");
1119 Reference
< XContainer
> xCont( xEventCont
, UNO_QUERY
);
1121 xCont
->removeContainerListener( m_xContainerListener
);
1123 m_xContainerListener
.clear();
1126 void DlgEdObj::_propertyChange( const css::beans::PropertyChangeEvent
& evt
)
1131 DlgEdForm
* pRealDlgEdForm
= dynamic_cast<DlgEdForm
*>(this);
1132 if (!pRealDlgEdForm
)
1133 pRealDlgEdForm
= GetDlgEdForm();
1134 if (!pRealDlgEdForm
)
1136 DlgEditor
& rDlgEditor
= pRealDlgEdForm
->GetDlgEditor();
1137 if (rDlgEditor
.isInPaint())
1140 // dialog model changed
1141 rDlgEditor
.SetDialogModelChanged();
1143 // update position and size
1144 if ( evt
.PropertyName
== DLGED_PROP_POSITIONX
|| evt
.PropertyName
== DLGED_PROP_POSITIONY
||
1145 evt
.PropertyName
== DLGED_PROP_WIDTH
|| evt
.PropertyName
== DLGED_PROP_HEIGHT
||
1146 evt
.PropertyName
== DLGED_PROP_DECORATION
)
1148 PositionAndSizeChange( evt
);
1150 if ( evt
.PropertyName
== DLGED_PROP_DECORATION
)
1151 GetDialogEditor().ResetDialog();
1153 // change name of control in dialog model
1154 else if ( evt
.PropertyName
== DLGED_PROP_NAME
)
1156 if (!dynamic_cast<DlgEdForm
*>(this))
1162 catch (container::NoSuchElementException
const&)
1164 css::uno::Any anyEx
= cppu::getCaughtException();
1165 throw lang::WrappedTargetRuntimeException("", nullptr,
1171 else if ( evt
.PropertyName
== DLGED_PROP_STEP
)
1176 else if ( evt
.PropertyName
== DLGED_PROP_TABINDEX
)
1178 if (!dynamic_cast<DlgEdForm
*>(this))
1179 TabIndexChange(evt
);
1183 void DlgEdObj::_elementInserted()
1187 // dialog model changed
1188 GetDialogEditor().SetDialogModelChanged();
1192 void DlgEdObj::_elementReplaced()
1196 // dialog model changed
1197 GetDialogEditor().SetDialogModelChanged();
1201 void DlgEdObj::_elementRemoved()
1205 // dialog model changed
1206 GetDialogEditor().SetDialogModelChanged();
1210 void DlgEdObj::SetLayer(SdrLayerID nLayer
)
1212 SdrLayerID nOldLayer
= GetLayer();
1214 if ( nLayer
!= nOldLayer
)
1216 SdrUnoObj::SetLayer( nLayer
);
1218 DlgEdHint
aHint( DlgEdHint::LAYERCHANGED
, this );
1219 GetDlgEdForm()->GetDlgEditor().Broadcast( aHint
);
1223 DlgEdForm::DlgEdForm(
1224 SdrModel
& rSdrModel
,
1225 DlgEditor
& rDlgEditor_
)
1226 : DlgEdObj(rSdrModel
),
1227 rDlgEditor(rDlgEditor_
)
1231 DlgEdForm::~DlgEdForm()
1235 void DlgEdForm::SetRectFromProps()
1237 // get form position and size from properties
1238 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
1242 sal_Int32 nXIn
= 0, nYIn
= 0, nWidthIn
= 0, nHeightIn
= 0;
1243 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nXIn
;
1244 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nYIn
;
1245 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidthIn
;
1246 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeightIn
;
1248 // transform coordinates
1249 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
1250 if ( TransformFormToSdrCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
1252 // set rectangle position and size
1253 Point
aPoint( nXOut
, nYOut
);
1254 Size
aSize( nWidthOut
, nHeightOut
);
1255 SetSnapRect( tools::Rectangle( aPoint
, aSize
) );
1259 void DlgEdForm::SetPropsFromRect()
1261 // get form position and size from rectangle
1262 tools::Rectangle aRect_
= GetSnapRect();
1263 sal_Int32 nXIn
= aRect_
.Left();
1264 sal_Int32 nYIn
= aRect_
.Top();
1265 sal_Int32 nWidthIn
= aRect_
.GetWidth();
1266 sal_Int32 nHeightIn
= aRect_
.GetHeight();
1268 // transform coordinates
1269 sal_Int32 nXOut
, nYOut
, nWidthOut
, nHeightOut
;
1270 if ( TransformSdrToFormCoordinates( nXIn
, nYIn
, nWidthIn
, nHeightIn
, nXOut
, nYOut
, nWidthOut
, nHeightOut
) )
1273 Reference
< beans::XPropertySet
> xPSet( GetUnoControlModel(), UNO_QUERY
);
1276 xPSet
->setPropertyValue( DLGED_PROP_POSITIONX
, Any(nXOut
) );
1277 xPSet
->setPropertyValue( DLGED_PROP_POSITIONY
, Any(nYOut
) );
1278 xPSet
->setPropertyValue( DLGED_PROP_WIDTH
, Any(nWidthOut
) );
1279 xPSet
->setPropertyValue( DLGED_PROP_HEIGHT
, Any(nHeightOut
) );
1284 void DlgEdForm::AddChild( DlgEdObj
* pDlgEdObj
)
1286 pChildren
.push_back( pDlgEdObj
);
1289 void DlgEdForm::RemoveChild( DlgEdObj
* pDlgEdObj
)
1291 pChildren
.erase( std::remove( pChildren
.begin() , pChildren
.end() , pDlgEdObj
) );
1294 void DlgEdForm::PositionAndSizeChange( const beans::PropertyChangeEvent
& evt
)
1296 DlgEditor
& rEditor
= GetDlgEditor();
1297 DlgEdPage
& rPage
= rEditor
.GetPage();
1299 sal_Int32 nPageXIn
= 0;
1300 sal_Int32 nPageYIn
= 0;
1301 Size aPageSize
= rPage
.GetSize();
1302 sal_Int32 nPageWidthIn
= aPageSize
.Width();
1303 sal_Int32 nPageHeightIn
= aPageSize
.Height();
1304 sal_Int32 nPageX
, nPageY
, nPageWidth
, nPageHeight
;
1305 if ( TransformSdrToFormCoordinates( nPageXIn
, nPageYIn
, nPageWidthIn
, nPageHeightIn
, nPageX
, nPageY
, nPageWidth
, nPageHeight
) )
1307 Reference
< beans::XPropertySet
> xPSetForm( GetUnoControlModel(), UNO_QUERY
);
1308 if ( xPSetForm
.is() )
1310 sal_Int32 nValue
= 0;
1311 evt
.NewValue
>>= nValue
;
1312 sal_Int32 nNewValue
= nValue
;
1314 if ( evt
.PropertyName
== DLGED_PROP_POSITIONX
)
1316 if ( nNewValue
< nPageX
)
1319 else if ( evt
.PropertyName
== DLGED_PROP_POSITIONY
)
1321 if ( nNewValue
< nPageY
)
1324 else if ( evt
.PropertyName
== DLGED_PROP_WIDTH
)
1326 if ( nNewValue
< 1 )
1329 else if ( evt
.PropertyName
== DLGED_PROP_HEIGHT
)
1331 if ( nNewValue
< 1 )
1335 if ( nNewValue
!= nValue
)
1337 EndListening( false );
1338 xPSetForm
->setPropertyValue( evt
.PropertyName
, Any(nNewValue
) );
1344 bool bAdjustedPageSize
= rEditor
.AdjustPageSize();
1346 std::vector
<DlgEdObj
*> const& aChildList
= GetChildren();
1348 if ( bAdjustedPageSize
)
1350 rEditor
.InitScrollBars();
1351 aPageSize
= rPage
.GetSize();
1352 nPageWidthIn
= aPageSize
.Width();
1353 nPageHeightIn
= aPageSize
.Height();
1354 if ( TransformSdrToControlCoordinates( nPageXIn
, nPageYIn
, nPageWidthIn
, nPageHeightIn
, nPageX
, nPageY
, nPageWidth
, nPageHeight
) )
1356 for (auto const& child
: aChildList
)
1358 Reference
< beans::XPropertySet
> xPSet( child
->GetUnoControlModel(), UNO_QUERY
);
1361 sal_Int32 nX
= 0, nY
= 0, nWidth
= 0, nHeight
= 0;
1362 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nX
;
1363 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nY
;
1364 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidth
;
1365 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeight
;
1367 sal_Int32 nNewX
= nX
;
1368 if ( nX
+ nWidth
> nPageX
+ nPageWidth
)
1370 nNewX
= nPageX
+ nPageWidth
- nWidth
;
1371 if ( nNewX
< nPageX
)
1376 EndListening( false );
1377 xPSet
->setPropertyValue( DLGED_PROP_POSITIONX
, Any(nNewX
) );
1381 sal_Int32 nNewY
= nY
;
1382 if ( nY
+ nHeight
> nPageY
+ nPageHeight
)
1384 nNewY
= nPageY
+ nPageHeight
- nHeight
;
1385 if ( nNewY
< nPageY
)
1390 EndListening( false );
1391 xPSet
->setPropertyValue( DLGED_PROP_POSITIONY
, Any(nNewY
) );
1399 for (auto const& child
: aChildList
)
1400 child
->SetRectFromProps();
1403 void DlgEdForm::UpdateStep()
1405 SdrPage
* pSdrPage
= getSdrPageFromSdrObject();
1409 const size_t nObjCount
= pSdrPage
->GetObjCount();
1410 for ( size_t i
= 0 ; i
< nObjCount
; i
++ )
1412 DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pSdrPage
->GetObj(i
));
1413 if (pDlgEdObj
&& !dynamic_cast<DlgEdForm
*>(pDlgEdObj
))
1414 pDlgEdObj
->UpdateStep();
1419 void DlgEdForm::UpdateTabIndices()
1421 // stop listening with all children
1422 for (auto const& child
: pChildren
)
1424 child
->EndListening( false );
1427 Reference
< css::container::XNameAccess
> xNameAcc( GetUnoControlModel() , UNO_QUERY
);
1428 if ( xNameAcc
.is() )
1430 // get sequence of control names
1431 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
1432 const OUString
* pNames
= aNames
.getConstArray();
1433 sal_Int32 nCtrls
= aNames
.getLength();
1435 // create a map of tab indices and control names, sorted by tab index
1436 IndexToNameMap aIndexToNameMap
;
1437 for ( sal_Int32 i
= 0; i
< nCtrls
; ++i
)
1440 OUString
aName( pNames
[i
] );
1443 sal_Int16 nTabIndex
= -1;
1444 Any aCtrl
= xNameAcc
->getByName( aName
);
1445 Reference
< css::beans::XPropertySet
> xPSet
;
1448 xPSet
->getPropertyValue( DLGED_PROP_TABINDEX
) >>= nTabIndex
;
1451 aIndexToNameMap
.emplace( nTabIndex
, aName
);
1454 // set new tab indices
1455 sal_Int16 nNewTabIndex
= 0;
1456 for (auto const& indexToName
: aIndexToNameMap
)
1458 Any aCtrl
= xNameAcc
->getByName( indexToName
.second
);
1459 Reference
< beans::XPropertySet
> xPSet
;
1463 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, Any(nNewTabIndex
) );
1468 UpdateTabOrderAndGroups();
1471 // start listening with all children
1472 for (auto const& child
: pChildren
)
1474 child
->StartListening();
1478 void DlgEdForm::UpdateTabOrder()
1480 // When the tabindex of a control model changes, the dialog control is
1481 // notified about those changes. Due to #109067# (bad performance of
1482 // dialog editor) the dialog control doesn't activate the tab order
1483 // in design mode. When the dialog editor has reordered all
1484 // tabindices, this method allows to activate the taborder afterwards.
1486 Reference
< awt::XUnoControlContainer
> xCont( GetControl(), UNO_QUERY
);
1489 Sequence
< Reference
< awt::XTabController
> > aSeqTabCtrls
= xCont
->getTabControllers();
1490 const Reference
< awt::XTabController
>* pTabCtrls
= aSeqTabCtrls
.getConstArray();
1491 sal_Int32 nCount
= aSeqTabCtrls
.getLength();
1492 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
1493 pTabCtrls
[i
]->activateTabOrder();
1497 void DlgEdForm::UpdateGroups()
1499 // The grouping of radio buttons in a dialog is done by vcl.
1500 // In the dialog editor we have two views (=controls) for one
1501 // radio button model. One control is owned by the dialog control,
1502 // but not visible in design mode. The other control is owned by
1503 // the drawing layer object. Whereas the grouping of the first
1504 // control is done by vcl, the grouping of the control in the
1505 // drawing layer has to be done here.
1507 Reference
< awt::XTabControllerModel
> xTabModel( GetUnoControlModel() , UNO_QUERY
);
1508 if ( !xTabModel
.is() )
1511 // create a global list of controls that belong to the dialog
1512 std::vector
<DlgEdObj
*> aChildList
= GetChildren();
1513 sal_uInt32 nSize
= aChildList
.size();
1514 Sequence
< Reference
< awt::XControl
> > aSeqControls( nSize
);
1515 for ( sal_uInt32 i
= 0; i
< nSize
; ++i
)
1516 aSeqControls
.getArray()[i
] = aChildList
[i
]->GetControl();
1518 sal_Int32 nGroupCount
= xTabModel
->getGroupCount();
1519 for ( sal_Int32 nGroup
= 0; nGroup
< nGroupCount
; ++nGroup
)
1521 // get a list of control models that belong to this group
1523 Sequence
< Reference
< awt::XControlModel
> > aSeqModels
;
1524 xTabModel
->getGroup( nGroup
, aSeqModels
, aName
);
1525 const Reference
< awt::XControlModel
>* pModels
= aSeqModels
.getConstArray();
1526 sal_Int32 nModelCount
= aSeqModels
.getLength();
1528 // create a list of peers that belong to this group
1529 Sequence
< Reference
< awt::XWindow
> > aSeqPeers( nModelCount
);
1530 for ( sal_Int32 nModel
= 0; nModel
< nModelCount
; ++nModel
)
1532 // for each control model find the corresponding control in the global list
1533 const Reference
< awt::XControl
>* pControls
= aSeqControls
.getConstArray();
1534 sal_Int32 nControlCount
= aSeqControls
.getLength();
1535 for ( sal_Int32 nControl
= 0; nControl
< nControlCount
; ++nControl
)
1537 const Reference
< awt::XControl
> xCtrl( pControls
[nControl
] );
1540 Reference
< awt::XControlModel
> xCtrlModel( xCtrl
->getModel() );
1541 if ( xCtrlModel
.get() == pModels
[nModel
].get() )
1543 // get the control peer and insert into the list of peers
1544 aSeqPeers
.getArray()[ nModel
].set( xCtrl
->getPeer(), UNO_QUERY
);
1551 // set the group at the dialog peer
1552 Reference
< awt::XControl
> xDlg
= GetControl();
1555 Reference
< awt::XVclContainerPeer
> xDlgPeer( xDlg
->getPeer(), UNO_QUERY
);
1556 if ( xDlgPeer
.is() )
1557 xDlgPeer
->setGroup( aSeqPeers
);
1562 void DlgEdForm::UpdateTabOrderAndGroups()
1568 void DlgEdForm::NbcMove( const Size
& rSize
)
1570 SdrUnoObj::NbcMove( rSize
);
1572 // set geometry properties of form
1573 EndListening(false);
1577 // set geometry properties of all children
1578 for (auto const& child
: pChildren
)
1580 child
->EndListening(false);
1581 child
->SetPropsFromRect();
1582 child
->StartListening();
1585 // dialog model changed
1586 GetDlgEditor().SetDialogModelChanged();
1589 void DlgEdForm::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
1591 SdrUnoObj::NbcResize( rRef
, xFract
, yFract
);
1593 // set geometry properties of form
1594 EndListening(false);
1598 // set geometry properties of all children
1599 for (auto const& child
: pChildren
)
1601 child
->EndListening(false);
1602 child
->SetPropsFromRect();
1603 child
->StartListening();
1606 // dialog model changed
1607 GetDlgEditor().SetDialogModelChanged();
1610 bool DlgEdForm::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
1612 bool bResult
= SdrUnoObj::EndCreate(rStat
, eCmd
);
1615 EndListening(false);
1617 // set geometry properties
1620 // dialog model changed
1621 GetDlgEditor().SetDialogModelChanged();
1629 awt::DeviceInfo
DlgEdForm::getDeviceInfo() const
1631 awt::DeviceInfo aDeviceInfo
;
1633 DlgEditor
& rEditor
= GetDlgEditor();
1634 vcl::Window
& rWindow
= rEditor
.GetWindow();
1636 // obtain an XControl
1637 ::utl::SharedUNOComponent
< awt::XControl
> xDialogControl
; // ensures auto-disposal, if needed
1638 xDialogControl
.reset( GetControl(), ::utl::SharedUNOComponent
< awt::XControl
>::NoTakeOwnership
);
1639 if ( !xDialogControl
.is() )
1641 // don't create a temporary control all the time, this method here is called
1642 // way too often. Instead, use a cached DeviceInfo.
1644 if ( !!mpDeviceInfo
)
1645 return *mpDeviceInfo
;
1647 Reference
< awt::XControlContainer
> xEditorControlContainer( rEditor
.GetWindowControlContainer() );
1648 xDialogControl
.reset(
1649 GetTemporaryControlForWindow(rWindow
, xEditorControlContainer
),
1650 utl::SharedUNOComponent
< awt::XControl
>::TakeOwnership
1654 Reference
< awt::XDevice
> xDialogDevice
;
1655 if ( xDialogControl
.is() )
1656 xDialogDevice
.set( xDialogControl
->getPeer(), UNO_QUERY
);
1657 DBG_ASSERT( xDialogDevice
.is(), "DlgEdForm::getDeviceInfo: no device!" );
1658 if ( xDialogDevice
.is() )
1659 aDeviceInfo
= xDialogDevice
->getInfo();
1661 mpDeviceInfo
= aDeviceInfo
;
1665 void DlgEdObj::MakeDataAware( const Reference
< frame::XModel
>& xModel
)
1667 // Need to flesh this out, currently we will only support data-aware controls for calc
1668 // and only handle a subset of functionality e.g. linked-cell and cell range data source. Of course later
1669 // we need to disambiguate for writer ( and others ? ) and also support the generic form (db) bindings
1670 // we need some more work in xmlscript to be able to handle that
1671 Reference
< lang::XMultiServiceFactory
> xFac( xModel
, UNO_QUERY
);
1672 Reference
< form::binding::XBindableValue
> xBindable( GetUnoControlModel(), UNO_QUERY
);
1673 Reference
< form::binding::XListEntrySink
> xListEntrySink( GetUnoControlModel(), UNO_QUERY
);
1677 //tdf#90361 and tdf#104011 CellValueBinding and CellRangeListSource are unusable
1678 //without being initialized, so use createInstanceWithArguments with a
1679 //dummy BoundCell and CellRange instead of createInstance. This at least results in
1680 //the dialog editor not falling.
1681 css::beans::NamedValue aCellValue
;
1682 aCellValue
.Name
= "BoundCell";
1683 css::table::CellAddress aCellAddress
;
1684 aCellValue
.Value
<<= aCellAddress
;
1686 css::beans::NamedValue aCellRange
;
1687 aCellRange
.Name
= "CellRange";
1688 css::table::CellRangeAddress aRangeAddress
;
1689 aCellRange
.Value
<<= aRangeAddress
;
1691 Sequence
< Any
> aArgs
{ Any(aCellValue
), Any(aCellRange
) };
1693 if ( xBindable
.is() )
1695 Reference
< form::binding::XValueBinding
> xBinding( xFac
->createInstanceWithArguments( "com.sun.star.table.CellValueBinding", aArgs
), UNO_QUERY
);
1696 xBindable
->setValueBinding( xBinding
);
1698 if ( xListEntrySink
.is() )
1700 Reference
< form::binding::XListEntrySource
> xSource( xFac
->createInstanceWithArguments( "com.sun.star.table.CellRangeListSource", aArgs
), UNO_QUERY
);
1701 xListEntrySink
->setListEntrySource( xSource
);
1704 } // namespace basctl
1706 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */