blob: 8c3a87d756dec36b175948ba4c292633cb140d92 [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);
george825e7af742005-03-10 14:26:00 +000047 setItemChecked(IDC_AUTOPLAY, options->autoPlay);
george82c3950072005-03-20 12:01:54 +000048 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 }
george825e7af742005-03-10 14:26:00 +000054 }
55 virtual bool onOk() {
george825e7af742005-03-10 14:26:00 +000056 options->askPixelFormat = isItemChecked(IDC_ASK_PF);
57 options->acceptBell = isItemChecked(IDC_ACCEPT_BELL);
58 options->acceptCutText = isItemChecked(IDC_ACCEPT_CUT_TEXT);
george825e7af742005-03-10 14:26:00 +000059 options->autoPlay = isItemChecked(IDC_AUTOPLAY);
george82c3950072005-03-20 12:01:54 +000060 options->bigEndianFlag = isItemChecked(IDC_BIG_ENDIAN);
george82c3950072005-03-20 12:01:54 +000061 if (!options->askPixelFormat) {
george82dfb557b2005-03-21 18:26:50 +000062 options->pixelFormatIndex = int(SendMessage(combo, CB_GETCURSEL, 0, 0)) - 1;
george82c3950072005-03-20 12:01:54 +000063 if (options->pixelFormatIndex < 0) {
64 options->autoDetectPF = true;
65 } else {
george8210326862005-03-28 12:07:31 +000066 options->setPF(&((*supportedPF)[options->pixelFormatIndex])->PF);
george82c3950072005-03-20 12:01:54 +000067 options->pixelFormat.bigEndian = options->bigEndianFlag;
68 options->autoDetectPF = false;
69 }
70 }
george82dfb557b2005-03-21 18:26:50 +000071 options->writeToRegistry();
george825e7af742005-03-10 14:26:00 +000072 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));
george82c3950072005-03-20 12:01:54 +000077 enableItem(IDC_BIG_ENDIAN, !isItemChecked(IDC_ASK_PF));
george825e7af742005-03-10 14:26:00 +000078 }
79 if (item == IDC_DEFAULT) {
george82530a0752005-03-29 15:24:08 +000080 SendMessage(combo, CB_SETCURSEL, DEFAULT_PF_INDEX + 1, 0);
george825e7af742005-03-10 14:26:00 +000081 enableItem(IDC_PIXELFORMAT, !DEFAULT_ASK_PF);
george825513d5c2005-04-11 15:34:57 +000082 enableItem(IDC_BIG_ENDIAN, !DEFAULT_ASK_PF);
george825e7af742005-03-10 14:26:00 +000083 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);
george825e7af742005-03-10 14:26:00 +000086 setItemChecked(IDC_AUTOPLAY, DEFAULT_AUTOPLAY);
george82c3950072005-03-20 12:01:54 +000087 setItemChecked(IDC_BIG_ENDIAN, DEFAULT_BIG_ENDIAN);
george825e7af742005-03-10 14:26:00 +000088 }
george82a8b0c8d2005-03-26 11:12:25 +000089 if (item == IDC_EDIT_UPF) {
90 UserPixelFormatsDialog UpfListDialog(supportedPF);
george8210326862005-03-28 12:07:31 +000091 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);
george8205d86232005-03-28 12:16:08 +0000103 options->pixelFormatIndex = index - 1;
george8210326862005-03-28 12:07:31 +0000104 }
george82a8b0c8d2005-03-26 11:12:25 +0000105 }
george825e7af742005-03-10 14:26:00 +0000106 return false;
107 }
108
109 HWND combo;
110 PlayerOptions *options;
george829a7f9912005-03-20 09:47:56 +0000111 PixelFormatList *supportedPF;
george825e7af742005-03-10 14:26:00 +0000112};