Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
WIDGET_CustomTreeview.c
00001 /********************************************************************* 00002 * SEGGER Microcontroller GmbH * 00003 * Solutions for real time microcontroller applications * 00004 ********************************************************************** 00005 * * 00006 * (c) 1996 - 2018 SEGGER Microcontroller GmbH * 00007 * * 00008 * Internet: www.segger.com Support: support@segger.com * 00009 * * 00010 ********************************************************************** 00011 00012 ** emWin V5.48 - Graphical user interface for embedded applications ** 00013 All Intellectual Property rights in the Software belongs to SEGGER. 00014 emWin is protected by international copyright laws. Knowledge of the 00015 source code may not be used to write a similar product. This file may 00016 only be used in accordance with the following terms: 00017 00018 The software has been licensed to Cypress Semiconductor Corporation, 00019 whose registered office is situated at 198 Champion Ct. San Jose, CA 00020 95134 USA solely for the purposes of creating libraries for Cypress 00021 PSoC3 and PSoC5 processor-based devices, sublicensed and distributed 00022 under the terms and conditions of the Cypress End User License 00023 Agreement. 00024 Full source code is available at: www.segger.com 00025 00026 We appreciate your understanding and fairness. 00027 ---------------------------------------------------------------------- 00028 Licensing information 00029 Licensor: SEGGER Microcontroller Systems LLC 00030 Licensed to: Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA 00031 Licensed SEGGER software: emWin 00032 License number: GUI-00319 00033 License model: Services and License Agreement, signed June 10th, 2009 00034 Licensed platform: Any Cypress platform (Initial targets are: PSoC3, PSoC5) 00035 ---------------------------------------------------------------------- 00036 Support and Update Agreement (SUA) 00037 SUA period: 2009-06-12 - 2022-07-27 00038 Contact to extend SUA: sales@segger.com 00039 ---------------------------------------------------------------------- 00040 File : WIDGET_CustomTreeview.c 00041 Purpose : Demonstrates using the TREEVIEW widget 00042 Requirements: WindowManager - (x) 00043 MemoryDevices - (x) 00044 AntiAliasing - ( ) 00045 VNC-Server - ( ) 00046 PNG-Library - ( ) 00047 TrueTypeFonts - ( ) 00048 ---------------------------------------------------------------------- 00049 */ 00050 #include "DIALOG.h" 00051 00052 /********************************************************************* 00053 * 00054 * Defines 00055 * 00056 ********************************************************************** 00057 */ 00058 #define NUM_CHILD_NODES 4 00059 #define NUM_CHILD_ITEMS 4 00060 #define TREEVIEW_DEPTH 4 00061 #define USER_COLOR GUI_MAKE_COLOR(0x00FFFF) 00062 00063 // 00064 // Recommended memory to run the sample with adequate performance 00065 // 00066 #define RECOMMENDED_MEMORY (1024L * 40) 00067 00068 /********************************************************************* 00069 * 00070 * Static data 00071 * 00072 ********************************************************************** 00073 */ 00074 /********************************************************************* 00075 * 00076 * bmOpen 00077 */ 00078 static GUI_COLOR ColorsOpen[] = { 00079 GUI_MAKE_COLOR(0x0000FF), GUI_MAKE_COLOR(0x000000), USER_COLOR 00080 }; 00081 00082 static GUI_CONST_STORAGE GUI_LOGPALETTE PalOpen = { 00083 3, // number of entries 00084 1, // Has transparency 00085 &ColorsOpen[0] 00086 }; 00087 00088 static GUI_CONST_STORAGE unsigned char acOpen[] = { 00089 0x01, 0x55, 0x50, 0x00, 00090 0x01, 0xAA, 0x90, 0x00, 00091 0x05, 0xAA, 0x95, 0x54, 00092 0x06, 0xAA, 0xAA, 0xA4, 00093 0x55, 0x55, 0x55, 0xA4, 00094 0x6A, 0xAA, 0xAA, 0x64, 00095 0x6A, 0xAA, 0xAA, 0x64, 00096 0x1A, 0xAA, 0xAA, 0x94, 00097 0x1A, 0xAA, 0xAA, 0x94, 00098 0x06, 0xAA, 0xAA, 0xA4, 00099 0x05, 0x55, 0x55, 0x54, 00100 0x00, 0x00, 0x00, 0x00 00101 }; 00102 00103 GUI_CONST_STORAGE GUI_BITMAP bmOpen = { 00104 16, // XSize 00105 12, // YSize 00106 4, // BytesPerLine 00107 2, // BitsPerPixel 00108 acOpen, // Pointer to picture data (indices) 00109 &PalOpen // Pointer to palette 00110 }; 00111 00112 /********************************************************************* 00113 * 00114 * bmLeaf 00115 */ 00116 static GUI_COLOR ColorsLeaf[] = { 00117 GUI_MAKE_COLOR(0x0000FF), USER_COLOR, GUI_MAKE_COLOR(0x000000) 00118 }; 00119 00120 static GUI_CONST_STORAGE GUI_LOGPALETTE PalLeaf = { 00121 3, // number of entries 00122 1, // Has transparency 00123 &ColorsLeaf[0] 00124 }; 00125 00126 static GUI_CONST_STORAGE unsigned char acLeaf[] = { 00127 0x0A, 0xAA, 0xA8, 0x00, 00128 0x09, 0x55, 0x5A, 0x00, 00129 0x09, 0x55, 0x59, 0x80, 00130 0x09, 0xAA, 0x9A, 0x80, 00131 0x09, 0x55, 0x55, 0x80, 00132 0x09, 0xAA, 0xA9, 0x80, 00133 0x09, 0x55, 0x55, 0x80, 00134 0x09, 0xAA, 0xA9, 0x80, 00135 0x09, 0x55, 0x55, 0x80, 00136 0x09, 0xAA, 0xA9, 0x80, 00137 0x09, 0x55, 0x55, 0x80, 00138 0x09, 0xAA, 0xA9, 0x80, 00139 0x09, 0x55, 0x55, 0x80, 00140 0x0A, 0xAA, 0xAA, 0x80, 00141 0x00, 0x00, 0x00, 0x00 00142 }; 00143 00144 GUI_CONST_STORAGE GUI_BITMAP bmLeaf = { 00145 14, // XSize 00146 15, // YSize 00147 4, // BytesPerLine 00148 2, // BitsPerPixel 00149 acLeaf, // Pointer to picture data (indices) 00150 &PalLeaf // Pointer to palette 00151 }; 00152 00153 /********************************************************************* 00154 * 00155 * bmClosed 00156 */ 00157 static GUI_COLOR ColorsClosed[] = { 00158 GUI_MAKE_COLOR(0x0000FF), USER_COLOR, GUI_MAKE_COLOR(0x000000) 00159 }; 00160 00161 static GUI_CONST_STORAGE GUI_LOGPALETTE PalClosed = { 00162 3, // number of entries 00163 1, // Has transparency 00164 &ColorsClosed[0] 00165 }; 00166 00167 static GUI_CONST_STORAGE unsigned char acClosed[] = { 00168 0x02, 0xAA, 0xA0, 0x00, 00169 0x02, 0x55, 0x60, 0x00, 00170 0x0A, 0xAA, 0xAA, 0xA8, 00171 0x09, 0x55, 0x55, 0x58, 00172 0x09, 0x55, 0x55, 0x58, 00173 0x09, 0x55, 0x55, 0x58, 00174 0x09, 0x55, 0x55, 0x58, 00175 0x09, 0x55, 0x55, 0x58, 00176 0x09, 0x55, 0x55, 0x58, 00177 0x09, 0x55, 0x55, 0x58, 00178 0x0A, 0xAA, 0xAA, 0xA8, 00179 0x00, 0x00, 0x00, 0x00 00180 }; 00181 00182 GUI_CONST_STORAGE GUI_BITMAP bmClosed = { 00183 16, // XSize 00184 12, // YSize 00185 4, // BytesPerLine 00186 2, // BitsPerPixel 00187 acClosed, // to picture data (indices) 00188 &PalClosed // Pointer to palette 00189 }; 00190 00191 /********************************************************************* 00192 * 00193 * bmPlus 00194 */ 00195 static GUI_CONST_STORAGE GUI_COLOR _ColorsPlus[] = { 00196 0x00FF00, 0xFFFFFF, 0x241CED 00197 }; 00198 00199 static GUI_CONST_STORAGE GUI_LOGPALETTE _PalPlus = { 00200 3, // Number of entries 00201 1, // Has transparency 00202 &_ColorsPlus[0] 00203 }; 00204 00205 static GUI_CONST_STORAGE unsigned char _acPlus[] = { 00206 0x00, 0xAA, 0xA8, 0x00, 00207 0x0A, 0xA5, 0x6A, 0x80, 00208 0x2A, 0xA5, 0x6A, 0xA0, 00209 0xAA, 0x55, 0x56, 0xA8, 00210 0xAA, 0x55, 0x56, 0xA8, 00211 0xAA, 0x55, 0x56, 0xA8, 00212 0x2A, 0xA5, 0x6A, 0xA0, 00213 0x0A, 0xA5, 0x6A, 0x80, 00214 0x00, 0xAA, 0xA8, 0x00 00215 }; 00216 00217 static GUI_CONST_STORAGE GUI_BITMAP bmPlus = { 00218 15, // xSize 00219 9, // ySize 00220 4, // BytesPerLine 00221 2, // BitsPerPixel 00222 _acPlus, // Pointer to picture data (indices) 00223 &_PalPlus // Pointer to palette 00224 }; 00225 00226 /********************************************************************* 00227 * 00228 * bmMinus 00229 */ 00230 static GUI_CONST_STORAGE GUI_COLOR _ColorsMinus[] = { 00231 0x00FF00, 0x241CED, 0xFFFFFF 00232 }; 00233 00234 static GUI_CONST_STORAGE GUI_LOGPALETTE _PalMinus = { 00235 3, // Number of entries 00236 1, // Has transparency 00237 &_ColorsMinus[0] 00238 }; 00239 00240 static GUI_CONST_STORAGE unsigned char _acMinus[] = { 00241 0x00, 0x55, 0x54, 0x00, 00242 0x05, 0x55, 0x55, 0x40, 00243 0x15, 0x55, 0x55, 0x50, 00244 0x55, 0xAA, 0xA9, 0x54, 00245 0x55, 0xAA, 0xA9, 0x54, 00246 0x55, 0xAA, 0xA9, 0x54, 00247 0x15, 0x55, 0x55, 0x50, 00248 0x05, 0x55, 0x55, 0x40, 00249 0x00, 0x55, 0x54, 0x00 00250 }; 00251 00252 static GUI_CONST_STORAGE GUI_BITMAP bmMinus = { 00253 15, // xSize 00254 9, // ySize 00255 4, // BytesPerLine 00256 2, // BitsPerPixel 00257 _acMinus, // Pointer to picture data (indices) 00258 &_PalMinus // Pointer to palette 00259 }; 00260 00261 /********************************************************************* 00262 * 00263 * Static code 00264 * 00265 ********************************************************************** 00266 */ 00267 /********************************************************************* 00268 * 00269 * _FillNode 00270 * 00271 * Function description 00272 * Recursive filling of node 00273 * 00274 * Parameters: 00275 * hTree - obvious 00276 * NumNodes - Number of child nodes to be created at each node 00277 * NumLeafs - Number of leaves to be created at each node 00278 * MaxDepth - Maximum depth (1.1.1.1.1.....) 00279 * CurDepth - Current depth 00280 * acBuffer - String to be used for TREEVIEW items 00281 * p - Pointer into to string to be used for numbering 00282 * 00283 * Return value: 00284 * 0 on success, 1 on error 00285 */ 00286 static int _FillNode(WM_HWIN hTree, TREEVIEW_ITEM_Handle hNode, int NumNodes, int NumLeafs, int MaxDepth, int CurDepth, char * acBuffer, char * p) { 00287 TREEVIEW_ITEM_Handle hItem = 0; 00288 int i, Position; 00289 00290 *(p + 1) = 0; 00291 *p = '0' - 1; 00292 if (--CurDepth) { 00293 // 00294 // Create nodes 00295 // 00296 for (i = 0; i < NumNodes; i++) { 00297 (*p)++; 00298 Position = hItem ? TREEVIEW_INSERT_BELOW : TREEVIEW_INSERT_FIRST_CHILD; 00299 hItem = TREEVIEW_ITEM_Create(1, acBuffer, 0); 00300 if (hItem == 0) { 00301 return 1; // Error 00302 } 00303 TREEVIEW_AttachItem(hTree, hItem, hNode, Position); 00304 hNode = hItem; 00305 *(p + 1) = '.'; 00306 p += 2; 00307 // 00308 // Recursive call of 'this' function for each node 00309 // 00310 _FillNode(hTree, hNode, NumNodes, NumLeafs, MaxDepth, CurDepth, acBuffer, p); 00311 p -= 2; 00312 *(p + 1) = 0; 00313 } 00314 } 00315 // 00316 // Create Leafs 00317 // 00318 for (i = 0; i < NumLeafs; i++) { 00319 (*p)++; 00320 Position = hItem ? TREEVIEW_INSERT_BELOW : TREEVIEW_INSERT_FIRST_CHILD; 00321 hItem = TREEVIEW_ITEM_Create(0, acBuffer, 0); 00322 if (hItem == 0) { 00323 return 1; // Error 00324 } 00325 TREEVIEW_AttachItem(hTree, hItem, hNode, Position); 00326 hNode = hItem; 00327 } 00328 return 0; 00329 } 00330 00331 /********************************************************************* 00332 * 00333 * _DrawLine 00334 */ 00335 static void _DrawLine(int x0, int y0, int x1, int y1) { 00336 GUI_SetColor(GUI_GREEN); 00337 GUI_SetLineStyle(GUI_LS_DOT); 00338 GUI_DrawLine(x0, y0, x1, y1); 00339 GUI_SetLineStyle(GUI_LS_SOLID); 00340 } 00341 00342 /********************************************************************* 00343 * 00344 * _SwapColors 00345 */ 00346 static void _SwapColors(GUI_COLOR * pColor) { 00347 GUI_COLOR Color; 00348 00349 Color = *(pColor + 1); 00350 *(pColor + 1) = *(pColor + 2); 00351 *(pColor + 2) = Color; 00352 00353 } 00354 00355 /********************************************************************* 00356 * 00357 * _TREEVIEW_OwnerDraw 00358 */ 00359 static int _TREEVIEW_OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) { 00360 TREEVIEW_ITEM_DRAW_INFO * pDrawInfo; 00361 TREEVIEW_ITEM_INFO ItemInfo; 00362 TREEVIEW_ITEM_Handle hItem; 00363 int i; 00364 GUI_COLOR * pColor; 00365 00366 pDrawInfo = (TREEVIEW_ITEM_DRAW_INFO *)pDrawItemInfo->p; 00367 switch (pDrawItemInfo->Cmd) { 00368 case WIDGET_ITEM_DRAW_BACKGROUND: 00369 hItem = TREEVIEW_GetSel(pDrawItemInfo->hWin); 00370 TREEVIEW_OwnerDraw(pDrawItemInfo); 00371 if (hItem == pDrawInfo->hItem) { 00372 GUI_DrawGradientRoundedV(pDrawInfo->rText.x0 - 25, pDrawItemInfo->y0, pDrawInfo->rText.x1 + 10, pDrawItemInfo->y1, 3, GUI_RED, GUI_DARKRED); 00373 GUI_SetColor(GUI_RED); 00374 GUI_DrawRoundedFrame(pDrawInfo->rText.x0 - 25, pDrawItemInfo->y0, pDrawInfo->rText.x1 + 10, pDrawItemInfo->y1, 3, 2); 00375 } 00376 break; 00377 case WIDGET_ITEM_DRAW_BITMAP: 00378 // 00379 // Invert colors of bitmap in case of drawing a selected item 00380 // 00381 hItem = TREEVIEW_GetSel(pDrawItemInfo->hWin); 00382 TREEVIEW_ITEM_GetInfo(pDrawInfo->hItem, &ItemInfo); 00383 if (ItemInfo.Level >= 1) { 00384 if ((hItem == pDrawInfo->hItem) && ((pDrawItemInfo->ItemIndex == TREEVIEW_BI_CLOSED) || (pDrawItemInfo->ItemIndex == TREEVIEW_BI_OPEN) || (pDrawItemInfo->ItemIndex == TREEVIEW_BI_LEAF))) { 00385 pColor = (GUI_COLOR *)pDrawInfo->pBmOCL->pPal->pPalEntries; 00386 _SwapColors(pColor); 00387 TREEVIEW_OwnerDraw(pDrawItemInfo); 00388 _SwapColors(pColor); 00389 } else { 00390 TREEVIEW_OwnerDraw(pDrawItemInfo); 00391 } 00392 } 00393 break; 00394 case WIDGET_ITEM_DRAW_TEXT: 00395 // 00396 // Make sure text is transparent 00397 // 00398 GUI_SetTextMode(GUI_TM_TRANS); 00399 TREEVIEW_OwnerDraw(pDrawItemInfo); 00400 break; 00401 case WIDGET_ITEM_DRAW_TICKS: 00402 TREEVIEW_ITEM_GetInfo(pDrawInfo->hItem, &ItemInfo); 00403 // 00404 // Draw lines 00405 // 00406 for (i = 0; i < pDrawInfo->NumLines; i++) { 00407 if (ItemInfo.IsNode) { 00408 // 00409 // Extend horizontal line in case of a node 00410 // 00411 if (pDrawInfo->ay0[i] == pDrawInfo->ay1[i]) { 00412 pDrawInfo->ax1[i] += 10; 00413 } 00414 } 00415 _DrawLine(pDrawInfo->ax0[i], pDrawInfo->ay0[i], pDrawInfo->ax1[i], pDrawInfo->ay1[i]); 00416 } 00417 // 00418 // Draw connectors 00419 // 00420 for (i = 0; i < pDrawInfo->NumConnectors; i++) { 00421 _DrawLine(pDrawInfo->axc[i], pDrawItemInfo->y0, pDrawInfo->axc[i], pDrawItemInfo->y1); 00422 } 00423 break; 00424 default: 00425 return TREEVIEW_OwnerDraw(pDrawItemInfo); 00426 } 00427 return 0; 00428 } 00429 00430 static void _cbBk(WM_MESSAGE * pMsg) { 00431 int xSize; 00432 00433 switch (pMsg->MsgId) { 00434 case WM_PAINT: 00435 xSize = LCD_GetXSize(); 00436 GUI_Clear(); 00437 GUI_SetFont(GUI_FONT_24_ASCII); 00438 GUI_DispStringHCenterAt("Customized TREEVIEW widget", xSize >> 1, 5); 00439 GUI_DrawHLine(30, 0, xSize - 1); 00440 break; 00441 } 00442 } 00443 00444 /********************************************************************* 00445 * 00446 * Public code 00447 * 00448 ********************************************************************** 00449 */ 00450 /********************************************************************* 00451 * 00452 * MainTask 00453 */ 00454 void MainTask(void) { 00455 WM_HWIN hTree; 00456 TREEVIEW_ITEM_Handle hNode; 00457 int xSize, ySize; 00458 char acBuffer[(TREEVIEW_DEPTH << 1) + 1]; 00459 00460 // 00461 // Initialize emWin 00462 // 00463 WM_SetCreateFlags(WM_CF_MEMDEV); 00464 GUI_Init(); 00465 // 00466 // Check if recommended memory for the sample is available 00467 // 00468 if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) { 00469 GUI_ErrorOut("Not enough memory available."); 00470 return; 00471 } 00472 xSize = LCD_GetXSize(); 00473 ySize = LCD_GetYSize(); 00474 // 00475 // Set defaults for background and widgets 00476 // 00477 WM_SetCallback(WM_HBKWIN, _cbBk); 00478 SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX); 00479 SCROLLBAR_SetDefaultWidth(20); 00480 SCROLLBAR_SetThumbSizeMin(25); 00481 // 00482 // 00483 // 00484 GUI_SetFont(GUI_FONT_24_ASCII); 00485 GUI_DispStringHCenterAt("Customized TREEVIEW widget", 160, 5); 00486 // 00487 // Create TREEVIEW 00488 // 00489 hTree = TREEVIEW_CreateEx(0, 35, xSize, ySize - 35, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, 0, GUI_ID_TREEVIEW0); 00490 TREEVIEW_SetAutoScrollV(hTree, 1); 00491 TREEVIEW_SetFont(hTree, GUI_FONT_24_ASCII); 00492 TREEVIEW_SetIndent(hTree, 30); 00493 TREEVIEW_SetTextIndent(hTree, 20); 00494 TREEVIEW_SetImage(hTree, TREEVIEW_BI_PLUS, &bmPlus); 00495 TREEVIEW_SetImage(hTree, TREEVIEW_BI_MINUS, &bmMinus); 00496 TREEVIEW_SetImage(hTree, TREEVIEW_BI_CLOSED, &bmClosed); 00497 TREEVIEW_SetImage(hTree, TREEVIEW_BI_OPEN, &bmOpen); 00498 TREEVIEW_SetImage(hTree, TREEVIEW_BI_LEAF, &bmLeaf); 00499 TREEVIEW_SetBitmapOffset(hTree, TREEVIEW_BI_PM, -21, -6); 00500 TREEVIEW_SetOwnerDraw(hTree, _TREEVIEW_OwnerDraw); 00501 TREEVIEW_SetBkColor(hTree, TREEVIEW_CI_SEL, USER_COLOR); 00502 TREEVIEW_SetBkColor(hTree, TREEVIEW_CI_UNSEL, GUI_BLACK); 00503 TREEVIEW_SetTextColor(hTree, TREEVIEW_CI_SEL, GUI_WHITE); 00504 TREEVIEW_SetTextColor(hTree, TREEVIEW_CI_UNSEL, GUI_WHITE); 00505 WIDGET_SetEffect(hTree, &WIDGET_Effect_None); 00506 // 00507 // Fill TREEVIEW 00508 // 00509 hNode = TREEVIEW_InsertItem(hTree, TREEVIEW_ITEM_TYPE_NODE, 0, 0, "Tree"); 00510 _FillNode(hTree, hNode, NUM_CHILD_NODES, NUM_CHILD_ITEMS, TREEVIEW_DEPTH, TREEVIEW_DEPTH, acBuffer, acBuffer); 00511 TREEVIEW_ITEM_Expand(hNode); 00512 WM_SetFocus(hTree); 00513 while (1) { 00514 GUI_Delay(100); 00515 } 00516 } 00517 00518 /*************************** End of file ****************************/
Generated on Thu Jul 14 2022 12:58:43 by
