Select one of the symbols to view example projects that use it.
 
Outline
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "GUIDEMO.h"
#define LISTVIEW_SIZE_X
#define MIN_SPACE
<anonymous enum>
COL_PROP
ACTION_ITEM
_pNames
_aColProps
_aAction
_aColor
_AddRow(GUI_HWIN, int)
_InitListview(GUI_HWIN)
_Action(GUI_HWIN)
_DemoListview()
GUIDEMO_Listview()
Files
loading...
CodeScopeSTM32 Libraries and SamplesSTemWin_SampleDemoSTemWin/App/GUIDEMO_Listview.c
 
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/********************************************************************* * Portions COPYRIGHT(c) 2016 STMicroelectronics * * Portions SEGGER Microcontroller GmbH & Co. KG * * Solutions for real time microcontroller applications * ********************************************************************** * * * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG * * * * Internet: www.segger.com Support: support@segger.com * * * ********************************************************************** ** emWin V5.28 - Graphical user interface for embedded applications ** All Intellectual Property rights in the Software belongs to SEGGER. emWin is protected by international copyright laws. Knowledge of the source code may not be used to write a similar product. This file may only be used in accordance with the following terms: The software has been licensed to STMicroelectronics International N.V. a Dutch company with a Swiss branch and its headquarters in Plan- les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_ troller products commercialized by Licensee only, sublicensed and dis_ tributed under the terms and conditions of the End User License Agree_ ment supplied by STMicroelectronics International N.V. Full source code is available at: www.segger.com We appreciate your understanding and fairness. ---------------------------------------------------------------------- File : GUIDEMO_Listview.c Purpose : Listview demo ---------------------------------------------------------------------- *//* ... */ /** ****************************************************************************** * @file GUIDEMO_Listview.c * @author MCD Application Team * @brief Listview demo ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include "GUIDEMO.h" #if (SHOW_GUIDEMO_LISTVIEW && GUI_WINSUPPORT) /********************************************************************* * * Defines * ********************************************************************** *//* ... */ #define LISTVIEW_SIZE_X 210 #define MIN_SPACE 5 /********************************************************************* * * Types * ********************************************************************** *//* ... */ enum { JOB_ADDROWS = 1, JOB_SETSORT, JOB_REVERSE, JOB_INCSEL, JOB_DECSEL, JOB_COLOR ...}; /********************************************************************* * * COL_PROP *//* ... */ typedef struct { char * pText; int Width; int Align; int (* fpCompare)(const void * p0, const void * p1); ...} COL_PROP; /********************************************************************* * * ACTION_ITEM *//* ... */ typedef struct { int Delay; int Job; const char * pDescription; ...} ACTION_ITEM; /********************************************************************* * * Static data * ********************************************************************** *//* ... */ /********************************************************************* * * _pNames *//* ... */ static const char * _pNames[] = { "Adina", "Adis", "Aimee", "Alea", "Alessio", "Aletta", "Alexia", "Alissa", "Amelia", "Anakin", "Ania", "Ankea", "Annalies", "Annina", "Annrike", "Arkadius", "Arvin", "Aurelia", "Ava", "Beeke", "Benita", "Bennit", "Bent", "Berenike", "Berit", "Birk", "Bosse", "Carsta", "Catalina", "Celia", "Charis", "Charlin", "Charlotta", "Cordelia", "Corey", "Cornelis", "Corvin", "Cosima", "Crisula", "Darian", "Darina", "Deik", "Derek", "Destina", "Devin", "Diane", "Dina", "Dion", "Dorette", "Dorle", "Duncan", "Eddy", "Einar", "Elea", "Elin", "Elita", "Elona", "Elouise", "Emilian", "Emina", "Emmeline", "Enna", "Estelle", "Etta", "Fabiola", "Fabrice", "Falko", "Felice", "Feline", "Femke", "Fiete", "Filippa", "Fine", "Finia", "Finley", "Fleur", "Florentine" "Florenz", "Florin", "Floyd", "Fokko", "Fritzi", "Gero", "Gerret", "Gerwin", "Gideon", "Gillian", "Glen", "Gunilla", "Hanka", "Heinke", "Helmar", "Henner", "Hennes", "Henrieke", "Immo", "India", "Isalie", "Iven", "Jade", "Janice", "Janika", "Janka", "Janneke", "Jannika", "Jano", "Jarla", "Jarne", "Jarno", "Jaromir", "Jaron", "Jelana", "Jesper", "Joleen", "Jolie", "Jonte", "Joost", "J�rdis", "Joris", "Josie", "Josina", "Jula", "Julina", "Jytte", "Kalle", "Kennet", "Keno", "Kiana", "Kieran", "Laila", "Laureen", "Laurens", "Laurent", "Lauritz", "Leana", "Leandra", "Leandro", "Len", "Lenore", "Leona", "Leonore", "Levke", "Lewin", "Lientje", "Lilith", "Line", "Linna", "Linnea", "Lisanne", "Livia", "Lorena", "Lorna", "Lovis", "Luana", "Ludger", "Madita", "Mads", "Maiga", "Mailin", "Malina", "Manja", "Marieke", "Marielle", "Mariette", "Mariola", "Marla", "Marlena", "Marlin", "Marlo", "Marthe", "Martje", "Matz", "Maureen", "Mayra", "Medina", "Melda", "Melek", "Melike", "Melinda", "Melis", "Melisa", "Merit", "Mieke", "Mila", "Mina", "Mio", "Mirella", "Momke", "Momme", "Morris", "Nantke", "Nelson", "Nika", "Norwin", "Oke", "Onno", "Otis", "Ove", "Peer", "Pelle", "Philine", "Philomena", "Quentin", "Quint", "Rahel", "Raik", "Riana", "Ricardo", "Rika", "Rixa", "Rolex", "Ruwen", "Ryan", "Salma", "Sandrine", "Severin", "Sidonie", "Silas", "Silja", "Simeon", "Sinja", "Smilla", "Stig", "Stine", "Talisa", "Tamina", "Tammo", "Tara", "Thyra", "Tiana", "Tjalf", "Tjark", "Tjelle", "Tjorben", "Tomma", "Tore", "Vanity", "Violet", "Violetta", "Wilko", "Wulf", "Yasmina", "Ylvie", "Younes", "Yves", "Yvette", ...}; /********************************************************************* * * _aColProps *//* ... */ static const COL_PROP _aColProps[] = { { "Name", 70, GUI_TA_LEFT, LISTVIEW_CompareText}, { "Code", 50, GUI_TA_HCENTER, LISTVIEW_CompareText}, { "Balance", 60, GUI_TA_RIGHT, LISTVIEW_CompareDec } ...}; /********************************************************************* * * _aAction *//* ... */ static const ACTION_ITEM _aAction[] = { { 0, JOB_ADDROWS, "Adding some rows" }, { 900, 0, NULL }, { 500, 0, "Enable sorting" }, { 500, 0, NULL }, { 600, JOB_SETSORT, NULL }, { 600, JOB_SETSORT, NULL }, { 600, JOB_SETSORT, NULL }, { 500, 0, "Using reverse/normal\nsorting order" }, { 500, 0, NULL }, { 600, JOB_REVERSE, NULL }, { 600, JOB_REVERSE, NULL }, { 600, JOB_REVERSE, NULL }, { 500, 0, "Changing selection" }, { 500, 0, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_INCSEL, NULL }, { 50, JOB_DECSEL, NULL }, { 50, JOB_DECSEL, NULL }, { 50, JOB_DECSEL, NULL }, { 50, JOB_DECSEL, NULL }, { 50, JOB_DECSEL, NULL }, { 500, 0, "Setting some individual colors" }, { 500, 0, NULL }, { 50, JOB_COLOR, NULL }, {1800, 0, NULL }, ...}; /********************************************************************* * * _aColor *//* ... */ static const GUI_COLOR _aColor[] = { GUI_BLUE , GUI_GREEN , GUI_RED , GUI_CYAN , GUI_MAGENTA , GUI_YELLOW , GUI_LIGHTBLUE , GUI_LIGHTGREEN , GUI_LIGHTRED , GUI_LIGHTCYAN , GUI_LIGHTMAGENTA, GUI_LIGHTYELLOW , GUI_DARKBLUE , GUI_DARKGREEN , GUI_DARKRED , GUI_DARKCYAN , GUI_DARKMAGENTA , GUI_DARKYELLOW , GUI_WHITE , GUI_LIGHTGRAY , GUI_GRAY , GUI_DARKGRAY , GUI_BLACK , GUI_BROWN , ...}; /********************************************************************* * * Static code * ********************************************************************** *//* ... */ /********************************************************************* * * _AddRow * * Purpose: * Inserts or adds a new row of data to the given LISTVIEW * * Parameter: * hItem - Handle of LISTVIEW widget * Insert - 1 for inserting a row,0 for adding a row *//* ... */ static int _AddRow(WM_HWIN hItem, int Insert) { int i, r; char * pText[3]; char acText[3][20] = {{0}}; // // Create name field // i = rand() % GUI_COUNTOF(_pNames); strcpy(acText[0], _pNames[i]); // // Create code field // for (i = 0; i < 5; i++) { acText[1][i] = rand() % 26 + 'A'; }for (i = 0; i < 5; i++) { ... } // // Create balance field // i = (rand() % 10000) - 5000; sprintf(acText[2], "%i", i); // // Fill pointer array // for (i = 0; i < 3; i++) { pText[i] = acText[i]; }for (i = 0; i < 3; i++) { ... } // // Add/Insert row // if (Insert) { r = LISTVIEW_InsertRow(hItem, 0, (const GUI_ConstString *)pText); }if (Insert) { ... } else { r = LISTVIEW_AddRow(hItem, (const GUI_ConstString *)pText); }else { ... } return r; }{ ... } /********************************************************************* * * _InitListview * * Purpose: * Adds some data to the listview widget *//* ... */ static void _InitListview(WM_HWIN hList) { int i; HEADER_SetDragLimit(LISTVIEW_GetHeader(hList), 1); LISTVIEW_SetAutoScrollV(hList, 1); LISTVIEW_SetGridVis(hList, 1); LISTVIEW_SetRBorder(hList, 5); LISTVIEW_SetLBorder(hList, 5); for (i = 0; i < 3; i++) { LISTVIEW_AddColumn(hList, _aColProps[i].Width, _aColProps[i].pText, _aColProps[i].Align); LISTVIEW_SetCompareFunc(hList, i, _aColProps[i].fpCompare); }for (i = 0; i < 3; i++) { ... } LISTVIEW_EnableSort(hList); }{ ... } /********************************************************************* * * _Action * * Purpose: * Does some action with the widget *//* ... */ static void _Action(WM_HWIN hList) { unsigned ColoredCol = 0; unsigned ColoredRow = 0; unsigned i, NumRows; int ColorIndex = 0; int Reverse = 0; int SortedColumn = -1; int Index; Index = 0; do { if (_aAction[Index].pDescription) { GUIDEMO_ShowInfo(_aAction[Index].pDescription); }if (_aAction[Index].pDescription) { ... } switch (_aAction[Index].Job) { case JOB_COLOR: NumRows = LISTVIEW_GetNumRows(hList); for (i = 0; i < NumRows; i++) { LISTVIEW_SetItemBkColor(hList, ColoredCol, ColoredRow, LISTVIEW_CI_UNSEL, _aColor[ColorIndex]); if (++ColorIndex == GUI_COUNTOF(_aColor)) { ColorIndex = 0; }if (++ColorIndex == GUI_COUNTOF(_aColor)) { ... } if (++ColoredCol == LISTVIEW_GetNumColumns(hList)) { ColoredCol = 0; }if (++ColoredCol == LISTVIEW_GetNumColumns(hList)) { ... } if (++ColoredRow == NumRows) { ColoredRow = 0; }if (++ColoredRow == NumRows) { ... } }for (i = 0; i < NumRows; i++) { ... } break;case JOB_COLOR: case JOB_INCSEL: LISTVIEW_IncSel(hList); break;case JOB_INCSEL: case JOB_DECSEL: LISTVIEW_DecSel(hList); break;case JOB_DECSEL: case JOB_REVERSE: Reverse ^= 1; LISTVIEW_SetSort(hList, SortedColumn, Reverse); break;case JOB_REVERSE: case JOB_ADDROWS: for (i = 0; i < 40; i++) { _AddRow(hList, 0); }for (i = 0; i < 40; i++) { ... } break;case JOB_ADDROWS: case JOB_SETSORT: if (SortedColumn == -1) { SortedColumn = 0; }if (SortedColumn == -1) { ... } else { SortedColumn++; if (SortedColumn == (int)LISTVIEW_GetNumColumns(hList)) { SortedColumn = 0; }if (SortedColumn == (int)LISTVIEW_GetNumColumns(hList)) { ... } }else { ... } LISTVIEW_SetSort(hList, SortedColumn, Reverse); break;case JOB_SETSORT: }switch (_aAction[Index].Job) { ... } GUI_Delay(_aAction[Index].Delay); ...} while ((++Index < GUI_COUNTOF(_aAction)) && (GUIDEMO_CheckCancel() == 0)); }{ ... } /********************************************************************* * * _DemoListview *//* ... */ static void _DemoListview(void) { WM_HWIN hList; int xSize, ySize, xSpace, ySpace; xSize = LCD_GetXSize(); ySize = LCD_GetYSize(); if ((CONTROL_SIZE_X + MIN_SPACE) < ((xSize - LISTVIEW_SIZE_X) >> 1)) { xSpace = (xSize - LISTVIEW_SIZE_X) >> 1; }if ((CONTROL_SIZE_X + MIN_SPACE) < ((xSize - LISTVIEW_SIZE_X) >> 1)) { ... } else { xSpace = (xSize - LISTVIEW_SIZE_X - CONTROL_SIZE_X) >> 1; }else { ... } ySpace = (ySize - INFO_SIZE_Y) >> 3; hList = LISTVIEW_CreateEx(xSpace, INFO_SIZE_Y + ySpace, LISTVIEW_SIZE_X, ySize - INFO_SIZE_Y - (ySpace << 1), WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTVIEW0); WM_SetFocus(hList); _InitListview(hList); _Action(hList); WM_DeleteWindow(hList); }{ ... } /********************************************************************* * * Public code * ********************************************************************** *//* ... */ /********************************************************************* * * GUIDEMO_Listview *//* ... */ void GUIDEMO_Listview(void) { GUIDEMO_ShowIntro("Listview demo", "Shows some features of\n" "the LISTVEW widget"); GUIDEMO_DrawBk(1); GUIDEMO_ShowInfoWin(); _DemoListview(); }{ ... } /* ... */#else void GUIDEMO_Listview(void) {} /* ... */ #endif