1 
2 /**************************************************************************
3  * Copyright (C) 2007-2015 Ruben Pollan Bella <meskio@sindominio.net>     *
4  *                                                                        *
5  *  This file is part of TuDu.                                            *
6  *                                                                        *
7  *  TuDu is free software; you can redistribute it and/or modify          *
8  *  it under the terms of the GNU General Public License as published by  *
9  *  the Free Software Foundation; version 3 of the License.        *
10  *                                                                        *
11  *  TuDu is distributed in the hope that it will be useful,               *
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *  GNU General Public License for more details.                          *
15  *                                                                        *
16  *  You should have received a copy of the GNU General Public License     *
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. *
18  **************************************************************************/
19 
20 #ifndef EDITOR_H
21 #define EDITOR_H
22 
23 #include "includes.h"
24 #include "data.h"
25 #include "window.h"
26 
27 class Editor
28 {
29 public:
30 	/* return values for the editor */
31 	enum return_t {
32 		NOT_SAVED = 0,
33 		SAVED,
34 		/* In case of changes that need to redraw or resize the screen.
35 		 * After update the screen the function edit should be call again. */
36 		RESIZE,
37 		REDRAW
38 	};
39 
40 	Editor();
41 
42 	wstring& getText();
43 	int& cursorPos();
44 	return_t edit(Window& win, int begin_y, int begin_x, int ncols);
45 protected:
46 	Window *window;
47 	int y;
48 	int x;
49 	unsigned int cols;
50 	wstring text;
51 	int cursor;
52 	wint_t key;
53 	bool exit;
54 	return_t result;
55 
56 	virtual void initialize();
57 	virtual void updateText();
58 	virtual void left();
59 	virtual void right();
60 	virtual void up();
61 	virtual void down();
62 	virtual void home();
63 	virtual void end();
64 	virtual void backspace();
65 	virtual void supr();
66 	virtual void tab();
67 	virtual void other();
68 	virtual void enter();
69 	virtual void esc();
70 };
71 
72 class LineEditor: public Editor
73 {
74 protected:
75 	void updateText();
76 	void left();
77 	void right();
78 	void home();
79 	void end();
80 	void backspace();
81 	void supr();
82 	void tab();
83 	void other();
84 };
85 
86 class TitleEditor: public LineEditor
87 {
88 protected:
89 	int textLines;
90 	int cursor_col;
91 	int cursor_line;
92 
93 	void initialize();
94 	void updateText();
95 	void up();
96 	void down();
97 };
98 
99 class CategoryEditor: public LineEditor
100 {
101 public:
102 	return_t edit(Window& win, int begin_y, int begin_x, int ncols);
103 protected:
104 	set<wstring>::iterator search;
105 	set<wstring>::iterator first;
106 	int length;
107 
108 	bool cmp(unsigned int idx, wstring str);
109 	void tab();
110 };
111 
112 class HistoryEditor: public LineEditor
113 {
114 protected:
115 	list<wstring> history;
116 	list<wstring>::iterator shown;
117 
118 	void initialize();
119 	void up();
120 	void down();
121 	void enter();
122 	void backspace();
123 };
124 
125 class CmdEditor: public HistoryEditor
126 {
127 protected:
128 	map<wstring,wstring>::iterator com_search;
129 	map<wstring,wstring>::iterator com_first;
130 	set<wstring>::iterator search;
131 	set<wstring>::iterator first;
132 	int length;
133 	int param;
134 
135 	void initialize();
136 	bool cmp(wstring str);
137 	void tab();
138 	void command_completion(wstring& com);
139 	void category_completion(wstring& cat, int num_param);
140 };
141 
142 class DateEditor: public Editor
143 {
144 public:
145 	return_t edit(Window& win, int begin_y, int begin_x);
146 protected:
147 	void updateText();
148 	void left();
149 	void right();
150 	void up();
151 	void down();
152 	void home();
153 	void end();
154 	void other();
155 };
156 
157 class PriorityEditor: public Editor
158 {
159 public:
160 	return_t edit(Window& win, int begin_y, int begin_x);
161 protected:
162 	void updateText();
163 	void up();
164 	void down();
165 	void backspace();
166 	void supr();
167 	void other();
168 };
169 
170 #endif
171