2007-04-24 [wwp] 2.9.1cvs19
[claws.git] / src / textview.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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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/gtkwidget.h>
29 #include <gtk/gtktextiter.h>
30
31 typedef struct _TextView        TextView;
32 typedef struct _ClickableText   ClickableText;
33 struct _ClickableText
34 {
35         gchar *uri;
36
37         gchar *filename;
38
39         gpointer data;
40
41         guint start;
42         guint end;
43         
44         gboolean is_quote;
45         gint quote_level;
46         gboolean q_expanded;
47         gchar *fg_color;
48 };
49
50
51 #include "messageview.h"
52 #include "procmime.h"
53
54 struct _TextView
55 {
56         GtkWidget *vbox;
57         GtkWidget *scrolledwin;
58         GtkWidget *text;
59
60         GtkWidget *link_popup_menu;
61         GtkItemFactory *link_popup_factory;
62         GtkWidget *mail_popup_menu;
63         GtkItemFactory *mail_popup_factory;
64         GtkWidget *file_popup_menu;
65         GtkItemFactory *file_popup_factory;
66
67         gboolean default_text;
68         gboolean is_in_signature;
69         
70         GSList *uri_list;
71         gint body_pos;
72
73         gboolean show_all_headers;
74
75         MessageView *messageview;
76         gint last_buttonpress;
77
78         ClickableText *uri_hover;
79         GtkTextIter uri_hover_start_iter;
80         GtkTextIter uri_hover_end_iter;
81         GtkWidget *image;
82         gboolean loading;
83         gboolean stop_loading;
84         gint prev_quote_level;
85 };
86
87 TextView *textview_create               (void);
88 void textview_init                      (TextView       *textview);
89 void textview_reflect_prefs             (TextView       *textview);
90
91 void textview_show_message      (TextView       *textview,
92                                  MimeInfo       *mimeinfo,
93                                  const gchar    *file);
94 void textview_show_part         (TextView       *textview,
95                                  MimeInfo       *mimeinfo,
96                                  FILE           *fp);
97 void textview_show_error        (TextView       *textview);
98 void textview_show_mime_part    (TextView       *textview,
99                                  MimeInfo       *partinfo);
100 void textview_clear             (TextView       *textview);
101 void textview_destroy           (TextView       *textview);
102 void textview_set_all_headers   (TextView       *textview,
103                                  gboolean        all_headers);
104 void textview_set_font          (TextView       *textview,
105                                  const gchar    *codeset);
106 void textview_set_text          (TextView       *textview,
107                                  const gchar    *text);
108 void textview_set_position      (TextView       *textview,
109                                  gint            pos);
110 void textview_scroll_one_line   (TextView       *textview,
111                                  gboolean        up);
112 gboolean textview_scroll_page   (TextView       *textview,
113                                  gboolean        up);
114
115 gboolean textview_search_string                 (TextView       *textview,
116                                                  const gchar    *str,
117                                                  gboolean        case_sens);
118 gboolean textview_search_string_backward        (TextView       *textview,
119                                                  const gchar    *str,
120                                                  gboolean        case_sens);
121 void textview_cursor_wait(TextView *textview);
122 void textview_cursor_normal(TextView *textview);
123 void textview_show_icon(TextView *textview, const gchar *stock_id);
124 void textview_get_selection_offsets     (TextView       *textview, 
125                                          gint           *sel_start, 
126                                          gint           *sel_end);
127 gboolean textview_uri_security_check    (TextView       *textview, 
128                                          ClickableText  *uri);
129 gchar *textview_get_visible_uri         (TextView       *textview, 
130                                          ClickableText  *uri);
131
132 #define TEXTVIEW_INSERT(str) \
133         gtk_text_buffer_insert_with_tags_by_name \
134                                 (buffer, &iter, str, -1,\
135                                  "header", NULL)
136
137 #define TEXTVIEW_INSERT_LINK(str, fname, udata) {                               \
138         ClickableText *uri;                                                     \
139         uri = g_new0(ClickableText, 1);                                 \
140         uri->uri = g_strdup("");                                        \
141         uri->start = gtk_text_iter_get_offset(&iter);                   \
142         gtk_text_buffer_insert_with_tags_by_name                        \
143                                 (buffer, &iter, str, -1,                \
144                                  "link", "header_title", "header",      \
145                                  NULL);                                 \
146         uri->end = gtk_text_iter_get_offset(&iter);                     \
147         uri->filename = fname?g_strdup(fname):NULL;                     \
148         uri->data = udata;                                              \
149         textview->uri_list =                                            \
150                 g_slist_prepend(textview->uri_list, uri);               \
151 }
152
153 #endif /* __TEXTVIEW_H__ */