1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
11 #include "TableEditPanel.hxx"
12 #include <sal/config.h>
13 #include <swtypes.hxx>
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>
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);
36 throw css::lang::IllegalArgumentException("no XFrame given to TableEditPanel::Create",
39 return std::make_unique
<TableEditPanel
>(pParent
, rxFrame
, pBindings
);
42 void TableEditPanel::NotifyItemUpdate(const sal_uInt16 nSID
, const SfxItemState eState
,
43 const SfxPoolItem
* pState
)
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
);
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("");
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
);
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("");
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();
174 m_xSplitMergeDispatch
.reset();
175 m_xSplitMerge
.reset();
177 m_xDeleteDispatch
.reset();
180 m_xColumnSizingDispatch
.reset();
181 m_xColumnSizing
.reset();
183 m_xRowSizingDispatch
.reset();
184 m_xRowSizing
.reset();
186 m_xSelectDispatch
.reset();
189 m_xInsertDispatch
.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
,
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
,
231 } // end of namespace ::sw::sidebar
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */