1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/*
Copyright (C) 2010-2015 Kai Habel
This file is part of Octave.
Octave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
Octave 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 General Public License
for more details.
You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_FLTK
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#endif
#include <FL/Fl.H>
#include <FL/Fl_File_Chooser.H>
// FLTK headers may include X11/X.h which defines Complex, and that
// conflicts with Octave's Complex typedef. We don't need the X11
// Complex definition in this file, so remove it before including Octave
// headers which may require Octave's Complex typedef.
#undef Complex
#endif
#include "defun-dld.h"
#include "file-ops.h"
DEFUN_DLD (__fltk_uigetfile__, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} __fltk_uigetfile__ (@dots{})\n\
Undocumented internal function.\n\
@end deftypefn")
{
#ifdef HAVE_FLTK
// Expected argument list:
//
// args(0) ... FileFilter in fltk format
// args(1) ... Title
// args(2) ... Default Filename
// args(3) ... PostionValue [x,y]
// args(4) ... SelectValue "on"/"off"/"dir"/"create"
octave_value_list retval (3, octave_value (0));
std::string file_filter = args(0).string_value ();
std::string title = args(1).string_value ();
std::string default_name = args(2).string_value ();
Matrix pos = args(3).matrix_value ();
int multi_type = Fl_File_Chooser::SINGLE;
std::string flabel = "Filename:";
std::string multi = args(4).string_value ();
if (multi == "on")
multi_type = Fl_File_Chooser::MULTI;
else if (multi == "dir")
{
multi_type = Fl_File_Chooser::DIRECTORY;
flabel = "Directory:";
}
else if (multi == "create")
multi_type = Fl_File_Chooser::CREATE;
Fl_File_Chooser::filename_label = flabel.c_str ();
Fl_File_Chooser fc (default_name.c_str (), file_filter.c_str (),
multi_type, title.c_str ());
fc.preview (0);
if (multi_type == Fl_File_Chooser::CREATE)
fc.ok_label ("Save");
fc.show ();
while (fc.shown ())
Fl::wait ();
if (fc.value ())
{
int file_count = fc.count ();
std::string fname;
//fltk uses forward slash even for windows
std::string sep = "/";
size_t idx;
if (file_count == 1 && multi_type != Fl_File_Chooser::DIRECTORY)
{
fname = fc.value ();
idx = fname.find_last_of (sep);
retval(0) = fname.substr (idx + 1);
}
else
{
Cell file_cell = Cell (file_count, 1);
for (octave_idx_type n = 1; n <= file_count; n++)
{
fname = fc.value (n);
idx = fname.find_last_of (sep);
file_cell(n - 1) = fname.substr (idx + 1);
}
retval(0) = file_cell;
}
if (multi_type == Fl_File_Chooser::DIRECTORY)
retval(0) = file_ops::native_separator_path (std::string (fc.value ()));
else
{
retval(1) = file_ops::native_separator_path (
std::string (fc.directory ()) + sep);
retval(2) = fc.filter_value () + 1;
}
}
fc.hide ();
Fl::flush ();
return retval;
#else
error ("__fltk_uigetfile__: not available without OpenGL and FLTK libraries");
return octave_value ();
#endif
}
/*
## No test needed for internal helper function.
%!assert (1)
*/
|