gtk-demo: Use normal way to lookup up symbols

We're a normal application, so we can use the normal way to hook up code
into builder files, which is using dlsym() for the function pointers.

There's no need to to extra work exporting static symbols.
This commit is contained in:
Benjamin Otte 2019-11-29 08:48:48 +01:00
parent 292371932b
commit a15fb95c46
14 changed files with 90 additions and 138 deletions

View File

@ -226,8 +226,8 @@ set_widget_type (GtkFishbowl *fishbowl,
}
void
next_button_clicked_cb (GtkButton *source,
gpointer user_data)
fishbowl_next_button_clicked_cb (GtkButton *source,
gpointer user_data)
{
GtkFishbowl *fishbowl = user_data;
int new_index;
@ -241,8 +241,8 @@ next_button_clicked_cb (GtkButton *source,
}
void
prev_button_clicked_cb (GtkButton *source,
gpointer user_data)
fishbowl_prev_button_clicked_cb (GtkButton *source,
gpointer user_data)
{
GtkFishbowl *fishbowl = user_data;
int new_index;
@ -256,8 +256,8 @@ prev_button_clicked_cb (GtkButton *source,
}
void
changes_toggled_cb (GtkToggleButton *button,
gpointer user_data)
fishbowl_changes_toggled_cb (GtkToggleButton *button,
gpointer user_data)
{
if (gtk_toggle_button_get_active (button))
gtk_button_set_icon_name (GTK_BUTTON (button), "changes-prevent");
@ -287,13 +287,7 @@ do_fishbowl (GtkWidget *do_widget)
g_type_ensure (GTK_TYPE_FISHBOWL);
builder = gtk_builder_new ();
gtk_builder_add_callback_symbols (builder,
"next_button_clicked_cb", G_CALLBACK (next_button_clicked_cb),
"prev_button_clicked_cb", G_CALLBACK (prev_button_clicked_cb),
"changes_toggled_cb", G_CALLBACK (changes_toggled_cb),
NULL);
gtk_builder_add_from_resource (builder, "/fishbowl/fishbowl.ui", NULL);
builder = gtk_builder_new_from_resource ("/fishbowl/fishbowl.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);

View File

@ -15,13 +15,13 @@
<child>
<object class="GtkButton">
<property name="icon-name">pan-start-symbolic</property>
<signal name="clicked" handler="prev_button_clicked_cb" object="bowl" swapped="no"/>
<signal name="clicked" handler="fishbowl_prev_button_clicked_cb" object="bowl" swapped="no"/>
</object>
</child>
<child>
<object class="GtkButton">
<property name="icon-name">pan-end-symbolic</property>
<signal name="clicked" handler="next_button_clicked_cb" object="bowl" swapped="no"/>
<signal name="clicked" handler="fishbowl_next_button_clicked_cb" object="bowl" swapped="no"/>
</object>
</child>
</object>
@ -50,7 +50,7 @@
<object class="GtkToggleButton" id="changes_allow">
<property name="icon-name">changes-allow</property>
<property name="relief">none</property>
<signal name="notify::active" handler="changes_toggled_cb"/>
<signal name="notify::active" handler="fishbowl_changes_toggled_cb"/>
</object>
</child>
</object>

View File

@ -13,7 +13,7 @@
<property name="can-focus">1</property>
<property name="receives-default">1</property>
<property name="tooltip-text">Reset</property>
<signal name="clicked" handler="reset" swapped="no"/>
<signal name="clicked" handler="font_features_reset_features" swapped="no"/>
<child>
<object class="GtkImage">
<property name="icon-name">view-refresh-symbolic</property>
@ -42,7 +42,7 @@
<property name="receives-default">1</property>
<property name="font">Sans 12</property>
<property name="level">family|style|size|variations|features</property>
<signal name="font-set" handler="font_changed" swapped="no"/>
<signal name="font-set" handler="font_features_font_changed" swapped="no"/>
</object>
</child>
<child>
@ -63,7 +63,7 @@
<object class="GtkComboBox" id="script_lang">
<property name="can-focus">1</property>
<property name="margin-top">10</property>
<signal name="changed" handler="script_changed" swapped="no"/>
<signal name="changed" handler="font_features_script_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
@ -137,7 +137,7 @@
Разъяренный чтец эгоистично бьёт пятью жердями шустрого фехтовальщика. Наш банк вчера же выплатил Ф.Я. Эйхгольду комиссию за ценные вещи. Эх, чужак, общий съём цен шляп (юфть) вдрызг! В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!
Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός</property>
<signal name="activate" handler="stop_edit"/>
<signal name="activate" handler="font_features_stop_edit"/>
<property name="valign">start</property>
<property name="width-chars">50</property>
</object>
@ -181,7 +181,7 @@
<property name="icon-name">document-edit-symbolic</property>
<property name="halign">end</property>
<property name="valign">end</property>
<signal name="toggled" handler="toggle_edit"/>
<signal name="toggled" handler="font_features_toggle_edit"/>
</object>
</child>
</object>

View File

@ -1109,23 +1109,23 @@ done:
g_free (design_coords);
}
static void
font_changed (void)
void
font_features_font_changed (void)
{
update_script_combo ();
update_features ();
update_font_variations ();
}
static void
script_changed (void)
void
font_features_script_changed (void)
{
update_features ();
update_display ();
}
static void
reset_features (void)
void
font_features_reset_features (void)
{
GList *l;
@ -1170,8 +1170,8 @@ switch_to_label (void)
update_display ();
}
static void
toggle_edit (void)
void
font_features_toggle_edit (void)
{
if (strcmp (gtk_stack_get_visible_child_name (GTK_STACK (stack)), "label") == 0)
switch_to_entry ();
@ -1179,8 +1179,8 @@ toggle_edit (void)
switch_to_label ();
}
static void
stop_edit (void)
void
font_features_stop_edit (void)
{
g_signal_emit_by_name (edit_toggle, "clicked");
}
@ -1195,7 +1195,7 @@ entry_key_press (GtkEventController *controller,
if (keyval == GDK_KEY_Escape)
{
gtk_editable_set_text (GTK_EDITABLE (entry), text);
stop_edit ();
font_features_stop_edit ();
return GDK_EVENT_STOP;
}
@ -1213,14 +1213,7 @@ do_font_features (GtkWidget *do_widget)
GtkWidget *feature_list;
GtkEventController *controller;
builder = gtk_builder_new ();
gtk_builder_add_callback_symbol (builder, "update_display", update_display);
gtk_builder_add_callback_symbol (builder, "font_changed", font_changed);
gtk_builder_add_callback_symbol (builder, "script_changed", script_changed);
gtk_builder_add_callback_symbol (builder, "reset", reset_features);
gtk_builder_add_callback_symbol (builder, "stop_edit", G_CALLBACK (stop_edit));
gtk_builder_add_callback_symbol (builder, "toggle_edit", G_CALLBACK (toggle_edit));
gtk_builder_add_from_resource (builder, "/font_features/font-features.ui", NULL);
builder = gtk_builder_new_from_resource ("/font_features/font-features.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
feature_list = GTK_WIDGET (gtk_builder_get_object (builder, "feature_list"));
@ -1338,7 +1331,7 @@ do_font_features (GtkWidget *do_widget)
else
g_hash_table_remove_all (axes);
font_changed ();
font_features_font_changed ();
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);

View File

@ -169,9 +169,9 @@ set_widget_type (int type)
tick_cb = gtk_widget_add_tick_callback (window, scroll_cb, NULL, NULL);
}
static void
next_clicked_cb (GtkButton *source,
gpointer user_data)
void
iconscroll_next_clicked_cb (GtkButton *source,
gpointer user_data)
{
int new_index;
@ -184,9 +184,9 @@ next_clicked_cb (GtkButton *source,
set_widget_type (new_index);
}
static void
prev_clicked_cb (GtkButton *source,
gpointer user_data)
void
iconscroll_prev_clicked_cb (GtkButton *source,
gpointer user_data)
{
int new_index;
@ -205,12 +205,7 @@ do_iconscroll (GtkWidget *do_widget)
{
GtkBuilder *builder;
builder = gtk_builder_new ();
gtk_builder_add_callback_symbols (builder,
"next_clicked_cb", G_CALLBACK (next_clicked_cb),
"prev_clicked_cb", G_CALLBACK (prev_clicked_cb),
NULL);
gtk_builder_add_from_resource (builder, "/iconscroll/iconscroll.ui", NULL);
builder = gtk_builder_new_from_resource ("/iconscroll/iconscroll.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);

View File

@ -15,13 +15,13 @@
<child>
<object class="GtkButton">
<property name="icon-name">pan-start-symbolic</property>
<signal name="clicked" handler="prev_clicked_cb"/>
<signal name="clicked" handler="iconscroll_prev_clicked_cb"/>
</object>
</child>
<child>
<object class="GtkButton">
<property name="icon-name">pan-end-symbolic</property>
<signal name="clicked" handler="next_clicked_cb"/>
<signal name="clicked" handler="iconscroll_next_clicked_cb"/>
</object>
</child>
</object>

View File

@ -1037,7 +1037,6 @@ activate (GApplication *app)
GtkWidget *widget;
GtkTreeModel *model;
GtkTreeIter iter;
GError *error = NULL;
GtkWidget *sw;
GtkWidget *scrollbar;
GtkWidget *menu;
@ -1047,13 +1046,7 @@ activate (GApplication *app)
{ "run", activate_run, NULL, NULL, NULL }
};
builder = gtk_builder_new ();
gtk_builder_add_from_resource (builder, "/ui/main.ui", &error);
if (error != NULL)
{
g_critical ("%s", error->message);
exit (1);
}
builder = gtk_builder_new_from_resource ("/ui/main.ui");
window = (GtkWindow *)gtk_builder_get_object (builder, "window");
gtk_application_add_window (GTK_APPLICATION (app), window);

View File

@ -14,8 +14,8 @@
#include <gtk/gtk.h>
static void
tool_clicked (GtkButton *button)
void
modelbutton_tool_clicked (GtkButton *button)
{
gboolean active;
@ -39,9 +39,7 @@ do_modelbutton (GtkWidget *do_widget)
GtkBuilder *builder;
GActionGroup *actions;
builder = gtk_builder_new ();
gtk_builder_add_callback_symbol (builder, "tool_clicked", G_CALLBACK (tool_clicked));
gtk_builder_add_from_resource (builder, "/modelbutton/modelbutton.ui", NULL);
builder = gtk_builder_new_from_resource ("/modelbutton/modelbutton.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));

View File

@ -101,21 +101,21 @@
<object class="GtkModelButton">
<property name="text">Hammer</property>
<property name="role">check</property>
<signal name="clicked" handler="tool_clicked"/>
<signal name="clicked" handler="modelbutton_tool_clicked"/>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="text">Screwdriver</property>
<property name="role">check</property>
<signal name="clicked" handler="tool_clicked"/>
<signal name="clicked" handler="modelbutton_tool_clicked"/>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="text">Drill</property>
<property name="role">check</property>
<signal name="clicked" handler="tool_clicked"/>
<signal name="clicked" handler="modelbutton_tool_clicked"/>
</object>
</child>
</object>

View File

@ -25,44 +25,44 @@ show_shortcuts (GtkWidget *window,
g_object_unref (builder);
}
static void
builder_shortcuts (GtkWidget *window)
void
shortcuts_builder_shortcuts (GtkWidget *window)
{
show_shortcuts (window, "shortcuts-builder", NULL);
}
static void
gedit_shortcuts (GtkWidget *window)
void
shortcuts_gedit_shortcuts (GtkWidget *window)
{
show_shortcuts (window, "shortcuts-gedit", NULL);
}
static void
clocks_shortcuts (GtkWidget *window)
void
shortcuts_clocks_shortcuts (GtkWidget *window)
{
show_shortcuts (window, "shortcuts-clocks", NULL);
}
static void
clocks_shortcuts_stopwatch (GtkWidget *window)
void
shortcuts_clocks_shortcuts_stopwatch (GtkWidget *window)
{
show_shortcuts (window, "shortcuts-clocks", "stopwatch");
}
static void
boxes_shortcuts (GtkWidget *window)
void
shortcuts_boxes_shortcuts (GtkWidget *window)
{
show_shortcuts (window, "shortcuts-boxes", NULL);
}
static void
boxes_shortcuts_wizard (GtkWidget *window)
void
shortcuts_boxes_shortcuts_wizard (GtkWidget *window)
{
show_shortcuts (window, "shortcuts-boxes", "wizard");
}
static void
boxes_shortcuts_display (GtkWidget *window)
void
shortcuts_boxes_shortcuts_display (GtkWidget *window)
{
show_shortcuts (window, "shortcuts-boxes", "display");
}
@ -85,17 +85,7 @@ do_shortcuts (GtkWidget *do_widget)
{
GtkBuilder *builder;
builder = gtk_builder_new ();
gtk_builder_add_callback_symbols (builder,
"builder_shortcuts", G_CALLBACK (builder_shortcuts),
"gedit_shortcuts", G_CALLBACK (gedit_shortcuts),
"clocks_shortcuts", G_CALLBACK (clocks_shortcuts),
"clocks_shortcuts_stopwatch", G_CALLBACK (clocks_shortcuts_stopwatch),
"boxes_shortcuts", G_CALLBACK (boxes_shortcuts),
"boxes_shortcuts_wizard", G_CALLBACK (boxes_shortcuts_wizard),
"boxes_shortcuts_display", G_CALLBACK (boxes_shortcuts_display),
NULL);
gtk_builder_add_from_resource (builder, "/shortcuts/shortcuts.ui", NULL);
builder = gtk_builder_new_from_resource ("/shortcuts/shortcuts.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));

View File

@ -10,43 +10,43 @@
<child>
<object class="GtkButton">
<property name="label">Builder</property>
<signal name="clicked" handler="builder_shortcuts" swapped="1" object="window1"/>
<signal name="clicked" handler="shortcuts_builder_shortcuts" swapped="1" object="window1"/>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label">GEdit</property>
<signal name="clicked" handler="gedit_shortcuts" swapped="1" object="window1"/>
<signal name="clicked" handler="shortcuts_gedit_shortcuts" swapped="1" object="window1"/>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label">Clocks - All</property>
<signal name="clicked" handler="clocks_shortcuts" swapped="1" object="window1"/>
<signal name="clicked" handler="shortcuts_clocks_shortcuts" swapped="1" object="window1"/>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label">Clocks - Stopwatch</property>
<signal name="clicked" handler="clocks_shortcuts_stopwatch" swapped="1" object="window1"/>
<signal name="clicked" handler="shortcuts_clocks_shortcuts_stopwatch" swapped="1" object="window1"/>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label">Boxes</property>
<signal name="clicked" handler="boxes_shortcuts" swapped="1" object="window1"/>
<signal name="clicked" handler="shortcuts_boxes_shortcuts" swapped="1" object="window1"/>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label">Boxes - Wizard</property>
<signal name="clicked" handler="boxes_shortcuts_wizard" swapped="1" object="window1"/>
<signal name="clicked" handler="shortcuts_boxes_shortcuts_wizard" swapped="1" object="window1"/>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label">Boxes - Display</property>
<signal name="clicked" handler="boxes_shortcuts_display" swapped="1" object="window1"/>
<signal name="clicked" handler="shortcuts_boxes_shortcuts_display" swapped="1" object="window1"/>
</object>
</child>
</object>

View File

@ -11,9 +11,9 @@
#include <math.h>
#include <stdlib.h>
static gint
hex_spin_input (GtkSpinButton *spin_button,
gdouble *new_val)
gint
spinbutton_hex_spin_input (GtkSpinButton *spin_button,
gdouble *new_val)
{
const gchar *buf;
gchar *err;
@ -28,8 +28,8 @@ hex_spin_input (GtkSpinButton *spin_button,
return TRUE;
}
static gint
hex_spin_output (GtkSpinButton *spin_button)
gint
spinbutton_hex_spin_output (GtkSpinButton *spin_button)
{
GtkAdjustment *adjustment;
gchar *buf;
@ -48,9 +48,9 @@ hex_spin_output (GtkSpinButton *spin_button)
return TRUE;
}
static gint
time_spin_input (GtkSpinButton *spin_button,
gdouble *new_val)
gint
spinbutton_time_spin_input (GtkSpinButton *spin_button,
gdouble *new_val)
{
const gchar *text;
gchar **str;
@ -87,8 +87,8 @@ time_spin_input (GtkSpinButton *spin_button,
return TRUE;
}
static gint
time_spin_output (GtkSpinButton *spin_button)
gint
spinbutton_time_spin_output (GtkSpinButton *spin_button)
{
GtkAdjustment *adjustment;
gchar *buf;
@ -121,9 +121,9 @@ static gchar *month[12] = {
"December"
};
static gint
month_spin_input (GtkSpinButton *spin_button,
gdouble *new_val)
gint
spinbutton_month_spin_input (GtkSpinButton *spin_button,
gdouble *new_val)
{
gint i;
gchar *tmp1, *tmp2;
@ -150,8 +150,8 @@ month_spin_input (GtkSpinButton *spin_button,
return TRUE;
}
static gint
month_spin_output (GtkSpinButton *spin_button)
gint
spinbutton_month_spin_output (GtkSpinButton *spin_button)
{
GtkAdjustment *adjustment;
gdouble value;
@ -190,16 +190,7 @@ do_spinbutton (GtkWidget *do_widget)
GtkAdjustment *adj;
GtkWidget *label;
builder = gtk_builder_new ();
gtk_builder_add_callback_symbols (builder,
"hex_spin_input", G_CALLBACK (hex_spin_input),
"hex_spin_output", G_CALLBACK (hex_spin_output),
"time_spin_input", G_CALLBACK (time_spin_input),
"time_spin_output", G_CALLBACK (time_spin_output),
"month_spin_input", G_CALLBACK (month_spin_input),
"month_spin_output", G_CALLBACK (month_spin_output),
NULL);
gtk_builder_add_from_resource (builder, "/spinbutton/spinbutton.ui", NULL);
builder = gtk_builder_new_from_resource ("/spinbutton/spinbutton.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));

View File

@ -83,8 +83,8 @@
<property name="halign">start</property>
<property name="width-chars">4</property>
<property name="adjustment">hex_adjustment</property>
<signal name="input" handler="hex_spin_input"/>
<signal name="output" handler="hex_spin_output"/>
<signal name="input" handler="spinbutton_hex_spin_input"/>
<signal name="output" handler="spinbutton_hex_spin_output"/>
<property name="wrap">1</property>
<layout>
<property name="left-attach">1</property>
@ -119,8 +119,8 @@
<property name="halign">start</property>
<property name="width-chars">5</property>
<property name="adjustment">time_adjustment</property>
<signal name="input" handler="time_spin_input"/>
<signal name="output" handler="time_spin_output"/>
<signal name="input" handler="spinbutton_time_spin_input"/>
<signal name="output" handler="spinbutton_time_spin_output"/>
<property name="wrap">1</property>
<layout>
<property name="left-attach">1</property>
@ -154,8 +154,8 @@
<object class="GtkSpinButton" id="month_spin">
<property name="halign">start</property>
<property name="width-chars">9</property>
<signal name="input" handler="month_spin_input"/>
<signal name="output" handler="month_spin_output"/>
<signal name="input" handler="spinbutton_month_spin_input"/>
<signal name="output" handler="spinbutton_month_spin_output"/>
<property name="adjustment">month_adjustment</property>
<property name="wrap">1</property>
<property name="update-policy">if-valid</property>

View File

@ -4,14 +4,14 @@
static GtkWidget *header_stack;
static GtkWidget *page_stack;
static void
void
back_to_main (GtkButton *button)
{
gtk_stack_set_visible_child_name (GTK_STACK (header_stack), "main");
gtk_stack_set_visible_child_name (GTK_STACK (page_stack), "page1");
}
static void
void
go_to_secondary (GtkButton *button)
{
gtk_stack_set_visible_child_name (GTK_STACK (header_stack), "secondary");
@ -31,8 +31,6 @@ main (int argc, char *argv[])
gtk_init ();
builder = gtk_builder_new ();
gtk_builder_add_callback_symbol (builder, "back_to_main", G_CALLBACK (back_to_main));
gtk_builder_add_callback_symbol (builder, "go_to_secondary", G_CALLBACK (go_to_secondary));
gtk_builder_add_from_file (builder, "teststackedheaders.ui", NULL);
win = (GtkWidget *)gtk_builder_get_object (builder, "window");