00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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 }
00170
00171
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_