GG
Edit.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3  Copyright (C) 2003-2008 T. Zachary Laine
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public License
7  as published by the Free Software Foundation; either version 2.1
8  of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free
17  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  02111-1307 USA
19 
20  If you do not wish to comply with the terms of the LGPL please
21  contact the author as other terms are available for a fee.
22 
23  Zach Laine
24  whatwasthataddress@gmail.com */
25 
29 #ifndef _GG_Edit_h_
30 #define _GG_Edit_h_
31 
32 #include <GG/ClrConstants.h>
33 #include <GG/TextControl.h>
34 
35 
36 namespace GG {
37 
57 class GG_API Edit : public TextControl
58 {
59 public:
61 
63  typedef boost::signal<void (const std::string&)> EditedSignalType;
64 
68  typedef boost::signal<void (const std::string&)> FocusUpdateSignalType;
70 
72 
73  Edit(X x, Y y, X w, const std::string& str, const boost::shared_ptr<Font>& font, Clr color,
74  Clr text_color = CLR_BLACK, Clr interior = CLR_ZERO, Flags<WndFlag> flags = INTERACTIVE);
76 
78  virtual Pt MinUsableSize() const;
79  virtual Pt ClientUpperLeft() const;
80  virtual Pt ClientLowerRight() const;
81 
84  const std::pair<CPSize, CPSize>& CursorPosn() const;
85 
87  Clr InteriorColor() const;
88 
90  Clr HiliteColor() const;
91 
93  Clr SelectedTextColor() const;
94 
97 
101 
103  virtual void Render();
104 
105  virtual void SetColor(Clr c);
106 
108  void SetInteriorColor(Clr c);
109 
111  void SetHiliteColor(Clr c);
112 
114  void SetSelectedTextColor(Clr c);
115 
123  virtual void SelectRange(CPSize from, CPSize to);
124 
127  virtual void SelectAll();
128 
129  virtual void SetText(const std::string& str);
131 
132 protected:
134  Edit();
135 
136 
138 
139  virtual bool MultiSelected() const;
140 
142  CPSize FirstCharShown() const;
143 
146  bool RecentlyEdited() const;
147 
150  CPSize CharIndexOf(X x) const;
151 
154  X FirstCharOffset() const;
155 
158  X ScreenPosOfChar(CPSize idx) const;
159 
162  CPSize LastVisibleChar() const;
163 
165  unsigned int LastButtonDownTime() const;
166 
169  bool InDoubleButtonDownMode() const;
170 
173  std::pair<CPSize, CPSize> DoubleButtonDownCursorPos() const;
175 
177  virtual void LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
178  virtual void LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
179  virtual void LButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
180  virtual void LClick(const Pt& pt, Flags<ModKey> mod_keys);
181  virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
182  virtual void GainingFocus();
183  virtual void LosingFocus();
184 
192  std::pair<CPSize, CPSize> GetDoubleButtonDownWordIndices(CPSize char_index);
193 
199  std::pair<CPSize, CPSize> GetDoubleButtonDownDragWordIndices(CPSize char_index);
200 
203  void ClearDoubleButtonDownMode();
205 
208  static const int PIXEL_MARGIN;
209 
210 private:
211  void ClearSelected();
212  void AdjustView();
213 
217  std::pair<CPSize, CPSize> m_cursor_pos;
218 
219  CPSize m_first_char_shown;
220  Clr m_int_color;
221  Clr m_hilite_color;
222  Clr m_sel_text_color;
223 
224  bool m_recently_edited;
225 
226  unsigned int m_last_button_down_time;
227  bool m_in_double_click_mode;
228  std::pair<CPSize, CPSize> m_double_click_cursor_pos;
229 };
230 
231 void GG_API GetTranslatedCodePoint(Key key,
232  boost::uint32_t key_code_point,
233  Flags<ModKey> mod_keys,
234  std::string& translated_code_point);
235 
236 } // namespace GG
237 
238 #endif