Exemplo n.º 1
0
static DataField *
LoadDataField(const XMLNode &node, const CallBackTableEntry *LookUpTable)
{
  TCHAR data_type[32];
  TCHAR display_format[32];
  TCHAR edit_format[32];
  double step;
  bool fine;

  _tcscpy(data_type,
          StringToStringDflt(node.getAttribute(_T("DataType")), _T("")));
  _tcscpy(display_format,
          StringToStringDflt(node. getAttribute(_T("DisplayFormat")), _T("")));
  _tcscpy(edit_format,
          StringToStringDflt(node.getAttribute(_T("EditFormat")), _T("")));

  fixed min = fixed(StringToFloatDflt(node.getAttribute(_T("Min")), INT_MIN));
  fixed max = fixed(StringToFloatDflt(node.getAttribute(_T("Max")), INT_MAX));
  step = StringToFloatDflt(node.getAttribute(_T("Step")), 1);
  fine = StringToIntDflt(node.getAttribute(_T("Fine")), false);

  DataField::DataAccessCallback callback = (DataField::DataAccessCallback)
    GetCallBack(LookUpTable, node, _T("OnDataAccess"));

  if (_tcsicmp(data_type, _T("enum")) == 0)
    return new DataFieldEnum(callback);

  if (_tcsicmp(data_type, _T("filereader")) == 0) {
    DataFieldFileReader *df = new DataFieldFileReader(callback);

    if (StringToIntDflt(node.getAttribute(_T("Nullable")), true))
      df->AddNull();

    return df;
  }

  if (_tcsicmp(data_type, _T("boolean")) == 0)
    return new DataFieldBoolean(false, _("On"), _("Off"), callback);

  if (_tcsicmp(data_type, _T("double")) == 0)
    return new DataFieldFloat(edit_format, display_format, min, max,
                              fixed_zero, fixed(step), fine, callback);

  if (_tcsicmp(data_type, _T("time")) == 0) {
    DataFieldTime *df = new DataFieldTime((int)min, (int)max, 0,
                                          (unsigned)step, callback);
    unsigned max_token = StringToIntDflt(node.getAttribute(_T("MaxTokens")), 2);
    df->SetMaxTokenNumber(max_token);
    return df;
  }

  if (_tcsicmp(data_type, _T("integer")) == 0)
    return new DataFieldInteger(edit_format, display_format, (int)min, (int)max,
                                0, (int)step, callback);

  if (_tcsicmp(data_type, _T("string")) == 0)
    return new DataFieldString(_T(""), callback);

  return NULL;
}
Exemplo n.º 2
0
static DataField *
LoadDataField(const XMLNode &node, CallBackTableEntry *LookUpTable,
              const DialogStyle eDialogStyle)
{
  TCHAR DataType[32];
  TCHAR DisplayFmt[32];
  TCHAR EditFormat[32];
  double Step;
  int Fine;

  _tcscpy(DataType,
          StringToStringDflt(node.getAttribute(_T("DataType")),
                             _T("")));
  _tcscpy(DisplayFmt,
          StringToStringDflt(node. getAttribute(_T("DisplayFormat")),
                             _T("")));
  _tcscpy(EditFormat,
          StringToStringDflt(node.getAttribute(_T("EditFormat")),
                             _T("")));

  fixed Min = fixed(StringToFloatDflt(node.getAttribute(_T("Min")), INT_MIN));
  fixed Max = fixed(StringToFloatDflt(node.getAttribute(_T("Max")), INT_MAX));
  Step = StringToFloatDflt(node.getAttribute(_T("Step")), 1);
  Fine = StringToIntDflt(node.getAttribute(_T("Fine")), 0);

  DataField::DataAccessCallback_t callback = (DataField::DataAccessCallback_t)
    CallBackLookup(LookUpTable,
                   StringToStringDflt(node.getAttribute(_T("OnDataAccess")),
                                      NULL));

  if (_tcsicmp(DataType, _T("enum")) == 0)
    return new DataFieldEnum(callback);

  if (_tcsicmp(DataType, _T("filereader")) == 0)
    return new DataFieldFileReader(callback);

  if (_tcsicmp(DataType, _T("boolean")) == 0)
    return new DataFieldBoolean(false, _("ON"), _("OFF"), callback);

  if (_tcsicmp(DataType, _T("double")) == 0)
    return new DataFieldFloat(EditFormat, DisplayFmt, Min, Max,
                              fixed_zero, fixed(Step), fixed(Fine),
                              callback);

  if (_tcsicmp(DataType, _T("integer")) == 0)
    return new DataFieldInteger(EditFormat, DisplayFmt, Min, Max,
                                0, (int)Step, callback);

  if (_tcsicmp(DataType, _T("string")) == 0)
    return new DataFieldString(_T(""), callback);

  return NULL;
}