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/
33 using System.Windows.Forms;
35 using LibCECTray.Properties;
37 namespace LibCECTray.settings
40 /// A setting of type CecDeviceType that can be persisted in the registry
42 class CECSettingDeviceType : CECSettingNumeric
44 public CECSettingDeviceType(string keyName, string friendlyName, CecDeviceType defaultValue, SettingChangedHandler changedHandler) :
45 base(CECSettingType.DeviceType, keyName, friendlyName, (int)defaultValue, changedHandler, OnFormat)
47 LowerLimit = (int) CecDeviceType.Tv;
48 UpperLimit = (int) CecDeviceType.AudioSystem;
51 private static void OnFormat(object sender, ListControlConvertEventArgs listControlConvertEventArgs)
54 if (int.TryParse((string)listControlConvertEventArgs.Value, out iValue))
55 listControlConvertEventArgs.Value = FormatValue(iValue);
58 public new CecDeviceType Value
60 get { return base.Value >= (int)CecDeviceType.Tv && base.Value <= (int)CecDeviceType.AudioSystem ? (CecDeviceType)base.Value : CecDeviceType.Reserved; }
63 base.Value = (int)value;
64 if (Form == null) return;
67 case CecDeviceType.RecordingDevice:
68 Form.SetControlText(ValueControl, Resources.device_recorder);
70 case CecDeviceType.PlaybackDevice:
71 Form.SetControlText(ValueControl, Resources.device_playbackdevice);
73 case CecDeviceType.Tuner:
74 Form.SetControlText(ValueControl, Resources.device_tuner);
77 Form.SetControlText(ValueControl, Resources.device_recorder);
83 public new CecDeviceType DefaultValue
85 get { return base.DefaultValue >= (int)CecDeviceType.Tv && base.DefaultValue <= (int)CecDeviceType.AudioSystem ? (CecDeviceType)base.DefaultValue : CecDeviceType.Reserved; }
86 set { base.DefaultValue = (int)value; }
89 private static string FormatValue(int value)
91 switch ((CecDeviceType)value)
93 case CecDeviceType.Tv:
94 return Resources.device_tv;
95 case CecDeviceType.PlaybackDevice:
96 return Resources.device_playbackdevice;
97 case CecDeviceType.AudioSystem:
98 return Resources.device_audiosystem;
99 case CecDeviceType.RecordingDevice:
100 return Resources.device_recorder;
101 case CecDeviceType.Tuner:
102 return Resources.device_tuner;
103 case CecDeviceType.Reserved:
104 return Resources.device_reserved;
106 return Resources.unknown;
109 protected override bool AllowedValue(int value)
111 if ((CecDeviceType)value == CecDeviceType.Reserved)
113 for (var i = 0; i < _allowedTypeMask.Types.Length; i++)
115 if (_allowedTypeMask.Types[i] == (CecDeviceType) value)
121 private CecDeviceTypeList _allowedTypeMask;
122 public CecDeviceTypeList AllowedTypeMask
126 return _allowedTypeMask ?? (_allowedTypeMask = new CecDeviceTypeList
131 CecDeviceType.Tv, CecDeviceType.PlaybackDevice,
132 CecDeviceType.RecordingDevice,
133 CecDeviceType.AudioSystem, CecDeviceType.Tuner
139 _allowedTypeMask = value;