mirror of
https://github.com/fltk/fltk.git
synced 2026-05-23 07:46:09 +08:00
Added Fl_Native_File_Chooser widget (with manolo's cocoa mods) to FLTK.
* Source brought into CMP standards compliance * test program added (test/native-filechooser.cxx) * Tested with linux (Ubuntu8) and with OSX (cocoa and non-cocoa builds) TODO: * Needs doxygen docs from Greg's original HTML documentation * Needs mods to Windows build files * Needs mods to cmake, and other build files * Needs Manolo's latest mods (from STR #2298) mentioned on and after "02:05 Jan 13, 2010" git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6997 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// FLTK native OS file chooser widget
|
||||
//
|
||||
// Copyright 1998-2009 by Bill Spitzak and others.
|
||||
// Copyright 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems on the following page:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
|
||||
#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*/
|
||||
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// FLTK native OS file chooser widget
|
||||
//
|
||||
// Copyright 1998-2009 by Bill Spitzak and others.
|
||||
// Copyright 2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems on the following page:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
|
||||
#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;
|
||||
|
||||
//added by MG
|
||||
Fl_File_Browser *my_fileList;
|
||||
Fl_Check_Button *show_hidden;
|
||||
char old_dir[300];
|
||||
int prev_filtervalue;
|
||||
static void show_hidden_cb(Fl_Check_Button *o, void *data);
|
||||
static void remove_hidden_files(Fl_File_Browser *my_fileList);
|
||||
|
||||
// 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();
|
||||
// added by MG
|
||||
Fl_Choice *showChoice;
|
||||
};
|
||||
@@ -0,0 +1,156 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// FLTK native OS file chooser widget
|
||||
//
|
||||
// Copyright 1998-2009 by Bill Spitzak and others.
|
||||
// Copyright 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems on the following page:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
|
||||
// OSX-SPECIFIC NATIVE BROWSER
|
||||
#ifdef __APPLE_CC__
|
||||
#include <Carbon/Carbon.h>
|
||||
#else /*__APPLE_CC__*/
|
||||
#include <Carbon.h>
|
||||
#endif /*__APPLE_CC__*/
|
||||
#include <config.h>
|
||||
|
||||
#undef check // necessary for use of Fl::check()
|
||||
|
||||
#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
|
||||
};
|
||||
#ifndef __APPLE_COCOA__
|
||||
protected:
|
||||
NavDialogCreationOptions _opts; // file navigation options
|
||||
#endif
|
||||
private:
|
||||
int _btype; // kind-of browser to show()
|
||||
int _options; // general options
|
||||
#ifdef __APPLE_COCOA__
|
||||
void *_panel;
|
||||
#else
|
||||
NavDialogRef _ref; // file navigation reference
|
||||
#endif
|
||||
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
|
||||
|
||||
#ifndef __APPLE_COCOA__
|
||||
// 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);
|
||||
};
|
||||
#endif
|
||||
// Private methods
|
||||
void errmsg(const char *msg);
|
||||
void clear_pathnames();
|
||||
void set_single_pathname(const char *s);
|
||||
#ifdef __APPLE_COCOA__
|
||||
int get_saveas_basename(void);
|
||||
#else
|
||||
int get_saveas_basename(NavDialogRef& ref);
|
||||
#endif
|
||||
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);
|
||||
#ifndef __APPLE_COCOA__
|
||||
static Boolean filter_proc_cb(AEDesc *, void *, void *, NavFilterModes);
|
||||
Boolean filter_proc_cb2(AEDesc*, void*, void*, NavFilterModes);
|
||||
#endif
|
||||
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();
|
||||
};
|
||||
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// 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
|
||||
OPENFILENAMEW _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();
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
// "$Id$"
|
||||
//
|
||||
// FLTK native OS file chooser widget
|
||||
//
|
||||
// Copyright 1998-2005 by Bill Spitzak and others.
|
||||
// Copyright 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems to:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
|
||||
// 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
|
||||
|
||||
//
|
||||
// End of "$Id:".
|
||||
//
|
||||
@@ -0,0 +1,395 @@
|
||||
// "$Id$"
|
||||
//
|
||||
// FLTK native OS file chooser widget
|
||||
//
|
||||
// Copyright 1998-2005 by Bill Spitzak and others.
|
||||
// Copyright 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems to:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
|
||||
#include <FL/Fl_Native_File_Chooser.H>
|
||||
#include <FL/Fl_File_Icon.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
|
||||
|
||||
#include "Fl_Native_File_Chooser_common.cxx"
|
||||
#include <sys/stat.h>
|
||||
|
||||
// CTOR
|
||||
FNFC_CLASS::FNFC_CTOR(int val) {
|
||||
//// CANT USE THIS -- MESSES UP LINKING/CREATES DEPENDENCY ON fltk_images.
|
||||
//// Have user call this from app instead.
|
||||
////
|
||||
//// static int init = 0; // 'first time' initialize flag
|
||||
//// if ( init == 0 ) {
|
||||
//// // Initialize when instanced for first time
|
||||
//// Fl_File_Icon::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;
|
||||
file_chooser = new Fl_File_Chooser(NULL, NULL, 0, NULL);
|
||||
type(val); // do this after file_chooser created
|
||||
_nfilters = 0;
|
||||
|
||||
// Added by MG
|
||||
Fl_Button *b = file_chooser->previewButton;
|
||||
Fl_Window *w = b->window();
|
||||
Fl_Group::current(w); // adds a "Show hidden files" check button in file_chooser's window
|
||||
show_hidden = new Fl_Check_Button(b->x() + b->w() + 10, b->y(), 145, b->h(), "Show hidden files");
|
||||
show_hidden->callback((Fl_Callback*)show_hidden_cb, this);
|
||||
// This is a hack to bypass the fact that fileList is a private member of file_chooser.
|
||||
// Find it as 1st child of 2nd child of file_chooser's window.
|
||||
Fl_Group *g = (Fl_Group *)w->array()[1];
|
||||
my_fileList = (Fl_File_Browser *)g->array()[0];
|
||||
old_dir[0] = 0; // to detect directory changes
|
||||
prev_filtervalue = file_chooser->filter_value(); // to detect filter changes
|
||||
// Hack to get file_chooser's showChoice widget.
|
||||
// Find it as 1st child of 1st child of file_chooser's window.
|
||||
g = (Fl_Group *)w->array()[0];
|
||||
showChoice = (Fl_Choice *)g->array()[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();
|
||||
|
||||
// BLOCK WHILE BROWSER SHOWN
|
||||
while ( file_chooser->shown() ) {
|
||||
if(strcmp(old_dir, file_chooser->directory()) != 0) {
|
||||
strcpy(old_dir, file_chooser->directory());
|
||||
if(!show_hidden->value()) remove_hidden_files(my_fileList);
|
||||
} else if(prev_filtervalue != file_chooser->filter_value() ) {
|
||||
prev_filtervalue = file_chooser->filter_value();
|
||||
if(!show_hidden->value() ) remove_hidden_files(my_fileList);
|
||||
}
|
||||
Fl::wait();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void FNFC_CLASS::show_hidden_cb(Fl_Check_Button *o, void *data)
|
||||
{
|
||||
Fl_Native_File_Chooser *mychooser = (Fl_Native_File_Chooser *)data;
|
||||
if(o->value()) {
|
||||
mychooser->my_fileList->load(mychooser->file_chooser->directory());
|
||||
} else {
|
||||
remove_hidden_files(mychooser->my_fileList);
|
||||
mychooser->my_fileList->redraw();
|
||||
}
|
||||
}
|
||||
|
||||
void FNFC_CLASS::remove_hidden_files(Fl_File_Browser *my_fileList)
|
||||
{
|
||||
int count = my_fileList->size();
|
||||
for(int num = count; num >= 1; num--) {
|
||||
const char *p = my_fileList->text(num);
|
||||
if(*p == '.' && strcmp(p, "../") != 0) my_fileList->remove(num);
|
||||
}
|
||||
my_fileList->topline(1);
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id:".
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,83 @@
|
||||
// "$Id$"
|
||||
//
|
||||
// FLTK native OS file chooser widget
|
||||
//
|
||||
// Copyright 1998-2005 by Bill Spitzak and others.
|
||||
// Copyright 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems to:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
|
||||
#include <string.h>
|
||||
#include <FL/Enumerations.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);
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id:".
|
||||
//
|
||||
+502
-528
File diff suppressed because it is too large
Load Diff
@@ -63,6 +63,7 @@ CPPFILES = \
|
||||
Fl_Menu_add.cxx \
|
||||
Fl_Menu_global.cxx \
|
||||
Fl_Multi_Label.cxx \
|
||||
Fl_Native_File_Chooser.cxx \
|
||||
Fl_Overlay_Window.cxx \
|
||||
Fl_Pack.cxx \
|
||||
Fl_Pixmap.cxx \
|
||||
@@ -476,6 +477,8 @@ include makedepend
|
||||
# These dependencies aren't part of the makedepend file since
|
||||
# they are part of the WIN32 and MacOS code base...
|
||||
Fl_get_key.o: Fl_get_key_mac.cxx Fl_get_key_win32.cxx
|
||||
Fl_Native_File_Chooser.o : Fl_Native_File_Chooser_MAC.cxx Fl_Native_File_Chooser_WIN32.cxx \
|
||||
Fl_Native_File_Chooser_FLTK.cxx
|
||||
Fl.o: Fl_mac.cxx Fl_win32.cxx Fl_cocoa.mm
|
||||
fl_color.o: fl_color_mac.cxx fl_color_win32.cxx
|
||||
fl_dnd.o: fl_dnd_mac.cxx fl_dnd_win32.cxx fl_dnd_x.cxx
|
||||
@@ -512,6 +515,9 @@ Fl_Image.o: ../FL/mac.H ../FL/win32.H
|
||||
fl_line_style.o: ../FL/mac.H ../FL/win32.H
|
||||
Fl_mac.o: ../FL/mac.H ../FL/win32.H
|
||||
Fl_cocoa.o: ../FL/mac.H ../FL/win32.H
|
||||
Fl_Native_File_Chooser_MAC.o: ../FL/Fl_Native_File_Chooser.H ../FL/Fl_Native_File_Chooser_MAC.H
|
||||
Fl_Native_File_Chooser_WIN32.o: ../FL/Fl_Native_File_Chooser.H ../FL/Fl_Native_File_Chooser_WIN32.H
|
||||
Fl_Native_File_Chooser_FLTK.o: ../FL/Fl_Native_File_Chooser.H ../FL/Fl_Native_File_Chooser_FLTK.H
|
||||
Fl_Menu_Window.o: ../FL/mac.H ../FL/win32.H
|
||||
fl_overlay.o: ../FL/mac.H ../FL/win32.H
|
||||
fl_overlay_visual.o: ../FL/mac.H ../FL/win32.H
|
||||
|
||||
@@ -215,6 +215,8 @@ Fl_Multi_Label.o: ../FL/fl_types.h ../FL/Xutf8.h ../FL/Enumerations.H
|
||||
Fl_Multi_Label.o: ../FL/Fl_Export.H ../FL/fl_types.h ../FL/Fl_Widget.H
|
||||
Fl_Multi_Label.o: ../FL/Fl_Menu_Item.H ../FL/Fl_Widget.H ../FL/Fl_Image.H
|
||||
Fl_Multi_Label.o: ../FL/Fl_Multi_Label.H
|
||||
Fl_Native_File_Chooser.o: ../config.h Fl_Native_File_Chooser_common.cxx \
|
||||
../FL/Fl_Native_File_Chooser.H ../FL/Fl.H ../FL/filename.H
|
||||
Fl_Overlay_Window.o: ../config.h ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H
|
||||
Fl_Overlay_Window.o: ../FL/fl_types.h ../FL/Xutf8.h ../FL/Enumerations.H
|
||||
Fl_Overlay_Window.o: ../FL/Fl_Export.H ../FL/fl_types.h
|
||||
|
||||
@@ -61,6 +61,7 @@ CPPFILES = &
|
||||
Fl_Menu_add.obj &
|
||||
Fl_Menu_global.obj &
|
||||
Fl_Multi_Label.obj &
|
||||
Fl_Native_File_Chooser.obj &
|
||||
Fl_Overlay_Window.obj &
|
||||
Fl_Pack.obj &
|
||||
Fl_Pixmap.obj &
|
||||
|
||||
@@ -74,6 +74,7 @@ CPPFILES =\
|
||||
menubar.cxx \
|
||||
message.cxx \
|
||||
minimum.cxx \
|
||||
native-filechooser.cxx \
|
||||
navigation.cxx \
|
||||
output.cxx \
|
||||
overlay.cxx \
|
||||
@@ -139,6 +140,7 @@ ALL = \
|
||||
menubar$(EXEEXT) \
|
||||
message$(EXEEXT) \
|
||||
minimum$(EXEEXT) \
|
||||
native-filechooser$(EXEEXT) \
|
||||
navigation$(EXEEXT) \
|
||||
output$(EXEEXT) \
|
||||
overlay$(EXEEXT) \
|
||||
@@ -377,6 +379,8 @@ message$(EXEEXT): message.o
|
||||
|
||||
minimum$(EXEEXT): minimum.o
|
||||
|
||||
native-filechooser$(EXEEXT): native-filechooser.o
|
||||
|
||||
navigation$(EXEEXT): navigation.o
|
||||
|
||||
output$(EXEEXT): output.o $(FLLIBNAME)
|
||||
|
||||
@@ -62,6 +62,7 @@ ALL = &
|
||||
$(ODIR)/menubar$(EXEEXT) &
|
||||
$(ODIR)/message$(EXEEXT) &
|
||||
$(ODIR)/minimum$(EXEEXT) &
|
||||
$(ODIR)/native-filechooser$(EXEEXT) &
|
||||
$(ODIR)/navigation$(EXEEXT) &
|
||||
$(ODIR)/output$(EXEEXT) &
|
||||
$(ODIR)/overlay$(EXEEXT) &
|
||||
@@ -179,6 +180,8 @@ $(ODIR)/message$(EXEEXT) : $(ODIR)/message.obj
|
||||
|
||||
$(ODIR)/minimum$(EXEEXT) : $(ODIR)/minimum.obj
|
||||
|
||||
$(ODIR)/native-filechooser$(EXEEXT) : $(ODIR)/native-filechooser.obj
|
||||
|
||||
$(ODIR)/navigation$(EXEEXT) : $(ODIR)/navigation.obj
|
||||
|
||||
$(ODIR)/output$(EXEEXT) : $(ODIR)/output.obj
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// Simple test of the Fl_Native_File_Chooser.
|
||||
//
|
||||
// Copyright 1998-2009 by Bill Spitzak and others.
|
||||
// Copyright 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
// USA.
|
||||
//
|
||||
// Please report all bugs and problems on the following page:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/fl_ask.H> // fl_beep()
|
||||
#include <FL/Fl_Window.H>
|
||||
#include <FL/Fl_Button.H>
|
||||
#include <FL/Fl_Input.H>
|
||||
#include <FL/Fl_Native_File_Chooser.H>
|
||||
|
||||
// GLOBALS
|
||||
Fl_Input *G_filename = NULL;
|
||||
|
||||
void Butt_CB(Fl_Widget*, void*) {
|
||||
// Create native chooser
|
||||
Fl_Native_File_Chooser native;
|
||||
native.title("Pick a file");
|
||||
native.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
||||
native.filter("Text\t*.txt\n"
|
||||
"C Files\t*.{cxx,h,c}\n"
|
||||
"Apps\t*.{app}\n"); // TODO: need to add kNavSupportPackages to non-cocoa <FNFC>_MAC.cxx
|
||||
native.preset_file(G_filename->value());
|
||||
// Show native chooser
|
||||
switch ( native.show() ) {
|
||||
case -1: fprintf(stderr, "ERROR: %s\n", native.errmsg()); break; // ERROR
|
||||
case 1: fprintf(stderr, "*** CANCEL\n"); fl_beep(); break; // CANCEL
|
||||
default: // PICKED FILE
|
||||
if ( native.filename() ) {
|
||||
G_filename->value(native.filename());
|
||||
} else {
|
||||
G_filename->value("NULL");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
//// For a nicer looking browser under linux, uncomment the following line.
|
||||
//// (If you do this, you'll need to link with fltk_images)
|
||||
////
|
||||
//// Fl_File_Icon::load_system_icons();
|
||||
|
||||
Fl_Window *win = new Fl_Window(600, 100, "FLTK Window");
|
||||
win->begin();
|
||||
{
|
||||
int y = 10;
|
||||
G_filename = new Fl_Input(80, y, win->w()-80-10, 25, "Filename");
|
||||
G_filename->value(argc < 2 ? "." : argv[1]);
|
||||
G_filename->tooltip("Default filename");
|
||||
y += G_filename->h() + 5;
|
||||
Fl_Button *but = new Fl_Button(win->w()-80-10, win->h()-25-10, 80, 25, "Pick File");
|
||||
but->callback(Butt_CB);
|
||||
}
|
||||
win->end();
|
||||
win->resizable(win);
|
||||
win->show();
|
||||
return(Fl::run());
|
||||
}
|
||||
Reference in New Issue
Block a user