From ba456be50d3b780e4accf075ba78d5badf282b05 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 21 Jun 2015 19:09:56 +0000 Subject: MS_UTIL_OPENURL -> mir_core::Utils_OpenUrl git-svn-id: http://svn.miranda-ng.org/main/trunk@14306 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/core/stdchat/src/window.cpp | 17 +++----- src/core/stdhelp/src/help.cpp | 6 +-- src/core/stdurl/urldialogs.cpp | 4 +- src/core/stduserinfo/src/stdinfo.cpp | 4 +- src/mir_app/src/enterstring.cpp | 6 +-- src/mir_app/src/lpopts.cpp | 4 +- src/mir_app/src/openurl.cpp | 82 ------------------------------------ src/mir_app/src/pluginopts.cpp | 4 +- src/mir_app/src/proto_opts.cpp | 2 +- src/mir_app/src/skin2opts.cpp | 2 +- src/mir_app/src/sounds.cpp | 2 +- src/mir_app/src/utils.cpp | 3 -- src/mir_core/src/mir_core.def | 2 + src/mir_core/src/mir_core64.def | 2 + src/mir_core/src/openurl.cpp | 78 ++++++++++++++++++++++++++++++++++ 15 files changed, 105 insertions(+), 113 deletions(-) delete mode 100644 src/mir_app/src/openurl.cpp create mode 100644 src/mir_core/src/openurl.cpp (limited to 'src') diff --git a/src/core/stdchat/src/window.cpp b/src/core/stdchat/src/window.cpp index 13dc4c0497..511c18c65b 100644 --- a/src/core/stdchat/src/window.cpp +++ b/src/core/stdchat/src/window.cpp @@ -2215,18 +2215,15 @@ LABEL_SHOWWINDOW: case ID_SEARCH_GOOGLE: if (pszWord[0]) - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, - (LPARAM)CMString(FORMAT, _T("http://www.google.com/search?q=%s"), pszWord).GetString()); + Utils_OpenUrlT(CMString(FORMAT, _T("http://www.google.com/search?q=%s"), pszWord)); PostMessage(hwndDlg, WM_MOUSEACTIVATE, 0, 0); break; case ID_SEARCH_WIKIPEDIA: - if (pszWord[0]) { - TCHAR szURL[1024]; - mir_sntprintf(szURL, _countof(szURL), _T("http://en.wikipedia.org/wiki/%s"), pszWord); - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)szURL); - } + if (pszWord[0]) + Utils_OpenUrlT(CMString(FORMAT, _T("http://en.wikipedia.org/wiki/%s"), pszWord)); + PostMessage(hwndDlg, WM_MOUSEACTIVATE, 0, 0); break; @@ -2267,11 +2264,11 @@ LABEL_SHOWWINDOW: ClientToScreen(((NMHDR *) lParam)->hwndFrom, &pt); switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL)) { case ID_NEW: - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW|OUF_TCHAR, (LPARAM) tr.lpstrText); + Utils_OpenUrlT(tr.lpstrText); break; case ID_CURR: - CallService(MS_UTILS_OPENURL, OUF_TCHAR, (LPARAM) tr.lpstrText); + Utils_OpenUrlT(tr.lpstrText); break; case ID_COPY: @@ -2292,7 +2289,7 @@ LABEL_SHOWWINDOW: return TRUE; } - CallService(MS_UTILS_OPENURL, OUF_TCHAR|OUF_NEWWINDOW, (LPARAM) tr.lpstrText); + Utils_OpenUrlT(tr.lpstrText); SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); mir_free(tr.lpstrText); break; diff --git a/src/core/stdhelp/src/help.cpp b/src/core/stdhelp/src/help.cpp index af276a413d..a6a09e1220 100644 --- a/src/core/stdhelp/src/help.cpp +++ b/src/core/stdhelp/src/help.cpp @@ -41,19 +41,19 @@ static INT_PTR AboutCommand(WPARAM wParam, LPARAM) static INT_PTR IndexCommand(WPARAM, LPARAM) { - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)_T("http://wiki.miranda-ng.org")); + Utils_OpenUrl("http://wiki.miranda-ng.org"); return 0; } static INT_PTR WebsiteCommand(WPARAM, LPARAM) { - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)_T("http://miranda-ng.org")); + Utils_OpenUrl("http://miranda-ng.org"); return 0; } static INT_PTR BugCommand(WPARAM, LPARAM) { - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)_T("http://trac.miranda-ng.org/newticket")); + Utils_OpenUrl("http://trac.miranda-ng.org/newticket"); return 0; } diff --git a/src/core/stdurl/urldialogs.cpp b/src/core/stdurl/urldialogs.cpp index f654cae874..3fb66a7e25 100644 --- a/src/core/stdurl/urldialogs.cpp +++ b/src/core/stdurl/urldialogs.cpp @@ -168,10 +168,10 @@ INT_PTR CALLBACK DlgProcUrlRecv(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP GetDlgItemTextA(hwndDlg, IDC_URL, url, _countof(url)); switch(TrackPopupMenu(hSubMenu, TPM_RETURNCMD, rc.left, rc.bottom, 0, hwndDlg, NULL)) { case IDM_OPENNEW: - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)url); + Utils_OpenUrl(url); break; case IDM_OPENEXISTING: - CallService(MS_UTILS_OPENURL, 0, (LPARAM)url); + Utils_OpenUrl(url); break; case IDM_COPYLINK: { diff --git a/src/core/stduserinfo/src/stdinfo.cpp b/src/core/stduserinfo/src/stdinfo.cpp index 0ac9910f84..d51607ad5c 100644 --- a/src/core/stduserinfo/src/stdinfo.cpp +++ b/src/core/stduserinfo/src/stdinfo.cpp @@ -345,7 +345,7 @@ static INT_PTR CALLBACK WorkDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_WEBPAGE))) { char szPage[256]; GetDlgItemTextA(hwndDlg, IDC_WEBPAGE, szPage, _countof(szPage)); - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)szPage); + Utils_OpenUrl(szPage); } } break; @@ -483,7 +483,7 @@ static INT_PTR CALLBACK BackgroundDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_WEBPAGE))) { char szPage[256]; GetDlgItemTextA(hwndDlg, IDC_WEBPAGE, szPage, _countof(szPage)); - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)szPage); + Utils_OpenUrl(szPage); } break; } diff --git a/src/mir_app/src/enterstring.cpp b/src/mir_app/src/enterstring.cpp index d1d42ab4cc..1019b695e3 100644 --- a/src/mir_app/src/enterstring.cpp +++ b/src/mir_app/src/enterstring.cpp @@ -198,11 +198,9 @@ static INT_PTR CALLBACK sttEnterStringDlgProc(HWND hwndDlg, UINT msg, WPARAM wPa TEXTRANGE tr; tr.chrg = param->chrg; tr.lpstrText = (TCHAR *)mir_alloc(sizeof(TCHAR)*(tr.chrg.cpMax - tr.chrg.cpMin + 2)); - SendMessage(param->nmhdr.hwndFrom, EM_GETTEXTRANGE, 0, (LPARAM)& tr); + SendMessage(param->nmhdr.hwndFrom, EM_GETTEXTRANGE, 0, (LPARAM)&tr); - char *tmp = mir_t2a(tr.lpstrText); - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)tmp); - mir_free(tmp); + Utils_OpenUrlT(tr.lpstrText); mir_free(tr.lpstrText); } return TRUE; diff --git a/src/mir_app/src/lpopts.cpp b/src/mir_app/src/lpopts.cpp index 735d4ab1bf..96f3f78553 100644 --- a/src/mir_app/src/lpopts.cpp +++ b/src/mir_app/src/lpopts.cpp @@ -126,12 +126,12 @@ INT_PTR CALLBACK DlgLangpackOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP char buf[512]; mir_strcpy(buf, "mailto:"); if (GetDlgItemTextA(hwndDlg, LOWORD(wParam), &buf[7], _countof(buf) - 7)) - CallService(MS_UTILS_OPENURL, 0, (LPARAM)buf); + Utils_OpenUrl(buf); } break; case IDC_MORELANG: - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)"http://wiki.miranda-ng.org/index.php?title=Langpacks/en#Download"); + Utils_OpenUrl("http://wiki.miranda-ng.org/index.php?title=Langpacks/en#Download"); break; case IDC_LANGUAGES: diff --git a/src/mir_app/src/openurl.cpp b/src/mir_app/src/openurl.cpp deleted file mode 100644 index 1ad7b508ad..0000000000 --- a/src/mir_app/src/openurl.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "stdafx.h" -#include - -struct TOpenUrlInfo -{ - TOpenUrlInfo(TCHAR *_url, int _bNew) : - szUrl(_url), - newWindow(_bNew) - {} - - ptrT szUrl; - int newWindow; -}; - -static void OpenURLThread(void *arg) -{ - TOpenUrlInfo *hUrlInfo = (TOpenUrlInfo*)arg; - - // wack a protocol on it - CMString tszUrl; - if ((isalpha(hUrlInfo->szUrl[0]) && hUrlInfo->szUrl[1] == ':') || hUrlInfo->szUrl[0] == '\\') - tszUrl.Format(_T("file:///%s"), hUrlInfo->szUrl); - else { - int i; - for (i = 0; _istalpha(hUrlInfo->szUrl[i]); i++); - if (hUrlInfo->szUrl[i] == ':') - tszUrl = hUrlInfo->szUrl; - else if (!_tcsnicmp(hUrlInfo->szUrl, _T("ftp."), 4)) - tszUrl.Format(_T("ftp://%s"), hUrlInfo->szUrl); - else - tszUrl.Format(_T("http://%s"), hUrlInfo->szUrl); - } - - // check user defined browser for opening urls - ptrT tszBrowser(db_get_tsa(NULL, "Miranda", "OpenUrlBrowser")); - if (tszBrowser) - ShellExecute(NULL, _T("open"), tszBrowser, tszUrl, NULL, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT); - else - ShellExecute(NULL, _T("open"), tszUrl, NULL, NULL, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT); - - delete hUrlInfo; -} - -static INT_PTR OpenURL(WPARAM wParam, LPARAM lParam) -{ - if (lParam == 0) - return 1; - - TOpenUrlInfo *hUrlInfo = new TOpenUrlInfo((wParam & OUF_UNICODE) ? mir_wstrdup((WCHAR*)lParam) : mir_a2t((char*)lParam), wParam & OUF_NEWWINDOW); - forkthread(OpenURLThread, 0, hUrlInfo); - return 0; -} - -int InitOpenUrl(void) -{ - CreateServiceFunction(MS_UTILS_OPENURL, OpenURL); - return 0; -} diff --git a/src/mir_app/src/pluginopts.cpp b/src/mir_app/src/pluginopts.cpp index 278050a96d..24ef35348b 100644 --- a/src/mir_app/src/pluginopts.cpp +++ b/src/mir_app/src/pluginopts.cpp @@ -522,7 +522,7 @@ INT_PTR CALLBACK DlgPluginOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar if (HIWORD(wParam) == STN_CLICKED) { switch (LOWORD(wParam)) { case IDC_GETMOREPLUGINS: - CallService(MS_UTILS_OPENURL, 0, (LPARAM) "http://miranda-ng.org/downloads/"); + Utils_OpenUrl("http://miranda-ng.org/downloads/"); break; case IDC_PLUGINEMAIL: @@ -531,7 +531,7 @@ INT_PTR CALLBACK DlgPluginOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar char *p = &buf[7]; mir_strcpy(buf, "mailto:"); if (GetDlgItemTextA(hwndDlg, LOWORD(wParam), p, _countof(buf) - 7)) - CallService(MS_UTILS_OPENURL, 0, (LPARAM)(LOWORD(wParam) == IDC_PLUGINEMAIL ? buf : p)); + Utils_OpenUrl(LOWORD(wParam) == IDC_PLUGINEMAIL ? buf : p); break; } } diff --git a/src/mir_app/src/proto_opts.cpp b/src/mir_app/src/proto_opts.cpp index ce4c986679..0c5ae404f3 100644 --- a/src/mir_app/src/proto_opts.cpp +++ b/src/mir_app/src/proto_opts.cpp @@ -913,7 +913,7 @@ INT_PTR CALLBACK AccMgrDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM break; case IDC_LNK_ADDONS: - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)"http://miranda-ng.org/"); + Utils_OpenUrl("http://miranda-ng.org/"); break; case IDOK: diff --git a/src/mir_app/src/skin2opts.cpp b/src/mir_app/src/skin2opts.cpp index 194a2a7696..882eade304 100644 --- a/src/mir_app/src/skin2opts.cpp +++ b/src/mir_app/src/skin2opts.cpp @@ -202,7 +202,7 @@ void UndoSubItemChanges(HWND htv, HTREEITEM hItem, int cmd) static void OpenIconsPage() { - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)"http://miranda-ng.org/"); + Utils_OpenUrl("http://miranda-ng.org/"); } static int OpenPopupMenu(HWND hwndDlg) diff --git a/src/mir_app/src/sounds.cpp b/src/mir_app/src/sounds.cpp index 0fb366e812..6722e17c83 100644 --- a/src/mir_app/src/sounds.cpp +++ b/src/mir_app/src/sounds.cpp @@ -335,7 +335,7 @@ INT_PTR CALLBACK DlgProcSoundOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM SetDlgItemText(hwndDlg, IDC_LOCATION, strFull); } if (LOWORD(wParam) == IDC_GETMORE) { - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)"http://miranda-ng.org/addons/category/14"); + Utils_OpenUrl("http://miranda-ng.org/addons/category/14"); break; } if (LOWORD(wParam) == IDC_LOCATION) diff --git a/src/mir_app/src/utils.cpp b/src/mir_app/src/utils.cpp index 64b204da68..8efafe2673 100644 --- a/src/mir_app/src/utils.cpp +++ b/src/mir_app/src/utils.cpp @@ -28,9 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. INT_PTR ResizeDialog(WPARAM wParam, LPARAM lParam); -int InitOpenUrl(void); int InitPathUtils(void); -void InitXmlApi(void); int InitCrypt(void); void UninitCrypt(void); @@ -352,7 +350,6 @@ int LoadUtilsModule(void) CreateServiceFunction(MS_UTILS_ENTERSTRING, svcEnterString); CreateServiceFunction(MS_SYSTEM_RESTART, RestartMiranda); - InitOpenUrl(); InitPathUtils(); InitCrypt(); return 0; diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index d12bbf2897..fed657fd09 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -971,3 +971,5 @@ TimeZone_ToStringW @1128 TimeZone_UtcToLocal @1129 Utils_ResizeDialog @1130 Utils_GetRandom @1131 +Utils_OpenUrl @1132 +Utils_OpenUrlW @1133 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 3cd65aa139..af4a9a45d7 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -971,3 +971,5 @@ TimeZone_ToStringW @1128 TimeZone_UtcToLocal @1129 Utils_ResizeDialog @1130 Utils_GetRandom @1131 +Utils_OpenUrl @1132 +Utils_OpenUrlW @1133 diff --git a/src/mir_core/src/openurl.cpp b/src/mir_core/src/openurl.cpp new file mode 100644 index 0000000000..00b2813322 --- /dev/null +++ b/src/mir_core/src/openurl.cpp @@ -0,0 +1,78 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" +#include + +struct TOpenUrlInfo +{ + TOpenUrlInfo(TCHAR *_url, int _bNew) : + szUrl(_url), + newWindow(_bNew) + {} + + ptrT szUrl; + int newWindow; +}; + +static void OpenURLThread(void *arg) +{ + TOpenUrlInfo *hUrlInfo = (TOpenUrlInfo*)arg; + + // wack a protocol on it + CMString tszUrl; + if ((isalpha(hUrlInfo->szUrl[0]) && hUrlInfo->szUrl[1] == ':') || hUrlInfo->szUrl[0] == '\\') + tszUrl.Format(_T("file:///%s"), hUrlInfo->szUrl); + else { + int i; + for (i = 0; _istalpha(hUrlInfo->szUrl[i]); i++); + if (hUrlInfo->szUrl[i] == ':') + tszUrl = hUrlInfo->szUrl; + else if (!_tcsnicmp(hUrlInfo->szUrl, _T("ftp."), 4)) + tszUrl.Format(_T("ftp://%s"), hUrlInfo->szUrl); + else + tszUrl.Format(_T("http://%s"), hUrlInfo->szUrl); + } + + // check user defined browser for opening urls + ptrT tszBrowser(db_get_tsa(NULL, "Miranda", "OpenUrlBrowser")); + if (tszBrowser) + ShellExecute(NULL, _T("open"), tszBrowser, tszUrl, NULL, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT); + else + ShellExecute(NULL, _T("open"), tszUrl, NULL, NULL, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT); + + delete hUrlInfo; +} + +MIR_CORE_DLL(void) Utils_OpenUrl(const char *pszUrl, bool bOpenInNewWindow) +{ + if (pszUrl) + forkthread(OpenURLThread, 0, new TOpenUrlInfo(mir_a2t(pszUrl), bOpenInNewWindow)); +} + +MIR_CORE_DLL(void) Utils_OpenUrlW(const wchar_t *pszUrl, bool bOpenInNewWindow) +{ + if (pszUrl) + forkthread(OpenURLThread, 0, new TOpenUrlInfo(mir_wstrdup(pszUrl), bOpenInNewWindow)); +} -- cgit v1.2.3