Merge setting link colours for wxGTK3 wxHyperlinkCtrl

Closes https://github.com/wxWidgets/wxWidgets/pull/249
This commit is contained in:
Vadim Zeitlin
2016-03-07 16:17:11 +01:00
5 changed files with 124 additions and 6 deletions

View File

@@ -67,6 +67,10 @@ All (GUI):
- Update Scintilla to v3.6.3 (Paul Kulchenko).
wxGTK:
- Implement setting link colours in wxHyperlinkCtrl for GTK+3 (Hanmac).
wxMSW:
- Fix crash when using wxCHMHelpController() in 64 bit builds (Xlord2).

View File

@@ -13,6 +13,12 @@
#include "wx/generic/hyperlink.h"
#include "wx/scopedptr.h"
#ifdef __WXGTK3__
class wxHyperlinkCtrlColData;
#endif
// ----------------------------------------------------------------------------
// wxHyperlinkCtrl
// ----------------------------------------------------------------------------
@@ -72,6 +78,19 @@ protected:
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;
private:
enum LinkKind
{
Link_Normal,
Link_Visited
};
void DoSetLinkColour(LinkKind linkKind, const wxColour& colour);
#ifdef __WXGTK3__
wxScopedPtr<wxHyperlinkCtrlColData> m_colData;
#endif
wxDECLARE_DYNAMIC_CLASS(wxHyperlinkCtrl);
};

View File

@@ -14,6 +14,7 @@
#ifdef __WXGTK3__
typedef struct _cairo cairo_t;
typedef struct _GtkStyleProvider GtkStyleProvider;
typedef struct _GtkCssProvider GtkCssProvider;
#define WXUNUSED_IN_GTK2(x) x
#define WXUNUSED_IN_GTK3(x)
#else
@@ -409,7 +410,11 @@ protected:
// Copies m_children tab order to GTK focus chain:
void RealizeTabOrder();
#ifndef __WXGTK3__
#ifdef __WXGTK3__
// Use the given CSS string for styling the widget. The provider must be
// allocated, and remains owned, by the caller.
void ApplyCssStyle(GtkCssProvider* provider, const char* style);
#else // GTK+ < 3
// Called by ApplyWidgetStyle (which is called by SetFont() and
// SetXXXColour etc to apply style changed to native widgets) to create
// modified GTK style with non-standard attributes.

View File

@@ -32,6 +32,10 @@
#include <gtk/gtk.h>
#include "wx/gtk/private.h"
#ifdef __WXGTK3__
#include "wx/gtk/private/object.h"
#endif
// ----------------------------------------------------------------------------
// local functions
// ----------------------------------------------------------------------------
@@ -85,6 +89,23 @@ static void clicked_hook(GtkLinkButton* button, const char*, void*)
}
#endif
#ifdef __WXGTK3__
// Used to store GtkCssProviders we need to change the link colours with GTK+3.
class wxHyperlinkCtrlColData
{
public:
wxHyperlinkCtrlColData() :
m_normalLinkCssProvider(gtk_css_provider_new()),
m_visitedLinkCssProvider(gtk_css_provider_new())
{}
wxGtkObject<GtkCssProvider> m_normalLinkCssProvider;
wxGtkObject<GtkCssProvider> m_visitedLinkCssProvider;
};
#endif // __WXGTK3__
// ----------------------------------------------------------------------------
// wxHyperlinkCtrl
// ----------------------------------------------------------------------------
@@ -197,12 +218,45 @@ wxString wxHyperlinkCtrl::GetURL() const
return wxGenericHyperlinkCtrl::GetURL();
}
void wxHyperlinkCtrl::DoSetLinkColour(LinkKind linkKind, const wxColour& colour)
{
#ifdef __WXGTK3__
if ( !m_colData )
m_colData.reset(new wxHyperlinkCtrlColData());
const char* cssProp = NULL;
GtkCssProvider* cssProvider = NULL;
switch ( linkKind )
{
case Link_Normal:
cssProp = "link-color";
cssProvider = m_colData->m_normalLinkCssProvider;
break;
case Link_Visited:
cssProp = "visited-link-color";
cssProvider = m_colData->m_visitedLinkCssProvider;
break;
}
wxCHECK_RET( cssProvider, wxS("unknown link kind") );
const GdkRGBA *col = colour;
wxGtkString
css(g_strdup_printf("* { %s: %s; }", cssProp, gdk_rgba_to_string(col)));
ApplyCssStyle(cssProvider, css);
#else // !__WXGTK3__
// simply do nothing: GTK+ does not allow us to change it :(
wxUnusedVar(linkKind);
wxUnusedVar(colour);
#endif
}
void wxHyperlinkCtrl::SetNormalColour(const wxColour &colour)
{
if ( UseNative() )
{
// simply do nothing: GTK+ does not allow us to change it :(
}
DoSetLinkColour(Link_Normal, colour);
else
wxGenericHyperlinkCtrl::SetNormalColour(colour);
}
@@ -212,6 +266,16 @@ wxColour wxHyperlinkCtrl::GetNormalColour() const
wxColour ret;
if ( UseNative() )
{
#ifdef __WXGTK3__
GdkRGBA *link_color = NULL;
gtk_widget_style_get(m_widget, "link-color", &link_color, NULL);
if ( link_color )
{
ret = wxColour(*link_color);
gdk_rgba_free (link_color);
}
#else // !__WXGTK3__
GdkColor* link_color;
GdkColor color = { 0, 0, 0, 0xeeee };
@@ -226,6 +290,7 @@ wxColour wxHyperlinkCtrl::GetNormalColour() const
}
wxGCC_WARNING_RESTORE()
ret = wxColour(color);
#endif // __WXGTK3__/!__WXGTK3__
}
else
ret = wxGenericHyperlinkCtrl::GetNormalColour();
@@ -237,7 +302,7 @@ void wxHyperlinkCtrl::SetVisitedColour(const wxColour &colour)
{
if ( UseNative() )
{
// simply do nothing: GTK+ does not allow us to change it :(
DoSetLinkColour(Link_Visited, colour);
}
else
wxGenericHyperlinkCtrl::SetVisitedColour(colour);
@@ -248,6 +313,16 @@ wxColour wxHyperlinkCtrl::GetVisitedColour() const
wxColour ret;
if ( UseNative() )
{
#ifdef __WXGTK3__
GdkRGBA *link_color = NULL;
gtk_widget_style_get(m_widget, "visited-link-color", &link_color, NULL);
if ( link_color )
{
ret = wxColour(*link_color);
gdk_rgba_free (link_color);
}
#else // !__WXGTK3__
GdkColor* link_color;
GdkColor color = { 0, 0x5555, 0x1a1a, 0x8b8b };
@@ -262,6 +337,7 @@ wxColour wxHyperlinkCtrl::GetVisitedColour() const
}
wxGCC_WARNING_RESTORE()
ret = wxColour(color);
#endif // __WXGTK3__/!__WXGTK3__
}
else
ret = base_type::GetVisitedColour();

View File

@@ -4426,7 +4426,21 @@ PangoContext *wxWindowGTK::GTKGetPangoDefaultContext()
return gtk_widget_get_pango_context( m_widget );
}
#ifndef __WXGTK3__
#ifdef __WXGTK3__
void wxWindowGTK::ApplyCssStyle(GtkCssProvider* provider, const char* style)
{
wxCHECK_RET(m_widget, "invalid window");
gtk_style_context_remove_provider(gtk_widget_get_style_context(m_widget),
GTK_STYLE_PROVIDER(provider));
gtk_css_provider_load_from_data(provider, style, -1, NULL);
gtk_style_context_add_provider(gtk_widget_get_style_context(m_widget),
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
#else // GTK+ < 3
GtkRcStyle* wxWindowGTK::GTKCreateWidgetStyle()
{
GtkRcStyle *style = gtk_rc_style_new();