Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / sidebar / TableEditPanel.cxx
blob61dcd2d4e52a35190197407e3eafdd75fc5fd505
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 <svx/dlgctrl.hxx>
19 #include <swmodule.hxx>
20 #include <usrpref.hxx>
21 #include <comphelper/lok.hxx>
23 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 namespace sw::sidebar
27 std::unique_ptr<PanelLayout>
28 TableEditPanel::Create(weld::Widget* 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 std::make_unique<TableEditPanel>(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_aRowHeightEdit.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_aRowHeightEdit.normalize(nNewHeight);
59 m_aRowHeightEdit.set_value(nNewHeight, FieldUnit::TWIP);
62 else if (eState != SfxItemState::DISABLED)
63 m_aRowHeightEdit.set_text("");
65 break;
67 case SID_ATTR_TABLE_COLUMN_WIDTH:
69 bool bDisabled = eState == SfxItemState::DISABLED;
70 m_aColumnWidthEdit.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_aColumnWidthEdit.normalize(nNewWidth);
79 m_aColumnWidthEdit.set_value(nNewWidth, FieldUnit::TWIP);
82 else if (eState != SfxItemState::DISABLED)
83 m_aColumnWidthEdit.set_text("");
85 break;
90 TableEditPanel::TableEditPanel(weld::Widget* pParent,
91 const css::uno::Reference<css::frame::XFrame>& rxFrame,
92 SfxBindings* pBindings)
93 : PanelLayout(pParent, "TableEditPanel", "modules/swriter/ui/sidebartableedit.ui")
94 , m_pBindings(pBindings)
95 , m_aRowHeightEdit(m_xBuilder->weld_metric_spin_button("rowheight", FieldUnit::CM))
96 , m_aColumnWidthEdit(m_xBuilder->weld_metric_spin_button("columnwidth", FieldUnit::CM))
97 , m_xInsert(m_xBuilder->weld_toolbar("insert"))
98 , m_xInsertDispatch(new ToolbarUnoDispatcher(*m_xInsert, *m_xBuilder, rxFrame))
99 , m_xSelect(m_xBuilder->weld_toolbar("select"))
100 , m_xSelectDispatch(new ToolbarUnoDispatcher(*m_xSelect, *m_xBuilder, rxFrame))
101 , m_xRowSizing(m_xBuilder->weld_toolbar("rowsizing"))
102 , m_xRowSizingDispatch(new ToolbarUnoDispatcher(*m_xRowSizing, *m_xBuilder, rxFrame))
103 , m_xColumnSizing(m_xBuilder->weld_toolbar("columnsizing"))
104 , m_xColumnSizingDispatch(new ToolbarUnoDispatcher(*m_xColumnSizing, *m_xBuilder, rxFrame))
105 , m_xDelete(m_xBuilder->weld_toolbar("delete"))
106 , m_xDeleteDispatch(new ToolbarUnoDispatcher(*m_xDelete, *m_xBuilder, rxFrame))
107 , m_xSplitMerge(m_xBuilder->weld_toolbar("split_merge"))
108 , m_xSplitMergeDispatch(new ToolbarUnoDispatcher(*m_xSplitMerge, *m_xBuilder, rxFrame))
109 , m_xMisc(m_xBuilder->weld_toolbar("misc"))
110 , m_xMiscDispatch(new ToolbarUnoDispatcher(*m_xMisc, *m_xBuilder, rxFrame))
111 , m_aRowHeightController(SID_ATTR_TABLE_ROW_HEIGHT, *pBindings, *this)
112 , m_aColumnWidthController(SID_ATTR_TABLE_COLUMN_WIDTH, *pBindings, *this)
113 , m_aInsertRowsBeforeController(FN_TABLE_INSERT_ROW_BEFORE, *pBindings, *this)
114 , m_aInsertRowsAfterController(FN_TABLE_INSERT_ROW_AFTER, *pBindings, *this)
115 , m_aInsertColumnsBeforeController(FN_TABLE_INSERT_COL_BEFORE, *pBindings, *this)
116 , m_aInsertColumnsAfterController(FN_TABLE_INSERT_COL_AFTER, *pBindings, *this)
117 , m_aDeleteRowsController(FN_TABLE_DELETE_ROW, *pBindings, *this)
118 , m_aDeleteColumnsController(FN_TABLE_DELETE_COL, *pBindings, *this)
119 , m_aDeleteTableController(FN_TABLE_DELETE_TABLE, *pBindings, *this)
120 , m_aSetMinimalRowHeightController(SID_TABLE_MINIMAL_ROW_HEIGHT, *pBindings, *this)
121 , m_aSetOptimalRowHeightController(FN_TABLE_OPTIMAL_HEIGHT, *pBindings, *this)
122 , m_aDistributeRowsController(FN_TABLE_BALANCE_ROWS, *pBindings, *this)
123 , m_aSetMinimalColumnWidthController(SID_TABLE_MINIMAL_COLUMN_WIDTH, *pBindings, *this)
124 , m_aSetOptimalColumnWidthController(FN_TABLE_ADJUST_CELLS, *pBindings, *this)
125 , m_aDistributeColumnsController(FN_TABLE_BALANCE_CELLS, *pBindings, *this)
126 , m_aMergeCellsController(FN_TABLE_MERGE_CELLS, *pBindings, *this)
128 // tdf#130197 Give this toolbar a width as if it had 5 entries (the parent
129 // grid has homogeneous width set so both columns will have the same
130 // width). This will align this TableEditPanel's columns with
131 // ParaPropertyPanel's columns
132 padWidthForSidebar(*m_xSplitMerge, rxFrame);
134 InitRowHeightToolitem();
135 InitColumnWidthToolitem();
137 if (comphelper::LibreOfficeKit::isActive())
138 m_xMisc->set_item_visible(".uno:InsertFormula", false);
141 void TableEditPanel::InitRowHeightToolitem()
143 Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, RowHeightMofiyHdl);
144 m_aRowHeightEdit.connect_value_changed(aLink);
146 FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
147 m_aRowHeightEdit.SetFieldUnit(eFieldUnit);
149 m_aRowHeightEdit.set_min(MINLAY, FieldUnit::TWIP);
150 m_aRowHeightEdit.set_max(SAL_MAX_INT32, FieldUnit::TWIP);
152 limitWidthForSidebar(m_aRowHeightEdit);
155 void TableEditPanel::InitColumnWidthToolitem()
157 Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, ColumnWidthMofiyHdl);
158 m_aColumnWidthEdit.connect_value_changed(aLink);
160 FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
161 m_aColumnWidthEdit.SetFieldUnit(eFieldUnit);
163 m_aColumnWidthEdit.set_min(MINLAY, FieldUnit::TWIP);
164 m_aColumnWidthEdit.set_max(SAL_MAX_INT32, FieldUnit::TWIP);
166 limitWidthForSidebar(m_aColumnWidthEdit);
169 TableEditPanel::~TableEditPanel()
171 m_xMiscDispatch.reset();
172 m_xMisc.reset();
174 m_xSplitMergeDispatch.reset();
175 m_xSplitMerge.reset();
177 m_xDeleteDispatch.reset();
178 m_xDelete.reset();
180 m_xColumnSizingDispatch.reset();
181 m_xColumnSizing.reset();
183 m_xRowSizingDispatch.reset();
184 m_xRowSizing.reset();
186 m_xSelectDispatch.reset();
187 m_xSelect.reset();
189 m_xInsertDispatch.reset();
190 m_xInsert.reset();
192 m_aRowHeightController.dispose();
193 m_aColumnWidthController.dispose();
194 m_aInsertRowsBeforeController.dispose();
195 m_aInsertRowsAfterController.dispose();
196 m_aInsertColumnsBeforeController.dispose();
197 m_aInsertColumnsAfterController.dispose();
198 m_aDeleteRowsController.dispose();
199 m_aDeleteColumnsController.dispose();
200 m_aDeleteTableController.dispose();
201 m_aSetMinimalRowHeightController.dispose();
202 m_aSetOptimalRowHeightController.dispose();
203 m_aDistributeRowsController.dispose();
204 m_aSetMinimalColumnWidthController.dispose();
205 m_aSetOptimalColumnWidthController.dispose();
206 m_aDistributeColumnsController.dispose();
207 m_aMergeCellsController.dispose();
210 IMPL_LINK_NOARG(TableEditPanel, RowHeightMofiyHdl, weld::MetricSpinButton&, void)
212 SwTwips nNewHeight = static_cast<SwTwips>(
213 m_aRowHeightEdit.denormalize(m_aRowHeightEdit.get_value(FieldUnit::TWIP)));
214 SfxUInt32Item aRowHeight(SID_ATTR_TABLE_ROW_HEIGHT);
215 aRowHeight.SetValue(nNewHeight);
217 m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_ROW_HEIGHT, SfxCallMode::RECORD,
218 { &aRowHeight });
221 IMPL_LINK_NOARG(TableEditPanel, ColumnWidthMofiyHdl, weld::MetricSpinButton&, void)
223 SwTwips nNewWidth = static_cast<SwTwips>(
224 m_aColumnWidthEdit.denormalize(m_aColumnWidthEdit.get_value(FieldUnit::TWIP)));
225 SfxUInt32Item aColumnWidth(SID_ATTR_TABLE_COLUMN_WIDTH);
226 aColumnWidth.SetValue(nNewWidth);
228 m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_COLUMN_WIDTH, SfxCallMode::RECORD,
229 { &aColumnWidth });
231 } // end of namespace ::sw::sidebar
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */