-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmenumodel.c
More file actions
45 lines (41 loc) · 1.11 KB
/
menumodel.c
File metadata and controls
45 lines (41 loc) · 1.11 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
#include "menumodel.h"
int menumodel_additem(MenuModel* prModel, const int id, const char* sText) {
MenuItem* prItem = NULL;
int rowCount = 0;
if (prModel == NULL) {
return MENUMODEL_NULLPTR;
}
rowCount = prModel->rowCount;
if (rowCount + 1 >= MENUMODEL_ROW_MAX) {
return MENUMODEL_MEMORY;
}
prModel->rowCount++;
prItem = menumodel_get(prModel, rowCount);
if (prItem == NULL) {
return MENUMODEL_FAILURE;
}
prItem->id = id;
strncpy(prItem->text, sText, MENUMODEL_TEXT_LEN);
return MENUMODEL_SUCCESS;
}
MenuItem* menumodel_get(MenuModel* prModel, const int index) {
if (prModel != NULL) {
if ((index >= 0) && (index < prModel->rowCount)) {
return &prModel->items[index];
}
}
return NULL;
}
int menumodel_init(MenuModel* prModel) {
MenuItem* prItem = NULL;
int i = 0;
if (prModel == NULL) {
return MENUMODEL_NULLPTR;
}
for (i = 0; i < MENUMODEL_ROW_MAX; i++) {
prItem = &prModel->items[i];
prItem->id = -1;
}
prModel->rowCount = 0;
return MENUMODEL_SUCCESS;
}