1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
void CHTMLEditionDlg::HTMLtoTEXTFormat(CString htmlText)
{
CString strTextFormat(htmlText);
int index;
CHARFORMAT Cfm;
Cfm.cbSize = sizeof(CHARFORMAT);
//on affiche le texte
m_commentaire.SetWindowTextA(strTextFormat);
//on remplace les <U></U> par des zones soulignées
index = strTextFormat.Find("<U>",0);
while(index!=-1 && index<strTextFormat.GetLength())
{
int iFin = strTextFormat.Find("</U>",index);
strTextFormat.Format("%s%s",strTextFormat.Left(iFin),strTextFormat.Mid(iFin+4));
m_commentaire.SetSel(iFin,iFin+4);
m_commentaire.ReplaceSel("",false);
strTextFormat.Format("%s%s",strTextFormat.Left(index),strTextFormat.Mid(index+3));
m_commentaire.SetSel(index,index+3);
m_commentaire.ReplaceSel("",false);
//on applique la mise en forme
m_commentaire.SetSel(index,iFin-3);
m_commentaire.GetSelectionCharFormat(Cfm);
Cfm.dwMask = CFM_UNDERLINE;
Cfm.dwEffects ^= CFE_UNDERLINE;
m_commentaire.SetSelectionCharFormat(Cfm);
//on passe à la balise suivante
index = strTextFormat.Find("<U>",0);
}
//on remplace les <I></I> par des zones en italique
index = strTextFormat.Find("<I>",0);
while(index!=-1 && index<strTextFormat.GetLength())
{
int iFin = strTextFormat.Find("</I>",index);
strTextFormat.Format("%s%s",strTextFormat.Left(iFin),strTextFormat.Mid(iFin+4));
m_commentaire.SetSel(iFin,iFin+4);
m_commentaire.ReplaceSel("",false);
strTextFormat.Format("%s%s",strTextFormat.Left(index),strTextFormat.Mid(index+3));
m_commentaire.SetSel(index,index+3);
m_commentaire.ReplaceSel("",false);
//on applique la mise en forme
m_commentaire.SetSel(index,iFin-3);
m_commentaire.GetSelectionCharFormat(Cfm);
Cfm.dwMask = CFM_ITALIC;
Cfm.dwEffects ^= CFE_ITALIC;
m_commentaire.SetSelectionCharFormat(Cfm);
//on passe à la balise suivante
index = strTextFormat.Find("<I>",0);
}
//on remplace les <B></B> par des zones en gras
index = strTextFormat.Find("<B>",0);
while(index!=-1 && index<strTextFormat.GetLength())
{
int iFin = strTextFormat.Find("</B>",index);
strTextFormat.Format("%s%s",strTextFormat.Left(iFin),strTextFormat.Mid(iFin+4));
m_commentaire.SetSel(iFin,iFin+4);
m_commentaire.ReplaceSel("",false);
strTextFormat.Format("%s%s",strTextFormat.Left(index),strTextFormat.Mid(index+3));
m_commentaire.SetSel(index,index+3);
m_commentaire.ReplaceSel("",false);
//on applique la mise en forme
m_commentaire.SetSel(index,iFin-3);
m_commentaire.GetSelectionCharFormat(Cfm);
Cfm.dwMask = CFM_BOLD;
Cfm.dwEffects ^= CFE_BOLD;
m_commentaire.SetSelectionCharFormat(Cfm);
//on passe à la balise suivante
index = strTextFormat.Find("<B>",0);
}
//on remplace les liens pas des zones soulignées bleues
//TODO
//on remplace les <BR> par des sauts de ligne
index = strTextFormat.ReverseFind('<');
if(index != -1)
index = strTextFormat.Find("<BR>",index);
while(index!=-1 && index>=0)
{
strTextFormat.Format("%s\r\n%s",strTextFormat.Left(index),strTextFormat.Mid(index+4));
m_commentaire.SetSel(index,index+4);
m_commentaire.ReplaceSel("\r\n",false);
index = strTextFormat.ReverseFind('<');
if(index != -1)
index = strTextFormat.Find("<BR>",index);
}
m_commentaire.SetFocus();
} |
Partager