summaryrefslogtreecommitdiff
path: root/src/T2DLL/CToggleButtonDisabled.cpp
blob: 277fdd7823968c3bbd74d63d0ea729962437d892 (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
#include "StdAfx.h"
#include "CToggleButtonDisabled.h"
#include "T2BitImage.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CToggleButtonDisabled::CToggleButtonDisabled(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette)
	: T2DlgItem(towerDoc, imageObj, palette)
{
}

/*virtual*/ BOOL CToggleButtonDisabled::Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId) {
	CRect rect1 = rect;
	CRect rect2;

	if (GetObjectImage(rect2, windowName)) {
		rect1.right = rect1.left + rect2.Width();
		rect1.bottom = rect1.top + rect2.Height();
	} else {
		rect1.right = rect1.left + 20;
		rect1.bottom = rect1.top + 20;
	}

	return T2DlgItem::Create(windowName, style, rect1, parentWnd, nId);
}

/*virtual*/ void CToggleButtonDisabled::SetValue(int value) {
	T2DlgItem::SetValue(value);

	if (IsWindowEnabled()) {
		if (mValue == 0)
			SetPattern(0);
		else if (mValue == 1)
			SetPattern(100);
	}
}

void CToggleButtonDisabled::Enable() {
	EnableWindow(true);
	SetValue(mValue);
}

void CToggleButtonDisabled::Disable() {
	EnableWindow(false);
	SetPattern(200);
}

/*virtual*/ BOOL CToggleButtonDisabled::OnT2DlgItemEraseBkgnd(CDC* dc) {
	CRect theClientRect;
	GetClientRect(theClientRect);

	int savedDC = dc->SaveDC();

	dc->SelectPalette(mPalette, false);
	dc->RealizePalette();

	CPen pen;
	CBrush theBrush;

	CString text;
	GetWindowText(text);

	RECT theImageRect;
	T2BitImage *theImage = GetObjectImage(theImageRect, text, GetPattern());
	if (theImage)
		theImage->CopyImage(dc, theImageRect, theClientRect, 0, NULL);

	dc->RestoreDC(savedDC);

	return true;
}

/*virtual*/ void CToggleButtonDisabled::OnT2DlgItemLButtonDown(UINT nFlags, CPoint pt) {
	SetCapture();
	m74 = true;

	if (IsWindowEnabled()) {
		SetValue(!mValue);
		Notify(mValue ? 2 : 3, NULL);
	}
}

/*virtual*/ void CToggleButtonDisabled::OnT2DlgItemLButtonUp(UINT nFlags, CPoint pt) {
	ReleaseCapture();
	m74 = false;
}

/*virtual*/ void CToggleButtonDisabled::OnT2DlgItemMouseMove(UINT nFlags, CPoint pt) {
}