3 * Copyright (C) 2007, Harbour, All rights reserved.
6 #ifndef _F_TEXT_OUTPUT_H_
7 #define _F_TEXT_OUTPUT_H_
9 #include <F_Text_Display.H>
11 #include <F_Scrollbar.H>
16 class F_Text_Output : public F_Widget {
22 unsigned int topline_;
23 std::vector <std::string> lines;
25 unsigned int line_buf_size;
26 unsigned int max_line_size_;
27 unsigned int start_col_; // starting column
30 bool handle(F_Event_t &ev);
31 void add_line(const char *str);
32 static void vs_callback(F_Scrollbar *s, void *) {
33 F_Text_Output *to = (F_Text_Output *)s->parent_wdg();
34 if (s->value() > (to->lines.size() - (to->h() - 1)))
35 to->topline(to->lines.size() - (to->h() - 1));
37 to->topline(s->value());
39 static void hs_callback(F_Scrollbar *s, void *) {
40 F_Text_Output *to = (F_Text_Output *)s->parent_wdg();
41 if (s->value() > (to->max_line_size() - (to->w() - 1)))
42 to->startcol(to->max_line_size() - (to->w() - 1));
44 to->startcol(s->value());
47 void startcol(int sc) {
54 F_Text_Output(F_Box_Type_t btype, coord_t x, coord_t y, dim_t w, dim_t h,
55 const char *label = 0) : F_Widget(x, y, w, h, label) {
61 line_buf_size = 10240U;
62 line_buf = new char[line_buf_size];
63 // hor slider is created with max width
64 hs = new F_Scrollbar(F_NO_BOX, F_HORIZONTAL, x, y + h - 2, w, 1);
65 vs = new F_Scrollbar(F_NO_BOX, F_VERTICAL, w + x - 1, y + 1, 1, h - 2);
66 vs->callback((F_Callback *)vs_callback);
67 hs->callback((F_Callback *)hs_callback);
71 ~F_Text_Output() { delete [] line_buf; }
72 unsigned int max_line_size() { return max_line_size_; }
73 unsigned int start_col() { return start_col_; }
74 void topline(int tl) {
77 if (tl > int(lines.size()))
78 topline_ = lines.size();
83 void wrap(F_Wrap_t w) { wrap_ = w; draw(); }
93 void add(std::string &s) { add_line(s.c_str()); }
94 void add(const char *s) { add_line(s); }
95 void addf(const char *fmt, ...) {
97 ::va_start(args, fmt);
99 ::vsnprintf(line_buf, line_buf_size, fmt, args);