Re: where is alloc_color called
- From: Chris Vine <chris cvine freeserve co uk>
- To: Mitchell Laks <mlaks verizon net>
- Cc: gtkmm-list gnome org
- Subject: Re: where is alloc_color called
- Date: Thu, 26 Apr 2007 20:50:46 +0100
On Thu, 2007-04-26 at 03:18 -0400, Mitchell Laks wrote:
> Hi,
>
> I am struggling to understand the (deprecated) but still useful parts of Gdk.
>
> Thus I read in the books (Havoc and Martin books) and tutorials about Gtk+ that I need to
> 0) get a graphics context
> 1) create a color object
> 2) assign it a color by filling in rgb values or using common name as per rgb.txt
> 3) then allocate it on the X server (ie fill in the internal X representation of the color)
> this is done using the visual from the X server which identifies the internal representation
> of the color done with alloc_color function
> 4) then when i am done using it i will unref the color, just as i might unref the graphics context
>
> Then I see in gtkmm code, as I expect to, RefPtrs for Gdk::GC graphics contexts, because gtkmm
> will handle the unref of the graphics context itself.
>
> however Gdk::Colors are created without using a RefPtr, and for instance in the
> example file demos/gtk-demo/example_drawingarea.cc
> (which works :) I see no use at all of the alloc_color member function which exists in gtkmm,
> so How does the gulong pixel element of the Gtk+ _GdkColor struct get assigned a value?
> moreover I see no way that the server side resource "Gdk::Color" will be unrefed by gtkmm...
Gdk::Color objects are not "created" in the sense of requiring a special
create function returning a pointer (or in the case of gtkmm, a
Glib::RefPtr<>). They are just a wrapper for the GdkColor struct, and
you can create them in local scope, as the example does, and they can be
passed to any of the Gdk/Gtk functions to which they are an argument
without their life having to be extended beyond that of the function
call in question.
You do not always have to allocate a colour with
Gdk::Colormap::alloc_color(). Some (in fact, most of the Gtk functions
which take a Color object as an argument) do not require it, nor
according to the documentation does Gdk::GC::set_rgb_fg_color() (which
is the function which the example calls) or its Gtk equivalent
Gtk::Widget::modify_fg(). These functions will allocate it themselves.
Gdk::Colormap::alloc_color() is required for those functions which do
not do that, such as Gdk drawing functions.
I may have misunderstood your last question, but the Gdk::Color object
in the example will be destroyed when it goes out of scope - objects of
local scope are on the stack. That is how C++ works (and also C for
that matter, although C will not call a destructor for you). So far as
concerns server side resources, you rarely need to call
Gdk::Color::free_color(), unless you allocate the colour as writeable.
Chris
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]