Fl_Type.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. //
  2. // "$Id: Fl_Type.h 10093 2014-02-04 00:34:41Z AlbrechtS $"
  3. //
  4. // Widget type header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Each object described by Fluid is one of these objects. They
  7. // are all stored in a double-linked list.
  8. //
  9. // There is also a single "factory" instance of each type of this.
  10. // The method "make()" is called on this factory to create a new
  11. // instance of this object. It could also have a "copy()" function,
  12. // but it was easier to implement this by using the file read/write
  13. // that is needed to save the setup anyways.
  14. //
  15. // Copyright 1998-2010 by Bill Spitzak and others.
  16. //
  17. // This library is free software. Distribution and use rights are outlined in
  18. // the file "COPYING" which should have been included with this file. If this
  19. // file is missing or damaged, see the license at:
  20. //
  21. // http://www.fltk.org/COPYING.php
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. #include <FL/Fl_Widget.H>
  28. #include <FL/Fl_Menu.H>
  29. #include <FL/Fl_Window.H>
  30. #include <FL/Fl_Plugin.H>
  31. #include "Fluid_Image.h"
  32. #include <FL/fl_draw.H>
  33. void set_modflag(int mf);
  34. class Fl_Type {
  35. friend class Widget_Browser;
  36. friend Fl_Widget *make_type_browser(int,int,int,int,const char *l=0);
  37. friend class Fl_Window_Type;
  38. virtual void setlabel(const char *); // virtual part of label(char*)
  39. protected:
  40. Fl_Type();
  41. const char *name_;
  42. const char *macro_name_;
  43. const char *dirty_name_;
  44. const char *label_;
  45. const char *callback_;
  46. const char *user_data_;
  47. const char *user_data_type_;
  48. const char *comment_;
  49. public: // things that should not be public:
  50. Fl_Type *parent; // parent, which is previous in list
  51. char new_selected; // browser highlight
  52. char selected; // copied here by selection_changed()
  53. char open_; // state of triangle in browser
  54. char visible; // true if all parents are open
  55. char rtti; // hack because I have no rtti, this is 0 for base class
  56. int level; // number of parents over this
  57. static Fl_Type *first, *last; // linked list of all objects
  58. Fl_Type *next, *prev; // linked list of all objects
  59. Fl_Type *factory;
  60. const char *callback_name();
  61. int code_position, header_position;
  62. int code_position_end, header_position_end;
  63. protected:
  64. int user_defined(const char* cbname) const;
  65. public:
  66. virtual ~Fl_Type();
  67. virtual Fl_Type *make() = 0;
  68. void add(Fl_Type *parent); // add as new child
  69. void insert(Fl_Type *n); // insert into list before n
  70. Fl_Type* remove(); // remove from list
  71. void move_before(Fl_Type*); // move before a sibling
  72. virtual const char *title(); // string for browser
  73. virtual const char *type_name() = 0; // type for code output
  74. virtual const char *alt_type_name() { return type_name(); } // alternate type for FLTK2 code output
  75. const char *name() const {return name_;}
  76. void name(const char *);
  77. const char *macro_name() const {return macro_name_;}
  78. void macro_name(const char *);
  79. const char *macro_name2name();
  80. const char *dirty_name() const {return dirty_name_;}
  81. void dirty_name(const char *);
  82. const char *label() const {return label_;}
  83. void label(const char *);
  84. const char *callback() const {return callback_;}
  85. void callback(const char *);
  86. const char *user_data() const {return user_data_;}
  87. void user_data(const char *);
  88. const char *user_data_type() const {return user_data_type_;}
  89. void user_data_type(const char *);
  90. const char *comment() { return comment_; }
  91. void comment(const char *);
  92. virtual Fl_Type* click_test(int,int);
  93. virtual void add_child(Fl_Type*, Fl_Type* beforethis);
  94. virtual void move_child(Fl_Type*, Fl_Type* beforethis);
  95. virtual void remove_child(Fl_Type*);
  96. static Fl_Type *current; // most recently picked object
  97. virtual void open(); // what happens when you double-click
  98. // read and write data to a saved file:
  99. void write();
  100. virtual void write_properties();
  101. virtual void read_property(const char *);
  102. virtual int read_fdesign(const char*, const char*);
  103. // write code, these are called in order:
  104. virtual void write_static(); // write static stuff to .c file
  105. virtual void write_code1(); // code and .h before children
  106. virtual void write_code2(); // code and .h after children
  107. void write_comment_h(const char *ind=""); // write the commentary text into the header file
  108. void write_comment_c(const char *ind=""); // write the commentary text into the source file
  109. // live mode
  110. virtual Fl_Widget *enter_live_mode(int top=0); // build wdgets needed for live mode
  111. virtual void leave_live_mode(); // free allocated resources
  112. virtual void copy_properties(); // copy properties from this type into a potetial live object
  113. // get message number for I18N
  114. int msgnum();
  115. // fake rtti:
  116. virtual int is_parent() const;
  117. virtual int is_widget() const;
  118. virtual int is_button() const;
  119. virtual int is_input() const;
  120. virtual int is_value_input() const;
  121. virtual int is_text_display() const;
  122. virtual int is_valuator() const;
  123. virtual int is_spinner() const;
  124. virtual int is_menu_item() const;
  125. virtual int is_menu_button() const;
  126. virtual int is_group() const;
  127. virtual int is_window() const;
  128. virtual int is_code_block() const;
  129. virtual int is_decl_block() const;
  130. virtual int is_comment() const;
  131. virtual int is_class() const;
  132. virtual int is_public() const;
  133. virtual int pixmapID() { return 0; }
  134. const char* class_name(const int need_nest) const;
  135. const class Fl_Class_Type* is_in_class() const;
  136. };
  137. class Fl_Function_Type : public Fl_Type {
  138. const char* return_type;
  139. char public_, cdecl_, constructor, havewidgets;
  140. public:
  141. Fl_Function_Type() :
  142. Fl_Type(),
  143. return_type(0L), public_(0), cdecl_(0), constructor(0), havewidgets(0)
  144. { }
  145. ~Fl_Function_Type() {
  146. if (return_type) free((void*)return_type);
  147. }
  148. Fl_Type *make();
  149. void write_code1();
  150. void write_code2();
  151. void open();
  152. int ismain() {return name_ == 0;}
  153. virtual const char *type_name() {return "Function";}
  154. virtual const char *title() {
  155. return name() ? name() : "main()";
  156. }
  157. int is_parent() const {return 1;}
  158. int is_code_block() const {return 1;}
  159. virtual int is_public() const;
  160. int pixmapID() { return 7; }
  161. void write_properties();
  162. void read_property(const char *);
  163. int has_signature(const char *, const char*) const;
  164. const char * rtype() {return return_type;};
  165. };
  166. class Fl_Code_Type : public Fl_Type {
  167. public:
  168. Fl_Type *make();
  169. void write_code1();
  170. void write_code2();
  171. void open();
  172. virtual const char *type_name() {return "code";}
  173. int is_code_block() const {return 0;}
  174. int pixmapID() { return 8; }
  175. virtual int is_public() const;
  176. };
  177. class Fl_CodeBlock_Type : public Fl_Type {
  178. const char* after;
  179. public:
  180. Fl_CodeBlock_Type() : Fl_Type(), after(0L) { }
  181. ~Fl_CodeBlock_Type() {
  182. if (after) free((void*)after);
  183. }
  184. Fl_Type *make();
  185. void write_code1();
  186. void write_code2();
  187. void open();
  188. virtual const char *type_name() {return "codeblock";}
  189. int is_code_block() const {return 1;}
  190. int is_parent() const {return 1;}
  191. virtual int is_public() const;
  192. int pixmapID() { return 9; }
  193. void write_properties();
  194. void read_property(const char *);
  195. };
  196. class Fl_Decl_Type : public Fl_Type {
  197. protected:
  198. char public_;
  199. char static_;
  200. bool has_initialization_;
  201. public:
  202. Fl_Type *make();
  203. void write_code1();
  204. void write_code2();
  205. void open();
  206. virtual const char *type_name() {return "decl";}
  207. void write_properties();
  208. void read_property(const char *);
  209. virtual int is_public() const;
  210. int pixmapID() { return 10; }
  211. };
  212. class Fl_Data_Type : public Fl_Decl_Type {
  213. const char *filename_;
  214. public:
  215. Fl_Data_Type() : Fl_Decl_Type(), filename_(0L) { }
  216. ~Fl_Data_Type() {
  217. if (filename_) free((void*)filename_);
  218. }
  219. Fl_Type *make();
  220. void write_code1();
  221. void write_code2();
  222. void open();
  223. virtual const char *type_name() {return "data";}
  224. void write_properties();
  225. void read_property(const char *);
  226. int pixmapID() { return 49; }
  227. };
  228. class Fl_Block_Type : public Fl_Type {
  229. FILE *global_out, *block_out;
  230. const char* file_name;
  231. const char* after;
  232. const char* before;
  233. char public_;
  234. public:
  235. Fl_Block_Type():Fl_Type(){
  236. file_name = NULL;
  237. after = NULL;
  238. before = NULL;
  239. }
  240. ~Fl_Block_Type(){
  241. if(file_name) free((void*)file_name);
  242. if(after) free((void*)after);
  243. if(before) free((void*)before);
  244. }
  245. Fl_Type *make();
  246. void write_code1();
  247. void write_code2();
  248. void open();
  249. virtual const char *type_name() {return "block";}
  250. void write_properties();
  251. void read_property(const char *);
  252. int is_parent() const {return 1;}
  253. int is_decl_block() const {return 1;}
  254. virtual int is_public() const;
  255. int pixmapID() { return 11; }
  256. const char* get_file_name() {return file_name;};
  257. };
  258. class Fl_DeclBlock_Type : public Fl_Type {
  259. const char* after;
  260. char public_;
  261. public:
  262. Fl_DeclBlock_Type() : Fl_Type(), after(0L) { }
  263. ~Fl_DeclBlock_Type() {
  264. if (after) free((void*)after);
  265. }
  266. Fl_Type *make();
  267. void write_code1();
  268. void write_code2();
  269. void open();
  270. virtual const char *type_name() {return "declblock";}
  271. void write_properties();
  272. void read_property(const char *);
  273. int is_parent() const {return 1;}
  274. int is_decl_block() const {return 1;}
  275. virtual int is_public() const;
  276. int pixmapID() { return 11; }
  277. };
  278. class Fl_Comment_Type : public Fl_Type {
  279. char in_c_, in_h_, style_;
  280. char title_buf[64];
  281. public:
  282. Fl_Type *make();
  283. void write_code1();
  284. void write_code2();
  285. void open();
  286. virtual const char *type_name() {return "comment";}
  287. virtual const char *title(); // string for browser
  288. void write_properties();
  289. void read_property(const char *);
  290. virtual int is_public() const { return 1; }
  291. virtual int is_comment() const { return 1; }
  292. int pixmapID() { return 46; }
  293. };
  294. class Fl_Class_Type : public Fl_Type {
  295. const char* subclass_of;
  296. char public_;
  297. public:
  298. Fl_Class_Type() : Fl_Type(), subclass_of(0L) { }
  299. ~Fl_Class_Type() {
  300. if (subclass_of) free((void*)subclass_of);
  301. }
  302. // state variables for output:
  303. char write_public_state; // true when public: has been printed
  304. Fl_Class_Type* parent_class; // save class if nested
  305. //
  306. Fl_Type *make();
  307. void write_code1();
  308. void write_code2();
  309. void open();
  310. virtual const char *type_name() {return "class";}
  311. int is_parent() const {return 1;}
  312. int is_decl_block() const {return 1;}
  313. int is_class() const {return 1;}
  314. virtual int is_public() const;
  315. int pixmapID() { return 12; }
  316. void write_properties();
  317. void read_property(const char *);
  318. // class prefix attribute access
  319. void prefix(const char* p);
  320. const char* prefix() const {return class_prefix;}
  321. int has_function(const char*, const char*) const;
  322. private:
  323. const char* class_prefix;
  324. };
  325. #define NUM_EXTRA_CODE 6
  326. #define NUM_EXTRA_CODE_STD 4
  327. class Fl_Widget_Type : public Fl_Type {
  328. virtual Fl_Widget *widget(int,int,int,int) = 0;
  329. virtual Fl_Widget_Type *_make() = 0; // virtual constructor
  330. virtual void setlabel(const char *);
  331. const char *extra_code_[NUM_EXTRA_CODE];
  332. const char *subclass_;
  333. const char *tooltip_;
  334. const char *image_name_;
  335. const char *inactive_name_;
  336. uchar hotspot_;
  337. protected:
  338. void write_static();
  339. void write_code1();
  340. void write_widget_code();
  341. void write_extra_code_num(int n);
  342. void write_extra_code();
  343. void write_block_close();
  344. void write_code2();
  345. void write_color(const char*, Fl_Color);
  346. Fl_Widget *live_widget;
  347. public:
  348. static int default_size;
  349. const char *xclass; // junk string, used for shortcut
  350. Fl_Widget *o;
  351. int public_;
  352. Fluid_Image *image;
  353. void setimage(Fluid_Image *);
  354. Fluid_Image *inactive;
  355. void setinactive(Fluid_Image *);
  356. Fl_Widget_Type();
  357. Fl_Type *make();
  358. void open();
  359. const char *extra_code(int n) const {return extra_code_[n];}
  360. void extra_code(int n,const char *);
  361. const char *subclass() const {return subclass_;}
  362. void subclass(const char *);
  363. const char *tooltip() const {return tooltip_;}
  364. void tooltip(const char *);
  365. const char *image_name() const {return image_name_;}
  366. void image_name(const char *);
  367. const char *inactive_name() const {return inactive_name_;}
  368. void inactive_name(const char *);
  369. uchar hotspot() const {return hotspot_;}
  370. void hotspot(uchar v) {hotspot_ = v;}
  371. uchar resizable() const;
  372. void resizable(uchar v);
  373. virtual int textstuff(int what, Fl_Font &, int &, Fl_Color &);
  374. virtual Fl_Menu_Item *subtypes();
  375. virtual int is_widget() const;
  376. virtual int is_public() const;
  377. virtual void write_properties();
  378. virtual void read_property(const char *);
  379. virtual int read_fdesign(const char*, const char*);
  380. virtual Fl_Widget *enter_live_mode(int top=0);
  381. virtual void leave_live_mode();
  382. virtual void copy_properties();
  383. virtual void ideal_size(int &w, int &h);
  384. virtual void ideal_spacing(int &x, int &y);
  385. ~Fl_Widget_Type();
  386. void redraw();
  387. };
  388. #include <FL/Fl_Tabs.H>
  389. #include <FL/Fl_Pack.H>
  390. #include <FL/Fl_Wizard.H>
  391. class igroup : public Fl_Group {
  392. public:
  393. void resize(int,int,int,int);
  394. void full_resize(int X, int Y, int W, int H) { Fl_Group::resize(X, Y, W, H); }
  395. igroup(int X,int Y,int W,int H) : Fl_Group(X,Y,W,H) {Fl_Group::current(0);}
  396. };
  397. class itabs : public Fl_Tabs {
  398. public:
  399. void resize(int,int,int,int);
  400. void full_resize(int X, int Y, int W, int H) { Fl_Group::resize(X, Y, W, H); }
  401. itabs(int X,int Y,int W,int H) : Fl_Tabs(X,Y,W,H) {}
  402. };
  403. class iwizard : public Fl_Wizard {
  404. public:
  405. void resize(int,int,int,int);
  406. void full_resize(int X, int Y, int W, int H) { Fl_Group::resize(X, Y, W, H); }
  407. iwizard(int X,int Y,int W,int H) : Fl_Wizard(X,Y,W,H) {}
  408. };
  409. class Fl_Group_Type : public Fl_Widget_Type {
  410. public:
  411. virtual const char *type_name() {return "Fl_Group";}
  412. virtual const char *alt_type_name() {return "fltk::Group";}
  413. Fl_Widget *widget(int X,int Y,int W,int H) {
  414. igroup *g = new igroup(X,Y,W,H); Fl_Group::current(0); return g;}
  415. Fl_Widget_Type *_make() {return new Fl_Group_Type();}
  416. Fl_Type *make();
  417. void write_code1();
  418. void write_code2();
  419. void add_child(Fl_Type*, Fl_Type*);
  420. void move_child(Fl_Type*, Fl_Type*);
  421. void remove_child(Fl_Type*);
  422. int is_parent() const {return 1;}
  423. int is_group() const {return 1;}
  424. int pixmapID() { return 6; }
  425. virtual Fl_Widget *enter_live_mode(int top=0);
  426. virtual void leave_live_mode();
  427. virtual void copy_properties();
  428. };
  429. extern const char pack_type_name[];
  430. extern Fl_Menu_Item pack_type_menu[];
  431. class Fl_Pack_Type : public Fl_Group_Type {
  432. Fl_Menu_Item *subtypes() {return pack_type_menu;}
  433. public:
  434. virtual const char *type_name() {return pack_type_name;}
  435. virtual const char *alt_type_name() {return "fltk::PackedGroup";}
  436. Fl_Widget_Type *_make() {return new Fl_Pack_Type();}
  437. int pixmapID() { return 22; }
  438. void copy_properties();
  439. };
  440. extern const char table_type_name[];
  441. class Fl_Table_Type : public Fl_Group_Type {
  442. public:
  443. virtual const char *type_name() {return table_type_name;}
  444. virtual const char *alt_type_name() {return "fltk::TableGroup";}
  445. Fl_Widget_Type *_make() {return new Fl_Table_Type();}
  446. Fl_Widget *widget(int X,int Y,int W,int H);
  447. int pixmapID() { return 51; }
  448. virtual Fl_Widget *enter_live_mode(int top=0);
  449. void add_child(Fl_Type*, Fl_Type*);
  450. void move_child(Fl_Type*, Fl_Type*);
  451. void remove_child(Fl_Type*);
  452. };
  453. extern const char tabs_type_name[];
  454. class Fl_Tabs_Type : public Fl_Group_Type {
  455. public:
  456. virtual void ideal_spacing(int &x, int &y) {
  457. x = 10;
  458. fl_font(o->labelfont(), o->labelsize());
  459. y = fl_height() + o->labelsize() - 6;
  460. }
  461. virtual const char *type_name() {return tabs_type_name;}
  462. virtual const char *alt_type_name() {return "fltk::TabGroup";}
  463. Fl_Widget *widget(int X,int Y,int W,int H) {
  464. itabs *g = new itabs(X,Y,W,H); Fl_Group::current(0); return g;}
  465. Fl_Widget_Type *_make() {return new Fl_Tabs_Type();}
  466. Fl_Type* click_test(int,int);
  467. void add_child(Fl_Type*, Fl_Type*);
  468. void remove_child(Fl_Type*);
  469. int pixmapID() { return 13; }
  470. Fl_Widget *enter_live_mode(int top=0);
  471. };
  472. extern const char scroll_type_name[];
  473. extern Fl_Menu_Item scroll_type_menu[];
  474. class Fl_Scroll_Type : public Fl_Group_Type {
  475. Fl_Menu_Item *subtypes() {return scroll_type_menu;}
  476. public:
  477. virtual const char *type_name() {return scroll_type_name;}
  478. virtual const char *alt_type_name() {return "fltk::ScrollGroup";}
  479. Fl_Widget_Type *_make() {return new Fl_Scroll_Type();}
  480. int pixmapID() { return 19; }
  481. Fl_Widget *enter_live_mode(int top=0);
  482. void copy_properties();
  483. };
  484. extern const char tile_type_name[];
  485. class Fl_Tile_Type : public Fl_Group_Type {
  486. public:
  487. virtual const char *type_name() {return tile_type_name;}
  488. virtual const char *alt_type_name() {return "fltk::TileGroup";}
  489. Fl_Widget_Type *_make() {return new Fl_Tile_Type();}
  490. int pixmapID() { return 20; }
  491. void copy_properties();
  492. };
  493. extern const char wizard_type_name[];
  494. class Fl_Wizard_Type : public Fl_Group_Type {
  495. public:
  496. virtual const char *type_name() {return wizard_type_name;}
  497. virtual const char *alt_type_name() {return "fltk::WizardGroup";}
  498. Fl_Widget *widget(int X,int Y,int W,int H) {
  499. iwizard *g = new iwizard(X,Y,W,H); Fl_Group::current(0); return g;}
  500. Fl_Widget_Type *_make() {return new Fl_Wizard_Type();}
  501. int pixmapID() { return 21; }
  502. };
  503. #include <FL/Fl_Scroll.H>
  504. extern Fl_Menu_Item window_type_menu[];
  505. class Fl_Window_Scroll : public Fl_Window {
  506. public:
  507. Fl_Scroll *dsa; //design scrollable area
  508. void _init() {
  509. dsa = new Fl_Scroll(x(), y(), w(), h(), 0);
  510. resizable(dsa);
  511. }
  512. Fl_Window_Scroll(int X, int Y, int W, int H, char *L=0) : Fl_Window(X, Y, W, H, L) {_init();}
  513. Fl_Window_Scroll(int W, int H, char *L=0) : Fl_Window(W, H, L) {_init();}
  514. };
  515. class Fl_Window_Type : public Fl_Widget_Type {
  516. protected:
  517. Fl_Menu_Item* subtypes() {return window_type_menu;}
  518. friend class Overlay_Window;
  519. int mx,my; // mouse position during dragging
  520. int x1,y1; // initial position of selection box
  521. int bx,by,br,bt; // bounding box of selection before snapping
  522. int sx,sy,sr,st; // bounding box of selection after snapping to guides
  523. int dx,dy;
  524. int drag; // which parts of bbox are being moved
  525. int numselected; // number of children selected
  526. enum {LEFT=1,RIGHT=2,BOTTOM=4,TOP=8,DRAG=16,BOX=32};
  527. void draw_overlay();
  528. void newdx();
  529. void newposition(Fl_Widget_Type *,int &x,int &y,int &w,int &h);
  530. int handle(int);
  531. virtual void setlabel(const char *);
  532. void write_code1();
  533. void write_code2();
  534. Fl_Widget_Type *_make() {return 0;} // we don't call this
  535. Fl_Widget *widget(int,int,int,int) {return 0;}
  536. int recalc; // set by fix_overlay()
  537. void moveallchildren();
  538. int pixmapID() { return 1; }
  539. public:
  540. Fl_Window_Type() { drag = dx = dy = 0; sr_min_w = sr_min_h = sr_max_w = sr_max_h = 0; }
  541. uchar modal, non_modal;
  542. Fl_Type *make();
  543. virtual const char *type_name() {return "Fl_Window";}
  544. virtual const char *alt_type_name() {return "fltk::Window";}
  545. void open();
  546. void fix_overlay(); // Update the bounding box, etc
  547. uchar *read_image(int &ww, int &hh); // Read an image of the window
  548. virtual void write_properties();
  549. virtual void read_property(const char *);
  550. virtual int read_fdesign(const char*, const char*);
  551. void add_child(Fl_Type*, Fl_Type*);
  552. void move_child(Fl_Type*, Fl_Type*);
  553. void remove_child(Fl_Type*);
  554. int is_parent() const {return 1;}
  555. int is_group() const {return 1;}
  556. int is_window() const {return 1;}
  557. Fl_Widget *enter_live_mode(int top=0);
  558. void leave_live_mode();
  559. void copy_properties();
  560. int sr_min_w, sr_min_h, sr_max_w, sr_max_h;
  561. };
  562. #define FL_WIDGET_CLASS_FL_GROUP 0
  563. #define FL_WIDGET_CLASS_FL_WIDGET 1
  564. extern Fl_Menu_Item widget_class_type_menu[];
  565. extern const char *current_inner_structure;
  566. const char *check_inner_struct(char *wname, int size_wname, const char *name);
  567. #define CHECK_INNER_STRUCT(buf, s, aname) \
  568. s = check_inner_struct(buf, sizeof(buf), aname);
  569. class Fl_Widget_Class_Type : private Fl_Window_Type {
  570. protected:
  571. //Fl_Menu_Item* subtypes() {return widget_class_type_menu;}
  572. public:
  573. Fl_Widget_Class_Type() {
  574. write_public_state = 0;
  575. wc_relative = 0;
  576. wc_inner_struct = NULL;
  577. saved_current_inner_structure = NULL;
  578. }
  579. ~Fl_Widget_Class_Type(){
  580. if(wc_inner_struct) free((void *)wc_inner_struct);
  581. }
  582. // state variables for output:
  583. char write_public_state; // true when public: has been printed
  584. char wc_relative; // if true, reposition all child widgets in an Fl_Group
  585. const char *wc_inner_struct; // if not null create a inner struct for members
  586. const char *saved_current_inner_structure;
  587. virtual void write_properties();
  588. virtual void read_property(const char *);
  589. void write_code1();
  590. void write_code2();
  591. Fl_Type *make();
  592. virtual const char *type_name() {return "widget_class";}
  593. int pixmapID() { return 48; }
  594. int is_parent() const {return 1;}
  595. int is_code_block() const {return 1;}
  596. int is_decl_block() const {return 1;}
  597. int is_class() const {return 1;}
  598. };
  599. extern Fl_Menu_Item menu_item_type_menu[];
  600. class Fl_Menu_Item_Type : public Fl_Widget_Type {
  601. public:
  602. Fl_Menu_Item* subtypes() {return menu_item_type_menu;}
  603. const char* type_name() {return "MenuItem";}
  604. const char* alt_type_name() {return "fltk::Item";}
  605. Fl_Type* make();
  606. int is_menu_item() const {return 1;}
  607. int is_button() const {return 1;} // this gets shortcut to work
  608. Fl_Widget* widget(int,int,int,int) {return 0;}
  609. Fl_Widget_Type* _make() {return 0;}
  610. const char* menu_name(int& i);
  611. int flags();
  612. void write_static();
  613. void write_arr_definition();
  614. void write_item();
  615. void write_code1();
  616. void write_code2();
  617. int pixmapID() { return 16; }
  618. };
  619. class Fl_Submenu_Type : public Fl_Menu_Item_Type {
  620. public:
  621. Fl_Menu_Item* subtypes() {return 0;}
  622. const char* type_name() {return "Submenu";}
  623. const char* alt_type_name() {return "fltk::ItemGroup";}
  624. int is_parent() const {return 1;}
  625. int is_button() const {return 0;} // disable shortcut
  626. Fl_Type* make();
  627. // changes to submenu must propagate up so build_menu is called
  628. // on the parent Fl_Menu_Type:
  629. void add_child(Fl_Type*a, Fl_Type*b) {parent->add_child(a,b);}
  630. void move_child(Fl_Type*a, Fl_Type*b) {parent->move_child(a,b);}
  631. void remove_child(Fl_Type*a) {parent->remove_child(a);}
  632. int pixmapID() { return 18; }
  633. };
  634. #include <FL/Fl_Menu_.H>
  635. class Fl_Menu_Type : public Fl_Widget_Type {
  636. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  637. Fl_Menu_ *myo = (Fl_Menu_*)(w==4 ? ((Fl_Widget_Type*)this->factory)->o : this->o);
  638. switch (w) {
  639. case 4:
  640. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  641. case 1: myo->textfont(f); break;
  642. case 2: myo->textsize(s); break;
  643. case 3: myo->textcolor(c); break;
  644. }
  645. return 1;
  646. }
  647. public:
  648. int is_menu_button() const {return 1;}
  649. int is_parent() const {return 1;}
  650. int menusize;
  651. virtual void build_menu();
  652. Fl_Menu_Type() : Fl_Widget_Type() {menusize = 0;}
  653. ~Fl_Menu_Type() {
  654. if (menusize) delete[] (Fl_Menu_Item*)(((Fl_Menu_*)o)->menu());
  655. }
  656. void add_child(Fl_Type*, Fl_Type*) {build_menu();}
  657. void move_child(Fl_Type*, Fl_Type*) {build_menu();}
  658. void remove_child(Fl_Type*) {build_menu();}
  659. Fl_Type* click_test(int x, int y);
  660. void write_code2();
  661. void copy_properties();
  662. };
  663. extern Fl_Menu_Item button_type_menu[];
  664. #include <FL/Fl_Menu_Button.H>
  665. class Fl_Menu_Button_Type : public Fl_Menu_Type {
  666. Fl_Menu_Item *subtypes() {return button_type_menu;}
  667. public:
  668. virtual void ideal_size(int &w, int &h) {
  669. Fl_Widget_Type::ideal_size(w, h);
  670. w += 2 * ((o->labelsize() - 3) & ~1) + o->labelsize() - 4;
  671. h = (h / 5) * 5;
  672. if (h < 15) h = 15;
  673. if (w < (15 + h)) w = 15 + h;
  674. }
  675. virtual const char *type_name() {return "Fl_Menu_Button";}
  676. virtual const char *alt_type_name() {return "fltk::MenuButton";}
  677. Fl_Widget *widget(int X,int Y,int W,int H) {
  678. return new Fl_Menu_Button(X,Y,W,H,"menu");}
  679. Fl_Widget_Type *_make() {return new Fl_Menu_Button_Type();}
  680. int pixmapID() { return 26; }
  681. };
  682. extern Fl_Menu_Item dummymenu[];
  683. #include <FL/Fl_Choice.H>
  684. class Fl_Choice_Type : public Fl_Menu_Type {
  685. public:
  686. virtual void ideal_size(int &w, int &h) {
  687. Fl_Widget_Type::ideal_size(w, h);
  688. int w1 = o->h() - Fl::box_dh(o->box());
  689. if (w1 > 20) w1 = 20;
  690. w1 = (w1 - 4) / 3;
  691. if (w1 < 1) w1 = 1;
  692. w += 2 * w1 + o->labelsize() - 4;
  693. h = (h / 5) * 5;
  694. if (h < 15) h = 15;
  695. if (w < (15 + h)) w = 15 + h;
  696. }
  697. virtual const char *type_name() {return "Fl_Choice";}
  698. virtual const char *alt_type_name() {return "fltk::Choice";}
  699. Fl_Widget *widget(int X,int Y,int W,int H) {
  700. Fl_Choice *myo = new Fl_Choice(X,Y,W,H,"choice:");
  701. myo->menu(dummymenu);
  702. return myo;
  703. }
  704. Fl_Widget_Type *_make() {return new Fl_Choice_Type();}
  705. int pixmapID() { return 15; }
  706. };
  707. #include <FL/Fl_Input_Choice.H>
  708. class Fl_Input_Choice_Type : public Fl_Menu_Type {
  709. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  710. Fl_Input_Choice *myo = (Fl_Input_Choice*)(w==4 ? ((Fl_Widget_Type*)this->factory)->o : this->o);
  711. switch (w) {
  712. case 4:
  713. case 0: f = (Fl_Font)myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  714. case 1: myo->textfont(f); break;
  715. case 2: myo->textsize(s); break;
  716. case 3: myo->textcolor(c); break;
  717. }
  718. return 1;
  719. }
  720. public:
  721. virtual void ideal_size(int &w, int &h) {
  722. Fl_Input_Choice *myo = (Fl_Input_Choice *)o;
  723. fl_font(myo->textfont(), myo->textsize());
  724. h = fl_height() + myo->textsize() - 6;
  725. w = o->w() - 20 - Fl::box_dw(o->box());
  726. int ww = (int)fl_width('m');
  727. w = ((w + ww - 1) / ww) * ww + 20 + Fl::box_dw(o->box());
  728. if (h < 15) h = 15;
  729. if (w < (15 + h)) w = 15 + h;
  730. }
  731. virtual const char *type_name() {return "Fl_Input_Choice";}
  732. virtual const char *alt_type_name() {return "fltk::ComboBox";}
  733. virtual Fl_Type* click_test(int,int);
  734. Fl_Widget *widget(int X,int Y,int W,int H) {
  735. Fl_Input_Choice *myo = new Fl_Input_Choice(X,Y,W,H,"input choice:");
  736. myo->menu(dummymenu);
  737. myo->value("input");
  738. return myo;
  739. }
  740. Fl_Widget_Type *_make() {return new Fl_Input_Choice_Type();}
  741. virtual void build_menu();
  742. int pixmapID() { return 15; }
  743. void copy_properties();
  744. };
  745. #include <FL/Fl_Window.H>
  746. #include <FL/Fl_Menu_Bar.H>
  747. class Fl_Menu_Bar_Type : public Fl_Menu_Type {
  748. public:
  749. virtual void ideal_size(int &w, int &h) {
  750. w = o->window()->w();
  751. h = ((o->labelsize() + Fl::box_dh(o->box()) + 4) / 5) * 5;
  752. if (h < 15) h = 15;
  753. }
  754. virtual const char *type_name() {return "Fl_Menu_Bar";}
  755. virtual const char *alt_type_name() {return "fltk::MenuBar";}
  756. Fl_Widget *widget(int X,int Y,int W,int H) {return new Fl_Menu_Bar(X,Y,W,H);}
  757. Fl_Widget_Type *_make() {return new Fl_Menu_Bar_Type();}
  758. int pixmapID() { return 17; }
  759. };
  760. // object list operations:
  761. Fl_Widget *make_widget_browser(int X,int Y,int W,int H);
  762. extern int modflag;
  763. void delete_all(int selected_only=0);
  764. void selection_changed(Fl_Type* new_current);
  765. void reveal_in_browser(Fl_Type*);
  766. int has_toplevel_function(const char *rtype, const char *sig);
  767. // file operations:
  768. # ifdef __GNUC__
  769. # define __fl_attr(x) __attribute__ (x)
  770. # else
  771. # define __fl_attr(x)
  772. # endif // __GNUC__
  773. void write_word(const char *);
  774. void write_string(const char *,...) __fl_attr((__format__ (__printf__, 1, 2)));
  775. int write_file(const char *, int selected_only = 0);
  776. int write_code(const char *cfile, const char *hfile);
  777. int write_strings(const char *sfile);
  778. int write_declare(const char *, ...) __fl_attr((__format__ (__printf__, 1, 2)));
  779. int is_id(char);
  780. const char* unique_id(void* o, const char*, const char*, const char*);
  781. void write_c(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2)));
  782. void write_h(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2)));
  783. void write_cstring(const char *);
  784. void write_cstring(const char *,int length);
  785. void write_cdata(const char *,int length);
  786. void write_indent(int n);
  787. void write_open(int);
  788. void write_close(int n);
  789. extern int write_number;
  790. extern int write_sourceview;
  791. void write_public(int state); // writes pubic:/private: as needed
  792. extern int indentation;
  793. extern const char* indent();
  794. int read_file(const char *, int merge);
  795. const char *read_word(int wantbrace = 0);
  796. void read_error(const char *format, ...);
  797. // check legality of c code (sort of) and return error:
  798. const char *c_check(const char *c, int type = 0);
  799. // replace a string pointer with new value, strips leading/trailing blanks:
  800. int storestring(const char *n, const char * & p, int nostrip=0);
  801. extern int include_H_from_C;
  802. extern int use_FL_COMMAND;
  803. /*
  804. * This class is needed for additional command line plugins.
  805. */
  806. class Fl_Commandline_Plugin : public Fl_Plugin {
  807. public:
  808. Fl_Commandline_Plugin(const char *name)
  809. : Fl_Plugin(klass(), name) { }
  810. virtual const char *klass() { return "commandline"; }
  811. // return a unique name for this plugin
  812. virtual const char *name() = 0;
  813. // return a help text for all supported commands
  814. virtual const char *help() = 0;
  815. // handle a command and return the number of args used, or 0
  816. virtual int arg(int argc, char **argv, int &i) = 0;
  817. // optional test the plugin
  818. virtual int test(const char *a1=0L, const char *a2=0L, const char *a3=0L) {
  819. return 0;
  820. }
  821. // show a GUI panel to edit some data
  822. virtual void show_panel() { }
  823. };
  824. //
  825. // End of "$Id: Fl_Type.h 10093 2014-02-04 00:34:41Z AlbrechtS $".
  826. //