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

Generated by: LCOV version 1.10