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