2
0

HandleData.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Jackson Harper ([email protected])
  24. //
  25. //
  26. using System;
  27. using System.Drawing;
  28. using System.Collections;
  29. namespace System.Windows.Forms {
  30. internal class HandleData : IDisposable {
  31. private Queue message_queue;
  32. private Rectangle invalid = Rectangle.Empty;
  33. private Object dc;
  34. private bool has_expose;
  35. private bool is_visible;
  36. #region Constructors and destructors
  37. public HandleData ()
  38. {
  39. is_visible = true;
  40. }
  41. public void Dispose () {
  42. DeviceContext = null;
  43. }
  44. #endregion
  45. #region Paint area handling
  46. public Object DeviceContext {
  47. get { return dc; }
  48. set {
  49. if (value is Graphics) {
  50. if (dc != null) {
  51. ((Graphics)dc).Dispose ();
  52. }
  53. }
  54. dc = value;
  55. }
  56. }
  57. public bool HasExpose {
  58. get {
  59. return has_expose;
  60. }
  61. set {
  62. has_expose = value;
  63. }
  64. }
  65. public bool IsVisible {
  66. get {
  67. return is_visible;
  68. }
  69. set {
  70. is_visible = value;
  71. }
  72. }
  73. public Rectangle InvalidArea {
  74. get {
  75. return invalid;
  76. }
  77. }
  78. public void AddToInvalidArea (int x, int y, int width, int height)
  79. {
  80. if (invalid == Rectangle.Empty) {
  81. invalid = new Rectangle (x, y, width, height);
  82. return;
  83. }
  84. invalid = Rectangle.Union (invalid, new Rectangle (x, y, width, height));
  85. }
  86. public void AddToInvalidArea (Rectangle r)
  87. {
  88. if (invalid == Rectangle.Empty) {
  89. invalid = r;
  90. return;
  91. }
  92. invalid = Rectangle.Union (invalid, r);
  93. }
  94. public void ClearInvalidArea ()
  95. {
  96. invalid = Rectangle.Empty;
  97. has_expose = false;
  98. }
  99. #endregion // Paint area methods
  100. #region Message storage and retrieval
  101. public bool MessageWaiting {
  102. get {
  103. if ((message_queue == null) || (message_queue.Count == 0)) {
  104. return false;
  105. }
  106. return true;
  107. }
  108. }
  109. public bool GetMessage(ref MSG msg) {
  110. MSG message;
  111. if ((message_queue == null) || (message_queue.Count == 0)) {
  112. return false;
  113. }
  114. message = (MSG)message_queue.Dequeue();
  115. msg = message;
  116. return true;
  117. }
  118. public bool StoreMessage(ref MSG msg) {
  119. MSG message = new MSG();
  120. if (message_queue == null) {
  121. message_queue = new Queue();
  122. }
  123. message = msg;
  124. message_queue.Enqueue(message);
  125. return true;
  126. }
  127. #endregion // Message storage and retrieval
  128. }
  129. }