Resolves: tdf#125106 fix cell protect TriState toggles
Change-Id: I1f145558fe9d86682e03481fb2800386d04d2b1d
Reviewed-on: https://gerrit.libreoffice.org/71905
Tested-by: Xisco Faulí <xiscofauli@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sc/source/ui/attrdlg/tabpages.cxx b/sc/source/ui/attrdlg/tabpages.cxx
index 4e82125..6ce555b 100644
--- a/sc/source/ui/attrdlg/tabpages.cxx
+++ b/sc/source/ui/attrdlg/tabpages.cxx
@@ -49,10 +49,10 @@ ScTabPageProtection::ScTabPageProtection(TabPageParent pParent, const SfxItemSet
// States will be set in Reset
bTriEnabled = bDontCare = bProtect = bHideForm = bHideCell = bHidePrint = false;
m_xBtnProtect->connect_toggled(LINK(this, ScTabPageProtection, ButtonClickHdl));
m_xBtnHideCell->connect_toggled(LINK(this, ScTabPageProtection, ButtonClickHdl));
m_xBtnHideFormula->connect_toggled(LINK(this, ScTabPageProtection, ButtonClickHdl));
m_xBtnHidePrint->connect_toggled(LINK(this, ScTabPageProtection, ButtonClickHdl));
m_xBtnProtect->connect_toggled(LINK(this, ScTabPageProtection, ProtectClickHdl));
m_xBtnHideCell->connect_toggled(LINK(this, ScTabPageProtection, HideCellClickHdl));
m_xBtnHideFormula->connect_toggled(LINK(this, ScTabPageProtection, HideFormulaClickHdl));
m_xBtnHidePrint->connect_toggled(LINK(this, ScTabPageProtection, HidePrintClickHdl));
}
ScTabPageProtection::~ScTabPageProtection()
@@ -98,14 +98,10 @@ void ScTabPageProtection::Reset( const SfxItemSet* rCoreAttrs )
bHidePrint = pProtAttr->GetHidePrint();
}
// Start Controls
if (bTriEnabled)
{
m_xBtnProtect->set_state(TRISTATE_INDET);
m_xBtnHideCell->set_state(TRISTATE_INDET);
m_xBtnHideFormula->set_state(TRISTATE_INDET);
m_xBtnHidePrint->set_state(TRISTATE_INDET);
}
aHideCellState.bTriStateEnabled = bTriEnabled;
aProtectState.bTriStateEnabled = bTriEnabled;
aHideFormulaState.bTriStateEnabled = bTriEnabled;
aHidePrintState.bTriStateEnabled = bTriEnabled;
UpdateButtons();
}
@@ -148,7 +144,51 @@ DeactivateRC ScTabPageProtection::DeactivatePage( SfxItemSet* pSetP )
return DeactivateRC::LeavePage;
}
IMPL_LINK(ScTabPageProtection, ButtonClickHdl, weld::ToggleButton&, rBox, void)
void TriStateEnabled::ButtonToggled(weld::ToggleButton& rToggle)
{
if (bTriStateEnabled)
{
switch (eState)
{
case TRISTATE_INDET:
rToggle.set_state(TRISTATE_FALSE);
break;
case TRISTATE_TRUE:
rToggle.set_state(TRISTATE_INDET);
break;
case TRISTATE_FALSE:
rToggle.set_state(TRISTATE_TRUE);
break;
}
}
eState = rToggle.get_state();
}
IMPL_LINK(ScTabPageProtection, ProtectClickHdl, weld::ToggleButton&, rBox, void)
{
aProtectState.ButtonToggled(rBox);
ButtonClick(rBox);
}
IMPL_LINK(ScTabPageProtection, HideCellClickHdl, weld::ToggleButton&, rBox, void)
{
aHideCellState.ButtonToggled(rBox);
ButtonClick(rBox);
}
IMPL_LINK(ScTabPageProtection, HideFormulaClickHdl, weld::ToggleButton&, rBox, void)
{
aHideFormulaState.ButtonToggled(rBox);
ButtonClick(rBox);
}
IMPL_LINK(ScTabPageProtection, HidePrintClickHdl, weld::ToggleButton&, rBox, void)
{
aHidePrintState.ButtonToggled(rBox);
ButtonClick(rBox);
}
void ScTabPageProtection::ButtonClick(weld::ToggleButton& rBox)
{
TriState eState = rBox.get_state();
if (eState == TRISTATE_INDET)
@@ -192,6 +232,11 @@ void ScTabPageProtection::UpdateButtons()
m_xBtnHidePrint->set_state(bHidePrint ? TRISTATE_TRUE : TRISTATE_FALSE);
}
aHideCellState.eState = m_xBtnHideCell->get_state();
aProtectState.eState = m_xBtnProtect->get_state();
aHideFormulaState.eState = m_xBtnHideFormula->get_state();
aHidePrintState.eState = m_xBtnHidePrint->get_state();
bool bEnable = (m_xBtnHideCell->get_state() != TRISTATE_TRUE);
{
m_xBtnProtect->set_sensitive(bEnable);
diff --git a/sc/source/ui/inc/tabpages.hxx b/sc/source/ui/inc/tabpages.hxx
index 8abd667..5d195bb 100644
--- a/sc/source/ui/inc/tabpages.hxx
+++ b/sc/source/ui/inc/tabpages.hxx
@@ -22,6 +22,18 @@
#include <sfx2/tabdlg.hxx>
struct TriStateEnabled
{
TriState eState;
bool bTriStateEnabled;
TriStateEnabled()
: eState(TRISTATE_INDET)
, bTriStateEnabled(true)
{
}
void ButtonToggled(weld::ToggleButton& rToggle);
};
class ScTabPageProtection : public SfxTabPage
{
friend class VclPtr<ScTabPageProtection>;
@@ -50,14 +62,23 @@ private:
bool bHideCell;
bool bHidePrint;
TriStateEnabled aHideCellState;
TriStateEnabled aProtectState;
TriStateEnabled aHideFormulaState;
TriStateEnabled aHidePrintState;
std::unique_ptr<weld::CheckButton> m_xBtnHideCell;
std::unique_ptr<weld::CheckButton> m_xBtnProtect;
std::unique_ptr<weld::CheckButton> m_xBtnHideFormula;
std::unique_ptr<weld::CheckButton> m_xBtnHidePrint;
// Handler:
DECL_LINK(ButtonClickHdl, weld::ToggleButton&, void);
void UpdateButtons();
DECL_LINK(ProtectClickHdl, weld::ToggleButton&, void);
DECL_LINK(HideCellClickHdl, weld::ToggleButton&, void);
DECL_LINK(HideFormulaClickHdl, weld::ToggleButton&, void);
DECL_LINK(HidePrintClickHdl, weld::ToggleButton&, void);
void ButtonClick(weld::ToggleButton& rBox);
void UpdateButtons();
};
#endif // INCLUDED_SC_SOURCE_UI_INC_TABPAGES_HXX