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