Replace deprecated gtk_clist (memwin)
authorHugo Villeneuve <hugo@hugovil.com>
Thu, 12 Sep 2013 22:12:23 +0000 (18:12 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Thu, 10 Oct 2013 01:08:16 +0000 (21:08 -0400)
src/memwin.c

index 6583ed7..839ed1d 100644 (file)
 #include "cpu8051.h"
 #include "memwin.h"
 
-static GtkWidget *memclist;
+static GtkWidget *memlist;
+
+enum
+{
+       COL_ADDRESS = 0,
+       COL_ASCII = 17,
+       N_COLUMNS,
+};
 
 GtkWidget *
 memwin_init(void)
 {
        int i;
+       int rows;
        GtkWidget *scrollwin;
-       PangoFontDescription *pango_font;
-       char *memdummy[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                            0, 0, 0, 0, 0, 0, 0, 0, 0 };
+       GtkCellRenderer *renderer;
+       GtkTreeViewColumn *column;
+       GtkListStore *store;
+       GtkTreeIter iter;
 
        scrollwin = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwin),
@@ -51,21 +60,61 @@ memwin_init(void)
                                       GTK_POLICY_AUTOMATIC,
                                       GTK_POLICY_AUTOMATIC);
 
-       memclist = gtk_clist_new(18);
-       gtk_clist_set_selection_mode(GTK_CLIST(memclist), GTK_SELECTION_SINGLE);
-
-       for (i = 0; i < 18; i++) {
-               gtk_clist_set_column_justification(
-                       GTK_CLIST(memclist), i, GTK_JUSTIFY_LEFT);
+       /* Creating a model */
+       store = gtk_list_store_new(N_COLUMNS,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING,
+                                  G_TYPE_STRING);
+
+       /* Creating the view component */
+       memlist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+       gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(memlist), TRUE);
+
+       gtk_container_add(GTK_CONTAINER(scrollwin), memlist);
+
+       g_object_unref(store);
+
+
+       /* Columns and cell renderers */
+       renderer = gtk_cell_renderer_text_new();
+
+       /* Add address column */
+       column = gtk_tree_view_column_new_with_attributes(
+               "Address", renderer, "text", COL_ADDRESS, NULL);
+       gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(memlist), column);
+
+       for (i = 1; i < 17; i++) {
+               column = gtk_tree_view_column_new_with_attributes(
+                       "Val", renderer, "text", i, NULL);
+               gtk_tree_view_append_column(GTK_TREE_VIEW(memlist), column);
        }
 
-       pango_font = pango_font_description_from_string(FIXED_FONT);
-       gtk_widget_modify_font(memclist, pango_font);
-
-       for (i = 0; i < 16; i++)
-               gtk_clist_append(GTK_CLIST(memclist), memdummy);
+       column = gtk_tree_view_column_new_with_attributes(
+               "ASCII", renderer, "text", COL_ASCII, NULL);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(memlist), column);
 
-       gtk_container_add(GTK_CONTAINER(scrollwin), memclist);
+       /* Initialize with 16 rows of dummy data... */
+       for (rows = 0; rows < 16; rows++) {
+               /* Add new row. */
+               gtk_list_store_append(store, &iter);
+               gtk_list_store_set(store, &iter, COL_ADDRESS, "0x0000", -1);
+       }
 
        return scrollwin;
 }
@@ -74,9 +123,13 @@ memwin_init(void)
 void
 memwin_DumpD(char *MemAddress)
 {
-       char TextTmp[1024];
-       int row, column, TextLength;
+       int row;
        unsigned int Address;
+       GtkListStore *store;
+
+#ifdef EMU8051_DEBUG
+       printf("memwin_DumpD, address = %s\n", MemAddress);
+#endif
 
        if (strlen(MemAddress) != 0) {
                if (STREQ(MemAddress, "PC"))
@@ -87,17 +140,37 @@ memwin_DumpD(char *MemAddress)
                Address = 0;
        }
 
-       gtk_clist_freeze(GTK_CLIST(memclist));
+       store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(memlist)));
 
        for (row = 0; row < 16; row++) {
+               int valid;
+               GtkTreeIter iter;
+               char TextTmp[1024];
+               int column, TextLength;
+
+               if (row == 0) {
+                       /* Get first row in list store */
+                       valid = gtk_tree_model_get_iter_first(
+                               GTK_TREE_MODEL(store), &iter);
+               } else {
+                       /* Get next row in list store */
+                       valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+               }
+
+               if (!valid) {
+                       printf("Invalid iter...\n");
+                       return;
+               }
+
                sprintf(TextTmp, "%.4X", Address);
-               gtk_clist_set_text(GTK_CLIST(memclist), row, 0, TextTmp);
+               gtk_list_store_set(store, &iter, COL_ADDRESS, TextTmp, -1);
 
                for (column = 0; column < 16; column++) {
                        sprintf(TextTmp, "%.2X",
                                (int) cpu8051_ReadD(Address + column));
-                       gtk_clist_set_text(GTK_CLIST(memclist), row,
-                                          column + 1, TextTmp);
+
+                       gtk_list_store_set(store, &iter, column + 1, TextTmp,
+                                          -1);
                }
 
                TextLength = 0;
@@ -111,11 +184,9 @@ memwin_DumpD(char *MemAddress)
                                TextLength +=
                                        sprintf(&TextTmp[TextLength], ".");
                }
-               gtk_clist_set_text(GTK_CLIST(memclist), row, 17, TextTmp);
+
+               gtk_list_store_set(store, &iter, 17, TextTmp, -1);
 
                Address += 16;
        }
-
-       gtk_clist_select_row(GTK_CLIST(memclist), 0, 0);
-       gtk_clist_thaw(GTK_CLIST(memclist));
 }