2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 /** @file src/wx/wx_util.h
23 * @brief Some utility functions and classes.
27 #ifndef DCPOMATIC_WX_UTIL_H
28 #define DCPOMATIC_WX_UTIL_H
31 #include "lib/config.h"
32 #include "lib/dcpomatic_time.h"
33 #include <dcp/warnings.h>
34 LIBDCP_DISABLE_WARNINGS
35 #include <wx/gbsizer.h>
38 LIBDCP_ENABLE_WARNINGS
39 #include <boost/signals2.hpp>
40 #include <boost/thread.hpp>
44 class wxDirPickerCtrl;
46 class wxSpinCtrlDouble;
52 #define DCPOMATIC_SIZER_X_GAP 8
53 #define DCPOMATIC_SIZER_Y_GAP 8
54 #define DCPOMATIC_SIZER_GAP 8
55 #define DCPOMATIC_DIALOG_BORDER 12
57 #define DCPOMATIC_SPIN_CTRL_WIDTH 118
59 #define DCPOMATIC_SPIN_CTRL_WIDTH 56
62 /** Amount by which you need to bottom-pad text next to a checkbox in order
63 * for the text baselines to be aligned.
66 #define DCPOMATIC_CHECKBOX_BOTTOM_PAD 2
68 #define DCPOMATIC_CHECKBOX_BOTTOM_PAD 0
71 /** Amount by which you need to top-pad a choice to make it line up, in some cases */
73 #define DCPOMATIC_CHOICE_TOP_PAD 1
75 #define DCPOMATIC_CHOICE_TOP_PAD 0
78 /** Spacing to use between buttons in a vertical/horizontal line */
79 #if defined(DCPOMATIC_OSX) || defined(__WXGTK3__)
80 #define DCPOMATIC_BUTTON_STACK_GAP 2
82 #define DCPOMATIC_BUTTON_STACK_GAP 0
86 /** i18n macro to support strings like Context|String
87 * so that `String' can be translated to different things
88 * in different contexts.
90 #define S_(x) context_translation(x)
93 extern void error_dialog (wxWindow *, wxString, boost::optional<wxString> e = boost::optional<wxString>());
94 extern void message_dialog (wxWindow *, wxString);
95 extern bool confirm_dialog (wxWindow *, wxString);
96 extern wxStaticText* create_label (wxWindow* p, wxString t, bool left);
97 extern wxStaticText* add_label_to_sizer (wxSizer *, wxWindow *, wxString, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
98 extern wxStaticText* add_label_to_sizer (wxSizer *, wxStaticText *, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
99 extern wxStaticText* add_label_to_sizer (wxGridBagSizer *, wxWindow *, wxString, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
100 extern wxStaticText* add_label_to_sizer (wxGridBagSizer *, wxStaticText *, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
101 extern std::string wx_to_std (wxString);
102 extern wxString std_to_wx (std::string);
103 extern void dcpomatic_setup_i18n ();
104 extern wxString context_translation (wxString);
105 extern std::string string_client_data (wxClientData* o);
106 extern std::string selection_string_client_data(wxChoice* choice);
107 extern wxString time_to_timecode (dcpomatic::DCPTime t, double fps);
108 extern void setup_audio_channels_choice (wxChoice* choice, int minimum);
109 extern wxSplashScreen* maybe_show_splash ();
110 extern double calculate_mark_interval (double start);
111 extern bool display_progress (wxString title, wxString task);
112 extern bool report_errors_from_last_job (wxWindow* parent);
113 extern wxString bitmap_path (std::string name);
114 extern wxString icon_path(std::string name);
115 extern wxSize small_button_size (wxWindow* parent, wxString text);
116 extern bool gui_is_dark ();
117 extern double dpi_scale_factor (wxWindow* window);
118 extern int search_ctrl_height ();
119 extern void report_config_load_failure(wxWindow* parent, Config::LoadFailure what);
123 Offset (wxString n, int h, int m)
134 extern int get_offsets (std::vector<Offset>& offsets);
140 AudioAPI(wxString name, std::string id, RtAudio::Api rtaudio_id)
143 , _rtaudio_id(rtaudio_id)
146 wxString name() const {
150 std::string id() const {
154 RtAudio::Api rtaudio_id() const {
161 RtAudio::Api _rtaudio_id;
165 std::vector<AudioAPI> audio_apis();
166 AudioAPI id_to_audio_api(std::string id);
167 AudioAPI id_to_audio_api(boost::optional<std::string> id);
168 AudioAPI index_to_audio_api(int index);
171 extern void checked_set (FilePickerCtrl* widget, boost::filesystem::path value);
172 extern void checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value);
173 extern void checked_set (wxSpinCtrl* widget, int value);
174 extern void checked_set (wxSpinCtrlDouble* widget, double value);
175 extern void checked_set (wxChoice* widget, int value);
176 extern void checked_set (wxChoice* widget, std::string value);
177 extern void checked_set (wxChoice* widget, std::vector<std::pair<std::string, std::string> > items);
178 extern void checked_set (wxTextCtrl* widget, std::string value);
179 extern void checked_set (wxTextCtrl* widget, wxString value);
180 extern void checked_set (PasswordEntry* widget, std::string value);
181 extern void checked_set (wxCheckBox* widget, bool value);
182 extern void checked_set (wxRadioButton* widget, bool value);
183 extern void checked_set (wxStaticText* widget, std::string value);
184 extern void checked_set (wxStaticText* widget, wxString value);
186 extern int wx_get (wxChoice* widget);
187 extern int wx_get (wxSpinCtrl* widget);
188 extern double wx_get (wxSpinCtrlDouble* widget);
190 #ifdef DCPOMATIC_WINDOWS
191 #define DCPOMATIC_USE_OWN_PICKER