DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2463
Version: 1.3-current


When playing with the new Fl::option() function I found 2 problems (maybe).

#1: It looks like the wrong preference hierarchy would be read.
    prefs.get("ArrowFocus", tmp, 0);
should probably read:
     opt.get("ArrowFocus", tmp, 0);
etc.

#2: This is more subtle: IMHO the user preferences should only override
the system preferences, if the user really _set_ his preferences. The
current code would always set the user preferences or the default value,
if the user preferences are not found (or the particular value is not set
in the preference file). Thus, you can't set system preferences to
anything else than the default effectively.

I suggest changing it in a similar way as the attached patch
Fl_Options.diff. Note that this reads the user preferences with the
default value -1 to indicate whether the option has been set or not. This
might be critical, since -1 is not a legal option value; thus we must take
care not to write the preferences back.

Maybe there's a better way, but I hope you get the idea.


Link: http://www.fltk.org/str.php?L2463
Version: 1.3-current
Index: src/Fl.cxx
===================================================================
--- src/Fl.cxx  (revision 7930)
+++ src/Fl.cxx  (working copy)
@@ -1762,14 +1762,23 @@
     { // first, read the system wide preferences
       Fl_Preferences prefs(Fl_Preferences::SYSTEM, "fltk.org", "fltk");
       Fl_Preferences opt(prefs, "options");
-      prefs.get("ArrowFocus", tmp, 0); options_[OPTION_ARROW_FOCUS] = tmp;
-      prefs.get("NativeFilechooser", tmp, 0); 
options_[OPTION_NATIVE_FILECHOOSER] = tmp;
+      opt.get("ArrowFocus", tmp, 0); options_[OPTION_ARROW_FOCUS] = tmp;
+      opt.get("NativeFilechooser", tmp, 0); 
options_[OPTION_NATIVE_FILECHOOSER] = tmp;
     }
     { // next, check the user preferences
+      // override system options only, if the option is set ( >= 0 )
       Fl_Preferences prefs(Fl_Preferences::USER, "fltk.org", "fltk");
       Fl_Preferences opt(prefs, "options");
-      prefs.get("ArrowFocus", tmp, 0); options_[OPTION_ARROW_FOCUS] = tmp;
-      prefs.get("NativeFilechooser", tmp, 0); 
options_[OPTION_NATIVE_FILECHOOSER] = tmp;
+      opt.get("ArrowFocus", tmp, -1); if (tmp >= 0) 
options_[OPTION_ARROW_FOCUS] = tmp;
+      opt.get("NativeFilechooser", tmp, -1); if (tmp >= 0) 
options_[OPTION_NATIVE_FILECHOOSER] = tmp;
+
+#if 0  // for testing only
+       opt.set("ArrowFocus", 1);
+       opt.set("NativeFilechooser", 1);
+       opt.flush();
+       printf ("OPTIONS: ArrowFocus = %d, NativeFilechooser = 
%d\n",options_[0],options_[1]);
+#endif
+
     }
     { // now, if the developer has registered this app, we could as for 
per-application preferences
     }
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to