GUIDEMO_Listview.c 15 KB

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