2005-01-29 [paul] 1.0.0cvs23.2
[claws.git] / src / gtk / gtkutils.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2005 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GTKUTILS_H__
21 #define __GTKUTILS_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <glib.h>
28 #include <gdk/gdk.h>
29 #include <gtk/gtkmain.h>
30 #include <gtk/gtkwidget.h>
31 #include <gtk/gtkcontainer.h>
32 #include <gtk/gtkeditable.h>
33 #include <gtk/gtkctree.h>
34 #include <gtk/gtkcombo.h>
35 #include <gtk/gtktextview.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <stdlib.h>
38 #if HAVE_WCHAR_H
39 #  include <wchar.h>
40 #endif
41
42 typedef struct _ComboButton     ComboButton;
43
44 struct _ComboButton
45 {
46         GtkWidget *arrow;
47         GtkWidget *button;
48         GtkWidget *menu;
49         GtkItemFactory *factory;
50         gpointer data;
51 };
52
53 #define GTK_EVENTS_FLUSH() \
54 { \
55         while (gtk_events_pending()) \
56                 gtk_main_iteration(); \
57 }
58
59 #define PIXMAP_CREATE(widget, pixmap, mask, xpm_d) \
60 { \
61         if (!pixmap) { \
62                 GtkStyle *style = gtk_widget_get_style(widget); \
63                 pixmap = gdk_pixmap_create_from_xpm_d \
64                         (widget->window, &mask, \
65                          &style->bg[GTK_STATE_NORMAL], xpm_d); \
66         } \
67 }
68
69 #define PIXMAP_CREATE_FROM_FILE(widget, pixmap, mask, filename) \
70 { \
71         if (!pixmap) { \
72                 GtkStyle *style = gtk_widget_get_style(widget); \
73                 pixmap = gdk_pixmap_create_from_xpm \
74                         (widget->window, &mask, \
75                          &style->bg[GTK_STATE_NORMAL], filename); \
76         } \
77 }
78
79 #define GTK_WIDGET_PTR(wid)     (*(GtkWidget **)wid)
80
81 #define GTKUT_CTREE_NODE_SET_ROW_DATA(node, d) \
82 { \
83         GTK_CTREE_ROW(node)->row.data = d; \
84 }
85
86 #define GTKUT_CTREE_NODE_GET_ROW_DATA(node) \
87         (GTK_CTREE_ROW(node)->row.data)
88
89 #define GTKUT_CTREE_REFRESH(clist) \
90         GTK_CLIST_GET_CLASS(clist)->refresh(clist)
91
92 gboolean gtkut_get_font_size            (GtkWidget      *widget,
93                                          gint           *width,
94                                          gint           *height);
95
96 void gtkut_convert_int_to_gdk_color     (gint            rgbvalue,
97                                          GdkColor       *color);
98
99 void gtkut_button_set_create            (GtkWidget      **bbox,
100                                          GtkWidget      **button1,
101                                          const gchar     *label1,
102                                          GtkWidget      **button2,
103                                          const gchar     *label2,
104                                          GtkWidget      **button3,
105                                          const gchar     *label3);
106
107 void gtkut_stock_button_set_create      (GtkWidget      **bbox,
108                                          GtkWidget      **button1,
109                                          const gchar     *label1,
110                                          GtkWidget      **button2,
111                                          const gchar     *label2,
112                                          GtkWidget      **button3,
113                                          const gchar     *label3);
114
115 ComboButton *gtkut_combo_button_create  (GtkWidget              *button,
116                                          GtkItemFactoryEntry    *entries,
117                                          gint                    n_entries,
118                                          const gchar            *path,
119                                          gpointer                data);
120
121 void gtkut_ctree_node_move_if_on_the_edge
122                                         (GtkCTree       *ctree,
123                                          GtkCTreeNode   *node);
124 gint gtkut_ctree_get_nth_from_node      (GtkCTree       *ctree,
125                                          GtkCTreeNode   *node);
126 GtkCTreeNode *gtkut_ctree_node_next     (GtkCTree       *ctree,
127                                          GtkCTreeNode   *node);
128 GtkCTreeNode *gtkut_ctree_node_prev     (GtkCTree       *ctree,
129                                          GtkCTreeNode   *node);
130 gboolean gtkut_ctree_node_is_selected   (GtkCTree       *ctree,
131                                          GtkCTreeNode   *node);
132 GtkCTreeNode *gtkut_ctree_find_collapsed_parent
133                                         (GtkCTree       *ctree,
134                                          GtkCTreeNode   *node);
135 void gtkut_ctree_expand_parent_all      (GtkCTree       *ctree,
136                                          GtkCTreeNode   *node);
137 gboolean gtkut_ctree_node_is_parent     (GtkCTreeNode   *parent, 
138                                          GtkCTreeNode   *node);
139 void gtkut_ctree_set_focus_row          (GtkCTree       *ctree,
140                                          GtkCTreeNode   *node);
141
142 void gtkut_clist_set_focus_row          (GtkCList       *clist,
143                                          gint            row);
144
145 void gtkut_combo_set_items              (GtkCombo       *combo,
146                                          const gchar    *str1, ...);
147
148 gchar *gtkut_editable_get_selection     (GtkEditable    *editable);
149 void gtkut_editable_disable_im          (GtkEditable    *editable);
150
151 void gtkut_container_remove             (GtkContainer   *container,
152                                          GtkWidget      *widget);
153
154
155 void gtkut_window_popup                 (GtkWidget      *window);
156
157 void gtkut_widget_get_uposition         (GtkWidget      *widget,
158                                          gint           *px,
159                                          gint           *py);
160 void gtkut_widget_disable_theme_engine  (GtkWidget      *widget);
161 void gtkut_widget_wait_for_draw         (GtkWidget      *widget);
162 void gtkut_widget_init                  (void);
163
164 void gtkut_widget_set_app_icon          (GtkWidget      *widget);
165 void gtkut_widget_set_composer_icon     (GtkWidget      *widget);
166
167 GtkWidget *gtkut_account_menu_new       (GList                  *ac_list,
168                                          GCallback               callback,
169                                          gpointer                data);
170
171 void gtkut_set_widget_bgcolor_rgb       (GtkWidget      *widget,
172                                          guint           rgbvalue);
173
174 gboolean gtkut_text_buffer_match_string (GtkTextBuffer  *text,
175                                          gint            pos,
176                                          gunichar       *wcs,
177                                          gint            len,
178                                          gboolean        case_sens);
179 guint gtkut_text_buffer_str_compare_n   (GtkTextBuffer  *text,
180                                          guint           pos1,
181                                          guint           pos2,
182                                          guint           len,
183                                          guint           text_len);
184 guint gtkut_text_buffer_str_compare     (GtkTextBuffer  *text,
185                                          guint           start_pos,
186                                          guint           text_len,
187                                          const gchar    *str);
188 gboolean gtkut_text_buffer_is_uri_string(GtkTextBuffer  *text,
189                                          guint           start_pos,
190                                          guint           text_len);
191 gchar *gtkut_text_view_get_selection    (GtkTextView    *textview);
192 GtkWidget *gtkut_get_focused_child      (GtkContainer   *parent);
193 #endif /* __GTKUTILS_H__ */