2010-01-14 02:13:59 +03:00
|
|
|
//
|
|
|
|
// "$Id$"
|
|
|
|
//
|
|
|
|
// Simple test of the Fl_Native_File_Chooser.
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
2010-01-14 02:13:59 +03:00
|
|
|
// Copyright 2004 Greg Ercolano.
|
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
2010-01-14 02:13:59 +03:00
|
|
|
//
|
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
|
|
|
//
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/fl_ask.H> // fl_beep()
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl_Input.H>
|
2011-01-01 23:27:07 +03:00
|
|
|
#include <FL/Fl_Box.H>
|
2010-01-14 02:13:59 +03:00
|
|
|
#include <FL/Fl_Native_File_Chooser.H>
|
|
|
|
|
|
|
|
// GLOBALS
|
|
|
|
Fl_Input *G_filename = NULL;
|
|
|
|
|
2013-08-16 03:01:15 +04:00
|
|
|
void PickFile_CB(Fl_Widget*, void*) {
|
2010-01-14 02:13:59 +03:00
|
|
|
// Create native chooser
|
|
|
|
Fl_Native_File_Chooser native;
|
|
|
|
native.title("Pick a file");
|
|
|
|
native.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
|
|
|
native.filter("Text\t*.txt\n"
|
|
|
|
"C Files\t*.{cxx,h,c}\n"
|
|
|
|
"Apps\t*.{app}\n"); // TODO: need to add kNavSupportPackages to non-cocoa <FNFC>_MAC.cxx
|
|
|
|
native.preset_file(G_filename->value());
|
|
|
|
// Show native chooser
|
|
|
|
switch ( native.show() ) {
|
|
|
|
case -1: fprintf(stderr, "ERROR: %s\n", native.errmsg()); break; // ERROR
|
|
|
|
case 1: fprintf(stderr, "*** CANCEL\n"); fl_beep(); break; // CANCEL
|
|
|
|
default: // PICKED FILE
|
|
|
|
if ( native.filename() ) {
|
|
|
|
G_filename->value(native.filename());
|
|
|
|
} else {
|
|
|
|
G_filename->value("NULL");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-16 03:01:15 +04:00
|
|
|
void PickDir_CB(Fl_Widget*, void*) {
|
|
|
|
// Create native chooser
|
|
|
|
Fl_Native_File_Chooser native;
|
|
|
|
native.title("Pick a Directory");
|
|
|
|
native.directory(G_filename->value());
|
|
|
|
native.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
|
|
|
|
// Show native chooser
|
|
|
|
switch ( native.show() ) {
|
|
|
|
case -1: fprintf(stderr, "ERROR: %s\n", native.errmsg()); break; // ERROR
|
|
|
|
case 1: fprintf(stderr, "*** CANCEL\n"); fl_beep(); break; // CANCEL
|
|
|
|
default: // PICKED DIR
|
|
|
|
if ( native.filename() ) {
|
|
|
|
G_filename->value(native.filename());
|
|
|
|
} else {
|
|
|
|
G_filename->value("NULL");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-14 02:13:59 +03:00
|
|
|
int main(int argc, char **argv) {
|
2010-01-14 21:42:13 +03:00
|
|
|
//// For a nicer looking browser under linux, call Fl_File_Icon::load_system_icons();
|
2010-01-14 02:13:59 +03:00
|
|
|
//// (If you do this, you'll need to link with fltk_images)
|
2010-01-14 21:42:13 +03:00
|
|
|
//// NOTE: If you do not load the system icons, the file chooser will still work, but
|
|
|
|
//// no icons will be shown. However, this means you do not need to link in the
|
|
|
|
//// fltk_images library, potentially reducing the size of your executable.
|
|
|
|
//// Loading the system icons is not required by the OSX or Windows native file choosers.
|
2010-01-15 00:49:46 +03:00
|
|
|
#if !defined(WIN32) && !defined(__APPLE__)
|
2010-01-14 21:42:13 +03:00
|
|
|
Fl_File_Icon::load_system_icons();
|
2010-01-14 22:57:08 +03:00
|
|
|
#endif
|
2010-01-14 02:13:59 +03:00
|
|
|
|
2011-01-01 23:27:07 +03:00
|
|
|
int argn = 1;
|
|
|
|
#ifdef __APPLE__
|
|
|
|
// OS X may add the process number as the first argument - ignore
|
|
|
|
if (argc>argn && strncmp(argv[1], "-psn_", 5)==0)
|
|
|
|
argn++;
|
|
|
|
#endif
|
|
|
|
|
2010-01-14 21:42:13 +03:00
|
|
|
Fl_Window *win = new Fl_Window(600, 100, "Native File Chooser Test");
|
2011-01-01 23:27:07 +03:00
|
|
|
win->size_range(300, 100, 0, 100);
|
2010-01-14 02:13:59 +03:00
|
|
|
win->begin();
|
|
|
|
{
|
|
|
|
int y = 10;
|
|
|
|
G_filename = new Fl_Input(80, y, win->w()-80-10, 25, "Filename");
|
2011-01-01 23:27:07 +03:00
|
|
|
G_filename->value(argc <= argn ? "." : argv[argn]);
|
2010-01-14 02:13:59 +03:00
|
|
|
G_filename->tooltip("Default filename");
|
|
|
|
y += G_filename->h() + 5;
|
|
|
|
Fl_Button *but = new Fl_Button(win->w()-80-10, win->h()-25-10, 80, 25, "Pick File");
|
2013-08-16 03:01:15 +04:00
|
|
|
but->callback(PickFile_CB);
|
|
|
|
Fl_Button *butdir = new Fl_Button(but->x()-80-10, win->h()-25-10, 80, 25, "Pick Dir");
|
|
|
|
butdir->callback(PickDir_CB);
|
2011-01-01 23:27:07 +03:00
|
|
|
Fl_Box *dummy = new Fl_Box(80, 0, 430, 100);
|
|
|
|
dummy->hide();
|
|
|
|
win->resizable(dummy);
|
2010-01-14 02:13:59 +03:00
|
|
|
}
|
|
|
|
win->end();
|
2011-01-01 23:27:07 +03:00
|
|
|
win->show(argc, argv);
|
2010-01-14 02:13:59 +03:00
|
|
|
return(Fl::run());
|
|
|
|
}
|
2010-01-14 21:42:13 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// End of "$Id$".
|
|
|
|
//
|
|
|
|
|