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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
//////////////////////////////////////////////////////////////////////////////
// File: hyperlink.cpp
// Purpose: wxHyperLink control
// Maintainer: Wyo
// Created: 2003-04-07
// RCS-ID: $Id: hyperlink.cpp,v 1.11 2006/03/09 10:21:07 rwalton Exp $
// Copyright: (c) 2004 wxCode
// Licence: wxWindows
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// information
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// headers
//----------------------------------------------------------------------------
#include "stdwx.h"
#include "BOINCGUIApp.h"
#include "hyperlink.h" // wxHyperLink control
//----------------------------------------------------------------------------
// resources
//----------------------------------------------------------------------------
//============================================================================
// declarations
//============================================================================
//============================================================================
// implementation
//============================================================================
//----------------------------------------------------------------------------
// wxHyperLink
//----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS (wxHyperLink, wxStaticText)
BEGIN_EVENT_TABLE (wxHyperLink, wxStaticText)
EVT_ENTER_WINDOW (wxHyperLink::OnWindowEnter)
EVT_LEAVE_WINDOW (wxHyperLink::OnWindowLeave)
EVT_LEFT_DCLICK (wxHyperLink::OnLinkActivate)
EVT_LEFT_DOWN (wxHyperLink::OnLinkActivate)
END_EVENT_TABLE()
bool wxHyperLink::Create (wxWindow *parent,
wxWindowID id,
const wxString &label,
const wxPoint &pos,
const wxSize &size,
long style,
const wxString &name) {
bool okay = FALSE;
// create static text
okay = wxStaticText::Create (parent, id, label, pos, size, style, name);
wxASSERT_MSG (okay, wxT("Failed to create wxStaticText, needed by wxHyperLink!"));
// initialize variables
m_URL = wxEmptyString;
m_Marked = false;
m_Visited = false;
m_MarkedColour = wxColour (wxT("DARK GREY"));
m_NormalColour = wxColour (wxT("BLUE"));
m_VisitedColour = wxColour (wxT("PURPLE"));
m_HoverCursor = wxCursor (wxCURSOR_HAND);
// set foreground colour
SetForegroundColour (m_NormalColour);
wxFont font = GetFont();
font.SetUnderlined (true);
SetFont (font);
// get background colour
m_BackgroundColour = GetBackgroundColour ();
return okay;
} // Create
//----------------------------------------------------------------------------
// event handlers
void wxHyperLink::OnWindowEnter (wxMouseEvent &WXUNUSED(event)) {
SetCursor (m_HoverCursor);
Refresh();
}
void wxHyperLink::OnWindowLeave (wxMouseEvent &WXUNUSED(event)) {
SetCursor (wxNullCursor);
Refresh();
}
void wxHyperLink::OnLinkActivate (wxMouseEvent &WXUNUSED(event)) {
m_Visited = TRUE;
SetForegroundColour (m_VisitedColour);
SetBackgroundColour (m_BackgroundColour);
Refresh();
if (m_URL.IsEmpty()) {
ExecuteLink (GetLabel());
}else{
ExecuteLink (m_URL);
}
}
//----------------------------------------------------------------------------
// settings functions
wxCursor wxHyperLink::GetHoverCursor () {
return m_HoverCursor;
}
void wxHyperLink::SetHoverCursor (wxCursor cursor) {
m_HoverCursor = cursor;
}
wxColour wxHyperLink::GetMarkedColour () {
return m_MarkedColour;
}
void wxHyperLink::SetMarkedColour (wxColour colour) {
m_MarkedColour = colour;
}
wxColour wxHyperLink::GetNormalColour () {
return m_NormalColour;
}
void wxHyperLink::SetNormalColour (wxColour colour) {
m_NormalColour = colour;
if (!m_Visited) {
SetForegroundColour (m_NormalColour);
}else{
SetForegroundColour (m_VisitedColour);
}
Refresh();
}
wxColour wxHyperLink::GetVisitedColour () {
return m_VisitedColour;
}
void wxHyperLink::SetVisitedColour (wxColour colour) {
m_VisitedColour = colour;
if (!m_Visited) {
SetForegroundColour (m_NormalColour);
}else{
SetForegroundColour (m_VisitedColour);
}
Refresh();
}
wxString wxHyperLink::GetURL () {
return m_URL;
}
void wxHyperLink::SetURL (const wxString &url) {
m_URL = url;
}
//----------------------------------------------------------------------------
// private functions
void wxHyperLink::ExecuteLink (const wxString &strLink) {
wxString cmd;
wxString strMimeType = wxEmptyString;
bool mime_type_found = false;
if (strLink.StartsWith(wxT("http://")))
strMimeType = wxT("text/html");
else if (strLink.StartsWith(wxT("ftp://")))
strMimeType = wxT("text/html");
else if (strLink.StartsWith(wxT("mailto:")))
strMimeType = wxT("message/rfc822");
else
return;
wxFileType* ft = wxTheMimeTypesManager->GetFileTypeFromMimeType(strMimeType);
if (ft) {
if (ft->GetOpenCommand(&cmd, wxFileType::MessageParameters(strLink))) {
#ifdef __WXMAC__
cmd.Replace(wxT("<"), wxEmptyString);
cmd.Prepend(wxT("open "));
#else
cmd.Replace(wxT("file://"), wxEmptyString);
#endif
mime_type_found = true;
::wxExecute(cmd);
}
delete ft;
}
#if defined(__WXGTK__) || defined(__WXMOTIF__)
if (!mime_type_found) {
cmd = ::wxGetenv(wxT("BROWSER"));
if(cmd.IsEmpty()) {
wxString strDialogTitle = wxEmptyString;
wxString strDialogMessage = wxEmptyString;
// %s is the application name
// i.e. 'BOINC Manager', 'GridRepublic Manager'
strDialogTitle.Printf(
_("%s - Can't find web browser"),
wxGetApp().GetBrand()->GetApplicationName().c_str()
);
// 1st %s is the application name
// i.e. 'BOINC Manager', 'GridRepublic Manager'
// 2nd %s is the URL that the browser is supposed to
// open.
// 3rd %s is the application name
// i.e. 'BOINC Manager', 'GridRepublic Manager'
strDialogMessage.Printf(
_("%s tried to display the web page\n"
"\t%s\n"
"but couldn't find a web browser.\n"
"To fix this, set the environment variable\n"
"BROWSER to the path of your web browser,\n"
"then restart the %s."),
wxGetApp().GetBrand()->GetApplicationName().c_str(),
strLink.c_str(),
wxGetApp().GetBrand()->GetApplicationName().c_str()
);
::wxMessageBox(
strDialogMessage,
strDialogTitle,
wxOK | wxICON_INFORMATION
);
} else {
cmd += wxT(" ") + strLink;
::wxExecute(cmd,wxEXEC_ASYNC);
}
}
#endif
}
const char *BOINC_RCSID_d587835b7e="$Id: hyperlink.cpp,v 1.11 2006/03/09 10:21:07 rwalton Exp $";
|