Correct backtrace() array size argument
[forms.git] / F / F_Linux_Console_Display.H
blobaab44a5b3a4ccd8b5ad1db2b3369f26425441856
2  /*
3   *   Copyright (C) 2007, Harbour, All rights reserved.
4   */
6 #ifndef _F_LINUX_CONSOLE_DISPLAY_H_
7 #define _F_LINUX_CONSOLE_DISPLAY_H_
9 #include <F_Text_Display.H>
10 #include <F_Window.H>
12 #include <stdio.h>
14 namespace F {
16 class F_Linux_Console_Display : public F_Text_Display {
18   FILE *vcsa_;
19   coord_t old_cursor_x, old_cursor_y, cursor_x, cursor_y;
20   coord_t old_mouse_x, old_mouse_y, mouse_x, mouse_y;
21   F_Event_Type_t mouse_ev_t; // current mouse event type
22   F_Pointer_Event_Code_t mouse_ev_c; // current mouse event code
23   F_Text_Symbol symbol_under_mouse_;
24   F_Window *window_belowmouse_;
25   
26   void put_line(coord_t x, coord_t y, dim_t len, F_Text_Symbol *src);
27   void get_line(coord_t x, coord_t y, dim_t len, F_Text_Symbol *dest);
28     
29   inline void put_symbol_region(F_Region *region, F_Text_Symbol_Buffer &src) {
30      for (register coord_t cur_line = region->y(); cur_line < (region->y() + region->h()); cur_line++)
31           put_line(region->x(), cur_line, region->w(), src[((cur_line - region->y()) * region->w())]);
32  }       
33   inline void get_symbol_region(F_Region *region, F_Text_Symbol_Buffer &dest) {
34      for (register coord_t cur_line = region->y(); cur_line < (region->y() + region->h()); cur_line++)
35           get_line(region->x(), cur_line, region->w(), dest[((cur_line - region->y()) * region->w())]);
36  }
37   
38  public:
40   F_Linux_Console_Display(FILE *vcsa, dim_t w, dim_t h) : F_Text_Display(w, h) {
41     vcsa_ = vcsa;
42     old_mouse_x = old_mouse_y = mouse_x = mouse_y = F_MAX_COORD_T;
43     mouse_ev_t = F_EVENT_NONE;
44     mouse_ev_c = F_POINTER_NONE;
45     window_belowmouse_ = 0;
46   }
47   ~F_Linux_Console_Display() { fclose(vcsa_); }
49   // ÏÂÒÁÂÁÙ×ÁÅÔ ÓÏÂÙÔÉÑ É ÐÅÒÅÄÁÅÔ ÉÈ ÄÁÌØÛÅ - ÏËÎÁÍ/×ÉÄÖÅÔÁÍ
50   bool handle(F_Event_t &ev);
51   F_Window *window_belowmouse() { return window_belowmouse_; }
52   void window_belowmouse(F_Window *w) { window_belowmouse_ = w; }
53   // tty magic : cursor on/off
54   void cursor(bool on) {
55     if (on && (cursor_x >= 0) && (cursor_x <= w()) && (cursor_y <= h()) &&
56       (cursor_y >= 0))
57         fprintf(stdout, "%c%s",27,"[?25h");
58     else
59       fprintf(stdout, "%c%s",27,"[?25l");
60     fflush(stdout);
61   }
62   // set cursor
63   void cursor(coord_t x, coord_t y);
64   // get cursor
65   void cursor(coord_t *x, coord_t *y);
66   void restore_mouse_pointer() {
67     if ((old_mouse_x == F_MAX_COORD_T) || (old_mouse_y == F_MAX_COORD_T))
68       return;
69     if ((old_mouse_x < w()) && (old_mouse_y < h())) {
70       put_line(old_mouse_x, old_mouse_y, 1, &symbol_under_mouse_);
71     }
72   }
73   void draw_mouse_pointer() {
74     if ((mouse_x == F_MAX_COORD_T) || (mouse_y == F_MAX_COORD_T))
75       return;
76     restore_mouse_pointer();
77     if (!mouse_cursor_)
78       return;
79     if (mouse_x > (coord_t)(w() - 1))
80       mouse_x = w() - 1;
81     if (mouse_y > (coord_t)(h() - 1))
82       mouse_y = h() - 1;
83     get_line(mouse_x, mouse_y, 1, &symbol_under_mouse_);
84     F_Text_Symbol t = symbol_under_mouse_;
85     bool blink = (symbol_under_mouse_.bg() & 0x8);
86     bool bright = (symbol_under_mouse_.fg() & 0x8);
87     // invert new
88     t.fg((~symbol_under_mouse_.fg() & 0x7) | (bright ? 0x8 : 0));
89     t.bg((~symbol_under_mouse_.bg() & 0x7) | (blink ? 0x8 : 0));
90     put_line(mouse_x, mouse_y, 1, &t);
91     old_mouse_x = mouse_x;
92     old_mouse_y = mouse_y;
93   }
94   void store() {
95     // ÓÏÈÒÁÎÑÅÍ ÜËÒÁΠנbacking store
96     get_symbol_region(this, back_buf);
97     // É ÔÏÖÅ ÓÁÍÏÅ × front store
98     get_symbol_region(this, draw_buf);
99     cursor(&old_cursor_x, &old_cursor_y);
101   void restore() {
102     put_symbol_region(this, back_buf);
103     cursor(old_cursor_x, old_cursor_y);
104     cursor(1);
105   }
107   friend class F_Linux_Console_UI;
109  }; // class F_Linux_Console_Display
111 }; // namespace F
113 #endif