Even better when i don't change m_RefGC because
this also changes the style of the other widgets (in this case the
button)
Could it be that Gdk::Window::create() creates a
refptr to a copy, and we are then painting on the wrong window?
anyway the corrected version:
void MyWidget::on_realize()
{
std::cout << "on_realize"<<std::endl;
//Call base
class:
Gtk::Widget::on_realize();
//TODO: Not sure whether this is
necessary:
set_flags(Gtk::REALIZED);
set_window(
get_parent_window() );
GtkWidget* cWidget =
(GtkWidget*)gobj();
cWidget->style =
gtk_style_attach(cWidget->style, get_window()->gobj());
if(!m_refGdkWindow)
{
//Create the GdkWindow:
GdkWindowAttr
attributes;
memset(&attributes, 0,
sizeof(attributes));
Gtk::Allocation allocation =
get_allocation();
//Set initial position and size
of the Gdk::Window:
attributes.x =
allocation.get_x();
attributes.y =
allocation.get_y();
attributes.width =
allocation.get_width();
attributes.height =
allocation.get_height();
attributes.window_type =
GDK_WINDOW_CHILD;
attributes.wclass =
GDK_INPUT_OUTPUT;
// m_refGdkWindow =
Gdk::Window::create(get_window() /* parent */, &attributes, GDK_WA_X |
GDK_WA_Y);
m_refGdkWindow = get_window();
//Allocate a GC for use in
on_expose_event():
m_refGC =
Gdk::GC::create(m_refGdkWindow);
}
}
----- Original Message -----
Sent: Tuesday, January 11, 2005 9:09
AM
Subject: custom widget example
I have made some progress with the custom widget
example by making some changes to the on_realize function, it now displays a
red background with a blue line.
void
MyWidget::on_realize()
{ std::cout <<
"on_realize"<<std::endl;
//Call base class:
Gtk::Widget::on_realize();
//TODO: Not sure whether this is
necessary:
set_flags(Gtk::REALIZED);
set_window(
get_parent_window() );
GtkWidget* cWidget =
(GtkWidget*)gobj();
cWidget->style =
gtk_style_attach(cWidget->style, get_window()->gobj());
if(!m_refGdkWindow)
{
//Create the GdkWindow:
GdkWindowAttr
attributes;
memset(&attributes, 0,
sizeof(attributes));
Gtk::Allocation allocation =
get_allocation();
//Set initial position and
size of the Gdk::Window:
attributes.x =
allocation.get_x();
attributes.y =
allocation.get_y();
attributes.width =
allocation.get_width();
attributes.height =
allocation.get_height();
attributes.window_type =
GDK_WINDOW_CHILD;
attributes.wclass =
GDK_INPUT_OUTPUT;
// m_refGdkWindow =
Gdk::Window::create(get_window() /* parent */, &attributes, GDK_WA_X |
GDK_WA_Y);
m_refGdkWindow = get_window();
//Allocate a GC for use in
on_expose_event():
// m_refGC =
Gdk::GC::create(m_refGdkWindow);
m_refGC =
this->get_style()->get_fg_gc(Gtk::STATE_NORMAL);
}
}
_______________________________________________
gtkmm-list mailing
list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list