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  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  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  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 }
138 
140 
142 {
143  Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, RowHeightMofiyHdl);
144  m_xRowHeightEdit->connect_value_changed(aLink);
145 
146  FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
147  m_xRowHeightEdit->SetFieldUnit(eFieldUnit);
148 
149  m_xRowHeightEdit->set_min(MINLAY, FieldUnit::TWIP);
150  m_xRowHeightEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
151 
153 }
154 
156 {
157  Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, ColumnWidthMofiyHdl);
158  m_xColumnWidthEdit->connect_value_changed(aLink);
159 
160  FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
161  m_xColumnWidthEdit->SetFieldUnit(eFieldUnit);
162 
163  m_xColumnWidthEdit->set_min(MINLAY, FieldUnit::TWIP);
164  m_xColumnWidthEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
165 
167 }
168 
170 {
171  m_xRowHeightEdit.reset();
172  m_xColumnWidthEdit.reset();
173 
174  m_xMiscDispatch.reset();
175  m_xMisc.reset();
176 
177  m_xSplitMergeDispatch.reset();
178  m_xSplitMerge.reset();
179 
180  m_xDeleteDispatch.reset();
181  m_xDelete.reset();
182 
183  m_xColumnSizingDispatch.reset();
184  m_xColumnSizing.reset();
185 
186  m_xRowSizingDispatch.reset();
187  m_xRowSizing.reset();
188 
189  m_xSelectDispatch.reset();
190  m_xSelect.reset();
191 
192  m_xInsertDispatch.reset();
193  m_xInsert.reset();
194 
211 
213 }
214 
216 {
217  SwTwips nNewHeight = static_cast<SwTwips>(
218  m_xRowHeightEdit->denormalize(m_xRowHeightEdit->get_value(FieldUnit::TWIP)));
220  aRowHeight.SetValue(nNewHeight);
221 
222  m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_ROW_HEIGHT, SfxCallMode::RECORD,
223  { &aRowHeight });
224 }
225 
227 {
228  SwTwips nNewWidth = static_cast<SwTwips>(
229  m_xColumnWidthEdit->denormalize(m_xColumnWidthEdit->get_value(FieldUnit::TWIP)));
231  aColumnWidth.SetValue(nNewWidth);
232 
233  m_pBindings->GetDispatcher()->ExecuteList(SID_ATTR_TABLE_COLUMN_WIDTH, SfxCallMode::RECORD,
234  { &aColumnWidth });
235 }
236 } // end of namespace ::sw::sidebar
237 
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FieldUnit
#define FN_TABLE_INSERT_COL_BEFORE
Definition: cmdid.h:355
std::unique_ptr< ToolbarUnoDispatcher > m_xRowSizingDispatch
#define FN_TABLE_OPTIMAL_HEIGHT
Definition: cmdid.h:368
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:429
::sfx2::sidebar::ControllerItem m_aColumnWidthController
#define FN_TABLE_DELETE_TABLE
Definition: cmdid.h:369
#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:359
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:349
#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:363
::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:347
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
::sfx2::sidebar::ControllerItem m_aDistributeRowsController
#define FN_TABLE_INSERT_ROW_AFTER
Definition: cmdid.h:352
virtual void dispose() override
#define FN_TABLE_BALANCE_CELLS
Definition: cmdid.h:416
SfxItemState
#define FN_TABLE_BALANCE_ROWS
Definition: cmdid.h:417
::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:428
void SetValue(sal_uInt32 nTheValue)
sal_uInt32 GetValue() const
#define FN_TABLE_INSERT_ROW_BEFORE
Definition: cmdid.h:354
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:346
::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