fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / formatsh.cxx
blob586a2364b4ee2a33e8fe491f0e8b3d6ac700ebeb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/container/XNameAccess.hpp>
24 #include "scitems.hxx"
25 #include <editeng/borderline.hxx>
26 #include <editeng/eeitem.hxx>
28 #include <sfx2/app.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/objface.hxx>
32 #include <sfx2/request.hxx>
33 #include <svl/whiter.hxx>
34 #include <vcl/msgbox.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/zformat.hxx>
38 #include <svl/languageoptions.hxx>
39 #include <editeng/boxitem.hxx>
40 #include <editeng/langitem.hxx>
41 #include <svx/numinf.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <sfx2/templdlg.hxx>
44 #include <sfx2/tplpitem.hxx>
45 #include <editeng/svxenum.hxx>
46 #include <svx/algitem.hxx>
47 #include <editeng/wghtitem.hxx>
48 #include <editeng/postitem.hxx>
49 #include <editeng/udlnitem.hxx>
50 #include <editeng/lineitem.hxx>
51 #include <editeng/colritem.hxx>
52 #include <editeng/brushitem.hxx>
53 #include <editeng/frmdiritem.hxx>
54 #include <editeng/scripttypeitem.hxx>
55 #include <svtools/colorcfg.hxx>
56 #include <editeng/shaditem.hxx>
57 #include <editeng/justifyitem.hxx>
59 #include "formatsh.hxx"
60 #include "sc.hrc"
61 #include "globstr.hrc"
62 #include "docsh.hxx"
63 #include "patattr.hxx"
64 #include "scmod.hxx"
65 #include "stlpool.hxx"
66 #include "stlsheet.hxx"
67 #include "printfun.hxx"
68 #include "docpool.hxx"
69 #include "scresid.hxx"
70 #include "tabvwsh.hxx"
71 #include "undostyl.hxx"
72 #include "markdata.hxx"
73 #include "markarr.hxx"
75 #define ScFormatShell
76 #define TableFont
77 #define FormatForSelection
78 #include "scslots.hxx"
80 #include "scabstdlg.hxx"
81 #include <editeng/fontitem.hxx>
83 #include <boost/scoped_ptr.hpp>
85 using namespace ::com::sun::star;
87 namespace {
89 SvxCellHorJustify lclConvertSlotToHAlign( sal_uInt16 nSlot )
91 SvxCellHorJustify eHJustify = SVX_HOR_JUSTIFY_STANDARD;
92 switch( nSlot )
94 case SID_ALIGN_ANY_HDEFAULT: eHJustify = SVX_HOR_JUSTIFY_STANDARD; break;
95 case SID_ALIGN_ANY_LEFT: eHJustify = SVX_HOR_JUSTIFY_LEFT; break;
96 case SID_ALIGN_ANY_HCENTER: eHJustify = SVX_HOR_JUSTIFY_CENTER; break;
97 case SID_ALIGN_ANY_RIGHT: eHJustify = SVX_HOR_JUSTIFY_RIGHT; break;
98 case SID_ALIGN_ANY_JUSTIFIED: eHJustify = SVX_HOR_JUSTIFY_BLOCK; break;
99 default: OSL_FAIL( "lclConvertSlotToHAlign - invalid slot" );
101 return eHJustify;
104 SvxCellVerJustify lclConvertSlotToVAlign( sal_uInt16 nSlot )
106 SvxCellVerJustify eVJustify = SVX_VER_JUSTIFY_STANDARD;
107 switch( nSlot )
109 case SID_ALIGN_ANY_VDEFAULT: eVJustify = SVX_VER_JUSTIFY_STANDARD; break;
110 case SID_ALIGN_ANY_TOP: eVJustify = SVX_VER_JUSTIFY_TOP; break;
111 case SID_ALIGN_ANY_VCENTER: eVJustify = SVX_VER_JUSTIFY_CENTER; break;
112 case SID_ALIGN_ANY_BOTTOM: eVJustify = SVX_VER_JUSTIFY_BOTTOM; break;
113 default: OSL_FAIL( "lclConvertSlotToVAlign - invalid slot" );
115 return eVJustify;
118 } // namespace
120 TYPEINIT1( ScFormatShell, SfxShell );
122 SFX_IMPL_INTERFACE(ScFormatShell, SfxShell)
124 void ScFormatShell::InitInterface_Impl()
126 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_SERVER,
127 RID_OBJECTBAR_FORMAT);
130 ScFormatShell::ScFormatShell(ScViewData* pData) :
131 SfxShell(pData->GetViewShell()),
132 pViewData(pData)
134 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
136 SetPool( &pTabViewShell->GetPool() );
137 ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
138 SetUndoManager( pMgr );
139 if ( !pViewData->GetDocument()->IsUndoEnabled() )
141 pMgr->SetMaxUndoActionCount( 0 );
143 SetHelpId(HID_SCSHELL_FORMATSH);
144 SetName(OUString("Format"));
147 ScFormatShell::~ScFormatShell()
151 void ScFormatShell::GetStyleState( SfxItemSet& rSet )
153 ScDocument* pDoc = GetViewData()->GetDocument();
154 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
155 SfxStyleSheetBasePool* pStylePool = pDoc->GetStyleSheetPool();
157 bool bProtected = false;
158 SCTAB nTabCount = pDoc->GetTableCount();
159 for (SCTAB i=0; i<nTabCount; i++)
160 if (pDoc->IsTabProtected(i)) // look after protected table
161 bProtected = true;
163 SfxWhichIter aIter(rSet);
164 sal_uInt16 nWhich = aIter.FirstWhich();
165 sal_uInt16 nSlotId = 0;
167 while ( nWhich )
169 nSlotId = SfxItemPool::IsWhich( nWhich )
170 ? GetPool().GetSlotId( nWhich )
171 : nWhich;
173 switch ( nSlotId )
175 case SID_STYLE_APPLY:
176 if ( !pStylePool )
177 rSet.DisableItem( nSlotId );
178 break;
180 case SID_STYLE_FAMILY2: // cell style sheets
182 SfxStyleSheet* pStyleSheet = const_cast<SfxStyleSheet*>(
183 pTabViewShell->GetStyleSheetFromMarked());
185 if ( pStyleSheet )
186 rSet.Put( SfxTemplateItem( nSlotId, pStyleSheet->GetName() ) );
187 else
188 rSet.Put( SfxTemplateItem( nSlotId, OUString() ) );
190 break;
192 case SID_STYLE_FAMILY4: // page style sheets
194 SCTAB nCurTab = GetViewData()->GetTabNo();
195 OUString aPageStyle = pDoc->GetPageStyle( nCurTab );
196 SfxStyleSheet* pStyleSheet = pStylePool ? static_cast<SfxStyleSheet*>(pStylePool->
197 Find( aPageStyle, SFX_STYLE_FAMILY_PAGE )) : NULL;
199 if ( pStyleSheet )
200 rSet.Put( SfxTemplateItem( nSlotId, aPageStyle ) );
201 else
202 rSet.Put( SfxTemplateItem( nSlotId, OUString() ) );
204 break;
206 case SID_STYLE_WATERCAN:
208 rSet.Put( SfxBoolItem( nSlotId, SC_MOD()->GetIsWaterCan() ) );
210 break;
212 case SID_STYLE_UPDATE_BY_EXAMPLE:
214 SfxPoolItem* pItem = NULL;
215 pTabViewShell->GetViewFrame()->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
216 SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
218 bool bPage = pFamilyItem && SFX_STYLE_FAMILY_PAGE == SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue());
219 delete pItem;
221 if ( bProtected || bPage )
222 rSet.DisableItem( nSlotId );
224 break;
226 case SID_STYLE_EDIT:
227 case SID_STYLE_DELETE:
228 case SID_STYLE_HIDE:
229 case SID_STYLE_SHOW:
231 SfxPoolItem* pItem = NULL;
232 pTabViewShell->GetViewFrame()->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
233 SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
234 bool bPage = pFamilyItem && SFX_STYLE_FAMILY_PAGE == SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue());
235 delete pItem;
237 if ( bProtected && !bPage )
238 rSet.DisableItem( nSlotId );
240 break;
242 default:
243 break;
246 nWhich = aIter.NextWhich();
250 void ScFormatShell::ExecuteStyle( SfxRequest& rReq )
252 // in case of vertical toolbar
253 if ( !rReq.GetArgs() )
255 pViewData->GetDispatcher().Execute( SID_STYLE_DESIGNER, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
256 return;
259 SfxBindings& rBindings = pViewData->GetBindings();
260 const SfxItemSet* pArgs = rReq.GetArgs();
261 const sal_uInt16 nSlotId = rReq.GetSlot();
262 const SCTAB nCurTab = GetViewData()->GetTabNo();
263 ScDocShell* pDocSh = GetViewData()->GetDocShell();
264 ScTabViewShell* pTabViewShell= GetViewData()->GetViewShell();
265 ScDocument& rDoc = pDocSh->GetDocument();
266 ScMarkData& rMark = GetViewData()->GetMarkData();
267 ScModule* pScMod = SC_MOD();
268 OUString aRefName;
269 bool bUndo = rDoc.IsUndoEnabled();
270 SfxStyleSheetBasePool* pStylePool = rDoc.GetStyleSheetPool();
272 if ( (nSlotId == SID_STYLE_PREVIEW)
273 || (nSlotId == SID_STYLE_END_PREVIEW) )
275 if (nSlotId == SID_STYLE_PREVIEW)
277 SfxStyleFamily eFamily = SFX_STYLE_FAMILY_PARA;
278 const SfxPoolItem* pFamItem;
279 if ( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_STYLE_FAMILY, true, &pFamItem ) )
280 eFamily = (SfxStyleFamily) static_cast<const SfxUInt16Item*>(pFamItem)->GetValue();
281 const SfxPoolItem* pNameItem;
282 OUString aStyleName;
283 if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem ))
284 aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue();
285 if ( eFamily == SFX_STYLE_FAMILY_PARA ) // CellStyles
287 ScMarkData aFuncMark( pViewData->GetMarkData() );
288 ScViewUtil::UnmarkFiltered( aFuncMark, &rDoc );
289 aFuncMark.MarkToMulti();
291 if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() )
293 SCCOL nCol = pViewData->GetCurX();
294 SCROW nRow = pViewData->GetCurY();
295 SCTAB nTab = pViewData->GetTabNo();
296 ScRange aRange( nCol, nRow, nTab );
297 aFuncMark.SetMarkArea( aRange );
299 rDoc.SetPreviewSelection( aFuncMark );
300 ScStyleSheet* pPreviewStyle = static_cast<ScStyleSheet*>( pStylePool->Find( aStyleName, eFamily ) );
301 rDoc.SetPreviewCellStyle( pPreviewStyle );
302 ScPatternAttr aAttr( *rDoc.GetSelectionPattern( aFuncMark ) );
303 aAttr.SetStyleSheet( pPreviewStyle );
305 SfxItemSet aItemSet( GetPool() );
307 ScPatternAttr aNewAttrs( GetViewData()->GetDocument()->GetPool() );
308 SfxItemSet& rNewSet = aNewAttrs.GetItemSet();
309 rNewSet.Put( aItemSet, false );
311 rDoc.ApplySelectionPattern( aNewAttrs, rDoc.GetPreviewSelection() );
312 pTabViewShell->UpdateSelectionArea( aFuncMark, &aAttr );
315 else
317 // No mark at all happens when creating a new document, in which
318 // case the selection pattern obtained would be empty (created of
319 // GetPool()) anyway and nothing needs to be applied.
320 ScMarkData aPreviewMark( rDoc.GetPreviewSelection());
321 if (aPreviewMark.IsMarked() || aPreviewMark.IsMultiMarked())
323 ScPatternAttr aAttr( *rDoc.GetSelectionPattern( aPreviewMark ) );
324 if ( ScStyleSheet* pPreviewStyle = rDoc.GetPreviewCellStyle() )
325 aAttr.SetStyleSheet( pPreviewStyle );
326 rDoc.SetPreviewCellStyle(NULL);
328 SfxItemSet aItemSet( GetPool() );
330 ScPatternAttr aNewAttrs( GetViewData()->GetDocument()->GetPool() );
331 SfxItemSet& rNewSet = aNewAttrs.GetItemSet();
332 rNewSet.Put( aItemSet, false );
333 rDoc.ApplySelectionPattern( aNewAttrs, aPreviewMark );
334 pTabViewShell->UpdateSelectionArea( aPreviewMark, &aAttr );
338 else if ( (nSlotId == SID_STYLE_NEW)
339 || (nSlotId == SID_STYLE_EDIT)
340 || (nSlotId == SID_STYLE_DELETE)
341 || (nSlotId == SID_STYLE_HIDE)
342 || (nSlotId == SID_STYLE_SHOW)
343 || (nSlotId == SID_STYLE_APPLY)
344 || (nSlotId == SID_STYLE_WATERCAN)
345 || (nSlotId == SID_STYLE_FAMILY)
346 || (nSlotId == SID_STYLE_NEW_BY_EXAMPLE)
347 || (nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE) )
349 SfxStyleSheetBase* pStyleSheet = NULL;
351 bool bStyleToMarked = false;
352 bool bListAction = false;
353 bool bAddUndo = false; // add ScUndoModifyStyle (style modified)
354 ScStyleSaveData aOldData; // for undo/redo
355 ScStyleSaveData aNewData;
357 SfxStyleFamily eFamily = SFX_STYLE_FAMILY_PARA;
358 const SfxPoolItem* pFamItem;
359 if ( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_STYLE_FAMILY, true, &pFamItem ) )
360 eFamily = (SfxStyleFamily) static_cast<const SfxUInt16Item*>(pFamItem)->GetValue();
361 else if ( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_STYLE_FAMILYNAME, true, &pFamItem ) )
363 OUString sFamily = static_cast<const SfxStringItem*>(pFamItem)->GetValue();
364 if (sFamily == "CellStyles")
365 eFamily = SFX_STYLE_FAMILY_PARA;
366 else if (sFamily == "PageStyles")
367 eFamily = SFX_STYLE_FAMILY_PAGE;
370 OUString aStyleName;
371 sal_uInt16 nRetMask = 0xffff;
373 pStylePool->SetSearchMask( eFamily, SFXSTYLEBIT_ALL );
375 switch ( nSlotId )
377 case SID_STYLE_NEW:
379 const SfxPoolItem* pNameItem;
380 if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem ))
381 aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue();
383 const SfxPoolItem* pRefItem=NULL;
384 if (pArgs && SfxItemState::SET == pArgs->GetItemState( SID_STYLE_REFERENCE, true, &pRefItem ))
386 if(pRefItem!=NULL)
387 aRefName = static_cast<const SfxStringItem*>(pRefItem)->GetValue();
390 pStyleSheet = &(pStylePool->Make( aStyleName, eFamily,
391 SFXSTYLEBIT_USERDEF ) );
393 if ( pStyleSheet && pStyleSheet->HasParentSupport() )
394 pStyleSheet->SetParent(aRefName);
396 break;
398 case SID_STYLE_APPLY:
400 SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_APPLY_STYLE, false );
401 SFX_REQUEST_ARG( rReq, pFamilyItem, SfxStringItem, SID_STYLE_FAMILYNAME, false );
402 if ( pFamilyItem && pNameItem )
404 com::sun::star::uno::Reference< com::sun::star::style::XStyleFamiliesSupplier > xModel(pDocSh->GetModel(), com::sun::star::uno::UNO_QUERY);
407 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xStyles;
408 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xCont = xModel->getStyleFamilies();
409 xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
410 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xInfo;
411 xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
412 OUString aUIName;
413 xInfo->getPropertyValue("DisplayName") >>= aUIName;
414 if ( !aUIName.isEmpty() )
415 rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
417 catch( com::sun::star::uno::Exception& )
422 //fall-through
423 case SID_STYLE_EDIT:
424 case SID_STYLE_DELETE:
425 case SID_STYLE_HIDE:
426 case SID_STYLE_SHOW:
427 case SID_STYLE_NEW_BY_EXAMPLE:
429 const SfxPoolItem* pNameItem;
430 if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem ))
431 aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue();
432 pStyleSheet = pStylePool->Find( aStyleName, eFamily );
434 aOldData.InitFromStyle( pStyleSheet );
436 break;
438 case SID_STYLE_WATERCAN:
440 bool bWaterCan = pScMod->GetIsWaterCan();
442 if( !bWaterCan )
444 const SfxPoolItem* pItem;
446 if ( SfxItemState::SET ==
447 pArgs->GetItemState( nSlotId, true, &pItem ) )
449 const SfxStringItem* pStrItem = PTR_CAST(SfxStringItem,pItem);
450 if ( pStrItem )
452 aStyleName = pStrItem->GetValue();
453 pStyleSheet = pStylePool->Find( aStyleName, eFamily );
455 if ( pStyleSheet )
457 static_cast<ScStyleSheetPool*>(pStylePool)->
458 SetActualStyleSheet( pStyleSheet );
459 rReq.Done();
465 if ( !bWaterCan && pStyleSheet )
467 pScMod->SetWaterCan( true );
468 pTabViewShell->SetActivePointer( Pointer(PointerStyle::Fill) );
469 rReq.Done();
471 else
473 pScMod->SetWaterCan( false );
474 pTabViewShell->SetActivePointer( Pointer(PointerStyle::Arrow) );
475 rReq.Done();
478 break;
480 default:
481 break;
484 // set new style for WaterCan-Mode
485 if ( nSlotId == SID_STYLE_APPLY && pScMod->GetIsWaterCan() && pStyleSheet )
486 static_cast<ScStyleSheetPool*>(pStylePool)->SetActualStyleSheet( pStyleSheet );
488 switch ( eFamily )
490 case SFX_STYLE_FAMILY_PARA:
492 switch ( nSlotId )
494 case SID_STYLE_DELETE:
496 if ( pStyleSheet )
498 pTabViewShell->RemoveStyleSheetInUse( pStyleSheet );
499 pStylePool->Remove( pStyleSheet );
500 pTabViewShell->InvalidateAttribs();
501 nRetMask = sal_uInt16(true);
502 bAddUndo = true;
503 rReq.Done();
505 else
506 nRetMask = sal_uInt16(false);
508 break;
510 case SID_STYLE_HIDE:
511 case SID_STYLE_SHOW:
513 if ( pStyleSheet )
515 pStyleSheet->SetHidden( nSlotId == SID_STYLE_HIDE );
516 pTabViewShell->InvalidateAttribs();
517 rReq.Done();
519 else
520 nRetMask = sal_uInt16(false);
522 break;
524 case SID_STYLE_APPLY:
526 if ( pStyleSheet && !pScMod->GetIsWaterCan() )
528 // apply style sheet to document
529 pTabViewShell->SetStyleSheetToMarked( static_cast<SfxStyleSheet*>(pStyleSheet) );
530 pTabViewShell->InvalidateAttribs();
531 rReq.Done();
534 break;
536 case SID_STYLE_NEW_BY_EXAMPLE:
537 case SID_STYLE_UPDATE_BY_EXAMPLE:
539 // create/replace style sheet by attributes
540 // at cursor position:
542 const ScPatternAttr* pAttrItem = NULL;
544 // Die Abfrage, ob markiert ist, war hier immer falsch,
545 // darum jetzt gar nicht mehr, und einfach vom Cursor.
546 // Wenn Attribute aus der Selektion genommen werden sollen,
547 // muss noch darauf geachtet werden, Items aus Vorlagen nicht
548 // zu uebernehmen (GetSelectionPattern sammelt auch Items aus
549 // Vorlagen zusammen) (#44748#)
550 // pAttrItem = GetSelectionPattern();
552 // ScViewData* pViewData = GetViewData();
553 SCCOL nCol = pViewData->GetCurX();
554 SCROW nRow = pViewData->GetCurY();
555 pAttrItem = rDoc.GetPattern( nCol, nRow, nCurTab );
557 SfxItemSet aAttrSet = pAttrItem->GetItemSet();
558 aAttrSet.ClearItem( ATTR_MERGE );
559 aAttrSet.ClearItem( ATTR_MERGE_FLAG );
560 // bedingte Formatierung und Gueltigkeit nicht uebernehmen,
561 // weil sie in der Vorlage nicht editiert werden koennen
562 aAttrSet.ClearItem( ATTR_VALIDDATA );
563 aAttrSet.ClearItem( ATTR_CONDITIONAL );
565 if ( SID_STYLE_NEW_BY_EXAMPLE == nSlotId )
567 if ( bUndo )
569 OUString aUndo = ScGlobal::GetRscString( STR_UNDO_EDITCELLSTYLE );
570 pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
571 bListAction = true;
574 bool bConvertBack = false;
575 SfxStyleSheet* pSheetInUse = const_cast<SfxStyleSheet*>(
576 pTabViewShell->GetStyleSheetFromMarked());
578 // wenn neuer Style vorhanden und in der Selektion
579 // verwendet wird, so darf der Parent nicht uebernommen
580 // werden:
582 if ( pStyleSheet && pSheetInUse && pStyleSheet == pSheetInUse )
583 pSheetInUse = NULL;
585 // wenn bereits vorhanden, erstmal entfernen...
586 if ( pStyleSheet )
588 // Style-Pointer zu Namen vor Erase,
589 // weil Zellen sonst ungueltige Pointer
590 // enthalten.
591 //!!! bei Gelenheit mal eine Methode, die
592 // das fuer einen bestimmten Style macht
593 rDoc.StylesToNames();
594 bConvertBack = true;
595 pStylePool->Remove(pStyleSheet);
598 // ...und neu anlegen
599 pStyleSheet = &pStylePool->Make( aStyleName, eFamily,
600 SFXSTYLEBIT_USERDEF );
602 // wenn ein Style vorhanden ist, so wird dieser
603 // Parent der neuen Vorlage:
604 if ( pSheetInUse && pStyleSheet->HasParentSupport() )
605 pStyleSheet->SetParent( pSheetInUse->GetName() );
607 if ( bConvertBack )
608 // Namen zu Style-Pointer
609 rDoc.UpdStlShtPtrsFrmNms();
610 else
611 rDoc.GetPool()->CellStyleCreated( aStyleName, &rDoc );
613 // Attribute uebernehmen und Style anwenden
614 pStyleSheet->GetItemSet().Put( aAttrSet );
615 pTabViewShell->UpdateStyleSheetInUse( pStyleSheet );
617 // call SetStyleSheetToMarked after adding the ScUndoModifyStyle
618 // (pStyleSheet pointer is used!)
619 bStyleToMarked = true;
621 else // ( nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE )
623 pStyleSheet = const_cast<SfxStyleSheet*>(pTabViewShell->GetStyleSheetFromMarked());
625 if ( pStyleSheet )
627 aOldData.InitFromStyle( pStyleSheet );
629 if ( bUndo )
631 OUString aUndo = ScGlobal::GetRscString( STR_UNDO_EDITCELLSTYLE );
632 pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
633 bListAction = true;
636 pStyleSheet->GetItemSet().Put( aAttrSet );
637 pTabViewShell->UpdateStyleSheetInUse( pStyleSheet );
639 // call SetStyleSheetToMarked after adding the ScUndoModifyStyle
640 // (pStyleSheet pointer is used!)
641 bStyleToMarked = true;
645 aNewData.InitFromStyle( pStyleSheet );
646 bAddUndo = true;
647 rReq.Done();
649 break;
651 default:
652 break;
654 } // case SFX_STYLE_FAMILY_PARA:
655 break;
657 case SFX_STYLE_FAMILY_PAGE:
659 switch ( nSlotId )
661 case SID_STYLE_DELETE:
663 nRetMask = sal_uInt16( NULL != pStyleSheet );
664 if ( pStyleSheet )
666 if ( rDoc.RemovePageStyleInUse( pStyleSheet->GetName() ) )
668 ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(true), nCurTab ).UpdatePages();
669 rBindings.Invalidate( SID_STATUS_PAGESTYLE );
670 rBindings.Invalidate( FID_RESET_PRINTZOOM );
672 pStylePool->Remove( pStyleSheet );
673 rBindings.Invalidate( SID_STYLE_FAMILY4 );
674 pDocSh->SetDocumentModified();
675 bAddUndo = true;
676 rReq.Done();
679 break;
681 case SID_STYLE_HIDE:
682 case SID_STYLE_SHOW:
684 nRetMask = sal_uInt16( NULL != pStyleSheet );
685 if ( pStyleSheet )
687 pStyleSheet->SetHidden( nSlotId == SID_STYLE_HIDE );
688 rBindings.Invalidate( SID_STYLE_FAMILY4 );
689 pDocSh->SetDocumentModified();
690 rReq.Done();
693 break;
695 case SID_STYLE_APPLY:
697 nRetMask = sal_uInt16( NULL != pStyleSheet );
698 if ( pStyleSheet && !pScMod->GetIsWaterCan() )
700 ScUndoApplyPageStyle* pUndoAction = 0;
701 SCTAB nTabCount = rDoc.GetTableCount();
702 ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
703 for (; itr != itrEnd && *itr < nTabCount; ++itr)
705 OUString aOldName = rDoc.GetPageStyle( *itr );
706 if ( aOldName != aStyleName )
708 rDoc.SetPageStyle( *itr, aStyleName );
709 ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(true), *itr ).UpdatePages();
710 if( !pUndoAction )
711 pUndoAction = new ScUndoApplyPageStyle( pDocSh, aStyleName );
712 pUndoAction->AddSheetAction( *itr, aOldName );
715 if( pUndoAction )
717 pDocSh->GetUndoManager()->AddUndoAction( pUndoAction );
718 pDocSh->SetDocumentModified();
719 rBindings.Invalidate( SID_STYLE_FAMILY4 );
720 rBindings.Invalidate( SID_STATUS_PAGESTYLE );
721 rBindings.Invalidate( FID_RESET_PRINTZOOM );
723 rReq.Done();
726 break;
728 case SID_STYLE_NEW_BY_EXAMPLE:
730 const OUString& rStrCurStyle = rDoc.GetPageStyle( nCurTab );
732 if ( rStrCurStyle != aStyleName )
734 SfxStyleSheetBase* pCurStyle = pStylePool->Find( rStrCurStyle, eFamily );
735 SfxItemSet aAttrSet = pCurStyle->GetItemSet();
736 SCTAB nInTab;
737 bool bUsed = rDoc.IsPageStyleInUse( aStyleName, &nInTab );
739 // wenn bereits vorhanden, erstmal entfernen...
740 if ( pStyleSheet )
741 pStylePool->Remove( pStyleSheet );
743 // ...und neu anlegen
744 pStyleSheet = &pStylePool->Make( aStyleName, eFamily,
745 SFXSTYLEBIT_USERDEF );
747 // Attribute uebernehmen
748 pStyleSheet->GetItemSet().Put( aAttrSet );
749 pDocSh->SetDocumentModified();
751 // wenn in Verwendung -> Update
752 if ( bUsed )
753 ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(true), nInTab ).UpdatePages();
755 aNewData.InitFromStyle( pStyleSheet );
756 bAddUndo = true;
757 rReq.Done();
758 nRetMask = sal_uInt16(true);
761 break;
763 default:
764 break;
765 } // switch ( nSlotId )
766 } // case SFX_STYLE_FAMILY_PAGE:
767 break;
769 default:
770 break;
771 } // switch ( eFamily )
773 // Neu anlegen oder bearbeiten ueber Dialog:
774 if ( nSlotId == SID_STYLE_NEW || nSlotId == SID_STYLE_EDIT )
776 if ( pStyleSheet )
778 SfxStyleFamily eFam = pStyleSheet->GetFamily();
779 boost::scoped_ptr<SfxAbstractTabDialog> pDlg;
780 sal_uInt16 nRsc = 0;
782 // alte Items aus der Vorlage merken
783 SfxItemSet aOldSet = pStyleSheet->GetItemSet();
784 OUString aOldName = pStyleSheet->GetName();
786 switch ( eFam )
788 case SFX_STYLE_FAMILY_PAGE:
789 nRsc = RID_SCDLG_STYLES_PAGE;
790 break;
792 case SFX_STYLE_FAMILY_PARA:
793 default:
795 SfxItemSet& rSet = pStyleSheet->GetItemSet();
797 const SfxPoolItem* pItem;
798 if ( rSet.GetItemState( ATTR_VALUE_FORMAT,
799 false, &pItem ) == SfxItemState::SET )
801 // NumberFormat Value aus Value und Language
802 // erzeugen und eintueten
803 sal_uLong nFormat =
804 static_cast<const SfxUInt32Item*>(pItem)->GetValue();
805 LanguageType eLang =
806 static_cast<const SvxLanguageItem*>(&rSet.Get(
807 ATTR_LANGUAGE_FORMAT ))->GetLanguage();
808 sal_uLong nLangFormat = rDoc.GetFormatTable()->
809 GetFormatForLanguageIfBuiltIn( nFormat, eLang );
810 if ( nLangFormat != nFormat )
812 SfxUInt32Item aNewItem( ATTR_VALUE_FORMAT, nLangFormat );
813 rSet.Put( aNewItem );
814 aOldSet.Put( aNewItem );
815 // auch in aOldSet fuer Vergleich nach dem Dialog,
816 // sonst geht evtl. eine Aenderung der Sprache verloren
820 boost::scoped_ptr<SvxNumberInfoItem> pNumberInfoItem(
821 ScTabViewShell::MakeNumberInfoItem(&rDoc, GetViewData()));
823 pDocSh->PutItem( *pNumberInfoItem );
824 nRsc = RID_SCDLG_STYLES_PAR;
826 // auf jeden Fall ein SvxBoxInfoItem mit Table = sal_False im Set:
827 // (wenn gar kein Item da ist, loescht der Dialog auch das
828 // BORDER_OUTER SvxBoxItem aus dem Vorlagen-Set)
830 if ( rSet.GetItemState( ATTR_BORDER_INNER, false ) != SfxItemState::SET )
832 SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
833 aBoxInfoItem.SetTable(false); // keine inneren Linien
834 aBoxInfoItem.SetDist(true);
835 aBoxInfoItem.SetMinDist(false);
836 rSet.Put( aBoxInfoItem );
839 break;
842 // If GetDefDialogParent is a dialog, it must be used
843 // (style catalog)
845 vcl::Window* pParent = Application::GetDefDialogParent();
846 if ( !pParent || !pParent->IsDialog() )
848 // GetDefDialogParent currently doesn't return the window
849 // that was set with SetDefDialogParent (but dynamically finds the
850 // topmost parent of the focus window), so IsDialog above is FALSE
851 // even if called from the style catalog.
852 // -> Use NULL if a modal dialog is open, to enable the Dialog's
853 // default parent handling.
854 if ( Application::IsInModalMode() )
855 pParent = NULL;
856 else
857 pParent = pTabViewShell->GetDialogParent();
860 pTabViewShell->SetInFormatDialog(true);
862 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
863 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
865 pDlg.reset(pFact->CreateScStyleDlg( pParent, *pStyleSheet, nRsc, nRsc ));
866 OSL_ENSURE(pDlg, "Dialog create fail!");
867 short nResult = pDlg->Execute();
868 pTabViewShell->SetInFormatDialog(false);
870 if ( nResult == RET_OK )
872 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
874 if ( pOutSet )
876 nRetMask = pStyleSheet->GetMask();
878 // Attribut-Vergleiche (frueher in ModifyStyleSheet)
879 // jetzt hier mit den alten Werten (Style ist schon veraendert)
881 if ( SFX_STYLE_FAMILY_PARA == eFam )
883 SfxItemSet& rNewSet = pStyleSheet->GetItemSet();
884 bool bNumFormatChanged;
885 if ( ScGlobal::CheckWidthInvalidate(
886 bNumFormatChanged, rNewSet, aOldSet ) )
887 rDoc.InvalidateTextWidth( NULL, NULL, bNumFormatChanged );
889 SCTAB nTabCount = rDoc.GetTableCount();
890 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
891 if (rDoc.IsStreamValid(nTab))
892 rDoc.SetStreamValid(nTab, false);
894 sal_uLong nOldFormat = static_cast<const SfxUInt32Item&>(aOldSet.
895 Get( ATTR_VALUE_FORMAT )).GetValue();
896 sal_uLong nNewFormat = static_cast<const SfxUInt32Item&>(rNewSet.
897 Get( ATTR_VALUE_FORMAT )).GetValue();
898 if ( nNewFormat != nOldFormat )
900 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
901 const SvNumberformat* pOld = pFormatter->GetEntry( nOldFormat );
902 const SvNumberformat* pNew = pFormatter->GetEntry( nNewFormat );
903 if ( pOld && pNew && pOld->GetLanguage() != pNew->GetLanguage() )
904 rNewSet.Put( SvxLanguageItem(
905 pNew->GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
908 rDoc.GetPool()->CellStyleCreated( pStyleSheet->GetName(), &rDoc );
910 else
912 //! auch fuer Seitenvorlagen die Abfragen hier
914 OUString aNewName = pStyleSheet->GetName();
915 if ( aNewName != aOldName &&
916 rDoc.RenamePageStyleInUse( aOldName, aNewName ) )
918 rBindings.Invalidate( SID_STATUS_PAGESTYLE );
919 rBindings.Invalidate( FID_RESET_PRINTZOOM );
922 rDoc.ModifyStyleSheet( *pStyleSheet, *pOutSet );
923 rBindings.Invalidate( FID_RESET_PRINTZOOM );
926 pDocSh->SetDocumentModified();
928 if ( SFX_STYLE_FAMILY_PARA == eFam )
930 ScTabViewShell::UpdateNumberFormatter(
931 static_cast<const SvxNumberInfoItem&>(
932 *(pDocSh->GetItem(SID_ATTR_NUMBERFORMAT_INFO)) ));
934 pTabViewShell->UpdateStyleSheetInUse( pStyleSheet );
935 pTabViewShell->InvalidateAttribs();
938 aNewData.InitFromStyle( pStyleSheet );
939 bAddUndo = true;
942 else
944 if ( nSlotId == SID_STYLE_NEW )
945 pStylePool->Remove( pStyleSheet );
946 else
948 // falls zwischendurch etwas mit dem temporaer geaenderten
949 // ItemSet gepainted wurde:
950 pDocSh->PostPaintGridAll();
956 rReq.SetReturnValue( SfxUInt16Item( nSlotId, nRetMask ) );
958 if ( bAddUndo && bUndo)
959 pDocSh->GetUndoManager()->AddUndoAction(
960 new ScUndoModifyStyle( pDocSh, eFamily, aOldData, aNewData ) );
962 if ( bStyleToMarked )
964 // call SetStyleSheetToMarked after adding the ScUndoModifyStyle,
965 // so redo will find the modified style
966 pTabViewShell->SetStyleSheetToMarked( static_cast<SfxStyleSheet*>(pStyleSheet) );
967 pTabViewShell->InvalidateAttribs();
970 if ( bListAction )
971 pDocSh->GetUndoManager()->LeaveListAction();
973 else
975 OSL_FAIL( "Unknown slot (ScViewShell::ExecuteStyle)" );
979 void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
981 ScModule* pScMod = SC_MOD();
982 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
983 const SfxItemSet* pReqArgs = rReq.GetArgs();
984 sal_uInt16 nSlot = rReq.GetSlot();
985 SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
987 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
989 // Eingabe beenden
990 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
992 switch ( nSlot )
994 case SID_NUMBER_TWODEC:
995 case SID_NUMBER_SCIENTIFIC:
996 case SID_NUMBER_DATE:
997 case SID_NUMBER_CURRENCY:
998 case SID_NUMBER_PERCENT:
999 case SID_NUMBER_STANDARD:
1000 case SID_NUMBER_FORMAT:
1001 case SID_NUMBER_INCDEC:
1002 case SID_NUMBER_DECDEC:
1003 case FID_DEFINE_NAME:
1004 case FID_ADD_NAME:
1005 case FID_USE_NAME:
1006 case FID_INSERT_NAME:
1007 case SID_SPELL_DIALOG:
1008 case SID_HANGUL_HANJA_CONVERSION:
1010 pScMod->InputEnterHandler();
1011 pTabViewShell->UpdateInputHandler();
1012 break;
1014 default:
1015 break;
1019 short nType = GetCurrentNumberFormatType();
1020 SfxItemSet aSet( GetPool(), nSlot, nSlot );
1021 switch ( nSlot )
1023 case SID_NUMBER_TWODEC:
1024 pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER, 4 ); // Standard+4 = #.##0,00
1025 rReq.Done();
1026 break;
1027 case SID_NUMBER_SCIENTIFIC:
1028 if ((nType & css::util::NumberFormat::SCIENTIFIC))
1029 pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
1030 else
1031 pTabViewShell->SetNumberFormat( css::util::NumberFormat::SCIENTIFIC );
1032 aSet.Put( SfxBoolItem(nSlot, !(nType & css::util::NumberFormat::SCIENTIFIC)) );
1033 rBindings.Invalidate( nSlot );
1034 rReq.Done();
1035 break;
1036 case SID_NUMBER_DATE:
1037 if ((nType & css::util::NumberFormat::DATE))
1038 pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
1039 else
1040 pTabViewShell->SetNumberFormat( css::util::NumberFormat::DATE );
1041 aSet.Put( SfxBoolItem(nSlot, !(nType & css::util::NumberFormat::DATE)) );
1042 rBindings.Invalidate( nSlot );
1043 rReq.Done();
1044 break;
1045 case SID_NUMBER_TIME:
1046 if ((nType & css::util::NumberFormat::TIME))
1047 pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
1048 else
1049 pTabViewShell->SetNumberFormat( css::util::NumberFormat::TIME );
1050 aSet.Put( SfxBoolItem(nSlot, !(nType & css::util::NumberFormat::TIME)) );
1051 rBindings.Invalidate( nSlot );
1052 rReq.Done();
1053 break;
1054 case SID_NUMBER_CURRENCY:
1055 if ((nType & css::util::NumberFormat::CURRENCY))
1056 pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
1057 else
1058 pTabViewShell->SetNumberFormat( css::util::NumberFormat::CURRENCY );
1059 aSet.Put( SfxBoolItem(nSlot, !(nType & css::util::NumberFormat::CURRENCY)) );
1060 rBindings.Invalidate( nSlot );
1061 rReq.Done();
1062 break;
1063 case SID_NUMBER_PERCENT:
1064 if ((nType & css::util::NumberFormat::PERCENT))
1065 pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
1066 else
1067 pTabViewShell->SetNumberFormat( css::util::NumberFormat::PERCENT );
1068 aSet.Put( SfxBoolItem(nSlot, !(nType & css::util::NumberFormat::PERCENT)) );
1069 rBindings.Invalidate( nSlot );
1070 rReq.Done();
1071 break;
1072 case SID_NUMBER_STANDARD:
1073 pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
1074 rReq.Done();
1075 break;
1076 case SID_NUMBER_INCDEC:
1077 pTabViewShell->ChangeNumFmtDecimals( true );
1078 rReq.Done();
1079 break;
1080 case SID_NUMBER_DECDEC:
1081 pTabViewShell->ChangeNumFmtDecimals( false );
1082 rReq.Done();
1083 break;
1085 case SID_NUMBER_FORMAT:
1086 //if ( pReqArgs )
1088 // const SfxPoolItem* pItem;
1089 // if(pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SfxItemState::SET)
1090 // {
1091 // String aCode = ((const SfxStringItem*)pItem)->GetValue();
1092 // pTabViewShell->SetNumFmtByStr( aCode );
1093 // }
1096 // symphony version with format interpretation
1097 if(pReqArgs)
1099 const SfxPoolItem* pItem;
1100 ScDocument* pDoc = pViewData->GetDocument();
1101 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
1102 LanguageType eLanguage = ScGlobal::eLnge;
1103 sal_Int16 eType = -1;
1104 sal_uInt32 nCurrentNumberFormat;
1106 pDoc->GetNumberFormat(pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo(), nCurrentNumberFormat);
1107 const SvNumberformat* pEntry = pFormatter->GetEntry(nCurrentNumberFormat);
1109 if(pEntry)
1111 eLanguage = pEntry->GetLanguage();
1112 eType = pEntry->GetType();
1115 //Just use eType to judge whether the command is fired for NUMBER/PERCENT/CURRENCY/SCIENTIFIC
1116 //In sidebar, users can fire SID_NUMBER_FORMAT command by operating the related UI controls before they are disable
1117 switch(eType)
1119 case css::util::NumberFormat::ALL:
1120 case css::util::NumberFormat::NUMBER:
1121 case css::util::NumberFormat::NUMBER| css::util::NumberFormat::DEFINED:
1122 case css::util::NumberFormat::PERCENT:
1123 case css::util::NumberFormat::PERCENT| css::util::NumberFormat::DEFINED:
1124 case css::util::NumberFormat::CURRENCY:
1125 case css::util::NumberFormat::CURRENCY|css::util::NumberFormat::DEFINED:
1126 case css::util::NumberFormat::SCIENTIFIC:
1127 case css::util::NumberFormat::SCIENTIFIC|css::util::NumberFormat::DEFINED:
1128 eType = 0;
1129 break;
1130 default:
1131 eType =-1;
1134 if(SfxItemState::SET == pReqArgs->GetItemState(nSlot, true, &pItem) && eType != -1)
1136 OUString aCode = static_cast<const SfxStringItem*>(pItem)->GetValue();
1137 sal_uInt16 aLen = aCode.getLength();
1138 OUString* sFormat = new OUString[4];
1139 OUString sTmpStr = "";
1140 sal_uInt16 nCount(0);
1141 sal_uInt16 nStrCount(0);
1143 while(nCount < aLen)
1145 sal_Unicode cChar = aCode[nCount];
1147 if(cChar == ',')
1149 sFormat[nStrCount] = sTmpStr;
1150 sTmpStr.clear();
1151 nStrCount++;
1153 else
1155 sTmpStr += OUString(cChar);
1158 nCount++;
1160 if(nStrCount > 3)
1161 break;
1164 const bool bThousand = (bool)sFormat[0].toInt32();
1165 const bool bNegRed = (bool)sFormat[1].toInt32();
1166 const sal_uInt16 nPrecision = (sal_uInt16)sFormat[2].toInt32();
1167 const sal_uInt16 nLeadZeroes = (sal_uInt16)sFormat[3].toInt32();
1169 aCode = pFormatter->GenerateFormat(
1170 nCurrentNumberFormat,//modify
1171 eLanguage,
1172 bThousand,
1173 bNegRed,
1174 nPrecision,
1175 nLeadZeroes);
1176 pTabViewShell->SetNumFmtByStr(aCode);
1177 delete[] sFormat;
1180 break;
1182 case SID_ATTR_NUMBERFORMAT_VALUE:
1183 if ( pReqArgs )
1185 const SfxPoolItem* pItem;
1186 if ( pReqArgs->GetItemState( ATTR_VALUE_FORMAT, true, &pItem ) == SfxItemState::SET )
1188 // We have to accomplish this using ApplyAttributes()
1189 // because we also need the language information to be
1190 // considered.
1191 const SfxItemSet& rOldSet =
1192 pTabViewShell->GetSelectionPattern()->GetItemSet();
1193 SfxItemPool* pDocPool = GetViewData()->GetDocument()->GetPool();
1194 SfxItemSet aNewSet( *pDocPool, ATTR_PATTERN_START, ATTR_PATTERN_END );
1195 aNewSet.Put( *pItem );
1196 pTabViewShell->ApplyAttributes( &aNewSet, &rOldSet, true );
1199 break;
1201 case SID_NUMBER_TYPE_FORMAT:
1202 if ( pReqArgs )
1204 const SfxPoolItem* pItem;
1205 if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
1207 sal_uInt16 nFormat = static_cast<const SfxInt16Item *>(pItem)->GetValue();
1208 switch(nFormat)
1210 case 0:
1211 pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER); //Modify
1212 break;
1213 case 1:
1214 pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER, 2 ); //Modify
1215 break;
1216 case 2:
1217 pTabViewShell->SetNumberFormat( css::util::NumberFormat::PERCENT );
1218 break;
1219 case 3:
1220 pTabViewShell->SetNumberFormat( css::util::NumberFormat::CURRENCY );
1221 break;
1222 case 4:
1223 pTabViewShell->SetNumberFormat( css::util::NumberFormat::DATE );
1224 break;
1225 case 5:
1226 pTabViewShell->SetNumberFormat( css::util::NumberFormat::TIME );
1227 break;
1228 case 6:
1229 pTabViewShell->SetNumberFormat( css::util::NumberFormat::SCIENTIFIC );
1230 break;
1231 case 7:
1232 pTabViewShell->SetNumberFormat( css::util::NumberFormat::FRACTION );
1233 break;
1234 case 8:
1235 pTabViewShell->SetNumberFormat( css::util::NumberFormat::LOGICAL );
1236 break;
1237 case 9:
1238 pTabViewShell->SetNumberFormat( css::util::NumberFormat::TEXT );
1239 break;
1240 default:
1243 rReq.Done();
1246 break;
1248 default:
1249 OSL_FAIL("falscher Slot bei ExecuteEdit");
1250 break;
1254 void ScFormatShell::ExecuteAlignment( SfxRequest& rReq )
1256 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1257 SfxBindings& rBindings = pViewData->GetBindings();
1258 const SfxItemSet* pSet = rReq.GetArgs();
1259 sal_uInt16 nSlot = rReq.GetSlot();
1261 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
1263 switch( nSlot )
1265 // pseudo slots for Format menu
1266 case SID_ALIGN_ANY_HDEFAULT:
1267 case SID_ALIGN_ANY_LEFT:
1268 case SID_ALIGN_ANY_HCENTER:
1269 case SID_ALIGN_ANY_RIGHT:
1270 case SID_ALIGN_ANY_JUSTIFIED:
1271 pTabViewShell->ApplyAttr( SvxHorJustifyItem( lclConvertSlotToHAlign( nSlot ), ATTR_HOR_JUSTIFY ) );
1272 break;
1273 case SID_ALIGN_ANY_VDEFAULT:
1274 case SID_ALIGN_ANY_TOP:
1275 case SID_ALIGN_ANY_VCENTER:
1276 case SID_ALIGN_ANY_BOTTOM:
1277 pTabViewShell->ApplyAttr( SvxVerJustifyItem( lclConvertSlotToVAlign( nSlot ), ATTR_VER_JUSTIFY ) );
1278 break;
1280 default:
1281 if( pSet )
1283 const SfxPoolItem* pItem = NULL;
1284 if( pSet->GetItemState(GetPool().GetWhich(nSlot), true, &pItem ) == SfxItemState::SET )
1287 switch ( nSlot )
1289 case SID_ATTR_ALIGN_HOR_JUSTIFY:
1290 case SID_ATTR_ALIGN_VER_JUSTIFY:
1291 case SID_ATTR_ALIGN_INDENT:
1292 case SID_ATTR_ALIGN_HYPHENATION:
1293 case SID_ATTR_ALIGN_DEGREES:
1294 case SID_ATTR_ALIGN_LOCKPOS:
1295 case SID_ATTR_ALIGN_MARGIN:
1296 case SID_ATTR_ALIGN_STACKED:
1297 pTabViewShell->ApplyAttr( *pItem );
1298 break;
1300 case SID_H_ALIGNCELL:
1302 SvxCellHorJustify eJust = (SvxCellHorJustify)static_cast<const SvxHorJustifyItem*>(pItem)->GetValue();
1303 // #i78476# update alignment of text in cell edit mode
1304 pTabViewShell->UpdateInputHandlerCellAdjust( eJust );
1305 pTabViewShell->ApplyAttr( SvxHorJustifyItem( eJust, ATTR_HOR_JUSTIFY ) );
1307 break;
1308 case SID_V_ALIGNCELL:
1309 pTabViewShell->ApplyAttr( SvxVerJustifyItem( (SvxCellVerJustify)static_cast<const SvxVerJustifyItem*>(pItem)->GetValue(), ATTR_VER_JUSTIFY ) );
1310 break;
1311 default:
1312 OSL_FAIL( "ExecuteAlignment: invalid slot" );
1313 return;
1318 rBindings.Invalidate( SID_ATTR_PARA_ADJUST_LEFT );
1319 rBindings.Invalidate( SID_ATTR_PARA_ADJUST_RIGHT );
1320 rBindings.Invalidate( SID_ATTR_PARA_ADJUST_BLOCK );
1321 rBindings.Invalidate( SID_ATTR_PARA_ADJUST_CENTER);
1322 rBindings.Invalidate( SID_ALIGNLEFT );
1323 rBindings.Invalidate( SID_ALIGNRIGHT );
1324 rBindings.Invalidate( SID_ALIGNCENTERHOR );
1325 rBindings.Invalidate( SID_ALIGNBLOCK );
1326 rBindings.Invalidate( SID_ALIGNTOP );
1327 rBindings.Invalidate( SID_ALIGNBOTTOM );
1328 rBindings.Invalidate( SID_ALIGNCENTERVER );
1329 rBindings.Invalidate( SID_V_ALIGNCELL );
1330 rBindings.Invalidate( SID_H_ALIGNCELL );
1331 // pseudo slots for Format menu
1332 rBindings.Invalidate( SID_ALIGN_ANY_HDEFAULT );
1333 rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
1334 rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
1335 rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
1336 rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
1337 rBindings.Invalidate( SID_ALIGN_ANY_VDEFAULT );
1338 rBindings.Invalidate( SID_ALIGN_ANY_TOP );
1339 rBindings.Invalidate( SID_ALIGN_ANY_VCENTER );
1340 rBindings.Invalidate( SID_ALIGN_ANY_BOTTOM );
1341 rBindings.Update();
1343 if( ! rReq.IsAPI() )
1344 rReq.Done();
1347 void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
1349 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1350 SfxBindings& rBindings = pViewData->GetBindings();
1351 const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
1352 const SfxItemSet* pSet = rReq.GetArgs();
1353 sal_uInt16 nSlot = rReq.GetSlot();
1354 SfxAllItemSet* pNewSet = 0;
1356 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
1358 if ( (nSlot == SID_ATTR_CHAR_WEIGHT)
1359 ||(nSlot == SID_ATTR_CHAR_POSTURE)
1360 ||(nSlot == SID_ATTR_CHAR_UNDERLINE)
1361 ||(nSlot == SID_ULINE_VAL_NONE)
1362 ||(nSlot == SID_ULINE_VAL_SINGLE)
1363 ||(nSlot == SID_ULINE_VAL_DOUBLE)
1364 ||(nSlot == SID_ULINE_VAL_DOTTED) )
1366 pNewSet = new SfxAllItemSet( GetPool() );
1368 switch ( nSlot )
1370 case SID_ATTR_CHAR_WEIGHT:
1372 // #i78017 establish the same behaviour as in Writer
1373 SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
1375 SfxItemPool& rPool = GetPool();
1376 SvxScriptSetItem aSetItem( nSlot, rPool );
1377 if ( pSet )
1378 aSetItem.PutItemForScriptType( nScript, pSet->Get( ATTR_FONT_WEIGHT ) );
1379 else
1381 // toggle manually
1383 FontWeight eWeight = WEIGHT_BOLD;
1384 SvxScriptSetItem aOldSetItem( nSlot, rPool );
1385 aOldSetItem.GetItemSet().Put( pAttrs->GetItemSet(), false );
1386 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
1387 if ( pCore && static_cast<const SvxWeightItem*>(pCore)->GetWeight() == WEIGHT_BOLD )
1388 eWeight = WEIGHT_NORMAL;
1390 aSetItem.PutItemForScriptType( nScript, SvxWeightItem( eWeight, ATTR_FONT_WEIGHT ) );
1392 pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1393 pNewSet->Put( aSetItem.GetItemSet(), false );
1395 break;
1397 case SID_ATTR_CHAR_POSTURE:
1399 // #i78017 establish the same behaviour as in Writer
1400 SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
1402 SfxItemPool& rPool = GetPool();
1403 SvxScriptSetItem aSetItem( nSlot, rPool );
1404 if ( pSet )
1405 aSetItem.PutItemForScriptType( nScript, pSet->Get( ATTR_FONT_POSTURE ) );
1406 else
1408 // toggle manually
1410 FontItalic eItalic = ITALIC_NORMAL;
1411 SvxScriptSetItem aOldSetItem( nSlot, rPool );
1412 aOldSetItem.GetItemSet().Put( pAttrs->GetItemSet(), false );
1413 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
1414 if ( pCore && static_cast<const SvxPostureItem*>(pCore)->GetPosture() == ITALIC_NORMAL )
1415 eItalic = ITALIC_NONE;
1417 aSetItem.PutItemForScriptType( nScript, SvxPostureItem( eItalic, ATTR_FONT_POSTURE ) );
1419 pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1420 pNewSet->Put( aSetItem.GetItemSet(), false );
1422 break;
1424 case SID_ATTR_CHAR_UNDERLINE:
1426 FontUnderline eUnderline;
1428 if( pSet )
1430 const SfxPoolItem& rUnderline = pSet->Get( ATTR_FONT_UNDERLINE );
1432 if( rUnderline.ISA(SvxUnderlineItem) )
1434 pTabViewShell->ApplyAttr( rUnderline );
1435 pNewSet->Put( rUnderline,rUnderline.Which() );
1437 else if ( rUnderline.ISA(SvxTextLineItem) )
1439 // #i106580# also allow SvxTextLineItem (base class of SvxUnderlineItem)
1440 const SvxTextLineItem& rTextLineItem = static_cast<const SvxTextLineItem&>(rUnderline);
1441 SvxUnderlineItem aNewItem( rTextLineItem.GetLineStyle(), rTextLineItem.Which() );
1442 aNewItem.SetColor( rTextLineItem.GetColor() );
1443 pTabViewShell->ApplyAttr( aNewItem );
1444 pNewSet->Put( aNewItem, aNewItem.Which() );
1447 else
1449 SvxUnderlineItem aUnderline( static_cast<const SvxUnderlineItem&>(
1450 pAttrs->GetItem(
1451 ATTR_FONT_UNDERLINE ) ) );
1452 eUnderline = (UNDERLINE_NONE != aUnderline.GetLineStyle())
1453 ? UNDERLINE_NONE
1454 : UNDERLINE_SINGLE;
1455 aUnderline.SetLineStyle( eUnderline );
1456 pTabViewShell->ApplyAttr( aUnderline );
1457 pNewSet->Put( aUnderline,aUnderline.Which() );
1460 break;
1462 case SID_ULINE_VAL_NONE:
1463 pTabViewShell->ApplyAttr( SvxUnderlineItem( UNDERLINE_NONE, ATTR_FONT_UNDERLINE ) );
1464 break;
1465 case SID_ULINE_VAL_SINGLE: // Toggles
1466 case SID_ULINE_VAL_DOUBLE:
1467 case SID_ULINE_VAL_DOTTED:
1469 FontUnderline eOld = static_cast<const SvxUnderlineItem&>(
1470 pAttrs->GetItem(ATTR_FONT_UNDERLINE)).GetLineStyle();
1471 FontUnderline eNew = eOld;
1472 switch (nSlot)
1474 case SID_ULINE_VAL_SINGLE:
1475 eNew = ( eOld == UNDERLINE_SINGLE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
1476 break;
1477 case SID_ULINE_VAL_DOUBLE:
1478 eNew = ( eOld == UNDERLINE_DOUBLE ) ? UNDERLINE_NONE : UNDERLINE_DOUBLE;
1479 break;
1480 case SID_ULINE_VAL_DOTTED:
1481 eNew = ( eOld == UNDERLINE_DOTTED ) ? UNDERLINE_NONE : UNDERLINE_DOTTED;
1482 break;
1484 pTabViewShell->ApplyAttr( SvxUnderlineItem( eNew, ATTR_FONT_UNDERLINE ) );
1486 break;
1488 default:
1489 break;
1491 rBindings.Invalidate( nSlot );
1493 else
1496 * "Selbstgemachte" RadioButton-Funktionalitaet
1497 * Beim Toggle gibt es den Standard-State, d.h. kein
1498 * Button ist gedrueckt
1501 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
1502 const SfxPoolItem* pItem = NULL;
1503 const SvxHorJustifyItem* pHorJustify = NULL;
1504 const SvxVerJustifyItem* pVerJustify = NULL;
1505 SvxCellHorJustify eHorJustify = SVX_HOR_JUSTIFY_STANDARD;
1506 SvxCellVerJustify eVerJustify = SVX_VER_JUSTIFY_STANDARD;
1508 if (rAttrSet.GetItemState(ATTR_HOR_JUSTIFY, true,&pItem ) == SfxItemState::SET)
1510 pHorJustify = static_cast<const SvxHorJustifyItem*>(pItem);
1511 eHorJustify = SvxCellHorJustify( pHorJustify->GetValue() );
1513 if (rAttrSet.GetItemState(ATTR_VER_JUSTIFY, true,&pItem ) == SfxItemState::SET)
1515 pVerJustify = static_cast<const SvxVerJustifyItem*>(pItem);
1516 eVerJustify = SvxCellVerJustify( pVerJustify->GetValue() );
1519 switch ( nSlot )
1521 case SID_ALIGNLEFT:
1522 rReq.SetSlot( SID_H_ALIGNCELL );
1523 rReq.AppendItem( SvxHorJustifyItem(
1524 !pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_LEFT) ?
1525 SVX_HOR_JUSTIFY_LEFT : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1526 ExecuteSlot( rReq, GetInterface() );
1527 return;
1529 case SID_ALIGNRIGHT:
1530 rReq.SetSlot( SID_H_ALIGNCELL );
1531 rReq.AppendItem( SvxHorJustifyItem(
1532 !pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_RIGHT) ?
1533 SVX_HOR_JUSTIFY_RIGHT : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1534 ExecuteSlot( rReq, GetInterface() );
1535 return;
1537 case SID_ALIGNCENTERHOR:
1538 rReq.SetSlot( SID_H_ALIGNCELL );
1539 rReq.AppendItem( SvxHorJustifyItem(
1540 !pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_CENTER) ?
1541 SVX_HOR_JUSTIFY_CENTER : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1542 ExecuteSlot( rReq, GetInterface() );
1543 return;
1545 case SID_ALIGNBLOCK:
1546 rReq.SetSlot( SID_H_ALIGNCELL );
1547 rReq.AppendItem( SvxHorJustifyItem(
1548 !pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_BLOCK) ?
1549 SVX_HOR_JUSTIFY_BLOCK : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1550 ExecuteSlot( rReq, GetInterface() );
1551 return;
1553 case SID_ALIGNTOP:
1554 rReq.SetSlot( SID_V_ALIGNCELL );
1555 rReq.AppendItem( SvxVerJustifyItem(
1556 !pVerJustify || (eVerJustify != SVX_VER_JUSTIFY_TOP) ?
1557 SVX_VER_JUSTIFY_TOP : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
1558 ExecuteSlot( rReq, GetInterface() );
1559 return;
1561 case SID_ALIGNBOTTOM:
1562 rReq.SetSlot( SID_V_ALIGNCELL );
1563 rReq.AppendItem( SvxVerJustifyItem(
1564 !pVerJustify || (eVerJustify != SVX_VER_JUSTIFY_BOTTOM) ?
1565 SVX_VER_JUSTIFY_BOTTOM : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
1566 ExecuteSlot( rReq, GetInterface() );
1567 return;
1569 case SID_ALIGNCENTERVER:
1570 rReq.SetSlot( SID_V_ALIGNCELL );
1571 rReq.AppendItem( SvxVerJustifyItem(
1572 !pVerJustify || (eVerJustify != SVX_VER_JUSTIFY_CENTER) ?
1573 SVX_VER_JUSTIFY_CENTER : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
1574 ExecuteSlot( rReq, GetInterface() );
1575 return;
1577 default:
1578 break;
1583 rBindings.Update();
1585 if( pNewSet )
1587 rReq.Done( *pNewSet );
1588 delete pNewSet;
1590 else
1592 rReq.Done();
1597 void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
1599 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1600 SfxBindings& rBindings = pViewData->GetBindings();
1601 const SfxItemSet* pNewAttrs = rReq.GetArgs();
1602 sal_uInt16 nSlot = rReq.GetSlot();
1604 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
1605 ScDocument* pDoc = GetViewData()->GetDocument();
1606 if ( !pNewAttrs )
1608 switch ( nSlot )
1610 case SID_ATTR_CHAR_ENDPREVIEW_FONT:
1612 pDoc->SetPreviewFont(NULL);
1613 pTabViewShell->UpdateSelectionArea( pDoc->GetPreviewSelection() );
1614 break;
1616 case SID_ATTR_CHAR_COLOR:
1617 case SID_ATTR_CHAR_FONT:
1618 case SID_ATTR_CHAR_FONTHEIGHT:
1619 pTabViewShell->ExecuteCellFormatDlg(rReq, "font"); // wenn ToolBar vertikal
1620 break;
1622 case SID_BACKGROUND_COLOR:
1624 SvxBrushItem aBrushItem( static_cast<const SvxBrushItem&>(
1625 pTabViewShell->GetSelectionPattern()->GetItem( ATTR_BACKGROUND ) ) );
1626 aBrushItem.SetColor( COL_TRANSPARENT );
1627 pTabViewShell->ApplyAttr( aBrushItem );
1629 break;
1631 case SID_ATTR_ALIGN_LINEBREAK: // ohne Parameter als Toggle
1633 const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
1634 bool bOld = static_cast<const SfxBoolItem&>(pAttrs->GetItem(ATTR_LINEBREAK)).GetValue();
1635 SfxBoolItem aBreakItem( ATTR_LINEBREAK, !bOld );
1636 pTabViewShell->ApplyAttr( aBreakItem );
1638 SfxAllItemSet aNewSet( GetPool() );
1639 aNewSet.Put( aBreakItem,aBreakItem.Which() );
1640 rReq.Done( aNewSet );
1642 rBindings.Invalidate( nSlot );
1644 break;
1647 else
1649 switch ( nSlot )
1651 case SID_ATTR_CHAR_PREVIEW_FONT:
1653 SfxItemPool& rPool = GetPool();
1654 sal_uInt16 nWhich = rPool.GetWhich( nSlot );
1655 const SvxFontItem& rFont = static_cast<const SvxFontItem&>(pNewAttrs->Get( nWhich ));
1656 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, rPool );
1657 SvtScriptType nScript = pTabViewShell->GetSelectionScriptType();
1658 aSetItem.PutItemForScriptType( nScript, rFont );
1660 ScMarkData aFuncMark( pViewData->GetMarkData() );
1661 ScViewUtil::UnmarkFiltered( aFuncMark, pDoc );
1662 pDoc->SetPreviewFont( aSetItem.GetItemSet().Clone() );
1663 aFuncMark.MarkToMulti();
1665 if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() )
1667 SCCOL nCol = pViewData->GetCurX();
1668 SCROW nRow = pViewData->GetCurY();
1669 SCTAB nTab = pViewData->GetTabNo();
1670 ScRange aRange( nCol, nRow, nTab );
1671 aFuncMark.SetMarkArea( aRange );
1673 pDoc->SetPreviewSelection( aFuncMark );
1674 pTabViewShell->UpdateSelectionArea( aFuncMark );
1675 break;
1677 case SID_ATTR_CHAR_OVERLINE:
1678 case SID_ATTR_CHAR_STRIKEOUT:
1679 case SID_ATTR_ALIGN_LINEBREAK:
1680 case SID_ATTR_CHAR_COLOR:
1681 case SID_ATTR_CHAR_CONTOUR:
1682 case SID_ATTR_CHAR_SHADOWED:
1683 case SID_ATTR_CHAR_RELIEF:
1684 case SID_SCATTR_PROTECTION :
1685 pTabViewShell->ApplyAttr( pNewAttrs->Get( pNewAttrs->GetPool()->GetWhich( nSlot ) ) );
1686 rBindings.Invalidate( nSlot );
1687 rBindings.Update( nSlot );
1688 break;
1690 case SID_ATTR_CHAR_FONT:
1691 case SID_ATTR_CHAR_FONTHEIGHT:
1693 // #i78017 establish the same behaviour as in Writer
1694 SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
1695 if (nSlot == SID_ATTR_CHAR_FONT)
1696 nScript = pTabViewShell->GetSelectionScriptType();
1698 SfxItemPool& rPool = GetPool();
1699 SvxScriptSetItem aSetItem( nSlot, rPool );
1700 sal_uInt16 nWhich = rPool.GetWhich( nSlot );
1701 aSetItem.PutItemForScriptType( nScript, pNewAttrs->Get( nWhich ) );
1703 pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1705 rBindings.Invalidate( nSlot );
1706 rBindings.Update( nSlot );
1708 break;
1710 case SID_FRAME_LINESTYLE:
1712 // Default-Linie aktualisieren
1713 const ::editeng::SvxBorderLine* pLine =
1714 static_cast<const SvxLineItem&>(
1715 pNewAttrs->Get( SID_FRAME_LINESTYLE )).
1716 GetLine();
1718 if ( pLine )
1720 ::editeng::SvxBorderLine* pDefLine = pTabViewShell->GetDefaultFrameLine();
1722 if ( pDefLine )
1724 pDefLine->SetBorderLineStyle(
1725 pLine->GetBorderLineStyle());
1726 pDefLine->SetWidth( pLine->GetWidth( ) );
1727 pTabViewShell->SetSelectionFrameLines( pDefLine, false );
1729 else
1731 pTabViewShell->SetDefaultFrameLine( pLine );
1732 pTabViewShell->GetDefaultFrameLine()->SetColor( COL_BLACK );
1733 pTabViewShell->SetSelectionFrameLines( pLine, false );
1736 else
1738 Color aColorBlack( COL_BLACK );
1739 ::editeng::SvxBorderLine aDefLine( &aColorBlack, 20,
1740 table::BorderLineStyle::SOLID );
1741 pTabViewShell->SetDefaultFrameLine( &aDefLine );
1742 pTabViewShell->SetSelectionFrameLines( NULL, false );
1745 break;
1747 case SID_FRAME_LINECOLOR:
1749 ::editeng::SvxBorderLine* pDefLine = pTabViewShell->GetDefaultFrameLine();
1750 const Color& rColor = static_cast<const SvxColorItem&>(
1751 pNewAttrs->Get( SID_FRAME_LINECOLOR )).
1752 GetValue();
1754 // Default-Linie aktualisieren
1755 if ( pDefLine )
1757 pDefLine->SetColor( rColor );
1758 pTabViewShell->SetSelectionFrameLines( pDefLine, true );
1760 else
1762 ::editeng::SvxBorderLine aDefLine( &rColor, 20,
1763 table::BorderLineStyle::SOLID );
1764 pTabViewShell->SetDefaultFrameLine( &aDefLine );
1765 pTabViewShell->SetSelectionFrameLines( &aDefLine, false );
1768 break;
1770 case SID_ATTR_BORDER_OUTER:
1771 case SID_ATTR_BORDER:
1773 ::editeng::SvxBorderLine* pDefLine = pTabViewShell->GetDefaultFrameLine();
1774 const ScPatternAttr* pOldAttrs = pTabViewShell->GetSelectionPattern();
1775 boost::scoped_ptr<SfxItemSet> pOldSet(
1776 new SfxItemSet(
1777 *(pDoc->GetPool()),
1778 ATTR_PATTERN_START,
1779 ATTR_PATTERN_END ));
1780 boost::scoped_ptr<SfxItemSet> pNewSet(
1781 new SfxItemSet(
1782 *(pDoc->GetPool()),
1783 ATTR_PATTERN_START,
1784 ATTR_PATTERN_END ));
1785 const SfxPoolItem& rBorderAttr =
1786 pOldAttrs->GetItemSet().
1787 Get( ATTR_BORDER );
1789 // Border-Items vom Controller auswerten:
1790 const SfxPoolItem* pItem = 0;
1792 if ( pNewAttrs->GetItemState( ATTR_BORDER, true, &pItem )
1793 == SfxItemState::SET )
1795 // The SvxFrameToolBoxControl toolbox controller uses a default
1796 // SvxBorderLine (all widths 0) to mark the lines that should be set.
1797 // Macro recording uses a SvxBoxItem with the real values (OutWidth > 0)
1798 // or NULL pointers for no lines.
1799 // -> Substitute existing lines with pDefLine only if widths are 0.
1800 SvxBoxItem aBoxItem ( *static_cast<const SvxBoxItem*>(pItem ));
1801 if ( aBoxItem.GetTop() && aBoxItem.GetTop()->GetOutWidth() == 0 )
1802 aBoxItem.SetLine( pDefLine, SvxBoxItemLine::TOP );
1803 if ( aBoxItem.GetBottom() && aBoxItem.GetBottom()->GetOutWidth() == 0 )
1804 aBoxItem.SetLine( pDefLine, SvxBoxItemLine::BOTTOM );
1805 if ( aBoxItem.GetLeft() && aBoxItem.GetLeft()->GetOutWidth() == 0 )
1806 aBoxItem.SetLine( pDefLine, SvxBoxItemLine::LEFT );
1807 if ( aBoxItem.GetRight() && aBoxItem.GetRight()->GetOutWidth() == 0 )
1808 aBoxItem.SetLine( pDefLine, SvxBoxItemLine::RIGHT );
1809 pNewSet->Put( aBoxItem );
1810 rReq.AppendItem( aBoxItem );
1813 if ( pNewAttrs->GetItemState( ATTR_BORDER_INNER, true, &pItem )
1814 == SfxItemState::SET )
1816 SvxBoxInfoItem aBoxInfoItem( *static_cast<const SvxBoxInfoItem*>(pItem) );
1817 if ( aBoxInfoItem.GetHori() && aBoxInfoItem.GetHori()->GetOutWidth() == 0 )
1818 aBoxInfoItem.SetLine( pDefLine, SvxBoxInfoItemLine::HORI );
1819 if ( aBoxInfoItem.GetVert() && aBoxInfoItem.GetVert()->GetOutWidth() == 0 )
1820 aBoxInfoItem.SetLine( pDefLine, SvxBoxInfoItemLine::VERT );
1821 pNewSet->Put( aBoxInfoItem );
1822 rReq.AppendItem( aBoxInfoItem );
1824 else
1826 SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
1827 aBoxInfoItem.SetLine( NULL, SvxBoxInfoItemLine::HORI );
1828 aBoxInfoItem.SetLine( NULL, SvxBoxInfoItemLine::VERT );
1829 pNewSet->Put( aBoxInfoItem );
1832 pOldSet->Put( rBorderAttr );
1833 pTabViewShell->ApplyAttributes( pNewSet.get(), pOldSet.get() );
1835 break;
1837 case SID_ATTR_BORDER_DIAG_TLBR:
1838 case SID_ATTR_BORDER_DIAG_BLTR:
1840 const ScPatternAttr* pOldAttrs = pTabViewShell->GetSelectionPattern();
1841 boost::scoped_ptr<SfxItemSet> pOldSet(new SfxItemSet(pOldAttrs->GetItemSet()));
1842 boost::scoped_ptr<SfxItemSet> pNewSet(new SfxItemSet(pOldAttrs->GetItemSet()));
1843 const SfxPoolItem* pItem = 0;
1845 if(SID_ATTR_BORDER_DIAG_TLBR == nSlot)
1847 if(SfxItemState::SET == pNewAttrs->GetItemState(ATTR_BORDER_TLBR, true, &pItem))
1849 SvxLineItem aItem(ATTR_BORDER_TLBR);
1850 aItem.SetLine(static_cast<const SvxLineItem&>(pNewAttrs->Get(ATTR_BORDER_TLBR)).GetLine());
1851 pNewSet->Put(aItem);
1852 rReq.AppendItem(aItem);
1853 pTabViewShell->ApplyAttributes(pNewSet.get(), pOldSet.get());
1856 else // if( nSlot == SID_ATTR_BORDER_DIAG_BLTR )
1858 if(SfxItemState::SET == pNewAttrs->GetItemState(ATTR_BORDER_BLTR, true, &pItem ))
1860 SvxLineItem aItem(ATTR_BORDER_BLTR);
1861 aItem.SetLine(static_cast<const SvxLineItem&>(pNewAttrs->Get(ATTR_BORDER_BLTR)).GetLine());
1862 pNewSet->Put(aItem);
1863 rReq.AppendItem(aItem);
1864 pTabViewShell->ApplyAttributes(pNewSet.get(), pOldSet.get());
1868 rBindings.Invalidate(nSlot);
1870 break;
1872 // ATTR_BACKGROUND (=SID_ATTR_BRUSH) muss ueber zwei IDs
1873 // gesetzt werden:
1874 case SID_BACKGROUND_COLOR:
1876 const SvxColorItem rNewColorItem = static_cast<const SvxColorItem&>(
1877 pNewAttrs->Get( SID_BACKGROUND_COLOR ) );
1879 SvxBrushItem aBrushItem( static_cast<const SvxBrushItem&>(
1880 pTabViewShell->GetSelectionPattern()->
1881 GetItem( ATTR_BACKGROUND ) ) );
1883 aBrushItem.SetColor( rNewColorItem.GetValue() );
1885 pTabViewShell->ApplyAttr( aBrushItem );
1887 break;
1889 case SID_ATTR_BRUSH:
1891 SvxBrushItem aBrushItem( static_cast<const SvxBrushItem&>(
1892 pTabViewShell->GetSelectionPattern()->
1893 GetItem( ATTR_BACKGROUND ) ) );
1894 const SvxBrushItem& rNewBrushItem = static_cast<const SvxBrushItem&>(
1895 pNewAttrs->Get( GetPool().GetWhich(nSlot) ) );
1896 aBrushItem.SetColor(rNewBrushItem.GetColor());
1897 pTabViewShell->ApplyAttr( aBrushItem );
1899 break;
1901 case SID_ATTR_BORDER_SHADOW:
1903 const SvxShadowItem& rNewShadowItem = static_cast<const SvxShadowItem&>(
1904 pNewAttrs->Get( ATTR_SHADOW ) );
1905 pTabViewShell->ApplyAttr( rNewShadowItem );
1907 break;
1909 default:
1910 break;
1913 if( ! rReq.IsAPI() )
1914 if( ! rReq.IsDone() )
1915 rReq.Done();
1919 void ScFormatShell::GetAttrState( SfxItemSet& rSet )
1921 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1922 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
1923 //const ::editeng::SvxBorderLine* pLine = pTabViewShell->GetDefaultFrameLine();
1924 const SvxBrushItem& rBrushItem = static_cast<const SvxBrushItem&>(rAttrSet.Get( ATTR_BACKGROUND ));
1925 SfxWhichIter aIter( rSet );
1926 sal_uInt16 nWhich = aIter.FirstWhich();
1928 rSet.Put( rAttrSet, false );
1930 // choose font info according to selection script type
1931 SvtScriptType nScript = SvtScriptType::NONE; // GetSelectionScriptType never returns 0
1932 if ( rSet.GetItemState( ATTR_FONT ) != SfxItemState::UNKNOWN )
1934 if (nScript == SvtScriptType::NONE) nScript = pTabViewShell->GetSelectionScriptType();
1935 ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT, nScript );
1937 if ( rSet.GetItemState( ATTR_FONT_HEIGHT ) != SfxItemState::UNKNOWN )
1939 if (nScript == SvtScriptType::NONE) nScript = pTabViewShell->GetSelectionScriptType();
1940 ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_HEIGHT, nScript );
1943 while ( nWhich )
1945 switch(nWhich)
1947 case SID_BACKGROUND_COLOR:
1949 rSet.Put( SvxColorItem( rBrushItem.GetColor(), SID_BACKGROUND_COLOR ) );
1951 if(SfxItemState::DONTCARE == rAttrSet.GetItemState(ATTR_BACKGROUND))
1953 rSet.InvalidateItem(SID_BACKGROUND_COLOR);
1956 break;
1957 case SID_FRAME_LINESTYLE:
1958 case SID_FRAME_LINECOLOR:
1960 // handled together because both need the cell border information for decisions
1961 // rSet.Put( SvxColorItem( pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLOR ) );
1962 Color aCol = 0;
1963 editeng::SvxBorderLine aLine(0,0,0,false);
1964 bool bCol = false;
1965 bool bColDisable = false, bStyleDisable = false;
1966 SvxBoxItem aBoxItem(ATTR_BORDER);
1967 SvxBoxInfoItem aInfoItem(ATTR_BORDER_INNER);
1969 pTabViewShell->GetSelectionFrame(aBoxItem, aInfoItem);
1971 if( aBoxItem.GetTop() )
1973 bCol = true;
1974 aCol = aBoxItem.GetTop()->GetColor() ;
1975 aLine.SetColor(aCol);
1976 aLine.SetWidth( aBoxItem.GetTop()->GetWidth());
1977 aLine.SetBorderLineStyle( aBoxItem.GetTop()->GetBorderLineStyle());
1980 if( aBoxItem.GetBottom() )
1982 if(!bCol)
1984 bCol = true;
1985 aCol = aBoxItem.GetBottom()->GetColor() ;
1986 aLine.SetColor(aCol);
1987 aLine.SetWidth( aBoxItem.GetBottom()->GetWidth());
1988 aLine.SetBorderLineStyle( aBoxItem.GetBottom()->GetBorderLineStyle());
1990 else
1992 if(aCol != aBoxItem.GetBottom()->GetColor() )
1993 bColDisable = true;
1994 if(!( aLine == *(aBoxItem.GetBottom())) )
1995 bStyleDisable = true;
1999 if( aBoxItem.GetLeft() )
2001 if(!bCol)
2003 bCol = true;
2004 aCol = aBoxItem.GetLeft()->GetColor() ;
2005 aLine.SetColor(aCol);
2006 aLine.SetWidth( aBoxItem.GetLeft()->GetWidth());
2007 aLine.SetBorderLineStyle( aBoxItem.GetLeft()->GetBorderLineStyle());
2009 else
2011 if(aCol != aBoxItem.GetLeft()->GetColor() )
2012 bColDisable = true;
2013 if(!( aLine == *(aBoxItem.GetLeft())) )
2014 bStyleDisable = true;
2018 if( aBoxItem.GetRight() )
2020 if(!bCol)
2022 bCol = true;
2023 aCol = aBoxItem.GetRight()->GetColor() ;
2024 aLine.SetColor(aCol);
2025 aLine.SetWidth( aBoxItem.GetRight()->GetWidth());
2026 aLine.SetBorderLineStyle( aBoxItem.GetRight()->GetBorderLineStyle());
2028 else
2030 if(aCol != aBoxItem.GetRight()->GetColor() )
2031 bColDisable = true;
2032 if(!( aLine == *(aBoxItem.GetRight())) )
2033 bStyleDisable = true;
2037 if( aInfoItem.GetVert())
2039 if(!bCol)
2041 bCol = true;
2042 aCol = aInfoItem.GetVert()->GetColor() ;
2043 aLine.SetColor(aCol);
2044 aLine.SetWidth( aInfoItem.GetVert()->GetWidth());
2045 aLine.SetBorderLineStyle( aInfoItem.GetVert()->GetBorderLineStyle());
2047 else
2049 if(aCol != aInfoItem.GetVert()->GetColor() )
2050 bColDisable = true;
2051 if(!( aLine == *(aInfoItem.GetVert())) )
2052 bStyleDisable = true;
2056 if( aInfoItem.GetHori())
2058 if(!bCol)
2060 bCol = true;
2061 aCol = aInfoItem.GetHori()->GetColor() ;
2062 aLine.SetColor(aCol);
2063 aLine.SetWidth( aInfoItem.GetHori()->GetWidth());
2064 aLine.SetBorderLineStyle( aInfoItem.GetHori()->GetBorderLineStyle());
2066 else
2068 if(aCol != aInfoItem.GetHori()->GetColor() )
2069 bColDisable = true;
2070 if(!( aLine == *(aInfoItem.GetHori())) )
2071 bStyleDisable = true;
2075 if( !aInfoItem.IsValid( SvxBoxInfoItemValidFlags::VERT )
2076 || !aInfoItem.IsValid( SvxBoxInfoItemValidFlags::HORI )
2077 || !aInfoItem.IsValid( SvxBoxInfoItemValidFlags::LEFT )
2078 || !aInfoItem.IsValid( SvxBoxInfoItemValidFlags::RIGHT )
2079 || !aInfoItem.IsValid( SvxBoxInfoItemValidFlags::TOP )
2080 || !aInfoItem.IsValid( SvxBoxInfoItemValidFlags::BOTTOM ) )
2082 bColDisable = true;
2083 bStyleDisable = true;
2086 if(SID_FRAME_LINECOLOR == nWhich)
2088 if(bColDisable) // if different lines have differernt colors
2090 aCol = COL_TRANSPARENT;
2091 rSet.Put( SvxColorItem(aCol, SID_FRAME_LINECOLOR ) );
2092 rSet.InvalidateItem(SID_FRAME_LINECOLOR);
2094 else if( !bCol && !bColDisable) // if no line available
2096 aCol = COL_AUTO;
2097 rSet.Put( SvxColorItem(aCol, SID_FRAME_LINECOLOR ) );
2099 else
2100 rSet.Put( SvxColorItem(aCol, SID_FRAME_LINECOLOR ) );
2102 else // if( nWhich == SID_FRAME_LINESTYLE)
2104 if(bStyleDisable) // if have several lines but don't have same style
2106 aLine.SetWidth( 1 );
2107 SvxLineItem aItem(SID_FRAME_LINESTYLE);
2108 aItem.SetLine(&aLine);
2109 rSet.Put( aItem );
2110 rSet.InvalidateItem(SID_FRAME_LINESTYLE);
2112 else // all the lines have same style or no line availavle, use initial value (0,0,0,0)
2114 SvxLineItem aItem(SID_FRAME_LINESTYLE);
2115 aItem.SetLine(&aLine);
2116 rSet.Put( aItem );
2120 break;
2121 case SID_ATTR_BRUSH:
2123 rSet.Put( rBrushItem, GetPool().GetWhich(nWhich) );
2125 break;
2127 nWhich = aIter.NextWhich();
2130 // stuff for sidebar panels
2131 Invalidate(SID_ATTR_ALIGN_DEGREES);
2132 Invalidate(SID_ATTR_ALIGN_STACKED);
2135 void ScFormatShell::GetTextAttrState( SfxItemSet& rSet )
2137 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2138 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
2139 rSet.Put( rAttrSet, false ); // ItemStates mitkopieren
2141 // choose font info according to selection script type
2142 SvtScriptType nScript = SvtScriptType::NONE; // GetSelectionScriptType never returns 0
2143 if ( rSet.GetItemState( ATTR_FONT_WEIGHT ) != SfxItemState::UNKNOWN )
2145 if (nScript == SvtScriptType::NONE) nScript = pTabViewShell->GetSelectionScriptType();
2146 ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_WEIGHT, nScript );
2148 if ( rSet.GetItemState( ATTR_FONT_POSTURE ) != SfxItemState::UNKNOWN )
2150 if (nScript == SvtScriptType::NONE) nScript = pTabViewShell->GetSelectionScriptType();
2151 ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_POSTURE, nScript );
2154 SfxItemState eState;
2155 // const SfxPoolItem* pItem;
2157 // eigene Kontrolle ueber RadioButton-Funktionalitaet:
2159 // Unterstreichung
2161 eState = rAttrSet.GetItemState( ATTR_FONT_UNDERLINE, true );
2162 if ( eState == SfxItemState::DONTCARE )
2164 rSet.InvalidateItem( SID_ULINE_VAL_NONE );
2165 rSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
2166 rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
2167 rSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
2169 else
2171 FontUnderline eUnderline = static_cast<const SvxUnderlineItem&>(
2172 rAttrSet.Get(ATTR_FONT_UNDERLINE)).GetLineStyle();
2173 sal_uInt16 nId = SID_ULINE_VAL_NONE;
2174 switch (eUnderline)
2176 case UNDERLINE_SINGLE: nId = SID_ULINE_VAL_SINGLE; break;
2177 case UNDERLINE_DOUBLE: nId = SID_ULINE_VAL_DOUBLE; break;
2178 case UNDERLINE_DOTTED: nId = SID_ULINE_VAL_DOTTED; break;
2179 default:
2180 break;
2182 rSet.Put( SfxBoolItem( nId, true ) );
2185 // horizontale Ausrichtung
2187 const SvxHorJustifyItem* pHorJustify = NULL;
2188 const SvxVerJustifyItem* pVerJustify = NULL;
2189 SvxCellVerJustify eVerJustify = SVX_VER_JUSTIFY_STANDARD;
2190 sal_uInt16 nWhich = 0;
2191 bool bJustifyStd = false;
2192 SfxBoolItem aBoolItem ( 0, true );
2194 eState = rAttrSet.GetItemState( ATTR_HOR_JUSTIFY, true,
2195 reinterpret_cast<const SfxPoolItem**>(&pHorJustify) );
2196 switch ( eState )
2198 case SfxItemState::SET:
2200 switch ( SvxCellHorJustify( pHorJustify->GetValue() ) )
2202 case SVX_HOR_JUSTIFY_STANDARD:
2203 break;
2205 case SVX_HOR_JUSTIFY_LEFT:
2206 nWhich = SID_ALIGNLEFT;
2207 break;
2209 case SVX_HOR_JUSTIFY_RIGHT:
2210 nWhich = SID_ALIGNRIGHT;
2211 break;
2213 case SVX_HOR_JUSTIFY_CENTER:
2214 nWhich = SID_ALIGNCENTERHOR;
2215 break;
2217 case SVX_HOR_JUSTIFY_BLOCK:
2218 nWhich = SID_ALIGNBLOCK;
2219 break;
2221 case SVX_HOR_JUSTIFY_REPEAT:
2222 default:
2223 bJustifyStd = true;
2224 break;
2227 break;
2229 case SfxItemState::DONTCARE:
2230 rSet.InvalidateItem( SID_ALIGNLEFT );
2231 rSet.InvalidateItem( SID_ALIGNRIGHT );
2232 rSet.InvalidateItem( SID_ALIGNCENTERHOR );
2233 rSet.InvalidateItem( SID_ALIGNBLOCK );
2234 break;
2236 default:
2237 bJustifyStd = true;
2238 break;
2241 if ( nWhich )
2243 aBoolItem.SetWhich( nWhich );
2244 rSet.Put( aBoolItem );
2246 else if ( bJustifyStd )
2248 aBoolItem.SetValue( false );
2249 aBoolItem.SetWhich( SID_ALIGNLEFT ); rSet.Put( aBoolItem );
2250 aBoolItem.SetWhich( SID_ALIGNRIGHT ); rSet.Put( aBoolItem );
2251 aBoolItem.SetWhich( SID_ALIGNCENTERHOR ); rSet.Put( aBoolItem );
2252 aBoolItem.SetWhich( SID_ALIGNBLOCK ); rSet.Put( aBoolItem );
2253 bJustifyStd = false;
2256 // vertikale Ausrichtung
2258 nWhich = 0;
2259 aBoolItem.SetValue( true );
2261 eState = rAttrSet.GetItemState( ATTR_VER_JUSTIFY, true,
2262 reinterpret_cast<const SfxPoolItem**>(&pVerJustify) );
2264 switch ( eState )
2266 case SfxItemState::SET:
2268 eVerJustify = SvxCellVerJustify( pVerJustify->GetValue() );
2270 switch ( eVerJustify )
2272 case SVX_VER_JUSTIFY_TOP:
2273 nWhich = SID_ALIGNTOP;
2274 break;
2276 case SVX_VER_JUSTIFY_BOTTOM:
2277 nWhich = SID_ALIGNBOTTOM;
2278 break;
2280 case SVX_VER_JUSTIFY_CENTER:
2281 nWhich = SID_ALIGNCENTERVER;
2282 break;
2284 case SVX_VER_JUSTIFY_STANDARD:
2285 default:
2286 bJustifyStd = true;
2287 break;
2290 break;
2292 case SfxItemState::DONTCARE:
2293 rSet.InvalidateItem( SID_ALIGNTOP );
2294 rSet.InvalidateItem( SID_ALIGNBOTTOM );
2295 rSet.InvalidateItem( SID_ALIGNCENTERVER );
2296 break;
2298 default:
2299 bJustifyStd = true;
2300 break;
2303 if ( nWhich )
2305 aBoolItem.SetWhich( nWhich );
2306 rSet.Put( aBoolItem );
2308 else if ( bJustifyStd )
2310 aBoolItem.SetValue( false );
2311 aBoolItem.SetWhich( SID_ALIGNTOP ); rSet.Put( aBoolItem );
2312 aBoolItem.SetWhich( SID_ALIGNBOTTOM ); rSet.Put( aBoolItem );
2313 aBoolItem.SetWhich( SID_ALIGNCENTERVER ); rSet.Put( aBoolItem );
2317 void ScFormatShell::GetBorderState( SfxItemSet& rSet )
2319 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2320 SvxBoxItem aBoxItem( ATTR_BORDER );
2321 SvxBoxInfoItem aInfoItem( ATTR_BORDER_INNER );
2323 pTabViewShell->GetSelectionFrame( aBoxItem, aInfoItem );
2325 if ( rSet.GetItemState( ATTR_BORDER ) != SfxItemState::UNKNOWN )
2326 rSet.Put( aBoxItem );
2327 if ( rSet.GetItemState( ATTR_BORDER_INNER ) != SfxItemState::UNKNOWN )
2328 rSet.Put( aInfoItem );
2331 void ScFormatShell::GetAlignState( SfxItemSet& rSet )
2333 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2334 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
2335 SfxWhichIter aIter(rSet);
2336 sal_uInt16 nWhich = aIter.FirstWhich();
2338 SvxCellHorJustify eHAlign = SVX_HOR_JUSTIFY_STANDARD;
2339 bool bHasHAlign = rAttrSet.GetItemState( ATTR_HOR_JUSTIFY ) != SfxItemState::DONTCARE;
2340 if( bHasHAlign )
2341 eHAlign = (SvxCellHorJustify)static_cast<const SvxHorJustifyItem&>(rAttrSet.Get( ATTR_HOR_JUSTIFY )).GetValue();
2343 SvxCellVerJustify eVAlign = SVX_VER_JUSTIFY_STANDARD;
2344 bool bHasVAlign = rAttrSet.GetItemState( ATTR_VER_JUSTIFY ) != SfxItemState::DONTCARE;
2345 if( bHasVAlign )
2346 eVAlign = (SvxCellVerJustify)static_cast<const SvxVerJustifyItem&>(rAttrSet.Get( ATTR_VER_JUSTIFY )).GetValue();
2348 while ( nWhich )
2350 switch ( nWhich )
2352 case SID_H_ALIGNCELL:
2353 if ( bHasHAlign )
2354 rSet.Put( SvxHorJustifyItem( eHAlign, nWhich ));
2355 break;
2356 case SID_V_ALIGNCELL:
2357 if ( bHasVAlign )
2358 rSet.Put( SvxVerJustifyItem( eVAlign, nWhich ));
2359 break;
2361 // pseudo slots for Format menu
2362 case SID_ALIGN_ANY_HDEFAULT:
2363 case SID_ALIGN_ANY_LEFT:
2364 case SID_ALIGN_ANY_HCENTER:
2365 case SID_ALIGN_ANY_RIGHT:
2366 case SID_ALIGN_ANY_JUSTIFIED:
2367 rSet.Put( SfxBoolItem( nWhich, bHasHAlign && (eHAlign == lclConvertSlotToHAlign( nWhich )) ) );
2368 break;
2369 case SID_ALIGN_ANY_VDEFAULT:
2370 case SID_ALIGN_ANY_TOP:
2371 case SID_ALIGN_ANY_VCENTER:
2372 case SID_ALIGN_ANY_BOTTOM:
2373 rSet.Put( SfxBoolItem( nWhich, bHasVAlign && (eVAlign == lclConvertSlotToVAlign( nWhich )) ) );
2374 break;
2376 nWhich = aIter.NextWhich();
2380 void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
2382 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2383 ScDocument* pDoc = pViewData->GetDocument();
2384 short nType = GetCurrentNumberFormatType();
2386 SfxWhichIter aIter(rSet);
2387 sal_uInt16 nWhich = aIter.FirstWhich();
2388 while ( nWhich )
2390 switch ( nWhich )
2392 case SID_NUMBER_FORMAT:
2394 // String aFormatCode; // bleibt leer, wenn dont-care
2396 // const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
2397 // if ( rAttrSet.GetItemState( ATTR_VALUE_FORMAT ) != SfxItemState::DONTCARE )
2398 // {
2399 // sal_uLong nNumberFormat = ((const SfxUInt32Item&)rAttrSet.Get(
2400 // ATTR_VALUE_FORMAT )).GetValue();
2402 // SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
2403 // const SvNumberformat* pFormatEntry = pFormatter->GetEntry( nNumberFormat );
2404 // if ( pFormatEntry )
2405 // aFormatCode = pFormatEntry->GetFormatstring();
2406 // }
2408 // rSet.Put( SfxStringItem( nWhich, aFormatCode ) );
2411 // symphony version with format interpretation
2413 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
2415 if(SfxItemState::DONTCARE != rAttrSet.GetItemState(ATTR_VALUE_FORMAT))
2417 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
2418 sal_uInt32 nNumberFormat = static_cast<const SfxUInt32Item&>(rAttrSet.Get(ATTR_VALUE_FORMAT)).GetValue();
2419 bool bThousand(false);
2420 bool bNegRed(false);
2421 sal_uInt16 nPrecision(0);
2422 sal_uInt16 nLeadZeroes(0);
2424 pFormatter->GetFormatSpecialInfo(nNumberFormat,bThousand, bNegRed, nPrecision, nLeadZeroes);
2426 const SvNumberformat* pFormatEntry = pFormatter->GetEntry( nNumberFormat );
2427 if (pFormatEntry && (pFormatEntry->GetType() & css::util::NumberFormat::SCIENTIFIC))
2429 // if scientific, bThousand is used for engineering notation
2430 const sal_uInt16 nIntegerDigits = pFormatEntry->GetFormatIntegerDigits();
2431 if (nIntegerDigits > 0 && ((nIntegerDigits % 3) == 0))
2432 bThousand = true;
2433 else
2434 bThousand = false;
2436 OUString aFormat;
2437 static OUString sBreak = ",";
2438 const OUString sThousand = OUString::number(static_cast<sal_Int32>(bThousand));
2439 const OUString sNegRed = OUString::number(static_cast<sal_Int32>(bNegRed));
2440 const OUString sPrecision = OUString::number(nPrecision);
2441 const OUString sLeadZeroes = OUString::number(nLeadZeroes);
2443 aFormat += sThousand;
2444 aFormat += sBreak;
2445 aFormat += sNegRed;
2446 aFormat += sBreak;
2447 aFormat += sPrecision;
2448 aFormat += sBreak;
2449 aFormat += sLeadZeroes;
2450 aFormat += sBreak;
2452 rSet.Put(SfxStringItem(nWhich, aFormat));
2454 else
2456 rSet.InvalidateItem( nWhich );
2459 break;
2461 case SID_NUMBER_TYPE_FORMAT:
2463 sal_Int16 aFormatCode = -1;
2464 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
2465 if ( rAttrSet.GetItemState( ATTR_VALUE_FORMAT ) >= SfxItemState::DEFAULT ) //Modify for more robust
2467 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
2468 sal_uInt32 nNumberFormat = pTabViewShell->GetSelectionPattern()->GetNumberFormat( pFormatter );
2469 const SvNumberformat* pFormatEntry = pFormatter->GetEntry( nNumberFormat );
2470 bool bStandard = false;
2472 if ( pFormatEntry )
2474 aFormatCode = pFormatEntry->GetType();
2475 bStandard = pFormatEntry->IsStandard();
2478 switch(aFormatCode)
2480 case css::util::NumberFormat::NUMBER:
2481 case css::util::NumberFormat::NUMBER| css::util::NumberFormat::DEFINED:
2482 //use format code and standard format code to judge whether it is General,
2483 //if (nNumberFormat == nStandardNumberFormat)
2484 if (bStandard)
2485 aFormatCode = 0;
2486 else
2487 aFormatCode = 1;
2488 break;
2489 case css::util::NumberFormat::PERCENT:
2490 case css::util::NumberFormat::PERCENT| css::util::NumberFormat::DEFINED:
2491 aFormatCode = 2;
2492 break;
2493 case css::util::NumberFormat::CURRENCY:
2494 case css::util::NumberFormat::CURRENCY| css::util::NumberFormat::DEFINED:
2495 aFormatCode = 3;
2496 break;
2497 case css::util::NumberFormat::DATE:
2498 case css::util::NumberFormat::DATE| css::util::NumberFormat::DEFINED:
2499 //Add
2500 case css::util::NumberFormat::DATETIME:
2501 case css::util::NumberFormat::DATETIME | css::util::NumberFormat::DEFINED:
2502 aFormatCode = 4;
2503 break;
2504 case css::util::NumberFormat::TIME:
2505 case css::util::NumberFormat::TIME| css::util::NumberFormat::DEFINED:
2506 aFormatCode = 5;
2507 break;
2508 case css::util::NumberFormat::SCIENTIFIC:
2509 case css::util::NumberFormat::SCIENTIFIC| css::util::NumberFormat::DEFINED:
2510 aFormatCode = 6;
2511 break;
2512 case css::util::NumberFormat::FRACTION:
2513 case css::util::NumberFormat::FRACTION| css::util::NumberFormat::DEFINED:
2514 aFormatCode = 7;
2515 break;
2516 case css::util::NumberFormat::LOGICAL:
2517 case css::util::NumberFormat::LOGICAL| css::util::NumberFormat::DEFINED:
2518 aFormatCode = 8;
2519 break;
2520 case css::util::NumberFormat::TEXT:
2521 case css::util::NumberFormat::TEXT| css::util::NumberFormat::DEFINED:
2522 aFormatCode = 9;
2523 break;
2524 default:
2525 aFormatCode = -1; //for more roburst
2527 if( aFormatCode == -1 )
2528 rSet.InvalidateItem( nWhich );
2529 else
2530 rSet.Put( SfxInt16Item( nWhich, aFormatCode ) );
2532 else
2534 rSet.InvalidateItem( nWhich );
2538 break;
2539 case SID_NUMBER_SCIENTIFIC:
2540 rSet.Put( SfxBoolItem(nWhich, (nType & css::util::NumberFormat::SCIENTIFIC)) );
2541 break;
2542 case SID_NUMBER_DATE:
2543 rSet.Put( SfxBoolItem(nWhich, (nType & css::util::NumberFormat::DATE)) );
2544 break;
2545 case SID_NUMBER_CURRENCY:
2546 rSet.Put( SfxBoolItem(nWhich, (nType & css::util::NumberFormat::CURRENCY)) );
2547 break;
2548 case SID_NUMBER_PERCENT:
2549 rSet.Put( SfxBoolItem(nWhich, (nType & css::util::NumberFormat::PERCENT)) );
2550 break;
2551 case SID_NUMBER_TIME:
2552 rSet.Put( SfxBoolItem(nWhich, (nType & css::util::NumberFormat::TIME)) );
2553 break;
2555 nWhich = aIter.NextWhich();
2559 void ScFormatShell::ExecuteTextDirection( SfxRequest& rReq )
2561 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2562 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
2563 bool bEditMode = false;
2564 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
2566 bEditMode=true;
2567 SC_MOD()->InputEnterHandler();
2568 pTabViewShell->UpdateInputHandler();
2570 sal_uInt16 nSlot = rReq.GetSlot();
2571 switch( nSlot )
2573 case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
2574 case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
2576 bool bVert = (nSlot == SID_TEXTDIRECTION_TOP_TO_BOTTOM);
2577 ScPatternAttr aAttr( GetViewData()->GetDocument()->GetPool() );
2578 SfxItemSet& rItemSet = aAttr.GetItemSet();
2579 rItemSet.Put( SfxBoolItem( ATTR_STACKED, bVert ) );
2580 rItemSet.Put( SfxBoolItem( ATTR_VERTICAL_ASIAN, bVert ) );
2581 pTabViewShell->ApplySelectionPattern( aAttr );
2582 pTabViewShell->AdjustBlockHeight();
2584 break;
2586 case SID_ATTR_PARA_LEFT_TO_RIGHT:
2587 case SID_ATTR_PARA_RIGHT_TO_LEFT:
2589 SvxFrameDirection eDirection = ( nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT ) ?
2590 FRMDIR_HORI_LEFT_TOP : FRMDIR_HORI_RIGHT_TOP;
2591 pTabViewShell->ApplyAttr( SvxFrameDirectionItem( eDirection, ATTR_WRITINGDIR ) );
2593 break;
2595 if (bEditMode)
2596 SC_MOD()->SetInputMode( SC_INPUT_TABLE );
2599 void ScFormatShell::GetTextDirectionState( SfxItemSet& rSet )
2601 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2602 const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
2604 bool bVertDontCare =
2605 (rAttrSet.GetItemState( ATTR_VERTICAL_ASIAN ) == SfxItemState::DONTCARE) ||
2606 (rAttrSet.GetItemState( ATTR_STACKED ) == SfxItemState::DONTCARE);
2607 bool bLeftRight = !bVertDontCare &&
2608 !static_cast<const SfxBoolItem&>(rAttrSet.Get( ATTR_STACKED )).GetValue();
2609 bool bTopBottom = !bVertDontCare && !bLeftRight &&
2610 static_cast<const SfxBoolItem&>(rAttrSet.Get( ATTR_VERTICAL_ASIAN )).GetValue();
2612 bool bBidiDontCare = (rAttrSet.GetItemState( ATTR_WRITINGDIR ) == SfxItemState::DONTCARE);
2613 EEHorizontalTextDirection eBidiDir = EE_HTEXTDIR_DEFAULT;
2614 if ( !bBidiDontCare )
2616 SvxFrameDirection eCellDir = (SvxFrameDirection)static_cast<const SvxFrameDirectionItem&>(
2617 rAttrSet.Get( ATTR_WRITINGDIR )).GetValue();
2618 if ( eCellDir == FRMDIR_ENVIRONMENT )
2619 eBidiDir = (EEHorizontalTextDirection)GetViewData()->GetDocument()->
2620 GetEditTextDirection( GetViewData()->GetTabNo() );
2621 else if ( eCellDir == FRMDIR_HORI_RIGHT_TOP )
2622 eBidiDir = EE_HTEXTDIR_R2L;
2623 else
2624 eBidiDir = EE_HTEXTDIR_L2R;
2627 SvtLanguageOptions aLangOpt;
2628 bool bDisableCTLFont = !aLangOpt.IsCTLFontEnabled();
2629 bool bDisableVerticalText = !aLangOpt.IsVerticalTextEnabled();
2631 SfxWhichIter aIter( rSet );
2632 sal_uInt16 nWhich = aIter.FirstWhich();
2633 while( nWhich )
2635 switch( nWhich )
2637 case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
2638 case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
2639 if ( bDisableVerticalText )
2640 rSet.DisableItem( nWhich );
2641 else
2643 if( bVertDontCare )
2644 rSet.InvalidateItem( nWhich );
2645 else if ( nWhich == SID_TEXTDIRECTION_LEFT_TO_RIGHT )
2646 rSet.Put( SfxBoolItem( nWhich, bLeftRight ) );
2647 else
2648 rSet.Put( SfxBoolItem( nWhich, bTopBottom ) );
2650 break;
2652 case SID_ATTR_PARA_LEFT_TO_RIGHT:
2653 case SID_ATTR_PARA_RIGHT_TO_LEFT:
2654 if ( bDisableCTLFont )
2655 rSet.DisableItem( nWhich );
2656 else
2658 if ( bTopBottom )
2659 rSet.DisableItem( nWhich );
2660 else if ( bBidiDontCare )
2661 rSet.InvalidateItem( nWhich );
2662 else if ( nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT )
2663 rSet.Put( SfxBoolItem( nWhich, eBidiDir == EE_HTEXTDIR_L2R ) );
2664 else
2665 rSet.Put( SfxBoolItem( nWhich, eBidiDir == EE_HTEXTDIR_R2L ) );
2668 nWhich = aIter.NextWhich();
2672 void ScFormatShell::ExecFormatPaintbrush( SfxRequest& rReq )
2674 ScViewFunc* pView = pViewData->GetView();
2675 if ( pView->HasPaintBrush() )
2677 // cancel paintbrush mode
2678 pView->ResetBrushDocument();
2680 else
2682 bool bLock = false;
2683 const SfxItemSet *pArgs = rReq.GetArgs();
2684 if( pArgs && pArgs->Count() >= 1 )
2685 bLock = static_cast<const SfxBoolItem&>(pArgs->Get(SID_FORMATPAINTBRUSH)).GetValue();
2687 // in case of multi selection, deselect all and use the cursor position
2688 ScRange aDummy;
2689 if ( pViewData->GetSimpleArea(aDummy) != SC_MARK_SIMPLE )
2690 pView->Unmark();
2692 ScDocument* pBrushDoc = new ScDocument( SCDOCMODE_CLIP );
2693 pView->CopyToClip( pBrushDoc, false, true );
2694 pView->SetBrushDocument( pBrushDoc, bLock );
2698 void ScFormatShell::StateFormatPaintbrush( SfxItemSet& rSet )
2700 if ( pViewData->HasEditView( pViewData->GetActivePart() ) )
2701 rSet.DisableItem( SID_FORMATPAINTBRUSH );
2702 else
2703 rSet.Put( SfxBoolItem( SID_FORMATPAINTBRUSH, pViewData->GetView()->HasPaintBrush() ) );
2706 short ScFormatShell::GetCurrentNumberFormatType()
2708 short nType = css::util::NumberFormat::ALL;
2709 ScDocument* pDoc = GetViewData()->GetDocument();
2710 ScMarkData aMark(GetViewData()->GetMarkData());
2711 const SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
2712 if (!pFormatter)
2713 return nType;
2715 // TODO: Find out how to get a selected table range in case multiple tables
2716 // are selected. Currently we only check for the current active table.
2718 if ( aMark.IsMarked() || aMark.IsMultiMarked() )
2720 aMark.MarkToMulti();
2721 ScRange aRange;
2722 aMark.GetMultiMarkArea(aRange);
2724 const ScMarkArray* pArray = aMark.GetArray();
2725 if (!pArray)
2726 return nType;
2728 short nComboType = css::util::NumberFormat::ALL;
2729 bool bFirstItem = true;
2730 for (SCCOL nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); ++nCol)
2732 const ScMarkArray& rColArray = pArray[nCol];
2733 if (!rColArray.HasMarks())
2734 continue;
2736 SCROW nRow1, nRow2;
2737 ScMarkArrayIter aMarkIter(&rColArray);
2738 while (aMarkIter.Next(nRow1, nRow2))
2740 ScRange aColRange(nCol, nRow1, aRange.aStart.Tab());
2741 aColRange.aEnd.SetRow(nRow2);
2742 sal_uInt32 nNumFmt = pDoc->GetNumberFormat(aColRange);
2743 const SvNumberformat* pEntry = pFormatter->GetEntry(nNumFmt);
2744 if (!pEntry)
2745 return 0;
2747 short nThisType = pEntry->GetType();
2748 if (bFirstItem)
2750 bFirstItem = false;
2751 nComboType = nThisType;
2753 else if (nComboType != nThisType)
2754 // mixed number format type.
2755 return css::util::NumberFormat::ALL;
2758 nType = nComboType;
2760 else
2762 sal_uInt32 nNumFmt;
2763 pDoc->GetNumberFormat( pViewData->GetCurX(), pViewData->GetCurY(),
2764 pViewData->GetTabNo(), nNumFmt );
2765 const SvNumberformat* pEntry = pFormatter->GetEntry( nNumFmt );
2766 nType = pEntry ? pEntry->GetType() : 0;
2768 return nType;
2771 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */