Add indent option to wxGridBagSizer version of add_label_to_sizer
[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 "wx_ptr.h"
32 #include "lib/config.h"
33 #include "lib/dcpomatic_time.h"
34 #include <dcp/warnings.h>
35 LIBDCP_DISABLE_WARNINGS
36 #include <wx/gbsizer.h>
37 #include <wx/wx.h>
38 LIBDCP_ENABLE_WARNINGS
39 #include <boost/signals2.hpp>
40 #include <boost/thread.hpp>
41
42
43 class FilePickerCtrl;
44 class LanguageTagWidget;
45 class RegionSubtagWidget;
46 class wxDirPickerCtrl;
47 class wxSpinCtrl;
48 class wxSpinCtrlDouble;
49 class wxGridBagSizer;
50 class wxSplashScreen;
51 class PasswordEntry;
52
53
54 #define DCPOMATIC_SIZER_X_GAP 8
55 #define DCPOMATIC_SIZER_Y_GAP 8
56 #define DCPOMATIC_SIZER_GAP 8
57 #define DCPOMATIC_DIALOG_BORDER 12
58 #ifdef __WXGTK3__
59 #define DCPOMATIC_SPIN_CTRL_WIDTH 118
60 #else
61 #define DCPOMATIC_SPIN_CTRL_WIDTH 56
62 #endif
63
64 /** Amount by which you need to bottom-pad text next to a checkbox in order
65  *  for the text baselines to be aligned.
66  */
67 #ifdef DCPOMATIC_OSX
68 #define DCPOMATIC_CHECKBOX_BOTTOM_PAD 2
69 #else
70 #define DCPOMATIC_CHECKBOX_BOTTOM_PAD 0
71 #endif
72
73 #define DCPOMATIC_SUBHEADING_TOP_PAD 16
74
75 /** Amount by which you need to top-pad a choice to make it line up, in some cases */
76 #ifdef DCPOMATIC_OSX
77 #define DCPOMATIC_CHOICE_TOP_PAD 1
78 #else
79 #define DCPOMATIC_CHOICE_TOP_PAD 0
80 #endif
81
82 /** Spacing to use between buttons in a vertical/horizontal line */
83 #if defined(DCPOMATIC_OSX) || defined(__WXGTK3__)
84 #define DCPOMATIC_BUTTON_STACK_GAP 2
85 #else
86 #define DCPOMATIC_BUTTON_STACK_GAP 0
87 #endif
88
89 #ifdef DCPOMATIC_LINUX
90 #define DCPOMATIC_RTAUDIO_API RtAudio::LINUX_PULSE
91 #endif
92 #ifdef DCPOMATIC_WINDOWS
93 #define DCPOMATIC_RTAUDIO_API RtAudio::UNSPECIFIED
94 #endif
95 #ifdef DCPOMATIC_OSX
96 #define DCPOMATIC_RTAUDIO_API RtAudio::MACOSX_CORE
97 #endif
98
99
100 /** i18n macro to support strings like Context|String
101  *  so that `String' can be translated to different things
102  *  in different contexts.
103  */
104 #define S_(x) context_translation(x)
105
106
107 extern void error_dialog (wxWindow *, wxString, boost::optional<wxString> e = boost::optional<wxString>());
108 extern void message_dialog (wxWindow *, wxString);
109 extern bool confirm_dialog (wxWindow *, wxString);
110 extern wxStaticText* create_label (wxWindow* p, wxString t, bool left);
111 extern wxStaticText* add_label_to_sizer (wxSizer *, wxWindow *, wxString, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
112 extern wxStaticText* add_label_to_sizer (wxSizer *, wxStaticText *, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
113 extern wxStaticText* add_label_to_sizer(wxGridBagSizer *, wxWindow *, wxString, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan, bool indent = false);
114 extern wxStaticText* add_label_to_sizer (wxGridBagSizer *, wxStaticText *, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
115 extern std::string wx_to_std (wxString);
116 extern wxString std_to_wx (std::string);
117 extern void dcpomatic_setup_i18n ();
118 extern wxString context_translation (wxString);
119 extern std::string string_client_data (wxClientData* o);
120 extern wxString time_to_timecode (dcpomatic::DCPTime t, double fps);
121 extern void setup_audio_channels_choice (wxChoice* choice, int minimum);
122 extern wx_ptr<wxSplashScreen> maybe_show_splash();
123 extern double calculate_mark_interval (double start);
124 extern bool display_progress (wxString title, wxString task);
125 extern bool report_errors_from_last_job (wxWindow* parent);
126 extern wxString bitmap_path (std::string name);
127 extern wxString icon_path(std::string name);
128 extern wxSize small_button_size (wxWindow* parent, wxString text);
129 extern bool gui_is_dark ();
130 extern double dpi_scale_factor (wxWindow* window);
131 extern int search_ctrl_height ();
132 extern void report_config_load_failure(wxWindow* parent, Config::LoadFailure what);
133
134 struct Offset
135 {
136         Offset (wxString n, int h, int m)
137                 : name (n)
138                 , hour (h)
139                 , minute (m)
140         {}
141
142         wxString name;
143         int hour;
144         int minute;
145 };
146
147 extern int get_offsets (std::vector<Offset>& offsets);
148
149
150 extern void checked_set (FilePickerCtrl* widget, boost::filesystem::path value);
151 extern void checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value);
152 extern void checked_set (wxSpinCtrl* widget, int value);
153 extern void checked_set (wxSpinCtrlDouble* widget, double value);
154 extern void checked_set (wxChoice* widget, int value);
155 extern void checked_set (wxChoice* widget, std::string value);
156 extern void checked_set (wxChoice* widget, std::vector<std::pair<std::string, std::string> > items);
157 extern void checked_set (wxTextCtrl* widget, std::string value);
158 extern void checked_set (wxTextCtrl* widget, wxString value);
159 extern void checked_set (PasswordEntry* widget, std::string value);
160 extern void checked_set (wxCheckBox* widget, bool value);
161 extern void checked_set (wxRadioButton* widget, bool value);
162 extern void checked_set (wxStaticText* widget, std::string value);
163 extern void checked_set (wxStaticText* widget, wxString value);
164 extern void checked_set(LanguageTagWidget* widget, dcp::LanguageTag value);
165 extern void checked_set(LanguageTagWidget* widget, boost::optional<dcp::LanguageTag> value);
166 extern void checked_set(RegionSubtagWidget* widget, boost::optional<dcp::LanguageTag::RegionSubtag> value);
167
168 extern int wx_get (wxChoice* widget);
169 extern int wx_get (wxSpinCtrl* widget);
170 extern double wx_get (wxSpinCtrlDouble* widget);
171
172 #ifdef DCPOMATIC_WINDOWS
173 #define DCPOMATIC_USE_OWN_PICKER
174 #endif
175
176
177 #endif