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.
 
Regards,
Marco
 
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);
  }
}
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]