Have "font_apply()" return an indication as to whether it succeeded or
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 24 Jan 2004 01:02:54 +0000 (01:02 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 24 Jan 2004 01:02:54 +0000 (01:02 +0000)
failed and, if it failed, how it failed.  Have it leave up to its caller
the job of reporting that it couldn't load the requested font; have its
callers do that, and have them set the zoom level on failure so that we
have a zoom level that is at least more likely to work.  Make the alert
boxes for "font_apply()" failures be error boxes, not warning boxes.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@9818 f5534014-38df-0310-8fa8-9805f1628bb7

gtk/gui_prefs.c
gtk/main.c
gtk/main.h
gtk/recent.c

index 46aaf7c1cfdb5000d03b91eb86e99efd125b6263..04ba3e7f0e05c22118acd60c5fa4815814bd968b 100644 (file)
@@ -1,7 +1,7 @@
 /* gui_prefs.c
  * Dialog box for GUI preferences
  *
- * $Id: gui_prefs.c,v 1.59 2004/01/23 20:13:23 guy Exp $
+ * $Id: gui_prefs.c,v 1.60 2004/01/24 01:02:54 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -45,6 +45,7 @@
 #include "packet_list.h"
 #include "compat_macros.h"
 #include "toolbar.h"
+#include "recent.h"
 
 static gint fetch_enum_value(gpointer control, const enum_val_t *enumvals);
 static gint fileopen_dir_changed_cb(GtkWidget *myentry _U_, GdkEvent *event, gpointer parent_w);
@@ -459,7 +460,26 @@ gui_prefs_apply(GtkWidget *w _U_)
 
        if (font_changed) {
                /* This redraws the hex dump windows. */
-               font_apply();
+               switch (font_apply()) {
+
+               case FA_SUCCESS:
+                       break;
+
+               case FA_FONT_NOT_RESIZEABLE:
+                       /* "font_apply()" popped up an alert box. */
+                       /* turn off zooming - font can't be resized */
+                       recent.gui_zoom_level = 0;
+                       break;
+
+               case FA_FONT_NOT_AVAILABLE:
+                       /* We assume this means that the specified size
+                          isn't available. */
+                       simple_dialog(ESD_TYPE_CRIT, NULL,
+                           "That font font isn't available at the specified zoom level;\n"
+                           "turning zooming off.");
+                       recent.gui_zoom_level = 0;
+                       break;
+               }
        } else {
                /* Redraw the hex dump windows, in case the
                   highlight style changed.
index 27f6af17b1197a378777fedf105eeeccd23fecf0..b4b14afc573c2f5396302db773842dd857254c02 100644 (file)
@@ -1,6 +1,6 @@
 /* main.c
  *
- * $Id: main.c,v 1.371 2004/01/23 21:22:18 guy Exp $
+ * $Id: main.c,v 1.372 2004/01/24 01:02:54 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -314,25 +314,80 @@ goto_bottom_frame_cb(GtkWidget *w _U_, gpointer d _U_)
 void
 view_zoom_in_cb(GtkWidget *w _U_, gpointer d _U_)
 {
+    gint save_gui_zoom_level;
 
+    save_gui_zoom_level = recent.gui_zoom_level;
     recent.gui_zoom_level++;
-    font_apply();
+    switch (font_apply()) {
+
+    case FA_SUCCESS:
+        break;
+
+    case FA_FONT_NOT_RESIZEABLE:
+        /* "font_apply()" popped up an alert box. */
+        recent.gui_zoom_level = save_gui_zoom_level;   /* undo zoom */
+        break;
+
+    case FA_FONT_NOT_AVAILABLE:
+        /* We assume this means that the specified size isn't available. */
+        simple_dialog(ESD_TYPE_CRIT, NULL,
+            "Your current font isn't available in the next larger size.\n");
+        recent.gui_zoom_level = save_gui_zoom_level;   /* undo zoom */
+        break;
+    }
 }
 
 void
 view_zoom_out_cb(GtkWidget *w _U_, gpointer d _U_)
 {
+    gint save_gui_zoom_level;
 
+    save_gui_zoom_level = recent.gui_zoom_level;
     recent.gui_zoom_level--;
-    font_apply();
+    switch (font_apply()) {
+
+    case FA_SUCCESS:
+        break;
+
+    case FA_FONT_NOT_RESIZEABLE:
+        /* "font_apply()" popped up an alert box. */
+        recent.gui_zoom_level = save_gui_zoom_level;   /* undo zoom */
+        break;
+
+    case FA_FONT_NOT_AVAILABLE:
+        /* We assume this means that the specified size isn't available. */
+        simple_dialog(ESD_TYPE_CRIT, NULL,
+            "Your current font isn't available in the next smaller size.\n");
+        recent.gui_zoom_level = save_gui_zoom_level;   /* undo zoom */
+        break;
+    }
 }
 
 void
 view_zoom_100_cb(GtkWidget *w _U_, gpointer d _U_)
 {
+    gint save_gui_zoom_level;
 
+    save_gui_zoom_level = recent.gui_zoom_level;
     recent.gui_zoom_level = 0;
-    font_apply();
+    switch (font_apply()) {
+
+    case FA_SUCCESS:
+        break;
+
+    case FA_FONT_NOT_RESIZEABLE:
+        /* "font_apply()" popped up an alert box. */
+        recent.gui_zoom_level = save_gui_zoom_level;   /* undo zoom */
+        break;
+
+    case FA_FONT_NOT_AVAILABLE:
+        /* We assume this means that the specified size isn't available.
+           XXX - this "shouldn't happen". */
+        simple_dialog(ESD_TYPE_CRIT, NULL,
+            "Your current font couldn't be reloaded at the size you selected.\n");
+        recent.gui_zoom_level = save_gui_zoom_level;   /* undo zoom */
+        break;
+    }
 }
 
 
@@ -2887,7 +2942,7 @@ font_zoom(char *gui_font_name)
     return g_strdup(new_font_name);
 }
 
-void
+fa_ret_t
 font_apply(void) {
     char *gui_font_name;
 #if GTK_MAJOR_VERSION < 2
@@ -2907,10 +2962,9 @@ font_apply(void) {
         * We just report that for now as a font not available in
         * multiple sizes.
         */
-        simple_dialog(ESD_TYPE_WARN, NULL,
-            "Your current font isn't available in any other sizes.\n"
-            "Please update your font setting in Edit->Preferences!");
-        return;
+        simple_dialog(ESD_TYPE_CRIT, NULL,
+            "Your current font isn't available in any other sizes.\n");
+        return FA_FONT_NOT_RESIZEABLE;
     }
 
 #if GTK_MAJOR_VERSION < 2
@@ -2923,9 +2977,6 @@ font_apply(void) {
     pango_font_description_set_weight(new_b_font, PANGO_WEIGHT_BOLD);
 #endif
     if (new_r_font == NULL || new_b_font == NULL) {
-        simple_dialog(ESD_TYPE_WARN, NULL,
-            "Font name: \"%s\" invalid, cannot load font!", 
-            gui_font_name);
         /* We're no longer using the new fonts; unreference them. */
 #if GTK_MAJOR_VERSION < 2
         if (new_r_font != NULL)
@@ -2939,7 +2990,11 @@ font_apply(void) {
             pango_font_description_free(new_b_font);
 #endif
         g_free(gui_font_name);
-        return;
+
+        /* We let our caller pop up a dialog box, as the error message
+           depends on the context (did they zoom in or out, or did they
+           do something else? */
+        return FA_FONT_NOT_AVAILABLE;
     }
 
     /* the font(s) seem to be ok */
@@ -2971,6 +3026,7 @@ font_apply(void) {
         pango_font_description_free(old_b_font);
 #endif
     g_free(gui_font_name);
+    return FA_SUCCESS;
 }
 
 
index 63bfecdcbe1947453307d3504520b3e715eb5efc..5cfdbc1b3071f0627d9589e62fd35edc8d03c735 100644 (file)
@@ -1,7 +1,7 @@
 /* main.h
  * Global defines, etc.
  *
- * $Id: main.h,v 1.37 2004/01/20 18:47:24 ulfl Exp $
+ * $Id: main.h,v 1.38 2004/01/24 01:02:54 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -106,7 +106,12 @@ extern void dfilter_recent_combo_write_all(FILE *rf);
 
 extern void main_widgets_rearrange(void);
 
-extern void font_apply(void);
+typedef enum {
+       FA_SUCCESS,
+       FA_FONT_NOT_RESIZEABLE,
+       FA_FONT_NOT_AVAILABLE
+} fa_ret_t;
+extern fa_ret_t font_apply(void);
 #if GTK_MAJOR_VERSION < 2
 char *font_boldify(const char *);
 void set_fonts(GdkFont *regular, GdkFont *bold);
index 57bc1e6633a60ea95f2d75a78e268ebdc2bc8a15..5b4021c905ed143a12e6434b87291464306a049f 100644 (file)
@@ -2,7 +2,7 @@
  * Recent "preference" handling routines
  * Copyright 2004, Ulf Lamping <ulf.lamping@web.de>
  *
- * $Id: recent.c,v 1.5 2004/01/20 18:47:25 ulfl Exp $
+ * $Id: recent.c,v 1.6 2004/01/24 01:02:54 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -260,7 +260,26 @@ read_recent(char **rf_path_return, int *rf_errno_return)
   }
 
   menu_recent_read_finished();
-  font_apply();
+
+  switch (font_apply()) {
+
+  case FA_SUCCESS:
+    break;
+
+  case FA_FONT_NOT_RESIZEABLE:
+    /* "font_apply()" popped up an alert box. */
+    recent.gui_zoom_level = 0; /* turn off zooming - font can't be resized */
+    break;
+
+  case FA_FONT_NOT_AVAILABLE:
+    /* XXX - did we successfully load the un-zoomed version earlier?
+       If so, this *probably* means the font is available, but not at
+       this particular zoom level, but perhaps some other failure
+       occurred; I'm not sure you can determine which is the case,
+       however. */
+    recent.gui_zoom_level = 0; /* turn off zooming - zoom level is unavailable */
+    break;
+  }
 }