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.cpp150
1 files changed, 46 insertions, 104 deletions
diff --git a/linden/indra/llwindow/llwindowwin32.cpp b/linden/indra/llwindow/llwindowwin32.cpp
index 2001899..047fa31 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
@@ -1942,6 +1953,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
1942 window_imp->convertCoords(window_coord, &gl_coord); 1953 window_imp->convertCoords(window_coord, &gl_coord);
1943 } 1954 }
1944 MASK mask = gKeyboard->currentMask(TRUE); 1955 MASK mask = gKeyboard->currentMask(TRUE);
1956 // generate move event to update mouse coordinates
1957 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
1945 if (window_imp->mCallbacks->handleMouseDown(window_imp, gl_coord, mask)) 1958 if (window_imp->mCallbacks->handleMouseDown(window_imp, gl_coord, mask))
1946 { 1959 {
1947 return 0; 1960 return 0;
@@ -1969,6 +1982,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
1969 window_imp->convertCoords(window_coord, &gl_coord); 1982 window_imp->convertCoords(window_coord, &gl_coord);
1970 } 1983 }
1971 MASK mask = gKeyboard->currentMask(TRUE); 1984 MASK mask = gKeyboard->currentMask(TRUE);
1985 // generate move event to update mouse coordinates
1986 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
1972 if (window_imp->mCallbacks->handleDoubleClick(window_imp, gl_coord, mask) ) 1987 if (window_imp->mCallbacks->handleDoubleClick(window_imp, gl_coord, mask) )
1973 { 1988 {
1974 return 0; 1989 return 0;
@@ -1999,6 +2014,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
1999 window_imp->convertCoords(window_coord, &gl_coord); 2014 window_imp->convertCoords(window_coord, &gl_coord);
2000 } 2015 }
2001 MASK mask = gKeyboard->currentMask(TRUE); 2016 MASK mask = gKeyboard->currentMask(TRUE);
2017 // generate move event to update mouse coordinates
2018 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2002 if (window_imp->mCallbacks->handleMouseUp(window_imp, gl_coord, mask)) 2019 if (window_imp->mCallbacks->handleMouseUp(window_imp, gl_coord, mask))
2003 { 2020 {
2004 return 0; 2021 return 0;
@@ -2015,7 +2032,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2015 window_imp->interruptLanguageTextInput(); 2032 window_imp->interruptLanguageTextInput();
2016 } 2033 }
2017 2034
2018 // Because we move the cursor position in tllviewerhe app, we need to query 2035 // 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. 2036 // 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 2037 // 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 2038 // first click changes the cursor position, all subsequent clicks
@@ -2031,6 +2048,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2031 window_imp->convertCoords(window_coord, &gl_coord); 2048 window_imp->convertCoords(window_coord, &gl_coord);
2032 } 2049 }
2033 MASK mask = gKeyboard->currentMask(TRUE); 2050 MASK mask = gKeyboard->currentMask(TRUE);
2051 // generate move event to update mouse coordinates
2052 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2034 if (window_imp->mCallbacks->handleRightMouseDown(window_imp, gl_coord, mask)) 2053 if (window_imp->mCallbacks->handleRightMouseDown(window_imp, gl_coord, mask))
2035 { 2054 {
2036 return 0; 2055 return 0;
@@ -2057,6 +2076,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2057 window_imp->convertCoords(window_coord, &gl_coord); 2076 window_imp->convertCoords(window_coord, &gl_coord);
2058 } 2077 }
2059 MASK mask = gKeyboard->currentMask(TRUE); 2078 MASK mask = gKeyboard->currentMask(TRUE);
2079 // generate move event to update mouse coordinates
2080 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2060 if (window_imp->mCallbacks->handleRightMouseUp(window_imp, gl_coord, mask)) 2081 if (window_imp->mCallbacks->handleRightMouseUp(window_imp, gl_coord, mask))
2061 { 2082 {
2062 return 0; 2083 return 0;
@@ -2089,6 +2110,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2089 window_imp->convertCoords(window_coord, &gl_coord); 2110 window_imp->convertCoords(window_coord, &gl_coord);
2090 } 2111 }
2091 MASK mask = gKeyboard->currentMask(TRUE); 2112 MASK mask = gKeyboard->currentMask(TRUE);
2113 // generate move event to update mouse coordinates
2114 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2092 if (window_imp->mCallbacks->handleMiddleMouseDown(window_imp, gl_coord, mask)) 2115 if (window_imp->mCallbacks->handleMiddleMouseDown(window_imp, gl_coord, mask))
2093 { 2116 {
2094 return 0; 2117 return 0;
@@ -2115,6 +2138,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
2115 window_imp->convertCoords(window_coord, &gl_coord); 2138 window_imp->convertCoords(window_coord, &gl_coord);
2116 } 2139 }
2117 MASK mask = gKeyboard->currentMask(TRUE); 2140 MASK mask = gKeyboard->currentMask(TRUE);
2141 // generate move event to update mouse coordinates
2142 window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask);
2118 if (window_imp->mCallbacks->handleMiddleMouseUp(window_imp, gl_coord, mask)) 2143 if (window_imp->mCallbacks->handleMiddleMouseUp(window_imp, gl_coord, mask))
2119 { 2144 {
2120 return 0; 2145 return 0;
@@ -2376,7 +2401,7 @@ BOOL LLWindowWin32::pasteTextFromClipboard(LLWString &dst)
2376 if (utf16str) 2401 if (utf16str)
2377 { 2402 {
2378 dst = utf16str_to_wstring(utf16str); 2403 dst = utf16str_to_wstring(utf16str);
2379 LLWString::removeCRLF(dst); 2404 LLWStringUtil::removeCRLF(dst);
2380 GlobalUnlock(h_data); 2405 GlobalUnlock(h_data);
2381 success = TRUE; 2406 success = TRUE;
2382 } 2407 }
@@ -2399,7 +2424,7 @@ BOOL LLWindowWin32::copyTextToClipboard(const LLWString& wstr)
2399 2424
2400 // Provide a copy of the data in Unicode format. 2425 // Provide a copy of the data in Unicode format.
2401 LLWString sanitized_string(wstr); 2426 LLWString sanitized_string(wstr);
2402 LLWString::addCRLF(sanitized_string); 2427 LLWStringUtil::addCRLF(sanitized_string);
2403 llutf16string out_utf16 = wstring_to_utf16str(sanitized_string); 2428 llutf16string out_utf16 = wstring_to_utf16str(sanitized_string);
2404 const size_t size_utf16 = (out_utf16.length() + 1) * sizeof(WCHAR); 2429 const size_t size_utf16 = (out_utf16.length() + 1) * sizeof(WCHAR);
2405 2430
@@ -2486,86 +2511,6 @@ BOOL LLWindowWin32::getClientRectInScreenSpace( RECT* rectp )
2486 return success; 2511 return success;
2487} 2512}
2488 2513
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) 2514void LLWindowWin32::flashIcon(F32 seconds)
2570{ 2515{
2571 FLASHWINFO flash_info; 2516 FLASHWINFO flash_info;
@@ -2803,12 +2748,12 @@ void LLSplashScreenWin32::showImpl()
2803} 2748}
2804 2749
2805 2750
2806void LLSplashScreenWin32::updateImpl(const char *mesg) 2751void LLSplashScreenWin32::updateImpl(const std::string& mesg)
2807{ 2752{
2808 if (!mWindow) return; 2753 if (!mWindow) return;
2809 2754
2810 WCHAR w_mesg[1024]; 2755 WCHAR w_mesg[1024];
2811 mbstowcs(w_mesg, mesg, 1024); 2756 mbstowcs(w_mesg, mesg.c_str(), 1024);
2812 2757
2813 SendDlgItemMessage(mWindow, 2758 SendDlgItemMessage(mWindow,
2814 666, // HACK: text id 2759 666, // HACK: text id
@@ -2840,7 +2785,7 @@ LRESULT CALLBACK LLSplashScreenWin32::windowProc(HWND h_wnd, UINT u_msg,
2840// Helper Funcs 2785// Helper Funcs
2841// 2786//
2842 2787
2843S32 OSMessageBoxWin32(const char* text, const char* caption, U32 type) 2788S32 OSMessageBoxWin32(const std::string& text, const std::string& caption, U32 type)
2844{ 2789{
2845 UINT uType; 2790 UINT uType;
2846 2791
@@ -2861,7 +2806,7 @@ S32 OSMessageBoxWin32(const char* text, const char* caption, U32 type)
2861 } 2806 }
2862 2807
2863 // HACK! Doesn't properly handle wide strings! 2808 // HACK! Doesn't properly handle wide strings!
2864 int retval_win = MessageBoxA(NULL, text, caption, uType); 2809 int retval_win = MessageBoxA(NULL, text.c_str(), caption.c_str(), uType);
2865 S32 retval; 2810 S32 retval;
2866 2811
2867 switch(retval_win) 2812 switch(retval_win)
@@ -2887,15 +2832,13 @@ S32 OSMessageBoxWin32(const char* text, const char* caption, U32 type)
2887} 2832}
2888 2833
2889 2834
2890void spawn_web_browser(const char* escaped_url ) 2835void LLWindowWin32::spawnWebBrowser(const std::string& escaped_url )
2891{ 2836{
2892 bool found = false; 2837 bool found = false;
2893 S32 i; 2838 S32 i;
2894 for (i = 0; i < gURLProtocolWhitelistCount; i++) 2839 for (i = 0; i < gURLProtocolWhitelistCount; i++)
2895 { 2840 {
2896 S32 len = strlen(gURLProtocolWhitelist[i]); /* Flawfinder: ignore */ 2841 if (escaped_url.find(gURLProtocolWhitelist[i]) == 0)
2897 if (!strncmp(escaped_url, gURLProtocolWhitelist[i], len)
2898 && escaped_url[len] == ':')
2899 { 2842 {
2900 found = true; 2843 found = true;
2901 break; 2844 break;
@@ -2931,10 +2874,9 @@ void spawn_web_browser(const char* escaped_url )
2931 // Figure out the user's default web browser 2874 // Figure out the user's default web browser
2932 // HKEY_CLASSES_ROOT\http\shell\open\command 2875 // HKEY_CLASSES_ROOT\http\shell\open\command
2933 /* 2876 /*
2934 char reg_path_str[256]; // Flawfinder: ignore 2877 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]; 2878 WCHAR reg_path_wstr[256];
2937 mbstowcs(reg_path_wstr, reg_path_str, sizeof(reg_path_wstr)/sizeof(reg_path_wstr[0])); 2879 mbstowcs(reg_path_wstr, reg_path_str.c_str(), sizeof(reg_path_wstr)/sizeof(reg_path_wstr[0]));
2938 2880
2939 HKEY key; 2881 HKEY key;
2940 WCHAR browser_open_wstr[1024]; 2882 WCHAR browser_open_wstr[1024];