Commit 098a1ce9 authored by Davis King's avatar Davis King

Added copy and paste support to the text_field and also cleaned up some

of the popup_menu stuff.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402730
parent ce6e08e3
......@@ -1707,7 +1707,7 @@ namespace dlib
for (unsigned long i = 0; i < items.size(); ++i)
{
if (std::tolower(key) == std::tolower(items[i]->get_hot_key()) &&
(items[i]->has_click_event() || submenus[i]) )
(items[i]->has_click_event() || submenus[i]) && item_enabled[i] )
{
// only hide this popup window if this isn't a submenu
if (submenus[i] == 0)
......@@ -3078,6 +3078,8 @@ namespace dlib
drawable(w,MOUSE_CLICK | KEYBOARD_EVENTS | FOCUS_EVENTS | WINDOW_MOVED),
popup_menu_shown(false)
{
menu_.set_on_hide_handler(*this,&popup_menu_region::on_menu_becomes_hidden);
enable_events();
}
......@@ -3102,6 +3104,17 @@ namespace dlib
rect = resize_rect(rect,width,height);
}
// ----------------------------------------------------------------------------------------
void popup_menu_region::
set_rect (
const rectangle& new_rect
)
{
auto_mutex M(m);
rect = new_rect;
}
// ----------------------------------------------------------------------------------------
popup_menu& popup_menu_region::
......@@ -3153,6 +3166,21 @@ namespace dlib
menu_.hide();
popup_menu_shown = false;
}
if (key == (unsigned long)base_window::KEY_ESC)
{
menu_.hide();
popup_menu_shown = false;
}
}
// ----------------------------------------------------------------------------------------
void popup_menu_region::
on_menu_becomes_hidden (
)
{
popup_menu_shown = false;
}
// ----------------------------------------------------------------------------------------
......
......@@ -1676,19 +1676,17 @@ namespace dlib
if (c.intersect(rect).is_empty())
return;
if (enabled)
{
f->draw_string(c,rect,text);
}
else
{
f->draw_string(c,rect,text,128);
}
unsigned char color = 0;
if (enabled == false)
color = 128;
f->draw_string(c,rect,text,color);
if (underline_p1 != underline_p2)
{
point base(rect.left(),rect.top());
draw_line(c, base+underline_p1, base+underline_p2);
draw_line(c, base+underline_p1, base+underline_p2, color);
}
}
......@@ -2486,6 +2484,10 @@ namespace dlib
class popup_menu_region : public drawable
{
/*!
CONVENTION
popup_menu_visible() == popup_menu_shown
!*/
public:
......@@ -2501,6 +2503,10 @@ namespace dlib
long height
);
void set_rect (
const rectangle& new_rect
);
popup_menu& menu (
);
......@@ -2510,6 +2516,9 @@ namespace dlib
void disable (
);
bool popup_menu_visible (
) const { auto_mutex M(m); return popup_menu_shown; }
protected:
void on_keydown (
......@@ -2535,6 +2544,9 @@ namespace dlib
bool is_double_click
);
void on_menu_becomes_hidden (
);
void draw (
const canvas&
) const;
......
......@@ -1481,6 +1481,9 @@ namespace dlib
class popup_menu_region : public drawable
{
/*!
INITIAL VALUE
- popup_menu_visible() == false
WHAT THIS OBJECT REPRESENTS
This object represents a region on a window where if the user
right clicks the mouse over this region a popup_menu pops up.
......@@ -1525,6 +1528,24 @@ namespace dlib
same but its width and height are modified
!*/
void set_rect (
const rectangle& new_rect
);
/*!
ensures
- #get_rect() == new_rect
!*/
bool popup_menu_visible (
) const;
/*!
ensures
- if (the popup menu is currently visible on the screen) then
- returns true
- else
- returns false
!*/
popup_menu& menu (
);
/*!
......
This diff is collapsed.
......@@ -359,12 +359,22 @@ namespace dlib
highlight_start(0),
highlight_end(-1),
shift_pos(-1),
t(*this,&text_field::timer_action)
t(*this,&text_field::timer_action),
right_click_menu(w)
{
style.reset(new text_field_style_default());
rect.set_bottom(mfont->height()+ (style->get_padding(*mfont))*2);
rect.set_right((style->get_padding(*mfont))*2);
cursor_x = style->get_padding(*mfont);
right_click_menu.menu().add_menu_item(menu_item_text("Cut",*this,&text_field::on_cut,'t'));
right_click_menu.menu().add_menu_item(menu_item_text("Copy",*this,&text_field::on_copy,'C'));
right_click_menu.menu().add_menu_item(menu_item_text("Paste",*this,&text_field::on_paste,'P'));
right_click_menu.menu().add_menu_item(menu_item_text("Delete",*this,&text_field::on_delete_selected,'D'));
right_click_menu.menu().add_menu_item(menu_item_separator());
right_click_menu.menu().add_menu_item(menu_item_text("Select All",*this,&text_field::on_select_all,'A'));
right_click_menu.set_rect(get_text_rect());
enable_events();
t.set_delay_time(500);
......@@ -430,6 +440,11 @@ namespace dlib
unsigned long width
);
void set_pos (
long x,
long y
);
void set_main_font (
const shared_ptr_thread_safe<font>& f
);
......@@ -443,9 +458,15 @@ namespace dlib
void disable (
);
void enable (
);
void hide (
);
void show (
);
template <
typename T
>
......@@ -485,6 +506,27 @@ namespace dlib
private:
void on_cut (
);
void on_copy (
);
void on_paste (
);
void on_select_all (
);
void on_delete_selected (
);
void on_text_is_selected (
);
void on_no_text_selected (
);
void on_user_event (
int num
)
......@@ -561,6 +603,8 @@ namespace dlib
timer<text_field>::kernel_2a t;
popup_menu_region right_click_menu;
// restricted functions
text_field(text_field&); // copy constructor
text_field& operator=(text_field&); // assignment operator
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment