FLTK 1.5.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();
67 int filename_relative_(char *to, int tolen, const char *from, const char *base, bool case_sensitive);
68public:
69 virtual ~Fl_System_Driver();
70 static int command_key;
71 static int control_key;
72
73 // implement if the system adds unwanted program argument(s)
74 virtual int single_arg(const char *) { return 0; }
75 // implement if the system adds unwanted program argument pair(s)
76 virtual int arg_and_value(const char * /*name*/, const char * /*value*/) { return 0; }
77 static void warning(const char* format, ...);
78 // implement to set the default effect of Fl::warning()
79 virtual void warning(const char* format, va_list args);
80 static void error(const char* format, ...);
81 // implement to set the default effect of Fl::error()
82 virtual void error(const char* format, va_list args);
83 static void fatal(const char* format, ...);
84 // implement to set the default effect of Fl::error()
85 virtual void fatal(const char* format, va_list args);
86
87 // implement these to support cross-platform file operations
88 virtual char *utf2mbcs(const char *s) {return (char*)s;}
89 virtual char *getenv(const char*) {return NULL;}
90 virtual int putenv(const char *) {return -1;}
91 virtual int open(const char* /*f*/, int /*oflags*/, int /*pmode*/) {return -1;}
92
93 // implement these to support cross-platform string operations
94 virtual char *strdup(const char *) {return NULL;}
95
96 // Note: the default implementation ignores the 'binary' argument.
97 // Some platforms (notably Windows) may use this argument.
98 virtual int open_ext(const char* f, int /*binary*/, int oflags, int pmode) {
99 return this->open(f, oflags, pmode);
100 }
101 virtual FILE *fopen(const char* f, const char *mode);
102 virtual int system(const char*) {return -1;}
103 virtual int execvp(const char * /*file*/, char *const * /*argv*/) {return -1;}
104 virtual int chmod(const char* /*f*/, int /*mode*/) {return -1;}
105 virtual int access(const char* /*f*/, int /*mode*/) { return -1;}
106 virtual int flstat(const char* /*f*/, struct stat *) { return -1;}
107 virtual char *getcwd(char* /*b*/, int /*l*/) {return NULL;}
108 virtual int chdir(const char*) {return -1;}
109 virtual int unlink(const char*) {return -1;}
110 virtual int mkdir(const char* /*f*/, int /*mode*/) {return -1;}
111 virtual int rmdir(const char*) {return -1;}
112 virtual int rename(const char* /*f*/, const char * /*n*/) {return -1;}
113
114 // Windows commandline argument conversion to UTF-8.
115 // Default implementation: no-op, overridden only on Windows
116 virtual int args_to_utf8(int argc, char ** &argv) { return argc; }
117
118 // the default implementation of these utf8... functions should be enough
119 virtual unsigned utf8towc(const char* src, unsigned srclen, wchar_t* dst, unsigned dstlen);
120 virtual unsigned utf8fromwc(char* dst, unsigned dstlen, const wchar_t* src, unsigned srclen);
121 virtual int utf8locale() {return 1;}
122 virtual unsigned utf8to_mb(const char* src, unsigned srclen, char* dst, unsigned dstlen);
123 virtual unsigned utf8from_mb(char* dst, unsigned dstlen, const char* src, unsigned srclen);
124 // implement to shield fprintf() from locale changes in decimal point
125 virtual int clocale_vprintf(FILE *output, const char *format, va_list args);
126 virtual int clocale_vsnprintf(char *output, size_t output_size, const char *format, va_list args);
127 virtual int clocale_vsscanf(const char *input, const char *format, va_list args);
128 // implement scandir-like function
129 virtual int filename_list(const char * /*d*/, dirent ***,
130 int (* /*sort*/)(struct dirent **, struct dirent **),
131 char *errmsg=NULL, int errmsg_sz=0) {
132 (void)errmsg; (void)errmsg_sz;
133 return -1;
134 }
135 // the default implementation of filename_expand() may be enough
136 virtual int filename_expand(char *to, int tolen, const char *from);
137 // to implement
138 virtual const char *getpwnam(const char *) {return NULL;}
139 // the default implementation of filename_relative() is in src/filename_absolute.cxx and may be enough
140 virtual int filename_relative(char *to, int tolen, const char *from, const char *base);
141 // the default implementation of filename_absolute() is in src/filename_absolute.cxx and may be enough
142 virtual int filename_absolute(char *to, int tolen, const char *from, const char *base);
143 // the default implementation of filename_isdir() is in src/filename_isdir.cxx and may be enough
144 virtual int filename_isdir(const char* n);
145 // the default implementation of filename_isdir_quick() is in src/filename_isdir.cxx and may be enough
146 virtual int filename_isdir_quick(const char* n);
147 // the default implementation of filename_ext() is in src/filename_ext.cxx and may be enough
148 virtual const char *filename_ext(const char *buf);
149 // implement to support fl_filename_name()
150 virtual const char *filename_name(const char *buf) {return buf;}
151 // implement to support fl_open_uri()
152 virtual int open_uri(const char * /*uri*/, char * /*msg*/, int /*msglen*/) {return 0;}
153 // the default implementation of use_tooltip_timeout_condition() may be enough
154 virtual int use_tooltip_timeout_condition() {return 0;}
155 // the default implementation of use_recent_tooltip_fix() may be enough
156 virtual int use_recent_tooltip_fix() {return 0;}
157 // the default implementation of need_test_shortcut_extra() may be enough
158 virtual int need_test_shortcut_extra() {return 0;}
159 // implement to support Fl_File_Browser::load()
160 virtual int file_browser_load_filesystem(Fl_File_Browser *, char * /*filename*/, int /*lname*/, Fl_File_Icon *) {return 0;}
161 // the default implementation of file_browser_load_directory() should be enough
162 virtual int file_browser_load_directory(const char *directory, char *filename, size_t name_size,
163 dirent ***pfiles, Fl_File_Sort_F *sort,
164 char *errmsg=NULL, int errmsg_sz=0);
165 // implement to support Fl_Preferences
166 virtual void newUUID(char *uuidBuffer) { uuidBuffer[0] = 0; }
167 // implement to support Fl_Preferences
168 virtual char *preference_rootnode(Fl_Preferences *, Fl_Preferences::Root,
169 const char * /*vendor*/,
170 const char * /*application*/) {return NULL;}
171 // the default implementation of preferences_need_protection_check() may be enough
172 virtual int preferences_need_protection_check() {return 0;}
173 // implement to support Fl_Plugin_Manager::load()
174 virtual void *load(const char *) {return NULL;}
175 // the default implementation is most probably enough
176 virtual void png_extra_rgba_processing(unsigned char * /*array*/, int /*w*/, int /*h*/) {}
177 // the default implementation is most probably enough
178 virtual const char *next_dir_sep(const char *start) { return strchr(start, '/');}
179 // implement to support threading
180 virtual void awake(void*) {}
181 virtual int lock() {return 1;}
182 virtual void unlock() {}
183 virtual void* thread_message() {return NULL;}
184 // implement to support Fl_File_Icon
185 virtual int file_type(const char *filename);
186 // implement to return the user's home directory name
187 virtual const char *home_directory_name() { return ""; }
188 // the default implementation is most probably enough
189 virtual const char *filesystems_label() { return "File Systems"; }
190 // return TRUE means \ same as / in file names
191 virtual int backslash_as_slash() {return 0;}
192 // return TRUE means : indicates a drive letter in file names
193 virtual int colon_is_drive() {return 0;}
194 // return TRUE means that files whose name begins with dot are hidden
195 virtual int dot_file_hidden() {return 0;}
196 // return TRUE when file names are case insensitive
197 virtual int case_insensitive_filenames() {return 0;}
198 // the implementations of local_to_latin1() and latin1_to_local() are in fl_encoding_latin1.cxx
199 virtual const char *local_to_latin1(const char *t, int n);
200 virtual const char *latin1_to_local(const char *t, int n);
201 // the implementations of local_to_mac_roman() and mac_roman_to_local() are in fl_encoding_mac_roman.cxx
202 virtual const char *local_to_mac_roman(const char *t, int n);
203 virtual const char *mac_roman_to_local(const char *t, int n);
204 // draw default tree view expando button
205 virtual void tree_draw_expando_button(int x, int y, bool state, bool active);
206 // the default implementation of tree_connector_style() is in Fl_Tree_Prefs.cxx and can be enough
207 virtual int tree_connector_style();
208 virtual void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0);
209 virtual void add_fd(int fd, Fl_FD_Handler cb, void* = 0);
210 virtual void remove_fd(int, int when);
211 virtual void remove_fd(int);
212 // the default implementation of open_callback() may be enough
213 virtual void open_callback(void (*)(const char *));
214 // The default implementation may be enough.
215 virtual void gettime(time_t *sec, int *usec);
216 // The default implementation of the next 4 functions may be enough.
217 virtual const char *shift_name() { return "Shift"; }
218 virtual const char *meta_name() { return "Meta"; }
219 virtual const char *alt_name() { return "Alt"; }
220 virtual const char *control_name() { return "Ctrl"; }
221 virtual Fl_Sys_Menu_Bar_Driver *sys_menu_bar_driver() { return NULL; }
222 virtual void lock_ring() {}
223 virtual void unlock_ring() {}
224 virtual double wait(double); // must FL_OVERRIDE
225 virtual int ready() { return 0; } // must FL_OVERRIDE
226 virtual int close_fd(int) {return -1;} // to close a file descriptor
227};
228
229#endif // FL_SYSTEM_DRIVER_H
230
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:122
Root
Define the scope of the preferences.
Definition Fl_Preferences.H:128
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:112
The Fl is the FLTK global (static) class containing state information and global methods for the curr...
Definition Fl.H:140
static int wait()
Waits until "something happens" and then returns.
Definition Fl.cxx:672
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:2434
static int ready()
This is similar to Fl::check() except this does not call Fl::flush() or any callbacks,...
Definition Fl.cxx:717
static void remove_fd(int, int when)
Removes a file descriptor handler.
Definition Fl.cxx:2241
static void add_fd(int fd, int when, Fl_FD_Handler cb, void *=0)
Adds file descriptor fd to listen to.
Definition Fl.cxx:2228
static int args_to_utf8(int argc, char **&argv)
Convert Windows commandline arguments to UTF-8.
Definition Fl.cxx:2514
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:109
int Fl_File_Sort_F(struct dirent **, struct dirent **)
File sorting function.
Definition filename.H:112
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 int x()
Returns the leftmost x coordinate of the main screen work area.
Definition screen_xywh.cxx:31
static int y()
Returns the topmost y coordinate of the main screen work area.
Definition screen_xywh.cxx:38
static void(* error)(const char *,...)
FLTK calls Fl::error() to output a normal error message.
Definition Fl.H:546
static void(* fatal)(const char *,...)
FLTK calls Fl::fatal() to output a fatal error message.
Definition Fl.H:563
static void(* warning)(const char *,...)
FLTK calls Fl::warning() to output a warning message.
Definition Fl.H:531