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