[gcalctool] Fix double pasting into display with middle button
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Fix double pasting into display with middle button
- Date: Fri, 16 Jul 2010 01:35:02 +0000 (UTC)
commit 222f6710ef8f443d30e009544fd2191ea2328b5c
Author: Robert Ancell <robert ancell gmail com>
Date: Fri Jul 16 11:34:27 2010 +1000
Fix double pasting into display with middle button
NEWS | 6 ++-
src/math-display.c | 55 +++++++++-----------
src/math-display.h | 3 +
src/math-equation.c | 138 +++++++++++++-------------------------------------
src/math-equation.h | 1 +
src/math-window.c | 4 +-
6 files changed, 71 insertions(+), 136 deletions(-)
---
diff --git a/NEWS b/NEWS
index 20335ac..fba9a9d 100644
--- a/NEWS
+++ b/NEWS
@@ -3,7 +3,11 @@
* Copyright (c) 1987-2009 Sun Microsystems, Inc.
* All Rights Reserved.
*/
-
+
+Overview of changes in gcalctool 5.31.6
+
+ * Fix double pasting into display with middle button
+
Overview of changes in gcalctool 5.31.5
* Call gsettings_sync() before quit
diff --git a/src/math-display.c b/src/math-display.c
index 915d9df..62f0218 100644
--- a/src/math-display.c
+++ b/src/math-display.c
@@ -29,10 +29,14 @@ enum {
struct MathDisplayPrivate
{
+ /* Equation being displayed */
MathEquation *equation;
- GtkWidget *display_item; /* Calculator display. */
- GtkTextBuffer *info_buffer; /* Buffer used in info messages */
+ /* Display widget */
+ GtkWidget *text_view;
+
+ /* Buffer that shows errors etc */
+ GtkTextBuffer *info_buffer;
};
G_DEFINE_TYPE (MathDisplay, math_display, GTK_TYPE_VBOX);
@@ -225,19 +229,9 @@ display_key_press_cb(GtkWidget *widget, GdkEventKey *event, MathDisplay *display
static gboolean
key_press_cb(MathDisplay *display, GdkEventKey *event)
{
- gboolean result;
- g_signal_emit_by_name(display->priv->display_item, "key-press-event", event, &result);
- return result;
-}
-
-
-static gboolean
-button_release_cb(GtkWidget *widget, GdkEventButton *event, MathDisplay *display)
-{
- if (event->button == 2)
- math_equation_paste(display->priv->equation);
-
- return FALSE;
+ gboolean result;
+ g_signal_emit_by_name(display->priv->text_view, "key-press-event", event, &result);
+ return result;
}
@@ -256,25 +250,24 @@ create_gui(MathDisplay *display)
g_signal_connect(display, "key-press-event", G_CALLBACK(key_press_cb), display);
- display->priv->display_item = gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(display->priv->equation));
- gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(display->priv->display_item), GTK_WRAP_WORD);
- gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(display->priv->display_item), FALSE);
- gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(display->priv->display_item), 8);
- gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(display->priv->display_item), 2);
+ display->priv->text_view = gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(display->priv->equation));
+ gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(display->priv->text_view), GTK_WRAP_WORD);
+ gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(display->priv->text_view), FALSE);
+ gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(display->priv->text_view), 8);
+ gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(display->priv->text_view), 2);
/* TEMP: Disabled for now as GTK+ doesn't properly render a right aligned right margin, see bug #482688 */
- /*gtk_text_view_set_right_margin(GTK_TEXT_VIEW(display->priv->display_item), 6);*/
- gtk_text_view_set_justification(GTK_TEXT_VIEW(display->priv->display_item), GTK_JUSTIFY_RIGHT);
- gtk_widget_ensure_style(display->priv->display_item);
- font_desc = pango_font_description_copy(gtk_widget_get_style(display->priv->display_item)->font_desc);
+ /*gtk_text_view_set_right_margin(GTK_TEXT_VIEW(display->priv->text_view), 6);*/
+ gtk_text_view_set_justification(GTK_TEXT_VIEW(display->priv->text_view), GTK_JUSTIFY_RIGHT);
+ gtk_widget_ensure_style(display->priv->text_view);
+ font_desc = pango_font_description_copy(gtk_widget_get_style(display->priv->text_view)->font_desc);
pango_font_description_set_size(font_desc, 16 * PANGO_SCALE);
- gtk_widget_modify_font(display->priv->display_item, font_desc);
+ gtk_widget_modify_font(display->priv->text_view, font_desc);
pango_font_description_free(font_desc);
- gtk_widget_set_name(display->priv->display_item, "displayitem");
- atk_object_set_role(gtk_widget_get_accessible(display->priv->display_item), ATK_ROLE_EDITBAR);
+ gtk_widget_set_name(display->priv->text_view, "displayitem");
+ atk_object_set_role(gtk_widget_get_accessible(display->priv->text_view), ATK_ROLE_EDITBAR);
//FIXME:<property name="AtkObject::accessible-description" translatable="yes" comments="Accessible description for the area in which results are displayed">Result Region</property>
- g_signal_connect(display->priv->display_item, "key-press-event", G_CALLBACK(display_key_press_cb), display);
- g_signal_connect(display->priv->display_item, "button-release-event", G_CALLBACK(button_release_cb), display);
- gtk_box_pack_start(GTK_BOX(display), display->priv->display_item, TRUE, TRUE, 0);
+ g_signal_connect(display->priv->text_view, "key-press-event", G_CALLBACK(display_key_press_cb), display);
+ gtk_box_pack_start(GTK_BOX(display), display->priv->text_view, TRUE, TRUE, 0);
info_view = gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(info_view), GTK_WRAP_WORD);
@@ -288,7 +281,7 @@ create_gui(MathDisplay *display)
display->priv->info_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(info_view));
gtk_widget_show(info_view);
- gtk_widget_show(display->priv->display_item);
+ gtk_widget_show(display->priv->text_view);
g_signal_connect(display->priv->equation, "notify::status", G_CALLBACK(status_changed_cb), display);
status_changed_cb(display->priv->equation, NULL, display);
diff --git a/src/math-display.h b/src/math-display.h
index 0a0b9fc..f933d37 100644
--- a/src/math-display.h
+++ b/src/math-display.h
@@ -42,8 +42,11 @@ typedef struct
} MathDisplayClass;
GType math_display_get_type(void);
+
MathDisplay *math_display_new(void);
+
MathDisplay *math_display_new_with_equation(MathEquation *equation);
+
MathEquation *math_display_get_equation(MathDisplay *display);
#endif /* MATH_DISPLAY_H */
diff --git a/src/math-equation.c b/src/math-equation.c
index 6265d01..af68cd1 100644
--- a/src/math-equation.c
+++ b/src/math-equation.c
@@ -100,11 +100,6 @@ struct MathEquationPrivate
gboolean in_delete;
MathVariables *variables;
-
- // FIXME: Replace with GtkClipboard
- GdkAtom clipboard_atom; /* ??? */ //
- GdkAtom primary_atom; /* ??? */ // FIXME: Is this middle click?
- char *shelf; /* PUT selection shelf contents. */
};
G_DEFINE_TYPE (MathEquation, math_equation, GTK_TYPE_TEXT_BUFFER);
@@ -460,6 +455,36 @@ apply_state(MathEquation *equation, MathEquationState *state)
void
+math_equation_copy(MathEquation *equation)
+{
+ GtkTextIter start, end;
+ gchar *text;
+
+ if (!gtk_text_buffer_get_selection_bounds(GTK_TEXT_BUFFER(equation), &start, &end))
+ gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(equation), &start, &end);
+
+ text = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(equation), &start, &end, FALSE);
+ gtk_clipboard_set_text(gtk_clipboard_get(GDK_NONE), text, -1);
+ g_free (text);
+}
+
+
+static void
+on_paste(GtkClipboard *clipboard, const gchar *text, gpointer data)
+{
+ MathEquation *equation = data;
+ math_equation_insert (equation, text);
+}
+
+
+void
+math_equation_paste(MathEquation *equation)
+{
+ gtk_clipboard_request_text(gtk_clipboard_get(GDK_NONE), on_paste, equation);
+}
+
+
+void
math_equation_undo(MathEquation *equation)
{
GList *link;
@@ -523,6 +548,12 @@ math_equation_get_numeric_point_text(MathEquation *equation)
}
+const gchar *math_equation_get_thousands_separator_text(MathEquation *equation)
+{
+ return equation->priv->tsep;
+}
+
+
void
math_equation_set_accuracy(MathEquation *equation, gint accuracy)
{
@@ -806,99 +837,6 @@ math_equation_get_answer(MathEquation *equation)
void
-math_equation_copy(MathEquation *equation)
-{
- gchar *string = NULL;
- GtkTextIter start, end;
-
- if (!gtk_text_buffer_get_selection_bounds(GTK_TEXT_BUFFER(equation), &start, &end))
- gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(equation), &start, &end);
-
- string = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(equation), &start, &end, FALSE);
-
- if (equation->priv->shelf != NULL)
- g_free(equation->priv->shelf);
- equation->priv->shelf = g_locale_from_utf8(string, strlen(string), NULL, NULL, NULL);
-
- gtk_clipboard_set_text(gtk_clipboard_get(equation->priv->clipboard_atom), equation->priv->shelf, -1);
-
- g_free(string);
-}
-
-
-static void
-on_paste(GtkClipboard *clipboard, const gchar *text, MathEquation *equation)
-{
- const char *input;
- char c, *output, *clean_text;
-
- /* Copy input to modify, no operation can make the clean string longer than
- * the original string */
- clean_text = strdup(text);
-
- output = clean_text;
- for (input = text; *input; input++) {
- /* If the clipboard buffer contains any occurances of the "thousands
- * separator", remove them.
- */
- if (equation->priv->tsep[0] != '\0' && strncmp(input, equation->priv->tsep, strlen(equation->priv->tsep)) == 0) {
- input += strlen(equation->priv->tsep) - 1;
- continue;
- }
-
- /* Replace radix with "." */
- else if (strncmp(input, equation->priv->radix, strlen(equation->priv->radix)) == 0) {
- input += strlen(equation->priv->radix) - 1;
- c = '.';
- }
-
- /* Replace tabs with spaces */
- else if (*input == '\t') {
- c = ' ';
- }
-
- /* Terminate on newlines */
- else if (*input == '\r' || *input == '\n') {
- c = '\0';
- }
-
- /* If an "A", "B", "C", "D" or "F" character is encountered, it
- * will be converted to its lowercase equivalent. If an "E" is
- * found, and the next character is a "-" or a "+", then it
- * remains as an upper case "E" (it's assumed to be a possible
- * exponential number), otherwise its converted to a lower case
- * "e". See bugs #455889 and #469245 for more details.
- */
- else if (*input >= 'A' && *input <= 'F') {
- c = *input;
- if (*input == 'E') {
- if (*(input+1) != '-' && *(input+1) != '+')
- c = tolower(*input);
- }
- else
- c = tolower(*input);
- }
-
- else
- c = *input;
-
- *output++ = c;
- }
- *output++ = '\0';
-
- math_equation_insert(equation, clean_text);
-}
-
-
-void
-math_equation_paste(MathEquation *equation)
-{
- gtk_clipboard_request_text(gtk_clipboard_get(equation->priv->clipboard_atom),
- (GtkClipboardTextReceivedFunc)on_paste, equation);
-}
-
-
-void
math_equation_store(MathEquation *equation, const gchar *name)
{
MPNumber t;
@@ -1747,10 +1685,6 @@ math_equation_init(MathEquation *equation)
equation->priv->variables = math_variables_new();
- // Use GtkClipboad instead
- equation->priv->primary_atom = gdk_atom_intern("PRIMARY", FALSE);
- equation->priv->clipboard_atom = gdk_atom_intern("CLIPBOARD", FALSE);
-
equation->priv->state.status = g_strdup("");
equation->priv->show_zeroes = FALSE;
equation->priv->show_tsep = FALSE;
diff --git a/src/math-equation.h b/src/math-equation.h
index e1c5f45..e93137d 100644
--- a/src/math-equation.h
+++ b/src/math-equation.h
@@ -62,6 +62,7 @@ MathVariables *math_equation_get_variables(MathEquation *equation);
const gchar *math_equation_get_digit_text(MathEquation *equation, guint digit);
const gchar *math_equation_get_numeric_point_text(MathEquation *equation);
+const gchar *math_equation_get_thousands_separator_text(MathEquation *equation);
void math_equation_set_status(MathEquation *equation, const gchar *status);
const gchar *math_equation_get_status(MathEquation *equation);
diff --git a/src/math-window.c b/src/math-window.c
index 08c1d88..85300cd 100644
--- a/src/math-window.c
+++ b/src/math-window.c
@@ -105,14 +105,14 @@ math_window_critical_error(MathWindow *window, const gchar *title, const gchar *
static void
copy_cb(GtkWidget *widget, MathWindow *window)
{
- math_equation_copy(window->priv->equation);
+ math_equation_copy (window->priv->equation);
}
static void
paste_cb(GtkWidget *widget, MathWindow *window)
{
- math_equation_paste(window->priv->equation);
+ math_equation_paste (window->priv->equation);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]