fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

template_panel.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // FLUID template support for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2017 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 // generated by Fast Light User Interface Designer (fluid) version 1.0305
20 
21 #include "template_panel.h"
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include "../src/flstring.h"
25 #include <errno.h>
26 #include <FL/filename.H>
27 #include <FL/fl_ask.H>
28 #include <FL/Fl_Shared_Image.H>
29 #include <FL/Fl_Preferences.H>
30 #if defined(WIN32) && !defined(__CYGWIN__)
31 #include <io.h>
32 #else
33 #include <unistd.h>
34 #endif // WIN32 && !__CYGWIN__
36 
38 
39 static void cb_template_panel(Fl_Double_Window*, void*) {
41 if (img) img->release();
43 
45 template_name->value("");
48 }
49 
51 
52 static void cb_template_browser(Fl_Browser*, void*) {
53  if (Fl::event_clicks()) {
55  return;
56 }
58 if (img) img->release();
61 
62 int item = template_browser->value();
63 
64 if (item <= 1) template_instance->deactivate();
66 
67 if (item < 1) {
70  return;
71 }
72 
74 
75 const char *flfile = (const char *)template_browser->data(item);
76 if (!flfile) {
78  return;
79 }
80 
82 
84 
85 char pngfile[1024], *ext;
86 
87 strlcpy(pngfile, flfile, sizeof(pngfile));
88 if ((ext = strrchr(pngfile, '.')) == NULL) return;
89 strcpy(ext, ".png");
90 
91 img = Fl_Shared_Image::get(pngfile);
92 
93 if (img) {
94  template_preview->image(img);
96 };
97 }
98 
100 
102 
103 static void cb_template_name(Fl_Input*, void*) {
104  if (strlen(template_name->value())) {
107 } else template_submit->deactivate();
108 }
109 
111 
113 
114 static void cb_Cancel(Fl_Button*, void*) {
116 if (img) img->release();
118 
120 template_name->value("");
123 }
124 
126 
127 static void cb_template_submit(Fl_Return_Button*, void*) {
129 if (img) img->release();
131 
133 }
134 
136  { template_panel = new Fl_Double_Window(460, 355, "New/Save Template");
138  { template_browser = new Fl_Browser(10, 28, 180, 250, "Available Templates:");
144  } // Fl_Browser* template_browser
145  { template_preview = new Fl_Box(200, 28, 250, 250);
149  } // Fl_Box* template_preview
150  { template_name = new Fl_Input(198, 288, 252, 25, "Template Name:");
154  template_name->when(3);
155  } // Fl_Input* template_name
156  { template_instance = new Fl_Input(198, 288, 252, 25, "Instance Name:");
160  } // Fl_Input* template_instance
161  { Fl_Group* o = new Fl_Group(10, 323, 440, 25);
162  { template_delete = new Fl_Button(10, 323, 143, 25, "Delete Template");
164  } // Fl_Button* template_delete
165  { Fl_Box* o = new Fl_Box(153, 323, 126, 25);
167  } // Fl_Box* o
168  { Fl_Button* o = new Fl_Button(289, 323, 72, 25, "Cancel");
170  } // Fl_Button* o
171  { template_submit = new Fl_Return_Button(371, 323, 79, 25, "Save");
173  } // Fl_Return_Button* template_submit
174  o->end();
175  } // Fl_Group* o
177  template_panel->end();
178  } // Fl_Double_Window* template_panel
179  return template_panel;
180 }
181 
183  int i;
184  void *filename;
185 
186  for (i = 1; i <= template_browser->size(); i ++) {
187  if ((filename = template_browser->data(i)) != NULL) free(filename);
188  }
189 
192 }
193 
194 void template_delete_cb(Fl_Button *, void *) {
195  int item = template_browser->value();
196  if (item < 1) return;
197 
198  const char *name = template_browser->text(item);
199  const char *flfile = (const char *)template_browser->data(item);
200  if (!flfile) return;
201 
202  if (!fl_choice("Are you sure you want to delete the template \"%s\"?",
203  "Cancel", "Delete", 0, name)) return;
204 
205  if (unlink(flfile)) {
206  fl_alert("Unable to delete template \"%s\":\n%s", name, strerror(errno));
207  return;
208  }
209 
210  template_browser->remove(item);
212 }
213 
215  int i;
216  char name[1024], filename[1024], path[1024], *ptr;
217  struct dirent **files;
218  int num_files;
219 
220  fluid_prefs.getUserdataPath(path, sizeof(path));
221  strlcat(path, "templates", sizeof(path));
222 
223  num_files = fl_filename_list(path, &files);
224 
225  for (i = 0; i < num_files; i ++) {
226  if (fl_filename_match(files[i]->d_name, "*.fl")) {
227  // Format the name as the filename with "_" replaced with " "
228  // and without the trailing ".fl"...
229  strlcpy(name, files[i]->d_name, sizeof(name));
230  *strstr(name, ".fl") = '\0';
231 
232  for (ptr = name; *ptr; ptr ++) {
233  if (*ptr == '_') *ptr = ' ';
234  }
235 
236  // Add the template to the browser...
237  snprintf(filename, sizeof(filename), "%s/%s", path, files[i]->d_name);
238  template_browser->add(name, strdup(filename));
239  }
240 
241  free(files[i]);
242  }
243 
244  if (num_files > 0) free(files);
245 }
246 
247 //
248 // End of "$Id$".
249 //
make_template_panel
Fl_Double_Window * make_template_panel()
Definition: template_panel.cxx:135
FL_Enter
#define FL_Enter
The enter key.
Definition: Enumerations.H:471
template_delete
Fl_Button * template_delete
Definition: template_panel.cxx:112
Fl_Widget::activate
void activate()
Definition: Fl_Widget.cxx:241
Fl_Widget::align
Fl_Align align() const
Definition: Fl_Widget.H:348
Fl_Group::end
void end()
Definition: Fl_Group.cxx:75
cb_template_panel
static void cb_template_panel(Fl_Double_Window *, void *)
Definition: template_panel.cxx:39
fluid_prefs
Fl_Preferences fluid_prefs
fl_ask.H
template_delete_cb
void template_delete_cb(Fl_Button *, void *)
Definition: template_panel.cxx:194
Fl_Input_::value
int value(const char *)
Definition: Fl_Input_.cxx:1284
cb_template_browser
static void cb_template_browser(Fl_Browser *, void *)
Definition: template_panel.cxx:52
Fl_Button
Buttons generate callbacks when they are clicked by the user.
Definition: Fl_Button.H:79
Fl_Widget::labelfont
Fl_Font labelfont() const
Definition: Fl_Widget.H:487
template_name
Fl_Input * template_name
Definition: template_panel.cxx:101
filename.H
free
void free()
Fl_Browser::value
int value() const
Definition: Fl_Browser.cxx:826
NULL
#define NULL
Definition: forms.H:34
Fl_Preferences::getUserdataPath
char getUserdataPath(char *path, int pathlen)
Creates a path that is related to the preferences file and that is usable for additional application ...
Definition: Fl_Preferences.cxx:885
Fl_Browser::remove
void remove(int line)
Definition: Fl_Browser.cxx:229
cb_template_submit
static void cb_template_submit(Fl_Return_Button *, void *)
Definition: template_panel.cxx:127
Fl_Widget::when
Fl_When when() const
Definition: Fl_Widget.H:621
Fl_Widget::do_callback
void do_callback()
Definition: Fl_Widget.H:861
Fl_Browser
Definition: Fl_Browser.H:80
Fl::event_key
static int event_key()
Definition: Fl.H:723
Fl_Callback
void() Fl_Callback(Fl_Widget *, void *)
Definition: Fl_Widget.H:49
snprintf
#define snprintf
Definition: flstring.h:64
fl_choice
int fl_choice(const char *q, const char *b0, const char *b1, const char *b2,...)
Definition: fl_ask.cxx:459
Fl_Browser_::deselect
int deselect(int docallbacks=0)
Definition: Fl_Browser_.cxx:650
FL_ALIGN_INSIDE
const Fl_Align FL_ALIGN_INSIDE
Definition: Enumerations.H:843
Fl_Browser::text
const char * text(int line) const
Definition: Fl_Browser.cxx:722
FL_ALIGN_TOP_LEFT
const Fl_Align FL_ALIGN_TOP_LEFT
Definition: Enumerations.H:858
template_preview
Fl_Box * template_preview
Definition: template_panel.cxx:99
fl_filename_match
int fl_filename_match(const char *name, const char *pattern)
Definition: filename_match.cxx:44
fl_filename_list
int fl_filename_list(const char *d, dirent ***list, Fl_File_Sort_F *sort)
Definition: filename_list.cxx:75
filename
static const char * filename
Definition: fluid.cxx:119
Fl_Window::set_modal
void set_modal()
Definition: Fl_Window.H:289
template_load
void template_load()
Definition: template_panel.cxx:214
strlcpy
#define strlcpy
Definition: flstring.h:84
Fl_Return_Button
Definition: Fl_Return_Button.H:33
Fl_Double_Window::hide
void hide()
Definition: Fl_Double_Window.cxx:505
Fl_Widget::hide
virtual void hide()
Definition: Fl_Widget.cxx:283
Fl_Input
Definition: Fl_Input.H:222
Fl_Widget::redraw
void redraw()
Definition: Fl.cxx:1782
Fl_Widget::deactivate
void deactivate()
Definition: Fl_Widget.cxx:253
Fl_Group
Definition: Fl_Group.H:41
Fl_Group::current
static Fl_Group * current()
Definition: Fl_Group.cxx:84
Fl_Widget::box
Fl_Boxtype box() const
Definition: Fl_Widget.H:363
Fl_Input_::textfont
Fl_Font textfont() const
Definition: Fl_Input_.H:386
template_browser
Fl_Browser * template_browser
Definition: template_panel.cxx:50
cb_Cancel
static void cb_Cancel(Fl_Button *, void *)
Definition: template_panel.cxx:114
Fl_Shared_Image.H
Fl_Box
Definition: Fl_Box.H:34
Fl::event_clicks
static int event_clicks()
Definition: Fl.H:645
Fl_Shared_Image::get
static Fl_Shared_Image * get(const char *name, int W=0, int H=0)
Definition: Fl_Shared_Image.cxx:541
Fl_Widget::callback
Fl_Callback_p callback() const
Definition: Fl_Widget.H:561
Fl_Browser::add
void add(const char *newtext, void *d=0)
Definition: Fl_Browser.cxx:710
template_clear
void template_clear()
Definition: template_panel.cxx:182
Fl_Double_Window
Definition: Fl_Double_Window.H:40
template_instance
Fl_Input * template_instance
Definition: template_panel.cxx:110
Fl_Preferences
Fl_Preferences provides methods to store user settings between application starts.
Definition: Fl_Preferences.H:60
Fl_Widget::type
uchar type() const
Definition: Fl_Widget.H:274
cb_template_name
static void cb_template_name(Fl_Input *, void *)
Definition: template_panel.cxx:103
Fl_Preferences.H
Fl_Browser::clear
void clear()
Definition: Fl_Browser.cxx:685
Fl_Browser::data
void * data(int line) const
Definition: Fl_Browser.cxx:735
template_panel
Fl_Double_Window * template_panel
Definition: template_panel.cxx:37
strlcat
#define strlcat
Definition: flstring.h:79
Fl_Align
unsigned Fl_Align
Definition: Enumerations.H:828
Fl_Browser::size
int size() const
Definition: Fl_Browser.H:141
name
static const char * name
Definition: Fl_arg.cxx:53
fl_alert
void fl_alert(const char *,...)
Definition: fl_ask.cxx:361
Fl_Shared_Image
Definition: Fl_Shared_Image.H:50
dirent
#define dirent
Definition: numericsort.c:31
template_panel.h
Fl_Shared_Image::release
void release()
Definition: Fl_Shared_Image.cxx:230
Fl_Widget::image
Fl_Image * image()
Definition: Fl_Widget.H:514
Fl_Group::resizable
void resizable(Fl_Widget &o)
Definition: Fl_Group.H:117
template_submit
Fl_Return_Button * template_submit
Definition: template_panel.cxx:125
FL_THIN_DOWN_BOX
see figure 1
Definition: Enumerations.H:612