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