Kaydet (Commit) 65d4676e authored tarafından Caolán McNamara's avatar Caolán McNamara

weld ScTableProtectionDlg

Change-Id: Icbf9e3b679b58d2781a52a0f55b16511eed14485
Reviewed-on: https://gerrit.libreoffice.org/67279
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst b8ac898e
...@@ -20,23 +20,18 @@ ...@@ -20,23 +20,18 @@
#ifndef INCLUDED_SC_SOURCE_UI_INC_PROTECTIONDLG_HXX #ifndef INCLUDED_SC_SOURCE_UI_INC_PROTECTIONDLG_HXX
#define INCLUDED_SC_SOURCE_UI_INC_PROTECTIONDLG_HXX #define INCLUDED_SC_SOURCE_UI_INC_PROTECTIONDLG_HXX
#include <vcl/dialog.hxx> #include <vcl/weld.hxx>
#include <vcl/button.hxx>
#include <vcl/layout.hxx>
#include <svx/checklbx.hxx>
#include <scdllapi.h> #include <scdllapi.h>
namespace vcl { class Window; } namespace vcl { class Window; }
class ScTableProtection; class ScTableProtection;
class ScTableProtectionDlg : public ModalDialog class ScTableProtectionDlg : public weld::GenericDialogController
{ {
public: public:
ScTableProtectionDlg() = delete; ScTableProtectionDlg() = delete;
explicit SC_DLLPUBLIC ScTableProtectionDlg(vcl::Window* pParent); explicit SC_DLLPUBLIC ScTableProtectionDlg(weld::Window* pParent);
virtual ~ScTableProtectionDlg() override; virtual ~ScTableProtectionDlg() override;
virtual void dispose() override;
void SetDialogData(const ScTableProtection& rData); void SetDialogData(const ScTableProtection& rData);
...@@ -47,17 +42,6 @@ private: ...@@ -47,17 +42,6 @@ private:
void EnableOptionalWidgets(bool bEnable); void EnableOptionalWidgets(bool bEnable);
VclPtr<CheckBox> m_pBtnProtect;
VclPtr<VclContainer> m_pPasswords;
VclPtr<VclContainer> m_pOptions;
VclPtr<Edit> m_pPassword1Edit;
VclPtr<Edit> m_pPassword2Edit;
VclPtr<SvxCheckListBox> m_pOptionsListBox;
VclPtr<OKButton> m_pBtnOk;
OUString m_aSelectLockedCells; OUString m_aSelectLockedCells;
OUString m_aSelectUnlockedCells; OUString m_aSelectUnlockedCells;
OUString m_aInsertColumns; OUString m_aInsertColumns;
...@@ -65,9 +49,25 @@ private: ...@@ -65,9 +49,25 @@ private:
OUString m_aDeleteColumns; OUString m_aDeleteColumns;
OUString m_aDeleteRows; OUString m_aDeleteRows;
DECL_LINK( OKHdl, Button*, void ); std::unique_ptr<weld::CheckButton> m_xBtnProtect;
DECL_LINK( CheckBoxHdl, Button*, void ); std::unique_ptr<weld::Container> m_xPasswords;
DECL_LINK( PasswordModifyHdl, Edit&, void ); std::unique_ptr<weld::Container> m_xOptions;
std::unique_ptr<weld::Entry> m_xPassword1Edit;
std::unique_ptr<weld::Entry> m_xPassword2Edit;
std::unique_ptr<weld::TreeView> m_xOptionsListBox;
std::unique_ptr<weld::Button> m_xBtnOk;
std::unique_ptr<weld::Label> m_xProtected;
std::unique_ptr<weld::Label> m_xUnprotected;
std::unique_ptr<weld::Label> m_xInsertColumns;
std::unique_ptr<weld::Label> m_xInsertRows;
std::unique_ptr<weld::Label> m_xDeleteColumns;
std::unique_ptr<weld::Label> m_xDeleteRows;
void InsertEntry(const OUString& rTxt);
DECL_LINK(OKHdl, weld::Button&, void);
DECL_LINK(CheckBoxHdl, weld::ToggleButton&, void);
DECL_LINK(PasswordModifyHdl, weld::Entry&, void);
}; };
#endif #endif
......
...@@ -38,118 +38,123 @@ const std::vector<ScTableProtection::Option> aOptions = { ...@@ -38,118 +38,123 @@ const std::vector<ScTableProtection::Option> aOptions = {
} }
ScTableProtectionDlg::ScTableProtectionDlg(vcl::Window* pParent) ScTableProtectionDlg::ScTableProtectionDlg(weld::Window* pParent)
: ModalDialog( pParent, "ProtectSheetDialog", "modules/scalc/ui/protectsheetdlg.ui" ) : weld::GenericDialogController(pParent, "modules/scalc/ui/protectsheetdlg.ui", "ProtectSheetDialog")
, m_xBtnProtect(m_xBuilder->weld_check_button("protect"))
, m_xPasswords(m_xBuilder->weld_container("passwords"))
, m_xOptions(m_xBuilder->weld_container("options"))
, m_xPassword1Edit(m_xBuilder->weld_entry("password1"))
, m_xPassword2Edit(m_xBuilder->weld_entry("password2"))
, m_xOptionsListBox(m_xBuilder->weld_tree_view("checklist"))
, m_xBtnOk(m_xBuilder->weld_button("ok"))
, m_xProtected(m_xBuilder->weld_label("protected"))
, m_xUnprotected(m_xBuilder->weld_label("unprotected"))
, m_xInsertColumns(m_xBuilder->weld_label("insert-columns"))
, m_xInsertRows(m_xBuilder->weld_label("insert-rows"))
, m_xDeleteColumns(m_xBuilder->weld_label("delete-columns"))
, m_xDeleteRows(m_xBuilder->weld_label("delete-rows"))
{ {
get(m_pPasswords, "passwords"); m_aSelectLockedCells = m_xProtected->get_label();
get(m_pOptions, "options"); m_aSelectUnlockedCells = m_xUnprotected->get_label();
get(m_pBtnProtect, "protect"); m_aInsertColumns = m_xInsertColumns->get_label();
get(m_pOptionsListBox, "checklist"); m_aInsertRows = m_xInsertRows->get_label();
get(m_pPassword1Edit, "password1"); m_aDeleteColumns = m_xDeleteColumns->get_label();
get(m_pPassword2Edit, "password2"); m_aDeleteRows = m_xDeleteRows->get_label();
get(m_pBtnOk, "ok");
std::vector<int> aWidths;
m_aSelectLockedCells = get<FixedText>("protected")->GetText(); aWidths.push_back(m_xOptionsListBox->get_approximate_digit_width() * 3 + 6);
m_aSelectUnlockedCells = get<FixedText>("unprotected")->GetText(); m_xOptionsListBox->set_column_fixed_widths(aWidths);
m_aInsertColumns = get<FixedText>("insert-columns")->GetText();
m_aInsertRows = get<FixedText>("insert-rows")->GetText();
m_aDeleteColumns = get<FixedText>("delete-columns")->GetText();
m_aDeleteRows = get<FixedText>("delete-rows")->GetText();
Init(); Init();
} }
ScTableProtectionDlg::~ScTableProtectionDlg() ScTableProtectionDlg::~ScTableProtectionDlg()
{ {
disposeOnce();
}
void ScTableProtectionDlg::dispose()
{
m_pBtnProtect.clear();
m_pPasswords.clear();
m_pOptions.clear();
m_pPassword1Edit.clear();
m_pPassword2Edit.clear();
m_pOptionsListBox.clear();
m_pBtnOk.clear();
ModalDialog::dispose();
} }
void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData) void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
{ {
for (size_t i = 0; i < aOptions.size(); ++i) for (size_t i = 0; i < aOptions.size(); ++i)
m_pOptionsListBox->CheckEntryPos(i, rData.isOptionEnabled(aOptions[i])); m_xOptionsListBox->set_toggle(i, rData.isOptionEnabled(aOptions[i]), 0);
} }
void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
{ {
rData.setProtected(m_pBtnProtect->IsChecked()); rData.setProtected(m_xBtnProtect->get_active());
// We assume that the two password texts match. // We assume that the two password texts match.
rData.setPassword(m_pPassword1Edit->GetText()); rData.setPassword(m_xPassword1Edit->get_text());
for (size_t i = 0; i < aOptions.size(); ++i) for (size_t i = 0; i < aOptions.size(); ++i)
rData.setOption(aOptions[i], m_pOptionsListBox->IsChecked(i)); rData.setOption(aOptions[i], m_xOptionsListBox->get_toggle(i, 0));
}
void ScTableProtectionDlg::InsertEntry(const OUString& rTxt)
{
m_xOptionsListBox->insert(nullptr, -1, nullptr, nullptr, nullptr,
nullptr, nullptr, false);
const int nRow = m_xOptionsListBox->n_children() - 1;
m_xOptionsListBox->set_toggle(nRow, false, 0);
m_xOptionsListBox->set_text(nRow, rTxt, 1);
} }
void ScTableProtectionDlg::Init() void ScTableProtectionDlg::Init()
{ {
m_pBtnProtect->SetClickHdl(LINK( this, ScTableProtectionDlg, CheckBoxHdl )); m_xBtnProtect->connect_toggled(LINK(this, ScTableProtectionDlg, CheckBoxHdl));
m_pBtnOk->SetClickHdl(LINK( this, ScTableProtectionDlg, OKHdl )); m_xBtnOk->connect_clicked(LINK(this, ScTableProtectionDlg, OKHdl));
Link<Edit&,void> aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl ); Link<weld::Entry&,void> aLink = LINK(this, ScTableProtectionDlg, PasswordModifyHdl);
m_pPassword1Edit->SetModifyHdl(aLink); m_xPassword1Edit->connect_changed(aLink);
m_pPassword2Edit->SetModifyHdl(aLink); m_xPassword2Edit->connect_changed(aLink);
m_pOptionsListBox->SetUpdateMode(false); m_xOptionsListBox->freeze();
m_pOptionsListBox->Clear(); m_xOptionsListBox->clear();
m_pOptionsListBox->InsertEntry(m_aSelectLockedCells); InsertEntry(m_aSelectLockedCells);
m_pOptionsListBox->InsertEntry(m_aSelectUnlockedCells); InsertEntry(m_aSelectUnlockedCells);
m_pOptionsListBox->InsertEntry(m_aInsertColumns); InsertEntry(m_aInsertColumns);
m_pOptionsListBox->InsertEntry(m_aInsertRows); InsertEntry(m_aInsertRows);
m_pOptionsListBox->InsertEntry(m_aDeleteColumns); InsertEntry(m_aDeleteColumns);
m_pOptionsListBox->InsertEntry(m_aDeleteRows); InsertEntry(m_aDeleteRows);
m_pOptionsListBox->CheckEntryPos(0); m_xOptionsListBox->set_toggle(0, true, 0);
m_pOptionsListBox->CheckEntryPos(1); m_xOptionsListBox->set_toggle(1, true, 0);
m_pOptionsListBox->SetUpdateMode(true); m_xOptionsListBox->thaw();
// Set the default state of the dialog. // Set the default state of the dialog.
m_pBtnProtect->Check(); m_xBtnProtect->set_active(true);
m_pPassword1Edit->GrabFocus(); m_xPassword1Edit->grab_focus();
} }
void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable) void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
{ {
m_pPasswords->Enable(bEnable); m_xPasswords->set_sensitive(bEnable);
m_pOptions->Enable(bEnable); m_xOptions->set_sensitive(bEnable);
m_pOptionsListBox->Invalidate(); //TODO m_xOptionsListBox->Invalidate();
} }
IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, Button*, pBtn, void ) IMPL_LINK(ScTableProtectionDlg, CheckBoxHdl, weld::ToggleButton&, rBtn, void)
{ {
if (pBtn == m_pBtnProtect) if (&rBtn == m_xBtnProtect.get())
{ {
bool bChecked = m_pBtnProtect->IsChecked(); bool bChecked = m_xBtnProtect->get_active();
EnableOptionalWidgets(bChecked); EnableOptionalWidgets(bChecked);
m_pBtnOk->Enable(bChecked); m_xBtnOk->set_sensitive(bChecked);
} }
} }
IMPL_LINK_NOARG(ScTableProtectionDlg, OKHdl, Button*, void) IMPL_LINK_NOARG(ScTableProtectionDlg, OKHdl, weld::Button&, void)
{ {
EndDialog(RET_OK); m_xDialog->response(RET_OK);
} }
IMPL_LINK_NOARG(ScTableProtectionDlg, PasswordModifyHdl, Edit&, void) IMPL_LINK_NOARG(ScTableProtectionDlg, PasswordModifyHdl, weld::Entry&, void)
{ {
OUString aPass1 = m_pPassword1Edit->GetText(); OUString aPass1 = m_xPassword1Edit->get_text();
OUString aPass2 = m_pPassword2Edit->GetText(); OUString aPass2 = m_xPassword2Edit->get_text();
m_pBtnOk->Enable(aPass1 == aPass2); m_xBtnOk->set_sensitive(aPass1 == aPass2);
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -1157,18 +1157,19 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) ...@@ -1157,18 +1157,19 @@ void ScTabViewShell::Execute( SfxRequest& rReq )
{ {
// Protect a current sheet. // Protect a current sheet.
VclPtrInstance< ScTableProtectionDlg > pDlg(GetDialogParent()); vcl::Window* pWin = GetDialogParent();
ScTableProtectionDlg aDlg(pWin ? pWin->GetFrameWeld() : nullptr);
ScTableProtection* pProtect = pDoc->GetTabProtection(nTab); ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
if (pProtect) if (pProtect)
pDlg->SetDialogData(*pProtect); aDlg.SetDialogData(*pProtect);
if (pDlg->Execute() == RET_OK) if (aDlg.run() == RET_OK)
{ {
pScMod->InputEnterHandler(); pScMod->InputEnterHandler();
ScTableProtection aNewProtect; ScTableProtection aNewProtect;
pDlg->WriteData(aNewProtect); aDlg.WriteData(aNewProtect);
ProtectSheet(nTab, aNewProtect); ProtectSheet(nTab, aNewProtect);
if (!pReqArgs) if (!pReqArgs)
{ {
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 --> <!-- Generated with glade 3.22.1 -->
<interface domain="sc"> <interface domain="sc">
<requires lib="gtk+" version="3.18"/> <requires lib="gtk+" version="3.18"/>
<requires lib="LibreOffice" version="1.0"/> <object class="GtkTreeStore" id="liststore1">
<columns>
<!-- column-name check1 -->
<column type="gboolean"/>
<!-- column-name text -->
<column type="gchararray"/>
<!-- column-name id -->
<column type="gchararray"/>
<!-- column-name checkvis1 -->
<column type="gboolean"/>
</columns>
</object>
<object class="GtkDialog" id="ProtectSheetDialog"> <object class="GtkDialog" id="ProtectSheetDialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">6</property> <property name="border_width">6</property>
<property name="title" translatable="yes" context="protectsheetdlg|ProtectSheetDialog">Protect Sheet</property> <property name="title" translatable="yes" context="protectsheetdlg|ProtectSheetDialog">Protect Sheet</property>
<property name="modal">True</property>
<property name="default_width">0</property>
<property name="default_height">0</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox"> <child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1"> <object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property> <property name="can_focus">False</property>
...@@ -144,7 +161,9 @@ ...@@ -144,7 +161,9 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="visibility">False</property> <property name="visibility">False</property>
<property name="activates_default">True</property>
<property name="width_chars">24</property> <property name="width_chars">24</property>
<property name="input_purpose">password</property>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
...@@ -157,7 +176,9 @@ ...@@ -157,7 +176,9 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="visibility">False</property> <property name="visibility">False</property>
<property name="activates_default">True</property>
<property name="width_chars">24</property> <property name="width_chars">24</property>
<property name="input_purpose">password</property>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
...@@ -192,7 +213,7 @@ ...@@ -192,7 +213,7 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes" context="protectsheetdlg|label4">Allow all users of this sheet to:</property> <property name="label" translatable="yes" context="protectsheetdlg|label4">Allow all users of this sheet to:</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="mnemonic_widget">checklist:border</property> <property name="mnemonic_widget">checklist</property>
<property name="xalign">0</property> <property name="xalign">0</property>
</object> </object>
<packing> <packing>
...@@ -202,13 +223,55 @@ ...@@ -202,13 +223,55 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="svxcorelo-SvxCheckListBox" id="checklist:border"> <object class="GtkScrolledWindow">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<child internal-child="selection"> <property name="hscrollbar_policy">never</property>
<object class="GtkTreeSelection" id="Checked Tree List-selection1"/> <property name="vscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="checklist">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="model">liststore1</property>
<property name="headers_visible">False</property>
<property name="search_column">0</property>
<property name="show_expanders">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="Macro Library List-selection2"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn4">
<property name="resizable">True</property>
<property name="spacing">6</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererToggle" id="cellrenderer5"/>
<attributes>
<attribute name="visible">3</attribute>
<attribute name="active">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn5">
<property name="resizable">True</property>
<property name="spacing">6</property>
<child>
<object class="GtkCellRendererText" id="cellrenderer4"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child> </child>
</object> </object>
<packing> <packing>
...@@ -235,10 +298,10 @@ ...@@ -235,10 +298,10 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="unprotected"> <object class="GtkLabel" id="delete-rows">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes" context="protectsheetdlg|unprotected">Select unprotected cells</property> <property name="label" translatable="yes" context="protectsheetdlg|delete-rows">Delete rows</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -247,10 +310,10 @@ ...@@ -247,10 +310,10 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="insert-columns"> <object class="GtkLabel" id="insert-rows">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes" context="protectsheetdlg|insert-columns">Insert columns</property> <property name="label" translatable="yes" context="protectsheetdlg|insert-rows">Insert rows</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -259,10 +322,10 @@ ...@@ -259,10 +322,10 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="insert-rows"> <object class="GtkLabel" id="unprotected">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes" context="protectsheetdlg|insert-rows">Insert rows</property> <property name="label" translatable="yes" context="protectsheetdlg|unprotected">Select unprotected cells</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -271,10 +334,10 @@ ...@@ -271,10 +334,10 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="delete-columns"> <object class="GtkLabel" id="insert-columns">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes" context="protectsheetdlg|delete-columns">Delete columns</property> <property name="label" translatable="yes" context="protectsheetdlg|insert-columns">Insert columns</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -283,10 +346,10 @@ ...@@ -283,10 +346,10 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="delete-rows"> <object class="GtkLabel" id="delete-columns">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes" context="protectsheetdlg|delete-rows">Delete rows</property> <property name="label" translatable="yes" context="protectsheetdlg|delete-columns">Delete columns</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment