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 
25 namespace sw::sidebar
26 {
28  const css::uno::Reference<css::frame::XFrame>& rxFrame,
29  SfxBindings* pBindings)
30 {
31  if (pParent == nullptr)
32  throw css::lang::IllegalArgumentException(
33  "no parent Window given to TableEditPanel::Create", nullptr, 0);
34  if (!rxFrame.is())
35  throw css::lang::IllegalArgumentException("no XFrame given to TableEditPanel::Create",
36  nullptr, 1);
37 
38  return VclPtr<TableEditPanel>::Create(pParent, rxFrame, pBindings);
39 }
40 
41 void TableEditPanel::NotifyItemUpdate(const sal_uInt16 nSID, const SfxItemState eState,
42  const SfxPoolItem* pState)
43 {
44  switch (nSID)
45  {
47  {
48  bool bDisabled = eState == SfxItemState::DISABLED;
49  m_xRowHeightEdit->set_sensitive(!bDisabled);
50 
51  if (pState && eState >= SfxItemState::DEFAULT)
52  {
53  const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState);
54  if (pItem)
55  {
56  tools::Long nNewHeight = pItem->GetValue();
57  nNewHeight = m_xRowHeightEdit->normalize(nNewHeight);
58  m_xRowHeightEdit->set_value(nNewHeight, FieldUnit::TWIP);
59  }
60  }
61  else if (eState != SfxItemState::DISABLED)
62  m_xRowHeightEdit->set_text("");
63 
64  break;
65  }
67  {
68  bool bDisabled = eState == SfxItemState::DISABLED;
69  m_xColumnWidthEdit->set_sensitive(!bDisabled);
70 
71  if (pState && eState >= SfxItemState::DEFAULT)
72  {
73  const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState);
74  if (pItem)
75  {
76  tools::Long nNewWidth = pItem->GetValue();
77  nNewWidth = m_xColumnWidthEdit->normalize(nNewWidth);
78  m_xColumnWidthEdit->set_value(nNewWidth, FieldUnit::TWIP);
79  }
80  }
81  else if (eState != SfxItemState::DISABLED)
82  m_xColumnWidthEdit->set_text("");
83 
84  break;
85  }
86  }
87 }
88 
90  const css::uno::Reference<css::frame::XFrame>& rxFrame,
91  SfxBindings* pBindings)
92  : PanelLayout(pParent, "TableEditPanel", "modules/swriter/ui/sidebartableedit.ui", rxFrame)
93  , m_pBindings(pBindings)
94  , m_xRowHeightEdit(
95  new SvxRelativeField(m_xBuilder->weld_metric_spin_button("rowheight", FieldUnit::CM)))
96  , m_xColumnWidthEdit(
97  new SvxRelativeField(m_xBuilder->weld_metric_spin_button("columnwidth", FieldUnit::CM)))
98  , m_xInsert(m_xBuilder->weld_toolbar("insert"))
99  , m_xInsertDispatch(new ToolbarUnoDispatcher(*m_xInsert, *m_xBuilder, rxFrame))
100  , m_xSelect(m_xBuilder->weld_toolbar("select"))
101  , m_xSelectDispatch(new ToolbarUnoDispatcher(*m_xSelect, *m_xBuilder, rxFrame))
102  , m_xRowSizing(m_xBuilder->weld_toolbar("rowsizing"))
103  , m_xRowSizingDispatch(new ToolbarUnoDispatcher(*m_xRowSizing, *m_xBuilder, rxFrame))
104  , m_xColumnSizing(m_xBuilder->weld_toolbar("columnsizing"))
105  , m_xColumnSizingDispatch(new ToolbarUnoDispatcher(*m_xColumnSizing, *m_xBuilder, rxFrame))
106  , m_xDelete(m_xBuilder->weld_toolbar("delete"))
107  , m_xDeleteDispatch(new ToolbarUnoDispatcher(*m_xDelete, *m_xBuilder, rxFrame))
108  , m_xSplitMerge(m_xBuilder->weld_toolbar("split_merge"))
109  , m_xSplitMergeDispatch(new ToolbarUnoDispatcher(*m_xSplitMerge, *m_xBuilder, rxFrame))
110  , m_xMisc(m_xBuilder->weld_toolbar("misc"))
111  , m_xMiscDispatch(new ToolbarUnoDispatcher(*m_xMisc, *m_xBuilder, rxFrame))
112  , m_aRowHeightController(SID_ATTR_TABLE_ROW_HEIGHT, *pBindings, *this)
113  , m_aColumnWidthController(SID_ATTR_TABLE_COLUMN_WIDTH, *pBindings, *this)
114  , m_aInsertRowsBeforeController(FN_TABLE_INSERT_ROW_BEFORE, *pBindings, *this)
115  , m_aInsertRowsAfterController(FN_TABLE_INSERT_ROW_AFTER, *pBindings, *this)
116  , m_aInsertColumnsBeforeController(FN_TABLE_INSERT_COL_BEFORE, *pBindings, *this)
117  , m_aInsertColumnsAfterController(FN_TABLE_INSERT_COL_AFTER, *pBindings, *this)
118  , m_aDeleteRowsController(FN_TABLE_DELETE_ROW, *pBindings, *this)
119  , m_aDeleteColumnsController(FN_TABLE_DELETE_COL, *pBindings, *this)
120  , m_aDeleteTableController(FN_TABLE_DELETE_TABLE, *pBindings, *this)
121  , m_aSetMinimalRowHeightController(SID_TABLE_MINIMAL_ROW_HEIGHT, *pBindings, *this)
122  , m_aSetOptimalRowHeightController(FN_TABLE_OPTIMAL_HEIGHT, *pBindings, *this)
123  , m_aDistributeRowsController(FN_TABLE_BALANCE_ROWS, *pBindings, *this)
124  , m_aSetMinimalColumnWidthController(SID_TABLE_MINIMAL_COLUMN_WIDTH, *pBindings, *this)
125  , m_aSetOptimalColumnWidthController(FN_TABLE_ADJUST_CELLS, *pBindings, *this)
126  , m_aDistributeColumnsController(FN_TABLE_BALANCE_CELLS, *pBindings, *this)
127  , m_aMergeCellsController(FN_TABLE_MERGE_CELLS, *pBindings, *this)
128 {
129  // tdf#130197 Give this toolbar a width as if it had 5 entries (the parent
130  // grid has homogeneous width set so both columns will have the same
131  // width). This will align this TableEditPanel's columns with
132  // ParaPropertyPanel's columns
134 
137 
139  m_xMisc->set_item_visible(".uno:InsertFormula", false);
140 }
141 
143 
145 {
146  Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, RowHeightMofiyHdl);
147  m_xRowHeightEdit->connect_value_changed(aLink);
148 
149  FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
150  m_xRowHeightEdit->SetFieldUnit(eFieldUnit);
151 
152  m_xRowHeightEdit->set_min(MINLAY, FieldUnit::TWIP);
153  m_xRowHeightEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
154 
156 }
157 
159 {
160  Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, ColumnWidthMofiyHdl);
161  m_xColumnWidthEdit->connect_value_changed(aLink);
162 
163  FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
164  m_xColumnWidthEdit->SetFieldUnit(eFieldUnit);
165 
166  m_xColumnWidthEdit->set_min(MINLAY, FieldUnit::TWIP);
167  m_xColumnWidthEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
168 
170 }
171 
173 {
174  m_xRowHeightEdit.reset();
175  m_xColumnWidthEdit.reset();
176 
177  m_xMiscDispatch.reset();
178  m_xMisc.reset();
179 
180  m_xSplitMergeDispatch.reset();
181  m_xSplitMerge.reset();
182 
183  m_xDeleteDispatch.reset();
184  m_xDelete.reset();
185 
186  m_xColumnSizingDispatch.reset();
187  m_xColumnSizing.reset();
188 
189  m_xRowSizingDispatch.reset();
190  m_xRowSizing.reset();
191 
192  m_xSelectDispatch.reset();
193  m_xSelect.reset();
194 
195  m_xInsertDispatch.reset();
196  m_xInsert.reset();
197 
214 
216 }
217 
219 {
220  SwTwips nNewHeight = static_cast<SwTwips>(
221  m_xRowHeightEdit->denormalize(m_xRowHeightEdit->get_value(FieldUnit::TWIP)));
223  aRowHeight.SetValue(nNewHeight);
224 
225  m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_ROW_HEIGHT, SfxCallMode::RECORD,
226  { &aRowHeight });
227 }
228 
230 {
231  SwTwips nNewWidth = static_cast<SwTwips>(
232  m_xColumnWidthEdit->denormalize(m_xColumnWidthEdit->get_value(FieldUnit::TWIP)));
234  aColumnWidth.SetValue(nNewWidth);
235 
236  m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_COLUMN_WIDTH, SfxCallMode::RECORD,
237  { &aColumnWidth });
238 }
239 } // end of namespace ::sw::sidebar
240 
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FieldUnit
#define FN_TABLE_INSERT_COL_BEFORE
Definition: cmdid.h:358
std::unique_ptr< ToolbarUnoDispatcher > m_xRowSizingDispatch
#define FN_TABLE_OPTIMAL_HEIGHT
Definition: cmdid.h:371
void padWidthForSidebar(weld::Toolbar &rToolbar, const css::uno::Reference< css::frame::XFrame > &rFrame)
void limitWidthForSidebar(weld::SpinButton &rSpinButton)
::sfx2::sidebar::ControllerItem m_aDeleteTableController
::sfx2::sidebar::ControllerItem m_aDeleteRowsController
std::unique_ptr< ToolbarUnoDispatcher > m_xColumnSizingDispatch
#define SID_ATTR_TABLE_COLUMN_WIDTH
Definition: cmdid.h:432
::sfx2::sidebar::ControllerItem m_aColumnWidthController
#define FN_TABLE_DELETE_TABLE
Definition: cmdid.h:372
long Long
#define MINLAY
Definition: swtypes.hxx:66
std::unique_ptr< weld::Toolbar > m_xMisc
std::unique_ptr< ToolbarUnoDispatcher > m_xSelectDispatch
#define FN_TABLE_INSERT_COL_AFTER
Definition: cmdid.h:362
std::unique_ptr< weld::Toolbar > m_xColumnSizing
std::unique_ptr< weld::Toolbar > m_xInsert
::sfx2::sidebar::ControllerItem m_aInsertColumnsBeforeController
virtual void dispose() override
std::unique_ptr< ToolbarUnoDispatcher > m_xSplitMergeDispatch
std::unique_ptr< weld::Toolbar > m_xRowSizing
::sfx2::sidebar::ControllerItem m_aInsertRowsBeforeController
virtual ~TableEditPanel() override
#define FN_TABLE_MERGE_CELLS
Definition: cmdid.h:352
#define SW_MOD()
Definition: swmodule.hxx:255
#define SAL_MAX_INT32
virtual void dispose()
std::unique_ptr< weld::Toolbar > m_xDelete
#define FN_TABLE_ADJUST_CELLS
Definition: cmdid.h:366
::sfx2::sidebar::ControllerItem m_aSetMinimalColumnWidthController
::sfx2::sidebar::ControllerItem m_aSetMinimalRowHeightController
::sfx2::sidebar::ControllerItem m_aSetOptimalColumnWidthController
std::unique_ptr< ToolbarUnoDispatcher > m_xInsertDispatch
#define FN_TABLE_DELETE_COL
Definition: cmdid.h:350
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
tools::Long SwTwips
Definition: swtypes.hxx:49
::sfx2::sidebar::ControllerItem m_aDistributeRowsController
#define FN_TABLE_INSERT_ROW_AFTER
Definition: cmdid.h:355
virtual void dispose() override
#define FN_TABLE_BALANCE_CELLS
Definition: cmdid.h:419
SfxItemState
#define FN_TABLE_BALANCE_ROWS
Definition: cmdid.h:420
::sfx2::sidebar::ControllerItem m_aSetOptimalRowHeightController
::sfx2::sidebar::ControllerItem m_aDeleteColumnsController
::sfx2::sidebar::ControllerItem m_aInsertColumnsAfterController
static VclPtr< reference_type > Create(Arg &&...arg)
::sfx2::sidebar::ControllerItem m_aDistributeColumnsController
::sfx2::sidebar::ControllerItem m_aInsertRowsAfterController
std::unique_ptr< ToolbarUnoDispatcher > m_xMiscDispatch
std::unique_ptr< weld::Toolbar > m_xSplitMerge
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
std::unique_ptr< SvxRelativeField > m_xRowHeightEdit
#define SID_ATTR_TABLE_ROW_HEIGHT
Definition: cmdid.h:431
void SetValue(sal_uInt32 nTheValue)
sal_uInt32 GetValue() const
#define FN_TABLE_INSERT_ROW_BEFORE
Definition: cmdid.h:357
std::unique_ptr< ToolbarUnoDispatcher > m_xDeleteDispatch
static VclPtr< vcl::Window > Create(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
#define FN_TABLE_DELETE_ROW
Definition: cmdid.h:349
::sfx2::sidebar::ControllerItem m_aRowHeightController
TableEditPanel(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
std::unique_ptr< weld::Toolbar > m_xSelect
std::unique_ptr< SvxRelativeField > m_xColumnWidthEdit
::sfx2::sidebar::ControllerItem m_aMergeCellsController