storing buttons in vector -- need to define copy ctor?
- From: "Joe Van Dyk" <joevandyk gmail com>
- To: gtkmm-list gnome org
- Subject: storing buttons in vector -- need to define copy ctor?
- Date: Fri, 2 Jun 2006 12:58:12 -0700
Hi,
I was playing around with some code that was posted on the list
earlier. The original code had an array of four
DepressedToggleButtons. I changed that array to a vector, because
vectors are good, right?
However, it fails to compile -- something about the copy ctor.
Error:
g++ -o buttons main.cpp `pkg-config gtkmm-2.4 --cflags --libs`
main.cpp: In copy constructor
'Gtk::DepressedToggleButton::DepressedToggleButton(const
Gtk::DepressedToggleButton&)':
main.cpp:8: instantiated from 'void
__gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp =
Gtk::DepressedToggleButton]'
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_vector.h:606:
instantiated from 'void std::vector<_Tp, _Alloc>::push_back(const
_Tp&) [with _Tp = Gtk::DepressedToggleButton, _Alloc =
std::allocator<Gtk::DepressedToggleButton>]'
main.cpp:67: instantiated from here
/usr/include/glibmm-2.4/glibmm/objectbase.h:154: error:
'Glib::ObjectBase::ObjectBase(const Glib::ObjectBase&)' is private
main.cpp:8: error: within this context
/usr/include/gtkmm-2.4/gtkmm/togglebutton.h:70: error:
'Gtk::ToggleButton::ToggleButton(const Gtk::ToggleButton&)' is private
main.cpp:8: error: within this context
Source:
#include <iostream>
#include <gtkmm.h>
#include <vector>
namespace Gtk
{
class DepressedToggleButton : public Gtk::ToggleButton
{
public:
DepressedToggleButton() :
color(Gdk::Color("yellow"))
{ set_color(color); }
DepressedToggleButton(Gdk::Color c) :
color(c)
{ set_color(c); }
void set_color(Gdk::Color c)
{
Glib::RefPtr<Gtk::Style> style = Gtk::Style::create();
style->set_bg(Gtk::STATE_ACTIVE, c);
style->set_bg(Gtk::STATE_PRELIGHT, c);
set_style(style);
}
Gdk::Color get_color()
{ return color; }
protected:
virtual bool on_expose_event(GdkEventExpose* event);
private:
Gdk::Color color;
};
bool DepressedToggleButton::on_expose_event(GdkEventExpose* event)
{ return Gtk::Button::on_expose_event(event); }
}
class TestButton : public Gtk::Window
{
public:
TestButton();
protected:
void HandleButton(int i);
Gtk::VBox m_VBox;
Gtk::HButtonBox m_HButtonBox;
std::vector<Gtk::DepressedToggleButton> m_DepressedToggleButton;
private:
bool state;
};
TestButton::TestButton() :
state(false)
{
set_title("DepressedToggleButton");
add(m_VBox);
for (int i = 0; i < 4; ++i)
{
Gtk::DepressedToggleButton b;
m_DepressedToggleButton.push_back(b);
}
m_HButtonBox.set_border_width(5);
m_HButtonBox.set_layout(Gtk::BUTTONBOX_END);
m_HButtonBox.set_spacing(5);
m_DepressedToggleButton[0].set_label("First");
m_DepressedToggleButton[0].set_color(Gdk::Color("red"));
m_DepressedToggleButton[1].set_label("Second");
m_DepressedToggleButton[1].set_color(Gdk::Color("blue"));
m_DepressedToggleButton[2].set_label("Third");
m_DepressedToggleButton[2].set_color(Gdk::Color("green"));
m_DepressedToggleButton[3].set_label("Fourth"); // use default color
for (int i = 0; i < 4; i++)
{
m_DepressedToggleButton[i].signal_clicked().connect(
sigc::bind<int>(sigc::mem_fun(*this,
&TestButton::HandleButton),
i));
m_HButtonBox.add (m_DepressedToggleButton[i]);
}
m_VBox.pack_start(m_HButtonBox, Gtk::BUTTONBOX_END, 0);
set_resizable(false);
show_all_children();
}
int main(int argc, char *argv[])
{
Gtk::Main app(argc, argv);
TestButton test;
Gtk::Main::run(test);
return 0;
}
void TestButton::HandleButton(int i)
{
std::cout << "Button " << i << " clicked!\n";
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]