X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3cb3b8b84de3ff3b660108724139c24b39746449..38534f596974042130716a26276e9564b0b72295:/include/wx/hyperlink.h diff --git a/include/wx/hyperlink.h b/include/wx/hyperlink.h index f696a0ea1a..969a6864d7 100644 --- a/include/wx/hyperlink.h +++ b/include/wx/hyperlink.h @@ -9,8 +9,8 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_HYPERLINK_H__ -#define _WX_HYPERLINK_H__ +#ifndef _WX_HYPERLINK_H_ +#define _WX_HYPERLINK_H_ #include "wx/defs.h" @@ -23,9 +23,12 @@ // ---------------------------------------------------------------------------- #define wxHL_CONTEXTMENU 0x0001 -#define wxHL_DEFAULT_STYLE wxHL_CONTEXTMENU|wxNO_BORDER +#define wxHL_ALIGN_LEFT 0x0002 +#define wxHL_ALIGN_RIGHT 0x0004 +#define wxHL_ALIGN_CENTRE 0x0008 +#define wxHL_DEFAULT_STYLE (wxHL_CONTEXTMENU|wxNO_BORDER|wxHL_ALIGN_CENTRE) -extern WXDLLEXPORT_DATA(const wxChar) wxHyperlinkCtrlNameStr[]; +extern WXDLLIMPEXP_DATA_ADV(const char) wxHyperlinkCtrlNameStr[]; // ---------------------------------------------------------------------------- @@ -42,164 +45,130 @@ extern WXDLLEXPORT_DATA(const wxChar) wxHyperlinkCtrlNameStr[]; // just like a wxCommandEvent. // // Use the EVT_HYPERLINK() to catch link events. -class WXDLLIMPEXP_CORE wxHyperlinkCtrl : public wxControl +class WXDLLIMPEXP_ADV wxHyperlinkCtrlBase : public wxControl { public: - // Default constructor (for two-step construction). - wxHyperlinkCtrl() { } - - // Constructor. - wxHyperlinkCtrl(wxWindow *parent, - wxWindowID id, - const wxString& label, const wxString& url, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxHL_DEFAULT_STYLE, - const wxString& name = wxHyperlinkCtrlNameStr) - { - (void)Create(parent, id, label, url, pos, size, style, name); - } - - // Creation function (for two-step construction). - bool Create(wxWindow *parent, - wxWindowID id, - const wxString& label, const wxString& url, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxHL_DEFAULT_STYLE, - const wxString& name = wxHyperlinkCtrlNameStr); - // get/set - wxColour GetHoverColour() const { return m_hoverColour; } - void SetHoverColour(const wxColour &colour) { m_hoverColour = colour; } + virtual wxColour GetHoverColour() const = 0; + virtual void SetHoverColour(const wxColour &colour) = 0; - wxColour GetNormalColour() const { return m_normalColour; } - void SetNormalColour(const wxColour &colour); + virtual wxColour GetNormalColour() const = 0; + virtual void SetNormalColour(const wxColour &colour) = 0; - wxColour GetVisitedColour() const { return m_visitedColour; } - void SetVisitedColour(const wxColour &colour); + virtual wxColour GetVisitedColour() const = 0; + virtual void SetVisitedColour(const wxColour &colour) = 0; - wxString GetURL() const { return m_url; } - void SetURL (const wxString &url) { m_url=url; } + virtual wxString GetURL() const = 0; + virtual void SetURL (const wxString &url) = 0; - void SetVisited(bool visited = true) { m_visited=visited; } - bool GetVisited() const { return m_visited; } + virtual void SetVisited(bool visited = true) = 0; + virtual bool GetVisited() const = 0; // NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour, // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important ! + virtual bool HasTransparentBackground() { return true; } protected: - // event handlers - - // Renders the hyperlink. - void OnPaint(wxPaintEvent& event); - - // If the click originates inside the bounding box of the label, - // a flag is set so that an event will be fired when the left - // button is released. - void OnLeftDown(wxMouseEvent& event); - - // If the click both originated and finished inside the bounding box - // of the label, a HyperlinkEvent is fired. - void OnLeftUp(wxMouseEvent& event); - void OnRightUp(wxMouseEvent& event); - - // Changes the cursor to a hand, if the mouse is inside the label's - // bounding box. - void OnEnterWindow(wxMouseEvent& event); - - // Changes the cursor back to the default, if necessary. - void OnLeaveWindow(wxMouseEvent& event); - - // handles "Copy URL" menuitem - void OnPopUpCopy(wxCommandEvent& event); - - - // overridden base class virtuals - - // Returns the best size for the window, which is the size needed - // to display the text label. - virtual void DoGetSize(int *width, int *height) const; - virtual wxSize DoGetBestSize() const; - - // creates a context menu with "Copy URL" menuitem - virtual void DoContextMenu(const wxPoint &); - -private: - // URL associated with the link. This is transmitted inside - // the HyperlinkEvent fired when the user clicks on the label. - wxString m_url; - - // Foreground colours for various link types. - // NOTE: wxWindow::m_backgroundColour is used for background, - // wxWindow::m_foregroundColour is used to render non-visited links - wxColour m_hoverColour; - wxColour m_normalColour; - wxColour m_visitedColour; - - // True if the mouse cursor is inside the label's bounding box. - bool m_rollover; + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } - // True if the link has been clicked before. - bool m_visited; + // checks for validity some of the ctor/Create() function parameters + void CheckParams(const wxString& label, const wxString& url, long style); - // True if a click is in progress (left button down) and the click - // originated inside the label's bounding box. - bool m_clicking; - -private: - DECLARE_DYNAMIC_CLASS(wxHyperlinkCtrl) - DECLARE_EVENT_TABLE() +public: + // not part of the public API but needs to be public as used by + // GTK+ callbacks: + void SendEvent(); }; - // ---------------------------------------------------------------------------- // wxHyperlinkEvent // ---------------------------------------------------------------------------- -// Declare an event identifier. -BEGIN_DECLARE_EVENT_TYPES() - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_HYPERLINK, 3700) -END_DECLARE_EVENT_TYPES() +class WXDLLIMPEXP_FWD_ADV wxHyperlinkEvent; + +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_HYPERLINK, wxHyperlinkEvent ); // // An event fired when the user clicks on the label in a hyperlink control. // See HyperlinkControl for details. // -class WXDLLIMPEXP_CORE wxHyperlinkEvent : public wxCommandEvent +class WXDLLIMPEXP_ADV wxHyperlinkEvent : public wxCommandEvent { public: - wxHyperlinkEvent() {} wxHyperlinkEvent(wxObject *generator, wxWindowID id, const wxString& url) - : wxCommandEvent(wxEVT_COMMAND_HYPERLINK, id), m_url(url) - { SetEventObject(generator); } + : wxCommandEvent(wxEVT_HYPERLINK, id), + m_url(url) + { + SetEventObject(generator); + } // Returns the URL associated with the hyperlink control // that the user clicked on. wxString GetURL() const { return m_url; } void SetURL(const wxString &url) { m_url=url; } + // default copy ctor, assignment operator and dtor are ok + virtual wxEvent *Clone() const { return new wxHyperlinkEvent(*this); } + private: // URL associated with the hyperlink control that the used clicked on. wxString m_url; + + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHyperlinkEvent) }; -// Define a typedef for event handler functions. -typedef void (wxEvtHandler::*wxHyperlinkEventFunction)(wxHyperlinkEvent&); -// Define an event table macro. -#define EVT_HYPERLINK(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_COMMAND_HYPERLINK, \ - id, id, (wxObjectEventFunction) (wxEventFunction) \ - wxStaticCastEvent(wxHyperlinkEventFunction, &fn), (wxObject *) NULL), +// ---------------------------------------------------------------------------- +// event types and macros +// ---------------------------------------------------------------------------- + +typedef void (wxEvtHandler::*wxHyperlinkEventFunction)(wxHyperlinkEvent&); -// Newer event macro #define wxHyperlinkEventHandler(func) \ - (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxHyperlinkEventFunction, &func) + wxEVENT_HANDLER_CAST(wxHyperlinkEventFunction, func) + +#define EVT_HYPERLINK(id, fn) \ + wx__DECLARE_EVT1(wxEVT_HYPERLINK, id, wxHyperlinkEventHandler(fn)) + + +#if defined(__WXGTK210__) && !defined(__WXUNIVERSAL__) + #include "wx/gtk/hyperlink.h" +// Note that the native control is only available in Unicode version under MSW. +#elif defined(__WXMSW__) && wxUSE_UNICODE && !defined(__WXUNIVERSAL__) + #include "wx/msw/hyperlink.h" +#else + #include "wx/generic/hyperlink.h" + + class WXDLLIMPEXP_ADV wxHyperlinkCtrl : public wxGenericHyperlinkCtrl + { + public: + wxHyperlinkCtrl() { } + + wxHyperlinkCtrl(wxWindow *parent, + wxWindowID id, + const wxString& label, + const wxString& url, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxHL_DEFAULT_STYLE, + const wxString& name = wxHyperlinkCtrlNameStr) + : wxGenericHyperlinkCtrl(parent, id, label, url, pos, size, + style, name) + { + } + + private: + wxDECLARE_DYNAMIC_CLASS_NO_COPY( wxHyperlinkCtrl ); + }; +#endif + +// old wxEVT_COMMAND_* constants +#define wxEVT_COMMAND_HYPERLINK wxEVT_HYPERLINK #endif // wxUSE_HYPERLINKCTRL -#endif // _WX_HYPERLINK_H__ +#endif // _WX_HYPERLINK_H_