blob: 72244e95c6b9aca75fd61bc511f2360a8cd1a1fd [file] [log] [blame]
george82a8b0c8d2005-03-26 11: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// -=- UserPixelFormatsDialog.h
20
george8210326862005-03-28 12:07:31 +000021#include <rfbplayer/EditPixelFormatDialog.h>
22
23#define UPF_REGISTRY_PATH "Software\\TightVnc\\RfbPlayer\\UserDefinedPF"
george82a8b0c8d2005-03-26 11:12:25 +000024
25class UserPixelFormatsDialog : public rfb::win32::Dialog {
26public:
27 UserPixelFormatsDialog(PixelFormatList *_supportedPF)
28 : Dialog(GetModuleHandle(0)), supportedPF(_supportedPF), pfList(0) {}
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_USERPF_LIST), parent);
33 }
34
35protected:
36 // Dialog methods (protected)
37 virtual void initDialog() {
38 pfList = GetDlgItem(handle, IDC_PF_LIST);
39 for (int i = supportedPF->getDefaultPFCount(); i < supportedPF->count(); i++) {
40 SendMessage(pfList, LB_ADDSTRING,
george8210326862005-03-28 12:07:31 +000041 0, (LPARAM)(LPCTSTR)(((*supportedPF)[i])->format_name));
george82a8b0c8d2005-03-26 11:12:25 +000042 }
43 SendMessage(pfList, LB_SETCURSEL, 0, 0);
44 }
45 virtual bool onCommand(int item, int cmd) {
46 switch (item) {
47 case IDC_ADD_BUTTON:
george8210326862005-03-28 12:07:31 +000048 {
49 char format_name[MAX_STR_LEN] = "";
50 PixelFormat pf(32, 24, 0, 1, 0, 0, 0, 0, 0, 0);
51 EditPixelFormatDialog edit(supportedPF, format_name, &pf);
52 if (edit.showDialog(handle)) {
53 supportedPF->add(format_name, pf);
54 SendMessage(pfList, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)format_name);
55 };
56 (*supportedPF)[15];
57 }
george82a8b0c8d2005-03-26 11:12:25 +000058 break;
59 case IDC_REMOVE_BUTTON:
george8210326862005-03-28 12:07:31 +000060 {
61 int index = SendMessage(pfList, LB_GETCURSEL, 0, 0);
62 if (index == LB_ERR) {
63 MessageBox(handle, "You must select the pixel format for remove.",
64 "RfbPlayer", MB_OK | MB_ICONWARNING);
65 return false;
66 } else {
67 supportedPF->remove(supportedPF->getDefaultPFCount() + index);
68 SendMessage(pfList, LB_DELETESTRING, index, 0);
69 }
70 }
george82a8b0c8d2005-03-26 11:12:25 +000071 break;
george8210326862005-03-28 12:07:31 +000072 case IDC_PF_LIST:
73 if (cmd != LBN_DBLCLK) break;
george82a8b0c8d2005-03-26 11:12:25 +000074 case IDC_EDIT_BUTTON:
george8210326862005-03-28 12:07:31 +000075 {
76 int index = SendMessage(pfList, LB_GETCURSEL, 0, 0);
77 PixelFormat *pf =
78 &(supportedPF->operator[](index + supportedPF->getDefaultPFCount())->PF);
79 char *format_name =
80 (supportedPF)->operator[](index + supportedPF->getDefaultPFCount())->format_name;
81 EditPixelFormatDialog edit(supportedPF, format_name, pf);
82 if (edit.showDialog(handle)) {
83 SendMessage(pfList, LB_DELETESTRING, index, 0);
84 SendMessage(pfList, LB_INSERTSTRING, index, (LPARAM)(LPCTSTR)format_name);
85 SendMessage(pfList, LB_SETCURSEL, index, 0);
86 };
87 }
george82a8b0c8d2005-03-26 11:12:25 +000088 break;
89 default:
90 break;
91 }
92 return false;
93 }
george8210326862005-03-28 12:07:31 +000094 virtual bool onOk() {
95 supportedPF->writeUserDefinedPF(HKEY_CURRENT_USER, UPF_REGISTRY_PATH);
96 return true;
97 }
george82a8b0c8d2005-03-26 11:12:25 +000098
99 HWND pfList;
100 PixelFormatList *supportedPF;
101};