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 88 DlgEdHint::DlgEdHint( DlgEdHintKind eHint ) 89 :eHintKind( eHint ) 90 { 91 } 92 93 //---------------------------------------------------------------------------- 94 95 DlgEdHint::DlgEdHint( DlgEdHintKind eHint, DlgEdObj* pObj ) 96 :eHintKind( eHint ) 97 ,pDlgEdObj( pObj ) 98 { 99 } 100 101 //---------------------------------------------------------------------------- 102 103 DlgEdHint::~DlgEdHint() 104 { 105 } 106 107 108 //============================================================================ 109 // DlgEditor 110 //============================================================================ 111 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 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 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 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 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 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 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 310 void DlgEditor::SetScrollBars( ScrollBar* pHS, ScrollBar* pVS ) 311 { 312 pHScroll = pHS; 313 pVScroll = pVS; 314 315 InitScrollBars(); 316 } 317 318 //---------------------------------------------------------------------------- 319 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 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 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 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 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 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 504 void DlgEditor::MouseButtonDown( const MouseEvent& rMEvt ) 505 { 506 if( pWindow ) 507 pWindow->GrabFocus(); 508 pFunc->MouseButtonDown( rMEvt ); 509 } 510 511 //---------------------------------------------------------------------------- 512 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 523 void DlgEditor::MouseMove( const MouseEvent& rMEvt ) 524 { 525 pFunc->MouseMove( rMEvt ); 526 } 527 528 //---------------------------------------------------------------------------- 529 530 sal_Bool DlgEditor::KeyInput( const KeyEvent& rKEvt ) 531 { 532 return pFunc->KeyInput( rKEvt ); 533 } 534 535 //---------------------------------------------------------------------------- 536 537 void DlgEditor::Paint( const Rectangle& rRect ) 538 { 539 aPaintRect = rRect; 540 PaintTimeout( &aPaintTimer ); 541 } 542 543 //---------------------------------------------------------------------------- 544 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 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 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 698 void DlgEditor::SetInsertObj( sal_uInt16 eObj ) 699 { 700 eActObj = eObj; 701 702 if( pDlgEdView ) 703 pDlgEdView->SetCurrentObj( eActObj, DlgInventor ); 704 } 705 706 //---------------------------------------------------------------------------- 707 708 sal_uInt16 DlgEditor::GetInsertObj() const 709 { 710 return eActObj; 711 } 712 713 //---------------------------------------------------------------------------- 714 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 744 void DlgEditor::Cut() 745 { 746 Copy(); 747 Delete(); 748 } 749 750 //---------------------------------------------------------------------------- 751 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 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 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 Sequence< sal_Int8 > 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 aAny >>= DialogModelBytes; 1005 } 1006 1007 if ( xClipDialogModel.is() ) 1008 { 1009 Reference< XComponentContext > xContext; 1010 Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY ); 1011 OSL_ASSERT( xProps.is() ); 1012 OSL_VERIFY( xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext ); 1013 ::xmlscript::importDialogModel( ::xmlscript::createInputStream( *((::rtl::ByteSequence*)(&DialogModelBytes)) ) , xClipDialogModel, xContext ); 1014 } 1015 1016 // get control models from clipboard dialog model 1017 Reference< ::com::sun::star::container::XNameAccess > xNameAcc( xClipDialogModel, UNO_QUERY ); 1018 if ( xNameAcc.is() ) 1019 { 1020 Sequence< OUString > aNames = xNameAcc->getElementNames(); 1021 const OUString* pNames = aNames.getConstArray(); 1022 sal_uInt32 nCtrls = aNames.getLength(); 1023 1024 Reference< resource::XStringResourcePersistence > xStringResourcePersistence; 1025 if( nCtrls > 0 && bSourceIsLocalized ) 1026 { 1027 Reference< lang::XMultiServiceFactory > xSMgr = getProcessServiceFactory(); 1028 xStringResourcePersistence = Reference< resource::XStringResourcePersistence >( xSMgr->createInstance 1029 ( ::rtl::OUString::createFromAscii( "com.sun.star.resource.StringResource" ) ), UNO_QUERY ); 1030 if( xStringResourcePersistence.is() ) 1031 xStringResourcePersistence->importBinary( aResData ); 1032 } 1033 for( sal_uInt32 n = 0; n < nCtrls; n++ ) 1034 { 1035 Any aA = xNameAcc->getByName( pNames[n] ); 1036 Reference< ::com::sun::star::awt::XControlModel > xCM; 1037 aA >>= xCM; 1038 1039 // clone the control model 1040 Reference< util::XCloneable > xClone( xCM, uno::UNO_QUERY ); 1041 Reference< awt::XControlModel > xCtrlModel( xClone->createClone(), uno::UNO_QUERY ); 1042 1043 DlgEdObj* pCtrlObj = new DlgEdObj(); 1044 pCtrlObj->SetDlgEdForm(pDlgEdForm); // set parent form 1045 pDlgEdForm->AddChild(pCtrlObj); // add child to parent form 1046 pCtrlObj->SetUnoControlModel( xCtrlModel ); // set control model 1047 1048 // set new name 1049 ::rtl::OUString aOUniqueName( pCtrlObj->GetUniqueName() ); 1050 Reference< beans::XPropertySet > xPSet( xCtrlModel , UNO_QUERY ); 1051 Any aUniqueName; 1052 aUniqueName <<= aOUniqueName; 1053 xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName ); 1054 1055 // set tabindex 1056 Reference< container::XNameAccess > xNA( m_xUnoControlDialogModel , UNO_QUERY ); 1057 Sequence< OUString > aNames_ = xNA->getElementNames(); 1058 Any aTabIndex; 1059 aTabIndex <<= (sal_Int16) aNames_.getLength(); 1060 xPSet->setPropertyValue( DLGED_PROP_TABINDEX, aTabIndex ); 1061 1062 if( bLocalized ) 1063 { 1064 Any aControlAny; 1065 aControlAny <<= xCtrlModel; 1066 if( bSourceIsLocalized && xStringResourcePersistence.is() ) 1067 { 1068 Reference< resource::XStringResourceResolver > 1069 xSourceStringResolver( xStringResourcePersistence, UNO_QUERY ); 1070 LocalizationMgr::copyResourcesForPastedEditorObject( this, 1071 aControlAny, aOUniqueName, xSourceStringResolver ); 1072 } 1073 else 1074 { 1075 LocalizationMgr::setControlResourceIDsForNewEditorObject 1076 ( this, aControlAny, aOUniqueName ); 1077 } 1078 } 1079 1080 // insert control model in editor dialog model 1081 Any aCtrlModel; 1082 aCtrlModel <<= xCtrlModel; 1083 m_xUnoControlDialogModel->insertByName( aOUniqueName , aCtrlModel ); 1084 1085 // insert object into drawing page 1086 pDlgEdModel->GetPage(0)->InsertObject( pCtrlObj ); 1087 pCtrlObj->SetRectFromProps(); 1088 pCtrlObj->UpdateStep(); 1089 pDlgEdForm->UpdateTabOrderAndGroups(); // #110559# 1090 pCtrlObj->StartListening(); // start listening 1091 1092 // mark object 1093 SdrPageView* pPgView = pDlgEdView->GetSdrPageView(); 1094 pDlgEdView->MarkObj( pCtrlObj, pPgView, sal_False, sal_True); 1095 } 1096 1097 // center marked objects in dialog editor form 1098 Point aMarkCenter = (pDlgEdView->GetMarkedObjRect()).Center(); 1099 Point aFormCenter = (pDlgEdForm->GetSnapRect()).Center(); 1100 Point aPoint = aFormCenter - aMarkCenter; 1101 Size aSize( aPoint.X() , aPoint.Y() ); 1102 pDlgEdView->MoveMarkedObj( aSize ); // update of control model properties (position + size) in NbcMove 1103 pDlgEdView->MarkListHasChanged(); 1104 1105 // dialog model changed 1106 SetDialogModelChanged(sal_True); 1107 } 1108 } 1109 } 1110 } 1111 } 1112 1113 //---------------------------------------------------------------------------- 1114 1115 void DlgEditor::Delete() 1116 { 1117 if( !pDlgEdView->AreObjectsMarked() ) 1118 return; 1119 1120 // remove control models of marked objects from dialog model 1121 sal_uLong nMark = pDlgEdView->GetMarkedObjectList().GetMarkCount(); 1122 1123 for( sal_uLong i = 0; i < nMark; i++ ) 1124 { 1125 SdrObject* pObj = pDlgEdView->GetMarkedObjectList().GetMark(i)->GetMarkedSdrObj(); 1126 DlgEdObj* pDlgEdObj = PTR_CAST(DlgEdObj, pObj); 1127 1128 if ( pDlgEdObj && !pDlgEdObj->ISA(DlgEdForm) ) 1129 { 1130 // get name from property 1131 ::rtl::OUString aName; 1132 uno::Reference< beans::XPropertySet > xPSet(pDlgEdObj->GetUnoControlModel(), uno::UNO_QUERY); 1133 if (xPSet.is()) 1134 { 1135 xPSet->getPropertyValue( DLGED_PROP_NAME ) >>= aName; 1136 } 1137 1138 // remove control from dialog model 1139 Reference< ::com::sun::star::container::XNameAccess > xNameAcc(pDlgEdObj->GetDlgEdForm()->GetUnoControlModel(), UNO_QUERY ); 1140 if ( xNameAcc.is() && xNameAcc->hasByName(aName) ) 1141 { 1142 Reference< ::com::sun::star::container::XNameContainer > xCont(xNameAcc, UNO_QUERY ); 1143 if ( xCont.is() ) 1144 { 1145 if( xCont->hasByName( aName ) ) 1146 { 1147 Any aAny = xCont->getByName( aName ); 1148 LocalizationMgr::deleteControlResourceIDsForDeletedEditorObject( this, aAny, aName ); 1149 } 1150 xCont->removeByName( aName ); 1151 } 1152 } 1153 1154 // remove child from parent form 1155 pDlgEdForm->RemoveChild( pDlgEdObj ); 1156 } 1157 } 1158 1159 // update tab indices 1160 pDlgEdForm->UpdateTabIndices(); 1161 1162 pDlgEdView->BrkAction(); 1163 1164 sal_Bool bDlgMarked = UnmarkDialog(); 1165 pDlgEdView->DeleteMarked(); 1166 if( bDlgMarked ) 1167 RemarkDialog(); 1168 } 1169 1170 //---------------------------------------------------------------------------- 1171 1172 sal_Bool DlgEditor::IsPasteAllowed() 1173 { 1174 sal_Bool bPaste = sal_False; 1175 1176 // get clipboard 1177 Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow()->GetClipboard(); 1178 if ( xClipboard.is() ) 1179 { 1180 // get clipboard content 1181 const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 1182 Reference< datatransfer::XTransferable > xTransf = xClipboard->getContents(); 1183 Application::AcquireSolarMutex( nRef ); 1184 if ( xTransf.is() ) 1185 { 1186 if ( xTransf->isDataFlavorSupported( m_ClipboardDataFlavors[0] ) ) 1187 { 1188 bPaste = sal_True; 1189 } 1190 } 1191 } 1192 1193 return bPaste; 1194 } 1195 1196 //---------------------------------------------------------------------------- 1197 1198 void DlgEditor::ShowProperties() 1199 { 1200 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 1201 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 1202 if ( pViewFrame && !pViewFrame->HasChildWindow( SID_SHOW_PROPERTYBROWSER ) ) 1203 pViewFrame->ToggleChildWindow( SID_SHOW_PROPERTYBROWSER ); 1204 } 1205 1206 //---------------------------------------------------------------------------- 1207 1208 void DlgEditor::UpdatePropertyBrowserDelayed() 1209 { 1210 aMarkTimer.Start(); 1211 } 1212 1213 //---------------------------------------------------------------------------- 1214 1215 sal_Bool DlgEditor::IsModified() const 1216 { 1217 return pDlgEdModel->IsChanged() || bDialogModelChanged; 1218 } 1219 1220 //---------------------------------------------------------------------------- 1221 1222 void DlgEditor::ClearModifyFlag() 1223 { 1224 pDlgEdModel->SetChanged( sal_False ); 1225 bDialogModelChanged = sal_False; 1226 } 1227 1228 //---------------------------------------------------------------------------- 1229 1230 #define LMARGPRN 1700 1231 #define RMARGPRN 900 1232 #define TMARGPRN 2000 1233 #define BMARGPRN 1000 1234 #define BORDERPRN 300 1235 1236 //---------------------------------------------------------------------------- 1237 1238 void lcl_PrintHeader( Printer* pPrinter, const String& rTitle ) // not working yet 1239 { 1240 pPrinter->Push(); 1241 1242 short nLeftMargin = LMARGPRN; 1243 Size aSz = pPrinter->GetOutputSize(); 1244 short nBorder = BORDERPRN; 1245 1246 pPrinter->SetLineColor( COL_BLACK ); 1247 pPrinter->SetFillColor(); 1248 1249 Font aFont( pPrinter->GetFont() ); 1250 aFont.SetWeight( WEIGHT_BOLD ); 1251 aFont.SetAlign( ALIGN_BOTTOM ); 1252 pPrinter->SetFont( aFont ); 1253 1254 long nFontHeight = pPrinter->GetTextHeight(); 1255 1256 // 1.Border => Strich, 2+3 Border = Freiraum. 1257 long nYTop = TMARGPRN-3*nBorder-nFontHeight; 1258 1259 long nXLeft = nLeftMargin-nBorder; 1260 long nXRight = aSz.Width()-RMARGPRN+nBorder; 1261 1262 pPrinter->DrawRect( Rectangle( 1263 Point( nXLeft, nYTop ), 1264 Size( nXRight-nXLeft, aSz.Height() - nYTop - BMARGPRN + nBorder ) ) ); 1265 1266 long nY = TMARGPRN-2*nBorder; 1267 Point aPos( nLeftMargin, nY ); 1268 pPrinter->DrawText( aPos, rTitle ); 1269 1270 nY = TMARGPRN-nBorder; 1271 1272 pPrinter->DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) ); 1273 1274 pPrinter->Pop(); 1275 } 1276 1277 //---------------------------------------------------------------------------- 1278 1279 sal_Int32 DlgEditor::countPages( Printer* ) 1280 { 1281 return 1; 1282 } 1283 1284 void DlgEditor::printPage( sal_Int32 nPage, Printer* pPrinter, const String& rTitle ) 1285 { 1286 if( nPage == 0 ) 1287 Print( pPrinter, rTitle ); 1288 } 1289 1290 //---------------------------------------------------------------------------- 1291 1292 void DlgEditor::Print( Printer* pPrinter, const String& rTitle ) // not working yet 1293 { 1294 if( pDlgEdView ) 1295 { 1296 MapMode aOldMap( pPrinter->GetMapMode()); 1297 Font aOldFont( pPrinter->GetFont() ); 1298 1299 MapMode aMap( MAP_100TH_MM ); 1300 pPrinter->SetMapMode( aMap ); 1301 Font aFont; 1302 #ifdef OS2 1303 //aFont.SetName( System::GetStandardFont( STDFONT_SWISS ).GetName() ); 1304 #endif 1305 aFont.SetAlign( ALIGN_BOTTOM ); 1306 aFont.SetSize( Size( 0, 360 )); 1307 pPrinter->SetFont( aFont ); 1308 1309 Size aPaperSz = pPrinter->GetOutputSize(); 1310 aPaperSz.Width() -= (LMARGPRN+RMARGPRN); 1311 aPaperSz.Height() -= (TMARGPRN+BMARGPRN); 1312 1313 lcl_PrintHeader( pPrinter, rTitle ); 1314 1315 Bitmap aDlg; 1316 #ifdef OS2 1317 Bitmap* pDlg = new Bitmap; 1318 //pSbxForm->SnapShot( *pDlg ); 1319 SvMemoryStream* pStrm = new SvMemoryStream; 1320 *pStrm << *pDlg; 1321 delete pDlg; 1322 pStrm->Seek(0); 1323 *pStrm >> aDlg; 1324 delete pStrm; 1325 #else 1326 //pSbxForm->SnapShot( aDlg ); 1327 #endif 1328 Size aBmpSz( pPrinter->PixelToLogic( aDlg.GetSizePixel() ) ); 1329 double nPaperSzWidth = aPaperSz.Width(); 1330 double nPaperSzHeight = aPaperSz.Height(); 1331 double nBmpSzWidth = aBmpSz.Width(); 1332 double nBmpSzHeight = aBmpSz.Height(); 1333 double nScaleX = (nPaperSzWidth / nBmpSzWidth ); 1334 double nScaleY = (nPaperSzHeight / nBmpSzHeight ); 1335 1336 Size aOutputSz; 1337 if( nBmpSzHeight * nScaleX <= nPaperSzHeight ) 1338 { 1339 aOutputSz.Width() = (long)(((double)nBmpSzWidth) * nScaleX); 1340 aOutputSz.Height() = (long)(((double)nBmpSzHeight) * nScaleX); 1341 } 1342 else 1343 { 1344 aOutputSz.Width() = (long)(((double)nBmpSzWidth) * nScaleY); 1345 aOutputSz.Height() = (long)(((double)nBmpSzHeight) * nScaleY); 1346 } 1347 1348 Point aPosOffs( 1349 (aPaperSz.Width() / 2) - (aOutputSz.Width() / 2), 1350 (aPaperSz.Height()/ 2) - (aOutputSz.Height() / 2)); 1351 1352 aPosOffs.X() += LMARGPRN; 1353 aPosOffs.Y() += TMARGPRN; 1354 1355 pPrinter->DrawBitmap( aPosOffs, aOutputSz, aDlg ); 1356 1357 pPrinter->SetMapMode( aOldMap ); 1358 pPrinter->SetFont( aOldFont ); 1359 } 1360 } 1361 1362 //---------------------------------------------------------------------------- 1363 1364 bool DlgEditor::AdjustPageSize() 1365 { 1366 bool bAdjustedPageSize = false; 1367 Reference< beans::XPropertySet > xPSet( m_xUnoControlDialogModel, UNO_QUERY ); 1368 if ( xPSet.is() ) 1369 { 1370 sal_Int32 nFormXIn = 0, nFormYIn = 0, nFormWidthIn = 0, nFormHeightIn = 0; 1371 xPSet->getPropertyValue( DLGED_PROP_POSITIONX ) >>= nFormXIn; 1372 xPSet->getPropertyValue( DLGED_PROP_POSITIONY ) >>= nFormYIn; 1373 xPSet->getPropertyValue( DLGED_PROP_WIDTH ) >>= nFormWidthIn; 1374 xPSet->getPropertyValue( DLGED_PROP_HEIGHT ) >>= nFormHeightIn; 1375 1376 sal_Int32 nFormX, nFormY, nFormWidth, nFormHeight; 1377 if ( pDlgEdForm && pDlgEdForm->TransformFormToSdrCoordinates( nFormXIn, nFormYIn, nFormWidthIn, nFormHeightIn, nFormX, nFormY, nFormWidth, nFormHeight ) ) 1378 { 1379 Size aPageSizeDelta( 400, 300 ); 1380 DBG_ASSERT( pWindow, "DlgEditor::AdjustPageSize: no window!" ); 1381 if ( pWindow ) 1382 aPageSizeDelta = pWindow->PixelToLogic( aPageSizeDelta, MapMode( MAP_100TH_MM ) ); 1383 1384 sal_Int32 nNewPageWidth = nFormX + nFormWidth + aPageSizeDelta.Width(); 1385 sal_Int32 nNewPageHeight = nFormY + nFormHeight + aPageSizeDelta.Height(); 1386 1387 Size aPageSizeMin( DLGED_PAGE_WIDTH_MIN, DLGED_PAGE_HEIGHT_MIN ); 1388 DBG_ASSERT( pWindow, "DlgEditor::AdjustPageSize: no window!" ); 1389 if ( pWindow ) 1390 aPageSizeMin = pWindow->PixelToLogic( aPageSizeMin, MapMode( MAP_100TH_MM ) ); 1391 sal_Int32 nPageWidthMin = aPageSizeMin.Width(); 1392 sal_Int32 nPageHeightMin = aPageSizeMin.Height(); 1393 1394 if ( nNewPageWidth < nPageWidthMin ) 1395 nNewPageWidth = nPageWidthMin; 1396 1397 if ( nNewPageHeight < nPageHeightMin ) 1398 nNewPageHeight = nPageHeightMin; 1399 1400 if ( pDlgEdPage ) 1401 { 1402 Size aPageSize = pDlgEdPage->GetSize(); 1403 if ( nNewPageWidth != aPageSize.Width() || nNewPageHeight != aPageSize.Height() ) 1404 { 1405 Size aNewPageSize( nNewPageWidth, nNewPageHeight ); 1406 pDlgEdPage->SetSize( aNewPageSize ); 1407 DBG_ASSERT( pDlgEdView, "DlgEditor::AdjustPageSize: no view!" ); 1408 if ( pDlgEdView ) 1409 pDlgEdView->SetWorkArea( Rectangle( Point( 0, 0 ), aNewPageSize ) ); 1410 bAdjustedPageSize = true; 1411 } 1412 } 1413 } 1414 } 1415 1416 return bAdjustedPageSize; 1417 } 1418 1419 //---------------------------------------------------------------------------- 1420