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: drtxtob1.cxx,v $
10 * $Revision: 1.32.72.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/outliner.hxx>
39 #include <svx/ulspitem.hxx>
42 #include <svx/lspcitem.hxx>
45 #include <svx/adjitem.hxx>
47 #include <vcl/vclenum.hxx>
48 #include <sfx2/app.hxx>
49 #include <svtools/whiter.hxx>
50 #include <svtools/itempool.hxx>
51 #include <svtools/style.hxx>
52 #include <sfx2/tplpitem.hxx>
53 #include <sfx2/request.hxx>
54 #include <sfx2/viewfrm.hxx>
55 #include <sfx2/dispatch.hxx>
56 #include <svx/escpitem.hxx>
57 #include <svx/wghtitem.hxx>
58 #include <svx/postitem.hxx>
59 #include <svx/udlnitem.hxx>
60 #include <svx/crsditem.hxx>
61 #include <svx/cntritem.hxx>
62 #include <svx/shdditem.hxx>
63 #include <svx/xtable.hxx>
64 #include <svx/svdobj.hxx>
65 #include <svx/outlobj.hxx>
66 #include <svx/flstitem.hxx>
67 #include <svx/editeng.hxx>
68 #include <svtools/intitem.hxx>
69 #ifndef _SVX_SRIPTTYPEITEM_HXX //autogen
70 #include <svx/scripttypeitem.hxx>
72 #include <svx/svdoutl.hxx>
73 #include <svx/writingmodeitem.hxx>
74 #include <svx/frmdiritem.hxx>
75 #include <svtools/itemiter.hxx>
81 #include "ViewShell.hxx"
82 #include "drawview.hxx"
83 #include "drawdoc.hxx"
84 #include "OutlineView.hxx"
86 #include "futempl.hxx"
87 #include "DrawDocShell.hxx"
88 #include "Outliner.hxx"
93 /*************************************************************************
95 |* Bearbeitung der SfxRequests
97 \************************************************************************/
99 void TextObjectBar::Execute( SfxRequest
&rReq
)
101 const SfxItemSet
* pArgs
= rReq
.GetArgs();
102 const SfxPoolItem
* pPoolItem
= NULL
;
103 USHORT nSlot
= rReq
.GetSlot();
104 BOOL bOutlineMode
= FALSE
;
105 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
107 std::auto_ptr
< OutlineViewModelChangeGuard
> aGuard
;
109 if (mpView
->ISA(OutlineView
))
112 pOLV
= static_cast<OutlineView
*>(mpView
)
113 ->GetViewByWindow(mpViewShell
->GetActiveWindow());
115 aGuard
.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView
&>(*mpView
) ) );
120 case SID_STYLE_APPLY
:
124 SdDrawDocument
* pDoc
= mpView
->GetDoc();
125 OSL_ASSERT (mpViewShell
->GetViewShell()!=NULL
);
126 FunctionReference
xFunc( FuTemplate::Create( mpViewShell
, static_cast< ::sd::Window
*>( mpViewShell
->GetViewShell()->GetWindow()), mpView
, pDoc
, rReq
) );
133 if( rReq
.GetSlot() == SID_STYLE_APPLY
)
135 if( mpViewShell
&& mpViewShell
->GetViewFrame() )
136 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_APPLY
);
142 if( mpViewShell
&& mpViewShell
->GetViewFrame() )
143 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute( SID_STYLE_DESIGNER
, SFX_CALLMODE_ASYNCHRON
);
150 case SID_PARASPACE_INCREASE
:
151 case SID_PARASPACE_DECREASE
:
155 ESelection aSel
= pOLV
->GetSelection();
157 ULONG nStartPara
= aSel
.nStartPara
;
158 ULONG nEndPara
= aSel
.nEndPara
;
159 if( !aSel
.HasRange() )
162 nEndPara
= pOLV
->GetOutliner()->GetParagraphCount() - 1;
164 for( ULONG nPara
= nStartPara
; nPara
<= nEndPara
; nPara
++ )
166 SfxStyleSheet
* pStyleSheet
= NULL
;
167 if (pOLV
->GetOutliner() != NULL
)
168 pStyleSheet
= pOLV
->GetOutliner()->GetStyleSheet(nPara
);
169 if (pStyleSheet
!= NULL
)
171 SfxItemSet
aAttr( pStyleSheet
->GetItemSet() );
172 SfxItemSet
aTmpSet( pOLV
->GetOutliner()->GetParaAttribs( (USHORT
) nPara
) );
173 aAttr
.Put( aTmpSet
, FALSE
); // FALSE= InvalidItems nicht als Default, sondern als "Loecher" betrachten
174 const SvxULSpaceItem
& rItem
= (const SvxULSpaceItem
&) aAttr
.Get( EE_PARA_ULSPACE
);
175 SvxULSpaceItem
* pNewItem
= (SvxULSpaceItem
*) rItem
.Clone();
177 long nUpper
= pNewItem
->GetUpper();
178 if( nSlot
== SID_PARASPACE_INCREASE
)
183 nUpper
= Max( (long) nUpper
, 0L );
185 pNewItem
->SetUpper( (USHORT
) nUpper
);
187 long nLower
= pNewItem
->GetLower();
188 if( nSlot
== SID_PARASPACE_INCREASE
)
193 nLower
= Max( (long) nLower
, 0L );
195 pNewItem
->SetLower( (USHORT
) nLower
);
197 SfxItemSet
aNewAttrs( aAttr
);
198 aNewAttrs
.Put( *pNewItem
);
200 pOLV
->GetOutliner()->SetParaAttribs( (USHORT
)nPara
, aNewAttrs
);
206 // Der folgende Code kann enabled werden, wenn ich von
207 // JOE einen richtigen Status (DontCare) bekomme;
209 // Wird enabled, obwohl es nicht richtig funktioniert (s.o.)
210 SfxItemSet
aEditAttr( mpView
->GetDoc()->GetPool() );
211 mpView
->GetAttributes( aEditAttr
);
212 if( aEditAttr
.GetItemState( EE_PARA_ULSPACE
) >= SFX_ITEM_AVAILABLE
)
214 SfxItemSet
aNewAttrs(*(aEditAttr
.GetPool()), aEditAttr
.GetRanges());
215 const SvxULSpaceItem
& rItem
= (const SvxULSpaceItem
&) aEditAttr
.Get( EE_PARA_ULSPACE
);
216 SvxULSpaceItem
* pNewItem
= (SvxULSpaceItem
*) rItem
.Clone();
217 long nUpper
= pNewItem
->GetUpper();
219 if( nSlot
== SID_PARASPACE_INCREASE
)
224 nUpper
= Max( (long) nUpper
, 0L );
226 pNewItem
->SetUpper( (USHORT
) nUpper
);
228 long nLower
= pNewItem
->GetLower();
229 if( nSlot
== SID_PARASPACE_INCREASE
)
234 nLower
= Max( (long) nLower
, 0L );
236 pNewItem
->SetLower( (USHORT
) nLower
);
238 aNewAttrs
.Put( *pNewItem
);
241 mpView
->SetAttributes( aNewAttrs
);
247 // Um die Preview (im Gliederungsmodus) zu aktualisieren muss
248 // der Slot invalidiert werden:
249 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE
, TRUE
, FALSE
);
253 case SID_OUTLINE_LEFT
:
257 pOLV
->AdjustDepth( -1 );
259 // Ensure bold/italic etc. icon state updates
261 // #96551# trigger preview refresh
262 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE
, TRUE
, FALSE
);
268 case SID_OUTLINE_RIGHT
:
272 pOLV
->AdjustDepth( 1 );
274 // Ensure bold/italic etc. icon state updates
276 // #96551# trigger preview refresh
277 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE
, TRUE
, FALSE
);
287 pOLV
->AdjustHeight( -1 );
289 // #96551# trigger preview refresh
290 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE
, TRUE
, FALSE
);
296 case SID_OUTLINE_DOWN
:
300 pOLV
->AdjustHeight( 1 );
302 // #96551# trigger preview refresh
303 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE
, TRUE
, FALSE
);
309 case SID_TEXTDIRECTION_LEFT_TO_RIGHT
:
310 case SID_TEXTDIRECTION_TOP_TO_BOTTOM
:
312 mpView
->SdrEndTextEdit();
313 SfxItemSet
aAttr( mpView
->GetDoc()->GetPool(), SDRATTR_TEXTDIRECTION
, SDRATTR_TEXTDIRECTION
, 0 );
314 aAttr
.Put( SvxWritingModeItem(
315 nSlot
== SID_TEXTDIRECTION_LEFT_TO_RIGHT
?
316 com::sun::star::text::WritingMode_LR_TB
: com::sun::star::text::WritingMode_TB_RL
,
317 SDRATTR_TEXTDIRECTION
) );
319 mpView
->SetAttributes( aAttr
);
321 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE
, TRUE
, FALSE
);
325 case FN_NUM_BULLET_ON
:
327 pOLV
->ToggleBullets();
330 case SID_GROW_FONT_SIZE
:
331 case SID_SHRINK_FONT_SIZE
:
333 const SvxFontListItem
* pFonts
= (const SvxFontListItem
*)mpViewShell
->GetDocSh()->GetItem( SID_ATTR_CHAR_FONTLIST
);
334 const FontList
* pFontList
= pFonts
? pFonts
->GetFontList(): 0;
337 FuText::ChangeFontSize( nSlot
== SID_GROW_FONT_SIZE
, pOLV
, pFontList
, mpView
);
338 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT
);
347 SfxItemSet
aEditAttr( mpView
->GetDoc()->GetPool() );
348 mpView
->GetAttributes( aEditAttr
);
349 SfxItemSet
aNewAttr(*(aEditAttr
.GetPool()), aEditAttr
.GetRanges());
353 //aNewAttr.InvalidateAllItems(); <- Macht Probleme (#35465#)
357 case SID_ATTR_CHAR_WEIGHT
:
359 FontWeight eFW
= ( (const SvxWeightItem
&) aEditAttr
.
360 Get( EE_CHAR_WEIGHT
) ).GetWeight();
361 aNewAttr
.Put( SvxWeightItem( eFW
== WEIGHT_NORMAL
?
362 WEIGHT_BOLD
: WEIGHT_NORMAL
,
366 case SID_ATTR_CHAR_POSTURE
:
368 FontItalic eFI
= ( (const SvxPostureItem
&) aEditAttr
.
369 Get( EE_CHAR_ITALIC
) ).GetPosture();
370 aNewAttr
.Put( SvxPostureItem( eFI
== ITALIC_NORMAL
?
371 ITALIC_NONE
: ITALIC_NORMAL
,
375 case SID_ATTR_CHAR_UNDERLINE
:
377 FontUnderline eFU
= ( (const SvxUnderlineItem
&) aEditAttr
.
378 Get( EE_CHAR_UNDERLINE
) ).GetLineStyle();
379 aNewAttr
.Put( SvxUnderlineItem( eFU
== UNDERLINE_SINGLE
?
380 UNDERLINE_NONE
: UNDERLINE_SINGLE
,
381 EE_CHAR_UNDERLINE
) );
384 case SID_ATTR_CHAR_OVERLINE
:
386 FontUnderline eFO
= ( (const SvxOverlineItem
&) aEditAttr
.
387 Get( EE_CHAR_OVERLINE
) ).GetLineStyle();
388 aNewAttr
.Put( SvxOverlineItem( eFO
== UNDERLINE_SINGLE
?
389 UNDERLINE_NONE
: UNDERLINE_SINGLE
,
390 EE_CHAR_OVERLINE
) );
393 case SID_ATTR_CHAR_CONTOUR
:
395 aNewAttr
.Put( SvxContourItem( !( (const SvxContourItem
&) aEditAttr
.
396 Get( EE_CHAR_OUTLINE
) ).GetValue(), EE_CHAR_OUTLINE
) );
399 case SID_ATTR_CHAR_SHADOWED
:
401 aNewAttr
.Put( SvxShadowedItem( !( (const SvxShadowedItem
&) aEditAttr
.
402 Get( EE_CHAR_SHADOW
) ).GetValue(), EE_CHAR_SHADOW
) );
405 case SID_ATTR_CHAR_STRIKEOUT
:
407 FontStrikeout eFSO
= ( ( (const SvxCrossedOutItem
&) aEditAttr
.
408 Get( EE_CHAR_STRIKEOUT
) ).GetStrikeout() );
409 aNewAttr
.Put( SvxCrossedOutItem( eFSO
== STRIKEOUT_SINGLE
?
410 STRIKEOUT_NONE
: STRIKEOUT_SINGLE
, EE_CHAR_STRIKEOUT
) );
414 case SID_ATTR_PARA_ADJUST_LEFT
:
416 aNewAttr
.Put( SvxAdjustItem( SVX_ADJUST_LEFT
, EE_PARA_JUST
) );
419 case SID_ATTR_PARA_ADJUST_CENTER
:
421 aNewAttr
.Put( SvxAdjustItem( SVX_ADJUST_CENTER
, EE_PARA_JUST
) );
424 case SID_ATTR_PARA_ADJUST_RIGHT
:
426 aNewAttr
.Put( SvxAdjustItem( SVX_ADJUST_RIGHT
, EE_PARA_JUST
) );
429 case SID_ATTR_PARA_ADJUST_BLOCK
:
431 aNewAttr
.Put( SvxAdjustItem( SVX_ADJUST_BLOCK
, EE_PARA_JUST
) );
434 case SID_ATTR_PARA_LINESPACE_10
:
436 SvxLineSpacingItem
aItem( SVX_LINESPACE_ONE_LINE
, EE_PARA_SBL
);
437 aItem
.SetPropLineSpace( 100 );
438 aNewAttr
.Put( aItem
);
441 case SID_ATTR_PARA_LINESPACE_15
:
443 SvxLineSpacingItem
aItem( SVX_LINESPACE_ONE_POINT_FIVE_LINES
, EE_PARA_SBL
);
444 aItem
.SetPropLineSpace( 150 );
445 aNewAttr
.Put( aItem
);
448 case SID_ATTR_PARA_LINESPACE_20
:
450 SvxLineSpacingItem
aItem( SVX_LINESPACE_TWO_LINES
, EE_PARA_SBL
);
451 aItem
.SetPropLineSpace( 200 );
452 aNewAttr
.Put( aItem
);
455 case SID_SET_SUPER_SCRIPT
:
457 SvxEscapementItem
aItem( EE_CHAR_ESCAPEMENT
);
458 SvxEscapement eEsc
= (SvxEscapement
) ( (const SvxEscapementItem
&)
459 aEditAttr
.Get( EE_CHAR_ESCAPEMENT
) ).GetEnumValue();
461 if( eEsc
== SVX_ESCAPEMENT_SUPERSCRIPT
)
462 aItem
.SetEscapement( SVX_ESCAPEMENT_OFF
);
464 aItem
.SetEscapement( SVX_ESCAPEMENT_SUPERSCRIPT
);
465 aNewAttr
.Put( aItem
);
468 case SID_SET_SUB_SCRIPT
:
470 SvxEscapementItem
aItem( EE_CHAR_ESCAPEMENT
);
471 SvxEscapement eEsc
= (SvxEscapement
) ( (const SvxEscapementItem
&)
472 aEditAttr
.Get( EE_CHAR_ESCAPEMENT
) ).GetEnumValue();
474 if( eEsc
== SVX_ESCAPEMENT_SUBSCRIPT
)
475 aItem
.SetEscapement( SVX_ESCAPEMENT_OFF
);
477 aItem
.SetEscapement( SVX_ESCAPEMENT_SUBSCRIPT
);
478 aNewAttr
.Put( aItem
);
482 // Attribute fuer die TextObjectBar
483 case SID_ATTR_CHAR_FONT
:
487 if( SFX_ITEM_SET
== pArgs
->GetItemState( EE_CHAR_FONTINFO
, TRUE
, &pPoolItem
) )
488 aNewAttr
.Put( *pPoolItem
);
491 mpViewShell
->GetViewFrame()->GetDispatcher()->
492 Execute( SID_CHAR_DLG
, SFX_CALLMODE_ASYNCHRON
);
495 case SID_ATTR_CHAR_FONTHEIGHT
:
499 if( SFX_ITEM_SET
== pArgs
->GetItemState( EE_CHAR_FONTHEIGHT
, TRUE
, &pPoolItem
) )
500 aNewAttr
.Put( *pPoolItem
);
503 mpViewShell
->GetViewFrame()->GetDispatcher()->
504 Execute( SID_CHAR_DLG
, SFX_CALLMODE_ASYNCHRON
);
507 case SID_ATTR_CHAR_COLOR
:
509 if( pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState( EE_CHAR_COLOR
, TRUE
, &pPoolItem
) )
510 aNewAttr
.Put( *pPoolItem
);
514 case FN_NUM_BULLET_ON:
516 if (aEditAttr.GetItemState(EE_PARA_BULLETSTATE) == SFX_ITEM_ON)
518 SfxUInt16Item aBulletState((const SfxUInt16Item&) aEditAttr.Get(EE_PARA_BULLETSTATE));
520 if (aBulletState.GetValue() != 0)
523 aNewAttr.Put(SfxUInt16Item(EE_PARA_BULLETSTATE, 0));
528 aNewAttr.Put(SfxUInt16Item(EE_PARA_BULLETSTATE, 1));
534 aNewAttr.Put(SfxUInt16Item(EE_PARA_BULLETSTATE, 1));
541 rReq
.Done( aNewAttr
);
542 pArgs
= rReq
.GetArgs();
544 else if ( nSlot
== SID_ATTR_PARA_LEFT_TO_RIGHT
||
545 nSlot
== SID_ATTR_PARA_RIGHT_TO_LEFT
)
547 sal_Bool bLeftToRight
= nSlot
== SID_ATTR_PARA_LEFT_TO_RIGHT
;
549 USHORT nAdjust
= SVX_ADJUST_LEFT
;
550 if( SFX_ITEM_ON
== aEditAttr
.GetItemState(EE_PARA_JUST
, TRUE
, &pPoolItem
) )
551 nAdjust
= ( (SvxAdjustItem
*)pPoolItem
)->GetEnumValue();
555 aNewAttr
.Put( SvxFrameDirectionItem( FRMDIR_HORI_LEFT_TOP
, EE_PARA_WRITINGDIR
) );
556 if( nAdjust
== SVX_ADJUST_RIGHT
)
557 aNewAttr
.Put( SvxAdjustItem( SVX_ADJUST_LEFT
, EE_PARA_JUST
) );
561 aNewAttr
.Put( SvxFrameDirectionItem( FRMDIR_HORI_RIGHT_TOP
, EE_PARA_WRITINGDIR
) );
562 if( nAdjust
== SVX_ADJUST_LEFT
)
563 aNewAttr
.Put( SvxAdjustItem( SVX_ADJUST_RIGHT
, EE_PARA_JUST
) );
566 rReq
.Done( aNewAttr
);
567 pArgs
= rReq
.GetArgs();
569 Invalidate( SID_RULER_TEXT_RIGHT_TO_LEFT
);
571 else if ( nSlot
== SID_ATTR_CHAR_FONT
||
572 nSlot
== SID_ATTR_CHAR_FONTHEIGHT
||
573 nSlot
== SID_ATTR_CHAR_POSTURE
||
574 nSlot
== SID_ATTR_CHAR_WEIGHT
)
576 // #i78017 establish the same behaviour as in Writer
577 USHORT nScriptType
= SCRIPTTYPE_LATIN
| SCRIPTTYPE_ASIAN
| SCRIPTTYPE_COMPLEX
;
578 if (nSlot
== SID_ATTR_CHAR_FONT
)
579 nScriptType
= mpView
->GetScriptType();
581 SfxItemPool
& rPool
= mpView
->GetDoc()->GetPool();
582 SvxScriptSetItem
aSvxScriptSetItem( nSlot
, rPool
);
583 aSvxScriptSetItem
.PutItemForScriptType( nScriptType
, pArgs
->Get( rPool
.GetWhich( nSlot
) ) );
584 aNewAttr
.Put( aSvxScriptSetItem
.GetItemSet() );
585 rReq
.Done( aNewAttr
);
586 pArgs
= rReq
.GetArgs();
589 mpView
->SetAttributes(*pArgs
);
591 // Aus Performance- und Erweiterungsgruenden wird
592 // jetzt die komplette Shell invalidiert
595 // Um die Preview (im Gliederungsmodus) zu aktualisieren muss
596 // der Slot invalidiert werden:
597 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE
, TRUE
, FALSE
);
602 Invalidate( SID_OUTLINE_LEFT
);
603 Invalidate( SID_OUTLINE_RIGHT
);
604 Invalidate( SID_OUTLINE_UP
);
605 Invalidate( SID_OUTLINE_DOWN
);
608 } // end of namespace sd