2 #ifndef _F_TEXT_OUTPUT_H_
3 #define _F_TEXT_OUTPUT_H_
5 #include <F_Text_Display.H>
7 #include <F_Scrollbar.H>
12 class F_Text_Output : public F_Widget {
18 unsigned int topline_;
19 std::vector <std::string> lines;
21 unsigned int line_buf_size;
22 unsigned int max_line_size_;
23 unsigned int start_col_; // starting column
26 bool handle(F_Event_t &ev);
27 void add_line(const char *str);
28 static void vs_callback(F_Scrollbar *s, void *) {
29 F_Text_Output *to = (F_Text_Output *)s->parent_wdg();
30 if (s->value() > (to->lines.size() - (to->h() - 1)))
31 to->topline(to->lines.size() - (to->h() - 1));
33 to->topline(s->value());
35 static void hs_callback(F_Scrollbar *s, void *) {
36 F_Text_Output *to = (F_Text_Output *)s->parent_wdg();
37 if (s->value() > (to->max_line_size() - (to->w() - 1)))
38 to->startcol(to->max_line_size() - (to->w() - 1));
40 to->startcol(s->value());
43 void startcol(int sc) {
50 F_Text_Output(F_Box_Type_t btype, coord_t x, coord_t y, dim_t w, dim_t h,
51 const char *label = 0) : F_Widget(x, y, w, h, label) {
57 line_buf_size = 10240U;
58 line_buf = new char[line_buf_size];
59 // hor slider is created with max width
60 hs = new F_Scrollbar(F_NO_BOX, F_HORIZONTAL, x, y + h - 2, w, 1);
61 vs = new F_Scrollbar(F_NO_BOX, F_VERTICAL, w + x - 1, y + 1, 1, h - 2);
62 vs->callback((F_Callback *)vs_callback);
63 hs->callback((F_Callback *)hs_callback);
67 ~F_Text_Output() { delete [] line_buf; }
68 unsigned int max_line_size() { return max_line_size_; }
69 unsigned int start_col() { return start_col_; }
70 void topline(int tl) {
73 if (tl > int(lines.size()))
74 topline_ = lines.size();
79 void wrap(F_Wrap_t w) { wrap_ = w; draw(); }
89 void add(std::string &s) { add_line(s.c_str()); }
90 void add(const char *s) { add_line(s); }
91 void addf(const char *fmt, ...) {
93 ::va_start(args, fmt);
95 ::vsnprintf(line_buf, line_buf_size, fmt, args);