GG
MultiEdit.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_MultiEdit_h_
30 #define _GG_MultiEdit_h_
31 
32 #include <GG/Edit.h>
33 #include <GG/MultiEditFwd.h>
34 
35 
36 namespace GG {
37 
38 class Scroll;
39 
60 class GG_API MultiEdit : public Edit
61 {
62 public:
64 
65  MultiEdit(X x, Y y, X w, Y h, const std::string& str, const boost::shared_ptr<Font>& font,
66  Clr color, Flags<MultiEditStyle> style = MULTI_LINEWRAP, Clr text_color = CLR_BLACK,
67  Clr interior = CLR_ZERO, Flags<WndFlag> flags = INTERACTIVE);
68 
70  virtual ~MultiEdit();
72 
74  virtual Pt MinUsableSize() const;
75  virtual Pt ClientLowerRight() const;
76 
78  Flags<MultiEditStyle> Style() const;
79 
83  std::size_t MaxLinesOfHistory() const;
85 
87  virtual void Render();
88 
89  virtual void SizeMove(const Pt& ul, const Pt& lr);
90 
91  virtual void SelectAll();
92  virtual void SetText(const std::string& str);
93 
95  void SetStyle(Flags<MultiEditStyle> style);
96 
99  void SetMaxLinesOfHistory(std::size_t max);
101 
105  static const std::size_t ALL_LINES;
106 
108  static const unsigned int BORDER_THICK;
109 
110 protected:
112  MultiEdit();
113 
114 
116 
117  virtual bool MultiSelected() const;
118 
121  X RightMargin() const;
122 
125  Y BottomMargin() const;
126 
129  std::pair<std::size_t, CPSize> CharAt(const Pt& pt) const;
130 
134  std::pair<std::size_t, CPSize> CharAt(CPSize idx) const;
135 
137  Pt ScrollPosition() const;
138 
145  CPSize CharIndexOf(std::size_t row, CPSize char_idx,
146  const std::vector<Font::LineData>* line_data = 0) const;
147 
150  X RowStartX(std::size_t row) const;
151 
154  X CharXOffset(std::size_t row, CPSize idx) const;
155 
158  std::size_t RowAt(Y y) const;
159 
162  CPSize CharAt(std::size_t row, X x) const;
163 
165  std::size_t FirstVisibleRow() const;
166 
168  std::size_t LastVisibleRow() const;
169 
171  std::size_t FirstFullyVisibleRow() const;
172 
174  std::size_t LastFullyVisibleRow() const;
175 
178  CPSize FirstVisibleChar(std::size_t row) const;
179 
182  CPSize LastVisibleChar(std::size_t row) const;
183 
185  std::pair<std::size_t, CPSize> HighCursorPos() const;
186 
188  std::pair<std::size_t, CPSize> LowCursorPos() const;
190 
192  virtual void LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
193  virtual void LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
194  virtual void MouseWheel(const Pt& pt, int move, Flags<ModKey> mod_keys);
195  virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
196 
198  void RecreateScrolls();
199 
207  void PreserveTextPositionOnNextSetText();
209 
212  static const unsigned int SCROLL_WIDTH;
213 
214 private:
215  void Init();
216  void ValidateStyle();
217  void ClearSelected();
218  void AdjustView();
219  void AdjustScrolls();
220  void VScrolled(int upper, int lower, int range_upper, int range_lower);
221  void HScrolled(int upper, int lower, int range_upper, int range_lower);
222 
223  Flags<MultiEditStyle> m_style;
224 
225  std::pair<std::size_t, CPSize> m_cursor_begin;
226  std::pair<std::size_t, CPSize> m_cursor_end;
227  // if m_cursor_begin == m_cursor_end, the caret is draw at m_cursor_end
228 
229  Pt m_contents_sz;
230 
231  X m_first_col_shown;
232  Y m_first_row_shown;
233 
234  std::size_t m_max_lines_history;
235 
236  Scroll* m_vscroll;
237  Scroll* m_hscroll;
238 
239  bool m_preserve_text_position_on_next_set_text;
240  bool m_ignore_adjust_scrolls;
241 };
242 
243 } // namespace GG
244 
245 #endif