13#include "helpers/formatstring.h"
109 while (nextWindow->
next != NULL)
111 nextWindow = nextWindow->
next;
113 nextWindow->
next = window;
114 window->
prev = nextWindow;
127 if (window->
prev != NULL)
137 if (window->
next != NULL)
160 while (window != NULL)
164 foundWindow = window;
167 window = window->
next;
188 bool messageProcessed =
false;
190 if (window != NULL && message != NULL)
197 printf(
" --> Button Down in \"%s\", window selected\n", window->
_title);
205 printf(
" --> Button Down not in \"%s\", window deselected\n", window->
_title);
210 return messageProcessed;
223 bool messageProcessed =
false;
225 if (window != NULL && message != NULL)
234 messageProcessed =
true;
237 printf(
" --> Button Up in \"%s\" close box, sending Close message\n", window->
_title);
244 printf(
" --> Button Up in \"%s\", no further action taken\n", window->
_title);
250 return messageProcessed;
263 bool messageProcessed =
false;
265 if (window != NULL && message != NULL)
269 printf(
" --> Close in \"%s\", sending Destroy message\n", window->
_title);
273 messageProcessed =
true;
280 printf(
" --> Close seen in \"%s\" but this window is not selected, ignoring\n", window->
_title);
285 return messageProcessed;
301 bool messageProcessed =
false;
303 if (window != NULL && message != NULL)
305 printf(
" --> Destroy in \"%s\", removing window from handler chain and destroying window\n", window->
_title);
309 messageProcessed =
true;
312 return messageProcessed;
339 printf(
" Error! Out of memory condition adding a window to the handler chain in MessageWindow_Create()!\n");
369 bool processed =
false;
395 printf(
"Error! Cannot process unrecognized message type: %d!\n", message->
MessageType);
411 bool success =
false;
422 char* buffer =
formatstring(
"[id=%2d] \"%s\" (%s), selected=%s",
430 printf(
" Error! Out of memory condition formatting a MessageWindow as a string!\n");
436 printf(
" Error! Out of memory formatting message window in MessageWindow_ToString()!\n");
bool HandlerChain_AddWindow(int windowId)
Add an instance of a MessageWindow to end of the list of windows, protected by a multi-threading lock...
void HandlerChain_RemoveWindow(int windowId)
Remove an instance of a MessageWindow from the list, protected by a multi-threading lock.
void HandlerChain_SendMessage(int windowId, Message *message)
Send a message to each of the handlers in the list, protected by a multi-threading lock.
Declaration of the Handler Chain functions, HandlerChain_SendMessage(), HandlerChain_AddWindow(),...
void Message_Initialize(Message *message, MessageType type, int x, int y)
Initialize a Message structure.
@ ButtonUp
Take an action on the currently selected window.
@ ButtonDown
Selects a window based on position.
@ Destroy
Window is being told to destroy itself. This is sent in response to seeing the Close message.
@ Close
Window is asked to close itself, generally sent by the window itself in response to a button up in a ...
const int CLOSE_HEIGHT
Height of the close region in the window.
static int _nextWindowId
The next ID to use for a new window.
static MessageWindow * _FindWindow(int windowId)
Helper function to find a MessageWindow given the window's ID.
static bool _HandleButtonUpMessage(MessageWindow *window, Message *message)
Helper function to handle the ButtonUp message.
bool MessageWindow_ProcessMessage(int windowId, Message *message)
Pass a Message object to a window for processing.
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.
static void _RemoveWindowFromList(MessageWindow *window)
Helper function to remove the given MessageWindow object from the linked list of MessageWindow object...
static bool _HandleButtonDownMessage(MessageWindow *window, Message *message)
Helper function to handle the ButtonDown message.
const int CLOSE_WIDTH
Width of the close region in the window.
void MessageWindow_Destroy(int windowId)
Destroy the MessageWindow object with the given ID. Removes the window from any message handling as w...
static void _AppendWindowToList(MessageWindow *window)
Helper function to append the given MessageWindow to the list of MessageWindow objects.
static bool _HandleCloseMessage(MessageWindow *window, Message *message)
Helper function to handle the Close message.
bool MessageWindow_ToString(int windowId, DynamicString *output)
Convert the specified window to a string representation.
static MessageWindow * _windowList
List of all created MessageWindow objects, in a double-linked list.
static bool _HandleDestroyMessage(MessageWindow *window, Message *message)
Helper function to trigger the destruction of the window. The window is destroyed and can no longer r...
Declaration of the MessageWindow support functions, MessageWindow_Create(), MessageWindow_Destroy(),...
bool WindowRectangle_ToString(WindowRectangle *rectangle, DynamicString *output)
Convert the given WindowRectangle to a string representation.
void WindowRectangle_Initialize(WindowRectangle *rectangle, int x, int y, int width, int height)
Initialize the specified WindowRectangle based on the given position and size in some arbitrary space...
bool WindowRectangle_PointInside(WindowRectangle *rectangle, MessagePosition *point)
Determine if the given WindowRectangle object contains the given MessagePosition.
Declaration of the WindowRectangle structure and its support functions, WindowRectangle_Initialize(),...
void DynamicString_Clear(DynamicString *string)
Clear a DynamicString object, releasing any allocated memory. Resets to an empty string.
bool DynamicString_Append(DynamicString *string, const char *s)
Append the specified string to the DynamicString object.
Represents a window in an arbitrary space. It has an ID, title, and position. A close box is within t...
WindowRectangle _closeBox
Position of the close window within the window box, although the coordinates are also global coordina...
struct _Window * prev
Previous window in a linked list. NULL if this window is the head of the list.
bool _selected
Whether this window has been selected (a button click occurred within the window).
int _windowId
Unique ID of this window.
WindowRectangle _windowBox
Position of this window in global coordinates.
struct _Window * next
Next window in a linked list. NULL if this windows is the last in the list.
const char * _title
Title/Name of this window.
Represents a string that can be grown dynamically.
char * string
The string that can grow.
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.
Represents a rectangular region, with upper left and lower right coordinates.