summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FL/Fl_Device.H4
-rw-r--r--FL/mac.H1
-rw-r--r--src/Fl_Device.cxx19
-rw-r--r--src/Fl_cocoa.mm8
-rw-r--r--src/Fl_win32.cxx4
-rw-r--r--src/Fl_x.cxx3
-rw-r--r--src/fl_font_mac.cxx4
-rw-r--r--src/fl_set_font.cxx12
-rw-r--r--src/fl_set_fonts_mac.cxx2
9 files changed, 39 insertions, 18 deletions
diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H
index caece3b7c..3162255b9 100644
--- a/FL/Fl_Device.H
+++ b/FL/Fl_Device.H
@@ -585,10 +585,8 @@ class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device {
public:
static const char *class_id;
const char *class_name() {return class_id;};
- /** \brief A constructor that sets the graphics driver used by the display */
Fl_Display_Device(Fl_Graphics_Driver *graphics_driver);
- /** Returns the platform display device. */
- static inline Fl_Display_Device *display_device() {return _display;};
+ static Fl_Display_Device *display_device();
#ifdef __APPLE__
static bool high_resolution() {return high_res_window_;}
#endif
diff --git a/FL/mac.H b/FL/mac.H
index ff8efc155..42247b4a8 100644
--- a/FL/mac.H
+++ b/FL/mac.H
@@ -197,6 +197,7 @@ public:
static const int CoreText_threshold; // Mac OS version from which the Core Text API is used to display text
static Fl_Fontdesc* calc_fl_fonts(void); // computes the fl_fonts global variable
static int dnd(int use_selection); // call Fl_X::dnd(1) to support text dragging
+ static int calc_mac_os_version(void); // computes the fl_mac_os_version global variable
private:
#if FLTK_ABI_VERSION >= 10304
CGRect* subRect_; // makes sure subwindow remains inside its parent window
diff --git a/src/Fl_Device.cxx b/src/Fl_Device.cxx
index 5a959f806..a0f5b4338 100644
--- a/src/Fl_Device.cxx
+++ b/src/Fl_Device.cxx
@@ -71,11 +71,28 @@ void Fl_Graphics_Driver::text_extents(const char*t, int n, int& dx, int& dy, int
dy = descent();
}
-Fl_Display_Device::Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device( graphics_driver) {
+/** A constructor that sets the graphics driver used by the display */
+Fl_Display_Device::Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device(graphics_driver) {
this->set_current();
};
+/** Returns the platform display device. */
+Fl_Display_Device *Fl_Display_Device::display_device() {
+ static Fl_Display_Device *display = new Fl_Display_Device(new
+#if defined(__APPLE__)
+ Fl_Quartz_Graphics_Driver
+#elif defined(WIN32)
+ Fl_GDI_Graphics_Driver
+#else
+ Fl_Xlib_Graphics_Driver
+#endif
+ );
+ return display;
+};
+
+Fl_Display_Device *Fl_Display_Device::_display = Fl_Display_Device::display_device();
+
//
// End of "$Id$".
//
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 622b51e20..4cb7f9140 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -89,14 +89,13 @@ extern int fl_send_system_handlers(void *e);
static void convert_crlf(char * string, size_t len);
static void createAppleMenu(void);
static void cocoaMouseHandler(NSEvent *theEvent);
-static int calc_mac_os_version();
static void clipboard_check(void);
static NSString *calc_utf8_format(void);
static unsigned make_current_counts = 0; // if > 0, then Fl_Window::make_current() can be called only once
static Fl_X *fl_x_to_redraw = NULL; // set by Fl_X::flush() to the Fl_X object of the window to be redrawn
static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, int w, int h);
-Fl_Display_Device *Fl_Display_Device::_display = new Fl_Display_Device(new Fl_Quartz_Graphics_Driver); // the platform display
+int fl_mac_os_version = Fl_X::calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4)
// public variables
CGContextRef fl_gc = 0;
@@ -105,8 +104,6 @@ bool fl_show_iconic; // true if called from iconize() - shows
//int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
Window fl_window;
Fl_Window *Fl_Window::current_;
-int fl_mac_os_version = calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4)
-Fl_Fontdesc* fl_fonts = Fl_X::calc_fl_fonts();
static NSString *utf8_format = calc_utf8_format();
// forward declarations of variables in this file
@@ -4492,7 +4489,8 @@ void *Fl_X::get_carbon_function(const char *function_name) {
/* Returns the version of the running Mac OS as an int such as 100802 for 10.8.2
*/
-static int calc_mac_os_version() {
+int Fl_X::calc_mac_os_version() {
+ if (fl_mac_os_version) return fl_mac_os_version;
int M, m, b = 0;
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index 0bcd2e102..830a6c81d 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -87,10 +87,6 @@ static void fl_clipboard_notify_target(HWND wnd);
static void fl_clipboard_notify_untarget(HWND wnd);
// Internal variables
-static Fl_GDI_Graphics_Driver fl_gdi_driver;
-static Fl_Display_Device fl_gdi_display(&fl_gdi_driver);
-Fl_Display_Device *Fl_Display_Device::_display = &fl_gdi_display; // the platform display
-
static HWND clipboard_wnd = 0;
static HWND next_clipboard_wnd = 0;
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx
index c84be4c15..9dee09514 100644
--- a/src/Fl_x.cxx
+++ b/src/Fl_x.cxx
@@ -72,9 +72,6 @@ static bool have_xfixes = false;
# if HAVE_XRENDER
# include <X11/extensions/Xrender.h>
# endif
-static Fl_Xlib_Graphics_Driver fl_xlib_driver;
-static Fl_Display_Device fl_xlib_display(&fl_xlib_driver);
-Fl_Display_Device *Fl_Display_Device::_display = &fl_xlib_display;// the platform display
////////////////////////////////////////////////////////////////
// interface to poll/select call:
diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx
index 0a741a7de..1b2eba1ae 100644
--- a/src/fl_font_mac.cxx
+++ b/src/fl_font_mac.cxx
@@ -19,6 +19,8 @@
#include <config.h>
#include <math.h>
+Fl_Fontdesc* fl_fonts = Fl_X::calc_fl_fonts();
+
/* from fl_utf.c */
extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
@@ -235,6 +237,8 @@ static UniChar *mac_Utf8_to_Utf16(const char *txt, int len, int *new_len)
Fl_Fontdesc* Fl_X::calc_fl_fonts(void)
{
+ if (fl_fonts) return fl_fonts;
+ if (!fl_mac_os_version) fl_mac_os_version = calc_mac_os_version();
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
return (fl_mac_os_version >= Fl_X::CoreText_threshold ? built_in_table_PS : built_in_table_full);
#else
diff --git a/src/fl_set_font.cxx b/src/fl_set_font.cxx
index 777b6e417..865f8f00d 100644
--- a/src/fl_set_font.cxx
+++ b/src/fl_set_font.cxx
@@ -32,6 +32,9 @@ static int table_size;
the string is not copied, so the string must be in static memory.
*/
void Fl::set_font(Fl_Font fnum, const char* name) {
+#ifdef __APPLE__
+ if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
+#endif
while (fnum >= table_size) {
int i = table_size;
if (!i) { // don't realloc the built-in table
@@ -70,7 +73,7 @@ void Fl::set_font(Fl_Font fnum, const char* name) {
s->xlist = 0;
#endif
s->first = 0;
- fl_font(-1, 0);
+ Fl_Display_Device::display_device()->driver()->font(-1, 0);
}
/** Copies one face to another. */
void Fl::set_font(Fl_Font fnum, Fl_Font from) {
@@ -81,7 +84,12 @@ void Fl::set_font(Fl_Font fnum, Fl_Font from) {
face. Under X this value is passed to XListFonts to get all the sizes
of this face.
*/
-const char* Fl::get_font(Fl_Font fnum) {return fl_fonts[fnum].name;}
+const char* Fl::get_font(Fl_Font fnum) {
+#ifdef __APPLE__
+ if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
+#endif
+ return fl_fonts[fnum].name;
+}
//
// End of "$Id$".
diff --git a/src/fl_set_fonts_mac.cxx b/src/fl_set_fonts_mac.cxx
index e6f11e144..213a3272d 100644
--- a/src/fl_set_fonts_mac.cxx
+++ b/src/fl_set_fonts_mac.cxx
@@ -29,6 +29,7 @@
// turn a stored font name into a pretty name:
const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
+ if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
Fl_Fontdesc *f = fl_fonts + fnum;
if (!f->fontname[0]) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
@@ -180,6 +181,7 @@ else {
static int array[128];
int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
+ if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
Fl_Fontdesc *s = fl_fonts+fnum;
if (!s->name) s = fl_fonts; // empty slot in table, use entry 0
int cnt = 0;