From 3ecd31d9fd1866ed712cd66a5046e7417356bac9 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 13 Jul 2007 15:54:16 +0000 Subject: [PATCH] Add ui_table_add_row() for easily adding widgets to a GtkTable, and use it in project_new(). Group 'generic' functions related to GTK+ together at the top of ui_utils.h. Make sure G_GNUC_NULL_TERMINATED is defined in geany.h. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1702 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 7 +++++++ src/geany.h | 5 +++++ src/project.c | 24 ++++++------------------ src/ui_utils.c | 23 +++++++++++++++++++++++ src/ui_utils.h | 47 +++++++++++++++++++++++++++-------------------- src/utils.h | 4 ---- 6 files changed, 68 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3465309..f0c12003 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,13 @@ remove some unnecessary border width. Add ui->dialog_vbox_new() and ui->frame_new_with_alignment() functions to the plugin API. + * src/ui_utils.h, src/utils.h, src/project.c, src/geany.h, + src/ui_utils.c: + Add ui_table_add_row() for easily adding widgets to a GtkTable, and + use it in project_new(). + Group 'generic' functions related to GTK+ together at the top of + ui_utils.h. + Make sure G_GNUC_NULL_TERMINATED is defined in geany.h. 2007-07-12 Enrico Tröger diff --git a/src/geany.h b/src/geany.h index 4587769a..12240c5a 100644 --- a/src/geany.h +++ b/src/geany.h @@ -210,6 +210,11 @@ enum }; +/* Useful for some variable argument list functions, e.g. in utils.h */ +#if ! GLIB_CHECK_VERSION(2, 8, 0) +#define G_GNUC_NULL_TERMINATED +#endif + // implementation in main.c; prototype is here so that all files can use it. void geany_debug(gchar const *format, ...) G_GNUC_PRINTF (1, 2); diff --git a/src/project.c b/src/project.c index 757d0d40..c97abaa7 100644 --- a/src/project.c +++ b/src/project.c @@ -124,21 +124,14 @@ void project_new() gtk_table_set_col_spacings(GTK_TABLE(table), 10); label = gtk_label_new(_("Name:")); - gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment(GTK_MISC(label), 1, 0); e->name = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN); - gtk_table_attach(GTK_TABLE(table), e->name, 1, 2, 0, 1, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); + + ui_table_add_row(GTK_TABLE(table), 0, label, e->name, NULL); label = gtk_label_new(_("Filename:")); - gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment(GTK_MISC(label), 1, 0); e->file_name = gtk_entry_new(); @@ -151,14 +144,10 @@ void project_new() bbox = gtk_hbox_new(FALSE, 6); gtk_box_pack_start_defaults(GTK_BOX(bbox), e->file_name); gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); - gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 1, 2, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); + + ui_table_add_row(GTK_TABLE(table), 1, label, bbox, NULL); label = gtk_label_new(_("Base path:")); - gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment(GTK_MISC(label), 1, 0); e->base_path = gtk_entry_new(); @@ -167,9 +156,8 @@ void project_new() "This can be a new path, or an existing directory tree."), NULL); bbox = ui_path_box_new(_("Choose Project Base Path"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path)); - gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 2, 3, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); + + ui_table_add_row(GTK_TABLE(table), 2, label, bbox, NULL); gtk_container_add(GTK_CONTAINER(vbox), table); diff --git a/src/ui_utils.c b/src/ui_utils.c index fc51f175..065b1267 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -1266,3 +1266,26 @@ void ui_statusbar_showhide(gboolean state) else gtk_widget_hide(app->statusbar); } + + +/* Pack all GtkWidgets passed after the row argument into a table, using + * one widget per cell. The first widget is not expanded, as this is usually + * a label. */ +void ui_table_add_row(GtkTable *table, gint row, ...) +{ + va_list args; + gint i; + GtkWidget *widget; + + va_start(args, row); + for (i = 0; (widget = va_arg(args, GtkWidget*), widget != NULL); i++) + { + gint options = (i == 0) ? GTK_FILL : GTK_EXPAND | GTK_FILL; + + gtk_table_attach(GTK_TABLE(table), widget, i, i + 1, row, row + 1, + options, 0, 0, 0); + } + va_end(args); +} + + diff --git a/src/ui_utils.h b/src/ui_utils.h index 0dbbdb73..3309e3ee 100644 --- a/src/ui_utils.h +++ b/src/ui_utils.h @@ -24,6 +24,33 @@ #ifndef GEANY_UI_UTILS_H #define GEANY_UI_UTILS_H 1 +/* The following block of functions are more generic functions and closely related to + * certain GTK+ widgets. */ + +void ui_widget_show_hide(GtkWidget *widget, gboolean show); + +void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str); + +GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment); + +GtkWidget *ui_dialog_vbox_new(GtkDialog *dialog); + +GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text); + +void ui_hbutton_box_copy_layout(GtkButtonBox *master, GtkButtonBox *copy); + +void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text); + +GtkWidget *ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry); + +void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title, + GtkFileChooserAction action, GtkEntry *entry); + +void ui_table_add_row(GtkTable *table, gint row, ...) G_GNUC_NULL_TERMINATED; + +/* End of 'generic' functions */ + + // Display text on the statusbar without logging it to the Status window. void ui_set_statusbar(const gchar *format, ...) G_GNUC_PRINTF (1, 2); @@ -62,8 +89,6 @@ void ui_save_buttons_toggle(gboolean enable); void ui_close_buttons_toggle(); -void ui_widget_show_hide(GtkWidget *widget, gboolean show); - void ui_treeviews_show_hide(gboolean force); void ui_document_show_hide(gint idx); @@ -89,22 +114,6 @@ void ui_show_markers_margin(); void ui_show_linenumber_margin(); -GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment); - -GtkWidget *ui_dialog_vbox_new(GtkDialog *dialog); - -GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text); - -void ui_hbutton_box_copy_layout(GtkButtonBox *master, GtkButtonBox *copy); - -void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text); - -GtkWidget *ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry); - -void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title, - GtkFileChooserAction action, GtkEntry *entry); - - void ui_update_tab_status(gint idx); @@ -113,8 +122,6 @@ typedef gboolean TVMatchCallback(); gboolean ui_tree_view_find_next(GtkTreeView *treeview, TVMatchCallback cb); -void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str); - void ui_statusbar_showhide(gboolean state); #endif diff --git a/src/utils.h b/src/utils.h index 508004b3..56138e7f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -25,10 +25,6 @@ #ifndef GEANY_UTILS_H #define GEANY_UTILS_H 1 -#if ! GLIB_CHECK_VERSION(2, 8, 0) -#define G_GNUC_NULL_TERMINATED -#endif - // Returns: TRUE if ptr points to a non-zero value. #define NZV(ptr) \ ((ptr) && (ptr)[0])