You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

872 lines
27KB

  1. //
  2. // "$Id: Fl_Type.h 8172 2011-01-03 08:28:38Z matt $"
  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; you can redistribute it and/or
  18. // modify it under the terms of the GNU Library General Public
  19. // License as published by the Free Software Foundation; either
  20. // version 2 of the License, or (at your option) any later version.
  21. //
  22. // This library is distributed in the hope that it will be useful,
  23. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. // Library General Public License for more details.
  26. //
  27. // You should have received a copy of the GNU Library General Public
  28. // License along with this library; if not, write to the Free Software
  29. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  30. // USA.
  31. //
  32. // Please report all bugs and problems on the following page:
  33. //
  34. // http://www.fltk.org/str.php
  35. //
  36. #include <FL/Fl_Widget.H>
  37. #include <FL/Fl_Menu.H>
  38. #include <FL/Fl_Plugin.H>
  39. #include "Fluid_Image.h"
  40. #include <FL/fl_draw.H>
  41. void set_modflag(int mf);
  42. class Fl_Type {
  43. friend class Widget_Browser;
  44. friend Fl_Widget *make_type_browser(int,int,int,int,const char *l=0);
  45. friend class Fl_Window_Type;
  46. virtual void setlabel(const char *); // virtual part of label(char*)
  47. protected:
  48. Fl_Type();
  49. const char *name_;
  50. const char *label_;
  51. const char *callback_;
  52. const char *user_data_;
  53. const char *user_data_type_;
  54. const char *comment_;
  55. public: // things that should not be public:
  56. Fl_Type *parent; // parent, which is previous in list
  57. char new_selected; // browser highlight
  58. char selected; // copied here by selection_changed()
  59. char open_; // state of triangle in browser
  60. char visible; // true if all parents are open
  61. char rtti; // hack because I have no rtti, this is 0 for base class
  62. int level; // number of parents over this
  63. static Fl_Type *first, *last; // linked list of all objects
  64. Fl_Type *next, *prev; // linked list of all objects
  65. Fl_Type *factory;
  66. const char *callback_name();
  67. int code_position, header_position;
  68. int code_position_end, header_position_end;
  69. protected:
  70. int user_defined(const char* cbname) const;
  71. public:
  72. virtual ~Fl_Type();
  73. virtual Fl_Type *make() = 0;
  74. void add(Fl_Type *parent); // add as new child
  75. void insert(Fl_Type *n); // insert into list before n
  76. Fl_Type* remove(); // remove from list
  77. void move_before(Fl_Type*); // move before a sibling
  78. virtual const char *title(); // string for browser
  79. virtual const char *type_name() = 0; // type for code output
  80. virtual const char *alt_type_name() { return type_name(); } // alternate type for FLTK2 code output
  81. const char *name() const {return name_;}
  82. void name(const char *);
  83. const char *label() const {return label_;}
  84. void label(const char *);
  85. const char *callback() const {return callback_;}
  86. void callback(const char *);
  87. const char *user_data() const {return user_data_;}
  88. void user_data(const char *);
  89. const char *user_data_type() const {return user_data_type_;}
  90. void user_data_type(const char *);
  91. const char *comment() { return comment_; }
  92. void comment(const char *);
  93. virtual Fl_Type* click_test(int,int);
  94. virtual void add_child(Fl_Type*, Fl_Type* beforethis);
  95. virtual void move_child(Fl_Type*, Fl_Type* beforethis);
  96. virtual void remove_child(Fl_Type*);
  97. static Fl_Type *current; // most recently picked object
  98. virtual void open(); // what happens when you double-click
  99. // read and write data to a saved file:
  100. void write();
  101. virtual void write_properties();
  102. virtual void read_property(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. };
  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. public:
  200. Fl_Type *make();
  201. void write_code1();
  202. void write_code2();
  203. void open();
  204. virtual const char *type_name() {return "decl";}
  205. void write_properties();
  206. void read_property(const char *);
  207. virtual int is_public() const;
  208. int pixmapID() { return 10; }
  209. };
  210. class Fl_Data_Type : public Fl_Decl_Type {
  211. const char *filename_;
  212. public:
  213. Fl_Data_Type() : Fl_Decl_Type(), filename_(0L) { }
  214. ~Fl_Data_Type() {
  215. if (filename_) free((void*)filename_);
  216. }
  217. Fl_Type *make();
  218. void write_code1();
  219. void write_code2();
  220. void open();
  221. virtual const char *type_name() {return "data";}
  222. void write_properties();
  223. void read_property(const char *);
  224. int pixmapID() { return 49; }
  225. };
  226. class Fl_DeclBlock_Type : public Fl_Type {
  227. const char* after;
  228. char public_;
  229. public:
  230. Fl_DeclBlock_Type() : Fl_Type(), after(0L) { }
  231. ~Fl_DeclBlock_Type() {
  232. if (after) free((void*)after);
  233. }
  234. Fl_Type *make();
  235. void write_code1();
  236. void write_code2();
  237. void open();
  238. virtual const char *type_name() {return "declblock";}
  239. void write_properties();
  240. void read_property(const char *);
  241. int is_parent() const {return 1;}
  242. int is_decl_block() const {return 1;}
  243. virtual int is_public() const;
  244. int pixmapID() { return 11; }
  245. };
  246. class Fl_Comment_Type : public Fl_Type {
  247. char in_c_, in_h_, style_;
  248. char title_buf[64];
  249. public:
  250. Fl_Type *make();
  251. void write_code1();
  252. void write_code2();
  253. void open();
  254. virtual const char *type_name() {return "comment";}
  255. virtual const char *title(); // string for browser
  256. void write_properties();
  257. void read_property(const char *);
  258. virtual int is_public() const { return 1; }
  259. virtual int is_comment() const { return 1; }
  260. int pixmapID() { return 46; }
  261. };
  262. class Fl_Class_Type : public Fl_Type {
  263. const char* subclass_of;
  264. char public_;
  265. public:
  266. Fl_Class_Type() : Fl_Type(), subclass_of(0L) { }
  267. ~Fl_Class_Type() {
  268. if (subclass_of) free((void*)subclass_of);
  269. }
  270. // state variables for output:
  271. char write_public_state; // true when public: has been printed
  272. Fl_Class_Type* parent_class; // save class if nested
  273. //
  274. Fl_Type *make();
  275. void write_code1();
  276. void write_code2();
  277. void open();
  278. virtual const char *type_name() {return "class";}
  279. int is_parent() const {return 1;}
  280. int is_decl_block() const {return 1;}
  281. int is_class() const {return 1;}
  282. virtual int is_public() const;
  283. int pixmapID() { return 12; }
  284. void write_properties();
  285. void read_property(const char *);
  286. // class prefix attribute access
  287. void prefix(const char* p);
  288. const char* prefix() const {return class_prefix;}
  289. int has_function(const char*, const char*) const;
  290. private:
  291. const char* class_prefix;
  292. };
  293. #define NUM_EXTRA_CODE 4
  294. class Fl_Widget_Type : public Fl_Type {
  295. virtual Fl_Widget *widget(int,int,int,int) = 0;
  296. virtual Fl_Widget_Type *_make() = 0; // virtual constructor
  297. virtual void setlabel(const char *);
  298. const char *extra_code_[NUM_EXTRA_CODE];
  299. const char *subclass_;
  300. const char *tooltip_;
  301. const char *image_name_;
  302. const char *inactive_name_;
  303. uchar hotspot_;
  304. protected:
  305. void write_static();
  306. void write_code1();
  307. void write_widget_code();
  308. void write_extra_code();
  309. void write_block_close();
  310. void write_code2();
  311. void write_color(const char*, Fl_Color);
  312. Fl_Widget *live_widget;
  313. public:
  314. static int default_size;
  315. const char *xclass; // junk string, used for shortcut
  316. Fl_Widget *o;
  317. int public_;
  318. Fluid_Image *image;
  319. void setimage(Fluid_Image *);
  320. Fluid_Image *inactive;
  321. void setinactive(Fluid_Image *);
  322. Fl_Widget_Type();
  323. Fl_Type *make();
  324. void open();
  325. const char *extra_code(int n) const {return extra_code_[n];}
  326. void extra_code(int n,const char *);
  327. const char *subclass() const {return subclass_;}
  328. void subclass(const char *);
  329. const char *tooltip() const {return tooltip_;}
  330. void tooltip(const char *);
  331. const char *image_name() const {return image_name_;}
  332. void image_name(const char *);
  333. const char *inactive_name() const {return inactive_name_;}
  334. void inactive_name(const char *);
  335. uchar hotspot() const {return hotspot_;}
  336. void hotspot(uchar v) {hotspot_ = v;}
  337. uchar resizable() const;
  338. void resizable(uchar v);
  339. virtual int textstuff(int what, Fl_Font &, int &, Fl_Color &);
  340. virtual Fl_Menu_Item *subtypes();
  341. virtual int is_widget() const;
  342. virtual int is_public() const;
  343. virtual void write_properties();
  344. virtual void read_property(const char *);
  345. virtual Fl_Widget *enter_live_mode(int top=0);
  346. virtual void leave_live_mode();
  347. virtual void copy_properties();
  348. virtual void ideal_size(int &w, int &h);
  349. virtual void ideal_spacing(int &x, int &y);
  350. ~Fl_Widget_Type();
  351. void redraw();
  352. };
  353. #include <FL/Fl_Tabs.H>
  354. #include <FL/Fl_Pack.H>
  355. #include <FL/Fl_Wizard.H>
  356. class igroup : public Fl_Group {
  357. public:
  358. void resize(int,int,int,int);
  359. void full_resize(int X, int Y, int W, int H) { Fl_Group::resize(X, Y, W, H); }
  360. igroup(int X,int Y,int W,int H) : Fl_Group(X,Y,W,H) {Fl_Group::current(0);}
  361. };
  362. class itabs : public Fl_Tabs {
  363. public:
  364. void resize(int,int,int,int);
  365. void full_resize(int X, int Y, int W, int H) { Fl_Group::resize(X, Y, W, H); }
  366. itabs(int X,int Y,int W,int H) : Fl_Tabs(X,Y,W,H) {}
  367. };
  368. class iwizard : public Fl_Wizard {
  369. public:
  370. void resize(int,int,int,int);
  371. void full_resize(int X, int Y, int W, int H) { Fl_Group::resize(X, Y, W, H); }
  372. iwizard(int X,int Y,int W,int H) : Fl_Wizard(X,Y,W,H) {}
  373. };
  374. class Fl_Group_Type : public Fl_Widget_Type {
  375. public:
  376. virtual const char *type_name() {return "Fl_Group";}
  377. virtual const char *alt_type_name() {return "fltk::Group";}
  378. Fl_Widget *widget(int X,int Y,int W,int H) {
  379. igroup *g = new igroup(X,Y,W,H); Fl_Group::current(0); return g;}
  380. Fl_Widget_Type *_make() {return new Fl_Group_Type();}
  381. Fl_Type *make();
  382. void write_code1();
  383. void write_code2();
  384. void add_child(Fl_Type*, Fl_Type*);
  385. void move_child(Fl_Type*, Fl_Type*);
  386. void remove_child(Fl_Type*);
  387. int is_parent() const {return 1;}
  388. int is_group() const {return 1;}
  389. int pixmapID() { return 6; }
  390. virtual Fl_Widget *enter_live_mode(int top=0);
  391. virtual void leave_live_mode();
  392. virtual void copy_properties();
  393. };
  394. extern const char pack_type_name[];
  395. extern Fl_Menu_Item pack_type_menu[];
  396. class Fl_Pack_Type : public Fl_Group_Type {
  397. Fl_Menu_Item *subtypes() {return pack_type_menu;}
  398. public:
  399. virtual const char *type_name() {return pack_type_name;}
  400. virtual const char *alt_type_name() {return "fltk::PackedGroup";}
  401. Fl_Widget_Type *_make() {return new Fl_Pack_Type();}
  402. int pixmapID() { return 22; }
  403. void copy_properties();
  404. };
  405. extern const char table_type_name[];
  406. class Fl_Table_Type : public Fl_Group_Type {
  407. public:
  408. virtual const char *type_name() {return table_type_name;}
  409. virtual const char *alt_type_name() {return "fltk::TableGroup";}
  410. Fl_Widget_Type *_make() {return new Fl_Table_Type();}
  411. Fl_Widget *widget(int X,int Y,int W,int H);
  412. int pixmapID() { return 51; }
  413. virtual Fl_Widget *enter_live_mode(int top=0);
  414. void add_child(Fl_Type*, Fl_Type*);
  415. void move_child(Fl_Type*, Fl_Type*);
  416. void remove_child(Fl_Type*);
  417. };
  418. extern const char tabs_type_name[];
  419. class Fl_Tabs_Type : public Fl_Group_Type {
  420. public:
  421. virtual void ideal_spacing(int &x, int &y) {
  422. x = 10;
  423. fl_font(o->labelfont(), o->labelsize());
  424. y = fl_height() + o->labelsize() - 6;
  425. }
  426. virtual const char *type_name() {return tabs_type_name;}
  427. virtual const char *alt_type_name() {return "fltk::TabGroup";}
  428. Fl_Widget *widget(int X,int Y,int W,int H) {
  429. itabs *g = new itabs(X,Y,W,H); Fl_Group::current(0); return g;}
  430. Fl_Widget_Type *_make() {return new Fl_Tabs_Type();}
  431. Fl_Type* click_test(int,int);
  432. void add_child(Fl_Type*, Fl_Type*);
  433. void remove_child(Fl_Type*);
  434. int pixmapID() { return 13; }
  435. Fl_Widget *enter_live_mode(int top=0);
  436. };
  437. extern const char scroll_type_name[];
  438. extern Fl_Menu_Item scroll_type_menu[];
  439. class Fl_Scroll_Type : public Fl_Group_Type {
  440. Fl_Menu_Item *subtypes() {return scroll_type_menu;}
  441. public:
  442. virtual const char *type_name() {return scroll_type_name;}
  443. virtual const char *alt_type_name() {return "fltk::ScrollGroup";}
  444. Fl_Widget_Type *_make() {return new Fl_Scroll_Type();}
  445. int pixmapID() { return 19; }
  446. Fl_Widget *enter_live_mode(int top=0);
  447. void copy_properties();
  448. };
  449. extern const char tile_type_name[];
  450. class Fl_Tile_Type : public Fl_Group_Type {
  451. public:
  452. virtual const char *type_name() {return tile_type_name;}
  453. virtual const char *alt_type_name() {return "fltk::TileGroup";}
  454. Fl_Widget_Type *_make() {return new Fl_Tile_Type();}
  455. int pixmapID() { return 20; }
  456. void copy_properties();
  457. };
  458. extern const char wizard_type_name[];
  459. class Fl_Wizard_Type : public Fl_Group_Type {
  460. public:
  461. virtual const char *type_name() {return wizard_type_name;}
  462. virtual const char *alt_type_name() {return "fltk::WizardGroup";}
  463. Fl_Widget *widget(int X,int Y,int W,int H) {
  464. iwizard *g = new iwizard(X,Y,W,H); Fl_Group::current(0); return g;}
  465. Fl_Widget_Type *_make() {return new Fl_Wizard_Type();}
  466. int pixmapID() { return 21; }
  467. };
  468. extern Fl_Menu_Item window_type_menu[];
  469. class Fl_Window_Type : public Fl_Widget_Type {
  470. protected:
  471. Fl_Menu_Item* subtypes() {return window_type_menu;}
  472. friend class Overlay_Window;
  473. int mx,my; // mouse position during dragging
  474. int x1,y1; // initial position of selection box
  475. int bx,by,br,bt; // bounding box of selection before snapping
  476. int sx,sy,sr,st; // bounding box of selection after snapping to guides
  477. int dx,dy;
  478. int drag; // which parts of bbox are being moved
  479. int numselected; // number of children selected
  480. enum {LEFT=1,RIGHT=2,BOTTOM=4,TOP=8,DRAG=16,BOX=32};
  481. void draw_overlay();
  482. void newdx();
  483. void newposition(Fl_Widget_Type *,int &x,int &y,int &w,int &h);
  484. int handle(int);
  485. virtual void setlabel(const char *);
  486. void write_code1();
  487. void write_code2();
  488. Fl_Widget_Type *_make() {return 0;} // we don't call this
  489. Fl_Widget *widget(int,int,int,int) {return 0;}
  490. int recalc; // set by fix_overlay()
  491. void moveallchildren();
  492. int pixmapID() { return 1; }
  493. public:
  494. Fl_Window_Type() { drag = dx = dy = 0; sr_min_w = sr_min_h = sr_max_w = sr_max_h = 0; }
  495. uchar modal, non_modal;
  496. Fl_Type *make();
  497. virtual const char *type_name() {return "Fl_Window";}
  498. virtual const char *alt_type_name() {return "fltk::Window";}
  499. void open();
  500. void fix_overlay(); // Update the bounding box, etc
  501. uchar *read_image(int &ww, int &hh); // Read an image of the window
  502. virtual void write_properties();
  503. virtual void read_property(const char *);
  504. void add_child(Fl_Type*, Fl_Type*);
  505. void move_child(Fl_Type*, Fl_Type*);
  506. void remove_child(Fl_Type*);
  507. int is_parent() const {return 1;}
  508. int is_group() const {return 1;}
  509. int is_window() const {return 1;}
  510. Fl_Widget *enter_live_mode(int top=0);
  511. void leave_live_mode();
  512. void copy_properties();
  513. int sr_min_w, sr_min_h, sr_max_w, sr_max_h;
  514. };
  515. class Fl_Widget_Class_Type : private Fl_Window_Type {
  516. public:
  517. Fl_Widget_Class_Type() {
  518. write_public_state = 0;
  519. wc_relative = 0;
  520. }
  521. // state variables for output:
  522. char write_public_state; // true when public: has been printed
  523. char wc_relative; // if true, reposition all child widgets in an Fl_Group
  524. virtual void write_properties();
  525. virtual void read_property(const char *);
  526. void write_code1();
  527. void write_code2();
  528. Fl_Type *make();
  529. virtual const char *type_name() {return "widget_class";}
  530. int pixmapID() { return 48; }
  531. int is_parent() const {return 1;}
  532. int is_code_block() const {return 1;}
  533. int is_decl_block() const {return 1;}
  534. int is_class() const {return 1;}
  535. };
  536. extern Fl_Menu_Item menu_item_type_menu[];
  537. class Fl_Menu_Item_Type : public Fl_Widget_Type {
  538. public:
  539. Fl_Menu_Item* subtypes() {return menu_item_type_menu;}
  540. const char* type_name() {return "MenuItem";}
  541. const char* alt_type_name() {return "fltk::Item";}
  542. Fl_Type* make();
  543. int is_menu_item() const {return 1;}
  544. int is_button() const {return 1;} // this gets shortcut to work
  545. Fl_Widget* widget(int,int,int,int) {return 0;}
  546. Fl_Widget_Type* _make() {return 0;}
  547. const char* menu_name(int& i);
  548. int flags();
  549. void write_static();
  550. void write_item();
  551. void write_code1();
  552. void write_code2();
  553. int pixmapID() { return 16; }
  554. };
  555. class Fl_Submenu_Type : public Fl_Menu_Item_Type {
  556. public:
  557. Fl_Menu_Item* subtypes() {return 0;}
  558. const char* type_name() {return "Submenu";}
  559. const char* alt_type_name() {return "fltk::ItemGroup";}
  560. int is_parent() const {return 1;}
  561. int is_button() const {return 0;} // disable shortcut
  562. Fl_Type* make();
  563. // changes to submenu must propagate up so build_menu is called
  564. // on the parent Fl_Menu_Type:
  565. void add_child(Fl_Type*a, Fl_Type*b) {parent->add_child(a,b);}
  566. void move_child(Fl_Type*a, Fl_Type*b) {parent->move_child(a,b);}
  567. void remove_child(Fl_Type*a) {parent->remove_child(a);}
  568. int pixmapID() { return 18; }
  569. };
  570. #include <FL/Fl_Menu_.H>
  571. class Fl_Menu_Type : public Fl_Widget_Type {
  572. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  573. Fl_Menu_ *myo = (Fl_Menu_*)(w==4 ? ((Fl_Widget_Type*)this->factory)->o : this->o);
  574. switch (w) {
  575. case 4:
  576. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  577. case 1: myo->textfont(f); break;
  578. case 2: myo->textsize(s); break;
  579. case 3: myo->textcolor(c); break;
  580. }
  581. return 1;
  582. }
  583. public:
  584. int is_menu_button() const {return 1;}
  585. int is_parent() const {return 1;}
  586. int menusize;
  587. virtual void build_menu();
  588. Fl_Menu_Type() : Fl_Widget_Type() {menusize = 0;}
  589. ~Fl_Menu_Type() {
  590. if (menusize) delete[] (Fl_Menu_Item*)(((Fl_Menu_*)o)->menu());
  591. }
  592. void add_child(Fl_Type*, Fl_Type*) {build_menu();}
  593. void move_child(Fl_Type*, Fl_Type*) {build_menu();}
  594. void remove_child(Fl_Type*) {build_menu();}
  595. Fl_Type* click_test(int x, int y);
  596. void write_code2();
  597. void copy_properties();
  598. };
  599. extern Fl_Menu_Item button_type_menu[];
  600. #include <FL/Fl_Menu_Button.H>
  601. class Fl_Menu_Button_Type : public Fl_Menu_Type {
  602. Fl_Menu_Item *subtypes() {return button_type_menu;}
  603. public:
  604. virtual void ideal_size(int &w, int &h) {
  605. Fl_Widget_Type::ideal_size(w, h);
  606. w += 2 * ((o->labelsize() - 3) & ~1) + o->labelsize() - 4;
  607. h = (h / 5) * 5;
  608. if (h < 15) h = 15;
  609. if (w < (15 + h)) w = 15 + h;
  610. }
  611. virtual const char *type_name() {return "Fl_Menu_Button";}
  612. virtual const char *alt_type_name() {return "fltk::MenuButton";}
  613. Fl_Widget *widget(int X,int Y,int W,int H) {
  614. return new Fl_Menu_Button(X,Y,W,H,"menu");}
  615. Fl_Widget_Type *_make() {return new Fl_Menu_Button_Type();}
  616. int pixmapID() { return 26; }
  617. };
  618. extern Fl_Menu_Item dummymenu[];
  619. #include <FL/Fl_Choice.H>
  620. class Fl_Choice_Type : public Fl_Menu_Type {
  621. public:
  622. virtual void ideal_size(int &w, int &h) {
  623. Fl_Widget_Type::ideal_size(w, h);
  624. int w1 = o->h() - Fl::box_dh(o->box());
  625. if (w1 > 20) w1 = 20;
  626. w1 = (w1 - 4) / 3;
  627. if (w1 < 1) w1 = 1;
  628. w += 2 * w1 + o->labelsize() - 4;
  629. h = (h / 5) * 5;
  630. if (h < 15) h = 15;
  631. if (w < (15 + h)) w = 15 + h;
  632. }
  633. virtual const char *type_name() {return "Fl_Choice";}
  634. virtual const char *alt_type_name() {return "fltk::Choice";}
  635. Fl_Widget *widget(int X,int Y,int W,int H) {
  636. Fl_Choice *myo = new Fl_Choice(X,Y,W,H,"choice:");
  637. myo->menu(dummymenu);
  638. return myo;
  639. }
  640. Fl_Widget_Type *_make() {return new Fl_Choice_Type();}
  641. int pixmapID() { return 15; }
  642. };
  643. #include <FL/Fl_Input_Choice.H>
  644. class Fl_Input_Choice_Type : public Fl_Menu_Type {
  645. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  646. Fl_Input_Choice *myo = (Fl_Input_Choice*)(w==4 ? ((Fl_Widget_Type*)this->factory)->o : this->o);
  647. switch (w) {
  648. case 4:
  649. case 0: f = (Fl_Font)myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  650. case 1: myo->textfont(f); break;
  651. case 2: myo->textsize(s); break;
  652. case 3: myo->textcolor(c); break;
  653. }
  654. return 1;
  655. }
  656. public:
  657. virtual void ideal_size(int &w, int &h) {
  658. Fl_Input_Choice *myo = (Fl_Input_Choice *)o;
  659. fl_font(myo->textfont(), myo->textsize());
  660. h = fl_height() + myo->textsize() - 6;
  661. w = o->w() - 20 - Fl::box_dw(o->box());
  662. int ww = (int)fl_width('m');
  663. w = ((w + ww - 1) / ww) * ww + 20 + Fl::box_dw(o->box());
  664. if (h < 15) h = 15;
  665. if (w < (15 + h)) w = 15 + h;
  666. }
  667. virtual const char *type_name() {return "Fl_Input_Choice";}
  668. virtual const char *alt_type_name() {return "fltk::ComboBox";}
  669. virtual Fl_Type* click_test(int,int);
  670. Fl_Widget *widget(int X,int Y,int W,int H) {
  671. Fl_Input_Choice *myo = new Fl_Input_Choice(X,Y,W,H,"input choice:");
  672. myo->menu(dummymenu);
  673. myo->value("input");
  674. return myo;
  675. }
  676. Fl_Widget_Type *_make() {return new Fl_Input_Choice_Type();}
  677. virtual void build_menu();
  678. int pixmapID() { return 15; }
  679. void copy_properties();
  680. };
  681. #include <FL/Fl_Window.H>
  682. #include <FL/Fl_Menu_Bar.H>
  683. class Fl_Menu_Bar_Type : public Fl_Menu_Type {
  684. public:
  685. virtual void ideal_size(int &w, int &h) {
  686. w = o->window()->w();
  687. h = ((o->labelsize() + Fl::box_dh(o->box()) + 4) / 5) * 5;
  688. if (h < 15) h = 15;
  689. }
  690. virtual const char *type_name() {return "Fl_Menu_Bar";}
  691. virtual const char *alt_type_name() {return "fltk::MenuBar";}
  692. Fl_Widget *widget(int X,int Y,int W,int H) {return new Fl_Menu_Bar(X,Y,W,H);}
  693. Fl_Widget_Type *_make() {return new Fl_Menu_Bar_Type();}
  694. int pixmapID() { return 17; }
  695. };
  696. // object list operations:
  697. Fl_Widget *make_widget_browser(int X,int Y,int W,int H);
  698. extern int modflag;
  699. void delete_all(int selected_only=0);
  700. void selection_changed(Fl_Type* new_current);
  701. void reveal_in_browser(Fl_Type*);
  702. int has_toplevel_function(const char *rtype, const char *sig);
  703. // file operations:
  704. # ifdef __GNUC__
  705. # define __fl_attr(x) __attribute__ (x)
  706. # else
  707. # define __fl_attr(x)
  708. # endif // __GNUC__
  709. void write_word(const char *);
  710. void write_string(const char *,...) __fl_attr((__format__ (__printf__, 1, 2)));
  711. int write_file(const char *, int selected_only = 0);
  712. int write_code(const char *cfile, const char *hfile);
  713. int write_strings(const char *sfile);
  714. int write_declare(const char *, ...) __fl_attr((__format__ (__printf__, 1, 2)));
  715. int is_id(char);
  716. const char* unique_id(void* o, const char*, const char*, const char*);
  717. void write_c(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2)));
  718. void write_h(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2)));
  719. void write_cstring(const char *);
  720. void write_cstring(const char *,int length);
  721. void write_cdata(const char *,int length);
  722. void write_indent(int n);
  723. void write_open(int);
  724. void write_close(int n);
  725. extern int write_number;
  726. extern int write_sourceview;
  727. void write_public(int state); // writes pubic:/private: as needed
  728. extern int indentation;
  729. extern const char* indent();
  730. int read_file(const char *, int merge);
  731. const char *read_word(int wantbrace = 0);
  732. void read_error(const char *format, ...);
  733. // check legality of c code (sort of) and return error:
  734. const char *c_check(const char *c, int type = 0);
  735. // replace a string pointer with new value, strips leading/trailing blanks:
  736. int storestring(const char *n, const char * & p, int nostrip=0);
  737. extern int include_H_from_C;
  738. extern int use_FL_COMMAND;
  739. /*
  740. * This class is needed for additional command line plugins.
  741. */
  742. class Fl_Commandline_Plugin : public Fl_Plugin {
  743. public:
  744. Fl_Commandline_Plugin(const char *name)
  745. : Fl_Plugin(klass(), name) { }
  746. virtual const char *klass() { return "commandline"; }
  747. // return a unique name for this plugin
  748. virtual const char *name() = 0;
  749. // return a help text for all supported commands
  750. virtual const char *help() = 0;
  751. // handle a command and return the number of args used, or 0
  752. virtual int arg(int argc, char **argv, int &i) = 0;
  753. // optional test the plugin
  754. virtual int test(const char *a1=0L, const char *a2=0L, const char *a3=0L) {
  755. return 0;
  756. }
  757. // show a GUI panel to edit some data
  758. virtual void show_panel() { }
  759. };
  760. //
  761. // End of "$Id: Fl_Type.h 8172 2011-01-03 08:28:38Z matt $".
  762. //