From 4410ef2dede8ef2df794e877b59f656e32c6bc39 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 3 Nov 2014 20:12:09 +0000 Subject: more code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@10913 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Sessions/Src/Main.cpp | 79 +++++----- plugins/Sessions/Src/Options.cpp | 324 +++++++++++++++++++-------------------- plugins/Sessions/Src/Sessions.h | 22 +-- plugins/Sessions/Src/Utils.cpp | 3 +- 4 files changed, 209 insertions(+), 219 deletions(-) diff --git a/plugins/Sessions/Src/Main.cpp b/plugins/Sessions/Src/Main.cpp index 32d0608052..eb3e11abb8 100644 --- a/plugins/Sessions/Src/Main.cpp +++ b/plugins/Sessions/Src/Main.cpp @@ -19,37 +19,33 @@ along with this program. If not, see . #include "sessions.h" -HINSTANCE hinstance = NULL; - -WNDPROC mainProc; +HINSTANCE g_hInst = NULL; HGENMENU hmSaveCurrentSession, hmLoadLastSession, hmLoadSession, hmSessionsManager; -HANDLE hmTBButton[2],hiTBbutton[2],iTBbutton[2]; +HANDLE hmTBButton[2], hiTBbutton[2], iTBbutton[2]; -BOOL g_hghostw; +bool g_hghostw; HWND hClistControl; int g_ses_limit; int g_ses_count; -BOOL g_bExclHidden; -BOOL g_bWarnOnHidden; -BOOL g_bOtherWarnings; -BOOL g_bCrashRecovery; -BOOL g_bIncompletedSave; +bool g_bExclHidden; +bool g_bWarnOnHidden; +bool g_bOtherWarnings; +bool g_bCrashRecovery; +bool g_bIncompletedSave; HWND g_hDlg; HWND g_hSDlg; -BOOL DONT = FALSE; -BOOL StartUp, isLastTRUE = FALSE, g_mode,bSC = FALSE; +bool DONT = false; +bool StartUp, isLastTRUE = false, g_mode, bSC = false; MCONTACT session_list[255] = { 0 }; MCONTACT user_session_list[255] = { 0 }; MCONTACT session_list_recovered[255]; -int count = 0; - int hLangpack; int OptionsInit(WPARAM, LPARAM); @@ -168,7 +164,7 @@ INT_PTR CALLBACK SaveSessionDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lpar dd = 5; hClistControl = CreateWindowEx(WS_EX_CLIENTEDGE, _T(CLISTCONTROL_CLASS), _T(""), WS_TABSTOP | WS_VISIBLE | WS_CHILD, - x, y, dx, dy, hdlg, (HMENU)IDC_CLIST, hinstance, 0); + x, y, dx, dy, hdlg, (HMENU)IDC_CLIST, g_hInst, 0); SetWindowLongPtr(hClistControl, GWL_STYLE, GetWindowLongPtr(hClistControl, GWL_STYLE) | CLS_CHECKBOXES | CLS_HIDEEMPTYGROUPS | CLS_USEGROUPS | CLS_GREYALTERNATE | CLS_GROUPCHECKBOXES); @@ -456,7 +452,7 @@ INT_PTR SaveUserSessionHandles(WPARAM wparam, LPARAM lparam) return 1; } - g_hSDlg = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_SAVEDIALOG), 0, SaveSessionDlgProc); + g_hSDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_SAVEDIALOG), 0, SaveSessionDlgProc); return 0; } @@ -471,7 +467,7 @@ INT_PTR OpenSessionsManagerWindow(WPARAM wparam, LPARAM lparam) tszSession(db_get_tsa(NULL, MODNAME, "SessionDate_0")), tszUserSession(db_get_tsa(NULL, MODNAME, "UserSessionDsc_0")); if (g_bIncompletedSave || tszSession || tszUserSession) { - g_hDlg = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc); + g_hDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc); return 0; } if (g_bOtherWarnings) @@ -495,16 +491,15 @@ int SaveSessionDate() TCHAR *szSessionTime = (TCHAR*)mir_alloc(lenn*sizeof(TCHAR)); mir_sntprintf(szSessionTime, lenn, _T("%s - %s"), szTimeBuf, szDateBuf); - char szSessionDate[256]; - DBVARIANT dbv = { 0 }; - mir_snprintf(szSessionDate, SIZEOF(szSessionDate), "%s_%d", "SessionDate", 0); - db_get_ts(NULL, MODNAME, szSessionDate, &dbv); - TCHAR *szSessionDateBuf_1 = mir_tstrdup(dbv.ptszVal); - db_free(&dbv); + char szSetting[256]; + mir_snprintf(szSetting, SIZEOF(szSetting), "%s_%d", "SessionDate", 0); + TCHAR *ptszSaveSessionDate = db_get_tsa(NULL, MODNAME, szSetting); - db_set_ts(NULL, MODNAME, szSessionDate, szSessionTime); + db_set_ts(NULL, MODNAME, szSetting, szSessionTime); mir_free(szSessionTime); - ResaveSettings("SessionDate", 1, g_ses_limit, szSessionDateBuf_1); + + if (ptszSaveSessionDate) + ResaveSettings("SessionDate", 1, g_ses_limit, ptszSaveSessionDate); if (szTimeBuf) mir_free(szTimeBuf); @@ -521,13 +516,13 @@ int SaveUserSessionName(TCHAR *szUSessionName) if (session_list[0] == 0) return 1; - char szUserSessionNameBuf[256]; - mir_snprintf(szUserSessionNameBuf, SIZEOF(szUserSessionNameBuf), "%s_%u", "UserSessionDsc", 0); - ptrT szUserSessionName(db_get_tsa(NULL, MODNAME, szUserSessionNameBuf)); - if (szUserSessionName) - ResaveSettings("UserSessionDsc", 1, 255, szUserSessionName); + char szSetting[256]; + mir_snprintf(szSetting, SIZEOF(szSetting), "%s_%u", "UserSessionDsc", 0); + TCHAR *ptszUserSessionName = db_get_tsa(NULL, MODNAME, szSetting); + if (ptszUserSessionName) + ResaveSettings("UserSessionDsc", 1, 255, ptszUserSessionName); - db_set_ts(NULL, MODNAME, szUserSessionNameBuf, szUSessionName); + db_set_ts(NULL, MODNAME, szSetting, szUSessionName); return 0; } @@ -587,7 +582,7 @@ int LoadSession(WPARAM wparam, LPARAM lparam) MessageBox(NULL, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING); return 1; } - if (!g_bWarnOnHidden&&g_bOtherWarnings) { + if (!g_bWarnOnHidden && g_bOtherWarnings) { MessageBox(NULL, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING); return 1; } @@ -689,7 +684,7 @@ int OkToExit(WPARAM wparam, LPARAM lparam) db_set_b(NULL, MODNAME, "lastempty", 0); } else if (exitmode == 1 && session_list[0] != 0) { - DialogBox(hinstance, MAKEINTRESOURCE(IDD_EXDIALOG), 0, ExitDlgProc); + DialogBox(g_hInst, MAKEINTRESOURCE(IDD_EXDIALOG), 0, ExitDlgProc); } else db_set_b(NULL, MODNAME, "lastempty", 1); return 0; @@ -760,11 +755,11 @@ static INT_PTR LaunchSessions(WPARAM wParam, LPARAM lParam) int startup = db_get_b(NULL, MODNAME, "StartupMode", 3); if (startup == 1 || (startup == 3 && isLastTRUE == TRUE)) { StartUp = TRUE; - g_hDlg = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc); + g_hDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc); } else if (startup == 2 && isLastTRUE == TRUE) { g_hghostw = TRUE; - g_hDlg = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc); + g_hDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc); } return 0; } @@ -846,7 +841,7 @@ extern "C" __declspec(dllexport) int Unload(void) BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID lpvReserved) { - hinstance = hinst; + g_hInst = hinst; return 1; } @@ -870,13 +865,13 @@ extern "C" __declspec(dllexport) int Load(void) if (!g_ses_count) g_ses_count = db_get_b(0, "Sessions (Unicode)", "UserSessionsCount", 0); g_ses_limit = db_get_b(0, MODNAME, "TrackCount", 10); - g_bExclHidden = db_get_b(NULL, MODNAME, "ExclHidden", 0); - g_bWarnOnHidden = db_get_b(NULL, MODNAME, "WarnOnHidden", 0); - g_bOtherWarnings = db_get_b(NULL, MODNAME, "OtherWarnings", 1); - g_bCrashRecovery = db_get_b(NULL, MODNAME, "CrashRecovery", 0); + g_bExclHidden = db_get_b(NULL, MODNAME, "ExclHidden", 0) != 0; + g_bWarnOnHidden = db_get_b(NULL, MODNAME, "WarnOnHidden", 0) != 0; + g_bOtherWarnings = db_get_b(NULL, MODNAME, "OtherWarnings", 1) != 0; + g_bCrashRecovery = db_get_b(NULL, MODNAME, "CrashRecovery", 0) != 0; if (g_bCrashRecovery) - g_bIncompletedSave = !db_get_b(NULL, MODNAME, "lastSaveCompleted", 0); + g_bIncompletedSave = !db_get_b(NULL, MODNAME, "lastSaveCompleted", 0) != 0; if (g_bIncompletedSave) { int i = 0; @@ -900,6 +895,6 @@ extern "C" __declspec(dllexport) int Load(void) HookEvent(ME_SYSTEM_PRESHUTDOWN, SessionPreShutdown); // Icons - Icon_Register(hinstance, MODNAME, iconList, SIZEOF(iconList)); + Icon_Register(g_hInst, MODNAME, iconList, SIZEOF(iconList)); return 0; } diff --git a/plugins/Sessions/Src/Options.cpp b/plugins/Sessions/Src/Options.cpp index a6f4cde015..8ac6acb967 100644 --- a/plugins/Sessions/Src/Options.cpp +++ b/plugins/Sessions/Src/Options.cpp @@ -20,41 +20,41 @@ along with this program. If not, see . #include "sessions.h" HICON hIcon; -HICON hMarked,hNotMarked; +HICON hMarked, hNotMarked; -HWND hComboBox=NULL; -HWND hComboBoxEdit=NULL; +HWND hComboBox = NULL; +HWND hComboBoxEdit = NULL; -HWND hOpClistControl=NULL; +HWND hOpClistControl = NULL; static BOOL bOptionsInit; int opses_count; -BOOL bSesssionNameChanged=0; +BOOL bSesssionNameChanged = 0; -MCONTACT session_list_t[255]={0}; +MCONTACT session_list_t[255] = { 0 }; HWND g_opHdlg; int width; -HDC hdc=NULL; +HDC hdc = NULL; RECT lprect; RECT rc; POINT pt; -BOOL bChecked=FALSE; +BOOL bChecked = FALSE; -int OpLoadSessionContacts(WPARAM wparam,LPARAM lparam) +int OpLoadSessionContacts(WPARAM wparam, LPARAM lparam) { ZeroMemory(session_list_t, sizeof(session_list_t)); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - if (LoadContactsFromMask(hContact,1,lparam)) { - int i = GetInSessionOrder(hContact,1, lparam); + if (LoadContactsFromMask(hContact, 1, lparam)) { + int i = GetInSessionOrder(hContact, 1, lparam); session_list_t[i] = hContact; } } int i; - for (i=0; session_list_t[i] != 0; i++) + for (i = 0; session_list_t[i] != 0; i++) SendDlgItemMessage(g_opHdlg, IDC_OPCLIST, LB_ADDSTRING, 0, CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)session_list_t[i], GCDNF_TCHAR)); return i; @@ -91,22 +91,22 @@ static LRESULT CALLBACK ComboBoxSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, case WM_LBUTTONDBLCLK: case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: - SendMessage(hComboBox,CB_SHOWDROPDOWN,1,0); + SendMessage(hComboBox, CB_SHOWDROPDOWN, 1, 0); return TRUE; case WM_NCLBUTTONDBLCLK: case WM_NCLBUTTONDOWN: if (!bChecked) { - MarkUserDefSession(opses_count,1); + MarkUserDefSession(opses_count, 1); hIcon = hMarked; bChecked = TRUE; - RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_FRAME); + RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME); } else { - MarkUserDefSession(opses_count,0); + MarkUserDefSession(opses_count, 0); hIcon = hNotMarked; bChecked = FALSE; - RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_FRAME); + RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME); } break; @@ -120,8 +120,8 @@ static LRESULT CALLBACK ComboBoxSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, case WM_NCPAINT: hdc = GetDC(hwnd); GetClientRect(hwnd, &rc); - rc.left=rc.right; - rc.right=rc.left+16; + rc.left = rc.right; + rc.right = rc.left + 16; FillRect(hdc, &rc, (HBRUSH)GetSysColor(COLOR_WINDOW)); DrawIconEx(hdc, rc.left, 0, hIcon, 16, 16, 0, NULL, DI_NORMAL); ReleaseDC(hwnd, hdc); @@ -130,71 +130,67 @@ static LRESULT CALLBACK ComboBoxSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, case WM_NCCALCSIZE: { NCCALCSIZE_PARAMS *ncsParam = (NCCALCSIZE_PARAMS*)lParam; - ncsParam->rgrc[ 0 ].right -= 16; + ncsParam->rgrc[0].right -= 16; } break; case WM_NCHITTEST: - { - LRESULT lr = mir_callNextSubclass(hwnd, ComboBoxSubclassProc, msg, wParam, lParam ); - if (lr == HTNOWHERE ) - lr = HTOBJECT; - return lr; - } + LRESULT lr = mir_callNextSubclass(hwnd, ComboBoxSubclassProc, msg, wParam, lParam); + if (lr == HTNOWHERE) + lr = HTOBJECT; + return lr; } return mir_callNextSubclass(hwnd, ComboBoxSubclassProc, msg, wParam, lParam); } -INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) +static INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) { switch(msg) { case WM_INITDIALOG: + TranslateDialogDefault(hdlg); { - int startupmode,exitmode; - COMBOBOXINFO cbi={0}; + COMBOBOXINFO cbi = { 0 }; cbi.cbSize = sizeof(cbi); - opses_count=0; - g_opHdlg=hdlg; - bOptionsInit=TRUE; - TranslateDialogDefault(hdlg); + opses_count = 0; + g_opHdlg = hdlg; + bOptionsInit = TRUE; hMarked = Skin_GetIconByHandle(iconList[1].hIcolib); hNotMarked = Skin_GetIconByHandle(iconList[2].hIcolib); - hIcon=(bChecked=IsMarkedUserDefSession(opses_count))?hMarked:hNotMarked; + hIcon = (bChecked = IsMarkedUserDefSession(opses_count)) ? hMarked : hNotMarked; - SetDlgItemInt(hdlg, IDC_TRACK,g_ses_limit=db_get_b(0, MODNAME, "TrackCount", 10), FALSE); + SetDlgItemInt(hdlg, IDC_TRACK, g_ses_limit = db_get_b(0, MODNAME, "TrackCount", 10), FALSE); SendDlgItemMessage(hdlg, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(10, 1)); SendDlgItemMessage(hdlg, IDC_SPIN1, UDM_SETPOS, 0, GetDlgItemInt(hdlg, IDC_TRACK, NULL, FALSE)); SendDlgItemMessage(hdlg, IDC_OPCLIST, LB_RESETCONTENT, 0, 0); SetDlgItemInt(hdlg, IDC_STARTDELAY, db_get_w(NULL, MODNAME, "StartupModeDelay", 1500), FALSE); - startupmode = db_get_b(NULL, MODNAME, "StartupMode", 3); - exitmode = db_get_b(NULL, MODNAME, "ShutdownMode", 2); + int startupmode = db_get_b(NULL, MODNAME, "StartupMode", 3); + int exitmode = db_get_b(NULL, MODNAME, "ShutdownMode", 2); - g_bExclHidden = db_get_b(NULL, MODNAME, "ExclHidden", 0); - g_bWarnOnHidden = db_get_b(NULL, MODNAME, "WarnOnHidden", 0); - g_bOtherWarnings = db_get_b(NULL, MODNAME, "OtherWarnings", 1); - g_bCrashRecovery = db_get_b(NULL, MODNAME, "CrashRecovery", 0); - - CheckDlgButton(hdlg,IDC_EXCLHIDDEN,g_bExclHidden?BST_CHECKED:BST_UNCHECKED); - CheckDlgButton(hdlg,IDC_LASTHIDDENWARN,g_bWarnOnHidden?BST_CHECKED:BST_UNCHECKED); - CheckDlgButton(hdlg,IDC_WARNINGS,g_bOtherWarnings?BST_CHECKED:BST_UNCHECKED); - CheckDlgButton(hdlg,IDC_CRASHRECOVERY,g_bCrashRecovery?BST_CHECKED:BST_UNCHECKED); + g_bExclHidden = db_get_b(NULL, MODNAME, "ExclHidden", 0) != 0; + g_bWarnOnHidden = db_get_b(NULL, MODNAME, "WarnOnHidden", 0) != 0; + g_bOtherWarnings = db_get_b(NULL, MODNAME, "OtherWarnings", 1) != 0; + g_bCrashRecovery = db_get_b(NULL, MODNAME, "CrashRecovery", 0) != 0; + CheckDlgButton(hdlg, IDC_EXCLHIDDEN, g_bExclHidden ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hdlg, IDC_LASTHIDDENWARN, g_bWarnOnHidden ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hdlg, IDC_WARNINGS, g_bOtherWarnings ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hdlg, IDC_CRASHRECOVERY, g_bCrashRecovery ? BST_CHECKED : BST_UNCHECKED); if (startupmode == 1) - CheckDlgButton(hdlg,IDC_STARTDIALOG,BST_CHECKED); + CheckDlgButton(hdlg, IDC_STARTDIALOG, BST_CHECKED); else if (startupmode == 3) { - CheckDlgButton(hdlg,IDC_STARTDIALOG,BST_CHECKED); - CheckDlgButton(hdlg,IDC_CHECKLAST,BST_CHECKED); + CheckDlgButton(hdlg, IDC_STARTDIALOG, BST_CHECKED); + CheckDlgButton(hdlg, IDC_CHECKLAST, BST_CHECKED); } else if (startupmode == 2) { - CheckDlgButton(hdlg,IDC_RLOADLAST,BST_CHECKED); + CheckDlgButton(hdlg, IDC_RLOADLAST, BST_CHECKED); EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), FALSE); } - else if (startupmode == 0) { - CheckDlgButton(hdlg,IDC_RNOTHING,BST_CHECKED); + else if (startupmode == 0) { + CheckDlgButton(hdlg, IDC_RNOTHING, BST_CHECKED); EnableWindow(GetDlgItem(hdlg, IDC_STARTDELAY), FALSE); EnableWindow(GetDlgItem(hdlg, IDC_STATICOP), FALSE); EnableWindow(GetDlgItem(hdlg, IDC_STATICMS), FALSE); @@ -202,52 +198,52 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) } if (exitmode == 0) { - CheckDlgButton(hdlg,IDC_REXDSAVE,BST_CHECKED); - EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC1),FALSE); - EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC2),FALSE); - EnableWindow(GetDlgItem(hdlg,IDC_TRACK),FALSE); - EnableWindow(GetDlgItem(hdlg,IDC_SPIN1),FALSE); + CheckDlgButton(hdlg, IDC_REXDSAVE, BST_CHECKED); + EnableWindow(GetDlgItem(hdlg, IDC_EXSTATIC1), FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_EXSTATIC2), FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_TRACK), FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_SPIN1), FALSE); } else if (exitmode == 1) - CheckDlgButton(hdlg,IDC_REXASK,BST_CHECKED); + CheckDlgButton(hdlg, IDC_REXASK, BST_CHECKED); else if (exitmode == 2) - CheckDlgButton(hdlg,IDC_REXSAVE,BST_CHECKED); + CheckDlgButton(hdlg, IDC_REXSAVE, BST_CHECKED); - LoadSessionToCombobox (hdlg,1,255,"UserSessionDsc",0); + LoadSessionToCombobox(hdlg, 1, 255, "UserSessionDsc", 0); if (SendDlgItemMessage(hdlg, IDC_LIST, CB_GETCOUNT, 0, 0)) { - EnableWindow(GetDlgItem(hdlg,IDC_EDIT),TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_EDIT), TRUE); SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0); - if (!OpLoadSessionContacts(0,opses_count)) - EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE); + if (!OpLoadSessionContacts(0, opses_count)) + EnableWindow(GetDlgItem(hdlg, IDC_DEL), FALSE); } - GetComboBoxInfo(GetDlgItem(hdlg,IDC_LIST),&cbi); + GetComboBoxInfo(GetDlgItem(hdlg, IDC_LIST), &cbi); mir_subclassWindow(cbi.hwndItem, ComboBoxSubclassProc); - hComboBoxEdit=cbi.hwndItem; - hComboBox=cbi.hwndCombo; + hComboBoxEdit = cbi.hwndItem; + hComboBox = cbi.hwndCombo; - SetWindowPos( hComboBoxEdit, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED ); + SetWindowPos(hComboBoxEdit, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - bOptionsInit=FALSE; + bOptionsInit = FALSE; } break; case WM_CTLCOLORLISTBOX: - switch(GetDlgCtrlID((HWND) lparam)) { + switch (GetDlgCtrlID((HWND)lparam)) { case IDC_OPCLIST: - SetBkMode((HDC) wparam, TRANSPARENT); - return (BOOL) CreateSolidBrush(GetSysColor(COLOR_3DFACE)); + SetBkMode((HDC)wparam, TRANSPARENT); + return (BOOL)CreateSolidBrush(GetSysColor(COLOR_3DFACE)); } break; case WM_NOTIFY: - switch(((LPNMHDR)lparam)->code) { + switch (((LPNMHDR)lparam)->code) { case PSN_APPLY: { - int iDelay=GetDlgItemInt(hdlg, IDC_STARTDELAY,NULL, FALSE); + int iDelay = GetDlgItemInt(hdlg, IDC_STARTDELAY, NULL, FALSE); db_set_w(0, MODNAME, "StartupModeDelay", (WORD)iDelay); - db_set_b(0, MODNAME, "TrackCount", (BYTE)(g_ses_limit=GetDlgItemInt(hdlg, IDC_TRACK,NULL, FALSE))); + db_set_b(0, MODNAME, "TrackCount", (BYTE)(g_ses_limit = GetDlgItemInt(hdlg, IDC_TRACK, NULL, FALSE))); if (IsDlgButtonChecked(hdlg, IDC_REXSAVE)) db_set_b(NULL, MODNAME, "ShutdownMode", 2); else if (IsDlgButtonChecked(hdlg, IDC_REXDSAVE)) @@ -274,28 +270,27 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) return 1; case CLN_CHECKCHANGED: - if (((LPNMHDR)lparam)->idFrom == IDC_EMCLIST) - { + if (((LPNMHDR)lparam)->idFrom == IDC_EMCLIST) { int iSelection = (int)((NMCLISTCONTROL *)lparam)->hItem; MCONTACT hContact = db_find_first(); - for ( ; hContact; hContact = db_find_next(hContact)) + for (; hContact; hContact = db_find_next(hContact)) if (SendDlgItemMessage(hdlg, IDC_EMCLIST, CLM_FINDCONTACT, hContact, 0) == iSelection) break; if (hContact) - EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_SAVE), TRUE); else - EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_SAVE), FALSE); } } break; case WM_COMMAND: - switch(LOWORD(wparam)) { + switch (LOWORD(wparam)) { case IDC_LIST: - switch(HIWORD(wparam)) { + switch (HIWORD(wparam)) { case CBN_EDITCHANGE: - EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); - bSesssionNameChanged=TRUE; + EnableWindow(GetDlgItem(hdlg, IDC_SAVE), TRUE); + bSesssionNameChanged = TRUE; break; case CBN_SELCHANGE: @@ -306,90 +301,91 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) opses_count = SendMessage(hCombo, CB_GETITEMDATA, (WPARAM)index, 0); SendDlgItemMessage(hdlg, IDC_OPCLIST, LB_RESETCONTENT, 0, 0); if (IsMarkedUserDefSession(opses_count)) { - hIcon=hMarked; - bChecked=TRUE; - RedrawWindow(hComboBoxEdit, NULL, NULL, RDW_INVALIDATE|RDW_NOCHILDREN|RDW_UPDATENOW|RDW_FRAME); + hIcon = hMarked; + bChecked = TRUE; + RedrawWindow(hComboBoxEdit, NULL, NULL, RDW_INVALIDATE | RDW_NOCHILDREN | RDW_UPDATENOW | RDW_FRAME); } else { - hIcon=hNotMarked; - bChecked=FALSE; - RedrawWindow(hComboBoxEdit, NULL, NULL, RDW_INVALIDATE|RDW_NOCHILDREN|RDW_UPDATENOW|RDW_FRAME); + hIcon = hNotMarked; + bChecked = FALSE; + RedrawWindow(hComboBoxEdit, NULL, NULL, RDW_INVALIDATE | RDW_NOCHILDREN | RDW_UPDATENOW | RDW_FRAME); } - OpLoadSessionContacts(0,opses_count); + OpLoadSessionContacts(0, opses_count); if (!hOpClistControl) - EnableWindow(GetDlgItem(hdlg,IDC_DEL),TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_DEL), TRUE); else { for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) - SendMessage(hOpClistControl, CLM_SETCHECKMARK, hContact,0); + SendMessage(hOpClistControl, CLM_SETCHECKMARK, hContact, 0); - for (int i=0 ; session_list_t[i] > 0; i++) { + for (int i = 0; session_list_t[i] > 0; i++) { MCONTACT hContact = (MCONTACT)SendMessage(hOpClistControl, CLM_FINDCONTACT, (WPARAM)session_list_t[i], 0); SendMessage(hOpClistControl, CLM_SETCHECKMARK, hContact, 1); } - EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_SAVE), FALSE); } } - }break; - }break; + } + } + break; case IDC_EDIT: if (!hOpClistControl) { - ShowWindow(GetDlgItem(hdlg,IDC_OPCLIST),SW_HIDE); - EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE); + ShowWindow(GetDlgItem(hdlg, IDC_OPCLIST), SW_HIDE); + EnableWindow(GetDlgItem(hdlg, IDC_DEL), FALSE); //EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); - SetWindowText(GetDlgItem(hdlg,IDC_EDIT),TranslateT("View")); + SetWindowText(GetDlgItem(hdlg, IDC_EDIT), TranslateT("View")); hOpClistControl = CreateWindowEx(WS_EX_STATICEDGE, _T(CLISTCONTROL_CLASS), _T(""), - WS_TABSTOP |WS_VISIBLE | WS_CHILD , - 14,198,161,163,hdlg, (HMENU)IDC_EMCLIST, hinstance, 0); + WS_TABSTOP | WS_VISIBLE | WS_CHILD, + 14, 198, 161, 163, hdlg, (HMENU)IDC_EMCLIST, g_hInst, 0); SetWindowLongPtr(hOpClistControl, GWL_STYLE, - GetWindowLongPtr(hOpClistControl, GWL_STYLE)|CLS_CHECKBOXES|CLS_HIDEEMPTYGROUPS|CLS_USEGROUPS|CLS_GREYALTERNATE|CLS_GROUPCHECKBOXES); - SendMessage(hOpClistControl, CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP|CLS_EX_TRACKSELECT, 0); + GetWindowLongPtr(hOpClistControl, GWL_STYLE) | CLS_CHECKBOXES | CLS_HIDEEMPTYGROUPS | CLS_USEGROUPS | CLS_GREYALTERNATE | CLS_GROUPCHECKBOXES); + SendMessage(hOpClistControl, CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT, 0); - SendMessage(hOpClistControl,WM_TIMER,TIMERID_REBUILDAFTER,0); + SendMessage(hOpClistControl, WM_TIMER, TIMERID_REBUILDAFTER, 0); - for (int i=0 ; session_list_t[i] > 0; i++) { - HANDLE hItem=(HANDLE)SendMessage(hOpClistControl,CLM_FINDCONTACT, (WPARAM)session_list_t[i], 0); - SendMessage(hOpClistControl, CLM_SETCHECKMARK, (WPARAM)hItem,1); + for (int i = 0; session_list_t[i] > 0; i++) { + HANDLE hItem = (HANDLE)SendMessage(hOpClistControl, CLM_FINDCONTACT, (WPARAM)session_list_t[i], 0); + SendMessage(hOpClistControl, CLM_SETCHECKMARK, (WPARAM)hItem, 1); } } else { - ShowWindow(GetDlgItem(hdlg,IDC_OPCLIST),SW_SHOWNA); - EnableWindow(GetDlgItem(hdlg,IDC_DEL),TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE); - SetWindowText(GetDlgItem(hdlg,IDC_EDIT),TranslateT("Edit")); + ShowWindow(GetDlgItem(hdlg, IDC_OPCLIST), SW_SHOWNA); + EnableWindow(GetDlgItem(hdlg, IDC_DEL), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_SAVE), FALSE); + SetWindowText(GetDlgItem(hdlg, IDC_EDIT), TranslateT("Edit")); DestroyWindow(hOpClistControl); - hOpClistControl=NULL; + hOpClistControl = NULL; } break; case IDC_SAVE: { - int i=0; + int i = 0; for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - BYTE res =(BYTE)SendMessage(GetDlgItem(hdlg,IDC_EMCLIST), CLM_GETCHECKMARK, - SendMessage(GetDlgItem(hdlg,IDC_EMCLIST), CLM_FINDCONTACT, hContact, 0), 0); + BYTE res = (BYTE)SendMessage(GetDlgItem(hdlg, IDC_EMCLIST), CLM_GETCHECKMARK, + SendMessage(GetDlgItem(hdlg, IDC_EMCLIST), CLM_FINDCONTACT, hContact, 0), 0); if (res) { - SetSessionMark(hContact,1,'1',opses_count); - SetInSessionOrder(hContact,1,opses_count,i); + SetSessionMark(hContact, 1, '1', opses_count); + SetInSessionOrder(hContact, 1, opses_count, i); i++; } else { - SetSessionMark(hContact,1,'0',opses_count); - SetInSessionOrder(hContact,1,opses_count,0); + SetSessionMark(hContact, 1, '0', opses_count); + SetInSessionOrder(hContact, 1, opses_count, 0); } } if (bSesssionNameChanged) { if (GetWindowTextLength(hComboBoxEdit)) { - TCHAR szUserSessionName[MAX_PATH]={'\0'}; + TCHAR szUserSessionName[MAX_PATH] = { '\0' }; GetWindowText(hComboBoxEdit, szUserSessionName, SIZEOF(szUserSessionName)); - RenameUserDefSession(opses_count,szUserSessionName); - SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT ,0,0); - LoadSessionToCombobox (hdlg,1,255,"UserSessionDsc",0); + RenameUserDefSession(opses_count, szUserSessionName); + SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0); + LoadSessionToCombobox(hdlg, 1, 255, "UserSessionDsc", 0); } - bSesssionNameChanged=FALSE; + bSesssionNameChanged = FALSE; } - EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_SAVE), FALSE); } break; @@ -399,19 +395,19 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) SendDlgItemMessage(hdlg, IDC_OPCLIST, LB_RESETCONTENT, 0, 0); SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0); - LoadSessionToCombobox (hdlg,1,255,"UserSessionDsc",0); + LoadSessionToCombobox(hdlg, 1, 255, "UserSessionDsc", 0); - opses_count=0; + opses_count = 0; if (SendDlgItemMessage(hdlg, IDC_LIST, CB_GETCOUNT, 0, 0)) { - EnableWindow(GetDlgItem(hdlg,IDC_EDIT),TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_EDIT), TRUE); SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0); - if (!OpLoadSessionContacts(0,opses_count)) - EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE); + if (!OpLoadSessionContacts(0, opses_count)) + EnableWindow(GetDlgItem(hdlg, IDC_DEL), FALSE); } else { - EnableWindow(GetDlgItem(hdlg,IDC_EDIT),FALSE); - EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_EDIT), FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_DEL), FALSE); } break; @@ -420,7 +416,7 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) EnableWindow(GetDlgItem(hdlg, IDC_STATICOP), TRUE); EnableWindow(GetDlgItem(hdlg, IDC_STATICMS), TRUE); EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), TRUE); - SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); + SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; case IDC_RLOADLAST: @@ -428,7 +424,7 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) EnableWindow(GetDlgItem(hdlg, IDC_STATICOP), TRUE); EnableWindow(GetDlgItem(hdlg, IDC_STATICMS), TRUE); EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), FALSE); - SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); + SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; case IDC_RNOTHING: @@ -436,72 +432,72 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) EnableWindow(GetDlgItem(hdlg, IDC_STATICOP), FALSE); EnableWindow(GetDlgItem(hdlg, IDC_STATICMS), FALSE); EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), FALSE); - SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); + SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; case IDC_REXSAVE: - EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC1),TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC2),TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_TRACK),TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_SPIN1),TRUE); - SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); + EnableWindow(GetDlgItem(hdlg, IDC_EXSTATIC1), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_EXSTATIC2), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_TRACK), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_SPIN1), TRUE); + SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; case IDC_REXDSAVE: - EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC1),FALSE); - EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC2),FALSE); - EnableWindow(GetDlgItem(hdlg,IDC_TRACK),FALSE); - EnableWindow(GetDlgItem(hdlg,IDC_SPIN1),FALSE); - SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); + EnableWindow(GetDlgItem(hdlg, IDC_EXSTATIC1), FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_EXSTATIC2), FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_TRACK), FALSE); + EnableWindow(GetDlgItem(hdlg, IDC_SPIN1), FALSE); + SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; case IDC_REXASK: - EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC1),TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_EXSTATIC2),TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_TRACK),TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_SPIN1),TRUE); - SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); + EnableWindow(GetDlgItem(hdlg, IDC_EXSTATIC1), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_EXSTATIC2), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_TRACK), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_SPIN1), TRUE); + SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; } - if (HIWORD(wparam) == CBN_DROPDOWN&&!hOpClistControl) { - SendMessage(hComboBoxEdit,EM_SETSEL ,0,0); - SendMessage(hComboBoxEdit,EM_SCROLLCARET ,0,0); - SendMessage(hComboBoxEdit,WM_KILLFOCUS ,0,0); + if (HIWORD(wparam) == CBN_DROPDOWN && !hOpClistControl) { + SendMessage(hComboBoxEdit, EM_SETSEL, 0, 0); + SendMessage(hComboBoxEdit, EM_SCROLLCARET, 0, 0); + SendMessage(hComboBoxEdit, WM_KILLFOCUS, 0, 0); HideCaret(hComboBoxEdit); } - if ((HIWORD(wparam)!=CBN_DROPDOWN)&&(LOWORD(wparam) == IDC_LIST)&&!hOpClistControl) { - SendMessage(hComboBoxEdit,EM_SCROLLCARET ,0,0); + if ((HIWORD(wparam) != CBN_DROPDOWN) && (LOWORD(wparam) == IDC_LIST) && !hOpClistControl) { + SendMessage(hComboBoxEdit, EM_SCROLLCARET, 0, 0); HideCaret(hComboBoxEdit); } - if ((LOWORD(wparam) == IDC_STARTDELAY) && (HIWORD(wparam)!=EN_CHANGE || (HWND)lparam != GetFocus())) + if ((LOWORD(wparam) == IDC_STARTDELAY) && (HIWORD(wparam) != EN_CHANGE || (HWND)lparam != GetFocus())) return 0; - if (lparam&&!bOptionsInit&&(HIWORD(wparam) == BN_CLICKED)&& (GetFocus() == (HWND)lparam) - &&((LOWORD(wparam) == IDC_CHECKLAST)||((LOWORD(wparam)>=IDC_EXCLHIDDEN)&&(LOWORD(wparam)<=IDC_CRASHRECOVERY)))) - SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); + if (lparam && !bOptionsInit && (HIWORD(wparam) == BN_CLICKED) && (GetFocus() == (HWND)lparam) && + ((LOWORD(wparam) == IDC_CHECKLAST) || ((LOWORD(wparam) >= IDC_EXCLHIDDEN) && (LOWORD(wparam) <= IDC_CRASHRECOVERY)))) + SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); return 0; case WM_CLOSE: - EndDialog(hdlg,0); + EndDialog(hdlg, 0); return 0; } return 0; } -int OptionsInit(WPARAM wparam,LPARAM lparam) +int OptionsInit(WPARAM wparam, LPARAM lparam) { OPTIONSDIALOGPAGE odp = { sizeof(odp) }; odp.position = 955000000; - odp.hInstance = hinstance; + odp.hInstance = g_hInst; odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); odp.pszTitle = MODNAME; odp.pfnDlgProc = OptionsProc; odp.pszGroup = LPGEN("Message Sessions"); odp.flags = ODPF_BOLDGROUPS; - Options_AddPage(wparam,&odp); + Options_AddPage(wparam, &odp); return 0; } diff --git a/plugins/Sessions/Src/Sessions.h b/plugins/Sessions/Src/Sessions.h index c053fde48d..abc6a27bf2 100644 --- a/plugins/Sessions/Src/Sessions.h +++ b/plugins/Sessions/Src/Sessions.h @@ -52,25 +52,25 @@ extern IconItem iconList[]; #define MIIM_STRING 0x00000040 -int DelUserDefSession(int ses_count); +int DelUserDefSession(int ses_count); int DeleteAutoSession(int ses_count); -int LoadSession(WPARAM ,LPARAM ); -int SaveSessionHandles(WPARAM ,LPARAM ); -INT_PTR SaveUserSessionHandles(WPARAM ,LPARAM ); +int LoadSession(WPARAM, LPARAM); +int SaveSessionHandles(WPARAM, LPARAM); +INT_PTR SaveUserSessionHandles(WPARAM, LPARAM); int SaveUserSessionName(TCHAR*); -INT_PTR CloseCurrentSession(WPARAM ,LPARAM ); +INT_PTR CloseCurrentSession(WPARAM, LPARAM); int SaveSessionDate(); -extern HINSTANCE hinstance; +extern HINSTANCE g_hInst; extern MCONTACT session_list_recovered[255]; extern MCONTACT session_list[255]; extern int g_ses_limit; extern int g_ses_count; -extern BOOL g_bExclHidden; -extern BOOL g_bWarnOnHidden; -extern BOOL g_bOtherWarnings; -extern BOOL g_bCrashRecovery; -extern BOOL g_bIncompletedSave; +extern bool g_bExclHidden; +extern bool g_bWarnOnHidden; +extern bool g_bOtherWarnings; +extern bool g_bCrashRecovery; +extern bool g_bIncompletedSave; #define TIMERID_LOAD 12 #define TIMERID_SHOW 11 diff --git a/plugins/Sessions/Src/Utils.cpp b/plugins/Sessions/Src/Utils.cpp index 3a4271d942..8a738cd970 100644 --- a/plugins/Sessions/Src/Utils.cpp +++ b/plugins/Sessions/Src/Utils.cpp @@ -169,8 +169,7 @@ void AddInSessionOrder(MCONTACT hContact, int mode, int ordernum, int writemode) int len = (int)strlen(pszBuffer); len = (len == 0) ? 20 : len + 2; char *temp = (char*)_alloca(len+1); - ZeroMemory(temp, len+1); - mir_snprintf(temp, len + 1, "%02u%s", ordernum, szValue); + mir_snprintf(temp, len+1, "%02u%s", ordernum, szValue); db_set_s(hContact, MODNAME, "UserSessionsOrder", temp); mir_free(pszBuffer); -- cgit v1.2.3