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