No Data Structures (2)

gtk3a

A little bit improved?

#include "radiobuttons.h"
#include <iostream>
void myfunc (int);

RadioButtons::RadioButtons() :
  m_Box_Top(Gtk::ORIENTATION_VERTICAL),
  m_Box1 (Gtk::ORIENTATION_HORIZONTAL, 10),
  m_Box10(Gtk::ORIENTATION_VERTICAL  , 10),
  m_Box11(Gtk::ORIENTATION_VERTICAL  , 10),
  m_Box12(Gtk::ORIENTATION_VERTICAL  , 10),
  m_Box2 (Gtk::ORIENTATION_VERTICAL  , 10),
  m_Button_Quit ("Quit")
{
  set_title("Spinor Lab");
  set_border_width(10);

  static char label[10][256] = { "CW", "CW-R", "LSB", "USB", "DSP FIL1", "DSP FIL2", "DSP FIL3", "DSP SHARP", "DSP SOFT" };

  for(int i=0;i<9;i++) {
    m_RadioButton[i].set_label(label[i]);
  }

  for(int i=0;i<=3;i++) {
    if(i==0) {m_group[0] = m_RadioButton[i].get_group();
    } else {
      m_RadioButton[i].set_group(m_group[0]);
    }
    m_Box10.pack_start(m_RadioButton[i], FALSE, FALSE, 0);
  }

  for(int i=4;i<=6;i++) {
    if(i==4) {m_group[1] = m_RadioButton[i].get_group();
    } else {
      m_RadioButton[i].set_group(m_group[1]);
    }
    m_Box11.pack_start(m_RadioButton[i], FALSE, FALSE, 0);
  }

  for(int i=7;i<=8;i++) {
    if(i==7) {m_group[2] = m_RadioButton[i].get_group();
    } else {
      m_RadioButton[i].set_group(m_group[2]);
    }
    m_Box12.pack_start(m_RadioButton[i], FALSE, FALSE, 0);
  }

  add(m_Box_Top);

  m_Box_Top.pack_start(m_Box1);
  m_Box_Top.pack_start(m_HSeparator);
  m_Box_Top.pack_start(m_Box2);

  m_Box1.set_border_width(10);
  m_Box2.set_border_width(10);

  m_Box1.pack_start(m_Box10);
  m_Box1.pack_start(m_VSeparator[0]);
  m_Box1.pack_start(m_Box11);
  m_Box1.pack_start(m_VSeparator[1]);
  m_Box1.pack_start(m_Box12);
  
  m_RadioButton[0].set_active();

  m_Box2.pack_start(m_Button_Quit);

  m_Button_Quit.set_can_default();
  m_Button_Quit.grab_default();

  m_Button_Quit.signal_clicked().connect (sigc::            mem_fun(*this, &RadioButtons::on_button_clicked )    );
  for(int i=0;i<9;i++) {
    m_RadioButton[i].signal_clicked().connect(sigc::bind<gint> (mem_fun(*this, &RadioButtons::on_button_clicked9), i));
  }

  show_all_children();
}
void RadioButtons::on_button_clicked9(gint data)
{

  if(m_RadioButton[data].get_active()) {
    std::cout << "button " << data << " is active " << std::endl;
	myfunc(data);
  }
}
#ifndef GTKMM_EXAMPLE_RADIOBUTTONS_H
#define GTKMM_EXAMPLE_RADIOBUTTONS_H

#include <gtkmm/box.h>
#include <gtkmm/window.h>
#include <gtkmm/radiobutton.h>
#include <gtkmm/separator.h>

class RadioButtons : public Gtk::Window
{
public:
  RadioButtons();
  virtual ~RadioButtons();
protected:
  void on_button_clicked ();
  void on_button_clicked9(gint data);
  Gtk::Box         m_Box_Top, m_Box1, m_Box10, m_Box11, m_Box12, m_Box2;
  Gtk::RadioButton::Group m_group[ 3];
  Gtk::RadioButton m_RadioButton [10];
  Gtk::HSeparator  m_HSeparator;
  Gtk::VSeparator  m_VSeparator  [ 2];
  Gtk::Button      m_Button_Quit;
};

#endif //GTKMM_EXAMPLE_RADIOBUTTONS_H

Leave a Reply

Your email address will not be published. Required fields are marked *