update dev300-m58
[ooovba.git] / sw / source / ui / shells / tabsh.cxx
blob577ea95c64b2bcd304c8005a6cbd0672d0aebc96
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabsh.cxx,v $
10 * $Revision: 1.46.212.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <hintids.hxx>
35 #ifndef _ZFORLIST_HXX
36 #define _ZFORLIST_DECLARE_TABLE
37 #include <svtools/zforlist.hxx>
38 #endif
39 #include <svtools/stritem.hxx>
40 #include <svtools/whiter.hxx>
41 #include <svtools/moduleoptions.hxx>
42 #include <svx/rulritem.hxx>
43 #include <svx/srchitem.hxx>
44 #include <svx/lrspitem.hxx>
45 #include <svx/ulspitem.hxx>
46 #include <svx/brshitem.hxx>
47 #include <svx/boxitem.hxx>
48 #include <svx/shaditem.hxx>
49 #include <svx/spltitem.hxx>
50 #include <svx/langitem.hxx>
51 #include <svx/keepitem.hxx>
52 #include <svx/bolnitem.hxx>
53 #include <svx/colritem.hxx>
54 #include <svx/frmdiritem.hxx>
55 #include <svx/numinf.hxx>
56 #include <svx/svddef.hxx>
57 #include <svx/svxdlg.hxx>
58 #include <svtools/zformat.hxx>
59 #include <sfx2/bindings.hxx>
60 #include <vcl/msgbox.hxx>
61 #include <sfx2/request.hxx>
62 #include <sfx2/dispatch.hxx>
63 #include <sfx2/objface.hxx>
66 #include <fmtornt.hxx>
67 #include <fmtclds.hxx>
68 #include <fmtlsplt.hxx>
69 #include <fmtrowsplt.hxx>
70 #include <fmtfsize.hxx>
71 #include <swmodule.hxx>
72 #include <wrtsh.hxx>
73 #include <wview.hxx>
74 #include <frmatr.hxx>
75 #include <uitool.hxx>
76 #include <inputwin.hxx>
77 #include <uiitems.hxx>
78 #include <usrpref.hxx>
79 #include <tabsh.hxx>
80 #include "swtablerep.hxx"
81 #include <tablemgr.hxx>
82 #include <cellatr.hxx>
83 #include <frmfmt.hxx>
84 #include <swundo.hxx>
85 #include <swtable.hxx>
86 #include <docsh.hxx>
87 #include <tblsel.hxx>
89 #include <dialog.hrc>
93 //!!! new: insert table
95 #include <svx/htmlmode.hxx>
96 #include <modcfg.hxx>
97 #include <tblafmt.hxx>
98 #include <instable.hxx>
100 //!!!
102 #ifndef _POPUP_HRC
103 #include <popup.hrc>
104 #endif
105 #ifndef _SHELLS_HRC
106 #include <shells.hrc>
107 #endif
108 #ifndef _TABLE_HRC
109 #include <table.hrc>
110 #endif
111 #ifndef _CMDID_H
112 #include <cmdid.h>
113 #endif
114 #ifndef _GLOBALS_HRC
115 #include <globals.hrc>
116 #endif
117 #ifndef _HELPID_H
118 #include <helpid.h>
119 #endif
120 #include <unoobj.hxx>
122 #define SwTableShell
123 #include <sfx2/msg.hxx>
124 #include <swslots.hxx>
126 #include "swabstdlg.hxx"
127 #include <table.hrc>
129 using namespace ::com::sun::star;
131 //-----------------------------------------------------------------------------
133 SFX_IMPL_INTERFACE(SwTableShell, SwBaseShell, SW_RES(STR_SHELLNAME_TABLE))
135 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_TAB_POPUPMENU));
136 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TABLE_TOOLBOX));
140 TYPEINIT1(SwTableShell,SwBaseShell)
142 /************************************************************************/
144 const USHORT __FAR_DATA aUITableAttrRange[] =
146 FN_PARAM_TABLE_NAME, FN_PARAM_TABLE_NAME,
147 FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE,
148 FN_PARAM_TABLE_SPACE, FN_PARAM_TABLE_SPACE,
149 FN_TABLE_REP, FN_TABLE_REP,
150 SID_RULER_BORDERS, SID_RULER_BORDERS,
151 RES_LR_SPACE, RES_UL_SPACE,
152 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_SHADOW,
153 RES_BOX, RES_SHADOW,
154 RES_BACKGROUND, RES_BACKGROUND,
155 SID_BACKGRND_DESTINATION, SID_BACKGRND_DESTINATION,
156 SID_HTML_MODE, SID_HTML_MODE,
157 SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE,
158 RES_PAGEDESC, RES_BREAK,
159 RES_KEEP, RES_KEEP,
160 RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT,
161 FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN,
162 RES_FRAMEDIR, RES_FRAMEDIR,
163 RES_ROW_SPLIT, RES_ROW_SPLIT,
164 FN_TABLE_BOX_TEXTDIRECTION, FN_TABLE_BOX_TEXTDIRECTION,
165 // --> collapsing borders FME 2005-05-27 #i29550#
166 RES_COLLAPSING_BORDERS, RES_COLLAPSING_BORDERS,
167 // <-- collapsing borders
171 const USHORT* SwuiGetUITableAttrRange()
173 return aUITableAttrRange;
176 static void lcl_SetAttr( SwWrtShell &rSh, const SfxPoolItem &rItem )
178 SfxItemSet aSet( rSh.GetView().GetPool(), rItem.Which(), rItem.Which(), 0);
179 aSet.Put( rItem );
180 rSh.SetTblAttr( aSet );
183 /************************************************************************/
186 static SwTableRep* lcl_TableParamToItemSet( SfxItemSet& rSet, SwWrtShell &rSh )
188 SwFrmFmt *pFmt = rSh.GetTableFmt();
189 SwTabCols aCols;
190 rSh.GetTabCols( aCols );
192 //Ersteinmal die einfachen Attribute besorgen.
193 rSet.Put( SfxStringItem( FN_PARAM_TABLE_NAME, pFmt->GetName()));
194 rSet.Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, rSh.GetRowsToRepeat() ) );
195 rSet.Put( pFmt->GetShadow() );
196 rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, rSh.GetBoxAlign()));
197 rSet.Put( pFmt->GetFrmDir() );
199 SvxULSpaceItem aULSpace( pFmt->GetULSpace() );
200 rSet.Put( aULSpace );
202 USHORT nBackgroundDestination = rSh.GetViewOptions()->GetTblDest();
203 rSet.Put(SwBackgroundDestinationItem(SID_BACKGRND_DESTINATION, nBackgroundDestination ));
204 SvxBrushItem aBrush( RES_BACKGROUND );
205 // rSh.GetBoxBackground(aBrush);
206 // rSet.Put( aBrush );
207 if(rSh.GetRowBackground(aBrush))
208 rSet.Put( aBrush, SID_ATTR_BRUSH_ROW );
209 else
210 rSet.InvalidateItem(SID_ATTR_BRUSH_ROW);
211 rSh.GetTabBackground(aBrush);
212 rSet.Put( aBrush, SID_ATTR_BRUSH_TABLE );
214 // text direction in boxes
215 SvxFrameDirectionItem aBoxDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
216 if(rSh.GetBoxDirection( aBoxDirection ))
217 rSet.Put(aBoxDirection, FN_TABLE_BOX_TEXTDIRECTION);
219 BOOL bTableSel = rSh.IsTableMode();
220 if(!bTableSel)
222 rSh.StartAllAction();
223 rSh.Push();
224 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute( FN_TABLE_SELECT_ALL, FALSE );
226 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
228 // Tabellenvariante, wenn mehrere Tabellenzellen selektiert
229 rSh.GetCrsr(); //Damit GetCrsrCnt() auch das Richtige liefert
230 aBoxInfo.SetTable (rSh.IsTableMode() && rSh.GetCrsrCnt() > 1 ||
231 !bTableSel);
232 // Abstandsfeld immer anzeigen
233 aBoxInfo.SetDist ((BOOL) TRUE);
234 // Minimalgroesse in Tabellen und Absaetzen setzen
235 aBoxInfo.SetMinDist( !bTableSel || rSh.IsTableMode() ||
236 rSh.GetSelectionType() &
237 (nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL));
238 // Default-Abstand immer setzen
239 aBoxInfo.SetDefDist (MIN_BORDER_DIST);
240 // Einzelne Linien koennen nur in Tabellen DontCare-Status haben
241 aBoxInfo.SetValid( VALID_DISABLE, !bTableSel || !rSh.IsTableMode() );
243 rSet.Put(aBoxInfo);
244 rSh.GetTabBorders( rSet );
246 //row split
247 SwFmtRowSplit* pSplit = 0;
248 rSh.GetRowSplit(pSplit);
249 if(pSplit)
251 rSet.Put(*pSplit);
252 delete pSplit;
255 if(!bTableSel)
257 rSh.ClearMark();
258 rSh.Pop(FALSE);
259 rSh.EndAllAction();
262 SwTabCols aTabCols;
263 rSh.GetTabCols( aTabCols );
264 SvxColumnItem aColItem;
267 // Pointer wird nach der Dialogausfuehrung geloescht
268 SwTableRep* pRep = new SwTableRep( aTabCols, rSh.IsTblComplex());
269 pRep->SetSpace(aCols.GetRightMax());
271 USHORT nPercent = 0;
272 long nWidth = ::GetTableWidth(pFmt, aCols, &nPercent, &rSh );
273 // Die Tabellenbreite ist fuer relative Angaben nicht korrekt
274 if(nPercent)
275 nWidth = pRep->GetSpace() * nPercent / 100;
276 USHORT nAlign = pFmt->GetHoriOrient().GetHoriOrient();
277 pRep->SetAlign(nAlign);
278 SvxLRSpaceItem aLRSpace( pFmt->GetLRSpace() );
279 SwTwips nLeft = aLRSpace.GetLeft();
280 SwTwips nRight = aLRSpace.GetRight();
281 SwTwips nDiff = pRep->GetSpace() - nRight - nLeft - nWidth;
282 if(nAlign != text::HoriOrientation::FULL && Abs(nDiff) > 2)
284 SwTwips nLR = pRep->GetSpace() - nWidth;
285 switch ( nAlign )
287 case text::HoriOrientation::CENTER: nLeft = nRight = nLR / 2;
288 break;
289 case text::HoriOrientation::LEFT: nRight = nLR; nLeft = 0;
290 break;
291 case text::HoriOrientation::RIGHT: nLeft = nLR, nRight = 0;
292 break;
293 case text::HoriOrientation::LEFT_AND_WIDTH:
294 nRight = nLR - nLeft;
295 break;
296 case text::HoriOrientation::NONE:
297 if(!nPercent)
298 nWidth = pRep->GetSpace() - nLeft - nRight;
299 break;
302 pRep->SetLeftSpace(nLeft);
303 pRep->SetRightSpace(nRight);
305 pRep->SetWidth(nWidth);
306 pRep->SetWidthPercent(nPercent);
307 // sind einzelne Zeilen/Zellen selektiert, wird die Spaltenbearbeitung veraendert
308 pRep->SetLineSelected(bTableSel && ! rSh.HasWholeTabSelection());
309 rSet.Put(SwPtrItem(FN_TABLE_REP, pRep));
310 return pRep;
313 /************************************************************************/
316 void ItemSetToTableParam( const SfxItemSet& rSet,
317 SwWrtShell &rSh )
319 rSh.StartAllAction();
320 rSh.StartUndo( UNDO_TABLE_ATTR );
321 const SfxPoolItem* pItem = 0;
323 SwViewOption aUsrPref( *rSh.GetViewOptions() );
324 USHORT nBackgroundDestination = aUsrPref.GetTblDest();
325 if(SFX_ITEM_SET == rSet.GetItemState(SID_BACKGRND_DESTINATION, FALSE, &pItem))
327 nBackgroundDestination = ((SfxUInt16Item*)pItem)->GetValue();
328 aUsrPref.SetTblDest((BYTE)nBackgroundDestination);
329 SW_MOD()->ApplyUsrPref(aUsrPref, &rSh.GetView());
331 BOOL bBorder = ( SFX_ITEM_SET == rSet.GetItemState( RES_BOX ) ||
332 SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER ) );
333 pItem = 0;
334 BOOL bBackground = SFX_ITEM_SET == rSet.GetItemState( RES_BACKGROUND, FALSE, &pItem );
335 const SfxPoolItem* pRowItem = 0, *pTableItem = 0;
336 bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_ROW, FALSE, &pRowItem );
337 bBackground |= SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BRUSH_TABLE, FALSE, &pTableItem );
338 const SfxPoolItem* pSplit = 0;
339 BOOL bRowSplit = SFX_ITEM_SET == rSet.GetItemState( RES_ROW_SPLIT, FALSE, &pSplit );
340 const SfxPoolItem* pBoxDirection = 0;
341 BOOL bBoxDirection = SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_BOX_TEXTDIRECTION, FALSE, &pBoxDirection );
342 if( bBackground || bBorder || bRowSplit || bBoxDirection)
345 Die Umrandung wird auf die vorliegende Selektion angewendet
346 Liegt keine Selektion vor, wird die Tabelle vollstaendig selektiert.
347 Der Hintergrund wird immer auf den aktuellen Zustand angewendet.
350 BOOL bTableSel = rSh.IsTableMode();
351 rSh.StartAllAction();
353 if(bBackground)
355 if(pItem)
356 rSh.SetBoxBackground( *(const SvxBrushItem*)pItem );
357 if(pRowItem)
359 SvxBrushItem aBrush(*(const SvxBrushItem*)pRowItem);
360 aBrush.SetWhich(RES_BACKGROUND);
361 rSh.SetRowBackground(aBrush);
363 if(pTableItem)
365 SvxBrushItem aBrush(*(const SvxBrushItem*)pTableItem);
366 aBrush.SetWhich(RES_BACKGROUND);
367 rSh.SetTabBackground( aBrush );
371 if(bBoxDirection)
373 SvxFrameDirectionItem aDirection( FRMDIR_ENVIRONMENT, RES_FRAMEDIR );
374 aDirection.SetValue(static_cast< const SvxFrameDirectionItem* >(pBoxDirection)->GetValue());
375 rSh.SetBoxDirection(aDirection);
378 if(bBorder || bRowSplit)
380 rSh.Push();
381 if(!bTableSel)
383 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute( FN_TABLE_SELECT_ALL );
385 if(bBorder)
386 rSh.SetTabBorders( rSet );
388 if(bRowSplit)
390 rSh.SetRowSplit(*static_cast<const SwFmtRowSplit*>(pSplit));
393 if(!bTableSel)
395 rSh.ClearMark();
397 rSh.Pop(FALSE);
400 rSh.EndAllAction();
403 SwTabCols aTabCols;
404 BOOL bTabCols = FALSE;
405 BOOL bSingleLine = FALSE;
406 SwTableRep* pRep = 0;
407 SwFrmFmt *pFmt = rSh.GetTableFmt();
408 SfxItemSet aSet( rSh.GetAttrPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
409 if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP, FALSE, &pItem ))
411 pRep = (SwTableRep*)((const SwPtrItem*)pItem)->GetValue();
413 const SwTwips nWidth = pRep->GetWidth();
414 if ( text::HoriOrientation::FULL == pRep->GetAlign() )
416 SwFmtHoriOrient aAttr( pFmt->GetHoriOrient() );
417 aAttr.SetHoriOrient( text::HoriOrientation::FULL );
418 aSet.Put( aAttr );
420 else
422 SwFmtFrmSize aSz( ATT_VAR_SIZE, nWidth );
423 if(pRep->GetWidthPercent())
425 aSz.SetWidthPercent( (BYTE)pRep->GetWidthPercent() );
427 aSet.Put(aSz);
430 SvxLRSpaceItem aLRSpace( RES_LR_SPACE );
431 aLRSpace.SetLeft(pRep->GetLeftSpace());
432 aLRSpace.SetRight(pRep->GetRightSpace());
433 aSet.Put( aLRSpace );
435 sal_Int16 eOrient = pRep->GetAlign();
436 SwFmtHoriOrient aAttr( 0, eOrient );
437 aSet.Put( aAttr );
438 // Damit beim recording die Ausrichtung nicht durch die Abstaende ueberschrieben
439 // wird, darf das Item nur bei manueller Ausrichtung aufgez. werden
440 if(eOrient != text::HoriOrientation::NONE)
441 ((SfxItemSet&)rSet).ClearItem( SID_ATTR_LRSPACE );
444 if(pRep->HasColsChanged())
446 bTabCols = TRUE;
451 if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, FALSE, &pItem))
452 rSh.SetRowsToRepeat( ((SfxUInt16Item*)pItem)->GetValue() );
454 if( SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_SET_VERT_ALIGN, FALSE, &pItem))
455 rSh.SetBoxAlign(((SfxUInt16Item*)(pItem))->GetValue());
457 if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_NAME, FALSE, &pItem ))
458 rSh.SetTableName( *pFmt, ((const SfxStringItem*)pItem)->GetValue() );
460 // kopiere die ausgesuchten Attribute in den ItemSet
461 static USHORT __READONLY_DATA aIds[] =
463 RES_PAGEDESC,
464 RES_BREAK,
465 RES_KEEP,
466 RES_LAYOUT_SPLIT,
467 RES_UL_SPACE,
468 RES_SHADOW,
469 RES_FRAMEDIR,
470 // --> collapsing borders FME 2005-05-27 #i29550#
471 RES_COLLAPSING_BORDERS,
472 // <-- collapsing borders
475 for( const USHORT* pIds = aIds; *pIds; ++pIds )
476 if( SFX_ITEM_SET == rSet.GetItemState( *pIds, FALSE, &pItem))
477 aSet.Put( *pItem );
479 if( aSet.Count() )
480 rSh.SetTblAttr( aSet );
482 if(bTabCols)
484 rSh.GetTabCols( aTabCols );
485 bSingleLine = pRep->FillTabCols( aTabCols );
486 rSh.SetTabCols( aTabCols, bSingleLine );
489 rSh.EndUndo( UNDO_TABLE_ATTR );
490 rSh.EndAllAction();
493 /************************************************************************/
496 static void lcl_TabGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine)
498 if(pBorderLine->GetInWidth() > rBorderLine.GetInWidth())
499 rBorderLine.SetInWidth(pBorderLine->GetInWidth());
501 if(pBorderLine->GetOutWidth() > rBorderLine.GetOutWidth())
502 rBorderLine.SetOutWidth(pBorderLine->GetOutWidth());
504 if(pBorderLine->GetDistance() > rBorderLine.GetDistance())
505 rBorderLine.SetDistance(pBorderLine->GetDistance());
507 rBorderLine.SetColor(pBorderLine->GetColor());
511 void SwTableShell::Execute(SfxRequest &rReq)
513 BOOL bUseDialog = TRUE;
514 const SfxItemSet* pArgs = rReq.GetArgs();
515 SwWrtShell &rSh = GetShell();
517 //Erstmal die Slots, die keinen FrmMgr benoetigen.
518 BOOL bMore = FALSE;
519 const SfxPoolItem* pItem = 0;
520 USHORT nSlot = rReq.GetSlot();
521 if(pArgs)
522 pArgs->GetItemState(GetPool().GetWhich(nSlot), FALSE, &pItem);
523 BOOL bCallDone = FALSE;
524 switch ( nSlot )
526 case SID_ATTR_BORDER:
528 /* BOOL bPopCrsr = FALSE;
529 if ( !rReq.IsAPI() )
531 //Keine Tabellenselektion -> Aenderung wird auf die gesamte
532 //Tabelle.
533 if ( !rSh.IsTableMode() )
535 rSh.StartAction();
536 bPopCrsr = TRUE;
537 rSh.Push();
538 rSh.EnterStdMode();
539 rSh.MoveTable( fnTableCurr, fnTableStart );
540 rSh.SttSelect();
541 rSh.MoveTable( fnTableCurr, fnTableEnd );
542 rSh.EndSelect();
545 if(!pArgs)
546 break;
547 //Items erzeugen, weil wir sowieso nacharbeiten muessen
548 SvxBoxItem aBox( RES_BOX );
549 SfxItemSet aCoreSet( GetPool(),
550 RES_BOX, RES_BOX,
551 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
553 SvxBoxInfoItem aCoreInfo( SID_ATTR_BORDER_INNER );
554 aCoreSet.Put(aCoreInfo);
555 rSh.GetTabBorders( aCoreSet );
556 const SvxBoxItem& rCoreBox = (const SvxBoxItem&)
557 aCoreSet.Get(RES_BOX);
558 const SfxPoolItem *pBoxItem = 0;
559 if ( pArgs->GetItemState(RES_BOX, TRUE, &pBoxItem) == SFX_ITEM_SET )
561 aBox = *(SvxBoxItem*)pBoxItem;
562 if ( !rReq.IsAPI() )
563 aBox.SetDistance( Max(rCoreBox.GetDistance(),USHORT(55)) );
564 else if ( aBox.GetDistance() < MIN_BORDER_DIST )
565 aBox.SetDistance( Max(rCoreBox.GetDistance(),(USHORT)MIN_BORDER_DIST) );
567 else
568 {ASSERT( !this, "Wo ist das Box-Item?" )}
570 //since the drawing layer also supports borders the which id might be a different one
571 SvxBoxInfoItem aInfo( SID_ATTR_BORDER_INNER );
572 if (pArgs->GetItemState(SID_ATTR_BORDER_INNER, TRUE, &pBoxItem) == SFX_ITEM_SET)
573 aInfo = *(SvxBoxInfoItem*)pBoxItem;
574 else if( pArgs->GetItemState(SDRATTR_TABLE_BORDER_INNER, TRUE, &pBoxItem) == SFX_ITEM_SET )
576 aInfo = *(SvxBoxInfoItem*)pBoxItem;
577 aInfo.SetWhich(SID_ATTR_BORDER_INNER);
580 aInfo.SetTable( TRUE );
581 aInfo.SetValid( VALID_DISABLE, FALSE );
584 // Die Attribute aller Linien werden gelesen und das staerkste gewinnt
585 const SvxBorderLine* pBorderLine;
586 SvxBorderLine aBorderLine;
587 if ((pBorderLine = rCoreBox.GetTop()) != NULL)
588 lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine);
589 if ((pBorderLine = rCoreBox.GetBottom()) != NULL)
590 lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine);
591 if ((pBorderLine = rCoreBox.GetLeft()) != NULL)
592 lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine);
593 if ((pBorderLine = rCoreBox.GetRight()) != NULL)
594 lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine);
595 if ((pBorderLine = aCoreInfo.GetHori()) != NULL)
596 lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine);
597 if ((pBorderLine = aCoreInfo.GetVert()) != NULL)
598 lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine);
600 if(aBorderLine.GetOutWidth() == 0)
602 aBorderLine.SetInWidth(0);
603 aBorderLine.SetOutWidth(DEF_LINE_WIDTH_0);
606 BOOL bLine = FALSE;
607 if ( (pBorderLine = aBox.GetTop()) != NULL)
608 aBox.SetLine(&aBorderLine, BOX_LINE_TOP), bLine |= TRUE;
609 if ((pBorderLine = aBox.GetBottom()) != NULL)
610 aBox.SetLine(&aBorderLine, BOX_LINE_BOTTOM), bLine |= TRUE;
611 if ((pBorderLine = aBox.GetLeft()) != NULL)
612 aBox.SetLine(&aBorderLine, BOX_LINE_LEFT), bLine |= TRUE;
613 if ((pBorderLine = aBox.GetRight()) != NULL)
614 aBox.SetLine(&aBorderLine, BOX_LINE_RIGHT), bLine |= TRUE;
615 if ((pBorderLine = aInfo.GetHori()) != NULL)
616 aInfo.SetLine(&aBorderLine, BOXINFO_LINE_HORI), bLine |= TRUE;
617 if ((pBorderLine = aInfo.GetVert()) != NULL)
618 aInfo.SetLine(&aBorderLine, BOXINFO_LINE_VERT), bLine |= TRUE;
620 // if ( bPopCrsr && !bLine )
621 // aBox.SetDistance( 0 );
623 aCoreSet.Put( aBox );
624 aCoreSet.Put( aInfo );
625 rSh.SetTabBorders( aCoreSet );
627 // we must record the "real" values because otherwise the lines can't be reconstructed on playtime
628 // the coding style of the controller (setting lines with width 0) is not transportable via Query/PutValue in
629 // the SvxBoxItem
630 rReq.AppendItem( aBox );
631 rReq.AppendItem( aInfo );
632 bCallDone = TRUE;
634 /* if ( bPopCrsr )
636 rSh.KillPams();
637 rSh.Pop(FALSE);
638 rSh.EndAction();
641 break;
642 case FN_INSERT_TABLE:
643 InsertTable( rReq );
644 break;
645 case FN_FORMAT_TABLE_DLG:
647 //#127012# get the bindings before the dialog is called
648 // it might happen that this shell is removed after closing the dialog
649 SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
650 SfxItemSet aCoreSet( GetPool(), aUITableAttrRange);
652 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &rSh.GetView()));
653 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< UINT16 >(eMetric)));
654 SwTableRep* pTblRep = ::lcl_TableParamToItemSet( aCoreSet, rSh );
655 SfxAbstractTabDialog * pDlg = NULL;
656 if ( bUseDialog )
658 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
659 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
661 pDlg = pFact->CreateSwTableTabDlg( GetView().GetWindow(), GetPool(), &aCoreSet, &rSh, DLG_FORMAT_TABLE );
662 DBG_ASSERT(pDlg, "Dialogdiet fail!");
664 aCoreSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(GetView().GetDocShell())));
665 rSh.GetTblAttr(aCoreSet);
666 // GetTblAttr buegelt den Background ueber!
667 SvxBrushItem aBrush( RES_BACKGROUND );
668 if(rSh.GetBoxBackground(aBrush))
669 aCoreSet.Put( aBrush );
670 else
671 aCoreSet.InvalidateItem( RES_BACKGROUND );
673 if ( !pDlg && rReq.GetArgs() || pDlg->Execute() == RET_OK )
675 const SfxItemSet* pOutSet = pDlg ? pDlg->GetOutputItemSet() : rReq.GetArgs();
676 if ( pDlg )
678 //to record FN_INSERT_TABLE correctly
679 rReq.SetSlot(FN_FORMAT_TABLE_DLG);
680 rReq.Done( *pOutSet );
682 ItemSetToTableParam( *pOutSet, rSh );
685 delete pDlg;
686 delete pTblRep;
687 rBindings.Update(SID_RULER_BORDERS);
688 rBindings.Update(SID_ATTR_TABSTOP);
689 rBindings.Update(SID_RULER_BORDERS_VERTICAL);
690 rBindings.Update(SID_ATTR_TABSTOP_VERTICAL);
692 break;
693 case SID_ATTR_BRUSH:
694 case SID_ATTR_BRUSH_ROW :
695 case SID_ATTR_BRUSH_TABLE :
696 if(rReq.GetArgs())
697 ItemSetToTableParam(*rReq.GetArgs(), rSh);
698 break;
699 case FN_NUM_FORMAT_TABLE_DLG:
701 SwView* pView = GetActiveView();
702 if(pView)
704 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
705 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< UINT16 >(eMetric)));
706 SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
707 SfxItemSet aCoreSet( GetPool(),
708 SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_VALUE,
709 SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO,
710 0 );
712 SfxItemSet aBoxSet( *aCoreSet.GetPool(),
713 RES_BOXATR_FORMAT, RES_BOXATR_FORMAT,
714 RES_BOXATR_VALUE, RES_BOXATR_VALUE,
715 0 );
716 rSh.GetTblBoxFormulaAttrs( aBoxSet );
718 SfxItemState eState = aBoxSet.GetItemState(RES_BOXATR_FORMAT);
719 if(eState == SFX_ITEM_DEFAULT)
721 aCoreSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE,
722 pFormatter->GetFormatIndex(NF_TEXT, LANGUAGE_SYSTEM)));
724 else
725 aCoreSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE,
726 ((SwTblBoxNumFormat&)aBoxSet.Get(
727 RES_BOXATR_FORMAT )).GetValue() ));
729 String sCurText( rSh.GetTableBoxText() );
730 aCoreSet.Put( SvxNumberInfoItem( pFormatter,
731 ((SwTblBoxValue&)aBoxSet.Get(
732 RES_BOXATR_VALUE)).GetValue(),
733 sCurText, SID_ATTR_NUMBERFORMAT_INFO ));
735 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
736 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
738 SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( GetView().GetWindow(),aCoreSet,
739 pView->GetViewFrame()->GetFrame()->GetFrameInterface(),
740 RC_DLG_SWNUMFMTDLG );
741 DBG_ASSERT(pDlg, "Dialogdiet fail!");
743 if (RET_OK == pDlg->Execute())
745 const SfxPoolItem* pNumberFormatItem = GetView().GetDocShell()->
746 GetItem( SID_ATTR_NUMBERFORMAT_INFO );
748 if( pNumberFormatItem && 0 != ((SvxNumberInfoItem*)pNumberFormatItem)->GetDelCount() )
750 const sal_uInt32* pDelArr = ((SvxNumberInfoItem*)
751 pNumberFormatItem)->GetDelArray();
753 for ( USHORT i = 0; i < ((SvxNumberInfoItem*)pNumberFormatItem)->GetDelCount(); i++ )
754 ((SvxNumberInfoItem*)pNumberFormatItem)->
755 GetNumberFormatter()->DeleteEntry( pDelArr[i] );
758 if( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState(
759 SID_ATTR_NUMBERFORMAT_VALUE, FALSE, &pNumberFormatItem ))
761 SfxItemSet aBoxFormatSet( *aCoreSet.GetPool(),
762 RES_BOXATR_FORMAT, RES_BOXATR_FORMAT );
763 aBoxFormatSet.Put( SwTblBoxNumFormat(
764 ((SfxUInt32Item*)pNumberFormatItem)->GetValue() ));
765 rSh.SetTblBoxFormulaAttrs( aBoxFormatSet );
769 delete pDlg;
772 break;
773 case FN_CALC_TABLE:
774 rSh.UpdateTable();
775 bCallDone = TRUE;
776 break;
777 case FN_TABLE_OPTIMAL_HEIGHT:
779 const SwFmtFrmSize aSz;
780 rSh.SetRowHeight( aSz );
781 bCallDone = TRUE;
783 break;
784 case FN_TABLE_DELETE_COL:
785 if ( rSh.DeleteCol() && rSh.HasSelection() )
786 rSh.EnterStdMode();
787 bCallDone = TRUE;
788 break;
789 case FN_END_TABLE:
790 rSh.MoveTable( fnTableCurr, fnTableEnd );
791 bCallDone = TRUE;
792 break;
793 case FN_START_TABLE:
794 rSh.MoveTable( fnTableCurr, fnTableStart );
795 bCallDone = TRUE;
796 break;
797 case FN_GOTO_NEXT_CELL:
799 BOOL bAppendLine = TRUE;
800 if( pItem )
801 bAppendLine = ((SfxBoolItem*)pItem)->GetValue();
802 rReq.SetReturnValue( SfxBoolItem( nSlot,
803 rSh.GoNextCell( bAppendLine ) ) );
804 bCallDone = TRUE;
806 break;
807 case FN_GOTO_PREV_CELL:
808 rReq.SetReturnValue( SfxBoolItem( nSlot, rSh.GoPrevCell() ) );
809 bCallDone = TRUE;
810 break;
811 case FN_TABLE_DELETE_ROW:
812 if ( rSh.DeleteRow() && rSh.HasSelection() )
813 rSh.EnterStdMode();
814 bCallDone = TRUE;
815 break;
816 case FN_TABLE_MERGE_CELLS:
817 if ( rSh.IsTableMode() )
818 switch ( rSh.MergeTab() )
820 case TBLMERGE_OK:
821 bCallDone = TRUE;
822 //no break;
823 case TBLMERGE_NOSELECTION: break;
824 case TBLMERGE_TOOCOMPLEX:
826 InfoBox aInfoBox( GetView().GetWindow(),
827 SW_RES( MSG_ERR_TABLE_MERGE ) );
828 aInfoBox.Execute();
829 break;
831 default: ASSERT( !this, "unbekannter Returnwert MergeTab.");
833 break;
834 case FN_TABLE_ADJUST_CELLS:
835 case FN_TABLE_BALANCE_CELLS:
837 BOOL bBalance = (FN_TABLE_BALANCE_CELLS == nSlot);
838 if ( rSh.IsAdjustCellWidthAllowed(bBalance) )
841 // remove actions to make a valid table selection
842 UnoActionRemoveContext aRemoveContext(rSh.GetDoc());
844 rSh.AdjustCellWidth(bBalance);
846 bCallDone = TRUE;
848 break;
849 case FN_TABLE_BALANCE_ROWS:
850 if ( rSh.BalanceRowHeight(TRUE) )
851 rSh.BalanceRowHeight(FALSE);
852 bCallDone = TRUE;
853 break;
854 case FN_TABLE_SELECT_ALL:
855 rSh.EnterStdMode();
856 rSh.MoveTable( fnTableCurr, fnTableStart );
857 rSh.SttSelect();
858 rSh.MoveTable( fnTableCurr, fnTableEnd );
859 rSh.EndSelect();
860 bCallDone = TRUE;
861 break;
862 case FN_TABLE_SELECT_COL:
863 rSh.EnterStdMode();
864 rSh.SelectTableCol();
865 bCallDone = TRUE;
866 break;
867 case FN_TABLE_SELECT_ROW:
868 rSh.EnterStdMode();
869 rSh.SelectTableRow();
870 bCallDone = TRUE;
871 break;
872 case FN_TABLE_SET_READ_ONLY_CELLS:
873 rSh.ProtectCells();
874 rSh.ResetSelect( 0, FALSE );
875 bCallDone = TRUE;
876 break;
877 case FN_TABLE_UNSET_READ_ONLY_CELLS:
878 rSh.UnProtectCells();
879 bCallDone = TRUE;
880 break;
881 case SID_AUTOFORMAT:
883 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
884 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
886 AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(&GetView().GetViewFrame()->GetWindow(), &rSh , DLG_AUTOFMT_TABLE );
887 DBG_ASSERT(pDlg, "Dialogdiet fail!");
888 pDlg->Execute();
889 delete pDlg;
891 break;
892 case FN_TABLE_SET_ROW_HEIGHT:
894 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
895 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
897 VclAbstractDialog* pDlg = pFact->CreateVclAbstractDialog( GetView().GetWindow(), rSh, DLG_ROW_HEIGHT );
898 DBG_ASSERT(pDlg, "Dialogdiet fail!");
899 pDlg->Execute();
900 delete pDlg;
902 break;
903 case FN_NUMBER_BULLETS:
904 case FN_NUM_BULLET_ON:
905 ASSERT( !this, "Funktion darf zur Zeit nicht gerufen werden." );
906 break;
908 case FN_TABLE_INSERT_COL:
909 case FN_TABLE_INSERT_ROW:
911 BOOL bColumn = rReq.GetSlot() == FN_TABLE_INSERT_COL;
912 USHORT nCount = 0;
913 BOOL bAfter = TRUE;
914 if (pItem)
916 nCount = ((const SfxInt16Item* )pItem)->GetValue();
917 if(SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_INSERT_AFTER, TRUE, &pItem))
918 bAfter = ((const SfxBoolItem* )pItem)->GetValue();
920 else if( !rReq.IsAPI() )
921 ++nCount;
923 if( nCount )
925 // i74180: Table border patch submitted by chensuchun:
926 // -->get the SvxBoxInfoItem of the table before insert
927 SfxItemSet aCoreSet( GetPool(), aUITableAttrRange);
928 ::lcl_TableParamToItemSet( aCoreSet, rSh );
929 bool bSetInnerBorders = false;
930 SwUndoId nUndoId = UNDO_EMPTY;
931 // <--End
933 if( bColumn )
935 rSh.StartUndo( UNDO_TABLE_INSCOL );
936 rSh.InsertCol( nCount, bAfter );
937 bSetInnerBorders = true;
938 nUndoId = UNDO_TABLE_INSCOL;
940 else if ( !rSh.IsInRepeatedHeadline() )
942 rSh.StartUndo( UNDO_TABLE_INSROW );
943 rSh.InsertRow( nCount, bAfter );
944 bSetInnerBorders = true;
945 nUndoId = UNDO_TABLE_INSROW;
948 // -->after inserting,reset the inner table borders
949 if ( bSetInnerBorders )
951 const SvxBoxInfoItem aBoxInfo((const SvxBoxInfoItem&)
952 aCoreSet.Get(SID_ATTR_BORDER_INNER));
953 SfxItemSet aSet( GetPool(), SID_ATTR_BORDER_INNER,
954 SID_ATTR_BORDER_INNER, 0);
955 aSet.Put( aBoxInfo );
956 ItemSetToTableParam( aSet, rSh );
957 rSh.EndUndo( nUndoId );
959 // <--
961 bCallDone = TRUE;
962 break;
965 nSlot = bColumn ? FN_TABLE_INSERT_COL_DLG : FN_TABLE_INSERT_ROW_DLG;
967 // kein break; bei Count = 0 kommt der Dialog
968 case FN_TABLE_INSERT_COL_DLG:
969 case FN_TABLE_INSERT_ROW_DLG:
971 if ( FN_TABLE_INSERT_ROW_DLG != nSlot || !rSh.IsInRepeatedHeadline())
973 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
974 ::std::auto_ptr<SvxAbstractInsRowColDlg> pDlg( pFact ? pFact->CreateSvxInsRowColDlg( GetView().GetWindow(), nSlot == FN_TABLE_INSERT_COL_DLG, nSlot) : 0);
976 if( pDlg.get() && (pDlg->Execute() == 1) )
978 USHORT nDispatchSlot = (nSlot == FN_TABLE_INSERT_COL_DLG) ? FN_TABLE_INSERT_COL : FN_TABLE_INSERT_ROW;
979 SfxUInt16Item aCountItem( nDispatchSlot, static_cast< UINT16 >(pDlg->getInsertCount()) );
980 SfxBoolItem aAfter( FN_PARAM_INSERT_AFTER, !pDlg->isInsertBefore() );
981 SfxViewFrame* pVFrame = GetView().GetViewFrame();
982 if( pVFrame )
983 pVFrame->GetDispatcher()->Execute( nDispatchSlot, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD, &aCountItem, &aAfter, 0L);
987 break;
988 case FN_TABLE_SPLIT_CELLS:
990 long nCount=0;
991 BOOL bHorizontal=TRUE;
992 BOOL bProportional = FALSE;
993 SFX_REQUEST_ARG( rReq, pSplit, SfxInt32Item, FN_TABLE_SPLIT_CELLS, sal_False );
994 SFX_REQUEST_ARG( rReq, pHor, SfxBoolItem, FN_PARAM_1, sal_False );
995 SFX_REQUEST_ARG( rReq, pProp, SfxBoolItem, FN_PARAM_2, sal_False );
996 if ( pSplit )
998 nCount = pSplit->GetValue();
999 if ( pHor )
1000 bHorizontal = pHor->GetValue();
1001 if ( pProp )
1002 bProportional = pProp->GetValue();
1004 else
1006 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1007 if( pFact )
1009 const long nMaxVert = rSh.GetAnyCurRect( RECT_FRM ).Width() / MINLAY;
1010 SvxAbstractSplittTableDialog* pDlg = pFact->CreateSvxSplittTableDialog( GetView().GetWindow(), rSh.IsTableVertical(), nMaxVert, 99 );
1011 if( pDlg && (pDlg->Execute() == RET_OK) )
1013 nCount = pDlg->GetCount();
1014 bHorizontal = pDlg->IsHorizontal();
1015 bProportional = pDlg->IsProportional();
1016 rReq.AppendItem( SfxInt32Item( FN_TABLE_SPLIT_CELLS, nCount ) );
1017 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bHorizontal ) );
1018 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bProportional ) );
1020 delete pDlg;
1024 if ( nCount>1 )
1026 rSh.SplitTab(!bHorizontal, static_cast< USHORT >( nCount-1 ), bProportional );
1027 bCallDone = TRUE;
1029 else
1030 rReq.Ignore();
1032 break;
1034 case FN_TABLE_SPLIT_TABLE:
1036 SFX_REQUEST_ARG( rReq, pType, SfxUInt16Item, FN_PARAM_1, sal_False );
1037 if( pType )
1039 switch( pType->GetValue() )
1041 case HEADLINE_NONE :
1042 case HEADLINE_BORDERCOPY:
1043 case HEADLINE_CNTNTCOPY:
1044 case HEADLINE_BOXATTRCOPY:
1045 case HEADLINE_BOXATRCOLLCOPY:
1046 rSh.SplitTable(pType->GetValue()) ;
1047 default: ;//wrong parameter, do nothing
1050 else
1052 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1053 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
1055 AbstractSplitTableDialog* pDlg = pFact->CreateSplitTblDialog( GetView().GetWindow(), rSh );
1056 DBG_ASSERT(pDlg, "Dialogdiet fail!");
1057 pDlg->Execute();
1058 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, pDlg->GetSplitMode() ) );
1059 delete pDlg;
1060 bCallDone = sal_True;
1063 break;
1065 case FN_TABLE_MERGE_TABLE:
1067 BOOL bPrev = rSh.CanMergeTable( TRUE );
1068 BOOL bNext = rSh.CanMergeTable( FALSE );
1070 if( bPrev && bNext )
1072 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1073 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
1074 VclAbstractDialog* pDlg = pFact->CreateSwVclDialog( DLG_MERGE_TABLE, GetView().GetWindow(), bPrev );
1075 DBG_ASSERT(pDlg, "dialogdiet pDlg fail!");
1076 if( RET_OK != pDlg->Execute())
1077 bPrev = bNext = FALSE;
1078 delete pDlg;
1081 if( bPrev || bNext )
1082 rSh.MergeTable( bPrev );
1084 break;
1086 case FN_TABLE_MODE_FIX :
1087 case FN_TABLE_MODE_FIX_PROP :
1088 case FN_TABLE_MODE_VARIABLE :
1090 rSh.SetTblChgMode( ( FN_TABLE_MODE_FIX == nSlot ? TBLFIX_CHGABS
1091 : FN_TABLE_MODE_FIX_PROP == nSlot
1092 ? TBLFIX_CHGPROP
1093 : TBLVAR_CHGABS ) );
1095 SfxBindings& rBind = GetView().GetViewFrame()->GetBindings();
1096 static USHORT __READONLY_DATA aInva[] =
1097 { FN_TABLE_MODE_FIX,
1098 FN_TABLE_MODE_FIX_PROP,
1099 FN_TABLE_MODE_VARIABLE,
1102 rBind.Invalidate( aInva );
1103 bCallDone = TRUE;
1105 break;
1106 case FN_TABLE_AUTOSUM:
1108 SfxViewFrame* pVFrame = GetView().GetViewFrame();
1109 pVFrame->GetDispatcher()->Execute(FN_EDIT_FORMULA, SFX_CALLMODE_SYNCHRON);
1110 const USHORT nId = SwInputChild::GetChildWindowId();
1111 SwInputChild* pChildWin = (SwInputChild*)pVFrame->
1112 GetChildWindow( nId );
1113 String sSum;
1114 GetShell().GetAutoSum(sSum);
1115 if( pChildWin )
1116 pChildWin->SetFormula( sSum );
1119 break;
1120 case FN_TABLE_HEADLINE_REPEAT:
1121 if(0 != rSh.GetRowsToRepeat())
1122 rSh.SetRowsToRepeat( 0 );
1123 else
1124 rSh.SetRowsToRepeat(rSh.GetRowSelectionFromTop());
1125 break;
1126 case FN_TABLE_SELECT_CELL :
1127 rSh.SelectTableCell();
1128 break;
1129 case FN_TABLE_DELETE_TABLE :
1131 rSh.StartAction();
1132 rSh.StartUndo();
1133 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(FN_TABLE_SELECT_ALL);
1134 rSh.DeleteRow();
1135 rSh.EndUndo();
1136 rSh.EndAction();
1138 //'this' is already destroyed
1139 return;
1140 //break;
1141 default:
1142 bMore = TRUE;
1145 if ( !bMore )
1147 if(bCallDone)
1148 rReq.Done();
1149 return;
1151 else
1152 bMore = FALSE;
1153 //Jetzt die Slots, die direkt auf dem TableFmt arbeiten.
1154 SwFrmFmt *pFmt = rSh.GetTableFmt();
1155 switch ( nSlot )
1157 case SID_ATTR_ULSPACE:
1159 if(pItem)
1161 SvxULSpaceItem aULSpace( *(const SvxULSpaceItem*)pItem );
1162 aULSpace.SetWhich( RES_UL_SPACE );
1163 ::lcl_SetAttr( rSh, aULSpace );
1166 break;
1168 case SID_ATTR_LRSPACE:
1170 if(pItem)
1172 SfxItemSet aSet( GetPool(), RES_LR_SPACE, RES_LR_SPACE,
1173 RES_HORI_ORIENT, RES_HORI_ORIENT, 0 );
1174 SvxLRSpaceItem aLRSpace( *(const SvxLRSpaceItem*)pItem );
1175 aLRSpace.SetWhich( RES_LR_SPACE );
1176 aSet.Put( aLRSpace );
1177 SwFmtHoriOrient aHori( pFmt->GetHoriOrient() );
1178 aHori.SetHoriOrient( text::HoriOrientation::NONE );
1179 aSet.Put( aLRSpace );
1180 rSh.SetTblAttr( aSet );
1183 break;
1184 // der letzte case-Zweig der noch einen TabellenManager braucht!!
1185 case FN_TABLE_SET_COL_WIDTH:
1187 SwTableFUNC aMgr( &rSh, FALSE);
1188 aMgr.ColWidthDlg(GetView().GetWindow());
1190 break;
1191 case FN_TABLE_VERT_NONE:
1192 case FN_TABLE_VERT_CENTER:
1193 case FN_TABLE_VERT_BOTTOM:
1195 USHORT nAlign = nSlot == FN_TABLE_VERT_NONE ?
1196 text::VertOrientation::NONE :
1197 nSlot == FN_TABLE_VERT_CENTER ?
1198 text::VertOrientation::CENTER : text::VertOrientation::BOTTOM;
1199 rSh.SetBoxAlign(nAlign);
1200 bCallDone = TRUE;
1202 break;
1204 case SID_ATTR_PARA_SPLIT:
1205 if ( pItem )
1207 SwFmtLayoutSplit aSplit( ((const SvxFmtSplitItem*)pItem)->GetValue());
1208 SfxItemSet aSet(GetPool(), RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT, 0 );
1209 aSet.Put(aSplit);
1210 rSh.SetTblAttr(aSet);
1212 break;
1214 case SID_ATTR_PARA_KEEP:
1215 if ( pItem )
1217 SvxFmtKeepItem aKeep( *(const SvxFmtKeepItem*)pItem );
1218 aKeep.SetWhich( RES_KEEP );
1219 SfxItemSet aSet(GetPool(), RES_KEEP, RES_KEEP, 0 );
1220 aSet.Put(aKeep);
1221 rSh.SetTblAttr(aSet);
1223 break;
1224 case FN_TABLE_ROW_SPLIT :
1226 const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(pItem);
1227 SwFmtRowSplit* pSplit = 0;
1228 if(!pBool)
1230 rSh.GetRowSplit(pSplit);
1231 if(pSplit)
1232 pSplit->SetValue(!pSplit->GetValue());
1233 else
1234 pSplit = new SwFmtRowSplit(TRUE);
1236 else
1238 pSplit = new SwFmtRowSplit(pBool->GetValue());
1240 rSh.SetRowSplit( *pSplit );
1241 delete pSplit;
1243 break;
1245 default:
1246 ASSERT( !this, "falscher Dispatcher" );
1247 return;
1249 if(bCallDone)
1250 rReq.Done();
1252 /*--------------------------------------------------------------------
1253 Beschreibung:
1254 --------------------------------------------------------------------*/
1256 void SwTableShell::GetState(SfxItemSet &rSet)
1258 SfxWhichIter aIter( rSet );
1259 SwWrtShell &rSh = GetShell();
1260 SwFrmFmt *pFmt = rSh.GetTableFmt();
1261 // os #124829# crash report: in case of an invalid shell selection return immediately
1262 if(!pFmt)
1263 return;
1264 USHORT nSlot = aIter.FirstWhich();
1265 while ( nSlot )
1267 switch ( nSlot )
1269 case FN_TABLE_MERGE_CELLS:
1270 if ( !rSh.IsTableMode() )
1271 rSet.DisableItem(FN_TABLE_MERGE_CELLS);
1272 break;
1273 case FN_TABLE_ADJUST_CELLS:
1274 if ( !rSh.IsAdjustCellWidthAllowed() )
1275 rSet.DisableItem(FN_TABLE_ADJUST_CELLS);
1276 break;
1278 case FN_TABLE_BALANCE_CELLS:
1279 if ( !rSh.IsAdjustCellWidthAllowed(TRUE) )
1280 rSet.DisableItem(FN_TABLE_BALANCE_CELLS);
1281 break;
1283 case FN_TABLE_BALANCE_ROWS:
1284 if ( !rSh.BalanceRowHeight(TRUE) )
1285 rSet.DisableItem(FN_TABLE_BALANCE_ROWS);
1286 break;
1287 case FN_OPTIMIZE_TABLE:
1288 if ( !rSh.IsTableMode() &&
1289 !rSh.IsAdjustCellWidthAllowed() &&
1290 !rSh.IsAdjustCellWidthAllowed(TRUE) &&
1291 !rSh.BalanceRowHeight(TRUE) )
1292 rSet.DisableItem(FN_OPTIMIZE_TABLE);
1293 break;
1294 case SID_INSERT_DIAGRAM:
1296 SvtModuleOptions aMOpt;
1297 if ( !aMOpt.IsMath() || rSh.IsTblComplexForChart() )
1298 rSet.DisableItem(nSlot);
1300 break;
1302 case FN_INSERT_TABLE:
1303 // Irgendeinen Wert "putten", damit Controller enabled bleibt.
1304 // Statt "Insert:Table" erscheint dann "Format:Table".
1305 // rSet.Put(SfxUInt16Item(nSlot, 1));
1306 break;
1308 case FN_TABLE_OPTIMAL_HEIGHT:
1310 //Disablen wenn bereits auto-Hoehe eingestellt ist.
1311 SwFmtFrmSize *pSz;
1312 rSh.GetRowHeight( pSz );
1313 if ( pSz )
1315 if ( ATT_VAR_SIZE == pSz->GetHeightSizeType() )
1316 rSet.DisableItem( nSlot );
1317 delete pSz;
1320 break;
1321 case FN_TABLE_INSERT_ROW:
1322 case FN_TABLE_INSERT_ROW_DLG:
1324 if ( rSh.IsInRepeatedHeadline() )
1325 rSet.DisableItem( nSlot );
1327 break;
1328 case RES_LR_SPACE:
1329 rSet.Put(pFmt->GetLRSpace());
1330 break;
1331 case RES_UL_SPACE:
1332 rSet.Put(pFmt->GetULSpace());
1333 break;
1334 case FN_TABLE_VERT_NONE:
1335 case FN_TABLE_VERT_CENTER:
1336 case FN_TABLE_VERT_BOTTOM:
1338 USHORT nAlign = rSh.GetBoxAlign();
1339 BOOL bSet = nSlot == FN_TABLE_VERT_NONE && nAlign == text::VertOrientation::NONE||
1340 nSlot == FN_TABLE_VERT_CENTER && nAlign == text::VertOrientation::CENTER ||
1341 nSlot == FN_TABLE_VERT_BOTTOM && nAlign == text::VertOrientation::BOTTOM;
1342 rSet.Put(SfxBoolItem(nSlot, bSet));
1344 break;
1346 case FN_TABLE_MODE_FIX :
1347 case FN_TABLE_MODE_FIX_PROP :
1348 case FN_TABLE_MODE_VARIABLE :
1350 TblChgMode nMode = rSh.GetTblChgMode();
1351 BOOL bSet = nSlot == FN_TABLE_MODE_FIX && nMode == TBLFIX_CHGABS ||
1352 nSlot == FN_TABLE_MODE_FIX_PROP && nMode == TBLFIX_CHGPROP ||
1353 nSlot == FN_TABLE_MODE_VARIABLE && nMode == TBLVAR_CHGABS;
1354 rSet.Put(SfxBoolItem(nSlot, bSet));
1356 break;
1358 case SID_ATTR_PARA_SPLIT:
1359 rSet.Put( pFmt->GetKeep() );
1360 break;
1362 case SID_ATTR_PARA_KEEP:
1363 rSet.Put( pFmt->GetLayoutSplit() );
1364 break;
1365 case FN_TABLE_SPLIT_TABLE:
1367 if ( rSh.IsInHeadline() )
1368 rSet.DisableItem( nSlot );
1370 break;
1371 case FN_TABLE_MERGE_TABLE:
1373 BOOL bAsk;
1374 if( !rSh.CanMergeTable( TRUE, &bAsk ))
1375 rSet.DisableItem( nSlot );
1377 break;
1379 case FN_TABLE_DELETE_ROW:
1381 SwSelBoxes aBoxes;
1382 ::GetTblSel( rSh, aBoxes, nsSwTblSearchType::TBLSEARCH_ROW );
1383 if( ::HasProtectedCells( aBoxes ))
1384 rSet.DisableItem( nSlot );
1386 break;
1387 case FN_TABLE_DELETE_COL:
1389 SwSelBoxes aBoxes;
1390 ::GetTblSel( rSh, aBoxes, nsSwTblSearchType::TBLSEARCH_COL );
1391 if( ::HasProtectedCells( aBoxes ))
1392 rSet.DisableItem( nSlot );
1394 break;
1396 case FN_TABLE_UNSET_READ_ONLY_CELLS:
1397 // disable in readonly sections, but enable in protected cells
1398 if( !rSh.CanUnProtectCells() )
1399 rSet.DisableItem( nSlot );
1400 break;
1401 case RES_ROW_SPLIT:
1403 const SwFmtLayoutSplit& rTabSplit = pFmt->GetLayoutSplit();
1404 if ( 0 == rTabSplit.GetValue() )
1406 rSet.DisableItem( nSlot );
1408 else
1410 SwFmtRowSplit* pSplit = 0;
1411 rSh.GetRowSplit(pSplit);
1412 if(pSplit)
1413 rSet.Put(*pSplit);
1414 else
1415 rSet.InvalidateItem( nSlot );
1416 delete pSplit;
1419 break;
1420 case FN_TABLE_HEADLINE_REPEAT:
1421 if(0 != rSh.GetRowsToRepeat())
1422 rSet.Put(SfxBoolItem(nSlot, sal_True));
1423 else if(!rSh.GetRowSelectionFromTop())
1424 rSet.DisableItem( nSlot );
1425 else
1426 rSet.Put(SfxBoolItem(nSlot, sal_False));
1427 break;
1428 case FN_TABLE_SELECT_CELL :
1429 if(rSh.HasBoxSelection())
1430 rSet.DisableItem( nSlot );
1431 break;
1433 nSlot = aIter.NextWhich();
1437 /*--------------------------------------------------------------------
1438 Beschreibung:
1439 --------------------------------------------------------------------*/
1441 SwTableShell::SwTableShell(SwView &_rView) :
1442 SwBaseShell(_rView)
1444 SetName(String::CreateFromAscii("Table"));
1445 SetHelpId(SW_TABSHELL);
1448 /*--------------------------------------------------------------------
1449 Beschreibung:
1450 --------------------------------------------------------------------*/
1452 void SwTableShell::GetFrmBorderState(SfxItemSet &rSet)
1454 SfxItemSet aCoreSet( GetPool(),
1455 RES_BOX, RES_BOX,
1456 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER, 0 );
1457 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
1458 aCoreSet.Put( aBoxInfo );
1459 GetShell().GetTabBorders( aCoreSet );
1460 rSet.Put( aCoreSet );
1463 /*--------------------------------------------------------------------
1464 Beschreibung:
1465 --------------------------------------------------------------------*/
1467 void SwTableShell::ExecTableStyle(SfxRequest& rReq)
1469 SwWrtShell &rSh = GetShell();
1470 const SfxItemSet *pArgs = rReq.GetArgs();
1471 if(pArgs)
1472 switch ( rReq.GetSlot() )
1474 case SID_FRAME_LINESTYLE:
1475 case SID_FRAME_LINECOLOR:
1477 /* Tabellenselektion ist abgeschafft
1478 BOOL bPopCrsr = FALSE;
1479 if ( !rReq.IsAPI() )
1481 //Keine Tabellenselektion -> Aenderung wird auf die gesamte
1482 //Tabelle.
1483 if ( !rSh.IsTableMode() )
1485 bPopCrsr = TRUE;
1486 rSh.Push();
1487 rSh.StartAction();
1488 rSh.EnterStdMode();
1489 rSh.MoveTable( fnTableCurr, fnTableStart );
1490 rSh.SttSelect();
1491 rSh.MoveTable( fnTableCurr, fnTableEnd );
1492 rSh.EndSelect();
1495 if ( rReq.GetSlot() == SID_FRAME_LINESTYLE )
1497 const SvxLineItem &rLineItem = (const SvxLineItem&)pArgs->
1498 Get( SID_FRAME_LINESTYLE );
1499 const SvxBorderLine* pBorderLine = rLineItem.GetLine();
1500 rSh.SetTabLineStyle( 0, TRUE, pBorderLine);
1502 else
1504 const SvxColorItem &rNewColorItem = (const SvxColorItem&)pArgs->
1505 Get( SID_FRAME_LINECOLOR );
1506 rSh.SetTabLineStyle( &rNewColorItem.GetValue() );
1509 rReq.Done();
1510 /* if ( bPopCrsr )
1512 rSh.KillPams();
1513 rSh.Pop(FALSE);
1514 rSh.EndAction();
1516 break;
1522 void SwTableShell::GetLineStyleState(SfxItemSet &rSet)
1524 SfxItemSet aCoreSet( GetPool(),
1525 RES_BOX, RES_BOX,
1526 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER, 0);
1527 SvxBoxInfoItem aCoreInfo( SID_ATTR_BORDER_INNER );
1528 aCoreSet.Put(aCoreInfo);
1529 GetShell().GetTabBorders( aCoreSet );
1531 const SvxBoxItem& rBoxItem = (const SvxBoxItem&)aCoreSet.Get( RES_BOX );
1532 const SvxBorderLine* pLine = rBoxItem.GetTop();
1534 rSet.Put( SvxColorItem( pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLOR ) );
1535 SvxLineItem aLine( SID_FRAME_LINESTYLE );
1536 aLine.SetLine(pLine);
1537 rSet.Put( aLine );
1540 void SwTableShell::ExecNumberFormat(SfxRequest& rReq)
1542 const SfxItemSet* pArgs = rReq.GetArgs();
1543 SwWrtShell &rSh = GetShell();
1545 //Erstmal die Slots, die keinen FrmMgr benoetigen.
1546 const SfxPoolItem* pItem = 0;
1547 USHORT nSlot = rReq.GetSlot();
1548 if(pArgs)
1549 pArgs->GetItemState(GetPool().GetWhich(nSlot), FALSE, &pItem);
1551 // Sprache immer von Cursorposition besorgen
1552 LanguageType eLang = rSh.GetCurLang();
1553 SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
1554 sal_uInt32 nNumberFormat = NUMBERFORMAT_ENTRY_NOT_FOUND;
1555 USHORT nFmtType = 0, nOffset = 0;
1557 switch ( nSlot )
1559 case FN_NUMBER_FORMAT:
1560 if( pItem )
1562 // Index fuer String bestimmen
1563 String aCode( ((const SfxStringItem*)pItem)->GetValue() );
1564 nNumberFormat = pFormatter->GetEntryKey( aCode, eLang );
1565 if( NUMBERFORMAT_ENTRY_NOT_FOUND == nNumberFormat )
1567 // neu eintragen
1568 xub_StrLen nErrPos;
1569 short nType;
1570 if( !pFormatter->PutEntry( aCode, nErrPos, nType,
1571 nNumberFormat, eLang ))
1572 nNumberFormat = NUMBERFORMAT_ENTRY_NOT_FOUND;
1575 break;
1576 case FN_NUMBER_STANDARD: nFmtType = NUMBERFORMAT_NUMBER; break;
1577 case FN_NUMBER_SCIENTIFIC: nFmtType = NUMBERFORMAT_SCIENTIFIC; break;
1578 case FN_NUMBER_DATE: nFmtType = NUMBERFORMAT_DATE; break;
1579 case FN_NUMBER_TIME: nFmtType = NUMBERFORMAT_TIME; break;
1580 case FN_NUMBER_CURRENCY: nFmtType = NUMBERFORMAT_CURRENCY; break;
1581 case FN_NUMBER_PERCENT: nFmtType = NUMBERFORMAT_PERCENT; break;
1583 case FN_NUMBER_TWODEC: // #.##0,00
1584 nFmtType = NUMBERFORMAT_NUMBER;
1585 nOffset = NF_NUMBER_1000DEC2;
1586 break;
1588 default:
1589 ASSERT(FALSE, falscher Dispatcher);
1590 return;
1593 if( nFmtType )
1594 nNumberFormat = pFormatter->GetStandardFormat( nFmtType, eLang ) + nOffset;
1596 if( NUMBERFORMAT_ENTRY_NOT_FOUND != nNumberFormat )
1598 SfxItemSet aBoxSet( GetPool(), RES_BOXATR_FORMAT, RES_BOXATR_FORMAT );
1599 aBoxSet.Put( SwTblBoxNumFormat( nNumberFormat ));
1600 rSh.SetTblBoxFormulaAttrs( aBoxSet );