HandleData.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #region Constructors and destructors
  36. public HandleData ()
  37. {
  38. }
  39. public void Dispose () {
  40. DeviceContext = null;
  41. }
  42. #endregion
  43. #region Paint area handling
  44. public Object DeviceContext {
  45. get { return dc; }
  46. set {
  47. if (value is Graphics) {
  48. if (dc != null) {
  49. ((Graphics)dc).Dispose ();
  50. }
  51. }
  52. dc = value;
  53. }
  54. }
  55. public bool HasExpose {
  56. get {
  57. return has_expose;
  58. }
  59. set {
  60. has_expose = value;
  61. }
  62. }
  63. public Rectangle InvalidArea {
  64. get {
  65. return invalid;
  66. }
  67. }
  68. public void AddToInvalidArea (int x, int y, int width, int height)
  69. {
  70. if (invalid == Rectangle.Empty) {
  71. invalid = new Rectangle (x, y, width, height);
  72. return;
  73. }
  74. invalid = Rectangle.Union (invalid, new Rectangle (x, y, width, height));
  75. }
  76. public void AddToInvalidArea (Rectangle r)
  77. {
  78. if (invalid == Rectangle.Empty) {
  79. invalid = r;
  80. return;
  81. }
  82. invalid = Rectangle.Union (invalid, r);
  83. }
  84. public void ClearInvalidArea ()
  85. {
  86. invalid = Rectangle.Empty;
  87. has_expose = false;
  88. }
  89. #endregion // Paint area methods
  90. #region Message storage and retrieval
  91. public bool MessageWaiting {
  92. get {
  93. if ((message_queue == null) || (message_queue.Count == 0)) {
  94. return false;
  95. }
  96. return true;
  97. }
  98. }
  99. public bool GetMessage(ref MSG msg) {
  100. MSG message;
  101. if ((message_queue == null) || (message_queue.Count == 0)) {
  102. return false;
  103. }
  104. message = (MSG)message_queue.Dequeue();
  105. msg = message;
  106. return true;
  107. }
  108. public bool StoreMessage(ref MSG msg) {
  109. MSG message = new MSG();
  110. if (message_queue == null) {
  111. message_queue = new Queue();
  112. }
  113. message = msg;
  114. message_queue.Enqueue(message);
  115. return true;
  116. }
  117. #endregion // Message storage and retrieval
  118. }
  119. }