d5e3325492b276c5f45625208b13e08288640974
[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/dcpomatic_time.h"
32 #include "lib/warnings.h"
33 DCPOMATIC_DISABLE_WARNINGS
34 #include <wx/wx.h>
35 DCPOMATIC_ENABLE_WARNINGS
36 #include <wx/gbsizer.h>
37 #include <boost/thread.hpp>
38 #include <boost/signals2.hpp>
39
40
41 class FilePickerCtrl;
42 class wxDirPickerCtrl;
43 class wxSpinCtrl;
44 class wxSpinCtrlDouble;
45 class wxGridBagSizer;
46 class wxSplashScreen;
47 class PasswordEntry;
48
49
50 #define DCPOMATIC_SIZER_X_GAP 8
51 #define DCPOMATIC_SIZER_Y_GAP 8
52 #define DCPOMATIC_SIZER_GAP 8
53 #define DCPOMATIC_DIALOG_BORDER 12
54 #ifdef __WXGTK3__
55 #define DCPOMATIC_SPIN_CTRL_WIDTH 118
56 #else
57 #define DCPOMATIC_SPIN_CTRL_WIDTH 56
58 #endif
59
60 /** Amount by which you need to bottom-pad text next to a checkbox in order
61  *  for the text baselines to be aligned.
62  */
63 #ifdef DCPOMATIC_OSX
64 #define DCPOMATIC_CHECKBOX_BOTTOM_PAD 2
65 #else
66 #define DCPOMATIC_CHECKBOX_BOTTOM_PAD 0
67 #endif
68
69 /** Spacing to use between buttons in a vertical/horizontal line */
70 #if defined(DCPOMATIC_OSX) || defined(__WXGTK3__)
71 #define DCPOMATIC_BUTTON_STACK_GAP 2
72 #else
73 #define DCPOMATIC_BUTTON_STACK_GAP 0
74 #endif
75
76 #ifdef DCPOMATIC_LINUX
77 #define DCPOMATIC_RTAUDIO_API RtAudio::LINUX_PULSE
78 #endif
79 #ifdef DCPOMATIC_WINDOWS
80 #define DCPOMATIC_RTAUDIO_API RtAudio::UNSPECIFIED
81 #endif
82 #ifdef DCPOMATIC_OSX
83 #define DCPOMATIC_RTAUDIO_API RtAudio::MACOSX_CORE
84 #endif
85
86
87 /** i18n macro to support strings like Context|String
88  *  so that `String' can be translated to different things
89  *  in different contexts.
90  */
91 #define S_(x) context_translation(x)
92
93
94 extern void error_dialog (wxWindow *, wxString, boost::optional<wxString> e = boost::optional<wxString>());
95 extern void message_dialog (wxWindow *, wxString);
96 extern bool confirm_dialog (wxWindow *, wxString);
97 extern wxStaticText* create_label (wxWindow* p, wxString t, bool left);
98 extern wxStaticText* add_label_to_sizer (wxSizer *, wxWindow *, wxString, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
99 extern wxStaticText* add_label_to_sizer (wxSizer *, wxStaticText *, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
100 extern wxStaticText* add_label_to_sizer (wxGridBagSizer *, wxWindow *, wxString, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
101 extern wxStaticText* add_label_to_sizer (wxGridBagSizer *, wxStaticText *, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
102 extern std::string wx_to_std (wxString);
103 extern wxString std_to_wx (std::string);
104 extern void dcpomatic_setup_i18n ();
105 extern wxString context_translation (wxString);
106 extern std::string string_client_data (wxClientData* o);
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 wxSize small_button_size (wxWindow* parent, wxString text);
115
116
117 struct Offset
118 {
119         Offset (wxString n, int h, int m)
120                 : name (n)
121                 , hour (h)
122                 , minute (m)
123         {}
124
125         wxString name;
126         int hour;
127         int minute;
128 };
129
130 extern int get_offsets (std::vector<Offset>& offsets);
131
132
133 extern void checked_set (FilePickerCtrl* widget, boost::filesystem::path value);
134 extern void checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value);
135 extern void checked_set (wxSpinCtrl* widget, int value);
136 extern void checked_set (wxSpinCtrlDouble* widget, double value);
137 extern void checked_set (wxChoice* widget, int value);
138 extern void checked_set (wxChoice* widget, std::string value);
139 extern void checked_set (wxChoice* widget, std::vector<std::pair<std::string, std::string> > items);
140 extern void checked_set (wxTextCtrl* widget, std::string value);
141 extern void checked_set (wxTextCtrl* widget, wxString value);
142 extern void checked_set (PasswordEntry* widget, std::string value);
143 extern void checked_set (wxCheckBox* widget, bool value);
144 extern void checked_set (wxRadioButton* widget, bool value);
145 extern void checked_set (wxStaticText* widget, std::string value);
146 extern void checked_set (wxStaticText* widget, wxString value);
147
148 extern int wx_get (wxChoice* widget);
149 extern int wx_get (wxSpinCtrl* widget);
150 extern double wx_get (wxSpinCtrlDouble* widget);
151
152 #if defined(__WXMSW__)
153 #define DCPOMATIC_USE_OWN_PICKER
154 #endif
155
156
157 #endif