Represents a rectangular region that can handle messages directed to that region. More...
Public Member Functions | |
bool | ProcessMessage (Message message) |
Processes a message. | |
override string | ToString () |
Convert this handler to a string. | |
bool | ProcessMessage (Message message) |
Called with a message on each window. | |
string | ToString () |
Convert the handler to a string. | |
Static Public Member Functions | |
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 instance to the given HandlerChain object. | |
Properties | |
int | ID [get] |
Returns the ID of the message handler. | |
Private Member Functions | |
delegate bool | MessageHandler (Message message) |
bool | _PointInWindow (MessagePosition position) |
Determine if the specified point is in this MessageWindow's region. | |
bool | _PointInCloseBox (MessagePosition position) |
Determine if the specified point is in this MessageWindow's "close" region. | |
MessageWindow (int windowId, string title, int x, int y, int width, int height, HandlerChain handlerChain) | |
Constructor. | |
bool | _HandleButtonDownMessage (Message message) |
Helper method to handle the ButtonDown message. | |
bool | _HandleButtonUpMessage (Message message) |
Helper method to handle the ButtonUp message. | |
bool | _HandleCloseMessage (Message message) |
Helper method to handle the Close message. | |
Private Attributes | |
Dictionary< MessageType, MessageHandler > | _messageHandlers = new Dictionary<MessageType, MessageHandler>() |
Maps a message type to a handler method of type MessageHandler. | |
int | _windowId |
Unique ID of this window. | |
string | _title |
Title/Name of this window. | |
WindowRectangle | _windowBox |
Position of this window in global coordinates. | |
WindowRectangle | _closeBox |
Position of the close window within the window box, although the coordinates are also global coordinates to eliminate the need to convert between window and global coordinates. | |
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). | |
Static Private Attributes | |
const int | CLOSE_WIDTH = 2 |
const int | CLOSE_HEIGHT = 2 |
static int | _nextWindowId = 1 |
Used for assigning a unique ID to each created window. | |
Represents a rectangular region that can handle messages directed to that region.
Note: The IMessageHandler interface is an example of a Facade design pattern, where the complexity of the MessageWindow is exposed only through a few methods to a system that only needs to deal with those few methods.
Definition at line 97 of file HandlerChain_MessageWindow_Class.cs.
|
inlineprivate |
Constructor.
windowId | Unique ID of the window to use. |
title | Title of the window. |
x | Global x position of the upper left corner of the window's region. |
y | Global y position of the upper left corner of the window's region. |
width | Width of the window's region. |
height | Height of the window's region. |
handlerChain | A HandlerChain object that will be used for removal of this window when it is closed. |
Definition at line 211 of file HandlerChain_MessageWindow_Class.cs.
References MessageWindow._closeBox, MessageWindow._HandleButtonDownMessage(), MessageWindow._HandleButtonUpMessage(), MessageWindow._HandleCloseMessage(), MessageWindow._handlerChain, MessageWindow._messageHandlers, MessageWindow._selected, MessageWindow._title, MessageWindow._windowBox, MessageWindow._windowId, MessageWindow.CLOSE_HEIGHT, MessageWindow.CLOSE_WIDTH, WindowRectangle.Right, and WindowRectangle.Top.
|
inlineprivate |
Helper method to handle the ButtonDown message.
message | A Message object describing the ButtonDown message. |
Definition at line 242 of file HandlerChain_MessageWindow_Class.cs.
References MessageWindow._PointInWindow(), MessageWindow._selected, MessageWindow._title, and Message.Position.
Referenced by MessageWindow.MessageWindow().
|
inlineprivate |
Helper method to handle the ButtonUp message.
message | A Message object describing the ButtonUp message. |
Definition at line 275 of file HandlerChain_MessageWindow_Class.cs.
References MessageWindow._handlerChain, MessageWindow._PointInCloseBox(), MessageWindow._PointInWindow(), MessageWindow._selected, MessageWindow._title, Message.Position, and HandlerChain.SendMessage().
Referenced by MessageWindow.MessageWindow().
|
inlineprivate |
Helper method to handle the Close message.
message | A Message object describing the Close message. |
Definition at line 307 of file HandlerChain_MessageWindow_Class.cs.
References MessageWindow._handlerChain, MessageWindow._selected, MessageWindow._title, and HandlerChain.RemoveHandler().
Referenced by MessageWindow.MessageWindow().
|
inlineprivate |
Determine if the specified point is in this MessageWindow's "close" region.
position | The point to examine. |
Definition at line 193 of file HandlerChain_MessageWindow_Class.cs.
References MessageWindow._closeBox, and WindowRectangle.PointInside().
Referenced by MessageWindow._HandleButtonUpMessage().
|
inlineprivate |
Determine if the specified point is in this MessageWindow's region.
position | The global coordinate to examine. |
Definition at line 180 of file HandlerChain_MessageWindow_Class.cs.
References MessageWindow._windowBox, and WindowRectangle.PointInside().
Referenced by MessageWindow._HandleButtonDownMessage(), and MessageWindow._HandleButtonUpMessage().
|
inlinestatic |
Creates an instance of the MessageWindow class with the specified attributes and adds the new instance to the given HandlerChain object.
title | Title of the MessageWindow. |
x | X position of the upper left corner of the window's region. |
y | Y position of the upper left corner of hte window's region. |
width | Width of the window's region. |
height | Height of the window's region. |
handlerChain | A HandlerChain object that will be given the window. |
Each MessageWindow instance is assigned a unique ID, which is required by the HandlerChain object.
Definition at line 165 of file HandlerChain_MessageWindow_Class.cs.
References MessageWindow._nextWindowId, and HandlerChain.AddHandler().
Referenced by HandlerChain_Exercise._HandlerChain_ConstructWindowChain().
|
private |
Referenced by MessageWindow.ProcessMessage().
|
inline |
Processes a message.
message | The Message object to process. |
The message types are mapped to handlers in the MessageWindow constructor and stored in the _messageHandlers dictionary.
Implements IMessageHandler.
Definition at line 354 of file HandlerChain_MessageWindow_Class.cs.
References MessageWindow._messageHandlers, MessageWindow.MessageHandler(), and Message.MessageType.
|
inline |
Convert this handler to a string.
Implements IMessageHandler.
Definition at line 372 of file HandlerChain_MessageWindow_Class.cs.
References MessageWindow._selected, MessageWindow._title, MessageWindow._windowBox, and MessageWindow.ID.
|
private |
Position of the close window within the window box, although the coordinates are also global coordinates to eliminate the need to convert between window and global coordinates.
Definition at line 130 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow._PointInCloseBox(), and MessageWindow.MessageWindow().
|
private |
The HandlerChain to which this window belongs (as an IMessageHandler object).
Definition at line 141 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow._HandleButtonUpMessage(), MessageWindow._HandleCloseMessage(), and MessageWindow.MessageWindow().
|
private |
Maps a message type to a handler method of type MessageHandler.
Definition at line 108 of file HandlerChain_MessageWindow_Class.cs.
Referenced by HandlerChain.AddHandler(), MessageWindow.MessageWindow(), MessageWindow.ProcessMessage(), HandlerChain.RemoveHandler(), HandlerChain.SendMessage(), and HandlerChain.ToString().
|
staticprivate |
Used for assigning a unique ID to each created window.
Definition at line 147 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow.CreateWindow().
|
private |
Whether this window has been selected (a button click occurred within the window).
Definition at line 136 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow._HandleButtonDownMessage(), MessageWindow._HandleButtonUpMessage(), MessageWindow._HandleCloseMessage(), MessageWindow.MessageWindow(), and MessageWindow.ToString().
|
private |
Title/Name of this window.
Definition at line 118 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow._HandleButtonDownMessage(), MessageWindow._HandleButtonUpMessage(), MessageWindow._HandleCloseMessage(), MessageWindow.MessageWindow(), and MessageWindow.ToString().
|
private |
Position of this window in global coordinates.
Definition at line 123 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow._PointInWindow(), MessageWindow.MessageWindow(), and MessageWindow.ToString().
|
private |
Unique ID of this window.
Definition at line 113 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow.ID(), and MessageWindow.MessageWindow().
|
staticprivate |
Definition at line 101 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow.MessageWindow().
|
staticprivate |
Definition at line 100 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow.MessageWindow().
|
get |
Returns the ID of the message handler.
Implements IMessageHandler.
Definition at line 334 of file HandlerChain_MessageWindow_Class.cs.
Referenced by MessageWindow.ToString().