-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogramMenuEditTemplate.c
More file actions
117 lines (103 loc) · 3.08 KB
/
programMenuEditTemplate.c
File metadata and controls
117 lines (103 loc) · 3.08 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
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
#include "programMenuEditTemplate.h"
int currentChoice;
int currentField;
int choicesNumber;
void *currentChoicePointer;
bool somethingDeleted;
EditArguments initEditStructArguments(void *(*getNextItem)(void*),
void *(*getPreviousItem)(void*),
bool (*deleteSelectedItem)(),
void (*printTable)(int),
struct MachineTime *(*getCurrentChoiceRecord)(void*),
int choicesNumber,
void *start)
{
EditArguments arguments;
arguments.getPreviousItem = getPreviousItem;
arguments.getNextItem = getNextItem;
arguments.deleteSelectedItem = deleteSelectedItem;
arguments.printTable = printTable;
arguments.getCurrentChoiceRecord = getCurrentChoiceRecord;
arguments.choicesNumber = choicesNumber;
arguments.start = start;
return arguments;
}
void toogleChoice(WINDOW *win, int choice,int type)
{
mvwchgat(win, choice + TABLE_HEAD_SIZE, 1, TABLE_CHOICE_WIDTH, type, MAIN_THEME_COLOR_PAIR, NULL);
wmove(table, 0, 0);
}
void moveCursorDown(WINDOW *win,void *(*getNextItem)(void *))
{
if (currentChoice >= choicesNumber)
{
currentChoice = choicesNumber;
}
else
{
toogleChoice(win, currentChoice, A_NORMAL);
currentChoicePointer = getNextItem(currentChoicePointer);
currentChoice++;
}
}
void moveCursorUp(WINDOW *win, void *(*getPreviousItem)(void *))
{
if (currentChoice <= 0)
{
currentChoice = 0;
}
else
{
toogleChoice(win, currentChoice, A_NORMAL);
currentChoicePointer = getPreviousItem(currentChoicePointer);
currentChoice--;
}
}
bool editKeypressHandler(WINDOW *win, EditArguments arguments)
{
int key = getch();
switch (key)
{
case KEY_DOWN:
moveCursorDown(win, arguments.getNextItem);
break;
case KEY_UP:
moveCursorUp(win, arguments.getPreviousItem);
break;
case KEY_MAC_ENTER:
editRecord(win, arguments);
break;
case MAC_BACKSPACE:
return arguments.deleteSelectedItem();
break;
case KEY_ESC:
return EXIT;
break;
default:
break;
}
return CONTINUE;
}
void editStruct(WINDOW *win, EditArguments arguments)
{
currentChoice = 0;
currentChoicePointer = arguments.start;
choicesNumber = arguments.choicesNumber;
somethingDeleted = false;
do
{
if (controlsLocked)
{
break;
}
if (somethingDeleted)
{
wclear(win);
somethingDeleted = false;
}
arguments.printTable(HELP_EDIT_MODE);
toogleChoice(win, currentChoice, A_REVERSE);
wrefresh(win);
} while ( EXIT != editKeypressHandler(win, arguments) );
toogleChoice(win, currentChoice, A_NORMAL);
}