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