📄 fl_file_browser.cxx
字号:
//
// "$Id: Fl_File_Browser.cxx,v 1.1.1.1 2003/06/03 22:25:42 agno Exp $"
//
// Fl_File_Browser routines.
//
// Copyright 1999-2003 by Michael Sweet.
//
// 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.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
// Contents:
//
// 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.
//
//
// Include necessary header files...
//
#include <FL/Fl_File_Browser.H>
#include <FL/fl_draw.H>
#include <FL/filename.H>
#include <stdio.h>
#include <stdlib.h>
#include "flstring.h"
#ifdef __CYGWIN__
# include <mntent.h>
#elif defined(WIN32)
# include <windows.h>
# include <direct.h>
// Apparently Borland C++ defines DIRECTORY in <direct.h>, which
// interfers with the Fl_File_Icon enumeration of the same name.
# ifdef DIRECTORY
# undef DIRECTORY
# endif // DIRECTORY
#endif // __CYGWIN__
#ifdef __EMX__
# define INCL_DOS
# define INCL_DOSMISC
# include <os2.h>
#endif // __EMX__
// CodeWarrior (__MWERKS__) gets its include paths confused, so we
// temporarily disable this...
#if defined(__APPLE__) && !defined(__MWERKS__)
# include <sys/param.h>
# include <sys/ucred.h>
# include <sys/mount.h>
#endif // __APPLE__ && !__MWERKS__
//
// 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
};
//
// 'Fl_File_Browser::full_height()' - Return the height of the list.
//
int // O - Height in pixels
Fl_File_Browser::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);
}
//
// 'Fl_File_Browser::item_height()' - Return the height of a list item.
//
int // O - Height in pixels
Fl_File_Browser::item_height(void *p) const // I - List item data
{
FL_BLINE *line; // Pointer to line
char *t; // Pointer into text
int height; // Width of line
int textheight; // Height of text
// Figure out the standard text height...
fl_font(textfont(), textsize());
textheight = fl_height();
// We always have at least 1 line...
height = textheight;
// Scan for newlines...
line = (FL_BLINE *)p;
if (line != NULL)
for (t = line->txt; *t != '\0'; t ++)
if (*t == '\n')
height += textheight;
// If we have enabled icons then add space for them...
if (Fl_File_Icon::first() != NULL && height < iconsize_)
height = iconsize_;
// Add space for the selection border..
height += 2;
// Return the height
return (height);
}
//
// 'Fl_File_Browser::item_width()' - Return the width of a list item.
//
int // O - Width in pixels
Fl_File_Browser::item_width(void *p) const // I - List item data
{
int i; // Looping var
FL_BLINE *line; // Pointer to line
char *t, // 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
const int *columns; // Columns
// Set the font and size...
fl_font(textfont(), textsize());
// Scan for newlines...
line = (FL_BLINE *)p;
columns = column_widths();
if (strchr(line->txt, '\n') == NULL &&
strchr(line->txt, column_char()) == NULL)
{
// Do a fast width calculation...
width = (int)fl_width(line->txt);
}
else
{
// More than 1 line or have columns; find the maximum width...
width = 0;
tempwidth = 0;
column = 0;
for (t = line->txt, ptr = fragment; *t != '\0'; t ++)
if (*t == '\n')
{
// Newline - nul terminate this fragment and get the width...
*ptr = '\0';
tempwidth += (int)fl_width(fragment);
// Update the max width as needed...
if (tempwidth > width)
width = tempwidth;
// Point back to the start of the fragment...
ptr = fragment;
tempwidth = 0;
column = 0;
}
else if (*t == column_char())
{
// Advance to the next column...
column ++;
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);
if (tempwidth > width)
width = tempwidth;
ptr = fragment;
}
else
*ptr++ = *t;
if (ptr > fragment)
{
// Nul terminate this fragment and get the width...
*ptr = '\0';
tempwidth += (int)fl_width(fragment);
// Update the max width as needed...
if (tempwidth > width)
width = tempwidth;
}
}
// If we have enabled icons then add space for them...
if (Fl_File_Icon::first() != NULL)
width += iconsize_ + 8;
// Add space for the selection border..
width += 2;
// Return the width
return (width);
}
//
// 'Fl_File_Browser::item_draw()' - Draw a list item.
//
void
Fl_File_Browser::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) const // I - Height of item
{
int i; // Looping var
FL_BLINE *line; // Pointer to line
Fl_Color c; // Text color
char *t, // 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
// Draw the list item text...
line = (FL_BLINE *)p;
if (line->txt[strlen(line->txt) - 1] == '/')
fl_font(textfont() | FL_BOLD, textsize());
else
fl_font(textfont(), textsize());
if (line->flags & SELECTED)
c = fl_contrast(textcolor(), selection_color());
else
c = textcolor();
if (Fl_File_Icon::first() == NULL)
{
// No icons, just draw the text...
X ++;
W -= 2;
}
else
{
// Draw the icon if it is set...
if (line->data)
((Fl_File_Icon *)line->data)->draw(X, Y, iconsize_, iconsize_,
(line->flags & SELECTED) ? FL_YELLOW :
FL_LIGHT2,
active_r());
// Draw the text offset to the right...
X += iconsize_ + 9;
W -= iconsize_ - 10;
// Center the text vertically...
height = fl_height();
for (t = line->txt; *t != '\0'; t ++)
if (*t == '\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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -