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

Generated by: LCOV version 1.10