1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drtxtob.cxx,v $
10 * $Revision: 1.28.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "TextObjectBar.hxx"
37 #include <svx/ulspitem.hxx>
38 #include <svx/lspcitem.hxx>
39 #include <svx/adjitem.hxx>
40 #include <vcl/vclenum.hxx>
41 #include <sfx2/app.hxx>
42 #include <svtools/whiter.hxx>
43 #include <svtools/itempool.hxx>
44 #include <svtools/style.hxx>
45 #include <svtools/languageoptions.hxx>
46 #include <sfx2/tplpitem.hxx>
47 #include <svx/escpitem.hxx>
48 #include <svx/svdoutl.hxx>
49 #include <svtools/intitem.hxx>
50 #include <svx/scripttypeitem.hxx>
51 #include <svx/outlobj.hxx>
52 #include <svx/writingmodeitem.hxx>
53 #include <svx/frmdiritem.hxx>
56 #include <sfx2/objface.hxx>
60 #include "res_bmp.hrc"
64 #include "drawdoc.hxx"
65 #include "DrawViewShell.hxx"
66 #include "OutlineViewShell.hxx"
67 #include "ViewShellBase.hxx"
68 #include "ToolBarManager.hxx"
69 #include "futempl.hxx"
70 #include "sdresid.hxx"
72 #include "OutlineView.hxx"
77 #include "sdslots.hxx"
81 /*************************************************************************
83 |* Standardinterface deklarieren (Die Slotmap darf nicht leer sein, also
84 |* tragen wir etwas ein, was hier (hoffentlich) nie vorkommt).
86 \************************************************************************/
89 SFX_IMPL_INTERFACE( TextObjectBar
, SfxShell
, SdResId(STR_TEXTOBJECTBARSHELL
) )
93 TYPEINIT1( TextObjectBar
, SfxShell
);
95 /*************************************************************************
97 |* Standard-Konstruktor
99 \************************************************************************/
101 TextObjectBar::TextObjectBar (
102 ViewShell
* pSdViewSh
,
103 SfxItemPool
& rItemPool
,
104 ::sd::View
* pSdView
)
105 : SfxShell(pSdViewSh
->GetViewShell()),
106 mpViewShell( pSdViewSh
),
113 OutlineView
* pOutlinerView
= dynamic_cast< OutlineView
* >( mpView
);
116 SetUndoManager(&pOutlinerView
->GetOutliner()->GetUndoManager());
120 SdDrawDocument
* pDoc
= mpView
->GetDoc();
123 DrawDocShell
* pDocShell
= pDoc
->GetDocSh();
126 SetUndoManager(pDocShell
->GetUndoManager());
127 DrawViewShell
* pDrawViewShell
= dynamic_cast< DrawViewShell
* >( pSdViewSh
);
128 if ( pDrawViewShell
)
129 SetRepeatTarget(pSdView
);
135 SetName( String( RTL_CONSTASCII_USTRINGPARAM( "TextObjectBar" )));
137 // SetHelpId( SD_IF_SDDRAWTEXTOBJECTBAR );
140 /*************************************************************************
144 \************************************************************************/
146 TextObjectBar::~TextObjectBar()
148 SetRepeatTarget(NULL
);
151 /*************************************************************************
153 |* Status der Attribut-Items
155 \************************************************************************/
157 void TextObjectBar::GetAttrState( SfxItemSet
& rSet
)
159 SfxWhichIter
aIter( rSet
);
160 USHORT nWhich
= aIter
.FirstWhich();
161 BOOL bTemplate
= FALSE
;
162 SfxItemSet
aAttrSet( mpView
->GetDoc()->GetPool() );
163 SvtLanguageOptions aLangOpt
;
164 sal_Bool bDisableParagraphTextDirection
= !aLangOpt
.IsCTLFontEnabled();
165 sal_Bool bDisableVerticalText
= !aLangOpt
.IsVerticalTextEnabled();
167 mpView
->GetAttributes( aAttrSet
);
171 USHORT nSlotId
= SfxItemPool::IsWhich(nWhich
)
172 ? GetPool().GetSlotId(nWhich
)
177 case SID_ATTR_CHAR_FONT
:
178 case SID_ATTR_CHAR_FONTHEIGHT
:
179 case SID_ATTR_CHAR_WEIGHT
:
180 case SID_ATTR_CHAR_POSTURE
:
182 SvxScriptSetItem
aSetItem( nSlotId
, GetPool() );
183 aSetItem
.GetItemSet().Put( aAttrSet
, FALSE
);
185 USHORT nScriptType
= mpView
->GetScriptType();
187 if( (nSlotId
== SID_ATTR_CHAR_FONT
) || (nSlotId
== SID_ATTR_CHAR_FONTHEIGHT
) )
189 // #42732# input language should be preferred over
190 // current cursor position to detect script type
191 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
193 if (mpView
->ISA(OutlineView
))
195 pOLV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
196 mpViewShell
->GetActiveWindow());
199 if(pOLV
&& !pOLV
->GetSelection().HasRange())
201 if( mpViewShell
&& mpViewShell
->GetViewShell() && mpViewShell
->GetViewShell()->GetWindow() )
203 LanguageType nInputLang
= mpViewShell
->GetViewShell()->GetWindow()->GetInputLanguage();
204 if(nInputLang
!= LANGUAGE_DONTKNOW
&& nInputLang
!= LANGUAGE_SYSTEM
)
205 nScriptType
= SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang
);
210 const SfxPoolItem
* pI
= aSetItem
.GetItemOfScript( nScriptType
);
212 aAttrSet
.Put( *pI
, nWhich
);
214 aAttrSet
.InvalidateItem( nWhich
);
219 case SID_STYLE_APPLY
:
220 case SID_STYLE_FAMILY2
:
222 SfxStyleSheet
* pStyleSheet
= mpView
->GetStyleSheetFromMarked();
224 rSet
.Put( SfxTemplateItem( nWhich
, pStyleSheet
->GetName() ) );
227 rSet
.Put( SfxTemplateItem( nWhich
, String() ) );
233 case SID_OUTLINE_LEFT
:
234 case SID_OUTLINE_RIGHT
:
236 case SID_OUTLINE_DOWN
:
238 BOOL bDisableLeft
= TRUE
;
239 BOOL bDisableRight
= TRUE
;
240 BOOL bDisableUp
= TRUE
;
241 BOOL bDisableDown
= TRUE
;
242 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
244 if (mpView
->ISA(OutlineView
))
246 pOLV
= static_cast<OutlineView
*>(mpView
)->GetViewByWindow(
247 mpViewShell
->GetActiveWindow());
250 BOOL bOutlineViewSh
= mpViewShell
->ISA(OutlineViewShell
);
253 ( pOLV
->GetOutliner()->GetMode() == OUTLINERMODE_OUTLINEOBJECT
|| bOutlineViewSh
) )
255 // Outliner im Gliederungsmodus
256 ::Outliner
* pOutl
= pOLV
->GetOutliner();
257 List
* pList
= pOLV
->CreateSelectionList();
258 Paragraph
* pPara
= (Paragraph
*) pList
->First();
260 // #96539# find out if we are a OutlineView
261 BOOL
bIsOutlineView(OUTLINERMODE_OUTLINEVIEW
== pOLV
->GetOutliner()->GetMode());
263 // #96539# This is ONLY for OutlineViews
266 // #96250# and #78665#
267 // allow move up if position is 2 or greater OR it
268 // is a title object (and thus depth==1)
269 if(pOutl
->GetAbsPos(pPara
) > 1 || ( pOutl
->HasParaFlag(pPara
,PARAFLAG_ISPAGE
) && pOutl
->GetAbsPos(pPara
) > 0 ) )
277 // #96539# old behaviour for OUTLINERMODE_OUTLINEOBJECT
278 if(pOutl
->GetAbsPos(pPara
) > 0)
287 sal_Int16 nDepth
= pOutl
->GetDepth( (USHORT
) pOutl
->GetAbsPos( pPara
) );
289 if (nDepth
> 0 || (bOutlineViewSh
&& (nDepth
<= 0) && !pOutl
->HasParaFlag( pPara
, PARAFLAG_ISPAGE
)) )
291 // Nicht minimale Tiefe
292 bDisableLeft
= FALSE
;
295 if( (nDepth
< pOLV
->GetOutliner()->GetMaxDepth() && ( !bOutlineViewSh
|| pOutl
->GetAbsPos(pPara
) != 0 )) ||
296 (bOutlineViewSh
&& (nDepth
<= 0) && pOutl
->HasParaFlag( pPara
, PARAFLAG_ISPAGE
) && pOutl
->GetAbsPos(pPara
) != 0) )
298 // Nicht maximale Tiefe und nicht ganz oben
299 bDisableRight
= FALSE
;
302 pPara
= static_cast<Paragraph
*>( pList
->Next() );
305 if ( ( pOutl
->GetAbsPos((Paragraph
*) pList
->Last()) < pOutl
->GetParagraphCount() - 1 ) &&
306 ( pOutl
->GetParagraphCount() > 1 || !bOutlineViewSh
) )
308 // Nicht letzter Absatz
309 bDisableDown
= FALSE
;
312 // #96250# and #78665#
313 // disable when first para and 2nd is not a title
314 pPara
= static_cast< Paragraph
* >( pList
->First() );
315 if(!bDisableDown
&& bIsOutlineView
317 && 0 == pOutl
->GetAbsPos(pPara
)
318 && pOutl
->GetParagraphCount() > 1
319 && !pOutl
->HasParaFlag( pOutl
->GetParagraph(1), PARAFLAG_ISPAGE
) )
321 // Needs to be disabled
329 rSet
.DisableItem(SID_OUTLINE_LEFT
);
331 rSet
.DisableItem(SID_OUTLINE_RIGHT
);
333 rSet
.DisableItem(SID_OUTLINE_UP
);
335 rSet
.DisableItem(SID_OUTLINE_DOWN
);
339 case SID_TEXTDIRECTION_LEFT_TO_RIGHT
:
340 case SID_TEXTDIRECTION_TOP_TO_BOTTOM
:
342 if ( bDisableVerticalText
)
344 rSet
.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT
);
345 rSet
.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM
);
349 BOOL bLeftToRight
= TRUE
;
351 SdrOutliner
* pOutl
= mpView
->GetTextEditOutliner();
354 if( pOutl
->IsVertical() )
355 bLeftToRight
= FALSE
;
358 bLeftToRight
= ( (const SvxWritingModeItem
&) aAttrSet
.Get( SDRATTR_TEXTDIRECTION
) ).GetValue() == com::sun::star::text::WritingMode_LR_TB
;
360 rSet
.Put( SfxBoolItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT
, bLeftToRight
) );
361 rSet
.Put( SfxBoolItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM
, !bLeftToRight
) );
364 bDisableParagraphTextDirection
= sal_True
;
369 case SID_GROW_FONT_SIZE
:
370 case SID_SHRINK_FONT_SIZE
:
380 nWhich
= aIter
.NextWhich();
383 rSet
.Put( aAttrSet
, FALSE
); // <- FALSE, damit DontCare-Status uebernommen wird
386 // die sind im Gliederungsmodus disabled
387 if (!mpViewShell
->ISA(DrawViewShell
))
389 rSet
.DisableItem( SID_ATTR_PARA_ADJUST_LEFT
);
390 rSet
.DisableItem( SID_ATTR_PARA_ADJUST_RIGHT
);
391 rSet
.DisableItem( SID_ATTR_PARA_ADJUST_CENTER
);
392 rSet
.DisableItem( SID_ATTR_PARA_ADJUST_BLOCK
);
393 rSet
.DisableItem( SID_ATTR_PARA_LINESPACE_10
);
394 rSet
.DisableItem( SID_ATTR_PARA_LINESPACE_15
);
395 rSet
.DisableItem( SID_ATTR_PARA_LINESPACE_20
);
396 rSet
.DisableItem( SID_PARASPACE_INCREASE
);
397 rSet
.DisableItem( SID_PARASPACE_DECREASE
);
398 rSet
.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM
);
399 rSet
.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT
);
400 rSet
.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT
);
401 rSet
.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT
);
406 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
409 ESelection aSel
= pOLV
->GetSelection();
411 ULONG nStartPara
= aSel
.nStartPara
;
412 ULONG nEndPara
= aSel
.nEndPara
;
413 if( !aSel
.HasRange() )
416 nEndPara
= pOLV
->GetOutliner()->GetParagraphCount() - 1;
419 for( ULONG nPara
= nStartPara
; nPara
<= nEndPara
; nPara
++ )
421 const SfxItemSet
& rItems
= pOLV
->GetOutliner()->GetParaAttribs( (USHORT
)nPara
);
422 const SvxULSpaceItem
& rItem
= (const SvxULSpaceItem
&) rItems
.Get( EE_PARA_ULSPACE
);
423 nUpper
= Max( nUpper
, (long)rItem
.GetUpper() );
426 rSet
.DisableItem( SID_PARASPACE_DECREASE
);
430 // Wird zur Zeit nie disabled !
431 //rSet.DisableItem( SID_PARASPACE_INCREASE );
432 //rSet.DisableItem( SID_PARASPACE_DECREASE );
436 SvxAdjust eAdj
= ( (const SvxAdjustItem
&) aAttrSet
.Get( EE_PARA_JUST
) ).GetAdjust();
439 case SVX_ADJUST_LEFT
:
440 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_LEFT
, TRUE
) );
442 case SVX_ADJUST_CENTER
:
443 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_CENTER
, TRUE
) );
445 case SVX_ADJUST_RIGHT
:
446 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_RIGHT
, TRUE
) );
448 case SVX_ADJUST_BLOCK
:
449 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_BLOCK
, TRUE
) );
455 // paragraph text direction
456 if( bDisableParagraphTextDirection
)
458 rSet
.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT
);
459 rSet
.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT
);
463 switch( ( ( (SvxFrameDirectionItem
&) aAttrSet
.Get( EE_PARA_WRITINGDIR
) ) ).GetValue() )
465 case FRMDIR_VERT_TOP_LEFT
:
466 case FRMDIR_VERT_TOP_RIGHT
:
468 rSet
.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT
);
469 rSet
.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT
);
473 case FRMDIR_HORI_LEFT_TOP
:
474 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT
, TRUE
) );
475 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT
, FALSE
) );
478 case FRMDIR_HORI_RIGHT_TOP
:
479 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT
, FALSE
) );
480 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT
, TRUE
) );
484 // The case for the superordinate object is missing.
485 case FRMDIR_ENVIRONMENT
:
487 SdDrawDocument
* pDoc
= mpView
->GetDoc();
488 ::com::sun::star::text::WritingMode eMode
= pDoc
->GetDefaultWritingMode();
489 sal_Bool
bIsLeftToRight(sal_False
);
491 if(::com::sun::star::text::WritingMode_LR_TB
== eMode
492 || ::com::sun::star::text::WritingMode_TB_RL
== eMode
)
494 bIsLeftToRight
= sal_True
;
497 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT
, bIsLeftToRight
) );
498 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT
, !bIsLeftToRight
) );
505 if (aAttrSet.GetItemState(EE_PARA_BULLETSTATE) == SFX_ITEM_ON)
507 SfxUInt16Item aBulletState((const SfxUInt16Item&) aAttrSet.Get(EE_PARA_BULLETSTATE));
509 if (aBulletState.GetValue() != 0)
511 rSet.Put(SfxBoolItem(FN_NUM_BULLET_ON, TRUE));
515 rSet.Put(SfxBoolItem(FN_NUM_BULLET_ON, FALSE));
519 USHORT nLineSpace
= (USHORT
) ( (const SvxLineSpacingItem
&) aAttrSet
.
520 Get( EE_PARA_SBL
) ).GetPropLineSpace();
524 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_10
, TRUE
) );
527 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_15
, TRUE
) );
530 rSet
.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_20
, TRUE
) );
535 // Ausrichtung (hoch/tief) wird auch im Gliederungsmodus gebraucht
536 SvxEscapement eEsc
= (SvxEscapement
) ( (const SvxEscapementItem
&)
537 aAttrSet
.Get( EE_CHAR_ESCAPEMENT
) ).GetEnumValue();
539 if( eEsc
== SVX_ESCAPEMENT_SUPERSCRIPT
)
540 rSet
.Put( SfxBoolItem( SID_SET_SUPER_SCRIPT
, TRUE
) );
541 else if( eEsc
== SVX_ESCAPEMENT_SUBSCRIPT
)
542 rSet
.Put( SfxBoolItem( SID_SET_SUB_SCRIPT
, TRUE
) );
545 /*************************************************************************
549 \************************************************************************/
551 void TextObjectBar::Command( const CommandEvent
& )
556 } // end of namespace sd