Skip to content

Commit

Permalink
Replace Fl_System_Driver::driver() by Fl::system_driver()
Browse files Browse the repository at this point in the history
for coherence with the Fl::screen_driver() function.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11494 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Apr 1, 2016
1 parent 524ebce commit f1a157b
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 42 deletions.
3 changes: 2 additions & 1 deletion FL/Fl.H
Expand Up @@ -23,7 +23,7 @@
#ifndef Fl_H
# define Fl_H

#include <FL/Fl_System_Driver.H>
#include <FL/Fl_System_Driver.H> // for FL_SOCKET
#ifdef FLTK_HAVE_CAIRO
# include <FL/Fl_Cairo.H>
#endif
Expand Down Expand Up @@ -135,6 +135,7 @@ private:
public:

static Fl_Screen_Driver *screen_driver();
static Fl_System_Driver *system_driver();

public: // run time information about compile time configuration
/** \defgroup cfg_gfx runtime graphics driver configuration */
Expand Down
4 changes: 3 additions & 1 deletion FL/Fl_Screen_Driver.H
Expand Up @@ -20,7 +20,9 @@
#define FL_SCREEN_DRIVER_H

#include <FL/Fl_Device.H>
#include <FL/Fl.H>
#include <FL/fl_types.h>
#include <FL/Fl.H> // for Fl_Timeout_Handler


// TODO: add text composition?
// TODO: add Fl::display
Expand Down
6 changes: 4 additions & 2 deletions FL/Fl_System_Driver.H
Expand Up @@ -65,12 +65,13 @@ typedef int FL_SOCKET;
\brief A base class for platform-specific system operations.
*/
class FL_EXPORT Fl_System_Driver {
friend class Fl;
protected:
// implement once for each platform
static Fl_System_Driver *newSystemDriver();
Fl_System_Driver();
public:
virtual ~Fl_System_Driver();
// copy the implementation in Fl_XXX_System_Driver.cxx to the corresponding file for the new platform
static Fl_System_Driver *driver();
// These flags are useful after calling XParseGeometry(). They indicate which of its arguments
// contain meaningful data upon return.
static const int flNoValue;
Expand All @@ -80,6 +81,7 @@ public:
static const int flYValue;
static const int flXNegative;
static const int flYNegative;

// implement if the system adds unwanted program argument(s)
virtual int single_arg(const char *arg) { return 0; }
// implement if the system adds unwanted program argument pair(s)
Expand Down
6 changes: 6 additions & 0 deletions src/Fl.cxx
Expand Up @@ -181,6 +181,12 @@ Fl_Screen_Driver *Fl::screen_driver()
return screen_driver_;
}

Fl_System_Driver *Fl::system_driver()
{
static Fl_System_Driver* system_driver_ = Fl_System_Driver::newSystemDriver();
return system_driver_;
}

//
// 'Fl::version()' - Return the API version number...
//
Expand Down
6 changes: 3 additions & 3 deletions src/Fl_System_Driver.cxx
Expand Up @@ -46,7 +46,7 @@ Fl_System_Driver::~Fl_System_Driver()
void Fl_System_Driver::warning(const char* format, ...) {
va_list args;
va_start(args, format);
driver()->warning(format, args);
Fl::system_driver()->warning(format, args);
va_end(args);
}

Expand All @@ -59,7 +59,7 @@ void Fl_System_Driver::warning(const char* format, va_list args) {
void Fl_System_Driver::error(const char* format, ...) {
va_list args;
va_start(args, format);
driver()->error(format, args);
Fl::system_driver()->error(format, args);
va_end(args);
}

Expand All @@ -72,7 +72,7 @@ void Fl_System_Driver::error(const char *format, va_list args) {
void Fl_System_Driver::fatal(const char* format, ...) {
va_list args;
va_start(args, format);
driver()->fatal(format, args);
Fl::system_driver()->fatal(format, args);
va_end(args);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Fl_arg.cxx
Expand Up @@ -157,7 +157,7 @@ int Fl::arg(int argc, char **argv, int &i) {
Fl_Tooltip::disable();
i++;
return 1;
} else if (Fl_System_Driver::driver()->single_arg(s)) {
} else if (Fl::system_driver()->single_arg(s)) {
i++;
}

Expand All @@ -168,14 +168,14 @@ int Fl::arg(int argc, char **argv, int &i) {
if (fl_match(s, "geometry")) {

int flags, gx, gy; unsigned int gw, gh;
flags = Fl_System_Driver::driver()->XParseGeometry(v, &gx, &gy, &gw, &gh);
flags = Fl::system_driver()->XParseGeometry(v, &gx, &gy, &gw, &gh);
if (!flags) return 0;
geometry = v;

} else if (fl_match(s, "display", 2)) {
Fl_System_Driver::driver()->display_arg(v);
Fl::system_driver()->display_arg(v);

} else if (Fl_System_Driver::driver()->arg_and_value(s, v)) {
} else if (Fl::system_driver()->arg_and_value(s, v)) {
// nothing to do

} else if (fl_match(s, "title", 2)) {
Expand Down Expand Up @@ -283,7 +283,7 @@ void Fl_Window::show(int argc, char **argv) {
if (!beenhere) {
if (geometry) {
int fl = 0, gx = x(), gy = y(); unsigned int gw = w(), gh = h();
fl = Fl_System_Driver::driver()->XParseGeometry(geometry, &gx, &gy, &gw, &gh);
fl = Fl::system_driver()->XParseGeometry(geometry, &gx, &gy, &gw, &gh);
if (fl & Fl_System_Driver::flXNegative) gx = Fl::w()-w()+gx;
if (fl & Fl_System_Driver::flYNegative) gy = Fl::h()-h()+gy;
// int mw,mh; minsize(mw,mh);
Expand Down
12 changes: 9 additions & 3 deletions src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
Expand Up @@ -40,9 +40,15 @@ const char* fl_local_meta = "⌘\\"; // U+2318 (place of interest sign)
//const char* fl_local_shift = "\xe2\x87\xa7\\"; // U+21E7 (upwards white arrow)
const char* fl_local_shift = "\\"; // U+21E7 (upwards white arrow)

Fl_System_Driver *Fl_System_Driver::driver() {
static Fl_System_Driver *d = new Fl_Darwin_System_Driver();
return d;

/**
Creates a driver that manages all screen and display related calls.
This function must be implemented once for every platform.
*/
Fl_System_Driver *Fl_System_Driver::newSystemDriver()
{
return new Fl_Darwin_System_Driver();
}

Fl_Darwin_System_Driver::Fl_Darwin_System_Driver() {
Expand Down
11 changes: 8 additions & 3 deletions src/drivers/Posix/Fl_Posix_System_Driver.cxx
Expand Up @@ -30,9 +30,14 @@ const char* fl_local_ctrl = "Ctrl";
const char* fl_local_meta = "Meta";
const char* fl_local_shift = "Shift";

Fl_System_Driver *Fl_System_Driver::driver() {
static Fl_System_Driver *d = new Fl_Posix_System_Driver();
return d;
/**
Creates a driver that manages all screen and display related calls.
This function must be implemented once for every platform.
*/
Fl_System_Driver *Fl_System_Driver::newSystemDriver()
{
return new Fl_Posix_System_Driver();
}

void Fl_Posix_System_Driver::display_arg(const char *arg) {
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/PostScript/Fl_PostScript.cxx
Expand Up @@ -145,7 +145,7 @@ int Fl_PostScript_Graphics_Driver::clocale_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
int retval = Fl_System_Driver::driver()->clocale_printf(output, format, args);
int retval = Fl::system_driver()->clocale_printf(output, format, args);
va_end(args);
return retval;
}
Expand Down
12 changes: 8 additions & 4 deletions src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
Expand Up @@ -39,10 +39,14 @@ static wchar_t *mbwbuf = NULL;
static wchar_t *wbuf = NULL;
static wchar_t *wbuf1 = NULL;


Fl_System_Driver *Fl_System_Driver::driver() {
static Fl_System_Driver *d = new Fl_WinAPI_System_Driver();
return d;
/**
Creates a driver that manages all screen and display related calls.
This function must be implemented once for every platform.
*/
Fl_System_Driver *Fl_System_Driver::newSystemDriver()
{
return new Fl_WinAPI_System_Driver();
}

void Fl_WinAPI_System_Driver::warning(const char *format, va_list args) {
Expand Down
39 changes: 20 additions & 19 deletions src/fl_utf8.cxx
Expand Up @@ -18,6 +18,7 @@
// http://www.fltk.org/str.php
//

#include <FL/Fl.H>
#include <FL/Fl_System_Driver.H>
#include <FL/filename.H>
#include <stdarg.h>
Expand Down Expand Up @@ -282,7 +283,7 @@ unsigned int fl_nonspacing(unsigned int ucs)
*/
char * fl_utf2mbcs(const char *s)
{
return Fl_System_Driver::driver()->utf2mbcs(s);
return Fl::system_driver()->utf2mbcs(s);
}

/** Cross-platform function to get environment variables with a UTF-8 encoded
Expand All @@ -300,7 +301,7 @@ char * fl_utf2mbcs(const char *s)
*/

char *fl_getenv(const char* v) {
return Fl_System_Driver::driver()->getenv(v);
return Fl::system_driver()->getenv(v);
}


Expand All @@ -320,7 +321,7 @@ int fl_open(const char* f, int oflags, ...)
va_start(ap, oflags);
pmode = va_arg (ap, int);
va_end(ap);
return Fl_System_Driver::driver()->open(f, oflags, pmode);
return Fl::system_driver()->open(f, oflags, pmode);
}


Expand All @@ -334,7 +335,7 @@ int fl_open(const char* f, int oflags, ...)
\sa fl_open().
*/
FILE *fl_fopen(const char* f, const char *mode) {
return Fl_System_Driver::driver()->fopen(f, mode);
return Fl::system_driver()->fopen(f, mode);
}

/** Cross-platform function to run a system command with a UTF-8 encoded string.
Expand All @@ -350,12 +351,12 @@ FILE *fl_fopen(const char* f, const char *mode) {

int fl_system(const char* cmd)
{
return Fl_System_Driver::driver()->system(cmd);
return Fl::system_driver()->system(cmd);
}

int fl_execvp(const char *file, char *const *argv)
{
return Fl_System_Driver::driver()->execvp(file, argv);
return Fl::system_driver()->execvp(file, argv);
}

/** Cross-platform function to set a files mode() with a UTF-8 encoded
Expand All @@ -369,7 +370,7 @@ int fl_execvp(const char *file, char *const *argv)
\return the return value of _wchmod() on Windows or chmod() on other platforms.
*/
int fl_chmod(const char* f, int mode) {
return Fl_System_Driver::driver()->chmod(f, mode);
return Fl::system_driver()->chmod(f, mode);
}

/** Cross-platform function to test a files access() with a UTF-8 encoded
Expand All @@ -383,7 +384,7 @@ int fl_chmod(const char* f, int mode) {
\return the return value of _waccess() on Windows or access() on other platforms.
*/
int fl_access(const char* f, int mode) {
return Fl_System_Driver::driver()->access(f, mode);
return Fl::system_driver()->access(f, mode);
}

/** Cross-platform function to stat() a file using a UTF-8 encoded
Expand All @@ -397,7 +398,7 @@ int fl_access(const char* f, int mode) {
\return the return value of _wstat() on Windows or stat() on other platforms.
*/
int fl_stat(const char* f, struct stat *b) {
return Fl_System_Driver::driver()->stat(f, b);
return Fl::system_driver()->stat(f, b);
}

// TODO: add fl_chdir if we have fl_getcwd
Expand All @@ -416,7 +417,7 @@ char *fl_getcwd(char* b, int l) {
if (b == NULL) {
b = (char*) malloc(l+1);
}
return Fl_System_Driver::driver()->getcwd(b, l);
return Fl::system_driver()->getcwd(b, l);
}

/** Cross-platform function to unlink() (that is, delete) a file using
Expand All @@ -429,7 +430,7 @@ char *fl_getcwd(char* b, int l) {
\return the return value of _wunlink() on Windows or unlink() on other platforms.
*/
int fl_unlink(const char* f) {
return Fl_System_Driver::driver()->unlink(f);
return Fl::system_driver()->unlink(f);
}

/** Cross-platform function to create a directory with a UTF-8 encoded
Expand All @@ -443,7 +444,7 @@ int fl_unlink(const char* f) {
\return the return value of _wmkdir() on Windows or mkdir() on other platforms.
*/
int fl_mkdir(const char* f, int mode) {
return Fl_System_Driver::driver()->mkdir(f, mode);
return Fl::system_driver()->mkdir(f, mode);
}

/** Cross-platform function to remove a directory with a UTF-8 encoded
Expand All @@ -456,7 +457,7 @@ int fl_mkdir(const char* f, int mode) {
\return the return value of _wrmdir() on Windows or rmdir() on other platforms.
*/
int fl_rmdir(const char* f) {
return Fl_System_Driver::driver()->rmdir(f);
return Fl::system_driver()->rmdir(f);
}

/** Cross-platform function to rename a filesystem object using
Expand All @@ -470,7 +471,7 @@ int fl_rmdir(const char* f) {
\return the return value of _wrename() on Windows or rename() on other platforms.
*/
int fl_rename(const char* f, const char *n) {
return Fl_System_Driver::driver()->rename(f, n);
return Fl::system_driver()->rename(f, n);
}

/** Cross-platform function to recursively create a path in the file system.
Expand Down Expand Up @@ -1144,7 +1145,7 @@ int fl_wcwidth(const char* src) {
unsigned fl_utf8towc(const char* src, unsigned srclen,
wchar_t* dst, unsigned dstlen)
{
return Fl_System_Driver::driver()->utf8towc(src, srclen, dst, dstlen);
return Fl::system_driver()->utf8towc(src, srclen, dst, dstlen);
}


Expand Down Expand Up @@ -1177,7 +1178,7 @@ unsigned fl_utf8towc(const char* src, unsigned srclen,
*/
unsigned fl_utf8fromwc(char* dst, unsigned dstlen, const wchar_t* src, unsigned srclen)
{
return Fl_System_Driver::driver()->utf8fromwc(dst, dstlen, src, srclen);
return Fl::system_driver()->utf8fromwc(dst, dstlen, src, srclen);
}


Expand All @@ -1195,7 +1196,7 @@ unsigned fl_utf8fromwc(char* dst, unsigned dstlen, const wchar_t* src, unsigned
*/
int fl_utf8locale()
{
return Fl_System_Driver::driver()->utf8locale();
return Fl::system_driver()->utf8locale();
}


Expand Down Expand Up @@ -1225,7 +1226,7 @@ unsigned fl_utf8to_mb(const char* src, unsigned srclen, char* dst, unsigned dstl
}
return srclen;
}
return Fl_System_Driver::driver()->utf8to_mb(src, srclen, dst, dstlen);
return Fl::system_driver()->utf8to_mb(src, srclen, dst, dstlen);
}


Expand Down Expand Up @@ -1257,7 +1258,7 @@ unsigned fl_utf8from_mb(char* dst, unsigned dstlen, const char* src, unsigned sr
}
return srclen;
}
return Fl_System_Driver::driver()->utf8from_mb(dst, dstlen, src, srclen);
return Fl::system_driver()->utf8from_mb(dst, dstlen, src, srclen);
}

//============================================================
Expand Down

0 comments on commit f1a157b

Please sign in to comment.