LCOV - code coverage report
Current view: top level - libreoffice/basctl/source/dlged - dlgedobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 894 0.0 %
Date: 2012-12-27 Functions: 0 66 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10