Added IsSupportingRTP function to simplify detecting when STUN supports RTP
[pwlib.git] / src / ptclib / html.cxx
blob4b55bd2c5c5d626277d955cae59b7daa85473b98
1 /*
2 * html.cxx
4 * HTML classes.
6 * Portable Windows Library
8 * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
26 * $Log$
27 * Revision 1.21 2004/04/12 05:42:25 csoutheren
28 * Fixed problem with radio buttons
30 * Revision 1.20 2004/04/03 06:54:24 rjongbloed
31 * Many and various changes to support new Visual C++ 2003
33 * Revision 1.19 2002/11/06 22:47:24 robertj
34 * Fixed header comment (copyright etc)
36 * Revision 1.18 2001/02/13 04:39:08 robertj
37 * Fixed problem with operator= in container classes. Some containers will
38 * break unless the copy is virtual (eg PStringStream's buffer pointers) so
39 * needed to add a new AssignContents() function to all containers.
41 * Revision 1.17 1998/11/30 04:51:51 robertj
42 * New directory structure
44 * Revision 1.16 1998/09/23 06:22:04 robertj
45 * Added open source copyright license.
47 * Revision 1.15 1998/01/26 02:49:15 robertj
48 * GNU support.
50 * Revision 1.14 1997/06/16 13:18:03 robertj
51 * Set Is() function to be const as it should have been.
53 * Revision 1.13 1996/08/19 13:40:31 robertj
54 * Fixed incorrect formatting of HTML tags (cosmetic only).
56 * Revision 1.12 1996/06/28 13:08:55 robertj
57 * Changed PHTML class so can create html fragments.
58 * Fixed nesting problem in tables.
60 * Revision 1.11 1996/06/01 04:18:45 robertj
61 * Fixed bug in RadioButton, having 2 VALUE fields
63 * Revision 1.10 1996/04/29 12:21:22 robertj
64 * Fixed spelling error in assert.
65 * Fixed check box HTML, should always have a value.
66 * Added display of value of unclosed HTML element.
68 * Revision 1.9 1996/04/14 02:52:04 robertj
69 * Added hidden fields to HTML.
71 * Revision 1.8 1996/03/31 09:03:07 robertj
72 * Changed HTML token so doesn't have trailing CRLF.
74 * Revision 1.7 1996/03/16 04:54:06 robertj
75 * Made the assert for unclosed HTML elements only on debug version.
77 * Revision 1.6 1996/03/12 11:30:33 robertj
78 * Fixed resetting of HTML output using operator=.
80 * Revision 1.5 1996/03/10 13:14:55 robertj
81 * Simplified some of the classes and added catch all string for attributes.
83 * Revision 1.4 1996/02/25 11:14:22 robertj
84 * Radio button support for forms.
86 * Revision 1.3 1996/02/19 13:31:51 robertj
87 * Removed MSC_VER test as now completely removed from WIN16 library.
89 * Revision 1.2 1996/02/08 12:24:30 robertj
90 * Further implementation.
92 * Revision 1.1 1996/02/03 11:18:46 robertj
93 * Initial revision
95 * Revision 1.3 1996/01/28 02:49:16 robertj
96 * Further implementation.
98 * Revision 1.2 1996/01/26 02:24:30 robertj
99 * Further implemetation.
101 * Revision 1.1 1996/01/23 13:04:32 robertj
102 * Initial revision
106 #ifdef __GNUC__
107 #pragma implementation "html.h"
108 #endif
110 #include <ptlib.h>
111 #include <ptclib/html.h>
114 //////////////////////////////////////////////////////////////////////////////
115 // PHTML
117 PHTML::PHTML(ElementInSet initialState)
119 memset(elementSet, 0, sizeof(elementSet));
120 tableNestLevel = 0;
121 initialElement = initialState;
122 switch (initialState) {
123 case NumElementsInSet :
124 break;
125 case InBody :
126 Set(InBody);
127 break;
128 case InForm :
129 Set(InBody);
130 Set(InForm);
131 break;
132 default :
133 PAssertAlways(PInvalidParameter);
138 PHTML::PHTML(const char * cstr)
140 memset(elementSet, 0, sizeof(elementSet));
141 tableNestLevel = 0;
142 initialElement = NumElementsInSet;
143 ostream & this_stream = *this;
144 this_stream << Title(cstr) << Body() << Heading(1) << cstr << Heading(1);
148 PHTML::PHTML(const PString & str)
150 memset(elementSet, 0, sizeof(elementSet));
151 tableNestLevel = 0;
152 initialElement = NumElementsInSet;
153 ostream & this_stream = *this;
154 this_stream << Title(str) << Body() << Heading(1) << str << Heading(1);
158 PHTML::~PHTML()
160 #ifndef NDEBUG
161 if (initialElement != NumElementsInSet) {
162 Clr(initialElement);
163 Clr(InBody);
165 for (PINDEX i = 0; i < PARRAYSIZE(elementSet); i++)
166 PAssert(elementSet[i] == 0, psprintf("Failed to close element %u", i));
167 #endif
171 void PHTML::AssignContents(const PContainer & cont)
173 PStringStream::AssignContents(cont);
174 memset(elementSet, 0, sizeof(elementSet));
178 BOOL PHTML::Is(ElementInSet elmt) const
180 return (elementSet[elmt>>3]&(1<<(elmt&7))) != 0;
184 void PHTML::Set(ElementInSet elmt)
186 elementSet[elmt>>3] |= (1<<(elmt&7));
190 void PHTML::Clr(ElementInSet elmt)
192 elementSet[elmt>>3] &= ~(1<<(elmt&7));
196 void PHTML::Toggle(ElementInSet elmt)
198 elementSet[elmt>>3] ^= (1<<(elmt&7));
202 void PHTML::Element::Output(PHTML & html) const
204 PAssert(reqElement == NumElementsInSet || html.Is(reqElement),
205 "HTML element out of context");
207 if (crlf == BothCRLF || (crlf == OpenCRLF && !html.Is(inElement)))
208 html << "\r\n";
210 html << '<';
211 if (html.Is(inElement))
212 html << '/';
213 html << name;
215 AddAttr(html);
217 if (attr != NULL)
218 html << ' ' << attr;
220 html << '>';
221 if (crlf == BothCRLF || (crlf == CloseCRLF && html.Is(inElement)))
222 html << "\r\n";
224 if (inElement != NumElementsInSet)
225 html.Toggle(inElement);
229 void PHTML::Element::AddAttr(PHTML &) const
234 PHTML::HTML::HTML(const char * attr)
235 : Element("HTML", attr, InHTML, NumElementsInSet, BothCRLF)
239 PHTML::Head::Head()
240 : Element("HEAD", NULL, InHead, NumElementsInSet, BothCRLF)
244 void PHTML::Head::Output(PHTML & html) const
246 PAssert(!html.Is(InBody), "HTML element out of context");
247 if (!html.Is(InHTML))
248 html << HTML();
249 Element::Output(html);
253 PHTML::Body::Body(const char * attr)
254 : Element("BODY", attr, InBody, NumElementsInSet, BothCRLF)
259 void PHTML::Body::Output(PHTML & html) const
261 if (!html.Is(InHTML))
262 html << HTML();
263 if (html.Is(InTitle))
264 html << Title();
265 if (html.Is(InHead))
266 html << Head();
267 Element::Output(html);
268 if (!html.Is(InBody))
269 html << HTML();
273 PHTML::Title::Title()
274 : Element("TITLE", NULL, InTitle, InHead, CloseCRLF)
276 titleString = NULL;
279 PHTML::Title::Title(const char * titleCStr)
280 : Element("TITLE", NULL, InTitle, InHead, CloseCRLF)
282 titleString = titleCStr;
285 PHTML::Title::Title(const PString & titleStr)
286 : Element("TITLE", NULL, InTitle, InHead, CloseCRLF)
288 titleString = titleStr;
291 void PHTML::Title::Output(PHTML & html) const
293 PAssert(!html.Is(InBody), "HTML element out of context");
294 if (!html.Is(InHead))
295 html << Head();
296 if (html.Is(InTitle)) {
297 if (titleString != NULL)
298 html << titleString;
299 Element::Output(html);
301 else {
302 Element::Output(html);
303 if (titleString != NULL) {
304 html << titleString;
305 Element::Output(html);
311 PHTML::Banner::Banner(const char * attr)
312 : Element("BANNER", attr, NumElementsInSet, InBody, BothCRLF)
317 PHTML::Division::Division(const char * attr)
318 : Element("DIV", attr, InDivision, InBody, BothCRLF)
323 PHTML::Heading::Heading(int number,
324 int sequence,
325 int skip,
326 const char * attr)
327 : Element("H", attr, InHeading, InBody, CloseCRLF)
329 num = number;
330 srcString = NULL;
331 seqNum = sequence;
332 skipSeq = skip;
335 PHTML::Heading::Heading(int number,
336 const char * image,
337 int sequence,
338 int skip,
339 const char * attr)
340 : Element("H", attr, InHeading, InBody, CloseCRLF)
342 num = number;
343 srcString = image;
344 seqNum = sequence;
345 skipSeq = skip;
348 PHTML::Heading::Heading(int number,
349 const PString & imageStr,
350 int sequence,
351 int skip,
352 const char * attr)
353 : Element("H", attr, InHeading, InBody, CloseCRLF)
355 num = number;
356 srcString = imageStr;
357 seqNum = sequence;
358 skipSeq = skip;
361 void PHTML::Heading::AddAttr(PHTML & html) const
363 PAssert(num >= 1 && num <= 6, "Bad heading number");
364 html << num;
365 if (srcString != NULL)
366 html << " SRC=\"" << srcString << '"';
367 if (seqNum > 0)
368 html << " SEQNUM=" << seqNum;
369 if (skipSeq > 0)
370 html << " SKIP=" << skipSeq;
374 PHTML::BreakLine::BreakLine(const char * attr)
375 : Element("BR", attr, NumElementsInSet, InBody, CloseCRLF)
380 PHTML::Paragraph::Paragraph(const char * attr)
381 : Element("P", attr, NumElementsInSet, InBody, OpenCRLF)
386 PHTML::PreFormat::PreFormat(int widthInChars, const char * attr)
387 : Element("PRE", attr, InPreFormat, InBody, CloseCRLF)
389 width = widthInChars;
393 void PHTML::PreFormat::AddAttr(PHTML & html) const
395 if (width > 0)
396 html << " WIDTH=" << width;
400 PHTML::HotLink::HotLink(const char * href, const char * attr)
401 : Element("A", attr, InAnchor, InBody, NoCRLF)
403 hrefString = href;
406 void PHTML::HotLink::AddAttr(PHTML & html) const
408 if (hrefString != NULL && *hrefString != '\0')
409 html << " HREF=\"" << hrefString << '"';
410 else
411 PAssert(html.Is(InAnchor), PInvalidParameter);
415 PHTML::Target::Target(const char * name, const char * attr)
416 : Element("A", attr, NumElementsInSet, InBody, NoCRLF)
418 nameString = name;
421 void PHTML::Target::AddAttr(PHTML & html) const
423 if (nameString != NULL && *nameString != '\0')
424 html << " NAME=\"" << nameString << '"';
428 PHTML::ImageElement::ImageElement(const char * n,
429 const char * attr,
430 ElementInSet elmt,
431 ElementInSet req,
432 OptionalCRLF c,
433 const char * image)
434 : Element(n, attr, elmt, req, c)
436 srcString = image;
440 void PHTML::ImageElement::AddAttr(PHTML & html) const
442 if (srcString != NULL)
443 html << " SRC=\"" << srcString << '"';
447 PHTML::Image::Image(const char * src, int w, int h, const char * attr)
448 : ImageElement("IMG", attr, NumElementsInSet, InBody, NoCRLF, src)
450 altString = NULL;
451 width = w;
452 height = h;
455 PHTML::Image::Image(const char * src,
456 const char * alt,
457 int w, int h,
458 const char * attr)
459 : ImageElement("IMG", attr, NumElementsInSet, InBody, NoCRLF, src)
461 altString = alt;
462 width = w;
463 height = h;
466 void PHTML::Image::AddAttr(PHTML & html) const
468 PAssert(srcString != NULL && *srcString != '\0', PInvalidParameter);
469 if (altString != NULL)
470 html << " ALT=\"" << altString << '"';
471 if (width != 0)
472 html << " WIDTH=" << width;
473 if (height != 0)
474 html << " HEIGHT=" << height;
475 ImageElement::AddAttr(html);
479 PHTML::HRule::HRule(const char * image, const char * attr)
480 : ImageElement("HR", attr, NumElementsInSet, InBody, BothCRLF, image)
485 PHTML::Note::Note(const char * image, const char * attr)
486 : ImageElement("NOTE", attr, InNote, InBody, BothCRLF, image)
491 PHTML::Address::Address(const char * attr)
492 : Element("ADDRESS", attr, InAddress, InBody, BothCRLF)
497 PHTML::BlockQuote::BlockQuote(const char * attr)
498 : Element("BQ", attr, InBlockQuote, InBody, BothCRLF)
503 PHTML::Credit::Credit(const char * attr)
504 : Element("CREDIT", attr, NumElementsInSet, InBlockQuote, OpenCRLF)
508 PHTML::SetTab::SetTab(const char * id, const char * attr)
509 : Element("TAB", attr, NumElementsInSet, InBody, NoCRLF)
511 ident = id;
514 void PHTML::SetTab::AddAttr(PHTML & html) const
516 PAssert(ident != NULL && *ident != '\0', PInvalidParameter);
517 html << " ID=" << ident;
521 PHTML::Tab::Tab(int indent, const char * attr)
522 : Element("TAB", attr, NumElementsInSet, InBody, NoCRLF)
524 ident = NULL;
525 indentSize = indent;
528 PHTML::Tab::Tab(const char * id, const char * attr)
529 : Element("TAB", attr, NumElementsInSet, InBody, NoCRLF)
531 ident = id;
532 indentSize = 0;
535 void PHTML::Tab::AddAttr(PHTML & html) const
537 PAssert(indentSize!=0 || (ident!=NULL && *ident!='\0'), PInvalidParameter);
538 if (indentSize > 0)
539 html << " INDENT=" << indentSize;
540 else
541 html << " TO=" << ident;
545 PHTML::SimpleList::SimpleList(const char * attr)
546 : Element("UL", attr, InList, InBody, BothCRLF)
550 void PHTML::SimpleList::AddAttr(PHTML & html) const
552 html << " PLAIN";
556 PHTML::BulletList::BulletList(const char * attr)
557 : Element("UL", attr, InList, InBody, BothCRLF)
562 PHTML::OrderedList::OrderedList(int seqNum, const char * attr)
563 : Element("OL", attr, InList, InBody, BothCRLF)
565 sequenceNum = seqNum;
568 void PHTML::OrderedList::AddAttr(PHTML & html) const
570 if (sequenceNum > 0)
571 html << " SEQNUM=" << sequenceNum;
572 if (sequenceNum < 0)
573 html << " CONTINUE";
577 PHTML::DefinitionList::DefinitionList(const char * attr)
578 : Element("DL", attr, InList, InBody, BothCRLF)
583 PHTML::ListHeading::ListHeading(const char * attr)
584 : Element("LH", attr, InListHeading, InList, CloseCRLF)
588 PHTML::ListItem::ListItem(int skip, const char * attr)
589 : Element("LI", attr, NumElementsInSet, InList, OpenCRLF)
591 skipSeq = skip;
594 void PHTML::ListItem::AddAttr(PHTML & html) const
596 if (skipSeq > 0)
597 html << " SKIP=" << skipSeq;
601 PHTML::DefinitionTerm::DefinitionTerm(const char * attr)
602 : Element("DT", attr, NumElementsInSet, InList, NoCRLF)
606 void PHTML::DefinitionTerm::Output(PHTML & html) const
608 PAssert(!html.Is(InDefinitionTerm), "HTML definition item missing");
609 Element::Output(html);
610 html.Set(InDefinitionTerm);
614 PHTML::DefinitionItem::DefinitionItem(const char * attr)
615 : Element("DD", attr, NumElementsInSet, InList, NoCRLF)
619 void PHTML::DefinitionItem::Output(PHTML & html) const
621 PAssert(html.Is(InDefinitionTerm), "HTML definition term missing");
622 Element::Output(html);
623 html.Clr(InDefinitionTerm);
627 PHTML::TableStart::TableStart(const char * attr)
628 : Element("TABLE", attr, InTable, InBody, BothCRLF)
630 borderFlag = FALSE;
633 PHTML::TableStart::TableStart(BorderCodes border, const char * attr)
634 : Element("TABLE", attr, InTable, InBody, BothCRLF)
636 borderFlag = border == Border;
639 void PHTML::TableStart::Output(PHTML & html) const
641 if (html.tableNestLevel > 0)
642 html.Clr(InTable);
643 Element::Output(html);
646 void PHTML::TableStart::AddAttr(PHTML & html) const
648 if (borderFlag)
649 html << " BORDER";
650 html.tableNestLevel++;
654 PHTML::TableEnd::TableEnd()
655 : Element("TABLE", "", InTable, InBody, BothCRLF)
659 void PHTML::TableEnd::Output(PHTML & html) const
661 PAssert(html.tableNestLevel > 0, "Table nesting error");
662 Element::Output(html);
663 html.tableNestLevel--;
664 if (html.tableNestLevel > 0)
665 html.Set(InTable);
669 PHTML::TableRow::TableRow(const char * attr)
670 : Element("TR", attr, NumElementsInSet, InTable, OpenCRLF)
675 PHTML::TableHeader::TableHeader(const char * attr)
676 : Element("TH", attr, NumElementsInSet, InTable, CloseCRLF)
681 PHTML::TableData::TableData(const char * attr)
682 : Element("TD", attr, NumElementsInSet, InTable, NoCRLF)
687 PHTML::Form::Form(const char * method,
688 const char * action,
689 const char * mimeType,
690 const char * script)
691 : Element("FORM", NULL, InForm, InBody, BothCRLF)
693 methodString = method;
694 actionString = action;
695 mimeTypeString = mimeType;
696 scriptString = script;
699 void PHTML::Form::AddAttr(PHTML & html) const
701 if (methodString != NULL)
702 html << " METHOD=" << methodString;
703 if (actionString != NULL)
704 html << " ACTION=\"" << actionString << '"';
705 if (mimeTypeString != NULL)
706 html << " ENCTYPE=\"" << mimeTypeString << '"';
707 if (scriptString != NULL)
708 html << " SCRIPT=\"" << scriptString << '"';
712 PHTML::FieldElement::FieldElement(const char * n,
713 const char * attr,
714 ElementInSet elmt,
715 OptionalCRLF c,
716 DisableCodes disabled)
717 : Element(n, attr, elmt, InForm, c)
719 disabledFlag = disabled == Disabled;
722 void PHTML::FieldElement::AddAttr(PHTML & html) const
724 if (disabledFlag)
725 html << " DISABLED";
729 PHTML::Select::Select(const char * fname, const char * attr)
730 : FieldElement("SELECT", attr, InSelect, BothCRLF, Enabled)
732 nameString = fname;
735 PHTML::Select::Select(const char * fname,
736 DisableCodes disabled,
737 const char * attr)
738 : FieldElement("SELECT", attr, InSelect, BothCRLF, disabled)
740 nameString = fname;
743 void PHTML::Select::AddAttr(PHTML & html) const
745 if (!html.Is(InSelect)) {
746 PAssert(nameString != NULL && *nameString != '\0', PInvalidParameter);
747 html << " NAME=\"" << nameString << '"';
749 FieldElement::AddAttr(html);
753 PHTML::Option::Option(const char * attr)
754 : FieldElement("OPTION", attr, NumElementsInSet, NoCRLF, Enabled)
756 selectedFlag = FALSE;
759 PHTML::Option::Option(SelectionCodes select,
760 const char * attr)
761 : FieldElement("OPTION", attr, NumElementsInSet, NoCRLF, Enabled)
763 selectedFlag = select == Selected;
766 PHTML::Option::Option(DisableCodes disabled,
767 const char * attr)
768 : FieldElement("OPTION", attr, NumElementsInSet, NoCRLF, disabled)
770 selectedFlag = FALSE;
773 PHTML::Option::Option(SelectionCodes select,
774 DisableCodes disabled,
775 const char * attr)
776 : FieldElement("OPTION", attr, NumElementsInSet, NoCRLF, disabled)
778 selectedFlag = select == Selected;
781 void PHTML::Option::AddAttr(PHTML & html) const
783 if (selectedFlag)
784 html << " SELECTED";
785 FieldElement::AddAttr(html);
789 PHTML::FormField::FormField(const char * n,
790 const char * attr,
791 ElementInSet elmt,
792 OptionalCRLF c,
793 DisableCodes disabled,
794 const char * fname)
795 : FieldElement(n, attr, elmt, c, disabled)
797 nameString = fname;
800 void PHTML::FormField::AddAttr(PHTML & html) const
802 PAssert(nameString != NULL && *nameString != '\0', PInvalidParameter);
803 html << " NAME=\"" << nameString << '"';
804 FieldElement::AddAttr(html);
808 PHTML::TextArea::TextArea(const char * fname,
809 DisableCodes disabled,
810 const char * attr)
811 : FormField("TEXTAREA", attr, InSelect, BothCRLF, disabled, fname)
813 numRows = numCols = 0;
816 PHTML::TextArea::TextArea(const char * fname,
817 int rows, int cols,
818 DisableCodes disabled,
819 const char * attr)
820 : FormField("TEXTAREA", attr, InSelect, BothCRLF, disabled, fname)
822 numRows = rows;
823 numCols = cols;
826 void PHTML::TextArea::AddAttr(PHTML & html) const
828 if (numRows > 0)
829 html << " ROWS=" << numRows;
830 if (numCols > 0)
831 html << " COLS=" << numCols;
832 FormField::AddAttr(html);
836 PHTML::InputField::InputField(const char * type,
837 const char * fname,
838 DisableCodes disabled,
839 const char * attr)
840 : FormField("INPUT", attr, NumElementsInSet, NoCRLF, disabled, fname)
842 typeString = type;
845 void PHTML::InputField::AddAttr(PHTML & html) const
847 PAssert(typeString != NULL && *typeString != '\0', PInvalidParameter);
848 html << " TYPE=" << typeString;
849 FormField::AddAttr(html);
853 PHTML::HiddenField::HiddenField(const char * fname,
854 const char * value,
855 const char * attr)
856 : InputField("hidden", fname, Enabled, attr)
858 valueString = value;
861 void PHTML::HiddenField::AddAttr(PHTML & html) const
863 InputField::AddAttr(html);
864 PAssert(valueString != NULL, PInvalidParameter);
865 html << " VALUE=\"" << valueString << '"';
869 PHTML::InputText::InputText(const char * fname,
870 int size,
871 const char * init,
872 const char * attr)
873 : InputField("text", fname, Enabled, attr)
875 width = size;
876 length = 0;
877 value = init;
880 PHTML::InputText::InputText(const char * fname,
881 int size,
882 DisableCodes disabled,
883 const char * attr)
884 : InputField("text", fname, disabled, attr)
886 width = size;
887 length = 0;
888 value = NULL;
891 PHTML::InputText::InputText(const char * fname,
892 int size,
893 int maxLength,
894 DisableCodes disabled,
895 const char * attr)
896 : InputField("text", fname, disabled, attr)
898 width = size;
899 length = maxLength;
900 value = NULL;
903 PHTML::InputText::InputText(const char * fname,
904 int size,
905 const char * init,
906 int maxLength,
907 DisableCodes disabled,
908 const char * attr)
909 : InputField("text", fname, disabled, attr)
911 width = size;
912 length = maxLength;
913 value = init;
916 PHTML::InputText::InputText(const char * type,
917 const char * fname,
918 int size,
919 const char * init,
920 int maxLength,
921 DisableCodes disabled,
922 const char * attr)
923 : InputField(type, fname, disabled, attr)
925 width = size;
926 length = maxLength;
927 value = init;
930 void PHTML::InputText::AddAttr(PHTML & html) const
932 InputField::AddAttr(html);
933 html << " SIZE=" << width;
934 if (length > 0)
935 html << " MAXLENGTH=" << length;
936 if (value != NULL)
937 html << " VALUE=\"" << value << '"';
941 PHTML::InputPassword::InputPassword(const char * fname,
942 int size,
943 const char * init,
944 const char * attr)
945 : InputText("password", fname, size, init, 0, Enabled, attr)
949 PHTML::InputPassword::InputPassword(const char * fname,
950 int size,
951 DisableCodes disabled,
952 const char * attr)
953 : InputText("password", fname, size, NULL, 0, disabled, attr)
957 PHTML::InputPassword::InputPassword(const char * fname,
958 int size,
959 int maxLength,
960 DisableCodes disabled,
961 const char * attr)
962 : InputText("password", fname, size, NULL, maxLength, disabled, attr)
966 PHTML::InputPassword::InputPassword(const char * fname,
967 int size,
968 const char * init,
969 int maxLength,
970 DisableCodes disabled,
971 const char * attr)
972 : InputText("password", fname, size, init, maxLength, disabled, attr)
977 PHTML::RadioButton::RadioButton(const char * fname,
978 const char * value,
979 const char * attr)
980 : InputField("radio", fname, Enabled, attr)
982 valueString = value;
983 checkedFlag = FALSE;
986 PHTML::RadioButton::RadioButton(const char * fname,
987 const char * value,
988 DisableCodes disabled,
989 const char * attr)
990 : InputField("radio", fname, disabled, attr)
992 valueString = value;
993 checkedFlag = FALSE;
996 PHTML::RadioButton::RadioButton(const char * fname,
997 const char * value,
998 CheckedCodes check,
999 DisableCodes disabled,
1000 const char * attr)
1001 : InputField("radio", fname, disabled, attr)
1003 valueString = value;
1004 checkedFlag = check == Checked;
1007 PHTML::RadioButton::RadioButton(const char * type,
1008 const char * fname,
1009 const char * value,
1010 CheckedCodes check,
1011 DisableCodes disabled,
1012 const char * attr)
1013 : InputField(type, fname, disabled, attr)
1015 valueString = value;
1016 checkedFlag = check == Checked;
1019 void PHTML::RadioButton::AddAttr(PHTML & html) const
1021 InputField::AddAttr(html);
1022 PAssert(valueString != NULL, PInvalidParameter);
1023 html << " VALUE=\"" << valueString << "\"";
1024 if (checkedFlag)
1025 html << " CHECKED";
1029 PHTML::CheckBox::CheckBox(const char * fname, const char * attr)
1030 : RadioButton("checkbox", fname, "TRUE", UnChecked, Enabled, attr)
1034 PHTML::CheckBox::CheckBox(const char * fname,
1035 DisableCodes disabled,
1036 const char * attr)
1037 : RadioButton("checkbox", fname, "TRUE", UnChecked, disabled, attr)
1041 PHTML::CheckBox::CheckBox(const char * fname,
1042 CheckedCodes check,
1043 DisableCodes disabled,
1044 const char * attr)
1045 : RadioButton("checkbox", fname, "TRUE", check, disabled, attr)
1050 PHTML::InputRange::InputRange(const char * fname,
1051 int min, int max, int value,
1052 DisableCodes disabled,
1053 const char * attr)
1054 : InputField("range", fname, disabled, attr)
1056 PAssert(min <= max, PInvalidParameter);
1057 minValue = min;
1058 maxValue = max;
1059 if (value < min)
1060 initValue = min;
1061 else if (value > max)
1062 initValue = max;
1063 else
1064 initValue = value;
1067 void PHTML::InputRange::AddAttr(PHTML & html) const
1069 InputField::AddAttr(html);
1070 PINDEX max = PMAX(-minValue, maxValue);
1071 PINDEX width = 3;
1072 while (max > 10) {
1073 width++;
1074 max /= 10;
1076 html << " SIZE=" << width
1077 << " MIN=" << minValue
1078 << " MAX=" << maxValue
1079 << " VALUE=\"" << initValue << "\"";
1083 PHTML::InputFile::InputFile(const char * fname,
1084 const char * accept,
1085 DisableCodes disabled,
1086 const char * attr)
1087 : InputField("file", fname, disabled, attr)
1089 acceptString = accept;
1092 void PHTML::InputFile::AddAttr(PHTML & html) const
1094 InputField::AddAttr(html);
1095 if (acceptString != NULL)
1096 html << " ACCEPT=\"" << acceptString << '"';
1100 PHTML::InputImage::InputImage(const char * fname,
1101 const char * src,
1102 DisableCodes disabled,
1103 const char * attr)
1104 : InputField("image", fname, disabled, attr)
1106 srcString = src;
1109 PHTML::InputImage::InputImage(const char * type,
1110 const char * fname,
1111 const char * src,
1112 DisableCodes disabled,
1113 const char * attr)
1114 : InputField(type, fname, disabled, attr)
1116 srcString = src;
1119 void PHTML::InputImage::AddAttr(PHTML & html) const
1121 InputField::AddAttr(html);
1122 if (srcString != NULL)
1123 html << " SRC=\"" << srcString << '"';
1127 PHTML::InputScribble::InputScribble(const char * fname,
1128 const char * src,
1129 DisableCodes disabled,
1130 const char * attr)
1131 : InputImage("scribble", fname, src, disabled, attr)
1135 PHTML::ResetButton::ResetButton(const char * title,
1136 const char * fname,
1137 const char * src,
1138 DisableCodes disabled,
1139 const char * attr)
1140 : InputImage("reset", fname != NULL ? fname : "reset", src, disabled, attr)
1142 titleString = title;
1145 PHTML::ResetButton::ResetButton(const char * type,
1146 const char * title,
1147 const char * fname,
1148 const char * src,
1149 DisableCodes disabled,
1150 const char * attr)
1151 : InputImage(type, fname, src, disabled, attr)
1153 titleString = title;
1156 void PHTML::ResetButton::AddAttr(PHTML & html) const
1158 InputImage::AddAttr(html);
1159 if (titleString != NULL)
1160 html << " VALUE=\"" << titleString << '"';
1164 PHTML::SubmitButton::SubmitButton(const char * title,
1165 const char * fname,
1166 const char * src,
1167 DisableCodes disabled,
1168 const char * attr)
1169 : ResetButton("submit",
1170 title, fname != NULL ? fname : "submit", src, disabled, attr)
1174 // End Of File ///////////////////////////////////////////////////////////////