merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / view / drtxtob1.cxx
blob3873169af140924b02da2731fa8954805ba5d449
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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>
38 #ifndef _ULSPITEM_HXX
39 #include <svx/ulspitem.hxx>
40 #endif
41 #ifndef _LSPCITEM_HXX
42 #include <svx/lspcitem.hxx>
43 #endif
44 #ifndef _ADJITEM_HXX
45 #include <svx/adjitem.hxx>
46 #endif
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>
71 #endif
72 #include <svx/svdoutl.hxx>
73 #include <svx/writingmodeitem.hxx>
74 #include <svx/frmdiritem.hxx>
75 #include <svtools/itemiter.hxx>
78 #include "app.hrc"
80 #include "eetext.hxx"
81 #include "ViewShell.hxx"
82 #include "drawview.hxx"
83 #include "drawdoc.hxx"
84 #include "OutlineView.hxx"
85 #include "Window.hxx"
86 #include "futempl.hxx"
87 #include "DrawDocShell.hxx"
88 #include "Outliner.hxx"
89 #include "futext.hxx"
91 namespace sd {
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))
111 bOutlineMode = TRUE;
112 pOLV = static_cast<OutlineView*>(mpView)
113 ->GetViewByWindow(mpViewShell->GetActiveWindow());
115 aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
118 switch (nSlot)
120 case SID_STYLE_APPLY:
122 if( pArgs )
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 ) );
128 if(xFunc.is())
130 xFunc->Activate();
131 xFunc->Deactivate();
133 if( rReq.GetSlot() == SID_STYLE_APPLY )
135 if( mpViewShell && mpViewShell->GetViewFrame() )
136 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_APPLY );
140 else
142 if( mpViewShell && mpViewShell->GetViewFrame() )
143 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_STYLE_DESIGNER, SFX_CALLMODE_ASYNCHRON );
146 rReq.Done();
148 break;
150 case SID_PARASPACE_INCREASE:
151 case SID_PARASPACE_DECREASE:
153 if( pOLV )
155 ESelection aSel = pOLV->GetSelection();
156 aSel.Adjust();
157 ULONG nStartPara = aSel.nStartPara;
158 ULONG nEndPara = aSel.nEndPara;
159 if( !aSel.HasRange() )
161 nStartPara = 0;
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 )
179 nUpper += 100;
180 else
182 nUpper -= 100;
183 nUpper = Max( (long) nUpper, 0L );
185 pNewItem->SetUpper( (USHORT) nUpper );
187 long nLower = pNewItem->GetLower();
188 if( nSlot == SID_PARASPACE_INCREASE )
189 nLower += 100;
190 else
192 nLower -= 100;
193 nLower = Max( (long) nLower, 0L );
195 pNewItem->SetLower( (USHORT) nLower );
197 SfxItemSet aNewAttrs( aAttr );
198 aNewAttrs.Put( *pNewItem );
199 delete pNewItem;
200 pOLV->GetOutliner()->SetParaAttribs( (USHORT)nPara, aNewAttrs );
204 else
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 )
220 nUpper += 100;
221 else
223 nUpper -= 100;
224 nUpper = Max( (long) nUpper, 0L );
226 pNewItem->SetUpper( (USHORT) nUpper );
228 long nLower = pNewItem->GetLower();
229 if( nSlot == SID_PARASPACE_INCREASE )
230 nLower += 100;
231 else
233 nLower -= 100;
234 nLower = Max( (long) nLower, 0L );
236 pNewItem->SetLower( (USHORT) nLower );
238 aNewAttrs.Put( *pNewItem );
239 delete pNewItem;
241 mpView->SetAttributes( aNewAttrs );
244 rReq.Done();
246 Invalidate();
247 // Um die Preview (im Gliederungsmodus) zu aktualisieren muss
248 // der Slot invalidiert werden:
249 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE, TRUE, FALSE );
251 break;
253 case SID_OUTLINE_LEFT:
255 if (pOLV)
257 pOLV->AdjustDepth( -1 );
259 // Ensure bold/italic etc. icon state updates
260 Invalidate();
261 // #96551# trigger preview refresh
262 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE, TRUE, FALSE );
264 rReq.Done();
266 break;
268 case SID_OUTLINE_RIGHT:
270 if (pOLV)
272 pOLV->AdjustDepth( 1 );
274 // Ensure bold/italic etc. icon state updates
275 Invalidate();
276 // #96551# trigger preview refresh
277 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE, TRUE, FALSE );
279 rReq.Done();
281 break;
283 case SID_OUTLINE_UP:
285 if (pOLV)
287 pOLV->AdjustHeight( -1 );
289 // #96551# trigger preview refresh
290 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE, TRUE, FALSE );
292 rReq.Done();
294 break;
296 case SID_OUTLINE_DOWN:
298 if (pOLV)
300 pOLV->AdjustHeight( 1 );
302 // #96551# trigger preview refresh
303 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE, TRUE, FALSE );
305 rReq.Done();
307 break;
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 ) );
318 rReq.Done( aAttr );
319 mpView->SetAttributes( aAttr );
320 Invalidate();
321 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE, TRUE, FALSE );
323 break;
325 case FN_NUM_BULLET_ON:
326 if( pOLV )
327 pOLV->ToggleBullets();
328 break;
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;
335 if( pFontList )
337 FuText::ChangeFontSize( nSlot == SID_GROW_FONT_SIZE, pOLV, pFontList, mpView );
338 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
340 rReq.Done();
342 break;
345 default:
347 SfxItemSet aEditAttr( mpView->GetDoc()->GetPool() );
348 mpView->GetAttributes( aEditAttr );
349 SfxItemSet aNewAttr(*(aEditAttr.GetPool()), aEditAttr.GetRanges());
351 if( !pArgs )
353 //aNewAttr.InvalidateAllItems(); <- Macht Probleme (#35465#)
355 switch ( nSlot )
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,
363 EE_CHAR_WEIGHT ) );
365 break;
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,
372 EE_CHAR_ITALIC ) );
374 break;
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 ) );
383 break;
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 ) );
392 break;
393 case SID_ATTR_CHAR_CONTOUR:
395 aNewAttr.Put( SvxContourItem( !( (const SvxContourItem&) aEditAttr.
396 Get( EE_CHAR_OUTLINE ) ).GetValue(), EE_CHAR_OUTLINE ) );
398 break;
399 case SID_ATTR_CHAR_SHADOWED:
401 aNewAttr.Put( SvxShadowedItem( !( (const SvxShadowedItem&) aEditAttr.
402 Get( EE_CHAR_SHADOW ) ).GetValue(), EE_CHAR_SHADOW ) );
404 break;
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 ) );
412 break;
414 case SID_ATTR_PARA_ADJUST_LEFT:
416 aNewAttr.Put( SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST ) );
418 break;
419 case SID_ATTR_PARA_ADJUST_CENTER:
421 aNewAttr.Put( SvxAdjustItem( SVX_ADJUST_CENTER, EE_PARA_JUST ) );
423 break;
424 case SID_ATTR_PARA_ADJUST_RIGHT:
426 aNewAttr.Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
428 break;
429 case SID_ATTR_PARA_ADJUST_BLOCK:
431 aNewAttr.Put( SvxAdjustItem( SVX_ADJUST_BLOCK, EE_PARA_JUST ) );
433 break;
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 );
440 break;
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 );
447 break;
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 );
454 break;
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 );
463 else
464 aItem.SetEscapement( SVX_ESCAPEMENT_SUPERSCRIPT );
465 aNewAttr.Put( aItem );
467 break;
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 );
476 else
477 aItem.SetEscapement( SVX_ESCAPEMENT_SUBSCRIPT );
478 aNewAttr.Put( aItem );
480 break;
482 // Attribute fuer die TextObjectBar
483 case SID_ATTR_CHAR_FONT:
485 if( pArgs )
487 if( SFX_ITEM_SET == pArgs->GetItemState( EE_CHAR_FONTINFO, TRUE, &pPoolItem ) )
488 aNewAttr.Put( *pPoolItem );
490 else
491 mpViewShell->GetViewFrame()->GetDispatcher()->
492 Execute( SID_CHAR_DLG, SFX_CALLMODE_ASYNCHRON );
494 break;
495 case SID_ATTR_CHAR_FONTHEIGHT:
497 if( pArgs )
499 if( SFX_ITEM_SET == pArgs->GetItemState( EE_CHAR_FONTHEIGHT, TRUE, &pPoolItem ) )
500 aNewAttr.Put( *pPoolItem );
502 else
503 mpViewShell->GetViewFrame()->GetDispatcher()->
504 Execute( SID_CHAR_DLG, SFX_CALLMODE_ASYNCHRON );
506 break;
507 case SID_ATTR_CHAR_COLOR:
509 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( EE_CHAR_COLOR, TRUE, &pPoolItem ) )
510 aNewAttr.Put( *pPoolItem );
512 break;
513 /* #i35937#
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)
522 // Ausschalten
523 aNewAttr.Put(SfxUInt16Item(EE_PARA_BULLETSTATE, 0));
525 else
527 // Einschalten
528 aNewAttr.Put(SfxUInt16Item(EE_PARA_BULLETSTATE, 1));
531 else
533 // Einschalten
534 aNewAttr.Put(SfxUInt16Item(EE_PARA_BULLETSTATE, 1));
537 break;
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();
553 if( bLeftToRight )
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 ) );
559 else
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
593 Invalidate();
595 // Um die Preview (im Gliederungsmodus) zu aktualisieren muss
596 // der Slot invalidiert werden:
597 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_PREVIEW_STATE, TRUE, FALSE );
599 break;
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