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_svx.hxx" 30 31 #include <com/sun/star/text/WritingMode.hpp> 32 33 #include <vcl/toolbox.hxx> 34 35 #include <svl/itempool.hxx> 36 37 #include <svtools/toolbarmenu.hxx> 38 #include <svtools/popupwindowcontroller.hxx> 39 #include <svtools/popupmenucontrollerbase.hxx> 40 41 #include <sfx2/app.hxx> 42 #include <sfx2/dispatch.hxx> 43 44 #include <editeng/eeitem.hxx> 45 #include <editeng/frmdiritem.hxx> 46 47 #include <svx/fmmodel.hxx> 48 #include <svx/svxids.hrc> 49 #include <svx/dialmgr.hxx> 50 #include <svx/dialogs.hrc> 51 #include <svx/svdpage.hxx> 52 #include <svx/svdobj.hxx> 53 #include <svx/svdview.hxx> 54 #include <svx/svdoutl.hxx> 55 56 #include "svx/gallery.hxx" 57 #include <svx/dlgutil.hxx> 58 59 #include <svx/fontworkgallery.hxx> 60 #include "fontworkgallery.hrc" 61 62 #include <algorithm> 63 64 #include "helpid.hrc" 65 66 using ::rtl::OUString; 67 using ::svtools::ToolbarMenu; 68 69 using namespace ::com::sun::star; 70 using namespace ::com::sun::star::uno; 71 using namespace ::com::sun::star::lang; 72 using namespace ::com::sun::star::beans; 73 using namespace ::com::sun::star::frame; 74 75 namespace svx 76 { 77 78 const int nColCount = 4; 79 const int nLineCount = 4; 80 81 /************************************************************************* 82 |* Svx3DWin - FloatingWindow 83 \************************************************************************/ 84 FontWorkGalleryDialog::FontWorkGalleryDialog( SdrView* pSdrView, Window* pParent, sal_uInt16 /*nSID*/ ) : 85 ModalDialog( pParent, SVX_RES( RID_SVX_MDLG_FONTWORK_GALLERY ) ), 86 maFLFavorites ( this, SVX_RES( FL_FAVORITES ) ), 87 maCtlFavorites ( this, SVX_RES( CTL_FAVORITES ) ), 88 maOKButton ( this, SVX_RES( BTN_OK ) ), 89 maCancelButton ( this, SVX_RES( BTN_CANCEL ) ), 90 maHelpButton ( this, SVX_RES( BTN_HELP ) ), 91 mnThemeId ( 0xffff ), 92 mpSdrView ( pSdrView ), 93 mpModel ( (FmFormModel*)pSdrView->GetModel() ), 94 maStrClickToAddText ( SVX_RES( STR_CLICK_TO_ADD_TEXT ) ), 95 mppSdrObject ( NULL ), 96 mpDestModel ( NULL ) 97 { 98 FreeResource(); 99 100 maCtlFavorites.SetDoubleClickHdl( LINK( this, FontWorkGalleryDialog, DoubleClickFavoriteHdl ) ); 101 maOKButton.SetClickHdl( LINK( this, FontWorkGalleryDialog, ClickOKHdl ) ); 102 103 maCtlFavorites.SetColCount( nColCount ); 104 maCtlFavorites.SetLineCount( nLineCount ); 105 maCtlFavorites.SetExtraSpacing( 3 ); 106 107 initfavorites( GALLERY_THEME_FONTWORK, maFavoritesHorizontal ); 108 fillFavorites( GALLERY_THEME_FONTWORK, maFavoritesHorizontal ); 109 } 110 111 static void delete_bitmap( Bitmap* p ) { delete p; } 112 113 // ----------------------------------------------------------------------- 114 FontWorkGalleryDialog::~FontWorkGalleryDialog() 115 { 116 std::for_each( maFavoritesHorizontal.begin(), maFavoritesHorizontal.end(), delete_bitmap ); 117 } 118 119 // ----------------------------------------------------------------------- 120 121 void FontWorkGalleryDialog::initfavorites(sal_uInt16 nThemeId, std::vector< Bitmap * >& rFavorites) 122 { 123 // Ueber die Gallery werden die Favoriten eingelesen 124 sal_uIntPtr nFavCount = GalleryExplorer::GetSdrObjCount( nThemeId ); 125 126 // Gallery thema locken 127 GalleryExplorer::BeginLocking(nThemeId); 128 129 sal_uInt32 nModelPos; 130 FmFormModel *pModel = NULL; 131 for( nModelPos = 0; nModelPos < nFavCount; nModelPos++ ) 132 { 133 Bitmap* pThumb = new Bitmap; 134 135 if( GalleryExplorer::GetSdrObj( nThemeId, nModelPos, pModel, pThumb ) ) 136 { 137 /* 138 VirtualDevice aVDev; 139 Size aRenderSize( aThumbSize.Width() * 4, aThumbSize.Height() * 4 ); 140 aVDev.SetOutputSizePixel( aRenderSize ); 141 142 if( GalleryExplorer::DrawCentered( &aVDev, *pModel ) ) 143 { 144 aThumb = aVDev.GetBitmap( Point(), aVDev.GetOutputSizePixel() ); 145 146 Size aMS( 4, 4 ); 147 BmpFilterParam aParam( aMS ); 148 aThumb.Filter( BMP_FILTER_MOSAIC, &aParam ); 149 aThumb.Scale( aThumbSize ); 150 } 151 */ 152 } 153 154 rFavorites.push_back( pThumb ); 155 } 156 157 // Gallery thema freigeben 158 GalleryExplorer::EndLocking(nThemeId); 159 } 160 161 void FontWorkGalleryDialog::fillFavorites( sal_uInt16 nThemeId, std::vector< Bitmap * >& rFavorites ) 162 { 163 mnThemeId = nThemeId; 164 165 Size aThumbSize( maCtlFavorites.GetSizePixel() ); 166 aThumbSize.Width() /= nColCount; 167 aThumbSize.Height() /= nLineCount; 168 aThumbSize.Width() -= 12; 169 aThumbSize.Height() -= 12; 170 171 std::vector< Bitmap * >::size_type nFavCount = rFavorites.size(); 172 173 // ValueSet Favoriten 174 if( nFavCount > (nColCount * nLineCount) ) 175 { 176 WinBits nWinBits = maCtlFavorites.GetStyle(); 177 nWinBits |= WB_VSCROLL; 178 maCtlFavorites.SetStyle( nWinBits ); 179 } 180 181 maCtlFavorites.Clear(); 182 183 sal_uInt32 nFavorite; 184 for( nFavorite = 1; nFavorite <= nFavCount; nFavorite++ ) 185 { 186 String aStr(SVX_RES(RID_SVXFLOAT3D_FAVORITE)); 187 aStr += sal_Unicode(' '); 188 aStr += String::CreateFromInt32((sal_Int32)nFavorite); 189 Image aThumbImage( *rFavorites[nFavorite-1] ); 190 maCtlFavorites.InsertItem( (sal_uInt16)nFavorite, aThumbImage, aStr ); 191 } 192 } 193 194 void FontWorkGalleryDialog::changeText( SdrTextObj* pObj ) 195 { 196 if( pObj ) 197 { 198 SdrOutliner& rOutl = mpModel->GetDrawOutliner(pObj); 199 200 sal_uInt16 nOutlMode = rOutl.GetMode(); 201 Size aPaperSize = rOutl.GetPaperSize(); 202 sal_Bool bUpdateMode = rOutl.GetUpdateMode(); 203 rOutl.SetUpdateMode(sal_False); 204 rOutl.SetParaAttribs( 0, rOutl.GetEmptyItemSet() ); 205 206 // #95114# Always set the object's StyleSheet at the Outliner to 207 // use the current objects StyleSheet. Thus it's the same as in 208 // SetText(...). 209 // #95114# Moved this implementation from where SetObjText(...) was called 210 // to inside this method to work even when outliner is fetched here. 211 rOutl.SetStyleSheet(0, pObj->GetStyleSheet()); 212 213 rOutl.SetPaperSize( pObj->GetLogicRect().GetSize() ); 214 215 rOutl.SetText( maStrClickToAddText, rOutl.GetParagraph( 0 ) ); 216 pObj->SetOutlinerParaObject( rOutl.CreateParaObject() ); 217 218 rOutl.Init( nOutlMode ); 219 rOutl.SetParaAttribs( 0, rOutl.GetEmptyItemSet() ); 220 rOutl.SetUpdateMode( bUpdateMode ); 221 rOutl.SetPaperSize( aPaperSize ); 222 223 rOutl.Clear(); 224 } 225 } 226 227 void FontWorkGalleryDialog::SetSdrObjectRef( SdrObject** ppSdrObject, SdrModel* pModel ) 228 { 229 mppSdrObject = ppSdrObject; 230 mpDestModel = pModel; 231 } 232 233 void FontWorkGalleryDialog::insertSelectedFontwork() 234 { 235 sal_uInt16 nItemId = maCtlFavorites.GetSelectItemId(); 236 237 if( nItemId > 0 ) 238 { 239 FmFormModel* pModel = new FmFormModel(); 240 pModel->GetItemPool().FreezeIdRanges(); 241 242 if( GalleryExplorer::GetSdrObj( mnThemeId, nItemId-1, pModel ) ) 243 { 244 SdrPage* pPage = pModel->GetPage(0); 245 if( pPage && pPage->GetObjCount() ) 246 { 247 SdrObject* pNewObject = pPage->GetObj(0)->Clone(); 248 249 // center shape on current view 250 OutputDevice* pOutDev = mpSdrView->GetFirstOutputDevice(); 251 if( pOutDev ) 252 { 253 Rectangle aObjRect( pNewObject->GetLogicRect() ); 254 Rectangle aVisArea = pOutDev->PixelToLogic(Rectangle(Point(0,0), pOutDev->GetOutputSizePixel())); 255 /* 256 sal_Int32 nObjHeight = aObjRect.GetHeight(); 257 VirtualDevice aVirDev( 1 ); // calculating the optimal textwidth 258 Font aFont; 259 aFont.SetHeight( nObjHeight ); 260 aVirDev.SetMapMode( MAP_100TH_MM ); 261 aVirDev.SetFont( aFont ); 262 aObjRect.SetSize( Size( aVirDev.GetTextWidth( maStrClickToAddText ), nObjHeight ) ); 263 */ 264 Point aPagePos = aVisArea.Center(); 265 aPagePos.X() -= aObjRect.GetWidth() / 2; 266 aPagePos.Y() -= aObjRect.GetHeight() / 2; 267 Rectangle aNewObjectRectangle(aPagePos, aObjRect.GetSize()); 268 SdrPageView* pPV = mpSdrView->GetSdrPageView(); 269 270 pNewObject->SetLogicRect(aNewObjectRectangle); 271 if ( mppSdrObject ) 272 { 273 *mppSdrObject = pNewObject; 274 (*mppSdrObject)->SetModel( mpDestModel ); 275 } 276 else if( pPV ) 277 { 278 mpSdrView->InsertObjectAtView( pNewObject, *pPV ); 279 // changeText( PTR_CAST( SdrTextObj, pNewObject ) ); 280 } 281 } 282 } 283 } 284 285 delete pModel; 286 } 287 } 288 289 // ----------------------------------------------------------------------- 290 291 IMPL_LINK( FontWorkGalleryDialog, ClickOKHdl, void*, EMPTYARG ) 292 { 293 insertSelectedFontwork(); 294 EndDialog( true ); 295 return 0; 296 } 297 298 // ----------------------------------------------------------------------- 299 300 IMPL_LINK( FontWorkGalleryDialog, DoubleClickFavoriteHdl, void*, EMPTYARG ) 301 { 302 insertSelectedFontwork(); 303 EndDialog( true ); 304 return( 0L ); 305 } 306 307 //------------------------------------------------------------------------ 308 309 SFX_IMPL_TOOLBOX_CONTROL( FontWorkShapeTypeControl, SfxStringItem ); 310 FontWorkShapeTypeControl::FontWorkShapeTypeControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) 311 : SfxToolBoxControl( nSlotId, nId, rTbx ) 312 { 313 rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) ); 314 rTbx.Invalidate(); 315 } 316 317 // ----------------------------------------------------------------------- 318 319 FontWorkShapeTypeControl::~FontWorkShapeTypeControl() 320 { 321 } 322 323 // ----------------------------------------------------------------------- 324 325 SfxPopupWindowType FontWorkShapeTypeControl::GetPopupWindowType() const 326 { 327 return SFX_POPUPWINDOW_ONCLICK; //( aLastAction.getLength() == 0 ? SFX_POPUPWINDOW_ONCLICK : SFX_POPUPWINDOW_ONTIMEOUT ); 328 } 329 330 // ----------------------------------------------------------------------- 331 332 SfxPopupWindow* FontWorkShapeTypeControl::CreatePopupWindow() 333 { 334 rtl::OUString aSubTbxResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/fontworkshapetype" ) ); 335 createAndPositionSubToolBar( aSubTbxResName ); 336 return NULL; 337 } 338 339 // ----------------------------------------------------------------------- 340 341 void FontWorkShapeTypeControl::Select( sal_Bool ) 342 { 343 344 } 345 346 // ======================================================================== 347 // FontWorkAlignmentWindow 348 // ======================================================================== 349 350 class FontWorkAlignmentWindow : public ToolbarMenu 351 { 352 public: 353 FontWorkAlignmentWindow( svt::ToolboxController& rController, const Reference< XFrame >& rFrame, Window* pParentWindow ); 354 355 virtual void SAL_CALL statusChanged( const frame::FeatureStateEvent& Event ) throw ( RuntimeException ); 356 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 357 358 private: 359 svt::ToolboxController& mrController; 360 361 Image maImgAlgin1; 362 Image maImgAlgin2; 363 Image maImgAlgin3; 364 Image maImgAlgin4; 365 Image maImgAlgin5; 366 Image maImgAlgin1h; 367 Image maImgAlgin2h; 368 Image maImgAlgin3h; 369 Image maImgAlgin4h; 370 Image maImgAlgin5h; 371 372 const rtl::OUString msFontworkAlignment; 373 374 DECL_LINK( SelectHdl, void * ); 375 376 void implSetAlignment( int nAlignmentMode, bool bEnabled ); 377 }; 378 379 FontWorkAlignmentWindow::FontWorkAlignmentWindow( svt::ToolboxController& rController, const Reference< XFrame >& rFrame, Window* pParentWindow ) 380 : ToolbarMenu( rFrame, pParentWindow, SVX_RES( RID_SVXFLOAT_FONTWORK_ALIGNMENT )) 381 , mrController( rController ) 382 , maImgAlgin1( SVX_RES( IMG_FONTWORK_ALIGN_LEFT_16 ) ) 383 , maImgAlgin2( SVX_RES( IMG_FONTWORK_ALIGN_CENTER_16 ) ) 384 , maImgAlgin3( SVX_RES( IMG_FONTWORK_ALIGN_RIGHT_16 ) ) 385 , maImgAlgin4( SVX_RES( IMG_FONTWORK_ALIGN_WORD_16 ) ) 386 , maImgAlgin5( SVX_RES( IMG_FONTWORK_ALIGN_STRETCH_16 ) ) 387 , maImgAlgin1h( SVX_RES( IMG_FONTWORK_ALIGN_LEFT_16_H ) ) 388 , maImgAlgin2h( SVX_RES( IMG_FONTWORK_ALIGN_CENTER_16_H ) ) 389 , maImgAlgin3h( SVX_RES( IMG_FONTWORK_ALIGN_RIGHT_16_H ) ) 390 , maImgAlgin4h( SVX_RES( IMG_FONTWORK_ALIGN_WORD_16_H ) ) 391 , maImgAlgin5h( SVX_RES( IMG_FONTWORK_ALIGN_STRETCH_16_H ) ) 392 , msFontworkAlignment( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontworkAlignment" ) ) 393 { 394 bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode(); 395 396 SetHelpId( HID_POPUP_FONTWORK_ALIGN ); 397 SetSelectHdl( LINK( this, FontWorkAlignmentWindow, SelectHdl ) ); 398 399 appendEntry( 0, String( SVX_RES( STR_ALIGN_LEFT ) ), bHighContrast ? maImgAlgin1h : maImgAlgin1 ); 400 appendEntry( 1, String( SVX_RES( STR_ALIGN_CENTER ) ), bHighContrast ? maImgAlgin2h : maImgAlgin2 ); 401 appendEntry( 2, String( SVX_RES( STR_ALIGN_RIGHT ) ), bHighContrast ? maImgAlgin3h : maImgAlgin3 ); 402 appendEntry( 3, String( SVX_RES( STR_ALIGN_WORD ) ), bHighContrast ? maImgAlgin4h : maImgAlgin4 ); 403 appendEntry( 4, String( SVX_RES( STR_ALIGN_STRETCH ) ), bHighContrast ? maImgAlgin5h : maImgAlgin5 ); 404 405 SetOutputSizePixel( getMenuSize() ); 406 407 FreeResource(); 408 409 AddStatusListener( msFontworkAlignment ); 410 } 411 412 // ----------------------------------------------------------------------- 413 414 void FontWorkAlignmentWindow::implSetAlignment( int nSurface, bool bEnabled ) 415 { 416 int i; 417 for( i = 0; i < 5; i++ ) 418 { 419 checkEntry( i, (i == nSurface) && bEnabled ); 420 enableEntry( i, bEnabled ); 421 } 422 } 423 424 // ----------------------------------------------------------------------- 425 426 void SAL_CALL FontWorkAlignmentWindow::statusChanged( const frame::FeatureStateEvent& Event ) throw ( RuntimeException ) 427 { 428 if( Event.FeatureURL.Main.equals( msFontworkAlignment ) ) 429 { 430 if( !Event.IsEnabled ) 431 { 432 implSetAlignment( 0, false ); 433 } 434 else 435 { 436 sal_Int32 nValue = 0; 437 if( Event.State >>= nValue ) 438 implSetAlignment( nValue, true ); 439 } 440 } 441 } 442 443 // ----------------------------------------------------------------------- 444 445 void FontWorkAlignmentWindow::DataChanged( const DataChangedEvent& rDCEvt ) 446 { 447 ToolbarMenu::DataChanged( rDCEvt ); 448 449 if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) ) 450 { 451 bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode(); 452 453 appendEntry( 0, String( SVX_RES( STR_ALIGN_LEFT ) ), bHighContrast ? maImgAlgin1h : maImgAlgin1 ); 454 appendEntry( 1, String( SVX_RES( STR_ALIGN_CENTER ) ), bHighContrast ? maImgAlgin2h : maImgAlgin2 ); 455 appendEntry( 2, String( SVX_RES( STR_ALIGN_RIGHT ) ), bHighContrast ? maImgAlgin3h : maImgAlgin3 ); 456 appendEntry( 3, String( SVX_RES( STR_ALIGN_WORD ) ), bHighContrast ? maImgAlgin4h : maImgAlgin4 ); 457 appendEntry( 4, String( SVX_RES( STR_ALIGN_STRETCH ) ), bHighContrast ? maImgAlgin5h : maImgAlgin5 ); 458 } 459 } 460 461 // ----------------------------------------------------------------------- 462 463 IMPL_LINK( FontWorkAlignmentWindow, SelectHdl, void *, EMPTYARG ) 464 { 465 if ( IsInPopupMode() ) 466 EndPopupMode(); 467 468 sal_Int32 nAlignment = getSelectedEntryId(); 469 if( nAlignment >= 0 ) 470 { 471 Sequence< PropertyValue > aArgs( 1 ); 472 aArgs[0].Name = msFontworkAlignment.copy(5); 473 aArgs[0].Value <<= (sal_Int32)nAlignment; 474 475 mrController.dispatchCommand( msFontworkAlignment, aArgs ); 476 477 implSetAlignment( nAlignment, true ); 478 } 479 480 return 0; 481 } 482 483 // ======================================================================== 484 // FontWorkAlignmentControl 485 // ======================================================================== 486 487 class FontWorkAlignmentControl : public svt::PopupWindowController 488 { 489 public: 490 FontWorkAlignmentControl( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServiceManager ); 491 492 virtual ::Window* createPopupWindow( ::Window* pParent ); 493 494 // XServiceInfo 495 virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); 496 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); 497 498 using svt::PopupWindowController::createPopupWindow; 499 }; 500 501 502 // ----------------------------------------------------------------------- 503 504 FontWorkAlignmentControl::FontWorkAlignmentControl( const Reference< lang::XMultiServiceFactory >& rServiceManager ) 505 : svt::PopupWindowController( rServiceManager, Reference< frame::XFrame >(), OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontworkAlignment" ) ) ) 506 { 507 } 508 509 // ----------------------------------------------------------------------- 510 511 ::Window* FontWorkAlignmentControl::createPopupWindow( ::Window* pParent ) 512 { 513 return new FontWorkAlignmentWindow( *this, m_xFrame, pParent ); 514 } 515 516 // ----------------------------------------------------------------------- 517 // XServiceInfo 518 // ----------------------------------------------------------------------- 519 520 OUString SAL_CALL FontWorkAlignmentControl_getImplementationName() 521 { 522 return OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.FontWorkAlignmentController" )); 523 } 524 525 // -------------------------------------------------------------------- 526 527 Sequence< OUString > SAL_CALL FontWorkAlignmentControl_getSupportedServiceNames() throw( RuntimeException ) 528 { 529 Sequence< OUString > aSNS( 1 ); 530 aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" )); 531 return aSNS; 532 } 533 534 // -------------------------------------------------------------------- 535 536 Reference< XInterface > SAL_CALL SAL_CALL FontWorkAlignmentControl_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException ) 537 { 538 return *new FontWorkAlignmentControl( rSMgr ); 539 } 540 541 // -------------------------------------------------------------------- 542 543 OUString SAL_CALL FontWorkAlignmentControl::getImplementationName( ) throw (RuntimeException) 544 { 545 return FontWorkAlignmentControl_getImplementationName(); 546 } 547 548 // -------------------------------------------------------------------- 549 550 Sequence< OUString > SAL_CALL FontWorkAlignmentControl::getSupportedServiceNames( ) throw (RuntimeException) 551 { 552 return FontWorkAlignmentControl_getSupportedServiceNames(); 553 } 554 555 556 // #################################################################### 557 558 class FontWorkCharacterSpacingWindow : public ToolbarMenu 559 { 560 public: 561 FontWorkCharacterSpacingWindow( svt::ToolboxController& rController, const Reference< XFrame >& rFrame, Window* pParentWindow ); 562 563 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ); 564 private: 565 svt::ToolboxController& mrController; 566 567 const rtl::OUString msFontworkCharacterSpacing; 568 const rtl::OUString msFontworkKernCharacterPairs; 569 570 DECL_LINK( SelectHdl, void * ); 571 572 void implSetCharacterSpacing( sal_Int32 nCharacterSpacing, bool bEnabled ); 573 void implSetKernCharacterPairs( sal_Bool bKernOnOff, bool bEnabled ); 574 575 }; 576 577 // ----------------------------------------------------------------------- 578 579 FontWorkCharacterSpacingWindow::FontWorkCharacterSpacingWindow( svt::ToolboxController& rController, const Reference< XFrame >& rFrame, Window* pParentWindow ) 580 : ToolbarMenu( rFrame, pParentWindow, SVX_RES( RID_SVXFLOAT_FONTWORK_CHARSPACING )) 581 , mrController( rController ) 582 , msFontworkCharacterSpacing( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontworkCharacterSpacing" ) ) 583 , msFontworkKernCharacterPairs( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontworkKernCharacterPairs" ) ) 584 { 585 SetHelpId( HID_POPUP_FONTWORK_CHARSPACE ); 586 SetSelectHdl( LINK( this, FontWorkCharacterSpacingWindow, SelectHdl ) ); 587 588 appendEntry( 0, String( SVX_RES( STR_CHARS_SPACING_VERY_TIGHT ) ), MIB_RADIOCHECK ); 589 appendEntry( 1, String( SVX_RES( STR_CHARS_SPACING_TIGHT ) ), MIB_RADIOCHECK ); 590 appendEntry( 2, String( SVX_RES( STR_CHARS_SPACING_NORMAL ) ), MIB_RADIOCHECK ); 591 appendEntry( 3, String( SVX_RES( STR_CHARS_SPACING_LOOSE ) ), MIB_RADIOCHECK ); 592 appendEntry( 4, String( SVX_RES( STR_CHARS_SPACING_VERY_LOOSE ) ), MIB_RADIOCHECK ); 593 appendEntry( 5, String( SVX_RES( STR_CHARS_SPACING_CUSTOM ) ), MIB_RADIOCHECK ); 594 appendSeparator(); 595 appendEntry( 6, String( SVX_RES( STR_CHARS_SPACING_KERN_PAIRS ) ), MIB_CHECKABLE ); 596 597 SetOutputSizePixel( getMenuSize() ); 598 599 FreeResource(); 600 601 AddStatusListener( msFontworkCharacterSpacing ); 602 AddStatusListener( msFontworkKernCharacterPairs ); 603 } 604 605 // ----------------------------------------------------------------------- 606 607 void FontWorkCharacterSpacingWindow::implSetCharacterSpacing( sal_Int32 nCharacterSpacing, bool bEnabled ) 608 { 609 sal_Int32 i; 610 for ( i = 0; i < 6; i++ ) 611 { 612 checkEntry( i, sal_False ); 613 enableEntry( i, bEnabled ); 614 } 615 if ( nCharacterSpacing != -1 ) 616 { 617 sal_Int32 nEntry; 618 switch( nCharacterSpacing ) 619 { 620 case 80 : nEntry = 0; break; 621 case 90 : nEntry = 1; break; 622 case 100 : nEntry = 2; break; 623 case 120 : nEntry = 3; break; 624 case 150 : nEntry = 4; break; 625 default : nEntry = 5; break; 626 } 627 checkEntry( nEntry, bEnabled ); 628 } 629 } 630 631 // ----------------------------------------------------------------------- 632 633 void FontWorkCharacterSpacingWindow::implSetKernCharacterPairs( sal_Bool, bool bEnabled ) 634 { 635 enableEntry( 6, bEnabled ); 636 checkEntry( 6, bEnabled ); 637 } 638 639 // ----------------------------------------------------------------------- 640 641 void SAL_CALL FontWorkCharacterSpacingWindow::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ) 642 { 643 if( Event.FeatureURL.Main.equals( msFontworkCharacterSpacing ) ) 644 { 645 if( !Event.IsEnabled ) 646 { 647 implSetCharacterSpacing( 0, false ); 648 } 649 else 650 { 651 sal_Int32 nValue = 0; 652 if( Event.State >>= nValue ) 653 implSetCharacterSpacing( nValue, true ); 654 } 655 } 656 else if( Event.FeatureURL.Main.equals( msFontworkKernCharacterPairs ) ) 657 { 658 if( !Event.IsEnabled ) 659 { 660 implSetKernCharacterPairs( 0, false ); 661 } 662 else 663 { 664 sal_Bool bValue = sal_False; 665 if( Event.State >>= bValue ) 666 implSetKernCharacterPairs( bValue, true ); 667 } 668 } 669 } 670 671 // ----------------------------------------------------------------------- 672 673 IMPL_LINK( FontWorkCharacterSpacingWindow, SelectHdl, void *, EMPTYARG ) 674 { 675 if ( IsInPopupMode() ) 676 EndPopupMode(); 677 678 sal_Int32 nSelection = getSelectedEntryId(); 679 sal_Int32 nCharacterSpacing; 680 switch( nSelection ) 681 { 682 case 0 : nCharacterSpacing = 80; break; 683 case 1 : nCharacterSpacing = 90; break; 684 case 2 : nCharacterSpacing = 100; break; 685 case 3 : nCharacterSpacing = 120; break; 686 case 4 : nCharacterSpacing = 150; break; 687 default : nCharacterSpacing = 100; break; 688 } 689 if ( nSelection == 5 ) // custom spacing 690 { 691 Sequence< PropertyValue > aArgs( 1 ); 692 aArgs[0].Name = msFontworkCharacterSpacing.copy(5); 693 aArgs[0].Value <<= (sal_Int32)nCharacterSpacing; 694 695 mrController.dispatchCommand( OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontworkCharacterSpacingDialog" )), aArgs ); 696 } 697 else if ( nSelection == 6 ) // KernCharacterPairs 698 { 699 rtl::OUString aCommand( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontworkKernCharacterPairs" )); 700 701 Sequence< PropertyValue > aArgs( 1 ); 702 aArgs[0].Name = msFontworkKernCharacterPairs.copy(5); 703 aArgs[0].Value <<= (sal_Bool) sal_True; 704 705 mrController.dispatchCommand( msFontworkKernCharacterPairs, aArgs ); 706 707 implSetKernCharacterPairs( sal_True, true ); 708 } 709 else if( nSelection >= 0 ) 710 { 711 Sequence< PropertyValue > aArgs( 1 ); 712 aArgs[0].Name = msFontworkCharacterSpacing.copy(5); 713 aArgs[0].Value <<=( sal_Int32)nCharacterSpacing; 714 715 mrController.dispatchCommand( msFontworkCharacterSpacing, aArgs ); 716 717 implSetCharacterSpacing( nCharacterSpacing, true ); 718 } 719 720 return 0; 721 } 722 723 // ======================================================================== 724 // FontWorkCharacterSpacingControl 725 // ======================================================================== 726 727 class FontWorkCharacterSpacingControl : public svt::PopupWindowController 728 { 729 public: 730 FontWorkCharacterSpacingControl( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServiceManager ); 731 732 virtual ::Window* createPopupWindow( ::Window* pParent ); 733 734 // XServiceInfo 735 virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ); 736 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); 737 738 using svt::PopupWindowController::createPopupWindow; 739 }; 740 741 742 FontWorkCharacterSpacingControl::FontWorkCharacterSpacingControl( const Reference< lang::XMultiServiceFactory >& rServiceManager ) 743 : svt::PopupWindowController( rServiceManager, Reference< frame::XFrame >(), OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontworkCharacterSpacingFloater" ) ) ) 744 { 745 } 746 747 // ----------------------------------------------------------------------- 748 749 ::Window* FontWorkCharacterSpacingControl::createPopupWindow( ::Window* pParent ) 750 { 751 return new FontWorkCharacterSpacingWindow( *this, m_xFrame, pParent ); 752 } 753 754 // ----------------------------------------------------------------------- 755 // XServiceInfo 756 // ----------------------------------------------------------------------- 757 758 OUString SAL_CALL FontWorkCharacterSpacingControl_getImplementationName() 759 { 760 return OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.FontWorkCharacterSpacingController" )); 761 } 762 763 // -------------------------------------------------------------------- 764 765 Sequence< OUString > SAL_CALL FontWorkCharacterSpacingControl_getSupportedServiceNames() throw( RuntimeException ) 766 { 767 Sequence< OUString > aSNS( 1 ); 768 aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" )); 769 return aSNS; 770 } 771 772 // -------------------------------------------------------------------- 773 774 Reference< XInterface > SAL_CALL SAL_CALL FontWorkCharacterSpacingControl_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException ) 775 { 776 return *new FontWorkCharacterSpacingControl( rSMgr ); 777 } 778 779 // -------------------------------------------------------------------- 780 781 OUString SAL_CALL FontWorkCharacterSpacingControl::getImplementationName( ) throw (RuntimeException) 782 { 783 return FontWorkCharacterSpacingControl_getImplementationName(); 784 } 785 786 // -------------------------------------------------------------------- 787 788 Sequence< OUString > SAL_CALL FontWorkCharacterSpacingControl::getSupportedServiceNames( ) throw (RuntimeException) 789 { 790 return FontWorkCharacterSpacingControl_getSupportedServiceNames(); 791 } 792 793 // ======================================================================== 794 // FontworkCharacterSpacingDialog 795 // ======================================================================== 796 797 FontworkCharacterSpacingDialog::FontworkCharacterSpacingDialog( Window* pParent, sal_Int32 nScale ) 798 : ModalDialog( pParent, SVX_RES( RID_SVX_MDLG_FONTWORK_CHARSPACING ) ), 799 maFLScale( this, SVX_RES( FT_VALUE ) ), 800 maMtrScale( this, SVX_RES( MF_VALUE ) ), 801 maOKButton( this, SVX_RES( BTN_OK ) ), 802 maCancelButton( this, SVX_RES( BTN_CANCEL ) ), 803 maHelpButton( this, SVX_RES( BTN_HELP ) ) 804 { 805 maMtrScale.SetValue( nScale ); 806 FreeResource(); 807 } 808 809 FontworkCharacterSpacingDialog::~FontworkCharacterSpacingDialog() 810 { 811 } 812 813 sal_Int32 FontworkCharacterSpacingDialog::getScale() const 814 { 815 return (sal_Int32)maMtrScale.GetValue(); 816 } 817 818 } 819