Mac OS X: introduced global variable fl_mac_os_version and cleaned a few unused variables.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7892 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2010-11-25 18:21:21 +00:00
parent 0f3e028a13
commit 7eb27fa4bd
6 changed files with 27 additions and 31 deletions

View File

@ -185,6 +185,11 @@ extern void fl_open_callback(void (*cb)(const char *));
* \param shortcut optional shortcut to attach to the "About myprog" menu item (e.g., FL_META+'a') * \param shortcut optional shortcut to attach to the "About myprog" menu item (e.g., FL_META+'a')
*/ */
extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0); extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
/** The version number of the running Mac OS X (e.g., 0x1064 for 10.6.4)
*/
extern int fl_mac_os_version;
/** @} */ /** @} */
// //

View File

@ -687,7 +687,7 @@ Returns the Fl_Window that corresponds to the given window reference,
or \c NULL if not found. FLTK windows that are children of top-level or \c NULL if not found. FLTK windows that are children of top-level
windows share the \c Window of the top-level window. windows share the \c Window of the top-level window.
void fl_open_callback(void (*cb)(const char *)) void \ref fl_open_callback(void (*cb)(const char *))
\par \par
\c cb will be called with a single Unix-style file name and path. \c cb will be called with a single Unix-style file name and path.
@ -749,7 +749,9 @@ handle the Resource Fork correctly.
\par Mac File Paths \par Mac File Paths
FLTK uses UNIX-style filenames and paths. FLTK uses UTF-8-encoded UNIX-style filenames and paths.
\sa group_macosx
\htmlonly \htmlonly

View File

@ -130,19 +130,16 @@ void *fl_system_menu; // this is really a NSMenu*
Fl_Sys_Menu_Bar *fl_sys_menu_bar = 0; Fl_Sys_Menu_Bar *fl_sys_menu_bar = 0;
void *fl_default_cursor; // this is really a NSCursor* void *fl_default_cursor; // this is really a NSCursor*
void *fl_capture = 0; // (NSWindow*) we need this to compensate for a missing(?) mouse capture void *fl_capture = 0; // (NSWindow*) we need this to compensate for a missing(?) mouse capture
//ulong fl_event_time; // the last timestamp from an x event
char fl_key_vector[32]; // used by Fl::get_key() char fl_key_vector[32]; // used by Fl::get_key()
bool fl_show_iconic; // true if called from iconize() - shows the next created window in collapsed state bool fl_show_iconic; // true if called from iconize() - shows the next created window in collapsed state
int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
//const Fl_Window* fl_modal_for; // parent of modal() window
Window fl_window; Window fl_window;
Fl_Window *Fl_Window::current_; Fl_Window *Fl_Window::current_;
//EventRef fl_os_event; // last (mouse) event int fl_mac_os_version = 0; // the version number of the running Mac OS X (e.g., 0x1064 for 10.6.4)
// forward declarations of variables in this file // forward declarations of variables in this file
static int got_events = 0; static int got_events = 0;
static Fl_Window* resize_from_system; static Fl_Window* resize_from_system;
static SInt32 MACsystemVersion;
#if CONSOLIDATE_MOTION #if CONSOLIDATE_MOTION
static Fl_Window* send_motion; static Fl_Window* send_motion;
@ -1371,8 +1368,10 @@ void fl_open_display() {
while (ign_event); while (ign_event);
fl_default_cursor = [NSCursor arrowCursor]; fl_default_cursor = [NSCursor arrowCursor];
Gestalt(gestaltSystemVersion, &MACsystemVersion); SInt32 version;
Gestalt(gestaltSystemVersion, &version);
fl_mac_os_version = (int)version;
// bring the application into foreground without a 'CARB' resource // bring the application into foreground without a 'CARB' resource
Boolean same_psn; Boolean same_psn;
ProcessSerialNumber cur_psn, front_psn; ProcessSerialNumber cur_psn, front_psn;
@ -2757,7 +2756,7 @@ int MACscreen_init(XRectangle screens[])
{ {
NSDictionary *options; NSDictionary *options;
options = [NSDictionary dictionaryWithObjectsAndKeys: options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@" FLTK %d.%d Cocoa", FL_MAJOR_VERSION, [NSString stringWithFormat:@" GUI with FLTK %d.%d", FL_MAJOR_VERSION,
FL_MINOR_VERSION ], @"Copyright", FL_MINOR_VERSION ], @"Copyright",
nil]; nil];
[NSApp orderFrontStandardAboutPanelWithOptions:options]; [NSApp orderFrontStandardAboutPanelWithOptions:options];
@ -2815,13 +2814,12 @@ static void createAppleMenu(void)
FLaboutItemTarget *about = [[FLaboutItemTarget alloc] init]; FLaboutItemTarget *about = [[FLaboutItemTarget alloc] init];
[menuItem setTarget:about]; [menuItem setTarget:about];
[appleMenu addItem:[NSMenuItem separatorItem]]; [appleMenu addItem:[NSMenuItem separatorItem]];
// temporary for testing Fl_Printer. Contains also printPanel of class FLaboutItemTarget. // Print front window
menuItem = [appleMenu addItemWithTitle:@"Print front window" action:@selector(printPanel) keyEquivalent:@""]; menuItem = [appleMenu addItemWithTitle:@"Print front window" action:@selector(printPanel) keyEquivalent:@""];
[menuItem setTarget:about]; [menuItem setTarget:about];
[appleMenu setAutoenablesItems:NO]; [appleMenu setAutoenablesItems:NO];
[menuItem setEnabled:YES]; [menuItem setEnabled:YES];
[appleMenu addItem:[NSMenuItem separatorItem]]; [appleMenu addItem:[NSMenuItem separatorItem]];
// end of temporary for testing Fl_Printer
// Services Menu // Services Menu
services = [[NSMenu alloc] init]; services = [[NSMenu alloc] init];
[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""]; [appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
@ -2844,7 +2842,7 @@ static void createAppleMenu(void)
[menuItem setSubmenu:appleMenu]; [menuItem setSubmenu:appleMenu];
mainmenu = [[NSMenu alloc] initWithTitle:@""]; mainmenu = [[NSMenu alloc] initWithTitle:@""];
[mainmenu addItem:menuItem]; [mainmenu addItem:menuItem];
if (MACsystemVersion < 0x1060) { if (fl_mac_os_version < 0x1060) {
// [NSApp setAppleMenu:appleMenu]; // [NSApp setAppleMenu:appleMenu];
// to avoid compiler warning raised by use of undocumented setAppleMenu : // to avoid compiler warning raised by use of undocumented setAppleMenu :
[NSApp performSelector:@selector(setAppleMenu:) withObject:appleMenu]; [NSApp performSelector:@selector(setAppleMenu:) withObject:appleMenu];
@ -3208,7 +3206,7 @@ unsigned char *MACbitmapFromRectOfWindow(Fl_Window *win, int x, int y, int w, in
win = win->window(); win = win->window();
} }
CGFloat epsilon = 0; CGFloat epsilon = 0;
if (MACsystemVersion >= 0x1060) epsilon = 0.001; if (fl_mac_os_version >= 0x1060) epsilon = 0.001;
// The epsilon offset is absolutely necessary under 10.6. Without it, the top pixel row and // The epsilon offset is absolutely necessary under 10.6. Without it, the top pixel row and
// left pixel column are not read, and bitmap is read shifted by one pixel in both directions. // left pixel column are not read, and bitmap is read shifted by one pixel in both directions.
// Under 10.5, we want no offset. // Under 10.5, we want no offset.

View File

@ -33,10 +33,6 @@
#include <FL/x.H> #include <FL/x.H>
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
// warning: this function is only implemented in Quickdraw. The function
// below may not work if FLTK is compiled with Quartz enabled
extern EventRef fl_os_event;
extern char *fl_selection_buffer; extern char *fl_selection_buffer;
extern int fl_selection_length; extern int fl_selection_length;

View File

@ -34,9 +34,6 @@ extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short*
#define check_default_font() {if (!fl_fontsize) fl_font(0, 12);} #define check_default_font() {if (!fl_fontsize) fl_font(0, 12);}
static const CGAffineTransform font_mx = { 1, 0, 0, -1, 0, 0 }; static const CGAffineTransform font_mx = { 1, 0, 0, -1, 0, 0 };
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
static SInt32 MACsystemVersion = 0;
#endif
Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) { Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
next = 0; next = 0;
@ -50,9 +47,8 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
size = Size; size = Size;
minsize = maxsize = Size; minsize = maxsize = Size;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(MACsystemVersion == 0) Gestalt(gestaltSystemVersion, &MACsystemVersion); if(fl_mac_os_version == 0) fl_open_display();
if(fl_mac_os_version >= 0x1050) {//unfortunately, CTFontCreateWithName != NULL on 10.4 also!
if(MACsystemVersion >= 0x1050) {//unfortunately, CTFontCreateWithName != NULL on 10.4 also!
CFStringRef str = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8); CFStringRef str = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8);
fontref = CTFontCreateWithName(str, size, NULL); fontref = CTFontCreateWithName(str, size, NULL);
CGGlyph glyph[2]; CGGlyph glyph[2];
@ -170,7 +166,7 @@ Fl_Font_Descriptor::~Fl_Font_Descriptor() {
*/ */
if (this == fl_fontsize) fl_fontsize = 0; if (this == fl_fontsize) fl_fontsize = 0;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(MACsystemVersion >= 0x1050) CFRelease(fontref); if(fl_mac_os_version >= 0x1050) CFRelease(fontref);
#else #else
/* ATSUDisposeTextLayout(layout); /* ATSUDisposeTextLayout(layout);
ATSUDisposeStyle(style); */ ATSUDisposeStyle(style); */
@ -273,7 +269,7 @@ double fl_width(const UniChar* txt, int n) {
return 8*n; // user must select a font first! return 8*n; // user must select a font first!
} }
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(MACsystemVersion >= 0x1050) { if(fl_mac_os_version >= 0x1050) {
CTFontRef fontref = fl_fontsize->fontref; CTFontRef fontref = fl_fontsize->fontref;
CFStringRef str = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n * sizeof(UniChar), kCFStringEncodingUTF16, false); CFStringRef str = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n * sizeof(UniChar), kCFStringEncodingUTF16, false);
CFAttributedStringRef astr = CFAttributedStringCreate(NULL, str, NULL); CFAttributedStringRef astr = CFAttributedStringCreate(NULL, str, NULL);
@ -342,7 +338,7 @@ void fl_text_extents(const UniChar* txt, int n, int &dx, int &dy, int &w, int &h
return; return;
} }
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(MACsystemVersion >= 0x1050) { if(fl_mac_os_version >= 0x1050) {
CTFontRef fontref = fl_fontsize->fontref; CTFontRef fontref = fl_fontsize->fontref;
CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n *sizeof(UniChar), kCFStringEncodingUTF16, false); CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n *sizeof(UniChar), kCFStringEncodingUTF16, false);
CFAttributedStringRef astr = CFAttributedStringCreate(NULL, str16, NULL); CFAttributedStringRef astr = CFAttributedStringCreate(NULL, str16, NULL);
@ -435,7 +431,7 @@ void fl_draw(const char *str, int n, float x, float y) {
// convert to UTF-16 first // convert to UTF-16 first
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n); UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(MACsystemVersion >= 0x1050) { if(fl_mac_os_version >= 0x1050) {
CFStringRef keys[2]; CFStringRef keys[2];
CFTypeRef values[2]; CFTypeRef values[2];
CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)uniStr, n * sizeof(UniChar), kCFStringEncodingUTF16, false); CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)uniStr, n * sizeof(UniChar), kCFStringEncodingUTF16, false);

View File

@ -63,9 +63,8 @@ Fl_Font Fl::set_fonts(const char* xstarname) {
if (fl_free_font > FL_FREE_FONT) return (Fl_Font)fl_free_font; // if already called if (fl_free_font > FL_FREE_FONT) return (Fl_Font)fl_free_font; // if already called
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
static SInt32 MACsystemVersion = 0; if(fl_mac_os_version == 0) fl_open_display();
if(MACsystemVersion == 0) Gestalt(gestaltSystemVersion, &MACsystemVersion); if(fl_mac_os_version >= 0x1050) {
if(MACsystemVersion >= 0x1050) {
//if(CTFontCreateWithFontDescriptor != NULL) {// CTFontCreateWithFontDescriptor != NULL on 10.4 also! //if(CTFontCreateWithFontDescriptor != NULL) {// CTFontCreateWithFontDescriptor != NULL on 10.4 also!
int value[1] = {1}; int value[1] = {1};
CFDictionaryRef dict = CFDictionaryCreate(NULL, CFDictionaryRef dict = CFDictionaryCreate(NULL,
@ -131,7 +130,7 @@ else {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
} }
#endif #endif
return 0; // FIXME: I do not understand the shuffeling of the above ifdef's and why they are here! return 0;
} }
static int array[128]; static int array[128];