aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llwindow/llwindowwin32.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llwindow/llwindowwin32.cpp')
-rw-r--r--linden/indra/llwindow/llwindowwin32.cpp154
1 files changed, 49 insertions, 105 deletions
diff --git a/linden/indra/llwindow/llwindowwin32.cpp b/linden/indra/llwindow/llwindowwin32.cpp
index 2001899..3729a71 100644
--- a/linden/indra/llwindow/llwindowwin32.cpp
+++ b/linden/indra/llwindow/llwindowwin32.cpp
@@ -54,8 +54,6 @@
54#include "llstring.h" 54#include "llstring.h"
55#include "lldir.h" 55#include "lldir.h"
56 56
57#include "llglheaders.h"
58
59#include "indra_constants.h" 57#include "indra_constants.h"
60 58
61#include "llpreeditor.h" 59#include "llpreeditor.h"
@@ -82,7 +80,7 @@ LLW32MsgCallback gAsyncMsgCallback = NULL;
82// LLWindowWin32 80// LLWindowWin32
83// 81//
84 82
85void show_window_creation_error(const char* title) 83void show_window_creation_error(const std::string& title)
86{ 84{
87 LL_WARNS("Window") << title << LL_ENDL; 85 LL_WARNS("Window") << title << LL_ENDL;
88} 86}
@@ -359,7 +357,7 @@ LLWinImm::~LLWinImm()
359} 357}
360 358
361 359
362LLWindowWin32::LLWindowWin32(char *title, char *name, S32 x, S32 y, S32 width, 360LLWindowWin32::LLWindowWin32(const std::string& title, const std::string& name, S32 x, S32 y, S32 width,
363 S32 height, U32 flags, 361 S32 height, U32 flags,
364 BOOL fullscreen, BOOL clearBg, 362 BOOL fullscreen, BOOL clearBg,
365 BOOL disable_vsync, BOOL use_gl, 363 BOOL disable_vsync, BOOL use_gl,
@@ -386,7 +384,7 @@ LLWindowWin32::LLWindowWin32(char *title, char *name, S32 x, S32 y, S32 width,
386 RECT window_rect; 384 RECT window_rect;
387 385
388 // Set the window title 386 // Set the window title
389 if (!title) 387 if (title.empty())
390 { 388 {
391 mWindowTitle = new WCHAR[50]; 389 mWindowTitle = new WCHAR[50];
392 wsprintf(mWindowTitle, L"OpenGL Window"); 390 wsprintf(mWindowTitle, L"OpenGL Window");
@@ -394,12 +392,12 @@ LLWindowWin32::LLWindowWin32(char *title, char *name, S32 x, S32 y, S32 width,
394 else 392 else
395 { 393 {
396 mWindowTitle = new WCHAR[256]; // Assume title length < 255 chars. 394 mWindowTitle = new WCHAR[256]; // Assume title length < 255 chars.
397 mbstowcs(mWindowTitle, title, 255); 395 mbstowcs(mWindowTitle, title.c_str(), 255);
398 mWindowTitle[255] = 0; 396 mWindowTitle[255] = 0;
399 } 397 }
400 398
401 // Set the window class name 399 // Set the window class name
402 if (!name) 400 if (name.empty())
403 { 401 {
404 mWindowClassName = new WCHAR[50]; 402 mWindowClassName = new WCHAR[50];
405 wsprintf(mWindowClassName, L"OpenGL Window"); 403 wsprintf(mWindowClassName, L"OpenGL Window");
@@ -407,7 +405,7 @@ LLWindowWin32::LLWindowWin32(char *title, char *name, S32 x, S32 y, S32 width,
407 else 405 else
408 { 406 {
409 mWindowClassName = new WCHAR[256]; // Assume title length < 255 chars. 407 mWindowClassName = new WCHAR[256]; // Assume title length < 255 chars.
410 mbstowcs(mWindowClassName, name, 255); 408 mbstowcs(mWindowClassName, name.c_str(), 255);
411 mWindowClassName[255] = 0; 409 mWindowClassName[255] = 0;
412 } 410 }
413 411
@@ -571,8 +569,7 @@ LLWindowWin32::LLWindowWin32(char *title, char *name, S32 x, S32 y, S32 width,
571 mFullscreenBits = -1; 569 mFullscreenBits = -1;
572 mFullscreenRefresh = -1; 570 mFullscreenRefresh = -1;
573 571
574 char error[256]; /* Flawfinder: ignore */ 572 std::string error = llformat("Unable to run fullscreen at %d x %d.\nRunning in window.", width, height);
575 snprintf(error, sizeof(error), "Unable to run fullscreen at %d x %d.\nRunning in window.", width, height); /* Flawfinder: ignore */
576 OSMessageBox(error, "Error", OSMB_OK); 573 OSMessageBox(error, "Error", OSMB_OK);
577 } 574 }
578 } 575 }
@@ -1390,6 +1387,20 @@ BOOL LLWindowWin32::setCursorPosition(const LLCoordWindow position)
1390 return FALSE; 1387 return FALSE;
1391 } 1388 }
1392 1389
1390 // Inform the application of the new mouse position (needed for per-frame
1391 // hover/picking to function).
1392 LLCoordGL gl_pos;
1393 convertCoords(position, &gl_pos);
1394 mCallbacks->handleMouseMove(this, gl_pos, (MASK)0);
1395
1396 // DEV-18951 VWR-8524 Camera moves wildly when alt-clicking.
1397 // Because we have preemptively notified the application of the new
1398 // mouse position via handleMouseMove() above, we need to clear out
1399 // any stale mouse move events. RN/JC
1400 MSG msg;
1401 while (PeekMessage(&msg, NULL, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
1402 { }
1403
1393 return SetCursorPos(screen_pos.mX, screen_pos.mY); 1404 return SetCursorPos(screen_pos.mX, screen_pos.mY);
1394} 1405}
1395 1406
@@ -1564,7 +1575,9 @@ void LLWindowWin32::gatherInput()
1564 1575
1565 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) && msg_count < MAX_MESSAGE_PER_UPDATE) 1576 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) && msg_count < MAX_MESSAGE_PER_UPDATE)
1566 { 1577 {
1578 mCallbacks->handlePingWatchdog(this, "Main:TranslateGatherInput");
1567 TranslateMessage(&msg); 1579 TranslateMessage(&msg);
1580 mCallbacks->handlePingWatchdog(this, "Main:DispatchGatherInput");
1568 DispatchMessage(&msg); 1581 DispatchMessage(&msg);
1569 msg_count++; 1582 msg_count++;
1570 1583
@@ -1591,7 +1604,7 @@ void LLWindowWin32::gatherInput()
1591 } 1604 }
1592 } 1605 }
1593 */ 1606 */
1594 1607 mCallbacks->handlePingWatchdog(this, "Main:AsyncCallbackGatherInput");
1595 // For async host by name support. Really hacky. 1608 // For async host by name support. Really hacky.
1596 if (gAsyncMsgCallback && (LL_WM_HOST_RESOLVED == msg.message)) 1609 if (gAsyncMsgCallback && (LL_WM_HOST_RESOLVED == msg.message))
1597 { 1610 {
@@ -1942,6 +1955,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
1942 window_imp->convertCoords(window_coord, &gl_coord); 1955 window_imp->convertCoords(window_coord, &gl_coord);
1943 } 1956 }
1944 MASK mask = gKeyboard->currentMask(TRUE); 1957 MASK mask = gKeyboard->currentMask(TRUE);
1958 // generate move event to update mouse coordinates
1959 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
1945 if (window_imp->mCallbacks->handleMouseDown(window_imp, gl_coord, mask)) 1960 if (window_imp->mCallbacks->handleMouseDown(window_imp, gl_coord, mask))
1946 { 1961 {
1947 return 0; 1962 return 0;
@@ -1969,6 +1984,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
1969 window_imp->convertCoords(window_coord, &gl_coord); 1984 window_imp->convertCoords(window_coord, &gl_coord);
1970 } 1985 }
1971 MASK mask = gKeyboard->currentMask(TRUE); 1986 MASK mask = gKeyboard->currentMask(TRUE);
1987 // generate move event to update mouse coordinates
1988 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
1972 if (window_imp->mCallbacks->handleDoubleClick(window_imp, gl_coord, mask) ) 1989 if (window_imp->mCallbacks->handleDoubleClick(window_imp, gl_coord, mask) )
1973 { 1990 {
1974 return 0; 1991 return 0;
@@ -1999,6 +2016,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
1999 window_imp->convertCoords(window_coord, &gl_coord); 2016 window_imp->convertCoords(window_coord, &gl_coord);
2000 } 2017 }
2001 MASK mask = gKeyboard->currentMask(TRUE); 2018 MASK mask = gKeyboard->currentMask(TRUE);
2019 // generate move event to update mouse coordinates
2020 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2002 if (window_imp->mCallbacks->handleMouseUp(window_imp, gl_coord, mask)) 2021 if (window_imp->mCallbacks->handleMouseUp(window_imp, gl_coord, mask))
2003 { 2022 {
2004 return 0; 2023 return 0;
@@ -2015,7 +2034,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2015 window_imp->interruptLanguageTextInput(); 2034 window_imp->interruptLanguageTextInput();
2016 } 2035 }
2017 2036
2018 // Because we move the cursor position in tllviewerhe app, we need to query 2037 // Because we move the cursor position in the llviewerapp, we need to query
2019 // to find out where the cursor at the time the event is handled. 2038 // to find out where the cursor at the time the event is handled.
2020 // If we don't do this, many clicks could get buffered up, and if the 2039 // If we don't do this, many clicks could get buffered up, and if the
2021 // first click changes the cursor position, all subsequent clicks 2040 // first click changes the cursor position, all subsequent clicks
@@ -2031,6 +2050,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2031 window_imp->convertCoords(window_coord, &gl_coord); 2050 window_imp->convertCoords(window_coord, &gl_coord);
2032 } 2051 }
2033 MASK mask = gKeyboard->currentMask(TRUE); 2052 MASK mask = gKeyboard->currentMask(TRUE);
2053 // generate move event to update mouse coordinates
2054 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2034 if (window_imp->mCallbacks->handleRightMouseDown(window_imp, gl_coord, mask)) 2055 if (window_imp->mCallbacks->handleRightMouseDown(window_imp, gl_coord, mask))
2035 { 2056 {
2036 return 0; 2057 return 0;
@@ -2057,6 +2078,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2057 window_imp->convertCoords(window_coord, &gl_coord); 2078 window_imp->convertCoords(window_coord, &gl_coord);
2058 } 2079 }
2059 MASK mask = gKeyboard->currentMask(TRUE); 2080 MASK mask = gKeyboard->currentMask(TRUE);
2081 // generate move event to update mouse coordinates
2082 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2060 if (window_imp->mCallbacks->handleRightMouseUp(window_imp, gl_coord, mask)) 2083 if (window_imp->mCallbacks->handleRightMouseUp(window_imp, gl_coord, mask))
2061 { 2084 {
2062 return 0; 2085 return 0;
@@ -2089,6 +2112,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2089 window_imp->convertCoords(window_coord, &gl_coord); 2112 window_imp->convertCoords(window_coord, &gl_coord);
2090 } 2113 }
2091 MASK mask = gKeyboard->currentMask(TRUE); 2114 MASK mask = gKeyboard->currentMask(TRUE);
2115 // generate move event to update mouse coordinates
2116 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2092 if (window_imp->mCallbacks->handleMiddleMouseDown(window_imp, gl_coord, mask)) 2117 if (window_imp->mCallbacks->handleMiddleMouseDown(window_imp, gl_coord, mask))
2093 { 2118 {
2094 return 0; 2119 return 0;
@@ -2115,6 +2140,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2115 window_imp->convertCoords(window_coord, &gl_coord); 2140 window_imp->convertCoords(window_coord, &gl_coord);
2116 } 2141 }
2117 MASK mask = gKeyboard->currentMask(TRUE); 2142 MASK mask = gKeyboard->currentMask(TRUE);
2143 // generate move event to update mouse coordinates
2144 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2118 if (window_imp->mCallbacks->handleMiddleMouseUp(window_imp, gl_coord, mask)) 2145 if (window_imp->mCallbacks->handleMiddleMouseUp(window_imp, gl_coord, mask))
2119 { 2146 {
2120 return 0; 2147 return 0;
@@ -2376,7 +2403,7 @@ BOOL LLWindowWin32::pasteTextFromClipboard(LLWString &dst)
2376 if (utf16str) 2403 if (utf16str)
2377 { 2404 {
2378 dst = utf16str_to_wstring(utf16str); 2405 dst = utf16str_to_wstring(utf16str);
2379 LLWString::removeCRLF(dst); 2406 LLWStringUtil::removeCRLF(dst);
2380 GlobalUnlock(h_data); 2407 GlobalUnlock(h_data);
2381 success = TRUE; 2408 success = TRUE;
2382 } 2409 }
@@ -2399,7 +2426,7 @@ BOOL LLWindowWin32::copyTextToClipboard(const LLWString& wstr)
2399 2426
2400 // Provide a copy of the data in Unicode format. 2427 // Provide a copy of the data in Unicode format.
2401 LLWString sanitized_string(wstr); 2428 LLWString sanitized_string(wstr);
2402 LLWString::addCRLF(sanitized_string); 2429 LLWStringUtil::addCRLF(sanitized_string);
2403 llutf16string out_utf16 = wstring_to_utf16str(sanitized_string); 2430 llutf16string out_utf16 = wstring_to_utf16str(sanitized_string);
2404 const size_t size_utf16 = (out_utf16.length() + 1) * sizeof(WCHAR); 2431 const size_t size_utf16 = (out_utf16.length() + 1) * sizeof(WCHAR);
2405 2432
@@ -2486,86 +2513,6 @@ BOOL LLWindowWin32::getClientRectInScreenSpace( RECT* rectp )
2486 return success; 2513 return success;
2487} 2514}
2488 2515
2489
2490BOOL LLWindowWin32::sendEmail(const char* address, const char* subject, const char* body_text,
2491 const char* attachment, const char* attachment_displayed_name )
2492{
2493 // Based on "A SendMail() DLL" by Greg Turner, Windows Developer Magazine, Nov. 1997.
2494 // See article for use of GetProcAddress
2495 // No restrictions on use.
2496
2497 enum SendResult
2498 {
2499 LL_EMAIL_SUCCESS,
2500 LL_EMAIL_MAPI_NOT_INSTALLED, // No MAPI Server (eg Microsoft Exchange) installed
2501 LL_EMAIL_MAPILOAD_FAILED, // Load of MAPI32.DLL failed
2502 LL_EMAIL_SEND_FAILED // The message send itself failed
2503 };
2504
2505 SendResult result = LL_EMAIL_SUCCESS;
2506
2507 U32 mapi_installed = GetProfileInt(L"Mail", L"MAPI", 0);
2508 if( !mapi_installed)
2509 {
2510 result = LL_EMAIL_MAPI_NOT_INSTALLED;
2511 }
2512 else
2513 {
2514 HINSTANCE hMAPIInst = LoadLibrary(L"MAPI32.DLL"); /* Flawfinder: ignore */
2515 if(!hMAPIInst)
2516 {
2517 result = LL_EMAIL_MAPILOAD_FAILED;
2518 }
2519 else
2520 {
2521 LPMAPISENDMAIL pMAPISendMail = (LPMAPISENDMAIL) GetProcAddress(hMAPIInst, "MAPISendMail");
2522
2523 // Send the message
2524 MapiRecipDesc recipients[1];
2525 recipients[0].ulReserved = 0;
2526 recipients[0].ulRecipClass = MAPI_TO;
2527 recipients[0].lpszName = (char*)address;
2528 recipients[0].lpszAddress = (char*)address;
2529 recipients[0].ulEIDSize = 0;
2530 recipients[0].lpEntryID = 0;
2531
2532 MapiFileDesc files[1];
2533 files[0].ulReserved = 0;
2534 files[0].flFlags = 0; // non-OLE file
2535 files[0].nPosition = -1; // Leave file location in email unspecified.
2536 files[0].lpszPathName = (char*)attachment; // Must be fully qualified name, including drive letter.
2537 files[0].lpszFileName = (char*)attachment_displayed_name; // If NULL, uses attachment as displayed name.
2538 files[0].lpFileType = NULL; // Recipient will have to figure out what kind of file this is.
2539
2540 MapiMessage msg;
2541 memset(&msg, 0, sizeof(msg));
2542 msg.lpszSubject = (char*)subject; // may be NULL
2543 msg.lpszNoteText = (char*)body_text;
2544 msg.nRecipCount = address ? 1 : 0;
2545 msg.lpRecips = address ? recipients : NULL;
2546 msg.nFileCount = attachment ? 1 : 0;
2547 msg.lpFiles = attachment ? files : NULL;
2548
2549 U32 success = pMAPISendMail(0, (U32) mWindowHandle, &msg, MAPI_DIALOG|MAPI_LOGON_UI|MAPI_NEW_SESSION, 0);
2550 if(success != SUCCESS_SUCCESS)
2551 {
2552 result = LL_EMAIL_SEND_FAILED;
2553 }
2554
2555 FreeLibrary(hMAPIInst);
2556 }
2557 }
2558
2559 return result == LL_EMAIL_SUCCESS;
2560}
2561
2562
2563S32 LLWindowWin32::stat(const char* file_name, struct stat* stat_info)
2564{
2565 llassert( sizeof(struct stat) == sizeof(struct _stat) ); // They are defined identically in sys/stat.h, but I'm paranoid.
2566 return LLFile::stat( file_name, (struct _stat*) stat_info );
2567}
2568
2569void LLWindowWin32::flashIcon(F32 seconds) 2516void LLWindowWin32::flashIcon(F32 seconds)
2570{ 2517{
2571 FLASHWINFO flash_info; 2518 FLASHWINFO flash_info;
@@ -2803,12 +2750,12 @@ void LLSplashScreenWin32::showImpl()
2803} 2750}
2804 2751
2805 2752
2806void LLSplashScreenWin32::updateImpl(const char *mesg) 2753void LLSplashScreenWin32::updateImpl(const std::string& mesg)
2807{ 2754{
2808 if (!mWindow) return; 2755 if (!mWindow) return;
2809 2756
2810 WCHAR w_mesg[1024]; 2757 WCHAR w_mesg[1024];
2811 mbstowcs(w_mesg, mesg, 1024); 2758 mbstowcs(w_mesg, mesg.c_str(), 1024);
2812 2759
2813 SendDlgItemMessage(mWindow, 2760 SendDlgItemMessage(mWindow,
2814 666, // HACK: text id 2761 666, // HACK: text id
@@ -2840,7 +2787,7 @@ LRESULT CALLBACK LLSplashScreenWin32::windowProc(HWND h_wnd, UINT u_msg,
2840// Helper Funcs 2787// Helper Funcs
2841// 2788//
2842 2789
2843S32 OSMessageBoxWin32(const char* text, const char* caption, U32 type) 2790S32 OSMessageBoxWin32(const std::string& text, const std::string& caption, U32 type)
2844{ 2791{
2845 UINT uType; 2792 UINT uType;
2846 2793
@@ -2861,7 +2808,7 @@ S32 OSMessageBoxWin32(const char* text, const char* caption, U32 type)
2861 } 2808 }
2862 2809
2863 // HACK! Doesn't properly handle wide strings! 2810 // HACK! Doesn't properly handle wide strings!
2864 int retval_win = MessageBoxA(NULL, text, caption, uType); 2811 int retval_win = MessageBoxA(NULL, text.c_str(), caption.c_str(), uType);
2865 S32 retval; 2812 S32 retval;
2866 2813
2867 switch(retval_win) 2814 switch(retval_win)
@@ -2887,15 +2834,13 @@ S32 OSMessageBoxWin32(const char* text, const char* caption, U32 type)
2887} 2834}
2888 2835
2889 2836
2890void spawn_web_browser(const char* escaped_url ) 2837void LLWindowWin32::spawnWebBrowser(const std::string& escaped_url )
2891{ 2838{
2892 bool found = false; 2839 bool found = false;
2893 S32 i; 2840 S32 i;
2894 for (i = 0; i < gURLProtocolWhitelistCount; i++) 2841 for (i = 0; i < gURLProtocolWhitelistCount; i++)
2895 { 2842 {
2896 S32 len = strlen(gURLProtocolWhitelist[i]); /* Flawfinder: ignore */ 2843 if (escaped_url.find(gURLProtocolWhitelist[i]) == 0)
2897 if (!strncmp(escaped_url, gURLProtocolWhitelist[i], len)
2898 && escaped_url[len] == ':')
2899 { 2844 {
2900 found = true; 2845 found = true;
2901 break; 2846 break;
@@ -2931,10 +2876,9 @@ void spawn_web_browser(const char* escaped_url )
2931 // Figure out the user's default web browser 2876 // Figure out the user's default web browser
2932 // HKEY_CLASSES_ROOT\http\shell\open\command 2877 // HKEY_CLASSES_ROOT\http\shell\open\command
2933 /* 2878 /*
2934 char reg_path_str[256]; // Flawfinder: ignore 2879 std::string reg_path_str = gURLProtocolWhitelistHandler[i] + "\\shell\\open\\command";
2935 snprintf(reg_path_str, sizeof(reg_path_str), "%s\\shell\\open\\command", gURLProtocolWhitelistHandler[i]); // Flawfinder: ignore
2936 WCHAR reg_path_wstr[256]; 2880 WCHAR reg_path_wstr[256];
2937 mbstowcs(reg_path_wstr, reg_path_str, sizeof(reg_path_wstr)/sizeof(reg_path_wstr[0])); 2881 mbstowcs(reg_path_wstr, reg_path_str.c_str(), sizeof(reg_path_wstr)/sizeof(reg_path_wstr[0]));
2938 2882
2939 HKEY key; 2883 HKEY key;
2940 WCHAR browser_open_wstr[1024]; 2884 WCHAR browser_open_wstr[1024];