2007-01-23 [colin] 2.7.1cvs52
[claws.git] / src / gtk / gtkutils.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 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 <gtk/gtktreemodel.h>
38 #include <stdlib.h>
39 #if HAVE_WCHAR_H
40 #  include <wchar.h>
41 #endif
42
43 typedef struct _ComboButton     ComboButton;
44
45 struct _ComboButton
46 {
47         GtkWidget *arrow;
48         GtkWidget *button;
49         GtkWidget *menu;
50         GtkItemFactory *factory;
51         gpointer data;
52 };
53
54 #define GTK_EVENTS_FLUSH() \
55 { \
56         while (gtk_events_pending()) \
57                 gtk_main_iteration(); \
58 }
59
60 #define PIXMAP_CREATE(widget, pixmap, mask, xpm_d) \
61 { \
62         if (!pixmap) { \
63                 GtkStyle *style = gtk_widget_get_style(widget); \
64                 pixmap = gdk_pixmap_create_from_xpm_d \
65                         (widget->window, &mask, \
66                          &style->bg[GTK_STATE_NORMAL], xpm_d); \
67         } \
68 }
69
70 #define PIXMAP_CREATE_FROM_FILE(widget, pixmap, mask, filename) \
71 { \
72         if (!pixmap) { \
73                 GtkStyle *style = gtk_widget_get_style(widget); \
74                 pixmap = gdk_pixmap_create_from_xpm \
75                         (widget->window, &mask, \
76                          &style->bg[GTK_STATE_NORMAL], filename); \
77         } \
78 }
79
80 #define GTK_WIDGET_PTR(wid)     (*(GtkWidget **)wid)
81
82 #define GTKUT_CTREE_NODE_SET_ROW_DATA(node, d) \
83 { \
84         GTK_CTREE_ROW(node)->row.data = d; \
85 }
86
87 #define GTKUT_CTREE_NODE_GET_ROW_DATA(node) \
88         (GTK_CTREE_ROW(node)->row.data)
89
90 #define GTKUT_CTREE_REFRESH(clist) \
91         GTK_CLIST_GET_CLASS(clist)->refresh(clist)
92
93 gboolean gtkut_get_font_size            (GtkWidget      *widget,
94                                          gint           *width,
95                                          gint           *height);
96
97 void gtkut_convert_int_to_gdk_color     (gint            rgbvalue,
98                                          GdkColor       *color);
99
100 void gtkut_stock_button_add_help(GtkWidget *bbox, GtkWidget **help_btn);
101
102 void gtkut_stock_button_set_create_with_help(GtkWidget **bbox,
103                 GtkWidget **help_button,
104                 GtkWidget **button1, const gchar *label1,
105                 GtkWidget **button2, const gchar *label2,
106                 GtkWidget **button3, const gchar *label3);
107
108 void gtkut_stock_button_set_create      (GtkWidget      **bbox,
109                                          GtkWidget      **button1,
110                                          const gchar     *label1,
111                                          GtkWidget      **button2,
112                                          const gchar     *label2,
113                                          GtkWidget      **button3,
114                                          const gchar     *label3);
115
116 void gtkut_stock_with_text_button_set_create(GtkWidget **bbox,
117                                    GtkWidget **button1, const gchar *label1, const gchar *text1,
118                                    GtkWidget **button2, const gchar *label2, const gchar *text2,
119                                    GtkWidget **button3, const gchar *label3, const gchar *text3);
120
121 ComboButton *gtkut_combo_button_create  (GtkWidget              *button,
122                                          GtkItemFactoryEntry    *entries,
123                                          gint                    n_entries,
124                                          const gchar            *path,
125                                          gpointer                data);
126
127 void gtkut_ctree_node_move_if_on_the_edge
128                                         (GtkCTree       *ctree,
129                                          GtkCTreeNode   *node,
130                                          gint            _row);
131 gint gtkut_ctree_get_nth_from_node      (GtkCTree       *ctree,
132                                          GtkCTreeNode   *node);
133 GtkCTreeNode *gtkut_ctree_node_next     (GtkCTree       *ctree,
134                                          GtkCTreeNode   *node);
135 GtkCTreeNode *gtkut_ctree_node_prev     (GtkCTree       *ctree,
136                                          GtkCTreeNode   *node);
137 gboolean gtkut_ctree_node_is_selected   (GtkCTree       *ctree,
138                                          GtkCTreeNode   *node);
139 GtkCTreeNode *gtkut_ctree_find_collapsed_parent
140                                         (GtkCTree       *ctree,
141                                          GtkCTreeNode   *node);
142 void gtkut_ctree_expand_parent_all      (GtkCTree       *ctree,
143                                          GtkCTreeNode   *node);
144 gboolean gtkut_ctree_node_is_parent     (GtkCTreeNode   *parent, 
145                                          GtkCTreeNode   *node);
146 void gtkut_ctree_set_focus_row          (GtkCTree       *ctree,
147                                          GtkCTreeNode   *node);
148
149 void gtkut_clist_set_focus_row          (GtkCList       *clist,
150                                          gint            row);
151
152 void gtkut_combo_set_items              (GtkCombo       *combo,
153                                          const gchar    *str1, ...);
154
155 gchar *gtkut_editable_get_selection     (GtkEditable    *editable);
156 void gtkut_editable_disable_im          (GtkEditable    *editable);
157
158 void gtkut_container_remove             (GtkContainer   *container,
159                                          GtkWidget      *widget);
160
161 gboolean gtkut_text_buffer_match_string (GtkTextBuffer          *buffer,
162                                          const GtkTextIter      *iter,
163                                          gunichar               *wcs,
164                                          gint                    len,
165                                          gboolean                case_sens);
166 gboolean gtkut_text_buffer_find         (GtkTextBuffer          *buffer,
167                                          const GtkTextIter      *iter,
168                                          const gchar            *str,
169                                          gboolean                case_sens,
170                                          GtkTextIter            *match_pos);
171 gboolean gtkut_text_buffer_find_backward(GtkTextBuffer          *buffer,
172                                          const GtkTextIter      *iter,
173                                          const gchar            *str,
174                                          gboolean                case_sens,
175                                          GtkTextIter            *match_pos);
176
177 gchar *gtkut_text_view_get_selection    (GtkTextView    *textview);
178 void gtkut_text_view_set_position               (GtkTextView *text, gint pos);
179 gboolean gtkut_text_view_search_string  (GtkTextView *text, const gchar *str,
180                                         gboolean case_sens);
181 gboolean gtkut_text_view_search_string_backward (GtkTextView *text, const gchar *str,
182                                         gboolean case_sens);
183
184 GtkWidget *label_window_create(const gchar *str);
185 void gtkut_window_popup                 (GtkWidget      *window);
186
187 void gtkut_widget_get_uposition         (GtkWidget      *widget,
188                                          gint           *px,
189                                          gint           *py);
190 void gtkut_widget_draw_now              (GtkWidget      *widget);
191 void gtkut_widget_init                  (void);
192
193 void gtkut_widget_set_app_icon          (GtkWidget      *widget);
194 void gtkut_widget_set_composer_icon     (GtkWidget      *widget);
195
196 GtkWidget *gtkut_account_menu_new       (GList                  *ac_list,
197                                          GCallback               callback,
198                                          gpointer                data);
199
200 void gtkut_set_widget_bgcolor_rgb       (GtkWidget      *widget,
201                                          guint           rgbvalue);
202
203 void gtkut_widget_set_small_font_size(GtkWidget *widget);
204 GtkWidget *gtkut_get_focused_child      (GtkContainer   *parent);
205
206 GtkWidget *gtkut_get_browse_file_btn(const gchar *label);
207 GtkWidget *gtkut_get_browse_directory_btn(const gchar *label);
208 GtkWidget *gtkut_get_replace_btn(const gchar *label);
209 GtkWidget *gtkut_get_options_frame(GtkWidget *box, GtkWidget **frame, const gchar *frame_label);
210 #if HAVE_LIBCOMPFACE
211 GtkWidget *xface_get_from_header(const gchar *o_xface, GdkColor *background,
212                                  GdkWindow *window);
213 #endif
214 gboolean get_tag_range(GtkTextIter *iter,
215                                        GtkTextTag *tag,
216                                        GtkTextIter *start_iter,
217                                        GtkTextIter *end_iter);
218
219 GtkWidget *face_get_from_header(const gchar *o_face);
220 GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *label);
221
222 GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox, gboolean focus_on_click);
223 void gtkutils_scroll_one_line   (GtkWidget *widget, 
224                                  GtkAdjustment *vadj, 
225                                  gboolean up);
226 gboolean gtkutils_scroll_page   (GtkWidget *widget, 
227                                  GtkAdjustment *vadj, 
228                                  gboolean up);
229
230 gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
231                                  GtkTreeIter *iter,
232                                  const gchar* text);
233 gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
234                                  GtkTreeIter *iter);
235
236 #endif /* __GTKUTILS_H__ */