gwenhywfar 4.0.3
|
00001 /*************************************************************************** 00002 begin : Mon Feb 22 2010 00003 copyright : (C) 2010 by Martin Preuss 00004 email : martin@libchipcard.de 00005 00006 *************************************************************************** 00007 * Please see toplevel file COPYING for license details * 00008 ***************************************************************************/ 00009 00010 #ifdef HAVE_CONFIG_H 00011 # include <config.h> 00012 #endif 00013 00014 #define DISABLE_DEBUGLOG 00015 00016 00017 #include "g_unorderedlist_p.h" 00018 #include "g_box_l.h" 00019 #include "g_generic_l.h" 00020 #include "htmlctx_l.h" 00021 #include "o_box_l.h" 00022 #include "o_grid_l.h" 00023 #include "o_gridentry_l.h" 00024 #include "o_word_l.h" 00025 00026 #include <gwenhywfar/debug.h> 00027 00028 00029 GWEN_INHERIT(HTML_GROUP, GROUP_UNORDEREDLIST) 00030 00031 00032 00033 HTML_GROUP *HtmlGroup_UnorderedList_new(const char *groupName, 00034 HTML_GROUP *parent, 00035 GWEN_XML_CONTEXT *ctx) { 00036 HTML_GROUP *g; 00037 GROUP_UNORDEREDLIST *xg; 00038 00039 /* create base group */ 00040 g=HtmlGroup_Generic_new(groupName, parent, ctx); 00041 assert(g); 00042 00043 /* inherit */ 00044 GWEN_NEW_OBJECT(GROUP_UNORDEREDLIST, xg); 00045 GWEN_INHERIT_SETDATA(HTML_GROUP, GROUP_UNORDEREDLIST, g, xg, 00046 HtmlGroup_UnorderedList_FreeData); 00047 00048 /* set virtual functions */ 00049 HtmlGroup_SetStartTagFn(g, HtmlGroup_UnorderedList_StartTag); 00050 00051 return g; 00052 } 00053 00054 00055 00056 void GWENHYWFAR_CB HtmlGroup_UnorderedList_FreeData(void *bp, void *p) { 00057 GROUP_UNORDEREDLIST *xg; 00058 00059 xg=(GROUP_UNORDEREDLIST*) p; 00060 GWEN_FREE_OBJECT(xg); 00061 } 00062 00063 00064 00065 int HtmlGroup_UnorderedList_StartTag(HTML_GROUP *g, const char *tagName) { 00066 GROUP_UNORDEREDLIST *xg; 00067 HTML_GROUP *gNew=NULL; 00068 GWEN_XML_CONTEXT *ctx; 00069 00070 assert(g); 00071 xg=GWEN_INHERIT_GETDATA(HTML_GROUP, GROUP_UNORDEREDLIST, g); 00072 assert(xg); 00073 00074 ctx=HtmlGroup_GetXmlContext(g); 00075 00076 if (strcasecmp(tagName, "li")==0) { 00077 HTML_OBJECT *o; 00078 HTML_OBJECT *oGrid; 00079 00080 /* first column in the grid is "-" */ 00081 oGrid=HtmlObject_GridEntry_new(ctx); 00082 HtmlObject_GridEntry_SetColumn(oGrid, 0); 00083 HtmlObject_GridEntry_SetRow(oGrid, xg->row); 00084 HtmlObject_SetProperties(oGrid, HtmlGroup_GetProperties(g)); 00085 HtmlObject_Tree_AddChild(HtmlGroup_GetObject(g), oGrid); 00086 00087 o=HtmlObject_Word_new(ctx, "-"); 00088 HtmlObject_SetProperties(o, HtmlGroup_GetProperties(g)); 00089 HtmlObject_Tree_AddChild(oGrid, o); 00090 00091 /* Create new parser group with new properties but use the same object */ 00092 gNew=HtmlGroup_Box_new(tagName, g, ctx); 00093 HtmlGroup_SetProperties(gNew, HtmlGroup_GetProperties(g)); 00094 o=HtmlGroup_GetObject(g); 00095 assert(o); 00096 if (HtmlObject_GetObjectType(o)==HtmlObjectType_Grid) { 00097 int i; 00098 00099 i=HtmlObject_Grid_GetRows(o); 00100 HtmlObject_Grid_SetRows(o, ++i); 00101 } 00102 00103 /* second column is the content of li */ 00104 o=HtmlObject_GridEntry_new(ctx); 00105 HtmlObject_GridEntry_SetColumn(oGrid, 1); 00106 HtmlObject_GridEntry_SetRow(oGrid, xg->row); 00107 HtmlObject_SetProperties(o, HtmlGroup_GetProperties(g)); 00108 HtmlObject_Tree_AddChild(oGrid, o); 00109 00110 HtmlGroup_SetObject(gNew, o); 00111 xg->row++; 00112 } 00113 else { 00114 DBG_ERROR(GWEN_LOGDOMAIN, 00115 "Unexpected group [%s]", tagName); 00116 return GWEN_ERROR_BAD_DATA; 00117 } 00118 00119 if (gNew) { 00120 HtmlCtx_SetCurrentGroup(ctx, gNew); 00121 GWEN_XmlCtx_IncDepth(ctx); 00122 } 00123 00124 return 0; 00125 } 00126 00127 00128