Thursday, April 19th 2018, 8:53pm UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

PeteBone

Beginner

Date of registration: Nov 8th 2017

Posts: 5

Location: Lincolnshire, United Kingdom

Occupation: Senior Hardware and Software Design Engineer

1

Wednesday, January 10th 2018, 12:21pm

LISTVIEW_GetSel() function always returning 0 after vertical scrollbar has been moved.

Hi,

I am writing an application running on a STM32 processor using the STemWin precompiled library based on emWin version 5.40.

I am using a 'LISTVIEW' object in my application to list 100 items for the user to select from.

I am able to select an item from the list and the index is returned correctly until the vertical scrollbar is moved, once the vertical scrollbar has been moved the LISTVIEW_GetSel() function is always returning the value 0 regardless of the selection in the 'LISTVIEW'.

Here is a snippet of my window callback which handles this...

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	static int			selected;

	case WM_NOTIFY_PARENT:
		Id    = WM_GetId(pMsg->hWinSrc);
		NCode = pMsg->Data.v;
		switch(Id) {
			case ID_LISTVIEW_0: // Notifications sent by 'Listview'
				switch(NCode) {
					case WM_NOTIFICATION_CLICKED:
						WM_HideWindow(_hNumKeyboard);
						break;
					case WM_NOTIFICATION_RELEASED:
						break;
					case WM_NOTIFICATION_SEL_CHANGED:
						hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
						selected = LISTVIEW_GetSel(hItem);
						break;
				}
				break;


I have tried using the auto scroll bar function and have also tried adding the scrollbar manually but both scenarios yield the same result.

I would appreciate it if you have any suggestions as to what might be going wrong here. Hopefully I am just missing something obvious!

Thank you in advance.

Kind Regards,

Pete

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 561

2

Wednesday, January 10th 2018, 2:10pm

Hello Pete,

I have tried to reproduce this but it is working on my side. I have tested with the latest version of emWin as well as with V5.40.

Here is the code I have used for testing:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "DIALOG.h"
#include <stdio.h>

/*********************************************************************
*
*   	Defines
*
**********************************************************************
*/
#define ID_WINDOW_0	(GUI_ID_USER + 0x00)
#define ID_LISTVIEW_0  (GUI_ID_USER + 0x02)

/*********************************************************************
*
*   	Static data
*
**********************************************************************
*/
/*********************************************************************
*
*   	_aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
  { LISTVIEW_CreateIndirect, "Listview", ID_LISTVIEW_0, 10, 10, 302, 252, 0, 0x0, 0 },
};

/*********************************************************************
*
*   	Static code
*
**********************************************************************
*/
/*********************************************************************
*
*   	_cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  int 	NCode;
  int 	Id;
  char	acBuffer[64];
  int 	Sel;
  int 	i;

  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
	//
	// Initialization of 'Listview'
	//
	hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
	LISTVIEW_AddColumn(hItem, 100, "Col 0", GUI_TA_HCENTER | GUI_TA_VCENTER);
	LISTVIEW_AddColumn(hItem, 100, "Col 1", GUI_TA_HCENTER | GUI_TA_VCENTER);
	LISTVIEW_AddColumn(hItem, 100, "Col 2", GUI_TA_HCENTER | GUI_TA_VCENTER);
	for (i = 0; i < 100; i++) {
  	LISTVIEW_AddRow(hItem, NULL);
  	sprintf(acBuffer, "Item %i", i);
  	LISTVIEW_SetItemText(hItem, 0, i, acBuffer);
	}
	LISTVIEW_SetAutoScrollV(hItem, 1);
	LISTVIEW_SetGridVis(hItem, 1);
	break;
  case WM_NOTIFY_PARENT:
	Id	= WM_GetId(pMsg->hWinSrc);
	NCode = pMsg->Data.v;
	switch(Id) {
	case ID_LISTVIEW_0: // Notifications sent by 'Listview'
  	switch(NCode) {
  	case WM_NOTIFICATION_CLICKED:
    	break;
  	case WM_NOTIFICATION_RELEASED:
    	break;
  	case WM_NOTIFICATION_SEL_CHANGED:
    	hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
    	Sel   = LISTVIEW_GetSel(hItem);
    	break;
  	}
  	break;
	}
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	Public code
*
**********************************************************************
*/
/*********************************************************************
*
*   	MainTask
*/
void MainTask(void) {
  GUI_Init();
  GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  while (1) {
	GUI_Delay(100);
  }
}

/*************************** End of file ****************************/


For now I can't say what is going wrong on your side. Please give it a try and check if the code above runs.

Regards
Sven

PeteBone

Beginner

Date of registration: Nov 8th 2017

Posts: 5

Location: Lincolnshire, United Kingdom

Occupation: Senior Hardware and Software Design Engineer

3

Wednesday, January 10th 2018, 3:06pm

Hi Sven,

Thank you for your fast response.

I added your code to my application as a new module and when called it does indeed work correctly, so that leaves me thinking I have probably done something stupid in the module that is coursing me a problem.

I have attached the code for the entire module, it would be much appreciated if you wouldn't mind taking a quick look to see if there is anything obviously wrong that might break the LISTVIEW_GetSel() function.

Thanks again.

Kind Regards,

Pete
PeteBone has attached the following file:
  • point.zip (2.86 kB - 45 times downloaded - Last download: Yesterday, 11:20pm)

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 561

4

Wednesday, January 10th 2018, 3:37pm

Hi,

I checked your application, but I couldn't find anything obvious. I modified it a little bit to be able to let in run in the simulation (deleting unknowns), but it was working. I always get the proper selection, no matter if I use the scrollbar.

Attached is my modified version.

Not sure if this will help, but did you tried to increase the emWin memory (most likely in GUIConf.c)?

Regards
Sven
SEGGER - Schoenen has attached the following file:
  • point_SEGGER.zip (1.84 kB - 35 times downloaded - Last download: Yesterday, 11:21pm)

PeteBone

Beginner

Date of registration: Nov 8th 2017

Posts: 5

Location: Lincolnshire, United Kingdom

Occupation: Senior Hardware and Software Design Engineer

5

Wednesday, January 10th 2018, 3:52pm

Hi Sven,

Thank you again for your fast response.

I monitor the free GUI memory all the time and it never gets below about 2MB so I don't think there is a memory allocation issue. It is however worrying that this is happening as it suggests stack corruption or something of that nature. I will have to look into the application as a whole now see if I can see what is going wrong.

Thank you for your time and confirming there are no known issues with the 'LISTVIEW' item at this time.

I will continue to look into the issue here.

Cheers,

Pete