Skip to content
Snippets Groups Projects
Commit 4b0100aa authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

remove obsolete NativeFileChooser contrib

parent 61dd3030
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 2993 deletions
# WARNING: Makefile automatically derives version number from the first line
# of this file that starts with x.x
# |
# \|/
# v
0.84
-----------------------------------------------------
o FLTK2 SUPPORT!
Merged in Frederic Hoerni's mods for fltk2 support,
converted to fltk2 style namespace.
o Makefile fix for IMGLIB from Gonzalo Garramuno (fltk.general 09/30/07)
o Incorporated Ian MacArthur's Makefile for fltk-config
o 80 column compliance
o Build:
> Tar file now extracts with version number in the directory name,
> 'make tar' logic now moved into separate shell script
o Windows:
> Fixed memory leak with lpstrFile (alloc'ed twice)
> Removed unused strfree() code in ClearOFN()
> Small code formatting fixes
0.83d
-----------------------------------------------------
o Linux:
> Added Shane Hill's #include <sys/stat.h> to Fl_Native_File_Chooser_FLTK.cxx
o Windows:
> Added OFN_NOCHANGEDIR flag to prevent GetOpenFileName() from changing the CWD
> Added Andreas Sch?mann's fix for _nfilters++ to the add_filter() method
> Fixed showfile() GetCurrentDirectory() call
o Copyright fixes and README.txt brought up to date
0.83c -- 02/03/2006 fix release
-----------------------------------------------------
o Windows:
> Fixed behavior of BROWSE_SAVE_FILE
> Fixed SAVEAS_CONFIRM
> Mods to getcwd() macros in test-browser.cxx for MINGW
> Fixes to test-browser.cxx for MinGW compiles (removed #ifdef VISUAL_STUDIO)
o Linux:
> "Save File" now has working "Show SaveAs Confirm" dialog
> "Save File" under linux wasn't letting user type in a filename
> 'int type()' method wasn't implemented, added _btype
> Removed ifeq() cruft from Makefile.LINUX
o Applied Ian's fixes to Makefile.fltkconfig
o Makefile was sourcing user's ~/.cshrc, added '-f' to SHELL=/bin/csh -f
0.83b -- 01/07/2006 erco: small patches from Ian
------------------------------------------------
o Makefile.fltkconfig WINDOWS -> WIN32
o Tar forces owner/group to 0/0, fixed perms on images dir
0.83a -- 01/06/2006 erco: small patches from Ian
------------------------------------------------
o Makefile.fltkconfig patch
o Enforce correct perms on files in tar file
0.83 -- 12/06/2005 erco: misc
-----------------------------------------------
o Windows: Added preset_file() support
o Linux: missing filters() method
o All: Added options() to API, removed macosx_*()
o Added options() to the API with flags:
o NEW_FOLDER
o PREVIEW
o SAVEAS_CONFIRM
o Removed macosx_*() stuff -- bad idea
0.82 -- 12/05/2005 erco: misc fixes after merge
-----------------------------------------------
o win32 filter fixes for Alessandro's 11/29 report
o Rellocated Macos reference links from code to REFERENCE-MAC.txt
o Made sure all #ifdefs use _WIN32 instead of other variants.
o Fixed problem with FLTK chooser not showing its icons (natevw)
o Added macosx_*() platform specific accessors
TODO: See ./TODO for outstanding items
0.81 -- 11/28/2005 erco: linux version cleanup
----------------------------------------------
o Support documented filters
o free/strdup -> new/delete
o added #ifndef at top of FL/Fl_Native_File_Chooser.H to prevent recursion
0.80 -- 11/27/2005 erco+nate: code merge, cleanup
-------------------------------------------------
o Merge in Nathan's changes
o Updated docs for all changes noted here
o Rewrote mac's filter code to support old "*.a" and new "Desc1\t*.a\nDesc2\t*.b" syntax
o Changed Nathan's set_filter() -> filter_value() (consistent with FLTK's own chooser)
o Renamed test program to test-browser.cxx
o Code cleanup: variable + method naming, 80 column conformance, indents, strdup/malloc -> new
TODO: Linux version needs code cleanup (strdup -> new, etc)
0.70 -- 08/04/05 erco: general cleanup
--------------------------------------
o Implemented Linux.
This was easy -- just use Fl_File_Chooser.
o Removed references to non-existant size() method from docs;
the correct method name is total_filenames()
0.62 -- 02/02/2005
------------------
o Added Ian's mods to main.cxx to use getcwd() instead of fixed path
o Added #include/#define's to support getcwd() under Windows VS
0.61 -- 01/26/2005
------------------
o Applied Ian MacArthur's 01/26/2005 fixes,
and Makefile.fltkconfig, including tab fixes and line 90 .obj -> .o fix.
o Enabled /Wall on Windows VS7.x, and fixed all problems related to Fl_Native*
(mainly, ctor type value was being ignored)
# Gmsh - Copyright (C) 1997-2012 C. Geuzaine, J.-F. Remacle
#
# See the LICENSE.txt file for license information. Please report all
# bugs and problems to <gmsh@geuz.org>.
set(SRC
Fl_Native_File_Chooser.cxx
)
file(GLOB_RECURSE HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.H)
append_gmsh_src(contrib/NativeFileChooser "${SRC};${HDR}")
Greg Ercolano -- initial version for mac + win32, code maintainer
Ian MacArthur -- various fixes, additions, Makefile.fltkconfig
Nathan Vander Wilt -- filter code for WIN32 and Mac, FLTK chooser
Boris Mayer -- various debugging
Frederic Hoerni -- fltk2 port
//
// Fl_Native_File_Chooser.H -- FLTK native OS file chooser widget
//
// Copyright 2004 by Greg Ercolano.
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// USA.
//
#ifndef FL_NATIVE_FILE_CHOOSER_H
#define FL_NATIVE_FILE_CHOOSER_H
// Use Windows' chooser
#ifdef _WIN32
#include <FL/Fl_Native_File_Chooser_WIN32.H>
#endif
// Use Apple's chooser
#ifdef __APPLE__
#include <FL/Fl_Native_File_Chooser_MAC.H>
#endif
// All else falls back to FLTK's own chooser
#if ! defined(__APPLE__) && !defined(_WIN32)
#include <FL/Fl_Native_File_Chooser_FLTK.H>
#endif
#endif /*FL_NATIVE_FILE_CHOOSER_H*/
//
// Fl_Native_File_Chooser_DEFAULT.H -- FLTK native OS file chooser widget
//
// Copyright 2005 by Nathan Vander Wilt.
// March 2005 - wrapper around Fl_File_Chooser
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// USA.
//
#include <FL/Fl_File_Chooser.H>
#include <string.h>
class Fl_Native_File_Chooser {
public:
enum Type {
BROWSE_FILE = 0,
BROWSE_DIRECTORY,
BROWSE_MULTI_FILE,
BROWSE_MULTI_DIRECTORY,
BROWSE_SAVE_FILE,
BROWSE_SAVE_DIRECTORY
};
enum Option {
NO_OPTIONS = 0x0000, // no options enabled
SAVEAS_CONFIRM = 0x0001, // Show native 'Save As' overwrite
// confirm dialog (if supported)
NEW_FOLDER = 0x0002, // Show 'New Folder' icon
// (if supported)
PREVIEW = 0x0004 // enable preview mode
};
private:
int _btype; // kind-of browser to show()
int _options; // general options
char *_filter; // user supplied filter
char *_parsedfilt; // parsed filter
int _filtvalue; // selected filter
char *_preset_file;
char *_prevvalue; // Returned filename
char *_directory;
char *_errmsg; // error message
Fl_File_Chooser *file_chooser;
int exist_dialog() {
return(fl_choice("File exists. Are you sure you want to overwrite?",
"Cancel", " OK ", NULL));
}
void load_system_icons() {
Fl_File_Icon::load_system_icons();
}
int _nfilters;
// Private methods
void errmsg(const char *msg);
int type_fl_file(int);
void parse_filter();
void keeplocation();
public:
Fl_Native_File_Chooser(int val=BROWSE_FILE);
~Fl_Native_File_Chooser();
// Public methods
void type(int);
int type() const;
void options(int);
int options() const;
int count() const;
const char *filename() const;
const char *filename(int i) const;
void directory(const char *val);
const char *directory() const;
void title(const char *);
const char* title() const;
const char *filter() const;
void filter(const char *);
int filters() const { return(_nfilters); }
void filter_value(int i);
int filter_value() const;
void preset_file(const char*);
const char* preset_file() const;
const char *errmsg() const;
int show();
};
//
// Fl_Native_File_Chooser_MAC.H -- FLTK native OS file chooser widget
//
// Copyright 2004 by Greg Ercolano.
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// USA.
//
// 10 20 30 40 50 60 70
// | | | | | | |
// 4567890123456789012345678901234567890123456789012345678901234567890123456789
// OSX-SPECIFIC NATIVE BROWSER
#ifdef __APPLE_CC__
#include <Carbon/Carbon.h>
#else
#include <Carbon.h>
#endif
#include <FL/filename.H>
#define MAXFILTERS 80
class Fl_Native_File_Chooser {
public:
enum Type {
BROWSE_FILE = 0,
BROWSE_DIRECTORY,
BROWSE_MULTI_FILE,
BROWSE_MULTI_DIRECTORY,
BROWSE_SAVE_FILE,
BROWSE_SAVE_DIRECTORY
};
enum Option {
NO_OPTIONS = 0x0000, // no options enabled
SAVEAS_CONFIRM = 0x0001, // Show native 'Save As' overwrite
// confirm dialog (if supported)
NEW_FOLDER = 0x0002, // Show 'New Folder' icon
// (if supported)
PREVIEW = 0x0004, // enable preview mode
};
protected:
NavDialogCreationOptions _opts; // file navigation options
private:
int _btype; // kind-of browser to show()
int _options; // general options
NavDialogRef _ref; // file navigation reference
NavActionState _keepstate; // holds button permissions
NavMenuItemSpec _tempitem; // Popup menu selection
char **_pathnames; // array of pathnames
int _tpathnames; // total pathnames
char *_directory; // default pathname to use
char *_title; // title for window
char *_preset_file; // the 'save as' filename
char *_filter; // user-side search filter, eg:
// C Files\t*.[ch]\nText Files\t*.txt"
char *_filt_names; // filter names (tab delimited)
// eg. "C Files\tText Files"
char *_filt_patt[MAXFILTERS];
// array of filter patterns, eg:
// _filt_patt[0]="*.{cxx,h}"
// _filt_patt[1]="*.txt"
int _filt_total; // parse_filter() # of filters loaded
int _filt_value; // index of the selected filter
char *_errmsg; // error message
// PRIVATE CLASS TO HANDLE NAVIGATION DIALOG REPLY STRUCT
// Class-ified, mainly to ensure proper cleanup.
//
class NavReply {
int _valid_reply;
NavReplyRecord _reply;
public:
NavReply();
~NavReply();
int get_reply(NavDialogRef& ref);
int get_saveas_basename(char *s, int slen);
int get_dirname(char *s, int slen);
int get_pathnames(char **&pathnames, int& tpathnames);
};
// Private methods
void errmsg(const char *msg);
void clear_pathnames();
void set_single_pathname(const char *s);
int get_saveas_basename(NavDialogRef& ref);
int get_pathnames(NavDialogRef& ref);
static void event_handler(NavEventCallbackMessage callBackSelector,
NavCBRecPtr cbparm, void *data);
void clear_filters();
void add_filter(const char *, const char *);
void parse_filter(const char *from);
static Boolean filter_proc_cb(AEDesc *, void *, void *, NavFilterModes);
Boolean filter_proc_cb2(AEDesc*, void*, void*, NavFilterModes);
int post();
public:
Fl_Native_File_Chooser(int val = BROWSE_FILE);
~Fl_Native_File_Chooser();
// Public methods
void type(int);
int type() const;
void options(int);
int options() const;
int count() const;
const char *filename() const;
const char *filename(int i) const;
void directory(const char *);
const char *directory() const;
void title(const char *);
const char *title() const;
const char *filter() const;
void filter(const char *);
void filter_value(int i) { _filt_value = i; }
int filter_value() { return(_filt_value); }
int filters() { return(_filt_total); }
void preset_file(const char *);
const char *preset_file();
const char *errmsg() const;
int show();
};
//
// Fl_Native_File_Chooser_WINDOWS.H -- FLTK native OS file chooser widget
//
// Copyright 2004 by Greg Ercolano.
// April 2005 - API changes, improved filter processing by Nathan Vander Wilt
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// USA.
//
// #define _WIN32_WINNT 0x0501 // needed for OPENFILENAME's 'FlagsEx'
#include <stdio.h>
#include <stdlib.h> // malloc
#include <windows.h>
#include <commdlg.h> // OPENFILENAME, GetOpenFileName()
#include <shlobj.h> // BROWSEINFO, SHBrowseForFolder()
class Fl_Native_File_Chooser {
public:
enum Type {
BROWSE_FILE = 0,
BROWSE_DIRECTORY,
BROWSE_MULTI_FILE,
BROWSE_MULTI_DIRECTORY,
BROWSE_SAVE_FILE,
BROWSE_SAVE_DIRECTORY
};
enum Option {
NO_OPTIONS = 0x0000, // no options enabled
SAVEAS_CONFIRM = 0x0001, // Show native 'Save As' overwrite
// confirm dialog (if supported)
NEW_FOLDER = 0x0002, // Show 'New Folder' icon
// (if supported)
PREVIEW = 0x0004, // enable preview mode
};
private:
int _btype; // kind-of browser to show()
int _options; // general options
OPENFILENAME _ofn; // GetOpenFileName() & GetSaveFileName() struct
BROWSEINFO _binf; // SHBrowseForFolder() struct
char **_pathnames; // array of pathnames
int _tpathnames; // total pathnames
char *_directory; // default pathname to use
char *_title; // title for window
char *_filter; // user-side search filter
char *_parsedfilt; // filter parsed for Windows dialog
int _nfilters; // number of filters parse_filter counted
char *_preset_file; // the file to preselect
char *_errmsg; // error message
// Private methods
void errmsg(const char *msg);
void clear_pathnames();
void set_single_pathname(const char *s);
void add_pathname(const char *s);
void FreePIDL(ITEMIDLIST *pidl);
void ClearOFN();
void ClearBINF();
void Win2Unix(char *s);
void Unix2Win(char *s);
int showfile();
static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data);
int showdir();
void parse_filter(const char *);
void clear_filters();
void add_filter(const char *, const char *);
public:
Fl_Native_File_Chooser(int val = BROWSE_FILE);
~Fl_Native_File_Chooser();
// Public methods
void type(int val);
int type() const;
void options(int);
int options() const;
int count() const;
const char *filename() const;
const char *filename(int i) const;
void directory(const char *val);
const char *directory() const;
void title(const char *val);
const char *title() const;
const char *filter() const;
void filter(const char *val);
int filters() const { return _nfilters; }
void filter_value(int i);
int filter_value() const;
void preset_file(const char *);
const char *preset_file() const;
const char *errmsg() const;
int show();
};
//
// Fl_Native_File_Chooser.cxx -- FLTK native OS file chooser widget
//
// Copyright 2004 by Greg Ercolano.
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// USA.
//
// Use Windows' chooser
#ifdef _WIN32
#include "Fl_Native_File_Chooser_WIN32.cxx"
#endif
// Use Apple's chooser
#ifdef __APPLE__
#include "Fl_Native_File_Chooser_MAC.cxx"
#endif
// All else falls back to FLTK's own chooser
#if ! defined(__APPLE__) && !defined(_WIN32)
#include "Fl_Native_File_Chooser_FLTK.cxx"
#endif
//
// Fl_Native_File_Chooser_FLTK.cxx -- FLTK native OS file chooser widget
//
// Copyright 2004 by Greg Ercolano.
// API changes + filter improvements by Nathan Vander Wilt 2005
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// USA.
//
// Please keep code 80 column compliant.
//
// 10 20 30 40 50 60 70
// | | | | | | |
// 4567890123456789012345678901234567890123456789012345678901234567890123456789
//
#ifdef FLTK1
//
// FLTK1
//
#include <FL/Fl_Native_File_Chooser.H>
#define FNFC_CLASS Fl_Native_File_Chooser
#define FNFC_CTOR Fl_Native_File_Chooser
#define FLTK_CHOOSER_SINGLE Fl_File_Chooser::SINGLE
#define FLTK_CHOOSER_DIRECTORY Fl_File_Chooser::DIRECTORY
#define FLTK_CHOOSER_MULTI Fl_File_Chooser::MULTI
#define FLTK_CHOOSER_CREATE Fl_File_Chooser::CREATE
#else
//
// FLTK2
//
#include <fltk/NativeFileChooser.h>
#include <fltk/run.h>
#define FNFC_CTOR NativeFileChooser
#define FNFC_CLASS fltk::FNFC_CTOR
#define FLTK_CHOOSER_SINGLE fltk::FileChooser::SINGLE
#define FLTK_CHOOSER_DIRECTORY fltk::FileChooser::DIRECTORY
#define FLTK_CHOOSER_MULTI fltk::FileChooser::MULTI
#define FLTK_CHOOSER_CREATE fltk::FileChooser::CREATE
#endif
#include "common.cxx"
#include <sys/stat.h>
// CTOR
FNFC_CLASS::FNFC_CTOR(int val) {
static int init = 0; // 'first time' initialize flag
if ( init == 0 ) {
// Initialize when instanced for first time
load_system_icons();
init = 1;
}
_btype = val;
_options = NO_OPTIONS;
_filter = NULL;
_filtvalue = 0;
_parsedfilt = NULL;
_preset_file = NULL;
_prevvalue = NULL;
_directory = NULL;
_errmsg = NULL;
#ifdef FLTK1
file_chooser = new Fl_File_Chooser(NULL, NULL, 0, NULL);
#else
file_chooser = new fltk::FileChooser(NULL, NULL, 0, NULL);
#endif
type(val); // do this after file_chooser created
_nfilters = 0;
}
// DTOR
FNFC_CLASS::~FNFC_CTOR() {
delete file_chooser;
_filter = strfree(_filter);
_parsedfilt = strfree(_parsedfilt);
_preset_file = strfree(_preset_file);
_prevvalue = strfree(_prevvalue);
_directory = strfree(_directory);
_errmsg = strfree(_errmsg);
}
// PRIVATE: SET ERROR MESSAGE
void FNFC_CLASS::errmsg(const char *msg) {
_errmsg = strfree(_errmsg);
_errmsg = strnew(msg);
}
// PRIVATE: translate Native types to Fl_File_Chooser types
int FNFC_CLASS::type_fl_file(int val) {
switch (val) {
case BROWSE_FILE:
return(FLTK_CHOOSER_SINGLE);
case BROWSE_DIRECTORY:
return(FLTK_CHOOSER_SINGLE | FLTK_CHOOSER_DIRECTORY);
case BROWSE_MULTI_FILE:
return(FLTK_CHOOSER_MULTI);
case BROWSE_MULTI_DIRECTORY:
return(FLTK_CHOOSER_DIRECTORY | FLTK_CHOOSER_MULTI);
case BROWSE_SAVE_FILE:
return(FLTK_CHOOSER_SINGLE | FLTK_CHOOSER_CREATE);
case BROWSE_SAVE_DIRECTORY:
return(FLTK_CHOOSER_DIRECTORY | FLTK_CHOOSER_MULTI | FLTK_CHOOSER_CREATE);
default:
return(FLTK_CHOOSER_SINGLE);
}
}
void FNFC_CLASS::type(int val) {
_btype = val;
file_chooser->type(type_fl_file(val));
}
int FNFC_CLASS::type() const {
return(_btype);
}
// SET OPTIONS
void FNFC_CLASS::options(int val) {
_options = val;
}
// GET OPTIONS
int FNFC_CLASS::options() const {
return(_options);
}
// Show chooser, blocks until done.
// RETURNS:
// 0 - user picked a file
// 1 - user cancelled
// -1 - failed; errmsg() has reason
//
int FNFC_CLASS::show() {
// FILTER
if ( _parsedfilt ) {
file_chooser->filter(_parsedfilt);
}
// FILTER VALUE
// Set this /after/ setting the filter
//
file_chooser->filter_value(_filtvalue);
// DIRECTORY
if ( _directory && _directory[0] ) {
file_chooser->directory(_directory);
} else {
file_chooser->directory(_prevvalue);
}
// PRESET FILE
if ( _preset_file ) {
file_chooser->value(_preset_file);
}
// OPTIONS: PREVIEW
file_chooser->preview( (options() & PREVIEW) ? 1 : 0);
// OPTIONS: NEW FOLDER
if ( options() & NEW_FOLDER )
file_chooser->type(file_chooser->type() |
FLTK_CHOOSER_CREATE); // on
// SHOW
file_chooser->show();
#ifdef FLTK1
// FLTK1: BLOCK WHILE BROWSER SHOWN
while ( file_chooser->shown() ) {
Fl::wait();
}
#else
// FLTK2: BLOCK WHILE BROWSER SHOWN
while ( file_chooser->visible() ) {
fltk::wait();
}
#endif
if ( file_chooser->value() && file_chooser->value()[0] ) {
_prevvalue = strfree(_prevvalue);
_prevvalue = strnew(file_chooser->value());
_filtvalue = file_chooser->filter_value(); // update filter value
// HANDLE SHOWING 'SaveAs' CONFIRM
if ( options() & SAVEAS_CONFIRM && type() == BROWSE_SAVE_FILE ) {
struct stat buf;
if ( stat(file_chooser->value(), &buf) != -1 ) {
if ( buf.st_mode & S_IFREG ) { // Regular file + exists?
if ( exist_dialog() == 0 ) {
return(1);
}
}
}
}
}
if ( file_chooser->count() ) return(0);
else return(1);
}
// RETURN ERROR MESSAGE
const char *FNFC_CLASS::errmsg() const {
return(_errmsg ? _errmsg : "No error");
}
// GET FILENAME
const char* FNFC_CLASS::filename() const {
if ( file_chooser->count() > 0 ) return(file_chooser->value());
return("");
}
// GET FILENAME FROM LIST OF FILENAMES
const char* FNFC_CLASS::filename(int i) const {
if ( i < file_chooser->count() )
return(file_chooser->value(i+1)); // convert fltk 1 based to our 0 based
return("");
}
// SET TITLE
// Can be NULL if no title desired.
//
void FNFC_CLASS::title(const char *val) {
file_chooser->label(val);
}
// GET TITLE
// Can return NULL if none set.
//
const char *FNFC_CLASS::title() const {
return(file_chooser->label());
}
// SET FILTER
// Can be NULL if no filter needed
//
void FNFC_CLASS::filter(const char *val) {
_filter = strfree(_filter);
_filter = strnew(val);
parse_filter();
}
// GET FILTER
const char *FNFC_CLASS::filter() const {
return(_filter);
}
// SET SELECTED FILTER
void FNFC_CLASS::filter_value(int val) {
_filtvalue = val;
}
// RETURN SELECTED FILTER
int FNFC_CLASS::filter_value() const {
return(_filtvalue);
}
// GET TOTAL FILENAMES CHOSEN
int FNFC_CLASS::count() const {
return(file_chooser->count());
}
// PRESET PATHNAME
// Can be NULL if no preset is desired.
//
void FNFC_CLASS::directory(const char *val) {
_directory = strfree(_directory);
_directory = strnew(val);
}
// GET PRESET PATHNAME
// Can return NULL if none set.
//
const char *FNFC_CLASS::directory() const {
return(_directory);
}
// Convert our filter format to fltk's chooser format
// FROM TO (FLTK)
// ------------------------- --------------------------
// "*.cxx" "*.cxx Files(*.cxx)"
// "C Files\t*.{cxx,h}" "C Files(*.{cxx,h})"
// "C Files\t*.{cxx,h}\nText Files\t*.txt" "C Files(*.{cxx,h})\tText Files(*.txt)"
//
// Returns a modified version of the filter that the caller is responsible
// for freeing with strfree().
//
void FNFC_CLASS::parse_filter() {
_parsedfilt = strfree(_parsedfilt); // clear previous parsed filter (if any)
_nfilters = 0;
char *in = _filter;
if ( !in ) return;
int has_name = strchr(in, '\t') ? 1 : 0;
char mode = has_name ? 'n' : 'w'; // parse mode: n=title, w=wildcard
char wildcard[1024] = ""; // parsed wildcard
char name[1024] = "";
// Parse filter user specified
for ( ; 1; in++ ) {
/*** DEBUG
printf("WORKING ON '%c': mode=<%c> name=<%s> wildcard=<%s>\n",
*in, mode, name, wildcard);
***/
switch (*in) {
// FINISHED PARSING NAME?
case '\t':
if ( mode != 'n' ) goto regchar;
mode = 'w';
break;
// ESCAPE NEXT CHAR
case '\\':
++in;
goto regchar;
// FINISHED PARSING ONE OF POSSIBLY SEVERAL FILTERS?
case '\r':
case '\n':
case '\0':
// APPEND NEW FILTER TO LIST
if ( wildcard[0] ) {
// OUT: "name(wild)\tname(wild)"
char comp[2048];
sprintf(comp, "%s%.511s(%.511s)", ((_parsedfilt)?"\t":""),
name, wildcard);
_parsedfilt = strapp(_parsedfilt, comp);
_nfilters++;
//DEBUG printf("DEBUG: PARSED FILT NOW <%s>\n", _parsedfilt);
}
// RESET
wildcard[0] = name[0] = '\0';
mode = strchr(in, '\t') ? 'n' : 'w';
// DONE?
if ( *in == '\0' ) return; // done
else continue; // not done yet, more filters
// Parse all other chars
default: // handle all non-special chars
regchar: // handle regular char
switch ( mode ) {
case 'n': chrcat(name, *in); continue;
case 'w': chrcat(wildcard, *in); continue;
}
break;
}
}
//NOTREACHED
}
// SET PRESET FILENAME
void FNFC_CLASS::preset_file(const char* val) {
_preset_file = strfree(_preset_file);
_preset_file = strnew(val);
}
// GET PRESET FILENAME
const char* FNFC_CLASS::preset_file() const {
return(_preset_file);
}
This diff is collapsed.
This diff is collapsed.
Fl_Native_File_Chooser -- Access platform's native file choosers in FLTK
------------------------------------------------------------------------
WHAT IS "Fl_Native_File_Chooser"?
=================================
Fl_Native_File_Chooser is a 'widget' wrapper to access the
different platform's native file choosers. On platforms that
don't have a 'native' file chooser (linux), we use FLTK's own.
The purpose of this library is to make a consistent interface
for accessing the different native file choosers.
Tested under Linux, Mac OSX and Windows with fltk 1.1.6.
Tested under Linux with fltk 2.x.
LICENSING
=========
Fl_Native_File_Chooser comes with complete free source code.
Fl_Native_File_Chooser is available under the terms of the
GNU Library General Public License. See COPYING for more info.
Yes, it can be used in commercial software! Free! Imagine that.
BUILD INSTRUCTIONS
==================
1. Which version of FLTK?
Fl_Native_File_Chooser now supports fltk1 and fltk2 as of 0.83e.
Edit the Makefile and uncomment/modify the FLTKCONFIG and FLTK2CONFIG
variables as needed.
If both variables are uncommented, both versions of
Fl_Native_File_Chooser will be built.
For instance, if you have both fltk1 and fltk2 installed on your
system, the top of your Makefile settings might look like:
FLTKCONFIG=/usr/local/src/fltk-1.1.x-svn/fltk-config
FLTK2CONFIG=/usr/local/src/fltk-2.0-svn/fltk2-config
Then you can build both with just:
make
These test programs are created, depending on if you have
configured the above for fltk1, fltk2, or both:
./test-browser -- fltk1 exerciser demo
./simple-app -- fltk1 simple app
./test-browser-fltk2 -- fltk2 exerciser demo
./simple-app-fltk2 -- fltk2 simple app
Originally Fl_Native_File_Chooser was designed for FLTK1,
so there may be some left over FLTK1 specific references
in the docs. Please report these as bugs (see below)
PLATFORM SPECIFIC NOTES
=======================
For linux and osx the default compilers are used.
For Windows, tested with VS Express 8 + make.bat / Makefile.MICROSOFT.
Ian confirmed it compiled OK under Windows with mingw using the default
unix Makefile.
WHERE'S THE DOCUMENTATION?
==========================
./documentation/index.html
HOW DO I LINK Fl_Native_File_Chooser INTO MY OWN APPLICATION?
=============================================================
./documentation/how-to-use.html
FILE LAYOUT
===========
./Makefile -- main Makefile for unix builds
./Makefile.MICROSOFT -- main Makefile for native Microsoft builds
./documentation/index.html -- public documentation for fltk1 + fltk2
./FL \__ fltk1 include files and lib
./Fl_Native_File_Chooser.o / (for your app to include and link)
./fltk \__ fltk2 include files and lib
./NativeFileChooser.o / (for your app to include and link)
./reference -- project's reference docs (internal use)
*_FLTK.{cxx,H,h} -- Platforms that don't have native choosers
*_MAC.{cxx,H,h} -- Mac platform specific source code
*_WIN32.{cxx,H,h} -- Windows platform specific source code
RELEASE NOTES/VERSION INFORMATION
=================================
See ./CHANGES.
BUGS? FEATURE REQUESTS?
=======================
Send bugs and RFE's to erco at seriss dot com
> Determine why Mac and OSX don't open browser with preset file selected.
WINDOWS: tried to make this work, but it just doesn't support it!
Even calling GetOpenFileName(&_ofn); twice in a row.
> 0.84: Ian MacArthur indicated mingw warns about strapp and strdump
being "defined but not used" cause it's a static. Should
probably make a lib, disable this warning, or reference
the calls in an unused subroutine.
> 0.83d: Namespace pollution: Yuri wants Carbon.h/win32.h
to not be in the public .H files. Can probably make an 'underbar'
version of the class to isolate them. See erco's post on
fltk.general 06/24/07.
> 0.83d: MAC / Save File:
If:
1) /tmp/foo.xxx exists
2) Directory: set to /tmp
3) Preset File set to foo.xxx
..when browser opens, foo.xxx is GRAYED OUT, even though filter
appears to be on. Can still click on grayed out items to pick them,
and Save As: name changes. Weird!
Looks OK when 'Single File' is selected.
(?) > 0.83d: WINDOWS/FILE BROWSE:
(?) If simple-app's preset filename doesn't end in a backslash,
(?) browser shows contents of parent dir, not dir itself.
(?) Maybe append a slash if stat() shows preset filename is a DIR?
-- 0.82c --
(?) > 0.82c: Windows "Save As" is not setting correct directory in browser
(?) > 0.82: Andreas reports problem with Mac chooser not showing thumbnails
(?) that live on remote drives even though the Finder does.
(?) Files located on the local file system show up OK.
(?) (See Reference #1 below for Apple's SimpleText.c excerpts?)
(?) Also, see Andreas' email 12/05/2005 (Reference #2 below)
(?) > 0.82: Presetting value() under linux causes chooser to open with file
(?) highlighted in the chooser, but not in windows or mac.
(?) > 0.82: Fl_Native_File_Chooser: WINDOWS doesn't handle returning UTF8 from
(?) native windows file chooser.. comes back as garbage, possibly as non-UTF8?
(?) (Found problem on Japanese localized machine by browsing to a dir
(?) with Japanese chars. Shows OK in windows browser, but when returned
(?) to Fl_Input, comes up as garbage, even though the Fl_Input is capable
(?) of showing text correctly if japanese text pasted as text into the
(?) Fl_Input from Windows URL input)
*** DONE ***
(DONE) > 0.82c: "Save As" + "Show Confirm Dialog" is not showing the confirm dialog..!
(DONE) TESTED ON LINUX AND OSX TO WORK OK.
(DONE) > 0.83c: Shane Hill on 02/07/06 reports that under Windows, doing regular
(DONE) file browsing results in the current working dir being changed.
(DONE) Luckily there appears to be a WIN32 flag for this, but the docs
(DONE) say it's ineffective..!?
(DONE) OFN_NOCHANGEDIR
(DONE) Restores the current directory to its original value if the user changed
(DONE) the directory while searching for files.
(DONE) Windows NT 4.0/2000/XP: This flag is ineffective for GetOpenFileName.
(DONE) ^^^^^^^^^^^^^^^^^^^^^^^^
(DONE) > 0.82: Alessandro: uses very long wildcard strings..
(DONE) Replace fixed arrays (char wildcard[80]) with new strapp() stuff.
------------------------------------------------------------------------
Reference #1
------------------------------------------------------------------------
// REFERENCE FROM SimpleText.c for erco..
short numTypes;
OSType typeList[20];
OSType fileType = '\?\?\?\?';
NavDialogRef navDialog;
DetermineWindowTypeOrOpen( nil, fileType, &typeList[0], &numTypes, nil );
// Open as many documents as the user wishes through Appleevents
return OpenFileDialog( 'ttxt', numTypes, typeList, &navDialog );
OSType typeList[20];
OSType docList[20];
pFileTypes[*numTypes] = 'MooV';
pDocumentTypes[*numTypes] = kMovieWindow;
(*numTypes)++;
OSStatus OpenFileDialog(
OSType applicationSignature,
short numTypes,
OSType typeList[],
NavDialogRef *outDialog )
{
OSStatus theErr = noErr;
if ( gOpenFileDialog == NULL )
{
NavDialogCreationOptions dialogOptions;
NavTypeListHandle openList = NULL;
NavGetDefaultDialogCreationOptions( &dialogOptions );
dialogOptions.modality = kWindowModalityNone;
dialogOptions.clientName = CFStringCreateWithPascalString(
NULL, LMGetCurApName(), GetApplicationTextEncoding());
openList = (NavTypeListHandle)NewOpenHandle( applicationSignature, numTypes, typeList );
theErr = NavCreateGetFileDialog( &dialogOptions, openList,
GetPrivateEventUPP(),
NULL, NULL, NULL, &gOpenFileDialog );
------------------------------------------------------------------------
Reference #2
------------------------------------------------------------------------
Andreas Schömann wrote:
> Greg Ercolano wrote:
>
>> Andreas Schömann wrote:
>>
>>> I've found a problem: when loading images (jpg) via network, no thumbnail is shown in the file chooser. Actual loading works. The network device is NTFS formatted. I thought it might be an access rights problem, but with 'Finder' it works fine...
BTW, Andreas is specifically referring to the MAC file browser;
when you have it in 'column' mode, when you highlight eg. a jpg
image, the preview that normally displays off to the right
doesn't show up.
I looked at the SimpleText.c code that comes with the OSX
developer toolkit, ie:
/Developer//Examples/Carbon/SimpleText/*
..and it looks like they use a few options to NavCreateGetFileDialog()
that I don't use, namely arg2 and arg3 to set a list of files
and a callback.
I have to admit I don't fully understand the Mac stuff when it
comes to this sort of thing. Apparently there's a global database
somewhere of 4 character file types that dates back to the 1980's,
and it appears one needs to know these names and hard code them
into your app (as is done in SimpleText.cxx).
I think I'll leave this unfinished, since it's not really a show
stopper, and I'm not sure how to make it work correctly.
> 4) Here on my machine Fl_Native_File_Chooser displays a preview for _local_ images (e.g. .jpeg, .tiff and .png)
Really?
I actually couldn't get that to work on my 10.4.3 box.
When I single click on a jpeg, png, or other image format,
it shows a generic image, but the correct text info about
the image's file type.
What does work is if I click on .c or .cxx files it shows
correctly, and if I click on a .rm file (Real Media),
it shows Real's icon logo.. (shrug)
In the Finder, when you click on images, it shows a thumbnail
of the actual image.
> Hmmmh, somewhat confusing results...
> Especially the different behaviour of Finder and File Chooser is a mystery to me. Why did Apple do that? Maybe this has changed with Tiger?
> 1) and 2) tell me that one can disable file preview with 'Navigation Services', though probably not by intention.
It might be I'm missing some args to NavCreateGetFileDialog()
(arg2 and 3?) Unfortunately I'm not sure what is the correct
code to make that work, if that's even the cause.
Or maybe I need to link in some apple framework that's missing
to make that stuff work.
> I also had a look into the documentation ( http://developer.apple.com/documentation/Carbon/Conceptual/ProvidingNavigationDialogs/index.html ) and it says that 'Navigation Services' offers to specify a 'preview callback' with 'NavCreateGetFileDialog'. This is called when the user selects a file and offers a way to preview custom file types. But Fl_Native_File_Chooser does not use this feature and in that case 'Navigation Services' inspects the file.
Right, as described above.
However, I'd think there'd be defaults for things like jpeg/png/etc.
I'd hate to think I have to manually provide callbacks for each
image type..!
------------------------------------------------------------------------
Reference #3
------------------------------------------------------------------------
//
// common.cxx -- common string subs for Fl_Native_File_Chooser
//
// Copyright 2004 by Greg Ercolano.
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// USA.
//
// Please keep code 80 column compliant.
//
// 10 20 30 40 50 60 70
// | | | | | | |
// 4567890123456789012345678901234567890123456789012345678901234567890123456789
//
#include <string.h>
// COPY A STRING WITH 'new'
// Value can be NULL
//
static char *strnew(const char *val) {
if ( val == NULL ) return(NULL);
char *s = new char[strlen(val)+1];
strcpy(s, val);
return(s);
}
// FREE STRING CREATED WITH strnew(), NULLS OUT STRING
// Value can be NULL
//
static char *strfree(char *val) {
if ( val ) delete [] val;
return(NULL);
}
// 'DYNAMICALLY' APPEND ONE STRING TO ANOTHER
// Returns newly allocated string, or NULL
// if s && val == NULL.
// 's' can be NULL; returns a strnew(val).
// 'val' can be NULL; s is returned unmodified.
//
// Usage:
// char *s = strnew("foo"); // s = "foo"
// s = strapp(s, "bar"); // s = "foobar"
//
static char *strapp(char *s, const char *val) {
if ( ! val ) {
return(s); // Nothing to append? return s
}
if ( ! s ) {
return(strnew(val)); // New string? return copy of val
}
char *news = new char[strlen(s)+strlen(val)+1];
strcpy(news, s);
strcat(news, val);
delete [] s; // delete old string
return(news); // return new copy
}
// APPEND A CHARACTER TO A STRING
// This does NOT allocate space for the new character.
//
static void chrcat(char *s, char c) {
char tmp[2] = { c, '\0' };
strcat(s, tmp);
}
......@@ -84,10 +84,6 @@ This version of Gmsh may contain code (in the contrib/mpeg_encode subdirectory)
copyright (c) 1995 The Regents of the University of California: check the
configuration options.
This version of Gmsh may contain code (in the contrib/NativeFileChooser
subdirectory), copyright (C) 2004 Greg Ercolano: check the configuration
options.
This version of Gmsh may contain code (in the contrib/Netgen subdirectory)
copyright (C) 1994-2004 Joachim Sch"oberl: check the configuration options.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment