merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / dialogs / logindlg.cxx
blob2071c5edd1db7ed3071b10c7a95be3498360bffc
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.10 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <filedlg.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <svtools/logindlg.hxx>
37 #ifndef _SVTOOLS_LOGINDLG_HRC_
38 #include "logindlg.hrc"
39 #endif
40 #ifndef _SVTOOLS_HRC
41 #include <svtools/svtools.hrc>
42 #endif
43 #include <svtools/svtdata.hxx>
45 #ifdef UNX
46 #include <limits.h>
47 #define _MAX_PATH PATH_MAX
48 #endif
50 // LoginDialog -------------------------------------------------------
52 //............................................................................
53 namespace svt
55 //............................................................................
57 void LoginDialog::HideControls_Impl( USHORT nFlags )
59 FASTBOOL bPathHide = FALSE;
60 FASTBOOL bErrorHide = FALSE;
61 FASTBOOL bAccountHide = FALSE;
63 if ( ( nFlags & LF_NO_PATH ) == LF_NO_PATH )
65 aPathFT.Hide();
66 aPathED.Hide();
67 aPathBtn.Hide();
68 bPathHide = TRUE;
70 else if ( ( nFlags & LF_PATH_READONLY ) == LF_PATH_READONLY )
72 aPathED.Hide();
73 aPathInfo.Show();
74 aPathBtn.Hide();
77 if ( ( nFlags & LF_NO_USERNAME ) == LF_NO_USERNAME )
79 aNameFT.Hide();
80 aNameED.Hide();
82 else if ( ( nFlags & LF_USERNAME_READONLY ) == LF_USERNAME_READONLY )
84 aNameED.Hide();
85 aNameInfo.Show();
88 if ( ( nFlags & LF_NO_PASSWORD ) == LF_NO_PASSWORD )
90 aPasswordFT.Hide();
91 aPasswordED.Hide();
94 if ( ( nFlags & LF_NO_SAVEPASSWORD ) == LF_NO_SAVEPASSWORD )
95 aSavePasswdBtn.Hide();
97 if ( ( nFlags & LF_NO_ERRORTEXT ) == LF_NO_ERRORTEXT )
99 aErrorInfo.Hide();
100 aErrorGB.Hide();
101 bErrorHide = TRUE;
104 if ( ( nFlags & LF_NO_ACCOUNT ) == LF_NO_ACCOUNT )
106 aAccountFT.Hide();
107 aAccountED.Hide();
108 bAccountHide = TRUE;
111 if ( bErrorHide )
113 long nOffset = aLoginGB.GetPosPixel().Y() -
114 aErrorGB.GetPosPixel().Y();
115 Point aNewPnt = aRequestInfo.GetPosPixel();
116 aNewPnt.Y() -= nOffset;
117 aRequestInfo.SetPosPixel( aNewPnt );
118 aNewPnt = aPathFT.GetPosPixel();
119 aNewPnt.Y() -= nOffset;
120 aPathFT.SetPosPixel( aNewPnt );
121 aNewPnt = aPathED.GetPosPixel();
122 aNewPnt.Y() -= nOffset;
123 aPathED.SetPosPixel( aNewPnt );
124 aNewPnt = aPathInfo.GetPosPixel();
125 aNewPnt.Y() -= nOffset;
126 aPathInfo.SetPosPixel( aNewPnt );
127 aNewPnt = aPathBtn.GetPosPixel();
128 aNewPnt.Y() -= nOffset;
129 aPathBtn.SetPosPixel( aNewPnt );
130 aNewPnt = aNameFT.GetPosPixel();
131 aNewPnt.Y() -= nOffset;
132 aNameFT.SetPosPixel( aNewPnt );
133 aNewPnt = aNameED.GetPosPixel();
134 aNewPnt.Y() -= nOffset;
135 aNameED.SetPosPixel( aNewPnt );
136 aNewPnt = aNameInfo.GetPosPixel();
137 aNewPnt.Y() -= nOffset;
138 aNameInfo.SetPosPixel( aNewPnt );
139 aNewPnt = aPasswordFT.GetPosPixel();
140 aNewPnt.Y() -= nOffset;
141 aPasswordFT.SetPosPixel( aNewPnt );
142 aNewPnt = aPasswordED.GetPosPixel();
143 aNewPnt.Y() -= nOffset;
144 aPasswordED.SetPosPixel( aNewPnt );
145 aNewPnt = aAccountFT.GetPosPixel();
146 aNewPnt.Y() -= nOffset;
147 aAccountFT.SetPosPixel( aNewPnt );
148 aNewPnt = aAccountED.GetPosPixel();
149 aNewPnt.Y() -= nOffset;
150 aAccountED.SetPosPixel( aNewPnt );
151 aNewPnt = aSavePasswdBtn.GetPosPixel();
152 aNewPnt.Y() -= nOffset;
153 aSavePasswdBtn.SetPosPixel( aNewPnt );
154 aNewPnt = aLoginGB.GetPosPixel();
155 aNewPnt.Y() -= nOffset;
156 aLoginGB.SetPosPixel( aNewPnt );
157 Size aNewSiz = GetSizePixel();
158 aNewSiz.Height() -= nOffset;
159 SetSizePixel( aNewSiz );
162 if ( bPathHide )
164 long nOffset = aNameED.GetPosPixel().Y() -
165 aPathED.GetPosPixel().Y();
167 Point aTmpPnt1 = aNameFT.GetPosPixel();
168 Point aTmpPnt2 = aPasswordFT.GetPosPixel();
169 aNameFT.SetPosPixel( aPathFT.GetPosPixel() );
170 aPasswordFT.SetPosPixel( aTmpPnt1 );
171 aAccountFT.SetPosPixel( aTmpPnt2 );
172 aTmpPnt1 = aNameED.GetPosPixel();
173 aTmpPnt2 = aPasswordED.GetPosPixel();
174 aNameED.SetPosPixel( aPathED.GetPosPixel() );
175 aPasswordED.SetPosPixel( aTmpPnt1 );
176 aAccountED.SetPosPixel( aTmpPnt2 );
177 aNameInfo.SetPosPixel( aPathInfo.GetPosPixel() );
178 aTmpPnt1 = aSavePasswdBtn.GetPosPixel();
179 aTmpPnt1.Y() -= nOffset;
180 aSavePasswdBtn.SetPosPixel( aTmpPnt1 );
181 Size aNewSz = GetSizePixel();
182 aNewSz.Height() -= nOffset;
183 SetSizePixel( aNewSz );
186 if ( bAccountHide )
188 long nOffset = aAccountED.GetPosPixel().Y() - aPasswordED.GetPosPixel().Y();
190 Point aTmpPnt = aSavePasswdBtn.GetPosPixel();
191 aTmpPnt.Y() -= nOffset;
192 aSavePasswdBtn.SetPosPixel( aTmpPnt );
193 Size aNewSz = GetSizePixel();
194 aNewSz.Height() -= nOffset;
195 SetSizePixel( aNewSz );
199 // -----------------------------------------------------------------------
201 IMPL_LINK( LoginDialog, OKHdl_Impl, OKButton *, EMPTYARG )
203 // trim the strings
204 aNameED.SetText( aNameED.GetText().EraseLeadingChars().
205 EraseTrailingChars() );
206 aPasswordED.SetText( aPasswordED.GetText().EraseLeadingChars().
207 EraseTrailingChars() );
208 EndDialog( RET_OK );
209 return 1;
212 // -----------------------------------------------------------------------
214 IMPL_LINK( LoginDialog, PathHdl_Impl, PushButton *, EMPTYARG )
216 PathDialog* pDlg = new PathDialog( this, WB_3DLOOK );
217 // DirEntry aEntry;
218 // aEntry.ToAbs();
219 // pDlg->SetPath( aEntry.GetFull() );
221 if ( pDlg->Execute() == RET_OK )
222 aPathED.SetText( pDlg->GetPath() );
224 delete pDlg;
225 return 1;
228 // -----------------------------------------------------------------------
230 LoginDialog::LoginDialog
232 Window* pParent,
233 USHORT nFlags,
234 const String& rServer,
235 const String* pRealm
238 ModalDialog( pParent, SvtResId( DLG_LOGIN ) ),
240 aErrorInfo ( this, SvtResId( INFO_LOGIN_ERROR ) ),
241 aErrorGB ( this, SvtResId( GB_LOGIN_ERROR ) ),
242 aRequestInfo ( this, SvtResId( INFO_LOGIN_REQUEST ) ),
243 aPathFT ( this, SvtResId( FT_LOGIN_PATH ) ),
244 aPathED ( this, SvtResId( ED_LOGIN_PATH ) ),
245 aPathInfo ( this, SvtResId( INFO_LOGIN_PATH ) ),
246 aPathBtn ( this, SvtResId( BTN_LOGIN_PATH ) ),
247 aNameFT ( this, SvtResId( FT_LOGIN_USERNAME ) ),
248 aNameED ( this, SvtResId( ED_LOGIN_USERNAME ) ),
249 aNameInfo ( this, SvtResId( INFO_LOGIN_USERNAME ) ),
250 aPasswordFT ( this, SvtResId( FT_LOGIN_PASSWORD ) ),
251 aPasswordED ( this, SvtResId( ED_LOGIN_PASSWORD ) ),
252 aAccountFT ( this, SvtResId( FT_LOGIN_ACCOUNT ) ),
253 aAccountED ( this, SvtResId( ED_LOGIN_ACCOUNT ) ),
254 aSavePasswdBtn ( this, SvtResId( CB_LOGIN_SAVEPASSWORD ) ),
255 aLoginGB ( this, SvtResId( GB_LOGIN_LOGIN ) ),
256 aOKBtn ( this, SvtResId( BTN_LOGIN_OK ) ),
257 aCancelBtn ( this, SvtResId( BTN_LOGIN_CANCEL ) ),
258 aHelpBtn ( this, SvtResId( BTN_LOGIN_HELP ) )
261 // Einlog-Ort eintragen
262 String aServer;
264 if ( ( ( nFlags & LF_NO_ACCOUNT ) == LF_NO_ACCOUNT ) && pRealm && pRealm->Len() )
266 aServer = *pRealm;
267 ( ( aServer += ' ' ) += String( SvtResId( STR_LOGIN_AT ) ) ) += ' ';
269 aServer += rServer;
270 String aTxt = aRequestInfo.GetText();
271 aTxt.SearchAndReplaceAscii( "%1", aServer );
272 aRequestInfo.SetText( aTxt );
274 FreeResource();
276 aPathED.SetMaxTextLen( _MAX_PATH );
277 aNameED.SetMaxTextLen( _MAX_PATH );
279 aOKBtn.SetClickHdl( LINK( this, LoginDialog, OKHdl_Impl ) );
280 aPathBtn.SetClickHdl( LINK( this, LoginDialog, PathHdl_Impl ) );
282 HideControls_Impl( nFlags );
285 // -----------------------------------------------------------------------
287 void LoginDialog::SetName( const String& rNewName )
289 aNameED.SetText( rNewName );
290 aNameInfo.SetText( rNewName );
293 // -----------------------------------------------------------------------
295 void LoginDialog::ClearPassword()
297 aPasswordED.SetText( String() );
299 if ( 0 == aNameED.GetText().Len() )
300 aNameED.GrabFocus();
301 else
302 aPasswordED.GrabFocus();
305 // -----------------------------------------------------------------------
307 void LoginDialog::ClearAccount()
309 aAccountED.SetText( String() );
310 aAccountED.GrabFocus();
313 //............................................................................
314 } // namespace svt
315 //............................................................................