Responding to background change in panels with MM



I'm using libpanelapplettmm-2.6 and libgtkmm-2.4.

I've been able to coerce the simple sample panel applet to respond to
the background change and set it's background pixmap properly when I
uwrap the pixmap and use the gtk+ calls.  I'm not having success doing
the same thing with the gtkmm calls.  Part of the sticking point is
that the Pixmap passed into the callback is const and the style calls
want a non-const Pixmap.

It seems odd that the sample applet didn't do this as it is present in
panel samples for the gnomw-panel library.

Ideas?



void MyApplet::on_back_change(Gnome::Panel::AppletBackgroundType type,
			      const Gdk::Color & color,
			      const Glib::RefPtr<const Gdk::Pixmap>& pixmap)
{
// *** show that we're responding to pixmap changes by setting label
// text for the applet.
  static int c;
  char sz[10];
  sprintf (sz, "%d", c++);
  label->set_text (sz);

// *** This just gets in the way.
//  Gtk::MessageDialog dialog("Changed background!");
//  dialog.run();

	/* reset style, a-ok here */
  set_style (Glib::wrap ((GtkStyle*)NULL));
  Glib::RefPtr<Gtk::RcStyle> rc_style = Gtk::RcStyle::create ();
  modify_style (rc_style);

  switch (type) {
  case PANEL_NO_BACKGROUND:
    break;
  case PANEL_COLOR_BACKGROUND:
    modify_bg (Gtk::STATE_NORMAL, color);  // fine here
    break;
  case PANEL_PIXMAP_BACKGROUND:
#if 1
    {
      Glib::RefPtr<Gtk::Style> style = get_style ();
      GdkPixmapObject* pm = (GdkPixmapObject*) Glib::unwrap (pixmap);
      style->set_bg_pixmap (Gtk::STATE_NORMAL, Glib::wrap (pm));
      set_style (style);
    }
#else
    {
      GtkStyle* style = gtk_style_copy (GTK_WIDGET (gobj ())->style);
      if (style->bg_pixmap[GTK_STATE_NORMAL])
	g_object_unref (style->bg_pixmap[GTK_STATE_NORMAL]);
      {
	GdkPixmap* p = (GdkPixmap*) Glib::unwrap (pixmap);
        style->bg_pixmap[GTK_STATE_NORMAL]
          = (GdkPixmap*) g_object_ref (p);
      }
      gtk_widget_set_style (GTK_WIDGET (gobj ()), style);
      g_object_unref (style);
    }
#endif
    break;
  }
}



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