Commit 368aa730 authored by Andreas J. Guelzow's avatar Andreas J. Guelzow Committed by Andreas J. Guelzow

moved to gui-utils.c/h (entry_to_int) : ditto (float_to_entry) : ditto

2002-01-26  Andreas J. Guelzow <aguelzow@taliesin.ca>

	* dialog-analysis-tools.c (entry_to_float) : moved to gui-utils.c/h
	(entry_to_int) : ditto
	(float_to_entry) : ditto
	(int_to_entry) : ditto
	* dialog-autosave.c (autosave_on_off_toggled) renamed to
	  autosave_set_sensitivity and improved functionality
	(dialog_autosave_prompt) : rewritten to use standard gtk dialog
	(dialog_autosave) : rewritten as non-modal
	(cb_autosave_cancel) : new
	(cb_autosave_help) : new
	(cb_autosave_ok) : new

2002-01-26  Andreas J. Guelzow <aguelzow@taliesin.ca>

	* src/gui-util.c (entry_to_float) :
	  moved here from dialogs/dialog-analysis-tools.c
	(entry_to_int) : ditto
	(float_to_entry) : ditto
	(int_to_entry) : ditto

	* src/gui-util.h (entry_to_float) new function (used to be static)
	(entry_to_int) : ditto
	(float_to_entry) : ditto
	(int_to_entry) : ditto
parent 543195fb
2002-01-26 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/gui-util.c (entry_to_float) :
moved here from dialogs/dialog-analysis-tools.c
(entry_to_int) : ditto
(float_to_entry) : ditto
(int_to_entry) : ditto
* src/gui-util.h (entry_to_float) new function (used to be static)
(entry_to_int) : ditto
(float_to_entry) : ditto
(int_to_entry) : ditto
2002-01-25 Andreas J. Guelzow <aguelzow@taliesin.ca>
* item-grid.c (item_grid_event) : don't scroll at end of formula
......
Gnumeric 1.1.0
Andreas:
* Fix gnumeric_notice
* Port gnumeric_notice to gnome2
* Fix #63485
* Make the autosave dialog non-modal, port to gnome2
Jody:
* Initial port to gnome2.
......
2002-01-26 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/gui-util.c (entry_to_float) :
moved here from dialogs/dialog-analysis-tools.c
(entry_to_int) : ditto
(float_to_entry) : ditto
(int_to_entry) : ditto
* src/gui-util.h (entry_to_float) new function (used to be static)
(entry_to_int) : ditto
(float_to_entry) : ditto
(int_to_entry) : ditto
2002-01-25 Andreas J. Guelzow <aguelzow@taliesin.ca>
* item-grid.c (item_grid_event) : don't scroll at end of formula
......
2002-01-26 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/gui-util.c (entry_to_float) :
moved here from dialogs/dialog-analysis-tools.c
(entry_to_int) : ditto
(float_to_entry) : ditto
(int_to_entry) : ditto
* src/gui-util.h (entry_to_float) new function (used to be static)
(entry_to_int) : ditto
(float_to_entry) : ditto
(int_to_entry) : ditto
2002-01-25 Andreas J. Guelzow <aguelzow@taliesin.ca>
* item-grid.c (item_grid_event) : don't scroll at end of formula
......
2002-01-26 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/gui-util.c (entry_to_float) :
moved here from dialogs/dialog-analysis-tools.c
(entry_to_int) : ditto
(float_to_entry) : ditto
(int_to_entry) : ditto
* src/gui-util.h (entry_to_float) new function (used to be static)
(entry_to_int) : ditto
(float_to_entry) : ditto
(int_to_entry) : ditto
2002-01-25 Andreas J. Guelzow <aguelzow@taliesin.ca>
* item-grid.c (item_grid_event) : don't scroll at end of formula
......
2002-01-26 Andreas J. Guelzow <aguelzow@taliesin.ca>
* dialog-analysis-tools.c (entry_to_float) : moved to gui-utils.c/h
(entry_to_int) : ditto
(float_to_entry) : ditto
(int_to_entry) : ditto
* dialog-autosave.c (autosave_on_off_toggled) renamed to
autosave_set_sensitivity and improved functionality
(dialog_autosave_prompt) : rewritten to use standard gtk dialog
(dialog_autosave) : rewritten as non-modal
(cb_autosave_cancel) : new
(cb_autosave_help) : new
(cb_autosave_ok) : new
2002-01-24 Jon K Hellan <hellan@acm.org>
* dialog-formula-guru.c (cb_formula_guru_entry_focus_in): Align
......
......@@ -454,120 +454,6 @@ typedef union {
/* by virtually all tools. */
/**********************************************/
/**
* entry_to_float:
* @entry:
* @the_float:
* update:
*
* retrieve a float from an entry field parsing all reasonable formats
*
**/
static int
entry_to_float (GtkEntry *entry, gnum_float *the_float, gboolean update)
{
char const *text = NULL;
Value *value = NULL;
StyleFormat *format = NULL;
text = gtk_entry_get_text (entry);
value = format_match_number (text, NULL, &format);
if ((value == NULL) || !VALUE_IS_NUMBER (value)) {
*the_float = 0.0;
return 1;
}
*the_float = value_get_as_float (value);
if (update) {
char *tmp = format_value (format, value, NULL, 16);
gtk_entry_set_text (entry, tmp);
g_free (tmp);
}
value_release (value);
return 0;
}
/**
* entry_to_int:
* @entry:
* @the_int:
* update:
*
* retrieve an int from an entry field parsing all reasonable formats
*
**/
static int
entry_to_int (GtkEntry *entry, gint *the_int, gboolean update)
{
char const *text = NULL;
Value *value = NULL;
StyleFormat *format = NULL;
text = gtk_entry_get_text (entry);
value = format_match_number (text, NULL, &format);
if ((value == NULL) || !(value->type == VALUE_INTEGER)) {
*the_int = 0;
return 1;
}
*the_int = value_get_as_int (value);
if (update) {
char *tmp = format_value (format, value, NULL, 16);
gtk_entry_set_text (entry, tmp);
g_free (tmp);
}
value_release (value);
return 0;
}
/**
* float_to_entry:
* @entry:
* @the_float:
*
*
**/
static void
float_to_entry (GtkEntry *entry, gnum_float the_float) {
char *text = NULL;
Value *val = NULL;
val = value_new_float(the_float);
text = format_value (NULL, val, NULL, 16);
if (text) {
gtk_entry_set_text (entry, text);
g_free (text);
}
if (val)
value_release(val);
return;
}
/**
* int_to_entry:
* @entry:
* @the_float:
*
*
**/
static void
int_to_entry (GtkEntry *entry, gint the_int) {
char *text = NULL;
Value *val = NULL;
val = value_new_int(the_int);
text = format_value (NULL, val, NULL, 16);
if (text) {
gtk_entry_set_text (entry, text);
g_free (text);
}
if (val)
value_release(val);
return;
}
/**
* gnumeric_expr_entry_parse_to_value:
......@@ -708,7 +594,6 @@ tool_help_cb (GtkWidget *button, GenericToolState *state)
/**
* tool_destroy:
* @window:
* @focus_widget:
* @state:
*
* Destroy the dialog and associated data structures.
......
......@@ -19,120 +19,194 @@
#include <glade/glade.h>
typedef struct {
GladeXML *gui;
GtkWidget *dialog;
GtkWidget *minutes_entry;
GtkWidget *prompt_cb;
GtkWidget *autosave_on_off;
GtkWidget *ok_button;
GtkWidget *cancel_button;
GtkWidget *help_button;
Workbook *wb;
WorkbookControlGUI *wbcg;
} autosave_t;
#define AUTOSAVE_KEY "autosave-setup-dialog"
static void
autosave_on_off_toggled(GtkWidget *widget, autosave_t *p)
autosave_set_sensitivity (GtkWidget *widget, autosave_t *state)
{
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (state->autosave_on_off));
gint minutes;
gint minutes_valid = entry_to_int (GTK_ENTRY (state->minutes_entry), &minutes, FALSE);
gtk_widget_set_sensitive (state->minutes_entry, active);
gtk_widget_set_sensitive (state->prompt_cb, active);
gtk_widget_set_sensitive (state->ok_button, !active ||
((minutes_valid == 0) && (minutes > 0)));
gtk_widget_set_sensitive (p->minutes_entry, active);
gtk_widget_set_sensitive (p->prompt_cb, active);
}
gboolean
dialog_autosave_prompt (WorkbookControlGUI *wbcg)
{
GtkWidget *dia;
GladeXML *gui;
gint v;
gui = gnumeric_glade_xml_new (wbcg, "autosave-prompt.glade");
if (gui == NULL)
return 0;
dia = glade_xml_get_widget (gui, "AutoSavePrompt");
if (!dia) {
printf("Corrupt file autosave-prompt.glade\n");
return 0;
gint result;
GtkWidget *dialog;
dialog = gtk_message_dialog_new (wbcg_toplevel (wbcg),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
_("Do you want to save the workbook %s ?"),
workbook_get_filename (wb_control_workbook
(WORKBOOK_CONTROL (wbcg))));
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return result == GTK_RESPONSE_YES;
}
/**
* dialog_autosave:
* @window:
* @state:
*
* Destroy the dialog and associated data structures.
*
**/
static gboolean
dialog_autosave_destroy (GtkObject *w, autosave_t *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
if (state->gui != NULL) {
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
v = gnumeric_dialog_run (wbcg, GTK_DIALOG (dia));
if (v != -1)
gtk_object_destroy (GTK_OBJECT (dia));
g_object_unref (G_OBJECT (gui));
state->dialog = NULL;
g_free (state);
if (v == 0)
return TRUE;
else
return FALSE;
return FALSE;
}
void
dialog_autosave (WorkbookControlGUI *wbcg)
/**
* cb_autosave_cancel:
* @button:
* @state:
*
* Close (destroy) the dialog
**/
static void
cb_autosave_cancel (GtkWidget *button, autosave_t *state)
{
GladeXML *gui;
GtkWidget *dia;
GtkWidget *autosave_on_off;
gchar buf[20];
gint v;
autosave_t p;
wbcg_autosave_cancel (wbcg);
gtk_widget_destroy (state->dialog);
return;
}
gui = gnumeric_glade_xml_new (wbcg, "autosave.glade");
if (gui == NULL)
return;
/**
* cb_autosave_help:
* @button:
* @state:
**/
static void
cb_autosave_help (GtkWidget *button, autosave_t *state)
{
gnumeric_help_display ("autosave.html");
return;
}
dia = glade_xml_get_widget (gui, "AutoSave");
p.minutes_entry = glade_xml_get_widget (gui, "minutes");
p.prompt_cb = glade_xml_get_widget (gui, "prompt_on_off");
autosave_on_off = glade_xml_get_widget (gui, "autosave_on_off");
/**
* cb_autosave_ok:
* @button:
* @state:
**/
static void
cb_autosave_ok (GtkWidget *button, autosave_t *state)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (state->autosave_on_off))) {
int minutes;
int minutes_valid = entry_to_int (GTK_ENTRY (state->minutes_entry),
&minutes, TRUE);
if (!dia || !p.minutes_entry || !p.prompt_cb || !autosave_on_off) {
printf ("Corrupt file autosave.glade\n");
return;
}
g_return_if_fail (minutes_valid == 0); /* Why is ok active? */
wbcg_autosave_set (state->wbcg, minutes,
gtk_toggle_button_get_active (
GTK_TOGGLE_BUTTON (state->prompt_cb)));
} else
wbcg_autosave_set (state->wbcg, 0, FALSE);
gtk_widget_destroy (state->dialog);
}
sprintf(buf, "%d", wbcg->autosave_minutes);
gtk_entry_set_text (GTK_ENTRY (p.minutes_entry), buf);
void
dialog_autosave (WorkbookControlGUI *wbcg)
{
autosave_t *state;
gnome_dialog_editable_enters (GNOME_DIALOG (dia),
GTK_EDITABLE (p.minutes_entry));
g_return_if_fail (wbcg != NULL);
gtk_signal_connect (GTK_OBJECT (autosave_on_off), "toggled",
GTK_SIGNAL_FUNC (autosave_on_off_toggled),
&p);
if (gnumeric_dialog_raise_if_exists (wbcg, AUTOSAVE_KEY))
return;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (autosave_on_off),
wbcg->autosave);
state = g_new (autosave_t, 1);
state->wbcg = wbcg;
state->wb = wb_control_workbook (WORKBOOK_CONTROL (wbcg));
if (!wbcg->autosave) {
gtk_widget_set_sensitive (p.minutes_entry, FALSE);
gtk_widget_set_sensitive (p.prompt_cb, FALSE);
state->gui = gnumeric_glade_xml_new (wbcg, "autosave.glade");
if (state->gui == NULL) {
g_free (state);
return;
}
gtk_toggle_button_set_active ((GtkToggleButton *) p.prompt_cb,
wbcg->autosave_prompt);
loop:
v = gnumeric_dialog_run (wbcg, GTK_DIALOG (dia));
if (v == 0) {
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (autosave_on_off))) {
int tmp = atoi (gtk_entry_get_text (
GTK_ENTRY (p.minutes_entry)));
if (tmp <= 0) {
gnumeric_notice (wbcg, GTK_MESSAGE_ERROR,
_("You should introduce a proper "
"number of minutes in the entry."));
gtk_widget_grab_focus (p.minutes_entry);
goto loop;
}
wbcg_autosave_set (
wbcg, tmp, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (p.prompt_cb)));
} else
wbcg_autosave_set (wbcg, 0, FALSE);
} else if (v == 2) {
gnumeric_help_display ("autosave.html");
goto loop;
state->dialog = glade_xml_get_widget (state->gui, "AutoSave");
state->minutes_entry = glade_xml_get_widget (state->gui, "minutes");
state->prompt_cb = glade_xml_get_widget (state->gui, "prompt_on_off");
state->autosave_on_off = glade_xml_get_widget (state->gui, "autosave_on_off");
state->ok_button = glade_xml_get_widget (state->gui, "button1");
state->cancel_button = glade_xml_get_widget (state->gui, "button2");
state->help_button = glade_xml_get_widget (state->gui, "button3");
if (!state->dialog || !state->minutes_entry || !state->prompt_cb ||
!state->autosave_on_off) {
gnumeric_notice (wbcg, GTK_MESSAGE_ERROR,
_("Could not create the autosave dialog."));
g_free (state);
return;
}
float_to_entry (GTK_ENTRY (state->minutes_entry), wbcg->autosave_minutes);
gnumeric_editable_enters (GTK_WINDOW (state->dialog),
GTK_EDITABLE (state->minutes_entry));
gtk_signal_connect (GTK_OBJECT (state->autosave_on_off), "toggled",
GTK_SIGNAL_FUNC (autosave_set_sensitivity),
state);
gtk_signal_connect (GTK_OBJECT (state->minutes_entry), "changed",
GTK_SIGNAL_FUNC (autosave_set_sensitivity),
state);
gtk_signal_connect (GTK_OBJECT (state->ok_button), "clicked",
GTK_SIGNAL_FUNC (cb_autosave_ok), state);
gtk_signal_connect (GTK_OBJECT (state->cancel_button), "clicked",
GTK_SIGNAL_FUNC (cb_autosave_cancel), state);
gtk_signal_connect (GTK_OBJECT (state->help_button), "clicked",
GTK_SIGNAL_FUNC (cb_autosave_help), state);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state->autosave_on_off),
wbcg->autosave);
gtk_toggle_button_set_active ((GtkToggleButton *) state->prompt_cb,
wbcg->autosave_prompt);
if (v != -1)
gtk_object_destroy (GTK_OBJECT (dia));
autosave_set_sensitivity (NULL, state);
gnumeric_keyed_dialog (state->wbcg, GTK_WINDOW (state->dialog),
AUTOSAVE_KEY);
gtk_widget_show (state->dialog);
g_object_unref (G_OBJECT (gui));
}
......@@ -15,6 +15,7 @@
#include "style.h"
#include "style-color.h"
#include "error-info.h"
#include "value.h"
#include <string.h>
#include <gal/widgets/e-colors.h>
......@@ -1049,3 +1050,120 @@ gnumeric_textview_set_text (GtkTextView *text_view, char const *txt)
gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)),
txt, -1);
}
/**
* entry_to_float:
* @entry:
* @the_float:
* update:
*
* retrieve a float from an entry field parsing all reasonable formats
*
**/
int
entry_to_float (GtkEntry *entry, gnum_float *the_float, gboolean update)
{
char const *text = NULL;
Value *value = NULL;
StyleFormat *format = NULL;
text = gtk_entry_get_text (entry);
value = format_match_number (text, NULL, &format);
if ((value == NULL) || !VALUE_IS_NUMBER (value)) {
*the_float = 0.0;
return 1;
}
*the_float = value_get_as_float (value);
if (update) {
char *tmp = format_value (format, value, NULL, 16);
gtk_entry_set_text (entry, tmp);
g_free (tmp);
}
value_release (value);
return 0;
}
/**
* entry_to_int:
* @entry:
* @the_int:
* update:
*
* retrieve an int from an entry field parsing all reasonable formats
*
**/
int
entry_to_int (GtkEntry *entry, gint *the_int, gboolean update)
{
char const *text = NULL;
Value *value = NULL;
StyleFormat *format = NULL;
text = gtk_entry_get_text (entry);
value = format_match_number (text, NULL, &format);
if ((value == NULL) || !(value->type == VALUE_INTEGER)) {
*the_int = 0;
return 1;
}
*the_int = value_get_as_int (value);
if (update) {
char *tmp = format_value (format, value, NULL, 16);
gtk_entry_set_text (entry, tmp);
g_free (tmp);
}
value_release (value);
return 0;
}
/**
* float_to_entry:
* @entry:
* @the_float:
*
*
**/
void
float_to_entry (GtkEntry *entry, gnum_float the_float)
{
char *text = NULL;
Value *val = NULL;
val = value_new_float(the_float);
text = format_value (NULL, val, NULL, 16);
if (text) {
gtk_entry_set_text (entry, text);
g_free (text);
}
if (val)
value_release(val);
return;
}
/**
* int_to_entry:
* @entry:
* @the_float:
*
*
**/
void
int_to_entry (GtkEntry *entry, gint the_int)
{
char *text = NULL;
Value *val = NULL;
val = value_new_int(the_int);
text = format_value (NULL, val, NULL, 16);
if (text) {
gtk_entry_set_text (entry, text);
g_free (text);
}
if (val)
value_release(val);
return;
}
......@@ -111,4 +111,10 @@ void gnumeric_pbox_init_help (GtkWidget *dialog, char const *link);
char *gnumeric_textview_get_text (GtkTextView *text_view);
void gnumeric_textview_set_text (GtkTextView *text_view, char const *txt);
int entry_to_float (GtkEntry *entry, gnum_float *the_float, gboolean update);
int entry_to_int (GtkEntry *entry, gint *the_int, gboolean update);
void float_to_entry (GtkEntry *entry, gnum_float the_float);
void int_to_entry (GtkEntry *entry, gint the_int);
#endif /* GNUMERIC_GUI_UTIL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment