android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / frmdlg / column.cxx
blob028b9f1b209a79642934eac40ce5976c86370d08
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 <column.hxx>
22 #include <hintids.hxx>
23 #include <svx/dialmgr.hxx>
24 #include <svx/strings.hrc>
25 #include <sfx2/htmlmode.hxx>
26 #include <svx/colorbox.hxx>
27 #include <editeng/borderline.hxx>
28 #include <editeng/boxitem.hxx>
29 #include <editeng/lrspitem.hxx>
30 #include <editeng/sizeitem.hxx>
31 #include <editeng/frmdiritem.hxx>
32 #include <editeng/ulspitem.hxx>
33 #include <svl/ctloptions.hxx>
34 #include <svl/itemset.hxx>
35 #include <sfx2/dispatch.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <vcl/event.hxx>
38 #include <vcl/fieldvalues.hxx>
39 #include <vcl/settings.hxx>
40 #include <vcl/svapp.hxx>
42 #include <swmodule.hxx>
44 #include <swtypes.hxx>
45 #include <wrtsh.hxx>
46 #include <view.hxx>
47 #include <docsh.hxx>
48 #include <uitool.hxx>
49 #include <cmdid.h>
50 #include <viewopt.hxx>
51 #include <fmtclbl.hxx>
52 #include <fmtfsize.hxx>
53 #include <frmatr.hxx>
54 #include <colmgr.hxx>
55 #include <prcntfld.hxx>
56 #include <strings.hrc>
57 #include <section.hxx>
58 #include <pagedesc.hxx>
60 //to match associated data in ColumnPage.ui
61 #define LISTBOX_SELECTION 0
62 #define LISTBOX_SECTION 1
63 #define LISTBOX_SECTIONS 2
64 #define LISTBOX_PAGE 3
65 #define LISTBOX_FRAME 4
67 using namespace ::com::sun::star;
69 #define FRAME_FORMAT_WIDTH 1000
71 // static data
72 const sal_uInt16 nVisCols = 3;
74 static bool IsMarkInSameSection( SwWrtShell& rWrtSh, const SwSection* pSect )
76 rWrtSh.SwapPam();
77 bool bRet = pSect == rWrtSh.GetCurrSection();
78 rWrtSh.SwapPam();
79 return bRet;
82 SwColumnDlg::SwColumnDlg(weld::Window* pParent, SwWrtShell& rSh)
83 : SfxDialogController(pParent, "modules/swriter/ui/columndialog.ui", "ColumnDialog")
84 , m_rWrtShell(rSh)
85 , m_pFrameSet(nullptr)
86 , m_nOldSelection(0)
87 , m_nSelectionWidth(0)
88 , m_bPageChanged(false)
89 , m_bSectionChanged(false)
90 , m_bSelSectionChanged(false)
91 , m_bFrameChanged(false)
92 , m_xContentArea(m_xBuilder->weld_container("content"))
93 , m_xOkButton(m_xBuilder->weld_button("ok"))
95 SwRect aRect;
96 m_rWrtShell.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
98 m_nSelectionWidth = aRect.Width();
100 SfxItemSet* pColPgSet = nullptr;
101 static const auto aSectIds = svl::Items<RES_FRM_SIZE, RES_FRM_SIZE,
102 RES_COL, RES_COL,
103 RES_COLUMNBALANCE, RES_FRAMEDIR>;
105 const SwSection* pCurrSection = m_rWrtShell.GetCurrSection();
106 const sal_uInt16 nFullSectCnt = m_rWrtShell.GetFullSelectedSectionCount();
107 if( pCurrSection && ( !m_rWrtShell.HasSelection() || 0 != nFullSectCnt ))
109 m_nSelectionWidth = rSh.GetSectionWidth(*pCurrSection->GetFormat());
110 if ( !m_nSelectionWidth )
111 m_nSelectionWidth = USHRT_MAX;
112 m_pSectionSet.reset( new SfxItemSet( m_rWrtShell.GetAttrPool(), aSectIds ) );
113 m_pSectionSet->Put( pCurrSection->GetFormat()->GetAttrSet() );
114 pColPgSet = m_pSectionSet.get();
117 if( m_rWrtShell.HasSelection() && m_rWrtShell.IsInsRegionAvailable() &&
118 ( !pCurrSection || ( 1 != nFullSectCnt &&
119 IsMarkInSameSection( m_rWrtShell, pCurrSection ) )))
121 m_pSelectionSet.reset( new SfxItemSet( m_rWrtShell.GetAttrPool(), aSectIds ) );
122 pColPgSet = m_pSelectionSet.get();
125 if( m_rWrtShell.GetFlyFrameFormat() )
127 const SwFrameFormat* pFormat = rSh.GetFlyFrameFormat() ;
128 m_pFrameSet = new SfxItemSet(m_rWrtShell.GetAttrPool(), aSectIds );
129 m_pFrameSet->Put(pFormat->GetFrameSize());
130 m_pFrameSet->Put(pFormat->GetCol());
131 pColPgSet = m_pFrameSet;
134 const SwPageDesc* pPageDesc = m_rWrtShell.GetSelectedPageDescs();
135 if( pPageDesc )
137 m_pPageSet = std::make_unique<SfxItemSetFixed<
138 RES_FRM_SIZE, RES_FRM_SIZE,
139 RES_LR_SPACE, RES_LR_SPACE,
140 RES_COL, RES_COL>>(m_rWrtShell.GetAttrPool());
142 const SwFrameFormat &rFormat = pPageDesc->GetMaster();
143 m_nPageWidth = rFormat.GetFrameSize().GetSize().Width();
145 const SvxLRSpaceItem& rLRSpace = rFormat.GetLRSpace();
146 const SvxBoxItem& rBox = rFormat.GetBox();
147 m_nPageWidth -= rLRSpace.GetLeft() + rLRSpace.GetRight() + rBox.GetSmallestDistance();
149 m_pPageSet->Put(rFormat.GetCol());
150 m_pPageSet->Put(rFormat.GetLRSpace());
151 pColPgSet = m_pPageSet.get();
154 assert(pColPgSet);
156 // create TabPage
157 m_xTabPage = std::make_unique<SwColumnPage>(m_xContentArea.get(), this, *pColPgSet);
158 m_xTabPage->GetApplyLabel()->show();
159 weld::ComboBox* pApplyToLB = m_xTabPage->GetApplyComboBox();
160 pApplyToLB->show();
162 if (pCurrSection && (!m_rWrtShell.HasSelection() || 0 != nFullSectCnt))
164 pApplyToLB->remove_id(1 >= nFullSectCnt ? OUString::number(LISTBOX_SECTIONS) : OUString::number(LISTBOX_SECTION));
166 else
168 pApplyToLB->remove_id(OUString::number(LISTBOX_SECTION));
169 pApplyToLB->remove_id(OUString::number(LISTBOX_SECTIONS));
172 if (!( m_rWrtShell.HasSelection() && m_rWrtShell.IsInsRegionAvailable() &&
173 ( !pCurrSection || ( 1 != nFullSectCnt &&
174 IsMarkInSameSection( m_rWrtShell, pCurrSection ) ))))
175 pApplyToLB->remove_id(OUString::number(LISTBOX_SELECTION));
177 if (!m_rWrtShell.GetFlyFrameFormat())
178 pApplyToLB->remove_id(OUString::number(LISTBOX_FRAME));
180 const int nPagePos = pApplyToLB->find_id(OUString::number(LISTBOX_PAGE));
181 if (m_pPageSet && pPageDesc)
183 const OUString sPageStr = pApplyToLB->get_text(nPagePos) + pPageDesc->GetName();
184 pApplyToLB->remove(nPagePos);
185 OUString sId(OUString::number(LISTBOX_PAGE));
186 pApplyToLB->insert(nPagePos, sPageStr, &sId, nullptr, nullptr);
188 else
189 pApplyToLB->remove( nPagePos );
191 pApplyToLB->set_active(0);
192 ObjectHdl(nullptr);
194 pApplyToLB->connect_changed(LINK(this, SwColumnDlg, ObjectListBoxHdl));
195 m_xOkButton->connect_clicked(LINK(this, SwColumnDlg, OkHdl));
196 //#i80458# if no columns can be set then disable OK
197 if (!pApplyToLB->get_count())
198 m_xOkButton->set_sensitive(false);
199 //#i97810# set focus to the TabPage
200 m_xTabPage->ActivateColumnControl();
203 SwColumnDlg::~SwColumnDlg()
205 m_xTabPage.reset();
208 IMPL_LINK(SwColumnDlg, ObjectListBoxHdl, weld::ComboBox&, rBox, void)
210 ObjectHdl(&rBox);
213 void SwColumnDlg::ObjectHdl(const weld::ComboBox* pBox)
215 SfxItemSet* pSet = EvalCurrentSelection();
217 if (pBox)
219 m_xTabPage->FillItemSet(pSet);
221 weld::ComboBox* pApplyToLB = m_xTabPage->GetApplyComboBox();
222 m_nOldSelection = pApplyToLB->get_active_id().toInt32();
223 tools::Long nWidth = m_nSelectionWidth;
224 switch(m_nOldSelection)
226 case LISTBOX_SELECTION :
227 pSet = m_pSelectionSet.get();
228 if( m_pSelectionSet )
229 pSet->Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth, nWidth));
230 break;
231 case LISTBOX_SECTION :
232 case LISTBOX_SECTIONS :
233 pSet = m_pSectionSet.get();
234 pSet->Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth, nWidth));
235 break;
236 case LISTBOX_PAGE :
237 nWidth = m_nPageWidth;
238 pSet = m_pPageSet.get();
239 pSet->Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth, nWidth));
240 break;
241 case LISTBOX_FRAME:
242 pSet = m_pFrameSet;
243 break;
246 bool bIsSection = pSet == m_pSectionSet.get() || pSet == m_pSelectionSet.get();
247 m_xTabPage->ShowBalance(bIsSection);
248 m_xTabPage->SetInSection(bIsSection);
249 m_xTabPage->SetFrameMode(true);
250 m_xTabPage->SetPageWidth(nWidth);
251 if( pSet )
252 m_xTabPage->Reset(pSet);
255 IMPL_LINK_NOARG(SwColumnDlg, OkHdl, weld::Button&, void)
257 // evaluate current selection
258 SfxItemSet* pSet = EvalCurrentSelection();
259 m_xTabPage->FillItemSet(pSet);
261 if(m_pSelectionSet && SfxItemState::SET == m_pSelectionSet->GetItemState(RES_COL))
263 //insert region with columns
264 const SwFormatCol& rColItem = m_pSelectionSet->Get(RES_COL);
265 //only if there actually are columns!
266 if(rColItem.GetNumCols() > 1)
267 m_rWrtShell.GetView().GetViewFrame().GetDispatcher()->Execute(
268 FN_INSERT_REGION, SfxCallMode::ASYNCHRON, *m_pSelectionSet );
271 if(m_pSectionSet && m_pSectionSet->Count() && m_bSectionChanged )
273 const SwSection* pCurrSection = m_rWrtShell.GetCurrSection();
274 const SwSectionFormat* pFormat = pCurrSection->GetFormat();
275 const size_t nNewPos = m_rWrtShell.GetSectionFormatPos( *pFormat );
276 SwSectionData aData(*pCurrSection);
277 m_rWrtShell.UpdateSection( nNewPos, aData, m_pSectionSet.get() );
280 if(m_pSectionSet && m_pSectionSet->Count() && m_bSelSectionChanged )
282 m_rWrtShell.SetSectionAttr( *m_pSectionSet );
285 if(m_pPageSet && SfxItemState::SET == m_pPageSet->GetItemState(RES_COL) && m_bPageChanged)
287 // determine current PageDescriptor and fill the Set with it
288 const size_t nCurIdx = m_rWrtShell.GetCurPageDesc();
289 SwPageDesc aPageDesc(m_rWrtShell.GetPageDesc(nCurIdx));
290 SwFrameFormat &rFormat = aPageDesc.GetMaster();
291 rFormat.SetFormatAttr(m_pPageSet->Get(RES_COL));
292 m_rWrtShell.ChgPageDesc(nCurIdx, aPageDesc);
294 if(m_pFrameSet && SfxItemState::SET == m_pFrameSet->GetItemState(RES_COL) && m_bFrameChanged)
296 SfxItemSetFixed<RES_COL, RES_COL> aTmp(*m_pFrameSet->GetPool());
297 aTmp.Put(*m_pFrameSet);
298 m_rWrtShell.StartAction();
299 m_rWrtShell.Push();
300 m_rWrtShell.SetFlyFrameAttr( aTmp );
301 // undo the frame selection again
302 if(m_rWrtShell.IsFrameSelected())
304 m_rWrtShell.UnSelectFrame();
305 m_rWrtShell.LeaveSelFrameMode();
307 m_rWrtShell.Pop();
308 m_rWrtShell.EndAction();
310 m_xDialog->response(RET_OK);
313 SfxItemSet* SwColumnDlg::EvalCurrentSelection()
315 SfxItemSet* pSet = nullptr;
317 switch(m_nOldSelection)
319 case LISTBOX_SELECTION :
320 pSet = m_pSelectionSet.get();
321 break;
322 case LISTBOX_SECTION :
323 pSet = m_pSectionSet.get();
324 m_bSectionChanged = true;
325 break;
326 case LISTBOX_SECTIONS :
327 pSet = m_pSectionSet.get();
328 m_bSelSectionChanged = true;
329 break;
330 case LISTBOX_PAGE :
331 pSet = m_pPageSet.get();
332 m_bPageChanged = true;
333 break;
334 case LISTBOX_FRAME:
335 pSet = m_pFrameSet;
336 m_bFrameChanged = true;
337 break;
340 return pSet;
343 static
344 sal_uInt16 GetMaxWidth( SwColMgr const * pColMgr, sal_uInt16 nCols )
346 sal_uInt16 nMax = pColMgr->GetActualSize();
347 if( --nCols )
348 nMax -= pColMgr->GetGutterWidth() * nCols;
349 return nMax;
352 const WhichRangesContainer SwColumnPage::s_aPageRg(svl::Items<RES_COL, RES_COL>);
354 void SwColumnPage::ResetColWidth()
356 if( m_nCols )
358 const sal_uInt16 nWidth = GetMaxWidth( m_xColMgr.get(), m_nCols ) / m_nCols;
360 for(sal_uInt16 i = 0; i < m_nCols; ++i)
361 m_nColWidth[i] = static_cast<tools::Long>(nWidth);
366 constexpr sal_uInt16 g_nMinWidth(MINLAY);
368 // Now as TabPage
369 SwColumnPage::SwColumnPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet)
370 : SfxTabPage(pPage, pController, "modules/swriter/ui/columnpage.ui", "ColumnPage", &rSet)
371 , m_nFirstVis(0)
372 , m_pModifiedField(nullptr)
373 , m_bFormat(false)
374 , m_bFrame(false)
375 , m_bHtmlMode(false)
376 , m_bLockUpdate(false)
377 , m_xCLNrEdt(m_xBuilder->weld_spin_button("colsnf"))
378 , m_xBalanceColsCB(m_xBuilder->weld_check_button("balance"))
379 , m_xBtnBack(m_xBuilder->weld_button("back"))
380 , m_xLbl1(m_xBuilder->weld_label("1"))
381 , m_xLbl2(m_xBuilder->weld_label("2"))
382 , m_xLbl3(m_xBuilder->weld_label("3"))
383 , m_xBtnNext(m_xBuilder->weld_button("next"))
384 , m_xAutoWidthBox(m_xBuilder->weld_check_button("autowidth"))
385 , m_xLineTypeLbl(m_xBuilder->weld_label("linestyleft"))
386 , m_xLineWidthLbl(m_xBuilder->weld_label("linewidthft"))
387 , m_xLineWidthEdit(m_xBuilder->weld_metric_spin_button("linewidthmf", FieldUnit::POINT))
388 , m_xLineColorLbl(m_xBuilder->weld_label("linecolorft"))
389 , m_xLineHeightLbl(m_xBuilder->weld_label("lineheightft"))
390 , m_xLineHeightEdit(m_xBuilder->weld_metric_spin_button("lineheightmf", FieldUnit::PERCENT))
391 , m_xLinePosLbl(m_xBuilder->weld_label("lineposft"))
392 , m_xLinePosDLB(m_xBuilder->weld_combo_box("lineposlb"))
393 , m_xTextDirectionFT(m_xBuilder->weld_label("textdirectionft"))
394 , m_xTextDirectionLB(new svx::FrameDirectionListBox(m_xBuilder->weld_combo_box("textdirectionlb")))
395 , m_xLineColorDLB(new ColorListBox(m_xBuilder->weld_menu_button("colorlb"),
396 [this]{ return GetDialogController()->getDialog(); }))
397 , m_xLineTypeDLB(new SvtLineListBox(m_xBuilder->weld_menu_button("linestylelb")))
398 , m_xEd1(new SwPercentField(m_xBuilder->weld_metric_spin_button("width1mf", FieldUnit::CM)))
399 , m_xEd2(new SwPercentField(m_xBuilder->weld_metric_spin_button("width2mf", FieldUnit::CM)))
400 , m_xEd3(new SwPercentField(m_xBuilder->weld_metric_spin_button("width3mf", FieldUnit::CM)))
401 , m_xDistEd1(new SwPercentField(m_xBuilder->weld_metric_spin_button("spacing1mf", FieldUnit::CM)))
402 , m_xDistEd2(new SwPercentField(m_xBuilder->weld_metric_spin_button("spacing2mf", FieldUnit::CM)))
403 , m_xDefaultVS(new weld::CustomWeld(*m_xBuilder, "valueset", m_aDefaultVS))
404 , m_xPgeExampleWN(new weld::CustomWeld(*m_xBuilder, "pageexample", m_aPgeExampleWN))
405 , m_xFrameExampleWN(new weld::CustomWeld(*m_xBuilder, "frameexample", m_aFrameExampleWN))
406 , m_xApplyToFT(m_xBuilder->weld_label("applytoft"))
407 , m_xApplyToLB(m_xBuilder->weld_combo_box("applytolb"))
409 connectPercentField(*m_xEd1);
410 connectPercentField(*m_xEd2);
411 connectPercentField(*m_xEd3);
412 connectPercentField(*m_xDistEd1);
413 connectPercentField(*m_xDistEd2);
415 m_xTextDirectionLB->append(SvxFrameDirection::Horizontal_LR_TB, SvxResId(RID_SVXSTR_FRAMEDIR_LTR));
416 m_xTextDirectionLB->append(SvxFrameDirection::Horizontal_RL_TB, SvxResId(RID_SVXSTR_FRAMEDIR_RTL));
417 m_xTextDirectionLB->append(SvxFrameDirection::Environment, SvxResId(RID_SVXSTR_FRAMEDIR_SUPER));
419 SetExchangeSupport();
421 m_aDefaultVS.SetColCount(5);
423 for (int i = 0; i < 5; ++i)
424 //Set accessible name one by one
426 OUString aItemText;
427 switch( i )
429 case 0:
430 aItemText = SwResId( STR_COLUMN_VALUESET_ITEM0 ) ;
431 break;
432 case 1:
433 aItemText = SwResId( STR_COLUMN_VALUESET_ITEM1 ) ;
434 break;
435 case 2:
436 aItemText = SwResId( STR_COLUMN_VALUESET_ITEM2 ) ;
437 break;
438 case 3:
439 aItemText = SwResId( STR_COLUMN_VALUESET_ITEM3 );
440 break;
441 default:
442 aItemText = SwResId( STR_COLUMN_VALUESET_ITEM4 );
443 break;
445 m_aDefaultVS.InsertItem( i + 1, aItemText, i );
448 m_aDefaultVS.SetSelectHdl(LINK(this, SwColumnPage, SetDefaultsHdl));
450 Link<weld::SpinButton&,void> aCLNrLk = LINK(this, SwColumnPage, ColModify);
451 m_xCLNrEdt->connect_value_changed(aCLNrLk);
452 Link<weld::MetricSpinButton&,void> aLk = LINK(this, SwColumnPage, GapModify);
453 m_xDistEd1->connect_value_changed(aLk);
454 m_xDistEd2->connect_value_changed(aLk);
456 aLk = LINK(this, SwColumnPage, EdModify);
458 m_xEd1->connect_value_changed(aLk);
459 m_xEd2->connect_value_changed(aLk);
460 m_xEd3->connect_value_changed(aLk);
462 m_xBtnBack->connect_clicked(LINK(this, SwColumnPage, Up));
463 m_xBtnNext->connect_clicked(LINK(this, SwColumnPage, Down));
464 m_xAutoWidthBox->connect_toggled(LINK(this, SwColumnPage, AutoWidthHdl));
466 Link<weld::MetricSpinButton&,void> aLk2 = LINK( this, SwColumnPage, UpdateColMgr );
467 m_xLineTypeDLB->SetSelectHdl(LINK(this, SwColumnPage, UpdateColMgrLineBox));
468 m_xLineWidthEdit->connect_value_changed(aLk2);
469 m_xLineColorDLB->SetSelectHdl(LINK( this, SwColumnPage, UpdateColMgrColorBox));
470 m_xLineHeightEdit->connect_value_changed(aLk2);
471 m_xLinePosDLB->connect_changed(LINK(this, SwColumnPage, UpdateColMgrListBox));
473 // Separator line
474 m_xLineTypeDLB->SetSourceUnit( FieldUnit::TWIP );
476 // Fill the line styles listbox
477 m_xLineTypeDLB->InsertEntry(
478 ::editeng::SvxBorderLine::getWidthImpl(SvxBorderLineStyle::SOLID),
479 SvxBorderLineStyle::SOLID );
480 m_xLineTypeDLB->InsertEntry(
481 ::editeng::SvxBorderLine::getWidthImpl(SvxBorderLineStyle::DOTTED),
482 SvxBorderLineStyle::DOTTED );
483 m_xLineTypeDLB->InsertEntry(
484 ::editeng::SvxBorderLine::getWidthImpl(SvxBorderLineStyle::DASHED),
485 SvxBorderLineStyle::DASHED );
487 sal_Int64 nLineWidth = m_xLineWidthEdit->get_value(FieldUnit::POINT);
488 nLineWidth = static_cast<tools::Long>(vcl::ConvertDoubleValue(
489 nLineWidth,
490 m_xLineWidthEdit->get_digits(),
491 FieldUnit::POINT, MapUnit::MapTwip ));
492 m_xLineTypeDLB->SetWidth(nLineWidth);
493 m_xLineColorDLB->SelectEntry(COL_BLACK);
496 SwColumnPage::~SwColumnPage()
498 m_xFrameExampleWN.reset();
499 m_xPgeExampleWN.reset();
500 m_xDefaultVS.reset();
501 m_xDistEd2.reset();
502 m_xDistEd1.reset();
503 m_xEd3.reset();
504 m_xEd2.reset();
505 m_xEd1.reset();
506 m_xLineTypeDLB.reset();
507 m_xLineColorDLB.reset();
508 m_xTextDirectionLB.reset();
511 void SwColumnPage::SetPageWidth(tools::Long nPageWidth)
513 tools::Long nNewMaxWidth = static_cast< tools::Long >(m_xEd1->NormalizePercent(nPageWidth));
515 m_xDistEd1->set_max(nNewMaxWidth, FieldUnit::TWIP);
516 m_xDistEd2->set_max(nNewMaxWidth, FieldUnit::TWIP);
517 m_xEd1->set_max(nNewMaxWidth, FieldUnit::TWIP);
518 m_xEd2->set_max(nNewMaxWidth, FieldUnit::TWIP);
519 m_xEd3->set_max(nNewMaxWidth, FieldUnit::TWIP);
522 void SwColumnPage::connectPercentField(SwPercentField &rWrap)
524 weld::MetricSpinButton *pField = rWrap.get();
525 assert(pField);
526 m_aPercentFieldsMap[pField] = &rWrap;
529 void SwColumnPage::Reset(const SfxItemSet *rSet)
531 const sal_uInt16 nHtmlMode =
532 ::GetHtmlMode(static_cast<const SwDocShell*>(SfxObjectShell::Current()));
533 if(nHtmlMode & HTMLMODE_ON)
535 m_bHtmlMode = true;
536 m_xAutoWidthBox->set_sensitive(false);
538 FieldUnit aMetric = ::GetDfltMetric(m_bHtmlMode);
539 m_xEd1->SetMetric(aMetric);
540 m_xEd2->SetMetric(aMetric);
541 m_xEd3->SetMetric(aMetric);
542 m_xDistEd1->SetMetric(aMetric);
543 m_xDistEd2->SetMetric(aMetric);
544 //default spacing between cols = 0.5cm
545 m_xDistEd1->set_value(50, FieldUnit::CM);
546 m_xDistEd2->set_value(50, FieldUnit::CM);
548 m_xColMgr.reset(new SwColMgr(*rSet));
549 m_nCols = m_xColMgr->GetCount() ;
550 m_xCLNrEdt->set_max(std::max(o3tl::narrowing<sal_uInt16>(m_xCLNrEdt->get_max()), m_nCols));
552 if(m_bFrame)
554 if(m_bFormat) // there is no size here
555 m_xColMgr->SetActualWidth(FRAME_FORMAT_WIDTH);
556 else
558 const SwFormatFrameSize& rSize = rSet->Get(RES_FRM_SIZE);
559 const SvxBoxItem& rBox = rSet->Get(RES_BOX);
560 m_xColMgr->SetActualWidth(o3tl::narrowing<sal_uInt16>(rSize.GetSize().Width()) - rBox.GetSmallestDistance());
563 if (m_xBalanceColsCB->get_visible())
565 if( const SwFormatNoBalancedColumns* pItem = rSet->GetItemIfSet( RES_COLUMNBALANCE, false ) )
566 m_xBalanceColsCB->set_active(!pItem->GetValue());
567 else
568 m_xBalanceColsCB->set_active(true);
571 //text direction
572 if( SfxItemState::DEFAULT <= rSet->GetItemState( RES_FRAMEDIR ) )
574 const SvxFrameDirectionItem& rItem = rSet->Get(RES_FRAMEDIR);
575 SvxFrameDirection nVal = rItem.GetValue();
576 m_xTextDirectionLB->set_active_id(nVal);
577 m_xTextDirectionLB->save_value();
580 Init();
581 ActivatePage( *rSet );
584 // create TabPage
585 std::unique_ptr<SfxTabPage> SwColumnPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
587 return std::make_unique<SwColumnPage>(pPage, pController, *rSet);
590 // stuff attributes into the Set when OK
591 bool SwColumnPage::FillItemSet(SfxItemSet *rSet)
593 // set in ItemSet;
594 // the current settings are already present
596 const SfxPoolItem* pOldItem;
597 const SwFormatCol& rCol = m_xColMgr->GetColumns();
598 if(nullptr == (pOldItem = GetOldItem( *rSet, RES_COL )) ||
599 rCol != *pOldItem )
600 rSet->Put(rCol);
602 if (m_xBalanceColsCB->get_visible())
604 rSet->Put(SwFormatNoBalancedColumns(!m_xBalanceColsCB->get_active()));
606 if (m_xTextDirectionLB->get_visible())
608 if (m_xTextDirectionLB->get_value_changed_from_saved())
610 rSet->Put(SvxFrameDirectionItem(m_xTextDirectionLB->get_active_id(), RES_FRAMEDIR) );
613 return true;
616 // update ColumnManager
617 IMPL_LINK_NOARG( SwColumnPage, UpdateColMgrListBox, weld::ComboBox&, void )
619 UpdateColMgr(*m_xLineWidthEdit);
622 IMPL_LINK_NOARG( SwColumnPage, UpdateColMgrLineBox, SvtLineListBox&, void )
624 UpdateColMgr(*m_xLineWidthEdit);
627 IMPL_LINK_NOARG( SwColumnPage, UpdateColMgrColorBox, ColorListBox&, void )
629 UpdateColMgr(*m_xLineWidthEdit);
632 IMPL_LINK_NOARG( SwColumnPage, UpdateColMgr, weld::MetricSpinButton&, void )
634 if (!m_xColMgr)
635 return;
636 tools::Long nGutterWidth = m_xColMgr->GetGutterWidth();
637 if (m_nCols > 1)
639 // Determine whether the most narrow column is too narrow
640 // for the adjusted column gap
641 tools::Long nMin = m_nColWidth[0];
643 for( sal_uInt16 i = 1; i < m_nCols; ++i )
644 nMin = std::min(nMin, m_nColWidth[i]);
646 bool bAutoWidth = m_xAutoWidthBox->get_active();
647 if(!bAutoWidth)
649 m_xColMgr->SetAutoWidth(false);
650 // when the user didn't allocate the whole width,
651 // add the missing amount to the last column.
652 tools::Long nSum = 0;
653 for(sal_uInt16 i = 0; i < m_nCols; ++i)
654 nSum += m_nColWidth[i];
655 nGutterWidth = 0;
656 for(sal_uInt16 i = 0; i < m_nCols - 1; ++i)
657 nGutterWidth += m_nColDist[i];
658 nSum += nGutterWidth;
660 tools::Long nMaxW = m_xColMgr->GetActualSize();
662 if( nSum < nMaxW )
663 m_nColWidth[m_nCols - 1] += nMaxW - nSum;
665 m_xColMgr->SetColWidth( 0, static_cast< sal_uInt16 >(m_nColWidth[0] + m_nColDist[0]/2) );
666 for( sal_uInt16 i = 1; i < m_nCols-1; ++i )
668 tools::Long nActDist = (m_nColDist[i] + m_nColDist[i - 1]) / 2;
669 m_xColMgr->SetColWidth( i, static_cast< sal_uInt16 >(m_nColWidth[i] + nActDist ));
671 m_xColMgr->SetColWidth( m_nCols-1, static_cast< sal_uInt16 >(m_nColWidth[m_nCols-1] + m_nColDist[m_nCols -2]/2) );
675 bool bEnable = isLineNotNone();
676 m_xLineHeightEdit->set_sensitive(bEnable);
677 m_xLineHeightLbl->set_sensitive(bEnable);
678 m_xLineWidthLbl->set_sensitive(bEnable);
679 m_xLineWidthEdit->set_sensitive(bEnable);
680 m_xLineColorDLB->set_sensitive(bEnable);
681 m_xLineColorLbl->set_sensitive(bEnable);
683 sal_Int64 nLineWidth = m_xLineWidthEdit->get_value(FieldUnit::PERCENT);
684 nLineWidth = static_cast<tools::Long>(vcl::ConvertDoubleValue(
685 nLineWidth,
686 m_xLineWidthEdit->get_digits(),
687 m_xLineWidthEdit->get_unit(), MapUnit::MapTwip ));
688 if( !bEnable )
689 m_xColMgr->SetNoLine();
690 else
692 m_xColMgr->SetLineWidthAndColor(
693 m_xLineTypeDLB->GetSelectEntryStyle(),
694 nLineWidth,
695 m_xLineColorDLB->GetSelectEntryColor() );
696 m_xColMgr->SetAdjust(SwColLineAdj(m_xLinePosDLB->get_active() + 1));
697 m_xColMgr->SetLineHeightPercent(static_cast<short>(m_xLineHeightEdit->get_value(FieldUnit::PERCENT)));
698 bEnable = m_xColMgr->GetLineHeightPercent() != 100;
700 m_xLinePosLbl->set_sensitive(bEnable);
701 m_xLinePosDLB->set_sensitive(bEnable);
703 //fdo#66815 if the values are going to be the same, don't update
704 //them to avoid the listbox selection resetting
705 if (nLineWidth != m_xLineTypeDLB->GetWidth())
706 m_xLineTypeDLB->SetWidth(nLineWidth);
707 Color aColor(m_xLineColorDLB->GetSelectEntryColor());
708 if (aColor != m_xLineTypeDLB->GetColor())
709 m_xLineTypeDLB->SetColor(aColor);
711 else
713 m_xColMgr->NoCols();
714 m_nCols = 0;
717 //set maximum values
718 m_xCLNrEdt->set_max(std::max(tools::Long(1),
719 std::min(tools::Long(nMaxCols), tools::Long(m_xColMgr->GetActualSize() / (nGutterWidth + MINLAY)) )));
721 //prompt example window
722 if(!m_bLockUpdate)
724 if(m_bFrame)
726 m_aFrameExampleWN.SetColumns(m_xColMgr->GetColumns());
727 m_aFrameExampleWN.Invalidate();
729 else
730 m_aPgeExampleWN.Invalidate();
734 void SwColumnPage::Init()
736 m_xCLNrEdt->set_value(m_nCols);
738 bool bAutoWidth = m_xColMgr->IsAutoWidth() || m_bHtmlMode;
739 m_xAutoWidthBox->set_active(bAutoWidth);
741 sal_Int32 nColumnWidthSum = 0;
742 // set the widths
743 for(sal_uInt16 i = 0; i < m_nCols; ++i)
745 m_nColWidth[i] = m_xColMgr->GetColWidth(i);
746 nColumnWidthSum += m_nColWidth[i];
747 if(i < m_nCols - 1)
748 m_nColDist[i] = m_xColMgr->GetGutterWidth(i);
751 if( 1 < m_nCols )
753 // #97495# make sure that the automatic column width's are always equal
754 if(bAutoWidth)
756 nColumnWidthSum /= m_nCols;
757 for(sal_uInt16 i = 0; i < m_nCols; ++i)
758 m_nColWidth[i] = nColumnWidthSum;
760 SwColLineAdj eAdj = m_xColMgr->GetAdjust();
761 if( COLADJ_NONE == eAdj ) // the dialog doesn't know a NONE!
763 eAdj = COLADJ_TOP;
764 //without Adjust no line type
765 m_xLineTypeDLB->SelectEntry(SvxBorderLineStyle::NONE);
766 m_xLineHeightEdit->set_value(100, FieldUnit::PERCENT);
768 else
770 // Need to multiply by 100 because of the 2 decimals
771 m_xLineWidthEdit->set_value( m_xColMgr->GetLineWidth() * 100, FieldUnit::TWIP);
772 m_xLineColorDLB->SelectEntry( m_xColMgr->GetLineColor() );
773 m_xLineTypeDLB->SelectEntry( m_xColMgr->GetLineStyle() );
774 m_xLineTypeDLB->SetWidth( m_xColMgr->GetLineWidth( ) );
775 m_xLineHeightEdit->set_value(m_xColMgr->GetLineHeightPercent(), FieldUnit::PERCENT);
778 m_xLinePosDLB->set_active( static_cast< sal_Int32 >(eAdj - 1) );
780 else
782 m_xLinePosDLB->set_active(0);
783 m_xLineTypeDLB->SelectEntry(SvxBorderLineStyle::NONE);
784 m_xLineHeightEdit->set_value(100, FieldUnit::PERCENT);
787 UpdateCols();
788 Update(nullptr);
790 // set maximum number of columns
791 // values below 1 are not allowed
792 m_xCLNrEdt->set_max(std::max(tools::Long(1),
793 std::min(tools::Long(nMaxCols), tools::Long(m_xColMgr->GetActualSize() / g_nMinWidth) )));
796 bool SwColumnPage::isLineNotNone() const
798 // nothing is turned off
799 return m_xLineTypeDLB->GetSelectEntryStyle() != SvxBorderLineStyle::NONE;
803 * The number of columns has changed -- here the controls for editing of the
804 * columns are en- or disabled according to the column number. In case there are
805 * more than nVisCols (=3) all Edit are being enabled and the buttons for
806 * scrolling too. Otherwise Edits are being enabled according to the column
807 * numbers; one column can not be edited.
809 void SwColumnPage::UpdateCols()
811 bool bEnableBtns= false;
812 bool bEnable12 = false;
813 bool bEnable3 = false;
814 const bool bEdit = !m_xAutoWidthBox->get_active();
815 if ( m_nCols > nVisCols )
817 bEnableBtns = !m_bHtmlMode;
818 bEnable12 = bEnable3 = bEdit;
820 else if( bEdit )
822 // here are purposely hardly any breaks
823 switch(m_nCols)
825 case 3: bEnable3 = true;
826 [[fallthrough]];
827 case 2: bEnable12= true; break;
828 default: /* do nothing */;
831 m_xEd1->set_sensitive(bEnable12);
832 bool bEnable = m_nCols > 1;
833 m_xDistEd1->set_sensitive(bEnable);
834 m_xAutoWidthBox->set_sensitive(bEnable && !m_bHtmlMode);
835 m_xEd2->set_sensitive(bEnable12);
836 m_xDistEd2->set_sensitive(bEnable3);
837 m_xEd3->set_sensitive(bEnable3);
838 m_xLbl1->set_sensitive(bEnable12);
839 m_xLbl2->set_sensitive(bEnable12);
840 m_xLbl3->set_sensitive(bEnable3);
841 m_xBtnBack->set_sensitive(bEnableBtns);
842 m_xBtnNext->set_sensitive(bEnableBtns);
844 m_xLineTypeDLB->set_sensitive( bEnable );
845 m_xLineTypeLbl->set_sensitive( bEnable );
847 if (bEnable)
849 bEnable = isLineNotNone();
852 //all these depend on > 1 column and line style != none
853 m_xLineHeightEdit->set_sensitive(bEnable);
854 m_xLineHeightLbl->set_sensitive(bEnable);
855 m_xLineWidthLbl->set_sensitive(bEnable);
856 m_xLineWidthEdit->set_sensitive(bEnable);
857 m_xLineColorDLB->set_sensitive(bEnable);
858 m_xLineColorLbl->set_sensitive(bEnable);
860 if (bEnable)
861 bEnable = m_xColMgr->GetLineHeightPercent() != 100;
863 //and these additionally depend on line height != 100%
864 m_xLinePosDLB->set_sensitive(bEnable);
865 m_xLinePosLbl->set_sensitive(bEnable);
868 void SwColumnPage::SetLabels( sal_uInt16 nVis )
870 //insert ~ before the last character, e.g. 1 -> ~1, 10 -> 1~0
871 const OUString sLbl( '~' );
873 const OUString sLbl1(OUString::number( nVis + 1 ));
874 m_xLbl1->set_label(sLbl1.replaceAt(sLbl1.getLength()-1, 0, sLbl));
876 const OUString sLbl2(OUString::number( nVis + 2 ));
877 m_xLbl2->set_label(sLbl2.replaceAt(sLbl2.getLength()-1, 0, sLbl));
879 const OUString sLbl3(OUString::number( nVis + 3 ));
880 m_xLbl3->set_label(sLbl3.replaceAt(sLbl3.getLength()-1, 0, sLbl));
882 const OUString sColumnWidth = SwResId( STR_ACCESS_COLUMN_WIDTH ) ;
883 m_xEd1->set_accessible_name(sColumnWidth.replaceFirst("%1", sLbl1));
884 m_xEd2->set_accessible_name(sColumnWidth.replaceFirst("%1", sLbl2));
885 m_xEd3->set_accessible_name(sColumnWidth.replaceFirst("%1", sLbl3));
887 const OUString sDist = SwResId( STR_ACCESS_PAGESETUP_SPACING ) ;
888 m_xDistEd1->set_accessible_name(
889 sDist.replaceFirst("%1", sLbl1).replaceFirst("%2", sLbl2));
891 m_xDistEd2->set_accessible_name(
892 sDist.replaceFirst("%1", sLbl2).replaceFirst("%2", sLbl3));
896 * Handler that is called at alteration of the column number. An alteration of
897 * the column number overwrites potential user's width settings; all columns
898 * are equally wide.
900 IMPL_LINK_NOARG(SwColumnPage, ColModify, weld::SpinButton&, void)
902 ColModify(/*bForceColReset=*/false);
905 void SwColumnPage::ColModify(bool bForceColReset)
907 m_nCols = o3tl::narrowing<sal_uInt16>(m_xCLNrEdt->get_value());
908 //#107890# the handler is also called from LoseFocus()
909 //then no change has been made and thus no action should be taken
910 // #i17816# changing the displayed types within the ValueSet
911 //from two columns to two columns with different settings doesn't invalidate the
912 // example windows in ::ColModify()
913 if (!bForceColReset && m_xColMgr->GetCount() == m_nCols)
914 return;
916 if (!bForceColReset)
917 m_aDefaultVS.SetNoSelection();
918 tools::Long nDist = static_cast< tools::Long >(m_xDistEd1->DenormalizePercent(m_xDistEd1->get_value(FieldUnit::TWIP)));
919 m_xColMgr->SetCount(m_nCols, o3tl::narrowing<sal_uInt16>(nDist));
920 for(sal_uInt16 i = 0; i < m_nCols; i++)
921 m_nColDist[i] = nDist;
922 m_nFirstVis = 0;
923 SetLabels( m_nFirstVis );
924 UpdateCols();
925 ResetColWidth();
926 Update(nullptr);
930 * Modify handler for an alteration of the column width or the column gap.
931 * These changes take effect time-displaced. With an alteration of the column
932 * width the automatic calculation of the column width is overruled; only an
933 * alteration of the column number leads back to that default.
935 IMPL_LINK(SwColumnPage, GapModify, weld::MetricSpinButton&, rMetricField, void)
937 if (m_nCols < 2)
938 return;
939 SwPercentField *pField = m_aPercentFieldsMap[&rMetricField];
940 assert(pField);
941 tools::Long nActValue = static_cast< tools::Long >(pField->DenormalizePercent(pField->get_value(FieldUnit::TWIP)));
942 if (m_xAutoWidthBox->get_active())
944 const tools::Long nMaxGap = static_cast< tools::Long >
945 ((m_xColMgr->GetActualSize() - m_nCols * MINLAY)/(m_nCols - 1));
946 if(nActValue > nMaxGap)
948 nActValue = nMaxGap;
949 m_xDistEd1->set_value(m_xDistEd1->NormalizePercent(nMaxGap), FieldUnit::TWIP);
951 m_xColMgr->SetGutterWidth(o3tl::narrowing<sal_uInt16>(nActValue));
952 for(sal_uInt16 i = 0; i < m_nCols; i++)
953 m_nColDist[i] = nActValue;
955 ResetColWidth();
956 UpdateCols();
958 else
960 const sal_uInt16 nVis = m_nFirstVis + ((pField == m_xDistEd2.get()) ? 1 : 0);
961 tools::Long nDiff = nActValue - m_nColDist[nVis];
962 if(nDiff)
964 tools::Long nLeft = m_nColWidth[nVis];
965 tools::Long nRight = m_nColWidth[nVis + 1];
966 if(nLeft + nRight + 2 * MINLAY < nDiff)
967 nDiff = nLeft + nRight - 2 * MINLAY;
968 if(nDiff < nRight - MINLAY)
970 nRight -= nDiff;
972 else
974 tools::Long nTemp = nDiff - nRight + MINLAY;
975 nRight = MINLAY;
976 if(nLeft > nTemp - MINLAY)
978 nLeft -= nTemp;
979 nTemp = 0;
981 else
983 nTemp -= nLeft + MINLAY;
984 nLeft = MINLAY;
986 nDiff = nTemp;
988 m_nColWidth[nVis] = nLeft;
989 m_nColWidth[nVis + 1] = nRight;
990 m_nColDist[nVis] += nDiff;
992 m_xColMgr->SetColWidth( nVis, sal_uInt16(nLeft) );
993 m_xColMgr->SetColWidth( nVis + 1, sal_uInt16(nRight) );
994 m_xColMgr->SetGutterWidth( sal_uInt16(m_nColDist[nVis]), nVis );
998 Update(&rMetricField);
1001 IMPL_LINK(SwColumnPage, EdModify, weld::MetricSpinButton&, rEdit, void)
1003 SwPercentField *pField = m_aPercentFieldsMap[&rEdit];
1004 assert(pField);
1005 m_pModifiedField = pField;
1006 Timeout();
1009 // Handler behind the Checkbox for automatic width. When the box is checked
1010 // no explicit values for the column width can be entered.
1011 IMPL_LINK(SwColumnPage, AutoWidthHdl, weld::Toggleable&, rBox, void)
1013 tools::Long nDist = static_cast< tools::Long >(m_xDistEd1->DenormalizePercent(m_xDistEd1->get_value(FieldUnit::TWIP)));
1014 m_xColMgr->SetCount(m_nCols, o3tl::narrowing<sal_uInt16>(nDist));
1015 for(sal_uInt16 i = 0; i < m_nCols; i++)
1016 m_nColDist[i] = nDist;
1017 if (rBox.get_active())
1019 m_xColMgr->SetGutterWidth(sal_uInt16(nDist));
1020 ResetColWidth();
1022 m_xColMgr->SetAutoWidth(rBox.get_active(), sal_uInt16(nDist));
1023 UpdateCols();
1024 Update(nullptr);
1027 // scroll up the contents of the edits
1028 IMPL_LINK_NOARG(SwColumnPage, Up, weld::Button&, void)
1030 if( m_nFirstVis )
1032 --m_nFirstVis;
1033 SetLabels( m_nFirstVis );
1034 Update(nullptr);
1038 // scroll down the contents of the edits.
1039 IMPL_LINK_NOARG(SwColumnPage, Down, weld::Button&, void)
1041 if( m_nFirstVis + nVisCols < m_nCols )
1043 ++m_nFirstVis;
1044 SetLabels( m_nFirstVis );
1045 Update(nullptr);
1049 // relict from ancient times - now directly without time handler; triggered by
1050 // an alteration of the column width or the column gap.
1051 void SwColumnPage::Timeout()
1053 SwPercentField *pField = m_pModifiedField;
1054 if (m_pModifiedField)
1056 // find the changed column
1057 sal_uInt16 nChanged = m_nFirstVis;
1058 if (m_pModifiedField == m_xEd2.get())
1059 ++nChanged;
1060 else if (m_pModifiedField == m_xEd3.get())
1061 nChanged += 2;
1063 tools::Long nNewWidth = static_cast< tools::Long >
1064 (m_pModifiedField->DenormalizePercent(m_pModifiedField->get_value(FieldUnit::TWIP)));
1065 tools::Long nDiff = nNewWidth - m_nColWidth[nChanged];
1067 // when it's the last column
1068 if(nChanged == m_nCols - 1)
1070 m_nColWidth[0] -= nDiff;
1071 if(m_nColWidth[0] < static_cast<tools::Long>(g_nMinWidth))
1073 nNewWidth -= g_nMinWidth - m_nColWidth[0];
1074 m_nColWidth[0] = g_nMinWidth;
1078 else if(nDiff)
1080 m_nColWidth[nChanged + 1] -= nDiff;
1081 if(m_nColWidth[nChanged + 1] < static_cast<tools::Long>(g_nMinWidth))
1083 nNewWidth -= g_nMinWidth - m_nColWidth[nChanged + 1];
1084 m_nColWidth[nChanged + 1] = g_nMinWidth;
1087 m_nColWidth[nChanged] = nNewWidth;
1088 m_pModifiedField = nullptr;
1091 Update(pField ? pField->get() : nullptr);
1094 // Update the view
1095 void SwColumnPage::Update(const weld::MetricSpinButton* pInteractiveField)
1097 m_xBalanceColsCB->set_sensitive(m_nCols > 1);
1098 if(m_nCols >= 2)
1100 sal_Int64 nCurrentValue, nNewValue;
1102 nCurrentValue = m_xEd1->NormalizePercent(m_xEd1->DenormalizePercent(m_xEd1->get_value(FieldUnit::TWIP)));
1103 nNewValue = m_xEd1->NormalizePercent(m_nColWidth[m_nFirstVis]);
1105 //fdo#87612 if we're interacting with this widget and the value will be the same
1106 //then leave it alone (i.e. don't change equivalent values of e.g. .8 -> 0.8)
1107 if (nNewValue != nCurrentValue || pInteractiveField != m_xEd1->get())
1108 m_xEd1->set_value(nNewValue, FieldUnit::TWIP);
1110 nCurrentValue = m_xDistEd1->NormalizePercent(m_xDistEd1->DenormalizePercent(m_xDistEd1->get_value(FieldUnit::TWIP)));
1111 nNewValue = m_xDistEd1->NormalizePercent(m_nColDist[m_nFirstVis]);
1112 if (nNewValue != nCurrentValue || pInteractiveField != m_xDistEd1->get())
1113 m_xDistEd1->set_value(nNewValue, FieldUnit::TWIP);
1115 nCurrentValue = m_xEd2->NormalizePercent(m_xEd2->DenormalizePercent(m_xEd2->get_value(FieldUnit::TWIP)));
1116 nNewValue = m_xEd2->NormalizePercent(m_nColWidth[m_nFirstVis+1]);
1117 if (nNewValue != nCurrentValue || pInteractiveField != m_xEd2->get())
1118 m_xEd2->set_value(nNewValue, FieldUnit::TWIP);
1120 if(m_nCols >= 3)
1122 nCurrentValue = m_xDistEd2->NormalizePercent(m_xDistEd2->DenormalizePercent(m_xDistEd2->get_value(FieldUnit::TWIP)));
1123 nNewValue = m_xDistEd2->NormalizePercent(m_nColDist[m_nFirstVis+1]);
1124 if (nNewValue != nCurrentValue || pInteractiveField != m_xDistEd2->get())
1125 m_xDistEd2->set_value(nNewValue, FieldUnit::TWIP);
1127 nCurrentValue = m_xEd3->NormalizePercent(m_xEd3->DenormalizePercent(m_xEd3->get_value(FieldUnit::TWIP)));
1128 nNewValue = m_xEd3->NormalizePercent(m_nColWidth[m_nFirstVis+2]);
1129 if (nNewValue != nCurrentValue || pInteractiveField != m_xEd3->get())
1130 m_xEd3->set_value(nNewValue, FieldUnit::TWIP);
1132 else
1134 m_xEd3->set_text(OUString());
1135 m_xDistEd2->set_text(OUString());
1138 else
1140 m_xEd1->set_text(OUString());
1141 m_xEd2->set_text(OUString());
1142 m_xEd3->set_text(OUString());
1143 m_xDistEd1->set_text(OUString());
1144 m_xDistEd2->set_text(OUString());
1146 UpdateColMgr(*m_xLineWidthEdit);
1149 // Update Bsp
1150 void SwColumnPage::ActivatePage(const SfxItemSet& rSet)
1152 bool bVertical = false;
1153 if (SfxItemState::DEFAULT <= rSet.GetItemState(RES_FRAMEDIR))
1155 const SvxFrameDirectionItem& rDirItem =
1156 rSet.Get(RES_FRAMEDIR);
1157 bVertical = rDirItem.GetValue() == SvxFrameDirection::Vertical_RL_TB||
1158 rDirItem.GetValue() == SvxFrameDirection::Vertical_LR_TB;
1161 if (!m_bFrame)
1163 if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_PAGE_SIZE ))
1165 const SvxSizeItem& rSize = rSet.Get(SID_ATTR_PAGE_SIZE);
1167 sal_uInt16 nActWidth;
1169 if (!bVertical)
1171 const SvxLRSpaceItem& rLRSpace = rSet.Get(RES_LR_SPACE);
1172 const SvxBoxItem& rBox = rSet.Get(RES_BOX);
1173 nActWidth = rSize.GetSize().Width()
1174 - rLRSpace.GetLeft() - rLRSpace.GetRight() - rBox.GetSmallestDistance();
1176 else
1178 const SvxULSpaceItem& rULSpace = rSet.Get( RES_UL_SPACE );
1179 const SvxBoxItem& rBox = rSet.Get(RES_BOX);
1180 nActWidth = rSize.GetSize().Height()
1181 - rULSpace.GetUpper() - rULSpace.GetLower() - rBox.GetSmallestDistance();
1185 if( m_xColMgr->GetActualSize() != nActWidth)
1187 m_xColMgr->SetActualWidth(nActWidth);
1188 ColModify(/*bForceColReset=*/false);
1189 UpdateColMgr( *m_xLineWidthEdit );
1192 m_xFrameExampleWN->hide();
1193 m_aPgeExampleWN.UpdateExample(rSet, m_xColMgr.get());
1194 m_xPgeExampleWN->show();
1197 else
1199 m_xPgeExampleWN->hide();
1200 m_xFrameExampleWN->show();
1202 // Size
1203 const SwFormatFrameSize& rSize = rSet.Get(RES_FRM_SIZE);
1204 const SvxBoxItem& rBox = rSet.Get(RES_BOX);
1206 sal_uInt16 nTotalWish;
1207 if (m_bFormat)
1208 nTotalWish = FRAME_FORMAT_WIDTH;
1209 else
1211 tools::Long const nDistance = rBox.GetSmallestDistance();
1212 nTotalWish = (!bVertical ? rSize.GetWidth() : rSize.GetHeight()) - 2 * nDistance;
1215 // set maximum values of column width
1216 SetPageWidth(nTotalWish);
1218 if(m_xColMgr->GetActualSize() != nTotalWish)
1220 m_xColMgr->SetActualWidth(nTotalWish);
1221 Init();
1223 bool bPercent;
1224 // only relative data in frame format
1225 if ( m_bFormat || (rSize.GetWidthPercent() && rSize.GetWidthPercent() != SwFormatFrameSize::SYNCED) )
1227 // set value for 100%
1228 m_xEd1->SetRefValue(nTotalWish);
1229 m_xEd2->SetRefValue(nTotalWish);
1230 m_xEd3->SetRefValue(nTotalWish);
1231 m_xDistEd1->SetRefValue(nTotalWish);
1232 m_xDistEd2->SetRefValue(nTotalWish);
1234 // switch to %-view
1235 bPercent = true;
1237 else
1238 bPercent = false;
1240 m_xEd1->ShowPercent(bPercent);
1241 m_xEd2->ShowPercent(bPercent);
1242 m_xEd3->ShowPercent(bPercent);
1243 m_xDistEd1->ShowPercent(bPercent);
1244 m_xDistEd2->ShowPercent(bPercent);
1245 m_xDistEd1->SetMetricFieldMin(0);
1246 m_xDistEd2->SetMetricFieldMin(0);
1248 Update(nullptr);
1251 DeactivateRC SwColumnPage::DeactivatePage(SfxItemSet *_pSet)
1253 if(_pSet)
1254 FillItemSet(_pSet);
1256 return DeactivateRC::LeavePage;
1259 IMPL_LINK(SwColumnPage, SetDefaultsHdl, ValueSet *, pVS, void)
1261 const sal_uInt16 nItem = pVS->GetSelectedItemId();
1262 if( nItem < 4 )
1264 m_xCLNrEdt->set_value(nItem);
1265 m_xAutoWidthBox->set_active(true);
1266 m_xDistEd1->set_value(50, FieldUnit::CM);
1267 ColModify(/*bForceColReset=*/true);
1269 else
1271 m_bLockUpdate = true;
1272 m_xCLNrEdt->set_value(2);
1273 m_xAutoWidthBox->set_active(false);
1274 m_xDistEd1->set_value(50, FieldUnit::CM);
1275 ColModify(/*bForceColReset=*/true);
1276 // now set the width ratio to 2 : 1 or 1 : 2 respectively
1277 const tools::Long nSmall = static_cast< tools::Long >(m_xColMgr->GetActualSize() / 3);
1278 if(nItem == 4)
1280 m_xEd2->set_value(m_xEd2->NormalizePercent(nSmall), FieldUnit::TWIP);
1281 m_pModifiedField = m_xEd2.get();
1283 else
1285 m_xEd1->set_value(m_xEd1->NormalizePercent(nSmall), FieldUnit::TWIP);
1286 m_pModifiedField = m_xEd1.get();
1288 m_bLockUpdate = false;
1289 Timeout();
1294 void SwColumnPage::SetFrameMode(bool bMod)
1296 m_bFrame = bMod;
1299 void SwColumnPage::SetInSection(bool bSet)
1301 if(!SvtCTLOptions::IsCTLFontEnabled())
1302 return;
1304 m_xTextDirectionFT->set_visible(bSet);
1305 m_xTextDirectionLB->set_visible(bSet);
1308 void ColumnValueSet::UserDraw(const UserDrawEvent& rUDEvt)
1310 vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
1311 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1313 tools::Rectangle aRect = rUDEvt.GetRect();
1314 const sal_uInt16 nItemId = rUDEvt.GetItemId();
1315 tools::Long nRectWidth = aRect.GetWidth();
1316 tools::Long nRectHeight = aRect.GetHeight();
1318 Point aBLPos = aRect.TopLeft();
1319 Color aFillColor(pDev->GetFillColor());
1320 Color aLineColor(pDev->GetLineColor());
1321 pDev->SetFillColor(rStyleSettings.GetFieldColor());
1322 pDev->SetLineColor(rStyleSettings.GetFieldTextColor());
1324 tools::Long nStep = std::abs(std::abs(nRectHeight * 95 /100) / 11);
1325 tools::Long nTop = (nRectHeight - 11 * nStep ) / 2;
1326 sal_uInt16 nCols = 0;
1327 tools::Long nStarts[3];
1328 tools::Long nEnds[3];
1329 nStarts[0] = nRectWidth * 10 / 100;
1330 switch( nItemId )
1332 case 1:
1333 nEnds[0] = nRectWidth * 9 / 10;
1334 nCols = 1;
1335 break;
1336 case 2: nCols = 2;
1337 nEnds[0] = nRectWidth * 45 / 100;
1338 nStarts[1] = nEnds[0] + nStep;
1339 nEnds[1] = nRectWidth * 9 / 10;
1340 break;
1341 case 3: nCols = 3;
1342 nEnds[0] = nRectWidth * 30 / 100;
1343 nStarts[1] = nEnds[0] + nStep;
1344 nEnds[1] = nRectWidth * 63 / 100;
1345 nStarts[2] = nEnds[1] + nStep;
1346 nEnds[2] = nRectWidth * 9 / 10;
1347 break;
1348 case 4: nCols = 2;
1349 nEnds[0] = nRectWidth * 63 / 100;
1350 nStarts[1] = nEnds[0] + nStep;
1351 nEnds[1] = nRectWidth * 9 / 10;
1352 break;
1353 case 5: nCols = 2;
1354 nEnds[0] = nRectWidth * 30 / 100;
1355 nStarts[1] = nEnds[0] + nStep;
1356 nEnds[1] = nRectWidth * 9 / 10;
1357 break;
1359 for(sal_uInt16 j = 0; j < nCols; j++ )
1361 Point aStart(aBLPos.X() + nStarts[j], 0);
1362 Point aEnd(aBLPos.X() + nEnds[j], 0);
1363 for( sal_uInt16 i = 0; i < 12; i ++)
1365 aStart.setY( aBLPos.Y() + nTop + i * nStep);
1366 aEnd.setY( aStart.Y() );
1367 pDev->DrawLine(aStart, aEnd);
1370 pDev->SetFillColor(aFillColor);
1371 pDev->SetLineColor(aLineColor);
1374 void ColumnValueSet::StyleUpdated()
1376 SetFormat();
1377 Invalidate();
1378 ValueSet::StyleUpdated();
1381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */