gcalctool r2255 - in branches/gnome-2-24: . gcalctool
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gcalctool r2255 - in branches/gnome-2-24: . gcalctool
- Date: Sat, 11 Oct 2008 03:50:23 +0000 (UTC)
Author: rancell
Date: Sat Oct 11 03:50:22 2008
New Revision: 2255
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2255&view=rev
Log:
Only update bit panel when display contains a solved number (Bug #548690)
Modified:
branches/gnome-2-24/ChangeLog
branches/gnome-2-24/gcalctool/display.c
branches/gnome-2-24/gcalctool/display.h
branches/gnome-2-24/gcalctool/gtk.c
Modified: branches/gnome-2-24/gcalctool/display.c
==============================================================================
--- branches/gnome-2-24/gcalctool/display.c (original)
+++ branches/gnome-2-24/gcalctool/display.c Sat Oct 11 03:50:22 2008
@@ -205,6 +205,54 @@
return get_state(display)->expression;
}
+gboolean display_get_integer(GCDisplay *display, gint64 *value)
+{
+ const char *text;
+ char buf[MAX_DISPLAY];
+ gchar *endptr;
+ guint bases[] = {2, 8, 10, 16};
+
+ text = display_get_text(display);
+ if (text[0] == '\0') {
+ text = "0";
+ }
+ else if (display_is_result(display)) {
+ make_number(buf, MAX_DISPLAY, display_get_answer(display), v->base, FALSE);
+ text = buf;
+ }
+
+ *value = g_ascii_strtoll(text, &endptr, bases[v->base]);
+ if(*endptr != '\0' || ((*value == G_MAXINT64 || *value == G_MININT64) && errno == ERANGE))
+ return FALSE;
+ return TRUE;
+}
+
+gboolean display_get_unsigned_integer(GCDisplay *display, guint64 *value)
+{
+ const char *text;
+ char buf[MAX_DISPLAY];
+ gchar *endptr;
+ guint bases[] = {2, 8, 10, 16};
+
+ text = display_get_text(display);
+ if (text[0] == '\0') {
+ text = "0";
+ }
+ else if (display_is_result(display)) {
+ make_number(buf, MAX_DISPLAY, display_get_answer(display), v->base, FALSE);
+ text = buf;
+ }
+
+ /* strtoull() treats the string like a 2's complement number which is not what we want */
+ if(text[0] == '-')
+ return FALSE;
+
+ *value = g_ascii_strtoull(text, &endptr, bases[v->base]);
+ if(*endptr != '\0' || (*value == G_MAXUINT64 && errno == ERANGE))
+ return FALSE;
+ return TRUE;
+}
+
int *display_get_answer(GCDisplay *display)
{
return get_state(display)->ans;
Modified: branches/gnome-2-24/gcalctool/display.h
==============================================================================
--- branches/gnome-2-24/gcalctool/display.h (original)
+++ branches/gnome-2-24/gcalctool/display.h Sat Oct 11 03:50:22 2008
@@ -57,6 +57,8 @@
void display_clear(GCDisplay *);
void display_refresh(GCDisplay *);
+gboolean display_get_integer(GCDisplay *display, gint64 *value);
+gboolean display_get_unsigned_integer(GCDisplay *display, guint64 *value);
int *display_get_answer(GCDisplay *);
int display_get_cursor(GCDisplay *);
Modified: branches/gnome-2-24/gcalctool/gtk.c
==============================================================================
--- branches/gnome-2-24/gcalctool/gtk.c (original)
+++ branches/gnome-2-24/gcalctool/gtk.c Sat Oct 11 03:50:22 2008
@@ -744,29 +744,23 @@
static void
set_bit_panel(void)
{
- int bit_str_len, i;
- int MP[MP_SIZE];
- char bit_str[MAXLINE], label[MAXLINE];
-
- if (display_is_usable_number(&v->display, MP) || !is_integer(MP)) {
- gtk_widget_set_sensitive(X->bit_panel, FALSE);
+ int i;
+ const gchar *label;
+ guint64 value;
+
+ if (!display_get_unsigned_integer(&v->display, &value))
+ {
+ gtk_widget_set_sensitive(X->bit_panel, FALSE);
return;
}
- make_fixed(bit_str, MAXLINE, MP, BIN, MAXLINE, FALSE);
- bit_str_len = strlen(bit_str);
- if (bit_str_len <= MAXBITS) {
- gtk_widget_set_sensitive(X->bit_panel, TRUE);
-
- for (i = 0; i < MAXBITS; i++) {
- if (i < bit_str_len) {
- SNPRINTF(label, MAXLINE, " %c", bit_str[bit_str_len-i-1]);
- } else {
- SNPRINTF(label, MAXLINE, " 0");
- }
- gtk_label_set_text(GTK_LABEL(X->bits[MAXBITS - i - 1]), label);
- }
- } else {
- gtk_widget_set_sensitive(X->bit_panel, FALSE);
+ gtk_widget_set_sensitive(X->bit_panel, TRUE);
+
+ for (i = 0; i < MAXBITS; i++) {
+ if (value & (1LL << (MAXBITS-i-1)))
+ label = " 1";
+ else
+ label = " 0";
+ gtk_label_set_text(GTK_LABEL(X->bits[i]), label);
}
}
@@ -1621,34 +1615,32 @@
static gboolean
bit_toggle_cb(GtkWidget *event_box, GdkEventButton *event)
{
- double number;
- unsigned long long lval;
- int n, MP1[MP_SIZE], index, ret;
-
- index = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(event_box),
- "bit_index"));
- n = MAXBITS - index - 1;
-
- ret = display_is_usable_number(&v->display, display_get_answer(&v->display));
- assert(!ret);
- mp_set_from_mp(display_get_answer(&v->display), MP1);
-
- number = mp_cast_to_double(MP1);
- lval = (long long) number;
-
- if (lval & (1LL << n)) {
- lval &= ~(1LL << n);
- gtk_label_set_text(GTK_LABEL(X->bits[index]), " 0");
- } else {
- lval |= (1LL << n);
- gtk_label_set_text(GTK_LABEL(X->bits[index]), " 1");
- }
- number = (double) lval;
-
- mp_set_from_double(number, display_get_answer(&v->display));
- display_set_string(&v->display, "Ans", -1);
+ guint64 value;
+ int index;
+ const gchar *text;
+ char buf[MAX_DISPLAY];
+ int MP[MP_SIZE];
+
+ index = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(event_box), "bit_index"));
+ assert(display_get_unsigned_integer(&v->display, &value));
+ value ^= (1LL << (MAXBITS - index - 1));
+
+ /* FIXME: Convert to since we don't support setting MP numbers from 64 bit integers */
+ SNPRINTF(buf, MAX_DISPLAY, "%llu", value);
+ MPstr_to_num(buf, DEC, MP);
+
+ /* FIXME: Set as string as display_set_number doesn't store correctly */
+ make_number(buf, MAX_DISPLAY, MP, v->base, FALSE);
+ display_set_string(&v->display, buf, -1);
display_refresh(&v->display);
+ text = gtk_label_get_text(GTK_LABEL(X->bits[index]));
+ if (strcmp(text, " 0") == 0)
+ text = " 1";
+ else
+ text = " 0";
+ gtk_label_set_text(GTK_LABEL(X->bits[index]), text);
+
return (TRUE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]