More importantly, the HWidget class also handles all of the message routing between the SkyGI kernel and the different widget objects. It accomplishes this by mapping SkyGI handles to HWidget ptrs--encapsulated in the HWidgetMap class--and then uses a generic window procedure that looks up the HWidget ptr and invokes the HandleMessage() method for that object.
The widget object is considered the "boss" over the SkyGI HANDLE: if the widget dies, it automatically destroys the GUI object as well. However, widgets that are set to "auto-destruct" let the underlying GUI object be destroyed along with the owner. Since widgets are typically created as "children" of a parent window, most widget will fall into this category.
To try and prevent the situation where the GUI object is destroyed without the widget object being informed, the MSG_WINDOW_DESTROY messages is trapped. This gives the widget object the chance to mark the GUI window handle (m_hMe) as no longer valid and unhook itself from the message map. This is vital because things would get unstable in a hurry if the handle referenced a window that didn't exist any more!
|
Public Member Functions |
| virtual bool | HandleMessage (HANDLE hWnd, s_gi_msg *pMsg, HRESULT &hr) |
| | Message handler.
|
| ErrCode | Adopt (HANDLE hWnd) |
| | Creates a widget out of an existing window.
|
| virtual ErrCode | Destroy (void) |
| | Destroys the widget.
|
| virtual ErrCode | Draw (HRect &rDirty) |
| | Draw the widget's content.
|
| virtual ErrCode | Show (void) const |
| | Makes a window visible.
|
| virtual ErrCode | Smudge (HRect const *prDirty=NULL) |
| | Marks a portion of the widget's viewable area as dirty.
|
| bool | GetBounds (HRect &rBounds) |
| | Returns the client window's dimensions as a rectangle.
|
| bool | GetClientBounds (HRect &rBounds) |
| | Returns the client window's dimensions as a rectangle.
|
| ErrCode | GetScreenBounds (HRect &rBounds) |
| | Returns the window's screen position as a rectangle.
|
| int32 | GetHeight (void) const |
| | Returns the currenct height of the window in pixels.
|
| int32 | GetWidth (void) const |
| | Returns the currenct width of the window in pixels.
|
| s_window * | GetParentWindow (void) const |
| | Returns a ptr to the underlying s_window structure.
|
| HPoint | GetPosition (void) const |
| | Returns the window's current position.
|
| s_window * | GetWindow (void) const |
| | Returns a ptr to the underlying s_window structure.
|
| int32 | GetXPos (void) const |
| | Returns the currenct X coordinate of the window in pixels.
|
| int32 | GetYPos (void) const |
| | Returns the currenct Y coordinate of the window in pixels.
|
| HANDLE | GetHandle (void) const |
| | Gets the widget's handle.
|
| void | SetAutoDestruct (bool bAuto=true) |
| | Sets the widget's autodestruct state.
|
| ErrCode | SetBounds (int32 nX, int32 nY, int32 nXDim, int32 nYDim, bool bRedraw=true) |
| | Sets the widget's size and location.
|
| virtual ErrCode | SetBounds (const HRect &rBounds, bool bRedraw=true) |
| | Sets the widget's size and location.
|
| ErrCode | SetPosition (int32 nX, int32 nY, bool bRedraw=true) |
| | Sets the widget's location.
|
| bool | IsValid (void) const |
| | Evaluates to true if the widget is valid.
|
| HRESULT | SendCommand (uint32 uCmd) const |
| | Sends a command to the widget.
|
| HRESULT | SendMessage (uint32 uType, uint32 uP1=0, uint32 uP2=0, s_region *pr=NULL) const |
| | Sends a message to the window.
|
Static Public Member Functions |
| static HRESULT | WidgetProc (HANDLE hWnd, s_gi_msg *pMsg) |
| | Generic window procedure that routes messages to widget objects.
|
Protected Member Functions |
| bool | onCommand (uint32 uCmd, HRESULT &hr) |
| | Handler for all commands sent to this widget.
|
| bool | onMouseBut1Released (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_MOUSE_BUT1_RELEASED message.
|
| bool | onMouseBut2Released (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_MOUSE_BUT2_RELEASED message.
|
| bool | onMouseEnter (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_MOUSE_ENTER message.
|
| bool | onMouseLeave (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_MOUSE_LEAVE message.
|
| bool | onMouseMove (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_MOUSE_MOVE message.
|
| virtual bool | onPreDestroy (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_PRE_DESTROY message.
|
| virtual bool | onRedraw (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_GUI_REDRAW message.
|
| virtual bool | onCreateWindow (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_GUI_CREATE_WINDOW message.
|
| virtual bool | onWindowDestroy (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_WINDOW_DESTROY message.
|
| virtual bool | onWindowSized (const s_gi_msg &msg, HRESULT &hr) |
| | Handler for the MSG_WINDOW_SIZED message.
|
| ErrCode | disableMessages (void) |
| | Disables the flow of messages to the widget object.
|
| ErrCode | enableMessages (void) |
| | Enables the flow of messages to the widget object.
|
Static Protected Member Functions |
| static HANDLE | getParentFromHandle (HANDLE hWnd) |
| | Returns a ptr to the underlying s_window structure.
|
Protected Attributes |
|
bool | m_bAutoDestruct |
| | True if window destroys widget.
|
|
HANDLE | m_hMe |
| | Handle to this widget.
|
|
tWindowFunction | m_pfnWndProc |
| | Ptr to original window procedure.
|
Static Protected Attributes |
|
static HMap< HANDLE, HWidget * > | s_map |
| | Global handles <=> widgets map.
|