summaryrefslogtreecommitdiff
path: root/plugins/SendScreenshotPlus/src/UAboutForm.cpp
blob: 6b1e9c56425d88d9620b3099c93037a475e812f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*

Miranda NG: the free IM client for Microsoft* Windows*

Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org),
Copyright (c) 2000-09 Miranda ICQ/IM project,

This file is part of Send Screenshot Plus, a Miranda IM plugin.
Copyright (c) 2010 Ing.U.Horn

Parts of this file based on original sorce code
(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "global.h"

#include <list>
void TfrmAbout::Unload(){
	std::list<TfrmAbout*> lst;
	for(CHandleMapping::iterator iter=_HandleMapping.begin(); iter!=_HandleMapping.end(); ++iter){
		lst.push_back(iter->second);//we can't delete inside loop.. not MT compatible
	}
	while(!lst.empty()){
		DestroyWindow(lst.front()->m_hWnd);//deletes class
		lst.pop_front();
	}
}

//---------------------------------------------------------------------------
TfrmAbout::CHandleMapping TfrmAbout::_HandleMapping;

INT_PTR CALLBACK TfrmAbout::DlgTfrmAbout(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	if (msg == WM_CTLCOLOREDIT || msg == WM_CTLCOLORSTATIC) {
		switch ( GetWindowLongPtr(( HWND )lParam, GWL_ID )) {
			case IDC_CREDIT:
			case IDC_LICENSE:
				SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT));
				break;
			default:
				return FALSE;
		}
		return (LRESULT)GetStockObject(WHITE_BRUSH); 	//GetSysColorBrush(COLOR_WINDOW);
	}

	CHandleMapping::iterator wnd(_HandleMapping.end());
	if (msg == WM_INITDIALOG) {
		wnd = _HandleMapping.insert(CHandleMapping::value_type(hWnd, reinterpret_cast<TfrmAbout*>(lParam))).first;
		reinterpret_cast<TfrmAbout*>(lParam)->m_hWnd = hWnd;
		return wnd->second->wmInitdialog(wParam, lParam);
	}
	wnd=_HandleMapping.find(hWnd);
	if (wnd==_HandleMapping.end()) {	// something screwed up
		return FALSE;					//dialog! do not use ::DefWindowProc(hWnd, msg, wParam, lParam);
	}

	switch (msg)
	{
		// case WM_INITDIALOG:	done on top
		case WM_COMMAND:
			return wnd->second->wmCommand(wParam, lParam);
			break;
		case WM_CLOSE:
			return wnd->second->wmClose(wParam, lParam);
			break;
		case WM_DESTROY:
			delete wnd->second;
			break;
	}
	return FALSE;
}

//---------------------------------------------------------------------------
//WM_INITDIALOG:
LRESULT TfrmAbout::wmInitdialog(WPARAM wParam, LPARAM lParam) {
	// Headerbar
	SendDlgItemMessage(m_hWnd, IDC_HEADERBAR, WM_SETICON, ICON_BIG, (LPARAM)GetIcon(ICO_MAIN));

	//License
	{
		TCHAR* pszText = NULL;
		mir_tstradd(pszText, _T(__COPYRIGHT));
		mir_tstradd(pszText, _T("\r\n\r\n"));

		HRSRC hRes = FindResource(g_hSendSS,MAKEINTRESOURCE(IDR_LICENSE),_T("TEXT"));
		DWORD size = SizeofResource(g_hSendSS,hRes);
		char* data = (char*)mir_alloc(size+1);
		memcpy(data,LockResource(LoadResource(g_hSendSS,hRes)),size);
		data[size] = '\0';
		TCHAR* pszCopyright = mir_a2t(data);
		mir_free(data);
		mir_tstradd(pszText, pszCopyright);
		mir_free(pszCopyright);
		SetDlgItemText(m_hWnd,IDC_LICENSE, pszText);
		mir_free(pszText);
	}

	//Credit
	{
		HRSRC hRes = FindResource(g_hSendSS,MAKEINTRESOURCE(IDR_CREDIT),_T("TEXT"));
		DWORD size = SizeofResource(g_hSendSS,hRes);
		char* data = (char*)mir_alloc(size+1);
		memcpy(data,LockResource(LoadResource(g_hSendSS,hRes)),size);
		data[size] = '\0';
		TCHAR* pszText = mir_a2t(data);
		mir_free(data);
		SetDlgItemText(m_hWnd,IDC_CREDIT, pszText);
		mir_free(pszText);
	}

	SendMessage(m_hWnd, WM_SETICON, ICON_BIG,	(LPARAM)GetIcon(ICO_MAIN));
	SendMessage(m_hWnd, WM_SETICON, ICON_SMALL,	(LPARAM)GetIcon(ICO_MAINXS));

	//init controls
	btnPageClick();

	TranslateDialogDefault(m_hWnd);
	return FALSE;
}

//WM_COMMAND:
LRESULT TfrmAbout::wmCommand(WPARAM wParam, LPARAM lParam) {
	//---------------------------------------------------------------------------
	if (HIWORD(wParam) == BN_CLICKED) {
		switch(LOWORD(wParam)) {
			case IDCANCEL: // ESC pressed
				this->Close();
				break;
			case IDA_btnClose:
				Close();
				break;
			case IDA_CONTRIBLINK:
				m_Page = !m_Page;
				btnPageClick();
				break;
			default:
				break;
		}
	}
	return FALSE;
}

//WM_CLOSE:
LRESULT TfrmAbout::wmClose(WPARAM wParam, LPARAM lParam) {
	SendMessage(m_hWndOwner,UM_CLOSING, (WPARAM)m_hWnd, (LPARAM)IDD_UAboutForm);
	DestroyWindow(m_hWnd);
	return FALSE;
}

//---------------------------------------------------------------------------
TfrmAbout::TfrmAbout(HWND Owner) {
	m_hWndOwner = Owner;
	m_Page = 1;
	// create window
	m_hWnd = CreateDialogParam(g_hSendSS, MAKEINTRESOURCE(IDD_UAboutForm),0, DlgTfrmAbout,(LPARAM)this);
	//register object
	_HandleMapping.insert(CHandleMapping::value_type(m_hWnd, this));
}

TfrmAbout::~TfrmAbout() {
	_HandleMapping.erase(m_hWnd);
}

//---------------------------------------------------------------------------
void TfrmAbout::btnPageClick() {
	HWND hCtrl = GetDlgItem(m_hWnd, IDA_CONTRIBLINK);
	const TCHAR* credits=TranslateT("Credits");
	const TCHAR* copyright=TranslateT("Copyright");
	const TCHAR* title;
	const TCHAR* button;
	if(!m_Page) {
		ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_HIDE);
		ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_SHOW);
		SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_ARROWR));
		title=copyright;
		button=credits;
	} else {
		ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_SHOW);
		ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_HIDE);
		SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)GetIconBtn(ICO_BTN_ARROWL));
		title=credits;
		button=copyright;
	}
	SetWindowText(hCtrl, button);
	TCHAR newTitle[128];
	TCHAR* pszPlug = mir_a2t(__PLUGIN_NAME);
	TCHAR* pszVer  = mir_a2t(__VERSION_STRING_DOTS);
	mir_sntprintf(newTitle,SIZEOF(newTitle), _T("%s - %s\nv%s"), pszPlug, title , pszVer);
	mir_free(pszPlug);
	mir_free(pszVer);
	SetDlgItemText(m_hWnd, IDC_HEADERBAR, newTitle);
	InvalidateRect(GetDlgItem(m_hWnd,IDC_HEADERBAR),NULL,1);
}