Tuesday, May 22nd 2018, 11:45pm UTC+2

You are not logged in.

  • Login
  • Register

gvi70000

Beginner

Date of registration: May 15th 2017

Posts: 11

1

Wednesday, May 2nd 2018, 3:06pm

Window <-> child dialog data exchange

Hi,

I have a window with several Edit boxes, when i click the edit i open a dialog where i change a global array value.
The window and the dialog are defined in 2 different c files as i intend to use this dialog in several windows.
The dialog is created as follows:

Source code

1
2
3
4
#define ID_VALUE_CHANGE	1000#define ID_SMALL_CHANGE	1001#define ID_BIG_CHANGE		1002#define ID_BUTTON_OK		1003#define ID_BUTTON_KO		1004
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {  { FRAMEWIN_CreateIndirect,	"Value Editor", ID_VALUE_CHANGE, 127, 68, 225, 135, 0, 0x0, 0 },  { SPINBOX_CreateIndirect,		NULL, ID_SMALL_CHANGE, 3, 3, 150, 70, 0, 0x0, 0 },  { SLIDER_CreateIndirect,		NULL, ID_BIG_CHANGE, 3, 85, 150, 24, 0, 0x0, 0 },  { BUTTON_CreateIndirect,		NULL, ID_BUTTON_OK, 165, 3, 50, 50, 0, 0x0, 0 },  { BUTTON_CreateIndirect,		NULL, ID_BUTTON_KO, 165, 63, 50, 50, 0, 0x0, 0 },};
static void _cbDialog(WM_MESSAGE * pMsg) {  int NCode;  int Id;//make these as static for ImageControl.c to avoid repeated calls of WM_GetDialogItem	BUTTON_Handle hButton;	SPINBOX_Handle hSpin;	SLIDER_Handle hSlide;	  switch (pMsg->MsgId) {	case WM_INIT_DIALOG:		hButton = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_OK);		BUTTON_SetBitmapEx(hButton, BUTTON_BI_UNPRESSED, &bmLoad, 13, 13);		hButton = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_KO);		BUTTON_SetBitmapEx(hButton, BUTTON_BI_UNPRESSED, &bmOff, 13, 13);		hSpin = WM_GetDialogItem(pMsg->hWin, ID_SMALL_CHANGE);		SPINBOX_SetFont(hSpin, GUI_FONT_32B_1);		SPINBOX_SetRange(hSpin, 0, maxProfile[myItemIndex]);		SPINBOX_SetValue(hSpin, arrProfile[myItemIndex]);			hSlide = WM_GetDialogItem(pMsg->hWin, ID_BIG_CHANGE);		SLIDER_SetRange(hSlide, 0, maxProfile[myItemIndex]);		SLIDER_SetValue(hSlide, arrProfile[myItemIndex]);    break;  case WM_NOTIFY_PARENT:    Id    = WM_GetId(pMsg->hWinSrc);    NCode = pMsg->Data.v;    switch(Id) {    case ID_BIG_CHANGE: // Notifications sent by 'Slider'	case ID_SMALL_CHANGE: // Notifications sent by 'Spinbox'		if(NCode == WM_NOTIFICATION_VALUE_CHANGED) {			hSpin = WM_GetDialogItem(pMsg->hWin, ID_SMALL_CHANGE);			hSlide = WM_GetDialogItem(pMsg->hWin, ID_BIG_CHANGE);			if(Id == ID_BIG_CHANGE) {				SPINBOX_SetValue(hSpin, SLIDER_GetValue(hSlide));			} else {				SLIDER_SetValue(hSlide, SPINBOX_GetValue(hSpin));			}		}    break;    case ID_BUTTON_OK: // Notifications sent by 'Button'		if(NCode == WM_NOTIFICATION_RELEASED) {			WM_GetClientWindow();			hSpin = WM_GetDialogItem(pMsg->hWin, ID_SMALL_CHANGE);			arrProfile[myItemIndex] = SPINBOX_GetValue(hSpin);			WM_DeleteWindow(pMsg->hWin);		}    break;    case ID_BUTTON_KO: // Notifications sent by 'Button'			if(NCode == WM_NOTIFICATION_RELEASED)				WM_DeleteWindow(pMsg->hWin);      break;    }    break;  default:    WM_DefaultProc(pMsg);    break;  }}
WM_HWIN ShowEditValue(WM_HWIN myItem, U8 myIdx) {	parentItem = myItem;	myItemIndex = myIdx;	//return the handle of the dialog	return GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, myItem, 0, 0);};



the parent window

Source code

1
2
3
4
5
static WM_HWIN _hManual;
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {	{ WINDOW_CreateIndirect,	NULL, ID_ManualMenu, -1, 0, 480, 272, 0, 0x0, 0 },	{ EDIT_CreateIndirect, NULL, ID_Sequence_Delay, 102, 50, 90, BtnSize, 0, 0x0, 0 },	{ BUTTON_CreateIndirect,	"Shutter 2", ID_Shutter2, 270, 150, 140, BtnSize, 0, 0x0, 0 },	{ BUTTON_CreateIndirect,	NULL, ID_ScreenOff, 10, 230, BtnSize, BtnSize, 0, 0x0, 0 },};
static void _cbDialog(WM_MESSAGE * pMsg) {	WM_HWIN hItem;	WM_HWIN hEditWin;	U8 crtItem;	arrProfile[Sequence_Delay] = 999;	int     NCode;	int     Id;	switch (pMsg->MsgId) {	case WM_INIT_DIALOG:		hItem = WM_GetDialogItem(pMsg->hWin, ID_Sequence_Delay);		EDIT_SetFont(hItem, GUI_FONT_32B_1);	  EDIT_SetDecMode(hItem, arrProfile[Sequence_Delay], 0, maxProfile[Sequence_Delay], 0, GUI_EDIT_NORMAL);				hItem = WM_GetDialogItem(pMsg->hWin, ID_Exit);		BUTTON_SetBitmapEx(hItem, BUTTON_BI_UNPRESSED, &bmOff, 4, 4);				hItem = WM_GetDialogItem(pMsg->hWin, ID_ScreenOff);		BUTTON_SetBitmapEx(hItem, BUTTON_BI_UNPRESSED, &bmBulbOff, 4, 4);		break;	case WM_NOTIFY_PARENT:		Id    = WM_GetId(pMsg->hWinSrc);		NCode = pMsg->Data.v;		//hItem = WM_GetDialogItem(pMsg->hWin, Id);		if(NCode == WM_NOTIFICATION_RELEASED) {			switch(Id) {			case ID_Sequence_Delay: // Notifications sent by 'Sequence_Delay'				//create the dialog to change the EDIT Box value				ShowEditValue(_hManual, Sequence_Delay);				break;					case ID_Exit: // Notifications sent by 'Exit'				WM_DeleteWindow(_hManual);				MainTask();				break;			case ID_ScreenOff: // Notifications sent by 'Screen'				toogleBackLight();				break;			}		}		break;	case WM_PAINT:		//draw background		GUI_DrawBitmap(&bmBackGround, 0, 0);		// show free/used memory		ShowMem();		break;	case WM_NOTIFICATION_CHILD_DELETED:		//update here the EDIT box that was chaged in WM_NOTIFICATION_VALUE_CHANGED of slider and spin		EDIT_SetDecMode(hItem, arrProfile[Sequence_Delay], 0, maxProfile[Sequence_Delay], 0, GUI_EDIT_NORMAL);	break;	default:		WM_DefaultProc(pMsg);		break;	}}
static void _InitManual(void) {	_hManual = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);}
void ExecManual(void) {	_InitManual();	WM_SetFocus(_hManual);}
NOTE: I remove irrelevant code

I have the following questions: related to the above code

1. In the dialog creation if i use myItem then the dialog is not created
GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, myItem, 0, 0);


if i use GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0); then is created but it will be the child of the desktop, correct?
How shall i proceed in order to make the dialog child of the ID_ManualMenu window?


2. When i delete the dialog i need to notify the ID_ManualMenu window that the global array is changed and it needs to update the value of the Edit box
Is the WM_NOTIFICATION_CHILD_DELETED the correct way to do it? I see may examples using WM_SendMessageNoPara but i can only make this work inside the window, not between a window and a dialog


3. Is there a place where i can find the range of values used for default IDs? I try to define my own ID's but i am afraid that i will overlap some predefined ones



Thank you

gvi70000

Beginner

Date of registration: May 15th 2017

Posts: 11

2

Wednesday, May 2nd 2018, 5:55pm

All point solved
1. I was not giving the correct handle
2.In the Main window i use

case WM_USER:
hItem = WM_GetDialogItem(pMsg->hWin, ID_Sequence_Delay);
EDIT_SetDecMode(hItem, arrProfile[Sequence_Delay], 0, maxProfile[Sequence_Delay], 0, GUI_EDIT_NORMAL);
break;
and in the dialog

arrProfile[myItemIndex] = SPINBOX_GetValue(hSpin);
WM_SendMessageNoPara(parentItem, WM_USER);
WM_DeleteWindow(pMsg->hWin);

3. I found the values in GUI.h and WM.H
:thumbsup:

This post has been edited 1 times, last edit by "gvi70000" (May 2nd 2018, 6:24pm)