Move get_carbon_function() to the Fl_Darwin_System_Driver class where it belongs.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11501 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-04-02 07:03:18 +00:00
parent 7b37960d95
commit 77e5a5c11a
6 changed files with 25 additions and 23 deletions

View File

@ -167,7 +167,6 @@ public:
int set_cursor(const Fl_RGB_Image*, int, int);
static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
static void *get_carbon_function(const char *name);
static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // compute work area of a given screen
static int next_marked_length; // next length of marked text after current marked text will have been replaced
static const int CoreText_threshold; // Mac OS version from which the Core Text API is used to display text

View File

@ -1813,13 +1813,13 @@ static int input_method_startup()
if (retval == -1) {
fl_open_display();
if (fl_mac_os_version >= 100500) {
TSMGetActiveDocument = (TSMGetActiveDocument_type)Fl_X::get_carbon_function("TSMGetActiveDocument");
TSMSetDocumentProperty = (TSMSetDocumentProperty_type)Fl_X::get_carbon_function("TSMSetDocumentProperty");
TSMRemoveDocumentProperty = (TSMRemoveDocumentProperty_type)Fl_X::get_carbon_function("TSMRemoveDocumentProperty");
TISCreateASCIICapableInputSourceList = (TISCreateASCIICapableInputSourceList_type)Fl_X::get_carbon_function("TISCreateASCIICapableInputSourceList");
TSMGetActiveDocument = (TSMGetActiveDocument_type)Fl_Darwin_System_Driver::get_carbon_function("TSMGetActiveDocument");
TSMSetDocumentProperty = (TSMSetDocumentProperty_type)Fl_Darwin_System_Driver::get_carbon_function("TSMSetDocumentProperty");
TSMRemoveDocumentProperty = (TSMRemoveDocumentProperty_type)Fl_Darwin_System_Driver::get_carbon_function("TSMRemoveDocumentProperty");
TISCreateASCIICapableInputSourceList = (TISCreateASCIICapableInputSourceList_type)Fl_Darwin_System_Driver::get_carbon_function("TISCreateASCIICapableInputSourceList");
retval = (TSMGetActiveDocument && TSMSetDocumentProperty && TSMRemoveDocumentProperty && TISCreateASCIICapableInputSourceList ? 1 : 0);
} else {
KeyScript = (KeyScript_type)Fl_X::get_carbon_function("KeyScript");
KeyScript = (KeyScript_type)Fl_Darwin_System_Driver::get_carbon_function("KeyScript");
retval = (KeyScript? 1 : 0);
}
}
@ -4331,17 +4331,6 @@ void Fl_Cocoa_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top,
CGContextRelease(auxgc);
}
/* Returns the address of a Carbon function after dynamically loading the Carbon library if needed.
Supports old Mac OS X versions that may use a couple of Carbon calls:
GetKeys used by OS X 10.3 or before (in Fl::get_key())
PMSessionPageSetupDialog and PMSessionPrintDialog used by 10.4 or before (in Fl_Printer::start_job())
*/
void *Fl_X::get_carbon_function(const char *function_name) {
static void *carbon = dlopen("/System/Library/Frameworks/Carbon.framework/Carbon", RTLD_LAZY);
return (carbon ? dlsym(carbon, function_name) : NULL);
}
/* Returns the version of the running Mac OS as an int such as 100802 for 10.8.2
*/
int Fl_X::calc_mac_os_version() {

View File

@ -22,6 +22,7 @@
#include <FL/Fl.H>
#include <FL/x.H>
#include "drivers/Darwin/Fl_Darwin_System_Driver.H"
// The list of Mac OS virtual keycodes appears with OS 10.5 in
// ...../Carbon.framework/Frameworks/HIToolbox.framework/Headers/Events.h
@ -254,7 +255,7 @@ int Fl::get_key(int k) {
// use the GetKeys Carbon function
typedef void (*keymap_f)(fl_KeyMap);
static keymap_f f = NULL;
if (!f) f = ( keymap_f )Fl_X::get_carbon_function("GetKeys");
if (!f) f = ( keymap_f )Fl_Darwin_System_Driver::get_carbon_function("GetKeys");
(*f)(foo);
#ifdef MAC_TEST_FOR_KEYCODES
static int cnt = 0;

View File

@ -20,6 +20,7 @@
#include <FL/Fl_Shared_Image.H>
#include <FL/Fl_Window_Driver.H>
#include "../Quartz/Fl_Quartz_Printer_Graphics_Driver.H"
#include "../Darwin/Fl_Darwin_System_Driver.H"
#include <FL/Fl.H>
#include <FL/x.H>
@ -137,7 +138,7 @@ int Fl_Cocoa_Printer_Driver::start_job (int pagecount, int *frompage, int *topag
// get pointer to the PMSessionPageSetupDialog Carbon function
typedef OSStatus (*dialog_f)(PMPrintSession, PMPageFormat, Boolean *);
static dialog_f f = NULL;
if (!f) f = (dialog_f)Fl_X::get_carbon_function("PMSessionPageSetupDialog");
if (!f) f = (dialog_f)Fl_Darwin_System_Driver::get_carbon_function("PMSessionPageSetupDialog");
status = (*f)(printSession, pageFormat, &accepted);
if (status != noErr || !accepted) {
Fl::first_window()->show();
@ -151,7 +152,7 @@ int Fl_Cocoa_Printer_Driver::start_job (int pagecount, int *frompage, int *topag
// get pointer to the PMSessionPrintDialog Carbon function
typedef OSStatus (*dialog_f2)(PMPrintSession, PMPrintSettings, PMPageFormat, Boolean *);
static dialog_f2 f2 = NULL;
if (!f2) f2 = (dialog_f2)Fl_X::get_carbon_function("PMSessionPrintDialog");
if (!f2) f2 = (dialog_f2)Fl_Darwin_System_Driver::get_carbon_function("PMSessionPrintDialog");
status = (*f2)(printSession, printSettings, pageFormat, &accepted);
if (!accepted) status = kPMCancel;
if (status != noErr) {
@ -168,11 +169,11 @@ int Fl_Cocoa_Printer_Driver::start_job (int pagecount, int *frompage, int *topag
mystring[0] = kPMGraphicsContextCoreGraphics;
CFArrayRef array = CFArrayCreate(NULL, (const void **)mystring, 1, &kCFTypeArrayCallBacks);
PMSessionSetDocumentFormatGeneration_type PMSessionSetDocumentFormatGeneration =
(PMSessionSetDocumentFormatGeneration_type)Fl_X::get_carbon_function("PMSessionSetDocumentFormatGeneration");
(PMSessionSetDocumentFormatGeneration_type)Fl_Darwin_System_Driver::get_carbon_function("PMSessionSetDocumentFormatGeneration");
status = PMSessionSetDocumentFormatGeneration(printSession, kPMDocumentFormatDefault, array, NULL);
CFRelease(array);
PMSessionBeginDocumentNoDialog_type PMSessionBeginDocumentNoDialog =
(PMSessionBeginDocumentNoDialog_type)Fl_X::get_carbon_function("PMSessionBeginDocumentNoDialog");
(PMSessionBeginDocumentNoDialog_type)Fl_Darwin_System_Driver::get_carbon_function("PMSessionBeginDocumentNoDialog");
status = PMSessionBeginDocumentNoDialog(printSession, printSettings, pageFormat);
#endif //__LP64__
}
@ -292,7 +293,7 @@ int Fl_Cocoa_Printer_Driver::start_page (void)
{
#if ! __LP64_
PMSessionGetGraphicsContext_type PMSessionGetGraphicsContext =
(PMSessionGetGraphicsContext_type)Fl_X::get_carbon_function("PMSessionGetGraphicsContext");
(PMSessionGetGraphicsContext_type)Fl_Darwin_System_Driver::get_carbon_function("PMSessionGetGraphicsContext");
status = PMSessionGetGraphicsContext(printSession, NULL, (void **)&gc);
#endif
}

View File

@ -63,6 +63,7 @@ public:
virtual int rmdir(const char* f) {return ::rmdir(f);}
virtual int rename(const char* f, const char *n) {return ::rename(f, n);}
virtual int clocale_printf(FILE *output, const char *format, va_list args);
static void *get_carbon_function(const char *name);
};
#endif // FL_DARWIN_SYSTEM_DRIVER_H

View File

@ -28,6 +28,7 @@
#include <locale.h>
#endif
#include <stdio.h>
#include <dlfcn.h>
int Fl_X::next_marked_length = 0;
@ -79,6 +80,16 @@ int Fl_Darwin_System_Driver::clocale_printf(FILE *output, const char *format, va
return retval;
}
/* Returns the address of a Carbon function after dynamically loading the Carbon library if needed.
Supports old Mac OS X versions that may use a couple of Carbon calls:
GetKeys used by OS X 10.3 or before (in Fl::get_key())
PMSessionPageSetupDialog and PMSessionPrintDialog used by 10.4 or before (in Fl_Printer::start_job())
*/
void *Fl_Darwin_System_Driver::get_carbon_function(const char *function_name) {
static void *carbon = dlopen("/System/Library/Frameworks/Carbon.framework/Carbon", RTLD_LAZY);
return (carbon ? dlsym(carbon, function_name) : NULL);
}
//
// End of "$Id$".
//