Humble Framework for SkyOS


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

HTextEdit.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 **  $Header: /SkyOS.root/HFramework/HTextEdit.h 4     4/17/05 12:29p Lee Neuse $
00004 **
00005 ****************************************************************************/
00012 #ifndef HTEXTEDIT_H
00013 #   define  HTEXTEDIT_H
00014 
00015 #ifndef HWIDGET_H
00016 #   include <HWidget.h>
00017 #endif
00018 
00024 class HTextEdit : public HWidget
00025     {
00026     typedef HWidget     base_class;
00027     static StringPtr    ClassName(void) { return "HTextEdit"; }
00028 /*  ----------------------------------------------------------------------
00029     VARIABLES
00030     ----------------------------------------------------------------------  */
00031 protected:
00032     bool                m_bReadOnly;    
00033     uint32              m_uTextLines;   
00034 /*  ----------------------------------------------------------------------
00035     CTOR/DTOR
00036     ----------------------------------------------------------------------  */
00037 public:
00038     HTextEdit(void) : HWidget(), m_bReadOnly(false), m_uTextLines(0)
00039         { /* STUB CTOR */ }
00040 
00041     virtual             
00042     ~HTextEdit(void)
00043         { Destroy(); }
00044 /*  ----------------------------------------------------------------------
00045     MESSAGE HANDLERS
00046     ----------------------------------------------------------------------  */
00047 protected:
00048     BEGIN_MSG_MAP("HTextEdit")
00049         CHAIN_MAP( base_class )
00050     END_MSG_MAP
00051 /*  ----------------------------------------------------------------------
00052     METHODS
00053     ----------------------------------------------------------------------  */
00054 public:
00062     ErrCode
00063     AddText(StringPtr pstr, bool bRedraw = true)
00064         {
00065         ErrCode         ec = HError::NoError();
00066 
00067         try
00068             {
00069             if (!IsValid())     
00070                 ec = HError::Set(ERR_NOT_INITIALIZED, __FILE__, __LINE__);
00071             else if (NULL_PTR(pstr))    
00072                 ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);        
00073             else if (GI_widget_textfield_add_line(m_hMe, TEXT(pstr)) != S_OK)
00074                 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00075             else    // all is well
00076                 {
00077                 m_uTextLines += STR_COUNT(pstr, '\n') + 1;
00078                 if (bRedraw)
00079                     ec = redrawText();
00080                 }
00081             }
00082         catch (const std::exception & e)
00083             {
00084             DEBUG_LOG("HTextEdit::AddText() => caught %s.\n", e.what());
00085             if ((ec = ErrCode(HError::GetLastError())) == NO_ERROR)
00086                 ec = HError::Set(ERR_STL_EXCEPTION, __FILE__, __LINE__);
00087             }
00088         
00089         return ec;
00090         }
00100     ErrCode
00101     Create(HANDLE hParent, StringPtr pstrName, 
00102             HRect * prBounds = NULL, uint32 uStyle = 0)
00103         {
00104         ErrCode     ec = HError::NoError();
00105         
00106         ASSERT( NULL_HND(m_hMe) );  // Don't step on an existing textedit
00107         
00108         if (GOOD_HND(hParent))
00109             {
00110             int32           nX, nY,
00111                             nXDim, nYDim;
00112             
00113             if (NULL_PTR(prBounds) || prBounds->IsEmpty())
00114                 nX = nY = nXDim = nYDim = 0;
00115             else
00116                 {
00117                 nX = prBounds->x1;
00118                 nY = prBounds->y1;
00119                 nXDim = prBounds->GetWidth();
00120                 nYDim = prBounds->GetHeight();
00121                 }
00122 
00123             m_bReadOnly = (uStyle & WGF_TEXTFIELD_DISABLE_INPUT) ? true : false;
00124             m_uTextLines = 0;
00125             m_hMe  = GI_create_widget_textfield(hParent, TEXT(pstrName), 
00126                                                 nX, nY, nXDim, nYDim, 
00127                                                 uStyle);
00128             if (GOOD_HND(m_hMe))
00129                 {
00130                 DEBUG_LOG(  "HTextEdit[%p]::Create() => m_hMe = 0x%08lX\n", 
00131                             this, int32(m_hMe));
00132                 }
00133             else
00134                 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00135             }
00136         else
00137             ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);
00138 
00139         return ec;
00140         }
00146     ErrCode
00147     DeleteAllText(void)
00148         {
00149         ErrCode         ec = HError::NoError();
00150         
00151         if (IsValid())
00152             {
00153             if (GI_widget_textfield_delete(m_hMe) == S_OK)
00154                 {
00155                 m_uTextLines = 0;
00156                 ec = redrawText();
00157                 }
00158             else
00159                 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00160             }
00161         else
00162             ec = HError::Set(ERR_NOT_INITIALIZED, __FILE__, __LINE__);
00163             
00164         return ec;
00165         }
00166 
00167 protected:
00172     ErrCode
00173     redrawText(void) const
00174         {
00175         ErrCode ec = HError::NoError();
00176             
00177         if (IsValid()) 
00178             {
00179             if (GI_widget_textfield_redraw(m_hMe) != S_OK)
00180                 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00181             }
00182         else
00183             ec = HError::Set(ERR_NOT_INITIALIZED, __FILE__, __LINE__);
00184         
00185         return ec;
00186         }
00187 /*  ----------------------------------------------------------------------
00188     GETTERS & SETTERS
00189     ----------------------------------------------------------------------  */
00190 public:
00195     inline uint32       GetLineCount(void) const
00196                             { return m_uTextLines; }
00207     ErrCode             SetLineBackColor(uint32 uLine, const HColor & color)
00208                             {
00209                             ErrCode     ec = HError::NoError();
00210 
00211                             if (IsValid())
00212                                 {
00213                                 if (isValidLine(uLine))
00214                                     {
00215                                     uLine--;    // make line # zero-relative
00216                                     if (GI_widget_textfield_set_line_backcolor(m_hMe, uLine, COLOR(color)) != S_OK)
00217                                         ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00218                                     }
00219                                 else
00220                                     ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);
00221                                 }
00222                             else
00223                                 ec = HError::Set(ERR_NOT_INITIALIZED, __FILE__, __LINE__);
00224                             
00225                             return ec;
00226                             }
00231     ErrCode             SetReadOnly(bool bReadOnly)
00232                             {
00233                             ErrCode     ec = HError::NoError();
00234                             
00235                             m_bReadOnly = bReadOnly; 
00236                             if (IsValid() && 
00237                                 GI_widget_textfield_set_rdonly(m_hMe, (bReadOnly ? 1 : 0)) != S_OK)
00238                                 {
00239                                 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00240                                 }
00241                             
00242                             return ec;
00243                             }
00244 /*  ----------------------------------------------------------------------
00245     INLINES
00246     ----------------------------------------------------------------------  */
00247 public:
00250     inline bool         IsReadOnly(void) const
00251                             { return m_bReadOnly; }
00252 protected:
00253     inline bool         isValidLine(uint32 uLine) const
00254                             { return (uLine > 0 && uLine <= m_uTextLines); }
00255     };
00256 
00257 #endif  // HTEXTEDIT_H
00258 /****************************************************************************
00259 **
00260 **  $History: HTextEdit.h $
00261  * 
00262  * *****************  Version 4  *****************
00263  * User: Lee Neuse    Date: 4/17/05    Time: 12:29p
00264  * Updated in $/SkyOS.root/HFramework
00265  * Development snapshot 050417
00266  * 
00267  * *****************  Version 3  *****************
00268  * User: Neusel       Date: 12/23/04   Time: 1:34p
00269  * Updated in $/SkyOS.root/pig/Humble
00270  * Posted as HFramework-debug 20041223
00271  * 
00272  * *****************  Version 2  *****************
00273  * User: Neusel       Date: 12/10/04   Time: 3:57p
00274  * Updated in $/SkyOS.root/pig/Humble
00275  * 20041210
00276  * 
00277  * *****************  Version 1  *****************
00278  * User: Neusel       Date: 12/08/04   Time: 5:06p
00279  * Created in $/SkyOS.root/pig/Humble
00280  * 20041208
00281 **
00282 **  -------------------------------------------------------------------------
00283 **
00284 **  End of HTextEdit.h
00285 **
00286 ****************************************************************************/