Implement setting link colours in wxHyperlinkCtrl for GTK+3
Use GtkCssProvider to customize the colours used. Closes #17089.
This commit is contained in:
parent
1e70c05759
commit
d30673e507
@ -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).
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user