xref: /aoo42x/main/sc/source/ui/view/formatsh.cxx (revision facb16e7)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 
32 //------------------------------------------------------------------
33 
34 //svdraw.hxx
35 #define _SDR_NOITEMS
36 #define _SDR_NOTOUCH
37 #define _SDR_NOTRANSFORM
38 #define _SI_NOSBXCONTROLS
39 #define _VCONT_HXX
40 #define _SI_NOOTHERFORMS
41 #define _VCTRLS_HXX
42 #define _SI_NOCONTROL
43 #define _SETBRW_HXX
44 #define _VCBRW_HXX
45 #define _SI_NOSBXCONTROLS
46 
47 //------------------------------------------------------------------
48 
49 #include "scitems.hxx"
50 #include <editeng/eeitem.hxx>
51 
52 #include <sfx2/app.hxx>
53 #include <sfx2/viewfrm.hxx>
54 #include <sfx2/objface.hxx>
55 #include <sfx2/request.hxx>
56 #include <svl/whiter.hxx>
57 #include <vcl/msgbox.hxx>
58 
59 #define _ZFORLIST_DECLARE_TABLE
60 #include <svl/stritem.hxx>
61 #include <svl/zformat.hxx>
62 #include <svl/languageoptions.hxx>
63 #include <editeng/boxitem.hxx>
64 #include <editeng/langitem.hxx>
65 #include <svx/numinf.hxx>
66 #include <sfx2/dispatch.hxx>
67 #include <sfx2/templdlg.hxx>
68 #include <sfx2/tplpitem.hxx>
69 #include <editeng/svxenum.hxx>
70 #include <svx/algitem.hxx>
71 #include <editeng/wghtitem.hxx>
72 #include <editeng/postitem.hxx>
73 #include <editeng/udlnitem.hxx>
74 #include <editeng/bolnitem.hxx>
75 #include <editeng/colritem.hxx>
76 #include <editeng/brshitem.hxx>
77 #include <editeng/frmdiritem.hxx>
78 #include <editeng/scripttypeitem.hxx>
79 #include <svtools/colorcfg.hxx>
80 #include <editeng/shaditem.hxx>
81 
82 #include "formatsh.hxx"
83 #include "sc.hrc"
84 #include "globstr.hrc"
85 #include "docsh.hxx"
86 #include "patattr.hxx"
87 #include "scmod.hxx"
88 //CHINA001 #include "styledlg.hxx"
89 #include "attrdlg.hrc"
90 #include "stlpool.hxx"
91 #include "stlsheet.hxx"
92 #include "printfun.hxx"
93 #include "docpool.hxx"
94 #include "scresid.hxx"
95 #include "tabvwsh.hxx"
96 #include "undostyl.hxx"
97 
98 
99 #define ScFormatShell
100 #define	TableFont
101 #define FormatForSelection
102 #include "scslots.hxx"
103 
104 #include "scabstdlg.hxx" //CHINA001
105 
106 namespace {
107 
108 SvxCellHorJustify lclConvertSlotToHAlign( sal_uInt16 nSlot )
109 {
110     SvxCellHorJustify eHJustify = SVX_HOR_JUSTIFY_STANDARD;
111     switch( nSlot )
112     {
113         case SID_ALIGN_ANY_HDEFAULT:    eHJustify = SVX_HOR_JUSTIFY_STANDARD;   break;
114         case SID_ALIGN_ANY_LEFT:        eHJustify = SVX_HOR_JUSTIFY_LEFT;       break;
115         case SID_ALIGN_ANY_HCENTER:     eHJustify = SVX_HOR_JUSTIFY_CENTER;     break;
116         case SID_ALIGN_ANY_RIGHT:       eHJustify = SVX_HOR_JUSTIFY_RIGHT;      break;
117         case SID_ALIGN_ANY_JUSTIFIED:   eHJustify = SVX_HOR_JUSTIFY_BLOCK;      break;
118         default:    DBG_ERRORFILE( "lclConvertSlotToHAlign - invalid slot" );
119     }
120     return eHJustify;
121 }
122 
123 SvxCellVerJustify lclConvertSlotToVAlign( sal_uInt16 nSlot )
124 {
125     SvxCellVerJustify eVJustify = SVX_VER_JUSTIFY_STANDARD;
126     switch( nSlot )
127     {
128         case SID_ALIGN_ANY_VDEFAULT:    eVJustify = SVX_VER_JUSTIFY_STANDARD;   break;
129         case SID_ALIGN_ANY_TOP:         eVJustify = SVX_VER_JUSTIFY_TOP;        break;
130         case SID_ALIGN_ANY_VCENTER:     eVJustify = SVX_VER_JUSTIFY_CENTER;     break;
131         case SID_ALIGN_ANY_BOTTOM:      eVJustify = SVX_VER_JUSTIFY_BOTTOM;     break;
132         default:    DBG_ERRORFILE( "lclConvertSlotToVAlign - invalid slot" );
133     }
134     return eVJustify;
135 }
136 
137 } // namespace
138 
139 TYPEINIT1( ScFormatShell, SfxShell );
140 
141 SFX_IMPL_INTERFACE(ScFormatShell, SfxShell, ScResId(SCSTR_FORMATSHELL) )
142 {
143 	SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD |
144 								SFX_VISIBILITY_SERVER,
145 								ScResId(RID_OBJECTBAR_FORMAT));
146 
147 }
148 
149 
150 ScFormatShell::ScFormatShell(ScViewData* pData) :
151 	SfxShell(pData->GetViewShell()),
152 	pViewData(pData)
153 {
154 	ScTabViewShell*	pTabViewShell = GetViewData()->GetViewShell();
155 
156 	SetPool( &pTabViewShell->GetPool() );
157     ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
158     SetUndoManager( pMgr );
159     if ( !pViewData->GetDocument()->IsUndoEnabled() )
160     {
161         pMgr->SetMaxUndoActionCount( 0 );
162     }
163 	SetHelpId(HID_SCSHELL_FORMATSH);
164 	SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Format")));
165 }
166 
167 ScFormatShell::~ScFormatShell()
168 {
169 }
170 
171 //------------------------------------------------------------------
172 
173 void __EXPORT ScFormatShell::GetStyleState( SfxItemSet& rSet )
174 {
175 	ScDocument*				pDoc  		= GetViewData()->GetDocument();
176 	ScTabViewShell*	pTabViewShell  		= GetViewData()->GetViewShell();
177 	SfxStyleSheetBasePool*	pStylePool	= pDoc->GetStyleSheetPool();
178 
179 	sal_Bool bProtected = sal_False;
180 	SCTAB nTabCount = pDoc->GetTableCount();
181 	for (SCTAB i=0; i<nTabCount; i++)
182 		if (pDoc->IsTabProtected(i))				// ueberhaupt eine Tabelle geschuetzt?
183 			bProtected = sal_True;
184 
185 	SfxWhichIter	aIter(rSet);
186 	sal_uInt16			nWhich = aIter.FirstWhich();
187 	sal_uInt16			nSlotId = 0;
188 
189 	while ( nWhich )
190 	{
191 		nSlotId = SfxItemPool::IsWhich( nWhich )
192 					? GetPool().GetSlotId( nWhich )
193 					: nWhich;
194 
195 		switch ( nSlotId )
196 		{
197 			case SID_STYLE_APPLY:
198 				if ( !pStylePool )
199 					rSet.DisableItem( nSlotId );
200 				break;
201 
202 			case SID_STYLE_FAMILY2:		// Zellvorlagen
203 			{
204 				SfxStyleSheet* pStyleSheet = (SfxStyleSheet*)
205 											 pTabViewShell->GetStyleSheetFromMarked();
206 
207 				if ( pStyleSheet )
208 					rSet.Put( SfxTemplateItem( nSlotId, pStyleSheet->GetName() ) );
209 				else
210 					rSet.Put( SfxTemplateItem( nSlotId, String() ) );
211 			}
212 			break;
213 
214 			case SID_STYLE_FAMILY4:		// Seitenvorlagen
215 			{
216 				SCTAB			nCurTab		= GetViewData()->GetTabNo();
217 				String			aPageStyle  = pDoc->GetPageStyle( nCurTab );
218 				SfxStyleSheet*	pStyleSheet = (SfxStyleSheet*)pStylePool->
219 									Find( aPageStyle, SFX_STYLE_FAMILY_PAGE );
220 
221 				if ( pStyleSheet )
222 					rSet.Put( SfxTemplateItem( nSlotId, aPageStyle ) );
223 				else
224 					rSet.Put( SfxTemplateItem( nSlotId, String() ) );
225 			}
226 			break;
227 
228 			case SID_STYLE_WATERCAN:
229 			{
230 				rSet.Put( SfxBoolItem( nSlotId, SC_MOD()->GetIsWaterCan() ) );
231 			}
232 			break;
233 
234 			case SID_STYLE_UPDATE_BY_EXAMPLE:
235 			{
236 				ISfxTemplateCommon* pDesigner = SFX_APP()->
237 						GetCurrentTemplateCommon(pTabViewShell->GetViewFrame()->GetBindings());
238 				sal_Bool bPage = pDesigner && SFX_STYLE_FAMILY_PAGE == pDesigner->GetActualFamily();
239 
240 				if ( bProtected || bPage )
241 					rSet.DisableItem( nSlotId );
242 			}
243 			break;
244 
245 			case SID_STYLE_EDIT:
246 			case SID_STYLE_DELETE:
247 			{
248 				ISfxTemplateCommon* pDesigner = SFX_APP()->
249 						GetCurrentTemplateCommon(pTabViewShell->GetViewFrame()->GetBindings());
250 				sal_Bool bPage = pDesigner && SFX_STYLE_FAMILY_PAGE == pDesigner->GetActualFamily();
251 
252 				if ( bProtected && !bPage )
253 					rSet.DisableItem( nSlotId );
254 			}
255 			break;
256 
257 			default:
258 				break;
259 		}
260 
261 		nWhich = aIter.NextWhich();
262 	}
263 }
264 
265 //------------------------------------------------------------------
266 
267 void __EXPORT ScFormatShell::ExecuteStyle( SfxRequest& rReq )
268 {
269 	// Wenn ToolBar vertikal :
270 	if ( !rReq.GetArgs() )
271 	{
272 		pViewData->GetDispatcher().Execute( SID_STYLE_DESIGNER, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
273 		return;
274 	}
275 
276 	//--------------------------------------------------------------------
277 	SfxBindings&		rBindings	= pViewData->GetBindings();
278 	const SfxItemSet*   pArgs   	= rReq.GetArgs();
279 	const sal_uInt16        nSlotId 	= rReq.GetSlot();
280 	const SCTAB		    nCurTab		= GetViewData()->GetTabNo();
281 	ScDocShell*			pDocSh		= GetViewData()->GetDocShell();
282 	ScTabViewShell*		pTabViewShell= GetViewData()->GetViewShell();
283 	ScDocument*         pDoc    	= pDocSh->GetDocument();
284 	ScMarkData&			rMark		= GetViewData()->GetMarkData();
285 	ScModule*			pScMod		= SC_MOD();
286 	String				aRefName;
287 	sal_Bool				bUndo		= pDoc->IsUndoEnabled();
288 
289 	if (   (nSlotId == SID_STYLE_NEW)
290 		|| (nSlotId == SID_STYLE_EDIT)
291 		|| (nSlotId == SID_STYLE_DELETE)
292 		|| (nSlotId == SID_STYLE_APPLY)
293 		|| (nSlotId == SID_STYLE_WATERCAN)
294 		|| (nSlotId == SID_STYLE_FAMILY)
295 		|| (nSlotId == SID_STYLE_NEW_BY_EXAMPLE)
296 		|| (nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE) )
297 	{
298 		SfxStyleSheetBasePool*  pStylePool	= pDoc->GetStyleSheetPool();
299 		SfxStyleSheetBase*      pStyleSheet = NULL;
300 
301 		sal_Bool bStyleToMarked = sal_False;
302 		sal_Bool bListAction = sal_False;
303 		sal_Bool bAddUndo = sal_False;			// add ScUndoModifyStyle (style modified)
304 		ScStyleSaveData aOldData;		// for undo/redo
305 		ScStyleSaveData aNewData;
306 
307 		SfxStyleFamily eFamily = SFX_STYLE_FAMILY_PARA;
308 		const SfxPoolItem* pFamItem;
309 		if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_FAMILY, sal_True, &pFamItem ) )
310 			eFamily = (SfxStyleFamily)((const SfxUInt16Item*)pFamItem)->GetValue();
311         else
312 		if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_FAMILYNAME, sal_True, &pFamItem ) )
313         {
314             String sFamily = ((const SfxStringItem*)pFamItem)->GetValue();
315             if (sFamily.CompareToAscii("CellStyles") == COMPARE_EQUAL)
316                 eFamily = SFX_STYLE_FAMILY_PARA;
317             else
318             if (sFamily.CompareToAscii("PageStyles") == COMPARE_EQUAL)
319                 eFamily = SFX_STYLE_FAMILY_PAGE;
320         }
321 
322 		String                  aStyleName;
323 		sal_uInt16                  nRetMask = 0xffff;
324 //      #96983# only stylist sends focus to sheet
325 //        sal_Bool                    bGrabFocus = ( SID_STYLE_APPLY == nSlotId );
326 
327 		pStylePool->SetSearchMask( eFamily, SFXSTYLEBIT_ALL );
328 
329 		switch ( nSlotId )
330 		{
331 			case SID_STYLE_NEW:
332 				{
333 					const SfxPoolItem* pNameItem;
334 					if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( nSlotId, sal_True, &pNameItem ))
335 						aStyleName  = ((const SfxStringItem*)pNameItem)->GetValue();
336 
337 					const SfxPoolItem* pRefItem=NULL;
338 					if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_STYLE_REFERENCE, sal_True, &pRefItem ))
339 					{
340 						if(pRefItem!=NULL)
341 							aRefName  = ((const SfxStringItem*)pRefItem)->GetValue();
342 					}
343 
344 					pStyleSheet = &(pStylePool->Make( aStyleName, eFamily,
345 													  SFXSTYLEBIT_USERDEF ) );
346 
347 					if ( pStyleSheet && pStyleSheet->HasParentSupport() )
348 						pStyleSheet->SetParent(aRefName);
349 				}
350 				break;
351 
352 			case SID_STYLE_APPLY:
353             {
354                 SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_APPLY_STYLE, sal_False );
355                 SFX_REQUEST_ARG( rReq, pFamilyItem, SfxStringItem, SID_STYLE_FAMILYNAME, sal_False );
356                 if ( pFamilyItem && pNameItem )
357                 {
358                     com::sun::star::uno::Reference< com::sun::star::style::XStyleFamiliesSupplier > xModel(pDocSh->GetModel(), com::sun::star::uno::UNO_QUERY);
359                     try
360                     {
361                         com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xStyles;
362                         com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xCont = xModel->getStyleFamilies();
363                         xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
364                         com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xInfo;
365                         xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
366                         ::rtl::OUString aUIName;
367                         xInfo->getPropertyValue( ::rtl::OUString::createFromAscii("DisplayName") ) >>= aUIName;
368                         if ( aUIName.getLength() )
369                             rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
370                     }
371                     catch( com::sun::star::uno::Exception& )
372                     {
373                     }
374                 }
375             }
376 			case SID_STYLE_EDIT:
377 			case SID_STYLE_DELETE:
378 			case SID_STYLE_NEW_BY_EXAMPLE:
379 				{
380 					const SfxPoolItem* pNameItem;
381 					if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( nSlotId, sal_True, &pNameItem ))
382 						aStyleName  = ((const SfxStringItem*)pNameItem)->GetValue();
383 					pStyleSheet = pStylePool->Find( aStyleName, eFamily );
384 
385 					aOldData.InitFromStyle( pStyleSheet );
386 				}
387 				break;
388 
389 			case SID_STYLE_WATERCAN:
390 			{
391 				sal_Bool bWaterCan = pScMod->GetIsWaterCan();
392 
393 				if( !bWaterCan )
394 				{
395 					const SfxPoolItem* pItem;
396 
397 					if ( SFX_ITEM_SET ==
398 						 pArgs->GetItemState( nSlotId, sal_True, &pItem ) )
399 					{
400 						const SfxStringItem* pStrItem = PTR_CAST(SfxStringItem,pItem);
401 						if ( pStrItem )
402 						{
403 							aStyleName  = pStrItem->GetValue();
404 							pStyleSheet = pStylePool->Find( aStyleName, eFamily );
405 
406 							if ( pStyleSheet )
407 							{
408 								((ScStyleSheetPool*)pStylePool)->
409 										SetActualStyleSheet( pStyleSheet );
410 								rReq.Done();
411 							}
412 						}
413 					}
414 				}
415 
416 				if ( !bWaterCan && pStyleSheet )
417 				{
418 					pScMod->SetWaterCan( sal_True );
419 					pTabViewShell->SetActivePointer( Pointer(POINTER_FILL) );
420 					rReq.Done();
421 				}
422 				else
423 				{
424 					pScMod->SetWaterCan( sal_False );
425 					pTabViewShell->SetActivePointer( Pointer(POINTER_ARROW) );
426 					rReq.Done();
427 				}
428 			}
429 			break;
430 
431 			default:
432 				break;
433 		}
434 
435 		// Neuen Style fuer WaterCan-Mode setzen
436 		if ( nSlotId == SID_STYLE_APPLY && pScMod->GetIsWaterCan() && pStyleSheet )
437 			((ScStyleSheetPool*)pStylePool)->SetActualStyleSheet( pStyleSheet );
438 
439 		switch ( eFamily )
440 		{
441 			case SFX_STYLE_FAMILY_PARA:
442 			{
443 				switch ( nSlotId )
444 				{
445 					case SID_STYLE_DELETE:
446 					{
447 						if ( pStyleSheet )
448 						{
449                             pTabViewShell->RemoveStyleSheetInUse( pStyleSheet );
450 							pStylePool->Remove( pStyleSheet );
451 							pTabViewShell->InvalidateAttribs();
452 							nRetMask = sal_True;
453 							bAddUndo = sal_True;
454 							rReq.Done();
455 						}
456 						else
457 							nRetMask = sal_False;
458 					}
459 					break;
460 
461 					case SID_STYLE_APPLY:
462 					{
463 						if ( pStyleSheet && !pScMod->GetIsWaterCan() )
464 						{
465 							// Anwenden der Vorlage auf das Dokument
466 							pTabViewShell->SetStyleSheetToMarked( (SfxStyleSheet*)pStyleSheet );
467 							pTabViewShell->InvalidateAttribs();
468 							rReq.Done();
469 						}
470 					}
471 					break;
472 
473 					case SID_STYLE_NEW_BY_EXAMPLE:
474 					case SID_STYLE_UPDATE_BY_EXAMPLE:
475 					{
476 						// Vorlage erzeugen/ersetzen durch Attribute
477 						// an der Cursor-Position:
478 
479 						const ScPatternAttr* pAttrItem = NULL;
480 
481 						// Die Abfrage, ob markiert ist, war hier immer falsch,
482 						// darum jetzt gar nicht mehr, und einfach vom Cursor.
483 						// Wenn Attribute aus der Selektion genommen werden sollen,
484 						// muss noch darauf geachtet werden, Items aus Vorlagen nicht
485 						// zu uebernehmen (GetSelectionPattern sammelt auch Items aus
486 						// Vorlagen zusammen) (#44748#)
487 						//		pAttrItem = GetSelectionPattern();
488 
489                         // ScViewData* pViewData = GetViewData();
490 						SCCOL		nCol = pViewData->GetCurX();
491 						SCROW		nRow = pViewData->GetCurY();
492 						pAttrItem = pDoc->GetPattern( nCol, nRow, nCurTab );
493 
494 						SfxItemSet aAttrSet = pAttrItem->GetItemSet();
495 						aAttrSet.ClearItem( ATTR_MERGE );
496 						aAttrSet.ClearItem( ATTR_MERGE_FLAG );
497 						//	bedingte Formatierung und Gueltigkeit nicht uebernehmen,
498 						//	weil sie in der Vorlage nicht editiert werden koennen
499 						aAttrSet.ClearItem( ATTR_VALIDDATA );
500 						aAttrSet.ClearItem( ATTR_CONDITIONAL );
501 
502 						if ( SID_STYLE_NEW_BY_EXAMPLE == nSlotId )
503 						{
504 							if ( bUndo )
505 							{
506 								String aUndo = ScGlobal::GetRscString( STR_UNDO_EDITCELLSTYLE );
507 								pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
508 								bListAction = sal_True;
509 							}
510 
511 							sal_Bool			bConvertBack = sal_False;
512 							SfxStyleSheet*	pSheetInUse = (SfxStyleSheet*)
513 														  pTabViewShell->GetStyleSheetFromMarked();
514 
515 							// wenn neuer Style vorhanden und in der Selektion
516 							// verwendet wird, so darf der Parent nicht uebernommen
517 							// werden:
518 
519 							if ( pStyleSheet && pSheetInUse && pStyleSheet == pSheetInUse )
520 								pSheetInUse = NULL;
521 
522 							// wenn bereits vorhanden, erstmal entfernen...
523 							if ( pStyleSheet )
524 							{
525 								// Style-Pointer zu Namen vor Erase,
526 								// weil Zellen sonst ungueltige Pointer
527 								// enthalten.
528 								//!!! bei Gelenheit mal eine Methode, die
529 								//    das fuer einen bestimmten Style macht
530 								pDoc->StylesToNames();
531 								bConvertBack = sal_True;
532 								pStylePool->Remove(pStyleSheet);
533 							}
534 
535 							// ...und neu anlegen
536 							pStyleSheet = &pStylePool->Make( aStyleName, eFamily,
537 															 SFXSTYLEBIT_USERDEF );
538 
539 							// wenn ein Style vorhanden ist, so wird dieser
540 							// Parent der neuen Vorlage:
541 							if ( pSheetInUse && pStyleSheet->HasParentSupport() )
542 								pStyleSheet->SetParent( pSheetInUse->GetName() );
543 
544 							if ( bConvertBack )
545 								// Namen zu Style-Pointer
546 								pDoc->UpdStlShtPtrsFrmNms();
547                             else
548                                 pDoc->GetPool()->CellStyleCreated( aStyleName );
549 
550 							// Attribute uebernehmen und Style anwenden
551 							pStyleSheet->GetItemSet().Put( aAttrSet );
552                             pTabViewShell->UpdateStyleSheetInUse( pStyleSheet );
553 
554 							//	call SetStyleSheetToMarked after adding the ScUndoModifyStyle
555 							//	(pStyleSheet pointer is used!)
556 							bStyleToMarked = sal_True;
557 						}
558 						else // ( nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE )
559 						{
560 							pStyleSheet = (SfxStyleSheet*)pTabViewShell->GetStyleSheetFromMarked();
561 
562 							if ( pStyleSheet )
563 							{
564 								aOldData.InitFromStyle( pStyleSheet );
565 
566 								if ( bUndo )
567 								{
568 									String aUndo = ScGlobal::GetRscString( STR_UNDO_EDITCELLSTYLE );
569 									pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
570 									bListAction = sal_True;
571 								}
572 
573 								pStyleSheet->GetItemSet().Put( aAttrSet );
574                                 pTabViewShell->UpdateStyleSheetInUse( pStyleSheet );
575 
576 								//	call SetStyleSheetToMarked after adding the ScUndoModifyStyle
577 								//	(pStyleSheet pointer is used!)
578 								bStyleToMarked = sal_True;
579 							}
580 						}
581 
582 						aNewData.InitFromStyle( pStyleSheet );
583 						bAddUndo = sal_True;
584 						rReq.Done();
585 					}
586 					break;
587 
588 					default:
589 						break;
590 				}
591 			} // case SFX_STYLE_FAMILY_PARA:
592 			break;
593 
594 			case SFX_STYLE_FAMILY_PAGE:
595 			{
596 				switch ( nSlotId )
597 				{
598 					case SID_STYLE_DELETE:
599 					{
600 						nRetMask = ( NULL != pStyleSheet );
601 						if ( pStyleSheet )
602 						{
603 							if ( pDoc->RemovePageStyleInUse( pStyleSheet->GetName() ) )
604 							{
605 								ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(sal_True), nCurTab ).UpdatePages();
606 								rBindings.Invalidate( SID_STATUS_PAGESTYLE );
607 								rBindings.Invalidate( FID_RESET_PRINTZOOM );
608 							}
609 							pStylePool->Remove( pStyleSheet );
610 							rBindings.Invalidate( SID_STYLE_FAMILY4 );
611 							pDocSh->SetDocumentModified();
612 							bAddUndo = sal_True;
613 							rReq.Done();
614 						}
615 					}
616 					break;
617 
618 					case SID_STYLE_APPLY:
619 					{
620 						nRetMask = ( NULL != pStyleSheet );
621 						if ( pStyleSheet && !pScMod->GetIsWaterCan() )
622 						{
623                             ScUndoApplyPageStyle* pUndoAction = 0;
624                             for( SCTAB nTab = 0, nTabCount = pDoc->GetTableCount(); nTab < nTabCount; ++nTab )
625                             {
626                                 if( rMark.GetTableSelect( nTab ) )
627                                 {
628                                     String aOldName = pDoc->GetPageStyle( nTab );
629                                     if ( aOldName != aStyleName )
630                                     {
631                                         pDoc->SetPageStyle( nTab, aStyleName );
632                                         ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(sal_True), nTab ).UpdatePages();
633                                         if( !pUndoAction )
634                                             pUndoAction = new ScUndoApplyPageStyle( pDocSh, aStyleName );
635                                         pUndoAction->AddSheetAction( nTab, aOldName );
636                                     }
637                                 }
638                             }
639                             if( pUndoAction )
640                             {
641                                 pDocSh->GetUndoManager()->AddUndoAction( pUndoAction );
642                                 pDocSh->SetDocumentModified();
643                                 rBindings.Invalidate( SID_STYLE_FAMILY4 );
644                                 rBindings.Invalidate( SID_STATUS_PAGESTYLE );
645                                 rBindings.Invalidate( FID_RESET_PRINTZOOM );
646                             }
647 							rReq.Done();
648 						}
649 					}
650 					break;
651 
652 					case SID_STYLE_NEW_BY_EXAMPLE:
653 					{
654 						const String& rStrCurStyle = pDoc->GetPageStyle( nCurTab );
655 
656 						if ( rStrCurStyle != aStyleName )
657 						{
658 							SfxStyleSheetBase*	pCurStyle = pStylePool->Find( rStrCurStyle, eFamily );
659 							SfxItemSet			aAttrSet  = pCurStyle->GetItemSet();
660 							SCTAB				nInTab;
661 							sal_Bool				bUsed = pDoc->IsPageStyleInUse( aStyleName, &nInTab );
662 
663 							// wenn bereits vorhanden, erstmal entfernen...
664 							if ( pStyleSheet )
665 								pStylePool->Remove( pStyleSheet );
666 
667 							// ...und neu anlegen
668 							pStyleSheet = &pStylePool->Make( aStyleName, eFamily,
669 															 SFXSTYLEBIT_USERDEF );
670 
671 							// Attribute uebernehmen
672 							pStyleSheet->GetItemSet().Put( aAttrSet );
673 							pDocSh->SetDocumentModified();
674 
675 							// wenn in Verwendung -> Update
676 							if ( bUsed )
677 								ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(sal_True), nInTab ).UpdatePages();
678 
679 							aNewData.InitFromStyle( pStyleSheet );
680 							bAddUndo = sal_True;
681 							rReq.Done();
682 							nRetMask = sal_True;
683 						}
684 					}
685 					break;
686 
687 					default:
688 						break;
689 				} // switch ( nSlotId )
690 			} // case SFX_STYLE_FAMILY_PAGE:
691 			break;
692 
693 			default:
694 				break;
695 		} // switch ( eFamily )
696 
697 		// Neu anlegen oder bearbeiten ueber Dialog:
698 		if ( nSlotId == SID_STYLE_NEW || nSlotId == SID_STYLE_EDIT )
699 		{
700 			if ( pStyleSheet )
701 			{
702 				SvxNumberInfoItem* pNumberInfoItem = NULL;
703 
704 				SfxStyleFamily	eFam    = pStyleSheet->GetFamily();
705                 // ScDocument*     pDoc    = GetViewData()->GetDocument();
706                 // ScDocShell*     pDocSh  = GetViewData()->GetDocShell();
707 				//CHINA001 ScStyleDlg*		pDlg    = NULL;
708 				SfxAbstractTabDialog* pDlg    = NULL; //CHINA001
709 				sal_uInt16			nRsc	= 0;
710 
711 				//	#37034#/#37245# alte Items aus der Vorlage merken
712 				SfxItemSet aOldSet = pStyleSheet->GetItemSet();
713 				String aOldName = pStyleSheet->GetName();
714 
715 				switch ( eFam )
716 				{
717 					case SFX_STYLE_FAMILY_PAGE:
718 						nRsc = RID_SCDLG_STYLES_PAGE;
719 						break;
720 
721 					case SFX_STYLE_FAMILY_PARA:
722 					default:
723 						{
724 							SfxItemSet& rSet = pStyleSheet->GetItemSet();
725 
726 							const SfxPoolItem* pItem;
727 							if ( rSet.GetItemState( ATTR_VALUE_FORMAT,
728 									sal_False, &pItem ) == SFX_ITEM_SET )
729 							{
730 								// NumberFormat Value aus Value und Language
731 								// erzeugen und eintueten
732 								sal_uLong nFormat =
733 									((SfxUInt32Item*)pItem)->GetValue();
734 								LanguageType eLang =
735 									((SvxLanguageItem*)&rSet.Get(
736 									ATTR_LANGUAGE_FORMAT ))->GetLanguage();
737 								sal_uLong nLangFormat = pDoc->GetFormatTable()->
738 									GetFormatForLanguageIfBuiltIn( nFormat, eLang );
739 								if ( nLangFormat != nFormat )
740 								{
741 									SfxUInt32Item aNewItem( ATTR_VALUE_FORMAT, nLangFormat );
742 									rSet.Put( aNewItem );
743 									aOldSet.Put( aNewItem );
744 									// auch in aOldSet fuer Vergleich nach dem Dialog,
745 									// sonst geht evtl. eine Aenderung der Sprache verloren
746 								}
747 							}
748 
749 							pTabViewShell->MakeNumberInfoItem( pDoc, GetViewData(), &pNumberInfoItem );
750 							pDocSh->PutItem( *pNumberInfoItem );
751 							nRsc = RID_SCDLG_STYLES_PAR;
752 
753 							//	auf jeden Fall ein SvxBoxInfoItem mit Table = sal_False im Set:
754 							//	(wenn gar kein Item da ist, loescht der Dialog auch das
755 							//	 BORDER_OUTER SvxBoxItem aus dem Vorlagen-Set)
756 
757 							if ( rSet.GetItemState( ATTR_BORDER_INNER, sal_False ) != SFX_ITEM_SET )
758 							{
759 								SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
760 								aBoxInfoItem.SetTable(sal_False);		// keine inneren Linien
761                                 aBoxInfoItem.SetDist(sal_True);
762                                 aBoxInfoItem.SetMinDist(sal_False);
763 								rSet.Put( aBoxInfoItem );
764 							}
765 						}
766 						break;
767 				}
768 
769 				//	If GetDefDialogParent is a dialog, it must be used
770 				//	(style catalog)
771 
772 				Window* pParent = Application::GetDefDialogParent();
773 				if ( !pParent || !pParent->IsDialog() )
774 				{
775 					//	#107256# GetDefDialogParent currently doesn't return the window
776 					//	that was set with SetDefDialogParent (but dynamically finds the
777 					//	topmost parent of the focus window), so IsDialog above is FALSE
778 					//	even if called from the style catalog.
779 					//	-> Use NULL if a modal dialog is open, to enable the Dialog's
780 					//	default parent handling.
781 					if ( Application::IsInModalMode() )
782 						pParent = NULL;
783 					else
784 						pParent = pTabViewShell->GetDialogParent();
785 				}
786 
787 				pTabViewShell->SetInFormatDialog(sal_True);
788 
789 				//CHINA001 pDlg = new ScStyleDlg( pParent, *pStyleSheet, nRsc );
790 				ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
791 				DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
792 
793 				pDlg = pFact->CreateScStyleDlg( pParent, *pStyleSheet, nRsc, nRsc );
794 				DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
795 				short nResult = pDlg->Execute();
796 				pTabViewShell->SetInFormatDialog(sal_False);
797 
798 				if ( nResult == RET_OK )
799 				{
800 					const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
801 
802 					if ( pOutSet )
803 					{
804 						nRetMask = pStyleSheet->GetMask();
805 
806 						//	#37034#/#37245# Attribut-Vergleiche (frueher in ModifyStyleSheet)
807 						//	jetzt hier mit den alten Werten (Style ist schon veraendert)
808 
809 						if ( SFX_STYLE_FAMILY_PARA == eFam )
810 						{
811 //							pDoc->CellStyleChanged( *pStyleSheet, aOldSet );
812 
813 							SfxItemSet& rNewSet = pStyleSheet->GetItemSet();
814 							sal_Bool bNumFormatChanged;
815 							if ( ScGlobal::CheckWidthInvalidate(
816 												bNumFormatChanged, aOldSet, rNewSet ) )
817 								pDoc->InvalidateTextWidth( NULL, NULL, bNumFormatChanged );
818 
819                             SCTAB nTabCount = pDoc->GetTableCount();
820                             for (SCTAB nTab=0; nTab<nTabCount; nTab++)
821                                 if (pDoc->IsStreamValid(nTab))
822                                     pDoc->SetStreamValid(nTab, sal_False);
823 
824 							sal_uLong nOldFormat = ((const SfxUInt32Item&)aOldSet.
825 													Get( ATTR_VALUE_FORMAT )).GetValue();
826 							sal_uLong nNewFormat = ((const SfxUInt32Item&)rNewSet.
827 													Get( ATTR_VALUE_FORMAT )).GetValue();
828 							if ( nNewFormat != nOldFormat )
829 							{
830 								SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
831 								const SvNumberformat* pOld = pFormatter->GetEntry( nOldFormat );
832 								const SvNumberformat* pNew = pFormatter->GetEntry( nNewFormat );
833 								if ( pOld && pNew && pOld->GetLanguage() != pNew->GetLanguage() )
834 									rNewSet.Put( SvxLanguageItem(
835 													pNew->GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
836 							}
837 
838                             pDoc->GetPool()->CellStyleCreated( pStyleSheet->GetName() );
839 						}
840 						else
841 						{
842 							//!	auch fuer Seitenvorlagen die Abfragen hier
843 
844 							String aNewName = pStyleSheet->GetName();
845 							if ( aNewName != aOldName &&
846 									pDoc->RenamePageStyleInUse( aOldName, aNewName ) )
847 							{
848 								rBindings.Invalidate( SID_STATUS_PAGESTYLE );
849 								rBindings.Invalidate( FID_RESET_PRINTZOOM );
850 							}
851 
852 							pDoc->ModifyStyleSheet( *pStyleSheet, *pOutSet );
853 							rBindings.Invalidate( FID_RESET_PRINTZOOM );
854 						}
855 
856 						pDocSh->SetDocumentModified();
857 
858 						if ( SFX_STYLE_FAMILY_PARA == eFam )
859 						{
860 							pTabViewShell->UpdateNumberFormatter( pDoc,
861 								(const SvxNumberInfoItem&)
862 									*(pDocSh->GetItem(SID_ATTR_NUMBERFORMAT_INFO)) );
863 
864                             pTabViewShell->UpdateStyleSheetInUse( pStyleSheet );
865 							pTabViewShell->InvalidateAttribs();
866 						}
867 
868 						aNewData.InitFromStyle( pStyleSheet );
869 						bAddUndo = sal_True;
870 					}
871 				}
872 				else
873 				{
874 					if ( nSlotId == SID_STYLE_NEW )
875 						pStylePool->Remove( pStyleSheet );
876 					else
877 					{
878 						//	falls zwischendurch etwas mit dem temporaer geaenderten
879 						//	ItemSet gepainted wurde:
880 						pDocSh->PostPaintGridAll();
881 					}
882 				}
883 				delete pDlg;
884 			}
885 		}
886 
887 //		if ( nRetMask != 0xffff )// Irgendein Wert MUSS geliefert werden JN
888 			rReq.SetReturnValue( SfxUInt16Item( nSlotId, nRetMask ) );
889 
890 //      #96983# only stylist sends focus to sheet
891 //        if ( bGrabFocus )
892 //            pTabViewShell->GetActiveWin()->GrabFocus();
893 
894 		if ( bAddUndo && bUndo)
895 			pDocSh->GetUndoManager()->AddUndoAction(
896 						new ScUndoModifyStyle( pDocSh, eFamily, aOldData, aNewData ) );
897 
898 		if ( bStyleToMarked )
899 		{
900 			//	call SetStyleSheetToMarked after adding the ScUndoModifyStyle,
901 			//	so redo will find the modified style
902 			pTabViewShell->SetStyleSheetToMarked( (SfxStyleSheet*)pStyleSheet );
903 			pTabViewShell->InvalidateAttribs();
904 		}
905 
906 		if ( bListAction )
907 			pDocSh->GetUndoManager()->LeaveListAction();
908 	}
909 	else
910 	{
911 		DBG_ERROR( "Unknown slot (ScViewShell::ExecuteStyle)" );
912 	}
913 }
914 
915 void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
916 {
917 	ScModule*			pScMod		= SC_MOD();
918 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
919 	const SfxItemSet*	pReqArgs	= rReq.GetArgs();
920 	sal_uInt16				nSlot		= rReq.GetSlot();
921 
922 	pTabViewShell->HideListBox();					// Autofilter-DropDown-Listbox
923 
924 									// Eingabe beenden
925 	if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
926 	{
927 		switch ( nSlot )
928 		{
929 			case SID_NUMBER_TWODEC:
930 			case SID_NUMBER_SCIENTIFIC:
931 			case SID_NUMBER_DATE:
932 			case SID_NUMBER_CURRENCY:
933 			case SID_NUMBER_PERCENT:
934 			case SID_NUMBER_STANDARD:
935 			case SID_NUMBER_FORMAT:
936 			case SID_NUMBER_INCDEC:
937 			case SID_NUMBER_DECDEC:
938 			case FID_DEFINE_NAME:
939 			case FID_USE_NAME:
940 			case FID_INSERT_NAME:
941             case SID_SPELL_DIALOG:
942             case SID_HANGUL_HANJA_CONVERSION:
943 
944 			pScMod->InputEnterHandler();
945 			pTabViewShell->UpdateInputHandler();
946 			break;
947 
948 			default:
949 			break;
950 		}
951 	}
952 
953 	switch ( nSlot )
954 	{
955 		case SID_NUMBER_TWODEC:
956 			pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER, 4 );		// Standard+4 = #.##0,00
957 			rReq.Done();
958 			break;
959 		case SID_NUMBER_SCIENTIFIC:
960 			pTabViewShell->SetNumberFormat( NUMBERFORMAT_SCIENTIFIC );
961 			rReq.Done();
962 			break;
963 		case SID_NUMBER_DATE:
964 			pTabViewShell->SetNumberFormat( NUMBERFORMAT_DATE );
965 			rReq.Done();
966 			break;
967 		case SID_NUMBER_TIME:
968 			pTabViewShell->SetNumberFormat( NUMBERFORMAT_TIME );
969 			rReq.Done();
970 			break;
971 		case SID_NUMBER_CURRENCY:
972 			pTabViewShell->SetNumberFormat( NUMBERFORMAT_CURRENCY );
973 			rReq.Done();
974 			break;
975 		case SID_NUMBER_PERCENT:
976 			pTabViewShell->SetNumberFormat( NUMBERFORMAT_PERCENT );
977 			rReq.Done();
978 			break;
979 		case SID_NUMBER_STANDARD:
980 			pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
981 			rReq.Done();
982 			break;
983 		case SID_NUMBER_INCDEC:
984 			pTabViewShell->ChangeNumFmtDecimals( sal_True );
985 			rReq.Done();
986 			break;
987 		case SID_NUMBER_DECDEC:
988 			pTabViewShell->ChangeNumFmtDecimals( sal_False );
989 			rReq.Done();
990 			break;
991 
992 		case SID_NUMBER_FORMAT:
993 			if ( pReqArgs )
994 			{
995 				const SfxPoolItem* pItem;
996 				if(pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET)
997 				{
998 					String aCode = ((const SfxStringItem*)pItem)->GetValue();
999 					pTabViewShell->SetNumFmtByStr( aCode );
1000 				}
1001 			}
1002 			break;
1003 
1004         case SID_ATTR_NUMBERFORMAT_VALUE:
1005 			if ( pReqArgs )
1006 			{
1007 				const SfxPoolItem* pItem;
1008 				if ( pReqArgs->GetItemState( ATTR_VALUE_FORMAT, sal_True, &pItem ) == SFX_ITEM_SET )
1009 				{
1010                     // We have to accomplish this using ApplyAttributes()
1011                     // because we also need the language information to be
1012                     // considered.
1013                     const SfxItemSet& rOldSet =
1014                         pTabViewShell->GetSelectionPattern()->GetItemSet();
1015                     SfxItemPool* pDocPool = GetViewData()->GetDocument()->GetPool();
1016                     SfxItemSet aNewSet( *pDocPool, ATTR_PATTERN_START, ATTR_PATTERN_END );
1017                     aNewSet.Put( *pItem );
1018                     pTabViewShell->ApplyAttributes( &aNewSet, &rOldSet, sal_True );
1019 				}
1020 			}
1021 			break;
1022 
1023 		default:
1024 			DBG_ERROR("falscher Slot bei ExecuteEdit");
1025 			break;
1026 	}
1027 }
1028 
1029 
1030 //------------------------------------------------------------------
1031 
1032 #define APPLY_HOR_JUSTIFY(j) \
1033 	{																		\
1034 		if ( !pHorJustify || (eHorJustify != (j) ) )                        \
1035 			pTabViewShell->ApplyAttr( SvxHorJustifyItem( (j) ) );                          \
1036 		else                                                                \
1037 			pTabViewShell->ApplyAttr( SvxHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD ) );     \
1038 	}
1039 
1040 #define APPLY_VER_JUSTIFY(j) \
1041 	{																		\
1042 		if ( !pVerJustify || (eVerJustify != (j) ) )                        \
1043 			pTabViewShell->ApplyAttr( SvxVerJustifyItem( (j) ) );                          \
1044 		else                                                                \
1045 			pTabViewShell->ApplyAttr( SvxVerJustifyItem( SVX_VER_JUSTIFY_STANDARD ) );     \
1046 	}
1047 
1048 void ScFormatShell::ExecuteAlignment( SfxRequest& rReq )
1049 {
1050 	ScTabViewShell*	pTabViewShell  		= GetViewData()->GetViewShell();
1051 	SfxBindings&			rBindings	= pViewData->GetBindings();
1052 	const SfxItemSet*       pSet		= rReq.GetArgs();
1053 	sal_uInt16					nSlot		= rReq.GetSlot();
1054 
1055 	pTabViewShell->HideListBox();	// Autofilter-DropDown-Listbox
1056 
1057     switch( nSlot )
1058     {
1059         // pseudo slots for Format menu
1060         case SID_ALIGN_ANY_HDEFAULT:
1061         case SID_ALIGN_ANY_LEFT:
1062         case SID_ALIGN_ANY_HCENTER:
1063         case SID_ALIGN_ANY_RIGHT:
1064         case SID_ALIGN_ANY_JUSTIFIED:
1065             pTabViewShell->ApplyAttr( SvxHorJustifyItem( lclConvertSlotToHAlign( nSlot ), ATTR_HOR_JUSTIFY ) );
1066         break;
1067         case SID_ALIGN_ANY_VDEFAULT:
1068         case SID_ALIGN_ANY_TOP:
1069         case SID_ALIGN_ANY_VCENTER:
1070         case SID_ALIGN_ANY_BOTTOM:
1071             pTabViewShell->ApplyAttr( SvxVerJustifyItem( lclConvertSlotToVAlign( nSlot ), ATTR_VER_JUSTIFY ) );
1072         break;
1073 
1074         default:
1075             if( pSet )
1076             {
1077                 const SfxPoolItem* pItem = NULL;
1078                 if( pSet->GetItemState(GetPool().GetWhich(nSlot), sal_True, &pItem  ) == SFX_ITEM_SET )
1079                 {
1080 
1081                     switch ( nSlot )
1082                     {
1083                         case SID_ATTR_ALIGN_HOR_JUSTIFY:
1084                         case SID_ATTR_ALIGN_VER_JUSTIFY:
1085                         case SID_ATTR_ALIGN_INDENT:
1086                         case SID_ATTR_ALIGN_HYPHENATION:
1087                         case SID_ATTR_ALIGN_DEGREES:
1088                         case SID_ATTR_ALIGN_LOCKPOS:
1089                         case SID_ATTR_ALIGN_MARGIN:
1090                         case SID_ATTR_ALIGN_STACKED:
1091                             pTabViewShell->ApplyAttr( *pItem );
1092                         break;
1093 
1094                         case SID_H_ALIGNCELL:
1095                         {
1096                             SvxCellHorJustify eJust = (SvxCellHorJustify)((const SvxHorJustifyItem*)pItem)->GetValue();
1097                             // #i78476# update alignment of text in cell edit mode
1098                             pTabViewShell->UpdateInputHandlerCellAdjust( eJust );
1099                             pTabViewShell->ApplyAttr( SvxHorJustifyItem( eJust, ATTR_HOR_JUSTIFY ) );
1100                         }
1101                         break;
1102                         case SID_V_ALIGNCELL:
1103                             pTabViewShell->ApplyAttr( SvxVerJustifyItem( (SvxCellVerJustify)((const SvxVerJustifyItem*)pItem)->GetValue(), ATTR_VER_JUSTIFY ) );
1104                         break;
1105                         default:
1106                             DBG_ERROR( "ExecuteAlignment: invalid slot" );
1107                             return;
1108                     }
1109                 }
1110             }
1111     }
1112 
1113     rBindings.Invalidate( SID_ALIGNLEFT );
1114     rBindings.Invalidate( SID_ALIGNRIGHT );
1115     rBindings.Invalidate( SID_ALIGNCENTERHOR );
1116     rBindings.Invalidate( SID_ALIGNBLOCK );
1117     rBindings.Invalidate( SID_ALIGNTOP );
1118     rBindings.Invalidate( SID_ALIGNBOTTOM );
1119     rBindings.Invalidate( SID_ALIGNCENTERVER );
1120     rBindings.Invalidate( SID_V_ALIGNCELL );
1121     rBindings.Invalidate( SID_H_ALIGNCELL );
1122     // pseudo slots for Format menu
1123     rBindings.Invalidate( SID_ALIGN_ANY_HDEFAULT );
1124     rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
1125     rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
1126     rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
1127     rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
1128     rBindings.Invalidate( SID_ALIGN_ANY_VDEFAULT );
1129     rBindings.Invalidate( SID_ALIGN_ANY_TOP );
1130     rBindings.Invalidate( SID_ALIGN_ANY_VCENTER );
1131     rBindings.Invalidate( SID_ALIGN_ANY_BOTTOM );
1132     rBindings.Update();
1133 
1134     if( ! rReq.IsAPI() )
1135         rReq.Done();
1136 }
1137 
1138 void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
1139 {
1140 	ScTabViewShell*	pTabViewShell  		= GetViewData()->GetViewShell();
1141 	SfxBindings&			rBindings	= pViewData->GetBindings();
1142 	const ScPatternAttr*    pAttrs		= pTabViewShell->GetSelectionPattern();
1143 	const SfxItemSet*       pSet		= rReq.GetArgs();
1144 	sal_uInt16					nSlot		= rReq.GetSlot();
1145 	SfxAllItemSet*			pNewSet = 0;
1146 
1147 	pTabViewShell->HideListBox();					// Autofilter-DropDown-Listbox
1148 
1149 	if (  (nSlot == SID_ATTR_CHAR_WEIGHT)
1150 		||(nSlot == SID_ATTR_CHAR_POSTURE)
1151 		||(nSlot == SID_ATTR_CHAR_UNDERLINE)
1152 		||(nSlot == SID_ULINE_VAL_NONE)
1153 		||(nSlot == SID_ULINE_VAL_SINGLE)
1154 		||(nSlot == SID_ULINE_VAL_DOUBLE)
1155 		||(nSlot == SID_ULINE_VAL_DOTTED) )
1156 	{
1157 		pNewSet = new SfxAllItemSet( GetPool() );
1158 
1159 		switch ( nSlot )
1160 		{
1161 			case SID_ATTR_CHAR_WEIGHT:
1162 			{
1163 				// #i78017 establish the same behaviour as in Writer
1164 				sal_uInt8 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
1165 
1166 				SfxItemPool& rPool = GetPool();
1167 				SvxScriptSetItem aSetItem( nSlot, rPool );
1168 				if ( pSet )
1169 					aSetItem.PutItemForScriptType( nScript, pSet->Get( ATTR_FONT_WEIGHT ) );
1170 				else
1171 				{
1172 					//	toggle manually
1173 
1174 					FontWeight eWeight = WEIGHT_BOLD;
1175 					SvxScriptSetItem aOldSetItem( nSlot, rPool );
1176 					aOldSetItem.GetItemSet().Put( pAttrs->GetItemSet(), sal_False );
1177 					const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
1178 					if ( pCore && ((const SvxWeightItem*)pCore)->GetWeight() == WEIGHT_BOLD )
1179 						eWeight = WEIGHT_NORMAL;
1180 
1181                     aSetItem.PutItemForScriptType( nScript, SvxWeightItem( eWeight, ATTR_FONT_WEIGHT ) );
1182 				}
1183 				pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1184 				pNewSet->Put( aSetItem.GetItemSet(), sal_False );
1185 			}
1186 			break;
1187 
1188 			case SID_ATTR_CHAR_POSTURE:
1189 			{
1190 				// #i78017 establish the same behaviour as in Writer
1191 				sal_uInt8 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
1192 
1193 				SfxItemPool& rPool = GetPool();
1194 				SvxScriptSetItem aSetItem( nSlot, rPool );
1195 				if ( pSet )
1196 					aSetItem.PutItemForScriptType( nScript, pSet->Get( ATTR_FONT_POSTURE ) );
1197 				else
1198 				{
1199 					//	toggle manually
1200 
1201 					FontItalic eItalic = ITALIC_NORMAL;
1202 					SvxScriptSetItem aOldSetItem( nSlot, rPool );
1203 					aOldSetItem.GetItemSet().Put( pAttrs->GetItemSet(), sal_False );
1204 					const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
1205 					if ( pCore && ((const SvxPostureItem*)pCore)->GetPosture() == ITALIC_NORMAL )
1206 						eItalic = ITALIC_NONE;
1207 
1208                     aSetItem.PutItemForScriptType( nScript, SvxPostureItem( eItalic, ATTR_FONT_POSTURE ) );
1209 				}
1210 				pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1211 				pNewSet->Put( aSetItem.GetItemSet(), sal_False );
1212 			}
1213 			break;
1214 
1215 			case SID_ATTR_CHAR_UNDERLINE:
1216 				{
1217 					FontUnderline       eUnderline;
1218 
1219 					if( pSet )
1220 					{
1221                         const SfxPoolItem& rUnderline = pSet->Get( ATTR_FONT_UNDERLINE );
1222 
1223 						if( rUnderline.ISA(SvxUnderlineItem) )
1224 						{
1225 							pTabViewShell->ApplyAttr( rUnderline );
1226 							pNewSet->Put( rUnderline,rUnderline.Which() );
1227 						}
1228                         else if ( rUnderline.ISA(SvxTextLineItem) )
1229                         {
1230                             // #i106580# also allow SvxTextLineItem (base class of SvxUnderlineItem)
1231                             const SvxTextLineItem& rTextLineItem = static_cast<const SvxTextLineItem&>(rUnderline);
1232                             SvxUnderlineItem aNewItem( rTextLineItem.GetLineStyle(), rTextLineItem.Which() );
1233                             aNewItem.SetColor( rTextLineItem.GetColor() );
1234                             pTabViewShell->ApplyAttr( aNewItem );
1235                             pNewSet->Put( aNewItem, aNewItem.Which() );
1236                         }
1237 					}
1238 					else
1239 					{
1240 						SvxUnderlineItem aUnderline( (const SvxUnderlineItem&)
1241 														pAttrs->GetItem(
1242 															ATTR_FONT_UNDERLINE ) );
1243 						eUnderline = (UNDERLINE_NONE != aUnderline.GetLineStyle())
1244 									? UNDERLINE_NONE
1245 									: UNDERLINE_SINGLE;
1246 						aUnderline.SetLineStyle( eUnderline );
1247 						pTabViewShell->ApplyAttr( aUnderline );
1248 						pNewSet->Put( aUnderline,aUnderline.Which() );
1249 					}
1250 				}
1251 				break;
1252 
1253 			case SID_ULINE_VAL_NONE:
1254 				pTabViewShell->ApplyAttr( SvxUnderlineItem( UNDERLINE_NONE, ATTR_FONT_UNDERLINE ) );
1255 				break;
1256 			case SID_ULINE_VAL_SINGLE:		// Toggles
1257 			case SID_ULINE_VAL_DOUBLE:
1258 			case SID_ULINE_VAL_DOTTED:
1259 				{
1260 					FontUnderline eOld = ((const SvxUnderlineItem&)
1261 											pAttrs->GetItem(ATTR_FONT_UNDERLINE)).GetLineStyle();
1262 					FontUnderline eNew = eOld;
1263 					switch (nSlot)
1264 					{
1265 						case SID_ULINE_VAL_SINGLE:
1266 							eNew = ( eOld == UNDERLINE_SINGLE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
1267 							break;
1268 						case SID_ULINE_VAL_DOUBLE:
1269 							eNew = ( eOld == UNDERLINE_DOUBLE ) ? UNDERLINE_NONE : UNDERLINE_DOUBLE;
1270 							break;
1271 						case SID_ULINE_VAL_DOTTED:
1272 							eNew = ( eOld == UNDERLINE_DOTTED ) ? UNDERLINE_NONE : UNDERLINE_DOTTED;
1273 							break;
1274 					}
1275 					pTabViewShell->ApplyAttr( SvxUnderlineItem( eNew, ATTR_FONT_UNDERLINE ) );
1276 				}
1277 				break;
1278 
1279 			default:
1280 				break;
1281 		}
1282 		rBindings.Invalidate( nSlot );
1283 	}
1284 	else
1285 	{
1286 		/*
1287 		 * "Selbstgemachte" RadioButton-Funktionalitaet
1288 		 * Beim Toggle gibt es den Standard-State, d.h. kein
1289 		 * Button ist gedrueckt
1290 		 */
1291 
1292 		const SfxItemSet&		 rAttrSet	= pTabViewShell->GetSelectionPattern()->GetItemSet();
1293 		const SfxPoolItem*       pItem       = NULL;
1294 		const SvxHorJustifyItem* pHorJustify = NULL;
1295 		const SvxVerJustifyItem* pVerJustify = NULL;
1296 		SvxCellHorJustify        eHorJustify = SVX_HOR_JUSTIFY_STANDARD;
1297 		SvxCellVerJustify        eVerJustify = SVX_VER_JUSTIFY_STANDARD;
1298 
1299 		if (rAttrSet.GetItemState(ATTR_HOR_JUSTIFY, sal_True,&pItem ) == SFX_ITEM_SET)
1300 		{
1301 			pHorJustify = (const SvxHorJustifyItem*)pItem;
1302 			eHorJustify = SvxCellHorJustify( pHorJustify->GetValue() );
1303 		}
1304 		if (rAttrSet.GetItemState(ATTR_VER_JUSTIFY, sal_True,&pItem ) == SFX_ITEM_SET)
1305 		{
1306 			pVerJustify = (const SvxVerJustifyItem*)pItem;
1307 			eVerJustify = SvxCellVerJustify( pVerJustify->GetValue() );
1308 		}
1309 
1310 		switch ( nSlot )
1311 		{
1312 			case SID_ALIGNLEFT:
1313 				rReq.SetSlot( SID_H_ALIGNCELL );
1314 				rReq.AppendItem( SvxHorJustifyItem(
1315 					!pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_LEFT) ?
1316 					SVX_HOR_JUSTIFY_LEFT : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1317 				ExecuteSlot( rReq, GetInterface() );
1318 				return;
1319 //				APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_LEFT );
1320                 //break;
1321 
1322 			case SID_ALIGNRIGHT:
1323 				rReq.SetSlot( SID_H_ALIGNCELL );
1324 				rReq.AppendItem( SvxHorJustifyItem(
1325 					!pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_RIGHT) ?
1326 					SVX_HOR_JUSTIFY_RIGHT : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1327 				ExecuteSlot( rReq, GetInterface() );
1328 				return;
1329 //				APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_RIGHT );
1330                 //break;
1331 
1332 			case SID_ALIGNCENTERHOR:
1333 				rReq.SetSlot( SID_H_ALIGNCELL );
1334 				rReq.AppendItem( SvxHorJustifyItem(
1335 					!pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_CENTER) ?
1336 					SVX_HOR_JUSTIFY_CENTER : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1337 				ExecuteSlot( rReq, GetInterface() );
1338 				return;
1339 //				APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_CENTER );
1340                 //break;
1341 
1342 			case SID_ALIGNBLOCK:
1343 				rReq.SetSlot( SID_H_ALIGNCELL );
1344 				rReq.AppendItem( SvxHorJustifyItem(
1345 					!pHorJustify || (eHorJustify != SVX_HOR_JUSTIFY_BLOCK) ?
1346 					SVX_HOR_JUSTIFY_BLOCK : SVX_HOR_JUSTIFY_STANDARD, SID_H_ALIGNCELL ) );
1347 				ExecuteSlot( rReq, GetInterface() );
1348 				return;
1349 //				APPLY_HOR_JUSTIFY( SVX_HOR_JUSTIFY_BLOCK );
1350                 //break;
1351 
1352 			case SID_ALIGNTOP:
1353 				rReq.SetSlot( SID_V_ALIGNCELL );
1354 				rReq.AppendItem( SvxVerJustifyItem(
1355 					!pVerJustify || (eVerJustify != SVX_VER_JUSTIFY_TOP) ?
1356 					SVX_VER_JUSTIFY_TOP : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
1357 				ExecuteSlot( rReq, GetInterface() );
1358 				return;
1359 //				APPLY_VER_JUSTIFY( SVX_VER_JUSTIFY_TOP );
1360                 //break;
1361 
1362 			case SID_ALIGNBOTTOM:
1363 				rReq.SetSlot( SID_V_ALIGNCELL );
1364 				rReq.AppendItem( SvxVerJustifyItem(
1365 					!pVerJustify || (eVerJustify != SVX_VER_JUSTIFY_BOTTOM) ?
1366 					SVX_VER_JUSTIFY_BOTTOM : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
1367 				ExecuteSlot( rReq, GetInterface() );
1368 				return;
1369 //				APPLY_VER_JUSTIFY( SVX_VER_JUSTIFY_BOTTOM );
1370                 //break;
1371 
1372 			case SID_ALIGNCENTERVER:
1373 				rReq.SetSlot( SID_V_ALIGNCELL );
1374 				rReq.AppendItem( SvxVerJustifyItem(
1375 					!pVerJustify || (eVerJustify != SVX_VER_JUSTIFY_CENTER) ?
1376 					SVX_VER_JUSTIFY_CENTER : SVX_VER_JUSTIFY_STANDARD, SID_V_ALIGNCELL ) );
1377 				ExecuteSlot( rReq, GetInterface() );
1378 				return;
1379 //				APPLY_VER_JUSTIFY( SVX_VER_JUSTIFY_CENTER );
1380                 //break;
1381 
1382 			default:
1383 			break;
1384 		}
1385 
1386 	}
1387 
1388 	rBindings.Update();
1389 //	rReq.Done();
1390 
1391 	if( pNewSet )
1392 	{
1393 		rReq.Done( *pNewSet );
1394 		delete pNewSet;
1395 	}
1396 	else
1397 	{
1398 		rReq.Done();
1399 	}
1400 
1401 }
1402 
1403 #undef APPLY_HOR_JUSTIFY
1404 #undef APPLY_VER_JUSTIFY
1405 
1406 //------------------------------------------------------------------
1407 
1408 void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
1409 {
1410 	ScTabViewShell*	pTabViewShell  		= GetViewData()->GetViewShell();
1411 	SfxBindings&		rBindings = pViewData->GetBindings();
1412 	const SfxItemSet*	pNewAttrs = rReq.GetArgs();
1413 
1414 	pTabViewShell->HideListBox();					// Autofilter-DropDown-Listbox
1415 
1416 	if ( !pNewAttrs )
1417 	{
1418 		sal_uInt16 nSlot = rReq.GetSlot();
1419 
1420 		switch ( nSlot )
1421 		{
1422 			case SID_ATTR_CHAR_FONT:
1423 			case SID_ATTR_CHAR_FONTHEIGHT:
1424 				pTabViewShell->ExecuteCellFormatDlg( rReq, TP_FONT );	    // wenn ToolBar vertikal
1425 				break;
1426 
1427 			case SID_ATTR_ALIGN_LINEBREAK:					// ohne Parameter als Toggle
1428 				{
1429 					const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
1430 					sal_Bool bOld = ((const SfxBoolItem&)pAttrs->GetItem(ATTR_LINEBREAK)).GetValue();
1431 					SfxBoolItem aBreakItem( ATTR_LINEBREAK, !bOld );
1432 					pTabViewShell->ApplyAttr( aBreakItem );
1433 
1434 					SfxAllItemSet aNewSet( GetPool() );
1435 					aNewSet.Put( aBreakItem,aBreakItem.Which() );
1436 					rReq.Done( aNewSet );
1437 
1438 					rBindings.Invalidate( nSlot );
1439 				}
1440 				break;
1441 
1442 			case SID_BACKGROUND_COLOR:
1443 				{
1444 					//	SID_BACKGROUND_COLOR without arguments -> set transparent background
1445 
1446 					SvxBrushItem        aBrushItem( (const SvxBrushItem&)
1447 											pTabViewShell->GetSelectionPattern()->
1448 												GetItem( ATTR_BACKGROUND ) );
1449 
1450 					aBrushItem.SetColor( COL_TRANSPARENT );
1451 
1452 					pTabViewShell->ApplyAttr( aBrushItem );
1453 				}
1454 				break;
1455 		}
1456 	}
1457 	else
1458 	{
1459 		sal_uInt16 nSlot = rReq.GetSlot();
1460 
1461 		switch ( nSlot )
1462 		{
1463             case SID_ATTR_CHAR_OVERLINE:
1464             case SID_ATTR_CHAR_STRIKEOUT:
1465 			case SID_ATTR_ALIGN_LINEBREAK:
1466 			case SID_ATTR_CHAR_COLOR:
1467             case SID_ATTR_CHAR_CONTOUR:
1468             case SID_ATTR_CHAR_SHADOWED:
1469             case SID_ATTR_CHAR_RELIEF:
1470             case SID_SCATTR_PROTECTION :
1471 				pTabViewShell->ApplyAttr( pNewAttrs->Get( pNewAttrs->GetPool()->GetWhich( nSlot ) ) );
1472 				rBindings.Invalidate( nSlot );
1473 				rBindings.Update( nSlot );
1474 				break;
1475 
1476 			case SID_ATTR_CHAR_FONT:
1477 			case SID_ATTR_CHAR_FONTHEIGHT:
1478 				{
1479 					// #i78017 establish the same behaviour as in Writer
1480 					sal_uInt8 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
1481 					if (nSlot == SID_ATTR_CHAR_FONT)
1482 						nScript = pTabViewShell->GetSelectionScriptType();
1483 
1484 					SfxItemPool& rPool = GetPool();
1485 					SvxScriptSetItem aSetItem( nSlot, rPool );
1486 					sal_uInt16 nWhich = rPool.GetWhich( nSlot );
1487 					aSetItem.PutItemForScriptType( nScript, pNewAttrs->Get( nWhich ) );
1488 
1489 					pTabViewShell->ApplyUserItemSet( aSetItem.GetItemSet() );
1490 
1491 					rBindings.Invalidate( nSlot );
1492 					rBindings.Update( nSlot );
1493 				}
1494 				break;
1495 
1496 			case SID_FRAME_LINESTYLE:
1497 				{
1498 					// Default-Linie aktualisieren
1499 					const SvxBorderLine* pLine =
1500 							((const SvxLineItem&)
1501 								pNewAttrs->Get( SID_FRAME_LINESTYLE )).
1502 								GetLine();
1503 
1504 					if ( pLine )
1505 					{
1506 						SvxBorderLine* pDefLine = pTabViewShell->GetDefaultFrameLine();
1507 
1508 						if ( pDefLine )
1509 						{
1510 							pDefLine->SetOutWidth( pLine->GetOutWidth() );
1511 							pDefLine->SetInWidth ( pLine->GetInWidth() );
1512 							pDefLine->SetDistance( pLine->GetDistance() );
1513 							pTabViewShell->SetSelectionFrameLines( pDefLine, sal_False );
1514 						}
1515 						else
1516 						{
1517 							pTabViewShell->SetDefaultFrameLine( pLine );
1518 							pTabViewShell->GetDefaultFrameLine()->SetColor( COL_BLACK );
1519 							pTabViewShell->SetSelectionFrameLines( pLine, sal_False );
1520 						}
1521 					}
1522 					else
1523 					{
1524 						Color           aColorBlack( COL_BLACK );
1525 						SvxBorderLine   aDefLine( &aColorBlack, 20, 0, 0 );
1526 						pTabViewShell->SetDefaultFrameLine( &aDefLine );
1527 						pTabViewShell->SetSelectionFrameLines( NULL, sal_False );
1528 					}
1529 				}
1530 				break;
1531 
1532 			case SID_FRAME_LINECOLOR:
1533 				{
1534 					SvxBorderLine*  pDefLine = pTabViewShell->GetDefaultFrameLine();
1535 					const Color&    rColor = ((const SvxColorItem&)
1536 										pNewAttrs->Get( SID_FRAME_LINECOLOR )).
1537 											GetValue();
1538 
1539 					// Default-Linie aktualisieren
1540 					if ( pDefLine )
1541 					{
1542 						pDefLine->SetColor( rColor );
1543 						pTabViewShell->SetSelectionFrameLines( pDefLine, sal_True );
1544 					}
1545 					else
1546 					{
1547 						SvxBorderLine   aDefLine( &rColor, 20, 0, 0 );
1548 						pTabViewShell->SetDefaultFrameLine( &aDefLine );
1549 						pTabViewShell->SetSelectionFrameLines( &aDefLine, sal_False );
1550 					}
1551 				}
1552 				break;
1553 
1554 			case SID_ATTR_BORDER_OUTER:
1555 			case SID_ATTR_BORDER:
1556 				{
1557 					SvxBorderLine*          pDefLine = pTabViewShell->GetDefaultFrameLine();
1558 					const ScPatternAttr*    pOldAttrs = pTabViewShell->GetSelectionPattern();
1559 					ScDocument*             pDoc = GetViewData()->GetDocument();
1560 					SfxItemSet*             pOldSet =
1561 												new SfxItemSet(
1562 														*(pDoc->GetPool()),
1563 														ATTR_PATTERN_START,
1564 														ATTR_PATTERN_END );
1565 					SfxItemSet*             pNewSet =
1566 												new SfxItemSet(
1567 														*(pDoc->GetPool()),
1568 														ATTR_PATTERN_START,
1569 														ATTR_PATTERN_END );
1570 					const SfxPoolItem&      rBorderAttr =
1571 												pOldAttrs->GetItemSet().
1572 													Get( ATTR_BORDER );
1573 
1574 					// Border-Items vom Controller auswerten:
1575 					const SfxPoolItem* pItem = 0;
1576 
1577 					if ( pNewAttrs->GetItemState( ATTR_BORDER, sal_True, &pItem )
1578 						 == SFX_ITEM_SET )
1579 					{
1580 						//	#100959# The SvxFrameToolBoxControl toolbox controller uses a default
1581 						//	SvxBorderLine (all widths 0) to mark the lines that should be set.
1582 						//	Macro recording uses a SvxBoxItem with the real values (OutWidth > 0)
1583 						//	or NULL pointers for no lines.
1584 						//	-> Substitute existing lines with pDefLine only if widths are 0.
1585 						SvxBoxItem aBoxItem ( *(const SvxBoxItem*)pItem );
1586 						if ( aBoxItem.GetTop() && aBoxItem.GetTop()->GetOutWidth() == 0 )
1587 							aBoxItem.SetLine( pDefLine, BOX_LINE_TOP );
1588 						if ( aBoxItem.GetBottom() && aBoxItem.GetBottom()->GetOutWidth() == 0 )
1589 							aBoxItem.SetLine( pDefLine, BOX_LINE_BOTTOM );
1590 						if ( aBoxItem.GetLeft() && aBoxItem.GetLeft()->GetOutWidth() == 0 )
1591 							aBoxItem.SetLine( pDefLine, BOX_LINE_LEFT );
1592 						if ( aBoxItem.GetRight() && aBoxItem.GetRight()->GetOutWidth() == 0 )
1593 							aBoxItem.SetLine( pDefLine, BOX_LINE_RIGHT );
1594 						pNewSet->Put( aBoxItem );
1595                         rReq.AppendItem( aBoxItem );
1596 					}
1597 
1598 					if ( pNewAttrs->GetItemState( ATTR_BORDER_INNER, sal_True, &pItem )
1599 						 == SFX_ITEM_SET )
1600 					{
1601 						SvxBoxInfoItem aBoxInfoItem( *(const SvxBoxInfoItem*)pItem );
1602 						if ( aBoxInfoItem.GetHori() && aBoxInfoItem.GetHori()->GetOutWidth() == 0 )
1603 							aBoxInfoItem.SetLine( pDefLine, BOXINFO_LINE_HORI );
1604 						if ( aBoxInfoItem.GetVert() && aBoxInfoItem.GetVert()->GetOutWidth() == 0 )
1605 							aBoxInfoItem.SetLine( pDefLine, BOXINFO_LINE_VERT );
1606 						pNewSet->Put( aBoxInfoItem );
1607                         rReq.AppendItem( aBoxInfoItem );
1608 					}
1609 					else
1610 					{
1611 						SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
1612 						aBoxInfoItem.SetLine( NULL, BOXINFO_LINE_HORI );
1613 						aBoxInfoItem.SetLine( NULL, BOXINFO_LINE_VERT );
1614 						pNewSet->Put( aBoxInfoItem );
1615 					}
1616 
1617 					pOldSet->Put( rBorderAttr );
1618 					pTabViewShell->ApplyAttributes( pNewSet, pOldSet );
1619 
1620 					delete pOldSet;
1621 					delete pNewSet;
1622 				}
1623 				break;
1624 
1625 			case SID_ATTR_BORDER_DIAG_TLBR:
1626 			case SID_ATTR_BORDER_DIAG_BLTR:
1627 				{
1628 					ScDocument* pDoc = GetViewData()->GetDocument();
1629 					const ScPatternAttr* pOldAttrs = pTabViewShell->GetSelectionPattern();
1630 					SfxItemSet* pOldSet = new SfxItemSet(pOldAttrs->GetItemSet());
1631 					SfxItemSet* pNewSet = new SfxItemSet(pOldAttrs->GetItemSet());
1632 					const SfxPoolItem* pItem = 0;
1633 
1634                     if(SID_ATTR_BORDER_DIAG_TLBR == nSlot)
1635 					{
1636 						if(SFX_ITEM_SET == pNewAttrs->GetItemState(ATTR_BORDER_TLBR, true, &pItem))
1637 						{
1638 							SvxLineItem aItem(ATTR_BORDER_TLBR);
1639 							aItem.SetLine(((const SvxLineItem&)pNewAttrs->Get(ATTR_BORDER_TLBR)).GetLine());
1640 							pNewSet->Put(aItem);
1641 							rReq.AppendItem(aItem);
1642 							pTabViewShell->ApplyAttributes(pNewSet, pOldSet);
1643 						}
1644 					}
1645 					else // if( nSlot == SID_ATTR_BORDER_DIAG_BLTR )
1646 					{
1647 						if(SFX_ITEM_SET == pNewAttrs->GetItemState(ATTR_BORDER_BLTR, true, &pItem ))
1648 						{
1649 							SvxLineItem aItem(ATTR_BORDER_BLTR);
1650 							aItem.SetLine(((const SvxLineItem&)pNewAttrs->Get(ATTR_BORDER_BLTR)).GetLine());
1651 							pNewSet->Put(aItem);
1652 							rReq.AppendItem(aItem);
1653 							pTabViewShell->ApplyAttributes(pNewSet, pOldSet);
1654 						}
1655 					}
1656 
1657                     delete pOldSet;
1658 					delete pNewSet;
1659 					rBindings.Invalidate(nSlot);
1660 				}
1661 				break;
1662 
1663 			// ATTR_BACKGROUND (=SID_ATTR_BRUSH) muss ueber zwei IDs
1664 			// gesetzt werden:
1665 			case SID_BACKGROUND_COLOR:
1666 				{
1667 					const SvxColorItem  rNewColorItem = (const SvxColorItem&)
1668 											pNewAttrs->Get( SID_BACKGROUND_COLOR );
1669 
1670 					SvxBrushItem        aBrushItem( (const SvxBrushItem&)
1671 											pTabViewShell->GetSelectionPattern()->
1672 												GetItem( ATTR_BACKGROUND ) );
1673 
1674 					aBrushItem.SetColor( rNewColorItem.GetValue() );
1675 
1676 					pTabViewShell->ApplyAttr( aBrushItem );
1677 				}
1678 				break;
1679 
1680 				case SID_ATTR_BRUSH:
1681 				{
1682 					SvxBrushItem        aBrushItem( (const SvxBrushItem&)
1683 											pTabViewShell->GetSelectionPattern()->
1684 												GetItem( ATTR_BACKGROUND ) );
1685 					const SvxBrushItem& rNewBrushItem = (const SvxBrushItem&)
1686 											pNewAttrs->Get( GetPool().GetWhich(nSlot) );
1687 					aBrushItem.SetColor(rNewBrushItem.GetColor());
1688 					pTabViewShell->ApplyAttr( aBrushItem );
1689 				}
1690 				break;
1691 
1692 			case SID_ATTR_BORDER_SHADOW:
1693 				{
1694 					const SvxShadowItem& rNewShadowItem = (const SvxShadowItem&)
1695 											pNewAttrs->Get( ATTR_SHADOW );
1696 					pTabViewShell->ApplyAttr( rNewShadowItem );
1697 				}
1698 				break;
1699 
1700 			default:
1701 			break;
1702 		}
1703 
1704 		if( ! rReq.IsAPI() )
1705 			if( ! rReq.IsDone() )
1706 				rReq.Done();
1707 	}
1708 }
1709 
1710 void ScFormatShell::GetAttrState( SfxItemSet& rSet )
1711 {
1712 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
1713 	const SfxItemSet&	 rAttrSet	= pTabViewShell->GetSelectionPattern()->GetItemSet();
1714 	const SvxBorderLine* pLine      = pTabViewShell->GetDefaultFrameLine();
1715 	const SvxBrushItem&  rBrushItem = (const SvxBrushItem&)rAttrSet.Get( ATTR_BACKGROUND );
1716 	SfxWhichIter aIter( rSet );
1717 	sal_uInt16 nWhich = aIter.FirstWhich();
1718 
1719 	rSet.Put( rAttrSet, sal_False );
1720 
1721 	//	choose font info according to selection script type
1722 	sal_uInt8 nScript = 0;		// GetSelectionScriptType never returns 0
1723 	if ( rSet.GetItemState( ATTR_FONT ) != SFX_ITEM_UNKNOWN )
1724 	{
1725 		if (!nScript) nScript = pTabViewShell->GetSelectionScriptType();
1726 		ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT, nScript );
1727 	}
1728 	if ( rSet.GetItemState( ATTR_FONT_HEIGHT ) != SFX_ITEM_UNKNOWN )
1729 	{
1730 		if (!nScript) nScript = pTabViewShell->GetSelectionScriptType();
1731 		ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_HEIGHT, nScript );
1732 	}
1733 
1734 	while ( nWhich )
1735 	{
1736 		switch(nWhich)
1737 		{
1738 			case SID_BACKGROUND_COLOR:
1739 			{
1740                 rSet.Put( SvxColorItem( rBrushItem.GetColor(), SID_BACKGROUND_COLOR ) );
1741 
1742                 if(SFX_ITEM_DONTCARE == rAttrSet.GetItemState(ATTR_BACKGROUND))
1743                 {
1744                     rSet.InvalidateItem(SID_BACKGROUND_COLOR);
1745                 }
1746 			}
1747 			break;
1748     		case SID_FRAME_LINESTYLE:
1749 			case SID_FRAME_LINECOLOR:
1750 			{
1751                 // handled together because both need the cell border information for decisions
1752                 // rSet.Put( SvxColorItem( pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLOR ) );
1753 				Color aCol = 0;
1754 				sal_uInt16 nOut = 0, nIn = 0, nDis = 0;
1755 				SvxBorderLine aLine(0,0,0,0);
1756 				bool bCol = 0;
1757 				bool bColDisable = 0, bStyleDisable = 0;
1758                 SvxBoxItem aBoxItem(ATTR_BORDER);
1759                 SvxBoxInfoItem aInfoItem(ATTR_BORDER_INNER);
1760 
1761                 pTabViewShell->GetSelectionFrame(aBoxItem, aInfoItem);
1762 
1763 				if( aBoxItem.GetTop() )
1764 				{
1765 					bCol = 1;
1766 					aCol = aBoxItem.GetTop()->GetColor() ;
1767 					aLine.SetColor(aCol);
1768 					aLine.SetOutWidth( aBoxItem.GetTop()->GetOutWidth());
1769 					aLine.SetInWidth( aBoxItem.GetTop()->GetInWidth());
1770 					aLine.SetDistance( aBoxItem.GetTop()->GetDistance());
1771 				}
1772 
1773                 if( aBoxItem.GetBottom() )
1774 				{
1775 					if(bCol == 0)
1776 					{
1777 						bCol = 1;
1778 						aCol = aBoxItem.GetBottom()->GetColor() ;
1779 						aLine.SetColor(aCol);
1780 						aLine.SetOutWidth( aBoxItem.GetBottom()->GetOutWidth());
1781 						aLine.SetInWidth( aBoxItem.GetBottom()->GetInWidth());
1782 						aLine.SetDistance( aBoxItem.GetBottom()->GetDistance());
1783 					}
1784 					else
1785 					{
1786 						if(aCol != aBoxItem.GetBottom()->GetColor() )
1787 							bColDisable = 1;
1788 						if(!( aLine == *(aBoxItem.GetBottom())) )
1789 							bStyleDisable = 1;
1790 					}
1791 				}
1792 
1793                 if( aBoxItem.GetLeft() )
1794 				{
1795 					if(bCol == 0)
1796 					{
1797 						bCol = 1;
1798 						aCol = aBoxItem.GetLeft()->GetColor() ;
1799 						aLine.SetColor(aCol);
1800 						aLine.SetOutWidth( aBoxItem.GetLeft()->GetOutWidth());
1801 						aLine.SetInWidth( aBoxItem.GetLeft()->GetInWidth());
1802 						aLine.SetDistance( aBoxItem.GetLeft()->GetDistance());
1803 					}
1804 					else
1805 					{
1806 						if(aCol != aBoxItem.GetLeft()->GetColor() )
1807 							bColDisable = 1;
1808 						if(!( aLine == *(aBoxItem.GetLeft())) )
1809 							bStyleDisable = 1;
1810 					}
1811 				}
1812 
1813                 if( aBoxItem.GetRight() )
1814 				{
1815 					if(bCol == 0)
1816 					{
1817 						bCol = 1;
1818 						aCol = aBoxItem.GetRight()->GetColor() ;
1819 						aLine.SetColor(aCol);
1820 						aLine.SetOutWidth( aBoxItem.GetRight()->GetOutWidth());
1821 						aLine.SetInWidth( aBoxItem.GetRight()->GetInWidth());
1822 						aLine.SetDistance( aBoxItem.GetRight()->GetDistance());
1823 					}
1824 					else
1825 					{
1826 						if(aCol != aBoxItem.GetRight()->GetColor() )
1827 							bColDisable = 1;
1828 						if(!( aLine == *(aBoxItem.GetRight())) )
1829 							bStyleDisable = 1;
1830 					}
1831 				}
1832 
1833                 if( aInfoItem.GetVert())
1834 				{
1835 					if(bCol == 0)
1836 					{
1837 						bCol = 1;
1838 						aCol = aInfoItem.GetVert()->GetColor() ;
1839 						aLine.SetColor(aCol);
1840 						aLine.SetOutWidth( aInfoItem.GetVert()->GetOutWidth());
1841 						aLine.SetInWidth( aInfoItem.GetVert()->GetInWidth());
1842 						aLine.SetDistance( aInfoItem.GetVert()->GetDistance());
1843 					}
1844 					else
1845 					{
1846 						if(aCol != aInfoItem.GetVert()->GetColor() )
1847 							bColDisable = 1;
1848 						if(!( aLine == *(aInfoItem.GetVert())) )
1849 							bStyleDisable = 1;
1850 					}
1851 				}
1852 
1853                 if( aInfoItem.GetHori())
1854 				{
1855 					if(bCol == 0)
1856 					{
1857 						bCol = 1;
1858 						aCol = aInfoItem.GetHori()->GetColor() ;
1859 						aLine.SetColor(aCol);
1860 						aLine.SetOutWidth( aInfoItem.GetHori()->GetOutWidth());
1861 						aLine.SetInWidth( aInfoItem.GetHori()->GetInWidth());
1862 						aLine.SetDistance( aInfoItem.GetHori()->GetDistance());
1863 					}
1864 					else
1865 					{
1866 						if(aCol != aInfoItem.GetHori()->GetColor() )
1867 							bColDisable = 1;
1868 						if(!( aLine == *(aInfoItem.GetHori())) )
1869 							bStyleDisable = 1;
1870 					}
1871 				}
1872 
1873 				if( !aInfoItem.IsValid( VALID_VERT )
1874 					|| !aInfoItem.IsValid( VALID_HORI )
1875 					|| !aInfoItem.IsValid( VALID_LEFT )
1876 					|| !aInfoItem.IsValid( VALID_RIGHT )
1877 					|| !aInfoItem.IsValid( VALID_TOP )
1878 					|| !aInfoItem.IsValid( VALID_BOTTOM ) )
1879 				{
1880 					bColDisable = 1;
1881 					bStyleDisable = 1;
1882 				}
1883 
1884 				if(SID_FRAME_LINECOLOR == nWhich)
1885 				{
1886 					if(bColDisable) // if different lines have differernt colors
1887 					{
1888 						aCol = COL_TRANSPARENT;
1889 						rSet.Put( SvxColorItem(aCol, SID_FRAME_LINECOLOR ) );
1890 						rSet.InvalidateItem(SID_FRAME_LINECOLOR);
1891 					}
1892 					else if( bCol == 0 && bColDisable == 0) // if no line available
1893 					{
1894 						aCol = COL_AUTO;
1895 						rSet.Put( SvxColorItem(aCol, SID_FRAME_LINECOLOR ) );
1896 					}
1897 					else
1898 						rSet.Put( SvxColorItem(aCol, SID_FRAME_LINECOLOR ) );
1899 				}
1900 				else // if( nWhich == SID_FRAME_LINESTYLE)
1901 				{
1902 					if(bStyleDisable) // if have several lines but don't have same style
1903 					{
1904 						aLine.SetOutWidth( 1 );
1905 						aLine.SetInWidth( 0 );
1906 						aLine.SetDistance( 0 );
1907 						SvxLineItem aItem(SID_FRAME_LINESTYLE);
1908 						aItem.SetLine(&aLine);
1909 						rSet.Put( aItem );
1910 						rSet.InvalidateItem(SID_FRAME_LINESTYLE);
1911 					}
1912 					else // all the lines have same style or no line availavle, use initial value (0,0,0,0)
1913 					{
1914 						SvxLineItem aItem(SID_FRAME_LINESTYLE);
1915 						aItem.SetLine(&aLine);
1916 						rSet.Put( aItem );
1917 					}
1918 				}
1919 			}
1920 			break;
1921 			case SID_ATTR_BRUSH:
1922 			{
1923 				rSet.Put( rBrushItem, GetPool().GetWhich(nWhich) );
1924 			}
1925 			break;
1926 /*			case SID_ATTR_ALIGN_LINEBREAK:
1927 			{
1928 				const SfxBoolItem& rBreakItem = (const SfxBoolItem&)rAttrSet.Get( ATTR_LINEBREAK );
1929 				rSet.Put( rBreakItem, GetPool().GetWhich(nWhich) );
1930 			}
1931 			break;
1932 */
1933 		}
1934 		nWhich = aIter.NextWhich();
1935 	}
1936 
1937     if(nWhich)
1938     {
1939         // stuff for sidebar panels
1940         Invalidate(SID_ATTR_ALIGN_DEGREES);
1941         Invalidate(SID_ATTR_ALIGN_STACKED);
1942     }
1943 }
1944 
1945 //------------------------------------------------------------------
1946 
1947 void ScFormatShell::GetTextAttrState( SfxItemSet& rSet )
1948 {
1949 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
1950 	const SfxItemSet& rAttrSet	= pTabViewShell->GetSelectionPattern()->GetItemSet();
1951 	rSet.Put( rAttrSet, sal_False ); // ItemStates mitkopieren
1952 
1953 	//	choose font info according to selection script type
1954 	sal_uInt8 nScript = 0;		// GetSelectionScriptType never returns 0
1955 	if ( rSet.GetItemState( ATTR_FONT_WEIGHT ) != SFX_ITEM_UNKNOWN )
1956 	{
1957 		if (!nScript) nScript = pTabViewShell->GetSelectionScriptType();
1958 		ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_WEIGHT, nScript );
1959 	}
1960 	if ( rSet.GetItemState( ATTR_FONT_POSTURE ) != SFX_ITEM_UNKNOWN )
1961 	{
1962 		if (!nScript) nScript = pTabViewShell->GetSelectionScriptType();
1963 		ScViewUtil::PutItemScript( rSet, rAttrSet, ATTR_FONT_POSTURE, nScript );
1964 	}
1965 
1966 	SfxItemState eState;
1967 //	const SfxPoolItem* pItem;
1968 
1969 	//--------------------------------------------------------------------
1970 	// eigene Kontrolle ueber RadioButton-Funktionalitaet:
1971 	//--------------------------------------------------------------------
1972 	// Unterstreichung
1973 	//------------------------
1974 
1975 	eState = rAttrSet.GetItemState( ATTR_FONT_UNDERLINE, sal_True );
1976 	if ( eState == SFX_ITEM_DONTCARE )
1977 	{
1978 		rSet.InvalidateItem( SID_ULINE_VAL_NONE );
1979 		rSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
1980 		rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
1981 		rSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
1982 	}
1983 	else
1984 	{
1985 		FontUnderline eUnderline = ((const SvxUnderlineItem&)
1986 					rAttrSet.Get(ATTR_FONT_UNDERLINE)).GetLineStyle();
1987 		sal_uInt16 nId = SID_ULINE_VAL_NONE;
1988 		switch (eUnderline)
1989 		{
1990 			case UNDERLINE_SINGLE:	nId = SID_ULINE_VAL_SINGLE;	break;
1991 			case UNDERLINE_DOUBLE:	nId = SID_ULINE_VAL_DOUBLE;	break;
1992 			case UNDERLINE_DOTTED:	nId = SID_ULINE_VAL_DOTTED;	break;
1993 			default:
1994 				break;
1995 		}
1996 		rSet.Put( SfxBoolItem( nId, sal_True ) );
1997 	}
1998 
1999 	//------------------------
2000 	// horizontale Ausrichtung
2001 	//------------------------
2002 
2003 	const SvxHorJustifyItem* pHorJustify = NULL;
2004 	const SvxVerJustifyItem* pVerJustify = NULL;
2005 	SvxCellHorJustify        eHorJustify = SVX_HOR_JUSTIFY_STANDARD;
2006 	SvxCellVerJustify        eVerJustify = SVX_VER_JUSTIFY_STANDARD;
2007 	sal_uInt16		 			 nWhich		 = 0;
2008 	sal_Bool					 bJustifyStd = sal_False;
2009 	SfxBoolItem				 aBoolItem	 ( 0, sal_True );
2010 
2011 	eState 	 = rAttrSet.GetItemState( ATTR_HOR_JUSTIFY, sal_True,
2012 										(const SfxPoolItem**)&pHorJustify );
2013 	switch ( eState )
2014 	{
2015 		case SFX_ITEM_SET:
2016 			{
2017 				eHorJustify = SvxCellHorJustify( pHorJustify->GetValue() );
2018 
2019 				switch ( SvxCellHorJustify( pHorJustify->GetValue() ) )
2020 				{
2021 					case SVX_HOR_JUSTIFY_STANDARD:
2022 						break;
2023 
2024 					case SVX_HOR_JUSTIFY_LEFT:
2025 						nWhich = SID_ALIGNLEFT;
2026 						break;
2027 
2028 					case SVX_HOR_JUSTIFY_RIGHT:
2029 						nWhich = SID_ALIGNRIGHT;
2030 						break;
2031 
2032 					case SVX_HOR_JUSTIFY_CENTER:
2033 						nWhich = SID_ALIGNCENTERHOR;
2034 						break;
2035 
2036 					case SVX_HOR_JUSTIFY_BLOCK:
2037 						nWhich = SID_ALIGNBLOCK;
2038 						break;
2039 
2040 					case SVX_HOR_JUSTIFY_REPEAT:
2041 					default:
2042 						bJustifyStd = sal_True;
2043 						break;
2044 				}
2045 			}
2046 			break;
2047 
2048 		case SFX_ITEM_DONTCARE:
2049 			rSet.InvalidateItem( SID_ALIGNLEFT );
2050 			rSet.InvalidateItem( SID_ALIGNRIGHT );
2051 			rSet.InvalidateItem( SID_ALIGNCENTERHOR );
2052 			rSet.InvalidateItem( SID_ALIGNBLOCK );
2053 			break;
2054 
2055 		default:
2056 			bJustifyStd = sal_True;
2057 			break;
2058 	}
2059 
2060 	if ( nWhich )
2061 	{
2062 		aBoolItem.SetWhich( nWhich );
2063 		rSet.Put( aBoolItem );
2064 	}
2065 	else if ( bJustifyStd )
2066 	{
2067 		aBoolItem.SetValue( sal_False );
2068 		aBoolItem.SetWhich( SID_ALIGNLEFT );	  rSet.Put( aBoolItem );
2069 		aBoolItem.SetWhich( SID_ALIGNRIGHT );	  rSet.Put( aBoolItem );
2070 		aBoolItem.SetWhich( SID_ALIGNCENTERHOR ); rSet.Put( aBoolItem );
2071 		aBoolItem.SetWhich( SID_ALIGNBLOCK );	  rSet.Put( aBoolItem );
2072 		bJustifyStd = sal_False;
2073 	}
2074 
2075 	//------------------------
2076 	// vertikale Ausrichtung
2077 	//------------------------
2078 
2079 	nWhich = 0;
2080 	aBoolItem.SetValue( sal_True );
2081 
2082 	eState = rAttrSet.GetItemState( ATTR_VER_JUSTIFY, sal_True,
2083 									(const SfxPoolItem**)&pVerJustify );
2084 
2085 	switch ( eState )
2086 	{
2087 		case SFX_ITEM_SET:
2088 			{
2089 				eVerJustify = SvxCellVerJustify( pVerJustify->GetValue() );
2090 
2091 				switch ( eVerJustify )
2092 				{
2093 					case SVX_VER_JUSTIFY_TOP:
2094 						nWhich = SID_ALIGNTOP;
2095 						break;
2096 
2097 					case SVX_VER_JUSTIFY_BOTTOM:
2098 						nWhich = SID_ALIGNBOTTOM;
2099 						break;
2100 
2101 					case SVX_VER_JUSTIFY_CENTER:
2102 						nWhich = SID_ALIGNCENTERVER;
2103 						break;
2104 
2105 					case SVX_VER_JUSTIFY_STANDARD:
2106 					default:
2107 						bJustifyStd = sal_True;
2108 						break;
2109 				}
2110 			}
2111 			break;
2112 
2113 		case SFX_ITEM_DONTCARE:
2114 			rSet.InvalidateItem( SID_ALIGNTOP );
2115 			rSet.InvalidateItem( SID_ALIGNBOTTOM );
2116 			rSet.InvalidateItem( SID_ALIGNCENTERVER );
2117 			break;
2118 
2119 		default:
2120 			bJustifyStd = sal_True;
2121 			break;
2122 	}
2123 
2124 	if ( nWhich )
2125 	{
2126 		aBoolItem.SetWhich( nWhich );
2127 		rSet.Put( aBoolItem );
2128 	}
2129 	else if ( bJustifyStd )
2130 	{
2131 		aBoolItem.SetValue( sal_False );
2132 		aBoolItem.SetWhich( SID_ALIGNTOP );	  	  rSet.Put( aBoolItem );
2133 		aBoolItem.SetWhich( SID_ALIGNBOTTOM );	  rSet.Put( aBoolItem );
2134 		aBoolItem.SetWhich( SID_ALIGNCENTERVER ); rSet.Put( aBoolItem );
2135 	}
2136 }
2137 
2138 
2139 //------------------------------------------------------------------
2140 
2141 void ScFormatShell::GetBorderState( SfxItemSet& rSet )
2142 {
2143 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
2144 	SvxBoxItem		aBoxItem( ATTR_BORDER );
2145 	SvxBoxInfoItem	aInfoItem( ATTR_BORDER_INNER );
2146 
2147 	pTabViewShell->GetSelectionFrame( aBoxItem, aInfoItem );
2148 
2149 	if ( rSet.GetItemState( ATTR_BORDER ) != SFX_ITEM_UNKNOWN )
2150 		rSet.Put( aBoxItem );
2151 	if ( rSet.GetItemState( ATTR_BORDER_INNER ) != SFX_ITEM_UNKNOWN )
2152 		rSet.Put( aInfoItem );
2153 }
2154 
2155 //------------------------------------------------------------------
2156 
2157 void ScFormatShell::GetAlignState( SfxItemSet& rSet )
2158 {
2159 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
2160 	const SfxItemSet& rAttrSet    = pTabViewShell->GetSelectionPattern()->GetItemSet();
2161 	SfxWhichIter	aIter(rSet);
2162 	sal_uInt16			nWhich = aIter.FirstWhich();
2163 
2164     SvxCellHorJustify eHAlign = SVX_HOR_JUSTIFY_STANDARD;
2165     bool bHasHAlign = rAttrSet.GetItemState( ATTR_HOR_JUSTIFY ) != SFX_ITEM_DONTCARE;
2166     if( bHasHAlign )
2167         eHAlign = (SvxCellHorJustify)((const SvxHorJustifyItem&) rAttrSet.Get( ATTR_HOR_JUSTIFY )).GetValue();
2168 
2169     SvxCellVerJustify eVAlign = SVX_VER_JUSTIFY_STANDARD;
2170     bool bHasVAlign = rAttrSet.GetItemState( ATTR_VER_JUSTIFY ) != SFX_ITEM_DONTCARE;
2171     if( bHasVAlign )
2172         eVAlign = (SvxCellVerJustify)((const SvxVerJustifyItem&) rAttrSet.Get( ATTR_VER_JUSTIFY )).GetValue();
2173 
2174 	while ( nWhich )
2175 	{
2176 		switch ( nWhich )
2177 		{
2178 			case SID_H_ALIGNCELL:
2179                 if ( bHasHAlign )
2180                     rSet.Put( SvxHorJustifyItem( eHAlign, nWhich ));
2181 			break;
2182 			case SID_V_ALIGNCELL:
2183                 if ( bHasVAlign )
2184                     rSet.Put( SvxVerJustifyItem( eVAlign, nWhich ));
2185 			break;
2186 
2187             // pseudo slots for Format menu
2188             case SID_ALIGN_ANY_HDEFAULT:
2189             case SID_ALIGN_ANY_LEFT:
2190             case SID_ALIGN_ANY_HCENTER:
2191             case SID_ALIGN_ANY_RIGHT:
2192             case SID_ALIGN_ANY_JUSTIFIED:
2193                 rSet.Put( SfxBoolItem( nWhich, bHasHAlign && (eHAlign == lclConvertSlotToHAlign( nWhich )) ) );
2194             break;
2195             case SID_ALIGN_ANY_VDEFAULT:
2196             case SID_ALIGN_ANY_TOP:
2197             case SID_ALIGN_ANY_VCENTER:
2198             case SID_ALIGN_ANY_BOTTOM:
2199                 rSet.Put( SfxBoolItem( nWhich, bHasVAlign && (eVAlign == lclConvertSlotToVAlign( nWhich )) ) );
2200             break;
2201 		}
2202 		nWhich = aIter.NextWhich();
2203 	}
2204 }
2205 
2206 void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
2207 {
2208 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
2209 
2210     // ScViewData* pViewData   = GetViewData();
2211 	ScDocument* pDoc		= pViewData->GetDocument();
2212 
2213 	SfxWhichIter aIter(rSet);
2214 	sal_uInt16 nWhich = aIter.FirstWhich();
2215 	while ( nWhich )
2216 	{
2217 		switch ( nWhich )
2218 		{
2219 			case SID_NUMBER_FORMAT:
2220 				{
2221 					String aFormatCode;			// bleibt leer, wenn dont-care
2222 
2223 					const SfxItemSet& rAttrSet  = pTabViewShell->GetSelectionPattern()->GetItemSet();
2224 					if ( rAttrSet.GetItemState( ATTR_VALUE_FORMAT ) != SFX_ITEM_DONTCARE )
2225 					{
2226 						sal_uLong nNumberFormat = ((const SfxUInt32Item&)rAttrSet.Get(
2227 													ATTR_VALUE_FORMAT )).GetValue();
2228 
2229 						SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
2230 						const SvNumberformat* pFormatEntry = pFormatter->GetEntry( nNumberFormat );
2231 						if ( pFormatEntry )
2232 							aFormatCode = pFormatEntry->GetFormatstring();
2233 					}
2234 
2235 					rSet.Put( SfxStringItem( nWhich, aFormatCode ) );
2236 				}
2237 				break;
2238 
2239 		}
2240 		nWhich = aIter.NextWhich();
2241 	}
2242 }
2243 
2244 
2245 void ScFormatShell::ExecuteTextDirection( SfxRequest& rReq )
2246 {
2247     ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2248     pTabViewShell->HideListBox();               // Autofilter-DropDown-Listbox
2249     if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
2250     {
2251         SC_MOD()->InputEnterHandler();
2252         pTabViewShell->UpdateInputHandler();
2253     }
2254 
2255     sal_uInt16 nSlot = rReq.GetSlot();
2256     switch( nSlot )
2257     {
2258         case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
2259         case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
2260         {
2261             sal_Bool bVert = (nSlot == SID_TEXTDIRECTION_TOP_TO_BOTTOM);
2262             ScPatternAttr aAttr( GetViewData()->GetDocument()->GetPool() );
2263             SfxItemSet& rItemSet = aAttr.GetItemSet();
2264             rItemSet.Put( SfxBoolItem( ATTR_STACKED, bVert ) );
2265             rItemSet.Put( SfxBoolItem( ATTR_VERTICAL_ASIAN, bVert ) );
2266             pTabViewShell->ApplySelectionPattern( aAttr );
2267             pTabViewShell->AdjustBlockHeight();
2268         }
2269         break;
2270 
2271         case SID_ATTR_PARA_LEFT_TO_RIGHT:
2272         case SID_ATTR_PARA_RIGHT_TO_LEFT:
2273         {
2274             SvxFrameDirection eDirection = ( nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT ) ?
2275                                                 FRMDIR_HORI_LEFT_TOP : FRMDIR_HORI_RIGHT_TOP;
2276             pTabViewShell->ApplyAttr( SvxFrameDirectionItem( eDirection, ATTR_WRITINGDIR ) );
2277         }
2278         break;
2279     }
2280 }
2281 
2282 void ScFormatShell::GetTextDirectionState( SfxItemSet& rSet )
2283 {
2284     ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2285     const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
2286 
2287     sal_Bool bVertDontCare =
2288         (rAttrSet.GetItemState( ATTR_VERTICAL_ASIAN ) == SFX_ITEM_DONTCARE) ||
2289         (rAttrSet.GetItemState( ATTR_STACKED ) == SFX_ITEM_DONTCARE);
2290     sal_Bool bLeftRight = !bVertDontCare &&
2291         !((const SfxBoolItem&) rAttrSet.Get( ATTR_STACKED )).GetValue();
2292     sal_Bool bTopBottom = !bVertDontCare && !bLeftRight &&
2293         ((const SfxBoolItem&) rAttrSet.Get( ATTR_VERTICAL_ASIAN )).GetValue();
2294 
2295     sal_Bool bBidiDontCare = (rAttrSet.GetItemState( ATTR_WRITINGDIR ) == SFX_ITEM_DONTCARE);
2296     EEHorizontalTextDirection eBidiDir = EE_HTEXTDIR_DEFAULT;
2297     if ( !bBidiDontCare )
2298     {
2299         SvxFrameDirection eCellDir = (SvxFrameDirection)((const SvxFrameDirectionItem&)
2300                                         rAttrSet.Get( ATTR_WRITINGDIR )).GetValue();
2301         if ( eCellDir == FRMDIR_ENVIRONMENT )
2302             eBidiDir = (EEHorizontalTextDirection)GetViewData()->GetDocument()->
2303                                 GetEditTextDirection( GetViewData()->GetTabNo() );
2304         else if ( eCellDir == FRMDIR_HORI_RIGHT_TOP )
2305             eBidiDir = EE_HTEXTDIR_R2L;
2306         else
2307             eBidiDir = EE_HTEXTDIR_L2R;
2308     }
2309 
2310 	SvtLanguageOptions	aLangOpt;
2311 	sal_Bool bDisableCTLFont = !aLangOpt.IsCTLFontEnabled();
2312 	sal_Bool bDisableVerticalText = !aLangOpt.IsVerticalTextEnabled();
2313 
2314     SfxWhichIter aIter( rSet );
2315     sal_uInt16 nWhich = aIter.FirstWhich();
2316     while( nWhich )
2317     {
2318         switch( nWhich )
2319         {
2320             case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
2321             case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
2322                 if ( bDisableVerticalText )
2323 					rSet.DisableItem( nWhich );
2324 				else
2325 				{
2326 					if( bVertDontCare )
2327 						rSet.InvalidateItem( nWhich );
2328 					else if ( nWhich == SID_TEXTDIRECTION_LEFT_TO_RIGHT )
2329 						rSet.Put( SfxBoolItem( nWhich, bLeftRight ) );
2330 					else
2331 						rSet.Put( SfxBoolItem( nWhich, bTopBottom ) );
2332 				}
2333             break;
2334 
2335             case SID_ATTR_PARA_LEFT_TO_RIGHT:
2336             case SID_ATTR_PARA_RIGHT_TO_LEFT:
2337 				if ( bDisableCTLFont )
2338 					rSet.DisableItem( nWhich );
2339 				else
2340 				{
2341 					if ( bTopBottom )
2342 						rSet.DisableItem( nWhich );
2343 					else if ( bBidiDontCare )
2344 						rSet.InvalidateItem( nWhich );
2345 					else if ( nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT )
2346 						rSet.Put( SfxBoolItem( nWhich, eBidiDir == EE_HTEXTDIR_L2R ) );
2347 					else
2348 						rSet.Put( SfxBoolItem( nWhich, eBidiDir == EE_HTEXTDIR_R2L ) );
2349 				}
2350         }
2351         nWhich = aIter.NextWhich();
2352     }
2353 }
2354 
2355 void ScFormatShell::ExecFormatPaintbrush( SfxRequest& rReq )
2356 {
2357     ScViewFunc* pView = pViewData->GetView();
2358     if ( pView->HasPaintBrush() )
2359     {
2360         // cancel paintbrush mode
2361         pView->ResetBrushDocument();
2362     }
2363     else
2364     {
2365         sal_Bool bLock = sal_False;
2366         const SfxItemSet *pArgs = rReq.GetArgs();
2367         if( pArgs && pArgs->Count() >= 1 )
2368             bLock = static_cast<const SfxBoolItem&>(pArgs->Get(SID_FORMATPAINTBRUSH)).GetValue();
2369 
2370         // in case of multi selection, deselect all and use the cursor position
2371         ScRange aDummy;
2372         if ( pViewData->GetSimpleArea(aDummy) != SC_MARK_SIMPLE )
2373             pView->Unmark();
2374 
2375         ScDocument* pBrushDoc = new ScDocument( SCDOCMODE_CLIP );
2376         pView->CopyToClip( pBrushDoc, sal_False, sal_True );
2377         pView->SetBrushDocument( pBrushDoc, bLock );
2378     }
2379 }
2380 
2381 void ScFormatShell::StateFormatPaintbrush( SfxItemSet& rSet )
2382 {
2383     if ( pViewData->HasEditView( pViewData->GetActivePart() ) )
2384         rSet.DisableItem( SID_FORMATPAINTBRUSH );
2385     else
2386         rSet.Put( SfxBoolItem( SID_FORMATPAINTBRUSH, pViewData->GetView()->HasPaintBrush() ) );
2387 }
2388 
2389 void  ScFormatShell::ExecViewOptions( SfxRequest& rReq )
2390 {
2391 	ScTabViewShell*	pTabViewShell  		= GetViewData()->GetViewShell();
2392 	SfxBindings&		rBindings = pViewData->GetBindings();
2393 	const SfxItemSet*	pNewAttrs = rReq.GetArgs();
2394 
2395 	if ( pNewAttrs )
2396 	{
2397 		sal_uInt16 nSlot = rReq.GetSlot();
2398 
2399 		if( nSlot  == SID_SCGRIDSHOW)
2400 		{
2401 
2402 			ScViewData*				pViewData = pTabViewShell->GetViewData();
2403 			const ScViewOptions&	rOldOpt	  = pViewData->GetOptions();
2404 			ScDocShell*				pDocSh  = PTR_CAST(ScDocShell, SfxObjectShell::Current());
2405 			bool bState =	((const SfxBoolItem &)pNewAttrs->Get( pNewAttrs->GetPool()->GetWhich( nSlot ) )).GetValue();
2406 
2407 			if ( (bool)rOldOpt.GetOption( VOPT_GRID ) !=  bState)
2408 			{
2409 				ScViewOptions rNewOpt(rOldOpt);
2410 				rNewOpt.SetOption( VOPT_GRID,  bState);
2411 				pViewData->SetOptions( rNewOpt );
2412 				pViewData->GetDocument()->SetViewOptions( rNewOpt );
2413 				pDocSh->SetDocumentModified();
2414 				//add , write the change to sc view config
2415 				ScModule*			pScMod		= SC_MOD();
2416 				pScMod->SetViewOptions( rNewOpt );
2417 				//add end
2418 				rBindings.Invalidate( nSlot );
2419 			}
2420 		}
2421 	}
2422 
2423 }
2424 
2425 void  ScFormatShell::GetViewOptions( SfxItemSet& rSet )
2426 {
2427 	ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2428 	if( pTabViewShell )
2429 	{
2430 		ScViewOptions	aViewOpt = pTabViewShell->GetViewData()->GetOptions();
2431 		rSet.ClearItem(SID_SCGRIDSHOW);
2432 		SfxBoolItem aItem( SID_SCGRIDSHOW, aViewOpt.GetOption( VOPT_GRID ) );
2433 		rSet.Put(aItem);
2434 	}
2435 }
2436 
2437 // eof
2438