fix bug 4773, 'remove obsolescent AC_C_CONST'
[claws.git] / src / gtk / gtkutils.h
blob4a53ab7276733552855dcc0f16328181e685829e
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
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.
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.
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/>.
19 #ifndef __GTKUTILS_H__
20 #define __GTKUTILS_H__
22 #ifdef HAVE_CONFIG_H
23 #include "claws-features.h"
24 #endif
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
34 #include "gtkcmctree.h"
36 #define GTK_EVENTS_FLUSH() \
37 { \
38 while (gtk_events_pending()) \
39 gtk_main_iteration(); \
42 #define GTK_WIDGET_PTR(wid) (*(GtkWidget **)wid)
44 #define GTKUT_CTREE_NODE_SET_ROW_DATA(node, d) \
45 { \
46 GTK_CMCTREE_ROW(node)->row.data = d; \
49 #define GTKUT_CTREE_NODE_GET_ROW_DATA(node) \
50 (GTK_CMCTREE_ROW(node)->row.data)
52 #define GTKUT_CTREE_REFRESH(clist) \
53 GTK_CMCLIST_GET_CLASS(clist)->refresh(clist)
55 /* String used in color button labels.
56 * Instead of hardcoding a size which doesn't look the same on different
57 * resolutions, use a space;m-space;space label and let GTK to compute
58 * the appropriate button size for current font.
59 * This macro is only used in gtkut_set_button_color(). */
60 #define GTKUT_COLOR_BUTTON_LABEL "\x20\xE2\x80\x83\x20"
62 /* Set "color" to the same color as "rgba" */
63 #define GTKUT_GDKRGBA_TO_GDKCOLOR(rgba, color) { \
64 color.pixel = 0; \
65 color.red = (guint16)(rgba.red * 65535); \
66 color.green = (guint16)(rgba.green * 65535); \
67 color.blue = (guint16)(rgba.blue * 65535); \
70 /* Set "rgba" to the same color as "color" */
71 #define GTKUT_GDKCOLOR_TO_GDKRGBA(color, rgba) { \
72 rgba.red = (gdouble)color.red / 65535; \
73 rgba.green = (gdouble)color.green / 65535; \
74 rgba.blue = (gdouble)color.blue / 65535; \
75 rgba.alpha = 1.0; \
78 /* Since GDK's gdk_rgba_to_string() produces a string
79 * representation unsuitable for us, we have to have
80 * our own function to produce a "#rrggbb" string from
81 * a GdkRGBA.
82 * The returned string has to be freed by the caller. */
83 gchar *gtkut_gdk_rgba_to_string(GdkRGBA *rgba);
85 gboolean gtkut_get_font_size (GtkWidget *widget,
86 gint *width,
87 gint *height);
89 void gtkut_stock_button_add_help(GtkWidget *bbox, GtkWidget **help_btn);
91 void gtkut_stock_button_set_create_with_help(GtkWidget **bbox,
92 GtkWidget **help_button,
93 GtkWidget **button1, const gchar *stock_icon1, const gchar *label1,
94 GtkWidget **button2, const gchar *stock_icon2, const gchar *label2,
95 GtkWidget **button3, const gchar *stock_icon3, const gchar *label3);
97 void gtkut_stock_button_set_create (GtkWidget **bbox,
98 GtkWidget **button1,
99 const gchar *stock_icon1,
100 const gchar *label1,
101 GtkWidget **button2,
102 const gchar *stock_icon2,
103 const gchar *label2,
104 GtkWidget **button3,
105 const gchar *stock_icon3,
106 const gchar *label3);
108 void gtkut_stock_with_text_button_set_create(GtkWidget **bbox,
109 GtkWidget **button1, const gchar *label1, const gchar *text1,
110 GtkWidget **button2, const gchar *label2, const gchar *text2,
111 GtkWidget **button3, const gchar *label3, const gchar *text3);
113 void gtkut_ctree_node_move_if_on_the_edge
114 (GtkCMCTree *ctree,
115 GtkCMCTreeNode *node,
116 gint _row);
117 gint gtkut_ctree_get_nth_from_node (GtkCMCTree *ctree,
118 GtkCMCTreeNode *node);
119 GtkCMCTreeNode *gtkut_ctree_node_next (GtkCMCTree *ctree,
120 GtkCMCTreeNode *node);
121 GtkCMCTreeNode *gtkut_ctree_node_prev (GtkCMCTree *ctree,
122 GtkCMCTreeNode *node);
123 gboolean gtkut_ctree_node_is_selected (GtkCMCTree *ctree,
124 GtkCMCTreeNode *node);
125 GtkCMCTreeNode *gtkut_ctree_find_collapsed_parent
126 (GtkCMCTree *ctree,
127 GtkCMCTreeNode *node);
128 void gtkut_ctree_expand_parent_all (GtkCMCTree *ctree,
129 GtkCMCTreeNode *node);
130 gboolean gtkut_ctree_node_is_parent (GtkCMCTreeNode *parent,
131 GtkCMCTreeNode *node);
132 void gtkut_ctree_set_focus_row (GtkCMCTree *ctree,
133 GtkCMCTreeNode *node);
135 void gtkut_clist_set_focus_row (GtkCMCList *clist,
136 gint row);
138 gchar *gtkut_text_view_get_selection (GtkTextView *textview);
139 void gtkut_text_view_set_position (GtkTextView *text, gint pos);
140 gboolean gtkut_text_view_search_string (GtkTextView *text, const gchar *str,
141 gboolean case_sens);
142 gboolean gtkut_text_view_search_string_backward (GtkTextView *text, const gchar *str,
143 gboolean case_sens);
145 GtkWidget *label_window_create(const gchar *str);
146 void label_window_destroy(GtkWidget *widget);
148 void gtkut_window_popup (GtkWidget *window);
149 GtkWidget *gtkut_window_new (GtkWindowType type,
150 const gchar *class);
153 void gtkut_widget_get_uposition (GtkWidget *widget,
154 gint *px,
155 gint *py);
156 void gtkut_widget_init (void);
158 void gtkut_widget_set_app_icon (GtkWidget *widget);
159 void gtkut_widget_set_composer_icon (GtkWidget *widget);
161 GtkWidget *gtkut_account_menu_new (GList *ac_list,
162 GCallback callback,
163 gpointer data);
165 void gtkut_widget_set_small_font_size(GtkWidget *widget);
166 GtkWidget *gtkut_get_focused_child (GtkContainer *parent);
168 GtkWidget *gtkut_get_browse_file_btn(const gchar *label);
169 GtkWidget *gtkut_get_browse_directory_btn(const gchar *label);
170 GtkWidget *gtkut_get_replace_btn(const gchar *label);
171 GtkWidget *gtkut_stock_button(const gchar *stock_image, const gchar *label);
172 GtkWidget *gtkut_get_options_frame(GtkWidget *box, GtkWidget **frame, const gchar *frame_label);
173 #if HAVE_LIBCOMPFACE
174 GtkWidget *xface_get_from_header(const gchar *o_xface);
175 #endif
176 gboolean get_tag_range(GtkTextIter *iter,
177 GtkTextTag *tag,
178 GtkTextIter *start_iter,
179 GtkTextIter *end_iter);
181 GtkWidget *face_get_from_header(const gchar *o_face);
183 GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox, gboolean focus_on_click);
184 void gtkutils_scroll_one_line (GtkWidget *widget,
185 GtkAdjustment *vadj,
186 gboolean up);
187 gboolean gtkutils_scroll_page (GtkWidget *widget,
188 GtkAdjustment *vadj,
189 gboolean up);
191 gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
192 GtkTreeIter *iter,
193 const gchar* text);
194 gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
195 GtkTreeIter *iter);
197 gint gtkut_list_view_get_selected_row(GtkWidget *list_view);
198 gboolean gtkut_list_view_select_row(GtkWidget *list, gint row);
200 GtkUIManager *gtkut_create_ui_manager(void);
201 GtkUIManager *gtkut_ui_manager(void);
203 GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *pixbuf, gboolean inline_img,
204 gboolean fit_img_height,
205 int box_width, int box_height);
207 GtkWidget *gtkut_time_select_combo_new();
208 void gtkut_time_select_select_by_time(GtkComboBox *combo, int hour, int minute);
209 gboolean gtkut_time_select_get_time(GtkComboBox *combo, int *hour, int *minute);
211 void gtk_calendar_select_today(GtkCalendar *calendar);
213 typedef void (*ClawsIOFunc)(gpointer data, gint source, GIOCondition condition);
214 gint
215 claws_input_add (gint source,
216 GIOCondition condition,
217 ClawsIOFunc function,
218 gpointer data,
219 gboolean is_sock);
221 #define CLAWS_SET_TIP(widget,tip) { \
222 if (widget != NULL) { \
223 if (tip != NULL) \
224 gtk_widget_set_tooltip_text(GTK_WIDGET(widget), tip); \
225 else \
226 gtk_widget_set_has_tooltip(GTK_WIDGET(widget), FALSE); \
230 #if defined USE_GNUTLS
231 typedef struct _AutoConfigureData {
232 const gchar *ssl_service;
233 const gchar *tls_service;
234 gchar *address;
235 gint resolver_error;
237 GtkEntry *hostname_entry;
238 GtkToggleButton *set_port;
239 GtkSpinButton *port;
240 gint default_port;
241 gint default_ssl_port;
242 GtkToggleButton *tls_checkbtn;
243 GtkToggleButton *ssl_checkbtn;
244 GtkToggleButton *auth_checkbtn;
245 GtkEntry *uid_entry;
246 GtkLabel *info_label;
247 GtkButton *configure_button;
248 GtkButton *cancel_button;
249 GCancellable *cancel;
250 GMainLoop *main_loop;
251 } AutoConfigureData;
253 void auto_configure_service(AutoConfigureData *data);
254 gboolean auto_configure_service_sync(const gchar *service, const gchar *domain, gchar **srvhost, guint16 *srvport);
255 #endif
257 gboolean gtkut_pointer_is_grabbed(GtkWidget *widget);
259 /* Returns pointer stored in selected row of a tree view's model
260 * in a given column. The column has to be of type G_TYPE_POINTER
261 * or G_TYPE_STRING (in this case, the returned value has to be
262 * freed by the caller.
263 * _model, _selection and _iter parameters are optional, and if
264 * not NULL, they will be set to point to corresponding GtkTreeModel,
265 * GtkTreeSelection, and GtkTreeIter of the selected row. */
266 gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
267 gint column, GtkTreeModel **_model, GtkTreeSelection **_selection,
268 GtkTreeIter *_iter);
270 #endif /* __GTKUTILS_H__ */