blob: a673844dbd131207c07b617b79cc6ab43f64f5ef [file] [log] [blame]
george825e7af742005-03-10 14:26:00 +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
george825e7af742005-03-10 14:26:00 +000021#include <rfbplayer/PlayerOptions.h>
george82a8b0c8d2005-03-26 11:12:25 +000022#include <rfbplayer/UserPixelFormatsDialog.h>
george825e7af742005-03-10 14:26:00 +000023
24class OptionsDialog : public rfb::win32::Dialog {
25public:
george829a7f9912005-03-20 09:47:56 +000026 OptionsDialog(PlayerOptions *_options, PixelFormatList *_supportedPF)
27 : Dialog(GetModuleHandle(0)), options(_options), combo(0),
28 supportedPF(_supportedPF) {}
george825e7af742005-03-10 14:26:00 +000029 // - Show the dialog and return true if OK was clicked,
30 // false in case of error or Cancel
george82d9957b72005-03-11 14:22:14 +000031 virtual bool showDialog(HWND parent) {
32 return Dialog::showDialog(MAKEINTRESOURCE(IDD_OPTIONS), parent);
george825e7af742005-03-10 14:26:00 +000033 }
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"));
george829a7f9912005-03-20 09:47:56 +000040 for (int i = 0; i < supportedPF->count(); i++) {
41 SendMessage(combo, CB_ADDSTRING,
george8210326862005-03-28 12:07:31 +000042 0, (LPARAM)(LPCTSTR)(((*supportedPF)[i])->format_name));
george829a7f9912005-03-20 09:47:56 +000043 }
44 SendMessage(combo, CB_SETCURSEL, options->pixelFormatIndex + 1, 0);
george825e7af742005-03-10 14:26:00 +000045 setItemChecked(IDC_ACCEPT_BELL, options->acceptBell);
46 setItemChecked(IDC_ACCEPT_CUT_TEXT, options->acceptCutText);
47 setItemChecked(IDC_AUTO_STORE_PARAM, options->autoStoreSettings);
48 setItemChecked(IDC_AUTOPLAY, options->autoPlay);
george82c3950072005-03-20 12:01:54 +000049 setItemChecked(IDC_BIG_ENDIAN, options->bigEndianFlag);
50 if (options->askPixelFormat) {
51 setItemChecked(IDC_ASK_PF, true);
52 enableItem(IDC_PIXELFORMAT, false);
53 enableItem(IDC_BIG_ENDIAN, false);
54 }
george825e7af742005-03-10 14:26:00 +000055 }
56 virtual bool onOk() {
george825e7af742005-03-10 14:26:00 +000057 options->askPixelFormat = isItemChecked(IDC_ASK_PF);
58 options->acceptBell = isItemChecked(IDC_ACCEPT_BELL);
59 options->acceptCutText = isItemChecked(IDC_ACCEPT_CUT_TEXT);
60 options->autoStoreSettings = isItemChecked(IDC_AUTO_STORE_PARAM);
61 options->autoPlay = isItemChecked(IDC_AUTOPLAY);
george82c3950072005-03-20 12:01:54 +000062 options->bigEndianFlag = isItemChecked(IDC_BIG_ENDIAN);
george82c3950072005-03-20 12:01:54 +000063 if (!options->askPixelFormat) {
george82dfb557b2005-03-21 18:26:50 +000064 options->pixelFormatIndex = int(SendMessage(combo, CB_GETCURSEL, 0, 0)) - 1;
george82c3950072005-03-20 12:01:54 +000065 if (options->pixelFormatIndex < 0) {
66 options->autoDetectPF = true;
67 } else {
george8210326862005-03-28 12:07:31 +000068 options->setPF(&((*supportedPF)[options->pixelFormatIndex])->PF);
george82c3950072005-03-20 12:01:54 +000069 options->pixelFormat.bigEndian = options->bigEndianFlag;
70 options->autoDetectPF = false;
71 }
72 }
george82dfb557b2005-03-21 18:26:50 +000073 options->writeToRegistry();
george825e7af742005-03-10 14:26:00 +000074 return true;
75 }
76 virtual bool onCommand(int item, int cmd) {
77 if (item == IDC_ASK_PF) {
78 enableItem(IDC_PIXELFORMAT, !isItemChecked(IDC_ASK_PF));
george82c3950072005-03-20 12:01:54 +000079 enableItem(IDC_BIG_ENDIAN, !isItemChecked(IDC_ASK_PF));
george825e7af742005-03-10 14:26:00 +000080 }
81 if (item == IDC_DEFAULT) {
george829a7f9912005-03-20 09:47:56 +000082 SendMessage(combo, CB_SETCURSEL, DEFAULT_PF_INDEX, 0);
george825e7af742005-03-10 14:26:00 +000083 enableItem(IDC_PIXELFORMAT, !DEFAULT_ASK_PF);
84 setItemChecked(IDC_ASK_PF, DEFAULT_ASK_PF);
85 setItemChecked(IDC_ACCEPT_BELL, DEFAULT_ACCEPT_BELL);
86 setItemChecked(IDC_ACCEPT_CUT_TEXT, DEFAULT_ACCEPT_CUT_TEXT);
87 setItemChecked(IDC_AUTO_STORE_PARAM, DEFAULT_STORE_SETTINGS);
88 setItemChecked(IDC_AUTOPLAY, DEFAULT_AUTOPLAY);
george82c3950072005-03-20 12:01:54 +000089 setItemChecked(IDC_BIG_ENDIAN, DEFAULT_BIG_ENDIAN);
george825e7af742005-03-10 14:26:00 +000090 }
george82a8b0c8d2005-03-26 11:12:25 +000091 if (item == IDC_EDIT_UPF) {
92 UserPixelFormatsDialog UpfListDialog(supportedPF);
george8210326862005-03-28 12:07:31 +000093 if (UpfListDialog.showDialog(handle)) {
94 int index = SendMessage(combo, CB_GETCURSEL, 0, 0);
95 SendMessage(combo, CB_RESETCONTENT, 0, 0);
96 SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)("Auto"));
97 for (int i = 0; i < supportedPF->count(); i++) {
98 SendMessage(combo, CB_ADDSTRING,
99 0, (LPARAM)(LPCTSTR)(((*supportedPF)[i])->format_name));
100 }
101 if ( index > (SendMessage(combo, CB_GETCOUNT, 0, 0) - 1)) {
102 index = SendMessage(combo, CB_GETCOUNT, 0, 0) - 1;
103 }
104 SendMessage(combo, CB_SETCURSEL, index, 0);
105 }
george82a8b0c8d2005-03-26 11:12:25 +0000106 }
george825e7af742005-03-10 14:26:00 +0000107 return false;
108 }
109
110 HWND combo;
111 PlayerOptions *options;
george829a7f9912005-03-20 09:47:56 +0000112 PixelFormatList *supportedPF;
george825e7af742005-03-10 14:26:00 +0000113};