Re: Default settings for GtkTextAttributes



Owen:
 
> The gtk_text_iter_get_attributes() function was intended for
> retrieving the attributes for display - after all a user has no way of
> knowing whether these attributes come from tags set on the buffer, or
> from default values set for the entire buffer.

You seem to imply that this function returns the default values as
well as the values set by tags.  From looking at the code, it seems
that the default values are set in the gtktexttag.c function
gtk_text_attributes_new(), which is passed into the gtktextiter.c
function gtk_text_iter_get_attributes().  The comments for
gtk_text_iter_get_attributes() support this.  These comments read
as follows:

 * Computes the effect of any tags applied to this spot in the
 * text. The @values parameter should be initialized to the default
 * settings you wish to use if no tags are in effect.
 * gtk_text_iter_get_attributes () will modify @values, applying the
 * effects of any tags present at @iter. If any tags affected @values,
 * the function returns TRUE.

Therefore it seems like we could save ourselves a *lot* of work by
not re-inventing the wheel. For our own purposes we need to know, for
most attributes, whether they were explicitly set (via tags) or simply
"inherited" from the default.

If our understanding that gtk_text_attributes_new() is supposed to be
setting the defaults, and gtk_text_iter_get_attributes() then replaces
any values in the structure with ones from the tags, then we could 
easily use this interface to meet our needs with just a few minor changes:

The following enumerations would need an "UNSET" value added to them:

   GtkJustification
   GtkTextDirection
   GtkWrapMode
   PangoFontDescription -> PangoStyle
   PangoFontDescription -> PangoVariant
   PangoFontDescription -> PangoWeight
   PangoFontDescription -> PangoStretch
   
   In a purist sense, some things that are being communicated via flags
   like GtkTextAppearance->strikethrough should also have an unset value
   (in other words they would have likely have to be changed to 
   be enumerations).  However we have reviewed all such flags in the
   structure and we don't feel any of them are ones that we are
   particularly interested in.  Therefore, these could be left alone
   for now.
   
   If, for some reason, it is not possible to add new "UNSET" values to
   the above, then perhaps flags could be added to the GtkTextAttributes
   structure that could be used to communicate which ones were actually
   set via a tag.
   
   We will also need a public accessor for view->layout->default_style

Now we just need to call the gtk_text_iter_get_attributes() function
with a structure where everything that we are interested in is set to
values can be identified as unset, and we are returned the settings just
from the tags.

> I don't see changing GtkTextAttributes - for the use 
> gtk_text_iter_get_attributes() was originally intended for, 
> the set flags would be overkill, since for display, we need
> to know _all_ the attributes.

Again I'm a little confused since it doesn't seem that the
gtk_text_iter_get_attributes() function returns any default values or
accesses view->layout->default_style in any way.  It seems that it
depends on the gtk_text_attributes_new() function to fill in the 
default values before calling gtk_text_iter_get_attributes().  Is
this understanding incorrect?
 
As a separate issue, we still think it is a bug that the 
gtk_text_attributes_new() function is broken.  It doesn't seem to be
setting the values to the defaults from view->layout->default_style.

The fact that it just initializes all enumerations to 0 causes some
real problems. Then when you pass this structure into
gtk_text_iter_get_attributes() and the structure is passed back you
don't know if an actual tag set the PangoWeight to
"PANGO_WEIGHT_ULTRALIGHT" or if this is just because the value got
initialized to 0 in gtk_text_attributes_new().  Isn't 
gtk_text_attributes_new() *supposed* to be setting the values to the
defaults that are specified in view->layout->default_style?  It doesn't
seem to be doing this.

> If you really need to get the information about what attributes have
> been overriden on a particular stretch of text, it should be possible
> (if a little long-winded) for you to go down a level and work from
> gtk_text_iter_get_tags() instead.

We could do that.  However, it seems like a lot of work to do this
when the gtk_text_iter_get_attributes() function *almost* does what
we need.  If we write low-level code that interacts with the tags
directly, then there is an increased chance of the code getting out
of sync.  It seems it would be best to keep knowledge of how the tags
work in the TextView widget itself.

We can do the work and provide patches if that will make it possible
to make these functions work to meet our needs as well as yours.

Brian 





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