HandleData.cs 3.0 KB

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