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).
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// Copyright 1998-2005 by Bill Spitzak and others.
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
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
|
|
|
|
|
|
|
|
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>
|
|
|
|
#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,
|
|
|
|
*swap;
|
2001-11-02 23:38:15 +03:00
|
|
|
Fl_Int_Input *field;
|
2000-12-08 18:44:24 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void b_cb(Fl_Widget* o, void*) {
|
|
|
|
printf("callback, selection = %d, event_clicks = %d\n",
|
|
|
|
((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);
|
|
|
|
}
|
|
|
|
|
2004-07-27 00:52:52 +04:00
|
|
|
void swap_cb(Fl_Widget *o, void *) {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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";
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Window window(400,400,fname);
|
2000-12-08 18:44:24 +03:00
|
|
|
browser = new Fl_Select_Browser(0,0,400,350,0);
|
|
|
|
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);
|
2001-12-21 17:35:34 +03:00
|
|
|
if (!browser->load(fname)) {
|
|
|
|
#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
|
|
|
|
int done = 1;
|
|
|
|
if ( i == argc )
|
|
|
|
{
|
|
|
|
fname = "../test/browser.cxx";
|
|
|
|
done = browser->load(fname);
|
|
|
|
}
|
|
|
|
if ( !done )
|
|
|
|
{
|
|
|
|
printf("Can't load %s, %s\n", fname, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-12-01 04:54:30 +03:00
|
|
|
#else
|
1998-10-06 22:21:25 +04:00
|
|
|
printf("Can't load %s, %s\n", fname, strerror(errno));
|
2001-12-21 17:35:34 +03:00
|
|
|
exit(1);
|
2001-12-01 04:54:30 +03:00
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2000-12-08 18:44:24 +03:00
|
|
|
browser->position(0);
|
|
|
|
|
2001-11-02 23:38:15 +03:00
|
|
|
field = new Fl_Int_Input(50, 350, 350, 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)");
|
|
|
|
|
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
|
|
|
|