| 1 | /* |
| 2 | * This file is part of the libCEC(R) library. |
| 3 | * |
| 4 | * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. |
| 5 | * libCEC(R) is an original work, containing original code. |
| 6 | * |
| 7 | * libCEC(R) is a trademark of Pulse-Eight Limited. |
| 8 | * |
| 9 | * This program is dual-licensed; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | * |
| 23 | * |
| 24 | * Alternatively, you can license this library under a commercial license, |
| 25 | * please contact Pulse-Eight Licensing for more information. |
| 26 | * |
| 27 | * For more information contact: |
| 28 | * Pulse-Eight Licensing <license@pulse-eight.com> |
| 29 | * http://www.pulse-eight.com/ |
| 30 | * http://www.pulse-eight.net/ |
| 31 | */ |
| 32 | |
| 33 | using System; |
| 34 | using System.Windows.Forms; |
| 35 | using CecSharp; |
| 36 | using LibCECTray.controller.applications; |
| 37 | |
| 38 | namespace LibCECTray.ui |
| 39 | { |
| 40 | /// <summary> |
| 41 | /// Form that implements IAsyncControls |
| 42 | /// </summary> |
| 43 | class AsyncForm : Form, IAsyncControls |
| 44 | { |
| 45 | /// <summary> |
| 46 | /// Changes the ShowInTaskbar value |
| 47 | /// </summary> |
| 48 | /// <param name="val">True to show, false to hide</param> |
| 49 | public void SetShowInTaskbar(bool val) |
| 50 | { |
| 51 | if (InvokeRequired) |
| 52 | { |
| 53 | SetShowInTaskbarCallback d = SetShowInTaskbar; |
| 54 | try |
| 55 | { |
| 56 | Invoke(d, new object[] { val }); |
| 57 | } |
| 58 | catch (Exception) { } |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | ShowInTaskbar = val; |
| 63 | } |
| 64 | } |
| 65 | private delegate void SetShowInTaskbarCallback(bool val); |
| 66 | |
| 67 | /// <summary> |
| 68 | /// Enable or disable a control |
| 69 | /// </summary> |
| 70 | /// <param name="control">The control to change</param> |
| 71 | /// <param name="val">True to enable, false to disable</param> |
| 72 | public void SetControlEnabled(Control control, bool val) |
| 73 | { |
| 74 | AsyncControls.SetControlEnabled(this, control, val); |
| 75 | } |
| 76 | |
| 77 | /// <summary> |
| 78 | /// Change the text label of a control |
| 79 | /// </summary> |
| 80 | /// <param name="control">The control to change</param> |
| 81 | /// <param name="val">The new text</param> |
| 82 | public void SetControlText(Control control, string val) |
| 83 | { |
| 84 | AsyncControls.SetControlText(this, control, val); |
| 85 | } |
| 86 | |
| 87 | /// <summary> |
| 88 | /// Changes the toolstrip menu text |
| 89 | /// </summary> |
| 90 | /// <param name="item">The toolstrip menu item to change</param> |
| 91 | /// <param name="val">The new value</param> |
| 92 | public void SetToolStripMenuText(ToolStripMenuItem item, string val) |
| 93 | { |
| 94 | AsyncControls.SetToolStripMenuText(this, item, val); |
| 95 | } |
| 96 | |
| 97 | /// <summary> |
| 98 | /// Change the checked status of a checkbox |
| 99 | /// </summary> |
| 100 | /// <param name="control">The control to change</param> |
| 101 | /// <param name="val">True to change to checked, false to change to unchecked</param> |
| 102 | public void SetCheckboxChecked(CheckBox control, bool val) |
| 103 | { |
| 104 | AsyncControls.SetCheckboxChecked(this, control, val); |
| 105 | } |
| 106 | |
| 107 | /// <summary> |
| 108 | /// Change the checked status of an item in a CheckedListBox |
| 109 | /// </summary> |
| 110 | /// <param name="control">The control to change</param> |
| 111 | /// <param name="index">The index of the checkbox in the list to change</param> |
| 112 | /// <param name="val">True to change to checked, false to change to unchecked</param> |
| 113 | public void SetCheckboxItemChecked(CheckedListBox control, int index, bool val) |
| 114 | { |
| 115 | AsyncControls.SetCheckboxItemChecked(this, control, index, val); |
| 116 | } |
| 117 | |
| 118 | /// <summary> |
| 119 | /// Changes the progress value of a progress bar |
| 120 | /// </summary> |
| 121 | /// <param name="control">The control to change</param> |
| 122 | /// <param name="val">The new percentage</param> |
| 123 | public void SetProgressValue(ProgressBar control, int val) |
| 124 | { |
| 125 | AsyncControls.SetProgressValue(this, control, val); |
| 126 | } |
| 127 | |
| 128 | /// <summary> |
| 129 | /// Replaces the items of a combobox |
| 130 | /// </summary> |
| 131 | /// <param name="control">The control to change</param> |
| 132 | /// <param name="selectedIndex">The new selection index</param> |
| 133 | /// <param name="val">The new content</param> |
| 134 | public void SetComboBoxItems(ComboBox control, int selectedIndex, object[] val) |
| 135 | { |
| 136 | AsyncControls.SetComboBoxItems(this, control, selectedIndex, val); |
| 137 | } |
| 138 | |
| 139 | /// <summary> |
| 140 | /// Make a control visible or invisible |
| 141 | /// </summary> |
| 142 | /// <param name="control">The control to change</param> |
| 143 | /// <param name="val">True to make it visible, false to make it invisible</param> |
| 144 | public void SetControlVisible(Control control, bool val) |
| 145 | { |
| 146 | AsyncControls.SetControlVisible(this, control, val); |
| 147 | } |
| 148 | |
| 149 | /// <summary> |
| 150 | /// Display a new dialog |
| 151 | /// </summary> |
| 152 | /// <param name="control">The control to display</param> |
| 153 | /// <param name="modal">True to make it a modal dialog</param> |
| 154 | public void DisplayDialog(Form control, bool modal) |
| 155 | { |
| 156 | AsyncControls.DisplayDialog(this, control, modal); |
| 157 | } |
| 158 | |
| 159 | /// <summary> |
| 160 | /// Hides a control |
| 161 | /// </summary> |
| 162 | /// <param name="val">True to hide, false to show</param> |
| 163 | public void SafeHide(bool val) |
| 164 | { |
| 165 | AsyncControls.SafeHide(this, val); |
| 166 | } |
| 167 | |
| 168 | /// <summary> |
| 169 | /// Change the selected index |
| 170 | /// </summary> |
| 171 | /// <param name="control">The control to change</param> |
| 172 | /// <param name="index">The new selected index</param> |
| 173 | public void SetSelectedIndex(ComboBox control, int index) |
| 174 | { |
| 175 | AsyncControls.SetSelectedIndex(this, control, index); |
| 176 | } |
| 177 | |
| 178 | /// <summary> |
| 179 | /// Get the name of the selected tab in a TabControl |
| 180 | /// </summary> |
| 181 | /// <param name="container">The tab container</param> |
| 182 | /// <param name="tabPages">The tab pages</param> |
| 183 | /// <returns>The name of the selected tab</returns> |
| 184 | public string GetSelectedTabName(TabControl container, TabControl.TabPageCollection tabPages) |
| 185 | { |
| 186 | return AsyncControls.GetSelectedTabName(container, tabPages); |
| 187 | } |
| 188 | |
| 189 | /// <summary> |
| 190 | /// Selects the row with the given CecKeypress for a datagrid |
| 191 | /// </summary> |
| 192 | /// <param name="container">The datagrid container</param> |
| 193 | /// <param name="dgView">The datagrid</param> |
| 194 | /// <param name="key">The key to selected</param> |
| 195 | public void SelectKeypressRow(Control container, DataGridView dgView, CecKeypress key) |
| 196 | { |
| 197 | AsyncControls.SelectKeypressRow(container, dgView, key); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /// <summary> |
| 202 | /// TabPage that implements IAsyncControls |
| 203 | /// </summary> |
| 204 | class AsyncTabPage : TabPage, IAsyncControls |
| 205 | { |
| 206 | /// <summary> |
| 207 | /// Enable or disable a control |
| 208 | /// </summary> |
| 209 | /// <param name="control">The control to change</param> |
| 210 | /// <param name="val">True to enable, false to disable</param> |
| 211 | public void SetControlEnabled(Control control, bool val) |
| 212 | { |
| 213 | AsyncControls.SetControlEnabled(this, control, val); |
| 214 | } |
| 215 | |
| 216 | /// <summary> |
| 217 | /// Change the text label of a control |
| 218 | /// </summary> |
| 219 | /// <param name="control">The control to change</param> |
| 220 | /// <param name="val">The new text</param> |
| 221 | public void SetControlText(Control control, string val) |
| 222 | { |
| 223 | AsyncControls.SetControlText(this, control, val); |
| 224 | } |
| 225 | |
| 226 | /// <summary> |
| 227 | /// Changes the toolstrip menu text |
| 228 | /// </summary> |
| 229 | /// <param name="item">The toolstrip menu item to change</param> |
| 230 | /// <param name="val">The new value</param> |
| 231 | public void SetToolStripMenuText(ToolStripMenuItem item, string val) |
| 232 | { |
| 233 | AsyncControls.SetToolStripMenuText(this, item, val); |
| 234 | } |
| 235 | |
| 236 | /// <summary> |
| 237 | /// Change the checked status of a checkbox |
| 238 | /// </summary> |
| 239 | /// <param name="control">The control to change</param> |
| 240 | /// <param name="val">True to change to checked, false to change to unchecked</param> |
| 241 | public void SetCheckboxChecked(CheckBox control, bool val) |
| 242 | { |
| 243 | AsyncControls.SetCheckboxChecked(this, control, val); |
| 244 | } |
| 245 | |
| 246 | /// <summary> |
| 247 | /// Change the checked status of an item in a CheckedListBox |
| 248 | /// </summary> |
| 249 | /// <param name="control">The control to change</param> |
| 250 | /// <param name="index">The index of the checkbox in the list to change</param> |
| 251 | /// <param name="val">True to change to checked, false to change to unchecked</param> |
| 252 | public void SetCheckboxItemChecked(CheckedListBox control, int index, bool val) |
| 253 | { |
| 254 | AsyncControls.SetCheckboxItemChecked(this, control, index, val); |
| 255 | } |
| 256 | |
| 257 | /// <summary> |
| 258 | /// Changes the progress value of a progress bar |
| 259 | /// </summary> |
| 260 | /// <param name="control">The control to change</param> |
| 261 | /// <param name="val">The new percentage</param> |
| 262 | public void SetProgressValue(ProgressBar control, int val) |
| 263 | { |
| 264 | AsyncControls.SetProgressValue(this, control, val); |
| 265 | } |
| 266 | |
| 267 | /// <summary> |
| 268 | /// Replaces the items of a combobox |
| 269 | /// </summary> |
| 270 | /// <param name="control">The control to change</param> |
| 271 | /// <param name="selectedIndex">The new selection index</param> |
| 272 | /// <param name="val">The new content</param> |
| 273 | public void SetComboBoxItems(ComboBox control, int selectedIndex, object[] val) |
| 274 | { |
| 275 | AsyncControls.SetComboBoxItems(this, control, selectedIndex, val); |
| 276 | } |
| 277 | |
| 278 | /// <summary> |
| 279 | /// Make a control visible or invisible |
| 280 | /// </summary> |
| 281 | /// <param name="control">The control to change</param> |
| 282 | /// <param name="val">True to make it visible, false to make it invisible</param> |
| 283 | public void SetControlVisible(Control control, bool val) |
| 284 | { |
| 285 | AsyncControls.SetControlVisible(this, control, val); |
| 286 | } |
| 287 | |
| 288 | /// <summary> |
| 289 | /// Display a new dialog |
| 290 | /// </summary> |
| 291 | /// <param name="control">The control to display</param> |
| 292 | /// <param name="modal">True to make it a modal dialog</param> |
| 293 | public void DisplayDialog(Form control, bool modal) |
| 294 | { |
| 295 | AsyncControls.DisplayDialog(this, control, modal); |
| 296 | } |
| 297 | |
| 298 | /// <summary> |
| 299 | /// Hides a control |
| 300 | /// </summary> |
| 301 | /// <param name="val">True to hide, false to show</param> |
| 302 | public void SafeHide(bool val) |
| 303 | { |
| 304 | AsyncControls.SafeHide(this, val); |
| 305 | } |
| 306 | |
| 307 | /// <summary> |
| 308 | /// Change the selected index |
| 309 | /// </summary> |
| 310 | /// <param name="control">The control to change</param> |
| 311 | /// <param name="index">The new selected index</param> |
| 312 | public void SetSelectedIndex(ComboBox control, int index) |
| 313 | { |
| 314 | AsyncControls.SetSelectedIndex(this, control, index); |
| 315 | } |
| 316 | |
| 317 | /// <summary> |
| 318 | /// Get the name of the selected tab in a TabControl |
| 319 | /// </summary> |
| 320 | /// <param name="container">The tab container</param> |
| 321 | /// <param name="tabPages">The tab pages</param> |
| 322 | /// <returns>The name of the selected tab</returns> |
| 323 | public string GetSelectedTabName(TabControl container, TabControl.TabPageCollection tabPages) |
| 324 | { |
| 325 | return AsyncControls.GetSelectedTabName(container, tabPages); |
| 326 | } |
| 327 | |
| 328 | /// <summary> |
| 329 | /// Selects the row with the given CecKeypress for a datagrid |
| 330 | /// </summary> |
| 331 | /// <param name="container">The datagrid container</param> |
| 332 | /// <param name="dgView">The datagrid</param> |
| 333 | /// <param name="key">The key to selected</param> |
| 334 | public void SelectKeypressRow(Control container, DataGridView dgView, CecKeypress key) |
| 335 | { |
| 336 | AsyncControls.SelectKeypressRow(container, dgView, key); |
| 337 | } |
| 338 | } |
| 339 | } |