Commit 146af066 authored by Davis King's avatar Davis King

Added the popup_menu_region widget.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402537
parent 54a1ffd3
......@@ -3258,6 +3258,149 @@ namespace dlib
};
scrollable_region::~scrollable_region(){}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// class popup_menu_region
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class popup_menu_region : public drawable
{
public:
popup_menu_region(
drawable_window& w
) :
drawable(w,MOUSE_CLICK | KEYBOARD_EVENTS | FOCUS_EVENTS | WINDOW_MOVED),
popup_menu_shown(false)
{
enable_events();
}
virtual ~popup_menu_region(
){ disable_events();}
void set_size (
long width,
long height
)
{
auto_mutex M(m);
rect = resize_rect(rect,width,height);
}
popup_menu& menu (
)
{
return menu_;
}
void hide (
)
{
auto_mutex M(m);
drawable::hide();
menu_.hide();
popup_menu_shown = false;
}
void disable (
)
{
auto_mutex M(m);
drawable::disable();
menu_.hide();
popup_menu_shown = false;
}
protected:
void on_keydown (
unsigned long key,
bool is_printable,
unsigned long state
)
{
if (enabled && !hidden && popup_menu_shown)
{
menu_.forwarded_on_keydown(key, is_printable, state);
}
else if (popup_menu_shown)
{
menu_.hide();
popup_menu_shown = false;
}
}
void on_focus_lost (
)
{
if (popup_menu_shown)
{
menu_.hide();
popup_menu_shown = false;
}
}
void on_focus_gained (
)
{
if (popup_menu_shown)
{
menu_.hide();
popup_menu_shown = false;
}
}
void on_window_moved(
)
{
if (popup_menu_shown)
{
menu_.hide();
popup_menu_shown = false;
}
}
void on_mouse_down (
unsigned long btn,
unsigned long state,
long x,
long y,
bool is_double_click
)
{
if (enabled && !hidden && rect.contains(x,y) && btn == base_window::RIGHT)
{
long orig_x, orig_y;
parent.get_pos(orig_x, orig_y);
menu_.set_pos(orig_x+x, orig_y+y);
menu_.show();
popup_menu_shown = true;
}
else if (popup_menu_shown)
{
menu_.hide();
popup_menu_shown = false;
}
}
void draw (
const canvas&
) const{}
private:
popup_menu menu_;
bool popup_menu_shown;
// restricted functions
popup_menu_region(popup_menu_region&); // copy constructor
popup_menu_region& operator=(popup_menu_region&); // assignment operator
};
// ----------------------------------------------------------------------------------------
}
......
......@@ -1322,6 +1322,79 @@ namespace dlib
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// class popup_menu_region
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class popup_menu_region : public drawable
{
/*!
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.
Note that this widget doesn't actually draw anything, it just
provides a region the user can click on to get a popup menu.
!*/
public:
popup_menu_region(
drawable_window& w
);
/*!
ensures
- #*this is properly initialized
- #*this has been added to window w
- #parent_window() == w
throws
- std::bad_alloc
- dlib::thread_error
!*/
virtual ~popup_menu_region(
);
/*!
ensures
- all resources associated with *this have been released
!*/
void set_size (
long width_,
long height_
);
/*!
ensures
- #width() == width_
- #height() == height_
- #top() == top()
- #left() == left()
- i.e. The location of the upper left corner of this widget stays the
same but its width and height are modified
!*/
popup_menu& menu (
);
/*!
ensures
- returns a reference to the popup_menu for this object. It is
the menu that is displayed when the user right clicks on
this widget
!*/
private:
// restricted functions
popup_menu_region(popup_menu_region&); // copy constructor
popup_menu_region& operator=(popup_menu_region&); // assignment operator
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// class zoomable_region
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class zoomable_region : public drawable
......
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