/*********************************************************************
*                    SEGGER Microcontroller GmbH                     *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 1996 - 2022  SEGGER Microcontroller GmbH                *
*                                                                    *
*        Internet: www.segger.com    Support:  support@segger.com    *
*                                                                    *
**********************************************************************

** emWin V6.26 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws.   Knowledge of the
source code may not be used to write a similar product.  This file may
only  be used  in accordance  with  a license  and should  not be  re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File        : SCROLLER_Usage_DefaultWidgets.c
Purpose     : Sample that demonstrates how SCROLLER widgets can be
              attached to emWin widgets.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
Wiki link   : https://wiki.segger.com/SCROLLER_-_Usage_DefaultWidgets_(Sample)
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
/*********************************************************************
*
*       _acContent_Listview
*/
static const char * _acContent_Listview[][3] = {
  { "1002", "Murphy",    "Diane",    },
  { "1056", "Patterson", "Mary",     },
  { "1076", "Firrelli",  "Jeff",     },
  { "1088", "Patterson", "William",  },
  { "1102", "Bondur",    "Gerard",   },
  { "1143", "Bow",       "Anthony",  },
  { "1165", "Jennings",  "Leslie",   },
  { "1166", "Thompson",  "Leslie",   },
  { "1188", "Firrelli",  "Julie",    },
  { "1216", "Patterson", "Steve",    },
  { "1286", "Tseng",     "Foon Yue", },
  { "1002", "Murphy",    "Diane",    },
  { "1056", "Patterson", "Mary",     },
  { "1076", "Firrelli",  "Jeff",     },
  { "1088", "Patterson", "William",  },
  { "1102", "Bondur",    "Gerard",   },
  { "1143", "Bow",       "Anthony",  },
  { "1165", "Jennings",  "Leslie",   },
  { "1166", "Thompson",  "Leslie",   },
  { "1188", "Firrelli",  "Julie",    },
  { "1216", "Patterson", "Steve",    },
  { "1286", "Tseng",     "Foon Yue", },
  { "1002", "Murphy",    "Diane",    },
  { "1056", "Patterson", "Mary",     },
  { "1076", "Firrelli",  "Jeff",     },
  { "1088", "Patterson", "William",  },
  { "1102", "Bondur",    "Gerard",   },
  { "1143", "Bow",       "Anthony",  },
  { "1165", "Jennings",  "Leslie",   },
  { "1166", "Thompson",  "Leslie",   },
  { "1188", "Firrelli",  "Julie",    },
  { "1216", "Patterson", "Steve",    },
  { "1286", "Tseng",     "Foon Yue", },
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _CreateListview
*/
static LISTVIEW_Handle _CreateListview(void) {
  LISTVIEW_Handle hListview;
  int             i;

  //
  // Create listview widget
  //
  hListview = LISTVIEW_CreateEx(0, 0, 200, LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTVIEW0);
  //
  // Add columns to listview
  //
  LISTVIEW_AddColumn(hListview, 45, "Emp. Nr.", GUI_TA_LEFT);
  LISTVIEW_AddColumn(hListview, 60, "Last Name", GUI_TA_LEFT);
  LISTVIEW_AddColumn(hListview, 60, "First Name", GUI_TA_LEFT);
  //
  // Add rows to listview
  //
  for (i = 0; i < GUI_COUNTOF(_acContent_Listview); i++) {
    LISTVIEW_AddRow(hListview, _acContent_Listview[i]);
  }
  //
  // Set compare functions
  //
  LISTVIEW_SetCompareFunc(hListview, 0, LISTVIEW_CompareDec);
  LISTVIEW_SetCompareFunc(hListview, 1, LISTVIEW_CompareText);
  LISTVIEW_SetCompareFunc(hListview, 2, LISTVIEW_CompareText);
  //
  // Enable sorting
  //
  LISTVIEW_EnableSort(hListview);
  //
  // Enable motion
  //
  LISTVIEW_EnableMotion(hListview, LISTVIEW_CF_MOTION_V);
  return hListview;
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  LISTVIEW_Handle hListview;
  SCROLLER_Handle hScroller;

  //
  // Init GUI
  //
  GUI_Init();
  WM_SetDesktopColor(GUI_WHITE);
  //
  // Enable multi-buffering
  //
  WM_MULTIBUF_Enable(1);
  //
  // Create LISTVIEW
  //
  hListview = _CreateListview();
  //
  // Attach SCROLLER to LISTVIEW with fading and touch enabled.
  // The same way a SCROLLER can be attached to the widgets LISTBOX,
  // MULTIEDIT, SWIPELIST and DROPDOWN.
  //
  hScroller = SCROLLER_CreateAttached(hListview, SCROLLER_CF_VERTICAL | SCROLLER_CF_FADING | SCROLLER_CF_TOUCH);

  while (1) {
    GUI_Delay(100);
  }
}

/*************************** End of file ****************************/
