00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __GUI_WIDGETS_TEXT_BOX_HPP_INCLUDED__
00016 #define __GUI_WIDGETS_TEXT_BOX_HPP_INCLUDED__
00017
00018 #include "gui/widgets/text.hpp"
00019
00020
00021 namespace gui2 {
00022
00023
00024 class ttext_history
00025 {
00026 public:
00027
00028 static ttext_history get_history(const std::string& id, const bool enabled);
00029
00030
00031 ttext_history() :
00032 history_(0),
00033 pos_(0),
00034 enabled_(false)
00035 {
00036 }
00037
00038
00039
00040 void push(const std::string& text);
00041
00042
00043 std::string up(const std::string& text = "");
00044 std::string down(const std::string& text = "");
00045
00046
00047
00048 std::string get_value() const;
00049
00050 void set_enabled(bool enabled = true) { enabled_ = enabled; }
00051 bool get_enabled() const { return enabled_; }
00052
00053 private:
00054 ttext_history(std::vector<std::string>* history, const bool enabled) :
00055 history_(history),
00056 pos_(history->size()),
00057 enabled_(enabled)
00058 {}
00059
00060 std::vector<std::string>* history_;
00061 unsigned pos_;
00062
00063 bool enabled_;
00064 };
00065
00066
00067 class ttext_box : public ttext_
00068 {
00069
00070 public:
00071
00072 ttext_box() :
00073 ttext_(),
00074 character_offset_(),
00075 history_(),
00076 text_x_offset_(0),
00077 text_y_offset_(0),
00078 text_height_(0),
00079 dragging_(false)
00080 {
00081 set_wants_mouse_left_double_click();
00082 }
00083
00084 void set_history(const std::string& id)
00085 { history_ = ttext_history::get_history(id, true); }
00086
00087 void save_to_history() { history_.push(text()); }
00088 void save_to_history(const std::string& text) { history_.push(text); }
00089
00090 protected:
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 void insert_char(Uint16 unicode);
00102
00103
00104 void delete_char(const bool before_cursor);
00105
00106
00107 void delete_selection();
00108
00109
00110 void set_canvas_text();
00111
00112
00113 void set_size(const SDL_Rect& rect);
00114
00115 void goto_end_of_line(const bool select = false) { goto_end_of_data(select); }
00116 void goto_start_of_line(const bool select = false) { goto_start_of_data(select); }
00117
00118
00119 void handle_mouse_selection(tevent_handler& event, const bool start_selection);
00120
00121
00122 void mouse_left_button_down(tevent_handler& event);
00123
00124
00125 void mouse_move(tevent_handler& event);
00126
00127
00128 void mouse_left_button_up(tevent_handler&);
00129
00130
00131 void mouse_left_button_double_click(tevent_handler&);
00132
00133 private:
00134
00135 void handle_key_up_arrow(SDLMod modifier, bool& handled);
00136 void handle_key_down_arrow(SDLMod modifier, bool& handled);
00137
00138
00139 void handle_key_clear_line(SDLMod modifier, bool& handled);
00140
00141
00142 std::vector<unsigned> character_offset_;
00143
00144
00145 void calculate_char_offset();
00146
00147
00148
00149 unsigned get_character_offset_at(const unsigned offset);
00150
00151 ttext_history history_;
00152
00153
00154 const std::string& get_control_type() const
00155 { static const std::string type = "text_box"; return type; }
00156
00157
00158 void load_config_extra();
00159
00160 unsigned text_x_offset_;
00161 unsigned text_y_offset_;
00162 unsigned text_height_;
00163
00164
00165 void update_offsets();
00166
00167 bool dragging_;
00168 };
00169
00170
00171
00172 }
00173
00174 #endif
00175