Version 16 (modified by 6 years ago) ( diff ) | ,
---|
CForm
C++ class the provides form features. Most applications may use the helper macros FORM_INIT, FORM_ADD_INPUT, FORM_ADD_BUTTON, FORM_SHOW, FORM_RUN, FORM_HIDE, and EVENT to prevent having to work with CForm items directly.
Methods
EnableItem
CFormItem* EnableItem(const char* pszName, bool enable, bool show)
Parameters
- pszName = The button title or input prompt text
- enable = true to enable the item, false to disable
- show = true to update the display, false do not update the display
Return Value
The EnableItem function returns a pointer to the CFormItem found based on the provided name; NULL is returned if no item is found with a matching name.
Remarks
Allows conditionally showing items on a form.
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; vector<const char*> hideItems; vector<const char*> showItems; 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(); } if(mode == MODE_OFF) { hideItems.push_back(LANG(STR_LOCREM_COMMTYPE_PROMPT)); hideItems.push_back(LANG(STR_LOCREM_PORT_PROMPT)); hideItems.push_back(LANG(STR_LOCREM_IPADDR_PROMPT)); hideItems.push_back(LANG(STR_LOCREM_COMMPORT_PROMPT)); } else { showItems.push_back(LANG(STR_LOCREM_COMMTYPE_PROMPT)); if(type == SERIAL) { showItems.push_back(LANG(STR_LOCREM_COMMPORT_PROMPT)); hideItems.push_back(LANG(STR_LOCREM_IPADDR_PROMPT)); hideItems.push_back(LANG(STR_LOCREM_PORT_PROMPT)); } else { hideItems.push_back(LANG(STR_LOCREM_COMMPORT_PROMPT)); showItems.push_back(LANG(STR_LOCREM_PORT_PROMPT)); if(mode == MODE_REMOTE) { showItems.push_back(LANG(STR_LOCREM_IPADDR_PROMPT)); } else { hideItems.push_back(LANG(STR_LOCREM_IPADDR_PROMPT)); } } } // 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 size_t n; for(n = 0; n < hideItems.size(); n++) { pForm->EnableItem(hideItems[n], false, true); } for(n = 0; n < showItems.size(); n++) { pForm->EnableItem(showItems[n], true, true); } } 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; }
GetItem
CFormItem* GetItem(int i)
Parameters
- i = The item index to return
Return Value
The GetItem function returns a pointer to the CFormItem found based on the provided index; NULL is returned if the index is out of range.
Remarks
Example
FindName
CFormItem* EnableName(const char* pszName)
Parameters
- pszName = The button title or input prompt text
Return Value
The FindName function returns a pointer to the CFormItem found based on the provided name; NULL is returned if no item is found with a matching name.
Remarks
Example
!GetItemByIDVal
CFormItem* GetItemByIDVal(int nIDVal)
Parameters
- nIDVal = The item ID value of a form item in the form
Return Value
The !GetItemByIDVal function returns a pointer to the CFormItem found based on the provided ID value; NULL is returned if no item is found with a ID value.
Remarks
Example
GetItemIndex
int GetItemIndex(CFormItem* pItem)
Parameters
- pItem = pointer to a CFormButton or CFormInput item.
Return Value
The GetItemIndex function returns the item index of the pointer specified; -1 is returned if no item is found with a matching name.
Remarks
Example
GetItemCount
int GetItemCount(void)
Parameters
- function does not take any parameters.
Return Value
The GetItemCount function returns the number of items in the form.