1998-10-21 20:29:01 +04:00
|
|
|
//
|
|
|
|
// Widget type header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2024-03-03 00:58:52 +03:00
|
|
|
// Copyright 1998-2024 by Bill Spitzak and others.
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// 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
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
#ifndef _FLUID_FL_TYPE_H
|
|
|
|
#define _FLUID_FL_TYPE_H
|
2021-10-17 13:24:39 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl_Widget.H>
|
2005-03-08 16:46:31 +03:00
|
|
|
#include <FL/fl_draw.H>
|
2021-10-17 13:24:39 +03:00
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
#include "code.h"
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
class Fl_Type;
|
2021-12-11 21:43:00 +03:00
|
|
|
class Fl_Group_Type;
|
|
|
|
class Fl_Window_Type;
|
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
class Fd_Project_Reader;
|
|
|
|
class Fd_Project_Writer;
|
|
|
|
|
2024-09-11 23:29:39 +03:00
|
|
|
/**
|
|
|
|
Declare where a new type is placed in the hierarchy.
|
|
|
|
|
|
|
|
Note that a type can also be the start of a hierarchy of types. In that case,
|
|
|
|
|
|
|
|
\see Fl_Type *Fl_..._Type::make(Strategy strategy) calls `add()`
|
|
|
|
Add single Type:
|
|
|
|
Fl_Type *add_new_widget_from_user(Fl_Type *inPrototype, Strategy strategy, bool and_open)
|
|
|
|
Fl_Type *add_new_widget_from_user(const char *inName, Strategy strategy, bool and_open)
|
|
|
|
Fl_Type *add_new_widget_from_file(const char *inName, Strategy strategy)
|
|
|
|
Add a hierarchy of Types
|
|
|
|
void Fl_Type::add(Fl_Type *p, Strategy strategy)
|
|
|
|
int read_file(const char *filename, int merge, Strategy strategy)
|
|
|
|
Fl_Type *Fd_Project_Reader::read_children(Fl_Type *p, int merge, Strategy strategy, char skip_options)
|
|
|
|
int Fd_Project_Reader::read_project(const char *filename, int merge, Strategy strategy)
|
|
|
|
*/
|
2021-12-11 21:43:00 +03:00
|
|
|
typedef enum {
|
|
|
|
kAddAsLastChild = 0,
|
|
|
|
kAddAfterCurrent
|
|
|
|
} Strategy;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2023-10-20 20:00:42 +03:00
|
|
|
enum ID {
|
|
|
|
// administrative
|
|
|
|
ID_Base_, ID_Widget_, ID_Menu_Manager_, ID_Menu_, ID_Browser_, ID_Valuator_,
|
|
|
|
// non-widget
|
|
|
|
ID_Function, ID_Code, ID_CodeBlock,
|
|
|
|
ID_Decl, ID_DeclBlock, ID_Class,
|
|
|
|
ID_Widget_Class, ID_Comment, ID_Data,
|
|
|
|
// groups
|
|
|
|
ID_Window, ID_Group, ID_Pack,
|
|
|
|
ID_Flex, ID_Tabs, ID_Scroll,
|
|
|
|
ID_Tile, ID_Wizard, ID_Grid,
|
|
|
|
// buttons
|
|
|
|
ID_Button, ID_Return_Button, ID_Light_Button,
|
|
|
|
ID_Check_Button, ID_Repeat_Button, ID_Round_Button,
|
|
|
|
// valuators
|
|
|
|
ID_Slider, ID_Scrollbar, ID_Value_Slider,
|
|
|
|
ID_Adjuster, ID_Counter, ID_Spinner,
|
|
|
|
ID_Dial, ID_Roller, ID_Value_Input, ID_Value_Output,
|
|
|
|
// text
|
|
|
|
ID_Input, ID_Output, ID_Text_Editor,
|
2023-11-15 15:02:48 +03:00
|
|
|
ID_Text_Display, ID_File_Input, ID_Terminal,
|
2023-10-20 20:00:42 +03:00
|
|
|
// menus
|
|
|
|
ID_Menu_Bar, ID_Menu_Button, ID_Choice,
|
|
|
|
ID_Input_Choice, ID_Submenu, ID_Menu_Item,
|
|
|
|
ID_Checkbox_Menu_Item, ID_Radio_Menu_Item,
|
|
|
|
// browsers
|
|
|
|
ID_Browser, ID_Check_Browser, ID_File_Browser,
|
|
|
|
ID_Tree, ID_Help_View, ID_Table,
|
|
|
|
// misc
|
|
|
|
ID_Box, ID_Clock, ID_Progress,
|
|
|
|
ID_Max_
|
|
|
|
};
|
|
|
|
|
2023-10-20 01:23:09 +03:00
|
|
|
void update_visibility_flag(Fl_Type *p);
|
2021-12-08 17:52:15 +03:00
|
|
|
void delete_all(int selected_only=0);
|
|
|
|
int storestring(const char *n, const char * & p, int nostrip=0);
|
2016-07-19 00:12:25 +03:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
void select_all_cb(Fl_Widget *,void *);
|
|
|
|
void select_none_cb(Fl_Widget *,void *);
|
|
|
|
void earlier_cb(Fl_Widget*,void*);
|
|
|
|
void later_cb(Fl_Widget*,void*);
|
2005-03-19 11:38:21 +03:00
|
|
|
|
2023-10-20 00:54:31 +03:00
|
|
|
/**
|
|
|
|
\brief This is the base class for all elements in the project tree.
|
|
|
|
|
|
|
|
All widgets and other types in the project are derived from Fl_Types. They
|
|
|
|
are organized in a doubly linked list. Every Type also has depth information
|
|
|
|
to create a pseudo tree structure. To make walking up the tree faster, Type
|
|
|
|
also holds a pointer to the `parent` Type.
|
|
|
|
|
|
|
|
Types can be identified using the builtin ID system that works like RTTI. The
|
|
|
|
method `id()` returns the exact type, and the method `is_a(ID)` returns true
|
|
|
|
if this is the exact type or derived from the type, and a dynamic cast will
|
|
|
|
work reliably.
|
|
|
|
|
|
|
|
\todo it would be nice if we can handle multiple independent trees. To do that
|
|
|
|
we must remove static members like `first` and `last`.
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2023-10-20 00:54:31 +03:00
|
|
|
\todo add virtual methods to handle events, draw widgets, and draw overlays.
|
|
|
|
It may also make sense to have a virtual method that returns a boolean if
|
|
|
|
a specific type can be added as a child.
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-10-20 00:54:31 +03:00
|
|
|
\todo it may make sense to have a readable iterator class instead of relying
|
|
|
|
on pointer manipulation. Or use std in future releases.
|
|
|
|
*/
|
|
|
|
class Fl_Type {
|
|
|
|
/** Copy the label text to Widgets and Windows, does nothing in Type. */
|
2021-12-08 17:52:15 +03:00
|
|
|
virtual void setlabel(const char *) { } // virtual part of label(char*)
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Fl_Type();
|
|
|
|
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Name of a widget, or code some non-widget Types. */
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *name_;
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Label text of a widget. */
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *label_;
|
2023-10-20 00:54:31 +03:00
|
|
|
/** If it is just a word, it's the name of the callback function. Otherwise
|
|
|
|
it is the full callback C++ code. Can be NULL. */
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *callback_;
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Widget user data field as C++ text. */
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *user_data_;
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Widget user data type as C++ text, usually `void*` or `long`. */
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *user_data_type_;
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Optional comment for every node in the graph. Visible in browser and
|
|
|
|
panels, and will also be copied to the source code. */
|
2008-09-18 02:43:15 +04:00
|
|
|
const char *comment_;
|
2023-10-26 01:38:58 +03:00
|
|
|
/** a unique ID within the project */
|
|
|
|
unsigned short uid_;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
public: // things that should not be public:
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Quick link to the parent Type instead of walking up the linked list. */
|
2021-12-11 21:43:00 +03:00
|
|
|
Fl_Type *parent;
|
2023-10-20 01:23:09 +03:00
|
|
|
/** This type is rendered "selected" in the tree browser. */
|
1998-10-06 22:21:25 +04:00
|
|
|
char new_selected; // browser highlight
|
2024-03-03 00:58:52 +03:00
|
|
|
/** Backup storage for selection if an error occurred during some operation
|
2023-10-20 01:23:09 +03:00
|
|
|
(see `haderror`). It seems that this is often confused with new_selected
|
|
|
|
which seems to hold the true and visible selection state. */
|
1998-10-06 22:21:25 +04:00
|
|
|
char selected; // copied here by selection_changed()
|
2020-07-01 19:03:10 +03:00
|
|
|
char open_; // state of triangle in browser
|
1998-10-06 22:21:25 +04:00
|
|
|
char visible; // true if all parents are open
|
2020-07-01 19:03:10 +03:00
|
|
|
int level; // number of parents over this
|
2021-12-11 21:43:00 +03:00
|
|
|
static Fl_Type *first, *last;
|
|
|
|
Fl_Type *next, *prev;
|
2022-02-14 00:01:16 +03:00
|
|
|
Fl_Type *prev_sibling();
|
|
|
|
Fl_Type *next_sibling();
|
|
|
|
Fl_Type *first_child();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
Fl_Type *factory;
|
2023-01-26 17:23:43 +03:00
|
|
|
const char *callback_name(Fd_Code_Writer& f);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2024-04-17 18:51:32 +03:00
|
|
|
// text positions of this type in code, header, and project file (see codeview)
|
2023-10-24 15:28:56 +03:00
|
|
|
int code_static_start, code_static_end;
|
|
|
|
int code1_start, code1_end;
|
|
|
|
int code2_start, code2_end;
|
2023-10-25 15:44:02 +03:00
|
|
|
int header1_start, header1_end;
|
|
|
|
int header2_start, header2_end;
|
2023-10-24 15:28:56 +03:00
|
|
|
int header_static_start, header_static_end;
|
|
|
|
int proj1_start, proj1_end;
|
|
|
|
int proj2_start, proj2_end;
|
2005-11-03 23:43:19 +03:00
|
|
|
|
2009-03-27 23:05:03 +03:00
|
|
|
protected:
|
|
|
|
int user_defined(const char* cbname) const;
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~Fl_Type();
|
2021-12-11 21:43:00 +03:00
|
|
|
virtual Fl_Type *make(Strategy strategy) = 0;
|
|
|
|
|
|
|
|
Fl_Window_Type *window();
|
|
|
|
Fl_Group_Type *group();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-12-11 21:43:00 +03:00
|
|
|
void add(Fl_Type *parent, Strategy strategy);
|
1998-10-06 22:21:25 +04:00
|
|
|
void insert(Fl_Type *n); // insert into list before n
|
2020-07-01 19:03:10 +03:00
|
|
|
Fl_Type* remove(); // remove from list
|
1998-10-06 22:21:25 +04:00
|
|
|
void move_before(Fl_Type*); // move before a sibling
|
|
|
|
|
|
|
|
virtual const char *title(); // string for browser
|
|
|
|
virtual const char *type_name() = 0; // type for code output
|
2009-10-02 23:08:55 +04:00
|
|
|
virtual const char *alt_type_name() { return type_name(); } // alternate type for FLTK2 code output
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
const char *name() const {return name_;}
|
|
|
|
void name(const char *);
|
|
|
|
const char *label() const {return label_;}
|
|
|
|
void label(const char *);
|
|
|
|
const char *callback() const {return callback_;}
|
|
|
|
void callback(const char *);
|
|
|
|
const char *user_data() const {return user_data_;}
|
|
|
|
void user_data(const char *);
|
|
|
|
const char *user_data_type() const {return user_data_type_;}
|
|
|
|
void user_data_type(const char *);
|
2008-09-18 02:43:15 +04:00
|
|
|
const char *comment() { return comment_; }
|
|
|
|
void comment(const char *);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
virtual Fl_Type* click_test(int,int) { return NULL; }
|
2023-11-14 20:14:48 +03:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
virtual void add_child(Fl_Type*, Fl_Type* beforethis) { }
|
|
|
|
virtual void move_child(Fl_Type*, Fl_Type* beforethis) { }
|
|
|
|
virtual void remove_child(Fl_Type*) { }
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2023-10-27 19:31:14 +03:00
|
|
|
/** Give widgets a change to arrange their children after all children were add.
|
|
|
|
If adding individual children, this is called immediately, but if children
|
|
|
|
are read via a project file, we wait until all children are read and then
|
|
|
|
lay out the group.
|
|
|
|
*/
|
|
|
|
virtual void layout_widget() { }
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
static Fl_Type *current; // most recently picked object
|
2021-12-11 21:43:00 +03:00
|
|
|
static Fl_Type *current_dnd;
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
virtual void open(); // what happens when you double-click
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// read and write data to a saved file:
|
2023-01-26 17:23:43 +03:00
|
|
|
virtual void write(Fd_Project_Writer &f);
|
|
|
|
virtual void write_properties(Fd_Project_Writer &f);
|
|
|
|
virtual void read_property(Fd_Project_Reader &f, const char *);
|
2023-10-21 14:18:50 +03:00
|
|
|
virtual void write_parent_properties(Fd_Project_Writer &f, Fl_Type *child, bool encapsulate);
|
2023-11-05 16:53:42 +03:00
|
|
|
virtual void read_parent_property(Fd_Project_Reader &f, Fl_Type *child, const char *property);
|
1998-10-06 22:21:25 +04:00
|
|
|
virtual int read_fdesign(const char*, const char*);
|
2022-11-01 15:30:05 +03:00
|
|
|
virtual void postprocess_read() { }
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// write code, these are called in order:
|
2023-01-26 17:23:43 +03:00
|
|
|
virtual void write_static(Fd_Code_Writer& f); // write static stuff to .c file
|
2024-04-25 18:52:32 +03:00
|
|
|
virtual void write_static_after(Fd_Code_Writer& f); // write static stuff after children
|
2023-01-26 17:23:43 +03:00
|
|
|
virtual void write_code1(Fd_Code_Writer& f); // code and .h before children
|
|
|
|
virtual void write_code2(Fd_Code_Writer& f); // code and .h after children
|
|
|
|
void write_comment_h(Fd_Code_Writer& f, const char *ind=""); // write the commentary text into the header file
|
|
|
|
void write_comment_c(Fd_Code_Writer& f, const char *ind=""); // write the commentary text into the source file
|
|
|
|
void write_comment_inline_c(Fd_Code_Writer& f, const char *ind=0L); // write the commentary text
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2005-07-08 18:12:00 +04:00
|
|
|
// live mode
|
2024-03-03 00:58:52 +03:00
|
|
|
virtual Fl_Widget *enter_live_mode(int top=0); // build widgets needed for live mode
|
2005-07-08 18:12:00 +04:00
|
|
|
virtual void leave_live_mode(); // free allocated resources
|
2024-03-03 00:58:52 +03:00
|
|
|
virtual void copy_properties(); // copy properties from this type into a potential live object
|
2005-07-08 18:12:00 +04:00
|
|
|
|
2000-05-16 16:26:07 +04:00
|
|
|
// get message number for I18N
|
|
|
|
int msgnum();
|
|
|
|
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Return 1 if the Type can have children. */
|
2024-09-11 16:00:48 +03:00
|
|
|
virtual int can_have_children() const {return 0;}
|
2023-07-19 21:41:58 +03:00
|
|
|
/** Return 1 if the type is a widget or menu item. */
|
2021-12-08 17:52:15 +03:00
|
|
|
virtual int is_widget() const {return 0;}
|
2023-07-19 21:41:58 +03:00
|
|
|
/** Return 1 if the type is a widget but not a menu item. */
|
|
|
|
virtual int is_true_widget() const {return 0;}
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Return 1 if a type behaves like a button (Fl_Button and Fl_Menu_Item and derived, but not Fl_Submenu_Type. */
|
2021-12-08 17:52:15 +03:00
|
|
|
virtual int is_button() const {return 0;}
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Return 1 if this is a Fl_Widget_Class_Type, Fl_CodeBlock_Type, or Fl_Function_Type */
|
2021-12-08 17:52:15 +03:00
|
|
|
virtual int is_code_block() const {return 0;}
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Return 1 if this is a Fl_Widget_Class_Type, Fl_Class_Type, or Fl_DeclBlock_Type */
|
2021-12-08 17:52:15 +03:00
|
|
|
virtual int is_decl_block() const {return 0;}
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Return 1 if this is a Fl_Class_Type or Fl_Widget_Class_Type. */
|
2021-12-08 17:52:15 +03:00
|
|
|
virtual int is_class() const {return 0;}
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Return 1 if the type browser shall draw a padlock over the icon. */
|
2021-12-08 17:52:15 +03:00
|
|
|
virtual int is_public() const {return 1;}
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Return the type ID for this Type. */
|
2023-07-17 21:40:55 +03:00
|
|
|
virtual ID id() const { return ID_Base_; }
|
2023-10-20 00:54:31 +03:00
|
|
|
/** Check if this Type is of the give type ID or derived from that type ID. */
|
2023-07-19 21:41:58 +03:00
|
|
|
virtual bool is_a(ID inID) const { return (inID==ID_Base_); }
|
2002-10-31 00:08:39 +03:00
|
|
|
|
2000-02-05 12:20:46 +03:00
|
|
|
const char* class_name(const int need_nest) const;
|
2023-10-20 00:54:31 +03:00
|
|
|
bool is_in_class() const;
|
|
|
|
|
|
|
|
int has_function(const char*, const char*) const;
|
2023-10-24 16:36:03 +03:00
|
|
|
|
2023-10-26 01:38:58 +03:00
|
|
|
unsigned short set_uid(unsigned short suggested_uid=0);
|
|
|
|
unsigned short get_uid() { return uid_; }
|
|
|
|
static Fl_Type *find_by_uid(unsigned short uid);
|
|
|
|
|
2023-10-24 16:36:03 +03:00
|
|
|
static Fl_Type *find_in_text(int text_type, int crsr);
|
2023-11-01 00:00:29 +03:00
|
|
|
|
|
|
|
/// If this is greater zero, widgets will be allowed to lay out their children.
|
|
|
|
static int allow_layout;
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
#endif // _FLUID_FL_TYPE_H
|