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