macos.h

Go to the documentation of this file.
00001 /* $Id: macos.h 15718 2009-03-15 00:32:18Z rubidium $ */
00002 
00005 #ifndef MACOS_H
00006 #define MACOS_H
00007 
00008 /* It would seem that to ensure backward compability we have to ensure that we have defined MAC_OS_X_VERSION_10_x everywhere */
00009 #ifndef MAC_OS_X_VERSION_10_3
00010 #define MAC_OS_X_VERSION_10_3 1030
00011 #endif
00012 
00013 #ifndef MAC_OS_X_VERSION_10_4
00014 #define MAC_OS_X_VERSION_10_4 1040
00015 #endif
00016 
00017 #ifndef MAC_OS_X_VERSION_10_5
00018 #define MAC_OS_X_VERSION_10_5 1050
00019 #endif
00020 
00021 
00022 /*
00023  * Functions to show the popup window
00024  * use ShowMacDialog when you want to control title, message and text on the button
00025  * ShowMacAssertDialog is used by assert
00026  * ShowMacErrorDialog should be used when an unrecoverable error shows up. It only contains the title, which will should tell what went wrong
00027  * the function then adds text that tells the user to update and then report the bug if it's present in the newest version
00028  * It also quits in a nice way since we call it when we know something happened that will crash OpenTTD (like a needed pointer turns out to be NULL or similar)
00029  */
00030 void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel );
00031 void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression );
00032 void ShowMacErrorDialog(const char *error);
00033 
00034 /* Since MacOS X users will never see an assert unless they started the game from a terminal
00035  * we're using a custom assert(e) macro. */
00036 #undef assert
00037 
00038 #ifdef NDEBUG
00039 #define assert(e)       ((void)0)
00040 #else
00041 
00042 #define assert(e) \
00043     (__builtin_expect(!(e), 0) ? ShowMacAssertDialog ( __func__, __FILE__, __LINE__, #e ): (void)0 )
00044 #endif
00045 
00046 
00047 
00052 long GetMacOSVersionMajor();
00053 
00058 long GetMacOSVersionMinor();
00059 
00064 long GetMacOSVersionBugfix();
00065 
00073 static inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix)
00074 {
00075   long maj = GetMacOSVersionMajor();
00076   long min = GetMacOSVersionMinor();
00077   long bf = GetMacOSVersionBugfix();
00078 
00079   if (maj < major) return false;
00080   if (maj == major && min < minor) return false;
00081   if (maj == major && min == minor && bf < bugfix) return false;
00082 
00083   return true;
00084 }
00085 
00086 /*
00087  * OSX 10.3.9 has blessed us with a signal with unlikable side effects.
00088  * The most problematic side effect is that it makes OpenTTD 'think' that
00089  * it's running on 10.4.0 or higher and thus tries to link to functions
00090  * that are only defined there. So now we'll remove all and any signal
00091  * handling for OSX < 10.4 and 10.3.9 works as it should at the cost of
00092  * not giving a useful error when savegame loading goes wrong.
00093  */
00094 #define signal(sig, func) (MacOSVersionIsAtLeast(10, 4, 0) ? signal(sig, func) : NULL)
00095 
00096 #endif /* MACOS_H */

Generated on Wed Jun 3 19:05:13 2009 for OpenTTD by  doxygen 1.5.6