src/os/macosx/macos.h
author rubidium
Sun, 25 May 2008 19:17:03 +0000
changeset 9354 845e07db4549
parent 9111 48ce04029fe4
child 9776 056e0e5c964a
permissions -rw-r--r--
(svn r13251) -Codechange: rename _patches to _settings as that is more logic.
-Codechange: move all Settings into substructs of _settings in a way that they are logically grouped.
2847
65c54f935db6 (svn r3395) Add Id tag (and svn property) to macosx files.
peter1138
parents: 2223
diff changeset
     1
/* $Id$ */
65c54f935db6 (svn r3395) Add Id tag (and svn property) to macosx files.
peter1138
parents: 2223
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 7965
diff changeset
     3
/** @file macos.h Functions related to MacOS support. */
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 7965
diff changeset
     4
2188
640a0a5f77ea (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
     5
#ifndef MACOS_H
640a0a5f77ea (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
     6
#define MACOS_H
640a0a5f77ea (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
     7
3127
56a9c0db7c18 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
     8
/*
56a9c0db7c18 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
     9
 * Functions to show the popup window
56a9c0db7c18 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    10
 * use ShowMacDialog when you want to control title, message and text on the button
56a9c0db7c18 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    11
 * ShowMacAssertDialog is used by assert
56a9c0db7c18 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    12
 * ShowMacErrorDialog should be used when an unrecoverable error shows up. It only contains the title, which will should tell what went wrong
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 3127
diff changeset
    13
 * the function then adds text that tells the user to update and then report the bug if it's present in the newest version
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 3127
diff changeset
    14
 * 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)
3127
56a9c0db7c18 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    15
 */
5941
adaea39e84ab (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5587
diff changeset
    16
void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel );
adaea39e84ab (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5587
diff changeset
    17
void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression );
adaea39e84ab (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5587
diff changeset
    18
void ShowMacErrorDialog(const char *error);
2188
640a0a5f77ea (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
    19
2223
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    20
// Since MacOS X users will never see an assert unless they started the game from a terminal
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    21
// we're using a custom assert(e) macro.
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    22
#undef assert
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    23
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    24
#ifdef NDEBUG
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    25
#define assert(e)       ((void)0)
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    26
#else
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    27
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    28
#define assert(e) \
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    29
		(__builtin_expect(!(e), 0) ? ShowMacAssertDialog ( __func__, __FILE__, __LINE__, #e ): (void)0 )
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    30
#endif
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    31
7965
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    32
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    33
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    34
/**
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    35
 * Get the major version of Mac OS we are running under. Useful for things like the cocoa driver.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    36
 * @return major version of the os. This would be 10 in the case of 10.4.11.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    37
 */
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    38
long GetMacOSVersionMajor();
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    39
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    40
/**
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    41
 * Get the minor version of Mac OS we are running under. Useful for things like the cocoa driver.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    42
 * @return minor version of the os. This would be 4 in the case of 10.4.11.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    43
 */
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    44
long GetMacOSVersionMinor();
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    45
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    46
/**
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    47
 * Get the bugfix version of Mac OS we are running under. Useful for things like the cocoa driver.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    48
 * @return bugfix version of the os. This would be 11 in the case of 10.4.11.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    49
 */
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    50
long GetMacOSVersionBugfix();
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    51
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    52
/**
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    53
 * Check if we are at least running on the specified version of Mac OS.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    54
 * @param major major version of the os. This would be 10 in the case of 10.4.11.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    55
 * @param minor minor version of the os. This would be 4 in the case of 10.4.11.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    56
 * @param bugfix bugfix version of the os. This would be 11 in the case of 10.4.11.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    57
 * @return true if the running os is at least what we asked, false otherwise.
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    58
 */
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    59
static inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix)
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    60
{
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    61
	long maj = GetMacOSVersionMajor();
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    62
	long min = GetMacOSVersionMinor();
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    63
	long bf = GetMacOSVersionBugfix();
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    64
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    65
	if (maj < major) return false;
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    66
	if (maj == major && min < minor) return false;
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    67
	if (maj == major && min == minor && bf < bugfix) return false;
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    68
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    69
	return true;
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    70
}
e651c71175d6 (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 5941
diff changeset
    71
2223
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
    72
#endif /* MACOS_H */