1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <hintids.hxx>
21 #include <vcl/svapp.hxx>
22 #include <vcl/weld.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 <fmtpdsc.hxx>
32 #include <fmtlsplt.hxx>
33
34 #include <fmtrowsplt.hxx>
35 #include <sfx2/htmlmode.hxx>
36 #include <sfx2/sfxdlg.hxx>
37
38 #include <strings.hrc>
39 #include <svx/strings.hrc>
40 #include <svx/dialmgr.hxx>
41
42 #include <wrtsh.hxx>
43 #include <view.hxx>
44 #include <viewopt.hxx>
45 #include <uitool.hxx>
46 #include <tabledlg.hxx>
47 #include "../../uibase/table/tablepg.hxx"
48 #include <tablemgr.hxx>
49 #include <pagedesc.hxx>
50 #include <uiitems.hxx>
51 #include <poolfmt.hxx>
52 #include <swtablerep.hxx>
53 #include <SwStyleNameMapper.hxx>
54
55 #include <cmdid.h>
56 #include <svx/dialogs.hrc>
57 #include <svx/flagsdef.hxx>
58 #include <osl/diagnose.h>
59 #include <officecfg/Office/Common.hxx>
60
61 #include <com/sun/star/text/HoriOrientation.hpp>
62 #include <com/sun/star/text/VertOrientation.hpp>
63
64 using namespace ::com::sun::star;
65
SwFormatTablePage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rSet)66 SwFormatTablePage::SwFormatTablePage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
67 : SfxTabPage(pPage, pController, u"modules/swriter/ui/formattablepage.ui"_ustr, u"FormatTablePage"_ustr, &rSet)
68 , m_pTableData(nullptr)
69 , m_nSaveWidth(0)
70 , m_nMinTableWidth(MINLAY)
71 , m_bModified(false)
72 , m_bFull(false)
73 , m_bHtmlMode(false)
74 , m_xNameED(m_xBuilder->weld_entry(u"name"_ustr))
75 , m_xWidthFT(m_xBuilder->weld_label(u"widthft"_ustr))
76 , m_xWidthMF(new SwPercentField(m_xBuilder->weld_metric_spin_button(u"widthmf"_ustr, FieldUnit::CM)))
77 , m_xRelWidthCB(m_xBuilder->weld_check_button(u"relwidth"_ustr))
78 , m_xFullBtn(m_xBuilder->weld_radio_button(u"full"_ustr))
79 , m_xLeftBtn(m_xBuilder->weld_radio_button(u"left"_ustr))
80 , m_xFromLeftBtn(m_xBuilder->weld_radio_button(u"fromleft"_ustr))
81 , m_xRightBtn(m_xBuilder->weld_radio_button(u"right"_ustr))
82 , m_xCenterBtn(m_xBuilder->weld_radio_button(u"center"_ustr))
83 , m_xFreeBtn(m_xBuilder->weld_radio_button(u"free"_ustr))
84 , m_xLeftFT(m_xBuilder->weld_label(u"leftft"_ustr))
85 , m_xLeftMF(new SwPercentField(m_xBuilder->weld_metric_spin_button(u"leftmf"_ustr, FieldUnit::CM)))
86 , m_xRightFT(m_xBuilder->weld_label(u"rightft"_ustr))
87 , m_xRightMF(new SwPercentField(m_xBuilder->weld_metric_spin_button(u"rightmf"_ustr, FieldUnit::CM)))
88 , m_xTopFT(m_xBuilder->weld_label(u"aboveft"_ustr))
89 , m_xTopMF(m_xBuilder->weld_metric_spin_button(u"abovemf"_ustr, FieldUnit::CM))
90 , m_xBottomFT(m_xBuilder->weld_label(u"belowft"_ustr))
91 , m_xBottomMF(m_xBuilder->weld_metric_spin_button(u"belowmf"_ustr, FieldUnit::CM))
92 , m_xTextDirectionLB(new svx::FrameDirectionListBox(m_xBuilder->weld_combo_box(u"textdirection"_ustr)))
93 , m_xProperties(m_xBuilder->weld_widget(u"properties"_ustr))
94 {
95 m_xWidthMF->GetMetricFieldRange(m_nOrigWidthMin, m_nOrigWidthMax);
96 m_xLeftMF->GetMetricFieldRange(m_nOrigLeftMin, m_nOrigLeftMax);
97 m_xRightMF->GetMetricFieldRange(m_nOrigRightMin, m_nOrigRightMax);
98
99 //lock these to initial sizes so they don't change on percent to non percent change
100 Size aPrefSize(m_xLeftMF->get()->get_preferred_size());
101 m_xLeftMF->get()->set_size_request(aPrefSize.Width(), aPrefSize.Height());
102 m_xRightMF->get()->set_size_request(aPrefSize.Width(), aPrefSize.Height());
103 m_xWidthMF->get()->set_size_request(aPrefSize.Width(), aPrefSize.Height());
104
105 m_xTextDirectionLB->append(SvxFrameDirection::Horizontal_LR_TB, SvxResId(RID_SVXSTR_FRAMEDIR_LTR));
106 m_xTextDirectionLB->append(SvxFrameDirection::Horizontal_RL_TB, SvxResId(RID_SVXSTR_FRAMEDIR_RTL));
107 m_xTextDirectionLB->append(SvxFrameDirection::Environment, SvxResId(RID_SVXSTR_FRAMEDIR_SUPER));
108
109 SetExchangeSupport();
110
111 if(const SfxUInt16Item* pModeItem = rSet.GetItemIfSet(SID_HTML_MODE, false))
112 m_bHtmlMode = 0 != (pModeItem->GetValue() & HTMLMODE_ON);
113
114 bool bCTL = SvtCTLOptions::IsCTLFontEnabled();
115 m_xProperties->set_visible(!m_bHtmlMode && bCTL);
116
117 Init();
118 }
119
~SwFormatTablePage()120 SwFormatTablePage::~SwFormatTablePage()
121 {
122 }
123
Init()124 void SwFormatTablePage::Init()
125 {
126 m_xLeftMF->SetMetricFieldMin(-999999);
127 m_xRightMF->SetMetricFieldMin(-999999);
128
129 //handler
130 Link<weld::Toggleable&,void> aLk2 = LINK( this, SwFormatTablePage, AutoClickHdl );
131 m_xFullBtn->connect_toggled( aLk2 );
132 m_xFreeBtn->connect_toggled( aLk2 );
133 m_xLeftBtn->connect_toggled( aLk2 );
134 m_xFromLeftBtn->connect_toggled( aLk2 );
135 m_xRightBtn->connect_toggled( aLk2 );
136 m_xCenterBtn->connect_toggled( aLk2 );
137
138 Link<weld::MetricSpinButton&,void> aLk = LINK(this, SwFormatTablePage, ValueChangedHdl);
139 m_xTopMF->connect_value_changed(aLk);
140 m_xBottomMF->connect_value_changed(aLk);
141 m_xRightMF->connect_value_changed(aLk);
142 m_xLeftMF->connect_value_changed(aLk);
143 m_xWidthMF->connect_value_changed(aLk);
144
145 m_xRelWidthCB->connect_toggled(LINK( this, SwFormatTablePage, RelWidthClickHdl ));
146 }
147
IMPL_LINK(SwFormatTablePage,RelWidthClickHdl,weld::Toggleable &,rBtn,void)148 IMPL_LINK( SwFormatTablePage, RelWidthClickHdl, weld::Toggleable&, rBtn, void )
149 {
150 OSL_ENSURE(m_pTableData, "table data not available?");
151 bool bIsChecked = rBtn.get_active();
152 sal_Int64 nLeft = m_xLeftMF->DenormalizePercent(m_xLeftMF->get_value(FieldUnit::TWIP));
153 sal_Int64 nRight = m_xRightMF->DenormalizePercent(m_xRightMF->get_value(FieldUnit::TWIP));
154 m_xWidthMF->ShowPercent(bIsChecked);
155 m_xLeftMF->ShowPercent(bIsChecked);
156 m_xRightMF->ShowPercent(bIsChecked);
157
158 if (bIsChecked)
159 {
160 m_xWidthMF->SetRefValue(m_pTableData->GetSpace());
161 m_xLeftMF->SetRefValue(m_pTableData->GetSpace());
162 m_xRightMF->SetRefValue(m_pTableData->GetSpace());
163 m_xLeftMF->SetMetricFieldMin(0); //will be overwritten by the Percentfield
164 m_xRightMF->SetMetricFieldMin(0); //ditto
165 m_xLeftMF->SetMetricFieldMax(99);
166 m_xRightMF->SetMetricFieldMax(99);
167 m_xLeftMF->set_value(m_xLeftMF->NormalizePercent(nLeft ), FieldUnit::TWIP );
168 m_xRightMF->set_value(m_xRightMF->NormalizePercent(nRight ), FieldUnit::TWIP );
169 }
170 else
171 ModifyHdl(*m_xLeftMF->get()); //correct values again
172
173 if (m_xFreeBtn->get_active())
174 {
175 bool bEnable = !rBtn.get_active();
176 m_xRightMF->set_sensitive(bEnable);
177 m_xRightFT->set_sensitive(bEnable);
178 }
179 m_bModified = true;
180 }
181
IMPL_LINK_NOARG(SwFormatTablePage,AutoClickHdl,weld::Toggleable &,void)182 IMPL_LINK_NOARG(SwFormatTablePage, AutoClickHdl, weld::Toggleable&, void)
183 {
184 bool bRestore = true,
185 bLeftEnable = false,
186 bRightEnable= false,
187 bWidthEnable= false,
188 bOthers = true;
189 if (m_xFullBtn->get_active())
190 {
191 m_xLeftMF->set_value(0);
192 m_xRightMF->set_value(0);
193 m_nSaveWidth = static_cast<SwTwips>(m_xWidthMF->DenormalizePercent(m_xWidthMF->get_value(FieldUnit::TWIP)));
194 m_xWidthMF->set_value(m_xWidthMF->NormalizePercent(m_pTableData->GetSpace()), FieldUnit::TWIP);
195 m_bFull = true;
196 bRestore = false;
197 }
198 else if (m_xLeftBtn->get_active())
199 {
200 bRightEnable = bWidthEnable = true;
201 m_xLeftMF->set_value(0);
202 }
203 else if (m_xFromLeftBtn->get_active())
204 {
205 bLeftEnable = bWidthEnable = true;
206 m_xRightMF->set_value(0);
207 }
208 else if (m_xRightBtn->get_active())
209 {
210 bLeftEnable = bWidthEnable = true;
211 m_xRightMF->set_value(0);
212 }
213 else if (m_xCenterBtn->get_active())
214 {
215 bLeftEnable = bWidthEnable = true;
216 }
217 else if (m_xFreeBtn->get_active())
218 {
219 RightModify();
220 bLeftEnable = true;
221 bWidthEnable = true;
222 bOthers = false;
223 }
224 m_xLeftMF->set_sensitive(bLeftEnable);
225 m_xLeftFT->set_sensitive(bLeftEnable);
226 m_xWidthMF->set_sensitive(bWidthEnable);
227 m_xWidthFT->set_sensitive(bWidthEnable);
228 if ( bOthers )
229 {
230 m_xRightMF->set_sensitive(bRightEnable);
231 m_xRightFT->set_sensitive(bRightEnable);
232 m_xRelWidthCB->set_sensitive(bWidthEnable);
233 }
234
235 if(m_bFull && bRestore)
236 {
237 //After being switched on automatic, the width was pinned
238 //in order to restore the width while switching back to.
239 m_bFull = false;
240 m_xWidthMF->set_value(m_xWidthMF->NormalizePercent(m_nSaveWidth ), FieldUnit::TWIP );
241 }
242 ModifyHdl(*m_xWidthMF->get());
243 m_bModified = true;
244 }
245
RightModify()246 void SwFormatTablePage::RightModify()
247 {
248 if (!m_xFreeBtn->get_active())
249 return;
250
251 bool bEnable = m_xRightMF->get_value() == 0;
252 m_xRelWidthCB->set_sensitive(bEnable);
253 if ( !bEnable )
254 {
255 m_xRelWidthCB->set_active(false);
256 RelWidthClickHdl(*m_xRelWidthCB);
257 }
258 bEnable = m_xRelWidthCB->get_active();
259 m_xRightMF->set_sensitive(!bEnable);
260 m_xRightFT->set_sensitive(!bEnable);
261 }
262
IMPL_LINK(SwFormatTablePage,ValueChangedHdl,weld::MetricSpinButton &,rEdit,void)263 IMPL_LINK( SwFormatTablePage, ValueChangedHdl, weld::MetricSpinButton&, rEdit, void )
264 {
265 if (m_xRightMF->get() == &rEdit)
266 RightModify();
267 ModifyHdl(rEdit);
268 }
269
ModifyHdl(const weld::MetricSpinButton & rEdit,bool bAllowInconsistencies)270 void SwFormatTablePage::ModifyHdl(const weld::MetricSpinButton& rEdit, bool bAllowInconsistencies)
271 {
272 SwTwips nCurWidth = static_cast< SwTwips >(m_xWidthMF->DenormalizePercent(m_xWidthMF->get_value(FieldUnit::TWIP)));
273 SwTwips nPrevWidth = nCurWidth;
274 SwTwips nRight = static_cast< SwTwips >(m_xRightMF->DenormalizePercent(m_xRightMF->get_value(FieldUnit::TWIP)));
275 SwTwips nLeft = static_cast< SwTwips >(m_xLeftMF->DenormalizePercent(m_xLeftMF->get_value(FieldUnit::TWIP)));
276 SwTwips nDiff;
277
278 if (&rEdit == m_xWidthMF->get())
279 {
280 if( nCurWidth < MINLAY )
281 nCurWidth = MINLAY;
282 nDiff = nRight + nLeft + nCurWidth - m_pTableData->GetSpace() ;
283 //right aligned: only change the left margin
284 if (m_xRightBtn->get_active())
285 nLeft -= nDiff;
286 //left aligned: only change the right margin
287 else if(m_xLeftBtn->get_active())
288 nRight -= nDiff;
289 //left margin and width allowed - first right - then left
290 else if (m_xFromLeftBtn->get_active())
291 {
292 if( nRight >= nDiff )
293 nRight -= nDiff;
294 else
295 {
296 nDiff -= nRight;
297 nRight = 0;
298 if(nLeft >= nDiff)
299 nLeft -= nDiff;
300 else
301 {
302 nRight += nLeft - nDiff;
303 nLeft = 0;
304 nCurWidth = m_pTableData->GetSpace();
305 }
306 }
307 }
308 //centered: change both sides equally
309 else if (m_xCenterBtn->get_active())
310 {
311 if(nLeft != nRight)
312 {
313 nDiff += nLeft + nRight;
314 nLeft = nDiff/2;
315 nRight = nDiff/2;
316 }
317 else
318 {
319 nLeft -= nDiff/2;
320 nRight -= nDiff/2;
321 }
322 }
323 //free alignment: decrease both margins
324 else if (m_xFreeBtn->get_active())
325 {
326 nLeft -= nDiff/2;
327 nRight -= nDiff/2;
328 }
329 }
330 if (&rEdit == m_xRightMF->get())
331 {
332
333 if( nRight + nLeft > m_pTableData->GetSpace() - MINLAY )
334 nRight = m_pTableData->GetSpace() -nLeft - MINLAY;
335
336 nCurWidth = m_pTableData->GetSpace() - nLeft - nRight;
337 }
338 if (&rEdit == m_xLeftMF->get())
339 {
340 if(!m_xFromLeftBtn->get_active())
341 {
342 bool bCenter = m_xCenterBtn->get_active();
343 if( bCenter )
344 nRight = nLeft;
345 if(nRight + nLeft > m_pTableData->GetSpace() - MINLAY )
346 {
347 nLeft = bCenter ? (m_pTableData->GetSpace() - MINLAY) /2 :
348 (m_pTableData->GetSpace() - MINLAY) - nRight;
349 nRight = bCenter ? (m_pTableData->GetSpace() - MINLAY) /2 : nRight;
350 }
351 nCurWidth = m_pTableData->GetSpace() - nLeft - nRight;
352 }
353 else
354 {
355 //Upon changes on the left side the right margin will be changed at first,
356 //thereafter the width.
357 nDiff = nRight + nLeft + nCurWidth - m_pTableData->GetSpace() ;
358
359 nRight -= nDiff;
360 nCurWidth = m_pTableData->GetSpace() - nLeft - nRight;
361 }
362 }
363
364 m_xRightMF->set_value( m_xRightMF->NormalizePercent( nRight ), FieldUnit::TWIP );
365 m_xLeftMF->set_value( m_xLeftMF->NormalizePercent( nLeft ), FieldUnit::TWIP );
366
367 if (nCurWidth != nPrevWidth )
368 {
369 m_xWidthMF->set_value(m_xWidthMF->NormalizePercent(nCurWidth), FieldUnit::TWIP);
370
371 // tdf#135021 if the user changed the width spinbutton, and in this
372 // ModifyHdl we changed the value of that width spinbutton, then rerun
373 // the ModifyHdl on the replaced value so the left/right/width value
374 // relationships are consistent.
375 // But (tdf#135693) only make one effort of rectifying the inconsistency
376 if (&rEdit == m_xWidthMF->get() && !bAllowInconsistencies)
377 ModifyHdl(rEdit, true);
378 }
379
380 m_bModified = true;
381 }
382
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rAttrSet)383 std::unique_ptr<SfxTabPage> SwFormatTablePage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
384 {
385 return std::make_unique<SwFormatTablePage>(pPage, pController, *rAttrSet);
386 }
387
FillItemSet(SfxItemSet * rCoreSet)388 bool SwFormatTablePage::FillItemSet( SfxItemSet* rCoreSet )
389 {
390 //Test if one of the controls still has the focus
391 if (m_xWidthMF->has_focus())
392 ModifyHdl(*m_xWidthMF->get());
393 else if (m_xLeftMF->has_focus())
394 ModifyHdl(*m_xLeftMF->get());
395 else if (m_xRightMF->has_focus())
396 ModifyHdl(*m_xRightMF->get());
397 else if (m_xTopMF->has_focus())
398 ModifyHdl(*m_xTopMF);
399 else if (m_xBottomMF->has_focus())
400 ModifyHdl(*m_xBottomMF);
401
402 if (m_bModified)
403 {
404 if (m_xBottomMF->get_value_changed_from_saved() ||
405 m_xTopMF->get_value_changed_from_saved() )
406 {
407 SvxULSpaceItem aULSpace(RES_UL_SPACE);
408 aULSpace.SetUpper(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
409 aULSpace.SetLower(m_xBottomMF->denormalize(m_xBottomMF->get_value(FieldUnit::TWIP)));
410 rCoreSet->Put(aULSpace);
411 }
412
413 }
414 if (m_xNameED->get_value_changed_from_saved())
415 {
416 rCoreSet->Put(SfxStringItem(FN_PARAM_TABLE_NAME, m_xNameED->get_text()));
417 m_bModified = true;
418 }
419
420 if (m_xTextDirectionLB->get_visible())
421 {
422 if (m_xTextDirectionLB->get_value_changed_from_saved())
423 {
424 SvxFrameDirection nDirection = m_xTextDirectionLB->get_active_id();
425 rCoreSet->Put(SvxFrameDirectionItem(nDirection, RES_FRAMEDIR));
426 m_bModified = true;
427 }
428 }
429
430 return m_bModified;
431 }
432
Reset(const SfxItemSet *)433 void SwFormatTablePage::Reset( const SfxItemSet* )
434 {
435 const SfxItemSet& rSet = GetItemSet();
436
437 if(m_bHtmlMode)
438 {
439 m_xNameED->set_sensitive(false);
440 m_xTopFT->hide();
441 m_xTopMF->hide();
442 m_xBottomFT->hide();
443 m_xBottomMF->hide();
444 m_xFreeBtn->set_sensitive(false);
445 }
446
447 // set back to original state
448 m_xRelWidthCB->set_active(false);
449 m_xWidthMF->ShowPercent(false);
450 m_xLeftMF->ShowPercent(false);
451 m_xRightMF->ShowPercent(false);
452 m_xWidthMF->SetMetricFieldRange(m_nOrigWidthMin, m_nOrigWidthMax);
453 m_xLeftMF->SetMetricFieldRange(m_nOrigLeftMin, m_nOrigLeftMax);
454 m_xRightMF->SetMetricFieldRange(m_nOrigRightMin, m_nOrigRightMax);
455
456 FieldUnit aMetric = ::GetDfltMetric(m_bHtmlMode);
457 m_xWidthMF->SetMetric(aMetric);
458 m_xRightMF->SetMetric(aMetric);
459 m_xLeftMF->SetMetric(aMetric);
460 SetFieldUnit(*m_xTopMF, aMetric);
461 SetFieldUnit(*m_xBottomMF, aMetric);
462
463 //Name
464 if(const SfxStringItem* pNameItem = rSet.GetItemIfSet( FN_PARAM_TABLE_NAME, false ))
465 {
466 m_xNameED->set_text(pNameItem->GetValue());
467 m_xNameED->save_value();
468 }
469
470 if(const SwPtrItem* pRepItem = rSet.GetItemIfSet( FN_TABLE_REP, false ))
471 {
472 m_pTableData = static_cast<SwTableRep*>( pRepItem->GetValue());
473 if (!m_xOrigTableData)
474 m_xOrigTableData.reset(new SwTableRep(*m_pTableData));
475 else // tdf#134925 and tdf#134913, reset back to the original data seen on dialog creation
476 *m_pTableData = *m_xOrigTableData;
477
478 m_nMinTableWidth = m_pTableData->GetColCount() * MINLAY;
479
480 if(m_pTableData->GetWidthPercent())
481 {
482 m_xRelWidthCB->set_active(true);
483 RelWidthClickHdl(*m_xRelWidthCB);
484 m_xWidthMF->set_value(m_pTableData->GetWidthPercent(), FieldUnit::PERCENT);
485
486 m_xWidthMF->save_value();
487 m_nSaveWidth = static_cast< SwTwips >(m_xWidthMF->get_value(FieldUnit::PERCENT));
488 }
489 else
490 {
491 m_xWidthMF->set_value(m_xWidthMF->NormalizePercent(
492 m_pTableData->GetWidth()), FieldUnit::TWIP);
493 m_xWidthMF->save_value();
494 m_nSaveWidth = m_pTableData->GetWidth();
495 m_nMinTableWidth = std::min( m_nSaveWidth, m_nMinTableWidth );
496 }
497
498 m_xWidthMF->SetRefValue(m_pTableData->GetSpace());
499
500 m_xLeftMF->set_value(m_xLeftMF->NormalizePercent(
501 m_pTableData->GetLeftSpace()), FieldUnit::TWIP);
502 m_xRightMF->set_value(m_xRightMF->NormalizePercent(
503 m_pTableData->GetRightSpace()), FieldUnit::TWIP);
504 m_xLeftMF->save_value();
505 m_xRightMF->save_value();
506
507 bool bSetRight = false, bSetLeft = false;
508 switch( m_pTableData->GetAlign() )
509 {
510 case text::HoriOrientation::NONE:
511 m_xFreeBtn->set_active(true);
512 if (m_xRelWidthCB->get_active())
513 bSetRight = true;
514 break;
515 case text::HoriOrientation::FULL:
516 {
517 bSetRight = bSetLeft = true;
518 m_xFullBtn->set_active(true);
519 m_xWidthMF->set_sensitive(false);
520 m_xRelWidthCB->set_sensitive(false);
521 m_xWidthFT->set_sensitive(false);
522 }
523 break;
524 case text::HoriOrientation::LEFT:
525 {
526 bSetLeft = true;
527 m_xLeftBtn->set_active(true);
528 }
529 break;
530 case text::HoriOrientation::LEFT_AND_WIDTH :
531 {
532 bSetRight = true;
533 m_xFromLeftBtn->set_active(true);
534 }
535 break;
536 case text::HoriOrientation::RIGHT:
537 {
538 bSetRight = true;
539 m_xRightBtn->set_active(true);
540 }
541 break;
542 case text::HoriOrientation::CENTER:
543 {
544 bSetRight = true;
545 m_xCenterBtn->set_active(true);
546 }
547 break;
548 }
549 if ( bSetRight )
550 {
551 m_xRightMF->set_sensitive(false);
552 m_xRightFT->set_sensitive(false);
553 }
554 if ( bSetLeft )
555 {
556 m_xLeftMF->set_sensitive(false);
557 m_xLeftFT->set_sensitive(false);
558 }
559
560 }
561
562 //Margins
563 if(const SvxULSpaceItem* pSpaceItem = rSet.GetItemIfSet( RES_UL_SPACE, false ))
564 {
565 m_xTopMF->set_value(m_xTopMF->normalize(
566 pSpaceItem->GetUpper()), FieldUnit::TWIP);
567 m_xBottomMF->set_value(m_xBottomMF->normalize(
568 pSpaceItem->GetLower()), FieldUnit::TWIP);
569 m_xTopMF->save_value();
570 m_xBottomMF->save_value();
571 }
572
573 //Text direction
574 if( const SvxFrameDirectionItem* pDirectionItem = rSet.GetItemIfSet( RES_FRAMEDIR ) )
575 {
576 SvxFrameDirection nVal = pDirectionItem->GetValue();
577 m_xTextDirectionLB->set_active_id(nVal);
578 m_xTextDirectionLB->save_value();
579 }
580
581 m_xWidthMF->set_max( 2*m_xWidthMF->NormalizePercent( m_pTableData->GetSpace() ), FieldUnit::TWIP );
582 m_xRightMF->set_max( m_xRightMF->NormalizePercent( m_pTableData->GetSpace() ), FieldUnit::TWIP );
583 m_xLeftMF->set_max( m_xLeftMF->NormalizePercent( m_pTableData->GetSpace() ), FieldUnit::TWIP );
584 m_xWidthMF->set_min( m_xWidthMF->NormalizePercent( m_nMinTableWidth ), FieldUnit::TWIP );
585 }
586
ActivatePage(const SfxItemSet & rSet)587 void SwFormatTablePage::ActivatePage( const SfxItemSet& rSet )
588 {
589 if(SfxItemState::SET != rSet.GetItemState( FN_TABLE_REP ))
590 return;
591
592 assert(m_pTableData && "table data not available?");
593
594 SwTwips nCurWidth = text::HoriOrientation::FULL != m_pTableData->GetAlign() ?
595 m_pTableData->GetWidth() :
596 m_pTableData->GetSpace();
597 if(m_pTableData->GetWidthPercent() != 0 ||
598 nCurWidth == m_xWidthMF->DenormalizePercent(m_xWidthMF->get_value(FieldUnit::TWIP)))
599 return;
600
601 m_xWidthMF->set_value(m_xWidthMF->NormalizePercent(
602 nCurWidth), FieldUnit::TWIP);
603 m_xWidthMF->save_value();
604 m_nSaveWidth = nCurWidth;
605 m_xLeftMF->set_value(m_xLeftMF->NormalizePercent(
606 m_pTableData->GetLeftSpace()), FieldUnit::TWIP);
607 m_xLeftMF->save_value();
608 m_xRightMF->set_value(m_xRightMF->NormalizePercent(
609 m_pTableData->GetRightSpace()), FieldUnit::TWIP);
610 m_xRightMF->save_value();
611 }
612
DeactivatePage(SfxItemSet * _pSet)613 DeactivateRC SwFormatTablePage::DeactivatePage( SfxItemSet* _pSet )
614 {
615 //test the table name for spaces
616 OUString sTableName = m_xNameED->get_text();
617 if(sTableName.indexOf(' ') != -1)
618 {
619 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetFrameWeld(),
620 VclMessageType::Info, VclButtonsType::Ok,
621 SwResId(STR_WRONG_TABLENAME)));
622 xInfoBox->run();
623 m_xNameED->grab_focus();
624 return DeactivateRC::KeepPage;
625 }
626 if(_pSet)
627 {
628 FillItemSet(_pSet);
629 if(m_bModified)
630 {
631 SwTwips lLeft = static_cast< SwTwips >(m_xLeftMF->DenormalizePercent(m_xLeftMF->get_value(FieldUnit::TWIP)));
632 SwTwips lRight = static_cast< SwTwips >(m_xRightMF->DenormalizePercent(m_xRightMF->get_value(FieldUnit::TWIP)));
633
634 if( m_xLeftMF->get_value_changed_from_saved() ||
635 m_xRightMF->get_value_changed_from_saved() )
636 {
637 m_pTableData->SetWidthChanged();
638 m_pTableData->SetLeftSpace( lLeft);
639 m_pTableData->SetRightSpace( lRight);
640 }
641
642 SwTwips lWidth;
643 if (m_xRelWidthCB->get_active() && m_xRelWidthCB->get_sensitive())
644 {
645 lWidth = m_pTableData->GetSpace() - lRight - lLeft;
646 const sal_uInt16 nPercentWidth = m_xWidthMF->get_value(FieldUnit::PERCENT);
647 if(m_pTableData->GetWidthPercent() != nPercentWidth)
648 {
649 m_pTableData->SetWidthPercent(nPercentWidth);
650 m_pTableData->SetWidthChanged();
651 }
652 }
653 else
654 {
655 m_pTableData->SetWidthPercent(0);
656 lWidth = static_cast<SwTwips>(m_xWidthMF->DenormalizePercent(m_xWidthMF->get_value(FieldUnit::TWIP)));
657 }
658 m_pTableData->SetWidth(lWidth);
659
660 SwTwips nColSum = 0;
661
662 for( sal_uInt16 i = 0; i < m_pTableData->GetColCount(); i++)
663 {
664 nColSum += m_pTableData->GetColumns()[i].nWidth;
665 }
666 if(nColSum != m_pTableData->GetWidth())
667 {
668 SwTwips nMinWidth = std::min( tools::Long(MINLAY),
669 static_cast<tools::Long>(m_pTableData->GetWidth() /
670 m_pTableData->GetColCount() - 1));
671 SwTwips nDiff = nColSum - m_pTableData->GetWidth();
672 while ( std::abs(nDiff) > m_pTableData->GetColCount() + 1 )
673 {
674 SwTwips nSub = nDiff / m_pTableData->GetColCount();
675 for( sal_uInt16 i = 0; i < m_pTableData->GetColCount(); i++)
676 {
677 if(m_pTableData->GetColumns()[i].nWidth - nMinWidth > nSub)
678 {
679 m_pTableData->GetColumns()[i].nWidth -= nSub;
680 nDiff -= nSub;
681 }
682 else
683 {
684 nDiff -= m_pTableData->GetColumns()[i].nWidth - nMinWidth;
685 m_pTableData->GetColumns()[i].nWidth = nMinWidth;
686 }
687
688 }
689 }
690 }
691
692 sal_Int16 nAlign = 0;
693 if (m_xRightBtn->get_active())
694 nAlign = text::HoriOrientation::RIGHT;
695 else if(m_xLeftBtn->get_active())
696 nAlign = text::HoriOrientation::LEFT;
697 else if(m_xFromLeftBtn->get_active())
698 nAlign = text::HoriOrientation::LEFT_AND_WIDTH;
699 else if(m_xCenterBtn->get_active())
700 nAlign = text::HoriOrientation::CENTER;
701 else if(m_xFreeBtn->get_active())
702 nAlign = text::HoriOrientation::NONE;
703 else if(m_xFullBtn->get_active())
704 {
705 nAlign = text::HoriOrientation::FULL;
706 lWidth = lAutoWidth;
707 }
708 if(nAlign != m_pTableData->GetAlign())
709 {
710 m_pTableData->SetWidthChanged();
711 m_pTableData->SetAlign(nAlign);
712 }
713
714 if(m_pTableData->GetWidth() != lWidth )
715 {
716 m_pTableData->SetWidthChanged();
717 m_pTableData->SetWidth(
718 nAlign == text::HoriOrientation::FULL ? m_pTableData->GetSpace() : lWidth );
719 }
720 if(m_pTableData->HasWidthChanged())
721 _pSet->Put(SwPtrItem(FN_TABLE_REP, m_pTableData));
722 }
723 }
724 return DeactivateRC::LeavePage;
725 }
726
727 //Description: Page column configuration
SwTableColumnPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rSet)728 SwTableColumnPage::SwTableColumnPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
729 : SfxTabPage(pPage, pController, u"modules/swriter/ui/tablecolumnpage.ui"_ustr, u"TableColumnPage"_ustr, &rSet)
730 , m_pTableData(nullptr)
731 , m_pSizeHdlEvent(nullptr)
732 , m_nTableWidth(0)
733 , m_nMinWidth(MINLAY)
734 , m_nMetFields(MET_FIELDS)
735 , m_nNoOfCols(0)
736 , m_nNoOfVisibleCols(0)
737 , m_bModified(false)
738 , m_bModifyTable(false)
739 , m_bPercentMode(false)
740 , m_aFieldArr { m_xBuilder->weld_metric_spin_button(u"width1"_ustr, FieldUnit::CM),
741 m_xBuilder->weld_metric_spin_button(u"width2"_ustr, FieldUnit::CM),
742 m_xBuilder->weld_metric_spin_button(u"width3"_ustr, FieldUnit::CM),
743 m_xBuilder->weld_metric_spin_button(u"width4"_ustr, FieldUnit::CM),
744 m_xBuilder->weld_metric_spin_button(u"width5"_ustr, FieldUnit::CM)}
745 , m_aTextArr { m_xBuilder->weld_label(u"1"_ustr),
746 m_xBuilder->weld_label(u"2"_ustr),
747 m_xBuilder->weld_label(u"3"_ustr),
748 m_xBuilder->weld_label(u"4"_ustr),
749 m_xBuilder->weld_label(u"5"_ustr)}
750 , m_xModifyTableCB(m_xBuilder->weld_check_button(u"adaptwidth"_ustr))
751 , m_xProportionalCB(m_xBuilder->weld_check_button(u"adaptcolumns"_ustr))
752 , m_xSpaceFT(m_xBuilder->weld_label(u"spaceft"_ustr))
753 , m_xSpaceSFT(m_xBuilder->weld_label(u"space"_ustr))
754 , m_xSpaceED(m_xBuilder->weld_metric_spin_button(u"spacefmt"_ustr, FieldUnit::CM))
755 , m_xUpBtn(m_xBuilder->weld_button(u"next"_ustr))
756 , m_xDownBtn(m_xBuilder->weld_button(u"back"_ustr))
757 {
758 SetExchangeSupport();
759
760 // fire off this handler to happen on next event loop when all the rest of
761 // the pages are instantiated and the dialog preferred size is that of the
762 // all the pages that currently exist and the rest to come after this one
763 m_pSizeHdlEvent = Application::PostUserEvent(LINK(this, SwTableColumnPage, SizeHdl));
764
765 const SfxUInt16Item* pModeItem = GetItemSet().GetItemIfSet(SID_HTML_MODE, false);
766 Init(pModeItem && pModeItem->GetValue() & HTMLMODE_ON);
767 }
768
IMPL_LINK_NOARG(SwTableColumnPage,SizeHdl,void *,void)769 IMPL_LINK_NOARG(SwTableColumnPage, SizeHdl, void*, void)
770 {
771 m_pSizeHdlEvent = nullptr;
772
773 //tdf#120420 keeping showing column width fields unless
774 //the dialog begins to grow, then stop adding them
775 weld::Window* pTopLevel = GetFrameWeld();
776 Size aOrigSize = pTopLevel->get_preferred_size();
777 for (sal_uInt16 i = 0; i < MET_FIELDS; ++i)
778 {
779 m_aFieldArr[i].show();
780 m_aTextArr[i]->show();
781
782 if (pTopLevel->get_preferred_size().Width() > aOrigSize.Width())
783 {
784 m_nMetFields = i + 1;
785 m_aTextArr[i]->set_grid_width(1);
786 m_xUpBtn->set_grid_left_attach(m_nMetFields * 2 - 1);
787 break;
788 }
789 }
790
791 // tdf#143142 m_nMetFields has been updated and we need to re-check whether to show right button or not.
792 if (m_nNoOfVisibleCols > m_nMetFields)
793 {
794 m_xUpBtn->set_sensitive(true);
795 }
796
797 }
798
~SwTableColumnPage()799 SwTableColumnPage::~SwTableColumnPage()
800 {
801 if (m_pSizeHdlEvent)
802 {
803 Application::RemoveUserEvent(m_pSizeHdlEvent);
804 m_pSizeHdlEvent = nullptr;
805 }
806 }
807
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rAttrSet)808 std::unique_ptr<SfxTabPage> SwTableColumnPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
809 {
810 return std::make_unique<SwTableColumnPage>(pPage, pController, *rAttrSet);
811 }
812
Reset(const SfxItemSet *)813 void SwTableColumnPage::Reset( const SfxItemSet* )
814 {
815 const SfxItemSet& rSet = GetItemSet();
816
817 if(const SwPtrItem* pRepItem = rSet.GetItemIfSet( FN_TABLE_REP, false ))
818 {
819 m_pTableData = static_cast<SwTableRep*>( pRepItem->GetValue());
820 if (!m_xOrigTableData)
821 m_xOrigTableData.reset(new SwTableRep(*m_pTableData));
822 else // tdf#134925 and tdf#134913, reset back to the original data seen on dialog creation
823 *m_pTableData = *m_xOrigTableData;
824
825 m_nNoOfVisibleCols = m_pTableData->GetColCount();
826 m_nNoOfCols = m_pTableData->GetAllColCount();
827 m_nTableWidth = m_pTableData->GetAlign() != text::HoriOrientation::FULL &&
828 m_pTableData->GetAlign() != text::HoriOrientation::LEFT_AND_WIDTH?
829 m_pTableData->GetWidth() : m_pTableData->GetSpace();
830
831 for( sal_uInt16 i = 0; i < m_nNoOfCols; i++ )
832 {
833 if (m_pTableData->GetColumns()[i].nWidth < m_nMinWidth)
834 m_nMinWidth = m_pTableData->GetColumns()[i].nWidth;
835 }
836 sal_Int64 nMinTwips = m_aFieldArr[0].NormalizePercent( m_nMinWidth );
837 sal_Int64 nMaxTwips = m_aFieldArr[0].NormalizePercent( m_nTableWidth );
838 for( sal_uInt16 i = 0; (i < m_nMetFields) && (i < m_nNoOfVisibleCols); i++ )
839 {
840 m_aFieldArr[i].set_value( m_aFieldArr[i].NormalizePercent(
841 GetVisibleWidth(i) ), FieldUnit::TWIP );
842 m_aFieldArr[i].set_min(nMinTwips, FieldUnit::TWIP);
843 m_aFieldArr[i].set_max(nMaxTwips, FieldUnit::TWIP);
844 m_aFieldArr[i].set_sensitive(true);
845 m_aTextArr[i]->set_sensitive(true);
846 }
847
848 if (m_nNoOfVisibleCols > m_nMetFields)
849 {
850 m_xUpBtn->set_sensitive(true);
851 }
852
853 for( sal_uInt16 i = m_nNoOfVisibleCols; i < m_nMetFields; ++i )
854 {
855 m_aFieldArr[i].set_text(OUString());
856 m_aTextArr[i]->set_sensitive(false);
857 }
858 }
859 ActivatePage(rSet);
860 }
861
Init(bool bWeb)862 void SwTableColumnPage::Init(bool bWeb)
863 {
864 FieldUnit aMetric = ::GetDfltMetric(bWeb);
865 Link<weld::MetricSpinButton&,void> aLk = LINK(this, SwTableColumnPage, ValueChangedHdl);
866 for (sal_uInt16 i = 0; i < MET_FIELDS; ++i)
867 {
868 m_aValueTable[i] = i;
869 m_aFieldArr[i].SetMetric(aMetric);
870 m_aFieldArr[i].connect_value_changed(aLk);
871 }
872 SetFieldUnit(*m_xSpaceED, aMetric);
873
874 Link<weld::Button&,void> aClickLk = LINK(this, SwTableColumnPage, AutoClickHdl);
875 m_xUpBtn->connect_clicked(aClickLk);
876 m_xDownBtn->connect_clicked(aClickLk);
877
878 Link<weld::Toggleable&,void> aToggleLk = LINK(this, SwTableColumnPage, ModeHdl);
879 m_xModifyTableCB->connect_toggled(aToggleLk);
880 m_xProportionalCB->connect_toggled(aToggleLk);
881 }
882
IMPL_LINK(SwTableColumnPage,AutoClickHdl,weld::Button &,rControl,void)883 IMPL_LINK(SwTableColumnPage, AutoClickHdl, weld::Button&, rControl, void)
884 {
885 //move display window
886 if (&rControl == m_xDownBtn.get())
887 {
888 if(m_aValueTable[0] > 0)
889 {
890 for(sal_uInt16 & rn : m_aValueTable)
891 rn -= 1;
892 }
893 }
894 if (&rControl == m_xUpBtn.get())
895 {
896 if( m_aValueTable[ m_nMetFields -1 ] < m_nNoOfVisibleCols -1 )
897 {
898 for(sal_uInt16 & rn : m_aValueTable)
899 rn += 1;
900 }
901 }
902 for( sal_uInt16 i = 0; (i < m_nNoOfVisibleCols ) && ( i < m_nMetFields); i++ )
903 {
904 OUString sEntry('~');
905 OUString sIndex = OUString::number( m_aValueTable[i] + 1 );
906 sEntry += sIndex;
907 m_aTextArr[i]->set_label(sEntry);
908 }
909
910 m_xDownBtn->set_sensitive(m_aValueTable[0] > 0);
911 m_xUpBtn->set_sensitive(m_aValueTable[ m_nMetFields -1 ] < m_nNoOfVisibleCols -1 );
912 UpdateCols(0);
913 }
914
IMPL_LINK(SwTableColumnPage,ValueChangedHdl,weld::MetricSpinButton &,rEdit,void)915 IMPL_LINK(SwTableColumnPage, ValueChangedHdl, weld::MetricSpinButton&, rEdit, void)
916 {
917 m_bModified = true;
918 ModifyHdl(&rEdit);
919 }
920
IMPL_LINK(SwTableColumnPage,ModeHdl,weld::Toggleable &,rBox,void)921 IMPL_LINK(SwTableColumnPage, ModeHdl, weld::Toggleable&, rBox, void)
922 {
923 const bool bCheck = rBox.get_active();
924 if (&rBox == m_xProportionalCB.get())
925 {
926 if (bCheck)
927 m_xModifyTableCB->set_active(true);
928 m_xModifyTableCB->set_sensitive(!bCheck && m_bModifyTable);
929 }
930 }
931
FillItemSet(SfxItemSet *)932 bool SwTableColumnPage::FillItemSet( SfxItemSet* )
933 {
934 for (SwPercentField & i : m_aFieldArr)
935 {
936 if (i.has_focus())
937 {
938 ModifyHdl(i.get());
939 break;
940 }
941 }
942
943 if (m_bModified)
944 {
945 m_pTableData->SetColsChanged();
946 }
947 return m_bModified;
948 }
949
ModifyHdl(const weld::MetricSpinButton * pField)950 void SwTableColumnPage::ModifyHdl(const weld::MetricSpinButton* pField)
951 {
952 SwPercentField *pEdit = nullptr;
953 sal_uInt16 i;
954
955 for( i = 0; i < m_nMetFields; i++)
956 {
957 if (pField == m_aFieldArr[i].get())
958 {
959 pEdit = &m_aFieldArr[i];
960 break;
961 }
962 }
963
964 if (m_nMetFields <= i || !pEdit)
965 {
966 OSL_ENSURE(false, "cannot happen.");
967 return;
968 }
969
970 SetVisibleWidth(m_aValueTable[i], pEdit->DenormalizePercent(pEdit->get_value(FieldUnit::TWIP)));
971
972 UpdateCols( m_aValueTable[i] );
973 }
974
UpdateCols(sal_uInt16 nCurrentPos)975 void SwTableColumnPage::UpdateCols( sal_uInt16 nCurrentPos )
976 {
977 SwTwips nSum = 0;
978
979 for( sal_uInt16 i = 0; i < m_nNoOfCols; i++ )
980 {
981 nSum += (m_pTableData->GetColumns())[i].nWidth;
982 }
983 SwTwips nDiff = nSum - m_nTableWidth;
984
985 bool bModifyTableChecked = m_xModifyTableCB->get_active();
986 bool bProp = m_xProportionalCB->get_active();
987
988 if (!bModifyTableChecked && !bProp)
989 {
990 //The table width is constant, the difference is balanced with the other columns
991 sal_uInt16 nLoopCount = 0;
992 while( nDiff )
993 {
994 if( ++nCurrentPos == m_nNoOfVisibleCols)
995 {
996 nCurrentPos = 0;
997 ++nLoopCount;
998 //#i101353# in small tables it might not be possible to balance column width
999 if( nLoopCount > 1 )
1000 break;
1001 }
1002 if( nDiff < 0 )
1003 {
1004 SetVisibleWidth(nCurrentPos, GetVisibleWidth(nCurrentPos) -nDiff);
1005 nDiff = 0;
1006 }
1007 else if( GetVisibleWidth(nCurrentPos) >= nDiff + m_nMinWidth )
1008 {
1009 SetVisibleWidth(nCurrentPos, GetVisibleWidth(nCurrentPos) -nDiff);
1010 nDiff = 0;
1011 }
1012 if( nDiff > 0 && GetVisibleWidth(nCurrentPos) > m_nMinWidth )
1013 {
1014 if( nDiff >= (GetVisibleWidth(nCurrentPos) - m_nMinWidth) )
1015 {
1016 nDiff -= (GetVisibleWidth(nCurrentPos) - m_nMinWidth);
1017 SetVisibleWidth(nCurrentPos, m_nMinWidth);
1018 }
1019 else
1020 {
1021 nDiff = 0;
1022 SetVisibleWidth(nCurrentPos, GetVisibleWidth(nCurrentPos) -nDiff);
1023 }
1024 OSL_ENSURE(nDiff >= 0, "nDiff < 0 cannot be here!");
1025 }
1026 }
1027 }
1028 else if (bModifyTableChecked && !bProp)
1029 {
1030 //Difference is balanced by the width of the table,
1031 //other columns remain unchanged.
1032 OSL_ENSURE(nDiff <= m_pTableData->GetSpace() - m_nTableWidth, "wrong maximum" );
1033 SwTwips nActSpace = m_pTableData->GetSpace() - m_nTableWidth;
1034 if(nDiff > nActSpace)
1035 {
1036 m_nTableWidth = m_pTableData->GetSpace();
1037 SetVisibleWidth(nCurrentPos, GetVisibleWidth(nCurrentPos) - nDiff + nActSpace );
1038 }
1039 else
1040 {
1041 m_nTableWidth += nDiff;
1042 }
1043 }
1044 else if (bModifyTableChecked && bProp)
1045 {
1046 //All columns will be changed proportionally with,
1047 //the table width is adjusted accordingly.
1048 const double fOrigColWidth = std::max(SwTwips(1), GetVisibleWidth(nCurrentPos) - nDiff);
1049 const double fMaxWidth = std::max(m_pTableData->GetSpace(), m_nTableWidth);
1050 const double fMaxPercent = fMaxWidth / m_nTableWidth;
1051 const double fPercentChange = std::min(fMaxPercent, GetVisibleWidth(nCurrentPos)/fOrigColWidth);
1052 SwTwips nNewTableSize = 0;
1053 for( sal_uInt16 i = 0; i < m_nNoOfVisibleCols; i++ )
1054 {
1055 SwTwips nNewColWidth = round( fPercentChange * (i == nCurrentPos ? fOrigColWidth : GetVisibleWidth(i)) );
1056 if ( nNewColWidth < MINLAY )
1057 nNewColWidth = MINLAY;
1058 SetVisibleWidth(i, nNewColWidth);
1059 nNewTableSize += nNewColWidth;
1060 }
1061 m_nTableWidth = nNewTableSize;
1062 }
1063
1064 if (!m_bPercentMode)
1065 {
1066 m_xSpaceED->set_value(m_xSpaceED->normalize(m_pTableData->GetSpace() - m_nTableWidth), FieldUnit::TWIP);
1067 m_xSpaceSFT->set_label(m_xSpaceED->get_text());
1068 }
1069 else
1070 m_xSpaceSFT->set_label(OUString());
1071
1072 for( sal_uInt16 i = 0; ( i < m_nNoOfVisibleCols ) && ( i < m_nMetFields ); i++)
1073 {
1074 m_aFieldArr[i].set_value(m_aFieldArr[i].NormalizePercent(
1075 GetVisibleWidth(m_aValueTable[i]) ), FieldUnit::TWIP);
1076 }
1077 }
1078
ActivatePage(const SfxItemSet &)1079 void SwTableColumnPage::ActivatePage( const SfxItemSet& )
1080 {
1081 m_bPercentMode = m_pTableData->GetWidthPercent() != 0;
1082 for( sal_uInt16 i = 0; (i < m_nMetFields) && (i < m_nNoOfVisibleCols); i++ )
1083 {
1084 m_aFieldArr[i].SetRefValue(m_pTableData->GetWidth());
1085 m_aFieldArr[i].ShowPercent( m_bPercentMode );
1086 }
1087
1088 const sal_uInt16 nTableAlign = m_pTableData->GetAlign();
1089 if((text::HoriOrientation::FULL != nTableAlign && m_nTableWidth != m_pTableData->GetWidth()) ||
1090 (text::HoriOrientation::FULL == nTableAlign && m_nTableWidth != m_pTableData->GetSpace()))
1091 {
1092 m_nTableWidth = text::HoriOrientation::FULL == nTableAlign ?
1093 m_pTableData->GetSpace() :
1094 m_pTableData->GetWidth();
1095 UpdateCols(0);
1096 }
1097 m_bModifyTable = true;
1098 if (m_pTableData->GetWidthPercent() ||
1099 text::HoriOrientation::FULL == nTableAlign ||
1100 m_pTableData->IsLineSelected() )
1101 m_bModifyTable = false;
1102 if (m_bPercentMode)
1103 {
1104 m_xModifyTableCB->set_active(false);
1105 m_xProportionalCB->set_active(false);
1106 }
1107 else if (!m_bModifyTable)
1108 {
1109 m_xProportionalCB->set_active(false);
1110 m_xModifyTableCB->set_active(false);
1111 }
1112 m_xSpaceFT->set_sensitive(!m_bPercentMode);
1113 m_xSpaceSFT->set_sensitive(!m_bPercentMode);
1114 m_xModifyTableCB->set_sensitive( !m_bPercentMode && m_bModifyTable );
1115 m_xProportionalCB->set_sensitive(!m_bPercentMode && m_bModifyTable );
1116
1117 m_xSpaceED->set_value(m_xSpaceED->normalize(
1118 m_pTableData->GetSpace() - m_nTableWidth), FieldUnit::TWIP);
1119 m_xSpaceSFT->set_label(m_xSpaceED->get_text());
1120
1121 }
1122
DeactivatePage(SfxItemSet * _pSet)1123 DeactivateRC SwTableColumnPage::DeactivatePage( SfxItemSet* _pSet )
1124 {
1125 if(_pSet)
1126 {
1127 FillItemSet(_pSet);
1128 if(text::HoriOrientation::FULL != m_pTableData->GetAlign() && m_pTableData->GetWidth() != m_nTableWidth)
1129 {
1130 m_pTableData->SetWidth(m_nTableWidth);
1131 SwTwips nDiff = m_pTableData->GetSpace() - m_pTableData->GetWidth() -
1132 m_pTableData->GetLeftSpace() - m_pTableData->GetRightSpace();
1133 switch( m_pTableData->GetAlign() )
1134 {
1135 case text::HoriOrientation::RIGHT:
1136 m_pTableData->SetLeftSpace(m_pTableData->GetLeftSpace() + nDiff);
1137 break;
1138 case text::HoriOrientation::LEFT:
1139 m_pTableData->SetRightSpace(m_pTableData->GetRightSpace() + nDiff);
1140 break;
1141 case text::HoriOrientation::NONE:
1142 {
1143 SwTwips nDiff2 = nDiff/2;
1144 if( nDiff > 0 ||
1145 (-nDiff2 < m_pTableData->GetRightSpace() && - nDiff2 < m_pTableData->GetLeftSpace()))
1146 {
1147 m_pTableData->SetRightSpace(m_pTableData->GetRightSpace() + nDiff2);
1148 m_pTableData->SetLeftSpace(m_pTableData->GetLeftSpace() + nDiff2);
1149 }
1150 else
1151 {
1152 if(m_pTableData->GetRightSpace() > m_pTableData->GetLeftSpace())
1153 {
1154 m_pTableData->SetLeftSpace(0);
1155 m_pTableData->SetRightSpace(m_pTableData->GetSpace() - m_pTableData->GetWidth());
1156 }
1157 else
1158 {
1159 m_pTableData->SetRightSpace(0);
1160 m_pTableData->SetLeftSpace(m_pTableData->GetSpace() - m_pTableData->GetWidth());
1161 }
1162 }
1163 }
1164 break;
1165 case text::HoriOrientation::CENTER:
1166 m_pTableData->SetRightSpace(m_pTableData->GetRightSpace() + nDiff/2);
1167 m_pTableData->SetLeftSpace(m_pTableData->GetLeftSpace() + nDiff/2);
1168 break;
1169 case text::HoriOrientation::LEFT_AND_WIDTH :
1170 if(nDiff > m_pTableData->GetRightSpace())
1171 {
1172 m_pTableData->SetLeftSpace(m_pTableData->GetSpace() - m_pTableData->GetWidth());
1173 }
1174 m_pTableData->SetRightSpace(
1175 m_pTableData->GetSpace() - m_pTableData->GetWidth() - m_pTableData->GetLeftSpace());
1176 break;
1177 }
1178 m_pTableData->SetWidthChanged();
1179 }
1180 _pSet->Put(SwPtrItem( FN_TABLE_REP, m_pTableData ));
1181 }
1182 return DeactivateRC::LeavePage;
1183 }
1184
GetVisibleWidth(sal_uInt16 nPos)1185 SwTwips SwTableColumnPage::GetVisibleWidth(sal_uInt16 nPos)
1186 {
1187 sal_uInt16 i=0;
1188
1189 while( nPos )
1190 {
1191 if(m_pTableData->GetColumns()[i].bVisible)
1192 nPos--;
1193 i++;
1194 }
1195 SwTwips nReturn = m_pTableData->GetColumns()[i].nWidth;
1196 OSL_ENSURE(i < m_nNoOfCols, "Array index out of range");
1197 while(!m_pTableData->GetColumns()[i].bVisible && (i + 1) < m_nNoOfCols)
1198 nReturn += m_pTableData->GetColumns()[++i].nWidth;
1199
1200 return nReturn;
1201 }
1202
SetVisibleWidth(sal_uInt16 nPos,SwTwips nNewWidth)1203 void SwTableColumnPage::SetVisibleWidth(sal_uInt16 nPos, SwTwips nNewWidth)
1204 {
1205 sal_uInt16 i=0;
1206 while( nPos )
1207 {
1208 if(m_pTableData->GetColumns()[i].bVisible)
1209 nPos--;
1210 i++;
1211 }
1212 OSL_ENSURE(i < m_nNoOfCols, "Array index out of range");
1213 m_pTableData->GetColumns()[i].nWidth = nNewWidth;
1214 while(!m_pTableData->GetColumns()[i].bVisible && (i + 1) < m_nNoOfCols)
1215 m_pTableData->GetColumns()[++i].nWidth = 0;
1216
1217 }
1218
SwTableTabDlg(weld::Window * pParent,const SfxItemSet * pItemSet,SwWrtShell * pSh)1219 SwTableTabDlg::SwTableTabDlg(weld::Window* pParent, const SfxItemSet* pItemSet, SwWrtShell* pSh)
1220 : SfxTabDialogController(pParent, u"modules/swriter/ui/tableproperties.ui"_ustr, u"TablePropertiesDialog"_ustr, pItemSet)
1221 , m_pShell(pSh)
1222 {
1223 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1224 AddTabPage(u"table"_ustr, &SwFormatTablePage::Create, nullptr);
1225 AddTabPage(u"textflow"_ustr, &SwTextFlowPage::Create, nullptr);
1226 AddTabPage(u"columns"_ustr, &SwTableColumnPage::Create, nullptr);
1227 AddTabPage(u"background"_ustr, pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BKG), nullptr);
1228 AddTabPage(u"borders"_ustr, pFact->GetTabPageCreatorFunc(RID_SVXPAGE_BORDER), nullptr);
1229 }
1230
PageCreated(const OUString & rId,SfxTabPage & rPage)1231 void SwTableTabDlg::PageCreated(const OUString& rId, SfxTabPage& rPage)
1232 {
1233 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
1234 if (rId == "background")
1235 {
1236 SvxBackgroundTabFlags const nFlagType = SvxBackgroundTabFlags::SHOW_TBLCTL;
1237 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, static_cast<sal_uInt32>(nFlagType)));
1238 rPage.PageCreated(aSet);
1239 }
1240 else if (rId == "borders")
1241 {
1242 aSet.Put (SfxUInt16Item(SID_SWMODE_TYPE, static_cast<sal_uInt16>(SwBorderModes::TABLE)));
1243 rPage.PageCreated(aSet);
1244 }
1245 else if (rId == "textflow")
1246 {
1247 static_cast<SwTextFlowPage&>(rPage).SetShell(m_pShell);
1248 const FrameTypeFlags eType = m_pShell->GetFrameType(nullptr,true);
1249 if( !(FrameTypeFlags::BODY & eType) )
1250 static_cast<SwTextFlowPage&>(rPage).DisablePageBreak();
1251 }
1252 }
1253
SwTextFlowPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rSet)1254 SwTextFlowPage::SwTextFlowPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
1255 : SfxTabPage(pPage, pController, u"modules/swriter/ui/tabletextflowpage.ui"_ustr, u"TableTextFlowPage"_ustr, &rSet)
1256 , m_pShell(nullptr)
1257 , m_bPageBreak(true)
1258 , m_bHtmlMode(false)
1259 , m_xPgBrkCB(m_xBuilder->weld_check_button(u"break"_ustr))
1260 , m_xPgBrkRB(m_xBuilder->weld_radio_button(u"page"_ustr))
1261 , m_xColBrkRB(m_xBuilder->weld_radio_button(u"column"_ustr))
1262 , m_xPgBrkBeforeRB(m_xBuilder->weld_radio_button(u"before"_ustr))
1263 , m_xPgBrkAfterRB(m_xBuilder->weld_radio_button(u"after"_ustr))
1264 , m_xPageCollCB(m_xBuilder->weld_check_button(u"pagestyle"_ustr))
1265 , m_xPageCollLB(m_xBuilder->weld_combo_box(u"pagestylelb"_ustr))
1266 , m_xPageNoCB(m_xBuilder->weld_check_button(u"pagenoft"_ustr))
1267 , m_xPageNoNF(m_xBuilder->weld_spin_button(u"pagenonf"_ustr))
1268 , m_xSplitCB(m_xBuilder->weld_check_button(u"split"_ustr))
1269 , m_xSplitRowCB(m_xBuilder->weld_check_button(u"splitrow"_ustr))
1270 , m_xKeepCB(m_xBuilder->weld_check_button(u"keep"_ustr))
1271 , m_xHeadLineCB(m_xBuilder->weld_check_button(u"headline"_ustr))
1272 , m_xRepeatHeaderCombo(m_xBuilder->weld_widget(u"repeatheader"_ustr))
1273 , m_xRepeatHeaderNF(m_xBuilder->weld_spin_button(u"repeatheadernf"_ustr))
1274 , m_xTextDirectionLB(m_xBuilder->weld_combo_box(u"textorientation"_ustr))
1275 , m_xVertOrientLB(m_xBuilder->weld_combo_box(u"vertorient"_ustr))
1276 {
1277 m_xPgBrkCB->connect_toggled(LINK(this, SwTextFlowPage, PageBreakHdl_Impl));
1278 m_xPgBrkBeforeRB->connect_toggled(
1279 LINK(this, SwTextFlowPage, PageBreakPosHdl_Impl));
1280 m_xPgBrkAfterRB->connect_toggled(
1281 LINK(this, SwTextFlowPage, PageBreakPosHdl_Impl));
1282 m_xPageCollCB->connect_toggled(
1283 LINK(this, SwTextFlowPage, ApplyCollClickHdl_Impl));
1284 m_xColBrkRB->connect_toggled(
1285 LINK(this, SwTextFlowPage, PageBreakTypeHdl_Impl));
1286 m_xPgBrkRB->connect_toggled(
1287 LINK(this, SwTextFlowPage, PageBreakTypeHdl_Impl));
1288 m_xPageNoCB->connect_toggled(
1289 LINK(this, SwTextFlowPage, PageNoClickHdl_Impl));
1290 m_xSplitCB->connect_toggled(
1291 LINK(this, SwTextFlowPage, SplitHdl_Impl));
1292 m_xHeadLineCB->connect_toggled(LINK(this, SwTextFlowPage, HeadLineCBClickHdl));
1293
1294 const SfxUInt16Item *pModeItem = rSet.GetItemIfSet( SID_HTML_MODE, false );
1295 if(pModeItem && pModeItem->GetValue() & HTMLMODE_ON)
1296 {
1297 m_xKeepCB->hide();
1298 m_xSplitCB->hide();
1299 m_xSplitRowCB->hide();
1300 }
1301
1302 HeadLineCBClickHdl(*m_xHeadLineCB);
1303 }
1304
~SwTextFlowPage()1305 SwTextFlowPage::~SwTextFlowPage()
1306 {
1307 }
1308
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rAttrSet)1309 std::unique_ptr<SfxTabPage> SwTextFlowPage::Create(weld::Container* pPage, weld::DialogController* pController,
1310 const SfxItemSet* rAttrSet)
1311 {
1312 return std::make_unique<SwTextFlowPage>(pPage, pController, *rAttrSet);
1313 }
1314
FillItemSet(SfxItemSet * rSet)1315 bool SwTextFlowPage::FillItemSet( SfxItemSet* rSet )
1316 {
1317 bool bModified = false;
1318
1319 //Repeat Heading
1320 if (m_xHeadLineCB->get_state_changed_from_saved() ||
1321 m_xRepeatHeaderNF->get_value_changed_from_saved() )
1322 {
1323 bModified |= nullptr != rSet->Put(
1324 SfxUInt16Item(FN_PARAM_TABLE_HEADLINE, m_xHeadLineCB->get_active() ? sal_uInt16(m_xRepeatHeaderNF->get_value()) : 0));
1325 }
1326 if (m_xKeepCB->get_state_changed_from_saved())
1327 bModified |= nullptr != rSet->Put( SvxFormatKeepItem( m_xKeepCB->get_active(), RES_KEEP));
1328
1329 if (m_xSplitCB->get_state_changed_from_saved())
1330 bModified |= nullptr != rSet->Put( SwFormatLayoutSplit( m_xSplitCB->get_active()));
1331
1332 if (m_xSplitRowCB->get_state_changed_from_saved())
1333 bModified |= nullptr != rSet->Put( SwFormatRowSplit( m_xSplitRowCB->get_active()));
1334
1335 const SvxFormatBreakItem* pBreak = GetOldItem( *rSet, RES_BREAK );
1336 const SwFormatPageDesc* pDesc = GetOldItem( *rSet, RES_PAGEDESC );
1337
1338 bool bState = m_xPageCollCB->get_active();
1339
1340 //If we have a page style, then there's no break
1341 bool bPageItemPut = false;
1342 if ( bState != (m_xPageCollCB->get_saved_state() == TRISTATE_TRUE)
1343 || (bState && m_xPageCollLB->get_value_changed_from_saved())
1344 || (m_xPageNoCB->get_sensitive() && m_xPageNoCB->get_state_changed_from_saved())
1345 || (m_xPageNoNF->get_sensitive() && m_xPageNoNF->get_value_changed_from_saved()))
1346 {
1347 OUString sPage;
1348
1349 if ( bState )
1350 {
1351 sPage = m_xPageCollLB->get_active_text();
1352 }
1353 sal_uInt16 nPgNum = o3tl::narrowing<sal_uInt16>(m_xPageNoNF->get_value());
1354 bool const usePageNo(bState && m_xPageNoCB->get_active());
1355 std::optional<sal_uInt16> const oPageNum(
1356 usePageNo ? nPgNum : std::optional<sal_Int16>());
1357 if (!pDesc || !pDesc->GetPageDesc()
1358 || (pDesc->GetPageDesc()->GetName() != sPage)
1359 || (pDesc->GetNumOffset() != oPageNum))
1360 {
1361 SwFormatPageDesc aFormat( m_pShell->FindPageDescByName( sPage, true ) );
1362 aFormat.SetNumOffset(oPageNum);
1363 bModified |= nullptr != rSet->Put( aFormat );
1364 bPageItemPut = bState;
1365 }
1366 }
1367 bool bIsChecked = m_xPgBrkCB->get_active();
1368 if ( !bPageItemPut &&
1369 ( bState != (m_xPageCollCB->get_saved_state() == TRISTATE_TRUE) ||
1370 bIsChecked != (m_xPgBrkCB->get_saved_state() == TRISTATE_TRUE) ||
1371 m_xPgBrkBeforeRB->get_state_changed_from_saved() ||
1372 m_xPgBrkRB->get_state_changed_from_saved() ))
1373 {
1374 SvxFormatBreakItem aBreak( GetItemSet().Get( RES_BREAK ) );
1375
1376 if(bIsChecked)
1377 {
1378 bool bBefore = m_xPgBrkBeforeRB->get_active();
1379
1380 if (m_xPgBrkRB->get_active())
1381 {
1382 if ( bBefore )
1383 aBreak.SetValue( SvxBreak::PageBefore );
1384 else
1385 aBreak.SetValue( SvxBreak::PageAfter );
1386 }
1387 else
1388 {
1389 if ( bBefore )
1390 aBreak.SetValue( SvxBreak::ColumnBefore );
1391 else
1392 aBreak.SetValue( SvxBreak::ColumnAfter );
1393 }
1394 }
1395 else
1396 {
1397 aBreak.SetValue( SvxBreak::NONE );
1398 }
1399
1400 if ( !pBreak || !( *pBreak == aBreak ) )
1401 {
1402 bModified |= nullptr != rSet->Put( aBreak );
1403 }
1404 }
1405
1406 if (m_xTextDirectionLB->get_value_changed_from_saved())
1407 {
1408 OUString sId = m_xTextDirectionLB->get_active_id();
1409 bModified |= nullptr != rSet->Put(SvxFrameDirectionItem(static_cast<SvxFrameDirection>(sId.toUInt32()), FN_TABLE_BOX_TEXTORIENTATION));
1410 }
1411
1412 if (m_xVertOrientLB->get_value_changed_from_saved())
1413 {
1414 sal_uInt16 nOrient = USHRT_MAX;
1415 switch (m_xVertOrientLB->get_active())
1416 {
1417 case 0 : nOrient = text::VertOrientation::NONE; break;
1418 case 1 : nOrient = text::VertOrientation::CENTER; break;
1419 case 2 : nOrient = text::VertOrientation::BOTTOM; break;
1420 }
1421 if (nOrient != USHRT_MAX)
1422 bModified |= nullptr != rSet->Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, nOrient));
1423 }
1424
1425 return bModified;
1426
1427 }
1428
Reset(const SfxItemSet * rSet)1429 void SwTextFlowPage::Reset( const SfxItemSet* rSet )
1430 {
1431 bool bFlowAllowed = !m_bHtmlMode || officecfg::Office::Common::Filter::HTML::Export::PrintLayout::get();
1432 if(bFlowAllowed)
1433 {
1434 //Inserting of the existing page templates in the list box
1435 const size_t nCount = m_pShell->GetPageDescCnt();
1436
1437 for( size_t i = 0; i < nCount; ++i)
1438 {
1439 const SwPageDesc &rPageDesc = m_pShell->GetPageDesc(i);
1440 m_xPageCollLB->append_text(rPageDesc.GetName());
1441 }
1442
1443 OUString aFormatName;
1444 for (sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
1445 {
1446 aFormatName = SwStyleNameMapper::GetUIName(i, aFormatName);
1447 if (m_xPageCollLB->find_text(aFormatName) == -1)
1448 m_xPageCollLB->append_text(aFormatName);
1449 }
1450
1451 if(const SvxFormatKeepItem* pKeepItem = rSet->GetItemIfSet( RES_KEEP, false ))
1452 {
1453 m_xKeepCB->set_active( pKeepItem->GetValue() );
1454 m_xKeepCB->save_state();
1455 }
1456 if(const SwFormatLayoutSplit* pSplitItem = rSet->GetItemIfSet( RES_LAYOUT_SPLIT, false ))
1457 {
1458 m_xSplitCB->set_active( pSplitItem->GetValue() );
1459 }
1460 else
1461 m_xSplitCB->set_active(true);
1462
1463 m_xSplitCB->save_state();
1464 SplitHdl_Impl(*m_xSplitCB);
1465
1466 if(const SwFormatRowSplit* pSplitItem = rSet->GetItemIfSet( RES_ROW_SPLIT, false ))
1467 {
1468 m_xSplitRowCB->set_active( pSplitItem->GetValue() );
1469 }
1470 else
1471 m_xSplitRowCB->set_state(TRISTATE_INDET);
1472 m_xSplitRowCB->save_state();
1473
1474 if(m_bPageBreak)
1475 {
1476 if(const SwFormatPageDesc* pPageDescItem = rSet->GetItemIfSet( RES_PAGEDESC, false ))
1477 {
1478 OUString sPageDesc;
1479 const SwPageDesc* pDesc = pPageDescItem->GetPageDesc();
1480
1481 ::std::optional<sal_uInt16> oNumOffset = pPageDescItem->GetNumOffset();
1482 if (oNumOffset)
1483 {
1484 m_xPageNoCB->set_active(true);
1485 m_xPageNoNF->set_sensitive(true);
1486 m_xPageNoNF->set_value(*oNumOffset);
1487 }
1488 else
1489 {
1490 m_xPageNoCB->set_active(false);
1491 m_xPageNoNF->set_sensitive(false);
1492 }
1493
1494 if(pDesc)
1495 sPageDesc = pDesc->GetName();
1496 if (!sPageDesc.isEmpty() && m_xPageCollLB->find_text(sPageDesc) != -1)
1497 {
1498 m_xPageCollLB->set_active_text(sPageDesc);
1499 m_xPageCollCB->set_active(true);
1500
1501 m_xPgBrkCB->set_sensitive(true);
1502 m_xPgBrkRB->set_sensitive(true);
1503 m_xColBrkRB->set_sensitive(true);
1504 m_xPgBrkBeforeRB->set_sensitive(true);
1505 m_xPgBrkAfterRB->set_sensitive(true);
1506 m_xPageCollCB->set_sensitive(true);
1507
1508 m_xPgBrkCB->set_active(true);
1509 m_xColBrkRB->set_active( false );
1510 m_xPgBrkBeforeRB->set_active(true);
1511 m_xPgBrkAfterRB->set_active( false );
1512 }
1513 else
1514 {
1515 m_xPageCollLB->set_active(-1);
1516 m_xPageCollCB->set_active(false);
1517 }
1518 }
1519
1520 if(const SvxFormatBreakItem* pPageBreak = rSet->GetItemIfSet( RES_BREAK, false ))
1521 {
1522 SvxBreak eBreak = pPageBreak->GetBreak();
1523
1524 if ( eBreak != SvxBreak::NONE )
1525 {
1526 m_xPgBrkCB->set_active(true);
1527 m_xPageCollCB->set_sensitive(false);
1528 m_xPageCollLB->set_sensitive(false);
1529 m_xPageNoCB->set_sensitive(false);
1530 m_xPageNoNF->set_sensitive(false);
1531 }
1532 switch ( eBreak )
1533 {
1534 case SvxBreak::PageBefore:
1535 m_xPgBrkRB->set_active(true);
1536 m_xColBrkRB->set_active( false );
1537 m_xPgBrkBeforeRB->set_active(true);
1538 m_xPgBrkAfterRB->set_active( false );
1539 break;
1540 case SvxBreak::PageAfter:
1541 m_xPgBrkRB->set_active(true);
1542 m_xColBrkRB->set_active( false );
1543 m_xPgBrkBeforeRB->set_active( false );
1544 m_xPgBrkAfterRB->set_active(true);
1545 break;
1546 case SvxBreak::ColumnBefore:
1547 m_xPgBrkRB->set_active( false );
1548 m_xColBrkRB->set_active(true);
1549 m_xPgBrkBeforeRB->set_active(true);
1550 m_xPgBrkAfterRB->set_active( false );
1551 break;
1552 case SvxBreak::ColumnAfter:
1553 m_xPgBrkRB->set_active( false );
1554 m_xColBrkRB->set_active(true);
1555 m_xPgBrkBeforeRB->set_active( false );
1556 m_xPgBrkAfterRB->set_active(true);
1557 break;
1558 default:; //prevent warning
1559 }
1560
1561 }
1562 if (m_xPgBrkBeforeRB->get_active())
1563 PageBreakPosHdl_Impl(*m_xPgBrkBeforeRB);
1564 else if (m_xPgBrkAfterRB->get_active())
1565 PageBreakPosHdl_Impl(*m_xPgBrkAfterRB);
1566 PageBreakHdl_Impl(*m_xPgBrkCB);
1567 }
1568 }
1569 else
1570 {
1571 m_xPgBrkRB->set_sensitive(false);
1572 m_xColBrkRB->set_sensitive(false);
1573 m_xPgBrkBeforeRB->set_sensitive(false);
1574 m_xPgBrkAfterRB->set_sensitive(false);
1575 m_xKeepCB->set_sensitive(false);
1576 m_xSplitCB->set_sensitive(false);
1577 m_xPgBrkCB->set_sensitive(false);
1578 m_xPageCollCB->set_sensitive(false);
1579 m_xPageCollLB->set_sensitive(false);
1580 }
1581
1582 if(const SfxUInt16Item* pHeadlineItem = rSet->GetItemIfSet( FN_PARAM_TABLE_HEADLINE, false ))
1583 {
1584 sal_uInt16 nRep = pHeadlineItem->GetValue();
1585 m_xHeadLineCB->set_active(nRep > 0);
1586 m_xHeadLineCB->save_state();
1587 m_xRepeatHeaderNF->set_value(nRep);
1588 m_xRepeatHeaderNF->set_min(1);
1589 m_xRepeatHeaderNF->save_value();
1590 }
1591 if ( rSet->GetItemState(FN_TABLE_BOX_TEXTORIENTATION) > SfxItemState::DEFAULT )
1592 {
1593 SvxFrameDirection nDirection = rSet->Get(FN_TABLE_BOX_TEXTORIENTATION).GetValue();
1594 m_xTextDirectionLB->set_active_id(OUString::number(static_cast<sal_uInt32>(nDirection)));
1595 }
1596
1597 if ( rSet->GetItemState(FN_TABLE_SET_VERT_ALIGN) > SfxItemState::DEFAULT )
1598 {
1599 sal_uInt16 nVert = rSet->Get(FN_TABLE_SET_VERT_ALIGN).GetValue();
1600 sal_uInt16 nPos = 0;
1601 switch(nVert)
1602 {
1603 case text::VertOrientation::NONE: nPos = 0; break;
1604 case text::VertOrientation::CENTER: nPos = 1; break;
1605 case text::VertOrientation::BOTTOM: nPos = 2; break;
1606 }
1607 m_xVertOrientLB->set_active(nPos);
1608 }
1609
1610 m_xPageCollCB->save_state();
1611 m_xPageCollLB->save_value();
1612 m_xPgBrkCB->save_state();
1613 m_xPgBrkRB->save_state();
1614 m_xColBrkRB->save_state();
1615 m_xPgBrkBeforeRB->save_state();
1616 m_xPgBrkAfterRB->save_state();
1617 m_xPageNoCB->save_state();
1618 m_xPageNoNF->save_value();
1619 m_xTextDirectionLB->save_value();
1620 m_xVertOrientLB->save_value();
1621
1622 HeadLineCBClickHdl(*m_xHeadLineCB);
1623 }
1624
SetShell(SwWrtShell * pSh)1625 void SwTextFlowPage::SetShell(SwWrtShell* pSh)
1626 {
1627 m_pShell = pSh;
1628 m_bHtmlMode = 0 != (::GetHtmlMode(m_pShell->GetView().GetDocShell()) & HTMLMODE_ON);
1629 if(m_bHtmlMode)
1630 {
1631 m_xPageNoNF->set_sensitive(false);
1632 m_xPageNoCB->set_sensitive(false);
1633 }
1634 }
1635
IMPL_LINK_NOARG(SwTextFlowPage,PageBreakHdl_Impl,weld::Toggleable &,void)1636 IMPL_LINK_NOARG(SwTextFlowPage, PageBreakHdl_Impl, weld::Toggleable&, void)
1637 {
1638 if (m_xPgBrkCB->get_active())
1639 {
1640 m_xPgBrkRB->set_sensitive(true);
1641 m_xColBrkRB->set_sensitive(true);
1642 m_xPgBrkBeforeRB->set_sensitive(true);
1643 m_xPgBrkAfterRB->set_sensitive(true);
1644
1645 if (m_xPgBrkRB->get_active() && m_xPgBrkBeforeRB->get_active())
1646 {
1647 m_xPageCollCB->set_sensitive(true);
1648
1649 bool bEnable = m_xPageCollCB->get_active() && m_xPageCollLB->get_count();
1650 m_xPageCollLB->set_sensitive(bEnable);
1651 if (!m_bHtmlMode)
1652 {
1653 m_xPageNoCB->set_sensitive(bEnable);
1654 m_xPageNoNF->set_sensitive(bEnable && m_xPageNoCB->get_active());
1655 }
1656 }
1657 }
1658 else
1659 {
1660 m_xPageCollCB->set_active(false);
1661 m_xPageCollCB->set_sensitive(false);
1662 m_xPageCollLB->set_sensitive(false);
1663 m_xPageNoCB->set_sensitive(false);
1664 m_xPageNoNF->set_sensitive(false);
1665 m_xPgBrkRB->set_sensitive(false);
1666 m_xColBrkRB->set_sensitive(false);
1667 m_xPgBrkBeforeRB->set_sensitive(false);
1668 m_xPgBrkAfterRB->set_sensitive(false);
1669 }
1670 }
1671
IMPL_LINK_NOARG(SwTextFlowPage,ApplyCollClickHdl_Impl,weld::Toggleable &,void)1672 IMPL_LINK_NOARG(SwTextFlowPage, ApplyCollClickHdl_Impl, weld::Toggleable&, void)
1673 {
1674 bool bEnable = false;
1675 if (m_xPageCollCB->get_active() && m_xPageCollLB->get_count())
1676 {
1677 bEnable = true;
1678 m_xPageCollLB->set_active(0);
1679 }
1680 else
1681 {
1682 m_xPageCollLB->set_active(-1);
1683 }
1684 m_xPageCollLB->set_sensitive(bEnable);
1685 if (!m_bHtmlMode)
1686 {
1687 m_xPageNoCB->set_sensitive(bEnable);
1688 m_xPageNoNF->set_sensitive(bEnable && m_xPageNoCB->get_active());
1689 }
1690 }
1691
IMPL_LINK_NOARG(SwTextFlowPage,PageBreakPosHdl_Impl,weld::Toggleable &,void)1692 IMPL_LINK_NOARG(SwTextFlowPage, PageBreakPosHdl_Impl, weld::Toggleable&, void)
1693 {
1694 if (!m_xPgBrkCB->get_active())
1695 return;
1696
1697 if (m_xPgBrkBeforeRB->get_active() && m_xPgBrkRB->get_active())
1698 {
1699 m_xPageCollCB->set_sensitive(true);
1700
1701 bool bEnable = m_xPageCollCB->get_active() && m_xPageCollLB->get_count();
1702
1703 m_xPageCollLB->set_sensitive(bEnable);
1704 if (!m_bHtmlMode)
1705 {
1706 m_xPageNoCB->set_sensitive(bEnable);
1707 m_xPageNoNF->set_sensitive(bEnable && m_xPageNoCB->get_active());
1708 }
1709 }
1710 else if (m_xPgBrkAfterRB->get_active())
1711 {
1712 m_xPageCollCB->set_active(false);
1713 m_xPageCollCB->set_sensitive(false);
1714 m_xPageCollLB->set_sensitive(false);
1715 m_xPageNoCB->set_sensitive(false);
1716 m_xPageNoNF->set_sensitive(false);
1717 }
1718 }
1719
IMPL_LINK_NOARG(SwTextFlowPage,PageBreakTypeHdl_Impl,weld::Toggleable &,void)1720 IMPL_LINK_NOARG(SwTextFlowPage, PageBreakTypeHdl_Impl, weld::Toggleable&, void)
1721 {
1722 if (m_xColBrkRB->get_active() || m_xPgBrkAfterRB->get_active())
1723 {
1724 m_xPageCollCB->set_active(false);
1725 m_xPageCollCB->set_sensitive(false);
1726 m_xPageCollLB->set_sensitive(false);
1727 m_xPageNoCB->set_sensitive(false);
1728 m_xPageNoNF->set_sensitive(false);
1729 }
1730 else if (m_xPgBrkBeforeRB->get_active())
1731 PageBreakPosHdl_Impl(*m_xPgBrkBeforeRB);
1732 }
1733
IMPL_LINK_NOARG(SwTextFlowPage,PageNoClickHdl_Impl,weld::Toggleable &,void)1734 IMPL_LINK_NOARG(SwTextFlowPage, PageNoClickHdl_Impl, weld::Toggleable&, void)
1735 {
1736 m_xPageNoNF->set_sensitive(m_xPageNoCB->get_active());
1737 }
1738
IMPL_LINK(SwTextFlowPage,SplitHdl_Impl,weld::Toggleable &,rBox,void)1739 IMPL_LINK(SwTextFlowPage, SplitHdl_Impl, weld::Toggleable&, rBox, void)
1740 {
1741 m_xSplitRowCB->set_sensitive(rBox.get_active());
1742 }
1743
IMPL_LINK_NOARG(SwTextFlowPage,HeadLineCBClickHdl,weld::Toggleable &,void)1744 IMPL_LINK_NOARG(SwTextFlowPage, HeadLineCBClickHdl, weld::Toggleable&, void)
1745 {
1746 m_xRepeatHeaderCombo->set_sensitive(m_xHeadLineCB->get_active());
1747 }
1748
DisablePageBreak()1749 void SwTextFlowPage::DisablePageBreak()
1750 {
1751 m_bPageBreak = false;
1752 m_xPgBrkCB->set_sensitive(false);
1753 m_xPgBrkRB->set_sensitive(false);
1754 m_xColBrkRB->set_sensitive(false);
1755 m_xPgBrkBeforeRB->set_sensitive(false);
1756 m_xPgBrkAfterRB->set_sensitive(false);
1757 m_xPageCollCB->set_sensitive(false);
1758 m_xPageCollLB->set_sensitive(false);
1759 m_xPageNoCB->set_sensitive(false);
1760 m_xPageNoNF->set_sensitive(false);
1761 }
1762
1763 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1764