00001
00002
00003
00004
00005
00006
00007
00008
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <wx/wxprec.h>
00022
00023 #ifdef __BORLANDC__
00024 #pragma hdrstop
00025 #endif
00026
00027
00028
00029 #ifndef WX_PRECOMP
00030 #include <wx/wx.h>
00031 #endif
00032
00033
00034 #include <wx/mimetype.h>
00035
00036
00037 #include "hyperlink.h"
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 IMPLEMENT_DYNAMIC_CLASS (wxHyperLink, wxStaticText)
00059
00060 BEGIN_EVENT_TABLE (wxHyperLink, wxStaticText)
00061 EVT_ENTER_WINDOW (wxHyperLink::OnWindowEnter)
00062 EVT_LEAVE_WINDOW (wxHyperLink::OnWindowLeave)
00063 EVT_LEFT_DCLICK (wxHyperLink::OnLinkActivate)
00064 EVT_LEFT_DOWN (wxHyperLink::OnLinkActivate)
00065 END_EVENT_TABLE()
00066
00067 bool wxHyperLink::Create (wxWindow *parent,
00068 wxWindowID id,
00069 const wxString &label,
00070 const wxPoint &pos,
00071 const wxSize &size,
00072 long style,
00073 const wxString &name) {
00074 bool okay = FALSE;
00075
00076
00077 okay = wxStaticText::Create (parent, id, label, pos, size, style, name);
00078 wxASSERT_MSG (okay, _("Failed to create wxStaticText, needed by wxHyperLink!"));
00079
00080
00081 m_URL = wxEmptyString;
00082 m_Marked = false;
00083 m_Visited = false;
00084 m_MarkedColour = wxColour ("DARK GREY");
00085 m_NormalColour = wxColour ("BLUE");
00086 m_VisitedColour = wxColour ("PURPLE");
00087 m_HoverCursor = wxCursor (wxCURSOR_HAND);
00088
00089
00090 SetForegroundColour (m_NormalColour);
00091 wxFont font = GetFont();
00092 font.SetUnderlined (true);
00093 SetFont (font);
00094
00095
00096 m_BackgroundColour = GetBackgroundColour ();
00097
00098 return okay;
00099 }
00100
00101
00102
00103
00104 void wxHyperLink::OnWindowEnter (wxMouseEvent &WXUNUSED(event)) {
00105 SetCursor (m_HoverCursor);
00106 Refresh();
00107 }
00108
00109 void wxHyperLink::OnWindowLeave (wxMouseEvent &WXUNUSED(event)) {
00110 SetCursor (wxNullCursor);
00111 Refresh();
00112 }
00113
00114 void wxHyperLink::OnLinkActivate (wxMouseEvent &WXUNUSED(event)) {
00115 m_Visited = TRUE;
00116 SetForegroundColour (m_VisitedColour);
00117 SetBackgroundColour (m_BackgroundColour);
00118 Refresh();
00119 if (m_URL.IsEmpty()) {
00120 ExecuteLink (GetLabel());
00121 }else{
00122 ExecuteLink (m_URL);
00123 }
00124 }
00125
00126
00127
00128
00129 wxCursor wxHyperLink::GetHoverCursor () {
00130 return m_HoverCursor;
00131 }
00132
00133 void wxHyperLink::SetHoverCursor (wxCursor cursor) {
00134 m_HoverCursor = cursor;
00135 }
00136
00137 wxColour wxHyperLink::GetMarkedColour () {
00138 return m_MarkedColour;
00139 }
00140
00141 void wxHyperLink::SetMarkedColour (wxColour colour) {
00142 m_MarkedColour = colour;
00143 }
00144
00145 wxColour wxHyperLink::GetNormalColour () {
00146 return m_NormalColour;
00147 }
00148
00149 void wxHyperLink::SetNormalColour (wxColour colour) {
00150 m_NormalColour = colour;
00151 if (!m_Visited) {
00152 SetForegroundColour (m_NormalColour);
00153 }else{
00154 SetForegroundColour (m_VisitedColour);
00155 }
00156 Refresh();
00157 }
00158
00159 wxColour wxHyperLink::GetVisitedColour () {
00160 return m_VisitedColour;
00161 }
00162
00163 void wxHyperLink::SetVisitedColour (wxColour colour) {
00164 m_VisitedColour = colour;
00165 if (!m_Visited) {
00166 SetForegroundColour (m_NormalColour);
00167 }else{
00168 SetForegroundColour (m_VisitedColour);
00169 }
00170 Refresh();
00171 }
00172
00173 wxString wxHyperLink::GetURL () {
00174 return m_URL;
00175 }
00176
00177 void wxHyperLink::SetURL (const wxString &url) {
00178 m_URL = url;
00179 }
00180
00181
00182
00183
00184 void wxHyperLink::ExecuteLink (const wxString &link) {
00185 wxString mimetype = wxEmptyString;
00186 if (link.StartsWith (_T("http://"))) {
00187 mimetype = _T("text/html");
00188 }else if (link.StartsWith (_T("ftp://"))) {
00189 mimetype = _T("text/html");
00190 }else if (link.StartsWith (_T("mailto:"))) {
00191 mimetype = _T("message/rfc822");
00192 }else{
00193 return;
00194 }
00195 wxFileType *filetype = wxTheMimeTypesManager->GetFileTypeFromMimeType (mimetype);
00196 if (filetype) {
00197 wxString cmd;
00198 if (filetype->GetOpenCommand (&cmd, wxFileType::MessageParameters (link))) {
00199 cmd.Replace(_T("file://"), wxEmptyString);
00200 ::wxExecute(cmd);
00201 }
00202 }
00203 }
00204