LCOV - code coverage report
Current view: top level - basctl/source/dlged - dlged.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 664 0.0 %
Date: 2014-11-03 Functions: 0 47 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "basidesh.hxx"
      22             : #include "dlged.hxx"
      23             : #include "dlgedclip.hxx"
      24             : #include "dlgeddef.hxx"
      25             : #include "dlgedfac.hxx"
      26             : #include "dlgedfunc.hxx"
      27             : #include "dlgedmod.hxx"
      28             : #include "dlgedobj.hxx"
      29             : #include "dlgedpage.hxx"
      30             : #include "dlgedview.hxx"
      31             : #include "iderdll.hxx"
      32             : #include "localizationmgr.hxx"
      33             : #include "baside3.hxx"
      34             : 
      35             : #include <com/sun/star/awt/Toolkit.hpp>
      36             : #include <com/sun/star/awt/UnoControlDialog.hpp>
      37             : #include <com/sun/star/awt/XDialog.hpp>
      38             : #include <com/sun/star/resource/StringResource.hpp>
      39             : #include <com/sun/star/util/XCloneable.hpp>
      40             : #include <com/sun/star/util/NumberFormatsSupplier.hpp>
      41             : #include <comphelper/types.hxx>
      42             : #include <sfx2/viewfrm.hxx>
      43             : #include <svl/itempool.hxx>
      44             : #include <svx/sdrpaintwindow.hxx>
      45             : #include <svx/svxids.hrc>
      46             : #include <toolkit/helper/vclunohelper.hxx>
      47             : #include <vcl/svapp.hxx>
      48             : #include <xmlscript/xml_helper.hxx>
      49             : #include <xmlscript/xmldlg_imexp.hxx>
      50             : 
      51             : namespace basctl
      52             : {
      53             : 
      54             : using namespace comphelper;
      55             : using namespace ::com::sun::star;
      56             : using namespace ::com::sun::star::uno;
      57             : using namespace ::com::sun::star::beans;
      58             : using namespace ::com::sun::star::io;
      59             : 
      60           0 : static OUString aResourceResolverPropName( "ResourceResolver" );
      61           0 : static OUString aDecorationPropName( "Decoration" );
      62           0 : static OUString aTitlePropName( "Title" );
      63             : 
      64             : 
      65             : 
      66             : // DlgEdHint
      67             : 
      68             : 
      69           0 : DlgEdHint::DlgEdHint(Kind eHint)
      70             :     : eKind(eHint)
      71           0 :     , pDlgEdObj(0)
      72             : {
      73           0 : }
      74             : 
      75           0 : DlgEdHint::DlgEdHint(Kind eHint, DlgEdObj* pObj)
      76             :     : eKind(eHint)
      77           0 :     , pDlgEdObj(pObj)
      78             : {
      79           0 : }
      80             : 
      81           0 : DlgEdHint::~DlgEdHint()
      82             : {
      83           0 : }
      84             : 
      85             : 
      86             : // DlgEditor
      87             : 
      88             : 
      89           0 : void DlgEditor::ShowDialog()
      90             : {
      91           0 :     uno::Reference< uno::XComponentContext >  xContext = getProcessComponentContext();
      92             : 
      93             :     // create a dialog
      94           0 :     uno::Reference< awt::XUnoControlDialog > xDlg = awt::UnoControlDialog::create( xContext );
      95             : 
      96             :     // clone the dialog model
      97           0 :     uno::Reference< util::XCloneable > xC( m_xUnoControlDialogModel, uno::UNO_QUERY );
      98           0 :     uno::Reference< util::XCloneable > xNew = xC->createClone();
      99           0 :     uno::Reference< awt::XControlModel > xDlgMod( xNew, uno::UNO_QUERY );
     100             : 
     101           0 :     uno::Reference< beans::XPropertySet > xSrcDlgModPropSet( m_xUnoControlDialogModel, uno::UNO_QUERY );
     102           0 :     uno::Reference< beans::XPropertySet > xNewDlgModPropSet( xDlgMod, uno::UNO_QUERY );
     103           0 :     if( xNewDlgModPropSet.is() )
     104             :     {
     105           0 :         if( xSrcDlgModPropSet.is() )
     106             :         {
     107             :             try
     108             :             {
     109           0 :                 Any aResourceResolver = xSrcDlgModPropSet->getPropertyValue( aResourceResolverPropName );
     110           0 :                 xNewDlgModPropSet->setPropertyValue( aResourceResolverPropName, aResourceResolver );
     111             :             }
     112           0 :             catch(const UnknownPropertyException& )
     113             :             {
     114             :                 OSL_FAIL( "DlgEditor::ShowDialog(): No ResourceResolver property" );
     115             :             }
     116             :         }
     117             : 
     118             :         // Disable decoration
     119           0 :         bool bDecoration = true;
     120             :         try
     121             :         {
     122           0 :             Any aDecorationAny = xSrcDlgModPropSet->getPropertyValue( aDecorationPropName );
     123           0 :             aDecorationAny >>= bDecoration;
     124           0 :             if( !bDecoration )
     125             :             {
     126           0 :                 xNewDlgModPropSet->setPropertyValue( aDecorationPropName, makeAny( true ) );
     127           0 :                 xNewDlgModPropSet->setPropertyValue( aTitlePropName, makeAny( OUString() ) );
     128           0 :             }
     129             :         }
     130           0 :         catch(const UnknownPropertyException& )
     131             :         {}
     132             :     }
     133             : 
     134             :     // set the model
     135           0 :     xDlg->setModel( xDlgMod );
     136             : 
     137             :     // create a peer
     138           0 :     uno::Reference< awt::XToolkit> xToolkit = awt::Toolkit::create( xContext );
     139           0 :     xDlg->createPeer( xToolkit, rWindow.GetComponentInterface() );
     140             : 
     141           0 :     xDlg->execute();
     142             : 
     143             :     // need to cast because of multiple inheritance
     144           0 :     Reference<awt::XControl>(xDlg)->dispose();
     145           0 : }
     146             : 
     147             : 
     148           0 : bool DlgEditor::UnmarkDialog()
     149             : {
     150           0 :     SdrObject*      pDlgObj = pDlgEdModel->GetPage(0)->GetObj(0);
     151           0 :     SdrPageView*    pPgView = pDlgEdView->GetSdrPageView();
     152             : 
     153           0 :     bool bWasMarked = pDlgEdView->IsObjMarked( pDlgObj );
     154             : 
     155           0 :     if( bWasMarked )
     156           0 :         pDlgEdView->MarkObj( pDlgObj, pPgView, true );
     157             : 
     158           0 :     return bWasMarked;
     159             : }
     160             : 
     161             : 
     162           0 : bool DlgEditor::RemarkDialog()
     163             : {
     164           0 :     SdrObject*      pDlgObj = pDlgEdModel->GetPage(0)->GetObj(0);
     165           0 :     SdrPageView*    pPgView = pDlgEdView->GetSdrPageView();
     166             : 
     167           0 :     bool bWasMarked = pDlgEdView->IsObjMarked( pDlgObj );
     168             : 
     169           0 :     if( !bWasMarked )
     170           0 :         pDlgEdView->MarkObj( pDlgObj, pPgView, false );
     171             : 
     172           0 :     return bWasMarked;
     173             : }
     174             : 
     175             : 
     176           0 : DlgEditor::DlgEditor (
     177             :     vcl::Window& rWindow_, DialogWindowLayout& rLayout_,
     178             :     com::sun::star::uno::Reference<com::sun::star::frame::XModel> const& xModel,
     179             :     com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> xDialogModel
     180             : )
     181             :     :pHScroll(NULL)
     182             :     ,pVScroll(NULL)
     183           0 :     ,pDlgEdModel(new DlgEdModel())
     184           0 :     ,pDlgEdPage(new DlgEdPage(*pDlgEdModel))
     185           0 :     ,pDlgEdView(new DlgEdView(*pDlgEdModel, rWindow_, *this))
     186             :     ,m_ClipboardDataFlavors(1)
     187             :     ,m_ClipboardDataFlavorsResource(2)
     188           0 :     ,pObjFac(new DlgEdFactory(xModel))
     189             :     ,rWindow(rWindow_)
     190           0 :     ,pFunc(new DlgEdFuncSelect(*this))
     191             :     ,rLayout(rLayout_)
     192             :     ,eMode( DlgEditor::SELECT )
     193             :     ,eActObj( OBJ_DLG_PUSHBUTTON )
     194             :     ,bFirstDraw(false)
     195             :     ,aGridSize( 100, 100 )  // 100TH_MM
     196             :     ,bGridVisible(false)
     197             :     ,bGridSnap(true)
     198             :     ,bCreateOK(true)
     199             :     ,bDialogModelChanged(false)
     200             :     ,mnPaintGuard(0)
     201           0 :     ,m_xDocument( xModel )
     202             : {
     203           0 :     pDlgEdModel->GetItemPool().FreezeIdRanges();
     204           0 :     pDlgEdModel->SetScaleUnit( MAP_100TH_MM );
     205             : 
     206           0 :     SdrLayerAdmin& rAdmin = pDlgEdModel->GetLayerAdmin();
     207           0 :     rAdmin.NewLayer( rAdmin.GetControlLayerName() );
     208           0 :     rAdmin.NewLayer( OUString( "HiddenLayer" ) );
     209             : 
     210           0 :     pDlgEdModel->InsertPage(pDlgEdPage);
     211             : 
     212             :     // set clipboard data flavors
     213           0 :     m_ClipboardDataFlavors[0].MimeType =             "application/vnd.sun.xml.dialog" ;
     214           0 :     m_ClipboardDataFlavors[0].HumanPresentableName = "Dialog 6.0" ;
     215           0 :     m_ClipboardDataFlavors[0].DataType =             ::getCppuType( (const Sequence< sal_Int8 >*) 0 );
     216             : 
     217           0 :     m_ClipboardDataFlavorsResource[0] =                      m_ClipboardDataFlavors[0];
     218           0 :     m_ClipboardDataFlavorsResource[1].MimeType =             "application/vnd.sun.xml.dialogwithresource" ;
     219           0 :     m_ClipboardDataFlavorsResource[1].HumanPresentableName = "Dialog 8.0" ;
     220           0 :     m_ClipboardDataFlavorsResource[1].DataType =             ::getCppuType( (const Sequence< sal_Int8 >*) 0 );
     221             : 
     222           0 :     aPaintTimer.SetTimeout( 1 );
     223           0 :     aPaintTimer.SetTimeoutHdl( LINK( this, DlgEditor, PaintTimeout ) );
     224             : 
     225           0 :     aMarkTimer.SetTimeout( 100 );
     226           0 :     aMarkTimer.SetTimeoutHdl( LINK( this, DlgEditor, MarkTimeout ) );
     227             : 
     228           0 :     rWindow.SetMapMode( MapMode( MAP_100TH_MM ) );
     229           0 :     pDlgEdPage->SetSize( rWindow.PixelToLogic( Size(DLGED_PAGE_WIDTH_MIN, DLGED_PAGE_HEIGHT_MIN) ) );
     230             : 
     231           0 :     pDlgEdView->ShowSdrPage(pDlgEdView->GetModel()->GetPage(0));
     232           0 :     pDlgEdView->SetLayerVisible( OUString( "HiddenLayer" ), false );
     233           0 :     pDlgEdView->SetMoveSnapOnlyTopLeft(true);
     234           0 :     pDlgEdView->SetWorkArea( Rectangle( Point( 0, 0 ), pDlgEdPage->GetSize() ) );
     235             : 
     236           0 :     pDlgEdView->SetGridCoarse( aGridSize );
     237           0 :     pDlgEdView->SetSnapGridWidth(Fraction(aGridSize.Width(), 1), Fraction(aGridSize.Height(), 1));
     238           0 :     pDlgEdView->SetGridSnap( bGridSnap );
     239           0 :     pDlgEdView->SetGridVisible( bGridVisible );
     240           0 :     pDlgEdView->SetDragStripes(false);
     241             : 
     242           0 :     pDlgEdView->SetDesignMode(true);
     243             : 
     244           0 :     ::comphelper::disposeComponent( m_xControlContainer );
     245             : 
     246           0 :     SetDialog(xDialogModel);
     247           0 : }
     248             : 
     249             : 
     250           0 : DlgEditor::~DlgEditor()
     251             : {
     252           0 :     aPaintTimer.Stop();
     253           0 :     aMarkTimer.Stop();
     254             : 
     255           0 :     ::comphelper::disposeComponent( m_xControlContainer );
     256           0 : }
     257             : 
     258             : 
     259           0 : Reference< awt::XControlContainer > DlgEditor::GetWindowControlContainer()
     260             : {
     261           0 :     if (!m_xControlContainer.is())
     262           0 :         m_xControlContainer = VCLUnoHelper::CreateControlContainer(&rWindow);
     263           0 :     return m_xControlContainer;
     264             : }
     265             : 
     266             : 
     267           0 : void DlgEditor::SetScrollBars( ScrollBar* pHS, ScrollBar* pVS )
     268             : {
     269           0 :     pHScroll = pHS;
     270           0 :     pVScroll = pVS;
     271             : 
     272           0 :     InitScrollBars();
     273           0 : }
     274             : 
     275             : 
     276           0 : void DlgEditor::InitScrollBars()
     277             : {
     278             :     DBG_ASSERT( pHScroll, "DlgEditor::InitScrollBars: no horizontal scroll bar!" );
     279             :     DBG_ASSERT( pVScroll, "DlgEditor::InitScrollBars: no vertical scroll bar!" );
     280           0 :     if ( !pHScroll || !pVScroll )
     281           0 :         return;
     282             : 
     283           0 :     Size aOutSize = rWindow.GetOutputSize();
     284           0 :     Size aPgSize  = pDlgEdPage->GetSize();
     285             : 
     286           0 :     pHScroll->SetRange( Range( 0, aPgSize.Width()  ));
     287           0 :     pVScroll->SetRange( Range( 0, aPgSize.Height() ));
     288           0 :     pHScroll->SetVisibleSize( (sal_uLong)aOutSize.Width() );
     289           0 :     pVScroll->SetVisibleSize( (sal_uLong)aOutSize.Height() );
     290             : 
     291           0 :     pHScroll->SetLineSize( aOutSize.Width() / 10 );
     292           0 :     pVScroll->SetLineSize( aOutSize.Height() / 10 );
     293           0 :     pHScroll->SetPageSize( aOutSize.Width() / 2 );
     294           0 :     pVScroll->SetPageSize( aOutSize.Height() / 2 );
     295             : 
     296           0 :     DoScroll( pHScroll );
     297           0 :     DoScroll( pVScroll );
     298             : }
     299             : 
     300             : 
     301           0 : void DlgEditor::DoScroll( ScrollBar* )
     302             : {
     303           0 :     if( !pHScroll || !pVScroll )
     304           0 :         return;
     305             : 
     306           0 :     MapMode aMap = rWindow.GetMapMode();
     307           0 :     Point aOrg = aMap.GetOrigin();
     308             : 
     309           0 :     Size  aScrollPos( pHScroll->GetThumbPos(), pVScroll->GetThumbPos() );
     310           0 :     aScrollPos = rWindow.LogicToPixel( aScrollPos );
     311           0 :     aScrollPos = rWindow.PixelToLogic( aScrollPos );
     312             : 
     313           0 :     long  nX   = aScrollPos.Width() + aOrg.X();
     314           0 :     long  nY   = aScrollPos.Height() + aOrg.Y();
     315             : 
     316           0 :     if( !nX && !nY )
     317           0 :         return;
     318             : 
     319           0 :     rWindow.Update();
     320             : 
     321             :     // #i31562#
     322             :     // When scrolling, someone was rescuing the Wallpaper and forced the window scroll to
     323             :     // be done without background refresh. I do not know why, but that causes the repaint
     324             :     // problems. Taking that out.
     325             :     //  Wallpaper aOldBackground = rWindow.GetBackground();
     326             :     //  rWindow.SetBackground();
     327             : 
     328             :     // #i74769# children should be scrolled
     329           0 :     rWindow.Scroll( -nX, -nY, SCROLL_CHILDREN);
     330           0 :     aMap.SetOrigin( Point( -aScrollPos.Width(), -aScrollPos.Height() ) );
     331           0 :     rWindow.SetMapMode( aMap );
     332           0 :     rWindow.Update();
     333             : 
     334           0 :     DlgEdHint aHint( DlgEdHint::WINDOWSCROLLED );
     335           0 :     Broadcast( aHint );
     336             : }
     337             : 
     338             : 
     339           0 : void DlgEditor::UpdateScrollBars()
     340             : {
     341           0 :     MapMode aMap = rWindow.GetMapMode();
     342           0 :     Point aOrg = aMap.GetOrigin();
     343             : 
     344           0 :     if ( pHScroll )
     345           0 :         pHScroll->SetThumbPos( -aOrg.X() );
     346             : 
     347           0 :     if ( pVScroll )
     348           0 :         pVScroll->SetThumbPos( -aOrg.Y() );
     349           0 : }
     350             : 
     351             : 
     352           0 : void DlgEditor::SetDialog( uno::Reference< container::XNameContainer > xUnoControlDialogModel )
     353             : {
     354             :     // set dialog model
     355           0 :     m_xUnoControlDialogModel = xUnoControlDialogModel;
     356             : 
     357             :     // create dialog form
     358           0 :     pDlgEdForm = new DlgEdForm(*this);
     359           0 :     uno::Reference< awt::XControlModel > xDlgMod( m_xUnoControlDialogModel , uno::UNO_QUERY );
     360           0 :     pDlgEdForm->SetUnoControlModel(xDlgMod);
     361           0 :     static_cast<DlgEdPage*>(pDlgEdModel->GetPage(0))->SetDlgEdForm( pDlgEdForm );
     362           0 :     pDlgEdModel->GetPage(0)->InsertObject( pDlgEdForm );
     363           0 :     AdjustPageSize();
     364           0 :     pDlgEdForm->SetRectFromProps();
     365           0 :     pDlgEdForm->UpdateTabIndices();     // for backward compatibility
     366           0 :     pDlgEdForm->StartListening();
     367             : 
     368             :     // create controls
     369           0 :     Reference< ::com::sun::star::container::XNameAccess > xNameAcc( m_xUnoControlDialogModel, UNO_QUERY );
     370           0 :     if ( xNameAcc.is() )
     371             :     {
     372             :         // get sequence of control names
     373           0 :         Sequence< OUString > aNames = xNameAcc->getElementNames();
     374           0 :         const OUString* pNames = aNames.getConstArray();
     375           0 :         sal_Int32 nCtrls = aNames.getLength();
     376             : 
     377             :         // create a map of tab indices and control names, sorted by tab index
     378           0 :         IndexToNameMap aIndexToNameMap;
     379           0 :         for ( sal_Int32 i = 0; i < nCtrls; ++i )
     380             :         {
     381             :             // get name
     382           0 :             OUString aName( pNames[i] );
     383             : 
     384             :             // get tab index
     385           0 :             sal_Int16 nTabIndex = -1;
     386           0 :             Any aCtrl = xNameAcc->getByName( aName );
     387           0 :             Reference< ::com::sun::star::beans::XPropertySet > xPSet;
     388           0 :                aCtrl >>= xPSet;
     389           0 :             if ( xPSet.is() )
     390           0 :                 xPSet->getPropertyValue( DLGED_PROP_TABINDEX ) >>= nTabIndex;
     391             : 
     392             :             // insert into map
     393           0 :             aIndexToNameMap.insert( IndexToNameMap::value_type( nTabIndex, aName ) );
     394           0 :         }
     395             : 
     396             :         // create controls and insert them into drawing page
     397           0 :         for ( IndexToNameMap::iterator aIt = aIndexToNameMap.begin(); aIt != aIndexToNameMap.end(); ++aIt )
     398             :         {
     399           0 :             Any aCtrl = xNameAcc->getByName( aIt->second );
     400           0 :             Reference< ::com::sun::star::awt::XControlModel > xCtrlModel;
     401           0 :             aCtrl >>= xCtrlModel;
     402           0 :             DlgEdObj* pCtrlObj = new DlgEdObj();
     403           0 :             pCtrlObj->SetUnoControlModel( xCtrlModel );
     404           0 :             pCtrlObj->SetDlgEdForm( pDlgEdForm );
     405           0 :             pDlgEdForm->AddChild( pCtrlObj );
     406           0 :             pDlgEdModel->GetPage(0)->InsertObject( pCtrlObj );
     407           0 :             pCtrlObj->SetRectFromProps();
     408           0 :             pCtrlObj->UpdateStep();
     409           0 :             pCtrlObj->StartListening();
     410           0 :         }
     411             :     }
     412             : 
     413           0 :     bFirstDraw = true;
     414             : 
     415           0 :     pDlgEdModel->SetChanged(false);
     416           0 : }
     417             : 
     418           0 : void DlgEditor::ResetDialog ()
     419             : {
     420           0 :     DlgEdForm* pOldDlgEdForm = pDlgEdForm;
     421           0 :     DlgEdPage* pPage = static_cast<DlgEdPage*>(pDlgEdModel->GetPage(0));
     422           0 :     SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
     423           0 :     bool bWasMarked = pDlgEdView->IsObjMarked( pOldDlgEdForm );
     424           0 :     pDlgEdView->UnmarkAll();
     425           0 :     pPage->Clear();
     426           0 :     pPage->SetDlgEdForm( NULL );
     427           0 :     SetDialog( m_xUnoControlDialogModel );
     428           0 :     if( bWasMarked )
     429           0 :         pDlgEdView->MarkObj( pDlgEdForm, pPgView, false );
     430           0 : }
     431             : 
     432             : 
     433           0 : Reference< util::XNumberFormatsSupplier > const & DlgEditor::GetNumberFormatsSupplier()
     434             : {
     435           0 :     if ( !m_xSupplier.is() )
     436             :     {
     437           0 :         Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     438           0 :         Reference< util::XNumberFormatsSupplier > xSupplier( util::NumberFormatsSupplier::createWithDefaultLocale(xContext) );
     439             : 
     440           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     441           0 :         if ( !m_xSupplier.is() )
     442             :         {
     443           0 :             m_xSupplier = xSupplier;
     444           0 :         }
     445             :     }
     446           0 :     return m_xSupplier;
     447             : }
     448             : 
     449             : 
     450           0 : void DlgEditor::MouseButtonDown( const MouseEvent& rMEvt )
     451             : {
     452           0 :     rWindow.GrabFocus();
     453           0 :     pFunc->MouseButtonDown( rMEvt );
     454           0 : }
     455             : 
     456             : 
     457           0 : void DlgEditor::MouseButtonUp( const MouseEvent& rMEvt )
     458             : {
     459           0 :     bool bRet = pFunc->MouseButtonUp( rMEvt );
     460             : 
     461           0 :     if( eMode == DlgEditor::INSERT )
     462           0 :         bCreateOK = bRet;
     463           0 : }
     464             : 
     465             : 
     466           0 : void DlgEditor::MouseMove( const MouseEvent& rMEvt )
     467             : {
     468           0 :     pFunc->MouseMove( rMEvt );
     469           0 : }
     470             : 
     471             : 
     472           0 : bool DlgEditor::KeyInput( const KeyEvent& rKEvt )
     473             : {
     474           0 :     return pFunc->KeyInput( rKEvt );
     475             : }
     476             : 
     477             : 
     478           0 : void DlgEditor::Paint( const Rectangle& rRect )
     479             : {
     480           0 :     aPaintRect = rRect;
     481           0 :     PaintTimeout( &aPaintTimer );
     482           0 : }
     483             : 
     484             : 
     485           0 : IMPL_LINK_NOARG(DlgEditor, PaintTimeout)
     486             : {
     487           0 :     mnPaintGuard++;
     488             : 
     489           0 :     Size aMacSize;
     490           0 :     if( bFirstDraw &&
     491           0 :         rWindow.IsVisible() &&
     492           0 :         (rWindow.GetOutputSize() != aMacSize) )
     493             :     {
     494           0 :         bFirstDraw = false;
     495             : 
     496             :         // get property set
     497           0 :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  xPSet(pDlgEdForm->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY);
     498             : 
     499           0 :         if ( xPSet.is() )
     500             :         {
     501             :             // get dialog size from properties
     502           0 :             sal_Int32 nWidth = 0, nHeight = 0;
     503           0 :             xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidth;
     504           0 :             xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeight;
     505             : 
     506           0 :             if ( nWidth == 0 && nHeight == 0 )
     507             :             {
     508           0 :                 Size   aSize = rWindow.PixelToLogic( Size( 400, 300 ) );
     509             : 
     510             :                 // align with grid
     511           0 :                 Size aGridSize_(long(pDlgEdView->GetSnapGridWidthX()), long(pDlgEdView->GetSnapGridWidthY()));
     512           0 :                 aSize.Width()  -= aSize.Width()  % aGridSize_.Width();
     513           0 :                 aSize.Height() -= aSize.Height() % aGridSize_.Height();
     514             : 
     515           0 :                 Point  aPos;
     516           0 :                 Size   aOutSize = rWindow.GetOutputSize();
     517           0 :                 aPos.X() = (aOutSize.Width()>>1)  -  (aSize.Width()>>1);
     518           0 :                 aPos.Y() = (aOutSize.Height()>>1) -  (aSize.Height()>>1);
     519             : 
     520             :                 // align with grid
     521           0 :                 aPos.X() -= aPos.X() % aGridSize_.Width();
     522           0 :                 aPos.Y() -= aPos.Y() % aGridSize_.Height();
     523             : 
     524             :                 // don't put in the corner
     525           0 :                 Point aMinPos = rWindow.PixelToLogic( Point( 30, 20 ) );
     526           0 :                 if( (aPos.X() < aMinPos.X()) || (aPos.Y() < aMinPos.Y()) )
     527             :                 {
     528           0 :                     aPos = aMinPos;
     529           0 :                     aPos.X() -= aPos.X() % aGridSize_.Width();
     530           0 :                     aPos.Y() -= aPos.Y() % aGridSize_.Height();
     531             :                 }
     532             : 
     533             :                 // set dialog position and size
     534           0 :                 pDlgEdForm->SetSnapRect( Rectangle( aPos, aSize ) );
     535           0 :                 pDlgEdForm->EndListening(false);
     536           0 :                 pDlgEdForm->SetPropsFromRect();
     537           0 :                 pDlgEdForm->GetDlgEditor().SetDialogModelChanged(true);
     538           0 :                 pDlgEdForm->StartListening();
     539             : 
     540             :                 // set position and size of controls
     541           0 :                 if (const size_t nObjCount = pDlgEdPage->GetObjCount())
     542             :                 {
     543           0 :                     for ( size_t i = 0 ; i < nObjCount ; ++i )
     544           0 :                         if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pDlgEdPage->GetObj(i)))
     545           0 :                             if (!dynamic_cast<DlgEdForm*>(pDlgEdObj))
     546           0 :                                 pDlgEdObj->SetRectFromProps();
     547             :                 }
     548             :             }
     549           0 :         }
     550             :     }
     551             : 
     552             :     // repaint, get PageView and prepare Region
     553           0 :     SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
     554           0 :     const vcl::Region aPaintRectRegion(aPaintRect);
     555             : 
     556             : 
     557             :     // #i74769#
     558           0 :     SdrPaintWindow* pTargetPaintWindow = 0;
     559             : 
     560             :     // mark repaint start
     561           0 :     if(pPgView)
     562             :     {
     563           0 :         pTargetPaintWindow = pPgView->GetView().BeginDrawLayers(&rWindow, aPaintRectRegion);
     564             :         OSL_ENSURE(pTargetPaintWindow, "BeginDrawLayers: Got no SdrPaintWindow (!)");
     565             :     }
     566             : 
     567             :     // draw background self using wallpaper
     568             :     // #i79128# ...and use correct OutDev for that
     569           0 :     if(pTargetPaintWindow)
     570             :     {
     571           0 :         OutputDevice& rTargetOutDev = pTargetPaintWindow->GetTargetOutputDevice();
     572           0 :         rTargetOutDev.DrawWallpaper(aPaintRect, Wallpaper(Color(COL_WHITE)));
     573             :     }
     574             : 
     575             :     // do paint (unbuffered) and mark repaint end
     576           0 :     if(pPgView)
     577             :     {
     578             :         // paint of control layer is done in EndDrawLayers anyway...
     579           0 :         pPgView->GetView().EndDrawLayers(*pTargetPaintWindow, true);
     580             :     }
     581             : 
     582           0 :     mnPaintGuard--;
     583             : 
     584           0 :     return 0;
     585             : }
     586             : 
     587             : 
     588           0 : IMPL_LINK_NOARG(DlgEditor, MarkTimeout)
     589             : {
     590           0 :     rLayout.UpdatePropertyBrowser();
     591           0 :     return 1;
     592             : }
     593             : 
     594             : 
     595           0 : void DlgEditor::SetMode (Mode eNewMode )
     596             : {
     597           0 :     if ( eNewMode != eMode )
     598             :     {
     599           0 :         if ( eNewMode == INSERT )
     600           0 :             pFunc.reset(new DlgEdFuncInsert(*this));
     601             :         else
     602           0 :             pFunc.reset(new DlgEdFuncSelect(*this));
     603             : 
     604           0 :         if ( eNewMode == READONLY )
     605           0 :             pDlgEdModel->SetReadOnly( true );
     606             :         else
     607           0 :             pDlgEdModel->SetReadOnly( false );
     608             :     }
     609             : 
     610           0 :     if ( eNewMode == TEST )
     611           0 :         ShowDialog();
     612             : 
     613           0 :     eMode = eNewMode;
     614           0 : }
     615             : 
     616             : 
     617           0 : void DlgEditor::SetInsertObj( sal_uInt16 eObj )
     618             : {
     619           0 :     eActObj = eObj;
     620             : 
     621           0 :     pDlgEdView->SetCurrentObj( eActObj, DlgInventor );
     622           0 : }
     623             : 
     624             : 
     625             : 
     626             : 
     627           0 : void DlgEditor::CreateDefaultObject()
     628             : {
     629             :     // create object by factory
     630           0 :     SdrObject* pObj = SdrObjFactory::MakeNewObject( pDlgEdView->GetCurrentObjInventor(), pDlgEdView->GetCurrentObjIdentifier(), pDlgEdPage );
     631             : 
     632           0 :     if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pObj))
     633             :     {
     634             :         // set position and size
     635           0 :         Size aSize = rWindow.PixelToLogic( Size( 96, 24 ) );
     636           0 :         Point aPoint = (pDlgEdForm->GetSnapRect()).Center();
     637           0 :         aPoint.X() -= aSize.Width() / 2;
     638           0 :         aPoint.Y() -= aSize.Height() / 2;
     639           0 :         pDlgEdObj->SetSnapRect( Rectangle( aPoint, aSize ) );
     640             : 
     641             :         // set default property values
     642           0 :         pDlgEdObj->SetDefaults();
     643             : 
     644             :         // insert object into drawing page
     645           0 :         SdrPageView* pPageView = pDlgEdView->GetSdrPageView();
     646           0 :         pDlgEdView->InsertObjectAtView( pDlgEdObj, *pPageView);
     647             : 
     648             :         // start listening
     649           0 :         pDlgEdObj->StartListening();
     650             :     }
     651           0 : }
     652             : 
     653             : 
     654           0 : void DlgEditor::Cut()
     655             : {
     656           0 :     Copy();
     657           0 :     Delete();
     658           0 : }
     659             : 
     660             : 
     661           0 : void implCopyStreamToByteSequence( Reference< XInputStream > xStream,
     662             :     Sequence< sal_Int8 >& bytes )
     663             : {
     664           0 :     sal_Int32 nRead = xStream->readBytes( bytes, xStream->available() );
     665             :     for (;;)
     666             :     {
     667           0 :         Sequence< sal_Int8 > readBytes;
     668           0 :         nRead = xStream->readBytes( readBytes, 1024 );
     669           0 :         if (! nRead)
     670           0 :             break;
     671             : 
     672           0 :         sal_Int32 nPos = bytes.getLength();
     673           0 :         bytes.realloc( nPos + nRead );
     674           0 :         memcpy( bytes.getArray() + nPos, readBytes.getConstArray(), (sal_uInt32)nRead );
     675           0 :     }
     676           0 : }
     677             : 
     678           0 : void DlgEditor::Copy()
     679             : {
     680           0 :     if( !pDlgEdView->AreObjectsMarked() )
     681           0 :         return;
     682             : 
     683             :     // stop all drawing actions
     684           0 :     pDlgEdView->BrkAction();
     685             : 
     686             :     // create an empty clipboard dialog model
     687           0 :     Reference< util::XCloneable > xClone( m_xUnoControlDialogModel, UNO_QUERY );
     688           0 :     Reference< util::XCloneable > xNewClone = xClone->createClone();
     689           0 :     Reference< container::XNameContainer > xClipDialogModel( xNewClone, UNO_QUERY );
     690             : 
     691           0 :     Reference< container::XNameAccess > xNAcc( xClipDialogModel, UNO_QUERY );
     692           0 :     if ( xNAcc.is() )
     693             :     {
     694           0 :            Sequence< OUString > aNames = xNAcc->getElementNames();
     695           0 :            const OUString* pNames = aNames.getConstArray();
     696           0 :         sal_uInt32 nCtrls = aNames.getLength();
     697             : 
     698           0 :         for ( sal_uInt32 n = 0; n < nCtrls; n++ )
     699             :         {
     700           0 :                xClipDialogModel->removeByName( pNames[n] );
     701           0 :         }
     702             :     }
     703             : 
     704             :     // insert control models of marked objects into clipboard dialog model
     705           0 :     const size_t nMark = pDlgEdView->GetMarkedObjectList().GetMarkCount();
     706           0 :     for( size_t i = 0; i < nMark; ++i )
     707             :     {
     708           0 :         SdrObject* pObj = pDlgEdView->GetMarkedObjectList().GetMark(i)->GetMarkedSdrObj();
     709           0 :         DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pObj);
     710             : 
     711           0 :         if (pDlgEdObj && !dynamic_cast<DlgEdForm*>(pDlgEdObj))
     712             :         {
     713           0 :             OUString aName;
     714           0 :             Reference< beans::XPropertySet >  xMarkPSet(pDlgEdObj->GetUnoControlModel(), uno::UNO_QUERY);
     715           0 :             if (xMarkPSet.is())
     716             :             {
     717           0 :                 xMarkPSet->getPropertyValue( DLGED_PROP_NAME ) >>= aName;
     718             :             }
     719             : 
     720           0 :             Reference< container::XNameAccess > xNameAcc(m_xUnoControlDialogModel, UNO_QUERY );
     721           0 :             if ( xNameAcc.is() && xNameAcc->hasByName(aName) )
     722             :             {
     723           0 :                 Any aCtrl = xNameAcc->getByName( aName );
     724             : 
     725             :                 // clone control model
     726           0 :                 Reference< util::XCloneable > xCtrl;
     727           0 :                    aCtrl >>= xCtrl;
     728           0 :                 Reference< util::XCloneable > xNewCtrl = xCtrl->createClone();
     729           0 :                 Any aNewCtrl;
     730           0 :                 aNewCtrl <<= xNewCtrl;
     731             : 
     732           0 :                 if (xClipDialogModel.is())
     733           0 :                     xClipDialogModel->insertByName( aName , aNewCtrl );
     734           0 :             }
     735             :         }
     736             :     }
     737             : 
     738             :     // export clipboard dialog model to xml
     739             :     Reference< XComponentContext > xContext(
     740           0 :         comphelper::getProcessComponentContext() );
     741           0 :     Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xClipDialogModel, xContext, m_xDocument );
     742           0 :     Reference< XInputStream > xStream( xISP->createInputStream() );
     743           0 :     Sequence< sal_Int8 > DialogModelBytes;
     744           0 :     implCopyStreamToByteSequence( xStream, DialogModelBytes );
     745           0 :     xStream->closeInput();
     746             : 
     747             :     // set clipboard content
     748           0 :     Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow().GetClipboard();
     749           0 :     if ( xClipboard.is() )
     750             :     {
     751             :         // With resource?
     752           0 :         uno::Reference< beans::XPropertySet > xDialogModelPropSet( m_xUnoControlDialogModel, uno::UNO_QUERY );
     753           0 :         uno::Reference< resource::XStringResourcePersistence > xStringResourcePersistence;
     754           0 :         if( xDialogModelPropSet.is() )
     755             :         {
     756             :             try
     757             :             {
     758           0 :                 Any aResourceResolver = xDialogModelPropSet->getPropertyValue( aResourceResolverPropName );
     759           0 :                 aResourceResolver >>= xStringResourcePersistence;
     760             :             }
     761           0 :             catch(const UnknownPropertyException& )
     762             :             {}
     763             :         }
     764             : 
     765           0 :         DlgEdTransferableImpl* pTrans = NULL;
     766           0 :         if( xStringResourcePersistence.is() )
     767             :         {
     768             :             // With resource, support old and new format
     769             : 
     770             :             // Export xClipDialogModel another time with ids replaced by current language string
     771             :             uno::Reference< resource::XStringResourceManager >
     772           0 :                 xStringResourceManager( xStringResourcePersistence, uno::UNO_QUERY );
     773           0 :             LocalizationMgr::resetResourceForDialog( xClipDialogModel, xStringResourceManager );
     774           0 :             Reference< XInputStreamProvider > xISP2 = ::xmlscript::exportDialogModel( xClipDialogModel, xContext, m_xDocument );
     775           0 :             Reference< XInputStream > xStream2( xISP2->createInputStream() );
     776           0 :             Sequence< sal_Int8 > NoResourceDialogModelBytes;
     777           0 :             implCopyStreamToByteSequence( xStream2, NoResourceDialogModelBytes );
     778           0 :             xStream2->closeInput();
     779             : 
     780             :             // Old format contains dialog with replaced ids
     781           0 :             Sequence< Any > aSeqData(2);
     782           0 :             Any aNoResourceDialogModelBytesAny;
     783           0 :             aNoResourceDialogModelBytesAny <<= NoResourceDialogModelBytes;
     784           0 :             aSeqData[0] = aNoResourceDialogModelBytesAny;
     785             : 
     786             :             // New format contains dialog and resource
     787           0 :             Sequence< sal_Int8 > aResData = xStringResourcePersistence->exportBinary();
     788             : 
     789             :             // Create sequence for combined dialog and resource
     790           0 :             sal_Int32 nDialogDataLen = DialogModelBytes.getLength();
     791           0 :             sal_Int32 nResDataLen = aResData.getLength();
     792             : 
     793             :             // Combined data = 4 Bytes 32Bit Offset to begin of resource data, lowest byte first
     794             :             // + nDialogDataLen bytes dialog data + nResDataLen resource data
     795           0 :             sal_Int32 nTotalLen = 4 + nDialogDataLen + nResDataLen;
     796           0 :             sal_Int32 nResOffset = 4 + nDialogDataLen;
     797           0 :             Sequence< sal_Int8 > aCombinedData( nTotalLen );
     798           0 :             sal_Int8* pCombinedData = aCombinedData.getArray();
     799             : 
     800             :             // Write offset
     801           0 :             sal_Int32 n = nResOffset;
     802           0 :             for( sal_Int16 i = 0 ; i < 4 ; i++ )
     803             :             {
     804           0 :                 pCombinedData[i] = sal_Int8( n & 0xff );
     805           0 :                 n >>= 8;
     806             :             }
     807           0 :             memcpy( pCombinedData + 4, DialogModelBytes.getConstArray(), nDialogDataLen );
     808           0 :             memcpy( pCombinedData + nResOffset, aResData.getConstArray(), nResDataLen );
     809             : 
     810           0 :             Any aCombinedDataAny;
     811           0 :             aCombinedDataAny <<= aCombinedData;
     812           0 :             aSeqData[1] = aCombinedDataAny;
     813             : 
     814           0 :             pTrans = new DlgEdTransferableImpl( m_ClipboardDataFlavorsResource, aSeqData );
     815             :         }
     816             :         else
     817             :         {
     818             :             // No resource, support only old format
     819           0 :             Sequence< Any > aSeqData(1);
     820           0 :             Any aDialogModelBytesAny;
     821           0 :             aDialogModelBytesAny <<= DialogModelBytes;
     822           0 :             aSeqData[0] = aDialogModelBytesAny;
     823           0 :             pTrans = new DlgEdTransferableImpl( m_ClipboardDataFlavors , aSeqData );
     824             :         }
     825           0 :         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
     826           0 :         xClipboard->setContents( pTrans , pTrans );
     827           0 :         Application::AcquireSolarMutex( nRef );
     828           0 :     }
     829             : }
     830             : 
     831             : 
     832           0 : void DlgEditor::Paste()
     833             : {
     834             :     // stop all drawing actions
     835           0 :     pDlgEdView->BrkAction();
     836             : 
     837             :     // unmark all objects
     838           0 :     pDlgEdView->UnmarkAll();
     839             : 
     840             :     // get clipboard
     841           0 :     Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow().GetClipboard();
     842           0 :     if ( xClipboard.is() )
     843             :     {
     844             :         // get clipboard content
     845           0 :         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
     846           0 :         Reference< datatransfer::XTransferable > xTransf = xClipboard->getContents();
     847           0 :         Application::AcquireSolarMutex( nRef );
     848           0 :         if ( xTransf.is() )
     849             :         {
     850             :             // Is target dialog (library) localized?
     851           0 :             uno::Reference< beans::XPropertySet > xDialogModelPropSet( m_xUnoControlDialogModel, uno::UNO_QUERY );
     852           0 :             uno::Reference< resource::XStringResourceManager > xStringResourceManager;
     853           0 :             if( xDialogModelPropSet.is() )
     854             :             {
     855             :                 try
     856             :                 {
     857           0 :                     Any aResourceResolver = xDialogModelPropSet->getPropertyValue( aResourceResolverPropName );
     858           0 :                     aResourceResolver >>= xStringResourceManager;
     859             :                 }
     860           0 :                 catch(const UnknownPropertyException& )
     861             :                 {}
     862             :             }
     863           0 :             bool bLocalized = false;
     864           0 :             if( xStringResourceManager.is() )
     865           0 :                 bLocalized = ( xStringResourceManager->getLocales().getLength() > 0 );
     866             : 
     867           0 :             if ( xTransf->isDataFlavorSupported( m_ClipboardDataFlavors[0] ) )
     868             :             {
     869             :                 // create clipboard dialog model from xml
     870           0 :                 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
     871           0 :                 Reference< container::XNameContainer > xClipDialogModel( xContext->getServiceManager()->createInstanceWithContext(
     872           0 :                     "com.sun.star.awt.UnoControlDialogModel", xContext ), uno::UNO_QUERY );
     873             : 
     874           0 :                 bool bSourceIsLocalized = false;
     875           0 :                 Sequence< sal_Int8 > DialogModelBytes;
     876           0 :                 Sequence< sal_Int8 > aResData;
     877           0 :                 if( bLocalized && xTransf->isDataFlavorSupported( m_ClipboardDataFlavorsResource[1] ) )
     878             :                 {
     879           0 :                     bSourceIsLocalized = true;
     880             : 
     881           0 :                     Any aCombinedDataAny = xTransf->getTransferData( m_ClipboardDataFlavorsResource[1] );
     882           0 :                     Sequence< sal_Int8 > aCombinedData;
     883           0 :                     aCombinedDataAny >>= aCombinedData;
     884           0 :                     const sal_Int8* pCombinedData = aCombinedData.getConstArray();
     885             : 
     886           0 :                     sal_Int32 nTotalLen = aCombinedData.getLength();
     887             : 
     888             :                     // Reading offset
     889           0 :                     sal_Int32 nResOffset = 0;
     890           0 :                     sal_Int32 nFactor = 1;
     891           0 :                     for( sal_Int16 i = 0; i < 4; i++ )
     892             :                     {
     893           0 :                         nResOffset += nFactor * sal_uInt8( pCombinedData[i] );
     894           0 :                         nFactor *= 256;
     895             :                     }
     896             : 
     897           0 :                     sal_Int32 nResDataLen = nTotalLen - nResOffset;
     898           0 :                     sal_Int32 nDialogDataLen = nTotalLen - nResDataLen - 4;
     899             : 
     900           0 :                     DialogModelBytes.realloc( nDialogDataLen );
     901           0 :                     memcpy( DialogModelBytes.getArray(), pCombinedData + 4, nDialogDataLen );
     902             : 
     903           0 :                     aResData.realloc( nResDataLen );
     904           0 :                     memcpy( aResData.getArray(), pCombinedData + nResOffset, nResDataLen );
     905             :                 }
     906             :                 else
     907             :                 {
     908           0 :                     Any aAny = xTransf->getTransferData( m_ClipboardDataFlavors[0] );
     909           0 :                     aAny >>= DialogModelBytes;
     910             :                 }
     911             : 
     912           0 :                 if ( xClipDialogModel.is() )
     913             :                 {
     914           0 :                     ::xmlscript::importDialogModel( ::xmlscript::createInputStream( rtl::ByteSequence(DialogModelBytes.getArray(), DialogModelBytes.getLength()) ) , xClipDialogModel, xContext, m_xDocument );
     915             :                 }
     916             : 
     917             :                 // get control models from clipboard dialog model
     918           0 :                 Reference< ::com::sun::star::container::XNameAccess > xNameAcc( xClipDialogModel, UNO_QUERY );
     919           0 :                 if ( xNameAcc.is() )
     920             :                 {
     921           0 :                        Sequence< OUString > aNames = xNameAcc->getElementNames();
     922           0 :                        const OUString* pNames = aNames.getConstArray();
     923           0 :                     sal_uInt32 nCtrls = aNames.getLength();
     924             : 
     925           0 :                     Reference< resource::XStringResourcePersistence > xStringResourcePersistence;
     926           0 :                     if( nCtrls > 0 && bSourceIsLocalized )
     927             :                     {
     928           0 :                         xStringResourcePersistence = css::resource::StringResource::create( getProcessComponentContext() );
     929           0 :                         xStringResourcePersistence->importBinary( aResData );
     930             :                     }
     931           0 :                     for( sal_uInt32 n = 0; n < nCtrls; n++ )
     932             :                     {
     933           0 :                            Any aA = xNameAcc->getByName( pNames[n] );
     934           0 :                         Reference< ::com::sun::star::awt::XControlModel > xCM;
     935           0 :                            aA >>= xCM;
     936             : 
     937             :                         // clone the control model
     938           0 :                         Reference< util::XCloneable > xClone( xCM, uno::UNO_QUERY );
     939           0 :                         Reference< awt::XControlModel > xCtrlModel( xClone->createClone(), uno::UNO_QUERY );
     940             : 
     941           0 :                         DlgEdObj* pCtrlObj = new DlgEdObj();
     942           0 :                         pCtrlObj->SetDlgEdForm(pDlgEdForm);         // set parent form
     943           0 :                         pDlgEdForm->AddChild(pCtrlObj);             // add child to parent form
     944           0 :                         pCtrlObj->SetUnoControlModel( xCtrlModel ); // set control model
     945             : 
     946             :                         // set new name
     947           0 :                         OUString aOUniqueName( pCtrlObj->GetUniqueName() );
     948           0 :                         Reference< beans::XPropertySet > xPSet( xCtrlModel , UNO_QUERY );
     949           0 :                         Any aUniqueName;
     950           0 :                         aUniqueName <<= aOUniqueName;
     951           0 :                         xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName );
     952             : 
     953             :                         // set tabindex
     954           0 :                         Reference< container::XNameAccess > xNA( m_xUnoControlDialogModel , UNO_QUERY );
     955           0 :                            Sequence< OUString > aNames_ = xNA->getElementNames();
     956           0 :                         Any aTabIndex;
     957           0 :                         aTabIndex <<= (sal_Int16) aNames_.getLength();
     958           0 :                         xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex );
     959             : 
     960           0 :                         if( bLocalized )
     961             :                         {
     962           0 :                             Any aControlAny;
     963           0 :                             aControlAny <<= xCtrlModel;
     964           0 :                             if( bSourceIsLocalized && xStringResourcePersistence.is() )
     965             :                             {
     966             :                                 Reference< resource::XStringResourceResolver >
     967           0 :                                     xSourceStringResolver( xStringResourcePersistence, UNO_QUERY );
     968             :                                 LocalizationMgr::copyResourcesForPastedEditorObject( this,
     969           0 :                                     aControlAny, aOUniqueName, xSourceStringResolver );
     970             :                             }
     971             :                             else
     972             :                             {
     973             :                                 LocalizationMgr::setControlResourceIDsForNewEditorObject
     974           0 :                                     ( this, aControlAny, aOUniqueName );
     975           0 :                             }
     976             :                         }
     977             : 
     978             :                         // insert control model in editor dialog model
     979           0 :                         Any aCtrlModel;
     980           0 :                         aCtrlModel <<= xCtrlModel;
     981           0 :                         m_xUnoControlDialogModel->insertByName( aOUniqueName , aCtrlModel );
     982             : 
     983             :                         // insert object into drawing page
     984           0 :                         pDlgEdModel->GetPage(0)->InsertObject( pCtrlObj );
     985           0 :                         pCtrlObj->SetRectFromProps();
     986           0 :                         pCtrlObj->UpdateStep();
     987           0 :                         pDlgEdForm->UpdateTabOrderAndGroups();
     988           0 :                         pCtrlObj->StartListening();                         // start listening
     989             : 
     990             :                         // mark object
     991           0 :                         SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
     992           0 :                         pDlgEdView->MarkObj( pCtrlObj, pPgView, false, true);
     993           0 :                     }
     994             : 
     995             :                     // center marked objects in dialog editor form
     996           0 :                     Point aMarkCenter = (pDlgEdView->GetMarkedObjRect()).Center();
     997           0 :                     Point aFormCenter = (pDlgEdForm->GetSnapRect()).Center();
     998           0 :                     Point aPoint = aFormCenter - aMarkCenter;
     999           0 :                     Size  aSize( aPoint.X() , aPoint.Y() );
    1000           0 :                     pDlgEdView->MoveMarkedObj( aSize );                     // update of control model properties (position + size) in NbcMove
    1001           0 :                     pDlgEdView->MarkListHasChanged();
    1002             : 
    1003             :                     // dialog model changed
    1004           0 :                     SetDialogModelChanged(true);
    1005           0 :                 }
    1006           0 :             }
    1007           0 :         }
    1008           0 :     }
    1009           0 : }
    1010             : 
    1011             : 
    1012           0 : void DlgEditor::Delete()
    1013             : {
    1014           0 :     if( !pDlgEdView->AreObjectsMarked() )
    1015           0 :         return;
    1016             : 
    1017             :     // remove control models of marked objects from dialog model
    1018           0 :     const size_t nMark = pDlgEdView->GetMarkedObjectList().GetMarkCount();
    1019             : 
    1020           0 :     for( size_t i = 0; i < nMark; ++i )
    1021             :     {
    1022           0 :         SdrObject* pObj = pDlgEdView->GetMarkedObjectList().GetMark(i)->GetMarkedSdrObj();
    1023           0 :         DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pObj);
    1024             : 
    1025           0 :         if ( pDlgEdObj && !dynamic_cast<DlgEdForm*>(pDlgEdObj) )
    1026             :         {
    1027             :             // get name from property
    1028           0 :             OUString aName;
    1029           0 :             uno::Reference< beans::XPropertySet >  xPSet(pDlgEdObj->GetUnoControlModel(), uno::UNO_QUERY);
    1030           0 :             if (xPSet.is())
    1031             :             {
    1032           0 :                 xPSet->getPropertyValue( DLGED_PROP_NAME ) >>= aName;
    1033             :             }
    1034             : 
    1035             :             // remove control from dialog model
    1036           0 :             Reference< ::com::sun::star::container::XNameAccess > xNameAcc(pDlgEdObj->GetDlgEdForm()->GetUnoControlModel(), UNO_QUERY );
    1037           0 :             if ( xNameAcc.is() && xNameAcc->hasByName(aName) )
    1038             :             {
    1039           0 :                 Reference< ::com::sun::star::container::XNameContainer > xCont(xNameAcc, UNO_QUERY );
    1040           0 :                 if ( xCont.is() )
    1041             :                 {
    1042           0 :                     if( xCont->hasByName( aName ) )
    1043             :                     {
    1044           0 :                         Any aAny = xCont->getByName( aName );
    1045           0 :                         LocalizationMgr::deleteControlResourceIDsForDeletedEditorObject( this, aAny, aName );
    1046             :                     }
    1047           0 :                     xCont->removeByName( aName );
    1048           0 :                 }
    1049             :             }
    1050             : 
    1051             :             // remove child from parent form
    1052           0 :             pDlgEdForm->RemoveChild( pDlgEdObj );
    1053             :         }
    1054             :     }
    1055             : 
    1056             :     // update tab indices
    1057           0 :     pDlgEdForm->UpdateTabIndices();
    1058             : 
    1059           0 :     pDlgEdView->BrkAction();
    1060             : 
    1061           0 :     bool const bDlgMarked = UnmarkDialog();
    1062           0 :     pDlgEdView->DeleteMarked();
    1063           0 :     if( bDlgMarked )
    1064           0 :         RemarkDialog();
    1065             : }
    1066             : 
    1067             : 
    1068           0 : bool DlgEditor::IsPasteAllowed()
    1069             : {
    1070             :     // get clipboard
    1071           0 :     Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow().GetClipboard();
    1072           0 :     if ( xClipboard.is() )
    1073             :     {
    1074             :         // get clipboard content
    1075           0 :         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
    1076           0 :         Reference< datatransfer::XTransferable > xTransf = xClipboard->getContents();
    1077           0 :         Application::AcquireSolarMutex( nRef );
    1078           0 :         return xTransf.is() && xTransf->isDataFlavorSupported( m_ClipboardDataFlavors[0] );
    1079             :     }
    1080           0 :     return false;
    1081             : }
    1082             : 
    1083             : 
    1084           0 : void DlgEditor::ShowProperties()
    1085             : {
    1086           0 :     rLayout.ShowPropertyBrowser();
    1087           0 : }
    1088             : 
    1089             : 
    1090           0 : void DlgEditor::UpdatePropertyBrowserDelayed()
    1091             : {
    1092           0 :     aMarkTimer.Start();
    1093           0 : }
    1094             : 
    1095             : 
    1096           0 : bool DlgEditor::IsModified() const
    1097             : {
    1098           0 :     return pDlgEdModel->IsChanged() || bDialogModelChanged;
    1099             : }
    1100             : 
    1101             : 
    1102           0 : void DlgEditor::ClearModifyFlag()
    1103             : {
    1104           0 :     pDlgEdModel->SetChanged(false);
    1105           0 :     bDialogModelChanged = false;
    1106           0 : }
    1107             : 
    1108             : 
    1109             : namespace Print
    1110             : {
    1111             :     long const nLeftMargin = 1700;
    1112             :     long const nRightMargin = 900;
    1113             :     long const nTopMargin = 2000;
    1114             :     long const nBottomMargin = 1000;
    1115             :     long const nBorder = 300;
    1116             : }
    1117             : 
    1118           0 : void lcl_PrintHeader( Printer* pPrinter, const OUString& rTitle ) // not working yet
    1119             : {
    1120             : 
    1121           0 :     pPrinter->Push();
    1122             : 
    1123           0 :     Size const aSz = pPrinter->GetOutputSize();
    1124             : 
    1125           0 :     pPrinter->SetLineColor( COL_BLACK );
    1126           0 :     pPrinter->SetFillColor();
    1127             : 
    1128           0 :     vcl::Font aFont( pPrinter->GetFont() );
    1129           0 :     aFont.SetWeight( WEIGHT_BOLD );
    1130           0 :     aFont.SetAlign( ALIGN_BOTTOM );
    1131           0 :     pPrinter->SetFont( aFont );
    1132             : 
    1133           0 :     long const nFontHeight = pPrinter->GetTextHeight();
    1134             : 
    1135             :     // 1st border => line, 2+3 border = free space
    1136           0 :     long const nYTop = Print::nTopMargin - 3*Print::nBorder - nFontHeight;
    1137             : 
    1138           0 :     long const nXLeft = Print::nLeftMargin - Print::nBorder;
    1139           0 :     long const nXRight = aSz.Width() - Print::nRightMargin + Print::nBorder;
    1140             : 
    1141             :     pPrinter->DrawRect(Rectangle(
    1142             :         Point(nXLeft, nYTop),
    1143           0 :         Size(nXRight - nXLeft, aSz.Height() - nYTop - Print::nBottomMargin + Print::nBorder)
    1144           0 :     ));
    1145             : 
    1146           0 :     long nY = Print::nTopMargin - 2*Print::nBorder;
    1147           0 :     Point aPos(Print::nLeftMargin, nY);
    1148           0 :     pPrinter->DrawText( aPos, rTitle );
    1149             : 
    1150           0 :     nY = Print::nTopMargin - Print::nBorder;
    1151           0 :     pPrinter->DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
    1152             : 
    1153           0 :     pPrinter->Pop();
    1154           0 : }
    1155             : 
    1156             : 
    1157           0 : sal_Int32 DlgEditor::countPages( Printer* )
    1158             : {
    1159           0 :     return 1;
    1160             : }
    1161             : 
    1162           0 : void DlgEditor::printPage( sal_Int32 nPage, Printer* pPrinter, const OUString& rTitle )
    1163             : {
    1164           0 :     if( nPage == 0 )
    1165           0 :         Print( pPrinter, rTitle );
    1166           0 : }
    1167             : 
    1168             : 
    1169           0 : void DlgEditor::Print( Printer* pPrinter, const OUString& rTitle )    // not working yet
    1170             : {
    1171             :     {
    1172           0 :         MapMode aOldMap( pPrinter->GetMapMode());
    1173           0 :         vcl::Font aOldFont( pPrinter->GetFont() );
    1174             : 
    1175           0 :         MapMode aMap( MAP_100TH_MM );
    1176           0 :         pPrinter->SetMapMode( aMap );
    1177           0 :         vcl::Font aFont;
    1178           0 :         aFont.SetAlign( ALIGN_BOTTOM );
    1179           0 :         aFont.SetSize( Size( 0, 360 ));
    1180           0 :         pPrinter->SetFont( aFont );
    1181             : 
    1182           0 :         Size aPaperSz = pPrinter->GetOutputSize();
    1183           0 :         aPaperSz.Width() -= (Print::nLeftMargin + Print::nRightMargin);
    1184           0 :         aPaperSz.Height() -= (Print::nTopMargin + Print::nBottomMargin);
    1185             : 
    1186           0 :         lcl_PrintHeader( pPrinter, rTitle );
    1187             : 
    1188           0 :         Bitmap aDlg;
    1189           0 :         Size aBmpSz( pPrinter->PixelToLogic( aDlg.GetSizePixel() ) );
    1190           0 :         double nPaperSzWidth = aPaperSz.Width();
    1191           0 :         double nPaperSzHeight = aPaperSz.Height();
    1192           0 :         double nBmpSzWidth = aBmpSz.Width();
    1193           0 :         double nBmpSzHeight = aBmpSz.Height();
    1194           0 :         double nScaleX = (nPaperSzWidth / nBmpSzWidth );
    1195           0 :         double nScaleY = (nPaperSzHeight / nBmpSzHeight );
    1196             : 
    1197           0 :         Size aOutputSz;
    1198           0 :         if( nBmpSzHeight * nScaleX <= nPaperSzHeight )
    1199             :         {
    1200           0 :             aOutputSz.Width() = (long)(((double)nBmpSzWidth) * nScaleX);
    1201           0 :             aOutputSz.Height() = (long)(((double)nBmpSzHeight) * nScaleX);
    1202             :         }
    1203             :         else
    1204             :         {
    1205           0 :             aOutputSz.Width() = (long)(((double)nBmpSzWidth) * nScaleY);
    1206           0 :             aOutputSz.Height() = (long)(((double)nBmpSzHeight) * nScaleY);
    1207             :         }
    1208             : 
    1209             :         Point aPosOffs(
    1210           0 :             (aPaperSz.Width() / 2) - (aOutputSz.Width() / 2),
    1211           0 :             (aPaperSz.Height()/ 2) - (aOutputSz.Height() / 2));
    1212             : 
    1213           0 :         aPosOffs.X() += Print::nLeftMargin;
    1214           0 :         aPosOffs.Y() += Print::nTopMargin;
    1215             : 
    1216           0 :         pPrinter->DrawBitmap( aPosOffs, aOutputSz, aDlg );
    1217             : 
    1218           0 :         pPrinter->SetMapMode( aOldMap );
    1219           0 :         pPrinter->SetFont( aOldFont );
    1220             :     }
    1221           0 : }
    1222             : 
    1223             : 
    1224           0 : bool DlgEditor::AdjustPageSize()
    1225             : {
    1226           0 :     bool bAdjustedPageSize = false;
    1227           0 :     Reference< beans::XPropertySet > xPSet( m_xUnoControlDialogModel, UNO_QUERY );
    1228           0 :     if ( xPSet.is() )
    1229             :     {
    1230           0 :         sal_Int32 nFormXIn = 0, nFormYIn = 0, nFormWidthIn = 0, nFormHeightIn = 0;
    1231           0 :         xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nFormXIn;
    1232           0 :         xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nFormYIn;
    1233           0 :         xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nFormWidthIn;
    1234           0 :         xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nFormHeightIn;
    1235             : 
    1236             :         sal_Int32 nFormX, nFormY, nFormWidth, nFormHeight;
    1237           0 :         if ( pDlgEdForm && pDlgEdForm->TransformFormToSdrCoordinates( nFormXIn, nFormYIn, nFormWidthIn, nFormHeightIn, nFormX, nFormY, nFormWidth, nFormHeight ) )
    1238             :         {
    1239           0 :             Size aPageSizeDelta( 400, 300 );
    1240           0 :             aPageSizeDelta = rWindow.PixelToLogic( aPageSizeDelta, MapMode( MAP_100TH_MM ) );
    1241             : 
    1242           0 :             sal_Int32 nNewPageWidth = nFormX + nFormWidth + aPageSizeDelta.Width();
    1243           0 :             sal_Int32 nNewPageHeight = nFormY + nFormHeight + aPageSizeDelta.Height();
    1244             : 
    1245           0 :             Size aPageSizeMin( DLGED_PAGE_WIDTH_MIN, DLGED_PAGE_HEIGHT_MIN );
    1246           0 :             aPageSizeMin = rWindow.PixelToLogic( aPageSizeMin, MapMode( MAP_100TH_MM ) );
    1247           0 :             sal_Int32 nPageWidthMin = aPageSizeMin.Width();
    1248           0 :             sal_Int32 nPageHeightMin = aPageSizeMin.Height();
    1249             : 
    1250           0 :             if ( nNewPageWidth < nPageWidthMin )
    1251           0 :                 nNewPageWidth = nPageWidthMin;
    1252             : 
    1253           0 :             if ( nNewPageHeight < nPageHeightMin )
    1254           0 :                 nNewPageHeight = nPageHeightMin;
    1255             : 
    1256           0 :             if ( pDlgEdPage )
    1257             :             {
    1258           0 :                 Size aPageSize = pDlgEdPage->GetSize();
    1259           0 :                 if ( nNewPageWidth != aPageSize.Width() || nNewPageHeight != aPageSize.Height() )
    1260             :                 {
    1261           0 :                     Size aNewPageSize( nNewPageWidth, nNewPageHeight );
    1262           0 :                     pDlgEdPage->SetSize( aNewPageSize );
    1263           0 :                     pDlgEdView->SetWorkArea( Rectangle( Point( 0, 0 ), aNewPageSize ) );
    1264           0 :                     bAdjustedPageSize = true;
    1265             :                 }
    1266             :             }
    1267             :         }
    1268             :     }
    1269             : 
    1270           0 :     return bAdjustedPageSize;
    1271             : }
    1272             : 
    1273             : 
    1274           0 : } // namespace basctl
    1275             : 
    1276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10