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.

1125 lines
37KB

  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_Help_View.H>
  595. class Fl_Help_View_Type : public Fl_Widget_Type {
  596. public:
  597. virtual void ideal_size(int &w, int &h) {
  598. Fl_Help_View *myo = (Fl_Help_View *)o;
  599. fl_font(myo->textfont(), myo->textsize());
  600. h -= Fl::box_dh(o->box());
  601. w -= Fl::box_dw(o->box());
  602. int ww = (int)fl_width('m');
  603. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  604. h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
  605. Fl::box_dh(o->box());
  606. if (h < 30) h = 30;
  607. if (w < 50) w = 50;
  608. }
  609. virtual const char *type_name() {return "Fl_Help_View";}
  610. virtual const char *alt_type_name() {return "fltk::HelpView";}
  611. Fl_Widget *widget(int x,int y,int w,int h) {
  612. Fl_Help_View *myo = new Fl_Help_View(x,y,w,h);
  613. if (!compile_only) {
  614. myo->value("<HTML><BODY><H1>Fl_Help_View Widget</H1>"
  615. "<P>This is a Fl_Help_View widget.</P></BODY></HTML>");
  616. }
  617. return myo;}
  618. Fl_Widget_Type *_make() {return new Fl_Help_View_Type();}
  619. int pixmapID() { return 35; }
  620. };
  621. static Fl_Help_View_Type Fl_Help_View_type;
  622. ////////////////////////////////////////////////////////////////
  623. #include <FL/Fl_Progress.H>
  624. class Fl_Progress_Type : public Fl_Widget_Type {
  625. public:
  626. virtual const char *type_name() {return "Fl_Progress";}
  627. virtual const char *alt_type_name() {return "fltk::ProgressBar";}
  628. Fl_Widget *widget(int x,int y,int w,int h) {
  629. Fl_Progress *myo = new Fl_Progress(x,y,w,h,"label");
  630. myo->value(50);
  631. return myo;}
  632. Fl_Widget_Type *_make() {return new Fl_Progress_Type();}
  633. int pixmapID() { return 36; }
  634. };
  635. static Fl_Progress_Type Fl_Progress_type;
  636. ////////////////////////////////////////////////////////////////
  637. #include <FL/Fl_Adjuster.H>
  638. class Fl_Adjuster_Type : public Fl_Widget_Type {
  639. int is_valuator() const {return 1;}
  640. public:
  641. virtual const char *type_name() {return "Fl_Adjuster";}
  642. virtual const char *alt_type_name() {return "fltk::Adjuster";}
  643. Fl_Widget *widget(int x,int y,int w,int h) {
  644. return new Fl_Adjuster(x,y,w,h);}
  645. Fl_Widget_Type *_make() {return new Fl_Adjuster_Type();}
  646. int pixmapID() { return 40; }
  647. };
  648. static Fl_Adjuster_Type Fl_Adjuster_type;
  649. ////////////////////////////////////////////////////////////////
  650. #include <FL/Fl_Dial.H>
  651. static Fl_Menu_Item dial_type_menu[] = {
  652. {"Dot",0,0,(void*)0},
  653. {"Line",0,0,(void*)FL_LINE_DIAL},
  654. {"Fill",0,0,(void*)FL_FILL_DIAL},
  655. {0}};
  656. class Fl_Dial_Type : public Fl_Widget_Type {
  657. Fl_Menu_Item *subtypes() {return dial_type_menu;}
  658. int is_valuator() const {return 1;}
  659. public:
  660. virtual const char *type_name() {return "Fl_Dial";}
  661. virtual const char *alt_type_name() {return "fltk::Dial";}
  662. Fl_Widget *widget(int x,int y,int w,int h) {
  663. return new Fl_Dial(x,y,w,h);}
  664. Fl_Widget_Type *_make() {return new Fl_Dial_Type();}
  665. int pixmapID() { return 42; }
  666. };
  667. static Fl_Dial_Type Fl_Dial_type;
  668. ////////////////////////////////////////////////////////////////
  669. #include <FL/Fl_Roller.H>
  670. static Fl_Menu_Item roller_type_menu[] = {
  671. {"Vertical",0,0,(void*)0},
  672. {"Horizontal",0,0,(void*)FL_HORIZONTAL},
  673. {0}};
  674. class Fl_Roller_Type : public Fl_Widget_Type {
  675. Fl_Menu_Item *subtypes() {return roller_type_menu;}
  676. int is_valuator() const {return 1;}
  677. public:
  678. virtual const char *type_name() {return "Fl_Roller";}
  679. virtual const char *alt_type_name() {return "fltk::Roller";}
  680. Fl_Widget *widget(int x,int y,int w,int h) {
  681. return new Fl_Roller(x,y,w,h);}
  682. Fl_Widget_Type *_make() {return new Fl_Roller_Type();}
  683. int pixmapID() { return 43; }
  684. };
  685. static Fl_Roller_Type Fl_Roller_type;
  686. ////////////////////////////////////////////////////////////////
  687. #include <FL/Fl_Scrollbar.H>
  688. static Fl_Menu_Item slider_type_menu[] = {
  689. {"Vertical",0,0,(void*)FL_VERT_SLIDER},
  690. {"Horizontal",0,0,(void*)FL_HOR_SLIDER},
  691. {"Vert Fill",0,0,(void*)FL_VERT_FILL_SLIDER},
  692. {"Horz Fill",0,0,(void*)FL_HOR_FILL_SLIDER},
  693. {"Vert Knob",0,0,(void*)FL_VERT_NICE_SLIDER},
  694. {"Horz Knob",0,0,(void*)FL_HOR_NICE_SLIDER},
  695. {0}};
  696. class Fl_Slider_Type : public Fl_Widget_Type {
  697. Fl_Menu_Item *subtypes() {return slider_type_menu;}
  698. int is_valuator() const {return 2;}
  699. public:
  700. virtual const char *type_name() {return "Fl_Slider";}
  701. virtual const char *alt_type_name() {return "fltk::Slider";}
  702. Fl_Widget *widget(int x,int y,int w,int h) {
  703. return new Fl_Slider(x,y,w,h,"slider:");}
  704. Fl_Widget_Type *_make() {return new Fl_Slider_Type();}
  705. int pixmapID() { return 37; }
  706. };
  707. static Fl_Slider_Type Fl_Slider_type;
  708. static Fl_Menu_Item scrollbar_type_menu[] = {
  709. {"Vertical",0,0,(void*)FL_VERT_SLIDER},
  710. {"Horizontal",0,0,(void*)FL_HOR_SLIDER},
  711. {0}};
  712. class Fl_Scrollbar_Type : public Fl_Slider_Type {
  713. Fl_Menu_Item *subtypes() {return scrollbar_type_menu;}
  714. int is_valuator() const {return 3;}
  715. public:
  716. virtual const char *type_name() {return "Fl_Scrollbar";}
  717. virtual const char *alt_type_name() {return "fltk::Scrollbar";}
  718. Fl_Widget *widget(int x,int y,int w,int h) {
  719. return new Fl_Scrollbar(x,y,w,h);}
  720. Fl_Widget_Type *_make() {return new Fl_Scrollbar_Type();}
  721. int pixmapID() { return 38; }
  722. };
  723. static Fl_Scrollbar_Type Fl_Scrollbar_type;
  724. ////////////////////////////////////////////////////////////////
  725. #include <FL/Fl_Output.H>
  726. static Fl_Menu_Item output_type_menu[] = {
  727. {"Normal",0,0,(void*)FL_NORMAL_OUTPUT},
  728. {"Multiline",0,0,(void*)FL_MULTILINE_OUTPUT},
  729. {0}};
  730. class Fl_Output_Type : public Fl_Input_Type {
  731. Fl_Menu_Item *subtypes() {return output_type_menu;}
  732. public:
  733. virtual void ideal_size(int &w, int &h) {
  734. Fl_Output *myo = (Fl_Output *)o;
  735. fl_font(myo->textfont(), myo->textsize());
  736. h = fl_height() + myo->textsize() - 6;
  737. w -= Fl::box_dw(o->box());
  738. int ww = (int)fl_width('m');
  739. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  740. if (h < 15) h = 15;
  741. if (w < 15) w = 15;
  742. }
  743. virtual const char *type_name() {return "Fl_Output";}
  744. virtual const char *alt_type_name() {return "fltk::Output";}
  745. Fl_Widget *widget(int x,int y,int w,int h) {
  746. Fl_Output *myo = new Fl_Output(x,y,w,h,"output:");
  747. myo->value("Text Output");
  748. return myo;
  749. }
  750. Fl_Widget_Type *_make() {return new Fl_Output_Type();}
  751. int pixmapID() { return 27; }
  752. };
  753. static Fl_Output_Type Fl_Output_type;
  754. ////////////////////////////////////////////////////////////////
  755. #include <FL/Fl_Value_Input.H>
  756. class Fl_Value_Input_Type : public Fl_Widget_Type {
  757. public:
  758. virtual void ideal_size(int &w, int &h) {
  759. Fl_Value_Input *myo = (Fl_Value_Input *)o;
  760. fl_font(myo->textfont(), myo->textsize());
  761. h = fl_height() + myo->textsize() - 6;
  762. w -= Fl::box_dw(o->box());
  763. int ww = (int)fl_width('m');
  764. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  765. if (h < 15) h = 15;
  766. if (w < 15) w = 15;
  767. }
  768. virtual const char *type_name() {return "Fl_Value_Input";}
  769. virtual const char *alt_type_name() {return "fltk::ValueInput";}
  770. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  771. int is_valuator() const {return 1;}
  772. int is_value_input() const {return 1;}
  773. Fl_Widget *widget(int x,int y,int w,int h) {
  774. Fl_Value_Input *myo = new Fl_Value_Input(x,y,w,h,"value:");
  775. return myo;
  776. }
  777. Fl_Widget_Type *_make() {return new Fl_Value_Input_Type();}
  778. int pixmapID() { return 44; }
  779. };
  780. static Fl_Value_Input_Type Fl_Value_Input_type;
  781. int Fl_Value_Input_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  782. Fl_Value_Input *myo = (Fl_Value_Input*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  783. switch (w) {
  784. case 4:
  785. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  786. case 1: myo->textfont(f); break;
  787. case 2: myo->textsize(s); break;
  788. case 3: myo->textcolor(c); break;
  789. }
  790. return 1;
  791. }
  792. ////////////////////////////////////////////////////////////////
  793. #include <FL/Fl_Value_Output.H>
  794. class Fl_Value_Output_Type : public Fl_Widget_Type {
  795. public:
  796. virtual void ideal_size(int &w, int &h) {
  797. Fl_Value_Output *myo = (Fl_Value_Output *)o;
  798. fl_font(myo->textfont(), myo->textsize());
  799. h = fl_height() + myo->textsize() - 6;
  800. w = o->w() - Fl::box_dw(o->box());
  801. int ww = (int)fl_width('m');
  802. w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
  803. if (h < 15) h = 15;
  804. if (w < 15) w = 15;
  805. }
  806. virtual const char *type_name() {return "Fl_Value_Output";}
  807. virtual const char *alt_type_name() {return "fltk::ValueOutput";}
  808. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  809. int is_valuator() const {return 1;}
  810. Fl_Widget *widget(int x,int y,int w,int h) {
  811. Fl_Value_Output *myo = new Fl_Value_Output(x,y,w,h,"value:");
  812. return myo;
  813. }
  814. Fl_Widget_Type *_make() {return new Fl_Value_Output_Type();}
  815. int pixmapID() { return 45; }
  816. };
  817. static Fl_Value_Output_Type Fl_Value_Output_type;
  818. int Fl_Value_Output_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  819. Fl_Value_Output *myo = (Fl_Value_Output*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  820. switch (w) {
  821. case 4:
  822. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  823. case 1: myo->textfont(f); break;
  824. case 2: myo->textsize(s); break;
  825. case 3: myo->textcolor(c); break;
  826. }
  827. return 1;
  828. }
  829. ////////////////////////////////////////////////////////////////
  830. #include <FL/Fl_Value_Slider.H>
  831. class Fl_Value_Slider_Type : public Fl_Slider_Type {
  832. int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
  833. public:
  834. virtual const char *type_name() {return "Fl_Value_Slider";}
  835. virtual const char *alt_type_name() {return "fltk::ValueSlider";}
  836. Fl_Widget *widget(int x,int y,int w,int h) {
  837. return new Fl_Value_Slider(x,y,w,h,"slider:");}
  838. Fl_Widget_Type *_make() {return new Fl_Value_Slider_Type();}
  839. int pixmapID() { return 39; }
  840. };
  841. static Fl_Value_Slider_Type Fl_Value_Slider_type;
  842. int Fl_Value_Slider_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
  843. Fl_Value_Slider *myo = (Fl_Value_Slider*)(w==4 ? ((Fl_Widget_Type*)factory)->o : o);
  844. switch (w) {
  845. case 4:
  846. case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
  847. case 1: myo->textfont(f); break;
  848. case 2: myo->textsize(s); break;
  849. case 3: myo->textcolor(c); break;
  850. }
  851. return 1;
  852. }
  853. ////////////////////////////////////////////////////////////////
  854. extern class Fl_Function_Type Fl_Function_type;
  855. extern class Fl_Code_Type Fl_Code_type;
  856. extern class Fl_CodeBlock_Type Fl_CodeBlock_type;
  857. extern class Fl_Data_Type Fl_Data_type;
  858. extern class Fl_Decl_Type Fl_Decl_type;
  859. extern class Fl_DeclBlock_Type Fl_DeclBlock_type;
  860. extern class Fl_Comment_Type Fl_Comment_type;
  861. extern class Fl_Class_Type Fl_Class_type;
  862. extern class Fl_Window_Type Fl_Window_type;
  863. extern class Fl_Widget_Class_Type Fl_Widget_Class_type;
  864. extern class Fl_Group_Type Fl_Group_type;
  865. extern class Fl_Pack_Type Fl_Pack_type;
  866. extern class Fl_Tabs_Type Fl_Tabs_type;
  867. extern class Fl_Scroll_Type Fl_Scroll_type;
  868. extern class Fl_Table_Type Fl_Table_type;
  869. extern class Fl_Tile_Type Fl_Tile_type;
  870. extern class Fl_Input_Choice_Type Fl_Input_Choice_type;
  871. extern class Fl_Choice_Type Fl_Choice_type;
  872. extern class Fl_Menu_Bar_Type Fl_Menu_Bar_type;
  873. extern class Fl_Menu_Button_Type Fl_Menu_Button_type;
  874. extern class Fl_Menu_Item_Type Fl_Menu_Item_type;
  875. extern class Fl_Submenu_Type Fl_Submenu_type;
  876. extern class Fl_Wizard_Type Fl_Wizard_type;
  877. extern void select(Fl_Type *,int);
  878. extern void select_only(Fl_Type *);
  879. #include <FL/Fl_Window.H>
  880. static void cb(Fl_Widget *, void *v) {
  881. undo_checkpoint();
  882. undo_suspend();
  883. Fl_Type *t = ((Fl_Type*)v)->make();
  884. if (t) {
  885. if (t->is_widget() && !t->is_window()) {
  886. Fl_Widget_Type *wt = (Fl_Widget_Type *)t;
  887. // Set font sizes...
  888. wt->o->labelsize(Fl_Widget_Type::default_size);
  889. Fl_Font f;
  890. int s = Fl_Widget_Type::default_size;
  891. Fl_Color c;
  892. wt->textstuff(2, f, s, c);
  893. // Resize and/or reposition new widget...
  894. int w = 0, h = 0;
  895. wt->ideal_size(w, h);
  896. if (!strcmp(wt->type_name(), "Fl_Menu_Bar")) {
  897. // Move and resize the menubar across the top of the window...
  898. wt->o->resize(0, 0, w, h);
  899. } else {
  900. // Just resize to the ideal size...
  901. wt->o->size(w, h);
  902. }
  903. }
  904. select_only(t);
  905. set_modflag(1);
  906. t->open();
  907. } else {
  908. undo_current --;
  909. undo_last --;
  910. }
  911. undo_resume();
  912. }
  913. Fl_Menu_Item New_Menu[] = {
  914. {"Code",0,0,0,FL_SUBMENU},
  915. {"Function/Method",0,cb,(void*)&Fl_Function_type},
  916. {"Code",0,cb,(void*)&Fl_Code_type},
  917. {"Code Block",0,cb,(void*)&Fl_CodeBlock_type},
  918. {"Declaration",0,cb,(void*)&Fl_Decl_type},
  919. {"Declaration Block",0,cb,(void*)&Fl_DeclBlock_type},
  920. {"Class",0,cb,(void*)&Fl_Class_type},
  921. {"Widget Class",0,cb,(void*)&Fl_Widget_Class_type},
  922. {"Comment",0,cb,(void*)&Fl_Comment_type},
  923. {"Binary Data",0,cb,(void*)&Fl_Data_type},
  924. {0},
  925. {"Group",0,0,0,FL_SUBMENU},
  926. {0,0,cb,(void*)&Fl_Window_type},
  927. {0,0,cb,(void*)&Fl_Group_type},
  928. {0,0,cb,(void*)&Fl_Pack_type},
  929. {0,0,cb,(void*)&Fl_Tabs_type},
  930. {0,0,cb,(void*)&Fl_Scroll_type},
  931. {0,0,cb,(void*)&Fl_Table_type},
  932. {0,0,cb,(void*)&Fl_Tile_type},
  933. {0,0,cb,(void*)&Fl_Wizard_type},
  934. {0},
  935. {"Buttons",0,0,0,FL_SUBMENU},
  936. {0,0,cb,(void*)&Fl_Button_type},
  937. {0,0,cb,(void*)&Fl_Return_Button_type},
  938. {0,0,cb,(void*)&Fl_Light_Button_type},
  939. {0,0,cb,(void*)&Fl_Check_Button_type},
  940. {0,0,cb,(void*)&Fl_Repeat_Button_type},
  941. {0,0,cb,(void*)&Fl_Round_Button_type},
  942. {0},
  943. {"Valuators",0,0,0,FL_SUBMENU},
  944. {0,0,cb,(void*)&Fl_Slider_type},
  945. {0,0,cb,(void*)&Fl_Scrollbar_type},
  946. {0,0,cb,(void*)&Fl_Value_Slider_type},
  947. {0,0,cb,(void*)&Fl_Adjuster_type},
  948. {0,0,cb,(void*)&Fl_Counter_type},
  949. {0,0,cb,(void*)&Fl_Spinner_type},
  950. {0,0,cb,(void*)&Fl_Dial_type},
  951. {0,0,cb,(void*)&Fl_Roller_type},
  952. {0,0,cb,(void*)&Fl_Value_Input_type},
  953. {0,0,cb,(void*)&Fl_Value_Output_type},
  954. {0},
  955. {"Text",0,0,0,FL_SUBMENU},
  956. {0,0,cb,(void*)&Fl_File_Input_type},
  957. {0,0,cb,(void*)&Fl_Input_type},
  958. {0,0,cb,(void*)&Fl_Output_type},
  959. {0,0,cb,(void*)&Fl_Text_Display_type},
  960. {0,0,cb,(void*)&Fl_Text_Editor_type},
  961. {0},
  962. {"Menus",0,0,0,FL_SUBMENU},
  963. {0,0,cb,(void*)&Fl_Menu_Bar_type},
  964. {0,0,cb,(void*)&Fl_Menu_Button_type},
  965. {0,0,cb,(void*)&Fl_Choice_type},
  966. {0,0,cb,(void*)&Fl_Input_Choice_type},
  967. {0,0,cb, (void*)&Fl_Submenu_type},
  968. {0,0,cb, (void*)&Fl_Menu_Item_type},
  969. {0},
  970. {"Browsers",0,0,0,FL_SUBMENU},
  971. {0,0,cb,(void*)&Fl_Browser_type},
  972. {0,0,cb,(void*)&Fl_Check_Browser_type},
  973. {0,0,cb,(void*)&Fl_File_Browser_type},
  974. {0,0,cb,(void*)&Fl_Tree_type},
  975. {0},
  976. {"Other",0,0,0,FL_SUBMENU},
  977. {0,0,cb,(void*)&Fl_Box_type},
  978. {0,0,cb,(void*)&Fl_Help_View_type},
  979. {0,0,cb,(void*)&Fl_Progress_type},
  980. {0},
  981. {0}};
  982. #include <FL/Fl_Multi_Label.H>
  983. // modify a menuitem to display an icon in front of the label
  984. static void make_iconlabel( Fl_Menu_Item *mi, Fl_Image *ic, const char *txt )
  985. {
  986. if (ic) {
  987. char *t1 = new char[strlen(txt)+6];
  988. strcpy( t1, " " );
  989. strcat(t1, txt);
  990. strcat(t1, "...");
  991. mi->image( ic );
  992. Fl_Multi_Label *ml = new Fl_Multi_Label;
  993. ml->labela = (char*)ic;
  994. ml->labelb = t1;
  995. ml->typea = _FL_IMAGE_LABEL;
  996. ml->typeb = FL_NORMAL_LABEL;
  997. ml->label( mi );
  998. }
  999. else if (txt!=mi->text)
  1000. mi->label(txt);
  1001. }
  1002. void fill_in_New_Menu() {
  1003. for (unsigned i = 0; i < sizeof(New_Menu)/sizeof(*New_Menu); i++) {
  1004. Fl_Menu_Item *m = New_Menu+i;
  1005. if (m->user_data()) {
  1006. Fl_Type *t = (Fl_Type*)m->user_data();
  1007. if (m->text) {
  1008. make_iconlabel( m, pixmap[t->pixmapID()], m->label() );
  1009. } else {
  1010. const char *n = t->type_name();
  1011. if (!strncmp(n,"Fl_",3)) n += 3;
  1012. if (!strncmp(n,"fltk::",6)) n += 6;
  1013. make_iconlabel( m, pixmap[t->pixmapID()], n );
  1014. }
  1015. }
  1016. }
  1017. }
  1018. // use keyword to pick the type, this is used to parse files:
  1019. int reading_file;
  1020. Fl_Type *Fl_Type_make(const char *tn) {
  1021. reading_file = 1; // makes labels be null
  1022. Fl_Type *r = 0;
  1023. for (unsigned i = 0; i < sizeof(New_Menu)/sizeof(*New_Menu); i++) {
  1024. Fl_Menu_Item *m = New_Menu+i;
  1025. if (!m->user_data()) continue;
  1026. Fl_Type *t = (Fl_Type*)(m->user_data());
  1027. if (!strcasecmp(tn,t->type_name())) {r = t->make(); break;}
  1028. if (!strcasecmp(tn,t->alt_type_name())) {r = t->make(); break;}
  1029. }
  1030. reading_file = 0;
  1031. return r;
  1032. }
  1033. //
  1034. // End of "$Id: factory.cxx 8172 2011-01-03 08:28:38Z matt $".
  1035. //