Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using value models to display date or time widgets

The listener callback function for the button calls c_simple_widget_app_DisplayDateTime(), which displays either the date or the time depending on which radio button was selected.

c_simple_widget_app_DisplayDateTime() has to determine which radio button the user selected. To do this, c_simple_widget_app_DisplayDateTime() must get the value model for the radio button, then get the data from the value model. For a radio button, the data in the value model is a boolean indicating the state of the radio button (selected or unselected).

  1. The first time c_simple_widget_app_DisplayDateTime() is called, it creates an XY container to display a date or time widget, as follows:
    if (AEE_SUCCESS != ISHELL_CreateInstance(pMe->piShell,
                AEECLSID_CXYContainer, (void **)&pMe->picTimeDateXYCon)) {
     		pMe->picTimeDateXYCon = NULL;
    }
    
    // get the widget interface for the radio XY container
    if (AEE_SUCCESS != IXYContainer_QueryInterface(pMe->picTimeDateXYCon,
                AEEIID_IWidget, (void**)&pMe->piwTimeDateXYCon)) {
    	 	pMe->piwTimeDateXYCon = NULL;
    }
    
    // set the extent for the TimeDate XY container
    we.width = pMe->rootcontainerwidth;
    we.height = pMe->rootcontainerheight / 2;
    IWidget_SetExtent(pMe->piwTimeDateXYCon, &we);
  2. It then determines which radio button was selected, as follows:
    1. Get the value model for radio button 1, then get the boolean data from the model:
      if (AEE_SUCCESS != IWidget_GetModel(pMe->piwRadio1,
                  AEEIID_IValueModel, (IModel **)&piRadio1ValueModel)) {
          DBGPRINTF("get radio1 value model failed");
          return FALSE;
      }
      
      radio1_selected = IValueModel_GetBool(piRadio1ValueModel);
    2. If radio button 1 was selected, call c_simple_widget_app_BlankScreen() and c_simple_widget_app_DisplayDate():
      if (!c_simple_widget_app_BlankScreen(pMe)) {
              return FALSE;
          }
          if (!c_simple_widget_app_DisplayDate(pMe)) {
               DBGPRINTF("display date failed");
               return FALSE;
          }

      c_simple_widget_app_BlankScreen() removes the XY container from the root container, which means the title, radio buttons, and button in the XY container are no longer displayed

      if (AEE_SUCCESS != IRootContainer_Remove(pMe->picRoot, pMe->piwXYCon)) {
          return FALSE;
      }

      c_simple_widget_app_DisplayDate() displays the date, as follows:

      1. if the time widget was displayed last, remove it from the time and date XY container (to avoid displaying the date on top of the time):
        if (pMe->time_display) {
            if (AEE_SUCCESS != IXYContainer_Remove(pMe->picTimeDateXYCon,
                        pMe->piwJulianTime)) {
                return FALSE;
            }
            pMe->time_display = FALSE;
        }
      2. If the Julian date widget has not been created yet, call ISHELL_CreateInstance() to create it:
        if (AEE_SUCCESS != ISHELL_CreateInstance(pMe->piShell,
                    AEECLSID_CJulianDateWidget, (void **)piwJulianDate)) {
         		return FALSE;
        }

        If the Julian date widget exists, and was not the most recently displayed widget, it is inserted into the date and time XY container again. Step 3 is skipped.

      3. Set the extent of the date widget and set the border width to zero (no border):
        // set the extent of the date widget
        we.height = 20;
        we.width = pMe->rootcontainerwidth - 40;
        IWidget_SetExtent(piwJulianDate, &we);
        
        (void) IWidget_SetBorderWidth(piwJulianDate, 0);
      4. Set the position of the date widget and make it visible, as follows:
        dwpos.x = 0;
        dwpos.y = 0;
        dwpos.bVisible = TRUE;
      5. Call IXYContainer_Insert() to insert the date widget into the date and time XY container:
        if (AEE_SUCCESS != IXYContainer_Insert(pMe->picTimeDateXYCon,
                    piwJulianDate, WIDGET_ZNORMAL, &dwpos)) {
         		return FALSE;
        }
    3. If radio button 1 was not selected, get the value model and model data for radio button 2 and determine whether the time should be displayed:
          // get the model and state for radio button 2
          if (AEE_SUCCESS != IWidget_GetModel(pMe->piwRadio2, AEEIID_IValueModel,
                      (IModel **)&piRadio2ValueModel)) {
              piRadio2ValueModel = NULL;
              return FALSE;
          }
          radio2_selected = IValueModel_GetBool(piRadio2ValueModel);
      
          if (radio2_selected) {
              if (!c_simple_widget_app_BlankScreen(pMe)) {;
                  return FALSE;
              }
              if (!c_simple_widget_app_DisplayTime(pMe)) {
                  DBGPRINTF("display time failed");
                  return FALSE;
              }
          }
      }

      c_simple_widget_app_DisplayTime() creates a Julian time widget, which is similar to creating a Julian date widget as in c_simple_widget_app_DisplayDate().

  3. c_simple_widget_app_DisplayDateTime() then sets the position of the date and time XY container and inserts it into the root container:
        dwpos.x = 20;
        dwpos.y = 40;
        dwpos.bVisible = TRUE;
    
        // insert the XY container in the root container
        if (AEE_SUCCESS != IRootContainer_Insert(pMe->picRoot,
                    pMe->piwTimeDateXYCon, WIDGET_ZNORMAL, &dwpos)) {
            return FALSE;
        }
    
        
  4. A radio button has a reference to its value model, so the pointers to the value models are released, as follows:
    if (NULL != piRadio1ValueModel) {
        IValueModel_Release(piRadio1ValueModel);
    }
    if (NULL != piRadio2ValueModel) {
        IValueModel_Release(piRadio2ValueModel);
    }