43649a248581a1deb8ff66e99f3d9d6c6b9fa7e4
[claws.git] / src / gtk / gtkutils.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2013 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 "claws-features.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 #include "gtkcmctree.h"
36
37 #ifndef GDK_KEY_Escape
38 #include "gdkkeysyms-new.h"
39 #endif
40
41 #define GTK_EVENTS_FLUSH() \
42 { \
43         while (gtk_events_pending()) \
44                 gtk_main_iteration(); \
45 }
46
47 #define GTK_WIDGET_PTR(wid)     (*(GtkWidget **)wid)
48
49 #define GTKUT_CTREE_NODE_SET_ROW_DATA(node, d) \
50 { \
51         GTK_CMCTREE_ROW(node)->row.data = d; \
52 }
53
54 #define GTKUT_CTREE_NODE_GET_ROW_DATA(node) \
55         (GTK_CMCTREE_ROW(node)->row.data)
56
57 #define GTKUT_CTREE_REFRESH(clist) \
58         GTK_CMCLIST_GET_CLASS(clist)->refresh(clist)
59
60 gboolean gtkut_get_font_size            (GtkWidget      *widget,
61                                          gint           *width,
62                                          gint           *height);
63
64 void gtkut_convert_int_to_gdk_color     (gint            rgbvalue,
65                                          GdkColor       *color);
66 gint gtkut_convert_gdk_color_to_int     (GdkColor       *color);
67
68 void gtkut_stock_button_add_help(GtkWidget *bbox, GtkWidget **help_btn);
69
70 void gtkut_stock_button_set_create_with_help(GtkWidget **bbox,
71                 GtkWidget **help_button,
72                 GtkWidget **button1, const gchar *label1,
73                 GtkWidget **button2, const gchar *label2,
74                 GtkWidget **button3, const gchar *label3);
75
76 void gtkut_stock_button_set_create      (GtkWidget      **bbox,
77                                          GtkWidget      **button1,
78                                          const gchar     *label1,
79                                          GtkWidget      **button2,
80                                          const gchar     *label2,
81                                          GtkWidget      **button3,
82                                          const gchar     *label3);
83
84 void gtkut_stock_with_text_button_set_create(GtkWidget **bbox,
85                                    GtkWidget **button1, const gchar *label1, const gchar *text1,
86                                    GtkWidget **button2, const gchar *label2, const gchar *text2,
87                                    GtkWidget **button3, const gchar *label3, const gchar *text3);
88
89 void gtkut_ctree_node_move_if_on_the_edge
90                                         (GtkCMCTree     *ctree,
91                                          GtkCMCTreeNode *node,
92                                          gint            _row);
93 gint gtkut_ctree_get_nth_from_node      (GtkCMCTree     *ctree,
94                                          GtkCMCTreeNode *node);
95 GtkCMCTreeNode *gtkut_ctree_node_next   (GtkCMCTree     *ctree,
96                                          GtkCMCTreeNode *node);
97 GtkCMCTreeNode *gtkut_ctree_node_prev   (GtkCMCTree     *ctree,
98                                          GtkCMCTreeNode *node);
99 gboolean gtkut_ctree_node_is_selected   (GtkCMCTree     *ctree,
100                                          GtkCMCTreeNode *node);
101 GtkCMCTreeNode *gtkut_ctree_find_collapsed_parent
102                                         (GtkCMCTree     *ctree,
103                                          GtkCMCTreeNode *node);
104 void gtkut_ctree_expand_parent_all      (GtkCMCTree     *ctree,
105                                          GtkCMCTreeNode *node);
106 gboolean gtkut_ctree_node_is_parent     (GtkCMCTreeNode         *parent, 
107                                          GtkCMCTreeNode         *node);
108 void gtkut_ctree_set_focus_row          (GtkCMCTree     *ctree,
109                                          GtkCMCTreeNode *node);
110
111 void gtkut_clist_set_focus_row          (GtkCMCList     *clist,
112                                          gint            row);
113
114 void gtkut_container_remove             (GtkContainer   *container,
115                                          GtkWidget      *widget);
116
117 gchar *gtkut_text_view_get_selection    (GtkTextView    *textview);
118 void gtkut_text_view_set_position               (GtkTextView *text, gint pos);
119 gboolean gtkut_text_view_search_string  (GtkTextView *text, const gchar *str,
120                                         gboolean case_sens);
121 gboolean gtkut_text_view_search_string_backward (GtkTextView *text, const gchar *str,
122                                         gboolean case_sens);
123
124 GtkWidget *label_window_create(const gchar *str);
125 void label_window_destroy(GtkWidget *widget);
126
127 void gtkut_window_popup                 (GtkWidget      *window);
128 GtkWidget *gtkut_window_new             (GtkWindowType   type,
129                                          const gchar    *class);
130
131
132 void gtkut_widget_get_uposition         (GtkWidget      *widget,
133                                          gint           *px,
134                                          gint           *py);
135 void gtkut_widget_draw_now              (GtkWidget      *widget);
136 void gtkut_widget_init                  (void);
137
138 void gtkut_widget_set_app_icon          (GtkWidget      *widget);
139 void gtkut_widget_set_composer_icon     (GtkWidget      *widget);
140
141 void gtkut_widget_set_mapped            (GtkWidget *widget, gboolean mapped);
142 void gtkut_widget_set_realized          (GtkWidget *widget, gboolean realized);
143 void gtkut_widget_set_can_default       (GtkWidget *widget, gboolean can_default);
144 void gtkut_widget_set_receives_default  (GtkWidget *widget, gboolean receives_default);
145 void gtkut_widget_set_can_focus         (GtkWidget *widget, gboolean can_focus);
146 void gtkut_widget_set_has_window        (GtkWidget *widget, gboolean has_window);
147
148
149 GtkWidget *gtkut_account_menu_new       (GList                  *ac_list,
150                                          GCallback               callback,
151                                          gpointer                data);
152
153 void gtkut_set_widget_bgcolor_rgb       (GtkWidget      *widget,
154                                          guint           rgbvalue);
155
156 void gtkut_widget_set_small_font_size(GtkWidget *widget);
157 GtkWidget *gtkut_get_focused_child      (GtkContainer   *parent);
158
159 GtkWidget *gtkut_get_browse_file_btn(const gchar *label);
160 GtkWidget *gtkut_get_browse_directory_btn(const gchar *label);
161 GtkWidget *gtkut_get_replace_btn(const gchar *label);
162 GtkWidget *gtkut_get_options_frame(GtkWidget *box, GtkWidget **frame, const gchar *frame_label);
163 #if HAVE_LIBCOMPFACE
164 GtkWidget *xface_get_from_header(const gchar *o_xface);
165 #endif
166 gboolean get_tag_range(GtkTextIter *iter,
167                                        GtkTextTag *tag,
168                                        GtkTextIter *start_iter,
169                                        GtkTextIter *end_iter);
170
171 GtkWidget *face_get_from_header(const gchar *o_face);
172 GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *label);
173
174 GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox, gboolean focus_on_click);
175 void gtkutils_scroll_one_line   (GtkWidget *widget, 
176                                  GtkAdjustment *vadj, 
177                                  gboolean up);
178 gboolean gtkutils_scroll_page   (GtkWidget *widget, 
179                                  GtkAdjustment *vadj, 
180                                  gboolean up);
181
182 gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
183                                  GtkTreeIter *iter,
184                                  const gchar* text);
185 gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
186                                  GtkTreeIter *iter);
187
188 gint gtkut_list_view_get_selected_row(GtkWidget *list_view);
189 gboolean gtkut_list_view_select_row(GtkWidget *list, gint row);
190
191 GtkUIManager *gtkut_create_ui_manager(void);
192 GtkUIManager *gtkut_ui_manager(void);
193
194 GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *pixbuf, int box_width,
195                                      int box_height);
196
197 typedef void (*ClawsIOFunc)(gpointer data, gint source, GIOCondition condition);
198 gint
199 claws_input_add    (gint              source,
200                     GIOCondition      condition,
201                     ClawsIOFunc       function,
202                     gpointer          data,
203                     gboolean          is_sock);
204
205 #define CLAWS_SET_TIP(widget,tip) {                                     \
206         if (tip != NULL)                                                \
207                 gtk_widget_set_tooltip_text(GTK_WIDGET(widget), tip);   \
208         else                                                            \
209                 gtk_widget_set_has_tooltip(GTK_WIDGET(widget), FALSE);  \
210 }
211
212 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
213 typedef struct _AutoConfigureData {
214         const gchar *ssl_service;
215         const gchar *tls_service;
216         gchar *domain;
217
218         GtkEntry *hostname_entry;
219         GtkToggleButton *set_port;
220         GtkSpinButton *port;
221         gint default_port;
222         gint default_ssl_port;
223         GtkToggleButton *tls_checkbtn;
224         GtkToggleButton *ssl_checkbtn;
225         GtkLabel *info_label;
226         GtkButton *configure_button;
227         GtkButton *cancel_button;
228         GCancellable *cancel;
229         GMainLoop *main_loop;
230 } AutoConfigureData;
231
232 void auto_configure_service(AutoConfigureData *data);
233 #endif
234
235
236 #if GTK_CHECK_VERSION (3, 2, 0)
237 #define GTK_TYPE_VBOX GTK_TYPE_BOX
238 #define GtkVBox GtkBox
239 #define GtkVBoxClass GtkBoxClass
240 #define gtk_vbox_new(hmg,spc) g_object_new (GTK_TYPE_BOX, \
241     "homogeneous", hmg, "spacing", spc, \
242     "orientation", GTK_ORIENTATION_VERTICAL, NULL)
243 #define GTK_TYPE_HBOX GTK_TYPE_BOX
244 #define GtkHBox GtkBox
245 #define GtkHBoxClass GtkBoxClass
246 #define gtk_hbox_new(hmg,spc) g_object_new (GTK_TYPE_BOX, \
247     "homogeneous", hmg, "spacing", spc, \
248     "orientation", GTK_ORIENTATION_HORIZONTAL, NULL)
249 #define gtk_hseparator_new() g_object_new (GTK_TYPE_SEPARATOR, NULL)
250 #define gtk_hpaned_new() g_object_new (GTK_TYPE_PANED, NULL)
251 #define gtk_vpaned_new() g_object_new (GTK_TYPE_PANED, \
252     "orientation", GTK_ORIENTATION_VERTICAL, NULL)
253 #endif
254 #if !GTK_CHECK_VERSION(2,22,0)
255 #define gdk_drag_context_get_selected_action(x) ((x)->action)
256 #define gdk_drag_context_get_actions(x) ((x)->actions)
257 #define gtk_text_view_get_vadjustment(x) ((x)->vadjustment)
258 #define gdk_drag_context_get_suggested_action(x) ((x)->suggested_action)
259 #define gtk_button_get_event_window(x) ((x)->event_window)
260 #endif
261 #if !GTK_CHECK_VERSION(2,20,0)
262 #define gtk_widget_get_requisition(x,r) (*(r) = (x)->requisition)
263 #define gtk_statusbar_get_message_area(x) ((x)->label)
264 #define gtk_widget_get_realized(x) (GTK_WIDGET_REALIZED(x))
265 #define gtk_widget_get_mapped(x) (GTK_WIDGET_MAPPED(x))
266 #endif
267 #if !GTK_CHECK_VERSION(2,18,0)
268 #define gtk_widget_get_allocation(x,a) (*(a) = (x)->allocation)
269 #define gtk_widget_set_allocation(x,a) ((x)->allocation = *(a))
270 #define gtk_widget_has_focus(x) (GTK_WIDGET_HAS_FOCUS(x))
271 #define gtk_widget_get_can_focus(x) (GTK_WIDGET_CAN_FOCUS(x))
272 #define gtk_widget_has_grab(x) (GTK_WIDGET_HAS_GRAB(x))
273 #define gtk_widget_get_visible(x) (GTK_WIDGET_VISIBLE(x))
274 #define gtk_widget_get_realized(x) (GTK_WIDGET_REALIZED(x))
275 #define gtk_widget_is_sensitive(x) (GTK_WIDGET_IS_SENSITIVE(x))
276 #define gtk_widget_get_sensitive(x) (GTK_WIDGET_SENSITIVE(x))
277 #define gtk_widget_is_drawable(x) (GTK_WIDGET_DRAWABLE(x))
278 #define gtk_widget_get_state(x) (GTK_WIDGET_STATE(x))
279 #define gtk_widget_get_mapped(x) (GTK_WIDGET_MAPPED(x))
280 #define gtk_widget_get_has_window(x) (!(GTK_WIDGET_NO_WINDOW(x)))
281 #define gtk_widget_get_app_paintable(x) (GTK_WIDGET_APP_PAINTABLE(x))
282 #define gtk_widget_set_window(x,w) {                    \
283         if ((x)->window != w) {                         \
284                 (x)->window = w;                        \
285                 g_object_notify (G_OBJECT(x), "window");\
286         }                                               \
287 }
288 #endif
289 #endif /* __GTKUTILS_H__ */