From cbe3cb21f5bca61a03bbd4ae811ee906e09b3f4f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 13 Jun 2015 16:55:17 +0000 Subject: - miranda32.exe now does nothing bug extends PATH to %miranda_root%\libs and loads mir_app.dll; - everything that was in miranda32.exe (including resources) moved to mir_app.dll; - exports from mir_app.dll now available for using directly, without perversions; - src/stdplug.h deleted; git-svn-id: http://svn.miranda-ng.org/main/trunk@14143 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/utils/colourpicker.cpp | 108 ------- src/modules/utils/enterstring.cpp | 274 ------------------ src/modules/utils/hyperlink.cpp | 272 ------------------ src/modules/utils/imgconv.cpp | 144 ---------- src/modules/utils/openurl.cpp | 82 ------ src/modules/utils/path.cpp | 458 ------------------------------ src/modules/utils/resizer.cpp | 158 ----------- src/modules/utils/timeutils.cpp | 103 ------- src/modules/utils/timezones.cpp | 557 ------------------------------------- src/modules/utils/utils.cpp | 496 --------------------------------- src/modules/utils/windowlist.cpp | 111 -------- 11 files changed, 2763 deletions(-) delete mode 100644 src/modules/utils/colourpicker.cpp delete mode 100644 src/modules/utils/enterstring.cpp delete mode 100644 src/modules/utils/hyperlink.cpp delete mode 100644 src/modules/utils/imgconv.cpp delete mode 100644 src/modules/utils/openurl.cpp delete mode 100644 src/modules/utils/path.cpp delete mode 100644 src/modules/utils/resizer.cpp delete mode 100644 src/modules/utils/timeutils.cpp delete mode 100644 src/modules/utils/timezones.cpp delete mode 100644 src/modules/utils/utils.cpp delete mode 100644 src/modules/utils/windowlist.cpp (limited to 'src/modules/utils') diff --git a/src/modules/utils/colourpicker.cpp b/src/modules/utils/colourpicker.cpp deleted file mode 100644 index e93a1c90b7..0000000000 --- a/src/modules/utils/colourpicker.cpp +++ /dev/null @@ -1,108 +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 "..\..\core\commonheaders.h" - -static LRESULT CALLBACK ColourPickerWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch(message) { - case WM_CREATE: - SetWindowLongPtr(hwnd, 0, 0); - SetWindowLongPtr(hwnd, sizeof(COLORREF), 0); - break; - case CPM_SETDEFAULTCOLOUR: - SetWindowLongPtr(hwnd, sizeof(COLORREF), lParam); - break; - case CPM_GETDEFAULTCOLOUR: - return GetWindowLongPtr(hwnd, sizeof(COLORREF)); - case CPM_SETCOLOUR: - SetWindowLongPtr(hwnd, 0, lParam); - InvalidateRect(hwnd, NULL, FALSE); - break; - case CPM_GETCOLOUR: - return GetWindowLongPtr(hwnd, 0); - case WM_LBUTTONUP: - { - CHOOSECOLOR cc = {0}; - COLORREF custColours[16] = {0}; - custColours[0] = GetWindowLongPtr(hwnd, sizeof(COLORREF)); - cc.lStructSize = sizeof(CHOOSECOLOR); - cc.hwndOwner = hwnd; - cc.hInstance = (HWND)hInst; - cc.rgbResult = GetWindowLongPtr(hwnd, 0); - cc.lpCustColors = custColours; - cc.Flags = CC_ANYCOLOR|CC_FULLOPEN|CC_RGBINIT; - if (ChooseColor(&cc)) { - SetWindowLongPtr(hwnd, 0, cc.rgbResult); - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hwnd), CPN_COLOURCHANGED), (LPARAM)hwnd); - InvalidateRect(hwnd, NULL, FALSE); - } - break; - } - case WM_ENABLE: - InvalidateRect(hwnd, NULL, FALSE); - break; - case WM_NCPAINT: - case WM_PAINT: - { - PAINTSTRUCT ps; - HDC hdc1; - RECT rc; - HBRUSH hBrush; - - hdc1 = BeginPaint(hwnd, &ps); - GetClientRect(hwnd, &rc); - DrawEdge(hdc1, &rc, EDGE_ETCHED, BF_RECT); - InflateRect(&rc, -2, -2); - if (IsWindowEnabled(hwnd)) - hBrush = CreateSolidBrush(GetWindowLongPtr(hwnd, 0)); - else - hBrush = CreateHatchBrush(HS_BDIAGONAL, GetSysColor(COLOR_GRAYTEXT)); - SetBkColor(hdc1, GetSysColor(COLOR_BTNFACE)); - FillRect(hdc1, &rc, hBrush); - DeleteObject(hBrush); - EndPaint(hwnd, &ps); - break; - } - } - return DefWindowProc(hwnd, message, wParam, lParam); -} - -int InitColourPicker(void) -{ - WNDCLASS wcl; - - wcl.lpfnWndProc = ColourPickerWndProc; - wcl.cbClsExtra = 0; - wcl.cbWndExtra = sizeof(COLORREF)*2; - wcl.hInstance = hInst; - wcl.hCursor = NULL; - wcl.lpszClassName = _T(WNDCLASS_COLOURPICKER); - wcl.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); - wcl.hIcon = NULL; - wcl.lpszMenuName = NULL; - wcl.style = CS_HREDRAW|CS_VREDRAW|CS_GLOBALCLASS; - RegisterClass(&wcl); - return 0; -} diff --git a/src/modules/utils/enterstring.cpp b/src/modules/utils/enterstring.cpp deleted file mode 100644 index c7fd4b4001..0000000000 --- a/src/modules/utils/enterstring.cpp +++ /dev/null @@ -1,274 +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 "..\..\core\commonheaders.h" - -struct EnterStringFormParam : public ENTER_STRING -{ - int idcControl; - int height; -}; - -static int UIEmulateBtnClick(HWND hwndDlg, UINT idcButton) -{ - if (IsWindowEnabled(GetDlgItem(hwndDlg, idcButton))) - PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(idcButton, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, idcButton)); - return 0; -} - -static int sttEnterStringResizer(HWND, LPARAM, UTILRESIZECONTROL *urc) -{ - switch (urc->wId) { - case IDC_TXT_MULTILINE: - case IDC_TXT_COMBO: - case IDC_TXT_RICHEDIT: - return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT; - - case IDOK: - case IDCANCEL: - return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM; - } - return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; -} - -static void ComboLoadRecentStrings(HWND hwndDlg, EnterStringFormParam *pForm) -{ - for (int i = 0; i < pForm->recentCount; i++) { - char setting[MAXMODULELABELLENGTH]; - mir_snprintf(setting, "%s%d", pForm->szDataPrefix, i); - ptrT tszRecent(db_get_tsa(NULL, pForm->szModuleName, setting)); - if (tszRecent != NULL) - SendDlgItemMessage(hwndDlg, pForm->idcControl, CB_ADDSTRING, 0, tszRecent); - } - - if (!SendDlgItemMessage(hwndDlg, pForm->idcControl, CB_GETCOUNT, 0, 0)) - SendDlgItemMessage(hwndDlg, pForm->idcControl, CB_ADDSTRING, 0, (LPARAM)_T("")); -} - -static void ComboAddRecentString(HWND hwndDlg, EnterStringFormParam *pForm) -{ - TCHAR *string = pForm->ptszResult; - if (!string || !*string) - return; - - if (SendDlgItemMessage(hwndDlg, pForm->idcControl, CB_FINDSTRING, (WPARAM)-1, (LPARAM)string) != CB_ERR) - return; - - int id; - SendDlgItemMessage(hwndDlg, pForm->idcControl, CB_ADDSTRING, 0, (LPARAM)string); - if ((id = SendDlgItemMessage(hwndDlg, pForm->idcControl, CB_FINDSTRING, (WPARAM)-1, (LPARAM)_T(""))) != CB_ERR) - SendDlgItemMessage(hwndDlg, pForm->idcControl, CB_DELETESTRING, id, 0); - - id = db_get_b(NULL, pForm->szModuleName, pForm->szDataPrefix, 0); - char setting[MAXMODULELABELLENGTH]; - mir_snprintf(setting, "%s%d", pForm->szDataPrefix, id); - db_set_ts(NULL, pForm->szModuleName, setting, string); - db_set_b(NULL, pForm->szModuleName, pForm->szDataPrefix, (id + 1) % pForm->idcControl); -} - -static INT_PTR CALLBACK sttEnterStringDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - EnterStringFormParam *params = (EnterStringFormParam *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadSkinnedIconBig(SKINICON_OTHER_RENAME)); - SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadSkinnedIcon(SKINICON_OTHER_RENAME)); - params = (EnterStringFormParam *)lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)params); - SetWindowText(hwndDlg, params->caption); - { - RECT rc; GetWindowRect(hwndDlg, &rc); - switch (params->type) { - case ESF_PASSWORD: - params->idcControl = IDC_TXT_PASSWORD; - params->height = rc.bottom - rc.top; - break; - - case ESF_MULTILINE: - params->idcControl = IDC_TXT_MULTILINE; - params->height = 0; - rc.bottom += (rc.bottom - rc.top) * 2; - SetWindowPos(hwndDlg, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOREPOSITION); - break; - - case ESF_COMBO: - params->idcControl = IDC_TXT_COMBO; - params->height = rc.bottom - rc.top; - if (params->szDataPrefix && params->recentCount) - ComboLoadRecentStrings(hwndDlg, params); - break; - - case ESF_RICHEDIT: - params->idcControl = IDC_TXT_RICHEDIT; - SendDlgItemMessage(hwndDlg, IDC_TXT_RICHEDIT, EM_AUTOURLDETECT, TRUE, 0); - SendDlgItemMessage(hwndDlg, IDC_TXT_RICHEDIT, EM_SETEVENTMASK, 0, ENM_LINK); - params->height = 0; - rc.bottom += (rc.bottom - rc.top) * 2; - SetWindowPos(hwndDlg, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOREPOSITION); - break; - } - } - ShowWindow(GetDlgItem(hwndDlg, params->idcControl), SW_SHOW); - if (params->ptszInitVal) - SetDlgItemText(hwndDlg, params->idcControl, params->ptszInitVal); - - if (params->szDataPrefix) - Utils_RestoreWindowPosition(hwndDlg, NULL, params->szModuleName, params->szDataPrefix); - - SetTimer(hwndDlg, 1000, 50, NULL); - - if (params->timeout > 0) { - SetTimer(hwndDlg, 1001, 1000, NULL); - TCHAR buf[128]; - mir_sntprintf(buf, TranslateT("OK (%d)"), params->timeout); - SetDlgItemText(hwndDlg, IDOK, buf); - } - - return TRUE; - - case WM_DESTROY: - Window_FreeIcon_IcoLib(hwndDlg); - break; - - case WM_TIMER: - switch (wParam) { - case 1000: - KillTimer(hwndDlg, 1000); - EnableWindow(GetParent(hwndDlg), TRUE); - break; - - case 1001: - TCHAR buf[128]; - mir_sntprintf(buf, TranslateT("OK (%d)"), --params->timeout); - SetDlgItemText(hwndDlg, IDOK, buf); - - if (params->timeout < 0) { - KillTimer(hwndDlg, 1001); - UIEmulateBtnClick(hwndDlg, IDOK); - } - } - return TRUE; - - case WM_SIZE: - { - UTILRESIZEDIALOG urd = { 0 }; - urd.cbSize = sizeof(urd); - urd.hInstance = hInst; - urd.hwndDlg = hwndDlg; - urd.lpTemplate = MAKEINTRESOURCEA(IDD_ENTER_STRING); - urd.pfnResizer = sttEnterStringResizer; - CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); - } - break; - - case WM_GETMINMAXINFO: - { - LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam; - if (params && params->height) - lpmmi->ptMaxSize.y = lpmmi->ptMaxTrackSize.y = params->height; - } - break; - - case WM_NOTIFY: - { - ENLINK *param = (ENLINK *)lParam; - if (param->nmhdr.idFrom != IDC_TXT_RICHEDIT) break; - if (param->nmhdr.code != EN_LINK) break; - if (param->msg != WM_LBUTTONUP) break; - - CHARRANGE sel; - SendMessage(param->nmhdr.hwndFrom, EM_EXGETSEL, 0, (LPARAM)& sel); - if (sel.cpMin != sel.cpMax) break; // allow link selection - - 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); - - char *tmp = mir_t2a(tr.lpstrText); - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)tmp); - mir_free(tmp); - mir_free(tr.lpstrText); - } - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_TXT_MULTILINE: - case IDC_TXT_RICHEDIT: - if ((HIWORD(wParam) != EN_SETFOCUS) && (HIWORD(wParam) != EN_KILLFOCUS)) { - SetDlgItemText(hwndDlg, IDOK, TranslateT("OK")); - KillTimer(hwndDlg, 1001); - } - break; - - case IDC_TXT_COMBO: - if ((HIWORD(wParam) != CBN_SETFOCUS) && (HIWORD(wParam) != CBN_KILLFOCUS)) { - SetDlgItemText(hwndDlg, IDOK, TranslateT("OK")); - KillTimer(hwndDlg, 1001); - } - break; - - case IDCANCEL: - if (params->szDataPrefix) - Utils_SaveWindowPosition(hwndDlg, NULL, params->szModuleName, params->szDataPrefix); - - EndDialog(hwndDlg, 0); - break; - - case IDOK: - HWND hWnd = GetDlgItem(hwndDlg, params->idcControl); - int len = GetWindowTextLength(hWnd)+1; - params->ptszResult = (LPTSTR)mir_alloc(sizeof(TCHAR)*len); - GetWindowText(hWnd, params->ptszResult, len); - - if ((params->type == ESF_COMBO) && params->szDataPrefix && params->recentCount) - ComboAddRecentString(hwndDlg, params); - if (params->szDataPrefix) - Utils_SaveWindowPosition(hwndDlg, NULL, params->szModuleName, params->szDataPrefix); - - EndDialog(hwndDlg, 1); - break; - } - } - - return FALSE; -} - -INT_PTR __cdecl svcEnterString(WPARAM, LPARAM lParam) -{ - ENTER_STRING *pForm = (ENTER_STRING*)lParam; - if (pForm == NULL || pForm->cbSize != sizeof(ENTER_STRING)) - return FALSE; - - EnterStringFormParam param; - memcpy(¶m, pForm, sizeof(ENTER_STRING)); - if (!DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ENTER_STRING), GetForegroundWindow(), sttEnterStringDlgProc, LPARAM(¶m))) - return FALSE; - - pForm->ptszResult = param.ptszResult; - return TRUE; -} diff --git a/src/modules/utils/hyperlink.cpp b/src/modules/utils/hyperlink.cpp deleted file mode 100644 index 12e2b2790e..0000000000 --- a/src/modules/utils/hyperlink.cpp +++ /dev/null @@ -1,272 +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 "..\..\core\commonheaders.h" - -struct HyperlinkWndData { - HFONT hEnableFont, hDisableFont; - RECT rcText; - COLORREF enableColor, disableColor, focusColor; - BYTE flags; /* see HLKF_* */ -}; - -/* flags */ -#define HLKF_HASENABLECOLOR 0x1 /* dat->enableColor is not system default */ -#define HLKF_HASDISABLECOLOR 0x2 /* dat->disableColor is not system default */ - -/* internal messages */ -#define HLK_MEASURETEXT (WM_USER+1) -#define HLK_INVALIDATE (WM_USER+2) - -static LRESULT CALLBACK HyperlinkWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - struct HyperlinkWndData *dat = (struct HyperlinkWndData*)GetWindowLongPtr(hwnd, 0); - switch(msg) { - case WM_NCCREATE: - dat = (struct HyperlinkWndData*)mir_calloc(sizeof(struct HyperlinkWndData)); - if (dat == NULL) return FALSE; /* fail creation */ - SetWindowLongPtr(hwnd, 0, (LONG_PTR)dat); /* always succeeds */ - /* fall thru */ - case WM_SYSCOLORCHANGE: - if (!(dat->flags&HLKF_HASENABLECOLOR)) { - if (GetSysColorBrush(COLOR_HOTLIGHT) == NULL) dat->enableColor = RGB(0, 0, 255); - else dat->enableColor = GetSysColor(COLOR_HOTLIGHT); - dat->focusColor = RGB(GetRValue(dat->enableColor) / 2, GetGValue(dat->enableColor) / 2, GetBValue(dat->enableColor) / 2); - } - if (!(dat->flags&HLKF_HASDISABLECOLOR)) - dat->disableColor = GetSysColor(COLOR_GRAYTEXT); - break; - - case WM_SETFOCUS: - case WM_KILLFOCUS: - RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE); - break; - case WM_MOUSEACTIVATE: - SetFocus(hwnd); - return MA_ACTIVATE; - case WM_GETDLGCODE: - { - if (lParam) - { - MSG *msg = (MSG *) lParam; - if (msg->message == WM_KEYDOWN) - { - if (msg->wParam == VK_TAB) - return 0; - if (msg->wParam == VK_ESCAPE) - return 0; - } else - if (msg->message == WM_CHAR) - { - if (msg->wParam == '\t') - return 0; - if (msg->wParam == 27) - return 0; - } - } - return DLGC_WANTMESSAGE; - } - - case WM_KEYDOWN: - { - switch (wParam) - { - case VK_SPACE: - case VK_RETURN: - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hwnd), STN_CLICKED), (LPARAM)hwnd); - break; - } - return 0; - } - - case WM_LBUTTONDOWN: - { POINT pt; - POINTSTOPOINT(pt, MAKEPOINTS(lParam)); - if (!PtInRect(&dat->rcText, pt)) break; - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hwnd), STN_CLICKED), (LPARAM)hwnd); - return 0; - } - case WM_SETFONT: - { LOGFONT lf; - HFONT hFont; - if ((HFONT)wParam == NULL) { /* use default system color */ - dat->hEnableFont = dat->hDisableFont = NULL; - return 0; - } - if (GetObject((HFONT)wParam, sizeof(lf), &lf)) { - lf.lfUnderline = 1; - hFont = CreateFontIndirect(&lf); - if (hFont != NULL) { - dat->hEnableFont = hFont; - dat->hDisableFont = (HFONT)wParam; - if (LOWORD(lParam)) SendMessage(hwnd, HLK_INVALIDATE, 0, 0); - SendMessage(hwnd, HLK_MEASURETEXT, 0, 0); - } - } - return 0; - } - case WM_ERASEBKGND: - return TRUE; - case WM_ENABLE: - case HLK_INVALIDATE: - { RECT rcWnd; - POINT pt; - HWND hwndParent; - if (!GetWindowRect(hwnd, &rcWnd)) break; - pt.x = rcWnd.left; - pt.y = rcWnd.top; - hwndParent = GetParent(hwnd); - if (hwndParent == NULL) hwndParent = hwnd; - if (!ScreenToClient(hwndParent, &pt)) break; - rcWnd.right = pt.x+(rcWnd.right-rcWnd.left); - rcWnd.bottom = pt.y+(rcWnd.bottom-rcWnd.top); - rcWnd.left = pt.x; - rcWnd.top = pt.y; - InvalidateRect(hwndParent, &rcWnd, TRUE); - return 0; - } - case WM_GETFONT: - return (LRESULT)dat->hDisableFont; - case WM_CREATE: - case HLK_MEASURETEXT: - { TCHAR szText[256]; - if (!GetWindowText(hwnd, szText, SIZEOF(szText))) return 0; - lParam = (LPARAM)szText; - /* fall thru */ - case WM_SETTEXT: - { HFONT hPrevFont = NULL; - SIZE textSize; - RECT rc; - HDC hdc; - LONG style; - BOOL fMeasured = FALSE; - hdc = GetDC(hwnd); - if (hdc == NULL) return 0; /* text change failed */ - if (dat->hEnableFont != NULL) hPrevFont = (HFONT)SelectObject(hdc, dat->hEnableFont); - if (dat->hEnableFont == NULL || hPrevFont != NULL) /* select failed? */ - if (GetTextExtentPoint32(hdc, (TCHAR*)lParam, (int)mir_tstrlen((TCHAR*)lParam), &textSize)) - if (GetClientRect(hwnd, &rc)) { - dat->rcText.top = 0; - dat->rcText.bottom = dat->rcText.top+textSize.cy; - style = GetWindowLongPtr(hwnd, GWL_STYLE); - if (style&SS_CENTER) dat->rcText.left = (rc.right-textSize.cx)/2; - else if (style&SS_RIGHT) dat->rcText.left = rc.right-textSize.cx; - else dat->rcText.left = 0; - dat->rcText.right = dat->rcText.left+textSize.cx; - fMeasured = TRUE; - } - if (dat->hEnableFont != NULL && hPrevFont != NULL) SelectObject(hdc, hPrevFont); - ReleaseDC(hwnd, hdc); - if (!fMeasured) return 0; /* text change failed */ - SendMessage(hwnd, HLK_INVALIDATE, 0, 0); - break; - }} - case WM_SETCURSOR: - { POINT pt; - HCURSOR hCursor; - if (!GetCursorPos(&pt)) return FALSE; - if (!ScreenToClient(hwnd, &pt)) return FALSE; - if (PtInRect(&dat->rcText, pt)) { - hCursor = (HCURSOR)GetClassLongPtr(hwnd, GCLP_HCURSOR); - if (hCursor == NULL) hCursor = LoadCursor(NULL, IDC_HAND); /* Win2000+ */ - } - else hCursor = LoadCursor(NULL, IDC_ARROW); - SetCursor(hCursor); - return TRUE; - } - case HLK_SETENABLECOLOUR: - { COLORREF prevColor = dat->enableColor; - dat->enableColor = (COLORREF)wParam; - dat->focusColor = RGB(GetRValue(dat->enableColor) / 2, GetGValue(dat->enableColor) / 2, GetBValue(dat->enableColor) / 2); - dat->flags|=HLKF_HASENABLECOLOR; - return (LRESULT)prevColor; - } - case HLK_SETDISABLECOLOUR: - { COLORREF prevColor = dat->disableColor; - dat->disableColor = (COLORREF)wParam; - dat->flags|=HLKF_HASDISABLECOLOR; - return (LRESULT)prevColor; - } - case WM_NCPAINT: - return 0; - case WM_PAINT: - { HFONT hPrevFont; - RECT rc; - TCHAR szText[256]; - UINT alignFlag; - COLORREF textColor; - PAINTSTRUCT ps; - HDC hdc; - - hdc = BeginPaint(hwnd, &ps); - if (hdc != NULL) { - if (IsWindowEnabled(hwnd)) { - hPrevFont = (HFONT)SelectObject(hdc, dat->hEnableFont); - textColor = (GetFocus() == hwnd) ? dat->focusColor : dat->enableColor; - } else { - hPrevFont = (HFONT)SelectObject(hdc, dat->hDisableFont); - textColor = dat->disableColor; - } - if (GetClientRect(hwnd, &rc) && GetWindowText(hwnd, szText, SIZEOF(szText))) { - BOOL fSmoothing; - UINT fSmoothingType; - SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &fSmoothing, 0); - SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &fSmoothingType, 0); - if (fSmoothing && fSmoothingType == FE_FONTSMOOTHINGCLEARTYPE) - DrawThemeParentBackground(hwnd, hdc, &rc); - SetBkMode(hdc, TRANSPARENT); - SetTextColor(hdc, textColor); - alignFlag = (GetWindowLongPtr(hwnd, GWL_STYLE)&(SS_CENTER|SS_RIGHT|SS_LEFT)); - DrawText(hdc, szText, -1, &rc, alignFlag|DT_NOPREFIX|DT_SINGLELINE|DT_TOP); - } - if (hPrevFont != NULL) SelectObject(hdc, hPrevFont); - EndPaint(hwnd, &ps); - } - return 0; - } - case WM_NCDESTROY: - if (dat->hEnableFont != NULL) DeleteObject(dat->hEnableFont); - mir_free(dat); - break; - } - return DefWindowProc(hwnd, msg, wParam, lParam); -} - -int InitHyperlink(void) -{ - WNDCLASS wcl; - - wcl.lpfnWndProc = HyperlinkWndProc; - wcl.cbClsExtra = 0; - wcl.cbWndExtra = sizeof(struct HyperlinkWndData*); - wcl.hInstance = hInst; - wcl.hCursor = NULL; - wcl.lpszClassName = WNDCLASS_HYPERLINK; - wcl.hbrBackground = NULL; - wcl.hIcon = NULL; - wcl.lpszMenuName = NULL; - wcl.style = CS_HREDRAW|CS_VREDRAW|CS_GLOBALCLASS|CS_PARENTDC; - RegisterClass(&wcl); /* automatically unregistered on exit */ - return 0; -} diff --git a/src/modules/utils/imgconv.cpp b/src/modules/utils/imgconv.cpp deleted file mode 100644 index 8bbbb308cb..0000000000 --- a/src/modules/utils/imgconv.cpp +++ /dev/null @@ -1,144 +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 "..\..\core\commonheaders.h" - -typedef DWORD ARGB; - -void InitBitmapInfo(BITMAPINFO &bmi, const SIZE &size) -{ - memset(&bmi, 0, sizeof(BITMAPINFO)); - bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biCompression = BI_RGB; - bmi.bmiHeader.biBitCount = 32; - - bmi.bmiHeader.biWidth = size.cx; - bmi.bmiHeader.biHeight = size.cy; -} - -void ConvertToPARGB32(HDC hdc, ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow) -{ - BITMAPINFO bmi; - InitBitmapInfo(bmi, sizImage); - - void *pvBits = malloc(sizImage.cx * 4 * sizImage.cy); - if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight) { - ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth; - ARGB *pargbMask = (ARGB *)pvBits; - - for (ULONG y = bmi.bmiHeader.biHeight + 1; --y;) { - for (ULONG x = bmi.bmiHeader.biWidth + 1; --x;) { - if (*pargbMask++) { - // transparent pixel - *pargb++=0; - } - else { - // opaque pixel - *pargb++ |= 0xFF000000; - } - } - - pargb += cxDelta; - } - } - free(pvBits); -} - -bool HasAlpha(ARGB *pargb, SIZE& sizImage, int cxRow) -{ - ULONG cxDelta = cxRow - sizImage.cx; - for (ULONG y = sizImage.cy; y--;) { - for (ULONG x = sizImage.cx; x--;) { - if (*pargb++ & 0xFF000000) - return true; - } - pargb += cxDelta; - } - - return false; -} - -void ConvertBufferToPARGB32(HANDLE hPaintBuffer, HDC hdc, HICON hIcon, SIZE& sizIcon) -{ - RGBQUAD *prgbQuad; - int cxRow; - HRESULT hr = getBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow); - if (SUCCEEDED(hr)) { - ARGB *pargb = (ARGB *)prgbQuad; - if (!HasAlpha(pargb, sizIcon, cxRow)) { - ICONINFO info; - if (GetIconInfo(hIcon, &info)) { - if (info.hbmMask) - ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow); - - DeleteObject(info.hbmColor); - DeleteObject(info.hbmMask); - } - } - } -} - -HBITMAP ConvertIconToBitmap(HICON hicon, HIMAGELIST hIml, int iconId) -{ - SIZE sizIcon; - sizIcon.cx = GetSystemMetrics(SM_CXSMICON); - sizIcon.cy = GetSystemMetrics(SM_CYSMICON); - - RECT rcIcon = { 0, 0, sizIcon.cx, sizIcon.cy }; - - HDC hdc = CreateCompatibleDC(NULL); - - BITMAPINFO bmi; - InitBitmapInfo(bmi, sizIcon); - - HBITMAP hbmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0); - HBITMAP hbmpOld = (HBITMAP)SelectObject(hdc, hbmp); - - BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; - BP_PAINTPARAMS paintParams = {0}; - paintParams.cbSize = sizeof(paintParams); - paintParams.dwFlags = BPPF_ERASE; - paintParams.pBlendFunction = &bfAlpha; - - HDC hdcBuffer; - HANDLE hPaintBuffer = beginBufferedPaint(hdc, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer); - if (hPaintBuffer) { - if (hIml) - ImageList_Draw(hIml, iconId, hdc, 0, 0, ILD_TRANSPARENT); - else - DrawIconEx(hdcBuffer, 0, 0, hicon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL); - - // If icon did not have an alpha channel we need to convert buffer to PARGB - ConvertBufferToPARGB32(hPaintBuffer, hdc, hicon, sizIcon); - - // This will write the buffer contents to the destination bitmap - endBufferedPaint(hPaintBuffer, TRUE); - } - - SelectObject(hdc, hbmpOld); - DeleteDC(hdc); - - return hbmp; -} diff --git a/src/modules/utils/openurl.cpp b/src/modules/utils/openurl.cpp deleted file mode 100644 index afbfa4681b..0000000000 --- a/src/modules/utils/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 "..\..\core\commonheaders.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/modules/utils/path.cpp b/src/modules/utils/path.cpp deleted file mode 100644 index a7ac429900..0000000000 --- a/src/modules/utils/path.cpp +++ /dev/null @@ -1,458 +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 "..\..\core\commonheaders.h" -#include "../database/profilemanager.h" - -#include "..\..\..\plugins\ExternalAPI\m_folders.h" - -extern TCHAR g_profileDir[MAX_PATH], g_shortProfileName[MAX_PATH]; - -static HANDLE hAvatarFolder; -static TCHAR tszAvatarRoot[MAX_PATH]; - -static INT_PTR pathToRelative(WPARAM wParam, LPARAM lParam) -{ - return PathToRelative((char*)wParam, (char*)lParam); -} - -static INT_PTR pathToAbsolute(WPARAM wParam, LPARAM lParam) -{ - return PathToAbsolute((char*)wParam, (char*)lParam); -} - -static INT_PTR createDirTree(WPARAM, LPARAM lParam) -{ - if (lParam == 0) - return 1; - - return CreateDirectoryTree((char*)lParam); -} - -static INT_PTR pathToRelativeW(WPARAM wParam, LPARAM lParam) -{ - return PathToRelativeW((WCHAR*)wParam, (WCHAR*)lParam ); -} - -static INT_PTR pathToAbsoluteW(WPARAM wParam, LPARAM lParam) -{ - return PathToAbsoluteW((WCHAR*)wParam, (WCHAR*)lParam, NULL); -} - -static INT_PTR createDirTreeW(WPARAM, LPARAM lParam) -{ - if (lParam == 0) - return 1; - - return CreateDirectoryTreeW((WCHAR*)lParam); -} - -TCHAR *GetContactID(MCONTACT hContact) -{ - TCHAR *theValue = {0}; - char *szProto = GetContactProto(hContact); - if (db_get_b(hContact, szProto, "ChatRoom", 0) == 1) { - DBVARIANT dbv; - if (!db_get_ts(hContact, szProto, "ChatRoomID", &dbv)) { - theValue = (TCHAR *)mir_tstrdup(dbv.ptszVal); - db_free(&dbv); - return theValue; - } - } - else { - CONTACTINFO ci = {0}; - ci.cbSize = sizeof(ci); - ci.hContact = hContact; - ci.szProto = szProto; - ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { - switch (ci.type) { - case CNFT_ASCIIZ: - return (TCHAR *)ci.pszVal; - break; - case CNFT_DWORD: - return _itot(ci.dVal, (TCHAR *)mir_alloc(sizeof(TCHAR)*32), 10); - break; - } - } - } - return NULL; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Variables parser - -#define XSTR(target, s) _xstrselect(target, s, _T(s)) - -static __forceinline int _xcscmp(const char *s1, const char *s2) { return strcmp(s1, s2); } -static __forceinline int _xcsncmp(const char *s1, const char *s2, size_t n) { return strncmp(s1, s2, n); } -static __forceinline size_t _xcslen(const char *s1) { return strlen(s1); } -static __forceinline char *_xcscpy(char *s1, const char *s2) { return strcpy(s1, s2); } -static __forceinline char *_xcsncpy(char *s1, const char *s2, size_t n) { return strncpy(s1, s2, n); } -static __forceinline char *_xstrselect(char *, char *s1, TCHAR *s2) { return s1; } -static __forceinline char *_itox(char *, int a) { return itoa(a, (char *)mir_alloc(sizeof(char)*20), 10); } -static __forceinline char *mir_a2x(char *, char *s) { return mir_strdup(s); } - -static __forceinline char *GetContactNickX(char *, MCONTACT hContact) -{ - return mir_strdup((char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, 0)); -} - -static __forceinline char *GetContactIDX(char *, MCONTACT hContact) -{ - TCHAR *id = GetContactID(hContact); - char* res = mir_t2a(id); - mir_free(id); - return res; -} - -static __forceinline char *GetEnvironmentVariableX(char *variable) -{ - char result[512]; - if (GetEnvironmentVariableA(variable, result, SIZEOF(result))) - return mir_strdup(result); - return NULL; -} - -static __forceinline char *GetProfileDirX(char*) -{ - return mir_t2a(g_profileDir); -} - -static __forceinline char *SHGetSpecialFolderPathX(int iCSIDL, char* var) -{ - char result[512]; - if (SHGetSpecialFolderPathA(NULL, result, iCSIDL, FALSE)) - return mir_strdup(result); - return NULL; -} - -static __forceinline char *GetModulePathX(char *, HMODULE hModule) -{ - char result[MAX_PATH]; - GetModuleFileNameA(hModule, result, sizeof(result)); - char* str = strrchr(result, '\\'); - if (str) *str = 0; - return mir_strdup(result); -} - -static __forceinline char *GetUserNameX(char *) -{ - char result[128]; - DWORD size = SIZEOF(result); - if (GetUserNameA(result, &size)) - return mir_strdup(result); - return NULL; -} - -static __forceinline char *GetProfileNameX(char *) -{ - return mir_t2a(g_shortProfileName); -} - -static __forceinline char *GetPathVarX(char *, int code) -{ - TCHAR szFullPath[MAX_PATH]; - - switch(code) { - case 1: - if (hAvatarFolder != NULL) - _tcsncpy_s(szFullPath, tszAvatarRoot, _TRUNCATE); - else - mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s\\AvatarCache"), g_profileDir, g_shortProfileName); - break; - case 2: - mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s\\Logs"), g_profileDir, g_shortProfileName); - break; - case 3: - mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s"), g_profileDir, g_shortProfileName); - break; - } - return makeFileName(szFullPath); -} - -static __forceinline int _xcscmp(const TCHAR *s1, const TCHAR *s2) { return _tcscmp(s1, s2); } -static __forceinline int _xcsncmp(const TCHAR *s1, const TCHAR *s2, size_t n) { return _tcsncmp(s1, s2, n); } -static __forceinline size_t _xcslen(const TCHAR *s1) { return _tcslen(s1); } -static __forceinline TCHAR *_xcscpy(TCHAR *s1, const TCHAR *s2) { return _tcscpy(s1, s2); } -static __forceinline TCHAR *_xcsncpy(TCHAR *s1, const TCHAR *s2, size_t n) { return _tcsncpy(s1, s2, n); } -static __forceinline TCHAR *_xstrselect(TCHAR *, char *s1, TCHAR *s2) { return s2; } -static __forceinline TCHAR *_itox(TCHAR *, int a) { return _itot(a, (TCHAR *)mir_alloc(sizeof(TCHAR)*20), 10); } -static __forceinline TCHAR *mir_a2x(TCHAR *, char *s) { return mir_a2t(s); } - -static __forceinline TCHAR *GetContactNickX(TCHAR *, MCONTACT hContact) -{ - return mir_tstrdup((TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR)); -} - -static __forceinline TCHAR *GetContactIDX(TCHAR *, MCONTACT hContact) -{ - return GetContactID(hContact); -} - -static __forceinline TCHAR *GetEnvironmentVariableX(TCHAR *variable) -{ - TCHAR result[512]; - if (GetEnvironmentVariable(variable, result, SIZEOF(result))) - return mir_tstrdup(result); - return NULL; -} - -static __forceinline TCHAR *SHGetSpecialFolderPathX(int iCSIDL, TCHAR* var) -{ - TCHAR result[512]; - if (SHGetSpecialFolderPath(NULL, result, iCSIDL, FALSE)) - return mir_tstrdup(result); - return NULL; -} - -static __forceinline TCHAR *GetProfileDirX(TCHAR*) -{ - return mir_tstrdup(g_profileDir); -} - -static __forceinline TCHAR *GetModulePathX(TCHAR *, HMODULE hModule) -{ - TCHAR result[MAX_PATH]; - GetModuleFileName(hModule, result, SIZEOF(result)); - TCHAR* str = _tcsrchr(result, '\\'); - if (str) *str = 0; - return mir_tstrdup(result); -} - -static __forceinline TCHAR *GetUserNameX(TCHAR *) -{ - TCHAR result[128]; - DWORD size = SIZEOF(result); - if (GetUserName(result, &size)) - return mir_tstrdup(result); - return NULL; -} - -static __forceinline TCHAR *GetProfileNameX(TCHAR *) -{ - return mir_tstrdup(g_shortProfileName); -} - -static __forceinline TCHAR *GetPathVarX(TCHAR *, int code) -{ - TCHAR szFullPath[MAX_PATH]; - - switch(code) { - case 1: - if (hAvatarFolder != NULL) - _tcsncpy_s(szFullPath, tszAvatarRoot, _TRUNCATE); - else - mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s\\AvatarCache"), g_profileDir, g_shortProfileName); - break; - case 2: - mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s\\Logs"), g_profileDir, g_shortProfileName); - break; - case 3: - mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s"), g_profileDir, g_shortProfileName); - break; - } - return mir_tstrdup(szFullPath); -} - -template -XCHAR *GetInternalVariable(XCHAR *key, size_t keyLength, MCONTACT hContact) -{ - XCHAR *theValue = NULL; - XCHAR *theKey = (XCHAR *)_alloca(sizeof(XCHAR) * (keyLength + 1)); - _xcsncpy(theKey, key, keyLength); - theKey[keyLength] = 0; - - if (hContact) { - if (!_xcscmp(theKey, XSTR(key, "nick"))) - theValue = GetContactNickX(key, hContact); - else if (!_xcscmp(theKey, XSTR(key, "proto"))) - theValue = mir_a2x(key, GetContactProto(hContact)); - else if (!_xcscmp(theKey, XSTR(key, "accountname"))) { - PROTOACCOUNT *acc = ProtoGetAccount(GetContactProto(hContact)); - if (acc != NULL) - theValue = mir_a2x(key, _T2A(acc->tszAccountName)); - } - else if (!_xcscmp(theKey, XSTR(key, "userid"))) - theValue = GetContactIDX(key, hContact); - } - - if (!theValue) { - if (!_xcscmp(theKey, XSTR(key, "miranda_path"))) - theValue = GetModulePathX(key, NULL); - else if (!_xcscmp(theKey, XSTR(key, "appdata"))) - theValue = SHGetSpecialFolderPathX(CSIDL_APPDATA, theKey); - else if (!_xcscmp(theKey, XSTR(key, "mydocuments"))) - theValue = SHGetSpecialFolderPathX(CSIDL_PERSONAL, theKey); - else if (!_xcscmp(theKey, XSTR(key, "desktop"))) - theValue = SHGetSpecialFolderPathX(CSIDL_DESKTOPDIRECTORY, theKey); - else if (!_xcscmp(theKey, XSTR(key, "miranda_profilesdir"))) - theValue = GetProfileDirX(key); - else if (!_xcscmp(theKey, XSTR(key, "miranda_profilename"))) - theValue = GetProfileNameX(key); - else if (!_xcscmp(theKey, XSTR(key, "username"))) - theValue = GetUserNameX(key); - else if (!_xcscmp(theKey, XSTR(key, "miranda_avatarcache"))) - theValue = GetPathVarX(key, 1); - else if (!_xcscmp(theKey, XSTR(key, "miranda_logpath"))) - theValue = GetPathVarX(key, 2); - else if (!_xcscmp(theKey, XSTR(key, "miranda_userdata"))) - theValue = GetPathVarX(key, 3); - } - - if (!theValue) - theValue = GetEnvironmentVariableX(theKey); - - return theValue; -} - -template -XCHAR *GetVariableFromArray(REPLACEVARSARRAY *vars, XCHAR *key, size_t keyLength, MCONTACT hContact, bool *bFree) -{ - *bFree = false; - for (REPLACEVARSARRAY *var = vars; var && var->lptzKey; ++var) - if ((_xcslen((XCHAR *)var->lptzKey) == keyLength) && !_xcsncmp(key, (XCHAR *)var->lptzKey, keyLength)) - return (XCHAR *)var->lptzValue; - - *bFree = true; - return GetInternalVariable(key, keyLength, hContact); -} - -template -XCHAR *ReplaceVariables(XCHAR *str, REPLACEVARSDATA *data) -{ - if (!str) - return NULL; - - XCHAR *p; - XCHAR *varStart = 0; - size_t length = 0; - bool bFree; - - for (p = str; *p; ++p) { - if (*p == '%') { - if (varStart) { - if (p == varStart) - length++; - else if (XCHAR *value = GetVariableFromArray(data->variables, varStart, p-varStart, data->hContact, &bFree)) { - length += _xcslen(value); - if (bFree) mir_free(value); - } - else // variable not found - length += p-varStart+2; - - varStart = 0; - } - else varStart = p+1; - } - else if (!varStart) - length++; - } - if (varStart) - length += (p - varStart)+1; - - XCHAR *result = (XCHAR *)mir_alloc(sizeof(XCHAR) * (length + 1)); - XCHAR *q = result; - varStart = NULL; - - for (p = str; *p; ++p) { - if (*p == '%') { - if (varStart) { - if (p == varStart) - *q++='%'; - else if (XCHAR *value = GetVariableFromArray(data->variables, varStart, p-varStart, data->hContact, &bFree)) { - _xcscpy(q, value); - q += _xcslen(value); - if (bFree) mir_free(value); - } - else { - // variable not found - _xcsncpy(q, varStart-1, p-varStart+2); - q += p-varStart+2; - } - varStart = 0; - } - else varStart = p+1; - } - else if (!varStart) - *q++=*p; - } - - if (varStart) { - size_t len = p - varStart + 1; - _xcsncpy(q, varStart-1, len); - q += len; - } - - *q = 0; - - return result; -} - -static INT_PTR replaceVars(WPARAM wParam, LPARAM lParam) -{ - REPLACEVARSDATA *data = (REPLACEVARSDATA *)lParam; - if (data->dwFlags & RVF_UNICODE) - return (INT_PTR)ReplaceVariables((WCHAR *)wParam, data); - - return (INT_PTR)ReplaceVariables((char *)wParam, data); -} - -int InitPathUtils(void) -{ - CreateServiceFunction(MS_UTILS_PATHTORELATIVE, pathToRelative); - CreateServiceFunction(MS_UTILS_PATHTORELATIVEW, pathToRelativeW); - - CreateServiceFunction(MS_UTILS_PATHTOABSOLUTE, pathToAbsolute); - CreateServiceFunction(MS_UTILS_PATHTOABSOLUTEW, pathToAbsoluteW); - - CreateServiceFunction(MS_UTILS_CREATEDIRTREE, createDirTree); - CreateServiceFunction(MS_UTILS_CREATEDIRTREEW, createDirTreeW); - - CreateServiceFunction(MS_UTILS_REPLACEVARS, replaceVars); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static int OnFoldersChanged(WPARAM, LPARAM) -{ - mir_sntprintf(tszAvatarRoot, SIZEOF(tszAvatarRoot), _T("%s\\%s\\AvatarCache"), g_profileDir, g_shortProfileName); - - TCHAR tmpVar[MAX_PATH]; - if (!FoldersGetCustomPathT(hAvatarFolder, tmpVar, SIZEOF(tmpVar), tszAvatarRoot)) - _tcsncpy_s(tszAvatarRoot, tmpVar, _TRUNCATE); - return 0; -} - -void InitPathVar() -{ - mir_sntprintf(tszAvatarRoot, SIZEOF(tszAvatarRoot), _T("%s\\%s\\AvatarCache"), g_profileDir, g_shortProfileName); - if (hAvatarFolder = FoldersRegisterCustomPathT( LPGEN("Avatars"), LPGEN("Avatars root folder"), tszAvatarRoot)) { - TCHAR tmpVar[MAX_PATH]; - if (!FoldersGetCustomPathT(hAvatarFolder, tmpVar, SIZEOF(tmpVar), tszAvatarRoot)) - _tcsncpy_s(tszAvatarRoot, tmpVar, _TRUNCATE); - HookEvent(ME_FOLDERS_PATH_CHANGED, OnFoldersChanged); - } -} diff --git a/src/modules/utils/resizer.cpp b/src/modules/utils/resizer.cpp deleted file mode 100644 index 17f9e5bd34..0000000000 --- a/src/modules/utils/resizer.cpp +++ /dev/null @@ -1,158 +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 "..\..\core\commonheaders.h" - -#pragma pack(2) - -typedef struct { - DWORD helpID; - DWORD exStyle; - DWORD style; - short x; - short y; - short cx; - short cy; - DWORD id; -} START_OF_DLGITEMTEMPLATEEX; - -typedef struct { - WORD dlgVer; - WORD signature; - DWORD helpID; - DWORD exStyle; - DWORD style; - WORD cDlgItems; - short x; - short y; - short cx; - short cy; -} START_OF_DLGTEMPLATEEX; - -INT_PTR ResizeDialog(WPARAM, LPARAM lParam) -{ - UTILRESIZEDIALOG *urd = (UTILRESIZEDIALOG*)lParam; - HDWP hDwp; - int i; - DLGITEMTEMPLATE *pItem = NULL; - START_OF_DLGITEMTEMPLATEEX *pItemEx = NULL; - RECT rc; - PWORD pWord; - DLGTEMPLATE *pTemplate; - START_OF_DLGTEMPLATEEX *pTemplateEx; - UTILRESIZECONTROL urc; - int procResult; - int extendedDlg, itemCount; - - if (urd == NULL || urd->cbSize != sizeof(UTILRESIZEDIALOG)) return 1; - pTemplate = (DLGTEMPLATE*)LockResource(LoadResource(urd->hInstance, FindResourceA(urd->hInstance, urd->lpTemplate, MAKEINTRESOURCEA(5)))); - pTemplateEx = (START_OF_DLGTEMPLATEEX*)pTemplate; - extendedDlg = pTemplateEx->signature == 0xFFFF; - if (extendedDlg && pTemplateEx->dlgVer != 1) - return 1; - - if (extendedDlg) pWord = (PWORD)(pTemplateEx+1); - else pWord = (PWORD)(pTemplate+1); - if (*pWord == 0xFFFF) pWord+=2; else while (*pWord++); //menu - if (*pWord == 0xFFFF) pWord+=2; else while (*pWord++); //class - while (*pWord++); //title - if (extendedDlg) { - if (pTemplateEx->style&DS_SETFONT) { - pWord+=3; //font size, weight, italic - while (*pWord++); //font name - } - } - else { - if (pTemplate->style&DS_SETFONT) { - pWord++; //font size - while (*pWord++); //font name - } - } - - urc.cbSize = sizeof(UTILRESIZECONTROL); - rc.left = 0; rc.top = 0; - if (extendedDlg) {rc.right = pTemplateEx->cx; rc.bottom = pTemplateEx->cy;} - else {rc.right = pTemplate->cx; rc.bottom = pTemplate->cy;} - MapDialogRect(urd->hwndDlg, &rc); - urc.dlgOriginalSize.cx = rc.right; urc.dlgOriginalSize.cy = rc.bottom; - GetClientRect(urd->hwndDlg, &rc); - urc.dlgNewSize.cx = rc.right; urc.dlgNewSize.cy = rc.bottom; - - if (extendedDlg) itemCount = pTemplateEx->cDlgItems; - else itemCount = pTemplate->cdit; - hDwp = BeginDeferWindowPos(itemCount); - for (i=0;iid; - urc.rcItem.left = pItemEx->x; urc.rcItem.top = pItemEx->y; - urc.rcItem.right = urc.rcItem.left+pItemEx->cx; urc.rcItem.bottom = urc.rcItem.top+pItemEx->cy; - } - else { - pItem = (DLGITEMTEMPLATE*)pWord; - pWord = (PWORD)(pItem+1); - - urc.wId = pItem->id; - urc.rcItem.left = pItem->x; urc.rcItem.top = pItem->y; - urc.rcItem.right = urc.rcItem.left+pItem->cx; urc.rcItem.bottom = urc.rcItem.top+pItem->cy; - } - if (*pWord == 0xFFFF) pWord+=2; else while (*pWord++); //menu - if (*pWord == 0xFFFF) pWord+=2; else while (*pWord++); //class - pWord+=1+(1+*pWord)/2; //creation data - - if (urc.wId == 65535) continue; //using this breaks the dwp, so just ignore it - - MapDialogRect(urd->hwndDlg, &urc.rcItem); - procResult = (urd->pfnResizer)(urd->hwndDlg, urd->lParam, &urc); - if (procResult&RD_ANCHORX_RIGHT) { - urc.rcItem.left+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx; - urc.rcItem.right+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx; - } - else if (procResult&RD_ANCHORX_WIDTH) - urc.rcItem.right+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx; - else if (procResult&RD_ANCHORX_CENTRE) { - urc.rcItem.left+=(urc.dlgNewSize.cx-urc.dlgOriginalSize.cx)/2; - urc.rcItem.right+=(urc.dlgNewSize.cx-urc.dlgOriginalSize.cx)/2; - } - if (procResult&RD_ANCHORY_BOTTOM) { - urc.rcItem.top+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy; - urc.rcItem.bottom+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy; - } - else if (procResult&RD_ANCHORY_HEIGHT) - urc.rcItem.bottom+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy; - else if (procResult&RD_ANCHORY_CENTRE) { - urc.rcItem.top+=(urc.dlgNewSize.cy-urc.dlgOriginalSize.cy)/2; - urc.rcItem.bottom+=(urc.dlgNewSize.cy-urc.dlgOriginalSize.cy)/2; - } - HWND hCtrl = GetDlgItem(urd->hwndDlg, extendedDlg ? pItemEx->id : pItem->id); - if (NULL != hCtrl) /* Wine fix. */ - hDwp = DeferWindowPos(hDwp, hCtrl, 0, urc.rcItem.left, urc.rcItem.top, urc.rcItem.right-urc.rcItem.left, urc.rcItem.bottom-urc.rcItem.top, SWP_NOZORDER); - } - EndDeferWindowPos(hDwp); - return 0; -} diff --git a/src/modules/utils/timeutils.cpp b/src/modules/utils/timeutils.cpp deleted file mode 100644 index a2f926f74d..0000000000 --- a/src/modules/utils/timeutils.cpp +++ /dev/null @@ -1,103 +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. - -implements services to handle location - based timezones, instead of -simple UTC offsets. -*/ - -#include "..\..\core\commonheaders.h" - -// KB167296 -void UnixTimeToFileTime(mir_time ts, LPFILETIME pft) -{ - unsigned __int64 ll = UInt32x32To64(ts, 10000000) + 116444736000000000i64; - pft->dwLowDateTime = (DWORD)ll; - pft->dwHighDateTime = ll >> 32; -} - -mir_time FileTimeToUnixTime(LPFILETIME pft) -{ - unsigned __int64 ll = (unsigned __int64)pft->dwHighDateTime << 32 | pft->dwLowDateTime; - ll -= 116444736000000000i64; - return (mir_time)(ll / 10000000); -} - -void FormatTime(const SYSTEMTIME *st, const TCHAR *szFormat, TCHAR *szDest, int cbDest) -{ - if (szDest == NULL || cbDest == 0) return; - - CMString tszTemp; - - for (const TCHAR* pFormat = szFormat; *pFormat; ++pFormat) { - DWORD fmt; - bool date, iso = false; - switch (*pFormat) { - case 't': - fmt = TIME_NOSECONDS; - date = false; - break; - - case 's': - fmt = 0; - date = false; - break; - - case 'm': - fmt = TIME_NOMINUTESORSECONDS; - date = false; - break; - - case 'd': - fmt = DATE_SHORTDATE; - date = true; - break; - - case 'D': - fmt = DATE_LONGDATE; - date = true; - break; - - case 'I': - iso = true; - break; - - default: - tszTemp.AppendChar(*pFormat); - continue; - } - - TCHAR dateTimeStr[64]; - if (iso) - tszTemp.AppendFormat(_T("%d-%02d-%02dT%02d:%02d:%02dZ"), st->wYear, st->wMonth, st->wDay, st->wHour, st->wMinute, st->wSecond); - else if (date) { - GetDateFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, SIZEOF(dateTimeStr)); - tszTemp.Append(dateTimeStr); - } - else { - GetTimeFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, SIZEOF(dateTimeStr)); - tszTemp.Append(dateTimeStr); - } - } - - _tcsncpy_s(szDest, cbDest, tszTemp, _TRUNCATE); -} diff --git a/src/modules/utils/timezones.cpp b/src/modules/utils/timezones.cpp deleted file mode 100644 index 6cf2a9c0f6..0000000000 --- a/src/modules/utils/timezones.cpp +++ /dev/null @@ -1,557 +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. - -implements services to handle location - based timezones, instead of -simple UTC offsets. -*/ - -#include "..\..\core\commonheaders.h" - -TIME_API tmi; - -typedef DWORD (WINAPI *pfnGetDynamicTimeZoneInformation_t)(DYNAMIC_TIME_ZONE_INFORMATION *pdtzi); -static pfnGetDynamicTimeZoneInformation_t pfnGetDynamicTimeZoneInformation; - -struct REG_TZI_FORMAT -{ - LONG Bias; - LONG StandardBias; - LONG DaylightBias; - SYSTEMTIME StandardDate; - SYSTEMTIME DaylightDate; -}; - -#define MIM_TZ_DISPLAYLEN 128 - -struct MIM_TIMEZONE -{ - unsigned hash; - int offset; - - TCHAR tszName[MIM_TZ_NAMELEN]; // windows name for the time zone - wchar_t szDisplay[MIM_TZ_DISPLAYLEN]; // more descriptive display name (that's what usually appears in dialogs) - // every hour should be sufficient. - TIME_ZONE_INFORMATION tzi; - - static int compareBias(const MIM_TIMEZONE* p1, const MIM_TIMEZONE* p2) - { return p2->tzi.Bias - p1->tzi.Bias; } -}; - -struct TZ_INT_INFO -{ - DWORD timestamp; // last time updated - MIM_TIMEZONE myTZ; // set to my own timezone -}; - -static TZ_INT_INFO myInfo; - -static OBJLIST g_timezones(55, NumericKeySortT); -static LIST g_timezonesBias(55, MIM_TIMEZONE::compareBias); - -void FormatTime(const SYSTEMTIME *st, const TCHAR *szFormat, TCHAR *szDest, int cbDest); -void UnixTimeToFileTime(mir_time ts, LPFILETIME pft); -mir_time FileTimeToUnixTime(LPFILETIME pft); - -#define fnSystemTimeToTzSpecificLocalTime SystemTimeToTzSpecificLocalTime - -static int timeapiGetTimeZoneTime(HANDLE hTZ, SYSTEMTIME *st) -{ - if (st == NULL) return 1; - - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == UTC_TIME_HANDLE) - GetSystemTime(st); - else if (tz && tz != &myInfo.myTZ) { - SYSTEMTIME sto; - GetSystemTime(&sto); - return !fnSystemTimeToTzSpecificLocalTime(&tz->tzi, &sto, st); - } - else - GetLocalTime(st); - - return 0; -} - -static LPCTSTR timeapiGetTzName(HANDLE hTZ) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == NULL) - return myInfo.myTZ.tszName; - else if (tz == UTC_TIME_HANDLE) - return _T("UTC"); - - return tz->tszName; -} - -static LPCTSTR timeapiGetTzDescription(LPCTSTR TZname) -{ - for (int i = 0; i < g_timezonesBias.getCount(); i++) { - MIM_TIMEZONE *tz = g_timezonesBias[i]; - - if (!mir_tstrcmp(tz->tszName, TZname)) - return tz->szDisplay; - } - return _T(""); -} - -static void CalcTsOffset(MIM_TIMEZONE *tz) -{ - SYSTEMTIME st, stl; - GetSystemTime(&st); - - FILETIME ft; - SystemTimeToFileTime(&st, &ft); - mir_time ts1 = FileTimeToUnixTime(&ft); - - if (!fnSystemTimeToTzSpecificLocalTime(&tz->tzi, &st, &stl)) - return; - - SystemTimeToFileTime(&stl, &ft); - mir_time ts2 = FileTimeToUnixTime(&ft); - - tz->offset = ts2 - ts1; -} - -static bool IsSameTime(MIM_TIMEZONE *tz) -{ - SYSTEMTIME st, stl; - - if (tz == &myInfo.myTZ) - return true; - - timeapiGetTimeZoneTime(tz, &stl); - timeapiGetTimeZoneTime(NULL, &st); - - return st.wHour == stl.wHour && st.wMinute == stl.wMinute; -} - -static HANDLE timeapiGetInfoByName(LPCTSTR tszName, DWORD dwFlags) -{ - if (tszName == NULL) - return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; - - if (mir_tstrcmp(myInfo.myTZ.tszName, tszName) == 0) - return (dwFlags & TZF_DIFONLY) ? NULL : &myInfo.myTZ; - - MIM_TIMEZONE tzsearch; - tzsearch.hash = mir_hashstrT(tszName); - - MIM_TIMEZONE *tz = g_timezones.find(&tzsearch); - if (tz == NULL) - return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; - - if (dwFlags & TZF_DIFONLY) - return IsSameTime(tz) ? NULL : tz; - - return tz; -} - -static HANDLE timeapiGetInfoByContact(MCONTACT hContact, LPCSTR szModule, DWORD dwFlags) -{ - if (hContact == NULL && szModule == NULL) - return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; - - if (szModule == NULL) szModule = "UserInfo"; - - DBVARIANT dbv; - if (!db_get_ts(hContact, szModule, "TzName", &dbv)) { - HANDLE res = timeapiGetInfoByName(dbv.ptszVal, dwFlags); - db_free(&dbv); - if (res) return res; - } - - signed char timezone = (signed char)db_get_b(hContact, szModule, "Timezone", -1); - if (timezone == -1) { - char *szProto = GetContactProto(hContact); - if (!db_get_ts(hContact, szProto, "TzName", &dbv)) { - HANDLE res = timeapiGetInfoByName(dbv.ptszVal, dwFlags); - db_free(&dbv); - if (res) return res; - } - timezone = (signed char)db_get_b(hContact, szProto, "Timezone", -1); - } - - if (timezone != -1) { - MIM_TIMEZONE tzsearch; - tzsearch.tzi.Bias = timezone * 30; - if (myInfo.myTZ.tzi.Bias == tzsearch.tzi.Bias) { - if (dwFlags & TZF_DIFONLY) return NULL; - return &myInfo.myTZ; - } - - int i = g_timezonesBias.getIndex(&tzsearch); - while (i >= 0 && g_timezonesBias[i]->tzi.Bias == tzsearch.tzi.Bias) --i; - - int delta = LONG_MAX; - for (int j = ++i; j < g_timezonesBias.getCount() && g_timezonesBias[j]->tzi.Bias == tzsearch.tzi.Bias; ++j) { - int delta1 = abs(g_timezonesBias[j]->tzi.DaylightDate.wMonth - myInfo.myTZ.tzi.DaylightDate.wMonth); - if (delta1 <= delta) { - delta = delta1; - i = j; - } - } - - if (i >= 0) { - MIM_TIMEZONE *tz = g_timezonesBias[i]; - return ((dwFlags & TZF_DIFONLY) && IsSameTime(tz)) ? NULL : tz; - } - } - return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; -} - -static void timeapiSetInfoByContact(MCONTACT hContact, LPCSTR szModule, HANDLE hTZ) -{ - if (szModule == NULL) szModule = "UserInfo"; - - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz) { - db_set_ts(hContact, szModule, "TzName", tz->tszName); - db_set_b(hContact, szModule, "Timezone", (char)((tz->tzi.Bias + tz->tzi.StandardBias) / 30)); - } - else { - db_unset(hContact, szModule, "TzName"); - db_unset(hContact, szModule, "Timezone"); - } -} - -static int timeapiPrintDateTime(HANDLE hTZ, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == NULL && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) - return 1; - - SYSTEMTIME st; - if (timeapiGetTimeZoneTime(tz, &st)) - return 1; - - FormatTime(&st, szFormat, szDest, cbDest); - return 0; -} - -static int timeapiPrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == NULL && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) - return 1; - - if (tz == NULL) - tz = &myInfo.myTZ; - - FILETIME ft; - if (tz == UTC_TIME_HANDLE) - UnixTimeToFileTime(ts, &ft); - else { - if (tz->offset == INT_MIN) - CalcTsOffset(tz); - - UnixTimeToFileTime(ts + tz->offset, &ft); - } - - SYSTEMTIME st; - FileTimeToSystemTime(&ft, &st); - - FormatTime(&st, szFormat, szDest, cbDest); - return 0; -} - -static LPTIME_ZONE_INFORMATION timeapiGetTzi(HANDLE hTZ) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - return tz ? &tz->tzi : &myInfo.myTZ.tzi; -} - -static mir_time timeapiTimeStampToTimeZoneTimeStamp(HANDLE hTZ, mir_time ts) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == NULL) - tz = &myInfo.myTZ; - - if (tz == UTC_TIME_HANDLE) - return ts; - - if (tz->offset == INT_MIN) - CalcTsOffset(tz); - - return ts + tz->offset; -} - -struct ListMessages -{ - UINT addStr, getSel, setSel, getData, setData; -}; - -static const ListMessages lbMessages = { LB_ADDSTRING, LB_GETCURSEL, LB_SETCURSEL, LB_GETITEMDATA, LB_SETITEMDATA }; -static const ListMessages cbMessages = { CB_ADDSTRING, CB_GETCURSEL, CB_SETCURSEL, CB_GETITEMDATA, CB_SETITEMDATA }; - -static const ListMessages* GetListMessages(HWND hWnd, DWORD dwFlags) -{ - if (hWnd == NULL) - return NULL; - - if (!(dwFlags & (TZF_PLF_CB | TZF_PLF_LB))) { - TCHAR tszClassName[128]; - GetClassName(hWnd, tszClassName, SIZEOF(tszClassName)); - if (!mir_tstrcmpi(tszClassName, _T("COMBOBOX"))) - dwFlags |= TZF_PLF_CB; - else if (!mir_tstrcmpi(tszClassName, _T("LISTBOX"))) - dwFlags |= TZF_PLF_LB; - } - if (dwFlags & TZF_PLF_CB) - return &cbMessages; - else if (dwFlags & TZF_PLF_LB) - return &lbMessages; - else - return NULL; -} - -/////////////////////////////////////////////////////////////////////////////// - -static int timeapiSelectListItem(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags) -{ - const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags); - if (lstMsg == NULL) - return -1; - - if (szModule == NULL) szModule = "UserInfo"; - - int iSelection = 0; - ptrT tszName(db_get_tsa(hContact, szModule, "TzName")); - if (tszName != NULL) { - unsigned hash = mir_hashstrT(tszName); - for (int i = 0; i < g_timezonesBias.getCount(); i++) { - if (hash == g_timezonesBias[i]->hash) { - iSelection = i + 1; - break; - } - } - } - else { - signed char cBias = db_get_b(hContact, szModule, "Timezone", -100); - if (cBias != -100) { - int iBias = cBias * 30; - for (int i = 0; i < g_timezonesBias.getCount(); i++) { - if (iBias == g_timezonesBias[i]->tzi.Bias) { - iSelection = i + 1; - break; - } - } - } - } - - SendMessage(hWnd, lstMsg->setSel, iSelection, 0); - return iSelection; -} - -static int timeapiPrepareList(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags) -{ - const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags); - if (lstMsg == NULL) - return 0; - - SendMessage(hWnd, lstMsg->addStr, 0, (LPARAM)TranslateT("")); - - for (int i = 0; i < g_timezonesBias.getCount(); i++) { - MIM_TIMEZONE *tz = g_timezonesBias[i]; - - SendMessage(hWnd, lstMsg->addStr, 0, (LPARAM)tz->szDisplay); - SendMessage(hWnd, lstMsg->setData, i + 1, (LPARAM)tz); - } - - return timeapiSelectListItem(hContact, szModule, hWnd, dwFlags); -} - -static void timeapiStoreListResult(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags) -{ - if (szModule == NULL) szModule = "UserInfo"; - - const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags); - if (lstMsg) { - LRESULT offset = SendMessage(hWnd, lstMsg->getSel, 0, 0); - if (offset > 0) { - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)SendMessage(hWnd, lstMsg->getData, offset, 0); - if ((INT_PTR)tz != CB_ERR && tz != NULL) - timeapiSetInfoByContact(hContact, szModule, tz); - } - else timeapiSetInfoByContact(hContact, szModule, NULL); - } -} - -/////////////////////////////////////////////////////////////////////////////// - -static INT_PTR GetTimeApi(WPARAM, LPARAM lParam) -{ - TIME_API* tmi = (TIME_API*)lParam; - if (tmi == NULL) - return FALSE; - - if (tmi->cbSize != sizeof(TIME_API)) - return FALSE; - - tmi->createByName = timeapiGetInfoByName; - tmi->createByContact = timeapiGetInfoByContact; - tmi->storeByContact = timeapiSetInfoByContact; - - tmi->printDateTime = timeapiPrintDateTime; - tmi->printTimeStamp = timeapiPrintTimeStamp; - - tmi->prepareList = timeapiPrepareList; - tmi->selectListItem = timeapiSelectListItem; - tmi->storeListResults = timeapiStoreListResult; - - tmi->getTimeZoneTime = timeapiGetTimeZoneTime; - tmi->timeStampToTimeZoneTimeStamp = timeapiTimeStampToTimeZoneTimeStamp; - tmi->getTzi = timeapiGetTzi; - tmi->getTzName = timeapiGetTzName; - tmi->getTzDescription = timeapiGetTzDescription; - - return TRUE; -} - -static INT_PTR TimestampToLocal(WPARAM wParam, LPARAM) -{ - return timeapiTimeStampToTimeZoneTimeStamp(NULL, (mir_time)wParam); -} - -static INT_PTR TimestampToStringT(WPARAM wParam, LPARAM lParam) -{ - DBTIMETOSTRINGT *tts = (DBTIMETOSTRINGT*)lParam; - if (tts != NULL) - timeapiPrintTimeStamp(NULL, (mir_time)wParam, tts->szFormat, tts->szDest, tts->cbDest, 0); - return 0; -} - -static INT_PTR TimestampToStringA(WPARAM wParam, LPARAM lParam) -{ - DBTIMETOSTRING *tts = (DBTIMETOSTRING*)lParam; - if (tts != NULL) { - TCHAR *szDest = (TCHAR*)alloca(tts->cbDest*sizeof(TCHAR)); - timeapiPrintTimeStamp(NULL, (mir_time)wParam, _A2T(tts->szFormat), szDest, tts->cbDest, 0); - WideCharToMultiByte(CP_ACP, 0, szDest, -1, tts->szDest, tts->cbDest, NULL, NULL); - } - return 0; -} - -void GetLocalizedString(HKEY hSubKey, const TCHAR *szName, wchar_t *szBuf, DWORD cbLen) -{ - DWORD dwLength = cbLen * sizeof(wchar_t); - RegQueryValueEx(hSubKey, szName, NULL, NULL, (unsigned char *)szBuf, &dwLength); - szBuf[min(dwLength / sizeof(TCHAR), cbLen - 1)] = 0; -} - -extern "C" void RecalculateTime(void) -{ - GetTimeZoneInformation(&myInfo.myTZ.tzi); - myInfo.timestamp = time(NULL); - myInfo.myTZ.offset = INT_MIN; - - bool found = false; - DYNAMIC_TIME_ZONE_INFORMATION dtzi; - - if (pfnGetDynamicTimeZoneInformation && pfnGetDynamicTimeZoneInformation(&dtzi) != TIME_ZONE_ID_INVALID) { - TCHAR *myTzKey = mir_u2t(dtzi.TimeZoneKeyName); - _tcsncpy_s(myInfo.myTZ.tszName, myTzKey, _TRUNCATE); - mir_free(myTzKey); - found = true; - } - - for (int i = 0; i < g_timezones.getCount(); i++) { - MIM_TIMEZONE &tz = g_timezones[i]; - if (tz.offset != INT_MIN) - tz.offset = INT_MIN; - - if (!found) { - if (!mir_wstrcmp(tz.tzi.StandardName, myInfo.myTZ.tzi.StandardName) || !mir_wstrcmp(tz.tzi.DaylightName, myInfo.myTZ.tzi.DaylightName)) { - _tcsncpy_s(myInfo.myTZ.tszName, tz.tszName, _TRUNCATE); - found = true; - } - } - } -} - -void InitTimeZones(void) -{ - REG_TZI_FORMAT tzi; - HKEY hKey; - - const TCHAR *tszKey = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"); - - /* - * use GetDynamicTimeZoneInformation() on Vista+ - this will return a structure with - * the registry key name, so finding our own time zone later will be MUCH easier for - * localized systems or systems with a MUI pack installed - */ - if (IsWinVerVistaPlus()) - pfnGetDynamicTimeZoneInformation = (pfnGetDynamicTimeZoneInformation_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetDynamicTimeZoneInformation"); - - if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, tszKey, 0, KEY_ENUMERATE_SUB_KEYS, &hKey)) { - DWORD dwIndex = 0; - HKEY hSubKey; - TCHAR tszName[MIM_TZ_NAMELEN]; - - DWORD dwSize = SIZEOF(tszName); - while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, tszName, &dwSize, NULL, NULL, 0, NULL)) { - if (ERROR_SUCCESS == RegOpenKeyEx(hKey, tszName, 0, KEY_QUERY_VALUE, &hSubKey)) { - dwSize = sizeof(tszName); - - DWORD dwLength = sizeof(tzi); - if (ERROR_SUCCESS != RegQueryValueEx(hSubKey, _T("TZI"), NULL, NULL, (unsigned char *)&tzi, &dwLength)) - continue; - - MIM_TIMEZONE *tz = new MIM_TIMEZONE; - - tz->tzi.Bias = tzi.Bias; - tz->tzi.StandardDate = tzi.StandardDate; - tz->tzi.StandardBias = tzi.StandardBias; - tz->tzi.DaylightDate = tzi.DaylightDate; - tz->tzi.DaylightBias = tzi.DaylightBias; - - mir_tstrcpy(tz->tszName, tszName); - tz->hash = mir_hashstrT(tszName); - tz->offset = INT_MIN; - - GetLocalizedString(hSubKey, _T("Display"), tz->szDisplay, SIZEOF(tz->szDisplay)); - GetLocalizedString(hSubKey, _T("Std"), tz->tzi.StandardName, SIZEOF(tz->tzi.StandardName)); - GetLocalizedString(hSubKey, _T("Dlt"), tz->tzi.DaylightName, SIZEOF(tz->tzi.DaylightName)); - - g_timezones.insert(tz); - g_timezonesBias.insert(tz); - - RegCloseKey(hSubKey); - } - dwSize = SIZEOF(tszName); - } - RegCloseKey(hKey); - } - - RecalculateTime(); - - CreateServiceFunction(MS_SYSTEM_GET_TMI, GetTimeApi); - - CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOLOCAL, TimestampToLocal); - CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOSTRINGT, TimestampToStringT); - - CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOSTRING, TimestampToStringA); - - tmi.cbSize = sizeof(tmi); - GetTimeApi(0, (LPARAM)&tmi); -} diff --git a/src/modules/utils/utils.cpp b/src/modules/utils/utils.cpp deleted file mode 100644 index abcca9426f..0000000000 --- a/src/modules/utils/utils.cpp +++ /dev/null @@ -1,496 +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 "..\..\core\commonheaders.h" - -#define MS_SYSTEM_GET_MD5I "Miranda/System/GetMD5I" - -INT_PTR ResizeDialog(WPARAM wParam, LPARAM lParam); - -int InitOpenUrl(void); -int InitWindowList(void); -int InitPathUtils(void); -int InitHyperlink(void); -int InitColourPicker(void); -void InitXmlApi(void); - -void InitTimeZones(void); - -int InitCrypt(void); -void UninitCrypt(void); - -INT_PTR __cdecl svcEnterString(WPARAM, LPARAM lParam); - -static BOOL bModuleInitialized = FALSE; - -static CountryListEntry countries[] = { - {0, LPGEN("Unspecified"), ""}, - {9999, LPGEN("Other"), ""}, - {0xFFFF, LPGEN("Unknown"), ""}, - {93, LPGEN("Afghanistan"), "AF"}, - {358, LPGEN("Aland Islands"), "AX"}, - {355, LPGEN("Albania"), "AL"}, - {213, LPGEN("Algeria"), "DZ"}, - {1684, LPGEN("American Samoa"), "AS"}, - {376, LPGEN("Andorra"), "AD"}, - {244, LPGEN("Angola"), "AO"}, - {1264, LPGEN("Anguilla"), "AI"}, - {0xFFFE, LPGEN("Antarctica"), "AQ"}, - {1268, LPGEN("Antigua and Barbuda"), "AG"}, - {54, LPGEN("Argentina"), "AR"}, - {374, LPGEN("Armenia"), "AM"}, - {297, LPGEN("Aruba"), "AW"}, - {61, LPGEN("Australia"), "AU"}, - {43, LPGEN("Austria"), "AT"}, - {994, LPGEN("Azerbaijan"), "AZ"}, - {1242, LPGEN("Bahamas"), "BS"}, - {973, LPGEN("Bahrain"), "BH"}, - {880, LPGEN("Bangladesh"), "BD"}, - {1246, LPGEN("Barbados"), "BB"}, - {375, LPGEN("Belarus"), "BY"}, - {32, LPGEN("Belgium"), "BE"}, - {501, LPGEN("Belize"), "BZ"}, - {229, LPGEN("Benin"), "BJ"}, - {1441, LPGEN("Bermuda"), "BM"}, - {975, LPGEN("Bhutan"), "BT"}, - {591, LPGEN("Bolivia"), "BO"}, - {5997, LPGEN("Bonaire, Sint Eustatius and Saba"), "BQ"}, - {387, LPGEN("Bosnia and Herzegovina"), "BA"}, - {267, LPGEN("Botswana"), "BW"}, - {55, LPGEN("Bouvet Island"), "BV"}, - {55, LPGEN("Brazil"), "BR"}, - {246, LPGEN("British Indian Ocean Territory"), "IO"}, - {673, LPGEN("Brunei"), "BN"}, - {359, LPGEN("Bulgaria"), "BG"}, - {226, LPGEN("Burkina Faso"), "BF"}, - {257, LPGEN("Burundi"), "BI"}, - {855, LPGEN("Cambodia"), "KH"}, - {237, LPGEN("Cameroon"), "CM"}, - {1, LPGEN("Canada"), "CA"}, - {238, LPGEN("Cape Verde"), "CV"}, - {1345, LPGEN("Cayman Islands"), "KY"}, - {236, LPGEN("Central African Republic"), "CF"}, - {235, LPGEN("Chad"), "TD"}, - {56, LPGEN("Chile"), "CL"}, - {86, LPGEN("China"), "CN"}, - {61, LPGEN("Christmas Island"), "CX"}, - {61, LPGEN("Cocos (Keeling) Islands"), "CC"}, - {57, LPGEN("Colombia"), "CO"}, - {269, LPGEN("Comoros"), "KM"}, - {242, LPGEN("Congo, Republic of the"), "CG"}, - {243, LPGEN("Congo, Democratic Republic of the"), "CD"}, - {682, LPGEN("Cook Islands"), "CK"}, - {506, LPGEN("Costa Rica"), "CR"}, - {225, LPGEN("Cote d'Ivoire"), "CI"}, - {385, LPGEN("Croatia"), "HR"}, - {53, LPGEN("Cuba"), "CU"}, - {5999, LPGEN("Curacao"), "CW"}, - {357, LPGEN("Cyprus"), "CY"}, - {420, LPGEN("Czech Republic"), "CZ"}, - {45, LPGEN("Denmark"), "DK"}, - {253, LPGEN("Djibouti"), "DJ"}, - {1767, LPGEN("Dominica"), "DM"}, - {1809, LPGEN("Dominican Republic"), "DO"}, - {670, LPGEN("East Timor"), "TL"}, - {593, LPGEN("Ecuador"), "EC"}, - {20, LPGEN("Egypt"), "EG"}, - {503, LPGEN("El Salvador"), "SV"}, - {240, LPGEN("Equatorial Guinea"), "GQ"}, - {291, LPGEN("Eritrea"), "ER"}, - {372, LPGEN("Estonia"), "EE"}, - {251, LPGEN("Ethiopia"), "ET"}, - {500, LPGEN("Falkland Islands (Malvinas)"), "FK"}, - {298, LPGEN("Faroe Islands"), "FO"}, - {679, LPGEN("Fiji"), "FJ"}, - {358, LPGEN("Finland"), "FI"}, - {33, LPGEN("France"), "FR"}, - {594, LPGEN("French Guiana"), "GF"}, - {689, LPGEN("French Polynesia"), "PF"}, - {0xFFFE, LPGEN("French Southern and Antarctic Lands"), "TF"}, - {241, LPGEN("Gabon"), "GA"}, - {220, LPGEN("Gambia"), "GM"}, - {995, LPGEN("Georgia"), "GE"}, - {49, LPGEN("Germany"), "DE"}, - {233, LPGEN("Ghana"), "GH"}, - {350, LPGEN("Gibraltar"), "GI"}, - {30, LPGEN("Greece"), "GR"}, - {299, LPGEN("Greenland"), "GL"}, - {1473, LPGEN("Grenada"), "GD"}, - {590, LPGEN("Guadeloupe"), "GP"}, - {1671, LPGEN("Guam"), "GU"}, - {502, LPGEN("Guatemala"), "GT"}, - {44, LPGEN("Guernsey"), "GG"}, - {224, LPGEN("Guinea"), "GN"}, - {245, LPGEN("Guinea-Bissau"), "GW"}, - {592, LPGEN("Guyana"), "GY"}, - {509, LPGEN("Haiti"), "HT"}, - {0xFFFE, LPGEN("Heard Island and McDonald Islands"), "HM"}, - {504, LPGEN("Honduras"), "HN"}, - {852, LPGEN("Hong Kong"), "HK"}, - {36, LPGEN("Hungary"), "HU"}, - {354, LPGEN("Iceland"), "IS"}, - {91, LPGEN("India"), "IN"}, - {62, LPGEN("Indonesia"), "ID"}, - {98, LPGEN("Iran"), "IR"}, - {964, LPGEN("Iraq"), "IQ"}, - {353, LPGEN("Ireland"), "IE"}, - {44, LPGEN("Isle of Man"), "IM"}, - {972, LPGEN("Israel"), "IL"}, - {39, LPGEN("Italy"), "IT"}, - {1876, LPGEN("Jamaica"), "JM"}, - {81, LPGEN("Japan"), "JP"}, - {44, LPGEN("Jersey"), "JE"}, - {962, LPGEN("Jordan"), "JO"}, - {76, LPGEN("Kazakhstan"), "KZ"}, - {254, LPGEN("Kenya"), "KE"}, - {686, LPGEN("Kiribati"), "KI"}, - {850, LPGEN("North Korea"), "KP"}, - {82, LPGEN("South Korea"), "KR"}, - {965, LPGEN("Kuwait"), "KW"}, - {996, LPGEN("Kyrgyzstan"), "KG"}, - {856, LPGEN("Laos"), "LA"}, - {371, LPGEN("Latvia"), "LV"}, - {961, LPGEN("Lebanon"), "LB"}, - {266, LPGEN("Lesotho"), "LS"}, - {231, LPGEN("Liberia"), "LR"}, - {218, LPGEN("Libya"), "LY"}, - {423, LPGEN("Liechtenstein"), "LI"}, - {370, LPGEN("Lithuania"), "LT"}, - {352, LPGEN("Luxembourg"), "LU"}, - {853, LPGEN("Macau"), "MO"}, - {389, LPGEN("Macedonia"), "MK"}, - {261, LPGEN("Madagascar"), "MG"}, - {265, LPGEN("Malawi"), "MW"}, - {60, LPGEN("Malaysia"), "MY"}, - {960, LPGEN("Maldives"), "MV"}, - {223, LPGEN("Mali"), "ML"}, - {356, LPGEN("Malta"), "MT"}, - {692, LPGEN("Marshall Islands"), "MH"}, - {596, LPGEN("Martinique"), "MQ"}, - {222, LPGEN("Mauritania"), "MR"}, - {230, LPGEN("Mauritius"), "MU"}, - {262, LPGEN("Mayotte"), "YT"}, - {52, LPGEN("Mexico"), "MX"}, - {691, LPGEN("Micronesia, Federated States of"), "FM"}, - {373, LPGEN("Moldova"), "MD"}, - {377, LPGEN("Monaco"), "MC"}, - {976, LPGEN("Mongolia"), "MN"}, - {382, LPGEN("Montenegro"), "ME"}, - {1664, LPGEN("Montserrat"), "MS"}, - {212, LPGEN("Morocco"), "MA"}, - {258, LPGEN("Mozambique"), "MZ"}, - {95, LPGEN("Myanmar"), "MM"}, - {264, LPGEN("Namibia"), "NA"}, - {674, LPGEN("Nauru"), "NR"}, - {977, LPGEN("Nepal"), "NP"}, - {31, LPGEN("Netherlands"), "NL"}, - {687, LPGEN("New Caledonia"), "NC"}, - {64, LPGEN("New Zealand"), "NZ"}, - {505, LPGEN("Nicaragua"), "NI"}, - {227, LPGEN("Niger"), "NE"}, - {234, LPGEN("Nigeria"), "NG"}, - {683, LPGEN("Niue"), "NU"}, - {672, LPGEN("Norfolk Island"), "NF"}, - {1670, LPGEN("Northern Mariana Islands"), "MP"}, - {47, LPGEN("Norway"), "NO"}, - {968, LPGEN("Oman"), "OM"}, - {92, LPGEN("Pakistan"), "PK"}, - {680, LPGEN("Palau"), "PW"}, - {970, LPGEN("Palestinian Territories"), "PS"}, - {507, LPGEN("Panama"), "PA"}, - {675, LPGEN("Papua New Guinea"), "PG"}, - {595, LPGEN("Paraguay"), "PY"}, - {51, LPGEN("Peru"), "PE"}, - {63, LPGEN("Philippines"), "PH"}, - {64, LPGEN("Pitcairn Islands"), "PN"}, - {48, LPGEN("Poland"), "PL"}, - {351, LPGEN("Portugal"), "PT"}, - {1787, LPGEN("Puerto Rico"), "PR"}, - {974, LPGEN("Qatar"), "QA"}, - {262, LPGEN("Reunion"), "RE"}, - {40, LPGEN("Romania"), "RO"}, - {7, LPGEN("Russia"), "RU"}, - {250, LPGEN("Rwanda"), "RW"}, - {590, LPGEN("Saint Barthelemy"), "BL"}, - {290, LPGEN("Saint Helena, Ascension and Tristan da Cunha"), "SH"}, - {1869, LPGEN("Saint Kitts and Nevis"), "KN"}, - {1758, LPGEN("Saint Lucia"), "LC"}, - {590, LPGEN("Saint Martin (French part)"), "MF"}, - {508, LPGEN("Saint Pierre and Miquelon"), "PM"}, - {1784, LPGEN("Saint Vincent and the Grenadines"), "VC"}, - {685, LPGEN("Samoa"), "WS"}, - {378, LPGEN("San Marino"), "SM"}, - {239, LPGEN("Sao Tome and Principe"), "ST"}, - {966, LPGEN("Saudi Arabia"), "SA"}, - {221, LPGEN("Senegal"), "SN"}, - {381, LPGEN("Serbia"), "RS"}, - {248, LPGEN("Seychelles"), "SC"}, - {232, LPGEN("Sierra Leone"), "SL"}, - {65, LPGEN("Singapore"), "SG"}, - {1721, LPGEN("Sint Maarten (Dutch part)"), "SX"}, - {421, LPGEN("Slovakia"), "SK"}, - {386, LPGEN("Slovenia"), "SI"}, - {677, LPGEN("Solomon Islands"), "SB"}, - {252, LPGEN("Somalia"), "SO"}, - {27, LPGEN("South Africa"), "ZA"}, - {500, LPGEN("South Georgia and the South Sandwich Islands"), "GS"}, - {211, LPGEN("South Sudan"), "SS"}, - {34, LPGEN("Spain"), "ES"}, - {94, LPGEN("Sri Lanka"), "LK"}, - {249, LPGEN("Sudan"), "SD"}, - {597, LPGEN("Suriname"), "SR"}, - {4779, LPGEN("Svalbard and Jan Mayen"), "SJ"}, - {268, LPGEN("Swaziland"), "SZ"}, - {46, LPGEN("Sweden"), "SE"}, - {41, LPGEN("Switzerland"), "CH"}, - {963, LPGEN("Syria"), "SY"}, - {886, LPGEN("Taiwan"), "TW"}, - {992, LPGEN("Tajikistan"), "TJ"}, - {255, LPGEN("Tanzania"), "TZ"}, - {66, LPGEN("Thailand"), "TH"}, - {228, LPGEN("Togo"), "TG"}, - {690, LPGEN("Tokelau"), "TK"}, - {676, LPGEN("Tonga"), "TO"}, - {1868, LPGEN("Trinidad and Tobago"), "TT"}, - {216, LPGEN("Tunisia"), "TN"}, - {90, LPGEN("Turkey"), "TR"}, - {993, LPGEN("Turkmenistan"), "TM"}, - {1649, LPGEN("Turks and Caicos Islands"), "TC"}, - {688, LPGEN("Tuvalu"), "TV"}, - {256, LPGEN("Uganda"), "UG"}, - {380, LPGEN("Ukraine"), "UA"}, - {971, LPGEN("United Arab Emirates"), "AE"}, - {44, LPGEN("United Kingdom"), "GB"}, - {1, LPGEN("United States"), "US"}, - {699, LPGEN("United States Minor Outlying Islands"), "UM"}, - {598, LPGEN("Uruguay"), "UY"}, - {998, LPGEN("Uzbekistan"), "UZ"}, - {678, LPGEN("Vanuatu"), "VU"}, - {379, LPGEN("Vatican City"), "VA"}, - {58, LPGEN("Venezuela"), "VE"}, - {84, LPGEN("Vietnam"), "VN"}, - {1284, LPGEN("Virgin Islands (British)"), "VG"}, - {1340, LPGEN("Virgin Islands (United States)"), "VI"}, - {681, LPGEN("Wallis and Futuna"), "WF"}, - {5289, LPGEN("Western Sahara"), "EH"}, - {967, LPGEN("Yemen"), "YE"}, - {260, LPGEN("Zambia"), "ZM"}, - {263, LPGEN("Zimbabwe"), "ZW"} -}; - -static INT_PTR GetCountryByNumber(WPARAM wParam, LPARAM) -{ - for (int i = 0; i < SIZEOF(countries); i++) - if ((int)wParam == countries[i].id) - return (INT_PTR)countries[i].szName; - - return NULL; -} - -static INT_PTR GetCountryByISOCode(WPARAM wParam, LPARAM) -{ - for (int i = 0; i < SIZEOF(countries); i++) - if ( mir_strcmpi((char*)wParam, countries[i].ISOcode) == 0) - return (INT_PTR)countries[i].szName; - - return NULL; -} - -static INT_PTR GetCountryList(WPARAM wParam, LPARAM lParam) -{ - *(int*)wParam = SIZEOF(countries); - *(CountryListEntry**)lParam = countries; - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static INT_PTR SaveWindowPosition(WPARAM, LPARAM lParam) -{ - SAVEWINDOWPOS *swp = (SAVEWINDOWPOS*)lParam; - WINDOWPLACEMENT wp; - char szSettingName[64]; - - wp.length = sizeof(wp); - GetWindowPlacement(swp->hwnd, &wp); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sx", swp->szNamePrefix); - db_set_dw(swp->hContact, swp->szModule, szSettingName, wp.rcNormalPosition.left); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sy", swp->szNamePrefix); - db_set_dw(swp->hContact, swp->szModule, szSettingName, wp.rcNormalPosition.top); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%swidth", swp->szNamePrefix); - db_set_dw(swp->hContact, swp->szModule, szSettingName, wp.rcNormalPosition.right-wp.rcNormalPosition.left); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sheight", swp->szNamePrefix); - db_set_dw(swp->hContact, swp->szModule, szSettingName, wp.rcNormalPosition.bottom-wp.rcNormalPosition.top); - return 0; -} - -static INT_PTR svcAssertInsideScreen(WPARAM wParam, LPARAM lParam) -{ - LPRECT rc = (LPRECT)wParam; - if (rc == NULL) - return -1; - - return AssertInsideScreen(*rc); -} - -int AssertInsideScreen(RECT &rc) -{ - RECT rcScreen; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, FALSE); - if (MonitorFromRect(&rc, MONITOR_DEFAULTTONULL)) - return 0; - - MONITORINFO mi = {0}; - HMONITOR hMonitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST); - mi.cbSize = sizeof(mi); - if (GetMonitorInfo(hMonitor, &mi)) - rcScreen = mi.rcWork; - - if (rc.top >= rcScreen.bottom) - OffsetRect(&rc, 0, rcScreen.bottom - rc.bottom); - else if (rc.bottom <= rcScreen.top) - OffsetRect(&rc, 0, rcScreen.top - rc.top); - if (rc.left >= rcScreen.right) - OffsetRect(&rc, rcScreen.right - rc.right, 0); - else if (rc.right <= rcScreen.left) - OffsetRect(&rc, rcScreen.left - rc.left, 0); - - return 1; -} - -static INT_PTR RestoreWindowPosition(WPARAM wParam, LPARAM lParam) -{ - SAVEWINDOWPOS *swp = (SAVEWINDOWPOS*)lParam; - WINDOWPLACEMENT wp; - char szSettingName[64]; - int x, y; - - wp.length = sizeof(wp); - GetWindowPlacement(swp->hwnd, &wp); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sx", swp->szNamePrefix); - x = db_get_dw(swp->hContact, swp->szModule, szSettingName, -1); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sy", swp->szNamePrefix); - y = (int)db_get_dw(swp->hContact, swp->szModule, szSettingName, -1); - if (x == -1) return 1; - if (wParam&RWPF_NOSIZE) { - OffsetRect(&wp.rcNormalPosition, x-wp.rcNormalPosition.left, y-wp.rcNormalPosition.top); - } - else { - wp.rcNormalPosition.left = x; - wp.rcNormalPosition.top = y; - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%swidth", swp->szNamePrefix); - wp.rcNormalPosition.right = wp.rcNormalPosition.left+db_get_dw(swp->hContact, swp->szModule, szSettingName, -1); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sheight", swp->szNamePrefix); - wp.rcNormalPosition.bottom = wp.rcNormalPosition.top+db_get_dw(swp->hContact, swp->szModule, szSettingName, -1); - } - wp.flags = 0; - if (wParam & RWPF_HIDDEN) - wp.showCmd = SW_HIDE; - if (wParam & RWPF_NOACTIVATE) - wp.showCmd = SW_SHOWNOACTIVATE; - - if (!(wParam & RWPF_NOMOVE)) - AssertInsideScreen(wp.rcNormalPosition); - - SetWindowPlacement(swp->hwnd, &wp); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static INT_PTR RestartMiranda(WPARAM wParam, LPARAM) -{ - TCHAR mirandaPath[MAX_PATH], cmdLine[MAX_PATH]; - PROCESS_INFORMATION pi; - STARTUPINFO si = {0}; - si.cb = sizeof(si); - GetModuleFileName(NULL, mirandaPath, SIZEOF(mirandaPath)); - if (wParam) { - VARST profilename( _T("%miranda_profilename%")); - mir_sntprintf(cmdLine, SIZEOF(cmdLine), _T("\"%s\" /restart:%d /profile=%s"), mirandaPath, GetCurrentProcessId(), (TCHAR*)profilename); - } - else mir_sntprintf(cmdLine, SIZEOF(cmdLine), _T("\"%s\" /restart:%d"), mirandaPath, GetCurrentProcessId()); - - CallService("CloseAction", 0, 0); - CreateProcess(mirandaPath, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -typedef BOOL (APIENTRY *PGENRANDOM)(PVOID, ULONG); - -static INT_PTR GenerateRandom(WPARAM wParam, LPARAM lParam) -{ - if (wParam == 0 || lParam == 0) return 0; - - PGENRANDOM pfnRtlGenRandom = NULL; - HMODULE hModule = GetModuleHandleA("advapi32"); - if (hModule) - { - pfnRtlGenRandom = (PGENRANDOM)GetProcAddress(hModule, "SystemFunction036"); - if (pfnRtlGenRandom) - { - if (!pfnRtlGenRandom((PVOID)lParam, wParam)) - pfnRtlGenRandom = NULL; - } - } - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -int LoadUtilsModule(void) -{ - bModuleInitialized = TRUE; - - CreateServiceFunction(MS_UTILS_RESIZEDIALOG, ResizeDialog); - CreateServiceFunction(MS_UTILS_SAVEWINDOWPOSITION, SaveWindowPosition); - CreateServiceFunction(MS_UTILS_RESTOREWINDOWPOSITION, RestoreWindowPosition); - CreateServiceFunction(MS_UTILS_ASSERTINSIDESCREEN, svcAssertInsideScreen); - CreateServiceFunction(MS_UTILS_GETCOUNTRYBYNUMBER, GetCountryByNumber); - CreateServiceFunction(MS_UTILS_GETCOUNTRYBYISOCODE, GetCountryByISOCode); - CreateServiceFunction(MS_UTILS_GETCOUNTRYLIST, GetCountryList); - CreateServiceFunction(MS_UTILS_GETRANDOM, GenerateRandom); - CreateServiceFunction(MS_UTILS_ENTERSTRING, svcEnterString); - CreateServiceFunction(MS_SYSTEM_RESTART, RestartMiranda); - - InitOpenUrl(); - InitWindowList(); - InitHyperlink(); - InitPathUtils(); - InitColourPicker(); - InitXmlApi(); - InitTimeZones(); - InitCrypt(); - return 0; -} - -void UnloadUtilsModule(void) -{ - if (!bModuleInitialized) - return; - - UninitCrypt(); -} diff --git a/src/modules/utils/windowlist.cpp b/src/modules/utils/windowlist.cpp deleted file mode 100644 index 19445a3851..0000000000 --- a/src/modules/utils/windowlist.cpp +++ /dev/null @@ -1,111 +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 "..\..\core\commonheaders.h" - -struct TWindowListItem -{ - TWindowListItem(MCONTACT _contact, HWND _wnd) : - hContact(_contact), - hWnd(_wnd) - {} - - MCONTACT hContact; - HWND hWnd; -}; - -typedef OBJLIST TWindowList; - -static INT_PTR AllocWindowList(WPARAM, LPARAM) -{ - return (INT_PTR)new TWindowList(10, NumericKeySortT); -} - -static INT_PTR DestroyWindowList(WPARAM wParam, LPARAM) -{ - delete (TWindowList*)wParam; - return 0; -} - -static INT_PTR AddToWindowList(WPARAM, LPARAM lParam) -{ - WINDOWLISTENTRY *pEntry = (WINDOWLISTENTRY*)lParam; - TWindowList *pList = (TWindowList*)pEntry->hList; - if (pList != NULL) - pList->insert(new TWindowListItem(pEntry->hContact, pEntry->hwnd)); - return 0; -} - -static INT_PTR RemoveFromWindowList(WPARAM wParam, LPARAM lParam) -{ - if (wParam == 0) return 1; - TWindowList &pList = *(TWindowList*)wParam; - for (int i = 0; i < pList.getCount(); i++) { - if (pList[i].hWnd == (HWND)lParam) { - pList.remove(i); - return 0; - } - } - return 1; -} - -static INT_PTR FindInWindowList(WPARAM wParam, LPARAM lParam) -{ - if (wParam == 0) return NULL; - TWindowList &pList = *(TWindowList*)wParam; - TWindowListItem *p = pList.find((TWindowListItem*)&lParam); - return (p == NULL) ? NULL : (INT_PTR)p->hWnd; -} - -static INT_PTR BroadcastToWindowList(WPARAM wParam, LPARAM lParam) -{ - if (wParam == 0 || lParam == 0) return NULL; - TWindowList &pList = *(TWindowList*)wParam; - MSG *msg = (MSG*)lParam; - for (int i = pList.getCount()-1; i >= 0; i--) - SendMessage(pList[i].hWnd, msg->message, msg->wParam, msg->lParam); - return 0; -} - -static INT_PTR BroadcastToWindowListAsync(WPARAM wParam, LPARAM lParam) -{ - if (wParam == 0 || lParam == 0) return NULL; - TWindowList &pList = *(TWindowList*)wParam; - MSG *msg = (MSG*)lParam; - for (int i = pList.getCount()-1; i >= 0; i--) - PostMessage(pList[i].hWnd, msg->message, msg->wParam, msg->lParam); - return 0; -} - -int InitWindowList(void) -{ - CreateServiceFunction(MS_UTILS_ALLOCWINDOWLIST, AllocWindowList); - CreateServiceFunction(MS_UTILS_DESTROYWINDOWLIST, DestroyWindowList); - CreateServiceFunction(MS_UTILS_ADDTOWINDOWLIST, AddToWindowList); - CreateServiceFunction(MS_UTILS_REMOVEFROMWINDOWLIST, RemoveFromWindowList); - CreateServiceFunction(MS_UTILS_BROADCASTTOWINDOWLIST, BroadcastToWindowList); - CreateServiceFunction(MS_UTILS_BROADCASTTOWINDOWLIST_ASYNC, BroadcastToWindowListAsync); - CreateServiceFunction(MS_UTILS_FINDWINDOWINLIST, FindInWindowList); - return 0; -} -- cgit v1.2.3