try again
[claws.git] / src / gtk / gtkutils.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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_stock_button_add_help(GtkWidget *bbox, GtkWidget **help_btn);
100
101 void gtkut_stock_button_set_create_with_help(GtkWidget **bbox,
102                 GtkWidget **help_button,
103                 GtkWidget **button1, const gchar *label1,
104                 GtkWidget **button2, const gchar *label2,
105                 GtkWidget **button3, 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            _row);
125 gint gtkut_ctree_get_nth_from_node      (GtkCTree       *ctree,
126                                          GtkCTreeNode   *node);
127 GtkCTreeNode *gtkut_ctree_node_next     (GtkCTree       *ctree,
128                                          GtkCTreeNode   *node);
129 GtkCTreeNode *gtkut_ctree_node_prev     (GtkCTree       *ctree,
130                                          GtkCTreeNode   *node);
131 gboolean gtkut_ctree_node_is_selected   (GtkCTree       *ctree,
132                                          GtkCTreeNode   *node);
133 GtkCTreeNode *gtkut_ctree_find_collapsed_parent
134                                         (GtkCTree       *ctree,
135                                          GtkCTreeNode   *node);
136 void gtkut_ctree_expand_parent_all      (GtkCTree       *ctree,
137                                          GtkCTreeNode   *node);
138 gboolean gtkut_ctree_node_is_parent     (GtkCTreeNode   *parent, 
139                                          GtkCTreeNode   *node);
140 void gtkut_ctree_set_focus_row          (GtkCTree       *ctree,
141                                          GtkCTreeNode   *node);
142
143 void gtkut_clist_set_focus_row          (GtkCList       *clist,
144                                          gint            row);
145
146 void gtkut_combo_set_items              (GtkCombo       *combo,
147                                          const gchar    *str1, ...);
148
149 gchar *gtkut_editable_get_selection     (GtkEditable    *editable);
150 void gtkut_editable_disable_im          (GtkEditable    *editable);
151
152 void gtkut_container_remove             (GtkContainer   *container,
153                                          GtkWidget      *widget);
154
155 gboolean gtkut_text_buffer_match_string (GtkTextBuffer          *buffer,
156                                          const GtkTextIter      *iter,
157                                          gunichar               *wcs,
158                                          gint                    len,
159                                          gboolean                case_sens);
160 gboolean gtkut_text_buffer_find         (GtkTextBuffer          *buffer,
161                                          const GtkTextIter      *iter,
162                                          const gchar            *str,
163                                          gboolean                case_sens,
164                                          GtkTextIter            *match_pos);
165 gboolean gtkut_text_buffer_find_backward(GtkTextBuffer          *buffer,
166                                          const GtkTextIter      *iter,
167                                          const gchar            *str,
168                                          gboolean                case_sens,
169                                          GtkTextIter            *match_pos);
170
171 gchar *gtkut_text_view_get_selection    (GtkTextView    *textview);
172 void gtkut_text_view_set_position               (GtkTextView *text, gint pos);
173 gboolean gtkut_text_view_search_string  (GtkTextView *text, const gchar *str,
174                                         gboolean case_sens);
175 gboolean gtkut_text_view_search_string_backward (GtkTextView *text, const gchar *str,
176                                         gboolean case_sens);
177
178 GtkWidget *label_window_create(const gchar *str);
179 void gtkut_window_popup                 (GtkWidget      *window);
180
181 void gtkut_widget_get_uposition         (GtkWidget      *widget,
182                                          gint           *px,
183                                          gint           *py);
184 void gtkut_widget_draw_now              (GtkWidget      *widget);
185 void gtkut_widget_init                  (void);
186
187 void gtkut_widget_set_app_icon          (GtkWidget      *widget);
188 void gtkut_widget_set_composer_icon     (GtkWidget      *widget);
189
190 GtkWidget *gtkut_account_menu_new       (GList                  *ac_list,
191                                          GCallback               callback,
192                                          gpointer                data);
193
194 void gtkut_set_widget_bgcolor_rgb       (GtkWidget      *widget,
195                                          guint           rgbvalue);
196
197 void gtkut_widget_set_small_font_size(GtkWidget *widget);
198 GtkWidget *gtkut_get_focused_child      (GtkContainer   *parent);
199
200 GtkWidget *gtkut_get_browse_file_btn(const gchar *label);
201 GtkWidget *gtkut_get_browse_directory_btn(const gchar *label);
202 GtkWidget *gtkut_get_replace_btn(const gchar *label);
203 #if HAVE_LIBCOMPFACE
204 gint create_xpm_from_xface(gchar *xpm[], const gchar *xface);
205 GtkWidget *xface_get_from_header(const gchar *o_xface, GdkColor *background,
206                                  GdkWindow *window);
207 #endif
208 gboolean get_tag_range(GtkTextIter *iter,
209                                        GtkTextTag *tag,
210                                        GtkTextIter *start_iter,
211                                        GtkTextIter *end_iter);
212
213 GtkWidget *face_get_from_header(const gchar *o_face);
214 GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *label);
215
216 GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox, gboolean focus_on_click);
217 void gtkutils_scroll_one_line   (GtkWidget *widget, 
218                                  GtkAdjustment *vadj, 
219                                  gboolean up);
220 gboolean gtkutils_scroll_page   (GtkWidget *widget, 
221                                  GtkAdjustment *vadj, 
222                                  gboolean up);
223 #endif /* __GTKUTILS_H__ */