From c874769aaa91b110d87eb7b8d267680eb2008bbf Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 7 Apr 2013 21:56:20 +0000 Subject: Sessions: contacts are HANDLEs, not DWORDs git-svn-id: http://svn.miranda-ng.org/main/trunk@4381 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Sessions/Src/Main.cpp | 199 ++++++++++++--------------- plugins/Sessions/Src/Options.cpp | 286 ++++++++++++++++++--------------------- plugins/Sessions/Src/Sessions.h | 4 +- plugins/Sessions/Src/Utils.cpp | 250 +++++++++++++--------------------- plugins/Sessions/Src/Utils.h | 6 +- 5 files changed, 318 insertions(+), 427 deletions(-) (limited to 'plugins/Sessions') diff --git a/plugins/Sessions/Src/Main.cpp b/plugins/Sessions/Src/Main.cpp index 8058d452d7..f422608a58 100644 --- a/plugins/Sessions/Src/Main.cpp +++ b/plugins/Sessions/Src/Main.cpp @@ -23,7 +23,6 @@ HINSTANCE hinstance = NULL; WNDPROC mainProc; -HANDLE hServiceOpenManager, hServiceShowFavMenu, hServiceCloseCurrentSession, hServiceSaveUserSession, hServiceLoadLastSession; HGENMENU hmSaveCurrentSession, hmLoadLastSession, hmLoadSession, hmSessionsManager; HANDLE hmTBButton[2],hiTBbutton[2],iTBbutton[2]; @@ -45,9 +44,9 @@ HWND g_hSDlg; BOOL DONT = FALSE; BOOL StartUp, isLastTRUE = FALSE, g_mode,bSC = FALSE; -DWORD session_list[255] = {0}; -DWORD user_session_list[255] = {0}; -DWORD session_list_recovered[255]; +HANDLE session_list[255] = {0}; +HANDLE user_session_list[255] = {0}; +HANDLE session_list_recovered[255]; int count = 0; unsigned int ses_count = 0; @@ -234,9 +233,8 @@ INT_PTR CALLBACK SaveSessionDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lpar for (i=0; hContact; hContact = db_find_next(hContact)) { BYTE res =(BYTE)SendMessage(hClistControl, CLM_GETCHECKMARK, SendMessage(hClistControl, CLM_FINDCONTACT, (WPARAM)hContact, 0), 0); - if (res) - { - user_session_list[i]=(DWORD)hContact; + if (res) { + user_session_list[i] = hContact; i++; } } @@ -287,16 +285,16 @@ INT_PTR CALLBACK LoadSessionDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lpar case WM_INITDIALOG: { int iDelay=db_get_w(NULL, MODNAME, "StartupModeDelay", 1500); - if (g_hghostw==TRUE) + if (g_hghostw == TRUE) SetTimer(hdlg, TIMERID_LOAD, iDelay, NULL); else { ses_count=0; TranslateDialogDefault(hdlg); - if ((ses_count=LoadSessionToCombobox(hdlg,0,ses_limit,"SessionDate",0))==ses_limit) + if ((ses_count=LoadSessionToCombobox(hdlg,0,ses_limit,"SessionDate",0)) == ses_limit) EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),TRUE); - if (LoadSessionToCombobox(hdlg,0,255,"UserSessionDsc",ses_limit)==0 && ses_count!=0) + if (LoadSessionToCombobox(hdlg,0,255,"UserSessionDsc",ses_limit) == 0 && ses_count!=0) ses_count=0; if (session_list_recovered[0]) @@ -353,12 +351,12 @@ INT_PTR CALLBACK LoadSessionDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lpar case IDC_SESSDEL: { - if (session_list_recovered[0]&&ses_count==256) + if (session_list_recovered[0]&&ses_count == 256) { int i=0; while(session_list_recovered[i]) { - db_set_b((HANDLE)session_list_recovered[i], MODNAME, "wasInLastSession", 0); + db_set_b(session_list_recovered[i], MODNAME, "wasInLastSession", 0); i++; } ZeroMemory(session_list_recovered,SIZEOF(session_list_recovered)); @@ -367,10 +365,10 @@ INT_PTR CALLBACK LoadSessionDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lpar EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),FALSE); SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0); - if ((ses_count=LoadSessionToCombobox(hdlg,1,ses_limit,"SessionDate",0))==ses_limit) + if ((ses_count=LoadSessionToCombobox(hdlg,1,ses_limit,"SessionDate",0)) == ses_limit) EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),TRUE); - if (LoadSessionToCombobox(hdlg,1,255,"UserSessionDsc",ses_limit)==0 && ses_count!=0) + if (LoadSessionToCombobox(hdlg,1,255,"UserSessionDsc",ses_limit) == 0 && ses_count!=0) ses_count=0; SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0); @@ -383,10 +381,10 @@ INT_PTR CALLBACK LoadSessionDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lpar EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),FALSE); SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0); - if ((ses_count=LoadSessionToCombobox(hdlg,0,ses_limit,"SessionDate",0))==ses_limit) + if ((ses_count=LoadSessionToCombobox(hdlg,0,ses_limit,"SessionDate",0)) == ses_limit) EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),TRUE); - if (LoadSessionToCombobox(hdlg,0,255,"UserSessionDsc",ses_limit)==0 && ses_count!=0) + if (LoadSessionToCombobox(hdlg,0,255,"UserSessionDsc",ses_limit) == 0 && ses_count!=0) ses_count=0; if (session_list_recovered[0]) ses_count=256; @@ -398,10 +396,10 @@ INT_PTR CALLBACK LoadSessionDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lpar DeleteAutoSession(ses_count); EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),FALSE); SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0); - if ((ses_count=LoadSessionToCombobox(hdlg,0,ses_limit,"SessionDate",0))==ses_limit) + if ((ses_count=LoadSessionToCombobox(hdlg,0,ses_limit,"SessionDate",0)) == ses_limit) EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),TRUE); - if (LoadSessionToCombobox(hdlg,0,255,"UserSessionDsc",ses_limit)==0 && ses_count!=0) + if (LoadSessionToCombobox(hdlg,0,255,"UserSessionDsc",ses_limit) == 0 && ses_count!=0) ses_count=0; if (session_list_recovered[0]) ses_count=256; @@ -449,7 +447,7 @@ INT_PTR CloseCurrentSession(WPARAM wparam,LPARAM lparam) while(session_list[0]!=0) { mwid.cbSize = sizeof(MessageWindowInputData); - mwid.hContact=(HANDLE)session_list[i]; + mwid.hContact=session_list[i]; mwid.uFlags=MSG_WINDOW_UFLAG_MSG_BOTH; mwd.cbSize = sizeof(MessageWindowData); @@ -462,8 +460,7 @@ INT_PTR CloseCurrentSession(WPARAM wparam,LPARAM lparam) hWnd=GetAncestor(mwd.hwndWindow,GA_ROOT); SendMessage(hWnd,WM_CLOSE,0,1); } - else - SendMessage(mwd.hwndWindow, WM_CLOSE, 0, 0); + else SendMessage(mwd.hwndWindow, WM_CLOSE, 0, 0); } ZeroMemory(session_list,SIZEOF(session_list)); return 0; @@ -471,34 +468,25 @@ INT_PTR CloseCurrentSession(WPARAM wparam,LPARAM lparam) int SaveSessionHandles(WPARAM wparam,LPARAM lparam) { - int k=0; + if (session_list[0] == 0) + return 1; - if (session_list[0]!=0) - { - for (HANDLE hContact = db_find_first(); hContact; - hContact = db_find_next(hContact)) - { - if ((k=CheckForDuplicate(session_list,(DWORD)hContact))!=-1 - &&!(g_bExclHidden&&!CheckContactVisibility(hContact))) - { - AddSessionMark((HANDLE)hContact,lparam,'1'); - AddInSessionOrder((HANDLE)hContact,lparam,k,1); - } - else - { - AddSessionMark((HANDLE)hContact,lparam,'0'); - AddInSessionOrder((HANDLE)hContact,lparam,0,0); - } + int k=0; + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + if ((k=CheckForDuplicate(session_list,hContact)) != -1 && !(g_bExclHidden && !CheckContactVisibility(hContact))) { + AddSessionMark(hContact,lparam,'1'); + AddInSessionOrder(hContact,lparam,k,1); } - if (lparam==1) - { - g_ses_count++; - db_set_b(0, MODNAME, "UserSessionsCount", (BYTE)g_ses_count); + else { + AddSessionMark(hContact,lparam,'0'); + AddInSessionOrder(hContact,lparam,0,0); } - return 0; } - else - return 1; + if (lparam == 1) { + g_ses_count++; + db_set_b(0, MODNAME, "UserSessionsCount", (BYTE)g_ses_count); + } + return 0; } INT_PTR SaveUserSessionHandles(WPARAM wparam,LPARAM lparam) @@ -614,7 +602,7 @@ int LoadSession(WPARAM wparam,LPARAM lparam) int dup=0; int hidden[255]={'0'}; HANDLE hContact; - DWORD session_list_t[255]={0}; + HANDLE session_list_t[255]={0}; int mode=0; int i=0,j=0; if ((UINT)lparam>=ses_limit&&lparam!=256) @@ -622,27 +610,24 @@ int LoadSession(WPARAM wparam,LPARAM lparam) mode=1; lparam-=ses_limit; } - if (session_list_recovered[0]&&lparam==256&&mode==0) + if (session_list_recovered[0]&&lparam == 256&&mode == 0) memcpy(session_list_t,session_list_recovered,SIZEOF(session_list_t)); else - for (hContact = db_find_first(); hContact; - hContact = db_find_next(hContact)) - { - if (LoadContactsFromMask(hContact,mode,lparam)) - { + for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + if (LoadContactsFromMask(hContact,mode,lparam)) { i=GetInSessionOrder(hContact,mode, lparam); - session_list_t[i]=(DWORD)hContact; + session_list_t[i] = hContact; } } i=0; //TODO: change to "switch" while(session_list_t[i]!=0) { - if (CheckForDuplicate(session_list,session_list_t[i])==-1) + if (CheckForDuplicate(session_list, session_list_t[i]) == -1) CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)session_list_t[i], 0); else if (g_bWarnOnHidden) { - if (!CheckContactVisibility((HANDLE)session_list_t[i])) + if (!CheckContactVisibility(session_list_t[i])) { hidden[j]=i+1; j++; @@ -652,13 +637,13 @@ int LoadSession(WPARAM wparam,LPARAM lparam) i++; } - if (i==0) + if (i == 0) { if (g_bOtherWarnings) MessageBox(NULL, TranslateT("No contacts to open"), TranslateT("Sessions Manager"), MB_OK|MB_ICONWARNING); return 1; } - else if (dup==i) + else if (dup == i) { if (!hidden) { @@ -673,7 +658,7 @@ int LoadSession(WPARAM wparam,LPARAM lparam) } else if (g_bWarnOnHidden) { - if (MessageBox(NULL, TranslateT("This Session already opened(but probably hidden)\nDo you want to show hidden contacts?"), TranslateT("Sessions Manager"), MB_YESNO|MB_ICONQUESTION)==IDYES) + if (MessageBox(NULL, TranslateT("This Session already opened(but probably hidden)\nDo you want to show hidden contacts?"), TranslateT("Sessions Manager"), MB_YESNO|MB_ICONQUESTION) == IDYES) { j=0; while(hidden[j]!=0) @@ -768,11 +753,6 @@ int DeleteAutoSession(int ses_count) int SessionPreShutdown(WPARAM wparam,LPARAM lparam) { DONT=1; - DestroyServiceFunction(hServiceOpenManager); - DestroyServiceFunction(hServiceCloseCurrentSession); - DestroyServiceFunction(hServiceShowFavMenu); - DestroyServiceFunction(hServiceLoadLastSession); - DestroyServiceFunction(hServiceSaveUserSession); if (g_hDlg) DestroyWindow(g_hDlg); if (g_hSDlg) DestroyWindow(g_hSDlg); @@ -780,7 +760,7 @@ int SessionPreShutdown(WPARAM wparam,LPARAM lparam) if (g_bIncompletedSave) { int i=0; while(session_list_recovered[i]) { - db_set_b((HANDLE)session_list_recovered[i], MODNAME, "wasInLastSession", 0); + db_set_b(session_list_recovered[i], MODNAME, "wasInLastSession", 0); i++; } } @@ -793,17 +773,16 @@ int OkToExit(WPARAM wparam,LPARAM lparam) { int exitmode=db_get_b(NULL, MODNAME, "ShutdownMode", 2); DONT=1; - if (exitmode==2&&session_list[0]!=0) - { + if (exitmode == 2&&session_list[0]!=0) { SaveSessionDate(); SaveSessionHandles(0,0); db_set_b(NULL, MODNAME, "lastempty", 0); } - else if (exitmode==1&&session_list[0]!=0) + else if (exitmode == 1&&session_list[0]!=0) { DialogBox(hinstance,MAKEINTRESOURCE(IDD_EXDIALOG), 0, ExitDlgProc); } - else db_set_b(NULL, MODNAME, "lastempty", 1); + else db_set_b(NULL, MODNAME, "lastempty", 1); return 0; } @@ -811,15 +790,13 @@ static int GetContactHandle(WPARAM wparam,LPARAM lParam) { MessageWindowEventData *MWeventdata = (MessageWindowEventData*)lParam; - if (MWeventdata->uType == MSG_WINDOW_EVT_OPEN) - { + if (MWeventdata->uType == MSG_WINDOW_EVT_OPEN) { if (strstr(MWeventdata->szModule,"tabSRMsg")) g_mode=1; - AddToCurSession((DWORD)MWeventdata->hContact,0); + AddToCurSession(MWeventdata->hContact,0); if (g_bCrashRecovery) db_set_b(MWeventdata->hContact, MODNAME, "wasInLastSession", 1); } - else if (MWeventdata->uType == MSG_WINDOW_EVT_CLOSE) - { - if (!DONT) DelFromCurSession((DWORD)MWeventdata->hContact,0); + else if (MWeventdata->uType == MSG_WINDOW_EVT_CLOSE) { + if (!DONT) DelFromCurSession(MWeventdata->hContact,0); if (g_bCrashRecovery) db_set_b(MWeventdata->hContact, MODNAME, "wasInLastSession", 0); } @@ -835,7 +812,7 @@ INT_PTR BuildFavMenu(WPARAM wparam,LPARAM lparam) GetCursorPos(&pt); FillFavoritesMenu(hMenu,g_ses_count); res = TrackPopupMenu(hMenu, TPM_RETURNCMD|TPM_NONOTIFY, pt.x, pt.y, 0, GetActiveWindow(), NULL); - if (res==0) return 1; + if (res == 0) return 1; LoadSession(0,(res-1)+ses_limit); return 0; } @@ -875,50 +852,14 @@ static int PluginInit(WPARAM wparam,LPARAM lparam) HookEvent(ME_OPT_INITIALISE, OptionsInit); HookEvent(ME_TTB_MODULELOADED, CreateButtons); - hServiceShowFavMenu = CreateServiceFunction(MS_SESSIONS_SHOWFAVORITESMENU, BuildFavMenu); - hServiceOpenManager = CreateServiceFunction(MS_SESSIONS_OPENMANAGER, OpenSessionsManagerWindow); - hServiceLoadLastSession = CreateServiceFunction(MS_SESSIONS_RESTORELASTSESSION, LoadLastSession/*LoadSession*/); - hServiceSaveUserSession = CreateServiceFunction(MS_SESSIONS_SAVEUSERSESSION, SaveUserSessionHandles); - hServiceCloseCurrentSession = CreateServiceFunction(MS_SESSIONS_CLOSESESSION, CloseCurrentSession); - - g_ses_count = db_get_b(0, MODNAME, "UserSessionsCount", 0); - if (!g_ses_count) - g_ses_count = db_get_b(0, "Sessions (Unicode)", "UserSessionsCount", 0); - 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); - - if (g_bCrashRecovery) - g_bIncompletedSave=!db_get_b(NULL, MODNAME, "lastSaveCompleted", 0); - - if (g_bIncompletedSave) - { - int i=0; - HANDLE hContact; - ZeroMemory(session_list_recovered,255); - - for (hContact = db_find_first(); hContact; - hContact = db_find_next(hContact)) - { - if (db_get_b(hContact, MODNAME, "wasInLastSession", 0)) - session_list_recovered[i++]=(DWORD)hContact; - } - } - if (!session_list_recovered[0]) g_bIncompletedSave=FALSE; - db_set_b(NULL, MODNAME, "lastSaveCompleted", 0); - - if (!db_get_b(NULL, MODNAME, "lastempty", 1)||g_bIncompletedSave) isLastTRUE=TRUE; - startup=db_get_b(NULL, MODNAME, "StartupMode", 3); - if (startup==1||(startup==3&&isLastTRUE==TRUE)) + if (startup == 1||(startup == 3&&isLastTRUE == TRUE)) { StartUp=TRUE; g_hDlg=CreateDialog(hinstance,MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc); } - else if (startup==2&&isLastTRUE==TRUE) + else if (startup == 2&&isLastTRUE == TRUE) { g_hghostw=TRUE; g_hDlg=CreateDialog(hinstance,MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc); @@ -1007,6 +948,38 @@ extern "C" __declspec(dllexport) int Load(void) { mir_getLP(&pluginInfo); + CreateServiceFunction(MS_SESSIONS_SHOWFAVORITESMENU, BuildFavMenu); + CreateServiceFunction(MS_SESSIONS_OPENMANAGER, OpenSessionsManagerWindow); + CreateServiceFunction(MS_SESSIONS_RESTORELASTSESSION, LoadLastSession/*LoadSession*/); + CreateServiceFunction(MS_SESSIONS_SAVEUSERSESSION, SaveUserSessionHandles); + CreateServiceFunction(MS_SESSIONS_CLOSESESSION, CloseCurrentSession); + + g_ses_count = db_get_b(0, MODNAME, "UserSessionsCount", 0); + if (!g_ses_count) + g_ses_count = db_get_b(0, "Sessions (Unicode)", "UserSessionsCount", 0); + 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); + + if (g_bCrashRecovery) + g_bIncompletedSave=!db_get_b(NULL, MODNAME, "lastSaveCompleted", 0); + + if (g_bIncompletedSave) { + int i=0; + ZeroMemory(session_list_recovered, sizeof(session_list_recovered)); + + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + if (db_get_b(hContact, MODNAME, "wasInLastSession", 0)) + session_list_recovered[i++] = hContact; + } + if (!session_list_recovered[0]) g_bIncompletedSave=FALSE; + db_set_b(NULL, MODNAME, "lastSaveCompleted", 0); + + if (!db_get_b(NULL, MODNAME, "lastempty", 1)||g_bIncompletedSave) + isLastTRUE = TRUE; + HookEvent(ME_SYSTEM_MODULESLOADED, PluginInit); HookEvent(ME_SYSTEM_OKTOEXIT, OkToExit); HookEvent(ME_SYSTEM_PRESHUTDOWN, SessionPreShutdown); diff --git a/plugins/Sessions/Src/Options.cpp b/plugins/Sessions/Src/Options.cpp index e8860f6f6f..926d641226 100644 --- a/plugins/Sessions/Src/Options.cpp +++ b/plugins/Sessions/Src/Options.cpp @@ -31,7 +31,7 @@ static BOOL bOptionsInit; int opses_count; BOOL bSesssionNameChanged=0; -DWORD session_list_t[255]={0}; +HANDLE session_list_t[255]={0}; HWND g_opHdlg; @@ -44,115 +44,100 @@ BOOL bChecked=FALSE; int OpLoadSessionContacts(WPARAM wparam,LPARAM lparam) { - HANDLE hContact; - int i=0; - ZeroMemory(session_list_t,SIZEOF(session_list_t)); - - for (hContact = db_find_first(); hContact; - hContact = db_find_next(hContact)) - { - if (LoadContactsFromMask(hContact,1,lparam)) - { - i=GetInSessionOrder(hContact,1, lparam); - session_list_t[i]=(DWORD)hContact; + ZeroMemory(session_list_t, sizeof(session_list_t)); + + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + if (LoadContactsFromMask(hContact,1,lparam)) { + int i = GetInSessionOrder(hContact,1, lparam); + session_list_t[i] = hContact; } } - i=0; - while(session_list_t[i]!=0) - { - SendDlgItemMessage(g_opHdlg, IDC_OPCLIST, LB_ADDSTRING, 0, - (LPARAM)(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, - (WPARAM)session_list_t[i], GCDNF_TCHAR)); - i++; - } + int 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; } static LRESULT CALLBACK ComboBoxSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch (msg) - { - case WM_ERASEBKGND: - return TRUE; - - case EM_SETSEL: - if (!hOpClistControl) - return HideCaret(hwnd); - break; - - case WM_GETDLGCODE: - if (!hOpClistControl) - return DLGC_WANTARROWS; - break; + switch (msg) { + case WM_ERASEBKGND: + return TRUE; - case WM_SETCURSOR: - { - if (!hOpClistControl) - { - SetCursor(LoadCursor(NULL, IDC_ARROW)); - return TRUE; - } - }break; + case EM_SETSEL: + if (!hOpClistControl) + return HideCaret(hwnd); + break; - case WM_LBUTTONDOWN: - if (hOpClistControl) - break; - HideCaret(hwnd); + case WM_GETDLGCODE: + if (!hOpClistControl) + return DLGC_WANTARROWS; + break; - case WM_LBUTTONDBLCLK: - case WM_MBUTTONDOWN: - case WM_MBUTTONDBLCLK: - SendMessage(hComboBox,CB_SHOWDROPDOWN,1,0); + case WM_SETCURSOR: + if (!hOpClistControl) { + SetCursor(LoadCursor(NULL, IDC_ARROW)); return TRUE; + } + break; - case WM_NCLBUTTONDBLCLK: - case WM_NCLBUTTONDOWN: - if (!bChecked) - { - MarkUserDefSession(opses_count,1); - hIcon=hMarked; - bChecked=TRUE; - RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_FRAME); - } - else - { - MarkUserDefSession(opses_count,0); - hIcon=hNotMarked; - bChecked=FALSE; - RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_FRAME); - } + case WM_LBUTTONDOWN: + if (hOpClistControl) break; + HideCaret(hwnd); + + case WM_LBUTTONDBLCLK: + case WM_MBUTTONDOWN: + case WM_MBUTTONDBLCLK: + SendMessage(hComboBox,CB_SHOWDROPDOWN,1,0); + return TRUE; + + case WM_NCLBUTTONDBLCLK: + case WM_NCLBUTTONDOWN: + if (!bChecked) { + MarkUserDefSession(opses_count,1); + hIcon = hMarked; + bChecked = TRUE; + RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_FRAME); + } + else { + MarkUserDefSession(opses_count,0); + hIcon = hNotMarked; + bChecked = FALSE; + RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_FRAME); + } + break; - case WM_MOUSEMOVE: - if (hOpClistControl) - break; - - case WM_NCMOUSEMOVE: - return TRUE; - - case WM_NCPAINT: - { - hdc=GetDC(hwnd); - GetClientRect(hwnd, &rc); - rc.left=rc.right; - rc.right=rc.left+16; + case WM_MOUSEMOVE: + if (hOpClistControl) + break; - FillRect(hdc, &rc, (HBRUSH)GetSysColor(COLOR_WINDOW)); - DrawIconEx(hdc, rc.left, 0, hIcon, 16, 16, 0, NULL, DI_NORMAL); - ReleaseDC(hwnd, hdc); - }break; + case WM_NCMOUSEMOVE: + return TRUE; + + case WM_NCPAINT: + hdc = GetDC(hwnd); + GetClientRect(hwnd, &rc); + 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); + break; - case WM_NCCALCSIZE: + case WM_NCCALCSIZE: { NCCALCSIZE_PARAMS *ncsParam = (NCCALCSIZE_PARAMS*)lParam; ncsParam->rgrc[ 0 ].right -= 16; - }break; + } + break; - case WM_NCHITTEST: + case WM_NCHITTEST: { LRESULT lr = mir_callNextSubclass(hwnd, ComboBoxSubclassProc, msg, wParam, lParam ); - if (lr==HTNOWHERE ) + if (lr == HTNOWHERE ) lr = HTOBJECT; return lr; } @@ -198,40 +183,38 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) CheckDlgButton(hdlg,IDC_CRASHRECOVERY,g_bCrashRecovery?BST_CHECKED:BST_UNCHECKED); - if (startupmode==1) + if (startupmode == 1) CheckDlgButton(hdlg,IDC_STARTDIALOG,BST_CHECKED); - else if (startupmode==3) - { + else if (startupmode == 3) { CheckDlgButton(hdlg,IDC_STARTDIALOG,BST_CHECKED); CheckDlgButton(hdlg,IDC_CHECKLAST,BST_CHECKED); } - else if (startupmode==2) - { + else if (startupmode == 2) { CheckDlgButton(hdlg,IDC_RLOADLAST,BST_CHECKED); EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), FALSE); } - else if (startupmode==0) - { + 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); EnableWindow(GetDlgItem(hdlg, IDC_CHECKLAST), FALSE); } - if (exitmode==0) - { + + 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); } - else if (exitmode==1) CheckDlgButton(hdlg,IDC_REXASK,BST_CHECKED); - else if (exitmode==2) CheckDlgButton(hdlg,IDC_REXSAVE,BST_CHECKED); + else if (exitmode == 1) + CheckDlgButton(hdlg,IDC_REXASK,BST_CHECKED); + else if (exitmode == 2) + CheckDlgButton(hdlg,IDC_REXSAVE,BST_CHECKED); LoadSessionToCombobox (hdlg,1,255,"UserSessionDsc",0); - if (SendDlgItemMessage(hdlg, IDC_LIST, CB_GETCOUNT, 0, 0)) - { + if (SendDlgItemMessage(hdlg, IDC_LIST, CB_GETCOUNT, 0, 0)) { EnableWindow(GetDlgItem(hdlg,IDC_EDIT),TRUE); SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0); if (!OpLoadSessionContacts(0,opses_count)) @@ -247,7 +230,8 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) SetWindowPos( hComboBoxEdit, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED ); bOptionsInit=FALSE; - }break; + } + break; case WM_CTLCOLORLISTBOX: switch(GetDlgCtrlID((HWND) lparam)) { @@ -263,31 +247,34 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) { int iDelay=GetDlgItemInt(hdlg, IDC_STARTDELAY,NULL, FALSE); db_set_w(0, MODNAME, "StartupModeDelay", (WORD)iDelay); - db_set_b(0, MODNAME, "TrackCount", (BYTE)(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)) db_set_b(NULL, MODNAME, "ShutdownMode", 0); - else if (IsDlgButtonChecked(hdlg, IDC_REXASK)) db_set_b(NULL, MODNAME, "ShutdownMode", 1); - - if (IsDlgButtonChecked(hdlg, IDC_STARTDIALOG)) - { + if (IsDlgButtonChecked(hdlg, IDC_REXSAVE)) + db_set_b(NULL, MODNAME, "ShutdownMode", 2); + else if (IsDlgButtonChecked(hdlg, IDC_REXDSAVE)) + db_set_b(NULL, MODNAME, "ShutdownMode", 0); + else if (IsDlgButtonChecked(hdlg, IDC_REXASK)) + db_set_b(NULL, MODNAME, "ShutdownMode", 1); + + if (IsDlgButtonChecked(hdlg, IDC_STARTDIALOG)) { if (!IsDlgButtonChecked(hdlg, IDC_CHECKLAST)) db_set_b(NULL, MODNAME, "StartupMode", 1); - else db_set_b(NULL, MODNAME, "StartupMode", 3); + else + db_set_b(NULL, MODNAME, "StartupMode", 3); } - else if (IsDlgButtonChecked(hdlg, IDC_RLOADLAST)) db_set_b(NULL, MODNAME, "StartupMode", 2); - else if (IsDlgButtonChecked(hdlg, IDC_RNOTHING)) db_set_b(NULL, MODNAME, "StartupMode", 0); + else if (IsDlgButtonChecked(hdlg, IDC_RLOADLAST)) + db_set_b(NULL, MODNAME, "StartupMode", 2); + else if (IsDlgButtonChecked(hdlg, IDC_RNOTHING)) + db_set_b(NULL, MODNAME, "StartupMode", 0); db_set_b(NULL, MODNAME, "ExclHidden", (BYTE)(IsDlgButtonChecked(hdlg, IDC_EXCLHIDDEN) ? (g_bExclHidden = 1) : (g_bExclHidden = 0))); db_set_b(NULL, MODNAME, "WarnOnHidden", (BYTE)(IsDlgButtonChecked(hdlg, IDC_LASTHIDDENWARN) ? (g_bWarnOnHidden = 1) : (g_bWarnOnHidden = 0))); db_set_b(NULL, MODNAME, "OtherWarnings", (BYTE)(IsDlgButtonChecked(hdlg, IDC_WARNINGS) ? (g_bOtherWarnings = 1) : (g_bOtherWarnings = 0))); db_set_b(NULL, MODNAME, "CrashRecovery", (BYTE)(IsDlgButtonChecked(hdlg, IDC_CRASHRECOVERY) ? (g_bCrashRecovery = 1) : (g_bCrashRecovery = 0))); - - return 1; } + return 1; case CLN_CHECKCHANGED: - if (((LPNMHDR)lparam)->idFrom ==IDC_EMCLIST) + if (((LPNMHDR)lparam)->idFrom == IDC_EMCLIST) { int iSelection = (int)((NMCLISTCONTROL *)lparam)->hItem; HANDLE hContact = db_find_first(); @@ -350,10 +337,7 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) }break; case IDC_EDIT: - if (!hOpClistControl) - { - int i; - HANDLE hItem; + if (!hOpClistControl) { ShowWindow(GetDlgItem(hdlg,IDC_OPCLIST),SW_HIDE); EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE); //EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); @@ -368,15 +352,12 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) SendMessage(hOpClistControl,WM_TIMER,TIMERID_REBUILDAFTER,0); - for (i=0 ; session_list_t[i]>0; i++) - { - hItem=(HANDLE)SendMessage(hOpClistControl,CLM_FINDCONTACT, (WPARAM)session_list_t[i], 0); - //hItem=session_list[i]; + 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 - { + else { ShowWindow(GetDlgItem(hdlg,IDC_OPCLIST),SW_SHOWNA); EnableWindow(GetDlgItem(hdlg,IDC_DEL),TRUE); EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE); @@ -388,20 +369,16 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) case IDC_SAVE: { - int i; - HANDLE hContact = db_find_first(); - for (i=0 ; hContact;hContact = db_find_next(hContact)) - { + int i=0; + for (HANDLE 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, (WPARAM)hContact, 0), 0); - if (res) - { + if (res) { SetSessionMark(hContact,1,'1',opses_count); SetInSessionOrder(hContact,1,opses_count,i); i++; } - else - { + else { SetSessionMark(hContact,1,'0',opses_count); SetInSessionOrder(hContact,1,opses_count,0); } @@ -417,31 +394,30 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) bSesssionNameChanged=FALSE; } EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE); - }break; + } + break; case IDC_DEL: - { - int i=0,index=0; - DelUserDefSession(opses_count); + DelUserDefSession(opses_count); - SendDlgItemMessage(hdlg, IDC_OPCLIST, LB_RESETCONTENT, 0, 0); - SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0); + 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); - SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0); - if (!OpLoadSessionContacts(0,opses_count)) - EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE); - } - else { - EnableWindow(GetDlgItem(hdlg,IDC_EDIT),FALSE); + if (SendDlgItemMessage(hdlg, IDC_LIST, CB_GETCOUNT, 0, 0)) { + 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); - } - }break; + } + else { + EnableWindow(GetDlgItem(hdlg,IDC_EDIT),FALSE); + EnableWindow(GetDlgItem(hdlg,IDC_DEL),FALSE); + } + break; case IDC_STARTDIALOG: EnableWindow(GetDlgItem(hdlg, IDC_STARTDELAY), TRUE); @@ -492,14 +468,14 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) break; } - if (HIWORD(wparam)==CBN_DROPDOWN&&!hOpClistControl) { + 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) { + if ((HIWORD(wparam)!=CBN_DROPDOWN)&&(LOWORD(wparam) == IDC_LIST)&&!hOpClistControl) { SendMessage(hComboBoxEdit,EM_SCROLLCARET ,0,0); HideCaret(hComboBoxEdit); } @@ -507,8 +483,8 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) 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)))) + 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; @@ -533,4 +509,4 @@ int OptionsInit(WPARAM wparam,LPARAM lparam) Options_AddPage(wparam,&odp); return 0; -} \ No newline at end of file +} diff --git a/plugins/Sessions/Src/Sessions.h b/plugins/Sessions/Src/Sessions.h index 7ad107b01d..b7e9186f62 100644 --- a/plugins/Sessions/Src/Sessions.h +++ b/plugins/Sessions/Src/Sessions.h @@ -58,8 +58,8 @@ INT_PTR CloseCurrentSession(WPARAM ,LPARAM ); int SaveSessionDate(); extern HINSTANCE hinstance; -extern DWORD session_list_recovered[255]; -extern DWORD session_list[255]; +extern HANDLE session_list_recovered[255]; +extern HANDLE session_list[255]; extern unsigned int ses_limit; extern unsigned int g_ses_count; extern BOOL g_bExclHidden; diff --git a/plugins/Sessions/Src/Utils.cpp b/plugins/Sessions/Src/Utils.cpp index d2f5c58c12..480c8d3c0f 100644 --- a/plugins/Sessions/Src/Utils.cpp +++ b/plugins/Sessions/Src/Utils.cpp @@ -17,55 +17,43 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - #include "sessions.h" -void AddSessionMark(HANDLE hContact,int mode,char bit) +void AddSessionMark(HANDLE hContact, int mode, char bit) { + DBVARIANT dbv; unsigned int i; char temp_1[1]={'\0'},temp_2[1]={'\0'}; char szDst[256]={'\0'}; char* pszBuffer=NULL; - if (mode==0) - { - DBVARIANT dbv; - if (!db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv) && dbv.pszVal) - { + if (mode == 0) { + if (!db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv) && dbv.pszVal) { temp_1[0]=dbv.pszVal[0]; - for (i=0;i