| 1 |
// ---------------------------------------------------------------------------- |
| 2 |
// FTextView.h |
| 3 |
// |
| 4 |
// Copyright (C) 2007-2009 |
| 5 |
// Stelios Bounanos, M0GLD |
| 6 |
// |
| 7 |
// This file is part of FLAMP. |
| 8 |
// |
| 9 |
// This 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 |
// This software 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 |
|
| 24 |
#ifndef FTextView_H_ |
| 25 |
#define FTextView_H_ |
| 26 |
|
| 27 |
#include <stddef.h> |
| 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 |
CLICK_START, QSY = CLICK_START, /* FOO, BAR, ..., */ |
| 47 |
NATTR }; |
| 48 |
|
| 49 |
FTextBase(int x, int y, int w, int h, const char *l = 0); |
| 50 |
virtual ~FTextBase() { delete tbuf; delete sbuf; } |
| 51 |
|
| 52 |
virtual void add(const char *text, int attr = RECV); |
| 53 |
virtual void add(unsigned char c, int attr = RECV); |
| 54 |
void addstr(const char *text, int attr = RECV) { add(text, attr); } |
| 55 |
void addchr(unsigned char c, int attr = RECV) { add(c, attr); } |
| 56 |
|
| 57 |
virtual int handle(int event); |
| 58 |
virtual void handle_context_menu(void) { } |
| 59 |
virtual void clear(void);//{ tbuf->text(""); sbuf->text(""); } |
| 60 |
|
| 61 |
void set_word_wrap(bool b); |
| 62 |
bool get_word_wrap(void) { return wrap; } |
| 63 |
|
| 64 |
virtual void setFont(Fl_Font f, int attr = NATTR); |
| 65 |
void setFontSize(int s, int attr = NATTR); |
| 66 |
void setFontColor(Fl_Color c, int attr = NATTR); |
| 67 |
// Override Fl_Text_Display, which stores the font number in an unsigned |
| 68 |
// character and therefore cannot represent all fonts |
| 69 |
Fl_Font textfont(void) { return styles[0].font; } |
| 70 |
void textfont(Fl_Font f) { setFont(f); } |
| 71 |
void textfont(uchar s) { textfont((Fl_Font)s); } |
| 72 |
|
| 73 |
void cursorON(void) { show_cursor(); } |
| 74 |
virtual void resize(int X, int Y, int W, int H); |
| 75 |
|
| 76 |
static bool wheight_mult_tsize(void *arg, int xd, int yd); |
| 77 |
|
| 78 |
protected: |
| 79 |
void set_style(int attr, Fl_Font f, int s, Fl_Color c, |
| 80 |
int set = SET_FONT | SET_SIZE | SET_COLOR); |
| 81 |
int readFile(const char* fn = 0); |
| 82 |
void saveFile(void); |
| 83 |
char* get_word(int x, int y, const char* nwchars = "", bool ontext = true); |
| 84 |
void init_context_menu(void); |
| 85 |
void show_context_menu(void); |
| 86 |
virtual void menu_cb(size_t item) { } |
| 87 |
int reset_wrap_col(void); |
| 88 |
void reset_styles(int set); |
| 89 |
void (*read_cb)(const char *); |
| 90 |
public: |
| 91 |
void set_read_cb(void (func(const char*))) { read_cb = func;} |
| 92 |
private: |
| 93 |
FTextBase(); |
| 94 |
FTextBase(const FTextBase &t); |
| 95 |
|
| 96 |
protected: |
| 97 |
enum { FTEXT_DEF = 'A' }; |
| 98 |
enum set_style_op_e { SET_FONT = 1 << 0, SET_SIZE = 1 << 1, SET_COLOR = 1 << 2 }; |
| 99 |
Fl_Text_Buffer_mod *tbuf; ///< text buffer |
| 100 |
Fl_Text_Buffer_mod *sbuf; ///< style buffer |
| 101 |
Fl_Text_Display_mod::Style_Table_Entry styles[NATTR]; |
| 102 |
Fl_Menu_Item *context_menu; |
| 103 |
int popx, popy; |
| 104 |
int wrap; |
| 105 |
int wrap_col; |
| 106 |
int max_lines; |
| 107 |
bool scroll_hint; |
| 108 |
bool restore_wrap; |
| 109 |
// bool wrap_restore; |
| 110 |
|
| 111 |
private: |
| 112 |
int oldw, oldh, olds; |
| 113 |
Fl_Font oldf; |
| 114 |
}; |
| 115 |
|
| 116 |
/// |
| 117 |
/// A TextBase subclass to display received & transmitted text |
| 118 |
/// |
| 119 |
class FTextView : public FTextBase |
| 120 |
{ |
| 121 |
public: |
| 122 |
FTextView(int x, int y, int w, int h, const char *l = 0); |
| 123 |
~FTextView() { } |
| 124 |
|
| 125 |
virtual int handle(int event); |
| 126 |
|
| 127 |
protected: |
| 128 |
enum { |
| 129 |
VIEW_MENU_COPY, VIEW_MENU_CLEAR, VIEW_MENU_SELECT_ALL, |
| 130 |
VIEW_MENU_SAVE, VIEW_MENU_WRAP |
| 131 |
}; |
| 132 |
|
| 133 |
virtual void handle_context_menu(void); |
| 134 |
virtual void menu_cb(size_t item); |
| 135 |
static void changed_cb(int pos, int nins, int ndel, int nsty, |
| 136 |
const char *dtext, void *arg); |
| 137 |
void change_keybindings(void); |
| 138 |
|
| 139 |
private: |
| 140 |
FTextView(); |
| 141 |
FTextView(const FTextView &t); |
| 142 |
|
| 143 |
protected: |
| 144 |
static Fl_Menu_Item menu[]; |
| 145 |
bool quick_entry; |
| 146 |
}; |
| 147 |
|
| 148 |
|
| 149 |
/// |
| 150 |
/// A FTextBase subclass to display and edit text to be transmitted |
| 151 |
/// |
| 152 |
class FTextEdit : public FTextBase |
| 153 |
{ |
| 154 |
public: |
| 155 |
FTextEdit(int x, int y, int w, int h, const char *l = 0); |
| 156 |
|
| 157 |
virtual int handle(int event); |
| 158 |
|
| 159 |
protected: |
| 160 |
enum { |
| 161 |
EDIT_MENU_CUT, EDIT_MENU_COPY, EDIT_MENU_PASTE, EDIT_MENU_CLEAR, |
| 162 |
EDIT_MENU_READ, EDIT_MENU_WRAP |
| 163 |
}; |
| 164 |
virtual int handle_key(int key); |
| 165 |
int handle_key_ascii(int key); |
| 166 |
virtual int handle_dnd_drag(int pos); |
| 167 |
int handle_dnd_drop(void); |
| 168 |
virtual void handle_context_menu(void); |
| 169 |
virtual void menu_cb(size_t item); |
| 170 |
static void changed_cb(int pos, int nins, int ndel, int nsty, |
| 171 |
const char *dtext, void *arg); |
| 172 |
|
| 173 |
private: |
| 174 |
FTextEdit(); |
| 175 |
FTextEdit(const FTextEdit &t); |
| 176 |
|
| 177 |
protected: |
| 178 |
static Fl_Menu_Item menu[]; |
| 179 |
char ascii_cnt; |
| 180 |
unsigned ascii_chr; |
| 181 |
bool dnd_paste; |
| 182 |
}; |
| 183 |
|
| 184 |
#endif // FTextView_H_ |
| 185 |
|
| 186 |
// Local Variables: |
| 187 |
// mode: c++ |
| 188 |
// c-file-style: "linux" |
| 189 |
// End: |