Fix preprocessor definitions for wxBase build under OS X.

Define __WXOSX__ for non-GUI build under Darwin. Ensure that the rest of the
code compiles correctly when just __WXOSX__ is defined but neither of
__WXOSX_{CARBON,COCOA,IPHONE}__ is. This ensures that wxBase can actually be
built under Mac.

Move OS X symbols definitions in wx/platform.h after wx/setup.h inclusion as
they rely on __DARWIN__ and wxUSE_GUI values which are both define in that
file now. Still keep them before wx/chkconf.h inclusion which relies on
__WXOSX_XXX__ being defined. Yes, it's a mess and should be cleaned up more
permanently some day.

Also remove some redundancy from wx/osx/{carbon,cocoa}/private.h by factoring
out common parts into wx/osx/core/private.h. Also include this header itself
from wx/osx/private.h directly instead of including it thrice from different
sub-ports headers.

Closes #12660.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66077 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2010-11-09 23:53:42 +00:00
parent 947d5ad04c
commit 382c4adea6
8 changed files with 106 additions and 146 deletions

View File

@ -14,10 +14,6 @@
#ifndef _WX_PRIVATE_H_
#define _WX_PRIVATE_H_
#include "wx/osx/core/private.h"
#include <Carbon/Carbon.h>
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
typedef UInt32 URefCon;
typedef SInt32 SRefCon;
@ -942,16 +938,6 @@ UPP Get##x() \
return sHandler; \
}
//---------------------------------------------------------------------------
// wxMac string conversions
//---------------------------------------------------------------------------
// filefn.cpp
WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
//---------------------------------------------------------------------------
// cocoa bridging utilities
//---------------------------------------------------------------------------

View File

@ -41,7 +41,8 @@
* to configure the build otherwise and give error messages
*/
#if !wxUSE_GRAPHICS_CONTEXT || ( defined( wxMAC_USE_CORE_GRAPHICS ) && !wxMAC_USE_CORE_GRAPHICS )
#if wxUSE_GUI && (!wxUSE_GRAPHICS_CONTEXT || \
( defined( wxMAC_USE_CORE_GRAPHICS ) && !wxMAC_USE_CORE_GRAPHICS ))
# error "OS X builds use CoreGraphics in this wx version, you cannot turn back to QuickDraw completely"
#endif

View File

@ -14,20 +14,8 @@
#ifndef _WX_PRIVATE_COCOA_H_
#define _WX_PRIVATE_COCOA_H_
#include "wx/osx/core/private.h"
#include "wx/defs.h"
#include <ApplicationServices/ApplicationServices.h>
#if wxOSX_USE_ATSU_TEXT
// we need theming and atsu
#include <Carbon/Carbon.h>
#else
// we only need theming, if we find a better include replace the following
#include <Carbon/Carbon.h>
#endif
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
@ -53,22 +41,9 @@ OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
CGImageRef inImage) ;
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image );
CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage );
#endif
long UMAGetSystemVersion() ;
WXDLLIMPEXP_BASE void wxMacStringToPascal( const wxString&from , StringPtr to );
WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
class WXDLLIMPEXP_FWD_CORE wxDialog;
//
//
//
#if wxUSE_GUI
class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
{
public :

View File

@ -32,13 +32,21 @@
#define wxOSX_10_6_AND_LATER(x)
#endif
#if wxOSX_USE_COCOA_OR_CARBON
#if !wxUSE_GUI || wxOSX_USE_COCOA_OR_CARBON
// Carbon functions are currently still used in wxOSX/Cocoa too (including
// wxBase part of it).
#include <Carbon/Carbon.h>
WXDLLIMPEXP_BASE long UMAGetSystemVersion() ;
void WXDLLIMPEXP_CORE wxMacStringToPascal( const wxString&from , unsigned char * to );
wxString WXDLLIMPEXP_CORE wxMacMakeStringFromPascal( const unsigned char * from );
WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
#endif
#if wxUSE_GUI

View File

@ -14,8 +14,6 @@
#ifndef _WX_PRIVATE_IPHONE_H_
#define _WX_PRIVATE_IPHONE_H_
#include "wx/osx/core/private.h"
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif

View File

@ -1,18 +1,16 @@
/* common warning snippet for all osx direct includes */
#ifndef wxOSX_USE_CARBON
#error "this files should only be included after platform.h was included"
#endif
#ifndef _WX_PRIVATE_OSX_H_
#define _WX_PRIVATE_OSX_H_
#include "wx/osx/core/private.h"
#if wxOSX_USE_IPHONE
#include "wx/osx/iphone/private.h"
#elif wxOSX_USE_CARBON
#include "wx/osx/carbon/private.h"
#elif wxOSX_USE_COCOA
#include "wx/osx/cocoa/private.h"
#elif wxUSE_GUI
#error "Must include wx/defs.h first"
#endif
#endif

View File

@ -27,95 +27,13 @@
# endif
#endif
/*
WXOSX targets
__WXOSX_MAC__ means Mac OS X, non embedded
__WXOSX_IPHONE__ means OS X iPhone
*/
/*
Normally all of __WXOSX_XXX__, __WXOSX__ and __WXMAC__ are defined by
configure but ensure that we also define them if configure was not used for
whatever reason.
The primare symbol remains __WXOSX_XXX__ one, __WXOSX__ exists to allow
checking for any OS X port (Carbon and Cocoa) and __WXMAC__ is an old name
for it.
*/
#if defined(__WXOSX_CARBON__) || defined(__WXOSX_COCOA__) || defined(__WXOSX_IPHONE__)
# ifndef __WXOSX__
# define __WXOSX__ 1
# endif
# ifndef __WXMAC__
# define __WXMAC__ 1
# endif
#ifdef __WXMAC_XCODE__
# include <unistd.h>
# include <TargetConditionals.h>
# include <AvailabilityMacros.h>
# include "wx/osx/config_xcode.h"
#endif
#ifdef __WXOSX__
/* setup precise defines according to sdk used */
# include <TargetConditionals.h>
# if defined(__WXOSX_IPHONE__)
# if !( defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE )
# error "incorrect SDK for an iPhone build"
# endif
# elif defined(__WXOSX_CARBON__) || defined(__WXOSX_COCOA__)
# if !( defined(TARGET_OS_MAC) && TARGET_OS_MAC )
# error "incorrect SDK for a Mac OS X build"
# endif
# define __WXOSX_MAC__ 1
# else
# error "one of __WXOSX_IPHONE__, __WXOSX_CARBON__ or __WXOSX_COCOA__ must be defined"
# endif
#endif
#ifdef __WXOSX_MAC__
# if defined(__MACH__)
# include <AvailabilityMacros.h>
# ifndef MAC_OS_X_VERSION_10_4
# define MAC_OS_X_VERSION_10_4 1040
# endif
# ifndef MAC_OS_X_VERSION_10_5
# define MAC_OS_X_VERSION_10_5 1050
# endif
# ifndef MAC_OS_X_VERSION_10_6
# define MAC_OS_X_VERSION_10_6 1060
# endif
# else
# error "only mach-o configurations are supported"
# endif
#endif
/*
__WXOSX_OR_COCOA__ is a common define to wxOSX (Carbon or Cocoa) and wxCocoa ports under OS X.
DO NOT use this define in base library code. Although wxMac has its own
private base library (and thus __WXOSX_OR_COCOA__,__WXMAC__ and related defines are
valid there), wxCocoa shares its library with other ports like wxGTK and wxX11.
To keep wx authors from screwing this up, only enable __WXOSX_OR_COCOA__ for wxCocoa when
not compiling the base library. We determine this by first checking if
wxUSE_BASE is not defined. If it is not defined, then we're not buildling
the base library, and possibly not building wx at all (but actually building
user code that's using wx). If it is defined then we must check to make sure
it is not true. If it is true, we're building base.
If you want it in the common darwin base library then use __DARWIN__. You
can use any Darwin-available libraries like CoreFoundation but please avoid
using OS X libraries like Carbon or CoreServices.
*/
#if defined(__WXOSX__) || (defined(__WXCOCOA__) && (!defined(wxUSE_BASE) || !wxUSE_BASE))
# define __WXOSX_OR_COCOA__ 1
#endif
#ifdef __WXOSX_OR_COCOA__
# ifdef __WXMAC_XCODE__
# include <unistd.h>
# include <TargetConditionals.h>
# include <AvailabilityMacros.h>
# include "wx/osx/config_xcode.h"
# endif
#endif
/*
first define Windows symbols if they're not defined on the command line: we
can autodetect everything we need if _WIN32 is defined
@ -725,6 +643,91 @@
# define SIZEOF_SIZE_T 4
# endif
#endif
/*
Define various OS X symbols before including wx/chkconf.h which uses them.
__WXOSX_MAC__ means Mac OS X, non embedded
__WXOSX_IPHONE__ means OS X iPhone
*/
/*
Normally all of __WXOSX_XXX__, __WXOSX__ and __WXMAC__ are defined by
configure but ensure that we also define them if configure was not used for
whatever reason.
The primary symbol remains __WXOSX_XXX__ one, __WXOSX__ exists to allow
checking for any OS X port (Carbon and Cocoa) and __WXMAC__ is an old name
for it.
*/
#if defined(__WXOSX_CARBON__) || defined(__WXOSX_COCOA__) || defined(__WXOSX_IPHONE__) \
|| (defined(__DARWIN__) && !wxUSE_GUI)
# ifndef __WXOSX__
# define __WXOSX__ 1
# endif
# ifndef __WXMAC__
# define __WXMAC__ 1
# endif
#endif
#ifdef __WXOSX__
/* setup precise defines according to sdk used */
# include <TargetConditionals.h>
# if defined(__WXOSX_IPHONE__)
# if !( defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE )
# error "incorrect SDK for an iPhone build"
# endif
# else
# if wxUSE_GUI && !(defined(__WXOSX_CARBON__) || defined(__WXOSX_COCOA__))
# error "one of __WXOSX_IPHONE__, __WXOSX_CARBON__ or __WXOSX_COCOA__ must be defined for the GUI build"
# endif
# if !( defined(TARGET_OS_MAC) && TARGET_OS_MAC )
# error "incorrect SDK for a Mac OS X build"
# endif
# define __WXOSX_MAC__ 1
# endif
#endif
#ifdef __WXOSX_MAC__
# if defined(__MACH__)
# include <AvailabilityMacros.h>
# ifndef MAC_OS_X_VERSION_10_4
# define MAC_OS_X_VERSION_10_4 1040
# endif
# ifndef MAC_OS_X_VERSION_10_5
# define MAC_OS_X_VERSION_10_5 1050
# endif
# ifndef MAC_OS_X_VERSION_10_6
# define MAC_OS_X_VERSION_10_6 1060
# endif
# else
# error "only mach-o configurations are supported"
# endif
#endif
/*
__WXOSX_OR_COCOA__ is a common define to wxOSX (Carbon or Cocoa) and wxCocoa ports under OS X.
DO NOT use this define in base library code. Although wxMac has its own
private base library (and thus __WXOSX_OR_COCOA__,__WXMAC__ and related defines are
valid there), wxCocoa shares its library with other ports like wxGTK and wxX11.
To keep wx authors from screwing this up, only enable __WXOSX_OR_COCOA__ for wxCocoa when
not compiling the base library. We determine this by first checking if
wxUSE_BASE is not defined. If it is not defined, then we're not buildling
the base library, and possibly not building wx at all (but actually building
user code that's using wx). If it is defined then we must check to make sure
it is not true. If it is true, we're building base.
If you want it in the common darwin base library then use __DARWIN__. You
can use any Darwin-available libraries like CoreFoundation but please avoid
using OS X libraries like Carbon or CoreServices.
*/
#if defined(__WXOSX__) || (defined(__WXCOCOA__) && (!defined(wxUSE_BASE) || !wxUSE_BASE))
# define __WXOSX_OR_COCOA__ 1
#endif
/*
check the consistency of the settings in setup.h: note that this must be
done after setting wxUSE_UNICODE correctly as it is used in wx/chkconf.h
@ -815,15 +818,6 @@
# define wxUSE_WXDIB 1
#endif
/*
We need AvailabilityMacros.h for ifdefing out things that don't exist on
OSX 10.2 and lower
FIXME: We need a better way to detect for 10.3 then including a system header
*/
#ifdef __DARWIN__
#include <AvailabilityMacros.h>
#endif
#if defined (__WXPALMOS__)
#include "wx/palmos/missing.h"
#endif // __WXPALMOS__

View File

@ -60,7 +60,7 @@ extern bool WXDLLEXPORT wxIsDebuggerRunning()
return false;
}
#if wxOSX_USE_COCOA_OR_CARBON
#if !wxUSE_GUI || wxOSX_USE_COCOA_OR_CARBON
// have a fast version for mac code that returns the version as a return value