diff options
author | George Hazan <ghazan@miranda.im> | 2018-01-26 22:31:20 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-01-26 22:31:27 +0300 |
commit | 391980ce1e890445542441eeb5d9f9cc18ae1baf (patch) | |
tree | ee1b165175dcdaeeaabd2ddb822542e648663a90 /plugins/Popup/src | |
parent | bf8ad124d03b4fd059318d9ba8889b11faaf5b53 (diff) |
code optimization
Diffstat (limited to 'plugins/Popup/src')
-rw-r--r-- | plugins/Popup/src/actions.cpp | 17 | ||||
-rw-r--r-- | plugins/Popup/src/icons.cpp | 12 | ||||
-rw-r--r-- | plugins/Popup/src/opt_class.cpp | 76 |
3 files changed, 52 insertions, 53 deletions
diff --git a/plugins/Popup/src/actions.cpp b/plugins/Popup/src/actions.cpp index 9235521bec..181297e265 100644 --- a/plugins/Popup/src/actions.cpp +++ b/plugins/Popup/src/actions.cpp @@ -45,8 +45,8 @@ void LoadActions() { sizeof(POPUPACTION), LoadIconEx(IDI_ACT_COPY), LPGEN("General") "/" LPGEN("Copy to clipboard"), 0 },
};
- for (int i = 0; i < _countof(actions); ++i)
- RegisterAction(&actions[i]);
+ for (auto &it : actions)
+ RegisterAction(&it);
}
void UnloadActions()
@@ -174,7 +174,6 @@ static UINT controls[] = INT_PTR CALLBACK DlgProcPopupActions(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static bool windowInitialized = false;
- int i;
switch (msg) {
case WM_INITDIALOG:
@@ -224,7 +223,7 @@ INT_PTR CALLBACK DlgProcPopupActions(HWND hwnd, UINT msg, WPARAM wParam, LPARAM LIST<char> groups(1, strcmp);
- for (i = 0; i < gActions.getCount(); ++i) {
+ for (int i = 0; i < gActions.getCount(); ++i) {
char szGroup[64];
char *szName = strchr(gActions[i]->lpzTitle, '/');
if (!szName) szName = gActions[i]->lpzTitle;
@@ -261,8 +260,8 @@ INT_PTR CALLBACK DlgProcPopupActions(HWND hwnd, UINT msg, WPARAM wParam, LPARAM }
BOOL enabled = (PopupOptions.actions & ACT_ENABLE) ? TRUE : FALSE;
- for (i = 0; i < _countof(controls); ++i)
- EnableWindow(GetDlgItem(hwnd, controls[i]), enabled);
+ for (auto &it : controls)
+ EnableWindow(GetDlgItem(hwnd, it), enabled);
}
windowInitialized = true;
break;
@@ -275,8 +274,8 @@ INT_PTR CALLBACK DlgProcPopupActions(HWND hwnd, UINT msg, WPARAM wParam, LPARAM SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
{
BOOL enabled = (PopupOptions.actions & ACT_ENABLE) ? TRUE : FALSE;
- for (i = 0; i < _countof(controls); ++i)
- EnableWindow(GetDlgItem(hwnd, controls[i]), enabled);
+ for (auto &it : controls)
+ EnableWindow(GetDlgItem(hwnd, it), enabled);
}
break;
@@ -344,7 +343,7 @@ INT_PTR CALLBACK DlgProcPopupActions(HWND hwnd, UINT msg, WPARAM wParam, LPARAM db_set_dw(NULL, MODULNAME, "Actions", PopupOptions.actions);
HWND hwndList = GetDlgItem(hwnd, IDC_ACTIONS);
- for (i = 0; i < gActions.getCount(); ++i) {
+ for (int i = 0; i < gActions.getCount(); ++i) {
gActions[i]->flags = (ListView_GetItemState(hwndList, i, LVIS_STATEIMAGEMASK) == 0x2000) ? PAF_ENABLED : 0;
db_set_b(NULL, "PopupActions", gActions[i]->lpzTitle, (gActions[i]->flags & PAF_ENABLED) ? 1 : 0);
}
diff --git a/plugins/Popup/src/icons.cpp b/plugins/Popup/src/icons.cpp index 297a9d982f..b1b5a985fc 100644 --- a/plugins/Popup/src/icons.cpp +++ b/plugins/Popup/src/icons.cpp @@ -69,18 +69,18 @@ void InitIcons() HICON LoadIconEx(int iconId, bool big)
{
- for (int i = 0; i < _countof(iconList); i++)
- if (iconList[i].defIconID == iconId)
- return IcoLib_GetIconByHandle(iconList[i].hIcolib, big);
+ for (auto &it : iconList)
+ if (it.defIconID == iconId)
+ return IcoLib_GetIconByHandle(it.hIcolib, big);
return nullptr;
}
HANDLE GetIconHandle(int iconId)
{
- for (int i = 0; i < _countof(iconList); i++)
- if (iconList[i].defIconID == iconId)
- return iconList[i].hIcolib;
+ for (auto &it : iconList)
+ if (it.defIconID == iconId)
+ return it.hIcolib;
return nullptr;
}
diff --git a/plugins/Popup/src/opt_class.cpp b/plugins/Popup/src/opt_class.cpp index 742bc2dbee..1b7cf2b05c 100644 --- a/plugins/Popup/src/opt_class.cpp +++ b/plugins/Popup/src/opt_class.cpp @@ -168,8 +168,6 @@ static statusButtons[] = { INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- int i;
-
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwnd);
@@ -183,7 +181,7 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l ImageList_ReplaceIcon(hImgLst, -1, LoadIconEx(IDI_OPT_GROUP));
TreeView_SetImageList(hwndTree, hImgLst, TVSIL_NORMAL);
- for (i = 0; i < gTreeData.getCount(); ++i) {
+ for (int i = 0; i < gTreeData.getCount(); ++i) {
POPUPTREEDATA *p = gTreeData[i];
wchar_t itemName[MAXMODULELABELLENGTH];
@@ -202,24 +200,24 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l OptTree_Translate(hwndTree);
// Bold Title
- for (i = 0; i < _countof(titleIds); ++i) {
+ for (auto &it : titleIds) {
LOGFONT lf;
- GetObject((HFONT)SendDlgItemMessage(hwnd, titleIds[i], WM_GETFONT, 0, 0), sizeof(lf), &lf);
+ GetObject((HFONT)SendDlgItemMessage(hwnd, it, WM_GETFONT, 0, 0), sizeof(lf), &lf);
lf.lfWeight = FW_BOLD;
- SendDlgItemMessage(hwnd, titleIds[i], WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), TRUE);
+ SendDlgItemMessage(hwnd, it, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), TRUE);
}
// spindown for Timeout
SendDlgItemMessage(hwnd, IDC_TIMEOUT_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(SETTING_LIFETIME_MAX, SETTING_LIFETIME_INFINITE));
SetDlgItemInt(hwnd, IDC_TIMEOUT, (UINT)0, TRUE);
// status buttons
- for (i = 0; i < _countof(statusButtons); ++i) {
- SendDlgItemMessage(hwnd, statusButtons[i].idCtrl, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwnd, statusButtons[i].idCtrl, BUTTONSETASPUSHBTN, TRUE, 0);
- SendDlgItemMessage(hwnd, statusButtons[i].idCtrl, BM_SETIMAGE,
- IMAGE_ICON, (LPARAM)Skin_LoadIcon(statusButtons[i].iconId));
- SendDlgItemMessage(hwnd, statusButtons[i].idCtrl, BUTTONADDTOOLTIP,
- (WPARAM)Translate(statusButtons[i].title), 0);
+ for (auto &it : statusButtons) {
+ SendDlgItemMessage(hwnd, it.idCtrl, BUTTONSETASFLATBTN, TRUE, 0);
+ SendDlgItemMessage(hwnd, it.idCtrl, BUTTONSETASPUSHBTN, TRUE, 0);
+ SendDlgItemMessage(hwnd, it.idCtrl, BM_SETIMAGE,
+ IMAGE_ICON, (LPARAM)Skin_LoadIcon(it.iconId));
+ SendDlgItemMessage(hwnd, it.idCtrl, BUTTONADDTOOLTIP,
+ (WPARAM)Translate(it.title), 0);
}
// info icon
SendDlgItemMessage(hwnd, IDC_ICO_INFO, STM_SETICON, (WPARAM)LoadIconEx(IDI_MB_INFO), 0);
@@ -265,7 +263,7 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l SendDlgItemMessage(hwnd, IDC_TIMEOUT_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(250, -1));
// combo left action (EXTRA)
hCtrl = GetDlgItem(hwnd, IDC_LACTION);
- for (i = 0; i < ptd->notification.actionCount; ++i) {
+ for (int i = 0; i < ptd->notification.actionCount; ++i) {
psztAction = mir_a2u(ptd->notification.lpActions[i].lpzTitle);
ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateW(psztAction)), ptd->notification.lpActions[i].lpzTitle);
mir_free(psztAction); psztAction = nullptr;
@@ -273,25 +271,27 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l // combo right action (EXTRA)
hCtrl = GetDlgItem(hwnd, IDC_RACTION);
psztAction = nullptr;
- for (i = 0; i < ptd->notification.actionCount; ++i) {
+ for (int i = 0; i < ptd->notification.actionCount; ++i) {
psztAction = mir_a2u(ptd->notification.lpActions[i].lpzTitle);
ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateW(psztAction)), ptd->notification.lpActions[i].lpzTitle);
mir_free(psztAction); psztAction = nullptr;
}
// enable all controls
- for (i = 0; i < _countof(ctrlsAll); ++i){
- ShowWindow(GetDlgItem(hwnd, ctrlsAll[i].idCtrl), ctrlsAll[i].onTyp1 ? SW_SHOW : SW_HIDE);
- EnableWindow(GetDlgItem(hwnd, ctrlsAll[i].idCtrl), ctrlsAll[i].onTyp1);
+ for (auto &it : ctrlsAll) {
+ ShowWindow(GetDlgItem(hwnd, it.idCtrl), it.onTyp1 ? SW_SHOW : SW_HIDE);
+ EnableWindow(GetDlgItem(hwnd, it.idCtrl), it.onTyp1);
}
// enable or disable controls ctrlsEnable
- for (i = 0; i < _countof(ctrlsEnable); ++i)
- EnableWindow(GetDlgItem(hwnd, ctrlsEnable[i]), ptd->enabled ? TRUE : FALSE);
+ for (auto &it : ctrlsEnable)
+ EnableWindow(GetDlgItem(hwnd, it), ptd->enabled ? TRUE : FALSE);
+
// show or hide controls ctrlsContact
- for (i = 0; i < _countof(ctrlsContact); ++i)
- ShowWindow(GetDlgItem(hwnd, ctrlsContact[i]), ptd->notification.dwFlags&PNF_CONTACT ? SW_SHOW : SW_HIDE);
+ for (auto &it : ctrlsContact)
+ ShowWindow(GetDlgItem(hwnd, it), ptd->notification.dwFlags&PNF_CONTACT ? SW_SHOW : SW_HIDE);
+
// statusButtons state
- for (i = 0; i < _countof(statusButtons); ++i)
- CheckDlgButton(hwnd, statusButtons[i].idCtrl, ptd->disableWhen & statusButtons[i].disableWhenFlag ? BST_CHECKED : BST_UNCHECKED);
+ for (auto &it : statusButtons)
+ CheckDlgButton(hwnd, it.idCtrl, ptd->disableWhen & it.disableWhenFlag ? BST_CHECKED : BST_UNCHECKED);
}
// element typ2 (CLASS Plugins)
else if (ptd->typ == 2) {
@@ -299,9 +299,9 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l SetDlgItemInt(hwnd, IDC_TIMEOUT, (UINT)ptd->timeoutValue, TRUE);
SendDlgItemMessage(hwnd, IDC_TIMEOUT_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(250, -1));
// enable ctrls
- for (i = 0; i < _countof(ctrlsAll); ++i){
- ShowWindow(GetDlgItem(hwnd, ctrlsAll[i].idCtrl), ctrlsAll[i].onTyp2 ? SW_SHOW : SW_HIDE);
- EnableWindow(GetDlgItem(hwnd, ctrlsAll[i].idCtrl), ctrlsAll[i].onTyp2);
+ for (auto &it : ctrlsAll) {
+ ShowWindow(GetDlgItem(hwnd, it.idCtrl), it.onTyp2 ? SW_SHOW : SW_HIDE);
+ EnableWindow(GetDlgItem(hwnd, it.idCtrl), it.onTyp2);
}
}
// checkbox enable notify
@@ -315,9 +315,9 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l } // end if (tvi.lParam)
else {
// enable / disable controls
- for (i = 0; i < _countof(ctrlsAll); ++i) {
- ShowWindow(GetDlgItem(hwnd, ctrlsAll[i].idCtrl), ctrlsAll[i].onTyp0 ? SW_SHOW : SW_HIDE);
- EnableWindow(GetDlgItem(hwnd, ctrlsAll[i].idCtrl), ctrlsAll[i].onTyp0);
+ for (auto &it : ctrlsAll) {
+ ShowWindow(GetDlgItem(hwnd, it.idCtrl), it.onTyp0 ? SW_SHOW : SW_HIDE);
+ EnableWindow(GetDlgItem(hwnd, it.idCtrl), it.onTyp0);
}
}
}
@@ -333,8 +333,8 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l switch (idCtrl) {
case IDC_ENABLE:
ptd->enabled = (BYTE)Button_GetCheck((HWND)lParam);
- for (i = 0; i < _countof(ctrlsEnable); ++i)
- EnableWindow(GetDlgItem(hwnd, ctrlsEnable[i]), ptd->enabled);
+ for (auto &it : ctrlsEnable)
+ EnableWindow(GetDlgItem(hwnd, it), ptd->enabled);
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
@@ -378,10 +378,10 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l case IDC_SOFFLINE2: case IDC_SONLINE2: case IDC_SAWAY2: case IDC_SNA2: case IDC_SOCCUPIED2:
case IDC_SDND2: case IDC_SFREE4CHAT2: case IDC_SINVISIBLE2: case IDC_SPHONE2: case IDC_SLUNCH2:
ptd->disableWhen = 0;
- for (i = 0; i < _countof(statusButtons); ++i) {
- if (IsDlgButtonChecked(hwnd, statusButtons[i].idCtrl))
- ptd->disableWhen |= statusButtons[i].disableWhenFlag;
- if (idCtrl == (UINT)statusButtons[i].idCtrl)
+ for (auto &it : statusButtons) {
+ if (IsDlgButtonChecked(hwnd, it.idCtrl))
+ ptd->disableWhen |= it.disableWhenFlag;
+ if (idCtrl == (UINT)it.idCtrl)
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
}
}
@@ -438,7 +438,7 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l case 0:
switch (((LPNMHDR)lParam)->code) {
case PSN_RESET:
- for (i = 0; i < gTreeData.getCount(); ++i) {
+ for (int i = 0; i < gTreeData.getCount(); ++i) {
POPUPTREEDATA *p = gTreeData[i];
switch (p->typ) {
case 1:
@@ -453,7 +453,7 @@ INT_PTR CALLBACK DlgProcOptsClasses(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l return TRUE;
case PSN_APPLY:
- for (i = 0; i < gTreeData.getCount(); ++i) {
+ for (int i = 0; i < gTreeData.getCount(); ++i) {
POPUPTREEDATA *p = gTreeData[i];
switch (p->typ) {
case 1:
|