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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#include "cmCursesStringWidget.h"
#include "cmCursesForm.h"
inline int ctrl(int z)
{
return (z&037);
}
cmCursesStringWidget::cmCursesStringWidget(int width, int height,
int left, int top) :
cmCursesWidget(width, height, left, top)
{
m_InEdit = false;
m_Type = cmCacheManager::STRING;
set_field_fore(m_Field, A_NORMAL);
set_field_back(m_Field, A_STANDOUT);
field_opts_off(m_Field, O_STATIC);
}
bool cmCursesStringWidget::HandleInput(int& key, FORM* form, WINDOW* w)
{
// 10 == enter
if (!m_InEdit && ( key != 10 ) )
{
return false;
}
char* originalStr=0;
char debugMessage[128];
// <Enter> is used to change edit mode (like <Esc> in vi).
while(1)
{
sprintf(debugMessage, "String widget handling input, key: %d", key);
cmCursesForm::LogMessage(debugMessage);
// If resize occured during edit, move out of edit mode
if (!m_InEdit && ( key != 10 && key != KEY_ENTER ) )
{
return false;
}
// 10 == enter
if (key == 10 || key == KEY_ENTER)
{
if (m_InEdit)
{
cmCursesForm::LogMessage("String widget leaving edit.");
m_InEdit = false;
delete[] originalStr;
// trick to force forms to update the field buffer
form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_PREV_FIELD);
return true;
}
else
{
cmCursesForm::LogMessage("String widget entering edit.");
m_InEdit = true;
char* buf = field_buffer(m_Field, 0);
originalStr = new char[strlen(buf)+1];
strcpy(originalStr, buf);
}
}
else if ( key == KEY_DOWN || key == ctrl('n') ||
key == KEY_UP || key == ctrl('p') ||
key == KEY_NPAGE || key == ctrl('d') ||
key == KEY_PPAGE || key == ctrl('u'))
{
m_InEdit = false;
delete[] originalStr;
// trick to force forms to update the field buffer
form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_PREV_FIELD);
return false;
}
// esc
else if (key == 27)
{
if (m_InEdit)
{
m_InEdit = false;
this->SetString(originalStr);
delete[] originalStr;
touchwin(w);
wrefresh(w);
return true;
}
}
else if ( key == KEY_LEFT || key == ctrl('b') )
{
form_driver(form, REQ_PREV_CHAR);
}
else if ( key == KEY_RIGHT || key == ctrl('f') )
{
form_driver(form, REQ_NEXT_CHAR);
}
else if ( key == ctrl('k') )
{
form_driver(form, REQ_CLR_EOL);
}
else if ( key == ctrl('a') )
{
form_driver(form, REQ_BEG_FIELD);
}
else if ( key == ctrl('e') )
{
form_driver(form, REQ_END_FIELD);
}
else if ( key == ctrl('d') || key == 127 ||
key == KEY_BACKSPACE || key == KEY_DC )
{
form_driver(form, REQ_DEL_PREV);
}
else
{
form_driver(form, key);
}
touchwin(w);
wrefresh(w);
key=getch();
}
}
void cmCursesStringWidget::SetString(const char* value)
{
this->SetValue(value);
}
const char* cmCursesStringWidget::GetString()
{
return this->GetValue();
}
const char* cmCursesStringWidget::GetValue()
{
return field_buffer(m_Field, 0);
}
|