Declaration of the MessageWindow structure, along with the implementation of the support functions, MessageWindow_Create(), MessageWindow_Destroy(), MessageWindow_ProcessMessage(), and MessageWindow_ToString(), as used in the HandlerChain Pattern. More...
#include <stdlib.h>
#include <stdio.h>
#include "helpers/formatstring.h"
#include "HandlerChain_WindowRectangle.h"
#include "HandlerChain_HandlerFunctions.h"
#include "HandlerChain_MessageWindow.h"
Go to the source code of this file.
Classes | |
struct | _Window |
Represents a window in an arbitrary space. It has an ID, title, and position. A close box is within the window's rectangle. The window can be selected by sending a button down message with the position within this window. If a button down message occurs outside this window, it is deselected. More... | |
Typedefs | |
typedef struct _Window | MessageWindow |
Alias for struct _Window, which represents a window in an arbitrary space. It has an ID, title, and position. A close box is within the window's rectangle. The window can be selected by sending a button down message with the position within this window. If a button down message occurs outside this window, it is deselected. | |
Functions | |
static void | _AppendWindowToList (MessageWindow *window) |
Helper function to append the given MessageWindow to the list of MessageWindow objects. | |
static void | _RemoveWindowFromList (MessageWindow *window) |
Helper function to remove the given MessageWindow object from the linked list of MessageWindow objects. | |
static MessageWindow * | _FindWindow (int windowId) |
Helper function to find a MessageWindow given the window's ID. | |
static bool | _HandleButtonDownMessage (MessageWindow *window, Message *message) |
Helper function to handle the ButtonDown message. | |
static bool | _HandleButtonUpMessage (MessageWindow *window, Message *message) |
Helper function to handle the ButtonUp message. | |
static bool | _HandleCloseMessage (MessageWindow *window, Message *message) |
Helper function to handle the Close message. | |
static bool | _HandleDestroyMessage (MessageWindow *window, Message *message) |
Helper function to trigger the destruction of the window. The window is destroyed and can no longer receive any messages. | |
int | MessageWindow_Create (const char *title, int x, int y, int w, int h) |
Create a MessageWindow object with the given properties and return the ID of the object. | |
void | MessageWindow_Destroy (int windowId) |
Destroy the MessageWindow object with the given ID. Removes the window from any message handling as well. | |
bool | MessageWindow_ProcessMessage (int windowId, Message *message) |
Pass a Message object to a window for processing. | |
bool | MessageWindow_ToString (int windowId, DynamicString *output) |
Convert the specified window to a string representation. | |
Variables | |
const int | CLOSE_WIDTH = 2 |
Width of the close region in the window. | |
const int | CLOSE_HEIGHT = 2 |
Height of the close region in the window. | |
static MessageWindow * | _windowList = NULL |
List of all created MessageWindow objects, in a double-linked list. | |
static int | _nextWindowId = 1 |
The next ID to use for a new window. | |
Declaration of the MessageWindow structure, along with the implementation of the support functions, MessageWindow_Create(), MessageWindow_Destroy(), MessageWindow_ProcessMessage(), and MessageWindow_ToString(), as used in the HandlerChain Pattern.
Definition in file HandlerChain_MessageWindow.c.
typedef struct _Window MessageWindow |
Alias for struct _Window, which represents a window in an arbitrary space. It has an ID, title, and position. A close box is within the window's rectangle. The window can be selected by sending a button down message with the position within this window. If a button down message occurs outside this window, it is deselected.
Definition at line 82 of file HandlerChain_MessageWindow.c.
|
static |
Helper function to append the given MessageWindow to the list of MessageWindow objects.
window | A MessageWindow object to append to the list. |
Definition at line 100 of file HandlerChain_MessageWindow.c.
References _windowList, _Window::next, and _Window::prev.
Referenced by MessageWindow_Create().
|
static |
Helper function to find a MessageWindow given the window's ID.
windowId | The ID of the window to find. |
Definition at line 153 of file HandlerChain_MessageWindow.c.
References _Window::_windowId, _windowList, and _Window::next.
Referenced by MessageWindow_Destroy(), MessageWindow_ProcessMessage(), and MessageWindow_ToString().
|
static |
Helper function to handle the ButtonDown message.
window | The MessageWindow that is handling the message |
message | A Message object describing the ButtonDown message. |
Definition at line 183 of file HandlerChain_MessageWindow.c.
References _Window::_selected, _Window::_title, _Window::_windowBox, Message::Position, and WindowRectangle_PointInside().
Referenced by MessageWindow_ProcessMessage().
|
static |
Helper function to handle the ButtonUp message.
window | The MessageWindow that is handling the message |
message | A Message object describing the ButtonUp message. |
Definition at line 221 of file HandlerChain_MessageWindow.c.
References _Window::_closeBox, _Window::_selected, _Window::_title, _Window::_windowBox, _Window::_windowId, Close, HandlerChain_SendMessage(), Message_Initialize(), Message::Position, WindowRectangle_PointInside(), MessagePosition::X, and MessagePosition::Y.
Referenced by MessageWindow_ProcessMessage().
|
static |
Helper function to handle the Close message.
window | The MessageWindow that is handling the message |
message | A Message object describing the Close message. |
Definition at line 261 of file HandlerChain_MessageWindow.c.
References _Window::_selected, _Window::_title, _Window::_windowId, Destroy, HandlerChain_SendMessage(), and Message_Initialize().
Referenced by MessageWindow_ProcessMessage().
|
static |
Helper function to trigger the destruction of the window. The window is destroyed and can no longer receive any messages.
The given MessageWindow is destroyed and can no longer be used after this function returns.
window | The MessageWindow that is handling the message. |
message | The Message object describing the Destroy message. |
Definition at line 299 of file HandlerChain_MessageWindow.c.
References _Window::_selected, _Window::_title, _Window::_windowId, HandlerChain_RemoveWindow(), and MessageWindow_Destroy().
Referenced by MessageWindow_ProcessMessage().
|
static |
Helper function to remove the given MessageWindow object from the linked list of MessageWindow objects.
window | The MessageWindow object to remove from the list. |
Definition at line 123 of file HandlerChain_MessageWindow.c.
References _windowList, _Window::next, and _Window::prev.
Referenced by MessageWindow_Destroy().
int MessageWindow_Create | ( | const char * | title, |
int | x, | ||
int | y, | ||
int | w, | ||
int | h | ||
) |
Create a MessageWindow object with the given properties and return the ID of the object.
title | Title of the window. |
x | Horizontal position of the upper left corner of the window. |
y | Vertical position of the upper left corner of the window. |
w | Width of the window. |
h | Height of the window. |
Definition at line 318 of file HandlerChain_MessageWindow.c.
References _AppendWindowToList(), _Window::_closeBox, _nextWindowId, _Window::_title, _Window::_windowBox, _Window::_windowId, CLOSE_HEIGHT, CLOSE_WIDTH, HandlerChain_AddWindow(), WindowRectangle::Right, WindowRectangle::Top, and WindowRectangle_Initialize().
Referenced by _HandlerChain_ConstructWindowChain().
void MessageWindow_Destroy | ( | int | windowId | ) |
Destroy the MessageWindow object with the given ID. Removes the window from any message handling as well.
windowId | ID of the MessageWindow to destroy. |
Definition at line 354 of file HandlerChain_MessageWindow.c.
References _FindWindow(), and _RemoveWindowFromList().
Referenced by _HandleDestroyMessage().
bool MessageWindow_ProcessMessage | ( | int | windowId, |
Message * | message | ||
) |
Pass a Message object to a window for processing.
windowId | The ID of the window who will get the message. |
message | The Message object to process. |
Definition at line 367 of file HandlerChain_MessageWindow.c.
References _FindWindow(), _HandleButtonDownMessage(), _HandleButtonUpMessage(), _HandleCloseMessage(), _HandleDestroyMessage(), ButtonDown, ButtonUp, Close, Destroy, and Message::MessageType.
Referenced by HandlerChain_SendMessage().
bool MessageWindow_ToString | ( | int | windowId, |
DynamicString * | output | ||
) |
Convert the specified window to a string representation.
windowId | ID of the window to convert. |
output | A DynamicString that returns the string version of the window. Call DynamicString_Initialize() on this object before passing as an argument. |
Definition at line 409 of file HandlerChain_MessageWindow.c.
References _FindWindow(), _Window::_selected, _Window::_title, _Window::_windowBox, _Window::_windowId, DynamicString_Append(), DynamicString_Clear(), formatstring(), DynamicString::string, and WindowRectangle_ToString().
Referenced by HandlerChain_ToString().
|
static |
The next ID to use for a new window.
Definition at line 93 of file HandlerChain_MessageWindow.c.
Referenced by MessageWindow_Create().
|
static |
List of all created MessageWindow objects, in a double-linked list.
Definition at line 88 of file HandlerChain_MessageWindow.c.
Referenced by _AppendWindowToList(), _FindWindow(), and _RemoveWindowFromList().
const int CLOSE_HEIGHT = 2 |
Height of the close region in the window.
Definition at line 21 of file HandlerChain_MessageWindow.c.
Referenced by MessageWindow_Create().
const int CLOSE_WIDTH = 2 |
Width of the close region in the window.
Definition at line 20 of file HandlerChain_MessageWindow.c.
Referenced by MessageWindow_Create().