1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003 - Tim Kemp and Stefan Kueng
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software
\r
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
19 #include "LoginDialog.h"
\r
20 #include "TortoisePlinkRes.h"
\r
23 HINSTANCE g_hmodThisDll;
\r
29 LoginDialog(const std::string& prompt);
\r
31 static bool DoLoginDialog(std::string& password, const std::string& prompt);
\r
37 std::string myPassword;
\r
38 std::string myPrompt;
\r
40 void CreateModule(void);
\r
41 void RetrieveValues();
\r
43 std::string GetPassword();
\r
45 friend BOOL CALLBACK LoginDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
\r
49 BOOL DoLoginDialog(char* password, int maxlen, const char* prompt)
\r
51 g_hmodThisDll = GetModuleHandle(0);
\r
52 g_hwndMain = GetParentHwnd();
\r
53 std::string passwordstr;
\r
54 BOOL res = LoginDialog::DoLoginDialog(passwordstr, prompt);
\r
56 strncpy(password, passwordstr.c_str(), maxlen);
\r
61 BOOL CALLBACK LoginDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
63 if (uMsg == WM_INITDIALOG)
\r
65 LoginDialog* pDlg = (LoginDialog*) lParam;
\r
66 pDlg->_hdlg = hwndDlg;
\r
67 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
\r
69 SendDlgItemMessage(hwndDlg, IDC_LOGIN_PROMPT, WM_SETTEXT,
\r
70 pDlg->myPrompt.length(), (LPARAM) pDlg->myPrompt.c_str());
\r
71 // Make sure edit control has the focus
\r
72 //SendDlgItemMessage(hwndDlg, IDC_LOGIN_PASSWORD, WM_SETFOCUS, 0, 0);
\r
73 if (GetDlgCtrlID((HWND) wParam) != IDC_LOGIN_PASSWORD)
\r
75 SetFocus(GetDlgItem(hwndDlg, IDC_LOGIN_PASSWORD));
\r
80 else if (uMsg == WM_COMMAND && LOWORD(wParam) == IDCANCEL && HIWORD(wParam) == BN_CLICKED)
\r
82 LoginDialog* pDlg = (LoginDialog*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
\r
84 EndDialog(hwndDlg, IDCANCEL);
\r
87 else if (uMsg == WM_COMMAND && LOWORD(wParam) == IDOK && HIWORD(wParam) == BN_CLICKED)
\r
89 LoginDialog* pDlg = (LoginDialog*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
\r
91 pDlg->RetrieveValues();
\r
92 EndDialog(hwndDlg, IDOK);
\r
98 LoginDialog::LoginDialog(const std::string& prompt)
\r
103 void LoginDialog::CreateModule(void)
\r
105 DialogBoxParam(g_hmodThisDll, MAKEINTRESOURCE(IDD_LOGIN), g_hwndMain,
\r
106 (DLGPROC)(LoginDialogProc), (long)this);
\r
110 bool LoginDialog::DoLoginDialog(std::string& password, const std::string& prompt)
\r
112 LoginDialog *pDlg = new LoginDialog(prompt);
\r
114 pDlg->CreateModule();
\r
116 bool ret = pDlg->myOK;
\r
117 password = pDlg->myPassword;
\r
125 std::string LoginDialog::GetPassword()
\r
128 SendDlgItemMessage(_hdlg, IDC_LOGIN_PASSWORD, WM_GETTEXT, sizeof(szTxt), (LPARAM)szTxt);
\r
129 std::string strText = szTxt;
\r
133 void LoginDialog::RetrieveValues()
\r
135 myPassword = GetPassword();
\r
142 vi.dwOSVersionInfoSize = sizeof(vi);
\r
143 if (GetVersionEx(&vi))
\r
145 if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT)
\r
153 HWND GetParentHwnd()
\r
157 return GetDesktopWindow();
\r
161 return GetForegroundWindow();
\r