OpenCPN Partial API docs
Loading...
Searching...
No Matches
hotkeys_dlg.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2024 Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#include <array>
25#include <string>
26
27#include <wx/button.h>
28#include <wx/dialog.h>
29#include <wx/grid.h>
30#include <wx/intl.h>
31#include <wx/sizer.h>
32#include <wx/stattext.h>
33#include <wx/string.h>
34
35#include "ocpn_plugin.h"
36
37#include "hotkeys_dlg.h"
38#include "manual.h"
39
40static inline wxString U8(const char* s) { return wxString::FromUTF8(s); }
41
43class ButtonsSizer : public wxStdDialogButtonSizer {
44public:
46 class ManualButton : public wxButton {
47 public:
48 ManualButton(wxWindow* parent)
49 : wxButton(parent, wxID_OK, _("Browse manual")) {
50 Bind(wxEVT_COMMAND_BUTTON_CLICKED, [&](wxCommandEvent) {
51 wxString datadir = GetPluginDataDir("manual_pi");
52 Manual(this, datadir.ToStdString()).Launch("Hotkeys");
53 });
54 }
55 };
56
58 class CloseButton : public wxButton {
59 public:
60 CloseButton(wxDialog* parent) : wxButton(parent, wxID_CLOSE) {
61 Bind(wxEVT_COMMAND_BUTTON_CLICKED,
62 [parent](wxCommandEvent) { parent->EndModal(wxID_OK); });
63 };
64 };
65
66 ButtonsSizer(wxDialog* parent) : wxStdDialogButtonSizer() {
67 AddButton(new ManualButton(parent));
68 AddButton(new CloseButton(parent));
69 Realize();
70 };
71};
72
74class GridSizer : public wxGridSizer {
75private:
76 static constexpr int kGridSize{4};
77 static constexpr int kNumMsgs{12};
78 using MsgLine = std::array<wxString, kGridSize>;
79 using Messages = std::array<MsgLine, kNumMsgs>;
80
81public:
82 GridSizer(wxWindow* parent) : wxGridSizer(kGridSize) {
83 const auto osSystemId = wxPlatformInfo::Get().GetOperatingSystemId();
84 const Messages& kMessages =
85 (osSystemId & wxOS_MAC) ? kMacMessages : kWinLinuxMessages;
86
87 for (const MsgLine& line : kMessages)
88 for (const wxString& word : line)
89 Add(new wxStaticText(parent, wxID_ANY, word),
90 wxSizerFlags().DoubleBorder());
91 }
92
93private:
94 // It's unclear whether _() actually works in this context or
95 // if wxTRANSLATE is needed instead...
96 const Messages kWinLinuxMessages{
97 // clang-format off
98 {{_("Zoom in"), "+, PgUp",
99 _("Zoom out"), "-, PgDown"},
100 {_("Fine zoom in"), "Alt +",
101 _("Fine zoom out"), "Alt -"},
102 {_("Fine zoom"), _("Ctrl scroll-wheel"),
103 "", ""},
104 {_("Panning"), U8("→ ← ↑ ↓")
105 , _("Slow panning"), U8("Alt → ← ↑ ↓")},
106 {_("Larger scale chart"), U8("Ctrl ←, F7"),
107 _("Smaller scale chart"), U8("Ctrl →, F8")},
108 {_("Toggle quilting "), "Q, F9",
109 _("Toggle auto-follow"), "Ctrl A, F2"},
110 {_("Toggle outlines"), "O, F12",
111 _("Toggle range rings"), "R"},
112 {_("Toggle chart bar"), "Ctrl B",
113 _("Change color scheme"), "Ctrl-G, F5"},
114 {_("Toggle full screen"), "F11",
115 "", ""},
116 {"", "", "", ""},
117 {_("Start measure mode"), "M, F4",
118 _("Stop measure mode"), "Esc"},
119 {_("Drop mark"), _("Ctrl O, space bar"),
120 _("Open Data Monitor"), "E"}}};
121
122 const Messages kMacMessages{
123 {{_("Zoom in"), "+, PgUp",
124 _("Zoom out"), "-, PgDown"},
125 {_("Fine zoom in"), "Alt +",
126 _("Fine zoom out"), "Alt -"},
127 {_("Fine zoom"), _("Ctrl scroll-wheel"),
128 "", ""},
129 {_("Panning"), U8("→ ← ↑ ↓")
130 , _("Slow panning"), U8("Alt → ← ↑ ↓")},
131 {_("Larger scale chart"), U8("Cmd ←, F7"),
132 _("Smaller scale chart"), U8("Cmd →, F8")},
133 {_("Toggle quilting "), "Q, F9",
134 _("Toggle auto-follow"), "Cmd A"},
135 {_("Toggle outlines"), "O, F12",
136 _("Toggle range rings"), "R"},
137 {_("Toggle chart bar"), "Ctrl B",
138 _("Change color scheme"), "Ctrl-G, F5"},
139 {_("Toggle full screen"), "Ctrl Cmd F",
140 "", ""},
141 {"", "", "", ""},
142 {_("Start measure mode"), "F4",
143 _("Stop measure mode"), "Esc"},
144 {_("Drop mark"), _("Ctrl O, space bar"),
145 _("Open Data Monitor"), "E"}}}; // clang-format on
146};
147
148HotkeysDlg::HotkeysDlg(wxWindow* parent)
149 : wxDialog(parent, wxID_ANY, _("Keyboard Shortcuts")) {
150 auto vbox = new wxBoxSizer(wxVERTICAL);
151 auto flags = wxSizerFlags().DoubleBorder();
152 vbox->Add(new GridSizer(this), flags.Expand());
153 vbox->Add(new wxStaticText(this, wxID_ANY,
154 _("More keys are available in the manual.")),
155 wxSizerFlags().DoubleBorder().Centre());
156 vbox->Add(new ButtonsSizer(this), flags.Expand());
157 SetSizer(vbox);
158 Fit();
159 Layout();
160 Bind(wxEVT_CLOSE_WINDOW, [&](wxCloseEvent&) { EndModal(wxID_OK); });
161}
wxString GetPluginDataDir(const char *plugin_name)
Returns an installed plugin's data directory given a plugin name.
The "Browse manual" button.
The Done button.
Overall help message: key functions and bindings in a string matrix.
Hotheys help dialog (the '?' button).
PlugIn Object Definition/API.