2001-08-02 01:24:49 +04:00
|
|
|
//
|
2001-08-03 22:46:57 +04:00
|
|
|
// "$Id: Fl_FileBrowser.cxx,v 1.13.2.2 2001/08/03 18:46:57 easysw Exp $"
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
2001-08-02 20:17:04 +04:00
|
|
|
// Fl_FileBrowser routines.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
2001-08-02 20:17:04 +04:00
|
|
|
// Copyright 1999-2001 by Michael Sweet.
|
2001-08-02 01:24:49 +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.
|
|
|
|
//
|
2001-08-02 20:17:04 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// Contents:
|
|
|
|
//
|
2001-08-02 20:17:04 +04:00
|
|
|
// Fl_FileBrowser::full_height() - Return the height of the list.
|
|
|
|
// Fl_FileBrowser::item_height() - Return the height of a list item.
|
|
|
|
// Fl_FileBrowser::item_width() - Return the width of a list item.
|
|
|
|
// Fl_FileBrowser::item_draw() - Draw a list item.
|
|
|
|
// Fl_FileBrowser::Fl_FileBrowser() - Create a Fl_FileBrowser widget.
|
|
|
|
// Fl_FileBrowser::load() - Load a directory into the browser.
|
|
|
|
// Fl_FileBrowser::filter() - Set the filename filter.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Include necessary header files...
|
|
|
|
//
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
#include <FL/Fl_FileBrowser.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/filename.H>
|
|
|
|
#include <stdio.h>
|
2001-08-02 01:24:49 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
#if defined(WIN32)
|
2001-08-02 01:24:49 +04:00
|
|
|
# include <windows.h>
|
|
|
|
# include <direct.h>
|
2001-08-02 20:17:04 +04:00
|
|
|
#endif /* WIN32 */
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
#if defined(__EMX__)
|
|
|
|
#define INCL_DOS
|
|
|
|
#define INCL_DOSMISC
|
|
|
|
#include <os2.h>
|
|
|
|
#endif /* __EMX__ */
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// FL_BLINE definition from "Fl_Browser.cxx"...
|
|
|
|
//
|
|
|
|
|
|
|
|
#define SELECTED 1
|
|
|
|
#define NOTDISPLAYED 2
|
|
|
|
|
|
|
|
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)
|
|
|
|
short length; // sizeof(txt)-1, may be longer than string
|
|
|
|
char flags; // selected, displayed
|
|
|
|
char txt[1]; // start of allocated array
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
//
|
|
|
|
// 'Fl_FileBrowser::full_height()' - Return the height of the list.
|
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Height in pixels
|
|
|
|
Fl_FileBrowser::full_height() const
|
|
|
|
{
|
|
|
|
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-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// 'Fl_FileBrowser::item_height()' - Return the height of a list item.
|
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Height in pixels
|
|
|
|
Fl_FileBrowser::item_height(void *p) const // I - List item data
|
|
|
|
{
|
|
|
|
FL_BLINE *line; // Pointer to line
|
|
|
|
char *text; // Pointer into text
|
|
|
|
int height; // Width of line
|
|
|
|
int textheight; // Height of text
|
|
|
|
|
|
|
|
|
|
|
|
// Figure out the standard text height...
|
2001-08-02 20:17:04 +04:00
|
|
|
fl_font(textfont(), textsize());
|
|
|
|
textheight = fl_height();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
// We always have at least 1 line...
|
|
|
|
height = textheight;
|
|
|
|
|
|
|
|
// Scan for newlines...
|
|
|
|
line = (FL_BLINE *)p;
|
|
|
|
|
|
|
|
if (line != NULL)
|
|
|
|
for (text = line->txt; *text != '\0'; text ++)
|
|
|
|
if (*text == '\n')
|
|
|
|
height += textheight;
|
|
|
|
|
|
|
|
// If we have enabled icons then add space for them...
|
|
|
|
if (Fl_FileIcon::first() != NULL && height < iconsize_)
|
|
|
|
height = iconsize_;
|
|
|
|
|
|
|
|
// Add space for the selection border..
|
|
|
|
height += 2;
|
|
|
|
|
|
|
|
// Return the height
|
|
|
|
return (height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 'Fl_FileBrowser::item_width()' - Return the width of a list item.
|
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Width in pixels
|
|
|
|
Fl_FileBrowser::item_width(void *p) const // I - List item data
|
|
|
|
{
|
2001-08-02 20:17:04 +04:00
|
|
|
int i; // Looping var
|
2001-08-02 01:24:49 +04:00
|
|
|
FL_BLINE *line; // Pointer to line
|
|
|
|
char *text, // Pointer into text
|
|
|
|
*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 20:17:04 +04:00
|
|
|
const int *columns; // Columns
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
|
|
|
|
// Set the font and size...
|
2001-08-02 20:17:04 +04:00
|
|
|
fl_font(textfont(), textsize());
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
// Scan for newlines...
|
2001-08-02 20:17:04 +04:00
|
|
|
line = (FL_BLINE *)p;
|
|
|
|
columns = column_widths();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
if (strchr(line->txt, '\n') == NULL &&
|
2001-08-02 20:17:04 +04:00
|
|
|
strchr(line->txt, column_char()) == NULL)
|
2001-08-02 01:24:49 +04:00
|
|
|
{
|
|
|
|
// Do a fast width calculation...
|
2001-08-02 20:17:04 +04:00
|
|
|
width = (int)fl_width(line->txt);
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// More than 1 line or have columns; find the maximum width...
|
|
|
|
width = 0;
|
|
|
|
tempwidth = 0;
|
|
|
|
column = 0;
|
|
|
|
|
|
|
|
for (text = line->txt, ptr = fragment; *text != '\0'; text ++)
|
|
|
|
if (*text == '\n')
|
|
|
|
{
|
|
|
|
// Newline - nul terminate this fragment and get the width...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
tempwidth += (int)fl_width(fragment);
|
2001-08-02 01:24:49 +04: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 20:17:04 +04:00
|
|
|
column = 0;
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
2001-08-02 20:17:04 +04:00
|
|
|
else if (*text == column_char())
|
2001-08-02 01:24:49 +04:00
|
|
|
{
|
|
|
|
// Advance to the next column...
|
|
|
|
column ++;
|
2001-08-02 20:17:04 +04: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-02 01:24:49 +04:00
|
|
|
|
|
|
|
if (tempwidth > width)
|
|
|
|
width = tempwidth;
|
|
|
|
|
|
|
|
ptr = fragment;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ptr++ = *text;
|
|
|
|
|
|
|
|
if (ptr > fragment)
|
|
|
|
{
|
|
|
|
// Nul terminate this fragment and get the width...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
tempwidth += (int)fl_width(fragment);
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
// Update the max width as needed...
|
|
|
|
if (tempwidth > width)
|
|
|
|
width = tempwidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have enabled icons then add space for them...
|
|
|
|
if (Fl_FileIcon::first() != NULL)
|
|
|
|
width += iconsize_ + 8;
|
|
|
|
|
|
|
|
// Add space for the selection border..
|
|
|
|
width += 2;
|
|
|
|
|
|
|
|
// Return the width
|
|
|
|
return (width);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 'Fl_FileBrowser::item_draw()' - Draw a list item.
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
2001-08-03 22:46:57 +04:00
|
|
|
Fl_FileBrowser::item_draw(void *p, // I - List item data
|
|
|
|
int x, // I - Upper-lefthand X coordinate
|
|
|
|
int y, // I - Upper-lefthand Y coordinate
|
|
|
|
int w, // I - Width of item
|
|
|
|
int h) const // I - Height of item
|
2001-08-02 01:24:49 +04:00
|
|
|
{
|
2001-08-02 20:17:04 +04:00
|
|
|
int i; // Looping var
|
2001-08-02 01:24:49 +04:00
|
|
|
FL_BLINE *line; // Pointer to line
|
2001-08-02 20:17:04 +04:00
|
|
|
Fl_Color c; // Text color
|
|
|
|
char *text, // Pointer into text
|
|
|
|
*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-02 01:24:49 +04:00
|
|
|
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
(void)h;
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
// Draw the list item text...
|
|
|
|
line = (FL_BLINE *)p;
|
|
|
|
|
2001-08-03 22:46:57 +04:00
|
|
|
if (line->txt[strlen(line->txt) - 1] == '/')
|
|
|
|
fl_font(textfont() | FL_BOLD, textsize());
|
|
|
|
else
|
|
|
|
fl_font(textfont(), textsize());
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
if (line->flags & SELECTED)
|
|
|
|
c = contrast(textcolor(), selection_color());
|
2001-08-02 01:24:49 +04:00
|
|
|
else
|
2001-08-02 20:17:04 +04:00
|
|
|
c = textcolor();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
if (Fl_FileIcon::first() == NULL)
|
|
|
|
{
|
|
|
|
// No icons, just draw the text...
|
2001-08-02 20:17:04 +04:00
|
|
|
x ++;
|
|
|
|
w -= 2;
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-02 20:17:04 +04:00
|
|
|
// Draw the icon if it is set...
|
2001-08-02 01:24:49 +04:00
|
|
|
if (line->data)
|
|
|
|
((Fl_FileIcon *)line->data)->draw(x, y, iconsize_, iconsize_,
|
2001-08-03 22:46:57 +04:00
|
|
|
(line->flags & SELECTED) ? FL_YELLOW :
|
|
|
|
FL_LIGHT2,
|
|
|
|
active_r());
|
2001-08-02 20:17:04 +04:00
|
|
|
|
|
|
|
// Draw the text offset to the right...
|
|
|
|
x += iconsize_ + 9;
|
|
|
|
w -= iconsize_ - 10;
|
|
|
|
|
|
|
|
// Center the text vertically...
|
|
|
|
height = fl_height();
|
|
|
|
|
|
|
|
for (text = line->txt; *text != '\0'; text ++)
|
|
|
|
if (*text == '\n')
|
|
|
|
height += fl_height();
|
|
|
|
|
|
|
|
if (height < iconsize_)
|
|
|
|
y += (iconsize_ - height) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the text...
|
|
|
|
line = (FL_BLINE *)p;
|
|
|
|
columns = column_widths();
|
|
|
|
width = 0;
|
|
|
|
column = 0;
|
|
|
|
|
|
|
|
if (active_r())
|
|
|
|
fl_color(c);
|
|
|
|
else
|
|
|
|
fl_color(inactive(c));
|
|
|
|
|
|
|
|
for (text = line->txt, ptr = fragment; *text != '\0'; text ++)
|
|
|
|
if (*text == '\n')
|
|
|
|
{
|
|
|
|
// Newline - nul terminate this fragment and draw it...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
|
|
|
fl_draw(fragment, x + width, y, w - width, fl_height(),
|
|
|
|
(Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP));
|
|
|
|
|
|
|
|
// Point back to the start of the fragment...
|
|
|
|
ptr = fragment;
|
|
|
|
width = 0;
|
|
|
|
y += fl_height();
|
|
|
|
column = 0;
|
|
|
|
}
|
|
|
|
else if (*text == column_char())
|
|
|
|
{
|
|
|
|
// Tab - nul terminate this fragment and draw it...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
|
|
|
fl_draw(fragment, x + width, y, w - width, fl_height(),
|
|
|
|
(Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP));
|
|
|
|
|
|
|
|
// Advance to the next column...
|
|
|
|
column ++;
|
|
|
|
if (columns)
|
|
|
|
{
|
|
|
|
for (i = 0, width = 0; i < column && columns[i]; i ++)
|
|
|
|
width += columns[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
width = column * (int)(fl_height() * 0.6 * 8.0);
|
|
|
|
|
|
|
|
ptr = fragment;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ptr++ = *text;
|
|
|
|
|
|
|
|
if (ptr > fragment)
|
|
|
|
{
|
|
|
|
// Nul terminate this fragment and draw it...
|
|
|
|
*ptr = '\0';
|
|
|
|
|
|
|
|
fl_draw(fragment, x + width, y, w - width, fl_height(),
|
|
|
|
(Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP));
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 'Fl_FileBrowser::Fl_FileBrowser()' - Create a Fl_FileBrowser widget.
|
|
|
|
//
|
|
|
|
|
|
|
|
Fl_FileBrowser::Fl_FileBrowser(int x, // I - Upper-lefthand X coordinate
|
2001-08-02 20:17:04 +04:00
|
|
|
int y, // I - Upper-lefthand Y coordinate
|
|
|
|
int w, // I - Width in pixels
|
|
|
|
int h, // I - Height in pixels
|
|
|
|
const char *l) // I - Label text
|
2001-08-02 01:24:49 +04:00
|
|
|
: Fl_Browser(x, y, w, h, l)
|
|
|
|
{
|
|
|
|
// Initialize the filter pattern, current directory, and icon size...
|
|
|
|
pattern_ = "*";
|
|
|
|
directory_ = "";
|
2001-08-02 20:17:04 +04:00
|
|
|
iconsize_ = 3 * textsize() / 2;
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 'Fl_FileBrowser::load()' - Load a directory into the browser.
|
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Number of files loaded
|
|
|
|
Fl_FileBrowser::load(const char *directory)// I - Directory to load
|
|
|
|
{
|
|
|
|
int i; // Looping var
|
|
|
|
int num_files; // Number of files in directory
|
2001-08-03 22:46:57 +04:00
|
|
|
int num_dirs; // Number of directories in list
|
2001-08-02 01:24:49 +04:00
|
|
|
char filename[4096]; // Current file
|
|
|
|
Fl_FileIcon *icon; // Icon to use
|
|
|
|
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
// printf("Fl_FileBrowser::load(\"%s\")\n", directory);
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
clear();
|
|
|
|
directory_ = directory;
|
|
|
|
|
|
|
|
if (directory_[0] == '\0')
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// No directory specified; for UNIX list all mount points. For DOS
|
|
|
|
// list all valid drive letters...
|
|
|
|
//
|
|
|
|
|
|
|
|
num_files = 0;
|
2001-08-02 20:17:04 +04:00
|
|
|
if ((icon = Fl_FileIcon::find("any", Fl_FileIcon::DEVICE)) == NULL)
|
|
|
|
icon = Fl_FileIcon::find("any", Fl_FileIcon::DIRECTORY);
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
#if defined(WIN32)
|
2001-08-02 01:24:49 +04:00
|
|
|
DWORD drives; // Drive available bits
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
drives = GetLogicalDrives();
|
|
|
|
for (i = 'A'; i <= 'Z'; i ++, drives >>= 1)
|
|
|
|
if (drives & 1)
|
|
|
|
{
|
2001-08-03 22:46:57 +04:00
|
|
|
sprintf(filename, "%c:/", i);
|
2001-08-02 20:17:04 +04:00
|
|
|
|
|
|
|
if (i < 'C')
|
|
|
|
add(filename, icon);
|
|
|
|
else
|
|
|
|
add(filename, icon);
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
num_files ++;
|
|
|
|
}
|
|
|
|
#elif defined(__EMX__)
|
|
|
|
ULONG curdrive; // Current drive
|
|
|
|
ULONG drives; // Drive available bits
|
|
|
|
int start = 3; // 'C' (MRS - dunno if this is correct!)
|
|
|
|
|
|
|
|
|
|
|
|
DosQueryCurrentDisk(&curdrive, &drives);
|
|
|
|
drives >>= start - 1;
|
|
|
|
for (i = 'A'; i <= 'Z'; i ++, drives >>= 1)
|
|
|
|
if (drives & 1)
|
|
|
|
{
|
2001-08-03 22:46:57 +04:00
|
|
|
sprintf(filename, "%c:/", i);
|
2001-08-02 01:24:49 +04:00
|
|
|
add(filename, icon);
|
|
|
|
|
|
|
|
num_files ++;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
FILE *mtab; // /etc/mtab or /etc/mnttab file
|
|
|
|
char line[1024]; // Input line
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// Open the file that contains a list of mounted filesystems...
|
|
|
|
//
|
2001-08-02 20:17:04 +04:00
|
|
|
# if defined(hpux) || defined(__sun)
|
2001-08-02 01:24:49 +04:00
|
|
|
mtab = fopen("/etc/mnttab", "r"); // Fairly standard
|
|
|
|
# elif defined(__sgi) || defined(linux)
|
|
|
|
mtab = fopen("/etc/mtab", "r"); // More standard
|
|
|
|
# else
|
|
|
|
mtab = fopen("/etc/fstab", "r"); // Otherwise fallback to full list
|
|
|
|
if (mtab == NULL)
|
|
|
|
mtab = fopen("/etc/vfstab", "r");
|
|
|
|
# endif
|
|
|
|
|
|
|
|
if (mtab != NULL)
|
|
|
|
{
|
|
|
|
while (fgets(line, sizeof(line), mtab) != NULL)
|
|
|
|
{
|
|
|
|
if (line[0] == '#' || line[0] == '\n')
|
|
|
|
continue;
|
|
|
|
if (sscanf(line, "%*s%4095s", filename) != 1)
|
|
|
|
continue;
|
|
|
|
|
2001-08-03 22:46:57 +04:00
|
|
|
strncat(filename, "/", sizeof(filename) - 1);
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
// printf("Fl_FileBrowser::load() - adding \"%s\" to list...\n", filename);
|
2001-08-02 01:24:49 +04:00
|
|
|
add(filename, icon);
|
|
|
|
num_files ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(mtab);
|
|
|
|
}
|
2001-08-02 20:17:04 +04:00
|
|
|
#endif // WIN32 || __EMX__
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dirent **files; // Files in in directory
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Build the file list...
|
|
|
|
//
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
#if defined(WIN32) || defined(__EMX__)
|
2001-08-02 01:24:49 +04:00
|
|
|
strncpy(filename, directory_, sizeof(filename) - 1);
|
|
|
|
filename[sizeof(filename) - 1] = '\0';
|
|
|
|
i = strlen(filename) - 1;
|
|
|
|
|
|
|
|
if (i == 2 && filename[1] == ':' &&
|
|
|
|
(filename[2] == '/' || filename[2] == '\\'))
|
|
|
|
filename[2] = '/';
|
|
|
|
else if (filename[i] != '/' && filename[i] != '\\')
|
|
|
|
strcat(filename, "/");
|
|
|
|
|
|
|
|
num_files = filename_list(filename, &files);
|
|
|
|
#else
|
|
|
|
num_files = filename_list(directory_, &files);
|
2001-08-02 20:17:04 +04:00
|
|
|
#endif /* WIN32 || __EMX__ */
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
if (num_files <= 0)
|
|
|
|
return (0);
|
|
|
|
|
2001-08-03 22:46:57 +04:00
|
|
|
for (i = 0, num_dirs = 0; i < num_files; i ++)
|
2001-08-02 01:24:49 +04:00
|
|
|
{
|
|
|
|
if (strcmp(files[i]->d_name, ".") != 0 &&
|
|
|
|
strcmp(files[i]->d_name, "..") != 0)
|
|
|
|
{
|
2001-08-03 22:46:57 +04:00
|
|
|
snprintf(filename, sizeof(filename), "%s/%s", directory_,
|
|
|
|
files[i]->d_name);
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2001-08-03 22:46:57 +04:00
|
|
|
if (filename_isdir(filename))
|
|
|
|
{
|
|
|
|
char name[1024]; // Temporary directory name
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "%s/", files[i]->d_name);
|
|
|
|
|
|
|
|
num_dirs ++;
|
|
|
|
insert(num_dirs, name, Fl_FileIcon::find(filename));
|
|
|
|
}
|
|
|
|
else if (filename_match(files[i]->d_name, pattern_))
|
2001-08-02 01:24:49 +04:00
|
|
|
add(files[i]->d_name, Fl_FileIcon::find(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
free(files[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(files);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (num_files);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 'Fl_FileBrowser::filter()' - Set the filename filter.
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
Fl_FileBrowser::filter(const char *pattern) // I - Pattern string
|
|
|
|
{
|
|
|
|
// If pattern is NULL set the pattern to "*"...
|
|
|
|
if (pattern)
|
|
|
|
pattern_ = pattern;
|
|
|
|
else
|
|
|
|
pattern_ = "*";
|
|
|
|
|
|
|
|
// Reload the current directory...
|
|
|
|
load(directory_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-08-03 22:46:57 +04:00
|
|
|
// End of "$Id: Fl_FileBrowser.cxx,v 1.13.2.2 2001/08/03 18:46:57 easysw Exp $".
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|