nss: upgrade to release 3.73
[LibreOffice.git] / basctl / source / dlged / dlged.cxx
blob533e2381f3e7f2752d6d5c98cb29a07f04cc1fae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <dlged.hxx>
22 #include <dlgedclip.hxx>
23 #include <dlgeddef.hxx>
24 #include <dlgedfac.hxx>
25 #include <dlgedfunc.hxx>
26 #include <dlgedmod.hxx>
27 #include <dlgedobj.hxx>
28 #include <dlgedpage.hxx>
29 #include <dlgedview.hxx>
30 #include <localizationmgr.hxx>
31 #include <baside3.hxx>
33 #include <com/sun/star/awt/Toolkit.hpp>
34 #include <com/sun/star/awt/UnoControlDialog.hpp>
35 #include <com/sun/star/resource/StringResource.hpp>
36 #include <com/sun/star/util/XCloneable.hpp>
37 #include <com/sun/star/util/NumberFormatsSupplier.hpp>
38 #include <comphelper/types.hxx>
39 #include <comphelper/processfactory.hxx>
40 #include <tools/debug.hxx>
41 #include <svl/itempool.hxx>
42 #include <svx/sdrpaintwindow.hxx>
43 #include <svx/svdpagv.hxx>
44 #include <toolkit/helper/vclunohelper.hxx>
45 #include <vcl/print.hxx>
46 #include <vcl/scrbar.hxx>
47 #include <vcl/svapp.hxx>
48 #include <xmlscript/xml_helper.hxx>
49 #include <xmlscript/xmldlg_imexp.hxx>
51 namespace basctl
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 const char aResourceResolverPropName[] = "ResourceResolver";
61 const char aDecorationPropName[] = "Decoration";
64 // DlgEdHint
67 DlgEdHint::DlgEdHint(Kind eHint)
68 : eKind(eHint)
69 , pDlgEdObj(nullptr)
73 DlgEdHint::DlgEdHint(Kind eHint, DlgEdObj* pObj)
74 : eKind(eHint)
75 , pDlgEdObj(pObj)
79 DlgEdHint::~DlgEdHint()
84 // DlgEditor
87 void DlgEditor::ShowDialog()
89 uno::Reference< uno::XComponentContext > xContext = getProcessComponentContext();
91 // create a dialog
92 uno::Reference< awt::XUnoControlDialog > xDlg = awt::UnoControlDialog::create( xContext );
94 // clone the dialog model
95 uno::Reference< util::XCloneable > xC( m_xUnoControlDialogModel, uno::UNO_QUERY );
96 uno::Reference< util::XCloneable > xNew = xC->createClone();
97 uno::Reference< awt::XControlModel > xDlgMod( xNew, uno::UNO_QUERY );
99 uno::Reference< beans::XPropertySet > xSrcDlgModPropSet( m_xUnoControlDialogModel, uno::UNO_QUERY );
100 uno::Reference< beans::XPropertySet > xNewDlgModPropSet( xDlgMod, uno::UNO_QUERY );
101 if( xNewDlgModPropSet.is() )
103 if( xSrcDlgModPropSet.is() )
107 Any aResourceResolver = xSrcDlgModPropSet->getPropertyValue( aResourceResolverPropName );
108 xNewDlgModPropSet->setPropertyValue( aResourceResolverPropName, aResourceResolver );
110 catch(const UnknownPropertyException& )
112 OSL_FAIL( "DlgEditor::ShowDialog(): No ResourceResolver property" );
116 // Disable decoration
119 bool bDecoration = true;
121 Any aDecorationAny = xSrcDlgModPropSet->getPropertyValue( aDecorationPropName );
122 aDecorationAny >>= bDecoration;
123 if( !bDecoration )
125 xNewDlgModPropSet->setPropertyValue( aDecorationPropName, Any( true ) );
126 xNewDlgModPropSet->setPropertyValue( "Title", Any( OUString() ) );
129 catch(const UnknownPropertyException& )
133 // set the model
134 xDlg->setModel( xDlgMod );
136 // create a peer
137 uno::Reference< awt::XToolkit> xToolkit = awt::Toolkit::create( xContext );
138 xDlg->createPeer( xToolkit, rWindow.GetComponentInterface() );
140 xDlg->execute();
142 // need to cast because of multiple inheritance
143 Reference<awt::XControl>(xDlg)->dispose();
147 bool DlgEditor::UnmarkDialog()
149 SdrObject* pDlgObj = pDlgEdModel->GetPage(0)->GetObj(0);
150 SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
152 bool bWasMarked = pDlgEdView->IsObjMarked( pDlgObj );
154 if( bWasMarked )
155 pDlgEdView->MarkObj( pDlgObj, pPgView, true );
157 return bWasMarked;
161 bool DlgEditor::RemarkDialog()
163 SdrObject* pDlgObj = pDlgEdModel->GetPage(0)->GetObj(0);
164 SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
166 bool bWasMarked = pDlgEdView->IsObjMarked( pDlgObj );
168 if( !bWasMarked )
169 pDlgEdView->MarkObj( pDlgObj, pPgView );
171 return bWasMarked;
175 DlgEditor::DlgEditor (
176 vcl::Window& rWindow_, DialogWindowLayout& rLayout_,
177 css::uno::Reference<css::frame::XModel> const& xModel,
178 css::uno::Reference<css::container::XNameContainer> const & xDialogModel
180 :pHScroll(nullptr)
181 ,pVScroll(nullptr)
182 ,pDlgEdModel(new DlgEdModel())
183 ,pDlgEdPage(new DlgEdPage(*pDlgEdModel))
184 ,m_ClipboardDataFlavors(1)
185 ,m_ClipboardDataFlavorsResource(2)
186 ,pObjFac(new DlgEdFactory(xModel))
187 ,rWindow(rWindow_)
188 ,pFunc(new DlgEdFuncSelect(*this))
189 ,rLayout(rLayout_)
190 ,eMode( DlgEditor::SELECT )
191 ,eActObj( OBJ_DLG_PUSHBUTTON )
192 ,bFirstDraw(false)
193 ,bCreateOK(true)
194 ,bDialogModelChanged(false)
195 ,aMarkIdle("basctl DlgEditor Mark")
196 ,mnPaintGuard(0)
197 ,m_xDocument( xModel )
199 pDlgEdModel->GetItemPool().FreezeIdRanges();
200 pDlgEdView.reset(new DlgEdView(*pDlgEdModel, rWindow_, *this));
201 pDlgEdModel->SetScaleUnit( MapUnit::Map100thMM );
203 SdrLayerAdmin& rAdmin = pDlgEdModel->GetLayerAdmin();
204 rAdmin.NewLayer( rAdmin.GetControlLayerName() );
205 rAdmin.NewLayer( "HiddenLayer" );
207 pDlgEdModel->InsertPage(pDlgEdPage);
209 // set clipboard data flavors
210 m_ClipboardDataFlavors[0].MimeType = "application/vnd.sun.xml.dialog" ;
211 m_ClipboardDataFlavors[0].HumanPresentableName = "Dialog 6.0" ;
212 m_ClipboardDataFlavors[0].DataType = cppu::UnoType<Sequence< sal_Int8 >>::get();
214 m_ClipboardDataFlavorsResource[0] = m_ClipboardDataFlavors[0];
215 m_ClipboardDataFlavorsResource[1].MimeType = "application/vnd.sun.xml.dialogwithresource" ;
216 m_ClipboardDataFlavorsResource[1].HumanPresentableName = "Dialog 8.0" ;
217 m_ClipboardDataFlavorsResource[1].DataType = cppu::UnoType<Sequence< sal_Int8 >>::get();
219 aMarkIdle.SetInvokeHandler( LINK( this, DlgEditor, MarkTimeout ) );
221 rWindow.SetMapMode( MapMode( MapUnit::Map100thMM ) );
222 pDlgEdPage->SetSize( rWindow.PixelToLogic( Size(DLGED_PAGE_WIDTH_MIN, DLGED_PAGE_HEIGHT_MIN) ) );
224 pDlgEdView->ShowSdrPage(pDlgEdView->GetModel()->GetPage(0));
225 pDlgEdView->SetLayerVisible( "HiddenLayer", false );
226 pDlgEdView->SetMoveSnapOnlyTopLeft(true);
227 pDlgEdView->SetWorkArea( tools::Rectangle( Point( 0, 0 ), pDlgEdPage->GetSize() ) );
229 Size aGridSize( 100, 100 ); // 100TH_MM
230 pDlgEdView->SetGridCoarse( aGridSize );
231 pDlgEdView->SetSnapGridWidth(Fraction(aGridSize.Width(), 1), Fraction(aGridSize.Height(), 1));
232 pDlgEdView->SetGridSnap( true );
233 pDlgEdView->SetGridVisible( false );
234 pDlgEdView->SetDragStripes(false);
236 pDlgEdView->SetDesignMode();
238 ::comphelper::disposeComponent( m_xControlContainer );
240 SetDialog(xDialogModel);
244 DlgEditor::~DlgEditor()
246 aMarkIdle.Stop();
248 ::comphelper::disposeComponent( m_xControlContainer );
252 Reference< awt::XControlContainer > const & DlgEditor::GetWindowControlContainer()
254 if (!m_xControlContainer.is())
255 m_xControlContainer = VCLUnoHelper::CreateControlContainer(&rWindow);
256 return m_xControlContainer;
260 void DlgEditor::SetScrollBars( ScrollBar* pHS, ScrollBar* pVS )
262 pHScroll = pHS;
263 pVScroll = pVS;
265 InitScrollBars();
269 void DlgEditor::InitScrollBars()
271 DBG_ASSERT( pHScroll, "DlgEditor::InitScrollBars: no horizontal scroll bar!" );
272 DBG_ASSERT( pVScroll, "DlgEditor::InitScrollBars: no vertical scroll bar!" );
273 if ( !pHScroll || !pVScroll )
274 return;
276 Size aOutSize = rWindow.GetOutputSize();
277 Size aPgSize = pDlgEdPage->GetSize();
279 pHScroll->SetRange( Range( 0, aPgSize.Width() ));
280 pVScroll->SetRange( Range( 0, aPgSize.Height() ));
281 pHScroll->SetVisibleSize( static_cast<sal_uLong>(aOutSize.Width()) );
282 pVScroll->SetVisibleSize( static_cast<sal_uLong>(aOutSize.Height()) );
284 pHScroll->SetLineSize( aOutSize.Width() / 10 );
285 pVScroll->SetLineSize( aOutSize.Height() / 10 );
286 pHScroll->SetPageSize( aOutSize.Width() / 2 );
287 pVScroll->SetPageSize( aOutSize.Height() / 2 );
289 DoScroll();
293 void DlgEditor::DoScroll()
295 if( !pHScroll || !pVScroll )
296 return;
298 MapMode aMap = rWindow.GetMapMode();
299 Point aOrg = aMap.GetOrigin();
301 Size aScrollPos( pHScroll->GetThumbPos(), pVScroll->GetThumbPos() );
302 aScrollPos = rWindow.LogicToPixel( aScrollPos );
303 aScrollPos = rWindow.PixelToLogic( aScrollPos );
305 tools::Long nX = aScrollPos.Width() + aOrg.X();
306 tools::Long nY = aScrollPos.Height() + aOrg.Y();
308 if( !nX && !nY )
309 return;
311 rWindow.PaintImmediately();
313 // #i31562#
314 // When scrolling, someone was rescuing the Wallpaper and forced the window scroll to
315 // be done without background refresh. I do not know why, but that causes the repaint
316 // problems. Taking that out.
317 // Wallpaper aOldBackground = rWindow.GetBackground();
318 // rWindow.SetBackground();
320 // #i74769# children should be scrolled
321 rWindow.Scroll( -nX, -nY, ScrollFlags::Children);
322 aMap.SetOrigin( Point( -aScrollPos.Width(), -aScrollPos.Height() ) );
323 rWindow.SetMapMode( aMap );
324 rWindow.PaintImmediately();
326 DlgEdHint aHint( DlgEdHint::WINDOWSCROLLED );
327 Broadcast( aHint );
331 void DlgEditor::UpdateScrollBars()
333 MapMode aMap = rWindow.GetMapMode();
334 Point aOrg = aMap.GetOrigin();
336 if ( pHScroll )
337 pHScroll->SetThumbPos( -aOrg.X() );
339 if ( pVScroll )
340 pVScroll->SetThumbPos( -aOrg.Y() );
344 void DlgEditor::SetDialog( const uno::Reference< container::XNameContainer >& xUnoControlDialogModel )
346 // set dialog model
347 m_xUnoControlDialogModel = xUnoControlDialogModel;
349 // create dialog form
350 pDlgEdForm = new DlgEdForm(*pDlgEdModel, *this);
351 uno::Reference< awt::XControlModel > xDlgMod( m_xUnoControlDialogModel , uno::UNO_QUERY );
352 pDlgEdForm->SetUnoControlModel(xDlgMod);
353 static_cast<DlgEdPage*>(pDlgEdModel->GetPage(0))->SetDlgEdForm( pDlgEdForm );
354 pDlgEdModel->GetPage(0)->InsertObject( pDlgEdForm );
355 AdjustPageSize();
356 pDlgEdForm->SetRectFromProps();
357 pDlgEdForm->UpdateTabIndices(); // for backward compatibility
358 pDlgEdForm->StartListening();
360 // create controls
361 if ( m_xUnoControlDialogModel.is() )
363 // get sequence of control names
364 Sequence< OUString > aNames = m_xUnoControlDialogModel->getElementNames();
365 const OUString* pNames = aNames.getConstArray();
366 sal_Int32 nCtrls = aNames.getLength();
368 // create a map of tab indices and control names, sorted by tab index
369 IndexToNameMap aIndexToNameMap;
370 for ( sal_Int32 i = 0; i < nCtrls; ++i )
372 // get name
373 OUString aName( pNames[i] );
375 // get tab index
376 sal_Int16 nTabIndex = -1;
377 Any aCtrl = m_xUnoControlDialogModel->getByName( aName );
378 Reference< css::beans::XPropertySet > xPSet;
379 aCtrl >>= xPSet;
380 if ( xPSet.is() )
381 xPSet->getPropertyValue( DLGED_PROP_TABINDEX ) >>= nTabIndex;
383 // insert into map
384 aIndexToNameMap.emplace( nTabIndex, aName );
387 // create controls and insert them into drawing page
388 for (auto const& indexToName : aIndexToNameMap)
390 Any aCtrl = m_xUnoControlDialogModel->getByName( indexToName.second );
391 Reference< css::awt::XControlModel > xCtrlModel;
392 aCtrl >>= xCtrlModel;
393 DlgEdObj* pCtrlObj = new DlgEdObj(*pDlgEdModel);
394 pCtrlObj->SetUnoControlModel( xCtrlModel );
395 pCtrlObj->SetDlgEdForm( pDlgEdForm );
396 pDlgEdForm->AddChild( pCtrlObj );
397 pDlgEdModel->GetPage(0)->InsertObject( pCtrlObj );
398 pCtrlObj->SetRectFromProps();
399 pCtrlObj->UpdateStep();
400 pCtrlObj->StartListening();
404 bFirstDraw = true;
406 pDlgEdModel->SetChanged(false);
409 void DlgEditor::ResetDialog ()
411 DlgEdForm* pOldDlgEdForm = pDlgEdForm;
412 DlgEdPage* pPage = static_cast<DlgEdPage*>(pDlgEdModel->GetPage(0));
413 SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
414 bool bWasMarked = pDlgEdView->IsObjMarked( pOldDlgEdForm );
415 pDlgEdView->UnmarkAll();
417 // clear SdrObjects with broadcasting
418 pPage->ClearSdrObjList();
420 pPage->SetDlgEdForm( nullptr );
421 SetDialog( m_xUnoControlDialogModel );
422 if( bWasMarked )
423 pDlgEdView->MarkObj( pDlgEdForm, pPgView );
427 Reference< util::XNumberFormatsSupplier > const & DlgEditor::GetNumberFormatsSupplier()
429 if ( !m_xSupplier.is() )
431 Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
432 Reference< util::XNumberFormatsSupplier > xSupplier( util::NumberFormatsSupplier::createWithDefaultLocale(xContext) );
434 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
435 if ( !m_xSupplier.is() )
437 m_xSupplier = xSupplier;
440 return m_xSupplier;
444 void DlgEditor::MouseButtonDown( const MouseEvent& rMEvt )
446 rWindow.GrabFocus();
447 pFunc->MouseButtonDown( rMEvt );
451 void DlgEditor::MouseButtonUp( const MouseEvent& rMEvt )
453 bool bRet = pFunc->MouseButtonUp( rMEvt );
455 if( eMode == DlgEditor::INSERT )
456 bCreateOK = bRet;
460 void DlgEditor::MouseMove( const MouseEvent& rMEvt )
462 pFunc->MouseMove( rMEvt );
466 bool DlgEditor::KeyInput( const KeyEvent& rKEvt )
468 return pFunc->KeyInput( rKEvt );
472 void DlgEditor::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
474 aPaintRect = rRect;
475 mnPaintGuard++;
477 if (bFirstDraw && rWindow.IsVisible() && (rRenderContext.GetOutputSize() != Size()))
479 bFirstDraw = false;
481 // get property set
482 css::uno::Reference<css::beans::XPropertySet> xPSet(pDlgEdForm->GetUnoControlModel(), css::uno::UNO_QUERY);
484 if (xPSet.is())
486 // get dialog size from properties
487 sal_Int32 nWidth = 0, nHeight = 0;
488 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nWidth;
489 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nHeight;
491 if (nWidth == 0 && nHeight == 0)
493 Size aSize = rRenderContext.PixelToLogic( Size( 400, 300 ) );
495 // align with grid
496 Size aGridSize_(tools::Long(pDlgEdView->GetSnapGridWidthX()), tools::Long(pDlgEdView->GetSnapGridWidthY()));
497 aSize.AdjustWidth( -(aSize.Width() % aGridSize_.Width()) );
498 aSize.AdjustHeight( -(aSize.Height() % aGridSize_.Height()) );
500 Point aPos;
501 Size aOutSize = rRenderContext.GetOutputSize();
502 aPos.setX( (aOutSize.Width()>>1) - (aSize.Width()>>1) );
503 aPos.setY( (aOutSize.Height()>>1) - (aSize.Height()>>1) );
505 // align with grid
506 aPos.AdjustX( -(aPos.X() % aGridSize_.Width()) );
507 aPos.AdjustY( -(aPos.Y() % aGridSize_.Height()) );
509 // don't put in the corner
510 Point aMinPos = rRenderContext.PixelToLogic( Point( 30, 20 ) );
511 if( (aPos.X() < aMinPos.X()) || (aPos.Y() < aMinPos.Y()) )
513 aPos = aMinPos;
514 aPos.AdjustX( -(aPos.X() % aGridSize_.Width()) );
515 aPos.AdjustY( -(aPos.Y() % aGridSize_.Height()) );
518 // set dialog position and size
519 pDlgEdForm->SetSnapRect( tools::Rectangle( aPos, aSize ) );
520 pDlgEdForm->EndListening(false);
521 pDlgEdForm->SetPropsFromRect();
522 pDlgEdForm->GetDlgEditor().SetDialogModelChanged();
523 pDlgEdForm->StartListening();
525 // set position and size of controls
526 if (const size_t nObjCount = pDlgEdPage->GetObjCount())
528 for (size_t i = 0 ; i < nObjCount ; ++i)
530 if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pDlgEdPage->GetObj(i)))
532 if (!dynamic_cast<DlgEdForm*>(pDlgEdObj))
534 pDlgEdObj->SetRectFromProps();
543 // repaint, get PageView and prepare Region
544 SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
545 const vcl::Region aPaintRectRegion(aPaintRect);
547 // #i74769#
548 SdrPaintWindow* pTargetPaintWindow = nullptr;
550 // mark repaint start
551 if (pPgView)
553 pTargetPaintWindow = pPgView->GetView().BeginDrawLayers(&rRenderContext, aPaintRectRegion);
554 OSL_ENSURE(pTargetPaintWindow, "BeginDrawLayers: Got no SdrPaintWindow (!)");
557 // draw background self using wallpaper
558 // #i79128# ...and use correct OutDev for that
559 if (pTargetPaintWindow)
561 OutputDevice& rTargetOutDev = pTargetPaintWindow->GetTargetOutputDevice();
562 rTargetOutDev.DrawWallpaper(aPaintRect, Wallpaper(COL_WHITE));
565 // do paint (unbuffered) and mark repaint end
566 if (pPgView)
568 // paint of control layer is done in EndDrawLayers anyway...
569 pPgView->GetView().EndDrawLayers(*pTargetPaintWindow, true);
572 mnPaintGuard--;
576 IMPL_LINK_NOARG(DlgEditor, MarkTimeout, Timer *, void)
578 rLayout.UpdatePropertyBrowser();
582 void DlgEditor::SetMode (Mode eNewMode )
584 if ( eNewMode != eMode )
586 if ( eNewMode == INSERT )
587 pFunc.reset(new DlgEdFuncInsert(*this));
588 else
589 pFunc.reset(new DlgEdFuncSelect(*this));
591 if ( eNewMode == READONLY )
592 pDlgEdModel->SetReadOnly( true );
593 else
594 pDlgEdModel->SetReadOnly( false );
597 if ( eNewMode == TEST )
598 ShowDialog();
600 eMode = eNewMode;
604 void DlgEditor::SetInsertObj(SdrObjKind eObj)
606 eActObj = eObj;
608 pDlgEdView->SetCurrentObj( eActObj, SdrInventor::BasicDialog );
611 void DlgEditor::CreateDefaultObject()
613 // create object by factory
614 SdrObject* pObj = SdrObjFactory::MakeNewObject(
615 *pDlgEdModel,
616 pDlgEdView->GetCurrentObjInventor(),
617 pDlgEdView->GetCurrentObjIdentifier());
619 DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pObj);
620 if (!pDlgEdObj)
621 return;
623 // set position and size
624 Size aSize = rWindow.PixelToLogic( Size( 96, 24 ) );
625 Point aPoint = pDlgEdForm->GetSnapRect().Center();
626 aPoint.AdjustX( -(aSize.Width() / 2) );
627 aPoint.AdjustY( -(aSize.Height() / 2) );
628 pDlgEdObj->SetSnapRect( tools::Rectangle( aPoint, aSize ) );
630 // set default property values
631 pDlgEdObj->SetDefaults();
633 // insert object into drawing page
634 SdrPageView* pPageView = pDlgEdView->GetSdrPageView();
635 if (pDlgEdView->InsertObjectAtView(pDlgEdObj, *pPageView))
637 // start listening
638 pDlgEdObj->StartListening();
642 void DlgEditor::Cut()
644 Copy();
645 Delete();
648 static void implCopyStreamToByteSequence( const Reference< XInputStream >& xStream,
649 Sequence< sal_Int8 >& bytes )
651 xStream->readBytes( bytes, xStream->available() );
652 for (;;)
654 Sequence< sal_Int8 > readBytes;
655 sal_Int32 nRead = xStream->readBytes( readBytes, 1024 );
656 if (! nRead)
657 break;
659 sal_Int32 nPos = bytes.getLength();
660 bytes.realloc( nPos + nRead );
661 memcpy( bytes.getArray() + nPos, readBytes.getConstArray(), static_cast<sal_uInt32>(nRead) );
665 void DlgEditor::Copy()
667 if( !pDlgEdView->AreObjectsMarked() )
668 return;
670 // stop all drawing actions
671 pDlgEdView->BrkAction();
673 // create an empty clipboard dialog model
674 Reference< util::XCloneable > xClone( m_xUnoControlDialogModel, UNO_QUERY );
675 Reference< util::XCloneable > xNewClone = xClone->createClone();
676 Reference< container::XNameContainer > xClipDialogModel( xNewClone, UNO_QUERY );
678 if ( xClipDialogModel.is() )
680 Sequence< OUString > aNames = xClipDialogModel->getElementNames();
681 const OUString* pNames = aNames.getConstArray();
682 sal_uInt32 nCtrls = aNames.getLength();
684 for ( sal_uInt32 n = 0; n < nCtrls; n++ )
686 xClipDialogModel->removeByName( pNames[n] );
690 // insert control models of marked objects into clipboard dialog model
691 const size_t nMark = pDlgEdView->GetMarkedObjectList().GetMarkCount();
692 for( size_t i = 0; i < nMark; ++i )
694 SdrObject* pObj = pDlgEdView->GetMarkedObjectList().GetMark(i)->GetMarkedSdrObj();
695 DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pObj);
697 if (pDlgEdObj && !dynamic_cast<DlgEdForm*>(pDlgEdObj))
699 OUString aName;
700 Reference< beans::XPropertySet > xMarkPSet(pDlgEdObj->GetUnoControlModel(), uno::UNO_QUERY);
701 if (xMarkPSet.is())
703 xMarkPSet->getPropertyValue( DLGED_PROP_NAME ) >>= aName;
706 if ( m_xUnoControlDialogModel.is() && m_xUnoControlDialogModel->hasByName(aName) )
708 Any aCtrl = m_xUnoControlDialogModel->getByName( aName );
710 // clone control model
711 Reference< util::XCloneable > xCtrl;
712 aCtrl >>= xCtrl;
713 Reference< util::XCloneable > xNewCtrl = xCtrl->createClone();
714 Any aNewCtrl;
715 aNewCtrl <<= xNewCtrl;
717 if (xClipDialogModel.is())
718 xClipDialogModel->insertByName( aName , aNewCtrl );
723 // export clipboard dialog model to xml
724 Reference< XComponentContext > xContext(
725 comphelper::getProcessComponentContext() );
726 Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xClipDialogModel, xContext, m_xDocument );
727 Reference< XInputStream > xStream( xISP->createInputStream() );
728 Sequence< sal_Int8 > DialogModelBytes;
729 implCopyStreamToByteSequence( xStream, DialogModelBytes );
730 xStream->closeInput();
732 // set clipboard content
733 Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow().GetClipboard();
734 if ( !xClipboard.is() )
735 return;
737 // With resource?
738 uno::Reference< beans::XPropertySet > xDialogModelPropSet( m_xUnoControlDialogModel, uno::UNO_QUERY );
739 uno::Reference< resource::XStringResourcePersistence > xStringResourcePersistence;
740 if( xDialogModelPropSet.is() )
744 Any aResourceResolver = xDialogModelPropSet->getPropertyValue( aResourceResolverPropName );
745 aResourceResolver >>= xStringResourcePersistence;
747 catch(const UnknownPropertyException& )
751 DlgEdTransferableImpl* pTrans = nullptr;
752 if( xStringResourcePersistence.is() )
754 // With resource, support old and new format
756 // Export xClipDialogModel another time with ids replaced by current language string
757 LocalizationMgr::resetResourceForDialog( xClipDialogModel, xStringResourcePersistence );
758 Reference< XInputStreamProvider > xISP2 = ::xmlscript::exportDialogModel( xClipDialogModel, xContext, m_xDocument );
759 Reference< XInputStream > xStream2( xISP2->createInputStream() );
760 Sequence< sal_Int8 > NoResourceDialogModelBytes;
761 implCopyStreamToByteSequence( xStream2, NoResourceDialogModelBytes );
762 xStream2->closeInput();
764 // Old format contains dialog with replaced ids
765 Sequence< Any > aSeqData(2);
766 Any aNoResourceDialogModelBytesAny;
767 aNoResourceDialogModelBytesAny <<= NoResourceDialogModelBytes;
768 aSeqData[0] = aNoResourceDialogModelBytesAny;
770 // New format contains dialog and resource
771 Sequence< sal_Int8 > aResData = xStringResourcePersistence->exportBinary();
773 // Create sequence for combined dialog and resource
774 sal_Int32 nDialogDataLen = DialogModelBytes.getLength();
775 sal_Int32 nResDataLen = aResData.getLength();
777 // Combined data = 4 Bytes 32Bit Offset to begin of resource data, lowest byte first
778 // + nDialogDataLen bytes dialog data + nResDataLen resource data
779 sal_Int32 nTotalLen = 4 + nDialogDataLen + nResDataLen;
780 sal_Int32 nResOffset = 4 + nDialogDataLen;
781 Sequence< sal_Int8 > aCombinedData( nTotalLen );
782 sal_Int8* pCombinedData = aCombinedData.getArray();
784 // Write offset
785 sal_Int32 n = nResOffset;
786 for( sal_Int16 i = 0 ; i < 4 ; i++ )
788 pCombinedData[i] = sal_Int8( n & 0xff );
789 n >>= 8;
791 memcpy( pCombinedData + 4, DialogModelBytes.getConstArray(), nDialogDataLen );
792 memcpy( pCombinedData + nResOffset, aResData.getConstArray(), nResDataLen );
794 aSeqData[1] <<= aCombinedData;
796 pTrans = new DlgEdTransferableImpl( m_ClipboardDataFlavorsResource, aSeqData );
798 else
800 // No resource, support only old format
801 Sequence< Any > aSeqData(1);
802 Any aDialogModelBytesAny;
803 aDialogModelBytesAny <<= DialogModelBytes;
804 aSeqData[0] = aDialogModelBytesAny;
805 pTrans = new DlgEdTransferableImpl( m_ClipboardDataFlavors , aSeqData );
807 SolarMutexReleaser aReleaser;
808 xClipboard->setContents( pTrans , pTrans );
812 void DlgEditor::Paste()
814 // stop all drawing actions
815 pDlgEdView->BrkAction();
817 // unmark all objects
818 pDlgEdView->UnmarkAll();
820 // get clipboard
821 Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow().GetClipboard();
822 if ( !xClipboard.is() )
823 return;
825 Reference< datatransfer::XTransferable > xTransf;
827 SolarMutexReleaser aReleaser;
828 // get clipboard content
829 xTransf = xClipboard->getContents();
831 if ( !xTransf.is() )
832 return;
834 // Is target dialog (library) localized?
835 uno::Reference< beans::XPropertySet > xDialogModelPropSet( m_xUnoControlDialogModel, uno::UNO_QUERY );
836 uno::Reference< resource::XStringResourceManager > xStringResourceManager;
837 if( xDialogModelPropSet.is() )
841 Any aResourceResolver = xDialogModelPropSet->getPropertyValue( aResourceResolverPropName );
842 aResourceResolver >>= xStringResourceManager;
844 catch(const UnknownPropertyException& )
847 bool bLocalized = false;
848 if( xStringResourceManager.is() )
849 bLocalized = xStringResourceManager->getLocales().hasElements();
851 if ( !xTransf->isDataFlavorSupported( m_ClipboardDataFlavors[0] ) )
852 return;
854 // create clipboard dialog model from xml
855 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
856 Reference< container::XNameContainer > xClipDialogModel( xContext->getServiceManager()->createInstanceWithContext(
857 "com.sun.star.awt.UnoControlDialogModel", xContext ), uno::UNO_QUERY );
859 bool bSourceIsLocalized = false;
860 Sequence< sal_Int8 > DialogModelBytes;
861 Sequence< sal_Int8 > aResData;
862 if( bLocalized && xTransf->isDataFlavorSupported( m_ClipboardDataFlavorsResource[1] ) )
864 bSourceIsLocalized = true;
866 Any aCombinedDataAny = xTransf->getTransferData( m_ClipboardDataFlavorsResource[1] );
867 Sequence< sal_Int8 > aCombinedData;
868 aCombinedDataAny >>= aCombinedData;
869 const sal_Int8* pCombinedData = aCombinedData.getConstArray();
871 sal_Int32 nTotalLen = aCombinedData.getLength();
873 // Reading offset
874 sal_Int32 nResOffset = 0;
875 sal_Int32 nFactor = 1;
876 for( sal_Int16 i = 0; i < 4; i++ )
878 nResOffset += nFactor * sal_uInt8( pCombinedData[i] );
879 nFactor *= 256;
882 sal_Int32 nResDataLen = nTotalLen - nResOffset;
883 sal_Int32 nDialogDataLen = nTotalLen - nResDataLen - 4;
885 DialogModelBytes.realloc( nDialogDataLen );
886 memcpy( DialogModelBytes.getArray(), pCombinedData + 4, nDialogDataLen );
888 aResData.realloc( nResDataLen );
889 memcpy( aResData.getArray(), pCombinedData + nResOffset, nResDataLen );
891 else
893 Any aAny = xTransf->getTransferData( m_ClipboardDataFlavors[0] );
894 aAny >>= DialogModelBytes;
897 if ( xClipDialogModel.is() )
899 Reference<XInputStream> xIn = ::xmlscript::createInputStream( DialogModelBytes.getConstArray(), DialogModelBytes.getLength() );
900 ::xmlscript::importDialogModel( xIn , xClipDialogModel, xContext, m_xDocument );
903 // get control models from clipboard dialog model
904 if ( !xClipDialogModel.is() )
905 return;
907 Sequence< OUString > aNames = xClipDialogModel->getElementNames();
908 const OUString* pNames = aNames.getConstArray();
909 sal_uInt32 nCtrls = aNames.getLength();
911 Reference< resource::XStringResourcePersistence > xStringResourcePersistence;
912 if( nCtrls > 0 && bSourceIsLocalized )
914 xStringResourcePersistence = css::resource::StringResource::create( getProcessComponentContext() );
915 xStringResourcePersistence->importBinary( aResData );
917 for( sal_uInt32 n = 0; n < nCtrls; n++ )
919 Any aA = xClipDialogModel->getByName( pNames[n] );
920 Reference< css::awt::XControlModel > xCM;
921 aA >>= xCM;
923 // clone the control model
924 Reference< util::XCloneable > xClone( xCM, uno::UNO_QUERY );
925 Reference< awt::XControlModel > xCtrlModel( xClone->createClone(), uno::UNO_QUERY );
927 DlgEdObj* pCtrlObj = new DlgEdObj(*pDlgEdModel);
928 pCtrlObj->SetDlgEdForm(pDlgEdForm); // set parent form
929 pDlgEdForm->AddChild(pCtrlObj); // add child to parent form
930 pCtrlObj->SetUnoControlModel( xCtrlModel ); // set control model
932 // set new name
933 OUString aOUniqueName( pCtrlObj->GetUniqueName() );
934 Reference< beans::XPropertySet > xPSet( xCtrlModel , UNO_QUERY );
935 xPSet->setPropertyValue( DLGED_PROP_NAME, Any(aOUniqueName) );
937 // set tabindex
938 Sequence< OUString > aNames_ = m_xUnoControlDialogModel->getElementNames();
939 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, Any(static_cast<sal_Int16>(aNames_.getLength())) );
941 if( bLocalized )
943 Any aControlAny;
944 aControlAny <<= xCtrlModel;
945 if( bSourceIsLocalized && xStringResourcePersistence.is() )
947 LocalizationMgr::copyResourcesForPastedEditorObject( this,
948 aControlAny, aOUniqueName, xStringResourcePersistence );
950 else
952 LocalizationMgr::setControlResourceIDsForNewEditorObject
953 ( this, aControlAny, aOUniqueName );
957 // insert control model in editor dialog model
958 Any aCtrlModel;
959 aCtrlModel <<= xCtrlModel;
960 m_xUnoControlDialogModel->insertByName( aOUniqueName , aCtrlModel );
962 // insert object into drawing page
963 pDlgEdModel->GetPage(0)->InsertObject( pCtrlObj );
964 pCtrlObj->SetRectFromProps();
965 pCtrlObj->UpdateStep();
966 pDlgEdForm->UpdateTabOrderAndGroups();
967 pCtrlObj->StartListening(); // start listening
969 // mark object
970 SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
971 pDlgEdView->MarkObj( pCtrlObj, pPgView, false, true);
974 // center marked objects in dialog editor form
975 Point aMarkCenter = pDlgEdView->GetMarkedObjRect().Center();
976 Point aFormCenter = pDlgEdForm->GetSnapRect().Center();
977 Point aPoint = aFormCenter - aMarkCenter;
978 Size aSize( aPoint.X() , aPoint.Y() );
979 pDlgEdView->MoveMarkedObj( aSize ); // update of control model properties (position + size) in NbcMove
980 pDlgEdView->MarkListHasChanged();
982 // dialog model changed
983 SetDialogModelChanged();
987 void DlgEditor::Delete()
989 if( !pDlgEdView->AreObjectsMarked() )
990 return;
992 // remove control models of marked objects from dialog model
993 const size_t nMark = pDlgEdView->GetMarkedObjectList().GetMarkCount();
995 for( size_t i = 0; i < nMark; ++i )
997 SdrObject* pObj = pDlgEdView->GetMarkedObjectList().GetMark(i)->GetMarkedSdrObj();
998 DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pObj);
1000 if ( pDlgEdObj && !dynamic_cast<DlgEdForm*>(pDlgEdObj) )
1002 // get name from property
1003 OUString aName;
1004 uno::Reference< beans::XPropertySet > xPSet(pDlgEdObj->GetUnoControlModel(), uno::UNO_QUERY);
1005 if (xPSet.is())
1007 xPSet->getPropertyValue( DLGED_PROP_NAME ) >>= aName;
1010 // remove control from dialog model
1011 Reference< css::container::XNameAccess > xNameAcc(pDlgEdObj->GetDlgEdForm()->GetUnoControlModel(), UNO_QUERY );
1012 if ( xNameAcc.is() && xNameAcc->hasByName(aName) )
1014 Reference< css::container::XNameContainer > xCont(xNameAcc, UNO_QUERY );
1015 if ( xCont.is() )
1017 if( xCont->hasByName( aName ) )
1019 Any aAny = xCont->getByName( aName );
1020 LocalizationMgr::deleteControlResourceIDsForDeletedEditorObject( this, aAny, aName );
1022 xCont->removeByName( aName );
1026 // remove child from parent form
1027 pDlgEdForm->RemoveChild( pDlgEdObj );
1031 // update tab indices
1032 pDlgEdForm->UpdateTabIndices();
1034 pDlgEdView->BrkAction();
1036 bool const bDlgMarked = UnmarkDialog();
1037 pDlgEdView->DeleteMarked();
1038 if( bDlgMarked )
1039 RemarkDialog();
1043 bool DlgEditor::IsPasteAllowed()
1045 // get clipboard
1046 Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow().GetClipboard();
1047 if ( xClipboard.is() )
1049 Reference< datatransfer::XTransferable > xTransf;
1051 SolarMutexReleaser aReleaser;
1052 // get clipboard content
1053 xTransf = xClipboard->getContents();
1055 if (xTransf.is())
1056 return xTransf->isDataFlavorSupported(m_ClipboardDataFlavors[0]);
1058 return false;
1062 void DlgEditor::ShowProperties()
1064 rLayout.ShowPropertyBrowser();
1068 void DlgEditor::UpdatePropertyBrowserDelayed()
1070 aMarkIdle.Start();
1074 bool DlgEditor::IsModified() const
1076 return pDlgEdModel->IsChanged() || bDialogModelChanged;
1080 void DlgEditor::ClearModifyFlag()
1082 pDlgEdModel->SetChanged(false);
1083 bDialogModelChanged = false;
1087 namespace Print
1089 tools::Long const nLeftMargin = 1700;
1090 tools::Long const nRightMargin = 900;
1091 tools::Long const nTopMargin = 2000;
1092 tools::Long const nBottomMargin = 1000;
1093 tools::Long const nBorder = 300;
1096 static void lcl_PrintHeader( Printer* pPrinter, const OUString& rTitle ) // not working yet
1099 pPrinter->Push();
1101 Size const aSz = pPrinter->GetOutputSize();
1103 pPrinter->SetLineColor( COL_BLACK );
1104 pPrinter->SetFillColor();
1106 vcl::Font aFont( pPrinter->GetFont() );
1107 aFont.SetWeight( WEIGHT_BOLD );
1108 aFont.SetAlignment( ALIGN_BOTTOM );
1109 pPrinter->SetFont( aFont );
1111 tools::Long const nFontHeight = pPrinter->GetTextHeight();
1113 // 1st border => line, 2+3 border = free space
1114 tools::Long const nYTop = Print::nTopMargin - 3*Print::nBorder - nFontHeight;
1116 tools::Long const nXLeft = Print::nLeftMargin - Print::nBorder;
1117 tools::Long const nXRight = aSz.Width() - Print::nRightMargin + Print::nBorder;
1119 pPrinter->DrawRect(tools::Rectangle(
1120 Point(nXLeft, nYTop),
1121 Size(nXRight - nXLeft, aSz.Height() - nYTop - Print::nBottomMargin + Print::nBorder)
1124 tools::Long nY = Print::nTopMargin - 2*Print::nBorder;
1125 Point aPos(Print::nLeftMargin, nY);
1126 pPrinter->DrawText( aPos, rTitle );
1128 nY = Print::nTopMargin - Print::nBorder;
1129 pPrinter->DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
1131 pPrinter->Pop();
1135 void DlgEditor::printPage( sal_Int32 nPage, Printer* pPrinter, const OUString& rTitle )
1137 if( nPage == 0 )
1138 Print( pPrinter, rTitle );
1142 void DlgEditor::Print( Printer* pPrinter, const OUString& rTitle ) // not working yet
1144 MapMode aOldMap( pPrinter->GetMapMode());
1145 vcl::Font aOldFont( pPrinter->GetFont() );
1147 MapMode aMap( MapUnit::Map100thMM );
1148 pPrinter->SetMapMode( aMap );
1149 vcl::Font aFont;
1150 aFont.SetAlignment( ALIGN_BOTTOM );
1151 aFont.SetFontSize( Size( 0, 360 ));
1152 pPrinter->SetFont( aFont );
1154 Size aPaperSz = pPrinter->GetOutputSize();
1155 aPaperSz.AdjustWidth( -(Print::nLeftMargin + Print::nRightMargin) );
1156 aPaperSz.AdjustHeight( -(Print::nTopMargin + Print::nBottomMargin) );
1158 lcl_PrintHeader( pPrinter, rTitle );
1160 BitmapEx aDlgEx;
1161 Size aBmpSz( pPrinter->PixelToLogic( aDlgEx.GetSizePixel() ) );
1162 double nPaperSzWidth = aPaperSz.Width();
1163 double nPaperSzHeight = aPaperSz.Height();
1164 double nBmpSzWidth = aBmpSz.Width();
1165 double nBmpSzHeight = aBmpSz.Height();
1166 double nScaleX = nPaperSzWidth / nBmpSzWidth;
1167 double nScaleY = nPaperSzHeight / nBmpSzHeight;
1169 Size aOutputSz;
1170 if( nBmpSzHeight * nScaleX <= nPaperSzHeight )
1172 aOutputSz.setWidth( static_cast<tools::Long>(nBmpSzWidth * nScaleX) );
1173 aOutputSz.setHeight( static_cast<tools::Long>(nBmpSzHeight * nScaleX) );
1175 else
1177 aOutputSz.setWidth( static_cast<tools::Long>(nBmpSzWidth * nScaleY) );
1178 aOutputSz.setHeight( static_cast<tools::Long>(nBmpSzHeight * nScaleY) );
1181 Point aPosOffs(
1182 (aPaperSz.Width() / 2) - (aOutputSz.Width() / 2),
1183 (aPaperSz.Height()/ 2) - (aOutputSz.Height() / 2));
1185 aPosOffs.AdjustX(Print::nLeftMargin );
1186 aPosOffs.AdjustY(Print::nTopMargin );
1188 pPrinter->DrawBitmapEx( aPosOffs, aOutputSz, aDlgEx );
1190 pPrinter->SetMapMode( aOldMap );
1191 pPrinter->SetFont( aOldFont );
1195 bool DlgEditor::AdjustPageSize()
1197 bool bAdjustedPageSize = false;
1198 Reference< beans::XPropertySet > xPSet( m_xUnoControlDialogModel, UNO_QUERY );
1199 if ( xPSet.is() )
1201 sal_Int32 nFormXIn = 0, nFormYIn = 0, nFormWidthIn = 0, nFormHeightIn = 0;
1202 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nFormXIn;
1203 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nFormYIn;
1204 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nFormWidthIn;
1205 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nFormHeightIn;
1207 sal_Int32 nFormX, nFormY, nFormWidth, nFormHeight;
1208 if ( pDlgEdForm && pDlgEdForm->TransformFormToSdrCoordinates( nFormXIn, nFormYIn, nFormWidthIn, nFormHeightIn, nFormX, nFormY, nFormWidth, nFormHeight ) )
1210 Size aPageSizeDelta( 400, 300 );
1211 aPageSizeDelta = rWindow.PixelToLogic( aPageSizeDelta, MapMode( MapUnit::Map100thMM ) );
1213 sal_Int32 nNewPageWidth = nFormX + nFormWidth + aPageSizeDelta.Width();
1214 sal_Int32 nNewPageHeight = nFormY + nFormHeight + aPageSizeDelta.Height();
1216 Size aPageSizeMin( DLGED_PAGE_WIDTH_MIN, DLGED_PAGE_HEIGHT_MIN );
1217 aPageSizeMin = rWindow.PixelToLogic( aPageSizeMin, MapMode( MapUnit::Map100thMM ) );
1218 sal_Int32 nPageWidthMin = aPageSizeMin.Width();
1219 sal_Int32 nPageHeightMin = aPageSizeMin.Height();
1221 if ( nNewPageWidth < nPageWidthMin )
1222 nNewPageWidth = nPageWidthMin;
1224 if ( nNewPageHeight < nPageHeightMin )
1225 nNewPageHeight = nPageHeightMin;
1227 if ( pDlgEdPage )
1229 Size aPageSize = pDlgEdPage->GetSize();
1230 if ( nNewPageWidth != aPageSize.Width() || nNewPageHeight != aPageSize.Height() )
1232 Size aNewPageSize( nNewPageWidth, nNewPageHeight );
1233 pDlgEdPage->SetSize( aNewPageSize );
1234 pDlgEdView->SetWorkArea( tools::Rectangle( Point( 0, 0 ), aNewPageSize ) );
1235 bAdjustedPageSize = true;
1241 return bAdjustedPageSize;
1245 } // namespace basctl
1247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */