Re: How to make a button look like a treeview column title? [Was: How to use the treeview column title style for a button?]

2007-10-09 Thread Bastiaan Veelo
Kristian Rietveld wrote:
 On Mon, Oct 08, 2007 at 03:53:29PM +0200, Bastiaan Veelo wrote:
   
 Something like this seems to work for me:

   button = gtk_button_new_with_label (...);
   style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (button),
  *.GtkTreeView.GtkButton,
  NULL,
  G_OBJECT_TYPE (button));
   gtk_widget_set_style (button, style);
   
snip
 I guess I need to trick the theme engine into thinking that it is 
 drawing a GtkTreeView button. Is there a way to do that? If the method 
 would be engine-dependent, I need it to work on MS Windows.
 

 That is exactly what the code above tries to achieve.
snip

The reason why this is not going to work (for the windows theme at 
least, GTK+ 2.10) is a hard-coded check on the type of widget-parent in 
draw_box() on line 1929 of msw_style.c:

if (GTK_IS_TREE_VIEW (widget-parent)
|| GTK_IS_CLIST (widget-parent))
{
if (xp_theme_draw
(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
 width, height, state_type, area))
return;


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: How to make a button look like a treeview column title? [Was: How to use the treeview column title style for a button?]

2007-10-09 Thread Bastiaan Veelo
Bastiaan Veelo wrote:
 The reason why this is not going to work (for the windows theme at
 least, GTK+ 2.10) is a hard-coded check on the type of widget-parent in 
 draw_box() on line 1929 of msw_style.c:
   

So I faked the parent widget through some evil hacking in the expose 
function below. It works, for now.


#include gtk/gtk.h

G_BEGIN_DECLS

#define GTK_TYPE_HEADER (gtk_header_get_type ())
#define GTK_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST 
((obj), GTK_TYPE_HEADER, GtkMenuSheet))
#define GTK_HEADER_CLASS(klass) G_TYPE_CHECK_CLASS_CAST ((klass, 
GTK_TYPE_HEADER, GtkMenuSheetClass))
#define GTK_IS_HEADER(obj)  (G_TYPE_CHECK_INSTANCE_TYPE 
((obj), GTK_TYPE_HEADER))
#define GTK_IS_HEADER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE 
((klass), GTK_TYPE_HEADER))
#define GTK_HEADER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS 
((obj), GTK_TYPE_HEADER, GtkMenuSheetClass))

typedef struct _GtkHeader   GtkHeader;
typedef struct _GtkHeaderClass  GtkHeaderClass;

struct _GtkHeader
{
  GtkButton parent;
};

struct _GtkHeaderClass
{
  GtkButtonClass parent_class;
};

G_END_DECLS

GTypegtk_header_get_type (void) G_GNUC_CONST;
GtkWidget   *gtk_header_sheet_new();
static gboolean  gtk_header_expose   (GtkWidget  
*widget,
  GdkEventExpose 
*event);

static void
gtk_header_class_init (GtkHeaderClass *class)
{
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
  widget_class-expose_event = gtk_header_expose;
}

static void
gtk_header_init (GtkHeader *header)
{
}

/* GType Methods */

G_DEFINE_TYPE (GtkHeader, gtk_header, GTK_TYPE_BUTTON)

GType
gtk_header_type ()
{
  static GType header_type = 0;

  if (!header_type)
  {
static const GTypeInfo header_info =
{
  sizeof (GtkHeaderClass),
  NULL, /* base_init */
  NULL, /* base_finalize */
  (GClassInitFunc) gtk_header_class_init,
  NULL, /* class_finalize */
  NULL, /* class_data */
  sizeof (GtkHeader),
  0,/* n_preallocs */
  (GInstanceInitFunc) gtk_header_init,
};

header_type = g_type_register_static (GTK_TYPE_BUTTON,
  GtkHeader,
  header_info,
  0);
  }
  return header_type;
}

static gboolean
gtk_header_expose (GtkWidget  *widget,
   GdkEventExpose *event)
{
  static GtkWidget *treeview = NULL;
  if (!treeview) treeview = gtk_tree_view_new();

  /* Trick draw_box() in msw_style.c on line 1929 into thinking that our 
parent
 is a GtkTreeView. This works on MS Windows and GTK+ 2.10.6, but it may
 fail miserably when used with other themes or other versions of 
GTK+. */
  GtkWidget *real_parent = widget-parent;
  widget-parent = treeview;
  (* GTK_WIDGET_CLASS (gtk_header_parent_class)-expose_event) (widget, 
event);
  widget-parent = real_parent;

  return FALSE;
}

GtkWidget*
gtk_header_new (void)
{
  return g_object_new (GTK_TYPE_HEADER, NULL);
}

int main( int   argc,
  char *argv[] )
{
  gtk_init (argc, argv);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, destroy,
G_CALLBACK (gtk_widget_destroyed), window);

  GtkWidget *header = gtk_header_new();
  gtk_button_set_label (GTK_BUTTON (header), Header);
  /* Not sure whether the folowwing is necessary. */
  GtkStyle *style = gtk_rc_get_style_by_paths (gtk_widget_get_settings 
(header),
   NULL,
   *.GtkTreeView.GtkButton,
   GTK_TYPE_BUTTON);
  gtk_widget_set_style (header, style);
  gtk_container_add (GTK_CONTAINER (window), header);

  gtk_widget_show_all(window);
  gtk_main ();

  return 0;
}


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: How to make a button look like a treeview column title? [Was: How to use the treeview column title style for a button?]

2007-10-08 Thread Kristian Rietveld
On Mon, Oct 08, 2007 at 03:53:29PM +0200, Bastiaan Veelo wrote:
  Something like this seems to work for me:
 
button = gtk_button_new_with_label (...);
style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (button),
   *.GtkTreeView.GtkButton,
   NULL,
   G_OBJECT_TYPE (button));
gtk_widget_set_style (button, style);
 

 
 Thank you for replying. However, for me the above has no visible effect. 
 Now I understand that a GtkStyle is just about colors and similar 
 settings, which only partly determine the looks of a widget. In my case 
 I suspect that a GtkTreeView.GtkButton has the same GtkStyle settings as 
 ordinary buttons, which is why I see no change.

By default it does have the same settings, but in multiple themes it
does not.

 I recently discovered that there is something called a theme engine, and 
 I guess I need to trick the theme engine into thinking that it is 
 drawing a GtkTreeView button. Is there a way to do that? If the method 
 would be engine-dependent, I need it to work on MS Windows.

That is exactly what the code above tries to achieve.  I briefly looked
at the Windows theme source code and figured that it does things a little
different than the theme engine I first looked at.  Does using:

  style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (button),
 *.GtkTreeView.GtkButton,
 *.GtkTreeView.GtkButton,
 G_OBJECT_TYPE (button));

instead of the call to gtk_rc_get_style_by_paths() posted earlier have
any effect?


regards,

-kris.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: How to make a button look like a treeview column title? [Was: How to use the treeview column title style for a button?]

2007-10-08 Thread Bastiaan Veelo
Kristian Rietveld wrote:
 On Mon, Oct 08, 2007 at 03:53:29PM +0200, Bastiaan Veelo wrote:
   
 Something like this seems to work for me:

   button = gtk_button_new_with_label (...);
   style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (button),
  *.GtkTreeView.GtkButton,
  NULL,
  G_OBJECT_TYPE (button));
   gtk_widget_set_style (button, style);

   
   
 Thank you for replying. However, for me the above has no visible effect. 
 Now I understand that a GtkStyle is just about colors and similar 
 settings, which only partly determine the looks of a widget. In my case 
 I suspect that a GtkTreeView.GtkButton has the same GtkStyle settings as 
 ordinary buttons, which is why I see no change.
 

 By default it does have the same settings, but in multiple themes it
 does not.

   
 I recently discovered that there is something called a theme engine, and 
 I guess I need to trick the theme engine into thinking that it is 
 drawing a GtkTreeView button. Is there a way to do that? If the method 
 would be engine-dependent, I need it to work on MS Windows.
 

 That is exactly what the code above tries to achieve.  I briefly looked
 at the Windows theme source code and figured that it does things a little
 different than the theme engine I first looked at.  Does using:

   style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (button),
  *.GtkTreeView.GtkButton,
  *.GtkTreeView.GtkButton,
  G_OBJECT_TYPE (button));

 instead of the call to gtk_rc_get_style_by_paths() posted earlier have
 any effect?
   

No, it does not. Could it be that the style is overwritten as per 
http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-set-style?

Bastiaan.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: How to make a button look like a treeview column title? [Was: How to use the treeview column title style for a button?]

2007-10-08 Thread Bastiaan Veelo
I looked at modules/engines/ms-windows/msw_style.c, line 855, and tried 
the following, without succes:

  gchar* class_path = NULL;
  gtk_widget_class_path(button, NULL, class_path, NULL);

  gchar buf[1024];
  g_snprintf (buf, sizeof(buf),
widget_class \%s\ style \msw-header-button\\n,
class_path );
  gtk_rc_parse_string (buf);


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: How to make a button look like a treeview column title? [Was: How to use the treeview column title style for a button?]

2007-10-08 Thread Bastiaan Veelo

Hi,

I have done some more experimenting with styles, attached, and my 
confusion has only grown bigger. See comments in the source. I still 
cannot get an ordinary button to look like a tree view title...


Should I go ask on gtk-devel?

Regards,
Bastiaan.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: How to make a button look like a treeview column title? [Was: How to use the treeview column title style for a button?]

2007-10-08 Thread Bastiaan Veelo

One more try with attachments.

Bastiaan Veelo wrote:
I have done some more experimenting with styles, attached, and my 
confusion has only grown bigger. See comments in the source. I still 
cannot get an ordinary button to look like a tree view title...


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: How to make a button look like a treeview column title? [Was: How to use the treeview column title style for a button?]

2007-10-08 Thread Bastiaan Veelo
#include gtk/gtk.h

int main( int   argc,
  char *argv[] )
{
  gtk_init (argc, argv);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, destroy,
G_CALLBACK (gtk_widget_destroyed), window);

  GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
  GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
  GtkTreeViewColumn *column0 =
  gtk_tree_view_column_new_with_attributes (TreeViewButton,
renderer,
text,
0,
NULL);
  GtkWidget *treeview = gtk_tree_view_new_with_model 
(GTK_TREE_MODEL(store));
  gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column0);
  gtk_box_pack_start_defaults (GTK_BOX (vbox), treeview);

  GtkWidget *button = gtk_button_new_with_label( Ordinary button );
  gtk_box_pack_start_defaults( GTK_BOX( vbox ), button );

  /* Almost the same as ordinary button. Under Windows the focus frame 
is few pixels
   narrower than on an ordinary button. Under Kubuntu the button is 
slightly broader
   than an ordinary button but has no prelight. Anyway it does not look 
like a
   TreeView button at all. */
  GtkWidget *title1 = gtk_button_new_with_label( style by path 
*.GtkTreeView.GtkButton );
  gtk_box_pack_start_defaults( GTK_BOX( vbox ), title1 );
  GtkStyle *style = gtk_rc_get_style_by_paths (gtk_widget_get_settings 
(title1),
   *.GtkTreeView.GtkButton,
   *.GtkTreeView.GtkButton,
   G_OBJECT_TYPE (title1));
  gtk_widget_set_style (title1, style);

  /* Set to its own style. This has the surprising effect that the 
button seems
   to fall back to its default GTK style. */
  GtkWidget *title2 = gtk_button_new_with_label( Set to its own style );
  GtkStyle *style2 = gtk_widget_get_style(title2);
  gtk_widget_set_style (title2, style2);
  gtk_box_pack_start_defaults( GTK_BOX( vbox ), title2 );

  /* Copy the style from title1 which we have previously set. This works 
as expected,
   so why did the style on title2 not work? */
  GtkWidget *title2a = gtk_button_new_with_label( Set to style title1 );
  GtkStyle *style2a = gtk_widget_get_style(title1);
  gtk_widget_set_style (title2a, style2a);
  gtk_box_pack_start_defaults( GTK_BOX( vbox ), title2a );

  /* Set the style from a totally different widget. The button seems to 
fall back
   to GTK style, same as when trying to set to its own style. */
  GtkWidget *title3 = gtk_button_new_with_label( Set to window style );
  GtkStyle *style3 = gtk_widget_get_style(window);
  gtk_widget_set_style (title3, style3);
  gtk_box_pack_start_defaults( GTK_BOX( vbox ), title3 );

  /* This works as expected. */
  GtkWidget *title4 = gtk_button_new_with_label( gtk_widget_set_style() 
button );
  gtk_box_pack_start_defaults( GTK_BOX( vbox ), title4 );
  GtkStyle *style4 = gtk_rc_get_style_by_paths (gtk_widget_get_settings 
(title4),
*Button,
*Button,
 G_OBJECT_TYPE (title4));
  gtk_widget_set_style (title4, style4);

  /* Try a path like msw_style.c uses it. This looks exactly as an 
ordinary button. */
  GtkWidget *title5 = gtk_button_new_with_label( style by path 
*Treeview*Button* );
  gtk_box_pack_start_defaults( GTK_BOX( vbox ), title5 );
  GtkStyle *style5 = gtk_rc_get_style_by_paths (gtk_widget_get_settings 
(title5),
*Treeview*Button*,
*Treeview*Button*,
G_OBJECT_TYPE (title5));
  gtk_widget_set_style (title5, style5);

  /* Under Windows this looks like title1. Under Kubuntu it does too, 
but with prelight. */
  GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
  gtk_box_pack_start_defaults( GTK_BOX( vbox ), hbox );
  GtkWidget *title6 = gtk_button_new_with_label (msw-header-button);
  gtk_box_pack_start_defaults (GTK_BOX( hbox ), title6);
  gchar* class_path = NULL;
  gtk_widget_class_path(title6, NULL, class_path, NULL);
  g_debug(button class path = %s, class_path);
  gchar buf[1024];
  g_snprintf (buf, sizeof(buf),
  widget_class \%s\ style \msw-header-button\\n,
  class_path );
  g_debug(%s, buf);
  gtk_rc_parse_string (buf);

  gtk_widget_show_all(window);
  gtk_main ();

  return 0;
}


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list