Changes between Version 23 and Version 24 of Docs/Prog/Manual/ApplicationLibraries/lib825ev/Form/CForm


Ignore:
Timestamp:
05/17/19 15:11:03 (5 years ago)
Author:
Don Wilson
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Docs/Prog/Manual/ApplicationLibraries/lib825ev/Form/CForm

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