2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 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.Properties;
39 namespace LibCECTray.settings
42 /// A setting of type CecLogicalAddresses that can be persisted in the registry
44 class CECSettingLogicalAddresses : CECSettingNumeric
46 public CECSettingLogicalAddresses(string keyName, string friendlyName, CecLogicalAddresses defaultValue, SettingChangedHandler changedHandler) :
47 base(CECSettingType.LogicalAddresses, keyName, friendlyName, SerialiseLogicalAddresses(defaultValue), changedHandler)
51 private static int SerialiseLogicalAddresses(CecLogicalAddresses addresses)
54 for (int addr = (int)CecLogicalAddress.Tv; addr <= (int)CecLogicalAddress.Broadcast; addr++)
56 if (addresses.IsSet((CecLogicalAddress)addr))
58 retVal += (int)Math.Pow(2, addr);
65 private static CecLogicalAddresses DeserialiseLogicalAddresses(int addresses)
67 CecLogicalAddresses retVal = new CecLogicalAddresses();
71 for (int addr = (int)CecLogicalAddress.Tv; addr <= (int)CecLogicalAddress.Broadcast; addr++)
73 int val = (int)Math.Pow(2, addr);
74 if ((addresses & val) == val)
75 retVal.Set((CecLogicalAddress)addr);
81 public new CecLogicalAddresses Value
83 get { return DeserialiseLogicalAddresses(base.Value); }
86 base.Value = SerialiseLogicalAddresses(value);
87 if (Form == null) return;
88 for (int iPtr = 0; iPtr < 15; iPtr++)
89 Form.SetCheckboxItemChecked(ValueControl, iPtr, value.IsSet((CecLogicalAddress) iPtr));
93 public new CecLogicalAddresses DefaultValue
95 get { return DeserialiseLogicalAddresses(base.DefaultValue); }
96 set { base.DefaultValue = SerialiseLogicalAddresses(value); }
99 public static CecLogicalAddress GetLogicalAddressFromString(string name)
101 switch (name.Substring(0, 1).ToLower())
104 return CecLogicalAddress.Tv;
106 return CecLogicalAddress.RecordingDevice1;
108 return CecLogicalAddress.RecordingDevice2;
110 return CecLogicalAddress.Tuner1;
112 return CecLogicalAddress.PlaybackDevice1;
114 return CecLogicalAddress.AudioSystem;
116 return CecLogicalAddress.Tuner2;
118 return CecLogicalAddress.Tuner3;
120 return CecLogicalAddress.PlaybackDevice2;
122 return CecLogicalAddress.RecordingDevice3;
124 return CecLogicalAddress.Tuner4;
126 return CecLogicalAddress.PlaybackDevice3;
128 return CecLogicalAddress.Reserved1;
130 return CecLogicalAddress.Reserved2;
132 return CecLogicalAddress.FreeUse;
134 return CecLogicalAddress.Broadcast;
136 return CecLogicalAddress.Unknown;
140 public new CheckedListBox ValueControl
144 if (BaseValueControl == null)
146 CheckedListBox control = new CheckedListBox
148 FormattingEnabled = true,
150 Size = new System.Drawing.Size(118, 94),
151 Enabled = InitialEnabledValue
153 control.Items.AddRange(new object[] {
154 "0: " + Resources.device_tv,
155 "1: " + Resources.device_recorder + " 1",
156 "2: " + Resources.device_recorder + " 2",
157 "3: " + Resources.device_tuner + " 1",
158 "4: " + Resources.device_playbackdevice + " 1",
159 "5: " + Resources.device_audiosystem,
160 "6: " + Resources.device_tuner + " 2",
161 "7: " + Resources.device_tuner + " 3",
162 "8: " + Resources.device_playbackdevice + " 2",
163 "9: " + Resources.device_recorder + " 3",
164 "A: " + Resources.device_tuner + " 4",
165 "B: " + Resources.device_playbackdevice + " 3",
166 "C: " + Resources.device_reserved + " 1",
167 "D: " + Resources.device_reserved + " 2",
168 "E: " + Resources.device_free_use,
169 "F: " + Resources.device_broadcast});
170 control.SelectedValueChanged += delegate
172 CecLogicalAddresses addr = new CecLogicalAddresses();
173 foreach (var item in ((CheckedListBox)BaseValueControl).CheckedItems)
175 string c = item as string;
176 addr.Set(GetLogicalAddressFromString(c));
180 BaseValueControl = control;
182 return BaseValueControl as CheckedListBox;
186 public void ReplaceControls(IAsyncControls form, Control.ControlCollection controls, Control labelControl, CheckedListBox valueControl)
189 ReplaceControl(controls, labelControl, Label);
190 ReplaceControl(controls, valueControl, ValueControl);
193 public void ReplaceControls(IAsyncControls form, Control.ControlCollection controls, CheckedListBox valueControl)
196 ReplaceControl(controls, valueControl, ValueControl);
199 public override bool Enabled
204 Form.SetControlEnabled(ValueControl, value);
206 get { return base.Enabled; }