2001-08-01 21:24:49 +00:00
|
|
|
//
|
2005-02-05 18:26:21 +00:00
|
|
|
// "$Id$"
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
2001-09-29 14:38:59 +00:00
|
|
|
// Fl_File_Browser routines.
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
2010-11-28 21:06:39 +00:00
|
|
|
// Copyright 1999-2010 by Michael Sweet.
|
2016-04-10 06:33:19 +00:00
|
|
|
// Copyright 2016 by Bill Spitzak and others.
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
2011-07-19 04:49:30 +00: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:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
2005-04-16 00:13:17 +00:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
|
|
|
// Contents:
|
|
|
|
//
|
2002-05-02 14:31:10 +00:00
|
|
|
// Fl_File_Browser::full_height() - Return the height of the list.
|
|
|
|
// Fl_File_Browser::item_height() - Return the height of a list item.
|
|
|
|
// Fl_File_Browser::item_width() - Return the width of a list item.
|
|
|
|
// Fl_File_Browser::item_draw() - Draw a list item.
|
2001-09-29 14:38:59 +00:00
|
|
|
// Fl_File_Browser::Fl_File_Browser() - Create a Fl_File_Browser widget.
|
2002-05-02 14:31:10 +00:00
|
|
|
// Fl_File_Browser::load() - Load a directory into the browser.
|
|
|
|
// Fl_File_Browser::filter() - Set the filename filter.
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Include necessary header files...
|
|
|
|
//
|
|
|
|
|
2001-09-29 14:38:59 +00:00
|
|
|
#include <FL/Fl_File_Browser.H>
|
2016-04-08 15:48:28 +00:00
|
|
|
#include <FL/Fl.H>
|
2018-06-26 14:12:43 +00:00
|
|
|
#include "Fl_System_Driver.H"
|
2001-08-02 16:17:04 +00:00
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/filename.H>
|
2009-09-07 21:17:08 +00:00
|
|
|
#include <FL/Fl_Image.H> // icon
|
2001-08-02 16:17:04 +00:00
|
|
|
#include <stdio.h>
|
2001-08-01 21:24:49 +00:00
|
|
|
#include <stdlib.h>
|
2001-11-25 16:38:11 +00:00
|
|
|
#include "flstring.h"
|
2001-08-01 21:24:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// FL_BLINE definition from "Fl_Browser.cxx"...
|
|
|
|
//
|
|
|
|
|
|
|
|
#define SELECTED 1
|
|
|
|
#define NOTDISPLAYED 2
|
|
|
|
|
2009-09-09 05:16:41 +00:00
|
|
|
// TODO -- Warning: The definition of FL_BLINE here is a hack.
|
|
|
|
// Fl_File_Browser should not do this. PLEASE FIX.
|
|
|
|
// FL_BLINE should be private to Fl_Browser, and not re-defined here.
|
|
|
|
// For now, make sure this struct is precisely consistent with Fl_Browser.cxx.
|
|
|
|
//
|
2001-08-01 21:24:49 +00:00
|
|
|
struct FL_BLINE // data is in a linked list of these
|
|
|
|
{
|
|
|
|
FL_BLINE *prev; // Previous item in list
|
|
|
|
FL_BLINE *next; // Next item in list
|
|
|
|
void *data; // Pointer to data (function)
|
2009-09-07 21:17:08 +00:00
|
|
|
Fl_Image *icon; // Pointer to optional icon
|
2001-08-01 21:24:49 +00:00
|
|
|
short length; // sizeof(txt)-1, may be longer than string
|
|
|
|
char flags; // selected, displayed
|
|
|
|
char txt[1]; // start of allocated array
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-08-02 16:17:04 +00:00
|
|
|
//
|
2001-09-29 14:38:59 +00:00
|
|
|
// 'Fl_File_Browser::full_height()' - Return the height of the list.
|
2001-08-02 16:17:04 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Height in pixels
|
2001-09-29 14:38:59 +00:00
|
|
|
Fl_File_Browser::full_height() const
|
2001-08-02 16:17:04 +00:00
|
|
|
{
|
|
|
|
int i, // Looping var
|
|
|
|
th; // Total height of list.
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0, th = 0; i < size(); i ++)
|
|
|
|
th += item_height(find_line(i));
|
|
|
|
|
|
|
|
return (th);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
2001-09-29 14:38:59 +00:00
|
|
|
// 'Fl_File_Browser::item_height()' - Return the height of a list item.
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Height in pixels
|
2001-09-29 14:38:59 +00:00
|
|
|
Fl_File_Browser::item_height(void *p) const // I - List item data
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
|
|
|
FL_BLINE *line; // Pointer to line
|
2002-08-09 01:09:49 +00:00
|
|
|
char *t; // Pointer into text
|
2001-08-01 21:24:49 +00:00
|
|
|
int height; // Width of line
|
|
|
|
int textheight; // Height of text
|
|
|
|
|
|
|
|
|
|
|
|
// Figure out the standard text height...
|
2001-08-02 16:17:04 +00:00
|
|
|
fl_font(textfont(), textsize());
|
|
|
|
textheight = fl_height();
|
2001-08-01 21:24:49 +00:00
|
|
|
|
|
|
|
// We always have at least 1 line...
|
|
|
|
height = textheight;
|
|
|
|
|
|
|
|
// Scan for newlines...
|
|
|
|
line = (FL_BLINE *)p;
|
|
|
|
|
|
|
|
if (line != NULL)
|
2002-08-09 01:09:49 +00:00
|
|
|
for (t = line->txt; *t != '\0'; t ++)
|
|
|
|
if (*t == '\n')
|
2001-08-01 21:24:49 +00:00
|
|
|
height += textheight;
|
|
|
|
|
|
|
|
// If we have enabled icons then add space for them...
|
2001-09-29 14:38:59 +00:00
|
|
|
if (Fl_File_Icon::first() != NULL && height < iconsize_)
|
2001-08-01 21:24:49 +00:00
|
|
|
height = iconsize_;
|
|
|
|
|
|
|
|
// Add space for the selection border..
|
|
|
|
height += 2;
|
|
|
|
|
|
|
|
// Return the height
|
|
|
|
return (height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 14:38:59 +00:00
|
|
|
// 'Fl_File_Browser::item_width()' - Return the width of a list item.
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Width in pixels
|
2001-09-29 14:38:59 +00:00
|
|
|
Fl_File_Browser::item_width(void *p) const // I - List item data
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
2001-08-02 16:17:04 +00:00
|
|
|
int i; // Looping var
|
2001-08-01 21:24:49 +00:00
|
|
|
FL_BLINE *line; // Pointer to line
|
2002-08-09 01:09:49 +00:00
|
|
|
char *t, // Pointer into text
|
2001-08-01 21:24:49 +00:00
|
|
|
*ptr, // Pointer into fragment
|
|
|
|
fragment[10240]; // Fragment of text
|
|
|
|
int width, // Width of line
|
|
|
|
tempwidth; // Width of fragment
|
|
|
|
int column; // Current column
|
2001-08-02 16:17:04 +00:00
|
|
|
const int *columns; // Columns
|
2001-08-01 21:24:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Scan for newlines...
|
2001-08-02 16:17:04 +00:00
|
|
|
line = (FL_BLINE *)p;
|
|
|
|
columns = column_widths();
|
2001-08-01 21:24:49 +00:00
|
|
|
|
2006-10-29 12:13:56 +00:00
|
|
|
// Set the font and size...
|
|
|
|
if (line->txt[strlen(line->txt) - 1] == '/')
|
|
|
|
fl_font(textfont() | FL_BOLD, textsize());
|
|
|
|
else
|
|
|
|
fl_font(textfont(), textsize());
|
|
|
|
|
2001-08-01 21:24:49 +00:00
|
|
|
if (strchr(line->txt, '\n') == NULL &&
|
2001-08-02 16:17:04 +00:00
|
|
|
strchr(line->txt, column_char()) == NULL)
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
|
|
|
// Do a fast width calculation...
|
2001-08-02 16:17:04 +00:00
|
|
|
width = (int)fl_width(line->txt);
|
2001-08-01 21:24:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// More than 1 line or have columns; find the maximum width...
|
|
|
|
width = 0;
|
|
|
|
tempwidth = 0;
|
|
|
|
column = 0;
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
for (t = line->txt, ptr = fragment; *t != '\0'; t ++)
|
|
|
|
if (*t == '\n')
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
|
|
|
// Newline - nul terminate this fragment and get the width...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
2001-08-02 16:17:04 +00:00
|
|
|
tempwidth += (int)fl_width(fragment);
|
2001-08-01 21:24:49 +00:00
|
|
|
|
|
|
|
// Update the max width as needed...
|
|
|
|
if (tempwidth > width)
|
|
|
|
width = tempwidth;
|
|
|
|
|
|
|
|
// Point back to the start of the fragment...
|
|
|
|
ptr = fragment;
|
|
|
|
tempwidth = 0;
|
2001-08-02 16:17:04 +00:00
|
|
|
column = 0;
|
2001-08-01 21:24:49 +00:00
|
|
|
}
|
2002-08-09 01:09:49 +00:00
|
|
|
else if (*t == column_char())
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
|
|
|
// Advance to the next column...
|
|
|
|
column ++;
|
2001-08-02 16:17:04 +00:00
|
|
|
if (columns)
|
|
|
|
{
|
|
|
|
for (i = 0, tempwidth = 0; i < column && columns[i]; i ++)
|
|
|
|
tempwidth += columns[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tempwidth = column * (int)(fl_height() * 0.6 * 8.0);
|
2001-08-01 21:24:49 +00:00
|
|
|
|
|
|
|
if (tempwidth > width)
|
|
|
|
width = tempwidth;
|
|
|
|
|
|
|
|
ptr = fragment;
|
|
|
|
}
|
|
|
|
else
|
2002-08-09 01:09:49 +00:00
|
|
|
*ptr++ = *t;
|
2001-08-01 21:24:49 +00:00
|
|
|
|
|
|
|
if (ptr > fragment)
|
|
|
|
{
|
|
|
|
// Nul terminate this fragment and get the width...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
2001-08-02 16:17:04 +00:00
|
|
|
tempwidth += (int)fl_width(fragment);
|
2001-08-01 21:24:49 +00:00
|
|
|
|
|
|
|
// Update the max width as needed...
|
|
|
|
if (tempwidth > width)
|
|
|
|
width = tempwidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have enabled icons then add space for them...
|
2001-09-29 14:38:59 +00:00
|
|
|
if (Fl_File_Icon::first() != NULL)
|
2001-08-01 21:24:49 +00:00
|
|
|
width += iconsize_ + 8;
|
|
|
|
|
|
|
|
// Add space for the selection border..
|
|
|
|
width += 2;
|
|
|
|
|
|
|
|
// Return the width
|
|
|
|
return (width);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 14:38:59 +00:00
|
|
|
// 'Fl_File_Browser::item_draw()' - Draw a list item.
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
void
|
2001-09-29 14:38:59 +00:00
|
|
|
Fl_File_Browser::item_draw(void *p, // I - List item data
|
2002-08-09 01:09:49 +00:00
|
|
|
int X, // I - Upper-lefthand X coordinate
|
|
|
|
int Y, // I - Upper-lefthand Y coordinate
|
|
|
|
int W, // I - Width of item
|
2002-08-13 15:42:44 +00:00
|
|
|
int) const // I - Height of item
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
2001-08-02 16:17:04 +00:00
|
|
|
int i; // Looping var
|
2001-08-01 21:24:49 +00:00
|
|
|
FL_BLINE *line; // Pointer to line
|
2001-08-02 16:17:04 +00:00
|
|
|
Fl_Color c; // Text color
|
2002-08-09 01:09:49 +00:00
|
|
|
char *t, // Pointer into text
|
2001-08-02 16:17:04 +00:00
|
|
|
*ptr, // Pointer into fragment
|
|
|
|
fragment[10240]; // Fragment of text
|
|
|
|
int width, // Width of line
|
|
|
|
height; // Height of line
|
|
|
|
int column; // Current column
|
|
|
|
const int *columns; // Columns
|
2001-08-01 21:24:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Draw the list item text...
|
|
|
|
line = (FL_BLINE *)p;
|
|
|
|
|
2001-08-03 18:46:57 +00:00
|
|
|
if (line->txt[strlen(line->txt) - 1] == '/')
|
|
|
|
fl_font(textfont() | FL_BOLD, textsize());
|
|
|
|
else
|
|
|
|
fl_font(textfont(), textsize());
|
2001-08-01 21:24:49 +00:00
|
|
|
|
2001-08-02 16:17:04 +00:00
|
|
|
if (line->flags & SELECTED)
|
2001-10-29 03:44:33 +00:00
|
|
|
c = fl_contrast(textcolor(), selection_color());
|
2001-08-01 21:24:49 +00:00
|
|
|
else
|
2001-08-02 16:17:04 +00:00
|
|
|
c = textcolor();
|
2001-08-01 21:24:49 +00:00
|
|
|
|
2001-09-29 14:38:59 +00:00
|
|
|
if (Fl_File_Icon::first() == NULL)
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
|
|
|
// No icons, just draw the text...
|
2002-08-09 01:09:49 +00:00
|
|
|
X ++;
|
|
|
|
W -= 2;
|
2001-08-01 21:24:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-02 16:17:04 +00:00
|
|
|
// Draw the icon if it is set...
|
2001-08-01 21:24:49 +00:00
|
|
|
if (line->data)
|
2002-08-09 01:09:49 +00:00
|
|
|
((Fl_File_Icon *)line->data)->draw(X, Y, iconsize_, iconsize_,
|
2001-08-03 18:46:57 +00:00
|
|
|
(line->flags & SELECTED) ? FL_YELLOW :
|
|
|
|
FL_LIGHT2,
|
|
|
|
active_r());
|
2001-08-02 16:17:04 +00:00
|
|
|
|
|
|
|
// Draw the text offset to the right...
|
2002-08-09 01:09:49 +00:00
|
|
|
X += iconsize_ + 9;
|
|
|
|
W -= iconsize_ - 10;
|
2001-08-02 16:17:04 +00:00
|
|
|
|
|
|
|
// Center the text vertically...
|
|
|
|
height = fl_height();
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
for (t = line->txt; *t != '\0'; t ++)
|
|
|
|
if (*t == '\n')
|
2001-08-02 16:17:04 +00:00
|
|
|
height += fl_height();
|
|
|
|
|
|
|
|
if (height < iconsize_)
|
2002-08-09 01:09:49 +00:00
|
|
|
Y += (iconsize_ - height) / 2;
|
2001-08-02 16:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the text...
|
|
|
|
line = (FL_BLINE *)p;
|
|
|
|
columns = column_widths();
|
|
|
|
width = 0;
|
|
|
|
column = 0;
|
|
|
|
|
|
|
|
if (active_r())
|
|
|
|
fl_color(c);
|
|
|
|
else
|
2001-10-29 03:44:33 +00:00
|
|
|
fl_color(fl_inactive(c));
|
2001-08-02 16:17:04 +00:00
|
|
|
|
2014-11-27 15:29:54 +00:00
|
|
|
for (t = line->txt, ptr = fragment; *t != '\0'; t ++) {
|
|
|
|
if (*t == '\n') {
|
2001-08-02 16:17:04 +00:00
|
|
|
// Newline - nul terminate this fragment and draw it...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
fl_draw(fragment, X + width, Y, W - width, fl_height(),
|
2001-11-03 05:11:34 +00:00
|
|
|
(Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP), 0, 0);
|
2001-08-02 16:17:04 +00:00
|
|
|
|
|
|
|
// Point back to the start of the fragment...
|
|
|
|
ptr = fragment;
|
|
|
|
width = 0;
|
2002-08-09 01:09:49 +00:00
|
|
|
Y += fl_height();
|
2001-08-02 16:17:04 +00:00
|
|
|
column = 0;
|
2014-11-27 15:29:54 +00:00
|
|
|
} else if (*t == column_char()) {
|
2001-08-02 16:17:04 +00:00
|
|
|
// Tab - nul terminate this fragment and draw it...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
int cW = W - width; // Clip width...
|
2002-05-06 04:11:50 +00:00
|
|
|
|
2014-11-27 15:29:54 +00:00
|
|
|
if (columns) {
|
|
|
|
// Try clipping inside this column...
|
2014-05-04 13:46:09 +00:00
|
|
|
for (i = 0; i < column && columns[i]; i ++) { ; }
|
2002-05-06 04:11:50 +00:00
|
|
|
|
2014-11-27 15:29:54 +00:00
|
|
|
if (columns[i])
|
|
|
|
cW = columns[i];
|
2002-05-06 04:11:50 +00:00
|
|
|
}
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
fl_draw(fragment, X + width, Y, cW, fl_height(),
|
2001-11-03 05:11:34 +00:00
|
|
|
(Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP), 0, 0);
|
2001-08-02 16:17:04 +00:00
|
|
|
|
|
|
|
// Advance to the next column...
|
|
|
|
column ++;
|
2014-11-27 15:29:54 +00:00
|
|
|
if (columns) {
|
2001-08-02 16:17:04 +00:00
|
|
|
for (i = 0, width = 0; i < column && columns[i]; i ++)
|
|
|
|
width += columns[i];
|
|
|
|
}
|
|
|
|
else
|
2014-11-27 15:29:54 +00:00
|
|
|
width = column * (int)(fl_height() * 0.6 * 8.0);
|
2001-08-02 16:17:04 +00:00
|
|
|
ptr = fragment;
|
|
|
|
}
|
|
|
|
else
|
2002-08-09 01:09:49 +00:00
|
|
|
*ptr++ = *t;
|
2014-11-27 15:29:54 +00:00
|
|
|
}
|
|
|
|
if (ptr > fragment) {
|
2001-08-02 16:17:04 +00:00
|
|
|
// Nul terminate this fragment and draw it...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
fl_draw(fragment, X + width, Y, W - width, fl_height(),
|
2001-11-03 05:11:34 +00:00
|
|
|
(Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP), 0, 0);
|
2001-08-01 21:24:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 14:38:59 +00:00
|
|
|
// 'Fl_File_Browser::Fl_File_Browser()' - Create a Fl_File_Browser widget.
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
Fl_File_Browser::Fl_File_Browser(int X, // I - Upper-lefthand X coordinate
|
|
|
|
int Y, // I - Upper-lefthand Y coordinate
|
|
|
|
int W, // I - Width in pixels
|
|
|
|
int H, // I - Height in pixels
|
2002-03-29 14:16:03 +00:00
|
|
|
const char *l) // I - Label text
|
2002-08-09 01:09:49 +00:00
|
|
|
: Fl_Browser(X, Y, W, H, l)
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
|
|
|
// Initialize the filter pattern, current directory, and icon size...
|
|
|
|
pattern_ = "*";
|
|
|
|
directory_ = "";
|
2002-11-19 16:37:36 +00:00
|
|
|
iconsize_ = (uchar)(3 * textsize() / 2);
|
2001-09-04 13:13:29 +00:00
|
|
|
filetype_ = FILES;
|
2001-08-01 21:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 14:38:59 +00:00
|
|
|
// 'Fl_File_Browser::load()' - Load a directory into the browser.
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
|
|
|
|
2002-05-02 14:31:10 +00:00
|
|
|
int // O - Number of files loaded
|
|
|
|
Fl_File_Browser::load(const char *directory,// I - Directory to load
|
|
|
|
Fl_File_Sort_F *sort) // I - Sort function to use
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
2002-05-02 14:31:10 +00:00
|
|
|
int i; // Looping var
|
|
|
|
int num_files; // Number of files in directory
|
|
|
|
int num_dirs; // Number of directories in list
|
|
|
|
char filename[4096]; // Current file
|
|
|
|
Fl_File_Icon *icon; // Icon to use
|
2001-08-01 21:24:49 +00:00
|
|
|
|
|
|
|
|
2001-09-29 14:38:59 +00:00
|
|
|
// printf("Fl_File_Browser::load(\"%s\")\n", directory);
|
2001-08-02 16:17:04 +00:00
|
|
|
|
2001-08-01 21:24:49 +00:00
|
|
|
clear();
|
2004-02-26 03:06:41 +00:00
|
|
|
|
2001-08-01 21:24:49 +00:00
|
|
|
directory_ = directory;
|
|
|
|
|
2004-02-26 03:06:41 +00:00
|
|
|
if (!directory)
|
|
|
|
return (0);
|
|
|
|
|
2001-08-01 21:24:49 +00:00
|
|
|
if (directory_[0] == '\0')
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// No directory specified; for UNIX list all mount points. For DOS
|
|
|
|
// list all valid drive letters...
|
|
|
|
//
|
2001-09-29 14:38:59 +00:00
|
|
|
if ((icon = Fl_File_Icon::find("any", Fl_File_Icon::DEVICE)) == NULL)
|
|
|
|
icon = Fl_File_Icon::find("any", Fl_File_Icon::DIRECTORY);
|
2016-10-19 08:40:41 +00:00
|
|
|
num_files = Fl::system_driver()->file_browser_load_filesystem(this, filename, (int)sizeof(filename), icon);
|
2001-08-01 21:24:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dirent **files; // Files in in directory
|
|
|
|
//
|
|
|
|
// Build the file list...
|
|
|
|
//
|
2016-04-10 17:56:53 +00:00
|
|
|
num_files = Fl::system_driver()->file_browser_load_directory(directory_, filename, sizeof(filename), &files, sort);
|
2001-08-01 21:24:49 +00:00
|
|
|
if (num_files <= 0)
|
|
|
|
return (0);
|
|
|
|
|
2005-02-05 18:26:21 +00:00
|
|
|
for (i = 0, num_dirs = 0; i < num_files; i ++) {
|
2005-08-18 14:08:17 +00:00
|
|
|
if (strcmp(files[i]->d_name, "./")) {
|
2001-08-03 18:46:57 +00:00
|
|
|
snprintf(filename, sizeof(filename), "%s/%s", directory_,
|
|
|
|
files[i]->d_name);
|
2001-08-01 21:24:49 +00:00
|
|
|
|
2005-02-05 18:26:21 +00:00
|
|
|
icon = Fl_File_Icon::find(filename);
|
2005-02-06 19:36:10 +00:00
|
|
|
if ((icon && icon->type() == Fl_File_Icon::DIRECTORY) ||
|
2016-04-08 15:48:28 +00:00
|
|
|
Fl::system_driver()->filename_isdir_quick(filename)) {
|
2002-04-29 19:40:51 +00:00
|
|
|
num_dirs ++;
|
2005-02-05 18:26:21 +00:00
|
|
|
insert(num_dirs, files[i]->d_name, icon);
|
|
|
|
} else if (filetype_ == FILES &&
|
|
|
|
fl_filename_match(files[i]->d_name, pattern_)) {
|
|
|
|
add(files[i]->d_name, icon);
|
|
|
|
}
|
2001-08-01 21:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(files[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(files);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (num_files);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 14:38:59 +00:00
|
|
|
// 'Fl_File_Browser::filter()' - Set the filename filter.
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
void
|
2001-09-29 14:38:59 +00:00
|
|
|
Fl_File_Browser::filter(const char *pattern) // I - Pattern string
|
2001-08-01 21:24:49 +00:00
|
|
|
{
|
|
|
|
// If pattern is NULL set the pattern to "*"...
|
|
|
|
if (pattern)
|
|
|
|
pattern_ = pattern;
|
|
|
|
else
|
|
|
|
pattern_ = "*";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2005-02-05 18:26:21 +00:00
|
|
|
// End of "$Id$".
|
2001-08-01 21:24:49 +00:00
|
|
|
//
|