diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-03-04 17:05:19 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-03-05 00:32:13 +0100 |
commit | d6f1c3dece1ab321230cbaf6b5a11318ba04b216 (patch) | |
tree | 9a09218d3fb27dfef8939c8924dd100378196f78 /sfx2 | |
parent | 77db2da61658906c354084b13a95f1102949fbd0 (diff) |
weld SfxPasswordDialog Dialog
Change-Id: If8c9757986f4af7b7927717221860e65c8c7285e
Reviewed-on: https://gerrit.libreoffice.org/50755
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/dialog/passwd.cxx | 203 | ||||
-rw-r--r-- | sfx2/source/dialog/securitypage.cxx | 19 | ||||
-rw-r--r-- | sfx2/source/doc/docinsert.cxx | 8 | ||||
-rw-r--r-- | sfx2/uiconfig/ui/password.ui | 20 |
4 files changed, 116 insertions, 134 deletions
diff --git a/sfx2/source/dialog/passwd.cxx b/sfx2/source/dialog/passwd.cxx index 8c0f2378329c..7b4f236f39af 100644 --- a/sfx2/source/dialog/passwd.cxx +++ b/sfx2/source/dialog/passwd.cxx @@ -23,64 +23,81 @@ #include <sfx2/strings.hrc> #include <vcl/weld.hxx> -IMPL_LINK( SfxPasswordDialog, EditModifyHdl, Edit&, rEdit, void ) +IMPL_LINK_NOARG(SfxPasswordDialog, EditModifyHdl, weld::Entry&, void) { - ModifyHdl(&rEdit); + ModifyHdl(); } -void SfxPasswordDialog::ModifyHdl(Edit* pEdit) +void SfxPasswordDialog::ModifyHdl() { - if (mbAsciiOnly && (pEdit == mpPassword1ED || pEdit == mpPassword2ED)) - { - OUString aTest( pEdit->GetText() ); - const sal_Unicode* pTest = aTest.getStr(); - sal_Int32 nLen = aTest.getLength(); - OUStringBuffer aFilter( nLen ); - bool bReset = false; - for( sal_Int32 i = 0; i < nLen; i++ ) - { - if( *pTest > 0x007f ) - bReset = true; - else - aFilter.append( *pTest ); - pTest++; - } - if( bReset ) - { - pEdit->SetSelection( Selection( 0, nLen ) ); - pEdit->ReplaceSelected( aFilter.makeStringAndClear() ); - } + bool bEnable = m_xPassword1ED->get_text().getLength() >= mnMinLen; + if (m_xPassword2ED->get_visible()) + bEnable = (bEnable && (m_xPassword2ED->get_text().getLength() >= mnMinLen)); + m_xOKBtn->set_sensitive(bEnable); +} +IMPL_LINK(SfxPasswordDialog, InsertTextHdl, OUString&, rTest, bool) +{ + if (!mbAsciiOnly) + return true; + + const sal_Unicode* pTest = rTest.getStr(); + sal_Int32 nLen = rTest.getLength(); + OUStringBuffer aFilter(nLen); + bool bReset = false; + for (sal_Int32 i = 0; i < nLen; ++i) + { + if( *pTest > 0x007f ) + bReset = true; + else + aFilter.append(*pTest); + ++pTest; } - bool bEnable = mpPassword1ED->GetText().getLength() >= mnMinLen; - if( mpPassword2ED->IsVisible() ) - bEnable = (bEnable && (mpPassword2ED->GetText().getLength() >= mnMinLen)); - mpOKBtn->Enable( bEnable ); + + if (bReset) + rTest = aFilter.makeStringAndClear(); + + return true; } -IMPL_LINK_NOARG(SfxPasswordDialog, OKHdl, Button*, void) +IMPL_LINK_NOARG(SfxPasswordDialog, OKHdl, weld::Button&, void) { bool bConfirmFailed = bool( mnExtras & SfxShowExtras::CONFIRM ) && ( GetConfirm() != GetPassword() ); - if( ( mnExtras & SfxShowExtras::CONFIRM2 ) && ( mpConfirm2ED->GetText() != GetPassword2() ) ) + if( ( mnExtras & SfxShowExtras::CONFIRM2 ) && ( m_xConfirm2ED->get_text() != GetPassword2() ) ) bConfirmFailed = true; if ( bConfirmFailed ) { - std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning, VclButtonsType::Ok, SfxResId(STR_ERROR_WRONG_CONFIRM))); xBox->run(); - mpConfirm1ED->SetText( OUString() ); - mpConfirm1ED->GrabFocus(); + m_xConfirm1ED->set_text(OUString()); + m_xConfirm1ED->grab_focus(); } else - EndDialog( RET_OK ); + m_xDialog->response(RET_OK); } // CTOR / DTOR ----------------------------------------------------------- -SfxPasswordDialog::SfxPasswordDialog(vcl::Window* pParent, const OUString* pGroupText) - : ModalDialog(pParent, "PasswordDialog", "sfx/ui/password.ui") +SfxPasswordDialog::SfxPasswordDialog(weld::Window* pParent, const OUString* pGroupText) + : m_xBuilder(Application::CreateBuilder(pParent, "sfx/ui/password.ui")) + , m_xDialog(m_xBuilder->weld_dialog("PasswordDialog")) + , m_xPassword1Box(m_xBuilder->weld_frame("password1frame")) + , m_xUserFT(m_xBuilder->weld_label("userft")) + , m_xUserED(m_xBuilder->weld_entry("usered")) + , m_xPassword1FT(m_xBuilder->weld_label("pass1ft")) + , m_xPassword1ED(m_xBuilder->weld_entry("pass1ed")) + , m_xConfirm1FT(m_xBuilder->weld_label("confirm1ft")) + , m_xConfirm1ED(m_xBuilder->weld_entry("confirm1ed")) + , m_xPassword2Box(m_xBuilder->weld_frame("password2frame")) + , m_xPassword2FT(m_xBuilder->weld_label("pass2ft")) + , m_xPassword2ED(m_xBuilder->weld_entry("pass2ed")) + , m_xConfirm2FT(m_xBuilder->weld_label("confirm2ft")) + , m_xConfirm2ED(m_xBuilder->weld_entry("confirm2ed")) + , m_xMinLengthFT(m_xBuilder->weld_label("minlenft")) + , m_xOKBtn(m_xBuilder->weld_button("ok")) , maMinLenPwdStr(SfxResId(STR_PASSWD_MIN_LEN)) , maMinLenPwdStr1(SfxResId(STR_PASSWD_MIN_LEN1)) , maEmptyPwdStr(SfxResId(STR_PASSWD_EMPTY)) @@ -88,74 +105,35 @@ SfxPasswordDialog::SfxPasswordDialog(vcl::Window* pParent, const OUString* pGrou , mnExtras(SfxShowExtras::NONE) , mbAsciiOnly(false) { - get(mpPassword1Box, "password1frame"); - get(mpUserFT, "userft"); - get(mpUserED, "usered"); - get(mpPassword1FT, "pass1ft"); - get(mpPassword1ED, "pass1ed"); - get(mpConfirm1FT, "confirm1ft"); - get(mpConfirm1ED, "confirm1ed"); - - get(mpPassword2Box, "password2frame"); - get(mpPassword2FT, "pass2ft"); - get(mpPassword2ED, "pass2ed"); - get(mpConfirm2FT, "confirm2ft"); - get(mpConfirm2ED, "confirm2ed"); - - get(mpMinLengthFT, "minlenft"); - - get(mpOKBtn, "ok"); - - Link<Edit&,void> aLink = LINK( this, SfxPasswordDialog, EditModifyHdl ); - mpPassword1ED->SetModifyHdl( aLink ); - mpPassword2ED->SetModifyHdl( aLink ); - mpOKBtn->SetClickHdl( LINK( this, SfxPasswordDialog, OKHdl ) ); + Link<weld::Entry&,void> aLink = LINK(this, SfxPasswordDialog, EditModifyHdl); + m_xPassword1ED->connect_changed(aLink); + m_xPassword2ED->connect_changed(aLink); + Link<OUString&,bool> aLink2 = LINK(this, SfxPasswordDialog, InsertTextHdl); + m_xPassword1ED->connect_insert_text(aLink2); + m_xPassword2ED->connect_insert_text(aLink2); + m_xOKBtn->connect_clicked(LINK(this, SfxPasswordDialog, OKHdl)); if (pGroupText) - mpPassword1Box->set_label(*pGroupText); + m_xPassword1Box->set_label(*pGroupText); //set the text to the password length SetPasswdText(); } -SfxPasswordDialog::~SfxPasswordDialog() -{ - disposeOnce(); -} - -void SfxPasswordDialog::dispose() -{ - mpPassword1Box.clear(); - mpUserFT.clear(); - mpUserED.clear(); - mpPassword1FT.clear(); - mpPassword1ED.clear(); - mpConfirm1FT.clear(); - mpConfirm1ED.clear(); - mpPassword2Box.clear(); - mpPassword2FT.clear(); - mpPassword2ED.clear(); - mpConfirm2FT.clear(); - mpConfirm2ED.clear(); - mpMinLengthFT.clear(); - mpOKBtn.clear(); - ModalDialog::dispose(); -} - void SfxPasswordDialog::SetPasswdText( ) { -//set the new string to the minimum password length - if( mnMinLen == 0 ) - mpMinLengthFT->SetText(maEmptyPwdStr); + //set the new string to the minimum password length + if (mnMinLen == 0) + m_xMinLengthFT->set_label(maEmptyPwdStr); else { if( mnMinLen == 1 ) - mpMinLengthFT->SetText(maMinLenPwdStr1); + m_xMinLengthFT->set_label(maMinLenPwdStr1); else { maMainPwdStr = maMinLenPwdStr; maMainPwdStr = maMainPwdStr.replaceAll( "$(MINLEN)", OUString::number(static_cast<sal_Int32>(mnMinLen) ) ); - mpMinLengthFT->SetText(maMainPwdStr); + m_xMinLengthFT->set_label(maMainPwdStr); } } } @@ -165,54 +143,53 @@ void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen ) { mnMinLen = nLen; SetPasswdText(); - ModifyHdl( nullptr ); + ModifyHdl(); } void SfxPasswordDialog::ShowMinLengthText(bool bShow) { - mpMinLengthFT->Show(bShow); + m_xMinLengthFT->show(bShow); } - -short SfxPasswordDialog::Execute() +short SfxPasswordDialog::run() { - mpUserFT->Hide(); - mpUserED->Hide(); - mpConfirm1FT->Hide(); - mpConfirm1ED->Hide(); - mpPassword1FT->Hide(); - mpPassword2Box->Hide(); - mpPassword2FT->Hide(); - mpPassword2ED->Hide(); - mpPassword2FT->Hide(); - mpConfirm2FT->Hide(); - mpConfirm2ED->Hide(); + m_xUserFT->hide(); + m_xUserED->hide(); + m_xConfirm1FT->hide(); + m_xConfirm1ED->hide(); + m_xPassword1FT->hide(); + m_xPassword2Box->hide(); + m_xPassword2FT->hide(); + m_xPassword2ED->hide(); + m_xPassword2FT->hide(); + m_xConfirm2FT->hide(); + m_xConfirm2ED->hide(); if (mnExtras != SfxShowExtras::NONE) - mpPassword1FT->Show(); + m_xPassword1FT->show(); if (mnExtras & SfxShowExtras::USER) { - mpUserFT->Show(); - mpUserED->Show(); + m_xUserFT->show(); + m_xUserED->show(); } if (mnExtras & SfxShowExtras::CONFIRM) { - mpConfirm1FT->Show(); - mpConfirm1ED->Show(); + m_xConfirm1FT->show(); + m_xConfirm1ED->show(); } if (mnExtras & SfxShowExtras::PASSWORD2) { - mpPassword2Box->Show(); - mpPassword2FT->Show(); - mpPassword2ED->Show(); + m_xPassword2Box->show(); + m_xPassword2FT->show(); + m_xPassword2ED->show(); } if (mnExtras & SfxShowExtras::CONFIRM2) { - mpConfirm2FT->Show(); - mpConfirm2ED->Show(); + m_xConfirm2FT->show(); + m_xConfirm2ED->show(); } - return ModalDialog::Execute(); + return m_xDialog->run(); } diff --git a/sfx2/source/dialog/securitypage.cxx b/sfx2/source/dialog/securitypage.cxx index 8d9ef33a9293..fcd78d3f0ab5 100644 --- a/sfx2/source/dialog/securitypage.cxx +++ b/sfx2/source/dialog/securitypage.cxx @@ -92,18 +92,18 @@ namespace static bool lcl_GetPassword( - vcl::Window *pParent, + weld::Window *pParent, bool bProtect, /*out*/OUString &rPassword ) { bool bRes = false; - ScopedVclPtrInstance< SfxPasswordDialog > aPasswdDlg(pParent); - aPasswdDlg->SetMinLen( 1 ); + SfxPasswordDialog aPasswdDlg(pParent); + aPasswdDlg.SetMinLen(1); if (bProtect) - aPasswdDlg->ShowExtras( SfxShowExtras::CONFIRM ); - if (RET_OK == aPasswdDlg->Execute() && !aPasswdDlg->GetPassword().isEmpty()) + aPasswdDlg.ShowExtras( SfxShowExtras::CONFIRM ); + if (RET_OK == aPasswdDlg.run() && !aPasswdDlg.GetPassword().isEmpty()) { - rPassword = aPasswdDlg->GetPassword(); + rPassword = aPasswdDlg.GetPassword(); bRes = true; } return bRes; @@ -332,8 +332,7 @@ IMPL_LINK_NOARG(SfxSecurityPage_Impl, RecordChangesCBToggleHdl, CheckBox&, void) bool bAlreadyDone = false; if (!m_bEndRedliningWarningDone) { - vcl::Window* pWin = m_rMyTabPage.GetParent(); - std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr, + std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(m_rMyTabPage.GetFrameWeld(), VclMessageType::Warning, VclButtonsType::YesNo, m_aEndRedliningWarning)); xWarn->set_default_response(RET_NO); @@ -350,7 +349,7 @@ IMPL_LINK_NOARG(SfxSecurityPage_Impl, RecordChangesCBToggleHdl, CheckBox&, void) OUString aPasswordText; // dialog canceled or no password provided - if (!lcl_GetPassword( m_rMyTabPage.GetParent(), false, aPasswordText )) + if (!lcl_GetPassword( m_rMyTabPage.GetFrameWeld(), false, aPasswordText )) bAlreadyDone = true; // ask for password and if dialog is canceled or no password provided return @@ -390,7 +389,7 @@ IMPL_LINK_NOARG(SfxSecurityPage_Impl, ChangeProtectionPBHdl, Button*, void) if (bNeedPassword) { // ask for password and if dialog is canceled or no password provided return - if (!lcl_GetPassword( m_rMyTabPage.GetParent(), bNewProtection, aPasswordText )) + if (!lcl_GetPassword(m_rMyTabPage.GetFrameWeld(), bNewProtection, aPasswordText)) return; // provided password still needs to be checked? diff --git a/sfx2/source/doc/docinsert.cxx b/sfx2/source/doc/docinsert.cxx index de150152f6a2..2f53b7519163 100644 --- a/sfx2/source/doc/docinsert.cxx +++ b/sfx2/source/doc/docinsert.cxx @@ -216,12 +216,12 @@ IMPL_LINK_NOARG(DocumentInserter, DialogClosedHdl, sfx2::FileDialogHelper*, void if ( ( aValue >>= bPassWord ) && bPassWord ) { // ask for the password - ScopedVclPtrInstance< SfxPasswordDialog > aPasswordDlg(nullptr); - aPasswordDlg->ShowExtras( SfxShowExtras::CONFIRM ); - short nRet = aPasswordDlg->Execute(); + SfxPasswordDialog aPasswordDlg(m_xParent ? m_xParent->GetFrameWeld() : nullptr); + aPasswordDlg.ShowExtras( SfxShowExtras::CONFIRM ); + short nRet = aPasswordDlg.run(); if ( RET_OK == nRet ) { - m_pItemSet->Put( SfxStringItem( SID_PASSWORD, aPasswordDlg->GetPassword() ) ); + m_pItemSet->Put( SfxStringItem( SID_PASSWORD, aPasswordDlg.GetPassword() ) ); } else { diff --git a/sfx2/uiconfig/ui/password.ui b/sfx2/uiconfig/ui/password.ui index 09fbb09cf9ee..086c3965806a 100644 --- a/sfx2/uiconfig/ui/password.ui +++ b/sfx2/uiconfig/ui/password.ui @@ -1,11 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.20.0 --> +<!-- Generated with glade 3.20.2 --> <interface domain="sfx"> - <requires lib="gtk+" version="3.0"/> + <requires lib="gtk+" version="3.20"/> <object class="GtkDialog" id="PasswordDialog"> <property name="can_focus">False</property> <property name="border_width">6</property> <property name="title" translatable="yes" context="password|PasswordDialog">Enter Password</property> + <property name="modal">True</property> + <property name="default_width">0</property> + <property name="default_height">0</property> <property name="type_hint">dialog</property> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox1"> @@ -22,6 +25,7 @@ <property name="visible">True</property> <property name="sensitive">False</property> <property name="can_focus">True</property> + <property name="can_default">True</property> <property name="has_default">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> @@ -152,7 +156,7 @@ <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="visibility">False</property> - <property name="invisible_char">●</property> + <property name="input_purpose">password</property> <child internal-child="accessible"> <object class="AtkObject" id="pass1ed-atkobject"> <property name="AtkObject::accessible-name" translatable="yes" context="password|pass1ed-atkobject">Password</property> @@ -170,7 +174,7 @@ <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="visibility">False</property> - <property name="invisible_char">●</property> + <property name="input_purpose">password</property> </object> <packing> <property name="left_attach">1</property> @@ -250,7 +254,7 @@ <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="visibility">False</property> - <property name="invisible_char">●</property> + <property name="input_purpose">password</property> </object> <packing> <property name="left_attach">1</property> @@ -263,7 +267,7 @@ <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="visibility">False</property> - <property name="invisible_char">●</property> + <property name="input_purpose">password</property> </object> <packing> <property name="left_attach">1</property> @@ -314,9 +318,11 @@ </object> </child> <action-widgets> - <action-widget response="-5">ok</action-widget> <action-widget response="-6">cancel</action-widget> <action-widget response="-11">help</action-widget> </action-widgets> + <child> + <placeholder/> + </child> </object> </interface> |