nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / uibase / sidebar / TableEditPanel.cxx
blobde91b0e377373515ae5d63a6c1deee3f4a4f3767
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 */
11 #include "TableEditPanel.hxx"
12 #include <sal/config.h>
13 #include <swtypes.hxx>
14 #include <cmdid.h>
15 #include <svl/intitem.hxx>
16 #include <sfx2/bindings.hxx>
17 #include <sfx2/dispatch.hxx>
18 #include <svtools/unitconv.hxx>
19 #include <svx/dlgctrl.hxx>
20 #include <swmodule.hxx>
21 #include <usrpref.hxx>
22 #include <comphelper/lok.hxx>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 namespace sw::sidebar
28 VclPtr<vcl::Window> TableEditPanel::Create(vcl::Window* pParent,
29 const css::uno::Reference<css::frame::XFrame>& rxFrame,
30 SfxBindings* pBindings)
32 if (pParent == nullptr)
33 throw css::lang::IllegalArgumentException(
34 "no parent Window given to TableEditPanel::Create", nullptr, 0);
35 if (!rxFrame.is())
36 throw css::lang::IllegalArgumentException("no XFrame given to TableEditPanel::Create",
37 nullptr, 1);
39 return VclPtr<TableEditPanel>::Create(pParent, rxFrame, pBindings);
42 void TableEditPanel::NotifyItemUpdate(const sal_uInt16 nSID, const SfxItemState eState,
43 const SfxPoolItem* pState)
45 switch (nSID)
47 case SID_ATTR_TABLE_ROW_HEIGHT:
49 bool bDisabled = eState == SfxItemState::DISABLED;
50 m_xRowHeightEdit->set_sensitive(!bDisabled);
52 if (pState && eState >= SfxItemState::DEFAULT)
54 const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState);
55 if (pItem)
57 tools::Long nNewHeight = pItem->GetValue();
58 nNewHeight = m_xRowHeightEdit->normalize(nNewHeight);
59 m_xRowHeightEdit->set_value(nNewHeight, FieldUnit::TWIP);
62 else if (eState != SfxItemState::DISABLED)
63 m_xRowHeightEdit->set_text("");
65 break;
67 case SID_ATTR_TABLE_COLUMN_WIDTH:
69 bool bDisabled = eState == SfxItemState::DISABLED;
70 m_xColumnWidthEdit->set_sensitive(!bDisabled);
72 if (pState && eState >= SfxItemState::DEFAULT)
74 const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState);
75 if (pItem)
77 tools::Long nNewWidth = pItem->GetValue();
78 nNewWidth = m_xColumnWidthEdit->normalize(nNewWidth);
79 m_xColumnWidthEdit->set_value(nNewWidth, FieldUnit::TWIP);
82 else if (eState != SfxItemState::DISABLED)
83 m_xColumnWidthEdit->set_text("");
85 break;
90 TableEditPanel::TableEditPanel(vcl::Window* pParent,
91 const css::uno::Reference<css::frame::XFrame>& rxFrame,
92 SfxBindings* pBindings)
93 : PanelLayout(pParent, "TableEditPanel", "modules/swriter/ui/sidebartableedit.ui", rxFrame)
94 , m_pBindings(pBindings)
95 , m_xRowHeightEdit(
96 new SvxRelativeField(m_xBuilder->weld_metric_spin_button("rowheight", FieldUnit::CM)))
97 , m_xColumnWidthEdit(
98 new SvxRelativeField(m_xBuilder->weld_metric_spin_button("columnwidth", FieldUnit::CM)))
99 , m_xInsert(m_xBuilder->weld_toolbar("insert"))
100 , m_xInsertDispatch(new ToolbarUnoDispatcher(*m_xInsert, *m_xBuilder, rxFrame))
101 , m_xSelect(m_xBuilder->weld_toolbar("select"))
102 , m_xSelectDispatch(new ToolbarUnoDispatcher(*m_xSelect, *m_xBuilder, rxFrame))
103 , m_xRowSizing(m_xBuilder->weld_toolbar("rowsizing"))
104 , m_xRowSizingDispatch(new ToolbarUnoDispatcher(*m_xRowSizing, *m_xBuilder, rxFrame))
105 , m_xColumnSizing(m_xBuilder->weld_toolbar("columnsizing"))
106 , m_xColumnSizingDispatch(new ToolbarUnoDispatcher(*m_xColumnSizing, *m_xBuilder, rxFrame))
107 , m_xDelete(m_xBuilder->weld_toolbar("delete"))
108 , m_xDeleteDispatch(new ToolbarUnoDispatcher(*m_xDelete, *m_xBuilder, rxFrame))
109 , m_xSplitMerge(m_xBuilder->weld_toolbar("split_merge"))
110 , m_xSplitMergeDispatch(new ToolbarUnoDispatcher(*m_xSplitMerge, *m_xBuilder, rxFrame))
111 , m_xMisc(m_xBuilder->weld_toolbar("misc"))
112 , m_xMiscDispatch(new ToolbarUnoDispatcher(*m_xMisc, *m_xBuilder, rxFrame))
113 , m_aRowHeightController(SID_ATTR_TABLE_ROW_HEIGHT, *pBindings, *this)
114 , m_aColumnWidthController(SID_ATTR_TABLE_COLUMN_WIDTH, *pBindings, *this)
115 , m_aInsertRowsBeforeController(FN_TABLE_INSERT_ROW_BEFORE, *pBindings, *this)
116 , m_aInsertRowsAfterController(FN_TABLE_INSERT_ROW_AFTER, *pBindings, *this)
117 , m_aInsertColumnsBeforeController(FN_TABLE_INSERT_COL_BEFORE, *pBindings, *this)
118 , m_aInsertColumnsAfterController(FN_TABLE_INSERT_COL_AFTER, *pBindings, *this)
119 , m_aDeleteRowsController(FN_TABLE_DELETE_ROW, *pBindings, *this)
120 , m_aDeleteColumnsController(FN_TABLE_DELETE_COL, *pBindings, *this)
121 , m_aDeleteTableController(FN_TABLE_DELETE_TABLE, *pBindings, *this)
122 , m_aSetMinimalRowHeightController(SID_TABLE_MINIMAL_ROW_HEIGHT, *pBindings, *this)
123 , m_aSetOptimalRowHeightController(FN_TABLE_OPTIMAL_HEIGHT, *pBindings, *this)
124 , m_aDistributeRowsController(FN_TABLE_BALANCE_ROWS, *pBindings, *this)
125 , m_aSetMinimalColumnWidthController(SID_TABLE_MINIMAL_COLUMN_WIDTH, *pBindings, *this)
126 , m_aSetOptimalColumnWidthController(FN_TABLE_ADJUST_CELLS, *pBindings, *this)
127 , m_aDistributeColumnsController(FN_TABLE_BALANCE_CELLS, *pBindings, *this)
128 , m_aMergeCellsController(FN_TABLE_MERGE_CELLS, *pBindings, *this)
130 // tdf#130197 Give this toolbar a width as if it had 5 entries (the parent
131 // grid has homogeneous width set so both columns will have the same
132 // width). This will align this TableEditPanel's columns with
133 // ParaPropertyPanel's columns
134 padWidthForSidebar(*m_xSplitMerge, rxFrame);
136 InitRowHeightToolitem();
137 InitColumnWidthToolitem();
139 if (comphelper::LibreOfficeKit::isActive())
140 m_xMisc->set_item_visible(".uno:InsertFormula", false);
142 m_pInitialFocusWidget = &m_xRowHeightEdit->get_widget();
145 TableEditPanel::~TableEditPanel() { disposeOnce(); }
147 void TableEditPanel::InitRowHeightToolitem()
149 Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, RowHeightMofiyHdl);
150 m_xRowHeightEdit->connect_value_changed(aLink);
152 FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
153 m_xRowHeightEdit->SetFieldUnit(eFieldUnit);
155 m_xRowHeightEdit->set_min(MINLAY, FieldUnit::TWIP);
156 m_xRowHeightEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
158 limitWidthForSidebar(*m_xRowHeightEdit);
161 void TableEditPanel::InitColumnWidthToolitem()
163 Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, ColumnWidthMofiyHdl);
164 m_xColumnWidthEdit->connect_value_changed(aLink);
166 FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
167 m_xColumnWidthEdit->SetFieldUnit(eFieldUnit);
169 m_xColumnWidthEdit->set_min(MINLAY, FieldUnit::TWIP);
170 m_xColumnWidthEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
172 limitWidthForSidebar(*m_xColumnWidthEdit);
175 void TableEditPanel::dispose()
177 m_xRowHeightEdit.reset();
178 m_xColumnWidthEdit.reset();
180 m_xMiscDispatch.reset();
181 m_xMisc.reset();
183 m_xSplitMergeDispatch.reset();
184 m_xSplitMerge.reset();
186 m_xDeleteDispatch.reset();
187 m_xDelete.reset();
189 m_xColumnSizingDispatch.reset();
190 m_xColumnSizing.reset();
192 m_xRowSizingDispatch.reset();
193 m_xRowSizing.reset();
195 m_xSelectDispatch.reset();
196 m_xSelect.reset();
198 m_xInsertDispatch.reset();
199 m_xInsert.reset();
201 m_aRowHeightController.dispose();
202 m_aColumnWidthController.dispose();
203 m_aInsertRowsBeforeController.dispose();
204 m_aInsertRowsAfterController.dispose();
205 m_aInsertColumnsBeforeController.dispose();
206 m_aInsertColumnsAfterController.dispose();
207 m_aDeleteRowsController.dispose();
208 m_aDeleteColumnsController.dispose();
209 m_aDeleteTableController.dispose();
210 m_aSetMinimalRowHeightController.dispose();
211 m_aSetOptimalRowHeightController.dispose();
212 m_aDistributeRowsController.dispose();
213 m_aSetMinimalColumnWidthController.dispose();
214 m_aSetOptimalColumnWidthController.dispose();
215 m_aDistributeColumnsController.dispose();
216 m_aMergeCellsController.dispose();
218 PanelLayout::dispose();
221 IMPL_LINK_NOARG(TableEditPanel, RowHeightMofiyHdl, weld::MetricSpinButton&, void)
223 SwTwips nNewHeight = static_cast<SwTwips>(
224 m_xRowHeightEdit->denormalize(m_xRowHeightEdit->get_value(FieldUnit::TWIP)));
225 SfxUInt32Item aRowHeight(SID_ATTR_TABLE_ROW_HEIGHT);
226 aRowHeight.SetValue(nNewHeight);
228 m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_ROW_HEIGHT, SfxCallMode::RECORD,
229 { &aRowHeight });
232 IMPL_LINK_NOARG(TableEditPanel, ColumnWidthMofiyHdl, weld::MetricSpinButton&, void)
234 SwTwips nNewWidth = static_cast<SwTwips>(
235 m_xColumnWidthEdit->denormalize(m_xColumnWidthEdit->get_value(FieldUnit::TWIP)));
236 SfxUInt32Item aColumnWidth(SID_ATTR_TABLE_COLUMN_WIDTH);
237 aColumnWidth.SetValue(nNewWidth);
239 m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_COLUMN_WIDTH, SfxCallMode::RECORD,
240 { &aColumnWidth });
242 } // end of namespace ::sw::sidebar
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */