Repository navigation
Expand file tree
/
Copy pathTaskBarIcon.cpp
More file actions
56 lines (49 loc) · 1.73 KB
/
Copy pathTaskBarIcon.cpp
File metadata and controls
56 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Gammasoft.xpm"
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/panel.h>
#include <wx/settings.h>
#include <wx/stattext.h>
#include <wx/taskbar.h>
#include <wx/timer.h>
// Workaround : with wxWidgets version <= 3.2.0 wxTaskBarIcon mouse double click doesn't work on macOS
#if !defined(__APPLE__)
using TaskBarIcon = wxTaskBarIcon;
#else
class TaskBarIcon : public wxTaskBarIcon {
public:
TaskBarIcon(wxTaskBarIconType iconType = wxTBI_DEFAULT_TYPE) : wxTaskBarIcon {iconType} {
timer.Bind(wxEVT_TIMER, [&](wxTimerEvent& event) {
wxPostEvent(this, wxTaskBarIconEvent(wxEVT_TASKBAR_LEFT_DOWN, this));
wxPostEvent(this, wxTaskBarIconEvent(wxEVT_TASKBAR_LEFT_UP, this));
});
}
protected:
wxMenu* CreatePopupMenu() override {
if (!timer.IsRunning()) timer.StartOnce(wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC));
else wxPostEvent(this, wxTaskBarIconEvent(wxEVT_TASKBAR_LEFT_DCLICK, this));
return wxTaskBarIcon::CreatePopupMenu();
}
private:
wxTimer timer;
};
#endif
namespace TaskBarIconExample {
class Frame : public wxFrame {
public:
Frame() : wxFrame {nullptr, wxID_ANY, "TaskBarIcon example"} {
taskBarIcon.SetIcon(wxBitmapBundle::FromBitmap(wxBitmap {GammasoftIcon}));
taskBarIcon.Bind(wxEVT_TASKBAR_LEFT_DCLICK, [&](wxTaskBarIconEvent& event) {
Show(!IsShown());
});
}
private:
wxPanel* panel = new wxPanel {this};
wxStaticText* staticText1 = new wxStaticText {panel, wxID_ANY, "Double click on Gammasoft tray icon\nto show or hide this frame.", {10, 10}};
TaskBarIcon taskBarIcon;
};
class Application : public wxApp {
auto OnInit() -> bool override {return (new Frame)->Show();}
};
}
wxIMPLEMENT_APP(TaskBarIconExample::Application);