/* -*-c-*- -------------- mixgtk_mixal.c : * Implementation of the functions declared in mixgtk_mixal.h * ------------------------------------------------------------------ * Last change: Time-stamp: "01/03/10 02:27:52 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #include "mixgtk_widgets.h" #include "mixgtk_mixal.h" static const mix_vm_t *vm_; static GtkCList *clist_; static gulong lineno_; /* initialise the mixal widgets */ gboolean mixgtk_mixal_init (const mix_vm_t *vm) { g_return_val_if_fail (vm != NULL, FALSE); vm_ = vm; clist_ = GTK_CLIST (mixgtk_widget_factory_get (MIXGTK_WIDGET_MIXAL)); g_return_val_if_fail (clist_ != NULL, FALSE); return TRUE; } /* load the corresponding mixal file */ void mixgtk_mixal_load_file (void) { enum {ADDR_SIZE = 10, CONT_SIZE = 20}; static gchar ADDR[ADDR_SIZE], CONT[CONT_SIZE]; static const gchar *TEXT[3]; const mix_src_file_t *file; g_assert (vm_); g_assert (clist_); gtk_clist_clear (clist_); file = mix_vm_get_src_file (vm_); if (file != NULL) { gint k; mix_address_t addr; lineno_ = mix_src_file_get_line_no (file); gtk_clist_freeze (clist_); for (k = 0; k < lineno_; ++k) { TEXT[0] = TEXT[1] = ""; TEXT[2] = mix_src_file_get_line (file, k + 1); addr = mix_vm_get_lineno_address (vm_, k + 1); if (addr != MIX_VM_CELL_NO) { snprintf (ADDR, ADDR_SIZE, "%04d", mix_short_magnitude (addr)); mix_word_print_to_buffer (mix_vm_get_addr_contents (vm_, addr), CONT); TEXT[0] = ADDR; TEXT[1] = CONT; } gtk_clist_append (clist_, (gchar **)TEXT); } TEXT[0] = TEXT[1] = TEXT[2] = NULL; gtk_clist_append (clist_, (gchar **)TEXT); gtk_clist_thaw (clist_); } else lineno_ = 0; } /* update the widgets */ void mixgtk_mixal_update (void) { gint addr = 0; gint k = 0; gchar *addrval = NULL; g_assert (vm_); g_assert (clist_); addr = mix_short_magnitude (mix_vm_get_prog_count (vm_)); while (k < lineno_) { gtk_clist_get_text (clist_, k, 0, &addrval); if (addrval && atoi(addrval) == addr) break; ++k; } gtk_clist_select_row (clist_, k, 0); if (gtk_clist_row_is_visible (clist_, k) != GTK_VISIBILITY_FULL) gtk_clist_moveto (clist_, k, 0, 0.25, 0); }