fltk
1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Fossies Dox: fltk-1.3.5-source.tar.bz2 ("inofficial" and yet experimental doxygen-generated source code documentation) 
|
Go to the documentation of this file. 41 size_t len = strlen(path);
42 char *cp =
new char[(len+1)], *word = cp, *s = cp;
43 char **ap =
new char*[(len+1)], **arr = ap;
45 if (*path ==
'/' || *path == 0) {
46 if (word != s) { *s++ = 0; *arr++= word; word = s; }
47 if ( !*path++)
break;
else continue;
48 }
else if ( *path ==
'\\' ) {
49 if ( *(++path) ) { *s++ = *path++; }
else continue;
50 }
else { *s++ = *path++; }
53 if ( arr == ap )
delete[] cp;
60 if ( arr[0] ) {
delete[] arr[0]; }
69 static int find_total_children(
Fl_Tree_Item *item,
int count=0) {
71 for (
int t=0; t<item->
children(); t++ ) {
72 count = find_total_children(item->
child(t), count);
80 #if FLTK_ABI_VERSION >= 10303 92 #if FLTK_ABI_VERSION >= 10301 108 #if FLTK_ABI_VERSION >= 10303 113 _hscroll->callback(
scroll_cb, (
void*)
this);
134 #if FLTK_ABI_VERSION >= 10303 153 int dir,
int val,
bool visible ) {
168 if ( item==to )
break;
190 #if FLTK_ABI_VERSION >= 10303 193 int val,
bool visible) {
221 if ( on || (item == from) || (item == to) ) {
234 if ( (item == from) || (item == to) ) {
243 #if FLTK_ABI_VERSION >= 10303 266 #if FLTK_ABI_VERSION >= 10301 422 if ( !
_root )
return(ret);
423 static int last_my = 0;
428 #if FLTK_ABI_VERSION >= 10303 464 int val = is_ctrl ? 2 : 1;
466 #if FLTK_ABI_VERSION >= 10303 474 }
else if ( is_ctrl ) {
501 }
else if ( my > (
y()+
h()) ) {
513 #if FLTK_ABI_VERSION >= 10303 522 if (item==_lastselect)
break;
540 int val = is_ctrl ? 2 : 1;
552 #if FLTK_ABI_VERSION >= 10303 558 if (item && _lastselect && item != _lastselect &&
563 const int mid = item->
h() / 2;
564 const bool before =
h < mid;
568 if ((before &&
prev(item) != _lastselect) ||
569 (!before &&
next(item) != _lastselect)) {
573 int pos =
parent->find_child(item);
607 #if FLTK_ABI_VERSION >= 10303 619 #if FLTK_ABI_VERSION >= 10303 620 void Fl_Tree::calc_dimensions() {
649 if ( _tree_h >= 0 && _tree_w >= 0 ) {
651 int vshow = _tree_h > _toh ? 1 : 0;
652 int hshow = _tree_w > _tow ? 1 : 0;
654 if ( hshow && !vshow && (_tree_h > (_toh-scrollsize)) ) vshow = 1;
655 if ( vshow && !hshow && (_tree_w > (_tow-scrollsize)) ) hshow = 1;
668 _hscroll->resize(_tox, _toy+_toh-scrollsize,
669 _tow - (vshow ? scrollsize : 0), scrollsize);
681 _tih = _toh - (_hscroll->visible() ? _hscroll->h() : 0);
687 _hscroll->slider_size(
float(_tiw) /
float(_tree_w));
688 _hscroll->range(0.0, _tree_w - _tiw);
731 void Fl_Tree::calc_tree() {
733 _tree_w = _tree_h = -1;
735 if ( !
_root )
return;
748 int xmax = 0, render = 0, ytop =
Y;
762 #if FLTK_ABI_VERSION >= 10303 768 #if FLTK_ABI_VERSION >= 10303 773 if ( _tree_w == -1 ) calc_tree();
774 else calc_dimensions();
783 if ( !
_root )
return;
788 int W = _tiw - X + _tix;
811 fl_rectf(_hscroll->x()+_hscroll->w(),
825 const int mid = item->
h() / 2;
826 const bool before =
h < mid;
830 int tgt = item->
y() + (before ? 0 : item->
h());
831 fl_line(item->
x(), tgt, item->
x() + item->
w(), tgt);
847 int range2 = scrollval - ytoofar;
848 int size2 = ch + range2;
868 const int mid = item->
h() / 2;
869 const bool before =
h < mid;
873 int tgt = item->
y() + (before ? 0 : item->
h());
874 fl_line(item->
x(), tgt, item->
x() + item->
w(), tgt);
896 if ( !
_root )
return(0);
919 #if FLTK_ABI_VERSION >= 10301 921 int SY =
Y +
_prefs.marginbottom();
927 int ytoofar = (cy+ch) - SY;
928 if ( ytoofar > 0 ) ydiff += ytoofar;
959 if ( !
_root )
return;
968 if ( !
_root )
return;
982 #if FLTK_ABI_VERSION >= 10303 1016 #if FLTK_ABI_VERSION >= 10303 1031 #if FLTK_ABI_VERSION >= 10303 1042 return add(path, 0);
1117 #if FLTK_ABI_VERSION >= 10301 1118 if ( item == _lastselect ) _lastselect = 0;
1120 if ( item ==
_root ) {
1124 if ( !
parent )
return(-1);
1125 parent->remove_child(item);
1134 if ( !
_root )
return;
1138 #if FLTK_ABI_VERSION >= 10301 1181 return(const_cast<Fl_Tree_Item*>(
1182 static_cast<const Fl_Tree&>(*this).find_item(path)));
1189 #define SAFE_RCAT(c) { \ 1190 slen += 1; if ( slen >= pathnamelen ) { pathname[0] = '\0'; return(-2); } \ 1213 item = item ? item :
_root;
1214 if ( !item )
return(-1);
1216 char *s = (pathname+pathnamelen-1);
1223 int len = (int) strlen(
name);
1225 for ( --len; len>=0; len-- ) {
1227 if (
name[len] ==
'/' ||
name[len] ==
'\\' ) {
1234 if ( *(++s) ==
'/' ) { ++s; --slen; }
1235 if ( s != pathname ) memmove(pathname, s, slen);
1239 #if FLTK_ABI_VERSION >= 10303 1265 return(const_cast<Fl_Tree_Item*>(
1266 static_cast<const Fl_Tree&>(*this).find_clicked(yonly)));
1291 return(const_cast<Fl_Tree_Item*>(
1292 static_cast<const Fl_Tree&>(*this).find_clicked()));
1372 if ( i->
visible() )
return(i);
1392 if ( ! item )
return(0);
1393 return(item->
next());
1410 if ( ! item )
return(0);
1411 return(item->
prev());
1427 if ( !
_root )
return(0);
1480 #if FLTK_ABI_VERSION >= 10303 1576 if ( ! item )
return(0);
1582 else return(item->
prev());
1585 else return(item->
next());
1619 if ( ! (item =
first()) )
return(0);
1622 while ( (item = item->
next()) )
1628 if ( ! (item =
last()) )
return(0);
1631 while ( (item = item->
prev()) )
1639 #if FLTK_ABI_VERSION >= 10303 1664 return ret_items.
total();
1690 if ( item->
is_open() )
return(0);
1725 if ( ! item )
return(-1);
1726 return(
open(item, docallback));
1748 close(item, docallback);
1750 open(item, docallback);
1808 if ( ! item )
return(-1);
1809 return(
close(item, docallback));
1843 if ( ! item )
return(-1);
1871 if ( ! item )
return(-1);
1894 if ( !alreadySelected ) {
1903 #if FLTK_ABI_VERSION >= 10301 1905 if ( alreadySelected ) {
1906 if ( (item_reselect_mode() == FL_TREE_SELECTABLE_ALWAYS) && docallback ) {
1938 if ( ! item )
return(-1);
1939 return(
select(item, docallback));
2022 if ( ! item )
return(-1);
2023 return(
deselect(item, docallback));
2045 item = item ? item :
first();
2046 if ( ! item )
return(0);
2053 for (
int t=0; t<item->
children(); t++ ) {
2078 selitem = selitem ? selitem :
first();
2079 if ( ! selitem )
return(0);
2085 if ( item == selitem )
continue;
2091 #if FLTK_ABI_VERSION >= 10301 2093 if ( selitem->
is_selected() && (item_reselect_mode()==FL_TREE_SELECTABLE_ALWAYS) ) {
2095 select(selitem, docallback);
2098 select(selitem, docallback);
2104 select(selitem, docallback);
2130 item = item ? item :
first();
2131 if ( ! item )
return(0);
2135 if (
select(item, docallback) )
2138 for (
int t=0; t<item->
children(); t++ ) {
2187 if ( ! item )
return(-1);
2283 #if FLTK_ABI_VERSION >= 10301 2284 int Fl_Tree::marginbottom()
const {
2288 return(
_prefs.marginbottom());
2294 void Fl_Tree::marginbottom(
int val) {
2295 _prefs.marginbottom(val);
2361 #if FLTK_ABI_VERSION >= 10301 2362 int Fl_Tree::widgetmarginleft()
const {
2365 return(
_prefs.widgetmarginleft());
2370 void Fl_Tree::widgetmarginleft(
int val) {
2371 _prefs.widgetmarginleft(val);
2546 #if FLTK_ABI_VERSION >= 10301 2547 Fl_Tree_Item_Reselect_Mode Fl_Tree::item_reselect_mode()
const {
2551 return(
_prefs.item_reselect_mode());
2558 void Fl_Tree::item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode) {
2559 _prefs.item_reselect_mode(mode);
2565 Fl_Tree_Item_Draw_Mode Fl_Tree::item_draw_mode()
const {
2566 return(
_prefs.item_draw_mode());
2576 void Fl_Tree::item_draw_mode(Fl_Tree_Item_Draw_Mode mode) {
2577 _prefs.item_draw_mode(mode);
2587 void Fl_Tree::item_draw_mode(
int mode) {
2588 _prefs.item_draw_mode(Fl_Tree_Item_Draw_Mode(mode));
2603 item = item ? item :
first();
2604 if (!item)
return(0);
2605 return( (item->
y() >=
y()) && (item->
y() <= (
y()+
h()-item->
h())) ? 1 : 0);
2623 item = item ? item :
first();
2626 if ( newval < _vscroll->minimum() ) newval = (int)
_vscroll->
minimum();
2641 item = item ? item :
first();
2652 item = item ? item :
first();
2661 item = item ? item :
first();
2662 #if FLTK_ABI_VERSION >= 10303 2663 if (item)
show_item(item, (_tih/2)-(item->
h()/2));
2674 item = item ? item :
first();
2675 #if FLTK_ABI_VERSION >= 10303 2686 item = item ? item :
first();
2706 if (pos < 0) pos = 0;
2720 #if FLTK_ABI_VERSION >= 10303 2721 return((
int)_hscroll->value());
2735 #if FLTK_ABI_VERSION >= 10303 2736 if (pos < 0) pos = 0;
2737 if (pos > _hscroll->maximum()) pos = (
int)_hscroll->maximum();
2738 if (pos == _hscroll->value())
return;
2739 _hscroll->value(pos);
2758 #if FLTK_ABI_VERSION >= 10303 2759 return( (
w==
_vscroll ||
w==_hscroll) ? 1 : 0 );
2803 #if FLTK_ABI_VERSION >= 10303 2804 if ( _hscroll->h() != scrollsize ) {
2805 _hscroll->resize(
x(),
y()+
h()-scrollsize, _hscroll->w(), scrollsize);
2824 #if FLTK_ABI_VERSION >= 10303 2825 return(_hscroll->visible() ? 1 : 0);
2891 int i, j, n, pn = (int) strlen(
prefs.path());
2893 const char *path =
prefs.path();
2894 if (strcmp(path,
".")==0)
2899 for (i=0; i<n; i++) {
2904 n =
prefs.entries();
2905 for (i=0; i<n; i++) {
2907 char *
key = strdup(
prefs.entry(i));
2908 int kn = (int) strlen(
key);
2909 for (j=0; j<kn; j++) {
2910 if (
key[j]==
'/')
key[j]=
'\\';
2912 char *val;
prefs.get(
key, val,
"");
2913 int vn = (int) strlen(val);
2914 for (j=0; j<vn; j++) {
2915 if (val[j]==
'/') val[j]=
'\\';
2918 size_t sze = pn + strlen(
key) + vn;
2920 sprintf(
p,
"%s/%s = %s", path,
key, val);
2922 size_t sze = pn + strlen(
key) + 40;
2924 sprintf(
p,
"%s/%s = %.40s...", path,
key, val);
2938 #if FLTK_ABI_VERSION >= 10303 2939 for (i = j = 0; j <
children(); j++) {
2940 if (a[j] !=
_vscroll && a[j] != _hscroll ) a[i++] = a[j];
2945 for (i = j = 0; j <
children(); j++) {
2946 if (a[j] !=
_vscroll) a[i++] = a[j];
2957 #if FLTK_ABI_VERSION >= 10303 2958 _tree_w = _tree_h = -1;
int visible() const
See if the item is visible. Alias for is_visible().
Fl_Image * openicon() const
Fl_Tree_Reason _callback_reason
void show_item(Fl_Tree_Item *item, int yoff)
int connectorwidth() const
Get the tree connection line's width.
Fl_Tree_Item * insert(const Fl_Tree_Prefs &prefs, const char *new_label, int pos=0)
int linespacing() const
Get the line spacing value in pixels.
void fl_font(Fl_Font face, Fl_Fontsize fsize)
#define FL_Up
The up arrow key.
int showroot() const
Returns 1 if the root item is to be shown, or 0 if not.
void close()
Close this item and all its children.
Fl_Tree_Item * insert(Fl_Tree_Item *item, const char *name, int pos)
static void free_path(char **arr)
#define FL_Enter
The enter key.
void show_item_middle(Fl_Tree_Item *item)
Nothing selected when items are clicked.
Fl_Tree_Connector connectorstyle() const
Returns the line drawing style for inter-connecting items.
Fl_Tree_Item * find_item(const char *path)
Non-const version of Fl_Tree::find_item(const char *path) const.
void load(class Fl_Preferences &)
Load FLTK preferences.
void fl_line(int x, int y, int x1, int y1)
void fl_rectf(int x, int y, int w, int h)
int usericonmarginleft() const
Fl_Tree_Sort sortorder() const
Get the default sort order value.
Fl_Font item_labelfont() const
Get the default font face used for creating new items.
void widget(Fl_Widget *val)
Assign an FLTK widget to this item.
const Fl_Tree_Item * find_item(char **arr) const
int y() const
The item's y position relative to the window.
void open()
Open this item and all its children.
friend class Fl_Tree_Item
int is_vscroll_visible() const
Fl_Color item_labelfgcolor(void) const
Get the default label foreground color used for creating new items.
int deselect(Fl_Tree_Item *item, int docallback=1)
void draw()
Standard FLTK draw() method, handles drawing the tree widget.
static int box_dx(Fl_Boxtype)
void set_item_focus(Fl_Tree_Item *item)
Fl_Tree_Item * first_selected_item()
Base class for image caching and drawing.
int event_on_label(const Fl_Tree_Prefs &prefs) const
char showcollapse() const
Returns 1 if the collapse icon is enabled, 0 if not.
Fl_Tree_Item * next(Fl_Tree_Item *item=0)
int select_all(Fl_Tree_Item *item=0, int docallback=1)
int is_close(Fl_Tree_Item *item) const
Fl_Image * usericon() const
void fl_color(Fl_Color c)
static int event_button()
char is_selected() const
See if the item is selected.
int is_hscroll_visible() const
#define FL_SHIFT
One of the shift keys is down.
int move_into(Fl_Tree_Item *item, int pos=0)
Fl_Tree_Sort sortorder() const
Fl_Tree_Item * prev_visible(Fl_Tree_Prefs &prefs)
int is_open(Fl_Tree_Item *item) const
Fl_Tree_Item * first_visible()
#define FL_KP_Enter
The enter key on the keypad, same as Fl_KP+'\r'.
void deselect()
Disable the item's selection state.
Fl_Tree_Item * first_visible_item()
Fl_Tree_Select selectmode() const
Get the selection mode used for the tree.
void draw(int X, int &Y, int W, Fl_Widget *tree, Fl_Tree_Item *itemfocus, const Fl_Tree_Prefs &prefs, int lastchild=1)
Fl_Tree_Item * _callback_item
int showroot() const
Returns 1 if the root item is to be shown, or 0 if not.
void open_toggle(Fl_Tree_Item *item, int docallback=1)
Fl_Tree_Item * prev(Fl_Tree_Item *item=0)
Fl_Tree_Item * add(const char *path)
int move_above(Fl_Tree_Item *item)
Single item selected when item is clicked (default)
int item_pathname(char *pathname, int pathnamelen, const Fl_Tree_Item *item) const
int children() const
Return the number of children this item has.
int x() const
The item's x position relative to the window.
int is_root() const
Is this item the root of the tree?
Fl_Image * closeicon() const
int extend_selection_dir(Fl_Tree_Item *from, Fl_Tree_Item *to, int dir, int val, bool visible)
int open(Fl_Tree_Item *item, int docallback=1)
static int box_dh(Fl_Boxtype)
#define FL_HORIZONTAL
The valuator can work horizontally.
This file contains the definitions of the Fl_Tree class.
Fl_Color connectorcolor() const
Get the connector color used for tree connection lines.
an item was dragged into a new place
#define FL_Down
The down arrow key.
void range(double a, double b)
int remove(Fl_Tree_Item *item)
static int box_dw(Fl_Boxtype)
Fl_Scrollbar * _vscroll
Vertical scrollbar.
Fl_Color labelfgcolor() const
Obsolete: Get the default label foreground color. Please use item_labelfgcolor() instead.
int is_selected(Fl_Tree_Item *item) const
int select_only(Fl_Tree_Item *selitem, int docallback=1)
Fl_Tree_Item * callback_item()
Do the callback only when the widget value changes.
#define FL_Left
The left arrow key.
Fl_Tree_Item * insert_above(Fl_Tree_Item *above, const char *name)
#define FL_Right
The right arrow key.
static int box_dy(Fl_Boxtype)
int is_scrollbar(Fl_Widget *w)
void label(const char *val)
int extend_selection__(Fl_Tree_Item *from, Fl_Tree_Item *to, int val, bool visible)
#define FL_Tab
The tab key.
Fl_Tree_Item * _item_focus
int close(Fl_Tree_Item *item, int docallback=1)
Fl_Tree_Item * last_visible()
void add(Fl_Tree_Item *val)
void do_callback_for_item(Fl_Tree_Item *item, Fl_Tree_Reason reason)
Fl_Tree_Item * item_clicked()
void select_toggle()
Toggle the item's selection state.
int usericonmarginleft() const
Get the user icon's left margin value in pixels.
int connectorwidth() const
int h() const
The item's height.
void root_label(const char *new_label)
Fl_Widget *const * array() const
static char ** parse_path(const char *path)
#define FL_COMMAND
An alias for FL_CTRL on WIN32 and X11, or FL_META on MacOS X.
static void scroll_cb(Fl_Widget *, void *data)
Fl_Tree_Item * add(const Fl_Tree_Prefs &prefs, const char *new_label, Fl_Tree_Item *newitem)
void resize(int, int, int, int)
static void remove_timeout(Fl_Timeout_Handler, void *=0)
void fl_push_clip(int x, int y, int w, int h)
int marginleft() const
Get the left margin's value in pixels.
Fl_Image * openicon() const
Fl_Image * usericon() const
Gets the default 'user icon' (default is 0)
static Fl_Widget * focus()
Fl_Color item_labelbgcolor(void) const
const Fl_Tree_Item * find_clicked(const Fl_Tree_Prefs &prefs) const
void fix_scrollbar_order()
Ensure the scrollbars are the last children.
Fl_Tree_Item * insert_above(const Fl_Tree_Prefs &prefs, const char *new_label)
void display(Fl_Tree_Item *item)
int select(Fl_Tree_Item *item, int docallback=1)
void resize(int, int, int, int)
static Fl_Widget * pushed()
Fl_Boxtype selectbox() const
Fl_Tree_Item * next_visible_item(Fl_Tree_Item *start, int dir)
Use no lines connecting items.
const Fl_Color FL_SELECTION_COLOR
the default selection/highlight color
Manages an array of Fl_Tree_Item pointers.
int openchild_marginbottom() const
Fl_Tree(int X, int Y, int W, int H, const char *L=0)
Constructor.
static int scrollbar_size()
void show_item_top(Fl_Tree_Item *item)
Fl_Tree_Item * next_visible(Fl_Tree_Prefs &prefs)
float slider_size() const
int openchild_marginbottom() const
Get the margin below an open child in pixels.
void show_item_bottom(Fl_Tree_Item *item)
void extend_selection(Fl_Tree_Item *from, Fl_Tree_Item *to)
const Fl_Color FL_BACKGROUND2_COLOR
the default background color for text, list, and valuator widgets
static void add_timeout(double t, Fl_Timeout_Handler, void *=0)
Fl_Tree_Reason callback_reason() const
static int visible_focus()
int is_close() const
See if the item is 'closed'.
Fl_Preferences provides methods to store user settings between application starts.
Fl_Tree_Item * next_selected_item(Fl_Tree_Item *item=0)
int is_visible() const
See if the item is visible.
int has_children() const
See if this item has children.
void clear_children(Fl_Tree_Item *item)
with SHIFT, CTRL or mouse drags.
Fl_Tree_Connector connectorstyle() const
Get the connector style.
const Fl_Tree_Prefs & prefs() const
Fl_Tree_Item * child(int index)
Return the child item for the given 'index'.
void clear_children()
Clear all the children for this item.
int total() const
Return the total items in the array, or 0 if empty.
Fl_Boxtype selectbox() const
Get the default selection box's box drawing style as an Fl_Boxtype.
const Fl_Tree_Item * find_clicked() const
Fl_Tree_Item * root()
Returns the root item.
Fl_Tree_Item * get_item_focus() const
Get the item that currently has keyboard focus.
#define FL_LEFT_MOUSE
The left mouse button.
Fl_Tree_Select selectmode() const
Fl_Tree_Item * next_item(Fl_Tree_Item *item, int dir=FL_Down, bool visible=false)
Fl_Tree_Item * last_selected_item()
Fl_Color connectorcolor() const
Get the connector color used for tree connection lines.
Fl_Tree_Item * parent()
Return the parent for this item. Returns NULL if we are the root.
int scrollbar_size() const
int is_open() const
See if the item is 'open'.
Fl_Fontsize labelsize() const
Obsolete: Return the label's size in pixels. Please use item_labelsize() instead.
#define FL_CTRL
One of the ctrl keys is down.
#define FL_VERTICAL
The valuator can work vertically.
void show_self(const char *indent="") const
static void redraw_soon(void *data)
void draw_child(Fl_Widget &widget) const
Fl_Tree_Item * last_visible_item()
int deselect_all(Fl_Tree_Item *item=0, int docallback=1)
Fl_Font labelfont() const
Obsolete: Return the label's font. Please use item_labelfont() instead.
int displayed(Fl_Tree_Item *item)
Fl_Color labelbgcolor() const
Obsolete: Get the default label background color. Please use item_labelbgcolor() instead.
int event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const
Fl_Image * closeicon() const
int margintop() const
Get the top margin's value in pixels.
int labelmarginleft() const
Get the label's left margin value in pixels.
static int event_inside(int, int, int, int)
int move_below(Fl_Tree_Item *item)
void select_toggle(Fl_Tree_Item *item, int docallback=1)
int labelmarginleft() const
Fl_Fontsize item_labelsize() const
Get the default label fontsize used for creating new items.