root / trunk / linux / gtktools.cpp

Revision 725, 3.3 kB (checked in by leo, 6 months ago)

Linux compile fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1// Helper functions for GTK
2//
3
4#include <gtk/gtk.h>
5#include "gtktools.h"
6
7GtkWidget* new_pixmap (GtkWidget *widget, const char **data)
8{
9  GdkPixmap *gdkpixmap;
10  GdkBitmap *mask;
11  GtkWidget *pixmap;
12
13  gdkpixmap = gdk_pixmap_create_from_xpm_d (widget->window, &mask,
14                 &widget->style->bg[GTK_STATE_NORMAL], (gchar**)data);
15  pixmap = gtk_pixmap_new (gdkpixmap, mask);
16
17  gdk_pixmap_unref (gdkpixmap);
18  gdk_pixmap_unref (mask);
19
20  return pixmap;
21}
22
23GtkWidget* clist_title_with_arrow (GtkWidget* clist, char col, char* label_text)
24{
25  GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
26  GtkWidget *arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
27  GtkWidget *label = gtk_label_new (label_text);
28
29  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
30  gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, TRUE, 0);
31  gtk_widget_show (label);
32
33  gtk_widget_show (hbox);
34  gtk_clist_set_column_widget (GTK_CLIST (clist), col, hbox);
35  return arrow;
36}
37
38void set_notebook_tab (GtkWidget *notebook, gint page_num, GtkWidget *widget)
39{
40  gtk_notebook_set_tab_label(GTK_NOTEBOOK(notebook), gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), page_num), widget);
41  /*
42  GtkNotebookPage *page;
43  GtkWidget *notebook_page;
44
45  page = (GtkNotebookPage*) g_list_nth (GTK_NOTEBOOK (notebook)->children, page_num)->data;
46  notebook_page = page->child;
47  gtk_widget_ref (notebook_page);
48  gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), page_num);
49  gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), notebook_page,
50                            widget, page_num);
51  gtk_widget_unref (notebook_page);
52  */
53}
54
55void set_button_pixmap (GtkWidget* widget, float* color)
56{
57  if (widget->window == NULL)
58    return;
59
60  GdkColor c;
61  GdkGC* gc = gdk_gc_new(widget->window);
62  GdkPixmap* pixmap = gdk_pixmap_new(widget->window, widget->allocation.width - 20,
63                     widget->allocation.height - 20, -1);
64
65  c.red = (gushort)(color[0]*0xFFFF);
66  c.green = (gushort)(color[1]*0xFFFF);
67  c.blue = (gushort)(color[2]*0xFFFF);
68  gdk_color_alloc (gtk_widget_get_colormap(widget), &c);
69  gdk_gc_set_foreground(gc, &c);
70
71  gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0,
72              widget->allocation.width - 20, widget->allocation.height - 20);
73
74  GtkWidget* pixmapwid = gtk_pixmap_new (pixmap, (GdkBitmap*)NULL);
75  gtk_widget_show (pixmapwid);
76
77  gtk_container_remove (GTK_CONTAINER(widget), GTK_BIN(widget)->child);
78  gtk_container_add (GTK_CONTAINER(widget), pixmapwid);
79  gdk_gc_destroy(gc);
80}
81
82void set_button_pixmap2 (GtkWidget* widget, float* color)
83{
84  GdkColor c;
85  GdkGC* gc;
86  GdkPixmap* pixmap;
87
88  if (widget->window == NULL)
89    return;
90
91  if ((widget->allocation.width < 10) || (widget->allocation.height < 10))
92    return;
93
94  gc = gdk_gc_new (widget->window);
95  pixmap = gdk_pixmap_new (widget->window, widget->allocation.width - 10,
96               widget->allocation.height - 10, -1);
97
98  c.red = color[0]*65535;
99  c.green = color[1]*65535;
100  c.blue = color[2]*65535;
101  gdk_color_alloc (gtk_widget_get_colormap(widget), &c);
102  gdk_gc_set_foreground(gc, &c);
103
104  gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0,
105              widget->allocation.width - 5, widget->allocation.height - 5);
106
107  GtkWidget* pixmapwid = gtk_pixmap_new (pixmap, (GdkBitmap*)NULL);
108  gtk_widget_show (pixmapwid);
109
110  gtk_container_remove (GTK_CONTAINER(widget), GTK_BIN(widget)->child);
111  gtk_container_add (GTK_CONTAINER(widget), pixmapwid);
112  gdk_gc_destroy(gc);
113}
Note: See TracBrowser for help on using the browser.