summaryrefslogtreecommitdiff
path: root/branch-3.0-2011/examples
diff options
context:
space:
mode:
Diffstat (limited to 'branch-3.0-2011/examples')
-rw-r--r--branch-3.0-2011/examples/Makefile26
-rw-r--r--branch-3.0-2011/examples/README.examples122
-rw-r--r--branch-3.0-2011/examples/howto-add_fd-and-popen.cxx83
-rw-r--r--branch-3.0-2011/examples/howto-parse-args.cxx102
-rw-r--r--branch-3.0-2011/examples/howto-text-over-image-button.cxx91
-rw-r--r--branch-3.0-2011/examples/menubar-add.cxx93
-rw-r--r--branch-3.0-2011/examples/nativefilechooser-simple-app.cxx161
-rw-r--r--branch-3.0-2011/examples/table-as-container.cxx170
-rw-r--r--branch-3.0-2011/examples/table-simple.cxx129
-rw-r--r--branch-3.0-2011/examples/table-sort.cxx291
-rw-r--r--branch-3.0-2011/examples/table-spreadsheet-with-keyboard-nav.cxx350
-rw-r--r--branch-3.0-2011/examples/table-spreadsheet.cxx264
-rw-r--r--branch-3.0-2011/examples/tabs-simple.cxx92
-rw-r--r--branch-3.0-2011/examples/textdisplay-with-colors.cxx68
-rw-r--r--branch-3.0-2011/examples/texteditor-simple.cxx62
-rw-r--r--branch-3.0-2011/examples/tree-simple.cxx72
-rw-r--r--branch-3.0-2011/examples/wizard-simple.cxx90
17 files changed, 0 insertions, 2266 deletions
diff --git a/branch-3.0-2011/examples/Makefile b/branch-3.0-2011/examples/Makefile
deleted file mode 100644
index 3949df80a..000000000
--- a/branch-3.0-2011/examples/Makefile
+++ /dev/null
@@ -1,26 +0,0 @@
-include ../makeinclude
-
-ALL = howto-add_fd-and-popen$(EXEEXT) \
- howto-parse-args$(EXEEXT) \
- howto-text-over-image-button$(EXEEXT) \
- menubar-add$(EXEEXT) \
- nativefilechooser-simple-app$(EXEEXT) \
- table-as-container$(EXEEXT) \
- table-simple$(EXEEXT) \
- table-sort$(EXEEXT) \
- table-spreadsheet$(EXEEXT) \
- table-spreadsheet-with-keyboard-nav$(EXEEXT) \
- tabs-simple$(EXEEXT) \
- textdisplay-with-colors$(EXEEXT) \
- texteditor-simple$(EXEEXT) \
- tree-simple$(EXEEXT) \
- wizard-simple$(EXEEXT)
-
-# default target -- build everything
-default all: $(ALL)
-
-# clean everything
-clean:
- $(RM) $(ALL)
- $(RM) *.o
- $(RM) core
diff --git a/branch-3.0-2011/examples/README.examples b/branch-3.0-2011/examples/README.examples
deleted file mode 100644
index 6889eaad3..000000000
--- a/branch-3.0-2011/examples/README.examples
+++ /dev/null
@@ -1,122 +0,0 @@
-FLTK EXAMPLE PROGRAMS
----------------------
-
- This directory contains example FLTK programs that demonstrate
- recommended programming practices and techniques for FLTK application
- programmers. The "*-simple.cxx" files are a good starting point for
- those new to FLTK.
-
- The programs in this directory are NOT built automatically
- when you build FLTK; you have to manually build them.
-
- The goals of these example programs:
-
- o Show good programming style for app programmers to emulate
-
- o Show simple examples of how to use widgets to new users of FLTK.
-
- o Show intermediate or advanced examples of techniques often
- misused or hard to document
-
- o Demonstrate code that are FAQs on the newsgroup forum.
- (such as how to use threads, callbacks, etc)
-
- o Example code should be short, but not at the expense of clarity.
-
- o Where possible, examples should emphasize FLTK's simplicity.
-
-
-NEW SUBMISSIONS: RECOMMENDED PRACTICES
-
- These programs must follow FLTK coding style as defined in the FLTK
- "CMP" (Configuration Management Plan/Coding Standards).
-
- Example code should have the above goals in mind. The best examples
- are those that are as short and clear as possible; terse, but not
- at the expense of clarity.
-
- To avoid cluttering up the top level directory with ancillary files
- (such as image files or icons), examples that depend on more than
- just a .cxx/.h file pair should have their own subdirectory.
-
- Data files common to several examples should be located in the
- examples/data directory.
-
- Ancillary data files should be as small as possible, to keep the
- distribution tar files small. Avoid high resolution images or
- uncompressed images when possible.
-
- Examples that need large data sets (HD images, etc) should not
- be part of the FLTK distribution; they can be provided as separate
- packages (eg. as articles or external links).
-
- Some widgets have multiple capabilities that are best demonstrated
- separately. For instance, the table widget can be used as a
- custom data table, or as a spreadsheet, or as a widget container.
- So separate examples for each would be e.g. "table-custom-data.cxx",
- "table-spreadsheet.cxx", "table-widget-container.cxx", etc.
-
- Example programs should contain comments that help understand the
- concepts shown, but not so verbose as to dwarf the code or make
- the code hard to read. Within code, it's best to use single line
- comments to emphasize code that might be unclear. Let the code
- speak as much as possible.
-
- Examples programs may be referred to from the documentation
- as good examples on how to do particular programming techniques.
-
-
-NAMING CONVENTIONS
-
- Example programs that demonstrate a particular widget should start
- with that widget's name in lowercase, eg. "table.cxx" for Fl_Table.
-
- Demonstrations of a particular technique should start with
- "howto-xxx.cxx" to avoid naming conflicts with future widgets
- of the same name.
-
- xxx-simple.cxx -- Simplest possible example of widget xxx
- eg. table-simple.cxx
-
- xxx-<technique>.cxx -- A particular "technique" using widget xxx
- eg. "table-spreadsheet.cxx"
-
- howto-<technique>.cxx -- Demonstrate a particular technique, eg. "howto-threading.cxx"
-
- Some example programs may depend on multiple files. To avoid
- cluttering up the top level examples directory, such examples will
- have their own subdirectory with the files they depend on localized
- to that directory.
-
- Example programs should be as small as possible, to keep the
- distribution tar files small.
-
- Very large examples, or examples that depend on large data sets
- should be submitted as separate articles on the FLTK site, or as
- external links on the FLTK site's 'links' page.
-
-
-HISTORY
-
- Previous to FLTK 1.3.0, the fltk/test directory served the dual
- purpose of containing test suites as well as example code.
-
- But the fltk/test programs started becoming necessarily complex,
- testing for obscure problems, and not necessarily good demos for
- applications programmers.
-
- The fltk/examples directory was created in FLTK 1.3.0 to separate
- 'good programming examples' from the test suite code.
-
-
-DISCLAIMER
-
- The examples in this directory are provided 'as-is', without any express
- or implied warranty. In no event will the authors be held liable for
- any damages arising from the use of this software.
-
-
-BUGS
-
- If you find a bug, please report it through the fltk STR form at
- http://fltk.org/str.php
diff --git a/branch-3.0-2011/examples/howto-add_fd-and-popen.cxx b/branch-3.0-2011/examples/howto-add_fd-and-popen.cxx
deleted file mode 100644
index 19e9ae66f..000000000
--- a/branch-3.0-2011/examples/howto-add_fd-and-popen.cxx
+++ /dev/null
@@ -1,83 +0,0 @@
-//
-// "$Id$"
-//
-// How to use popen() and Fl::add_fd() - erco 10/04/04
-// Originally from erco's cheat sheet, permission by author.
-//
-// Shows how the interface can remain "alive" while external
-// command is running and outputing occassional data. For instance,
-// while the command is running, keyboard navigation works,
-// text can be highlighted, and the interface can be resized.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <stdio.h>
-#include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-#include <FL/Fl_Multi_Browser.H>
-
-#ifdef WIN32
-# define PING_CMD "ping -n 10 localhost" // 'slow command' under windows
-# ifdef _MSC_VER
-# define popen _popen
-# define pclose _pclose
-# else /*_MSC_VER*/
-# include <unistd.h> // non-MS win32 compilers (untested)
-# endif /*_MSC_VER*/
-#else
-# include <unistd.h>
-# define PING_CMD "ping -i 2 -c 10 localhost" // 'slow command' under unix
-#endif
-
-// GLOBALS
-FILE *G_fp = NULL;
-
-// Handler for add_fd() -- called whenever the ping command outputs a new line of data
-void HandleFD(int fd, void *data) {
- Fl_Multi_Browser *brow = (Fl_Multi_Browser*)data;
- char s[1024];
- if ( fgets(s, 1023, G_fp) == NULL ) { // read the line of data
- Fl::remove_fd(fileno(G_fp)); // command ended? disconnect callback
- pclose(G_fp); // close the descriptor
- brow->add(""); brow->add("<<DONE>>"); // append msg indicating command finished
- return;
- }
- brow->add(s); // line of data read? append to widget
-}
-
-int main(int argc, char *argv[]) {
- Fl_Window win(600,600);
- Fl_Multi_Browser brow(10,10,580,580);
- if ( ( G_fp = popen(PING_CMD, "r") ) == NULL ) { // start the external unix command
- perror("popen failed");
- return(1);
- }
- Fl::add_fd(fileno(G_fp), HandleFD, (void*)&brow); // setup a callback for the popen()ed descriptor
- win.resizable(brow);
- win.show(argc, argv);
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/howto-parse-args.cxx b/branch-3.0-2011/examples/howto-parse-args.cxx
deleted file mode 100644
index 15b3f4b74..000000000
--- a/branch-3.0-2011/examples/howto-parse-args.cxx
+++ /dev/null
@@ -1,102 +0,0 @@
-//
-// "$Id$"
-//
-// How to parse command line arguments - Duncan Gibson 2010-10-23
-// First posted in http://www.fltk.org/newsgroups.php?gfltk.general+v:31449
-//
-// Shows how to decode additional command line arguments using Fl::args()
-// on top of the "standard" options used by the toolkit itself.
-//
-// Note that this only handles "option separateValue" rather than the
-// usual *nix idiom of "option=value", and provides no validation nor
-// conversion of the paramter string into ints or floats.
-//
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <stdio.h>
-#include <string.h>
-#include <FL/Fl.H>
-#include <FL/Fl_Box.H>
-#include <FL/Fl_Window.H>
-
-int helpFlag = 0;
-char *optionString = 0;
-
-/*
- * callback function passed to Fl::args() to parse individual argument.
- * If there is a match, 'i' must be incremented by 2 or 1 as appropriate.
- * If there is no match, Fl::args() will then call Fl::arg() as fallback
- * to try to match the "standard" FLTK parameters.
- *
- * Returns 2 if argv[i] matches with required parameter in argv[i+1],
- * returns 1 if argv[i] matches on its own,
- * returns 0 if argv[i] does not match.
- */
-int arg(int argc, char **argv, int &i)
-{
- if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
- helpFlag = 1;
- i += 1;
- return 1;
- }
- if (strcmp("-o", argv[i]) == 0 || strcmp("--option", argv[i]) == 0) {
- if (i < argc-1 && argv[i+1] != 0) {
- optionString = argv[i+1];
- i += 2;
- return 2;
- }
- }
- return 0;
-}
-
-int main(int argc, char** argv)
-{
- int i = 1;
- if (Fl::args(argc, argv, i, arg) < argc)
- // note the concatenated strings to give a single format string!
- Fl::fatal("error: unknown option: %s\n"
- "usage: %s [options]\n"
- " -h | --help : print extended help message\n"
- " -o | --option # : example option with parameter\n"
- " plus standard fltk options\n",
- argv[i], argv[0]);
- if (helpFlag)
- Fl::fatal("usage: %s [options]\n"
- " -h | --help : print extended help message\n"
- " -o | --option # : example option with parameter\n"
- " plus standard fltk options:\n"
- "%s\n",
- argv[0], Fl::help);
-
- Fl_Window* mainWin = new Fl_Window(300, 200);
- Fl_Box* textBox = new Fl_Box(0, 0, 300, 200);
- if (optionString != 0)
- textBox->label(optionString);
- else
- textBox->label("re-run with [-o|--option] text");
- mainWin->show(argc, argv);
- return Fl::run();
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/howto-text-over-image-button.cxx b/branch-3.0-2011/examples/howto-text-over-image-button.cxx
deleted file mode 100644
index f4fad549f..000000000
--- a/branch-3.0-2011/examples/howto-text-over-image-button.cxx
+++ /dev/null
@@ -1,91 +0,0 @@
-//
-// "$Id$"
-//
-// Simple example of a button with text over an image
-// Originally from erco's cheat sheet 10/25/2010, permission by author.
-//
-// This shows how to include an 'inline' image (.xpm)
-// and have it appear on an Fl_Button. Demonstrates the use of the
-// FL_ALIGN_IMAGE_BACKDROP align() flag (new in FLTK 1.3.0).
-//
-// Note that the XPM can just as easily be in an #include file,
-// but to keep the example self contained, the image (a gray scale
-// gradient) is included here.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-#include <FL/Fl_Button.H>
-#include <FL/Fl_Pixmap.H>
-
-/* XPM */
-static const char * gradient_xpm[] = {
-"135 20 26 1",
-"a c #e0e0e0", "b c #dcdcdc", "c c #d8d8d8", "d c #d4d4d4", "e c #d2d2d2",
-"f c #d0d0d0", "g c #cccccc", "h c #c8c8c8", "i c #c4c4c4", "j c #c2c2c2",
-"k c #c0c0c0", "l c #bcbcbc", "m c #b8b8b8", "n c #b4b4b4", "o c #b2b2b2",
-"p c #b0b0b0", "q c #acacac", "r c #a8a8a8", "s c #a4a4a4", "t c #a2a2a2",
-"u c #a0a0a0", "v c #9c9c9c", "w c #989898", "x c #949494", "y c #929292",
-"z c #909090",
-"aaaaaaaaabbbbbbbbcccccccddddddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrssss",
-"aaaaaabbbbbbbbcccccccddddddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssst",
-"aaabbbbbbbbcccccccddddddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssstt",
-"bbbbbbbbcccccccddddddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrssssssssstttt",
-"bbbbbcccccccddddddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttu",
-"bbcccccccddddddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuu",
-"ccccccddddddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuu",
-"cccddddddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvv",
-"ddddddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvv",
-"dddeeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvw",
-"eeeeeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwww",
-"eeefffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwwwwww",
-"fffffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwwwwwwwxx",
-"ffffgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwwwwwwwxxxxx",
-"fgggggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwwwwwwwxxxxxxyy",
-"gggggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwwwwwwwxxxxxxyyyyy",
-"ggghhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwwwwwwwxxxxxxyyyyyyyy",
-"hhhhhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwwwwwwwxxxxxxyyyyyyyyzzz",
-"hhhhiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwwwwwwwxxxxxxyyyyyyyyzzzzzz",
-"hiiiiiiijjjjjjjkkkkkkkklllllllmmmmmmmnnnnnnnnnoooooooppppppppqqqqqqrrrrrrrsssssssssttttttuuuuuuuuvvvvvvvwwwwwwwwxxxxxxyyyyyyyyzzzzzzzzz"};
-
-int main(int argc, char **argv) {
- Fl_Pixmap gradient(gradient_xpm);
- Fl_Window *win = new Fl_Window(160, 75, "test"); // create window
-
- Fl_Button *but1 = new Fl_Button(10,10,140,25,"Button 1"); // create regular button
- but1->image(&gradient); // assign it an image
- but1->align(FL_ALIGN_IMAGE_BACKDROP|but1->align()); // use image as a 'backdrop'
-
- Fl_Button *but2 = new Fl_Button(10,40,140,25,"Button 2"); // create second instance of button
- but2->image(&gradient); // assign it same image
- but2->align(FL_ALIGN_IMAGE_BACKDROP|but2->align()); // use image as a 'backdrop'
-
- win->end();
- win->show(argc,argv);
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/menubar-add.cxx b/branch-3.0-2011/examples/menubar-add.cxx
deleted file mode 100644
index 5986b6863..000000000
--- a/branch-3.0-2011/examples/menubar-add.cxx
+++ /dev/null
@@ -1,93 +0,0 @@
-//
-// "$Id$"
-//
-// An example of using Fl_Menu_Bar's add() to dynamically create menubars
-//
-// Menu bars can be created several ways. Using add() allows
-// dynamically creating a menubar using a 'pathname' syntax.
-// Use if you're creating items dynamically, or if you're making
-// menubars by hand (as opposed to using fluid), as it's easier
-// to type and read.
-//
-// In this case we're using one callback for all items,
-// but you can make unique callbacks for each item if needed.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <stdio.h> // fprintf()
-#include <stdlib.h> // exit()
-#include <string.h> // strcmp()
-#include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-#include <FL/Fl_Menu_Bar.H>
-#include <FL/filename.H> // fl_open_uri()
-
-// This callback is invoked whenever the user clicks an item in the menu bar
-static void MyMenuCallback(Fl_Widget *w, void *) {
- Fl_Menu_Bar *bar = (Fl_Menu_Bar*)w; // Get the menubar widget
- const Fl_Menu_Item *item = bar->mvalue(); // Get the menu item that was picked
-
- char ipath[256]; bar->item_pathname(ipath, sizeof(ipath)); // Get full pathname of picked item
-
- fprintf(stderr, "callback: You picked '%s'", item->label()); // Print item picked
- fprintf(stderr, ", item_pathname() is '%s'", ipath); // ..and full pathname
-
- if ( item->flags & (FL_MENU_RADIO|FL_MENU_TOGGLE) ) { // Toggle or radio item?
- fprintf(stderr, ", value is %s", item->value()?"on":"off"); // Print item's value
- }
- fprintf(stderr, "\n");
- if ( strcmp(item->label(), "Google") == 0 ) { fl_open_uri("http://google.com/"); }
- if ( strcmp(item->label(), "&Quit") == 0 ) { exit(0); }
-}
-
-int main() {
- Fl::scheme("gtk+");
- Fl_Window *win = new Fl_Window(400,200, "menubar-simple"); // Create window
- Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25); // Create menubar, items..
- menu->add("&File/&Open", "^o", MyMenuCallback);
- menu->add("&File/&Save", "^s", MyMenuCallback, 0, FL_MENU_DIVIDER);
- menu->add("&File/&Quit", "^q", MyMenuCallback);
- menu->add("&Edit/&Copy", "^c", MyMenuCallback);
- menu->add("&Edit/&Paste", "^v", MyMenuCallback, 0, FL_MENU_DIVIDER);
- menu->add("&Edit/Radio 1", 0, MyMenuCallback, 0, FL_MENU_RADIO);
- menu->add("&Edit/Radio 2", 0, MyMenuCallback, 0, FL_MENU_RADIO|FL_MENU_DIVIDER);
- menu->add("&Edit/Toggle 1", 0, MyMenuCallback, 0, FL_MENU_TOGGLE); // Default: off
- menu->add("&Edit/Toggle 2", 0, MyMenuCallback, 0, FL_MENU_TOGGLE); // Default: off
- menu->add("&Edit/Toggle 3", 0, MyMenuCallback, 0, FL_MENU_TOGGLE|FL_MENU_VALUE); // Default: on
- menu->add("&Help/Google", 0, MyMenuCallback);
-
- // Example: show how we can dynamically change the state of item Toggle #2 (turn it 'on')
- {
- Fl_Menu_Item *item = (Fl_Menu_Item*)menu->find_item("&Edit/Toggle 2"); // Find item
- if ( item ) item->set(); // Turn it on
- else fprintf(stderr, "'Toggle 2' item not found?!\n"); // (optional) Not found? complain!
- }
-
- win->end();
- win->show();
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/nativefilechooser-simple-app.cxx b/branch-3.0-2011/examples/nativefilechooser-simple-app.cxx
deleted file mode 100644
index fefff28ea..000000000
--- a/branch-3.0-2011/examples/nativefilechooser-simple-app.cxx
+++ /dev/null
@@ -1,161 +0,0 @@
-//
-// "$Id$"
-//
-// An example of how to use Fl_Native_File_Chooser to open & save files.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <stdio.h> // printf
-#include <stdlib.h> // exit,malloc
-#include <string.h> // strerror
-#include <errno.h> // errno
-#include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-#include <FL/Fl_Menu_Bar.H>
-#include <FL/Fl_Native_File_Chooser.H>
-#include <FL/Fl_Box.H>
-#include <FL/fl_ask.H>
-
-class Application : public Fl_Window {
- Fl_Native_File_Chooser *fc;
- // Does file exist?
- int exist(const char *filename) {
- FILE *fp = fopen(filename, "r");
- if (fp) { fclose(fp); return(1); }
- else { return(0); }
- }
- // 'Open' the file
- void open(const char *filename) {
- printf("Open '%s'\n", filename);
- }
- // 'Save' the file
- // Create the file if it doesn't exist
- // and save something in it.
- //
- void save(const char *filename) {
- printf("Saving '%s'\n", filename);
- if ( !exist(filename) ) {
- FILE *fp = fopen(filename, "w"); // create file if it doesn't exist
- if ( fp ) {
- // A real app would do something useful here.
- fprintf(fp, "Hello world.\n");
- fclose(fp);
- } else {
- fl_message("Error: %s: %s", filename, strerror(errno));
- }
- } else {
- // A real app would do something useful here.
- }
- }
- // Handle an 'Open' request from the menu
- static void open_cb(Fl_Widget *w, void *v) {
- Application *app = (Application*)v;
- app->fc->title("Open");
- app->fc->type(Fl_Native_File_Chooser::BROWSE_FILE); // only picks files that exist
- switch ( app->fc->show() ) {
- case -1: break; // Error
- case 1: break; // Cancel
- default: // Choice
- app->fc->preset_file(app->fc->filename());
- app->open(app->fc->filename());
- break;
- }
- }
- // Handle a 'Save as' request from the menu
- static void saveas_cb(Fl_Widget *w, void *v) {
- Application *app = (Application*)v;
- app->fc->title("Save As");
- app->fc->type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE); // need this if file doesn't exist yet
- switch ( app->fc->show() ) {
- case -1: break; // Error
- case 1: break; // Cancel
- default: // Choice
- app->fc->preset_file(app->fc->filename());
- app->save(app->fc->filename());
- break;
- }
- }
- // Handle a 'Save' request from the menu
- static void save_cb(Fl_Widget *w, void *v) {
- Application *app = (Application*)v;
- if ( strlen(app->fc->filename()) == 0 ) {
- saveas_cb(w,v);
- } else {
- app->save(app->fc->filename());
- }
- }
- static void quit_cb(Fl_Widget *w, void *v) {
- exit(0);
- }
- // Return an 'untitled' default pathname
- const char* untitled_default() {
- static char *filename = 0;
- if ( !filename ) {
- const char *home =
- getenv("HOME") ? getenv("HOME") : // unix
- getenv("HOME_PATH") ? getenv("HOME_PATH") : // windows
- "."; // other
- filename = (char*)malloc(strlen(home)+20);
- sprintf(filename, "%s/untitled.txt", home);
- }
- return(filename);
- }
-public:
- // CTOR
- Application() : Fl_Window(400,200,"Native File Chooser Example") {
- Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25);
- menu->add("&File/&Open", FL_COMMAND+'o', open_cb, (void*)this);
- menu->add("&File/&Save", FL_COMMAND+'s', save_cb, (void*)this);
- menu->add("&File/&Save As", 0, saveas_cb, (void*)this);
- menu->add("&File/&Quit", FL_COMMAND+'q', quit_cb);
- // Describe the demo..
- Fl_Box *box = new Fl_Box(20,25+20,w()-40,h()-40-25);
- box->color(45);
- box->box(FL_FLAT_BOX);
- box->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE|FL_ALIGN_WRAP);
- box->label("This demo shows an example of implementing "
- "common 'File' menu operations like:\n"
- " File/Open, File/Save, File/Save As\n"
- "..using the Fl_Native_File_Chooser widget.\n\n"
- "Note 'Save' and 'Save As' really *does* create files! "
- "This is to show how behavior differs when "
- "files exist vs. do not.");
- box->labelsize(12);
- // Initialize the file chooser
- fc = new Fl_Native_File_Chooser();
- fc->filter("Text\t*.txt\n");
- fc->preset_file(untitled_default());
- end();
- }
-};
-
-int main(int argc, char *argv[]) {
- Fl::scheme("gtk+");
- Application *app = new Application();
- app->show(argc,argv);
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/table-as-container.cxx b/branch-3.0-2011/examples/table-as-container.cxx
deleted file mode 100644
index 64d3637ce..000000000
--- a/branch-3.0-2011/examples/table-as-container.cxx
+++ /dev/null
@@ -1,170 +0,0 @@
-//
-// "$Id$"
-//
-// Show how FLTK widgets can be parented by Fl_Table. -erco 03/30/2003
-//
-// Originally the 'widgettable.cxx' example program that came with
-// erco's Fl_Table widget. Added to FLTK in 2010.
-//
-// This demonstrates how to use Fl_Table as a 'container' for FLTK
-// widgets; one widget per cell. This isn't optimal for large tables,
-// where it's better to make one instance of a widget, and move it to
-// where it's needed. For an example of this, see the example program
-// "table-spreadsheet.cxx".
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems to:
-//
-// http://www.fltk.org/str.php
-//
-
-#include <stdio.h>
-#include <FL/Fl.H>
-#include <FL/Fl_Double_Window.H>
-#include <FL/Fl_Light_Button.H>
-#include <FL/Fl_Input.H>
-#include <FL/fl_draw.H>
-#include <FL/Fl_Table.H>
-
-void button_cb(Fl_Widget *w, void*);
-
-//
-// Simple demonstration class deriving from Fl_Table
-//
-class WidgetTable : public Fl_Table {
-protected:
- void draw_cell(TableContext context, // table cell drawing
- int R=0, int C=0, int X=0, int Y=0, int W=0, int H=0);
-
-public:
- WidgetTable(int x, int y, int w, int h, const char *l=0) : Fl_Table(x,y,w,h,l) {
- col_header(1);
- col_resize(1);
- col_header_height(25);
- row_header(1);
- row_resize(1);
- row_header_width(80);
- end();
- }
- ~WidgetTable() { }
-
- void SetSize(int newrows, int newcols) {
- rows(newrows);
- cols(newcols);
-
- begin(); // start adding widgets to group
- {
- for ( int r = 0; r<newrows; r++ ) {
- for ( int c = 0; c<newcols; c++ ) {
- int X,Y,W,H;
- find_cell(CONTEXT_TABLE, r, c, X, Y, W, H);
-
- char s[40];
- if ( c & 1 ) {
- // Create the input widgets
- sprintf(s, "%d.%d", r, c);
- Fl_Input *in = new Fl_Input(X,Y,W,H);
- in->value(s);
- } else {
- // Create the light buttons
- sprintf(s, "%d/%d ", r, c);
- Fl_Light_Button *butt = new Fl_Light_Button(X,Y,W,H,strdup(s));
- butt->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
- butt->callback(button_cb, (void*)0);
- butt->value( ((r+c*2) & 4 ) ? 1 : 0);
- }
- }
- }
- }
- end();
- }
-};
-
-// Handle drawing all cells in table
-void WidgetTable::draw_cell(TableContext context,
- int R, int C, int X, int Y, int W, int H) {
- switch ( context ) {
- case CONTEXT_STARTPAGE:
- fl_font(FL_HELVETICA, 12); // font used by all headers
- break;
-
- case CONTEXT_RC_RESIZE: {
- int X, Y, W, H;
- int index = 0;
- for ( int r = 0; r<rows(); r++ ) {
- for ( int c = 0; c<cols(); c++ ) {
- if ( index >= children() ) break;
- find_cell(CONTEXT_TABLE, r, c, X, Y, W, H);
- child(index++)->resize(X,Y,W,H);
- }
- }
- init_sizes(); // tell group children resized
- return;
- }
-
- case CONTEXT_ROW_HEADER:
- fl_push_clip(X, Y, W, H);
- {
- static char s[40];
- sprintf(s, "Row %d", R);
- fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, row_header_color());
- fl_color(FL_BLACK);
- fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER);
- }
- fl_pop_clip();
- return;
-
- case CONTEXT_COL_HEADER:
- fl_push_clip(X, Y, W, H);
- {
- static char s[40];
- sprintf(s, "Column %d", C);
- fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, col_header_color());
- fl_color(FL_BLACK);
- fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER);
- }
- fl_pop_clip();
- return;
-
- case CONTEXT_CELL:
- return; // fltk handles drawing the widgets
-
- default:
- return;
- }
-}
-
-void button_cb(Fl_Widget *w, void*) {
- fprintf(stderr, "BUTTON: %s\n", (const char*)w->label());
-}
-
-int main() {
- Fl_Double_Window win(940, 500, "table as container");
- WidgetTable table(20, 20, win.w()-40, win.h()-40, "FLTK widget table");
- table.SetSize(50, 50);
- win.end();
- win.resizable(table);
- win.show();
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/table-simple.cxx b/branch-3.0-2011/examples/table-simple.cxx
deleted file mode 100644
index b1ad7c140..000000000
--- a/branch-3.0-2011/examples/table-simple.cxx
+++ /dev/null
@@ -1,129 +0,0 @@
-//
-// "$Id$"
-//
-// Simple example of using Fl_Table - Greg Ercolano 11/29/2010
-//
-// Demonstrates the simplest use of Fl_Table possible.
-// Display a 10x10 array of integers with row/col headers.
-// No interaction; simple display of data only.
-// See other examples for more complex interactions with the table.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <FL/Fl.H>
-#include <FL/Fl_Double_Window.H>
-#include <FL/Fl_Table.H>
-#include <FL/fl_draw.H>
-
-#define MAX_ROWS 30
-#define MAX_COLS 30
-
-// Derive a class from Fl_Table
-class MyTable : public Fl_Table {
-
- int data[MAX_ROWS][MAX_COLS]; // data array for cells
-
- // Draw the row/col headings
- // Make this a dark thin upbox with the text inside.
- //
- void DrawHeader(const char *s, int X, int Y, int W, int H) {
- fl_push_clip(X,Y,W,H);
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, row_header_color());
- fl_color(FL_BLACK);
- fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
- fl_pop_clip();
- }
- // Draw the cell data
- // Dark gray text on white background with subtle border
- //
- void DrawData(const char *s, int X, int Y, int W, int H) {
- fl_push_clip(X,Y,W,H);
- // Draw cell bg
- fl_color(FL_WHITE); fl_rectf(X,Y,W,H);
- // Draw cell data
- fl_color(FL_GRAY0); fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
- // Draw box border
- fl_color(color()); fl_rect(X,Y,W,H);
- fl_pop_clip();
- }
- // Handle drawing table's cells
- // Fl_Table calls this function to draw each visible cell in the table.
- // It's up to us to use FLTK's drawing functions to draw the cells the way we want.
- //
- void draw_cell(TableContext context, int ROW=0, int COL=0, int X=0, int Y=0, int W=0, int H=0) {
- static char s[40];
- switch ( context ) {
- case CONTEXT_STARTPAGE: // before page is drawn..
- fl_font(FL_HELVETICA, 16); // set the font for our drawing operations
- return;
- case CONTEXT_COL_HEADER: // Draw column headers
- sprintf(s,"%c",'A'+COL); // "A", "B", "C", etc.
- DrawHeader(s,X,Y,W,H);
- return;
- case CONTEXT_ROW_HEADER: // Draw row headers
- sprintf(s,"%03d:",ROW); // "001:", "002:", etc
- DrawHeader(s,X,Y,W,H);
- return;
- case CONTEXT_CELL: // Draw data in cells
- sprintf(s,"%d",data[ROW][COL]);
- DrawData(s,X,Y,W,H);
- return;
- default:
- return;
- }
- }
-public:
- // Constructor
- // Make our data array, and initialize the table options.
- //
- MyTable(int X, int Y, int W, int H, const char *L=0) : Fl_Table(X,Y,W,H,L) {
- // Fill data array
- for ( int r=0; r<MAX_ROWS; r++ )
- for ( int c=0; c<MAX_COLS; c++ )
- data[r][c] = 1000+(r*1000)+c;
- // Rows
- rows(MAX_ROWS); // how many rows
- row_header(1); // enable row headers (along left)
- row_height_all(20); // default height of rows
- row_resize(0); // disable row resizing
- // Cols
- cols(MAX_COLS); // how many columns
- col_header(1); // enable column headers (along top)
- col_width_all(80); // default width of columns
- col_resize(1); // enable column resizing
- }
- ~MyTable() { }
-};
-
-int main(int argc, char **argv) {
- Fl_Double_Window win(900, 400, "Simple Table");
- MyTable table(10,10,880,380);
- win.end();
- win.resizable(table);
- win.show(argc,argv);
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/table-sort.cxx b/branch-3.0-2011/examples/table-sort.cxx
deleted file mode 100644
index 684b74c84..000000000
--- a/branch-3.0-2011/examples/table-sort.cxx
+++ /dev/null
@@ -1,291 +0,0 @@
-//
-// "$Id$"
-//
-// table-sort -- An example application using a sortable Fl_Table
-//
-// Originally the 'sortapp.cxx' example program that came with
-// erco's Fl_Table widget. Added to FLTK in 2010.
-//
-// Example of a non-trivial application that uses Fl_Table
-// with sortable columns. This example is not trying to be simple,
-// but to demonstrate the complexities of an actual app.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-
-#include <FL/Fl.H>
-#include <FL/Fl_Double_Window.H>
-#include <FL/fl_draw.H>
-#include <FL/Fl_Table_Row.H>
-
-#include <stdio.h>
-#include <string.h>
-#include <vector>
-#include <algorithm> // STL sort
-
-#define MARGIN 20
-
-#ifdef WIN32
-// WINDOWS
-# define DIRCMD "dir"
-# define DIRHEADER { "Date", "Time", "Size", "Filename", "", "", "", "", "" }
-# ifdef _MSC_VER
-# define popen _popen
-# endif
-#else /*WIN32*/
-// UNIX
-# include <ctype.h>
-# define DIRCMD "ls -l"
-# define DIRHEADER { "Perms", "#L", "Own", "Group", "Size", "Date", "", "", "Filename" }
-#endif /*WIN32*/
-
-// A single row of columns
-class Row {
-public:
- std::vector<char*> cols;
-};
-
-// Sort class to handle sorting column using std::sort
-class SortColumn {
- int _col, _reverse;
-public:
- SortColumn(int col, int reverse) {
- _col = col;
- _reverse = reverse;
- }
- bool operator()(const Row &a, const Row &b) {
- const char *ap = ( _col < (int)a.cols.size() ) ? a.cols[_col] : "",
- *bp = ( _col < (int)b.cols.size() ) ? b.cols[_col] : "";
- if ( isdigit(*ap) && isdigit(*bp) ) { // cheezy detection of numeric data
- // Numeric sort
- int av=0; sscanf(ap, "%d", &av);
- int bv=0; sscanf(bp, "%d", &bv);
- return( _reverse ? av < bv : bv < av );
- } else {
- // Alphabetic sort
- return( _reverse ? strcmp(ap, bp) > 0 : strcmp(ap, bp) < 0 );
- }
- }
-};
-
-// Derive a custom class from Fl_Table_Row
-class MyTable : public Fl_Table_Row {
-private:
- std::vector<Row> _rowdata; // data in each row
- int _sort_reverse;
- int _sort_lastcol;
-
- static void event_callback(Fl_Widget*, void*);
- void event_callback2(); // callback for table events
-
-protected:
- void draw_cell(TableContext context, int R=0, int C=0, // table cell drawing
- int X=0, int Y=0, int W=0, int H=0);
- void sort_column(int col, int reverse=0); // sort table by a column
- void draw_sort_arrow(int X,int Y,int W,int H,int sort);
-
-public:
- // Ctor
- MyTable(int x, int y, int w, int h, const char *l=0) : Fl_Table_Row(x,y,w,h,l) {
- _sort_reverse = 0;
- _sort_lastcol = -1;
- end();
- callback(event_callback, (void*)this);
- }
- ~MyTable() { } // Dtor
- void load_command(const char *cmd); // Load the output of a command into table
- void autowidth(int pad); // Automatically set column widths to data
- void resize_window(); // Resize parent window to size of table
-};
-
-// Sort a column up or down
-void MyTable::sort_column(int col, int reverse) {
- std::sort(_rowdata.begin(), _rowdata.end(), SortColumn(col, reverse));
- redraw();
-}
-
-// Draw sort arrow
-void MyTable::draw_sort_arrow(int X,int Y,int W,int H,int sort) {
- int xlft = X+(W-6)-8;
- int xctr = X+(W-6)-4;
- int xrit = X+(W-6)-0;
- int ytop = Y+(H/2)-4;
- int ybot = Y+(H/2)+4;
- if ( _sort_reverse ) {
- // Engraved down arrow
- fl_color(FL_WHITE);
- fl_line(xrit, ytop, xctr, ybot);
- fl_color(41); // dark gray
- fl_line(xlft, ytop, xrit, ytop);
- fl_line(xlft, ytop, xctr, ybot);
- } else {
- // Engraved up arrow
- fl_color(FL_WHITE);
- fl_line(xrit, ybot, xctr, ytop);
- fl_line(xrit, ybot, xlft, ybot);
- fl_color(41); // dark gray
- fl_line(xlft, ybot, xctr, ytop);
- }
-}
-
-// Handle drawing all cells in table
-void MyTable::draw_cell(TableContext context, int R, int C, int X, int Y, int W, int H) {
- const char *s = "";
- if ( R < (int)_rowdata.size() && C < (int)_rowdata[R].cols.size() )
- s = _rowdata[R].cols[C];
- switch ( context ) {
- case CONTEXT_COL_HEADER:
- fl_push_clip(X,Y,W,H); {
- static const char *head[] = DIRHEADER;
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, FL_BACKGROUND_COLOR);
- if ( C < 9 ) {
- fl_font(FL_HELVETICA_BOLD, 16);
- fl_color(FL_BLACK);
- fl_draw(head[C], X+2,Y,W,H, FL_ALIGN_LEFT, 0, 0); // +2=pad left
- // Draw sort arrow
- if ( C == _sort_lastcol ) {
- draw_sort_arrow(X,Y,W,H, _sort_reverse);
- }
- }
- }
- fl_pop_clip();
- return;
- case CONTEXT_CELL: {
- fl_push_clip(X,Y,W,H); {
- // Bg color
- Fl_Color bgcolor = row_selected(R) ? selection_color() : FL_WHITE;
- fl_color(bgcolor); fl_rectf(X,Y,W,H);
- fl_font(FL_HELVETICA, 16);
- fl_color(FL_BLACK); fl_draw(s, X+2,Y,W,H, FL_ALIGN_LEFT); // +2=pad left
- // Border
- fl_color(FL_LIGHT2); fl_rect(X,Y,W,H);
- }
- fl_pop_clip();
- return;
- }
- default:
- return;
- }
-}
-
-// Automatically set column widths to widest data in each column
-void MyTable::autowidth(int pad) {
- fl_font(FL_COURIER, 16);
- // Initialize all column widths to lowest value
- for ( int c=0; c<cols(); c++ ) col_width(c, pad);
- for ( int r=0; r<(int)_rowdata.size(); r++ ) {
- int w, h;
- for ( int c=0; c<(int)_rowdata[r].cols.size(); c++ ) {
- fl_measure(_rowdata[r].cols[c], w, h, 0); // get pixel width of text
- if ( (w + pad) > col_width(c)) col_width(c, w + pad);
- }
- }
- table_resized();
- redraw();
-}
-
-// Resize parent window to size of table
-void MyTable::resize_window() {
- // Determine exact outer width of table with all columns visible
- int width = 4; // width of table borders
- for ( int t=0; t<cols(); t++ ) width += col_width(t); // total width of all columns
- width += MARGIN*2;
- if ( width < 200 || width > Fl::w() ) return;
- window()->resize(window()->x(), window()->y(), width, window()->h()); // resize window to fit
-}
-
-// Load table with output of 'cmd'
-void MyTable::load_command(const char *cmd) {
- char s[512];
- FILE *fp = popen(cmd, "r");
- cols(0);
- for ( int r=0; fgets(s, sizeof(s)-1, fp); r++ ) {
- // Add a new row
- Row newrow; _rowdata.push_back(newrow);
- std::vector<char*> &rc = _rowdata[r].cols;
- // Break line into separate word 'columns'
- char *ss;
- const char *delim = " \t\n";
- for(int t=0; (t==0)?(ss=strtok(s,delim)):(ss=strtok(NULL,delim)); t++) {
- rc.push_back(strdup(ss));
- }
- // Keep track of max # columns
- if ( (int)rc.size() > cols() ) {
- cols((int)rc.size());
- }
- }
- // How many rows we loaded
- rows((int)_rowdata.size());
- // Auto-calculate widths, with 20 pixel padding
- autowidth(20);
-}
-
-// Callback whenever someone clicks on different parts of the table
-void MyTable::event_callback(Fl_Widget*, void *data) {
- MyTable *o = (MyTable*)data;
- o->event_callback2();
-}
-
-void MyTable::event_callback2() {
- //int ROW = callback_row(); // unused
- int COL = callback_col();
- TableContext context = callback_context();
- switch ( context ) {
- case CONTEXT_COL_HEADER: { // someone clicked on column header
- if ( Fl::event() == FL_RELEASE && Fl::event_button() == 1 ) {
- if ( _sort_lastcol == COL ) { // Click same column? Toggle sort
- _sort_reverse ^= 1;
- } else { // Click diff column? Up sort
- _sort_reverse = 0;
- }
- sort_column(COL, _sort_reverse);
- _sort_lastcol = COL;
- }
- break;
- }
- default:
- return;
- }
-}
-
-int main() {
- Fl_Double_Window win(900,500,"Table Sorting");
- MyTable table(MARGIN, MARGIN, win.w()-MARGIN*2, win.h()-MARGIN*2);
- table.selection_color(FL_YELLOW);
- table.col_header(1);
- table.col_resize(1);
- table.when(FL_WHEN_RELEASE); // handle table events on release
- table.load_command(DIRCMD); // load table with a directory listing
- table.row_height_all(18); // height of all rows
- table.tooltip("Click on column headings to toggle column sorting");
- table.color(FL_WHITE);
- win.end();
- win.resizable(table);
- table.resize_window();
- win.show();
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/table-spreadsheet-with-keyboard-nav.cxx b/branch-3.0-2011/examples/table-spreadsheet-with-keyboard-nav.cxx
deleted file mode 100644
index d8d7e1423..000000000
--- a/branch-3.0-2011/examples/table-spreadsheet-with-keyboard-nav.cxx
+++ /dev/null
@@ -1,350 +0,0 @@
-//
-// "$Id$"
-//
-// Simple example of an interactive spreadsheet using Fl_Table.
-// Uses Mr. Satan's technique of instancing an Fl_Input around.
-// Modified to test Jean-Marc's mods for keyboard nav and mouse selection.
-//
-// Fl_Table[1.00/LGPL] 04/18/03 Mister Satan -- Initial implementation, submitted to erco for Fl_Table
-// Fl_Table[1.10/LGPL] 05/17/03 Greg Ercolano -- Small mods to follow changes to Fl_Table
-// Fl_Table[1.20/LGPL] 02/22/04 Jean-Marc Lienher -- Keyboard nav and mouse selection
-// Fl_Table[1.21/LGPL] 02/22/04 Greg Ercolano -- Small reformatting mods, comments
-// FLTK[1.3.0/LGPL] 10/26/10 Greg Ercolano -- Moved from Fl_Table to FLTK 1.3.x, CMP compliance
-//
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <stdio.h>
-#include <stdlib.h>
-#include <FL/Fl.H>
-#include <FL/Fl_Double_Window.H>
-#include <FL/Fl_Table.H>
-#include <FL/Fl_Int_Input.H>
-#include <FL/Fl_Value_Slider.H>
-#include <FL/fl_draw.H>
-
-const int MAX_COLS = 26;
-const int MAX_ROWS = 500;
-
-class Spreadsheet : public Fl_Table {
- Fl_Int_Input *input; // single instance of Fl_Int_Input widget
- int values[MAX_ROWS][MAX_COLS]; // array of data for cells
- int row_edit, col_edit; // row/col being modified
- int s_left, s_top, s_right, s_bottom; // kb nav + mouse selection
-
-protected:
- void draw_cell(TableContext context,int=0,int=0,int=0,int=0,int=0,int=0);
- void event_callback2(); // table's event callback (instance)
- static void event_callback(Fl_Widget*, void *v) { // table's event callback (static)
- ((Spreadsheet*)v)->event_callback2();
- }
- static void input_cb(Fl_Widget*, void* v) { // input widget's callback
- ((Spreadsheet*)v)->set_value_hide();
- }
-
-public:
- Spreadsheet(int X,int Y,int W,int H,const char* L=0) : Fl_Table(X,Y,W,H,L) {
- callback(&event_callback, (void*)this);
- when(FL_WHEN_NOT_CHANGED|when());
- // Create input widget that we'll use whenever user clicks on a cell
- input = new Fl_Int_Input(W/2,H/2,0,0);
- input->hide();
- input->callback(input_cb, (void*)this);
- input->when(FL_WHEN_ENTER_KEY_ALWAYS); // callback triggered when user hits Enter
- input->maximum_size(5);
- for (int c = 0; c < MAX_COLS; c++)
- for (int r = 0; r < MAX_ROWS; r++)
- values[r][c] = (r + 2) * (c + 3); // initialize cells
- end();
- }
- ~Spreadsheet() { }
-
- // Apply value from input widget to values[row][col] array and hide (done editing)
- void set_value_hide() {
- values[row_edit][col_edit] = atoi(input->value());
- input->hide();
- window()->cursor(FL_CURSOR_DEFAULT); // XXX: if we don't do this, cursor can disappear!
- }
- // Change number of rows
- void rows(int val) {
- set_value_hide();
- Fl_Table::rows(val);
- }
- // Change number of columns
- void cols(int val) {
- set_value_hide();
- Fl_Table::cols(val);
- }
- // Get number of rows
- inline int rows() {
- return Fl_Table::rows();
- }
- // Get number of columns
- inline int cols() {
- return Fl_Table::cols();
- }
- // Start editing a new cell: move the Fl_Int_Input widget to specified row/column
- // Preload the widget with the cell's current value,
- // and make the widget 'appear' at the cell's location.
- //
- void start_editing(int R, int C) {
- row_edit = R; // Now editing this row/col
- col_edit = C;
- int X,Y,W,H;
- find_cell(CONTEXT_CELL, R,C, X,Y,W,H); // Find X/Y/W/H of cell
- input->resize(X,Y,W,H); // Move Fl_Input widget there
- char s[30]; sprintf(s, "%d", values[R][C]); // Load input widget with cell's current value
- input->value(s);
- input->position(0,strlen(s)); // Select entire input field
- input->show(); // Show the input widget, now that we've positioned it
- input->take_focus();
- }
- // Tell the input widget it's done editing, and to 'hide'
- void done_editing() {
- if (input->visible()) { // input widget visible, ie. edit in progress?
- set_value_hide(); // Transfer its current contents to cell and hide
- }
- }
- // Return the sum of all rows in this column
- int sum_rows(int C) {
- int sum = 0;
- for (int r=0; r<rows()-1; ++r) // -1: don't include cell data in 'totals' column
- sum += values[r][C];
- return(sum);
- }
- // Return the sum of all cols in this row
- int sum_cols(int R) {
- int sum = 0;
- for (int c=0; c<cols()-1; ++c) // -1: don't include cell data in 'totals' column
- sum += values[R][c];
- return(sum);
- }
- // Return the sum of all cells in table
- int sum_all() {
- int sum = 0;
- for (int c=0; c<cols()-1; ++c) // -1: don't include cell data in 'totals' column
- for (int r=0; r<rows()-1; ++r) // -1: ""
- sum += values[r][c];
- return(sum);
- }
-};
-
-// Handle drawing all cells in table
-void Spreadsheet::draw_cell(TableContext context, int R,int C, int X,int Y,int W,int H) {
- static char s[30];
- switch ( context ) {
- case CONTEXT_STARTPAGE: // table about to redraw
- // Get kb nav + mouse 'selection region' for use below
- get_selection(s_top, s_left, s_bottom, s_right);
- break;
-
- case CONTEXT_COL_HEADER: // table wants us to draw a column heading (C is column)
- fl_font(FL_HELVETICA | FL_BOLD, 14); // set font for heading to bold
- fl_push_clip(X,Y,W,H); // clip region for text
- {
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, col_header_color());
- fl_color(FL_BLACK);
- if (C == cols()-1) { // Last column? show 'TOTAL'
- fl_draw("TOTAL", X,Y,W,H, FL_ALIGN_CENTER);
- } else { // Not last column? show column letter
- sprintf(s, "%c", 'A' + C);
- fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
- }
- }
- fl_pop_clip();
- return;
-
- case CONTEXT_ROW_HEADER: // table wants us to draw a row heading (R is row)
- fl_font(FL_HELVETICA | FL_BOLD, 14); // set font for row heading to bold
- fl_push_clip(X,Y,W,H);
- {
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, row_header_color());
- fl_color(FL_BLACK);
- if (R == rows()-1) { // Last row? Show 'Total'
- fl_draw("TOTAL", X,Y,W,H, FL_ALIGN_CENTER);
- } else { // Not last row? show row#
- sprintf(s, "%d", R+1);
- fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
- }
- }
- fl_pop_clip();
- return;
-
- case CONTEXT_CELL: { // table wants us to draw a cell
- if (R == row_edit && C == col_edit && input->visible()) {
- return; // dont draw for cell with input widget over it
- }
- // Background
- // Keyboard nav and mouse selection highlighting
- if (R >= s_top && R <= s_bottom && C >= s_left && C <= s_right) {
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, FL_YELLOW);
- } else if ( C < cols()-1 && R < rows()-1 ) {
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, FL_WHITE);
- } else {
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, 0xbbddbb00); // money green
- }
- // Text
- fl_push_clip(X+3, Y+3, W-6, H-6);
- {
- fl_color(FL_BLACK);
- if (C == cols()-1 || R == rows()-1) { // Last row or col? Show total
- fl_font(FL_HELVETICA | FL_BOLD, 14); // ..in bold font
- if (C == cols()-1 && R == rows()-1) { // Last row+col? Total all cells
- sprintf(s, "%d", sum_all());
- } else if (C == cols()-1) { // Row subtotal
- sprintf(s, "%d", sum_cols(R));
- } else if (R == rows()-1) { // Col subtotal
- sprintf(s, "%d", sum_rows(C));
- }
- fl_draw(s, X+3,Y+3,W-6,H-6, FL_ALIGN_RIGHT);
- } else { // Not last row or col? Show cell contents
- fl_font(FL_HELVETICA, 14); // ..in regular font
- sprintf(s, "%d", values[R][C]);
- fl_draw(s, X+3,Y+3,W-6,H-6, FL_ALIGN_RIGHT);
- }
- }
- fl_pop_clip();
- return;
- }
-
- case CONTEXT_RC_RESIZE: { // table resizing rows or columns
- if (!input->visible()) return;
- find_cell(CONTEXT_TABLE, row_edit, col_edit, X, Y, W, H);
- if (X==input->x() && Y==input->y() && W==input->w() && H==input->h()) {
- return; // no change? ignore
- }
- input->resize(X,Y,W,H);
- return;
- }
-
- default:
- return;
- }
-}
-
-// Callback whenever someone clicks on different parts of the table
-void Spreadsheet::event_callback2() {
- int R = callback_row();
- int C = callback_col();
- TableContext context = callback_context();
-
- switch ( context ) {
- case CONTEXT_CELL: { // A table event occurred on a cell
- switch (Fl::event()) { // see what FLTK event caused it
- case FL_PUSH: // mouse click?
- done_editing(); // finish editing previous
- if (R != rows()-1 && C != cols()-1 ) // only edit cells not in total's columns
- start_editing(R,C); // start new edit
- return;
-
- case FL_KEYBOARD: // key press in table?
- if ( Fl::event_key() == FL_Escape ) exit(0); // ESC closes app
- if (C == cols()-1 || R == rows()-1) return; // no editing of totals column
- done_editing(); // finish any previous editing
- set_selection(R, C, R, C); // select the current cell
- start_editing(R,C); // start new edit
- if (Fl::event() == FL_KEYBOARD && Fl::e_text[0] != '\r') {
- input->handle(Fl::event()); // pass keypress to input widget
- }
- return;
- }
- return;
- }
-
- case CONTEXT_TABLE: // A table event occurred on dead zone in table
- case CONTEXT_ROW_HEADER: // A table event occurred on row/column header
- case CONTEXT_COL_HEADER:
- done_editing(); // done editing, hide
- return;
-
- default:
- return;
- }
-}
-
-// Change number of columns
-void setcols_cb(Fl_Widget* w, void* v) {
- Spreadsheet* table = (Spreadsheet*)v;
- Fl_Valuator* in = (Fl_Valuator*)w;
- int cols = int(in->value()) + 1;
- table->cols(cols);
- table->redraw();
-}
-
-// Change number of rows
-void setrows_cb(Fl_Widget* w, void* v) {
- Spreadsheet* table = (Spreadsheet*)v;
- Fl_Valuator* in = (Fl_Valuator*)w;
- int rows = int(in->value()) + 1;
- table->rows(rows);
- table->redraw();
-}
-
-int main() {
- Fl_Double_Window *win = new Fl_Double_Window(922, 382, "Fl_Table Spreadsheet with Keyboard Navigation");
- Spreadsheet* table = new Spreadsheet(20, 20, win->w()-80, win->h()-80);
- // Table rows
- table->row_header(1);
- table->row_header_width(70);
- table->row_resize(1);
- table->rows(11);
- table->row_height_all(25);
- // Table cols
- table->col_header(1);
- table->col_header_height(25);
- table->col_resize(1);
- table->cols(11);
- table->col_width_all(70);
- table->set_selection(0,0,0,0); // select top/left cell
-
- // Add children to window
- win->begin();
-
- // Row slider
- Fl_Value_Slider setrows(win->w()-40,20,20,win->h()-80, 0);
- setrows.type(FL_VERT_NICE_SLIDER);
- setrows.bounds(2,MAX_ROWS);
- setrows.step(1);
- setrows.value(table->rows()-1);
- setrows.callback(setrows_cb, (void*)table);
- setrows.when(FL_WHEN_CHANGED);
- setrows.clear_visible_focus();
-
- // Column slider
- Fl_Value_Slider setcols(20,win->h()-40,win->w()-80,20, 0);
- setcols.type(FL_HOR_NICE_SLIDER);
- setcols.bounds(2,MAX_COLS);
- setcols.step(1);
- setcols.value(table->cols()-1);
- setcols.callback(setcols_cb, (void*)table);
- setcols.when(FL_WHEN_CHANGED);
- setcols.clear_visible_focus();
-
- win->end();
- win->resizable(table);
- win->show();
-
- return Fl::run();
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/table-spreadsheet.cxx b/branch-3.0-2011/examples/table-spreadsheet.cxx
deleted file mode 100644
index 63c4b9048..000000000
--- a/branch-3.0-2011/examples/table-spreadsheet.cxx
+++ /dev/null
@@ -1,264 +0,0 @@
-//
-// "$Id$"
-//
-// Simple example of an interactive spreadsheet using Fl_Table.
-// Uses Mr. Satan's technique of instancing an Fl_Input around.
-//
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <stdio.h>
-#include <stdlib.h>
-#include <FL/Fl.H>
-#include <FL/Fl_Double_Window.H>
-#include <FL/Fl_Table.H>
-#include <FL/Fl_Int_Input.H>
-#include <FL/fl_draw.H>
-
-const int MAX_COLS = 10;
-const int MAX_ROWS = 10;
-
-class Spreadsheet : public Fl_Table {
- Fl_Int_Input *input; // single instance of Fl_Int_Input widget
- int values[MAX_ROWS][MAX_COLS]; // array of data for cells
- int row_edit, col_edit; // row/col being modified
-
-protected:
- void draw_cell(TableContext context,int=0,int=0,int=0,int=0,int=0,int=0);
- void event_callback2(); // table's event callback (instance)
- static void event_callback(Fl_Widget*,void *v) { // table's event callback (static)
- ((Spreadsheet*)v)->event_callback2();
- }
- static void input_cb(Fl_Widget*,void* v) { // input widget's callback
- ((Spreadsheet*)v)->set_value_hide();
- }
-
-public:
- Spreadsheet(int X,int Y,int W,int H,const char* L=0) : Fl_Table(X,Y,W,H,L) {
- callback(&event_callback, (void*)this);
- when(FL_WHEN_NOT_CHANGED|when());
- // Create input widget that we'll use whenever user clicks on a cell
- input = new Fl_Int_Input(W/2,H/2,0,0);
- input->hide();
- input->callback(input_cb, (void*)this);
- input->when(FL_WHEN_ENTER_KEY_ALWAYS); // callback triggered when user hits Enter
- input->maximum_size(5);
- for (int c = 0; c < MAX_COLS; c++)
- for (int r = 0; r < MAX_ROWS; r++)
- values[r][c] = c + (r*MAX_COLS); // initialize cells
- end();
- }
- ~Spreadsheet() { }
-
- // Apply value from input widget to values[row][col] array and hide (done editing)
- void set_value_hide() {
- values[row_edit][col_edit] = atoi(input->value());
- input->hide();
- window()->cursor(FL_CURSOR_DEFAULT); // XXX: if we don't do this, cursor can disappear!
- }
- // Start editing a new cell: move the Fl_Int_Input widget to specified row/column
- // Preload the widget with the cell's current value,
- // and make the widget 'appear' at the cell's location.
- //
- void start_editing(int R, int C) {
- row_edit = R; // Now editing this row/col
- col_edit = C;
- int X,Y,W,H;
- find_cell(CONTEXT_CELL, R,C, X,Y,W,H); // Find X/Y/W/H of cell
- input->resize(X,Y,W,H); // Move Fl_Input widget there
- char s[30]; sprintf(s, "%d", values[R][C]); // Load input widget with cell's current value
- input->value(s);
- input->position(0,strlen(s)); // Select entire input field
- input->show(); // Show the input widget, now that we've positioned it
- input->take_focus();
- }
- // Tell the input widget it's done editing, and to 'hide'
- void done_editing() {
- if (input->visible()) { // input widget visible, ie. edit in progress?
- set_value_hide(); // Transfer its current contents to cell and hide
- }
- }
- // Return the sum of all rows in this column
- int sum_rows(int C) {
- int sum = 0;
- for (int r=0; r<rows()-1; ++r) // -1: don't include cell data in 'totals' column
- sum += values[r][C];
- return(sum);
- }
- // Return the sum of all cols in this row
- int sum_cols(int R) {
- int sum = 0;
- for (int c=0; c<cols()-1; ++c) // -1: don't include cell data in 'totals' column
- sum += values[R][c];
- return(sum);
- }
- // Return the sum of all cells in table
- int sum_all() {
- int sum = 0;
- for (int c=0; c<cols()-1; ++c) // -1: don't include cell data in 'totals' column
- for (int r=0; r<rows()-1; ++r) // -1: ""
- sum += values[r][c];
- return(sum);
- }
-};
-
-// Handle drawing all cells in table
-void Spreadsheet::draw_cell(TableContext context, int R,int C, int X,int Y,int W,int H) {
- static char s[30];
- switch ( context ) {
- case CONTEXT_STARTPAGE: // table about to redraw
- break;
-
- case CONTEXT_COL_HEADER: // table wants us to draw a column heading (C is column)
- fl_font(FL_HELVETICA | FL_BOLD, 14); // set font for heading to bold
- fl_push_clip(X,Y,W,H); // clip region for text
- {
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, col_header_color());
- fl_color(FL_BLACK);
- if (C == cols()-1) { // Last column? show 'TOTAL'
- fl_draw("TOTAL", X,Y,W,H, FL_ALIGN_CENTER);
- } else { // Not last column? show column letter
- sprintf(s, "%c", 'A' + C);
- fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
- }
- }
- fl_pop_clip();
- return;
-
- case CONTEXT_ROW_HEADER: // table wants us to draw a row heading (R is row)
- fl_font(FL_HELVETICA | FL_BOLD, 14); // set font for row heading to bold
- fl_push_clip(X,Y,W,H);
- {
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, row_header_color());
- fl_color(FL_BLACK);
- if (R == rows()-1) { // Last row? Show 'Total'
- fl_draw("TOTAL", X,Y,W,H, FL_ALIGN_CENTER);
- } else { // Not last row? show row#
- sprintf(s, "%d", R+1);
- fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
- }
- }
- fl_pop_clip();
- return;
-
- case CONTEXT_CELL: { // table wants us to draw a cell
- if (R == row_edit && C == col_edit && input->visible()) {
- return; // dont draw for cell with input widget over it
- }
- // Background
- if ( C < cols()-1 && R < rows()-1 ) {
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, FL_WHITE);
- } else {
- fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, 0xbbddbb00); // money green
- }
- // Text
- fl_push_clip(X+3, Y+3, W-6, H-6);
- {
- fl_color(FL_BLACK);
- if (C == cols()-1 || R == rows()-1) { // Last row or col? Show total
- fl_font(FL_HELVETICA | FL_BOLD, 14); // ..in bold font
- if (C == cols()-1 && R == rows()-1) { // Last row+col? Total all cells
- sprintf(s, "%d", sum_all());
- } else if (C == cols()-1) { // Row subtotal
- sprintf(s, "%d", sum_cols(R));
- } else if (R == rows()-1) { // Col subtotal
- sprintf(s, "%d", sum_rows(C));
- }
- fl_draw(s, X+3,Y+3,W-6,H-6, FL_ALIGN_RIGHT);
- } else { // Not last row or col? Show cell contents
- fl_font(FL_HELVETICA, 14); // ..in regular font
- sprintf(s, "%d", values[R][C]);
- fl_draw(s, X+3,Y+3,W-6,H-6, FL_ALIGN_RIGHT);
- }
- }
- fl_pop_clip();
- return;
- }
-
- default:
- return;
- }
-}
-
-// Callback whenever someone clicks on different parts of the table
-void Spreadsheet::event_callback2() {
- int R = callback_row();
- int C = callback_col();
- TableContext context = callback_context();
-
- switch ( context ) {
- case CONTEXT_CELL: { // A table event occurred on a cell
- switch (Fl::event()) { // see what FLTK event caused it
- case FL_PUSH: // mouse click?
- done_editing(); // finish editing previous
- if (R != rows()-1 && C != cols()-1 ) // only edit cells not in total's columns
- start_editing(R,C); // start new edit
- return;
-
- case FL_KEYBOARD: // key press in table?
- if ( Fl::event_key() == FL_Escape ) exit(0); // ESC closes app
- if (C == cols()-1 || R == rows()-1) return; // no editing of totals column
- done_editing(); // finish any previous editing
- start_editing(R,C); // start new edit
- if (Fl::event() == FL_KEYBOARD && Fl::e_text[0] != '\r') {
- input->handle(Fl::event()); // pass keypress to input widget
- }
- return;
- }
- return;
- }
-
- case CONTEXT_TABLE: // A table event occurred on dead zone in table
- case CONTEXT_ROW_HEADER: // A table event occurred on row/column header
- case CONTEXT_COL_HEADER:
- done_editing(); // done editing, hide
- return;
-
- default:
- return;
- }
-}
-
-int main() {
- Fl_Double_Window *win = new Fl_Double_Window(862, 322, "Fl_Table Spreadsheet");
- Spreadsheet *table = new Spreadsheet(10, 10, win->w()-20, win->h()-20);
- // Table rows
- table->row_header(1);
- table->row_header_width(70);
- table->row_resize(1);
- table->rows(MAX_ROWS+1); // +1: leaves room for 'total row'
- table->row_height_all(25);
- // Table cols
- table->col_header(1);
- table->col_header_height(25);
- table->col_resize(1);
- table->cols(MAX_COLS+1); // +1: leaves room for 'total column'
- table->col_width_all(70);
- // Show window
- win->end();
- win->resizable(table);
- win->show();
- return Fl::run();
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/tabs-simple.cxx b/branch-3.0-2011/examples/tabs-simple.cxx
deleted file mode 100644
index cc347e979..000000000
--- a/branch-3.0-2011/examples/tabs-simple.cxx
+++ /dev/null
@@ -1,92 +0,0 @@
-//
-// "$Id$"
-//
-// Simple Fl_Tabs widget example.
-// Originally from erco's cheat sheet 06/05/2010, permission by author.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-#include <FL/Fl_Tabs.H>
-#include <FL/Fl_Group.H>
-#include <FL/Fl_Button.H>
-//
-// Simple tabs example
-// _____ _____
-// __/ Aaa \/ Bbb \______________________
-// | _______ |
-// | |_______| |
-// | _______ |
-// | |_______| |
-// | _______ |
-// | |_______| |
-// |______________________________________|
-//
-int main(int argc, char *argv[]) {
- Fl::scheme("gtk+");
- Fl_Window *win = new Fl_Window(500,200,"Tabs Example");
- {
- // Create the tab widget
- Fl_Tabs *tabs = new Fl_Tabs(10,10,500-20,200-20);
- {
- // ADD THE "Aaa" TAB
- // We do this by adding a child group to the tab widget.
- // The child group's label defined the label of the tab.
- //
- Fl_Group *aaa = new Fl_Group(10,35,500-20,200-45,"Aaa");
- {
- // Put some different buttons into the group, which will be shown
- // when the tab is selected.
- Fl_Button *b1 = new Fl_Button(50, 60,90,25,"Button A1"); b1->color(88+1);
- Fl_Button *b2 = new Fl_Button(50, 90,90,25,"Button A2"); b2->color(88+2);
- Fl_Button *b3 = new Fl_Button(50,120,90,25,"Button A3"); b3->color(88+3);
- }
- aaa->end();
-
- // ADD THE "Bbb" TAB
- // Same details as above.
- //
- Fl_Group *bbb = new Fl_Group(10,35,500-10,200-35,"Bbb");
- {
- // Put some different buttons into the group, which will be shown
- // when the tab is selected.
- Fl_Button *b1 = new Fl_Button( 50,60,90,25,"Button B1"); b1->color(88+1);
- Fl_Button *b2 = new Fl_Button(150,60,90,25,"Button B2"); b2->color(88+3);
- Fl_Button *b3 = new Fl_Button(250,60,90,25,"Button B3"); b3->color(88+5);
- Fl_Button *b4 = new Fl_Button( 50,90,90,25,"Button B4"); b4->color(88+2);
- Fl_Button *b5 = new Fl_Button(150,90,90,25,"Button B5"); b5->color(88+4);
- Fl_Button *b6 = new Fl_Button(250,90,90,25,"Button B6"); b6->color(88+6);
- }
- bbb->end();
- }
- tabs->end();
- }
- win->end();
- win->show(argc, argv);
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/textdisplay-with-colors.cxx b/branch-3.0-2011/examples/textdisplay-with-colors.cxx
deleted file mode 100644
index 050674ca1..000000000
--- a/branch-3.0-2011/examples/textdisplay-with-colors.cxx
+++ /dev/null
@@ -1,68 +0,0 @@
-//
-// "$Id$"
-//
-// How to use Fl_Text_Display with colors. -erco 11/09/2010
-// Originally from erco's cheat sheet, permission by author.
-//
-// Shows how to use the two Fl_Text_Buffer's needed to manage
-// the text and style info separately.
-//
-// For an example of a color text *editor*, see the 'editor'
-// example in the test directory.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-#include <FL/Fl_Text_Display.H>
-int main() {
- // Style table
- Fl_Text_Display::Style_Table_Entry stable[] = {
- // FONT COLOR FONT FACE FONT SIZE
- // --------------- ----------- --------------
- { FL_RED, FL_COURIER, 18 }, // A - Red
- { FL_DARK_YELLOW, FL_COURIER, 18 }, // B - Yellow
- { FL_DARK_GREEN, FL_COURIER, 18 }, // C - Green
- { FL_BLUE, FL_COURIER, 18 }, // D - Blue
- };
- Fl_Window *win = new Fl_Window(640, 480, "Simple Text Display With Colors");
- Fl_Text_Display *disp = new Fl_Text_Display(20, 20, 640-40, 480-40);
- Fl_Text_Buffer *tbuff = new Fl_Text_Buffer(); // text buffer
- Fl_Text_Buffer *sbuff = new Fl_Text_Buffer(); // style buffer
- disp->buffer(tbuff);
- int stable_size = sizeof(stable)/sizeof(stable[0]); // # entries in style table (4)
- disp->highlight_data(sbuff, stable, stable_size, 'A', 0, 0);
- // Text
- tbuff->text("Red Line 1\nYel Line 2\nGrn Line 3\nBlu Line 4\n"
- "Red Line 5\nYel Line 6\nGrn Line 7\nBlu Line 8\n");
- // Style for text
- sbuff->text("AAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\n"
- "AAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\n");
- win->resizable(*disp);
- win->show();
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/texteditor-simple.cxx b/branch-3.0-2011/examples/texteditor-simple.cxx
deleted file mode 100644
index cbcaea898..000000000
--- a/branch-3.0-2011/examples/texteditor-simple.cxx
+++ /dev/null
@@ -1,62 +0,0 @@
-//
-// "$Id$"
-//
-// A simple example of Fl_Text_Editor
-//
-// Fl_Text_Editor is unlike other FLTK widgets in that
-// to work correctly, it must be assigned to an instance of an
-// Fl_Text_Buffer. The below shows using buffer() to connect
-// the two classes together.
-//
-// Note that the example can also be used to demonstrate
-// Fl_Text_Display; just replace all instances of
-// Fl_Text_Editor with Fl_Text_Display and rebuild.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-
-#include <FL/Fl.H>
-#include <FL/Fl_Double_Window.H>
-#include <FL/Fl_Text_Editor.H>
-
-int main() {
- Fl_Double_Window *win = new Fl_Double_Window(640, 480, "Simple Fl_Text_Editor");
- Fl_Text_Buffer *buff = new Fl_Text_Buffer();
- Fl_Text_Editor *edit = new Fl_Text_Editor(20, 20, 640-40, 480-40);
- edit->buffer(buff); // attach the text buffer to our editor widget
- win->resizable(*edit);
- win->show();
- buff->text("line 0\nline 1\nline 2\n"
- "line 3\nline 4\nline 5\n"
- "line 6\nline 7\nline 8\n"
- "line 9\nline 10\nline 11\n"
- "line 12\nline 13\nline 14\n"
- "line 15\nline 16\nline 17\n"
- "line 18\nline 19\nline 20\n"
- "line 21\nline 22\nline 23\n");
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/tree-simple.cxx b/branch-3.0-2011/examples/tree-simple.cxx
deleted file mode 100644
index d7c13ab23..000000000
--- a/branch-3.0-2011/examples/tree-simple.cxx
+++ /dev/null
@@ -1,72 +0,0 @@
-//
-// "$Id$"
-//
-// Simple Fl_Tree widget example. - erco 06/05/2010
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <stdio.h>
-#include <FL/Fl.H>
-#include <FL/Fl_Double_Window.H>
-#include <FL/Fl_Tree.H>
-
-// Tree's callback
-// Invoked whenever someone clicks an item.
-//
-void TreeCallback(Fl_Widget *w, void *data) {
- Fl_Tree *tree = (Fl_Tree*)w;
- Fl_Tree_Item *item = (Fl_Tree_Item*)tree->item_clicked();
- fprintf(stderr, "TreeCallback: item clicked='%s'\n", (item)?item->label():"???");
-}
-
-int main(int argc, char *argv[]) {
- Fl::scheme("gtk+");
- Fl_Double_Window *win = new Fl_Double_Window(250, 400, "Simple Tree");
- win->begin();
- {
- // Create the tree
- Fl_Tree *tree = new Fl_Tree(10, 10, win->w()-20, win->h()-20);
- tree->showroot(0); // don't show root of tree
- tree->callback(TreeCallback); // setup a callback for the tree
-
- // Add some items
- tree->add("Flintstones/Fred");
- tree->add("Flintstones/Wilma");
- tree->add("Flintstones/Pebbles");
- tree->add("Simpsons/Homer");
- tree->add("Simpsons/Marge");
- tree->add("Simpsons/Bart");
- tree->add("Simpsons/Lisa");
-
- // Start with one of the items closed
- tree->close("Simpsons");
- }
- win->end();
- win->resizable(win);
- win->show(argc, argv);
- return(Fl::run());
-}
-
-//
-// End of "$Id$".
-//
diff --git a/branch-3.0-2011/examples/wizard-simple.cxx b/branch-3.0-2011/examples/wizard-simple.cxx
deleted file mode 100644
index 25b506d72..000000000
--- a/branch-3.0-2011/examples/wizard-simple.cxx
+++ /dev/null
@@ -1,90 +0,0 @@
-//
-// "$Id$"
-//
-// Simple Fl_Wizard widget example.
-// Originally from erco's cheat sheet 06/05/2010, permission by author.
-//
-// Copyright 2010 Greg Ercolano.
-// Copyright 1998-2010 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems on the following page:
-//
-// http://www.fltk.org/str.php
-//
-#include <stdlib.h>
-#include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-#include <FL/Fl_Group.H>
-#include <FL/Fl_Wizard.H>
-#include <FL/Fl_Button.H>
-#include <FL/Fl_Multiline_Output.H>
-//
-// Simple 'wizard' using fltk's new Fl_Wizard widget
-//
-Fl_Window *G_win = 0;
-Fl_Wizard *G_wiz = 0;
-
-void back_cb(Fl_Widget*,void*) { G_wiz->prev(); }
-void next_cb(Fl_Widget*,void*) { G_wiz->next(); }
-void done_cb(Fl_Widget*,void*) { exit(0); }
-
-int main(int argc, char **argv) {
- G_win = new Fl_Window(400,300,"Example Wizard");
- G_wiz = new Fl_Wizard(0,0,400,300);
-
- // Wizard: page 1
- {
- Fl_Group *g = new Fl_Group(0,0,400,300);
- Fl_Button *next = new Fl_Button(290,265,100,25,"Next @->"); next->callback(next_cb);
- Fl_Multiline_Output *out = new Fl_Multiline_Output(10,30,400-20,300-80,"Welcome");
- out->labelsize(20);
- out->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
- out->value("This is First page");
- g->end();
- }
- // Wizard: page 2
- {
- Fl_Group *g = new Fl_Group(0,0,400,300);
- Fl_Button *next = new Fl_Button(290,265,100,25,"Next @->"); next->callback(next_cb);
- Fl_Button *back = new Fl_Button(180,265,100,25,"@<- Back"); back->callback(back_cb);
- Fl_Multiline_Output *out = new Fl_Multiline_Output(10,30,400-20,300-80,"Terms And Conditions");
- out->labelsize(20);
- out->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
- out->value("This is the Second page");
- g->end();
- }
- // Wizard: page 3
- {
- Fl_Group *g = new Fl_Group(0,0,400,300);
- Fl_Button *done = new Fl_Button(290,265,100,25,"Finish"); done->callback(done_cb);
- Fl_Button *back = new Fl_Button(180,265,100,25,"@<- Back"); back->callback(back_cb);
- Fl_Multiline_Output *out = new Fl_Multiline_Output(10,30,400-20,300-80,"Finish");
- out->labelsize(20);
- out->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
- out->value("This is the Last page");
- g->end();
- }
- G_wiz->end();
- G_win->end();
- G_win->show(argc, argv);
- return Fl::run();
-}
-
-//
-// End of "$Id$".
-//