diff options
author | Rozhuk Ivan <rozhuk.im@gmail.com> | 2014-11-26 23:19:10 +0000 |
---|---|---|
committer | Rozhuk Ivan <rozhuk.im@gmail.com> | 2014-11-26 23:19:10 +0000 |
commit | 08e744c5f087a8e693d160c527097a9f6a5bf712 (patch) | |
tree | 00547497cdf2b61d1094309414f68d853c505879 /plugins/Variables/src | |
parent | 15cb1c735a559b88c7ede033510d8f106eb9e314 (diff) |
Variables: code cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@11109 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Variables/src')
-rw-r--r-- | plugins/Variables/src/help.cpp | 2476 | ||||
-rw-r--r-- | plugins/Variables/src/variables.cpp | 1135 |
2 files changed, 1802 insertions, 1809 deletions
diff --git a/plugins/Variables/src/help.cpp b/plugins/Variables/src/help.cpp index 39d567c990..ed9a034559 100644 --- a/plugins/Variables/src/help.cpp +++ b/plugins/Variables/src/help.cpp @@ -1,1238 +1,1238 @@ -/*
- Variables Plugin for Miranda-IM (www.miranda-im.org)
- Copyright 2003-2006 P. Boon
-
- 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 "variables.h"
-
-struct HELPDLGDATA
-{
- VARHELPINFO *vhs;
- HWND hwndSubjectDlg;
- HWND hwndExtraTextDlg;
- HWND hwndInputDlg;
-};
-
-static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam);
-
-extern HINSTANCE hInst;
-
-extern HCURSOR hCurSplitNS;
-
-static HWND hwndHelpDialog = NULL;
-
-static HICON hHelpIcon = NULL;
-
-static int defaultHelpDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc) {
-
- switch(urc->wId) {
- case IDC_ABOUT:
- case IDC_ABOUTFRAME:
- return RD_ANCHORX_WIDTH|RD_ANCHORY_TOP;
- }
-
- return RD_ANCHORX_WIDTH|RD_ANCHORY_HEIGHT;
-}
-
-// dialog box for the %extratext% input
-static INT_PTR CALLBACK extratextDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) {
-
- switch(msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- break;
-
- case VARM_SETEXTRATEXT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(GetDlgItem(hwndDlg, IDC_EXTRATEXT), WM_SETTEXT, wParam, lParam));
- return TRUE;
-
- case VARM_GETEXTRATEXTLENGTH:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(GetDlgItem(hwndDlg, IDC_EXTRATEXT), WM_GETTEXTLENGTH, wParam, lParam));
- return TRUE;
-
- case VARM_GETEXTRATEXT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(GetDlgItem(hwndDlg, IDC_EXTRATEXT), WM_GETTEXT, wParam, lParam));
- return TRUE;
-
- case WM_SIZE:
- if (!IsIconic( hwndDlg )) {
- UTILRESIZEDIALOG urd = { 0 };
- urd.cbSize = sizeof(urd);
- urd.hInstance = hInst;
- urd.hwndDlg = hwndDlg;
- urd.lpTemplate = MAKEINTRESOURCEA(IDD_EXTRATEXT_DIALOG);
- urd.pfnResizer = defaultHelpDialogResize;
- CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
-
- SendMessage(hwndDlg, WM_MOVE, 0, 0);
- }
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_EXTRATEXT:
- SendMessage(GetParent(hwndDlg), VARM_PARSE, 0, 0);
- break;
- }
- break;
- }
-
- return FALSE;
-}
-
-// dialog box for the %subject% selection
-void ResetCList(HWND hwndDlg)
-{
- if ((CallService(MS_CLUI_GETCAPS, 0, 0) & CLUIF_DISABLEGROUPS && !db_get_b(NULL, "CList", "UseGroups", SETTING_USEGROUPS_DEFAULT)) || !(GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE)&CLS_USEGROUPS))
- SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETUSEGROUPS, FALSE, 0);
- else
- SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETUSEGROUPS, TRUE, 0);
-
- SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETHIDEEMPTYGROUPS, 1, 0);
-}
-
-static int clistDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc)
-{
- switch (urc->wId) {
- case IDC_ABOUT:
- case IDC_ABOUTFRAME:
- return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP;
-
- case IDC_NULL:
- case IDC_CONTACT:
- return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
- }
-
- return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
-}
-
-static INT_PTR CALLBACK clistDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
-{
- switch(msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE, (GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE) | (CLS_SHOWHIDDEN) | (CLS_NOHIDEOFFLINE)) & ~CLS_CHECKBOXES & ~CLS_USEGROUPS );
- ResetCList(hwndDlg);
- CheckRadioButton(hwndDlg, IDC_NULL, IDC_CONTACT, IDC_NULL);
- EnableWindow(GetDlgItem(hwndDlg, IDC_CLIST), IsDlgButtonChecked(hwndDlg, IDC_CONTACT));
- break;
-
- case VARM_SETSUBJECT:
- {
- LPARAM res = 0;
- MCONTACT hItem, hContact = wParam;
- log_debugA("VARM_SETSUBJECT: %u", hContact);
- if (hContact == INVALID_CONTACT_ID) {
- TCHAR *tszContact = db_get_tsa(NULL, MODULENAME, SETTING_SUBJECT);
- log_debugA("VARM_SETSUBJECT: %s", tszContact);
- if (tszContact != NULL) {
- hContact = decodeContactFromString(tszContact);
- log_debugA("VARM_SETSUBJECT decoded: %u", hContact);
- mir_free(tszContact);
- } }
-
- if ((hContact != INVALID_CONTACT_ID) && (hContact != NULL))
- hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0);
- else
- hItem = NULL;
-
- if (hItem != NULL)
- res = (LPARAM)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SELECTITEM, (WPARAM)hItem, 0);
-
- CheckRadioButton(hwndDlg, IDC_NULL, IDC_CONTACT, hItem==NULL?IDC_NULL:IDC_CONTACT);
- EnableWindow(GetDlgItem(hwndDlg, IDC_CLIST), IsDlgButtonChecked(hwndDlg, IDC_CONTACT));
- SetFocus(GetDlgItem(hwndDlg, IDC_CLIST));
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)res);
- }
- return TRUE;
-
- case VARM_GETSUBJECT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- (IsDlgButtonChecked(hwndDlg, IDC_CONTACT) ? SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETSELECTION, 0, 0) : 0));
- return TRUE;
-
- case WM_SIZE:
- if (!IsIconic(hwndDlg)) {
- UTILRESIZEDIALOG urd = { sizeof(urd) };
- urd.hInstance = hInst;
- urd.hwndDlg = hwndDlg;
- urd.lParam = 0;
- /* ! uses ANSI version ! */
- urd.lpTemplate = MAKEINTRESOURCEA(IDD_CLIST_DIALOG);
- urd.pfnResizer = clistDialogResize;
- CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
-
- SendMessage(hwndDlg, WM_MOVE, 0, 0);
- }
- break;
-
- case WM_SHOWWINDOW:
- if ((wParam) && (IsDlgButtonChecked(hwndDlg, IDC_CONTACT)))
- SetFocus(GetDlgItem(hwndDlg, IDC_CLIST));
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_NULL:
- case IDC_CONTACT:
- CheckRadioButton(hwndDlg, IDC_NULL, IDC_CONTACT, LOWORD(wParam));
- EnableWindow(GetDlgItem(hwndDlg, IDC_CLIST), IsDlgButtonChecked(hwndDlg, IDC_CONTACT));
- if (IsDlgButtonChecked(hwndDlg, IDC_CONTACT))
- SetFocus(GetDlgItem(hwndDlg, IDC_CLIST));
- break;
- }
- break;
-
- case WM_NOTIFY:
- switch (((NMHDR *) lParam)->idFrom) {
- case IDC_CLIST:
- switch (((NMHDR *) lParam)->code) {
- case CLN_OPTIONSCHANGED:
- ResetCList(hwndDlg);
- break;
- }
- break;
- }
- break;
-
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
-
- case WM_DESTROY:
- db_unset(NULL, MODULENAME, SETTING_SUBJECT);
-
- MCONTACT hContact = (MCONTACT)SendMessage(hwndDlg, VARM_GETSUBJECT, 0, 0);
- if (hContact != NULL) {
- TCHAR *tszContact = encodeContactToString(hContact);
- if (tszContact != NULL) {
- db_set_ts(NULL, MODULENAME, SETTING_SUBJECT, tszContact);
- mir_free(tszContact);
- } }
- break;
- }
-
- return FALSE;
-}
-
-// dialog box for the tokens
-static TCHAR *getTokenCategory(TOKENREGISTEREX *tr) {
- if (tr == NULL) {
- return NULL;
- }
- char *cat = NULL;
- char *helpText = mir_strdup(tr->szHelpText);
- if (helpText == NULL) {
- return NULL;
- }
- char *cur = helpText;
- while (*cur != 0) {
- if (*cur == '\t') {
- *cur = 0;
- helpText = ( char* )mir_realloc(helpText, strlen(helpText)+1);
-
- TCHAR *res = mir_a2t(helpText);
- mir_free(helpText);
- return res;
- }
- cur++;
- }
-
- TCHAR *res = mir_a2t(helpText);
- mir_free(helpText);
- return res;
-
-}
-
-static TCHAR *getHelpDescription(TOKENREGISTEREX *tr)
-{
- if (tr == NULL)
- return NULL;
-
- char *cur = tr->szHelpText + strlen(tr->szHelpText);
- while (cur > tr->szHelpText) {
- if (*cur == '\t') {
-
- cur = mir_strdup(cur+1);
- TCHAR *res = mir_a2t(cur);
- mir_free(cur);
- return res;
-
- }
- cur--;
- }
-
- return mir_a2t(tr->szHelpText);
-
-}
-
-static TCHAR *getTokenDescription(TOKENREGISTEREX *tr)
-{
- char *args, *first, *second;
-
- if (tr == NULL)
- return NULL;
-
- args = NULL;
- TCHAR *tArgs = NULL;
- if (tr->szHelpText == NULL)
- return mir_tstrdup(tr->tszTokenString);
-
- char *helpText = mir_strdup(tr->szHelpText);
- if (helpText == NULL)
- return NULL;
-
- char *cur = helpText;
- first = second = NULL;
- while (*cur != 0) {
- if (*cur == '\t') {
- if (first == NULL)
- first = cur;
- else if (second == NULL)
- second = cur;
- }
- cur++;
- }
-
- if ((first != NULL) && (second != NULL)) {
- *second = 0;
- args = first+1;
- }
- else args = NULL;
-
- size_t len = _tcslen(tr->tszTokenString) + (args!=NULL?strlen(args):0) + 3;
- TCHAR *desc = (TCHAR*)mir_calloc(len * sizeof(TCHAR));
- if (desc == NULL)
- return NULL;
-
- if (tr->flags&TRF_FIELD)
- mir_sntprintf(desc, len, _T("%c%s%c"), FIELD_CHAR, tr->szTokenString, FIELD_CHAR);
- else {
- if (args != NULL)
- tArgs = mir_a2t(args);
-
- mir_sntprintf(desc, len, _T("%c%s%s"), FUNC_CHAR, tr->tszTokenString, (tArgs!=NULL?tArgs:_T("")));
- }
-
- mir_free(tArgs);
- mir_free(helpText);
- return desc;
-}
-
-static int CALLBACK compareTokenHelp(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
-{
- TOKENREGISTEREX *tr1 = (TOKENREGISTEREX *)lParam1;
- TOKENREGISTEREX *tr2 = (TOKENREGISTEREX *)lParam2;
- if (tr1 == NULL || tr2 == NULL)
- return 0;
-
- ptrT cat1(getTokenCategory(tr1));
- ptrT cat2(getTokenCategory(tr2));
- if (cat1 == NULL || cat2 == NULL)
- return 0;
-
- int res = _tcscmp(cat1, cat2);
- if (res != 0)
- return res;
-
- if (tr1->tszTokenString == NULL || tr2->tszTokenString == NULL)
- return 0;
-
- return _tcscmp(tr1->tszTokenString, tr2->tszTokenString);
-}
-
-static BOOL CALLBACK processTokenListMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- /* hwndDlg must be a child of the help dialog */
- switch(msg) {
- case WM_INITDIALOG:
- {
- TOKENREGISTEREX *tr;
- TCHAR *tszTokenDesc, *tszHelpDesc, *last, *cat, *text;
-
- // token list things
- HWND hList = GetDlgItem(hwndDlg, IDC_TOKENLIST);
-
- LVCOLUMN lvCol = { 0 };
- lvCol.mask = LVCF_TEXT;
- lvCol.pszText = TranslateT("Token");
- ListView_InsertColumn(hList, 0, &lvCol);
-
- lvCol.pszText = TranslateT("Description");
- ListView_InsertColumn(hList, 1, &lvCol);
-
- HELPDLGDATA *hdd = (HELPDLGDATA *)GetWindowLongPtr(GetParent(hwndDlg), GWLP_USERDATA);
- int i = -1;
- do {
- i += 1;
- tszHelpDesc = tszTokenDesc = NULL;
- tr = getTokenRegister(i);
- if ((tr == NULL) || (tr->tszTokenString == NULL))
- continue;
-
- else if (hdd != NULL) {
- if (!_tcscmp(tr->tszTokenString, SUBJECT)) {
- if (hdd->vhs->flags&VHF_HIDESUBJECTTOKEN)
- continue;
-
- if (hdd->vhs->szSubjectDesc != NULL)
- tszHelpDesc = mir_a2t(hdd->vhs->szSubjectDesc);
- }
- if (!_tcscmp(tr->tszTokenString, MIR_EXTRATEXT)) {
- if (hdd->vhs->flags & VHF_HIDEEXTRATEXTTOKEN)
- continue;
-
- if (hdd->vhs->szExtraTextDesc != NULL)
- tszHelpDesc = mir_a2t(hdd->vhs->szExtraTextDesc);
- }
- }
-
- LVITEM lvItem = { 0 };
- lvItem.mask = LVIF_TEXT | LVIF_PARAM;
- lvItem.iItem = ListView_GetItemCount(hList);
- lvItem.lParam = (LPARAM)tr;
- tszTokenDesc = getTokenDescription(tr);
- if (tszTokenDesc == NULL)
- continue;
-
- lvItem.pszText = tszTokenDesc;
- ListView_InsertItem(hList, &lvItem);
- mir_free(tszTokenDesc);
-
- lvItem.mask = LVIF_TEXT;
- if (tszHelpDesc == NULL)
- tszHelpDesc = getHelpDescription(tr);
-
- if (tszHelpDesc == NULL)
- tszHelpDesc = mir_tstrdup(_T("unknown"));
-
- lvItem.iSubItem = 1;
- lvItem.pszText = TranslateTS(tszHelpDesc);
- ListView_SetItem(hList, &lvItem);
- mir_free(tszHelpDesc);
- }
- while (tr != NULL);
-
- ListView_SetColumnWidth(hList, 0, LVSCW_AUTOSIZE);
- ListView_SetColumnWidth(hList, 1, LVSCW_AUTOSIZE);
- ListView_SortItems(hList, compareTokenHelp, 0);
- last = text = NULL;
- for (i = 0; i < ListView_GetItemCount(hList); i++) {
- LVITEM lvItem = { 0 };
- lvItem.mask = LVIF_PARAM;
- lvItem.iItem = i;
- if (ListView_GetItem(hList, &lvItem) == FALSE)
- continue;
-
- cat = getTokenCategory((TOKENREGISTEREX *)lvItem.lParam);
- if (cat != NULL) {
- text = mir_tstrdup(TranslateTS(cat));
- mir_free(cat);
- }
- else text = NULL;
-
- if (text != NULL && (last == NULL || _tcsicmp(last, text))) {
- lvItem.mask = LVIF_TEXT;
- lvItem.pszText = text;
- ListView_InsertItem(hList, &lvItem);
- if (last != NULL) {
- mir_free(last);
- lvItem.iSubItem = 0;
- lvItem.pszText = _T("");
- ListView_InsertItem(hList, &lvItem);
- }
- last = text;
- }
- else mir_free(text);
- }
- mir_free(last);
- }
- break;
-
- case WM_NOTIFY:
- if ((((NMHDR*)lParam)->idFrom == IDC_TOKENLIST) && (((NMHDR*)lParam)->code == NM_DBLCLK)) {
- HWND hwndInputDlg = (HWND)SendMessage(GetParent(hwndDlg), VARM_GETDIALOG, (WPARAM)VHF_INPUT, 0);
- if (hwndInputDlg == NULL)
- break;
-
- HWND hList = GetDlgItem(hwndDlg, IDC_TOKENLIST);
- int item = ListView_GetNextItem(hList, -1, LVNI_SELECTED|LVNI_FOCUSED);
-
- LVITEM lvItem = { 0 };
- lvItem.mask = LVIF_PARAM;
- lvItem.iItem = item;
- if (ListView_GetItem(hList, &lvItem) == FALSE)
- break;
-
- TOKENREGISTER *tr = (TOKENREGISTER *)lvItem.lParam;
- if (tr == NULL)
- break;
-
- size_t len = _tcslen(tr->tszTokenString) + 2;
- if (len < 0)
- break;
-
- TCHAR *tokenString = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
- if (tokenString == NULL)
- break;
-
- ZeroMemory(tokenString, (len+1)*sizeof(TCHAR));
- mir_sntprintf(tokenString, len + 1, _T("%c%s%c"), (tr->flags & TRF_FIELD) ? FIELD_CHAR : FUNC_CHAR, tr->tszTokenString, (tr->flags & TRF_FIELD) ? FIELD_CHAR : '(');
- SendDlgItemMessage(hwndInputDlg, IDC_TESTSTRING, EM_REPLACESEL, TRUE, (LPARAM)tokenString);
- mir_free(tokenString);
- SetFocus(GetDlgItem(hwndInputDlg, IDC_TESTSTRING));
- }
- break;
- }
-
- return FALSE;
-}
-
-// "token only" dialog proc
-static INT_PTR CALLBACK tokenHelpDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- processTokenListMessage(hwndDlg, msg, wParam, lParam);
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- break;
-
- case WM_SIZE:
- if (!IsIconic(hwndDlg)) {
- UTILRESIZEDIALOG urd = { 0 };
- urd.cbSize = sizeof(urd);
- urd.hInstance = hInst;
- urd.hwndDlg = hwndDlg;
- urd.lpTemplate = MAKEINTRESOURCEA(IDD_TOKENS_DIALOG);
- urd.pfnResizer = defaultHelpDialogResize;
- CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
-
- SendMessage(hwndDlg, WM_MOVE, 0, 0);
- }
- break;
- }
-
- return FALSE;
-}
-
-// token + input dialog proc
-// from SRMM
-static LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- RECT rc;
-
- switch (msg) {
- case WM_NCHITTEST:
- return HTCLIENT;
-
- case WM_SETCURSOR:
- GetClientRect(hwnd, &rc);
- //SetCursor(rc.right > rc.bottom ? hCurSplitNS : hCurSplitWE);
- if (rc.right > rc.bottom)
- SetCursor(hCurSplitNS);
-
- return TRUE;
-
- case WM_LBUTTONDOWN:
- SetCapture(hwnd);
- return 0;
-
- case WM_MOUSEMOVE:
- if (GetCapture() == hwnd) {
- GetClientRect(hwnd, &rc);
- SendMessage(GetParent(hwnd), DM_SPLITTERMOVED, rc.right > rc.bottom ? (short)HIWORD(GetMessagePos()) + rc.bottom / 2 : (short)LOWORD(GetMessagePos()) + rc.right / 2, (LPARAM)hwnd);
- }
- return 0;
-
- case WM_LBUTTONUP:
- ReleaseCapture();
- return 0;
- }
- return mir_callNextSubclass(hwnd, SplitterSubclassProc, msg, wParam, lParam);
-}
-
-struct INPUTDLGDATA
-{
- int splitterPos;
- int originalSplitterPos;
- POINT minInputSize;
- POINT minResultSize;
- HWND hwndHelpDlg;
-};
-
-static int iFrameX, iFrameY;
-
-static int inputDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc)
-{
- INPUTDLGDATA *dat = (INPUTDLGDATA *)lParam;
-
- switch (urc->wId) {
- case IDC_TOKENLIST:
- return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP;
-
- case IDC_TESTSTRING:
- urc->rcItem.bottom -= dat->splitterPos - dat->originalSplitterPos;
- return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
-
- case IDC_SPLITTER:
- urc->rcItem.top -= dat->splitterPos - dat->originalSplitterPos;
- urc->rcItem.bottom -= dat->splitterPos - dat->originalSplitterPos;
- return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM;
-
- case IDC_RESULT:
- urc->rcItem.top -= dat->splitterPos - dat->originalSplitterPos;
- return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM;
- }
-
- return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
-}
-
-static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
-{
- static INPUTDLGDATA *dat = (INPUTDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
-
- processTokenListMessage(hwndDlg, msg, wParam, lParam);
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- dat = (INPUTDLGDATA*)mir_alloc(sizeof(INPUTDLGDATA));
- ZeroMemory(dat, sizeof(INPUTDLGDATA));
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
- // splitter things
- dat->splitterPos = (INT_PTR)db_get_dw(NULL, MODULENAME, SETTING_SPLITTERPOS, -1);
- {
- RECT rc;
- POINT pt;
- GetWindowRect(GetDlgItem(hwndDlg, IDC_SPLITTER), &rc);
- pt.y = (rc.top + rc.bottom) / 2;
- pt.x = 0;
- ScreenToClient(hwndDlg, &pt);
- dat->originalSplitterPos = pt.y;
-
- if (dat->splitterPos == -1)
- dat->splitterPos = dat->originalSplitterPos;
-
- GetWindowRect(GetDlgItem(hwndDlg, IDC_SHOWHELP), &rc);
- mir_subclassWindow(GetDlgItem(hwndDlg, IDC_SPLITTER), SplitterSubclassProc);
-
- GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rc);
- dat->minInputSize.x = rc.right - rc.left;
- dat->minInputSize.y = rc.bottom - rc.top;
- GetWindowRect(GetDlgItem(hwndDlg, IDC_RESULT), &rc);
- dat->minResultSize.x = rc.right - rc.left;
- dat->minResultSize.y = rc.bottom - rc.top;
- }
-
- dat->hwndHelpDlg = GetParent(hwndDlg);
- SendMessage(hwndDlg, VARM_PARSE, 0, 0);
- SetTimer(hwndDlg, IDT_PARSE, 1000, NULL);
-
- SetFocus(GetDlgItem(hwndDlg, IDC_TESTSTRING));
- break;
-
- case DM_SPLITTERMOVED:
- {
- POINT pt;
- RECT rc, rcTeststring, rcResult;
- int oldSplitterY;
-
- if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SPLITTER)) {
- GetClientRect(hwndDlg, &rc);
- pt.x = 0;
- pt.y = wParam;
- ScreenToClient(hwndDlg, &pt);
- oldSplitterY = dat->splitterPos;
- dat->splitterPos = rc.bottom - pt.y + 223;
- GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rcTeststring);
- GetWindowRect(GetDlgItem(hwndDlg, IDC_RESULT), &rcResult);
- if ((((rcTeststring.bottom - rcTeststring.top) - (dat->splitterPos - oldSplitterY)) < dat->minInputSize.y) || (((rcResult.bottom - rcResult.top) + (dat->splitterPos - oldSplitterY)) < dat->minResultSize.y))
- dat->splitterPos = oldSplitterY;
- } }
-
- SendMessage(hwndDlg, WM_SIZE, 0, 0);
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_TESTSTRING:
- if (HIWORD(wParam) == EN_CHANGE)
- SendMessage(hwndDlg, VARM_PARSE, 0, 0);
- break;
- }
- break;
-
- case WM_GETMINMAXINFO:
- {
- RECT rc, rcTeststring;
- GetWindowRect(GetParent(hwndDlg), &rc);
- GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rcTeststring);
- ((MINMAXINFO*)lParam)->ptMinTrackSize.y = (rc.bottom - rc.top) - (((rcTeststring.bottom - rcTeststring.top) - dat->minResultSize.y));
- }
- break;
-
- case WM_SIZE:
- if (!IsIconic(hwndDlg)) {
- UTILRESIZEDIALOG urd = { 0 };
- urd.cbSize = sizeof(urd);
- urd.hInstance = hInst;
- urd.hwndDlg = hwndDlg;
- urd.lParam = (LPARAM)dat;
- urd.lpTemplate = MAKEINTRESOURCEA(IDD_INPUT_DIALOG);
- urd.pfnResizer = inputDialogResize;
- CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
- }
- SendMessage(hwndDlg, WM_MOVE, 0, 0);
- break;
-
- case WM_SHOWWINDOW:
- if (wParam)
- SendMessage(hwndDlg, VARM_PARSE, 0, 0);
- break;
-
- case WM_NOTIFY:
- break;
-
- case VARM_PARSE:
- {
- TCHAR *string = Hlp_GetDlgItemText(hwndDlg, IDC_TESTSTRING), *extraText;
- int len = SendMessage(GetParent(hwndDlg), VARM_GETEXTRATEXTLENGTH, 0, 0);
- if (len > 0) {
- extraText = (TCHAR*)mir_calloc((len + 1)* sizeof(TCHAR));
- SendMessage(GetParent(hwndDlg), VARM_GETEXTRATEXT, (WPARAM)len + 1, (LPARAM)extraText);
- }
- else extraText = NULL;
-
- if (string != NULL) {
- TCHAR *newString = variables_parsedup(string, extraText, (MCONTACT)SendMessage(GetParent(hwndDlg), VARM_GETSUBJECT, 0, 0));
- if (newString != NULL) {
- TCHAR *oldString = Hlp_GetDlgItemText(hwndDlg, IDC_RESULT);
- if (oldString == NULL || _tcscmp(oldString, newString))
- SetWindowText(GetDlgItem(hwndDlg, IDC_RESULT), newString);
-
- mir_free(newString);
- if (oldString != NULL)
- mir_free(oldString);
- }
- mir_free(string);
- }
- }
- break;
-
- case VARM_SETINPUTTEXT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(GetDlgItem(hwndDlg, IDC_TESTSTRING), WM_SETTEXT, wParam, lParam));
- return TRUE;
-
- case VARM_GETINPUTTEXTLENGTH:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(GetDlgItem(hwndDlg, IDC_TESTSTRING), WM_GETTEXTLENGTH, wParam, lParam));
- return TRUE;
-
- case VARM_GETINPUTTEXT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(GetDlgItem(hwndDlg, IDC_TESTSTRING), WM_GETTEXT, wParam, lParam));
- return TRUE;
-
- case WM_TIMER:
- SendMessage(hwndDlg, VARM_PARSE, 0, 0);
- break;
-
- case WM_DESTROY:
- KillTimer(hwndDlg, IDT_PARSE);
- db_set_dw(NULL, MODULENAME, SETTING_SPLITTERPOS, dat->splitterPos);
- if (dat != NULL) {
- mir_free(dat);
- dat = NULL;
- }
- break;
- }
-
- return FALSE;
-}
-
-// help info dialog
-static INT_PTR CALLBACK helpInfoDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
-{
- switch(msg) {
- case WM_INITDIALOG:
- SetDlgItemText(hwndDlg, IDC_HELPDESC, VAR_HELP_TEXT);
- TranslateDialogDefault(hwndDlg);
- break;
-
- case WM_SIZE:
- if (!IsIconic( hwndDlg )) {
- UTILRESIZEDIALOG urd = { 0 };
- urd.cbSize = sizeof(urd);
- urd.hInstance = hInst;
- urd.hwndDlg = hwndDlg;
- urd.lParam = 0;
- urd.lpTemplate = MAKEINTRESOURCEA(IDD_HELPINFO_DIALOG);
- urd.pfnResizer = defaultHelpDialogResize;
- CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
-
- SendMessage(hwndDlg, WM_MOVE, 0, 0);
- }
- break;
- }
-
- return FALSE;
-}
-
-// the parent page (tabs)
-static int helpDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc)
-{
- INPUTDLGDATA *dat = (INPUTDLGDATA *)lParam;
- switch(urc->wId) {
- case IDC_OK:
- case IDC_CANCEL:
- return RD_ANCHORX_RIGHT|RD_ANCHORY_BOTTOM;
- }
- return RD_ANCHORX_WIDTH|RD_ANCHORY_HEIGHT;
-}
-
-static INT_PTR CALLBACK helpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
-{
- HELPDLGDATA *dat = (HELPDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
-
- switch(msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- {
- hwndHelpDialog = hwndDlg;
- dat = (HELPDLGDATA*)mir_calloc(sizeof(HELPDLGDATA));
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
- dat->vhs = (VARHELPINFO *)lParam;
-
- // set tabs
- int tabCount = 0;
- RECT rcTabs, rcParent;
- HWND hTab = GetDlgItem(hwndDlg, IDC_TABS);
- GetWindowRect(hTab, &rcTabs);
- GetWindowRect(hwndDlg, &rcParent);
-
- TCITEM tci = { 0 };
- HWND hPage, hShow = 0;
- if (dat->vhs->flags&VHF_TOKENS) {
- // token tab
- tci.mask = TCIF_TEXT | TCIF_PARAM;
- tci.pszText = TranslateT("Tokens");
- hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_TOKENS_DIALOG), hwndDlg, tokenHelpDlgProc, (LPARAM)GetParent(hwndDlg));
- EnableThemeDialogTexture(hPage, ETDT_ENABLETAB);
-
- tci.lParam = (LPARAM)hPage;
- MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE);
- ShowWindow(hPage, SW_HIDE);
- TabCtrl_InsertItem(hTab, tabCount++, &tci);
- hShow = hShow == 0 ? hPage : hShow;
- }
- if (dat->vhs->flags&VHF_INPUT) {
- // input tab
- tci.mask = TCIF_TEXT | TCIF_PARAM;
- tci.pszText = TranslateT("Input");
- dat->hwndInputDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_INPUT_DIALOG), hwndDlg, inputDlgProc, (LPARAM)GetParent(hwndDlg));
- EnableThemeDialogTexture(hPage, ETDT_ENABLETAB);
-
- tci.lParam = (LPARAM)hPage;
- MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE);
- ShowWindow(hPage, SW_HIDE);
- TabCtrl_InsertItem(hTab, tabCount++, &tci);
- hShow = hShow == 0 ? hPage : hShow;
- if ((dat->vhs->fi != NULL) && (dat->vhs->fi->szFormat != NULL)) {
- if (dat->vhs->fi->flags & FIF_UNICODE)
- SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)dat->vhs->fi->tszFormat);
- else {
-
- WCHAR *wszFormatString = mir_a2t(dat->vhs->fi->szFormat);
- SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)wszFormatString);
- mir_free(wszFormatString);
-
- }
- }
- else if (dat->vhs->hwndCtrl != NULL) {
- TCHAR *tszText = Hlp_GetWindowText(dat->vhs->hwndCtrl);
- if (tszText != NULL) {
- SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)tszText);
- mir_free(tszText);
- }
- }
- if (dat->vhs->fi != NULL || dat->vhs->hwndCtrl != NULL) {
- SetWindowText(GetDlgItem(hwndDlg, IDC_CANCEL), TranslateT("Cancel"));
- ShowWindow(GetDlgItem(hwndDlg, IDC_OK), SW_SHOW);
- }
- }
- if ((dat->vhs->flags&VHF_SUBJECT) ||
- ((dat->vhs->flags&VHF_INPUT) && (((dat->vhs->fi != NULL) && (dat->vhs->fi->hContact != NULL)) || (dat->vhs->flags&VHF_SETLASTSUBJECT)))) {
- // subject window is created, but not necessarily shown
- dat->hwndSubjectDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CLIST_DIALOG), hwndDlg, clistDlgProc, (LPARAM)GetParent(hwndDlg));
- EnableThemeDialogTexture(hPage, ETDT_ENABLETAB);
-
- MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE);
- ShowWindow(hPage, SW_HIDE);
-
- if ((dat->vhs->fi != NULL) && (dat->vhs->fi->hContact != NULL))
- SendMessage(hwndDlg, VARM_SETSUBJECT, (WPARAM)dat->vhs->fi->hContact, 0);
- else if (dat->vhs->flags&VHF_SETLASTSUBJECT)
- SendMessage(hwndDlg, VARM_SETSUBJECT, (WPARAM)INVALID_HANDLE_VALUE, 0);
-
- if (dat->vhs->flags&VHF_SUBJECT) {
- // create subject tab
- tci.lParam = (LPARAM)hPage;
- tci.mask = TCIF_TEXT | TCIF_PARAM;
- tci.pszText = TranslateT("%subject%");
- TabCtrl_InsertItem(hTab, tabCount++, &tci);
- hShow = hShow == 0 ? hPage : hShow;
- }
- }
- if ((dat->vhs->flags&VHF_EXTRATEXT) ||
- ((dat->vhs->flags&VHF_INPUT) && (dat->vhs->fi != NULL) && (dat->vhs->fi->tszExtraText != NULL))) {
- // extratext window is created, but not necessarily shown
- dat->hwndExtraTextDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EXTRATEXT_DIALOG), hwndDlg, extratextDlgProc, (LPARAM)GetParent(hwndDlg));
- EnableThemeDialogTexture(hPage, ETDT_ENABLETAB);
-
- MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE);
- ShowWindow(hPage, SW_HIDE);
- if ((dat->vhs->fi != NULL) && (dat->vhs->fi->tszExtraText != NULL)) {
- if (dat->vhs->fi->flags & FIF_UNICODE)
- SendMessage(hwndDlg, VARM_SETEXTRATEXT, 0, (LPARAM)dat->vhs->fi->tszExtraText);
- else {
-
- WCHAR *wszSource = mir_a2t(dat->vhs->fi->szExtraText);
- SendMessage(hwndDlg, VARM_SETEXTRATEXT, 0, (LPARAM)wszSource);
- mir_free(wszSource);
-
- }
- }
- if (dat->vhs->flags&VHF_EXTRATEXT) {
- // create extratext tab
- tci.mask = TCIF_TEXT | TCIF_PARAM;
- tci.pszText = TranslateT("%extratext%");
- tci.lParam = (LPARAM)hPage;
- TabCtrl_InsertItem(hTab, tabCount++, &tci);
- hShow = hShow == 0 ? hPage : hShow;
- }
- }
- if (dat->vhs->flags&VHF_HELP) {
- // helpinfo tab
- tci.mask = TCIF_TEXT | TCIF_PARAM;
- tci.pszText = TranslateT("Help");
- hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_HELPINFO_DIALOG), hwndDlg, helpInfoDlgProc, (LPARAM)GetParent(hwndDlg));
- EnableThemeDialogTexture(hPage, ETDT_ENABLETAB);
-
- tci.lParam = (LPARAM)hPage;
- MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE);
- ShowWindow(hPage, SW_HIDE);
- TabCtrl_InsertItem(hTab, tabCount++, &tci);
- hShow = hShow == 0 ? hPage : hShow;
- }
- Utils_RestoreWindowPositionNoMove(hwndDlg, NULL, MODULENAME, "help");
- SetWindowText(hwndDlg, TranslateT("Variables Help"));
- ShowWindow(hShow, SW_SHOW);
- break;
- }
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_OK:
- if ((dat->vhs->fi != NULL) && (!(dat->vhs->flags&VHF_DONTFILLSTRUCT))) {
- int len = SendMessage(hwndDlg, VARM_GETINPUTTEXTLENGTH, 0, 0);
- if (len > 0) {
- if ((dat->vhs->fi != NULL) && (!(dat->vhs->flags&VHF_DONTFILLSTRUCT))) {
- if (dat->vhs->fi->flags&FIF_UNICODE) {
- dat->vhs->fi->tszFormat = (TCHAR*)mir_calloc((len + 1)*sizeof(WCHAR));
- SendMessage(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->tszFormat);
- }
- else {
- dat->vhs->fi->szFormat = (char*)mir_calloc(len + 1);
- SendMessageA(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->szFormat);
- }
- }
- }
- }
-
- if (dat->vhs->hwndCtrl != NULL) {
- int len = SendMessage(hwndDlg, VARM_GETINPUTTEXTLENGTH, 0, 0);
- if (len > 0) {
- TCHAR *tszText;
-
- tszText = (TCHAR*)mir_calloc((len + 1)*sizeof(TCHAR));
- if (tszText != NULL) {
- SendMessage(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len + 1, (LPARAM)tszText);
- SetWindowText(dat->vhs->hwndCtrl, tszText);
- mir_free(tszText);
- }
- }
- SendMessage(GetParent(dat->vhs->hwndCtrl),
- WM_COMMAND,
- MAKEWPARAM(GetDlgCtrlID(dat->vhs->hwndCtrl),
- EN_CHANGE),
- (LPARAM)dat->vhs->hwndCtrl);
- }
-
- if ((dat->vhs->flags&VHF_FULLFILLSTRUCT) && (dat->vhs->fi != NULL)) {
- int len = SendMessage(hwndDlg, VARM_GETEXTRATEXTLENGTH, 0, 0);
- if (len > 0) {
- if (dat->vhs->fi->flags&FIF_UNICODE) {
- dat->vhs->fi->tszExtraText = (TCHAR*)mir_calloc((len + 1)*sizeof(WCHAR));
- SendMessage(hwndDlg, VARM_GETEXTRATEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->tszExtraText);
- }
- else {
- dat->vhs->fi->szExtraText = (char*)mir_calloc(len + 1);
- SendMessageA(hwndDlg, VARM_GETEXTRATEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->szExtraText);
- }
- }
- dat->vhs->fi->hContact = (MCONTACT)SendMessage(hwndDlg, VARM_GETSUBJECT, 0, 0);
- }
- // fall through
-
- case IDC_CANCEL:
- if (GetParent(hwndDlg) == NULL)
- DestroyWindow(hwndDlg);
- else
- EndDialog(hwndDlg, 0);
- break;
- }
- break;
-
- case VARM_SETSUBJECT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(dat->hwndSubjectDlg, VARM_SETSUBJECT, wParam, lParam));
- return TRUE;
-
- case VARM_GETSUBJECT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(dat->hwndSubjectDlg, VARM_GETSUBJECT, wParam, lParam));
- return TRUE;
-
- case VARM_SETEXTRATEXT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(dat->hwndExtraTextDlg, VARM_SETEXTRATEXT, wParam, lParam));
- return TRUE;
-
- case VARM_GETEXTRATEXTLENGTH:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(dat->hwndExtraTextDlg, VARM_GETEXTRATEXTLENGTH, wParam, lParam));
- return TRUE;
-
- case VARM_GETEXTRATEXT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(dat->hwndExtraTextDlg, VARM_GETEXTRATEXT, wParam, lParam));
- return TRUE;
-
- case VARM_SETINPUTTEXT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(dat->hwndInputDlg, VARM_SETINPUTTEXT, wParam, lParam));
- return TRUE;
-
- case VARM_GETINPUTTEXTLENGTH:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(dat->hwndInputDlg, VARM_GETINPUTTEXTLENGTH, wParam, lParam));
- return TRUE;
-
- case VARM_GETINPUTTEXT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
- SendMessage(dat->hwndInputDlg, VARM_GETINPUTTEXT, wParam, lParam));
- return TRUE;
-
- case VARM_GETDIALOG:
- switch (wParam) {
- case VHF_INPUT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)dat->hwndInputDlg);
- return TRUE;
- }
- break;
-
- case WM_GETMINMAXINFO:
- {
- int i, count;
- TCITEM tci;
- RECT rcParent;
- HWND hTab;
- MINMAXINFO pageMinMax;
-
- GetWindowRect(hwndDlg, &rcParent);
- // defaults
- ((MINMAXINFO*)lParam)->ptMinTrackSize.x = 400;
- ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 400;
- hTab = GetDlgItem(hwndDlg, IDC_TABS);
- tci.mask = TCIF_PARAM;
- count = TabCtrl_GetItemCount(hTab);
- // return the largest of all pages
- for (i = 0; i < count; i++) {
- TabCtrl_GetItem(hTab, i, &tci);
- ZeroMemory(&pageMinMax, sizeof(pageMinMax));
- SendMessage((HWND)tci.lParam, WM_GETMINMAXINFO, wParam, (LPARAM)&pageMinMax);
- ((MINMAXINFO*)lParam)->ptMinTrackSize.x = max(((MINMAXINFO*)lParam)->ptMinTrackSize.x, pageMinMax.ptMinTrackSize.x);
- ((MINMAXINFO*)lParam)->ptMinTrackSize.y = max(((MINMAXINFO*)lParam)->ptMinTrackSize.y, pageMinMax.ptMinTrackSize.y);
- }
- }
- break;
-
- case WM_SIZE:
- if (!IsIconic(hwndDlg)) {
- UTILRESIZEDIALOG urd = { 0 };
- urd.cbSize = sizeof(urd);
- urd.hInstance = hInst;
- urd.hwndDlg = hwndDlg;
- urd.lParam = 0;
- // ! uses ANSI version !
- urd.lpTemplate = MAKEINTRESOURCEA(IDD_HELP_DIALOG);
- urd.pfnResizer = helpDialogResize;
- CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
-
- SendMessage(hwndDlg, WM_MOVE, 0, 0);
-
- RECT rcTabs, rcParent;
- HWND hTab = GetDlgItem(hwndDlg, IDC_TABS);
- GetWindowRect(hTab, &rcTabs);
- GetWindowRect(hwndDlg, &rcParent);
-
- TCITEM tci;
- tci.mask = TCIF_PARAM;
- int count = TabCtrl_GetItemCount(hTab);
- for (int i = 0; i < count; i++) {
- TabCtrl_GetItem(GetDlgItem(hwndDlg, IDC_TABS), i, &tci);
- MoveWindow((HWND)tci.lParam, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE);
- }
- }
- break;
-
- case WM_NOTIFY:
- if ((((NMHDR*)lParam)->idFrom == IDC_TABS)) {
- if (((NMHDR*)lParam)->code == TCN_SELCHANGING) {
- TCITEM tci;
-
- tci.mask = TCIF_PARAM;
- TabCtrl_GetItem(GetDlgItem(hwndDlg, IDC_TABS), TabCtrl_GetCurSel(GetDlgItem(hwndDlg, IDC_TABS)), &tci);
- ShowWindow((HWND)tci.lParam, SW_HIDE);
- }
- else if (((NMHDR*)lParam)->code == TCN_SELCHANGE) {
- TCITEM tci;
-
- tci.mask = TCIF_PARAM;
- TabCtrl_GetItem(GetDlgItem(hwndDlg, IDC_TABS), TabCtrl_GetCurSel(GetDlgItem(hwndDlg, IDC_TABS)), &tci);
- ShowWindow((HWND)tci.lParam, SW_SHOW);
- }
- }
- break;
-
- case WM_CLOSE:
- if (GetParent(hwndDlg) == NULL)
- DestroyWindow(hwndDlg);
- else
- EndDialog(hwndDlg, 0);
- break;
-
- case WM_DESTROY:
- Utils_SaveWindowPosition(hwndDlg, NULL, MODULENAME, "help");
-
- HWND hTab = GetDlgItem(hwndDlg, IDC_TABS);
-
- TCITEM tci;
- tci.mask = TCIF_PARAM;
- int count = TabCtrl_GetItemCount(hTab);
- for (int i = 0; i < count; i++) {
- TabCtrl_GetItem(hTab, i, &tci);
- if (((HWND)tci.lParam != dat->hwndSubjectDlg) && ((HWND)tci.lParam != dat->hwndExtraTextDlg))
- DestroyWindow((HWND)tci.lParam);
- }
-
- // these windows might have been created, but not inserted as tabs
- if (IsWindow(dat->hwndSubjectDlg))
- DestroyWindow(dat->hwndSubjectDlg);
-
- if (IsWindow(dat->hwndExtraTextDlg))
- DestroyWindow(dat->hwndExtraTextDlg);
-
- mir_free(dat);
- dat = NULL;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
- break;
- }
-
- return FALSE;
-}
-
-INT_PTR showHelpExService(WPARAM wParam, LPARAM lParam)
-{
- if (IsWindow(hwndHelpDialog)) {
- SetFocus(hwndHelpDialog);
- return 0;
- }
- if (lParam == 0)
- return -1;
-
- iFrameX = GetSystemMetrics(SM_CXSIZEFRAME);
- iFrameY = 3 * GetSystemMetrics(SM_CYSIZEFRAME);
-
- if (wParam)
- DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_HELP_DIALOG), (HWND)wParam, helpDlgProc, (LPARAM)lParam);
- else
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_HELP_DIALOG), NULL, helpDlgProc, (LPARAM)lParam);
-
- return 0;
-}
-
-INT_PTR showHelpService(WPARAM wParam, LPARAM lParam)
-{
- static VARHELPINFO *vhs = NULL;
- static FORMATINFO *fi = NULL;
-
- if (fi == NULL)
- fi = (FORMATINFO*)mir_alloc(sizeof(FORMATINFO));
-
- ZeroMemory(fi, sizeof(FORMATINFO));
- fi->cbSize = sizeof(FORMATINFO);
- fi->szFormat = (char *)lParam;
- if (vhs == NULL)
- vhs = (VARHELPINFO*)mir_alloc(sizeof(VARHELPINFO));
-
- ZeroMemory(vhs, sizeof(VARHELPINFO));
- vhs->cbSize = sizeof(VARHELPINFO);
- vhs->fi = fi;
- vhs->hwndCtrl = (HWND)wParam;
- vhs->flags = VHF_FULLDLG | VHF_DONTFILLSTRUCT;
-
- return showHelpExService(0, (LPARAM)vhs);
-}
-
-INT_PTR getSkinItemService(WPARAM wParam, LPARAM lParam)
-{
- int item = lParam;
- if (item == 0)
- return (INT_PTR)NULL;
-
- switch (item) {
- case VSI_HELPICON:
- if (hHelpIcon == NULL)
- hHelpIcon = Skin_GetIcon("vars_help");
- return (INT_PTR)hHelpIcon;
-
- case VSI_HELPTIPTEXT:
- return (INT_PTR)Translate("Open String Formatting Help");
- }
-
- return (INT_PTR)NULL;
-}
-
-int iconsChanged(WPARAM wParam, LPARAM lParam)
-{
- hHelpIcon = NULL;
- return 0;
-}
+/* + Variables Plugin for Miranda-IM (www.miranda-im.org) + Copyright 2003-2006 P. Boon + + 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 "variables.h" + +struct HELPDLGDATA +{ + VARHELPINFO *vhs; + HWND hwndSubjectDlg; + HWND hwndExtraTextDlg; + HWND hwndInputDlg; +}; + +static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam); + +extern HINSTANCE hInst; + +extern HCURSOR hCurSplitNS; + +static HWND hwndHelpDialog = NULL; + +static HICON hHelpIcon = NULL; + +static int defaultHelpDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc) { + + switch(urc->wId) { + case IDC_ABOUT: + case IDC_ABOUTFRAME: + return RD_ANCHORX_WIDTH|RD_ANCHORY_TOP; + } + + return RD_ANCHORX_WIDTH|RD_ANCHORY_HEIGHT; +} + +// dialog box for the %extratext% input +static INT_PTR CALLBACK extratextDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) { + + switch(msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + break; + + case VARM_SETEXTRATEXT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(GetDlgItem(hwndDlg, IDC_EXTRATEXT), WM_SETTEXT, wParam, lParam)); + return TRUE; + + case VARM_GETEXTRATEXTLENGTH: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(GetDlgItem(hwndDlg, IDC_EXTRATEXT), WM_GETTEXTLENGTH, wParam, lParam)); + return TRUE; + + case VARM_GETEXTRATEXT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(GetDlgItem(hwndDlg, IDC_EXTRATEXT), WM_GETTEXT, wParam, lParam)); + return TRUE; + + case WM_SIZE: + if (!IsIconic( hwndDlg )) { + UTILRESIZEDIALOG urd = { 0 }; + urd.cbSize = sizeof(urd); + urd.hInstance = hInst; + urd.hwndDlg = hwndDlg; + urd.lpTemplate = MAKEINTRESOURCEA(IDD_EXTRATEXT_DIALOG); + urd.pfnResizer = defaultHelpDialogResize; + CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); + + SendMessage(hwndDlg, WM_MOVE, 0, 0); + } + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_EXTRATEXT: + SendMessage(GetParent(hwndDlg), VARM_PARSE, 0, 0); + break; + } + break; + } + + return FALSE; +} + +// dialog box for the %subject% selection +void ResetCList(HWND hwndDlg) +{ + if ((CallService(MS_CLUI_GETCAPS, 0, 0) & CLUIF_DISABLEGROUPS && !db_get_b(NULL, "CList", "UseGroups", SETTING_USEGROUPS_DEFAULT)) || !(GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE)&CLS_USEGROUPS)) + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETUSEGROUPS, FALSE, 0); + else + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETUSEGROUPS, TRUE, 0); + + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SETHIDEEMPTYGROUPS, 1, 0); +} + +static int clistDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc) +{ + switch (urc->wId) { + case IDC_ABOUT: + case IDC_ABOUTFRAME: + return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP; + + case IDC_NULL: + case IDC_CONTACT: + return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; + } + + return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT; +} + +static INT_PTR CALLBACK clistDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch(msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE, (GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_CLIST), GWL_STYLE) | (CLS_SHOWHIDDEN) | (CLS_NOHIDEOFFLINE)) & ~CLS_CHECKBOXES & ~CLS_USEGROUPS ); + ResetCList(hwndDlg); + CheckRadioButton(hwndDlg, IDC_NULL, IDC_CONTACT, IDC_NULL); + EnableWindow(GetDlgItem(hwndDlg, IDC_CLIST), IsDlgButtonChecked(hwndDlg, IDC_CONTACT)); + break; + + case VARM_SETSUBJECT: + { + LPARAM res = 0; + MCONTACT hItem, hContact = wParam; + log_debugA("VARM_SETSUBJECT: %u", hContact); + if (hContact == INVALID_CONTACT_ID) { + TCHAR *tszContact = db_get_tsa(NULL, MODULENAME, SETTING_SUBJECT); + log_debugA("VARM_SETSUBJECT: %s", tszContact); + if (tszContact != NULL) { + hContact = decodeContactFromString(tszContact); + log_debugA("VARM_SETSUBJECT decoded: %u", hContact); + mir_free(tszContact); + } } + + if ((hContact != INVALID_CONTACT_ID) && (hContact != NULL)) + hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); + else + hItem = NULL; + + if (hItem != NULL) + res = (LPARAM)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_SELECTITEM, (WPARAM)hItem, 0); + + CheckRadioButton(hwndDlg, IDC_NULL, IDC_CONTACT, hItem==NULL?IDC_NULL:IDC_CONTACT); + EnableWindow(GetDlgItem(hwndDlg, IDC_CLIST), IsDlgButtonChecked(hwndDlg, IDC_CONTACT)); + SetFocus(GetDlgItem(hwndDlg, IDC_CLIST)); + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)res); + } + return TRUE; + + case VARM_GETSUBJECT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + (IsDlgButtonChecked(hwndDlg, IDC_CONTACT) ? SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_GETSELECTION, 0, 0) : 0)); + return TRUE; + + case WM_SIZE: + if (!IsIconic(hwndDlg)) { + UTILRESIZEDIALOG urd = { sizeof(urd) }; + urd.hInstance = hInst; + urd.hwndDlg = hwndDlg; + urd.lParam = 0; + /* ! uses ANSI version ! */ + urd.lpTemplate = MAKEINTRESOURCEA(IDD_CLIST_DIALOG); + urd.pfnResizer = clistDialogResize; + CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); + + SendMessage(hwndDlg, WM_MOVE, 0, 0); + } + break; + + case WM_SHOWWINDOW: + if ((wParam) && (IsDlgButtonChecked(hwndDlg, IDC_CONTACT))) + SetFocus(GetDlgItem(hwndDlg, IDC_CLIST)); + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_NULL: + case IDC_CONTACT: + CheckRadioButton(hwndDlg, IDC_NULL, IDC_CONTACT, LOWORD(wParam)); + EnableWindow(GetDlgItem(hwndDlg, IDC_CLIST), IsDlgButtonChecked(hwndDlg, IDC_CONTACT)); + if (IsDlgButtonChecked(hwndDlg, IDC_CONTACT)) + SetFocus(GetDlgItem(hwndDlg, IDC_CLIST)); + break; + } + break; + + case WM_NOTIFY: + switch (((NMHDR *) lParam)->idFrom) { + case IDC_CLIST: + switch (((NMHDR *) lParam)->code) { + case CLN_OPTIONSCHANGED: + ResetCList(hwndDlg); + break; + } + break; + } + break; + + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + + case WM_DESTROY: + db_unset(NULL, MODULENAME, SETTING_SUBJECT); + + MCONTACT hContact = (MCONTACT)SendMessage(hwndDlg, VARM_GETSUBJECT, 0, 0); + if (hContact != NULL) { + TCHAR *tszContact = encodeContactToString(hContact); + if (tszContact != NULL) { + db_set_ts(NULL, MODULENAME, SETTING_SUBJECT, tszContact); + mir_free(tszContact); + } } + break; + } + + return FALSE; +} + +// dialog box for the tokens +static TCHAR *getTokenCategory(TOKENREGISTEREX *tr) { + if (tr == NULL) { + return NULL; + } + char *cat = NULL; + char *helpText = mir_strdup(tr->szHelpText); + if (helpText == NULL) { + return NULL; + } + char *cur = helpText; + while (*cur != 0) { + if (*cur == '\t') { + *cur = 0; + helpText = ( char* )mir_realloc(helpText, strlen(helpText)+1); + + TCHAR *res = mir_a2t(helpText); + mir_free(helpText); + return res; + } + cur++; + } + + TCHAR *res = mir_a2t(helpText); + mir_free(helpText); + return res; + +} + +static TCHAR *getHelpDescription(TOKENREGISTEREX *tr) +{ + if (tr == NULL) + return NULL; + + char *cur = tr->szHelpText + strlen(tr->szHelpText); + while (cur > tr->szHelpText) { + if (*cur == '\t') { + + cur = mir_strdup(cur+1); + TCHAR *res = mir_a2t(cur); + mir_free(cur); + return res; + + } + cur--; + } + + return mir_a2t(tr->szHelpText); + +} + +static TCHAR *getTokenDescription(TOKENREGISTEREX *tr) +{ + char *args, *first, *second; + + if (tr == NULL) + return NULL; + + args = NULL; + TCHAR *tArgs = NULL; + if (tr->szHelpText == NULL) + return mir_tstrdup(tr->tszTokenString); + + char *helpText = mir_strdup(tr->szHelpText); + if (helpText == NULL) + return NULL; + + char *cur = helpText; + first = second = NULL; + while (*cur != 0) { + if (*cur == '\t') { + if (first == NULL) + first = cur; + else if (second == NULL) + second = cur; + } + cur++; + } + + if ((first != NULL) && (second != NULL)) { + *second = 0; + args = first+1; + } + else args = NULL; + + size_t len = _tcslen(tr->tszTokenString) + (args!=NULL?strlen(args):0) + 3; + TCHAR *desc = (TCHAR*)mir_calloc(len * sizeof(TCHAR)); + if (desc == NULL) + return NULL; + + if (tr->flags&TRF_FIELD) + mir_sntprintf(desc, len, _T("%c%s%c"), FIELD_CHAR, tr->szTokenString, FIELD_CHAR); + else { + if (args != NULL) + tArgs = mir_a2t(args); + + mir_sntprintf(desc, len, _T("%c%s%s"), FUNC_CHAR, tr->tszTokenString, (tArgs!=NULL?tArgs:_T(""))); + } + + mir_free(tArgs); + mir_free(helpText); + return desc; +} + +static int CALLBACK compareTokenHelp(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) +{ + TOKENREGISTEREX *tr1 = (TOKENREGISTEREX *)lParam1; + TOKENREGISTEREX *tr2 = (TOKENREGISTEREX *)lParam2; + if (tr1 == NULL || tr2 == NULL) + return 0; + + ptrT cat1(getTokenCategory(tr1)); + ptrT cat2(getTokenCategory(tr2)); + if (cat1 == NULL || cat2 == NULL) + return 0; + + int res = _tcscmp(cat1, cat2); + if (res != 0) + return res; + + if (tr1->tszTokenString == NULL || tr2->tszTokenString == NULL) + return 0; + + return _tcscmp(tr1->tszTokenString, tr2->tszTokenString); +} + +static BOOL CALLBACK processTokenListMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + /* hwndDlg must be a child of the help dialog */ + switch(msg) { + case WM_INITDIALOG: + { + TOKENREGISTEREX *tr; + TCHAR *tszTokenDesc, *tszHelpDesc, *last, *cat, *text; + + // token list things + HWND hList = GetDlgItem(hwndDlg, IDC_TOKENLIST); + + LVCOLUMN lvCol = { 0 }; + lvCol.mask = LVCF_TEXT; + lvCol.pszText = TranslateT("Token"); + ListView_InsertColumn(hList, 0, &lvCol); + + lvCol.pszText = TranslateT("Description"); + ListView_InsertColumn(hList, 1, &lvCol); + + HELPDLGDATA *hdd = (HELPDLGDATA *)GetWindowLongPtr(GetParent(hwndDlg), GWLP_USERDATA); + int i = -1; + do { + i += 1; + tszHelpDesc = tszTokenDesc = NULL; + tr = getTokenRegister(i); + if ((tr == NULL) || (tr->tszTokenString == NULL)) + continue; + + else if (hdd != NULL) { + if (!_tcscmp(tr->tszTokenString, SUBJECT)) { + if (hdd->vhs->flags&VHF_HIDESUBJECTTOKEN) + continue; + + if (hdd->vhs->szSubjectDesc != NULL) + tszHelpDesc = mir_a2t(hdd->vhs->szSubjectDesc); + } + if (!_tcscmp(tr->tszTokenString, MIR_EXTRATEXT)) { + if (hdd->vhs->flags & VHF_HIDEEXTRATEXTTOKEN) + continue; + + if (hdd->vhs->szExtraTextDesc != NULL) + tszHelpDesc = mir_a2t(hdd->vhs->szExtraTextDesc); + } + } + + LVITEM lvItem = { 0 }; + lvItem.mask = LVIF_TEXT | LVIF_PARAM; + lvItem.iItem = ListView_GetItemCount(hList); + lvItem.lParam = (LPARAM)tr; + tszTokenDesc = getTokenDescription(tr); + if (tszTokenDesc == NULL) + continue; + + lvItem.pszText = tszTokenDesc; + ListView_InsertItem(hList, &lvItem); + mir_free(tszTokenDesc); + + lvItem.mask = LVIF_TEXT; + if (tszHelpDesc == NULL) + tszHelpDesc = getHelpDescription(tr); + + if (tszHelpDesc == NULL) + tszHelpDesc = mir_tstrdup(_T("unknown")); + + lvItem.iSubItem = 1; + lvItem.pszText = TranslateTS(tszHelpDesc); + ListView_SetItem(hList, &lvItem); + mir_free(tszHelpDesc); + } + while (tr != NULL); + + ListView_SetColumnWidth(hList, 0, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hList, 1, LVSCW_AUTOSIZE); + ListView_SortItems(hList, compareTokenHelp, 0); + last = text = NULL; + for (i = 0; i < ListView_GetItemCount(hList); i++) { + LVITEM lvItem = { 0 }; + lvItem.mask = LVIF_PARAM; + lvItem.iItem = i; + if (ListView_GetItem(hList, &lvItem) == FALSE) + continue; + + cat = getTokenCategory((TOKENREGISTEREX *)lvItem.lParam); + if (cat != NULL) { + text = mir_tstrdup(TranslateTS(cat)); + mir_free(cat); + } + else text = NULL; + + if (text != NULL && (last == NULL || _tcsicmp(last, text))) { + lvItem.mask = LVIF_TEXT; + lvItem.pszText = text; + ListView_InsertItem(hList, &lvItem); + if (last != NULL) { + mir_free(last); + lvItem.iSubItem = 0; + lvItem.pszText = _T(""); + ListView_InsertItem(hList, &lvItem); + } + last = text; + } + else mir_free(text); + } + mir_free(last); + } + break; + + case WM_NOTIFY: + if ((((NMHDR*)lParam)->idFrom == IDC_TOKENLIST) && (((NMHDR*)lParam)->code == NM_DBLCLK)) { + HWND hwndInputDlg = (HWND)SendMessage(GetParent(hwndDlg), VARM_GETDIALOG, (WPARAM)VHF_INPUT, 0); + if (hwndInputDlg == NULL) + break; + + HWND hList = GetDlgItem(hwndDlg, IDC_TOKENLIST); + int item = ListView_GetNextItem(hList, -1, LVNI_SELECTED|LVNI_FOCUSED); + + LVITEM lvItem = { 0 }; + lvItem.mask = LVIF_PARAM; + lvItem.iItem = item; + if (ListView_GetItem(hList, &lvItem) == FALSE) + break; + + TOKENREGISTER *tr = (TOKENREGISTER *)lvItem.lParam; + if (tr == NULL) + break; + + size_t len = _tcslen(tr->tszTokenString) + 2; + if (len < 0) + break; + + TCHAR *tokenString = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR)); + if (tokenString == NULL) + break; + + ZeroMemory(tokenString, (len+1)*sizeof(TCHAR)); + mir_sntprintf(tokenString, len + 1, _T("%c%s%c"), (tr->flags & TRF_FIELD) ? FIELD_CHAR : FUNC_CHAR, tr->tszTokenString, (tr->flags & TRF_FIELD) ? FIELD_CHAR : '('); + SendDlgItemMessage(hwndInputDlg, IDC_TESTSTRING, EM_REPLACESEL, TRUE, (LPARAM)tokenString); + mir_free(tokenString); + SetFocus(GetDlgItem(hwndInputDlg, IDC_TESTSTRING)); + } + break; + } + + return FALSE; +} + +// "token only" dialog proc +static INT_PTR CALLBACK tokenHelpDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + processTokenListMessage(hwndDlg, msg, wParam, lParam); + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + break; + + case WM_SIZE: + if (!IsIconic(hwndDlg)) { + UTILRESIZEDIALOG urd = { 0 }; + urd.cbSize = sizeof(urd); + urd.hInstance = hInst; + urd.hwndDlg = hwndDlg; + urd.lpTemplate = MAKEINTRESOURCEA(IDD_TOKENS_DIALOG); + urd.pfnResizer = defaultHelpDialogResize; + CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); + + SendMessage(hwndDlg, WM_MOVE, 0, 0); + } + break; + } + + return FALSE; +} + +// token + input dialog proc +// from SRMM +static LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + RECT rc; + + switch (msg) { + case WM_NCHITTEST: + return HTCLIENT; + + case WM_SETCURSOR: + GetClientRect(hwnd, &rc); + //SetCursor(rc.right > rc.bottom ? hCurSplitNS : hCurSplitWE); + if (rc.right > rc.bottom) + SetCursor(hCurSplitNS); + + return TRUE; + + case WM_LBUTTONDOWN: + SetCapture(hwnd); + return 0; + + case WM_MOUSEMOVE: + if (GetCapture() == hwnd) { + GetClientRect(hwnd, &rc); + SendMessage(GetParent(hwnd), DM_SPLITTERMOVED, rc.right > rc.bottom ? (short)HIWORD(GetMessagePos()) + rc.bottom / 2 : (short)LOWORD(GetMessagePos()) + rc.right / 2, (LPARAM)hwnd); + } + return 0; + + case WM_LBUTTONUP: + ReleaseCapture(); + return 0; + } + return mir_callNextSubclass(hwnd, SplitterSubclassProc, msg, wParam, lParam); +} + +struct INPUTDLGDATA +{ + int splitterPos; + int originalSplitterPos; + POINT minInputSize; + POINT minResultSize; + HWND hwndHelpDlg; +}; + +static int iFrameX, iFrameY; + +static int inputDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc) +{ + INPUTDLGDATA *dat = (INPUTDLGDATA *)lParam; + + switch (urc->wId) { + case IDC_TOKENLIST: + return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP; + + case IDC_TESTSTRING: + urc->rcItem.bottom -= dat->splitterPos - dat->originalSplitterPos; + return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT; + + case IDC_SPLITTER: + urc->rcItem.top -= dat->splitterPos - dat->originalSplitterPos; + urc->rcItem.bottom -= dat->splitterPos - dat->originalSplitterPos; + return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; + + case IDC_RESULT: + urc->rcItem.top -= dat->splitterPos - dat->originalSplitterPos; + return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; + } + + return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; +} + +static INT_PTR CALLBACK inputDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + static INPUTDLGDATA *dat = (INPUTDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + processTokenListMessage(hwndDlg, msg, wParam, lParam); + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + dat = (INPUTDLGDATA*)mir_alloc(sizeof(INPUTDLGDATA)); + ZeroMemory(dat, sizeof(INPUTDLGDATA)); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); + // splitter things + dat->splitterPos = (INT_PTR)db_get_dw(NULL, MODULENAME, SETTING_SPLITTERPOS, -1); + { + RECT rc; + POINT pt; + GetWindowRect(GetDlgItem(hwndDlg, IDC_SPLITTER), &rc); + pt.y = (rc.top + rc.bottom) / 2; + pt.x = 0; + ScreenToClient(hwndDlg, &pt); + dat->originalSplitterPos = pt.y; + + if (dat->splitterPos == -1) + dat->splitterPos = dat->originalSplitterPos; + + GetWindowRect(GetDlgItem(hwndDlg, IDC_SHOWHELP), &rc); + mir_subclassWindow(GetDlgItem(hwndDlg, IDC_SPLITTER), SplitterSubclassProc); + + GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rc); + dat->minInputSize.x = rc.right - rc.left; + dat->minInputSize.y = rc.bottom - rc.top; + GetWindowRect(GetDlgItem(hwndDlg, IDC_RESULT), &rc); + dat->minResultSize.x = rc.right - rc.left; + dat->minResultSize.y = rc.bottom - rc.top; + } + + dat->hwndHelpDlg = GetParent(hwndDlg); + SendMessage(hwndDlg, VARM_PARSE, 0, 0); + SetTimer(hwndDlg, IDT_PARSE, 1000, NULL); + + SetFocus(GetDlgItem(hwndDlg, IDC_TESTSTRING)); + break; + + case DM_SPLITTERMOVED: + { + POINT pt; + RECT rc, rcTeststring, rcResult; + int oldSplitterY; + + if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SPLITTER)) { + GetClientRect(hwndDlg, &rc); + pt.x = 0; + pt.y = wParam; + ScreenToClient(hwndDlg, &pt); + oldSplitterY = dat->splitterPos; + dat->splitterPos = rc.bottom - pt.y + 223; + GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rcTeststring); + GetWindowRect(GetDlgItem(hwndDlg, IDC_RESULT), &rcResult); + if ((((rcTeststring.bottom - rcTeststring.top) - (dat->splitterPos - oldSplitterY)) < dat->minInputSize.y) || (((rcResult.bottom - rcResult.top) + (dat->splitterPos - oldSplitterY)) < dat->minResultSize.y)) + dat->splitterPos = oldSplitterY; + } } + + SendMessage(hwndDlg, WM_SIZE, 0, 0); + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_TESTSTRING: + if (HIWORD(wParam) == EN_CHANGE) + SendMessage(hwndDlg, VARM_PARSE, 0, 0); + break; + } + break; + + case WM_GETMINMAXINFO: + { + RECT rc, rcTeststring; + GetWindowRect(GetParent(hwndDlg), &rc); + GetWindowRect(GetDlgItem(hwndDlg, IDC_TESTSTRING), &rcTeststring); + ((MINMAXINFO*)lParam)->ptMinTrackSize.y = (rc.bottom - rc.top) - (((rcTeststring.bottom - rcTeststring.top) - dat->minResultSize.y)); + } + break; + + case WM_SIZE: + if (!IsIconic(hwndDlg)) { + UTILRESIZEDIALOG urd = { 0 }; + urd.cbSize = sizeof(urd); + urd.hInstance = hInst; + urd.hwndDlg = hwndDlg; + urd.lParam = (LPARAM)dat; + urd.lpTemplate = MAKEINTRESOURCEA(IDD_INPUT_DIALOG); + urd.pfnResizer = inputDialogResize; + CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); + } + SendMessage(hwndDlg, WM_MOVE, 0, 0); + break; + + case WM_SHOWWINDOW: + if (wParam) + SendMessage(hwndDlg, VARM_PARSE, 0, 0); + break; + + case WM_NOTIFY: + break; + + case VARM_PARSE: + { + TCHAR *string = Hlp_GetDlgItemText(hwndDlg, IDC_TESTSTRING), *extraText; + int len = SendMessage(GetParent(hwndDlg), VARM_GETEXTRATEXTLENGTH, 0, 0); + if (len > 0) { + extraText = (TCHAR*)mir_calloc((len + 1)* sizeof(TCHAR)); + SendMessage(GetParent(hwndDlg), VARM_GETEXTRATEXT, (WPARAM)len + 1, (LPARAM)extraText); + } + else extraText = NULL; + + if (string != NULL) { + TCHAR *newString = variables_parsedup(string, extraText, (MCONTACT)SendMessage(GetParent(hwndDlg), VARM_GETSUBJECT, 0, 0)); + if (newString != NULL) { + TCHAR *oldString = Hlp_GetDlgItemText(hwndDlg, IDC_RESULT); + if (oldString == NULL || _tcscmp(oldString, newString)) + SetWindowText(GetDlgItem(hwndDlg, IDC_RESULT), newString); + + mir_free(newString); + if (oldString != NULL) + mir_free(oldString); + } + mir_free(string); + } + } + break; + + case VARM_SETINPUTTEXT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(GetDlgItem(hwndDlg, IDC_TESTSTRING), WM_SETTEXT, wParam, lParam)); + return TRUE; + + case VARM_GETINPUTTEXTLENGTH: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(GetDlgItem(hwndDlg, IDC_TESTSTRING), WM_GETTEXTLENGTH, wParam, lParam)); + return TRUE; + + case VARM_GETINPUTTEXT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(GetDlgItem(hwndDlg, IDC_TESTSTRING), WM_GETTEXT, wParam, lParam)); + return TRUE; + + case WM_TIMER: + SendMessage(hwndDlg, VARM_PARSE, 0, 0); + break; + + case WM_DESTROY: + KillTimer(hwndDlg, IDT_PARSE); + if (dat == NULL) + break; + db_set_dw(NULL, MODULENAME, SETTING_SPLITTERPOS, dat->splitterPos); + mir_free(dat); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + break; + } + + return FALSE; +} + +// help info dialog +static INT_PTR CALLBACK helpInfoDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch(msg) { + case WM_INITDIALOG: + SetDlgItemText(hwndDlg, IDC_HELPDESC, VAR_HELP_TEXT); + TranslateDialogDefault(hwndDlg); + break; + + case WM_SIZE: + if (!IsIconic( hwndDlg )) { + UTILRESIZEDIALOG urd = { 0 }; + urd.cbSize = sizeof(urd); + urd.hInstance = hInst; + urd.hwndDlg = hwndDlg; + urd.lParam = 0; + urd.lpTemplate = MAKEINTRESOURCEA(IDD_HELPINFO_DIALOG); + urd.pfnResizer = defaultHelpDialogResize; + CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); + + SendMessage(hwndDlg, WM_MOVE, 0, 0); + } + break; + } + + return FALSE; +} + +// the parent page (tabs) +static int helpDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc) +{ + INPUTDLGDATA *dat = (INPUTDLGDATA *)lParam; + switch(urc->wId) { + case IDC_OK: + case IDC_CANCEL: + return RD_ANCHORX_RIGHT|RD_ANCHORY_BOTTOM; + } + return RD_ANCHORX_WIDTH|RD_ANCHORY_HEIGHT; +} + +static INT_PTR CALLBACK helpDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + HELPDLGDATA *dat = (HELPDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + switch(msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + { + hwndHelpDialog = hwndDlg; + dat = (HELPDLGDATA*)mir_calloc(sizeof(HELPDLGDATA)); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); + dat->vhs = (VARHELPINFO *)lParam; + + // set tabs + int tabCount = 0; + RECT rcTabs, rcParent; + HWND hTab = GetDlgItem(hwndDlg, IDC_TABS); + GetWindowRect(hTab, &rcTabs); + GetWindowRect(hwndDlg, &rcParent); + + TCITEM tci = { 0 }; + HWND hPage, hShow = 0; + if (dat->vhs->flags&VHF_TOKENS) { + // token tab + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("Tokens"); + hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_TOKENS_DIALOG), hwndDlg, tokenHelpDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); + + tci.lParam = (LPARAM)hPage; + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); + TabCtrl_InsertItem(hTab, tabCount++, &tci); + hShow = hShow == 0 ? hPage : hShow; + } + if (dat->vhs->flags&VHF_INPUT) { + // input tab + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("Input"); + dat->hwndInputDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_INPUT_DIALOG), hwndDlg, inputDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); + + tci.lParam = (LPARAM)hPage; + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); + TabCtrl_InsertItem(hTab, tabCount++, &tci); + hShow = hShow == 0 ? hPage : hShow; + if ((dat->vhs->fi != NULL) && (dat->vhs->fi->szFormat != NULL)) { + if (dat->vhs->fi->flags & FIF_UNICODE) + SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)dat->vhs->fi->tszFormat); + else { + + WCHAR *wszFormatString = mir_a2t(dat->vhs->fi->szFormat); + SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)wszFormatString); + mir_free(wszFormatString); + + } + } + else if (dat->vhs->hwndCtrl != NULL) { + TCHAR *tszText = Hlp_GetWindowText(dat->vhs->hwndCtrl); + if (tszText != NULL) { + SendMessage(hwndDlg, VARM_SETINPUTTEXT, 0, (LPARAM)tszText); + mir_free(tszText); + } + } + if (dat->vhs->fi != NULL || dat->vhs->hwndCtrl != NULL) { + SetWindowText(GetDlgItem(hwndDlg, IDC_CANCEL), TranslateT("Cancel")); + ShowWindow(GetDlgItem(hwndDlg, IDC_OK), SW_SHOW); + } + } + if ((dat->vhs->flags&VHF_SUBJECT) || + ((dat->vhs->flags&VHF_INPUT) && (((dat->vhs->fi != NULL) && (dat->vhs->fi->hContact != NULL)) || (dat->vhs->flags&VHF_SETLASTSUBJECT)))) { + // subject window is created, but not necessarily shown + dat->hwndSubjectDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CLIST_DIALOG), hwndDlg, clistDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); + + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); + + if ((dat->vhs->fi != NULL) && (dat->vhs->fi->hContact != NULL)) + SendMessage(hwndDlg, VARM_SETSUBJECT, (WPARAM)dat->vhs->fi->hContact, 0); + else if (dat->vhs->flags&VHF_SETLASTSUBJECT) + SendMessage(hwndDlg, VARM_SETSUBJECT, (WPARAM)INVALID_HANDLE_VALUE, 0); + + if (dat->vhs->flags&VHF_SUBJECT) { + // create subject tab + tci.lParam = (LPARAM)hPage; + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("%subject%"); + TabCtrl_InsertItem(hTab, tabCount++, &tci); + hShow = hShow == 0 ? hPage : hShow; + } + } + if ((dat->vhs->flags&VHF_EXTRATEXT) || + ((dat->vhs->flags&VHF_INPUT) && (dat->vhs->fi != NULL) && (dat->vhs->fi->tszExtraText != NULL))) { + // extratext window is created, but not necessarily shown + dat->hwndExtraTextDlg = hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EXTRATEXT_DIALOG), hwndDlg, extratextDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); + + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); + if ((dat->vhs->fi != NULL) && (dat->vhs->fi->tszExtraText != NULL)) { + if (dat->vhs->fi->flags & FIF_UNICODE) + SendMessage(hwndDlg, VARM_SETEXTRATEXT, 0, (LPARAM)dat->vhs->fi->tszExtraText); + else { + + WCHAR *wszSource = mir_a2t(dat->vhs->fi->szExtraText); + SendMessage(hwndDlg, VARM_SETEXTRATEXT, 0, (LPARAM)wszSource); + mir_free(wszSource); + + } + } + if (dat->vhs->flags&VHF_EXTRATEXT) { + // create extratext tab + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("%extratext%"); + tci.lParam = (LPARAM)hPage; + TabCtrl_InsertItem(hTab, tabCount++, &tci); + hShow = hShow == 0 ? hPage : hShow; + } + } + if (dat->vhs->flags&VHF_HELP) { + // helpinfo tab + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = TranslateT("Help"); + hPage = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_HELPINFO_DIALOG), hwndDlg, helpInfoDlgProc, (LPARAM)GetParent(hwndDlg)); + EnableThemeDialogTexture(hPage, ETDT_ENABLETAB); + + tci.lParam = (LPARAM)hPage; + MoveWindow(hPage, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + ShowWindow(hPage, SW_HIDE); + TabCtrl_InsertItem(hTab, tabCount++, &tci); + hShow = hShow == 0 ? hPage : hShow; + } + Utils_RestoreWindowPositionNoMove(hwndDlg, NULL, MODULENAME, "help"); + SetWindowText(hwndDlg, TranslateT("Variables Help")); + ShowWindow(hShow, SW_SHOW); + break; + } + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_OK: + if ((dat->vhs->fi != NULL) && (!(dat->vhs->flags&VHF_DONTFILLSTRUCT))) { + int len = SendMessage(hwndDlg, VARM_GETINPUTTEXTLENGTH, 0, 0); + if (len > 0) { + if ((dat->vhs->fi != NULL) && (!(dat->vhs->flags&VHF_DONTFILLSTRUCT))) { + if (dat->vhs->fi->flags&FIF_UNICODE) { + dat->vhs->fi->tszFormat = (TCHAR*)mir_calloc((len + 1)*sizeof(WCHAR)); + SendMessage(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->tszFormat); + } + else { + dat->vhs->fi->szFormat = (char*)mir_calloc(len + 1); + SendMessageA(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->szFormat); + } + } + } + } + + if (dat->vhs->hwndCtrl != NULL) { + int len = SendMessage(hwndDlg, VARM_GETINPUTTEXTLENGTH, 0, 0); + if (len > 0) { + TCHAR *tszText; + + tszText = (TCHAR*)mir_calloc((len + 1)*sizeof(TCHAR)); + if (tszText != NULL) { + SendMessage(hwndDlg, VARM_GETINPUTTEXT, (WPARAM)len + 1, (LPARAM)tszText); + SetWindowText(dat->vhs->hwndCtrl, tszText); + mir_free(tszText); + } + } + SendMessage(GetParent(dat->vhs->hwndCtrl), + WM_COMMAND, + MAKEWPARAM(GetDlgCtrlID(dat->vhs->hwndCtrl), + EN_CHANGE), + (LPARAM)dat->vhs->hwndCtrl); + } + + if ((dat->vhs->flags&VHF_FULLFILLSTRUCT) && (dat->vhs->fi != NULL)) { + int len = SendMessage(hwndDlg, VARM_GETEXTRATEXTLENGTH, 0, 0); + if (len > 0) { + if (dat->vhs->fi->flags&FIF_UNICODE) { + dat->vhs->fi->tszExtraText = (TCHAR*)mir_calloc((len + 1)*sizeof(WCHAR)); + SendMessage(hwndDlg, VARM_GETEXTRATEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->tszExtraText); + } + else { + dat->vhs->fi->szExtraText = (char*)mir_calloc(len + 1); + SendMessageA(hwndDlg, VARM_GETEXTRATEXT, (WPARAM)len + 1, (LPARAM)dat->vhs->fi->szExtraText); + } + } + dat->vhs->fi->hContact = (MCONTACT)SendMessage(hwndDlg, VARM_GETSUBJECT, 0, 0); + } + // fall through + + case IDC_CANCEL: + if (GetParent(hwndDlg) == NULL) + DestroyWindow(hwndDlg); + else + EndDialog(hwndDlg, 0); + break; + } + break; + + case VARM_SETSUBJECT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(dat->hwndSubjectDlg, VARM_SETSUBJECT, wParam, lParam)); + return TRUE; + + case VARM_GETSUBJECT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(dat->hwndSubjectDlg, VARM_GETSUBJECT, wParam, lParam)); + return TRUE; + + case VARM_SETEXTRATEXT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(dat->hwndExtraTextDlg, VARM_SETEXTRATEXT, wParam, lParam)); + return TRUE; + + case VARM_GETEXTRATEXTLENGTH: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(dat->hwndExtraTextDlg, VARM_GETEXTRATEXTLENGTH, wParam, lParam)); + return TRUE; + + case VARM_GETEXTRATEXT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(dat->hwndExtraTextDlg, VARM_GETEXTRATEXT, wParam, lParam)); + return TRUE; + + case VARM_SETINPUTTEXT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(dat->hwndInputDlg, VARM_SETINPUTTEXT, wParam, lParam)); + return TRUE; + + case VARM_GETINPUTTEXTLENGTH: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(dat->hwndInputDlg, VARM_GETINPUTTEXTLENGTH, wParam, lParam)); + return TRUE; + + case VARM_GETINPUTTEXT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, + SendMessage(dat->hwndInputDlg, VARM_GETINPUTTEXT, wParam, lParam)); + return TRUE; + + case VARM_GETDIALOG: + switch (wParam) { + case VHF_INPUT: + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)dat->hwndInputDlg); + return TRUE; + } + break; + + case WM_GETMINMAXINFO: + { + int i, count; + TCITEM tci; + RECT rcParent; + HWND hTab; + MINMAXINFO pageMinMax; + + GetWindowRect(hwndDlg, &rcParent); + // defaults + ((MINMAXINFO*)lParam)->ptMinTrackSize.x = 400; + ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 400; + hTab = GetDlgItem(hwndDlg, IDC_TABS); + tci.mask = TCIF_PARAM; + count = TabCtrl_GetItemCount(hTab); + // return the largest of all pages + for (i = 0; i < count; i++) { + TabCtrl_GetItem(hTab, i, &tci); + ZeroMemory(&pageMinMax, sizeof(pageMinMax)); + SendMessage((HWND)tci.lParam, WM_GETMINMAXINFO, wParam, (LPARAM)&pageMinMax); + ((MINMAXINFO*)lParam)->ptMinTrackSize.x = max(((MINMAXINFO*)lParam)->ptMinTrackSize.x, pageMinMax.ptMinTrackSize.x); + ((MINMAXINFO*)lParam)->ptMinTrackSize.y = max(((MINMAXINFO*)lParam)->ptMinTrackSize.y, pageMinMax.ptMinTrackSize.y); + } + } + break; + + case WM_SIZE: + if (!IsIconic(hwndDlg)) { + UTILRESIZEDIALOG urd = { 0 }; + urd.cbSize = sizeof(urd); + urd.hInstance = hInst; + urd.hwndDlg = hwndDlg; + urd.lParam = 0; + // ! uses ANSI version ! + urd.lpTemplate = MAKEINTRESOURCEA(IDD_HELP_DIALOG); + urd.pfnResizer = helpDialogResize; + CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); + + SendMessage(hwndDlg, WM_MOVE, 0, 0); + + RECT rcTabs, rcParent; + HWND hTab = GetDlgItem(hwndDlg, IDC_TABS); + GetWindowRect(hTab, &rcTabs); + GetWindowRect(hwndDlg, &rcParent); + + TCITEM tci; + tci.mask = TCIF_PARAM; + int count = TabCtrl_GetItemCount(hTab); + for (int i = 0; i < count; i++) { + TabCtrl_GetItem(GetDlgItem(hwndDlg, IDC_TABS), i, &tci); + MoveWindow((HWND)tci.lParam, (rcTabs.left - rcParent.left), (rcTabs.top - rcParent.top), (rcTabs.right - rcTabs.left) - 2 * iFrameX, (rcTabs.bottom - rcTabs.top) - 2 * iFrameY, TRUE); + } + } + break; + + case WM_NOTIFY: + if ((((NMHDR*)lParam)->idFrom == IDC_TABS)) { + if (((NMHDR*)lParam)->code == TCN_SELCHANGING) { + TCITEM tci; + + tci.mask = TCIF_PARAM; + TabCtrl_GetItem(GetDlgItem(hwndDlg, IDC_TABS), TabCtrl_GetCurSel(GetDlgItem(hwndDlg, IDC_TABS)), &tci); + ShowWindow((HWND)tci.lParam, SW_HIDE); + } + else if (((NMHDR*)lParam)->code == TCN_SELCHANGE) { + TCITEM tci; + + tci.mask = TCIF_PARAM; + TabCtrl_GetItem(GetDlgItem(hwndDlg, IDC_TABS), TabCtrl_GetCurSel(GetDlgItem(hwndDlg, IDC_TABS)), &tci); + ShowWindow((HWND)tci.lParam, SW_SHOW); + } + } + break; + + case WM_CLOSE: + if (GetParent(hwndDlg) == NULL) + DestroyWindow(hwndDlg); + else + EndDialog(hwndDlg, 0); + break; + + case WM_DESTROY: + Utils_SaveWindowPosition(hwndDlg, NULL, MODULENAME, "help"); + + HWND hTab = GetDlgItem(hwndDlg, IDC_TABS); + + TCITEM tci; + tci.mask = TCIF_PARAM; + int count = TabCtrl_GetItemCount(hTab); + for (int i = 0; i < count; i++) { + TabCtrl_GetItem(hTab, i, &tci); + if (((HWND)tci.lParam != dat->hwndSubjectDlg) && ((HWND)tci.lParam != dat->hwndExtraTextDlg)) + DestroyWindow((HWND)tci.lParam); + } + + // these windows might have been created, but not inserted as tabs + if (IsWindow(dat->hwndSubjectDlg)) + DestroyWindow(dat->hwndSubjectDlg); + + if (IsWindow(dat->hwndExtraTextDlg)) + DestroyWindow(dat->hwndExtraTextDlg); + + mir_free(dat); + dat = NULL; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + break; + } + + return FALSE; +} + +INT_PTR showHelpExService(WPARAM wParam, LPARAM lParam) +{ + if (IsWindow(hwndHelpDialog)) { + SetFocus(hwndHelpDialog); + return 0; + } + if (lParam == 0) + return -1; + + iFrameX = GetSystemMetrics(SM_CXSIZEFRAME); + iFrameY = 3 * GetSystemMetrics(SM_CYSIZEFRAME); + + if (wParam) + DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_HELP_DIALOG), (HWND)wParam, helpDlgProc, (LPARAM)lParam); + else + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_HELP_DIALOG), NULL, helpDlgProc, (LPARAM)lParam); + + return 0; +} + +INT_PTR showHelpService(WPARAM wParam, LPARAM lParam) +{ + static VARHELPINFO *vhs = NULL; + static FORMATINFO *fi = NULL; + + if (fi == NULL) + fi = (FORMATINFO*)mir_alloc(sizeof(FORMATINFO)); + + ZeroMemory(fi, sizeof(FORMATINFO)); + fi->cbSize = sizeof(FORMATINFO); + fi->szFormat = (char *)lParam; + if (vhs == NULL) + vhs = (VARHELPINFO*)mir_alloc(sizeof(VARHELPINFO)); + + ZeroMemory(vhs, sizeof(VARHELPINFO)); + vhs->cbSize = sizeof(VARHELPINFO); + vhs->fi = fi; + vhs->hwndCtrl = (HWND)wParam; + vhs->flags = VHF_FULLDLG | VHF_DONTFILLSTRUCT; + + return showHelpExService(0, (LPARAM)vhs); +} + +INT_PTR getSkinItemService(WPARAM wParam, LPARAM lParam) +{ + int item = lParam; + if (item == 0) + return (INT_PTR)NULL; + + switch (item) { + case VSI_HELPICON: + if (hHelpIcon == NULL) + hHelpIcon = Skin_GetIcon("vars_help"); + return (INT_PTR)hHelpIcon; + + case VSI_HELPTIPTEXT: + return (INT_PTR)Translate("Open String Formatting Help"); + } + + return (INT_PTR)NULL; +} + +int iconsChanged(WPARAM wParam, LPARAM lParam) +{ + hHelpIcon = NULL; + return 0; +} diff --git a/plugins/Variables/src/variables.cpp b/plugins/Variables/src/variables.cpp index 93ab27ab9d..7e79114115 100644 --- a/plugins/Variables/src/variables.cpp +++ b/plugins/Variables/src/variables.cpp @@ -1,571 +1,564 @@ -/*
- Variables Plugin for Miranda-IM (www.miranda-im.org)
- Copyright 2003-2006 P. Boon
-
- This program is mir_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 "variables.h"
-
-/* some handles */
-static HANDLE
- hFormatStringService,
- hRegisterVariableService,
- hGetMMIService,
- hShowHelpService,
- hShowHelpExService,
- hGetIconService;
-
-static HANDLE
- hOptionsHook = NULL,
- hIconsChangedHook = NULL;
-
-HCURSOR hCurSplitNS;
-
-struct ParseOptions gParseOpts;
-
-TCHAR* getArguments(TCHAR *string, TCHAR ***aargv, int *aargc)
-{
- BOOL bDontParse, bNewArg, bDone;
- TCHAR *cur, *scur, **argv;
- int i, argc, brackets;
-
- *aargv = NULL;
- *aargc = 0;
- argc = brackets = 0;
- argv = NULL;
- cur = string;
- while (*cur == ' ')
- cur++;
-
- if (*cur != '(')
- return NULL;
-
- cur++;
- scur = cur-1;
- bDontParse = bNewArg = bDone = FALSE;
- while ( (!bDone) && (*cur != 0)) {
- switch (*cur) {
- case DONTPARSE_CHAR:
- bDontParse = !bDontParse;
- break;
-
- case ',':
- if ((!bDontParse) && (brackets == 0))
- bNewArg = TRUE;
- break;
-
- case '(':
- if (!bDontParse)
- brackets += 1;
- break;
-
- case ')':
- if ((brackets == 0) && (!bDontParse))
- bDone = bNewArg = TRUE;
- else if ((brackets > 0) && (!bDontParse))
- brackets -= 1;
- break;
- }
- if (bNewArg) {
- argv = ( TCHAR** )mir_realloc(argv, (argc+1)*sizeof(TCHAR*));
- if (argv == NULL)
- return NULL;
-
- if (cur > scur) {
- argv[argc] = (TCHAR*)mir_alloc((cur-scur+2)*sizeof(TCHAR));
- if (argv[argc] == NULL)
- return NULL;
-
- memset(argv[argc], '\0', (cur-(scur+1)+1)*sizeof(TCHAR));
- _tcsncpy(argv[argc], scur+1, cur-(scur+1));
- }
- else argv[argc] = mir_tstrdup(_T(""));
-
- argc += 1;
- bNewArg = FALSE;
- scur = cur;
- }
- cur++;
- }
- // set args
- if (*(cur-1) == ')') {
- *aargv = argv;
- *aargc = argc;
- }
- else {
- for (i=0;i<argc;i++) {
- if (argv[i] != NULL) {
- mir_free(argv[i]);
- }
- }
- mir_free(argv);
- *aargv = NULL;
- *aargc = 0;
- cur = NULL;
- }
-
- return cur;
-}
-
-int isValidTokenChar(TCHAR tc) {
-
- return
- (tc != '(') &&
- (tc != ',') &&
- (tc != ')') &&
- (tc != FIELD_CHAR) &&
- (tc != FUNC_CHAR) &&
- (tc != FUNC_ONCE_CHAR) &&
- (tc != '/') &&
- (tc != 0);
-}
-
-/* pretty much the main loop */
-static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi)
-{
- TCHAR
- *string,
- *cur, // current position (pnt only)
- *tcur, // temp cur (pnt only)
- *scur, // start of variable(pnt only)
- *parsedToken, // parsed result (dyn alloc)
- **argv, // arguments (dyn alloc)
- **pargv, // dyn alloc
- *token; // variable name (pnt only)
- int argc = 0, i, scurPos, curPos, tmpVarPos;
- size_t pos;
- FORMATINFO afi;
- TOKENREGISTEREX *tr;
- ARGUMENTSINFO ai = { 0 };
-
- string = mir_tstrdup(szTemplate);
- if (string == NULL)
- return NULL;
-
- cur = tcur = scur = token = parsedToken = NULL;
- pargv = argv = NULL;
- //fi->pCount = 0;
- memcpy(&afi, fi, sizeof(afi));
- for (pos = 0;pos < _tcslen(string);pos++) {
- // string may move in memory, iterate by remembering the position in the string
- cur = string+pos;
- // mir_free memory from last iteration, this way we can bail out at any time in the loop
- if (parsedToken != NULL)
- mir_free(parsedToken);
-
- for (i=0;i<argc;i++)
- if (argv[i] != NULL)
- mir_free(argv[i]);
-
- if (argv != NULL)
- mir_free(argv);
-
- argc = 0;
- tcur = scur = token = parsedToken = NULL;
- pargv = argv = NULL;
- // new round
- if (*cur == DONTPARSE_CHAR) {
- MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR));
- if (*cur == DONTPARSE_CHAR)
- continue;
-
- while ( (*cur != DONTPARSE_CHAR) && (*cur != 0))
- cur++;
-
- MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR));
- pos = cur-string-1;
- continue;
- }
- // remove end of lines
- else if ((!_tcsncmp(cur, _T("\r\n"), 2)) && (gParseOpts.bStripEOL)) {
- MoveMemory(cur, cur+2, (_tcslen(cur+2)+1)*sizeof(TCHAR));
- pos = cur-string-1;
- continue;
- }
- else if ((*cur == '\n' && gParseOpts.bStripEOL) || (*cur == ' ' && gParseOpts.bStripWS)) {
- MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR));
- pos = cur - string - 1;
- continue;
- }
- // remove comments
- else if (!_tcsncmp(cur, _T(COMMENT_STRING), _tcslen(_T(COMMENT_STRING)))) {
- scur = cur;
- while ( _tcsncmp(cur, _T("\r\n"), 2) && *cur != '\n' && *cur != 0)
- cur++;
-
- if (*cur == 0) {
- *scur = 0;
- string = (TCHAR*)mir_realloc(string, (_tcslen(string)+1)*sizeof(TCHAR));
- continue;
- }
- MoveMemory(scur, cur, (_tcslen(cur)+1)*sizeof(TCHAR));
- pos = scur-string-1;
- continue;
- }
- else if ((*cur != FIELD_CHAR) && (*cur != FUNC_CHAR) && (*cur != FUNC_ONCE_CHAR)) {
- if (gParseOpts.bStripAll) {
- MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR));
- pos = cur - string - 1;
- }
- continue;
- }
- scur = tcur = cur+1;
- while (isValidTokenChar(*tcur))
- tcur++;
-
- if (tcur == cur) {
- fi->eCount += 1;
- continue;
- }
- token = (TCHAR*)mir_alloc((tcur-scur+1)*sizeof(TCHAR));
- if (token == NULL) {
- fi->eCount += 1;
- return NULL;
- }
- memset(token, '\0', (tcur-scur+1)*sizeof(TCHAR));
- _tcsncpy(token, cur+1, tcur-scur);
- // cur points to FIELD_CHAR or FUNC_CHAR
- tmpVarPos = -1;
- tr = NULL;
- if (*cur==FIELD_CHAR) {
- for(i = 0; i < fi->cbTemporaryVarsSize; i += 2) {
- if (lstrcmp(fi->tszaTemporaryVars[i], token) == 0) {
- tmpVarPos = i;
- break;
- }
- }
- }
- if (tmpVarPos < 0)
- tr = searchRegister(token, (*cur==FIELD_CHAR)?TRF_FIELD:TRF_FUNCTION);
- mir_free(token);
- if (tmpVarPos < 0 && tr == NULL) {
- fi->eCount += 1;
- // token not found, continue
- continue;
- }
- scur = cur; // store this pointer for later use
- if (*cur == FIELD_CHAR) {
- size_t len = _tcslen(tr != NULL ? tr->tszTokenString : fi->tszaTemporaryVars[tmpVarPos]);
- cur++;
- if (*(cur + len) != FIELD_CHAR) { // the next char after the token should be %
- fi->eCount += 1;
- continue;
- }
- cur += len+1;
- }
- else if ((*cur == FUNC_CHAR) || (*cur == FUNC_ONCE_CHAR)) {
- TCHAR *argcur;
-
- cur += _tcslen(tr->tszTokenString)+1;
- argcur = getArguments(cur, &argv, &argc);
- if ((argcur == cur) || (argcur == NULL)) {
- fi->eCount += 1;
- // error getting arguments
- continue;
- }
- cur = argcur;
- // arguments
- for (i=0;i<argc;i++) {
- if (argv[i] != NULL) {
- if (!(tr->flags&TRF_UNPARSEDARGS)) {
- afi.tszFormat = argv[i];
- afi.eCount = afi.pCount = 0;
- argv[i] = formatString(&afi);
- fi->eCount += afi.eCount;
- fi->pCount += afi.pCount;
- mir_free(afi.szFormat);
- }
- }
- if (argv[i] == NULL)
- argv[i] = mir_tstrdup(_T(""));
- }
- }
- // cur should now point at the character after FIELD_CHAR or after the last ')'
- if (tr != NULL) {
- pargv = ( TCHAR** )mir_alloc((argc+1)*sizeof(TCHAR*));
- if (pargv == NULL) {
- fi->eCount += 1;
- return NULL;
- }
- for (i=0;i<argc;i++)
- pargv[i+1] = argv[i];
-
- pargv[0] = tr->tszTokenString;
- ZeroMemory(&ai, sizeof(ai));
- ai.cbSize = sizeof(ai);
- ai.argc = argc+1;
- ai.targv = pargv;
- ai.fi = fi;
- if ((*scur == FUNC_ONCE_CHAR) || (*scur == FIELD_CHAR))
- ai.flags |= AIF_DONTPARSE;
-
- parsedToken = parseFromRegister(&ai);
- mir_free(pargv);
- }
- else parsedToken = fi->tszaTemporaryVars[tmpVarPos + 1];
-
- if (parsedToken == NULL) {
- fi->eCount += 1;
- continue;
- }
-
- //replaced a var
- if (ai.flags & AIF_FALSE )
- fi->eCount++;
- else
- fi->pCount++;
-
- // 'special' chars need to be taken care of (DONTPARSE, TRYPARSE, \r\n)
- // if the var contains the escape character, this character must be doubled, we don't want it to act as an esacpe char
- /*for (tcur=parsedToken;*tcur != '\0';tcur++) {
- if (*tcur == DONTPARSE_CHAR) {//|| (*(var+pos) == ')')) {
- parsedToken = mir_realloc(parsedToken, strlen(parsedToken) + 2);
- if (parsedToken == NULL) {
- fi->err = EMEM;
- return NULL;
- }
- CopyMemory(tcur+1, tcur, strlen(tcur)+1);
- tcur++;
- }
- }*/
-
- size_t parsedTokenLen = _tcslen(parsedToken);
- size_t initStrLen = _tcslen(string);
- size_t tokenLen = cur-scur;
- scurPos = scur-string;
- curPos = cur-string;
- if (tokenLen < parsedTokenLen) {
- // string needs more memory
- string = (TCHAR*)mir_realloc(string, (initStrLen-tokenLen+parsedTokenLen+1)*sizeof(TCHAR));
- if (string == NULL) {
- fi->eCount += 1;
- return NULL;
- }
- }
- scur = string+scurPos;
- cur = string+curPos;
- MoveMemory(scur + parsedTokenLen, cur, (_tcslen(cur)+1)*sizeof(TCHAR));
- CopyMemory(scur, parsedToken, parsedTokenLen*sizeof(TCHAR));
- {
- size_t len = _tcslen(string);
- string = (TCHAR*)mir_realloc(string, (len+1)*sizeof(TCHAR));
- }
- if (( ai.flags & AIF_DONTPARSE ) || tmpVarPos >= 0)
- pos += parsedTokenLen;
-
- pos--; // parse the same pos again, it changed
-
- if (tr == NULL)
- parsedToken = NULL; // To avoid mir_free
- }
- if (parsedToken != NULL)
- mir_free(parsedToken);
-
- for ( i=0; i < argc; i++ )
- if (argv[i] != NULL)
- mir_free(argv[i]);
-
- if (argv != NULL)
- mir_free(argv);
-
- return (TCHAR*)mir_realloc(string, (_tcslen(string)+1)*sizeof(TCHAR));
-}
-
-/*
- MS_VARS_FORMATSTRING
-*/
-static INT_PTR formatStringService(WPARAM wParam, LPARAM lParam)
-{
- INT_PTR res;
- int i;
- BOOL copied;
- FORMATINFO *fi, tempFi;
- FORMATINFOV1 *fiv1;
- TCHAR *tszFormat, *orgFormat, *tszSource, *orgSource, *tRes;
-
- if (((FORMATINFO *)wParam)->cbSize >= sizeof(FORMATINFO)) {
- ZeroMemory(&tempFi, sizeof(FORMATINFO));
- CopyMemory(&tempFi, (FORMATINFO *)wParam, sizeof(FORMATINFO));
- fi = &tempFi;
- }
- else if (((FORMATINFO *)wParam)->cbSize == FORMATINFOV2_SIZE) {
- ZeroMemory(&tempFi, sizeof(FORMATINFO));
- CopyMemory(&tempFi, (FORMATINFO *)wParam, FORMATINFOV2_SIZE);
- fi = &tempFi;
- }
- else {
- // old struct, must be ANSI
- fiv1 = (FORMATINFOV1 *)wParam;
- ZeroMemory(&tempFi, sizeof(FORMATINFO));
- tempFi.cbSize = sizeof(FORMATINFO);
- tempFi.hContact = fiv1->hContact;
- tempFi.szFormat = fiv1->szFormat;
- tempFi.szExtraText = fiv1->szSource;
- fi = &tempFi;
- }
- orgFormat = fi->tszFormat;
- orgSource = fi->tszExtraText;
-
- if (!(fi->flags&FIF_TCHAR)) {
- copied = TRUE;
- log_debugA("mir_a2t (%s)", fi->szExtraText);
- tszFormat = fi->szFormat!=NULL?mir_a2t(fi->szFormat):NULL;
- tszSource = fi->szExtraText!=NULL?mir_a2t(fi->szExtraText):NULL;
- for(i = 0; i < fi->cbTemporaryVarsSize; i++) {
- fi->tszaTemporaryVars[i] = fi->szaTemporaryVars[i]!=NULL?mir_a2t(fi->szaTemporaryVars[i]):NULL;
- }
- }
- else {
- copied = FALSE;
- tszFormat = fi->tszFormat;
- tszSource = fi->tszExtraText;
- }
-
- fi->tszFormat = tszFormat;
- fi->tszExtraText = tszSource;
-
- tRes = formatString(fi);
-
- if (!(fi->flags&FIF_TCHAR)) {
- res = (INT_PTR)mir_u2a(tRes);
- mir_free(tRes);
- }
- else res = (INT_PTR)tRes;
-
- if (copied) {
- mir_free(tszFormat);
- mir_free(tszSource);
- for(i = 0; i < fi->cbTemporaryVarsSize; i++)
- mir_free(fi->tszaTemporaryVars);
- }
-
- if (((FORMATINFO *)wParam)->cbSize == sizeof(FORMATINFOV1)) {
- ((FORMATINFOV1 *)wParam)->eCount = fi->eCount;
- ((FORMATINFOV1 *)wParam)->pCount = fi->pCount;
- }
- else {
- ((FORMATINFO *)wParam)->eCount = fi->eCount;
- ((FORMATINFO *)wParam)->pCount = fi->pCount;
- }
-
- return res;
-}
-
-TCHAR *formatString(FORMATINFO *fi)
-{
- /* the service to format a given string */
- if (fi->eCount + fi->pCount > 5000) {
- fi->eCount += 1;
- fi->pCount += 1;
- log_debugA("Variables: Overflow protection; %d parses", fi->eCount + fi->pCount);
- return NULL;
- }
- if ((fi == NULL) || (fi->tszFormat == NULL))
- return NULL;
-
- ptrT string( mir_tstrdup(fi->tszFormat));
- if (string == NULL)
- return NULL;
-
- return replaceDynVars(string, fi);
-}
-
-int setParseOptions(struct ParseOptions *po)
-{
- if (po == NULL)
- po = &gParseOpts;
-
- ZeroMemory(po, sizeof(struct ParseOptions));
- if (!db_get_b(NULL, MODULENAME, SETTING_STRIPALL, 0)) {
- po->bStripEOL = db_get_b(NULL, MODULENAME, SETTING_STRIPCRLF, 0);
- po->bStripWS = db_get_b(NULL, MODULENAME, SETTING_STRIPWS, 0);
- }
- else po->bStripAll = TRUE;
-
- return 0;
-}
-
-static IconItem icon = { LPGEN("Help"), "vars_help", IDI_V };
-
-int LoadVarModule()
-{
- if (initTokenRegister() != 0 || initContactModule() != 0)
- return -1;
-
- setParseOptions(NULL);
- hFormatStringService = CreateServiceFunction(MS_VARS_FORMATSTRING, formatStringService);
- hRegisterVariableService = CreateServiceFunction(MS_VARS_REGISTERTOKEN, registerToken);
- // help dialog
- hCurSplitNS = LoadCursor(NULL, IDC_SIZENS);
-
- hShowHelpService = CreateServiceFunction(MS_VARS_SHOWHELP, showHelpService);
- hShowHelpExService = CreateServiceFunction(MS_VARS_SHOWHELPEX, showHelpExService);
-
- Icon_Register(hInst, LPGEN("Variables"), &icon, 1);
-
- hIconsChangedHook = HookEvent(ME_SKIN2_ICONSCHANGED, iconsChanged);
-
- hGetIconService = CreateServiceFunction(MS_VARS_GETSKINITEM, getSkinItemService);
- hOptionsHook = HookEvent(ME_OPT_INITIALISE, OptionsInit);
-
- // register internal tokens
- registerExternalTokens();
- registerLogicTokens();
- registerMathTokens();
- registerMirandaTokens();
- registerStrTokens();
- registerSystemTokens();
- registerVariablesTokens();
- registerRegExpTokens();
- registerInetTokens();
- registerAliasTokens();
- registerMetaContactsTokens();
-
- log_debugA("Variables: Internal tokens registered");
-
- if (db_get_b(NULL, MODULENAME, SETTING_PARSEATSTARTUP, 0)) {
- FORMATINFO fi = { 0 };
- fi.cbSize = sizeof(fi);
- fi.tszFormat = db_get_tsa(NULL, MODULENAME, SETTING_STARTUPTEXT);
- if (fi.tszFormat != NULL) {
- mir_free(formatString(&fi));
- mir_free(fi.tszFormat);
- }
- }
- log_debugA("Variables: Init done");
-
- return 0;
-}
-
-int UnloadVarModule()
-{
- UnhookEvent(hOptionsHook);
- if (hIconsChangedHook != NULL)
- UnhookEvent(hIconsChangedHook);
-
- DestroyServiceFunction(hRegisterVariableService);
- DestroyServiceFunction(hFormatStringService);
- DestroyServiceFunction(hGetMMIService);
- DestroyServiceFunction(hShowHelpService);
- DestroyServiceFunction(hShowHelpExService);
- DestroyServiceFunction(hGetIconService);
- DestroyCursor(hCurSplitNS);
- deinitContactModule();
- deinitTokenRegister();
- unregisterAliasTokens();
- unregisterVariablesTokens();
- return 0;
-}
+/* + Variables Plugin for Miranda-IM (www.miranda-im.org) + Copyright 2003-2006 P. Boon + + This program is mir_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 "variables.h" + +/* some handles */ +static HANDLE + hFormatStringService, + hRegisterVariableService, + hGetMMIService, + hShowHelpService, + hShowHelpExService, + hGetIconService; + +static HANDLE + hOptionsHook = NULL, + hIconsChangedHook = NULL; + +HCURSOR hCurSplitNS; + +struct ParseOptions gParseOpts; + +TCHAR* getArguments(TCHAR *string, TCHAR ***aargv, int *aargc) +{ + BOOL bDontParse, bNewArg, bDone; + TCHAR *cur, *scur, **argv; + int i, argc, brackets; + + *aargv = NULL; + *aargc = 0; + argc = brackets = 0; + argv = NULL; + cur = string; + while (*cur == ' ') + cur++; + + if (*cur != '(') + return NULL; + + cur++; + scur = cur-1; + bDontParse = bNewArg = bDone = FALSE; + while ( (!bDone) && (*cur != 0)) { + switch (*cur) { + case DONTPARSE_CHAR: + bDontParse = !bDontParse; + break; + + case ',': + if ((!bDontParse) && (brackets == 0)) + bNewArg = TRUE; + break; + + case '(': + if (!bDontParse) + brackets += 1; + break; + + case ')': + if ((brackets == 0) && (!bDontParse)) + bDone = bNewArg = TRUE; + else if ((brackets > 0) && (!bDontParse)) + brackets -= 1; + break; + } + if (bNewArg) { + argv = ( TCHAR** )mir_realloc(argv, (argc+1)*sizeof(TCHAR*)); + if (argv == NULL) + return NULL; + + if (cur > scur) { + argv[argc] = (TCHAR*)mir_alloc((cur-scur+2)*sizeof(TCHAR)); + if (argv[argc] == NULL) + return NULL; + + memset(argv[argc], '\0', (cur-(scur+1)+1)*sizeof(TCHAR)); + _tcsncpy(argv[argc], scur+1, cur-(scur+1)); + } + else argv[argc] = mir_tstrdup(_T("")); + + argc += 1; + bNewArg = FALSE; + scur = cur; + } + cur++; + } + // set args + if (*(cur-1) == ')') { + *aargv = argv; + *aargc = argc; + } + else { + for (i=0;i<argc;i++) { + if (argv[i] != NULL) { + mir_free(argv[i]); + } + } + mir_free(argv); + *aargv = NULL; + *aargc = 0; + cur = NULL; + } + + return cur; +} + +int isValidTokenChar(TCHAR tc) { + + return + (tc != '(') && + (tc != ',') && + (tc != ')') && + (tc != FIELD_CHAR) && + (tc != FUNC_CHAR) && + (tc != FUNC_ONCE_CHAR) && + (tc != '/') && + (tc != 0); +} + +/* pretty much the main loop */ +static TCHAR* replaceDynVars(TCHAR* szTemplate, FORMATINFO* fi) +{ + TCHAR + *string, + *cur, // current position (pnt only) + *tcur, // temp cur (pnt only) + *scur, // start of variable(pnt only) + *parsedToken, // parsed result (dyn alloc) + **argv, // arguments (dyn alloc) + **pargv, // dyn alloc + *token; // variable name (pnt only) + int argc = 0, i, scurPos, curPos, tmpVarPos; + size_t pos; + FORMATINFO afi; + TOKENREGISTEREX *tr; + ARGUMENTSINFO ai = { 0 }; + + string = mir_tstrdup(szTemplate); + if (string == NULL) + return NULL; + + cur = tcur = scur = token = parsedToken = NULL; + pargv = argv = NULL; + //fi->pCount = 0; + memcpy(&afi, fi, sizeof(afi)); + for (pos = 0; pos < _tcslen(string); pos++) { + // string may move in memory, iterate by remembering the position in the string + cur = string+pos; + // mir_free memory from last iteration, this way we can bail out at any time in the loop + mir_free(parsedToken); + + for (i = 0; i < argc; i ++) + mir_free(argv[i]); + mir_free(argv); + argc = 0; + tcur = scur = token = parsedToken = NULL; + pargv = argv = NULL; + // new round + if (*cur == DONTPARSE_CHAR) { + MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR)); + if (*cur == DONTPARSE_CHAR) + continue; + + while ( (*cur != DONTPARSE_CHAR) && (*cur != 0)) + cur++; + + MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR)); + pos = cur-string-1; + continue; + } + // remove end of lines + else if ((!_tcsncmp(cur, _T("\r\n"), 2)) && (gParseOpts.bStripEOL)) { + MoveMemory(cur, cur+2, (_tcslen(cur+2)+1)*sizeof(TCHAR)); + pos = cur-string-1; + continue; + } + else if ((*cur == '\n' && gParseOpts.bStripEOL) || (*cur == ' ' && gParseOpts.bStripWS)) { + MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR)); + pos = cur - string - 1; + continue; + } + // remove comments + else if (!_tcsncmp(cur, _T(COMMENT_STRING), _tcslen(_T(COMMENT_STRING)))) { + scur = cur; + while ( _tcsncmp(cur, _T("\r\n"), 2) && *cur != '\n' && *cur != 0) + cur++; + + if (*cur == 0) { + *scur = 0; + string = (TCHAR*)mir_realloc(string, (_tcslen(string)+1)*sizeof(TCHAR)); + continue; + } + MoveMemory(scur, cur, (_tcslen(cur)+1)*sizeof(TCHAR)); + pos = scur-string-1; + continue; + } + else if ((*cur != FIELD_CHAR) && (*cur != FUNC_CHAR) && (*cur != FUNC_ONCE_CHAR)) { + if (gParseOpts.bStripAll) { + MoveMemory(cur, cur+1, (_tcslen(cur+1)+1)*sizeof(TCHAR)); + pos = cur - string - 1; + } + continue; + } + scur = tcur = cur+1; + while (isValidTokenChar(*tcur)) + tcur++; + + if (tcur == cur) { + fi->eCount += 1; + continue; + } + token = (TCHAR*)mir_alloc((tcur-scur+1)*sizeof(TCHAR)); + if (token == NULL) { + fi->eCount += 1; + return NULL; + } + memset(token, '\0', (tcur-scur+1)*sizeof(TCHAR)); + _tcsncpy(token, cur+1, tcur-scur); + // cur points to FIELD_CHAR or FUNC_CHAR + tmpVarPos = -1; + tr = NULL; + if (*cur==FIELD_CHAR) { + for(i = 0; i < fi->cbTemporaryVarsSize; i += 2) { + if (lstrcmp(fi->tszaTemporaryVars[i], token) == 0) { + tmpVarPos = i; + break; + } + } + } + if (tmpVarPos < 0) + tr = searchRegister(token, (*cur==FIELD_CHAR)?TRF_FIELD:TRF_FUNCTION); + mir_free(token); + if (tmpVarPos < 0 && tr == NULL) { + fi->eCount += 1; + // token not found, continue + continue; + } + scur = cur; // store this pointer for later use + if (*cur == FIELD_CHAR) { + size_t len = _tcslen(tr != NULL ? tr->tszTokenString : fi->tszaTemporaryVars[tmpVarPos]); + cur++; + if (*(cur + len) != FIELD_CHAR) { // the next char after the token should be % + fi->eCount += 1; + continue; + } + cur += len+1; + } + else if ((*cur == FUNC_CHAR) || (*cur == FUNC_ONCE_CHAR)) { + TCHAR *argcur; + + cur += _tcslen(tr->tszTokenString)+1; + argcur = getArguments(cur, &argv, &argc); + if ((argcur == cur) || (argcur == NULL)) { + fi->eCount += 1; + // error getting arguments + continue; + } + cur = argcur; + // arguments + for (i=0;i<argc;i++) { + if (argv[i] != NULL) { + if (!(tr->flags&TRF_UNPARSEDARGS)) { + afi.tszFormat = argv[i]; + afi.eCount = afi.pCount = 0; + argv[i] = formatString(&afi); + fi->eCount += afi.eCount; + fi->pCount += afi.pCount; + mir_free(afi.szFormat); + } + } + if (argv[i] == NULL) + argv[i] = mir_tstrdup(_T("")); + } + } + // cur should now point at the character after FIELD_CHAR or after the last ')' + if (tr != NULL) { + pargv = ( TCHAR** )mir_alloc((argc+1)*sizeof(TCHAR*)); + if (pargv == NULL) { + fi->eCount += 1; + return NULL; + } + for (i=0;i<argc;i++) + pargv[i+1] = argv[i]; + + pargv[0] = tr->tszTokenString; + ZeroMemory(&ai, sizeof(ai)); + ai.cbSize = sizeof(ai); + ai.argc = argc+1; + ai.targv = pargv; + ai.fi = fi; + if ((*scur == FUNC_ONCE_CHAR) || (*scur == FIELD_CHAR)) + ai.flags |= AIF_DONTPARSE; + + parsedToken = parseFromRegister(&ai); + mir_free(pargv); + } + else parsedToken = fi->tszaTemporaryVars[tmpVarPos + 1]; + + if (parsedToken == NULL) { + fi->eCount += 1; + continue; + } + + //replaced a var + if (ai.flags & AIF_FALSE ) + fi->eCount++; + else + fi->pCount++; + + // 'special' chars need to be taken care of (DONTPARSE, TRYPARSE, \r\n) + // if the var contains the escape character, this character must be doubled, we don't want it to act as an esacpe char + /*for (tcur=parsedToken;*tcur != '\0';tcur++) { + if (*tcur == DONTPARSE_CHAR) {//|| (*(var+pos) == ')')) { + parsedToken = mir_realloc(parsedToken, strlen(parsedToken) + 2); + if (parsedToken == NULL) { + fi->err = EMEM; + return NULL; + } + CopyMemory(tcur+1, tcur, strlen(tcur)+1); + tcur++; + } + }*/ + + size_t parsedTokenLen = _tcslen(parsedToken); + size_t initStrLen = _tcslen(string); + size_t tokenLen = cur-scur; + scurPos = scur-string; + curPos = cur-string; + if (tokenLen < parsedTokenLen) { + // string needs more memory + string = (TCHAR*)mir_realloc(string, (initStrLen-tokenLen+parsedTokenLen+1)*sizeof(TCHAR)); + if (string == NULL) { + fi->eCount += 1; + return NULL; + } + } + scur = string+scurPos; + cur = string+curPos; + MoveMemory(scur + parsedTokenLen, cur, (_tcslen(cur)+1)*sizeof(TCHAR)); + CopyMemory(scur, parsedToken, parsedTokenLen*sizeof(TCHAR)); + { + size_t len = _tcslen(string); + string = (TCHAR*)mir_realloc(string, (len+1)*sizeof(TCHAR)); + } + if (( ai.flags & AIF_DONTPARSE ) || tmpVarPos >= 0) + pos += parsedTokenLen; + + pos--; // parse the same pos again, it changed + + if (tr == NULL) + parsedToken = NULL; // To avoid mir_free + } + if (parsedToken != NULL) + mir_free(parsedToken); + + for (i = 0; i < argc; i ++) + mir_free(argv[i]); + mir_free(argv); + + return (TCHAR*)mir_realloc(string, (_tcslen(string)+1)*sizeof(TCHAR)); +} + +/* + MS_VARS_FORMATSTRING +*/ +static INT_PTR formatStringService(WPARAM wParam, LPARAM lParam) +{ + INT_PTR res; + int i; + BOOL copied; + FORMATINFO *fi, tempFi; + FORMATINFOV1 *fiv1; + TCHAR *tszFormat, *orgFormat, *tszSource, *orgSource, *tRes; + + if (((FORMATINFO *)wParam)->cbSize >= sizeof(FORMATINFO)) { + ZeroMemory(&tempFi, sizeof(FORMATINFO)); + CopyMemory(&tempFi, (FORMATINFO *)wParam, sizeof(FORMATINFO)); + fi = &tempFi; + } + else if (((FORMATINFO *)wParam)->cbSize == FORMATINFOV2_SIZE) { + ZeroMemory(&tempFi, sizeof(FORMATINFO)); + CopyMemory(&tempFi, (FORMATINFO *)wParam, FORMATINFOV2_SIZE); + fi = &tempFi; + } + else { + // old struct, must be ANSI + fiv1 = (FORMATINFOV1 *)wParam; + ZeroMemory(&tempFi, sizeof(FORMATINFO)); + tempFi.cbSize = sizeof(FORMATINFO); + tempFi.hContact = fiv1->hContact; + tempFi.szFormat = fiv1->szFormat; + tempFi.szExtraText = fiv1->szSource; + fi = &tempFi; + } + orgFormat = fi->tszFormat; + orgSource = fi->tszExtraText; + + if (!(fi->flags&FIF_TCHAR)) { + copied = TRUE; + log_debugA("mir_a2t (%s)", fi->szExtraText); + tszFormat = fi->szFormat!=NULL?mir_a2t(fi->szFormat):NULL; + tszSource = fi->szExtraText!=NULL?mir_a2t(fi->szExtraText):NULL; + for(i = 0; i < fi->cbTemporaryVarsSize; i++) { + fi->tszaTemporaryVars[i] = fi->szaTemporaryVars[i]!=NULL?mir_a2t(fi->szaTemporaryVars[i]):NULL; + } + } + else { + copied = FALSE; + tszFormat = fi->tszFormat; + tszSource = fi->tszExtraText; + } + + fi->tszFormat = tszFormat; + fi->tszExtraText = tszSource; + + tRes = formatString(fi); + + if (!(fi->flags&FIF_TCHAR)) { + res = (INT_PTR)mir_u2a(tRes); + mir_free(tRes); + } + else res = (INT_PTR)tRes; + + if (copied) { + mir_free(tszFormat); + mir_free(tszSource); + for(i = 0; i < fi->cbTemporaryVarsSize; i++) + mir_free(fi->tszaTemporaryVars); + } + + if (((FORMATINFO *)wParam)->cbSize == sizeof(FORMATINFOV1)) { + ((FORMATINFOV1 *)wParam)->eCount = fi->eCount; + ((FORMATINFOV1 *)wParam)->pCount = fi->pCount; + } + else { + ((FORMATINFO *)wParam)->eCount = fi->eCount; + ((FORMATINFO *)wParam)->pCount = fi->pCount; + } + + return res; +} + +TCHAR *formatString(FORMATINFO *fi) +{ + if (fi == NULL) + return NULL; + /* the service to format a given string */ + if ((fi->eCount + fi->pCount) > 5000) { + fi->eCount += 1; + fi->pCount += 1; + log_debugA("Variables: Overflow protection; %d parses", (fi->eCount + fi->pCount)); + return NULL; + } + if (fi->tszFormat == NULL) + return NULL; + ptrT string( mir_tstrdup(fi->tszFormat)); + if (string == NULL) + return NULL; + + return replaceDynVars(string, fi); +} + +int setParseOptions(struct ParseOptions *po) +{ + if (po == NULL) + po = &gParseOpts; + + ZeroMemory(po, sizeof(struct ParseOptions)); + if (!db_get_b(NULL, MODULENAME, SETTING_STRIPALL, 0)) { + po->bStripEOL = db_get_b(NULL, MODULENAME, SETTING_STRIPCRLF, 0); + po->bStripWS = db_get_b(NULL, MODULENAME, SETTING_STRIPWS, 0); + } + else po->bStripAll = TRUE; + + return 0; +} + +static IconItem icon = { LPGEN("Help"), "vars_help", IDI_V }; + +int LoadVarModule() +{ + if (initTokenRegister() != 0 || initContactModule() != 0) + return -1; + + setParseOptions(NULL); + hFormatStringService = CreateServiceFunction(MS_VARS_FORMATSTRING, formatStringService); + hRegisterVariableService = CreateServiceFunction(MS_VARS_REGISTERTOKEN, registerToken); + // help dialog + hCurSplitNS = LoadCursor(NULL, IDC_SIZENS); + + hShowHelpService = CreateServiceFunction(MS_VARS_SHOWHELP, showHelpService); + hShowHelpExService = CreateServiceFunction(MS_VARS_SHOWHELPEX, showHelpExService); + + Icon_Register(hInst, LPGEN("Variables"), &icon, 1); + + hIconsChangedHook = HookEvent(ME_SKIN2_ICONSCHANGED, iconsChanged); + + hGetIconService = CreateServiceFunction(MS_VARS_GETSKINITEM, getSkinItemService); + hOptionsHook = HookEvent(ME_OPT_INITIALISE, OptionsInit); + + // register internal tokens + registerExternalTokens(); + registerLogicTokens(); + registerMathTokens(); + registerMirandaTokens(); + registerStrTokens(); + registerSystemTokens(); + registerVariablesTokens(); + registerRegExpTokens(); + registerInetTokens(); + registerAliasTokens(); + registerMetaContactsTokens(); + + log_debugA("Variables: Internal tokens registered"); + + if (db_get_b(NULL, MODULENAME, SETTING_PARSEATSTARTUP, 0)) { + FORMATINFO fi = { 0 }; + fi.cbSize = sizeof(fi); + fi.tszFormat = db_get_tsa(NULL, MODULENAME, SETTING_STARTUPTEXT); + if (fi.tszFormat != NULL) { + mir_free(formatString(&fi)); + mir_free(fi.tszFormat); + } + } + log_debugA("Variables: Init done"); + + return 0; +} + +int UnloadVarModule() +{ + UnhookEvent(hOptionsHook); + if (hIconsChangedHook != NULL) + UnhookEvent(hIconsChangedHook); + + DestroyServiceFunction(hRegisterVariableService); + DestroyServiceFunction(hFormatStringService); + DestroyServiceFunction(hGetMMIService); + DestroyServiceFunction(hShowHelpService); + DestroyServiceFunction(hShowHelpExService); + DestroyServiceFunction(hGetIconService); + DestroyCursor(hCurSplitNS); + deinitContactModule(); + deinitTokenRegister(); + unregisterAliasTokens(); + unregisterVariablesTokens(); + return 0; +} |