MultiEdit.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003 T. Zachary Laine
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License
00007    as published by the Free Software Foundation; either version 2.1
00008    of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014     
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA
00019 
00020    If you do not wish to comply with the terms of the LGPL please
00021    contact the author as other terms are available for a fee.
00022     
00023    Zach Laine
00024    whatwasthataddress@hotmail.com */
00025 
00029 #ifndef _GG_MultiEdit_h_
00030 #define _GG_MultiEdit_h_
00031 
00032 #include <GG/Edit.h>
00033 
00034 
00035 namespace GG {
00036 
00037 class Scroll;
00038 
00040 GG_FLAG_TYPE(MultiEditStyle);
00041 extern GG_API const MultiEditStyle MULTI_NONE;             
00042 extern GG_API const MultiEditStyle MULTI_WORDBREAK;        
00043 extern GG_API const MultiEditStyle MULTI_LINEWRAP;         
00044 extern GG_API const MultiEditStyle MULTI_VCENTER;          
00045 extern GG_API const MultiEditStyle MULTI_TOP;              
00046 extern GG_API const MultiEditStyle MULTI_BOTTOM;           
00047 extern GG_API const MultiEditStyle MULTI_CENTER;           
00048 extern GG_API const MultiEditStyle MULTI_LEFT;             
00049 extern GG_API const MultiEditStyle MULTI_RIGHT;            
00050 extern GG_API const MultiEditStyle MULTI_READ_ONLY;        
00051 extern GG_API const MultiEditStyle MULTI_TERMINAL_STYLE;   
00052 extern GG_API const MultiEditStyle MULTI_INTEGRAL_HEIGHT;  
00053 extern GG_API const MultiEditStyle MULTI_NO_VSCROLL;       
00054 extern GG_API const MultiEditStyle MULTI_NO_HSCROLL;       
00055 extern GG_API const Flags<MultiEditStyle> MULTI_NO_SCROLL; 
00056 
00057 
00070 class GG_API MultiEdit : public Edit
00071 {
00072 public: 
00074     MultiEdit(int x, int y, int w, int h, const std::string& str, const boost::shared_ptr<Font>& font, Clr color, 
00075               Flags<MultiEditStyle> style = MULTI_LINEWRAP, Clr text_color = CLR_BLACK, Clr interior = CLR_ZERO, 
00076               Flags<WndFlag> flags = CLICKABLE); 
00077     virtual ~MultiEdit(); 
00078 
00079  
00081     virtual Pt MinUsableSize() const;
00082     virtual Pt ClientLowerRight() const;
00083 
00084     Flags<MultiEditStyle> Style() const; 
00085 
00088     int MaxLinesOfHistory() const;
00090  
00092     virtual void   Render();
00093     virtual void   LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00094     virtual void   LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00095     virtual void   MouseWheel(const Pt& pt, int move, Flags<ModKey> mod_keys);
00096     virtual void   KeyPress(Key key, Flags<ModKey> mod_keys);
00097 
00098     virtual void   SizeMove(const Pt& ul, const Pt& lr);
00099 
00100     virtual void   SelectAll();
00101     virtual void   SetText(const std::string& str);
00102 
00103     void           SetStyle(Flags<MultiEditStyle> style); 
00104 
00106     void           SetMaxLinesOfHistory(int max);
00107 
00108     virtual void   DefineAttributes(WndEditor* editor);
00110 
00111 protected: 
00113     MultiEdit(); 
00114 
00115  
00117     virtual bool MultiSelected() const;     
00118     int     RightMargin() const;            
00119     int     BottomMargin() const;           
00120     std::pair<int, int>
00121             CharAt(const Pt& pt) const;     
00122     std::pair<int, int>
00123             CharAt(int string_idx) const;   
00124 
00125     Pt      ScrollPosition() const;         
00126 
00129     int     StringIndexOf(int row, int char_idx, const std::vector<Font::LineData>* line_data = 0) const;
00130 
00131     int     RowStartX(int row) const;       
00132     int     CharXOffset(int row, int idx) const; 
00133     int     RowAt(int y) const;             
00134     int     CharAt(int row, int x) const;   
00135     int     FirstVisibleRow() const;        
00136     int     LastVisibleRow() const;         
00137     int     FirstFullyVisibleRow() const;   
00138     int     LastFullyVisibleRow() const;    
00139     int     FirstVisibleChar(int row) const;
00140     int     LastVisibleChar(int row) const; 
00141     std::pair<int, int>
00142             HighCursorPos() const;          
00143     std::pair<int, int>
00144             LowCursorPos() const;           
00145 
00146  
00148     void    RecreateScrolls();              
00149 
00155     void    PreserveTextPositionOnNextSetText();
00157 
00158     static const int SCROLL_WIDTH;          
00159     static const int BORDER_THICK;          
00160 
00161 private:
00162     void    Init();
00163     void    ValidateStyle();
00164     void    ClearSelected();   
00165     void    AdjustView();      
00166     void    AdjustScrolls();   
00167     void    VScrolled(int upper, int lower, int range_upper, int range_lower);
00168     void    HScrolled(int upper, int lower, int range_upper, int range_lower);
00169 
00170     Flags<MultiEditStyle> m_style;
00171 
00172     std::pair<int, int>  m_cursor_begin; 
00173     std::pair<int, int>  m_cursor_end;   
00174                                          // if m_cursor_begin == m_cursor_end, the caret is draw at m_cursor_end
00175 
00176     Pt          m_contents_sz;          
00177 
00178     int         m_first_col_shown;      
00179     int         m_first_row_shown;      
00180 
00181     int         m_max_lines_history;
00182 
00183     Scroll*     m_vscroll;
00184     Scroll*     m_hscroll;
00185 
00186     bool        m_preserve_text_position_on_next_set_text;
00187 
00188     friend class boost::serialization::access;
00189     template <class Archive>
00190     void serialize(Archive& ar, const unsigned int version);
00191 };
00192 
00193 } // namespace GG
00194 
00195 // template implementations
00196 template <class Archive>
00197 void GG::MultiEdit::serialize(Archive& ar, const unsigned int version)
00198 {
00199     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Edit)
00200         & BOOST_SERIALIZATION_NVP(m_style)
00201         & BOOST_SERIALIZATION_NVP(m_cursor_begin)
00202         & BOOST_SERIALIZATION_NVP(m_cursor_end)
00203         & BOOST_SERIALIZATION_NVP(m_contents_sz)
00204         & BOOST_SERIALIZATION_NVP(m_first_col_shown)
00205         & BOOST_SERIALIZATION_NVP(m_first_row_shown)
00206         & BOOST_SERIALIZATION_NVP(m_max_lines_history)
00207         & BOOST_SERIALIZATION_NVP(m_vscroll)
00208         & BOOST_SERIALIZATION_NVP(m_hscroll);
00209 
00210     if (Archive::is_loading::value)
00211         ValidateStyle();
00212 }
00213 
00214 #endif // _GG_MultiEdit_h_

Generated on Wed Mar 26 14:35:42 2008 for GG by  doxygen 1.5.2