summaryrefslogtreecommitdiff
path: root/fluid/panels
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2025-12-06 02:29:57 +0100
committerMatthias Melcher <github@matthiasm.com>2025-12-06 02:29:57 +0100
commit5e7ed2f6534bf8d99688e375c56f44f792bdf7bb (patch)
treebd59017682dad0a5887faf4b6cfe0bc8389ca9c6 /fluid/panels
parentb2746ad28693d61cecaa1e9fb57ab93c0050e3d3 (diff)
Fluid: fix class prefix user input check.
Diffstat (limited to 'fluid/panels')
-rw-r--r--fluid/panels/widget_panel.cxx40
-rw-r--r--fluid/panels/widget_panel.fl48
2 files changed, 69 insertions, 19 deletions
diff --git a/fluid/panels/widget_panel.cxx b/fluid/panels/widget_panel.cxx
index 5bbde2fec..5556a19fa 100644
--- a/fluid/panels/widget_panel.cxx
+++ b/fluid/panels/widget_panel.cxx
@@ -31,6 +31,7 @@
#include <FL/fl_ask.H>
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl_File_Chooser.H>
+#include <ctype.h>
#define ZERO_ENTRY 1000
extern const char* when_symbol_name(int n);
extern void set_whenmenu(int n);
@@ -2636,11 +2637,10 @@ static void cb_Attribute(Fl_Input* o, void* v) {
Class_Node* nd = (Class_Node*)current_node;
if (v == LOAD) {
- o->value( nd->prefix() );
+ o->value( nd->prefix().c_str() );
} else {
- const char *nn = nd->prefix();
- if ( ( nn && (strcmp(nn, o->value()) != 0))
- || (!nn && (strcmp("", o->value()) != 0)) )
+ auto nn = nd->prefix();
+ if (nn != o->value())
{
nd->prefix( o->value() );
Fluid.proj.set_modflag(1);
@@ -2657,13 +2657,37 @@ static void cb_Class(Fl_Input* o, void* v) {
o->value( nd->name() );
} else {
const char *nn = nd->name();
- if ( ( nn && (strcmp(nn, o->value()) != 0))
- || (!nn && (strcmp("", o->value()) != 0)) )
+ char *nv = strdup( o->value() );
+ // There is an inconsistency in the project file reader, so this string
+ // must not coantain anything but alphanumeric and underscore characters.
+ char *s = (char*)nv;
+ char *d = (char*)nv;
+ while (*s) {
+ if (isalnum((unsigned char)*s) || *s == '_') {
+ *d++ = *s;
+ }
+ s++;
+ }
+ *d = 0;
+ // The class name must not be empty either
+ if (*nv == 0) {
+ free((void*)nv);
+ nv = strdup("MyClass");
+ }
+ // The class name may have changed, so update the widget
+ o->value( nv );
+ // Now copy the new name into the node if it changed
+ if ( ( nn && (strcmp(nn, nv) != 0))
+ || (!nn && (strcmp("", nv) != 0)) )
{
- nd->name( o->value() );
+ nd->name( nv );
Fluid.proj.set_modflag(1);
redraw_browser();
}
+ // Don't forget to clean up
+ if (nv) {
+ free((void*)nv);
+ }
}
}
@@ -3239,6 +3263,7 @@ Fl_Double_Window* make_widget_panel() {
widget_tabs->labelcolor(FL_BACKGROUND2_COLOR);
widget_tabs->callback((Fl_Callback*)cb_widget_tabs);
widget_tabs->when(FL_WHEN_NEVER);
+ widget_tabs->hide();
{ wp_gui_tab = new Fl_Group(10, 30, 400, 330, "GUI");
wp_gui_tab->labelsize(11);
wp_gui_tab->callback((Fl_Callback*)propagate_load);
@@ -4326,7 +4351,6 @@ Fl_Double_Window* make_widget_panel() {
class_tabs->labelsize(11);
class_tabs->labelcolor(FL_WHITE);
class_tabs->callback((Fl_Callback*)cb_class_tabs);
- class_tabs->hide();
{ class_tabs_main = new Fl_Group(10, 30, 400, 330, "Class");
class_tabs_main->labelsize(11);
class_tabs_main->callback((Fl_Callback*)propagate_load);
diff --git a/fluid/panels/widget_panel.fl b/fluid/panels/widget_panel.fl
index beba75690..17c545d15 100644
--- a/fluid/panels/widget_panel.fl
+++ b/fluid/panels/widget_panel.fl
@@ -80,6 +80,9 @@ decl {\#include <FL/Fl_Menu_Item.H>} {private global
decl {\#include <FL/Fl_File_Chooser.H>} {private global
}
+decl {\#include <ctype.h>} {selected private global
+}
+
decl {\#define ZERO_ENTRY 1000} {private global
}
@@ -486,8 +489,8 @@ Function {make_widget_panel()} {
} {
Fl_Tabs widget_tabs {
callback {if (current_widget)
- propagate_load((Fl_Group *)o,v);} selected
- xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 7 when 0
+ propagate_load((Fl_Group *)o,v);}
+ xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 7 when 0 hide
code0 {o->show();}
} {
Fl_Group wp_gui_tab {
@@ -2972,8 +2975,8 @@ if (v == LOAD) {
}
Fl_Tabs class_tabs {
callback {if (current_node && current_node->is_a(Type::Class))
- propagate_load((Fl_Group *)o,v);}
- xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 255 hide
+ propagate_load((Fl_Group *)o,v);} open
+ xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 255
} {
Fl_Group class_tabs_main {
label Class
@@ -3032,11 +3035,10 @@ if (v == LOAD) {
Class_Node* nd = (Class_Node*)current_node;
if (v == LOAD) {
- o->value( nd->prefix() );
+ o->value( nd->prefix().c_str() );
} else {
- const char *nn = nd->prefix();
- if ( ( nn && (strcmp(nn, o->value()) != 0))
- || (!nn && (strcmp("", o->value()) != 0)) )
+ auto nn = nd->prefix();
+ if (nn != o->value())
{
nd->prefix( o->value() );
Fluid.proj.set_modflag(1);
@@ -3054,13 +3056,37 @@ if (v == LOAD) {
o->value( nd->name() );
} else {
const char *nn = nd->name();
- if ( ( nn && (strcmp(nn, o->value()) != 0))
- || (!nn && (strcmp("", o->value()) != 0)) )
+ char *nv = strdup( o->value() );
+ // There is an inconsistency in the project file reader, so this string
+ // must not coantain anything but alphanumeric and underscore characters.
+ char *s = (char*)nv;
+ char *d = (char*)nv;
+ while (*s) {
+ if (isalnum((unsigned char)*s) || *s == '_') {
+ *d++ = *s;
+ }
+ s++;
+ }
+ *d = 0;
+ // The class name must not be empty either
+ if (*nv == 0) {
+ free((void*)nv);
+ nv = strdup("MyClass");
+ }
+ // The class name may have changed, so update the widget
+ o->value( nv );
+ // Now copy the new name into the node if it changed
+ if ( ( nn && (strcmp(nn, nv) != 0))
+ || (!nn && (strcmp("", nv) != 0)) )
{
- nd->name( o->value() );
+ nd->name( nv );
Fluid.proj.set_modflag(1);
redraw_browser();
}
+ // Don't forget to clean up
+ if (nv) {
+ free((void*)nv);
+ }
}}
tooltip {class name, must be a single C++ keyword} xywh {95 75 305 20} labelfont 1 labelsize 11 textfont 4 textsize 11
}