Initial revision


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/UserPasswdDialog.cxx b/vncviewer/UserPasswdDialog.cxx
new file mode 100644
index 0000000..8ab4ba4
--- /dev/null
+++ b/vncviewer/UserPasswdDialog.cxx
@@ -0,0 +1,84 @@
+/* Copyright (C) 2002-2004 RealVNC Ltd.  All Rights Reserved.
+ *    
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+
+#include <vncviewer/UserPasswdDialog.h>
+#include <vncviewer/resource.h>
+
+using namespace rfb;
+using namespace rfb::win32;
+
+
+UserPasswdDialog::UserPasswdDialog() : Dialog(GetModuleHandle(0)), showUsername(false) {
+}
+
+
+void UserPasswdDialog::setCSecurity(const CSecurity* cs) {
+  description.replaceBuf(tstrDup(cs->description()));
+}
+
+bool UserPasswdDialog::showDialog() {
+  return Dialog::showDialog(MAKEINTRESOURCE(IDD_VNC_AUTH_DLG));
+}
+
+void UserPasswdDialog::initDialog() {
+  if (username.buf) {
+    setItemString(IDC_USERNAME, username.buf);
+    tstrFree(username.takeBuf());
+  }
+  if (password.buf) {
+    setItemString(IDC_PASSWORD, password.buf);
+    tstrFree(password.takeBuf());
+  }
+  if (!showUsername) {
+    setItemString(IDC_USERNAME, _T(""));
+    enableItem(IDC_USERNAME, false);
+  }
+  if (description.buf) {
+    TCharArray title(128);
+    GetWindowText(handle, title.buf, 128);
+    _tcsncat(title.buf, _T(" ["), 128);
+    _tcsncat(title.buf, description.buf, 128);
+    _tcsncat(title.buf, _T("]"), 128);
+    SetWindowText(handle, title.buf);
+  }
+}
+
+bool UserPasswdDialog::onOk() {
+	username.buf = getItemString(IDC_USERNAME);
+	password.buf = getItemString(IDC_PASSWORD);
+  return true;
+}
+
+
+bool UserPasswdDialog::getUserPasswd(char** user, char** passwd) {
+  bool result = false;
+  showUsername = user != 0;
+  if (user && *user)
+    username.buf = tstrDup(*user);
+  if (passwd && *passwd)
+    password.buf = tstrDup(*passwd);
+  if (showDialog()) {
+    if (user)
+      *user = strDup(username.buf);
+    *passwd = strDup(password.buf);
+    result = true;
+  }
+  tstrFree(username.takeBuf());
+  tstrFree(password.takeBuf());
+  return result;
+}