1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "basidesh.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"
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>
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
;
60 static const char aResourceResolverPropName
[] = "ResourceResolver";
61 static const char aDecorationPropName
[] = "Decoration";
62 static const char aTitlePropName
[] = "Title";
69 DlgEdHint::DlgEdHint(Kind eHint
)
75 DlgEdHint::DlgEdHint(Kind eHint
, DlgEdObj
* pObj
)
81 DlgEdHint::~DlgEdHint()
89 void DlgEditor::ShowDialog()
91 uno::Reference
< uno::XComponentContext
> xContext
= getProcessComponentContext();
94 uno::Reference
< awt::XUnoControlDialog
> xDlg
= awt::UnoControlDialog::create( xContext
);
96 // clone the dialog model
97 uno::Reference
< util::XCloneable
> xC( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
98 uno::Reference
< util::XCloneable
> xNew
= xC
->createClone();
99 uno::Reference
< awt::XControlModel
> xDlgMod( xNew
, uno::UNO_QUERY
);
101 uno::Reference
< beans::XPropertySet
> xSrcDlgModPropSet( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
102 uno::Reference
< beans::XPropertySet
> xNewDlgModPropSet( xDlgMod
, uno::UNO_QUERY
);
103 if( xNewDlgModPropSet
.is() )
105 if( xSrcDlgModPropSet
.is() )
109 Any aResourceResolver
= xSrcDlgModPropSet
->getPropertyValue( aResourceResolverPropName
);
110 xNewDlgModPropSet
->setPropertyValue( aResourceResolverPropName
, aResourceResolver
);
112 catch(const UnknownPropertyException
& )
114 OSL_FAIL( "DlgEditor::ShowDialog(): No ResourceResolver property" );
118 // Disable decoration
121 bool bDecoration
= true;
123 Any aDecorationAny
= xSrcDlgModPropSet
->getPropertyValue( aDecorationPropName
);
124 aDecorationAny
>>= bDecoration
;
127 xNewDlgModPropSet
->setPropertyValue( aDecorationPropName
, makeAny( true ) );
128 xNewDlgModPropSet
->setPropertyValue( aTitlePropName
, makeAny( OUString() ) );
131 catch(const UnknownPropertyException
& )
136 xDlg
->setModel( xDlgMod
);
139 uno::Reference
< awt::XToolkit
> xToolkit
= awt::Toolkit::create( xContext
);
140 xDlg
->createPeer( xToolkit
, rWindow
.GetComponentInterface() );
144 // need to cast because of multiple inheritance
145 Reference
<awt::XControl
>(xDlg
)->dispose();
149 bool DlgEditor::UnmarkDialog()
151 SdrObject
* pDlgObj
= pDlgEdModel
->GetPage(0)->GetObj(0);
152 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
154 bool bWasMarked
= pDlgEdView
->IsObjMarked( pDlgObj
);
157 pDlgEdView
->MarkObj( pDlgObj
, pPgView
, true );
163 bool DlgEditor::RemarkDialog()
165 SdrObject
* pDlgObj
= pDlgEdModel
->GetPage(0)->GetObj(0);
166 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
168 bool bWasMarked
= pDlgEdView
->IsObjMarked( pDlgObj
);
171 pDlgEdView
->MarkObj( pDlgObj
, pPgView
, false );
177 DlgEditor::DlgEditor (
178 vcl::Window
& rWindow_
, DialogWindowLayout
& rLayout_
,
179 com::sun::star::uno::Reference
<com::sun::star::frame::XModel
> const& xModel
,
180 com::sun::star::uno::Reference
<com::sun::star::container::XNameContainer
> xDialogModel
184 ,pDlgEdModel(new DlgEdModel())
185 ,pDlgEdPage(new DlgEdPage(*pDlgEdModel
))
186 ,m_ClipboardDataFlavors(1)
187 ,m_ClipboardDataFlavorsResource(2)
188 ,pObjFac(new DlgEdFactory(xModel
))
190 ,pFunc(new DlgEdFuncSelect(*this))
192 ,eMode( DlgEditor::SELECT
)
193 ,eActObj( OBJ_DLG_PUSHBUTTON
)
195 ,aGridSize( 100, 100 ) // 100TH_MM
199 ,bDialogModelChanged(false)
201 ,m_xDocument( xModel
)
203 pDlgEdModel
->GetItemPool().FreezeIdRanges();
204 pDlgEdView
.reset(new DlgEdView(*pDlgEdModel
, rWindow_
, *this));
205 pDlgEdModel
->SetScaleUnit( MAP_100TH_MM
);
207 SdrLayerAdmin
& rAdmin
= pDlgEdModel
->GetLayerAdmin();
208 rAdmin
.NewLayer( rAdmin
.GetControlLayerName() );
209 rAdmin
.NewLayer( OUString( "HiddenLayer" ) );
211 pDlgEdModel
->InsertPage(pDlgEdPage
);
213 // set clipboard data flavors
214 m_ClipboardDataFlavors
[0].MimeType
= "application/vnd.sun.xml.dialog" ;
215 m_ClipboardDataFlavors
[0].HumanPresentableName
= "Dialog 6.0" ;
216 m_ClipboardDataFlavors
[0].DataType
= cppu::UnoType
<Sequence
< sal_Int8
>>::get();
218 m_ClipboardDataFlavorsResource
[0] = m_ClipboardDataFlavors
[0];
219 m_ClipboardDataFlavorsResource
[1].MimeType
= "application/vnd.sun.xml.dialogwithresource" ;
220 m_ClipboardDataFlavorsResource
[1].HumanPresentableName
= "Dialog 8.0" ;
221 m_ClipboardDataFlavorsResource
[1].DataType
= cppu::UnoType
<Sequence
< sal_Int8
>>::get();
223 aMarkIdle
.SetPriority(SchedulerPriority::LOW
);
224 aMarkIdle
.SetIdleHdl( LINK( this, DlgEditor
, MarkTimeout
) );
226 rWindow
.SetMapMode( MapMode( MAP_100TH_MM
) );
227 pDlgEdPage
->SetSize( rWindow
.PixelToLogic( Size(DLGED_PAGE_WIDTH_MIN
, DLGED_PAGE_HEIGHT_MIN
) ) );
229 pDlgEdView
->ShowSdrPage(pDlgEdView
->GetModel()->GetPage(0));
230 pDlgEdView
->SetLayerVisible( OUString( "HiddenLayer" ), false );
231 pDlgEdView
->SetMoveSnapOnlyTopLeft(true);
232 pDlgEdView
->SetWorkArea( Rectangle( Point( 0, 0 ), pDlgEdPage
->GetSize() ) );
234 pDlgEdView
->SetGridCoarse( aGridSize
);
235 pDlgEdView
->SetSnapGridWidth(Fraction(aGridSize
.Width(), 1), Fraction(aGridSize
.Height(), 1));
236 pDlgEdView
->SetGridSnap( bGridSnap
);
237 pDlgEdView
->SetGridVisible( bGridVisible
);
238 pDlgEdView
->SetDragStripes(false);
240 pDlgEdView
->SetDesignMode(true);
242 ::comphelper::disposeComponent( m_xControlContainer
);
244 SetDialog(xDialogModel
);
248 DlgEditor::~DlgEditor()
252 ::comphelper::disposeComponent( m_xControlContainer
);
256 Reference
< awt::XControlContainer
> DlgEditor::GetWindowControlContainer()
258 if (!m_xControlContainer
.is())
259 m_xControlContainer
= VCLUnoHelper::CreateControlContainer(&rWindow
);
260 return m_xControlContainer
;
264 void DlgEditor::SetScrollBars( ScrollBar
* pHS
, ScrollBar
* pVS
)
273 void DlgEditor::InitScrollBars()
275 DBG_ASSERT( pHScroll
, "DlgEditor::InitScrollBars: no horizontal scroll bar!" );
276 DBG_ASSERT( pVScroll
, "DlgEditor::InitScrollBars: no vertical scroll bar!" );
277 if ( !pHScroll
|| !pVScroll
)
280 Size aOutSize
= rWindow
.GetOutputSize();
281 Size aPgSize
= pDlgEdPage
->GetSize();
283 pHScroll
->SetRange( Range( 0, aPgSize
.Width() ));
284 pVScroll
->SetRange( Range( 0, aPgSize
.Height() ));
285 pHScroll
->SetVisibleSize( (sal_uLong
)aOutSize
.Width() );
286 pVScroll
->SetVisibleSize( (sal_uLong
)aOutSize
.Height() );
288 pHScroll
->SetLineSize( aOutSize
.Width() / 10 );
289 pVScroll
->SetLineSize( aOutSize
.Height() / 10 );
290 pHScroll
->SetPageSize( aOutSize
.Width() / 2 );
291 pVScroll
->SetPageSize( aOutSize
.Height() / 2 );
293 DoScroll( pHScroll
);
294 DoScroll( pVScroll
);
298 void DlgEditor::DoScroll( ScrollBar
* )
300 if( !pHScroll
|| !pVScroll
)
303 MapMode aMap
= rWindow
.GetMapMode();
304 Point aOrg
= aMap
.GetOrigin();
306 Size
aScrollPos( pHScroll
->GetThumbPos(), pVScroll
->GetThumbPos() );
307 aScrollPos
= rWindow
.LogicToPixel( aScrollPos
);
308 aScrollPos
= rWindow
.PixelToLogic( aScrollPos
);
310 long nX
= aScrollPos
.Width() + aOrg
.X();
311 long nY
= aScrollPos
.Height() + aOrg
.Y();
319 // When scrolling, someone was rescuing the Wallpaper and forced the window scroll to
320 // be done without background refresh. I do not know why, but that causes the repaint
321 // problems. Taking that out.
322 // Wallpaper aOldBackground = rWindow.GetBackground();
323 // rWindow.SetBackground();
325 // #i74769# children should be scrolled
326 rWindow
.Scroll( -nX
, -nY
, SCROLL_CHILDREN
);
327 aMap
.SetOrigin( Point( -aScrollPos
.Width(), -aScrollPos
.Height() ) );
328 rWindow
.SetMapMode( aMap
);
331 DlgEdHint
aHint( DlgEdHint::WINDOWSCROLLED
);
336 void DlgEditor::UpdateScrollBars()
338 MapMode aMap
= rWindow
.GetMapMode();
339 Point aOrg
= aMap
.GetOrigin();
342 pHScroll
->SetThumbPos( -aOrg
.X() );
345 pVScroll
->SetThumbPos( -aOrg
.Y() );
349 void DlgEditor::SetDialog( uno::Reference
< container::XNameContainer
> xUnoControlDialogModel
)
352 m_xUnoControlDialogModel
= xUnoControlDialogModel
;
354 // create dialog form
355 pDlgEdForm
= new DlgEdForm(*this);
356 uno::Reference
< awt::XControlModel
> xDlgMod( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
357 pDlgEdForm
->SetUnoControlModel(xDlgMod
);
358 static_cast<DlgEdPage
*>(pDlgEdModel
->GetPage(0))->SetDlgEdForm( pDlgEdForm
);
359 pDlgEdModel
->GetPage(0)->InsertObject( pDlgEdForm
);
361 pDlgEdForm
->SetRectFromProps();
362 pDlgEdForm
->UpdateTabIndices(); // for backward compatibility
363 pDlgEdForm
->StartListening();
366 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc( m_xUnoControlDialogModel
, UNO_QUERY
);
369 // get sequence of control names
370 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
371 const OUString
* pNames
= aNames
.getConstArray();
372 sal_Int32 nCtrls
= aNames
.getLength();
374 // create a map of tab indices and control names, sorted by tab index
375 IndexToNameMap aIndexToNameMap
;
376 for ( sal_Int32 i
= 0; i
< nCtrls
; ++i
)
379 OUString
aName( pNames
[i
] );
382 sal_Int16 nTabIndex
= -1;
383 Any aCtrl
= xNameAcc
->getByName( aName
);
384 Reference
< ::com::sun::star::beans::XPropertySet
> xPSet
;
387 xPSet
->getPropertyValue( DLGED_PROP_TABINDEX
) >>= nTabIndex
;
390 aIndexToNameMap
.insert( IndexToNameMap::value_type( nTabIndex
, aName
) );
393 // create controls and insert them into drawing page
394 for ( IndexToNameMap::iterator aIt
= aIndexToNameMap
.begin(); aIt
!= aIndexToNameMap
.end(); ++aIt
)
396 Any aCtrl
= xNameAcc
->getByName( aIt
->second
);
397 Reference
< ::com::sun::star::awt::XControlModel
> xCtrlModel
;
398 aCtrl
>>= xCtrlModel
;
399 DlgEdObj
* pCtrlObj
= new DlgEdObj();
400 pCtrlObj
->SetUnoControlModel( xCtrlModel
);
401 pCtrlObj
->SetDlgEdForm( pDlgEdForm
);
402 pDlgEdForm
->AddChild( pCtrlObj
);
403 pDlgEdModel
->GetPage(0)->InsertObject( pCtrlObj
);
404 pCtrlObj
->SetRectFromProps();
405 pCtrlObj
->UpdateStep();
406 pCtrlObj
->StartListening();
412 pDlgEdModel
->SetChanged(false);
415 void DlgEditor::ResetDialog ()
417 DlgEdForm
* pOldDlgEdForm
= pDlgEdForm
;
418 DlgEdPage
* pPage
= static_cast<DlgEdPage
*>(pDlgEdModel
->GetPage(0));
419 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
420 bool bWasMarked
= pDlgEdView
->IsObjMarked( pOldDlgEdForm
);
421 pDlgEdView
->UnmarkAll();
423 pPage
->SetDlgEdForm( NULL
);
424 SetDialog( m_xUnoControlDialogModel
);
426 pDlgEdView
->MarkObj( pDlgEdForm
, pPgView
, false );
430 Reference
< util::XNumberFormatsSupplier
> const & DlgEditor::GetNumberFormatsSupplier()
432 if ( !m_xSupplier
.is() )
434 Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
435 Reference
< util::XNumberFormatsSupplier
> xSupplier( util::NumberFormatsSupplier::createWithDefaultLocale(xContext
) );
437 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
438 if ( !m_xSupplier
.is() )
440 m_xSupplier
= xSupplier
;
447 void DlgEditor::MouseButtonDown( const MouseEvent
& rMEvt
)
450 pFunc
->MouseButtonDown( rMEvt
);
454 void DlgEditor::MouseButtonUp( const MouseEvent
& rMEvt
)
456 bool bRet
= pFunc
->MouseButtonUp( rMEvt
);
458 if( eMode
== DlgEditor::INSERT
)
463 void DlgEditor::MouseMove( const MouseEvent
& rMEvt
)
465 pFunc
->MouseMove( rMEvt
);
469 bool DlgEditor::KeyInput( const KeyEvent
& rKEvt
)
471 return pFunc
->KeyInput( rKEvt
);
475 void DlgEditor::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
)
481 if (bFirstDraw
&& rWindow
.IsVisible() && (rRenderContext
.GetOutputSize() != aMacSize
))
486 css::uno::Reference
<css::beans::XPropertySet
> xPSet(pDlgEdForm
->GetUnoControlModel(), css::uno::UNO_QUERY
);
490 // get dialog size from properties
491 sal_Int32 nWidth
= 0, nHeight
= 0;
492 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidth
;
493 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeight
;
495 if (nWidth
== 0 && nHeight
== 0)
497 Size aSize
= rRenderContext
.PixelToLogic( Size( 400, 300 ) );
500 Size
aGridSize_(long(pDlgEdView
->GetSnapGridWidthX()), long(pDlgEdView
->GetSnapGridWidthY()));
501 aSize
.Width() -= aSize
.Width() % aGridSize_
.Width();
502 aSize
.Height() -= aSize
.Height() % aGridSize_
.Height();
505 Size aOutSize
= rRenderContext
.GetOutputSize();
506 aPos
.X() = (aOutSize
.Width()>>1) - (aSize
.Width()>>1);
507 aPos
.Y() = (aOutSize
.Height()>>1) - (aSize
.Height()>>1);
510 aPos
.X() -= aPos
.X() % aGridSize_
.Width();
511 aPos
.Y() -= aPos
.Y() % aGridSize_
.Height();
513 // don't put in the corner
514 Point aMinPos
= rRenderContext
.PixelToLogic( Point( 30, 20 ) );
515 if( (aPos
.X() < aMinPos
.X()) || (aPos
.Y() < aMinPos
.Y()) )
518 aPos
.X() -= aPos
.X() % aGridSize_
.Width();
519 aPos
.Y() -= aPos
.Y() % aGridSize_
.Height();
522 // set dialog position and size
523 pDlgEdForm
->SetSnapRect( Rectangle( aPos
, aSize
) );
524 pDlgEdForm
->EndListening(false);
525 pDlgEdForm
->SetPropsFromRect();
526 pDlgEdForm
->GetDlgEditor().SetDialogModelChanged(true);
527 pDlgEdForm
->StartListening();
529 // set position and size of controls
530 if (const size_t nObjCount
= pDlgEdPage
->GetObjCount())
532 for (size_t i
= 0 ; i
< nObjCount
; ++i
)
534 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pDlgEdPage
->GetObj(i
)))
536 if (!dynamic_cast<DlgEdForm
*>(pDlgEdObj
))
538 pDlgEdObj
->SetRectFromProps();
547 // repaint, get PageView and prepare Region
548 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
549 const vcl::Region
aPaintRectRegion(aPaintRect
);
552 SdrPaintWindow
* pTargetPaintWindow
= 0;
554 // mark repaint start
557 pTargetPaintWindow
= pPgView
->GetView().BeginDrawLayers(&rRenderContext
, aPaintRectRegion
);
558 OSL_ENSURE(pTargetPaintWindow
, "BeginDrawLayers: Got no SdrPaintWindow (!)");
561 // draw background self using wallpaper
562 // #i79128# ...and use correct OutDev for that
563 if (pTargetPaintWindow
)
565 OutputDevice
& rTargetOutDev
= pTargetPaintWindow
->GetTargetOutputDevice();
566 rTargetOutDev
.DrawWallpaper(aPaintRect
, Wallpaper(Color(COL_WHITE
)));
569 // do paint (unbuffered) and mark repaint end
572 // paint of control layer is done in EndDrawLayers anyway...
573 pPgView
->GetView().EndDrawLayers(*pTargetPaintWindow
, true);
580 IMPL_LINK_NOARG_TYPED(DlgEditor
, MarkTimeout
, Idle
*, void)
582 rLayout
.UpdatePropertyBrowser();
586 void DlgEditor::SetMode (Mode eNewMode
)
588 if ( eNewMode
!= eMode
)
590 if ( eNewMode
== INSERT
)
591 pFunc
.reset(new DlgEdFuncInsert(*this));
593 pFunc
.reset(new DlgEdFuncSelect(*this));
595 if ( eNewMode
== READONLY
)
596 pDlgEdModel
->SetReadOnly( true );
598 pDlgEdModel
->SetReadOnly( false );
601 if ( eNewMode
== TEST
)
608 void DlgEditor::SetInsertObj( sal_uInt16 eObj
)
612 pDlgEdView
->SetCurrentObj( eActObj
, DlgInventor
);
615 void DlgEditor::CreateDefaultObject()
617 // create object by factory
618 SdrObject
* pObj
= SdrObjFactory::MakeNewObject( pDlgEdView
->GetCurrentObjInventor(), pDlgEdView
->GetCurrentObjIdentifier(), pDlgEdPage
);
620 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pObj
))
622 // set position and size
623 Size aSize
= rWindow
.PixelToLogic( Size( 96, 24 ) );
624 Point aPoint
= (pDlgEdForm
->GetSnapRect()).Center();
625 aPoint
.X() -= aSize
.Width() / 2;
626 aPoint
.Y() -= aSize
.Height() / 2;
627 pDlgEdObj
->SetSnapRect( Rectangle( aPoint
, aSize
) );
629 // set default property values
630 pDlgEdObj
->SetDefaults();
632 // insert object into drawing page
633 SdrPageView
* pPageView
= pDlgEdView
->GetSdrPageView();
634 pDlgEdView
->InsertObjectAtView( pDlgEdObj
, *pPageView
);
637 pDlgEdObj
->StartListening();
642 void DlgEditor::Cut()
649 void implCopyStreamToByteSequence( Reference
< XInputStream
> xStream
,
650 Sequence
< sal_Int8
>& bytes
)
652 sal_Int32 nRead
= xStream
->readBytes( bytes
, xStream
->available() );
655 Sequence
< sal_Int8
> readBytes
;
656 nRead
= xStream
->readBytes( readBytes
, 1024 );
660 sal_Int32 nPos
= bytes
.getLength();
661 bytes
.realloc( nPos
+ nRead
);
662 memcpy( bytes
.getArray() + nPos
, readBytes
.getConstArray(), (sal_uInt32
)nRead
);
666 void DlgEditor::Copy()
668 if( !pDlgEdView
->AreObjectsMarked() )
671 // stop all drawing actions
672 pDlgEdView
->BrkAction();
674 // create an empty clipboard dialog model
675 Reference
< util::XCloneable
> xClone( m_xUnoControlDialogModel
, UNO_QUERY
);
676 Reference
< util::XCloneable
> xNewClone
= xClone
->createClone();
677 Reference
< container::XNameContainer
> xClipDialogModel( xNewClone
, UNO_QUERY
);
679 Reference
< container::XNameAccess
> xNAcc( xClipDialogModel
, UNO_QUERY
);
682 Sequence
< OUString
> aNames
= xNAcc
->getElementNames();
683 const OUString
* pNames
= aNames
.getConstArray();
684 sal_uInt32 nCtrls
= aNames
.getLength();
686 for ( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
688 xClipDialogModel
->removeByName( pNames
[n
] );
692 // insert control models of marked objects into clipboard dialog model
693 const size_t nMark
= pDlgEdView
->GetMarkedObjectList().GetMarkCount();
694 for( size_t i
= 0; i
< nMark
; ++i
)
696 SdrObject
* pObj
= pDlgEdView
->GetMarkedObjectList().GetMark(i
)->GetMarkedSdrObj();
697 DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pObj
);
699 if (pDlgEdObj
&& !dynamic_cast<DlgEdForm
*>(pDlgEdObj
))
702 Reference
< beans::XPropertySet
> xMarkPSet(pDlgEdObj
->GetUnoControlModel(), uno::UNO_QUERY
);
705 xMarkPSet
->getPropertyValue( DLGED_PROP_NAME
) >>= aName
;
708 Reference
< container::XNameAccess
> xNameAcc(m_xUnoControlDialogModel
, UNO_QUERY
);
709 if ( xNameAcc
.is() && xNameAcc
->hasByName(aName
) )
711 Any aCtrl
= xNameAcc
->getByName( aName
);
713 // clone control model
714 Reference
< util::XCloneable
> xCtrl
;
716 Reference
< util::XCloneable
> xNewCtrl
= xCtrl
->createClone();
718 aNewCtrl
<<= xNewCtrl
;
720 if (xClipDialogModel
.is())
721 xClipDialogModel
->insertByName( aName
, aNewCtrl
);
726 // export clipboard dialog model to xml
727 Reference
< XComponentContext
> xContext(
728 comphelper::getProcessComponentContext() );
729 Reference
< XInputStreamProvider
> xISP
= ::xmlscript::exportDialogModel( xClipDialogModel
, xContext
, m_xDocument
);
730 Reference
< XInputStream
> xStream( xISP
->createInputStream() );
731 Sequence
< sal_Int8
> DialogModelBytes
;
732 implCopyStreamToByteSequence( xStream
, DialogModelBytes
);
733 xStream
->closeInput();
735 // set clipboard content
736 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= GetWindow().GetClipboard();
737 if ( xClipboard
.is() )
740 uno::Reference
< beans::XPropertySet
> xDialogModelPropSet( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
741 uno::Reference
< resource::XStringResourcePersistence
> xStringResourcePersistence
;
742 if( xDialogModelPropSet
.is() )
746 Any aResourceResolver
= xDialogModelPropSet
->getPropertyValue( aResourceResolverPropName
);
747 aResourceResolver
>>= xStringResourcePersistence
;
749 catch(const UnknownPropertyException
& )
753 DlgEdTransferableImpl
* pTrans
= NULL
;
754 if( xStringResourcePersistence
.is() )
756 // With resource, support old and new format
758 // Export xClipDialogModel another time with ids replaced by current language string
759 uno::Reference
< resource::XStringResourceManager
>
760 xStringResourceManager( xStringResourcePersistence
, uno::UNO_QUERY
);
761 LocalizationMgr::resetResourceForDialog( xClipDialogModel
, xStringResourceManager
);
762 Reference
< XInputStreamProvider
> xISP2
= ::xmlscript::exportDialogModel( xClipDialogModel
, xContext
, m_xDocument
);
763 Reference
< XInputStream
> xStream2( xISP2
->createInputStream() );
764 Sequence
< sal_Int8
> NoResourceDialogModelBytes
;
765 implCopyStreamToByteSequence( xStream2
, NoResourceDialogModelBytes
);
766 xStream2
->closeInput();
768 // Old format contains dialog with replaced ids
769 Sequence
< Any
> aSeqData(2);
770 Any aNoResourceDialogModelBytesAny
;
771 aNoResourceDialogModelBytesAny
<<= NoResourceDialogModelBytes
;
772 aSeqData
[0] = aNoResourceDialogModelBytesAny
;
774 // New format contains dialog and resource
775 Sequence
< sal_Int8
> aResData
= xStringResourcePersistence
->exportBinary();
777 // Create sequence for combined dialog and resource
778 sal_Int32 nDialogDataLen
= DialogModelBytes
.getLength();
779 sal_Int32 nResDataLen
= aResData
.getLength();
781 // Combined data = 4 Bytes 32Bit Offset to begin of resource data, lowest byte first
782 // + nDialogDataLen bytes dialog data + nResDataLen resource data
783 sal_Int32 nTotalLen
= 4 + nDialogDataLen
+ nResDataLen
;
784 sal_Int32 nResOffset
= 4 + nDialogDataLen
;
785 Sequence
< sal_Int8
> aCombinedData( nTotalLen
);
786 sal_Int8
* pCombinedData
= aCombinedData
.getArray();
789 sal_Int32 n
= nResOffset
;
790 for( sal_Int16 i
= 0 ; i
< 4 ; i
++ )
792 pCombinedData
[i
] = sal_Int8( n
& 0xff );
795 memcpy( pCombinedData
+ 4, DialogModelBytes
.getConstArray(), nDialogDataLen
);
796 memcpy( pCombinedData
+ nResOffset
, aResData
.getConstArray(), nResDataLen
);
798 Any aCombinedDataAny
;
799 aCombinedDataAny
<<= aCombinedData
;
800 aSeqData
[1] = aCombinedDataAny
;
802 pTrans
= new DlgEdTransferableImpl( m_ClipboardDataFlavorsResource
, aSeqData
);
806 // No resource, support only old format
807 Sequence
< Any
> aSeqData(1);
808 Any aDialogModelBytesAny
;
809 aDialogModelBytesAny
<<= DialogModelBytes
;
810 aSeqData
[0] = aDialogModelBytesAny
;
811 pTrans
= new DlgEdTransferableImpl( m_ClipboardDataFlavors
, aSeqData
);
813 SolarMutexReleaser aReleaser
;
814 xClipboard
->setContents( pTrans
, pTrans
);
819 void DlgEditor::Paste()
821 // stop all drawing actions
822 pDlgEdView
->BrkAction();
824 // unmark all objects
825 pDlgEdView
->UnmarkAll();
828 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= GetWindow().GetClipboard();
829 if ( xClipboard
.is() )
831 Reference
< datatransfer::XTransferable
> xTransf
;
834 SolarMutexReleaser aReleaser
;
835 // get clipboard content
836 xTransf
= xClipboard
->getContents();
840 // Is target dialog (library) localized?
841 uno::Reference
< beans::XPropertySet
> xDialogModelPropSet( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
842 uno::Reference
< resource::XStringResourceManager
> xStringResourceManager
;
843 if( xDialogModelPropSet
.is() )
847 Any aResourceResolver
= xDialogModelPropSet
->getPropertyValue( aResourceResolverPropName
);
848 aResourceResolver
>>= xStringResourceManager
;
850 catch(const UnknownPropertyException
& )
853 bool bLocalized
= false;
854 if( xStringResourceManager
.is() )
855 bLocalized
= ( xStringResourceManager
->getLocales().getLength() > 0 );
857 if ( xTransf
->isDataFlavorSupported( m_ClipboardDataFlavors
[0] ) )
859 // create clipboard dialog model from xml
860 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
861 Reference
< container::XNameContainer
> xClipDialogModel( xContext
->getServiceManager()->createInstanceWithContext(
862 "com.sun.star.awt.UnoControlDialogModel", xContext
), uno::UNO_QUERY
);
864 bool bSourceIsLocalized
= false;
865 Sequence
< sal_Int8
> DialogModelBytes
;
866 Sequence
< sal_Int8
> aResData
;
867 if( bLocalized
&& xTransf
->isDataFlavorSupported( m_ClipboardDataFlavorsResource
[1] ) )
869 bSourceIsLocalized
= true;
871 Any aCombinedDataAny
= xTransf
->getTransferData( m_ClipboardDataFlavorsResource
[1] );
872 Sequence
< sal_Int8
> aCombinedData
;
873 aCombinedDataAny
>>= aCombinedData
;
874 const sal_Int8
* pCombinedData
= aCombinedData
.getConstArray();
876 sal_Int32 nTotalLen
= aCombinedData
.getLength();
879 sal_Int32 nResOffset
= 0;
880 sal_Int32 nFactor
= 1;
881 for( sal_Int16 i
= 0; i
< 4; i
++ )
883 nResOffset
+= nFactor
* sal_uInt8( pCombinedData
[i
] );
887 sal_Int32 nResDataLen
= nTotalLen
- nResOffset
;
888 sal_Int32 nDialogDataLen
= nTotalLen
- nResDataLen
- 4;
890 DialogModelBytes
.realloc( nDialogDataLen
);
891 memcpy( DialogModelBytes
.getArray(), pCombinedData
+ 4, nDialogDataLen
);
893 aResData
.realloc( nResDataLen
);
894 memcpy( aResData
.getArray(), pCombinedData
+ nResOffset
, nResDataLen
);
898 Any aAny
= xTransf
->getTransferData( m_ClipboardDataFlavors
[0] );
899 aAny
>>= DialogModelBytes
;
902 if ( xClipDialogModel
.is() )
904 ::xmlscript::importDialogModel( ::xmlscript::createInputStream( rtl::ByteSequence(DialogModelBytes
.getArray(), DialogModelBytes
.getLength()) ) , xClipDialogModel
, xContext
, m_xDocument
);
907 // get control models from clipboard dialog model
908 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc( xClipDialogModel
, UNO_QUERY
);
911 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
912 const OUString
* pNames
= aNames
.getConstArray();
913 sal_uInt32 nCtrls
= aNames
.getLength();
915 Reference
< resource::XStringResourcePersistence
> xStringResourcePersistence
;
916 if( nCtrls
> 0 && bSourceIsLocalized
)
918 xStringResourcePersistence
= css::resource::StringResource::create( getProcessComponentContext() );
919 xStringResourcePersistence
->importBinary( aResData
);
921 for( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
923 Any aA
= xNameAcc
->getByName( pNames
[n
] );
924 Reference
< ::com::sun::star::awt::XControlModel
> xCM
;
927 // clone the control model
928 Reference
< util::XCloneable
> xClone( xCM
, uno::UNO_QUERY
);
929 Reference
< awt::XControlModel
> xCtrlModel( xClone
->createClone(), uno::UNO_QUERY
);
931 DlgEdObj
* pCtrlObj
= new DlgEdObj();
932 pCtrlObj
->SetDlgEdForm(pDlgEdForm
); // set parent form
933 pDlgEdForm
->AddChild(pCtrlObj
); // add child to parent form
934 pCtrlObj
->SetUnoControlModel( xCtrlModel
); // set control model
937 OUString
aOUniqueName( pCtrlObj
->GetUniqueName() );
938 Reference
< beans::XPropertySet
> xPSet( xCtrlModel
, UNO_QUERY
);
940 aUniqueName
<<= aOUniqueName
;
941 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aUniqueName
);
944 Reference
< container::XNameAccess
> xNA( m_xUnoControlDialogModel
, UNO_QUERY
);
945 Sequence
< OUString
> aNames_
= xNA
->getElementNames();
947 aTabIndex
<<= (sal_Int16
) aNames_
.getLength();
948 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
953 aControlAny
<<= xCtrlModel
;
954 if( bSourceIsLocalized
&& xStringResourcePersistence
.is() )
956 Reference
< resource::XStringResourceResolver
>
957 xSourceStringResolver( xStringResourcePersistence
, UNO_QUERY
);
958 LocalizationMgr::copyResourcesForPastedEditorObject( this,
959 aControlAny
, aOUniqueName
, xSourceStringResolver
);
963 LocalizationMgr::setControlResourceIDsForNewEditorObject
964 ( this, aControlAny
, aOUniqueName
);
968 // insert control model in editor dialog model
970 aCtrlModel
<<= xCtrlModel
;
971 m_xUnoControlDialogModel
->insertByName( aOUniqueName
, aCtrlModel
);
973 // insert object into drawing page
974 pDlgEdModel
->GetPage(0)->InsertObject( pCtrlObj
);
975 pCtrlObj
->SetRectFromProps();
976 pCtrlObj
->UpdateStep();
977 pDlgEdForm
->UpdateTabOrderAndGroups();
978 pCtrlObj
->StartListening(); // start listening
981 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
982 pDlgEdView
->MarkObj( pCtrlObj
, pPgView
, false, true);
985 // center marked objects in dialog editor form
986 Point aMarkCenter
= (pDlgEdView
->GetMarkedObjRect()).Center();
987 Point aFormCenter
= (pDlgEdForm
->GetSnapRect()).Center();
988 Point aPoint
= aFormCenter
- aMarkCenter
;
989 Size
aSize( aPoint
.X() , aPoint
.Y() );
990 pDlgEdView
->MoveMarkedObj( aSize
); // update of control model properties (position + size) in NbcMove
991 pDlgEdView
->MarkListHasChanged();
993 // dialog model changed
994 SetDialogModelChanged(true);
1002 void DlgEditor::Delete()
1004 if( !pDlgEdView
->AreObjectsMarked() )
1007 // remove control models of marked objects from dialog model
1008 const size_t nMark
= pDlgEdView
->GetMarkedObjectList().GetMarkCount();
1010 for( size_t i
= 0; i
< nMark
; ++i
)
1012 SdrObject
* pObj
= pDlgEdView
->GetMarkedObjectList().GetMark(i
)->GetMarkedSdrObj();
1013 DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pObj
);
1015 if ( pDlgEdObj
&& !dynamic_cast<DlgEdForm
*>(pDlgEdObj
) )
1017 // get name from property
1019 uno::Reference
< beans::XPropertySet
> xPSet(pDlgEdObj
->GetUnoControlModel(), uno::UNO_QUERY
);
1022 xPSet
->getPropertyValue( DLGED_PROP_NAME
) >>= aName
;
1025 // remove control from dialog model
1026 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc(pDlgEdObj
->GetDlgEdForm()->GetUnoControlModel(), UNO_QUERY
);
1027 if ( xNameAcc
.is() && xNameAcc
->hasByName(aName
) )
1029 Reference
< ::com::sun::star::container::XNameContainer
> xCont(xNameAcc
, UNO_QUERY
);
1032 if( xCont
->hasByName( aName
) )
1034 Any aAny
= xCont
->getByName( aName
);
1035 LocalizationMgr::deleteControlResourceIDsForDeletedEditorObject( this, aAny
, aName
);
1037 xCont
->removeByName( aName
);
1041 // remove child from parent form
1042 pDlgEdForm
->RemoveChild( pDlgEdObj
);
1046 // update tab indices
1047 pDlgEdForm
->UpdateTabIndices();
1049 pDlgEdView
->BrkAction();
1051 bool const bDlgMarked
= UnmarkDialog();
1052 pDlgEdView
->DeleteMarked();
1058 bool DlgEditor::IsPasteAllowed()
1061 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= GetWindow().GetClipboard();
1062 if ( xClipboard
.is() )
1064 // get clipboard content
1065 SolarMutexReleaser aReleaser
;
1066 Reference
< datatransfer::XTransferable
> xTransf
= xClipboard
->getContents();
1068 return xTransf
.is() && xTransf
->isDataFlavorSupported( m_ClipboardDataFlavors
[0] );
1074 void DlgEditor::ShowProperties()
1076 rLayout
.ShowPropertyBrowser();
1080 void DlgEditor::UpdatePropertyBrowserDelayed()
1086 bool DlgEditor::IsModified() const
1088 return pDlgEdModel
->IsChanged() || bDialogModelChanged
;
1092 void DlgEditor::ClearModifyFlag()
1094 pDlgEdModel
->SetChanged(false);
1095 bDialogModelChanged
= false;
1101 long const nLeftMargin
= 1700;
1102 long const nRightMargin
= 900;
1103 long const nTopMargin
= 2000;
1104 long const nBottomMargin
= 1000;
1105 long const nBorder
= 300;
1108 void lcl_PrintHeader( Printer
* pPrinter
, const OUString
& rTitle
) // not working yet
1113 Size
const aSz
= pPrinter
->GetOutputSize();
1115 pPrinter
->SetLineColor( COL_BLACK
);
1116 pPrinter
->SetFillColor();
1118 vcl::Font
aFont( pPrinter
->GetFont() );
1119 aFont
.SetWeight( WEIGHT_BOLD
);
1120 aFont
.SetAlign( ALIGN_BOTTOM
);
1121 pPrinter
->SetFont( aFont
);
1123 long const nFontHeight
= pPrinter
->GetTextHeight();
1125 // 1st border => line, 2+3 border = free space
1126 long const nYTop
= Print::nTopMargin
- 3*Print::nBorder
- nFontHeight
;
1128 long const nXLeft
= Print::nLeftMargin
- Print::nBorder
;
1129 long const nXRight
= aSz
.Width() - Print::nRightMargin
+ Print::nBorder
;
1131 pPrinter
->DrawRect(Rectangle(
1132 Point(nXLeft
, nYTop
),
1133 Size(nXRight
- nXLeft
, aSz
.Height() - nYTop
- Print::nBottomMargin
+ Print::nBorder
)
1136 long nY
= Print::nTopMargin
- 2*Print::nBorder
;
1137 Point
aPos(Print::nLeftMargin
, nY
);
1138 pPrinter
->DrawText( aPos
, rTitle
);
1140 nY
= Print::nTopMargin
- Print::nBorder
;
1141 pPrinter
->DrawLine( Point( nXLeft
, nY
), Point( nXRight
, nY
) );
1147 void DlgEditor::printPage( sal_Int32 nPage
, Printer
* pPrinter
, const OUString
& rTitle
)
1150 Print( pPrinter
, rTitle
);
1154 void DlgEditor::Print( Printer
* pPrinter
, const OUString
& rTitle
) // not working yet
1157 MapMode
aOldMap( pPrinter
->GetMapMode());
1158 vcl::Font
aOldFont( pPrinter
->GetFont() );
1160 MapMode
aMap( MAP_100TH_MM
);
1161 pPrinter
->SetMapMode( aMap
);
1163 aFont
.SetAlign( ALIGN_BOTTOM
);
1164 aFont
.SetSize( Size( 0, 360 ));
1165 pPrinter
->SetFont( aFont
);
1167 Size aPaperSz
= pPrinter
->GetOutputSize();
1168 aPaperSz
.Width() -= (Print::nLeftMargin
+ Print::nRightMargin
);
1169 aPaperSz
.Height() -= (Print::nTopMargin
+ Print::nBottomMargin
);
1171 lcl_PrintHeader( pPrinter
, rTitle
);
1174 Size
aBmpSz( pPrinter
->PixelToLogic( aDlg
.GetSizePixel() ) );
1175 double nPaperSzWidth
= aPaperSz
.Width();
1176 double nPaperSzHeight
= aPaperSz
.Height();
1177 double nBmpSzWidth
= aBmpSz
.Width();
1178 double nBmpSzHeight
= aBmpSz
.Height();
1179 double nScaleX
= (nPaperSzWidth
/ nBmpSzWidth
);
1180 double nScaleY
= (nPaperSzHeight
/ nBmpSzHeight
);
1183 if( nBmpSzHeight
* nScaleX
<= nPaperSzHeight
)
1185 aOutputSz
.Width() = (long)(((double)nBmpSzWidth
) * nScaleX
);
1186 aOutputSz
.Height() = (long)(((double)nBmpSzHeight
) * nScaleX
);
1190 aOutputSz
.Width() = (long)(((double)nBmpSzWidth
) * nScaleY
);
1191 aOutputSz
.Height() = (long)(((double)nBmpSzHeight
) * nScaleY
);
1195 (aPaperSz
.Width() / 2) - (aOutputSz
.Width() / 2),
1196 (aPaperSz
.Height()/ 2) - (aOutputSz
.Height() / 2));
1198 aPosOffs
.X() += Print::nLeftMargin
;
1199 aPosOffs
.Y() += Print::nTopMargin
;
1201 pPrinter
->DrawBitmap( aPosOffs
, aOutputSz
, aDlg
);
1203 pPrinter
->SetMapMode( aOldMap
);
1204 pPrinter
->SetFont( aOldFont
);
1209 bool DlgEditor::AdjustPageSize()
1211 bool bAdjustedPageSize
= false;
1212 Reference
< beans::XPropertySet
> xPSet( m_xUnoControlDialogModel
, UNO_QUERY
);
1215 sal_Int32 nFormXIn
= 0, nFormYIn
= 0, nFormWidthIn
= 0, nFormHeightIn
= 0;
1216 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nFormXIn
;
1217 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nFormYIn
;
1218 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nFormWidthIn
;
1219 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nFormHeightIn
;
1221 sal_Int32 nFormX
, nFormY
, nFormWidth
, nFormHeight
;
1222 if ( pDlgEdForm
&& pDlgEdForm
->TransformFormToSdrCoordinates( nFormXIn
, nFormYIn
, nFormWidthIn
, nFormHeightIn
, nFormX
, nFormY
, nFormWidth
, nFormHeight
) )
1224 Size
aPageSizeDelta( 400, 300 );
1225 aPageSizeDelta
= rWindow
.PixelToLogic( aPageSizeDelta
, MapMode( MAP_100TH_MM
) );
1227 sal_Int32 nNewPageWidth
= nFormX
+ nFormWidth
+ aPageSizeDelta
.Width();
1228 sal_Int32 nNewPageHeight
= nFormY
+ nFormHeight
+ aPageSizeDelta
.Height();
1230 Size
aPageSizeMin( DLGED_PAGE_WIDTH_MIN
, DLGED_PAGE_HEIGHT_MIN
);
1231 aPageSizeMin
= rWindow
.PixelToLogic( aPageSizeMin
, MapMode( MAP_100TH_MM
) );
1232 sal_Int32 nPageWidthMin
= aPageSizeMin
.Width();
1233 sal_Int32 nPageHeightMin
= aPageSizeMin
.Height();
1235 if ( nNewPageWidth
< nPageWidthMin
)
1236 nNewPageWidth
= nPageWidthMin
;
1238 if ( nNewPageHeight
< nPageHeightMin
)
1239 nNewPageHeight
= nPageHeightMin
;
1243 Size aPageSize
= pDlgEdPage
->GetSize();
1244 if ( nNewPageWidth
!= aPageSize
.Width() || nNewPageHeight
!= aPageSize
.Height() )
1246 Size
aNewPageSize( nNewPageWidth
, nNewPageHeight
);
1247 pDlgEdPage
->SetSize( aNewPageSize
);
1248 pDlgEdView
->SetWorkArea( Rectangle( Point( 0, 0 ), aNewPageSize
) );
1249 bAdjustedPageSize
= true;
1255 return bAdjustedPageSize
;
1259 } // namespace basctl
1261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */