1 \membersection{Tag Handlers
}\label{handlers
}
3 wxHTML library provides architecture of pluginable
{\it tag handlers
}.
4 Tag handler is class that understands particular HTML tag (or tags) and is
7 \helpref{wxHtmlWinParser
}{wxhtmlwinparser
} has static table of
{\bf modules
}.
8 Each module contains one or more tag handlers. Each time new wxHtmlWinParser
9 object is constructed all modules are scanned and handlers are added
10 to wxHtmlParser's list of available handlers (note : wxHtmlParser's list
13 \wxheading{How it works
}
15 Common tag handler's
\helpref{HandleTag
}{wxhtmltaghandlerhandletag
} method
19 \item Save state of parent parser into local variables
20 \item Change parser state according to tag's params
21 \item Parse text between the tag and paired ending tag (if present)
22 \item Restore original parser state
25 See
\helpref{wxHtmlWinParser
}{wxhtmlwinparser
} for methods for modifying
26 parser's state. In general you can do things like opening/closing containers,
27 changing colors, fonts etc.
29 \wxheading{Providing own tag handlers
}
31 You should create new .cpp file and place following lines into it:
34 #include <mod_templ.h>
35 #include <forcelink.h>
36 FORCE_LINK_ME(yourmodulefilenamewithoutcpp)
39 Then you must define handlers and one module.
41 \wxheading{Tag handlers
}
43 The handler is derived from
\helpref{wxHtmlWinTagHandler
}{wxhtmlwintaghandler
}
44 (or directly from
\helpref{wxHtmlTagHandler
}{wxhtmltaghandler
})
46 You can use set of macros to define the handler (see src/mod_*.cpp files
47 for details). Handler definition must start with
{\bf TAG_HANDLER_BEGIN
} macro
48 and end with
{\bf TAG_HANDLER_END
} macro. I strongly recommend to have a look
49 at
{\it include/wxhtml/mod_templ.h
} file. Otherwise you won't understand
50 the structure of macros... See macros reference:
52 {\bf TAG_HANDLER_BEGIN
}(
{\it name
},
{\it tags
})
54 Starts handler definition.
{\it name
} is handler identifier (in fact
55 part of class name),
{\it tags
} is string containing list of tags
56 supported by this handler (in uppercase). This macro derives new class from
57 wxHtmlWinTagHandler and implements it's
58 \helpref{GetSupportedTags
}{wxhtmltaghandlergetsupportedtags
} method.
60 Example: TAG_HANDLER_BEGIN(FONTS, "B,I,U,T")
62 {\bf TAG_HANDLER_VARS
}
64 This macro starts block of variables definitions. (Variables are identical
65 to class attributes.) Example:
68 TAG_HANDLER_BEGIN(VARS_ONLY, "CRAZYTAG")
71 wxString something_else;
72 TAG_HANDLER_END(VARS_ONLY)
75 This macro is used only in rare cases.
77 {\bf TAG_HANDLER_CONSTR
}(
{\it name
})
79 This macro supplies object constructor.
{\it name
} is same name as the one
80 from TAG_HANDLER_BEGIN macro. Body of constructor follow after
81 this macro (you must use
{ and
} ). Example:
84 TAG_HANDLER_BEGIN(VARS2, "CRAZYTAG")
87 TAG_HANDLER_CONSTR(vars2)
91 TAG_HANDLER_END(VARS2)
94 Never used in wxHTML :-)
96 {\bf TAG_HANDLER_PROC
}(
{\it varib
})
98 This is very important macro. It defines
\helpref{HandleTag
}{wxhtmlparserhandletag
}
99 method.
{\it varib
} is name of parameter passed to the method, usually
100 {\it tag
}. Body of method follows after this macro.
101 Note than you must use
{ and
} ! Example:
104 TAG_HANDLER_BEGIN(TITLE, "TITLE")
105 TAG_HANDLER_PROC(tag)
107 printf("TITLE found...
\n");
109 TAG_HANDLER_END(TITLE)
112 {\bf TAG_HANDLER_END
}(
{\it name
})
114 Ends definition of tag handler
{\it name
}.
117 \wxheading{Tags Modules
}
119 You can use set of
3 macros TAGS_MODULE_BEGIN, TAGS_MODULE_ADD and
120 TAGS_MODULE_END to inherit new module from
121 \helpref{wxHtmlTagsModule
}{wxhtmltagsmodule
} and to create instance of it.
122 See macros reference:
124 {\bf TAGS_MODULE_BEGIN
}(
{\it modname
})
126 Begins module definition.
{\it modname
} is part of class name and must
129 {\bf TAGS_MODULE_ADD
}(
{\it name
})
131 Adds the handler to this module.
{\it name
} is the identifier from
134 {\bf TAGS_MODULE_END
}(
{\it modname
})
136 Ends the definition of module.
141 TAGS_MODULE_BEGIN(Examples)
142 TAGS_MODULE_ADD(VARS_ONLY)
143 TAGS_MODULE_ADD(VARS2)
144 TAGS_MODULE_ADD(TITLE)
145 TAGS_MODULE_END(Examples)