summaryrefslogtreecommitdiff
path: root/fluid
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-01-01 21:53:07 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-01-12 19:21:09 +0100
commitbafd3fd3d792b530d39d3af06e087dc63d2a25a2 (patch)
tree42f4d533490191a92a13863d07378820b04a7b9c /fluid
parent79832b679f2d195eb3b0f30ca920a857cc133b2b (diff)
Add Fl_Scheme_Choice widget and use it in test programs
This widget offers the selection of all known FLTK schemes as a simple widget based on Fl_Choice. Some test and demo programs use Fl_Scheme_Choice to enable the developer or user to switch schemes quickly for comparison. Todo: - add features to add new schemes during runtime (partially done) - update status when the scheme is changed by Fl::scheme("...")
Diffstat (limited to 'fluid')
-rw-r--r--fluid/alignment_panel.cxx32
-rw-r--r--fluid/alignment_panel.fl51
-rw-r--r--fluid/alignment_panel.h12
-rw-r--r--fluid/fluid.cxx94
4 files changed, 106 insertions, 83 deletions
diff --git a/fluid/alignment_panel.cxx b/fluid/alignment_panel.cxx
index e742640ce..dfe69d114 100644
--- a/fluid/alignment_panel.cxx
+++ b/fluid/alignment_panel.cxx
@@ -179,21 +179,11 @@ nalize labels and tooltips, usually \"gettext_noop\" or \"N_\"");
} // Fl_Double_Window* project_window
return project_window;
}
-void scheme_cb(Fl_Choice *, void *);
+void scheme_cb(Fl_Scheme_Choice *, void *);
Fl_Double_Window *settings_window=(Fl_Double_Window *)0;
-Fl_Choice *scheme_choice=(Fl_Choice *)0;
-
-Fl_Menu_Item menu_scheme_choice[] = {
- {"Default", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
- {"None", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
- {"Plastic", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
- {"GTK+", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
- {"Gleam", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
- {"Oxy", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
- {0,0,0,0,0,0,0,0,0}
-};
+Fl_Scheme_Choice *scheme_choice=(Fl_Scheme_Choice *)0;
Fl_Check_Button *tooltips_button=(Fl_Check_Button *)0;
@@ -258,16 +248,20 @@ static void cb_Close1(Fl_Button*, void*) {
Fl_Double_Window* make_settings_window() {
{ Fl_Double_Window* o = settings_window = new Fl_Double_Window(360, 355, "GUI Settings");
- { scheme_choice = new Fl_Choice(140, 10, 115, 25, "Scheme: ");
+ { scheme_choice = new Fl_Scheme_Choice(140, 10, 115, 25, "Scheme: ");
+ scheme_choice->box(FL_FLAT_BOX);
scheme_choice->down_box(FL_BORDER_BOX);
+ scheme_choice->color(FL_BACKGROUND_COLOR);
+ scheme_choice->selection_color(FL_SELECTION_COLOR);
+ scheme_choice->labeltype(FL_NORMAL_LABEL);
scheme_choice->labelfont(1);
+ scheme_choice->labelsize(14);
+ scheme_choice->labelcolor(FL_FOREGROUND_COLOR);
scheme_choice->callback((Fl_Callback*)scheme_cb);
- scheme_choice->menu(menu_scheme_choice);
- int s;
- fluid_prefs.get("scheme", s, 0);
- scheme_choice->value(s);
- scheme_cb(0, 0);
- } // Fl_Choice* scheme_choice
+ scheme_choice->align(Fl_Align(FL_ALIGN_LEFT));
+ scheme_choice->when(FL_WHEN_RELEASE);
+ init_scheme();
+ } // Fl_Scheme_Choice* scheme_choice
{ Fl_Group* o = new Fl_Group(20, 43, 330, 161);
o->labelfont(1);
o->align(Fl_Align(FL_ALIGN_CENTER));
diff --git a/fluid/alignment_panel.fl b/fluid/alignment_panel.fl
index 4e016220e..4525704ed 100644
--- a/fluid/alignment_panel.fl
+++ b/fluid/alignment_panel.fl
@@ -38,6 +38,9 @@ decl {\#include <FL/Fl_Text_Display.H>} {public local
decl {\#include <FL/filename.H>} {public local
}
+decl {\#include <FL/Fl_Scheme_Choice.H>} {public local
+}
+
decl {\#include <FL/Fl_Preferences.H>} {private global
}
@@ -47,11 +50,14 @@ decl {\#include <FL/fl_ask.H>} {private global
decl {\#include <string.h>} {private global
}
+decl {void init_scheme(void);} {
+ comment {// initialize the scheme from preferences} selected public global
+}
+
decl {extern struct Fl_Menu_Item *dbmanager_item;} {public local
}
-Function {make_project_window()} {open
-} {
+Function {make_project_window()} {} {
Fl_Window project_window {
label {Project Settings} open
xywh {472 246 399 298} type Double hide
@@ -168,50 +174,23 @@ set_modflag(-1, -1);}
decl {extern void i18n_cb(Fl_Choice *,void *);} {public local
}
-decl {void scheme_cb(Fl_Choice *, void *);} {public local
+decl {void scheme_cb(Fl_Scheme_Choice *, void *);} {public local
}
Function {make_settings_window()} {open
} {
Fl_Window settings_window {
- label {GUI Settings}
- xywh {442 538 360 355} type Double hide resizable
+ label {GUI Settings} open
+ xywh {701 666 360 355} type Double hide resizable
code0 {o->size_range(o->w(), o->h());} non_modal
} {
Fl_Choice scheme_choice {
label {Scheme: }
callback scheme_cb open
xywh {140 10 115 25} down_box BORDER_BOX labelfont 1
- code0 {int s;}
- code1 {fluid_prefs.get("scheme", s, 0);}
- code2 {scheme_choice->value(s);}
- code3 {scheme_cb(0, 0);}
- } {
- MenuItem {} {
- label Default
- xywh {0 0 35 25}
- }
- MenuItem {} {
- label None
- xywh {0 0 35 25}
- }
- MenuItem {} {
- label Plastic
- xywh {0 0 35 25}
- }
- MenuItem {} {
- label {GTK+}
- xywh {10 10 35 25}
- }
- MenuItem {} {
- label Gleam
- xywh {20 20 35 25}
- }
- MenuItem {} {
- label Oxy
- xywh {30 30 35 25}
- }
- }
+ code0 {init_scheme();}
+ class Fl_Scheme_Choice
+ } {}
Fl_Group {} {open
xywh {20 43 330 161} labelfont 1 align 0
} {
@@ -327,7 +306,7 @@ Function {make_shell_window()} {open
tooltip {save the design to the .fl file before running the command} xywh {82 39 136 19} down_box DOWN_BOX labelsize 12
}
Fl_Check_Button shell_writecode_button {
- label {save source code} selected
+ label {save source code}
tooltip {generate the source code and header file before running the command} xywh {82 59 120 19} down_box DOWN_BOX labelsize 12
}
Fl_Check_Button shell_writemsgs_button {
diff --git a/fluid/alignment_panel.h b/fluid/alignment_panel.h
index 5f6e35e74..845260289 100644
--- a/fluid/alignment_panel.h
+++ b/fluid/alignment_panel.h
@@ -25,6 +25,11 @@
#include <FL/Fl_Text_Buffer.H>
#include <FL/Fl_Text_Display.H>
#include <FL/filename.H>
+#include <FL/Fl_Scheme_Choice.H>
+/**
+ // initialize the scheme from preferences
+*/
+void init_scheme(void);
extern struct Fl_Menu_Item *dbmanager_item;
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Preferences.H>
@@ -63,10 +68,10 @@ extern Fl_Input *i18n_static_function_input;
Fl_Double_Window* make_project_window();
extern Fl_Menu_Item menu_i18n_type_chooser[];
extern void i18n_cb(Fl_Choice *,void *);
-extern void scheme_cb(Fl_Choice *, void *);
+extern void scheme_cb(Fl_Scheme_Choice *, void *);
extern Fl_Double_Window *settings_window;
-extern void scheme_cb(Fl_Choice*, void*);
-extern Fl_Choice *scheme_choice;
+extern void scheme_cb(Fl_Scheme_Choice*, void*);
+extern Fl_Scheme_Choice *scheme_choice;
extern Fl_Check_Button *tooltips_button;
extern Fl_Check_Button *completion_button;
extern Fl_Check_Button *openlast_button;
@@ -77,7 +82,6 @@ extern Fl_Spinner *recent_spinner;
extern Fl_Check_Button *use_external_editor_button;
extern Fl_Input *editor_command_input;
Fl_Double_Window* make_settings_window();
-extern Fl_Menu_Item menu_scheme_choice[];
extern Fl_Double_Window *shell_window;
extern Fl_Input *shell_command_input;
extern Fl_Check_Button *shell_savefl_button;
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx
index 62c3e9636..47266b63f 100644
--- a/fluid/fluid.cxx
+++ b/fluid/fluid.cxx
@@ -1475,34 +1475,80 @@ Fl_Menu_Item Main_Menu[] = {
/**
Change the app's and hence preview the design's scheme.
- The scheme setting is stored inthe app preferences.
+
+ The scheme setting is stored in the app preferences
+ - in key \p 'scheme_name' since 1.4.0
+ - in key \p 'scheme' (index: 0 - 4) in 1.3.x
+
+ This callback is triggered by changing the scheme in the
+ Fl_Scheme_Choice widget (\p Edit/GUI Settings).
+
+ \see init_scheme() for choice values and backwards compatibility
*/
-void scheme_cb(Fl_Choice *, void *) {
+void scheme_cb(Fl_Scheme_Choice *choice, void *) {
if (batch_mode)
return;
- switch (scheme_choice->value()) {
- case 0 : // Default
- Fl::scheme(NULL);
- break;
- case 1 : // None
- Fl::scheme("none");
- break;
- case 2 : // Plastic
- Fl::scheme("plastic");
- break;
- case 3 : // GTK+
- Fl::scheme("gtk+");
- break;
- case 4 : // Gleam
- Fl::scheme("gleam");
- break;
- case 5 : // Oxy
- Fl::scheme("oxy");
- break;
- }
-
- fluid_prefs.set("scheme", scheme_choice->value());
+ // set the new scheme only if the scheme was changed
+ const char *new_scheme = choice->text(choice->value());
+
+ if (Fl::is_scheme(new_scheme))
+ return;
+
+ Fl::scheme(new_scheme);
+ fluid_prefs.set("scheme_name", new_scheme);
+
+ // Backwards compatibility: store 1.3 scheme index (1-4).
+ // We assume that index 0-3 (base, plastic, gtk+, gleam) are in the
+ // same order as in 1.3.x (index 1-4), higher values are ignored
+
+ int scheme_index = scheme_choice->value();
+ if (scheme_index <= 3) // max. index for 1.3.x (Gleam)
+ fluid_prefs.set("scheme", scheme_index + 1); // compensate for different indexing
+}
+
+/**
+ Read Fluid's scheme preferences and set the app's scheme.
+
+ Since FLTK 1.4.0 the scheme \b name is stored as a character string
+ with key "scheme_name" in the preference database.
+
+ In FLTK 1.3.x the scheme preference was stored as an integer index
+ with key "scheme" in the database. The known schemes were hardcoded in
+ Fluid's sources (here for reference):
+
+ | Index | 1.3 Scheme Name | Choice | 1.4 Scheme Name |
+ |-------|-----------------|-------|-----------------|
+ | 0 | Default (same as None) | n/a | n/a |
+ | 1 | None (same as Default) | 0 | base |
+ | 2 | Plastic | 1 | plastic |
+ | 3 | GTK+ | 2 | gtk+ |
+ | 4 | Gleam | 3 | gleam |
+ | n/a | n/a | 4 | oxy |
+
+ The new Fluid tries to keep backwards compatibility and reads both
+ keys (\p scheme and \p scheme_name). If the latter is defined, it is used.
+ If not the old \p scheme (index) is used - but we need to subtract one to
+ get the new Fl_Scheme_Choice index (column "Choice" above).
+*/
+void init_scheme() {
+ int scheme_index = 0; // scheme index for backwards compatibility (1.3.x)
+ char *scheme_name; // scheme name since 1.4.0
+ fluid_prefs.get("scheme_name", scheme_name, "XXX"); // XXX means: not set => fallback 1.3.x
+ if (!strcmp(scheme_name, "XXX")) {
+ fluid_prefs.get("scheme", scheme_index, 0);
+ if (scheme_index > 0) {
+ scheme_index--;
+ scheme_choice->value(scheme_index); // set the choice value
+ }
+ if (scheme_index < 0)
+ scheme_index = 0;
+ else if (scheme_index > scheme_choice->size() - 1)
+ scheme_index = 0;
+ scheme_name = const_cast<char *>(scheme_choice->text(scheme_index));
+ fluid_prefs.set("scheme_name", scheme_name);
+ }
+ Fl::scheme(scheme_name);
}
/**