annotate src/win32/Hyperlink.cpp @ 4:5f6f2134e8ce

apu appears to not be used
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:35:58 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 // Hyperlink.cpp : implementation file
rlm@1 2 //
rlm@1 3
rlm@1 4 #include "stdafx.h"
rlm@1 5 #include "Hyperlink.h"
rlm@1 6
rlm@1 7 /////////////////////////////////////////////////////////////////////////////
rlm@1 8 // Hyperlink
rlm@1 9
rlm@1 10 Hyperlink::Hyperlink()
rlm@1 11 {
rlm@1 12 m_over = false;
rlm@1 13 }
rlm@1 14
rlm@1 15 Hyperlink::~Hyperlink()
rlm@1 16 {
rlm@1 17 m_underlineFont.DeleteObject();
rlm@1 18 }
rlm@1 19
rlm@1 20
rlm@1 21 BEGIN_MESSAGE_MAP(Hyperlink, CStatic)
rlm@1 22 //{{AFX_MSG_MAP(Hyperlink)
rlm@1 23 ON_WM_CTLCOLOR_REFLECT()
rlm@1 24 ON_WM_ERASEBKGND()
rlm@1 25 ON_WM_MOUSEMOVE()
rlm@1 26 //}}AFX_MSG_MAP
rlm@1 27 ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
rlm@1 28 END_MESSAGE_MAP()
rlm@1 29
rlm@1 30 /////////////////////////////////////////////////////////////////////////////
rlm@1 31 // Hyperlink message handlers
rlm@1 32
rlm@1 33 void Hyperlink::PreSubclassWindow()
rlm@1 34 {
rlm@1 35 DWORD dwStyle = GetStyle();
rlm@1 36 ::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
rlm@1 37
rlm@1 38 // 32649 is the hand cursor
rlm@1 39 m_cursor = LoadCursor(NULL, MAKEINTRESOURCE(32649));
rlm@1 40
rlm@1 41 CFont *font = GetFont();
rlm@1 42
rlm@1 43 LOGFONT lg;
rlm@1 44 font->GetLogFont(&lg);
rlm@1 45
rlm@1 46 lg.lfUnderline = TRUE;
rlm@1 47
rlm@1 48 m_underlineFont.CreateFontIndirect(&lg);
rlm@1 49 SetFont(&m_underlineFont);
rlm@1 50
rlm@1 51 CStatic::PreSubclassWindow();
rlm@1 52 }
rlm@1 53
rlm@1 54 void Hyperlink::OnClicked()
rlm@1 55 {
rlm@1 56 CString url;
rlm@1 57 GetWindowText(url);
rlm@1 58 ::ShellExecute(0, _T("open"), url,
rlm@1 59 0, 0, SW_SHOWNORMAL);
rlm@1 60 }
rlm@1 61
rlm@1 62 HBRUSH Hyperlink::CtlColor(CDC* pDC, UINT nCtlColor)
rlm@1 63 {
rlm@1 64 pDC->SetTextColor(RGB(0,0,240));
rlm@1 65
rlm@1 66 return (HBRUSH)GetStockObject(NULL_BRUSH);
rlm@1 67 }
rlm@1 68
rlm@1 69 BOOL Hyperlink::OnEraseBkgnd(CDC* pDC)
rlm@1 70 {
rlm@1 71 CRect rect;
rlm@1 72 GetClientRect(rect);
rlm@1 73 pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));
rlm@1 74
rlm@1 75 return TRUE;
rlm@1 76 }
rlm@1 77
rlm@1 78 void Hyperlink::OnMouseMove(UINT nFlags, CPoint point)
rlm@1 79 {
rlm@1 80 if(!m_over) {
rlm@1 81 m_over = true;
rlm@1 82 SetCapture();
rlm@1 83 ::SetCursor(m_cursor);
rlm@1 84 } else {
rlm@1 85 CRect r;
rlm@1 86 GetClientRect(&r);
rlm@1 87
rlm@1 88 if(!r.PtInRect(point)) {
rlm@1 89 m_over = false;
rlm@1 90 ReleaseCapture();
rlm@1 91 }
rlm@1 92 }
rlm@1 93 }