hyperlinkctrl.h

Go to the documentation of this file.
00001 
00002 // Name:        hyperlinkctrl.h
00003 // Purpose:     Hyperlink control for wxWidgets
00004 //                              Features include the ability to perform your own Left, Middle, and Right 
00005 //                              click events to perform your own custom event handling and ability to open
00006 //                              link in a new or current browser window.
00007 // Author:      Angelo Mandato
00008 // Created:     2005/08/10
00009 // RCS-ID:      $Id: hyperlinkctrl.h,v 1.1 2006/10/11 16:14:58 ndellamico Exp $
00010 // Copyright:   (c) 2005 Angelo Mandato (http://www.spaceblue.com)
00011 // Licence:     wxWidgets licence
00013 
00014 /*////////////////////////////////////////////////
00016         Name:                   Mark McManus
00017         Email:                  mmcmanus@scientificmetrics.com
00018         Notes:                  Contributed code for the EVT_COMMAND_LINK_CLICKED event
00019                                         which is fired when AutoBrowse(false) is set and added
00020                                         DoPopup(false) to supress pop up menu to copy web link.
00021                                         Thanks Mark!
00022         
00023 */
00024 
00025 #ifndef _WX_HYPERLINKCTRL_H_
00026 #define _WX_HYPERLINKCTRL_H_
00027 
00028 // optimization for GCC
00029 #if defined(__GNUG__) && !defined(__APPLE__)
00030 #pragma interface "hyperlinkctrl.h"
00031 #endif
00032 
00033 // Define below if you simply want to use wxCommandEvents for single click
00034 // click events on your links
00035 //#define HYPERLINKCTRL_COMMANDEVENT
00036 
00037 #include <wx/wx.h>
00038 #include "httpenginedef.h"
00039 
00040 BEGIN_DECLARE_EVENT_TYPES()
00041   DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_HTTPENGINE, wxEVT_COMMAND_LINK_CLICKED, 7771)
00042 #ifndef HYPERLINKCTRL_COMMANDEVENT
00043   DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_HTTPENGINE, wxEVT_COMMAND_LINK_MCLICKED, 7772)
00044   DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_HTTPENGINE, wxEVT_COMMAND_LINK_RCLICKED, 7773)
00045 #endif
00046 END_DECLARE_EVENT_TYPES()
00047 
00048 
00049 #ifdef HYPERLINKCTRL_COMMANDEVENT
00050 
00051 #define EVT_LINK(id, fn) \
00052     DECLARE_EVENT_TABLE_ENTRY( \
00053         wxEVT_COMMAND_LINK_CLICKED, id, -1, \
00054         (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)&fn, \
00055         (wxObject *) NULL \
00056     ),
00057 
00058 #else
00059 
00060 class wxHyperlinkEvent : public wxCommandEvent
00061 {
00062 public:
00063   wxHyperlinkEvent( WXTYPE eventType = wxEVT_COMMAND_LINK_RCLICKED, int id = 0 ) : wxCommandEvent( eventType, id ) { };
00064 
00065         virtual wxEvent *Clone() const { return new wxHyperlinkEvent(*this);  };
00066 
00067         void SetPosition( const wxPoint &pos ) { m_pos = pos; };
00068         wxPoint GetPosition(void) { return m_pos; };
00069 private:
00070         wxPoint m_pos;
00071 };
00072 
00073 typedef void (wxEvtHandler::*wxHyperlinkEventFunction)(wxHyperlinkEvent);
00074 
00075 // Event types for wxHyperlinkCtrl:
00076 #define EVT_LINK(id, fn) \
00077     DECLARE_EVENT_TABLE_ENTRY( \
00078         wxEVT_COMMAND_LINK_CLICKED, id, -1, \
00079         (wxObjectEventFunction)(wxEventFunction)(wxHyperlinkEventFunction)&fn, \
00080         (wxObject *) NULL \
00081     ),
00082 #define EVT_LINK_MCLICKED(id, fn) \
00083     DECLARE_EVENT_TABLE_ENTRY( \
00084         wxEVT_COMMAND_LINK_MCLICKED, id, -1, \
00085         (wxObjectEventFunction)(wxEventFunction)(wxHyperlinkEventFunction)&fn, \
00086         (wxObject *) NULL \
00087     ),
00088 #define EVT_LINK_RCLICKED(id, fn) \
00089     DECLARE_EVENT_TABLE_ENTRY( \
00090         wxEVT_COMMAND_LINK_RCLICKED, id, -1, \
00091         (wxObjectEventFunction)(wxEventFunction)(wxHyperlinkEventFunction)&fn, \
00092         (wxObject *) NULL \
00093     ),
00094 
00095 #endif
00096 
00097 enum
00098 {
00099         HYPERLINKS_POPUP_COPY = 1000,
00100 };
00101 
00102 // wxHyperlinkCtrl class
00103 class wxHyperlinkCtrl : public wxStaticText
00104 {
00105 public:
00106 
00107 #ifdef __WIN95__
00108         long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
00109 #endif
00110 
00111         // Constructor
00112         wxHyperlinkCtrl( wxWindow *parent, wxWindowID id, const wxString &label,
00113                         const wxPoint &pos= wxDefaultPosition, const wxSize &size= wxDefaultSize, int style = 0, const wxString& name = wxT("staticText"), const wxString& szURL = wxEmptyString);
00114 
00115         // Link Colours properties
00116         void SetColours( const wxColour &link = wxColour( wxT("BLUE") ), const wxColour &visited  = wxColour(wxT("VIOLET")), const wxColour &rollover = wxColour( wxT("BLUE") ))
00117         {
00118                 m_crLinkColour = link;
00119                 m_crVisitedColour = visited;
00120                 m_crLinkRolloverColor = rollover;
00121         };
00122         void GetColous( wxColour &link, wxColour &visited, wxColour &rollover )
00123         {
00124                 link = m_crLinkColour;
00125                 visited = m_crVisitedColour;
00126                 rollover = m_crLinkRolloverColor;
00127         };
00128 
00129         // Underline properties
00130         void SetUnderlines( const bool link = true, const bool visited = true, const bool rollover = true )
00131         {
00132                 m_bLinkUnderline = link;
00133                 m_bRolloverUnderline = rollover;
00134                 m_bVisitedUnderline = visited;
00135         };
00136         void GetUnderlines( bool link, bool visited, bool rollover )
00137         {
00138                 link = m_bLinkUnderline;
00139                 rollover = m_bRolloverUnderline;
00140                 visited = m_bVisitedUnderline;
00141         };
00142 
00143         // Set Link Cursor properties
00144         void SetLinkCursor( const wxCursor &cur = wxCURSOR_HAND) { m_crHand = cur; };
00145         void GetLinkCursor( wxCursor &cur ) { cur = m_crHand; };
00146 
00147         // Visited properties
00148         void SetVisited( const bool bVisited = false ) { m_bVisited = bVisited; };
00149         bool GetVisited( void ) { return m_bVisited; }
00150 
00151         // Bold font properties
00152         void SetBold( const bool bBold = false) { m_bBold = bBold; };
00153         bool GetBold( void ) { return m_bBold; };
00154 
00155         // URL properties
00156         void SetURL( const wxString &szURL ) { m_szURL = szURL; }
00157         wxString GetURL( void ) { return m_szURL; }
00158 
00159   // Open in same window property
00160   void OpenInSameWindow( const bool bIfPossible = false ) { m_bSameWinIfPossible = bIfPossible; };
00161 
00162         // Broswer Path
00163         void SetBrowserPath( const wxString &browser ) { m_szBrowserPath = browser; };
00164         wxString GetBrowserPath( void ) { return m_szBrowserPath; };
00165 
00166   // Roll over properties
00167         void EnableRollover( const bool bEnable = false ) { m_bEnableRollover = bEnable; };
00168 
00169         // Report errors property
00170         void ReportErrors( const bool bReport = true ) { m_bReportErrors = bReport; };
00171 
00172 //**Added By Mark McManus
00173   //AutoBrowse property
00174   void AutoBrowse( const bool bBrowse = true ){ m_bAutoBrowse = bBrowse; };
00175 
00176   //DoPopup property
00177   void DoPopup( const bool bPopup = true ) { m_bDoPopup = bPopup; };
00178 
00179 //**Mark McManus
00180 
00181         // Goto URL
00182         static bool GotoURL( const wxString &szUrl, const wxString &szBrowser = wxEmptyString, const bool bReportErrors = false, const bool bSameWinIfPossible = false );
00183 
00184         // Refresh link properties
00185         void UpdateLink( const bool bRefresh = true );
00186 
00187 private:
00188         // Copy URL event
00189         void OnPopUpCopy( wxCommandEvent &event );
00190 
00191         // Mouse event
00192         void OnMouseEvent( wxMouseEvent &event );
00193 
00194         // ErrorMmessage
00195         static void DisplayError( const wxString &szError, const bool bReportErrors );
00196         
00197         // The URL to goto.
00198         wxString m_szURL;
00199 
00200         // Browser Path
00201         wxString m_szBrowserPath;
00202 
00203         // Colours
00204         wxColour m_crLinkColour;
00205         wxColour m_crVisitedColour;
00206         wxColour m_crLinkRolloverColor;
00207 
00208         // Underlines
00209         bool m_bLinkUnderline;
00210         bool m_bRolloverUnderline;
00211         bool m_bVisitedUnderline;
00212 
00213         // Rollover enabled?
00214         bool m_bEnableRollover;
00215 
00216         // Visited link?
00217         bool m_bVisited;
00218 
00219         // Make link bold?
00220         bool m_bBold;
00221 
00222         // Specify a cursor
00223         wxCursor m_crHand;
00224 
00225         // Should Control report errors in dialog?
00226         bool m_bReportErrors;
00227 
00228 //**Added By Mark McManus
00229 
00230   //Should Control browse to the URL (if false just fire wxEVT_COMMAND_LINK_CLICKED)
00231   bool m_bAutoBrowse;
00232 
00233   //Should the control show the Copy popup menu (if false just fire wxEVT_COMMAND_RLINK_CLICKED)
00234   bool m_bDoPopup;
00235 //**Mark McManus
00236 
00237   bool m_bSameWinIfPossible;
00238 
00239   wxMenu *m_menuPopUp;
00240 
00241   DECLARE_EVENT_TABLE()
00242 };
00243 
00244 #endif

Generated on Mon Mar 19 17:14:08 2007 for CAENScope by  doxygen 1.4.6-NO