RE: settting the background and foreground



On Wed, 2011-01-12 at 10:15 -0600, Charles Seedle wrote:
> I tried putting the commands in the callback signal_realize
> 
>  
> 
> signal_realize().connect (sigc::mem_fun (*this,
> &ExampleWindow::onWindowRealize));
> 
>  
> 
>  
> 
> void ExampleWindow::onWindowRealize()
> 
> {
> 
>   Glib::RefPtr<Gdk::Window> win = get_window();
> 
>   Glib::RefPtr<Gdk::GC> some_gc = Gdk::GC::create(win);
> 
>   Glib::RefPtr<Gdk::Colormap> some_colormap = get_default_colormap();
> 
>   my_gray.set_red(0xc900);
> 
>   my_gray.set_green(0xca00);
> 
>   my_gray.set_blue(0xc800);
> 
>   some_colormap->alloc_color(my_gray);
> 
>  
> 
>   my_blue.set_red(0x0000);
> 
>   my_blue.set_green(0x7200);
> 
>   my_blue.set_blue(0xc800);
> 
>   some_colormap->alloc_color(my_blue);
> 
>  
> 
>   some_gc->set_foreground(my_gray);
> 
>   some_gc->set_background(my_blue);
> 
> }
> 
>  
> 
> The program console showed:
> 
>  
> 
> (Hello:2839): Gdk-CRITICAL **: gdk_gc_new: assertion `drawable !=
> NULL' failed
> 
>  
> 
> (Hello:2839): GLib-GObject-CRITICAL **: g_object_unref: assertion
> `G_IS_OBJECT (object)' failed
> 
>  
> 
> But the background and foreground were unchanged.
> 
>  
> 
>  
> 
> I also tried using: 
> 
> Glib::RefPtr<Gdk::Window> win = get_window();
> 
> gtk_widget_modify_bg( GtkWidget(win), (GtkStateType)Gtk::STATE_NORMAL,
> (GdkColor*)&my_blue );
> 
> gtk_widget_modify_fg( GtkWidget(win), (GtkStateType)Gtk::STATE_NORMAL,
> (GdkColor*)&my_gray );
> 
> It won’t compile because it does not like the reference pointer to
> widget conversion.
> 
> Any other ideas ??

Try using the Gtk::Widget::modify_* methods instead of the gtk+
functions (or use win->gobj() and a_color.gobj() with the functions).
If you're experiencing a bug, a small complete example exhibiting the
bug would be useful.  In that case, just file a bug so that the issue
can be looked at.

> 
>  
> 
> Randy Seedle
> 
>  
> 
> PS: This solution needs to work with “Gtkmm”.
> 
>  
> 
>  
> 
> From: José Alburquerque [mailto:jaalburquerque cox net] 
> Sent: Tuesday, January 11, 2011 12:51 PM
> To: charles seedle rigaku com
> Cc: <gtkmm-list gnome org>
> Subject: Re: settting the background and foreground
> 
> 
>  
> 
> El Jan 10, 2011, a las 4:32 PM, "Charles Seedle"
> <charles seedle rigaku com> escribió:
> 
> 
>  
> 
> 
>         I am tring to set the background and foreground of my main
>         window. Is there a good example of how to do this out there ?
>         
>         I keep getting the messeges:
>         
>          
>         
>          
>         
>         (Hello:22855): Gdk-CRITICAL **: gdk_gc_new: assertion
>         `drawable != NULL' failed
>         
>          
>         
>         (Hello:22855): Gdk-CRITICAL **: gdk_gc_set_foreground:
>         assertion `GDK_IS_GC (gc)' failed
>         
>          
>         
>         (Hello:22855): Gdk-CRITICAL **: gdk_gc_set_background:
>         assertion `GDK_IS_GC (gc)' failed
>         
>          
>         
>         (Hello:22855): GLib-GObject-CRITICAL **: g_object_unref:
>         assertion `G_IS_OBJECT (object)' failed
>         
>          
>         
>          
>         
>         From this code:
>         
>           Glib::RefPtr<Gdk::Window> win = get_window();
>         
>          
>         
>           Glib::RefPtr<Gdk::GC> some_gc = Gdk::GC::create(win);
>         
>           Glib::RefPtr<Gdk::Colormap> some_colormap =
>         get_default_colormap();
>         
>           set_decorated(false);
>         
>          
>         
>           my_gray.set_red(0xc900);
>         
>           my_gray.set_green(0xca00);
>         
>           my_gray.set_blue(0xc800);
>         
>          
>         
>           some_colormap->alloc_color(my_gray);
>         
>           some_gc->set_foreground(my_gray);
>         
>          
>         
>           my_blue.set_red(0x0000);
>         
>           my_blue.set_green(0x7200);
>         
>           my_blue.set_blue(0xc800);
>         
>          
>         
>           some_colormap->alloc_color(my_blue);
>         
>           some_gc->set_background(my_blue);
>         
>         
>  
> 
> 
> 
> When getting the window of a widget, you have to be sure it is
> realized first.  See Gtk::Widget::signal_realize().  Or maybe use one
> of the Gtk::Widget::modify_* methods.
> 
> 
> 
>  
> 
>  
> 
>  
> 
>  
> 
> Randy
> 
> 
>         _______________________________________________
>         gtkmm-list mailing list
>         gtkmm-list gnome org
>         http://mail.gnome.org/mailman/listinfo/gtkmm-list
>         
>         

-- 
José



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