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