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_sd.hxx" 30 31 #include "TextObjectBar.hxx" 32 33 #include <svx/svxids.hrc> 34 35 #include <i18npool/mslangid.hxx> 36 #include <editeng/ulspitem.hxx> 37 #include <editeng/lspcitem.hxx> 38 #include <editeng/adjitem.hxx> 39 #include <editeng/editview.hxx> 40 #include <editeng/editeng.hxx> 41 #include <editeng/outliner.hxx> 42 #include <editeng/unolingu.hxx> 43 #include <editeng/ulspitem.hxx> 44 #include <editeng/lspcitem.hxx> 45 #include <editeng/adjitem.hxx> 46 #include <vcl/vclenum.hxx> 47 #include <sfx2/app.hxx> 48 #include <svl/whiter.hxx> 49 #include <svl/itempool.hxx> 50 #include <svl/stritem.hxx> 51 #include <svl/style.hxx> 52 #include <svl/languageoptions.hxx> 53 #include <sfx2/tplpitem.hxx> 54 #include <editeng/escpitem.hxx> 55 #include <svx/svdoutl.hxx> 56 #include <svl/intitem.hxx> 57 #include <editeng/scripttypeitem.hxx> 58 #include <editeng/outlobj.hxx> 59 #include <editeng/writingmodeitem.hxx> 60 #include <editeng/frmdiritem.hxx> 61 62 63 #include <sfx2/objface.hxx> 64 65 #include "app.hrc" 66 #include "glob.hrc" 67 #include "res_bmp.hrc" 68 69 #include "eetext.hxx" 70 71 #include "drawdoc.hxx" 72 #include "DrawViewShell.hxx" 73 #include "OutlineViewShell.hxx" 74 #include "ViewShellBase.hxx" 75 #include "ToolBarManager.hxx" 76 #include "futempl.hxx" 77 #include "sdresid.hxx" 78 #include "Window.hxx" 79 #include "OutlineView.hxx" 80 81 82 using namespace sd; 83 using namespace ::com::sun::star; 84 85 #define TextObjectBar 86 #include "sdslots.hxx" 87 88 namespace sd { 89 90 /************************************************************************* 91 |* 92 |* Standardinterface deklarieren (Die Slotmap darf nicht leer sein, also 93 |* tragen wir etwas ein, was hier (hoffentlich) nie vorkommt). 94 |* 95 \************************************************************************/ 96 97 98 SFX_IMPL_INTERFACE( TextObjectBar, SfxShell, SdResId(STR_TEXTOBJECTBARSHELL) ) 99 { 100 } 101 102 TYPEINIT1( TextObjectBar, SfxShell ); 103 104 /************************************************************************* 105 |* 106 |* Standard-Konstruktor 107 |* 108 \************************************************************************/ 109 110 TextObjectBar::TextObjectBar ( 111 ViewShell* pSdViewSh, 112 SfxItemPool& rItemPool, 113 ::sd::View* pSdView ) 114 : SfxShell(pSdViewSh->GetViewShell()), 115 mpViewShell( pSdViewSh ), 116 mpView( pSdView ) 117 { 118 SetPool(&rItemPool); 119 120 if( mpView ) 121 { 122 OutlineView* pOutlinerView = dynamic_cast< OutlineView* >( mpView ); 123 if( pOutlinerView ) 124 { 125 SetUndoManager(&pOutlinerView->GetOutliner()->GetUndoManager()); 126 } 127 else 128 { 129 SdDrawDocument* pDoc = mpView->GetDoc(); 130 if( pDoc ) 131 { 132 DrawDocShell* pDocShell = pDoc->GetDocSh(); 133 if( pDocShell ) 134 { 135 SetUndoManager(pDocShell->GetUndoManager()); 136 DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( pSdViewSh ); 137 if ( pDrawViewShell ) 138 SetRepeatTarget(pSdView); 139 } 140 } 141 } 142 } 143 144 SetName( String( RTL_CONSTASCII_USTRINGPARAM( "TextObjectBar" ))); 145 146 // SetHelpId( SD_IF_SDDRAWTEXTOBJECTBAR ); 147 } 148 149 /************************************************************************* 150 |* 151 |* Destruktor 152 |* 153 \************************************************************************/ 154 155 TextObjectBar::~TextObjectBar() 156 { 157 SetRepeatTarget(NULL); 158 } 159 160 /************************************************************************* 161 |* 162 |* Status der Attribut-Items 163 |* 164 \************************************************************************/ 165 166 void TextObjectBar::GetAttrState( SfxItemSet& rSet ) 167 { 168 SfxWhichIter aIter( rSet ); 169 sal_uInt16 nWhich = aIter.FirstWhich(); 170 sal_Bool bTemplate = sal_False; 171 SfxItemSet aAttrSet( mpView->GetDoc()->GetPool() ); 172 SvtLanguageOptions aLangOpt; 173 sal_Bool bDisableParagraphTextDirection = !aLangOpt.IsCTLFontEnabled(); 174 sal_Bool bDisableVerticalText = !aLangOpt.IsVerticalTextEnabled(); 175 176 mpView->GetAttributes( aAttrSet ); 177 178 while ( nWhich ) 179 { 180 sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich) 181 ? GetPool().GetSlotId(nWhich) 182 : nWhich; 183 184 switch ( nSlotId ) 185 { 186 case SID_ATTR_CHAR_FONT: 187 case SID_ATTR_CHAR_FONTHEIGHT: 188 case SID_ATTR_CHAR_WEIGHT: 189 case SID_ATTR_CHAR_POSTURE: 190 { 191 SvxScriptSetItem aSetItem( nSlotId, GetPool() ); 192 aSetItem.GetItemSet().Put( aAttrSet, sal_False ); 193 194 sal_uInt16 nScriptType = mpView->GetScriptType(); 195 196 if( (nSlotId == SID_ATTR_CHAR_FONT) || (nSlotId == SID_ATTR_CHAR_FONTHEIGHT) ) 197 { 198 // #42732# input language should be preferred over 199 // current cursor position to detect script type 200 OutlinerView* pOLV = mpView->GetTextEditOutlinerView(); 201 202 if (mpView->ISA(OutlineView)) 203 { 204 pOLV = static_cast<OutlineView*>(mpView)->GetViewByWindow( 205 mpViewShell->GetActiveWindow()); 206 } 207 208 if(pOLV && !pOLV->GetSelection().HasRange()) 209 { 210 if( mpViewShell && mpViewShell->GetViewShell() && mpViewShell->GetViewShell()->GetWindow() ) 211 { 212 LanguageType nInputLang = mpViewShell->GetViewShell()->GetWindow()->GetInputLanguage(); 213 if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM) 214 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang ); 215 } 216 } 217 } 218 219 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType ); 220 if( pI ) 221 aAttrSet.Put( *pI, nWhich ); 222 else 223 aAttrSet.InvalidateItem( nWhich ); 224 } 225 break; 226 227 228 case SID_STYLE_APPLY: 229 case SID_STYLE_FAMILY2: 230 { 231 SfxStyleSheet* pStyleSheet = mpView->GetStyleSheetFromMarked(); 232 if( pStyleSheet ) 233 rSet.Put( SfxTemplateItem( nWhich, pStyleSheet->GetName() ) ); 234 else 235 { 236 rSet.Put( SfxTemplateItem( nWhich, String() ) ); 237 } 238 bTemplate = sal_True; 239 } 240 break; 241 242 case SID_OUTLINE_LEFT: 243 case SID_OUTLINE_RIGHT: 244 case SID_OUTLINE_UP: 245 case SID_OUTLINE_DOWN: 246 { 247 sal_Bool bDisableLeft = sal_True; 248 sal_Bool bDisableRight = sal_True; 249 sal_Bool bDisableUp = sal_True; 250 sal_Bool bDisableDown = sal_True; 251 OutlinerView* pOLV = mpView->GetTextEditOutlinerView(); 252 253 if (mpView->ISA(OutlineView)) 254 { 255 pOLV = static_cast<OutlineView*>(mpView)->GetViewByWindow( 256 mpViewShell->GetActiveWindow()); 257 } 258 259 sal_Bool bOutlineViewSh = mpViewShell->ISA(OutlineViewShell); 260 261 if (pOLV && 262 ( pOLV->GetOutliner()->GetMode() == OUTLINERMODE_OUTLINEOBJECT || bOutlineViewSh ) ) 263 { 264 // Outliner im Gliederungsmodus 265 ::Outliner* pOutl = pOLV->GetOutliner(); 266 List* pList = pOLV->CreateSelectionList(); 267 Paragraph* pPara = (Paragraph*) pList->First(); 268 269 // #96539# find out if we are a OutlineView 270 sal_Bool bIsOutlineView(OUTLINERMODE_OUTLINEVIEW == pOLV->GetOutliner()->GetMode()); 271 272 // #96539# This is ONLY for OutlineViews 273 if(bIsOutlineView) 274 { 275 // #96250# and #78665# 276 // allow move up if position is 2 or greater OR it 277 // is a title object (and thus depth==1) 278 if(pOutl->GetAbsPos(pPara) > 1 || ( pOutl->HasParaFlag(pPara,PARAFLAG_ISPAGE) && pOutl->GetAbsPos(pPara) > 0 ) ) 279 { 280 // Nicht ganz oben 281 bDisableUp = sal_False; 282 } 283 } 284 else 285 { 286 // #96539# old behaviour for OUTLINERMODE_OUTLINEOBJECT 287 if(pOutl->GetAbsPos(pPara) > 0) 288 { 289 // Nicht ganz oben 290 bDisableUp = sal_False; 291 } 292 } 293 294 while (pPara) 295 { 296 sal_Int16 nDepth = pOutl->GetDepth( (sal_uInt16) pOutl->GetAbsPos( pPara ) ); 297 298 if (nDepth > 0 || (bOutlineViewSh && (nDepth <= 0) && !pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE )) ) 299 { 300 // Nicht minimale Tiefe 301 bDisableLeft = sal_False; 302 } 303 304 if( (nDepth < pOLV->GetOutliner()->GetMaxDepth() && ( !bOutlineViewSh || pOutl->GetAbsPos(pPara) != 0 )) || 305 (bOutlineViewSh && (nDepth <= 0) && pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE ) && pOutl->GetAbsPos(pPara) != 0) ) 306 { 307 // Nicht maximale Tiefe und nicht ganz oben 308 bDisableRight = sal_False; 309 } 310 311 pPara = static_cast<Paragraph*>( pList->Next() ); 312 } 313 314 if ( ( pOutl->GetAbsPos((Paragraph*) pList->Last()) < pOutl->GetParagraphCount() - 1 ) && 315 ( pOutl->GetParagraphCount() > 1 || !bOutlineViewSh) ) 316 { 317 // Nicht letzter Absatz 318 bDisableDown = sal_False; 319 } 320 321 // #96250# and #78665# 322 // disable when first para and 2nd is not a title 323 pPara = static_cast< Paragraph* >( pList->First() ); 324 if(!bDisableDown && bIsOutlineView 325 && pPara 326 && 0 == pOutl->GetAbsPos(pPara) 327 && pOutl->GetParagraphCount() > 1 328 && !pOutl->HasParaFlag( pOutl->GetParagraph(1), PARAFLAG_ISPAGE ) ) 329 { 330 // Needs to be disabled 331 bDisableDown = sal_True; 332 } 333 334 delete pList; 335 } 336 337 if (bDisableLeft) 338 rSet.DisableItem(SID_OUTLINE_LEFT); 339 if (bDisableRight) 340 rSet.DisableItem(SID_OUTLINE_RIGHT); 341 if (bDisableUp) 342 rSet.DisableItem(SID_OUTLINE_UP); 343 if (bDisableDown) 344 rSet.DisableItem(SID_OUTLINE_DOWN); 345 } 346 break; 347 348 case SID_TEXTDIRECTION_LEFT_TO_RIGHT: 349 case SID_TEXTDIRECTION_TOP_TO_BOTTOM: 350 { 351 if ( bDisableVerticalText ) 352 { 353 rSet.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT ); 354 rSet.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM ); 355 } 356 else 357 { 358 sal_Bool bLeftToRight = sal_True; 359 360 SdrOutliner* pOutl = mpView->GetTextEditOutliner(); 361 if( pOutl ) 362 { 363 if( pOutl->IsVertical() ) 364 bLeftToRight = sal_False; 365 } 366 else 367 bLeftToRight = ( (const SvxWritingModeItem&) aAttrSet.Get( SDRATTR_TEXTDIRECTION ) ).GetValue() == com::sun::star::text::WritingMode_LR_TB; 368 369 rSet.Put( SfxBoolItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT, bLeftToRight ) ); 370 rSet.Put( SfxBoolItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM, !bLeftToRight ) ); 371 372 if( !bLeftToRight ) 373 bDisableParagraphTextDirection = sal_True; 374 } 375 } 376 break; 377 378 case SID_GROW_FONT_SIZE: 379 case SID_SHRINK_FONT_SIZE: 380 { 381 // todo 382 } 383 break; 384 385 case SID_THES: 386 { 387 if( mpView && mpView->GetTextEditOutlinerView() ) 388 { 389 EditView & rEditView = mpView->GetTextEditOutlinerView()->GetEditView();; 390 String aStatusVal; 391 LanguageType nLang = LANGUAGE_NONE; 392 bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, rEditView ); 393 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) ); 394 395 // disable "Thesaurus" context menu entry if there is nothing to look up 396 lang::Locale aLocale( SvxCreateLocale( nLang ) ); 397 uno::Reference< linguistic2::XThesaurus > xThes( LinguMgr::GetThesaurus() ); 398 if (!bIsLookUpWord || 399 !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( aLocale )) 400 rSet.DisableItem( SID_THES ); 401 } 402 else 403 { 404 rSet.DisableItem( SID_THES ); 405 } 406 //! avoid puting the same item as SfxBoolItem at the end of this function 407 nSlotId = 0; 408 } 409 break; 410 411 default: 412 break; 413 } 414 415 nWhich = aIter.NextWhich(); 416 } 417 418 rSet.Put( aAttrSet, sal_False ); // <- sal_False, damit DontCare-Status uebernommen wird 419 420 421 // die sind im Gliederungsmodus disabled 422 if (!mpViewShell->ISA(DrawViewShell)) 423 { 424 rSet.DisableItem( SID_ATTR_PARA_ADJUST_LEFT ); 425 rSet.DisableItem( SID_ATTR_PARA_ADJUST_RIGHT ); 426 rSet.DisableItem( SID_ATTR_PARA_ADJUST_CENTER ); 427 rSet.DisableItem( SID_ATTR_PARA_ADJUST_BLOCK ); 428 rSet.DisableItem( SID_ATTR_PARA_LINESPACE_10 ); 429 rSet.DisableItem( SID_ATTR_PARA_LINESPACE_15 ); 430 rSet.DisableItem( SID_ATTR_PARA_LINESPACE_20 ); 431 rSet.DisableItem( SID_PARASPACE_INCREASE ); 432 rSet.DisableItem( SID_PARASPACE_DECREASE ); 433 rSet.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM ); 434 rSet.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT ); 435 rSet.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT ); 436 rSet.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT ); 437 } 438 else 439 { 440 // Absatzabstand 441 OutlinerView* pOLV = mpView->GetTextEditOutlinerView(); 442 if( pOLV ) 443 { 444 ESelection aSel = pOLV->GetSelection(); 445 aSel.Adjust(); 446 sal_uLong nStartPara = aSel.nStartPara; 447 sal_uLong nEndPara = aSel.nEndPara; 448 if( !aSel.HasRange() ) 449 { 450 nStartPara = 0; 451 nEndPara = pOLV->GetOutliner()->GetParagraphCount() - 1; 452 } 453 long nUpper = 0L; 454 for( sal_uLong nPara = nStartPara; nPara <= nEndPara; nPara++ ) 455 { 456 const SfxItemSet& rItems = pOLV->GetOutliner()->GetParaAttribs( (sal_uInt16)nPara ); 457 const SvxULSpaceItem& rItem = (const SvxULSpaceItem&) rItems.Get( EE_PARA_ULSPACE ); 458 nUpper = Max( nUpper, (long)rItem.GetUpper() ); 459 } 460 if( nUpper == 0L ) 461 rSet.DisableItem( SID_PARASPACE_DECREASE ); 462 } 463 else 464 { 465 // Wird zur Zeit nie disabled ! 466 //rSet.DisableItem( SID_PARASPACE_INCREASE ); 467 //rSet.DisableItem( SID_PARASPACE_DECREASE ); 468 } 469 470 // Absatzausrichtung 471 SvxAdjust eAdj = ( (const SvxAdjustItem&) aAttrSet.Get( EE_PARA_JUST ) ).GetAdjust(); 472 switch( eAdj ) 473 { 474 case SVX_ADJUST_LEFT: 475 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_LEFT, sal_True ) ); 476 break; 477 case SVX_ADJUST_CENTER: 478 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_CENTER, sal_True ) ); 479 break; 480 case SVX_ADJUST_RIGHT: 481 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_RIGHT, sal_True ) ); 482 break; 483 case SVX_ADJUST_BLOCK: 484 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_BLOCK, sal_True ) ); 485 break; 486 default: 487 break; 488 } 489 490 // paragraph text direction 491 if( bDisableParagraphTextDirection ) 492 { 493 rSet.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT ); 494 rSet.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT ); 495 } 496 else 497 { 498 switch( ( ( (SvxFrameDirectionItem&) aAttrSet.Get( EE_PARA_WRITINGDIR ) ) ).GetValue() ) 499 { 500 case FRMDIR_VERT_TOP_LEFT: 501 case FRMDIR_VERT_TOP_RIGHT: 502 { 503 rSet.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT ); 504 rSet.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT ); 505 } 506 break; 507 508 case FRMDIR_HORI_LEFT_TOP: 509 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT, sal_True ) ); 510 rSet.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT, sal_False ) ); 511 break; 512 513 case FRMDIR_HORI_RIGHT_TOP: 514 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT, sal_False ) ); 515 rSet.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT, sal_True ) ); 516 break; 517 518 // #107865# 519 // The case for the superordinate object is missing. 520 case FRMDIR_ENVIRONMENT: 521 { 522 SdDrawDocument* pDoc = mpView->GetDoc(); 523 ::com::sun::star::text::WritingMode eMode = pDoc->GetDefaultWritingMode(); 524 sal_Bool bIsLeftToRight(sal_False); 525 526 if(::com::sun::star::text::WritingMode_LR_TB == eMode 527 || ::com::sun::star::text::WritingMode_TB_RL == eMode) 528 { 529 bIsLeftToRight = sal_True; 530 } 531 532 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT, bIsLeftToRight ) ); 533 rSet.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT, !bIsLeftToRight ) ); 534 } 535 break; 536 } 537 } 538 539 /* #i35937# 540 if (aAttrSet.GetItemState(EE_PARA_BULLETSTATE) == SFX_ITEM_ON) 541 { 542 SfxUInt16Item aBulletState((const SfxUInt16Item&) aAttrSet.Get(EE_PARA_BULLETSTATE)); 543 544 if (aBulletState.GetValue() != 0) 545 { 546 rSet.Put(SfxBoolItem(FN_NUM_BULLET_ON, sal_True)); 547 } 548 else 549 { 550 rSet.Put(SfxBoolItem(FN_NUM_BULLET_ON, sal_False)); 551 } 552 } 553 */ 554 sal_uInt16 nLineSpace = (sal_uInt16) ( (const SvxLineSpacingItem&) aAttrSet. 555 Get( EE_PARA_SBL ) ).GetPropLineSpace(); 556 switch( nLineSpace ) 557 { 558 case 100: 559 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_10, sal_True ) ); 560 break; 561 case 150: 562 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_15, sal_True ) ); 563 break; 564 case 200: 565 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_20, sal_True ) ); 566 break; 567 } 568 } 569 570 // Ausrichtung (hoch/tief) wird auch im Gliederungsmodus gebraucht 571 SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&) 572 aAttrSet.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue(); 573 574 if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT ) 575 rSet.Put( SfxBoolItem( SID_SET_SUPER_SCRIPT, sal_True ) ); 576 else if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT ) 577 rSet.Put( SfxBoolItem( SID_SET_SUB_SCRIPT, sal_True ) ); 578 } 579 580 /************************************************************************* 581 |* 582 |* Command event 583 |* 584 \************************************************************************/ 585 586 void TextObjectBar::Command( const CommandEvent& ) 587 { 588 } 589 590 591 } // end of namespace sd 592