1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlged.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
34 #include "dlgedfunc.hxx"
35 #include "dlgedfac.hxx"
36 #include <dlgedmod.hxx>
37 #include "dlgedpage.hxx"
38 #include "dlgedview.hxx"
39 #include "dlgedobj.hxx"
40 #include "dlgedclip.hxx"
41 #include <dlgeddef.hxx>
42 #include "propbrw.hxx"
43 #include <localizationmgr.hxx>
45 #include <basidesh.hxx>
46 #include <iderdll.hxx>
47 #include <vcl/scrbar.hxx>
48 #include <tools/shl.hxx>
49 #include <svtools/itempool.hxx>
50 #include <sfx2/viewfrm.hxx>
52 #ifndef _SVX_SVXIDS_HRC
53 #include <svx/svxids.hrc>
55 #include <svx/svdpagv.hxx>
56 #include <xmlscript/xml_helper.hxx>
57 #include <xmlscript/xmldlg_imexp.hxx>
58 #include <com/sun/star/beans/PropertyValue.hpp>
59 #include <com/sun/star/beans/XPropertySet.hpp>
60 #include <com/sun/star/beans/Property.hpp>
61 #include <com/sun/star/awt/XDialog.hpp>
62 #include <com/sun/star/util/XCloneable.hpp>
63 #include <com/sun/star/resource/XStringResourcePersistence.hpp>
64 #include <comphelper/processfactory.hxx>
65 #include <comphelper/types.hxx>
66 #include <vcl/svapp.hxx>
67 #include <toolkit/helper/vclunohelper.hxx>
70 #include <svx/sdrpaintwindow.hxx>
72 using namespace comphelper
;
73 using namespace ::com::sun::star
;
74 using namespace ::com::sun::star::uno
;
75 using namespace ::com::sun::star::beans
;
76 using namespace ::com::sun::star::io
;
77 using ::rtl::OUString
;
79 static ::rtl::OUString aResourceResolverPropName
=
80 ::rtl::OUString::createFromAscii( "ResourceResolver" );
81 static ::rtl::OUString aDecorationPropName
=
82 ::rtl::OUString::createFromAscii( "Decoration" );
83 static ::rtl::OUString aTitlePropName
=
84 ::rtl::OUString::createFromAscii( "Title" );
87 //============================================================================
89 //============================================================================
91 TYPEINIT1( DlgEdHint
, SfxHint
);
93 //----------------------------------------------------------------------------
95 DlgEdHint::DlgEdHint( DlgEdHintKind eHint
)
100 //----------------------------------------------------------------------------
102 DlgEdHint::DlgEdHint( DlgEdHintKind eHint
, DlgEdObj
* pObj
)
108 //----------------------------------------------------------------------------
110 DlgEdHint::~DlgEdHint()
115 //============================================================================
117 //============================================================================
119 void DlgEditor::ShowDialog()
121 uno::Reference
< lang::XMultiServiceFactory
> xMSF
= getProcessServiceFactory();
124 uno::Reference
< awt::XControl
> xDlg( xMSF
->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialog" ) ) ), uno::UNO_QUERY
);
126 // clone the dialog model
127 uno::Reference
< util::XCloneable
> xC( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
128 uno::Reference
< util::XCloneable
> xNew
= xC
->createClone();
129 uno::Reference
< awt::XControlModel
> xDlgMod( xNew
, uno::UNO_QUERY
);
131 uno::Reference
< beans::XPropertySet
> xSrcDlgModPropSet( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
132 uno::Reference
< beans::XPropertySet
> xNewDlgModPropSet( xDlgMod
, uno::UNO_QUERY
);
133 if( xNewDlgModPropSet
.is() )
135 if( xSrcDlgModPropSet
.is() )
139 Any aResourceResolver
= xSrcDlgModPropSet
->getPropertyValue( aResourceResolverPropName
);
140 xNewDlgModPropSet
->setPropertyValue( aResourceResolverPropName
, aResourceResolver
);
142 catch( UnknownPropertyException
& )
144 DBG_ERROR( "DlgEditor::ShowDialog(): No ResourceResolver property" );
148 // Disable decoration
149 bool bDecoration
= true;
152 Any aDecorationAny
= xSrcDlgModPropSet
->getPropertyValue( aDecorationPropName
);
153 aDecorationAny
>>= bDecoration
;
156 xNewDlgModPropSet
->setPropertyValue( aDecorationPropName
, makeAny( true ) );
157 xNewDlgModPropSet
->setPropertyValue( aTitlePropName
, makeAny( ::rtl::OUString() ) );
160 catch( UnknownPropertyException
& )
165 xDlg
->setModel( xDlgMod
);
168 uno::Reference
< awt::XToolkit
> xToolkit( xMSF
->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.ExtToolkit" ) ) ), uno::UNO_QUERY
);
169 xDlg
->createPeer( xToolkit
, pWindow
->GetComponentInterface() );
171 uno::Reference
< awt::XDialog
> xD( xDlg
, uno::UNO_QUERY
);
174 uno::Reference
< lang::XComponent
> xComponent(xDlg
, uno::UNO_QUERY
);
176 xComponent
->dispose();
179 //----------------------------------------------------------------------------
181 BOOL
DlgEditor::UnmarkDialog()
183 SdrObject
* pDlgObj
= pDlgEdModel
->GetPage(0)->GetObj(0);
184 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
186 BOOL bWasMarked
= pDlgEdView
->IsObjMarked( pDlgObj
);
189 pDlgEdView
->MarkObj( pDlgObj
, pPgView
, TRUE
);
194 //----------------------------------------------------------------------------
196 BOOL
DlgEditor::RemarkDialog()
198 SdrObject
* pDlgObj
= pDlgEdModel
->GetPage(0)->GetObj(0);
199 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
201 BOOL bWasMarked
= pDlgEdView
->IsObjMarked( pDlgObj
);
204 pDlgEdView
->MarkObj( pDlgObj
, pPgView
, FALSE
);
209 //----------------------------------------------------------------------------
211 DlgEditor::DlgEditor( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& xModel
)
218 ,m_xUnoControlDialogModel(NULL
)
219 ,m_ClipboardDataFlavors(1)
220 ,m_ClipboardDataFlavorsResource(2)
224 ,eMode( DLGED_SELECT
)
225 ,eActObj( OBJ_DLG_PUSHBUTTON
)
227 ,aGridSize( 100, 100 ) // 100TH_MM
231 ,bDialogModelChanged(FALSE
)
233 ,m_xDocument( xModel
)
235 pDlgEdModel
= new DlgEdModel();
236 pDlgEdModel
->GetItemPool().FreezeIdRanges();
237 pDlgEdModel
->SetScaleUnit( MAP_100TH_MM
);
239 SdrLayerAdmin
& rAdmin
= pDlgEdModel
->GetLayerAdmin();
240 rAdmin
.NewLayer( rAdmin
.GetControlLayerName() );
241 rAdmin
.NewLayer( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "HiddenLayer" ) ) );
243 pDlgEdPage
= new DlgEdPage( *pDlgEdModel
);
244 pDlgEdModel
->InsertPage( pDlgEdPage
);
246 pObjFac
= new DlgEdFactory();
248 pFunc
= new DlgEdFuncSelect( this );
250 // set clipboard data flavors
251 m_ClipboardDataFlavors
[0].MimeType
= ::rtl::OUString::createFromAscii("application/vnd.sun.xml.dialog");
252 m_ClipboardDataFlavors
[0].HumanPresentableName
= ::rtl::OUString::createFromAscii("Dialog 6.0");
253 m_ClipboardDataFlavors
[0].DataType
= ::getCppuType( (const Sequence
< sal_Int8
>*) 0 );
255 m_ClipboardDataFlavorsResource
[0] = m_ClipboardDataFlavors
[0];
256 m_ClipboardDataFlavorsResource
[1].MimeType
= ::rtl::OUString::createFromAscii("application/vnd.sun.xml.dialogwithresource");
257 m_ClipboardDataFlavorsResource
[1].HumanPresentableName
= ::rtl::OUString::createFromAscii("Dialog 8.0");
258 m_ClipboardDataFlavorsResource
[1].DataType
= ::getCppuType( (const Sequence
< sal_Int8
>*) 0 );
260 aPaintTimer
.SetTimeout( 1 );
261 aPaintTimer
.SetTimeoutHdl( LINK( this, DlgEditor
, PaintTimeout
) );
263 aMarkTimer
.SetTimeout( 100 );
264 aMarkTimer
.SetTimeoutHdl( LINK( this, DlgEditor
, MarkTimeout
) );
267 //----------------------------------------------------------------------------
269 DlgEditor::~DlgEditor()
274 ::comphelper::disposeComponent( m_xControlContainer
);
282 //----------------------------------------------------------------------------
284 Reference
< awt::XControlContainer
> DlgEditor::GetWindowControlContainer()
286 if ( !m_xControlContainer
.is() && pWindow
)
287 m_xControlContainer
= VCLUnoHelper::CreateControlContainer( pWindow
);
288 return m_xControlContainer
;
291 //----------------------------------------------------------------------------
293 void DlgEditor::SetWindow( Window
* pWindow_
)
295 DlgEditor::pWindow
= pWindow_
;
296 pWindow_
->SetMapMode( MapMode( MAP_100TH_MM
) );
297 pDlgEdPage
->SetSize( pWindow_
->PixelToLogic( Size( DLGED_PAGE_WIDTH_MIN
, DLGED_PAGE_HEIGHT_MIN
) ) );
299 pDlgEdView
= new DlgEdView( pDlgEdModel
, pWindow_
, this );
300 pDlgEdView
->ShowSdrPage(pDlgEdView
->GetModel()->GetPage(0));
301 pDlgEdView
->SetLayerVisible( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "HiddenLayer" ) ), FALSE
);
302 pDlgEdView
->SetMoveSnapOnlyTopLeft( TRUE
);
303 pDlgEdView
->SetWorkArea( Rectangle( Point( 0, 0 ), pDlgEdPage
->GetSize() ) );
305 pDlgEdView
->SetGridCoarse( aGridSize
);
306 pDlgEdView
->SetSnapGridWidth(Fraction(aGridSize
.Width(), 1), Fraction(aGridSize
.Height(), 1));
307 pDlgEdView
->SetGridSnap( bGridSnap
);
308 pDlgEdView
->SetGridVisible( bGridVisible
);
309 pDlgEdView
->SetDragStripes( FALSE
);
311 pDlgEdView
->SetDesignMode( TRUE
);
313 ::comphelper::disposeComponent( m_xControlContainer
);
316 //----------------------------------------------------------------------------
318 void DlgEditor::SetScrollBars( ScrollBar
* pHS
, ScrollBar
* pVS
)
326 //----------------------------------------------------------------------------
328 void DlgEditor::InitScrollBars()
330 DBG_ASSERT( pHScroll
, "DlgEditor::InitScrollBars: no horizontal scroll bar!" );
331 DBG_ASSERT( pVScroll
, "DlgEditor::InitScrollBars: no vertical scroll bar!" );
332 if ( !pHScroll
|| !pVScroll
)
335 Size aOutSize
= pWindow
->GetOutputSize();
336 Size aPgSize
= pDlgEdPage
->GetSize();
338 pHScroll
->SetRange( Range( 0, aPgSize
.Width() ));
339 pVScroll
->SetRange( Range( 0, aPgSize
.Height() ));
340 pHScroll
->SetVisibleSize( (ULONG
)aOutSize
.Width() );
341 pVScroll
->SetVisibleSize( (ULONG
)aOutSize
.Height() );
343 pHScroll
->SetLineSize( aOutSize
.Width() / 10 );
344 pVScroll
->SetLineSize( aOutSize
.Height() / 10 );
345 pHScroll
->SetPageSize( aOutSize
.Width() / 2 );
346 pVScroll
->SetPageSize( aOutSize
.Height() / 2 );
348 DoScroll( pHScroll
);
349 DoScroll( pVScroll
);
352 //----------------------------------------------------------------------------
354 void DlgEditor::DoScroll( ScrollBar
* )
356 if( !pHScroll
|| !pVScroll
)
359 MapMode aMap
= pWindow
->GetMapMode();
360 Point aOrg
= aMap
.GetOrigin();
362 Size
aScrollPos( pHScroll
->GetThumbPos(), pVScroll
->GetThumbPos() );
363 aScrollPos
= pWindow
->LogicToPixel( aScrollPos
);
364 aScrollPos
= pWindow
->PixelToLogic( aScrollPos
);
366 long nX
= aScrollPos
.Width() + aOrg
.X();
367 long nY
= aScrollPos
.Height() + aOrg
.Y();
375 // When scrolling, someone was rescuing the Wallpaper and forced the window scroll to
376 // be done without background refresh. I do not know why, but that causes the repaint
377 // problems. Taking that out.
378 // Wallpaper aOldBackground = pWindow->GetBackground();
379 // pWindow->SetBackground();
381 // #i74769# children should be scrolled
382 pWindow
->Scroll( -nX
, -nY
, SCROLL_CHILDREN
); // SCROLL_NOCHILDREN );
383 aMap
.SetOrigin( Point( -aScrollPos
.Width(), -aScrollPos
.Height() ) );
384 pWindow
->SetMapMode( aMap
);
387 // pWindow->SetBackground( aOldBackground );
389 DlgEdHint
aHint( DLGED_HINT_WINDOWSCROLLED
);
393 //----------------------------------------------------------------------------
395 void DlgEditor::UpdateScrollBars()
397 MapMode aMap
= pWindow
->GetMapMode();
398 Point aOrg
= aMap
.GetOrigin();
401 pHScroll
->SetThumbPos( -aOrg
.X() );
404 pVScroll
->SetThumbPos( -aOrg
.Y() );
407 //----------------------------------------------------------------------------
409 void DlgEditor::SetDialog( uno::Reference
< container::XNameContainer
> xUnoControlDialogModel
)
412 m_xUnoControlDialogModel
= xUnoControlDialogModel
;
414 // create dialog form
415 pDlgEdForm
= new DlgEdForm();
416 uno::Reference
< awt::XControlModel
> xDlgMod( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
417 pDlgEdForm
->SetUnoControlModel(xDlgMod
);
418 pDlgEdForm
->SetDlgEditor( this );
419 ((DlgEdPage
*)pDlgEdModel
->GetPage(0))->SetDlgEdForm( pDlgEdForm
);
420 pDlgEdModel
->GetPage(0)->InsertObject( pDlgEdForm
);
422 pDlgEdForm
->SetRectFromProps();
423 pDlgEdForm
->UpdateTabIndices(); // for backward compatibility
424 pDlgEdForm
->StartListening();
427 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc( m_xUnoControlDialogModel
, UNO_QUERY
);
430 // get sequence of control names
431 Sequence
< ::rtl::OUString
> aNames
= xNameAcc
->getElementNames();
432 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
433 sal_Int32 nCtrls
= aNames
.getLength();
435 // create a map of tab indices and control names, sorted by tab index
436 IndexToNameMap aIndexToNameMap
;
437 for ( sal_Int32 i
= 0; i
< nCtrls
; ++i
)
440 ::rtl::OUString
aName( pNames
[i
] );
443 sal_Int16 nTabIndex
= -1;
444 Any aCtrl
= xNameAcc
->getByName( aName
);
445 Reference
< ::com::sun::star::beans::XPropertySet
> xPSet
;
448 xPSet
->getPropertyValue( DLGED_PROP_TABINDEX
) >>= nTabIndex
;
451 aIndexToNameMap
.insert( IndexToNameMap::value_type( nTabIndex
, aName
) );
454 // create controls and insert them into drawing page
455 for ( IndexToNameMap::iterator aIt
= aIndexToNameMap
.begin(); aIt
!= aIndexToNameMap
.end(); ++aIt
)
457 Any aCtrl
= xNameAcc
->getByName( aIt
->second
);
458 Reference
< ::com::sun::star::awt::XControlModel
> xCtrlModel
;
459 aCtrl
>>= xCtrlModel
;
460 DlgEdObj
* pCtrlObj
= new DlgEdObj();
461 pCtrlObj
->SetUnoControlModel( xCtrlModel
);
462 pCtrlObj
->SetDlgEdForm( pDlgEdForm
);
463 pDlgEdForm
->AddChild( pCtrlObj
);
464 pDlgEdModel
->GetPage(0)->InsertObject( pCtrlObj
);
465 pCtrlObj
->SetRectFromProps();
466 pCtrlObj
->UpdateStep();
467 pCtrlObj
->StartListening();
473 pDlgEdModel
->SetChanged( FALSE
);
476 void DlgEditor::ResetDialog( void )
478 DlgEdForm
* pOldDlgEdForm
= pDlgEdForm
;
479 DlgEdPage
* pPage
= (DlgEdPage
*)pDlgEdModel
->GetPage(0);
480 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
481 BOOL bWasMarked
= pDlgEdView
->IsObjMarked( pOldDlgEdForm
);
482 pDlgEdView
->UnmarkAll();
484 pPage
->SetDlgEdForm( NULL
);
485 SetDialog( m_xUnoControlDialogModel
);
487 pDlgEdView
->MarkObj( pDlgEdForm
, pPgView
, FALSE
);
491 //----------------------------------------------------------------------------
493 Reference
< util::XNumberFormatsSupplier
> const & DlgEditor::GetNumberFormatsSupplier()
495 if ( !m_xSupplier
.is() )
497 Reference
< lang::XMultiServiceFactory
> xMSF
= ::comphelper::getProcessServiceFactory();
498 Reference
< util::XNumberFormatsSupplier
> xSupplier( xMSF
->createInstance(
499 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatsSupplier") ) ), UNO_QUERY
);
501 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
502 if ( !m_xSupplier
.is() )
504 m_xSupplier
= xSupplier
;
510 //----------------------------------------------------------------------------
512 void DlgEditor::MouseButtonDown( const MouseEvent
& rMEvt
)
515 pWindow
->GrabFocus();
516 pFunc
->MouseButtonDown( rMEvt
);
519 //----------------------------------------------------------------------------
521 void DlgEditor::MouseButtonUp( const MouseEvent
& rMEvt
)
523 BOOL bRet
= pFunc
->MouseButtonUp( rMEvt
);
525 if( (eMode
== DLGED_INSERT
) )
529 //----------------------------------------------------------------------------
531 void DlgEditor::MouseMove( const MouseEvent
& rMEvt
)
533 pFunc
->MouseMove( rMEvt
);
536 //----------------------------------------------------------------------------
538 BOOL
DlgEditor::KeyInput( const KeyEvent
& rKEvt
)
540 return pFunc
->KeyInput( rKEvt
);
543 //----------------------------------------------------------------------------
545 void DlgEditor::Paint( const Rectangle
& rRect
)
548 PaintTimeout( &aPaintTimer
);
551 //----------------------------------------------------------------------------
553 IMPL_LINK( DlgEditor
, PaintTimeout
, Timer
*, EMPTYARG
)
562 pWindow
->IsVisible() &&
563 (pWindow
->GetOutputSize() != aMacSize
) )
568 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xPSet(pDlgEdForm
->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY
);
572 // get dialog size from properties
573 sal_Int32 nWidth
= 0, nHeight
= 0;
574 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nWidth
;
575 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nHeight
;
577 if ( nWidth
== 0 && nHeight
== 0 )
579 Size aSize
= pWindow
->PixelToLogic( Size( 400, 300 ) );
582 Size
aGridSize_(long(pDlgEdView
->GetSnapGridWidthX()), long(pDlgEdView
->GetSnapGridWidthY()));
583 aSize
.Width() -= aSize
.Width() % aGridSize_
.Width();
584 aSize
.Height() -= aSize
.Height() % aGridSize_
.Height();
587 Size aOutSize
= pWindow
->GetOutputSize();
588 aPos
.X() = (aOutSize
.Width()>>1) - (aSize
.Width()>>1);
589 aPos
.Y() = (aOutSize
.Height()>>1) - (aSize
.Height()>>1);
592 aPos
.X() -= aPos
.X() % aGridSize_
.Width();
593 aPos
.Y() -= aPos
.Y() % aGridSize_
.Height();
595 // don't put in the corner
596 Point aMinPos
= pWindow
->PixelToLogic( Point( 30, 20 ) );
597 if( (aPos
.X() < aMinPos
.X()) || (aPos
.Y() < aMinPos
.Y()) )
600 aPos
.X() -= aPos
.X() % aGridSize_
.Width();
601 aPos
.Y() -= aPos
.Y() % aGridSize_
.Height();
604 // set dialog position and size
605 pDlgEdForm
->SetSnapRect( Rectangle( aPos
, aSize
) );
606 pDlgEdForm
->EndListening(sal_False
);
607 pDlgEdForm
->SetPropsFromRect();
608 pDlgEdForm
->GetDlgEditor()->SetDialogModelChanged(TRUE
);
609 pDlgEdForm
->StartListening();
611 // set position and size of controls
613 if ( pDlgEdPage
&& ( ( nObjCount
= pDlgEdPage
->GetObjCount() ) > 0 ) )
615 for ( ULONG i
= 0 ; i
< nObjCount
; i
++ )
617 SdrObject
* pObj
= pDlgEdPage
->GetObj(i
);
618 DlgEdObj
* pDlgEdObj
= PTR_CAST(DlgEdObj
, pObj
);
619 if ( pDlgEdObj
&& !pDlgEdObj
->ISA(DlgEdForm
) )
620 pDlgEdObj
->SetRectFromProps();
627 // repaint, get PageView and prepare Region
628 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
629 const Region
aPaintRectRegion(aPaintRect
);
633 SdrPaintWindow
* pTargetPaintWindow
= 0;
635 // mark repaint start
638 pTargetPaintWindow
= pPgView
->GetView().BeginDrawLayers(pWindow
, aPaintRectRegion
);
639 OSL_ENSURE(pTargetPaintWindow
, "BeginDrawLayers: Got no SdrPaintWindow (!)");
642 // draw background self using wallpaper
643 // #i79128# ...and use correct OutDev for that
644 if(pTargetPaintWindow
)
646 OutputDevice
& rTargetOutDev
= pTargetPaintWindow
->GetTargetOutputDevice();
647 rTargetOutDev
.DrawWallpaper(aPaintRect
, Wallpaper(Color(COL_WHITE
)));
650 // do paint (unbuffered) and mark repaint end
653 // paint of control layer is done in EndDrawLayers anyway...
654 pPgView
->GetView().EndDrawLayers(*pTargetPaintWindow
, true);
659 DBG_ASSERT(pWindow
,"Window not set");
663 //----------------------------------------------------------------------------
665 IMPL_LINK( DlgEditor
, MarkTimeout
, Timer
*, EMPTYARG
)
667 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
669 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
670 SfxChildWindow
* pChildWin
= pViewFrame
? pViewFrame
->GetChildWindow( SID_SHOW_PROPERTYBROWSER
) : NULL
;
674 ((PropBrw
*)(pChildWin
->GetWindow()))->Update( pIDEShell
);
679 //----------------------------------------------------------------------------
681 void DlgEditor::SetMode( DlgEdMode eNewMode
)
683 if ( eNewMode
!= eMode
)
687 if ( eNewMode
== DLGED_INSERT
)
688 pFunc
= new DlgEdFuncInsert( this );
690 pFunc
= new DlgEdFuncSelect( this );
692 if ( eNewMode
== DLGED_READONLY
)
693 pDlgEdModel
->SetReadOnly( TRUE
);
695 pDlgEdModel
->SetReadOnly( FALSE
);
698 if ( eNewMode
== DLGED_TEST
)
704 //----------------------------------------------------------------------------
706 void DlgEditor::SetInsertObj( USHORT eObj
)
711 pDlgEdView
->SetCurrentObj( eActObj
, DlgInventor
);
714 //----------------------------------------------------------------------------
716 USHORT
DlgEditor::GetInsertObj() const
721 //----------------------------------------------------------------------------
723 void DlgEditor::CreateDefaultObject()
725 // create object by factory
726 SdrObject
* pObj
= SdrObjFactory::MakeNewObject( pDlgEdView
->GetCurrentObjInventor(), pDlgEdView
->GetCurrentObjIdentifier(), pDlgEdPage
);
728 DlgEdObj
* pDlgEdObj
= PTR_CAST( DlgEdObj
, pObj
);
731 // set position and size
732 Size aSize
= pWindow
->PixelToLogic( Size( 96, 24 ) );
733 Point aPoint
= (pDlgEdForm
->GetSnapRect()).Center();
734 aPoint
.X() -= aSize
.Width() / 2;
735 aPoint
.Y() -= aSize
.Height() / 2;
736 pDlgEdObj
->SetSnapRect( Rectangle( aPoint
, aSize
) );
738 // set default property values
739 pDlgEdObj
->SetDefaults();
741 // insert object into drawing page
742 SdrPageView
* pPageView
= pDlgEdView
->GetSdrPageView();
743 pDlgEdView
->InsertObjectAtView( pDlgEdObj
, *pPageView
);
746 pDlgEdObj
->StartListening();
750 //----------------------------------------------------------------------------
752 void DlgEditor::Cut()
758 //----------------------------------------------------------------------------
760 void implCopyStreamToByteSequence( Reference
< XInputStream
> xStream
,
761 Sequence
< sal_Int8
>& bytes
)
763 sal_Int32 nRead
= xStream
->readBytes( bytes
, xStream
->available() );
766 Sequence
< sal_Int8
> readBytes
;
767 nRead
= xStream
->readBytes( readBytes
, 1024 );
771 sal_Int32 nPos
= bytes
.getLength();
772 bytes
.realloc( nPos
+ nRead
);
773 ::rtl_copyMemory( bytes
.getArray() + nPos
, readBytes
.getConstArray(), (sal_uInt32
)nRead
);
777 void DlgEditor::Copy()
779 if( !pDlgEdView
->AreObjectsMarked() )
782 // stop all drawing actions
783 pDlgEdView
->BrkAction();
785 // create an empty clipboard dialog model
786 Reference
< util::XCloneable
> xClone( m_xUnoControlDialogModel
, UNO_QUERY
);
787 Reference
< util::XCloneable
> xNewClone
= xClone
->createClone();
788 Reference
< container::XNameContainer
> xClipDialogModel( xNewClone
, UNO_QUERY
);
790 Reference
< container::XNameAccess
> xNAcc( xClipDialogModel
, UNO_QUERY
);
793 Sequence
< OUString
> aNames
= xNAcc
->getElementNames();
794 const OUString
* pNames
= aNames
.getConstArray();
795 sal_uInt32 nCtrls
= aNames
.getLength();
797 for ( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
799 xClipDialogModel
->removeByName( pNames
[n
] );
803 // insert control models of marked objects into clipboard dialog model
804 ULONG nMark
= pDlgEdView
->GetMarkedObjectList().GetMarkCount();
805 for( ULONG i
= 0; i
< nMark
; i
++ )
807 SdrObject
* pObj
= pDlgEdView
->GetMarkedObjectList().GetMark(i
)->GetMarkedSdrObj();
808 DlgEdObj
* pDlgEdObj
= PTR_CAST(DlgEdObj
, pObj
);
810 if (pDlgEdObj
&& !pDlgEdObj
->ISA(DlgEdForm
) )
812 ::rtl::OUString aName
;
813 Reference
< beans::XPropertySet
> xMarkPSet(pDlgEdObj
->GetUnoControlModel(), uno::UNO_QUERY
);
816 xMarkPSet
->getPropertyValue( DLGED_PROP_NAME
) >>= aName
;
819 Reference
< container::XNameAccess
> xNameAcc(m_xUnoControlDialogModel
, UNO_QUERY
);
820 if ( xNameAcc
.is() && xNameAcc
->hasByName(aName
) )
822 Any aCtrl
= xNameAcc
->getByName( aName
);
824 // clone control model
825 Reference
< util::XCloneable
> xCtrl
;
827 Reference
< util::XCloneable
> xNewCtrl
= xCtrl
->createClone();
829 aNewCtrl
<<= xNewCtrl
;
831 if (xClipDialogModel
.is())
832 xClipDialogModel
->insertByName( aName
, aNewCtrl
);
837 // export clipboard dialog model to xml
838 Reference
< XComponentContext
> xContext
;
839 Reference
< beans::XPropertySet
> xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY
);
840 OSL_ASSERT( xProps
.is() );
841 OSL_VERIFY( xProps
->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext
);
842 Reference
< XInputStreamProvider
> xISP
= ::xmlscript::exportDialogModel( xClipDialogModel
, xContext
, m_xDocument
);
843 Reference
< XInputStream
> xStream( xISP
->createInputStream() );
844 Sequence
< sal_Int8
> DialogModelBytes
;
845 implCopyStreamToByteSequence( xStream
, DialogModelBytes
);
846 xStream
->closeInput();
848 // set clipboard content
849 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= GetWindow()->GetClipboard();
850 if ( xClipboard
.is() )
853 uno::Reference
< beans::XPropertySet
> xDialogModelPropSet( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
854 uno::Reference
< resource::XStringResourcePersistence
> xStringResourcePersistence
;
855 if( xDialogModelPropSet
.is() )
859 Any aResourceResolver
= xDialogModelPropSet
->getPropertyValue( aResourceResolverPropName
);
860 aResourceResolver
>>= xStringResourcePersistence
;
862 catch( UnknownPropertyException
& )
866 DlgEdTransferableImpl
* pTrans
= NULL
;
867 if( xStringResourcePersistence
.is() )
869 // With resource, support old and new format
871 // Export xClipDialogModel another time with ids replaced by current language string
872 uno::Reference
< resource::XStringResourceManager
>
873 xStringResourceManager( xStringResourcePersistence
, uno::UNO_QUERY
);
874 LocalizationMgr::resetResourceForDialog( xClipDialogModel
, xStringResourceManager
);
875 Reference
< XInputStreamProvider
> xISP2
= ::xmlscript::exportDialogModel( xClipDialogModel
, xContext
, m_xDocument
);
876 Reference
< XInputStream
> xStream2( xISP2
->createInputStream() );
877 Sequence
< sal_Int8
> NoResourceDialogModelBytes
;
878 implCopyStreamToByteSequence( xStream2
, NoResourceDialogModelBytes
);
879 xStream2
->closeInput();
881 // Old format contains dialog with replaced ids
882 Sequence
< Any
> aSeqData(2);
883 Any aNoResourceDialogModelBytesAny
;
884 aNoResourceDialogModelBytesAny
<<= NoResourceDialogModelBytes
;
885 aSeqData
[0] = aNoResourceDialogModelBytesAny
;
887 // New format contains dialog and resource
888 Sequence
< sal_Int8
> aResData
= xStringResourcePersistence
->exportBinary();
890 // Create sequence for combined dialog and resource
891 sal_Int32 nDialogDataLen
= DialogModelBytes
.getLength();
892 sal_Int32 nResDataLen
= aResData
.getLength();
894 // Combined data = 4 Bytes 32Bit Offset to begin of resource data, lowest byte first
895 // + nDialogDataLen bytes dialog data + nResDataLen resource data
896 sal_Int32 nTotalLen
= 4 + nDialogDataLen
+ nResDataLen
;
897 sal_Int32 nResOffset
= 4 + nDialogDataLen
;
898 Sequence
< sal_Int8
> aCombinedData( nTotalLen
);
899 sal_Int8
* pCombinedData
= aCombinedData
.getArray();
902 sal_Int32 n
= nResOffset
;
903 for( sal_Int16 i
= 0 ; i
< 4 ; i
++ )
905 pCombinedData
[i
] = sal_Int8( n
& 0xff );
908 ::rtl_copyMemory( pCombinedData
+ 4, DialogModelBytes
.getConstArray(), nDialogDataLen
);
909 ::rtl_copyMemory( pCombinedData
+ nResOffset
, aResData
.getConstArray(), nResDataLen
);
911 Any aCombinedDataAny
;
912 aCombinedDataAny
<<= aCombinedData
;
913 aSeqData
[1] = aCombinedDataAny
;
915 pTrans
= new DlgEdTransferableImpl( m_ClipboardDataFlavorsResource
, aSeqData
);
919 // No resource, support only old format
920 Sequence
< Any
> aSeqData(1);
921 Any aDialogModelBytesAny
;
922 aDialogModelBytesAny
<<= DialogModelBytes
;
923 aSeqData
[0] = aDialogModelBytesAny
;
924 pTrans
= new DlgEdTransferableImpl( m_ClipboardDataFlavors
, aSeqData
);
926 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
927 xClipboard
->setContents( pTrans
, pTrans
);
928 Application::AcquireSolarMutex( nRef
);
932 //----------------------------------------------------------------------------
934 void DlgEditor::Paste()
936 // stop all drawing actions
937 pDlgEdView
->BrkAction();
939 // unmark all objects
940 pDlgEdView
->UnmarkAll();
943 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= GetWindow()->GetClipboard();
944 if ( xClipboard
.is() )
946 // get clipboard content
947 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
948 Reference
< datatransfer::XTransferable
> xTransf
= xClipboard
->getContents();
949 Application::AcquireSolarMutex( nRef
);
952 // Is target dialog (library) localized?
953 uno::Reference
< beans::XPropertySet
> xDialogModelPropSet( m_xUnoControlDialogModel
, uno::UNO_QUERY
);
954 uno::Reference
< resource::XStringResourceManager
> xStringResourceManager
;
955 if( xDialogModelPropSet
.is() )
959 Any aResourceResolver
= xDialogModelPropSet
->getPropertyValue( aResourceResolverPropName
);
960 aResourceResolver
>>= xStringResourceManager
;
962 catch( UnknownPropertyException
& )
965 bool bLocalized
= false;
966 if( xStringResourceManager
.is() )
967 bLocalized
= ( xStringResourceManager
->getLocales().getLength() > 0 );
969 if ( xTransf
->isDataFlavorSupported( m_ClipboardDataFlavors
[0] ) )
971 // create clipboard dialog model from xml
972 Reference
< lang::XMultiServiceFactory
> xMSF
= getProcessServiceFactory();
973 Reference
< container::XNameContainer
> xClipDialogModel( xMSF
->createInstance
974 ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ),
977 bool bSourceIsLocalized
= false;
978 Sequence
< sal_Int8
> DialogModelBytes
;
979 Sequence
< sal_Int8
> aResData
;
980 if( bLocalized
&& xTransf
->isDataFlavorSupported( m_ClipboardDataFlavorsResource
[1] ) )
982 bSourceIsLocalized
= true;
984 Any aCombinedDataAny
= xTransf
->getTransferData( m_ClipboardDataFlavorsResource
[1] );
985 Sequence
< sal_Int8
> aCombinedData
;
986 aCombinedDataAny
>>= aCombinedData
;
987 const sal_Int8
* pCombinedData
= aCombinedData
.getConstArray();
989 sal_Int32 nTotalLen
= aCombinedData
.getLength();
992 sal_Int32 nResOffset
= 0;
993 sal_Int32 nFactor
= 1;
994 for( sal_Int16 i
= 0; i
< 4; i
++ )
996 nResOffset
+= nFactor
* sal_uInt8( pCombinedData
[i
] );
1000 sal_Int32 nResDataLen
= nTotalLen
- nResOffset
;
1001 sal_Int32 nDialogDataLen
= nTotalLen
- nResDataLen
- 4;
1003 DialogModelBytes
.realloc( nDialogDataLen
);
1004 ::rtl_copyMemory( DialogModelBytes
.getArray(), pCombinedData
+ 4, nDialogDataLen
);
1006 aResData
.realloc( nResDataLen
);
1007 ::rtl_copyMemory( aResData
.getArray(), pCombinedData
+ nResOffset
, nResDataLen
);
1011 Any aAny
= xTransf
->getTransferData( m_ClipboardDataFlavors
[0] );
1012 aAny
>>= DialogModelBytes
;
1015 if ( xClipDialogModel
.is() )
1017 Reference
< XComponentContext
> xContext
;
1018 Reference
< beans::XPropertySet
> xProps( xMSF
, UNO_QUERY
);
1019 OSL_ASSERT( xProps
.is() );
1020 OSL_VERIFY( xProps
->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext
);
1021 ::xmlscript::importDialogModel( ::xmlscript::createInputStream( *((::rtl::ByteSequence
*)(&DialogModelBytes
)) ) , xClipDialogModel
, xContext
, m_xDocument
);
1024 // get control models from clipboard dialog model
1025 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc( xClipDialogModel
, UNO_QUERY
);
1026 if ( xNameAcc
.is() )
1028 Sequence
< OUString
> aNames
= xNameAcc
->getElementNames();
1029 const OUString
* pNames
= aNames
.getConstArray();
1030 sal_uInt32 nCtrls
= aNames
.getLength();
1032 Reference
< resource::XStringResourcePersistence
> xStringResourcePersistence
;
1033 if( nCtrls
> 0 && bSourceIsLocalized
)
1035 Reference
< lang::XMultiServiceFactory
> xSMgr
= getProcessServiceFactory();
1036 xStringResourcePersistence
= Reference
< resource::XStringResourcePersistence
>( xSMgr
->createInstance
1037 ( ::rtl::OUString::createFromAscii( "com.sun.star.resource.StringResource" ) ), UNO_QUERY
);
1038 if( xStringResourcePersistence
.is() )
1039 xStringResourcePersistence
->importBinary( aResData
);
1041 for( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
1043 Any aA
= xNameAcc
->getByName( pNames
[n
] );
1044 Reference
< ::com::sun::star::awt::XControlModel
> xCM
;
1047 // clone the control model
1048 Reference
< util::XCloneable
> xClone( xCM
, uno::UNO_QUERY
);
1049 Reference
< awt::XControlModel
> xCtrlModel( xClone
->createClone(), uno::UNO_QUERY
);
1051 DlgEdObj
* pCtrlObj
= new DlgEdObj();
1052 pCtrlObj
->SetDlgEdForm(pDlgEdForm
); // set parent form
1053 pDlgEdForm
->AddChild(pCtrlObj
); // add child to parent form
1054 pCtrlObj
->SetUnoControlModel( xCtrlModel
); // set control model
1057 ::rtl::OUString
aOUniqueName( pCtrlObj
->GetUniqueName() );
1058 Reference
< beans::XPropertySet
> xPSet( xCtrlModel
, UNO_QUERY
);
1060 aUniqueName
<<= aOUniqueName
;
1061 xPSet
->setPropertyValue( DLGED_PROP_NAME
, aUniqueName
);
1064 Reference
< container::XNameAccess
> xNA( m_xUnoControlDialogModel
, UNO_QUERY
);
1065 Sequence
< OUString
> aNames_
= xNA
->getElementNames();
1067 aTabIndex
<<= (sal_Int16
) aNames_
.getLength();
1068 xPSet
->setPropertyValue( DLGED_PROP_TABINDEX
, aTabIndex
);
1073 aControlAny
<<= xCtrlModel
;
1074 if( bSourceIsLocalized
&& xStringResourcePersistence
.is() )
1076 Reference
< resource::XStringResourceResolver
>
1077 xSourceStringResolver( xStringResourcePersistence
, UNO_QUERY
);
1078 LocalizationMgr::copyResourcesForPastedEditorObject( this,
1079 aControlAny
, aOUniqueName
, xSourceStringResolver
);
1083 LocalizationMgr::setControlResourceIDsForNewEditorObject
1084 ( this, aControlAny
, aOUniqueName
);
1088 // insert control model in editor dialog model
1090 aCtrlModel
<<= xCtrlModel
;
1091 m_xUnoControlDialogModel
->insertByName( aOUniqueName
, aCtrlModel
);
1093 // insert object into drawing page
1094 pDlgEdModel
->GetPage(0)->InsertObject( pCtrlObj
);
1095 pCtrlObj
->SetRectFromProps();
1096 pCtrlObj
->UpdateStep();
1097 pDlgEdForm
->UpdateTabOrderAndGroups(); // #110559#
1098 pCtrlObj
->StartListening(); // start listening
1101 SdrPageView
* pPgView
= pDlgEdView
->GetSdrPageView();
1102 pDlgEdView
->MarkObj( pCtrlObj
, pPgView
, FALSE
, TRUE
);
1105 // center marked objects in dialog editor form
1106 Point aMarkCenter
= (pDlgEdView
->GetMarkedObjRect()).Center();
1107 Point aFormCenter
= (pDlgEdForm
->GetSnapRect()).Center();
1108 Point aPoint
= aFormCenter
- aMarkCenter
;
1109 Size
aSize( aPoint
.X() , aPoint
.Y() );
1110 pDlgEdView
->MoveMarkedObj( aSize
); // update of control model properties (position + size) in NbcMove
1111 pDlgEdView
->MarkListHasChanged();
1113 // dialog model changed
1114 SetDialogModelChanged(TRUE
);
1121 //----------------------------------------------------------------------------
1123 void DlgEditor::Delete()
1125 if( !pDlgEdView
->AreObjectsMarked() )
1128 // remove control models of marked objects from dialog model
1129 ULONG nMark
= pDlgEdView
->GetMarkedObjectList().GetMarkCount();
1131 for( ULONG i
= 0; i
< nMark
; i
++ )
1133 SdrObject
* pObj
= pDlgEdView
->GetMarkedObjectList().GetMark(i
)->GetMarkedSdrObj();
1134 DlgEdObj
* pDlgEdObj
= PTR_CAST(DlgEdObj
, pObj
);
1136 if ( pDlgEdObj
&& !pDlgEdObj
->ISA(DlgEdForm
) )
1138 // get name from property
1139 ::rtl::OUString aName
;
1140 uno::Reference
< beans::XPropertySet
> xPSet(pDlgEdObj
->GetUnoControlModel(), uno::UNO_QUERY
);
1143 xPSet
->getPropertyValue( DLGED_PROP_NAME
) >>= aName
;
1146 // remove control from dialog model
1147 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc(pDlgEdObj
->GetDlgEdForm()->GetUnoControlModel(), UNO_QUERY
);
1148 if ( xNameAcc
.is() && xNameAcc
->hasByName(aName
) )
1150 Reference
< ::com::sun::star::container::XNameContainer
> xCont(xNameAcc
, UNO_QUERY
);
1153 if( xCont
->hasByName( aName
) )
1155 Any aAny
= xCont
->getByName( aName
);
1156 LocalizationMgr::deleteControlResourceIDsForDeletedEditorObject( this, aAny
, aName
);
1158 xCont
->removeByName( aName
);
1162 // remove child from parent form
1163 pDlgEdForm
->RemoveChild( pDlgEdObj
);
1167 // update tab indices
1168 pDlgEdForm
->UpdateTabIndices();
1170 pDlgEdView
->BrkAction();
1172 BOOL bDlgMarked
= UnmarkDialog();
1173 pDlgEdView
->DeleteMarked();
1178 //----------------------------------------------------------------------------
1180 BOOL
DlgEditor::IsPasteAllowed()
1182 BOOL bPaste
= FALSE
;
1185 Reference
< datatransfer::clipboard::XClipboard
> xClipboard
= GetWindow()->GetClipboard();
1186 if ( xClipboard
.is() )
1188 // get clipboard content
1189 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
1190 Reference
< datatransfer::XTransferable
> xTransf
= xClipboard
->getContents();
1191 Application::AcquireSolarMutex( nRef
);
1194 if ( xTransf
->isDataFlavorSupported( m_ClipboardDataFlavors
[0] ) )
1204 //----------------------------------------------------------------------------
1206 void DlgEditor::ShowProperties()
1208 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
1209 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
1210 if ( pViewFrame
&& !pViewFrame
->HasChildWindow( SID_SHOW_PROPERTYBROWSER
) )
1211 pViewFrame
->ToggleChildWindow( SID_SHOW_PROPERTYBROWSER
);
1214 //----------------------------------------------------------------------------
1216 void DlgEditor::UpdatePropertyBrowserDelayed()
1221 //----------------------------------------------------------------------------
1223 BOOL
DlgEditor::IsModified() const
1225 return pDlgEdModel
->IsChanged() || bDialogModelChanged
;
1228 //----------------------------------------------------------------------------
1230 void DlgEditor::ClearModifyFlag()
1232 pDlgEdModel
->SetChanged( FALSE
);
1233 bDialogModelChanged
= FALSE
;
1236 //----------------------------------------------------------------------------
1238 #define LMARGPRN 1700
1239 #define RMARGPRN 900
1240 #define TMARGPRN 2000
1241 #define BMARGPRN 1000
1242 #define BORDERPRN 300
1244 //----------------------------------------------------------------------------
1246 void lcl_PrintHeader( Printer
* pPrinter
, const String
& rTitle
) // not working yet
1250 short nLeftMargin
= LMARGPRN
;
1251 Size aSz
= pPrinter
->GetOutputSize();
1252 short nBorder
= BORDERPRN
;
1254 pPrinter
->SetLineColor( COL_BLACK
);
1255 pPrinter
->SetFillColor();
1257 Font
aFont( pPrinter
->GetFont() );
1258 aFont
.SetWeight( WEIGHT_BOLD
);
1259 aFont
.SetAlign( ALIGN_BOTTOM
);
1260 pPrinter
->SetFont( aFont
);
1262 long nFontHeight
= pPrinter
->GetTextHeight();
1264 // 1.Border => Strich, 2+3 Border = Freiraum.
1265 long nYTop
= TMARGPRN
-3*nBorder
-nFontHeight
;
1267 long nXLeft
= nLeftMargin
-nBorder
;
1268 long nXRight
= aSz
.Width()-RMARGPRN
+nBorder
;
1270 pPrinter
->DrawRect( Rectangle(
1271 Point( nXLeft
, nYTop
),
1272 Size( nXRight
-nXLeft
, aSz
.Height() - nYTop
- BMARGPRN
+ nBorder
) ) );
1274 long nY
= TMARGPRN
-2*nBorder
;
1275 Point
aPos( nLeftMargin
, nY
);
1276 pPrinter
->DrawText( aPos
, rTitle
);
1278 nY
= TMARGPRN
-nBorder
;
1280 pPrinter
->DrawLine( Point( nXLeft
, nY
), Point( nXRight
, nY
) );
1285 //----------------------------------------------------------------------------
1287 void DlgEditor::PrintData( Printer
* pPrinter
, const String
& rTitle
) // not working yet
1291 MapMode
aOldMap( pPrinter
->GetMapMode());
1292 Font
aOldFont( pPrinter
->GetFont() );
1294 MapMode
aMap( MAP_100TH_MM
);
1295 pPrinter
->SetMapMode( aMap
);
1298 //aFont.SetName( System::GetStandardFont( STDFONT_SWISS ).GetName() );
1300 aFont
.SetAlign( ALIGN_BOTTOM
);
1301 aFont
.SetSize( Size( 0, 360 ));
1302 pPrinter
->SetFont( aFont
);
1304 Size aPaperSz
= pPrinter
->GetOutputSize();
1305 aPaperSz
.Width() -= (LMARGPRN
+RMARGPRN
);
1306 aPaperSz
.Height() -= (TMARGPRN
+BMARGPRN
);
1308 pPrinter
->StartPage();
1310 lcl_PrintHeader( pPrinter
, rTitle
);
1314 Bitmap
* pDlg
= new Bitmap
;
1315 //pSbxForm->SnapShot( *pDlg );
1316 SvMemoryStream
* pStrm
= new SvMemoryStream
;
1323 //pSbxForm->SnapShot( aDlg );
1325 Size
aBmpSz( pPrinter
->PixelToLogic( aDlg
.GetSizePixel() ) );
1326 double nPaperSzWidth
= aPaperSz
.Width();
1327 double nPaperSzHeight
= aPaperSz
.Height();
1328 double nBmpSzWidth
= aBmpSz
.Width();
1329 double nBmpSzHeight
= aBmpSz
.Height();
1330 double nScaleX
= (nPaperSzWidth
/ nBmpSzWidth
);
1331 double nScaleY
= (nPaperSzHeight
/ nBmpSzHeight
);
1334 if( nBmpSzHeight
* nScaleX
<= nPaperSzHeight
)
1336 aOutputSz
.Width() = (long)(((double)nBmpSzWidth
) * nScaleX
);
1337 aOutputSz
.Height() = (long)(((double)nBmpSzHeight
) * nScaleX
);
1341 aOutputSz
.Width() = (long)(((double)nBmpSzWidth
) * nScaleY
);
1342 aOutputSz
.Height() = (long)(((double)nBmpSzHeight
) * nScaleY
);
1346 (aPaperSz
.Width() / 2) - (aOutputSz
.Width() / 2),
1347 (aPaperSz
.Height()/ 2) - (aOutputSz
.Height() / 2));
1349 aPosOffs
.X() += LMARGPRN
;
1350 aPosOffs
.Y() += TMARGPRN
;
1352 pPrinter
->DrawBitmap( aPosOffs
, aOutputSz
, aDlg
);
1354 pPrinter
->EndPage();
1356 pPrinter
->SetMapMode( aOldMap
);
1357 pPrinter
->SetFont( aOldFont
);
1361 //----------------------------------------------------------------------------
1363 bool DlgEditor::AdjustPageSize()
1365 bool bAdjustedPageSize
= false;
1366 Reference
< beans::XPropertySet
> xPSet( m_xUnoControlDialogModel
, UNO_QUERY
);
1369 sal_Int32 nFormXIn
= 0, nFormYIn
= 0, nFormWidthIn
= 0, nFormHeightIn
= 0;
1370 xPSet
->getPropertyValue( DLGED_PROP_POSITIONX
) >>= nFormXIn
;
1371 xPSet
->getPropertyValue( DLGED_PROP_POSITIONY
) >>= nFormYIn
;
1372 xPSet
->getPropertyValue( DLGED_PROP_WIDTH
) >>= nFormWidthIn
;
1373 xPSet
->getPropertyValue( DLGED_PROP_HEIGHT
) >>= nFormHeightIn
;
1375 sal_Int32 nFormX
, nFormY
, nFormWidth
, nFormHeight
;
1376 if ( pDlgEdForm
&& pDlgEdForm
->TransformFormToSdrCoordinates( nFormXIn
, nFormYIn
, nFormWidthIn
, nFormHeightIn
, nFormX
, nFormY
, nFormWidth
, nFormHeight
) )
1378 Size
aPageSizeDelta( 400, 300 );
1379 DBG_ASSERT( pWindow
, "DlgEditor::AdjustPageSize: no window!" );
1381 aPageSizeDelta
= pWindow
->PixelToLogic( aPageSizeDelta
, MapMode( MAP_100TH_MM
) );
1383 sal_Int32 nNewPageWidth
= nFormX
+ nFormWidth
+ aPageSizeDelta
.Width();
1384 sal_Int32 nNewPageHeight
= nFormY
+ nFormHeight
+ aPageSizeDelta
.Height();
1386 Size
aPageSizeMin( DLGED_PAGE_WIDTH_MIN
, DLGED_PAGE_HEIGHT_MIN
);
1387 DBG_ASSERT( pWindow
, "DlgEditor::AdjustPageSize: no window!" );
1389 aPageSizeMin
= pWindow
->PixelToLogic( aPageSizeMin
, MapMode( MAP_100TH_MM
) );
1390 sal_Int32 nPageWidthMin
= aPageSizeMin
.Width();
1391 sal_Int32 nPageHeightMin
= aPageSizeMin
.Height();
1393 if ( nNewPageWidth
< nPageWidthMin
)
1394 nNewPageWidth
= nPageWidthMin
;
1396 if ( nNewPageHeight
< nPageHeightMin
)
1397 nNewPageHeight
= nPageHeightMin
;
1401 Size aPageSize
= pDlgEdPage
->GetSize();
1402 if ( nNewPageWidth
!= aPageSize
.Width() || nNewPageHeight
!= aPageSize
.Height() )
1404 Size
aNewPageSize( nNewPageWidth
, nNewPageHeight
);
1405 pDlgEdPage
->SetSize( aNewPageSize
);
1406 DBG_ASSERT( pDlgEdView
, "DlgEditor::AdjustPageSize: no view!" );
1408 pDlgEdView
->SetWorkArea( Rectangle( Point( 0, 0 ), aNewPageSize
) );
1409 bAdjustedPageSize
= true;
1415 return bAdjustedPageSize
;
1418 //----------------------------------------------------------------------------