Humble Framework for SkyOS


Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

HWidget Class Reference
[Graphical User Interface]

#include <HWidget.h>

Inheritance diagram for HWidget:

HObjNoCopy HObj HCheckbox HMenu HPanel HPanelItem HTextEdit HWindow< T > HWindow< HApp > HWindow< HLayout > HWindow< HPane >

Detailed Description

This base class provides generic "one size fits all" processing that should be identical to all widgets. The HWidget class provides all of the basic functionality, which handles simple things like checking to see if the widget is valid, i.e., stuff that every widget would do exactly the same way. This way, it isn't necessary to keep re-writing the same logic over and over again, just add the code that is unique to the widget being created.

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!

Definition at line 104 of file HWidget.h.

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.


Member Function Documentation

virtual bool HWidget::HandleMessage HANDLE  hWnd,
s_gi_msg *  pMsg,
HRESULT &  hr
[virtual]
 

This message handler is called from the WidgetProc() function, and gives the widget the opportunity to intercept and act on messages from the SkyGI layer. Typically, most widgets will build this method by using the "message map" macros, but the HWidget base class has a fully coded version to handle messages in a more intuitive manner.

Returns:
True if message handled, false otherwse
Parameters:
hWnd Handle to window
pMsg Ptr to message
[out] hr Result code (preset to S_OK)

Definition at line 146 of file HWidget.h.

bool HWidget::onCommand uint32  uCmd,
HRESULT &  hr
[protected]
 

This method forwards the command to the widget's parent.

Returns:
True if handled, false otherwise
Parameters:
uCmd Command identifier (should always be CMD_APP_EXIT)
hr Set to S_FAILED on error, defaults to S_OK

Definition at line 199 of file HWidget.h.

bool HWidget::onMouseBut1Released const s_gi_msg &  msg,
HRESULT &  hr
[protected]
 

Handler invoked when the left mouse button is released within this window.

Returns:
Always true
Parameters:
msg MSG_MOUSE_BUT1_RELEASED message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Definition at line 225 of file HWidget.h.

bool HWidget::onMouseBut2Released const s_gi_msg &  msg,
HRESULT &  hr
[protected]
 

Handler invoked when the right mouse button is released within this window.

Returns:
Always true
Parameters:
msg MSG_MOUSE_BUT2_RELEASED message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Definition at line 243 of file HWidget.h.

bool HWidget::onMouseEnter const s_gi_msg &  msg,
HRESULT &  hr
[protected]
 

Returns:
Always true
Parameters:
msg MSG_MOUSE_ENTER message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Definition at line 259 of file HWidget.h.

bool HWidget::onMouseLeave const s_gi_msg &  msg,
HRESULT &  hr
[protected]
 

Returns:
Always true
Parameters:
msg MSG_MOUSE_LEAVE message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Definition at line 272 of file HWidget.h.

bool HWidget::onMouseMove const s_gi_msg &  msg,
HRESULT &  hr
[protected]
 

Returns:
Always true
Parameters:
msg MSG_MOUSE_MOVE message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Definition at line 285 of file HWidget.h.

virtual bool HWidget::onPreDestroy const s_gi_msg &  msg,
HRESULT &  hr
[protected, virtual]
 

Returns:
Always false
Parameters:
msg MSG_PRE_DESTROY message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Definition at line 298 of file HWidget.h.

virtual bool HWidget::onRedraw const s_gi_msg &  msg,
HRESULT &  hr
[protected, virtual]
 

Standard handler for the MSG_GUI_REDRAW message, which defaults to the default window handler.

Returns:
Always false
Parameters:
msg MSG_GUI_REDRAW message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Reimplemented in HWindow< T >, HWindow< HLayout >, HWindow< HPane >, and HWindow< HApp >.

Definition at line 314 of file HWidget.h.

virtual bool HWidget::onCreateWindow const s_gi_msg &  msg,
HRESULT &  hr
[protected, virtual]
 

Returns:
Always false
Parameters:
msg MSG_GUI_CREATE_WINDOW message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Definition at line 327 of file HWidget.h.

virtual bool HWidget::onWindowDestroy const s_gi_msg &  msg,
HRESULT &  hr
[protected, virtual]
 

Subclasses that provide a custom onWindowDestroy() MUST call this method once they've finished processing the message.

Returns:
Always false
Parameters:
msg MSG_WINDOW_DESTROY message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Reimplemented in HWindow< T >, HWindow< HLayout >, HWindow< HPane >, and HWindow< HApp >.

Definition at line 343 of file HWidget.h.

virtual bool HWidget::onWindowSized const s_gi_msg &  msg,
HRESULT &  hr
[protected, virtual]
 

Returns:
Always false
Parameters:
msg MSG_WINDOW_SIZED message received by window procedure
[out] hr S_OK on success, error code otherwise; preset to S_OK

Reimplemented in HWindow< T >, HWindow< HLayout >, HWindow< HPane >, and HWindow< HApp >.

Definition at line 364 of file HWidget.h.

ErrCode HWidget::Adopt HANDLE  hWnd  ) 
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
hWnd Handle to object to adopt

Definition at line 380 of file HWidget.h.

virtual ErrCode HWidget::Destroy void   )  [virtual]
 

This method destroys the underlying SkyGI widget object, first removing it from the message routing mechanism. Note that GI_destroy_window() is not called if the widget is set to "auto-destruct".

Returns:
NO_ERROR on success, error code otherwise

Reimplemented in HApp, HMenuBar, and HPanel.

Definition at line 408 of file HWidget.h.

virtual ErrCode HWidget::Draw HRect rDirty  )  [virtual]
 

Subclasses MUST override this method to provide all window drawing.

Returns:
Always ERR_NOT_IMPLEMENTED
Parameters:
rDirty Rectangle defining area to be drawn

Reimplemented in HApp, HPane, HLabel, and HLayout.

Definition at line 442 of file HWidget.h.

virtual ErrCode HWidget::Show void   )  const [virtual]
 

Makes the GUI window associated with this widget visible.

Returns:
NO_ERROR on success, error code otherwise

Reimplemented in HApp.

Definition at line 452 of file HWidget.h.

virtual ErrCode HWidget::Smudge HRect const *  prDirty = NULL  )  [virtual]
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
prDirty Ptr to rectangle to smudge, or NULL for entire widget

Definition at line 473 of file HWidget.h.

static HRESULT HWidget::WidgetProc HANDLE  hWnd,
s_gi_msg *  pMsg
[static]
 

Returns:
S_OK on success, error code otherwise
Parameters:
hWnd handle to the window the message is directed to
pMsg pointer to the s_gi_msg message structure

Definition at line 504 of file HWidget.h.

ErrCode HWidget::disableMessages void   )  [protected]
 

Returns:
NO_ERROR on success, error code otherwise

Definition at line 526 of file HWidget.h.

ErrCode HWidget::enableMessages void   )  [protected]
 

Returns:
NO_ERROR on success, error code otherwise

Definition at line 551 of file HWidget.h.

bool HWidget::GetBounds HRect rBounds  ) 
 

Returns:
true if returned rectangle is valid
Parameters:
[out] rBounds Rectangle

Definition at line 579 of file HWidget.h.

bool HWidget::GetClientBounds HRect rBounds  ) 
 

This method builds a rectangle that corresponds to the window's position and size relative to the PARENT.

Returns:
true if returned rectangle is valid
Parameters:
[out] rBounds Rectangle

Definition at line 607 of file HWidget.h.

ErrCode HWidget::GetScreenBounds HRect rBounds  ) 
 

This method builds a rectangle that corresponds to the window's position and size relative to the SCREEN.

Returns:
NO_ERROR on success, error code otherwise
Parameters:
[out] rBounds Rectangle

Definition at line 635 of file HWidget.h.

int32 HWidget::GetHeight void   )  const
 

Returns:
Height of window in pixels

Definition at line 661 of file HWidget.h.

int32 HWidget::GetWidth void   )  const
 

Returns:
Width of window in pixels

Definition at line 667 of file HWidget.h.

s_window* HWidget::GetParentWindow void   )  const
 

Returns:
Ptr to s_window structure, or NULL if invalid window

Definition at line 673 of file HWidget.h.

HPoint HWidget::GetPosition void   )  const
 

Returns:
Position (in parent window coordinates)

Definition at line 679 of file HWidget.h.

s_window* HWidget::GetWindow void   )  const
 

Returns:
Ptr to s_window structure, or NULL if invalid window

Definition at line 685 of file HWidget.h.

int32 HWidget::GetXPos void   )  const
 

Returns:
X-coordinate of window (relative to parent)

Definition at line 691 of file HWidget.h.

int32 HWidget::GetYPos void   )  const
 

Returns:
Y-coordinate of window (relative to parent)

Definition at line 697 of file HWidget.h.

HANDLE HWidget::GetHandle void   )  const
 

Returns:
Handle to the widget

Definition at line 703 of file HWidget.h.

void HWidget::SetAutoDestruct bool  bAuto = true  ) 
 

Parameters:
bAuto True to autodestruct, false otherwise

Definition at line 709 of file HWidget.h.

ErrCode HWidget::SetBounds int32  nX,
int32  nY,
int32  nXDim,
int32  nYDim,
bool  bRedraw = true
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
nX X position (in window coordinates)
nY Y position (in window coordinates)
nXDim Width (in pixels)
nYDim Height (in pixels)
bRedraw True to redraw afterwards

Definition at line 721 of file HWidget.h.

virtual ErrCode HWidget::SetBounds const HRect rBounds,
bool  bRedraw = true
[virtual]
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
rBounds Rectangle with the desired location in window coordinates
bRedraw True to redraw afterwards

Definition at line 733 of file HWidget.h.

ErrCode HWidget::SetPosition int32  nX,
int32  nY,
bool  bRedraw = true
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
nX X position (in window coordinates)
nY Y position (in window coordinates)
bRedraw True to redraw afterwards

Definition at line 763 of file HWidget.h.

static HANDLE HWidget::getParentFromHandle HANDLE  hWnd  )  [static, protected]
 

Returns:
Ptr to s_window structure, or NULL if invalid window

Definition at line 776 of file HWidget.h.

bool HWidget::IsValid void   )  const
 

Returns:
True if a valid widget, false otherwise

Definition at line 788 of file HWidget.h.

HRESULT HWidget::SendCommand uint32  uCmd  )  const
 

Returns:
S_OK on success, error code otherwise
Parameters:
uCmd Command to be sent to window

Definition at line 796 of file HWidget.h.

HRESULT HWidget::SendMessage uint32  uType,
uint32  uP1 = 0,
uint32  uP2 = 0,
s_region *  pr = NULL
const
 

Returns:
S_OK on success, error code otherwise
Parameters:
uType Message type to be sent to window
uP1 Value for the para1 field (defaults to zero)
uP2 Value for the para2 field (defaults to zero)
pr Optional value for the rect field [ignored]

Definition at line 807 of file HWidget.h.


The documentation for this class was generated from the following files:
 

2006.01.09-16:37