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