tdf#134779 Warning generated if the table size exceeds a particular limit
Change-Id: I2ee23c7b3f5638b48323a76535e7a3b5141d1ad0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105501
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/sw/source/ui/table/instable.cxx b/sw/source/ui/table/instable.cxx
index 3ca34f3..b700b85 100644
--- a/sw/source/ui/table/instable.cxx
+++ b/sw/source/ui/table/instable.cxx
@@ -25,7 +25,6 @@
#include <viewopt.hxx>
#include <comphelper/lok.hxx>
#define ROW_COL_PROD 16384
void SwInsTableDlg::GetValues( OUString& rName, sal_uInt16& rRow, sal_uInt16& rCol,
SwInsertTableOptions& rInsTableOpts, OUString& rAutoName,
@@ -33,8 +32,8 @@ void SwInsTableDlg::GetValues( OUString& rName, sal_uInt16& rRow, sal_uInt16& rC
{
SwInsertTableFlags nInsMode = SwInsertTableFlags::NONE;
rName = m_xNameEdit->get_text();
rRow = m_xRowNF->get_value();
rCol = m_xColNF->get_value();
rRow = m_xRowSpinButton->get_value();
rCol = m_xColSpinButton->get_value();
if (m_xHeaderCB->get_active())
nInsMode |= SwInsertTableFlags::Headline;
@@ -66,8 +65,9 @@ SwInsTableDlg::SwInsTableDlg(SwView& rView)
, pTAutoFormat(nullptr)
, nEnteredValRepeatHeaderNF(-1)
, m_xNameEdit(m_xBuilder->weld_entry("nameedit"))
, m_xColNF(m_xBuilder->weld_spin_button("colspin"))
, m_xRowNF(m_xBuilder->weld_spin_button("rowspin"))
, m_xWarning(m_xBuilder->weld_label("lbwarning"))
, m_xColSpinButton(m_xBuilder->weld_spin_button("colspin"))
, m_xRowSpinButton(m_xBuilder->weld_spin_button("rowspin"))
, m_xHeaderCB(m_xBuilder->weld_check_button("headercb"))
, m_xRepeatHeaderCB(m_xBuilder->weld_check_button("repeatcb"))
, m_xRepeatHeaderNF(m_xBuilder->weld_spin_button("repeatheaderspin"))
@@ -89,11 +89,8 @@ SwInsTableDlg::SwInsTableDlg(SwView& rView)
m_xNameEdit->connect_insert_text(LINK(this, SwInsTableDlg, TextFilterHdl));
m_xNameEdit->set_text(pShell->GetUniqueTableName());
m_xNameEdit->connect_changed(LINK(this, SwInsTableDlg, ModifyName));
m_xColNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
m_xRowNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
m_xRowNF->set_max(ROW_COL_PROD/m_xColNF->get_value());
m_xColNF->set_max(ROW_COL_PROD/m_xRowNF->get_value());
m_xRowSpinButton->connect_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
m_xColSpinButton->connect_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
m_xInsertBtn->connect_clicked(LINK(this, SwInsTableDlg, OKHdl));
@@ -116,7 +113,7 @@ SwInsTableDlg::SwInsTableDlg(SwView& rView)
RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
CheckBoxHdl(*m_xHeaderCB);
sal_Int64 nMax = m_xRowNF->get_value();
sal_Int64 nMax = m_xRowSpinButton->get_value();
if( nMax <= 1 )
nMax = 1;
else
@@ -124,6 +121,7 @@ SwInsTableDlg::SwInsTableDlg(SwView& rView)
m_xRepeatHeaderNF->set_max( nMax );
InitAutoTableFormat();
m_xWarning->set_label_type(weld::LabelType::Warning);
}
void SwInsTableDlg::InitAutoTableFormat()
@@ -227,21 +225,44 @@ IMPL_LINK( SwInsTableDlg, ModifyName, weld::Entry&, rEdit, void )
m_xInsertBtn->set_sensitive(pShell->GetTableStyle(sTableName) == nullptr);
}
IMPL_LINK( SwInsTableDlg, ModifyRowCol, weld::SpinButton&, rEdit, void )
// We use weld::Entry's "changed" notification here, not weld::SpinButton's "value_changed", because
// the latter only fires after the control looses focus; so the notification would not fire during
// typing a big number, so that user typing it and immediately clicking "Insert" would not see the
// warning.
// Since the notification is called in weld::Entry context, we can only rely on what's available for
// used weld::Entry's notification; specifically, we have to call spin buttons' get_text() instead
// of get_value(), because the latter is not guaranteed to return an up-to-date value at this point
// (depends on vcl plugin used).
IMPL_LINK( SwInsTableDlg, ModifyRowCol, weld::Entry&, rEdit, void )
{
if(&rEdit == m_xColNF.get())
sal_Int64 nRow = m_xRowSpinButton->get_text().toInt64();
sal_Int64 nCol = m_xColSpinButton->get_text().toInt64();
if (nRow > 255)
{
sal_Int64 nCol = m_xColNF->get_value();
if(!nCol)
nCol = 1;
m_xRowNF->set_max(ROW_COL_PROD/nCol);
m_xRowSpinButton->set_message_type(weld::EntryMessageType::Warning);
m_xWarning->set_visible(true);
}
else
{
sal_Int64 nRow = m_xRowNF->get_value();
m_xRowSpinButton->set_message_type(weld::EntryMessageType::Normal);
}
if (nCol > 63)
{
m_xColSpinButton->set_message_type(weld::EntryMessageType::Warning);
m_xWarning->set_visible(true);
}
else
{
m_xColSpinButton->set_message_type(weld::EntryMessageType::Normal);
}
if (nRow <= 255 && nCol <= 63)
{
m_xWarning->set_visible(false);
}
if (&rEdit != m_xColSpinButton.get())
{
if(!nRow)
nRow = 1;
m_xColNF->set_max(ROW_COL_PROD/nRow);
// adjust depending NF for repeated rows
sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
diff --git a/sw/source/uibase/inc/instable.hxx b/sw/source/uibase/inc/instable.hxx
index 05c02af..3070dcc 100644
--- a/sw/source/uibase/inc/instable.hxx
+++ b/sw/source/uibase/inc/instable.hxx
@@ -48,8 +48,9 @@ class SwInsTableDlg : public SfxDialogController
AutoFormatPreview m_aWndPreview;
std::unique_ptr<weld::Entry> m_xNameEdit;
std::unique_ptr<weld::SpinButton> m_xColNF;
std::unique_ptr<weld::SpinButton> m_xRowNF;
std::unique_ptr<weld::Label> m_xWarning;
std::unique_ptr<weld::SpinButton> m_xColSpinButton;
std::unique_ptr<weld::SpinButton> m_xRowSpinButton;
std::unique_ptr<weld::CheckButton> m_xHeaderCB;
std::unique_ptr<weld::CheckButton> m_xRepeatHeaderCB;
std::unique_ptr<weld::SpinButton> m_xRepeatHeaderNF;
@@ -68,7 +69,7 @@ class SwInsTableDlg : public SfxDialogController
DECL_LINK(TextFilterHdl, OUString&, bool);
DECL_LINK(SelFormatHdl, weld::TreeView&, void);
DECL_LINK(ModifyName, weld::Entry&, void);
DECL_LINK(ModifyRowCol, weld::SpinButton&, void);
DECL_LINK(ModifyRowCol, weld::Entry&, void);
DECL_LINK(OKHdl, weld::Button&, void);
DECL_LINK(CheckBoxHdl, weld::ToggleButton&, void);
DECL_LINK(RepeatHeaderCheckBoxHdl, weld::ToggleButton&, void);
diff --git a/sw/uiconfig/swriter/ui/inserttable.ui b/sw/uiconfig/swriter/ui/inserttable.ui
index d59e475..3e5bd06 100644
--- a/sw/uiconfig/swriter/ui/inserttable.ui
+++ b/sw/uiconfig/swriter/ui/inserttable.ui
@@ -4,14 +4,14 @@
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="lower">1</property>
<property name="upper">99</property>
<property name="upper">2000000</property>
<property name="value">2</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="lower">1</property>
<property name="upper">99</property>
<property name="upper">2000000</property>
<property name="value">2</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
@@ -238,7 +238,18 @@
<property name="left_attach">3</property>
<property name="top_attach">1</property>
</packing>
</child>
</child>
<child>
<object class="GtkLabel" id="lbwarning">
<property name="can_focus">False</property>
<property name="label" translatable="yes" context="inserttable|lbwarning">Warning : Large tables may adversely affect performance and compatibility</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="width">4</property>
</packing>
</child>
</object>
</child>
</object>