blob: 8c3a87d756dec36b175948ba4c292633cb140d92 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2004 TightVNC Team. 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// -=- OptionsDialog.h
20
21#include <rfbplayer/PlayerOptions.h>
22#include <rfbplayer/UserPixelFormatsDialog.h>
23
24class OptionsDialog : public rfb::win32::Dialog {
25public:
26 OptionsDialog(PlayerOptions *_options, PixelFormatList *_supportedPF)
27 : Dialog(GetModuleHandle(0)), options(_options), combo(0),
28 supportedPF(_supportedPF) {}
29 // - Show the dialog and return true if OK was clicked,
30 // false in case of error or Cancel
31 virtual bool showDialog(HWND parent) {
32 return Dialog::showDialog(MAKEINTRESOURCE(IDD_OPTIONS), parent);
33 }
34protected:
35
36 // Dialog methods (protected)
37 virtual void initDialog() {
38 combo = GetDlgItem(handle, IDC_PIXELFORMAT);
39 SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)("Auto"));
40 for (int i = 0; i < supportedPF->count(); i++) {
41 SendMessage(combo, CB_ADDSTRING,
42 0, (LPARAM)(LPCTSTR)(((*supportedPF)[i])->format_name));
43 }
44 SendMessage(combo, CB_SETCURSEL, options->pixelFormatIndex + 1, 0);
45 setItemChecked(IDC_ACCEPT_BELL, options->acceptBell);
46 setItemChecked(IDC_ACCEPT_CUT_TEXT, options->acceptCutText);
47 setItemChecked(IDC_AUTOPLAY, options->autoPlay);
48 setItemChecked(IDC_BIG_ENDIAN, options->bigEndianFlag);
49 if (options->askPixelFormat) {
50 setItemChecked(IDC_ASK_PF, true);
51 enableItem(IDC_PIXELFORMAT, false);
52 enableItem(IDC_BIG_ENDIAN, false);
53 }
54 }
55 virtual bool onOk() {
56 options->askPixelFormat = isItemChecked(IDC_ASK_PF);
57 options->acceptBell = isItemChecked(IDC_ACCEPT_BELL);
58 options->acceptCutText = isItemChecked(IDC_ACCEPT_CUT_TEXT);
59 options->autoPlay = isItemChecked(IDC_AUTOPLAY);
60 options->bigEndianFlag = isItemChecked(IDC_BIG_ENDIAN);
61 if (!options->askPixelFormat) {
62 options->pixelFormatIndex = int(SendMessage(combo, CB_GETCURSEL, 0, 0)) - 1;
63 if (options->pixelFormatIndex < 0) {
64 options->autoDetectPF = true;
65 } else {
66 options->setPF(&((*supportedPF)[options->pixelFormatIndex])->PF);
67 options->pixelFormat.bigEndian = options->bigEndianFlag;
68 options->autoDetectPF = false;
69 }
70 }
71 options->writeToRegistry();
72 return true;
73 }
74 virtual bool onCommand(int item, int cmd) {
75 if (item == IDC_ASK_PF) {
76 enableItem(IDC_PIXELFORMAT, !isItemChecked(IDC_ASK_PF));
77 enableItem(IDC_BIG_ENDIAN, !isItemChecked(IDC_ASK_PF));
78 }
79 if (item == IDC_DEFAULT) {
80 SendMessage(combo, CB_SETCURSEL, DEFAULT_PF_INDEX + 1, 0);
81 enableItem(IDC_PIXELFORMAT, !DEFAULT_ASK_PF);
82 enableItem(IDC_BIG_ENDIAN, !DEFAULT_ASK_PF);
83 setItemChecked(IDC_ASK_PF, DEFAULT_ASK_PF);
84 setItemChecked(IDC_ACCEPT_BELL, DEFAULT_ACCEPT_BELL);
85 setItemChecked(IDC_ACCEPT_CUT_TEXT, DEFAULT_ACCEPT_CUT_TEXT);
86 setItemChecked(IDC_AUTOPLAY, DEFAULT_AUTOPLAY);
87 setItemChecked(IDC_BIG_ENDIAN, DEFAULT_BIG_ENDIAN);
88 }
89 if (item == IDC_EDIT_UPF) {
90 UserPixelFormatsDialog UpfListDialog(supportedPF);
91 if (UpfListDialog.showDialog(handle)) {
92 int index = SendMessage(combo, CB_GETCURSEL, 0, 0);
93 SendMessage(combo, CB_RESETCONTENT, 0, 0);
94 SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)("Auto"));
95 for (int i = 0; i < supportedPF->count(); i++) {
96 SendMessage(combo, CB_ADDSTRING,
97 0, (LPARAM)(LPCTSTR)(((*supportedPF)[i])->format_name));
98 }
99 if ( index > (SendMessage(combo, CB_GETCOUNT, 0, 0) - 1)) {
100 index = SendMessage(combo, CB_GETCOUNT, 0, 0) - 1;
101 }
102 SendMessage(combo, CB_SETCURSEL, index, 0);
103 options->pixelFormatIndex = index - 1;
104 }
105 }
106 return false;
107 }
108
109 HWND combo;
110 PlayerOptions *options;
111 PixelFormatList *supportedPF;
112};