check_box.vala 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2012-2025 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. using Gtk;
  6. namespace Crown
  7. {
  8. public class CheckBox : Gtk.CheckButton, Property
  9. {
  10. // Data
  11. public bool _stop_emit;
  12. public new void set_inconsistent(bool inconsistent)
  13. {
  14. base.set_inconsistent(inconsistent);
  15. }
  16. public bool is_inconsistent()
  17. {
  18. return this.get_inconsistent();
  19. }
  20. public Value? generic_value()
  21. {
  22. return this.value;
  23. }
  24. public void set_generic_value(Value? val)
  25. {
  26. this.value = (bool)val;
  27. }
  28. public bool value
  29. {
  30. get
  31. {
  32. return this.active;
  33. }
  34. set
  35. {
  36. _stop_emit = true;
  37. this.active = value;
  38. _stop_emit = false;
  39. }
  40. }
  41. // Signals
  42. public signal void value_changed();
  43. public CheckBox()
  44. {
  45. // Data
  46. _stop_emit = false;
  47. this.toggled.connect(on_value_changed);
  48. }
  49. private void on_value_changed()
  50. {
  51. if (base.get_inconsistent()) {
  52. base.set_inconsistent(false);
  53. this.value = true;
  54. }
  55. if (!_stop_emit)
  56. value_changed();
  57. }
  58. }
  59. } /* namespace Crown */