blob: 29fd1bc91256baee58826de3528c15cbb167fa5c [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#include <vncviewer/ConnectionDialog.h>
20#include <vncviewer/CConn.h>
21#include <vncviewer/resource.h>
22#include <rfb_win32/AboutDialog.h>
23
24#include <tchar.h>
25
26using namespace rfb;
27using namespace rfb::win32;
28
29
30ConnectionDialog::ConnectionDialog(CConn* conn_) : Dialog(GetModuleHandle(0)), conn(conn_) {
31}
32
33
34bool ConnectionDialog::showDialog() {
35 return Dialog::showDialog(MAKEINTRESOURCE(IDD_CONNECTION_DLG));
36}
37
38void ConnectionDialog::initDialog() {
39 HWND box = GetDlgItem(handle, IDC_SERVER_EDIT);
40
41 std::list<char*> mru = MRU::getEntries();
42 std::list<char*>::iterator i;
43
44 // Locate the combo-box
45 // NB: TCharArray converts the supplied char* and assumes ownership!
46 for (i=mru.begin(); i!=mru.end(); i++) {
Peter Åstrand52da3d42008-12-11 08:40:05 +000047 SendMessage(box, CB_ADDSTRING, 0, (LPARAM)TCharArray(*i).buf);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000048 }
49
50 // Select the first item in the list
51 SendMessage(box, CB_SETCURSEL, 0, 0);
52
53 // Fill out the Security: drop-down and select the preferred option
54 HWND security = GetDlgItem(handle, IDC_SECURITY_LEVEL);
55 LRESULT n = SendMessage(security, CB_ADDSTRING, 0, (LPARAM)_T("Always Off"));
56 if (n != CB_ERR)
57 SendMessage(security, CB_SETCURSEL, n, 0);
58 enableItem(IDC_SECURITY_LEVEL, false);
59}
60
61
62bool ConnectionDialog::onOk() {
63 delete [] hostname.buf;
64 hostname.buf = 0;
65 hostname.buf = getItemString(IDC_SERVER_EDIT);
66 return hostname.buf[0] != 0;
67}
68
69bool ConnectionDialog::onCommand(int id, int cmd) {
70 switch (id) {
71 case IDC_ABOUT:
72 AboutDialog::instance.showDialog();
73 return true;
74 case IDC_OPTIONS:
75 conn->showOptionsDialog();
76 return true;
77 };
78 return false;
79}