Skip to content

Commit

Permalink
Adopted use of FL_LIBRARY #define symbol under Mac OS X. This allows …
Browse files Browse the repository at this point in the history
…to compile

client applications without including Mac OS system headers, with a gain in speed of 
compilation and portability. The source files of all FLTK libraries must now be compiled with 
-DFL_LIBRARY under Mac OS X. Make, CMake and Xcode project support files
have been modified accordingly.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8113 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Dec 23, 2010
1 parent 122c0e6 commit a8530c7
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 71 deletions.
6 changes: 3 additions & 3 deletions FL/Fl_Printer.H
Expand Up @@ -58,9 +58,9 @@ private:
float scale_x;
float scale_y;
float angle; // rotation angle in radians
PMPrintSession printSession;
PMPageFormat pageFormat;
PMPrintSettings printSettings;
Fl_PMPrintSession printSession;
Fl_PMPageFormat pageFormat;
Fl_PMPrintSettings printSettings;
#elif defined(WIN32)
int abortPrint;
PRINTDLG pd;
Expand Down
84 changes: 45 additions & 39 deletions FL/mac.H
Expand Up @@ -34,8 +34,28 @@
# error "Never use <FL/mac.H> directly; include <FL/x.H> instead."
#endif // !Fl_X_H

typedef void* Window; // this is really a pointer to the subclass FLWindow of NSWindow
typedef void* Fl_Offscreen; // this is really a CGContextRef
typedef void* Fl_Bitmask; // this is really a CGImageRef

#ifndef FL_LIBRARY // this part is used when compiling an application program

typedef void* Fl_Region;
typedef void* Fl_CGContextRef;
typedef void* Fl_PMPrintSettings;
typedef void* Fl_PMPageFormat;
typedef void* Fl_PMPrintSession;

#else // this part must be compiled when building the FLTK libraries

// Standard MacOS Carbon API includes...
#include <Carbon/Carbon.h>
#undef check // because of Fl::check()

typedef CGContextRef Fl_CGContextRef;
typedef PMPrintSettings Fl_PMPrintSettings;
typedef PMPageFormat Fl_PMPageFormat;
typedef PMPrintSession Fl_PMPrintSession;

#ifndef MAC_OS_X_VERSION_10_3
#define MAC_OS_X_VERSION_10_3 1030
Expand All @@ -53,6 +73,16 @@
#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3
#endif

typedef struct flCocoaRegion {
int count;
CGRect *rects;
} *Fl_Region; // a region is the union of a series of rectangles

# include "Fl_Window.H"

// Some random X equivalents
struct XPoint { int x, y; };
struct XRectangle {int x, y, width, height;};
#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
#if defined(__LP64__) && __LP64__
typedef double CGFloat;
Expand All @@ -61,21 +91,7 @@ typedef float CGFloat;
#endif
#endif // CGFLOAT_DEFINED


// Now make some fixes to the headers...
#undef check // Dunno where this comes from...

// Some random X equivalents
struct XPoint { int x, y; };
struct XRectangle {int x, y, width, height;};

typedef void *Window; // this is really a pter to the subclass FLWindow of NSWindow
typedef struct flCocoaRegion {
int count;
CGRect *rects;
} *Fl_Region; // a region is the union of a series of rectangles
extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);

inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
Fl_Region R = (Fl_Region)malloc(sizeof(*R));
R->count = 1;
Expand All @@ -85,26 +101,20 @@ inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
}
inline void XDestroyRegion(Fl_Region r) {
if(r) {
free(r->rects);
free(r);
}
free(r->rects);
free(r);
}
}
extern void *fl_default_cursor;
extern void *fl_system_menu;
typedef CGContextRef Fl_Offscreen;
typedef CGImageRef Fl_Bitmask;

void fl_clip_region(Fl_Region);

# include "Fl_Window.H"
extern void *fl_default_cursor;

// This object contains all mac-specific stuff about a window:
// WARNING: this object is highly subject to change!
class Fl_X
{
public:
Window xid; // pointer to the Cocoa window object (FLWindow*)
Fl_Offscreen other_xid; // pointer for offscreen bitmaps (doublebuffer)
Fl_Offscreen other_xid; // pointer for offscreen bitmaps (overlay window)
Fl_Window *w; // FLTK window for
Fl_Region region;
Fl_Region subRegion; // region for this specific subwindow
Expand Down Expand Up @@ -147,36 +157,32 @@ private:
static void relink(Fl_Window*, Fl_Window*);
};

inline Window fl_xid(const Fl_Window*w)
{
return Fl_X::i(w)->xid;
}

extern struct Fl_XMap {
RGBColor rgb;
ulong pen;
} *fl_current_xmap;

extern FL_EXPORT void *fl_display;
extern FL_EXPORT Window fl_window;
extern FL_EXPORT CGContextRef fl_gc;

#endif // FL_LIBRARY

extern FL_EXPORT Fl_CGContextRef fl_gc;
extern FL_EXPORT class Fl_Sys_Menu_Bar *fl_sys_menu_bar;

extern Window fl_xid(const Fl_Window*);
void fl_clip_region(Fl_Region);

extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
extern Fl_Offscreen fl_create_offscreen(int w, int h);
extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
extern void fl_delete_offscreen(Fl_Offscreen gWorld);
extern void fl_begin_offscreen(Fl_Offscreen gWorld);
extern void fl_end_offscreen();


extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);

extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
extern void fl_open_display();

extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
#endif // FL_DOXYGEN

/** \defgroup group_macosx Mac OS X-specific functions
Expand Down
34 changes: 8 additions & 26 deletions ide/Xcode3/FLTK.xcodeproj/project.pbxproj
Expand Up @@ -10999,6 +10999,7 @@
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = FL_LIBRARY;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
../../,
Expand Down Expand Up @@ -11873,8 +11874,6 @@
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = "USING_XCODE=1";
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -12065,8 +12064,6 @@
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = "USING_XCODE=1";
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -12561,8 +12558,6 @@
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
../../,
Expand Down Expand Up @@ -12594,6 +12589,7 @@
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = FL_LIBRARY;
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -12660,8 +12656,6 @@
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
../../,
Expand Down Expand Up @@ -12975,8 +12969,6 @@
ALWAYS_SEARCH_USER_PATHS = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = "USING_XCODE=1";
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -13047,6 +13039,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = FL_LIBRARY;
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -13108,8 +13101,6 @@
FRAMEWORK_VERSION = A;
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
../../,
Expand Down Expand Up @@ -13447,8 +13438,6 @@
FRAMEWORK_VERSION = A;
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
../../,
Expand Down Expand Up @@ -13791,8 +13780,6 @@
ALWAYS_SEARCH_USER_PATHS = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = "USING_XCODE=1";
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -13913,8 +13900,6 @@
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = "USING_XCODE=1";
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -14074,6 +14059,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = FL_LIBRARY;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
../../,
Expand Down Expand Up @@ -14290,12 +14276,12 @@
AC3226B9FE17327A0476ACA0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ONLY_ACTIVE_ARCH_PRE_XCODE_3_1)";
ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH_PRE_XCODE_3_1 = "$(NATIVE_ARCH_ACTUAL)";
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
};
Expand Down Expand Up @@ -14770,6 +14756,7 @@
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = FL_LIBRARY;
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -14801,8 +14788,6 @@
FRAMEWORK_VERSION = A;
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
../../,
Expand Down Expand Up @@ -15639,8 +15624,6 @@
ALWAYS_SEARCH_USER_PATHS = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = "USING_XCODE=1";
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -15769,6 +15752,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
GCC_PREPROCESSOR_DEFINITIONS = FL_LIBRARY;
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
Expand Down Expand Up @@ -15925,8 +15909,6 @@
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = fltk.pch;
HEADER_SEARCH_PATHS = (
../../ide/XCode3/,
../../,
Expand Down
3 changes: 3 additions & 0 deletions ide/Xcode3/fltk.pch
Expand Up @@ -6,3 +6,6 @@
#import <Cocoa/Cocoa.h>
#endif

#ifdef FL_LIBRARY
#include <Carbon/Carbon.h>
#endif
2 changes: 1 addition & 1 deletion makeinclude.in
Expand Up @@ -60,7 +60,7 @@ RC = @RC@
ARCHFLAGS = @ARCHFLAGS@
OPTIM = @OPTIM@
CFLAGS = $(OPTIM) @LARGEFILE@ @PTHREAD_FLAGS@ @CPPFLAGS@ @CFLAGS@
CXXFLAGS = $(OPTIM) @LARGEFILE@ @PTHREAD_FLAGS@ @CPPFLAGS@ @CXXFLAGS@
CXXFLAGS = $(OPTIM) @LARGEFILE@ @PTHREAD_FLAGS@ @CPPFLAGS@ @CXXFLAGS@ $(FLTKFLAGS)

# program to make the archive:
LIBNAME = @LIBNAME@
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -194,6 +194,7 @@ set(CFILES
)

if(APPLE)
add_definitions(-DFL_LIBRARY)
set(MMFILES
Fl_cocoa.mm
Fl_Quartz_Printer.mm
Expand Down
2 changes: 1 addition & 1 deletion src/Fl.cxx
Expand Up @@ -667,7 +667,7 @@ Fl_Window* Fl::next_window(const Fl_Window* window) {
*/
void Fl::first_window(Fl_Window* window) {
if (!window || !window->shown()) return;
fl_find(fl_xid(window));
fl_find( Fl_X::i(window)->xid );
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Fl_cocoa.mm
Expand Up @@ -3266,6 +3266,11 @@ CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h) {
return CGRectMake(x, y, w > 0 ? w - 0.9 : 0, h > 0 ? h - 0.9 : 0);
}

Window fl_xid(const Fl_Window* w)
{
return Fl_X::i(w)->xid;
}

#endif // __APPLE__

//
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Expand Up @@ -217,7 +217,7 @@ UTF8CFILES = \
xutf8/utf8Wrap.c

################################################################

FLTKFLAGS = -DFL_LIBRARY
include ../makeinclude

MMFILES = $(shell if test $(USEMMFILES) = Yes; then echo $(OBJCPPFILES); fi)
Expand Down
2 changes: 2 additions & 0 deletions test/demo.cxx
Expand Up @@ -136,6 +136,8 @@ const char *default_menu[] = {
# define chdir _chdir
# define putenv _putenv
# endif // !__WATCOMC__
#elif defined USING_XCODE
#include <Carbon/Carbon.h>
#else
# include <unistd.h>
#endif
Expand Down

0 comments on commit a8530c7

Please sign in to comment.