Edit.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_Edit_h_
00030 #define _GG_Edit_h_
00031 
00032 #include <GG/TextControl.h>
00033 
00034 
00035 namespace GG {
00036 
00049 class GG_API Edit : public TextControl
00050 {
00051 public: 
00053     typedef boost::signal<void (const std::string&)> EditedSignalType; 
00054     typedef boost::signal<void (const std::string&)> FocusUpdateSignalType; 
00055 
00056  
00058     typedef EditedSignalType::slot_type       EditedSlotType;      
00059     typedef FocusUpdateSignalType::slot_type  FocusUpdateSlotType; 
00060 
00061  
00063     Edit(int x, int y, int w, const std::string& str, const boost::shared_ptr<Font>& font, Clr color, Clr text_color = CLR_BLACK, Clr interior = CLR_ZERO, Flags<WndFlag> flags = CLICKABLE); 
00064 
00065  
00067     virtual Pt     MinUsableSize() const;
00068     virtual Pt     ClientUpperLeft() const;
00069     virtual Pt     ClientLowerRight() const;
00070 
00071     const std::pair<int, int>&
00072                    CursorPosn() const;         
00073     Clr            InteriorColor() const;      
00074     Clr            HiliteColor() const;        
00075     Clr            SelectedTextColor() const;  
00076 
00077     mutable EditedSignalType      EditedSignal;       
00078     mutable FocusUpdateSignalType FocusUpdateSignal;  
00079 
00080  
00082     virtual void   Render();
00083     virtual void   LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00084     virtual void   LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00085     virtual void   LClick(const Pt& pt, Flags<ModKey> mod_keys);
00086     virtual void   KeyPress(Key key, Flags<ModKey> mod_keys);
00087     virtual void   GainingFocus();
00088     virtual void   LosingFocus();
00089 
00090     virtual void   SetColor(Clr c);
00091     void           SetInteriorColor(Clr c);     
00092     void           SetHiliteColor(Clr c);       
00093     void           SetSelectedTextColor(Clr c); 
00094 
00099     virtual void   SelectRange(int from, int to);
00100 
00102     virtual void   SelectAll();
00103 
00104     virtual void   SetText(const std::string& str);
00105 
00106     virtual void   DefineAttributes(WndEditor* editor);
00108    
00109 protected: 
00111     Edit(); 
00112 
00113  
00115     virtual bool            MultiSelected() const;          
00116     int                     FirstCharShown() const;         
00117     bool                    RecentlyEdited() const;         
00118     int                     CharIndexOf(int x) const;       
00119     int                     FirstCharOffset() const;        
00120     int                     ScreenPosOfChar(int idx) const; 
00121     int                     LastVisibleChar() const;        
00122     int                     LastButtonDownTime() const;     
00123     bool                    InDoubleButtonDownMode() const; 
00124     std::pair<int, int>     DoubleButtonDownCursorPos() const; 
00125 
00126  
00128 
00132     std::pair<int, int>     GetDoubleButtonDownWordIndices(int char_index);
00133 
00137     std::pair<int, int>     GetDoubleButtonDownDragWordIndices(int char_index);
00138 
00140     void                    ClearDoubleButtonDownMode();
00142 
00143     static const int PIXEL_MARGIN; 
00144 
00145 private:
00146     void         ClearSelected();       
00147     void         AdjustView();          
00148 
00151     std::pair<int, int> m_cursor_pos;
00152 
00153     int                 m_first_char_shown; 
00154     Clr                 m_int_color;        
00155     Clr                 m_hilite_color;     
00156     Clr                 m_sel_text_color;   
00157 
00158     bool                m_recently_edited;  
00159 
00160     int                 m_last_button_down_time;
00161     bool                m_in_double_click_mode;
00162     std::pair<int, int> m_double_click_cursor_pos;
00163 
00164     friend class boost::serialization::access;
00165     template <class Archive>
00166     void serialize(Archive& ar, const unsigned int version);
00167 };
00168 
00169 } // namespace GG
00170 
00171 // template implementations
00172 template <class Archive>
00173 void GG::Edit::serialize(Archive& ar, const unsigned int version)
00174 {
00175     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(TextControl)
00176         & BOOST_SERIALIZATION_NVP(m_cursor_pos)
00177         & BOOST_SERIALIZATION_NVP(m_first_char_shown)
00178         & BOOST_SERIALIZATION_NVP(m_int_color)
00179         & BOOST_SERIALIZATION_NVP(m_hilite_color)
00180         & BOOST_SERIALIZATION_NVP(m_sel_text_color);
00181 }
00182 
00183 #endif // _GG_Edit_h_

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