Re: Default settings for GtkTextAttributes



Brian Cameron <Brian Cameron Sun COM> writes:
> 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.

This is to read text properties to blind users, etc., right?

I would guess that what you actually want is simply:

 GtkTextAttributes *default_attrs;
 GtkTextAttributes *actual_attrs;

 default_attrs = gtk_text_view_get_default_attributes (textview);
 actual_attrs = gtk_text_attributes_copy (default_attrs);
 if (gtk_text_iter_get_attributes (&iter, actual_attrs))
   {
      /* Compare default_attrs to actual_attrs */

      if (default_attrs->size != actual_attrs->size)
         /* report different size */    ;
 
      /* etc, for each field in attrs */
   }

I don't see why you'd want to report differences that aren't visible
to sighted users. (i.e. if a sighted user can't tell that the text
properties are changed from the default, why would a blind user want
to know either? this is just some program implementation detail.)

>    We will also need a public accessor for
>    view->layout->default_style

We've agreed that we need gtk_text_view_get_default_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?

Yes, this is wrong. You would normally get the attributes to pass in
by:
  a) calling gtk_text_attributes_new ()
  b) filling in some sane default values

so you are skipping step b). When GtkTextView uses the
get_attributes() function it does not skip step b), it computes
layout->default_style.

What you're doing is trying to get the values that GtkTextView would
compute, this is a view-specific operation. So it should involve a
function which is view-specific, such as
gtk_text_view_get_default_attributes().

The reason gtk_text_attributes_new() doesn't fill in better default
values is that there really aren't any that make a lot of sense, so
why waste the CPU cycles. Defaults need to come from the view.
gtk_text_attributes_new() simply allocates a new "blank"
GtkTextAttributes. Think of it as equivalent to the declaration "int i;".

> 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.

How could it do that? The text buffer and text attributes know nothing
about the view. There can be multiple GtkTextView viewing a single
GtkTextBuffer. Using view->layout->default_style would screw up the
model-view separation.

Havoc




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