Tidy up code to report failures to load config in the UI.
[dcpomatic.git] / src / wx / wx_util.h
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 /** @file src/wx/wx_util.h
23  *  @brief Some utility functions and classes.
24  */
25
26
27 #ifndef DCPOMATIC_WX_UTIL_H
28 #define DCPOMATIC_WX_UTIL_H
29
30
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>
36 #include <wx/wx.h>
37 LIBDCP_ENABLE_WARNINGS
38 #include <boost/signals2.hpp>
39 #include <boost/thread.hpp>
40
41
42 class FilePickerCtrl;
43 class wxDirPickerCtrl;
44 class wxSpinCtrl;
45 class wxSpinCtrlDouble;
46 class wxGridBagSizer;
47 class wxSplashScreen;
48 class PasswordEntry;
49
50
51 #define DCPOMATIC_SIZER_X_GAP 8
52 #define DCPOMATIC_SIZER_Y_GAP 8
53 #define DCPOMATIC_SIZER_GAP 8
54 #define DCPOMATIC_DIALOG_BORDER 12
55 #ifdef __WXGTK3__
56 #define DCPOMATIC_SPIN_CTRL_WIDTH 118
57 #else
58 #define DCPOMATIC_SPIN_CTRL_WIDTH 56
59 #endif
60
61 /** Amount by which you need to bottom-pad text next to a checkbox in order
62  *  for the text baselines to be aligned.
63  */
64 #ifdef DCPOMATIC_OSX
65 #define DCPOMATIC_CHECKBOX_BOTTOM_PAD 2
66 #else
67 #define DCPOMATIC_CHECKBOX_BOTTOM_PAD 0
68 #endif
69
70 /** Amount by which you need to top-pad a choice to make it line up, in some cases */
71 #ifdef DCPOMATIC_OSX
72 #define DCPOMATIC_CHOICE_TOP_PAD 1
73 #else
74 #define DCPOMATIC_CHOICE_TOP_PAD 0
75 #endif
76
77 /** Spacing to use between buttons in a vertical/horizontal line */
78 #if defined(DCPOMATIC_OSX) || defined(__WXGTK3__)
79 #define DCPOMATIC_BUTTON_STACK_GAP 2
80 #else
81 #define DCPOMATIC_BUTTON_STACK_GAP 0
82 #endif
83
84 #ifdef DCPOMATIC_LINUX
85 #define DCPOMATIC_RTAUDIO_API RtAudio::LINUX_PULSE
86 #endif
87 #ifdef DCPOMATIC_WINDOWS
88 #define DCPOMATIC_RTAUDIO_API RtAudio::UNSPECIFIED
89 #endif
90 #ifdef DCPOMATIC_OSX
91 #define DCPOMATIC_RTAUDIO_API RtAudio::MACOSX_CORE
92 #endif
93
94
95 /** i18n macro to support strings like Context|String
96  *  so that `String' can be translated to different things
97  *  in different contexts.
98  */
99 #define S_(x) context_translation(x)
100
101
102 extern void error_dialog (wxWindow *, wxString, boost::optional<wxString> e = boost::optional<wxString>());
103 extern void message_dialog (wxWindow *, wxString);
104 extern bool confirm_dialog (wxWindow *, wxString);
105 extern wxStaticText* create_label (wxWindow* p, wxString t, bool left);
106 extern wxStaticText* add_label_to_sizer (wxSizer *, wxWindow *, wxString, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
107 extern wxStaticText* add_label_to_sizer (wxSizer *, wxStaticText *, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
108 extern wxStaticText* add_label_to_sizer (wxGridBagSizer *, wxWindow *, wxString, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
109 extern wxStaticText* add_label_to_sizer (wxGridBagSizer *, wxStaticText *, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
110 extern std::string wx_to_std (wxString);
111 extern wxString std_to_wx (std::string);
112 extern void dcpomatic_setup_i18n ();
113 extern wxString context_translation (wxString);
114 extern std::string string_client_data (wxClientData* o);
115 extern wxString time_to_timecode (dcpomatic::DCPTime t, double fps);
116 extern void setup_audio_channels_choice (wxChoice* choice, int minimum);
117 extern wxSplashScreen* maybe_show_splash ();
118 extern double calculate_mark_interval (double start);
119 extern bool display_progress (wxString title, wxString task);
120 extern bool report_errors_from_last_job (wxWindow* parent);
121 extern wxString bitmap_path (std::string name);
122 extern wxSize small_button_size (wxWindow* parent, wxString text);
123 extern bool gui_is_dark ();
124 extern double dpi_scale_factor (wxWindow* window);
125 extern int search_ctrl_height ();
126 extern void report_config_load_failure(wxWindow* parent, Config::LoadFailure what);
127
128 struct Offset
129 {
130         Offset (wxString n, int h, int m)
131                 : name (n)
132                 , hour (h)
133                 , minute (m)
134         {}
135
136         wxString name;
137         int hour;
138         int minute;
139 };
140
141 extern int get_offsets (std::vector<Offset>& offsets);
142
143
144 extern void checked_set (FilePickerCtrl* widget, boost::filesystem::path value);
145 extern void checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value);
146 extern void checked_set (wxSpinCtrl* widget, int value);
147 extern void checked_set (wxSpinCtrlDouble* widget, double value);
148 extern void checked_set (wxChoice* widget, int value);
149 extern void checked_set (wxChoice* widget, std::string value);
150 extern void checked_set (wxChoice* widget, std::vector<std::pair<std::string, std::string> > items);
151 extern void checked_set (wxTextCtrl* widget, std::string value);
152 extern void checked_set (wxTextCtrl* widget, wxString value);
153 extern void checked_set (PasswordEntry* widget, std::string value);
154 extern void checked_set (wxCheckBox* widget, bool value);
155 extern void checked_set (wxRadioButton* widget, bool value);
156 extern void checked_set (wxStaticText* widget, std::string value);
157 extern void checked_set (wxStaticText* widget, wxString value);
158
159 extern int wx_get (wxChoice* widget);
160 extern int wx_get (wxSpinCtrl* widget);
161 extern double wx_get (wxSpinCtrlDouble* widget);
162
163 #ifdef DCPOMATIC_WINDOWS
164 #define DCPOMATIC_USE_OWN_PICKER
165 #endif
166
167
168 #endif