diff options
author | George Hazan <george.hazan@gmail.com> | 2014-03-13 17:23:22 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-03-13 17:23:22 +0000 |
commit | 09d8b6c7c0ad2a0ca9170809e7c1547f4239d520 (patch) | |
tree | 40e2aea3c396f703cd0b810e78100c5e8e59ed03 /plugins/LangMan/src | |
parent | d653062fa308f837393c5007ec557daf8c3b4c5c (diff) |
warning fix
git-svn-id: http://svn.miranda-ng.org/main/trunk@8596 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/LangMan/src')
-rw-r--r-- | plugins/LangMan/src/options.cpp | 517 |
1 files changed, 257 insertions, 260 deletions
diff --git a/plugins/LangMan/src/options.cpp b/plugins/LangMan/src/options.cpp index 17a1c321ea..c191f55fa0 100644 --- a/plugins/LangMan/src/options.cpp +++ b/plugins/LangMan/src/options.cpp @@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "common.h"
+typedef PLUGININFOEX* (__cdecl *pfnMirandaPluginInfo)(DWORD);
+
extern HINSTANCE hInst;
static HANDLE hHookOptInit;
@@ -33,99 +35,101 @@ static HANDLE hHookOptInit; // refresh on WM_THEMECHANGED
static HIMAGELIST CreateRadioImages(COLORREF clrBk, COLORREF clrText)
{
- register HDC hdc, hdcScreen;
- SIZE size;
- RECT rc;
- HBITMAP hbm, hbmPrev;
- HIMAGELIST himl = NULL;
-
/* draw bitmap */
- hdcScreen = GetDC(NULL);
- if (hdcScreen!=NULL) {
- hdc = CreateCompatibleDC(NULL); /* compatible to screen */
- if (hdc!=NULL) {
- size.cx = GetSystemMetrics(SM_CXSMICON);
- size.cy = GetSystemMetrics(SM_CYSMICON);
- SetRect(&rc, 0, 0, 2*size.cx, size.cy);
- hbm = CreateCompatibleBitmap(hdcScreen, rc.right, rc.bottom);
- if (hbm!=NULL) {
- hbmPrev = (HBITMAP)SelectObject(hdc, hbm);
- if (hbmPrev!=NULL) { /* error on select? */
- HTHEME hTheme = OpenThemeData(NULL, L"Button");
- SetRect(&rc, 0, 0, size.cx, size.cy);
- /* unchecked */
- if (!DrawThemeBackground(hTheme, hdc, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL, &rc, NULL)) {
- /* checked */
- OffsetRect(&rc, size.cx, 0);
- if (!DrawThemeBackground(hTheme, hdc, BP_RADIOBUTTON, RBS_CHECKEDNORMAL, &rc, NULL))
- himl = ImageList_Create(size.cx, size.cy, ILC_COLOR32|ILC_MASK, 3, 0);
- }
- CloseThemeData(hTheme);
- /* the classic way */
- if (himl == NULL) {
- register HDC hdcMono;
- HBITMAP hbmMono, hbmPrevMono;
- RECT rcRadio;
- COLORREF clrPrevText, clrPrevBk;
- HBRUSH hbrBk = CreateSolidBrush(clrBk);
- if (hbrBk!=NULL) {
- FillRect(hdc, &rc, hbrBk);
- DeleteObject(hbrBk);
- hdcMono = CreateCompatibleDC(hdc);
- if (hdcMono!=NULL) {
- hbmMono = CreateBitmap(rc.right, rc.bottom, 1, 1, NULL);
- if (hbmMono!=NULL) {
- hbmPrevMono = (HBITMAP)SelectObject(hdcMono, hbmMono);
- if (hbmPrevMono!=NULL) { /* error on select? */
- /* draws a black-and-white mask (see docs)
- * we need to colorize it using BitBlt with text and background color */
- clrPrevText = SetTextColor(hdc, clrText);
- clrPrevBk = SetBkColor(hdc, clrBk);
- /* check mark is slightly smaller than icon size */
- SetRect(&rcRadio, 0, 0, GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK));
- if (rcRadio.right>size.cx) rcRadio.right = size.cx;
- if (rcRadio.bottom>size.cy) rcRadio.bottom = size.cy;
- SetRect(&rc, ((size.cx-rcRadio.right)/2)+1, ((size.cy-rcRadio.bottom)/2)+1, rcRadio.right+1, rcRadio.bottom+1);
- /* unchecked */
- if (BitBlt(hdcMono, 0, 0, rcRadio.right, rcRadio.bottom, NULL, 0, 0, WHITENESS)) { /* white back */
- if (DrawFrameControl(hdcMono, &rcRadio, DFC_BUTTON, DFCS_BUTTONRADIO|DFCS_FLAT)) {
- if (BitBlt(hdc, rc.left, rc.top, rcRadio.right, rcRadio.bottom, hdcMono, 0, 0, SRCCOPY|NOMIRRORBITMAP)) {
- /* checked */
- OffsetRect(&rc, size.cx, 0);
- if (BitBlt(hdcMono, 0, 0, rcRadio.right, rcRadio.bottom, NULL, 0, 0, WHITENESS)) {/* white back */
- if (DrawFrameControl(hdcMono, &rcRadio, DFC_BUTTON, DFCS_BUTTONRADIO|DFCS_FLAT|DFCS_CHECKED)) {
- if (BitBlt(hdc, rc.left, rc.top, rcRadio.right, rcRadio.bottom, hdcMono, 0, 0, SRCCOPY|NOMIRRORBITMAP))
- himl = ImageList_Create(size.cx, size.cy, ILC_COLOR|ILC_MASK, 3, 0);
- } else BOX("second DrawFrameControl() failed");
- } else BOX("second BitBlt() failed");
- } else BOX("intermediate BitBlt() failed");
- } else BOX("DrawFrameControl() failed");
- } else BOX("first BitBlt() failed");
- /* restore */
- SetBkColor(hdc, clrPrevBk);
- SetTextColor(hdc, clrPrevText);
- SelectObject(hdcMono, hbmPrevMono);
- } else BOX("hbmPrevMono == NULL");
- DeleteObject(hbmMono);
- } else BOX("hbmMono == NULL");
- DeleteDC(hdcMono);
- } else BOX("hdcMono == NULL");
+ HDC hdcScreen = GetDC(NULL);
+ if (hdcScreen == NULL)
+ return NULL;
+
+ HIMAGELIST himl = NULL;
+ HDC hdc = CreateCompatibleDC(NULL); /* compatible to screen */
+ if (hdc != NULL) {
+ SIZE size = { GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON) };
+ RECT rc;
+ SetRect(&rc, 0, 0, 2 * size.cx, size.cy);
+ HBITMAP hbm = CreateCompatibleBitmap(hdcScreen, rc.right, rc.bottom);
+ if (hbm != NULL) {
+ HBITMAP hbmPrev = (HBITMAP)SelectObject(hdc, hbm);
+ if (hbmPrev != NULL) { /* error on select? */
+ HTHEME hTheme = OpenThemeData(NULL, L"Button");
+ SetRect(&rc, 0, 0, size.cx, size.cy);
+ /* unchecked */
+ if (!DrawThemeBackground(hTheme, hdc, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL, &rc, NULL)) {
+ /* checked */
+ OffsetRect(&rc, size.cx, 0);
+ if (!DrawThemeBackground(hTheme, hdc, BP_RADIOBUTTON, RBS_CHECKEDNORMAL, &rc, NULL))
+ himl = ImageList_Create(size.cx, size.cy, ILC_COLOR32 | ILC_MASK, 3, 0);
+ }
+ CloseThemeData(hTheme);
+
+ /* the classic way */
+ if (himl == NULL) {
+ RECT rcRadio;
+ HBRUSH hbrBk = CreateSolidBrush(clrBk);
+ if (hbrBk != NULL) {
+ FillRect(hdc, &rc, hbrBk);
+ DeleteObject(hbrBk);
+ HDC hdcMono = CreateCompatibleDC(hdc);
+ if (hdcMono != NULL) {
+ HBITMAP hbmMono = CreateBitmap(rc.right, rc.bottom, 1, 1, NULL);
+ if (hbmMono != NULL) {
+ HBITMAP hbmPrevMono = (HBITMAP)SelectObject(hdcMono, hbmMono);
+ if (hbmPrevMono != NULL) { /* error on select? */
+ /* draws a black-and-white mask (see docs)
+ * we need to colorize it using BitBlt with text and background color */
+ COLORREF clrPrevText = SetTextColor(hdc, clrText);
+ COLORREF clrPrevBk = SetBkColor(hdc, clrBk);
+ /* check mark is slightly smaller than icon size */
+ SetRect(&rcRadio, 0, 0, GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK));
+ if (rcRadio.right > size.cx) rcRadio.right = size.cx;
+ if (rcRadio.bottom > size.cy) rcRadio.bottom = size.cy;
+ SetRect(&rc, ((size.cx - rcRadio.right) / 2) + 1, ((size.cy - rcRadio.bottom) / 2) + 1, rcRadio.right + 1, rcRadio.bottom + 1);
+ /* unchecked */
+ if (BitBlt(hdcMono, 0, 0, rcRadio.right, rcRadio.bottom, NULL, 0, 0, WHITENESS)) { /* white back */
+ if (DrawFrameControl(hdcMono, &rcRadio, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_FLAT)) {
+ if (BitBlt(hdc, rc.left, rc.top, rcRadio.right, rcRadio.bottom, hdcMono, 0, 0, SRCCOPY | NOMIRRORBITMAP)) {
+ /* checked */
+ OffsetRect(&rc, size.cx, 0);
+ if (BitBlt(hdcMono, 0, 0, rcRadio.right, rcRadio.bottom, NULL, 0, 0, WHITENESS)) {/* white back */
+ if (DrawFrameControl(hdcMono, &rcRadio, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_FLAT | DFCS_CHECKED)) {
+ if (BitBlt(hdc, rc.left, rc.top, rcRadio.right, rcRadio.bottom, hdcMono, 0, 0, SRCCOPY | NOMIRRORBITMAP))
+ himl = ImageList_Create(size.cx, size.cy, ILC_COLOR | ILC_MASK, 3, 0);
+ }
+ else BOX("second DrawFrameControl() failed");
+ }
+ else BOX("second BitBlt() failed");
+ }
+ else BOX("intermediate BitBlt() failed");
+ }
+ else BOX("DrawFrameControl() failed");
+ }
+ else BOX("first BitBlt() failed");
+ /* restore */
+ SetBkColor(hdc, clrPrevBk);
+ SetTextColor(hdc, clrPrevText);
+ SelectObject(hdcMono, hbmPrevMono);
+ }
+ else BOX("hbmPrevMono == NULL");
+ DeleteObject(hbmMono);
+ }
+ else BOX("hbmMono == NULL");
+ DeleteDC(hdcMono);
}
+ else BOX("hdcMono == NULL");
}
- SelectObject(hdc, hbmPrev);
- /* create imagelist */
- if (himl!=NULL) {
- if (himl == NULL) BOX("img list create failed");
- if (himl!=NULL) if (ImageList_AddMasked(himl, hbm, clrBk) == -1) BOX("add failed");
- } else BOX("Win9x: drawing code not reached");
}
- DeleteObject(hbm);
+ SelectObject(hdc, hbmPrev);
+ /* create imagelist */
+ if (himl != NULL) {
+ if (himl == NULL) BOX("img list create failed");
+ if (himl != NULL) if (ImageList_AddMasked(himl, hbm, clrBk) == -1) BOX("add failed");
+ }
+ else BOX("Win9x: drawing code not reached");
}
- DeleteDC(hdc);
+ DeleteObject(hbm);
}
- ReleaseDC(NULL, hdcScreen);
+ DeleteDC(hdc);
}
-
+ ReleaseDC(NULL, hdcScreen);
return himl;
}
@@ -146,62 +150,63 @@ static void CleanupPluginName(char *szShortName) static void DisplayNotIncludedPlugins(HWND hwndListBox, const LANGPACK_INFO *pack)
{
- TCHAR szSearch[MAX_PATH], szDir[MAX_PATH], *p;
- BOOL fNeedsFree;
- char buf[128];
- TCHAR buf2[128];
- PLUGININFOEX *pluginInfo;
- PLUGININFOEX *(__cdecl *MirandaPluginInfo)(DWORD);
-
/* enum plugins */
- if (!(pack->flags&LPF_DEFAULT) && GetModuleFileName(NULL, szDir, SIZEOF(szDir))) {
- p = _tcsrchr(szDir, _T('\\'));
- if (p!=NULL) *p = _T('\0');
+ TCHAR szDir[MAX_PATH];
+ if (!(pack->flags & LPF_DEFAULT) && GetModuleFileName(NULL, szDir, SIZEOF(szDir))) {
+ TCHAR *p = _tcsrchr(szDir, _T('\\'));
+ if (p != NULL)
+ *p = _T('\0');
+
TCHAR szSearch[MAX_PATH];
mir_sntprintf(szSearch, SIZEOF(szSearch), _T("%s\\Plugins\\*.dll"), szDir);
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile(szSearch, &wfd);
- if (hFind!=INVALID_HANDLE_VALUE) {
+ if (hFind != INVALID_HANDLE_VALUE) {
DWORD mirandaVersion = CallService(MS_SYSTEM_GETVERSION, 0, 0);
SendMessage(hwndListBox, LB_SETLOCALE, CallService(MS_LANGPACK_GETLOCALE, 0, 0), 0); /* for sort order */
SendMessage(hwndListBox, LB_INITSTORAGE, 128, lstrlenA(pack->szPluginsIncluded)); /* speed up */
do {
if (wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) continue;
- if ((lstrlen(wfd.cFileName)<4) || (wfd.cFileName[lstrlen(wfd.cFileName)-4]!=_T('.'))) continue;
+ if ((lstrlen(wfd.cFileName) < 4) || (wfd.cFileName[lstrlen(wfd.cFileName) - 4] != _T('.'))) continue;
/* file name */
lstrcpy(szSearch, wfd.cFileName); /* buffer safe */
p = _tcsrchr(szSearch, _T('.'));
- if (p!=NULL) *p = _T('\0');
+ if (p != NULL)
+ *p = _T('\0');
- {
- char cFileNameA[MAX_PATH];
- cFileNameA[0] = '\0';
- WideCharToMultiByte(CP_ACP, 0, szSearch, -1, cFileNameA, sizeof(cFileNameA), NULL, NULL);
- if (IsPluginIncluded(pack, cFileNameA))
- continue;
- }
+ char cFileNameA[MAX_PATH];
+ cFileNameA[0] = '\0';
+ WideCharToMultiByte(CP_ACP, 0, szSearch, -1, cFileNameA, sizeof(cFileNameA), NULL, NULL);
+ if (IsPluginIncluded(pack, cFileNameA))
+ continue;
/* friendly name of the plugin */
mir_sntprintf(szSearch, SIZEOF(szSearch), _T("%s\\Plugins\\%s"), szDir, wfd.cFileName);
HMODULE hModule = GetModuleHandle(szSearch);
- fNeedsFree = (hModule == NULL);
+ bool fNeedsFree = (hModule == NULL);
if (hModule == NULL) {
hModule = LoadLibrary(szSearch);
if (hModule == NULL) continue;
}
+
/* plugin info */
- *(PROC*)&MirandaPluginInfo = GetProcAddress(hModule, "MirandaPluginInfoEx");
- if (MirandaPluginInfo!=NULL) { /* both structs have the same header */
- pluginInfo = MirandaPluginInfo(mirandaVersion);
- if (pluginInfo!=NULL && pluginInfo->cbSize >= sizeof(PLUGININFOEX) && pluginInfo->shortName!=NULL) {
+ pfnMirandaPluginInfo pFunc = (pfnMirandaPluginInfo)GetProcAddress(hModule, "MirandaPluginInfoEx");
+ if (pFunc != NULL) { /* both structs have the same header */
+ PLUGININFOEX *pluginInfo = pFunc(mirandaVersion);
+ if (pluginInfo != NULL && pluginInfo->cbSize >= sizeof(PLUGININFOEX) && pluginInfo->shortName != NULL) {
+ char buf[128];
lstrcpynA(buf, pluginInfo->shortName, sizeof(buf)); /* buffer safe */
CleanupPluginName(buf);
+
+ TCHAR buf2[128];
mir_sntprintf(buf2, SIZEOF(buf2), _T("%hs (%s)"), buf, CharLower(wfd.cFileName));
SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)buf2);
}
}
- if (fNeedsFree) FreeLibrary(hModule);
- } while(FindNextFile(hFind, &wfd));
+ if (fNeedsFree)
+ FreeLibrary(hModule);
+ }
+ while (FindNextFile(hFind, &wfd));
FindClose(hFind);
}
}
@@ -216,15 +221,16 @@ static void DisplayPackInfo(HWND hwndDlg, const LANGPACK_INFO *pack) SendDlgItemMessage(hwndDlg, IDC_LANGNOTINCLUDED, LB_RESETCONTENT, 0, 0);
DisplayNotIncludedPlugins(GetDlgItem(hwndDlg, IDC_LANGNOTINCLUDED), pack);
/* locale string */
- if (!(pack->flags&LPF_NOLOCALE)) {
+ if (!(pack->flags & LPF_NOLOCALE)) {
TCHAR szLocaleName[128];
szLocaleName[0] = _T('\0');
/* can't use LOCALE_SNAME as it is not present on pre WinVista */
if (!GetLocaleInfo(pack->Locale, LOCALE_SISO639LANGNAME, szLocaleName, SIZEOF(szLocaleName))) { /* Win98/NT4+ */
if (!GetLocaleInfo(pack->Locale, LOCALE_SLANGUAGE, szLocaleName, SIZEOF(szLocaleName))) /* not unique! */
szLocaleName[0] = _T('\0');
- } else {
- if (GetLocaleInfo(pack->Locale, LOCALE_SISO3166CTRYNAME, &szLocaleName[3], SIZEOF(szLocaleName)-3)) /* Win98/NT4+ */
+ }
+ else {
+ if (GetLocaleInfo(pack->Locale, LOCALE_SISO3166CTRYNAME, &szLocaleName[3], SIZEOF(szLocaleName) - 3)) /* Win98/NT4+ */
szLocaleName[2] = _T('-');
}
/* add some note if its incompatible */
@@ -232,7 +238,7 @@ static void DisplayPackInfo(HWND hwndDlg, const LANGPACK_INFO *pack) if (!IsValidLocale(pack->Locale, LCID_INSTALLED)) {
TCHAR *pszIncompat;
pszIncompat = TranslateT("(incompatible)");
- szLocaleName[SIZEOF(szLocaleName)-lstrlen(pszIncompat)-1] = 0;
+ szLocaleName[SIZEOF(szLocaleName) - lstrlen(pszIncompat) - 1] = 0;
lstrcat(lstrcat(szLocaleName, _T(" ")), pszIncompat); /* buffer safe */
}
SetDlgItemText(hwndDlg, IDC_LANGLOCALE, szLocaleName);
@@ -240,14 +246,15 @@ static void DisplayPackInfo(HWND hwndDlg, const LANGPACK_INFO *pack) else SetDlgItemText(hwndDlg, IDC_LANGLOCALE, TranslateT("Unknown"));
}
else SetDlgItemText(hwndDlg, IDC_LANGLOCALE, TranslateT("Current"));
+
/* file date */
- { SYSTEMTIME stFileDate;
- TCHAR szDate[128];
- szDate[0] = _T('\0');
- if (FileTimeToSystemTime(&pack->ftFileDate, &stFileDate))
- GetDateFormat((LCID)CallService(MS_LANGPACK_GETLOCALE, 0, 0), DATE_SHORTDATE, &stFileDate, NULL, szDate, SIZEOF(szDate));
- SetDlgItemText(hwndDlg, IDC_LANGDATE, szDate);
- }
+ SYSTEMTIME stFileDate;
+ TCHAR szDate[128];
+ szDate[0] = _T('\0');
+ if (FileTimeToSystemTime(&pack->ftFileDate, &stFileDate))
+ GetDateFormat((LCID)CallService(MS_LANGPACK_GETLOCALE, 0, 0), DATE_SHORTDATE, &stFileDate, NULL, szDate, SIZEOF(szDate));
+ SetDlgItemText(hwndDlg, IDC_LANGDATE, szDate);
+
/* version */
SetDlgItemTextA(hwndDlg, IDC_LANGVERSION, pack->szVersion);
if (pack->szVersion[0] && pack->szFLName[0]) {
@@ -255,10 +262,12 @@ static void DisplayPackInfo(HWND hwndDlg, const LANGPACK_INFO *pack) ShowWindow(GetDlgItem(hwndDlg, IDC_LANGVERSIONLABEL), SW_SHOW);
ShowWindow(GetDlgItem(hwndDlg, IDC_LANGVERSION), SW_SHOW);
}
- } else {
+ }
+ else {
ShowWindow(GetDlgItem(hwndDlg, IDC_LANGVERSIONLABEL), SW_HIDE);
ShowWindow(GetDlgItem(hwndDlg, IDC_LANGVERSION), SW_HIDE);
}
+
/* general */
SetDlgItemTextA(hwndDlg, IDC_LANGMODUSING, pack->szLastModifiedUsing);
SetDlgItemTextA(hwndDlg, IDC_LANGAUTHORS, pack->szAuthors);
@@ -273,20 +282,19 @@ static void DisplayPackInfo(HWND hwndDlg, const LANGPACK_INFO *pack) static void DeletePackFile(HWND hwndDlg, HWND hwndList, int iItem, LANGPACK_INFO *pack)
{
- SHFILEOPSTRUCT sfo;
- TCHAR szFileName[MAX_PATH];
- ZeroMemory(&sfo, sizeof(sfo));
+ SHFILEOPSTRUCT sfo = { 0 };
sfo.hwnd = hwndDlg;
sfo.wFunc = FO_DELETE;
sfo.fFlags = FOF_SIMPLEPROGRESS|FOF_SILENT; /* silent = no progress */
+
/* double zero terminated */
- if (GetPackPath(szFileName, SIZEOF(szFileName)-1, pack->flags&LPF_ENABLED, pack->szFileName)) {
+ TCHAR szFileName[MAX_PATH];
+ if (GetPackPath(szFileName, SIZEOF(szFileName) - 1, pack->flags & LPF_ENABLED, pack->szFileName)) {
szFileName[lstrlen(szFileName)+1] = _T('\0');
sfo.pFrom = szFileName;
/* ask to delete file */
if (!SHFileOperation(&sfo) && !sfo.fAnyOperationsAborted) {
LVITEM lvi;
- int nCount;
lvi.iItem = iItem;
lvi.iSubItem = 0;
lvi.mask = LVIF_STATE;
@@ -294,11 +302,11 @@ static void DeletePackFile(HWND hwndDlg, HWND hwndList, int iItem, LANGPACK_INFO if (ListView_GetItem(hwndList, &lvi)) {
ListView_DeleteItem(hwndList, iItem);
/* enable/select next item at same position */
- nCount = ListView_GetItemCount(hwndList);
- if (iItem<nCount) lvi.iItem = iItem;
- else lvi.iItem = iItem-1;
+ int nCount = ListView_GetItemCount(hwndList);
+ lvi.iItem = (iItem < nCount) ? iItem : iItem - 1;
ListView_SetItemState(hwndList, lvi.iItem, lvi.state, lvi.stateMask);
- if (nCount == 1) SendMessage(hwndDlg, M_SHOWFILECOL, 0, FALSE);
+ if (nCount == 1)
+ SendMessage(hwndDlg, M_SHOWFILECOL, 0, FALSE);
}
}
}
@@ -306,36 +314,33 @@ static void DeletePackFile(HWND hwndDlg, HWND hwndList, int iItem, LANGPACK_INFO static BOOL InsertPackItemEnumProc(LANGPACK_INFO *pack, WPARAM wParam, LPARAM lParam)
{
- LVITEM lvi;
- LANGPACK_INFO *pack2;
- UNREFERENCED_PARAMETER(lParam);
-
- pack2 = (LANGPACK_INFO*)mir_alloc(sizeof(LANGPACK_INFO));
+ LANGPACK_INFO *pack2 = (LANGPACK_INFO*)mir_alloc(sizeof(LANGPACK_INFO));
if (pack2 == NULL) return FALSE;
CopyMemory(pack2, pack, sizeof(LANGPACK_INFO));
+
/* country flag icon */
- lvi.mask = LVIF_TEXT|LVIF_PARAM|LVIF_STATE;
+ LVITEM lvi;
+ lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
if ((HIMAGELIST)lParam != NULL) {
HICON hIcon;
- if (pack->flags&LPF_DEFAULT)
+ if (pack->flags & LPF_DEFAULT)
hIcon = (HICON)CallService(MS_FLAGS_CREATEMERGEDFLAGICON, CTRY_UNITED_STATES, CTRY_UNITED_KINGDOM);
else {
int countryId = 0xFFFF; /* Unknown */
TCHAR szBuf[6];
/* get country id from locale */
- if (!(pack->flags&LPF_NOLOCALE))
+ if (!(pack->flags & LPF_NOLOCALE))
if (GetLocaleInfo(pack->Locale, LOCALE_ICOUNTRY, szBuf, SIZEOF(szBuf)))
countryId = _ttoi(szBuf);
hIcon = (HICON)CallService(MS_FLAGS_LOADFLAGICON, countryId, 0);
}
- if (hIcon == NULL) lvi.iImage = -1;
- else lvi.iImage = ImageList_AddIcon((HIMAGELIST)lParam, hIcon);
+ lvi.iImage = (hIcon == NULL) ? -1 : ImageList_AddIcon((HIMAGELIST)lParam, hIcon);
lvi.mask |= LVIF_IMAGE;
}
/* insert */
lvi.iItem = lvi.iSubItem = 0;
lvi.stateMask = LVIS_STATEIMAGEMASK | LVIS_SELECTED;
- lvi.state = INDEXTOSTATEIMAGEMASK((pack->flags&LPF_ENABLED)?2:1);
+ lvi.state = INDEXTOSTATEIMAGEMASK((pack->flags & LPF_ENABLED)?2:1);
if (pack->flags & LPF_ENABLED)
lvi.state |= LVIS_SELECTED | LVIS_FOCUSED;
lvi.pszText = TranslateTS(pack->szLanguage);
@@ -347,9 +352,9 @@ static BOOL InsertPackItemEnumProc(LANGPACK_INFO *pack, WPARAM wParam, LPARAM lP static int CALLBACK CompareListItem(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
- int cmp;
- cmp = CompareString((LCID)lParamSort, 0, ((LANGPACK_INFO*)lParam1)->szLanguage, -1, ((LANGPACK_INFO*)lParam2)->szLanguage, -1);
- if (cmp!=0) cmp -= 2;
+ int cmp = CompareString((LCID)lParamSort, 0, ((LANGPACK_INFO*)lParam1)->szLanguage, -1, ((LANGPACK_INFO*)lParam2)->szLanguage, -1);
+ if (cmp != 0)
+ cmp -= 2;
return cmp;
}
@@ -360,6 +365,7 @@ static HWND hwndLangOpt; static INT_PTR CALLBACK LangOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
HWND hwndList = GetDlgItem(hwndDlg, IDC_LANGLIST);
+ LVITEM lvi;
switch(msg) {
case WM_INITDIALOG:
@@ -401,23 +407,22 @@ static INT_PTR CALLBACK LangOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP return TRUE;
case M_SHOWFILECOL:
- if ((BOOL)lParam && ListView_GetItemCount(hwndList)>1) {
- LVCOLUMN lvc;
- LVITEM lvi;
- LANGPACK_INFO *pack;
+ if ((BOOL)lParam && ListView_GetItemCount(hwndList) > 1) {
/* add column */
+ LVCOLUMN lvc;
ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE_USEHEADER);
- lvc.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;
+ lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
lvc.pszText = TranslateT("File");
lvc.cx = 160;
ListView_InsertColumn(hwndList, lvc.iSubItem = 1, &lvc);
- ListView_SetColumnWidth(hwndList, 0, ListView_GetColumnWidth(hwndList, 0)-lvc.cx);
+ ListView_SetColumnWidth(hwndList, 0, ListView_GetColumnWidth(hwndList, 0) - lvc.cx);
+
/* add text */
lvi.mask = LVIF_PARAM;
lvi.iSubItem = 0;
- for(lvi.iItem = 0;ListView_GetItem(hwndList, &lvi);++lvi.iItem) {
- pack = (LANGPACK_INFO*)lvi.lParam;
- ListView_SetItemText(hwndList, lvi.iItem, 1, (pack->flags&LPF_DEFAULT)?TranslateT("built-in"):pack->szFileName);
+ for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) {
+ LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
+ ListView_SetItemText(hwndList, lvi.iItem, 1, (pack->flags&LPF_DEFAULT) ? TranslateT("built-in") : pack->szFileName);
}
}
else {
@@ -461,41 +466,44 @@ static INT_PTR CALLBACK LangOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP case WM_CONTEXTMENU:
if (GetDlgCtrlID((HWND)wParam) == IDC_LANGLIST) {
- LVHITTESTINFO hti;
- HMENU hContextMenu;
- RECT rc;
- LVITEM lvi;
- LANGPACK_INFO *pack;
/* get item */
+ LVHITTESTINFO hti;
POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
if (hti.pt.x == -1 && hti.pt.y == -1) {
/* keyboard invoked */
hti.iItem = ListView_GetNextItem((HWND)wParam, -1, LVNI_SELECTED);
- if (hti.iItem!=-1)
+ if (hti.iItem != -1)
break;
+
+ RECT rc;
if (!ListView_GetItemRect((HWND)wParam, hti.iItem, &rc, LVIR_SELECTBOUNDS))
break;
- hti.pt.x = rc.left+(rc.right-rc.left)/2;
- hti.pt.y = rc.top+(rc.bottom-rc.top)/2;
+
+ hti.pt.x = rc.left + (rc.right - rc.left) / 2;
+ hti.pt.y = rc.top + (rc.bottom - rc.top) / 2;
ClientToScreen((HWND)wParam, &hti.pt);
- } else {
+ }
+ else {
ScreenToClient((HWND)wParam, &hti.pt);
if (ListView_HitTest((HWND)wParam, &hti) == -1 || !(hti.flags&LVHT_ONITEM))
break;
POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
}
+
/* param */
lvi.iItem = hti.iItem;
lvi.iSubItem = 0;
lvi.mask = LVIF_PARAM;
- if (!ListView_GetItem((HWND)wParam, &lvi)) break;
- pack = (LANGPACK_INFO*)lvi.lParam;
+ if (!ListView_GetItem((HWND)wParam, &lvi))
+ break;
+
/* context menu */
- if (!(pack->flags&LPF_DEFAULT)) {
- hContextMenu = CreatePopupMenu();
- if (hContextMenu!=NULL) {
+ LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
+ if (!(pack->flags & LPF_DEFAULT)) {
+ HMENU hContextMenu = CreatePopupMenu();
+ if (hContextMenu != NULL) {
AppendMenu(hContextMenu, MF_STRING, 2, TranslateT("&Remove..."));
- if (TrackPopupMenuEx(hContextMenu, TPM_RETURNCMD|TPM_NONOTIFY|TPM_TOPALIGN|TPM_LEFTALIGN|TPM_RIGHTBUTTON|TPM_HORPOSANIMATION|TPM_VERPOSANIMATION, hti.pt.x, hti.pt.y, (HWND)wParam, NULL))
+ if (TrackPopupMenuEx(hContextMenu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_HORPOSANIMATION | TPM_VERPOSANIMATION, hti.pt.x, hti.pt.y, (HWND)wParam, NULL))
DeletePackFile(hwndDlg, (HWND)wParam, hti.iItem, pack);
DestroyMenu(hContextMenu);
}
@@ -509,107 +517,96 @@ static INT_PTR CALLBACK LangOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP return TRUE;
case WM_NOTIFY:
- {
- NMHDR *nmhdr = (NMHDR*)lParam;
- switch(nmhdr->idFrom) {
- case IDC_LANGLIST:
- switch(nmhdr->code) {
- case LVN_DELETEITEM:
- {
- LVITEM lvi;
- lvi.iItem = ((NMLISTVIEW*)lParam)->iItem; /* nmlv->lParam is invalid */
- lvi.iSubItem = 0;
- lvi.mask = LVIF_PARAM;
- if (ListView_GetItem(nmhdr->hwndFrom, &lvi))
- mir_free((LANGPACK_INFO*)lvi.lParam);
- break;
- }
- case LVN_ITEMCHANGED:
- {
- NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
- if (!(nmlv->uChanged&LVIF_STATE)) break;
- /* display info and check radio item */
- if (nmlv->uNewState&LVIS_SELECTED && !(nmlv->uOldState&LVIS_SELECTED)) {
- ListView_SetItemState(nmhdr->hwndFrom, nmlv->iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
- DisplayPackInfo(hwndDlg, (LANGPACK_INFO*)nmlv->lParam);
- }
- /* disable all other radio items */
- else if (nmlv->uNewState&INDEXTOSTATEIMAGEMASK(2)) {
- int iItem;
- for(iItem = ListView_GetItemCount(nmhdr->hwndFrom)-1;iItem!=-1;--iItem)
- if (iItem!=nmlv->iItem)
- ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);
- /* enable apply */
- if (nmlv->uOldState) {
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), SW_SHOW);
- }
- }
+ NMHDR *nmhdr = (NMHDR*)lParam;
+ switch (nmhdr->idFrom) {
+ case IDC_LANGLIST:
+ switch (nmhdr->code) {
+ case LVN_DELETEITEM:
+ lvi.iItem = ((NMLISTVIEW*)lParam)->iItem; /* nmlv->lParam is invalid */
+ lvi.iSubItem = 0;
+ lvi.mask = LVIF_PARAM;
+ if (ListView_GetItem(nmhdr->hwndFrom, &lvi))
+ mir_free((LANGPACK_INFO*)lvi.lParam);
+ break;
+
+ case LVN_ITEMCHANGED:
+ {
+ NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
+ if (!(nmlv->uChanged&LVIF_STATE))
break;
+
+ /* display info and check radio item */
+ if (nmlv->uNewState&LVIS_SELECTED && !(nmlv->uOldState&LVIS_SELECTED)) {
+ ListView_SetItemState(nmhdr->hwndFrom, nmlv->iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
+ DisplayPackInfo(hwndDlg, (LANGPACK_INFO*)nmlv->lParam);
}
- case LVN_KEYDOWN:
- {
- int iItem = ListView_GetNextItem(nmhdr->hwndFrom, -1, LVNI_SELECTED);
- switch(((NMLVKEYDOWN*)lParam)->wVKey) {
- case VK_SPACE:
- ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
- break;
-
- case VK_DELETE:
- {
- LVITEM lvi;
- LANGPACK_INFO *pack;
- lvi.iItem = iItem;
- lvi.iSubItem = 0;
- lvi.mask = LVIF_PARAM;
- if (ListView_GetItem(nmhdr->hwndFrom, &lvi)) {
- pack = (LANGPACK_INFO*)lvi.lParam;
- if (!(pack->flags&LPF_DEFAULT))
- DeletePackFile(hwndDlg, nmhdr->hwndFrom, iItem, pack);
- }
- break;
- }
+ /* disable all other radio items */
+ else if (nmlv->uNewState&INDEXTOSTATEIMAGEMASK(2)) {
+ for (int iItem = ListView_GetItemCount(nmhdr->hwndFrom) - 1; iItem != -1; --iItem)
+ if (iItem != nmlv->iItem)
+ ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);
+
+ /* enable apply */
+ if (nmlv->uOldState) {
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), SW_SHOW);
}
- break;
}
- case NM_CLICK:
- {
- LVHITTESTINFO hti;
- lParam = GetMessagePos();
- POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
- ScreenToClient(nmhdr->hwndFrom, &hti.pt);
- if (ListView_HitTest(nmhdr->hwndFrom, &hti)!=-1)
- if (hti.flags&(LVHT_ONITEMSTATEICON|LVHT_ONITEMICON)) /* one of them */
- ListView_SetItemState(nmhdr->hwndFrom, hti.iItem, LVIS_SELECTED, LVIS_SELECTED);
- break;
- }
- } /* switch nmhdr->code */
+ }
break;
- case 0:
- switch(nmhdr->code) {
- case PSN_APPLY:
- {
- LVITEM lvi;
- lvi.mask = LVIF_STATE|LVIF_PARAM;
- lvi.stateMask = LVIS_STATEIMAGEMASK;
+ case LVN_KEYDOWN:
+ {
+ int iItem = ListView_GetNextItem(nmhdr->hwndFrom, -1, LVNI_SELECTED);
+ switch (((NMLVKEYDOWN*)lParam)->wVKey) {
+ case VK_SPACE:
+ ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
+ break;
+
+ case VK_DELETE:
+ lvi.iItem = iItem;
lvi.iSubItem = 0;
- for(lvi.iItem = 0;ListView_GetItem(hwndList, &lvi);++lvi.iItem) {
+ lvi.mask = LVIF_PARAM;
+ if (ListView_GetItem(nmhdr->hwndFrom, &lvi)) {
LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
- if (lvi.state&INDEXTOSTATEIMAGEMASK(2)) {
- EnablePack(pack, _T("langpack_*.txt"));
- pack->flags |= LPF_ENABLED;
- }
- else pack->flags &= ~LPF_ENABLED;
+ if (!(pack->flags&LPF_DEFAULT))
+ DeletePackFile(hwndDlg, nmhdr->hwndFrom, iItem, pack);
}
- db_set_b(NULL, "LangMan", "EnableAutoUpdates", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_ENABLEAUTOUPDATES)!=0));
- return TRUE;
+ break;
}
- } /* switch nmhdr->code */
+ }
break;
- } /* switch nmhdr->idFrom */
+
+ case NM_CLICK:
+ LVHITTESTINFO hti;
+ lParam = GetMessagePos();
+ POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
+ ScreenToClient(nmhdr->hwndFrom, &hti.pt);
+ if (ListView_HitTest(nmhdr->hwndFrom, &hti) != -1)
+ if (hti.flags&(LVHT_ONITEMSTATEICON | LVHT_ONITEMICON)) /* one of them */
+ ListView_SetItemState(nmhdr->hwndFrom, hti.iItem, LVIS_SELECTED, LVIS_SELECTED);
+ }
break;
+
+ case 0:
+ switch (nmhdr->code) {
+ case PSN_APPLY:
+ lvi.mask = LVIF_STATE | LVIF_PARAM;
+ lvi.stateMask = LVIS_STATEIMAGEMASK;
+ lvi.iSubItem = 0;
+ for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) {
+ LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
+ if (lvi.state&INDEXTOSTATEIMAGEMASK(2)) {
+ EnablePack(pack, _T("langpack_*.txt"));
+ pack->flags |= LPF_ENABLED;
+ }
+ else pack->flags &= ~LPF_ENABLED;
+ }
+ db_set_b(NULL, "LangMan", "EnableAutoUpdates", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_ENABLEAUTOUPDATES) != 0));
+ return TRUE;
+ }
}
+ break;
}
return FALSE;
}
|