|
| 1 | +//////////////////////////////////////////////////////////////////////////////// |
| 2 | +// The MIT License (MIT) |
| 3 | +// |
| 4 | +// Copyright (c) 2023 Tim Stair |
| 5 | +// |
| 6 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +// of this software and associated documentation files (the "Software"), to deal |
| 8 | +// in the Software without restriction, including without limitation the rights |
| 9 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +// copies of the Software, and to permit persons to whom the Software is |
| 11 | +// furnished to do so, subject to the following conditions: |
| 12 | +// |
| 13 | +// The above copyright notice and this permission notice shall be included in all |
| 14 | +// copies or substantial portions of the Software. |
| 15 | +// |
| 16 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +// SOFTWARE. |
| 23 | +//////////////////////////////////////////////////////////////////////////////// |
| 24 | + |
| 25 | +using System; |
| 26 | +using System.Collections.Generic; |
| 27 | +using System.Windows.Forms; |
| 28 | + |
| 29 | +namespace KeyCap.Forms |
| 30 | +{ |
| 31 | + class ControlActiveProcessor |
| 32 | + { |
| 33 | + public Control Self { get; private set; } |
| 34 | + public Action<bool> OnActiveChange { get; set; } |
| 35 | + public List<Control> disabledControls { get; set; } |
| 36 | + public List<Control> enabledControls { get; set; } |
| 37 | + public List<CheckBox> uncheckedControls { get; set; } |
| 38 | + public List<CheckBox> checkedControls { get; set; } |
| 39 | + |
| 40 | + public ControlActiveProcessor(Control zControl) |
| 41 | + { |
| 42 | + Self = zControl; |
| 43 | + disabledControls = new List<Control>(); |
| 44 | + enabledControls = new List<Control>(); |
| 45 | + uncheckedControls = new List<CheckBox>(); |
| 46 | + checkedControls = new List<CheckBox>(); |
| 47 | + } |
| 48 | + |
| 49 | + public void Process(bool bActive) |
| 50 | + { |
| 51 | + foreach (var zControl in disabledControls) |
| 52 | + { |
| 53 | + zControl.Enabled = !bActive; |
| 54 | + } |
| 55 | + foreach (var zControl in enabledControls) |
| 56 | + { |
| 57 | + zControl.Enabled = bActive; |
| 58 | + } |
| 59 | + if (bActive) |
| 60 | + { |
| 61 | + foreach (var zCheckBox in uncheckedControls) |
| 62 | + { |
| 63 | + zCheckBox.Checked = false; |
| 64 | + } |
| 65 | + |
| 66 | + foreach (var zCheckBox in checkedControls) |
| 67 | + { |
| 68 | + zCheckBox.Checked = true; |
| 69 | + } |
| 70 | + |
| 71 | + Self.Enabled = true; |
| 72 | + } |
| 73 | + |
| 74 | + OnActiveChange?.Invoke(bActive); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments