Update ooo320-m1
[ooovba.git] / sc / source / ui / view / formatsh.cxx
blobfb9f77d9b853af0ba7a9066a9dec135996a5e884
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: formatsh.cxx,v $
10 * $Revision: 1.41.142.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_sc.hxx"
35 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/container/XNameAccess.hpp>
39 //------------------------------------------------------------------
41 //svdraw.hxx
42 #define _SDR_NOITEMS
43 #define _SDR_NOTOUCH
44 #define _SDR_NOTRANSFORM
45 #define _SI_NOSBXCONTROLS
46 #define _VCONT_HXX
47 #define _SI_NOOTHERFORMS
48 #define _VCTRLS_HXX
49 #define _SI_NOCONTROL
50 #define _SETBRW_HXX
51 #define _VCBRW_HXX
52 #define _SI_NOSBXCONTROLS
54 //------------------------------------------------------------------
56 #include "scitems.hxx"
57 #include <svx/eeitem.hxx>
59 #include <sfx2/app.hxx>
60 #include <sfx2/viewfrm.hxx>
61 #include <sfx2/bindings.hxx>
62 #include <sfx2/objface.hxx>
63 #include <sfx2/request.hxx>
64 #include <svtools/whiter.hxx>
65 #include <vcl/msgbox.hxx>
67 #define _ZFORLIST_DECLARE_TABLE
68 #include <svtools/stritem.hxx>
69 #include <svtools/zformat.hxx>
70 #include <svtools/languageoptions.hxx>
71 #include <svx/boxitem.hxx>
72 #include <svx/langitem.hxx>
73 #include <svx/numinf.hxx>
74 #include <sfx2/dispatch.hxx>
75 #include <sfx2/templdlg.hxx>
76 #include <sfx2/tplpitem.hxx>
77 #include <svx/svxenum.hxx>
78 #include <svx/algitem.hxx>
79 #include <svx/wghtitem.hxx>
80 #include <svx/postitem.hxx>
81 #include <svx/udlnitem.hxx>
82 #include <svx/bolnitem.hxx>
83 #include <svx/colritem.hxx>
84 #include <svx/brshitem.hxx>
85 #include <svx/frmdiritem.hxx>
86 #include <svx/scripttypeitem.hxx>
87 #include <svtools/colorcfg.hxx>
88 #include <svx/shaditem.hxx>
90 #include "formatsh.hxx"
91 #include "sc.hrc"
92 #include "globstr.hrc"
93 #include "docsh.hxx"
94 #include "patattr.hxx"
95 #include "scmod.hxx"
96 //CHINA001 #include "styledlg.hxx"
97 #include "attrdlg.hrc"
98 #include "stlpool.hxx"
99 #include "stlsheet.hxx"
100 #include "printfun.hxx"
101 #include "docpool.hxx"
102 #include "scresid.hxx"
103 #include "tabvwsh.hxx"
104 #include "undostyl.hxx"
107 #define ScFormatShell
108 #define TableFont
109 #define FormatForSelection
110 #include "scslots.hxx"
112 #define Interior
113 #include <svx/svxslots.hxx>
115 #include "scabstdlg.hxx" //CHINA001
117 namespace {
119 SvxCellHorJustify lclConvertSlotToHAlign( USHORT nSlot )
121 SvxCellHorJustify eHJustify = SVX_HOR_JUSTIFY_STANDARD;
122 switch( nSlot )
124 case SID_ALIGN_ANY_HDEFAULT: eHJustify = SVX_HOR_JUSTIFY_STANDARD; break;
125 case SID_ALIGN_ANY_LEFT: eHJustify = SVX_HOR_JUSTIFY_LEFT; break;
126 case SID_ALIGN_ANY_HCENTER: eHJustify = SVX_HOR_JUSTIFY_CENTER; break;
127 case SID_ALIGN_ANY_RIGHT: eHJustify = SVX_HOR_JUSTIFY_RIGHT; break;
128 case SID_ALIGN_ANY_JUSTIFIED: eHJustify = SVX_HOR_JUSTIFY_BLOCK; break;
129 default: DBG_ERRORFILE( "lclConvertSlotToHAlign - invalid slot" );
131 return eHJustify;
134 SvxCellVerJustify lclConvertSlotToVAlign( USHORT nSlot )
136 SvxCellVerJustify eVJustify = SVX_VER_JUSTIFY_STANDARD;
137 switch( nSlot )
139 case SID_ALIGN_ANY_VDEFAULT: eVJustify = SVX_VER_JUSTIFY_STANDARD; break;
140 case SID_ALIGN_ANY_TOP: eVJustify = SVX_VER_JUSTIFY_TOP; break;
141 case SID_ALIGN_ANY_VCENTER: eVJustify = SVX_VER_JUSTIFY_CENTER; break;
142 case SID_ALIGN_ANY_BOTTOM: eVJustify = SVX_VER_JUSTIFY_BOTTOM; break;
143 default: DBG_ERRORFILE( "lclConvertSlotToVAlign - invalid slot" );
145 return eVJustify;
148 } // namespace
150 TYPEINIT1( ScFormatShell, SfxShell );
152 SFX_IMPL_INTERFACE(ScFormatShell, SfxShell, ScResId(SCSTR_FORMATSHELL) )
154 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD |
155 SFX_VISIBILITY_SERVER,
156 ScResId(RID_OBJECTBAR_FORMAT));
161 ScFormatShell::ScFormatShell(ScViewData* pData) :
162 SfxShell(pData->GetViewShell()),
163 pViewData(pData)
165 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
167 SetPool( &pTabViewShell->GetPool() );
168 SfxUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
169 SetUndoManager( pMgr );
170 if ( !pViewData->GetDocument()->IsUndoEnabled() )
172 pMgr->SetMaxUndoActionCount( 0 );
174 SetHelpId(HID_SCSHELL_FORMATSH);
175 SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Format")));
178 ScFormatShell::~ScFormatShell()
182 //------------------------------------------------------------------
184 void __EXPORT ScFormatShell::GetStyleState( SfxItemSet& rSet )
186 ScDocument* pDoc = GetViewData()->GetDocument();
187 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
188 SfxStyleSheetBasePool* pStylePool = pDoc->GetStyleSheetPool();
190 BOOL bProtected = FALSE;
191 SCTAB nTabCount = pDoc->GetTableCount();
192 for (SCTAB i=0; i<nTabCount; i++)
193 if (pDoc->IsTabProtected(i)) // ueberhaupt eine Tabelle geschuetzt?
194 bProtected = TRUE;
196 SfxWhichIter aIter(rSet);
197 USHORT nWhich = aIter.FirstWhich();
198 USHORT nSlotId = 0;
200 while ( nWhich )
202 nSlotId = SfxItemPool::IsWhich( nWhich )
203 ? GetPool().GetSlotId( nWhich )
204 : nWhich;
206 switch ( nSlotId )
208 case SID_STYLE_APPLY:
209 if ( !pStylePool )
210 rSet.DisableItem( nSlotId );
211 break;
213 case SID_STYLE_FAMILY2: // Zellvorlagen
215 SfxStyleSheet* pStyleSheet = (SfxStyleSheet*)
216 pTabViewShell->GetStyleSheetFromMarked();
218 if ( pStyleSheet )
219 rSet.Put( SfxTemplateItem( nSlotId, pStyleSheet->GetName() ) );
220 else
221 rSet.Put( SfxTemplateItem( nSlotId, String() ) );
223 break;
225 case SID_STYLE_FAMILY4: // Seitenvorlagen
227 SCTAB nCurTab = GetViewData()->GetTabNo();
228 String aPageStyle = pDoc->GetPageStyle( nCurTab );
229 SfxStyleSheet* pStyleSheet = (SfxStyleSheet*)pStylePool->
230 Find( aPageStyle, SFX_STYLE_FAMILY_PAGE );
232 if ( pStyleSheet )
233 rSet.Put( SfxTemplateItem( nSlotId, aPageStyle ) );
234 else
235 rSet.Put( SfxTemplateItem( nSlotId, String() ) );
237 break;
239 case SID_STYLE_WATERCAN:
241 rSet.Put( SfxBoolItem( nSlotId, SC_MOD()->GetIsWaterCan() ) );
243 break;
245 case SID_STYLE_UPDATE_BY_EXAMPLE:
247 ISfxTemplateCommon* pDesigner = SFX_APP()->
248 GetCurrentTemplateCommon(pTabViewShell->GetViewFrame()->GetBindings());
249 BOOL bPage = pDesigner && SFX_STYLE_FAMILY_PAGE == pDesigner->GetActualFamily();
251 if ( bProtected || bPage )
252 rSet.DisableItem( nSlotId );
254 break;
256 case SID_STYLE_EDIT:
257 case SID_STYLE_DELETE:
259 ISfxTemplateCommon* pDesigner = SFX_APP()->
260 GetCurrentTemplateCommon(pTabViewShell->GetViewFrame()->GetBindings());
261 BOOL bPage = pDesigner && SFX_STYLE_FAMILY_PAGE == pDesigner->GetActualFamily();
263 if ( bProtected && !bPage )
264 rSet.DisableItem( nSlotId );
266 break;
268 default:
269 break;
272 nWhich = aIter.NextWhich();
276 //------------------------------------------------------------------
278 void __EXPORT ScFormatShell::ExecuteStyle( SfxRequest& rReq )
280 // Wenn ToolBar vertikal :
281 if ( !rReq.GetArgs() )
283 pViewData->GetDispatcher().Execute( SID_STYLE_DESIGNER, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
284 return;
287 //--------------------------------------------------------------------
288 SfxBindings& rBindings = pViewData->GetBindings();
289 const SfxItemSet* pArgs = rReq.GetArgs();
290 const USHORT nSlotId = rReq.GetSlot();
291 const SCTAB nCurTab = GetViewData()->GetTabNo();
292 ScDocShell* pDocSh = GetViewData()->GetDocShell();
293 ScTabViewShell* pTabViewShell= GetViewData()->GetViewShell();
294 ScDocument* pDoc = pDocSh->GetDocument();
295 ScMarkData& rMark = GetViewData()->GetMarkData();
296 ScModule* pScMod = SC_MOD();
297 String aRefName;
298 BOOL bUndo = pDoc->IsUndoEnabled();
300 if ( (nSlotId == SID_STYLE_NEW)
301 || (nSlotId == SID_STYLE_EDIT)
302 || (nSlotId == SID_STYLE_DELETE)
303 || (nSlotId == SID_STYLE_APPLY)
304 || (nSlotId == SID_STYLE_WATERCAN)
305 || (nSlotId == SID_STYLE_FAMILY)
306 || (nSlotId == SID_STYLE_NEW_BY_EXAMPLE)
307 || (nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE) )
309 SfxStyleSheetBasePool* pStylePool = pDoc->GetStyleSheetPool();
310 SfxStyleSheetBase* pStyleSheet = NULL;
312 BOOL bStyleToMarked = FALSE;
313 BOOL bListAction = FALSE;
314 BOOL bAddUndo = FALSE; // add ScUndoModifyStyle (style modified)
315 ScStyleSaveData aOldData; // for undo/redo
316 ScStyleSaveData aNewData;
318 SfxStyleFamily eFamily = SFX_STYLE_FAMILY_PARA;
319 const SfxPoolItem* pFamItem;
320 if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_FAMILY, TRUE, &pFamItem ) )
321 eFamily = (SfxStyleFamily)((const SfxUInt16Item*)pFamItem)->GetValue();
322 else
323 if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_FAMILYNAME, TRUE, &pFamItem ) )
325 String sFamily = ((const SfxStringItem*)pFamItem)->GetValue();
326 if (sFamily.CompareToAscii("CellStyles") == COMPARE_EQUAL)
327 eFamily = SFX_STYLE_FAMILY_PARA;
328 else
329 if (sFamily.CompareToAscii("PageStyles") == COMPARE_EQUAL)
330 eFamily = SFX_STYLE_FAMILY_PAGE;
333 String aStyleName;
334 USHORT nRetMask = 0xffff;
335 // #96983# only stylist sends focus to sheet
336 // BOOL bGrabFocus = ( SID_STYLE_APPLY == nSlotId );
338 pStylePool->SetSearchMask( eFamily, SFXSTYLEBIT_ALL );
340 switch ( nSlotId )
342 case SID_STYLE_NEW:
344 const SfxPoolItem* pNameItem;
345 if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( nSlotId, TRUE, &pNameItem ))
346 aStyleName = ((const SfxStringItem*)pNameItem)->GetValue();
348 const SfxPoolItem* pRefItem=NULL;
349 if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_REFERENCE, TRUE, &pRefItem ))
351 if(pRefItem!=NULL)
352 aRefName = ((const SfxStringItem*)pRefItem)->GetValue();
355 pStyleSheet = &(pStylePool->Make( aStyleName, eFamily,
356 SFXSTYLEBIT_USERDEF ) );
358 if ( pStyleSheet && pStyleSheet->HasParentSupport() )
359 pStyleSheet->SetParent(aRefName);
361 break;
363 case SID_STYLE_APPLY:
365 SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_APPLY_STYLE, sal_False );
366 SFX_REQUEST_ARG( rReq, pFamilyItem, SfxStringItem, SID_STYLE_FAMILYNAME, sal_False );
367 if ( pFamilyItem && pNameItem )
369 com::sun::star::uno::Reference< com::sun::star::style::XStyleFamiliesSupplier > xModel(pDocSh->GetModel(), com::sun::star::uno::UNO_QUERY);
372 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xStyles;
373 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xCont = xModel->getStyleFamilies();
374 xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
375 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xInfo;
376 xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
377 ::rtl::OUString aUIName;
378 xInfo->getPropertyValue( ::rtl::OUString::createFromAscii("DisplayName") ) >>= aUIName;
379 if ( aUIName.getLength() )
380 rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
382 catch( com::sun::star::uno::Exception& )
387 case SID_STYLE_EDIT:
388 case SID_STYLE_DELETE:
389 case SID_STYLE_NEW_BY_EXAMPLE:
391 const SfxPoolItem* pNameItem;
392 if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( nSlotId, TRUE, &pNameItem ))
393 aStyleName = ((const SfxStringItem*)pNameItem)->GetValue();
394 pStyleSheet = pStylePool->Find( aStyleName, eFamily );
396 aOldData.InitFromStyle( pStyleSheet );
398 break;
400 case SID_STYLE_WATERCAN:
402 BOOL bWaterCan = pScMod->GetIsWaterCan();
404 if( !bWaterCan )
406 const SfxPoolItem* pItem;
408 if ( SFX_ITEM_SET ==
409 pArgs->GetItemState( nSlotId, TRUE, &pItem ) )
411 const SfxStringItem* pStrItem = PTR_CAST(SfxStringItem,pItem);
412 if ( pStrItem )
414 aStyleName = pStrItem->GetValue();
415 pStyleSheet = pStylePool->Find( aStyleName, eFamily );
417 if ( pStyleSheet )
419 ((ScStyleSheetPool*)pStylePool)->
420 SetActualStyleSheet( pStyleSheet );
421 rReq.Done();
427 if ( !bWaterCan && pStyleSheet )
429 pScMod->SetWaterCan( TRUE );
430 pTabViewShell->SetActivePointer( Pointer(POINTER_FILL) );
431 rReq.Done();
433 else
435 pScMod->SetWaterCan( FALSE );
436 pTabViewShell->SetActivePointer( Pointer(POINTER_ARROW) );
437 rReq.Done();
440 break;
442 default:
443 break;
446 // Neuen Style fuer WaterCan-Mode setzen
447 if ( nSlotId == SID_STYLE_APPLY && pScMod->GetIsWaterCan() && pStyleSheet )
448 ((ScStyleSheetPool*)pStylePool)->SetActualStyleSheet( pStyleSheet );
450 switch ( eFamily )
452 case SFX_STYLE_FAMILY_PARA:
454 switch ( nSlotId )
456 case SID_STYLE_DELETE:
458 if ( pStyleSheet )
460 pTabViewShell->RemoveStyleSheetInUse( (SfxStyleSheet*)pStyleSheet );
461 pStylePool->Remove( pStyleSheet );
462 pTabViewShell->InvalidateAttribs();
463 nRetMask = TRUE;
464 bAddUndo = TRUE;
465 rReq.Done();
467 else
468 nRetMask = FALSE;
470 break;
472 case SID_STYLE_APPLY:
474 if ( pStyleSheet && !pScMod->GetIsWaterCan() )
476 // Anwenden der Vorlage auf das Dokument
477 pTabViewShell->SetStyleSheetToMarked( (SfxStyleSheet*)pStyleSheet );
478 pTabViewShell->InvalidateAttribs();
479 rReq.Done();
482 break;
484 case SID_STYLE_NEW_BY_EXAMPLE:
485 case SID_STYLE_UPDATE_BY_EXAMPLE:
487 // Vorlage erzeugen/ersetzen durch Attribute
488 // an der Cursor-Position:
490 const ScPatternAttr* pAttrItem = NULL;
492 // Die Abfrage, ob markiert ist, war hier immer falsch,
493 // darum jetzt gar nicht mehr, und einfach vom Cursor.
494 // Wenn Attribute aus der Selektion genommen werden sollen,
495 // muss noch darauf geachtet werden, Items aus Vorlagen nicht
496 // zu uebernehmen (GetSelectionPattern sammelt auch Items aus
497 // Vorlagen zusammen) (#44748#)
498 // pAttrItem = GetSelectionPattern();
500 // ScViewData* pViewData = GetViewData();
501 SCCOL nCol = pViewData->GetCurX();
502 SCROW nRow = pViewData->GetCurY();
503 pAttrItem = pDoc->GetPattern( nCol, nRow, nCurTab );
505 SfxItemSet aAttrSet = pAttrItem->GetItemSet();
506 aAttrSet.ClearItem( ATTR_MERGE );
507 aAttrSet.ClearItem( ATTR_MERGE_FLAG );
508 // bedingte Formatierung und Gueltigkeit nicht uebernehmen,
509 // weil sie in der Vorlage nicht editiert werden koennen
510 aAttrSet.ClearItem( ATTR_VALIDDATA );
511 aAttrSet.ClearItem( ATTR_CONDITIONAL );
513 if ( SID_STYLE_NEW_BY_EXAMPLE == nSlotId )
515 if ( bUndo )
517 String aUndo = ScGlobal::GetRscString( STR_UNDO_EDITCELLSTYLE );
518 pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
519 bListAction = TRUE;
522 BOOL bConvertBack = FALSE;
523 SfxStyleSheet* pSheetInUse = (SfxStyleSheet*)
524 pTabViewShell->GetStyleSheetFromMarked();
526 // wenn neuer Style vorhanden und in der Selektion
527 // verwendet wird, so darf der Parent nicht uebernommen
528 // werden:
530 if ( pStyleSheet && pSheetInUse && pStyleSheet == pSheetInUse )
531 pSheetInUse = NULL;
533 // wenn bereits vorhanden, erstmal entfernen...
534 if ( pStyleSheet )
536 // Style-Pointer zu Namen vor Erase,
537 // weil Zellen sonst ungueltige Pointer
538 // enthalten.
539 //!!! bei Gelenheit mal eine Methode, die
540 // das fuer einen bestimmten Style macht
541 pDoc->StylesToNames();
542 bConvertBack = TRUE;
543 pStylePool->Remove(pStyleSheet);
546 // ...und neu anlegen
547 pStyleSheet = &pStylePool->Make( aStyleName, eFamily,
548 SFXSTYLEBIT_USERDEF );
550 // wenn ein Style vorhanden ist, so wird dieser
551 // Parent der neuen Vorlage:
552 if ( pSheetInUse && pStyleSheet->HasParentSupport() )
553 pStyleSheet->SetParent( pSheetInUse->GetName() );
555 if ( bConvertBack )
556 // Namen zu Style-Pointer
557 pDoc->UpdStlShtPtrsFrmNms();
559 // Attribute uebernehmen und Style anwenden
560 pStyleSheet->GetItemSet().Put( aAttrSet );
561 pTabViewShell->UpdateStyleSheetInUse( (SfxStyleSheet*)pStyleSheet );
563 // call SetStyleSheetToMarked after adding the ScUndoModifyStyle
564 // (pStyleSheet pointer is used!)
565 bStyleToMarked = TRUE;
567 else // ( nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE )
569 pStyleSheet = (SfxStyleSheet*)pTabViewShell->GetStyleSheetFromMarked();
571 if ( pStyleSheet )
573 aOldData.InitFromStyle( pStyleSheet );
575 if ( bUndo )
577 String aUndo = ScGlobal::GetRscString( STR_UNDO_EDITCELLSTYLE );
578 pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
579 bListAction = TRUE;
582 pStyleSheet->GetItemSet().Put( aAttrSet );
583 pTabViewShell->UpdateStyleSheetInUse( (SfxStyleSheet*)pStyleSheet );
585 // call SetStyleSheetToMarked after adding the ScUndoModifyStyle
586 // (pStyleSheet pointer is used!)
587 bStyleToMarked = TRUE;
591 aNewData.InitFromStyle( pStyleSheet );
592 bAddUndo = TRUE;
593 rReq.Done();
595 break;
597 default:
598 break;
600 } // case SFX_STYLE_FAMILY_PARA:
601 break;
603 case SFX_STYLE_FAMILY_PAGE:
605 switch ( nSlotId )
607 case SID_STYLE_DELETE:
609 nRetMask = ( NULL != pStyleSheet );
610 if ( pStyleSheet )
612 if ( pDoc->RemovePageStyleInUse( pStyleSheet->GetName() ) )
614 ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(TRUE), nCurTab ).UpdatePages();
615 rBindings.Invalidate( SID_STATUS_PAGESTYLE );
616 rBindings.Invalidate( FID_RESET_PRINTZOOM );
618 pStylePool->Remove( pStyleSheet );
619 rBindings.Invalidate( SID_STYLE_FAMILY4 );
620 pDocSh->SetDocumentModified();
621 bAddUndo = TRUE;
622 rReq.Done();
625 break;
627 case SID_STYLE_APPLY:
629 nRetMask = ( NULL != pStyleSheet );
630 if ( pStyleSheet && !pScMod->GetIsWaterCan() )
632 ScUndoApplyPageStyle* pUndoAction = 0;
633 for( SCTAB nTab = 0, nTabCount = pDoc->GetTableCount(); nTab < nTabCount; ++nTab )
635 if( rMark.GetTableSelect( nTab ) )
637 String aOldName = pDoc->GetPageStyle( nTab );
638 if ( aOldName != aStyleName )
640 pDoc->SetPageStyle( nTab, aStyleName );
641 ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(TRUE), nTab ).UpdatePages();
642 if( !pUndoAction )
643 pUndoAction = new ScUndoApplyPageStyle( pDocSh, aStyleName );
644 pUndoAction->AddSheetAction( nTab, aOldName );
648 if( pUndoAction )
650 pDocSh->GetUndoManager()->AddUndoAction( pUndoAction );
651 pDocSh->SetDocumentModified();
652 rBindings.Invalidate( SID_STYLE_FAMILY4 );
653 rBindings.Invalidate( SID_STATUS_PAGESTYLE );
654 rBindings.Invalidate( FID_RESET_PRINTZOOM );
656 rReq.Done();
659 break;
661 case SID_STYLE_NEW_BY_EXAMPLE:
663 const String& rStrCurStyle = pDoc->GetPageStyle( nCurTab );
665 if ( rStrCurStyle != aStyleName )
667 SfxStyleSheetBase* pCurStyle = pStylePool->Find( rStrCurStyle, eFamily );
668 SfxItemSet aAttrSet = pCurStyle->GetItemSet();
669 SCTAB nInTab;
670 BOOL bUsed = pDoc->IsPageStyleInUse( aStyleName, &nInTab );
672 // wenn bereits vorhanden, erstmal entfernen...
673 if ( pStyleSheet )
674 pStylePool->Remove( pStyleSheet );
676 // ...und neu anlegen
677 pStyleSheet = &pStylePool->Make( aStyleName, eFamily,
678 SFXSTYLEBIT_USERDEF );
680 // Attribute uebernehmen
681 pStyleSheet->GetItemSet().Put( aAttrSet );
682 pDocSh->SetDocumentModified();
684 // wenn in Verwendung -> Update
685 if ( bUsed )
686 ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(TRUE), nInTab ).UpdatePages();
688 aNewData.InitFromStyle( pStyleSheet );
689 bAddUndo = TRUE;
690 rReq.Done();
691 nRetMask = TRUE;
694 break;
696 default:
697 break;
698 } // switch ( nSlotId )
699 } // case SFX_STYLE_FAMILY_PAGE:
700 break;
702 default:
703 break;
704 } // switch ( eFamily )
706 // Neu anlegen oder bearbeiten ueber Dialog:
707 if ( nSlotId == SID_STYLE_NEW || nSlotId == SID_STYLE_EDIT )
709 if ( pStyleSheet )
711 SvxNumberInfoItem* pNumberInfoItem = NULL;
713 SfxStyleFamily eFam = pStyleSheet->GetFamily();
714 // ScDocument* pDoc = GetViewData()->GetDocument();
715 // ScDocShell* pDocSh = GetViewData()->GetDocShell();
716 //CHINA001 ScStyleDlg* pDlg = NULL;
717 SfxAbstractTabDialog* pDlg = NULL; //CHINA001
718 USHORT nRsc = 0;
720 // #37034#/#37245# alte Items aus der Vorlage merken
721 SfxItemSet aOldSet = pStyleSheet->GetItemSet();
722 String aOldName = pStyleSheet->GetName();
724 switch ( eFam )
726 case SFX_STYLE_FAMILY_PAGE:
727 nRsc = RID_SCDLG_STYLES_PAGE;
728 break;
730 case SFX_STYLE_FAMILY_PARA:
731 default:
733 SfxItemSet& rSet = pStyleSheet->GetItemSet();
735 const SfxPoolItem* pItem;
736 if ( rSet.GetItemState( ATTR_VALUE_FORMAT,
737 FALSE, &pItem ) == SFX_ITEM_SET )
739 // NumberFormat Value aus Value und Language
740 // erzeugen und eintueten
741 ULONG nFormat =
742 ((SfxUInt32Item*)pItem)->GetValue();
743 LanguageType eLang =
744 ((SvxLanguageItem*)&rSet.Get(
745 ATTR_LANGUAGE_FORMAT ))->GetLanguage();
746 ULONG nLangFormat = pDoc->GetFormatTable()->
747 GetFormatForLanguageIfBuiltIn( nFormat, eLang );
748 if ( nLangFormat != nFormat )
750 SfxUInt32Item aNewItem( ATTR_VALUE_FORMAT, nLangFormat );
751 rSet.Put( aNewItem );
752 aOldSet.Put( aNewItem );
753 // auch in aOldSet fuer Vergleich nach dem Dialog,
754 // sonst geht evtl. eine Aenderung der Sprache verloren
758 pTabViewShell->MakeNumberInfoItem( pDoc, GetViewData(), &pNumberInfoItem );
759 pDocSh->PutItem( *pNumberInfoItem );
760 nRsc = RID_SCDLG_STYLES_PAR;
762 // auf jeden Fall ein SvxBoxInfoItem mit Table = FALSE im Set:
763 // (wenn gar kein Item da ist, loescht der Dialog auch das
764 // BORDER_OUTER SvxBoxItem aus dem Vorlagen-Set)
766 if ( rSet.GetItemState( ATTR_BORDER_INNER, FALSE ) != SFX_ITEM_SET )
768 SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
769 aBoxInfoItem.SetTable(FALSE); // keine inneren Linien
770 aBoxInfoItem.SetDist(TRUE);
771 aBoxInfoItem.SetMinDist(FALSE);
772 rSet.Put( aBoxInfoItem );
775 break;
778 // If GetDefDialogParent is a dialog, it must be used
779 // (style catalog)
781 Window* pParent = Application::GetDefDialogParent();
782 if ( !pParent || !pParent->IsDialog() )
784 // #107256# GetDefDialogParent currently doesn't return the window
785 // that was set with SetDefDialogParent (but dynamically finds the
786 // topmost parent of the focus window), so IsDialog above is FALSE
787 // even if called from the style catalog.
788 // -> Use NULL if a modal dialog is open, to enable the Dialog's
789 // default parent handling.
790 if ( Application::IsInModalMode() )
791 pParent = NULL;
792 else
793 pParent = pTabViewShell->GetDialogParent();
796 pTabViewShell->SetInFormatDialog(TRUE);
798 //CHINA001 pDlg = new ScStyleDlg( pParent, *pStyleSheet, nRsc );
799 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
800 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
802 pDlg = pFact->CreateScStyleDlg( pParent, *pStyleSheet, nRsc, nRsc );
803 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
804 short nResult = pDlg->Execute();
805 pTabViewShell->SetInFormatDialog(FALSE);
807 if ( nResult == RET_OK )
809 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
811 if ( pOutSet )
813 nRetMask = pStyleSheet->GetMask();
815 // #37034#/#37245# Attribut-Vergleiche (frueher in ModifyStyleSheet)
816 // jetzt hier mit den alten Werten (Style ist schon veraendert)
818 if ( SFX_STYLE_FAMILY_PARA == eFam )
820 // pDoc->CellStyleChanged( *pStyleSheet, aOldSet );
822 SfxItemSet& rNewSet = pStyleSheet->GetItemSet();
823 BOOL bNumFormatChanged;
824 if ( ScGlobal::CheckWidthInvalidate(
825 bNumFormatChanged, aOldSet, rNewSet ) )
826 pDoc->InvalidateTextWidth( NULL, NULL, bNumFormatChanged );
828 SCTAB nTabCount = pDoc->GetTableCount();
829 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
830 if (pDoc->IsStreamValid(nTab))
831 pDoc->SetStreamValid(nTab, FALSE);
833 ULONG nOldFormat = ((const SfxUInt32Item&)aOldSet.
834 Get( ATTR_VALUE_FORMAT )).GetValue();
835 ULONG nNewFormat = ((const SfxUInt32Item&)rNewSet.
836 Get( ATTR_VALUE_FORMAT )).GetValue();
837 if ( nNewFormat != nOldFormat )
839 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
840 const SvNumberformat* pOld = pFormatter->GetEntry( nOldFormat );
841 const SvNumberformat* pNew = pFormatter->GetEntry( nNewFormat );
842 if ( pOld && pNew && pOld->GetLanguage() != pNew->GetLanguage() )
843 rNewSet.Put( SvxLanguageItem(
844 pNew->GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
847 else
849 //! auch fuer Seitenvorlagen die Abfragen hier
851 String aNewName = pStyleSheet->GetName();
852 if ( aNewName != aOldName &&
853 pDoc->RenamePageStyleInUse( aOldName, aNewName ) )
855 rBindings.Invalidate( SID_STATUS_PAGESTYLE );
856 rBindings.Invalidate( FID_RESET_PRINTZOOM );
859 pDoc->ModifyStyleSheet( *pStyleSheet, *pOutSet );
860 rBindings.Invalidate( FID_RESET_PRINTZOOM );
863 pDocSh->SetDocumentModified();
865 if ( SFX_STYLE_FAMILY_PARA == eFam )
867 pTabViewShell->UpdateNumberFormatter( pDoc,
868 (const SvxNumberInfoItem&)
869 *(pDocSh->GetItem(SID_ATTR_NUMBERFORMAT_INFO)) );
871 pTabViewShell->UpdateStyleSheetInUse( (SfxStyleSheet*)pStyleSheet );
872 pTabViewShell->InvalidateAttribs();
875 aNewData.InitFromStyle( pStyleSheet );
876 bAddUndo = TRUE;
879 else
881 if ( nSlotId == SID_STYLE_NEW )
882 pStylePool->Remove( pStyleSheet );
883 else
885 // falls zwischendurch etwas mit dem temporaer geaenderten
886 // ItemSet gepainted wurde:
887 pDocSh->PostPaintGridAll();
890 delete pDlg;
894 // if ( nRetMask != 0xffff )// Irgendein Wert MUSS geliefert werden JN
895 rReq.SetReturnValue( SfxUInt16Item( nSlotId, nRetMask ) );
897 // #96983# only stylist sends focus to sheet
898 // if ( bGrabFocus )
899 // pTabViewShell->GetActiveWin()->GrabFocus();
901 if ( bAddUndo && bUndo)
902 pDocSh->GetUndoManager()->AddUndoAction(
903 new ScUndoModifyStyle( pDocSh, eFamily, aOldData, aNewData ) );
905 if ( bStyleToMarked )
907 // call SetStyleSheetToMarked after adding the ScUndoModifyStyle,
908 // so redo will find the modified style
909 pTabViewShell->SetStyleSheetToMarked( (SfxStyleSheet*)pStyleSheet );
910 pTabViewShell->InvalidateAttribs();
913 if ( bListAction )
914 pDocSh->GetUndoManager()->LeaveListAction();
916 else
918 DBG_ERROR( "Unknown slot (ScViewShell::ExecuteStyle)" );
922 void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
924 ScModule* pScMod = SC_MOD();
925 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
926 const SfxItemSet* pReqArgs = rReq.GetArgs();
927 USHORT nSlot = rReq.GetSlot();
928 SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
930 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
932 // Eingabe beenden
933 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
935 switch ( nSlot )
937 case SID_NUMBER_TWODEC:
938 case SID_NUMBER_SCIENTIFIC:
939 case SID_NUMBER_DATE:
940 case SID_NUMBER_CURRENCY:
941 case SID_NUMBER_PERCENT:
942 case SID_NUMBER_STANDARD:
943 case SID_NUMBER_FORMAT:
944 case SID_NUMBER_INCDEC:
945 case SID_NUMBER_DECDEC:
946 case FID_DEFINE_NAME:
947 case FID_USE_NAME:
948 case FID_INSERT_NAME:
949 case SID_SPELL_DIALOG:
950 case SID_HANGUL_HANJA_CONVERSION:
952 pScMod->InputEnterHandler();
953 pTabViewShell->UpdateInputHandler();
954 break;
956 default:
957 break;
961 short nType = GetCurrentNumberFormatType();
962 SfxItemSet aSet( GetPool(), nSlot, nSlot );
963 switch ( nSlot )
965 case SID_NUMBER_TWODEC:
966 pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER, 4 ); // Standard+4 = #.##0,00
967 rReq.Done();
968 break;
969 case SID_NUMBER_SCIENTIFIC:
970 if ((nType & NUMBERFORMAT_SCIENTIFIC))
971 pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
972 else
973 pTabViewShell->SetNumberFormat( NUMBERFORMAT_SCIENTIFIC );
974 aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_SCIENTIFIC)) );
975 rBindings.Invalidate( nSlot );
976 rReq.Done();
977 break;
978 case SID_NUMBER_DATE:
979 if ((nType & NUMBERFORMAT_DATE))
980 pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
981 else
982 pTabViewShell->SetNumberFormat( NUMBERFORMAT_DATE );
983 aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_DATE)) );
984 rBindings.Invalidate( nSlot );
985 rReq.Done();
986 break;
987 case SID_NUMBER_TIME:
988 if ((nType & NUMBERFORMAT_TIME))
989 pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
990 else
991 pTabViewShell->SetNumberFormat( NUMBERFORMAT_TIME );
992 aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_TIME)) );
993 rBindings.Invalidate( nSlot );
994 rReq.Done();
995 break;
996 case SID_NUMBER_CURRENCY:
997 if ((nType & NUMBERFORMAT_CURRENCY))
998 pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
999 else
1000 pTabViewShell->SetNumberFormat( NUMBERFORMAT_CURRENCY );
1001 aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_CURRENCY)) );
1002 rBindings.Invalidate( nSlot );
1003 rReq.Done();
1004 break;
1005 case SID_NUMBER_PERCENT:
1006 if ((nType & NUMBERFORMAT_PERCENT))
1007 pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
1008 else
1009 pTabViewShell->SetNumberFormat( NUMBERFORMAT_PERCENT );
1010 aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_PERCENT)) );
1011 rBindings.Invalidate( nSlot );
1012 rReq.Done();
1013 break;
1014 case SID_NUMBER_STANDARD:
1015 pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
1016 rReq.Done();
1017 break;
1018 case SID_NUMBER_INCDEC:
1019 pTabViewShell->ChangeNumFmtDecimals( TRUE );
1020 rReq.Done();
1021 break;
1022 case SID_NUMBER_DECDEC:
1023 pTabViewShell->ChangeNumFmtDecimals( FALSE );
1024 rReq.Done();
1025 break;
1027 case SID_NUMBER_FORMAT:
1028 if ( pReqArgs )
1030 const SfxPoolItem* pItem;
1031 if(pReqArgs->GetItemState(nSlot, TRUE, &pItem) == SFX_ITEM_SET)
1033 String aCode = ((const SfxStringItem*)pItem)->GetValue();
1034 pTabViewShell->SetNumFmtByStr( aCode );
1037 break;
1039 case SID_ATTR_NUMBERFORMAT_VALUE:
1040 if ( pReqArgs )
1042 const SfxPoolItem* pItem;
1043 if ( pReqArgs->GetItemState( ATTR_VALUE_FORMAT, TRUE, &pItem ) == SFX_ITEM_SET )
1045 // We have to accomplish this using ApplyAttributes()
1046 // because we also need the language information to be
1047 // considered.
1048 const SfxItemSet& rOldSet =
1049 pTabViewShell->GetSelectionPattern()->GetItemSet();
1050 SfxItemPool* pDocPool = GetViewData()->GetDocument()->GetPool();
1051 SfxItemSet aNewSet( *pDocPool, ATTR_PATTERN_START, ATTR_PATTERN_END );
1052 aNewSet.Put( *pItem );
1053 pTabViewShell->ApplyAttributes( &aNewSet, &rOldSet, TRUE );
1056 break;
1058 default:
1059 DBG_ERROR("falscher Slot bei ExecuteEdit");
1060 break;
1065 //------------------------------------------------------------------
1067 #define APPLY_HOR_JUSTIFY(j) \
1069 if ( !pHorJustify || (eHorJustify != (j) ) ) \
1070 pTabViewShell->ApplyAttr( SvxHorJustifyItem( (j) ) ); \
1071 else \
1072 pTabViewShell->ApplyAttr( SvxHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD ) ); \
1075 #define APPLY_VER_JUSTIFY(j) \
1077 if ( !pVerJustify || (eVerJustify != (j) ) ) \
1078 pTabViewShell->ApplyAttr( SvxVerJustifyItem( (j) ) ); \
1079 else \
1080 pTabViewShell->ApplyAttr( SvxVerJustifyItem( SVX_VER_JUSTIFY_STANDARD ) ); \
1083 void ScFormatShell::ExecuteAlignment( SfxRequest& rReq )
1085 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1086 SfxBindings& rBindings = pViewData->GetBindings();
1087 const SfxItemSet* pSet = rReq.GetArgs();
1088 USHORT nSlot = rReq.GetSlot();
1090 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
1092 switch( nSlot )
1094 // pseudo slots for Format menu
1095 case SID_ALIGN_ANY_HDEFAULT:
1096 case SID_ALIGN_ANY_LEFT:
1097 case SID_ALIGN_ANY_HCENTER:
1098 case SID_ALIGN_ANY_RIGHT:
1099 case SID_ALIGN_ANY_JUSTIFIED:
1100 pTabViewShell->ApplyAttr( SvxHorJustifyItem( lclConvertSlotToHAlign( nSlot ), ATTR_HOR_JUSTIFY ) );
1101 break;
1102 case SID_ALIGN_ANY_VDEFAULT:
1103 case SID_ALIGN_ANY_TOP:
1104 case SID_ALIGN_ANY_VCENTER:
1105 case SID_ALIGN_ANY_BOTTOM:
1106 pTabViewShell->ApplyAttr( SvxVerJustifyItem( lclConvertSlotToVAlign( nSlot ), ATTR_VER_JUSTIFY ) );
1107 break;
1109 default:
1110 if( pSet )
1112 const SfxPoolItem* pItem = NULL;
1113 if( pSet->GetItemState(GetPool().GetWhich(nSlot), TRUE, &pItem ) == SFX_ITEM_SET )
1116 switch ( nSlot )
1118 case SID_ATTR_ALIGN_HOR_JUSTIFY:
1119 case SID_ATTR_ALIGN_VER_JUSTIFY:
1120 case SID_ATTR_ALIGN_INDENT:
1121 case SID_ATTR_ALIGN_HYPHENATION:
1122 case SID_ATTR_ALIGN_DEGREES:
1123 case SID_ATTR_ALIGN_LOCKPOS:
1124 case SID_ATTR_ALIGN_MARGIN:
1125 case SID_ATTR_ALIGN_STACKED:
1126 pTabViewShell->ApplyAttr( *pItem );
1127 break;
1129 case SID_H_ALIGNCELL:
1131 SvxCellHorJustify eJust = (SvxCellHorJustify)((const SvxHorJustifyItem*)pItem)->GetValue();
1132 // #i78476# update alignment of text in cell edit mode
1133 pTabViewShell->UpdateInputHandlerCellAdjust( eJust );
1134 pTabViewShell->ApplyAttr( SvxHorJustifyItem( eJust, ATTR_HOR_JUSTIFY ) );
1136 break;
1137 case SID_V_ALIGNCELL:
1138 pTabViewShell->ApplyAttr( SvxVerJustifyItem( (SvxCellVerJustify)((const SvxVerJustifyItem*)pItem)->GetValue(), ATTR_VER_JUSTIFY ) );
1139 break;
1140 default:
1141 DBG_ERROR( "ExecuteAlignment: invalid slot" );
1142 return;
1148 rBindings.Invalidate( SID_ALIGNLEFT );
1149 rBindings.Invalidate( SID_ALIGNRIGHT );
1150 rBindings.Invalidate( SID_ALIGNCENTERHOR );
1151 rBindings.Invalidate( SID_ALIGNBLOCK );
1152 rBindings.Invalidate( SID_ALIGNTOP );
1153 rBindings.Invalidate( SID_ALIGNBOTTOM );
1154 rBindings.Invalidate( SID_ALIGNCENTERVER );
1155 rBindings.Invalidate( SID_V_ALIGNCELL );
1156 rBindings.Invalidate( SID_H_ALIGNCELL );
1157 // pseudo slots for Format menu
1158 rBindings.Invalidate( SID_ALIGN_ANY_HDEFAULT );
1159 rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
1160 rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
1161 rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
1162 rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
1163 rBindings.Invalidate( SID_ALIGN_ANY_VDEFAULT );
1164 rBindings.Invalidate( SID_ALIGN_ANY_TOP );
1165 rBindings.Invalidate( SID_ALIGN_ANY_VCENTER );
1166 rBindings.Invalidate( SID_ALIGN_ANY_BOTTOM );
1167 rBindings.Update();
1169 if( ! rReq.IsAPI() )
1170 rReq.Done();
1173 void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
1175 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1176 SfxBindings& rBindings = pViewData->GetBindings();
1177 const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
1178 const SfxItemSet* pSet = rReq.GetArgs();
1179 USHORT nSlot = rReq.GetSlot();
1180 SfxAllItemSet* pNewSet = 0;
1182 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
1184 if ( (nSlot == SID_ATTR_CHAR_WEIGHT)
1185 ||(nSlot == SID_ATTR_CHAR_POSTURE)
1186 ||(nSlot == SID_ATTR_CHAR_UNDERLINE)
1187 ||(nSlot == SID_ULINE_VAL_NONE)
1188 ||(nSlot == SID_ULINE_VAL_SINGLE)
1189 ||(nSlot == SID_ULINE_VAL_DOUBLE)
1190 ||(nSlot == SID_ULINE_VAL_DOTTED) )
1192 pNewSet = new SfxAllItemSet( GetPool() );
1194 switch ( nSlot )
1196 case SID_ATTR_CHAR_WEIGHT:
1198 // #i78017 establish the same behaviour as in Writer
1199 BYTE nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
1201 SfxItemPool& rPool = GetPool();
1202 SvxScriptSetItem aSetItem( nSlot, rPool );
1203 if ( pSet )
1204 aSetItem.PutItemForScriptType( nScript, pSet->Get( ATTR_FONT_WEIGHT ) );
1205 else
1207 // toggle manually
1209 FontWeight eWeight = WEIGHT_BOLD;
1210 SvxScriptSetItem aOldSetItem( nSlot, rPool );
1211 aOldSetItem.GetItemSet().Put( pAttrs->GetItemSet(), FALSE );
1212 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
1213 if ( pCore && ((const SvxWeightItem*)pCore)->GetWeight() == WEIGHT_BOLD )
1214 eWeight = WEIGHT_NORMAL;
1216 aSetItem.PutItemForScriptType( nScript, SvxWeightItem( eWeight, ATTR_FONT_WEIGHT ) );
1218 pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1219 pNewSet->Put( aSetItem.GetItemSet(), FALSE );
1221 break;
1223 case SID_ATTR_CHAR_POSTURE:
1225 // #i78017 establish the same behaviour as in Writer
1226 BYTE nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
1228 SfxItemPool& rPool = GetPool();
1229 SvxScriptSetItem aSetItem( nSlot, rPool );
1230 if ( pSet )
1231 aSetItem.PutItemForScriptType( nScript, pSet->Get( ATTR_FONT_POSTURE ) );
1232 else
1234 // toggle manually
1236 FontItalic eItalic = ITALIC_NORMAL;
1237 SvxScriptSetItem aOldSetItem( nSlot, rPool );
1238 aOldSetItem.GetItemSet().Put( pAttrs->GetItemSet(), FALSE );
1239 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
1240 if ( pCore && ((const SvxPostureItem*)pCore)->GetPosture() == ITALIC_NORMAL )
1241 eItalic = ITALIC_NONE;
1243 aSetItem.PutItemForScriptType( nScript, SvxPostureItem( eItalic, ATTR_FONT_POSTURE ) );
1245 pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1246 pNewSet->Put( aSetItem.GetItemSet(), FALSE );
1248 break;
1250 case SID_ATTR_CHAR_UNDERLINE:
1252 FontUnderline eUnderline;
1254 if( pSet )
1256 const SvxUnderlineItem& rUnderline = (const SvxUnderlineItem&)pSet->Get( ATTR_FONT_UNDERLINE );
1258 if( rUnderline.ISA(SvxUnderlineItem) )
1260 pTabViewShell->ApplyAttr( rUnderline );
1261 pNewSet->Put( rUnderline,rUnderline.Which() );
1264 else
1266 SvxUnderlineItem aUnderline( (const SvxUnderlineItem&)
1267 pAttrs->GetItem(
1268 ATTR_FONT_UNDERLINE ) );
1269 eUnderline = (UNDERLINE_NONE != aUnderline.GetLineStyle())
1270 ? UNDERLINE_NONE
1271 : UNDERLINE_SINGLE;
1272 aUnderline.SetLineStyle( eUnderline );
1273 pTabViewShell->ApplyAttr( aUnderline );
1274 pNewSet->Put( aUnderline,aUnderline.Which() );
1277 break;
1279 case SID_ULINE_VAL_NONE:
1280 pTabViewShell->ApplyAttr( SvxUnderlineItem( UNDERLINE_NONE, ATTR_FONT_UNDERLINE ) );
1281 break;
1282 case SID_ULINE_VAL_SINGLE: // Toggles
1283 case SID_ULINE_VAL_DOUBLE:
1284 case SID_ULINE_VAL_DOTTED:
1286 FontUnderline eOld = ((const SvxUnderlineItem&)
1287 pAttrs->GetItem(ATTR_FONT_UNDERLINE)).GetLineStyle();
1288 FontUnderline eNew = eOld;
1289 switch (nSlot)
1291 case SID_ULINE_VAL_SINGLE:
1292 eNew = ( eOld == UNDERLINE_SINGLE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
1293 break;
1294 case SID_ULINE_VAL_DOUBLE:
1295 eNew = ( eOld == UNDERLINE_DOUBLE ) ? UNDERLINE_NONE : UNDERLINE_DOUBLE;
1296 break;
1297 case SID_ULINE_VAL_DOTTED:
1298 eNew = ( eOld == UNDERLINE_DOTTED ) ? UNDERLINE_NONE : UNDERLINE_DOTTED;
1299 break;
1301 pTabViewShell->ApplyAttr( SvxUnderlineItem( eNew, ATTR_FONT_UNDERLINE ) );
1303 break;
1305 default:
1306 break;
1308 rBindings.Invalidate( nSlot );
1310 else
1313 * "Selbstgemachte" RadioButton-Funktionalitaet
1314 * Beim Toggle gibt es den Standard-State, d.h. kein
1315 * Button ist gedrueckt
1318 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
1319 const SfxPoolItem* pItem = NULL;
1320 const SvxHorJustifyItem* pHorJustify = NULL;
1321 const SvxVerJustifyItem* pVerJustify = NULL;
1322 SvxCellHorJustify eHorJustify = SVX_HOR_JUSTIFY_STANDARD;
1323 SvxCellVerJustify eVerJustify = SVX_VER_JUSTIFY_STANDARD;
1325 if (rAttrSet.GetItemState(ATTR_HOR_JUSTIFY, TRUE,&pItem ) == SFX_ITEM_SET)
1327 pHorJustify = (const SvxHorJustifyItem*)pItem;
1328 eHorJustify = SvxCellHorJustify( pHorJustify->GetValue() );
1330 if (rAttrSet.GetItemState(ATTR_VER_JUSTIFY, TRUE,&pItem ) == SFX_ITEM_SET)
1332 pVerJustify = (const SvxVerJustifyItem*)pItem;
1333 eVerJustify = SvxCellVerJustify( pVerJustify->GetValue() );
1336 switch ( nSlot )
1338 case SID_ALIGNLEFT:
1339 rReq.SetSlot( SID_H_ALIGNCELL );
1340 rReq.AppendItem( SvxHorJustifyItem(
1341 !pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_LEFT) ?
1342 SVX_HOR_JUSTIFY_LEFT : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1343 ExecuteSlot( rReq, GetInterface() );
1344 return;
1345 // APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_LEFT );
1346 //break;
1348 case SID_ALIGNRIGHT:
1349 rReq.SetSlot( SID_H_ALIGNCELL );
1350 rReq.AppendItem( SvxHorJustifyItem(
1351 !pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_RIGHT) ?
1352 SVX_HOR_JUSTIFY_RIGHT : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1353 ExecuteSlot( rReq, GetInterface() );
1354 return;
1355 // APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_RIGHT );
1356 //break;
1358 case SID_ALIGNCENTERHOR:
1359 rReq.SetSlot( SID_H_ALIGNCELL );
1360 rReq.AppendItem( SvxHorJustifyItem(
1361 !pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_CENTER) ?
1362 SVX_HOR_JUSTIFY_CENTER : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1363 ExecuteSlot( rReq, GetInterface() );
1364 return;
1365 // APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_CENTER );
1366 //break;
1368 case SID_ALIGNBLOCK:
1369 rReq.SetSlot( SID_H_ALIGNCELL );
1370 rReq.AppendItem( SvxHorJustifyItem(
1371 !pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_BLOCK) ?
1372 SVX_HOR_JUSTIFY_BLOCK : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1373 ExecuteSlot( rReq, GetInterface() );
1374 return;
1375 // APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_BLOCK );
1376 //break;
1378 case SID_ALIGNTOP:
1379 rReq.SetSlot( SID_V_ALIGNCELL );
1380 rReq.AppendItem( SvxVerJustifyItem(
1381 !pVerJustify || (eVerJustify != SVX_VER_JUSTIFY_TOP) ?
1382 SVX_VER_JUSTIFY_TOP : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
1383 ExecuteSlot( rReq, GetInterface() );
1384 return;
1385 // APPLY_VER_JUSTIFY( SVX_VER_JUSTIFY_TOP );
1386 //break;
1388 case SID_ALIGNBOTTOM:
1389 rReq.SetSlot( SID_V_ALIGNCELL );
1390 rReq.AppendItem( SvxVerJustifyItem(
1391 !pVerJustify || (eVerJustify != SVX_VER_JUSTIFY_BOTTOM) ?
1392 SVX_VER_JUSTIFY_BOTTOM : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
1393 ExecuteSlot( rReq, GetInterface() );
1394 return;
1395 // APPLY_VER_JUSTIFY( SVX_VER_JUSTIFY_BOTTOM );
1396 //break;
1398 case SID_ALIGNCENTERVER:
1399 rReq.SetSlot( SID_V_ALIGNCELL );
1400 rReq.AppendItem( SvxVerJustifyItem(
1401 !pVerJustify || (eVerJustify != SVX_VER_JUSTIFY_CENTER) ?
1402 SVX_VER_JUSTIFY_CENTER : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
1403 ExecuteSlot( rReq, GetInterface() );
1404 return;
1405 // APPLY_VER_JUSTIFY( SVX_VER_JUSTIFY_CENTER );
1406 //break;
1408 default:
1409 break;
1414 rBindings.Update();
1415 // rReq.Done();
1417 if( pNewSet )
1419 rReq.Done( *pNewSet );
1420 delete pNewSet;
1422 else
1424 rReq.Done();
1429 #undef APPLY_HOR_JUSTIFY
1430 #undef APPLY_VER_JUSTIFY
1432 //------------------------------------------------------------------
1434 void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
1436 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1437 SfxBindings& rBindings = pViewData->GetBindings();
1438 const SfxItemSet* pNewAttrs = rReq.GetArgs();
1440 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
1442 if ( !pNewAttrs )
1444 USHORT nSlot = rReq.GetSlot();
1446 switch ( nSlot )
1448 case SID_ATTR_CHAR_FONT:
1449 case SID_ATTR_CHAR_FONTHEIGHT:
1450 pTabViewShell->ExecuteCellFormatDlg( rReq, TP_FONT ); // wenn ToolBar vertikal
1451 break;
1453 case SID_ATTR_ALIGN_LINEBREAK: // ohne Parameter als Toggle
1455 const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
1456 BOOL bOld = ((const SfxBoolItem&)pAttrs->GetItem(ATTR_LINEBREAK)).GetValue();
1457 SfxBoolItem aBreakItem( ATTR_LINEBREAK, !bOld );
1458 pTabViewShell->ApplyAttr( aBreakItem );
1460 SfxAllItemSet aNewSet( GetPool() );
1461 aNewSet.Put( aBreakItem,aBreakItem.Which() );
1462 rReq.Done( aNewSet );
1464 rBindings.Invalidate( nSlot );
1466 break;
1468 case SID_BACKGROUND_COLOR:
1470 // SID_BACKGROUND_COLOR without arguments -> set transparent background
1472 SvxBrushItem aBrushItem( (const SvxBrushItem&)
1473 pTabViewShell->GetSelectionPattern()->
1474 GetItem( ATTR_BACKGROUND ) );
1476 aBrushItem.SetColor( COL_TRANSPARENT );
1478 pTabViewShell->ApplyAttr( aBrushItem );
1480 break;
1483 else
1485 USHORT nSlot = rReq.GetSlot();
1487 switch ( nSlot )
1489 case SID_ATTR_CHAR_OVERLINE:
1490 case SID_ATTR_CHAR_STRIKEOUT:
1491 case SID_ATTR_ALIGN_LINEBREAK:
1492 case SID_ATTR_CHAR_COLOR:
1493 case SID_ATTR_CHAR_CONTOUR:
1494 case SID_ATTR_CHAR_SHADOWED:
1495 case SID_ATTR_CHAR_RELIEF:
1496 case SID_SCATTR_PROTECTION :
1497 pTabViewShell->ApplyAttr( pNewAttrs->Get( pNewAttrs->GetPool()->GetWhich( nSlot ) ) );
1498 rBindings.Invalidate( nSlot );
1499 rBindings.Update( nSlot );
1500 break;
1502 case SID_ATTR_CHAR_FONT:
1503 case SID_ATTR_CHAR_FONTHEIGHT:
1505 // #i78017 establish the same behaviour as in Writer
1506 BYTE nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
1507 if (nSlot == SID_ATTR_CHAR_FONT)
1508 nScript = pTabViewShell->GetSelectionScriptType();
1510 SfxItemPool& rPool = GetPool();
1511 SvxScriptSetItem aSetItem( nSlot, rPool );
1512 USHORT nWhich = rPool.GetWhich( nSlot );
1513 aSetItem.PutItemForScriptType( nScript, pNewAttrs->Get( nWhich ) );
1515 pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1517 rBindings.Invalidate( nSlot );
1518 rBindings.Update( nSlot );
1520 break;
1522 case SID_FRAME_LINESTYLE:
1524 // Default-Linie aktualisieren
1525 const SvxBorderLine* pLine =
1526 ((const SvxLineItem&)
1527 pNewAttrs->Get( SID_FRAME_LINESTYLE )).
1528 GetLine();
1530 if ( pLine )
1532 SvxBorderLine* pDefLine = pTabViewShell->GetDefaultFrameLine();
1534 if ( pDefLine )
1536 pDefLine->SetOutWidth( pLine->GetOutWidth() );
1537 pDefLine->SetInWidth ( pLine->GetInWidth() );
1538 pDefLine->SetDistance( pLine->GetDistance() );
1539 pTabViewShell->SetSelectionFrameLines( pDefLine, FALSE );
1541 else
1543 pTabViewShell->SetDefaultFrameLine( pLine );
1544 pTabViewShell->GetDefaultFrameLine()->SetColor( COL_BLACK );
1545 pTabViewShell->SetSelectionFrameLines( pLine, FALSE );
1548 else
1550 Color aColorBlack( COL_BLACK );
1551 SvxBorderLine aDefLine( &aColorBlack, 20, 0, 0 );
1552 pTabViewShell->SetDefaultFrameLine( &aDefLine );
1553 pTabViewShell->SetSelectionFrameLines( NULL, FALSE );
1556 break;
1558 case SID_FRAME_LINECOLOR:
1560 SvxBorderLine* pDefLine = pTabViewShell->GetDefaultFrameLine();
1561 const Color& rColor = ((const SvxColorItem&)
1562 pNewAttrs->Get( SID_FRAME_LINECOLOR )).
1563 GetValue();
1565 // Default-Linie aktualisieren
1566 if ( pDefLine )
1568 pDefLine->SetColor( rColor );
1569 pTabViewShell->SetSelectionFrameLines( pDefLine, TRUE );
1571 else
1573 SvxBorderLine aDefLine( &rColor, 20, 0, 0 );
1574 pTabViewShell->SetDefaultFrameLine( &aDefLine );
1575 pTabViewShell->SetSelectionFrameLines( &aDefLine, FALSE );
1578 break;
1580 case SID_ATTR_BORDER_OUTER:
1581 case SID_ATTR_BORDER:
1583 SvxBorderLine* pDefLine = pTabViewShell->GetDefaultFrameLine();
1584 const ScPatternAttr* pOldAttrs = pTabViewShell->GetSelectionPattern();
1585 ScDocument* pDoc = GetViewData()->GetDocument();
1586 SfxItemSet* pOldSet =
1587 new SfxItemSet(
1588 *(pDoc->GetPool()),
1589 ATTR_PATTERN_START,
1590 ATTR_PATTERN_END );
1591 SfxItemSet* pNewSet =
1592 new SfxItemSet(
1593 *(pDoc->GetPool()),
1594 ATTR_PATTERN_START,
1595 ATTR_PATTERN_END );
1596 const SfxPoolItem& rBorderAttr =
1597 pOldAttrs->GetItemSet().
1598 Get( ATTR_BORDER );
1600 // Border-Items vom Controller auswerten:
1601 const SfxPoolItem* pItem = 0;
1603 if ( pNewAttrs->GetItemState( ATTR_BORDER, TRUE, &pItem )
1604 == SFX_ITEM_SET )
1606 // #100959# The SvxFrameToolBoxControl toolbox controller uses a default
1607 // SvxBorderLine (all widths 0) to mark the lines that should be set.
1608 // Macro recording uses a SvxBoxItem with the real values (OutWidth > 0)
1609 // or NULL pointers for no lines.
1610 // -> Substitute existing lines with pDefLine only if widths are 0.
1611 SvxBoxItem aBoxItem ( *(const SvxBoxItem*)pItem );
1612 if ( aBoxItem.GetTop() && aBoxItem.GetTop()->GetOutWidth() == 0 )
1613 aBoxItem.SetLine( pDefLine, BOX_LINE_TOP );
1614 if ( aBoxItem.GetBottom() && aBoxItem.GetBottom()->GetOutWidth() == 0 )
1615 aBoxItem.SetLine( pDefLine, BOX_LINE_BOTTOM );
1616 if ( aBoxItem.GetLeft() && aBoxItem.GetLeft()->GetOutWidth() == 0 )
1617 aBoxItem.SetLine( pDefLine, BOX_LINE_LEFT );
1618 if ( aBoxItem.GetRight() && aBoxItem.GetRight()->GetOutWidth() == 0 )
1619 aBoxItem.SetLine( pDefLine, BOX_LINE_RIGHT );
1620 pNewSet->Put( aBoxItem );
1621 rReq.AppendItem( aBoxItem );
1624 if ( pNewAttrs->GetItemState( ATTR_BORDER_INNER, TRUE, &pItem )
1625 == SFX_ITEM_SET )
1627 SvxBoxInfoItem aBoxInfoItem( *(const SvxBoxInfoItem*)pItem );
1628 if ( aBoxInfoItem.GetHori() && aBoxInfoItem.GetHori()->GetOutWidth() == 0 )
1629 aBoxInfoItem.SetLine( pDefLine, BOXINFO_LINE_HORI );
1630 if ( aBoxInfoItem.GetVert() && aBoxInfoItem.GetVert()->GetOutWidth() == 0 )
1631 aBoxInfoItem.SetLine( pDefLine, BOXINFO_LINE_VERT );
1632 pNewSet->Put( aBoxInfoItem );
1633 rReq.AppendItem( aBoxInfoItem );
1635 else
1637 SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
1638 aBoxInfoItem.SetLine( NULL, BOXINFO_LINE_HORI );
1639 aBoxInfoItem.SetLine( NULL, BOXINFO_LINE_VERT );
1640 pNewSet->Put( aBoxInfoItem );
1643 pOldSet->Put( rBorderAttr );
1644 pTabViewShell->ApplyAttributes( pNewSet, pOldSet );
1646 delete pOldSet;
1647 delete pNewSet;
1649 break;
1651 // ATTR_BACKGROUND (=SID_ATTR_BRUSH) muss ueber zwei IDs
1652 // gesetzt werden:
1653 case SID_BACKGROUND_COLOR:
1655 const SvxColorItem rNewColorItem = (const SvxColorItem&)
1656 pNewAttrs->Get( SID_BACKGROUND_COLOR );
1658 SvxBrushItem aBrushItem( (const SvxBrushItem&)
1659 pTabViewShell->GetSelectionPattern()->
1660 GetItem( ATTR_BACKGROUND ) );
1662 aBrushItem.SetColor( rNewColorItem.GetValue() );
1664 pTabViewShell->ApplyAttr( aBrushItem );
1666 break;
1668 case SID_ATTR_BRUSH:
1670 SvxBrushItem aBrushItem( (const SvxBrushItem&)
1671 pTabViewShell->GetSelectionPattern()->
1672 GetItem( ATTR_BACKGROUND ) );
1673 const SvxBrushItem& rNewBrushItem = (const SvxBrushItem&)
1674 pNewAttrs->Get( GetPool().GetWhich(nSlot) );
1675 aBrushItem.SetColor(rNewBrushItem.GetColor());
1676 pTabViewShell->ApplyAttr( aBrushItem );
1678 break;
1680 case SID_ATTR_BORDER_SHADOW:
1682 const SvxShadowItem& rNewShadowItem = (const SvxShadowItem&)
1683 pNewAttrs->Get( ATTR_SHADOW );
1684 pTabViewShell->ApplyAttr( rNewShadowItem );
1686 break;
1688 default:
1689 break;
1692 if( ! rReq.IsAPI() )
1693 if( ! rReq.IsDone() )
1694 rReq.Done();
1698 void ScFormatShell::GetAttrState( SfxItemSet& rSet )
1700 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1701 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
1702 const SvxBorderLine* pLine = pTabViewShell->GetDefaultFrameLine();
1703 const SvxBrushItem& rBrushItem = (const SvxBrushItem&)rAttrSet.Get( ATTR_BACKGROUND );
1704 SfxWhichIter aIter( rSet );
1705 USHORT nWhich = aIter.FirstWhich();
1707 rSet.Put( rAttrSet, FALSE );
1709 // choose font info according to selection script type
1710 BYTE nScript = 0; // GetSelectionScriptType never returns 0
1711 if ( rSet.GetItemState( ATTR_FONT ) != SFX_ITEM_UNKNOWN )
1713 if (!nScript) nScript = pTabViewShell->GetSelectionScriptType();
1714 ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT, nScript );
1716 if ( rSet.GetItemState( ATTR_FONT_HEIGHT ) != SFX_ITEM_UNKNOWN )
1718 if (!nScript) nScript = pTabViewShell->GetSelectionScriptType();
1719 ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_HEIGHT, nScript );
1722 while ( nWhich )
1724 switch(nWhich)
1726 case SID_BACKGROUND_COLOR:
1728 rSet.Put( SvxColorItem( rBrushItem.GetColor(), SID_BACKGROUND_COLOR ) );
1730 break;
1731 case SID_FRAME_LINECOLOR:
1733 rSet.Put( SvxColorItem( pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLOR ) );
1735 break;
1736 case SID_ATTR_BRUSH:
1738 rSet.Put( rBrushItem, GetPool().GetWhich(nWhich) );
1740 break;
1741 /* case SID_ATTR_ALIGN_LINEBREAK:
1743 const SfxBoolItem& rBreakItem = (const SfxBoolItem&)rAttrSet.Get( ATTR_LINEBREAK );
1744 rSet.Put( rBreakItem, GetPool().GetWhich(nWhich) );
1746 break;
1749 nWhich = aIter.NextWhich();
1753 //------------------------------------------------------------------
1755 void ScFormatShell::GetTextAttrState( SfxItemSet& rSet )
1757 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1758 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
1759 rSet.Put( rAttrSet, FALSE ); // ItemStates mitkopieren
1761 // choose font info according to selection script type
1762 BYTE nScript = 0; // GetSelectionScriptType never returns 0
1763 if ( rSet.GetItemState( ATTR_FONT_WEIGHT ) != SFX_ITEM_UNKNOWN )
1765 if (!nScript) nScript = pTabViewShell->GetSelectionScriptType();
1766 ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_WEIGHT, nScript );
1768 if ( rSet.GetItemState( ATTR_FONT_POSTURE ) != SFX_ITEM_UNKNOWN )
1770 if (!nScript) nScript = pTabViewShell->GetSelectionScriptType();
1771 ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_POSTURE, nScript );
1774 SfxItemState eState;
1775 // const SfxPoolItem* pItem;
1777 //--------------------------------------------------------------------
1778 // eigene Kontrolle ueber RadioButton-Funktionalitaet:
1779 //--------------------------------------------------------------------
1780 // Unterstreichung
1781 //------------------------
1783 eState = rAttrSet.GetItemState( ATTR_FONT_UNDERLINE, TRUE );
1784 if ( eState == SFX_ITEM_DONTCARE )
1786 rSet.InvalidateItem( SID_ULINE_VAL_NONE );
1787 rSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
1788 rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
1789 rSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
1791 else
1793 FontUnderline eUnderline = ((const SvxUnderlineItem&)
1794 rAttrSet.Get(ATTR_FONT_UNDERLINE)).GetLineStyle();
1795 USHORT nId = SID_ULINE_VAL_NONE;
1796 switch (eUnderline)
1798 case UNDERLINE_SINGLE: nId = SID_ULINE_VAL_SINGLE; break;
1799 case UNDERLINE_DOUBLE: nId = SID_ULINE_VAL_DOUBLE; break;
1800 case UNDERLINE_DOTTED: nId = SID_ULINE_VAL_DOTTED; break;
1801 default:
1802 break;
1804 rSet.Put( SfxBoolItem( nId, TRUE ) );
1807 //------------------------
1808 // horizontale Ausrichtung
1809 //------------------------
1811 const SvxHorJustifyItem* pHorJustify = NULL;
1812 const SvxVerJustifyItem* pVerJustify = NULL;
1813 SvxCellHorJustify eHorJustify = SVX_HOR_JUSTIFY_STANDARD;
1814 SvxCellVerJustify eVerJustify = SVX_VER_JUSTIFY_STANDARD;
1815 USHORT nWhich = 0;
1816 BOOL bJustifyStd = FALSE;
1817 SfxBoolItem aBoolItem ( 0, TRUE );
1819 eState = rAttrSet.GetItemState( ATTR_HOR_JUSTIFY, TRUE,
1820 (const SfxPoolItem**)&pHorJustify );
1821 switch ( eState )
1823 case SFX_ITEM_SET:
1825 eHorJustify = SvxCellHorJustify( pHorJustify->GetValue() );
1827 switch ( SvxCellHorJustify( pHorJustify->GetValue() ) )
1829 case SVX_HOR_JUSTIFY_STANDARD:
1830 break;
1832 case SVX_HOR_JUSTIFY_LEFT:
1833 nWhich = SID_ALIGNLEFT;
1834 break;
1836 case SVX_HOR_JUSTIFY_RIGHT:
1837 nWhich = SID_ALIGNRIGHT;
1838 break;
1840 case SVX_HOR_JUSTIFY_CENTER:
1841 nWhich = SID_ALIGNCENTERHOR;
1842 break;
1844 case SVX_HOR_JUSTIFY_BLOCK:
1845 nWhich = SID_ALIGNBLOCK;
1846 break;
1848 case SVX_HOR_JUSTIFY_REPEAT:
1849 default:
1850 bJustifyStd = TRUE;
1851 break;
1854 break;
1856 case SFX_ITEM_DONTCARE:
1857 rSet.InvalidateItem( SID_ALIGNLEFT );
1858 rSet.InvalidateItem( SID_ALIGNRIGHT );
1859 rSet.InvalidateItem( SID_ALIGNCENTERHOR );
1860 rSet.InvalidateItem( SID_ALIGNBLOCK );
1861 break;
1863 default:
1864 bJustifyStd = TRUE;
1865 break;
1868 if ( nWhich )
1870 aBoolItem.SetWhich( nWhich );
1871 rSet.Put( aBoolItem );
1873 else if ( bJustifyStd )
1875 aBoolItem.SetValue( FALSE );
1876 aBoolItem.SetWhich( SID_ALIGNLEFT ); rSet.Put( aBoolItem );
1877 aBoolItem.SetWhich( SID_ALIGNRIGHT ); rSet.Put( aBoolItem );
1878 aBoolItem.SetWhich( SID_ALIGNCENTERHOR ); rSet.Put( aBoolItem );
1879 aBoolItem.SetWhich( SID_ALIGNBLOCK ); rSet.Put( aBoolItem );
1880 bJustifyStd = FALSE;
1883 //------------------------
1884 // vertikale Ausrichtung
1885 //------------------------
1887 nWhich = 0;
1888 aBoolItem.SetValue( TRUE );
1890 eState = rAttrSet.GetItemState( ATTR_VER_JUSTIFY, TRUE,
1891 (const SfxPoolItem**)&pVerJustify );
1893 switch ( eState )
1895 case SFX_ITEM_SET:
1897 eVerJustify = SvxCellVerJustify( pVerJustify->GetValue() );
1899 switch ( eVerJustify )
1901 case SVX_VER_JUSTIFY_TOP:
1902 nWhich = SID_ALIGNTOP;
1903 break;
1905 case SVX_VER_JUSTIFY_BOTTOM:
1906 nWhich = SID_ALIGNBOTTOM;
1907 break;
1909 case SVX_VER_JUSTIFY_CENTER:
1910 nWhich = SID_ALIGNCENTERVER;
1911 break;
1913 case SVX_VER_JUSTIFY_STANDARD:
1914 default:
1915 bJustifyStd = TRUE;
1916 break;
1919 break;
1921 case SFX_ITEM_DONTCARE:
1922 rSet.InvalidateItem( SID_ALIGNTOP );
1923 rSet.InvalidateItem( SID_ALIGNBOTTOM );
1924 rSet.InvalidateItem( SID_ALIGNCENTERVER );
1925 break;
1927 default:
1928 bJustifyStd = TRUE;
1929 break;
1932 if ( nWhich )
1934 aBoolItem.SetWhich( nWhich );
1935 rSet.Put( aBoolItem );
1937 else if ( bJustifyStd )
1939 aBoolItem.SetValue( FALSE );
1940 aBoolItem.SetWhich( SID_ALIGNTOP ); rSet.Put( aBoolItem );
1941 aBoolItem.SetWhich( SID_ALIGNBOTTOM ); rSet.Put( aBoolItem );
1942 aBoolItem.SetWhich( SID_ALIGNCENTERVER ); rSet.Put( aBoolItem );
1947 //------------------------------------------------------------------
1949 void ScFormatShell::GetBorderState( SfxItemSet& rSet )
1951 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1952 SvxBoxItem aBoxItem( ATTR_BORDER );
1953 SvxBoxInfoItem aInfoItem( ATTR_BORDER_INNER );
1955 pTabViewShell->GetSelectionFrame( aBoxItem, aInfoItem );
1957 if ( rSet.GetItemState( ATTR_BORDER ) != SFX_ITEM_UNKNOWN )
1958 rSet.Put( aBoxItem );
1959 if ( rSet.GetItemState( ATTR_BORDER_INNER ) != SFX_ITEM_UNKNOWN )
1960 rSet.Put( aInfoItem );
1963 //------------------------------------------------------------------
1965 void ScFormatShell::GetAlignState( SfxItemSet& rSet )
1967 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1968 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
1969 SfxWhichIter aIter(rSet);
1970 USHORT nWhich = aIter.FirstWhich();
1972 SvxCellHorJustify eHAlign = SVX_HOR_JUSTIFY_STANDARD;
1973 bool bHasHAlign = rAttrSet.GetItemState( ATTR_HOR_JUSTIFY ) != SFX_ITEM_DONTCARE;
1974 if( bHasHAlign )
1975 eHAlign = (SvxCellHorJustify)((const SvxHorJustifyItem&) rAttrSet.Get( ATTR_HOR_JUSTIFY )).GetValue();
1977 SvxCellVerJustify eVAlign = SVX_VER_JUSTIFY_STANDARD;
1978 bool bHasVAlign = rAttrSet.GetItemState( ATTR_VER_JUSTIFY ) != SFX_ITEM_DONTCARE;
1979 if( bHasVAlign )
1980 eVAlign = (SvxCellVerJustify)((const SvxVerJustifyItem&) rAttrSet.Get( ATTR_VER_JUSTIFY )).GetValue();
1982 while ( nWhich )
1984 switch ( nWhich )
1986 case SID_H_ALIGNCELL:
1987 if ( bHasHAlign )
1988 rSet.Put( SvxHorJustifyItem( eHAlign, nWhich ));
1989 break;
1990 case SID_V_ALIGNCELL:
1991 if ( bHasVAlign )
1992 rSet.Put( SvxVerJustifyItem( eVAlign, nWhich ));
1993 break;
1995 // pseudo slots for Format menu
1996 case SID_ALIGN_ANY_HDEFAULT:
1997 case SID_ALIGN_ANY_LEFT:
1998 case SID_ALIGN_ANY_HCENTER:
1999 case SID_ALIGN_ANY_RIGHT:
2000 case SID_ALIGN_ANY_JUSTIFIED:
2001 rSet.Put( SfxBoolItem( nWhich, bHasHAlign && (eHAlign == lclConvertSlotToHAlign( nWhich )) ) );
2002 break;
2003 case SID_ALIGN_ANY_VDEFAULT:
2004 case SID_ALIGN_ANY_TOP:
2005 case SID_ALIGN_ANY_VCENTER:
2006 case SID_ALIGN_ANY_BOTTOM:
2007 rSet.Put( SfxBoolItem( nWhich, bHasVAlign && (eVAlign == lclConvertSlotToVAlign( nWhich )) ) );
2008 break;
2010 nWhich = aIter.NextWhich();
2014 void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
2016 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2017 ScDocument* pDoc = pViewData->GetDocument();
2018 short nType = GetCurrentNumberFormatType();
2020 SfxWhichIter aIter(rSet);
2021 USHORT nWhich = aIter.FirstWhich();
2022 while ( nWhich )
2024 switch ( nWhich )
2026 case SID_NUMBER_FORMAT:
2028 String aFormatCode; // bleibt leer, wenn dont-care
2030 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
2031 if ( rAttrSet.GetItemState( ATTR_VALUE_FORMAT ) != SFX_ITEM_DONTCARE )
2033 ULONG nNumberFormat = ((const SfxUInt32Item&)rAttrSet.Get(
2034 ATTR_VALUE_FORMAT )).GetValue();
2036 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
2037 const SvNumberformat* pFormatEntry = pFormatter->GetEntry( nNumberFormat );
2038 if ( pFormatEntry )
2039 aFormatCode = pFormatEntry->GetFormatstring();
2042 rSet.Put( SfxStringItem( nWhich, aFormatCode ) );
2044 break;
2045 case SID_NUMBER_SCIENTIFIC:
2046 rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_SCIENTIFIC)) );
2047 break;
2048 case SID_NUMBER_DATE:
2049 rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_DATE)) );
2050 break;
2051 case SID_NUMBER_CURRENCY:
2052 rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_CURRENCY)) );
2053 break;
2054 case SID_NUMBER_PERCENT:
2055 rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_PERCENT)) );
2056 break;
2057 case SID_NUMBER_TIME:
2058 rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_TIME)) );
2059 break;
2061 nWhich = aIter.NextWhich();
2066 void ScFormatShell::ExecuteTextDirection( SfxRequest& rReq )
2068 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2069 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
2070 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
2072 SC_MOD()->InputEnterHandler();
2073 pTabViewShell->UpdateInputHandler();
2076 USHORT nSlot = rReq.GetSlot();
2077 switch( nSlot )
2079 case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
2080 case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
2082 BOOL bVert = (nSlot == SID_TEXTDIRECTION_TOP_TO_BOTTOM);
2083 ScPatternAttr aAttr( GetViewData()->GetDocument()->GetPool() );
2084 SfxItemSet& rItemSet = aAttr.GetItemSet();
2085 rItemSet.Put( SfxBoolItem( ATTR_STACKED, bVert ) );
2086 rItemSet.Put( SfxBoolItem( ATTR_VERTICAL_ASIAN, bVert ) );
2087 pTabViewShell->ApplySelectionPattern( aAttr );
2088 pTabViewShell->AdjustBlockHeight();
2090 break;
2092 case SID_ATTR_PARA_LEFT_TO_RIGHT:
2093 case SID_ATTR_PARA_RIGHT_TO_LEFT:
2095 SvxFrameDirection eDirection = ( nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT ) ?
2096 FRMDIR_HORI_LEFT_TOP : FRMDIR_HORI_RIGHT_TOP;
2097 pTabViewShell->ApplyAttr( SvxFrameDirectionItem( eDirection, ATTR_WRITINGDIR ) );
2099 break;
2103 void ScFormatShell::GetTextDirectionState( SfxItemSet& rSet )
2105 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2106 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
2108 BOOL bVertDontCare =
2109 (rAttrSet.GetItemState( ATTR_VERTICAL_ASIAN ) == SFX_ITEM_DONTCARE) ||
2110 (rAttrSet.GetItemState( ATTR_STACKED ) == SFX_ITEM_DONTCARE);
2111 BOOL bLeftRight = !bVertDontCare &&
2112 !((const SfxBoolItem&) rAttrSet.Get( ATTR_STACKED )).GetValue();
2113 BOOL bTopBottom = !bVertDontCare && !bLeftRight &&
2114 ((const SfxBoolItem&) rAttrSet.Get( ATTR_VERTICAL_ASIAN )).GetValue();
2116 BOOL bBidiDontCare = (rAttrSet.GetItemState( ATTR_WRITINGDIR ) == SFX_ITEM_DONTCARE);
2117 EEHorizontalTextDirection eBidiDir = EE_HTEXTDIR_DEFAULT;
2118 if ( !bBidiDontCare )
2120 SvxFrameDirection eCellDir = (SvxFrameDirection)((const SvxFrameDirectionItem&)
2121 rAttrSet.Get( ATTR_WRITINGDIR )).GetValue();
2122 if ( eCellDir == FRMDIR_ENVIRONMENT )
2123 eBidiDir = (EEHorizontalTextDirection)GetViewData()->GetDocument()->
2124 GetEditTextDirection( GetViewData()->GetTabNo() );
2125 else if ( eCellDir == FRMDIR_HORI_RIGHT_TOP )
2126 eBidiDir = EE_HTEXTDIR_R2L;
2127 else
2128 eBidiDir = EE_HTEXTDIR_L2R;
2131 SvtLanguageOptions aLangOpt;
2132 BOOL bDisableCTLFont = !aLangOpt.IsCTLFontEnabled();
2133 BOOL bDisableVerticalText = !aLangOpt.IsVerticalTextEnabled();
2135 SfxWhichIter aIter( rSet );
2136 USHORT nWhich = aIter.FirstWhich();
2137 while( nWhich )
2139 switch( nWhich )
2141 case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
2142 case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
2143 if ( bDisableVerticalText )
2144 rSet.DisableItem( nWhich );
2145 else
2147 if( bVertDontCare )
2148 rSet.InvalidateItem( nWhich );
2149 else if ( nWhich == SID_TEXTDIRECTION_LEFT_TO_RIGHT )
2150 rSet.Put( SfxBoolItem( nWhich, bLeftRight ) );
2151 else
2152 rSet.Put( SfxBoolItem( nWhich, bTopBottom ) );
2154 break;
2156 case SID_ATTR_PARA_LEFT_TO_RIGHT:
2157 case SID_ATTR_PARA_RIGHT_TO_LEFT:
2158 if ( bDisableCTLFont )
2159 rSet.DisableItem( nWhich );
2160 else
2162 if ( bTopBottom )
2163 rSet.DisableItem( nWhich );
2164 else if ( bBidiDontCare )
2165 rSet.InvalidateItem( nWhich );
2166 else if ( nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT )
2167 rSet.Put( SfxBoolItem( nWhich, eBidiDir == EE_HTEXTDIR_L2R ) );
2168 else
2169 rSet.Put( SfxBoolItem( nWhich, eBidiDir == EE_HTEXTDIR_R2L ) );
2172 nWhich = aIter.NextWhich();
2176 void ScFormatShell::ExecFormatPaintbrush( SfxRequest& rReq )
2178 ScViewFunc* pView = pViewData->GetView();
2179 if ( pView->HasPaintBrush() )
2181 // cancel paintbrush mode
2182 pView->ResetBrushDocument();
2184 else
2186 BOOL bLock = FALSE;
2187 const SfxItemSet *pArgs = rReq.GetArgs();
2188 if( pArgs && pArgs->Count() >= 1 )
2189 bLock = static_cast<const SfxBoolItem&>(pArgs->Get(SID_FORMATPAINTBRUSH)).GetValue();
2191 // in case of multi selection, deselect all and use the cursor position
2192 ScRange aDummy;
2193 if ( pViewData->GetSimpleArea(aDummy) != SC_MARK_SIMPLE )
2194 pView->Unmark();
2196 ScDocument* pBrushDoc = new ScDocument( SCDOCMODE_CLIP );
2197 pView->CopyToClip( pBrushDoc, FALSE, TRUE );
2198 pView->SetBrushDocument( pBrushDoc, bLock );
2202 void ScFormatShell::StateFormatPaintbrush( SfxItemSet& rSet )
2204 if ( pViewData->HasEditView( pViewData->GetActivePart() ) )
2205 rSet.DisableItem( SID_FORMATPAINTBRUSH );
2206 else
2207 rSet.Put( SfxBoolItem( SID_FORMATPAINTBRUSH, pViewData->GetView()->HasPaintBrush() ) );
2210 short ScFormatShell::GetCurrentNumberFormatType()
2212 short nType = NUMBERFORMAT_ALL;
2213 ScDocument* pDoc = GetViewData()->GetDocument();
2214 ScMarkData aMark(GetViewData()->GetMarkData());
2215 const SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
2216 if (!pFormatter)
2217 return nType;
2219 // TODO: Find out how to get a selected table range in case multiple tables
2220 // are selected. Currently we only check for the current active table.
2222 if ( aMark.IsMarked() || aMark.IsMultiMarked() )
2224 aMark.MarkToMulti();
2225 ScRange aRange;
2226 aMark.GetMultiMarkArea(aRange);
2228 const ScMarkArray* pArray = aMark.GetArray();
2229 if (!pArray)
2230 return nType;
2232 short nComboType = NUMBERFORMAT_ALL;
2233 bool bFirstItem = true;
2234 for (SCCOL nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); ++nCol)
2236 const ScMarkArray& rColArray = pArray[nCol];
2237 if (!rColArray.HasMarks())
2238 continue;
2240 SCROW nRow1, nRow2;
2241 ScMarkArrayIter aMarkIter(&rColArray);
2242 while (aMarkIter.Next(nRow1, nRow2))
2244 ScRange aColRange(nCol, nRow1, aRange.aStart.Tab());
2245 aColRange.aEnd.SetRow(nRow2);
2246 sal_uInt32 nNumFmt = pDoc->GetNumberFormat(aColRange);
2247 const SvNumberformat* pEntry = pFormatter->GetEntry(nNumFmt);
2248 if (!pEntry)
2249 return 0;
2251 short nThisType = pEntry->GetType();
2252 if (bFirstItem)
2254 bFirstItem = false;
2255 nComboType = nThisType;
2257 else if (nComboType != nThisType)
2258 // mixed number format type.
2259 return NUMBERFORMAT_ALL;
2262 nType = nComboType;
2264 else
2266 sal_uInt32 nNumFmt;
2267 pDoc->GetNumberFormat( pViewData->GetCurX(), pViewData->GetCurY(),
2268 pViewData->GetTabNo(), nNumFmt );
2269 const SvNumberformat* pEntry = pFormatter->GetEntry( nNumFmt );
2270 nType = pEntry ? pEntry->GetType() : 0;
2272 return nType;