1 /* 2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client 3 * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto 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, gboolean inline_img, 185 gboolean fit_img_height, 186 int box_width, int box_height); 187 188 GtkWidget *gtkut_time_select_combo_new(); 189 void gtkut_time_select_select_by_time(GtkComboBox *combo, int hour, int minute); 190 gboolean gtkut_time_select_get_time(GtkComboBox *combo, int *hour, int *minute); 191 192 void gtk_calendar_select_today(GtkCalendar *calendar); 193 194 typedef void (*ClawsIOFunc)(gpointer data, gint source, GIOCondition condition); 195 gint 196 claws_input_add (gint source, 197 GIOCondition condition, 198 ClawsIOFunc function, 199 gpointer data, 200 gboolean is_sock); 201 202 #define CLAWS_SET_TIP(widget,tip) { \ 203 if (widget != NULL) { \ 204 if (tip != NULL) \ 205 gtk_widget_set_tooltip_text(GTK_WIDGET(widget), tip); \ 206 else \ 207 gtk_widget_set_has_tooltip(GTK_WIDGET(widget), FALSE); \ 208 } \ 209 } 210 211 #if defined USE_GNUTLS 212 typedef struct _AutoConfigureData { 213 const gchar *ssl_service; 214 const gchar *tls_service; 215 gchar *address; 216 gint resolver_error; 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 GtkToggleButton *auth_checkbtn; 226 GtkEntry *uid_entry; 227 GtkLabel *info_label; 228 GtkButton *configure_button; 229 GtkButton *cancel_button; 230 GCancellable *cancel; 231 GMainLoop *main_loop; 232 } AutoConfigureData; 233 234 void auto_configure_service(AutoConfigureData *data); 235 gboolean auto_configure_service_sync(const gchar *service, const gchar *domain, gchar **srvhost, guint16 *srvport); 236 #endif 237 238 /* Returns pointer stored in selected row of a tree view's model 239 * in a given column. The column has to be of type G_TYPE_POINTER 240 * or G_TYPE_STRING (in this case, the returned value has to be 241 * freed by the caller. 242 * _model, _selection and _iter parameters are optional, and if 243 * not NULL, they will be set to point to corresponding GtkTreeModel, 244 * GtkTreeSelection, and GtkTreeIter of the selected row. */ 245 gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view, 246 gint column, GtkTreeModel **_model, GtkTreeSelection **_selection, 247 GtkTreeIter *_iter); 248 249 #if GTK_CHECK_VERSION (3, 2, 0) 250 #define GTK_TYPE_VBOX GTK_TYPE_BOX 251 #define GtkVBox GtkBox 252 #define GtkVBoxClass GtkBoxClass 253 #define gtk_vbox_new(hmg,spc) g_object_new (GTK_TYPE_BOX, \ 254 "homogeneous", hmg, "spacing", spc, \ 255 "orientation", GTK_ORIENTATION_VERTICAL, NULL) 256 #define GTK_TYPE_HBOX GTK_TYPE_BOX 257 #define GtkHBox GtkBox 258 #define GtkHBoxClass GtkBoxClass 259 #define gtk_hbox_new(hmg,spc) g_object_new (GTK_TYPE_BOX, \ 260 "homogeneous", hmg, "spacing", spc, \ 261 "orientation", GTK_ORIENTATION_HORIZONTAL, NULL) 262 #define gtk_hseparator_new() g_object_new (GTK_TYPE_SEPARATOR, NULL) 263 #define gtk_hpaned_new() g_object_new (GTK_TYPE_PANED, NULL) 264 #define gtk_vpaned_new() g_object_new (GTK_TYPE_PANED, \ 265 "orientation", GTK_ORIENTATION_VERTICAL, NULL) 266 #endif 267 268 #endif /* __GTKUTILS_H__ */ 269