| 3 | |
| 4 | == Methods == |
| 5 | |
| 6 | === EnableItem === |
| 7 | |
| 8 | CFormItem* EnableItem(const char* pszName, bool enable, bool show) |
| 9 | |
| 10 | ==== Remarks ==== |
| 11 | |
| 12 | Allows conditionally showing or items items on a form. |
| 13 | |
| 14 | ==== Example ==== |
| 15 | |
| 16 | {{{ |
| 17 | void UpdateLocalRemoteForm(CForm *pForm) |
| 18 | { |
| 19 | int mode = 0; |
| 20 | int type = 0; |
| 21 | vector<const char*> hideItems; |
| 22 | vector<const char*> showItems; |
| 23 | |
| 24 | CFormInput *pMode = (CFormInput*)pForm->FindName(LANG(STR_LOCREM_MODE_PROMPT)); |
| 25 | if(pMode != NULL) |
| 26 | { |
| 27 | mode = pMode->GetSelItem(); |
| 28 | } |
| 29 | CFormInput *pType = (CFormInput*)pForm->FindName(LANG(STR_LOCREM_COMMTYPE_PROMPT)); |
| 30 | if(pType != NULL) |
| 31 | { |
| 32 | type = pType->GetSelItem(); |
| 33 | } |
| 34 | |
| 35 | if(mode == MODE_OFF) |
| 36 | { |
| 37 | hideItems.push_back(LANG(STR_LOCREM_COMMTYPE_PROMPT)); |
| 38 | hideItems.push_back(LANG(STR_LOCREM_PORT_PROMPT)); |
| 39 | hideItems.push_back(LANG(STR_LOCREM_IPADDR_PROMPT)); |
| 40 | hideItems.push_back(LANG(STR_LOCREM_COMMPORT_PROMPT)); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | showItems.push_back(LANG(STR_LOCREM_COMMTYPE_PROMPT)); |
| 45 | if(type == SERIAL) |
| 46 | { |
| 47 | showItems.push_back(LANG(STR_LOCREM_COMMPORT_PROMPT)); |
| 48 | |
| 49 | hideItems.push_back(LANG(STR_LOCREM_IPADDR_PROMPT)); |
| 50 | hideItems.push_back(LANG(STR_LOCREM_PORT_PROMPT)); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | hideItems.push_back(LANG(STR_LOCREM_COMMPORT_PROMPT)); |
| 55 | |
| 56 | showItems.push_back(LANG(STR_LOCREM_PORT_PROMPT)); |
| 57 | if(mode == MODE_REMOTE) |
| 58 | { |
| 59 | showItems.push_back(LANG(STR_LOCREM_IPADDR_PROMPT)); |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | hideItems.push_back(LANG(STR_LOCREM_IPADDR_PROMPT)); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // Hide items first to allow for conditional items to be at the same place in the form |
| 69 | // Otherwise we might show a condition item and then blank it out |
| 70 | size_t n; |
| 71 | for(n = 0; n < hideItems.size(); n++) |
| 72 | { |
| 73 | pForm->EnableItem(hideItems[n], false, true); |
| 74 | } |
| 75 | for(n = 0; n < showItems.size(); n++) |
| 76 | { |
| 77 | pForm->EnableItem(showItems[n], true, true); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | int CLocalRemote::Config(void) |
| 82 | { |
| 83 | |
| 84 | Shutdown(); |
| 85 | |
| 86 | uint8 byMode = (uint8) GetMode(); |
| 87 | commType = (uint8) GetCommType(); |
| 88 | commPort = (uint8) GetCommPort(); |
| 89 | FORM_INIT(CfgLR, EventLocalRemoteShow, NULL, NULL, NULL, nFormFlgShowHelp); |
| 90 | FORM_ADD_INPUT(CfgLR, Mode, FONT_WIDTH * 0, FONT_HEIGHT * 2, LANG(STR_LOCREM_MODE_PROMPT), 10, 0, 2, EventModeChanged, &byMode, FORM_UINT8_SEL, LANG(STR_LOCREM_MODE_CHOICES), LANG(STR_LOCREM_MODE_HELP)); |
| 91 | FORM_ADD_INPUT(CfgLR, Comm, FONT_WIDTH * 0, FONT_HEIGHT * 4, LANG(STR_LOCREM_COMMTYPE_PROMPT), 10, 0, 1, EventModeChanged, &commType, FORM_UINT8_SEL | FORM_FLAG_DISABLE, LANG(STR_LOCREM_TYPE_CHOICES), LANG(STR_LOCREM_COMMTYPE_HELP)); |
| 92 | FORM_ADD_INPUT(CfgLR, PortSerialMobile, 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) ); |
| 93 | 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)); |
| 94 | 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)); |
| 95 | |
| 96 | FORM_SHOW(CfgLR); |
| 97 | |
| 98 | UpdateLocalRemoteForm(&formCfgLR); |
| 99 | |
| 100 | int result = FORM_RUN(CfgLR); |
| 101 | FORM_HIDE(CfgLR); |
| 102 | |
| 103 | if (result != FORM_RESULT_ESC) |
| 104 | { |
| 105 | SetMode((LocalRemoteMode) byMode); |
| 106 | SetComType((LocalRemoteComm) commType); |
| 107 | SetComPort((LocalRemotePort) commPort); |
| 108 | |
| 109 | appCfg.Write(); |
| 110 | } |
| 111 | |
| 112 | Startup(); |
| 113 | |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | EVENT(ModeChanged) |
| 118 | { |
| 119 | UpdateLocalRemoteForm(pForm); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | EVENT(LocalRemoteShow) |
| 124 | { |
| 125 | ClearLCD(); |
| 126 | SetCurColor(COLOR_ATTENTION); |
| 127 | DisplayText(0, 0, LANG(STR_LOCREM_TITLE)); |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | }}} |
| 133 | |