Some missing i18n markup. Add S_ macro to allow contextual translations. Add update...
[dcpomatic.git] / src / wx / wx_util.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file src/wx/wx_util.h
21  *  @brief Some utility functions and classes.
22  */
23
24 #ifndef DCPOMATIC_WX_UTIL_H
25 #define DCPOMATIC_WX_UTIL_H
26
27 #include <wx/wx.h>
28 #include <wx/gbsizer.h>
29 #include <boost/function.hpp>
30 #include <boost/thread.hpp>
31 #include <boost/signals2.hpp>
32 #ifdef __WXGTK__
33 #include <gtk/gtk.h>
34 #endif
35
36 class wxFilePickerCtrl;
37 class wxSpinCtrl;
38 class wxSpinCtrlDouble;
39 class wxGridBagSizer;
40
41 #define DCPOMATIC_SIZER_X_GAP 8
42 #define DCPOMATIC_SIZER_Y_GAP 8
43 #define DCPOMATIC_SIZER_GAP 8
44 #define DCPOMATIC_DIALOG_BORDER 12
45
46 /** Spacing to use between buttons in a vertical line */
47 #ifdef DCPOMATIC_OSX
48 #define DCPOMATIC_BUTTON_STACK_GAP 2
49 #else
50 #define DCPOMATIC_BUTTON_STACK_GAP 0
51 #endif
52
53 /** i18n macro to support strings like Context|String
54  *  so that `String' can be translated to different things
55  *  in different contexts.
56  */
57 #define S_(x) context_translation(x)
58
59 extern void error_dialog (wxWindow *, wxString);
60 extern bool confirm_dialog (wxWindow *, wxString);
61 extern wxStaticText* add_label_to_sizer (wxSizer *, wxWindow *, wxString, bool left, int prop = 0);
62 extern wxStaticText* add_label_to_grid_bag_sizer (wxGridBagSizer *, wxWindow *, wxString, bool, wxGBPosition, wxGBSpan span = wxDefaultSpan);
63 extern std::string wx_to_std (wxString);
64 extern wxString std_to_wx (std::string);
65 extern void dcpomatic_setup_i18n ();
66 extern void run_gui_loop ();
67 extern wxString context_translation (wxString);
68
69 /** @class ThreadedStaticText
70  *
71  *  @brief A wxStaticText whose content is computed in a separate thread, to avoid holding
72  *  up the GUI while work is done.
73  */
74 class ThreadedStaticText : public wxStaticText
75 {
76 public:
77         ThreadedStaticText (wxWindow* parent, wxString initial, boost::function<std::string ()> fn);
78         ~ThreadedStaticText ();
79
80         /** Emitted in the UI thread when the text has been set up */
81         boost::signals2::signal<void()> Finished;
82
83 private:
84         void run (boost::function<std::string ()> fn);
85         void thread_finished (wxCommandEvent& ev);
86
87         /** Thread to do our work in */
88         boost::thread* _thread;
89         
90         static const int _update_event_id;
91 };
92
93 extern std::string string_client_data (wxClientData* o);
94
95 extern void checked_set (wxFilePickerCtrl* widget, std::string value);
96 extern void checked_set (wxSpinCtrl* widget, int value);
97 extern void checked_set (wxSpinCtrlDouble* widget, double value);
98 extern void checked_set (wxChoice* widget, int value);
99 extern void checked_set (wxChoice* widget, std::string value);
100 extern void checked_set (wxTextCtrl* widget, std::string value);
101 extern void checked_set (wxCheckBox* widget, bool value);
102 extern void checked_set (wxRadioButton* widget, bool value);
103 extern void checked_set (wxStaticText* widget, std::string value);
104
105 extern int wx_get (wxChoice* widget);
106 extern int wx_get (wxSpinCtrl* widget);
107 extern double wx_get (wxSpinCtrlDouble* widget);
108
109 /* GTK 2.24.17 has a buggy GtkFileChooserButton and it was put in Ubuntu 13.04.
110    This also seems to apply to 2.24.20 in Ubuntu 13.10 and 2.24.23 in Ubuntu 14.04.
111    Use our own dir picker as this is the least bad option I can think of.
112 */
113 #if defined(__WXMSW__) || (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION == 24 && (GTK_MICRO_VERSION == 17 || GTK_MICRO_VERSION == 20 || GTK_MICRO_VERSION == 23))
114 #define DCPOMATIC_USE_OWN_DIR_PICKER
115 #endif
116
117 #endif