MultiEdit.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003-2008 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@gmail.com */
00025 
00029 #ifndef _GG_MultiEdit_h_
00030 #define _GG_MultiEdit_h_
00031 
00032 #include <GG/Edit.h>
00033 #include <GG/MultiEditFwd.h>
00034 
00035 
00036 namespace GG {
00037 
00038 class Scroll;
00039 
00060 class GG_API MultiEdit : public Edit
00061 {
00062 public: 
00064 
00065     MultiEdit(X x, Y y, X w, Y h, const std::string& str, const boost::shared_ptr<Font>& font,
00066               Clr color, Flags<MultiEditStyle> style = MULTI_LINEWRAP, Clr text_color = CLR_BLACK,
00067               Clr interior = CLR_ZERO, Flags<WndFlag> flags = INTERACTIVE);
00068 
00070     virtual ~MultiEdit();
00072  
00074     virtual Pt MinUsableSize() const;
00075     virtual Pt ClientLowerRight() const;
00076 
00078     Flags<MultiEditStyle> Style() const;
00079 
00083     std::size_t MaxLinesOfHistory() const;
00085  
00087     virtual void   Render();
00088 
00089     virtual void   SizeMove(const Pt& ul, const Pt& lr);
00090 
00091     virtual void   SelectAll();
00092     virtual void   SetText(const std::string& str);
00093 
00095     void           SetStyle(Flags<MultiEditStyle> style);
00096 
00099     void           SetMaxLinesOfHistory(std::size_t max);
00100 
00101     virtual void   DefineAttributes(WndEditor* editor);
00103 
00104     static const std::size_t ALL_LINES;
00105 
00106 protected: 
00108     MultiEdit(); 
00109 
00110  
00112 
00113     virtual bool MultiSelected() const;
00114 
00117     X RightMargin() const;
00118 
00121     Y BottomMargin() const;
00122 
00125     std::pair<std::size_t, CPSize> CharAt(const Pt& pt) const;
00126 
00130     std::pair<std::size_t, CPSize> CharAt(CPSize idx) const;
00131 
00133     Pt ScrollPosition() const;
00134 
00141     CPSize CharIndexOf(std::size_t row, CPSize char_idx,
00142                        const std::vector<Font::LineData>* line_data = 0) const;
00143 
00146     X RowStartX(std::size_t row) const;
00147 
00150     X CharXOffset(std::size_t row, CPSize idx) const;
00151 
00154     std::size_t RowAt(Y y) const;
00155 
00158     CPSize CharAt(std::size_t row, X x) const;
00159 
00161     std::size_t FirstVisibleRow() const;
00162 
00164     std::size_t LastVisibleRow() const;
00165 
00167     std::size_t FirstFullyVisibleRow() const;
00168 
00170     std::size_t LastFullyVisibleRow() const;
00171 
00174     CPSize FirstVisibleChar(std::size_t row) const;
00175 
00178     CPSize LastVisibleChar(std::size_t row) const;
00179 
00181     std::pair<std::size_t, CPSize> HighCursorPos() const;
00182 
00184     std::pair<std::size_t, CPSize> LowCursorPos() const;
00186  
00188     virtual void LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00189     virtual void LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00190     virtual void MouseWheel(const Pt& pt, int move, Flags<ModKey> mod_keys);
00191     virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
00192 
00194     void RecreateScrolls();
00195 
00203     void PreserveTextPositionOnNextSetText();
00205 
00208     static const unsigned int SCROLL_WIDTH;
00209 
00211     static const unsigned int BORDER_THICK;
00212 
00213 private:
00214     void    Init();
00215     void    ValidateStyle();
00216     void    ClearSelected();   
00217     void    AdjustView();      
00218     void    AdjustScrolls();   
00219     void    VScrolled(int upper, int lower, int range_upper, int range_lower);
00220     void    HScrolled(int upper, int lower, int range_upper, int range_lower);
00221 
00222     Flags<MultiEditStyle> m_style;
00223 
00224     std::pair<std::size_t, CPSize> m_cursor_begin; 
00225     std::pair<std::size_t, CPSize> m_cursor_end;   
00226     // if m_cursor_begin == m_cursor_end, the caret is draw at m_cursor_end
00227 
00228     Pt          m_contents_sz;          
00229 
00230     X           m_first_col_shown;      
00231     Y           m_first_row_shown;      
00232 
00233     std::size_t m_max_lines_history;
00234 
00235     Scroll*     m_vscroll;
00236     Scroll*     m_hscroll;
00237 
00238     bool        m_preserve_text_position_on_next_set_text;
00239     bool        m_ignore_adjust_scrolls;
00240 
00241     friend class boost::serialization::access;
00242     template <class Archive>
00243     void serialize(Archive& ar, const unsigned int version);
00244 };
00245 
00246 } // namespace GG
00247 
00248 // template implementations
00249 template <class Archive>
00250 void GG::MultiEdit::serialize(Archive& ar, const unsigned int version)
00251 {
00252     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Edit)
00253         & BOOST_SERIALIZATION_NVP(m_style)
00254         & BOOST_SERIALIZATION_NVP(m_cursor_begin)
00255         & BOOST_SERIALIZATION_NVP(m_cursor_end)
00256         & BOOST_SERIALIZATION_NVP(m_contents_sz)
00257         & BOOST_SERIALIZATION_NVP(m_first_col_shown)
00258         & BOOST_SERIALIZATION_NVP(m_first_row_shown)
00259         & BOOST_SERIALIZATION_NVP(m_max_lines_history)
00260         & BOOST_SERIALIZATION_NVP(m_vscroll)
00261         & BOOST_SERIALIZATION_NVP(m_hscroll);
00262 
00263     if (Archive::is_loading::value)
00264         ValidateStyle();
00265 }
00266 
00267 #endif // _GG_MultiEdit_h_

Generated on Sat Mar 26 07:08:37 2011 for GG by  doxygen 1.5.9