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

« Back to documentation index

Show/hide line numbers WIDGET_SchemeLarge.c Source File

WIDGET_SchemeLarge.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_EffectVGA.c
00041 Purpose     : Example demonstrating the use of widget effects
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - (x)
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ----------------------------------------------------------------------
00049 */
00050 
00051 #include <stdlib.h>
00052 #include <stddef.h>
00053 #include <string.h>
00054 #include "GUI.h"
00055 #include "DIALOG.h"
00056 #include "PROGBAR.h"
00057 #include "LISTVIEW.h"
00058 #include "GRAPH.h"
00059 #include "MULTIPAGE.h"
00060 #include "MENU.h"
00061 #include "LCDConf.h"
00062 #include "GUIConf.h"
00063 
00064 #if !defined(WIDGET_USE_SCHEME_LARGE)
00065   #error Wrong scheme selected!
00066 #endif
00067 
00068 /*********************************************************************
00069 *
00070 *       Defines
00071 *
00072 **********************************************************************
00073 */
00074 #define NUM_WIDGETS         GUI_COUNTOF(_aID)
00075 #define ID_MENU             (GUI_ID_USER +  0)
00076 #define ID_MENU_FILE_NEW    (GUI_ID_USER +  1)
00077 #define ID_MENU_FILE_OPEN   (GUI_ID_USER +  2)
00078 #define ID_MENU_FILE_CLOSE  (GUI_ID_USER +  3)
00079 #define ID_MENU_FILE_EXIT   (GUI_ID_USER +  4)
00080 #define ID_MENU_FILE_RECENT (GUI_ID_USER +  5)
00081 #define ID_MENU_RECENT_0    (GUI_ID_USER +  6)
00082 #define ID_MENU_RECENT_1    (GUI_ID_USER +  7)
00083 #define ID_MENU_RECENT_2    (GUI_ID_USER +  8)
00084 #define ID_MENU_RECENT_3    (GUI_ID_USER +  9)
00085 #define ID_MENU_EDIT_UNDO   (GUI_ID_USER + 10)
00086 #define ID_MENU_EDIT_REDO   (GUI_ID_USER + 11)
00087 #define ID_MENU_EDIT_COPY   (GUI_ID_USER + 12)
00088 #define ID_MENU_EDIT_PASTE  (GUI_ID_USER + 13)
00089 #define ID_MENU_EDIT_DELETE (GUI_ID_USER + 14)
00090 #define ID_MENU_HELP_ABOUT  (GUI_ID_USER + 15)
00091 
00092 //
00093 // Recommended memory to run the sample with adequate performance
00094 //
00095 #define RECOMMENDED_MEMORY (1024L * 60)
00096 
00097 /*********************************************************************
00098 *
00099 *       Static data
00100 *
00101 **********************************************************************
00102 */
00103 //
00104 // Dialog resource of main dialog box
00105 //
00106 static const GUI_WIDGET_CREATE_INFO _aDlgWidgets[] = {
00107   { WINDOW_CreateIndirect,    "",             0,                    0,   0, 690, 435, 0},
00108   { TEXT_CreateIndirect,      "Progress bar",  GUI_ID_TEXT0,       10,  35, 120,  25, TEXT_CF_HCENTER},
00109   { PROGBAR_CreateIndirect,   NULL,            GUI_ID_PROGBAR0,    10,  60, 120,  25 },
00110   { TEXT_CreateIndirect,      "Button",        GUI_ID_TEXT0,       10,  90, 120,  25, TEXT_CF_HCENTER},
00111   { BUTTON_CreateIndirect,    "Button",        GUI_ID_BUTTON0,     10, 115, 120,  25 },
00112   { TEXT_CreateIndirect,      "Dropdown",      GUI_ID_TEXT0,       10, 145, 120,  25, TEXT_CF_HCENTER},
00113   { DROPDOWN_CreateIndirect,  NULL,            GUI_ID_DROPDOWN0,   10, 170, 120,  85, DROPDOWN_CF_AUTOSCROLLBAR},
00114   { TEXT_CreateIndirect,      "Edit",          GUI_ID_TEXT0,      150,  35, 120,  25, TEXT_CF_HCENTER},
00115   { EDIT_CreateIndirect,      NULL,            GUI_ID_EDIT0,      150,  60, 120,  25 },
00116   { TEXT_CreateIndirect,      "Listbox",       GUI_ID_TEXT0,      150,  90, 120,  25, TEXT_CF_HCENTER},
00117   { LISTBOX_CreateIndirect,   "",              GUI_ID_LISTBOX0,   150, 115, 120, 165, 0, 0 },
00118   { TEXT_CreateIndirect,      "Listview",      GUI_ID_TEXT0,      290,  35, 150,  25, TEXT_CF_HCENTER},
00119   { LISTVIEW_CreateIndirect,  NULL,            GUI_ID_LISTVIEW0,  290,  60, 150, 135, 0 },
00120   { TEXT_CreateIndirect,      "Multiedit",     GUI_ID_TEXT0,      290, 200, 150,  25, TEXT_CF_HCENTER},
00121   { MULTIEDIT_CreateIndirect, "",              GUI_ID_MULTIEDIT0, 290, 225, 150,  60, 0, 0 },
00122   { TEXT_CreateIndirect,      "Scrollbars",    GUI_ID_TEXT0,      460,  35, 100,  25, TEXT_CF_HCENTER},
00123   { SCROLLBAR_CreateIndirect, NULL,            GUI_ID_SCROLLBAR1, 460,  60,  20, 200, SCROLLBAR_CF_VERTICAL },
00124   { SCROLLBAR_CreateIndirect, NULL,            GUI_ID_SCROLLBAR2, 490,  60,  70, 200, SCROLLBAR_CF_VERTICAL },
00125   { SCROLLBAR_CreateIndirect, NULL,            GUI_ID_SCROLLBAR0, 460, 270, 100,  15, 0 },
00126   { TEXT_CreateIndirect,      "Sliders",       GUI_ID_TEXT0,      580,  35, 100,  25, TEXT_CF_HCENTER},
00127   { SLIDER_CreateIndirect,    NULL,            GUI_ID_SLIDER1,    580,  60,  20, 200, SLIDER_CF_VERTICAL },
00128   { SLIDER_CreateIndirect,    NULL,            GUI_ID_SLIDER2,    610,  60,  70, 200, SLIDER_CF_VERTICAL },
00129   { SLIDER_CreateIndirect,    NULL,            GUI_ID_SLIDER0,    580, 270, 100,  15, 0 },
00130   { TEXT_CreateIndirect,      "Graph",         GUI_ID_TEXT0,      210, 300, 175,  25, TEXT_CF_HCENTER},
00131   { GRAPH_CreateIndirect,     0,               GUI_ID_GRAPH0,     210, 325, 175, 100 },
00132   { TEXT_CreateIndirect,      "Multipage",     GUI_ID_TEXT0,      400, 300, 220,  25, TEXT_CF_HCENTER},
00133   { MULTIPAGE_CreateIndirect, "Multipage",     GUI_ID_MULTIPAGE0, 400, 325, 220, 100 },
00134 };
00135 //
00136 // Dialog resource of options dialog box
00137 //
00138 static const GUI_WIDGET_CREATE_INFO _aDlgOptions[] = {
00139   { FRAMEWIN_CreateIndirect,  "Effect", 0,                  10, 325, 185, 120,   0},
00140   { CHECKBOX_CreateIndirect,  NULL,     GUI_ID_CHECK0,       0,   2,  90,   0 },
00141   { RADIO_CreateIndirect,     NULL,     GUI_ID_RADIO0,      80,   2,  95, 100,   0,  0x1e03 },
00142 };
00143 //
00144 // Dialog resource of first multipage window
00145 //
00146 static const GUI_WIDGET_CREATE_INFO _aDialogCreate1[] = {
00147   { WINDOW_CreateIndirect,    "Dialog 1", 0,                   0,   0, 260, 100  },
00148   { TEXT_CreateIndirect,      "Dialog 1", 0,                   5,   5,  80,  25, TEXT_CF_LEFT },
00149   { BUTTON_CreateIndirect,    "Button",   GUI_ID_BUTTON0,      5,  30,  80,  25, 0},
00150 };
00151 //
00152 // Dialog resource of second multipage window
00153 //
00154 static const GUI_WIDGET_CREATE_INFO _aDialogCreate2[] = {
00155   { WINDOW_CreateIndirect,    "Dialog 2", 0,                   0,   0, 260, 100, },
00156   { TEXT_CreateIndirect,      "Dialog 2", 0,                   5,   5,  80,  25, TEXT_CF_LEFT },
00157   { SLIDER_CreateIndirect,    "",         GUI_ID_SLIDER0,      5,  30, 200,  40  },
00158 };
00159 //
00160 // Array of widget ID's
00161 //
00162 static int _aID[] = { GUI_ID_BUTTON0,    GUI_ID_EDIT0,      GUI_ID_LISTBOX0,   GUI_ID_PROGBAR0,   
00163                       GUI_ID_LISTVIEW0,  GUI_ID_MULTIEDIT0, GUI_ID_DROPDOWN0,  GUI_ID_SCROLLBAR0, 
00164                       GUI_ID_SCROLLBAR1, GUI_ID_SCROLLBAR2, GUI_ID_SLIDER0,    GUI_ID_SLIDER1,    
00165                       GUI_ID_SLIDER2,    GUI_ID_GRAPH0,     GUI_ID_MULTIPAGE0};
00166 //
00167 // Array of widget handles
00168 //
00169 static WM_HWIN _ahWin[GUI_COUNTOF(_aID)];
00170 //
00171 // Makes it easier to access the array _ahWin
00172 //
00173 enum { BUTTON0,    EDIT0,      LISTBOX0,   PROGBAR0, 
00174        LISTVIEW0,  MULTIEDIT0, DROPDOWN0,  SCROLLBAR0, 
00175        SCROLLBAR1, SCROLLBAR2, SLIDER0,    SLIDER1,    
00176        SLIDER2,    GRAPH0,     MULTIPAGE0};
00177 //
00178 // Array of available effects
00179 //
00180 const WIDGET_EFFECT * _apEffect[] = {&WIDGET_Effect_3D,     
00181                                      &WIDGET_Effect_Simple, 
00182                                      &WIDGET_Effect_None};
00183 //
00184 // Array of strings used to label the frame window
00185 //
00186 const char *   _apEffects[] = {"Widget effect: 3D",
00187                                "Widget effect: Simple", 
00188                                "Widget effect: None"};
00189 //
00190 // Used for graph widget
00191 //
00192 static I16                _aValue[3];                                      // Array of values to be added
00193 static GRAPH_DATA_Handle  _ahData[3];                                      // Array of handles for the GRAPH_DATA objects
00194 static GUI_COLOR          _aColor[] = {GUI_RED, GUI_GREEN, GUI_LIGHTBLUE}; // Array of colors for the GRAPH_DATA objects
00195 static WM_HWIN            _hDlg;
00196 static WM_HWIN            _hFrameWin;
00197 static int                _AutoMode = 1;
00198 
00199 /*********************************************************************
00200 *
00201 *       Static code
00202 *
00203 **********************************************************************
00204 */
00205 /*********************************************************************
00206 *
00207 *       _AddValues
00208 *
00209 * Function description
00210 *   This routine calculates new random values in dependence of the previous added values
00211 *   and adds them to the GRAPH_DATA objects
00212 */
00213 static void _AddValues(int MaxValue) {
00214   unsigned i;
00215 
00216   for (i = 0; i < GUI_COUNTOF(_aValue); i++) {
00217     int Add = rand() % (2 + i * i);
00218     int Vz  = ((rand() % 2) << 1) - 1;
00219     _aValue[i] += Add * Vz;
00220     if (_aValue[i] > MaxValue) {
00221       _aValue[i] = MaxValue;
00222     } else if (_aValue[i] < 0) {
00223       _aValue[i] = 0;
00224     }
00225     GRAPH_DATA_YT_AddValue(_ahData[i], _aValue[i]);
00226   }
00227 }
00228 
00229 /*********************************************************************
00230 *
00231 *       _SetWidgetEffect
00232 *
00233 * Function description
00234 *   Sets the effect for the given widget and recursive for its child windows
00235 */
00236 static void _SetWidgetEffect(WM_HWIN hWin, const WIDGET_EFFECT * pEffect) {
00237   WM_HWIN hChild;
00238 
00239   if (hWin) {
00240     WIDGET_SetEffect(hWin, pEffect); /* Set effect for the widget*/
00241     //
00242     // Iterate over the child windows
00243     //
00244     hChild = WM_GetFirstChild(hWin);
00245     while (hChild) {
00246       _SetWidgetEffect(hChild, pEffect); /* Set effect for the child windows */
00247       hChild = WM_GetNextSibling(hChild);
00248     }
00249   }
00250 }
00251 
00252 /*********************************************************************
00253 *
00254 *       _SetEffect
00255 */
00256 static void _SetEffect(int Index) {
00257   unsigned              i;
00258   const WIDGET_EFFECT * pEffect;
00259 
00260   pEffect = _apEffect[Index];
00261   WIDGET_SetDefaultEffect(pEffect);
00262   FRAMEWIN_SetText(_hFrameWin, _apEffects[Index]);
00263   //
00264   // Iterate over all dialog widgets
00265   //
00266   for (i = 0; i < NUM_WIDGETS; i++) {
00267     _SetWidgetEffect(_ahWin[i], _apEffect[Index]); /* Set effect */
00268   }
00269 }
00270 
00271 /*********************************************************************
00272 *
00273 *       _AddMenuItem
00274 */
00275 static void _AddMenuItem(MENU_Handle hMenu, MENU_Handle hSubmenu, const char* pText, U16 Id, U16 Flags) {
00276   MENU_ITEM_DATA Item;
00277 
00278   Item.pText    = pText;
00279   Item.hSubmenu = hSubmenu;
00280   Item.Flags    = Flags;
00281   Item.Id       = Id;
00282   MENU_AddItem(hMenu, &Item);
00283 }
00284 
00285 /*********************************************************************
00286 *
00287 *       _CreateMenu
00288 */
00289 static WM_HWIN _CreateMenu(WM_HWIN hParent) {
00290   MENU_Handle hMenu;
00291   MENU_Handle hMenuFile;
00292   MENU_Handle hMenuEdit;
00293   MENU_Handle hMenuHelp;
00294   MENU_Handle hMenuRecent;
00295   //
00296   // Create main menu
00297   //
00298   hMenu       = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_HORIZONTAL, ID_MENU);
00299   //
00300   // Create sub menus
00301   //
00302   hMenuFile   = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0);
00303   hMenuEdit   = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0);
00304   hMenuHelp   = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0);
00305   hMenuRecent = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0);
00306   //
00307   // Add menu items to menu 'Recent'
00308   //
00309   _AddMenuItem(hMenuRecent, 0,           "File 0",   ID_MENU_RECENT_0,    0);
00310   _AddMenuItem(hMenuRecent, 0,           "File 1",   ID_MENU_RECENT_1,    0);
00311   _AddMenuItem(hMenuRecent, 0,           "File 2",   ID_MENU_RECENT_2,    0);
00312   _AddMenuItem(hMenuRecent, 0,           "File 3",   ID_MENU_RECENT_3,    0);
00313   //
00314   // Add menu items to menu 'File'
00315   //
00316   _AddMenuItem(hMenuFile,   0,           "New",      ID_MENU_FILE_NEW,    0);
00317   _AddMenuItem(hMenuFile,   0,           "Open",     ID_MENU_FILE_OPEN,   0);
00318   _AddMenuItem(hMenuFile,   0,           "Close",    ID_MENU_FILE_CLOSE,  0);
00319   _AddMenuItem(hMenuFile,   0,           0,          0,                   MENU_IF_SEPARATOR);
00320   _AddMenuItem(hMenuFile,   hMenuRecent, "Files...", ID_MENU_FILE_RECENT, 0);
00321   _AddMenuItem(hMenuFile,   0,           0,          0,                   MENU_IF_SEPARATOR);
00322   _AddMenuItem(hMenuFile,   0,           "Exit",     ID_MENU_FILE_EXIT,   0);
00323   //
00324   // Add menu items to menu 'Edit'
00325   //
00326   _AddMenuItem(hMenuEdit,   0,           "Undo",     ID_MENU_EDIT_UNDO,   0);
00327   _AddMenuItem(hMenuEdit,   0,           "Redo",     ID_MENU_EDIT_REDO,   0);
00328   _AddMenuItem(hMenuEdit,   0,           0,          0,                   MENU_IF_SEPARATOR);
00329   _AddMenuItem(hMenuEdit,   0,           "Copy",     ID_MENU_EDIT_COPY,   0);
00330   _AddMenuItem(hMenuEdit,   0,           "Paste",    ID_MENU_EDIT_PASTE,  0);
00331   _AddMenuItem(hMenuEdit,   0,           "Delete",   ID_MENU_EDIT_DELETE, 0);
00332   //
00333   // Add menu items to menu 'Help'
00334   //
00335   _AddMenuItem(hMenuHelp,   0,           "About",    ID_MENU_HELP_ABOUT,  0);
00336   //
00337   // Add menu items to main menu
00338   //
00339   _AddMenuItem(hMenu,       hMenuFile,   "File",     0,                   0);
00340   _AddMenuItem(hMenu,       hMenuEdit,   "Edit",     0,                   0);
00341   _AddMenuItem(hMenu,       hMenuHelp,   "Help",     0,                   0);
00342   //
00343   // Attach menu to parent window
00344   //
00345   MENU_Attach(hMenu, hParent, 0, 0, WM_GetWindowSizeX(hParent), 0, 0);
00346   return hMenu;
00347 }
00348 
00349 /*********************************************************************
00350 *
00351 *       _cbBkWindow
00352 */
00353 static void _cbBkWindow(WM_MESSAGE * pMsg) {
00354   switch (pMsg->MsgId) {
00355   case WM_PAINT:
00356     GUI_SetBkColor(GUI_BLUE);
00357     GUI_Clear();
00358     GUI_SetColor(GUI_WHITE);
00359     GUI_SetFont(&GUI_Font24_ASCII);
00360     GUI_DispStringHCenterAt("WIDGET_Effect - Sample", 160, 5);
00361   default:
00362     WM_DefaultProc(pMsg);
00363   }
00364 }
00365 
00366 /*********************************************************************
00367 *
00368 *       _cbDialogPage
00369 *
00370 * Function description
00371 *   Dialog routine for multi page windows
00372 */
00373 static void _cbDialogPage(WM_MESSAGE * pMsg) {
00374   WM_DefaultProc(pMsg);
00375 }
00376 
00377 /*********************************************************************
00378 *
00379 *       _cbCallbackWidgets
00380 *
00381 * Function description
00382 *   Initializes the widgets of the main dialog box
00383 */
00384 static void _cbCallbackWidgets(WM_MESSAGE * pMsg) {
00385   GRAPH_SCALE_Handle hScaleH;
00386   GRAPH_SCALE_Handle hScaleV;
00387   WM_HWIN            hDlg;
00388   unsigned           i;
00389 
00390   hDlg = pMsg->hWin;
00391   switch (pMsg->MsgId) {
00392     case WM_INIT_DIALOG:
00393       //
00394       // Get handles of widgets
00395       //
00396       for (i = 0; i < NUM_WIDGETS; i++) {
00397         _ahWin[i] = WM_GetDialogItem(hDlg, _aID[i]);
00398       }
00399       //
00400       // Init dropdown widget
00401       //
00402       for (i = 0; i < 8; i++) {
00403         char acBuffer[] = {"Item x"};
00404         int Len = strlen(acBuffer);
00405         acBuffer[Len - 1] = '1' + i;
00406         DROPDOWN_AddString(_ahWin[DROPDOWN0], acBuffer);
00407       }
00408       //
00409       // Init edit widget
00410       //
00411       EDIT_SetText(_ahWin[EDIT0], "Edit");
00412       //
00413       // Init listbox widget
00414       //
00415       LISTBOX_SetAutoScrollV(_ahWin[LISTBOX0], 1);
00416       for (i = 0; i < 4; i++) {
00417         char acBuffer[] = {"Item x"};
00418         int Len = strlen(acBuffer);
00419         acBuffer[Len - 1] = '1' + i;
00420         LISTBOX_AddString(_ahWin[LISTBOX0], acBuffer);
00421       }
00422       //
00423       // Init listview widget
00424       //
00425       for (i = 0; i < 2; i++) {
00426         char acBuffer[] = {"Col. x"};
00427         int Len = strlen(acBuffer);
00428         acBuffer[Len - 1] = '1' + i;
00429         LISTVIEW_AddColumn(_ahWin[LISTVIEW0], 60, acBuffer, GUI_TA_CENTER);
00430       }
00431       for (i = 0; i < 9; i++) {
00432         int j;
00433         LISTVIEW_AddRow(_ahWin[LISTVIEW0], NULL);
00434         for (j = 0; j < (int)LISTVIEW_GetNumColumns(_ahWin[LISTVIEW0]); j++) {
00435           char acBuffer[] = {"Rx/Cx"};
00436           acBuffer[1] = '1' + i;
00437           acBuffer[4] = '1' + j;
00438           LISTVIEW_SetItemText(_ahWin[LISTVIEW0], j, i, acBuffer);
00439         }
00440       }
00441       LISTVIEW_SetGridVis(_ahWin[LISTVIEW0], 1);
00442       SCROLLBAR_CreateAttached(_ahWin[LISTVIEW0], SCROLLBAR_CF_VERTICAL);
00443       //
00444       // Init multiedit widget
00445       //
00446       MULTIEDIT_SetText(_ahWin[MULTIEDIT0], "This text could be modified by the MULTIEDIT widget");
00447       MULTIEDIT_SetWrapWord(_ahWin[MULTIEDIT0]);
00448       MULTIEDIT_SetAutoScrollV(_ahWin[MULTIEDIT0], 1);
00449       //
00450       // Init progbar widget
00451       //
00452       WIDGET_SetEffect(_ahWin[PROGBAR0], &WIDGET_Effect_3D);
00453       //
00454       // Init graph widget
00455       //
00456       for (i = 0; i < GUI_COUNTOF(_aColor); i++) {
00457         _aValue[i] = rand() % 95;
00458         _ahData[i] = GRAPH_DATA_YT_Create(_aColor[i], 500, 0, 0);
00459         GRAPH_AttachData(_ahWin[GRAPH0], _ahData[i]);
00460       }
00461       GRAPH_SetGridDistY(_ahWin[GRAPH0], 25);
00462       GRAPH_SetGridVis(_ahWin[GRAPH0], 1);
00463       GRAPH_SetGridFixedX(_ahWin[GRAPH0], 1);
00464       GRAPH_SetBorder(_ahWin[GRAPH0], 20, 4, 5, 4);
00465       //
00466       // Create and add vertical scale of graph widget
00467       //
00468       hScaleV = GRAPH_SCALE_Create(18, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 25);
00469       GRAPH_SCALE_SetTextColor(hScaleV, GUI_RED);
00470       GRAPH_AttachScale(_ahWin[GRAPH0], hScaleV);
00471       //
00472       // Create and add horizontal scale of graph widget
00473       //
00474       hScaleH = GRAPH_SCALE_Create(46, GUI_TA_HCENTER | GUI_TA_VCENTER, GRAPH_SCALE_CF_HORIZONTAL, 50);
00475       GRAPH_SCALE_SetTextColor(hScaleH, GUI_DARKGREEN);
00476       GRAPH_AttachScale(_ahWin[GRAPH0], hScaleH);
00477       //
00478       // Init multipage widget
00479       //
00480       MULTIPAGE_AddPage(_ahWin[MULTIPAGE0],
00481                         GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbDialogPage, WM_UNATTACHED, 0, 0), 
00482                         "Page 1");
00483       MULTIPAGE_AddPage(_ahWin[MULTIPAGE0],
00484                         GUI_CreateDialogBox(_aDialogCreate2, GUI_COUNTOF(_aDialogCreate2), &_cbDialogPage, WM_UNATTACHED, 0, 0), 
00485                         "Page 2");
00486       //
00487       // Create and attach menu
00488       //
00489       _CreateMenu(hDlg);
00490       break;
00491     default:
00492       WM_DefaultProc(pMsg);
00493   }
00494 }
00495 
00496 /*********************************************************************
00497 *
00498 *       _cbCallbackFramewin
00499 *
00500 * Function description
00501 *   Handles the scroll messages of the scrollbar
00502 */
00503 static void _cbCallbackFramewin(WM_MESSAGE * pMsg) {
00504   WM_HWIN hDlg;
00505 
00506   hDlg = pMsg->hWin;
00507   switch (pMsg->MsgId) {
00508     case WM_NOTIFY_PARENT:
00509       if (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED) {
00510         if (pMsg->hWinSrc == WM_GetScrollbarH(hDlg)) {
00511           int xPos, yPos;
00512           WM_SCROLL_STATE ScrollState;
00513           WM_GetScrollState(pMsg->hWinSrc, &ScrollState);
00514           xPos = WM_GetWindowOrgX(WM_GetParent(_hDlg)) - ScrollState.v;
00515           yPos = WM_GetWindowOrgY(_hDlg);
00516           WM_MoveTo(_hDlg, xPos, yPos);
00517         }
00518       }
00519       break;
00520     default:
00521       WM_DefaultProc(pMsg);
00522   }
00523 }
00524 
00525 /*********************************************************************
00526 *
00527 *       _cbCallbackOptions
00528 *
00529 * Function description
00530 *   Callback of the options dialog box, sets the widget effects
00531 */
00532 static void _cbCallbackOptions(WM_MESSAGE * pMsg) {
00533   WM_HWIN hDlg;
00534   WM_HWIN hItem;
00535 
00536   hDlg = pMsg->hWin;
00537   switch (pMsg->MsgId) {
00538     case WM_INIT_DIALOG:
00539       //
00540       // Init check box
00541       //
00542       hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK0);
00543       CHECKBOX_Check(hItem);
00544       CHECKBOX_SetText(hItem, "Auto");
00545       //
00546       // Init radio button
00547       //
00548       hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
00549       RADIO_SetText(hItem, "3D",     0);
00550       RADIO_SetText(hItem, "Simple", 1);
00551       RADIO_SetText(hItem, "None",   2);
00552       break;
00553     case WM_NOTIFY_PARENT:
00554       if (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED) {
00555         hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
00556         if (pMsg->hWinSrc == hItem) {
00557           _SetEffect(RADIO_GetValue(hItem));
00558         }
00559       } else if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
00560         hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK0);
00561         if (pMsg->hWinSrc == hItem) {
00562           _AutoMode = CHECKBOX_IsChecked(hItem);
00563         }
00564       }
00565       break;
00566     default:
00567       WM_DefaultProc(pMsg);
00568   }
00569 }
00570 
00571 /*********************************************************************
00572 *
00573 *       Public code
00574 *
00575 **********************************************************************
00576 */
00577 /*********************************************************************
00578 *
00579 *       MainTask
00580 */
00581 void MainTask(void) {
00582   GUI_RECT RectDlg;
00583   GUI_RECT RectClient;
00584   WM_HWIN  hScrollbar;
00585   WM_HWIN  hDlgOptions;
00586   int      Cnt;
00587   int      IndexEffect;
00588   int      ButtonState;
00589   int      DropdownState;
00590   int      ProgbarValue;
00591   int      ProgbarInc;
00592   int      SliderValue;
00593   int      SliderInc;
00594   int      ScrollbarValue;
00595   int      ScrollbarInc;
00596   int      ListViewInc;
00597   int      ListBoxInc;
00598   int      MultiEditInc;
00599   int      Vz;
00600   const char          * _apEffects[] = {"Widget effect: 3D", "Widget effect: Simple", "Widget effect: None"};
00601 
00602   Cnt            = 0;
00603   IndexEffect    = 0;
00604   ButtonState    = 0;
00605   DropdownState  = 0;
00606   ProgbarValue   = 0;
00607   ProgbarInc     = 1;
00608   SliderValue    = 0;
00609   SliderInc      = 1;
00610   ScrollbarValue = 0;
00611   ScrollbarInc   = 1;
00612   ListViewInc    = 1;
00613   ListBoxInc     = 1;
00614   MultiEditInc   = 1;
00615   Vz             = 1;
00616   GUI_Init();
00617   //
00618   // Check if recommended memory for the sample is available
00619   //
00620   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00621     GUI_ErrorOut("Not enough memory available."); 
00622     return;
00623   }
00624   GUI_CURSOR_Show();
00625   WM_SetCallback(WM_HBKWIN, _cbBkWindow);
00626   WM_SetCreateFlags(WM_CF_MEMDEV);  // Use memory devices on all windows to avoid flicker
00627   WM_EnableMemdev(WM_HBKWIN);       // Enable use of memory devices for desktop windows
00628   //
00629   // Create framewindow and set its properties
00630   //
00631   _hFrameWin = FRAMEWIN_CreateEx(0, 0, 640, 480, 0, WM_CF_SHOW, 0, 0, "", &_cbCallbackFramewin);
00632   FRAMEWIN_SetMoveable(_hFrameWin, 1);
00633   FRAMEWIN_SetText(_hFrameWin, _apEffects[0]);
00634   FRAMEWIN_SetFont(_hFrameWin, &GUI_Font13B_ASCII);
00635   //
00636   // Create main dialog window as child from framewindows client window
00637   //
00638   _hDlg = GUI_CreateDialogBox(_aDlgWidgets,
00639                               GUI_COUNTOF(_aDlgWidgets), 
00640                               &_cbCallbackWidgets, 
00641                               WM_GetClientWindow(_hFrameWin), 0, 0);
00642   //
00643   // Attach scrollbar to framewindows client window and set its properties
00644   //
00645   hScrollbar = SCROLLBAR_CreateAttached(WM_GetClientWindow(_hFrameWin), 0);
00646   WM_GetWindowRectEx(_hDlg, &RectDlg);
00647   WM_GetClientRectEx(WM_GetClientWindow(_hFrameWin), &RectClient);
00648   SCROLLBAR_SetNumItems(hScrollbar, RectDlg.x1);
00649   SCROLLBAR_SetPageSize(hScrollbar, RectClient.x1);
00650   //
00651   // Create options dialog with 'stay on top' and 'moveable' attribute
00652   //
00653   hDlgOptions = GUI_CreateDialogBox(_aDlgOptions, 
00654                                     GUI_COUNTOF(_aDlgOptions), 
00655                                     &_cbCallbackOptions, 
00656                                     WM_HBKWIN, 0, 0);
00657   FRAMEWIN_SetMoveable(hDlgOptions, 1);
00658   WM_SetStayOnTop(hDlgOptions, 1);
00659   //
00660   // Main loop for modifying the widgets
00661   //
00662   while (1) {
00663     if (_AutoMode) {
00664       Cnt++;
00665       //
00666       // Modify progbar
00667       //
00668       if ((Cnt % 2) == 0) {
00669         ProgbarValue += ProgbarInc;
00670         if ((ProgbarValue == 110) || (ProgbarValue == -10)) {
00671           ProgbarInc *= -1;
00672         }
00673         PROGBAR_SetValue(_ahWin[PROGBAR0], ProgbarValue);
00674       }
00675       //
00676       // Modify slider
00677       //
00678       if ((Cnt % 2) == 0) {
00679         int j;
00680 
00681         SliderValue += SliderInc;
00682         if ((SliderValue == 100) || (SliderValue == 0)) {
00683           SliderInc *= -1;
00684         }
00685         for (j = 0; j < 3; j++) {
00686           SLIDER_SetValue(_ahWin[SLIDER0 + j], SliderValue);
00687         }
00688       }
00689       //
00690       // Modify scrollbar
00691       //
00692       if ((Cnt % 3) == 0) {
00693         int j;
00694 
00695         ScrollbarValue += ScrollbarInc;
00696         if ((ScrollbarValue == 90) || (ScrollbarValue == 0)) {
00697           ScrollbarInc *= -1;
00698         }
00699         for (j = 0; j < 3; j++) {
00700           SCROLLBAR_SetValue(_ahWin[SCROLLBAR0 + j], ScrollbarValue);
00701         }
00702       }
00703       //
00704       // Modify multipage
00705       //
00706       if ((Cnt % 120) == 0) {
00707         MULTIPAGE_SelectPage(_ahWin[MULTIPAGE0], MULTIPAGE_GetSelection(_ahWin[MULTIPAGE0]) ^ 1);
00708       }
00709       //
00710       // Modify dropdown
00711       //
00712       if ((Cnt % 120) == 0) {
00713         DropdownState ^= 1;
00714         if (DropdownState) {
00715           DROPDOWN_Expand(_ahWin[DROPDOWN0]);
00716         } else {
00717           DROPDOWN_Collapse(_ahWin[DROPDOWN0]);
00718         }
00719       }
00720       //
00721       // Modify button
00722       //
00723       if ((Cnt % 40) == 0) {
00724         ButtonState ^= 1;
00725         BUTTON_SetPressed(_ahWin[BUTTON0], ButtonState);
00726       }
00727       //
00728       // Modify listbox
00729       //
00730       if ((Cnt % 30) == 0) {
00731         int Sel;
00732 
00733         Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]);
00734         if (Sel < 0) {
00735           Sel = 0;
00736         }
00737         LISTBOX_SetSel(_ahWin[LISTBOX0], Sel + ListBoxInc);
00738         Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]);
00739         if ((Sel == (int)LISTBOX_GetNumItems(_ahWin[LISTBOX0]) - 1) || (Sel == 0)) {
00740           ListBoxInc *= -1;
00741         }
00742       }
00743       //
00744       // Modify listview
00745       //
00746       if ((Cnt % 50) == 0) {
00747         int Sel;
00748 
00749         Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]);
00750         if (Sel < 0) {
00751           Sel = 0;
00752         }
00753         LISTVIEW_SetSel(_ahWin[LISTVIEW0], Sel + ListViewInc);
00754         Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]);
00755         if ((Sel == (int)LISTVIEW_GetNumRows(_ahWin[LISTVIEW0]) - 1) || (Sel == 0)) {
00756           ListViewInc *= -1;
00757         }
00758       }
00759       //
00760       // Modify multiedit
00761       //
00762       if ((Cnt % 5) == 0) {
00763         int  Sel;
00764         int  Len;
00765         char acBuffer[100];
00766 
00767         MULTIEDIT_SetCursorOffset(_ahWin[MULTIEDIT0], MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]) + MultiEditInc);
00768         MULTIEDIT_GetText(_ahWin[MULTIEDIT0], acBuffer, sizeof(acBuffer));
00769         Sel = MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]);
00770         Len = strlen(acBuffer);
00771         if ((Sel == (Len - 1)) || (Sel == 0)) {
00772           MultiEditInc *= -1;
00773         }
00774         if (!DropdownState) {
00775           WM_SetFocus(_ahWin[MULTIEDIT0]);
00776         }
00777       }
00778       //
00779       // Modify graph
00780       //
00781       _AddValues(95);
00782       //
00783       // Move window
00784       //
00785       if ((Cnt % 1200) == 0) {
00786         int             Inc;
00787         WM_HWIN         hScroll;
00788         WM_SCROLL_STATE ScrollState;
00789 
00790         hScroll = WM_GetScrollbarH(WM_GetClientWindow(_hFrameWin));
00791         WM_GetScrollState(hScroll, &ScrollState);
00792         Inc = (ScrollState.NumItems - ScrollState.PageSize) / 2;
00793         ScrollState.v += Inc * Vz;
00794         if ((ScrollState.v >= Inc * 2) || (ScrollState.v <= 0)) {
00795           Vz *= -1;
00796         }
00797         SCROLLBAR_SetValue(hScroll, ScrollState.v);
00798       }
00799       //
00800       // Change effect
00801       //
00802       if ((Cnt % 400) == 0) {
00803         int     Index;
00804         WM_HWIN hWin;
00805 
00806         IndexEffect++;
00807         Index = IndexEffect % GUI_COUNTOF(_apEffect);
00808         _SetEffect(Index);
00809         hWin = WM_GetDialogItem(hDlgOptions, GUI_ID_RADIO0);
00810         RADIO_SetValue(hWin, Index);
00811       }
00812     }
00813     //
00814     // Wait a while
00815     //
00816     GUI_Delay(10);
00817   }
00818 }
00819 
00820 /*************************** End of file ****************************/
00821