1 /* 2 * Copyright 2011 kubtek <kubtek@mail.com> 3 * 4 * This file is part of StarDict. 5 * 6 * StarDict is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * StarDict is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with StarDict. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef ARTICLEVIEW_H 21 #define ARTICLEVIEW_H 22 23 #include <string> 24 #include <gtk/gtk.h> 25 26 #include "pangoview.h" 27 #include "lib/dictbase.h" 28 29 enum BookNameStyle 30 { 31 BookNameStyle_Default, 32 BookNameStyle_OneBlankLine, 33 BookNameStyle_TwoBlankLines, 34 }; 35 36 //class which show dictionary's articles 37 class ArticleView { 38 public: 39 ArticleView(GtkContainer *owner, BookNameStyle booknamestyle, bool floatw=false) 40 : bookindex(0), bookname_style(booknamestyle), pango_view_(PangoWidgetBase::create(owner, floatw)), 41 for_float_win(floatw), headerindex(-1) {} 42 ArticleView(GtkBox *owner, BookNameStyle booknamestyle, bool floatw=false) bookname_style(booknamestyle)43 : bookname_style(booknamestyle), 44 pango_view_(PangoWidgetBase::create(owner, floatw)), 45 for_float_win(floatw), headerindex(-1) {} 46 47 void SetDictIndex(InstantDictIndex index); 48 void AppendHeaderMark(); 49 void AppendHeader(const char *dict_name, const char *dict_link = NULL); 50 void AppendWord(const gchar *word); 51 void AppendData(gchar *data, const gchar *oword, const gchar *origword); 52 void AppendNewline(); 53 void AppendDataSeparate(); 54 widget()55 GtkWidget *widget() { return pango_view_->widget(); } scroll_to(gdouble val)56 void scroll_to(gdouble val) { pango_view_->scroll_to(val); } set_text(const char * str)57 void set_text(const char *str) { pango_view_->set_text(str); } append_text(const char * str)58 void append_text(const char *str) { pango_view_->append_text(str); } append_pango_text(const char * str)59 void append_pango_text(const char *str) { pango_view_->append_pango_text(str); } 60 void append_pixbuf(GdkPixbuf *pixbuf, const char *label = NULL) { pango_view_->append_pixbuf(pixbuf, label); } append_widget(GtkWidget * widget)61 void append_widget(GtkWidget *widget) { pango_view_->append_widget(widget); } set_pango_text(const char * str)62 void set_pango_text(const char *str) { pango_view_->set_pango_text(str); } get_text()63 std::string get_text() { return pango_view_->get_text(); } append_pango_text_with_links(const std::string & str,const LinksPosList & links)64 void append_pango_text_with_links(const std::string& str, 65 const LinksPosList& links) { 66 pango_view_->append_pango_text_with_links(str, links); 67 } clear()68 void clear() { pango_view_->clear(); bookindex = 0; headerindex = -1; } append_mark(const char * mark)69 void append_mark(const char *mark) { pango_view_->append_mark(mark); } begin_update()70 void begin_update() { pango_view_->begin_update(); } end_update()71 void end_update() { pango_view_->end_update(); } goto_begin()72 void goto_begin() { pango_view_->goto_begin(); } goto_end()73 void goto_end() { pango_view_->goto_end(); } 74 #if GTK_MAJOR_VERSION >= 3 modify_bg(GtkStateFlags state,const GdkRGBA * color)75 void modify_bg(GtkStateFlags state, const GdkRGBA *color) { pango_view_->modify_bg(state, color); } 76 #else modify_bg(GtkStateType state,const GdkColor * color)77 void modify_bg(GtkStateType state, const GdkColor *color) { pango_view_->modify_bg(state, color); } 78 #endif vscroll_bar()79 GtkWidget *vscroll_bar() { return pango_view_->vscroll_bar(); } set_size(gint w,gint h)80 void set_size(gint w, gint h) { pango_view_->set_size(w, h); } scroll_space()81 gint scroll_space() { return pango_view_->scroll_space(); } scroll_pos()82 gdouble scroll_pos() { return pango_view_->scroll_pos(); } 83 void connect_on_link(const sigc::slot<void, const std::string &>& s); get_bookindex(void)84 unsigned int get_bookindex(void) { return bookindex; } set_bookname_style(BookNameStyle style)85 void set_bookname_style(BookNameStyle style) { bookname_style = style; } 86 private: 87 struct ParseResultItemWithMark; 88 89 unsigned int bookindex; 90 BookNameStyle bookname_style; 91 std::auto_ptr<PangoWidgetBase> pango_view_; 92 bool for_float_win; 93 InstantDictIndex dict_index; 94 /* Count headers. Add extra space before headers with index > 0. */ 95 int headerindex; 96 97 std::string xdxf2pango(const char *p, const gchar *oword, LinksPosList& links_list); 98 void append_and_mark_orig_word(const std::string& mark, 99 const gchar *origword, 100 const LinksPosList& links); 101 void append_resource_file_list(const gchar *p); 102 void append_data_parse_result(const gchar *real_oword, ParseResult& parse_result); 103 void append_data_res_image(const std::string& key, const std::string& mark, 104 bool& loaded); 105 void append_data_res_sound(const std::string& key, const std::string& mark, 106 bool& loaded); 107 void append_data_res_video(const std::string& key, const std::string& mark, 108 bool& loaded); 109 void append_data_res_attachment(const std::string& key, const std::string& mark, 110 bool& loaded); 111 static void on_resource_button_destroy(GtkWidget *object, gpointer user_data); 112 static void on_sound_button_clicked(GtkWidget *object, gpointer user_data); 113 static void on_video_button_clicked(GtkWidget *object, gpointer user_data); 114 static void on_attachment_button_clicked(GtkWidget *object, gpointer user_data); 115 static void on_resource_button_realize(GtkWidget *object, gpointer user_data); 116 }; 117 118 119 #endif//ARTICLEVIEW_H 120