merge the formfield patch from ooo-build
[ooovba.git] / uui / source / logindlg.cxx
blob99bbfac627a45d05b81456aa10031c871b546eb3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: logindlg.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <svtools/filedlg.hxx>
32 #include <vcl/msgbox.hxx>
33 #include "logindlg.hxx"
35 #ifndef UUI_LOGINDLG_HRC
36 #include "logindlg.hrc"
37 #endif
38 #ifndef UUI_IDS_HRC
39 #include "ids.hrc"
40 #endif
41 #include <tools/resid.hxx>
43 #ifdef UNX
44 #include <limits.h>
45 #define _MAX_PATH PATH_MAX
46 #endif
48 // LoginDialog -------------------------------------------------------
50 //............................................................................
51 //............................................................................
53 void LoginDialog::HideControls_Impl( USHORT nFlags )
55 FASTBOOL bPathHide = FALSE;
56 FASTBOOL bErrorHide = FALSE;
57 FASTBOOL bAccountHide = FALSE;
58 FASTBOOL bUseSysCredsHide = FALSE;
60 if ( ( nFlags & LF_NO_PATH ) == LF_NO_PATH )
62 aPathFT.Hide();
63 aPathED.Hide();
64 aPathBtn.Hide();
65 bPathHide = TRUE;
67 else if ( ( nFlags & LF_PATH_READONLY ) == LF_PATH_READONLY )
69 aPathED.Hide();
70 aPathInfo.Show();
71 aPathBtn.Hide();
74 if ( ( nFlags & LF_NO_USERNAME ) == LF_NO_USERNAME )
76 aNameFT.Hide();
77 aNameED.Hide();
79 else if ( ( nFlags & LF_USERNAME_READONLY ) == LF_USERNAME_READONLY )
81 aNameED.Hide();
82 aNameInfo.Show();
85 if ( ( nFlags & LF_NO_PASSWORD ) == LF_NO_PASSWORD )
87 aPasswordFT.Hide();
88 aPasswordED.Hide();
91 if ( ( nFlags & LF_NO_SAVEPASSWORD ) == LF_NO_SAVEPASSWORD )
92 aSavePasswdBtn.Hide();
94 if ( ( nFlags & LF_NO_ERRORTEXT ) == LF_NO_ERRORTEXT )
96 aErrorInfo.Hide();
97 aErrorGB.Hide();
98 bErrorHide = TRUE;
101 if ( ( nFlags & LF_NO_ACCOUNT ) == LF_NO_ACCOUNT )
103 aAccountFT.Hide();
104 aAccountED.Hide();
105 bAccountHide = TRUE;
108 if ( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS )
110 aUseSysCredsCB.Hide();
111 bUseSysCredsHide = TRUE;
114 if ( bErrorHide )
116 long nOffset = aLoginGB.GetPosPixel().Y() -
117 aErrorGB.GetPosPixel().Y();
118 Point aNewPnt = aRequestInfo.GetPosPixel();
119 aNewPnt.Y() -= nOffset;
120 aRequestInfo.SetPosPixel( aNewPnt );
121 aNewPnt = aPathFT.GetPosPixel();
122 aNewPnt.Y() -= nOffset;
123 aPathFT.SetPosPixel( aNewPnt );
124 aNewPnt = aPathED.GetPosPixel();
125 aNewPnt.Y() -= nOffset;
126 aPathED.SetPosPixel( aNewPnt );
127 aNewPnt = aPathInfo.GetPosPixel();
128 aNewPnt.Y() -= nOffset;
129 aPathInfo.SetPosPixel( aNewPnt );
130 aNewPnt = aPathBtn.GetPosPixel();
131 aNewPnt.Y() -= nOffset;
132 aPathBtn.SetPosPixel( aNewPnt );
133 aNewPnt = aNameFT.GetPosPixel();
134 aNewPnt.Y() -= nOffset;
135 aNameFT.SetPosPixel( aNewPnt );
136 aNewPnt = aNameED.GetPosPixel();
137 aNewPnt.Y() -= nOffset;
138 aNameED.SetPosPixel( aNewPnt );
139 aNewPnt = aNameInfo.GetPosPixel();
140 aNewPnt.Y() -= nOffset;
141 aNameInfo.SetPosPixel( aNewPnt );
142 aNewPnt = aPasswordFT.GetPosPixel();
143 aNewPnt.Y() -= nOffset;
144 aPasswordFT.SetPosPixel( aNewPnt );
145 aNewPnt = aPasswordED.GetPosPixel();
146 aNewPnt.Y() -= nOffset;
147 aPasswordED.SetPosPixel( aNewPnt );
148 aNewPnt = aAccountFT.GetPosPixel();
149 aNewPnt.Y() -= nOffset;
150 aAccountFT.SetPosPixel( aNewPnt );
151 aNewPnt = aAccountED.GetPosPixel();
152 aNewPnt.Y() -= nOffset;
153 aAccountED.SetPosPixel( aNewPnt );
154 aNewPnt = aSavePasswdBtn.GetPosPixel();
155 aNewPnt.Y() -= nOffset;
156 aSavePasswdBtn.SetPosPixel( aNewPnt );
157 aNewPnt = aUseSysCredsCB.GetPosPixel();
158 aNewPnt.Y() -= nOffset;
159 aUseSysCredsCB.SetPosPixel( aNewPnt );
160 aNewPnt = aLoginGB.GetPosPixel();
161 aNewPnt.Y() -= nOffset;
162 aLoginGB.SetPosPixel( aNewPnt );
163 Size aNewSiz = GetSizePixel();
164 aNewSiz.Height() -= nOffset;
165 SetSizePixel( aNewSiz );
168 if ( bPathHide )
170 long nOffset = aNameED.GetPosPixel().Y() -
171 aPathED.GetPosPixel().Y();
173 Point aTmpPnt1 = aNameFT.GetPosPixel();
174 Point aTmpPnt2 = aPasswordFT.GetPosPixel();
175 aNameFT.SetPosPixel( aPathFT.GetPosPixel() );
176 aPasswordFT.SetPosPixel( aTmpPnt1 );
177 aAccountFT.SetPosPixel( aTmpPnt2 );
178 aTmpPnt1 = aNameED.GetPosPixel();
179 aTmpPnt2 = aPasswordED.GetPosPixel();
180 aNameED.SetPosPixel( aPathED.GetPosPixel() );
181 aPasswordED.SetPosPixel( aTmpPnt1 );
182 aAccountED.SetPosPixel( aTmpPnt2 );
183 aNameInfo.SetPosPixel( aPathInfo.GetPosPixel() );
184 aTmpPnt1 = aSavePasswdBtn.GetPosPixel();
185 aTmpPnt1.Y() -= nOffset;
186 aSavePasswdBtn.SetPosPixel( aTmpPnt1 );
187 aTmpPnt1 = aUseSysCredsCB.GetPosPixel();
188 aTmpPnt1.Y() -= nOffset;
189 aUseSysCredsCB.SetPosPixel( aTmpPnt1 );
190 Size aNewSz = GetSizePixel();
191 aNewSz.Height() -= nOffset;
192 SetSizePixel( aNewSz );
195 if ( bAccountHide )
197 long nOffset = aAccountED.GetPosPixel().Y() - aPasswordED.GetPosPixel().Y();
199 Point aTmpPnt = aSavePasswdBtn.GetPosPixel();
200 aTmpPnt.Y() -= nOffset;
201 aSavePasswdBtn.SetPosPixel( aTmpPnt );
202 aTmpPnt = aUseSysCredsCB.GetPosPixel();
203 aTmpPnt.Y() -= nOffset;
204 aUseSysCredsCB.SetPosPixel( aTmpPnt );
205 Size aNewSz = GetSizePixel();
206 aNewSz.Height() -= nOffset;
207 SetSizePixel( aNewSz );
210 if ( bUseSysCredsHide )
212 long nOffset = aUseSysCredsCB.GetPosPixel().Y() -
213 aSavePasswdBtn.GetPosPixel().Y();
215 Size aNewSz = GetSizePixel();
216 aNewSz.Height() -= nOffset;
217 SetSizePixel( aNewSz );
221 // -----------------------------------------------------------------------
222 void LoginDialog::EnableUseSysCredsControls_Impl( BOOL bUseSysCredsEnabled )
224 aErrorInfo.Enable( !bUseSysCredsEnabled );
225 aErrorGB.Enable( !bUseSysCredsEnabled );
226 aRequestInfo.Enable( !bUseSysCredsEnabled );
227 aPathFT.Enable( !bUseSysCredsEnabled );
228 aPathED.Enable( !bUseSysCredsEnabled );
229 aPathInfo.Enable( !bUseSysCredsEnabled );
230 aPathBtn.Enable( !bUseSysCredsEnabled );
231 aNameFT.Enable( !bUseSysCredsEnabled );
232 aNameED.Enable( !bUseSysCredsEnabled );
233 aNameInfo.Enable( !bUseSysCredsEnabled );
234 aPasswordFT.Enable( !bUseSysCredsEnabled );
235 aPasswordED.Enable( !bUseSysCredsEnabled );
236 aAccountFT.Enable( !bUseSysCredsEnabled );
237 aAccountED.Enable( !bUseSysCredsEnabled );
240 // -----------------------------------------------------------------------
242 IMPL_LINK( LoginDialog, OKHdl_Impl, OKButton *, EMPTYARG )
244 // trim the strings
245 aNameED.SetText( aNameED.GetText().EraseLeadingChars().
246 EraseTrailingChars() );
247 aPasswordED.SetText( aPasswordED.GetText().EraseLeadingChars().
248 EraseTrailingChars() );
249 EndDialog( RET_OK );
250 return 1;
253 // -----------------------------------------------------------------------
255 IMPL_LINK( LoginDialog, PathHdl_Impl, PushButton *, EMPTYARG )
257 PathDialog* pDlg = new PathDialog( this, WB_3DLOOK );
258 pDlg->SetPath( aPathED.GetText() );
260 if ( pDlg->Execute() == RET_OK )
261 aPathED.SetText( pDlg->GetPath() );
263 delete pDlg;
264 return 1;
267 // -----------------------------------------------------------------------
269 IMPL_LINK( LoginDialog, UseSysCredsHdl_Impl, CheckBox *, EMPTYARG )
271 EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
272 return 1;
275 // -----------------------------------------------------------------------
277 LoginDialog::LoginDialog
279 Window* pParent,
280 USHORT nFlags,
281 const String& rServer,
282 const String* pRealm,
283 ResMgr* pResMgr
286 ModalDialog( pParent, ResId( DLG_UUI_LOGIN, *pResMgr ) ),
288 aErrorInfo ( this, ResId( INFO_LOGIN_ERROR, *pResMgr ) ),
289 aErrorGB ( this, ResId( GB_LOGIN_ERROR, *pResMgr ) ),
290 aRequestInfo ( this, ResId( INFO_LOGIN_REQUEST, *pResMgr ) ),
291 aPathFT ( this, ResId( FT_LOGIN_PATH, *pResMgr ) ),
292 aPathED ( this, ResId( ED_LOGIN_PATH, *pResMgr ) ),
293 aPathInfo ( this, ResId( INFO_LOGIN_PATH, *pResMgr ) ),
294 aPathBtn ( this, ResId( BTN_LOGIN_PATH, *pResMgr ) ),
295 aNameFT ( this, ResId( FT_LOGIN_USERNAME, *pResMgr ) ),
296 aNameED ( this, ResId( ED_LOGIN_USERNAME, *pResMgr ) ),
297 aNameInfo ( this, ResId( INFO_LOGIN_USERNAME, *pResMgr ) ),
298 aPasswordFT ( this, ResId( FT_LOGIN_PASSWORD, *pResMgr ) ),
299 aPasswordED ( this, ResId( ED_LOGIN_PASSWORD, *pResMgr ) ),
300 aAccountFT ( this, ResId( FT_LOGIN_ACCOUNT, *pResMgr ) ),
301 aAccountED ( this, ResId( ED_LOGIN_ACCOUNT, *pResMgr ) ),
302 aSavePasswdBtn ( this, ResId( CB_LOGIN_SAVEPASSWORD, *pResMgr ) ),
303 aUseSysCredsCB ( this, ResId( CB_LOGIN_USESYSCREDS, *pResMgr ) ),
304 aLoginGB ( this, ResId( GB_LOGIN_LOGIN, *pResMgr ) ),
305 aOKBtn ( this, ResId( BTN_LOGIN_OK, *pResMgr ) ),
306 aCancelBtn ( this, ResId( BTN_LOGIN_CANCEL, *pResMgr ) ),
307 aHelpBtn ( this, ResId( BTN_LOGIN_HELP, *pResMgr ) )
310 UniString aRequest;
311 if ((nFlags & LF_NO_ACCOUNT) != 0 && pRealm && pRealm->Len() != 0)
313 aRequest = ResId(STR_LOGIN_REALM, *pResMgr);
314 aRequest.SearchAndReplaceAscii("%2", *pRealm);
316 else
317 aRequest = aRequestInfo.GetText();
319 if ( !( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS ) )
320 EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
322 aRequest.SearchAndReplaceAscii("%1", rServer);
323 aRequestInfo.SetText(aRequest);
325 FreeResource();
327 aPathED.SetMaxTextLen( _MAX_PATH );
328 aNameED.SetMaxTextLen( _MAX_PATH );
330 aOKBtn.SetClickHdl( LINK( this, LoginDialog, OKHdl_Impl ) );
331 aPathBtn.SetClickHdl( LINK( this, LoginDialog, PathHdl_Impl ) );
332 aUseSysCredsCB.SetClickHdl( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
334 HideControls_Impl( nFlags );
337 // -----------------------------------------------------------------------
339 void LoginDialog::SetName( const String& rNewName )
341 aNameED.SetText( rNewName );
342 aNameInfo.SetText( rNewName );
345 // -----------------------------------------------------------------------
347 void LoginDialog::SetUseSystemCredentials( BOOL bUse )
349 if ( aUseSysCredsCB.IsVisible() )
351 aUseSysCredsCB.Check( bUse );
352 EnableUseSysCredsControls_Impl( bUse );
356 // -----------------------------------------------------------------------
358 void LoginDialog::ClearPassword()
360 aPasswordED.SetText( String() );
362 if ( 0 == aNameED.GetText().Len() )
363 aNameED.GrabFocus();
364 else
365 aPasswordED.GrabFocus();
368 // -----------------------------------------------------------------------
370 void LoginDialog::ClearAccount()
372 aAccountED.SetText( String() );
373 aAccountED.GrabFocus();
376 //............................................................................
377 //............................................................................