aboutsummaryrefslogtreecommitdiff
path: root/lib/gui/echeckbox.cpp
blob: c41721ceb586098b4682dc5e6d3c2d7ed56e7908 (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
#include <lib/gui/echeckbox.h>

#include <lib/gdi/font.h>
#include <lib/base/init.h>
#include <lib/base/init_num.h>
#include <lib/gui/eskin.h>

eCheckbox::eCheckbox(eWidget *parent, int checked, int takefocus, bool swapTxtPixmap, const char *deco)
	:eButton(parent, 0, takefocus, deco), swapTxtPixmap(swapTxtPixmap)
{
	align=eTextPara::dirLeft;
	ischecked = -1;
	setCheck(checked);
	CONNECT(selected, eCheckbox::sel);
}

eCheckbox::~eCheckbox()
{
}

void eCheckbox::sel()
{
	setCheck(ischecked?0:1);
	/*emit*/ checked(ischecked);
}

void eCheckbox::gotFocus()
{
#ifndef DISABLE_LCD
	if (parent && parent->LCDElement)
	{
		LCDTmp = new eLabel(parent->LCDElement);
		LCDTmp->hide();
		eSize s = parent->LCDElement->getSize();
		LCDTmp->move(ePoint(0,0));
		LCDTmp->resize(eSize(s.width(), s.height()));
		((eLabel*)LCDTmp)->setFlags(RS_WRAP);
		ePtr<gPixmap> pm;
		eSkin::getActive()->queryImage(pm, ischecked?"eCheckboxLCD.checked":"eCheckboxLCD.unchecked");
		LCDTmp->setPixmap(pm);
		((eLabel*)LCDTmp)->pixmap_position=ePoint(0, (size.height()-15)/2);
		((eLabel*)LCDTmp)->text_position=ePoint(21, 0);
		LCDTmp->setText(text);
		LCDTmp->show();
	}
#endif
	setForegroundColor(focusF, false);
	setBackgroundColor(focusB);
//	invalidate();
}

void eCheckbox::lostFocus()
{
#ifndef DISABLE_LCD
	if (LCDTmp)
	{
		delete LCDTmp;
		LCDTmp = 0;
	}
#endif
	eButton::lostFocus();
}


void eCheckbox::setCheck(int c)
{
	if (ischecked != -1 && ischecked == c)
		return;

	ischecked=c;

	ePtr<gPixmap> pixmap;
	eSkin::getActive()->queryImage(pixmap, ischecked?"eCheckbox.checked":"eCheckbox.unchecked");
	setPixmap(pixmap);
#ifndef DISABLE_LCD
	eSkin::getActive()->queryImage(pixmap, ischecked?"eCheckboxLCD.checked":"eCheckboxLCD.unchecked");
	if (LCDTmp)
		LCDTmp->setPixmap(pixmap);
#endif
}

int eCheckbox::setProperty(const eString &prop, const eString &value)
{
	if (prop=="swaptxtpixmap")	
	{
		swapTxtPixmap = (value != "off");
		event( eWidgetEvent::changedSize );
	}
	else
		return eButton::setProperty(prop, value);
	return 0;
}

int eCheckbox::eventHandler(const eWidgetEvent &event)
{
	switch (event.type)
	{
	case eWidgetEvent::changedSize:
		if (swapTxtPixmap)
		{
			text_position=ePoint(0,0);
			eLabel::invalidate();
			validate();
			pixmap_position=ePoint( para->getBoundBox().right()+5, (size.height()-pixmap->y) / 2 );
		}
		else
		{
			pixmap_position=ePoint(0, (size.height()-pixmap->y)/2);
			text_position=ePoint((int)(pixmap->x*1.25), 0);
		}
		//return eButton::eventHandler(event); // changed Size must seen by eLabel...
		break;

	default:
		return eButton::eventHandler(event);
	}
	return 1;
}

static eWidget *create_eCheckbox(eWidget *parent)
{
	return new eCheckbox(parent);
}

class eCheckboxSkinInit
{
public:
	eCheckboxSkinInit()
	{
		eSkin::addWidgetCreator("eCheckbox", create_eCheckbox);
	}
	~eCheckboxSkinInit()
	{
		eSkin::removeWidgetCreator("eCheckbox", create_eCheckbox);
	}
};

eAutoInitP0<eCheckboxSkinInit> init_eCheckboxSkinInit(eAutoInitNumbers::guiobject, "eCheckbox");