]>
git.saurik.com Git - wxWidgets.git/blob - src/html/m_pre.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxHtml module for <PRE> ... </PRE> tag (code citation) 
   4 // Author:      Vaclav Slavik 
   6 // Copyright:   (c) 1999 Vaclav Slavik 
   7 // Licence:     wxWindows Licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  11 #pragma implementation 
  14 #include "wx/wxprec.h" 
  17 #if wxUSE_HTML && wxUSE_STREAMS 
  25 #include "wx/html/forcelnk.h" 
  26 #include "wx/html/m_templ.h" 
  28 #include "wx/html/htmlcell.h" 
  29 #include "wx/tokenzr.h" 
  30 #include "wx/encconv.h" 
  34 // replaces '\t', ' ' and '\n' with HTML markup: 
  35 static wxString LINKAGEMODE 
HtmlizeWhitespaces(const wxString
& str
) 
  38     size_t i 
= 0, j 
= 0, len 
= str
.Len(); 
  39     for (i 
= 0; i 
< len
; i
++) 
  44                 while (i 
< len 
&& str
[i
] != wxT('>')) 
  55                 for (j 
= 8 - i%8
; j 
> 0; j
--) out 
<< wxT(" "); 
  66 //----------------------------------------------------------------------------- 
  68 //----------------------------------------------------------------------------- 
  71 TAG_HANDLER_BEGIN(PRE
, "PRE") 
  75         wxHtmlContainerCell 
*c
; 
  77         int fixed 
= m_WParser
->GetFontFixed(), 
  78             italic 
= m_WParser
->GetFontItalic(), 
  79             underlined 
= m_WParser
->GetFontUnderlined(), 
  80             bold 
= m_WParser
->GetFontBold(), 
  81             fsize 
= m_WParser
->GetFontSize(); 
  83         c 
= m_WParser
->GetContainer(); 
  84         m_WParser
->SetFontUnderlined(FALSE
); 
  85         m_WParser
->SetFontBold(FALSE
); 
  86         m_WParser
->SetFontItalic(FALSE
); 
  87         m_WParser
->SetFontFixed(TRUE
); 
  88         m_WParser
->SetFontSize(3); 
  89         c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont())); 
  91         m_WParser
->CloseContainer(); 
  92         c 
= m_WParser
->OpenContainer(); 
  93         c
->SetAlignHor(wxHTML_ALIGN_LEFT
); 
  94         c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
); 
  97             m_WParser
->GetSource()->Mid(tag
.GetBeginPos(), 
  98                                         tag
.GetEndPos1() - tag
.GetBeginPos()); 
  99         // It is safe to temporarily change the source being parsed, 
 100         // provided we restore the state back after parsing 
 101         m_Parser
->SetSourceAndSaveState(HtmlizeWhitespaces(srcMid
)); 
 102         m_Parser
->DoParsing(); 
 103         m_Parser
->RestoreState(); 
 105         m_WParser
->CloseContainer(); 
 106         c 
= m_WParser
->OpenContainer(); 
 108         m_WParser
->SetFontUnderlined(underlined
); 
 109         m_WParser
->SetFontBold(bold
); 
 110         m_WParser
->SetFontItalic(italic
); 
 111         m_WParser
->SetFontFixed(fixed
); 
 112         m_WParser
->SetFontSize(fsize
); 
 113         c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont())); 
 124 TAGS_MODULE_BEGIN(Pre
)