aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llwindow/llwindowmacosx.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llwindow/llwindowmacosx.cpp
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llwindow/llwindowmacosx.cpp')
-rw-r--r--linden/indra/llwindow/llwindowmacosx.cpp166
1 files changed, 63 insertions, 103 deletions
diff --git a/linden/indra/llwindow/llwindowmacosx.cpp b/linden/indra/llwindow/llwindowmacosx.cpp
index 5ab0ba6..5102173 100644
--- a/linden/indra/llwindow/llwindowmacosx.cpp
+++ b/linden/indra/llwindow/llwindowmacosx.cpp
@@ -29,8 +29,6 @@
29 * $/LicenseInfo$ 29 * $/LicenseInfo$
30 */ 30 */
31 31
32#if LL_DARWIN
33
34#include "linden_common.h" 32#include "linden_common.h"
35 33
36#include <Carbon/Carbon.h> 34#include <Carbon/Carbon.h>
@@ -42,10 +40,6 @@
42#include "llgl.h" 40#include "llgl.h"
43#include "llstring.h" 41#include "llstring.h"
44#include "lldir.h" 42#include "lldir.h"
45#include "llviewercontrol.h"
46
47#include "llglheaders.h"
48
49#include "indra_constants.h" 43#include "indra_constants.h"
50 44
51#include "llwindowmacosx-objc.h" 45#include "llwindowmacosx-objc.h"
@@ -66,37 +60,16 @@ const S32 MAX_NUM_RESOLUTIONS = 32;
66// LLWindowMacOSX 60// LLWindowMacOSX
67// 61//
68 62
69// Cross-platform bits: 63BOOL LLWindowMacOSX::sUseMultGL = FALSE;
64WindowRef LLWindowMacOSX::sMediaWindow = NULL;
70 65
71void show_window_creation_error(const char* title) 66// Cross-platform bits:
72{
73 llwarns << title << llendl;
74 /*
75 OSMessageBox(
76 "Second Life is unable to run because it can't set up your display.\n"
77 "We need to be able to make a 32-bit color window at 1024x768, with\n"
78 "an 8 bit alpha channel.\n"
79 "\n"
80 "First, be sure your monitor is set to True Color (32-bit) in\n"
81 "Start -> Control Panels -> Display -> Settings.\n"
82 "\n"
83 "Otherwise, this may be due to video card driver issues.\n"
84 "Please make sure you have the latest video card drivers installed.\n"
85 "ATI drivers are available at http://www.ati.com/\n"
86 "nVidia drivers are available at http://www.nvidia.com/\n"
87 "\n"
88 "If you continue to receive this message, contact customer service.",
89 title,
90 OSMB_OK);
91 */
92}
93 67
94BOOL check_for_card(const char* RENDERER, const char* bad_card) 68BOOL check_for_card(const char* RENDERER, const char* bad_card)
95{ 69{
96 if (!strnicmp(RENDERER, bad_card, strlen(bad_card))) 70 if (!strnicmp(RENDERER, bad_card, strlen(bad_card)))
97 { 71 {
98 char buffer[1024];/* Flawfinder: ignore */ 72 std::string buffer = llformat(
99 snprintf(buffer, sizeof(buffer),
100 "Your video card appears to be a %s, which Second Life does not support.\n" 73 "Your video card appears to be a %s, which Second Life does not support.\n"
101 "\n" 74 "\n"
102 "Second Life requires a video card with 32 Mb of memory or more, as well as\n" 75 "Second Life requires a video card with 32 Mb of memory or more, as well as\n"
@@ -110,7 +83,7 @@ BOOL check_for_card(const char* RENDERER, const char* bad_card)
110 "You can try to run Second Life, but it will probably crash or run\n" 83 "You can try to run Second Life, but it will probably crash or run\n"
111 "very slowly. Try anyway?", 84 "very slowly. Try anyway?",
112 bad_card); 85 bad_card);
113 S32 button = OSMessageBox(buffer, "Unsupported video card", OSMB_YESNO); 86 S32 button = OSMessageBox(buffer.c_str(), "Unsupported video card", OSMB_YESNO);
114 if (OSBTN_YES == button) 87 if (OSBTN_YES == button)
115 { 88 {
116 return FALSE; 89 return FALSE;
@@ -124,8 +97,6 @@ BOOL check_for_card(const char* RENDERER, const char* bad_card)
124 return FALSE; 97 return FALSE;
125} 98}
126 99
127
128
129// Switch to determine whether we capture all displays, or just the main one. 100// Switch to determine whether we capture all displays, or just the main one.
130// We may want to base this on the setting of _DEBUG... 101// We may want to base this on the setting of _DEBUG...
131 102
@@ -242,7 +213,7 @@ static LLWindowMacOSX *gWindowImplementation = NULL;
242 213
243 214
244 215
245LLWindowMacOSX::LLWindowMacOSX(char *title, char *name, S32 x, S32 y, S32 width, 216LLWindowMacOSX::LLWindowMacOSX(const std::string& title, const std::string& name, S32 x, S32 y, S32 width,
246 S32 height, U32 flags, 217 S32 height, U32 flags,
247 BOOL fullscreen, BOOL clearBg, 218 BOOL fullscreen, BOOL clearBg,
248 BOOL disable_vsync, BOOL use_gl, 219 BOOL disable_vsync, BOOL use_gl,
@@ -289,10 +260,11 @@ LLWindowMacOSX::LLWindowMacOSX(char *title, char *name, S32 x, S32 y, S32 width,
289 mOriginalAspectRatio = (double)CGDisplayPixelsWide(mDisplay) / (double)CGDisplayPixelsHigh(mDisplay); 260 mOriginalAspectRatio = (double)CGDisplayPixelsWide(mDisplay) / (double)CGDisplayPixelsHigh(mDisplay);
290 261
291 // Stash the window title 262 // Stash the window title
292 strcpy((char*)mWindowTitle + 1, title); /* Flawfinder: ignore */ 263 strcpy((char*)mWindowTitle + 1, title.c_str()); /* Flawfinder: ignore */
293 mWindowTitle[0] = strlen(title); /* Flawfinder: ignore */ 264 mWindowTitle[0] = title.length();
294 265
295 mEventHandlerUPP = NewEventHandlerUPP(staticEventHandler); 266 mEventHandlerUPP = NewEventHandlerUPP(staticEventHandler);
267 mMoveEventCampartorUPP = NewEventComparatorUPP(staticMoveEventComparator);
296 mGlobalHandlerRef = NULL; 268 mGlobalHandlerRef = NULL;
297 mWindowHandlerRef = NULL; 269 mWindowHandlerRef = NULL;
298 270
@@ -467,8 +439,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits
467 mFullscreenBits = -1; 439 mFullscreenBits = -1;
468 mFullscreenRefresh = -1; 440 mFullscreenRefresh = -1;
469 441
470 char error[256]; /* Flawfinder: ignore */ 442 std::string error= llformat("Unable to run fullscreen at %d x %d.\nRunning in window.", width, height);
471 snprintf(error, sizeof(error), "Unable to run fullscreen at %d x %d.\nRunning in window.", width, height);
472 OSMessageBox(error, "Error", OSMB_OK); 443 OSMessageBox(error, "Error", OSMB_OK);
473 } 444 }
474 } 445 }
@@ -809,7 +780,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits
809 aglSetInteger(mContext, AGL_SWAP_INTERVAL, &frames_per_swap); 780 aglSetInteger(mContext, AGL_SWAP_INTERVAL, &frames_per_swap);
810 781
811 //enable multi-threaded OpenGL 782 //enable multi-threaded OpenGL
812 if (gSavedSettings.getBOOL("RenderAppleUseMultGL")) 783 if (sUseMultGL)
813 { 784 {
814 CGLError cgl_err; 785 CGLError cgl_err;
815 CGLContextObj ctx = CGLGetCurrentContext(); 786 CGLContextObj ctx = CGLGetCurrentContext();
@@ -826,9 +797,6 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits
826 } 797 }
827 } 798 }
828 799
829 //make sure multisample starts off disabled
830 glDisable(GL_MULTISAMPLE_ARB);
831
832 // Don't need to get the current gamma, since there's a call that restores it to the system defaults. 800 // Don't need to get the current gamma, since there's a call that restores it to the system defaults.
833 return TRUE; 801 return TRUE;
834} 802}
@@ -1445,6 +1413,11 @@ BOOL LLWindowMacOSX::setCursorPosition(const LLCoordWindow position)
1445 // Under certain circumstances, this will trigger us to decouple the cursor. 1413 // Under certain circumstances, this will trigger us to decouple the cursor.
1446 adjustCursorDecouple(true); 1414 adjustCursorDecouple(true);
1447 1415
1416 // trigger mouse move callback
1417 LLCoordGL gl_pos;
1418 convertCoords(position, &gl_pos);
1419 mCallbacks->handleMouseMove(this, gl_pos, (MASK)0);
1420
1448 return result; 1421 return result;
1449} 1422}
1450 1423
@@ -1515,6 +1488,7 @@ void LLWindowMacOSX::adjustCursorDecouple(bool warpingMouse)
1515 // llinfos << "adjustCursorDecouple: decoupling cursor" << llendl; 1488 // llinfos << "adjustCursorDecouple: decoupling cursor" << llendl;
1516 CGAssociateMouseAndMouseCursorPosition(false); 1489 CGAssociateMouseAndMouseCursorPosition(false);
1517 mCursorDecoupled = true; 1490 mCursorDecoupled = true;
1491 FlushSpecificEventsFromQueue(GetCurrentEventQueue(), mMoveEventCampartorUPP, NULL);
1518 mCursorIgnoreNextDelta = TRUE; 1492 mCursorIgnoreNextDelta = TRUE;
1519 } 1493 }
1520 } 1494 }
@@ -1610,11 +1584,6 @@ void LLWindowMacOSX::afterDialog()
1610} 1584}
1611 1585
1612 1586
1613S32 LLWindowMacOSX::stat(const char* file_name, struct stat* stat_info)
1614{
1615 return ::stat( file_name, stat_info );
1616}
1617
1618void LLWindowMacOSX::flashIcon(F32 seconds) 1587void LLWindowMacOSX::flashIcon(F32 seconds)
1619{ 1588{
1620 // Don't do this if we're already started, since this would try to install the NMRec twice. 1589 // Don't do this if we're already started, since this would try to install the NMRec twice.
@@ -1744,15 +1713,6 @@ BOOL LLWindowMacOSX::copyTextToClipboard(const LLWString &s)
1744} 1713}
1745 1714
1746 1715
1747BOOL LLWindowMacOSX::sendEmail(const char* address, const char* subject, const char* body_text,
1748 const char* attachment, const char* attachment_displayed_name )
1749{
1750 // MBW -- XXX -- Um... yeah. I'll get to this later.
1751
1752 return false;
1753}
1754
1755
1756// protected 1716// protected
1757BOOL LLWindowMacOSX::resetDisplayResolution() 1717BOOL LLWindowMacOSX::resetDisplayResolution()
1758{ 1718{
@@ -1949,13 +1909,30 @@ BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordScreen *to)
1949 1909
1950 1910
1951 1911
1952void LLWindowMacOSX::setupFailure(const char* text, const char* caption, U32 type) 1912void LLWindowMacOSX::setupFailure(const std::string& text, const std::string& caption, U32 type)
1953{ 1913{
1954 destroyContext(); 1914 destroyContext();
1955 1915
1956 OSMessageBox(text, caption, type); 1916 OSMessageBox(text, caption, type);
1957} 1917}
1958 1918
1919pascal Boolean LLWindowMacOSX::staticMoveEventComparator( EventRef event, void* data)
1920{
1921 UInt32 evtClass = GetEventClass (event);
1922 UInt32 evtKind = GetEventKind (event);
1923
1924 if ((evtClass == kEventClassMouse) && ((evtKind == kEventMouseDragged) || (evtKind == kEventMouseMoved)))
1925 {
1926 return true;
1927 }
1928
1929 else
1930 {
1931 return false;
1932 }
1933}
1934
1935
1959pascal OSStatus LLWindowMacOSX::staticEventHandler(EventHandlerCallRef myHandler, EventRef event, void* userData) 1936pascal OSStatus LLWindowMacOSX::staticEventHandler(EventHandlerCallRef myHandler, EventRef event, void* userData)
1960{ 1937{
1961 LLWindowMacOSX *self = (LLWindowMacOSX*)userData; 1938 LLWindowMacOSX *self = (LLWindowMacOSX*)userData;
@@ -3020,20 +2997,13 @@ void LLSplashScreenMacOSX::showImpl()
3020#endif 2997#endif
3021} 2998}
3022 2999
3023void LLSplashScreenMacOSX::updateImpl(const char* mesg) 3000void LLSplashScreenMacOSX::updateImpl(const std::string& mesg)
3024{ 3001{
3025 if(mWindow != NULL) 3002 if(mWindow != NULL)
3026 { 3003 {
3027 CFStringRef string = NULL; 3004 CFStringRef string = NULL;
3028 3005
3029 if(mesg != NULL) 3006 string = CFStringCreateWithCString(NULL, mesg.c_str(), kCFStringEncodingUTF8);
3030 {
3031 string = CFStringCreateWithCString(NULL, mesg, kCFStringEncodingUTF8);
3032 }
3033 else
3034 {
3035 string = CFStringCreateWithCString(NULL, "", kCFStringEncodingUTF8);
3036 }
3037 3007
3038 if(string != NULL) 3008 if(string != NULL)
3039 { 3009 {
@@ -3068,7 +3038,7 @@ void LLSplashScreenMacOSX::hideImpl()
3068 3038
3069 3039
3070 3040
3071S32 OSMessageBoxMacOSX(const char* text, const char* caption, U32 type) 3041S32 OSMessageBoxMacOSX(const std::string& text, const std::string& caption, U32 type)
3072{ 3042{
3073 S32 result = OSBTN_CANCEL; 3043 S32 result = OSBTN_CANCEL;
3074 SInt16 retval_mac = 1; 3044 SInt16 retval_mac = 1;
@@ -3079,23 +3049,8 @@ S32 OSMessageBoxMacOSX(const char* text, const char* caption, U32 type)
3079 AlertType alertType = kAlertCautionAlert; 3049 AlertType alertType = kAlertCautionAlert;
3080 OSStatus err; 3050 OSStatus err;
3081 3051
3082 if(text != NULL) 3052 explanationString = CFStringCreateWithCString(NULL, text.c_str(), kCFStringEncodingUTF8);
3083 { 3053 errorString = CFStringCreateWithCString(NULL, caption.c_str(), kCFStringEncodingUTF8);
3084 explanationString = CFStringCreateWithCString(NULL, text, kCFStringEncodingUTF8);
3085 }
3086 else
3087 {
3088 explanationString = CFStringCreateWithCString(NULL, "", kCFStringEncodingUTF8);
3089 }
3090
3091 if(caption != NULL)
3092 {
3093 errorString = CFStringCreateWithCString(NULL, caption, kCFStringEncodingUTF8);
3094 }
3095 else
3096 {
3097 errorString = CFStringCreateWithCString(NULL, "", kCFStringEncodingUTF8);
3098 }
3099 3054
3100 params.version = kStdCFStringAlertVersionOne; 3055 params.version = kStdCFStringAlertVersionOne;
3101 params.movable = false; 3056 params.movable = false;
@@ -3179,15 +3134,13 @@ S32 OSMessageBoxMacOSX(const char* text, const char* caption, U32 type)
3179 3134
3180// Open a URL with the user's default web browser. 3135// Open a URL with the user's default web browser.
3181// Must begin with protocol identifier. 3136// Must begin with protocol identifier.
3182void spawn_web_browser(const char* escaped_url) 3137void LLWindowMacOSX::spawnWebBrowser(const std::string& escaped_url)
3183{ 3138{
3184 bool found = false; 3139 bool found = false;
3185 S32 i; 3140 S32 i;
3186 for (i = 0; i < gURLProtocolWhitelistCount; i++) 3141 for (i = 0; i < gURLProtocolWhitelistCount; i++)
3187 { 3142 {
3188 S32 len = strlen(gURLProtocolWhitelist[i]); /* Flawfinder: ignore */ 3143 if (escaped_url.find(gURLProtocolWhitelist[i]) != std::string::npos)
3189 if (!strncmp(escaped_url, gURLProtocolWhitelist[i], len)
3190 && escaped_url[len] == ':')
3191 { 3144 {
3192 found = true; 3145 found = true;
3193 break; 3146 break;
@@ -3196,7 +3149,7 @@ void spawn_web_browser(const char* escaped_url)
3196 3149
3197 if (!found) 3150 if (!found)
3198 { 3151 {
3199 llwarns << "spawn_web_browser() called for url with protocol not on whitelist: " << escaped_url << llendl; 3152 llwarns << "spawn_web_browser called for url with protocol not on whitelist: " << escaped_url << llendl;
3200 return; 3153 return;
3201 } 3154 }
3202 3155
@@ -3205,7 +3158,7 @@ void spawn_web_browser(const char* escaped_url)
3205 3158
3206 llinfos << "Opening URL " << escaped_url << llendl; 3159 llinfos << "Opening URL " << escaped_url << llendl;
3207 3160
3208 CFStringRef stringRef = CFStringCreateWithCString(NULL, escaped_url, kCFStringEncodingUTF8); 3161 CFStringRef stringRef = CFStringCreateWithCString(NULL, escaped_url.c_str(), kCFStringEncodingUTF8);
3209 if (stringRef) 3162 if (stringRef)
3210 { 3163 {
3211 // This will succeed if the string is a full URL, including the http:// 3164 // This will succeed if the string is a full URL, including the http://
@@ -3268,25 +3221,34 @@ BOOL LLWindowMacOSX::dialog_color_picker ( F32 *r, F32 *g, F32 *b)
3268 return (retval); 3221 return (retval);
3269} 3222}
3270 3223
3271static WindowRef dummywindowref = NULL;
3272 3224
3273void *LLWindowMacOSX::getPlatformWindow() 3225void *LLWindowMacOSX::getPlatformWindow()
3274{ 3226{
3275 if(mWindow != NULL) 3227 // NOTE: this will be NULL in fullscreen mode. Plan accordingly.
3276 return (void*)mWindow; 3228 return (void*)mWindow;
3229}
3230
3231void *LLWindowMacOSX::getMediaWindow()
3232{
3233 /*
3234 Mozilla needs to be initialized with a WindowRef to function properly.
3235 (There's no good reason for this, since it shouldn't be interacting with our window in any way, but that's another issue.)
3236 If we're in windowed mode, we _could_ hand it our actual window pointer, but a subsequent switch to fullscreen will destroy that window,
3237 which trips up Mozilla.
3238 Instead of using our actual window, we create an invisible window which will persist for the lifetime of the application and pass that to Mozilla.
3239 This satisfies its deep-seated need to latch onto a WindowRef and solves the issue with switching between fullscreen and windowed modes.
3277 3240
3278 // If we're in fullscreen mode, there's no window pointer available. 3241 Note that we will never destroy this window (by design!), but since only one will ever be created per run of the application, that's okay.
3279 // Since Mozilla needs one to function, create a dummy window here. 3242 */
3280 // Note that we will never destroy it, but since only one will be created per run of the application, that's okay.
3281 3243
3282 if(dummywindowref == NULL) 3244 if(sMediaWindow == NULL)
3283 { 3245 {
3284 Rect window_rect = {100, 100, 200, 200}; 3246 Rect window_rect = {100, 100, 200, 200};
3285 3247
3286 dummywindowref = NewCWindow( 3248 sMediaWindow = NewCWindow(
3287 NULL, 3249 NULL,
3288 &window_rect, 3250 &window_rect,
3289 "\p", 3251 (ConstStr255Param) "\p",
3290 false, // Create the window invisible. 3252 false, // Create the window invisible.
3291 zoomDocProc, // Window with a grow box and a zoom box 3253 zoomDocProc, // Window with a grow box and a zoom box
3292 kLastWindowOfClass, // create it behind other windows 3254 kLastWindowOfClass, // create it behind other windows
@@ -3294,7 +3256,7 @@ void *LLWindowMacOSX::getPlatformWindow()
3294 0); 3256 0);
3295 } 3257 }
3296 3258
3297 return (void*)dummywindowref; 3259 return (void*)sMediaWindow;
3298} 3260}
3299 3261
3300void LLWindowMacOSX::stopDockTileBounce() 3262void LLWindowMacOSX::stopDockTileBounce()
@@ -3402,5 +3364,3 @@ std::string LLWindowMacOSX::getFontListSans()
3402 // The third filename is in UTF8, but it shows up in the font menu as "STHeiti Light" 3364 // The third filename is in UTF8, but it shows up in the font menu as "STHeiti Light"
3403 return "\xE3\x83\x92\xE3\x83\xA9\xE3\x82\xAD\xE3\x82\x99\xE3\x83\x8E\xE8\xA7\x92\xE3\x82\xB3\xE3\x82\x99 Pro W3.otf;\xE3\x83\x92\xE3\x83\xA9\xE3\x82\xAD\xE3\x82\x99\xE3\x83\x8E\xE8\xA7\x92\xE3\x82\xB3\xE3\x82\x99 ProN W3.otf;AppleGothic.dfont;AppleGothic.ttf;\xe5\x8d\x8e\xe6\x96\x87\xe7\xbb\x86\xe9\xbb\x91.ttf"; 3365 return "\xE3\x83\x92\xE3\x83\xA9\xE3\x82\xAD\xE3\x82\x99\xE3\x83\x8E\xE8\xA7\x92\xE3\x82\xB3\xE3\x82\x99 Pro W3.otf;\xE3\x83\x92\xE3\x83\xA9\xE3\x82\xAD\xE3\x82\x99\xE3\x83\x8E\xE8\xA7\x92\xE3\x82\xB3\xE3\x82\x99 ProN W3.otf;AppleGothic.dfont;AppleGothic.ttf;\xe5\x8d\x8e\xe6\x96\x87\xe7\xbb\x86\xe9\xbb\x91.ttf";
3404} 3366}
3405
3406#endif // LL_DARWIN