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.

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