4131ec0f795034e633e41ec44d12bd936c196a60
[dcpomatic.git] / src / wx / wx_util.h
1 /*
2     Copyright (C) 2012-2020 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 /** @file src/wx/wx_util.h
22  *  @brief Some utility functions and classes.
23  */
24
25 #ifndef DCPOMATIC_WX_UTIL_H
26 #define DCPOMATIC_WX_UTIL_H
27
28 #include "lib/dcpomatic_time.h"
29 #include "lib/warnings.h"
30 DCPOMATIC_DISABLE_WARNINGS
31 #include <wx/wx.h>
32 DCPOMATIC_ENABLE_WARNINGS
33 #include <wx/gbsizer.h>
34 #include <boost/function.hpp>
35 #include <boost/thread.hpp>
36 #include <boost/signals2.hpp>
37
38 class FilePickerCtrl;
39 class wxDirPickerCtrl;
40 class wxSpinCtrl;
41 class wxSpinCtrlDouble;
42 class wxGridBagSizer;
43 class wxSplashScreen;
44 class PasswordEntry;
45
46 #define DCPOMATIC_SIZER_X_GAP 8
47 #define DCPOMATIC_SIZER_Y_GAP 8
48 #define DCPOMATIC_SIZER_GAP 8
49 #define DCPOMATIC_DIALOG_BORDER 12
50
51 /** Spacing to use between buttons in a vertical/horizontal line */
52 #if defined(DCPOMATIC_OSX) || defined(__WXGTK3__)
53 #define DCPOMATIC_BUTTON_STACK_GAP 2
54 #else
55 #define DCPOMATIC_BUTTON_STACK_GAP 0
56 #endif
57
58 #ifdef DCPOMATIC_LINUX
59 #define DCPOMATIC_RTAUDIO_API RtAudio::LINUX_PULSE
60 #endif
61 #ifdef DCPOMATIC_WINDOWS
62 #define DCPOMATIC_RTAUDIO_API RtAudio::UNSPECIFIED
63 #endif
64 #ifdef DCPOMATIC_OSX
65 #define DCPOMATIC_RTAUDIO_API RtAudio::MACOSX_CORE
66 #endif
67
68 /** i18n macro to support strings like Context|String
69  *  so that `String' can be translated to different things
70  *  in different contexts.
71  */
72 #define S_(x) context_translation(x)
73
74 extern void error_dialog (wxWindow *, wxString, boost::optional<wxString> e = boost::optional<wxString>());
75 extern void message_dialog (wxWindow *, wxString);
76 extern bool confirm_dialog (wxWindow *, wxString);
77 extern wxStaticText* create_label (wxWindow* p, wxString t, bool left);
78 extern wxStaticText* add_label_to_sizer (wxSizer *, wxWindow *, wxString, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
79 extern wxStaticText* add_label_to_sizer (wxSizer *, wxStaticText *, bool left, int prop = 0, int flags = wxLEFT | wxRIGHT);
80 extern wxStaticText* add_label_to_sizer (wxGridBagSizer *, wxWindow *, wxString, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
81 extern wxStaticText* add_label_to_sizer (wxGridBagSizer *, wxStaticText *, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
82 extern std::string wx_to_std (wxString);
83 extern wxString std_to_wx (std::string);
84 extern void dcpomatic_setup_i18n ();
85 extern wxString context_translation (wxString);
86 extern std::string string_client_data (wxClientData* o);
87 extern wxString time_to_timecode (dcpomatic::DCPTime t, double fps);
88 extern void setup_audio_channels_choice (wxChoice* choice, int minimum);
89 extern wxSplashScreen* maybe_show_splash ();
90 extern double calculate_mark_interval (double start);
91 extern bool display_progress (wxString title, wxString task);
92 extern bool report_errors_from_last_job (wxWindow* parent);
93 extern wxString bitmap_path (std::string name);
94 extern wxSize small_button_size (wxWindow* parent, wxString text);
95
96 struct Offset
97 {
98         Offset (wxString n, int h, int m)
99                 : name (n)
100                 , hour (h)
101                 , minute (m)
102         {}
103
104         wxString name;
105         int hour;
106         int minute;
107 };
108
109 extern int get_offsets (std::vector<Offset>& offsets);
110
111
112 extern void checked_set (FilePickerCtrl* widget, boost::filesystem::path value);
113 extern void checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value);
114 extern void checked_set (wxSpinCtrl* widget, int value);
115 extern void checked_set (wxSpinCtrlDouble* widget, double value);
116 extern void checked_set (wxChoice* widget, int value);
117 extern void checked_set (wxChoice* widget, std::string value);
118 extern void checked_set (wxChoice* widget, std::vector<std::pair<std::string, std::string> > items);
119 extern void checked_set (wxTextCtrl* widget, std::string value);
120 extern void checked_set (wxTextCtrl* widget, wxString value);
121 extern void checked_set (PasswordEntry* widget, std::string value);
122 extern void checked_set (wxCheckBox* widget, bool value);
123 extern void checked_set (wxRadioButton* widget, bool value);
124 extern void checked_set (wxStaticText* widget, std::string value);
125 extern void checked_set (wxStaticText* widget, wxString value);
126
127 extern int wx_get (wxChoice* widget);
128 extern int wx_get (wxSpinCtrl* widget);
129 extern double wx_get (wxSpinCtrlDouble* widget);
130
131 #if defined(__WXMSW__)
132 #define DCPOMATIC_USE_OWN_PICKER
133 #endif
134
135 #endif