wg_textbox.h

00001 // wg_textbox.h
00002 //
00003 // CTextBox interface
00004 //
00005 //
00006 // Copyright (c) 2002-2004 Rob Wiskow
00007 // rob-dev@boxedchaos.com
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022 //
00023 
00024 #ifndef _WG_TEXTBOX_H_
00025 #define _WG_TEXTBOX_H_
00026 
00027 #include "wg_window.h"
00028 #include "wg_painter.h"
00029 #include "wg_renderedstring.h"
00030 #include "wg_timer.h"
00031 #include "wg_resources.h"
00032 #include "wg_scrollbar.h"
00033 #include <vector>
00034 #include <map>
00035 
00036 
00037 namespace wGui
00038 {
00039 
00041 
00043 
00044 class CTextBox : public CWindow
00045 {
00046 public:
00052      CTextBox(const CRect& WindowRect, CWindow* pParent, CFontEngine* pFontEngine = 0);
00053 
00055      virtual ~CTextBox(void);
00056 
00059      virtual void SetReadOnly(bool bReadOnly);
00060 
00063      virtual bool IsReadOnly(void) const { return m_bReadOnly; }
00064 
00067      virtual std::wstring GetSelText(void) const;
00068 
00072      virtual void SetSelection(std::wstring::size_type iSelStart, int iSelLength);
00073 
00076      virtual std::wstring::size_type GetSelectionStart(void) const { return m_SelStart; }
00077 
00080      virtual int GetSelectionLength(void) const { return m_SelLength; }
00081 
00083      enum EScrollBarVisibility
00084      {
00085           SCROLLBAR_VIS_AUTO,  
00086           SCROLLBAR_VIS_NEVER,  
00087           SCROLLBAR_VIS_ALWAYS  
00088      };
00089 
00093      virtual void SetScrollBarVisibility(CScrollBar::EScrollBarType ScrollBarType, EScrollBarVisibility Visibility);
00094 
00098      virtual EScrollBarVisibility GetScrollBarVisibility(CScrollBar::EScrollBarType ScrollBarType) const
00099           { return m_ScrollBarVisibilityMap.find(ScrollBarType)->second; }
00100 
00101 
00102      // CWindow overrides
00104      virtual void Draw(void) const;
00105 
00108      virtual void SetWindowRect(const CRect& WindowRect);
00109 
00112      virtual void SetWindowText(const std::wstring& sText);
00113 
00119      virtual bool OnMouseButtonDown(CPoint Point, unsigned int Button);
00120 
00121 
00122      // CMessageClient overrides
00125      virtual bool HandleMessage(CMessage* pMessage);
00126 
00127 
00128 protected:
00129 
00133      void SelDelete(std::wstring* psString);
00134 
00137      void PrepareWindowText(const std::wstring& sText);
00138 
00140      void UpdateScrollBars(void);
00141 
00145      CPoint RowColFromIndex(std::wstring::size_type Index) const;
00146 
00151      std::wstring::size_type IndexFromRowCol(std::wstring::size_type Row, std::wstring::size_type Col) const;
00152 
00153      CFontEngine* m_pFontEngine; 
00154      std::vector<CRenderedString*> m_vpRenderedString; 
00155      unsigned char m_FontSize;  
00156      std::wstring::size_type m_SelStart;  
00157      long int m_SelLength;  
00158      std::wstring::size_type m_DragStart;  
00159      bool m_bReadOnly;  
00160      bool m_bMouseDown; 
00161      bool m_bLastMouseMoveInside;  
00162      CScrollBar* m_pVerticalScrollBar;  
00163      CScrollBar* m_pHorizontalScrollBar;  
00164      std::map<CScrollBar::EScrollBarType, EScrollBarVisibility> m_ScrollBarVisibilityMap;  
00165 
00166      // cached values
00167      unsigned int m_iLineCount;  
00168      unsigned int m_iRowHeight;  
00169      unsigned int m_iMaxWidth;  
00170 
00171 
00172 private:
00173      void operator=(CTextBox) { }  
00174      bool m_bDrawCursor;  
00175      mutable bool m_bScrollToCursor;  
00176      CTimer* m_pDblClickTimer;  
00177      CTimer* m_pCursorTimer;  
00178 };
00179 
00180 }
00181 
00182 
00183 #include "unit_tests/wg_textbox_unittests.h"
00184 
00185 #endif // _WG_TEXTBOX_H_

Generated on Wed May 16 23:11:26 2007 for wGui by  doxygen 1.5.1