Commit a4441c46 authored by Davis King's avatar Davis King

Switched the event handlers in the gui_widgets from member_function_pointers

to any_functions.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%404133
parent e2bc112a
......@@ -20,6 +20,7 @@
#include "../smart_pointers.h"
#include "../unicode.h"
#include <cctype>
#include "../any.h"
namespace dlib
......@@ -813,7 +814,7 @@ namespace dlib
)
{
auto_mutex M(m);
event_handler.set(object,event_handler_);
event_handler = make_mfp(object,event_handler_);
event_handler_self.clear();
}
......@@ -826,7 +827,7 @@ namespace dlib
)
{
auto_mutex M(m);
event_handler_self.set(object,event_handler_);
event_handler_self = make_mfp(object,event_handler_);
event_handler.clear();
}
......@@ -846,7 +847,7 @@ namespace dlib
)
{
auto_mutex M(m);
button_down_handler.set(object,event_handler);
button_down_handler = make_mfp(object,event_handler);
}
template <
......@@ -858,7 +859,7 @@ namespace dlib
)
{
auto_mutex M(m);
button_up_handler.set(object,event_handler);
button_up_handler = make_mfp(object,event_handler);
}
template <
......@@ -870,7 +871,7 @@ namespace dlib
)
{
auto_mutex M(m);
button_down_handler_self.set(object,event_handler);
button_down_handler_self = make_mfp(object,event_handler);
}
template <
......@@ -882,7 +883,7 @@ namespace dlib
)
{
auto_mutex M(m);
button_up_handler_self.set(object,event_handler);
button_up_handler_self = make_mfp(object,event_handler);
}
private:
......@@ -894,12 +895,12 @@ namespace dlib
dlib::ustring name_;
tooltip btn_tooltip;
member_function_pointer<>::kernel_1a event_handler;
member_function_pointer<button&>::kernel_1a event_handler_self;
member_function_pointer<>::kernel_1a button_down_handler;
member_function_pointer<bool>::kernel_1a button_up_handler;
member_function_pointer<button&>::kernel_1a button_down_handler_self;
member_function_pointer<bool,button&>::kernel_1a button_up_handler_self;
any_function<void()> event_handler;
any_function<void(button&)> event_handler_self;
any_function<void()> button_down_handler;
any_function<void(bool)> button_up_handler;
any_function<void(button&)> button_down_handler_self;
any_function<void(bool,button&)> button_up_handler_self;
scoped_ptr<button_style> style;
......@@ -991,7 +992,7 @@ namespace dlib
void set_scroll_handler (
T& object,
void (T::*eh)()
) { auto_mutex M(m); scroll_handler.set(object,eh); }
) { auto_mutex M(m); scroll_handler = make_mfp(object,eh); }
void set_pos (
long x,
......@@ -1183,8 +1184,8 @@ namespace dlib
button_action(w),
my_scroll_bar(object)
{
bup.set(object,up);
bdown.set(object,down);
bup = make_mfp(object,up);
bdown = make_mfp(object,down);
enable_events();
}
......@@ -1226,8 +1227,8 @@ namespace dlib
) { bup(mouse_over); }
scroll_bar& my_scroll_bar;
member_function_pointer<>::kernel_1a bdown;
member_function_pointer<bool>::kernel_1a bup;
any_function<void()> bdown;
any_function<void(bool)> bup;
};
friend class slider_class;
......@@ -1244,7 +1245,7 @@ namespace dlib
mouse_in_widget(false),
my_scroll_bar(object)
{
mfp.set(object,handler);
callback = make_mfp(object,handler);
enable_events();
}
......@@ -1311,7 +1312,7 @@ namespace dlib
void on_drag (
)
{
mfp();
callback();
}
void draw (
......@@ -1323,7 +1324,7 @@ namespace dlib
bool mouse_in_widget;
scroll_bar& my_scroll_bar;
member_function_pointer<>::kernel_1a mfp;
any_function<void()> callback;
};
......@@ -1349,7 +1350,7 @@ namespace dlib
slider_class slider;
bar_orientation ori;
filler top_filler, bottom_filler;
member_function_pointer<>::kernel_1a scroll_handler;
any_function<void()> scroll_handler;
long pos;
long max_pos;
......@@ -1569,7 +1570,7 @@ namespace dlib
private:
dlib::ustring text;
const shared_ptr_thread_safe<font> f;
member_function_pointer<>::kernel_1a action;
any_function<void()> action;
unichar hotkey;
point underline_p1;
point underline_p2;
......@@ -1587,7 +1588,7 @@ namespace dlib
)
{
dlib::ustring &str = text;
action.set(object,event_handler_);
action = make_mfp(object,event_handler_);
if (hk != 0)
{
......@@ -1713,7 +1714,7 @@ namespace dlib
private:
dlib::ustring text;
const shared_ptr_thread_safe<font> f;
member_function_pointer<>::kernel_1a action;
any_function<void()> action;
unichar hotkey;
point underline_p1;
point underline_p2;
......
......@@ -2690,12 +2690,12 @@ namespace dlib
void* param
)
{
// The point of this extra member function pointer stuff is to allow the user
// The point of this extra event_handler stuff is to allow the user
// to end the program from within the callback. So we want to destroy the
// window *before* we call their callback.
box_win& w = *reinterpret_cast<box_win*>(param);
w.close_window();
member_function_pointer<>::kernel_1a event_handler(w.event_handler);
any_function<void()> event_handler(w.event_handler);
delete &w;
if (event_handler.is_set())
event_handler();
......@@ -2717,10 +2717,10 @@ namespace dlib
on_window_close (
)
{
// The point of this extra member function pointer stuff is to allow the user
// The point of this extra event_handler stuff is to allow the user
// to end the program within the callback. So we want to destroy the
// window *before* we call their callback.
member_function_pointer<>::kernel_1a event_handler_copy(event_handler);
any_function<void()> event_handler_copy(event_handler);
delete this;
if (event_handler_copy.is_set())
event_handler_copy();
......
......@@ -25,6 +25,7 @@
#include "../misc_api.h"
#include <cctype>
#include <vector>
#include "../any.h"
#ifdef _MSC_VER
// This #pragma directive is also located in the algs.h file but for whatever
......@@ -240,7 +241,7 @@ namespace dlib
)
{
auto_mutex M(m);
event_handler.set(object,event_handler_);
event_handler = make_mfp(object,event_handler_);
event_handler_self.clear();
}
......@@ -253,7 +254,7 @@ namespace dlib
)
{
auto_mutex M(m);
event_handler_self.set(object,event_handler_);
event_handler_self = make_mfp(object,event_handler_);
event_handler.clear();
}
......@@ -267,8 +268,8 @@ namespace dlib
tooltip btn_tooltip;
bool checked;
member_function_pointer<>::kernel_1a event_handler;
member_function_pointer<toggle_button&>::kernel_1a event_handler_self;
any_function<void()> event_handler;
any_function<void(toggle_button&)> event_handler_self;
scoped_ptr<toggle_button_style> style;
......@@ -484,7 +485,7 @@ namespace dlib
)
{
auto_mutex M(m);
text_modified_handler.set(object,event_handler);
text_modified_handler = make_mfp(object,event_handler);
}
template <
......@@ -496,7 +497,7 @@ namespace dlib
)
{
auto_mutex M(m);
enter_key_handler.set(object,event_handler);
enter_key_handler = make_mfp(object,event_handler);
}
......@@ -509,7 +510,7 @@ namespace dlib
)
{
auto_mutex M(m);
focus_lost_handler.set(object,event_handler);
focus_lost_handler = make_mfp(object,event_handler);
}
private:
......@@ -603,9 +604,9 @@ namespace dlib
long highlight_start;
long highlight_end;
long shift_pos;
member_function_pointer<>::kernel_1a_c text_modified_handler;
member_function_pointer<>::kernel_1a_c enter_key_handler;
member_function_pointer<>::kernel_1a_c focus_lost_handler;
any_function<void()> text_modified_handler;
any_function<void()> enter_key_handler;
any_function<void()> focus_lost_handler;
scoped_ptr<text_field_style> style;
......@@ -849,7 +850,7 @@ namespace dlib
)
{
auto_mutex M(m);
text_modified_handler.set(object,event_handler);
text_modified_handler = make_mfp(object,event_handler);
}
template <
......@@ -861,7 +862,7 @@ namespace dlib
)
{
auto_mutex M(m);
enter_key_handler.set(object,event_handler);
enter_key_handler = make_mfp(object,event_handler);
}
......@@ -874,7 +875,7 @@ namespace dlib
)
{
auto_mutex M(m);
focus_lost_handler.set(object,event_handler);
focus_lost_handler = make_mfp(object,event_handler);
}
private:
......@@ -976,9 +977,9 @@ namespace dlib
long highlight_start;
long highlight_end;
long shift_pos;
member_function_pointer<>::kernel_1a_c text_modified_handler;
member_function_pointer<>::kernel_1a_c enter_key_handler;
member_function_pointer<>::kernel_1a_c focus_lost_handler;
any_function<void()> text_modified_handler;
any_function<void()> enter_key_handler;
any_function<void()> focus_lost_handler;
scoped_ptr<text_box_style> style;
......@@ -1163,7 +1164,7 @@ namespace dlib
)
{
auto_mutex M(m);
event_handler.set(object,eh);
event_handler = make_mfp(object,eh);
}
void set_tab_group (
......@@ -1240,7 +1241,7 @@ namespace dlib
const long top_pad;
const long bottom_pad;
member_function_pointer<unsigned long,unsigned long>::kernel_1a event_handler;
any_function<void(unsigned long,unsigned long)> event_handler;
// restricted functions
tabbed_display(tabbed_display&); // copy constructor
......@@ -1444,7 +1445,7 @@ namespace dlib
)
{
auto_mutex M(wm);
event_handler.set(object,event_handler_);
event_handler = make_mfp(object,event_handler_);
}
private:
......@@ -1464,7 +1465,7 @@ namespace dlib
label msg;
button btn_ok;
member_function_pointer<>::kernel_1a event_handler;
any_function<void()> event_handler;
};
class blocking_box_win : public drawable_window
......@@ -1667,7 +1668,7 @@ namespace dlib
void set_double_click_handler (
T& object,
void (T::*eh)(unsigned long index)
) { auto_mutex M(m); event_handler.set(object,eh); }
) { auto_mutex M(m); event_handler = make_mfp(object,eh); }
template <
typename T
......@@ -1675,7 +1676,7 @@ namespace dlib
void set_click_handler (
T& object,
void (T::*eh)(unsigned long index)
) { auto_mutex M(m); single_click_event_handler.set(object,eh); }
) { auto_mutex M(m); single_click_event_handler = make_mfp(object,eh); }
bool at_start (
) const;
......@@ -1730,8 +1731,8 @@ namespace dlib
bool ms_enabled;
typename array<data<S> >::kernel_2a_c items;
member_function_pointer<unsigned long>::kernel_1a event_handler;
member_function_pointer<unsigned long>::kernel_1a single_click_event_handler;
any_function<void(unsigned long)> event_handler;
any_function<void(unsigned long)> single_click_event_handler;
unsigned long last_selected;
scoped_ptr<list_box_style> style;
......@@ -1773,7 +1774,7 @@ namespace dlib
)
{
auto_mutex M(wm);
event_handler.set(object,event_handler_);
event_handler = make_mfp(object,event_handler_);
}
private:
......@@ -1836,7 +1837,7 @@ namespace dlib
std::string prefix;
int cur_dir;
member_function_pointer<const std::string&>::kernel_1a event_handler;
any_function<void(const std::string&)> event_handler;
sequence<scoped_ptr<toggle_button> >::kernel_2a_c sob;
};
}
......@@ -2309,7 +2310,7 @@ namespace dlib
)
{
auto_mutex M(m);
node_selected_handler.set(object,event_handler_);
node_selected_handler = make_mfp(object,event_handler_);
}
template <
......@@ -2321,7 +2322,7 @@ namespace dlib
)
{
auto_mutex M(m);
node_deselected_handler.set(object,event_handler_);
node_deselected_handler = make_mfp(object,event_handler_);
}
template <
......@@ -2333,7 +2334,7 @@ namespace dlib
)
{
auto_mutex M(m);
node_deleted_handler.set(object,event_handler_);
node_deleted_handler = make_mfp(object,event_handler_);
}
template <
......@@ -2345,7 +2346,7 @@ namespace dlib
)
{
auto_mutex M(m);
graph_modified_handler.set(object,event_handler_);
graph_modified_handler = make_mfp(object,event_handler_);
}
protected:
......@@ -2783,10 +2784,10 @@ namespace dlib
unsigned long selected_edge_parent;
unsigned long selected_edge_child;
member_function_pointer<unsigned long>::kernel_1a node_selected_handler;
member_function_pointer<unsigned long>::kernel_1a node_deselected_handler;
member_function_pointer<>::kernel_1a node_deleted_handler;
member_function_pointer<>::kernel_1a graph_modified_handler;
any_function<void(unsigned long)> node_selected_handler;
any_function<void(unsigned long)> node_deselected_handler;
any_function<void()> node_deleted_handler;
any_function<void()> graph_modified_handler;
graph_type external_graph;
// rebind the graph_ type to make us a graph_ of data structs
......@@ -2948,7 +2949,7 @@ namespace dlib
void set_text_modified_handler (
T& object,
void (T::*eh)(unsigned long, unsigned long)
) { text_modified_handler.set(object,eh); }
) { text_modified_handler = make_mfp(object,eh); }
private:
......@@ -3041,7 +3042,7 @@ namespace dlib
bool recent_cursor_move;
timer<text_grid>::kernel_2a cursor_timer;
rgb_pixel border_color_;
member_function_pointer<unsigned long, unsigned long>::kernel_1a_c text_modified_handler;
any_function<void(unsigned long, unsigned long)> text_modified_handler;
};
// ----------------------------------------------------------------------------------------
......
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