Annotation of libwww/Library/src/HTStyle.c, revision 2.26

2.25      frystyk     1: /*
                      2: **     GENERIC STYLE IMPLEMENTATION FOR HYPERTEXT
2.10      frystyk     3: **
2.14      frystyk     4: **     (c) COPYRIGHT MIT 1995.
2.10      frystyk     5: **     Please first read the full copyright statement in the file COPYRIGH.
2.26    ! frystyk     6: **     @(#) $Id: HTStyle.c,v 2.25 1999/01/06 15:38:47 frystyk Exp $
1.1       timbl       7: **
                      8: **     Styles allow the translation between a logical property
                      9: **     of a piece of text and its physical representation.
                     10: **
2.25      frystyk    11: **     A stylesheet is a collection of styles that can be applied
                     12: **     to the layout engine, for example provided by the HText
                     13: **     implementation.
1.1       timbl      14: */
2.11      roeber     15: 
2.12      frystyk    16: /* Library include files */
2.24      frystyk    17: #include "wwwsys.h"
2.25      frystyk    18: #include "WWWUtil.h"
1.1       timbl      19: #include "HTStyle.h"
                     20: 
2.7       timbl      21: struct _HTStyle {
2.25      frystyk    22:     char *     name;           /* Style name */
                     23:     int                element;        /* Element (if any) that this style applies to */
                     24:     void *     context;        /* Implementation specific style context */
                     25: };
2.7       timbl      26: 
2.25      frystyk    27: struct _HTStyleSheet {
                     28:     char *     name;
                     29:     HTList *   styles;
2.7       timbl      30: };
                     31: 
2.25      frystyk    32: /* ------------------------------------------------------------------------- */
                     33: /*                           INDIVIDUAL STYLES                              */
                     34: /* ------------------------------------------------------------------------- */
2.7       timbl      35: 
2.25      frystyk    36: PUBLIC HTStyle * HTStyle_new (const char * name, int element, void * context)
1.1       timbl      37: {
2.25      frystyk    38:     HTStyle * style = NULL;
2.20      frystyk    39:     if ((style = (HTStyle  *) HT_CALLOC(1, sizeof(HTStyle))) == NULL)
                     40:         HT_OUTOFMEM("HTStyleNew");
2.25      frystyk    41:     StrAllocCopy(style->name, name ? name : "unknown");
                     42:     style->element = element;
                     43:     style->context = context;
2.15      frystyk    44:     return style;
1.1       timbl      45: }
                     46: 
2.25      frystyk    47: PUBLIC BOOL HTStyle_delete  (HTStyle * me)
1.1       timbl      48: {
2.25      frystyk    49:     if (me) {
                     50:        HT_FREE(me->name);
                     51:        HT_FREE(me);
                     52:        return YES;
                     53:     }
                     54:     return NO;
1.1       timbl      55: }
                     56: 
2.25      frystyk    57: /* ------------------------------------------------------------------------- */
                     58: /*                               STYLE SHEETS                               */
                     59: /* ------------------------------------------------------------------------- */
1.1       timbl      60: 
2.25      frystyk    61: PUBLIC HTStyleSheet * HTStyleSheet_new (const char * name)
1.1       timbl      62: {
2.25      frystyk    63:     HTStyleSheet * ss;
                     64:     if ((ss = (HTStyleSheet *) HT_CALLOC(1, sizeof(HTStyleSheet))) == NULL)
                     65:         HT_OUTOFMEM("HTStyleSheet_new");
                     66:     StrAllocCopy(ss->name, name ? name : "unknown");
                     67:     ss->styles = HTList_new();
                     68:     return ss;
1.1       timbl      69: }
                     70: 
2.25      frystyk    71: PUBLIC BOOL HTStyleSheet_delete (HTStyleSheet * me)
1.1       timbl      72: {
2.25      frystyk    73:     if (me) {
                     74:        HTList * cur = me->styles;
                     75:        HTStyle * pres;
                     76:        while ((pres = (HTStyle *) HTList_nextObject(cur)))
                     77:            HTStyle_delete(pres);
                     78:        HTList_delete(me->styles);
                     79:        HT_FREE(me);
                     80:        return YES;
2.8       howcome    81:     }
2.25      frystyk    82:     return NO;
1.1       timbl      83: }
                     84: 
2.25      frystyk    85: PUBLIC BOOL HTStyleSheet_addStyle (HTStyleSheet * me, HTStyle * style)
1.1       timbl      86: {
2.25      frystyk    87:     return (me && style) ? HTList_addObject(me->styles, style) : NO;
1.1       timbl      88: }
                     89: 
2.25      frystyk    90: PUBLIC BOOL HTStyleSheet_deleteStyle (HTStyleSheet * me, HTStyle * style)
1.1       timbl      91: {
2.25      frystyk    92:     if (me && style) {
                     93:        HTList_removeObject(me->styles, style);
                     94:        HTStyle_delete(style);
                     95:        return YES;
1.1       timbl      96:     }
2.25      frystyk    97:     return NO;
1.1       timbl      98: }
                     99: 
2.25      frystyk   100: PUBLIC HTStyle * HTStyleSheet_findStyleWithName (HTStyleSheet * me, const char * name)
1.1       timbl     101: {
2.25      frystyk   102:     if (me && name) {
                    103:        HTList * cur = me->styles;
                    104:        HTStyle * pres;
                    105:        while ((pres = (HTStyle *) HTList_nextObject(cur))) {
                    106:            if (!strcasecomp(pres->name, name)) return pres;
1.1       timbl     107:        }
2.26    ! frystyk   108:        HTTRACE(SGML_TRACE, "StyleSheet.. No style named `%s' in stylesheet `%s'\n" _ 
        !           109:                    name _ me->name);
1.1       timbl     110:     }
2.25      frystyk   111:     return NULL;
1.1       timbl     112: }
                    113: 
2.25      frystyk   114: PUBLIC HTStyle * HTStyleSheet_findStyleForElement (HTStyleSheet * me, int element)
1.1       timbl     115: {
2.25      frystyk   116:     if (me) {
                    117:        HTList * cur = me->styles;
                    118:        HTStyle * pres;
                    119:        while ((pres = (HTStyle *) HTList_nextObject(cur))) {
                    120:            if (pres->element==element) return pres;
1.1       timbl     121:        }
2.26    ! frystyk   122:        HTTRACE(SGML_TRACE, "StyleSheet.. No style for element %d in stylesheet `%s'\n" _ 
        !           123:                    element _ me->name);
1.1       timbl     124:     }
2.25      frystyk   125:     return NULL;
1.1       timbl     126: }

Webmaster