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.

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