GUIDEMO_Listview.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*********************************************************************
  2. * SEGGER Microcontroller GmbH & Co. KG *
  3. * Solutions for real time microcontroller applications *
  4. **********************************************************************
  5. * *
  6. * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG *
  7. * *
  8. * Internet: www.segger.com Support: support@segger.com *
  9. * *
  10. **********************************************************************
  11. ** emWin V5.32 - Graphical user interface for embedded applications **
  12. All Intellectual Property rights in the Software belongs to SEGGER.
  13. emWin is protected by international copyright laws. Knowledge of the
  14. source code may not be used to write a similar product. This file may
  15. only be used in accordance with the following terms:
  16. The software has been licensed to STMicroelectronics International
  17. N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
  18. les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
  19. purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
  20. troller products commercialized by Licensee only, sublicensed and dis_
  21. tributed under the terms and conditions of the End User License Agree_
  22. ment supplied by STMicroelectronics International N.V.
  23. Full source code is available at: www.segger.com
  24. We appreciate your understanding and fairness.
  25. ----------------------------------------------------------------------
  26. Licensing information
  27. Licensor: SEGGER Software GmbH
  28. Licensed to: STMicroelectronics International NV
  29. Licensed SEGGER software: emWin
  30. License number: GUI-00429
  31. License model: Buyout SRC [Buyout Source Code License, signed November 29th 2012]
  32. Licensed product: -
  33. Licensed platform: STMs ARM Cortex-M based 32 BIT CPUs
  34. Licensed number of seats: -
  35. ----------------------------------------------------------------------
  36. File : GUIDEMO_Listview.c
  37. Purpose : Listview demo
  38. ----------------------------------------------------------------------
  39. */
  40. #include "GUIDEMO.h"
  41. #if (SHOW_GUIDEMO_LISTVIEW && GUI_WINSUPPORT)
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45. /*********************************************************************
  46. *
  47. * Defines
  48. *
  49. **********************************************************************
  50. */
  51. #define LISTVIEW_SIZE_X 210
  52. #define MIN_SPACE 5
  53. /*********************************************************************
  54. *
  55. * Types
  56. *
  57. **********************************************************************
  58. */
  59. enum {
  60. JOB_ADDROWS = 1,
  61. JOB_SETSORT,
  62. JOB_REVERSE,
  63. JOB_INCSEL,
  64. JOB_DECSEL,
  65. JOB_COLOR
  66. };
  67. /*********************************************************************
  68. *
  69. * COL_PROP
  70. */
  71. typedef struct {
  72. char * pText;
  73. int Width;
  74. int Align;
  75. int (* fpCompare)(const void * p0, const void * p1);
  76. } COL_PROP;
  77. /*********************************************************************
  78. *
  79. * ACTION_ITEM
  80. */
  81. typedef struct {
  82. int Delay;
  83. int Job;
  84. const char * pDescription;
  85. } ACTION_ITEM;
  86. /*********************************************************************
  87. *
  88. * Static data
  89. *
  90. **********************************************************************
  91. */
  92. /*********************************************************************
  93. *
  94. * _pNames
  95. */
  96. static const char * _pNames[] = {
  97. "Adina", "Adis", "Aimee", "Alea", "Alessio", "Aletta", "Alexia", "Alissa", "Amelia",
  98. "Anakin", "Ania", "Ankea", "Annalies", "Annina", "Annrike", "Arkadius", "Arvin",
  99. "Aurelia", "Ava", "Beeke", "Benita", "Bennit", "Bent", "Berenike", "Berit", "Birk",
  100. "Bosse", "Carsta", "Catalina", "Celia", "Charis", "Charlin", "Charlotta", "Cordelia",
  101. "Corey", "Cornelis", "Corvin", "Cosima", "Crisula", "Darian", "Darina", "Deik", "Derek",
  102. "Destina", "Devin", "Diane", "Dina", "Dion", "Dorette", "Dorle", "Duncan", "Eddy",
  103. "Einar", "Elea", "Elin", "Elita", "Elona", "Elouise", "Emilian", "Emina", "Emmeline",
  104. "Enna", "Estelle", "Etta", "Fabiola", "Fabrice", "Falko", "Felice", "Feline", "Femke",
  105. "Fiete", "Filippa", "Fine", "Finia", "Finley", "Fleur", "Florentine", "Florenz", "Florin",
  106. "Floyd", "Fokko", "Fritzi", "Gero", "Gerret", "Gerwin", "Gideon", "Gillian", "Glen",
  107. "Gunilla", "Hanka", "Heinke", "Helmar", "Henner", "Hennes", "Henrieke", "Immo",
  108. "India", "Isalie", "Iven", "Jade", "Janice", "Janika", "Janka", "Janneke", "Jannika",
  109. "Jano", "Jarla", "Jarne", "Jarno", "Jaromir", "Jaron", "Jelana", "Jesper", "Joleen", "Jolie",
  110. "Jonte", "Joost", "Jördis", "Joris", "Josie", "Josina", "Jula", "Julina", "Jytte", "Kalle",
  111. "Kennet", "Keno", "Kiana", "Kieran", "Laila", "Laureen", "Laurens", "Laurent",
  112. "Lauritz", "Leana", "Leandra", "Leandro", "Len", "Lenore", "Leona", "Leonore",
  113. "Levke", "Lewin", "Lientje", "Lilith", "Line", "Linna", "Linnea", "Lisanne", "Livia",
  114. "Lorena", "Lorna", "Lovis", "Luana", "Ludger", "Madita", "Mads", "Maiga", "Mailin",
  115. "Malina", "Manja", "Marieke", "Marielle", "Mariette", "Mariola", "Marla", "Marlena",
  116. "Marlin", "Marlo", "Marthe", "Martje", "Matz", "Maureen", "Mayra", "Medina",
  117. "Melda", "Melek", "Melike", "Melinda", "Melis", "Melisa", "Merit", "Mieke", "Mila",
  118. "Mina", "Mio", "Mirella", "Momke", "Momme", "Morris", "Nantke", "Nelson", "Nika",
  119. "Norwin", "Oke", "Onno", "Otis", "Ove", "Peer", "Pelle", "Philine", "Philomena",
  120. "Quentin", "Quint", "Rahel", "Raik", "Riana", "Ricardo", "Rika", "Rixa", "Rolex",
  121. "Ruwen", "Ryan", "Salma", "Sandrine", "Severin", "Sidonie", "Silas", "Silja", "Simeon",
  122. "Sinja", "Smilla", "Stig", "Stine", "Talisa", "Tamina", "Tammo", "Tara", "Thyra",
  123. "Tiana", "Tjalf", "Tjark", "Tjelle", "Tjorben", "Tomma", "Tore", "Vanity", "Violet",
  124. "Violetta", "Wilko", "Wulf", "Yasmina", "Ylvie", "Younes", "Yves", "Yvette",
  125. };
  126. /*********************************************************************
  127. *
  128. * _aColProps
  129. */
  130. static const COL_PROP _aColProps[] = {
  131. { "Name", 70, GUI_TA_LEFT, LISTVIEW_CompareText},
  132. { "Code", 50, GUI_TA_HCENTER, LISTVIEW_CompareText},
  133. { "Balance", 60, GUI_TA_RIGHT, LISTVIEW_CompareDec }
  134. };
  135. /*********************************************************************
  136. *
  137. * _aAction
  138. */
  139. static const ACTION_ITEM _aAction[] = {
  140. { 0, JOB_ADDROWS, "Adding some rows" },
  141. { 900, 0, NULL },
  142. { 500, 0, "Enable sorting" },
  143. { 500, 0, NULL },
  144. { 600, JOB_SETSORT, NULL },
  145. { 600, JOB_SETSORT, NULL },
  146. { 600, JOB_SETSORT, NULL },
  147. { 500, 0, "Using reverse/normal\nsorting order" },
  148. { 500, 0, NULL },
  149. { 600, JOB_REVERSE, NULL },
  150. { 600, JOB_REVERSE, NULL },
  151. { 600, JOB_REVERSE, NULL },
  152. { 500, 0, "Changing selection" },
  153. { 500, 0, NULL },
  154. { 50, JOB_INCSEL, NULL },
  155. { 50, JOB_INCSEL, NULL },
  156. { 50, JOB_INCSEL, NULL },
  157. { 50, JOB_INCSEL, NULL },
  158. { 50, JOB_INCSEL, NULL },
  159. { 50, JOB_INCSEL, NULL },
  160. { 50, JOB_INCSEL, NULL },
  161. { 50, JOB_INCSEL, NULL },
  162. { 50, JOB_INCSEL, NULL },
  163. { 50, JOB_INCSEL, NULL },
  164. { 50, JOB_DECSEL, NULL },
  165. { 50, JOB_DECSEL, NULL },
  166. { 50, JOB_DECSEL, NULL },
  167. { 50, JOB_DECSEL, NULL },
  168. { 50, JOB_DECSEL, NULL },
  169. { 500, 0, "Setting some individual colors" },
  170. { 500, 0, NULL },
  171. { 50, JOB_COLOR, NULL },
  172. {1800, 0, NULL },
  173. };
  174. /*********************************************************************
  175. *
  176. * _aColor
  177. */
  178. static const GUI_COLOR _aColor[] = {
  179. GUI_BLUE , GUI_GREEN , GUI_RED , GUI_CYAN ,
  180. GUI_MAGENTA , GUI_YELLOW , GUI_LIGHTBLUE , GUI_LIGHTGREEN ,
  181. GUI_LIGHTRED , GUI_LIGHTCYAN , GUI_LIGHTMAGENTA, GUI_LIGHTYELLOW ,
  182. GUI_DARKBLUE , GUI_DARKGREEN , GUI_DARKRED , GUI_DARKCYAN ,
  183. GUI_DARKMAGENTA , GUI_DARKYELLOW , GUI_WHITE , GUI_LIGHTGRAY ,
  184. GUI_GRAY , GUI_DARKGRAY , GUI_BLACK , GUI_BROWN ,
  185. };
  186. /*********************************************************************
  187. *
  188. * Static code
  189. *
  190. **********************************************************************
  191. */
  192. /*********************************************************************
  193. *
  194. * _AddRow
  195. *
  196. * Purpose:
  197. * Inserts or adds a new row of data to the given LISTVIEW
  198. *
  199. * Parameter:
  200. * hItem - Handle of LISTVIEW widget
  201. * Insert - 1 for inserting a row,0 for adding a row
  202. */
  203. static int _AddRow(WM_HWIN hItem, int Insert) {
  204. const char * pText[3];
  205. char acText[3][20] = {{ 0 }};
  206. int i;
  207. int r;
  208. //
  209. // Create name field
  210. //
  211. i = (unsigned)rand() % GUI_COUNTOF(_pNames);
  212. strcpy(acText[0], _pNames[i]);
  213. //
  214. // Create code field
  215. //
  216. for (i = 0; i < 5; i++) {
  217. acText[1][i] = rand() % 26 + 'A';
  218. }
  219. //
  220. // Create balance field
  221. //
  222. i = (rand() % 10000) - 5000;
  223. sprintf(acText[2], "%i", i);
  224. //
  225. // Fill pointer array
  226. //
  227. for (i = 0; i < 3; i++) {
  228. pText[i] = acText[i];
  229. }
  230. //
  231. // Add/Insert row
  232. //
  233. if (Insert) {
  234. r = LISTVIEW_InsertRow(hItem, 0, (const GUI_ConstString * )&pText);
  235. } else {
  236. r = LISTVIEW_AddRow(hItem, (const GUI_ConstString * )&pText);
  237. }
  238. return r;
  239. }
  240. /*********************************************************************
  241. *
  242. * _InitListview
  243. *
  244. * Purpose:
  245. * Adds some data to the listview widget
  246. */
  247. static void _InitListview(WM_HWIN hList) {
  248. int i;
  249. HEADER_SetDragLimit(LISTVIEW_GetHeader(hList), 1);
  250. LISTVIEW_SetAutoScrollV(hList, 1);
  251. LISTVIEW_SetGridVis(hList, 1);
  252. LISTVIEW_SetRBorder(hList, 5);
  253. LISTVIEW_SetLBorder(hList, 5);
  254. for (i = 0; i < 3; i++) {
  255. LISTVIEW_AddColumn(hList, _aColProps[i].Width, _aColProps[i].pText, _aColProps[i].Align);
  256. LISTVIEW_SetCompareFunc(hList, i, _aColProps[i].fpCompare);
  257. }
  258. LISTVIEW_EnableSort(hList);
  259. }
  260. /*********************************************************************
  261. *
  262. * _Action
  263. *
  264. * Purpose:
  265. * Does some action with the widget
  266. */
  267. static void _Action(WM_HWIN hList) {
  268. unsigned ColoredCol = 0;
  269. unsigned ColoredRow = 0;
  270. unsigned NumRows;
  271. unsigned Index;
  272. unsigned i;
  273. int SortedColumn = -1;
  274. int ColorIndex = 0;
  275. int Reverse = 0;
  276. Index = 0;
  277. do {
  278. if (_aAction[Index].pDescription) {
  279. GUIDEMO_SetInfoText(_aAction[Index].pDescription);
  280. }
  281. switch (_aAction[Index].Job) {
  282. case JOB_COLOR:
  283. NumRows = LISTVIEW_GetNumRows(hList);
  284. for (i = 0; i < NumRows; i++) {
  285. LISTVIEW_SetItemBkColor(hList, ColoredCol, ColoredRow, LISTVIEW_CI_UNSEL, _aColor[ColorIndex]);
  286. if (++ColorIndex == GUI_COUNTOF(_aColor)) {
  287. ColorIndex = 0;
  288. }
  289. if (++ColoredCol == LISTVIEW_GetNumColumns(hList)) {
  290. ColoredCol = 0;
  291. }
  292. if (++ColoredRow == NumRows) {
  293. ColoredRow = 0;
  294. }
  295. }
  296. break;
  297. case JOB_INCSEL:
  298. LISTVIEW_IncSel(hList);
  299. break;
  300. case JOB_DECSEL:
  301. LISTVIEW_DecSel(hList);
  302. break;
  303. case JOB_REVERSE:
  304. Reverse ^= 1;
  305. LISTVIEW_SetSort(hList, SortedColumn, Reverse);
  306. break;
  307. case JOB_ADDROWS:
  308. for (i = 0; i < 40; i++) {
  309. _AddRow(hList, 0);
  310. }
  311. break;
  312. case JOB_SETSORT:
  313. if (SortedColumn == -1) {
  314. SortedColumn = 0;
  315. } else {
  316. SortedColumn++;
  317. if (SortedColumn == (int)LISTVIEW_GetNumColumns(hList)) {
  318. SortedColumn = 0;
  319. }
  320. }
  321. LISTVIEW_SetSort(hList, SortedColumn, Reverse);
  322. break;
  323. }
  324. GUI_Delay(_aAction[Index].Delay);
  325. } while ((++Index < GUI_COUNTOF(_aAction)) && (GUIDEMO_CheckCancel() == 0));
  326. }
  327. /*********************************************************************
  328. *
  329. * _DemoListview
  330. */
  331. static void _DemoListview(void) {
  332. WM_HWIN hList;
  333. int xSpace;
  334. int ySpace;
  335. int xSize;
  336. int ySize;
  337. xSize = LCD_GetXSize();
  338. ySize = LCD_GetYSize();
  339. if ((CONTROL_SIZE_X + MIN_SPACE) < ((xSize - LISTVIEW_SIZE_X) / 2)) {
  340. xSpace = (xSize - LISTVIEW_SIZE_X) / 2;
  341. } else {
  342. xSpace = (xSize - LISTVIEW_SIZE_X - CONTROL_SIZE_X) / 2;
  343. }
  344. ySpace = (ySize - INFO_SIZE_Y) / 8;
  345. hList = LISTVIEW_CreateEx(xSpace, INFO_SIZE_Y + ySpace, LISTVIEW_SIZE_X, ySize - INFO_SIZE_Y - (ySpace * 2), WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTVIEW0);
  346. WM_SetFocus(hList);
  347. _InitListview(hList);
  348. _Action(hList);
  349. WM_DeleteWindow(hList);
  350. }
  351. /*********************************************************************
  352. *
  353. * Public code
  354. *
  355. **********************************************************************
  356. */
  357. /*********************************************************************
  358. *
  359. * GUIDEMO_Listview
  360. */
  361. void GUIDEMO_Listview(void) {
  362. GUIDEMO_ConfigureDemo("Listview widget", "Shows some features of\nthe LISTVEW widget", GUIDEMO_SHOW_CURSOR | GUIDEMO_SHOW_INFO | GUIDEMO_SHOW_CONTROL);
  363. GUIDEMO_DrawBk();
  364. _DemoListview();
  365. }
  366. #else
  367. void GUIDEMO_Listview_C(void);
  368. void GUIDEMO_Listview_C(void) {}
  369. #endif // SHOW_GUIDEMO_LISTVIEW && GUI_WINSUPPORT
  370. /*************************** End of file ****************************/