2008-11-05 [colin] 3.6.1cvs18
[claws.git] / src / gtk / gtkutils.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 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
20 #ifndef __GTKUTILS_H__
21 #define __GTKUTILS_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <glib.h>
28 #include <gdk/gdk.h>
29 #include <gtk/gtk.h>
30 #include <stdlib.h>
31 #if HAVE_WCHAR_H
32 #  include <wchar.h>
33 #endif
34
35 #ifdef MAEMO
36 #ifdef CHINOOK
37 #include <hildon/hildon-program.h>
38 #else
39 #include <hildon-widgets/hildon-program.h>
40 #include <hildon-widgets/hildon-window.h>
41 #endif
42 #include "main.h"
43 #endif
44
45 #include "gtkcmctree.h"
46
47 #define GTK_EVENTS_FLUSH() \
48 { \
49         while (gtk_events_pending()) \
50                 gtk_main_iteration(); \
51 }
52
53 #define PIXMAP_CREATE(widget, pixmap, mask, xpm_d) \
54 { \
55         if (!pixmap) { \
56                 GtkStyle *style = gtk_widget_get_style(widget); \
57                 pixmap = gdk_pixmap_create_from_xpm_d \
58                         (widget->window, &mask, \
59                          &style->bg[GTK_STATE_NORMAL], xpm_d); \
60         } \
61 }
62
63 #define PIXMAP_CREATE_FROM_FILE(widget, pixmap, mask, filename) \
64 { \
65         if (!pixmap) { \
66                 GtkStyle *style = gtk_widget_get_style(widget); \
67                 pixmap = gdk_pixmap_create_from_xpm \
68                         (widget->window, &mask, \
69                          &style->bg[GTK_STATE_NORMAL], filename); \
70         } \
71 }
72
73 #define GTK_WIDGET_PTR(wid)     (*(GtkWidget **)wid)
74
75 #define GTKUT_CTREE_NODE_SET_ROW_DATA(node, d) \
76 { \
77         GTK_CMCTREE_ROW(node)->row.data = d; \
78 }
79
80 #define GTKUT_CTREE_NODE_GET_ROW_DATA(node) \
81         (GTK_CMCTREE_ROW(node)->row.data)
82
83 #define GTKUT_CTREE_REFRESH(clist) \
84         GTK_CMCLIST_GET_CLASS(clist)->refresh(clist)
85
86 gboolean gtkut_get_font_size            (GtkWidget      *widget,
87                                          gint           *width,
88                                          gint           *height);
89
90 void gtkut_convert_int_to_gdk_color     (gint            rgbvalue,
91                                          GdkColor       *color);
92 gint gtkut_convert_gdk_color_to_int     (GdkColor       *color);
93
94 void gtkut_stock_button_add_help(GtkWidget *bbox, GtkWidget **help_btn);
95
96 void gtkut_stock_button_set_create_with_help(GtkWidget **bbox,
97                 GtkWidget **help_button,
98                 GtkWidget **button1, const gchar *label1,
99                 GtkWidget **button2, const gchar *label2,
100                 GtkWidget **button3, const gchar *label3);
101
102 void gtkut_stock_button_set_create      (GtkWidget      **bbox,
103                                          GtkWidget      **button1,
104                                          const gchar     *label1,
105                                          GtkWidget      **button2,
106                                          const gchar     *label2,
107                                          GtkWidget      **button3,
108                                          const gchar     *label3);
109
110 void gtkut_stock_with_text_button_set_create(GtkWidget **bbox,
111                                    GtkWidget **button1, const gchar *label1, const gchar *text1,
112                                    GtkWidget **button2, const gchar *label2, const gchar *text2,
113                                    GtkWidget **button3, const gchar *label3, const gchar *text3);
114
115 void gtkut_ctree_node_move_if_on_the_edge
116                                         (GtkCMCTree     *ctree,
117                                          GtkCMCTreeNode *node,
118                                          gint            _row);
119 gint gtkut_ctree_get_nth_from_node      (GtkCMCTree     *ctree,
120                                          GtkCMCTreeNode *node);
121 GtkCMCTreeNode *gtkut_ctree_node_next   (GtkCMCTree     *ctree,
122                                          GtkCMCTreeNode *node);
123 GtkCMCTreeNode *gtkut_ctree_node_prev   (GtkCMCTree     *ctree,
124                                          GtkCMCTreeNode *node);
125 gboolean gtkut_ctree_node_is_selected   (GtkCMCTree     *ctree,
126                                          GtkCMCTreeNode *node);
127 GtkCMCTreeNode *gtkut_ctree_find_collapsed_parent
128                                         (GtkCMCTree     *ctree,
129                                          GtkCMCTreeNode *node);
130 void gtkut_ctree_expand_parent_all      (GtkCMCTree     *ctree,
131                                          GtkCMCTreeNode *node);
132 gboolean gtkut_ctree_node_is_parent     (GtkCMCTreeNode         *parent, 
133                                          GtkCMCTreeNode         *node);
134 void gtkut_ctree_set_focus_row          (GtkCMCTree     *ctree,
135                                          GtkCMCTreeNode *node);
136
137 void gtkut_clist_set_focus_row          (GtkCMCList     *clist,
138                                          gint            row);
139
140 void gtkut_container_remove             (GtkContainer   *container,
141                                          GtkWidget      *widget);
142
143 gchar *gtkut_text_view_get_selection    (GtkTextView    *textview);
144 void gtkut_text_view_set_position               (GtkTextView *text, gint pos);
145 gboolean gtkut_text_view_search_string  (GtkTextView *text, const gchar *str,
146                                         gboolean case_sens);
147 gboolean gtkut_text_view_search_string_backward (GtkTextView *text, const gchar *str,
148                                         gboolean case_sens);
149
150 GtkWidget *label_window_create(const gchar *str);
151 void label_window_destroy(GtkWidget *widget);
152
153 void gtkut_window_popup                 (GtkWidget      *window);
154 GtkWidget *gtkut_window_new             (GtkWindowType   type,
155                                          const gchar    *class);
156
157
158 void gtkut_widget_get_uposition         (GtkWidget      *widget,
159                                          gint           *px,
160                                          gint           *py);
161 void gtkut_widget_draw_now              (GtkWidget      *widget);
162 void gtkut_widget_init                  (void);
163
164 void gtkut_widget_set_app_icon          (GtkWidget      *widget);
165 void gtkut_widget_set_composer_icon     (GtkWidget      *widget);
166
167 GtkWidget *gtkut_account_menu_new       (GList                  *ac_list,
168                                          GCallback               callback,
169                                          gpointer                data);
170
171 void gtkut_set_widget_bgcolor_rgb       (GtkWidget      *widget,
172                                          guint           rgbvalue);
173
174 void gtkut_widget_set_small_font_size(GtkWidget *widget);
175 GtkWidget *gtkut_get_focused_child      (GtkContainer   *parent);
176
177 GtkWidget *gtkut_get_browse_file_btn(const gchar *label);
178 GtkWidget *gtkut_get_browse_directory_btn(const gchar *label);
179 GtkWidget *gtkut_get_replace_btn(const gchar *label);
180 GtkWidget *gtkut_get_options_frame(GtkWidget *box, GtkWidget **frame, const gchar *frame_label);
181 #if HAVE_LIBCOMPFACE
182 GtkWidget *xface_get_from_header(const gchar *o_xface, GdkColor *background,
183                                  GdkWindow *window);
184 #endif
185 gboolean get_tag_range(GtkTextIter *iter,
186                                        GtkTextTag *tag,
187                                        GtkTextIter *start_iter,
188                                        GtkTextIter *end_iter);
189
190 GtkWidget *face_get_from_header(const gchar *o_face);
191 GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *label);
192
193 GtkWidget *gtkut_sc_combobox_create(GtkWidget *eventbox, gboolean focus_on_click);
194 void gtkutils_scroll_one_line   (GtkWidget *widget, 
195                                  GtkAdjustment *vadj, 
196                                  gboolean up);
197 gboolean gtkutils_scroll_page   (GtkWidget *widget, 
198                                  GtkAdjustment *vadj, 
199                                  gboolean up);
200
201 gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
202                                  GtkTreeIter *iter,
203                                  const gchar* text);
204 gboolean gtkut_tree_model_get_iter_last(GtkTreeModel *model,
205                                  GtkTreeIter *iter);
206
207 gint gtkut_list_view_get_selected_row(GtkWidget *list_view);
208 gboolean gtkut_list_view_select_row(GtkWidget *list, gint row);
209
210 GtkUIManager *gtkut_create_ui_manager(void);
211 GtkUIManager *gtkut_ui_manager(void);
212
213 gint
214 claws_input_add    (gint              source,
215                     GdkInputCondition condition,
216                     GdkInputFunction  function,
217                     gpointer          data,
218                     gboolean          is_sock);
219 #if GTK_CHECK_VERSION(2,12,0)
220 #define CLAWS_TIP_DECL() {}
221 #define CLAWS_SET_TIP(widget,tip) {                                     \
222         if (tip != NULL)                                                \
223                 gtk_widget_set_tooltip_text(GTK_WIDGET(widget), tip);   \
224         else                                                            \
225                 gtk_widget_set_has_tooltip(GTK_WIDGET(widget), FALSE);  \
226 }
227
228 #else
229 #define CLAWS_TIP_DECL() \
230         GtkTooltips *tips = gtk_tooltips_new();
231
232 #define CLAWS_SET_TIP(widget,tip) {                             \
233         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), widget,        \
234                             tip, NULL);                         \
235 }
236
237 #endif
238 #endif /* __GTKUTILS_H__ */