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;
50 m_xRowHeightEdit->set_sensitive(!bDisabled);
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_xRowHeightEdit->normalize(nNewHeight);
59 m_xRowHeightEdit->set_value(nNewHeight, FieldUnit::TWIP);
60 }
61 }
62 else if (eState != SfxItemState::DISABLED)
63 m_xRowHeightEdit->set_text("");
64
65 break;
66 }
68 {
69 bool bDisabled = eState == SfxItemState::DISABLED;
70 m_xColumnWidthEdit->set_sensitive(!bDisabled);
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_xColumnWidthEdit->normalize(nNewWidth);
79 m_xColumnWidthEdit->set_value(nNewWidth, FieldUnit::TWIP);
80 }
81 }
82 else if (eState != SfxItemState::DISABLED)
83 m_xColumnWidthEdit->set_text("");
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_xRowHeightEdit(
96 new SvxRelativeField(m_xBuilder->weld_metric_spin_button("rowheight", FieldUnit::CM)))
97 , m_xColumnWidthEdit(
98 new SvxRelativeField(m_xBuilder->weld_metric_spin_button("columnwidth", FieldUnit::CM)))
99 , m_xInsert(m_xBuilder->weld_toolbar("insert"))
100 , m_xInsertDispatch(new ToolbarUnoDispatcher(*m_xInsert, *m_xBuilder, rxFrame))
101 , m_xSelect(m_xBuilder->weld_toolbar("select"))
102 , m_xSelectDispatch(new ToolbarUnoDispatcher(*m_xSelect, *m_xBuilder, rxFrame))
103 , m_xRowSizing(m_xBuilder->weld_toolbar("rowsizing"))
104 , m_xRowSizingDispatch(new ToolbarUnoDispatcher(*m_xRowSizing, *m_xBuilder, rxFrame))
105 , m_xColumnSizing(m_xBuilder->weld_toolbar("columnsizing"))
106 , m_xColumnSizingDispatch(new ToolbarUnoDispatcher(*m_xColumnSizing, *m_xBuilder, rxFrame))
107 , m_xDelete(m_xBuilder->weld_toolbar("delete"))
108 , m_xDeleteDispatch(new ToolbarUnoDispatcher(*m_xDelete, *m_xBuilder, rxFrame))
109 , m_xSplitMerge(m_xBuilder->weld_toolbar("split_merge"))
110 , m_xSplitMergeDispatch(new ToolbarUnoDispatcher(*m_xSplitMerge, *m_xBuilder, rxFrame))
111 , m_xMisc(m_xBuilder->weld_toolbar("misc"))
112 , m_xMiscDispatch(new ToolbarUnoDispatcher(*m_xMisc, *m_xBuilder, rxFrame))
113 , m_aRowHeightController(SID_ATTR_TABLE_ROW_HEIGHT, *pBindings, *this)
114 , m_aColumnWidthController(SID_ATTR_TABLE_COLUMN_WIDTH, *pBindings, *this)
115 , m_aInsertRowsBeforeController(FN_TABLE_INSERT_ROW_BEFORE, *pBindings, *this)
116 , m_aInsertRowsAfterController(FN_TABLE_INSERT_ROW_AFTER, *pBindings, *this)
117 , m_aInsertColumnsBeforeController(FN_TABLE_INSERT_COL_BEFORE, *pBindings, *this)
118 , m_aInsertColumnsAfterController(FN_TABLE_INSERT_COL_AFTER, *pBindings, *this)
119 , m_aDeleteRowsController(FN_TABLE_DELETE_ROW, *pBindings, *this)
120 , m_aDeleteColumnsController(FN_TABLE_DELETE_COL, *pBindings, *this)
121 , m_aDeleteTableController(FN_TABLE_DELETE_TABLE, *pBindings, *this)
122 , m_aSetMinimalRowHeightController(SID_TABLE_MINIMAL_ROW_HEIGHT, *pBindings, *this)
123 , m_aSetOptimalRowHeightController(FN_TABLE_OPTIMAL_HEIGHT, *pBindings, *this)
124 , m_aDistributeRowsController(FN_TABLE_BALANCE_ROWS, *pBindings, *this)
125 , m_aSetMinimalColumnWidthController(SID_TABLE_MINIMAL_COLUMN_WIDTH, *pBindings, *this)
126 , m_aSetOptimalColumnWidthController(FN_TABLE_ADJUST_CELLS, *pBindings, *this)
127 , m_aDistributeColumnsController(FN_TABLE_BALANCE_CELLS, *pBindings, *this)
128 , m_aMergeCellsController(FN_TABLE_MERGE_CELLS, *pBindings, *this)
129{
130 // tdf#130197 Give this toolbar a width as if it had 5 entries (the parent
131 // grid has homogeneous width set so both columns will have the same
132 // width). This will align this TableEditPanel's columns with
133 // ParaPropertyPanel's columns
135
138
140 m_xMisc->set_item_visible(".uno:InsertFormula", false);
141}
142
144{
145 Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, RowHeightMofiyHdl);
146 m_xRowHeightEdit->connect_value_changed(aLink);
147
148 FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
149 m_xRowHeightEdit->SetFieldUnit(eFieldUnit);
150
151 m_xRowHeightEdit->set_min(MINLAY, FieldUnit::TWIP);
152 m_xRowHeightEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
153
155}
156
158{
159 Link<weld::MetricSpinButton&, void> aLink = LINK(this, TableEditPanel, ColumnWidthMofiyHdl);
160 m_xColumnWidthEdit->connect_value_changed(aLink);
161
162 FieldUnit eFieldUnit = SW_MOD()->GetUsrPref(false)->GetMetric();
163 m_xColumnWidthEdit->SetFieldUnit(eFieldUnit);
164
165 m_xColumnWidthEdit->set_min(MINLAY, FieldUnit::TWIP);
166 m_xColumnWidthEdit->set_max(SAL_MAX_INT32, FieldUnit::TWIP);
167
169}
170
172{
173 m_xRowHeightEdit.reset();
174 m_xColumnWidthEdit.reset();
175
176 m_xMiscDispatch.reset();
177 m_xMisc.reset();
178
179 m_xSplitMergeDispatch.reset();
180 m_xSplitMerge.reset();
181
182 m_xDeleteDispatch.reset();
183 m_xDelete.reset();
184
186 m_xColumnSizing.reset();
187
188 m_xRowSizingDispatch.reset();
189 m_xRowSizing.reset();
190
191 m_xSelectDispatch.reset();
192 m_xSelect.reset();
193
194 m_xInsertDispatch.reset();
195 m_xInsert.reset();
196
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: */
void SetValue(sal_uInt32 nTheValue)
sal_uInt32 GetValue() const
virtual void dispose()
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
std::unique_ptr< SvxRelativeField > m_xColumnWidthEdit
::sfx2::sidebar::ControllerItem m_aInsertColumnsBeforeController
std::unique_ptr< ToolbarUnoDispatcher > m_xSelectDispatch
virtual ~TableEditPanel() override
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)
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
std::unique_ptr< SvxRelativeField > m_xRowHeightEdit
::sfx2::sidebar::ControllerItem m_aDistributeColumnsController
std::unique_ptr< ToolbarUnoDispatcher > m_xSplitMergeDispatch
#define SID_ATTR_TABLE_COLUMN_WIDTH
Definition: cmdid.h:444
#define FN_TABLE_BALANCE_ROWS
Definition: cmdid.h:432
#define FN_TABLE_ADJUST_CELLS
Definition: cmdid.h:380
#define FN_TABLE_BALANCE_CELLS
Definition: cmdid.h:431
#define FN_TABLE_INSERT_ROW_BEFORE
Definition: cmdid.h:371
#define FN_TABLE_DELETE_ROW
Definition: cmdid.h:363
#define SID_ATTR_TABLE_ROW_HEIGHT
Definition: cmdid.h:443
#define FN_TABLE_INSERT_COL_BEFORE
Definition: cmdid.h:372
#define FN_TABLE_DELETE_COL
Definition: cmdid.h:364
#define FN_TABLE_MERGE_CELLS
Definition: cmdid.h:366
#define FN_TABLE_INSERT_ROW_AFTER
Definition: cmdid.h:369
#define FN_TABLE_OPTIMAL_HEIGHT
Definition: cmdid.h:385
#define FN_TABLE_DELETE_TABLE
Definition: cmdid.h:386
#define FN_TABLE_INSERT_COL_AFTER
Definition: cmdid.h:376
void limitWidthForSidebar(weld::SpinButton &rSpinButton)
SVX_DLLPUBLIC void padWidthForSidebar(weld::Toolbar &rToolbar, const css::uno::Reference< css::frame::XFrame > &rFrame)
FieldUnit
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
long Long
SfxItemState
#define SW_MOD()
Definition: swmodule.hxx:256
#define MINLAY
Definition: swtypes.hxx:62
tools::Long SwTwips
Definition: swtypes.hxx:51
#define SAL_MAX_INT32