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.

1140 lines
38KB

  1. //
  2. // "$Id: factory.cxx 8172 2011-01-03 08:28:38Z matt $"
  3. //
  4. // Widget factory code for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Type classes for most of the fltk widgets. Most of the work
  7. // is done by code in Fl_Widget_Type.C. Also a factory instance
  8. // of each of these type classes.
  9. //
  10. // This file also contains the "new" menu, which has a pointer
  11. // to a factory instance for every class (both the ones defined
  12. // here and ones in other files)
  13. //
  14. // Copyright 1998-2010 by Bill Spitzak and others.
  15. //
  16. // This library is free software; you can redistribute it and/or
  17. // modify it under the terms of the GNU Library General Public
  18. // License as published by the Free Software Foundation; either
  19. // version 2 of the License, or (at your option) any later version.
  20. //
  21. // This library is distributed in the hope that it will be useful,
  22. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. // Library General Public License for more details.
  25. //
  26. // You should have received a copy of the GNU Library General Public
  27. // License along with this library; if not, write to the Free Software
  28. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  29. // USA.
  30. //
  31. // Please report all bugs and problems on the following page:
  32. //
  33. // http://www.fltk.org/str.php
  34. //
  35. #include <FL/Fl.H>
  36. #include <FL/Fl_Group.H>
  37. #include <FL/Fl_Menu_Item.H>
  38. #include <FL/Fl_Pixmap.H>
  39. #include <FL/Fl_Tree.H>
  40. #include <stdio.h>
  41. #include "../src/flstring.h"
  42. #include "undo.h"
  43. #include "Fl_Widget_Type.h"
  44. extern Fl_Pixmap *pixmap[];
  45. #if !HAVE_STRCASECMP
  46. //
  47. // 'strcasecmp()' - Do a case-insensitive compare...
  48. //
  49. static int
  50. strcasecmp(const char *s, const char *t) {
  51. while (*s != '\0' && *t != '\0') {
  52. if (tolower(*s) < tolower(*t))
  53. return (-1);
  54. else if (tolower(*s) > tolower(*t))
  55. return (1);
  56. s ++;
  57. t ++;
  58. }
  59. if (*s == '\0' && *t == '\0')
  60. return (0);
  61. else if (*s != '\0')
  62. return (1);
  63. else
  64. return (-1);
  65. }
  66. #endif // !HAVE_STRCASECMP
  67. ////////////////////////////////////////////////////////////////
  68. #include <FL/Fl_Box.H>
  69. class Fl_Box_Type : public Fl_Widget_Type {
  70. public:
  71. virtual const char *type_name() {return "Fl_Box";}
  72. virtual const char *alt_type_name() {return "fltk::Widget";}
  73. Fl_Widget *widget(int x,int y,int w, int h) {
  74. return new Fl_Box(x,y,w,h,"label");}
  75. Fl_Widget_Type *_make() {return new Fl_Box_Type();}
  76. int pixmapID() { return 5; }
  77. };
  78. static Fl_Box_Type Fl_Box_type;
  79. ////////////////////////////////////////////////////////////////
  80. #include <FL/Fl_Button.H>
  81. static Fl_Menu_Item buttontype_menu[] = {
  82. {"Normal",0,0,(void*)0},
  83. {"Toggle",0,0,(void*)FL_TOGGLE_BUTTON},
  84. {"Radio",0,0,(void*)FL_RADIO_BUTTON},
  85. {0}};
  86. class Fl_Button_Type : public Fl_Widget_Type {
  87. Fl_Menu_Item *subtypes() {return buttontype_menu;}
  88. public:
  89. virtual void ideal_size(int &w, int &h) {
  90. Fl_Widget_Type::ideal_size(w, h);
  91. w += 2 * (o->labelsize() - 4);
  92. h = (h / 5) * 5;
  93. }
  94. virtual const char *type_name() {return "Fl_Button";}
  95. virtual const char *alt_type_name() {return "fltk::Button";}
  96. Fl_Widget *widget(int x,int y,int w,int h) {
  97. return new Fl_Button(x,y,w,h,"button");}
  98. Fl_Widget_Type *_make() {return new Fl_Button_Type();}
  99. int is_button() const {return 1;}
  100. int pixmapID() { return 2; }
  101. };
  102. static Fl_Button_Type Fl_Button_type;
  103. ////////////////////////////////////////////////////////////////
  104. #include <FL/Fl_Return_Button.H>
  105. class Fl_Return_Button_Type : public Fl_Button_Type {
  106. public:
  107. virtual void ideal_size(int &w, int &h) {
  108. Fl_Button_Type::ideal_size(w, h);
  109. int W = o->h();
  110. if (o->w()/3 < W) W = o->w()/3;
  111. w += W + 8 - o->labelsize();
  112. }
  113. virtual const char *type_name() {return "Fl_Return_Button";}
  114. virtual const char *alt_type_name() {return "fltk::ReturnButton";}
  115. Fl_Widget *widget(int x,int y,int w,int h) {
  116. return new Fl_Return_Button(x,y,w,h,"button");}
  117. Fl_Widget_Type *_make() {return new Fl_Return_Button_Type();}
  118. int pixmapID() { return 23; }
  119. };
  120. static Fl_Return_Button_Type Fl_Return_Button_type;
  121. ////////////////////////////////////////////////////////////////
  122. #include <FL/Fl_Repeat_Button.H>
  123. class Fl_Repeat_Button_Type : public Fl_Widget_Type {
  124. public:
  125. virtual const char *type_name() {return "Fl_Repeat_Button";}
  126. virtual const char *alt_type_name() {return "fltk::RepeatButton";}
  127. Fl_Widget *widget(int x,int y,int w,int h) {
  128. return new Fl_Repeat_Button(x,y,w,h,"button");}
  129. Fl_Widget_Type *_make() {return new Fl_Repeat_Button_Type();}
  130. int pixmapID() { return 25; }
  131. };
  132. static Fl_Repeat_Button_Type Fl_Repeat_Button_type;
  133. ////////////////////////////////////////////////////////////////
  134. #include <FL/Fl_Light_Button.H>
  135. class Fl_Light_Button_Type : public Fl_Button_Type {
  136. public:
  137. virtual void ideal_size(int &w, int &h) {
  138. Fl_Button_Type::ideal_size(w, h);
  139. w += 4;
  140. }
  141. virtual const char *type_name() {return "Fl_Light_Button";}
  142. virtual const char *alt_type_name() {return "fltk::LightButton";}
  143. Fl_Widget *widget(int x,int y,int w,int h) {
  144. return new Fl_Light_Button(x,y,w,h,"button");}
  145. Fl_Widget_Type *_make() {return new Fl_Light_Button_Type();}
  146. int pixmapID() { return 24; }
  147. };
  148. static Fl_Light_Button_Type Fl_Light_Button_type;
  149. ////////////////////////////////////////////////////////////////
  150. #include <FL/Fl_Check_Button.H>
  151. class Fl_Check_Button_Type : public Fl_Button_Type {
  152. public:
  153. virtual void ideal_size(int &w, int &h) {
  154. Fl_Button_Type::ideal_size(w, h);
  155. w += 4;
  156. }
  157. virtual const char *type_name() {return "Fl_Check_Button";}
  158. virtual const char *alt_type_name() {return "fltk::CheckButton";}
  159. Fl_Widget *widget(int x,int y,int w,int h) {
  160. return new Fl_Check_Button(x,y,w,h,"button");}
  161. Fl_Widget_Type *_make() {return new Fl_Check_Button_Type();}
  162. int pixmapID() { return 3; }
  163. };
  164. static Fl_Check_Button_Type Fl_Check_Button_type;
  165. ////////////////////////////////////////////////////////////////
  166. #include <FL/Fl_Round_Button.H>
  167. class Fl_Round_Button_Type : public Fl_Button_Type {
  168. public:
  169. virtual void ideal_size(int &w, int &h) {
  170. Fl_Button_Type::ideal_size(w, h);
  171. w += 4;
  172. }
  173. virtual const char *type_name() {return "Fl_Round_Button";}
  174. virtual const char *alt_type_name() {return "fltk::RadioButton";}
  175. Fl_Widget *widget(int x,int y,int w,int h) {
  176. return new Fl_Round_Button(x,y,w,h,"button");}
  177. Fl_Widget_Type *_make() {return new Fl_Round_Button_Type();}
  178. int pixmapID() { return 4; }
  179. };
  180. static Fl_Round_Button_Type Fl_Round_Button_type;
  181. ////////////////////////////////////////////////////////////////
  182. extern int compile_only;
  183. #include <FL/Fl_Browser.H>
  184. #include <FL/Fl_Check_Browser.H>
  185. #include <FL/Fl_File_Browser.H>
  186. static Fl_Menu_Item browser_type_menu[] = {
  187. {"No Select",0,0,(void*)FL_NORMAL_BROWSER},
  188. {"Select",0,0,(void*)FL_SELECT_BROWSER},
  189. {"Hold",0,0,(void*)FL_HOLD_BROWSER},
  190. {"Multi",0,0,(void*)FL_MULTI_BROWSER},
  191. {0}};
  192. class Fl_Browser_Type : public Fl_Widget_Type {
  193. Fl_Menu_Item *subtypes() {return browser_type_menu;}
  194. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  195. public:
  196. virtual void ideal_size(int &w, int &h) {
  197. Fl_Browser *myo = (Fl_Browser *)o;
  198. fl_font(myo->textfont(), myo->textsize());
  199. h -= Fl::box_dh(o->box());
  200. w -= Fl::box_dw(o->box());
  201. int ww = (int)fl_width('m');
  202. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  203. h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
  204. Fl::box_dh(o->box());
  205. if (h < 30) h = 30;
  206. if (w < 50) w = 50;
  207. }
  208. virtual const char *type_name() {return "Fl_Browser";}
  209. virtual const char *alt_type_name() {return "fltk::Browser";}
  210. Fl_Widget *widget(int x,int y,int w,int h) {
  211. Fl_Browser* b = new Fl_Browser(x,y,w,h);
  212. // Fl_Browser::add calls fl_height(), which requires the X display open.
  213. // Avoid this when compiling so it works w/o a display:
  214. if (!compile_only) {
  215. char buffer[20];
  216. for (int i = 1; i <= 20; i++) {
  217. sprintf(buffer,"Browser Line %d",i);
  218. b->add(buffer);
  219. }
  220. }
  221. return b;
  222. }
  223. Fl_Widget_Type *_make() {return new Fl_Browser_Type();}
  224. int pixmapID() { return 31; }
  225. };
  226. static Fl_Browser_Type Fl_Browser_type;
  227. int Fl_Browser_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  228. Fl_Browser *myo = (Fl_Browser*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  229. switch (w) {
  230. case 4:
  231. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  232. case 1: myo->textfont(f); break;
  233. case 2: myo->textsize(s); break;
  234. case 3: myo->textcolor(c); break;
  235. }
  236. return 1;
  237. }
  238. class Fl_Check_Browser_Type : public Fl_Widget_Type {
  239. Fl_Menu_Item *subtypes() {return browser_type_menu;}
  240. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  241. public:
  242. virtual void ideal_size(int &w, int &h) {
  243. Fl_Check_Browser *myo = (Fl_Check_Browser *)o;
  244. fl_font(myo->textfont(), myo->textsize());
  245. h -= Fl::box_dh(o->box());
  246. w -= Fl::box_dw(o->box()) - fl_height();
  247. int ww = (int)fl_width('m');
  248. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  249. h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
  250. Fl::box_dh(o->box());
  251. if (h < 30) h = 30;
  252. if (w < 50) w = 50;
  253. }
  254. virtual const char *type_name() {return "Fl_Check_Browser";}
  255. virtual const char *alt_type_name() {return "fltk::CheckBrowser";}
  256. Fl_Widget *widget(int x,int y,int w,int h) {
  257. Fl_Check_Browser* b = new Fl_Check_Browser(x,y,w,h);
  258. // Fl_Check_Browser::add calls fl_height(), which requires the X display open.
  259. // Avoid this when compiling so it works w/o a display:
  260. if (!compile_only) {
  261. char buffer[20];
  262. for (int i = 1; i <= 20; i++) {
  263. sprintf(buffer,"Browser Line %d",i);
  264. b->add(buffer);
  265. }
  266. }
  267. return b;
  268. }
  269. Fl_Widget_Type *_make() {return new Fl_Check_Browser_Type();}
  270. int pixmapID() { return 32; }
  271. };
  272. static Fl_Check_Browser_Type Fl_Check_Browser_type;
  273. int Fl_Check_Browser_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  274. Fl_Check_Browser *myo = (Fl_Check_Browser*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  275. switch (w) {
  276. case 4:
  277. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  278. case 1: myo->textfont(f); break;
  279. case 2: myo->textsize(s); break;
  280. case 3: myo->textcolor(c); break;
  281. }
  282. return 1;
  283. }
  284. class Fl_Tree_Type : public Fl_Widget_Type {
  285. public:
  286. virtual void ideal_size(int &w, int &h) {
  287. if (h < 60) h = 60;
  288. if (w < 80) w = 80;
  289. }
  290. virtual const char *type_name() {return "Fl_Tree";}
  291. virtual const char *alt_type_name() {return "fltk::TreeBrowser";}
  292. Fl_Widget *widget(int x,int y,int w,int h) {
  293. Fl_Tree* b = new Fl_Tree(x,y,w,h);
  294. if (!compile_only) {
  295. b->add("/A1/B1/C1");
  296. b->add("/A1/B1/C2");
  297. b->add("/A1/B2/C1");
  298. b->add("/A1/B2/C2");
  299. b->add("/A2/B1/C1");
  300. b->add("/A2/B1/C2");
  301. b->add("/A2/B2/C1");
  302. b->add("/A2/B2/C2");
  303. }
  304. return b;
  305. }
  306. Fl_Widget_Type *_make() {return new Fl_Tree_Type();}
  307. int pixmapID() { return 50; }
  308. };
  309. static Fl_Tree_Type Fl_Tree_type;
  310. class Fl_File_Browser_Type : public Fl_Widget_Type {
  311. Fl_Menu_Item *subtypes() {return browser_type_menu;}
  312. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  313. public:
  314. virtual void ideal_size(int &w, int &h) {
  315. Fl_File_Browser *myo = (Fl_File_Browser *)o;
  316. fl_font(myo->textfont(), myo->textsize());
  317. h -= Fl::box_dh(o->box());
  318. w -= Fl::box_dw(o->box()) + fl_height();
  319. int ww = (int)fl_width('m');
  320. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  321. h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
  322. Fl::box_dh(o->box());
  323. if (h < 30) h = 30;
  324. if (w < 50) w = 50;
  325. }
  326. virtual const char *type_name() {return "Fl_File_Browser";}
  327. virtual const char *alt_type_name() {return "fltk::FileBrowser";}
  328. Fl_Widget *widget(int x,int y,int w,int h) {
  329. Fl_File_Browser* b = new Fl_File_Browser(x,y,w,h);
  330. // Fl_File_Browser::add calls fl_height(), which requires the X display open.
  331. // Avoid this when compiling so it works w/o a display:
  332. if (!compile_only) {
  333. b->load(".");
  334. }
  335. return b;
  336. }
  337. Fl_Widget_Type *_make() {return new Fl_File_Browser_Type();}
  338. int pixmapID() { return 33; }
  339. };
  340. static Fl_File_Browser_Type Fl_File_Browser_type;
  341. int Fl_File_Browser_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  342. Fl_File_Browser *myo = (Fl_File_Browser*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  343. switch (w) {
  344. case 4:
  345. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  346. case 1: myo->textfont(f); break;
  347. case 2: myo->textsize(s); break;
  348. case 3: myo->textcolor(c); break;
  349. }
  350. return 1;
  351. }
  352. ////////////////////////////////////////////////////////////////
  353. #include <FL/Fl_Counter.H>
  354. static Fl_Menu_Item counter_type_menu[] = {
  355. {"Normal",0,0,(void*)FL_NORMAL_COUNTER},
  356. {"Simple",0,0,(void*)FL_SIMPLE_COUNTER},
  357. {0}};
  358. class Fl_Counter_Type : public Fl_Widget_Type {
  359. Fl_Menu_Item *subtypes() {return counter_type_menu;}
  360. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  361. int is_valuator() const {return 1;}
  362. int pixmapID() { return 41; }
  363. public:
  364. virtual const char *type_name() {return "Fl_Counter";}
  365. virtual const char *alt_type_name() {return "fltk::Counter";}
  366. Fl_Widget *widget(int x,int y,int w,int h) {
  367. return new Fl_Counter(x,y,w,h,"counter:");}
  368. Fl_Widget_Type *_make() {return new Fl_Counter_Type();}
  369. };
  370. static Fl_Counter_Type Fl_Counter_type;
  371. int Fl_Counter_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  372. Fl_Counter *myo = (Fl_Counter*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  373. switch (w) {
  374. case 4:
  375. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  376. case 1: myo->textfont(f); break;
  377. case 2: myo->textsize(s); break;
  378. case 3: myo->textcolor(c); break;
  379. }
  380. return 1;
  381. }
  382. ////////////////////////////////////////////////////////////////
  383. #include <FL/Fl_Spinner.H>
  384. static Fl_Menu_Item spinner_type_menu[] = {
  385. {"Integer",0,0,(void*)FL_INT_INPUT},
  386. {"Float", 0,0,(void*)FL_FLOAT_INPUT},
  387. {0}};
  388. class Fl_Spinner_Type : public Fl_Widget_Type {
  389. Fl_Menu_Item *subtypes() {return spinner_type_menu;}
  390. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  391. int pixmapID() { return 47; }
  392. public:
  393. virtual void ideal_size(int &w, int &h) {
  394. Fl_Spinner *myo = (Fl_Spinner *)o;
  395. fl_font(myo->textfont(), myo->textsize());
  396. h = fl_height() + myo->textsize() - 6;
  397. if (h < 15) h = 15;
  398. w -= Fl::box_dw(o->box());
  399. int ww = (int)fl_width('m');
  400. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box()) + h / 2;
  401. if (w < 40) w = 40 ;
  402. }
  403. virtual const char *type_name() {return "Fl_Spinner";}
  404. virtual const char *alt_type_name() {return "fltk::Spinner";}
  405. int is_spinner() const { return 1; }
  406. Fl_Widget *widget(int x,int y,int w,int h) {
  407. return new Fl_Spinner(x,y,w,h,"spinner:");}
  408. Fl_Widget_Type *_make() {return new Fl_Spinner_Type();}
  409. };
  410. static Fl_Spinner_Type Fl_Spinner_type;
  411. int Fl_Spinner_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  412. Fl_Spinner *myo = (Fl_Spinner*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  413. switch (w) {
  414. case 4:
  415. case 0: f = (Fl_Font)myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  416. case 1: myo->textfont(f); break;
  417. case 2: myo->textsize(s); break;
  418. case 3: myo->textcolor(c); break;
  419. }
  420. return 1;
  421. }
  422. ////////////////////////////////////////////////////////////////
  423. #include <FL/Fl_Input.H>
  424. static Fl_Menu_Item input_type_menu[] = {
  425. {"Normal",0,0,(void*)FL_NORMAL_INPUT},
  426. {"Multiline",0,0,(void*)FL_MULTILINE_INPUT},
  427. {"Secret",0,0,(void*)FL_SECRET_INPUT},
  428. {"Int",0,0,(void*)FL_INT_INPUT},
  429. {"Float",0,0,(void*)FL_FLOAT_INPUT},
  430. {0}};
  431. class Fl_Input_Type : public Fl_Widget_Type {
  432. Fl_Menu_Item *subtypes() {return input_type_menu;}
  433. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  434. public:
  435. virtual void ideal_size(int &w, int &h) {
  436. Fl_Input *myo = (Fl_Input *)o;
  437. fl_font(myo->textfont(), myo->textsize());
  438. h = fl_height() + myo->textsize() - 6;
  439. w -= Fl::box_dw(o->box());
  440. int ww = (int)fl_width('m');
  441. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  442. if (h < 15) h = 15;
  443. if (w < 15) w = 15;
  444. }
  445. virtual const char *type_name() {return "Fl_Input";}
  446. virtual const char *alt_type_name() {return "fltk::Input";}
  447. int is_input() const {return 1;}
  448. Fl_Widget *widget(int x,int y,int w,int h) {
  449. Fl_Input *myo = new Fl_Input(x,y,w,h,"input:");
  450. myo->value("Text Input");
  451. return myo;
  452. }
  453. Fl_Widget_Type *_make() {return new Fl_Input_Type();}
  454. int pixmapID() { return 14; }
  455. virtual void copy_properties() {
  456. Fl_Widget_Type::copy_properties();
  457. Fl_Input_ *d = (Fl_Input_*)live_widget, *s = (Fl_Input_*)o;
  458. d->textfont(s->textfont());
  459. d->textsize(s->textsize());
  460. d->textcolor(s->textcolor());
  461. d->shortcut(s->shortcut());
  462. }
  463. };
  464. static Fl_Input_Type Fl_Input_type;
  465. int Fl_Input_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  466. Fl_Input_ *myo = (Fl_Input_*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  467. switch (w) {
  468. case 4:
  469. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  470. case 1: myo->textfont(f); break;
  471. case 2: myo->textsize(s); break;
  472. case 3: myo->textcolor(c); break;
  473. }
  474. return 1;
  475. }
  476. ////////////////////////////////////////////////////////////////
  477. #include <FL/Fl_File_Input.H>
  478. class Fl_File_Input_Type : public Fl_Widget_Type {
  479. Fl_Menu_Item *subtypes() {return 0;}
  480. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  481. public:
  482. virtual void ideal_size(int &w, int &h) {
  483. Fl_File_Input *myo = (Fl_File_Input *)o;
  484. fl_font(myo->textfont(), myo->textsize());
  485. h = fl_height() + myo->textsize() + 4;
  486. w -= Fl::box_dw(o->box());
  487. int ww = (int)fl_width('m');
  488. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  489. if (h < 20) h = 20;
  490. if (w < 50) w = 50;
  491. }
  492. virtual const char *type_name() {return "Fl_File_Input";}
  493. virtual const char *alt_type_name() {return "fltk::FileInput";}
  494. int is_input() const {return 1;}
  495. Fl_Widget *widget(int x,int y,int w,int h) {
  496. Fl_File_Input *myo = new Fl_File_Input(x,y,w,h,"file:");
  497. myo->value("/now/is/the/time/for/a/filename.ext");
  498. return myo;
  499. }
  500. Fl_Widget_Type *_make() {return new Fl_File_Input_Type();}
  501. int pixmapID() { return 30; }
  502. };
  503. static Fl_File_Input_Type Fl_File_Input_type;
  504. int Fl_File_Input_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  505. Fl_File_Input *myo = (Fl_File_Input*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  506. switch (w) {
  507. case 4:
  508. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  509. case 1: myo->textfont(f); break;
  510. case 2: myo->textsize(s); break;
  511. case 3: myo->textcolor(c); break;
  512. }
  513. return 1;
  514. }
  515. ////////////////////////////////////////////////////////////////
  516. #include <FL/Fl_Text_Display.H>
  517. class Fl_Text_Display_Type : public Fl_Widget_Type {
  518. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  519. public:
  520. virtual void ideal_size(int &w, int &h) {
  521. Fl_Text_Display *myo = (Fl_Text_Display *)o;
  522. fl_font(myo->textfont(), myo->textsize());
  523. h -= Fl::box_dh(o->box());
  524. w -= Fl::box_dw(o->box());
  525. int ww = (int)fl_width('m');
  526. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  527. h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
  528. Fl::box_dh(o->box());
  529. if (h < 30) h = 30;
  530. if (w < 50) w = 50;
  531. }
  532. virtual const char *type_name() {return "Fl_Text_Display";}
  533. virtual const char *alt_type_name() {return "fltk::TextDisplay";}
  534. int is_text_display() const {return 1;}
  535. Fl_Widget *widget(int x,int y,int w,int h) {
  536. Fl_Text_Display *myo = new Fl_Text_Display(x,y,w,h);
  537. return myo;
  538. }
  539. Fl_Widget_Type *_make() {return new Fl_Text_Display_Type();}
  540. int pixmapID() { return 28; }
  541. };
  542. static Fl_Text_Display_Type Fl_Text_Display_type;
  543. int Fl_Text_Display_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  544. Fl_Text_Display *myo = (Fl_Text_Display*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  545. switch (w) {
  546. case 4:
  547. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  548. case 1: myo->textfont(f); break;
  549. case 2: myo->textsize(s); break;
  550. case 3: myo->textcolor(c); break;
  551. }
  552. return 1;
  553. }
  554. ////////////////////////////////////////////////////////////////
  555. #include <FL/Fl_Text_Editor.H>
  556. class Fl_Text_Editor_Type : public Fl_Widget_Type {
  557. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  558. public:
  559. virtual void ideal_size(int &w, int &h) {
  560. Fl_Text_Editor *myo = (Fl_Text_Editor *)o;
  561. fl_font(myo->textfont(), myo->textsize());
  562. h -= Fl::box_dh(o->box());
  563. w -= Fl::box_dw(o->box());
  564. int ww = (int)fl_width('m');
  565. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  566. h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
  567. Fl::box_dh(o->box());
  568. if (h < 30) h = 30;
  569. if (w < 50) w = 50;
  570. }
  571. virtual const char *type_name() {return "Fl_Text_Editor";}
  572. virtual const char *alt_type_name() {return "fltk::TextEditor";}
  573. int is_text_display() const {return 1;}
  574. Fl_Widget *widget(int x,int y,int w,int h) {
  575. Fl_Text_Editor *myo = new Fl_Text_Editor(x,y,w,h);
  576. return myo;
  577. }
  578. Fl_Widget_Type *_make() {return new Fl_Text_Editor_Type();}
  579. int pixmapID() { return 29; }
  580. };
  581. static Fl_Text_Editor_Type Fl_Text_Editor_type;
  582. int Fl_Text_Editor_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  583. Fl_Text_Editor *myo = (Fl_Text_Editor*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  584. switch (w) {
  585. case 4:
  586. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  587. case 1: myo->textfont(f); break;
  588. case 2: myo->textsize(s); break;
  589. case 3: myo->textcolor(c); break;
  590. }
  591. return 1;
  592. }
  593. ////////////////////////////////////////////////////////////////
  594. #include <FL/Fl_Clock.H>
  595. class Fl_Clock_Type : public Fl_Widget_Type {
  596. public:
  597. virtual const char *type_name() {return "Fl_Clock";}
  598. virtual const char *alt_type_name() {return "fltk::Clock";}
  599. Fl_Widget *widget(int x,int y,int w,int h) {
  600. return new Fl_Clock(x,y,w,h);}
  601. Fl_Widget_Type *_make() {return new Fl_Clock_Type();}
  602. int pixmapID() { return 34; }
  603. };
  604. static Fl_Clock_Type Fl_Clock_type;
  605. ////////////////////////////////////////////////////////////////
  606. #include <FL/Fl_Help_View.H>
  607. class Fl_Help_View_Type : public Fl_Widget_Type {
  608. public:
  609. virtual void ideal_size(int &w, int &h) {
  610. Fl_Help_View *myo = (Fl_Help_View *)o;
  611. fl_font(myo->textfont(), myo->textsize());
  612. h -= Fl::box_dh(o->box());
  613. w -= Fl::box_dw(o->box());
  614. int ww = (int)fl_width('m');
  615. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  616. h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
  617. Fl::box_dh(o->box());
  618. if (h < 30) h = 30;
  619. if (w < 50) w = 50;
  620. }
  621. virtual const char *type_name() {return "Fl_Help_View";}
  622. virtual const char *alt_type_name() {return "fltk::HelpView";}
  623. Fl_Widget *widget(int x,int y,int w,int h) {
  624. Fl_Help_View *myo = new Fl_Help_View(x,y,w,h);
  625. if (!compile_only) {
  626. myo->value("<HTML><BODY><H1>Fl_Help_View Widget</H1>"
  627. "<P>This is a Fl_Help_View widget.</P></BODY></HTML>");
  628. }
  629. return myo;}
  630. Fl_Widget_Type *_make() {return new Fl_Help_View_Type();}
  631. int pixmapID() { return 35; }
  632. };
  633. static Fl_Help_View_Type Fl_Help_View_type;
  634. ////////////////////////////////////////////////////////////////
  635. #include <FL/Fl_Progress.H>
  636. class Fl_Progress_Type : public Fl_Widget_Type {
  637. public:
  638. virtual const char *type_name() {return "Fl_Progress";}
  639. virtual const char *alt_type_name() {return "fltk::ProgressBar";}
  640. Fl_Widget *widget(int x,int y,int w,int h) {
  641. Fl_Progress *myo = new Fl_Progress(x,y,w,h,"label");
  642. myo->value(50);
  643. return myo;}
  644. Fl_Widget_Type *_make() {return new Fl_Progress_Type();}
  645. int pixmapID() { return 36; }
  646. };
  647. static Fl_Progress_Type Fl_Progress_type;
  648. ////////////////////////////////////////////////////////////////
  649. #include <FL/Fl_Adjuster.H>
  650. class Fl_Adjuster_Type : public Fl_Widget_Type {
  651. int is_valuator() const {return 1;}
  652. public:
  653. virtual const char *type_name() {return "Fl_Adjuster";}
  654. virtual const char *alt_type_name() {return "fltk::Adjuster";}
  655. Fl_Widget *widget(int x,int y,int w,int h) {
  656. return new Fl_Adjuster(x,y,w,h);}
  657. Fl_Widget_Type *_make() {return new Fl_Adjuster_Type();}
  658. int pixmapID() { return 40; }
  659. };
  660. static Fl_Adjuster_Type Fl_Adjuster_type;
  661. ////////////////////////////////////////////////////////////////
  662. #include <FL/Fl_Dial.H>
  663. static Fl_Menu_Item dial_type_menu[] = {
  664. {"Dot",0,0,(void*)0},
  665. {"Line",0,0,(void*)FL_LINE_DIAL},
  666. {"Fill",0,0,(void*)FL_FILL_DIAL},
  667. {0}};
  668. class Fl_Dial_Type : public Fl_Widget_Type {
  669. Fl_Menu_Item *subtypes() {return dial_type_menu;}
  670. int is_valuator() const {return 1;}
  671. public:
  672. virtual const char *type_name() {return "Fl_Dial";}
  673. virtual const char *alt_type_name() {return "fltk::Dial";}
  674. Fl_Widget *widget(int x,int y,int w,int h) {
  675. return new Fl_Dial(x,y,w,h);}
  676. Fl_Widget_Type *_make() {return new Fl_Dial_Type();}
  677. int pixmapID() { return 42; }
  678. };
  679. static Fl_Dial_Type Fl_Dial_type;
  680. ////////////////////////////////////////////////////////////////
  681. #include <FL/Fl_Roller.H>
  682. static Fl_Menu_Item roller_type_menu[] = {
  683. {"Vertical",0,0,(void*)0},
  684. {"Horizontal",0,0,(void*)FL_HORIZONTAL},
  685. {0}};
  686. class Fl_Roller_Type : public Fl_Widget_Type {
  687. Fl_Menu_Item *subtypes() {return roller_type_menu;}
  688. int is_valuator() const {return 1;}
  689. public:
  690. virtual const char *type_name() {return "Fl_Roller";}
  691. virtual const char *alt_type_name() {return "fltk::Roller";}
  692. Fl_Widget *widget(int x,int y,int w,int h) {
  693. return new Fl_Roller(x,y,w,h);}
  694. Fl_Widget_Type *_make() {return new Fl_Roller_Type();}
  695. int pixmapID() { return 43; }
  696. };
  697. static Fl_Roller_Type Fl_Roller_type;
  698. ////////////////////////////////////////////////////////////////
  699. #include <FL/Fl_Scrollbar.H>
  700. static Fl_Menu_Item slider_type_menu[] = {
  701. {"Vertical",0,0,(void*)FL_VERT_SLIDER},
  702. {"Horizontal",0,0,(void*)FL_HOR_SLIDER},
  703. {"Vert Fill",0,0,(void*)FL_VERT_FILL_SLIDER},
  704. {"Horz Fill",0,0,(void*)FL_HOR_FILL_SLIDER},
  705. {"Vert Knob",0,0,(void*)FL_VERT_NICE_SLIDER},
  706. {"Horz Knob",0,0,(void*)FL_HOR_NICE_SLIDER},
  707. {0}};
  708. class Fl_Slider_Type : public Fl_Widget_Type {
  709. Fl_Menu_Item *subtypes() {return slider_type_menu;}
  710. int is_valuator() const {return 2;}
  711. public:
  712. virtual const char *type_name() {return "Fl_Slider";}
  713. virtual const char *alt_type_name() {return "fltk::Slider";}
  714. Fl_Widget *widget(int x,int y,int w,int h) {
  715. return new Fl_Slider(x,y,w,h,"slider:");}
  716. Fl_Widget_Type *_make() {return new Fl_Slider_Type();}
  717. int pixmapID() { return 37; }
  718. };
  719. static Fl_Slider_Type Fl_Slider_type;
  720. static Fl_Menu_Item scrollbar_type_menu[] = {
  721. {"Vertical",0,0,(void*)FL_VERT_SLIDER},
  722. {"Horizontal",0,0,(void*)FL_HOR_SLIDER},
  723. {0}};
  724. class Fl_Scrollbar_Type : public Fl_Slider_Type {
  725. Fl_Menu_Item *subtypes() {return scrollbar_type_menu;}
  726. int is_valuator() const {return 3;}
  727. public:
  728. virtual const char *type_name() {return "Fl_Scrollbar";}
  729. virtual const char *alt_type_name() {return "fltk::Scrollbar";}
  730. Fl_Widget *widget(int x,int y,int w,int h) {
  731. return new Fl_Scrollbar(x,y,w,h);}
  732. Fl_Widget_Type *_make() {return new Fl_Scrollbar_Type();}
  733. int pixmapID() { return 38; }
  734. };
  735. static Fl_Scrollbar_Type Fl_Scrollbar_type;
  736. ////////////////////////////////////////////////////////////////
  737. #include <FL/Fl_Output.H>
  738. static Fl_Menu_Item output_type_menu[] = {
  739. {"Normal",0,0,(void*)FL_NORMAL_OUTPUT},
  740. {"Multiline",0,0,(void*)FL_MULTILINE_OUTPUT},
  741. {0}};
  742. class Fl_Output_Type : public Fl_Input_Type {
  743. Fl_Menu_Item *subtypes() {return output_type_menu;}
  744. public:
  745. virtual void ideal_size(int &w, int &h) {
  746. Fl_Output *myo = (Fl_Output *)o;
  747. fl_font(myo->textfont(), myo->textsize());
  748. h = fl_height() + myo->textsize() - 6;
  749. w -= Fl::box_dw(o->box());
  750. int ww = (int)fl_width('m');
  751. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  752. if (h < 15) h = 15;
  753. if (w < 15) w = 15;
  754. }
  755. virtual const char *type_name() {return "Fl_Output";}
  756. virtual const char *alt_type_name() {return "fltk::Output";}
  757. Fl_Widget *widget(int x,int y,int w,int h) {
  758. Fl_Output *myo = new Fl_Output(x,y,w,h,"output:");
  759. myo->value("Text Output");
  760. return myo;
  761. }
  762. Fl_Widget_Type *_make() {return new Fl_Output_Type();}
  763. int pixmapID() { return 27; }
  764. };
  765. static Fl_Output_Type Fl_Output_type;
  766. ////////////////////////////////////////////////////////////////
  767. #include <FL/Fl_Value_Input.H>
  768. class Fl_Value_Input_Type : public Fl_Widget_Type {
  769. public:
  770. virtual void ideal_size(int &w, int &h) {
  771. Fl_Value_Input *myo = (Fl_Value_Input *)o;
  772. fl_font(myo->textfont(), myo->textsize());
  773. h = fl_height() + myo->textsize() - 6;
  774. w -= Fl::box_dw(o->box());
  775. int ww = (int)fl_width('m');
  776. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  777. if (h < 15) h = 15;
  778. if (w < 15) w = 15;
  779. }
  780. virtual const char *type_name() {return "Fl_Value_Input";}
  781. virtual const char *alt_type_name() {return "fltk::ValueInput";}
  782. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  783. int is_valuator() const {return 1;}
  784. int is_value_input() const {return 1;}
  785. Fl_Widget *widget(int x,int y,int w,int h) {
  786. Fl_Value_Input *myo = new Fl_Value_Input(x,y,w,h,"value:");
  787. return myo;
  788. }
  789. Fl_Widget_Type *_make() {return new Fl_Value_Input_Type();}
  790. int pixmapID() { return 44; }
  791. };
  792. static Fl_Value_Input_Type Fl_Value_Input_type;
  793. int Fl_Value_Input_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  794. Fl_Value_Input *myo = (Fl_Value_Input*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  795. switch (w) {
  796. case 4:
  797. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  798. case 1: myo->textfont(f); break;
  799. case 2: myo->textsize(s); break;
  800. case 3: myo->textcolor(c); break;
  801. }
  802. return 1;
  803. }
  804. ////////////////////////////////////////////////////////////////
  805. #include <FL/Fl_Value_Output.H>
  806. class Fl_Value_Output_Type : public Fl_Widget_Type {
  807. public:
  808. virtual void ideal_size(int &w, int &h) {
  809. Fl_Value_Output *myo = (Fl_Value_Output *)o;
  810. fl_font(myo->textfont(), myo->textsize());
  811. h = fl_height() + myo->textsize() - 6;
  812. w = o->w() - Fl::box_dw(o->box());
  813. int ww = (int)fl_width('m');
  814. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  815. if (h < 15) h = 15;
  816. if (w < 15) w = 15;
  817. }
  818. virtual const char *type_name() {return "Fl_Value_Output";}
  819. virtual const char *alt_type_name() {return "fltk::ValueOutput";}
  820. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  821. int is_valuator() const {return 1;}
  822. Fl_Widget *widget(int x,int y,int w,int h) {
  823. Fl_Value_Output *myo = new Fl_Value_Output(x,y,w,h,"value:");
  824. return myo;
  825. }
  826. Fl_Widget_Type *_make() {return new Fl_Value_Output_Type();}
  827. int pixmapID() { return 45; }
  828. };
  829. static Fl_Value_Output_Type Fl_Value_Output_type;
  830. int Fl_Value_Output_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  831. Fl_Value_Output *myo = (Fl_Value_Output*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  832. switch (w) {
  833. case 4:
  834. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  835. case 1: myo->textfont(f); break;
  836. case 2: myo->textsize(s); break;
  837. case 3: myo->textcolor(c); break;
  838. }
  839. return 1;
  840. }
  841. ////////////////////////////////////////////////////////////////
  842. #include <FL/Fl_Value_Slider.H>
  843. class Fl_Value_Slider_Type : public Fl_Slider_Type {
  844. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  845. public:
  846. virtual const char *type_name() {return "Fl_Value_Slider";}
  847. virtual const char *alt_type_name() {return "fltk::ValueSlider";}
  848. Fl_Widget *widget(int x,int y,int w,int h) {
  849. return new Fl_Value_Slider(x,y,w,h,"slider:");}
  850. Fl_Widget_Type *_make() {return new Fl_Value_Slider_Type();}
  851. int pixmapID() { return 39; }
  852. };
  853. static Fl_Value_Slider_Type Fl_Value_Slider_type;
  854. int Fl_Value_Slider_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  855. Fl_Value_Slider *myo = (Fl_Value_Slider*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  856. switch (w) {
  857. case 4:
  858. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  859. case 1: myo->textfont(f); break;
  860. case 2: myo->textsize(s); break;
  861. case 3: myo->textcolor(c); break;
  862. }
  863. return 1;
  864. }
  865. ////////////////////////////////////////////////////////////////
  866. extern class Fl_Function_Type Fl_Function_type;
  867. extern class Fl_Code_Type Fl_Code_type;
  868. extern class Fl_CodeBlock_Type Fl_CodeBlock_type;
  869. extern class Fl_Data_Type Fl_Data_type;
  870. extern class Fl_Decl_Type Fl_Decl_type;
  871. extern class Fl_DeclBlock_Type Fl_DeclBlock_type;
  872. extern class Fl_Comment_Type Fl_Comment_type;
  873. extern class Fl_Class_Type Fl_Class_type;
  874. extern class Fl_Window_Type Fl_Window_type;
  875. extern class Fl_Widget_Class_Type Fl_Widget_Class_type;
  876. extern class Fl_Group_Type Fl_Group_type;
  877. extern class Fl_Pack_Type Fl_Pack_type;
  878. extern class Fl_Tabs_Type Fl_Tabs_type;
  879. extern class Fl_Scroll_Type Fl_Scroll_type;
  880. extern class Fl_Table_Type Fl_Table_type;
  881. extern class Fl_Tile_Type Fl_Tile_type;
  882. extern class Fl_Input_Choice_Type Fl_Input_Choice_type;
  883. extern class Fl_Choice_Type Fl_Choice_type;
  884. extern class Fl_Menu_Bar_Type Fl_Menu_Bar_type;
  885. extern class Fl_Menu_Button_Type Fl_Menu_Button_type;
  886. extern class Fl_Menu_Item_Type Fl_Menu_Item_type;
  887. extern class Fl_Submenu_Type Fl_Submenu_type;
  888. extern class Fl_Wizard_Type Fl_Wizard_type;
  889. extern void select(Fl_Type *,int);
  890. extern void select_only(Fl_Type *);
  891. #include <FL/Fl_Window.H>
  892. static void cb(Fl_Widget *, void *v) {
  893. undo_checkpoint();
  894. undo_suspend();
  895. Fl_Type *t = ((Fl_Type*)v)->make();
  896. if (t) {
  897. if (t->is_widget() && !t->is_window()) {
  898. Fl_Widget_Type *wt = (Fl_Widget_Type *)t;
  899. // Set font sizes...
  900. wt->o->labelsize(Fl_Widget_Type::default_size);
  901. Fl_Font f;
  902. int s = Fl_Widget_Type::default_size;
  903. Fl_Color c;
  904. wt->textstuff(2, f, s, c);
  905. // Resize and/or reposition new widget...
  906. int w = 0, h = 0;
  907. wt->ideal_size(w, h);
  908. if (!strcmp(wt->type_name(), "Fl_Menu_Bar")) {
  909. // Move and resize the menubar across the top of the window...
  910. wt->o->resize(0, 0, w, h);
  911. } else {
  912. // Just resize to the ideal size...
  913. wt->o->size(w, h);
  914. }
  915. }
  916. select_only(t);
  917. set_modflag(1);
  918. t->open();
  919. } else {
  920. undo_current --;
  921. undo_last --;
  922. }
  923. undo_resume();
  924. }
  925. Fl_Menu_Item New_Menu[] = {
  926. {"Code",0,0,0,FL_SUBMENU},
  927. {"Function/Method",0,cb,(void*)&Fl_Function_type},
  928. {"Code",0,cb,(void*)&Fl_Code_type},
  929. {"Code Block",0,cb,(void*)&Fl_CodeBlock_type},
  930. {"Declaration",0,cb,(void*)&Fl_Decl_type},
  931. {"Declaration Block",0,cb,(void*)&Fl_DeclBlock_type},
  932. {"Class",0,cb,(void*)&Fl_Class_type},
  933. {"Widget Class",0,cb,(void*)&Fl_Widget_Class_type},
  934. {"Comment",0,cb,(void*)&Fl_Comment_type},
  935. {"Binary Data",0,cb,(void*)&Fl_Data_type},
  936. {0},
  937. {"Group",0,0,0,FL_SUBMENU},
  938. {0,0,cb,(void*)&Fl_Window_type},
  939. {0,0,cb,(void*)&Fl_Group_type},
  940. {0,0,cb,(void*)&Fl_Pack_type},
  941. {0,0,cb,(void*)&Fl_Tabs_type},
  942. {0,0,cb,(void*)&Fl_Scroll_type},
  943. {0,0,cb,(void*)&Fl_Table_type},
  944. {0,0,cb,(void*)&Fl_Tile_type},
  945. {0,0,cb,(void*)&Fl_Wizard_type},
  946. {0},
  947. {"Buttons",0,0,0,FL_SUBMENU},
  948. {0,0,cb,(void*)&Fl_Button_type},
  949. {0,0,cb,(void*)&Fl_Return_Button_type},
  950. {0,0,cb,(void*)&Fl_Light_Button_type},
  951. {0,0,cb,(void*)&Fl_Check_Button_type},
  952. {0,0,cb,(void*)&Fl_Repeat_Button_type},
  953. {0,0,cb,(void*)&Fl_Round_Button_type},
  954. {0},
  955. {"Valuators",0,0,0,FL_SUBMENU},
  956. {0,0,cb,(void*)&Fl_Slider_type},
  957. {0,0,cb,(void*)&Fl_Scrollbar_type},
  958. {0,0,cb,(void*)&Fl_Value_Slider_type},
  959. {0,0,cb,(void*)&Fl_Adjuster_type},
  960. {0,0,cb,(void*)&Fl_Counter_type},
  961. {0,0,cb,(void*)&Fl_Spinner_type},
  962. {0,0,cb,(void*)&Fl_Dial_type},
  963. {0,0,cb,(void*)&Fl_Roller_type},
  964. {0,0,cb,(void*)&Fl_Value_Input_type},
  965. {0,0,cb,(void*)&Fl_Value_Output_type},
  966. {0},
  967. {"Text",0,0,0,FL_SUBMENU},
  968. {0,0,cb,(void*)&Fl_File_Input_type},
  969. {0,0,cb,(void*)&Fl_Input_type},
  970. {0,0,cb,(void*)&Fl_Output_type},
  971. {0,0,cb,(void*)&Fl_Text_Display_type},
  972. {0,0,cb,(void*)&Fl_Text_Editor_type},
  973. {0},
  974. {"Menus",0,0,0,FL_SUBMENU},
  975. {0,0,cb,(void*)&Fl_Menu_Bar_type},
  976. {0,0,cb,(void*)&Fl_Menu_Button_type},
  977. {0,0,cb,(void*)&Fl_Choice_type},
  978. {0,0,cb,(void*)&Fl_Input_Choice_type},
  979. {0,0,cb, (void*)&Fl_Submenu_type},
  980. {0,0,cb, (void*)&Fl_Menu_Item_type},
  981. {0},
  982. {"Browsers",0,0,0,FL_SUBMENU},
  983. {0,0,cb,(void*)&Fl_Browser_type},
  984. {0,0,cb,(void*)&Fl_Check_Browser_type},
  985. {0,0,cb,(void*)&Fl_File_Browser_type},
  986. {0,0,cb,(void*)&Fl_Tree_type},
  987. {0},
  988. {"Other",0,0,0,FL_SUBMENU},
  989. {0,0,cb,(void*)&Fl_Box_type},
  990. {0,0,cb,(void*)&Fl_Clock_type},
  991. {0,0,cb,(void*)&Fl_Help_View_type},
  992. {0,0,cb,(void*)&Fl_Progress_type},
  993. {0},
  994. {0}};
  995. #include <FL/Fl_Multi_Label.H>
  996. // modify a menuitem to display an icon in front of the label
  997. static void make_iconlabel( Fl_Menu_Item *mi, Fl_Image *ic, const char *txt )
  998. {
  999. if (ic) {
  1000. char *t1 = new char[strlen(txt)+6];
  1001. strcpy( t1, " " );
  1002. strcat(t1, txt);
  1003. strcat(t1, "...");
  1004. mi->image( ic );
  1005. Fl_Multi_Label *ml = new Fl_Multi_Label;
  1006. ml->labela = (char*)ic;
  1007. ml->labelb = t1;
  1008. ml->typea = _FL_IMAGE_LABEL;
  1009. ml->typeb = FL_NORMAL_LABEL;
  1010. ml->label( mi );
  1011. }
  1012. else if (txt!=mi->text)
  1013. mi->label(txt);
  1014. }
  1015. void fill_in_New_Menu() {
  1016. for (unsigned i = 0; i < sizeof(New_Menu)/sizeof(*New_Menu); i++) {
  1017. Fl_Menu_Item *m = New_Menu+i;
  1018. if (m->user_data()) {
  1019. Fl_Type *t = (Fl_Type*)m->user_data();
  1020. if (m->text) {
  1021. make_iconlabel( m, pixmap[t->pixmapID()], m->label() );
  1022. } else {
  1023. const char *n = t->type_name();
  1024. if (!strncmp(n,"Fl_",3)) n += 3;
  1025. if (!strncmp(n,"fltk::",6)) n += 6;
  1026. make_iconlabel( m, pixmap[t->pixmapID()], n );
  1027. }
  1028. }
  1029. }
  1030. }
  1031. // use keyword to pick the type, this is used to parse files:
  1032. int reading_file;
  1033. Fl_Type *Fl_Type_make(const char *tn) {
  1034. reading_file = 1; // makes labels be null
  1035. Fl_Type *r = 0;
  1036. for (unsigned i = 0; i < sizeof(New_Menu)/sizeof(*New_Menu); i++) {
  1037. Fl_Menu_Item *m = New_Menu+i;
  1038. if (!m->user_data()) continue;
  1039. Fl_Type *t = (Fl_Type*)(m->user_data());
  1040. if (!strcasecmp(tn,t->type_name())) {r = t->make(); break;}
  1041. if (!strcasecmp(tn,t->alt_type_name())) {r = t->make(); break;}
  1042. }
  1043. reading_file = 0;
  1044. return r;
  1045. }
  1046. //
  1047. // End of "$Id: factory.cxx 8172 2011-01-03 08:28:38Z matt $".
  1048. //