FLTK 1.4.0
Loading...
Searching...
No Matches
Fl_System_Driver.H
1//
2// A base class for platform specific system calls
3// for the Fast Light Tool Kit (FLTK).
4//
5// Copyright 2010-2022 by Bill Spitzak and others.
6//
7// This library is free software. Distribution and use rights are outlined in
8// the file "COPYING" which should have been included with this file. If this
9// file is missing or damaged, see the license at:
10//
11// https://www.fltk.org/COPYING.php
12//
13// Please see the following page on how to report bugs and issues:
14//
15// https://www.fltk.org/bugs.php
16//
17
28/* Class hierarchy
29 + Fl_System_Driver
30 | + Fl_Posix_System_Driver
31 | | + Fl_Unix_System_Driver
32 | | + Fl_Darwin_System_Driver
33 | + Fl_WinAPI_System_Driver
34 */
35
36#ifndef FL_SYSTEM_DRIVER_H
37#define FL_SYSTEM_DRIVER_H
38
39#include <FL/Fl.H>
40#include <FL/Fl_Export.H>
41#include <FL/filename.H>
42#include <FL/Fl_Preferences.H>
43#include <stdio.h>
44#include <stdlib.h>
45#include <stdarg.h>
46#include <string.h>
47#include <time.h>
48
49class Fl_File_Icon;
50class Fl_File_Browser;
51class Fl_Pixmap;
52class Fl_Widget;
53class Fl_Sys_Menu_Bar_Driver;
54
60class Fl_System_Driver {
61 friend class Fl;
62protected:
63 // implement once for each platform
64 static Fl_System_Driver *newSystemDriver();
65 Fl_System_Driver();
66 static bool awake_ring_empty();
67public:
68 virtual ~Fl_System_Driver();
69 static int command_key;
70 static int control_key;
71
72 // implement if the system adds unwanted program argument(s)
73 virtual int single_arg(const char *) { return 0; }
74 // implement if the system adds unwanted program argument pair(s)
75 virtual int arg_and_value(const char * /*name*/, const char * /*value*/) { return 0; }
76 static void warning(const char* format, ...);
77 // implement to set the default effect of Fl::warning()
78 virtual void warning(const char* format, va_list args);
79 static void error(const char* format, ...);
80 // implement to set the default effect of Fl::error()
81 virtual void error(const char* format, va_list args);
82 static void fatal(const char* format, ...);
83 // implement to set the default effect of Fl::error()
84 virtual void fatal(const char* format, va_list args);
85
86 // implement these to support cross-platform file operations
87 virtual char *utf2mbcs(const char *s) {return (char*)s;}
88 virtual char *getenv(const char*) {return NULL;}
89 virtual int putenv(const char *) {return -1;}
90 virtual int open(const char* /*f*/, int /*oflags*/, int /*pmode*/) {return -1;}
91
92 // implement these to support cross-platform string operations
93 virtual char *strdup(const char *) {return NULL;}
94
95 // Note: the default implementation ignores the 'binary' argument.
96 // Some platforms (notably Windows) may use this argument.
97 virtual int open_ext(const char* f, int /*binary*/, int oflags, int pmode) {
98 return this->open(f, oflags, pmode);
99 }
100 virtual FILE *fopen(const char* f, const char *mode);
101 virtual int system(const char*) {return -1;}
102 virtual int execvp(const char * /*file*/, char *const * /*argv*/) {return -1;}
103 virtual int chmod(const char* /*f*/, int /*mode*/) {return -1;}
104 virtual int access(const char* /*f*/, int /*mode*/) { return -1;}
105 virtual int flstat(const char* /*f*/, struct stat *) { return -1;}
106 virtual char *getcwd(char* /*b*/, int /*l*/) {return NULL;}
107 virtual int chdir(const char*) {return -1;}
108 virtual int unlink(const char*) {return -1;}
109 virtual int mkdir(const char* /*f*/, int /*mode*/) {return -1;}
110 virtual int rmdir(const char*) {return -1;}
111 virtual int rename(const char* /*f*/, const char * /*n*/) {return -1;}
112
113 // Windows commandline argument conversion to UTF-8.
114 // Default implementation: no-op, overridden only on Windows
115 virtual int args_to_utf8(int argc, char ** &argv) { return argc; }
116
117 // the default implementation of these utf8... functions should be enough
118 virtual unsigned utf8towc(const char* src, unsigned srclen, wchar_t* dst, unsigned dstlen);
119 virtual unsigned utf8fromwc(char* dst, unsigned dstlen, const wchar_t* src, unsigned srclen);
120 virtual int utf8locale() {return 1;}
121 virtual unsigned utf8to_mb(const char* src, unsigned srclen, char* dst, unsigned dstlen);
122 virtual unsigned utf8from_mb(char* dst, unsigned dstlen, const char* src, unsigned srclen);
123 // implement to shield fprintf() from locale changes in decimal point
124 virtual int clocale_vprintf(FILE *output, const char *format, va_list args);
125 virtual int clocale_vsnprintf(char *output, size_t output_size, const char *format, va_list args);
126 virtual int clocale_vsscanf(const char *input, const char *format, va_list args);
127 // implement scandir-like function
128 virtual int filename_list(const char * /*d*/, dirent ***,
129 int (* /*sort*/)(struct dirent **, struct dirent **),
130 char *errmsg=NULL, int errmsg_sz=0) {
131 (void)errmsg; (void)errmsg_sz;
132 return -1;
133 }
134 // the default implementation of filename_expand() may be enough
135 virtual int filename_expand(char *to, int tolen, const char *from);
136 // to implement
137 virtual const char *getpwnam(const char *) {return NULL;}
138 // the default implementation of filename_relative() is in src/filename_absolute.cxx and may be enough
139 virtual int filename_relative(char *to, int tolen, const char *from, const char *base);
140 // the default implementation of filename_absolute() is in src/filename_absolute.cxx and may be enough
141 virtual int filename_absolute(char *to, int tolen, const char *from, const char *base);
142 // the default implementation of filename_isdir() is in src/filename_isdir.cxx and may be enough
143 virtual int filename_isdir(const char* n);
144 // the default implementation of filename_isdir_quick() is in src/filename_isdir.cxx and may be enough
145 virtual int filename_isdir_quick(const char* n);
146 // the default implementation of filename_ext() is in src/filename_ext.cxx and may be enough
147 virtual const char *filename_ext(const char *buf);
148 // implement to support fl_filename_name()
149 virtual const char *filename_name(const char *buf) {return buf;}
150 // implement to support fl_open_uri()
151 virtual int open_uri(const char * /*uri*/, char * /*msg*/, int /*msglen*/) {return 0;}
152 // the default implementation of use_tooltip_timeout_condition() may be enough
153 virtual int use_tooltip_timeout_condition() {return 0;}
154 // the default implementation of use_recent_tooltip_fix() may be enough
155 virtual int use_recent_tooltip_fix() {return 0;}
156 // the default implementation of need_test_shortcut_extra() may be enough
157 virtual int need_test_shortcut_extra() {return 0;}
158 // implement to support Fl_File_Browser::load()
159 virtual int file_browser_load_filesystem(Fl_File_Browser *, char * /*filename*/, int /*lname*/, Fl_File_Icon *) {return 0;}
160 // the default implementation of file_browser_load_directory() should be enough
161 virtual int file_browser_load_directory(const char *directory, char *filename, size_t name_size,
162 dirent ***pfiles, Fl_File_Sort_F *sort,
163 char *errmsg=NULL, int errmsg_sz=0);
164 // implement to support Fl_Preferences
165 virtual void newUUID(char *uuidBuffer) { uuidBuffer[0] = 0; }
166 // implement to support Fl_Preferences
167 virtual char *preference_rootnode(Fl_Preferences *, Fl_Preferences::Root,
168 const char * /*vendor*/,
169 const char * /*application*/) {return NULL;}
170 // the default implementation of preferences_need_protection_check() may be enough
171 virtual int preferences_need_protection_check() {return 0;}
172 // implement to support Fl_Plugin_Manager::load()
173 virtual void *load(const char *) {return NULL;}
174 // the default implementation is most probably enough
175 virtual void png_extra_rgba_processing(unsigned char * /*array*/, int /*w*/, int /*h*/) {}
176 // the default implementation is most probably enough
177 virtual const char *next_dir_sep(const char *start) { return strchr(start, '/');}
178 // implement to support threading
179 virtual void awake(void*) {}
180 virtual int lock() {return 1;}
181 virtual void unlock() {}
182 virtual void* thread_message() {return NULL;}
183 // implement to support Fl_File_Icon
184 virtual int file_type(const char *filename);
185 // implement to return the user's home directory name
186 virtual const char *home_directory_name() { return ""; }
187 // the default implementation is most probably enough
188 virtual const char *filesystems_label() { return "File Systems"; }
189 // return TRUE means \ same as / in file names
190 virtual int backslash_as_slash() {return 0;}
191 // return TRUE means : indicates a drive letter in file names
192 virtual int colon_is_drive() {return 0;}
193 // return TRUE means that files whose name begins with dot are hidden
194 virtual int dot_file_hidden() {return 0;}
195 // return TRUE when file names are case insensitive
196 virtual int case_insensitive_filenames() {return 0;}
197 // the implementations of local_to_latin1() and latin1_to_local() are in fl_encoding_latin1.cxx
198 virtual const char *local_to_latin1(const char *t, int n);
199 virtual const char *latin1_to_local(const char *t, int n);
200 // the implementations of local_to_mac_roman() and mac_roman_to_local() are in fl_encoding_mac_roman.cxx
201 virtual const char *local_to_mac_roman(const char *t, int n);
202 virtual const char *mac_roman_to_local(const char *t, int n);
203 // the default implementations of tree_openpixmap() and tree_closepixmap() are
204 // in Fl_Tree_Prefs.cxx and can be enough
205 virtual Fl_Pixmap *tree_openpixmap();
206 virtual Fl_Pixmap *tree_closepixmap();
207 static const char *const tree_open_xpm[]; // used by tree_openpixmap()
208 static const char * const tree_close_xpm[]; // used by tree_closepixmap()
209 // the default implementation of tree_connector_style() is in Fl_Tree_Prefs.cxx and can be enough
210 virtual int tree_connector_style();
211 virtual void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0);
212 virtual void add_fd(int fd, Fl_FD_Handler cb, void* = 0);
213 virtual void remove_fd(int, int when);
214 virtual void remove_fd(int);
215 // the default implementation of open_callback() may be enough
216 virtual void open_callback(void (*)(const char *));
217 // The default implementation may be enough.
218 virtual void gettime(time_t *sec, int *usec);
219 // The default implementation of the next 4 functions may be enough.
220 virtual const char *shift_name() { return "Shift"; }
221 virtual const char *meta_name() { return "Meta"; }
222 virtual const char *alt_name() { return "Alt"; }
223 virtual const char *control_name() { return "Ctrl"; }
224 virtual Fl_Sys_Menu_Bar_Driver *sys_menu_bar_driver() { return NULL; }
225 virtual void lock_ring() {}
226 virtual void unlock_ring() {}
227 virtual double wait(double); // must FL_OVERRIDE
228 virtual int ready() { return 0; } // must FL_OVERRIDE
229 virtual int close_fd(int) {return -1;} // to close a file descriptor
230};
231
232#endif // FL_SYSTEM_DRIVER_H
233
Fl static class.
The Fl_File_Browser widget displays a list of filenames, optionally with file-specific icons.
Definition Fl_File_Browser.H:37
The Fl_File_Icon class manages icon images that can be used as labels in other widgets and as icons i...
Definition Fl_File_Icon.H:45
The Fl_Pixmap class supports caching and drawing of colormap (pixmap) images, including transparency.
Definition Fl_Pixmap.H:36
Fl_Preferences store user settings between application starts.
Definition Fl_Preferences.H:124
Root
Define the scope of the preferences.
Definition Fl_Preferences.H:130
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:104
The Fl is the FLTK global (static) class containing state information and global methods for the curr...
Definition Fl.H:137
static int wait()
Waits until "something happens" and then returns.
Definition Fl.cxx:625
static int args(int argc, char **argv, int &i, Fl_Args_Handler cb=0)
Parse command line switches using the cb argument handler.
Definition Fl_arg.cxx:276
static int system(const char *command)
Run a command line on the computer.
Definition Fl.cxx:2274
static int ready()
This is similar to Fl::check() except this does not call Fl::flush() or any callbacks,...
Definition Fl.cxx:670
static void remove_fd(int, int when)
Removes a file descriptor handler.
Definition Fl.cxx:2137
static void add_fd(int fd, int when, Fl_FD_Handler cb, void *=0)
Adds file descriptor fd to listen to.
Definition Fl.cxx:2124
static int args_to_utf8(int argc, char **&argv)
Convert Windows commandline arguments to UTF-8.
Definition Fl.cxx:2354
File names and URI utility functions.
void(* Fl_FD_Handler)(FL_SOCKET fd, void *data)
Signature of add_fd functions passed as parameters.
Definition Fl.H:106
int() Fl_File_Sort_F(struct dirent **, struct dirent **)
File sorting function.
Definition filename.H:114
static void unlock()
The unlock() method releases the lock that was set using the lock() method.
Definition Fl_lock.cxx:204
static void * thread_message()
The thread_message() method returns the last message that was sent from a child by the awake() method...
Definition Fl_lock.cxx:196
static void awake(void *message=0)
Sends a message pointer to the main thread, causing any pending Fl::wait() call to terminate so that ...
Definition Fl_lock.cxx:192
static int lock()
The lock() method blocks the current thread until it can safely access FLTK widgets and data.
Definition Fl_lock.cxx:200
static void(* error)(const char *,...)
FLTK calls Fl::error() to output a normal error message.
Definition Fl.H:532
static void(* fatal)(const char *,...)
FLTK calls Fl::fatal() to output a fatal error message.
Definition Fl.H:549
static void(* warning)(const char *,...)
FLTK calls Fl::warning() to output a warning message.
Definition Fl.H:517