aboutsummaryrefslogtreecommitdiff
path: root/Src/auth/Loginbox/pageEmpty.cpp
blob: 1455c79ac78d971eb73c01da19d66625582f252b (plain) (blame)
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
#include "./pageEmpty.h"
#include "./loginBox.h"
#include "./common.h"
#include "../resource.h"


static HRESULT CALLBACK LoginPageEmpty_CreateInstance(HWND hwnd, HWND hLoginbox, LoginPage **instance)
{
	if (NULL == instance) return E_POINTER;
	if (NULL == hwnd || NULL == hLoginbox) return E_INVALIDARG;

	*instance = new LoginPageEmpty(hwnd, hLoginbox);
	if (NULL == instance) return E_OUTOFMEMORY;

	return S_OK;
}

LoginPageEmpty::LoginPageEmpty(HWND hwnd, HWND hLoginbox)
	: LoginPage(hwnd, hLoginbox)
{
}

LoginPageEmpty::~LoginPageEmpty()
{
}

HWND LoginPageEmpty::CreatePage(HWND hLoginbox, HWND hParent)
{
	return LoginPage::CreatePage(hLoginbox, MAKEINTRESOURCE(IDD_PAGE_EMPTY), 
						hParent, NULL, LoginPageEmpty_CreateInstance);
}

BOOL LoginPageEmpty::OnInitDialog(HWND hFocus, LPARAM param)
{
	if (NULL != hLoginbox)
	{
		BOOL updateActive = LoginBox_GetUpdateState(hLoginbox);
		EnableCheckButton(FALSE == updateActive);
	}

	LoginPage::OnInitDialog(hFocus, param);
	return FALSE;
}

void LoginPageEmpty::OnCommand(UINT commandId, UINT eventType, HWND hControl)
{
	switch(commandId)
	{
		case IDC_CHECKNOW:
			if (BN_CLICKED == eventType && NULL != hLoginbox)
				LoginBox_UpdateProviders(hLoginbox, TRUE);
			break;
	}
	LoginPage::OnCommand(commandId, eventType, hControl);
}

void LoginPageEmpty::UpdateLayout(BOOL fRedraw)
{
	LoginPage::UpdateLayout(fRedraw);

	RECT clientRect;
	GetClientRect(hwnd, &clientRect);

	RECT offsetRect;
	SetRect(&offsetRect, 2, 4, 4, 22);
	MapDialogRect(hwnd, &offsetRect);

	clientRect.left += offsetRect.left;
	clientRect.top += offsetRect.top;
	clientRect.right -= offsetRect.right;
	clientRect.bottom -= offsetRect.bottom;

	UINT flags = SWP_NOACTIVATE | SWP_NOZORDER;
	if (FALSE == fRedraw) flags |= SWP_NOREDRAW;

	const INT szControls[] = { IDC_MESSAGE, IDC_CHECKNOW, IDC_CHECK_STATUS};
	HDWP hdwp = BeginDeferWindowPos(ARRAYSIZE(szControls));

	RECT rect;
	LONG clientTop = clientRect.top;
	LONG left, top = clientRect.top;
	for (INT i = 0; i < ARRAYSIZE(szControls); i++)
	{
		HWND hControl = GetDlgItem(hwnd, szControls[i]);
		if (NULL == hControl || FALSE == GetWindowRect(hControl, &rect)) continue;
		MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rect, 2);

		switch(szControls[i])
		{
			case IDC_MESSAGE:
				top = clientRect.top + ((clientRect.bottom - clientRect.top) - (rect.bottom - rect.top))/2;
				left = clientRect.left + ((clientRect.right - clientRect.left) - (rect.right - rect.left))/2;
				OffsetRect(&rect, left - rect.left, top - rect.top);
				clientTop = rect.bottom;
				break;
			case IDC_CHECKNOW:
				top = clientTop +  2*offsetRect.top;
				left = clientRect.left + ((clientRect.right - clientRect.left) - (rect.right - rect.left))/2;
				OffsetRect(&rect, left - rect.left, top - rect.top);
				break;
			case IDC_CHECK_STATUS:
				top = clientTop + offsetRect.top;
				left = clientRect.left + ((clientRect.right - clientRect.left) - (rect.right - rect.left))/2;
				OffsetRect(&rect, left - rect.left, top - rect.top);
				break;
		}
		
		hdwp = DeferWindowPos(hdwp, hControl, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, flags);
		if (NULL == hdwp) break;
	}

	if (NULL != hdwp)
		EndDeferWindowPos(hdwp);

}

HBRUSH LoginPageEmpty::OnGetStaticColor(HDC hdc, HWND hControl)
{
	INT_PTR controlId = (INT_PTR)GetWindowLongPtr(hControl, GWLP_ID);
	switch(controlId)
	{
		case IDC_MESSAGE:
		case IDC_CHECK_STATUS:
			SetTextColor(hdc, rgbSecondaryText);
			SetBkColor(hdc, rgbBack);
			return hbrBack;
	}

	return LoginPage::OnGetStaticColor(hdc, hControl);
}

BOOL LoginPageEmpty::OnGetLoginData(LoginData **ppLoginData)
{
	return FALSE;
}

void LoginPageEmpty::OnUpdateStateChange(BOOL updateActive)
{
	EnableCheckButton(FALSE == updateActive);
}

void LoginPageEmpty::EnableCheckButton(BOOL fEnable)
{
	HWND hButton = GetDlgItem(hwnd, IDC_CHECKNOW);
	HWND hStatus = GetDlgItem(hwnd, IDC_CHECK_STATUS);

	if (FALSE != fEnable)
	{
		if (NULL != hStatus)
			ShowWindow(hStatus, SW_HIDE);
		
		if (NULL != hButton)
		{
			EnableWindow(hButton, TRUE);
			ShowWindow(hButton, SW_SHOWNA);
		}
		
	}
	else
	{
		if (NULL  != hButton)
		{
			if (NULL != hStatus)
				ShowWindow(hButton, SW_HIDE);
			EnableWindow(hButton, FALSE);
		}
		if (NULL != hStatus)
			ShowWindow(hStatus, SW_SHOWNA);
	}
}