summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-06-21 21:11:28 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-06-21 21:11:28 +0000
commit6b327577051e49ef853117e9c04442c408fdf934 (patch)
treea344e021ffa4a9f2c01c4d10aa1c6924b5d9112a
parent341d37fdcb9ed6469974ec5d0083c7c376618656 (diff)
MS_UTILS_OPENURL Unicode
git-svn-id: http://svn.miranda-ng.org/main/trunk@520 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--include/m_utils.h14
-rw-r--r--src/modules/help/help.cpp15
-rw-r--r--src/modules/utils/openurl.cpp194
3 files changed, 39 insertions, 184 deletions
diff --git a/include/m_utils.h b/include/m_utils.h
index 34d82594e8..b8366f31a9 100644
--- a/include/m_utils.h
+++ b/include/m_utils.h
@@ -41,13 +41,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//and simple string scrambling, but they are very db-orientated
/* Opens a URL in the user's default web browser v0.1.0.1+
-wParam=bOpenInNewWindow
-lParam=(LPARAM)(const char*)szUrl
+wParam = OUF_* flags
+lParam = (LPARAM)(const TCHAR*)szUrl
returns 0 always
bOpenInNewWindow should be zero to open the URL in the browser window the user
last used, or nonzero to open in a new browser window. If there's no browser
running, one will be opened to show the URL.
*/
+
+#define OUF_NEWWINDOW 1
+#define OUF_UNICODE 2
+
+#if defined( _UNICODE )
+ #define OUF_TCHAR OUF_UNICODE
+#else
+ #define OUF_TCHAR 0
+#endif
+
#define MS_UTILS_OPENURL "Utils/OpenURL"
/* Resizes a dialog by calling a custom routine to move the individual
diff --git a/src/modules/help/help.cpp b/src/modules/help/help.cpp
index d6035957b7..33b37e86b0 100644
--- a/src/modules/help/help.cpp
+++ b/src/modules/help/help.cpp
@@ -50,22 +50,21 @@ static INT_PTR WebsiteCommand(WPARAM, LPARAM)
return 0;
}
-static int BugCommandEvent(WPARAM wParam, LPARAM lParam) {
- char *szUrl = (char*)lParam;
+static int BugCommandEvent(WPARAM wParam, LPARAM lParam)
+{
+ char *szUrl = (char*)lParam;
+ if (szUrl)
+ CallService(MS_UTILS_OPENURL, 1, (LPARAM)szUrl);
- if (szUrl) {
- CallService(MS_UTILS_OPENURL, 1, (LPARAM)szUrl);
- }
- return 0;
+ return 0;
}
static INT_PTR BugCommand(WPARAM, LPARAM)
{
- NotifyEventHooks(hBugEvent, 0, (LPARAM)"http://code.google.com/p/miranda/issues/list");
+ NotifyEventHooks(hBugEvent, 0, (LPARAM)"http://code.google.com/p/miranda/issues/list");
return 0;
}
-
int ShutdownHelpModule(WPARAM, LPARAM)
{
if (IsWindow(hAboutDlg)) DestroyWindow(hAboutDlg);
diff --git a/src/modules/utils/openurl.cpp b/src/modules/utils/openurl.cpp
index 296b9a3ecc..e2cf170359 100644
--- a/src/modules/utils/openurl.cpp
+++ b/src/modules/utils/openurl.cpp
@@ -23,206 +23,52 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "..\..\core\commonheaders.h"
#include <ctype.h>
-#define DDEMESSAGETIMEOUT 1000
-#define WNDCLASS_DDEMSGWINDOW _T("MirandaDdeMsgWindow")
-
-struct DdeMsgWindowData {
- int fAcked, fData;
- HWND hwndDde;
-};
-
-static LRESULT CALLBACK DdeMessageWindow(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- struct DdeMsgWindowData *dat;
- ATOM hSzItem;
- HGLOBAL hDdeData;
-
- dat=(struct DdeMsgWindowData*)GetWindowLongPtr(hwnd, 0);
- switch(msg) {
- case WM_DDE_ACK:
- dat->fAcked=1;
- dat->hwndDde=(HWND)wParam;
- return 0;
- case WM_DDE_DATA:
- UnpackDDElParam(msg, lParam, (PUINT_PTR)&hDdeData, (PUINT_PTR)&hSzItem);
- dat->fData=1;
- if (hDdeData) {
- DDEDATA *data;
- int release;
- data=(DDEDATA*)GlobalLock(hDdeData);
- if (data->fAckReq) {
- DDEACK ack={0};
- PostMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, *(PUINT)&ack, (UINT)hSzItem));
- }
- else GlobalDeleteAtom(hSzItem);
- release=data->fRelease;
- GlobalUnlock(hDdeData);
- if (release) GlobalFree(hDdeData);
- }
- else GlobalDeleteAtom(hSzItem);
- return 0;
- }
- return DefWindowProc(hwnd, msg, wParam, lParam);
-}
-
-static int DoDdeRequest(const char *szItemName, HWND hwndDdeMsg)
-{
- ATOM hSzItemName;
- DWORD timeoutTick, thisTick;
- MSG msg;
- struct DdeMsgWindowData *dat=(struct DdeMsgWindowData*)GetWindowLongPtr(hwndDdeMsg, 0);
-
- hSzItemName=GlobalAddAtomA(szItemName);
- if ( !PostMessage(dat->hwndDde, WM_DDE_REQUEST, (WPARAM)hwndDdeMsg, MAKELPARAM(CF_TEXT, hSzItemName))) {
- GlobalDeleteAtom(hSzItemName);
- return 1;
- }
- timeoutTick=GetTickCount()+5000;
- dat->fData=0; dat->fAcked=0;
- do {
- if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- if (dat->fData || dat->fAcked) break;
- thisTick=GetTickCount();
- if (thisTick>timeoutTick) break;
- } while (MsgWaitForMultipleObjects(0, NULL, FALSE, timeoutTick-thisTick, QS_ALLINPUT) == WAIT_OBJECT_0);
-
- if ( !dat->fData) {
- GlobalDeleteAtom(hSzItemName);
- return 1;
- }
- return 0;
-}
-
-//see Q160957 and http://developer.netscape.com/docs/manuals/communicator/DDE/index.htm
-static int DdeOpenUrl(const char *szBrowser, char *szUrl, int newWindow, HWND hwndDdeMsg)
-{
- ATOM hSzBrowser, hSzTopic;
- DWORD_PTR dwResult;
- char *szItemName;
- struct DdeMsgWindowData *dat=(struct DdeMsgWindowData*)GetWindowLongPtr(hwndDdeMsg, 0);
-
- hSzBrowser=GlobalAddAtomA(szBrowser);
- hSzTopic=GlobalAddAtomA("WWW_OpenURL");
- dat->fAcked=0;
- if ( !SendMessageTimeout(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)hwndDdeMsg, MAKELPARAM(hSzBrowser, hSzTopic), SMTO_ABORTIFHUNG|SMTO_NORMAL, DDEMESSAGETIMEOUT, &dwResult)
- || !dat->fAcked) {
- GlobalDeleteAtom(hSzTopic);
- GlobalDeleteAtom(hSzBrowser);
- return 1;
- }
- szItemName=(char*)mir_alloc(lstrlenA(szUrl)+7);
- wsprintfA(szItemName, "\"%s\", , %d", szUrl, newWindow?0:-1);
- if (DoDdeRequest(szItemName, hwndDdeMsg)) {
- mir_free(szItemName);
- GlobalDeleteAtom(hSzTopic);
- GlobalDeleteAtom(hSzBrowser);
- return 1;
- }
- PostMessage(dat->hwndDde, WM_DDE_TERMINATE, (WPARAM)hwndDdeMsg, 0);
- GlobalDeleteAtom(hSzTopic);
- GlobalDeleteAtom(hSzBrowser);
- mir_free(szItemName);
- return 0;
-}
-
typedef struct {
- char *szUrl;
- int newWindow;
-} TOpenUrlInfo;
+ TCHAR *szUrl;
+ int newWindow;
+}
+ TOpenUrlInfo;
static void OpenURLThread(void *arg)
{
TOpenUrlInfo *hUrlInfo = (TOpenUrlInfo*)arg;
- char *szResult;
- HWND hwndDdeMsg;
- struct DdeMsgWindowData msgWndData={0};
- char *pszProtocol;
- HKEY hKey;
- char szSubkey[80];
- char szCommandName[MAX_PATH];
- DWORD dataLength;
- int success=0;
-
- if ( !hUrlInfo->szUrl) return;
- hwndDdeMsg=CreateWindow(WNDCLASS_DDEMSGWINDOW, _T(""), 0, 0, 0, 0, 0, NULL, NULL, hMirandaInst, NULL);
- SetWindowLongPtr(hwndDdeMsg, 0, (LONG_PTR)&msgWndData);
-
- if ( !_strnicmp(hUrlInfo->szUrl, "ftp:", 4) || !_strnicmp(hUrlInfo->szUrl, "ftp.", 4)) pszProtocol="ftp";
- if ( !_strnicmp(hUrlInfo->szUrl, "mailto:", 7)) pszProtocol="mailto";
- if ( !_strnicmp(hUrlInfo->szUrl, "news:", 5)) pszProtocol="news";
- else pszProtocol="http";
- wsprintfA(szSubkey, "%s\\shell\\open\\command", pszProtocol);
- if (RegOpenKeyExA(HKEY_CURRENT_USER, szSubkey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS
- || RegOpenKeyExA(HKEY_CLASSES_ROOT, szSubkey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
- dataLength=SIZEOF(szCommandName);
- if (RegQueryValueEx(hKey, NULL, NULL, NULL, (PBYTE)szCommandName, &dataLength) == ERROR_SUCCESS) {
- _strlwr(szCommandName);
- if (strstr(szCommandName, "mozilla") || strstr(szCommandName, "netscape"))
- success=(DdeOpenUrl("mozilla", hUrlInfo->szUrl, hUrlInfo->newWindow, hwndDdeMsg) == 0 || DdeOpenUrl("netscape", hUrlInfo->szUrl, hUrlInfo->newWindow, hwndDdeMsg) == 0);
- else if (strstr(szCommandName, "iexplore") || strstr(szCommandName, "msimn"))
- success=0 == DdeOpenUrl("iexplore", hUrlInfo->szUrl, hUrlInfo->newWindow, hwndDdeMsg);
- else if (strstr(szCommandName, "opera"))
- success=0 == DdeOpenUrl("opera", hUrlInfo->szUrl, hUrlInfo->newWindow, hwndDdeMsg);
- //opera's the default anyway
- }
- RegCloseKey(hKey);
- }
-
- DestroyWindow(hwndDdeMsg);
- if (success) return;
+ if ( !hUrlInfo->szUrl)
+ return;
//wack a protocol on it
+ TCHAR *szResult = (TCHAR*)mir_alloc(sizeof(TCHAR)*(lstrlen(hUrlInfo->szUrl)+9));
if ((isalpha(hUrlInfo->szUrl[0]) && hUrlInfo->szUrl[1] == ':') || hUrlInfo->szUrl[0] == '\\') {
- szResult=(char*)mir_alloc(lstrlenA(hUrlInfo->szUrl)+9);
- wsprintfA(szResult, "file:///%s", hUrlInfo->szUrl);
+ wsprintf(szResult, _T("file:///%s"), hUrlInfo->szUrl);
}
else {
int i;
- for (i=0;isalpha(hUrlInfo->szUrl[i]);i++);
- if (hUrlInfo->szUrl[i] == ':') szResult=mir_strdup(hUrlInfo->szUrl);
+ for (i=0; _istalpha(hUrlInfo->szUrl[i]); i++);
+ if (hUrlInfo->szUrl[i] == ':')
+ szResult = mir_tstrdup(hUrlInfo->szUrl);
else {
- if ( !_strnicmp(hUrlInfo->szUrl, "ftp.", 4)) {
- szResult=(char*)mir_alloc(lstrlenA(hUrlInfo->szUrl)+7);
- wsprintfA(szResult, "ftp://%s", hUrlInfo->szUrl);
- }
- else {
- szResult=(char*)mir_alloc(lstrlenA(hUrlInfo->szUrl)+8);
- wsprintfA(szResult, "http://%s", hUrlInfo->szUrl);
- }
+ if ( !_tcsnicmp(hUrlInfo->szUrl, _T("ftp."), 4))
+ wsprintf(szResult, _T("ftp://%s"), hUrlInfo->szUrl);
+ else
+ wsprintf(szResult, _T("http://%s"), hUrlInfo->szUrl);
}
}
- ShellExecuteA(NULL, "open", szResult, NULL, NULL, SW_SHOWDEFAULT);
+ ShellExecute(NULL, _T("open"), szResult, NULL, NULL, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT);
mir_free(szResult);
mir_free(hUrlInfo->szUrl);
mir_free(hUrlInfo);
- return;
}
-static INT_PTR OpenURL(WPARAM wParam, LPARAM lParam) {
+static INT_PTR OpenURL(WPARAM wParam, LPARAM lParam)
+{
TOpenUrlInfo *hUrlInfo = (TOpenUrlInfo*)mir_alloc(sizeof(TOpenUrlInfo));
- hUrlInfo->szUrl = (char*)lParam?mir_strdup((char*)lParam):NULL;
- hUrlInfo->newWindow = (int)wParam;
+ hUrlInfo->szUrl = (wParam & OUF_UNICODE) ? mir_wstrdup((WCHAR*)lParam) : mir_a2t((char*)lParam);
+ hUrlInfo->newWindow = (wParam & OUF_NEWWINDOW) != 0;
forkthread(OpenURLThread, 0, (void*)hUrlInfo);
return 0;
}
int InitOpenUrl(void)
{
- WNDCLASS wcl;
- wcl.lpfnWndProc=DdeMessageWindow;
- wcl.cbClsExtra=0;
- wcl.cbWndExtra=sizeof(void*);
- wcl.hInstance=hMirandaInst;
- wcl.hCursor=NULL;
- wcl.lpszClassName=WNDCLASS_DDEMSGWINDOW;
- wcl.hbrBackground=NULL;
- wcl.hIcon=NULL;
- wcl.lpszMenuName=NULL;
- wcl.style=0;
- RegisterClass(&wcl);
CreateServiceFunction(MS_UTILS_OPENURL, OpenURL);
return 0;
}