diff --git a/FL/Fl_System_Driver.H b/FL/Fl_System_Driver.H index bf11d440c..819bd0cd8 100644 --- a/FL/Fl_System_Driver.H +++ b/FL/Fl_System_Driver.H @@ -25,6 +25,7 @@ #define FL_SYSTEM_DRIVER_H #include +#include #ifdef __APPLE__ typedef struct CGContext* Fl_Offscreen; @@ -51,13 +52,14 @@ typedef struct _XRegion *Fl_Region; #endif // __APPLE__ /** - \brief A base class for platform specific window handling code. + \brief A base class for platform-specific system operations. */ class FL_EXPORT Fl_System_Driver { protected: 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(); static const int flNoValue; static const int flWidthValue; @@ -66,10 +68,23 @@ 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) virtual int arg_and_value(const char *name, const char *value) { return 0; } + // implement to process the -display argument virtual void display_arg(const char *arg) { } + // default implementation should be enough virtual int XParseGeometry(const char*, int*, int*, unsigned int*, unsigned int*); + static void warning(const char* format, ...); + // implement to set the default effect of Fl::warning() + virtual void warning(const char* format, va_list args); + static void error(const char* format, ...); + // implement to set the default effect of Fl::error() + virtual void error(const char* format, va_list args); + static void fatal(const char* format, ...); + // implement to set the default effect of Fl::error() + virtual void fatal(const char* format, va_list args); }; #endif // FL_SYSTEM_DRIVER_H diff --git a/src/Fl_System_Driver.cxx b/src/Fl_System_Driver.cxx index 711d9abaa..9a372885d 100644 --- a/src/Fl_System_Driver.cxx +++ b/src/Fl_System_Driver.cxx @@ -19,6 +19,8 @@ #include #include +#include +#include const int Fl_System_Driver::flNoValue = 0x0000; const int Fl_System_Driver::flWidthValue = 0x0004; @@ -38,6 +40,46 @@ 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); + va_end(args); +} + +void Fl_System_Driver::warning(const char* format, va_list args) { + vfprintf(stderr, format, args); + fputc('\n', stderr); + fflush(stderr); +} + +void Fl_System_Driver::error(const char* format, ...) { + va_list args; + va_start(args, format); + driver()->error(format, args); + va_end(args); +} + +void Fl_System_Driver::error(const char *format, va_list args) { + vfprintf(stderr, format, args); + fputc('\n', stderr); + fflush(stderr); +} + +void Fl_System_Driver::fatal(const char* format, ...) { + va_list args; + va_start(args, format); + driver()->fatal(format, args); + va_end(args); +} + +void Fl_System_Driver::fatal(const char *format, va_list args) { + vfprintf(stderr, format, args); + fputc('\n', stderr); + fflush(stderr); + exit(1); +} + /* the following function was stolen from the X sources as indicated. */ /* Copyright Massachusetts Institute of Technology 1985, 1986, 1987 */ diff --git a/src/Fl_abort.cxx b/src/Fl_abort.cxx index a54004155..f0125e905 100644 --- a/src/Fl_abort.cxx +++ b/src/Fl_abort.cxx @@ -16,83 +16,15 @@ // http://www.fltk.org/str.php // -// This method is in its own source file so that stdlib and stdio -// do not need to be included in Fl.cxx: // You can also override this by redefining all of these. #include -#include -#include +#include #include -#include "flstring.h" -#if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_Screen_Driver - native message box -#elif defined(FL_PORTING) -# pragma message "FL_PORTING: use native message box below if one is available" -#else -#endif - -#ifdef WIN32 -# include - -static void warning(const char *, ...) { - // Show nothing for warnings under WIN32... -} - -static void error(const char *format, ...) { - va_list args; - char buf[1024]; - va_start(args, format); - vsnprintf(buf, 1024, format, args); - va_end(args); - MessageBox(0,buf,"Error",MB_ICONEXCLAMATION|MB_SYSTEMMODAL); -} - -static void fatal(const char *format, ...) { - va_list args; - char buf[1024]; - va_start(args, format); - vsnprintf(buf, 1024, format, args); - va_end(args); - MessageBox(0,buf,"Error",MB_ICONSTOP|MB_SYSTEMMODAL); - ::exit(1); -} - -#else - -static void warning(const char *format, ...) { - va_list args; - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); - fputc('\n', stderr); - fflush(stderr); -} - -static void error(const char *format, ...) { - va_list args; - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); - fputc('\n', stderr); - fflush(stderr); -} - -static void fatal(const char *format, ...) { - va_list args; - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); - fputc('\n', stderr); - fflush(stderr); - ::exit(1); -} - -#endif - -void (*Fl::warning)(const char* format, ...) = ::warning; -void (*Fl::error)(const char* format, ...) = ::error; -void (*Fl::fatal)(const char* format, ...) = ::fatal; +void (*Fl::warning)(const char* format, ...) = Fl_System_Driver::warning; +void (*Fl::error)(const char* format, ...) = Fl_System_Driver::error; +void (*Fl::fatal)(const char* format, ...) = Fl_System_Driver::fatal; // // End of "$Id$". diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H index d213fd4af..c937c97da 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H @@ -26,6 +26,7 @@ #define FL_WINAPI_SYSTEM_DRIVER_H #include +#include /* Move everything here that manages the system interface. @@ -41,6 +42,9 @@ class Fl_WinAPI_System_Driver : public Fl_System_Driver { public: + virtual void warning(const char *format, va_list args); + virtual void error(const char *format, va_list args); + virtual void fatal(const char *format, va_list args); }; #endif // FL_WINAPI_SYSTEM_DRIVER_H diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx index b3678c097..8ea6113a0 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx @@ -19,6 +19,8 @@ #include "../../config_lib.h" #include "Fl_WinAPI_System_Driver.H" +#include +#include #if !defined(FL_DOXYGEN) const char* fl_local_alt = "Alt"; @@ -32,6 +34,24 @@ Fl_System_Driver *Fl_System_Driver::driver() { return d; } +void Fl_WinAPI_System_Driver::warning(const char *format, va_list args) { + // Show nothing for warnings under WIN32... +} + +void Fl_WinAPI_System_Driver::error(const char *format, va_list args) { + char buf[1024]; + vsnprintf(buf, 1024, format, args); + MessageBox(0,buf,"Error",MB_ICONEXCLAMATION|MB_SYSTEMMODAL); +} + +void Fl_WinAPI_System_Driver::fatal(const char *format, va_list args) { + char buf[1024]; + vsnprintf(buf, 1024, format, args); + MessageBox(0,buf,"Error",MB_ICONSTOP|MB_SYSTEMMODAL); + ::exit(1); +} + + // // End of "$Id$". //