ocarina: Add a make_button_data() function

Used for passing extra data through the button clicked callback.  I also
use this patch to remove the extra GdkEvent argument passed to buttons,
since this argument isn't actually part of the callback...

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-05-13 13:36:42 -04:00
parent 5363cfac82
commit d03e38ffbb
6 changed files with 39 additions and 24 deletions

View File

@ -6,17 +6,22 @@ using namespace std;
#include <ocarina/ocarina.h>
GtkWidget *make_button_data(const gchar *stockid,
void (* func)(GtkWidget *, gpointer),
gpointer data,
bool show);
GtkWidget *make_button(const gchar *stockid,
void (* func)(GtkWidget *, GdkEvent *, gpointer),
void (* func)(GtkWidget *, gpointer),
bool show);
GtkWidget *make_larger_button(const gchar *stockid,
void (* func)(GtkWidget *, GdkEvent *, gpointer),
void (* func)(GtkWidget *, gpointer),
bool show);
GtkWidget *make_text_button(const gchar *stockid,
string text,
void (* func)(GtkWidget *, GdkEvent *, gpointer),
void (* func)(GtkWidget *, gpointer),
bool show);

View File

@ -53,27 +53,27 @@ static void slider_changed(GtkWidget *w, GtkScrollType s, gdouble v, gpointer d)
libsaria::audio::seek_to(v);
}
static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_play(GtkWidget *b, gpointer d)
{
libsaria::audio::play();
}
static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_pause(GtkWidget *b, gpointer d)
{
libsaria::audio::pause();
}
static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_stop(GtkWidget *b, gpointer d)
{
libsaria::audio::stop();
}
static void on_click_prev(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_prev(GtkWidget *b, gpointer d)
{
libsaria::deck::prev();
}
static void on_click_next(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_next(GtkWidget *b, gpointer d)
{
libsaria::deck::next();
}

View File

@ -85,7 +85,7 @@ void LibraryDriver::path_removed(libsaria::library::Path *path)
gtk_list_store_remove(path_list, &iter);
}
static void on_click_add(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_add(GtkWidget *b, gpointer d)
{
string dir = ocarina::choose_dir();
if (dir != "") {
@ -94,7 +94,7 @@ static void on_click_add(GtkWidget *b, GdkEvent *e, gpointer d)
}
}
static void on_click_update(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_update(GtkWidget *b, gpointer d)
{
println("Update button clicked");
}
@ -140,7 +140,7 @@ static gboolean key_pressed(GtkWidget *treeview, GdkEvent *event, gpointer data)
if (key == "Delete")
libsaria::library::delete_path(path);
else if (key == "plus" || key == "KP_Add")
on_click_add(NULL, NULL, NULL);
on_click_add(NULL, NULL);
else
return FALSE;
return TRUE;

View File

@ -10,7 +10,7 @@ static GtkWidget *tabs;
static GtkWidget *action_box;
static GtkWidget *open_button;
static void on_click_open_file(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_open_file(GtkWidget *b, gpointer d)
{
string file = ocarina::choose_file();
if (file != "") {

View File

@ -5,11 +5,12 @@
#include <libsaria/audio.h>
#include <libsaria/print.h>
static GtkWidget *get_button(void (* func)(GtkWidget *, GdkEvent *, gpointer),
static GtkWidget *get_button(void (* func)(GtkWidget *, gpointer),
gpointer data,
bool show)
{
GtkWidget *button = gtk_button_new();
GTK_CONNECT(button, "clicked", func, NULL);
g_signal_connect(button, "clicked", G_CALLBACK(func), data);
if (show == true)
gtk_widget_show(button);
return button;
@ -29,22 +30,31 @@ static GtkWidget *get_label(string text)
return label;
}
GtkWidget *make_button(const gchar *stockid,
void (* func)(GtkWidget *, GdkEvent *, gpointer),
bool show)
GtkWidget *make_button_data(const gchar *stockid,
void (* func)(GtkWidget *, gpointer),
gpointer data,
bool show)
{
GtkWidget *button = get_button(func, show);
GtkWidget *button = get_button(func, data, show);
GtkWidget *image = get_image(stockid, GTK_ICON_SIZE_MENU);
container_add(button, image);
return button;
}
GtkWidget *make_button(const gchar *stockid,
void (* func)(GtkWidget *, gpointer),
bool show)
{
return make_button_data(stockid, func, NULL, show);
}
GtkWidget *make_larger_button(const gchar *stockid,
void (* func)(GtkWidget *, GdkEvent *, gpointer),
void (* func)(GtkWidget *, gpointer),
bool show)
{
GtkWidget *button = get_button(func, show);
GtkWidget *button = get_button(func, NULL, show);
GtkWidget *image = get_image(stockid, GTK_ICON_SIZE_BUTTON);
gtk_container_add(GTK_CONTAINER(button), image);
return button;
@ -52,10 +62,10 @@ GtkWidget *make_larger_button(const gchar *stockid,
GtkWidget *make_text_button(const gchar *stockid,
string text,
void (* func)(GtkWidget *, GdkEvent *, gpointer),
void (* func)(GtkWidget *, gpointer),
bool show)
{
GtkWidget *button = get_button(func, show);
GtkWidget *button = get_button(func, NULL, show);
GtkWidget *image = get_image(stockid, GTK_ICON_SIZE_BUTTON);
GtkWidget *label = get_label(text);
GtkWidget *box = gtk_hbox_new(FALSE, 0);

View File

@ -15,7 +15,7 @@ using namespace std;
static GtkWidget *library_settings = NULL;
static map<GtkWidget *, string> widget_mapping;
static void on_click_add(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_add(GtkWidget *b, gpointer d)
{
string dir = ocarina::choose_dir();
if (dir != "" ) {
@ -24,7 +24,7 @@ static void on_click_add(GtkWidget *b, GdkEvent *e, gpointer d)
}
}
static void on_click_update(GtkWidget *b, GdkEvent *e, gpointer d)
static void on_click_update(GtkWidget *b, gpointer d)
{
//libsaria::library::update();
}