X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=info.c;h=7e6d77df9378908fcd570c23e996452ec630d339;hb=842b05415fac862e73cdbf3446dc801dbd2c156a;hp=83ba09b2a7e68398e90bc86e1fab304ba6e09219;hpb=41a1cf4b1967c689f4c3dab60ac284a1313bb9b4;p=ext%2Fsubsurface.git diff --git a/info.c b/info.c index 83ba09b..7e6d77d 100644 --- a/info.c +++ b/info.c @@ -12,18 +12,19 @@ #include #include #include +#include #include "dive.h" #include "display.h" #include "display-gtk.h" #include "divelist.h" -static GtkComboBoxEntry *location, *buddy, *divemaster; +static GtkEntry *location, *buddy, *divemaster; static GtkTextBuffer *notes; -static int location_changed = 1, notes_changed = 1; -static int divemaster_changed = 1, buddy_changed = 1; -static char *get_text(GtkTextBuffer *buffer) +#define unused /**/ + +unused char *get_text(GtkTextBuffer *buffer) { GtkTextIter start; GtkTextIter end; @@ -35,70 +36,71 @@ static char *get_text(GtkTextBuffer *buffer) /* old is NULL or a valid string, new is a valid string * NOTW: NULL and "" need to be treated as "unchanged" */ -static int text_changed(char *old, char *new) +static int text_changed(const char *old, const char *new) { return ((old && strcmp(old,new)) || (!old && strcmp("",new))); } +unused char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp) +{ + char *old = *textp; + const gchar *new; + GtkEntry *entry; + + entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box))); + new = gtk_entry_get_text(entry); + while (isspace(*new)) + new++; + if (!text_changed(old,new)) + return NULL; + free(old); + *textp = strdup(new); + return *textp; +} + + void flush_dive_info_changes(struct dive *dive) { - char *old_text; +#if 0 + char *old_text, *new_text; int changed = 0; if (!dive) return; - if (location_changed) { - char *new_text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(location)); - old_text = dive->location; - dive->location = new_text; - if (text_changed(old_text,dive->location)) - changed = 1; - if (old_text) - g_free(old_text); + new_text = get_combo_box_entry_text(location, &dive->location); + if (new_text) { + add_location(new_text); + changed = 1; } - if (divemaster_changed) { - char *new_text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(divemaster)); - old_text = dive->divemaster; - dive->divemaster = new_text; - if (text_changed(old_text,dive->divemaster)) - changed = 1; - if (old_text) - g_free(old_text); + new_text = get_combo_box_entry_text(divemaster, &dive->divemaster); + if (new_text) { + add_people(new_text); + changed = 1; } - if (buddy_changed) { - char *new_text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(buddy)); - old_text = dive->buddy; - dive->buddy = new_text; - if (text_changed(old_text,dive->buddy)) - changed = 1; - if (old_text) - g_free(old_text); + new_text = get_combo_box_entry_text(buddy, &dive->buddy); + if (new_text) { + add_people(new_text); + changed = 1; } - if (notes_changed) { - old_text = dive->notes; - dive->notes = get_text(notes); - if (text_changed(old_text,dive->notes)) - changed = 1; - if (old_text) - g_free(old_text); - } + old_text = dive->notes; + dive->notes = get_text(notes); + if (text_changed(old_text,dive->notes)) + changed = 1; + if (old_text) + g_free(old_text); + if (changed) mark_divelist_changed(TRUE); +#endif } -static void set_combo_box_entry_text(GtkComboBoxEntry *combo_box, const char *text) -{ - GtkEntry *entry = GTK_ENTRY(GTK_BIN(combo_box)->child); - gtk_entry_set_text(entry, text); -} - -#define SET_TEXT_ENTRY(x) \ - set_combo_box_entry_text(x, dive && dive->x ? dive->x : "") +#define SET_TEXT_VALUE(x) \ + gtk_entry_set_text(x, dive && dive->x ? dive->x : "") void show_dive_info(struct dive *dive) { @@ -126,13 +128,26 @@ void show_dive_info(struct dive *dive) text += 10; /* Skip the "Dive #0 - " part */ gtk_window_set_title(GTK_WINDOW(main_window), text); - SET_TEXT_ENTRY(divemaster); - SET_TEXT_ENTRY(buddy); - SET_TEXT_ENTRY(location); + SET_TEXT_VALUE(divemaster); + SET_TEXT_VALUE(buddy); + SET_TEXT_VALUE(location); gtk_text_buffer_set_text(notes, dive && dive->notes ? dive->notes : "", -1); } -static GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListStore *completions) +static GtkEntry *text_value(GtkWidget *box, const char *label) +{ + GtkWidget *widget; + GtkWidget *frame = gtk_frame_new(label); + + gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0); + widget = gtk_entry_new(); + gtk_widget_set_can_focus(widget, FALSE); + gtk_editable_set_editable(GTK_EDITABLE(widget), FALSE); + gtk_container_add(GTK_CONTAINER(frame), widget); + return GTK_ENTRY(widget); +} + +unused GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListStore *completions) { GtkEntry *entry; GtkWidget *combo_box; @@ -174,7 +189,10 @@ static GtkTextBuffer *text_view(GtkWidget *box, const char *label) gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN); view = gtk_text_view_new(); + gtk_widget_set_can_focus(view, FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD); + gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE); gtk_container_add(GTK_CONTAINER(scrolled_window), view); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); @@ -263,13 +281,13 @@ GtkWidget *extended_dive_info_widget(void) location_list = gtk_list_store_new(1, G_TYPE_STRING); gtk_container_set_border_width(GTK_CONTAINER(vbox), 6); - location = text_entry(vbox, "Location", location_list); + location = text_value(vbox, "Location"); hbox = gtk_hbox_new(FALSE, 3); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); - divemaster = text_entry(hbox, "Divemaster", people_list); - buddy = text_entry(hbox, "Buddy", people_list); + divemaster = text_value(hbox, "Divemaster"); + buddy = text_value(hbox, "Buddy"); notes = text_view(vbox, "Notes"); return vbox;