Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* 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 | |
| 21 | #include <rfbplayer/EditPixelFormatDialog.h> |
| 22 | |
| 23 | #define UPF_REGISTRY_PATH "Software\\TightVnc\\RfbPlayer\\UserDefinedPF" |
| 24 | |
| 25 | class UserPixelFormatsDialog : public rfb::win32::Dialog { |
| 26 | public: |
| 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 | |
| 35 | protected: |
| 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, |
| 41 | 0, (LPARAM)(LPCTSTR)(((*supportedPF)[i])->format_name)); |
| 42 | } |
| 43 | SendMessage(pfList, LB_SETCURSEL, 0, 0); |
| 44 | } |
| 45 | virtual bool onCommand(int item, int cmd) { |
| 46 | switch (item) { |
| 47 | case IDC_ADD_BUTTON: |
| 48 | { |
| 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 | } |
| 57 | break; |
| 58 | case IDC_REMOVE_BUTTON: |
| 59 | { |
| 60 | int index = SendMessage(pfList, LB_GETCURSEL, 0, 0); |
| 61 | if (index == LB_ERR) { |
| 62 | MessageBox(handle, "You must select the pixel format for remove.", |
| 63 | "RfbPlayer", MB_OK | MB_ICONWARNING); |
| 64 | return false; |
| 65 | } else { |
| 66 | supportedPF->remove(supportedPF->getDefaultPFCount() + index); |
| 67 | SendMessage(pfList, LB_DELETESTRING, index, 0); |
| 68 | } |
| 69 | } |
| 70 | break; |
| 71 | case IDC_PF_LIST: |
| 72 | if (cmd != LBN_DBLCLK) break; |
| 73 | case IDC_EDIT_BUTTON: |
| 74 | { |
| 75 | int index = SendMessage(pfList, LB_GETCURSEL, 0, 0); |
| 76 | if (index == LB_ERR) { |
| 77 | MessageBox(handle, "You must select the pixel format for remove.", |
| 78 | "RfbPlayer", MB_OK | MB_ICONWARNING); |
| 79 | return false; |
| 80 | } |
| 81 | PixelFormat *pf = |
| 82 | &(supportedPF->operator[](index + supportedPF->getDefaultPFCount())->PF); |
| 83 | char *format_name = |
| 84 | (supportedPF)->operator[](index + supportedPF->getDefaultPFCount())->format_name; |
| 85 | EditPixelFormatDialog edit(supportedPF, format_name, pf); |
| 86 | if (edit.showDialog(handle)) { |
| 87 | SendMessage(pfList, LB_DELETESTRING, index, 0); |
| 88 | SendMessage(pfList, LB_INSERTSTRING, index, (LPARAM)(LPCTSTR)format_name); |
| 89 | SendMessage(pfList, LB_SETCURSEL, index, 0); |
| 90 | } |
| 91 | } |
| 92 | break; |
| 93 | default: |
| 94 | break; |
| 95 | } |
| 96 | return false; |
| 97 | } |
| 98 | virtual bool onOk() { |
| 99 | supportedPF->writeUserDefinedPF(HKEY_CURRENT_USER, UPF_REGISTRY_PATH); |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | HWND pfList; |
| 104 | PixelFormatList *supportedPF; |
| 105 | }; |