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

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

Webmaster