summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjaortega <jaortega>2001-03-13 00:10:13 +0000
committerjaortega <jaortega>2001-03-13 00:10:13 +0000
commite6c615a67ef73267fc8b7a600d531d8ccc67908f (patch)
tree9b841a446a79aa937c03470bc19882313cb3d166
parenta7abb051dcb7cc730a527039b962fe9415a6486f (diff)
downloadmdk-e6c615a67ef73267fc8b7a600d531d8ccc67908f.tar.gz
mdk-e6c615a67ef73267fc8b7a600d531d8ccc67908f.tar.bz2
first functional GUI
-rw-r--r--mixgtk/Makefile.am4
-rw-r--r--mixgtk/mixgtk.c10
-rw-r--r--mixgtk/mixgtk.glade116
-rw-r--r--mixgtk/mixgtk_input.c184
-rw-r--r--mixgtk/mixgtk_input.h49
-rw-r--r--mixgtk/mixgtk_mixal.c2
-rw-r--r--mixgtk/mixgtk_mixvm.c56
7 files changed, 375 insertions, 46 deletions
diff --git a/mixgtk/Makefile.am b/mixgtk/Makefile.am
index ab7d069..7b1ed82 100644
--- a/mixgtk/Makefile.am
+++ b/mixgtk/Makefile.am
@@ -20,7 +20,9 @@ mixgtk_SOURCES = mixgtk.c mixgtk_gen_handlers.h mixgtk_gen_handlers.c \
mixgtk_widgets.h mixgtk_widgets.c \
mixgtk_device.h mixgtk_device.c \
mixgtk_mixvm.h mixgtk_mixvm.c \
- mixgtk_mixal.h mixgtk_mixal.c
+ mixgtk_mixal.h mixgtk_mixal.c \
+ mixgtk_input.h mixgtk_input.c
+
diff --git a/mixgtk/mixgtk.c b/mixgtk/mixgtk.c
index ac460ec..9dbae80 100644
--- a/mixgtk/mixgtk.c
+++ b/mixgtk/mixgtk.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mixgtk.c :
* Main function of the mix gtk front-end
* ------------------------------------------------------------------
- * Last change: Time-stamp: "01/03/10 00:03:23 jose"
+ * Last change: Time-stamp: "01/03/13 00:12:37 jose"
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
@@ -29,6 +29,7 @@
#include "mixgtk_device.h"
#include "mixgtk_mixvm.h"
#include "mixgtk_mixal.h"
+#include "mixgtk_input.h"
int
main(int argc, char *argv[])
@@ -73,6 +74,13 @@ main(int argc, char *argv[])
g_error ("Unable to initialise application (mixal widgets)\n");
return EXIT_FAILURE;
}
+
+ if (!mixgtk_input_init ())
+ {
+ g_error ("Unable to initialise application (word input widgets)\n");
+ return EXIT_FAILURE;
+ }
+
gtk_main();
diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade
index 154e708..247d08b 100644
--- a/mixgtk/mixgtk.glade
+++ b/mixgtk/mixgtk.glade
@@ -238,7 +238,7 @@
<signal>
<name>button_press_event</name>
<handler>on_register_click</handler>
- <last_modification_time>Sun, 11 Mar 2001 11:42:43 GMT</last_modification_time>
+ <last_modification_time>Mon, 12 Mar 2001 23:09:49 GMT</last_modification_time>
</signal>
<editable>False</editable>
<text_visible>True</text_visible>
@@ -1061,7 +1061,7 @@
<class>GtkDialog</class>
<name>word_dialog</name>
<visible>False</visible>
- <title>Enter word</title>
+ <title>Enter value</title>
<type>GTK_WINDOW_DIALOG</type>
<position>GTK_WIN_POS_NONE</position>
<modal>True</modal>
@@ -1113,6 +1113,11 @@
<name>word_reset</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
+ <signal>
+ <name>clicked</name>
+ <handler>on_word_reset_clicked</handler>
+ <last_modification_time>Mon, 12 Mar 2001 22:40:33 GMT</last_modification_time>
+ </signal>
<label>Reset</label>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
@@ -1122,6 +1127,11 @@
<name>word_ok</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
+ <signal>
+ <name>clicked</name>
+ <handler>on_word_ok_clicked</handler>
+ <last_modification_time>Mon, 12 Mar 2001 22:40:45 GMT</last_modification_time>
+ </signal>
<label>OK</label>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
@@ -1133,8 +1143,8 @@
<can_focus>True</can_focus>
<signal>
<name>clicked</name>
- <handler>gtk_widget_hide</handler>
- <last_modification_time>Sun, 11 Mar 2001 11:56:42 GMT</last_modification_time>
+ <handler>on_word_cancel_clicked</handler>
+ <last_modification_time>Mon, 12 Mar 2001 23:18:49 GMT</last_modification_time>
</signal>
<label>Cancel</label>
<relief>GTK_RELIEF_NORMAL</relief>
@@ -1161,6 +1171,12 @@
<width>143</width>
<height>22</height>
<can_focus>True</can_focus>
+ <signal>
+ <name>key_press_event</name>
+ <handler>on_word_dec_key_press</handler>
+ <after>True</after>
+ <last_modification_time>Mon, 12 Mar 2001 22:37:13 GMT</last_modification_time>
+ </signal>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
@@ -1175,37 +1191,35 @@
<width>22</width>
<height>22</height>
<can_focus>True</can_focus>
+ <signal>
+ <name>key_press_event</name>
+ <handler>on_word_byte_key_press</handler>
+ <after>True</after>
+ <last_modification_time>Mon, 12 Mar 2001 22:38:56 GMT</last_modification_time>
+ </signal>
<editable>True</editable>
<text_visible>True</text_visible>
- <text_max_length>0</text_max_length>
+ <text_max_length>3</text_max_length>
<text>00</text>
</widget>
<widget>
<class>GtkEntry</class>
- <name>entry35</name>
- <x>160</x>
- <y>64</y>
- <width>22</width>
- <height>22</height>
- <can_focus>True</can_focus>
- <editable>True</editable>
- <text_visible>True</text_visible>
- <text_max_length>0</text_max_length>
- <text>01</text>
- </widget>
-
- <widget>
- <class>GtkEntry</class>
<name>word_b3</name>
<x>160</x>
<y>64</y>
<width>22</width>
<height>22</height>
<can_focus>True</can_focus>
+ <signal>
+ <name>key_press_event</name>
+ <handler>on_word_byte_key_press</handler>
+ <after>True</after>
+ <last_modification_time>Mon, 12 Mar 2001 22:39:26 GMT</last_modification_time>
+ </signal>
<editable>True</editable>
<text_visible>True</text_visible>
- <text_max_length>0</text_max_length>
+ <text_max_length>3</text_max_length>
<text>00</text>
</widget>
@@ -1217,9 +1231,15 @@
<width>22</width>
<height>22</height>
<can_focus>True</can_focus>
+ <signal>
+ <name>key_press_event</name>
+ <handler>on_word_byte_key_press</handler>
+ <after>True</after>
+ <last_modification_time>Mon, 12 Mar 2001 22:39:50 GMT</last_modification_time>
+ </signal>
<editable>True</editable>
<text_visible>True</text_visible>
- <text_max_length>0</text_max_length>
+ <text_max_length>3</text_max_length>
<text>00</text>
</widget>
@@ -1231,10 +1251,16 @@
<width>22</width>
<height>22</height>
<can_focus>True</can_focus>
+ <signal>
+ <name>key_press_event</name>
+ <handler>on_word_byte_key_press</handler>
+ <after>True</after>
+ <last_modification_time>Mon, 12 Mar 2001 22:40:09 GMT</last_modification_time>
+ </signal>
<editable>True</editable>
<text_visible>True</text_visible>
- <text_max_length>0</text_max_length>
- <text>63</text>
+ <text_max_length>3</text_max_length>
+ <text>00</text>
</widget>
<widget>
@@ -1245,9 +1271,15 @@
<width>22</width>
<height>22</height>
<can_focus>True</can_focus>
+ <signal>
+ <name>key_press_event</name>
+ <handler>on_word_byte_key_press</handler>
+ <after>True</after>
+ <last_modification_time>Mon, 12 Mar 2001 22:38:24 GMT</last_modification_time>
+ </signal>
<editable>True</editable>
<text_visible>True</text_visible>
- <text_max_length>0</text_max_length>
+ <text_max_length>3</text_max_length>
<text>00</text>
</widget>
@@ -1261,24 +1293,8 @@
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
- <text_max_length>0</text_max_length>
- <text>-</text>
- </widget>
-
- <widget>
- <class>GtkLabel</class>
- <name>label60</name>
- <x>16</x>
- <y>34</y>
- <width>67</width>
- <height>20</height>
- <label>Decimal</label>
- <justify>GTK_JUSTIFY_CENTER</justify>
- <wrap>False</wrap>
- <xalign>0.5</xalign>
- <yalign>0.5</yalign>
- <xpad>0</xpad>
- <ypad>0</ypad>
+ <text_max_length>1</text_max_length>
+ <text>+</text>
</widget>
<widget>
@@ -1312,6 +1328,22 @@
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <name>label60</name>
+ <x>16</x>
+ <y>34</y>
+ <width>67</width>
+ <height>20</height>
+ <label>Decimal</label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0.5</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ </widget>
</widget>
</widget>
</widget>
diff --git a/mixgtk/mixgtk_input.c b/mixgtk/mixgtk_input.c
new file mode 100644
index 0000000..95e22bb
--- /dev/null
+++ b/mixgtk/mixgtk_input.c
@@ -0,0 +1,184 @@
+/* -*-c-*- -------------- mixgtk_input.c :
+ * Implementation of the functions declared in mixgtk_input.h
+ * ------------------------------------------------------------------
+ * Last change: Time-stamp: "01/03/13 01:04:13 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 <stdlib.h>
+#include "mixgtk_widgets.h"
+#include "mixgtk_input.h"
+
+enum {
+ MSG_, SIGN_, B1_, B2_, B3_, B4_, B5_, DEC_, RESET_, OK_, SIZE_
+};
+
+static const gchar *WGT_NAMES_[SIZE_] = {
+ "word_label", "word_sign", "word_b1", "word_b2", "word_b3",
+ "word_b4", "word_b5", "word_decimal", "word_reset", "word_ok"
+};
+
+
+static GtkDialog *dialog_;
+static GtkWidget *childs_[SIZE_];
+static input_callback_t callback_;
+static gpointer data_;
+
+/* init */
+extern gboolean
+mixgtk_input_init (void)
+{
+ gint k;
+
+ dialog_ = GTK_DIALOG (mixgtk_widget_factory_get (MIXGTK_WIDGET_WORD_DIALOG));
+ g_return_val_if_fail (dialog_ != NULL, FALSE);
+ 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);
+ }
+
+ return TRUE;
+}
+
+static void
+set_word_ (mix_word_t word)
+{
+ enum {SIZE = 50};
+ static gchar BUFFER[SIZE] = {0};
+ gint k;
+ gint val = mix_word_magnitude (word);
+ gboolean neg = mix_word_is_negative (word);
+ snprintf (BUFFER, SIZE, "%s%d", neg ? "-" : "", val);
+ gtk_entry_set_text (GTK_ENTRY (childs_[DEC_]), BUFFER);
+ gtk_entry_set_text (GTK_ENTRY (childs_[SIGN_]), neg ? "-" : "+");
+ for (k = 1; k < 6; ++k)
+ {
+ mix_byte_t b = mix_word_get_byte (word, k);
+ snprintf (BUFFER, SIZE, "%02d", (int)b);
+ gtk_entry_set_text (GTK_ENTRY (childs_[SIGN_ + k]), BUFFER);
+ }
+}
+
+
+/* get a word */
+void
+mixgtk_input_word (const gchar *message, mix_word_t def,
+ input_callback_t cb, gpointer data)
+{
+ gtk_label_set_text (GTK_LABEL (childs_[MSG_]), message);
+ set_word_ (def);
+ callback_ = cb;
+ data_ = data;
+ gtk_widget_show (childs_[B1_]);
+ gtk_widget_show (childs_[B2_]);
+ gtk_widget_show (childs_[B3_]);
+ gtk_widget_show (GTK_WIDGET (dialog_));
+}
+
+/* get a short */
+void
+mixgtk_input_short (const gchar *message, mix_short_t def,
+ input_callback_t cb, gpointer data)
+{
+ gtk_label_set_text (GTK_LABEL (childs_[MSG_]), message);
+ set_word_ (mix_word_to_short_fast (def));
+ callback_ = cb;
+ data_ = data;
+ gtk_widget_show (GTK_WIDGET (dialog_));
+ gtk_widget_hide (childs_[B1_]);
+ gtk_widget_hide (childs_[B2_]);
+ gtk_widget_hide (childs_[B3_]);
+ /* gtk_widget_draw (GTK_WIDGET (dialog_));*/
+}
+
+#include <gdk/gdkkeysyms.h>
+
+/* dec and bytes input handler */
+void
+on_word_dec_key_press (GtkWidget *dec, GdkEvent *event, gpointer *data)
+{
+ GdkEventKey *key = (GdkEventKey *)event;
+ if (key->string && strlen (key->string) > 0)
+ {
+ gchar *text = gtk_entry_get_text (GTK_ENTRY (childs_[DEC_]));
+ gint val = atoi (text);
+ set_word_ (mix_word_new (val));
+ }
+ if (key->keyval == GDK_KP_Tab || key->keyval == GDK_Tab ||
+ key->keyval == GDK_ISO_Left_Tab)
+ gtk_window_set_focus (GTK_WINDOW (dialog_), childs_[SIGN_]);
+}
+
+void
+on_word_byte_key_press (GtkWidget *widget, GdkEvent *event, gpointer *data)
+{
+ GdkEventKey *key = (GdkEventKey *)event;
+ if (key->string && strlen (key->string) > 0)
+ {
+ mix_byte_t bytes[5];
+ gint k;
+ gchar *s;
+ mix_word_t w;
+
+ for (k = 0; k < 5; ++k)
+ {
+ gchar *text = gtk_entry_get_text (GTK_ENTRY (childs_[B1_ + k]));
+ bytes[k] = mix_byte_new (atoi (text));
+ }
+ w = mix_bytes_to_word (bytes, 5);
+ s = gtk_entry_get_text (GTK_ENTRY (childs_[SIGN_]));
+ if (s && s[0] == '-') mix_word_reverse_sign (w);
+ set_word_ (w);
+ }
+ if (key->keyval == GDK_KP_Tab || key->keyval == GDK_Tab ||
+ key->keyval == GDK_ISO_Left_Tab)
+ {
+ gint k = 0;
+ while (widget != childs_[k]) ++k;
+ gtk_window_set_focus (GTK_WINDOW (dialog_),
+ childs_[(k + 1) & (SIZE_ - 1)]);
+ }
+}
+
+void
+on_word_ok_clicked (GtkWidget *widget, gpointer *data)
+{
+ const gchar *text = gtk_entry_get_text (GTK_ENTRY (childs_[DEC_]));
+ mix_word_t w = mix_word_new (atoi (text));
+ callback_ (w, data_);
+ gtk_widget_hide (GTK_WIDGET (dialog_));
+}
+
+void
+on_word_cancel_clicked (GtkWidget *widget, gpointer *data)
+{
+ gtk_widget_hide (GTK_WIDGET (dialog_));
+}
+
+void
+on_word_reset_clicked (GtkWidget *w, gpointer *data)
+{
+ set_word_ (MIX_WORD_ZERO);
+}
+
+
+
+
+
diff --git a/mixgtk/mixgtk_input.h b/mixgtk/mixgtk_input.h
new file mode 100644
index 0000000..275894d
--- /dev/null
+++ b/mixgtk/mixgtk_input.h
@@ -0,0 +1,49 @@
+/* -*-c-*- ---------------- mixgtk_input.h :
+ * Declaration of functions for user input
+ * ------------------------------------------------------------------
+ * Last change: Time-stamp: <01/03/12 23:35:14 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.
+ *
+ */
+
+
+#ifndef MIXGTK_INPUT_H
+#define MIXGTK_INPUT_H
+
+#include <mixlib/mix_types.h>
+
+/* 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,
+ input_callback_t cb, gpointer data);
+
+/* get a short */
+extern void
+mixgtk_input_short (const gchar *message, mix_short_t def,
+ input_callback_t cb, gpointer data );
+
+
+#endif /* MIXGTK_INPUT_H */
+
diff --git a/mixgtk/mixgtk_mixal.c b/mixgtk/mixgtk_mixal.c
index eeef239..b59688d 100644
--- a/mixgtk/mixgtk_mixal.c
+++ b/mixgtk/mixgtk_mixal.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mixgtk_mixal.c :
* Implementation of the functions declared in mixgtk_mixal.h
* ------------------------------------------------------------------
- * Last change: Time-stamp: "01/03/11 02:45:28 jose"
+ * Last change: Time-stamp: "01/03/12 23:48:29 jose"
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
diff --git a/mixgtk/mixgtk_mixvm.c b/mixgtk/mixgtk_mixvm.c
index 16fa410..1ef32a5 100644
--- a/mixgtk/mixgtk_mixvm.c
+++ b/mixgtk/mixgtk_mixvm.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mixgtk_mixvm.c :
* Implementation of the functions declared in mixgtk_mixvm.h
* ------------------------------------------------------------------
- * Last change: Time-stamp: "01/03/09 22:20:59 jose"
+ * Last change: Time-stamp: "01/03/13 00:24:56 jose"
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
@@ -25,6 +25,7 @@
#include "mixgtk_widgets.h"
#include "mixgtk_mixvm.h"
#include "mixgtk_cmd_dispatcher.h"
+#include "mixgtk_input.h"
/* register widgets */
#define REGISTER_NO_ (MIXGTK_WIDGET_rI6 - MIXGTK_WIDGET_rA + 1)
@@ -295,3 +296,56 @@ on_loc_arrow_clicked (GtkWidget *widget, gpointer data)
mixgtk_mixvm_update_cells_to_address (address);
}
+
+static void
+register_AX_ (mix_word_t w, gpointer reg)
+{
+ gint k = GPOINTER_TO_INT (reg);
+ if (k == 0)
+ mix_vm_set_rA (vm_, w);
+ else
+ mix_vm_set_rX (vm_, w);
+ update_register_ (MIXGTK_WIDGET_rA + k);
+}
+
+static void
+register_j_ (mix_word_t w, gpointer data)
+{
+ if (mix_word_is_negative (w)) mix_word_reverse_sign (w);
+ mix_vm_set_rJ (vm_, mix_word_to_short_fast (w));
+ update_register_ (MIXGTK_WIDGET_rJ);
+}
+
+static void
+register_i_ (mix_word_t w, gpointer reg)
+{
+ mix_vm_set_rI (vm_, GPOINTER_TO_INT (reg), mix_word_to_short_fast (w));
+ update_register_ (MIXGTK_WIDGET_rI1 - 1 + GPOINTER_TO_INT (reg));
+}
+
+void
+on_register_click (GtkWidget *w, GdkEvent *e, gpointer data)
+{
+ enum {SIZE = 20};
+ static gchar BUFFER[SIZE];
+ gint k;
+
+ if (w == GTK_WIDGET (reg_entries_[0]))
+ mixgtk_input_word ("Register A", mix_vm_get_rA (vm_),
+ register_AX_, GINT_TO_POINTER (0));
+ else if (w == GTK_WIDGET (reg_entries_[1]))
+ mixgtk_input_word ("Register X", mix_vm_get_rX (vm_),
+ register_AX_, GINT_TO_POINTER(1));
+ else if (w == GTK_WIDGET (reg_entries_[2]))
+ mixgtk_input_short ("Register J", mix_vm_get_rJ (vm_), register_j_, NULL);
+ else for (k = 1; k < 7; ++k)
+ {
+ if (w == GTK_WIDGET (reg_entries_[2 + k]))
+ {
+ snprintf (BUFFER, SIZE, "Register I%d", k);
+ mixgtk_input_short (BUFFER, mix_vm_get_rI (vm_, k),
+ register_i_, GINT_TO_POINTER (k));
+ break;
+ }
+ }
+}