Ignore SIGHUP's
[forms.git] / F / F_Text_Output.H
blob24731bf0c835d3dfbed67e751365b2f09ac0c464
2  /*
3   *   Copyright (C) 2007, Harbour, All rights reserved.
4   */
6 #ifndef _F_TEXT_OUTPUT_H_
7 #define _F_TEXT_OUTPUT_H_
9 #include <F_Text_Display.H>
10 #include <F_Window.H>
11 #include <F_Scrollbar.H>
12 #include <cstdarg>
14 namespace F {
16 class F_Text_Output : public F_Widget {
18   F_Wrap_t wrap_;
19   F_Scrollbar *vs, *hs;
20   // ËÏÌÉÞÅÓÔ×Ï ÓÔÒÏË
21   unsigned int size_;
22   unsigned int topline_;
23   std::vector <std::string> lines;
24   char *line_buf;
25   unsigned int line_buf_size;
26   unsigned int max_line_size_;
27   unsigned int start_col_; // starting column
29   void draw();
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));
36     else
37       to->topline(s->value());
38   }
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));
43     else
44       to->startcol(s->value());
45   }
47   void startcol(int sc) {
48     if (sc < 0)
49       sc = 0;
50     start_col_ = sc;
51     draw();
52    }
53  public:
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) {
56       wrap_ = F_NO_WRAP;
57       size_ = 0;
58       topline_ = 0;
59       max_line_size_ = 0;
60       start_col_ = 0;
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);
68       add_child(vs);
69       add_child(hs);
70  }
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) {
75     if (tl < 0)
76       tl = 0;
77     if (tl > int(lines.size()))
78       topline_ = lines.size();
79     else
80       topline_ = tl;
81     draw();
82   }
83   void wrap(F_Wrap_t w) { wrap_ = w; draw(); }
84   void clear() {
85     lines.clear();
86     topline_ = 0;
87     start_col_ = 0; // ?
88     max_line_size_ = 0;
89     vs->value(0);
90     hs->value(0);
91     draw();
92  }
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, ...) {
96    ::va_list args;
97    ::va_start(args, fmt);
98    ::va_end(args);
99    ::vsnprintf(line_buf, line_buf_size, fmt, args);
100    add_line(line_buf);
101   }
102  };
105 #endif