Skip to content

Commit

Permalink
FLUID: Minor fix and docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasWM committed Dec 22, 2024
1 parent 7d49c02 commit 89466c2
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions fluid/factory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// to a factory instance for every class (both the ones defined
// here and ones in other files)
//
// Copyright 1998-2023 by Bill Spitzak and others.
// Copyright 1998-2024 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
Expand Down Expand Up @@ -1116,6 +1116,9 @@ extern void select_only(Fl_Type *);
This is used to convert a type name into a pointer to the prototype.
This list may contain types that are supported in .fl files, but not
available in the *New* menu.
\note Make sure that this array stays synchronized to `Fl_Menu_Item New_Menu[]`
further down in this file.
*/
static Fl_Type *known_types[] = {
// functions
Expand Down Expand Up @@ -1203,6 +1206,8 @@ static Fl_Type *known_types[] = {
\param[in] inPrototype pointer to one of the FL_..._type prototype; note the
lower case 't' in type.
\param[in] strategy add after current or as last child
\param[in] and_open if set to true, call open() on the widget after creating it
\return the newly created type or NULL
\see add_new_widget_from_file(const char*, int)
add_new_widget_from_user(Fl_Type*, int)
Expand Down Expand Up @@ -1326,9 +1331,12 @@ Fl_Type *add_new_widget_from_user(Fl_Type *inPrototype, Strategy strategy, bool

/**
Create and add a new widget to the widget tree.
\param[in] inName find the right prototype by this name
\param[in] strategy where to add the node
\return the newly created node
\param[in] and_open if set to true, call open() on the widget after creating it
\return the newly created type or NULL
\see add_new_widget_from_file(const char*, int)
add_new_widget_from_user(Fl_Type*, int)
add_new_widget_from_user(const char*, int)
Expand All @@ -1355,6 +1363,9 @@ static void cbf(Fl_Widget *, void *v) {

/**
Callback for all widget menu items.
\param[in] v cast to Fl_Type to get the prototype of the type that the user
wants to create.
*/
static void cb(Fl_Widget *, void *v) {
Fl_Type *t = NULL;
Expand All @@ -1365,6 +1376,10 @@ static void cb(Fl_Widget *, void *v) {
select_only(t);
}

/**
\note Make sure that this menu stays synchronized to `Fl_Type *known_types[]`
defined further up in this file.
*/
Fl_Menu_Item New_Menu[] = {
{"Code",0,0,0,FL_SUBMENU},
{"Function/Method",0,cbf,(void*)&Fl_Function_type},
Expand Down Expand Up @@ -1471,6 +1486,11 @@ static void make_iconlabel(Fl_Menu_Item *mi, Fl_Image *ic, const char *txt)
}
}

/**
Create the labels and icons for the `New_Menu` array.
Names and icons are taken from the referenced prototypes.
*/
void fill_in_New_Menu() {
for (unsigned i = 0; i < sizeof(New_Menu)/sizeof(*New_Menu); i++) {
Fl_Menu_Item *m = New_Menu+i;
Expand Down Expand Up @@ -1523,10 +1543,10 @@ Fl_Type *typename_to_prototype(const char *inName)
add_new_widget_from_user(const char*, int)
*/
Fl_Type *add_new_widget_from_file(const char *inName, Strategy strategy) {
reading_file = 1; // makes labels be null
Fl_Type *prototype = typename_to_prototype(inName);
if (!prototype)
return NULL;
reading_file = 1; // makes labels be null
Fl_Type *new_node = prototype->make(strategy);
reading_file = 0;
return new_node;
Expand Down

0 comments on commit 89466c2

Please sign in to comment.