-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInputBox.cc
More file actions
52 lines (45 loc) · 1.13 KB
/
InputBox.cc
File metadata and controls
52 lines (45 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// InputBox
// Simple dialog box which prompts you about something
// It centers itself on its parent
#include "InputBox.h"
#include "InputLine.h"
#include "TTY.h"
#include "Color.h"
#include <cstring>
class InputBoxedLine : public InputLine
{
public:
InputBoxedLine(Window *_parent, int _w, int _h, int _x, int _y, history_id _id)
: InputLine (_parent, _w, _h, None, _x, _y, _id)
{
};
private:
virtual void execute() {
((InputBox*)parent)->execute(input_buf);
}
};
InputBox::InputBox (Window *_parent, char *_prompt, history_id id)
: Window(_parent, std::strlen(_prompt)+4, 7, Bordered, xy_center,xy_center ),
prompt(strdup(_prompt)) {
input = new InputBoxedLine(this,
width-2,1, // 2 chars smaller than the inside
1,3, // 1 char from left, in the middle
id);
input->set_prompt("");
}
void InputBox::redraw() {
set_color (bg_blue|fg_white);
clear();
gotoxy(1,1);
print (prompt);
dirty = false;
}
bool InputBox::keypress(int key) {
if (key == key_escape) {
if (canCancel())
die();
return true;
}
else
return Window::keypress(key);
}