1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "TextObjectBar.hxx"
22 #include <svx/svxids.hrc>
24 #include <i18nlangtag/mslangid.hxx>
25 #include <editeng/ulspitem.hxx>
26 #include <editeng/lspcitem.hxx>
27 #include <editeng/adjustitem.hxx>
28 #include <editeng/editview.hxx>
29 #include <editeng/editeng.hxx>
30 #include <editeng/outliner.hxx>
31 #include <editeng/unolingu.hxx>
32 #include <editeng/kernitem.hxx>
33 #include <vcl/vclenum.hxx>
34 #include <sfx2/app.hxx>
35 #include <sfx2/request.hxx>
36 #include <svl/whiter.hxx>
37 #include <svl/itempool.hxx>
38 #include <svl/stritem.hxx>
39 #include <svl/style.hxx>
40 #include <svl/languageoptions.hxx>
41 #include <sfx2/tplpitem.hxx>
42 #include <editeng/escapementitem.hxx>
43 #include <svx/svdoutl.hxx>
44 #include <svl/intitem.hxx>
45 #include <editeng/scripttypeitem.hxx>
46 #include <editeng/outlobj.hxx>
47 #include <editeng/writingmodeitem.hxx>
48 #include <editeng/frmdiritem.hxx>
49 #include <editeng/fhgtitem.hxx>
51 #include <sfx2/objface.hxx>
55 #include "res_bmp.hrc"
57 #include "drawdoc.hxx"
58 #include "DrawViewShell.hxx"
59 #include "OutlineViewShell.hxx"
60 #include "ViewShellBase.hxx"
61 #include "ToolBarManager.hxx"
62 #include "futempl.hxx"
63 #include "sdresid.hxx"
65 #include "OutlineView.hxx"
68 using namespace ::com::sun::star
;
71 #include "sdslots.hxx"
76 * Declare default interface (Slotmap must not be empty, therefore enter
77 * something that (hopefully) never occurs.
79 SFX_IMPL_INTERFACE(TextObjectBar
, SfxShell
)
81 void TextObjectBar::InitInterface_Impl()
85 TYPEINIT1( TextObjectBar
, SfxShell
);
87 TextObjectBar::TextObjectBar (
89 SfxItemPool
& rItemPool
,
91 : SfxShell(pSdViewSh
->GetViewShell()),
92 mpViewShell( pSdViewSh
),
99 OutlineView
* pOutlinerView
= dynamic_cast< OutlineView
* >( mpView
);
102 SetUndoManager(&pOutlinerView
->GetOutliner().GetUndoManager());
106 DrawDocShell
* pDocShell
= mpView
->GetDoc().GetDocSh();
109 SetUndoManager(pDocShell
->GetUndoManager());
110 DrawViewShell
* pDrawViewShell
= dynamic_cast< DrawViewShell
* >( pSdViewSh
);
111 if ( pDrawViewShell
)
112 SetRepeatTarget(pSdView
);
117 SetName( OUString( "TextObjectBar" ));
119 // SetHelpId( SD_IF_SDDRAWTEXTOBJECTBAR );
122 TextObjectBar::~TextObjectBar()
124 SetRepeatTarget(NULL
);
127 void TextObjectBar::GetCharState( SfxItemSet
& rSet
)
129 SfxItemSet
aCharAttrSet( mpView
->GetDoc().GetPool() );
130 mpView
->GetAttributes( aCharAttrSet
);
132 SfxItemSet
aNewAttr( mpViewShell
->GetPool(),EE_ITEMS_START
,EE_ITEMS_END
);
134 aNewAttr
.Put(aCharAttrSet
, false);
135 rSet
.Put(aNewAttr
, false);
137 SvxKerningItem aKern
= static_cast<const SvxKerningItem
&>( aCharAttrSet
.Get( EE_CHAR_KERNING
) );
138 //aKern.SetWhich(SID_ATTR_CHAR_KERNING);
141 SfxItemState eState
= aCharAttrSet
.GetItemState( EE_CHAR_KERNING
, true );
142 if ( eState
== SfxItemState::DONTCARE
)
144 rSet
.InvalidateItem(EE_CHAR_KERNING
);
149 * Status of attribute items.
151 void TextObjectBar::GetAttrState( SfxItemSet
& rSet
)
153 SfxWhichIter
aIter( rSet
);
154 sal_uInt16 nWhich
= aIter
.FirstWhich();
155 SfxItemSet
aAttrSet( mpView
->GetDoc().GetPool() );
156 SvtLanguageOptions aLangOpt
;
157 bool bDisableParagraphTextDirection
= !aLangOpt
.IsCTLFontEnabled();
158 bool bDisableVerticalText
= !aLangOpt
.IsVerticalTextEnabled();
160 mpView
->GetAttributes( aAttrSet
);
164 sal_uInt16 nSlotId
= SfxItemPool::IsWhich(nWhich
)
165 ? GetPool().GetSlotId(nWhich
)
170 case SID_ATTR_CHAR_FONT
:
171 case SID_ATTR_CHAR_FONTHEIGHT
:
172 case SID_ATTR_CHAR_WEIGHT
:
173 case SID_ATTR_CHAR_POSTURE
:
174 case SID_ATTR_CHAR_SHADOWED
:
175 case SID_ATTR_CHAR_STRIKEOUT
:
177 sal_uInt16 stretchX
= 100;
178 sal_uInt16 stretchY
= 100;
179 SvxScriptSetItem
aSetItem( nSlotId
, GetPool() );
180 aSetItem
.GetItemSet().Put( aAttrSet
, false );
182 SvtScriptType nScriptType
= mpView
->GetScriptType();
184 if( (nSlotId
== SID_ATTR_CHAR_FONT
) || (nSlotId
== SID_ATTR_CHAR_FONTHEIGHT
) )
186 // input language should be preferred over
187 // current cursor position to detect script type
188 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
189 SdrOutliner
*pOutliner
= mpView
->GetTextEditOutliner();
191 if (mpView
->ISA(OutlineView
))
193 pOLV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
194 mpViewShell
->GetActiveWindow());
198 pOutliner
->GetGlobalCharStretching( stretchX
, stretchY
);
200 if(pOLV
&& !pOLV
->GetSelection().HasRange())
202 if( mpViewShell
&& mpViewShell
->GetViewShell() && mpViewShell
->GetViewShell()->GetWindow() )
204 LanguageType nInputLang
= mpViewShell
->GetViewShell()->GetWindow()->GetInputLanguage();
205 if(nInputLang
!= LANGUAGE_DONTKNOW
&& nInputLang
!= LANGUAGE_SYSTEM
)
206 nScriptType
= SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang
);
211 const SfxPoolItem
* pI
= aSetItem
.GetItemOfScript( nScriptType
);
214 if( nSlotId
== SID_ATTR_CHAR_FONTHEIGHT
)
216 SvxFontHeightItem aFontItem
= dynamic_cast<const SvxFontHeightItem
&>(*pI
);
217 aFontItem
.SetHeight(aFontItem
.GetHeight(), stretchX
, aFontItem
.GetPropUnit());
218 aAttrSet
.Put( aFontItem
, nWhich
);
222 aAttrSet
.Put( *pI
, nWhich
);
227 aAttrSet
.InvalidateItem( nWhich
);
232 case SID_STYLE_APPLY
:
233 case SID_STYLE_FAMILY2
:
235 SfxStyleSheet
* pStyleSheet
= mpView
->GetStyleSheetFromMarked();
237 rSet
.Put( SfxTemplateItem( nWhich
, pStyleSheet
->GetName() ) );
240 rSet
.Put( SfxTemplateItem( nWhich
, OUString() ) );
245 case SID_OUTLINE_LEFT
:
246 case SID_OUTLINE_RIGHT
:
248 case SID_OUTLINE_DOWN
:
250 bool bDisableLeft
= true;
251 bool bDisableRight
= true;
252 bool bDisableUp
= true;
253 bool bDisableDown
= true;
255 //fdo#78151 it doesn't make sense to promote or demote outline levels in master view.
256 const DrawViewShell
* pDrawViewShell
= dynamic_cast< DrawViewShell
* >(mpViewShell
);
257 const bool bInMasterView
= pDrawViewShell
&& pDrawViewShell
->GetEditMode() == EM_MASTERPAGE
;
261 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
263 if (mpView
->ISA(OutlineView
))
265 pOLV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
266 mpViewShell
->GetActiveWindow());
269 bool bOutlineViewSh
= mpViewShell
->ISA(OutlineViewShell
);
272 ( pOLV
->GetOutliner()->GetMode() == OUTLINERMODE_OUTLINEOBJECT
|| bOutlineViewSh
) )
274 // Outliner at outline-mode
275 ::Outliner
* pOutl
= pOLV
->GetOutliner();
277 std::vector
<Paragraph
*> aSelList
;
278 pOLV
->CreateSelectionList(aSelList
);
279 Paragraph
* pPara
= aSelList
.empty() ? NULL
: *(aSelList
.begin());
281 // find out if we are a OutlineView
282 bool bIsOutlineView(OUTLINERMODE_OUTLINEVIEW
== pOLV
->GetOutliner()->GetMode());
284 // This is ONLY for OutlineViews
287 // allow move up if position is 2 or greater OR it
288 // is a title object (and thus depth==1)
289 if(pOutl
->GetAbsPos(pPara
) > 1 || ( ::Outliner::HasParaFlag(pPara
,ParaFlag::ISPAGE
) && pOutl
->GetAbsPos(pPara
) > 0 ) )
297 // old behaviour for OUTLINERMODE_OUTLINEOBJECT
298 if(pOutl
->GetAbsPos(pPara
) > 0)
305 for (std::vector
<Paragraph
*>::const_iterator iter
= aSelList
.begin(); iter
!= aSelList
.end(); ++iter
)
309 sal_Int16 nDepth
= pOutl
->GetDepth( pOutl
->GetAbsPos( pPara
) );
311 if (nDepth
> 0 || (bOutlineViewSh
&& (nDepth
<= 0) && !::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
)) )
314 bDisableLeft
= false;
317 if( (nDepth
< pOLV
->GetOutliner()->GetMaxDepth() && ( !bOutlineViewSh
|| pOutl
->GetAbsPos(pPara
) != 0 )) ||
318 (bOutlineViewSh
&& (nDepth
<= 0) && ::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
) && pOutl
->GetAbsPos(pPara
) != 0) )
320 // not maximum depth and not at top
321 bDisableRight
= false;
325 if ( ( pOutl
->GetAbsPos(pPara
) < pOutl
->GetParagraphCount() - 1 ) &&
326 ( pOutl
->GetParagraphCount() > 1 || !bOutlineViewSh
) )
328 // not last paragraph
329 bDisableDown
= false;
332 // disable when first para and 2nd is not a title
333 pPara
= aSelList
.empty() ? NULL
: *(aSelList
.begin());
335 if(!bDisableDown
&& bIsOutlineView
337 && 0 == pOutl
->GetAbsPos(pPara
)
338 && pOutl
->GetParagraphCount() > 1
339 && !::Outliner::HasParaFlag( pOutl
->GetParagraph(1), ParaFlag::ISPAGE
) )
341 // Needs to be disabled
348 rSet
.DisableItem(SID_OUTLINE_LEFT
);
350 rSet
.DisableItem(SID_OUTLINE_RIGHT
);
352 rSet
.DisableItem(SID_OUTLINE_UP
);
354 rSet
.DisableItem(SID_OUTLINE_DOWN
);
358 case SID_TEXTDIRECTION_LEFT_TO_RIGHT
:
359 case SID_TEXTDIRECTION_TOP_TO_BOTTOM
:
361 if ( bDisableVerticalText
)
363 rSet
.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT
);
364 rSet
.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM
);
368 bool bLeftToRight
= true;
370 SdrOutliner
* pOutl
= mpView
->GetTextEditOutliner();
373 if( pOutl
->IsVertical() )
374 bLeftToRight
= false;
377 bLeftToRight
= static_cast<const SvxWritingModeItem
&>( aAttrSet
.Get( SDRATTR_TEXTDIRECTION
) ).GetValue() == com::sun::star::text::WritingMode_LR_TB
;
379 rSet
.Put( SfxBoolItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT
, bLeftToRight
) );
380 rSet
.Put( SfxBoolItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM
, !bLeftToRight
) );
383 bDisableParagraphTextDirection
= true;
388 case SID_GROW_FONT_SIZE
:
389 case SID_SHRINK_FONT_SIZE
:
397 if (mpView
->GetTextEditOutlinerView())
399 EditView
& rEditView
= mpView
->GetTextEditOutlinerView()->GetEditView();
401 LanguageType nLang
= LANGUAGE_NONE
;
402 bool bIsLookUpWord
= GetStatusValueForThesaurusFromContext( aStatusVal
, nLang
, rEditView
);
403 rSet
.Put( SfxStringItem( SID_THES
, aStatusVal
) );
405 // disable "Thesaurus" context menu entry if there is nothing to look up
406 uno::Reference
< linguistic2::XThesaurus
> xThes( LinguMgr::GetThesaurus() );
407 if (!bIsLookUpWord
||
408 !xThes
.is() || nLang
== LANGUAGE_NONE
|| !xThes
->hasLocale( LanguageTag( nLang
). getLocale() ))
409 rSet
.DisableItem( SID_THES
);
413 rSet
.DisableItem( SID_THES
);
415 //! avoid putting the same item as SfxBoolItem at the end of this function
424 nWhich
= aIter
.NextWhich();
427 rSet
.Put( aAttrSet
, false ); // <- sal_False, so DontCare-Status gets acquired
429 // these are disabled in outline-mode
430 if (!mpViewShell
|| !mpViewShell
->ISA(DrawViewShell
))
432 rSet
.DisableItem( SID_ATTR_PARA_ADJUST_LEFT
);
433 rSet
.DisableItem( SID_ATTR_PARA_ADJUST_RIGHT
);
434 rSet
.DisableItem( SID_ATTR_PARA_ADJUST_CENTER
);
435 rSet
.DisableItem( SID_ATTR_PARA_ADJUST_BLOCK
);
436 rSet
.DisableItem( SID_ATTR_PARA_LINESPACE_10
);
437 rSet
.DisableItem( SID_ATTR_PARA_LINESPACE_15
);
438 rSet
.DisableItem( SID_ATTR_PARA_LINESPACE_20
);
439 rSet
.DisableItem( SID_PARASPACE_INCREASE
);
440 rSet
.DisableItem( SID_PARASPACE_DECREASE
);
441 rSet
.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM
);
442 rSet
.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT
);
443 rSet
.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT
);
444 rSet
.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT
);
449 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
452 ESelection aSel
= pOLV
->GetSelection();
454 sal_Int32 nStartPara
= aSel
.nStartPara
;
455 sal_Int32 nEndPara
= aSel
.nEndPara
;
456 if( !aSel
.HasRange() )
459 nEndPara
= pOLV
->GetOutliner()->GetParagraphCount() - 1;
462 for( sal_Int32 nPara
= nStartPara
; nPara
<= nEndPara
; nPara
++ )
464 const SfxItemSet
& rItems
= pOLV
->GetOutliner()->GetParaAttribs( nPara
);
465 const SvxULSpaceItem
& rItem
= static_cast<const SvxULSpaceItem
&>( rItems
.Get( EE_PARA_ULSPACE
) );
466 nUpper
= std::max( nUpper
, (long)rItem
.GetUpper() );
469 rSet
.DisableItem( SID_PARASPACE_DECREASE
);
473 // never disabled at the moment!
474 //rSet.DisableItem( SID_PARASPACE_INCREASE );
475 //rSet.DisableItem( SID_PARASPACE_DECREASE );
478 // paragraph justification
479 SvxLRSpaceItem aLR
= static_cast<const SvxLRSpaceItem
&>( aAttrSet
.Get( EE_PARA_LRSPACE
) );
481 SvxAdjust eAdj
= static_cast<const SvxAdjustItem
&>( aAttrSet
.Get( EE_PARA_JUST
) ).GetAdjust();
484 case SVX_ADJUST_LEFT
:
485 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_LEFT
, true ) );
487 case SVX_ADJUST_CENTER
:
488 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_CENTER
, true ) );
490 case SVX_ADJUST_RIGHT
:
491 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_RIGHT
, true ) );
493 case SVX_ADJUST_BLOCK
:
494 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_BLOCK
, true ) );
500 Invalidate(SID_ATTR_PARA_ADJUST_LEFT
);
501 Invalidate(SID_ATTR_PARA_ADJUST_CENTER
);
502 Invalidate(SID_ATTR_PARA_ADJUST_RIGHT
);
503 Invalidate(SID_ATTR_PARA_ADJUST_BLOCK
);
504 Invalidate(SID_ATTR_PARA_LINESPACE
);
505 Invalidate(SID_ATTR_PARA_ULSPACE
);
507 // paragraph text direction
508 if( bDisableParagraphTextDirection
)
510 rSet
.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT
);
511 rSet
.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT
);
515 switch( static_cast<const SvxFrameDirectionItem
&>( aAttrSet
.Get( EE_PARA_WRITINGDIR
) ).GetValue() )
517 case FRMDIR_VERT_TOP_LEFT
:
518 case FRMDIR_VERT_TOP_RIGHT
:
520 rSet
.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT
);
521 rSet
.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT
);
525 case FRMDIR_HORI_LEFT_TOP
:
526 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT
, true ) );
527 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT
, false ) );
530 case FRMDIR_HORI_RIGHT_TOP
:
531 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT
, false ) );
532 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT
, true ) );
535 // The case for the superordinate object is missing.
536 case FRMDIR_ENVIRONMENT
:
538 SdDrawDocument
& rDoc
= mpView
->GetDoc();
539 ::com::sun::star::text::WritingMode eMode
= rDoc
.GetDefaultWritingMode();
540 bool bIsLeftToRight(false);
542 if(::com::sun::star::text::WritingMode_LR_TB
== eMode
543 || ::com::sun::star::text::WritingMode_TB_RL
== eMode
)
545 bIsLeftToRight
= true;
548 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT
, bIsLeftToRight
) );
549 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT
, !bIsLeftToRight
) );
555 SvxLRSpaceItem aLRSpace
= static_cast<const SvxLRSpaceItem
&>( aAttrSet
.Get( EE_PARA_LRSPACE
) );
556 aLRSpace
.SetWhich(SID_ATTR_PARA_LRSPACE
);
558 Invalidate(SID_ATTR_PARA_LRSPACE
);
560 SfxItemState eState
= aAttrSet
.GetItemState( EE_PARA_LRSPACE
);
561 if ( eState
== SfxItemState::DONTCARE
)
563 rSet
.InvalidateItem(EE_PARA_LRSPACE
);
564 rSet
.InvalidateItem(SID_ATTR_PARA_LRSPACE
);
566 sal_uInt16 nLineSpace
= (sal_uInt16
) static_cast<const SvxLineSpacingItem
&>( aAttrSet
.
567 Get( EE_PARA_SBL
) ).GetPropLineSpace();
571 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_10
, true ) );
574 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_15
, true ) );
577 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_20
, true ) );
582 // justification (superscript, subscript) is also needed in outline-mode
583 SvxEscapement eEsc
= (SvxEscapement
) static_cast<const SvxEscapementItem
&>(
584 aAttrSet
.Get( EE_CHAR_ESCAPEMENT
) ).GetEnumValue();
586 if( eEsc
== SVX_ESCAPEMENT_SUPERSCRIPT
)
587 rSet
.Put( SfxBoolItem( SID_SET_SUPER_SCRIPT
, true ) );
588 else if( eEsc
== SVX_ESCAPEMENT_SUBSCRIPT
)
589 rSet
.Put( SfxBoolItem( SID_SET_SUB_SCRIPT
, true ) );
592 } // end of namespace sd
594 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */