summaryrefslogtreecommitdiffhomepage
path: root/mixgtk/mixgtk_mixal.c
diff options
context:
space:
mode:
Diffstat (limited to 'mixgtk/mixgtk_mixal.c')
-rw-r--r--mixgtk/mixgtk_mixal.c75
1 files changed, 71 insertions, 4 deletions
diff --git a/mixgtk/mixgtk_mixal.c b/mixgtk/mixgtk_mixal.c
index 8cbb015..db2218a 100644
--- a/mixgtk/mixgtk_mixal.c
+++ b/mixgtk/mixgtk_mixal.c
@@ -33,6 +33,10 @@
static mix_vm_t *vm_;
static GtkCList *clist_;
static gulong lineno_;
+static GtkStatusbar *status_;
+static gint status_context_;
+static GPtrArray *tips_text_ = NULL;
+
static GdkColor colors_[3][2];
static GdkColormap *colormap_ = NULL;
static const char* default_colors_[3][2] = {
@@ -86,7 +90,11 @@ mixgtk_mixal_init (mix_vm_t *vm)
vm_ = vm;
clist_ = GTK_CLIST (mixgtk_widget_factory_get (MIXGTK_WIDGET_MIXAL));
g_return_val_if_fail (clist_ != NULL, FALSE);
-
+
+ status_ = GTK_STATUSBAR (mixgtk_widget_factory_get (MIXGTK_WIDGET_STATUSBAR));
+ g_return_val_if_fail (status_ != NULL, FALSE);
+ status_context_ = gtk_statusbar_get_context_id (status_, "MIXAL status");
+
/* allocate colors */
colormap_ = gtk_widget_get_colormap (GTK_WIDGET (clist_));
for (i = 0; i < 3; ++i)
@@ -134,6 +142,42 @@ mixgtk_mixal_get_color (mixal_line_t line, mixal_line_zone_t zone)
}
/* load the corresponding mixal file */
+static void
+update_tips_ (const mix_symbol_table_t *table,
+ const gchar *line)
+{
+ enum {SIZE = 256};
+ static gchar BUFFER[256];
+ static const gchar *DELIMITERS = " /+*=-()\t,:\n";
+ if (line)
+ {
+ guint k = 0;
+ gchar *tip = g_strdup ("");
+ gchar *new_tip;
+ gchar **tokens;
+ gchar *text = g_strdup (line);
+ text = g_strdelimit (text, DELIMITERS, ' ');
+ tokens = g_strsplit (g_strstrip (text), " ", -1);
+ while (tokens[k])
+ {
+ if (mix_symbol_table_is_defined (table, tokens[k]))
+ {
+ mix_word_t val = mix_symbol_table_value (table, tokens[k]);
+ snprintf (BUFFER, SIZE, "[ %s = %s%ld ]", tokens[k],
+ mix_word_is_negative (val)? "-" : "+",
+ mix_word_magnitude (val));
+ new_tip = g_strconcat (tip, " ", BUFFER, NULL);
+ g_free (tip);
+ tip = new_tip;
+ }
+ ++k;
+ }
+ g_ptr_array_add (tips_text_, (gpointer)tip);
+ g_strfreev (tokens);
+ g_free (text);
+ }
+}
+
void
mixgtk_mixal_load_file (void)
{
@@ -148,19 +192,21 @@ mixgtk_mixal_load_file (void)
g_assert (clist_);
gtk_clist_clear (clist_);
-
file = mix_vm_get_src_file (vm_);
if (file != NULL)
{
gint k;
mix_address_t addr;
-
+ const mix_symbol_table_t *table = mix_vm_get_symbol_table (vm_);
+
lineno_ = mix_src_file_get_line_no (file);
-
+ if (tips_text_) g_ptr_array_free (tips_text_, TRUE);
+ tips_text_ = g_ptr_array_new ();
gtk_clist_freeze (clist_);
for (k = 0; k < lineno_; ++k)
{
const gchar *line = mix_src_file_get_line (file, k + 1);
+
snprintf (CONT, CONT_SIZE, "%03d: %s", k + 1, line);
addr = mix_vm_get_lineno_address (vm_, k + 1);
if (addr != MIX_VM_CELL_NO)
@@ -174,6 +220,8 @@ mixgtk_mixal_load_file (void)
gtk_clist_append (clist_, TEXT);
gtk_clist_set_row_data (clist_, k, GINT_TO_POINTER
(mix_short_magnitude (addr)));
+ if (table) update_tips_ (table, line);
+
}
gtk_clist_append (clist_, NULL_TEXT);
gtk_clist_set_row_data (clist_, k, GINT_TO_POINTER (MIX_VM_CELL_NO));
@@ -285,3 +333,22 @@ on_mixal_select_row (GtkWidget *w, gint row, gint col, GdkEventButton *e,
}
}
+gint
+on_mixal_motion_notify_event (GtkWidget *list, GdkEventMotion *event,
+ gpointer data)
+{
+ static gint last_row = 0;
+ static guint last_message = 0;
+ gint row = last_row, col = 0;
+ if (gtk_clist_get_selection_info (clist_, event->x, event->y, &row, &col)
+ && row != last_row && tips_text_)
+ {
+ last_row = row;
+ if (last_message)
+ gtk_statusbar_remove (status_, status_context_, last_message);
+ last_message = gtk_statusbar_push
+ (status_, status_context_,
+ (const gchar *)g_ptr_array_index (tips_text_, row));
+ }
+ return FALSE;
+}