📄 httpform.cxx
字号:
: PHTTPField(nam, NULL, help), units(unit != NULL ? unit : "")
{
low = lo;
high = hig;
value = initialValue = initVal;
}
PHTTPIntegerField::PHTTPIntegerField(const char * nam,
const char * titl,
int lo, int hig,
int initVal,
const char * unit,
const char * help)
: PHTTPField(nam, titl, help), units(unit != NULL ? unit : "")
{
low = lo;
high = hig;
value = initialValue = initVal;
}
PHTTPField * PHTTPIntegerField::NewField() const
{
return new PHTTPIntegerField(baseName, title, low, high, initialValue, units, help);
}
void PHTTPIntegerField::GetHTMLTag(PHTML & html) const
{
html << PHTML::InputRange(fullName, low, high, value) << " " << units;
}
void PHTTPIntegerField::SetValue(const PString & newVal)
{
value = newVal.AsInteger();
}
PString PHTTPIntegerField::GetValue(BOOL dflt) const
{
return PString(PString::Signed, dflt ? initialValue : value);
}
void PHTTPIntegerField::LoadFromConfig(PConfig & cfg)
{
PString section, key;
switch (SplitConfigKey(fullName, section, key)) {
case 1 :
value = cfg.GetInteger(key, initialValue);
break;
case 2 :
value = cfg.GetInteger(section, key, initialValue);
}
}
void PHTTPIntegerField::SaveToConfig(PConfig & cfg) const
{
PString section, key;
switch (SplitConfigKey(fullName, section, key)) {
case 1 :
cfg.SetInteger(key, value);
break;
case 2 :
cfg.SetInteger(section, key, value);
}
}
BOOL PHTTPIntegerField::Validated(const PString & newVal, PStringStream & msg) const
{
int val = newVal.AsInteger();
if (val >= low && val <= high)
return TRUE;
msg << "The field \"" << GetName() << "\" should be between "
<< low << " and " << high << ".<BR>";
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////
// PHTTPBooleanField
PHTTPBooleanField::PHTTPBooleanField(const char * name,
BOOL initVal,
const char * help)
: PHTTPField(name, NULL, help)
{
value = initialValue = initVal;
}
PHTTPBooleanField::PHTTPBooleanField(const char * name,
const char * title,
BOOL initVal,
const char * help)
: PHTTPField(name, title, help)
{
value = initialValue = initVal;
}
PHTTPField * PHTTPBooleanField::NewField() const
{
return new PHTTPBooleanField(baseName, title, initialValue, help);
}
void PHTTPBooleanField::GetHTMLTag(PHTML & html) const
{
html << PHTML::HiddenField(fullName, "FALSE")
<< PHTML::CheckBox(fullName, value ? PHTML::Checked : PHTML::UnChecked);
}
static void SpliceChecked(PString & text, BOOL value)
{
PINDEX pos = text.Find("checked");
if (value) {
if (pos == P_MAX_INDEX)
text.Splice(" checked", 6, 0);
}
else {
if (pos != P_MAX_INDEX) {
PINDEX len = 7;
if (text[pos-1] == ' ') {
pos--;
len++;
}
text.Delete(pos, len);
}
}
}
PString PHTTPBooleanField::GetHTMLInput(const PString & input) const
{
static PRegularExpression checkboxRegEx("type[ \t\r\n]*=[ \t\r\n]*\"?checkbox\"?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
if (input.FindRegEx(checkboxRegEx) != P_MAX_INDEX) {
PCaselessString text;
PINDEX before, after;
if (FindInputValue(input, before, after))
text = input(0, before) + "TRUE" + input.Mid(after);
else
text = "<input value=\"TRUE\"" + input.Mid(6);
SpliceChecked(text, value);
return "<input type=hidden name=\"" + fullName + "\">" + text;
}
static PRegularExpression radioRegEx("type[ \t\r\n]*=[ \t\r\n]*\"?radio\"?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
if (input.FindRegEx(radioRegEx) != P_MAX_INDEX) {
PINDEX before, after;
if (FindInputValue(input, before, after)) {
PCaselessString text = input;
PString val = input(before+1, after-1);
SpliceChecked(text, (value && (val *= "TRUE")) || (!value && (val *= "FALSE")));
return text;
}
return input;
}
return PHTTPField::GetHTMLInput(input);
}
void PHTTPBooleanField::SetValue(const PString & val)
{
value = toupper(val[0]) == 'T' || toupper(val[0]) == 'y' ||
val.AsInteger() != 0 || val.Find("TRUE") != P_MAX_INDEX;
}
PString PHTTPBooleanField::GetValue(BOOL dflt) const
{
return ((dflt ? initialValue : value) ? "True" : "False");
}
void PHTTPBooleanField::LoadFromConfig(PConfig & cfg)
{
PString section, key;
switch (SplitConfigKey(fullName, section, key)) {
case 1 :
value = cfg.GetBoolean(key, initialValue);
break;
case 2 :
value = cfg.GetBoolean(section, key, initialValue);
}
}
void PHTTPBooleanField::SaveToConfig(PConfig & cfg) const
{
PString section, key;
switch (SplitConfigKey(fullName, section, key)) {
case 1 :
cfg.SetBoolean(key, value);
break;
case 2 :
cfg.SetBoolean(section, key, value);
}
}
//////////////////////////////////////////////////////////////////////////////
// PHTTPRadioField
PHTTPRadioField::PHTTPRadioField(const char * name,
const PStringArray & valueArray,
PINDEX initVal,
const char * help)
: PHTTPField(name, NULL, help),
values(valueArray),
titles(valueArray),
value(valueArray[initVal]),
initialValue(value)
{
}
PHTTPRadioField::PHTTPRadioField(const char * name,
const PStringArray & valueArray,
const PStringArray & titleArray,
PINDEX initVal,
const char * help)
: PHTTPField(name, NULL, help),
values(valueArray),
titles(titleArray),
value(valueArray[initVal]),
initialValue(value)
{
}
PHTTPRadioField::PHTTPRadioField(const char * name,
PINDEX count,
const char * const * valueStrings,
PINDEX initVal,
const char * help)
: PHTTPField(name, NULL, help),
values(count, valueStrings),
titles(count, valueStrings),
value(valueStrings[initVal]),
initialValue(value)
{
}
PHTTPRadioField::PHTTPRadioField(const char * name,
PINDEX count,
const char * const * valueStrings,
const char * const * titleStrings,
PINDEX initVal,
const char * help)
: PHTTPField(name, NULL, help),
values(count, valueStrings),
titles(count, titleStrings),
value(valueStrings[initVal]),
initialValue(value)
{
}
PHTTPRadioField::PHTTPRadioField(const char * name,
const char * groupTitle,
const PStringArray & valueArray,
PINDEX initVal,
const char * help)
: PHTTPField(name, groupTitle, help),
values(valueArray),
titles(valueArray),
value(valueArray[initVal]),
initialValue(value)
{
}
PHTTPRadioField::PHTTPRadioField(const char * name,
const char * groupTitle,
const PStringArray & valueArray,
const PStringArray & titleArray,
PINDEX initVal,
const char * help)
: PHTTPField(name, groupTitle, help),
values(valueArray),
titles(titleArray),
value(valueArray[initVal]),
initialValue(value)
{
}
PHTTPRadioField::PHTTPRadioField(const char * name,
const char * groupTitle,
PINDEX count,
const char * const * valueStrings,
PINDEX initVal,
const char * help)
: PHTTPField(name, groupTitle, help),
values(count, valueStrings),
titles(count, valueStrings),
value(valueStrings[initVal]),
initialValue(value)
{
}
PHTTPRadioField::PHTTPRadioField(const char * name,
const char * groupTitle,
PINDEX count,
const char * const * valueStrings,
const char * const * titleStrings,
PINDEX initVal,
const char * help)
: PHTTPField(name, groupTitle, help),
values(count, valueStrings),
titles(count, titleStrings),
value(valueStrings[initVal]),
initialValue(value)
{
}
PHTTPField * PHTTPRadioField::NewField() const
{
return new PHTTPRadioField(*this);
}
void PHTTPRadioField::GetHTMLTag(PHTML & html) const
{
for (PINDEX i = 0; i < values.GetSize(); i++)
html << PHTML::RadioButton(fullName, values[i],
values[i] == value ? PHTML::Checked : PHTML::UnChecked)
<< titles[i]
<< PHTML::BreakLine();
}
PString PHTTPRadioField::GetHTMLInput(const PString & input) const
{
PString inval;
PINDEX before, after;
if (FindInputValue(input, before, after))
inval = input(before+1, after-1);
else
inval = baseName;
if (inval != value)
return input;
return "<input checked" + input.Mid(6);
}
PString PHTTPRadioField::GetValue(BOOL dflt) const
{
if (dflt)
return initialValue;
else
return value;
}
void PHTTPRadioField::SetValue(const PString & newVal)
{
value = newVal;
}
//////////////////////////////////////////////////////////////////////////////
// PHTTPSelectField
PHTTPSelectField::PHTTPSelectField(const char * name,
const PStringArray & valueArray,
PINDEX initVal,
const char * help)
: PHTTPField(name, NULL, help),
values(valueArray)
{
initialValue = initVal;
if (initVal < values.GetSize())
value = values[initVal];
}
PHTTPSelectField::PHTTPSelectField(const char * name,
PINDEX count,
const char * const * valueStrings,
PINDEX initVal,
const char * help)
: PHTTPField(name, NULL, help),
values(count, valueStrings)
{
initialValue = initVal;
if (initVal < count)
value = values[initVal];
}
PHTTPSelectField::PHTTPSelectField(const char * name,
const char * title,
const PStringArray & valueArray,
PINDEX initVal,
const char * help)
: PHTTPField(name, title, help),
values(valueArray)
{
initialValue = initVal;
if (initVal < values.GetSize())
value = values[initVal];
}
PHTTPSelectField::PHTTPSelectField(const char * name,
const char * title,
PINDEX count,
const char * const * valueStrings,
PINDEX initVal,
const char * help)
: PHTTPField(name, title, help),
values(count, valueStrings)
{
initialValue = initVal;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -