summaryrefslogtreecommitdiff
path: root/plugins/DbChecker/src/wizard.cpp
blob: c19fab31d6d7167a391cc536c787cf4aff0a687d (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
208
209
210
211
212
213
214
215
216
217
218
219
/*
Miranda Database Tool
Copyright 2000-2011 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.

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"

#define WZM_GETOPTS (WM_USER+1)
#define WZM_GOTOPAGE (WM_USER+2)

HFONT hBoldFont = nullptr;

static BOOL CALLBACK MyControlsEnumChildren(HWND hwnd, LPARAM)
{
	uint32_t style = GetWindowLongPtr(hwnd, GWL_STYLE);
	uint32_t exstyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
	char szClass[64];
	int makeBold = 0;

	GetClassNameA(hwnd, szClass, sizeof(szClass));
	if (!mir_strcmp(szClass, "Static")) {
		if (exstyle & WS_EX_CLIENTEDGE) {
			switch (style & SS_TYPEMASK) {
			case SS_LEFT: case SS_CENTER: case SS_RIGHT:
				makeBold = 1;
			}
		}
	}
	else if (!mir_strcmp(szClass, "Button")) {
		if (exstyle & WS_EX_CLIENTEDGE)
			makeBold = 1;
	}
	if (makeBold) {
		if (hBoldFont == nullptr) {
			LOGFONT lf;
			hBoldFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
			GetObject(hBoldFont, sizeof(lf), &lf);
			lf.lfWeight = FW_BOLD;
			hBoldFont = CreateFontIndirect(&lf);
		}
		SendMessage(hwnd, WM_SETFONT, (WPARAM)hBoldFont, 0);
		SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle&~WS_EX_CLIENTEDGE);
		SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
	}
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////////////////
// Basic wizard dialog class

CWizardPageDlg::CWizardPageDlg(int iDlgId) :
	CSuper(g_plugin, iDlgId),
	btnOk(this, IDOK),
	btnCancel(this, IDCANCEL)
{
	m_autoClose = 0; // disable built-in IDOK & IDCANCEL handlers;
	m_forceResizable = true;

	btnOk.OnClick = Callback(this, &CWizardPageDlg::onClick_Ok);
	btnCancel.OnClick = Callback(this, &CWizardPageDlg::onClick_Cancel);
}

void CWizardPageDlg::OnCancel()
{
	PostMessage(m_hwndParent, WM_CLOSE, 0, 0);
}

bool CWizardPageDlg::OnInitDialog()
{
	EnumChildWindows(m_hwnd, MyControlsEnumChildren, 0);
	return true;
}

void CWizardPageDlg::changePage(CWizardPageDlg *pNewPage)
{
	PostMessage(m_hwndParent, WZM_GOTOPAGE, 0, (LPARAM)pNewPage);
}

DbToolOptions* CWizardPageDlg::getOpts() const
{
	return (DbToolOptions *)SendMessage(m_hwndParent, WZM_GETOPTS, 0, 0);
}

/////////////////////////////////////////////////////////////////////////////////////////
// Wizard dialog class

CWizardDlg::CWizardDlg(DbToolOptions *opts) :
	CDlgBase(g_plugin, IDD_WIZARD),
	m_opts(opts),
	btnCancel(this, IDCANCEL),
	timerStart(this, 1)
{
	m_autoClose = CLOSE_ON_OK;
	SetMinSize(450, 300);

	btnCancel.OnClick = Callback(this, &CWizardDlg::onClick_Cancel);

	timerStart.OnEvent = Callback(this, &CWizardDlg::onTimer);
}

bool CWizardDlg::OnInitDialog()
{
	Utils_RestoreWindowPosition(m_hwnd, 0, MODULENAME, "Wizard_");
	Window_SetIcon_IcoLib(m_hwnd, g_plugin.getIconHandle(IDI_DBTOOL));
	timerStart.Start(100);
	return true;
}

bool CWizardDlg::OnApply() 
{
	SendMessage(hwndPage, WZN_PAGECHANGING, 0, 0);
	SendMessage(hwndPage, WM_COMMAND, IDOK, 0);
	return false;
}

void CWizardDlg::OnDestroy() 
{
	Utils_SaveWindowPosition(m_hwnd, 0, MODULENAME, "Wizard_");

	if (m_opts->dbChecker) {
		m_opts->dbChecker->Destroy();
		m_opts->dbChecker = nullptr;
	}
	delete m_opts;

	if (hwndPage)
		DestroyWindow(hwndPage);

	if (hBoldFont != nullptr) {
		DeleteObject(hBoldFont);
		hBoldFont = nullptr;
	}
}

INT_PTR CWizardDlg::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WZM_GETOPTS:
		SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, (LPARAM)m_opts);
		return true;

	case WZM_GOTOPAGE:
		ChangePage((CWizardPageDlg *)lParam);
		return FALSE;
	}

	INT_PTR res = CDlgBase::DlgProc(msg, wParam, lParam);
	if (msg == WM_SIZE && hwndPage) {
		SetWindowPos(hwndPage, 0, 0, 0, m_splitterX, m_splitterY, SWP_NOZORDER | SWP_NOACTIVATE);
		SendMessage(hwndPage, WM_SIZE, wParam, lParam);
		InvalidateRect(hwndPage, 0, 0);
	}

	return res;
}

int CWizardDlg::Resizer(UTILRESIZECONTROL *urc)
{
	switch (urc->wId) {
	case IDC_SPLITTER:
		m_splitterX = urc->dlgNewSize.cx;
		m_splitterY = urc->dlgNewSize.cy - (urc->dlgOriginalSize.cy - urc->rcItem.top);
		return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM;

	case IDOK:
	case IDCANCEL:
		return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
	}

	return RD_ANCHORX_LEFT | RD_ANCHORY_BOTTOM;
}

void CWizardDlg::onClick_Cancel(CCtrlButton *)
{
	SendMessage(hwndPage, WZN_CANCELCLICKED, 0, 0);
	EndModal(0);
}

void CWizardDlg::onTimer(CTimer *pTimer)
{
	pTimer->Stop();

	ChangePage(new COptionsPageDlg());
}

LRESULT CWizardDlg::ChangePage(CWizardPageDlg *pPage)
{
	if (hwndPage != nullptr)
		DestroyWindow(hwndPage);

	EnableWindow(GetDlgItem(m_hwnd, IDOK), TRUE);
	EnableWindow(GetDlgItem(m_hwnd, IDCANCEL), TRUE);
	SetDlgItemText(m_hwnd, IDCANCEL, TranslateT("Cancel"));
	{
		pPage->SetParent(m_hwnd);
		pPage->Show();
		hwndPage = pPage->GetHwnd();
	}
	SetWindowPos(hwndPage, nullptr, 0, 0, m_splitterX, m_splitterY, SWP_NOZORDER);

	ShowWindow(hwndPage, SW_SHOW);
	return 0;
}