gui1: Make it possible to define an edit target textbox...

...for a non-editable textbox

Content-altering events on a non-editable textbox are forwarded to the
edit target textbox as long as it is editable itself.
This commit is contained in:
Ignacio R. Morelle 2012-12-23 06:10:46 +00:00
parent fae847e48e
commit f29b5b3758
2 changed files with 25 additions and 1 deletions

View File

@ -36,7 +36,8 @@ textbox::textbox(CVideo &video, int width, const std::string& text, bool editabl
grabmouse_(false), text_pos_(0), editable_(editable),
show_cursor_(true), show_cursor_at_(0), text_image_(NULL),
wrap_(false), line_height_(0), yscroll_(0), alpha_(alpha),
alpha_focus_(alpha_focus)
alpha_focus_(alpha_focus),
edit_target_(NULL)
{
// static const SDL_Rect area = d.screen_area();
// const int height = font::draw_text(NULL,area,font_size,font::NORMAL_COLOR,"ABCD",0,0).h;
@ -528,6 +529,7 @@ void textbox::handle_event(const SDL_Event& event)
case SDLK_v: // paste
{
if(!editable()) {
pass_event_to_target(event);
break;
}
@ -579,6 +581,8 @@ void textbox::handle_event(const SDL_Event& event)
++cursor_;
}
}
} else {
pass_event_to_target(event);
}
}
@ -598,4 +602,18 @@ void textbox::handle_event(const SDL_Event& event)
set_dirty(true);
}
void textbox::pass_event_to_target(const SDL_Event& event)
{
if(edit_target_ && edit_target_->editable()) {
set_focus(false);
edit_target_->set_focus(true);
edit_target_->handle_event(event);
}
}
void textbox::set_edit_target(textbox* target)
{
edit_target_ = target;
}
} //end namespace gui

View File

@ -41,6 +41,8 @@ public:
void set_wrap(bool val);
void set_edit_target(textbox* target);
protected:
virtual void draw_contents();
virtual void set_inner_location(SDL_Rect const &);
@ -80,8 +82,12 @@ private:
double alpha_;
double alpha_focus_;
textbox* edit_target_;
void handle_event(const SDL_Event& event);
void pass_event_to_target(const SDL_Event& event);
void draw_cursor(int pos, CVideo &video) const;
void update_text_cache(bool reset = false, const SDL_Color& color =font::NORMAL_COLOR);
surface add_text_line(const wide_string& text, const SDL_Color& color =font::NORMAL_COLOR);