#include "intl.h"
-#define NUM_SHEETS 4
-
/* Insert the space */
-LPTSTR
-InsSpacePos(LPCTSTR szInsStr, const int nPos)
+PWSTR
+InsSpacePos(PCWSTR szInsStr, const int nPos)
{
- LPTSTR pszDestStr;
+ PWSTR pszDestStr;
INT nDestStrCnt = 0;
INT nStrCnt;
INT nStrSize;
- pszDestStr = (LPTSTR)malloc(MAX_SAMPLES_STR_SIZE * sizeof(TCHAR));
+ pszDestStr = (PWSTR)HeapAlloc(GetProcessHeap(), 0, MAX_SAMPLES_STR_SIZE * sizeof(WCHAR));
+ if (pszDestStr == NULL)
+ return NULL;
- _tcscpy(pszDestStr, szInsStr);
+ wcscpy(pszDestStr, szInsStr);
- nStrSize = _tcslen(szInsStr);
+ nStrSize = wcslen(szInsStr);
for (nStrCnt = 0; nStrCnt < nStrSize; nStrCnt++)
{
if (nStrCnt == nStrSize - nPos)
{
- pszDestStr[nDestStrCnt] = _T(' ');
+ pszDestStr[nDestStrCnt] = L' ';
nDestStrCnt++;
}
nDestStrCnt++;
}
- pszDestStr[nDestStrCnt] = _T('\0');
+ pszDestStr[nDestStrCnt] = L'\0';
return pszDestStr;
}
/* Insert the spaces by format string separated by ';' */
-LPTSTR
-InsSpacesFmt(LPCTSTR szSourceStr, LPCTSTR szFmtStr)
+PWSTR
+InsSpacesFmt(PCWSTR szSourceStr, PCWSTR szFmtStr)
{
- LPTSTR pszDestStr;
- LPTSTR pszTempStr;
- TCHAR szFmtVal[255];
+ PWSTR pszDestStr;
+ PWSTR pszTempStr;
+ WCHAR szFmtVal[255];
UINT nFmtCount = 0;
INT nValCount = 0;
INT nLastVal = 0;
INT nSpaceOffset = 0;
BOOL wasNul=FALSE;
- pszDestStr = (LPTSTR)malloc(255 * sizeof(TCHAR));
+ pszDestStr = (PWSTR)HeapAlloc(GetProcessHeap(), 0, 255 * sizeof(WCHAR));
+ if (pszDestStr == NULL)
+ return NULL;
- _tcscpy(pszDestStr, szSourceStr);
+ wcscpy(pszDestStr, szSourceStr);
/* If format is clean return source string */
if (!*szFmtStr)
return pszDestStr;
/* Search for all format values */
- for (nFmtCount = 0; nFmtCount <= _tcslen(szFmtStr); nFmtCount++)
+ for (nFmtCount = 0; nFmtCount <= wcslen(szFmtStr); nFmtCount++)
{
- if (szFmtStr[nFmtCount] == _T(';') || szFmtStr[nFmtCount] == _T('\0'))
+ if (szFmtStr[nFmtCount] == L';' || szFmtStr[nFmtCount] == L'\0')
{
- if (_ttoi(szFmtVal) == 0 && !wasNul)
+ if (_wtoi(szFmtVal) == 0 && !wasNul)
{
wasNul=TRUE;
break;
}
else
{
- nSpaceOffset += _ttoi(szFmtVal);
+ nSpaceOffset += _wtoi(szFmtVal);
}
- szFmtVal[nValCount] = _T('\0');
+ szFmtVal[nValCount] = L'\0';
nValCount=0;
/* Insert space to finded position plus all pos before */
pszTempStr = InsSpacePos(pszDestStr, nSpaceOffset);
- _tcscpy(pszDestStr,pszTempStr);
- free(pszTempStr);
+ wcscpy(pszDestStr,pszTempStr);
+ HeapFree(GetProcessHeap(), 0, pszTempStr);
/* Num of spaces total increment */
if (!wasNul)
{
nSpaceOffset++;
- nLastVal = _ttoi(szFmtVal);
+ nLastVal = _wtoi(szFmtVal);
}
}
else
/* Create spaces for rest part of string */
if (wasNul && nLastVal != 0)
{
- for (nFmtCount = nSpaceOffset + nLastVal; nFmtCount < _tcslen(pszDestStr); nFmtCount += nLastVal + 1)
+ for (nFmtCount = nSpaceOffset + nLastVal; nFmtCount < wcslen(pszDestStr); nFmtCount += nLastVal + 1)
{
pszTempStr = InsSpacePos(pszDestStr, nFmtCount);
- _tcscpy(pszDestStr, pszTempStr);
- free(pszTempStr);
+ wcscpy(pszDestStr, pszTempStr);
+ HeapFree(GetProcessHeap(), 0, pszTempStr);
}
}
return pszDestStr;
}
-/* Replace given template in source string with string to replace and return recieved string */
-LPTSTR
-ReplaceSubStr(LPCTSTR szSourceStr,
- LPCTSTR szStrToReplace,
- LPCTSTR szTempl)
+/* Replace given template in source string with string to replace and return received string */
+PWSTR
+ReplaceSubStr(PCWSTR szSourceStr,
+ PCWSTR szStrToReplace,
+ PCWSTR szTempl)
{
- LPTSTR szDestStr;
+ PWSTR szDestStr;
UINT nCharCnt;
UINT nSubStrCnt;
UINT nDestStrCnt;
UINT nFirstCharCnt;
- szDestStr = (LPTSTR)malloc(MAX_SAMPLES_STR_SIZE * sizeof(TCHAR));
+ szDestStr = (PWSTR)HeapAlloc(GetProcessHeap(), 0, MAX_SAMPLES_STR_SIZE * sizeof(WCHAR));
+ if (szDestStr == NULL)
+ return NULL;
nDestStrCnt = 0;
nFirstCharCnt = 0;
- _tcscpy(szDestStr, _T(""));
+ wcscpy(szDestStr, L"");
- while (nFirstCharCnt < _tcslen(szSourceStr))
+ while (nFirstCharCnt < wcslen(szSourceStr))
{
if (szSourceStr[nFirstCharCnt] == szTempl[0])
{
nSubStrCnt = 0;
- for (nCharCnt = nFirstCharCnt; nCharCnt < nFirstCharCnt + _tcslen(szTempl); nCharCnt++)
+ for (nCharCnt = nFirstCharCnt; nCharCnt < nFirstCharCnt + wcslen(szTempl); nCharCnt++)
{
if (szSourceStr[nCharCnt] == szTempl[nSubStrCnt])
{
break;
}
- if (_tcslen(szTempl) == nSubStrCnt)
+ if (wcslen(szTempl) == nSubStrCnt)
{
- _tcscat(szDestStr, szStrToReplace);
- nDestStrCnt = _tcslen(szDestStr);
- nFirstCharCnt += _tcslen(szTempl) - 1;
+ wcscat(szDestStr, szStrToReplace);
+ nDestStrCnt = wcslen(szDestStr);
+ nFirstCharCnt += wcslen(szTempl) - 1;
break;
}
}
else
{
szDestStr[nDestStrCnt++] = szSourceStr[nFirstCharCnt];
- szDestStr[nDestStrCnt] = _T('\0');
+ szDestStr[nDestStrCnt] = L'\0';
}
nFirstCharCnt++;
}
-static VOID
-InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, PGLOBALDATA pGlobalData)
-{
- ZeroMemory(psp, sizeof(PROPSHEETPAGE));
- psp->dwSize = sizeof(PROPSHEETPAGE);
- psp->dwFlags = PSP_DEFAULT;
- psp->hInstance = hApplet;
- psp->pszTemplate = MAKEINTRESOURCE(idDlg);
- psp->pfnDlgProc = DlgProc;
- psp->lParam = (LPARAM)pGlobalData;
-}
-
-
-/* Create applets */
-LONG
-APIENTRY
-SetupApplet(HWND hwndDlg, LCID lcid)
+VOID
+GetSelectedComboBoxText(
+ HWND hwndDlg,
+ INT nIdDlgItem,
+ PWSTR Buffer,
+ UINT uSize)
{
- PROPSHEETPAGE PsPage[NUM_SHEETS + 1];
- PROPSHEETHEADER psh;
- PGLOBALDATA pGlobalData;
- TCHAR Caption[MAX_STR_SIZE];
- INT ret;
-
- LoadString(hApplet, IDS_CUSTOMIZE_TITLE, Caption, sizeof(Caption) / sizeof(TCHAR));
-
- pGlobalData = (PGLOBALDATA)malloc(sizeof(GLOBALDATA));
-
- pGlobalData->lcid = lcid;
-
- ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
- psh.dwSize = sizeof(PROPSHEETHEADER);
- psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_PROPTITLE;
- psh.hwndParent = hwndDlg;
- psh.hInstance = hApplet;
- psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
- psh.pszCaption = Caption;
- psh.nPages = (sizeof(PsPage) / sizeof(PROPSHEETPAGE)) - 1;
- psh.nStartPage = 0;
- psh.ppsp = PsPage;
-
- InitPropSheetPage(&PsPage[0], IDD_NUMBERSPAGE, NumbersPageProc, pGlobalData);
- InitPropSheetPage(&PsPage[1], IDD_CURRENCYPAGE, CurrencyPageProc, pGlobalData);
- InitPropSheetPage(&PsPage[2], IDD_TIMEPAGE, TimePageProc, pGlobalData);
- InitPropSheetPage(&PsPage[3], IDD_DATEPAGE, DatePageProc, pGlobalData);
-
- if (IsSortPageNeeded(lcid))
+ HWND hChildWnd;
+ PWSTR tmp;
+ INT nIndex;
+ UINT uReqSize;
+
+ /* Get handle to time format control */
+ hChildWnd = GetDlgItem(hwndDlg, nIdDlgItem);
+ if (hChildWnd == NULL)
+ return;
+
+ /* Get index to selected time format */
+ nIndex = SendMessageW(hChildWnd, CB_GETCURSEL, 0, 0);
+ if (nIndex == CB_ERR)
{
- psh.nPages++;
- InitPropSheetPage(&PsPage[4], IDD_SORTPAGE, SortPageProc, pGlobalData);
+ /* No selection? Get content of the edit control */
+ SendMessageW(hChildWnd, WM_GETTEXT, uSize, (LPARAM)Buffer);
}
+ else
+ {
+ /* Get requested size, including the null terminator;
+ * it shouldn't be required because the previous CB_LIMITTEXT,
+ * but it would be better to check it anyways */
+ uReqSize = SendMessageW(hChildWnd, CB_GETLBTEXTLEN, (WPARAM)nIndex, 0) + 1;
+
+ /* Allocate enough space to be more safe */
+ tmp = (PWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, uReqSize * sizeof(WCHAR));
+ if (tmp != NULL)
+ {
+ /* Get selected time format text */
+ SendMessageW(hChildWnd, CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)tmp);
+
+ /* Finally, copy the result into the output */
+ wcsncpy(Buffer, tmp, uSize);
- ret = PropertySheet(&psh);
+ HeapFree(GetProcessHeap(), 0, tmp);
+ }
+ }
+}
- free(pGlobalData);
- return (LONG)(ret != -1);
+VOID
+GetSelectedComboBoxIndex(
+ HWND hwndDlg,
+ INT nIdDlgItem,
+ PINT pValue)
+{
+ *pValue = SendDlgItemMessageW(hwndDlg, nIdDlgItem, CB_GETCURSEL, 0, 0);
}
/* EOF */