1998-10-20 17:25:25 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
|
|
|
// Browser test program for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// http://www.fltk.org/COPYING.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
/*
|
|
|
|
This is a test of how the browser draws lines.
|
|
|
|
This is a second line.
|
|
|
|
This is a third.
|
|
|
|
|
|
|
|
That was a blank line above this.
|
|
|
|
|
|
|
|
@r@_Right justify
|
|
|
|
@c@_Center justify
|
|
|
|
@_Left justify
|
|
|
|
|
|
|
|
@bBold text
|
|
|
|
@iItalic text
|
|
|
|
@b@iBold Italic
|
|
|
|
@fFixed width
|
|
|
|
@f@bBold Fixed
|
|
|
|
@f@iItalic Fixed
|
|
|
|
@f@i@bBold Italic Fixed
|
|
|
|
@lLarge
|
|
|
|
@l@bLarge bold
|
|
|
|
@sSmall
|
|
|
|
@s@bSmall bold
|
|
|
|
@s@iSmall italic
|
|
|
|
@s@i@bSmall italic bold
|
|
|
|
@uunderscore
|
|
|
|
@C1RED
|
|
|
|
@C2Green
|
|
|
|
@C4Blue
|
2018-12-29 04:16:40 +03:00
|
|
|
@N@.Inactive
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2018-12-29 04:03:49 +03:00
|
|
|
@@ start line with '@'
|
|
|
|
@.@ alternative start line with '@'
|
2018-12-29 04:08:40 +03:00
|
|
|
@l@@ start tall line with '@'
|
|
|
|
@s@@ start small line with '@'
|
|
|
|
#s## start line with '#'
|
|
|
|
#s#.# alternative start line with '#'
|
2018-12-29 04:03:49 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
You should try different browser types:
|
|
|
|
Fl_Browser
|
|
|
|
Fl_Select_Browser
|
|
|
|
Fl_Hold_Browser
|
|
|
|
Fl_Multi_Browser
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Select_Browser.H>
|
|
|
|
#include <FL/Fl_Double_Window.H>
|
2000-12-08 18:44:24 +03:00
|
|
|
#include <FL/Fl_Button.H>
|
2001-11-02 23:38:15 +03:00
|
|
|
#include <FL/Fl_Int_Input.H>
|
2013-03-24 01:32:34 +04:00
|
|
|
#include <FL/Fl_Choice.H>
|
2017-10-17 03:28:56 +03:00
|
|
|
#include <FL/Fl_Simple_Terminal.H>
|
2001-11-02 23:38:15 +03:00
|
|
|
#include <FL/fl_ask.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-12-08 18:44:24 +03:00
|
|
|
Fl_Select_Browser *browser;
|
|
|
|
Fl_Button *top,
|
|
|
|
*bottom,
|
|
|
|
*middle,
|
2004-07-27 00:52:52 +04:00
|
|
|
*visible,
|
2008-12-27 00:20:38 +03:00
|
|
|
*swap,
|
|
|
|
*sort;
|
2013-03-24 01:32:34 +04:00
|
|
|
Fl_Choice *btype;
|
2017-09-19 20:17:44 +03:00
|
|
|
Fl_Choice *wtype;
|
2001-11-02 23:38:15 +03:00
|
|
|
Fl_Int_Input *field;
|
2017-10-17 03:28:56 +03:00
|
|
|
Fl_Simple_Terminal *tty = 0;
|
2000-12-08 18:44:24 +03:00
|
|
|
|
2017-09-19 20:17:44 +03:00
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
Fl_When wvalue;
|
|
|
|
} WhenItem;
|
|
|
|
|
|
|
|
// FL_WHEN chooser..
|
|
|
|
WhenItem when_items[] = {
|
|
|
|
{ "FL_WHEN_NEVER", FL_WHEN_NEVER },
|
|
|
|
{ "FL_WHEN_CHANGED", FL_WHEN_CHANGED },
|
|
|
|
{ "FL_WHEN_NOT_CHANGED", FL_WHEN_NOT_CHANGED },
|
|
|
|
{ "FL_WHEN_RELEASE", FL_WHEN_RELEASE },
|
|
|
|
{ "FL_WHEN_RELEASE_ALWAYS", FL_WHEN_RELEASE_ALWAYS },
|
|
|
|
{ "FL_WHEN_ENTER_KEY", FL_WHEN_ENTER_KEY },
|
|
|
|
{ "FL_WHEN_ENTER_KEY_ALWAYS", FL_WHEN_ENTER_KEY_ALWAYS },
|
|
|
|
{ "FL_WHEN_ENTER_KEY_CHANGED", FL_WHEN_ENTER_KEY_CHANGED },
|
|
|
|
{ "FL_WHEN_ENTER_KEY + FL_WHEN_RELEASE_ALWAYS", Fl_When(int(FL_WHEN_ENTER_KEY_CHANGED)+int(FL_WHEN_RELEASE_ALWAYS)) }
|
|
|
|
// TODO: Perhaps other FL_WHEN_* combos are relevant
|
|
|
|
};
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void b_cb(Fl_Widget* o, void*) {
|
2017-10-17 03:28:56 +03:00
|
|
|
tty->printf("callback, selection = \033[31m%d\033[0m, event_clicks = \033[32m%d\033[0m\n",
|
1998-10-06 22:21:25 +04:00
|
|
|
((Fl_Browser*)o)->value(), Fl::event_clicks());
|
|
|
|
}
|
|
|
|
|
2000-12-08 18:44:24 +03:00
|
|
|
void show_cb(Fl_Widget *o, void *) {
|
|
|
|
int line = atoi(field->value());
|
|
|
|
|
2001-11-02 23:38:15 +03:00
|
|
|
if (!line) {
|
|
|
|
fl_alert("Please enter a number in the text field\n"
|
|
|
|
"before clicking on the buttons.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-12-08 18:44:24 +03:00
|
|
|
if (o == top)
|
|
|
|
browser->topline(line);
|
|
|
|
else if (o == bottom)
|
|
|
|
browser->bottomline(line);
|
|
|
|
else if (o == middle)
|
|
|
|
browser->middleline(line);
|
|
|
|
else
|
|
|
|
browser->make_visible(line);
|
|
|
|
}
|
|
|
|
|
2007-05-20 04:01:06 +04:00
|
|
|
void swap_cb(Fl_Widget *, void *) {
|
2004-07-27 00:52:52 +04:00
|
|
|
int a = -1, b = -1;
|
|
|
|
for ( int t=0; t<browser->size(); t++ ) { // find two selected items
|
|
|
|
if ( browser->selected(t) ) {
|
|
|
|
if ( a < 0 )
|
|
|
|
{ a = t; }
|
|
|
|
else
|
|
|
|
{ b = t; break; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
browser->swap(a, b); // swap them
|
|
|
|
}
|
|
|
|
|
2008-12-27 00:20:38 +03:00
|
|
|
void sort_cb(Fl_Widget *, void *) {
|
2009-03-26 02:09:04 +03:00
|
|
|
browser->sort(FL_SORT_ASCENDING);
|
2008-12-27 00:20:38 +03:00
|
|
|
}
|
|
|
|
|
2013-03-24 01:32:34 +04:00
|
|
|
void btype_cb(Fl_Widget *, void *) {
|
|
|
|
for ( int t=1; t<=browser->size(); t++ ) browser->select(t,0);
|
|
|
|
browser->select(1,0); // leave focus box on first line
|
|
|
|
if ( strcmp(btype->text(),"Normal")==0) browser->type(FL_NORMAL_BROWSER);
|
|
|
|
else if ( strcmp(btype->text(),"Select")==0) browser->type(FL_SELECT_BROWSER);
|
|
|
|
else if ( strcmp(btype->text(),"Hold" )==0) browser->type(FL_HOLD_BROWSER);
|
|
|
|
else if ( strcmp(btype->text(),"Multi" )==0) browser->type(FL_MULTI_BROWSER);
|
|
|
|
browser->redraw();
|
|
|
|
}
|
|
|
|
|
2017-09-19 20:17:44 +03:00
|
|
|
void wtype_cb(Fl_Widget *, void *) {
|
|
|
|
if ( wtype->value() < 0 ) return;
|
|
|
|
browser->when( when_items[wtype->value()].wvalue ); // when value based on array
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int i;
|
|
|
|
if (!Fl::args(argc,argv,i)) Fl::fatal(Fl::help);
|
1998-12-06 18:57:05 +03:00
|
|
|
const char* fname = (i < argc) ? argv[i] : "browser.cxx";
|
2017-10-17 03:28:56 +03:00
|
|
|
Fl_Double_Window window(720,520,fname);
|
2017-09-19 20:17:44 +03:00
|
|
|
browser = new Fl_Select_Browser(0,0,window.w(),350,0);
|
2000-12-08 18:44:24 +03:00
|
|
|
browser->type(FL_MULTI_BROWSER);
|
|
|
|
//browser->type(FL_HOLD_BROWSER);
|
|
|
|
//browser->color(42);
|
|
|
|
browser->callback(b_cb);
|
|
|
|
// browser->scrollbar_right();
|
|
|
|
//browser->has_scrollbar(Fl_Browser::BOTH_ALWAYS);
|
2018-12-29 04:03:49 +03:00
|
|
|
//browser->format_char('#');
|
2001-12-21 17:35:34 +03:00
|
|
|
if (!browser->load(fname)) {
|
2008-05-13 18:48:28 +04:00
|
|
|
int done = 0;
|
2001-12-21 17:35:34 +03:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
// if 'browser' was started from the VisualC environment in Win32,
|
|
|
|
// the current directory is set to the environment itself,
|
|
|
|
// so we need to correct the browser file path
|
|
|
|
if ( i == argc )
|
|
|
|
{
|
|
|
|
fname = "../test/browser.cxx";
|
|
|
|
done = browser->load(fname);
|
|
|
|
}
|
2012-12-05 18:53:03 +04:00
|
|
|
#elif defined(__APPLE__)
|
2016-08-31 19:59:22 +03:00
|
|
|
char buf[2048];
|
|
|
|
strcpy(buf, argv[0]);
|
|
|
|
char *slash = strrchr(buf, '/');
|
|
|
|
if (slash) {
|
|
|
|
strcpy(slash, "/../../../browser.cxx");
|
2008-05-13 18:48:28 +04:00
|
|
|
}
|
2016-08-31 19:59:22 +03:00
|
|
|
done = browser->load(buf);
|
2008-05-13 18:48:28 +04:00
|
|
|
#endif
|
2001-12-21 17:35:34 +03:00
|
|
|
if ( !done )
|
|
|
|
{
|
2009-12-07 01:21:55 +03:00
|
|
|
fl_message("Can't load %s, %s\n", fname, strerror(errno));
|
2001-12-21 17:35:34 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2000-12-08 18:44:24 +03:00
|
|
|
browser->position(0);
|
|
|
|
|
2017-09-19 20:17:44 +03:00
|
|
|
field = new Fl_Int_Input(55, 350, window.w()-55, 25, "Line #:");
|
2000-12-08 18:44:24 +03:00
|
|
|
field->callback(show_cb);
|
|
|
|
|
2004-07-27 00:52:52 +04:00
|
|
|
top = new Fl_Button(0, 375, 80, 25, "Top");
|
2000-12-08 18:44:24 +03:00
|
|
|
top->callback(show_cb);
|
|
|
|
|
2004-07-27 00:52:52 +04:00
|
|
|
bottom = new Fl_Button(80, 375, 80, 25, "Bottom");
|
2000-12-08 18:44:24 +03:00
|
|
|
bottom->callback(show_cb);
|
|
|
|
|
2004-07-27 00:52:52 +04:00
|
|
|
middle = new Fl_Button(160, 375, 80, 25, "Middle");
|
2000-12-08 18:44:24 +03:00
|
|
|
middle->callback(show_cb);
|
|
|
|
|
2004-07-27 00:52:52 +04:00
|
|
|
visible = new Fl_Button(240, 375, 80, 25, "Make Vis.");
|
2000-12-08 18:44:24 +03:00
|
|
|
visible->callback(show_cb);
|
|
|
|
|
2004-07-27 00:52:52 +04:00
|
|
|
swap = new Fl_Button(320, 375, 80, 25, "Swap");
|
|
|
|
swap->callback(swap_cb);
|
|
|
|
swap->tooltip("Swaps two selected lines\n(Use CTRL-click to select two lines)");
|
|
|
|
|
2008-12-27 00:20:38 +03:00
|
|
|
sort = new Fl_Button(400, 375, 80, 25, "Sort");
|
|
|
|
sort->callback(sort_cb);
|
|
|
|
|
2013-03-24 01:32:34 +04:00
|
|
|
btype = new Fl_Choice(480, 375, 80, 25);
|
|
|
|
btype->add("Normal");
|
|
|
|
btype->add("Select");
|
|
|
|
btype->add("Hold");
|
|
|
|
btype->add("Multi");
|
|
|
|
btype->callback(btype_cb);
|
|
|
|
btype->value(3);
|
|
|
|
btype->tooltip("Changes the browser type()");
|
|
|
|
|
2017-09-19 20:17:44 +03:00
|
|
|
wtype = new Fl_Choice(560, 375, 160, 25);
|
|
|
|
wtype->textsize(8);
|
|
|
|
// Append items from when_items[] array
|
|
|
|
{
|
|
|
|
int len = sizeof(when_items) / sizeof(WhenItem);
|
|
|
|
for ( int i=0; i<len; i++ )
|
|
|
|
wtype->add(when_items[i].name);
|
|
|
|
}
|
|
|
|
wtype->callback(wtype_cb);
|
|
|
|
wtype->value(4); // FL_WHEN_RELEASE_ALWAYS is Fl_Browser's default
|
|
|
|
|
2017-10-17 03:28:56 +03:00
|
|
|
// Small terminal window for callback messages
|
|
|
|
tty = new Fl_Simple_Terminal(0,400,720,120);
|
|
|
|
tty->history_lines(50);
|
|
|
|
tty->ansi(true);
|
|
|
|
|
2000-12-08 18:44:24 +03:00
|
|
|
window.resizable(browser);
|
1998-10-06 22:21:25 +04:00
|
|
|
window.show(argc,argv);
|
|
|
|
return Fl::run();
|
|
|
|
}
|
|
|
|
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|