1 /*
2 
3     eboard - chess client
4     http://www.bergo.eng.br/eboard
5     https://github.com/fbergo/eboard
6     Copyright (C) 2000-2016 Felipe Bergo
7     fbergo/at/gmail/dot/com
8 
9     This program 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 2 of the License, or
12     (at your option) any later version.
13 
14     This program 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, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 
23 */
24 
25 
26 
27 #ifndef EBOARD_TEXT_H
28 #define EBOARD_TEXT_H 1
29 
30 #include "eboard.h"
31 #include "widgetproxy.h"
32 #include "ntext.h"
33 #include "notebook.h"
34 #include "history.h"
35 #include "util.h"
36 #include "stl.h"
37 
38 class OutputPane {
39  public:
40   virtual ~OutputPane();
41   virtual void append(const char *msg,int color,Importance imp=IM_NORMAL)=0;
42   virtual void append(const char *msg,const char *msg2,int color,Importance imp=IM_NORMAL)=0;
43   virtual void updateScrollBack()=0;
44   virtual void updateFont()=0;
45   virtual void setBackground(int color)=0;
46 };
47 
48 class Searchable {
49  public:
~Searchable()50   virtual ~Searchable() {}
51   virtual void execSearch()=0;
52   string SearchString;
53 };
54 
55 class TextFilter {
56  public:
57   TextFilter();
58   ~TextFilter();
59 
60   void set(const char *t);
61   const char *getString();
62 
63   bool accept(const char *textline);
64 
65  private:
66   string FilterString;
67   bool AcceptedLast;
68   void cleanUp();
69   vector<ExtPatternMatcher *> thefilter;
70 };
71 
72 class Text : public NText,
73              public NotebookInsider,
74              public OutputPane,
75              public Searchable {
76  public:
77  Text();
78  virtual ~Text();
79 
80   void append(const char *msg,int color,Importance imp=IM_NORMAL);
81   void append(const char *msg,const char *msg2,int color,Importance imp=IM_NORMAL);
82 
83   void pageUp();
84   void pageDown();
85 
86   void setBackground(int color);
87   void updateScrollBack();
88   void updateFont();
89 
90   void saveBuffer();
91 
92   void findText();
93   void findTextNext();
94 
95   void execSearch();
96 
97   TextFilter Filter;
98 
99  private:
100   int linecount;
101   int LastMatch;
102 };
103 
104 class TextSet : public OutputPane {
105  public:
106   TextSet();
107   ~TextSet();
108 
109   void addTarget(Text *target);
110   void removeTarget(Text *target);
111 
112   void append(const char *msg,int color,Importance imp=IM_NORMAL);
113   void append(const char *msg,const char *msg2,int color,Importance imp=IM_NORMAL);
114 
115   void pageUp();
116   void pageDown();
117 
118   void updateScrollBack();
119   void updateFont();
120   void setBackground(int color);
121 
122  private:
123   list<Text *> targets;
124 };
125 
126 class DetachedConsole : public WidgetProxy {
127  public:
128   DetachedConsole(TextSet *yourset, ConsoleListener *cl);
129   virtual ~DetachedConsole();
130 
131   const char *getFilter();
132 
133   void show();
134   void setFilter(const char *s);
135   void setPasswordMode(int pm);
136 
137  private:
138   Text *inner;
139   TextSet *myset;
140   GtkWidget *inputbox;
141   ConsoleListener *listener;
142   History::iterator hcursor;
143   int focus_sig_id;
144   string basetitle;
145   GtkWidget *flabel;
146 
147   static int ConsoleCount;
148 
149   void injectInput();
150   void historyUp();
151   void historyDown();
152 
153   void clone();
154   void updateFilterLabel();
155 
156   friend gint detached_delete  (GtkWidget * widget, GdkEvent * event, gpointer data);
157   friend void detached_destroy (GtkWidget * widget, gpointer data);
158   friend int  dc_input_key_press (GtkWidget * wid, GdkEventKey * evt,
159 				  gpointer data);
160   friend void dc_set_filter(GtkWidget *w,gpointer data);
161   friend void dc_new_console(GtkWidget *w,gpointer data);
162 };
163 
164 gint detached_delete  (GtkWidget * widget, GdkEvent * event, gpointer data);
165 void detached_destroy (GtkWidget * widget, gpointer data);
166 int  dc_input_key_press (GtkWidget * wid, GdkEventKey * evt,
167 				gpointer data);
168 void dc_set_filter(GtkWidget *w,gpointer data);
169 void dc_new_console(GtkWidget *w,gpointer data);
170 
171 class TextFilterDialog : public ModalDialog {
172  public:
173   TextFilterDialog(Text *target, GtkWidget *label2update);
174  private:
175   GtkWidget *pattern;
176   Text *obj;
177   GtkWidget *ulabel;
178   friend void tfd_ok(GtkWidget *w, gpointer data);
179 };
180 
181 void tfd_ok(GtkWidget *w, gpointer data);
182 
183 #endif
184