bump product version to 6.4.0.3
[LibreOffice.git] / cui / source / tabpages / align.cxx
blobcdd87f0cf2a463b42b7b78881f5b6f79e51eb279
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 <align.hxx>
22 #include <editeng/svxenum.hxx>
23 #include <svx/svxids.hrc>
24 #include <svx/strings.hrc>
25 #include <svx/dialmgr.hxx>
26 #include <bitmaps.hlst>
27 #include <svx/rotmodit.hxx>
29 #include <editeng/frmdiritem.hxx>
30 #include <editeng/justifyitem.hxx>
31 #include <svl/cjkoptions.hxx>
32 #include <svl/intitem.hxx>
33 #include <vcl/settings.hxx>
34 #include <vcl/event.hxx>
36 #define IID_BOTTOMLOCK 1
37 #define IID_TOPLOCK 2
38 #define IID_CELLLOCK 3
40 namespace svx {
42 const sal_uInt16 AlignmentTabPage::s_pRanges[] =
44 SID_ATTR_ALIGN_HOR_JUSTIFY,SID_ATTR_ALIGN_VER_JUSTIFY,
45 SID_ATTR_ALIGN_STACKED,SID_ATTR_ALIGN_LINEBREAK,
46 SID_ATTR_ALIGN_INDENT,SID_ATTR_ALIGN_INDENT,
47 SID_ATTR_ALIGN_DEGREES,SID_ATTR_ALIGN_DEGREES,
48 SID_ATTR_ALIGN_LOCKPOS,SID_ATTR_ALIGN_LOCKPOS,
49 SID_ATTR_ALIGN_HYPHENATION,SID_ATTR_ALIGN_HYPHENATION,
50 SID_ATTR_ALIGN_ASIANVERTICAL,SID_ATTR_ALIGN_ASIANVERTICAL,
51 SID_ATTR_FRAMEDIRECTION,SID_ATTR_FRAMEDIRECTION,
52 SID_ATTR_ALIGN_SHRINKTOFIT,SID_ATTR_ALIGN_SHRINKTOFIT,
57 namespace {
59 template<typename JustContainerType, typename JustEnumType>
60 void lcl_MaybeResetAlignToDistro(
61 weld::ComboBox& rLB, sal_uInt16 nListPos, const SfxItemSet& rCoreAttrs, sal_uInt16 nWhichAlign, sal_uInt16 nWhichJM, JustEnumType eBlock)
63 const SfxPoolItem* pItem;
64 if (rCoreAttrs.GetItemState(nWhichAlign, true, &pItem) != SfxItemState::SET)
65 // alignment not set.
66 return;
68 const SfxEnumItemInterface* p = static_cast<const SfxEnumItemInterface*>(pItem);
69 JustContainerType eVal = static_cast<JustContainerType>(p->GetEnumValue());
70 if (eVal != eBlock)
71 // alignment is not 'justify'. No need to go further.
72 return;
74 if (rCoreAttrs.GetItemState(nWhichJM, true, &pItem) != SfxItemState::SET)
75 // justification method is not set.
76 return;
78 p = static_cast<const SfxEnumItemInterface*>(pItem);
79 SvxCellJustifyMethod eMethod = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
80 if (eMethod == SvxCellJustifyMethod::Distribute)
82 // Select the 'distribute' entry in the specified list box.
83 rLB.set_active(nListPos);
87 void lcl_SetJustifyMethodToItemSet(SfxItemSet& rSet, sal_uInt16 nWhichJM, const weld::ComboBox& rLB, sal_uInt16 nListPos)
89 SvxCellJustifyMethod eJM = SvxCellJustifyMethod::Auto;
90 if (rLB.get_active() == nListPos)
91 eJM = SvxCellJustifyMethod::Distribute;
93 // tdf#129300 If it would create no change, don't force it
94 const SvxJustifyMethodItem& rOldItem = static_cast<const SvxJustifyMethodItem&>(rSet.Get(nWhichJM));
95 if (rOldItem.GetValue() == eJM)
96 return;
98 SvxJustifyMethodItem aItem(eJM, nWhichJM);
99 rSet.Put(aItem);
102 }//namespace
104 AlignmentTabPage::AlignmentTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs)
105 : SfxTabPage(pPage, pController, "cui/ui/cellalignment.ui", "CellAlignPage", &rCoreAttrs)
106 , m_aVsRefEdge(nullptr)
107 // text alignment
108 , m_xLbHorAlign(m_xBuilder->weld_combo_box("comboboxHorzAlign"))
109 , m_xFtIndent(m_xBuilder->weld_label("labelIndent"))
110 , m_xEdIndent(m_xBuilder->weld_metric_spin_button("spinIndentFrom", FieldUnit::POINT))
111 , m_xFtVerAlign(m_xBuilder->weld_label("labelVertAlign"))
112 , m_xLbVerAlign(m_xBuilder->weld_combo_box("comboboxVertAlign"))
113 //text rotation
114 , m_xFtRotate(m_xBuilder->weld_label("labelDegrees"))
115 , m_xNfRotate(m_xBuilder->weld_spin_button("spinDegrees"))
116 , m_xFtRefEdge(m_xBuilder->weld_label("labelRefEdge"))
117 //Asian mode
118 , m_xCbStacked(m_xBuilder->weld_check_button("checkVertStack"))
119 , m_xCbAsianMode(m_xBuilder->weld_check_button("checkAsianMode"))
120 // Properties
121 , m_xBoxDirection(m_xBuilder->weld_widget("boxDirection"))
122 , m_xBtnWrap(m_xBuilder->weld_check_button("checkWrapTextAuto"))
123 , m_xBtnHyphen(m_xBuilder->weld_check_button("checkHyphActive"))
124 , m_xBtnShrink(m_xBuilder->weld_check_button("checkShrinkFitCellSize"))
125 , m_xLbFrameDir(new svx::FrameDirectionListBox(m_xBuilder->weld_combo_box("comboTextDirBox")))
126 //ValueSet hover strings
127 , m_xFtBotLock(m_xBuilder->weld_label("labelSTR_BOTTOMLOCK"))
128 , m_xFtTopLock(m_xBuilder->weld_label("labelSTR_TOPLOCK"))
129 , m_xFtCelLock(m_xBuilder->weld_label("labelSTR_CELLLOCK"))
130 , m_xFtABCD(m_xBuilder->weld_label("labelABCD"))
131 , m_xAlignmentFrame(m_xBuilder->weld_widget("alignment"))
132 , m_xOrientFrame(m_xBuilder->weld_widget("orientation"))
133 , m_xPropertiesFrame(m_xBuilder->weld_widget("properties"))
134 , m_xVsRefEdge(new weld::CustomWeld(*m_xBuilder, "references", m_aVsRefEdge))
135 , m_xCtrlDial(new weld::CustomWeld(*m_xBuilder, "dialcontrol", m_aCtrlDial))
137 m_aCtrlDial.SetLinkedField(m_xNfRotate.get());
138 m_aCtrlDial.SetText(m_xFtABCD->get_label());
140 InitVsRefEgde();
142 m_xLbHorAlign->connect_changed(LINK(this, AlignmentTabPage, UpdateEnableHdl));
144 m_xCbStacked->connect_toggled(LINK(this, AlignmentTabPage, StackedClickHdl));
145 m_xCbAsianMode->connect_toggled(LINK(this, AlignmentTabPage, AsianModeClickHdl));
146 m_xBtnWrap->connect_toggled(LINK(this, AlignmentTabPage, WrapClickHdl));
147 m_xBtnHyphen->connect_toggled(LINK(this, AlignmentTabPage, HyphenClickHdl));
148 m_xBtnShrink->connect_toggled(LINK(this, AlignmentTabPage, ShrinkClickHdl));
150 // Asian vertical mode
151 m_xCbAsianMode->set_visible(SvtCJKOptions().IsVerticalTextEnabled());
153 m_xLbFrameDir->append(SvxFrameDirection::Horizontal_LR_TB, SvxResId(RID_SVXSTR_FRAMEDIR_LTR));
154 m_xLbFrameDir->append(SvxFrameDirection::Horizontal_RL_TB, SvxResId(RID_SVXSTR_FRAMEDIR_RTL));
155 m_xLbFrameDir->append(SvxFrameDirection::Environment, SvxResId(RID_SVXSTR_FRAMEDIR_SUPER));
157 // This page needs ExchangeSupport.
158 SetExchangeSupport();
161 AlignmentTabPage::~AlignmentTabPage()
163 m_xCtrlDial.reset();
164 m_xVsRefEdge.reset();
165 m_xLbFrameDir.reset();
168 std::unique_ptr<SfxTabPage> AlignmentTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
170 return std::make_unique<AlignmentTabPage>(pPage, pController, *rAttrSet);
173 bool AlignmentTabPage::FillItemSet( SfxItemSet* rSet )
175 bool bChanged = SfxTabPage::FillItemSet(rSet);
177 if (m_xLbHorAlign->get_value_changed_from_saved())
179 SvxCellHorJustify eJustify(SvxCellHorJustify::Standard);
180 switch (m_xLbHorAlign->get_active_id().toInt32())
182 case ALIGNDLG_HORALIGN_STD:
183 eJustify = SvxCellHorJustify::Standard;
184 break;
185 case ALIGNDLG_HORALIGN_LEFT:
186 eJustify = SvxCellHorJustify::Left;
187 break;
188 case ALIGNDLG_HORALIGN_CENTER:
189 eJustify = SvxCellHorJustify::Center;
190 break;
191 case ALIGNDLG_HORALIGN_RIGHT:
192 eJustify = SvxCellHorJustify::Right;
193 break;
194 case ALIGNDLG_HORALIGN_BLOCK:
195 case ALIGNDLG_HORALIGN_DISTRIBUTED:
196 eJustify = SvxCellHorJustify::Block;
197 break;
198 case ALIGNDLG_HORALIGN_FILL:
199 eJustify = SvxCellHorJustify::Repeat;
200 break;
202 rSet->Put(SvxHorJustifyItem(eJustify, GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY)));
203 bChanged = true;
206 if (m_xEdIndent->get_value_changed_from_saved())
208 rSet->Put(SfxUInt16Item(GetWhich(SID_ATTR_ALIGN_INDENT), m_xEdIndent->get_value(FieldUnit::TWIP)));
209 bChanged = true;
212 if (m_xLbVerAlign->get_value_changed_from_saved())
214 SvxCellVerJustify eJustify(SvxCellVerJustify::Standard);
215 switch (m_xLbVerAlign->get_active_id().toInt32())
217 case ALIGNDLG_VERALIGN_STD:
218 eJustify = SvxCellVerJustify::Standard;
219 break;
220 case ALIGNDLG_VERALIGN_TOP:
221 eJustify = SvxCellVerJustify::Top;
222 break;
223 case ALIGNDLG_VERALIGN_MID:
224 eJustify = SvxCellVerJustify::Center;
225 break;
226 case ALIGNDLG_VERALIGN_BOTTOM:
227 eJustify = SvxCellVerJustify::Bottom;
228 break;
229 case ALIGNDLG_VERALIGN_BLOCK:
230 case ALIGNDLG_VERALIGN_DISTRIBUTED:
231 eJustify = SvxCellVerJustify::Block;
232 break;
234 rSet->Put(SvxVerJustifyItem(eJustify, GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY)));
235 bChanged = true;
238 if (m_xNfRotate->get_value_changed_from_saved())
240 rSet->Put(SfxInt32Item(GetWhich(SID_ATTR_ALIGN_DEGREES), m_aCtrlDial.GetRotation()));
241 bChanged = true;
244 if (m_aVsRefEdge.IsValueChangedFromSaved())
246 switch (m_aVsRefEdge.GetSelectedItemId())
248 case IID_CELLLOCK:
249 rSet->Put(SvxRotateModeItem(SvxRotateMode::SVX_ROTATE_MODE_STANDARD, GetWhich(SID_ATTR_ALIGN_LOCKPOS)));
250 break;
251 case IID_TOPLOCK:
252 rSet->Put(SvxRotateModeItem(SvxRotateMode::SVX_ROTATE_MODE_TOP, GetWhich(SID_ATTR_ALIGN_LOCKPOS)));
253 break;
254 case IID_BOTTOMLOCK:
255 rSet->Put(SvxRotateModeItem(SvxRotateMode::SVX_ROTATE_MODE_BOTTOM, GetWhich(SID_ATTR_ALIGN_LOCKPOS)));
256 break;
257 default:
258 m_aVsRefEdge.SetNoSelection();
259 break;
261 bChanged = true;
264 if (m_xCbStacked->get_state_changed_from_saved())
266 rSet->Put(SfxBoolItem(GetWhich(SID_ATTR_ALIGN_STACKED), m_xCbStacked->get_active()));
267 bChanged = true;
270 if (m_xCbAsianMode->get_state_changed_from_saved())
272 rSet->Put(SfxBoolItem(GetWhich(SID_ATTR_ALIGN_ASIANVERTICAL), m_xCbAsianMode->get_active()));
273 bChanged = true;
276 if (m_xBtnWrap->get_state_changed_from_saved())
278 rSet->Put(SfxBoolItem(GetWhich(SID_ATTR_ALIGN_LINEBREAK), m_xBtnWrap->get_active()));
279 bChanged = true;
282 if (m_xBtnHyphen->get_state_changed_from_saved())
284 rSet->Put(SfxBoolItem(GetWhich(SID_ATTR_ALIGN_HYPHENATION), m_xBtnHyphen->get_active()));
285 bChanged = true;
288 if (m_xBtnShrink->get_state_changed_from_saved())
290 rSet->Put(SfxBoolItem(GetWhich(SID_ATTR_ALIGN_SHRINKTOFIT), m_xBtnShrink->get_active()));
291 bChanged = true;
294 if (m_xLbFrameDir->get_visible())
296 if (m_xLbFrameDir->get_value_changed_from_saved())
298 SvxFrameDirection eDir = m_xLbFrameDir->get_active_id();
299 rSet->Put(SvxFrameDirectionItem(eDir, GetWhich(SID_ATTR_FRAMEDIRECTION)));
300 bChanged = true;
304 // Special treatment for distributed alignment; we need to set the justify
305 // method to 'distribute' to distinguish from the normal justification.
307 sal_uInt16 nWhichHorJM = GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD);
308 lcl_SetJustifyMethodToItemSet(*rSet, nWhichHorJM, *m_xLbHorAlign, ALIGNDLG_HORALIGN_DISTRIBUTED);
309 if (!bChanged)
310 bChanged = HasAlignmentChanged(*rSet, nWhichHorJM);
312 sal_uInt16 nWhichVerJM = GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD);
313 lcl_SetJustifyMethodToItemSet(*rSet, nWhichVerJM, *m_xLbVerAlign, ALIGNDLG_VERALIGN_DISTRIBUTED);
314 if (!bChanged)
315 bChanged = HasAlignmentChanged(*rSet, nWhichVerJM);
317 return bChanged;
320 namespace
322 void ResetBool(sal_uInt16 nWhich, const SfxItemSet* pSet, weld::CheckButton& rBtn, weld::TriStateEnabled& rTriState)
324 SfxItemState eState = pSet->GetItemState(nWhich);
325 switch (eState)
327 case SfxItemState::UNKNOWN:
328 rBtn.hide();
329 rTriState.bTriStateEnabled = false;
330 break;
331 case SfxItemState::DISABLED:
332 case SfxItemState::READONLY:
333 rBtn.set_sensitive(false);
334 rTriState.bTriStateEnabled = false;
335 break;
336 case SfxItemState::DONTCARE:
337 rBtn.set_state(TRISTATE_INDET);
338 rTriState.bTriStateEnabled = true;
339 break;
340 case SfxItemState::DEFAULT:
341 case SfxItemState::SET:
343 const SfxBoolItem& rItem = static_cast<const SfxBoolItem&>(pSet->Get(nWhich));
344 rBtn.set_state(static_cast<TriState>(rItem.GetValue()));
345 rTriState.bTriStateEnabled = false;
346 break;
349 rBtn.save_state();
353 void AlignmentTabPage::Reset(const SfxItemSet* pCoreAttrs)
355 SfxTabPage::Reset(pCoreAttrs);
357 ResetBool(GetWhich(SID_ATTR_ALIGN_STACKED), pCoreAttrs, *m_xCbStacked, m_aStackedState);
358 ResetBool(GetWhich(SID_ATTR_ALIGN_ASIANVERTICAL), pCoreAttrs, *m_xCbAsianMode, m_aAsianModeState);
359 ResetBool(GetWhich(SID_ATTR_ALIGN_LINEBREAK), pCoreAttrs, *m_xBtnWrap, m_aWrapState);
360 ResetBool(GetWhich(SID_ATTR_ALIGN_HYPHENATION), pCoreAttrs, *m_xBtnHyphen, m_aHyphenState);
361 ResetBool(GetWhich(SID_ATTR_ALIGN_SHRINKTOFIT), pCoreAttrs, *m_xBtnShrink, m_aShrinkState);
363 sal_uInt16 nWhich = GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY);
364 SfxItemState eState = pCoreAttrs->GetItemState(nWhich);
365 switch (eState)
367 case SfxItemState::UNKNOWN:
368 m_xLbHorAlign->hide();
369 break;
370 case SfxItemState::DISABLED:
371 case SfxItemState::READONLY:
372 m_xLbHorAlign->set_sensitive(false);
373 break;
374 case SfxItemState::DONTCARE:
375 m_xLbHorAlign->set_active(-1);
376 break;
377 case SfxItemState::DEFAULT:
378 case SfxItemState::SET:
380 const SvxHorJustifyItem& rJustifyItem = static_cast<const SvxHorJustifyItem&>(pCoreAttrs->Get(nWhich));
381 switch (rJustifyItem.GetValue())
383 case SvxCellHorJustify::Standard:
384 m_xLbHorAlign->set_active_id(OUString::number(ALIGNDLG_HORALIGN_STD));
385 break;
386 case SvxCellHorJustify::Left:
387 m_xLbHorAlign->set_active_id(OUString::number(ALIGNDLG_HORALIGN_LEFT));
388 break;
389 case SvxCellHorJustify::Center:
390 m_xLbHorAlign->set_active_id(OUString::number(ALIGNDLG_HORALIGN_CENTER));
391 break;
392 case SvxCellHorJustify::Right:
393 m_xLbHorAlign->set_active_id(OUString::number(ALIGNDLG_HORALIGN_RIGHT));
394 break;
395 case SvxCellHorJustify::Block:
396 m_xLbHorAlign->set_active_id(OUString::number(ALIGNDLG_HORALIGN_BLOCK));
397 break;
398 case SvxCellHorJustify::Repeat:
399 m_xLbHorAlign->set_active_id(OUString::number(ALIGNDLG_HORALIGN_FILL));
400 break;
402 break;
406 nWhich = GetWhich(SID_ATTR_ALIGN_INDENT);
407 eState = pCoreAttrs->GetItemState(nWhich);
408 switch (eState)
410 case SfxItemState::UNKNOWN:
411 m_xEdIndent->hide();
412 m_xFtIndent->hide();
413 break;
414 case SfxItemState::DISABLED:
415 case SfxItemState::READONLY:
416 m_xEdIndent->set_sensitive(false);
417 break;
418 case SfxItemState::DONTCARE:
419 m_xEdIndent->set_text("");
420 break;
421 case SfxItemState::DEFAULT:
422 case SfxItemState::SET:
424 const SfxUInt16Item& rIndentItem = static_cast<const SfxUInt16Item&>(pCoreAttrs->Get(nWhich));
425 m_xEdIndent->set_value(rIndentItem.GetValue(), FieldUnit::TWIP);
426 break;
430 nWhich = GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY);
431 eState = pCoreAttrs->GetItemState(nWhich);
432 switch (eState)
434 case SfxItemState::UNKNOWN:
435 m_xLbVerAlign->hide();
436 m_xFtVerAlign->hide();
437 break;
438 case SfxItemState::DISABLED:
439 case SfxItemState::READONLY:
440 m_xLbVerAlign->set_sensitive(false);
441 break;
442 case SfxItemState::DONTCARE:
443 m_xLbVerAlign->set_active(-1);
444 break;
445 case SfxItemState::DEFAULT:
446 case SfxItemState::SET:
448 const SvxVerJustifyItem& rJustifyItem = static_cast<const SvxVerJustifyItem&>(pCoreAttrs->Get(nWhich));
449 switch (rJustifyItem.GetValue())
451 case SvxCellVerJustify::Standard:
452 m_xLbVerAlign->set_active_id(OUString::number(ALIGNDLG_VERALIGN_STD));
453 break;
454 case SvxCellVerJustify::Top:
455 m_xLbVerAlign->set_active_id(OUString::number(ALIGNDLG_VERALIGN_TOP));
456 break;
457 case SvxCellVerJustify::Center:
458 m_xLbVerAlign->set_active_id(OUString::number(ALIGNDLG_VERALIGN_MID));
459 break;
460 case SvxCellVerJustify::Bottom:
461 m_xLbVerAlign->set_active_id(OUString::number(ALIGNDLG_VERALIGN_BOTTOM));
462 break;
463 case SvxCellVerJustify::Block:
464 m_xLbVerAlign->set_active_id(OUString::number(ALIGNDLG_VERALIGN_BLOCK));
465 break;
467 break;
471 nWhich = GetWhich(SID_ATTR_ALIGN_DEGREES);
472 eState = pCoreAttrs->GetItemState(nWhich);
473 switch (eState)
475 case SfxItemState::UNKNOWN:
476 m_xNfRotate->hide();
477 m_xCtrlDial->hide();
478 break;
479 case SfxItemState::DISABLED:
480 case SfxItemState::READONLY:
481 m_xNfRotate->set_sensitive(false);
482 m_xCtrlDial->set_sensitive(false);
483 break;
484 case SfxItemState::DONTCARE:
485 m_aCtrlDial.SetNoRotation();
486 break;
487 case SfxItemState::DEFAULT:
488 case SfxItemState::SET:
490 const SfxInt32Item& rAlignItem = static_cast<const SfxInt32Item&>(pCoreAttrs->Get(nWhich));
491 m_aCtrlDial.SetRotation(rAlignItem.GetValue());
492 break;
496 nWhich = GetWhich(SID_ATTR_ALIGN_LOCKPOS);
497 eState = pCoreAttrs->GetItemState(nWhich);
498 switch (eState)
500 case SfxItemState::UNKNOWN:
501 m_xVsRefEdge->hide();
502 break;
503 case SfxItemState::DISABLED:
504 case SfxItemState::READONLY:
505 m_xVsRefEdge->set_sensitive(false);
506 break;
507 case SfxItemState::DONTCARE:
508 m_aVsRefEdge.SetNoSelection();
509 break;
510 case SfxItemState::DEFAULT:
511 case SfxItemState::SET:
513 const SvxRotateModeItem& rRotateModeItem = static_cast<const SvxRotateModeItem&>(pCoreAttrs->Get(nWhich));
514 switch (rRotateModeItem.GetValue())
516 case SvxRotateMode::SVX_ROTATE_MODE_STANDARD:
517 m_aVsRefEdge.SelectItem(IID_CELLLOCK);
518 break;
519 case SvxRotateMode::SVX_ROTATE_MODE_TOP:
520 m_aVsRefEdge.SelectItem(IID_TOPLOCK);
521 break;
522 case SvxRotateMode::SVX_ROTATE_MODE_BOTTOM:
523 m_aVsRefEdge.SelectItem(IID_BOTTOMLOCK);
524 break;
525 default:
526 m_aVsRefEdge.SetNoSelection();
527 break;
529 break;
532 m_aVsRefEdge.SaveValue();
534 //text direction
535 nWhich = GetWhich(SID_ATTR_FRAMEDIRECTION);
536 eState = pCoreAttrs->GetItemState(nWhich);
537 switch (eState)
539 case SfxItemState::UNKNOWN:
540 m_xLbFrameDir->hide();
541 break;
542 case SfxItemState::DISABLED:
543 case SfxItemState::READONLY:
544 m_xLbFrameDir->set_sensitive(false);
545 break;
546 case SfxItemState::DONTCARE:
547 m_xLbFrameDir->set_active(-1);
548 break;
549 case SfxItemState::DEFAULT:
550 case SfxItemState::SET:
552 const SvxFrameDirectionItem& rFrameDirItem = static_cast<const SvxFrameDirectionItem&>(pCoreAttrs->Get(nWhich));
553 m_xLbFrameDir->set_active_id(rFrameDirItem.GetValue());
554 break;
559 // Special treatment for distributed alignment; we need to set the justify
560 // method to 'distribute' to distinguish from the normal justification.
562 lcl_MaybeResetAlignToDistro<SvxCellHorJustify, SvxCellHorJustify>(
563 *m_xLbHorAlign, ALIGNDLG_HORALIGN_DISTRIBUTED, *pCoreAttrs,
564 GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY), GetWhich(SID_ATTR_ALIGN_HOR_JUSTIFY_METHOD),
565 SvxCellHorJustify::Block);
567 lcl_MaybeResetAlignToDistro<SvxCellVerJustify, SvxCellVerJustify>(
568 *m_xLbVerAlign, ALIGNDLG_VERALIGN_DISTRIBUTED, *pCoreAttrs,
569 GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY), GetWhich(SID_ATTR_ALIGN_VER_JUSTIFY_METHOD),
570 SvxCellVerJustify::Block);
572 m_xLbHorAlign->save_value();
573 m_xLbFrameDir->save_value();
574 m_xLbVerAlign->save_value();
575 m_xNfRotate->save_value();
576 m_xEdIndent->save_value();
578 UpdateEnableControls();
581 DeactivateRC AlignmentTabPage::DeactivatePage( SfxItemSet* _pSet )
583 if( _pSet )
584 FillItemSet( _pSet );
585 return DeactivateRC::LeavePage;
588 void AlignmentTabPage::InitVsRefEgde()
590 // remember selection - is deleted in call to ValueSet::Clear()
591 sal_uInt16 nSel = m_aVsRefEdge.GetSelectedItemId();
593 Image aBottomLock(StockImage::Yes, RID_SVXBMP_BOTTOMLOCK);
594 Image aTopLock(StockImage::Yes, RID_SVXBMP_TOPLOCK);
595 Image aCellLock(StockImage::Yes, RID_SVXBMP_CELLLOCK);
597 m_aVsRefEdge.Clear();
598 m_aVsRefEdge.SetStyle(m_aVsRefEdge.GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER);
600 m_aVsRefEdge.SetColCount(3);
601 m_aVsRefEdge.InsertItem(IID_BOTTOMLOCK, aBottomLock, m_xFtBotLock->get_label());
602 m_aVsRefEdge.InsertItem(IID_TOPLOCK, aTopLock, m_xFtTopLock->get_label());
603 m_aVsRefEdge.InsertItem(IID_CELLLOCK, aCellLock, m_xFtCelLock->get_label());
604 m_aVsRefEdge.SetOptimalSize();
606 m_aVsRefEdge.SelectItem( nSel );
609 void AlignmentTabPage::UpdateEnableControls()
611 const sal_Int32 nHorAlign = m_xLbHorAlign->get_active();
612 bool bHorLeft = (nHorAlign == ALIGNDLG_HORALIGN_LEFT);
613 bool bHorBlock = (nHorAlign == ALIGNDLG_HORALIGN_BLOCK);
614 bool bHorFill = (nHorAlign == ALIGNDLG_HORALIGN_FILL);
615 bool bHorDist = (nHorAlign == ALIGNDLG_HORALIGN_DISTRIBUTED);
617 // indent edit field only for left alignment
618 m_xFtIndent->set_sensitive( bHorLeft );
619 m_xEdIndent->set_sensitive( bHorLeft );
621 // stacked disabled for fill alignment
622 m_xCbStacked->set_sensitive(!bHorFill);
624 // hyphenation only for automatic line breaks or for block alignment
625 m_xBtnHyphen->set_sensitive( m_xBtnWrap->get_active() || bHorBlock );
627 // shrink only without automatic line break, and not for block, fill or distribute.
628 m_xBtnShrink->set_sensitive( (m_xBtnWrap->get_state() == TRISTATE_FALSE) && !bHorBlock && !bHorFill && !bHorDist );
630 // visibility of frames
631 m_xAlignmentFrame->set_visible(m_xLbHorAlign->get_visible() || m_xEdIndent->get_visible() ||
632 m_xLbVerAlign->get_visible());
633 m_xOrientFrame->set_visible(m_xCtrlDial->get_visible() || m_xVsRefEdge->get_visible() ||
634 m_xCbStacked->get_visible() || m_xCbAsianMode->get_visible());
635 m_xPropertiesFrame->set_visible(m_xBtnWrap->get_visible() || m_xBtnHyphen->get_visible() ||
636 m_xBtnShrink->get_visible() || m_xLbFrameDir->get_visible());
638 bool bStackedText = m_xCbStacked->get_active();
639 // windows to be disabled, if stacked text is turned ON
640 m_xFtRotate->set_sensitive(!bStackedText);
641 m_xFtRefEdge->set_sensitive(!bStackedText);
642 m_xVsRefEdge->set_sensitive(!bStackedText);
643 // windows to be disabled, if stacked text is turned OFF
644 m_xCbAsianMode->set_sensitive(bStackedText);
645 // rotation/stacked disabled for fill alignment/stacked
646 m_xCtrlDial->set_sensitive(!bHorFill && !bStackedText);
647 m_xNfRotate->set_sensitive(!bHorFill && !bStackedText);
650 bool AlignmentTabPage::HasAlignmentChanged( const SfxItemSet& rNew, sal_uInt16 nWhich ) const
652 const SfxItemSet& rOld = GetItemSet();
653 const SfxPoolItem* pItem;
654 SvxCellJustifyMethod eMethodOld = SvxCellJustifyMethod::Auto;
655 SvxCellJustifyMethod eMethodNew = SvxCellJustifyMethod::Auto;
656 if (rOld.GetItemState(nWhich, true, &pItem) == SfxItemState::SET)
658 const SfxEnumItemInterface* p = static_cast<const SfxEnumItemInterface*>(pItem);
659 eMethodOld = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
662 if (rNew.GetItemState(nWhich, true, &pItem) == SfxItemState::SET)
664 const SfxEnumItemInterface* p = static_cast<const SfxEnumItemInterface*>(pItem);
665 eMethodNew = static_cast<SvxCellJustifyMethod>(p->GetEnumValue());
668 return eMethodOld != eMethodNew;
671 IMPL_LINK(AlignmentTabPage, StackedClickHdl, weld::ToggleButton&, rToggle, void)
673 m_aStackedState.ButtonToggled(rToggle);
674 UpdateEnableControls();
677 IMPL_LINK(AlignmentTabPage, AsianModeClickHdl, weld::ToggleButton&, rToggle, void)
679 m_aAsianModeState.ButtonToggled(rToggle);
682 IMPL_LINK(AlignmentTabPage, WrapClickHdl, weld::ToggleButton&, rToggle, void)
684 m_aWrapState.ButtonToggled(rToggle);
685 UpdateEnableControls();
688 IMPL_LINK(AlignmentTabPage, HyphenClickHdl, weld::ToggleButton&, rToggle, void)
690 m_aHyphenState.ButtonToggled(rToggle);
693 IMPL_LINK(AlignmentTabPage, ShrinkClickHdl, weld::ToggleButton&, rToggle, void)
695 m_aShrinkState.ButtonToggled(rToggle);
698 IMPL_LINK_NOARG(AlignmentTabPage, UpdateEnableHdl, weld::ComboBox&, void)
700 UpdateEnableControls();
705 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */