summaryrefslogtreecommitdiff
path: root/src/mir_core/src/Linux/CDlgBase.cpp
blob: 8dbb1affcd1eda511629f73f0c2aae22373e0a53 (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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*

Object UI extensions
Copyright (c) 2008  Victor Pavlychko, George Hazan
Copyright (C) 2012-24 Miranda NG team

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"

static mir_cs csDialogs;

static int CompareDialogs(const CDlgBase *p1, const CDlgBase *p2)
{
	return (INT_PTR)p1->GetHwnd() - (INT_PTR)p2->GetHwnd();
}
static LIST<CDlgBase> arDialogs(10, CompareDialogs);

#pragma comment(lib, "uxtheme")

/////////////////////////////////////////////////////////////////////////////////////////
// CDlgBase

static int CompareControlId(const CCtrlBase *c1, const CCtrlBase *c2)
{
	return c1->GetCtrlId() - c2->GetCtrlId();
}

static int CompareTimerId(const CTimer *t1, const CTimer *t2)
{
	return t1->GetEventId() - t2->GetEventId();
}

CDlgBase::CDlgBase(CMPluginBase &pPlug, int idDialog)
	: m_controls(1, CompareControlId),
	m_timers(1, CompareTimerId),
	m_pPlugin(pPlug)
{
	m_idDialog = idDialog;
	m_autoClose = CLOSE_ON_OK | CLOSE_ON_CANCEL;
}

CDlgBase::~CDlgBase()
{
	m_bInitialized = false; // prevent double call of destructor 
	// if (m_hwnd)
	// 	DestroyWindow(m_hwnd);
}

/////////////////////////////////////////////////////////////////////////////////////////
// events

bool CDlgBase::OnInitDialog()
{
	return true;
}

bool CDlgBase::OnClose()
{
	return true;
}

bool CDlgBase::OnApply()
{
	return true;
}

void CDlgBase::OnChange()
{}

void CDlgBase::OnDestroy()
{}

void CDlgBase::OnReset()
{}

void CDlgBase::OnTimer(CTimer*)
{}

/////////////////////////////////////////////////////////////////////////////////////////
// methods

void CDlgBase::Close()
{
	// ::SendMessage(m_hwnd, WM_CLOSE, 0, 0);
}

void CDlgBase::Create()
{
	// CreateDialogParam(GetInst(), MAKEINTRESOURCE(m_idDialog), m_hwndParent, GlobalDlgProc, (LPARAM)this);
}

int CDlgBase::DoModal()
{
	m_isModal = true;
	// return DialogBoxParam(GetInst(), MAKEINTRESOURCE(m_idDialog), m_hwndParent, GlobalDlgProc, (LPARAM)this);
	return 0; //!!!!!!!!
}

void CDlgBase::EndModal(INT_PTR nResult)
{
	// ::EndDialog(m_hwnd, nResult);
}

HINSTANCE CDlgBase::GetInst() const
{
	return m_pPlugin.getInst();
}

void CDlgBase::NotifyChange(void)
{
	if (!m_bInitialized)
		return;

	OnChange();

	// if (m_hwndParent)
	// 	SendMessage(m_hwndParent, PSM_CHANGED, (WPARAM)m_hwnd, 0);
}

void CDlgBase::Resize()
{
	// SendMessage(m_hwnd, WM_SIZE, 0, 0);
}

void CDlgBase::SetCaption(const wchar_t *ptszCaption)
{
	// if (m_hwnd && ptszCaption)
	//	SetText(ptszCaption);
}

void CDlgBase::SetDraw(bool bEnable)
{
	// ::SendMessage(m_hwnd, WM_SETREDRAW, bEnable, 0);
}

void CDlgBase::Show(int nCmdShow)
{
	if (m_hwnd == nullptr)
		Create();
	// ShowWindow(m_hwnd, nCmdShow);
}

/////////////////////////////////////////////////////////////////////////////////////////

void CDlgBase::CreateLink(CCtrlData& ctrl, const char *szSetting, uint8_t type, uint32_t iValue)
{
	ctrl.CreateDbLink(m_pPlugin.getModule(), szSetting, type, iValue);
}

void CDlgBase::CreateLink(CCtrlData& ctrl, const char *szSetting, wchar_t *szValue)
{
	ctrl.CreateDbLink(m_pPlugin.getModule(), szSetting, szValue);
}

/////////////////////////////////////////////////////////////////////////////////////////
// virtual methods

int CDlgBase::Resizer(UTILRESIZECONTROL*)
{
	return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}

BOOL CALLBACK CDlgBase::GlobalFieldEnum(MWindow hwnd, LPARAM lParam)
{
	return TRUE;
}

INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
	return FALSE;
}

int CDlgBase::GlobalDlgResizer(MWindow hwnd, LPARAM, UTILRESIZECONTROL *urc)
{
	CDlgBase *wnd = CDlgBase::Find(hwnd);
	return (wnd == nullptr) ? 0 : wnd->Resizer(urc);
}

void CDlgBase::ThemeDialogBackground(BOOL tabbed)
{
}

void CDlgBase::AddControl(CCtrlBase *ctrl)
{
	m_controls.insert(ctrl);
}

void CDlgBase::RemoveControl(CCtrlBase *ctrl)
{
	m_controls.remove(ctrl);
}

void CDlgBase::NotifyControls(void (CCtrlBase::*fn)())
{
	for (auto &it : m_controls)
		(it->*fn)();
}

bool CDlgBase::VerifyControls(bool (CCtrlBase::*fn)())
{
	for (auto &it : m_controls)
		if (!(it->*fn)())
			return false;

	return true;
}

CCtrlBase* CDlgBase::FindControl(int idCtrl)
{
	CCtrlBase search(nullptr, idCtrl);
	return m_controls.find(&search);
}

CCtrlBase* CDlgBase::FindControl(MWindow hwnd)
{
	for (auto &it : m_controls)
		if (it->GetHwnd() == hwnd)
			return it;

	return nullptr;
}

void CDlgBase::AddTimer(CTimer *timer)
{
	m_timers.insert(timer);
}

void CDlgBase::RemoveTimer(UINT_PTR idEvent)
{
	CTimer search(nullptr, idEvent);
	m_timers.remove(&search);
}

CTimer* CDlgBase::FindTimer(int idEvent)
{
	CTimer search(nullptr, idEvent);
	return m_timers.find(&search);
}

CDlgBase* CDlgBase::Find(MWindow hwnd)
{
	void *bullshit[2]; // vfptr + hwnd
	bullshit[1] = hwnd;
	return arDialogs.find((CDlgBase*)&bullshit);
}