goffice r2287 - in trunk: . goffice/graph
- From: emmanuel svn gnome org
- To: svn-commits-list gnome org
- Subject: goffice r2287 - in trunk: . goffice/graph
- Date: Thu, 11 Dec 2008 16:03:38 +0000 (UTC)
Author: emmanuel
Date: Thu Dec 11 16:03:38 2008
New Revision: 2287
URL: http://svn.gnome.org/viewvc/goffice?rev=2287&view=rev
Log:
2008-12-11 Emmanuel Pacaud <emmanuel pacaud lapp in2p3 fr>
Use a GtkTextView for the equation expression.
* goffice/graph/gog-equation-prefs.glade: use a GtkTextView.
* goffice/graph/gog-equation.c (cb_equation_buffer_changed): replaces
cb_equation_entry_changed.
(gog_equation_populate_editor): use a GtkTextView.
(gog_equation_update): try to fix the user entered expression in order
to have a valid mathml tree.
Modified:
trunk/ChangeLog
trunk/goffice/graph/gog-equation-prefs.glade
trunk/goffice/graph/gog-equation.c
Modified: trunk/goffice/graph/gog-equation-prefs.glade
==============================================================================
--- trunk/goffice/graph/gog-equation-prefs.glade (original)
+++ trunk/goffice/graph/gog-equation-prefs.glade Thu Dec 11 16:03:38 2008
@@ -14,34 +14,21 @@
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
- <widget class="GtkHBox" id="hbox1">
+ <widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
- <property name="spacing">12</property>
- <child>
- <widget class="GtkLabel" id="label54">
- <property name="visible">True</property>
- <property name="label" translatable="yes">_Equation:</property>
- <property name="use_underline">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
<child>
- <widget class="GtkEntry" id="equation_entry">
+ <widget class="GtkTextView" id="equation_text">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="wrap_mode">GTK_WRAP_CHAR</property>
+ <property name="accepts_tab">False</property>
</widget>
- <packing>
- <property name="position">1</property>
- </packing>
</child>
</widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
</child>
<child>
<widget class="GtkCheckButton" id="compact_mode_check">
Modified: trunk/goffice/graph/gog-equation.c
==============================================================================
--- trunk/goffice/graph/gog-equation.c (original)
+++ trunk/goffice/graph/gog-equation.c Thu Dec 11 16:03:38 2008
@@ -61,9 +61,13 @@
#ifdef GOFFICE_WITH_GTK
static void
-cb_equation_entry_changed (GtkEntry *entry, GogEquation *equation)
+cb_equation_buffer_changed (GtkTextBuffer *buffer, GogEquation *equation)
{
- g_object_set (G_OBJECT (equation), "itex", gtk_entry_get_text (entry), NULL);
+ GtkTextIter start;
+ GtkTextIter end;
+
+ gtk_text_buffer_get_bounds (buffer, &start, &end);
+ g_object_set (G_OBJECT (equation), "itex", gtk_text_buffer_get_text (buffer, &start, &end, FALSE), NULL);
}
static void
cb_inline_mode_check_toggled (GtkToggleButton *button, GogEquation *equation)
@@ -80,13 +84,15 @@
GogEquation *equation = GOG_EQUATION (obj);
GladeXML *gui;
GtkWidget *widget;
+ GtkTextBuffer *buffer;
gui = go_libglade_new ("gog-equation-prefs.glade", "gog_equation_prefs", GETTEXT_PACKAGE, cc);
g_return_if_fail (gui != NULL);
- widget = glade_xml_get_widget (gui, "equation_entry");
- gtk_entry_set_text (GTK_ENTRY (widget), equation->itex);
- g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (cb_equation_entry_changed), obj);
+ widget = glade_xml_get_widget (gui, "equation_text");
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
+ gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), equation->itex, -1);
+ g_signal_connect (G_OBJECT (buffer), "changed", G_CALLBACK (cb_equation_buffer_changed), obj);
widget = glade_xml_get_widget (gui, "compact_mode_check");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), equation->inline_mode);
@@ -107,25 +113,60 @@
{
GogEquation *equation = GOG_EQUATION (obj);
GMathmlDocument *mathml;
- char *itex;
- size_t size;
+ GString *itex;
+ char *itex_iter;
+ char *prev_char = '\0';
+ size_t size_utf8;
unsigned int i;
+ int n_unclosed_braces = 0;
+ int j;
gboolean is_blank = TRUE;
+ gboolean add_dash = FALSE;
+
+ if (equation->itex != NULL && !g_utf8_validate (equation->itex, -1, NULL)) {
+ g_free (equation->itex);
+ equation->itex = NULL;
+ }
+
+ if (equation->itex != NULL) {
+ size_utf8 = g_utf8_strlen (equation->itex, -1);
+
+ if (size_utf8 > 0) {
+ for (i = 0, itex_iter = equation->itex;
+ i < size_utf8;
+ i++, itex_iter = g_utf8_next_char (itex_iter)) {
+ if (*itex_iter != ' ') {
+ is_blank = FALSE;
+
+ if (*itex_iter == '{' && *prev_char != '\\')
+ n_unclosed_braces++;
+ else if (*itex_iter == '}' && *prev_char != '\\')
+ n_unclosed_braces--;
+ }
+
+ prev_char = itex_iter;
+ }
+ if (prev_char != NULL && (*prev_char == '^' || *prev_char == '_'))
+ add_dash = TRUE;
- size = equation->itex != NULL ? strlen(equation->itex) : 0;
- for (i = 0; i < size; i++) {
- if (equation->itex[i] != ' ') {
- is_blank = FALSE;
- break;
}
}
if (equation->inline_mode)
- itex = g_strdup_printf ("$%s$", equation->itex);
+ itex = g_string_new ("$");
+ else
+ itex = g_string_new ("$$");
+ g_string_append (itex, equation->itex);
+ if (add_dash)
+ g_string_append_c (itex, '-');
+ for (j = 0; j < n_unclosed_braces; j++)
+ g_string_append_c (itex, '}');
+ if (equation->inline_mode)
+ itex = g_string_append (itex, "$");
else
- itex = g_strdup_printf ("$$%s$$", equation->itex);
+ itex = g_string_append (itex, "$$");
- mathml = gmathml_document_new_from_itex (itex);
+ mathml = gmathml_document_new_from_itex (itex->str);
/* Keep the last valid mathml document if the itex -> mathml conversion fails.
* It keep the equation from disappearing when the current equation entry is not a
@@ -139,7 +180,7 @@
} else
g_object_unref (mathml);
- g_free (itex);
+ g_string_free (itex, TRUE);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]