update copyright year
[claws.git] / src / textview.h
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2021 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 __TEXTVIEW_H__
20 #define __TEXTVIEW_H__
21
22 #ifdef HAVE_CONFIG_H
23 #include "claws-features.h"
24 #endif
25
26 #include <glib.h>
27 #include <gtk/gtk.h>
28
29 typedef struct _ClickableText   ClickableText;
30 struct _ClickableText
31 {
32         gchar *uri;
33
34         gchar *filename;
35
36         gpointer data;
37         gint data_len;
38
39         guint start;
40         guint end;
41         
42         gboolean is_quote;
43         gint quote_level;
44         gboolean q_expanded;
45         gchar *fg_color;
46 };
47
48
49 #include "viewtypes.h"
50 #include "procmime.h"
51
52 struct _TextView
53 {
54         GtkWidget *vbox;
55         GtkWidget *scrolledwin;
56         GtkWidget *text;
57
58         GtkUIManager *ui_manager;
59         GtkActionGroup *link_action_group;
60         GtkWidget *link_popup_menu;
61         GtkActionGroup *mail_action_group;
62         GtkWidget *mail_popup_menu;
63         GtkActionGroup *file_action_group;
64         GtkWidget *file_popup_menu;
65
66         gboolean default_text;
67         gboolean is_in_signature;
68         gboolean is_diff;
69         gboolean is_attachment;
70         gboolean is_in_git_patch;
71
72         GSList *uri_list;
73         gint body_pos;
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         gint avatar_type;
83         gboolean loading;
84         gboolean stop_loading;
85         gint prev_quote_level;
86 };
87
88 TextView *textview_create               (void);
89 void textview_init                      (TextView       *textview);
90 void textview_reflect_prefs             (TextView       *textview);
91
92 void textview_show_part         (TextView       *textview,
93                                  MimeInfo       *mimeinfo,
94                                  FILE           *fp);
95 void textview_show_error        (TextView       *textview);
96 void textview_show_info         (TextView       *textview,
97                                  const gchar    *info_str);
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_font          (TextView       *textview,
103                                  const gchar    *codeset);
104 void textview_set_text          (TextView       *textview,
105                                  const gchar    *text);
106 void textview_set_position      (TextView       *textview,
107                                  gint            pos);
108 void textview_scroll_one_line   (TextView       *textview,
109                                  gboolean        up);
110 gboolean textview_scroll_page   (TextView       *textview,
111                                  gboolean        up);
112 void textview_scroll_max        (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                                          gboolean        copied);
130 gchar *textview_get_visible_uri         (TextView       *textview, 
131                                          ClickableText  *uri);
132
133 #define TEXTVIEW_INSERT(str) \
134         gtk_text_buffer_insert_with_tags_by_name \
135                                 (buffer, &iter, str, -1,\
136                                  "header", NULL)
137
138 #define TEXTVIEW_INSERT_BOLD(str) \
139         gtk_text_buffer_insert_with_tags_by_name \
140                                 (buffer, &iter, str, -1,\
141                                  "header", "header_title", NULL)
142
143 #define TEXTVIEW_INSERT_LINK(str, fname, udata) {                               \
144         ClickableText *uri;                                                     \
145         uri = g_new0(ClickableText, 1);                                 \
146         uri->uri = g_strdup("");                                        \
147         uri->start = gtk_text_iter_get_offset(&iter);                   \
148         gtk_text_buffer_insert_with_tags_by_name                        \
149                                 (buffer, &iter, str, -1,                \
150                                  "link", "header_title", "header",      \
151                                  NULL);                                 \
152         uri->end = gtk_text_iter_get_offset(&iter);                     \
153         uri->filename = fname?g_strdup(fname):NULL;                     \
154         uri->data = udata;                                              \
155         textview->uri_list =                                            \
156                 g_slist_prepend(textview->uri_list, uri);               \
157 }
158
159 #endif /* __TEXTVIEW_H__ */