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