8using System.Collections.Generic;
58 bool isInside =
false;
75 return String.Format(
"x1={0,2}, y1={1,2}, x2={2,2}, y2={3,2}",
Left,
Top,
Right,
Bottom);
108 private Dictionary<MessageType, MessageHandler>
_messageHandlers =
new Dictionary<MessageType, MessageHandler>();
247 bool messageProcessed =
false;
254 Console.WriteLine(
" --> Button Down in \"{0}\", window selected",
_title);
262 Console.WriteLine(
" --> Button Down not in \"{0}\", window deselected",
_title);
265 return messageProcessed;
277 bool messageProcessed =
false;
285 messageProcessed =
true;
288 Console.WriteLine(
" --> Button Up in \"{0}\" close box, sending Close message",
_title);
293 Console.WriteLine(
" --> Button Up in \"{0}\", no further action taken",
_title);
297 return messageProcessed;
309 bool messageProcessed =
false;
312 Console.WriteLine(
" --> Close in \"{0}\", removing window from handler chain",
_title);
315 messageProcessed =
true;
321 Console.WriteLine(
" --> Close seen in \"{0}\" but this window is not selected, ignoring",
_title);
323 return messageProcessed;
356 bool messageProcessed =
false;
361 messageProcessed = handler(message);
364 return messageProcessed;
Represents a list of handlers that all implement the IMessageHandler interface. This list can be dyna...
void AddHandler(IMessageHandler window)
Add an instance of the IMessageHandler interface to end of the list of handlers, protected by a multi...
void RemoveHandler(IMessageHandler window)
Remove an instance of the IMessageHandler interface from the list, protected by a multi-threading loc...
void SendMessage(Message message)
Send a message to each of the handlers in the list, protected by a multi-threading lock.
Represents a rectangular region that can handle messages directed to that region.
WindowRectangle _closeBox
Position of the close window within the window box, although the coordinates are also global coordina...
static int _nextWindowId
Used for assigning a unique ID to each created window.
bool _HandleButtonUpMessage(Message message)
Helper method to handle the ButtonUp message.
bool _PointInWindow(MessagePosition position)
Determine if the specified point is in this MessageWindow's region.
bool _HandleButtonDownMessage(Message message)
Helper method to handle the ButtonDown message.
MessageWindow(int windowId, string title, int x, int y, int width, int height, HandlerChain handlerChain)
Constructor.
delegate bool MessageHandler(Message message)
bool ProcessMessage(Message message)
Processes a message.
static MessageWindow CreateWindow(string title, int x, int y, int width, int height, HandlerChain handlerChain)
Creates an instance of the MessageWindow class with the specified attributes and adds the new instanc...
bool _selected
Whether this window has been selected (a button click occurred within the window).
HandlerChain _handlerChain
The HandlerChain to which this window belongs (as an IMessageHandler object).
override string ToString()
Convert this handler to a string.
int _windowId
Unique ID of this window.
WindowRectangle _windowBox
Position of this window in global coordinates.
string _title
Title/Name of this window.
bool _HandleCloseMessage(Message message)
Helper method to handle the Close message.
bool _PointInCloseBox(MessagePosition position)
Determine if the specified point is in this MessageWindow's "close" region.
Dictionary< MessageType, MessageHandler > _messageHandlers
Maps a message type to a handler method of type MessageHandler.
int ID
Returns the ID of the message handler.
Represents a rectangular region, with upper left and lower right coordinates.
WindowRectangle(int x, int y, int width, int height)
Constructor.
override string ToString()
Convert this rectangle to a string.
bool PointInside(MessagePosition point)
Determine if the given point is in the rectangle.
Represents a handler in a chain of handlers. All objects that participate in the HandlerChain class m...
The namespace containing all Design Pattern Examples implemented in C#.
MessageType
Type of message handled by MessageWindow.
Represents a message sent to the windows. A message contains a type and a position.
MessagePosition Position
Position of message when the message was sent. In a real system, this would generally represent the p...
MessageType MessageType
Value from the MessageType enumeration indicating the type of this message.
Position of the message in global coordinates (same scope of coordinates as windows)....