Humble Framework for SkyOS


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

HWindow.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 **  $Header: /SkyOS.root/HFramework/HWindow.h 6     4/17/05 12:29p Lee Neuse $
00004 **
00005 ****************************************************************************/
00018 #ifndef HWINDOW_H
00019 #   define  HWINDOW_H
00020 
00021 #ifndef HCOLOR_H
00022 #   include "HColor.h"
00023 #endif
00024 
00025 #ifndef HWIDGET_H
00026 #   include "HWidget.h"
00027 #endif
00028 
00041 template <class T> 
00042 class HWindow : public HWidget,
00043                 public HColorable
00044     {
00045     typedef HWidget     base_class;
00046     static StringPtr    ClassName(void) { return "HWindow<T>"; }
00047 /*  ----------------------------------------------------------------------
00048     VARIABLES
00049     ----------------------------------------------------------------------  */
00050 protected:
00051     HGC                 m_gc;           
00052 /*  ----------------------------------------------------------------------
00053     CTOR/DTOR
00054     ----------------------------------------------------------------------  */
00055 public:
00056     HWindow(void) : HWidget()
00057         { /* STUB CTOR */ }
00058 
00059     virtual             
00060     ~HWindow(void)
00061         { /* STUB DTOR */ }
00062 /*  ----------------------------------------------------------------------
00063     MESSAGE HANDLERS
00064     ----------------------------------------------------------------------  */
00065 protected:
00066     BEGIN_MSG_MAP("HWindow")
00067         MAP_MSG( MSG_GUI_REDRAW,        onRedraw )
00068         MAP_MSG( MSG_WINDOW_DESTROY,    onWindowDestroy )
00069         MAP_MSG( MSG_WINDOW_SIZED,      onWindowSized )
00070 
00071         CHAIN_MAP( base_class )
00072     END_MSG_MAP
00084     virtual bool
00085     onRedraw(const s_gi_msg & msg, HRESULT & hr)
00086         {
00087         ASSERT(msg.type == MSG_GUI_REDRAW);
00088         
00089         HRect   rDirty(msg.rect);
00090 
00091         if (rDirty.IsEmpty())
00092             {
00093             DEBUG_LOG("HWindow[%p]::onRedraw() => empty dirty rectangle\n", this);
00094             rDirty.Set(0, 0, GetWidth() + 1, GetHeight() + 1);  // redraw everything
00095             }
00096             
00097         GI_beginpaint();
00098         if (Draw(rDirty) != NO_ERROR)
00099             hr = S_FAILED;
00100         GI_endpaint();
00101 
00102         return true;    // all done now because windows draw themselves
00103         }
00114     bool
00115     onWindowDestroy(const s_gi_msg & msg, HRESULT & hr)
00116         {
00117         ASSERT(msg.type == MSG_WINDOW_DESTROY);
00118 //      DEBUG_LOG("HWindow[%p]::onWindowDestroy()\n", this);
00119 
00120         (void) m_gc.Destroy();          
00121         return base_class::onWindowDestroy(msg, hr);
00122         }
00133     bool
00134     onWindowSized(const s_gi_msg & msg, HRESULT & hr)
00135         {
00136         ASSERT( msg.type == MSG_WINDOW_SIZED );
00137 //      DEBUG_LOG("HWindow::onWindowSized()\n");
00138 
00139         (void) UpdateLayout();
00140 
00141         return base_class::onWindowSized(msg, hr);
00142         }
00143 /*  ----------------------------------------------------------------------
00144     METHODS
00145     ----------------------------------------------------------------------  */
00146 public:
00159     virtual ErrCode
00160     Create( HANDLE          hParent, 
00161             StringPtr       pstrTitle = NULL, 
00162             HRect const *   prFrame = NULL, 
00163             uint32          uStyle = 0)
00164         {
00165         ErrCode         ec = HError::NoError();
00166         int32           nX, nY,
00167                         nXDim, nYDim;
00168         
00169         if (GOOD_PTR(prFrame))
00170             {
00171             nX = prFrame->x1;
00172             nY = prFrame->y1;
00173             nXDim = prFrame->GetWidth();
00174             nYDim = prFrame->GetHeight();
00175             }
00176         else
00177             nX = nY = nXDim = nYDim = 0;
00178         //
00179         //  Create the actual window
00180         //              
00181         m_hMe = GI_create_window(   reinterpret_cast<s_window *>(hParent), 
00182                                     TEXT(pstrTitle), 
00183                                     nX, nY, nXDim, nYDim, 
00184                                     uStyle, 0, NULL, 0);
00185         if (GOOD_HND(m_hMe))
00186             ec = manageWindow();
00187         else
00188             ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00189             
00190         return ec;
00191         }
00196     virtual ErrCode     UpdateLayout(void)
00197                             { return HError::NoError(); }
00198 protected:
00207     ErrCode
00208     manageWindow(void)
00209         {
00210         ErrCode     ec = HError::NoError();
00211 
00212         try
00213             {                       
00214             if (NULL_HND(m_hMe))
00215                 HError::Throw(ERR_BAD_WINDOW, __FILE__, __LINE__);
00216             
00217             DEBUG_LOG("HWindow[%p]::manageWindow() => 0x%08lX\n", this, int32(m_hMe));
00218             //
00219             //  Create the Graphic Context (GC) for this window
00220             //
00221             if ((ec = m_gc.Create(GC_TYPE_WINDOW, 0, 0, m_hMe)) != NO_ERROR)
00222                 throw HError::GetLastError();
00223             //
00224             //  Call the EnableMessages() method so that this window object 
00225             //  starts receiving window messages.
00226             //
00227             if ((ec = enableMessages()) != NO_ERROR)
00228                 throw HError::GetLastError();
00229             //
00230             //  Since the MSG_GUI_CREATE_WINDOW message isn't working as of 
00231             //  SkyOS 5.0 Beta 7 we manually invoke the method here by dummying 
00232             //  up a message and sending it to ourselves.
00233             //
00234             DEBUG_ONLY((void) SendMessage(MSG_GUI_CREATE_WINDOW));
00235             }
00236         catch (const std::exception & e)
00237             {
00238             DEBUG_LOG("HWindow[%p]::manageWindow() => caught %s\n", this, e.what());
00239             if ((ec = ErrCode( HError::GetLastError() )) == NO_ERROR)
00240                 ec = HError::Set(ERR_STL_EXCEPTION, __FILE__, __LINE__);
00241             }
00242             
00243         return ec;
00244         }
00245     };
00246 
00247 #endif  // HWINDOW_H
00248 /****************************************************************************
00249 **
00250 **  $History: HWindow.h $
00251  * 
00252  * *****************  Version 6  *****************
00253  * User: Lee Neuse    Date: 4/17/05    Time: 12:29p
00254  * Updated in $/SkyOS.root/HFramework
00255  * Development snapshot 050417
00256  * 
00257  * *****************  Version 5  *****************
00258  * User: Neusel       Date: 2/04/05    Time: 10:45a
00259  * Updated in $/SkyOS.root/pig/Humble
00260  * 
00261  * *****************  Version 4  *****************
00262  * User: Neusel       Date: 12/23/04   Time: 1:34p
00263  * Updated in $/SkyOS.root/pig/Humble
00264  * Posted as HFramework-debug 20041223
00265  * 
00266  * *****************  Version 3  *****************
00267  * User: Neusel       Date: 12/08/04   Time: 5:06p
00268  * Updated in $/SkyOS.root/pig/Humble
00269  * 20041208
00270  * 
00271  * *****************  Version 2  *****************
00272  * User: Neusel       Date: 11/30/04   Time: 1:01p
00273  * Updated in $/SkyOS.root/pig/Humble
00274  * Released as HUMBLE_VER 20041130.
00275  * 
00276  * *****************  Version 1  *****************
00277  * User: Neusel       Date: 11/23/04   Time: 8:24a
00278  * Created in $/SkyOS.root/pig/Humble
00279 **
00280 **  -------------------------------------------------------------------------
00281 **
00282 **  End of HWindow.h
00283 **
00284 ****************************************************************************/