Design Pattern Examples
Overview of object-oriented design patterns
HandlerChain_Message.h File Reference

Declaration of the Message and MessagePosition structures, along with the functions, MessagePosition_ToString(), Message_Initialize(), and Message_ToString(), as used in the HandlerChain Pattern. More...

Include dependency graph for HandlerChain_Message.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MessagePosition
 Position of the message in global coordinates (same scope of coordinates as windows). Although this can handle negative coordinates, the example is careful to use only positive coordinates. More...
 
struct  Message
 Represents a message sent to the windows. A message contains a type and a position. More...
 

Macros

#define __HANDLERCHAIN_MESSAGE_H__
 

Enumerations

enum  MessageType { Close = 0 , ButtonDown = 1 , ButtonUp = 2 , Destroy = 3 }
 Type of message handled by MessageWindow. More...
 

Functions

bool MessagePosition_ToString (MessagePosition *position, DynamicString *output)
 Convert a MessagePosition object to a string representation.
 
void Message_Initialize (Message *message, MessageType type, int x, int y)
 Initialize a Message structure.
 
bool Message_ToString (Message *message, DynamicString *output)
 Convert a Message object to a string representation.
 

Detailed Description

Declaration of the Message and MessagePosition structures, along with the functions, MessagePosition_ToString(), Message_Initialize(), and Message_ToString(), as used in the HandlerChain Pattern.

Definition in file HandlerChain_Message.h.

Macro Definition Documentation

◆ __HANDLERCHAIN_MESSAGE_H__

#define __HANDLERCHAIN_MESSAGE_H__

Definition at line 9 of file HandlerChain_Message.h.

Enumeration Type Documentation

◆ MessageType

Type of message handled by MessageWindow.

Enumerator
Close 

Window is asked to close itself, generally sent by the window itself in response to a button up in a Close region. Applies only to the currently selected window.

ButtonDown 

Selects a window based on position.

ButtonUp 

Take an action on the currently selected window.

Destroy 

Window is being told to destroy itself. This is sent in response to seeing the Close message.

Definition at line 16 of file HandlerChain_Message.h.

Function Documentation

◆ Message_Initialize()

void Message_Initialize ( Message message,
MessageType  type,
int  x,
int  y 
)

Initialize a Message structure.

Parameters
messageThe Message structure to initialize.
typeValue from the MessageType enumeration indicating the type of message being created.
xHorizontal position of the message.
yVertical position of the message.

Definition at line 51 of file HandlerChain_Message.c.

References Message::MessageType, Message::Position, MessagePosition::X, and MessagePosition::Y.

Referenced by _HandleButtonUpMessage(), _HandleChain_DestroyWindows(), _HandleCloseMessage(), and HandlerChain_Exercise().

◆ Message_ToString()

bool Message_ToString ( Message message,
DynamicString output 
)

Convert a Message object to a string representation.

Parameters
messageThe Message object to convert.
outputThe string representation of the Message object. Call DynamicString_Initialize() on this object before passing as an argument.
Returns
Returns true if the message was successfully converted to a string; otherwise, returns false, indicating an out of memory condition (or a NULL argument).

Definition at line 64 of file HandlerChain_Message.c.

References ButtonDown, ButtonUp, Close, Destroy, DynamicString_Append(), DynamicString_Clear(), DynamicString_Initialize(), formatstring(), MessagePosition_ToString(), Message::MessageType, Message::Position, and DynamicString::string.

◆ MessagePosition_ToString()

bool MessagePosition_ToString ( MessagePosition position,
DynamicString output 
)

Convert a MessagePosition object to a string representation.

Parameters
positionThe MessagePosition object to convert.
outputA DynamicString in which to store the string representation of the position argument. Call DynamicString_Initialize() on this object before passing as an argument.
Returns
Returns true if the message position was successfully converted to a string; otherwise, returns false, indicating an out of memory condition (or a NULL argument).

Definition at line 17 of file HandlerChain_Message.c.

References DynamicString_Append(), formatstring(), MessagePosition::X, and MessagePosition::Y.

Referenced by Message_ToString().