Skip to content

Commit 7cd752a

Browse files
committed
Improve toolbar appearence with GTK+ 3
Use symbolic icons for the toolbar. Also mark it as primary toolbar to have appearance consistent with other applications, particularly on Ubuntu.
1 parent f2be20f commit 7cd752a

File tree

8 files changed

+81
-6
lines changed

8 files changed

+81
-6
lines changed

artwork/Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ appicons512dir=$(iconsdir)/512x512/apps
99
pixmapsdir=$(datadir)/pixmaps
1010

1111
uiiconsdir=$(datadir)/poedit/icons
12+
uiiconssymbolicdir=$(uiiconsdir)/hicolor/scalable/actions
1213

1314
dist_appicons16_DATA = linux/appicon/16x16/apps/poedit.png
1415
dist_appicons24_DATA = linux/appicon/24x24/apps/poedit.png
@@ -19,6 +20,12 @@ dist_appicons512_DATA = linux/appicon/512x512/apps/poedit.png
1920

2021
dist_pixmaps_DATA = linux/appicon/48x48/apps/poedit.png
2122

23+
dist_uiiconssymbolic_DATA = \
24+
linux/poedit-sync-symbolic.svg \
25+
linux/poedit-update-symbolic.svg \
26+
linux/poedit-validate-symbolic.svg \
27+
linux/sidebar-symbolic.svg
28+
2229
dist_uiicons_DATA = \
2330
linux/document-new.png \
2431
linux/document-open.png \
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

artwork/linux/sidebar-symbolic.svg

Lines changed: 1 addition & 0 deletions
Loading

src/icons.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
#include <set>
3131

32+
#ifdef __WXGTK__
33+
#include <gtk/gtk.h>
34+
#endif
35+
3236
#include "icons.h"
3337

3438
#include "colorscheme.h"
@@ -112,6 +116,26 @@ void ProcessTemplateImage(wxImage& img, bool keepOpaque, bool inverted)
112116

113117
} // anonymous namespace
114118

119+
120+
121+
PoeditArtProvider::PoeditArtProvider()
122+
{
123+
#ifdef __WXGTK3__
124+
gtk_icon_theme_prepend_search_path(gtk_icon_theme_get_default(), GetIconsDir().fn_str());
125+
#endif
126+
}
127+
128+
129+
wxString PoeditArtProvider::GetIconsDir()
130+
{
131+
#if defined(__WXMSW__)
132+
return wxStandardPaths::Get().GetResourcesDir() + "\\Resources";
133+
#else
134+
return wxStandardPaths::Get().GetInstallPrefix() + "/share/poedit/icons";
135+
#endif
136+
}
137+
138+
115139
wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_,
116140
const wxArtClient& client,
117141
const wxSize& size)
@@ -147,12 +171,7 @@ wxBitmap PoeditArtProvider::CreateBitmap(const wxArtID& id_,
147171
}
148172
#endif // __WXGTK20__
149173

150-
wxString iconsdir =
151-
#if defined(__WXMSW__)
152-
wxStandardPaths::Get().GetResourcesDir() + "\\Resources";
153-
#else
154-
wxStandardPaths::Get().GetInstallPrefix() + "/share/poedit/icons";
155-
#endif
174+
auto iconsdir = GetIconsDir();
156175
if ( !wxDirExists(iconsdir) )
157176
{
158177
wxLogTrace("poedit.icons",

src/icons.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
#ifndef __WXOSX__
3636
class PoeditArtProvider : public wxArtProvider
3737
{
38+
public:
39+
PoeditArtProvider();
40+
3841
protected:
42+
static wxString GetIconsDir();
43+
3944
virtual wxBitmap CreateBitmap(const wxArtID& id,
4045
const wxArtClient& client,
4146
const wxSize& size);

src/wx/main_toolbar.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#include <wx/msw/uxtheme.h>
3939
#endif
4040

41+
#ifdef __WXGTK__
42+
#include <gtk/gtk.h>
43+
#endif
44+
4145

4246
class WXMainToolbar : public MainToolbar
4347
{
@@ -47,6 +51,15 @@ class WXMainToolbar : public MainToolbar
4751
m_tb = wxXmlResource::Get()->LoadToolBar(parent, "toolbar");
4852
m_idUpdate = XRCID("toolbar_update");
4953

54+
#ifdef __WXGTK3__
55+
gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(Toolbar())), GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
56+
SetIcon(0 , "document-open-symbolic");
57+
SetIcon(1 , "document-save-symbolic");
58+
SetIcon(3 , "poedit-validate-symbolic");
59+
SetIcon(4 , "poedit-update-symbolic");
60+
SetIcon(6 , "sidebar-symbolic");
61+
#endif
62+
5063
#ifdef __WXMSW__
5164
// De-uglify the toolbar a bit on Windows 10:
5265
if (IsWindows10OrGreater())
@@ -72,7 +85,11 @@ class WXMainToolbar : public MainToolbar
7285
{
7386
tool->SetLabel(_("Sync"));
7487
tool->SetShortHelp(_("Synchronize the translation with Crowdin"));
88+
#ifdef __WXGTK3__
89+
SetIcon(4 , "poedit-sync-symbolic");
90+
#else
7591
m_tb->SetToolNormalBitmap(m_idUpdate, wxArtProvider::GetBitmap("poedit-sync", wxART_TOOLBAR));
92+
#endif
7693
#ifdef __WXMSW__
7794
m_tb->SetToolDisabledBitmap(m_idUpdate, wxArtProvider::GetBitmap("poedit-sync@disabled", wxART_TOOLBAR));
7895
#endif
@@ -81,13 +98,36 @@ class WXMainToolbar : public MainToolbar
8198
{
8299
tool->SetLabel(MSW_OR_OTHER(_("Update from code"), _("Update from Code")));
83100
tool->SetShortHelp(_("Update catalog - synchronize it with sources"));
101+
#ifdef __WXGTK3__
102+
SetIcon(4 , "poedit-update-symbolic");
103+
#else
84104
m_tb->SetToolNormalBitmap(m_idUpdate, wxArtProvider::GetBitmap("poedit-update", wxART_TOOLBAR));
105+
#endif
85106
#ifdef __WXMSW__
86107
m_tb->SetToolDisabledBitmap(m_idUpdate, wxArtProvider::GetBitmap("poedit-update@disabled", wxART_TOOLBAR));
87108
#endif
88109
}
89110
}
90111

112+
#ifdef __WXGTK3__
113+
private:
114+
GtkToolbar *Toolbar()
115+
{
116+
#ifdef __WXGTK4__
117+
return GTK_TOOLBAR(m_tb->GetHandle());
118+
#else
119+
return GTK_TOOLBAR(gtk_bin_get_child(GTK_BIN(m_tb->GetHandle())));
120+
#endif
121+
}
122+
123+
void SetIcon(int index, const char *name)
124+
{
125+
GtkToolItem *i = gtk_toolbar_get_nth_item(Toolbar(), index);
126+
gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(i), NULL);
127+
gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(i), name);
128+
}
129+
#endif
130+
91131
private:
92132
wxToolBar *m_tb;
93133
int m_idUpdate;

0 commit comments

Comments
 (0)