New file chooser

pull/2/head
Stelios Bounanos 2008-03-31 01:48:46 +01:00
rodzic 19514d354a
commit ceb418cb15
33 zmienionych plików z 2665 dodań i 1925 usunięć

Wyświetl plik

@ -4,7 +4,7 @@
bin_PROGRAMS = fldigi
AM_CPPFLAGS = -I$(srcdir) -I$(srcdir)/include -I$(srcdir)/irrxml @BOOST_CPPFLAGS@
AM_CPPFLAGS = -I$(srcdir) -I$(srcdir)/include -I$(srcdir)/irrxml -Ifileselector @BOOST_CPPFLAGS@
AM_CXXFLAGS = @PORTAUDIO_CFLAGS@ @FLTK_CFLAGS@ @SNDFILE_CFLAGS@ \
@SAMPLERATE_CFLAGS@ @PULSEAUDIO_CFLAGS@ @HAMLIB_CFLAGS@ \
@ -120,9 +120,9 @@ fldigi_SOURCES += \
feld/feld.cxx \
feld/feldfonts.cxx \
fft/fft.cxx \
fileselector/File_Selector.cxx \
fileselector/File_Selector2.cxx \
fileselector/file_dir.cxx \
fileselector/FL/Fl_Native_File_Chooser.H \
fileselector/Fl_Native_File_Chooser.cxx \
fileselector/fileselect.cxx \
filters/fftfilt.cxx \
filters/filters.cxx \
filters/viterbi.cxx \
@ -133,8 +133,7 @@ fldigi_SOURCES += \
include/Enumerations.h \
include/FLdigiTypes.h \
include/FTextView.h \
include/FileString.h \
include/File_Selector.h \
include/fileselect.h \
include/Fl_Text_Display_mod.H \
include/Fl_Text_Editor_mod.H \
include/FreqControl.h \
@ -290,10 +289,17 @@ fldigi_SOURCES += \
wwv/analysis.cxx \
wwv/wwv.cxx
# Sources that are part of the distribution but are not compiled
# Sources that are part of the distribution but are not compiled directly
EXTRA_fldigi_SOURCES += \
blank/blank.cxx \
blank/blank.h \
fileselector/FL/Fl_Native_File_Chooser_FLTK.H \
fileselector/FL/Fl_Native_File_Chooser_MAC.H \
fileselector/FL/Fl_Native_File_Chooser_WIN32.H \
fileselector/Fl_Native_File_Chooser_FLTK.cxx \
fileselector/Fl_Native_File_Chooser_MAC.cxx \
fileselector/Fl_Native_File_Chooser_WIN32.cxx \
fileselector/flnfc_common.cxx \
feld/Feld7x7-14.cxx \
feld/Feld7x7n-14.cxx \
feld/FeldDx-14.cxx \
@ -328,14 +334,5 @@ EXTRA_DIST = \
$(srcdir)/../data/fldigi.desktop \
$(srcdir)/../data/mac/Info.plist.in \
$(srcdir)/../data/win32/fldigi.ico \
fileselector/allfiles.xbm \
fileselector/d1.xbm \
fileselector/d1_mask.xbm \
fileselector/ew.xbm \
fileselector/ew_mask.xbm \
fileselector/new.xbm \
fileselector/ns.xbm \
fileselector/ns_mask.xbm \
fileselector/up.xbm \
dialogs/confdialog.fl \
rigcontrol/rigdialog.fl

Wyświetl plik

@ -0,0 +1,40 @@
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
#ifndef FL_NATIVE_FILE_CHOOSER_H
#define FL_NATIVE_FILE_CHOOSER_H
// Use Windows' chooser
#if defined(_WIN32) //|| defined(__CYGWIN__)
#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) //&& !defined(__CYGWIN__)
#include <FL/Fl_Native_File_Chooser_FLTK.H>
#endif
#endif /*FL_NATIVE_FILE_CHOOSER_H*/

Wyświetl plik

@ -0,0 +1,97 @@
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// 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();
};

Wyświetl plik

@ -0,0 +1,138 @@
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// 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();
};

Wyświetl plik

@ -0,0 +1,108 @@
//
// 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
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();
};

Wyświetl plik

@ -1,347 +0,0 @@
//
// "$Id: File_Selector.cxx 4723 2005-12-30 10:13:17Z matt $"
//
// File_Selector dialog for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2005 by Bill Spitzak and others.
//
// 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
//
// generated by Fast Light User Interface Designer (fluid) version 1.0107
#include <config.h>
#include "File_Selector.h"
#include <FL/fl_draw.H>
void File_Selector::cb_window_i(Fl_Double_Window*, void*) {
fileName->value("");
fileList->deselect();
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
window->hide();
}
void File_Selector::cb_window(Fl_Double_Window* o, void* v) {
((File_Selector*)(o->user_data()))->cb_window_i(o,v);
}
void File_Selector::cb_showChoice_i(Fl_Choice*, void*) {
showChoiceCB();
}
void File_Selector::cb_showChoice(Fl_Choice* o, void* v) {
((File_Selector*)(o->parent()->parent()->user_data()))->cb_showChoice_i(o,v);
}
void File_Selector::cb_newButton_i(Fl_Button*, void*) {
newdir();
}
void File_Selector::cb_newButton(Fl_Button* o, void* v) {
((File_Selector*)(o->parent()->parent()->user_data()))->cb_newButton_i(o,v);
}
#include <FL/Fl_Bitmap.H>
static unsigned char idata_new[] =
{0,0,120,0,132,0,2,1,1,254,1,128,49,128,49,128,253,128,253,128,49,128,49,
128,1,128,1,128,255,255,0,0};
static Fl_Bitmap image_new(idata_new, 16, 16);
void File_Selector::cb__i(Fl_Tile*, void*) {
update_preview();
}
void File_Selector::cb_(Fl_Tile* o, void* v) {
((File_Selector*)(o->parent()->user_data()))->cb__i(o,v);
}
void File_Selector::cb_fileList_i(Fl_File_Browser*, void*) {
fileListCB();
}
void File_Selector::cb_fileList(Fl_File_Browser* o, void* v) {
((File_Selector*)(o->parent()->parent()->user_data()))->cb_fileList_i(o,v);
}
void File_Selector::cb_previewButton_i(Fl_Check_Button*, void*) {
preview(previewButton->value());
}
void File_Selector::cb_previewButton(Fl_Check_Button* o, void* v) {
((File_Selector*)(o->parent()->parent()->parent()->user_data()))->cb_previewButton_i(o,v);
}
void File_Selector::cb_fileName_i(Fl_File_Input*, void*) {
fileNameCB();
}
void File_Selector::cb_fileName(Fl_File_Input* o, void* v) {
((File_Selector*)(o->parent()->parent()->user_data()))->cb_fileName_i(o,v);
}
void File_Selector::cb_okButton_i(Fl_Return_Button*, void*) {
// Do any callback that is registered...
if (callback_)
(*callback_)(this, data_);
window->hide();
}
void File_Selector::cb_okButton(Fl_Return_Button* o, void* v) {
((File_Selector*)(o->parent()->parent()->parent()->user_data()))->cb_okButton_i(o,v);
}
void File_Selector::cb_cancelButton_i(Fl_Button*, void*) {
fileName->value("");
fileList->deselect();
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
window->hide();
}
void File_Selector::cb_cancelButton(Fl_Button* o, void* v) {
((File_Selector*)(o->parent()->parent()->parent()->user_data()))->cb_cancelButton_i(o,v);
}
File_Selector::File_Selector(const char *d, const char *p, int t, const char *title) {
Fl_Double_Window* w;
{ Fl_Double_Window* o = window = new Fl_Double_Window(490, 380, "Choose File");
w = o;
o->callback((Fl_Callback*)cb_window, (void*)(this));
{ Fl_Group* o = new Fl_Group(10, 10, 470, 25);
{ Fl_Choice* o = showChoice = new Fl_Choice(65, 10, 215, 25, "Show:");
o->down_box(FL_BORDER_BOX);
o->labelfont(1);
o->callback((Fl_Callback*)cb_showChoice);
Fl_Group::current()->resizable(o);
showChoice->label(show_label);
}
{ Fl_Button* o = newButton = new Fl_Button(455, 10, 25, 25);
o->image(image_new);
o->labelsize(8);
o->callback((Fl_Callback*)cb_newButton);
o->tooltip(new_directory_tooltip);
}
o->end();
}
{ Fl_Tile* o = new Fl_Tile(10, 45, 470, 225);
o->callback((Fl_Callback*)cb_);
{ Fl_File_Browser* o = fileList = new Fl_File_Browser(10, 45, 295, 225);
o->type(2);
o->callback((Fl_Callback*)cb_fileList);
w->hotspot(o);
}
{ Fl_Box* o = previewBox = new Fl_Box(305, 45, 175, 225, "?");
o->box(FL_DOWN_BOX);
o->labelsize(100);
o->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE);
}
o->end();
Fl_Group::current()->resizable(o);
}
{ Fl_Group* o = new Fl_Group(10, 275, 470, 95);
{ Fl_Group* o = new Fl_Group(10, 275, 470, 20);
{ Fl_Check_Button* o = previewButton = new Fl_Check_Button(10, 275, 73, 20, "Preview");
o->down_box(FL_DOWN_BOX);
o->value(1);
o->shortcut(0x80070);
o->callback((Fl_Callback*)cb_previewButton);
previewButton->label(preview_label);
}
{ Fl_Box* o = new Fl_Box(115, 275, 365, 20);
Fl_Group::current()->resizable(o);
}
o->end();
}
{ Fl_File_Input* o = fileName = new Fl_File_Input(115, 300, 365, 35);
o->labelfont(1);
o->callback((Fl_Callback*)cb_fileName);
o->when(FL_WHEN_ENTER_KEY);
Fl_Group::current()->resizable(o);
fileName->when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY_ALWAYS);
}
{ Fl_Box* o = new Fl_Box(10, 310, 105, 25, "Filename:");
o->labelfont(1);
o->align(FL_ALIGN_RIGHT|FL_ALIGN_INSIDE);
o->label(filename_label);
}
{ Fl_Group* o = new Fl_Group(10, 345, 470, 25);
{ Fl_Return_Button* o = okButton = new Fl_Return_Button(313, 345, 85, 25, "OK");
o->callback((Fl_Callback*)cb_okButton);
okButton->label(fl_ok);
}
{ Fl_Button* o = cancelButton = new Fl_Button(408, 345, 72, 25, "Cancel");
o->callback((Fl_Callback*)cb_cancelButton);
o->label(fl_cancel);
}
{ Fl_Box* o = new Fl_Box(10, 345, 30, 25);
Fl_Group::current()->resizable(o);
}
o->end();
}
o->end();
}
if (title) window->label(title);
o->set_modal();
o->end();
}
data_ = 0;
directory_[0] = 0;
window->xclass(PACKAGE_NAME);
window->size_range(window->w(), window->h(), Fl::w(), Fl::h());
type(t);
filter(p);
value(d);
type(t);
preview(1);
}
File_Selector::~File_Selector() {
Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
delete window;
}
void File_Selector::callback(void (*cb)(File_Selector *, void *), void *d ) {
callback_ = cb;
data_ = d;
}
void File_Selector::color(Fl_Color c) {
fileList->color(c);
}
Fl_Color File_Selector::color() {
return (fileList->color());
}
char * File_Selector::directory() {
return directory_;
}
const char * File_Selector::filter() {
return (fileList->filter());
}
int File_Selector::filter_value() {
return showChoice->value();
}
void File_Selector::filter_value(int f) {
showChoice->value(f);
showChoiceCB();
}
void File_Selector::hide() {
window->hide();
}
void File_Selector::iconsize(uchar s) {
fileList->iconsize(s);
}
uchar File_Selector::iconsize() {
return (fileList->iconsize());
}
void File_Selector::label(const char *l) {
window->label(l);
}
const char * File_Selector::label() {
return (window->label());
}
void File_Selector::ok_label(const char *l) {
okButton->label(l);
int w=0, h=0;
okButton->measure_label(w, h);
okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(),
w + 40, 25);
okButton->parent()->init_sizes();
}
const char * File_Selector::ok_label() {
return (okButton->label());
}
void File_Selector::show() {
window->hotspot(fileList);
window->show();
Fl::flush();
fl_cursor(FL_CURSOR_WAIT);
rescan();
fl_cursor(FL_CURSOR_DEFAULT);
fileName->take_focus();
}
int File_Selector::shown() {
return window->shown();
}
void File_Selector::textcolor(Fl_Color c) {
fileList->textcolor(c);
}
Fl_Color File_Selector::textcolor() {
return (fileList->textcolor());
}
void File_Selector::textfont(uchar f) {
fileList->textfont(f);
}
uchar File_Selector::textfont() {
return (fileList->textfont());
}
void File_Selector::textsize(uchar s) {
fileList->textsize(s);
}
uchar File_Selector::textsize() {
return (fileList->textsize());
}
void File_Selector::type(int t) {
type_ = t;
if (t & MULTI)
fileList->type(FL_MULTI_BROWSER);
else
fileList->type(FL_HOLD_BROWSER);
if (t & CREATE)
newButton->activate();
else
newButton->deactivate();
if (t & DIRECTORY)
fileList->filetype(Fl_File_Browser::DIRECTORIES);
else
fileList->filetype(Fl_File_Browser::FILES);
}
int File_Selector::type() {
return (type_);
}
void * File_Selector::user_data() const {
return (data_);
}
void File_Selector::user_data(void *d) {
data_ = d;
}
int File_Selector::visible() {
return window->visible();
}
//
// End of "$Id: File_Selector.cxx 4723 2005-12-30 10:13:17Z matt $".
//

Wyświetl plik

@ -0,0 +1,36 @@
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Use Windows' chooser
#if defined(_WIN32) //|| defined(__CYGWIN__)
#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) //&& !defined(__CYGWIN__)
#include "Fl_Native_File_Chooser_FLTK.cxx"
#endif

Wyświetl plik

@ -0,0 +1,376 @@
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please keep code 80 column compliant.
//
// 10 20 30 40 50 60 70
// | | | | | | |
// 4567890123456789012345678901234567890123456789012345678901234567890123456789
//
#define FLTK1
#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 "flnfc_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);
}

Wyświetl plik

@ -0,0 +1,865 @@
//
// Fl_Native_File_Chooser_MAC.cxx -- FLTK native OS file chooser widget
//
// Copyright 2004 by Greg Ercolano.
// FLTK2/MAC port by Greg Ercolano 2007.
//
// 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 keep code 80 column compliant.
//
// 10 20 30 40 50 60 70
// | | | | | | |
// 4567890123456789012345678901234567890123456789012345678901234567890123456789
//
// TODO:
// o When doing 'open file', only dir is preset, not filename.
// Possibly 'preset_file' could be used to select the filename.
//
#include "flnfc_common.cxx" // strnew/strfree/strapp/chrcat
#define FLTK1
#ifdef FLTK1
//
// FLTK1
//
#include <FL/Fl.H>
#include <FL/Fl_Native_File_Chooser.H>
#include <FL/filename.H>
#define FNFC_CLASS Fl_Native_File_Chooser
#define FNFC_CTOR Fl_Native_File_Chooser
#else
//
// FLTK2
//
#include <fltk/NativeFileChooser.h>
#include <fltk/run.h>
#include <fltk/filename.h>
#define FNFC_CTOR NativeFileChooser
#define FNFC_CLASS fltk::FNFC_CTOR
#define fl_filename_match filename_match // fltk1 name -> fltk2 name
#define fl_filename_isdir filename_isdir // fltk1 name -> fltk2 name
#endif
// TRY TO CONVERT AN AEDesc TO AN FSSpec
// As per Apple Technical Q&A QA1274
// eg: http://developer.apple.com/qa/qa2001/qa1274.html
// Returns 'noErr' if OK,
// or an 'OSX result code' on error.
//
static int AEDescToFSSpec(const AEDesc* desc, FSSpec* fsspec) {
OSStatus err = noErr;
AEDesc coerceDesc;
// If AEDesc isn't already an FSSpec, convert it to one
if ( desc->descriptorType != typeFSS ) {
if ( ( err = AECoerceDesc(desc, typeFSS, &coerceDesc) ) == noErr ) {
// Get FSSpec out of AEDesc
err = AEGetDescData(&coerceDesc, fsspec, sizeof(FSSpec));
AEDisposeDesc(&coerceDesc);
}
} else {
err = AEGetDescData(desc, fsspec, sizeof(FSSpec));
}
return( err );
}
// CONVERT AN FSSpec TO A PATHNAME
static void FSSpecToPath(const FSSpec &spec, char *buff, int bufflen) {
FSRef fsRef;
FSpMakeFSRef(&spec, &fsRef);
FSRefMakePath(&fsRef, (UInt8*)buff, bufflen);
}
// CONVERT REGULAR PATH -> FSSpec
// If file does not exist, expect fnfErr.
// Returns 'noErr' if OK,
// or an 'OSX result code' on error.
//
static OSStatus PathToFSSpec(const char *path, FSSpec &spec) {
OSStatus err;
FSRef ref;
if ((err = FSPathMakeRef((const UInt8*)path, &ref, NULL)) != noErr) {
return(err);
}
// FSRef -> FSSpec
if ((err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, &spec,
NULL)) != noErr) {
return(err);
}
return(noErr);
}
// NAVREPLY: CTOR
FNFC_CLASS::NavReply::NavReply() {
_valid_reply = 0;
}
// NAVREPLY: DTOR
FNFC_CLASS::NavReply::~NavReply() {
if ( _valid_reply ) {
NavDisposeReply(&_reply);
}
}
// GET REPLY FROM THE NAV* DIALOG
int FNFC_CLASS::NavReply::get_reply(NavDialogRef& ref) {
if ( _valid_reply ) {
NavDisposeReply(&_reply); // dispose of previous
_valid_reply = 0;
}
if ( ref == NULL || NavDialogGetReply(ref, &_reply) != noErr ) {
return(-1);
}
_valid_reply = 1;
return(0);
}
// RETURN THE BASENAME USER WANTS TO 'Save As'
int FNFC_CLASS::NavReply::get_saveas_basename(char *s, int slen) {
if (CFStringGetCString(_reply.saveFileName, s, slen-1,
kCFStringEncodingUTF8) == false) {
s[0] = '\0';
return(-1);
}
return(0);
}
// RETURN THE DIRECTORY NAME
// Returns 0 on success, -1 on error.
//
int FNFC_CLASS::NavReply::get_dirname(char *s, int slen) {
FSSpec fsspec;
if ( AEDescToFSSpec(&_reply.selection, &fsspec) != noErr ) {
// Conversion failed? Return empty name
s[0] = 0;
return(-1);
}
FSSpecToPath(fsspec, s, slen);
return(0);
}
// RETURN MULTIPLE DIRECTORIES
// Returns: 0 on success with pathnames[] containing pathnames selected,
// -1 on error
//
int FNFC_CLASS::NavReply::get_pathnames(char **&pathnames,
int& tpathnames) {
// How many items selected?
long count = 0;
if ( AECountItems(&_reply.selection, &count) != noErr )
{ return(-1); }
// Allocate space for that many pathnames
pathnames = new char*[count];
memset((void*)pathnames, 0, count*sizeof(char*));
tpathnames = count;
// Walk list of pathnames selected
for (short index=1; index<=count; index++) {
AEKeyword keyWord;
AEDesc desc;
if (AEGetNthDesc(&_reply.selection, index, typeFSS, &keyWord,
&desc) != noErr) {
pathnames[index-1] = strnew("");
continue;
}
FSSpec fsspec;
if (AEGetDescData(&desc, &fsspec, sizeof(FSSpec)) != noErr ) {
pathnames[index-1] = strnew("");
continue;
}
char s[4096];
FSSpecToPath(fsspec, s, sizeof(s)-1);
pathnames[index-1] = strnew(s);
AEDisposeDesc(&desc);
}
return(0);
}
// FREE PATHNAMES ARRAY, IF IT HAS ANY CONTENTS
void FNFC_CLASS::clear_pathnames() {
if ( _pathnames ) {
while ( --_tpathnames >= 0 ) {
_pathnames[_tpathnames] = strfree(_pathnames[_tpathnames]);
}
delete [] _pathnames;
_pathnames = NULL;
}
_tpathnames = 0;
}
// SET A SINGLE PATHNAME
void FNFC_CLASS::set_single_pathname(const char *s) {
clear_pathnames();
_pathnames = new char*[1];
_pathnames[0] = strnew(s);
_tpathnames = 1;
}
// GET THE 'Save As' FILENAME
// Returns -1 on error, errmsg() has reason, filename == "".
// 0 if OK, filename() has filename chosen.
//
int FNFC_CLASS::get_saveas_basename(NavDialogRef& ref) {
if ( ref == NULL ) {
errmsg("get_saveas_basename: ref is NULL");
return(-1);
}
NavReply reply;
OSStatus err;
if ((err = reply.get_reply(ref)) != noErr ) {
errmsg("NavReply::get_reply() failed");
clear_pathnames();
return(-1);
}
char pathname[4096] = "";
// Directory name..
// -2 leaves room to append '/'
//
if ( reply.get_dirname(pathname, sizeof(pathname)-2) < 0 ) {
clear_pathnames();
errmsg("NavReply::get_dirname() failed");
return(-1);
}
// Append '/'
int len = strlen(pathname);
pathname[len++] = '/';
pathname[len] = '\0';
// Basename..
if ( reply.get_saveas_basename(pathname+len, sizeof(pathname)-len) < 0 ) {
clear_pathnames();
errmsg("NavReply::get_saveas_basename() failed");
return(-1);
}
set_single_pathname(pathname);
return(0);
}
// GET (POTENTIALLY) MULTIPLE FILENAMES
// Returns:
// -1 -- error, errmsg() has reason, filename == ""
// 0 -- OK, pathnames()/filename() has pathname(s) chosen
//
int FNFC_CLASS::get_pathnames(NavDialogRef& ref) {
if ( ref == NULL ) {
errmsg("get_saveas_basename: ref is NULL");
return(-1);
}
NavReply reply;
OSStatus err;
if ((err = reply.get_reply(ref)) != noErr ) {
errmsg("NavReply::get_reply() failed");
clear_pathnames();
return(-1);
}
// First, clear pathnames array of any previous contents
clear_pathnames();
if ( reply.get_pathnames(_pathnames, _tpathnames) < 0 ) {
clear_pathnames();
errmsg("NavReply::get_dirname() failed");
return(-1);
}
return(0);
}
// NAV CALLBACK EVENT HANDLER
void FNFC_CLASS::event_handler(
NavEventCallbackMessage callBackSelector,
NavCBRecPtr cbparm,
void *data) {
OSStatus err;
FNFC_CLASS *nfb = (FNFC_CLASS*)data;
switch (callBackSelector) {
case kNavCBStart:
if ( nfb->directory() || nfb->preset_file() ) {
const char *pathname = nfb->directory()
? nfb->directory()
: nfb->preset_file();
FSSpec spec;
if ( ( err = PathToFSSpec(pathname, spec) ) != noErr ) {
fprintf(stderr, "PathToFSSpec(%s) failed: err=%d\n",
pathname, (int)err);
break;
}
AEDesc desc;
if ((err = AECreateDesc(typeFSS, &spec, sizeof(FSSpec),
&desc)) != noErr) {
fprintf(stderr, "AECreateDesc() failed: err=%d\n",
(int)err);
}
if ((err = NavCustomControl(cbparm->context,
kNavCtlSetLocation,
&desc)) != noErr) {
fprintf(stderr, "NavCustomControl() failed: err=%d\n",
(int)err);
}
AEDisposeDesc(&desc);
}
if ( nfb->_btype == BROWSE_SAVE_FILE && nfb->preset_file() ) {
CFStringRef namestr =
CFStringCreateWithCString(NULL,
nfb->preset_file(),
kCFStringEncodingASCII);
NavDialogSetSaveFileName(cbparm->context, namestr);
CFRelease(namestr);
}
NavCustomControl(cbparm->context,
kNavCtlSetActionState,
&nfb->_keepstate );
// Select the right filter in pop-up menu
if ( nfb->_filt_value == nfb->_filt_total ) {
// Select All Documents
NavPopupMenuItem kAll = kNavAllFiles;
NavCustomControl(cbparm->context, kNavCtlSelectAllType, &kAll);
} else if (nfb->_filt_value < nfb->_filt_total) {
// Select custom filter
nfb->_tempitem.version = kNavMenuItemSpecVersion;
nfb->_tempitem.menuCreator = 'extn';
nfb->_tempitem.menuType = nfb->_filt_value;
*nfb->_tempitem.menuItemName = '\0'; // needed on 10.3+
NavCustomControl(cbparm->context,
kNavCtlSelectCustomType,
&(nfb->_tempitem));
}
break;
case kNavCBPopupMenuSelect:
NavMenuItemSpecPtr ptr;
// they really buried this one!
ptr = (NavMenuItemSpecPtr)cbparm->eventData.eventDataParms.param;
if ( ptr->menuCreator ) {
// Gets index to filter ( menuCreator = 'extn' )
nfb->_filt_value = ptr->menuType;
} else {
// All docs filter selected ( menuCreator = '\0\0\0\0' )
nfb->_filt_value = nfb->_filt_total;
}
break;
case kNavCBSelectEntry:
NavActionState astate;
switch ( nfb->_btype ) {
// these don't need selection override
case BROWSE_MULTI_FILE:
case BROWSE_MULTI_DIRECTORY:
case BROWSE_SAVE_FILE:
break;
// These need to allow only one item, so disable
// Open button if user tries to select multiple files
case BROWSE_SAVE_DIRECTORY:
case BROWSE_DIRECTORY:
case BROWSE_FILE:
SInt32 selectcount;
AECountItems((AEDescList*)cbparm->
eventData.eventDataParms.param,
&selectcount);
if ( selectcount > 1 ) {
NavCustomControl(cbparm->context,
kNavCtlSetSelection,
NULL);
astate = nfb->_keepstate |
kNavDontOpenState |
kNavDontChooseState;
NavCustomControl(cbparm->context,
kNavCtlSetActionState,
&astate );
}
else {
astate= nfb->_keepstate | kNavNormalState;
NavCustomControl(cbparm->context,
kNavCtlSetActionState,
&astate );
}
break;
}
break;
}
}
// CONSTRUCTOR
FNFC_CLASS::FNFC_CTOR(int val) {
_btype = val;
NavGetDefaultDialogCreationOptions(&_opts);
_opts.optionFlags |= kNavDontConfirmReplacement; // no confirms for "save as"
_options = NO_OPTIONS;
_ref = NULL;
memset(&_tempitem, 0, sizeof(_tempitem));
_pathnames = NULL;
_tpathnames = 0;
_title = NULL;
_filter = NULL;
_filt_names = NULL;
memset(_filt_patt, 0, sizeof(char*) * MAXFILTERS);
_filt_total = 0;
_filt_value = 0;
_directory = NULL;
_preset_file = NULL;
_errmsg = NULL;
_keepstate = kNavNormalState;
}
// DESTRUCTOR
FNFC_CLASS::~FNFC_CTOR() {
// _opts // nothing to manage
if (_ref) { NavDialogDispose(_ref); _ref = NULL; }
// _options // nothing to manage
// _keepstate // nothing to manage
// _tempitem // nothing to manage
clear_pathnames();
_directory = strfree(_directory);
_title = strfree(_title);
_preset_file = strfree(_preset_file);
_filter = strfree(_filter);
//_filt_names // managed by clear_filters()
//_filt_patt[i] // managed by clear_filters()
//_filt_total // managed by clear_filters()
clear_filters();
//_filt_value // nothing to manage
_errmsg = strfree(_errmsg);
}
// SET THE TYPE OF BROWSER
void FNFC_CLASS::type(int val) {
_btype = val;
}
// GET TYPE OF BROWSER
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 THE BROWSER WINDOW
// Returns:
// 0 - user picked a file
// 1 - user cancelled
// -1 - failed; errmsg() has reason
//
int FNFC_CLASS::show() {
// Make sure fltk interface updates before posting our dialog
#ifdef FLTK1
Fl::flush();
#else
fltk::flush();
#endif
// BROWSER TITLE
CFStringRef cfs_title;
cfs_title = CFStringCreateWithCString(NULL,
_title ? _title : "No Title",
kCFStringEncodingASCII);
_opts.windowTitle = cfs_title;
_keepstate = kNavNormalState;
// BROWSER FILTERS
CFArrayRef filter_array = NULL;
{
// One or more filters specified?
if ( _filt_total ) {
// NAMES -> CFArrayRef
CFStringRef tab = CFSTR("\t");
CFStringRef tmp_cfs;
tmp_cfs = CFStringCreateWithCString(NULL, _filt_names,
kCFStringEncodingASCII);
filter_array = CFStringCreateArrayBySeparatingStrings(
NULL, tmp_cfs, tab);
CFRelease(tmp_cfs);
CFRelease(tab);
_opts.popupExtension = filter_array;
_opts.optionFlags |= kNavAllFilesInPopup;
} else {
filter_array = NULL;
_opts.popupExtension = NULL;
_opts.optionFlags |= kNavAllFilesInPopup;
}
}
// HANDLE OPTIONS WE SUPPORT
if ( _options & SAVEAS_CONFIRM ) {
_opts.optionFlags &= ~kNavDontConfirmReplacement; // enables confirm
} else {
_opts.optionFlags |= kNavDontConfirmReplacement; // disables confirm
}
// POST BROWSER
int err = post();
// RELEASE _FILT_ARR
if ( filter_array ) CFRelease(filter_array);
filter_array = NULL;
_opts.popupExtension = NULL;
_filt_total = 0;
// RELEASE TITLE
if ( cfs_title ) CFRelease(cfs_title);
cfs_title = NULL;
return(err);
}
// POST BROWSER
// Internal use only.
// Assumes '_opts' has been initialized.
//
// Returns:
// 0 - user picked a file
// 1 - user cancelled
// -1 - failed; errmsg() has reason
//
int FNFC_CLASS::post() {
// INITIALIZE BROWSER
OSStatus err;
if ( _filt_total == 0 ) { // Make sure they match
_filt_value = 0; // TBD: move to someplace more logical?
}
switch (_btype) {
case BROWSE_FILE:
case BROWSE_MULTI_FILE:
//_keepstate = kNavDontNewFolderState;
// Prompt user for one or more files
if ((err = NavCreateGetFileDialog(
&_opts, // options
0, // file types
event_handler, // event handler
0, // preview callback
filter_proc_cb, // filter callback
(void*)this, // callback data
&_ref)) != noErr ) { // dialog ref
errmsg("NavCreateGetFileDialog: failed");
return(-1);
}
break;
case BROWSE_DIRECTORY:
case BROWSE_MULTI_DIRECTORY:
_keepstate = kNavDontNewFolderState;
//FALLTHROUGH
case BROWSE_SAVE_DIRECTORY:
// Prompts user for one or more files or folders
if ((err = NavCreateChooseFolderDialog(
&_opts, // options
event_handler, // event callback
0, // filter callback
(void*)this, // callback data
&_ref)) != noErr ) { // dialog ref
errmsg("NavCreateChooseFolderDialog: failed");
return(-1);
}
break;
case BROWSE_SAVE_FILE:
// Prompt user for filename to 'save as'
if ((err = NavCreatePutFileDialog(
&_opts, // options
0, // file types
0, // file creator
event_handler, // event handler
(void*)this, // callback data
&_ref)) != noErr ) { // dialog ref
errmsg("NavCreatePutFileDialog: failed");
return(-1);
}
break;
}
// SHOW THE DIALOG
if ( ( err = NavDialogRun(_ref) ) != 0 ) {
char msg[80];
sprintf(msg, "NavDialogRun: failed (err=%d)", (int)err);
errmsg(msg);
return(-1);
}
// WHAT ACTION DID USER CHOOSE?
NavUserAction act = NavDialogGetUserAction(_ref);
if ( act == kNavUserActionNone ) {
errmsg("Nothing happened yet (dialog still open)");
return(-1);
}
else if ( act == kNavUserActionCancel ) { // user chose 'cancel'
return(1);
}
else if ( act == kNavUserActionSaveAs ) { // user chose 'save as'
return(get_saveas_basename(_ref));
}
// TOO MANY FILES CHOSEN?
int ret = get_pathnames(_ref);
if ( _btype == BROWSE_FILE && ret == 0 && _tpathnames != 1 ) {
char msg[80];
sprintf(msg, "Expected only one file to be chosen.. you chose %d.",
(int)_tpathnames);
errmsg(msg);
return(-1);
}
return(err);
}
// SET ERROR MESSAGE
// Internal use only.
//
void FNFC_CLASS::errmsg(const char *msg) {
_errmsg = strfree(_errmsg);
_errmsg = strnew(msg);
}
// RETURN ERROR MESSAGE
const char *FNFC_CLASS::errmsg() const {
return(_errmsg ? _errmsg : "No error");
}
// GET FILENAME
const char* FNFC_CLASS::filename() const {
if ( _pathnames && _tpathnames > 0 ) return(_pathnames[0]);
return("");
}
// GET FILENAME FROM LIST OF FILENAMES
const char* FNFC_CLASS::filename(int i) const {
if ( _pathnames && i < _tpathnames ) return(_pathnames[i]);
return("");
}
// GET TOTAL FILENAMES CHOSEN
int FNFC_CLASS::count() const {
return(_tpathnames);
}
// PRESET PATHNAME
// Value can be NULL for none.
//
void FNFC_CLASS::directory(const char *val) {
_directory = strfree(_directory);
_directory = strnew(val);
}
// GET PRESET PATHNAME
// Returned value can be NULL if none set.
//
const char* FNFC_CLASS::directory() const {
return(_directory);
}
// SET TITLE
// Value can be NULL if no title desired.
//
void FNFC_CLASS::title(const char *val) {
_title = strfree(_title);
_title = strnew(val);
}
// GET TITLE
// Returned value can be NULL if none set.
//
const char *FNFC_CLASS::title() const {
return(_title);
}
// SET FILTER
// Can be NULL if no filter needed
//
void FNFC_CLASS::filter(const char *val) {
_filter = strfree(_filter);
_filter = strnew(val);
// Parse filter user specified
// IN: _filter = "C Files\t*.{cxx,h}\nText Files\t*.txt"
// OUT: _filt_names = "C Files\tText Files"
// _filt_patt[0] = "*.{cxx,h}"
// _filt_patt[1] = "*.txt"
// _filt_total = 2
//
parse_filter(_filter);
}
// GET FILTER
// Returned value can be NULL if none set.
//
const char *FNFC_CLASS::filter() const {
return(_filter);
}
// CLEAR ALL FILTERS
// Internal use only.
//
void FNFC_CLASS::clear_filters() {
_filt_names = strfree(_filt_names);
for (int i=0; i<_filt_total; i++) {
_filt_patt[i] = strfree(_filt_patt[i]);
}
_filt_total = 0;
}
// PARSE USER'S FILTER SPEC
// Parses user specified filter ('in'),
// breaks out into _filt_patt[], _filt_names, and _filt_total.
//
// Handles:
// IN: OUT:_filt_names OUT: _filt_patt
// ------------------------------------ ------------------ ---------------
// "*.{ma,mb}" "*.{ma,mb} Files" "*.{ma,mb}"
// "*.[abc]" "*.[abc] Files" "*.[abc]"
// "*.txt" "*.txt Files" "*.c"
// "C Files\t*.[ch]" "C Files" "*.[ch]"
// "C Files\t*.[ch]\nText Files\t*.cxx" "C Files" "*.[ch]"
//
// Parsing Mode:
// IN:"C Files\t*.{cxx,h}"
// ||||||| |||||||||
// mode: nnnnnnn wwwwwwwww
// \_____/ \_______/
// Name Wildcard
//
void FNFC_CLASS::parse_filter(const char *in) {
clear_filters();
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':
// TITLE
// If user didn't specify a name, make one
//
if ( name[0] == '\0' ) {
sprintf(name, "%.*s Files", (int)sizeof(name)-10, wildcard);
}
// APPEND NEW FILTER TO LIST
if ( wildcard[0] ) {
// Add to filtername list
// Tab delimit if more than one. We later break
// tab delimited string into CFArray with
// CFStringCreateArrayBySeparatingStrings()
//
if ( _filt_total ) {
_filt_names = strapp(_filt_names, "\t");
}
_filt_names = strapp(_filt_names, name);
// Add filter to the pattern array
_filt_patt[_filt_total++] = strnew(wildcard);
}
// 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
}
// STATIC: FILTER CALLBACK
Boolean FNFC_CLASS::filter_proc_cb(AEDesc *theItem,
void *info,
void *callBackUD,
NavFilterModes filterMode) {
return((FNFC_CLASS*)callBackUD)->filter_proc_cb2(
theItem, info, callBackUD, filterMode);
}
// FILTER CALLBACK
// Return true if match,
// false if no match.
//
Boolean FNFC_CLASS::filter_proc_cb2(AEDesc *theItem,
void *info,
void *callBackUD,
NavFilterModes filterMode) {
// All files chosen or no filters
if ( _filt_value == _filt_total ) return(true);
FSSpec fsspec;
char pathname[4096];
// On fail, filter should return true by default
if ( AEDescToFSSpec(theItem, &fsspec) != noErr ) {
return(true);
}
FSSpecToPath(fsspec, pathname, sizeof(pathname)-1);
if ( fl_filename_isdir(pathname) ) return(true);
if ( fl_filename_match(pathname, _filt_patt[_filt_value]) ) return(true);
else return(false);
}
// SET PRESET FILE
// Value can be NULL for none.
//
void FNFC_CLASS::preset_file(const char* val) {
_preset_file = strfree(_preset_file);
_preset_file = strnew(val);
}
// PRESET FILE
// Returned value can be NULL if none set.
//
const char* FNFC_CLASS::preset_file() {
return(_preset_file);
}

Wyświetl plik

@ -0,0 +1,803 @@
//
// Fl_Native_File_Chooser_WIN32.cxx -- FLTK native OS file chooser widget
//
// Copyright 2004 by Greg Ercolano.
// API changes + filter improvements by Nathan Vander Wilt 2005
// FLTK2/WIN32 port 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please keep code 80 column compliant.
//
// 10 20 30 40 50 60 70
// | | | | | | |
// 4567890123456789012345678901234567890123456789012345678901234567890123456789
//
// Any application to multi-folder implementation:
// http://www.codeproject.com/dialog/selectfolder.asp
//
#include <stdio.h> // debugging
#include "flnfc_common.cxx" // strnew/strfree/strapp/chrcat
#define FLTK1
#ifdef FLTK1
//
// FLTK1
//
#include <FL/Fl_Native_File_Chooser.H>
#define FNFC_CLASS Fl_Native_File_Chooser
#define FNFC_CTOR Fl_Native_File_Chooser
#else
//
// FLTK2
//
#include <fltk/NativeFileChooser.h>
#include <fltk/run.h>
#define FNFC_CTOR NativeFileChooser
#define FNFC_CLASS fltk::FNFC_CTOR
#endif
#define LCURLY_CHR '{'
#define RCURLY_CHR '}'
#define LBRACKET_CHR '['
#define RBRACKET_CHR ']'
#define MAXFILTERS 80
// STATIC: PRINT WINDOWS 'DOUBLE NULL' STRING (DEBUG)
static void dnullprint(char *wp) {
if ( ! wp ) return;
for ( int t=0; true; t++ ) {
if ( wp[t] == '\0' && wp[t+1] == '\0' ) {
printf("\\0\\0");
fflush(stdout);
return;
} else if ( wp[t] == '\0' ) {
printf("\\0");
} else {
printf("%c",wp[t]);
}
}
}
// RETURN LENGTH OF DOUBLENULL STRING
// Includes single nulls in count, excludes trailing doublenull.
//
// 1234 567
// |||/\|||
// IN: "one\0two\0\0"
// OUT: 7
//
static int dnulllen(const char *wp) {
int len = 0;
while ( ! ( *(wp+0) == 0 && *(wp+1) == 0 ) )
{ ++wp; ++len; }
return(len);
}
// STATIC: Append a string to another, leaving terminated with DOUBLE NULL.
// Automatically handles extending length of string.
// wp can be NULL (a new wp will be allocated and initialized).
// string must be NULL terminated.
// The pointer wp may be modified on return.
//
static void dnullcat(char*&wp, const char *string, int n = -1 ) {
//DEBUG printf("DEBUG: dnullcat IN: <"); dnullprint(wp); printf(">\n");
int inlen = ( n < 0 ) ? strlen(string) : n;
if ( ! wp ) {
wp = new char[inlen + 4];
*(wp+0) = '\0';
*(wp+1) = '\0';
} else {
int wplen = dnulllen(wp);
// Make copy of wp into larger buffer
char *tmp = new char[wplen + inlen + 4];
memcpy(tmp, wp, wplen+2); // copy of wp plus doublenull
delete [] wp; // delete old wp
wp = tmp; // use new copy
//DEBUG printf("DEBUG: dnullcat COPY: <"); dnullprint(wp); printf("> (wplen=%d)\n", wplen);
}
// Find end of double null string
// *wp2 is left pointing at second null.
//
char *wp2 = wp;
if ( *(wp2+0) != '\0' && *(wp2+1) != '\0' ) {
for ( ; 1; wp2++ )
if ( *(wp2+0) == '\0' && *(wp2+1) == '\0' )
{ wp2++; break; }
}
if ( n == -1 ) n = strlen(string);
strncpy(wp2, string, n);
// Leave string double-null terminated
*(wp2+n+0) = '\0';
*(wp2+n+1) = '\0';
//DEBUG printf("DEBUG: dnullcat OUT: <"); dnullprint(wp); printf(">\n\n");
}
// CTOR
FNFC_CLASS::FNFC_CTOR(int val) {
_btype = val;
_options = NO_OPTIONS;
memset((void*)&_ofn, 0, sizeof(OPENFILENAME));
_ofn.lStructSize = sizeof(OPENFILENAME);
_ofn.hwndOwner = NULL;
memset((void*)&_binf, 0, sizeof(BROWSEINFO));
_pathnames = NULL;
_tpathnames = 0;
_directory = NULL;
_title = NULL;
_filter = NULL;
_parsedfilt = NULL;
_nfilters = 0;
_preset_file = NULL;
_errmsg = NULL;
}
// DTOR
FNFC_CLASS::~FNFC_CTOR() {
//_pathnames // managed by clear_pathnames()
//_tpathnames // managed by clear_pathnames()
_directory = strfree(_directory);
_title = strfree(_title);
_filter = strfree(_filter);
//_parsedfilt // managed by clear_filters()
//_nfilters // managed by clear_filters()
_preset_file = strfree(_preset_file);
_errmsg = strfree(_errmsg);
clear_filters();
clear_pathnames();
ClearOFN();
ClearBINF();
}
// SET TYPE OF BROWSER
void FNFC_CLASS::type(int val) {
_btype = val;
}
// GET TYPE OF BROWSER
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);
}
// PRIVATE: SET ERROR MESSAGE
void FNFC_CLASS::errmsg(const char *val) {
_errmsg = strfree(_errmsg);
_errmsg = strnew(val);
}
// FREE PATHNAMES ARRAY, IF IT HAS ANY CONTENTS
void FNFC_CLASS::clear_pathnames() {
if ( _pathnames ) {
while ( --_tpathnames >= 0 ) {
_pathnames[_tpathnames] = strfree(_pathnames[_tpathnames]);
}
delete [] _pathnames;
_pathnames = NULL;
}
_tpathnames = 0;
}
// SET A SINGLE PATHNAME
void FNFC_CLASS::set_single_pathname(const char *s) {
clear_pathnames();
_pathnames = new char*[1];
_pathnames[0] = strnew(s);
_tpathnames = 1;
}
// ADD PATHNAME TO EXISTING ARRAY
void FNFC_CLASS::add_pathname(const char *s) {
if ( ! _pathnames ) {
// Create first element in array
++_tpathnames;
_pathnames = new char*[_tpathnames];
} else {
// Grow array by 1
char **tmp = new char*[_tpathnames+1]; // create new buffer
memcpy((void*)tmp, (void*)_pathnames,
sizeof(char*)*_tpathnames); // copy old
delete [] _pathnames; // delete old
_pathnames = tmp; // use new
++_tpathnames;
}
_pathnames[_tpathnames-1] = strnew(s);
}
// FREE A PIDL (Pointer to IDentity List)
void FNFC_CLASS::FreePIDL(ITEMIDLIST *pidl) {
IMalloc *imalloc = NULL;
if ( SUCCEEDED(SHGetMalloc(&imalloc)) )
{ imalloc->Free(pidl); imalloc->Release(); imalloc = NULL; }
}
// CLEAR MICROSOFT OFN (OPEN FILE NAME) CLASS
void FNFC_CLASS::ClearOFN() {
// Free any previously allocated lpstrFile before zeroing out _ofn
if ( _ofn.lpstrFile ) {
_ofn.lpstrFile = strfree((char*)_ofn.lpstrFile);
}
if ( _ofn.lpstrInitialDir ) {
_ofn.lpstrInitialDir = (LPCSTR)strfree((char*)_ofn.lpstrInitialDir);
}
_ofn.lpstrFilter = NULL; // (deleted elsewhere)
int temp = _ofn.nFilterIndex; // keep the filter_value
memset((void*)&_ofn, 0, sizeof(_ofn));
_ofn.lStructSize = sizeof(OPENFILENAME);
_ofn.nFilterIndex = temp;
}
// CLEAR MICROSOFT BINF (BROWSER INFO) CLASS
void FNFC_CLASS::ClearBINF() {
if ( _binf.pidlRoot ) {
FreePIDL((ITEMIDLIST*)_binf.pidlRoot);
_binf.pidlRoot = NULL;
}
memset((void*)&_binf, 0, sizeof(_binf));
}
// CONVERT WINDOWS BACKSLASHES TO UNIX FRONTSLASHES
void FNFC_CLASS::Win2Unix(char *s) {
for ( ; *s; s++ )
if ( *s == '\\' ) *s = '/';
}
// CONVERT UNIX FRONTSLASHES TO WINDOWS BACKSLASHES
void FNFC_CLASS::Unix2Win(char *s) {
for ( ; *s; s++ )
if ( *s == '/' ) *s = '\\';
}
// SHOW FILE BROWSER
int FNFC_CLASS::showfile() {
ClearOFN();
clear_pathnames();
size_t fsize = 2048;
_ofn.Flags |= OFN_NOVALIDATE; // prevent disabling of front slashes
_ofn.Flags |= OFN_HIDEREADONLY; // hide goofy readonly flag
// USE NEW BROWSER
_ofn.Flags |= OFN_EXPLORER; // use newer explorer windows
_ofn.Flags |= OFN_ENABLESIZING; // allow window to be resized (hey, why not?)
// XXX: The docs for OFN_NOCHANGEDIR says the flag is 'ineffective' on XP/2K/NT!
// But let's set it anyway..
//
_ofn.Flags |= OFN_NOCHANGEDIR; // prevent dialog for messing up the cwd
switch ( _btype ) {
case BROWSE_DIRECTORY:
case BROWSE_MULTI_DIRECTORY:
case BROWSE_SAVE_DIRECTORY:
abort(); // never happens: handled by showdir()
case BROWSE_FILE:
fsize = 65536; // XXX: there must be a better way
break;
case BROWSE_MULTI_FILE:
_ofn.Flags |= OFN_ALLOWMULTISELECT;
fsize = 65536; // XXX: there must be a better way
break;
case BROWSE_SAVE_FILE:
if ( options() & SAVEAS_CONFIRM && type() == BROWSE_SAVE_FILE ) {
_ofn.Flags |= OFN_OVERWRITEPROMPT;
}
break;
}
// SPACE FOR RETURNED FILENAME
_ofn.lpstrFile = new char[fsize];
_ofn.nMaxFile = fsize-1;
_ofn.lpstrFile[0] = '\0';
_ofn.lpstrFile[1] = '\0'; // dnull
// PARENT WINDOW
_ofn.hwndOwner = GetForegroundWindow();
// DIALOG TITLE
_ofn.lpstrTitle = _title ? _title : NULL;
// FILTER
_ofn.lpstrFilter = _parsedfilt ? _parsedfilt : NULL;
// PRESET FILE
// If set, supercedes _directory. See KB Q86920 for details
//
if ( _preset_file ) {
size_t len = strlen(_preset_file);
if ( len >= _ofn.nMaxFile ) {
char msg[80];
sprintf(msg, "preset_file() filename is too long: %ld is >=%ld",
(long)len, (long)fsize);
return(-1);
}
strncpy(_ofn.lpstrFile, _preset_file, _ofn.nMaxFile);
Unix2Win(_ofn.lpstrFile);
_ofn.lpstrFile[len+0] = 0; // multiselect needs dnull
_ofn.lpstrFile[len+1] = 0;
}
if ( _directory ) {
// PRESET DIR
// XXX: See KB Q86920 for doc bug:
// http://support.microsoft.com/default.aspx?scid=kb;en-us;86920
//
_ofn.lpstrInitialDir = strnew(_directory);
Unix2Win((char*)_ofn.lpstrInitialDir);
}
// SAVE THE CURRENT DIRECTORY
// XXX: Save the cwd because GetOpenFileName() is probably going to
// change it, in spite of the OFN_NOCHANGEDIR flag, due to its docs
// saying the flag is 'ineffective'. %^(
//
char oldcwd[MAX_PATH];
GetCurrentDirectory(MAX_PATH, oldcwd);
oldcwd[MAX_PATH-1] = '\0';
// OPEN THE DIALOG WINDOW
int err;
if ( _btype == BROWSE_SAVE_FILE ) {
err = GetSaveFileName(&_ofn);
} else {
err = GetOpenFileName(&_ofn);
}
if ( err == 0 ) {
// EXTENDED ERROR CHECK
int err = CommDlgExtendedError();
// CANCEL?
if ( err == 0 )
return(1); // user hit 'cancel'
// AN ERROR OCCURRED
char msg[80];
sprintf(msg, "CommDlgExtendedError() code=%d", err);
errmsg(msg);
// XXX: RESTORE CWD
if ( oldcwd[0] ) SetCurrentDirectory(oldcwd);
return(-1);
}
// XXX: RESTORE CWD
if ( oldcwd[0] ) {
SetCurrentDirectory(oldcwd);
}
// PREPARE PATHNAMES FOR RETURN
switch ( _btype ) {
case BROWSE_FILE:
case BROWSE_SAVE_FILE:
set_single_pathname(_ofn.lpstrFile);
Win2Unix(_pathnames[_tpathnames-1]);
break;
case BROWSE_MULTI_FILE: {
// EXTRACT MULTIPLE FILENAMES
const char *dirname = _ofn.lpstrFile;
int dirlen = strlen(dirname);
if ( dirlen > 0 ) {
// WALK STRING SEARCHING FOR 'DOUBLE-NULL'
// eg. "/dir/name\0foo1\0foo2\0foo3\0\0"
//
char pathname[2048];
for ( const char *s = _ofn.lpstrFile + dirlen + 1;
*s; s+= (strlen(s)+1)) {
strcpy(pathname, dirname);
strcat(pathname, "\\");
strcat(pathname, s);
add_pathname(pathname);
Win2Unix(_pathnames[_tpathnames-1]);
}
}
// XXX
// Work around problem where pasted forward-slash pathname
// into the file browser causes new "Explorer" interface
// not to grok forward slashes, passing back as a 'filename'..!
//
if ( _tpathnames == 0 ) {
add_pathname(dirname);
Win2Unix(_pathnames[_tpathnames-1]);
}
break;
}
case BROWSE_DIRECTORY:
case BROWSE_MULTI_DIRECTORY:
case BROWSE_SAVE_DIRECTORY:
abort(); // never happens: handled by showdir()
}
return(0);
}
// Used by SHBrowseForFolder(), sets initial selected dir.
// Ref: Usenet: microsoft.public.vc.mfc, Dec 8 2000, 1:38p David Lowndes
// Subject: How to specify to select an initial folder .."
//
int CALLBACK FNFC_CLASS::Dir_CB(HWND win, UINT msg,
LPARAM param, LPARAM data) {
switch (msg) {
case BFFM_INITIALIZED:
if (data) ::SendMessage(win, BFFM_SETSELECTION, TRUE, data);
break;
case BFFM_SELCHANGED:
TCHAR path[MAX_PATH];
if ( SHGetPathFromIDList((ITEMIDLIST*)param, path) ) {
::SendMessage(win, BFFM_ENABLEOK, 0, 1);
} else {
//disable ok button if not a path
::SendMessage(win, BFFM_ENABLEOK, 0, 0);
}
break;
case BFFM_VALIDATEFAILED:
// we could pop up an annoying message here.
// also needs set ulFlags |= BIF_VALIDATE
break;
default:
break;
}
return(0);
}
// SHOW DIRECTORY BROWSER
int FNFC_CLASS::showdir() {
OleInitialize(NULL); // init needed by BIF_USENEWUI
ClearBINF();
clear_pathnames();
// PARENT WINDOW
_binf.hwndOwner = GetForegroundWindow();
// DIALOG TITLE
_binf.lpszTitle = _title ? _title : NULL;
// FLAGS
_binf.ulFlags = 0; // initialize
// TBD: make sure matches to runtime system, if need be.
//( what if _WIN32_IE doesn't match system? does the program not run? )
// TBD: match all 3 types of directories
#if defined(BIF_NONEWFOLDERBUTTON) // Version 6.0
if ( _btype == BROWSE_DIRECTORY ) _binf.ulFlags |= BIF_NONEWFOLDERBUTTON;
_binf.ulFlags |= BIF_USENEWUI | BIF_SHAREABLE | BIF_RETURNONLYFSDIRS;
#elif defined(BIF_USENEWUI) // Version 5.0
if ( _btype == BROWSE_DIRECTORY ) _binf.ulFlags |= BIF_EDITBOX;
else if ( _btype == BROWSE_SAVE_DIRECTORY ) _binf.ulFlags |= BIF_USENEWUI;
_binf.ulFlags |= BIF_SHAREABLE | BIF_RETURNONLYFSDIRS;
#elif defined(BIF_EDITBOX) // Version 4.71
_binf.ulFlags |= BIF_RETURNONLYFSDIRS | BIF_EDITBOX;
#else // Version Old
_binf.ulFlags |= BIF_RETURNONLYFSDIRS;
#endif
// BUFFER
char displayname[MAX_PATH];
_binf.pszDisplayName = displayname;
// PRESET DIR
char presetname[MAX_PATH];
if ( _directory ) {
strcpy(presetname, _directory);
Unix2Win(presetname);
_binf.lParam = (LPARAM)presetname;
}
else _binf.lParam = 0;
_binf.lpfn = Dir_CB;
// OPEN BROWSER
ITEMIDLIST *pidl = SHBrowseForFolder(&_binf);
// CANCEL?
if ( pidl == NULL ) return(1);
// GET THE PATHNAME(S) THE USER SELECTED
// TBD: expand NetHood shortcuts from this PIDL??
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shbrowseforfolder.asp
TCHAR path[MAX_PATH];
if ( SHGetPathFromIDList(pidl, path) ) {
Win2Unix(path);
add_pathname(path);
}
FreePIDL(pidl);
if ( !strlen(path) ) return(1); // don't return empty pathnames
return(0);
}
// RETURNS:
// 0 - user picked a file
// 1 - user cancelled
// -1 - failed; errmsg() has reason
//
int FNFC_CLASS::show() {
if ( _btype == BROWSE_DIRECTORY ||
_btype == BROWSE_MULTI_DIRECTORY ||
_btype == BROWSE_SAVE_DIRECTORY ) {
return(showdir());
} else {
return(showfile());
}
}
// RETURN ERROR MESSAGE
const char *FNFC_CLASS::errmsg() const {
return(_errmsg ? _errmsg : "No error");
}
// GET FILENAME
const char* FNFC_CLASS::filename() const {
if ( _pathnames && _tpathnames > 0 ) return(_pathnames[0]);
return("");
}
// GET FILENAME FROM LIST OF FILENAMES
const char* FNFC_CLASS::filename(int i) const {
if ( _pathnames && i < _tpathnames ) return(_pathnames[i]);
return("");
}
// GET TOTAL FILENAMES CHOSEN
int FNFC_CLASS::count() const {
return(_tpathnames);
}
// 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);
}
// SET TITLE
// Can be NULL if no title desired.
//
void FNFC_CLASS::title(const char *val) {
_title = strfree(_title);
_title = strnew(val);
}
// GET TITLE
// Can return NULL if none set.
//
const char *FNFC_CLASS::title() const {
return(_title);
}
// SET FILTER
// Can be NULL if no filter needed
//
void FNFC_CLASS::filter(const char *val) {
_filter = strfree(_filter);
clear_filters();
if ( val ) {
_filter = strnew(val);
parse_filter(_filter);
}
add_filter("All Files", "*.*"); // always include 'all files' option
#ifdef DEBUG
nullprint(_parsedfilt);
#endif /*DEBUG*/
}
// GET FILTER
// Can return NULL if none set.
//
const char *FNFC_CLASS::filter() const {
return(_filter);
}
// CLEAR FILTERS
void FNFC_CLASS::clear_filters() {
_nfilters = 0;
_parsedfilt = strfree(_parsedfilt);
}
// ADD A FILTER
void FNFC_CLASS::add_filter(
const char *name_in, // name of filter (optional: can be null)
const char *winfilter // windows style filter (eg. "*.cxx;*.h")
) {
// No name? Make one..
char name[1024];
if ( !name_in || name_in[0] == '\0' ) {
sprintf(name, "%.*s Files", sizeof(name)-10, winfilter);
} else {
sprintf(name, "%.*s", sizeof(name)-10, name_in);
}
dnullcat(_parsedfilt, name);
dnullcat(_parsedfilt, winfilter);
_nfilters++;
//DEBUG printf("DEBUG: ADD FILTER name=<%s> winfilter=<%s>\n", name, winfilter);
}
// CONVERT FLTK STYLE PATTERN MATCHES TO WINDOWS 'DOUBLENULL' PATTERN
// Handles:
// IN OUT
// ----------- -----------------------------
// *.{ma,mb} "*.{ma,mb} Files\0*.ma;*.mb\0\0"
// *.[abc] "*.[abc] Files\0*.a;*.b;*.c\0\0"
// *.txt "*.txt Files\0*.txt\0\0"
// C Files\t*.[ch] "C Files\0*.c;*.h\0\0"
//
// Example:
// IN: "*.{ma,mb}"
// OUT: "*.ma;*.mb Files\0*.ma;*.mb\0All Files\0*.*\0\0"
// --------------- --------- --------- ---
// | | | |
// Title Wildcards Title Wildcards
//
// Parsing Mode:
// IN:"C Files\t*.{cxx,h}"
// ||||||| |||||||||
// mode: nnnnnnn ww{{{{{{{
// \_____/ \_______/
// Name Wildcard
//
void FNFC_CLASS::parse_filter(const char *in) {
clear_filters();
if ( ! in ) return;
int has_name = strchr(in, '\t') ? 1 : 0;
char mode = has_name ? 'n' : 'w'; // parse mode: n=name, w=wildcard
int nwildcards = 0;
char wildcards[MAXFILTERS][1024]; // parsed wildcards (can be several)
char wildprefix[512] = "";
char name[512] = "";
// Init
int t;
for ( t=0; t<MAXFILTERS; t++ ) {
wildcards[t][0] = '\0';
}
// Parse
for ( ; 1; in++ ) {
//// DEBUG
//// printf("WORKING ON '%c': mode=<%c> name=<%s> wildprefix=<%s> nwildcards=%d wildcards[n]=<%s>\n",
//// *in, mode, name, wildprefix, nwildcards, wildcards[nwildcards]);
switch (*in) {
case ',':
case '|':
if ( mode == LCURLY_CHR ) {
// create new wildcard, copy in prefix
strcat(wildcards[nwildcards++], wildprefix);
continue;
} else {
goto regchar;
}
continue;
// FINISHED PARSING A NAME?
case '\t':
if ( mode != 'n' ) goto regchar;
// finish parsing name? switch to wildcard mode
mode = 'w';
break;
// ESCAPE NEXT CHAR
case '\\':
++in;
goto regchar;
// FINISHED PARSING ONE OF POSSIBLY SEVERAL FILTERS?
case '\r':
case '\n':
case '\0':
{
if ( mode == 'w' ) { // finished parsing wildcard?
if ( nwildcards == 0 ) {
strcpy(wildcards[nwildcards++], wildprefix);
}
// Append wildcards in Microsoft's "*.one;*.two" format
char comp[4096] = "";
for ( t=0; t<nwildcards; t++ ) {
if ( t != 0 ) strcat(comp, ";");
strcat(comp, wildcards[t]);
}
// Add if not empty
if ( comp[0] ) {
add_filter(name, comp);
}
}
// RESET
for ( t=0; t<MAXFILTERS; t++ ) {
wildcards[t][0] = '\0';
}
nwildcards = 0;
wildprefix[0] = name[0] = '\0';
mode = strchr(in,'\t') ? 'n' : 'w';
// DONE?
if ( *in == '\0' ) return; // done
continue; // not done yet, more filters
}
// STARTING A WILDCARD?
case LBRACKET_CHR:
case LCURLY_CHR:
mode = *in;
if ( *in == LCURLY_CHR ) {
// create new wildcard
strcat(wildcards[nwildcards++], wildprefix);
}
continue;
// ENDING A WILDCARD?
case RBRACKET_CHR:
case RCURLY_CHR:
mode = 'w'; // back to wildcard mode
continue;
// ALL OTHER NON-SPECIAL CHARACTERS
default:
regchar: // handle regular char
switch ( mode ) {
case LBRACKET_CHR:
// create new wildcard
++nwildcards;
// copy in prefix
strcpy(wildcards[nwildcards-1], wildprefix);
// append search char
chrcat(wildcards[nwildcards-1], *in);
continue;
case LCURLY_CHR:
if ( nwildcards > 0 ) {
chrcat(wildcards[nwildcards-1], *in);
}
continue;
case 'n':
chrcat(name, *in);
continue;
case 'w':
chrcat(wildprefix, *in);
for ( t=0; t<nwildcards; t++ ) {
chrcat(wildcards[t], *in);
}
continue;
}
break;
}
}
}
// SET 'CURRENTLY SELECTED FILTER'
void FNFC_CLASS::filter_value(int i) {
_ofn.nFilterIndex = i + 1;
}
// RETURN VALUE OF 'CURRENTLY SELECTED FILTER'
int FNFC_CLASS::filter_value() const {
return(_ofn.nFilterIndex ? _ofn.nFilterIndex-1 : _nfilters+1);
}
// PRESET FILENAME FOR 'SAVE AS' CHOOSER
void FNFC_CLASS::preset_file(const char* val) {
_preset_file = strfree(_preset_file);
_preset_file = strnew(val);
}
// GET PRESET FILENAME FOR 'SAVE AS' CHOOSER
const char* FNFC_CLASS::preset_file() const {
return(_preset_file);
}

Wyświetl plik

@ -1,6 +0,0 @@
#define allfiles_width 16
#define allfiles_height 16
static unsigned char allfiles_bits[] = {
0xfc, 0x3f, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x84, 0x21, 0xa4, 0x25,
0xc4, 0x23, 0xf4, 0x2f, 0xf4, 0x2f, 0xc4, 0x23, 0xa4, 0x25, 0x84, 0x21,
0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0xfc, 0x3f};

Wyświetl plik

@ -1,6 +0,0 @@
#define d1_width 16
#define d1_height 16
static unsigned char d1_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x38, 0x00, 0x78, 0x00,
0xe8, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x17, 0x00, 0x1e, 0x00, 0x1c,
0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

Wyświetl plik

@ -1,6 +0,0 @@
#define d1_mask_width 16
#define d1_mask_height 16
static unsigned char d1_mask_bits[] = {
0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0x7c, 0x00, 0xfc, 0x00,
0xfc, 0x01, 0xec, 0x03, 0xc0, 0x37, 0x80, 0x3f, 0x00, 0x3f, 0x00, 0x3e,
0x00, 0x3f, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00};

Wyświetl plik

@ -1,8 +0,0 @@
#define ew_width 16
#define ew_height 16
#define ew_x_hot 8
#define ew_y_hot 8
static unsigned char ew_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10,
0x0c, 0x30, 0xfe, 0x7f, 0xfe, 0x7f, 0x0c, 0x30, 0x08, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

Wyświetl plik

@ -1,8 +0,0 @@
#define ew_mask_width 16
#define ew_mask_height 16
#define ew_mask_x_hot 8
#define ew_mask_y_hot 8
static unsigned char ew_mask_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x1c, 0x38,
0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0x1c, 0x38, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

Wyświetl plik

@ -1,163 +0,0 @@
//
// "$Id: fl_file_dir.cxx 4288 2005-04-16 00:13:17Z mike $"
//
// File chooser widget for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2005 by Bill Spitzak and others.
//
// 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 <config.h>
#include <FL/filename.H>
#include <FL/fl_ask.H>
#include "File_Selector.h"
#include "FileString.h"
static File_Selector *fc = (File_Selector *)0;
static void (*current_callback)(const char*) = 0;
static const char *current_label = fl_ok;
// Do a file chooser callback...
static void callback(File_Selector *, void*) {
if (current_callback && fc->value())
(*current_callback)(fc->value());
}
// Set the file chooser callback
void File_Selector_callback(void (*cb)(const char*)) {
current_callback = cb;
}
// Set the "OK" button label
void File_Selector_ok_label(const char *l) {
if (l) current_label = l;
else current_label = fl_ok;
}
//
// 'File_Selector()' - Show a file chooser dialog and get a filename.
//
char * // O - Filename or NULL
File_Select(const char *message, // I - Message in titlebar
const char *pat, // I - Filename pattern
const char *fname, // I - Initial filename selection
int relative) { // I - 0 for absolute path
static char retname[1024]; // Returned filename
if (!fc) {
if (!fname || !*fname) fname = ".";
fc = new File_Selector(fname, pat, File_Selector::CREATE, message);
fc->callback(callback, 0);
} else {
fc->type(File_Selector::CREATE);
fc->filter(pat);
fc->label(message);
if (!fname || !*fname) {
if (fc->filter() != pat && (!pat || !fc->filter() ||
strcmp(pat, fc->filter())) && fc->value()) {
// if pattern is different, remove name but leave old directory:
strlcpy(retname, fc->value(), sizeof(retname));
char *p = strrchr(retname, '/');
if (p) {
// If the filename is "/foo", then the directory will be "/", not
// ""...
if (p == retname)
retname[1] = '\0';
else
*p = '\0';
}
// Set the directory...
fc->directory(retname);
}
}
else
fc->value(fname);
}
fc->ok_label(current_label);
fc->show();
while (fc->shown())
Fl::wait();
if (fc->value() && relative) {
fl_filename_relative(retname, sizeof(retname), fc->value());
return retname;
} else if (fc->value()) return (char *)fc->value();
else return 0;
}
//
// 'fl_dir_chooser()' - Show a file chooser dialog and get a directory.
//
char * // O - Directory or NULL
Dir_Chooser(const char *message, // I - Message for titlebar
const char *fname, // I - Initial directory name
int relative) // I - 0 for absolute
{
static char retname[1024]; // Returned directory name
if (!fc) {
if (!fname || !*fname) fname = ".";
fc = new File_Selector(fname, "*", File_Selector::CREATE |
File_Selector::DIRECTORY, message);
fc->callback(callback, 0);
} else {
fc->type(File_Selector::CREATE | File_Selector::DIRECTORY);
fc->filter("*");
if (fname && *fname) fc->value(fname);
fc->label(message);
}
fc->show();
while (fc->shown())
Fl::wait();
if (fc->value() && relative) {
fl_filename_relative(retname, sizeof(retname), fc->value());
return retname;
} else if (fc->value()) return (char *)fc->value();
else return 0;
}
//
// End of "$Id: fl_file_dir.cxx 4288 2005-04-16 00:13:17Z mike $".
//

Wyświetl plik

@ -0,0 +1,70 @@
#include <config.h>
#include "fileselect.h"
#include <FL/fl_ask.H>
#include <FL/Fl_Native_File_Chooser.H>
static Fl_Native_File_Chooser* chooser = 0;
static const char* get_file(void)
{
switch (chooser->show()) {
case -1:
fl_alert("%s", chooser->errmsg());
// fall through
case 1:
return NULL;
default:
return chooser->filename();
}
}
const char* file_select(const char* title, const char* filter, const char* def)
{
if (!chooser)
chooser = new Fl_Native_File_Chooser;
chooser->title(title);
chooser->filter(filter);
if (def)
chooser->preset_file(def);
chooser->options(Fl_Native_File_Chooser::PREVIEW);
chooser->type(Fl_Native_File_Chooser::BROWSE_FILE);
return get_file();
}
const char* file_saveas(const char* title, const char* filter, const char* def)
{
if (!chooser)
chooser = new Fl_Native_File_Chooser;
chooser->title(title);
chooser->filter(filter);
if (def)
chooser->preset_file(def);
chooser->options(Fl_Native_File_Chooser::SAVEAS_CONFIRM |
Fl_Native_File_Chooser::NEW_FOLDER |
Fl_Native_File_Chooser::PREVIEW);
chooser->type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
return get_file();
}
const char* dir_select(const char* title, const char* filter, const char* def)
{
if (!chooser)
chooser = new Fl_Native_File_Chooser;
chooser->title(title);
chooser->filter(filter);
if (def)
chooser->directory(def);
chooser->options(Fl_Native_File_Chooser::NEW_FOLDER |
Fl_Native_File_Chooser::PREVIEW);
chooser->type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
return get_file();
}

Wyświetl plik

@ -0,0 +1,78 @@
//
// flnfc_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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// 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);
}

Wyświetl plik

@ -1,6 +0,0 @@
#define new_width 16
#define new_height 16
static unsigned char new_bits[] = {
0x00, 0x00, 0x78, 0x00, 0x84, 0x00, 0x02, 0x01, 0x01, 0xfe, 0x01, 0x80,
0x31, 0x80, 0x31, 0x80, 0xfd, 0x80, 0xfd, 0x80, 0x31, 0x80, 0x31, 0x80,
0x01, 0x80, 0x01, 0x80, 0xff, 0xff, 0x00, 0x00};

Wyświetl plik

@ -1,8 +0,0 @@
#define ns_width 16
#define ns_height 16
#define ns_x_hot 8
#define ns_y_hot 8
static unsigned char ns_bits[] = {
0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0x80, 0x01, 0x80, 0x01,
0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00};

Wyświetl plik

@ -1,8 +0,0 @@
#define ns_mask_width 16
#define ns_mask_height 16
#define ns_mask_x_hot 8
#define ns_mask_y_hot 8
static unsigned char ns_mask_bits[] = {
0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f, 0xc0, 0x03,
0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f,
0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01};

Wyświetl plik

@ -1,6 +0,0 @@
#define up_width 16
#define up_height 16
static unsigned char up_bits[] = {
0x00, 0x00, 0x78, 0x00, 0x84, 0x00, 0x02, 0x01, 0x31, 0xfe, 0x79, 0x80,
0xfd, 0x80, 0x31, 0x80, 0x31, 0x80, 0x31, 0x80, 0x31, 0x80, 0x31, 0x80,
0x01, 0x80, 0x01, 0x80, 0xff, 0xff, 0x00, 0x00};

Wyświetl plik

@ -1,75 +0,0 @@
/*
* 'strlcat()' - Safely concatenate two strings.
*/
inline
size_t /* O - Length of string */
strlcat(char *dst, /* O - Destination string */
const char *src, /* I - Source string */
size_t size) { /* I - Size of destination string buffer */
size_t srclen; /* Length of source string */
size_t dstlen; /* Length of destination string */
/*
* Figure out how much room is left...
*/
dstlen = strlen(dst);
size -= dstlen + 1;
if (!size) return (dstlen); /* No room, return immediately... */
/*
* Figure out how much room is needed...
*/
srclen = strlen(src);
/*
* Copy the appropriate amount...
*/
if (srclen > size) srclen = size;
memcpy(dst + dstlen, src, srclen);
dst[dstlen + srclen] = '\0';
return (dstlen + srclen);
}
/*
* 'strlcpy()' - Safely copy two strings.
*/
inline
size_t /* O - Length of string */
strlcpy(char *dst, /* O - Destination string */
const char *src, /* I - Source string */
size_t size) { /* I - Size of destination string buffer */
size_t srclen; /* Length of source string */
/*
* Figure out how much room is needed...
*/
size --;
srclen = strlen(src);
/*
* Copy the appropriate amount...
*/
if (srclen > size) srclen = size;
memcpy(dst, src, srclen);
dst[srclen] = '\0';
return (srclen);
}

Wyświetl plik

@ -1,190 +0,0 @@
//
// "$Id: File_Selector.H 4473 2005-08-08 00:50:02Z mike $"
//
// File_Selector dialog for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2005 by Bill Spitzak and others.
//
// 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
//
// generated by Fast Light User Interface Designer (fluid) version 1.0107
#ifndef File_Selector_H
#define File_Selector_H
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <FL/Fl_Group.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_Menu_Button.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Tile.H>
#include <FL/Fl_File_Browser.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_File_Input.H>
#include <FL/Fl_Return_Button.H>
#include <FL/fl_ask.H>
class File_Selector {
public:
enum { SINGLE = 0, MULTI = 1, CREATE = 2, DIRECTORY = 4 };
private:
void (*callback_)(File_Selector*, void *);
void *data_;
char directory_[1024];
char pattern_[1024];
char preview_text_[2048];
int type_;
void fileListCB();
void fileNameCB();
void newdir();
static void previewCB(File_Selector *fc);
void showChoiceCB();
void update_favorites();
void update_preview();
public:
File_Selector(const char *d, const char *p, int t, const char *title);
private:
Fl_Double_Window *window;
void cb_window_i(Fl_Double_Window*, void*);
static void cb_window(Fl_Double_Window*, void*);
Fl_Choice *showChoice;
void cb_showChoice_i(Fl_Choice*, void*);
static void cb_showChoice(Fl_Choice*, void*);
Fl_Menu_Button *favoritesButton;
void cb_favoritesButton_i(Fl_Menu_Button*, void*);
static void cb_favoritesButton(Fl_Menu_Button*, void*);
public:
Fl_Button *newButton;
private:
void cb_newButton_i(Fl_Button*, void*);
static void cb_newButton(Fl_Button*, void*);
void cb__i(Fl_Tile*, void*);
static void cb_(Fl_Tile*, void*);
Fl_File_Browser *fileList;
void cb_fileList_i(Fl_File_Browser*, void*);
static void cb_fileList(Fl_File_Browser*, void*);
Fl_Box *previewBox;
public:
Fl_Check_Button *previewButton;
private:
void cb_previewButton_i(Fl_Check_Button*, void*);
static void cb_previewButton(Fl_Check_Button*, void*);
Fl_File_Input *fileName;
void cb_fileName_i(Fl_File_Input*, void*);
static void cb_fileName(Fl_File_Input*, void*);
Fl_Return_Button *okButton;
void cb_okButton_i(Fl_Return_Button*, void*);
static void cb_okButton(Fl_Return_Button*, void*);
Fl_Button *cancelButton;
void cb_cancelButton_i(Fl_Button*, void*);
static void cb_cancelButton(Fl_Button*, void*);
Fl_Double_Window *favWindow;
Fl_File_Browser *favList;
void cb_favList_i(Fl_File_Browser*, void*);
static void cb_favList(Fl_File_Browser*, void*);
Fl_Button *favUpButton;
void cb_favUpButton_i(Fl_Button*, void*);
static void cb_favUpButton(Fl_Button*, void*);
Fl_Button *favDeleteButton;
void cb_favDeleteButton_i(Fl_Button*, void*);
static void cb_favDeleteButton(Fl_Button*, void*);
Fl_Button *favDownButton;
void cb_favDownButton_i(Fl_Button*, void*);
static void cb_favDownButton(Fl_Button*, void*);
Fl_Button *favCancelButton;
void cb_favCancelButton_i(Fl_Button*, void*);
static void cb_favCancelButton(Fl_Button*, void*);
Fl_Return_Button *favOkButton;
void cb_favOkButton_i(Fl_Return_Button*, void*);
static void cb_favOkButton(Fl_Return_Button*, void*);
public:
~File_Selector();
void callback(void (*cb)(File_Selector *, void *), void *d = 0);
void color(Fl_Color c);
Fl_Color color();
int count();
void directory(const char *d);
char * directory();
void filter(const char *p);
const char * filter();
int filter_value();
void filter_value(int f);
void hide();
void iconsize(uchar s);
uchar iconsize();
void label(const char *l);
const char * label();
void ok_label(const char *l);
const char * ok_label();
void preview(int e);
int preview() const { return previewButton->value(); };
void rescan();
void show();
int shown();
void textcolor(Fl_Color c);
Fl_Color textcolor();
void textfont(uchar f);
uchar textfont();
void textsize(uchar s);
uchar textsize();
void type(int t);
int type();
void * user_data() const;
void user_data(void *d);
const char *value(int f = 1);
void value(const char *filename);
int visible();
static const char *add_favorites_label;
static const char *all_files_label;
static const char *custom_filter_label;
static const char *existing_file_label;
static const char *favorites_label;
static const char *filename_label;
static const char *filesystems_label;
static const char *manage_favorites_label;
static const char *new_directory_label;
static const char *new_directory_tooltip;
static const char *preview_label;
static const char *save_label;
static const char *show_label;
static Fl_File_Sort_F *sort;
};
extern char * // O - Directory or NULL
Dir_Chooser(const char *message, // I - Message for titlebar
const char *fname, // I - Initial directory name
int relative); // I - 0 for absolute
extern char * // O - Filename or NULL
File_Select(const char *message, // I - Message in titlebar
const char *pat, // I - Filename pattern
const char *fname, // I - Initial filename selection
int relative); // I - 0 for absolute path
#endif
//
// End of "$Id: File_Selector.H 4473 2005-08-08 00:50:02Z mike $".
//

Wyświetl plik

@ -0,0 +1,8 @@
#ifndef FILESELECT_H
#define FILESELECT_H
const char* file_select(const char* title, const char* filter, const char* def = 0);
const char* file_saveas(const char* title, const char* filter, const char* def = 0);
const char* dir_select(const char* title, const char* filter, const char* def = 0);
#endif // FILESELECT_H

Wyświetl plik

@ -13,7 +13,7 @@
#include "mfskvaricode.h"
#include "mbuffer.h"
//#include "File_Selector.h"
//#include "fileselect.h"
#include "picture.h"
#include <FL/Fl_Shared_Image.H>

Wyświetl plik

@ -143,7 +143,7 @@ public:
virtual size_t Read(double *, size_t) = 0;
virtual bool must_close(void) = 0;
#if USE_SNDFILE
void get_file_params(const char* def_fname, char** fname, int* format);
void get_file_params(const char* def_fname, const char** fname, int* format);
int Capture(bool val);
int Playback(bool val);
int Generate(bool val);

Wyświetl plik

@ -37,7 +37,7 @@
#include "ascii.h"
#include "File_Selector.h"
#include "fileselect.h"
#include "qrunner.h"
@ -831,8 +831,10 @@ void cb_picRxClose( Fl_Widget *w, void *who)
void cb_picRxSave( Fl_Widget *w, void *who)
{
mfsk *me = (mfsk *)who;
char *fn =
File_Select("Save Image file?","*.{gif,jpg,png}", "", 0);
const char *fn =
file_saveas("Save image file", "Portable Network Graphics\t*.png\n"
"Independent JPEG Group\t*.{jpg,jif,jpeg,jpe}\n"
"Graphics Interchange Format\t*.gif");
if (!fn) return;
me->picRx->save_jpeg(fn);
}
@ -936,8 +938,10 @@ void mfsk::updateTxPic(unsigned char data)
void cb_picTxLoad(Fl_Widget *,void *who) {
mfsk *TxWho = (mfsk *)who;
char *fn =
File_Select("Image file?","*.{gif,jpg,png}", "", 0);
const char *fn =
file_select("Load image file", "Portable Network Graphics\t*.png\n"
"Independent JPEG Group\t*.{jpg,jif,jpeg,jpe}\n"
"Graphics Interchange Format\t*.gif");
if (!fn) return;
TxWho->load_file(fn);
}

Wyświetl plik

@ -12,7 +12,7 @@
#include "globals.h"
#include <FL/Fl.H>
#include "File_Selector.h"
#include "fileselect.h"
#include <ctime>
#include <cstdio>
@ -588,7 +588,7 @@ void MACROTEXT::openMacroFile()
{
string deffilename = HomeDir;
deffilename.append("/macros.mdf");
char *p = File_Select("Open macro file", "*.mdf", deffilename.c_str(), 0);
const char *p = file_select("Open macro file", "Fldigi macro definition file\t*.mdf", deffilename.c_str());
if (p)
loadMacros(p);
}
@ -597,7 +597,7 @@ void MACROTEXT::saveMacroFile()
{
string deffilename = HomeDir;
deffilename.append("/macros.mdf");
char *p = File_Select("Save macro file", "*.mdf", deffilename.c_str(), 0);
const char *p = file_saveas("Save macro file", "Fldigi macro definition file\t*.mdf", deffilename.c_str());
if (p)
saveMacros(p);
}

Wyświetl plik

@ -28,6 +28,7 @@
#include <config.h>
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
@ -48,7 +49,7 @@
#include "configuration.h"
#include "status.h"
#include <FL/Fl.H>
#include "File_Selector.h"
#include "fileselect.h"
SoundBase::SoundBase()
@ -78,15 +79,17 @@ SoundBase::~SoundBase()
}
#if USE_SNDFILE
void SoundBase::get_file_params(const char* def_fname, char** fname, int* format)
void SoundBase::get_file_params(const char* def_fname, const char** fname, int* format)
{
const char* suffixes;
std::string filters = "Waveform Audio Format\t*.wav\n" "AU\t*.{au,snd}\n";
if (format_supported(SF_FORMAT_FLAC | SF_FORMAT_PCM_16))
suffixes = "*.{wav,flac,au}";
else
suffixes = "*.{wav,au}";
filters += "Free Lossless Audio Codec\t*.flac";
if ((*fname = File_Select("Audio file", suffixes, def_fname, 0)) == 0)
if (strstr(def_fname, "playback"))
*fname = file_select("Audio file", filters.c_str(), def_fname);
else
*fname = file_saveas("Audio file", filters.c_str(), def_fname);
if (!*fname)
return;
char* suffix = strrchr(*fname, '.');
@ -111,7 +114,7 @@ int SoundBase::Capture(bool val)
return 1;
}
char* fname;
const char* fname;
int format;
get_file_params("./capture.wav", &fname, &format);
if (!fname)
@ -143,7 +146,7 @@ int SoundBase::Playback(bool val)
playback = false;
return 1;
}
char* fname;
const char* fname;
int format;
get_file_params("./playback.wav", &fname, &format);
if (!fname)
@ -172,7 +175,7 @@ int SoundBase::Generate(bool val)
return 1;
}
char* fname;
const char* fname;
int format;
get_file_params("./generate.wav", &fname, &format);
if (!fname)

Wyświetl plik

@ -8,7 +8,7 @@
using namespace std;
#include "File_Selector.h"
#include "fileselect.h"
void colorbox::draw() {
int ypos = y() + 2;
@ -58,7 +58,7 @@ void loadPalette()
palfilename = HomeDir;
palfilename.append ("/fldigi.pal");
}
char *p = File_Select("Open palette", "*.pal", palfilename.c_str(), 0);
const char *p = file_select("Open palette", "Fldigi palette\t*.pal", palfilename.c_str());
if (!p) return;
if ((clrfile = fopen(p, "r")) != NULL) {
for (int i = 0; i < 9; i++) {
@ -94,7 +94,7 @@ void savePalette()
palfilename = HomeDir;
palfilename.append ("/fldigi.pal");
}
char *p = File_Select("Save palette", "*.pal", palfilename.c_str(), 0);
const char *p = file_saveas("Save palette", "Fldigi palette\t*.pal", palfilename.c_str());
if (!p) return;
if ((clrfile = fopen(p, "w")) != NULL) {
for (int i = 0; i < 9; i++) {

Wyświetl plik

@ -33,7 +33,7 @@
#include "cw.h"
#include "File_Selector.h"
#include "fileselect.h"
#include "ascii.h"
#include "configuration.h"
@ -183,7 +183,7 @@ void FTextBase::set_style(int attr, Fl_Font f, int s, Fl_Color c, int set)
///
void FTextBase::readFile(void)
{
char *fn = File_Select("Select ASCII text file", "*.txt", "", 0);
const char *fn = file_select("Append text", "Text\t*.txt");
if (fn) {
tbuf->appendfile(fn);
insert_position(tbuf->length());
@ -196,7 +196,7 @@ void FTextBase::readFile(void)
///
void FTextBase::saveFile(void)
{
char *fn = File_Select("Select ASCII text file", "*.txt", "", 0);
const char *fn = file_saveas("Save text as", "Text\t*.txt");
if (fn)
tbuf->outputfile(fn, 0, tbuf->length());
}