1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: logindlg.cxx,v $
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"
41 #include <tools/resid.hxx>
45 #define _MAX_PATH PATH_MAX
48 // LoginDialog -------------------------------------------------------
50 //............................................................................
51 //............................................................................
53 void LoginDialog::HideControls_Impl( USHORT nFlags
)
55 FASTBOOL bPathHide
= FALSE
;
56 FASTBOOL bErrorHide
= FALSE
;
57 FASTBOOL bAccountHide
= FALSE
;
59 if ( ( nFlags
& LF_NO_PATH
) == LF_NO_PATH
)
66 else if ( ( nFlags
& LF_PATH_READONLY
) == LF_PATH_READONLY
)
73 if ( ( nFlags
& LF_NO_USERNAME
) == LF_NO_USERNAME
)
78 else if ( ( nFlags
& LF_USERNAME_READONLY
) == LF_USERNAME_READONLY
)
84 if ( ( nFlags
& LF_NO_PASSWORD
) == LF_NO_PASSWORD
)
90 if ( ( nFlags
& LF_NO_SAVEPASSWORD
) == LF_NO_SAVEPASSWORD
)
91 aSavePasswdBtn
.Hide();
93 if ( ( nFlags
& LF_NO_ERRORTEXT
) == LF_NO_ERRORTEXT
)
100 if ( ( nFlags
& LF_NO_ACCOUNT
) == LF_NO_ACCOUNT
)
109 long nOffset
= aLoginGB
.GetPosPixel().Y() -
110 aErrorGB
.GetPosPixel().Y();
111 Point aNewPnt
= aRequestInfo
.GetPosPixel();
112 aNewPnt
.Y() -= nOffset
;
113 aRequestInfo
.SetPosPixel( aNewPnt
);
114 aNewPnt
= aPathFT
.GetPosPixel();
115 aNewPnt
.Y() -= nOffset
;
116 aPathFT
.SetPosPixel( aNewPnt
);
117 aNewPnt
= aPathED
.GetPosPixel();
118 aNewPnt
.Y() -= nOffset
;
119 aPathED
.SetPosPixel( aNewPnt
);
120 aNewPnt
= aPathInfo
.GetPosPixel();
121 aNewPnt
.Y() -= nOffset
;
122 aPathInfo
.SetPosPixel( aNewPnt
);
123 aNewPnt
= aPathBtn
.GetPosPixel();
124 aNewPnt
.Y() -= nOffset
;
125 aPathBtn
.SetPosPixel( aNewPnt
);
126 aNewPnt
= aNameFT
.GetPosPixel();
127 aNewPnt
.Y() -= nOffset
;
128 aNameFT
.SetPosPixel( aNewPnt
);
129 aNewPnt
= aNameED
.GetPosPixel();
130 aNewPnt
.Y() -= nOffset
;
131 aNameED
.SetPosPixel( aNewPnt
);
132 aNewPnt
= aNameInfo
.GetPosPixel();
133 aNewPnt
.Y() -= nOffset
;
134 aNameInfo
.SetPosPixel( aNewPnt
);
135 aNewPnt
= aPasswordFT
.GetPosPixel();
136 aNewPnt
.Y() -= nOffset
;
137 aPasswordFT
.SetPosPixel( aNewPnt
);
138 aNewPnt
= aPasswordED
.GetPosPixel();
139 aNewPnt
.Y() -= nOffset
;
140 aPasswordED
.SetPosPixel( aNewPnt
);
141 aNewPnt
= aAccountFT
.GetPosPixel();
142 aNewPnt
.Y() -= nOffset
;
143 aAccountFT
.SetPosPixel( aNewPnt
);
144 aNewPnt
= aAccountED
.GetPosPixel();
145 aNewPnt
.Y() -= nOffset
;
146 aAccountED
.SetPosPixel( aNewPnt
);
147 aNewPnt
= aSavePasswdBtn
.GetPosPixel();
148 aNewPnt
.Y() -= nOffset
;
149 aSavePasswdBtn
.SetPosPixel( aNewPnt
);
150 aNewPnt
= aLoginGB
.GetPosPixel();
151 aNewPnt
.Y() -= nOffset
;
152 aLoginGB
.SetPosPixel( aNewPnt
);
153 Size aNewSiz
= GetSizePixel();
154 aNewSiz
.Height() -= nOffset
;
155 SetSizePixel( aNewSiz
);
160 long nOffset
= aNameED
.GetPosPixel().Y() -
161 aPathED
.GetPosPixel().Y();
163 Point aTmpPnt1
= aNameFT
.GetPosPixel();
164 Point aTmpPnt2
= aPasswordFT
.GetPosPixel();
165 aNameFT
.SetPosPixel( aPathFT
.GetPosPixel() );
166 aPasswordFT
.SetPosPixel( aTmpPnt1
);
167 aAccountFT
.SetPosPixel( aTmpPnt2
);
168 aTmpPnt1
= aNameED
.GetPosPixel();
169 aTmpPnt2
= aPasswordED
.GetPosPixel();
170 aNameED
.SetPosPixel( aPathED
.GetPosPixel() );
171 aPasswordED
.SetPosPixel( aTmpPnt1
);
172 aAccountED
.SetPosPixel( aTmpPnt2
);
173 aNameInfo
.SetPosPixel( aPathInfo
.GetPosPixel() );
174 aTmpPnt1
= aSavePasswdBtn
.GetPosPixel();
175 aTmpPnt1
.Y() -= nOffset
;
176 aSavePasswdBtn
.SetPosPixel( aTmpPnt1
);
177 Size aNewSz
= GetSizePixel();
178 aNewSz
.Height() -= nOffset
;
179 SetSizePixel( aNewSz
);
184 long nOffset
= aAccountED
.GetPosPixel().Y() - aPasswordED
.GetPosPixel().Y();
186 Point aTmpPnt
= aSavePasswdBtn
.GetPosPixel();
187 aTmpPnt
.Y() -= nOffset
;
188 aSavePasswdBtn
.SetPosPixel( aTmpPnt
);
189 Size aNewSz
= GetSizePixel();
190 aNewSz
.Height() -= nOffset
;
191 SetSizePixel( aNewSz
);
195 // -----------------------------------------------------------------------
197 IMPL_LINK( LoginDialog
, OKHdl_Impl
, OKButton
*, EMPTYARG
)
200 aNameED
.SetText( aNameED
.GetText().EraseLeadingChars().
201 EraseTrailingChars() );
202 aPasswordED
.SetText( aPasswordED
.GetText().EraseLeadingChars().
203 EraseTrailingChars() );
208 // -----------------------------------------------------------------------
210 IMPL_LINK( LoginDialog
, PathHdl_Impl
, PushButton
*, EMPTYARG
)
212 PathDialog
* pDlg
= new PathDialog( this, WB_3DLOOK
);
213 pDlg
->SetPath( aPathED
.GetText() );
215 if ( pDlg
->Execute() == RET_OK
)
216 aPathED
.SetText( pDlg
->GetPath() );
222 // -----------------------------------------------------------------------
224 LoginDialog::LoginDialog
228 const String
& rServer
,
229 const String
* pRealm
,
233 ModalDialog( pParent
, ResId( DLG_UUI_LOGIN
, *pResMgr
) ),
235 aErrorInfo ( this, ResId( INFO_LOGIN_ERROR
, *pResMgr
) ),
236 aErrorGB ( this, ResId( GB_LOGIN_ERROR
, *pResMgr
) ),
237 aRequestInfo ( this, ResId( INFO_LOGIN_REQUEST
, *pResMgr
) ),
238 aPathFT ( this, ResId( FT_LOGIN_PATH
, *pResMgr
) ),
239 aPathED ( this, ResId( ED_LOGIN_PATH
, *pResMgr
) ),
240 aPathInfo ( this, ResId( INFO_LOGIN_PATH
, *pResMgr
) ),
241 aPathBtn ( this, ResId( BTN_LOGIN_PATH
, *pResMgr
) ),
242 aNameFT ( this, ResId( FT_LOGIN_USERNAME
, *pResMgr
) ),
243 aNameED ( this, ResId( ED_LOGIN_USERNAME
, *pResMgr
) ),
244 aNameInfo ( this, ResId( INFO_LOGIN_USERNAME
, *pResMgr
) ),
245 aPasswordFT ( this, ResId( FT_LOGIN_PASSWORD
, *pResMgr
) ),
246 aPasswordED ( this, ResId( ED_LOGIN_PASSWORD
, *pResMgr
) ),
247 aAccountFT ( this, ResId( FT_LOGIN_ACCOUNT
, *pResMgr
) ),
248 aAccountED ( this, ResId( ED_LOGIN_ACCOUNT
, *pResMgr
) ),
249 aSavePasswdBtn ( this, ResId( CB_LOGIN_SAVEPASSWORD
, *pResMgr
) ),
250 aLoginGB ( this, ResId( GB_LOGIN_LOGIN
, *pResMgr
) ),
251 aOKBtn ( this, ResId( BTN_LOGIN_OK
, *pResMgr
) ),
252 aCancelBtn ( this, ResId( BTN_LOGIN_CANCEL
, *pResMgr
) ),
253 aHelpBtn ( this, ResId( BTN_LOGIN_HELP
, *pResMgr
) )
257 if ((nFlags
& LF_NO_ACCOUNT
) != 0 && pRealm
&& pRealm
->Len() != 0)
259 aRequest
= ResId(STR_LOGIN_REALM
, *pResMgr
);
260 aRequest
.SearchAndReplaceAscii("%2", *pRealm
);
263 aRequest
= aRequestInfo
.GetText();
264 aRequest
.SearchAndReplaceAscii("%1", rServer
);
265 aRequestInfo
.SetText(aRequest
);
269 aPathED
.SetMaxTextLen( _MAX_PATH
);
270 aNameED
.SetMaxTextLen( _MAX_PATH
);
272 aOKBtn
.SetClickHdl( LINK( this, LoginDialog
, OKHdl_Impl
) );
273 aPathBtn
.SetClickHdl( LINK( this, LoginDialog
, PathHdl_Impl
) );
275 HideControls_Impl( nFlags
);
278 // -----------------------------------------------------------------------
280 void LoginDialog::SetName( const String
& rNewName
)
282 aNameED
.SetText( rNewName
);
283 aNameInfo
.SetText( rNewName
);
286 // -----------------------------------------------------------------------
288 void LoginDialog::ClearPassword()
290 aPasswordED
.SetText( String() );
292 if ( 0 == aNameED
.GetText().Len() )
295 aPasswordED
.GrabFocus();
298 // -----------------------------------------------------------------------
300 void LoginDialog::ClearAccount()
302 aAccountED
.SetText( String() );
303 aAccountED
.GrabFocus();
306 //............................................................................
307 //............................................................................