Annotation of Amaya/amaya/XHTMLbuilder.c, revision 1.145

1.1       cvs         1: /*
                      2:  *
1.140     vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2007
1.1       cvs         4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
                      7: 
                      8: /*
1.30      cvs         9:  * XHTMLbuilder.c
1.23      cvs        10:  * Builds the corresponding abstract tree for a Thot document of type HTML.
1.1       cvs        11:  *
1.20      cvs        12:  * Authors: L. Carcone
                     13:  *          V. Quint 
1.1       cvs        14:  */
                     15: 
                     16: #define THOT_EXPORT extern
                     17: #include "amaya.h"
                     18: #include "css.h"
1.2       cvs        19: #include "parser.h"
                     20: #include "HTML.h"
1.30      cvs        21: #include "fetchHTMLname.h"
1.2       cvs        22: 
1.13      cvs        23: #include "css_f.h"
1.76      vatton     24: #include "EDITstyle_f.h"
1.13      cvs        25: #include "fetchXMLname_f.h"
1.30      cvs        26: #include "fetchHTMLname_f.h"
1.22      cvs        27: #include "html2thot_f.h"
1.1       cvs        28: #include "HTMLactions_f.h"
                     29: #include "HTMLedit_f.h"
1.22      cvs        30: #include "HTMLform_f.h"
1.1       cvs        31: #include "HTMLimage_f.h"
                     32: #include "HTMLtable_f.h"
                     33: #include "HTMLimage_f.h"
1.104     vatton     34: #include "init_f.h"
1.1       cvs        35: #include "UIcss_f.h"
1.13      cvs        36: #include "styleparser_f.h"
1.2       cvs        37: #include "XHTMLbuilder_f.h"
1.13      cvs        38: #include "Xml2thot_f.h"
1.1       cvs        39: 
1.47      cvs        40: /* Elements that cannot contain text as immediate children.
                     41:    When some text is present in the HTML file it must be 
                     42:    surrounded by a Pseudo_paragraph element */
                     43: static int          NoTextChild[] =
1.129     vatton     44:   {
                     45:     HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
                     46:     HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
                     47:     HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
                     48:     HTML_EL_Numbered_List, HTML_EL_Option_Menu,
                     49:     HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
                     50:     HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
                     51:     HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
                     52:     HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
1.141     vatton     53:     HTML_EL_Data_cell, HTML_EL_Heading_cell, HTML_EL_INS, HTML_EL_DEL,
1.129     vatton     54:     0};
1.47      cvs        55: 
1.28      cvs        56: /* Define a pointer to let parser functions access the HTML entity table */
                     57: extern XmlEntity *pXhtmlEntityTable;
1.6       cvs        58: 
1.30      cvs        59: /* maximum size of error messages */
                     60: #define MaxMsgLength 200
                     61: 
1.6       cvs        62: /*----------------------------------------------------------------------
1.104     vatton     63:   ParseCharsetAndContentType:
1.6       cvs        64:   Parses the element HTTP-EQUIV and looks for the charset value.
                     65:   ----------------------------------------------------------------------*/
1.104     vatton     66: void ParseCharsetAndContentType (Element el, Document doc) 
1.30      cvs        67: 
1.6       cvs        68: {
1.129     vatton     69:   AttributeType attrType;
                     70:   Attribute     attr;
                     71:   ElementType   elType;
                     72:   CHARSET       charset;
                     73:   char         *text, *text2, *ptrText, *str;
                     74:   char          charsetname[MAX_LENGTH];
                     75:   int           length;
                     76:   int           pos, index = 0;
                     77: 
                     78:   charset = TtaGetDocumentCharset (doc);
                     79:   if (charset != UNDEFINED_CHARSET &&
                     80:       DocumentMeta[doc] && DocumentMeta[doc]->content_type)
                     81:     return;
                     82: 
                     83:   elType = TtaGetElementType (el);
                     84:   attrType.AttrSSchema = elType.ElSSchema;
                     85:   attrType.AttrTypeNum = HTML_ATTR_http_equiv;
                     86:   attr = TtaGetAttribute (el, attrType);
                     87:   if (attr != NULL)
                     88:     {
                     89:       /* There is a HTTP-EQUIV attribute */
                     90:       length = TtaGetTextAttributeLength (attr);
                     91:       if (length > 0)
                     92:         {
                     93:           text = (char *)TtaGetMemory (length + 1);
                     94:           TtaGiveTextAttributeValue (attr, text, &length);
                     95:           if (!strcasecmp (text, "content-type"))
                     96:             {
                     97:               attrType.AttrTypeNum = HTML_ATTR_meta_content;
                     98:               attr = TtaGetAttribute (el, attrType);
                     99:               if (attr != NULL)
                    100:                 {
                    101:                   length = TtaGetTextAttributeLength (attr);
                    102:                   if (length > 0)
                    103:                     {
                    104:                       text2 = (char *)TtaGetMemory (length + 1);
                    105:                       TtaGiveTextAttributeValue (attr, text2, &length);
                    106:                       ptrText = text2;
                    107:                       while (*ptrText)
                    108:                         {
                    109:                           *ptrText = tolower (*ptrText);
                    110:                           ptrText++;
                    111:                         }
                    112: 
                    113:                       if (!DocumentMeta[doc])
                    114:                         DocumentMeta[doc] = DocumentMetaDataAlloc ();
                    115:                       if (DocumentMeta[doc]->content_type == NULL)
                    116:                         {
1.104     vatton    117:                           
1.129     vatton    118:                           if (!strncmp (text2, "text/html", 9))
                    119:                             DocumentMeta[doc]->content_type = TtaStrdup ("text/html");
                    120:                           else
                    121:                             DocumentMeta[doc]->content_type = TtaStrdup (AM_XHTML_MIME_TYPE);
                    122:                         }
                    123: 
                    124:                       if (charset == UNDEFINED_CHARSET)
                    125:                         {
                    126:                           /* the charset is not already defined by the http header */
                    127:                           str = strstr (text2, "charset=");
                    128:                           if (str)
                    129:                             {
                    130:                               pos = str - text2 + 8;
                    131:                               while (text2[pos] != SPACE &&
                    132:                                      text2[pos] != TAB && text2[pos] != EOS)
                    133:                                 charsetname[index++] = text2[pos++];
                    134:                               charsetname[index] = EOS;
                    135:                               charset = TtaGetCharset (charsetname);
                    136:                               if (charset != UNDEFINED_CHARSET)
                    137:                                 TtaSetDocumentCharset (doc, charset, FALSE);
                    138:                             }
                    139:                         }
                    140:                       TtaFreeMemory (text2);
                    141:                     }       
                    142:                 } 
                    143:             }
                    144:           TtaFreeMemory (text);
                    145:         }
                    146:     }
1.6       cvs       147: }
                    148: 
1.126     tollenae  149: #ifdef TEMPLATES
1.130     vatton    150: /*----------------------------------------------------------------------
                    151:   ----------------------------------------------------------------------*/
1.126     tollenae  152: void ParseTemplateMeta (Element el, Document doc)
                    153: {
                    154:   AttributeType attrType;
                    155:   Attribute     attr;
                    156:   ElementType   elType;
                    157:   char         *text, *text2, *ptrText;
                    158:   int           length;
                    159: 
                    160:   elType = TtaGetElementType (el);
                    161:   attrType.AttrSSchema = elType.ElSSchema;
                    162:   attrType.AttrTypeNum = HTML_ATTR_meta_name;
                    163:   attr = TtaGetAttribute (el, attrType);
                    164: 
                    165:   if (attr != NULL)
                    166:     {
                    167:       /* There is a name attribute */
                    168:       length = TtaGetTextAttributeLength (attr);
                    169:       if (length > 0)
1.129     vatton    170:         {
                    171:           text = (char *)TtaGetMemory (length + 1);
                    172:           TtaGiveTextAttributeValue (attr, text, &length);
                    173:           if (!strcasecmp (text, "template"))
                    174:             {
                    175:               /* We are parsing the 'template' meta */
                    176:               attrType.AttrTypeNum = HTML_ATTR_meta_content;
                    177:               attr = TtaGetAttribute (el, attrType);
                    178:               if (attr != NULL)
                    179:                 {
                    180:                   length = TtaGetTextAttributeLength (attr);
                    181:                   if (length > 0)
                    182:                     {
                    183:                       text2 = (char *)TtaGetMemory (length + 1);
                    184:                       TtaGiveTextAttributeValue (attr, text2, &length);
                    185:                       ptrText = text2;
1.126     tollenae  186:                      
1.129     vatton    187:                       /* Convert all char to lower case */
                    188:                       while (*ptrText)
                    189:                         {
                    190:                           *ptrText = tolower (*ptrText);
                    191:                           ptrText++;
                    192:                         }
                    193: 
                    194:                       if (!DocumentMeta[doc])
                    195:                         DocumentMeta[doc] = DocumentMetaDataAlloc ();
                    196:                       if (DocumentMeta[doc]->template_version == NULL)
                    197:                         {
                    198:                           DocumentMeta[doc]->template_version = TtaStrdup (text2);
                    199:                         }
                    200:                       TtaFreeMemory (text2);
                    201:                     }       
                    202:                 } 
                    203:             }
                    204:           TtaFreeMemory (text);
                    205:         }
1.126     tollenae  206:     }
                    207: }
                    208: #endif /* TEMPLATES */
                    209: 
                    210: 
1.23      cvs       211: /*----------------------------------------------------------------------
1.129     vatton    212:   XhtmlCannotContainText 
                    213:   Return TRUE if element el is a block element.
1.47      cvs       214:   ----------------------------------------------------------------------*/
1.109     vatton    215: ThotBool XhtmlCannotContainText (ElementType elType)
1.47      cvs       216: 
                    217: {
1.129     vatton    218:   int        i;
                    219:   ThotBool   ret;
1.47      cvs       220: 
1.129     vatton    221:   if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
                    222:     /* not an HTML element */
                    223:     ret = TRUE;
                    224:   else
                    225:     {
                    226:       ret = FALSE;
                    227:       i = 0;
                    228:       while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
                    229:         i++;
                    230:       if (NoTextChild[i] == elType.ElTypeNum)
                    231:         ret = TRUE;
                    232:     }
                    233:   return ret;
1.23      cvs       234: }
1.145   ! vatton    235: /*----------------------------------------------------------------------
        !           236:   CheckNamespace
        !           237:   If attribute attrNum is not present on element el, generate a
        !           238:   parsing error message.
        !           239:   ----------------------------------------------------------------------*/
        !           240: static void CheckNamespace (Element el, Document doc)
        !           241: {
        !           242:   char           msgBuffer[MaxMsgLength];
        !           243:   int            lineNum;
        !           244: 
        !           245:   if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat &&
        !           246:       TtaGiveNamespaceDeclaration (doc, el) == NULL)
        !           247:     {
        !           248:       sprintf (msgBuffer, "Mandatory namespace for %s will be added when saving",
        !           249:                TtaGetElementTypeName(TtaGetElementType(el)));
        !           250:       lineNum = TtaGetElementLineNumber(el);
        !           251:       XmlParseError (warningMessage, (unsigned char*)msgBuffer, lineNum);
        !           252:       TtaSetANamespaceDeclaration (doc, el, NULL, XHTML_URI);
        !           253:     }
        !           254: }
1.23      cvs       255: 
1.6       cvs       256: /*----------------------------------------------------------------------
1.117     quint     257:   CheckMandatoryAttribute
                    258:   If attribute attrNum is not present on element el, generate a
                    259:   parsing error message.
1.111     vatton    260:   ----------------------------------------------------------------------*/
1.128     tollenae  261: void CheckMandatoryAttribute (Element el, Document doc, int attrNum)
1.111     vatton    262: {
                    263:   ElementType    elType;
                    264:   Attribute      attr;
                    265:   AttributeType  attrType;
1.117     quint     266:   int            lineNum;
1.114     vatton    267:   char          *name;
                    268:   char           msgBuffer[MaxMsgLength];
1.111     vatton    269: 
1.129     vatton    270:   elType = TtaGetElementType (el);
                    271:   attrType.AttrSSchema = elType.ElSSchema;
                    272:   attrType.AttrTypeNum = attrNum;
                    273:   attr = TtaGetAttribute (el, attrType);
                    274:   if (attr == NULL)
                    275:     {
                    276:       name = GetXMLAttributeName (attrType, elType, doc);
                    277:       if (name)
                    278:         {
                    279:           sprintf (msgBuffer, "Missing mandatory attribute %s for element %s",
                    280:                    name, TtaGetElementTypeName(TtaGetElementType(el)));
                    281:           lineNum = TtaGetElementLineNumber(el);
                    282:           if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                    283:             XmlParseError (errorParsing, (unsigned char *)msgBuffer, lineNum);
                    284:           else
                    285:             HTMLParseError (doc, msgBuffer, lineNum);
                    286:         }
                    287:     }
1.111     vatton    288: }
                    289: 
1.118     vatton    290: 
                    291: /*----------------------------------------------------------------------
                    292:   AddRowsColumns
                    293:   Add default rows and columns attributes to a TEXTAREA element.
                    294:   ----------------------------------------------------------------------*/
                    295: void AddRowsColumns (Element el, Document doc)
                    296: {
                    297:   ElementType    elType;
                    298:   Attribute      attr;
                    299:   AttributeType  attrType;
                    300: 
                    301:   /* Add defaults rows and columns to display the textarea */
                    302:   elType = TtaGetElementType (el);
                    303:   attrType.AttrSSchema = elType.ElSSchema;
                    304:   attrType.AttrTypeNum = HTML_ATTR_Rows;
                    305:   attr = TtaGetAttribute (el, attrType);
                    306:   if (attr == NULL)
                    307:     {
                    308:       attr = TtaNewAttribute (attrType);
                    309:       TtaAttachAttribute (el, attr, doc);
                    310:       TtaSetAttributeValue (attr, 4, el, doc);
                    311:     }
                    312:   attrType.AttrTypeNum = HTML_ATTR_Columns;
                    313:   attr = TtaGetAttribute (el, attrType);
                    314:   if (attr == NULL)
                    315:     {
                    316:       attr = TtaNewAttribute (attrType);
                    317:       TtaAttachAttribute (el, attr, doc);
                    318:       TtaSetAttributeValue (attr, 20, el, doc);
                    319:     }
                    320: }
                    321: 
1.111     vatton    322: /*----------------------------------------------------------------------
1.6       cvs       323:   XhtmlElementComplete
1.20      cvs       324:   Complete Xhtml elements.
1.6       cvs       325:   Check its attributes and its contents.
                    326:   ----------------------------------------------------------------------*/
1.99      cvs       327: void XhtmlElementComplete (ParserData *context, Element el, int *error)
1.30      cvs       328: {
1.129     vatton    329:   Document       doc;   
                    330:   ElementType    elType, newElType, childType;
                    331:   Element        child, desc, leaf, prev, next, last,
1.142     quint     332:     elFrames, lastFrame, lastChild, parent, picture, content, legend;
1.129     vatton    333:   Attribute      attr;
                    334:   AttributeType  attrType;
1.135     vatton    335:   SSchema        htmlSchema;
1.129     vatton    336:   Language       lang;
1.136     cvs       337:   char           *text;
1.129     vatton    338:   char           lastChar[2];
                    339:   char           *name1, *data;
1.142     quint     340:   int            typenum, length;
1.134     vatton    341:   ThotBool       isImage, isInline, clean;
1.129     vatton    342: 
                    343:   *error = 0;
                    344:   doc = context->doc;
                    345: 
                    346:   elType = TtaGetElementType (el);
                    347:   htmlSchema = elType.ElSSchema;
                    348:   isInline = IsXMLElementInline (elType, doc);
                    349:   newElType.ElSSchema = elType.ElSSchema;
                    350: 
1.141     vatton    351:   if (elType.ElTypeNum == HTML_EL_ins ||
                    352:       elType.ElTypeNum == HTML_EL_del)
                    353:     {
                    354:       child = TtaGetFirstChild (el);
                    355:       if (IsBlockElement (child))
                    356:         {
                    357:           // change the element type
                    358:           if (elType.ElTypeNum == HTML_EL_ins)
                    359:             TtaChangeTypeOfElement (el, doc, HTML_EL_INS);
                    360:           else
                    361:             TtaChangeTypeOfElement (el, doc, HTML_EL_DEL);
                    362:           isInline = FALSE;
                    363:         }
                    364:     }
1.129     vatton    365:   if (elType.ElTypeNum == HTML_EL_Paragraph ||
                    366:       elType.ElTypeNum == HTML_EL_Address ||
                    367:       elType.ElTypeNum == HTML_EL_H1 ||
                    368:       elType.ElTypeNum == HTML_EL_H2 ||
                    369:       elType.ElTypeNum == HTML_EL_H3 ||
                    370:       elType.ElTypeNum == HTML_EL_H4 ||
                    371:       elType.ElTypeNum == HTML_EL_H5 ||
                    372:       elType.ElTypeNum == HTML_EL_H6 ||
                    373:       elType.ElTypeNum == HTML_EL_Preformatted ||
                    374:       elType.ElTypeNum == HTML_EL_Term ||
                    375:       elType.ElTypeNum == HTML_EL_LEGEND ||
                    376:       elType.ElTypeNum == HTML_EL_CAPTION ||
                    377:       elType.ElTypeNum == HTML_EL_rb ||
                    378:       elType.ElTypeNum == HTML_EL_rt ||
                    379:       (isInline &&  !TtaIsLeaf (elType) &&
                    380:        elType.ElTypeNum != HTML_EL_Text_Area))
                    381:     /* It's an element that is supposed to contain at least a Basic_Elem.
                    382:        If it is empty, insert a Basic_Elem to allow the user to put the
                    383:        selection within this element */
                    384:     /* Don't do it for a Text_Area, as an Inserted_Text element has to be
                    385:        created (see below) */
                    386:     {
                    387:       child = TtaGetFirstChild (el);
                    388:       if (child == NULL)
                    389:         /* it's an empty inline element */
                    390:         /* insert a Basic_Elem element in the element */
                    391:         {
                    392:           newElType.ElTypeNum = HTML_EL_Basic_Elem;
                    393:           child = TtaNewTree (doc, newElType, "");
                    394:           TtaInsertFirstChild (&child, el, doc);
                    395:         }
                    396:     }
                    397:   if (!isInline)
                    398:     /* It's a block-level element. Is it within a character-level element? */
                    399:     if (elType.ElTypeNum != HTML_EL_Comment_ &&
1.138     vatton    400:         elType.ElTypeNum != HTML_EL_ASP_element &&
1.129     vatton    401:         elType.ElTypeNum != HTML_EL_XMLPI)
                    402:       BlockInCharLevelElem (el);
                    403: 
1.135     vatton    404:   typenum = elType.ElTypeNum;
                    405:   switch (typenum)
1.129     vatton    406:     {
1.145   ! vatton    407:     case HTML_EL_HTML:
        !           408:       CheckNamespace (el, doc);
        !           409:       break;
        !           410: 
1.134     vatton    411:     case HTML_EL_PICTURE_UNIT:
                    412:       /* Check the mandatory SRC attribute */
                    413:       CheckMandatoryAttribute (el, doc, HTML_ATTR_SRC);
                    414:       break;
                    415: 
1.129     vatton    416:     case HTML_EL_Object:       /* it's an object */
                    417:       data = NULL;
                    418:       isImage = FALSE;
                    419:       /* is there a type attribute on the object element? */
                    420:       attrType.AttrSSchema = elType.ElSSchema;
                    421:       attrType.AttrTypeNum = HTML_ATTR_Object_type;
                    422:       attr = TtaGetAttribute (el, attrType);
                    423:       if (attr)
                    424:         /* there is a type attribute. Get its value to see if the object
                    425:            represents an image */
                    426:         {
                    427:           length = TtaGetTextAttributeLength (attr);
                    428:           if (length > 0)
                    429:             {
                    430:               name1 = (char *)TtaGetMemory (length + 1);
                    431:               TtaGiveTextAttributeValue (attr, name1, &length);
                    432:               if (!strcmp (name1, AM_MATHML_MIME_TYPE) ||
                    433:                   !strcmp (name1, "application/postscript") ||
                    434:                   !strcmp (name1, "image/x-bitmap") ||
                    435:                   !strcmp (name1, "image/x-xpixmap") ||
                    436:                   !strcmp (name1, "image/gif") ||
                    437:                   !strcmp (name1, "image/jpeg") ||
                    438:                   !strcmp (name1, "image/png") ||
                    439:                   !strcmp (name1, "image/svg") ||
                    440:                   !strcmp (name1, AM_SVG_MIME_TYPE) ||
                    441:                   !strcmp (name1, AM_XHTML_MIME_TYPE) ||
                    442:                   !strcmp (name1, "text/html") ||
                    443:                   !strcmp (name1, "text/htm") ||
                    444:                   !strcmp (name1, AM_GENERIC_XML_MIME_TYPE))
                    445:                 isImage = TRUE;
                    446:               TtaFreeMemory (name1);
                    447:             }
                    448:         }
                    449: 
                    450:       attrType.AttrTypeNum = HTML_ATTR_data;
                    451:       attr = TtaGetAttribute (el, attrType);
                    452:       if (attr)
                    453:         /* the object has a data attribute */
                    454:         {
                    455:           length = TtaGetTextAttributeLength (attr);
                    456:           if (length > 0)
                    457:             {
                    458:               data = (char *)TtaGetMemory (length + 1);
                    459:               TtaGiveTextAttributeValue (attr, data, &length);
1.139     quint     460:               if (!isImage && length >= 5)
                    461:                 if (!strcmp (&data[length-4], ".mml") ||
                    462:                     !strcmp (&data[length-4], ".gif") ||
                    463:                     !strcmp (&data[length-4], ".jpg") ||
                    464:                     !strcmp (&data[length-5], ".jpeg") ||
                    465:                     !strcmp (&data[length-4], ".png") ||
                    466:                     !strcmp (&data[length-4], ".svg") ||
                    467:                     !strcmp (&data[length-5], ".svgz") ||
                    468:                     !strcmp (&data[length-4], ".htm") ||
                    469:                     !strcmp (&data[length-5], ".html") ||
                    470:                     !strcmp (&data[length-4], ".xml"))
1.129     vatton    471:                   isImage = TRUE;
                    472:             }
                    473:         }
1.140     vatton    474:       else
                    475:         {
                    476:           attrType.AttrTypeNum = HTML_ATTR_classid;
                    477:           attr = TtaGetAttribute (el, attrType);
                    478:           if (attr)
                    479:             /* the object has a data attribute */
                    480:             {
                    481:               length = TtaGetTextAttributeLength (attr);
                    482:               if (length > 0)
                    483:                 {
                    484:                   data = (char *)TtaGetMemory (length + 1);
                    485:                   TtaGiveTextAttributeValue (attr, data, &length);
                    486:                   if (!isImage && length >= 5)
                    487:                     if (!strcmp (&data[length-4], ".mml") ||
                    488:                         !strcmp (&data[length-4], ".gif") ||
                    489:                         !strcmp (&data[length-4], ".jpg") ||
                    490:                         !strcmp (&data[length-5], ".jpeg") ||
                    491:                         !strcmp (&data[length-4], ".png") ||
                    492:                         !strcmp (&data[length-4], ".svg") ||
                    493:                         !strcmp (&data[length-5], ".svgz") ||
                    494:                         !strcmp (&data[length-4], ".htm") ||
                    495:                         !strcmp (&data[length-5], ".html") ||
                    496:                         !strcmp (&data[length-4], ".xml"))
                    497:                       isImage = TRUE;
                    498:                 }
                    499:             }
                    500:         }
1.129     vatton    501:       picture = NULL;     /* no PICTURE element yet */
                    502:       child = TtaGetFirstChild (el);
                    503:       if (isImage)
                    504:         {
                    505:           /* the object represents an image. We need a PICTURE element as
                    506:              child of the object to hold the image */
                    507:           elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    508:           picture = TtaNewTree (doc, elType, "");
                    509:           if (child)
                    510:             TtaInsertSibling (picture, child, TRUE, doc);
                    511:           else
                    512:             TtaInsertFirstChild (&picture, el, doc);
                    513:           /* copy attribute data of the object into the SRC attribute of
                    514:              the PICTURE element */
                    515:           if (data)
                    516:             /* the object has a data attribute */
                    517:             {
1.134     vatton    518:               // remove extra spaces
                    519:               clean = FALSE;
                    520:               while (length > 0 && data[length-1] == SPACE)
                    521:                 {
                    522:                   data[length-1] = EOS;
                    523:                   length--;
                    524:                   clean = TRUE;
                    525:                 }
                    526:               if (clean)
                    527:                 TtaSetAttributeText (attr, data, el, doc);
                    528:               // copy the attribute in the picture element
1.129     vatton    529:               attrType.AttrTypeNum = HTML_ATTR_SRC;
                    530:               attr = TtaGetAttribute (picture, attrType);
                    531:               if (attr == NULL)
                    532:                 {
                    533:                   attr = TtaNewAttribute (attrType);
                    534:                   TtaAttachAttribute (picture, attr, doc);
1.134     vatton    535: 
1.129     vatton    536:                 }
                    537:               TtaSetAttributeText (attr, data, picture, doc);
1.134     vatton    538:               }
1.129     vatton    539:           attrType.AttrTypeNum = HTML_ATTR_Height_;
                    540:           attr = TtaGetAttribute (el, attrType);
                    541:           if (attr)
                    542:             /* the Object has a height attribute. Applies it to the
                    543:                picture element */
                    544:             {
                    545:               length = TtaGetTextAttributeLength (attr);
                    546:               if (length > 0)
                    547:                 {
                    548:                   text = (char *)TtaGetMemory (length + 1);
                    549:                   TtaGiveTextAttributeValue (attr, text, &length);
                    550:                   /* create the corresponding attribute IntHeightPercent or */
                    551:                   /* IntHeightPxl */
                    552:                   CreateAttrHeightPercentPxl (text, el, doc, -1);
                    553:                   TtaFreeMemory (text);
                    554:                 }
                    555:             }
                    556:           attrType.AttrTypeNum = HTML_ATTR_Width__;
                    557:           attr = TtaGetAttribute (el, attrType);
                    558:           if (attr)
                    559:             /* the Object has a width attribute. Applies it to the
                    560:                picture element */
                    561:             {
                    562:               length = TtaGetTextAttributeLength (attr);
                    563:               if (length > 0)
                    564:                 {
                    565:                   text = (char *)TtaGetMemory (length + 1);
                    566:                   TtaGiveTextAttributeValue (attr, text, &length);
                    567:                   /* create the corresponding attribute IntWidthPercent or */
                    568:                   /* IntWidthPxl */
                    569:                   CreateAttrWidthPercentPxl (text, el, doc, -1);
                    570:                   TtaFreeMemory (text);
                    571:                 }
                    572:             }
                    573:         }
                    574: 
                    575:       /* is the Object_Content element already created ? */
                    576:       if (child)
                    577:         /* the object element has at least 1 child element */
                    578:         {
1.139     quint     579:           /* put an attribute NoObjects on the Object element: this attribute
                    580:              will be removed when and if the actual object is loaded (see
                    581:              module HTMLimage.c */
                    582:           attrType.AttrTypeNum = HTML_ATTR_NoObjects;
                    583:           attr = TtaGetAttribute (el, attrType);
                    584:           if (!attr)
                    585:             {
                    586:               attr = TtaNewAttribute (attrType);
                    587:               TtaSetAttributeValue (attr, 1, el, doc);
                    588:               TtaAttachAttribute (el, attr, doc);
                    589:             }
                    590: 
1.129     vatton    591:           content = NULL;
                    592:           desc = child;
                    593:           elType = TtaGetElementType (desc);
                    594:           if (elType.ElTypeNum != HTML_EL_Object_Content)
                    595:             {
                    596:               TtaNextSibling(&desc);
                    597:               if (desc)
                    598:                 elType = TtaGetElementType (desc);
                    599:             }
                    600:           /* is it the Object_Content element ? */
                    601:           if (elType.ElTypeNum == HTML_EL_Object_Content)
                    602:             content = desc;
                    603:           else
                    604:             {
                    605:               /* create an Object_Content element */
                    606:               elType.ElTypeNum = HTML_EL_Object_Content;
                    607:               content = TtaNewElement (doc, elType);
                    608:               if (picture)
                    609:                 TtaInsertSibling (content, picture, FALSE, doc);
                    610:               else
                    611:                 TtaInsertSibling (content, child, TRUE, doc);
                    612:               /* move previous existing children into Object_Content */
                    613:               child = TtaGetLastChild(el);
                    614:               while (child != content)
                    615:                 {
                    616:                   TtaRemoveTree (child, doc);
                    617:                   TtaInsertFirstChild (&child, content, doc);
                    618:                   child = TtaGetLastChild(el);
                    619:                 }
                    620:             }
                    621:         }
1.134     vatton    622:       TtaFreeMemory (data);
                    623:       break;
                    624: 
1.135     vatton    625:     case HTML_EL_Image_Input:
1.134     vatton    626:     case HTML_EL_IMG:
                    627:       /* Check the mandatory ALT attribute */
                    628:       CheckMandatoryAttribute (el, doc, HTML_ATTR_ALT);
                    629:       /* Check the mandatory SRC attribute */
                    630:       CheckMandatoryAttribute (el, doc, HTML_ATTR_SRC);
                    631:       /* We need a PICTURE element as child to hold the image */
                    632:       picture = NULL;
1.137     quint     633:       for (child = TtaGetFirstChild (el); child && !picture;
                    634:            TtaNextSibling (&child))
1.134     vatton    635:         {
1.137     quint     636:           childType = TtaGetElementType (child);
                    637:           if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT &&
                    638:               childType.ElSSchema == elType.ElSSchema)
1.134     vatton    639:             // the picture is already created
                    640:             picture = child;
                    641:         }
                    642:       if (picture == NULL)
                    643:         {
1.137     quint     644:           childType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    645:           picture = TtaNewTree (doc, childType, "");
1.134     vatton    646:           if (child)
                    647:             TtaInsertSibling (picture, child, TRUE, doc);
                    648:           else
                    649:             TtaInsertFirstChild (&picture, el, doc);
                    650:         }
                    651:       attrType.AttrSSchema = elType.ElSSchema;
                    652:       attrType.AttrTypeNum = HTML_ATTR_SRC;
                    653:       attr = TtaGetAttribute (el, attrType);
                    654:       if (attr)
                    655:         /* the img has a src attribute */
                    656:         {
                    657:           length = TtaGetTextAttributeLength (attr);
                    658:           data = (char *)TtaGetMemory (length + 1);
                    659:           TtaGiveTextAttributeValue (attr, data, &length);
                    660:           if (data)
                    661:             {
                    662:               // remove extra spaces
                    663:               clean = FALSE;
                    664:               while (length > 0 && data[length-1] == SPACE)
                    665:                 {
                    666:                   data[length-1] = EOS;
                    667:                   length--;
                    668:                   clean = TRUE;
                    669:                 }
                    670:               if (clean)
                    671:                 TtaSetAttributeText (attr, data, el, doc);
                    672:               // copy the attribute in the picture element
                    673:               attr = TtaGetAttribute (picture, attrType);
                    674:               if (attr == NULL)
                    675:                 {
                    676:                   attr = TtaNewAttribute (attrType);
                    677:                   TtaAttachAttribute (picture, attr, doc);
                    678:                 }
                    679:               TtaSetAttributeText (attr, data, picture, doc);
                    680:               TtaFreeMemory (data);
                    681:             }
                    682:         }
1.135     vatton    683:       if (typenum == HTML_EL_IMG)
1.134     vatton    684:         {
1.135     vatton    685:           attrType.AttrTypeNum = HTML_ATTR_Height_;
                    686:           attr = TtaGetAttribute (el, attrType);
                    687:           if (attr)
                    688:             /* the img has a height attribute. Applies it to the
                    689:                picture element */
1.134     vatton    690:             {
1.135     vatton    691:               length = TtaGetTextAttributeLength (attr);
                    692:               if (length > 0)
                    693:                 {
                    694:                   text = (char *)TtaGetMemory (length + 1);
                    695:                   TtaGiveTextAttributeValue (attr, text, &length);
                    696:                   /* create the corresponding attribute IntHeightPercent or */
                    697:                   /* IntHeightPxl */
                    698:                   CreateAttrHeightPercentPxl (text, el, doc, -1);
                    699:                   TtaFreeMemory (text);
                    700:                 }
1.134     vatton    701:             }
1.135     vatton    702:           attrType.AttrTypeNum = HTML_ATTR_Width__;
                    703:           attr = TtaGetAttribute (el, attrType);
                    704:           if (attr)
                    705:             /* the img has a width attribute. Applies it to the
                    706:                picture element */
1.134     vatton    707:             {
1.135     vatton    708:               length = TtaGetTextAttributeLength (attr);
                    709:               if (length > 0)
                    710:                 {
                    711:                   text = (char *)TtaGetMemory (length + 1);
                    712:                   TtaGiveTextAttributeValue (attr, text, &length);
                    713:                   /* create the corresponding attribute IntWidthPercent or */
                    714:                   /* IntWidthPxl */
                    715:                   CreateAttrWidthPercentPxl (text, el, doc, -1);
                    716:                   TtaFreeMemory (text);
                    717:                 }
1.134     vatton    718:             }
1.135     vatton    719:          }
1.129     vatton    720:       break;
                    721: 
                    722:     case HTML_EL_Parameter:
                    723:       /* Check the mandatory name attribute */
                    724:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Param_name);
                    725:       break;
                    726: 
1.142     quint     727: 
1.129     vatton    728:     case HTML_EL_IFRAME:         /* it's an iframe */
                    729:       child = TtaGetFirstChild (el);
                    730:       /* is the Iframe_Content element already created ? */
                    731:       if (child)
                    732:         /* the iframe element has at least 1 child element */
                    733:         {
                    734:           content = NULL;
                    735:           desc = child;
                    736:           elType = TtaGetElementType (desc);
                    737:           if (elType.ElTypeNum != HTML_EL_Iframe_Content)
                    738:             {
                    739:               TtaNextSibling(&desc);
                    740:               if (desc)
                    741:                 elType = TtaGetElementType (desc);
                    742:             }
                    743:           /* is it the Iframe_Content element ? */
                    744:           if (elType.ElTypeNum == HTML_EL_Iframe_Content)
                    745:             content = desc;
                    746:           else
                    747:             {
                    748:               /* create an Iframe_Content element */
                    749:               elType.ElTypeNum = HTML_EL_Iframe_Content;
                    750:               content = TtaNewElement (doc, elType);
                    751:               TtaInsertSibling (content, child, TRUE, doc);
                    752:               /* move previous existing children into Iframe_Content */
                    753:               child = TtaGetLastChild(el);
                    754:               while (child != content)
                    755:                 {
                    756:                   TtaRemoveTree (child, doc);
                    757:                   TtaInsertFirstChild (&child, content, doc);
                    758:                   child = TtaGetLastChild(el);
                    759:                 }
                    760:             }
                    761:         }
                    762:       break;
                    763: 
                    764:     case HTML_EL_Unnumbered_List:
                    765:     case HTML_EL_Numbered_List:
                    766:     case HTML_EL_Menu:
                    767:     case HTML_EL_Directory:
                    768:       /* It's a List element. It should only have List_Item children.
                    769:          If it has List element chidren, move these List elements
                    770:          within their previous List_Item sibling.  This is to fix
                    771:          a bug in document generated by Mozilla. */
                    772:       prev = NULL;
                    773:       next = NULL;
                    774:       child = TtaGetFirstChild (el);
                    775:       while (child != NULL)
                    776:         {
                    777:           next = child;
                    778:           TtaNextSibling (&next);
                    779:           elType = TtaGetElementType (child);
                    780:           if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
                    781:               elType.ElTypeNum == HTML_EL_Numbered_List ||
                    782:               elType.ElTypeNum == HTML_EL_Menu ||
                    783:               elType.ElTypeNum == HTML_EL_Directory)
                    784:             /* this list element is a child of another list element */
                    785:             if (prev)
                    786:               {
                    787:                 elType = TtaGetElementType (prev);
                    788:                 if (elType.ElTypeNum == HTML_EL_List_Item)
                    789:                   {
                    790:                     /* get the last child of the previous List_Item */
                    791:                     desc = TtaGetFirstChild (prev);
                    792:                     last = NULL;
                    793:                     while (desc)
                    794:                       {
                    795:                         last = desc;
                    796:                         TtaNextSibling (&desc);
                    797:                       }
                    798:                     /* move the list element after the last child of the
                    799:                        previous List_Item */
                    800:                     TtaRemoveTree (child, doc);
                    801:                     if (last)
                    802:                       TtaInsertSibling (child, last, FALSE, doc);
                    803:                     else
                    804:                       TtaInsertFirstChild (&child, prev, doc);
                    805:                     child = prev;
                    806:                   }
                    807:               }
                    808:           prev = child;
                    809:           child = next;
                    810:         }
                    811:       break;
1.6       cvs       812:        
1.129     vatton    813:     case HTML_EL_FRAMESET:
                    814:       /* The FRAMESET element is now complete.  Gather all its FRAMESET
                    815:          and FRAME children and wrap them up in a Frames element */
                    816:       elFrames = NULL; lastFrame = NULL;
                    817:       lastChild = NULL;
                    818:       child = TtaGetFirstChild (el);
                    819:       while (child != NULL)
                    820:         {
                    821:           next = child;
                    822:           TtaNextSibling (&next);
                    823:           elType = TtaGetElementType (child);
                    824:           if (elType.ElTypeNum == HTML_EL_FRAMESET ||
                    825:               elType.ElTypeNum == HTML_EL_FRAME ||
1.138     vatton    826:               elType.ElTypeNum == HTML_EL_Comment_||
                    827:               elType.ElTypeNum == HTML_EL_ASP_element)
1.129     vatton    828:             {
                    829:               /* create the Frames element if it does not exist */
                    830:               if (elFrames == NULL)
                    831:                 {
                    832:                   newElType.ElSSchema = htmlSchema;
                    833:                   newElType.ElTypeNum = HTML_EL_Frames;
                    834:                   elFrames = TtaNewElement (doc, newElType);
                    835:                   if (DocumentMeta[doc]->xmlformat)
                    836:                     XmlSetElemLineNumber (elFrames);
                    837:                   else
                    838:                     SetHtmlElemLineNumber (elFrames);
                    839:                   TtaInsertSibling (elFrames, child, TRUE, doc);
                    840:                 }
                    841:               /* move the element as the last child of the Frames element */
                    842:               TtaRemoveTree (child, doc);
                    843:               if (lastFrame == NULL)
                    844:                 TtaInsertFirstChild (&child, elFrames, doc);
                    845:               else
                    846:                 TtaInsertSibling (child, lastFrame, FALSE, doc);
                    847:               lastFrame = child;
                    848:             }
                    849:           child = next;
                    850:         }
                    851:       break;
1.6       cvs       852:        
1.129     vatton    853:     case HTML_EL_Form:
                    854:       /* Check the mandatory action attribute */
                    855:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Script_URL);
                    856:       break;
                    857: 
                    858:     case HTML_EL_Input:        /* it's an INPUT without any TYPE attribute */
                    859:       /* Create a child of type Text_Input */
                    860:       elType.ElTypeNum = HTML_EL_Text_Input;
                    861:       child = TtaNewTree (doc, elType, "");
                    862:       if (DocumentMeta[doc]->xmlformat)
                    863:         XmlSetElemLineNumber (child);
                    864:       else
                    865:         SetHtmlElemLineNumber (child);
                    866:       TtaInsertFirstChild (&child, el, doc);
                    867:       /* now, process it like a Text_Input element */
                    868: 
                    869:     case HTML_EL_Text_Input:
                    870:     case HTML_EL_Password_Input:
                    871:     case HTML_EL_File_Input:
                    872:       /* set default size */
                    873:       attrType.AttrSSchema = elType.ElSSchema;
                    874:       attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                    875:       attr = TtaGetAttribute (el, attrType);
                    876:       if (!attr)
                    877:         CreateAttrIntAreaSize (20, el, doc);
                    878:       /* get element Inserted_Text */
                    879:       child = TtaGetFirstChild (el);
                    880:       if (child != NULL)
                    881:         {
                    882:           attrType.AttrTypeNum = HTML_ATTR_Value_;
                    883:           attr = TtaGetAttribute (el, attrType);
                    884:           if (attr != NULL)
                    885:             {
                    886:               /* copy the value of attribute "value" into the first text
                    887:                  leaf of element */
                    888:               length = TtaGetTextAttributeLength (attr);
                    889:               if (length > 0)
                    890:                 {
                    891:                   /* get the text leaf */
                    892:                   leaf = TtaGetFirstChild (child);
                    893:                   if (leaf != NULL)
                    894:                     {
                    895:                       childType = TtaGetElementType (leaf);
                    896:                       if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    897:                         {
                    898:                           /* copy attribute value into the text leaf */
                    899:                           text = (char *)TtaGetMemory (length + 1);
                    900:                           TtaGiveTextAttributeValue (attr, text, &length);
                    901:                           TtaSetTextContent (leaf, (unsigned char *)text, 
                    902:                                              TtaGetDefaultLanguage (), doc);
                    903:                           TtaFreeMemory (text);
                    904:                         }
                    905:                     }
                    906:                 }
                    907:             }
                    908:         }
                    909:       break;
1.6       cvs       910:        
1.129     vatton    911:     case HTML_EL_META:
                    912:       ParseCharsetAndContentType (el, doc);
                    913:       /* Check the mandatory CONTENT attribute */
                    914:       CheckMandatoryAttribute (el, doc, HTML_ATTR_meta_content);
1.126     tollenae  915: #ifdef TEMPLATES
1.129     vatton    916:       ParseTemplateMeta (el, doc);
1.126     tollenae  917: #endif /* TEMPLATES */
1.129     vatton    918:       break;
                    919: 
                    920:     case HTML_EL_BASE:
                    921:       /* Check the mandatory HREF attribute */
                    922:       CheckMandatoryAttribute (el, doc, HTML_ATTR_HREF_);
                    923:       break;
                    924: 
                    925:     case HTML_EL_BaseFont:
                    926:       /* Check the mandatory size attribute */
                    927:       CheckMandatoryAttribute (el, doc, HTML_ATTR_BaseFontSize);
                    928:       break;
                    929: 
                    930:     case HTML_EL_BDO:
                    931:       /* Check the mandatory DIR attribute */
                    932:       CheckMandatoryAttribute (el, doc, HTML_ATTR_dir);
                    933:       break;
1.114     vatton    934: 
1.129     vatton    935:     case HTML_EL_STYLE_:       /* it's a STYLE element */
                    936:     case HTML_EL_SCRIPT_:      /* it's a SCRIPT element */
                    937:     case HTML_EL_Preformatted: /* it's a PRE */
1.131     quint     938:       if (elType.ElTypeNum == HTML_EL_SCRIPT_)
                    939:         if (DocumentMeta[doc]->xmlformat)
                    940:           SetParsingScript (FALSE);
                    941:         else
                    942:           SetHtmlParsingScript (FALSE);
                    943: 
1.129     vatton    944:       /* if the last line of the Preformatted is empty, remove it */
                    945:       leaf = XmlLastLeafInElement (el);
                    946:       if (leaf != NULL)
                    947:         {
                    948:           elType = TtaGetElementType (leaf);
                    949:           if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    950:             /* the last leaf is a TEXT element */
                    951:             {
                    952:               length = TtaGetTextLength (leaf);
                    953:               if (length > 0)
                    954:                 {
                    955:                   TtaGiveSubString (leaf, (unsigned char *)lastChar, length, 1);
                    956:                   if (lastChar[0] == EOL)
                    957:                     /* last character is new line, delete it */
                    958:                     {
                    959:                       if (length == 1)
                    960:                         /* empty TEXT element */
                    961:                         TtaDeleteTree (leaf, doc);
                    962:                       else
                    963:                         /* remove the last character */
                    964:                         TtaDeleteTextContent (leaf, length, 1, doc);
                    965:                     }
                    966:                 }
                    967:             }
                    968:         }
                    969: 
                    970:       if (elType.ElTypeNum == HTML_EL_STYLE_)
                    971:         /* Check the mandatory TYPE attribute */
                    972:         CheckMandatoryAttribute (el, doc, HTML_ATTR_Notation);
                    973:       else if (elType.ElTypeNum == HTML_EL_SCRIPT_)
                    974:         /* Check the mandatory TYPE attribute */
                    975:         CheckMandatoryAttribute (el, doc, HTML_ATTR_content_type);
                    976: 
                    977:       if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                    978:         {
                    979:           if (IsXmlParsingCSS ())
                    980:             {
                    981:               text = GetStyleContents (el);
                    982:               if (text)
                    983:                 {
                    984:                   ReadCSSRules (doc, NULL, text, NULL,
                    985:                                 TtaGetElementLineNumber (el), FALSE, el);
                    986:                   TtaFreeMemory (text);
                    987:                 }
                    988:               SetXmlParsingCSS (FALSE);
                    989:             }
                    990:         }
                    991:       else
                    992:         {
                    993:           if (IsHtmlParsingCSS ())
                    994:             {
                    995:               text = GetStyleContents (el);
                    996:               if (text)
                    997:                 {
                    998:                   ReadCSSRules (doc, NULL, text, NULL,
                    999:                                 TtaGetElementLineNumber (el), FALSE, el);
                   1000:                   TtaFreeMemory (text);
                   1001:                 }
                   1002:               SetHtmlParsingCSS (FALSE);
                   1003:             }
                   1004:         }
                   1005:       /* and continue as if it were a Preformatted or a Script */
                   1006:       break;
1.6       cvs      1007:        
1.129     vatton   1008:     case HTML_EL_Text_Area:    /* it's a Text_Area */
                   1009:       if (DocumentMeta[doc]->xmlformat)
                   1010:         SetParsingTextArea (FALSE);
                   1011:       else
                   1012:         SetHtmlParsingTextArea (FALSE);
                   1013:       child = TtaGetFirstChild (el);
                   1014:       if (child == NULL)
                   1015:         /* it's an empty Text_Area */
                   1016:         /* insert a Inserted_Text element and a child Basic_Elem in the
                   1017:            Text_Area element */
                   1018:         {
                   1019:           newElType.ElTypeNum = HTML_EL_Inserted_Text;
                   1020:           child = TtaNewTree (doc, newElType, "");
                   1021:           TtaInsertFirstChild (&child, el, doc);
                   1022:         }
                   1023:       else
                   1024:         {
                   1025:           /* save the text into Default_Value attribute */
                   1026:           attrType.AttrSSchema = htmlSchema;
                   1027:           attrType.AttrTypeNum = HTML_ATTR_Default_Value;
                   1028:           if (TtaGetAttribute (el, attrType) == NULL)
                   1029:             /* attribute Default_Value is missing */
                   1030:             {
                   1031:               desc = TtaGetFirstChild (child);
                   1032:               if (desc)
                   1033:                 {
                   1034:                   length = TtaGetTextLength (desc);
                   1035:                   if (length > 0)
                   1036:                     {
                   1037:                       length++;
                   1038:                       attr = TtaNewAttribute (attrType);
                   1039:                       TtaAttachAttribute (el, attr, doc);
                   1040:                       text = (char *)TtaGetMemory (length);
                   1041:                       TtaGiveTextContent (desc, (unsigned char *)text, &length, &lang);
                   1042:                       TtaSetAttributeText (attr, text, el, doc);
                   1043:                       TtaFreeMemory (text);
                   1044:                     }
                   1045:                 }
                   1046:             }
                   1047:         }
                   1048:       /* Check the mandatory rows attribute */
                   1049:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Rows);
                   1050:       /* Check the mandatory columns attribute */
                   1051:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Columns);
                   1052:       /* Add default rows and columns attributes */
                   1053:       AddRowsColumns (el, doc);
                   1054:       break;
                   1055: 
                   1056:     case HTML_EL_Radio_Input:
                   1057:     case HTML_EL_Checkbox_Input:
                   1058:       /* put an attribute Checked if it is missing */
                   1059:       attrType.AttrSSchema = htmlSchema;
                   1060:       attrType.AttrTypeNum = HTML_ATTR_Checked;
                   1061:       if (TtaGetAttribute (el, attrType) == NULL)
                   1062:         /* attribute Checked is missing */
                   1063:         {
                   1064:           attr = TtaNewAttribute (attrType);
                   1065:           TtaAttachAttribute (el, attr, doc);
                   1066:           TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
                   1067:         }
                   1068:       break;
1.6       cvs      1069:        
1.129     vatton   1070:     case HTML_EL_Option_Menu:
                   1071:       /* Check that at least one option has a SELECTED attribute */
                   1072:       OnlyOneOptionSelected (el, doc, TRUE);
                   1073:       break;
                   1074: 
                   1075:     case HTML_EL_OptGroup:
                   1076:       /* Check the mandatory label attribute */
                   1077:       CheckMandatoryAttribute (el, doc, HTML_ATTR_label);
                   1078:       break;
                   1079: 
                   1080:     case HTML_EL_MAP:
                   1081:     case HTML_EL_map:
                   1082:       /* Check the mandatory attributes */
                   1083:       if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                   1084:         /* it's XHTML. Check attribute id */
                   1085:         CheckMandatoryAttribute (el, doc, HTML_ATTR_ID);
                   1086:       else
                   1087:         /* it's a HTML document. Check attribute name */
                   1088:         CheckMandatoryAttribute (el, doc, HTML_ATTR_NAME);
                   1089:       break;
                   1090: 
                   1091:     case HTML_EL_AREA:
                   1092:       /* Check the mandatory alt attribute */
                   1093:       CheckMandatoryAttribute (el, doc, HTML_ATTR_ALT);
                   1094:       break;
1.6       cvs      1095:        
1.129     vatton   1096:     case HTML_EL_LINK:
                   1097:       CheckCSSLink (el, doc, htmlSchema);
                   1098:       break;
1.6       cvs      1099:        
1.129     vatton   1100:     case HTML_EL_Data_cell:
                   1101:     case HTML_EL_Heading_cell:
                   1102:     case HTML_EL_List_Item:
                   1103:     case HTML_EL_Definition:
                   1104:       /* insert a pseudo paragraph into empty cells or list items */
                   1105:       child = TtaGetFirstChild (el);
                   1106:       if (child == NULL)
                   1107:         {
                   1108:           elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
                   1109:           child = TtaNewTree (doc, elType, "");
                   1110:           if (child != NULL)
                   1111:             TtaInsertFirstChild (&child, el, doc);
                   1112:         }
                   1113:       if (elType.ElTypeNum == HTML_EL_Data_cell ||
                   1114:           elType.ElTypeNum == HTML_EL_Heading_cell)
                   1115:         /* detect whether we are parsing a whole table or just a cell */
                   1116:         {
                   1117:           if (DocumentMeta[doc]->xmlformat)
                   1118:             {
                   1119:               if (IsWithinXmlTable ())
                   1120:                 NewCell (el, doc, FALSE, FALSE, FALSE);
                   1121:             }
                   1122:           else
                   1123:             {
                   1124:               if (IsWithinHtmlTable ())
                   1125:                 NewCell (el, doc, FALSE, FALSE, FALSE);
                   1126:             }
                   1127:         }
                   1128:       break;
1.6       cvs      1129:        
1.129     vatton   1130:     case HTML_EL_Table_:
                   1131:       CheckTable (el, doc);
                   1132:       SubWithinTable ();
                   1133:       break;
1.6       cvs      1134:        
1.129     vatton   1135:     case HTML_EL_TITLE:
                   1136:       /* show the TITLE in the main window */
                   1137:       UpdateTitle (el, doc);
                   1138:       break;
                   1139: 
                   1140:     case HTML_EL_rbc:
                   1141:       /* an rbc element has been read. Its parent should be a complex_ruby.
                   1142:          Change the type of the parent, as simple_ruby are created by
                   1143:          default */
                   1144:       parent = TtaGetParent (el);
                   1145:       if (parent)
                   1146:         {
                   1147:           newElType = TtaGetElementType (parent);
                   1148:           if (newElType.ElSSchema == elType.ElSSchema &&
                   1149:               newElType.ElTypeNum == HTML_EL_simple_ruby)
                   1150:             TtaChangeElementType (parent, HTML_EL_complex_ruby);
                   1151:         }
                   1152:       break;
1.41      cvs      1153: 
1.129     vatton   1154:     case HTML_EL_rtc1:
                   1155:       /* an rtc element has been parsed. If it has already a rtc1 sibling,
                   1156:          change its type to rtc2 */
                   1157:       prev = el;
                   1158:       do
                   1159:         {
                   1160:           TtaPreviousSibling(&prev);
                   1161:           if (prev)
                   1162:             {
                   1163:               newElType = TtaGetElementType (prev);
                   1164:               if (newElType.ElSSchema == elType.ElSSchema &&
                   1165:                   newElType.ElTypeNum == HTML_EL_rtc1)
                   1166:                 {
                   1167:                   TtaChangeElementType (el, HTML_EL_rtc2);
                   1168:                   prev = NULL;
                   1169:                 }
                   1170:             }
                   1171:         }
                   1172:       while (prev);
                   1173:       break;
                   1174: 
1.142     quint    1175:     case HTML_EL_FIELDSET:       /* it's a fieldset */
1.129     vatton   1176:       childType.ElTypeNum = 0;
                   1177:       child = TtaGetFirstChild (el);
1.142     quint    1178:       if (!child)
                   1179:         /* empty fieldset. Create a legend and a Fieldset_Content */
                   1180:         {
                   1181:           elType.ElTypeNum = HTML_EL_LEGEND;
                   1182:           legend = TtaNewTree (doc, elType, "");
                   1183:           TtaInsertFirstChild (&legend, el, doc);
                   1184:           elType.ElTypeNum = HTML_EL_Fieldset_Content;
                   1185:           content = TtaNewTree (doc, elType, "");
                   1186:           TtaInsertSibling (content, legend, FALSE, doc);
                   1187:         }
                   1188:       else
                   1189:         /* is the legend element already created ? */
1.129     vatton   1190:         {
1.142     quint    1191:           legend = NULL;
                   1192:           desc = child;
                   1193:           elType = TtaGetElementType (desc);
                   1194:           while (desc && elType.ElTypeNum != HTML_EL_LEGEND)
                   1195:             {
                   1196:               TtaNextSibling(&desc);
                   1197:               if (desc)
                   1198:                 elType = TtaGetElementType (desc);
                   1199:             }
                   1200:           /* is it the legend element ? */
                   1201:           if (elType.ElTypeNum == HTML_EL_LEGEND)
                   1202:             legend = desc;
1.129     vatton   1203:           else
1.142     quint    1204:             {
                   1205:               /* create a legend element */
                   1206:               elType.ElTypeNum = HTML_EL_LEGEND;
                   1207:               legend = TtaNewTree (doc, elType, "");
                   1208:               TtaInsertFirstChild (&legend, el, doc);
                   1209:             }
                   1210:           
                   1211:           /* is the Fieldset_Content element already created ? */
                   1212:           content = NULL;
                   1213:           desc = child;
                   1214:           elType = TtaGetElementType (desc);
                   1215:           while (desc && elType.ElTypeNum != HTML_EL_Fieldset_Content)
                   1216:             {
                   1217:               TtaNextSibling(&desc);
                   1218:               if (desc)
                   1219:                 elType = TtaGetElementType (desc);
                   1220:             }
                   1221:           /* is it the Fieldset_Content element ? */
                   1222:           if (elType.ElTypeNum == HTML_EL_Fieldset_Content)
                   1223:             content = desc;
                   1224:           else
                   1225:             {
                   1226:               /* create a Fieldset_Content element */
                   1227:               elType.ElTypeNum = HTML_EL_Fieldset_Content;
                   1228:               content = TtaNewTree (doc, elType, "");
                   1229:               TtaInsertSibling (content, legend, FALSE, doc);
                   1230:               desc = TtaGetFirstChild (content);
                   1231:               /* move previous existing children into the Fieldset_Content */
                   1232:               child = TtaGetLastChild(el);
                   1233:               while (child != content)
                   1234:                 {
                   1235:                   elType = TtaGetElementType (child);
                   1236:                   TtaRemoveTree (child, doc);
                   1237:                   TtaInsertFirstChild (&child, content, doc);
                   1238:                   if (desc)
                   1239:                     {
                   1240:                       TtaDeleteTree (desc, doc);
                   1241:                       desc = NULL;
                   1242:                     }
                   1243:                   child = TtaGetLastChild(el);
                   1244:                 }
                   1245:             }
1.129     vatton   1246:         }
                   1247:       break;
                   1248: 
                   1249:     default:
                   1250:       break;
                   1251:     }
1.6       cvs      1252: }
1.1       cvs      1253: 
                   1254: /*----------------------------------------------------------------------
1.129     vatton   1255:   PutInContent    
                   1256:   Put the string ChrString in the leaf of current element.
1.30      cvs      1257:   ----------------------------------------------------------------------*/
1.39      cvs      1258: Element         PutInContent (char *ChrString, ParserData *context)
1.30      cvs      1259: 
                   1260: {
1.129     vatton   1261:   Element      el, child;
                   1262:   ElementType  elType;
                   1263:   int          length;
                   1264: 
                   1265:   el = NULL;
                   1266:   if (context->lastElement != NULL)
                   1267:     {
                   1268:       /* search first leaf of current element */
                   1269:       el = context->lastElement;
                   1270:       do
                   1271:         {
                   1272:           child = TtaGetFirstChild (el);
                   1273:           if (child != NULL)
                   1274:             el = child;
                   1275:         }
                   1276:       while (child != NULL);
                   1277:       elType = TtaGetElementType (el);
                   1278:       length = 0;
                   1279:       if (elType.ElTypeNum == 1)
                   1280:         length = TtaGetTextLength (el);
                   1281:       if (length == 0)
                   1282:         TtaSetTextContent (el, (unsigned char *)ChrString,
                   1283:                            context->language, context->doc);
                   1284:       else
                   1285:         TtaAppendTextContent (el, (unsigned char *)ChrString, context->doc);
                   1286:     }
                   1287:   return el;
1.30      cvs      1288: }
                   1289: 
                   1290: /*----------------------------------------------------------------------
1.93      vatton   1291:   UnknownXhtmlNameSpace
                   1292:   The element doesn't belong to a supported namespace
1.51      cvs      1293:   ----------------------------------------------------------------------*/
1.93      vatton   1294: void UnknownXhtmlNameSpace (ParserData *context, Element *unknownEl,
1.129     vatton   1295:                             char* content)
1.51      cvs      1296: {
1.129     vatton   1297:   ElementType     elType;
                   1298:   Element         elText;
1.51      cvs      1299: 
1.129     vatton   1300:   /* Create a new Invalid_element */
                   1301:   elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
                   1302:   elType.ElTypeNum = HTML_EL_XHTML_Unknown_namespace;
                   1303:   *unknownEl = TtaNewElement (context->doc, elType);
                   1304:   if (*unknownEl != NULL)
                   1305:     {
                   1306:       XmlSetElemLineNumber (*unknownEl);
                   1307:       InsertXmlElement (unknownEl);
                   1308:       context->lastElementClosed = TRUE;
                   1309:       elType.ElTypeNum = HTML_EL_TEXT_UNIT;
                   1310:       elText = TtaNewElement (context->doc, elType);
                   1311:       XmlSetElemLineNumber (elText);
                   1312:       TtaInsertFirstChild (&elText, *unknownEl, context->doc);
                   1313:       TtaSetTextContent (elText, (unsigned char *)content, context->language, context->doc);
                   1314:       TtaSetAccessRight (elText, ReadOnly, context->doc);
                   1315:     }
1.51      cvs      1316: }
                   1317: 
                   1318: /*----------------------------------------------------------------------
1.129     vatton   1319:   CreateHTMLAttribute
                   1320:   create an attribute of type attrType for the element el.
1.30      cvs      1321:   ----------------------------------------------------------------------*/
1.93      vatton   1322: void CreateHTMLAttribute (Element       el,
1.129     vatton   1323:                           AttributeType attrType,
                   1324:                           char*         text,
                   1325:                           ThotBool      isInvalid,
                   1326:                           Document      doc,
                   1327:                           Attribute    *lastAttribute,
                   1328:                           Element      *lastAttrElement)
1.30      cvs      1329: {
1.129     vatton   1330:   int         attrKind;
                   1331:   int         length;
                   1332:   char       *buffer;
                   1333:   Attribute   attr, oldAttr;
                   1334: 
                   1335:   if (attrType.AttrTypeNum != 0)
                   1336:     {
                   1337:       oldAttr = TtaGetAttribute (el, attrType);
                   1338:       if (oldAttr != NULL)
                   1339:         /* this attribute already exists */
                   1340:         attr = oldAttr;
                   1341:       else
                   1342:         /* create a new attribute and attach it to the element */
                   1343:         {
                   1344:           attr = TtaNewAttribute (attrType);
                   1345:           TtaAttachAttribute (el, attr, doc);
                   1346:         }
                   1347:       *lastAttribute = attr;
                   1348:       *lastAttrElement = el;
                   1349: 
                   1350:       TtaGiveAttributeType (attr, &attrType, &attrKind);
                   1351:       if (attrKind == 0)       /* enumerate */
                   1352:         TtaSetAttributeValue (attr, 1, el, doc);
                   1353: 
                   1354:       /* attribute BORDER without any value (ThotBool attribute) is */
                   1355:       /* considered as BORDER=1 */
                   1356:       if (attrType.AttrTypeNum == HTML_ATTR_Border)
                   1357:         TtaSetAttributeValue (attr, 1, el, doc);
                   1358: 
                   1359:       if (isInvalid)
                   1360:         /* Copy the name of the invalid attribute as the content */
                   1361:         /* of the Invalid_attribute attribute. */
                   1362:         {
                   1363:           length = strlen (text) + 2;
                   1364:           length += TtaGetTextAttributeLength (attr);
                   1365:           buffer = (char *)TtaGetMemory (length + 1);
                   1366:           TtaGiveTextAttributeValue (attr, buffer, &length);
                   1367:           strcat (buffer, " ");
                   1368:           strcat (buffer, text);
                   1369:           TtaSetAttributeText (attr, buffer, el, doc);
                   1370:           TtaFreeMemory (buffer);
                   1371:         }
                   1372:     }
1.30      cvs      1373: }
                   1374: 
                   1375: 
                   1376: /*----------------------------------------------------------------------
1.129     vatton   1377:   XhtmlTypeAttrValue 
                   1378:   Value val has been read for the HTML attribute TYPE.
                   1379:   Create a child for the current Thot element INPUT accordingly.
1.30      cvs      1380:   ----------------------------------------------------------------------*/
1.135     vatton   1381: static void XhtmlTypeAttrValue (char *val,
                   1382:                                 Attribute currentAttribute,
                   1383:                                 Element lastAttrElement,
                   1384:                                 ParserData *context, ThotBool isXML)
1.30      cvs      1385: {
                   1386:   ElementType     elType;
                   1387:   Element         newChild;
                   1388:   AttributeType   attrType;
                   1389:   Attribute       attr;
1.39      cvs      1390:   char            msgBuffer[MaxMsgLength];
1.135     vatton   1391:   int             value, nb;
1.30      cvs      1392:   ThotBool        level;
                   1393: 
1.91      quint    1394:   /* Look in the dummy section of the attribute value table */
1.30      cvs      1395:   attrType.AttrTypeNum = DummyAttribute;
1.100     gully    1396:   MapHTMLAttributeValue (val, &attrType, &value);
1.135     vatton   1397:   elType = TtaGetElementType (context->lastElement);
1.91      quint    1398:   if (value <= 0)
                   1399:     /* invalid value for the type attribute of an input element */
1.30      cvs      1400:     {
1.37      cvs      1401:       sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.135     vatton   1402:       if (isXML)
                   1403:         XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1404:       else
                   1405:         HTMLParseError (context->doc, msgBuffer, 0);
1.36      cvs      1406:       MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.129     vatton   1407:                         &level, context->doc);
1.37      cvs      1408:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs      1409:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
1.129     vatton   1410:                            context->doc, &currentAttribute, &lastAttrElement);
1.30      cvs      1411:     }
                   1412:   else
1.91      quint    1413:     /* value is the Thot type of the element to be created for this value of
                   1414:        the TYPE attribute */
1.30      cvs      1415:     {
                   1416:       if (elType.ElTypeNum != HTML_EL_Input)
1.129     vatton   1417:         {
                   1418:           sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.135     vatton   1419:           if (isXML)
                   1420:             XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1421:           else
                   1422:             HTMLParseError (context->doc, msgBuffer, 0);
1.129     vatton   1423:         }
1.30      cvs      1424:       else
1.129     vatton   1425:         {
                   1426:           elType.ElTypeNum = value;
                   1427:           newChild = TtaNewTree (context->doc, elType, "");
1.135     vatton   1428:           
                   1429:           nb = TtaGetElementLineNumber (context->lastElement);
                   1430:           TtaSetElementLineNumber (newChild, nb);
1.129     vatton   1431:           TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
1.135     vatton   1432:           /* add the attribute type */
                   1433:           attrType.AttrSSchema = elType.ElSSchema;
                   1434:           attrType.AttrTypeNum = HTML_ATTR_type;
                   1435:           attr = TtaGetAttribute (newChild, attrType);
                   1436:           if (attr == NULL)
1.129     vatton   1437:             {
                   1438:               attr = TtaNewAttribute (attrType);
                   1439:               TtaAttachAttribute (newChild, attr, context->doc);
                   1440:             }
                   1441:         }
1.30      cvs      1442:     }
                   1443: }
                   1444: 
                   1445: /*----------------------------------------------------------------------
1.129     vatton   1446:   CreateAttrWidthPercentPxl
                   1447:   an HTML attribute "width" has been created for a Table, an image,
                   1448:   an Object of a HR.
                   1449:   Create the corresponding attribute IntWidthPercent or IntWidthPxl.
                   1450:   oldWidth is -1 or the old image width.
1.30      cvs      1451:   ----------------------------------------------------------------------*/
1.58      vatton   1452: void CreateAttrWidthPercentPxl (char *buffer, Element el,
1.129     vatton   1453:                                 Document doc, int oldWidth)
1.30      cvs      1454: {
                   1455:   AttributeType   attrTypePxl, attrTypePercent;
                   1456:   Attribute       attrOld, attrNew;
                   1457:   int             length, val;
1.39      cvs      1458:   char            msgBuffer[MaxMsgLength];
1.133     vatton   1459:   ElementType      elType, childType;
1.79      quint    1460:   Element         origEl, child;
1.30      cvs      1461:   int             w, h;
1.133     vatton   1462:   ThotBool        isImage, isSVG = FALSE;
1.30      cvs      1463: 
1.132     vatton   1464:   if (buffer == NULL || buffer[0] == EOS)
                   1465:     return;
1.79      quint    1466:   origEl = el;
1.30      cvs      1467:   elType = TtaGetElementType (el);
                   1468:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1.129     vatton   1469:              elType.ElTypeNum == HTML_EL_Data_cell ||
                   1470:              elType.ElTypeNum == HTML_EL_Heading_cell ||
1.134     vatton   1471:              elType.ElTypeNum == HTML_EL_Object ||
1.135     vatton   1472:              elType.ElTypeNum == HTML_EL_IMG ||
                   1473:              elType.ElTypeNum == HTML_EL_Image_Input);
1.133     vatton   1474: 
1.79      quint    1475:   if (elType.ElTypeNum == HTML_EL_Object)
                   1476:     /* the width attribute is attached to an Object element */
                   1477:     {
                   1478:       child = TtaGetFirstChild (el);
                   1479:       if (child)
1.129     vatton   1480:         {
                   1481:           childType = TtaGetElementType (child);
                   1482:           if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1483:             /* the Object element is of type image. apply the width
                   1484:                attribute to the actual image element */
                   1485:             el = child;
1.133     vatton   1486: #ifdef _SVG
                   1487:           else
                   1488:             {
                   1489:               el = child;
                   1490:               child = TtaGetFirstChild (el);
                   1491:               if (child)
                   1492:                 {
                   1493:                   childType = TtaGetElementType (child);
                   1494:                   isSVG = (!strcmp (TtaGetSSchemaName (childType.ElSSchema), "SVG") &&
                   1495:                       childType.ElTypeNum == SVG_EL_SVG);
                   1496:                 }
                   1497:             }
                   1498: #endif /* _SVG */
1.129     vatton   1499:         }
1.79      quint    1500:     }
1.133     vatton   1501: 
1.30      cvs      1502:   /* remove trailing spaces */
1.37      cvs      1503:   length = strlen (buffer) - 1;
1.30      cvs      1504:   while (length > 0 && buffer[length] <= SPACE)
                   1505:     length--;
1.109     vatton   1506:   attrTypePxl.AttrSSchema = elType.ElSSchema;
                   1507:   attrTypePercent.AttrSSchema = elType.ElSSchema;
1.30      cvs      1508:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
                   1509:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
1.144     vatton   1510:   do
1.30      cvs      1511:     {
1.144     vatton   1512:       /* is the last character a '%' ? */
                   1513:       if (buffer[length] == '%')
1.129     vatton   1514:         {
1.144     vatton   1515:           /* remove IntWidthPxl */
                   1516:           attrOld = TtaGetAttribute (el, attrTypePxl);
                   1517:           /* update IntWidthPercent */
                   1518:           attrNew = TtaGetAttribute (el, attrTypePercent);
                   1519:           if (attrNew == NULL)
                   1520:             {
                   1521:               attrNew = TtaNewAttribute (attrTypePercent);
                   1522:               TtaAttachAttribute (el, attrNew, doc);
                   1523:             }
                   1524:           else if (isImage && oldWidth == -1)
                   1525:             {
                   1526:               if (attrOld == NULL)
                   1527:                 oldWidth = TtaGetAttributeValue (attrNew);
                   1528:               else
                   1529:                 oldWidth = TtaGetAttributeValue (attrOld);
                   1530:             }
1.129     vatton   1531:         }
1.144     vatton   1532:       else
1.129     vatton   1533:         {
1.144     vatton   1534:           /* remove IntWidthPercent */
                   1535:           attrOld = TtaGetAttribute (el, attrTypePercent);
                   1536:           /* update IntWidthPxl */
                   1537:           attrNew = TtaGetAttribute (el, attrTypePxl);
                   1538:           if (attrNew == NULL)
                   1539:             {
                   1540:               attrNew = TtaNewAttribute (attrTypePxl);
                   1541:               TtaAttachAttribute (el, attrNew, doc);
                   1542:             }
                   1543:           else if (isImage && oldWidth == -1)
                   1544:             {
                   1545:               TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1546:               if (attrOld == NULL)
                   1547:                 oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
                   1548:               else
                   1549:                 oldWidth = w * TtaGetAttributeValue (attrOld) / 100;     
                   1550:             }
1.129     vatton   1551:         }
1.144     vatton   1552: 
                   1553:       if (attrOld)
                   1554:         TtaRemoveAttribute (el, attrOld, doc);
                   1555:       if (sscanf (buffer, "%d", &val))
                   1556:         TtaSetAttributeValue (attrNew, val, el, doc);
                   1557:       else
                   1558:         /* its not a number. Delete attribute and send an error message */
                   1559:         {
                   1560:           TtaRemoveAttribute (el, attrNew, doc);
                   1561:           if (strlen (buffer) > MaxMsgLength - 30)
                   1562:             buffer[MaxMsgLength - 30] = EOS;
                   1563:           sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1564:           HTMLParseError (doc, msgBuffer, 0);
1.129     vatton   1565:         }
1.144     vatton   1566: 
                   1567:       if (el != origEl)
                   1568:         // apply the attribute to the object itself
                   1569:         el = origEl;
                   1570:       else
                   1571:         el = NULL;
1.30      cvs      1572:     }
1.144     vatton   1573:   while (el);
1.30      cvs      1574: 
                   1575:   if (isImage)
1.79      quint    1576:     UpdateImageMap (origEl, doc, oldWidth, -1);
1.144     vatton   1577:   if (isSVG && oldWidth != -1)
1.133     vatton   1578:     {
                   1579:       // force the redisplay of the SVG element
                   1580:       el = TtaGetParent (child);
                   1581:       if (el)
                   1582:         {
                   1583:           TtaRemoveTree (child, doc);
                   1584:           TtaInsertFirstChild (&child, el, doc);
                   1585:         }
                   1586:     }
1.30      cvs      1587: }
                   1588: 
                   1589: /*----------------------------------------------------------------------
1.129     vatton   1590:   CreateAttrHeightPercentPxl
                   1591:   an HTML attribute "width" has been created for a Table, an image,
                   1592:   an Object or a HR.
                   1593:   Create the corresponding attribute IntHeightPercent or IntHeightPxl.
                   1594:   oldHeight is -1 or the old image width.
1.58      vatton   1595:   ----------------------------------------------------------------------*/
                   1596: void CreateAttrHeightPercentPxl (char *buffer, Element el,
1.129     vatton   1597:                                  Document doc, int oldHeight)
1.58      vatton   1598: {
                   1599:   AttributeType   attrTypePxl, attrTypePercent;
                   1600:   Attribute       attrOld, attrNew;
                   1601:   int             length, val;
                   1602:   char            msgBuffer[MaxMsgLength];
1.133     vatton   1603:   ElementType      elType, childType;
1.79      quint    1604:   Element         origEl, child;
1.58      vatton   1605:   int             w, h;
1.133     vatton   1606:   ThotBool        isImage, isSVG = FALSE;
1.58      vatton   1607: 
1.79      quint    1608:   origEl = el;
1.58      vatton   1609:   elType = TtaGetElementType (el);
                   1610:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1.129     vatton   1611:              elType.ElTypeNum == HTML_EL_Data_cell ||
                   1612:              elType.ElTypeNum == HTML_EL_Heading_cell ||
1.134     vatton   1613:              elType.ElTypeNum == HTML_EL_Object ||
                   1614:              elType.ElTypeNum == HTML_EL_IMG);
1.133     vatton   1615: 
1.79      quint    1616:   if (elType.ElTypeNum == HTML_EL_Object)
                   1617:     /* the height attribute is attached to an Object element */
                   1618:     {
                   1619:       child = TtaGetFirstChild (el);
1.81      cvs      1620:       if (!child)
1.129     vatton   1621:         return;
1.81      cvs      1622:       else
1.129     vatton   1623:         {
                   1624:           childType = TtaGetElementType (child);
                   1625:           if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1626:             /* the Object element is of type image. apply the width
                   1627:                attribute to the actual image element */
                   1628:             el = child;
1.133     vatton   1629: #ifdef _SVG
1.129     vatton   1630:           else
1.133     vatton   1631:             {
                   1632:               el = child;
                   1633:               child = TtaGetFirstChild (el);
                   1634:               if (child)
                   1635:                 {
                   1636:                   childType = TtaGetElementType (child);
                   1637:                   isSVG = (!strcmp (TtaGetSSchemaName (childType.ElSSchema), "SVG") &&
                   1638:                       childType.ElTypeNum == SVG_EL_SVG);
                   1639:                 }
                   1640:             }
                   1641: #endif /* _SVG */
1.129     vatton   1642:         }
1.79      quint    1643:     }
1.133     vatton   1644: 
1.58      vatton   1645:   /* remove trailing spaces */
                   1646:   length = strlen (buffer) - 1;
                   1647:   while (length > 0 && buffer[length] <= SPACE)
                   1648:     length--;
1.109     vatton   1649:   attrTypePxl.AttrSSchema = elType.ElSSchema;
                   1650:   attrTypePercent.AttrSSchema = elType.ElSSchema;
1.58      vatton   1651:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
                   1652:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
1.144     vatton   1653:   do
1.58      vatton   1654:     {
1.144     vatton   1655:       /* is the last character a '%' ? */
                   1656:       if (buffer[length] == '%')
1.129     vatton   1657:         {
1.144     vatton   1658:           /* remove IntHeightPxl */
                   1659:           attrOld = TtaGetAttribute (el, attrTypePxl);
                   1660:           /* update IntHeightPercent */
                   1661:           attrNew = TtaGetAttribute (el, attrTypePercent);
                   1662:           if (attrNew == NULL)
                   1663:             {
                   1664:               attrNew = TtaNewAttribute (attrTypePercent);
                   1665:               TtaAttachAttribute (el, attrNew, doc);
                   1666:             }
                   1667:           else if (isImage && oldHeight == -1)
                   1668:             {
                   1669:               if (attrOld == NULL)
                   1670:                 oldHeight = TtaGetAttributeValue (attrNew);
                   1671:               else
                   1672:                 oldHeight = TtaGetAttributeValue (attrOld);
                   1673:             }
1.129     vatton   1674:         }
1.144     vatton   1675:       else
1.129     vatton   1676:         {
1.144     vatton   1677:           /* remove IntHeightPercent */
                   1678:           attrOld = TtaGetAttribute (el, attrTypePercent);
                   1679:           /* update IntHeightPxl */
                   1680:           attrNew = TtaGetAttribute (el, attrTypePxl);
                   1681:           if (attrNew == NULL)
                   1682:             {
                   1683:               attrNew = TtaNewAttribute (attrTypePxl);
                   1684:               TtaAttachAttribute (el, attrNew, doc);
                   1685:             }
                   1686:           else if (isImage && oldHeight == -1)
                   1687:             {
                   1688:               TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1689:               if (attrOld == NULL)
                   1690:                 oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
                   1691:               else
                   1692:                 oldHeight = w * TtaGetAttributeValue (attrOld) / 100;    
                   1693:             }
1.129     vatton   1694:         }
1.144     vatton   1695: 
                   1696:       if (attrOld)
                   1697:         TtaRemoveAttribute (el, attrOld, doc);
                   1698:       if (sscanf (buffer, "%d", &val))
                   1699:         TtaSetAttributeValue (attrNew, val, el, doc);
                   1700:       else
                   1701:         /* its not a number. Delete attribute and send an error message */
                   1702:         {
                   1703:           TtaRemoveAttribute (el, attrNew, doc);
                   1704:           if (strlen (buffer) > MaxMsgLength - 30)
                   1705:             buffer[MaxMsgLength - 30] = EOS;
                   1706:           sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1707:           HTMLParseError (doc, msgBuffer, 0);
1.129     vatton   1708:         }
1.144     vatton   1709: 
                   1710:       if (el != origEl)
                   1711:         // apply the attribute to the object itself
                   1712:         el = origEl;
                   1713:       else
                   1714:         el = NULL;
1.58      vatton   1715:     }
1.144     vatton   1716:   while (el);
1.58      vatton   1717: 
                   1718:   if (isImage)
1.79      quint    1719:     UpdateImageMap (origEl, doc, oldHeight, -1);
1.144     vatton   1720:   if (isSVG && oldHeight != -1)
1.133     vatton   1721:     {
                   1722:       // force the redisplay of the SVG element
                   1723:       el = TtaGetParent (child);
                   1724:       if (el)
                   1725:         {
                   1726:           TtaRemoveTree (child, doc);
                   1727:           TtaInsertFirstChild (&child, el, doc);
                   1728:         }
                   1729:     }
1.58      vatton   1730: }
                   1731: 
                   1732: /*----------------------------------------------------------------------
1.129     vatton   1733:   CreateAttrIntAreaSize
                   1734:   an HTML attribute "size" has been created or modified for a input element.
                   1735:   Create or update the corresponding attribute IntAreaSize.
1.91      quint    1736:   ----------------------------------------------------------------------*/
                   1737: void CreateAttrIntAreaSize (int value, Element el, Document doc)
                   1738: {
                   1739:   AttributeType   attrType;
                   1740:   Attribute       attr;
                   1741:   ElementType    elType;
                   1742: 
                   1743:   elType = TtaGetElementType (el);
                   1744:   attrType.AttrSSchema = elType.ElSSchema;
1.135     vatton   1745:   if (elType.ElTypeNum == HTML_EL_Image_Input)
                   1746:     {
                   1747:       attrType.AttrTypeNum = HTML_ATTR_IntWidthPxl;
                   1748:       attr = TtaGetAttribute (el, attrType);
                   1749:       if (!attr)
                   1750:         {
                   1751:           attr = TtaNewAttribute (attrType);
                   1752:           TtaAttachAttribute (el, attr, doc);
                   1753:         }
                   1754:       /* the presentation rule associated with attribute IntWidthPxl */
                   1755:       TtaSetAttributeValue (attr, value, el, doc);
                   1756:     }
                   1757:   else
1.91      quint    1758:     {
1.135     vatton   1759:       attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                   1760:       attr = TtaGetAttribute (el, attrType);
                   1761:       if (!attr)
                   1762:         {
                   1763:           attr = TtaNewAttribute (attrType);
                   1764:           TtaAttachAttribute (el, attr, doc);
                   1765:         }
                   1766:       /* the presentation rule associated with attribute IntAreaSize expresses
                   1767:          the element width in "em". Convert the value into em */
                   1768:       TtaSetAttributeValue (attr, (int) (value * 0.40), el, doc);
1.91      quint    1769:     }
                   1770: }
                   1771: 
                   1772: /*----------------------------------------------------------------------
1.129     vatton   1773:   CreateAttrIntSize
                   1774:   an HTML attribute "size" has been created for a Font element.
                   1775:   Create the corresponding internal attribute.
1.30      cvs      1776:   ----------------------------------------------------------------------*/
1.109     vatton   1777: void CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30      cvs      1778: 
                   1779: {
1.129     vatton   1780:   ElementType    elType;
                   1781:   AttributeType  attrType;
                   1782:   int            val, ind, factor, delta;
                   1783:   Attribute      attr;
                   1784:   char         msgBuffer[MaxMsgLength];
                   1785: 
                   1786:   /* is the first character a '+' or a '-' ? */
                   1787:   elType = TtaGetElementType (el);
                   1788:   ind = 0;
                   1789:   factor = 1;
                   1790:   delta = 0;
                   1791:   if (buffer[0] == '+')
                   1792:     {
                   1793:       attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
                   1794:       ind++;
                   1795:       factor = 1;
                   1796:     }
                   1797:   else if (buffer[0] == '-')
                   1798:     {
                   1799:       attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
                   1800:       ind++;
                   1801:       factor = 1;
                   1802:     }
                   1803:   else
                   1804:     {
                   1805:       attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
                   1806:       delta = 1;
                   1807:     }
                   1808:   attrType.AttrSSchema = elType.ElSSchema;
                   1809:   attr = TtaGetAttribute (el, attrType);
                   1810:   if (sscanf (&buffer[ind], "%d", &val))
                   1811:     {
                   1812:       val = val * factor + delta;
                   1813:       if (attr == NULL)
                   1814:         {
                   1815:           /* this attribute doesn't exist, create it */
                   1816:           attr = TtaNewAttribute (attrType);
                   1817:           TtaAttachAttribute (el, attr, doc);
                   1818:         }
                   1819:       TtaSetAttributeValue (attr, val, el, doc);
                   1820:     }
                   1821:   else
                   1822:     /* its not a number. Delete attribute and send an error message */
                   1823:     {
                   1824:       if (attr)
                   1825:         TtaRemoveAttribute (el, attr, doc);
                   1826:       if (strlen (buffer) > MaxMsgLength - 30)
                   1827:         buffer[MaxMsgLength - 30] = EOS;
                   1828:       sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1829:       HTMLParseError (doc, msgBuffer, 0);
                   1830:     }
1.30      cvs      1831: }
                   1832: /*----------------------------------------------------------------------
1.129     vatton   1833:   EndOfHTMLAttributeValue
                   1834:   Filling of an HTML attribute value
1.30      cvs      1835:   ----------------------------------------------------------------------*/
1.109     vatton   1836: void EndOfHTMLAttributeValue (char *attrValue, AttributeMapping *lastMappedAttr,
1.129     vatton   1837:                               Attribute currentAttribute, Element lastAttrElement,
                   1838:                               ThotBool UnknownAttr, ParserData *context,
                   1839:                               ThotBool isXML)
1.30      cvs      1840: {
1.48      vatton   1841:   AttributeType   attrType, attrType1;
                   1842:   Attribute       attr;
1.79      quint    1843:   ElementType    elType;
1.48      vatton   1844:   Element         child, root;
                   1845:   Language        lang;
                   1846:   char            translation;
                   1847:   char            shape;
                   1848:   char           *buffer;
                   1849:   char           *attrName;
                   1850:   char            msgBuffer[MaxMsgLength];
                   1851:   int             val;
                   1852:   int             length;
                   1853:   int             attrKind;
                   1854:   ThotBool        done = FALSE;
1.88      vatton   1855:   ThotBool            loadcss;
1.30      cvs      1856: 
1.48      vatton   1857:   /* treatments of some particular HTML attributes */
                   1858:   if (!strcmp (lastMappedAttr->XMLattribute, "style"))
                   1859:     {
                   1860:       TtaSetAttributeText (currentAttribute, attrValue,
1.129     vatton   1861:                            lastAttrElement, context->doc);
1.88      vatton   1862:       /* check if we have to load CSS */
                   1863:       TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
                   1864:       if (loadcss)
1.129     vatton   1865:         ParseHTMLSpecificStyle (context->lastElement, attrValue,
1.143     quint    1866:                                 context->doc, 1000, FALSE);
1.48      vatton   1867:       done = TRUE;
                   1868:     }
                   1869:   else
                   1870:     {
                   1871:       if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1.129     vatton   1872:         HTMLSetAlinkColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1873:       else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1.129     vatton   1874:         HTMLSetAactiveColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1875:       else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1.129     vatton   1876:         HTMLSetAvisitedColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1877:     }
1.30      cvs      1878: 
1.48      vatton   1879:   if (!done)
                   1880:     {
1.109     vatton   1881:       elType = TtaGetElementType (lastAttrElement);
1.48      vatton   1882:       val = 0;
                   1883:       translation = lastMappedAttr->AttrOrContent;
                   1884:       switch (translation)
1.129     vatton   1885:         {
                   1886:         case 'C':      /* Content */
                   1887:           child = PutInContent (attrValue, context);
                   1888:           if (child != NULL)
                   1889:             TtaAppendTextContent (child, (unsigned char *)"\" ", context->doc);
                   1890:           break;
                   1891:         case 'A':
                   1892:           if (currentAttribute != NULL)
                   1893:             {
                   1894:               TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1895:               switch (attrKind)
                   1896:                 {
                   1897:                 case 0:        /* enumerate */
                   1898:                   if (isXML)
                   1899:                     MapHTMLAttributeValue (attrValue, &attrType, &val);
                   1900:                   else
                   1901:                     val = MapAttrValue (lastMappedAttr->ThotAttribute,
                   1902:                                         attrValue);
                   1903:                   if (val < 0)
                   1904:                     {
                   1905:                       TtaGiveAttributeType (currentAttribute,
                   1906:                                             &attrType, &attrKind);
                   1907:                       attrName = TtaGetAttributeName (attrType);
                   1908:                       sprintf (msgBuffer,
                   1909:                                "Invalid attribute value \"%s = %s\"",
                   1910:                                attrName, attrValue);
                   1911:                       if (isXML)
                   1912:                         XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1913:                       else
                   1914:                         /* we are parsing an HTML file, not an XHTML file */
                   1915:                         {
                   1916:                           /* generate an error message in the log */
                   1917:                           HTMLParseError (context->doc, msgBuffer, 0);
                   1918:                           /* special case for value POLYGON of attribute 
                   1919:                              shape (AREA element) */
                   1920:                           if (attrType.AttrTypeNum == HTML_ATTR_shape &&
                   1921:                               strcasecmp (attrValue, "POLYGON") == 0)
                   1922:                             {
                   1923:                               val = HTML_ATTR_shape_VAL_polygon;
                   1924:                               /* interpret it as if it were "poly" */
                   1925:                               TtaSetAttributeValue (currentAttribute, val,
                   1926:                                                     lastAttrElement, context->doc);
                   1927:                             }
                   1928:                           else
                   1929:                             /* remove the attribute and replace it by an */
                   1930:                             /* Invalid_attribute (not for XHTML) */
                   1931:                             {
                   1932:                               TtaRemoveAttribute (lastAttrElement,
                   1933:                                                   currentAttribute, context->doc);
                   1934:                               attrType.AttrSSchema = elType.ElSSchema;
                   1935:                               attrType.AttrTypeNum =
                   1936:                                 pHTMLAttributeMapping[0].ThotAttribute;
                   1937:                               sprintf (msgBuffer, "%s=%s", attrName,attrValue);
                   1938:                               CreateHTMLAttribute (lastAttrElement, attrType,
                   1939:                                                    msgBuffer, TRUE, context->doc,
                   1940:                                                    &currentAttribute, &lastAttrElement);
                   1941:                             }
                   1942:                         }
                   1943:                     }
                   1944:                   else
                   1945:                     TtaSetAttributeValue (currentAttribute, val,
                   1946:                                           lastAttrElement, context->doc);
                   1947:                   break;
                   1948:                 case 1:        /* integer */
                   1949:                   if (attrType.AttrTypeNum == HTML_ATTR_Border &&
                   1950:                       !strcasecmp (attrValue, "border"))
                   1951:                     {
                   1952:                       /* border="border" for a table */
                   1953:                       val = 1;
                   1954:                       TtaSetAttributeValue (currentAttribute, val,
                   1955:                                             lastAttrElement, context->doc);
                   1956:                     }
                   1957:                   else if (sscanf (attrValue, "%d", &val))
                   1958:                     TtaSetAttributeValue (currentAttribute, val,
                   1959:                                           lastAttrElement, context->doc);
                   1960:                   else
                   1961:                     {
                   1962:                       TtaRemoveAttribute (lastAttrElement, currentAttribute,
                   1963:                                           context->doc);
                   1964:                       sprintf (msgBuffer,
                   1965:                                "Unknown attribute value \"%s\"",
                   1966:                                attrValue);
                   1967:                       if (isXML)
                   1968:                         XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1969:                       else
                   1970:                         HTMLParseError (context->doc, msgBuffer, 0);
                   1971:                     }
                   1972:                   break;
                   1973:                 case 2:        /* text */
                   1974:                   if (!UnknownAttr)
                   1975:                     {
                   1976:                       TtaSetAttributeText (currentAttribute, attrValue,
                   1977:                                            lastAttrElement, context->doc);
                   1978:                       if (attrType.AttrTypeNum == HTML_ATTR_Language)
                   1979:                         {
                   1980:                           /* it's a LANG attribute value */
                   1981:                           lang = TtaGetLanguageIdFromName (attrValue);
                   1982:                           if (lang < 0)
                   1983:                             {
                   1984:                               sprintf (msgBuffer,
                   1985:                                        "warning - unsupported language: %s",
                   1986:                                        attrValue);
                   1987:                               if (isXML)
                   1988:                                 XmlParseError (warningMessage, (unsigned char *)msgBuffer, 0);
                   1989:                               else
                   1990:                                 HTMLParseError (context->doc, msgBuffer, 0);
                   1991:                             }
                   1992:                           else
                   1993:                             {
                   1994:                               /* change current language */
                   1995:                               context->language = lang;
                   1996:                               if (isXML)
                   1997:                                 SetLanguagInXmlStack (lang);
                   1998:                               else
                   1999:                                 SetLanguagInHTMLStack (lang);
                   2000:                             }
                   2001:                           root = TtaGetRootElement (context->doc);
                   2002:                           if (lastAttrElement == root)
                   2003:                             /* it's a LANG attribute on the root element */
                   2004:                             /* set the RealLang attribute */
                   2005:                             {
                   2006:                               attrType1.AttrSSchema = elType.ElSSchema;
                   2007:                               attrType1.AttrTypeNum = HTML_ATTR_RealLang;
                   2008:                               /* this attribute could be already present,
                   2009:                                  (lang and xml:lang attributes) */
                   2010:                               if (!TtaGetAttribute (lastAttrElement,
                   2011:                                                     attrType1))
                   2012:                                 /* it's not present. Add it */
                   2013:                                 {
                   2014:                                   attr = TtaNewAttribute (attrType1);
                   2015:                                   TtaAttachAttribute (lastAttrElement,
                   2016:                                                       attr, context->doc);
                   2017:                                   TtaSetAttributeValue (attr,
                   2018:                                                         HTML_ATTR_RealLang_VAL_Yes_,
                   2019:                                                         lastAttrElement,
                   2020:                                                         context->doc);
                   2021:                                 }
                   2022:                             }
                   2023:                         }
                   2024:                       else if (attrType.AttrTypeNum == HTML_ATTR_ID ||
                   2025:                                attrType.AttrTypeNum == HTML_ATTR_NAME)
                   2026:                         CheckUniqueName (lastAttrElement, context->doc,
                   2027:                                          currentAttribute, attrType);
                   2028:                       else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
                   2029:                         TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
                   2030:                                          lastAttrElement);
                   2031:                     }
                   2032:                   else
                   2033:                     {
                   2034:                       /* this is the content of an invalid attribute */
                   2035:                       /* append it to the current Invalid_attribute */
                   2036:                       if (!isXML)
                   2037:                         {
                   2038:                           length = strlen (attrValue) + 2;
                   2039:                           length += TtaGetTextAttributeLength (currentAttribute);
                   2040:                           buffer = (char *)TtaGetMemory (length + 1);
                   2041:                           TtaGiveTextAttributeValue (currentAttribute,
                   2042:                                                      buffer, &length);
                   2043:                           strcat (buffer, "=");
                   2044:                           strcat (buffer, attrValue);
                   2045:                           TtaSetAttributeText (currentAttribute, buffer,
                   2046:                                                lastAttrElement, context->doc);
                   2047:                           TtaFreeMemory (buffer);
                   2048:                         }
                   2049:                     }
                   2050:                   break;
                   2051:                 case 3:        /* reference */
                   2052:                   break;
                   2053:                 }
                   2054:             }
                   2055:           break;
                   2056:         case SPACE:
1.135     vatton   2057:           XhtmlTypeAttrValue (attrValue, currentAttribute,
                   2058:                               lastAttrElement, context,isXML );
1.129     vatton   2059:           break;  
                   2060:         default:
                   2061:           break;
                   2062:         }
1.30      cvs      2063: 
                   2064:       if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.129     vatton   2065:         /* HTML attribute "width" */
                   2066:         {
                   2067:           /* if it's an Object element, wait until all attributes are handled,
                   2068:              especially the data attribute that may generate the image to
                   2069:              which the width has to be applied */
                   2070:           if (elType.ElTypeNum != HTML_EL_Object)
                   2071:             /* create the corresponding attribute IntWidthPercent or */
                   2072:             /* IntWidthPxl */
                   2073:             CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
                   2074:                                        context->doc, -1);
                   2075:         }
1.58      vatton   2076:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.129     vatton   2077:         /* HTML attribute "height" */
                   2078:         {
                   2079:           /* if it's an Object element, wait until all attributes are handled,
                   2080:              especially the data attribute that may generate the image to
                   2081:              which the height has to be applied */
                   2082:           if (elType.ElTypeNum != HTML_EL_Object)
                   2083:             /* create the corresponding attribute IntHeightPercent or */
                   2084:             /* IntHeightPxl */
                   2085:             CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
                   2086:                                         context->doc, -1);
                   2087:         }
1.91      quint    2088:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Area_Size)
1.129     vatton   2089:         /* HTML attribute "size" for an element "input" */
                   2090:         CreateAttrIntAreaSize (val, lastAttrElement, context->doc);
1.48      vatton   2091:       else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
1.129     vatton   2092:         {
                   2093:           TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   2094:           if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
                   2095:             CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
                   2096:         }
1.48      vatton   2097:       else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
1.129     vatton   2098:         {
                   2099:           child = TtaGetFirstChild (lastAttrElement);
                   2100:           if (child != NULL)
                   2101:             {
                   2102:               switch (val)
                   2103:                 {
                   2104:                 case HTML_ATTR_shape_VAL_rectangle:
                   2105:                   shape = 'R';
                   2106:                   break;
                   2107:                 case HTML_ATTR_shape_VAL_circle:
                   2108:                   shape = 'a';
                   2109:                   break;
                   2110:                 case HTML_ATTR_shape_VAL_polygon:
                   2111:                   shape = 'p';
                   2112:                   break;
                   2113:                 default:
                   2114:                   shape = SPACE;
                   2115:                   break;
                   2116:                 }
                   2117:               TtaSetGraphicsShape (child, shape, context->doc);
                   2118:             }
                   2119:         }
1.48      vatton   2120:       else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
1.129     vatton   2121:         {
                   2122:           if (elType.ElTypeNum == HTML_EL_Text_Input ||
                   2123:               elType.ElTypeNum == HTML_EL_Password_Input ||
                   2124:               elType.ElTypeNum == HTML_EL_File_Input ||
                   2125:               elType.ElTypeNum == HTML_EL_Input)
                   2126:             /* create a Default_Value attribute with the same content */
                   2127:             {
                   2128:               attrType1.AttrSSchema = attrType.AttrSSchema;
                   2129:               attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
                   2130:               attr = TtaNewAttribute (attrType1);
                   2131:               TtaAttachAttribute (lastAttrElement, attr, context->doc);
                   2132:               TtaSetAttributeText (attr, attrValue,
                   2133:                                    lastAttrElement, context->doc);
                   2134:             }
                   2135:         }
1.30      cvs      2136:       else
1.129     vatton   2137:         {
                   2138:           /* Some HTML attributes are equivalent to a CSS property:      */
                   2139:           /*      background     ->                   background         */
                   2140:           /*      bgcolor        ->                   background         */
                   2141:           /*      text           ->                   color              */
                   2142:           /*      color          ->                   color              */
                   2143:           if (!strcmp (lastMappedAttr->XMLattribute, "background"))
                   2144:             {
                   2145:               if (strlen (attrValue) > MaxMsgLength - 30)
                   2146:                 attrValue[MaxMsgLength - 30] = EOS;
                   2147:               HTMLSetBackgroundImage (context->doc, context->lastElement,
1.143     quint    2148:                                       REPEAT, 2000, attrValue, FALSE);
1.129     vatton   2149:             }
                   2150:           else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
                   2151:             HTMLSetBackgroundColor (context->doc, context->lastElement,
1.143     quint    2152:                                     2000, attrValue);
1.129     vatton   2153:           else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
                   2154:                    !strcmp (lastMappedAttr->XMLattribute, "color"))
                   2155:             HTMLSetForegroundColor (context->doc, context->lastElement,
1.143     quint    2156:                                     2000, attrValue);
1.129     vatton   2157:         }
1.48      vatton   2158:     }
1.30      cvs      2159: }
                   2160: 
                   2161: /*----------------------------------------------------------------------
1.129     vatton   2162:   MapHTMLAttributeValue
                   2163:   Search in the Attribute Value Mapping Table the entry for the attribute
                   2164:   ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1       cvs      2165:   ----------------------------------------------------------------------*/
1.118     vatton   2166: void MapHTMLAttributeValue (char *attVal, const AttributeType *attrType,
1.129     vatton   2167:                             int *value)
1.1       cvs      2168: {
1.66      vatton   2169:   MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1       cvs      2170: }

Webmaster