update credits
[LibreOffice.git] / cui / source / dialogs / passwdomdlg.cxx
blob9c7ce0cfb4ffe681545814d30bf1b32230719b5e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "passwdomdlg.hrc"
21 #include "passwdomdlg.hxx"
23 #include "cuires.hrc"
24 #include "dialmgr.hxx"
26 #include <sfx2/tabdlg.hxx>
27 #include <vcl/fixed.hxx>
28 #include <vcl/edit.hxx>
29 #include <vcl/button.hxx>
30 #include <vcl/morebtn.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/msgbox.hxx>
35 //////////////////////////////////////////////////////////////////////
37 class PasswordReenterEdit_Impl : public Edit
39 String m_aDefaultTxt;
41 // disallow use of copy c-tor and assignment operator
42 PasswordReenterEdit_Impl( const PasswordReenterEdit_Impl & );
43 PasswordReenterEdit_Impl & operator = ( const PasswordReenterEdit_Impl & );
45 public:
46 PasswordReenterEdit_Impl( Window * pParent, const ResId &rResId );
47 virtual ~PasswordReenterEdit_Impl();
49 // Edit
50 virtual void Paint( const Rectangle& rRect );
54 PasswordReenterEdit_Impl::PasswordReenterEdit_Impl( Window * pParent, const ResId &rResId ) :
55 Edit( pParent, rResId )
60 PasswordReenterEdit_Impl::~PasswordReenterEdit_Impl()
65 void PasswordReenterEdit_Impl::Paint( const Rectangle& rRect )
67 if (GetText().isEmpty())
69 Push( PUSH_TEXTCOLOR );
70 SetTextColor( Color( COL_GRAY ) );
71 DrawText( Point(), m_aDefaultTxt );
73 Pop();
75 else
76 Edit::Paint( rRect );
80 //////////////////////////////////////////////////////////////////////
82 struct PasswordToOpenModifyDialog_Impl
84 PasswordToOpenModifyDialog * m_pParent;
86 FixedLine m_aFileEncryptionFL;
87 FixedText m_aPasswdToOpenFT;
88 Edit m_aPasswdToOpenED;
89 FixedText m_aReenterPasswdToOpenFT;
90 PasswordReenterEdit_Impl m_aReenterPasswdToOpenED;
91 FixedText m_aPasswdNoteFT;
92 FixedLine m_aButtonsFL;
93 MoreButton m_aMoreFewerOptionsBTN;
94 OKButton m_aOk;
95 CancelButton m_aCancel;
96 FixedLine m_aFileSharingOptionsFL;
97 CheckBox m_aOpenReadonlyCB;
98 FixedText m_aPasswdToModifyFT;
99 Edit m_aPasswdToModifyED;
100 FixedText m_aReenterPasswdToModifyFT;
101 PasswordReenterEdit_Impl m_aReenterPasswdToModifyED;
103 String m_aOneMismatch;
104 String m_aTwoMismatch;
105 String m_aInvalidStateForOkButton;
106 String m_aInvalidStateForOkButton_v2;
108 bool m_bIsPasswordToModify;
111 DECL_LINK( OkBtnClickHdl, OKButton * );
113 PasswordToOpenModifyDialog_Impl( PasswordToOpenModifyDialog * pParent,
114 sal_uInt16 nMinPasswdLen, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify );
115 ~PasswordToOpenModifyDialog_Impl();
119 PasswordToOpenModifyDialog_Impl::PasswordToOpenModifyDialog_Impl(
120 PasswordToOpenModifyDialog * pParent,
121 sal_uInt16 nMinPasswdLen,
122 sal_uInt16 nMaxPasswdLen,
123 bool bIsPasswordToModify ) :
124 m_pParent( pParent ),
125 m_aFileEncryptionFL ( pParent, CUI_RES( FL_FILE_ENCRYPTION ) ),
126 m_aPasswdToOpenFT ( pParent, CUI_RES( FT_PASSWD_TO_OPEN ) ),
127 m_aPasswdToOpenED ( pParent, CUI_RES( ED_PASSWD_TO_OPEN ) ),
128 m_aReenterPasswdToOpenFT ( pParent, CUI_RES( FT_REENTER_PASSWD_TO_OPEN ) ),
129 m_aReenterPasswdToOpenED ( pParent, CUI_RES( ED_REENTER_PASSWD_TO_OPEN ) ),
130 m_aPasswdNoteFT ( pParent, CUI_RES( FT_PASSWD_NOTE ) ),
131 m_aButtonsFL ( pParent, CUI_RES( FL_BUTTONS ) ),
132 m_aMoreFewerOptionsBTN ( pParent, CUI_RES( BTN_MORE_FEWER_OPTIONS ) ),
133 m_aOk ( pParent, CUI_RES( BTN_OK ) ),
134 m_aCancel ( pParent, CUI_RES( BTN_CANCEL ) ),
135 m_aFileSharingOptionsFL ( pParent, CUI_RES( FL_FILE_SHARING_OPTIONS ) ),
136 m_aOpenReadonlyCB ( pParent, CUI_RES( CB_OPEN_READONLY ) ),
137 m_aPasswdToModifyFT ( pParent, CUI_RES( FT_PASSWD_TO_MODIFY ) ),
138 m_aPasswdToModifyED ( pParent, CUI_RES( ED_PASSWD_TO_MODIFY ) ),
139 m_aReenterPasswdToModifyFT ( pParent, CUI_RES( FT_REENTER_PASSWD_TO_MODIFY ) ),
140 m_aReenterPasswdToModifyED ( pParent, CUI_RES( ED_REENTER_PASSWD_TO_MODIFY ) ),
141 m_aOneMismatch( CUI_RES( STR_ONE_PASSWORD_MISMATCH ) ),
142 m_aTwoMismatch( CUI_RES( STR_TWO_PASSWORDS_MISMATCH ) ),
143 m_aInvalidStateForOkButton( CUI_RES( STR_INVALID_STATE_FOR_OK_BUTTON ) ),
144 m_aInvalidStateForOkButton_v2( CUI_RES( STR_INVALID_STATE_FOR_OK_BUTTON_V2 ) ),
145 m_bIsPasswordToModify( bIsPasswordToModify )
147 m_aMoreFewerOptionsBTN.SetMoreText( String( CUI_RES( STR_MORE_OPTIONS ) ) );
148 m_aMoreFewerOptionsBTN.SetLessText( String( CUI_RES( STR_FEWER_OPTIONS ) ) );
150 m_aOk.SetClickHdl( LINK( this, PasswordToOpenModifyDialog_Impl, OkBtnClickHdl ) );
152 if (nMaxPasswdLen)
154 m_aPasswdToOpenED.SetMaxTextLen( nMaxPasswdLen );
155 m_aReenterPasswdToOpenED.SetMaxTextLen( nMaxPasswdLen );
156 m_aPasswdToModifyED.SetMaxTextLen( nMaxPasswdLen );
157 m_aReenterPasswdToModifyED.SetMaxTextLen( nMaxPasswdLen );
160 (void) nMinPasswdLen; // currently not supported
162 m_aPasswdToOpenED.GrabFocus();
164 m_aMoreFewerOptionsBTN.Enable( bIsPasswordToModify );
165 if (!bIsPasswordToModify)
166 m_aMoreFewerOptionsBTN.Hide( sal_True );
170 PasswordToOpenModifyDialog_Impl::~PasswordToOpenModifyDialog_Impl()
174 IMPL_LINK( PasswordToOpenModifyDialog_Impl, OkBtnClickHdl, OKButton *, EMPTYARG /*pBtn*/ )
176 bool bInvalidState = !m_aOpenReadonlyCB.IsChecked() &&
177 m_aPasswdToOpenED.GetText().isEmpty() &&
178 m_aPasswdToModifyED.GetText().isEmpty();
179 if (bInvalidState)
181 ErrorBox aErrorBox( m_pParent, WB_OK,
182 m_bIsPasswordToModify? m_aInvalidStateForOkButton : m_aInvalidStateForOkButton_v2 );
183 aErrorBox.Execute();
185 else // check for mismatched passwords...
187 const bool bToOpenMatch = m_aPasswdToOpenED.GetText() == m_aReenterPasswdToOpenED.GetText();
188 const bool bToModifyMatch = m_aPasswdToModifyED.GetText() == m_aReenterPasswdToModifyED.GetText();
189 const int nMismatch = (bToOpenMatch? 0 : 1) + (bToModifyMatch? 0 : 1);
190 if (nMismatch > 0)
192 ErrorBox aErrorBox( m_pParent, WB_OK, nMismatch == 1 ? m_aOneMismatch : m_aTwoMismatch );
193 aErrorBox.Execute();
195 Edit &rEdit = !bToOpenMatch? m_aPasswdToOpenED : m_aPasswdToModifyED;
196 PasswordReenterEdit_Impl &rRepeatEdit = !bToOpenMatch? m_aReenterPasswdToOpenED : m_aReenterPasswdToModifyED;
197 String aEmpty;
198 if (nMismatch == 1)
200 rEdit.SetText( aEmpty );
201 rRepeatEdit.SetText( aEmpty );
203 else if (nMismatch == 2)
205 m_aPasswdToOpenED.SetText( aEmpty );
206 m_aReenterPasswdToOpenED.SetText( aEmpty );
207 m_aPasswdToModifyED.SetText( aEmpty );
208 m_aReenterPasswdToModifyED.SetText( aEmpty );
210 rEdit.GrabFocus();
212 else
214 m_pParent->EndDialog( RET_OK );
218 return 0;
221 //////////////////////////////////////////////////////////////////////
224 PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(
225 Window * pParent,
226 sal_uInt16 nMinPasswdLen,
227 sal_uInt16 nMaxPasswdLen,
228 bool bIsPasswordToModify ) :
229 SfxModalDialog( pParent, CUI_RES( RID_DLG_PASSWORD_TO_OPEN_MODIFY ) )
231 m_pImpl = std::auto_ptr< PasswordToOpenModifyDialog_Impl >(
232 new PasswordToOpenModifyDialog_Impl( this, nMinPasswdLen, nMaxPasswdLen, bIsPasswordToModify ) );
234 FreeResource();
238 PasswordToOpenModifyDialog::~PasswordToOpenModifyDialog()
243 String PasswordToOpenModifyDialog::GetPasswordToOpen() const
245 const bool bPasswdOk =
246 !m_pImpl->m_aPasswdToOpenED.GetText().isEmpty() &&
247 m_pImpl->m_aPasswdToOpenED.GetText() == m_pImpl->m_aReenterPasswdToOpenED.GetText();
248 return bPasswdOk ? m_pImpl->m_aPasswdToOpenED.GetText() : OUString();
252 String PasswordToOpenModifyDialog::GetPasswordToModify() const
254 const bool bPasswdOk =
255 !m_pImpl->m_aPasswdToModifyED.GetText().isEmpty() &&
256 m_pImpl->m_aPasswdToModifyED.GetText() == m_pImpl->m_aReenterPasswdToModifyED.GetText();
257 return bPasswdOk ? m_pImpl->m_aPasswdToModifyED.GetText() : OUString();
261 bool PasswordToOpenModifyDialog::IsRecommendToOpenReadonly() const
263 return m_pImpl->m_aOpenReadonlyCB.IsChecked();
267 //////////////////////////////////////////////////////////////////////
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */