Andrew Reed / Mbed OS CITY1082-i2c_master_wifi_mqtt
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WIDGET_TreeviewTryIt.c Source File

WIDGET_TreeviewTryIt.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_TreeviewTryIt.c
00041 Purpose     : Demonstrates the use of the TREEVIEW widget
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - ( )
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ----------------------------------------------------------------------
00049 */
00050 
00051 #include <stddef.h>
00052 #include "DIALOG.h"
00053 #include "TREEVIEW.h"
00054 #include "MULTIPAGE.h"
00055 
00056 /*********************************************************************
00057 *
00058 *       Defines
00059 *
00060 **********************************************************************
00061 */
00062 #define NUM_CHILD_NODES 3
00063 #define NUM_CHILD_ITEMS 6
00064 #define TREEVIEW_DEPTH  5
00065 
00066 //
00067 // Recommended memory to run the sample with adequate performance
00068 //
00069 #define RECOMMENDED_MEMORY (1024L * 80)
00070 
00071 /*********************************************************************
00072 *
00073 *       Static data
00074 *
00075 **********************************************************************
00076 */
00077 /*********************************************************************
00078 *
00079 *       _aMain
00080 *
00081 * Description
00082 *   Main window containing the two treeviews and a multipage widget
00083 */
00084 static const GUI_WIDGET_CREATE_INFO _aMain[] = {
00085   { WINDOW_CreateIndirect,    NULL,                0,                   0,   0, 320, 240 },
00086   { TEXT_CreateIndirect,      "Treeview TryIt",    GUI_ID_TEXT0,      160,   0, 160,  20 },
00087   { TREEVIEW_CreateIndirect,  NULL,                GUI_ID_TREEVIEW0,    0,   0, 160, 220 },
00088   { TREEVIEW_CreateIndirect,  NULL,                GUI_ID_TREEVIEW1,    0, 220, 160,  20 },
00089   { MULTIPAGE_CreateIndirect, NULL,                GUI_ID_MULTIPAGE0, 160,  20, 160, 220 },
00090 };
00091 
00092 /*********************************************************************
00093 *
00094 *       _aPage0
00095 *
00096 * Description
00097 *   First page of the multipage widget for setting the widget properties
00098 */
00099 static const GUI_WIDGET_CREATE_INFO _aPage0[] = {
00100   { WINDOW_CreateIndirect,    NULL,                0,                   0,   0, 156, 192 },
00101   { TEXT_CreateIndirect,      "Selection",         0,                   5,  10, 100,  15 },
00102   { RADIO_CreateIndirect,     NULL,                GUI_ID_RADIO0,       5,  30, 100,   0, 0, 2 },
00103   { TEXT_CreateIndirect,      "Lines",             0,                   5,  70, 100,  15 },
00104   { RADIO_CreateIndirect,     NULL,                GUI_ID_RADIO1,       5,  90, 100,   0, 0, 2 },
00105   { TEXT_CreateIndirect,      "Font",              0,                   5, 130, 100,  15 },
00106   { RADIO_CreateIndirect,     NULL,                GUI_ID_RADIO4,       5, 150, 100,   0, 0, 2 },
00107   { TEXT_CreateIndirect,      "H",                 0,                  92,  10,  50,  15, TEXT_CF_LEFT },
00108   { TEXT_CreateIndirect,      "V",                 0,                 107,  10,  50,  15, TEXT_CF_LEFT },
00109   { TEXT_CreateIndirect,      "Scroll",            0,                 122,  10,  50,  15, TEXT_CF_LEFT },
00110   { TEXT_CreateIndirect,      "Auto",              0,                 122,  30,  50,  15, TEXT_CF_LEFT },
00111   { TEXT_CreateIndirect,      "Off",               0,                 122,  50,  50,  15, TEXT_CF_LEFT },
00112   { TEXT_CreateIndirect,      "On",                0,                 122,  70,  50,  15, TEXT_CF_LEFT },
00113   { RADIO_CreateIndirect,      NULL,               GUI_ID_RADIO2,      87,  30,   0,   0, 0, 3 },
00114   { RADIO_CreateIndirect,      NULL,               GUI_ID_RADIO3,     102,  30,   0,   0, 0, 3 },
00115 };
00116 
00117 /*********************************************************************
00118 *
00119 *       _aPage1
00120 *
00121 * Description
00122 *   Second page of the multipage widget for playing with the data
00123 */
00124 static const GUI_WIDGET_CREATE_INFO _aPage1[] = {
00125   { WINDOW_CreateIndirect,    NULL,                0,                   0,   0, 156, 192 },
00126   { BUTTON_CreateIndirect,    "Delete item",       GUI_ID_BUTTON0,      5,  10, 140,  18 },
00127   { BUTTON_CreateIndirect,    "Detach item",       GUI_ID_BUTTON1,      5,  28, 140,  18 },
00128   { BUTTON_CreateIndirect,    "Attach item",       GUI_ID_BUTTON2,      5,  46, 140,  18 },
00129   { BUTTON_CreateIndirect,    "Move up",           GUI_ID_BUTTON3,      5,  64, 140,  18 },
00130   { BUTTON_CreateIndirect,    "Move down",         GUI_ID_BUTTON4,      5,  82, 140,  18 },
00131   { BUTTON_CreateIndirect,    "New node",          GUI_ID_BUTTON5,      5, 100, 140,  18 },
00132   { BUTTON_CreateIndirect,    "New leaf",          GUI_ID_BUTTON6,      5, 118, 140,  18 },
00133   { BUTTON_CreateIndirect,    "Set leaf bitmap",   GUI_ID_BUTTON7,      5, 136, 140,  18 },
00134   { BUTTON_CreateIndirect,    "Set open bitmap",   GUI_ID_BUTTON8,      5, 154, 140,  18 },
00135   { BUTTON_CreateIndirect,    "Set closed bitmap", GUI_ID_BUTTON9,      5, 172, 140,  18 },
00136 };
00137 
00138 /*********************************************************************
00139 *
00140 *       _bmSmilie
00141 */
00142 static const GUI_COLOR _ColorsSmilie[] = {
00143 #if (GUI_USE_ARGB == 1)
00144      0xFFFFFFFF,0xFF000000,0xFF70FF70
00145 #else
00146      0xFFFFFF,0x000000,0x70FF70
00147 #endif
00148 };
00149 
00150 static const GUI_LOGPALETTE _PalSmilie = {
00151   3,    // Number of entries
00152   1,    // Has transparency
00153   &_ColorsSmilie[0]
00154 };
00155 
00156 static const unsigned char _acSmilie[] = {
00157   0x00, 0x55, 0x40, 0x00,
00158   0x01, 0xAA, 0x90, 0x00,
00159   0x06, 0xAA, 0xA4, 0x00,
00160   0x19, 0x6A, 0x59, 0x00,
00161   0x69, 0x6A, 0x5A, 0x40,
00162   0x6A, 0xA6, 0xAA, 0x40,
00163   0x6A, 0xA6, 0xAA, 0x40,
00164   0x6A, 0xA6, 0xAA, 0x40,
00165   0x6A, 0xAA, 0xAA, 0x40,
00166   0x1A, 0x6A, 0x69, 0x00,
00167   0x06, 0x95, 0xA4, 0x00,
00168   0x01, 0xAA, 0x90, 0x00,
00169   0x00, 0x55, 0x40, 0x00
00170 };
00171 
00172 static const GUI_BITMAP _bmSmilie = {
00173  13,          // XSize
00174  13,          // YSize
00175  4,           // BytesPerLine
00176  2,           // BitsPerPixel
00177  _acSmilie,   // Pointer to picture data (indices)
00178  &_PalSmilie  // Pointer to palette
00179 };
00180 
00181 /*********************************************************************
00182 *
00183 *       _bmBookOpen
00184 */
00185 static GUI_CONST_STORAGE GUI_COLOR _ColorsBookOpen[] = {
00186 #if (GUI_USE_ARGB == 1)
00187      0xFFFF0000,0xFFFFFFFF,0xFF000000,0xFF008000
00188     ,0xFF808080,0xFFC0C0C0
00189 #else
00190      0x0000FF,0xFFFFFF,0x000000,0x008000
00191     ,0x808080,0xC0C0C0
00192 #endif
00193 };
00194 
00195 static GUI_CONST_STORAGE GUI_LOGPALETTE _PalBookOpen = {
00196   6,    // Number of entries
00197   1,    // Has transparency
00198   &_ColorsBookOpen[0]
00199 };
00200 
00201 static GUI_CONST_STORAGE unsigned char _acBookOpen[] = {
00202   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00203   0x04, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00204   0x23, 0x15, 0x40, 0x00, 0x04, 0x44, 0x00, 0x00,
00205   0x23, 0x11, 0x40, 0x04, 0x41, 0x14, 0x00, 0x00,
00206   0x23, 0x11, 0x54, 0x41, 0x11, 0x14, 0x22, 0x00,
00207   0x23, 0x11, 0x12, 0x51, 0x11, 0x14, 0x13, 0x20,
00208   0x23, 0x11, 0x12, 0x51, 0x11, 0x14, 0x13, 0x20,
00209   0x23, 0x11, 0x12, 0x51, 0x11, 0x14, 0x13, 0x20,
00210   0x23, 0x11, 0x12, 0x51, 0x11, 0x14, 0x13, 0x20,
00211   0x23, 0x11, 0x12, 0x51, 0x11, 0x14, 0x13, 0x20,
00212   0x23, 0x31, 0x12, 0x51, 0x11, 0x45, 0x13, 0x20,
00213   0x02, 0x33, 0x12, 0x51, 0x44, 0x51, 0x13, 0x20,
00214   0x00, 0x23, 0x12, 0x44, 0x51, 0x11, 0x13, 0x20,
00215   0x00, 0x02, 0x33, 0x33, 0x33, 0x33, 0x33, 0x20,
00216   0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x20
00217 };
00218 
00219 GUI_CONST_STORAGE GUI_BITMAP _bmBookOpen = {
00220   15,            // XSize
00221   15,            // YSize
00222   8,             // BytesPerLine
00223   4,             // BitsPerPixel
00224   _acBookOpen,   // Pointer to picture data (indices)
00225   &_PalBookOpen  // Pointer to palette
00226 };
00227 
00228 /*********************************************************************
00229 *
00230 *       _bmBookClosed
00231 */
00232 static GUI_CONST_STORAGE GUI_COLOR _ColorsBookClosed[] = {
00233 #if (GUI_USE_ARGB == 1)
00234      0xFFFF0000,0xFF008000,0xFF000000,0xFFC0C0C0
00235 #else
00236      0x0000FF,0x008000,0x000000,0xC0C0C0
00237 #endif
00238 };
00239 
00240 static GUI_CONST_STORAGE GUI_LOGPALETTE _PalBookClosed = {
00241   4,    // Number of entries
00242   1,    // Has transparency
00243   &_ColorsBookClosed[0]
00244 };
00245 
00246 static GUI_CONST_STORAGE unsigned char _acBookClosed[] = {
00247   0x00, 0x02, 0x80, 0x00,
00248   0x00, 0x29, 0x60, 0x00,
00249   0x02, 0x95, 0x58, 0x00,
00250   0x29, 0x55, 0x56, 0x00,
00251   0x95, 0x55, 0x55, 0x80,
00252   0xA5, 0x55, 0x55, 0x60,
00253   0x99, 0x55, 0x55, 0x58,
00254   0x96, 0x55, 0x55, 0x5A,
00255   0x95, 0x95, 0x55, 0xAC,
00256   0x25, 0x65, 0x5A, 0xFC,
00257   0x09, 0x59, 0xAF, 0xFA,
00258   0x02, 0x56, 0xFF, 0xE8,
00259   0x00, 0x96, 0xFE, 0x80,
00260   0x00, 0x26, 0xE8, 0x00,
00261   0x00, 0x0A, 0x80, 0x00
00262 };
00263 
00264 GUI_CONST_STORAGE GUI_BITMAP _bmBookClosed = {
00265   16,              // XSize
00266   15,              // YSize
00267   4,               // BytesPerLine
00268   2,               // BitsPerPixel
00269   _acBookClosed,   // Pointer to picture data (indices)
00270   &_PalBookClosed  // Pointer to palette
00271 };
00272 
00273 /*********************************************************************
00274 *
00275 *       Static code
00276 *
00277 **********************************************************************
00278 */
00279 /*********************************************************************
00280 *
00281 *       _cbPage0
00282 *
00283 * Function description
00284 *   Callback routine for the first page of the multipage widget
00285 */
00286 static void _cbPage0(WM_MESSAGE * pMsg) {
00287   WM_HWIN hItem;
00288   WM_HWIN hDlg;
00289   WM_HWIN hTree;
00290   int     Sel;
00291   int     NCode;
00292   int     Id;
00293 
00294   hDlg  = pMsg->hWin;
00295   switch (pMsg->MsgId) {
00296   case WM_NOTIFY_PARENT:
00297     hTree = WM_GetDialogItem(WM_GetFirstChild(WM_HBKWIN), GUI_ID_TREEVIEW0);
00298     Id    = WM_GetId(pMsg->hWinSrc);      // Id of widget
00299     NCode = pMsg->Data.v;                 // Notification code
00300     hItem = WM_GetDialogItem(hDlg, Id);
00301     switch (Id) {
00302     case GUI_ID_RADIO0:                   // Select the selection mode
00303       switch (NCode) {
00304       case WM_NOTIFICATION_VALUE_CHANGED:
00305         Sel = RADIO_GetValue(hItem);
00306         TREEVIEW_SetSelMode(hTree, (Sel == 1) ? TREEVIEW_SELMODE_ROW : TREEVIEW_SELMODE_TEXT);
00307         break;
00308       }
00309       break;
00310     case GUI_ID_RADIO1:                   // Set the visibility of the lines
00311       switch (NCode) {
00312       case WM_NOTIFICATION_VALUE_CHANGED:
00313         Sel = RADIO_GetValue(hItem);
00314         TREEVIEW_SetHasLines(hTree, (Sel == 1) ? 1 : 0);
00315         break;
00316       }
00317       break;
00318     case GUI_ID_RADIO2:                   // Manage horizontal scrollbar
00319       switch (NCode) {
00320       case WM_NOTIFICATION_VALUE_CHANGED:
00321         Sel = RADIO_GetValue(hItem);
00322         if (Sel == 1) {
00323           WM_SetScrollbarH(hTree, 0);
00324         }
00325         TREEVIEW_SetAutoScrollH(hTree, (Sel == 0) ? 1 : 0);
00326         if (Sel == 2) {
00327           SCROLLBAR_CreateAttached(hTree, 0);
00328         }
00329         break;
00330       }
00331       break;
00332     case GUI_ID_RADIO3:                   // Manage vertical scrollbar
00333       switch (NCode) {
00334       case WM_NOTIFICATION_VALUE_CHANGED:
00335         Sel = RADIO_GetValue(hItem);
00336         if (Sel == 1) {
00337           WM_SetScrollbarV(hTree, 0);
00338         }
00339         TREEVIEW_SetAutoScrollV(hTree, (Sel == 0) ? 1 : 0);
00340         if (Sel == 2) {
00341           SCROLLBAR_CreateAttached(hTree, WIDGET_CF_VERTICAL);
00342         }
00343         break;
00344       }
00345       break;
00346     case GUI_ID_RADIO4:                   // Manage font
00347       switch (NCode) {
00348       case WM_NOTIFICATION_VALUE_CHANGED:
00349         Sel = RADIO_GetValue(hItem);
00350         TREEVIEW_SetFont(hTree, (Sel == 1) ? &GUI_Font24B_1: &GUI_Font13_1);
00351         break;
00352       }
00353       break;
00354     }
00355     break;
00356   case WM_INIT_DIALOG:                    // Initialize the items of the dialog
00357     hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
00358     RADIO_SetText(hItem, "Text select", 0);
00359     RADIO_SetText(hItem, "Row select",  1);
00360     RADIO_SetValue(hItem, 1);
00361     hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO1);
00362     RADIO_SetText(hItem, "Off", 0);
00363     RADIO_SetText(hItem, "On",  1);
00364     RADIO_SetValue(hItem, 1);
00365     hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO4);
00366     RADIO_SetText(hItem, "Small font", 0);
00367     RADIO_SetText(hItem, "Large font",  1);
00368     break;
00369   default:
00370     WM_DefaultProc(pMsg);
00371   }
00372 }
00373 
00374 /*********************************************************************
00375 *
00376 *       _cbPage1
00377 *
00378 * Function description
00379 *   Callback routine for the second page of the multipage widget
00380 */
00381 static void _cbPage1(WM_MESSAGE * pMsg) {
00382   TREEVIEW_ITEM_Handle hTVI0;
00383   TREEVIEW_ITEM_Handle hTVI1;
00384   TREEVIEW_ITEM_INFO   ItemInfo;
00385   WM_HWIN              hItem;
00386   WM_HWIN              hDlg;
00387   WM_HWIN              hTree0;
00388   WM_HWIN              hTree1;
00389   int                  i;
00390   int                  NCode;
00391   int                  Id;
00392 
00393   hDlg  = pMsg->hWin;
00394   switch (pMsg->MsgId) {
00395   case WM_NOTIFY_PARENT:
00396     hTree0= WM_GetDialogItem(WM_GetFirstChild(WM_HBKWIN), GUI_ID_TREEVIEW0);
00397     hTree1= WM_GetDialogItem(WM_GetFirstChild(WM_HBKWIN), GUI_ID_TREEVIEW1);
00398     Id    = WM_GetId(pMsg->hWinSrc);      // Id of widget
00399     NCode = pMsg->Data.v;                 // Notification code
00400     WM_GetDialogItem(hDlg, Id);
00401     switch (Id) {
00402     case GUI_ID_BUTTON0:                  // Delete
00403       switch (NCode) {
00404       case WM_NOTIFICATION_RELEASED:
00405         hTVI0 = TREEVIEW_GetSel(hTree0);
00406         if (hTVI0) {
00407           TREEVIEW_ITEM_Delete(hTVI0);
00408         } else {
00409           GUI_MessageBox("No item selected!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00410           WM_SetFocus(hTree0);
00411         }
00412         break;
00413       }
00414       break;
00415     case GUI_ID_BUTTON1:                  // Detach
00416       switch (NCode) {
00417       case WM_NOTIFICATION_RELEASED:
00418         hTVI1 = TREEVIEW_GetItem(hTree1, 0, TREEVIEW_GET_FIRST);
00419         if (hTVI1) {
00420           TREEVIEW_ITEM_Delete(hTVI1);
00421         }
00422         hTVI0 = TREEVIEW_GetSel(hTree0);
00423         TREEVIEW_ITEM_Detach(hTVI0);
00424         TREEVIEW_AttachItem(hTree1, hTVI0, 0, TREEVIEW_GET_FIRST);
00425         break;
00426       }
00427       break;
00428     case GUI_ID_BUTTON2:                  // Attach
00429       switch (NCode) {
00430       case WM_NOTIFICATION_RELEASED:
00431         hTVI1 = TREEVIEW_GetItem(hTree1, 0, TREEVIEW_GET_FIRST);
00432         if (hTVI1) {
00433           hTVI0 = TREEVIEW_GetSel(hTree0);
00434           TREEVIEW_ITEM_Detach(hTVI1);
00435           if (hTVI0) {
00436             TREEVIEW_AttachItem(hTree0, hTVI1, hTVI0, TREEVIEW_INSERT_ABOVE);
00437           } else {
00438             TREEVIEW_AttachItem(hTree0, hTVI1,     0, 0);
00439           }
00440         } else {
00441           GUI_MessageBox("No item in buffer!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00442           WM_SetFocus(hTree0);
00443         }
00444         break;
00445       }
00446       break;
00447     case GUI_ID_BUTTON3:                  // Move up
00448       switch (NCode) {
00449       case WM_NOTIFICATION_RELEASED:
00450         hTVI0 = TREEVIEW_GetSel(hTree0);
00451         if (hTVI0) {
00452           hTVI1 = TREEVIEW_GetItem(hTree0, hTVI0, TREEVIEW_GET_PREV_SIBLING);
00453           if (hTVI1) {
00454             TREEVIEW_ITEM_Detach(hTVI0);
00455             TREEVIEW_AttachItem(hTree0, hTVI0, hTVI1, TREEVIEW_INSERT_ABOVE);
00456             TREEVIEW_SetSel(hTree0, hTVI0);
00457           } else {
00458             GUI_MessageBox("Item is already on top!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00459             WM_SetFocus(hTree0);
00460           }
00461         }
00462         break;
00463       }
00464       break;
00465     case GUI_ID_BUTTON4:                  // Move down
00466       switch (NCode) {
00467       case WM_NOTIFICATION_RELEASED:
00468         hTVI0 = TREEVIEW_GetSel(hTree0);
00469         if (hTVI0) {
00470           hTVI1 = TREEVIEW_GetItem(hTree0, hTVI0, TREEVIEW_GET_NEXT_SIBLING);
00471           if (hTVI1) {
00472             TREEVIEW_ITEM_Detach(hTVI0);
00473             TREEVIEW_AttachItem(hTree0, hTVI0, hTVI1, TREEVIEW_INSERT_BELOW);
00474             TREEVIEW_SetSel(hTree0, hTVI0);
00475           } else {
00476             GUI_MessageBox("Item is already on bottom!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00477             WM_SetFocus(hTree0);
00478           }
00479         }
00480         break;
00481       }
00482       break;
00483     case GUI_ID_BUTTON5:                   // New node
00484       switch (NCode) {
00485       case WM_NOTIFICATION_RELEASED:
00486         hTVI0 = TREEVIEW_GetSel(hTree0);
00487         if (hTVI0) {
00488           TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo);
00489           if (ItemInfo.IsNode) {
00490             hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_NODE, hTVI0, TREEVIEW_INSERT_BELOW,  "New node");
00491           } else {
00492             hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_NODE, hTVI0, TREEVIEW_INSERT_ABOVE,  "New node");
00493           }
00494         } else {
00495           hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_NODE, 0, 0,  "New node");
00496         }
00497         hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_FIRST_CHILD, "New.A");
00498         hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_BELOW,  "New.B");
00499         hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_BELOW,  "New.C");
00500         TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_BELOW,  "New.D");
00501         break;
00502       }
00503       break;
00504     case GUI_ID_BUTTON6:                  // New leaf
00505       switch (NCode) {
00506       case WM_NOTIFICATION_RELEASED:
00507         hTVI0 = TREEVIEW_GetSel(hTree0);
00508         if (hTVI0) {
00509           TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo);
00510           TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_BELOW,  "New leaf");
00511         } else {
00512           TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, 0, 0,  "New leaf");
00513         }
00514         break;
00515       }
00516       break;
00517     case GUI_ID_BUTTON7:                  // Leaf bitmap
00518       switch (NCode) {
00519       case WM_NOTIFICATION_RELEASED:
00520         hTVI0 = TREEVIEW_GetSel(hTree0);
00521         if (hTVI0) {
00522           TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo);
00523           if (ItemInfo.IsNode == 0) {
00524             TREEVIEW_ITEM_SetImage(hTVI0, TREEVIEW_BI_LEAF, &_bmSmilie);
00525           } else {
00526             GUI_MessageBox("Item is not a leaf!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00527             WM_SetFocus(hTree0);
00528           }
00529         } else {
00530           GUI_MessageBox("No item selected!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00531           WM_SetFocus(hTree0);
00532         }
00533         break;
00534       }
00535       break;
00536     case GUI_ID_BUTTON8:                  // Open bitmap
00537       switch (NCode) {
00538       case WM_NOTIFICATION_RELEASED:
00539         hTVI0 = TREEVIEW_GetSel(hTree0);
00540         if (hTVI0) {
00541           TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo);
00542           if (ItemInfo.IsNode) {
00543             TREEVIEW_ITEM_SetImage(hTVI0, TREEVIEW_BI_OPEN, &_bmBookOpen);
00544           } else {
00545             GUI_MessageBox("Item is not a node!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00546             WM_SetFocus(hTree0);
00547           }
00548         } else {
00549           GUI_MessageBox("No item selected!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00550           WM_SetFocus(hTree0);
00551         }
00552         break;
00553       }
00554       break;
00555     case GUI_ID_BUTTON9:                  // Closed bitmap
00556       switch (NCode) {
00557       case WM_NOTIFICATION_RELEASED:
00558         hTVI0 = TREEVIEW_GetSel(hTree0);
00559         if (hTVI0) {
00560           TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo);
00561           if (ItemInfo.IsNode) {
00562             TREEVIEW_ITEM_SetImage(hTVI0, TREEVIEW_BI_CLOSED, &_bmBookClosed);
00563           } else {
00564             GUI_MessageBox("Item is not a node!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00565             WM_SetFocus(hTree0);
00566           }
00567         } else {
00568           GUI_MessageBox("No item selected!", "Info", GUI_MESSAGEBOX_CF_MODAL);
00569           WM_SetFocus(hTree0);
00570         }
00571         break;
00572       }
00573       break;
00574     }
00575     break;
00576   case WM_INIT_DIALOG:                    // Initialize the items of the dialog
00577     for (i = GUI_ID_BUTTON0; i <= GUI_ID_BUTTON9; i++) {
00578       hItem = WM_GetDialogItem(hDlg, i);
00579       if (hItem) {
00580         BUTTON_SetFocussable(hItem, 0);   // So the focus remains on the treeview after pressing the buttons
00581       }
00582     }
00583     break;
00584   default:
00585     WM_DefaultProc(pMsg);
00586   }
00587 }
00588 
00589 /*********************************************************************
00590 *
00591 *       _InitMultipage
00592 *
00593 * Function description
00594 *   Creates the pages of the multipage widget
00595 */
00596 static void _InitMultipage(WM_HWIN hWin) {
00597   WM_HWIN hPage0;
00598   WM_HWIN hPage1;
00599 
00600   hPage0 = GUI_CreateDialogBox(_aPage0, GUI_COUNTOF(_aPage0), _cbPage0, WM_UNATTACHED, 0, 0);
00601   MULTIPAGE_AddPage(hWin, hPage0, "Properties");
00602   hPage1 = GUI_CreateDialogBox(_aPage1, GUI_COUNTOF(_aPage1), _cbPage1, WM_UNATTACHED, 0, 0);
00603   MULTIPAGE_AddPage(hWin, hPage1, "Data");
00604 }
00605 
00606 /*********************************************************************
00607 *
00608 *       _FillNode
00609 *
00610 * Function description
00611 *   Recursive filling of node
00612 *
00613 * Parameters
00614 *   hTree     - obvious
00615 *   NumNodes  - Number of child nodes to be created at each node
00616 *   NumLeaves - Number of leaves to be created at each node
00617 *   MaxDepth  - Maximum depth (1.1.1.1.1.....)
00618 *   CurDepth  - Current depth
00619 *   acBuffer  - String to be used for TREEVIEW items
00620 *   p         - Pointer into to string to be used for numbering
00621 *
00622 * Return value
00623 *   0 on success, 1 on error
00624 */
00625 static int _FillNode(WM_HWIN hTree, TREEVIEW_ITEM_Handle hNode, int NumChildNodes, int NumChildItems, int MaxDepth, int Depth, char * p) {
00626   static char acBuffer[(TREEVIEW_DEPTH << 1) + 1];
00627   TREEVIEW_ITEM_Handle hItem;
00628   int                  i;
00629   int                  j;
00630   int                  Position;
00631 
00632   hItem = 0;
00633   if (p == NULL) {
00634     p = acBuffer;
00635   }
00636   *(p + 1) = 0;
00637   *p = '0' - 1;
00638   if (--Depth) {
00639     //
00640     // Create nodes
00641     //
00642     for (i = 0; i < NumChildNodes; i++) {
00643       (*p)++;
00644       Position = hItem ? TREEVIEW_INSERT_BELOW : TREEVIEW_INSERT_FIRST_CHILD;
00645       hItem = TREEVIEW_ITEM_Create(1, acBuffer, 0);
00646       if (hItem == 0) {
00647         return 1;  // Error
00648       }
00649       TREEVIEW_AttachItem(hTree, hItem, hNode, Position);
00650       hNode = hItem;
00651       *(p + 1) = '.';
00652       p += 2;
00653       _FillNode(hTree, hNode, NumChildNodes, NumChildItems, MaxDepth, Depth, p);
00654       p -= 2;
00655       *(p + 1) = 0;
00656     }
00657   }
00658   //
00659   // Create leaves
00660   //
00661   for (j = 0; j < NumChildItems; j++) {
00662     (*p)++;
00663     Position = hItem ? TREEVIEW_INSERT_BELOW : TREEVIEW_INSERT_FIRST_CHILD;
00664     hItem = TREEVIEW_ITEM_Create(0, acBuffer, 0);
00665     if (hItem == 0) {
00666       return 1;    // Error
00667     }
00668     TREEVIEW_AttachItem(hTree, hItem, hNode, Position);
00669     hNode = hItem;
00670   }
00671   return 0;
00672 }
00673 
00674 /*********************************************************************
00675 *
00676 *       _InitTreeview
00677 *
00678 * Function description
00679 *   Adds some data to the treeview widget
00680 */
00681 static int _InitTreeview(WM_HWIN hTree) {
00682   TREEVIEW_ITEM_Handle hNode;
00683   int r;
00684 
00685   hNode = TREEVIEW_InsertItem(hTree, TREEVIEW_ITEM_TYPE_NODE, 0, 0, "Tree");
00686   r = _FillNode(hTree, hNode, NUM_CHILD_NODES, NUM_CHILD_ITEMS, TREEVIEW_DEPTH, TREEVIEW_DEPTH, NULL);
00687   if (r) {
00688     //
00689     // Error message
00690     //
00691     WM_DeleteWindow(hTree);
00692     GUI_MessageBox("Error", "Not enough memory available!", 0);
00693     return 1;      // Error
00694   }
00695   TREEVIEW_SetAutoScrollH(hTree, 1);
00696   TREEVIEW_SetAutoScrollV(hTree, 1);
00697   TREEVIEW_ITEM_Expand(hNode);
00698   return 0;
00699 }
00700 
00701 /*********************************************************************
00702 *
00703 *       _cbMain
00704 *
00705 * Function description
00706 *   Callback routine of main window
00707 */
00708 static void _cbMain(WM_MESSAGE * pMsg) {
00709   WM_HWIN hItem;
00710   WM_HWIN hDlg;
00711 
00712   hDlg = pMsg->hWin;
00713   switch (pMsg->MsgId) {
00714   case WM_INIT_DIALOG:
00715     hItem = WM_GetDialogItem(hDlg, GUI_ID_TEXT0);
00716     TEXT_SetFont(hItem, &GUI_Font20B_ASCII);
00717     TEXT_SetTextAlign(hItem, GUI_TA_HCENTER);
00718     hItem = WM_GetDialogItem(hDlg, GUI_ID_MULTIPAGE0);
00719     _InitMultipage(hItem);
00720     hItem = WM_GetDialogItem(hDlg, GUI_ID_TREEVIEW0);
00721     _InitTreeview(hItem);
00722     hItem = WM_GetDialogItem(hDlg, GUI_ID_TREEVIEW1);
00723     WM_DisableWindow(hItem);
00724     break;
00725   case WM_PAINT:
00726     break;
00727   default:
00728     WM_DefaultProc(pMsg);
00729   }
00730 }
00731 
00732 /*********************************************************************
00733 *
00734 *       Public code
00735 *
00736 **********************************************************************
00737 */
00738 /*********************************************************************
00739 *
00740 *       MainTask
00741 */
00742 void MainTask(void) {
00743   WM_HWIN hItem;
00744   WM_HWIN hDlg;
00745 
00746   GUI_Init();
00747   //
00748   // Check if recommended memory for the sample is available
00749   //
00750   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00751     GUI_ErrorOut("Not enough memory available."); 
00752     return;
00753   }
00754   #if GUI_SUPPORT_CURSOR
00755     GUI_CURSOR_Show();
00756   #endif
00757   #if GUI_SUPPORT_MEMDEV
00758     WM_SetCreateFlags(WM_CF_MEMDEV);
00759   #endif
00760   hDlg = GUI_CreateDialogBox(_aMain, GUI_COUNTOF(_aMain), _cbMain, 0, 0, 0);
00761   hItem = WM_GetDialogItem(hDlg, GUI_ID_TREEVIEW0);
00762   if (hItem == 0) {
00763     WM_DeleteWindow(hDlg);
00764   } else {
00765     WM_SetFocus(hItem);
00766     while (1) {
00767       GUI_Delay(100);
00768     }
00769   }
00770 }
00771 
00772 /*************************** End of file ****************************/