wiki:Docs/Prog/Manual/ApplicationLibraries/lib825ev/Form/ShowItem

ShowItem

CFormItem* CForm::ShowItem(const char* name, bool updateDisplay = true)

CFormItem* CForm::ShowItem(int nIDVal, bool updateDisplay = true)

Parameters

  • name = The button title or input prompt text
  • nIDVal = The ID value of a button or input prompt
  • updateDisplay = (optional parameter, true if not included) true to update the display, false do not update the display

Return Value

The ShowItem function returns a pointer to the CFormItem found based on the provided name value; NULL is returned if no item is found with a matching name value.

Remarks

ShowItem is a wrapper for EnableItem with the enable parameter set to true to simplify code. It is equivalent to EnableItem(name, true, updateDisplay) or EnableItem(nIDVal, true, updateDisplay)

Example

The conditional items are initialized with the FORM_FLAG_DISABLE flag to start out hidden. After the FORM_SHOW is called the UpdateLocalRemoteForm function is called to show these items based on the data. When the mode or type selection is changed the event ModeOrTypeChg is called and the event calls UpdateLocalRemoteForm to update the conditional items appropriately.

void UpdateLocalRemoteForm(CForm *pForm)
{
	int mode = 0;
	int type = 0;

	CFormInput *pMode = (CFormInput*)pForm->FindName(LANG(STR_LOCREM_MODE_PROMPT));
	if(pMode != NULL)
	{
		mode = pMode->GetSelItem();
	}
	CFormInput *pType = (CFormInput*)pForm->FindName(LANG(STR_LOCREM_COMMTYPE_PROMPT));
	if(pType != NULL)
	{
		type = pType->GetSelItem();
	}

	// Must do hide items first to allow for conditional items to be at the same place
	// in the form otherwise we might show a condition item and then blank it out

	if(mode == MODE_OFF)
	{
		pForm->HideItem(LANG(STR_LOCREM_COMMTYPE_PROMPT));
		pForm->HideItem(LANG(STR_LOCREM_PORT_PROMPT));
		pForm->HideItem(LANG(STR_LOCREM_IPADDR_PROMPT));
		pForm->HideItem(LANG(STR_LOCREM_COMMPORT_PROMPT));
	}
	else
	{
		if(type == SERIAL)
		{
			pForm->HideItem(LANG(STR_LOCREM_IPADDR_PROMPT));
			pForm->HideItem(LANG(STR_LOCREM_PORT_PROMPT));

			pForm->ShowItem(LANG(STR_LOCREM_COMMPORT_PROMPT));
		}
		else
		{
			pForm->HideItem(LANG(STR_LOCREM_COMMPORT_PROMPT));

			if(mode == MODE_REMOTE || mode == MODE_REMOTE_SMA)
			{
				pForm->ShowItem(LANG(STR_LOCREM_IPADDR_PROMPT));
			}
			else
			{
				pForm->HideItem(LANG(STR_LOCREM_IPADDR_PROMPT));
			}
			pForm->ShowItem(LANG(STR_LOCREM_PORT_PROMPT));
		}
		pForm->ShowItem(LANG(STR_LOCREM_COMMTYPE_PROMPT));
	}
}

int CLocalRemote::Config(void)
{

	Shutdown();

	uint8 byMode = (uint8) GetMode();
	commType = (uint8) GetCommType();
	commPort = (uint8) GetCommPort();
	FORM_INIT(CfgLR, EventLocalRemoteShow, NULL, NULL, NULL, nFormFlgShowHelp);

	FORM_ADD_INPUT(CfgLR, Mode, FONT_WIDTH * 0, FONT_HEIGHT * 2, LANG(STR_LOCREM_MODE_PROMPT),     10, 0,     2, EventModeOrTypeChg, &byMode,    FORM_UINT8_SEL,                      LANG(STR_LOCREM_MODE_CHOICES),    LANG(STR_LOCREM_MODE_HELP));
	FORM_ADD_INPUT(CfgLR, Type, FONT_WIDTH * 0, FONT_HEIGHT * 4, LANG(STR_LOCREM_COMMTYPE_PROMPT), 10, 0,     1, EventModeOrTypeChg, &commType,  FORM_UINT8_SEL | FORM_FLAG_DISABLE,  LANG(STR_LOCREM_TYPE_CHOICES),    LANG(STR_LOCREM_COMMTYPE_HELP));
	FORM_ADD_INPUT(CfgLR, ComP, FONT_WIDTH * 0, FONT_HEIGHT * 6, LANG(STR_LOCREM_COMMPORT_PROMPT), 10, 0,     1, NULL,               &commPort,  FORM_UINT8_SEL | FORM_FLAG_DISABLE,  LANG(STR_LOCREM_COMPORT_CHOICES), LANG(STR_LOCREM_COMPORT_HELP) );
	FORM_ADD_INPUT(CfgLR, Port, FONT_WIDTH * 0, FONT_HEIGHT * 6, LANG(STR_LOCREM_PORT_PROMPT),      6, 0, 65535, NULL,               &GetPort(), FORM_UINT32 | FORM_FLAG_DISABLE,     NULL,                             LANG(STR_LOCREM_PORT_HELP));
	FORM_ADD_INPUT(CfgLR, IP,   FONT_WIDTH * 0, FONT_HEIGHT * 8, LANG(STR_LOCREM_IPADDR_PROMPT) ,  18, 0,     0, NULL,               GetIP(),    FORM_STR | FORM_FLAG_DISABLE,        NULL,                             LANG(STR_LOCREM_IP_HELP));

	FORM_SHOW(CfgLR);

	UpdateLocalRemoteForm(&formCfgLR);

	int result = FORM_RUN(CfgLR);
	FORM_HIDE(CfgLR);

	if (result != FORM_RESULT_ESC)
	{
		SetMode((LocalRemoteMode) byMode);
		SetComType((LocalRemoteComm) commType);
		SetComPort((LocalRemotePort) commPort);

		appCfg.Write();
	}

	Startup();

	return result;
}

EVENT(ModeOrTypeChg)
{
	UpdateLocalRemoteForm(pForm);
	return 0;
}

EVENT(LocalRemoteShow)
{
	ClearLCD();
	SetCurColor(COLOR_ATTENTION);
	DisplayText(0, 0, LANG(STR_LOCREM_TITLE));

	return 0;
}

See Also

Last modified 4 years ago Last modified on 10/02/20 07:59:33
Note: See TracWiki for help on using the wiki.