2011-10-07 [colin] 3.7.10cvs21
[claws.git] / src / gtk / gtkutils.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2011 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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
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/gtk.h>
30 #include <stdlib.h>
31 #if HAVE_WCHAR_H
32 #  include <wchar.h>
33 #endif
34
35 #ifdef MAEMO
36 #ifdef CHINOOK
37 #include <hildon/hildon-program.h>
38 #else
39 #include <hildon-widgets/hildon-program.h>
40 #include <hildon-widgets/hildon-window.h>
41 #endif
42 #include "main.h"
43 #endif
44
45 #if !GTK_CHECK_VERSION(3, 0, 0)
46 #include "gtkcmctree.h"
47 #endif
48
49 #define GTK_EVENTS_FLUSH() \
50 { \
51         while (gtk_events_pending()) \
52                 gtk_main_iteration(); \
53 }
54
55 #define GTK_WIDGET_PTR(wid)     (*(GtkWidget **)wid)
56
57 #define GTKUT_CTREE_NODE_SET_ROW_DATA(node, d) \
58 { \
59         GTK_CMCTREE_ROW(node)->row.data = d; \
60 }
61
62 #define GTKUT_CTREE_NODE_GET_ROW_DATA(node) \
63         (GTK_CMCTREE_ROW(node)->row.data)
64
65 #define GTKUT_CTREE_REFRESH(clist) \
66         GTK_CMCLIST_GET_CLASS(clist)->refresh(clist)
67
68 gboolean gtkut_get_font_size            (GtkWidget      *widget,
69                                          gint           *width,
70                                          gint           *height);
71
72 void gtkut_convert_int_to_gdk_color     (gint            rgbvalue,
73                                          GdkColor       *color);
74 gint gtkut_convert_gdk_color_to_int     (GdkColor       *color);
75
76 void gtkut_stock_button_add_help(GtkWidget *bbox, GtkWidget **help_btn);
77
78 void gtkut_stock_button_set_create_with_help(GtkWidget **bbox,
79                 GtkWidget **help_button,
80                 GtkWidget **button1, const gchar *label1,
81                 GtkWidget **button2, const gchar *label2,
82                 GtkWidget **button3, const gchar *label3);
83
84 void gtkut_stock_button_set_create      (GtkWidget      **bbox,
85                                          GtkWidget      **button1,
86                                          const gchar     *label1,
87                                          GtkWidget      **button2,
88                                          const gchar     *label2,
89                                          GtkWidget      **button3,
90                                          const gchar     *label3);
91
92 void gtkut_stock_with_text_button_set_create(GtkWidget **bbox,
93                                    GtkWidget **button1, const gchar *label1, const gchar *text1,
94                                    GtkWidget **button2, const gchar *label2, const gchar *text2,
95                                    GtkWidget **button3, const gchar *label3, const gchar *text3);
96
97 #if !GTK_CHECK_VERSION(3, 0, 0)
98 void gtkut_ctree_node_move_if_on_the_edge
99                                         (GtkCMCTree     *ctree,
100                                          GtkCMCTreeNode *node,
101                                          gint            _row);
102 gint gtkut_ctree_get_nth_from_node      (GtkCMCTree     *ctree,
103                                          GtkCMCTreeNode *node);
104 GtkCMCTreeNode *gtkut_ctree_node_next   (GtkCMCTree     *ctree,
105                                          GtkCMCTreeNode *node);
106 GtkCMCTreeNode *gtkut_ctree_node_prev   (GtkCMCTree     *ctree,
107                                          GtkCMCTreeNode *node);
108 gboolean gtkut_ctree_node_is_selected   (GtkCMCTree     *ctree,
109                                          GtkCMCTreeNode *node);
110 GtkCMCTreeNode *gtkut_ctree_find_collapsed_parent
111                                         (GtkCMCTree     *ctree,
112                                          GtkCMCTreeNode *node);
113 void gtkut_ctree_expand_parent_all      (GtkCMCTree     *ctree,
114                                          GtkCMCTreeNode *node);
115 gboolean gtkut_ctree_node_is_parent     (GtkCMCTreeNode         *parent, 
116                                          GtkCMCTreeNode         *node);
117 void gtkut_ctree_set_focus_row          (GtkCMCTree     *ctree,
118                                          GtkCMCTreeNode *node);
119 #endif
120
121 void gtkut_clist_set_focus_row          (GtkCMCList     *clist,
122                                          gint            row);
123
124 void gtkut_container_remove             (GtkContainer   *container,
125                                          GtkWidget      *widget);
126
127 gchar *gtkut_text_view_get_selection    (GtkTextView    *textview);
128 void gtkut_text_view_set_position               (GtkTextView *text, gint pos);
129 gboolean gtkut_text_view_search_string  (GtkTextView *text, const gchar *str,
130                                         gboolean case_sens);
131 gboolean gtkut_text_view_search_string_backward (GtkTextView *text, const gchar *str,
132                                         gboolean case_sens);
133
134 GtkWidget *label_window_create(const gchar *str);
135 void label_window_destroy(GtkWidget *widget);
136
137 void gtkut_window_popup                 (GtkWidget      *window);
138 GtkWidget *gtkut_window_new             (GtkWindowType   type,
139                                          const gchar    *class);
140
141
142 void gtkut_widget_get_uposition         (GtkWidget      *widget,
143                                          gint           *px,
144                                          gint           *py);
145 void gtkut_widget_draw_now              (GtkWidget      *widget);
146 void gtkut_widget_init                  (void);
147
148 void gtkut_widget_set_app_icon          (GtkWidget      *widget);
149 void gtkut_widget_set_composer_icon     (GtkWidget      *widget);
150
151 gboolean gtkut_widget_get_app_paintable (GtkWidget      *widget);
152 gboolean gtkut_widget_get_can_focus     (GtkWidget      *widget);
153 gboolean gtkut_widget_get_has_window    (GtkWidget      *widget);
154 gboolean gtkut_widget_get_mapped        (GtkWidget      *widget);
155 gboolean gtkut_widget_get_realized      (GtkWidget      *widget);
156 gboolean gtkut_widget_get_sensitive     (GtkWidget      *widget);
157 GtkStateType gtkut_widget_get_state     (GtkWidget      *widget);
158 gboolean gtkut_widget_get_visible       (GtkWidget      *widget);
159 gboolean gtkut_widget_has_grab          (GtkWidget      *widget);
160 gboolean gtkut_widget_has_focus         (GtkWidget      *widget);
161 gboolean gtkut_widget_is_drawable       (GtkWidget      *widget);
162 gboolean gtkut_widget_is_sensitive      (GtkWidget      *widget);
163 void gtkut_widget_set_mapped            (GtkWidget *widget, gboolean mapped);
164 void gtkut_widget_set_realized          (GtkWidget *widget, gboolean realized);
165 void gtkut_widget_set_can_default       (GtkWidget *widget, gboolean can_default);
166 void gtkut_widget_set_receives_default  (GtkWidget *widget, gboolean receives_default);
167 void gtkut_widget_set_can_focus         (GtkWidget *widget, gboolean can_focus);
168 void gtkut_widget_set_has_window        (GtkWidget *widget, gboolean has_window);
169
170
171 GtkWidget *gtkut_account_menu_new       (GList                  *ac_list,
172                                          GCallback               callback,
173                                          gpointer                data);
174
175 void gtkut_set_widget_bgcolor_rgb       (GtkWidget      *widget,
176                                          guint           rgbvalue);
177
178 void gtkut_widget_set_small_font_size(GtkWidget *widget);
179 GtkWidget *gtkut_get_focused_child      (GtkContainer   *parent);
180
181 GtkWidget *gtkut_get_browse_file_btn(const gchar *label);
182 GtkWidget *gtkut_get_browse_directory_btn(const gchar *label);
183 GtkWidget *gtkut_get_replace_btn(const gchar *label);
184 GtkWidget *gtkut_get_options_frame(GtkWidget *box, GtkWidget **frame, const gchar *frame_label);
185 #if HAVE_LIBCOMPFACE
186 GtkWidget *xface_get_from_header(const gchar *o_xface, GdkColor *background,
187                                  GdkWindow *window);
188 #endif
189 gboolean get_tag_range(GtkTextIter *iter,
190                                        GtkTextTag *tag,
191                                        GtkTextIter *start_iter,
192                                        GtkTextIter *end_iter);
193
194 GtkWidget *face_get_from_header(const gchar *o_face);
195 GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *label);
196
197 GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox, gboolean focus_on_click);
198 void gtkutils_scroll_one_line   (GtkWidget *widget, 
199                                  GtkAdjustment *vadj, 
200                                  gboolean up);
201 gboolean gtkutils_scroll_page   (GtkWidget *widget, 
202                                  GtkAdjustment *vadj, 
203                                  gboolean up);
204
205 gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
206                                  GtkTreeIter *iter,
207                                  const gchar* text);
208 gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
209                                  GtkTreeIter *iter);
210
211 gint gtkut_list_view_get_selected_row(GtkWidget *list_view);
212 gboolean gtkut_list_view_select_row(GtkWidget *list, gint row);
213
214 GtkUIManager *gtkut_create_ui_manager(void);
215 GtkUIManager *gtkut_ui_manager(void);
216
217 GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *pixbuf, int box_width,
218                                      int box_height);
219 gint
220 claws_input_add    (gint              source,
221                     GdkInputCondition condition,
222                     GdkInputFunction  function,
223                     gpointer          data,
224                     gboolean          is_sock);
225 #if GTK_CHECK_VERSION(2,12,0)
226 #define CLAWS_TIP_DECL() {}
227 #define CLAWS_SET_TIP(widget,tip) {                                     \
228         if (tip != NULL)                                                \
229                 gtk_widget_set_tooltip_text(GTK_WIDGET(widget), tip);   \
230         else                                                            \
231                 gtk_widget_set_has_tooltip(GTK_WIDGET(widget), FALSE);  \
232 }
233
234 #else
235 #define CLAWS_TIP_DECL() \
236         GtkTooltips *tips = gtk_tooltips_new();
237
238 #define CLAWS_SET_TIP(widget,tip) {                             \
239         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), widget,        \
240                             tip, NULL);                         \
241 }
242
243 #endif
244 #endif /* __GTKUTILS_H__ */