OpenCPN Partial API docs
Loading...
Searching...
No Matches
hotkeys_dlg.cpp
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, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
20#include <array>
21#include <string>
22
23#include <wx/button.h>
24#include <wx/dialog.h>
25#include <wx/grid.h>
26#include <wx/intl.h>
27#include <wx/sizer.h>
28#include <wx/stattext.h>
29#include <wx/string.h>
30
31#include "ocpn_plugin.h"
32
33#include "hotkeys_dlg.h"
34#include "manual.h"
35
36static inline wxString U8(const char* s) { return wxString::FromUTF8(s); }
37
39class ButtonsSizer : public wxStdDialogButtonSizer {
40public:
42 class ManualButton : public wxButton {
43 public:
44 ManualButton(wxWindow* parent)
45 : wxButton(parent, wxID_OK, _("Browse manual")) {
46 Bind(wxEVT_COMMAND_BUTTON_CLICKED, [&](wxCommandEvent) {
47 wxString datadir = GetPluginDataDir("manual_pi");
48 Manual(this, datadir.ToStdString()).Launch("Hotkeys");
49 });
50 }
51 };
52
54 class CloseButton : public wxButton {
55 public:
56 CloseButton(wxDialog* parent) : wxButton(parent, wxID_CLOSE) {
57 Bind(wxEVT_COMMAND_BUTTON_CLICKED,
58 [parent](wxCommandEvent) { parent->EndModal(wxID_OK); });
59 };
60 };
61
62 ButtonsSizer(wxDialog* parent) : wxStdDialogButtonSizer() {
63 AddButton(new ManualButton(parent));
64 AddButton(new CloseButton(parent));
65 Realize();
66 };
67};
68
70class GridSizer : public wxGridSizer {
71private:
72 static constexpr int kGridSize{4};
73 static constexpr int kNumMsgs{12};
74 using MsgLine = std::array<wxString, kGridSize>;
75 using Messages = std::array<MsgLine, kNumMsgs>;
76
77public:
78 GridSizer(wxWindow* parent) : wxGridSizer(kGridSize) {
79 const auto osSystemId = wxPlatformInfo::Get().GetOperatingSystemId();
80 const Messages& kMessages =
81 (osSystemId & wxOS_MAC) ? kMacMessages : kWinLinuxMessages;
82
83 for (const MsgLine& line : kMessages)
84 for (const wxString& word : line)
85 Add(new wxStaticText(parent, wxID_ANY, word),
86 wxSizerFlags().DoubleBorder());
87 }
88
89private:
90 // It's unclear whether _() actually works in this context or
91 // if wxTRANSLATE is needed instead...
92 const Messages kWinLinuxMessages{
93 // clang-format off
94 {{_("Zoom in"), "+, PgUp",
95 _("Zoom out"), "-, PgDown"},
96 {_("Fine zoom in"), "Alt +",
97 _("Fine zoom out"), "Alt -"},
98 {_("Fine zoom"), _("Ctrl scroll-wheel"),
99 "", ""},
100 {_("Panning"), U8("→ ← ↑ ↓")
101 , _("Slow panning"), U8("Alt → ← ↑ ↓")},
102 {_("Larger scale chart"), U8("Ctrl ←, F7"),
103 _("Smaller scale chart"), U8("Ctrl →, F8")},
104 {_("Toggle quilting "), "Q, F9",
105 _("Toggle auto-follow"), "Ctrl A, F2"},
106 {_("Toggle outlines"), "O, F12",
107 _("Toggle range rings"), "R"},
108 {_("Toggle chart bar"), "Ctrl B",
109 _("Change color scheme"), "Ctrl-G, F5"},
110 {_("Toggle full screen"), "F11",
111 "", ""},
112 {"", "", "", ""},
113 {_("Start measure mode"), "M, F4",
114 _("Stop measure mode"), "Esc"},
115 {_("Drop mark"), _("Ctrl O, space bar"),
116 _("Open NMEA debugger"), "E"}}};
117
118 const Messages kMacMessages{
119 {{_("Zoom in"), "+, PgUp",
120 _("Zoom out"), "-, PgDown"},
121 {_("Fine zoom in"), "Alt +",
122 _("Fine zoom out"), "Alt -"},
123 {_("Fine zoom"), _("Ctrl scroll-wheel"),
124 "", ""},
125 {_("Panning"), U8("→ ← ↑ ↓")
126 , _("Slow panning"), U8("Alt → ← ↑ ↓")},
127 {_("Larger scale chart"), U8("Cmd ←, F7"),
128 _("Smaller scale chart"), U8("Cmd →, F8")},
129 {_("Toggle quilting "), "Q, F9",
130 _("Toggle auto-follow"), "Cmd A"},
131 {_("Toggle outlines"), "O, F12",
132 _("Toggle range rings"), "R"},
133 {_("Toggle chart bar"), "Ctrl B",
134 _("Change color scheme"), "Ctrl-G, F5"},
135 {_("Toggle full screen"), "Ctrl Cmd F",
136 "", ""},
137 {"", "", "", ""},
138 {_("Start measure mode"), "F4",
139 _("Stop measure mode"), "Esc"},
140 {_("Drop mark"), _("Ctrl O, space bar"),
141 "", ""}}}; // clang-format on
142};
143
144HotkeysDlg::HotkeysDlg(wxWindow* parent)
145 : wxDialog(parent, wxID_ANY, _("Keyboard Shortcuts")) {
146 auto vbox = new wxBoxSizer(wxVERTICAL);
147 auto flags = wxSizerFlags().DoubleBorder();
148 vbox->Add(new GridSizer(this), flags.Expand());
149 vbox->Add(new wxStaticText(this, wxID_ANY,
150 _("More keys are available in the manual.")),
151 wxSizerFlags().DoubleBorder().Centre());
152 vbox->Add(new ButtonsSizer(this), flags.Expand());
153 SetSizer(vbox);
154 Fit();
155 Layout();
156 Bind(wxEVT_CLOSE_WINDOW, [&](wxCloseEvent&) { EndModal(wxID_OK); });
157}
The "Browse manual" button.
The Done button.
Overall help message: key functions and bindings in a string matrix.
PlugIn Object Definition/API.