bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / table / tabledlg.cxx
blobe833ba80676a304ed6c8bb85e6ed6678da60d8a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <hintids.hxx>
21 #include <comphelper/string.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <svl/stritem.hxx>
24 #include <svl/intitem.hxx>
25 #include <editeng/keepitem.hxx>
26 #include <editeng/formatbreakitem.hxx>
27 #include <editeng/ulspitem.hxx>
28 #include <editeng/frmdiritem.hxx>
29 #include <svl/ctloptions.hxx>
30 #include <swmodule.hxx>
31 #include <fmtornt.hxx>
32 #include <fmtpdsc.hxx>
33 #include <fmtlsplt.hxx>
35 #include <svtools/htmlcfg.hxx>
36 #include <fmtrowsplt.hxx>
37 #include <sfx2/htmlmode.hxx>
39 #include "access.hrc"
41 #include <docsh.hxx>
42 #include <wrtsh.hxx>
43 #include <view.hxx>
44 #include <viewopt.hxx>
45 #include <uitool.hxx>
46 #include <frmatr.hxx>
47 #include <tabledlg.hxx>
48 #include <tablepg.hxx>
49 #include <tablemgr.hxx>
50 #include <pagedesc.hxx>
51 #include <uiitems.hxx>
52 #include <poolfmt.hxx>
53 #include <SwStyleNameMapper.hxx>
55 #include <cmdid.h>
56 #include <table.hrc>
57 #include <svx/svxids.hrc>
58 #include <svx/dialogs.hrc>
59 #include <svx/flagsdef.hxx>
60 #include <svx/svxdlg.hxx>
62 using namespace ::com::sun::star;
65 SwFormatTablePage::SwFormatTablePage(Window* pParent, const SfxItemSet& rSet)
66 : SfxTabPage(pParent, "FormatTablePage", "modules/swriter/ui/formattablepage.ui", rSet)
67 , pTblData(0)
68 , nSaveWidth(0)
69 , nMinTableWidth(MINLAY)
70 , bModified(sal_False)
71 , bFull(0)
72 , bHtmlMode(sal_False)
74 get(m_pNameED, "name");
75 get(m_pWidthFT, "widthft");
76 m_aWidthMF.set(get<MetricField>("widthmf"));
77 m_aLeftMF.set(get<MetricField>("leftmf"));
78 m_aRightMF.set(get<MetricField>("rightmf"));
79 get(m_pRelWidthCB, "relwidth");
80 get(m_pFullBtn, "full");
81 get(m_pLeftBtn, "left");
82 get(m_pFromLeftBtn, "fromleft");
83 get(m_pRightBtn, "right");
84 get(m_pCenterBtn, "center");
85 get(m_pFreeBtn, "free");
86 get(m_pLeftFT, "leftft");
87 get(m_pRightFT, "rightft");
88 get(m_pTopFT, "aboveft");
89 get(m_pTopMF, "abovemf");
90 get(m_pBottomFT, "belowft");
91 get(m_pBottomMF, "belowmf");
92 get(m_pTextDirectionLB, "textdirection");
94 SetExchangeSupport();
96 const SfxPoolItem* pItem;
97 if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, sal_False, &pItem))
98 bHtmlMode = 0 != (((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON);
100 bool bCTL = SW_MOD()->GetCTLOptions().IsCTLFontEnabled();
101 get<VclContainer>("properties")->Show(!bHtmlMode && bCTL);
103 Init();
107 void SwFormatTablePage::Init()
109 m_aLeftMF.SetMetricFieldMin(-999999);
110 m_aRightMF.SetMetricFieldMin(-999999);
112 // handler
113 Link aLk = LINK( this, SwFormatTablePage, AutoClickHdl );
114 m_pFullBtn->SetClickHdl( aLk );
115 m_pFreeBtn->SetClickHdl( aLk );
116 m_pLeftBtn->SetClickHdl( aLk );
117 m_pFromLeftBtn->SetClickHdl( aLk );
118 m_pRightBtn->SetClickHdl( aLk );
119 m_pCenterBtn->SetClickHdl( aLk );
121 aLk = LINK( this, SwFormatTablePage, UpDownLoseFocusHdl );
122 m_pTopMF->SetUpHdl( aLk );
123 m_pBottomMF->SetUpHdl( aLk );
124 m_aRightMF.SetUpHdl( aLk );
125 m_aLeftMF.SetUpHdl( aLk );
126 m_aWidthMF.SetUpHdl( aLk );
128 m_pTopMF->SetDownHdl( aLk );
129 m_pBottomMF->SetDownHdl( aLk );
130 m_aRightMF.SetDownHdl( aLk );
131 m_aLeftMF.SetDownHdl( aLk );
132 m_aWidthMF.SetDownHdl( aLk );
134 m_pTopMF->SetLoseFocusHdl( aLk );
135 m_pBottomMF->SetLoseFocusHdl( aLk );
136 m_aRightMF.SetLoseFocusHdl( aLk );
137 m_aLeftMF.SetLoseFocusHdl( aLk );
138 m_aWidthMF.SetLoseFocusHdl( aLk );
140 m_pRelWidthCB->SetClickHdl(LINK( this, SwFormatTablePage, RelWidthClickHdl ));
143 IMPL_LINK( SwFormatTablePage, RelWidthClickHdl, CheckBox *, pBtn )
145 OSL_ENSURE(pTblData, "table data not available?");
146 sal_Bool bIsChecked = pBtn->IsChecked();
147 sal_Int64 nLeft = m_aLeftMF.DenormalizePercent(m_aLeftMF.GetValue(FUNIT_TWIP ));
148 sal_Int64 nRight = m_aRightMF.DenormalizePercent(m_aRightMF.GetValue(FUNIT_TWIP ));
149 m_aWidthMF.ShowPercent(bIsChecked);
150 m_aLeftMF.ShowPercent(bIsChecked);
151 m_aRightMF.ShowPercent(bIsChecked);
153 if (bIsChecked)
155 m_aWidthMF.SetRefValue(pTblData->GetSpace());
156 m_aLeftMF.SetRefValue(pTblData->GetSpace());
157 m_aRightMF.SetRefValue(pTblData->GetSpace());
158 m_aLeftMF.SetMetricFieldMin(0); // will be overwritten by the Percentfield
159 m_aRightMF.SetMetricFieldMin(0); // -""-
160 m_aLeftMF.SetMetricFieldMax(99); //
161 m_aRightMF.SetMetricFieldMax(99); //
162 m_aLeftMF.SetPrcntValue(m_aLeftMF.NormalizePercent(nLeft ), FUNIT_TWIP );
163 m_aRightMF.SetPrcntValue(m_aRightMF.NormalizePercent(nRight ), FUNIT_TWIP );
165 else
166 ModifyHdl(m_aLeftMF.get()); // correct values again
168 if(m_pFreeBtn->IsChecked())
170 sal_Bool bEnable = !pBtn->IsChecked();
171 m_aRightMF.Enable(bEnable);
172 m_pRightFT->Enable(bEnable);
174 bModified = sal_True;
176 return 0;
180 IMPL_LINK( SwFormatTablePage, AutoClickHdl, CheckBox *, pBox )
182 sal_Bool bRestore = sal_True,
183 bLeftEnable = sal_False,
184 bRightEnable= sal_False,
185 bWidthEnable= sal_False,
186 bOthers = sal_True;
187 if ((RadioButton *)pBox == m_pFullBtn)
189 m_aLeftMF.SetPrcntValue(0);
190 m_aRightMF.SetPrcntValue(0);
191 nSaveWidth = static_cast< SwTwips >(m_aWidthMF.DenormalizePercent(m_aWidthMF.GetValue(FUNIT_TWIP )));
192 m_aWidthMF.SetPrcntValue(m_aWidthMF.NormalizePercent(pTblData->GetSpace() ), FUNIT_TWIP );
193 bFull = sal_True;
194 bRestore = sal_False;
196 else if ((RadioButton *)pBox == m_pLeftBtn)
198 bRightEnable = bWidthEnable = sal_True;
199 m_aLeftMF.SetPrcntValue(0);
201 else if ((RadioButton *) pBox == m_pFromLeftBtn)
203 bLeftEnable = bWidthEnable = sal_True;
204 m_aRightMF.SetPrcntValue(0);
206 else if ((RadioButton *) pBox == m_pRightBtn)
208 bLeftEnable = bWidthEnable = sal_True;
209 m_aRightMF.SetPrcntValue(0);
211 else if ((RadioButton *) pBox == m_pCenterBtn)
213 bLeftEnable = bWidthEnable = sal_True;
215 else if ((RadioButton *) pBox == m_pFreeBtn)
217 RightModify();
218 bLeftEnable = sal_True;
219 bWidthEnable = sal_True;
220 bOthers = sal_False;
222 m_aLeftMF.Enable(bLeftEnable);
223 m_pLeftFT->Enable(bLeftEnable);
224 m_aWidthMF.Enable(bWidthEnable);
225 m_pWidthFT->Enable(bWidthEnable);
226 if ( bOthers )
228 m_aRightMF.Enable(bRightEnable);
229 m_pRightFT->Enable(bRightEnable);
230 m_pRelWidthCB->Enable(bWidthEnable);
233 if(bFull && bRestore)
235 // After being switched on automatic, the width was pinned
236 // in order to restore the width while switching back to.
237 bFull = sal_False;
238 m_aWidthMF.SetPrcntValue(m_aWidthMF.NormalizePercent(nSaveWidth ), FUNIT_TWIP );
240 ModifyHdl(m_aWidthMF.get());
241 bModified = sal_True;
242 return 0;
245 void SwFormatTablePage::RightModify()
247 if(m_pFreeBtn->IsChecked())
249 sal_Bool bEnable = m_aRightMF.GetValue() == 0;
250 m_pRelWidthCB->Enable(bEnable);
251 if ( !bEnable )
253 m_pRelWidthCB->Check(sal_False);
254 RelWidthClickHdl(m_pRelWidthCB);
256 bEnable = m_pRelWidthCB->IsChecked();
257 m_aRightMF.Enable(!bEnable);
258 m_pRightFT->Enable(!bEnable);
263 IMPL_LINK_INLINE_START( SwFormatTablePage, UpDownLoseFocusHdl, MetricField *, pEdit )
265 if( m_aRightMF.get() == pEdit)
266 RightModify();
267 ModifyHdl( pEdit );
268 return 0;
270 IMPL_LINK_INLINE_END( SwFormatTablePage, UpDownLoseFocusHdl, MetricField *, pEdit )
272 void SwFormatTablePage::ModifyHdl(const Edit * pEdit)
275 SwTwips nCurWidth = static_cast< SwTwips >(m_aWidthMF.DenormalizePercent(m_aWidthMF.GetValue( FUNIT_TWIP )));
276 SwTwips nPrevWidth = nCurWidth;
277 SwTwips nRight = static_cast< SwTwips >(m_aRightMF.DenormalizePercent(m_aRightMF.GetValue( FUNIT_TWIP )));
278 SwTwips nLeft = static_cast< SwTwips >(m_aLeftMF.DenormalizePercent(m_aLeftMF.GetValue( FUNIT_TWIP )));
279 SwTwips nDiff;
281 if (pEdit == m_aWidthMF.get())
283 if( nCurWidth < MINLAY )
284 nCurWidth = MINLAY;
285 nDiff = nRight + nLeft + nCurWidth - pTblData->GetSpace() ;
286 //right aligned: only change the left margin
287 if(m_pRightBtn->IsChecked())
288 nLeft -= nDiff;
289 //left aligned: only change the right margin
290 else if(m_pLeftBtn->IsChecked())
291 nRight -= nDiff;
292 //left margin and width allowed - first right - then left
293 else if(m_pFromLeftBtn->IsChecked())
295 if( nRight >= nDiff )
296 nRight -= nDiff;
297 else
299 nDiff -= nRight;
300 nRight = 0;
301 if(nLeft >= nDiff)
302 nLeft -= nDiff;
303 else
305 nRight += nLeft - nDiff;
306 nLeft = 0;
307 nCurWidth = pTblData->GetSpace();
312 //centered: change both sides equally
313 else if(m_pCenterBtn->IsChecked())
315 if((nLeft != nRight))
317 nDiff += nLeft + nRight;
318 nLeft = nDiff/2;
319 nRight = nDiff/2;
321 else
323 nLeft -= nDiff/2;
324 nRight -= nDiff/2;
327 //free alignment: decrease both margins
328 else if(m_pFreeBtn->IsChecked())
330 nLeft -= nDiff/2;
331 nRight -= nDiff/2;
334 if (pEdit == m_aRightMF.get())
337 if( nRight + nLeft > pTblData->GetSpace() - MINLAY )
338 nRight = pTblData->GetSpace() -nLeft - MINLAY;
340 nCurWidth = pTblData->GetSpace() - nLeft - nRight;
342 if (pEdit == m_aLeftMF.get())
344 if(!m_pFromLeftBtn->IsChecked())
346 sal_Bool bCenter = m_pCenterBtn->IsChecked();
347 if( bCenter )
348 nRight = nLeft;
349 if(nRight + nLeft > pTblData->GetSpace() - MINLAY )
351 nLeft = bCenter ? (pTblData->GetSpace() - MINLAY) /2 :
352 (pTblData->GetSpace() - MINLAY) - nRight;
353 nRight = bCenter ? (pTblData->GetSpace() - MINLAY) /2 : nRight;
355 nCurWidth = pTblData->GetSpace() - nLeft - nRight;
357 else
359 //Upon changes on the left side the right margin will be changed at first,
360 //thereafter the width.
361 nDiff = nRight + nLeft + nCurWidth - pTblData->GetSpace() ;
363 nRight -= nDiff;
364 nCurWidth = pTblData->GetSpace() - nLeft - nRight;
367 if (nCurWidth != nPrevWidth )
368 m_aWidthMF.SetPrcntValue( m_aWidthMF.NormalizePercent( nCurWidth ), FUNIT_TWIP );
369 m_aRightMF.SetPrcntValue( m_aRightMF.NormalizePercent( nRight ), FUNIT_TWIP );
370 m_aLeftMF.SetPrcntValue( m_aLeftMF.NormalizePercent( nLeft ), FUNIT_TWIP );
371 bModified = sal_True;
375 SfxTabPage* SwFormatTablePage::Create( Window* pParent,
376 const SfxItemSet& rAttrSet)
378 return new SwFormatTablePage( pParent, rAttrSet );
382 sal_Bool SwFormatTablePage::FillItemSet( SfxItemSet& rCoreSet )
384 // Test if one of the controls still has the focus.
385 if (m_aWidthMF.HasFocus())
386 ModifyHdl(m_aWidthMF.get());
387 else if (m_aLeftMF.HasFocus())
388 ModifyHdl(m_aLeftMF.get());
389 else if(m_aRightMF.HasFocus())
390 ModifyHdl(m_aRightMF.get());
391 else if(m_pTopMF->HasFocus())
392 ModifyHdl(m_pTopMF);
393 else if(m_pBottomMF->HasFocus())
394 ModifyHdl(m_pBottomMF);
396 if(bModified)
398 if( m_pBottomMF->GetText() != m_pBottomMF->GetSavedValue() ||
399 m_pTopMF->GetText() != m_pTopMF->GetSavedValue() )
401 SvxULSpaceItem aULSpace(RES_UL_SPACE);
402 aULSpace.SetUpper( (sal_uInt16) m_pTopMF->Denormalize(
403 m_pTopMF->GetValue( FUNIT_TWIP )));
404 aULSpace.SetLower( (sal_uInt16) m_pBottomMF->Denormalize(
405 m_pBottomMF->GetValue( FUNIT_TWIP )));
406 rCoreSet.Put(aULSpace);
410 if(m_pNameED->GetText() != m_pNameED->GetSavedValue())
412 rCoreSet.Put(SfxStringItem( FN_PARAM_TABLE_NAME, m_pNameED->GetText()));
413 bModified = sal_True;
416 sal_uInt16 nPos;
417 if( m_pTextDirectionLB->IsVisible() &&
418 ( nPos = m_pTextDirectionLB->GetSelectEntryPos() ) !=
419 m_pTextDirectionLB->GetSavedValue() )
421 sal_uInt32 nDirection = (sal_uInt32)(sal_uIntPtr)m_pTextDirectionLB->GetEntryData( nPos );
422 rCoreSet.Put( SvxFrameDirectionItem( (SvxFrameDirection)nDirection, RES_FRAMEDIR));
423 bModified = sal_True;
426 return bModified;
430 void SwFormatTablePage::Reset( const SfxItemSet& )
432 const SfxItemSet& rSet = GetItemSet();
433 const SfxPoolItem* pItem;
435 if(bHtmlMode)
437 m_pNameED->Disable();
438 m_pTopFT->Hide();
439 m_pTopMF->Hide();
440 m_pBottomFT->Hide();
441 m_pBottomMF->Hide();
442 m_pFreeBtn->Enable(sal_False);
444 FieldUnit aMetric = ::GetDfltMetric(bHtmlMode);
445 m_aWidthMF.SetMetric(aMetric);
446 m_aRightMF.SetMetric(aMetric);
447 m_aLeftMF.SetMetric(aMetric);
448 SetMetric(*m_pTopMF, aMetric);
449 SetMetric(*m_pBottomMF, aMetric);
451 //Name
452 if(SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_NAME, sal_False, &pItem ))
454 m_pNameED->SetText(((const SfxStringItem*)pItem)->GetValue());
455 m_pNameED->SaveValue();
458 if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP, sal_False, &pItem ))
460 pTblData = (SwTableRep*)((const SwPtrItem*) pItem)->GetValue();
461 nMinTableWidth = pTblData->GetColCount() * MINLAY;
463 if(pTblData->GetWidthPercent())
465 m_pRelWidthCB->Check(sal_True);
466 RelWidthClickHdl(m_pRelWidthCB);
467 m_aWidthMF.SetPrcntValue(pTblData->GetWidthPercent(), FUNIT_CUSTOM);
469 m_aWidthMF.SaveValue();
470 nSaveWidth = static_cast< SwTwips >(m_aWidthMF.GetValue(FUNIT_CUSTOM));
472 else
474 m_aWidthMF.SetPrcntValue(m_aWidthMF.NormalizePercent(
475 pTblData->GetWidth()), FUNIT_TWIP);
476 m_aWidthMF.SaveValue();
477 nSaveWidth = pTblData->GetWidth();
478 nMinTableWidth = std::min( nSaveWidth, nMinTableWidth );
481 m_aWidthMF.SetRefValue(pTblData->GetSpace());
482 m_aWidthMF.SetLast(m_aWidthMF.NormalizePercent( pTblData->GetSpace() ));
483 m_aLeftMF.SetLast(m_aLeftMF.NormalizePercent( pTblData->GetSpace() ));
484 m_aRightMF.SetLast(m_aRightMF.NormalizePercent( pTblData->GetSpace() ));
486 m_aLeftMF.SetPrcntValue(m_aLeftMF.NormalizePercent(
487 pTblData->GetLeftSpace()), FUNIT_TWIP);
488 m_aRightMF.SetPrcntValue(m_aRightMF.NormalizePercent(
489 pTblData->GetRightSpace()), FUNIT_TWIP);
490 m_aLeftMF.SaveValue();
491 m_aRightMF.SaveValue();
493 nOldAlign = pTblData->GetAlign();
495 bool bSetRight = false, bSetLeft = false;
496 switch( nOldAlign )
498 case text::HoriOrientation::NONE:
499 m_pFreeBtn->Check();
500 if(m_pRelWidthCB->IsChecked())
501 bSetRight = true;
502 break;
503 case text::HoriOrientation::FULL:
505 bSetRight = bSetLeft = true;
506 m_pFullBtn->Check();
507 m_aWidthMF.Enable(sal_False);
508 m_pRelWidthCB->Enable(sal_False);
509 m_pWidthFT->Enable(sal_False);
511 break;
512 case text::HoriOrientation::LEFT:
514 bSetLeft = true;
515 m_pLeftBtn->Check();
517 break;
518 case text::HoriOrientation::LEFT_AND_WIDTH :
520 bSetRight = true;
521 m_pFromLeftBtn->Check();
523 break;
524 case text::HoriOrientation::RIGHT:
526 bSetRight = true;
527 m_pRightBtn->Check();
529 break;
530 case text::HoriOrientation::CENTER:
532 bSetRight = true;
533 m_pCenterBtn->Check();
535 break;
537 if ( bSetRight )
539 m_aRightMF.Enable(sal_False);
540 m_pRightFT->Enable(sal_False);
542 if ( bSetLeft )
544 m_aLeftMF.Enable(sal_False);
545 m_pLeftFT->Enable(sal_False);
550 //Margins
551 if(SFX_ITEM_SET == rSet.GetItemState( RES_UL_SPACE, sal_False,&pItem ))
553 m_pTopMF->SetValue(m_pTopMF->Normalize(
554 ((const SvxULSpaceItem*)pItem)->GetUpper()), FUNIT_TWIP);
555 m_pBottomMF->SetValue(m_pBottomMF->Normalize(
556 ((const SvxULSpaceItem*)pItem)->GetLower()), FUNIT_TWIP);
557 m_pTopMF->SaveValue();
558 m_pBottomMF->SaveValue();
561 //text direction
562 if( SFX_ITEM_SET == rSet.GetItemState( RES_FRAMEDIR, sal_True, &pItem ) )
564 sal_uIntPtr nVal = ((SvxFrameDirectionItem*)pItem)->GetValue();
565 sal_uInt16 nPos = m_pTextDirectionLB->GetEntryPos( (void*) nVal );
566 m_pTextDirectionLB->SelectEntryPos( nPos );
567 m_pTextDirectionLB->SaveValue();
570 m_aWidthMF.SetMax( 2*m_aWidthMF.NormalizePercent( pTblData->GetSpace() ), FUNIT_TWIP );
571 m_aRightMF.SetMax( m_aRightMF.NormalizePercent( pTblData->GetSpace() ), FUNIT_TWIP );
572 m_aLeftMF.SetMax( m_aLeftMF.NormalizePercent( pTblData->GetSpace() ), FUNIT_TWIP );
573 m_aWidthMF.SetMin( m_aWidthMF.NormalizePercent( nMinTableWidth ), FUNIT_TWIP );
578 void SwFormatTablePage::ActivatePage( const SfxItemSet& rSet )
580 OSL_ENSURE(pTblData, "table data not available?");
581 if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP ))
583 SwTwips nCurWidth = text::HoriOrientation::FULL != pTblData->GetAlign() ?
584 pTblData->GetWidth() :
585 pTblData->GetSpace();
586 if(pTblData->GetWidthPercent() == 0 &&
587 nCurWidth != m_aWidthMF.DenormalizePercent(m_aWidthMF.GetValue(FUNIT_TWIP )))
589 m_aWidthMF.SetPrcntValue(m_aWidthMF.NormalizePercent(
590 nCurWidth), FUNIT_TWIP);
591 m_aWidthMF.SaveValue();
592 nSaveWidth = nCurWidth;
593 m_aLeftMF.SetPrcntValue(m_aLeftMF.NormalizePercent(
594 pTblData->GetLeftSpace()), FUNIT_TWIP);
595 m_aLeftMF.SaveValue();
596 m_aRightMF.SetPrcntValue(m_aRightMF.NormalizePercent(
597 pTblData->GetRightSpace()), FUNIT_TWIP);
598 m_aRightMF.SaveValue();
604 int SwFormatTablePage::DeactivatePage( SfxItemSet* _pSet )
606 // os: VCL sorgt nicht dafuer, dass das aktive Control im
607 // dialog bei OK den focus verliert
608 m_pNameED->GrabFocus();
609 // Test the table name for spaces
610 String sTblName = m_pNameED->GetText();
611 if(sTblName.Search(' ') != STRING_NOTFOUND)
613 InfoBox(this, SW_RES(MSG_WRONG_TABLENAME)).Execute();
614 m_pNameED->GrabFocus();
615 return KEEP_PAGE;
617 if(_pSet)
619 FillItemSet(*_pSet);
620 if(bModified)
622 SwTwips lLeft = static_cast< SwTwips >(m_aLeftMF.DenormalizePercent(m_aLeftMF.GetValue( FUNIT_TWIP )));
623 SwTwips lRight = static_cast< SwTwips >(m_aRightMF.DenormalizePercent(m_aRightMF.GetValue( FUNIT_TWIP )));
626 if( m_aLeftMF.GetText() != m_aLeftMF.GetSavedValue() ||
627 m_aRightMF.GetText() != m_aRightMF.GetSavedValue() )
629 pTblData->SetWidthChanged();
630 pTblData->SetLeftSpace( lLeft);
631 pTblData->SetRightSpace( lRight);
634 SwTwips lWidth;
635 if (m_pRelWidthCB->IsChecked() && m_pRelWidthCB->IsEnabled())
637 lWidth = pTblData->GetSpace() - lRight - lLeft;
638 sal_uInt16 nPercentWidth = (sal_uInt16)m_aWidthMF.GetValue(FUNIT_CUSTOM);
639 if(pTblData->GetWidthPercent() != nPercentWidth)
641 pTblData->SetWidthPercent(nPercentWidth);
642 pTblData->SetWidthChanged();
645 else
647 pTblData->SetWidthPercent(0);
648 lWidth = static_cast< SwTwips >(m_aWidthMF.DenormalizePercent(m_aWidthMF.GetValue( FUNIT_TWIP )));
650 pTblData->SetWidth(lWidth);
652 SwTwips nColSum = 0;
653 sal_uInt16 i;
655 for( i = 0; i < pTblData->GetColCount(); i++)
657 nColSum += pTblData->GetColumns()[i].nWidth;
659 if(nColSum != pTblData->GetWidth())
661 SwTwips nMinWidth = std::min( (long)MINLAY,
662 (long) (pTblData->GetWidth() /
663 pTblData->GetColCount() - 1));
664 SwTwips nDiff = nColSum - pTblData->GetWidth();
665 while ( std::abs(nDiff) > pTblData->GetColCount() + 1 )
667 SwTwips nSub = nDiff / pTblData->GetColCount();
668 for( i = 0; i < pTblData->GetColCount(); i++)
670 if(pTblData->GetColumns()[i].nWidth - nMinWidth > nSub)
672 pTblData->GetColumns()[i].nWidth -= nSub;
673 nDiff -= nSub;
675 else
677 nDiff -= pTblData->GetColumns()[i].nWidth - nMinWidth;
678 pTblData->GetColumns()[i].nWidth = nMinWidth;
685 sal_Int16 nAlign = 0;
686 if(m_pRightBtn->IsChecked())
687 nAlign = text::HoriOrientation::RIGHT;
688 else if(m_pLeftBtn->IsChecked())
689 nAlign = text::HoriOrientation::LEFT;
690 else if(m_pFromLeftBtn->IsChecked())
691 nAlign = text::HoriOrientation::LEFT_AND_WIDTH;
692 else if(m_pCenterBtn->IsChecked())
693 nAlign = text::HoriOrientation::CENTER;
694 else if(m_pFreeBtn->IsChecked())
695 nAlign = text::HoriOrientation::NONE;
696 else if(m_pFullBtn->IsChecked())
698 nAlign = text::HoriOrientation::FULL;
699 lWidth = lAutoWidth;
701 if(nAlign != pTblData->GetAlign())
703 pTblData->SetWidthChanged();
704 pTblData->SetAlign(nAlign);
707 if(pTblData->GetWidth() != lWidth )
709 pTblData->SetWidthChanged();
710 pTblData->SetWidth(
711 nAlign == text::HoriOrientation::FULL ? pTblData->GetSpace() : lWidth );
713 if(pTblData->HasWidthChanged())
714 _pSet->Put(SwPtrItem(FN_TABLE_REP, pTblData));
717 return sal_True;
719 //Description: Page column configuration
720 SwTableColumnPage::SwTableColumnPage(Window* pParent, const SfxItemSet& rSet)
721 : SfxTabPage(pParent, "TableColumnPage",
722 "modules/swriter/ui/tablecolumnpage.ui", rSet)
723 , nTableWidth(0)
724 , nMinWidth(MINLAY)
725 , nNoOfCols(0)
726 , nNoOfVisibleCols(0)
727 , bModified(false)
728 , bModifyTbl(false)
729 , bPercentMode(false)
731 get(m_pModifyTableCB, "adaptwidth");
732 get(m_pProportionalCB, "adaptcolumns");
733 get(m_pSpaceFT, "spaceft");
734 get(m_pSpaceED, "space-nospin");
735 get(m_pUpBtn, "next");
736 get(m_pDownBtn, "back");
738 m_aFieldArr[0].set(get<MetricField>("width1"));
739 m_aFieldArr[1].set(get<MetricField>("width2"));
740 m_aFieldArr[2].set(get<MetricField>("width3"));
741 m_aFieldArr[3].set(get<MetricField>("width4"));
742 m_aFieldArr[4].set(get<MetricField>("width5"));
743 m_aFieldArr[5].set(get<MetricField>("width6"));
745 m_pTextArr[0] = get<FixedText>("1");
746 m_pTextArr[1] = get<FixedText>("2");
747 m_pTextArr[2] = get<FixedText>("3");
748 m_pTextArr[3] = get<FixedText>("4");
749 m_pTextArr[4] = get<FixedText>("5");
750 m_pTextArr[5] = get<FixedText>("6");
752 SetExchangeSupport();
754 const SfxPoolItem* pItem;
755 Init((SFX_ITEM_SET == rSet.GetItemState( SID_HTML_MODE, sal_False,&pItem )
756 && ((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON));
759 //Description: Page column configuration
760 SwTableColumnPage::~SwTableColumnPage()
765 SfxTabPage* SwTableColumnPage::Create( Window* pParent,
766 const SfxItemSet& rAttrSet)
768 return new SwTableColumnPage( pParent, rAttrSet );
772 void SwTableColumnPage::Reset( const SfxItemSet& )
774 const SfxItemSet& rSet = GetItemSet();
776 const SfxPoolItem* pItem;
777 if(SFX_ITEM_SET == rSet.GetItemState( FN_TABLE_REP, sal_False, &pItem ))
779 pTblData = (SwTableRep*)((const SwPtrItem*) pItem)->GetValue();
780 nNoOfVisibleCols = pTblData->GetColCount();
781 nNoOfCols = pTblData->GetAllColCount();
782 nTableWidth = pTblData->GetAlign() != text::HoriOrientation::FULL &&
783 pTblData->GetAlign() != text::HoriOrientation::LEFT_AND_WIDTH?
784 pTblData->GetWidth() : pTblData->GetSpace();
786 sal_uInt16 i;
787 for( i = 0; i < nNoOfCols; i++ )
789 if( pTblData->GetColumns()[i].nWidth < nMinWidth )
790 nMinWidth = pTblData->GetColumns()[i].nWidth;
792 sal_Int64 nMinTwips = m_aFieldArr[0].NormalizePercent( nMinWidth );
793 sal_Int64 nMaxTwips = m_aFieldArr[0].NormalizePercent( nTableWidth );
794 for( i = 0; (i < MET_FIELDS) && (i < nNoOfVisibleCols); i++ )
796 m_aFieldArr[i].SetPrcntValue( m_aFieldArr[i].NormalizePercent(
797 GetVisibleWidth(i) ), FUNIT_TWIP );
798 m_aFieldArr[i].SetMin( nMinTwips , FUNIT_TWIP );
799 m_aFieldArr[i].SetMax( nMaxTwips , FUNIT_TWIP );
800 m_aFieldArr[i].Enable();
801 m_pTextArr[i]->Enable();
804 if( nNoOfVisibleCols > MET_FIELDS )
805 m_pUpBtn->Enable();
806 i = nNoOfVisibleCols;
807 while( i < MET_FIELDS )
809 m_aFieldArr[i].SetText( aEmptyStr );
810 m_pTextArr[i]->Disable();
811 i++;
814 ActivatePage(rSet);
819 void SwTableColumnPage::Init(sal_Bool bWeb)
821 FieldUnit aMetric = ::GetDfltMetric(bWeb);
822 Link aLkUp = LINK( this, SwTableColumnPage, UpHdl );
823 Link aLkDown = LINK( this, SwTableColumnPage, DownHdl );
824 Link aLkLF = LINK( this, SwTableColumnPage, LoseFocusHdl );
825 for( sal_uInt16 i = 0; i < MET_FIELDS; i++ )
827 aValueTbl[i] = i;
828 m_aFieldArr[i].SetMetric(aMetric);
829 m_aFieldArr[i].SetUpHdl( aLkUp );
830 m_aFieldArr[i].SetDownHdl( aLkDown );
831 m_aFieldArr[i].SetLoseFocusHdl( aLkLF );
833 SetMetric(*m_pSpaceED, aMetric);
835 Link aLk = LINK( this, SwTableColumnPage, AutoClickHdl );
836 m_pUpBtn->SetClickHdl( aLk );
837 m_pDownBtn->SetClickHdl( aLk );
839 aLk = LINK( this, SwTableColumnPage, ModeHdl );
840 m_pModifyTableCB->SetClickHdl( aLk );
841 m_pProportionalCB->SetClickHdl( aLk );
845 IMPL_LINK( SwTableColumnPage, AutoClickHdl, CheckBox *, pBox )
847 //move display window
848 if(pBox == (CheckBox *)m_pDownBtn)
850 if(aValueTbl[0] > 0)
852 for( sal_uInt16 i=0; i < MET_FIELDS; i++ )
853 aValueTbl[i] -= 1;
856 if (pBox == (CheckBox *)m_pUpBtn)
858 if( aValueTbl[ MET_FIELDS -1 ] < nNoOfVisibleCols -1 )
860 for(sal_uInt16 i=0;i < MET_FIELDS;i++)
861 aValueTbl[i] += 1;
864 for( sal_uInt16 i = 0; (i < nNoOfVisibleCols ) && ( i < MET_FIELDS); i++ )
866 String sEntry = OUString('~');
867 String sIndex = OUString::number( aValueTbl[i] + 1 );
868 sEntry += sIndex;
869 m_pTextArr[i]->SetText( sEntry );
871 //added by menghu for SODC_5143,12/12/2006
872 OUString sColumnWidth = SW_RESSTR( STR_ACCESS_COLUMN_WIDTH);
873 sColumnWidth = sColumnWidth.replaceFirst( "%1", sIndex );
874 m_aFieldArr[i].SetAccessibleName( sColumnWidth );
877 m_pDownBtn->Enable(aValueTbl[0] > 0);
878 m_pUpBtn->Enable(aValueTbl[ MET_FIELDS -1 ] < nNoOfVisibleCols -1 );
879 UpdateCols(0);
880 return 0;
884 IMPL_LINK_INLINE_START( SwTableColumnPage, UpHdl, MetricField*, pEdit )
886 bModified = sal_True;
887 ModifyHdl( pEdit );
888 return 0;
890 IMPL_LINK_INLINE_END( SwTableColumnPage, UpHdl, MetricField*, pEdit )
893 IMPL_LINK_INLINE_START( SwTableColumnPage, DownHdl, MetricField*, pEdit )
895 bModified = sal_True;
896 ModifyHdl( pEdit );
897 return 0;
899 IMPL_LINK_INLINE_END( SwTableColumnPage, DownHdl, MetricField*, pEdit )
902 IMPL_LINK_INLINE_START( SwTableColumnPage, LoseFocusHdl, MetricField*, pEdit )
904 if (pEdit->IsModified())
906 bModified = sal_True;
907 ModifyHdl( pEdit );
909 return 0;
911 IMPL_LINK_INLINE_END( SwTableColumnPage, LoseFocusHdl, MetricField*, pEdit )
914 IMPL_LINK( SwTableColumnPage, ModeHdl, CheckBox*, pBox )
916 sal_Bool bCheck = pBox->IsChecked();
917 if (pBox == m_pProportionalCB)
919 if(bCheck)
920 m_pModifyTableCB->Check();
921 m_pModifyTableCB->Enable(!bCheck && bModifyTbl);
923 return 0;
927 sal_Bool SwTableColumnPage::FillItemSet( SfxItemSet& )
929 for( sal_uInt16 i = 0; i < MET_FIELDS; i++ )
931 if (m_aFieldArr[i].HasFocus())
933 LoseFocusHdl(m_aFieldArr[i].get());
934 break;
938 if(bModified)
940 pTblData->SetColsChanged();
942 return bModified;
946 void SwTableColumnPage::ModifyHdl( MetricField* pField )
948 PercentFieldWrap *pEdit = NULL;
949 sal_uInt16 nAktPos;
950 sal_uInt16 i;
952 for( i = 0; i < MET_FIELDS; i++)
954 if (pField == m_aFieldArr[i].get())
956 pEdit = &m_aFieldArr[i];
957 break;
961 if (MET_FIELDS <= i || !pEdit)
963 OSL_ENSURE(false, "cannot happen.");
964 return;
967 SetVisibleWidth(aValueTbl[i], static_cast< SwTwips >(pEdit->DenormalizePercent(pEdit->GetValue( FUNIT_TWIP ))) );
968 nAktPos = aValueTbl[i];
970 UpdateCols( nAktPos );
974 void SwTableColumnPage::UpdateCols( sal_uInt16 nAktPos )
976 SwTwips nSum = 0;
977 sal_uInt16 i;
979 for( i = 0; i < nNoOfCols; i++ )
981 nSum += (pTblData->GetColumns())[i].nWidth;
983 SwTwips nDiff = nSum - nTableWidth;
985 sal_Bool bModifyTable = m_pModifyTableCB->IsChecked();
986 sal_Bool bProp = m_pProportionalCB->IsChecked();
988 if(!bModifyTable && !bProp )
990 // the table width is constant, the difference is balanced with the other columns
991 sal_uInt16 nLoopCount = 0;
992 while( nDiff )
994 if( ++nAktPos == nNoOfVisibleCols)
996 nAktPos = 0;
997 ++nLoopCount;
998 //#i101353# in small tables it might not be possible to balance column width
999 if( nLoopCount > 1 )
1000 break;
1002 if( nDiff < 0 )
1004 SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
1005 nDiff = 0;
1007 else if( GetVisibleWidth(nAktPos) >= nDiff + nMinWidth )
1009 SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
1010 nDiff = 0;
1012 if( nDiff > 0 && GetVisibleWidth(nAktPos) > nMinWidth )
1014 if( nDiff >= (GetVisibleWidth(nAktPos) - nMinWidth) )
1016 nDiff -= (GetVisibleWidth(nAktPos) - nMinWidth);
1017 SetVisibleWidth(nAktPos, nMinWidth);
1019 else
1021 nDiff = 0;
1022 SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) -nDiff);
1024 OSL_ENSURE(nDiff >= 0, "nDiff < 0 cannot be here!");
1028 else if(bModifyTable && !bProp)
1030 // Difference is balanced by the width of the table,
1031 // other columns remain unchanged.
1032 OSL_ENSURE(nDiff <= pTblData->GetSpace() - nTableWidth, "wrong maximum" );
1033 SwTwips nActSpace = pTblData->GetSpace() - nTableWidth;
1034 if(nDiff > nActSpace)
1036 nTableWidth = pTblData->GetSpace();
1037 SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) - nDiff + nActSpace );
1039 else
1041 nTableWidth += nDiff;
1044 else if(bModifyTable & bProp)
1046 // All columns will be changed proportionally with,
1047 // the table width is adjusted accordingly.
1048 OSL_ENSURE(nDiff * nNoOfVisibleCols <= pTblData->GetSpace() - nTableWidth, "wrong maximum" );
1049 long nAdd = nDiff;
1050 if(nDiff * nNoOfVisibleCols > pTblData->GetSpace() - nTableWidth)
1052 nAdd = (pTblData->GetSpace() - nTableWidth) / nNoOfVisibleCols;
1053 SetVisibleWidth(nAktPos, GetVisibleWidth(nAktPos) - nDiff + nAdd );
1054 nDiff = nAdd;
1056 if(nAdd)
1057 for(i = 0; i < nNoOfVisibleCols; i++ )
1059 if(i == nAktPos)
1060 continue;
1061 SwTwips nVisWidth;
1062 if((nVisWidth = GetVisibleWidth(i)) + nDiff < MINLAY)
1064 nAdd += nVisWidth - MINLAY;
1065 SetVisibleWidth(i, MINLAY);
1067 else
1069 SetVisibleWidth(i, nVisWidth + nDiff);
1070 nAdd += nDiff;
1074 nTableWidth += nAdd;
1077 if(!bPercentMode)
1078 m_pSpaceED->SetValue(m_pSpaceED->Normalize( pTblData->GetSpace() - nTableWidth) , FUNIT_TWIP);
1080 for( i = 0; ( i < nNoOfVisibleCols ) && ( i < MET_FIELDS ); i++)
1082 m_aFieldArr[i].SetPrcntValue(m_aFieldArr[i].NormalizePercent(
1083 GetVisibleWidth(aValueTbl[i]) ), FUNIT_TWIP);
1084 m_aFieldArr[i].ClearModifyFlag();
1088 void SwTableColumnPage::ActivatePage( const SfxItemSet& )
1090 bPercentMode = pTblData->GetWidthPercent() != 0;
1091 for( sal_uInt16 i = 0; (i < MET_FIELDS) && (i < nNoOfVisibleCols); i++ )
1093 m_aFieldArr[i].SetRefValue(pTblData->GetWidth());
1094 m_aFieldArr[i].ShowPercent( bPercentMode );
1097 sal_uInt16 nTblAlign = pTblData->GetAlign();
1098 if((text::HoriOrientation::FULL != nTblAlign && nTableWidth != pTblData->GetWidth()) ||
1099 (text::HoriOrientation::FULL == nTblAlign && nTableWidth != pTblData->GetSpace()))
1101 nTableWidth = text::HoriOrientation::FULL == nTblAlign ?
1102 pTblData->GetSpace() :
1103 pTblData->GetWidth();
1104 UpdateCols(0);
1106 bModifyTbl = sal_True;
1107 if(pTblData->GetWidthPercent() ||
1108 text::HoriOrientation::FULL == nTblAlign ||
1109 pTblData->IsLineSelected() )
1110 bModifyTbl = sal_False;
1111 if(bPercentMode)
1113 m_pModifyTableCB->Check(sal_False);
1114 m_pProportionalCB->Check(sal_False);
1116 else if( !bModifyTbl )
1118 m_pProportionalCB->Check(sal_False);
1119 m_pModifyTableCB->Check(sal_False);
1121 m_pSpaceFT->Enable(!bPercentMode);
1122 m_pSpaceED->Enable(!bPercentMode);
1123 m_pModifyTableCB->Enable( !bPercentMode && bModifyTbl );
1124 m_pProportionalCB->Enable(!bPercentMode && bModifyTbl );
1126 m_pSpaceED->SetValue(m_pSpaceED->Normalize(
1127 pTblData->GetSpace() - nTableWidth) , FUNIT_TWIP);
1132 int SwTableColumnPage::DeactivatePage( SfxItemSet* _pSet )
1134 if(_pSet)
1136 FillItemSet(*_pSet);
1137 if(text::HoriOrientation::FULL != pTblData->GetAlign() && pTblData->GetWidth() != nTableWidth)
1139 pTblData->SetWidth(nTableWidth);
1140 SwTwips nDiff = pTblData->GetSpace() - pTblData->GetWidth() -
1141 pTblData->GetLeftSpace() - pTblData->GetRightSpace();
1142 switch( pTblData->GetAlign() )
1144 case text::HoriOrientation::RIGHT:
1145 pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff);
1146 break;
1147 case text::HoriOrientation::LEFT:
1148 pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff);
1149 break;
1150 case text::HoriOrientation::NONE:
1152 SwTwips nDiff2 = nDiff/2;
1153 if( nDiff > 0 ||
1154 (-nDiff2 < pTblData->GetRightSpace() && - nDiff2 < pTblData->GetLeftSpace()))
1156 pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff2);
1157 pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff2);
1159 else
1161 if(pTblData->GetRightSpace() > pTblData->GetLeftSpace())
1163 pTblData->SetLeftSpace(0);
1164 pTblData->SetRightSpace(pTblData->GetSpace() - pTblData->GetWidth());
1166 else
1168 pTblData->SetRightSpace(0);
1169 pTblData->SetLeftSpace(pTblData->GetSpace() - pTblData->GetWidth());
1173 break;
1174 case text::HoriOrientation::CENTER:
1175 pTblData->SetRightSpace(pTblData->GetRightSpace() + nDiff/2);
1176 pTblData->SetLeftSpace(pTblData->GetLeftSpace() + nDiff/2);
1177 break;
1178 case text::HoriOrientation::LEFT_AND_WIDTH :
1179 if(nDiff > pTblData->GetRightSpace())
1181 pTblData->SetLeftSpace(pTblData->GetSpace() - pTblData->GetWidth());
1183 pTblData->SetRightSpace(
1184 pTblData->GetSpace() - pTblData->GetWidth() - pTblData->GetLeftSpace());
1185 break;
1187 pTblData->SetWidthChanged();
1189 _pSet->Put(SwPtrItem( FN_TABLE_REP, pTblData ));
1191 return sal_True;
1195 SwTwips SwTableColumnPage::GetVisibleWidth(sal_uInt16 nPos)
1197 sal_uInt16 i=0;
1199 while( nPos )
1201 if(pTblData->GetColumns()[i].bVisible && nPos)
1202 nPos--;
1203 i++;
1205 SwTwips nReturn = pTblData->GetColumns()[i].nWidth;
1206 OSL_ENSURE(i < nNoOfCols, "Array index out of range");
1207 while(!pTblData->GetColumns()[i].bVisible && (i + 1) < nNoOfCols)
1208 nReturn += pTblData->GetColumns()[++i].nWidth;
1210 return nReturn;
1214 void SwTableColumnPage::SetVisibleWidth(sal_uInt16 nPos, SwTwips nNewWidth)
1216 sal_uInt16 i=0;
1217 while( nPos )
1219 if(pTblData->GetColumns()[i].bVisible && nPos)
1220 nPos--;
1221 i++;
1223 OSL_ENSURE(i < nNoOfCols, "Array index out of range");
1224 pTblData->GetColumns()[i].nWidth = nNewWidth;
1225 while(!pTblData->GetColumns()[i].bVisible && (i + 1) < nNoOfCols)
1226 pTblData->GetColumns()[++i].nWidth = 0;
1230 SwTableTabDlg::SwTableTabDlg(Window* pParent, SfxItemPool&,
1231 const SfxItemSet* pItemSet, SwWrtShell* pSh)
1232 : SfxTabDialog(0, pParent, "TablePropertiesDialog",
1233 "modules/swriter/ui/tableproperties.ui", pItemSet, 0)
1234 , pShell(pSh)
1235 , m_nHtmlMode(::GetHtmlMode(pSh->GetView().GetDocShell()))
1237 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1238 OSL_ENSURE(pFact, "Dialogdiet fail!");
1239 AddTabPage("table", &SwFormatTablePage::Create, 0);
1240 m_nTextFlowId = AddTabPage("textflow", &SwTextFlowPage::Create, 0);
1241 AddTabPage("columns", &SwTableColumnPage::Create, 0);
1242 m_nBackgroundId = AddTabPage("background", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BACKGROUND), 0);
1243 m_nBorderId = AddTabPage("borders", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BORDER), 0);
1246 void SwTableTabDlg::PageCreated(sal_uInt16 nId, SfxTabPage& rPage)
1248 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
1249 if (nId == m_nBackgroundId)
1251 sal_Int32 nFlagType = SVX_SHOW_TBLCTL;
1252 if(!( m_nHtmlMode & HTMLMODE_ON ) ||
1253 m_nHtmlMode & HTMLMODE_SOME_STYLES)
1254 nFlagType |= SVX_SHOW_SELECTOR;
1255 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, nFlagType));
1256 rPage.PageCreated(aSet);
1258 else if (nId == m_nBorderId)
1260 aSet.Put (SfxUInt16Item(SID_SWMODE_TYPE,SW_BORDER_MODE_TABLE));
1261 rPage.PageCreated(aSet);
1263 else if (nId == m_nTextFlowId)
1265 ((SwTextFlowPage&)rPage).SetShell(pShell);
1266 const sal_uInt16 eType = pShell->GetFrmType(0,sal_True);
1267 if( !(FRMTYPE_BODY & eType) )
1268 ((SwTextFlowPage&)rPage).DisablePageBreak();
1272 SwTextFlowPage::SwTextFlowPage(Window* pParent, const SfxItemSet& rSet)
1273 : SfxTabPage(pParent, "TableTextFlowPage",
1274 "modules/swriter/ui/tabletextflowpage.ui", rSet)
1275 , pShell(0)
1276 , bPageBreak(true)
1277 , bHtmlMode(false)
1279 get(m_pPgBrkCB, "break");
1281 get(m_pPgBrkRB, "page");
1282 get(m_pColBrkRB, "column");
1284 get(m_pPgBrkBeforeRB, "before");
1285 get(m_pPgBrkAfterRB, "after");
1287 get(m_pPageCollCB, "pagestyle");
1288 get(m_pPageCollLB, "pagestylelb");
1289 get(m_pPageNoFT, "pagenoft");
1290 get(m_pPageNoNF, "pagenonf");
1292 get(m_pSplitCB, "split");
1293 get(m_pSplitRowCB, "splitrow");
1294 get(m_pKeepCB, "keep");
1295 get(m_pHeadLineCB, "headline");
1297 get(m_pRepeatHeaderCombo, "repeatheader");
1298 get(m_pRepeatHeaderNF, "repeatheadernf");
1300 get(m_pTextDirectionLB, "textdirection");
1301 get(m_pVertOrientLB, "vertorient");
1303 m_pPgBrkRB->SetAccessibleRelationMemberOf(m_pPgBrkCB);
1304 m_pColBrkRB->SetAccessibleRelationMemberOf(m_pPgBrkCB);
1305 m_pPgBrkBeforeRB->SetAccessibleRelationMemberOf(m_pPgBrkCB);
1306 m_pPgBrkAfterRB->SetAccessibleRelationMemberOf(m_pPgBrkCB);
1307 m_pPageCollLB->SetAccessibleName(m_pPageCollCB->GetText());
1309 m_pPgBrkCB->SetClickHdl(LINK(this, SwTextFlowPage, PageBreakHdl_Impl));
1310 m_pPgBrkBeforeRB->SetClickHdl(
1311 LINK( this, SwTextFlowPage, PageBreakPosHdl_Impl ) );
1312 m_pPgBrkAfterRB->SetClickHdl(
1313 LINK( this, SwTextFlowPage, PageBreakPosHdl_Impl ) );
1314 m_pPageCollCB->SetClickHdl(
1315 LINK( this, SwTextFlowPage, ApplyCollClickHdl_Impl ) );
1316 m_pColBrkRB->SetClickHdl(
1317 LINK( this, SwTextFlowPage, PageBreakTypeHdl_Impl ) );
1318 m_pPgBrkRB->SetClickHdl(
1319 LINK( this, SwTextFlowPage, PageBreakTypeHdl_Impl ) );
1320 m_pSplitCB->SetClickHdl(
1321 LINK( this, SwTextFlowPage, SplitHdl_Impl));
1322 m_pSplitRowCB->SetClickHdl(
1323 LINK( this, SwTextFlowPage, SplitRowHdl_Impl));
1324 m_pHeadLineCB->SetClickHdl( LINK( this, SwTextFlowPage, HeadLineCBClickHdl ) );
1326 #ifndef SW_FILEFORMAT_40
1327 const SfxPoolItem *pItem;
1328 if(SFX_ITEM_SET == rSet.GetItemState( SID_HTML_MODE, sal_False,&pItem )
1329 && ((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON)
1330 #endif
1332 m_pKeepCB->Hide();
1333 m_pSplitCB->Hide();
1334 m_pSplitRowCB->Hide();
1337 HeadLineCBClickHdl();
1340 SwTextFlowPage::~SwTextFlowPage()
1344 SfxTabPage* SwTextFlowPage::Create( Window* pParent,
1345 const SfxItemSet& rAttrSet)
1347 return new SwTextFlowPage(pParent, rAttrSet);
1350 sal_Bool SwTextFlowPage::FillItemSet( SfxItemSet& rSet )
1352 sal_Bool bModified = sal_False;
1354 // Repeat Heading
1355 if(m_pHeadLineCB->IsChecked() != m_pHeadLineCB->GetSavedValue() ||
1356 OUString::number( static_cast< sal_Int32 >(m_pRepeatHeaderNF->GetValue()) ) != m_pRepeatHeaderNF->GetSavedValue() )
1358 bModified |= 0 != rSet.Put(
1359 SfxUInt16Item(FN_PARAM_TABLE_HEADLINE, m_pHeadLineCB->IsChecked()? sal_uInt16(m_pRepeatHeaderNF->GetValue()) : 0 ));
1361 if(m_pKeepCB->IsChecked() != m_pKeepCB->GetSavedValue())
1362 bModified |= 0 != rSet.Put( SvxFmtKeepItem( m_pKeepCB->IsChecked(), RES_KEEP));
1364 if(m_pSplitCB->IsChecked() != m_pSplitCB->GetSavedValue())
1365 bModified |= 0 != rSet.Put( SwFmtLayoutSplit( m_pSplitCB->IsChecked()));
1367 if(m_pSplitRowCB->IsChecked() != m_pSplitRowCB->GetSavedValue())
1368 bModified |= 0 != rSet.Put( SwFmtRowSplit( m_pSplitRowCB->IsChecked()));
1371 const SvxFmtBreakItem* pBreak = (const SvxFmtBreakItem*)GetOldItem( rSet, RES_BREAK );
1372 const SwFmtPageDesc* pDesc = (const SwFmtPageDesc*) GetOldItem( rSet, RES_PAGEDESC );
1375 sal_Bool bState = m_pPageCollCB->IsChecked();
1377 // If we have a page style, then there's no break
1378 sal_Bool bPageItemPut = sal_False;
1379 if ( bState != m_pPageCollCB->GetSavedValue() ||
1380 ( bState &&
1381 m_pPageCollLB->GetSelectEntryPos() != m_pPageCollLB->GetSavedValue() )
1382 || (m_pPageNoNF->IsEnabled() && m_pPageNoNF->IsValueModified()) )
1384 String sPage;
1386 if ( bState )
1388 sPage = m_pPageCollLB->GetSelectEntry();
1390 sal_uInt16 nPgNum = static_cast< sal_uInt16 >(m_pPageNoNF->GetValue());
1391 if ( !pDesc || !pDesc->GetPageDesc() ||
1392 ( pDesc->GetPageDesc() && ((pDesc->GetPageDesc()->GetName() != sPage) ||
1393 !comphelper::string::equals(m_pPageNoNF->GetSavedValue(), nPgNum))))
1395 SwFmtPageDesc aFmt( pShell->FindPageDescByName( sPage, sal_True ) );
1396 aFmt.SetNumOffset(bState ? nPgNum : 0);
1397 bModified |= 0 != rSet.Put( aFmt );
1398 bPageItemPut = bState;
1401 sal_Bool bIsChecked = m_pPgBrkCB->IsChecked();
1402 if ( !bPageItemPut &&
1403 ( bState != m_pPageCollCB->GetSavedValue() ||
1404 bIsChecked != m_pPgBrkCB->GetSavedValue() ||
1405 m_pPgBrkBeforeRB->IsChecked() != m_pPgBrkBeforeRB->GetSavedValue() ||
1406 m_pPgBrkRB->IsChecked() != m_pPgBrkRB->GetSavedValue() ))
1408 SvxFmtBreakItem aBreak(
1409 (const SvxFmtBreakItem&)GetItemSet().Get( RES_BREAK ) );
1411 if(bIsChecked)
1413 sal_Bool bBefore = m_pPgBrkBeforeRB->IsChecked();
1415 if ( m_pPgBrkRB->IsChecked() )
1417 if ( bBefore )
1418 aBreak.SetValue( SVX_BREAK_PAGE_BEFORE );
1419 else
1420 aBreak.SetValue( SVX_BREAK_PAGE_AFTER );
1422 else
1424 if ( bBefore )
1425 aBreak.SetValue( SVX_BREAK_COLUMN_BEFORE );
1426 else
1427 aBreak.SetValue( SVX_BREAK_COLUMN_AFTER );
1430 else
1432 aBreak.SetValue( SVX_BREAK_NONE );
1435 if ( !pBreak || !( *(const SvxFmtBreakItem*)pBreak == aBreak ) )
1437 bModified |= 0 != rSet.Put( aBreak );
1441 if(m_pTextDirectionLB->GetSelectEntryPos() != m_pTextDirectionLB->GetSavedValue())
1443 bModified |= 0 != rSet.Put(
1444 SvxFrameDirectionItem(
1445 (SvxFrameDirection)(sal_uLong)m_pTextDirectionLB->GetEntryData(m_pTextDirectionLB->GetSelectEntryPos())
1446 , FN_TABLE_BOX_TEXTORIENTATION));
1449 if(m_pVertOrientLB->GetSelectEntryPos() != m_pVertOrientLB->GetSavedValue())
1451 sal_uInt16 nOrient = USHRT_MAX;
1452 switch(m_pVertOrientLB->GetSelectEntryPos())
1454 case 0 : nOrient = text::VertOrientation::NONE; break;
1455 case 1 : nOrient = text::VertOrientation::CENTER; break;
1456 case 2 : nOrient = text::VertOrientation::BOTTOM; break;
1458 if(nOrient != USHRT_MAX)
1459 bModified |= 0 != rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, nOrient));
1462 return bModified;
1466 void SwTextFlowPage::Reset( const SfxItemSet& rSet )
1468 const SfxPoolItem* pItem;
1469 SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
1470 bool bFlowAllowed = !bHtmlMode || rHtmlOpt.IsPrintLayoutExtension();
1471 if(bFlowAllowed)
1473 // Inserting of the existing page templates in the list box.
1474 const sal_uInt16 nCount = pShell->GetPageDescCnt();
1475 sal_uInt16 i;
1477 for( i = 0; i < nCount; ++i)
1479 const SwPageDesc &rPageDesc = pShell->GetPageDesc(i);
1480 m_pPageCollLB->InsertEntry(rPageDesc.GetName());
1483 String aFmtName;
1484 for(i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
1485 if( LISTBOX_ENTRY_NOTFOUND == m_pPageCollLB->GetEntryPos(
1486 aFmtName = SwStyleNameMapper::GetUIName( i, aFmtName ) ))
1487 m_pPageCollLB->InsertEntry( aFmtName );
1489 if(SFX_ITEM_SET == rSet.GetItemState( RES_KEEP, sal_False, &pItem ))
1491 m_pKeepCB->Check( ((const SvxFmtKeepItem*)pItem)->GetValue() );
1492 m_pKeepCB->SaveValue();
1494 if(SFX_ITEM_SET == rSet.GetItemState( RES_LAYOUT_SPLIT, sal_False, &pItem ))
1496 m_pSplitCB->Check( ((const SwFmtLayoutSplit*)pItem)->GetValue() );
1498 else
1499 m_pSplitCB->Check();
1501 m_pSplitCB->SaveValue();
1502 SplitHdl_Impl(m_pSplitCB);
1504 if(SFX_ITEM_SET == rSet.GetItemState( RES_ROW_SPLIT, sal_False, &pItem ))
1506 m_pSplitRowCB->Check( ((const SwFmtRowSplit*)pItem)->GetValue() );
1508 else
1509 m_pSplitRowCB->SetState(STATE_DONTKNOW);
1510 m_pSplitRowCB->SaveValue();
1512 if(bPageBreak)
1514 if(SFX_ITEM_SET == rSet.GetItemState( RES_PAGEDESC, sal_False, &pItem ))
1516 String sPageDesc;
1517 const SwPageDesc* pDesc = ((const SwFmtPageDesc*)pItem)->GetPageDesc();
1518 m_pPageNoNF->SetValue(((const SwFmtPageDesc*)pItem)->GetNumOffset());
1519 if(pDesc)
1520 sPageDesc = pDesc->GetName();
1521 if ( sPageDesc.Len() &&
1522 m_pPageCollLB->GetEntryPos( sPageDesc ) != LISTBOX_ENTRY_NOTFOUND )
1524 m_pPageCollLB->SelectEntry( sPageDesc );
1525 m_pPageCollCB->Check();
1527 m_pPgBrkCB->Enable();
1528 m_pPgBrkRB->Enable();
1529 m_pColBrkRB->Enable();
1530 m_pPgBrkBeforeRB->Enable();
1531 m_pPgBrkAfterRB->Enable();
1532 m_pPageCollCB->Enable();
1533 m_pPgBrkCB->Check();
1535 m_pPgBrkCB->Check( sal_True );
1536 m_pColBrkRB->Check( sal_False );
1537 m_pPgBrkBeforeRB->Check( sal_True );
1538 m_pPgBrkAfterRB->Check( sal_False );
1540 else
1542 m_pPageCollLB->SetNoSelection();
1543 m_pPageCollCB->Check(sal_False);
1547 if(SFX_ITEM_SET == rSet.GetItemState( RES_BREAK, sal_False, &pItem ))
1549 const SvxFmtBreakItem* pPageBreak = (const SvxFmtBreakItem*)pItem;
1550 SvxBreak eBreak = (SvxBreak)pPageBreak->GetValue();
1552 if ( eBreak != SVX_BREAK_NONE )
1554 m_pPgBrkCB->Check();
1555 m_pPageCollCB->Enable(sal_False);
1556 m_pPageCollLB->Enable(sal_False);
1557 m_pPageNoFT->Enable(sal_False);
1558 m_pPageNoNF->Enable(sal_False);
1560 switch ( eBreak )
1562 case SVX_BREAK_PAGE_BEFORE:
1563 m_pPgBrkRB->Check( sal_True );
1564 m_pColBrkRB->Check( sal_False );
1565 m_pPgBrkBeforeRB->Check( sal_True );
1566 m_pPgBrkAfterRB->Check( sal_False );
1567 break;
1568 case SVX_BREAK_PAGE_AFTER:
1569 m_pPgBrkRB->Check( sal_True );
1570 m_pColBrkRB->Check( sal_False );
1571 m_pPgBrkBeforeRB->Check( sal_False );
1572 m_pPgBrkAfterRB->Check( sal_True );
1573 break;
1574 case SVX_BREAK_COLUMN_BEFORE:
1575 m_pPgBrkRB->Check( sal_False );
1576 m_pColBrkRB->Check( sal_True );
1577 m_pPgBrkBeforeRB->Check( sal_True );
1578 m_pPgBrkAfterRB->Check( sal_False );
1579 break;
1580 case SVX_BREAK_COLUMN_AFTER:
1581 m_pPgBrkRB->Check( sal_False );
1582 m_pColBrkRB->Check( sal_True );
1583 m_pPgBrkBeforeRB->Check( sal_False );
1584 m_pPgBrkAfterRB->Check( sal_True );
1585 break;
1586 default:; //prevent warning
1590 if ( m_pPgBrkBeforeRB->IsChecked() )
1591 PageBreakPosHdl_Impl(m_pPgBrkBeforeRB);
1592 else if ( m_pPgBrkAfterRB->IsChecked() )
1593 PageBreakPosHdl_Impl(m_pPgBrkAfterRB);
1594 PageBreakHdl_Impl( m_pPgBrkCB );
1597 else
1599 m_pPgBrkRB->Enable(sal_False);
1600 m_pColBrkRB->Enable(sal_False);
1601 m_pPgBrkBeforeRB->Enable(sal_False);
1602 m_pPgBrkAfterRB->Enable(sal_False);
1603 m_pKeepCB->Enable(sal_False);
1604 m_pSplitCB->Enable(sal_False);
1605 m_pPgBrkCB->Enable(sal_False);
1606 m_pPageCollCB->Enable(sal_False);
1607 m_pPageCollLB->Enable(sal_False);
1610 if(SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE, sal_False, &pItem ))
1612 sal_uInt16 nRep = ((const SfxUInt16Item*)pItem)->GetValue();
1613 m_pHeadLineCB->Check( nRep > 0 );
1614 m_pHeadLineCB->SaveValue();
1615 m_pRepeatHeaderNF->SetValue( nRep );
1616 m_pRepeatHeaderNF->SaveValue();
1618 if ( rSet.GetItemState(FN_TABLE_BOX_TEXTORIENTATION) > SFX_ITEM_AVAILABLE )
1620 sal_uLong nDirection = ((const SvxFrameDirectionItem&)rSet.Get(FN_TABLE_BOX_TEXTORIENTATION)).GetValue();
1621 m_pTextDirectionLB->SelectEntryPos(m_pTextDirectionLB->GetEntryPos( (const void*)nDirection ));
1624 if ( rSet.GetItemState(FN_TABLE_SET_VERT_ALIGN) > SFX_ITEM_AVAILABLE )
1626 sal_uInt16 nVert = ((const SfxUInt16Item&)rSet.Get(FN_TABLE_SET_VERT_ALIGN)).GetValue();
1627 sal_uInt16 nPos = 0;
1628 switch(nVert)
1630 case text::VertOrientation::NONE: nPos = 0; break;
1631 case text::VertOrientation::CENTER: nPos = 1; break;
1632 case text::VertOrientation::BOTTOM: nPos = 2; break;
1634 m_pVertOrientLB->SelectEntryPos(nPos);
1637 m_pPageCollCB->SaveValue();
1638 m_pPageCollLB->SaveValue();
1639 m_pPgBrkCB->SaveValue();
1640 m_pPgBrkRB->SaveValue();
1641 m_pColBrkRB->SaveValue();
1642 m_pPgBrkBeforeRB->SaveValue();
1643 m_pPgBrkAfterRB->SaveValue();
1644 m_pPageNoNF->SaveValue();
1645 m_pTextDirectionLB->SaveValue();
1646 m_pVertOrientLB->SaveValue();
1648 HeadLineCBClickHdl();
1651 void SwTextFlowPage::SetShell(SwWrtShell* pSh)
1653 pShell = pSh;
1654 bHtmlMode = 0 != (::GetHtmlMode(pShell->GetView().GetDocShell()) & HTMLMODE_ON);
1655 if(bHtmlMode)
1657 m_pPageNoNF->Enable(sal_False);
1658 m_pPageNoFT->Enable(sal_False);
1662 IMPL_LINK_NOARG(SwTextFlowPage, PageBreakHdl_Impl)
1664 if( m_pPgBrkCB->IsChecked() )
1666 m_pPgBrkRB-> Enable();
1667 m_pColBrkRB-> Enable();
1668 m_pPgBrkBeforeRB-> Enable();
1669 m_pPgBrkAfterRB-> Enable();
1671 if ( m_pPgBrkRB->IsChecked() && m_pPgBrkBeforeRB->IsChecked() )
1673 m_pPageCollCB->Enable();
1675 sal_Bool bEnable = m_pPageCollCB->IsChecked() &&
1676 m_pPageCollLB->GetEntryCount();
1677 m_pPageCollLB->Enable(bEnable);
1678 if(!bHtmlMode)
1680 m_pPageNoFT->Enable(bEnable);
1681 m_pPageNoNF->Enable(bEnable);
1685 else
1687 m_pPageCollCB->Check( sal_False );
1688 m_pPageCollCB->Enable(sal_False);
1689 m_pPageCollLB->Enable(sal_False);
1690 m_pPageNoFT->Enable(sal_False);
1691 m_pPageNoNF->Enable(sal_False);
1692 m_pPgBrkRB-> Enable(sal_False);
1693 m_pColBrkRB-> Enable(sal_False);
1694 m_pPgBrkBeforeRB-> Enable(sal_False);
1695 m_pPgBrkAfterRB-> Enable(sal_False);
1697 return 0;
1700 IMPL_LINK_NOARG(SwTextFlowPage, ApplyCollClickHdl_Impl)
1702 sal_Bool bEnable = sal_False;
1703 if ( m_pPageCollCB->IsChecked() &&
1704 m_pPageCollLB->GetEntryCount() )
1706 bEnable = sal_True;
1707 m_pPageCollLB->SelectEntryPos( 0 );
1709 else
1711 m_pPageCollLB->SetNoSelection();
1713 m_pPageCollLB->Enable(bEnable);
1714 if(!bHtmlMode)
1716 m_pPageNoFT->Enable(bEnable);
1717 m_pPageNoNF->Enable(bEnable);
1719 return 0;
1722 IMPL_LINK( SwTextFlowPage, PageBreakPosHdl_Impl, RadioButton*, pBtn )
1724 if ( m_pPgBrkCB->IsChecked() )
1726 if ( pBtn == m_pPgBrkBeforeRB && m_pPgBrkRB->IsChecked() )
1728 m_pPageCollCB->Enable();
1730 sal_Bool bEnable = m_pPageCollCB->IsChecked() &&
1731 m_pPageCollLB->GetEntryCount();
1733 m_pPageCollLB->Enable(bEnable);
1734 if(!bHtmlMode)
1736 m_pPageNoFT->Enable(bEnable);
1737 m_pPageNoNF->Enable(bEnable);
1740 else if (pBtn == m_pPgBrkAfterRB)
1742 m_pPageCollCB->Check( sal_False );
1743 m_pPageCollCB->Enable(sal_False);
1744 m_pPageCollLB->Enable(sal_False);
1745 m_pPageNoFT->Enable(sal_False);
1746 m_pPageNoNF->Enable(sal_False);
1749 return 0;
1752 IMPL_LINK( SwTextFlowPage, PageBreakTypeHdl_Impl, RadioButton*, pBtn )
1754 if ( pBtn == m_pColBrkRB || m_pPgBrkAfterRB->IsChecked() )
1756 m_pPageCollCB->Check(sal_False);
1757 m_pPageCollCB->Enable(sal_False);
1758 m_pPageCollLB->Enable(sal_False);
1759 m_pPageNoFT->Enable(sal_False);
1760 m_pPageNoNF->Enable(sal_False);
1762 else if ( m_pPgBrkBeforeRB->IsChecked() )
1763 PageBreakPosHdl_Impl(m_pPgBrkBeforeRB);
1764 return 0;
1767 IMPL_LINK( SwTextFlowPage, SplitHdl_Impl, CheckBox*, pBox )
1769 m_pSplitRowCB->Enable(pBox->IsChecked());
1770 return 0;
1773 IMPL_LINK( SwTextFlowPage, SplitRowHdl_Impl, TriStateBox*, pBox )
1775 pBox->EnableTriState(sal_False);
1776 return 0;
1779 IMPL_LINK_NOARG(SwTextFlowPage, HeadLineCBClickHdl)
1781 m_pRepeatHeaderCombo->Enable(m_pHeadLineCB->IsChecked());
1783 return 0;
1786 void SwTextFlowPage::DisablePageBreak()
1788 bPageBreak = sal_False;
1789 m_pPgBrkCB->Disable();
1790 m_pPgBrkRB->Disable();
1791 m_pColBrkRB->Disable();
1792 m_pPgBrkBeforeRB->Disable();
1793 m_pPgBrkAfterRB->Disable();
1794 m_pPageCollCB->Disable();
1795 m_pPageCollLB->Disable();
1796 m_pPageNoFT->Disable();
1797 m_pPageNoNF->Disable();
1802 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */