diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-05-24 00:38:38 +0000 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-05-24 00:38:38 +0000 |
commit | 2bc36653227b86852e78a6d9bdec2ebb57c82bcb (patch) | |
tree | 90246837e864c5588ce351f5b18ad1814d9c19ec | |
parent | 4338f4a45e1478d21e20288a9333f61162a48b12 (diff) | |
download | mdk-2bc36653227b86852e78a6d9bdec2ebb57c82bcb.tar.gz mdk-2bc36653227b86852e78a6d9bdec2ebb57c82bcb.tar.bz2 |
deferred dialog creation
-rw-r--r-- | mixgtk/mixgtk.c | 26 | ||||
-rw-r--r-- | mixgtk/mixgtk.glade | 1 | ||||
-rw-r--r-- | mixgtk/mixgtk.h | 3 | ||||
-rw-r--r-- | mixgtk/mixgtk_colorsel.c | 32 | ||||
-rw-r--r-- | mixgtk/mixgtk_colorsel.h | 4 | ||||
-rw-r--r-- | mixgtk/mixgtk_fontsel.c | 25 | ||||
-rw-r--r-- | mixgtk/mixgtk_fontsel.h | 6 | ||||
-rw-r--r-- | mixgtk/mixgtk_input.c | 19 | ||||
-rw-r--r-- | mixgtk/mixgtk_input.h | 4 | ||||
-rw-r--r-- | mixgtk/mixgtk_mixvm.c | 24 | ||||
-rw-r--r-- | mixgtk/mixgtk_widgets.c | 84 | ||||
-rw-r--r-- | mixgtk/mixgtk_widgets.h | 24 |
12 files changed, 144 insertions, 108 deletions
diff --git a/mixgtk/mixgtk.c b/mixgtk/mixgtk.c index fb2d38a..ff218f6 100644 --- a/mixgtk/mixgtk.c +++ b/mixgtk/mixgtk.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk.c : * Main functions of the mix gtk front-end * ------------------------------------------------------------------ - * Last change: Time-stamp: "2001-05-04 01:33:02 jao" + * Last change: Time-stamp: "2001-05-20 18:03:05 jao" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -95,21 +95,21 @@ mixgtk_init (int argc, char *argv[]) return FALSE; } - if (!mixgtk_input_init ()) - { - g_error ("Unable to initialise application (word input widgets)\n"); - return FALSE; - } - - if (!mixgtk_fontsel_init () || !mixgtk_colorsel_init ()) - { - g_error ("Unable to initialise application (customization widgets)\n"); - return FALSE; - } - + mixgtk_fontsel_load_defaults (); + return TRUE; } +/* main loop */ +void +mixgtk_main (void) +{ + gtk_widget_show (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN)); + mixgtk_mixvm_update_vm_widgets (); + + gtk_main (); +} + /* clean up */ void mixgtk_release (void) diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index 174166d..5dde85d 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -18,6 +18,7 @@ <widget> <class>GtkWindow</class> <name>main_window</name> + <visible>False</visible> <signal> <name>destroy</name> <handler>on_main_window_destroy</handler> diff --git a/mixgtk/mixgtk.h b/mixgtk/mixgtk.h index c77433f..403847c 100644 --- a/mixgtk/mixgtk.h +++ b/mixgtk/mixgtk.h @@ -36,7 +36,8 @@ extern gboolean mixgtk_init (int argc, char *argv[]); /* enter the main mixgtk loop */ -#define mixgtk_main gtk_main +extern void +mixgtk_main (void); /* clean up */ extern void diff --git a/mixgtk/mixgtk_colorsel.c b/mixgtk/mixgtk_colorsel.c index c1f5a3d..b40f6d2 100644 --- a/mixgtk/mixgtk_colorsel.c +++ b/mixgtk/mixgtk_colorsel.c @@ -49,10 +49,7 @@ typedef struct static area_id_t areas_[LNO_][ZNO_]; static area_id_t *current_ = NULL; -#define COLORSEL_DLG_NAME_ "colorsel_dialog" static GtkWidget *colorseldlg_ = NULL; - - static void set_area_color_ (GtkWidget *area, const GdkColor *color) { @@ -78,39 +75,39 @@ set_area_color_ (GtkWidget *area, const GdkColor *color) static gint area_event_(GtkWidget *widget, GdkEvent *event, gpointer areaid) { - gint handled = FALSE; /* Check if we've received a button pressed event */ if (event->type == GDK_BUTTON_PRESS) { -/* handled = TRUE; */ current_ = (area_id_t *)areaid; /* Show the dialog */ gtk_widget_show (colorseldlg_); } - return handled; + return FALSE; } /* initialise the color selection dialog */ -gboolean -mixgtk_colorsel_init (void) +static void +init_colorsel_ (void) { int i, j; - color_dialog_ = mixgtk_widget_factory_get (MIXGTK_WIDGET_COLORSEL_DIALOG); - g_return_val_if_fail (color_dialog_ != NULL, FALSE); - colorseldlg_ = mixgtk_widget_factory_get_by_name (COLORSEL_DLG_NAME_); - g_return_val_if_fail (colorseldlg_ != NULL, FALSE); + color_dialog_ = mixgtk_widget_factory_get_dialog (MIXGTK_COLOR_DIALOG); + g_assert (color_dialog_ != NULL); + colorseldlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_COLORSEL_DIALOG); + g_assert (colorseldlg_ != NULL); for (i = 0; i < LNO_; ++i) for (j = 0; j < ZNO_; ++j) { - areas_[i][j].area = mixgtk_widget_factory_get_by_name (anames_[i][j]); - g_return_val_if_fail (areas_[i][j].area != NULL, FALSE); + areas_[i][j].area = + mixgtk_widget_factory_get_child_by_name + (MIXGTK_COLOR_DIALOG, anames_[i][j]); + g_assert (areas_[i][j].area != NULL); areas_[i][j].changed = FALSE; gtk_widget_set_events (areas_[i][j].area, GDK_BUTTON_PRESS_MASK); - gtk_signal_connect (GTK_OBJECT(areas_[i][j].area), "event", - (GtkSignalFunc)area_event_, (gpointer)&areas_[i][j]); + gtk_signal_connect (GTK_OBJECT(areas_[i][j].area), "event", + (GtkSignalFunc)area_event_, + (gpointer)&areas_[i][j]); } - return TRUE; } /* gtk callbacks */ @@ -120,6 +117,7 @@ on_colors_activate (GtkWidget *w, gpointer p) int i, j; /* must show widget before changing its colors */ + if (!color_dialog_) init_colorsel_ (); gtk_widget_show (color_dialog_); for (i = 0; i < LNO_; ++i) diff --git a/mixgtk/mixgtk_colorsel.h b/mixgtk/mixgtk_colorsel.h index aa50724..99253a7 100644 --- a/mixgtk/mixgtk_colorsel.h +++ b/mixgtk/mixgtk_colorsel.h @@ -27,10 +27,6 @@ #include <gtk/gtk.h> -/* initialise the color selection dialog */ -extern gboolean -mixgtk_colorsel_init (void); - /* gtk callbacks */ extern void on_colors_activate (GtkWidget *w, gpointer p); diff --git a/mixgtk/mixgtk_fontsel.c b/mixgtk/mixgtk_fontsel.c index b3233b2..16b6ba1 100644 --- a/mixgtk/mixgtk_fontsel.c +++ b/mixgtk/mixgtk_fontsel.c @@ -55,14 +55,22 @@ static const gchar *keys_[] = { static winfo infos_[WIDGET_NO_]; +/* initialise the font selection dialog */ +static void +init_fontsel_ (void) +{ + fontsel_dialog_ = mixgtk_widget_factory_get_dialog (MIXGTK_FONTSEL_DIALOG); + g_assert (fontsel_dialog_ != NULL); +} + void change_font_ (mixgtk_widget_id_t widget) { - winfo *info = (winfo *) g_hash_table_lookup (winfo_, - GINT_TO_POINTER (widget)); + winfo *info; + if (!fontsel_dialog_) init_fontsel_ (); + info = (winfo *) g_hash_table_lookup (winfo_, GINT_TO_POINTER (widget)); g_assert (info); widget_ = widget; - if (info->font) gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (fontsel_dialog_), info->font); @@ -71,19 +79,15 @@ change_font_ (mixgtk_widget_id_t widget) } - -/* initialise the font selection dialog */ -gboolean -mixgtk_fontsel_init (void) +void +mixgtk_fontsel_load_defaults (void) { int i; - fontsel_dialog_ = mixgtk_widget_factory_get (MIXGTK_WIDGET_FONTSEL_DIALOG); - g_return_val_if_fail (fontsel_dialog_ != NULL, FALSE); winfo_ = g_hash_table_new (NULL, NULL); for (i = 0; i < WIDGET_NO_; ++i) { infos_[i].widget = mixgtk_widget_factory_get (widget_ids_[i]); - g_return_val_if_fail (infos_[i].widget != NULL, FALSE); + g_assert (infos_[i].widget != NULL); infos_[i].style = gtk_style_copy (gtk_widget_get_style (infos_[i].widget)); gtk_widget_set_style (infos_[i].widget, infos_[i].style); @@ -103,7 +107,6 @@ mixgtk_fontsel_init (void) mixgtk_fontsel_set (widget_ids_[i], infos_[i].font); } } - return TRUE; } void diff --git a/mixgtk/mixgtk_fontsel.h b/mixgtk/mixgtk_fontsel.h index 5b9b1f6..af09c15 100644 --- a/mixgtk/mixgtk_fontsel.h +++ b/mixgtk/mixgtk_fontsel.h @@ -28,9 +28,9 @@ #include <glib.h> #include "mixgtk_widgets.h" -/* initialise the font selection dialog */ -extern gboolean -mixgtk_fontsel_init (void); +/* load default (configured) fonts */ +extern void +mixgtk_fontsel_load_defaults (void); /* set a widget's font */ extern void diff --git a/mixgtk/mixgtk_input.c b/mixgtk/mixgtk_input.c index 8726bab..95c697a 100644 --- a/mixgtk/mixgtk_input.c +++ b/mixgtk/mixgtk_input.c @@ -37,26 +37,24 @@ static const gchar *WGT_NAMES_[SIZE_] = { "word_b4", "word_b5", "word_decimal", "word_reset", "word_ok" }; -static GtkDialog *dialog_; +static GtkDialog *dialog_ = NULL; static GtkWidget *childs_[SIZE_]; static input_callback_t callback_; static gpointer data_; -/* init */ -extern gboolean -mixgtk_input_init (void) +static void +init_dialog_ (void) { gint k; - dialog_ = GTK_DIALOG (mixgtk_widget_factory_get (MIXGTK_WIDGET_WORD_DIALOG)); - g_return_val_if_fail (dialog_ != NULL, FALSE); + dialog_ = GTK_DIALOG (mixgtk_widget_factory_get_dialog (MIXGTK_WORD_DIALOG)); + g_assert (dialog_ != NULL); for (k = 0; k < SIZE_; ++k) { - childs_[k] = mixgtk_widget_factory_get_by_name (WGT_NAMES_[k]); - g_return_val_if_fail (childs_[k] != NULL, FALSE); + childs_[k] = mixgtk_widget_factory_get_child_by_name + (MIXGTK_WORD_DIALOG, WGT_NAMES_[k]); + g_assert (childs_[k] != NULL); } - return TRUE; - } static void @@ -84,6 +82,7 @@ void mixgtk_input_word (const gchar *message, mix_word_t def, input_callback_t cb, gpointer data) { + if (!dialog_) init_dialog_ (); gtk_label_set_text (GTK_LABEL (childs_[MSG_]), message); set_word_ (def); callback_ = cb; diff --git a/mixgtk/mixgtk_input.h b/mixgtk/mixgtk_input.h index 275894d..61ea2a5 100644 --- a/mixgtk/mixgtk_input.h +++ b/mixgtk/mixgtk_input.h @@ -30,10 +30,6 @@ /* callback function type */ typedef void (*input_callback_t)(mix_word_t result, gpointer data); -/* init */ -extern gboolean -mixgtk_input_init (void); - /* get a word */ extern void mixgtk_input_word (const gchar *message, mix_word_t def, diff --git a/mixgtk/mixgtk_mixvm.c b/mixgtk/mixgtk_mixvm.c index b3a52c1..bee588a 100644 --- a/mixgtk/mixgtk_mixvm.c +++ b/mixgtk/mixgtk_mixvm.c @@ -34,8 +34,8 @@ static GtkEntry *reg_entries_[REGISTER_NO_]; static GtkTooltips *tips_; static GtkEntry *loc_entry_; -static GtkWidget *goto_; -static GtkEntry *goto_entry_; +static GtkWidget *goto_ = NULL; +static GtkEntry *goto_entry_ = NULL; static GtkToggleButton *over_button_; static GtkToggleButton *cmp_buttons_[3]; static GtkCList *memory_; @@ -47,6 +47,16 @@ static mix_vm_t *vm_; #define GOTO_ENTRY_NAME_ "goto_entry" static void +init_goto_ (void) +{ + goto_ = mixgtk_widget_factory_get_dialog (MIXGTK_GOTO_DIALOG); + g_assert (goto_ != NULL); + goto_entry_ = GTK_ENTRY (mixgtk_widget_factory_get_child_by_name ( + MIXGTK_GOTO_DIALOG, GOTO_ENTRY_NAME_)); + g_assert (goto_entry_ != NULL); +} + +static void update_register_ (mixgtk_widget_id_t reg) { static gchar BUFFER[20]; @@ -161,15 +171,6 @@ mixgtk_mixvm_init (mix_vm_t *vm) gtk_signal_connect (GTK_OBJECT (adj), "value_changed", GTK_SIGNAL_FUNC (on_mem_adj_change_), NULL); - goto_ = mixgtk_widget_factory_get (MIXGTK_WIDGET_GOTO_DIALOG); - g_return_val_if_fail (goto_ != NULL, FALSE); - - goto_entry_ = GTK_ENTRY (mixgtk_widget_factory_get_by_name - (GOTO_ENTRY_NAME_)); - g_return_val_if_fail (goto_entry_ != NULL, FALSE); - - mixgtk_mixvm_update_vm_widgets (); - return TRUE; } @@ -400,6 +401,7 @@ on_memory_cells_select_row (GtkCList *w, gint row, gint col, void on_memory_cells_click_column (GtkCList *w, gint row, gpointer data) { + if (!goto_) init_goto_ (); gtk_widget_show (goto_); } diff --git a/mixgtk/mixgtk_widgets.c b/mixgtk/mixgtk_widgets.c index 61f973f..18d60e1 100644 --- a/mixgtk/mixgtk_widgets.c +++ b/mixgtk/mixgtk_widgets.c @@ -28,18 +28,22 @@ #include "mixgtk_config.h" #include "mixgtk_widgets.h" -/* the glade spec */ -static GladeXML *xml_ = NULL; - -/* widget names */ -static const gchar *names_[] = { +/* dialog names */ +static const gchar * dnames_[] = { "main_window", - "main_statusbar", "word_dialog", "about_dialog", "goto_dialog", "color_dialog", + "colorsel_dialog", "fontsel_dialog", +}; + +#define DLG_NO_ (sizeof (dnames_) / sizeof(dnames_[0])) + +/* widget names */ +static const gchar *names_[] = { + "main_statusbar", "mixvm_widget", "command_prompt", "command_log", @@ -73,39 +77,54 @@ static const gchar *names_[] = { #define GPL_TEXT_ "gpl_text" #define AUTOSAVE_ITEM_ "save_on_exit" -GtkWidget *about_; +/* the glade specs */ +static GladeXML *xml_[DLG_NO_] = {NULL}; +/* the about dialog */ +static GtkWidget *about_ = NULL; + +/* the xml file name */ +static const gchar *file_ = NULL; + +static void init_xml_ (mixgtk_dialog_id_t dlg) +{ + xml_[dlg] = glade_xml_new (file_, dnames_[dlg]); + glade_xml_signal_autoconnect (xml_[dlg]); + g_assert (xml_[dlg] != NULL); +} static void init_autosave_ (void) { GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM - (mixgtk_widget_factory_get_by_name (AUTOSAVE_ITEM_)); + (mixgtk_widget_factory_get_child_by_name + (MIXGTK_MAIN, AUTOSAVE_ITEM_)); if (item) { gtk_check_menu_item_set_active (item, mixgtk_config_is_autosave ()); } } +static void +init_about_ (void) +{ + GtkWidget *label; + about_ = mixgtk_widget_factory_get_dialog (MIXGTK_ABOUT_DIALOG); + g_assert (about_ != NULL); + label = mixgtk_widget_factory_get_child_by_name (MIXGTK_ABOUT_DIALOG, + VERSION_LABEL_); + g_assert (label != NULL); + gtk_label_set_text (GTK_LABEL(label), VERSION); + gtk_widget_show (label); +} + /* create a new factory from an xml glade file */ gboolean mixgtk_widget_factory_init (const char *glade_file) { - GtkWidget *label; - glade_init (); - xml_ = glade_xml_new (glade_file, NULL); - if (!xml_) return FALSE; - glade_xml_signal_autoconnect (xml_); - - about_ = mixgtk_widget_factory_get (MIXGTK_WIDGET_ABOUT_DIALOG); - g_return_val_if_fail (about_ != NULL, FALSE); - label = mixgtk_widget_factory_get_by_name (VERSION_LABEL_); - g_return_val_if_fail (label != NULL, FALSE); - gtk_label_set_text (GTK_LABEL(label), VERSION); - gtk_widget_show (label); - + file_ = g_strdup (glade_file); + init_xml_ (MIXGTK_MAIN); init_autosave_ (); - return TRUE; } @@ -114,19 +133,32 @@ GtkWidget * mixgtk_widget_factory_get (mixgtk_widget_id_t widget) { g_return_val_if_fail (widget < WIDGET_NO_, NULL); - return glade_xml_get_widget (xml_, names_[widget]); + return glade_xml_get_widget (xml_[MIXGTK_MAIN], names_[widget]); } -/* Get a widget by name */ + GtkWidget * -mixgtk_widget_factory_get_by_name (const gchar *name) +mixgtk_widget_factory_get_dialog (mixgtk_dialog_id_t dlg) { - return glade_xml_get_widget (xml_, name); + if (!xml_[dlg]) init_xml_ (dlg); + return glade_xml_get_widget (xml_[dlg], dnames_[dlg]); } +GtkWidget * +mixgtk_widget_factory_get_child_by_name (mixgtk_dialog_id_t dlg, + const gchar *name) +{ + g_return_val_if_fail (dlg < DLG_NO_, NULL); + g_return_val_if_fail (name != NULL, NULL); + if (!xml_[dlg]) init_xml_ (dlg); + return glade_xml_get_widget (xml_[dlg], name); +} + + /* about box */ void on_about_activate (GtkWidget *w, gpointer data) { + if (!about_) init_about_ (); gtk_widget_show (about_); } diff --git a/mixgtk/mixgtk_widgets.h b/mixgtk/mixgtk_widgets.h index 461e1bf..8054ed4 100644 --- a/mixgtk/mixgtk_widgets.h +++ b/mixgtk/mixgtk_widgets.h @@ -28,15 +28,20 @@ #include <gtk/gtk.h> #include <mixlib/mix_vm.h> +/* enumeration of gmixvm dialogs */ +typedef enum { + MIXGTK_MAIN, /* main app window */ + MIXGTK_WORD_DIALOG, /* input dialog for a mix word */ + MIXGTK_ABOUT_DIALOG, + MIXGTK_GOTO_DIALOG, + MIXGTK_COLOR_DIALOG, /* color customization dialog */ + MIXGTK_COLORSEL_DIALOG, /* color selection dialog */ + MIXGTK_FONTSEL_DIALOG, /* font selection dialog */ +} mixgtk_dialog_id_t; + /* enumeration of mixvm widget ids */ typedef enum { - MIXGTK_WIDGET_MAIN, /* main app window */ MIXGTK_WIDGET_STATUSBAR, - MIXGTK_WIDGET_WORD_DIALOG, /* input dialog for a mix word */ - MIXGTK_WIDGET_ABOUT_DIALOG, - MIXGTK_WIDGET_GOTO_DIALOG, - MIXGTK_WIDGET_COLORSEL_DIALOG, /* color customization dialog */ - MIXGTK_WIDGET_FONTSEL_DIALOG, /* font selection dialog */ MIXGTK_WIDGET_MIXVM, /* virtual machine */ MIXGTK_WIDGET_PROMPT, /* command prompt */ MIXGTK_WIDGET_LOG, /* command output */ @@ -69,6 +74,9 @@ typedef enum { extern gboolean mixgtk_widget_factory_init (const char *glade_file); +/* get a dialog */ +extern GtkWidget * +mixgtk_widget_factory_get_dialog (mixgtk_dialog_id_t dlg); /* get a widget */ extern GtkWidget * @@ -76,8 +84,8 @@ mixgtk_widget_factory_get (mixgtk_widget_id_t widget); /* Get a widget by name */ extern GtkWidget * -mixgtk_widget_factory_get_by_name (const gchar *name); - +mixgtk_widget_factory_get_child_by_name (mixgtk_dialog_id_t dlg, + const gchar *name); #endif /* MIXGTK_WIDGETS_H */ |