2001-08-02 01:24:49 +04:00
|
|
|
//
|
2001-11-25 19:38:11 +03:00
|
|
|
// "$Id: Fl_File_Browser.cxx,v 1.1.2.5 2001/11/25 16:38:11 easysw Exp $"
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// Fl_File_Browser 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-09-29 18:38:59 +04: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.
|
|
|
|
// Fl_File_Browser::Fl_File_Browser() - Create a Fl_File_Browser widget.
|
|
|
|
// Fl_File_Browser::load() - Load a directory into the browser.
|
|
|
|
// Fl_File_Browser::filter() - Set the filename filter.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Include necessary header files...
|
|
|
|
//
|
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
#include <FL/Fl_File_Browser.H>
|
2001-08-02 20:17:04 +04:00
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/filename.H>
|
|
|
|
#include <stdio.h>
|
2001-08-02 01:24:49 +04:00
|
|
|
#include <stdlib.h>
|
2001-11-25 19:38:11 +03:00
|
|
|
#include "flstring.h"
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2001-10-30 00:59:15 +03:00
|
|
|
#if defined(WIN32) && ! defined(__CYGWIN__)
|
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
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// 'Fl_File_Browser::full_height()' - Return the height of the list.
|
2001-08-02 20:17:04 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Height in pixels
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_File_Browser::full_height() const
|
2001-08-02 20:17:04 +04: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-02 01:24:49 +04:00
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// 'Fl_File_Browser::item_height()' - Return the height of a list item.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Height in pixels
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_File_Browser::item_height(void *p) const // I - List item data
|
2001-08-02 01:24:49 +04:00
|
|
|
{
|
|
|
|
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...
|
2001-09-29 18:38:59 +04:00
|
|
|
if (Fl_File_Icon::first() != NULL && height < iconsize_)
|
2001-08-02 01:24:49 +04:00
|
|
|
height = iconsize_;
|
|
|
|
|
|
|
|
// Add space for the selection border..
|
|
|
|
height += 2;
|
|
|
|
|
|
|
|
// Return the height
|
|
|
|
return (height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// 'Fl_File_Browser::item_width()' - Return the width of a list item.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
int // O - Width in pixels
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_File_Browser::item_width(void *p) const // I - List item data
|
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
|
|
|
|
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...
|
2001-09-29 18:38:59 +04:00
|
|
|
if (Fl_File_Icon::first() != NULL)
|
2001-08-02 01:24:49 +04:00
|
|
|
width += iconsize_ + 8;
|
|
|
|
|
|
|
|
// Add space for the selection border..
|
|
|
|
width += 2;
|
|
|
|
|
|
|
|
// Return the width
|
|
|
|
return (width);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// 'Fl_File_Browser::item_draw()' - Draw a list item.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
void
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_File_Browser::item_draw(void *p, // I - List item data
|
2001-08-03 22:46:57 +04:00
|
|
|
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)
|
2001-10-29 06:44:33 +03:00
|
|
|
c = fl_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
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
if (Fl_File_Icon::first() == NULL)
|
2001-08-02 01:24:49 +04:00
|
|
|
{
|
|
|
|
// 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)
|
2001-09-29 18:38:59 +04:00
|
|
|
((Fl_File_Icon *)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
|
2001-10-29 06:44:33 +03:00
|
|
|
fl_color(fl_inactive(c));
|
2001-08-02 20:17:04 +04:00
|
|
|
|
|
|
|
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(),
|
2001-11-03 08:11:34 +03:00
|
|
|
(Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP), 0, 0);
|
2001-08-02 20:17:04 +04:00
|
|
|
|
|
|
|
// 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(),
|
2001-11-03 08:11:34 +03:00
|
|
|
(Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP), 0, 0);
|
2001-08-02 20:17:04 +04:00
|
|
|
|
|
|
|
// 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(),
|
2001-11-03 08:11:34 +03:00
|
|
|
(Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP), 0, 0);
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// 'Fl_File_Browser::Fl_File_Browser()' - Create a Fl_File_Browser widget.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_File_Browser::Fl_File_Browser(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-09-04 17:13:29 +04:00
|
|
|
filetype_ = FILES;
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// 'Fl_File_Browser::load()' - Load a directory into the browser.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
2001-09-04 17:13:29 +04:00
|
|
|
int // O - Number of files loaded
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_File_Browser::load(const char *directory)// I - Directory to load
|
2001-08-02 01:24:49 +04:00
|
|
|
{
|
|
|
|
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
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_File_Icon *icon; // Icon to use
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
// printf("Fl_File_Browser::load(\"%s\")\n", directory);
|
2001-08-02 20:17:04 +04:00
|
|
|
|
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-09-29 18:38:59 +04:00
|
|
|
if ((icon = Fl_File_Icon::find("any", Fl_File_Icon::DEVICE)) == NULL)
|
|
|
|
icon = Fl_File_Icon::find("any", Fl_File_Icon::DIRECTORY);
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2001-10-30 00:59:15 +03:00
|
|
|
#if defined(WIN32) && ! defined (__CYGWIN__)
|
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-09-29 18:38:59 +04:00
|
|
|
// printf("Fl_File_Browser::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-10-30 00:59:15 +03:00
|
|
|
#if (defined(WIN32) && ! defined(__CYGWIN__)) || 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 ++;
|
2001-09-29 18:38:59 +04:00
|
|
|
insert(num_dirs, name, Fl_File_Icon::find(filename));
|
2001-08-03 22:46:57 +04:00
|
|
|
}
|
2001-09-04 17:13:29 +04:00
|
|
|
else if (filetype_ == FILES &&
|
|
|
|
filename_match(files[i]->d_name, pattern_))
|
2001-09-29 18:38:59 +04:00
|
|
|
add(files[i]->d_name, Fl_File_Icon::find(filename));
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(files[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(files);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (num_files);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// 'Fl_File_Browser::filter()' - Set the filename filter.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
void
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_File_Browser::filter(const char *pattern) // I - Pattern string
|
2001-08-02 01:24:49 +04:00
|
|
|
{
|
|
|
|
// If pattern is NULL set the pattern to "*"...
|
|
|
|
if (pattern)
|
|
|
|
pattern_ = pattern;
|
|
|
|
else
|
|
|
|
pattern_ = "*";
|
|
|
|
|
|
|
|
// Reload the current directory...
|
|
|
|
load(directory_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-11-25 19:38:11 +03:00
|
|
|
// End of "$Id: Fl_File_Browser.cxx,v 1.1.2.5 2001/11/25 16:38:11 easysw Exp $".
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|