1 // This is a part of the Active Template Library.
2 // Copyright (C) Microsoft Corporation
3 // All rights reserved.
5 // This source code is only intended as a supplement to the
6 // Active Template Library Reference and related
7 // electronic documentation provided with the library.
8 // See these sources for detailed information regarding the
9 // Active Template Library product.
17 #include <atlsiface.h>
22 #pragma pack(push,_ATL_PACKING)
47 ATL_HTML_TAG_BLOCKQUOTE
,
97 ATL_HTML_TAG_NOFRAMES
,
98 ATL_HTML_TAG_NOSCRIPT
,
100 ATL_HTML_TAG_COLGROUP
,
101 ATL_HTML_TAG_FIELDSET
,
104 ATL_HTML_TAG_TEXTAREA
,
115 extern __declspec(selectany
) const ATL_HTML_TAG s_tags
[] =
117 { _T("body"), TAGF_HASEND
| TAGF_BLOCK
},
118 { _T("a"), TAGF_HASEND
},
119 { _T("b"), TAGF_HASEND
},
120 { _T("i"), TAGF_HASEND
},
121 { _T("u"), TAGF_HASEND
},
122 { _T("font"), TAGF_HASEND
},
123 { _T("img"), TAGF_NONE
},
124 { _T("hr"), TAGF_NONE
},
125 { _T("br"), TAGF_NONE
},
126 { _T("div"), TAGF_HASEND
| TAGF_BLOCK
},
127 { _T("blockquote"), TAGF_HASEND
| TAGF_BLOCK
},
128 { _T("adress"), TAGF_HASEND
},
129 { _T("p"), TAGF_HASEND
| TAGF_BLOCK
},
130 { _T("h1"), TAGF_HASEND
| TAGF_BLOCK
},
131 { _T("h2"), TAGF_HASEND
| TAGF_BLOCK
},
132 { _T("h3"), TAGF_HASEND
| TAGF_BLOCK
},
133 { _T("h4"), TAGF_HASEND
| TAGF_BLOCK
},
134 { _T("h5"), TAGF_HASEND
| TAGF_BLOCK
},
135 { _T("h6"), TAGF_HASEND
| TAGF_BLOCK
},
136 { _T("pre"), TAGF_HASEND
| TAGF_BLOCK
},
137 { _T("q"), TAGF_HASEND
},
138 { _T("sub"), TAGF_HASEND
},
139 { _T("sup"), TAGF_HASEND
},
140 { _T("ins"), TAGF_HASEND
},
141 { _T("del"), TAGF_HASEND
},
142 { _T("em"), TAGF_HASEND
},
143 { _T("strong"), TAGF_HASEND
},
144 { _T("dfn"), TAGF_HASEND
},
145 { _T("code"), TAGF_HASEND
},
146 { _T("samp"), TAGF_HASEND
},
147 { _T("kbd"), TAGF_HASEND
},
148 { _T("var"), TAGF_HASEND
},
149 { _T("cite"), TAGF_HASEND
},
150 { _T("abbr"), TAGF_HASEND
},
151 { _T("acronym"), TAGF_HASEND
},
152 { _T("ol"), TAGF_HASEND
| TAGF_BLOCK
},
153 { _T("ul"), TAGF_HASEND
| TAGF_BLOCK
},
154 { _T("li"), TAGF_HASEND
},
155 { _T("dl"), TAGF_HASEND
| TAGF_BLOCK
},
156 { _T("dt"), TAGF_HASEND
},
157 { _T("dd"), TAGF_HASEND
},
158 { _T("table"), TAGF_HASEND
},
159 { _T("tr"), TAGF_HASEND
},
160 { _T("td"), TAGF_HASEND
},
161 { _T("form"), TAGF_HASEND
},
162 { _T("input"), TAGF_HASEND
},
163 { _T("select"), TAGF_HASEND
},
164 { _T("option"), TAGF_HASEND
},
165 { _T("head"), TAGF_HASEND
| TAGF_BLOCK
},
166 { _T("html"), TAGF_HASEND
| TAGF_BLOCK
},
167 { _T("map"), TAGF_HASEND
| TAGF_BLOCK
},
168 { _T("area"), TAGF_BLOCK
},
169 { _T("base"), TAGF_BLOCK
},
170 { _T("bdo"), TAGF_HASEND
},
171 { _T("big"), TAGF_HASEND
},
172 { _T("button"), TAGF_HASEND
},
173 { _T("iframe"), TAGF_HASEND
},
174 { _T("label"), TAGF_HASEND
},
175 { _T("link"), TAGF_NONE
},
176 { _T("meta"), TAGF_BLOCK
},
177 { _T("noframes"), TAGF_BLOCK
},
178 { _T("noscript"), TAGF_BLOCK
},
179 { _T("col"), TAGF_BLOCK
},
180 { _T("colgroup"), TAGF_HASEND
| TAGF_BLOCK
},
181 { _T("fieldset"), TAGF_HASEND
| TAGF_BLOCK
},
182 { _T("legend"), TAGF_HASEND
| TAGF_BLOCK
},
183 { _T("tbody"), TAGF_HASEND
| TAGF_BLOCK
},
184 { _T("textarea"), TAGF_HASEND
| TAGF_BLOCK
},
185 { _T("tfoot"), TAGF_HASEND
| TAGF_BLOCK
},
186 { _T("th"), TAGF_HASEND
| TAGF_BLOCK
},
187 { _T("title"), TAGF_HASEND
| TAGF_BLOCK
},
188 { _T("tt"), TAGF_HASEND
},
189 { _T("small"), TAGF_HASEND
},
190 { _T("span"), TAGF_HASEND
},
191 { _T("object"), TAGF_HASEND
| TAGF_BLOCK
},
192 { _T("param"), TAGF_NONE
},
205 #pragma warning(push)
206 #pragma warning(disable : 4793)
207 AtlHtmlAttrs(int nCount
, ...)
211 va_start(args
, nCount
);
212 for (int i
=0; i
<nCount
; i
++)
214 LPCTSTR szName
= va_arg(args
, LPCTSTR
);
215 LPCTSTR szVal
= va_arg(args
, LPCTSTR
);
222 #pragma warning(push)
223 #pragma warning(disable : 4793)
224 AtlHtmlAttrs(LPCTSTR szFormat
, ...)
226 if (!szFormat
|| !*szFormat
)
231 va_start(args
, szFormat
);
234 strTmp
.FormatV(szFormat
, args
);
237 m_strAttrs
+= _T(" ");
238 m_strAttrs
+= strTmp
;
242 BOOL
Add(LPCTSTR szName
, LPCTSTR szValue
)
245 m_strAttrs
.AppendFormat(_T(" %s=\"%s\""), szName
, szValue
);
247 m_strAttrs
.AppendFormat(_T(" %s"), szName
);
251 #pragma warning(push)
252 #pragma warning(disable : 4793)
253 void AddFormat(LPCTSTR szFormat
, ...)
257 va_start(args
, szFormat
);
260 strTmp
.FormatV(szFormat
, args
);
263 m_strAttrs
+= _T(" ");
264 m_strAttrs
+= strTmp
;
268 void Set(LPCTSTR szAttrs
)
274 if (!isspace(static_cast<unsigned char>(szAttrs
[0])))
276 if (!iswspace(szAttrs
[0]))
278 m_strAttrs
= _T(" ");
279 m_strAttrs
+= szAttrs
;
290 class CStreamOnWriteStream
: public IStream
293 IWriteStream
*m_pWriteStream
;
295 CStreamOnWriteStream()
297 m_pWriteStream
= NULL
;
300 void Init(IWriteStream
*pWriteStream
)
302 m_pWriteStream
= pWriteStream
;
306 STDMETHOD(QueryInterface
)(REFIID riid
, void **ppv
)
313 if (IsEqualGUID(riid
, IID_IUnknown
) ||
314 IsEqualGUID(riid
, IID_IStream
) ||
315 IsEqualGUID(riid
, IID_ISequentialStream
))
317 *ppv
= (IStream
*) this;
320 return E_NOINTERFACE
;
324 ULONG __stdcall
AddRef()
329 ULONG __stdcall
Release()
334 // ISequentialStream methods
335 HRESULT STDMETHODCALLTYPE
Read(void * /*pDest*/, ULONG
/*dwMaxLen*/, ULONG
* /*pdwRead*/)
340 HRESULT STDMETHODCALLTYPE
Write(const void *pv
, ULONG cb
, ULONG
*pcbWritten
)
342 ATLASSUME(m_pWriteStream
);
343 HRESULT hr
= m_pWriteStream
->WriteStream((const char *) pv
, cb
, pcbWritten
);
344 return (hr
==S_OK
) ? S_OK
: STG_E_WRITEFAULT
;
348 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
/*dlibMove*/, DWORD
/*dwOrigin*/, ULARGE_INTEGER
* /*plibNewPosition*/)
353 HRESULT STDMETHODCALLTYPE
SetSize(ULARGE_INTEGER
/*libNewSize*/)
358 HRESULT STDMETHODCALLTYPE
CopyTo(IStream
* /*pstm*/, ULARGE_INTEGER
/*cb*/, ULARGE_INTEGER
* /*pcbRead*/, ULARGE_INTEGER
* /*pcbWritten*/)
363 HRESULT STDMETHODCALLTYPE
Commit(DWORD
/*grfCommitFlags*/)
368 HRESULT STDMETHODCALLTYPE
Revert(void)
373 HRESULT STDMETHODCALLTYPE
LockRegion(ULARGE_INTEGER
/*libOffset*/, ULARGE_INTEGER
/*cb*/, DWORD
/*dwLockType*/)
378 HRESULT STDMETHODCALLTYPE
UnlockRegion(ULARGE_INTEGER
/*libOffset*/, ULARGE_INTEGER
/*cb*/, DWORD
/*dwLockType*/)
383 HRESULT STDMETHODCALLTYPE
Stat(STATSTG
* /*pstatstg*/, DWORD
/*grfStatFlag*/)
389 HRESULT STDMETHODCALLTYPE
Clone(IStream
** /*ppstm*/)
395 class CStreamFormatter
398 CStreamOnWriteStream m_sows
;
402 UINT m_nConversionCodepage
;
409 m_bEmitUnicode
= FALSE
;
410 m_nConversionCodepage
= _AtlGetConversionACP();
413 void Initialize(IStream
*pStream
, BOOL bAddCRLF
=TRUE
)
416 m_bAddCRLF
= bAddCRLF
;
419 void Initialize(IWriteStream
*pWriteStream
, BOOL bAddCRLF
=TRUE
)
421 m_bAddCRLF
= bAddCRLF
;
422 m_sows
.Init(pWriteStream
);
426 void EmitUnicode(BOOL bEmitUnicode
)
428 m_bEmitUnicode
= bEmitUnicode
;
431 void SetConversionCodepage(UINT nConversionCodepage
)
433 m_nConversionCodepage
= nConversionCodepage
;
436 void AddCRLF(bool bNewVal
)
438 m_bAddCRLF
= bNewVal
;
441 HRESULT
WriteRaw(LPCTSTR szString
, int nCount
=-1)
443 ATLENSURE_RETURN(szString
!= NULL
);
450 LPCWSTR sz
= szString
;
452 nCount
= (int) wcslen(szString
);
454 CA2W
sz(szString
, m_nConversionCodepage
);
455 nCount
= (int) wcslen(sz
);
458 return m_pStream
->Write(sz
, (DWORD
) nCount
*sizeof(WCHAR
), &dwWritten
);
463 CW2A
sz(szString
, m_nConversionCodepage
);
464 nCount
= (int) strlen(sz
);
466 LPCSTR sz
= szString
;
468 nCount
= (int) strlen(szString
);
471 return m_pStream
->Write(sz
, (DWORD
) nCount
, &dwWritten
);
475 HRESULT
StartTag(int nTagIndex
, LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
477 if (nTagIndex
< 0 || nTagIndex
>= ATL_HTML_TAG_LAST
)
479 if (m_bAddCRLF
&& (s_tags
[nTagIndex
].uFlags
& TAGF_BLOCK
))
480 WriteRaw(_T("\r\n"));
481 HRESULT hr
= StartTag(s_tags
[nTagIndex
].szTagName
, szContent
, szAttrs
);
484 if (m_bAddCRLF
&& (s_tags
[nTagIndex
].uFlags
& TAGF_BLOCK
))
485 WriteRaw(_T("\r\n"));
489 HRESULT
StartTag(LPCTSTR szTag
, LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
492 hr
= WriteRaw(_T("<"));
495 hr
= WriteRaw(szTag
);
498 hr
= WriteAttributes(szAttrs
);
501 hr
= WriteRaw(_T(">"));
504 if (szContent
&& *szContent
)
512 HRESULT
EndTag(int nTagIndex
)
514 if (nTagIndex
< 0 || nTagIndex
>= ATL_HTML_TAG_LAST
)
516 if (m_bAddCRLF
&& (s_tags
[nTagIndex
].uFlags
& TAGF_BLOCK
))
517 WriteRaw(_T("\r\n"));
518 HRESULT hr
= EndTag(s_tags
[nTagIndex
].szTagName
);
521 if (m_bAddCRLF
&& (s_tags
[nTagIndex
].uFlags
& TAGF_BLOCK
))
522 WriteRaw(_T("\r\n"));
526 HRESULT
EndTag(LPCTSTR szTag
)
528 HRESULT hr
= WriteRaw(_T("</"));
531 hr
= WriteRaw(szTag
);
534 return WriteRaw(_T(">"));
537 HRESULT
WriteAttributes(LPCTSTR szAttrs
)
539 if (szAttrs
&& szAttrs
[0])
542 if (!isspace(static_cast<unsigned char>(szAttrs
[0])))
544 if (!iswspace(szAttrs
[0]))
547 return WriteRaw(szAttrs
);
553 #pragma warning(push)
554 #pragma warning(disable : 4793)
555 HRESULT
WriteFormatted(LPCTSTR szFormat
, ...)
557 ATLASSERT(szFormat
!= NULL
);
562 va_start(args
, szFormat
);
565 TCHAR buffFixed
[1024];
566 CTempBuffer
<TCHAR
> buffHeap
;
567 TCHAR
*szTemp
= buffFixed
;
568 int nCount
= _vstprintf_s((LPTSTR
)szTemp
, _countof(buffFixed
), szFormat
, args
);
571 // we'll have to dynamically allocate the buffer
572 nCount
= _vsctprintf(szFormat
, args
);
574 ATLTRY(szTemp
= buffHeap
.Allocate(nCount
+ 1));
576 return E_OUTOFMEMORY
;
577 nCount
= _vstprintf_s(szTemp
, nCount
+1, szFormat
, args
);
583 return WriteRaw(szTemp
, (DWORD
) nCount
);
589 template <typename TData
, int nMax
=64>
603 return (m_nTop
== -1);
606 bool Push(const TData
*pData
)
608 if (m_nTop
+ 1 >= nMax
)
613 m_Data
[m_nTop
] = *pData
;
617 bool Pop(TData
*pData
)
622 *pData
= m_Data
[m_nTop
];
632 CString strLinkColor
;
633 CString strVLinkColor
;
634 CString strALinkColor
;
635 CString strBackground
;
639 CString strTdBgColor
;
640 CString strTableBgColor
;
641 CString strTrBgColor
;
651 class CHtmlGenBase
: public CStreamFormatter
656 return static_cast<T
*>(this);
659 enum ATL_HTML_FORM_METHOD
{ ATL_HTML_FORM_METHOD_NONE
=0, ATL_HTML_FORM_METHOD_GET
, ATL_HTML_FORM_METHOD_POST
, ATL_HTML_FORM_METHOD_MULTIPART
};
663 m_nWidthPercent
= -1;
664 m_nHeightPercent
= -1;
665 m_nFormMethod
= ATL_HTML_FORM_METHOD_NONE
;
669 void SetScheme(HTML_SCHEME
*pScheme
)
674 HRESULT
body(LPCTSTR szBgColor
=NULL
, LPCTSTR szBackground
=NULL
, LPCTSTR szTopMargin
=NULL
, LPCTSTR szLeftMargin
=NULL
,
675 LPCTSTR szAttrs
=NULL
)
680 if (szBgColor
&& *szBgColor
)
681 Attrs
.Add(_T("bgColor"), szBgColor
);
682 else if (m_pScheme
&& m_pScheme
->strBgColor
.GetLength())
683 Attrs
.Add(_T("bgColor"), m_pScheme
->strBgColor
);
685 if (szBackground
&& *szBackground
)
686 Attrs
.Add(_T("background"), szBackground
);
687 else if (m_pScheme
&& m_pScheme
->strBackground
.GetLength())
688 Attrs
.Add(_T("background"), m_pScheme
->strBackground
);
690 if (m_pScheme
&& m_pScheme
->strLinkColor
.GetLength())
691 Attrs
.Add(_T("link"), m_pScheme
->strLinkColor
);
693 if (m_pScheme
&& m_pScheme
->strALinkColor
.GetLength())
694 Attrs
.Add(_T("alink"), m_pScheme
->strALinkColor
);
696 if (m_pScheme
&& m_pScheme
->strVLinkColor
.GetLength())
697 Attrs
.Add(_T("vlink"), m_pScheme
->strVLinkColor
);
699 if (szTopMargin
&& *szTopMargin
)
700 Attrs
.Add(_T("topmargin"), szTopMargin
);
701 else if (m_pScheme
&& m_pScheme
->nTopMargin
!= -1)
702 Attrs
.AddFormat(_T("topmargin=\"%d\""), m_pScheme
->nTopMargin
);
704 if (szLeftMargin
&& *szLeftMargin
)
705 Attrs
.Add(_T("leftmargin"), szLeftMargin
);
706 else if (m_pScheme
&& m_pScheme
->nLeftMargin
!= -1)
707 Attrs
.AddFormat(_T("leftmargin=\"%d\""), m_pScheme
->nLeftMargin
);
709 return GetOuter()->StartTag(ATL_HTML_TAG_BODY
, NULL
, Attrs
);
714 return GetOuter()->EndTag(ATL_HTML_TAG_BODY
);
717 HRESULT
a(LPCTSTR szHref
, LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
722 if (m_strState
.GetLength()==0)
724 if (szHref
&& *szHref
)
725 Attrs
.Add(_T("href"), szHref
);
726 return GetOuter()->StartTag(ATL_HTML_TAG_A
, szContent
, Attrs
);
729 const TCHAR
*szQuestion
= NULL
;
731 szQuestion
= _tcschr(szHref
, '?');
733 CString strHref
= szHref
;
739 strHref
+= m_strState
;
741 if (szHref
&& *szHref
)
742 Attrs
.Add(_T("href"), strHref
);
744 return GetOuter()->StartTag(ATL_HTML_TAG_A
, szContent
, Attrs
);
749 return GetOuter()->EndTag(ATL_HTML_TAG_A
);
752 HRESULT
b(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
754 return GetOuter()->StartTag(ATL_HTML_TAG_B
, szContent
, szAttrs
);
759 return GetOuter()->EndTag(ATL_HTML_TAG_B
);
762 HRESULT
i(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
764 return GetOuter()->StartTag(ATL_HTML_TAG_I
, szContent
, szAttrs
);
769 return GetOuter()->EndTag(ATL_HTML_TAG_I
);
772 HRESULT
u(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
774 return GetOuter()->StartTag(ATL_HTML_TAG_U
, szContent
, szAttrs
);
779 return GetOuter()->EndTag(ATL_HTML_TAG_U
);
782 HRESULT
font(LPCTSTR szFace
, LPCTSTR szSize
=NULL
, LPCTSTR szColor
=NULL
, LPCTSTR szAttrs
=NULL
)
786 if (szFace
&& *szFace
)
787 Attrs
.Add(_T("face"), szFace
);
788 if (szSize
&& *szSize
)
789 Attrs
.Add(_T("size"), szSize
);
790 if (szColor
&& *szColor
)
791 Attrs
.Add(_T("color"), szColor
);
792 return GetOuter()->StartTag(ATL_HTML_TAG_FONT
, NULL
, Attrs
);
795 HRESULT
font(COLORREF clrColor
, LPCTSTR szAttrs
=NULL
)
798 _stprintf_s(szColor
, _countof(szColor
), _T("#%02x%02x%02x"), GetRValue(clrColor
),
799 GetGValue(clrColor
), GetBValue(clrColor
));
800 return GetOuter()->font(NULL
, NULL
, szColor
, szAttrs
);
805 return GetOuter()->EndTag(ATL_HTML_TAG_FONT
);
808 HRESULT
img(LPCTSTR szSrc
, LPCTSTR szAttrs
=NULL
)
810 ATLASSERT(szSrc
&& *szSrc
);
815 Attrs
.Add(_T("src"), szSrc
);
817 return GetOuter()->StartTag(ATL_HTML_TAG_IMG
, NULL
, Attrs
);
820 HRESULT
br(LPCTSTR szAttrs
=NULL
)
822 return GetOuter()->StartTag(ATL_HTML_TAG_BR
, NULL
, szAttrs
);
825 HRESULT
hr(LPCTSTR szAttrs
=NULL
)
827 return GetOuter()->StartTag(ATL_HTML_TAG_HR
, NULL
, szAttrs
);
830 HRESULT
div(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
832 return GetOuter()->StartTag(ATL_HTML_TAG_DIV
, szContent
, szAttrs
);
837 return GetOuter()->EndTag(ATL_HTML_TAG_DIV
);
840 HRESULT
blockquote(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
842 return GetOuter()->StartTag(ATL_HTML_TAG_BLOCKQUOTE
, szContent
, szAttrs
);
845 HRESULT
blockquoteEnd()
847 return GetOuter()->EndTag(ATL_HTML_TAG_BLOCKQUOTE
);
850 HRESULT
address(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
852 return GetOuter()->StartTag(ATL_HTML_TAG_ADDRESS
, szContent
, szAttrs
);
857 return GetOuter()->EndTag(ATL_HTML_TAG_ADDRESS
);
860 HRESULT
p(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
862 return GetOuter()->StartTag(ATL_HTML_TAG_P
, szContent
, szAttrs
);
867 return GetOuter()->EndTag(ATL_HTML_TAG_P
);
870 HRESULT
h(int nLevel
=1, LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
872 if (nLevel
< 1 || nLevel
> 6)
874 return GetOuter()->StartTag(ATL_HTML_TAG_H1
+nLevel
-1, szContent
, szAttrs
);
877 HRESULT
hEnd(int nLevel
=1)
879 if (nLevel
< 1 || nLevel
> 6)
881 return GetOuter()->EndTag(ATL_HTML_TAG_H1
+nLevel
-1);
884 HRESULT
pre(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
886 return GetOuter()->StartTag(ATL_HTML_TAG_PRE
, szContent
, szAttrs
);
891 return GetOuter()->EndTag(ATL_HTML_TAG_PRE
);
894 HRESULT
q(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
896 return GetOuter()->StartTag(ATL_HTML_TAG_Q
, szContent
, szAttrs
);
901 return GetOuter()->EndTag(ATL_HTML_TAG_Q
);
904 HRESULT
sub(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
906 return GetOuter()->StartTag(ATL_HTML_TAG_SUB
, szContent
, szAttrs
);
911 return GetOuter()->EndTag(ATL_HTML_TAG_SUB
);
914 HRESULT
sup(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
916 return GetOuter()->StartTag(ATL_HTML_TAG_SUP
, szContent
, szAttrs
);
921 return GetOuter()->EndTag(ATL_HTML_TAG_SUP
);
924 HRESULT
ins(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
926 return GetOuter()->StartTag(ATL_HTML_TAG_INS
, szContent
, szAttrs
);
931 return GetOuter()->EndTag(ATL_HTML_TAG_INS
);
934 HRESULT
del(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
936 return GetOuter()->StartTag(ATL_HTML_TAG_DEL
, szContent
, szAttrs
);
941 return GetOuter()->EndTag(ATL_HTML_TAG_DEL
);
945 HRESULT
em(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
947 return GetOuter()->StartTag(ATL_HTML_TAG_EM
, szContent
, szAttrs
);
952 return GetOuter()->EndTag(ATL_HTML_TAG_EM
);
955 HRESULT
strong(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
957 return GetOuter()->StartTag(ATL_HTML_TAG_STRONG
, szContent
, szAttrs
);
962 return GetOuter()->EndTag(ATL_HTML_TAG_STRONG
);
965 HRESULT
dfn(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
967 return GetOuter()->StartTag(ATL_HTML_TAG_DFN
, szContent
, szAttrs
);
972 return GetOuter()->EndTag(ATL_HTML_TAG_DFN
);
975 HRESULT
code(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
977 return GetOuter()->StartTag(ATL_HTML_TAG_CODE
, szContent
, szAttrs
);
982 return GetOuter()->EndTag(ATL_HTML_TAG_CODE
);
985 HRESULT
samp(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
987 return GetOuter()->StartTag(ATL_HTML_TAG_SAMP
, szContent
, szAttrs
);
992 return GetOuter()->EndTag(ATL_HTML_TAG_SAMP
);
995 HRESULT
kbd(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
997 return GetOuter()->StartTag(ATL_HTML_TAG_KBD
, szContent
, szAttrs
);
1002 return GetOuter()->EndTag(ATL_HTML_TAG_KBD
);
1005 HRESULT
var(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1007 return GetOuter()->StartTag(ATL_HTML_TAG_VAR
, szContent
, szAttrs
);
1012 return GetOuter()->EndTag(ATL_HTML_TAG_VAR
);
1015 HRESULT
cite(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1017 return GetOuter()->StartTag(ATL_HTML_TAG_CITE
, szContent
, szAttrs
);
1022 return GetOuter()->EndTag(ATL_HTML_TAG_CITE
);
1025 HRESULT
abbr(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1027 return GetOuter()->StartTag(ATL_HTML_TAG_ABBR
, szContent
, szAttrs
);
1032 return GetOuter()->EndTag(ATL_HTML_TAG_ABBR
);
1035 HRESULT
acronym(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1037 return GetOuter()->StartTag(ATL_HTML_TAG_ACRONYM
, szContent
, szAttrs
);
1040 HRESULT
acronymEnd()
1042 return GetOuter()->EndTag(ATL_HTML_TAG_ACRONYM
);
1046 HRESULT
ol(LPCTSTR szAttrs
=NULL
)
1048 return GetOuter()->StartTag(ATL_HTML_TAG_OL
, NULL
, szAttrs
);
1051 HRESULT
ul(LPCTSTR szAttrs
=NULL
)
1053 return GetOuter()->StartTag(ATL_HTML_TAG_UL
, NULL
, szAttrs
);
1058 return GetOuter()->EndTag(ATL_HTML_TAG_OL
);
1063 return GetOuter()->EndTag(ATL_HTML_TAG_UL
);
1066 HRESULT
li(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1068 return GetOuter()->StartTag(ATL_HTML_TAG_LI
, szContent
, szAttrs
);
1073 return GetOuter()->EndTag(ATL_HTML_TAG_LI
);
1076 HRESULT
dl(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1078 return GetOuter()->StartTag(ATL_HTML_TAG_DL
, szContent
, szAttrs
);
1083 return GetOuter()->EndTag(ATL_HTML_TAG_DL
);
1086 HRESULT
dt(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1088 return GetOuter()->StartTag(ATL_HTML_TAG_DT
, szContent
, szAttrs
);
1093 return GetOuter()->EndTag(ATL_HTML_TAG_DT
);
1096 HRESULT
dd(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1098 return GetOuter()->StartTag(ATL_HTML_TAG_DD
, szContent
, szAttrs
);
1103 return GetOuter()->EndTag(ATL_HTML_TAG_DD
);
1106 void SetSizePercent(int nWidth
, int nHeight
)
1108 m_nWidthPercent
= nWidth
;
1109 m_nHeightPercent
= nHeight
;
1112 HRESULT
table(int nBorderWidth
=0, LPCTSTR szAttrs
=NULL
)
1117 m_RowStack
.Push(&m_tableState
);
1118 m_tableState
.Clear();
1120 Attrs
.AddFormat(_T("border=\"%d\""), nBorderWidth
);
1122 if (m_nWidthPercent
!= -1)
1123 Attrs
.AddFormat(_T("width=\"%d%%\""), m_nWidthPercent
);
1124 if (m_nHeightPercent
!= -1)
1125 Attrs
.AddFormat(_T("height=\"%d%%\""), m_nHeightPercent
);
1127 if (m_pScheme
&& m_pScheme
->strTableBgColor
.GetLength())
1128 Attrs
.Add(_T("bgcolor"), m_pScheme
->strTableBgColor
);
1130 m_nWidthPercent
= -1;
1131 m_nHeightPercent
= -1;
1132 return GetOuter()->StartTag(ATL_HTML_TAG_TABLE
, NULL
, Attrs
);
1137 if (m_tableState
.m_bRowOpen
)
1138 GetOuter()->trEnd();
1139 m_RowStack
.Pop(&m_tableState
);
1140 return GetOuter()->EndTag(ATL_HTML_TAG_TABLE
);
1143 HRESULT
tr(LPCTSTR szAttrs
=NULL
)
1148 if (m_RowStack
.IsEmpty())
1149 GetOuter()->table();
1150 if (m_tableState
.m_bRowOpen
)
1151 GetOuter()->trEnd();
1152 m_tableState
.m_bRowOpen
= true;
1154 if (m_pScheme
&& m_pScheme
->strTrBgColor
.GetLength())
1155 Attrs
.Add(_T("bgcolor"), m_pScheme
->strTrBgColor
);
1156 return GetOuter()->StartTag(ATL_HTML_TAG_TR
, NULL
, Attrs
);
1159 HRESULT
td(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1164 if (!m_tableState
.m_bRowOpen
)
1166 m_tableState
.m_bDataOpen
= true;
1167 if (m_pScheme
&& m_pScheme
->strTdBgColor
.GetLength())
1168 Attrs
.Add(_T("bgColor"), m_pScheme
->strTdBgColor
);
1170 HRESULT hr
= GetOuter()->StartTag(ATL_HTML_TAG_TD
, szContent
, Attrs
);
1174 m_tableState
.m_bDataOpen
= false;
1180 if (!m_tableState
.m_bDataOpen
)
1182 m_tableState
.m_bDataOpen
= false;
1183 return GetOuter()->EndTag(ATL_HTML_TAG_TD
);
1188 if (!m_tableState
.m_bRowOpen
)
1190 if (m_tableState
.m_bDataOpen
)
1191 GetOuter()->tdEnd();
1192 m_tableState
.m_bRowOpen
= false;
1193 return GetOuter()->EndTag(ATL_HTML_TAG_TR
);
1196 HRESULT
form(LPCTSTR szAction
, ATL_HTML_FORM_METHOD nMethod
=ATL_HTML_FORM_METHOD_GET
, LPCTSTR szAttrs
=NULL
)
1198 static const LPCTSTR s_szFormMethods
[] = { NULL
, _T("get"), _T("post"), _T("multipart-www-url-encoded") };
1199 return GetOuter()->form(szAction
, s_szFormMethods
[nMethod
], szAttrs
);
1202 HRESULT
form(LPCTSTR szAction
, LPCTSTR szMethod
, LPCTSTR szAttrs
=NULL
)
1207 if (szAction
&& *szAction
)
1208 Attrs
.Add(_T("action"), szAction
);
1209 if (szMethod
&& *szMethod
)
1210 Attrs
.Add(_T("method"), szMethod
);
1212 return GetOuter()->StartTag(ATL_HTML_TAG_FORM
, NULL
, Attrs
);
1215 HRESULT
input(LPCTSTR szType
, LPCTSTR szName
, LPCTSTR szValue
, LPCTSTR szAttrs
=NULL
)
1220 if (szType
&& *szType
)
1221 Attrs
.Add(_T("type"), szType
);
1222 if (szName
&& *szName
)
1223 Attrs
.Add(_T("name"), szName
);
1224 if (szValue
&& *szValue
)
1225 Attrs
.Add(_T("value"), szValue
);
1226 return GetOuter()->StartTag(ATL_HTML_TAG_INPUT
, NULL
, Attrs
);
1229 HRESULT
submit(LPCTSTR szValue
=NULL
, LPCTSTR szName
=NULL
, LPCTSTR szAttrs
=NULL
)
1231 return input(_T("submit"), szName
, szValue
, szAttrs
);
1234 HRESULT
textarea(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1236 return GetOuter()->StartTag(ATL_HTML_TAG_TEXTAREA
, szContent
, szAttrs
);
1239 HRESULT
textareaEnd()
1241 return GetOuter()->EndTag(ATL_HTML_TAG_TEXTAREA
);
1246 return GetOuter()->EndTag(ATL_HTML_TAG_FORM
);
1250 HRESULT
select(LPCTSTR szName
, BOOL bMultiple
=FALSE
, LPCTSTR szAttrs
=NULL
)
1252 ATLASSERT(szName
&& *szName
);
1257 Attrs
.Add(_T("name"), szName
);
1259 Attrs
.Add(_T("multiple"), NULL
);
1260 return GetOuter()->StartTag(ATL_HTML_TAG_SELECT
, NULL
, Attrs
);
1263 HRESULT
option(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1265 return GetOuter()->StartTag(ATL_HTML_TAG_OPTION
, szContent
, szAttrs
);
1270 return GetOuter()->EndTag(ATL_HTML_TAG_OPTION
);
1275 return GetOuter()->EndTag(ATL_HTML_TAG_SELECT
);
1279 HRESULT
head(LPCTSTR szAttrs
=NULL
)
1281 return GetOuter()->StartTag(ATL_HTML_TAG_HEAD
, NULL
, szAttrs
);
1286 return GetOuter()->EndTag(ATL_HTML_TAG_HEAD
);
1289 HRESULT
html(LPCTSTR szAttrs
=NULL
)
1291 return GetOuter()->StartTag(ATL_HTML_TAG_HTML
, NULL
, szAttrs
);
1296 return GetOuter()->EndTag(ATL_HTML_TAG_HTML
);
1299 HRESULT
map(LPCTSTR szName
, LPCTSTR szAttrs
=NULL
)
1301 ATLASSERT(szName
&& *szName
);
1306 Attrs
.Add(_T("name"), szName
);
1307 return GetOuter()->StartTag(ATL_HTML_TAG_MAP
, NULL
, Attrs
);
1312 return GetOuter()->EndTag(ATL_HTML_TAG_MAP
);
1315 HRESULT
area(LPCTSTR szAlt
, LPCTSTR szHref
=NULL
, LPCTSTR szAttrs
=NULL
)
1320 if (szAlt
&& *szAlt
)
1321 Attrs
.Add(_T("alt"), szAlt
);
1322 if (szHref
&& *szHref
)
1323 Attrs
.Add(_T("href"), szHref
);
1324 return GetOuter()->StartTag(ATL_HTML_TAG_AREA
, NULL
, Attrs
);
1327 HRESULT
base(LPCTSTR szHref
, LPCTSTR szAttrs
=NULL
)
1329 ATLASSERT(szHref
&& *szHref
);
1334 Attrs
.Add(_T("href"), szHref
);
1335 return GetOuter()->StartTag(ATL_HTML_TAG_BASE
, NULL
, Attrs
);
1338 HRESULT
bdo(LPCTSTR szDir
, LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1340 ATLASSERT(szDir
&& *szDir
);
1345 Attrs
.Add(_T("dir"), szDir
);
1346 return GetOuter()->StartTag(ATL_HTML_TAG_BDO
, szContent
, Attrs
);
1351 return GetOuter()->EndTag(ATL_HTML_TAG_BDO
);
1354 HRESULT
big(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1356 return GetOuter()->StartTag(ATL_HTML_TAG_BIG
, szContent
, szAttrs
);
1361 return GetOuter()->EndTag(ATL_HTML_TAG_BIG
);
1364 HRESULT
button(LPCTSTR szName
=NULL
, LPCTSTR szValue
=NULL
, LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1369 if (szName
&& *szName
)
1370 Attrs
.Add(_T("name"), szName
);
1371 if (szValue
&& *szValue
)
1372 Attrs
.Add(_T("value"), szValue
);
1373 return GetOuter()->StartTag(ATL_HTML_TAG_BUTTON
, szContent
, Attrs
);
1378 return GetOuter()->EndTag(ATL_HTML_TAG_BUTTON
);
1381 HRESULT
iframe(LPCTSTR szSrc
=NULL
, LPCTSTR szWidth
=NULL
, LPCTSTR szHeight
=NULL
, LPCTSTR szAttrs
=NULL
)
1386 if (szSrc
&& *szSrc
)
1387 Attrs
.Add(_T("src"), szSrc
);
1388 if (szWidth
&& *szWidth
)
1389 Attrs
.Add(_T("width"), szWidth
);
1390 if (szHeight
&& *szHeight
)
1391 Attrs
.Add(_T("height"), szHeight
);
1392 return GetOuter()->StartTag(ATL_HTML_TAG_IFRAME
, NULL
, Attrs
);
1397 return GetOuter()->EndTag(ATL_HTML_TAG_IFRAME
);
1400 HRESULT
label(LPCTSTR szFor
=NULL
, LPCTSTR szAccessKey
=NULL
, LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1405 if (szFor
&& *szFor
)
1406 Attrs
.Add(_T("for"), szFor
);
1407 if (szAccessKey
&& *szAccessKey
)
1408 Attrs
.Add(_T("accesskey"), szAccessKey
);
1409 return GetOuter()->StartTag(ATL_HTML_TAG_LABEL
, szContent
, Attrs
);
1414 return GetOuter()->EndTag(ATL_HTML_TAG_LABEL
);
1417 HRESULT
link(LPCTSTR szRel
=NULL
, LPCTSTR szHref
=NULL
, LPCTSTR szAttrs
=NULL
)
1422 if (szRel
&& *szRel
)
1423 Attrs
.Add(_T("rel"), szRel
);
1424 if (szHref
&& *szHref
)
1425 Attrs
.Add(_T("href"), szHref
);
1426 return GetOuter()->StartTag(ATL_HTML_TAG_LINK
, NULL
, Attrs
);
1429 HRESULT
meta(LPCTSTR szName
=NULL
, LPCTSTR szContent
=NULL
, LPCTSTR szHttpEquiv
=NULL
, LPCTSTR szAttrs
=NULL
)
1434 if (szName
&& *szName
)
1435 Attrs
.Add(_T("name"), szName
);
1436 if (szContent
&& *szContent
)
1437 Attrs
.Add(_T("content"), szContent
);
1438 if (szHttpEquiv
&& *szHttpEquiv
)
1439 Attrs
.Add(_T("http-equiv"), szHttpEquiv
);
1440 return GetOuter()->StartTag(ATL_HTML_TAG_META
, NULL
, Attrs
);
1443 HRESULT
noframes(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1445 return GetOuter()->StartTag(ATL_HTML_TAG_NOFRAMES
, szContent
, szAttrs
);
1448 HRESULT
noframesEnd()
1450 return GetOuter()->EndTag(ATL_HTML_TAG_NOFRAMES
);
1453 HRESULT
noscript(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1455 return GetOuter()->StartTag(ATL_HTML_TAG_NOSCRIPT
, szContent
, szAttrs
);
1458 HRESULT
noscriptEnd()
1460 return GetOuter()->EndTag(ATL_HTML_TAG_NOSCRIPT
);
1463 HRESULT
col(int nSpan
=1, LPCTSTR szWidth
=NULL
, LPCTSTR szHeight
=NULL
, LPCTSTR szVAlign
=NULL
,
1464 LPCTSTR szHAlign
=NULL
, LPCTSTR szAttrs
=NULL
)
1471 Attrs
.AddFormat(_T("span"), _T("\"%d\""), nSpan
);
1472 if (szWidth
&& *szWidth
)
1473 Attrs
.Add(_T("width"), szWidth
);
1474 if (szHeight
&& *szHeight
)
1475 Attrs
.Add(_T("height"), szHeight
);
1476 if (szVAlign
&& *szVAlign
)
1477 Attrs
.Add(_T("valign"), szVAlign
);
1478 if (szHAlign
&& *szHAlign
)
1479 Attrs
.Add(_T("align"), szHAlign
);
1480 return GetOuter()->StartTag(ATL_HTML_TAG_COL
, NULL
, Attrs
);
1483 HRESULT
colgroup(int nSpan
=1, LPCTSTR szWidth
=NULL
, LPCTSTR szHeight
=NULL
, LPCTSTR szVAlign
=NULL
,
1484 LPCTSTR szHAlign
=NULL
, LPCTSTR szAttrs
=NULL
)
1490 Attrs
.AddFormat(_T("span"), _T("\"%d\""), nSpan
);
1491 if (szWidth
&& *szWidth
)
1492 Attrs
.Add(_T("width"), szWidth
);
1493 if (szHeight
&& *szHeight
)
1494 Attrs
.Add(_T("height"), szHeight
);
1495 if (szVAlign
&& *szVAlign
)
1496 Attrs
.Add(_T("valign"), szVAlign
);
1497 if (szHAlign
&& *szHAlign
)
1498 Attrs
.Add(_T("align"), szHAlign
);
1499 return GetOuter()->StartTag(ATL_HTML_TAG_COL
, NULL
, Attrs
);
1502 HRESULT
colgroupEnd()
1504 return GetOuter()->EndTag(ATL_HTML_TAG_COLGROUP
);
1507 HRESULT
fieldset(LPCTSTR szAttrs
=NULL
)
1509 return GetOuter()->StartTag(ATL_HTML_TAG_FIELDSET
, NULL
, szAttrs
);
1512 HRESULT
fieldsetEnd()
1514 return GetOuter()->EndTag(ATL_HTML_TAG_FIELDSET
);
1517 HRESULT
legend(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1519 return GetOuter()->StartTag(ATL_HTML_TAG_LEGEND
, szContent
, szAttrs
);
1524 return GetOuter()->EndTag(ATL_HTML_TAG_LEGEND
);
1527 HRESULT
tbody(LPCTSTR szAttrs
=NULL
)
1529 return GetOuter()->StartTag(ATL_HTML_TAG_TBODY
, NULL
, szAttrs
);
1534 return GetOuter()->StartTag(ATL_HTML_TAG_TBODY
);
1537 HRESULT
tfoot(LPCTSTR szAttrs
=NULL
)
1539 return GetOuter()->StartTag(ATL_HTML_TAG_TFOOT
, NULL
, szAttrs
);
1544 return GetOuter()->StartTag(ATL_HTML_TAG_TFOOT
);
1547 HRESULT
th(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1549 if (!m_tableState
.m_bRowOpen
)
1551 m_tableState
.m_bDataOpen
= true;
1552 return GetOuter()->StartTag(ATL_HTML_TAG_TH
, szContent
, szAttrs
);
1557 ATLASSUME(m_tableState
.m_bDataOpen
);
1558 m_tableState
.m_bDataOpen
= false;
1559 return GetOuter()->EndTag(ATL_HTML_TAG_TH
);
1562 HRESULT
title(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1564 return GetOuter()->StartTag(ATL_HTML_TAG_TITLE
, szContent
, szAttrs
);
1569 return GetOuter()->EndTag(ATL_HTML_TAG_TITLE
);
1572 HRESULT
tt(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1574 return GetOuter()->StartTag(ATL_HTML_TAG_TT
, szContent
, szAttrs
);
1579 return GetOuter()->EndTag(ATL_HTML_TAG_TT
);
1582 // unfortunately, we can't use small since it is defined as char
1584 HRESULT
_small(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1586 return GetOuter()->StartTag(ATL_HTML_TAG_SMALL
, szContent
, szAttrs
);
1591 return GetOuter()->EndTag(ATL_HTML_TAG_SMALL
);
1594 HRESULT
span(LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1596 return GetOuter()->StartTag(ATL_HTML_TAG_SPAN
, szContent
, szAttrs
);
1601 return GetOuter()->EndTag(ATL_HTML_TAG_SPAN
);
1604 HRESULT
object(LPCTSTR szClassId
, LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1608 if (szClassId
&& *szClassId
)
1609 Attrs
.Add(_T("classid"), szClassId
);
1610 return GetOuter()->StartTag(ATL_HTML_TAG_OBJECT
, szContent
, Attrs
);
1613 HRESULT
object(REFCLSID rclsid
, LPCTSTR szContent
=NULL
, LPCTSTR szAttrs
=NULL
)
1616 OLECHAR szClsid
[64];
1618 int i
= StringFromGUID2(rclsid
, szClsid
, 64);
1621 szClsid
[i
-2] = 0; // don't want curly braces
1622 strClassId
.Format(_T("clsid:%s"), OLE2T_EX_DEF(szClsid
+1));
1623 return object(strClassId
, szContent
, szAttrs
);
1628 return GetOuter()->EndTag(ATL_HTML_TAG_OBJECT
);
1631 HRESULT
param(LPCTSTR szName
, LPCTSTR szValue
, LPCTSTR szAttrs
=NULL
)
1633 ATLASSERT(szName
&& *szName
);
1638 Attrs
.Add(_T("name"), szName
);
1639 if (szValue
&& *szValue
)
1640 Attrs
.Add(_T("value"), szValue
);
1641 return GetOuter()->StartTag(ATL_HTML_TAG_PARAM
, NULL
, Attrs
);
1646 HTML_SCHEME
*m_pScheme
;
1650 TableState() : m_bRowOpen(false), m_bDataOpen(false)
1658 m_bDataOpen
= false;
1665 ATL_HTML_FORM_METHOD m_nFormMethod
;
1667 TableState m_tableState
;
1668 CSimpleStack
<TableState
> m_RowStack
;
1670 int m_nWidthPercent
;
1671 int m_nHeightPercent
;
1674 class CHtmlGen
: public CHtmlGenBase
<CHtmlGen
>
1682 #endif // __ATLHTML_H__