1 // ---------------------------------------------------------------------------- 2 // FTextView.h 3 // 4 // Copyright (C) 2007-2009 5 // Stelios Bounanos, M0GLD 6 // 7 // This file is part of fldigi. 8 // 9 // fldigi is free software; you can redistribute it and/or modify 10 // it under the terms of the GNU General Public License as published by 11 // the Free Software Foundation; either version 3 of the License, or 12 // (at your option) any later version. 13 // 14 // fldigi is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of the GNU General Public License 20 // along with this program. If not, see <http://www.gnu.org/licenses/>. 21 // ---------------------------------------------------------------------------- 22 23 #ifndef FTextView_H_ 24 #define FTextView_H_ 25 26 #include <stddef.h> 27 #include <string> 28 29 #include <FL/Fl.H> 30 #include <FL/Enumerations.H> 31 #include <FL/Fl_Menu_Item.H> 32 #include <FL/Fl_Tile.H> 33 34 #include "Fl_Text_Editor_mod.H" 35 36 /// 37 /// The text widgets base class. 38 /// This class implements a basic text editing widget based on Fl_Text_Editor_mod. 39 /// 40 class FTextBase : public Fl_Text_Editor_mod 41 { 42 public: 43 // CLICK_START: same as first clickable style 44 // NATTR: number of styles (last style + 1) 45 enum TEXT_ATTR { RECV, XMIT, CTRL, SKIP, ALTR, 46 FSQ_TX, FSQ_DIR, FSQ_UND, 47 CLICK_START, QSY = CLICK_START, /* FOO, BAR, ..., */ 48 NATTR }; 49 50 FTextBase(int x, int y, int w, int h, const char *l = 0); ~FTextBase()51 virtual ~FTextBase() { delete tbuf; delete sbuf; } 52 53 #if FLDIGI_FLTK_API_MAJOR == 1 && FLDIGI_FLTK_API_MINOR >= 3 54 virtual void add(unsigned int c, int attr = RECV); 55 #else 56 virtual void add(unsigned char c, int attr = RECV); 57 #endif 58 virtual void add(const char *text, int attr = RECV); 59 60 void addstr(std::string text, int attr = RECV) { add(text.c_str(), attr); } 61 void addchr(unsigned char c, int attr = RECV) { add(c, attr); } 62 63 virtual int handle(int event); handle_context_menu(void)64 virtual void handle_context_menu(void) { } 65 virtual void clear(void);//{ tbuf->text(""); sbuf->text(""); } 66 67 void set_word_wrap(bool b, bool b2 = false); get_word_wrap(void)68 bool get_word_wrap(void) { return wrap; } 69 70 virtual void setFont(Fl_Font f, int attr = NATTR); 71 void setFontSize(int s, int attr = NATTR); 72 void setFontColor(Fl_Color c, int attr = NATTR); 73 // Override Fl_Text_Display, which stores the font number in an unsigned 74 // character and therefore cannot represent all fonts textfont(void)75 Fl_Font textfont(void) { return styles[0].font; } textfont(Fl_Font f)76 void textfont(Fl_Font f) { setFont(f); } textfont(uchar s)77 void textfont(uchar s) { textfont((Fl_Font)s); } 78 cursorON(void)79 void cursorON(void) { show_cursor(); } 80 virtual void resize(int X, int Y, int W, int H); 81 82 static bool wheight_mult_tsize(void *arg, int xd, int yd); 83 84 protected: 85 void set_style(int attr, Fl_Font f, int s, Fl_Color c, 86 int set = SET_FONT | SET_SIZE | SET_COLOR); 87 int readFile(const char* fn = 0); 88 void saveFile(void); 89 char* get_word(int x, int y, const char* nwchars = "", int n = 1, bool ontext = true); 90 void init_context_menu(void); 91 void show_context_menu(void); menu_cb(size_t item)92 virtual void menu_cb(size_t item) { } 93 int reset_wrap_col(void); 94 void reset_styles(int set); 95 private: 96 FTextBase(); 97 FTextBase(const FTextBase &t); 98 99 protected: 100 enum { FTEXT_DEF = 'A' }; 101 enum set_style_op_e { SET_FONT = 1 << 0, SET_SIZE = 1 << 1, SET_COLOR = 1 << 2 }; 102 Fl_Text_Buffer_mod *tbuf; ///< text buffer 103 Fl_Text_Buffer_mod *sbuf; ///< style buffer 104 Fl_Text_Display_mod::Style_Table_Entry styles[NATTR]; 105 Fl_Menu_Item *context_menu; 106 int popx, popy; 107 bool wrap; 108 int wrap_col; 109 int max_lines; 110 bool scroll_hint; 111 bool restore_wrap; 112 // bool wrap_restore; 113 114 private: 115 int oldw, oldh, olds; 116 Fl_Font oldf; 117 }; 118 119 /// 120 /// A TextBase subclass to display received & transmitted text 121 /// 122 class FTextView : public FTextBase 123 { 124 public: 125 FTextView(int x, int y, int w, int h, const char *l = 0); ~FTextView()126 ~FTextView() { } 127 128 virtual int handle(int event); 129 130 protected: 131 enum { 132 VIEW_MENU_COPY, VIEW_MENU_CLEAR, VIEW_MENU_SELECT_ALL, 133 VIEW_MENU_SAVE, VIEW_MENU_WRAP 134 }; 135 136 virtual void handle_context_menu(void); 137 virtual void menu_cb(size_t item); 138 static void changed_cb(int pos, int nins, int ndel, int nsty, 139 const char *dtext, void *arg); 140 void change_keybindings(void); 141 142 private: 143 FTextView(); 144 FTextView(const FTextView &t); 145 146 protected: 147 static Fl_Menu_Item menu[]; 148 bool quick_entry; 149 }; 150 151 152 /// 153 /// A FTextBase subclass to display and edit text to be transmitted 154 /// 155 class FTextEdit : public FTextBase 156 { 157 public: 158 FTextEdit(int x, int y, int w, int h, const char *l = 0); 159 160 virtual int handle(int event); 161 162 protected: 163 enum { 164 EDIT_MENU_CUT, EDIT_MENU_COPY, EDIT_MENU_PASTE, EDIT_MENU_CLEAR, 165 EDIT_MENU_READ, EDIT_MENU_WRAP 166 }; 167 virtual int handle_key(int key); 168 int handle_key_ascii(int key); 169 virtual int handle_dnd_drag(int pos); 170 int handle_dnd_drop(void); 171 virtual void handle_context_menu(void); 172 virtual void menu_cb(size_t item); 173 static void changed_cb(int pos, int nins, int ndel, int nsty, 174 const char *dtext, void *arg); 175 176 private: 177 FTextEdit(); 178 FTextEdit(const FTextEdit &t); 179 180 protected: 181 static Fl_Menu_Item menu[]; 182 char ascii_cnt; 183 unsigned ascii_chr; 184 bool dnd_paste; 185 }; 186 187 #endif // FTextView_H_ 188 189 // Local Variables: 190 // mode: c++ 191 // c-file-style: "linux" 192 // End: 193