| 1 |
///////////////////////////////////////////////////////////////////////////// |
| 2 |
// Name: src/html/m_links.cpp |
| 3 |
// Purpose: wxHtml module for links & anchors |
| 4 |
// Author: Vaclav Slavik |
| 5 |
// RCS-ID: $Id: nslinks.cpp,v 1.2 2007/03/08 01:47:14 pabs3 Exp $ |
| 6 |
// Copyright: (c) 1999 Vaclav Slavik |
| 7 |
// Licence: wxWindows licence |
| 8 |
// |
| 9 |
// Reviewed for Unicode support by Jim Park -- 08/23/2007 |
| 10 |
// Basically, compiling wxWidgets as Unicode should do it. |
| 11 |
///////////////////////////////////////////////////////////////////////////// |
| 12 |
|
| 13 |
#include "wx/wxprec.h" |
| 14 |
|
| 15 |
#ifdef __BORLANDC__ |
| 16 |
#pragma hdrstop |
| 17 |
#endif |
| 18 |
|
| 19 |
#if wxUSE_HTML && wxUSE_STREAMS && !defined(NSISMENU_NOLINKTAGHANDLER) |
| 20 |
|
| 21 |
#ifndef WXPRECOMP |
| 22 |
#endif |
| 23 |
|
| 24 |
#include "wx/html/forcelnk.h" |
| 25 |
#include "wx/html/m_templ.h" |
| 26 |
|
| 27 |
#include <wx/filefn.h> |
| 28 |
#include <wx/stdpaths.h> |
| 29 |
|
| 30 |
#include <nsis-sconf.h> |
| 31 |
|
| 32 |
FORCE_LINK_ME(nslinks) |
| 33 |
|
| 34 |
// TODO: These helper function declarations should be in a header file |
| 35 |
typedef enum { SUT_UNKNOWN = 0, SUT_BIN = 0x14, SUT_DOC = 0x24, SUT_WEB = 0x34 } SPECIALURLTYPE; |
| 36 |
SPECIALURLTYPE TransformUrl(wxString&Url); |
| 37 |
|
| 38 |
class wxHtmlAnchorCell : public wxHtmlCell |
| 39 |
{ |
| 40 |
private: |
| 41 |
wxString m_AnchorName; |
| 42 |
|
| 43 |
public: |
| 44 |
wxHtmlAnchorCell(const wxString& name) : wxHtmlCell() |
| 45 |
{ m_AnchorName = name; } |
| 46 |
void Draw(wxDC& WXUNUSED(dc), |
| 47 |
int WXUNUSED(x), int WXUNUSED(y), |
| 48 |
int WXUNUSED(view_y1), int WXUNUSED(view_y2), |
| 49 |
wxHtmlRenderingInfo& WXUNUSED(info)) {} |
| 50 |
|
| 51 |
DECLARE_NO_COPY_CLASS(wxHtmlAnchorCell) |
| 52 |
}; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
TAG_HANDLER_BEGIN(A, "A") |
| 57 |
TAG_HANDLER_CONSTR(A) { } |
| 58 |
|
| 59 |
TAG_HANDLER_PROC(tag) |
| 60 |
{ |
| 61 |
if (tag.HasParam( wxT("HREF") )) |
| 62 |
{ |
| 63 |
wxHtmlLinkInfo oldlnk = m_WParser->GetLink(); |
| 64 |
wxColour oldclr = m_WParser->GetActualColor(); |
| 65 |
wxString href(tag.GetParam( wxT("HREF") )), target; |
| 66 |
|
| 67 |
if (tag.HasParam( wxT("TARGET") )) target = tag.GetParam( wxT("TARGET") ); |
| 68 |
|
| 69 |
wxColour colour = m_WParser->GetLinkColor(); |
| 70 |
wxHtmlLinkInfo linkInfo(href, target); |
| 71 |
|
| 72 |
wxString location = href; |
| 73 |
SPECIALURLTYPE ut = TransformUrl(location); |
| 74 |
if (ut == SUT_BIN || ut == SUT_DOC) |
| 75 |
{ |
| 76 |
if (!wxFileExists(location) && !wxDirExists(location)) |
| 77 |
{ |
| 78 |
colour = wxColour(0x80, 0x80, 0x80); |
| 79 |
linkInfo = wxHtmlLinkInfo(wxT("notinstalled.html"), target); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
m_WParser->SetActualColor(colour); |
| 84 |
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(colour)); |
| 85 |
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont())); |
| 86 |
m_WParser->SetLink(linkInfo); |
| 87 |
|
| 88 |
ParseInner(tag); |
| 89 |
|
| 90 |
m_WParser->SetLink(oldlnk); |
| 91 |
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont())); |
| 92 |
m_WParser->SetActualColor(oldclr); |
| 93 |
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr)); |
| 94 |
|
| 95 |
return true; |
| 96 |
} |
| 97 |
else return false; |
| 98 |
} |
| 99 |
|
| 100 |
TAG_HANDLER_END(A) |
| 101 |
|
| 102 |
|
| 103 |
#if wxCHECK_VERSION(3, 0, 0) |
| 104 |
TAGS_MODULE_BEGIN(Links) |
| 105 |
#else |
| 106 |
TAGS_MODULE_BEGIN(CustomLinks) |
| 107 |
#endif |
| 108 |
|
| 109 |
TAGS_MODULE_ADD(A) |
| 110 |
|
| 111 |
#if wxCHECK_VERSION(3, 0, 0) |
| 112 |
TAGS_MODULE_END(Links) |
| 113 |
#else |
| 114 |
TAGS_MODULE_END(CustomLinks) |
| 115 |
#endif |
| 116 |
|
| 117 |
|
| 118 |
#endif |