592e575578cf3aa72855a9658efff0c7b9adaa1b
[claws.git] / src / gtk / gtkutils.h
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2017 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 #ifndef __GTKUTILS_H__
20 #define __GTKUTILS_H__
21
22 #ifdef HAVE_CONFIG_H
23 #include "claws-features.h"
24 #endif
25
26 #include <glib.h>
27 #include <gdk/gdk.h>
28 #include <gtk/gtk.h>
29 #include <stdlib.h>
30 #if HAVE_WCHAR_H
31 #  include <wchar.h>
32 #endif
33
34 #include "gtkcmctree.h"
35
36 #ifndef GDK_KEY_Escape
37 #include "gdkkeysyms-new.h"
38 #endif
39
40 #define GTK_EVENTS_FLUSH() \
41 { \
42         while (gtk_events_pending()) \
43                 gtk_main_iteration(); \
44 }
45
46 #define GTK_WIDGET_PTR(wid)     (*(GtkWidget **)wid)
47
48 #define GTKUT_CTREE_NODE_SET_ROW_DATA(node, d) \
49 { \
50         GTK_CMCTREE_ROW(node)->row.data = d; \
51 }
52
53 #define GTKUT_CTREE_NODE_GET_ROW_DATA(node) \
54         (GTK_CMCTREE_ROW(node)->row.data)
55
56 #define GTKUT_CTREE_REFRESH(clist) \
57         GTK_CMCLIST_GET_CLASS(clist)->refresh(clist)
58
59 #define GTKUT_COLOR_BUTTON() \
60         gtk_button_new_with_label("\x20\xE2\x80\x83\x20")
61
62 gboolean gtkut_get_font_size            (GtkWidget      *widget,
63                                          gint           *width,
64                                          gint           *height);
65
66 void gtkut_convert_int_to_gdk_color     (gint            rgbvalue,
67                                          GdkColor       *color);
68 gint gtkut_convert_gdk_color_to_int     (GdkColor       *color);
69
70 void gtkut_stock_button_add_help(GtkWidget *bbox, GtkWidget **help_btn);
71
72 void gtkut_stock_button_set_create_with_help(GtkWidget **bbox,
73                 GtkWidget **help_button,
74                 GtkWidget **button1, const gchar *label1,
75                 GtkWidget **button2, const gchar *label2,
76                 GtkWidget **button3, const gchar *label3);
77
78 void gtkut_stock_button_set_create      (GtkWidget      **bbox,
79                                          GtkWidget      **button1,
80                                          const gchar     *label1,
81                                          GtkWidget      **button2,
82                                          const gchar     *label2,
83                                          GtkWidget      **button3,
84                                          const gchar     *label3);
85
86 void gtkut_stock_with_text_button_set_create(GtkWidget **bbox,
87                                    GtkWidget **button1, const gchar *label1, const gchar *text1,
88                                    GtkWidget **button2, const gchar *label2, const gchar *text2,
89                                    GtkWidget **button3, const gchar *label3, const gchar *text3);
90
91 void gtkut_ctree_node_move_if_on_the_edge
92                                         (GtkCMCTree     *ctree,
93                                          GtkCMCTreeNode *node,
94                                          gint            _row);
95 gint gtkut_ctree_get_nth_from_node      (GtkCMCTree     *ctree,
96                                          GtkCMCTreeNode *node);
97 GtkCMCTreeNode *gtkut_ctree_node_next   (GtkCMCTree     *ctree,
98                                          GtkCMCTreeNode *node);
99 GtkCMCTreeNode *gtkut_ctree_node_prev   (GtkCMCTree     *ctree,
100                                          GtkCMCTreeNode *node);
101 gboolean gtkut_ctree_node_is_selected   (GtkCMCTree     *ctree,
102                                          GtkCMCTreeNode *node);
103 GtkCMCTreeNode *gtkut_ctree_find_collapsed_parent
104                                         (GtkCMCTree     *ctree,
105                                          GtkCMCTreeNode *node);
106 void gtkut_ctree_expand_parent_all      (GtkCMCTree     *ctree,
107                                          GtkCMCTreeNode *node);
108 gboolean gtkut_ctree_node_is_parent     (GtkCMCTreeNode         *parent, 
109                                          GtkCMCTreeNode         *node);
110 void gtkut_ctree_set_focus_row          (GtkCMCTree     *ctree,
111                                          GtkCMCTreeNode *node);
112
113 void gtkut_clist_set_focus_row          (GtkCMCList     *clist,
114                                          gint            row);
115
116 void gtkut_container_remove             (GtkContainer   *container,
117                                          GtkWidget      *widget);
118
119 gchar *gtkut_text_view_get_selection    (GtkTextView    *textview);
120 void gtkut_text_view_set_position               (GtkTextView *text, gint pos);
121 gboolean gtkut_text_view_search_string  (GtkTextView *text, const gchar *str,
122                                         gboolean case_sens);
123 gboolean gtkut_text_view_search_string_backward (GtkTextView *text, const gchar *str,
124                                         gboolean case_sens);
125
126 GtkWidget *label_window_create(const gchar *str);
127 void label_window_destroy(GtkWidget *widget);
128
129 void gtkut_window_popup                 (GtkWidget      *window);
130 GtkWidget *gtkut_window_new             (GtkWindowType   type,
131                                          const gchar    *class);
132
133
134 void gtkut_widget_get_uposition         (GtkWidget      *widget,
135                                          gint           *px,
136                                          gint           *py);
137 void gtkut_widget_draw_now              (GtkWidget      *widget);
138 void gtkut_widget_init                  (void);
139
140 void gtkut_widget_set_app_icon          (GtkWidget      *widget);
141 void gtkut_widget_set_composer_icon     (GtkWidget      *widget);
142
143 GtkWidget *gtkut_account_menu_new       (GList                  *ac_list,
144                                          GCallback               callback,
145                                          gpointer                data);
146
147 void gtkut_set_widget_bgcolor_rgb       (GtkWidget      *widget,
148                                          guint           rgbvalue);
149
150 void gtkut_widget_set_small_font_size(GtkWidget *widget);
151 GtkWidget *gtkut_get_focused_child      (GtkContainer   *parent);
152
153 GtkWidget *gtkut_get_browse_file_btn(const gchar *label);
154 GtkWidget *gtkut_get_browse_directory_btn(const gchar *label);
155 GtkWidget *gtkut_get_replace_btn(const gchar *label);
156 GtkWidget *gtkut_get_options_frame(GtkWidget *box, GtkWidget **frame, const gchar *frame_label);
157 #if HAVE_LIBCOMPFACE
158 GtkWidget *xface_get_from_header(const gchar *o_xface);
159 #endif
160 gboolean get_tag_range(GtkTextIter *iter,
161                                        GtkTextTag *tag,
162                                        GtkTextIter *start_iter,
163                                        GtkTextIter *end_iter);
164
165 GtkWidget *face_get_from_header(const gchar *o_face);
166 GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *label);
167
168 GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox, gboolean focus_on_click);
169 void gtkutils_scroll_one_line   (GtkWidget *widget, 
170                                  GtkAdjustment *vadj, 
171                                  gboolean up);
172 gboolean gtkutils_scroll_page   (GtkWidget *widget, 
173                                  GtkAdjustment *vadj, 
174                                  gboolean up);
175
176 gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
177                                  GtkTreeIter *iter,
178                                  const gchar* text);
179 gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
180                                  GtkTreeIter *iter);
181
182 gint gtkut_list_view_get_selected_row(GtkWidget *list_view);
183 gboolean gtkut_list_view_select_row(GtkWidget *list, gint row);
184
185 GtkUIManager *gtkut_create_ui_manager(void);
186 GtkUIManager *gtkut_ui_manager(void);
187
188 GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *pixbuf, int box_width,
189                                      int box_height);
190
191 typedef void (*ClawsIOFunc)(gpointer data, gint source, GIOCondition condition);
192 gint
193 claws_input_add    (gint              source,
194                     GIOCondition      condition,
195                     ClawsIOFunc       function,
196                     gpointer          data,
197                     gboolean          is_sock);
198
199 #define CLAWS_SET_TIP(widget,tip) {                                             \
200         if (widget != NULL) {                                                   \
201                 if (tip != NULL)                                                \
202                         gtk_widget_set_tooltip_text(GTK_WIDGET(widget), tip);   \
203                 else                                                            \
204                         gtk_widget_set_has_tooltip(GTK_WIDGET(widget), FALSE);  \
205         }                                                                       \
206 }
207
208 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
209 typedef struct _AutoConfigureData {
210         const gchar *ssl_service;
211         const gchar *tls_service;
212         gchar *address;
213         gint resolver_error;
214
215         GtkEntry *hostname_entry;
216         GtkToggleButton *set_port;
217         GtkSpinButton *port;
218         gint default_port;
219         gint default_ssl_port;
220         GtkToggleButton *tls_checkbtn;
221         GtkToggleButton *ssl_checkbtn;
222         GtkToggleButton *auth_checkbtn;
223         GtkEntry *uid_entry;
224         GtkLabel *info_label;
225         GtkButton *configure_button;
226         GtkButton *cancel_button;
227         GCancellable *cancel;
228         GMainLoop *main_loop;
229 } AutoConfigureData;
230
231 void auto_configure_service(AutoConfigureData *data);
232 gboolean auto_configure_service_sync(const gchar *service, const gchar *domain, gchar **srvhost, guint16 *srvport);
233 #endif
234
235 /* Returns pointer stored in selected row of a tree view's model
236  * in a given column. The column has to be of type G_TYPE_POINTER
237  * or G_TYPE_STRING (in this case, the returned value has to be
238  * freed by the caller.
239  * _model, _selection and _iter parameters are optional, and if
240  * not NULL, they will be set to point to corresponding GtkTreeModel,
241  * GtkTreeSelection, and GtkTreeIter of the selected row. */
242 gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
243                 gint column, GtkTreeModel **_model, GtkTreeSelection **_selection,
244                 GtkTreeIter *_iter);
245
246 #if GTK_CHECK_VERSION (3, 2, 0)
247 #define GTK_TYPE_VBOX GTK_TYPE_BOX
248 #define GtkVBox GtkBox
249 #define GtkVBoxClass GtkBoxClass
250 #define gtk_vbox_new(hmg,spc) g_object_new (GTK_TYPE_BOX, \
251     "homogeneous", hmg, "spacing", spc, \
252     "orientation", GTK_ORIENTATION_VERTICAL, NULL)
253 #define GTK_TYPE_HBOX GTK_TYPE_BOX
254 #define GtkHBox GtkBox
255 #define GtkHBoxClass GtkBoxClass
256 #define gtk_hbox_new(hmg,spc) g_object_new (GTK_TYPE_BOX, \
257     "homogeneous", hmg, "spacing", spc, \
258     "orientation", GTK_ORIENTATION_HORIZONTAL, NULL)
259 #define gtk_hseparator_new() g_object_new (GTK_TYPE_SEPARATOR, NULL)
260 #define gtk_hpaned_new() g_object_new (GTK_TYPE_PANED, NULL)
261 #define gtk_vpaned_new() g_object_new (GTK_TYPE_PANED, \
262     "orientation", GTK_ORIENTATION_VERTICAL, NULL)
263 #endif
264
265 #endif /* __GTKUTILS_H__ */