Rewrite file src/Fl_arg.cxx under the driver model. Begin giving flesh to the Fl_System_Driver class.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11448 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
3dfec155ad
commit
6284720098
@ -54,9 +54,22 @@ typedef struct _XRegion *Fl_Region;
|
||||
\brief A base class for platform specific window handling code.
|
||||
*/
|
||||
class FL_EXPORT Fl_System_Driver {
|
||||
public:
|
||||
protected:
|
||||
Fl_System_Driver();
|
||||
public:
|
||||
virtual ~Fl_System_Driver();
|
||||
static Fl_System_Driver *driver();
|
||||
static const int flNoValue;
|
||||
static const int flWidthValue;
|
||||
static const int flHeightValue;
|
||||
static const int flXValue;
|
||||
static const int flYValue;
|
||||
static const int flXNegative;
|
||||
static const int flYNegative;
|
||||
virtual int single_arg(const char *arg) { return 0; }
|
||||
virtual int arg_and_value(const char *name, const char *value) { return 0; }
|
||||
virtual void display_arg(const char *arg) { }
|
||||
virtual int XParseGeometry(const char*, int*, int*, unsigned int*, unsigned int*);
|
||||
};
|
||||
|
||||
#endif // FL_SYSTEM_DRIVER_H
|
||||
|
@ -17,8 +17,16 @@
|
||||
//
|
||||
|
||||
|
||||
#include "config_lib.h"
|
||||
#include <FL/Fl_System_Driver.H>
|
||||
#include <stdlib.h>
|
||||
|
||||
const int Fl_System_Driver::flNoValue = 0x0000;
|
||||
const int Fl_System_Driver::flWidthValue = 0x0004;
|
||||
const int Fl_System_Driver::flHeightValue = 0x0008;
|
||||
const int Fl_System_Driver::flXValue = 0x0001;
|
||||
const int Fl_System_Driver::flYValue = 0x0002;
|
||||
const int Fl_System_Driver::flXNegative = 0x0010;
|
||||
const int Fl_System_Driver::flYNegative = 0x0020;
|
||||
|
||||
|
||||
Fl_System_Driver::Fl_System_Driver()
|
||||
@ -30,6 +38,139 @@ Fl_System_Driver::~Fl_System_Driver()
|
||||
{
|
||||
}
|
||||
|
||||
/* the following function was stolen from the X sources as indicated. */
|
||||
|
||||
/* Copyright Massachusetts Institute of Technology 1985, 1986, 1987 */
|
||||
/* $XConsortium: XParseGeom.c,v 11.18 91/02/21 17:23:05 rws Exp $ */
|
||||
|
||||
/*
|
||||
Permission to use, copy, modify, distribute, and sell this software and its
|
||||
documentation for any purpose is hereby granted without fee, provided that
|
||||
the above copyright notice appear in all copies and that both that
|
||||
copyright notice and this permission notice appear in supporting
|
||||
documentation, and that the name of M.I.T. not be used in advertising or
|
||||
publicity pertaining to distribution of the software without specific,
|
||||
written prior permission. M.I.T. makes no representations about the
|
||||
suitability of this software for any purpose. It is provided "as is"
|
||||
without express or implied warranty.
|
||||
*/
|
||||
|
||||
/*
|
||||
* XParseGeometry parses strings of the form
|
||||
* "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
|
||||
* width, height, xoffset, and yoffset are unsigned integers.
|
||||
* Example: "=80x24+300-49"
|
||||
* The equal sign is optional.
|
||||
* It returns a bitmask that indicates which of the four values
|
||||
* were actually found in the string. For each value found,
|
||||
* the corresponding argument is updated; for each value
|
||||
* not found, the corresponding argument is left unchanged.
|
||||
*/
|
||||
|
||||
static int ReadInteger(char* string, char** NextString)
|
||||
{
|
||||
int Result = 0;
|
||||
int Sign = 1;
|
||||
|
||||
if (*string == '+')
|
||||
string++;
|
||||
else if (*string == '-') {
|
||||
string++;
|
||||
Sign = -1;
|
||||
}
|
||||
for (; (*string >= '0') && (*string <= '9'); string++) {
|
||||
Result = (Result * 10) + (*string - '0');
|
||||
}
|
||||
*NextString = string;
|
||||
if (Sign >= 0)
|
||||
return (Result);
|
||||
else
|
||||
return (-Result);
|
||||
}
|
||||
|
||||
int Fl_System_Driver::XParseGeometry(const char* string, int* x, int* y,
|
||||
unsigned int* width, unsigned int* height)
|
||||
{
|
||||
int mask = Fl_System_Driver::flNoValue;
|
||||
char *strind;
|
||||
unsigned int tempWidth = 0, tempHeight = 0;
|
||||
int tempX = 0, tempY = 0;
|
||||
char *nextCharacter;
|
||||
|
||||
if ( (string == NULL) || (*string == '\0')) return(mask);
|
||||
if (*string == '=')
|
||||
string++; /* ignore possible '=' at beg of geometry spec */
|
||||
|
||||
strind = (char *)string;
|
||||
if (*strind != '+' && *strind != '-' && *strind != 'x') {
|
||||
tempWidth = ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return (0);
|
||||
strind = nextCharacter;
|
||||
mask |= flWidthValue;
|
||||
}
|
||||
|
||||
if (*strind == 'x' || *strind == 'X') {
|
||||
strind++;
|
||||
tempHeight = ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return (0);
|
||||
strind = nextCharacter;
|
||||
mask |= flHeightValue;
|
||||
}
|
||||
|
||||
if ((*strind == '+') || (*strind == '-')) {
|
||||
if (*strind == '-') {
|
||||
strind++;
|
||||
tempX = -ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return (0);
|
||||
strind = nextCharacter;
|
||||
mask |= flXNegative;
|
||||
|
||||
} else {
|
||||
strind++;
|
||||
tempX = ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return(0);
|
||||
strind = nextCharacter;
|
||||
}
|
||||
mask |= flXValue;
|
||||
if ((*strind == '+') || (*strind == '-')) {
|
||||
if (*strind == '-') {
|
||||
strind++;
|
||||
tempY = -ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return(0);
|
||||
strind = nextCharacter;
|
||||
mask |= flYNegative;
|
||||
|
||||
} else {
|
||||
strind++;
|
||||
tempY = ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return(0);
|
||||
strind = nextCharacter;
|
||||
}
|
||||
mask |= flYValue;
|
||||
}
|
||||
}
|
||||
|
||||
/* If strind isn't at the end of the string the it's an invalid
|
||||
geometry specification. */
|
||||
|
||||
if (*strind != '\0') return (0);
|
||||
|
||||
if (mask & flXValue)
|
||||
*x = tempX;
|
||||
if (mask & flYValue)
|
||||
*y = tempY;
|
||||
if (mask & flWidthValue)
|
||||
*width = tempWidth;
|
||||
if (mask & flHeightValue)
|
||||
*height = tempHeight;
|
||||
return (mask);
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
|
193
src/Fl_arg.cxx
193
src/Fl_arg.cxx
@ -20,34 +20,15 @@
|
||||
// You do not need to call this! Feel free to make up your own switches.
|
||||
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/x.H>
|
||||
#include <FL/Fl_Window.H>
|
||||
#include <FL/Fl_Window_Driver.H>
|
||||
#include <FL/Fl_Graphics_Driver.H>
|
||||
#include <FL/Fl_System_Driver.H>
|
||||
#include <FL/Fl_Tooltip.H>
|
||||
#include <FL/filename.H>
|
||||
#include <FL/fl_draw.H>
|
||||
#include <ctype.h>
|
||||
#include "flstring.h"
|
||||
|
||||
#if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_System_Driver - command line arguments
|
||||
#elif defined(FL_PORTING)
|
||||
# pragma message "FL_PORTING: implement special command line handling"
|
||||
#else
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(__APPLE__) || defined(FL_PORTING) // PORTME: Fl_System_Driver - parse geometry
|
||||
int XParseGeometry(const char*, int*, int*, unsigned int*, unsigned int*);
|
||||
# define NoValue 0x0000
|
||||
# define XValue 0x0001
|
||||
# define YValue 0x0002
|
||||
# define WidthValue 0x0004
|
||||
# define HeightValue 0x0008
|
||||
# define AllValues 0x000F
|
||||
# define XNegative 0x0010
|
||||
# define YNegative 0x0020
|
||||
#endif
|
||||
|
||||
static int fl_match(const char *a, const char *s, int atleast = 1) {
|
||||
const char *b = s;
|
||||
while (*a && (*a == *b || tolower(*a) == *b)) {a++; b++;}
|
||||
@ -176,13 +157,8 @@ int Fl::arg(int argc, char **argv, int &i) {
|
||||
Fl_Tooltip::disable();
|
||||
i++;
|
||||
return 1;
|
||||
#ifdef __APPLE__ // PORTME: Fl_System_Driver - platform command line
|
||||
// The Finder application in MacOS X passes the "-psn_N_NNNNN" option
|
||||
// to all apps...
|
||||
} else if (strncmp(s, "psn_", 4) == 0) {
|
||||
} else if (Fl_System_Driver::driver()->single_arg(s)) {
|
||||
i++;
|
||||
return 1;
|
||||
#endif // __APPLE__ // PORTME: Fl_System_Driver - platform command line
|
||||
}
|
||||
|
||||
const char *v = argv[i+1];
|
||||
@ -192,20 +168,15 @@ int Fl::arg(int argc, char **argv, int &i) {
|
||||
if (fl_match(s, "geometry")) {
|
||||
|
||||
int flags, gx, gy; unsigned int gw, gh;
|
||||
flags = XParseGeometry(v, &gx, &gy, &gw, &gh);
|
||||
flags = Fl_System_Driver::driver()->XParseGeometry(v, &gx, &gy, &gw, &gh);
|
||||
if (!flags) return 0;
|
||||
geometry = v;
|
||||
|
||||
#if !defined(WIN32) && !defined(__APPLE__) // PORTME: Fl_System_Driver - platform command line
|
||||
} else if (fl_match(s, "display", 2)) {
|
||||
Fl::display(v);
|
||||
#endif
|
||||
Fl_System_Driver::driver()->display_arg(v);
|
||||
|
||||
#ifdef __APPLE__ // PORTME: Fl_System_Driver - platform command line
|
||||
// Xcode in MacOS X may pass "-NSDocumentRevisionsDebugMode YES"
|
||||
} else if (strcmp(s, "NSDocumentRevisionsDebugMode") == 0) {
|
||||
} else if (Fl_System_Driver::driver()->arg_and_value(s, v)) {
|
||||
// nothing to do
|
||||
#endif // __APPLE__ // PORTME: Fl_System_Driver - platform command line
|
||||
|
||||
} else if (fl_match(s, "title", 2)) {
|
||||
title = v;
|
||||
@ -225,7 +196,9 @@ int Fl::arg(int argc, char **argv, int &i) {
|
||||
} else if (fl_match(s, "scheme", 1)) {
|
||||
Fl::scheme(v);
|
||||
|
||||
} else return 0; // unrecognized
|
||||
} else {
|
||||
return 0; // unrecognized
|
||||
}
|
||||
|
||||
i += 2;
|
||||
return 2;
|
||||
@ -310,16 +283,16 @@ 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 = XParseGeometry(geometry, &gx, &gy, &gw, &gh);
|
||||
if (fl & XNegative) gx = Fl::w()-w()+gx;
|
||||
if (fl & YNegative) gy = Fl::h()-h()+gy;
|
||||
fl = Fl_System_Driver::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);
|
||||
// if (mw > gw) gw = mw;
|
||||
// if (mh > gh) gh = mh;
|
||||
Fl_Widget *r = resizable();
|
||||
if (!r) resizable(this);
|
||||
// for WIN32 we assume window is not mapped yet:
|
||||
if (fl & (XValue | YValue))
|
||||
if (fl & (Fl_System_Driver::flXValue | Fl_System_Driver::flYValue))
|
||||
x(-1), resize(gx,gy,gw,gh);
|
||||
else
|
||||
size(gw,gh);
|
||||
@ -379,148 +352,6 @@ void Fl::args(int argc, char **argv) {
|
||||
int i; if (Fl::args(argc,argv,i) < argc) Fl::error(helpmsg);
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_System_Driver - platform command line arguments
|
||||
|
||||
/* the following function was stolen from the X sources as indicated. */
|
||||
|
||||
/* Copyright Massachusetts Institute of Technology 1985, 1986, 1987 */
|
||||
/* $XConsortium: XParseGeom.c,v 11.18 91/02/21 17:23:05 rws Exp $ */
|
||||
|
||||
/*
|
||||
Permission to use, copy, modify, distribute, and sell this software and its
|
||||
documentation for any purpose is hereby granted without fee, provided that
|
||||
the above copyright notice appear in all copies and that both that
|
||||
copyright notice and this permission notice appear in supporting
|
||||
documentation, and that the name of M.I.T. not be used in advertising or
|
||||
publicity pertaining to distribution of the software without specific,
|
||||
written prior permission. M.I.T. makes no representations about the
|
||||
suitability of this software for any purpose. It is provided "as is"
|
||||
without express or implied warranty.
|
||||
*/
|
||||
|
||||
/*
|
||||
* XParseGeometry parses strings of the form
|
||||
* "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
|
||||
* width, height, xoffset, and yoffset are unsigned integers.
|
||||
* Example: "=80x24+300-49"
|
||||
* The equal sign is optional.
|
||||
* It returns a bitmask that indicates which of the four values
|
||||
* were actually found in the string. For each value found,
|
||||
* the corresponding argument is updated; for each value
|
||||
* not found, the corresponding argument is left unchanged.
|
||||
*/
|
||||
|
||||
static int ReadInteger(char* string, char** NextString)
|
||||
{
|
||||
int Result = 0;
|
||||
int Sign = 1;
|
||||
|
||||
if (*string == '+')
|
||||
string++;
|
||||
else if (*string == '-') {
|
||||
string++;
|
||||
Sign = -1;
|
||||
}
|
||||
for (; (*string >= '0') && (*string <= '9'); string++) {
|
||||
Result = (Result * 10) + (*string - '0');
|
||||
}
|
||||
*NextString = string;
|
||||
if (Sign >= 0)
|
||||
return (Result);
|
||||
else
|
||||
return (-Result);
|
||||
}
|
||||
|
||||
int XParseGeometry(const char* string, int* x, int* y,
|
||||
unsigned int* width, unsigned int* height)
|
||||
{
|
||||
int mask = NoValue;
|
||||
char *strind;
|
||||
unsigned int tempWidth = 0, tempHeight = 0;
|
||||
int tempX = 0, tempY = 0;
|
||||
char *nextCharacter;
|
||||
|
||||
if ( (string == NULL) || (*string == '\0')) return(mask);
|
||||
if (*string == '=')
|
||||
string++; /* ignore possible '=' at beg of geometry spec */
|
||||
|
||||
strind = (char *)string;
|
||||
if (*strind != '+' && *strind != '-' && *strind != 'x') {
|
||||
tempWidth = ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return (0);
|
||||
strind = nextCharacter;
|
||||
mask |= WidthValue;
|
||||
}
|
||||
|
||||
if (*strind == 'x' || *strind == 'X') {
|
||||
strind++;
|
||||
tempHeight = ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return (0);
|
||||
strind = nextCharacter;
|
||||
mask |= HeightValue;
|
||||
}
|
||||
|
||||
if ((*strind == '+') || (*strind == '-')) {
|
||||
if (*strind == '-') {
|
||||
strind++;
|
||||
tempX = -ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return (0);
|
||||
strind = nextCharacter;
|
||||
mask |= XNegative;
|
||||
|
||||
} else {
|
||||
strind++;
|
||||
tempX = ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return(0);
|
||||
strind = nextCharacter;
|
||||
}
|
||||
mask |= XValue;
|
||||
if ((*strind == '+') || (*strind == '-')) {
|
||||
if (*strind == '-') {
|
||||
strind++;
|
||||
tempY = -ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return(0);
|
||||
strind = nextCharacter;
|
||||
mask |= YNegative;
|
||||
|
||||
} else {
|
||||
strind++;
|
||||
tempY = ReadInteger(strind, &nextCharacter);
|
||||
if (strind == nextCharacter)
|
||||
return(0);
|
||||
strind = nextCharacter;
|
||||
}
|
||||
mask |= YValue;
|
||||
}
|
||||
}
|
||||
|
||||
/* If strind isn't at the end of the string the it's an invalid
|
||||
geometry specification. */
|
||||
|
||||
if (*strind != '\0') return (0);
|
||||
|
||||
if (mask & XValue)
|
||||
*x = tempX;
|
||||
if (mask & YValue)
|
||||
*y = tempY;
|
||||
if (mask & WidthValue)
|
||||
*width = tempWidth;
|
||||
if (mask & HeightValue)
|
||||
*height = tempHeight;
|
||||
return (mask);
|
||||
}
|
||||
|
||||
#elif defined(FL_PORTING)
|
||||
|
||||
int XParseGeometry(const char* string, int* x, int* y, unsigned int* width, unsigned int* height) { return 0; }
|
||||
|
||||
#endif // ifdef WIN32
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
|
@ -41,6 +41,8 @@
|
||||
class Fl_Darwin_System_Driver : public Fl_System_Driver
|
||||
{
|
||||
public:
|
||||
virtual int single_arg(const char *arg);
|
||||
virtual int arg_and_value(const char *name, const char *value);
|
||||
};
|
||||
|
||||
#endif // FL_DARWIN_SYSTEM_DRIVER_H
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "../../config_lib.h"
|
||||
#include "Fl_Darwin_System_Driver.H"
|
||||
#include <string.h>
|
||||
|
||||
//const char* fl_local_alt = "\xe2\x8c\xa5\\"; // U+2325 (option key)
|
||||
const char* fl_local_alt = "⌥\\"; // U+2325 (option key)
|
||||
@ -29,6 +30,22 @@ 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;
|
||||
}
|
||||
|
||||
int Fl_Darwin_System_Driver::single_arg(const char *arg) {
|
||||
// The Finder application in MacOS X passes the "-psn_N_NNNNN" option to all apps.
|
||||
return (strncmp(arg, "psn_", 4) == 0);
|
||||
}
|
||||
|
||||
int Fl_Darwin_System_Driver::arg_and_value(const char *name, const char *value) {
|
||||
// Xcode in MacOS X may pass "-NSDocumentRevisionsDebugMode YES"
|
||||
return strcmp(name, "NSDocumentRevisionsDebugMode") == 0;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
|
@ -41,6 +41,8 @@
|
||||
class Fl_Posix_System_Driver : public Fl_System_Driver
|
||||
{
|
||||
public:
|
||||
virtual void display_arg(const char *arg);
|
||||
virtual int XParseGeometry(const char*, int*, int*, unsigned int*, unsigned int*);
|
||||
};
|
||||
|
||||
#endif // FL_POSIX_SYSTEM_DRIVER_H
|
||||
|
@ -17,8 +17,9 @@
|
||||
//
|
||||
|
||||
|
||||
#include "../../config_lib.h"
|
||||
#include "Fl_Posix_System_Driver.H"
|
||||
#include <FL/Fl.H>
|
||||
|
||||
|
||||
// Pointers you can use to change FLTK to a foreign language.
|
||||
// Note: Similar pointers are defined in FL/fl_ask.H and src/fl_ask.cxx
|
||||
@ -27,6 +28,20 @@ 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;
|
||||
}
|
||||
|
||||
void Fl_Posix_System_Driver::display_arg(const char *arg) {
|
||||
Fl::display(arg);
|
||||
}
|
||||
|
||||
int Fl_Posix_System_Driver::XParseGeometry(const char* string, int* x, int* y,
|
||||
unsigned int* width, unsigned int* height) {
|
||||
return ::XParseGeometry(string, x, y, width, height);
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
|
@ -27,6 +27,11 @@ const char* fl_local_meta = "Meta";
|
||||
const char* fl_local_shift = "Shift";
|
||||
#endif
|
||||
|
||||
Fl_System_Driver *Fl_System_Driver::driver() {
|
||||
static Fl_System_Driver *d = new Fl_WinAPI_System_Driver();
|
||||
return d;
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user