* X11Keyboard.cs: Detect and use the num lock mask.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / HandleData.cs
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 (jackson@ximian.com)
24 //
25 //
26
27
28 using System;
29 using System.Drawing;
30 using System.Collections;
31
32 namespace System.Windows.Forms {
33
34         internal class HandleData : IDisposable {
35
36                 private Queue           message_queue;
37                 private Rectangle       invalid = Rectangle.Empty;
38                 private Object          dc;
39                 private bool            has_expose;
40                 private bool            is_visible;
41
42                 #region Constructors and destructors
43                 public HandleData ()
44                 {
45                         is_visible = true;
46                 }
47
48                 public void Dispose () {
49                         DeviceContext = null;
50                 }
51                 #endregion
52
53                 #region Paint area handling
54                 public Object DeviceContext {
55                         get { return dc; }
56                         set {
57                                 if (value is Graphics) {
58                                         if (dc != null) {
59                                                 ((Graphics)dc).Dispose ();
60                                         }
61                                 }
62                                 dc = value;
63                         }
64                 }
65
66                 public bool HasExpose {
67                         get {
68                                 return has_expose;
69                         }
70                         set {
71                                 has_expose = value;
72                         }
73                 }
74
75                 public bool IsVisible {
76                         get {
77                                 return is_visible;
78                         }
79                         set {
80                                 is_visible = value;
81                         }
82                 }
83
84                 public Rectangle InvalidArea {
85                         get {
86                                 return invalid;
87                         }
88                 }
89                 public void AddToInvalidArea (int x, int y, int width, int height)
90                 {
91                         if (invalid == Rectangle.Empty) {
92                                 invalid = new Rectangle (x, y, width, height);
93                                 return;
94                         }
95                         invalid = Rectangle.Union (invalid, new Rectangle (x, y, width, height));
96                 }
97
98                 public void AddToInvalidArea (Rectangle r)
99                 {
100                         if (invalid == Rectangle.Empty) {
101                                 invalid = r;
102                                 return;
103                         }
104                         invalid = Rectangle.Union (invalid, r);
105                 }
106
107                 public void ClearInvalidArea ()
108                 {
109                         invalid = Rectangle.Empty;
110                         has_expose = false;
111                 }
112                 #endregion      // Paint area methods
113
114                 #region Message storage and retrieval
115                 public bool MessageWaiting {
116                         get {
117                                 if ((message_queue == null) || (message_queue.Count == 0)) {
118                                         return false;
119                                 }
120                                 return true;
121                         }
122                 }
123
124                 public bool GetMessage(ref MSG msg) {
125                         MSG     message;
126
127                         if ((message_queue == null) || (message_queue.Count == 0)) {
128                                 return false;
129                         }
130
131                         message = (MSG)message_queue.Dequeue();
132                         msg = message;
133
134                         return true;
135                 }
136
137                 public bool StoreMessage(ref MSG msg) {
138                         MSG message = new MSG();
139
140                         if (message_queue == null) {
141                                 message_queue = new Queue();
142                         }
143
144                         message = msg;
145                         message_queue.Enqueue(message);
146
147                         return true;
148                 }
149                 #endregion      // Message storage and retrieval
150         }
151 }
152