talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

gtkutils.h (7639B)


      1 /*
      2  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
      3  * Copyright (C) 1999-2022 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 #include <glib.h>
     23 #include <gdk/gdk.h>
     24 #include <gtk/gtk.h>
     25 #include <stdlib.h>
     26 #include <wchar.h>
     27 
     28 #include "gtkcmctree.h"
     29 
     30 #define GTK_EVENTS_FLUSH() \
     31 { \
     32 	while (gtk_events_pending()) \
     33 		gtk_main_iteration(); \
     34 }
     35 
     36 #define GTK_WIDGET_PTR(wid)	(*(GtkWidget **)wid)
     37 
     38 #define GTKUT_CTREE_NODE_SET_ROW_DATA(node, d) \
     39 { \
     40 	GTK_CMCTREE_ROW(node)->row.data = d; \
     41 }
     42 
     43 #define GTKUT_CTREE_NODE_GET_ROW_DATA(node) \
     44 	(GTK_CMCTREE_ROW(node)->row.data)
     45 
     46 #define GTKUT_CTREE_REFRESH(clist) \
     47 	GTK_CMCLIST_GET_CLASS(clist)->refresh(clist)
     48 
     49 /* Set "color" to the same color as "rgba" */
     50 #define GTKUT_GDKRGBA_TO_GDKCOLOR(rgba, color) { \
     51 	color.pixel = 0; \
     52 	color.red   = (guint16)(rgba.red * 65535); \
     53 	color.green = (guint16)(rgba.green * 65535); \
     54 	color.blue  = (guint16)(rgba.blue * 65535); \
     55 }
     56 
     57 /* Since GDK's gdk_rgba_to_string() produces a string
     58  * representation unsuitable for us, we have to have
     59  * our own function to produce a "#rrggbb" string from
     60  * a GdkRGBA.
     61  * The returned string has to be freed by the caller. */
     62 gchar *gtkut_gdk_rgba_to_string(GdkRGBA *rgba);
     63 
     64 void gtkut_stock_button_add_help(GtkWidget *bbox, GtkWidget **help_btn);
     65 
     66 void gtkut_stock_button_set_create_with_help(GtkWidget **bbox,
     67 		GtkWidget **help_button,
     68 		GtkWidget **button1, const gchar *stock_icon1, const gchar *label1,
     69 		GtkWidget **button2, const gchar *stock_icon2, const gchar *label2,
     70 		GtkWidget **button3, const gchar *stock_icon3, const gchar *label3);
     71 
     72 void gtkut_stock_button_set_create	(GtkWidget	**bbox,
     73 					 GtkWidget	**button1,
     74 					 const gchar	 *stock_icon1,
     75 					 const gchar	 *label1,
     76 					 GtkWidget	**button2,
     77 					 const gchar	 *stock_icon2,
     78 					 const gchar	 *label2,
     79 					 GtkWidget	**button3,
     80 					 const gchar	 *stock_icon3,
     81 					 const gchar	 *label3);
     82 
     83 void gtkut_stock_with_text_button_set_create(GtkWidget **bbox,
     84 				   GtkWidget **button1, const gchar *label1, const gchar *text1,
     85 				   GtkWidget **button2, const gchar *label2, const gchar *text2,
     86 				   GtkWidget **button3, const gchar *label3, const gchar *text3);
     87 
     88 void gtkut_ctree_node_move_if_on_the_edge
     89 					(GtkCMCTree	*ctree,
     90 					 GtkCMCTreeNode	*node,
     91 					 gint		 _row);
     92 gint gtkut_ctree_get_nth_from_node	(GtkCMCTree	*ctree,
     93 					 GtkCMCTreeNode	*node);
     94 GtkCMCTreeNode *gtkut_ctree_node_next	(GtkCMCTree	*ctree,
     95 					 GtkCMCTreeNode	*node);
     96 GtkCMCTreeNode *gtkut_ctree_node_prev	(GtkCMCTree	*ctree,
     97 					 GtkCMCTreeNode	*node);
     98 gboolean gtkut_ctree_node_is_selected	(GtkCMCTree	*ctree,
     99 					 GtkCMCTreeNode	*node);
    100 GtkCMCTreeNode *gtkut_ctree_find_collapsed_parent
    101 					(GtkCMCTree	*ctree,
    102 					 GtkCMCTreeNode	*node);
    103 void gtkut_ctree_expand_parent_all	(GtkCMCTree	*ctree,
    104 					 GtkCMCTreeNode	*node);
    105 gboolean gtkut_ctree_node_is_parent	(GtkCMCTreeNode 	*parent,
    106 					 GtkCMCTreeNode 	*node);
    107 void gtkut_ctree_set_focus_row		(GtkCMCTree	*ctree,
    108 					 GtkCMCTreeNode	*node);
    109 
    110 void gtkut_clist_set_focus_row		(GtkCMCList	*clist,
    111 					 gint		 row);
    112 
    113 gchar *gtkut_text_view_get_selection	(GtkTextView	*textview);
    114 void gtkut_text_view_set_position		(GtkTextView *text, gint pos);
    115 gboolean gtkut_text_view_search_string	(GtkTextView *text, const gchar *str,
    116 					gboolean case_sens);
    117 gboolean gtkut_text_view_search_string_backward	(GtkTextView *text, const gchar *str,
    118 					gboolean case_sens);
    119 
    120 GtkWidget *label_window_create(const gchar *str);
    121 void label_window_destroy(GtkWidget *widget);
    122 
    123 void gtkut_window_popup			(GtkWidget	*window);
    124 GtkWidget *gtkut_window_new		(GtkWindowType	 type,
    125 					 const gchar	*cls);
    126 
    127 
    128 void gtkut_widget_get_uposition		(GtkWidget	*widget,
    129 					 gint		*px,
    130 					 gint		*py);
    131 void gtkut_widget_init			(void);
    132 
    133 void gtkut_widget_set_app_icon		(GtkWidget	*widget);
    134 void gtkut_widget_set_composer_icon	(GtkWidget	*widget);
    135 
    136 PangoFontDescription *default_font(void);
    137 void gtkut_widget_set_small_font_size(GtkWidget *widget);
    138 GtkWidget *gtkut_get_focused_child	(GtkContainer 	*parent);
    139 
    140 GtkWidget *gtkut_get_browse_file_btn(const gchar *label);
    141 GtkWidget *gtkut_get_browse_directory_btn(const gchar *label);
    142 GtkWidget *gtkut_get_replace_btn(const gchar *label);
    143 GtkWidget *gtkut_stock_button(const gchar *stock_image, const gchar *label);
    144 GtkWidget *gtkut_get_options_frame(GtkWidget *box, GtkWidget **frame, const gchar *frame_label);
    145 gboolean get_tag_range(GtkTextIter *iter,
    146 				       GtkTextTag *tag,
    147 				       GtkTextIter *start_iter,
    148 				       GtkTextIter *end_iter);
    149 
    150 GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox, gboolean focus_on_click);
    151 
    152 gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
    153 				 GtkTreeIter *iter,
    154 				 const gchar* text);
    155 gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
    156 				 GtkTreeIter *iter);
    157 
    158 gint gtkut_list_view_get_selected_row(GtkWidget *list_view);
    159 gboolean gtkut_list_view_select_row(GtkWidget *list, gint row);
    160 
    161 GtkUIManager *gtkut_create_ui_manager(void);
    162 GtkUIManager *gtkut_ui_manager(void);
    163 
    164 typedef void (*ClawsIOFunc)(gpointer data, gint source, GIOCondition condition);
    165 gint
    166 claws_input_add    (gint	      source,
    167 		    GIOCondition      condition,
    168 		    ClawsIOFunc       function,
    169 		    gpointer	      data,
    170 		    gboolean          is_sock);
    171 
    172 #define CLAWS_SET_TIP(widget,tip) { 						\
    173 	if (widget != NULL) {							\
    174 		if (tip != NULL)						\
    175 			gtk_widget_set_tooltip_text(GTK_WIDGET(widget), tip); 	\
    176 		else								\
    177 			gtk_widget_set_has_tooltip(GTK_WIDGET(widget), FALSE);	\
    178 	}									\
    179 }
    180 
    181 typedef struct _AutoConfigureData {
    182 	const gchar *ssl_service;
    183 	const gchar *tls_service;
    184 	gchar *address;
    185 	gint resolver_error;
    186 
    187 	GtkEntry *hostname_entry;
    188 	GtkToggleButton *set_port;
    189 	GtkSpinButton *port;
    190 	gint default_port;
    191 	gint default_ssl_port;
    192 	GtkToggleButton *tls_checkbtn;
    193 	GtkToggleButton *ssl_checkbtn;
    194 	GtkToggleButton *auth_checkbtn;
    195 	GtkEntry *uid_entry;
    196 	GtkLabel *info_label;
    197 	GtkButton *configure_button;
    198 	GtkButton *cancel_button;
    199 	GCancellable *cancel;
    200 	GMainLoop *main_loop;
    201 } AutoConfigureData;
    202 
    203 void auto_configure_service(AutoConfigureData *data);
    204 gboolean auto_configure_service_sync(const gchar *service, const gchar *domain, gchar **srvhost, guint16 *srvport);
    205 
    206 gboolean gtkut_pointer_is_grabbed(GtkWidget *widget);
    207 
    208 /* Returns pointer stored in selected row of a tree view's model
    209  * in a given column. The column has to be of type G_TYPE_POINTER
    210  * or G_TYPE_STRING (in this case, the returned value has to be
    211  * freed by the caller.
    212  * _model, _selection and _iter parameters are optional, and if
    213  * not NULL, they will be set to point to corresponding GtkTreeModel,
    214  * GtkTreeSelection, and GtkTreeIter of the selected row. */
    215 gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
    216 		gint column, GtkTreeModel **_model, GtkTreeSelection **_selection,
    217 		GtkTreeIter *_iter);
    218 
    219 void gtkut_gdk_screen_size_changed (GdkScreen* self, gpointer data);
    220 #endif /* __GTKUTILS_H__ */