Skip to content

Commit

Permalink
GTK+: Use symbolic icons for source paths controls
Browse files Browse the repository at this point in the history
  • Loading branch information
vslavik committed Sep 11, 2019
1 parent 242cc73 commit c3e208d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
49 changes: 46 additions & 3 deletions src/icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <wx/log.h>
#include <wx/stdpaths.h>
#include <wx/image.h>
#include <wx/rawbmp.h>

#include <set>

Expand All @@ -45,7 +46,7 @@
namespace
{

#ifdef __WXGTK20__
#if defined(__WXGTK20__) && !defined(__WXGTK3__)
// translates poedit item id or Tango stock item id to "legacy" GNOME id:
wxString GetGnomeStockId(const wxString& id)
{
Expand All @@ -59,6 +60,10 @@ wxString GetGnomeStockId(const wxString& id)
MAP("document-properties", "stock_edit");
MAP("edit-delete", "gtk-delete");

MAP("folder-open@symbolic", "gtk-jump-to");
MAP("list-add@symbolic", "list-add");
MAP("list-remove@symbolic", "list-remove");

#undef MAP

return wxEmptyString; // no match found
Expand Down Expand Up @@ -114,6 +119,31 @@ void ProcessTemplateImage(wxImage& img, bool keepOpaque, bool inverted)
}
}

#ifdef __WXGTK3__
// FIXME: This is not correct, should use dedicated loading API instead
void ProcessSymbolicImage(wxBitmap& bmp)
{
wxAlphaPixelData data(bmp);
if (!data) { wxLogError("oh hell");
return;}

const char color = (ColorScheme::GetAppMode() == ColorScheme::Light) ? 0 : 255;

wxAlphaPixelData::Iterator p(data);
for (int y = 0; y < data.GetHeight(); ++y)
{
wxAlphaPixelData::Iterator rowStart = p;
for (int x = 0; x < data.GetWidth(); ++x, ++p)
{
if (p.Red() == 0xBE && p.Green() == 0xBE && p.Blue() == 0xBE)
p.Red() = p.Green() = p.Blue() = color;
}
p = rowStart;
p.OffsetY(data, 1);
}
}
#endif // __WXGTK3__

} // anonymous namespace


Expand Down Expand Up @@ -159,7 +189,7 @@ wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_,
// theme provider (that uses current icon theme and files from
// /usr/share/icons/<theme>) didn't find any matching icon.

#ifdef __WXGTK20__
#if defined(__WXGTK20__) && !defined(__WXGTK3__)
// try legacy GNOME icons from standard theme:
wxString gnomeId = GetGnomeStockId(id);
if ( !gnomeId.empty() )
Expand All @@ -169,7 +199,20 @@ wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_,
if ( gbmp.Ok() )
return gbmp;
}
#endif // __WXGTK20__
#endif // defined(__WXGTK20__) && !defined(__WXGTK3__)

#ifdef __WXGTK3__
CHECK_FOR_VARIANT(symbolic);
if (symbolicVariant)
{
wxBitmap bmp(wxArtProvider::GetBitmap(id + "-symbolic", client, size));
if (bmp.Ok())
{
ProcessSymbolicImage(bmp);
return bmp;
}
}
#endif

auto iconsdir = GetIconsDir();
if ( !wxDirExists(iconsdir) )
Expand Down
4 changes: 2 additions & 2 deletions src/prefsdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ class ExtractorsPageWindow : public PrefsPanel
m_delete = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-remove"), wxDefaultPosition, wxSize(PX(19),PX(19)));
int editButtonStyle = wxBU_EXACTFIT;
#elif defined(__WXGTK__)
m_new = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-add"), wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
m_delete = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-remove"), wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
m_new = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-add@symbolic"), wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
m_delete = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-remove@symbolic"), wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
int editButtonStyle = wxBU_EXACTFIT | wxBORDER_NONE;
#endif
m_edit = new wxButton(this, wxID_ANY, _(L"Edit…"), wxDefaultPosition, wxSize(-1, MSW_OR_OTHER(PX(19), -1)), editButtonStyle);
Expand Down
4 changes: 2 additions & 2 deletions src/propertiesdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ class PropertiesDialog::PathsList : public wxPanel
auto add = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-add"), wxDefaultPosition, wxSize(PX(19),PX(19)));
auto remove = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-remove"), wxDefaultPosition, wxSize(PX(19),PX(19)));
#elif defined(__WXGTK__)
auto add = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-add"), wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
auto remove = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-remove"), wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
auto add = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-add@symbolic"), wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
auto remove = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap("list-remove@symbolic"), wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
#endif
auto buttonSizer = new wxBoxSizer(wxHORIZONTAL);
buttonSizer->Add(add);
Expand Down
2 changes: 1 addition & 1 deletion src/resources/properties.xrc
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<style>wxNO_BORDER</style>
<variant>small</variant>
<bitmap platform="mac" stock_id="NSFollowLinkFreestandingTemplate"/>
<bitmap platform="unix" stock_id="gtk-jump-to"/>
<bitmap platform="unix" stock_id="folder-open@symbolic"/>
<bitmap platform="win" stock_id="follow-link"/>
<bg platform="win">#ffffff</bg>
</object>
Expand Down

0 comments on commit c3e208d

Please sign in to comment.