2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
34 using System.Windows.Forms;
36 using LibCECTray.controller.applications;
38 namespace LibCECTray.ui
41 /// Form that implements IAsyncControls
43 class AsyncForm : Form, IAsyncControls
46 /// Changes the ShowInTaskbar value
48 /// <param name="val">True to show, false to hide</param>
49 public void SetShowInTaskbar(bool val)
53 SetShowInTaskbarCallback d = SetShowInTaskbar;
56 Invoke(d, new object[] { val });
65 private delegate void SetShowInTaskbarCallback(bool val);
68 /// Enable or disable a control
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)
74 AsyncControls.SetControlEnabled(this, control, val);
78 /// Change the text label of a control
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)
84 AsyncControls.SetControlText(this, control, val);
88 /// Changes the toolstrip menu text
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)
94 AsyncControls.SetToolStripMenuText(this, item, val);
98 /// Change the checked status of a checkbox
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)
104 AsyncControls.SetCheckboxChecked(this, control, val);
108 /// Change the checked status of an item in a CheckedListBox
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)
115 AsyncControls.SetCheckboxItemChecked(this, control, index, val);
119 /// Changes the progress value of a progress bar
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)
125 AsyncControls.SetProgressValue(this, control, val);
129 /// Replaces the items of a combobox
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)
136 AsyncControls.SetComboBoxItems(this, control, selectedIndex, val);
140 /// Make a control visible or invisible
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)
146 AsyncControls.SetControlVisible(this, control, val);
150 /// Display a new dialog
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)
156 AsyncControls.DisplayDialog(this, control, modal);
162 /// <param name="val">True to hide, false to show</param>
163 public void SafeHide(bool val)
165 AsyncControls.SafeHide(this, val);
169 /// Change the selected index
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)
175 AsyncControls.SetSelectedIndex(this, control, index);
179 /// Get the name of the selected tab in a TabControl
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)
186 return AsyncControls.GetSelectedTabName(container, tabPages);
190 /// Selects the row with the given CecKeypress for a datagrid
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)
197 AsyncControls.SelectKeypressRow(container, dgView, key);
202 /// TabPage that implements IAsyncControls
204 class AsyncTabPage : TabPage, IAsyncControls
207 /// Enable or disable a control
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)
213 AsyncControls.SetControlEnabled(this, control, val);
217 /// Change the text label of a control
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)
223 AsyncControls.SetControlText(this, control, val);
227 /// Changes the toolstrip menu text
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)
233 AsyncControls.SetToolStripMenuText(this, item, val);
237 /// Change the checked status of a checkbox
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)
243 AsyncControls.SetCheckboxChecked(this, control, val);
247 /// Change the checked status of an item in a CheckedListBox
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)
254 AsyncControls.SetCheckboxItemChecked(this, control, index, val);
258 /// Changes the progress value of a progress bar
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)
264 AsyncControls.SetProgressValue(this, control, val);
268 /// Replaces the items of a combobox
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)
275 AsyncControls.SetComboBoxItems(this, control, selectedIndex, val);
279 /// Make a control visible or invisible
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)
285 AsyncControls.SetControlVisible(this, control, val);
289 /// Display a new dialog
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)
295 AsyncControls.DisplayDialog(this, control, modal);
301 /// <param name="val">True to hide, false to show</param>
302 public void SafeHide(bool val)
304 AsyncControls.SafeHide(this, val);
308 /// Change the selected index
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)
314 AsyncControls.SetSelectedIndex(this, control, index);
318 /// Get the name of the selected tab in a TabControl
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)
325 return AsyncControls.GetSelectedTabName(container, tabPages);
329 /// Selects the row with the given CecKeypress for a datagrid
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)
336 AsyncControls.SelectKeypressRow(container, dgView, key);