Fl_System_Driver.H 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // "$Id: Fl_System_Driver.H 12549 2017-11-10 12:56:00Z AlbrechtS $"
  3. //
  4. // A base class for platform specific system calls
  5. // for the Fast Light Tool Kit (FLTK).
  6. //
  7. // Copyright 2010-2017 by Bill Spitzak and others.
  8. //
  9. // This library is free software. Distribution and use rights are outlined in
  10. // the file "COPYING" which should have been included with this file. If this
  11. // file is missing or damaged, see the license at:
  12. //
  13. // http://www.fltk.org/COPYING.php
  14. //
  15. // Please report all bugs and problems on the following page:
  16. //
  17. // http://www.fltk.org/str.php
  18. //
  19. /** \file Fl_System_Driver.H
  20. \brief declaration of class Fl_System_Driver.
  21. */
  22. #ifndef FL_SYSTEM_DRIVER_H
  23. #define FL_SYSTEM_DRIVER_H
  24. #include <FL/Fl.H>
  25. #include <FL/Fl_Export.H>
  26. #include <FL/filename.H>
  27. #include <FL/Fl_Preferences.H>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <stdarg.h>
  31. #include <string.h>
  32. #include <time.h>
  33. class Fl_File_Icon;
  34. class Fl_File_Browser;
  35. class Fl_Pixmap;
  36. class Fl_Widget;
  37. /**
  38. \brief A base class for platform-specific system operations.
  39. This class is only for internal use by the FLTK library.
  40. Each supported platform implements several of the virtual methods of this class.
  41. */
  42. class FL_EXPORT Fl_System_Driver {
  43. friend class Fl;
  44. protected:
  45. // implement once for each platform
  46. static Fl_System_Driver *newSystemDriver();
  47. Fl_System_Driver();
  48. struct Keyname {unsigned int key; const char* name;};
  49. static Keyname table[];
  50. public:
  51. virtual ~Fl_System_Driver();
  52. // These flags are useful after calling XParseGeometry(). They indicate which of its arguments
  53. // contain meaningful data upon return.
  54. static const int fl_NoValue;
  55. static const int fl_WidthValue;
  56. static const int fl_HeightValue;
  57. static const int fl_XValue;
  58. static const int fl_YValue;
  59. static const int fl_XNegative;
  60. static const int fl_YNegative;
  61. // implement if the system adds unwanted program argument(s)
  62. virtual int single_arg(const char *arg) { return 0; }
  63. // implement if the system adds unwanted program argument pair(s)
  64. virtual int arg_and_value(const char *name, const char *value) { return 0; }
  65. // implement to process the -display argument
  66. virtual void display_arg(const char *arg) { }
  67. // default implementation should be enough
  68. virtual int XParseGeometry(const char* string, int* x, int* y, unsigned int* width, unsigned int* height);
  69. static void warning(const char* format, ...);
  70. // implement to set the default effect of Fl::warning()
  71. virtual void warning(const char* format, va_list args);
  72. static void error(const char* format, ...);
  73. // implement to set the default effect of Fl::error()
  74. virtual void error(const char* format, va_list args);
  75. static void fatal(const char* format, ...);
  76. // implement to set the default effect of Fl::error()
  77. virtual void fatal(const char* format, va_list args);
  78. // implement these to support cross-platform file operations
  79. virtual char *utf2mbcs(const char *s) {return (char*)s;}
  80. virtual char *getenv(const char* v) {return NULL;}
  81. virtual int putenv(char* v) {return -1;}
  82. virtual int open(const char* f, int oflags, int pmode) {return -1;}
  83. // Note: the default implementation ignores the 'binary' argument.
  84. // Some platforms (notably Windows) may use this argument.
  85. virtual int open_ext(const char* f, int binary, int oflags, int pmode) {
  86. return this->open(f, oflags, pmode);
  87. }
  88. virtual FILE *fopen(const char* f, const char *mode);
  89. virtual int system(const char* cmd) {return -1;}
  90. virtual int execvp(const char *file, char *const *argv) {return -1;}
  91. virtual int chmod(const char* f, int mode) {return -1;}
  92. virtual int access(const char* f, int mode) { return -1;}
  93. virtual int stat(const char* f, struct stat *b) { return -1;}
  94. virtual char *getcwd(char* b, int l) {return NULL;}
  95. virtual int chdir(const char* path) {return -1;}
  96. virtual int unlink(const char* fname) {return -1;}
  97. virtual int mkdir(const char* f, int mode) {return -1;}
  98. virtual int rmdir(const char* f) {return -1;}
  99. virtual int rename(const char* f, const char *n) {return -1;}
  100. // the default implementation of these utf8... functions should be enough
  101. virtual unsigned utf8towc(const char* src, unsigned srclen, wchar_t* dst, unsigned dstlen);
  102. virtual unsigned utf8fromwc(char* dst, unsigned dstlen, const wchar_t* src, unsigned srclen);
  103. virtual int utf8locale() {return 1;}
  104. virtual unsigned utf8to_mb(const char* src, unsigned srclen, char* dst, unsigned dstlen);
  105. virtual unsigned utf8from_mb(char* dst, unsigned dstlen, const char* src, unsigned srclen);
  106. // implement to shield fprintf() from locale changes in decimal point
  107. virtual int clocale_printf(FILE *output, const char *format, va_list args);
  108. // implement functions telling whether a key is pressed
  109. virtual int event_key(int k) {return 0;}
  110. virtual int get_key(int k) {return 0;}
  111. // implement scandir-like function
  112. virtual int filename_list(const char *d, dirent ***list, int (*sort)(struct dirent **, struct dirent **) ) {return -1;}
  113. // the default implementation of filename_expand() may be enough
  114. virtual int filename_expand(char *to, int tolen, const char *from);
  115. // to implement
  116. virtual const char *getpwnam(const char *login) {return NULL;}
  117. // the default implementation of filename_relative() is in src/filename_absolute.cxx and may be enough
  118. virtual int filename_relative(char *to, int tolen, const char *from, const char *base);
  119. // the default implementation of filename_absolute() is in src/filename_absolute.cxx and may be enough
  120. virtual int filename_absolute(char *to, int tolen, const char *from);
  121. // the default implementation of filename_isdir() is in src/filename_isdir.cxx and may be enough
  122. virtual int filename_isdir(const char* n);
  123. // the default implementation of filename_isdir_quick() is in src/filename_isdir.cxx and may be enough
  124. virtual int filename_isdir_quick(const char* n);
  125. // the default implementation of filename_ext() is in src/filename_ext.cxx and may be enough
  126. virtual const char *filename_ext(const char *buf);
  127. // implement to support fl_filename_name()
  128. virtual const char *filename_name(const char *buf) {return buf;}
  129. // whether a platform uses additional code in Fl_Menu::handle(int e)
  130. virtual int need_menu_handle_part2() {return 0;}
  131. // whether a platform uses additional code in Fl_Menu::handle_part1(int e)
  132. virtual int need_menu_handle_part1_extra() {return 0;}
  133. // implement to support fl_open_uri()
  134. virtual int open_uri(const char *uri, char *msg, int msglen) {return 0;}
  135. // the default implementation of use_tooltip_timeout_condition() may be enough
  136. virtual int use_tooltip_timeout_condition() {return 0;}
  137. // the default implementation of use_recent_tooltip_fix() may be enough
  138. virtual int use_recent_tooltip_fix() {return 0;}
  139. // the default implementation of shortcut_add_key_name() is in src/fl_shortcut.cxx
  140. virtual const char *shortcut_add_key_name(unsigned key, char *p, char *buf, const char **);
  141. // the default implementation of need_test_shortcut_extra() may be enough
  142. virtual int need_test_shortcut_extra() {return 0;}
  143. // implement to support Fl_File_Browser::load()
  144. virtual int file_browser_load_filesystem(Fl_File_Browser *browser, char *filename, int lname, Fl_File_Icon *icon) {return 0;}
  145. // the default implementation of file_browser_load_directory() should be enough
  146. virtual int file_browser_load_directory(const char *directory, char *filename, size_t name_size, dirent ***pfiles, Fl_File_Sort_F *sort);
  147. // implement to support Fl_Preferences
  148. virtual void newUUID(char *uuidBuffer) { uuidBuffer[0] = 0; }
  149. // implement to support Fl_Preferences
  150. virtual char *preference_rootnode(Fl_Preferences *prefs, Fl_Preferences::Root root, const char *vendor,
  151. const char *application) {return NULL;}
  152. // the default implementation of preferences_need_protection_check() may be enough
  153. virtual int preferences_need_protection_check() {return 0;}
  154. // implement to support Fl_Plugin_Manager::load()
  155. virtual void *dlopen(const char *filename) {return NULL;}
  156. // the default implementation is most probably enough
  157. virtual void png_extra_rgba_processing(unsigned char *array, int w, int h) {}
  158. // the default implementation is most probably enough
  159. virtual const char *next_dir_sep(const char *start) { return strchr(start, '/');}
  160. // implement to support threading
  161. virtual void awake(void*) {}
  162. virtual int lock() {return 1;}
  163. virtual void unlock() {}
  164. virtual void* thread_message() {return NULL;}
  165. // implement to support Fl_File_Icon
  166. virtual int file_type(const char *filename);
  167. // the default implementations of pixmap_extra_transparent_processing() and make_unused_color() and are most probably enough
  168. virtual int pixmap_extra_transparent_processing() {return 0;}
  169. virtual void make_unused_color(unsigned char &r, unsigned char &g, unsigned char &b) {}
  170. // implement to return the user's home directory name
  171. virtual const char *home_directory_name() { return ""; }
  172. // the default implementation is most probably enough
  173. virtual const char *filesystems_label() { return "File Systems"; }
  174. // return TRUE means \ same as / in file names
  175. virtual int backslash_as_slash() {return 0;}
  176. // return TRUE means : indicates a drive letter in file names
  177. virtual int colon_is_drive() {return 0;}
  178. // return TRUE means that files whose name begins with dot are hidden
  179. virtual int dot_file_hidden() {return 0;}
  180. // return TRUE when file names are case insensitive
  181. virtual int case_insensitive_filenames() {return 0;}
  182. // the implementations of local_to_latin1() and latin1_to_local() are in fl_encoding_latin1.cxx
  183. virtual const char *local_to_latin1(const char *t, int n);
  184. virtual const char *latin1_to_local(const char *t, int n);
  185. // the implementations of local_to_mac_roman() and mac_roman_to_local() are in fl_encoding_mac_roman.cxx
  186. virtual const char *local_to_mac_roman(const char *t, int n);
  187. virtual const char *mac_roman_to_local(const char *t, int n);
  188. // the default implementation is most probably enough
  189. virtual void own_colormap() {}
  190. // the default implementations of tree_openpixmap() and tree_closepixmap() are
  191. // in Fl_Tree_Prefs.cxx and can be enough
  192. virtual Fl_Pixmap *tree_openpixmap();
  193. virtual Fl_Pixmap *tree_closepixmap();
  194. static const char *const tree_open_xpm[]; // used by tree_openpixmap()
  195. static const char * const tree_close_xpm[]; // used by tree_closepixmap()
  196. // the default implementation of tree_connector_style() is in Fl_Tree_Prefs.cxx and can be enough
  197. virtual int tree_connector_style();
  198. // implement to support copy-to-clipboard
  199. virtual void copy(const char *stuff, int len, int clipboard, const char *type) {}
  200. // implement to support paste-from-clipboard
  201. virtual void paste(Fl_Widget &receiver, int clipboard, const char *type) {}
  202. // implement to support paste-from-clipboard
  203. virtual int clipboard_contains(const char *type) {return 0;}
  204. // implement to support paste-from-clipboard
  205. virtual void clipboard_notify_change() {}
  206. virtual void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0);
  207. virtual void add_fd(int fd, Fl_FD_Handler cb, void* = 0);
  208. virtual void remove_fd(int, int when);
  209. virtual void remove_fd(int);
  210. // the default implementation of open_callback() may be enough
  211. virtual void open_callback(void (*)(const char *));
  212. // The default implementation may be enough.
  213. virtual void gettime(time_t *sec, int *usec);
  214. // The default implementation of the next 4 functions may be enough.
  215. virtual const char *shift_name() { return "Shift"; }
  216. virtual const char *meta_name() { return "Meta"; }
  217. virtual const char *alt_name() { return "Alt"; }
  218. virtual const char *control_name() { return "Ctrl"; }
  219. };
  220. #endif // FL_SYSTEM_DRIVER_H
  221. //
  222. // End of "$Id: Fl_System_Driver.H 12549 2017-11-10 12:56:00Z AlbrechtS $".
  223. //