GG

Edit.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_Edit_h_
00030 #define _GG_Edit_h_
00031 
00032 #include <GG/ClrConstants.h>
00033 #include <GG/TextControl.h>
00034 
00035 
00036 namespace GG {
00037 
00057 class GG_API Edit : public TextControl
00058 {
00059 public: 
00061 
00063     typedef boost::signal<void (const std::string&)> EditedSignalType;
00064 
00068     typedef boost::signal<void (const std::string&)> FocusUpdateSignalType;
00070  
00072 
00073     Edit(X x, Y y, X w, const std::string& str, const boost::shared_ptr<Font>& font, Clr color,
00074          Clr text_color = CLR_BLACK, Clr interior = CLR_ZERO, Flags<WndFlag> flags = INTERACTIVE);
00076  
00078     virtual Pt MinUsableSize() const;
00079     virtual Pt ClientUpperLeft() const;
00080     virtual Pt ClientLowerRight() const;
00081 
00084     const std::pair<CPSize, CPSize>& CursorPosn() const;
00085 
00087     Clr InteriorColor() const;
00088 
00090     Clr HiliteColor() const;
00091 
00093     Clr SelectedTextColor() const;
00094 
00096     mutable EditedSignalType EditedSignal;
00097 
00099     mutable FocusUpdateSignalType FocusUpdateSignal;
00101  
00103     virtual void Render();
00104 
00105     virtual void SetColor(Clr c);
00106 
00108     void SetInteriorColor(Clr c);
00109 
00111     void SetHiliteColor(Clr c);
00112 
00114     void SetSelectedTextColor(Clr c);
00115 
00123     virtual void SelectRange(CPSize from, CPSize to);
00124 
00127     virtual void SelectAll();
00128 
00129     virtual void SetText(const std::string& str);
00130 
00131     virtual void DefineAttributes(WndEditor* editor);
00133 
00134 protected: 
00136     Edit(); 
00137 
00138  
00140 
00141     virtual bool MultiSelected() const;
00142 
00144     CPSize FirstCharShown() const;
00145 
00148     bool RecentlyEdited() const;
00149 
00152     CPSize CharIndexOf(X x) const;
00153 
00156     X FirstCharOffset() const;
00157 
00160     X ScreenPosOfChar(CPSize idx) const;
00161 
00164     CPSize LastVisibleChar() const;
00165 
00167     unsigned int LastButtonDownTime() const;
00168 
00171     bool InDoubleButtonDownMode() const;
00172 
00175     std::pair<CPSize, CPSize> DoubleButtonDownCursorPos() const;
00177  
00179     virtual void LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00180     virtual void LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00181     virtual void LButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
00182     virtual void LClick(const Pt& pt, Flags<ModKey> mod_keys);
00183     virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
00184     virtual void GainingFocus();
00185     virtual void LosingFocus();
00186 
00194     std::pair<CPSize, CPSize> GetDoubleButtonDownWordIndices(CPSize char_index);
00195 
00201     std::pair<CPSize, CPSize> GetDoubleButtonDownDragWordIndices(CPSize char_index);
00202 
00205     void ClearDoubleButtonDownMode();
00207 
00210     static const int PIXEL_MARGIN;
00211 
00212 private:
00213     void ClearSelected(); 
00214     void AdjustView();    
00215 
00219     std::pair<CPSize, CPSize> m_cursor_pos;
00220 
00221     CPSize       m_first_char_shown; 
00222     Clr          m_int_color;        
00223     Clr          m_hilite_color;     
00224     Clr          m_sel_text_color;   
00225 
00226     bool         m_recently_edited;  
00227 
00228     unsigned int m_last_button_down_time;
00229     bool         m_in_double_click_mode;
00230     std::pair<CPSize, CPSize> m_double_click_cursor_pos;
00231 
00232     friend class boost::serialization::access;
00233     template <class Archive>
00234     void serialize(Archive& ar, const unsigned int version);
00235 };
00236 
00237 void GG_API GetTranslatedCodePoint(Key key,
00238                                    boost::uint32_t key_code_point,
00239                                    Flags<ModKey> mod_keys,
00240                                    std::string& translated_code_point);
00241 
00242 } // namespace GG
00243 
00244 // template implementations
00245 template <class Archive>
00246 void GG::Edit::serialize(Archive& ar, const unsigned int version)
00247 {
00248     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(TextControl)
00249         & BOOST_SERIALIZATION_NVP(m_cursor_pos)
00250         & BOOST_SERIALIZATION_NVP(m_first_char_shown)
00251         & BOOST_SERIALIZATION_NVP(m_int_color)
00252         & BOOST_SERIALIZATION_NVP(m_hilite_color)
00253         & BOOST_SERIALIZATION_NVP(m_sel_text_color);
00254 }
00255 
00256 #endif // _GG_Edit_h_