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.

244 lines
6.2KB

  1. # data file for the Fltk User Interface Designer (fluid)
  2. version 1.0300
  3. header_name {.h}
  4. code_name {.cxx}
  5. comment {//
  6. // "$Id$"
  7. //
  8. // FLUID template support for the Fast Light Tool Kit (FLTK).
  9. //
  10. // Copyright 1998-2010 by Bill Spitzak and others.
  11. //
  12. // This library is free software; you can redistribute it and/or
  13. // modify it under the terms of the GNU Library General Public
  14. // License as published by the Free Software Foundation; either
  15. // version 2 of the License, or (at your option) any later version.
  16. //
  17. // This library is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. // Library General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU Library General Public
  23. // License along with this library; if not, write to the Free Software
  24. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  25. // USA.
  26. //
  27. // Please report all bugs and problems on the following page:
  28. //
  29. // http://www.fltk.org/str.php
  30. //
  31. } {in_source in_header
  32. }
  33. decl {\#include <stdio.h>} {}
  34. decl {\#include <stdlib.h>} {}
  35. decl {\#include "../src/flstring.h"} {}
  36. decl {\#include <errno.h>} {}
  37. decl {\#include <FL/filename.H>} {}
  38. decl {\#include <FL/fl_ask.H>} {}
  39. decl {\#include <FL/Fl_Shared_Image.H>} {}
  40. decl {\#include <FL/Fl_Preferences.H>} {}
  41. declblock {\#if defined(WIN32) && !defined(__CYGWIN__)} {after {\#endif // WIN32 && !__CYGWIN__}
  42. } {
  43. decl {\#include <io.h>} {}
  44. decl {\#else} {}
  45. decl {\#include <unistd.h>} {}
  46. }
  47. decl {extern Fl_Preferences fluid_prefs;} {}
  48. Function {make_template_panel()} {} {
  49. Fl_Window template_panel {
  50. label {New/Save Template}
  51. callback {Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
  52. if (img) img->release();
  53. template_preview->image(0);
  54. template_browser->deselect();
  55. template_name->value("");
  56. template_instance->value("");
  57. template_panel->hide();} open
  58. xywh {340 237 460 355} type Double resizable modal visible
  59. } {
  60. Fl_Browser template_browser {
  61. label {Available Templates:}
  62. callback {if (Fl::event_clicks()) {
  63. template_panel->hide();
  64. return;
  65. }
  66. Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
  67. if (img) img->release();
  68. template_preview->image(0);
  69. template_preview->redraw();
  70. int item = template_browser->value();
  71. if (item <= 1) template_instance->deactivate();
  72. else template_instance->activate();
  73. if (item < 1) {
  74. template_submit->deactivate();
  75. template_delete->deactivate();
  76. return;
  77. }
  78. template_submit->activate();
  79. const char *flfile = (const char *)template_browser->data(item);
  80. if (!flfile) {
  81. template_delete->deactivate();
  82. return;
  83. }
  84. template_name->value(template_browser->text(item));
  85. template_delete->activate();
  86. char pngfile[1024], *ext;
  87. strlcpy(pngfile, flfile, sizeof(pngfile));
  88. if ((ext = strrchr(pngfile, '.')) == NULL) return;
  89. strcpy(ext, ".png");
  90. img = Fl_Shared_Image::get(pngfile);
  91. if (img) {
  92. template_preview->image(img);
  93. template_preview->redraw();
  94. }}
  95. xywh {10 28 180 250} type Hold labelfont 1 align 5 when 3
  96. }
  97. Fl_Box template_preview {
  98. xywh {200 28 250 250} box THIN_DOWN_BOX align 85 resizable
  99. }
  100. Fl_Input template_name {
  101. label {Template Name:}
  102. callback {if (strlen(template_name->value())) {
  103. template_submit->activate();
  104. if (Fl::event_key() == FL_Enter) template_panel->hide();
  105. } else template_submit->deactivate();}
  106. xywh {124 288 326 25} labelfont 1 when 3 textfont 4
  107. }
  108. Fl_Input template_instance {
  109. label {Instance Name:}
  110. xywh {124 288 326 25} labelfont 1 textfont 4 hide
  111. }
  112. Fl_Group {} {
  113. xywh {10 323 440 25}
  114. } {
  115. Fl_Button template_delete {
  116. label {Delete Template}
  117. callback template_delete_cb
  118. xywh {10 323 133 25}
  119. }
  120. Fl_Box {} {
  121. xywh {153 323 126 25} resizable
  122. }
  123. Fl_Button {} {
  124. label Cancel
  125. callback {Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
  126. if (img) img->release();
  127. template_preview->image(0);
  128. template_browser->deselect();
  129. template_name->value("");
  130. template_instance->value("");
  131. template_panel->hide();}
  132. xywh {289 323 72 25}
  133. }
  134. Fl_Return_Button template_submit {
  135. label Save
  136. callback {Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
  137. if (img) img->release();
  138. template_preview->image(0);
  139. template_panel->hide();}
  140. xywh {371 323 79 25}
  141. }
  142. }
  143. }
  144. }
  145. Function {template_clear()} {return_type void
  146. } {
  147. code {int i;
  148. void *filename;
  149. for (i = 1; i <= template_browser->size(); i ++) {
  150. if ((filename = template_browser->data(i)) != NULL) free(filename);
  151. }
  152. template_browser->deselect();
  153. template_browser->clear();} {}
  154. }
  155. Function {template_delete_cb(Fl_Button *, void *)} {selected return_type void
  156. } {
  157. code {int item = template_browser->value();
  158. if (item < 1) return;
  159. const char *name = template_browser->text(item);
  160. const char *flfile = (const char *)template_browser->data(item);
  161. if (!flfile) return;
  162. if (!fl_choice("Are you sure you want to delete the template \\"%s\\"?",
  163. "Cancel", "Delete", 0, name)) return;
  164. if (unlink(flfile)) {
  165. fl_alert("Unable to delete template \\"%s\\":\\n%s", name, strerror(errno));
  166. return;
  167. }
  168. template_browser->remove(item);
  169. template_browser->do_callback();} {}
  170. }
  171. Function {template_load()} {return_type void
  172. } {
  173. code {int i;
  174. char name[1024], filename[1024], path[1024], *ptr;
  175. struct dirent **files;
  176. int num_files;
  177. fluid_prefs.getUserdataPath(path, sizeof(path));
  178. strlcat(path, "templates", sizeof(path));
  179. num_files = fl_filename_list(path, &files);
  180. for (i = 0; i < num_files; i ++) {
  181. if (fl_filename_match(files[i]->d_name, "*.fl")) {
  182. // Format the name as the filename with "_" replaced with " "
  183. // and without the trailing ".fl"...
  184. strlcpy(name, files[i]->d_name, sizeof(name));
  185. *strstr(name, ".fl") = '\\0';
  186. for (ptr = name; *ptr; ptr ++) {
  187. if (*ptr == '_') *ptr = ' ';
  188. }
  189. // Add the template to the browser...
  190. snprintf(filename, sizeof(filename), "%s/%s", path, files[i]->d_name);
  191. template_browser->add(name, strdup(filename));
  192. }
  193. free(files[i]);
  194. }
  195. if (num_files > 0) free(files);} {}
  196. }
  197. comment {
  198. //
  199. // End of "$Id$".
  200. //} {in_source in_header
  201. }