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 OUString
aResourceResolverPropName( "ResourceResolver" );
61 static OUString
aDecorationPropName( "Decoration" );
62 static OUString
aTitlePropName( "Title" );
69 TYPEINIT1( DlgEdHint
, SfxHint
);
71 DlgEdHint::DlgEdHint(Kind eHint
)
77 DlgEdHint::DlgEdHint(Kind eHint
, DlgEdObj
* pObj
)
83 DlgEdHint::~DlgEdHint()
91 void DlgEditor::ShowDialog()
93 uno::Reference
< uno::XComponentContext
> xContext
= getProcessComponentContext();
96 uno::Reference
< awt::XUnoControlDialog
> xDlg
= awt::UnoControlDialog::create( xContext
);
98 // clone the dialog model
99 uno::Reference
< util::XCloneable
> xC( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
100 uno::Reference
< util::XCloneable
> xNew
= xC
->createClone();
101 uno::Reference
< awt::XControlModel
> xDlgMod( xNew
, uno::UNO_QUERY
);
103 uno::Reference
< beans::XPropertySet
> xSrcDlgModPropSet( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
104 uno::Reference
< beans::XPropertySet
> xNewDlgModPropSet( xDlgMod
, uno::UNO_QUERY
);
105 if( xNewDlgModPropSet
.is() )
107 if( xSrcDlgModPropSet
.is() )
111 Any aResourceResolver
= xSrcDlgModPropSet
->getPropertyValue( aResourceResolverPropName
);
112 xNewDlgModPropSet
->setPropertyValue( aResourceResolverPropName
, aResourceResolver
);
114 catch(const UnknownPropertyException
& )
116 OSL_FAIL( "DlgEditor::ShowDialog(): No ResourceResolver property" );
120 // Disable decoration
121 bool bDecoration
= true;
124 Any aDecorationAny
= xSrcDlgModPropSet
->getPropertyValue( aDecorationPropName
);
125 aDecorationAny
>>= bDecoration
;
128 xNewDlgModPropSet
->setPropertyValue( aDecorationPropName
, makeAny( true ) );
129 xNewDlgModPropSet
->setPropertyValue( aTitlePropName
, makeAny( OUString() ) );
132 catch(const UnknownPropertyException
& )
137 xDlg
->setModel( xDlgMod
);
140 uno::Reference
< awt::XToolkit
> xToolkit
= awt::Toolkit::create( xContext
);
141 xDlg
->createPeer( xToolkit
, rWindow
.GetComponentInterface() );
145 // need to cast because of multiple inheritance
146 Reference
<awt::XControl
>(xDlg
)->dispose();
150 bool DlgEditor::UnmarkDialog()
152 SdrObject
* pDlgObj
= pDlgEdModel
->GetPage(0)->GetObj(0);
153 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
155 bool bWasMarked
= pDlgEdView
->IsObjMarked( pDlgObj
);
158 pDlgEdView
->MarkObj( pDlgObj
, pPgView
, true );
164 bool DlgEditor::RemarkDialog()
166 SdrObject
* pDlgObj
= pDlgEdModel
->GetPage(0)->GetObj(0);
167 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
169 bool bWasMarked
= pDlgEdView
->IsObjMarked( pDlgObj
);
172 pDlgEdView
->MarkObj( pDlgObj
, pPgView
, false );
178 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
185 ,pDlgEdModel(new DlgEdModel())
186 ,pDlgEdPage(new DlgEdPage(*pDlgEdModel
))
187 ,pDlgEdView(new DlgEdView(*pDlgEdModel
, rWindow_
, *this))
188 ,m_ClipboardDataFlavors(1)
189 ,m_ClipboardDataFlavorsResource(2)
190 ,pObjFac(new DlgEdFactory(xModel
))
192 ,pFunc(new DlgEdFuncSelect(*this))
194 ,eMode( DlgEditor::SELECT
)
195 ,eActObj( OBJ_DLG_PUSHBUTTON
)
197 ,aGridSize( 100, 100 ) // 100TH_MM
201 ,bDialogModelChanged(false)
203 ,m_xDocument( xModel
)
205 pDlgEdModel
->GetItemPool().FreezeIdRanges();
206 pDlgEdModel
->SetScaleUnit( MAP_100TH_MM
);
208 SdrLayerAdmin
& rAdmin
= pDlgEdModel
->GetLayerAdmin();
209 rAdmin
.NewLayer( rAdmin
.GetControlLayerName() );
210 rAdmin
.NewLayer( OUString( "HiddenLayer" ) );
212 pDlgEdModel
->InsertPage(pDlgEdPage
);
214 // set clipboard data flavors
215 m_ClipboardDataFlavors
[0].MimeType
= "application/vnd.sun.xml.dialog" ;
216 m_ClipboardDataFlavors
[0].HumanPresentableName
= "Dialog 6.0" ;
217 m_ClipboardDataFlavors
[0].DataType
= ::getCppuType( (const Sequence
< sal_Int8
>*) 0 );
219 m_ClipboardDataFlavorsResource
[0] = m_ClipboardDataFlavors
[0];
220 m_ClipboardDataFlavorsResource
[1].MimeType
= "application/vnd.sun.xml.dialogwithresource" ;
221 m_ClipboardDataFlavorsResource
[1].HumanPresentableName
= "Dialog 8.0" ;
222 m_ClipboardDataFlavorsResource
[1].DataType
= ::getCppuType( (const Sequence
< sal_Int8
>*) 0 );
224 aPaintTimer
.SetTimeout( 1 );
225 aPaintTimer
.SetTimeoutHdl( LINK( this, DlgEditor
, PaintTimeout
) );
227 aMarkTimer
.SetTimeout( 100 );
228 aMarkTimer
.SetTimeoutHdl( LINK( this, DlgEditor
, MarkTimeout
) );
230 rWindow
.SetMapMode( MapMode( MAP_100TH_MM
) );
231 pDlgEdPage
->SetSize( rWindow
.PixelToLogic( Size(DLGED_PAGE_WIDTH_MIN
, DLGED_PAGE_HEIGHT_MIN
) ) );
233 pDlgEdView
->ShowSdrPage(pDlgEdView
->GetModel()->GetPage(0));
234 pDlgEdView
->SetLayerVisible( OUString( "HiddenLayer" ), false );
235 pDlgEdView
->SetMoveSnapOnlyTopLeft(true);
236 pDlgEdView
->SetWorkArea( Rectangle( Point( 0, 0 ), pDlgEdPage
->GetSize() ) );
238 pDlgEdView
->SetGridCoarse( aGridSize
);
239 pDlgEdView
->SetSnapGridWidth(Fraction(aGridSize
.Width(), 1), Fraction(aGridSize
.Height(), 1));
240 pDlgEdView
->SetGridSnap( bGridSnap
);
241 pDlgEdView
->SetGridVisible( bGridVisible
);
242 pDlgEdView
->SetDragStripes(false);
244 pDlgEdView
->SetDesignMode(true);
246 ::comphelper::disposeComponent( m_xControlContainer
);
248 SetDialog(xDialogModel
);
252 DlgEditor::~DlgEditor()
257 ::comphelper::disposeComponent( m_xControlContainer
);
261 Reference
< awt::XControlContainer
> DlgEditor::GetWindowControlContainer()
263 if (!m_xControlContainer
.is())
264 m_xControlContainer
= VCLUnoHelper::CreateControlContainer(&rWindow
);
265 return m_xControlContainer
;
269 void DlgEditor::SetScrollBars( ScrollBar
* pHS
, ScrollBar
* pVS
)
278 void DlgEditor::InitScrollBars()
280 DBG_ASSERT( pHScroll
, "DlgEditor::InitScrollBars: no horizontal scroll bar!" );
281 DBG_ASSERT( pVScroll
, "DlgEditor::InitScrollBars: no vertical scroll bar!" );
282 if ( !pHScroll
|| !pVScroll
)
285 Size aOutSize
= rWindow
.GetOutputSize();
286 Size aPgSize
= pDlgEdPage
->GetSize();
288 pHScroll
->SetRange( Range( 0, aPgSize
.Width() ));
289 pVScroll
->SetRange( Range( 0, aPgSize
.Height() ));
290 pHScroll
->SetVisibleSize( (sal_uLong
)aOutSize
.Width() );
291 pVScroll
->SetVisibleSize( (sal_uLong
)aOutSize
.Height() );
293 pHScroll
->SetLineSize( aOutSize
.Width() / 10 );
294 pVScroll
->SetLineSize( aOutSize
.Height() / 10 );
295 pHScroll
->SetPageSize( aOutSize
.Width() / 2 );
296 pVScroll
->SetPageSize( aOutSize
.Height() / 2 );
298 DoScroll( pHScroll
);
299 DoScroll( pVScroll
);
303 void DlgEditor::DoScroll( ScrollBar
* )
305 if( !pHScroll
|| !pVScroll
)
308 MapMode aMap
= rWindow
.GetMapMode();
309 Point aOrg
= aMap
.GetOrigin();
311 Size
aScrollPos( pHScroll
->GetThumbPos(), pVScroll
->GetThumbPos() );
312 aScrollPos
= rWindow
.LogicToPixel( aScrollPos
);
313 aScrollPos
= rWindow
.PixelToLogic( aScrollPos
);
315 long nX
= aScrollPos
.Width() + aOrg
.X();
316 long nY
= aScrollPos
.Height() + aOrg
.Y();
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();
330 // #i74769# children should be scrolled
331 rWindow
.Scroll( -nX
, -nY
, SCROLL_CHILDREN
);
332 aMap
.SetOrigin( Point( -aScrollPos
.Width(), -aScrollPos
.Height() ) );
333 rWindow
.SetMapMode( aMap
);
336 DlgEdHint
aHint( DlgEdHint::WINDOWSCROLLED
);
341 void DlgEditor::UpdateScrollBars()
343 MapMode aMap
= rWindow
.GetMapMode();
344 Point aOrg
= aMap
.GetOrigin();
347 pHScroll
->SetThumbPos( -aOrg
.X() );
350 pVScroll
->SetThumbPos( -aOrg
.Y() );
354 void DlgEditor::SetDialog( uno::Reference
< container::XNameContainer
> xUnoControlDialogModel
)
357 m_xUnoControlDialogModel
= xUnoControlDialogModel
;
359 // create dialog form
360 pDlgEdForm
= new DlgEdForm(*this);
361 uno::Reference
< awt::XControlModel
> xDlgMod( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
362 pDlgEdForm
->SetUnoControlModel(xDlgMod
);
363 ((DlgEdPage
*)pDlgEdModel
->GetPage(0))->SetDlgEdForm( pDlgEdForm
);
364 pDlgEdModel
->GetPage(0)->InsertObject( pDlgEdForm
);
366 pDlgEdForm
->SetRectFromProps();
367 pDlgEdForm
->UpdateTabIndices(); // for backward compatibility
368 pDlgEdForm
->StartListening();
371 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc( m_xUnoControlDialogModel
, UNO_QUERY
);
374 // get sequence of control names
375 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
376 const OUString
* pNames
= aNames
.getConstArray();
377 sal_Int32 nCtrls
= aNames
.getLength();
379 // create a map of tab indices and control names, sorted by tab index
380 IndexToNameMap aIndexToNameMap
;
381 for ( sal_Int32 i
= 0; i
< nCtrls
; ++i
)
384 OUString
aName( pNames
[i
] );
387 sal_Int16 nTabIndex
= -1;
388 Any aCtrl
= xNameAcc
->getByName( aName
);
389 Reference
< ::com::sun::star::beans::XPropertySet
> xPSet
;
392 xPSet
->getPropertyValue( DLGED_PROP_TABINDEX
) >>= nTabIndex
;
395 aIndexToNameMap
.insert( IndexToNameMap::value_type( nTabIndex
, aName
) );
398 // create controls and insert them into drawing page
399 for ( IndexToNameMap::iterator aIt
= aIndexToNameMap
.begin(); aIt
!= aIndexToNameMap
.end(); ++aIt
)
401 Any aCtrl
= xNameAcc
->getByName( aIt
->second
);
402 Reference
< ::com::sun::star::awt::XControlModel
> xCtrlModel
;
403 aCtrl
>>= xCtrlModel
;
404 DlgEdObj
* pCtrlObj
= new DlgEdObj();
405 pCtrlObj
->SetUnoControlModel( xCtrlModel
);
406 pCtrlObj
->SetDlgEdForm( pDlgEdForm
);
407 pDlgEdForm
->AddChild( pCtrlObj
);
408 pDlgEdModel
->GetPage(0)->InsertObject( pCtrlObj
);
409 pCtrlObj
->SetRectFromProps();
410 pCtrlObj
->UpdateStep();
411 pCtrlObj
->StartListening();
417 pDlgEdModel
->SetChanged(false);
420 void DlgEditor::ResetDialog ()
422 DlgEdForm
* pOldDlgEdForm
= pDlgEdForm
;
423 DlgEdPage
* pPage
= (DlgEdPage
*)pDlgEdModel
->GetPage(0);
424 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
425 bool bWasMarked
= pDlgEdView
->IsObjMarked( pOldDlgEdForm
);
426 pDlgEdView
->UnmarkAll();
428 pPage
->SetDlgEdForm( NULL
);
429 SetDialog( m_xUnoControlDialogModel
);
431 pDlgEdView
->MarkObj( pDlgEdForm
, pPgView
, false );
435 Reference
< util::XNumberFormatsSupplier
> const & DlgEditor::GetNumberFormatsSupplier()
437 if ( !m_xSupplier
.is() )
439 Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
440 Reference
< util::XNumberFormatsSupplier
> xSupplier( util::NumberFormatsSupplier::createWithDefaultLocale(xContext
) );
442 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
443 if ( !m_xSupplier
.is() )
445 m_xSupplier
= xSupplier
;
452 void DlgEditor::MouseButtonDown( const MouseEvent
& rMEvt
)
455 pFunc
->MouseButtonDown( rMEvt
);
459 void DlgEditor::MouseButtonUp( const MouseEvent
& rMEvt
)
461 bool bRet
= pFunc
->MouseButtonUp( rMEvt
);
463 if( eMode
== DlgEditor::INSERT
)
468 void DlgEditor::MouseMove( const MouseEvent
& rMEvt
)
470 pFunc
->MouseMove( rMEvt
);
474 bool DlgEditor::KeyInput( const KeyEvent
& rKEvt
)
476 return pFunc
->KeyInput( rKEvt
);
480 void DlgEditor::Paint( const Rectangle
& rRect
)
483 PaintTimeout( &aPaintTimer
);
487 IMPL_LINK_NOARG(DlgEditor
, PaintTimeout
)
493 rWindow
.IsVisible() &&
494 (rWindow
.GetOutputSize() != aMacSize
) )
499 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xPSet(pDlgEdForm
->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY
);
503 // get dialog size from properties
504 sal_Int32 nWidth
= 0, nHeight
= 0;
505 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidth
;
506 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeight
;
508 if ( nWidth
== 0 && nHeight
== 0 )
510 Size aSize
= rWindow
.PixelToLogic( Size( 400, 300 ) );
513 Size
aGridSize_(long(pDlgEdView
->GetSnapGridWidthX()), long(pDlgEdView
->GetSnapGridWidthY()));
514 aSize
.Width() -= aSize
.Width() % aGridSize_
.Width();
515 aSize
.Height() -= aSize
.Height() % aGridSize_
.Height();
518 Size aOutSize
= rWindow
.GetOutputSize();
519 aPos
.X() = (aOutSize
.Width()>>1) - (aSize
.Width()>>1);
520 aPos
.Y() = (aOutSize
.Height()>>1) - (aSize
.Height()>>1);
523 aPos
.X() -= aPos
.X() % aGridSize_
.Width();
524 aPos
.Y() -= aPos
.Y() % aGridSize_
.Height();
526 // don't put in the corner
527 Point aMinPos
= rWindow
.PixelToLogic( Point( 30, 20 ) );
528 if( (aPos
.X() < aMinPos
.X()) || (aPos
.Y() < aMinPos
.Y()) )
531 aPos
.X() -= aPos
.X() % aGridSize_
.Width();
532 aPos
.Y() -= aPos
.Y() % aGridSize_
.Height();
535 // set dialog position and size
536 pDlgEdForm
->SetSnapRect( Rectangle( aPos
, aSize
) );
537 pDlgEdForm
->EndListening(false);
538 pDlgEdForm
->SetPropsFromRect();
539 pDlgEdForm
->GetDlgEditor().SetDialogModelChanged(true);
540 pDlgEdForm
->StartListening();
542 // set position and size of controls
543 if (sal_uLong nObjCount
= pDlgEdPage
->GetObjCount())
545 for ( sal_uLong i
= 0 ; i
< nObjCount
; i
++ )
546 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pDlgEdPage
->GetObj(i
)))
547 if (!dynamic_cast<DlgEdForm
*>(pDlgEdObj
))
548 pDlgEdObj
->SetRectFromProps();
554 // repaint, get PageView and prepare Region
555 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
556 const Region
aPaintRectRegion(aPaintRect
);
560 SdrPaintWindow
* pTargetPaintWindow
= 0;
562 // mark repaint start
565 pTargetPaintWindow
= pPgView
->GetView().BeginDrawLayers(&rWindow
, aPaintRectRegion
);
566 OSL_ENSURE(pTargetPaintWindow
, "BeginDrawLayers: Got no SdrPaintWindow (!)");
569 // draw background self using wallpaper
570 // #i79128# ...and use correct OutDev for that
571 if(pTargetPaintWindow
)
573 OutputDevice
& rTargetOutDev
= pTargetPaintWindow
->GetTargetOutputDevice();
574 rTargetOutDev
.DrawWallpaper(aPaintRect
, Wallpaper(Color(COL_WHITE
)));
577 // do paint (unbuffered) and mark repaint end
580 // paint of control layer is done in EndDrawLayers anyway...
581 pPgView
->GetView().EndDrawLayers(*pTargetPaintWindow
, true);
590 IMPL_LINK_NOARG(DlgEditor
, MarkTimeout
)
592 rLayout
.UpdatePropertyBrowser();
597 void DlgEditor::SetMode (Mode eNewMode
)
599 if ( eNewMode
!= eMode
)
601 if ( eNewMode
== INSERT
)
602 pFunc
.reset(new DlgEdFuncInsert(*this));
604 pFunc
.reset(new DlgEdFuncSelect(*this));
606 if ( eNewMode
== READONLY
)
607 pDlgEdModel
->SetReadOnly( true );
609 pDlgEdModel
->SetReadOnly( false );
612 if ( eNewMode
== TEST
)
619 void DlgEditor::SetInsertObj( sal_uInt16 eObj
)
623 pDlgEdView
->SetCurrentObj( eActObj
, DlgInventor
);
627 sal_uInt16
DlgEditor::GetInsertObj() const
633 void DlgEditor::CreateDefaultObject()
635 // create object by factory
636 SdrObject
* pObj
= SdrObjFactory::MakeNewObject( pDlgEdView
->GetCurrentObjInventor(), pDlgEdView
->GetCurrentObjIdentifier(), pDlgEdPage
);
638 if (DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pObj
))
640 // set position and size
641 Size aSize
= rWindow
.PixelToLogic( Size( 96, 24 ) );
642 Point aPoint
= (pDlgEdForm
->GetSnapRect()).Center();
643 aPoint
.X() -= aSize
.Width() / 2;
644 aPoint
.Y() -= aSize
.Height() / 2;
645 pDlgEdObj
->SetSnapRect( Rectangle( aPoint
, aSize
) );
647 // set default property values
648 pDlgEdObj
->SetDefaults();
650 // insert object into drawing page
651 SdrPageView
* pPageView
= pDlgEdView
->GetSdrPageView();
652 pDlgEdView
->InsertObjectAtView( pDlgEdObj
, *pPageView
);
655 pDlgEdObj
->StartListening();
660 void DlgEditor::Cut()
667 void implCopyStreamToByteSequence( Reference
< XInputStream
> xStream
,
668 Sequence
< sal_Int8
>& bytes
)
670 sal_Int32 nRead
= xStream
->readBytes( bytes
, xStream
->available() );
673 Sequence
< sal_Int8
> readBytes
;
674 nRead
= xStream
->readBytes( readBytes
, 1024 );
678 sal_Int32 nPos
= bytes
.getLength();
679 bytes
.realloc( nPos
+ nRead
);
680 memcpy( bytes
.getArray() + nPos
, readBytes
.getConstArray(), (sal_uInt32
)nRead
);
684 void DlgEditor::Copy()
686 if( !pDlgEdView
->AreObjectsMarked() )
689 // stop all drawing actions
690 pDlgEdView
->BrkAction();
692 // create an empty clipboard dialog model
693 Reference
< util::XCloneable
> xClone( m_xUnoControlDialogModel
, UNO_QUERY
);
694 Reference
< util::XCloneable
> xNewClone
= xClone
->createClone();
695 Reference
< container::XNameContainer
> xClipDialogModel( xNewClone
, UNO_QUERY
);
697 Reference
< container::XNameAccess
> xNAcc( xClipDialogModel
, UNO_QUERY
);
700 Sequence
< OUString
> aNames
= xNAcc
->getElementNames();
701 const OUString
* pNames
= aNames
.getConstArray();
702 sal_uInt32 nCtrls
= aNames
.getLength();
704 for ( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
706 xClipDialogModel
->removeByName( pNames
[n
] );
710 // insert control models of marked objects into clipboard dialog model
711 sal_uLong nMark
= pDlgEdView
->GetMarkedObjectList().GetMarkCount();
712 for( sal_uLong i
= 0; i
< nMark
; i
++ )
714 SdrObject
* pObj
= pDlgEdView
->GetMarkedObjectList().GetMark(i
)->GetMarkedSdrObj();
715 DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pObj
);
717 if (pDlgEdObj
&& !dynamic_cast<DlgEdForm
*>(pDlgEdObj
))
720 Reference
< beans::XPropertySet
> xMarkPSet(pDlgEdObj
->GetUnoControlModel(), uno::UNO_QUERY
);
723 xMarkPSet
->getPropertyValue( DLGED_PROP_NAME
) >>= aName
;
726 Reference
< container::XNameAccess
> xNameAcc(m_xUnoControlDialogModel
, UNO_QUERY
);
727 if ( xNameAcc
.is() && xNameAcc
->hasByName(aName
) )
729 Any aCtrl
= xNameAcc
->getByName( aName
);
731 // clone control model
732 Reference
< util::XCloneable
> xCtrl
;
734 Reference
< util::XCloneable
> xNewCtrl
= xCtrl
->createClone();
736 aNewCtrl
<<= xNewCtrl
;
738 if (xClipDialogModel
.is())
739 xClipDialogModel
->insertByName( aName
, aNewCtrl
);
744 // export clipboard dialog model to xml
745 Reference
< XComponentContext
> xContext(
746 comphelper::getProcessComponentContext() );
747 Reference
< XInputStreamProvider
> xISP
= ::xmlscript::exportDialogModel( xClipDialogModel
, xContext
, m_xDocument
);
748 Reference
< XInputStream
> xStream( xISP
->createInputStream() );
749 Sequence
< sal_Int8
> DialogModelBytes
;
750 implCopyStreamToByteSequence( xStream
, DialogModelBytes
);
751 xStream
->closeInput();
753 // set clipboard content
754 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= GetWindow().GetClipboard();
755 if ( xClipboard
.is() )
758 uno::Reference
< beans::XPropertySet
> xDialogModelPropSet( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
759 uno::Reference
< resource::XStringResourcePersistence
> xStringResourcePersistence
;
760 if( xDialogModelPropSet
.is() )
764 Any aResourceResolver
= xDialogModelPropSet
->getPropertyValue( aResourceResolverPropName
);
765 aResourceResolver
>>= xStringResourcePersistence
;
767 catch(const UnknownPropertyException
& )
771 DlgEdTransferableImpl
* pTrans
= NULL
;
772 if( xStringResourcePersistence
.is() )
774 // With resource, support old and new format
776 // Export xClipDialogModel another time with ids replaced by current language string
777 uno::Reference
< resource::XStringResourceManager
>
778 xStringResourceManager( xStringResourcePersistence
, uno::UNO_QUERY
);
779 LocalizationMgr::resetResourceForDialog( xClipDialogModel
, xStringResourceManager
);
780 Reference
< XInputStreamProvider
> xISP2
= ::xmlscript::exportDialogModel( xClipDialogModel
, xContext
, m_xDocument
);
781 Reference
< XInputStream
> xStream2( xISP2
->createInputStream() );
782 Sequence
< sal_Int8
> NoResourceDialogModelBytes
;
783 implCopyStreamToByteSequence( xStream2
, NoResourceDialogModelBytes
);
784 xStream2
->closeInput();
786 // Old format contains dialog with replaced ids
787 Sequence
< Any
> aSeqData(2);
788 Any aNoResourceDialogModelBytesAny
;
789 aNoResourceDialogModelBytesAny
<<= NoResourceDialogModelBytes
;
790 aSeqData
[0] = aNoResourceDialogModelBytesAny
;
792 // New format contains dialog and resource
793 Sequence
< sal_Int8
> aResData
= xStringResourcePersistence
->exportBinary();
795 // Create sequence for combined dialog and resource
796 sal_Int32 nDialogDataLen
= DialogModelBytes
.getLength();
797 sal_Int32 nResDataLen
= aResData
.getLength();
799 // Combined data = 4 Bytes 32Bit Offset to begin of resource data, lowest byte first
800 // + nDialogDataLen bytes dialog data + nResDataLen resource data
801 sal_Int32 nTotalLen
= 4 + nDialogDataLen
+ nResDataLen
;
802 sal_Int32 nResOffset
= 4 + nDialogDataLen
;
803 Sequence
< sal_Int8
> aCombinedData( nTotalLen
);
804 sal_Int8
* pCombinedData
= aCombinedData
.getArray();
807 sal_Int32 n
= nResOffset
;
808 for( sal_Int16 i
= 0 ; i
< 4 ; i
++ )
810 pCombinedData
[i
] = sal_Int8( n
& 0xff );
813 memcpy( pCombinedData
+ 4, DialogModelBytes
.getConstArray(), nDialogDataLen
);
814 memcpy( pCombinedData
+ nResOffset
, aResData
.getConstArray(), nResDataLen
);
816 Any aCombinedDataAny
;
817 aCombinedDataAny
<<= aCombinedData
;
818 aSeqData
[1] = aCombinedDataAny
;
820 pTrans
= new DlgEdTransferableImpl( m_ClipboardDataFlavorsResource
, aSeqData
);
824 // No resource, support only old format
825 Sequence
< Any
> aSeqData(1);
826 Any aDialogModelBytesAny
;
827 aDialogModelBytesAny
<<= DialogModelBytes
;
828 aSeqData
[0] = aDialogModelBytesAny
;
829 pTrans
= new DlgEdTransferableImpl( m_ClipboardDataFlavors
, aSeqData
);
831 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
832 xClipboard
->setContents( pTrans
, pTrans
);
833 Application::AcquireSolarMutex( nRef
);
838 void DlgEditor::Paste()
840 // stop all drawing actions
841 pDlgEdView
->BrkAction();
843 // unmark all objects
844 pDlgEdView
->UnmarkAll();
847 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= GetWindow().GetClipboard();
848 if ( xClipboard
.is() )
850 // get clipboard content
851 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
852 Reference
< datatransfer::XTransferable
> xTransf
= xClipboard
->getContents();
853 Application::AcquireSolarMutex( nRef
);
856 // Is target dialog (library) localized?
857 uno::Reference
< beans::XPropertySet
> xDialogModelPropSet( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
858 uno::Reference
< resource::XStringResourceManager
> xStringResourceManager
;
859 if( xDialogModelPropSet
.is() )
863 Any aResourceResolver
= xDialogModelPropSet
->getPropertyValue( aResourceResolverPropName
);
864 aResourceResolver
>>= xStringResourceManager
;
866 catch(const UnknownPropertyException
& )
869 bool bLocalized
= false;
870 if( xStringResourceManager
.is() )
871 bLocalized
= ( xStringResourceManager
->getLocales().getLength() > 0 );
873 if ( xTransf
->isDataFlavorSupported( m_ClipboardDataFlavors
[0] ) )
875 // create clipboard dialog model from xml
876 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
877 Reference
< container::XNameContainer
> xClipDialogModel( xContext
->getServiceManager()->createInstanceWithContext(
878 "com.sun.star.awt.UnoControlDialogModel", xContext
), uno::UNO_QUERY
);
880 bool bSourceIsLocalized
= false;
881 Sequence
< sal_Int8
> DialogModelBytes
;
882 Sequence
< sal_Int8
> aResData
;
883 if( bLocalized
&& xTransf
->isDataFlavorSupported( m_ClipboardDataFlavorsResource
[1] ) )
885 bSourceIsLocalized
= true;
887 Any aCombinedDataAny
= xTransf
->getTransferData( m_ClipboardDataFlavorsResource
[1] );
888 Sequence
< sal_Int8
> aCombinedData
;
889 aCombinedDataAny
>>= aCombinedData
;
890 const sal_Int8
* pCombinedData
= aCombinedData
.getConstArray();
892 sal_Int32 nTotalLen
= aCombinedData
.getLength();
895 sal_Int32 nResOffset
= 0;
896 sal_Int32 nFactor
= 1;
897 for( sal_Int16 i
= 0; i
< 4; i
++ )
899 nResOffset
+= nFactor
* sal_uInt8( pCombinedData
[i
] );
903 sal_Int32 nResDataLen
= nTotalLen
- nResOffset
;
904 sal_Int32 nDialogDataLen
= nTotalLen
- nResDataLen
- 4;
906 DialogModelBytes
.realloc( nDialogDataLen
);
907 memcpy( DialogModelBytes
.getArray(), pCombinedData
+ 4, nDialogDataLen
);
909 aResData
.realloc( nResDataLen
);
910 memcpy( aResData
.getArray(), pCombinedData
+ nResOffset
, nResDataLen
);
914 Any aAny
= xTransf
->getTransferData( m_ClipboardDataFlavors
[0] );
915 aAny
>>= DialogModelBytes
;
918 if ( xClipDialogModel
.is() )
920 ::xmlscript::importDialogModel( ::xmlscript::createInputStream( rtl::ByteSequence(DialogModelBytes
.getArray(), DialogModelBytes
.getLength()) ) , xClipDialogModel
, xContext
, m_xDocument
);
923 // get control models from clipboard dialog model
924 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc( xClipDialogModel
, UNO_QUERY
);
927 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
928 const OUString
* pNames
= aNames
.getConstArray();
929 sal_uInt32 nCtrls
= aNames
.getLength();
931 Reference
< resource::XStringResourcePersistence
> xStringResourcePersistence
;
932 if( nCtrls
> 0 && bSourceIsLocalized
)
934 xStringResourcePersistence
= css::resource::StringResource::create( getProcessComponentContext() );
935 xStringResourcePersistence
->importBinary( aResData
);
937 for( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
939 Any aA
= xNameAcc
->getByName( pNames
[n
] );
940 Reference
< ::com::sun::star::awt::XControlModel
> xCM
;
943 // clone the control model
944 Reference
< util::XCloneable
> xClone( xCM
, uno::UNO_QUERY
);
945 Reference
< awt::XControlModel
> xCtrlModel( xClone
->createClone(), uno::UNO_QUERY
);
947 DlgEdObj
* pCtrlObj
= new DlgEdObj();
948 pCtrlObj
->SetDlgEdForm(pDlgEdForm
); // set parent form
949 pDlgEdForm
->AddChild(pCtrlObj
); // add child to parent form
950 pCtrlObj
->SetUnoControlModel( xCtrlModel
); // set control model
953 OUString
aOUniqueName( pCtrlObj
->GetUniqueName() );
954 Reference
< beans::XPropertySet
> xPSet( xCtrlModel
, UNO_QUERY
);
956 aUniqueName
<<= aOUniqueName
;
957 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aUniqueName
);
960 Reference
< container::XNameAccess
> xNA( m_xUnoControlDialogModel
, UNO_QUERY
);
961 Sequence
< OUString
> aNames_
= xNA
->getElementNames();
963 aTabIndex
<<= (sal_Int16
) aNames_
.getLength();
964 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
969 aControlAny
<<= xCtrlModel
;
970 if( bSourceIsLocalized
&& xStringResourcePersistence
.is() )
972 Reference
< resource::XStringResourceResolver
>
973 xSourceStringResolver( xStringResourcePersistence
, UNO_QUERY
);
974 LocalizationMgr::copyResourcesForPastedEditorObject( this,
975 aControlAny
, aOUniqueName
, xSourceStringResolver
);
979 LocalizationMgr::setControlResourceIDsForNewEditorObject
980 ( this, aControlAny
, aOUniqueName
);
984 // insert control model in editor dialog model
986 aCtrlModel
<<= xCtrlModel
;
987 m_xUnoControlDialogModel
->insertByName( aOUniqueName
, aCtrlModel
);
989 // insert object into drawing page
990 pDlgEdModel
->GetPage(0)->InsertObject( pCtrlObj
);
991 pCtrlObj
->SetRectFromProps();
992 pCtrlObj
->UpdateStep();
993 pDlgEdForm
->UpdateTabOrderAndGroups();
994 pCtrlObj
->StartListening(); // start listening
997 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
998 pDlgEdView
->MarkObj( pCtrlObj
, pPgView
, false, true);
1001 // center marked objects in dialog editor form
1002 Point aMarkCenter
= (pDlgEdView
->GetMarkedObjRect()).Center();
1003 Point aFormCenter
= (pDlgEdForm
->GetSnapRect()).Center();
1004 Point aPoint
= aFormCenter
- aMarkCenter
;
1005 Size
aSize( aPoint
.X() , aPoint
.Y() );
1006 pDlgEdView
->MoveMarkedObj( aSize
); // update of control model properties (position + size) in NbcMove
1007 pDlgEdView
->MarkListHasChanged();
1009 // dialog model changed
1010 SetDialogModelChanged(true);
1018 void DlgEditor::Delete()
1020 if( !pDlgEdView
->AreObjectsMarked() )
1023 // remove control models of marked objects from dialog model
1024 sal_uLong nMark
= pDlgEdView
->GetMarkedObjectList().GetMarkCount();
1026 for( sal_uLong i
= 0; i
< nMark
; i
++ )
1028 SdrObject
* pObj
= pDlgEdView
->GetMarkedObjectList().GetMark(i
)->GetMarkedSdrObj();
1029 DlgEdObj
* pDlgEdObj
= dynamic_cast<DlgEdObj
*>(pObj
);
1031 if ( pDlgEdObj
&& !dynamic_cast<DlgEdForm
*>(pDlgEdObj
) )
1033 // get name from property
1035 uno::Reference
< beans::XPropertySet
> xPSet(pDlgEdObj
->GetUnoControlModel(), uno::UNO_QUERY
);
1038 xPSet
->getPropertyValue( DLGED_PROP_NAME
) >>= aName
;
1041 // remove control from dialog model
1042 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc(pDlgEdObj
->GetDlgEdForm()->GetUnoControlModel(), UNO_QUERY
);
1043 if ( xNameAcc
.is() && xNameAcc
->hasByName(aName
) )
1045 Reference
< ::com::sun::star::container::XNameContainer
> xCont(xNameAcc
, UNO_QUERY
);
1048 if( xCont
->hasByName( aName
) )
1050 Any aAny
= xCont
->getByName( aName
);
1051 LocalizationMgr::deleteControlResourceIDsForDeletedEditorObject( this, aAny
, aName
);
1053 xCont
->removeByName( aName
);
1057 // remove child from parent form
1058 pDlgEdForm
->RemoveChild( pDlgEdObj
);
1062 // update tab indices
1063 pDlgEdForm
->UpdateTabIndices();
1065 pDlgEdView
->BrkAction();
1067 bool const bDlgMarked
= UnmarkDialog();
1068 pDlgEdView
->DeleteMarked();
1074 bool DlgEditor::IsPasteAllowed()
1077 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= GetWindow().GetClipboard();
1078 if ( xClipboard
.is() )
1080 // get clipboard content
1081 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
1082 Reference
< datatransfer::XTransferable
> xTransf
= xClipboard
->getContents();
1083 Application::AcquireSolarMutex( nRef
);
1084 return xTransf
.is() && xTransf
->isDataFlavorSupported( m_ClipboardDataFlavors
[0] );
1090 void DlgEditor::ShowProperties()
1092 rLayout
.ShowPropertyBrowser();
1096 void DlgEditor::UpdatePropertyBrowserDelayed()
1102 bool DlgEditor::IsModified() const
1104 return pDlgEdModel
->IsChanged() || bDialogModelChanged
;
1108 void DlgEditor::ClearModifyFlag()
1110 pDlgEdModel
->SetChanged(false);
1111 bDialogModelChanged
= false;
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;
1124 void lcl_PrintHeader( Printer
* pPrinter
, const OUString
& rTitle
) // not working yet
1129 Size
const aSz
= pPrinter
->GetOutputSize();
1131 pPrinter
->SetLineColor( COL_BLACK
);
1132 pPrinter
->SetFillColor();
1134 Font
aFont( pPrinter
->GetFont() );
1135 aFont
.SetWeight( WEIGHT_BOLD
);
1136 aFont
.SetAlign( ALIGN_BOTTOM
);
1137 pPrinter
->SetFont( aFont
);
1139 long const nFontHeight
= pPrinter
->GetTextHeight();
1141 // 1st border => line, 2+3 border = free space
1142 long const nYTop
= Print::nTopMargin
- 3*Print::nBorder
- nFontHeight
;
1144 long const nXLeft
= Print::nLeftMargin
- Print::nBorder
;
1145 long const nXRight
= aSz
.Width() - Print::nRightMargin
+ Print::nBorder
;
1147 pPrinter
->DrawRect(Rectangle(
1148 Point(nXLeft
, nYTop
),
1149 Size(nXRight
- nXLeft
, aSz
.Height() - nYTop
- Print::nBottomMargin
+ Print::nBorder
)
1152 long nY
= Print::nTopMargin
- 2*Print::nBorder
;
1153 Point
aPos(Print::nLeftMargin
, nY
);
1154 pPrinter
->DrawText( aPos
, rTitle
);
1156 nY
= Print::nTopMargin
- Print::nBorder
;
1157 pPrinter
->DrawLine( Point( nXLeft
, nY
), Point( nXRight
, nY
) );
1163 sal_Int32
DlgEditor::countPages( Printer
* )
1168 void DlgEditor::printPage( sal_Int32 nPage
, Printer
* pPrinter
, const OUString
& rTitle
)
1171 Print( pPrinter
, rTitle
);
1175 void DlgEditor::Print( Printer
* pPrinter
, const OUString
& rTitle
) // not working yet
1178 MapMode
aOldMap( pPrinter
->GetMapMode());
1179 Font
aOldFont( pPrinter
->GetFont() );
1181 MapMode
aMap( MAP_100TH_MM
);
1182 pPrinter
->SetMapMode( aMap
);
1184 aFont
.SetAlign( ALIGN_BOTTOM
);
1185 aFont
.SetSize( Size( 0, 360 ));
1186 pPrinter
->SetFont( aFont
);
1188 Size aPaperSz
= pPrinter
->GetOutputSize();
1189 aPaperSz
.Width() -= (Print::nLeftMargin
+ Print::nRightMargin
);
1190 aPaperSz
.Height() -= (Print::nTopMargin
+ Print::nBottomMargin
);
1192 lcl_PrintHeader( pPrinter
, rTitle
);
1195 Size
aBmpSz( pPrinter
->PixelToLogic( aDlg
.GetSizePixel() ) );
1196 double nPaperSzWidth
= aPaperSz
.Width();
1197 double nPaperSzHeight
= aPaperSz
.Height();
1198 double nBmpSzWidth
= aBmpSz
.Width();
1199 double nBmpSzHeight
= aBmpSz
.Height();
1200 double nScaleX
= (nPaperSzWidth
/ nBmpSzWidth
);
1201 double nScaleY
= (nPaperSzHeight
/ nBmpSzHeight
);
1204 if( nBmpSzHeight
* nScaleX
<= nPaperSzHeight
)
1206 aOutputSz
.Width() = (long)(((double)nBmpSzWidth
) * nScaleX
);
1207 aOutputSz
.Height() = (long)(((double)nBmpSzHeight
) * nScaleX
);
1211 aOutputSz
.Width() = (long)(((double)nBmpSzWidth
) * nScaleY
);
1212 aOutputSz
.Height() = (long)(((double)nBmpSzHeight
) * nScaleY
);
1216 (aPaperSz
.Width() / 2) - (aOutputSz
.Width() / 2),
1217 (aPaperSz
.Height()/ 2) - (aOutputSz
.Height() / 2));
1219 aPosOffs
.X() += Print::nLeftMargin
;
1220 aPosOffs
.Y() += Print::nTopMargin
;
1222 pPrinter
->DrawBitmap( aPosOffs
, aOutputSz
, aDlg
);
1224 pPrinter
->SetMapMode( aOldMap
);
1225 pPrinter
->SetFont( aOldFont
);
1230 bool DlgEditor::AdjustPageSize()
1232 bool bAdjustedPageSize
= false;
1233 Reference
< beans::XPropertySet
> xPSet( m_xUnoControlDialogModel
, UNO_QUERY
);
1236 sal_Int32 nFormXIn
= 0, nFormYIn
= 0, nFormWidthIn
= 0, nFormHeightIn
= 0;
1237 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nFormXIn
;
1238 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nFormYIn
;
1239 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nFormWidthIn
;
1240 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nFormHeightIn
;
1242 sal_Int32 nFormX
, nFormY
, nFormWidth
, nFormHeight
;
1243 if ( pDlgEdForm
&& pDlgEdForm
->TransformFormToSdrCoordinates( nFormXIn
, nFormYIn
, nFormWidthIn
, nFormHeightIn
, nFormX
, nFormY
, nFormWidth
, nFormHeight
) )
1245 Size
aPageSizeDelta( 400, 300 );
1246 aPageSizeDelta
= rWindow
.PixelToLogic( aPageSizeDelta
, MapMode( MAP_100TH_MM
) );
1248 sal_Int32 nNewPageWidth
= nFormX
+ nFormWidth
+ aPageSizeDelta
.Width();
1249 sal_Int32 nNewPageHeight
= nFormY
+ nFormHeight
+ aPageSizeDelta
.Height();
1251 Size
aPageSizeMin( DLGED_PAGE_WIDTH_MIN
, DLGED_PAGE_HEIGHT_MIN
);
1252 aPageSizeMin
= rWindow
.PixelToLogic( aPageSizeMin
, MapMode( MAP_100TH_MM
) );
1253 sal_Int32 nPageWidthMin
= aPageSizeMin
.Width();
1254 sal_Int32 nPageHeightMin
= aPageSizeMin
.Height();
1256 if ( nNewPageWidth
< nPageWidthMin
)
1257 nNewPageWidth
= nPageWidthMin
;
1259 if ( nNewPageHeight
< nPageHeightMin
)
1260 nNewPageHeight
= nPageHeightMin
;
1264 Size aPageSize
= pDlgEdPage
->GetSize();
1265 if ( nNewPageWidth
!= aPageSize
.Width() || nNewPageHeight
!= aPageSize
.Height() )
1267 Size
aNewPageSize( nNewPageWidth
, nNewPageHeight
);
1268 pDlgEdPage
->SetSize( aNewPageSize
);
1269 pDlgEdView
->SetWorkArea( Rectangle( Point( 0, 0 ), aNewPageSize
) );
1270 bAdjustedPageSize
= true;
1276 return bAdjustedPageSize
;
1280 } // namespace basctl
1282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */