Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GUI_WIDGETS_TEXT_BOX_HPP_INCLUDED
00017 #define GUI_WIDGETS_TEXT_BOX_HPP_INCLUDED
00018
00019 #include "gui/widgets/text.hpp"
00020
00021 namespace gui2 {
00022
00023
00024
00025
00026
00027
00028
00029
00030 class ttext_history
00031 {
00032 public:
00033
00034
00035
00036
00037
00038
00039
00040
00041 static ttext_history get_history(const std::string& id, const bool enabled);
00042
00043 ttext_history() :
00044 history_(0),
00045 pos_(0),
00046 enabled_(false)
00047 {
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 void push(const std::string& text);
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 std::string up(const std::string& text = "");
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 std::string down(const std::string& text = "");
00081
00082
00083
00084
00085
00086
00087
00088
00089 std::string get_value() const;
00090
00091
00092
00093 void set_enabled(bool enabled = true) { enabled_ = enabled; }
00094 bool get_enabled() const { return enabled_; }
00095
00096 private:
00097 ttext_history(std::vector<std::string>* history, const bool enabled) :
00098 history_(history),
00099 pos_(history->size()),
00100 enabled_(enabled)
00101 {}
00102
00103
00104 std::vector<std::string>* history_;
00105
00106
00107 unsigned pos_;
00108
00109
00110 bool enabled_;
00111 };
00112
00113
00114 class ttext_box : public ttext_
00115 {
00116 public:
00117 ttext_box();
00118
00119
00120 void save_to_history() { history_.push(get_value()); }
00121
00122
00123
00124 void set_history(const std::string& id)
00125 { history_ = ttext_history::get_history(id, true); }
00126
00127 protected:
00128
00129
00130
00131
00132 void place(const tpoint& origin, const tpoint& size);
00133
00134
00135
00136
00137 void update_canvas();
00138
00139
00140 void goto_end_of_line(const bool select = false)
00141 { goto_end_of_data(select); }
00142
00143
00144 void goto_start_of_line(const bool select = false)
00145 { goto_start_of_data(select); }
00146
00147
00148 void delete_char(const bool before_cursor);
00149
00150
00151 void delete_selection();
00152
00153 void handle_mouse_selection(tpoint mouse, const bool start_selection);
00154 private:
00155
00156
00157 ttext_history history_;
00158
00159
00160
00161
00162
00163
00164
00165 unsigned text_x_offset_;
00166
00167
00168
00169
00170
00171
00172 unsigned text_y_offset_;
00173
00174
00175
00176
00177
00178
00179 unsigned text_height_;
00180
00181
00182 void update_offsets();
00183
00184
00185 bool dragging_;
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 void handle_key_up_arrow(SDLMod , bool& ) {}
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 void handle_key_down_arrow(SDLMod , bool& ) {}
00206
00207
00208
00209
00210
00211
00212 bool history_up();
00213
00214
00215
00216
00217
00218
00219 bool history_down();
00220
00221
00222 void handle_key_default(
00223 bool& handled, SDLKey key, SDLMod modifier, Uint16 unicode);
00224
00225
00226 void handle_key_clear_line(SDLMod modifier, bool& handled);
00227
00228
00229 const std::string& get_control_type() const;
00230
00231
00232 void load_config_extra();
00233
00234
00235
00236 void signal_handler_mouse_motion(
00237 const event::tevent event, bool& handled, const tpoint& coordinate);
00238
00239 void signal_handler_left_button_down(
00240 const event::tevent event, bool& handled);
00241
00242 void signal_handler_left_button_up(
00243 const event::tevent event, bool& handled);
00244
00245 void signal_handler_left_button_double_click(
00246 const event::tevent event, bool& handled);
00247 };
00248
00249 }
00250
00251 #endif
00252