2
0

MenuCommand.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // System.ComponentModel.Design.MenuCommand.cs
  3. //
  4. // Authors:
  5. // Alejandro Sánchez Acosta <[email protected]>
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) Alejandro Sánchez Acosta
  9. // (C) 2003 Andreas Nahr
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System.Runtime.InteropServices;
  32. namespace System.ComponentModel.Design
  33. {
  34. [ComVisible(true)]
  35. public class MenuCommand
  36. {
  37. private EventHandler handler;
  38. private CommandID command;
  39. private bool ischecked = false;
  40. private bool enabled = true;
  41. private bool issupported = true;
  42. private bool visible = true;
  43. public MenuCommand (EventHandler handler, CommandID command)
  44. {
  45. this.handler = handler;
  46. this.command = command;
  47. }
  48. public virtual bool Checked {
  49. get {
  50. return ischecked;
  51. }
  52. set {
  53. if (ischecked != value) {
  54. ischecked = value;
  55. OnCommandChanged (EventArgs.Empty);
  56. }
  57. }
  58. }
  59. public virtual CommandID CommandID {
  60. get {
  61. return command;
  62. }
  63. }
  64. public virtual bool Enabled {
  65. get {
  66. return enabled;
  67. }
  68. set {
  69. if (enabled != value)
  70. {
  71. enabled = value;
  72. OnCommandChanged (EventArgs.Empty);
  73. }
  74. }
  75. }
  76. [MonoTODO]
  77. public virtual int OleStatus {
  78. get {
  79. // This is calcualted from the other properties, but the docs to not tell how
  80. // Default seems to be "3", but changes with diffentent set properties
  81. return 3;
  82. }
  83. }
  84. public virtual bool Supported {
  85. get {
  86. return issupported;
  87. }
  88. set {
  89. issupported = value;
  90. }
  91. }
  92. public virtual bool Visible {
  93. get {
  94. return visible;
  95. }
  96. set {
  97. visible = value;
  98. }
  99. }
  100. public virtual void Invoke()
  101. {
  102. // FIXME Not sure if this invocation is what should be done here
  103. if (handler != null)
  104. handler (this, EventArgs.Empty);
  105. }
  106. protected virtual void OnCommandChanged (EventArgs e)
  107. {
  108. if (CommandChanged != null)
  109. CommandChanged (this, e);
  110. }
  111. public override string ToString()
  112. {
  113. // MS runtime produces a NullReferenceException here if CommandID property == null
  114. // which I guess isn't a good idea (throwing exceptions in ToStrings???) - bug in MS??
  115. string commandpart = string.Empty;
  116. if (command != null)
  117. commandpart = command.ToString ();
  118. commandpart = string.Concat (commandpart, " : ");
  119. if (this.Supported)
  120. commandpart = string.Concat (commandpart, "Supported");
  121. if (this.Enabled)
  122. commandpart = string.Concat (commandpart, "|Enabled");
  123. if (this.Visible)
  124. commandpart = string.Concat (commandpart, "|Visible");
  125. if (this.Checked)
  126. commandpart = string.Concat (commandpart, "|Checked");
  127. return commandpart;
  128. }
  129. public event EventHandler CommandChanged;
  130. }
  131. }