00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __GUI_WIDGETS_TEXT_HPP_INCLUDED__
00016 #define __GUI_WIDGETS_TEXT_HPP_INCLUDED__
00017
00018 #include "gui/widgets/control.hpp"
00019
00020 #include <string>
00021
00022 namespace gui2 {
00023
00024
00025
00026
00027 class ttext_ : public tcontrol
00028 {
00029
00030 public:
00031 ttext_() :
00032 tcontrol(COUNT),
00033 state_(ENABLED),
00034 text_(),
00035 sel_start_(0),
00036 sel_len_(0),
00037 max_length_(std::string::npos),
00038 dragging_(false)
00039 {
00040 }
00041
00042 void set_active(const bool ) { };
00043 bool get_active() const { return true; }
00044 unsigned get_state() const { return state_; }
00045
00046 void mouse_move(tevent_handler&);
00047
00048 void mouse_left_button_down(tevent_handler& event);
00049 void mouse_left_button_up(tevent_handler&);
00050 void mouse_left_button_double_click(tevent_handler&);
00051
00052 void mouse_middle_button_click(tevent_handler&);
00053
00054 void key_press(tevent_handler& event, bool& handled, SDLKey key, SDLMod modifier, Uint16 unicode);
00055
00056
00057 void set_text(const std::string& text);
00058 std::string get_text() const { return text_; }
00059 const std::string& text() const { return text_; }
00060
00061 protected:
00062
00063 virtual void goto_end_of_line(const bool select = false) = 0;
00064 void goto_end_of_data(const bool select = false) { set_cursor(text_.size(), select); }
00065
00066 virtual void goto_start_of_line(const bool select = false) = 0;
00067 void goto_start_of_data(const bool select = false) { set_cursor(0, select); }
00068
00069 void select_all() { sel_start_ = 0; goto_end_of_data(true); }
00070
00071 void set_cursor(const size_t offset, const bool select);
00072
00073 size_t get_sel_start() const { return sel_start_; }
00074 void set_sel_start(const size_t sel_start) { sel_start_ = sel_start; set_dirty(); }
00075
00076 size_t get_sel_len() const { return sel_len_; }
00077 void set_sel_len(const unsigned sel_len) { sel_len_ = sel_len; set_dirty(); }
00078
00079
00080 virtual void insert_char(Uint16 unicode) = 0;
00081
00082
00083 virtual void delete_char(const bool before_cursor) = 0;
00084
00085
00086 virtual void delete_selection() = 0;
00087
00088
00089 virtual void copy_selection(const bool mouse);
00090
00091
00092 virtual void paste_selection(const bool mouse);
00093
00094 protected:
00095
00096 std::string& text() { return text_; }
00097
00098 size_t& sel_start() { return sel_start_; }
00099
00100 int& sel_len() { return sel_len_; }
00101
00102 private:
00103
00104 enum tstate { ENABLED, DISABLED, FOCUSSED, COUNT };
00105
00106 void set_state(tstate state);
00107 tstate state_;
00108
00109
00110
00111 std::string text_;
00112
00113
00114 virtual void calculate_char_offset() = 0;
00115
00116 size_t sel_start_;
00117
00118
00119
00120 int sel_len_;
00121 size_t max_length_;
00122
00123
00124 bool dragging_;
00125
00126
00127 virtual void handle_key_up_arrow(SDLMod modifier, bool& handled) = 0;
00128 virtual void handle_key_down_arrow(SDLMod modifier, bool& handled) = 0;
00129
00130
00131 virtual void handle_key_clear_line(SDLMod modifier, bool& handled) = 0;
00132
00133
00134
00135
00136 virtual void handle_key_left_arrow(SDLMod modifier, bool& handled);
00137
00138
00139
00140
00141 virtual void handle_key_right_arrow(SDLMod modifier, bool& handled);
00142
00143
00144
00145
00146 virtual void handle_key_home(SDLMod modifier, bool& handled);
00147
00148
00149
00150
00151 virtual void handle_key_end(SDLMod modifier, bool& handled);
00152
00153
00154 virtual void handle_key_backspace(SDLMod modifier, bool& handled);
00155
00156
00157 virtual void handle_key_delete(SDLMod modifier, bool& handled);
00158
00159
00160 virtual void handle_key_default(bool& handled, SDLKey key, SDLMod modifier, Uint16 unicode);
00161
00162
00163 virtual void handle_key_page_up(SDLMod , bool& ) {}
00164 virtual void handle_key_page_down(SDLMod , bool& ) {}
00165 };
00166
00167 }
00168
00169 #endif