diff options
| author | George Hazan <george.hazan@gmail.com> | 2016-06-05 16:11:08 +0000 | 
|---|---|---|
| committer | George Hazan <george.hazan@gmail.com> | 2016-06-05 16:11:08 +0000 | 
| commit | eec361608fde60d63fe4511e26e3b95c7f72be13 (patch) | |
| tree | 0263d1829438c7778a713ee2ae6bbda27c0d260a /plugins/SimpleStatusMsg/src | |
| parent | 7e822f45eccd034e7acd8d868ce5dc8c55458ff0 (diff) | |
- fix for #1059;
- direct unsafe work with icons replaces with Window_SetIcon_IcoLib / Window_SetSkinIcon_IcoLib;
- code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@16917 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SimpleStatusMsg/src')
| -rw-r--r-- | plugins/SimpleStatusMsg/src/awaymsg.cpp | 196 | ||||
| -rw-r--r-- | plugins/SimpleStatusMsg/src/msgbox.cpp | 10 | 
2 files changed, 99 insertions, 107 deletions
diff --git a/plugins/SimpleStatusMsg/src/awaymsg.cpp b/plugins/SimpleStatusMsg/src/awaymsg.cpp index cb3d7eaf0c..1671584e39 100644 --- a/plugins/SimpleStatusMsg/src/awaymsg.cpp +++ b/plugins/SimpleStatusMsg/src/awaymsg.cpp @@ -69,42 +69,41 @@ static INT_PTR CALLBACK ReadAwayMsgDlgProc(HWND hwndDlg, UINT message, WPARAM wP  	AwayMsgDlgData *dat = (AwayMsgDlgData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  	switch (message) {
 -		case WM_INITDIALOG:
 -			TranslateDialogDefault(hwndDlg);
 -			dat = (AwayMsgDlgData *)mir_alloc(sizeof(AwayMsgDlgData));
 -			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
 +	case WM_INITDIALOG:
 +		TranslateDialogDefault(hwndDlg);
 +		dat = (AwayMsgDlgData *)mir_alloc(sizeof(AwayMsgDlgData));
 +		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
 +
 +		dat->hContact = lParam;
 +		dat->hSeq = (HANDLE)CallContactService(dat->hContact, PSS_GETAWAYMSG, 0, 0);
 +		dat->hAwayMsgEvent = dat->hSeq ? HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_AWAYMSG) : NULL;
 +		WindowList_Add(hWindowList, hwndDlg, dat->hContact);
 +		{
 +			TCHAR str[256], format[128];
 +			TCHAR *contactName = (TCHAR *)pcli->pfnGetContactDisplayName(dat->hContact, 0);
 +			char *szProto = GetContactProto(dat->hContact);
 +			WORD dwStatus = db_get_w(dat->hContact, szProto, "Status", ID_STATUS_OFFLINE);
 +			TCHAR *status = pcli->pfnGetStatusModeDescription(dwStatus, 0);
 -			dat->hContact = lParam;
 -			dat->hSeq = (HANDLE)CallContactService(dat->hContact, PSS_GETAWAYMSG, 0, 0);
 -			dat->hAwayMsgEvent = dat->hSeq ? HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_AWAYMSG) : NULL;
 -			WindowList_Add(hWindowList, hwndDlg, dat->hContact);
 -			{
 -				TCHAR str[256], format[128];
 -				TCHAR *contactName = (TCHAR *)pcli->pfnGetContactDisplayName(dat->hContact, 0);
 -				char *szProto = GetContactProto(dat->hContact);
 -				WORD dwStatus = db_get_w(dat->hContact, szProto, "Status", ID_STATUS_OFFLINE);
 -				TCHAR *status = pcli->pfnGetStatusModeDescription(dwStatus, 0);
 -
 -				GetWindowText(hwndDlg, format, _countof(format));
 -				mir_sntprintf(str, format, status, contactName);
 -				SetWindowText(hwndDlg, str);
 -				if (dat->hSeq) {
 -					GetDlgItemText(hwndDlg, IDC_RETRIEVING, format, _countof(format));
 -					mir_sntprintf(str, format, status);
 -				}
 -				else {
 -					mir_sntprintf(str, TranslateT("Failed to retrieve %s message."), status);
 -					SetDlgItemText(hwndDlg, IDOK, TranslateT("&Close"));
 -				}
 -				SetDlgItemText(hwndDlg, IDC_RETRIEVING, str);
 -				SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_LoadProtoIcon(szProto, dwStatus));
 -				SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_LoadProtoIcon(szProto, dwStatus));
 -				EnableWindow(GetDlgItem(hwndDlg, IDC_COPY), FALSE);
 +			GetWindowText(hwndDlg, format, _countof(format));
 +			mir_sntprintf(str, format, status, contactName);
 +			SetWindowText(hwndDlg, str);
 +			if (dat->hSeq) {
 +				GetDlgItemText(hwndDlg, IDC_RETRIEVING, format, _countof(format));
 +				mir_sntprintf(str, format, status);
 +			}
 +			else {
 +				mir_sntprintf(str, TranslateT("Failed to retrieve %s message."), status);
 +				SetDlgItemText(hwndDlg, IDOK, TranslateT("&Close"));
  			}
 -			Utils_RestoreWindowPosition(hwndDlg, lParam, "SRAway", "AwayMsgDlg");
 -			return TRUE;
 +			SetDlgItemText(hwndDlg, IDC_RETRIEVING, str);
 +			Window_SetProtoIcon_IcoLib(hwndDlg, szProto, dwStatus);
 +			EnableWindow(GetDlgItem(hwndDlg, IDC_COPY), FALSE);
 +		}
 +		Utils_RestoreWindowPosition(hwndDlg, lParam, "SRAway", "AwayMsgDlg");
 +		return TRUE;
 -		case HM_AWAYMSG:
 +	case HM_AWAYMSG:
  		{
  			ACKDATA *ack = (ACKDATA *)lParam;
  			if (ack->hContact != dat->hContact || ack->type != ACKTYPE_AWAYMSG)
 @@ -128,53 +127,52 @@ static INT_PTR CALLBACK ReadAwayMsgDlgProc(HWND hwndDlg, UINT message, WPARAM wP  			break;
  		}
 -		case WM_COMMAND:
 -			switch (LOWORD(wParam)) {
 -				case IDCANCEL:
 -				case IDOK:
 -					DestroyWindow(hwndDlg);
 -					break;
 +	case WM_COMMAND:
 +		switch (LOWORD(wParam)) {
 +		case IDCANCEL:
 +		case IDOK:
 +			DestroyWindow(hwndDlg);
 +			break;
 -				case IDC_COPY:
 -					if (!OpenClipboard(hwndDlg))
 +		case IDC_COPY:
 +			if (!OpenClipboard(hwndDlg))
 +				break;
 +			if (EmptyClipboard()) {
 +				TCHAR msg[1024];
 +				int len = GetDlgItemText(hwndDlg, IDC_MSG, msg, _countof(msg));
 +				if (len) {
 +					LPTSTR lptstrCopy;
 +					HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(TCHAR));
 +					if (hglbCopy == NULL) {
 +						CloseClipboard();
  						break;
 -					if (EmptyClipboard()) {
 -						TCHAR msg[1024];
 -						int len = GetDlgItemText(hwndDlg, IDC_MSG, msg, _countof(msg));
 -						if (len) {
 -							LPTSTR lptstrCopy;
 -							HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(TCHAR));
 -							if (hglbCopy == NULL) {
 -								CloseClipboard();
 -								break;
 -							}
 -							lptstrCopy = (LPTSTR)GlobalLock(hglbCopy);
 -							memcpy(lptstrCopy, msg, len * sizeof(TCHAR));
 -							lptstrCopy[len] = (TCHAR)0;
 -							GlobalUnlock(hglbCopy);
 -
 -							SetClipboardData(CF_UNICODETEXT, hglbCopy);
 -
 -						}
  					}
 -					CloseClipboard();
 -					break;
 -			}
 -			break;
 +					lptstrCopy = (LPTSTR)GlobalLock(hglbCopy);
 +					memcpy(lptstrCopy, msg, len * sizeof(TCHAR));
 +					lptstrCopy[len] = (TCHAR)0;
 +					GlobalUnlock(hglbCopy);
 -		case WM_CLOSE:
 -			DestroyWindow(hwndDlg);
 -			break;
 +					SetClipboardData(CF_UNICODETEXT, hglbCopy);
 -		case WM_DESTROY:
 -			if (dat->hAwayMsgEvent)
 -				UnhookEvent(dat->hAwayMsgEvent);
 -			Utils_SaveWindowPosition(hwndDlg, dat->hContact, "SRAway", "AwayMsgDlg");
 -			WindowList_Remove(hWindowList, hwndDlg);
 -			IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, NULL));
 -			IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, NULL));
 -			mir_free(dat);
 +				}
 +			}
 +			CloseClipboard();
  			break;
 +		}
 +		break;
 +
 +	case WM_CLOSE:
 +		DestroyWindow(hwndDlg);
 +		break;
 +
 +	case WM_DESTROY:
 +		if (dat->hAwayMsgEvent)
 +			UnhookEvent(dat->hAwayMsgEvent);
 +		Utils_SaveWindowPosition(hwndDlg, dat->hContact, "SRAway", "AwayMsgDlg");
 +		WindowList_Remove(hWindowList, hwndDlg);
 +		Window_FreeIcon_IcoLib(hwndDlg);
 +		mir_free(dat);
 +		break;
  	}
  	return FALSE;
  }
 @@ -185,8 +183,7 @@ static INT_PTR GetMessageCommand(WPARAM wParam, LPARAM)  		SetForegroundWindow(hwnd);
  		SetFocus(hwnd);
  	}
 -	else
 -		CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_READAWAYMSG), NULL, ReadAwayMsgDlgProc, wParam);
 +	else CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_READAWAYMSG), NULL, ReadAwayMsgDlgProc, wParam);
  	return 0;
  }
 @@ -195,12 +192,9 @@ static INT_PTR CALLBACK CopyAwayMsgDlgProc(HWND hwndDlg, UINT message, WPARAM wP  	AwayMsgDlgData *dat = (AwayMsgDlgData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  	switch (message) {
 -		case WM_INITDIALOG:
 +	case WM_INITDIALOG:
 +		TranslateDialogDefault(hwndDlg);
  		{
 -			TCHAR str[256], format[128];
 -			TCHAR *contactName;
 -
 -			TranslateDialogDefault(hwndDlg);
  			dat = (AwayMsgDlgData *)mir_alloc(sizeof(AwayMsgDlgData));
  			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
 @@ -208,16 +202,17 @@ static INT_PTR CALLBACK CopyAwayMsgDlgProc(HWND hwndDlg, UINT message, WPARAM wP  			dat->hSeq = (HANDLE)CallContactService(dat->hContact, PSS_GETAWAYMSG, 0, 0);
  			dat->hAwayMsgEvent = dat->hSeq ? HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_AWAYMSG) : NULL;
  			WindowList_Add(hWindowList2, hwndDlg, dat->hContact);
 -			contactName = (TCHAR *)pcli->pfnGetContactDisplayName(dat->hContact, 0);
 +			TCHAR *contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0);
 +			TCHAR str[256], format[128];
  			GetWindowText(hwndDlg, format, _countof(format));
  			mir_sntprintf(str, format, contactName);
  			SetWindowText(hwndDlg, str);
  			if (!dat->hSeq)
  				DestroyWindow(hwndDlg);
 -			return TRUE;
  		}
 +		return TRUE;
 -		case HM_AWAYMSG:
 +	case HM_AWAYMSG:
  		{
  			ACKDATA *ack = (ACKDATA *)lParam;
  			if (ack->hContact != dat->hContact || ack->type != ACKTYPE_AWAYMSG) {
 @@ -261,27 +256,27 @@ static INT_PTR CALLBACK CopyAwayMsgDlgProc(HWND hwndDlg, UINT message, WPARAM wP  			}
  			CloseClipboard();
  			DestroyWindow(hwndDlg);
 -			break;
  		}
 +		break;
 -		case WM_COMMAND:
 -			switch (LOWORD(wParam)) {
 -				case IDCANCEL:
 -				case IDOK:
 -					DestroyWindow(hwndDlg);
 -				break;
 -			}
 -			break;
 -
 -		case WM_CLOSE:
 +	case WM_COMMAND:
 +		switch (LOWORD(wParam)) {
 +		case IDCANCEL:
 +		case IDOK:
  			DestroyWindow(hwndDlg);
  			break;
 +		}
 +		break;
 -		case WM_DESTROY:
 -			if (dat->hAwayMsgEvent) UnhookEvent(dat->hAwayMsgEvent);
 -			WindowList_Remove(hWindowList2, hwndDlg);
 -			mir_free(dat);
 -			break;
 +	case WM_CLOSE:
 +		DestroyWindow(hwndDlg);
 +		break;
 +
 +	case WM_DESTROY:
 +		if (dat->hAwayMsgEvent) UnhookEvent(dat->hAwayMsgEvent);
 +		WindowList_Remove(hWindowList2, hwndDlg);
 +		mir_free(dat);
 +		break;
  	}
  	return FALSE;
  }
 @@ -414,6 +409,5 @@ int LoadAwayMsgModule(void)  	hGoToURLMenuItem = Menu_AddContactMenuItem(&mi);
  	HookEvent(ME_CLIST_PREBUILDCONTACTMENU, AwayMsgPreBuildMenu);
 -
  	return 0;
  }
 diff --git a/plugins/SimpleStatusMsg/src/msgbox.cpp b/plugins/SimpleStatusMsg/src/msgbox.cpp index 2e92192c4b..13b3da336a 100644 --- a/plugins/SimpleStatusMsg/src/msgbox.cpp +++ b/plugins/SimpleStatusMsg/src/msgbox.cpp @@ -804,8 +804,8 @@ void ChangeDlgStatus(HWND hwndDlg, struct MsgBoxData *msgbox_data, int iStatus)  	else if (iStatus > ID_STATUS_CURRENT)  		iStatus = GetCurrentStatus(NULL); -	IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_LoadProtoIcon(msgbox_data->m_szProto, iStatus))); -	IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_LoadProtoIcon(msgbox_data->m_szProto, iStatus))); +	Window_FreeIcon_IcoLib(hwndDlg); +	Window_SetProtoIcon_IcoLib(hwndDlg, msgbox_data->m_szProto, iStatus);  	if (!bDisabled && ((Proto_Status2Flag(iStatus) & msgbox_data->m_iStatusMsgModes)  		|| (iStatus == ID_STATUS_OFFLINE && (Proto_Status2Flag(ID_STATUS_INVISIBLE) & msgbox_data->m_iStatusMsgModes)))) @@ -923,8 +923,7 @@ INT_PTR CALLBACK AwayMsgBoxDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA  				icoStatus = init_data->m_iStatus;  			if (icoStatus < ID_STATUS_OFFLINE)  				icoStatus = ID_STATUS_OFFLINE; -			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_LoadProtoIcon(init_data->m_szProto, icoStatus)); -			SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_LoadProtoIcon(init_data->m_szProto, icoStatus)); +			Window_SetProtoIcon_IcoLib(hwndDlg, init_data->m_szProto, icoStatus);  			copy_init_data = (struct MsgBoxData *)mir_alloc(sizeof(struct MsgBoxData)); @@ -1615,8 +1614,7 @@ INT_PTR CALLBACK AwayMsgBoxDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA  			ReleaseIconEx("predef");  			ReleaseIconEx("add");  			ReleaseIconEx("clear"); -			IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); -			IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0)); +			Window_FreeIcon_IcoLib(hwndDlg);  			hwndSAMsgDialog = NULL;  			mir_free(msgbox_data);  | 
