Re: gtk questions - please help




> Sorry to ask you directly, but I have asked these questions three
> times on the list, and noone seems to want to answer them (and I
> don't know why).

The problem is you are asking hard questions.

> I am developing a GTK irc client and the UI is trailing behind due
> to these problems - in return, I don't mind contributing this to
> GNOME when it is in a usable state.
> 
> So, here goes:
> 
> 1. I'd like to use coloured text in a text widget - is this
> implemented, as I can only seem to get a single colour (other than
> black/white) - this relates to the question below.

Yes, it is implemented. Once you have a color allocated, you can
just pass it in as the appropriate argument to gtk_text_insert.
(Look at the gtktext.h header file)

> 2. How do you you map 0-255 RGB values to GtkColor values (for use in
> a text widget)

Currently, this is done using gdk_color_alloc. 

  GdkColor c;
  GdkColormap *cmap;

  cmap = gdk_colormap_get_system();
  c.red = 0xffff;
  c.green = 0xffff;
  c.blue = 0;
  if (!gdk_color_alloc (cmap, &c))
    g_error ("Couldn't allocate a yellow color");

In the near future, however, color allocation should be done
through GdkColorContexts instead. However, the interface
to that needs a bit of fixing, so I don't want to demonstrate
that right now.

Sometimes you can also get away with using the predefined
colors in a widgets style, if all you need are black, white,
gray, and blue.

> 3. How/Can I change the bg colours of the list and entry widgets?

This is a bit trickier than it seems. The trouble is that 
they are hard coded to use widget->style->white_gc. 

This is wrong. There is now (it may have been added recently?)
an additional field in the style base_gc which should be
used for that background.

It may be possible to get things working now by changing the 
widget->style->white_gc - I haven't tried it though. Assuming
that you want the GC to be standard in all other ways 
(i.e., not influenced by the rc file), the code would look
something like (untested):

  new_style = gtk_style_new();
  new_style->white = my_color;
  new_style->white_gc = gdk_gc_new();
  gdk_gc_set_foreground (new_style->white_gc, my_color);;
  
  gtk_widget_set_style (widget, new_style);

Hopefully, this will be fixed soon.

Regards,
                                        Owen



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