Update GWIN list.
Now supports item and page scrolling. A few bugs fixed.
This commit is contained in:
parent
58b5260013
commit
b0b3539639
2 changed files with 213 additions and 202 deletions
|
@ -52,6 +52,7 @@ typedef struct GListObject {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int cnt; // Number of items currently in the list (quicker than counting each time)
|
int cnt; // Number of items currently in the list (quicker than counting each time)
|
||||||
|
int top; // The element at the top of the visible list area
|
||||||
gfxQueueASync list_head; // The list of items
|
gfxQueueASync list_head; // The list of items
|
||||||
} GListObject;
|
} GListObject;
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ int gwinListAddItem(GHandle gh, const char* item, bool_t useAlloc);
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
char* gwinListItemGetText(GHandle gh, int item);
|
const char* gwinListItemGetText(GHandle gh, int item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the ID of an item with a given name
|
* @brief Get the ID of an item with a given name
|
||||||
|
|
412
src/gwin/list.c
412
src/gwin/list.c
|
@ -23,11 +23,15 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// user for the default drawing routine
|
// user for the default drawing routine
|
||||||
#define BORDER 3 // the border from the the text to the frame
|
#define SCROLLWIDTH 16 // the border from the scroll buttons to the frame
|
||||||
#define BORDER_SCROLL 20 // the border from the scroll buttons to the frame
|
|
||||||
#define ARROW 10 // arrow side length
|
#define ARROW 10 // arrow side length
|
||||||
|
#define TEXTGAP 1 // extra vertical padding for text
|
||||||
|
|
||||||
#define widget(gh) ((GListObject *)gh)
|
#define gh2obj ((GListObject *)gh)
|
||||||
|
#define gw2obj ((GListObject *)gw)
|
||||||
|
#define qi2li ((ListItem *)qi)
|
||||||
|
#define qix2li ((ListItem *)qix)
|
||||||
|
#define ple ((GEventGWinList *)pe)
|
||||||
|
|
||||||
#define GLIST_FLG_MULTISELECT (GWIN_FIRST_CONTROL_FLAG << 0)
|
#define GLIST_FLG_MULTISELECT (GWIN_FIRST_CONTROL_FLAG << 0)
|
||||||
#define GLIST_FLG_HASIMAGES (GWIN_FIRST_CONTROL_FLAG << 1)
|
#define GLIST_FLG_HASIMAGES (GWIN_FIRST_CONTROL_FLAG << 1)
|
||||||
|
@ -40,67 +44,13 @@ typedef struct ListItem {
|
||||||
uint16_t param; // A parameter the user can specify himself
|
uint16_t param; // A parameter the user can specify himself
|
||||||
const char* text;
|
const char* text;
|
||||||
#if GWIN_LIST_IMAGES
|
#if GWIN_LIST_IMAGES
|
||||||
gdispImage* pimg;
|
gdispImage* pimg;
|
||||||
#endif
|
#endif
|
||||||
} ListItem;
|
} ListItem;
|
||||||
|
|
||||||
// select the next item in the list
|
|
||||||
static int _selectDown(GWidgetObject *gw) {
|
|
||||||
#define gcw ((GListObject *)gw)
|
|
||||||
|
|
||||||
gfxQueueASyncItem *qi;
|
|
||||||
uint16_t i;
|
|
||||||
|
|
||||||
for (i = 0, qi = gfxQueueASyncPeek(&gcw->list_head); qi; qi = gfxQueueASyncNext(qi), i++) {
|
|
||||||
if (((ListItem*)qi)->flags & GLIST_FLG_SELECTED && i < gcw->cnt - 1) {
|
|
||||||
((ListItem*)qi)->flags &=~ GLIST_FLG_SELECTED;
|
|
||||||
qi = gfxQueueASyncNext(qi);
|
|
||||||
((ListItem*)qi)->flags |= GLIST_FLG_SELECTED;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_gwidgetRedraw((GHandle)gw);
|
|
||||||
|
|
||||||
return ++i;
|
|
||||||
|
|
||||||
#undef gcw
|
|
||||||
}
|
|
||||||
|
|
||||||
// select the previous item in the list
|
|
||||||
static int _selectUp(GWidgetObject *gw) {
|
|
||||||
#define gcw ((GListObject *)gw)
|
|
||||||
|
|
||||||
gfxQueueASyncItem *qi;
|
|
||||||
gfxQueueASyncItem *qi2;
|
|
||||||
uint16_t i;
|
|
||||||
|
|
||||||
qi = gfxQueueASyncPeek(&gcw->list_head);
|
|
||||||
qi2 = qi;
|
|
||||||
|
|
||||||
for (i = 0; qi2; qi2 = gfxQueueASyncNext(qi), i++) {
|
|
||||||
if (((ListItem*)qi2)->flags & GLIST_FLG_SELECTED) {
|
|
||||||
((ListItem*)qi2)->flags &=~ GLIST_FLG_SELECTED;
|
|
||||||
((ListItem*)qi)->flags |= GLIST_FLG_SELECTED;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
qi = qi2;
|
|
||||||
}
|
|
||||||
|
|
||||||
_gwidgetRedraw((GHandle)gw);
|
|
||||||
|
|
||||||
return --i;
|
|
||||||
|
|
||||||
#undef gcw
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sendListEvent(GWidgetObject *gw, int item) {
|
static void sendListEvent(GWidgetObject *gw, int item) {
|
||||||
GSourceListener* psl;
|
GSourceListener* psl;
|
||||||
GEvent* pe;
|
GEvent* pe;
|
||||||
#define pse ((GEventGWinList *)pe)
|
|
||||||
|
|
||||||
// Trigger a GWIN list event
|
// Trigger a GWIN list event
|
||||||
psl = 0;
|
psl = 0;
|
||||||
|
@ -109,128 +59,188 @@ static void sendListEvent(GWidgetObject *gw, int item) {
|
||||||
if (!(pe = geventGetEventBuffer(psl)))
|
if (!(pe = geventGetEventBuffer(psl)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pse->type = GEVENT_GWIN_LIST;
|
ple->type = GEVENT_GWIN_LIST;
|
||||||
pse->list = (GHandle)gw;
|
ple->list = (GHandle)gw;
|
||||||
pse->item = item;
|
ple->item = item;
|
||||||
|
|
||||||
geventSendEvent(psl);
|
geventSendEvent(psl);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef pse
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gwinListDefaultDraw(GWidgetObject* gw, void* param) {
|
static void gwinListDefaultDraw(GWidgetObject* gw, void* param) {
|
||||||
#define gcw ((GListObject *)gw)
|
|
||||||
(void)param;
|
(void)param;
|
||||||
|
|
||||||
uint16_t i, fheight;
|
#if GDISP_NEED_CONVEX_POLYGON
|
||||||
const point upArrow[] = { {0, ARROW}, {ARROW, ARROW}, {ARROW/2, 0} };
|
static const point upArrow[] = { {0, ARROW}, {ARROW, ARROW}, {ARROW/2, 0} };
|
||||||
const point downArrow[] = { {0, 0}, {ARROW, 0}, {ARROW/2, ARROW} };
|
static const point downArrow[] = { {0, 0}, {ARROW, 0}, {ARROW/2, ARROW} };
|
||||||
const gfxQueueASyncItem* qi;
|
#endif
|
||||||
|
|
||||||
fheight = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight);
|
const gfxQueueASyncItem* qi;
|
||||||
|
int i;
|
||||||
|
coord_t y, iheight, iwidth;
|
||||||
|
const GColorSet * ps;
|
||||||
|
|
||||||
// the list frame
|
ps = (gw->g.flags & GWIN_FLG_ENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled;
|
||||||
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->enabled.edge);
|
iheight = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight) + TEXTGAP;
|
||||||
gdispDrawLine(gw->g.x + gw->g.width - BORDER_SCROLL, gw->g.y, gw->g.x + gw->g.width - BORDER_SCROLL, gw->g.y + gw->g.height, gw->pstyle->enabled.edge);
|
|
||||||
gdispDrawLine(gw->g.x + gw->g.width - BORDER_SCROLL, gw->g.y + BORDER_SCROLL, gw->g.x + gw->g.width, gw->g.y + BORDER_SCROLL, gw->pstyle->enabled.edge);
|
|
||||||
gdispDrawLine(gw->g.x + gw->g.width - BORDER_SCROLL, gw->g.y + gw->g.height - BORDER_SCROLL, gw->g.x + gw->g.width, gw->g.y + gw->g.height - BORDER_SCROLL, gw->pstyle->enabled.edge);
|
|
||||||
|
|
||||||
// the up-button
|
// the scroll area
|
||||||
gdispFillConvexPoly(gw->g.x + gw->g.width - BORDER_SCROLL + ARROW/2, gw->g.y + BORDER_SCROLL - ARROW - ARROW/2, upArrow, 3, gw->pstyle->enabled.edge);
|
if (gw2obj->cnt > (gw->g.height-2) / iheight) {
|
||||||
|
iwidth = gw->g.width - (SCROLLWIDTH+3);
|
||||||
// the down-button
|
gdispFillArea(gw->g.x+iwidth+2, gw->g.y+1, SCROLLWIDTH, gw->g.height-2, gdispBlendColor(ps->fill, gw->pstyle->background, 128));
|
||||||
gdispFillConvexPoly(gw->g.x + gw->g.width - BORDER_SCROLL + ARROW/2, gw->g.y + gw->g.height - BORDER_SCROLL + ARROW/2, downArrow, 3, gw->pstyle->enabled.edge);
|
gdispDrawLine(gw->g.x+iwidth+1, gw->g.y+1, gw->g.x+iwidth+1, gw->g.y+gw->g.height-2, ps->edge);
|
||||||
|
#if GDISP_NEED_CONVEX_POLYGON
|
||||||
|
gdispFillConvexPoly(gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+(ARROW/2+1), upArrow, 3, ps->fill);
|
||||||
|
gdispFillConvexPoly(gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+gw->g.height-(ARROW+ARROW/2+1), downArrow, 3, ps->fill);
|
||||||
|
#else
|
||||||
|
#warning "GWIN: Lists display better when GDISP_NEED_CONVEX_POLGON is turned on"
|
||||||
|
gdispFillArea(gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+(ARROW/2+1), ARROW, ARROW, ps->fill);
|
||||||
|
gdispFillArea(gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+gw->g.height-(ARROW+ARROW/2+1), ARROW, ARROW, ps->fill);
|
||||||
|
#endif
|
||||||
|
} else
|
||||||
|
iwidth = gw->g.width - 2;
|
||||||
|
|
||||||
for (qi = gfxQueueASyncPeek(&gcw->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i += fheight + 2*BORDER) {
|
|
||||||
if (((ListItem*)qi)->flags & GLIST_FLG_SELECTED) {
|
// Find the top item
|
||||||
gdispFillStringBox(gw->g.x + BORDER, gw->g.y + BORDER + i, gw->g.width - 2*BORDER - BORDER_SCROLL, fheight, ((ListItem*)qi)->text, gwinGetDefaultFont(), gw->pstyle->background, gw->pstyle->enabled.text, justifyLeft);
|
for (qi = gfxQueueASyncPeek(&gw2obj->list_head), i = 0; i < gw2obj->top && qi; qi = gfxQueueASyncNext(qi), i++);
|
||||||
|
|
||||||
|
// Draw until we run out of room or items
|
||||||
|
for (y=1; y+iheight < gw->g.height-1 && qi; qi = gfxQueueASyncNext(qi), y += iheight) {
|
||||||
|
if (qi2li->flags & GLIST_FLG_SELECTED) {
|
||||||
|
//gdispFillStringBox(gw->g.x+1, gw->g.y+y, iwidth, iheight, qi2li->text, gwinGetDefaultFont(), gw->pstyle->background, ps->text, justifyLeft);
|
||||||
|
gdispFillStringBox(gw->g.x+1, gw->g.y+y, iwidth, iheight, qi2li->text, gwinGetDefaultFont(), ps->text, ps->fill, justifyLeft);
|
||||||
} else {
|
} else {
|
||||||
gdispFillStringBox(gw->g.x + BORDER, gw->g.y + BORDER + i, gw->g.width - 2*BORDER - BORDER_SCROLL, fheight, ((ListItem*)qi)->text, gwinGetDefaultFont(), gw->pstyle->enabled.text, gw->pstyle->background, justifyLeft);
|
gdispFillStringBox(gw->g.x+1, gw->g.y+y, iwidth, iheight, qi2li->text, gwinGetDefaultFont(), ps->text, gw->pstyle->background, justifyLeft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef gcw
|
// Fill any remaining item space
|
||||||
|
if (y < gw->g.height-1)
|
||||||
|
gdispFillArea(gw->g.x+1, gw->g.y+y, iwidth, gw->g.height-1-y, gw->pstyle->background);
|
||||||
|
|
||||||
|
// the list frame
|
||||||
|
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, ps->edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GINPUT_NEED_MOUSE
|
#if GINPUT_NEED_MOUSE
|
||||||
// a mouse down has occured over the list area
|
// a mouse down has occurred over the list area
|
||||||
static void MouseDown(GWidgetObject* gw, coord_t x, coord_t y) {
|
static void MouseDown(GWidgetObject* gw, coord_t x, coord_t y) {
|
||||||
#define gcw ((GListObject *)gw)
|
const gfxQueueASyncItem* qi;
|
||||||
#define li ((ListItem *)qi)
|
int item, i, pgsz;
|
||||||
(void) x;
|
coord_t iheight;
|
||||||
|
(void) x;
|
||||||
|
|
||||||
uint16_t i, item_id, item_height;
|
iheight = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight) + TEXTGAP;
|
||||||
const gfxQueueASyncItem* qi;
|
pgsz = (gw->g.height-2)/iheight;
|
||||||
|
if (pgsz < 1) pgsz = 1;
|
||||||
|
|
||||||
item_id = -1;
|
// Handle click over the scroll bar
|
||||||
|
if (gw2obj->cnt > pgsz && x >= gw->g.width-(SCROLLWIDTH+2)) {
|
||||||
if (x > gw->g.width - BORDER_SCROLL) {
|
if (y < 2*ARROW) {
|
||||||
if (y < BORDER_SCROLL)
|
if (gw2obj->top > 0) {
|
||||||
item_id = _selectUp(gw);
|
gw2obj->top--;
|
||||||
else if (y > gw->g.height - BORDER_SCROLL)
|
_gwidgetRedraw(&gw->g);
|
||||||
item_id = _selectDown(gw);
|
}
|
||||||
} else if (x < gw->g.width - BORDER_SCROLL - BORDER) {
|
} else if (y >= gw->g.height - 2*ARROW) {
|
||||||
item_height = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight) + 2*BORDER;
|
if (gw2obj->top < gw2obj->cnt - pgsz) {
|
||||||
item_id = (y) / item_height;
|
gw2obj->top++;
|
||||||
|
_gwidgetRedraw(&gw->g);
|
||||||
for(qi = gfxQueueASyncPeek(&gcw->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
}
|
||||||
if (item_id == i)
|
} else if (y < gw->g.height/2) {
|
||||||
li->flags |= GLIST_FLG_SELECTED;
|
if (gw2obj->top > 0) {
|
||||||
else
|
if (gw2obj->top > pgsz)
|
||||||
li->flags &=~ GLIST_FLG_SELECTED;
|
gw2obj->top -= pgsz;
|
||||||
|
else
|
||||||
|
gw2obj->top = 0;
|
||||||
|
_gwidgetRedraw(&gw->g);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (gw2obj->top < gw2obj->cnt - pgsz) {
|
||||||
|
if (gw2obj->top < gw2obj->cnt - 2*pgsz)
|
||||||
|
gw2obj->top += pgsz;
|
||||||
|
else
|
||||||
|
gw2obj->top = gw2obj->cnt - pgsz;
|
||||||
|
_gwidgetRedraw(&gw->g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_gwidgetRedraw((GHandle)gw);
|
// Handle click over the list area
|
||||||
|
item = gw2obj->top + y / iheight;
|
||||||
|
|
||||||
// do not generate an event if an empty section of the list has has been selected
|
if (item < 0 || item >= gw2obj->cnt)
|
||||||
if (item_id < 0 || item_id > gcw->cnt - 1)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sendListEvent(gw, item_id);
|
for(qi = gfxQueueASyncPeek(&gw2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
if (item == i)
|
||||||
|
qi2li->flags |= GLIST_FLG_SELECTED;
|
||||||
|
else
|
||||||
|
qi2li->flags &=~ GLIST_FLG_SELECTED;
|
||||||
|
}
|
||||||
|
|
||||||
#undef gcw
|
_gwidgetRedraw(&gw->g);
|
||||||
#undef li
|
sendListEvent(gw, item);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GINPUT_NEED_TOGGLE
|
#if GINPUT_NEED_TOGGLE
|
||||||
// a toggle-on has occurred
|
// a toggle-on has occurred
|
||||||
static void ToggleOn(GWidgetObject *gw, uint16_t role) {
|
static void ToggleOn(GWidgetObject *gw, uint16_t role) {
|
||||||
#define gcw ((GListObject *)gw)
|
const gfxQueueASyncItem * qi;
|
||||||
|
const gfxQueueASyncItem * qix;
|
||||||
|
int i;
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
// select down
|
// select down
|
||||||
case 0:
|
case 0:
|
||||||
_selectDown(gw);
|
for (i = 0, qi = gfxQueueASyncPeek(&gw2obj->list_head); qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
if ((qi2li->flags & GLIST_FLG_SELECTED)) {
|
||||||
|
qix = gfxQueueASyncNext(qi);
|
||||||
|
if (qix) {
|
||||||
|
qi2li->flags &=~ GLIST_FLG_SELECTED;
|
||||||
|
qix2li->flags |= GLIST_FLG_SELECTED;
|
||||||
|
_gwidgetRedraw(&gw->g);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// select up
|
// select up
|
||||||
case 1:
|
case 1:
|
||||||
_selectUp(gw);
|
qi = gfxQueueASyncPeek(&gw2obj->list_head);
|
||||||
|
qix = 0;
|
||||||
|
|
||||||
|
for (i = 0; qi; qix = qi, qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
if ((qi2li->flags & GLIST_FLG_SELECTED))
|
||||||
|
if (qix) {
|
||||||
|
qi2li->flags &=~ GLIST_FLG_SELECTED;
|
||||||
|
qix2li->flags |= GLIST_FLG_SELECTED;
|
||||||
|
_gwidgetRedraw(&gw->g);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef gcw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
|
static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
|
||||||
if (role)
|
if (role)
|
||||||
((GListObject *)gw)->t_up = instance;
|
gw2obj->t_up = instance;
|
||||||
else
|
else
|
||||||
((GListObject *)gw)->t_dn = instance;
|
gw2obj->t_dn = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
|
static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) {
|
||||||
return role ? ((GListObject *)gw)->t_up : ((GListObject *)gw)->t_dn;
|
return role ? gw2obj->t_up : gw2obj->t_dn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void _destroy(GHandle gh) {
|
static void _destroy(GHandle gh) {
|
||||||
const gfxQueueASyncItem* qi;
|
const gfxQueueASyncItem* qi;
|
||||||
|
|
||||||
while((qi = gfxQueueASyncGet(&((GListObject *)gh)->list_head)))
|
while((qi = gfxQueueASyncGet(&gh2obj->list_head)))
|
||||||
gfxFree((void *)qi);
|
gfxFree((void *)qi);
|
||||||
|
|
||||||
_gwidgetDestroy(gh);
|
_gwidgetDestroy(gh);
|
||||||
|
@ -271,31 +281,32 @@ static const gwidgetVMT listVMT = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
GHandle gwinListCreate(GListObject* widget, GWidgetInit* pInit) {
|
GHandle gwinListCreate(GListObject* gobj, GWidgetInit* pInit) {
|
||||||
if (!(widget = (GListObject *)_gwidgetCreate(&widget->w, pInit, &listVMT)))
|
if (!(gobj = (GListObject *)_gwidgetCreate(&gobj->w, pInit, &listVMT)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// initialize the item queue
|
// initialize the item queue
|
||||||
gfxQueueASyncInit(&(widget->list_head));
|
gfxQueueASyncInit(&gobj->list_head);
|
||||||
widget->cnt = 0;
|
gobj->cnt = 0;
|
||||||
|
gobj->top = 0;
|
||||||
|
|
||||||
gwinSetVisible(&widget->w.g, pInit->g.show);
|
gwinSetVisible(&gobj->w.g, pInit->g.show);
|
||||||
|
|
||||||
return (GHandle)widget;
|
return (GHandle)gobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) {
|
int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) {
|
||||||
size_t sz;
|
|
||||||
ListItem *newItem;
|
ListItem *newItem;
|
||||||
|
|
||||||
sz = useAlloc ? sizeof(ListItem)+strlen(item_name)+1 : sizeof(ListItem);
|
|
||||||
|
|
||||||
if (!(newItem = (ListItem *)gfxAlloc(sz)))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (useAlloc) {
|
if (useAlloc) {
|
||||||
|
if (!(newItem = (ListItem *)gfxAlloc(sizeof(ListItem)+strlen(item_name)+1)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
strcpy((char *)(newItem+1), item_name);
|
strcpy((char *)(newItem+1), item_name);
|
||||||
item_name = (const char *)(newItem+1);
|
item_name = (const char *)(newItem+1);
|
||||||
|
} else {
|
||||||
|
if (!(newItem = (ListItem *)gfxAlloc(sizeof(ListItem))))
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the item is not selected when added
|
// the item is not selected when added
|
||||||
|
@ -304,43 +315,43 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) {
|
||||||
newItem->text = item_name;
|
newItem->text = item_name;
|
||||||
|
|
||||||
// select the item if it's the first in the list
|
// select the item if it's the first in the list
|
||||||
if (widget(gh)->cnt == 0)
|
if (gh2obj->cnt == 0)
|
||||||
newItem->flags |= GLIST_FLG_SELECTED;
|
newItem->flags |= GLIST_FLG_SELECTED;
|
||||||
|
|
||||||
// add the new item to the list
|
// add the new item to the list
|
||||||
gfxQueueASyncPut(&widget(gh)->list_head, &newItem->q_item);
|
gfxQueueASyncPut(&gh2obj->list_head, &newItem->q_item);
|
||||||
|
|
||||||
// increment the total amount of entries in the list widget
|
// increment the total amount of entries in the list widget
|
||||||
widget(gh)->cnt++;
|
gh2obj->cnt++;
|
||||||
|
|
||||||
|
_gwidgetRedraw(gh);
|
||||||
|
|
||||||
// return the position in the list (-1 because we start with index 0)
|
// return the position in the list (-1 because we start with index 0)
|
||||||
return widget(gh)->cnt-1;
|
return gh2obj->cnt-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* gwinListItemGetText(GHandle gh, int item) {
|
const char* gwinListItemGetText(GHandle gh, int item) {
|
||||||
const gfxQueueASyncItem* qi;
|
const gfxQueueASyncItem* qi;
|
||||||
uint16_t i;
|
int i;
|
||||||
|
|
||||||
// is it a valid handle?
|
// is it a valid handle?
|
||||||
if (gh->vmt != (gwinVMT *)&listVMT)
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// watch out for an invalid item
|
// watch out for an invalid item
|
||||||
if (item < 0 || item > (widget(gh)->cnt) - 1)
|
if (item < 0 || item >= gh2obj->cnt)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
qi = gfxQueueASyncPeek(&widget(gh)->list_head);
|
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
if (i == item)
|
||||||
for (i = 0; i < item; i++) {
|
return qi2li->text;
|
||||||
qi = gfxQueueASyncNext(qi);
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
return ((ListItem*)qi)->text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gwinListFindText(GHandle gh, const char* text) {
|
int gwinListFindText(GHandle gh, const char* text) {
|
||||||
const gfxQueueASyncItem* qi;
|
const gfxQueueASyncItem* qi;
|
||||||
uint16_t i;
|
int i;
|
||||||
|
|
||||||
// is it a valid handle?
|
// is it a valid handle?
|
||||||
if (gh->vmt != (gwinVMT *)&listVMT)
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
|
@ -350,9 +361,7 @@ int gwinListFindText(GHandle gh, const char* text) {
|
||||||
if (!text)
|
if (!text)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
qi = gfxQueueASyncPeek(&widget(gh)->list_head);
|
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
|
||||||
for(qi = gfxQueueASyncPeek(&widget(gh)->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
|
||||||
if (strcmp(((ListItem *)qi)->text, text) == 0)
|
if (strcmp(((ListItem *)qi)->text, text) == 0)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -361,15 +370,15 @@ int gwinListFindText(GHandle gh, const char* text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int gwinListGetSelected(GHandle gh) {
|
int gwinListGetSelected(GHandle gh) {
|
||||||
const gfxQueueASyncItem *qi;
|
const gfxQueueASyncItem * qi;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// is it a valid handle?
|
// is it a valid handle?
|
||||||
if (gh->vmt != (gwinVMT *)&listVMT)
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for(qi = gfxQueueASyncPeek(&widget(gh)->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
if (((ListItem*)qi)->flags & GLIST_FLG_SELECTED)
|
if (qi2li->flags & GLIST_FLG_SELECTED)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,99 +386,100 @@ int gwinListGetSelected(GHandle gh) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void gwinListItemSetParam(GHandle gh, int item, uint16_t param) {
|
void gwinListItemSetParam(GHandle gh, int item, uint16_t param) {
|
||||||
const gfxQueueASyncItem* qi;
|
const gfxQueueASyncItem * qi;
|
||||||
uint16_t i;
|
int i;
|
||||||
|
|
||||||
// is it a valid handle?
|
// is it a valid handle?
|
||||||
if (gh->vmt != (gwinVMT *)&listVMT)
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// watch out for an invalid item
|
// watch out for an invalid item
|
||||||
if (item < 0 || item > (widget(gh)->cnt) - 1)
|
if (item < 0 || item > (gh2obj->cnt) - 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qi = gfxQueueASyncPeek(&widget(gh)->list_head);
|
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
if (i == item) {
|
||||||
for (i = 0; i < item; i++) {
|
qi2li->param = param;
|
||||||
((ListItem*)qi)->param = param;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gwinListDeleteAll(GHandle gh) {
|
void gwinListDeleteAll(GHandle gh) {
|
||||||
const gfxQueueASyncItem* qi;
|
gfxQueueASyncItem* qi;
|
||||||
|
|
||||||
while((qi = gfxQueueASyncGet(&((GListObject *)gh)->list_head)))
|
// is it a valid handle?
|
||||||
gfxFree((void *)qi);
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while((qi = gfxQueueASyncGet(&gh2obj->list_head)))
|
||||||
|
gfxFree(qi);
|
||||||
|
|
||||||
|
gh2obj->cnt = 0;
|
||||||
|
gh2obj->top = 0;
|
||||||
|
_gwidgetRedraw(gh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gwinListItemDelete(GHandle gh, int item) {
|
void gwinListItemDelete(GHandle gh, int item) {
|
||||||
const gfxQueueASyncItem* qi;
|
const gfxQueueASyncItem * qi;
|
||||||
uint16_t i;
|
int i;
|
||||||
|
|
||||||
// is it a valid handle?
|
// is it a valid handle?
|
||||||
if (gh->vmt != (gwinVMT *)&listVMT)
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// watch out for an invalid item
|
// watch out for an invalid item
|
||||||
if (item < 0 || item > (widget(gh)->cnt) - 1)
|
if (item < 0 || item >= gh2obj->cnt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qi = gfxQueueASyncPeek(&widget(gh)->list_head);
|
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
if (i == item) {
|
||||||
// get our item pointer
|
gfxQueueASyncRemove(&gh2obj->list_head, (gfxQueueASyncItem*)qi);
|
||||||
for (i = 0; i < item; i++) {
|
gfxFree((void *)qi);
|
||||||
qi = gfxQueueASyncNext(qi);
|
if (gh2obj->top >= item && gh2obj->top)
|
||||||
|
gh2obj->top--;
|
||||||
|
_gwidgetRedraw(gh);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gfxQueueASyncRemove(&widget(gh)->list_head, qi);
|
|
||||||
gfxFree((void*)qi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t gwinListItemGetParam(GHandle gh, int item) {
|
uint16_t gwinListItemGetParam(GHandle gh, int item) {
|
||||||
const gfxQueueASyncItem* qi;
|
const gfxQueueASyncItem * qi;
|
||||||
uint16_t i;
|
int i;
|
||||||
|
|
||||||
// is it a valid handle?
|
// is it a valid handle?
|
||||||
if (gh->vmt != (gwinVMT *)&listVMT)
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// watch out for an invalid item
|
// watch out for an invalid item
|
||||||
if (item < 0 || item > (widget(gh)->cnt) - 1)
|
if (item < 0 || item > (gh2obj->cnt) - 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
qi = gfxQueueASyncPeek(&widget(gh)->list_head);
|
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
if (i == item)
|
||||||
for (i = 0; i < item; i++) {
|
return qi2li->param;
|
||||||
qi = gfxQueueASyncNext(qi);
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
return ((ListItem*)qi)->param;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t gwinListItemIsSelected(GHandle gh, int item) {
|
bool_t gwinListItemIsSelected(GHandle gh, int item) {
|
||||||
const gfxQueueASyncItem* qi;
|
const gfxQueueASyncItem * qi;
|
||||||
uint16_t i;
|
int i;
|
||||||
|
|
||||||
// is it a valid handle?
|
// is it a valid handle?
|
||||||
if (gh->vmt != (gwinVMT *)&listVMT)
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// watch out for an invalid item
|
// watch out for an invalid item
|
||||||
if (item < 0 || item > (widget(gh)->cnt) - 1)
|
if (item < 0 || item > (gh2obj->cnt) - 1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
qi = gfxQueueASyncPeek(&widget(gh)->list_head);
|
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
if (i == item)
|
||||||
for (i = 0; i < item; i++) {
|
return (qi2li->flags & GLIST_FLG_SELECTED) ? TRUE : FALSE;
|
||||||
qi = gfxQueueASyncNext(qi);
|
|
||||||
}
|
}
|
||||||
|
return FALSE;
|
||||||
if (((ListItem*)qi)->flags & GLIST_FLG_SELECTED)
|
|
||||||
return TRUE;
|
|
||||||
else
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gwinListItemCount(GHandle gh) {
|
int gwinListItemCount(GHandle gh) {
|
||||||
|
@ -477,7 +487,7 @@ int gwinListItemCount(GHandle gh) {
|
||||||
if (gh->vmt != (gwinVMT *)&listVMT)
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return widget(gh)->cnt;
|
return gh2obj->cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GFX_USE_GWIN && GWIN_NEED_LIST
|
#endif // GFX_USE_GWIN && GWIN_NEED_LIST
|
||||||
|
|
Loading…
Add table
Reference in a new issue