LibreOffice Module sc (master) 1
AlignmentPropertyPanel.cxx
Go to the documentation of this file.
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
22#include <sc.hrc>
23#include <attrib.hxx>
24#include <scitems.hxx>
25#include <sfx2/bindings.hxx>
26#include <sfx2/dispatch.hxx>
27#include <svl/intitem.hxx>
28#include <svx/rotmodit.hxx>
29#include <svtools/unitconv.hxx>
30#include <com/sun/star/lang/IllegalArgumentException.hpp>
31
32using namespace css;
33using namespace css::uno;
34
35// namespace open
36
37namespace sc::sidebar {
38
40 weld::Widget* pParent,
41 const css::uno::Reference<css::frame::XFrame>& rxFrame,
42 SfxBindings* pBindings)
43 : PanelLayout(pParent, "AlignmentPropertyPanel", "modules/scalc/ui/sidebaralignment.ui")
44 , mxFTLeftIndent(m_xBuilder->weld_label("leftindentlabel"))
45 , mxMFLeftIndent(m_xBuilder->weld_metric_spin_button("leftindent", FieldUnit::POINT))
46 , mxCBXWrapText(m_xBuilder->weld_check_button("wraptext"))
47 , mxCBXMergeCell(m_xBuilder->weld_check_button("mergecells"))
48 , mxFtRotate(m_xBuilder->weld_label("orientationlabel"))
49 , mxMtrAngle(m_xBuilder->weld_metric_spin_button("orientationdegrees", FieldUnit::DEGREE))
50 , mxRefEdgeBottom(m_xBuilder->weld_toggle_button("bottom"))
51 , mxRefEdgeTop(m_xBuilder->weld_toggle_button("top"))
52 , mxRefEdgeStd(m_xBuilder->weld_toggle_button("standard"))
53 , mxCBStacked(m_xBuilder->weld_check_button("stacked"))
54 , mxTextOrientBox(m_xBuilder->weld_widget("textorientbox"))
55 , mxHorizontalAlign(m_xBuilder->weld_toolbar("horizontalalignment"))
56 , mxHorizontalAlignDispatch(new ToolbarUnoDispatcher(*mxHorizontalAlign, *m_xBuilder, rxFrame))
57 , mxVertAlign(m_xBuilder->weld_toolbar("verticalalignment"))
58 , mxVertAlignDispatch(new ToolbarUnoDispatcher(*mxVertAlign, *m_xBuilder, rxFrame))
59 , mxWriteDirection(m_xBuilder->weld_toolbar("writedirection"))
60 , mxWriteDirectionDispatch(new ToolbarUnoDispatcher(*mxWriteDirection, *m_xBuilder, rxFrame))
61 , mxIndentButtons(m_xBuilder->weld_toolbar("indentbuttons"))
62 , mxIndentButtonsDispatch(new ToolbarUnoDispatcher(*mxIndentButtons, *m_xBuilder, rxFrame))
63 , maAlignHorControl(SID_H_ALIGNCELL, *pBindings, *this)
64 , maLeftIndentControl(SID_ATTR_ALIGN_INDENT, *pBindings, *this)
65 , maMergeCellControl(FID_MERGE_TOGGLE, *pBindings, *this)
66 , maWrapTextControl(SID_ATTR_ALIGN_LINEBREAK, *pBindings, *this)
67 , maAngleControl(SID_ATTR_ALIGN_DEGREES, *pBindings, *this)
68 , maVrtStackControl(SID_ATTR_ALIGN_STACKED, *pBindings, *this)
69 , maRefEdgeControl(SID_ATTR_ALIGN_LOCKPOS, *pBindings, *this)
70 , mbMultiDisable(false)
71 , mpBindings(pBindings)
72{
73 Initialize();
74}
75
77{
79 mxIndentButtons.reset();
81 mxWriteDirection.reset();
82 mxVertAlignDispatch.reset();
83 mxVertAlign.reset();
85 mxHorizontalAlign.reset();
86
87 mxFTLeftIndent.reset();
88 mxMFLeftIndent.reset();
89 mxCBXWrapText.reset();
90 mxCBXMergeCell.reset();
91 mxFtRotate.reset();
92 mxMtrAngle.reset();
93 mxCBStacked.reset();
94 mxRefEdgeBottom.reset();
95 mxRefEdgeTop.reset();
96 mxRefEdgeStd.reset();
97 mxTextOrientBox.reset();
98
106}
107
109{
110 mxFTLeftIndent->set_sensitive(false);
111 mxMFLeftIndent->set_sensitive(false);
112 Link<weld::MetricSpinButton&,void> aLink = LINK(this, AlignmentPropertyPanel, MFLeftIndentMdyHdl);
113 mxMFLeftIndent->connect_value_changed( aLink );
114
115 mxCBXMergeCell->connect_toggled( LINK(this, AlignmentPropertyPanel, CBOXMergnCellClkHdl) );
116
117 mxCBXWrapText->connect_toggled( LINK(this, AlignmentPropertyPanel, CBOXWrapTextClkHdl) );
118
119 //rotation
120 mxMtrAngle->connect_value_changed(LINK( this, AlignmentPropertyPanel, AngleModifiedHdl));
121 mxCBStacked->connect_toggled(LINK(this, AlignmentPropertyPanel, ClickStackHdl));
122
123 Link<weld::Button&,void> aLink2 = LINK(this, AlignmentPropertyPanel, ReferenceEdgeHdl);
124 mxRefEdgeBottom->connect_clicked(aLink2);
125 mxRefEdgeTop->connect_clicked(aLink2);
126 mxRefEdgeStd->connect_clicked(aLink2);
127}
128
129IMPL_LINK(AlignmentPropertyPanel, ReferenceEdgeHdl, weld::Button&, rToggle, void)
130{
132 if (&rToggle == mxRefEdgeBottom.get())
134 else if (&rToggle == mxRefEdgeTop.get())
136 else /*if (&rToggle == mxRefEdgeStd.get())*/
138
139 mxRefEdgeBottom->set_active(eMode == SVX_ROTATE_MODE_BOTTOM);
140 mxRefEdgeTop->set_active(eMode == SVX_ROTATE_MODE_TOP);
141 mxRefEdgeStd->set_active(eMode == SVX_ROTATE_MODE_STANDARD);
142
144 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_ALIGN_LOCKPOS,
145 SfxCallMode::RECORD, { &aItem });
146}
147
149{
150 Degree100 nAngle(mxMtrAngle->get_value(FieldUnit::DEGREE) * 100);
151 ScRotateValueItem aAngleItem(nAngle);
152
154 SID_ATTR_ALIGN_DEGREES, SfxCallMode::RECORD, { &aAngleItem });
155}
156
158{
159 bool bVertical = mxCBStacked->get_active();
160 ScVerticalStackCell aStackItem(bVertical);
162 SID_ATTR_ALIGN_STACKED, SfxCallMode::RECORD, { &aStackItem });
163}
164
166{
167 sal_uInt16 nVal = mxMFLeftIndent->get_value(FieldUnit::NONE);
168 ScIndentItem aItem(static_cast<sal_uInt16>(CalcToUnit(nVal, MapUnit::MapTwip)));
169
170 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_ALIGN_INDENT,
171 SfxCallMode::RECORD, { &aItem });
172}
173
175{
176 bool bState = mxCBXMergeCell->get_active();
177
178 if( bState)
179 GetBindings()->GetDispatcher()->Execute(FID_MERGE_ON, SfxCallMode::RECORD);
180 else
181 GetBindings()->GetDispatcher()->Execute(FID_MERGE_OFF, SfxCallMode::RECORD);
182 GetBindings()->Invalidate(FID_MERGE_TOGGLE,true);
183}
184
186{
187 bool bState = mxCBXWrapText->get_active();
188 ScLineBreakCell aItem(bState);
189 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_ALIGN_LINEBREAK,
190 SfxCallMode::RECORD, { &aItem });
191}
192
193std::unique_ptr<PanelLayout> AlignmentPropertyPanel::Create (
194 weld::Widget* pParent,
195 const css::uno::Reference<css::frame::XFrame>& rxFrame,
196 SfxBindings* pBindings)
197{
198 if (pParent == nullptr)
199 throw lang::IllegalArgumentException("no parent Window given to AlignmentPropertyPanel::Create", nullptr, 0);
200 if ( ! rxFrame.is())
201 throw lang::IllegalArgumentException("no XFrame given to AlignmentPropertyPanel::Create", nullptr, 1);
202 if (pBindings == nullptr)
203 throw lang::IllegalArgumentException("no SfxBindings given to AlignmentPropertyPanel::Create", nullptr, 2);
204
205 return std::make_unique<AlignmentPropertyPanel>(pParent, rxFrame, pBindings);
206}
207
209 const vcl::EnumContext& rContext)
210{
211 if (maContext == rContext)
212 {
213 // Nothing to do.
214 return;
215 }
216
217 maContext = rContext;
218}
219
221 sal_uInt16 nSID,
222 SfxItemState eState,
223 const SfxPoolItem* pState)
224{
225 switch(nSID)
226 {
227 case SID_H_ALIGNCELL:
228 {
229 SvxCellHorJustify meHorAlignState = SvxCellHorJustify::Standard;
230 if(eState >= SfxItemState::DEFAULT)
231 if (auto pItem = dynamic_cast<const SvxHorJustifyItem*>( pState) )
232 meHorAlignState = pItem->GetValue();
233
234 if( meHorAlignState == SvxCellHorJustify::Repeat )
235 {
236 mxFtRotate->set_sensitive(false);
237 mxMtrAngle->set_sensitive(false);
238 }
239 else
240 {
241 mxFtRotate->set_sensitive(!mbMultiDisable);
242 mxMtrAngle->set_sensitive(!mbMultiDisable);
243 }
244
245 mxFTLeftIndent->set_sensitive( meHorAlignState == SvxCellHorJustify::Left );
246 mxMFLeftIndent->set_sensitive( meHorAlignState == SvxCellHorJustify::Left );
247 }
248 break;
249 case SID_ATTR_ALIGN_INDENT:
250 if(eState >= SfxItemState::DEFAULT && dynamic_cast<const SfxUInt16Item*>( pState) )
251 {
252 const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
253 sal_uInt16 nVal = pItem->GetValue();
254 mxMFLeftIndent->set_value( CalcToPoint(nVal, MapUnit::MapTwip, 1), FieldUnit::NONE );
255 }
256 else
257 {
258 mxMFLeftIndent->set_value(0, FieldUnit::NONE);
259 mxMFLeftIndent->set_text(OUString());
260 }
261 break;
262 case FID_MERGE_TOGGLE:
263 if(eState >= SfxItemState::DEFAULT && dynamic_cast<const SfxBoolItem*>( pState) )
264 {
265 mxCBXMergeCell->set_sensitive(true);
266 const SfxBoolItem* pItem = static_cast<const SfxBoolItem*>(pState);
267 mxCBXMergeCell->set_active(pItem->GetValue());
268 }
269 else
270 {
271 mxCBXMergeCell->set_active(false);
272 mxCBXMergeCell->set_sensitive(false);
273 }
274 break;
275
276 case SID_ATTR_ALIGN_LINEBREAK:
277 if(eState == SfxItemState::DISABLED)
278 {
279 mxCBXWrapText->set_active(false);
280 mxCBXWrapText->set_sensitive(false);
281 }
282 else
283 {
284 mxCBXWrapText->set_sensitive(true);
285 if(eState >= SfxItemState::DEFAULT && dynamic_cast<const ScLineBreakCell*>( pState) )
286 {
287 const ScLineBreakCell* pItem = static_cast<const ScLineBreakCell*>(pState);
288 mxCBXWrapText->set_active(pItem->GetValue());
289 }
290 else if(eState == SfxItemState::DONTCARE)
291 {
292 mxCBXWrapText->set_state(TRISTATE_INDET);
293 }
294 }
295 break;
296 case SID_ATTR_ALIGN_STACKED:
297 if (eState >= SfxItemState::DEFAULT)
298 {
299 const SfxBoolItem* pStackItem = static_cast<const ScVerticalStackCell*>(pState);
300 mbMultiDisable = pStackItem->GetValue();
301 mxCBStacked->set_active(mbMultiDisable);
302 mxTextOrientBox->set_sensitive(!mbMultiDisable);
303 }
304 else
305 {
306 mbMultiDisable = true;
307 mxTextOrientBox->set_sensitive(false);
308 mxCBStacked->set_state(TRISTATE_INDET);
309 }
310 break;
311 case SID_ATTR_ALIGN_LOCKPOS:
312 if( eState >= SfxItemState::DEFAULT)
313 {
314 const SvxRotateModeItem* pItem = static_cast<const SvxRotateModeItem*>(pState);
315 SvxRotateMode eMode = pItem->GetValue();
317 mxRefEdgeTop->set_active(eMode == SVX_ROTATE_MODE_TOP);
319 }
320 break;
321 case SID_ATTR_ALIGN_DEGREES:
322 if (eState >= SfxItemState::DEFAULT)
323 {
324 Degree100 nTmp = static_cast<const ScRotateValueItem*>(pState)->GetValue();
325 mxMtrAngle->set_value(toDegrees(nTmp), FieldUnit::DEGREE);
326 }
327 else
328 {
329 mxMtrAngle->set_text( OUString() );
330 }
331 break;
332 }
333}
334
335// namespace close
336
337} // end of namespace ::sc::sidebar
338
339/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetValue() const
SfxDispatcher * GetDispatcher() const
void Invalidate(sal_uInt16 nId)
bool GetValue() const
virtual void dispose()
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
::sfx2::sidebar::ControllerItem maAngleControl
std::unique_ptr< ToolbarUnoDispatcher > mxHorizontalAlignDispatch
::sfx2::sidebar::ControllerItem maAlignHorControl
std::unique_ptr< weld::ToggleButton > mxRefEdgeTop
std::unique_ptr< weld::Label > mxFtRotate
std::unique_ptr< weld::Toolbar > mxVertAlign
std::unique_ptr< weld::CheckButton > mxCBXMergeCell
std::unique_ptr< weld::CheckButton > mxCBXWrapText
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
std::unique_ptr< weld::Toolbar > mxIndentButtons
std::unique_ptr< weld::ToggleButton > mxRefEdgeBottom
::sfx2::sidebar::ControllerItem maVrtStackControl
std::unique_ptr< ToolbarUnoDispatcher > mxWriteDirectionDispatch
::sfx2::sidebar::ControllerItem maLeftIndentControl
std::unique_ptr< weld::CheckButton > mxCBStacked
std::unique_ptr< weld::Toolbar > mxWriteDirection
std::unique_ptr< ToolbarUnoDispatcher > mxVertAlignDispatch
virtual void HandleContextChange(const vcl::EnumContext &rContext) override
std::unique_ptr< weld::ToggleButton > mxRefEdgeStd
std::unique_ptr< weld::MetricSpinButton > mxMFLeftIndent
::sfx2::sidebar::ControllerItem maRefEdgeControl
std::unique_ptr< weld::Toolbar > mxHorizontalAlign
std::unique_ptr< weld::MetricSpinButton > mxMtrAngle
std::unique_ptr< ToolbarUnoDispatcher > mxIndentButtonsDispatch
std::unique_ptr< weld::Label > mxFTLeftIndent
::sfx2::sidebar::ControllerItem maMergeCellControl
AlignmentPropertyPanel(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
::sfx2::sidebar::ControllerItem maWrapTextControl
std::unique_ptr< weld::Widget > mxTextOrientBox
double toDegrees(D x)
virtual SfxBindings & GetBindings() override
FieldUnit
TRISTATE_INDET
Mode eMode
IMPL_LINK(AlignmentPropertyPanel, ReferenceEdgeHdl, weld::Button &, rToggle, void)
IMPL_LINK_NOARG(AlignmentPropertyPanel, AngleModifiedHdl, weld::MetricSpinButton &, void)
const char GetValue[]
SfxItemState
SvxRotateMode
SVX_ROTATE_MODE_BOTTOM
SVX_ROTATE_MODE_STANDARD
SVX_ROTATE_MODE_TOP
constexpr TypedWhichId< SvxRotateModeItem > ATTR_ROTATE_MODE(136)
SvxCellHorJustify
SVT_DLLPUBLIC tools::Long CalcToPoint(tools::Long nIn, MapUnit eUnit, sal_uInt16 nFactor)
SVT_DLLPUBLIC tools::Long CalcToUnit(float nIn, MapUnit eUnit)