Fl_Type.h 30 KB

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