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 <svtools/unitconv.hxx>
19 #include <svx/dlgctrl.hxx>
20 #include <swmodule.hxx>
21 #include <usrpref.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  if (pState && eState >= SfxItemState::DEFAULT)
49  {
50  const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState);
51  if (pItem)
52  {
53  long nNewHeight = pItem->GetValue();
54  nNewHeight = m_xRowHeightEdit->normalize(nNewHeight);
55  m_xRowHeightEdit->set_value(nNewHeight, FieldUnit::TWIP);
56  }
57  }
58  else if (eState == SfxItemState::DISABLED)
59  {
60  m_xRowHeightEdit->set_sensitive(false);
61  }
62  else
63  {
64  m_xRowHeightEdit->set_text("");
65  }
66  break;
67  }
69  {
70  if (pState && eState >= SfxItemState::DEFAULT)
71  {
72  const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pState);
73  if (pItem)
74  {
75  long nNewWidth = pItem->GetValue();
76  nNewWidth = m_xColumnWidthEdit->normalize(nNewWidth);
77  m_xColumnWidthEdit->set_value(nNewWidth, FieldUnit::TWIP);
78  }
79  }
80  else if (eState == SfxItemState::DISABLED)
81  {
82  m_xColumnWidthEdit->set_sensitive(false);
83  }
84  else
85  {
86  m_xColumnWidthEdit->set_text("");
87  }
88  break;
89  }
90  }
91 }
92 
94  const css::uno::Reference<css::frame::XFrame>& rxFrame,
95  SfxBindings* pBindings)
96  : PanelLayout(pParent, "TableEditPanel", "modules/swriter/ui/sidebartableedit.ui", rxFrame)
97  , m_pBindings(pBindings)
98  , m_xRowHeightEdit(
99  new SvxRelativeField(m_xBuilder->weld_metric_spin_button("rowheight", FieldUnit::CM)))
100  , m_xColumnWidthEdit(
101  new SvxRelativeField(m_xBuilder->weld_metric_spin_button("columnwidth", FieldUnit::CM)))
102  , m_xInsert(m_xBuilder->weld_toolbar("insert"))
103  , m_xInsertDispatch(new ToolbarUnoDispatcher(*m_xInsert, *m_xBuilder, rxFrame))
104  , m_xSelect(m_xBuilder->weld_toolbar("select"))
105  , m_xSelectDispatch(new ToolbarUnoDispatcher(*m_xSelect, *m_xBuilder, rxFrame))
106  , m_xRowSizing(m_xBuilder->weld_toolbar("rowsizing"))
107  , m_xRowSizingDispatch(new ToolbarUnoDispatcher(*m_xRowSizing, *m_xBuilder, rxFrame))
108  , m_xColumnSizing(m_xBuilder->weld_toolbar("columnsizing"))
109  , m_xColumnSizingDispatch(new ToolbarUnoDispatcher(*m_xColumnSizing, *m_xBuilder, rxFrame))
110  , m_xDelete(m_xBuilder->weld_toolbar("delete"))
111  , m_xDeleteDispatch(new ToolbarUnoDispatcher(*m_xDelete, *m_xBuilder, rxFrame))
112  , m_xSplitMerge(m_xBuilder->weld_toolbar("split_merge"))
113  , m_xSplitMergeDispatch(new ToolbarUnoDispatcher(*m_xSplitMerge, *m_xBuilder, rxFrame))
114  , m_xMisc(m_xBuilder->weld_toolbar("misc"))
115  , m_xMiscDispatch(new ToolbarUnoDispatcher(*m_xMisc, *m_xBuilder, rxFrame))
116  , m_aRowHeightController(SID_ATTR_TABLE_ROW_HEIGHT, *pBindings, *this)
117  , m_aColumnWidthController(SID_ATTR_TABLE_COLUMN_WIDTH, *pBindings, *this)
118  , m_aInsertRowsBeforeController(FN_TABLE_INSERT_ROW_BEFORE, *pBindings, *this)
119  , m_aInsertRowsAfterController(FN_TABLE_INSERT_ROW_AFTER, *pBindings, *this)
120  , m_aInsertColumnsBeforeController(FN_TABLE_INSERT_COL_BEFORE, *pBindings, *this)
121  , m_aInsertColumnsAfterController(FN_TABLE_INSERT_COL_AFTER, *pBindings, *this)
122  , m_aDeleteRowsController(FN_TABLE_DELETE_ROW, *pBindings, *this)
123  , m_aDeleteColumnsController(FN_TABLE_DELETE_COL, *pBindings, *this)
124  , m_aDeleteTableController(FN_TABLE_DELETE_TABLE, *pBindings, *this)
125  , m_aSetMinimalRowHeightController(SID_TABLE_MINIMAL_ROW_HEIGHT, *pBindings, *this)
126  , m_aSetOptimalRowHeightController(FN_TABLE_OPTIMAL_HEIGHT, *pBindings, *this)
127  , m_aDistributeRowsController(FN_TABLE_BALANCE_ROWS, *pBindings, *this)
128  , m_aSetMinimalColumnWidthController(SID_TABLE_MINIMAL_COLUMN_WIDTH, *pBindings, *this)
129  , m_aSetOptimalColumnWidthController(FN_TABLE_ADJUST_CELLS, *pBindings, *this)
130  , m_aDistributeColumnsController(FN_TABLE_BALANCE_CELLS, *pBindings, *this)
131  , m_aMergeCellsController(FN_TABLE_MERGE_CELLS, *pBindings, *this)
132 {
133  // tdf#130197 Give this toolbar a width as if it had 5 entries (the parent
134  // grid has homogeneous width set so both columns will have the same
135  // width). This will align this TableEditPanel's columns with
136  // ParaPropertyPanel's columns
138 
141 }
142 
144 
146 {
147  Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, RowHeightMofiyHdl);
148  m_xRowHeightEdit->connect_value_changed(aLink);
149 
150  FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
151  m_xRowHeightEdit->SetFieldUnit(eFieldUnit);
152 
153  m_xRowHeightEdit->set_min(MINLAY, FieldUnit::TWIP);
154  m_xRowHeightEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
155 
157 }
158 
160 {
161  Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, ColumnWidthMofiyHdl);
162  m_xColumnWidthEdit->connect_value_changed(aLink);
163 
164  FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
165  m_xColumnWidthEdit->SetFieldUnit(eFieldUnit);
166 
167  m_xColumnWidthEdit->set_min(MINLAY, FieldUnit::TWIP);
168  m_xColumnWidthEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
169 
171 }
172 
174 {
175  m_xRowHeightEdit.reset();
176  m_xColumnWidthEdit.reset();
177 
178  m_xMiscDispatch.reset();
179  m_xMisc.reset();
180 
181  m_xSplitMergeDispatch.reset();
182  m_xSplitMerge.reset();
183 
184  m_xDeleteDispatch.reset();
185  m_xDelete.reset();
186 
187  m_xColumnSizingDispatch.reset();
188  m_xColumnSizing.reset();
189 
190  m_xRowSizingDispatch.reset();
191  m_xRowSizing.reset();
192 
193  m_xSelectDispatch.reset();
194  m_xSelect.reset();
195 
196  m_xInsertDispatch.reset();
197  m_xInsert.reset();
198 
215 
217 }
218 
220 {
221  SwTwips nNewHeight = static_cast<SwTwips>(
222  m_xRowHeightEdit->denormalize(m_xRowHeightEdit->get_value(FieldUnit::TWIP)));
224  aRowHeight.SetValue(nNewHeight);
225 
226  m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_ROW_HEIGHT, SfxCallMode::RECORD,
227  { &aRowHeight });
228 }
229 
231 {
232  SwTwips nNewWidth = static_cast<SwTwips>(
233  m_xColumnWidthEdit->denormalize(m_xColumnWidthEdit->get_value(FieldUnit::TWIP)));
235  aColumnWidth.SetValue(nNewWidth);
236 
237  m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_COLUMN_WIDTH, SfxCallMode::RECORD,
238  { &aColumnWidth });
239 }
240 } // end of namespace ::sw::sidebar
241 
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FieldUnit
#define FN_TABLE_INSERT_COL_BEFORE
Definition: cmdid.h:353
std::unique_ptr< ToolbarUnoDispatcher > m_xRowSizingDispatch
#define FN_TABLE_OPTIMAL_HEIGHT
Definition: cmdid.h:366
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:427
::sfx2::sidebar::ControllerItem m_aColumnWidthController
#define FN_TABLE_DELETE_TABLE
Definition: cmdid.h:367
#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:357
long SwTwips
Definition: swtypes.hxx:49
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:347
#define SW_MOD()
Definition: swmodule.hxx:256
#define SAL_MAX_INT32
virtual void dispose()
std::unique_ptr< weld::Toolbar > m_xDelete
#define FN_TABLE_ADJUST_CELLS
Definition: cmdid.h:361
::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:345
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
::sfx2::sidebar::ControllerItem m_aDistributeRowsController
#define FN_TABLE_INSERT_ROW_AFTER
Definition: cmdid.h:350
virtual void dispose() override
#define FN_TABLE_BALANCE_CELLS
Definition: cmdid.h:414
SfxItemState
#define FN_TABLE_BALANCE_ROWS
Definition: cmdid.h:415
::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:426
void SetValue(sal_uInt32 nTheValue)
sal_uInt32 GetValue() const
#define FN_TABLE_INSERT_ROW_BEFORE
Definition: cmdid.h:352
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:344
::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