LibreOffice Module sw (master) 1
TableEditPanel.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 */
10
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>
22
23#include <com/sun/star/lang/IllegalArgumentException.hpp>
24
25namespace sw::sidebar
26{
27std::unique_ptr<PanelLayout>
29 const css::uno::Reference<css::frame::XFrame>& rxFrame,
30 SfxBindings* pBindings)
31{
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);
38
39 return std::make_unique<TableEditPanel>(pParent, rxFrame, pBindings);
40}
41
42void TableEditPanel::NotifyItemUpdate(const sal_uInt16 nSID, const SfxItemState eState,
43 const SfxPoolItem* pState)
44{
45 switch (nSID)
46 {
48 {
49 bool bDisabled = eState == SfxItemState::DISABLED;
51
52 if (pState && eState >= SfxItemState::DEFAULT)
53 {
54 const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState);
55 if (pItem)
56 {
57 tools::Long nNewHeight = pItem->GetValue();
58 nNewHeight = m_aRowHeightEdit.normalize(nNewHeight);
59 m_aRowHeightEdit.set_value(nNewHeight, FieldUnit::TWIP);
60 }
61 }
62 else if (eState != SfxItemState::DISABLED)
64
65 break;
66 }
68 {
69 bool bDisabled = eState == SfxItemState::DISABLED;
71
72 if (pState && eState >= SfxItemState::DEFAULT)
73 {
74 const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState);
75 if (pItem)
76 {
77 tools::Long nNewWidth = pItem->GetValue();
78 nNewWidth = m_aColumnWidthEdit.normalize(nNewWidth);
79 m_aColumnWidthEdit.set_value(nNewWidth, FieldUnit::TWIP);
80 }
81 }
82 else if (eState != SfxItemState::DISABLED)
84
85 break;
86 }
87 }
88}
89
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)
127{
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
133
136
138 m_xMisc->set_item_visible(".uno:InsertFormula", false);
139}
140
142{
143 Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, RowHeightMofiyHdl);
145
146 FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
147 m_aRowHeightEdit.SetFieldUnit(eFieldUnit);
148
149 m_aRowHeightEdit.set_min(MINLAY, FieldUnit::TWIP);
150 m_aRowHeightEdit.set_max(SAL_MAX_INT32, FieldUnit::TWIP);
151
153}
154
156{
157 Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, ColumnWidthMofiyHdl);
159
160 FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
162
163 m_aColumnWidthEdit.set_min(MINLAY, FieldUnit::TWIP);
164 m_aColumnWidthEdit.set_max(SAL_MAX_INT32, FieldUnit::TWIP);
165
167}
168
170{
171 m_xMiscDispatch.reset();
172 m_xMisc.reset();
173
174 m_xSplitMergeDispatch.reset();
175 m_xSplitMerge.reset();
176
177 m_xDeleteDispatch.reset();
178 m_xDelete.reset();
179
181 m_xColumnSizing.reset();
182
183 m_xRowSizingDispatch.reset();
184 m_xRowSizing.reset();
185
186 m_xSelectDispatch.reset();
187 m_xSelect.reset();
188
189 m_xInsertDispatch.reset();
190 m_xInsert.reset();
191
208}
209
211{
212 SwTwips nNewHeight = static_cast<SwTwips>(
213 m_aRowHeightEdit.denormalize(m_aRowHeightEdit.get_value(FieldUnit::TWIP)));
215 aRowHeight.SetValue(nNewHeight);
216
217 m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_ROW_HEIGHT, SfxCallMode::RECORD,
218 { &aRowHeight });
219}
220
222{
223 SwTwips nNewWidth = static_cast<SwTwips>(
224 m_aColumnWidthEdit.denormalize(m_aColumnWidthEdit.get_value(FieldUnit::TWIP)));
226 aColumnWidth.SetValue(nNewWidth);
227
228 m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_COLUMN_WIDTH, SfxCallMode::RECORD,
229 { &aColumnWidth });
230}
231} // end of namespace ::sw::sidebar
232
233/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetValue(sal_uInt32 nTheValue)
sal_uInt32 GetValue() const
virtual void dispose()
void set_text(const OUString &rText)
int normalize(int nValue) const
void connect_value_changed(const Link< weld::MetricSpinButton &, void > &rLink)
void set_min(int min, FieldUnit eValueUnit)
void SetFieldUnit(FieldUnit eUnit, bool bAll=false)
void set_max(int max, FieldUnit eValueUnit)
void set_value(int nValue, FieldUnit eValueUnit)
void set_sensitive(bool sensitive)
std::unique_ptr< weld::Toolbar > m_xSplitMerge
std::unique_ptr< ToolbarUnoDispatcher > m_xMiscDispatch
::sfx2::sidebar::ControllerItem m_aInsertRowsAfterController
std::unique_ptr< ToolbarUnoDispatcher > m_xRowSizingDispatch
std::unique_ptr< weld::Toolbar > m_xInsert
::sfx2::sidebar::ControllerItem m_aInsertColumnsAfterController
std::unique_ptr< weld::Toolbar > m_xDelete
::sfx2::sidebar::ControllerItem m_aRowHeightController
::sfx2::sidebar::ControllerItem m_aMergeCellsController
::sfx2::sidebar::ControllerItem m_aSetOptimalRowHeightController
std::unique_ptr< ToolbarUnoDispatcher > m_xInsertDispatch
std::unique_ptr< ToolbarUnoDispatcher > m_xColumnSizingDispatch
::sfx2::sidebar::ControllerItem m_aDeleteColumnsController
::sfx2::sidebar::ControllerItem m_aColumnWidthController
std::unique_ptr< ToolbarUnoDispatcher > m_xDeleteDispatch
std::unique_ptr< weld::Toolbar > m_xColumnSizing
::sfx2::sidebar::ControllerItem m_aDeleteTableController
::sfx2::sidebar::ControllerItem m_aInsertRowsBeforeController
std::unique_ptr< weld::Toolbar > m_xSelect
TableEditPanel(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
::sfx2::sidebar::ControllerItem m_aSetMinimalColumnWidthController
::sfx2::sidebar::ControllerItem m_aInsertColumnsBeforeController
std::unique_ptr< ToolbarUnoDispatcher > m_xSelectDispatch
virtual ~TableEditPanel() override
SvxRelativeField m_aColumnWidthEdit
std::unique_ptr< weld::Toolbar > m_xRowSizing
std::unique_ptr< weld::Toolbar > m_xMisc
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
SvxRelativeField m_aRowHeightEdit
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
::sfx2::sidebar::ControllerItem m_aSetMinimalRowHeightController
::sfx2::sidebar::ControllerItem m_aDistributeRowsController
::sfx2::sidebar::ControllerItem m_aDeleteRowsController
::sfx2::sidebar::ControllerItem m_aSetOptimalColumnWidthController
::sfx2::sidebar::ControllerItem m_aDistributeColumnsController
std::unique_ptr< ToolbarUnoDispatcher > m_xSplitMergeDispatch
#define SID_ATTR_TABLE_COLUMN_WIDTH
Definition: cmdid.h:463
#define FN_TABLE_BALANCE_ROWS
Definition: cmdid.h:451
#define FN_TABLE_ADJUST_CELLS
Definition: cmdid.h:399
#define FN_TABLE_BALANCE_CELLS
Definition: cmdid.h:450
#define FN_TABLE_INSERT_ROW_BEFORE
Definition: cmdid.h:390
#define FN_TABLE_DELETE_ROW
Definition: cmdid.h:382
#define SID_ATTR_TABLE_ROW_HEIGHT
Definition: cmdid.h:462
#define FN_TABLE_INSERT_COL_BEFORE
Definition: cmdid.h:391
#define FN_TABLE_DELETE_COL
Definition: cmdid.h:383
#define FN_TABLE_MERGE_CELLS
Definition: cmdid.h:385
#define FN_TABLE_INSERT_ROW_AFTER
Definition: cmdid.h:388
#define FN_TABLE_OPTIMAL_HEIGHT
Definition: cmdid.h:404
#define FN_TABLE_DELETE_TABLE
Definition: cmdid.h:405
#define FN_TABLE_INSERT_COL_AFTER
Definition: cmdid.h:395
void limitWidthForSidebar(weld::SpinButton &rSpinButton)
SVX_DLLPUBLIC void padWidthForSidebar(weld::Toolbar &rToolbar, const css::uno::Reference< css::frame::XFrame > &rFrame)
FieldUnit
IMPL_LINK_NOARG(AccessibilityCheckEntry, GotoButtonClicked, weld::LinkButton &, bool)
long Long
SfxItemState
#define SW_MOD()
Definition: swmodule.hxx:254
#define MINLAY
Definition: swtypes.hxx:62
tools::Long SwTwips
Definition: swtypes.hxx:51
#define SAL_MAX_INT32