summaryrefslogtreecommitdiff
path: root/plugins/HistoryStats/src/optionsctrlimpl_check.cpp
blob: d6c2b99c566660ad3679c542276951a7afd0e640 (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
#include "_globals.h"
#include "optionsctrlimpl.h"

/*
 * OptionsCtrlImpl::Check
 */

int OptionsCtrlImpl::Check::getStateImage()
{
	return m_bEnabled ? (m_bChecked ? siCheckC : siCheckU) : (m_bChecked ? siCheckCG : siCheckUG);
}

bool OptionsCtrlImpl::Check::getChildEnable()
{
	return
		!m_bDisableChildsOnUncheck && m_bDisableChilds && m_bEnabled ||
		m_bDisableChildsOnUncheck && m_bChecked && (!m_bDisableChilds || m_bEnabled);
}

void OptionsCtrlImpl::Check::updateItem()
{
	m_pCtrl->setStateImage(m_hItem, m_bEnabled ? (m_bChecked ? siCheckC : siCheckU) : (m_bChecked ? siCheckCG : siCheckUG));

	if (m_bDisableChilds || m_bDisableChildsOnUncheck)
	{
		enableChilds(getChildEnable());
	}
}

OptionsCtrlImpl::Check::Check(OptionsCtrlImpl* pCtrl, Item* pParent, const mu_text* szLabel, DWORD dwFlags, DWORD dwData)
	: Item(pCtrl, itCheck, szLabel, dwFlags, dwData)
{
	m_bChecked = bool_(dwFlags & OCF_CHECKED);
	m_bDisableChildsOnUncheck = bool_(dwFlags & OCF_DISABLECHILDSONUNCHECK);

	pCtrl->insertItem(pParent, this, szLabel, dwFlags, getStateImage());

	if (pParent)
	{
		pParent->childAdded(this);
	}
}

void OptionsCtrlImpl::Check::onToggle()
{
	if (m_bEnabled)
	{
		setChecked(!m_bChecked);
		m_pCtrl->setModified(this);
	}
}

void OptionsCtrlImpl::Check::childAdded(Item* pChild)
{
	if (m_bDisableChilds || m_bDisableChildsOnUncheck)
	{
		pChild->setEnabled(getChildEnable());
	}
}