SOL9 2.0 Class: RadioBox

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * RadioBox.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\RadioButton.h>
#include <sol\ClientDC.h>


namespace SOL {

class RadioBox :public RowColumn {
private:
    int          num;
    GroupBox*     frame;
      RadioButton** radiob;
    int        width;
    int        height;

public:
    RadioBox(): RowColumn() { }

public:
    RadioBox(View* parent, const char* name, Args& args)
    :RowColumn(parent)
    {
        num = (int) args.get(XmNitemCount);
        char** items = (char**)args.get(XmNitems);
        radiob = new RadioButton*[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);
            }
            radiob[i] = new RadioButton(parent, items[i], ar);
        }
    }

public:
    RadioBox::~RadioBox()
    {
        for(int i = 0; i<num; i++) {
            delete radiob[i];
        }
    }


public:
    virtual Boolean create(View* parent, const char* name, Args& args)
    {
        Boolean rc = True;

        View::setParent(parent);

        num = (int) args.get(XmNitemCount);
        char** items = (char**)args.get(XmNitems);
        radiob = new RadioButton*[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);
            }
            radiob[i] = new RadioButton(parent, items[i], ar);
        }

        return rc;
    }

public:
    void reshape(int x, int y, int width, int height)
    {
        View* parent = getParent();
        ClientDC cdc(parent);
        char*  label = "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++) {
            radiob[i]->reshape(x+ch, y+ch*(i+1), width-2*ch, ch);
        }
    }

public:
    int  getCheck()
    {
        int pos = -1;
        for (int i = 0; i < num; i++) {
            if(radiob[i] -> getCheck() == TRUE) {
                pos = i;
                break;
            }
        }
        return pos;
    }

public:
    void setCheck(int pos)
    {
        for(int i = 0; i < num; i++) {
            radiob[i] -> setCheck(FALSE);
        }
        if(pos >= 0 && pos < num) {
            radiob[pos] -> setCheck(TRUE);
        }
    }


/*    RadioBox(View* parent, const char* name, Args& args);
//    ~RadioBox();

//    virtual Boolean create(View* parent, const char* name, Args& args);

    void     reshape(int x, int y, int width, int height);
    int        getCheck();
    void    setCheck(int pos);
    */
};

}



Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.