blob: f0cdafe89c685e61a8dbcdd12b17c9a296b5ea04 [file] [log] [blame]
george823ff0c232005-03-27 11:32:01 +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// -=- EditPixelFormatDialog.h
20
21#include <rfb_win32/Dialog.h>
22
23class EditPixelFormatDialog : public rfb::win32::Dialog {
24public:
25 EditPixelFormatDialog(PixelFormatList *_supportedPF, char *_format_name,
26 PixelFormat *_pf)
27 : Dialog(GetModuleHandle(0)), format_name(_format_name),
28 supportedPF(_supportedPF), pf(_pf) {}
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_UPF_EDIT), parent);
33 }
34
35protected:
36 // Dialog methods (protected)
37 virtual void initDialog() {
38 HWND bppCombo = GetDlgItem(handle, IDC_BPP_COMBO);
39 SendMessage(bppCombo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)("8"));
40 SendMessage(bppCombo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)("16"));
41 SendMessage(bppCombo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)("32"));
42 SendMessage(bppCombo, CB_SETCURSEL, min(2, (pf->bpp - 8) / 8), 0);
43
44 HWND bigendianCombo = GetDlgItem(handle, IDC_BIGENDIAN_COMBO);
45 SendMessage(bigendianCombo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)("No"));
46 SendMessage(bigendianCombo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)("Yes"));
47 SendMessage(bigendianCombo, CB_SETCURSEL, pf->bigEndian, 0);
48
49 setItemString(IDC_NAME_EDIT, format_name);
50 setItemInt(IDC_DEPTH_EDIT, pf->depth);
51 setItemInt(IDC_REDMAX_EDIT, pf->redMax);
52 setItemInt(IDC_GREENMAX_EDIT, pf->greenMax);
53 setItemInt(IDC_BLUEMAX_EDIT, pf->blueMax);
54 setItemInt(IDC_REDSHIFT_EDIT, pf->redShift);
55 setItemInt(IDC_GREENSHIFT_EDIT, pf->greenShift);
56 setItemInt(IDC_BLUESHIFT_EDIT, pf->blueShift);
57 }
58 virtual bool onOk() {
59 // Check for the errors
60 char err_msg[256] = "\0";
61 if (((getItemString(IDC_NAME_EDIT))[0] == '\0') ||
62 ((getItemString(IDC_DEPTH_EDIT))[0] == '\0') ||
63 ((getItemString(IDC_REDMAX_EDIT))[0] == '\0') ||
64 ((getItemString(IDC_GREENMAX_EDIT))[0] == '\0') ||
65 ((getItemString(IDC_BLUEMAX_EDIT))[0] == '\0') ||
66 ((getItemString(IDC_REDSHIFT_EDIT))[0] == '\0') ||
67 ((getItemString(IDC_GREENSHIFT_EDIT))[0] == '\0') ||
68 ((getItemString(IDC_BLUESHIFT_EDIT))[0] == '\0')) {
69 strcpy(err_msg, "Please fill the all fields in the dialog.");
70 }
71 if (supportedPF->getIndexByPFName(format_name) !=
72 supportedPF->getIndexByPFName(getItemString(IDC_NAME_EDIT))) {
73 strcpy(err_msg, "The pixel format with that name is already exist.");
74 }
75 if (getItemInt(IDC_DEPTH_EDIT) <= 0) {
76 strcpy(err_msg, "The pixel depth must be larger than 0.");
77 }
78 if (err_msg[0] != 0) {
79 MessageBox(handle, err_msg, "RfbPlayer", MB_OK | MB_ICONWARNING);
80 return false;
81 }
82 // Fill the pixel format structure
83 strncpy(format_name, getItemString(IDC_NAME_EDIT), sizeof(format_name));
84 format_name[sizeof(format_name) - 1] = 0;
85 pf->bpp = getItemInt(IDC_BPP_COMBO);
86 pf->depth = getItemInt(IDC_DEPTH_EDIT);
87 pf->bigEndian = (SendMessage(GetDlgItem(handle, IDC_BIGENDIAN_COMBO),
88 CB_GETCURSEL, 0, 0)) ? true : false;
89 pf->trueColour = true;
90 pf->redMax = getItemInt(IDC_REDMAX_EDIT);
91 pf->greenMax = getItemInt(IDC_GREENMAX_EDIT);
92 pf->blueMax = getItemInt(IDC_BLUEMAX_EDIT);
93 pf->redShift = getItemInt(IDC_REDSHIFT_EDIT);
94 pf->greenShift = getItemInt(IDC_GREENSHIFT_EDIT);
95 pf->blueShift = getItemInt(IDC_BLUESHIFT_EDIT);
96 return true;
97 }
98
99 char *format_name;
100 PixelFormatList *supportedPF;
101 PixelFormat *pf;
102};