summaryrefslogtreecommitdiff
path: root/plugins/UserInfoEx/src/psp_base.cpp
blob: 514e12a9923daf836411815d8115f6d47c1eb4b2 (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
/*
UserinfoEx plugin for Miranda IM

Copyright:
© 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol

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 "stdafx.h"

PSPBaseDlg::PSPBaseDlg(int idDialog) :
	CUserInfoPageDlg(g_plugin, idDialog),
	m_ctrlList(nullptr)
{
	m_bFixedSize = true;
}

bool PSPBaseDlg::OnInitDialog()
{
	m_ctrlList = CCtrlList::CreateObj(m_hwnd);

	SendDlgItemMessage(m_hwnd, IDC_PAGETITLE, WM_SETFONT, (WPARAM)GetBoldFont(), 0);
	return true;
}

bool PSPBaseDlg::OnRefresh()
{
	if (auto *pszProto = GetBaseProto())
		if (m_ctrlList)
			return m_ctrlList->OnInfoChanged(m_hContact, pszProto);

	return false;
}

bool PSPBaseDlg::OnApply()
{
	if (auto *pszProto = GetBaseProto())		
		m_ctrlList->OnApply(m_hContact, pszProto);
	
	return true;
}

void PSPBaseDlg::OnReset()
{
	m_ctrlList->OnReset();
}

void PSPBaseDlg::OnDestroy()
{
	m_ctrlList->Release();
}

// Default dialog procedure, which handles common functions
INT_PTR PSPBaseDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg) {
	// set propertysheet page's background white in aero mode
	case WM_CTLCOLORSTATIC:
	case WM_CTLCOLORDLG:
		if (IsAeroMode())
			return (INT_PTR)GetStockBrush(WHITE_BRUSH);
		break;

	// Set text color of edit boxes according to the source of information they display.
	case WM_CTLCOLOREDIT:
		if (m_ctrlList)
			return m_ctrlList->OnSetTextColour((HWND)lParam, (HDC)wParam);
		break;

	case WM_COMMAND:
		if (m_ctrlList && !PspIsLocked(m_hwnd))
			m_ctrlList->OnChangedByUser(LOWORD(wParam), HIWORD(wParam));
		break;
	}
	
	return CUserInfoPageDlg::DlgProc(uMsg, wParam, lParam);
}

HFONT PSPBaseDlg::GetBoldFont() const
{
	HFONT res = nullptr;
	return SendMessage(m_hwndParent, PSM_GETBOLDFONT, INDEX_CURPAGE, LPARAM(&res)) ? res : nullptr;
}

MCONTACT PSPBaseDlg::GetContact() const
{
	MCONTACT res = 0;
	return SendMessage(m_hwndParent, PSM_GETCONTACT, INDEX_CURPAGE, LPARAM(&res)) ? res : 0;
}

const char *PSPBaseDlg::GetBaseProto() const
{
	const char *res = "";
	return (SendMessage(m_hwndParent, PSM_GETBASEPROTO, INDEX_CURPAGE, LPARAM(&res)) && *res) ? res : nullptr;
}

void PSPBaseDlg::UpdateCountryIcon(CCtrlCombo &pCombo)
{
	LPIDSTRLIST pd = (LPIDSTRLIST)pCombo.GetCurData();
	if (pd == nullptr)
		return;

	auto *pCtrl = FindControl(ICO_COUNTRY);
	HICON hIcon = LoadFlagIcon(pd->nID);
	HICON hOld = Static_SetIcon(pCtrl->GetHwnd(), hIcon);
	pCtrl->Show(hIcon != 0);
	IcoLib_ReleaseIcon(hOld);
}