summaryrefslogtreecommitdiff
path: root/src/mir_core/src/Windows/CCtrlSpin.cpp
blob: 905fe50a88b97f6bcb07229562e1244ae883e742 (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
/*

Object UI extensions
Copyright (c) 2008  Victor Pavlychko, George Hazan
Copyright (C) 2012-25 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"

/////////////////////////////////////////////////////////////////////////////////////////
// CCtrlSpin class

CCtrlSpin::CCtrlSpin(CDlgBase *dlg, int ctrlId, int16_t wMax, int16_t wMin) :
	CCtrlData(dlg, ctrlId),
	m_wMin(wMin),
	m_wMax(wMax),
	m_wCurr(0)
{
	m_bNotifiable = true;
}

BOOL CCtrlSpin::OnNotify(int, NMHDR *pnmh)
{
	if (pnmh->code == UDN_DELTAPOS) {
		auto *pEvent = (NMUPDOWN *)pnmh;
		m_wCurr = pEvent->iPos + pEvent->iDelta;

		NotifyChange();
		return TRUE;
	}
	return FALSE;
}

bool CCtrlSpin::OnApply()
{
	m_wCurr = SendMsg(UDM_GETPOS, 0, 0);
	if (m_hwnd && m_dbLink)
		SaveInt(m_wCurr);

	HWND hwndBuddy = (HWND)SendMsg(UDM_GETBUDDY, 0, 0);
	if (hwndBuddy) {
		wchar_t buf[100];
		_itow(m_wCurr, buf, 10);
		::SendMessage(hwndBuddy, WM_SETTEXT, 0, LPARAM(buf));
	}

	return true;
}

void CCtrlSpin::OnReset()
{
	SendMsg(UDM_SETRANGE, 0, MAKELPARAM(m_wMax, m_wMin));

	if (m_hwnd && m_dbLink)
		SetPosition(LoadInt());
}

int16_t CCtrlSpin::GetPosition()
{
	return m_wCurr;
}

void CCtrlSpin::SetPosition(int16_t wPos)
{
	SendMsg(UDM_SETPOS, 0, m_wCurr = wPos);
}