/*
* CheckBox.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.18
#pragma once
#include <sol\RowColumn.h>
#include <sol\GroupBox.h>
#include <sol\ToggleButton.h>
#include <sol\ClientDC.h>
namespace SOL {
class CheckBox :public RowColumn {
private:
int num;
GroupBox* frame;
ToggleButton** toggleb;
int width;
int height;
public:
CheckBox(): RowColumn() { }
public:
CheckBox(View* parent, const TCHAR* name, Args& args)
:RowColumn(parent)
{
num = (int) args.get(XmNitemCount);
TCHAR** items = (TCHAR**)args.get(XmNitems);
toggleb = new ToggleButton*[num];
Args ar;
frame = new GroupBox(parent, name, ar);
for(int i = 0; i<num; i++) {
ar.reset();
if(i == 0) {
ar.set(XmNstyle, (ulong)WS_GROUP);
}
toggleb[i] = new ToggleButton(parent, items[i], ar);
}
}
public:
~CheckBox()
{
delete frame;
for(int i = 0; i<num; i++) {
delete toggleb[i];
}
}
public:
virtual Boolean create(View* parent, const TCHAR* name, Args& args)
{
Boolean rc = True;
View::setParent(parent);
num = (int) args.get(XmNitemCount);
TCHAR** items = (TCHAR**)args.get(XmNitems);
toggleb = new ToggleButton*[num];
Args ar;
frame = new GroupBox(parent, name, ar);
for(int i = 0; i<num; i++) {
ar.reset();
if(i == 0) {
ar.set(XmNstyle, (ulong)WS_GROUP);
}
toggleb[i] = new ToggleButton(parent, items[i], ar);
}
return rc;
}
public:
void CheckBox::reshape(int x, int y, int width, int height)
{
View* parent = getParent();
ClientDC cdc(parent);
TCHAR* label = _T("A");
SIZE size;
cdc.getTextExtent(label, strlen(label), &size);
int ch = size.cy*3/2;
frame -> reshape(x, y, width, ch*(num+2));
for(int i = 0; i<num; i++) {
toggleb[i]->reshape(x+ch, y+ch*(i+1), width-2*ch, ch);
}
}
public:
int CheckBox::getCheck(int pos)
{
int rc = FALSE;
if(pos >= 0 && pos < num) {
rc = toggleb[pos] ->getCheck();
}
return rc;
}
public:
void CheckBox::setCheck(int pos)
{
if(pos >= 0 && pos < num) {
toggleb[pos] -> setCheck(TRUE);
}
}
};
}
|