05ed4c2ee1b9f55442473ecdf80ac13eb5f2caa2
[claws.git] / src / textview.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 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 __TEXTVIEW_H__
21 #define __TEXTVIEW_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <glib.h>
28 #include <gtk/gtk.h>
29
30 typedef struct _TextView        TextView;
31 typedef struct _ClickableText   ClickableText;
32 struct _ClickableText
33 {
34         gchar *uri;
35
36         gchar *filename;
37
38         gpointer data;
39
40         guint start;
41         guint end;
42         
43         gboolean is_quote;
44         gint quote_level;
45         gboolean q_expanded;
46         gchar *fg_color;
47 };
48
49
50 #include "messageview.h"
51 #include "procmime.h"
52
53 struct _TextView
54 {
55         GtkWidget *vbox;
56         GtkWidget *scrolledwin;
57         GtkWidget *text;
58
59         GtkUIManager *ui_manager;
60         GtkActionGroup *link_action_group;
61         GtkWidget *link_popup_menu;
62         GtkActionGroup *mail_action_group;
63         GtkWidget *mail_popup_menu;
64         GtkActionGroup *file_action_group;
65         GtkWidget *file_popup_menu;
66
67         gboolean default_text;
68         gboolean is_in_signature;
69         
70         GSList *uri_list;
71         gint body_pos;
72
73         MessageView *messageview;
74         gint last_buttonpress;
75
76         ClickableText *uri_hover;
77         GtkTextIter uri_hover_start_iter;
78         GtkTextIter uri_hover_end_iter;
79         GtkWidget *image;
80         gboolean loading;
81         gboolean stop_loading;
82         gint prev_quote_level;
83 };
84
85 TextView *textview_create               (void);
86 void textview_init                      (TextView       *textview);
87 void textview_reflect_prefs             (TextView       *textview);
88
89 void textview_show_part         (TextView       *textview,
90                                  MimeInfo       *mimeinfo,
91                                  FILE           *fp);
92 void textview_show_error        (TextView       *textview);
93 void textview_show_info         (TextView       *textview,
94                                  const gchar    *info_str);
95 void textview_show_mime_part    (TextView       *textview,
96                                  MimeInfo       *partinfo);
97 void textview_clear             (TextView       *textview);
98 void textview_destroy           (TextView       *textview);
99 void textview_set_font          (TextView       *textview,
100                                  const gchar    *codeset);
101 void textview_set_text          (TextView       *textview,
102                                  const gchar    *text);
103 void textview_set_position      (TextView       *textview,
104                                  gint            pos);
105 void textview_scroll_one_line   (TextView       *textview,
106                                  gboolean        up);
107 gboolean textview_scroll_page   (TextView       *textview,
108                                  gboolean        up);
109 void textview_scroll_max        (TextView       *textview,
110                                  gboolean        up);
111
112 gboolean textview_search_string                 (TextView       *textview,
113                                                  const gchar    *str,
114                                                  gboolean        case_sens);
115 gboolean textview_search_string_backward        (TextView       *textview,
116                                                  const gchar    *str,
117                                                  gboolean        case_sens);
118 void textview_cursor_wait(TextView *textview);
119 void textview_cursor_normal(TextView *textview);
120 void textview_show_icon(TextView *textview, const gchar *stock_id);
121 void textview_get_selection_offsets     (TextView       *textview, 
122                                          gint           *sel_start, 
123                                          gint           *sel_end);
124 gboolean textview_uri_security_check    (TextView       *textview, 
125                                          ClickableText  *uri);
126 gchar *textview_get_visible_uri         (TextView       *textview, 
127                                          ClickableText  *uri);
128
129 #define TEXTVIEW_INSERT(str) \
130         gtk_text_buffer_insert_with_tags_by_name \
131                                 (buffer, &iter, str, -1,\
132                                  "header", NULL)
133
134 #define TEXTVIEW_INSERT_BOLD(str) \
135         gtk_text_buffer_insert_with_tags_by_name \
136                                 (buffer, &iter, str, -1,\
137                                  "header", "header_title", NULL)
138
139 #define TEXTVIEW_INSERT_LINK(str, fname, udata) {                               \
140         ClickableText *uri;                                                     \
141         uri = g_new0(ClickableText, 1);                                 \
142         uri->uri = g_strdup("");                                        \
143         uri->start = gtk_text_iter_get_offset(&iter);                   \
144         gtk_text_buffer_insert_with_tags_by_name                        \
145                                 (buffer, &iter, str, -1,                \
146                                  "link", "header_title", "header",      \
147                                  NULL);                                 \
148         uri->end = gtk_text_iter_get_offset(&iter);                     \
149         uri->filename = fname?g_strdup(fname):NULL;                     \
150         uri->data = udata;                                              \
151         textview->uri_list =                                            \
152                 g_slist_prepend(textview->uri_list, uri);               \
153 }
154
155 #endif /* __TEXTVIEW_H__ */