f0e20be9598b015cb13fb8700220d0dfc3308d18
[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 wxString context_translation (wxString);
67
68 /** @class ThreadedStaticText
69  *
70  *  @brief A wxStaticText whose content is computed in a separate thread, to avoid holding
71  *  up the GUI while work is done.
72  */
73 class ThreadedStaticText : public wxStaticText
74 {
75 public:
76         ThreadedStaticText (wxWindow* parent, wxString initial, boost::function<std::string ()> fn);
77         ~ThreadedStaticText ();
78
79         /** Emitted in the UI thread when the text has been set up */
80         boost::signals2::signal<void()> Finished;
81
82 private:
83         void run (boost::function<std::string ()> fn);
84         void thread_finished (wxCommandEvent& ev);
85
86         /** Thread to do our work in */
87         boost::thread* _thread;
88         
89         static const int _update_event_id;
90 };
91
92 extern std::string string_client_data (wxClientData* o);
93
94 extern void checked_set (wxFilePickerCtrl* widget, std::string value);
95 extern void checked_set (wxSpinCtrl* widget, int value);
96 extern void checked_set (wxSpinCtrlDouble* widget, double value);
97 extern void checked_set (wxChoice* widget, int value);
98 extern void checked_set (wxChoice* widget, std::string value);
99 extern void checked_set (wxTextCtrl* widget, std::string value);
100 extern void checked_set (wxCheckBox* widget, bool value);
101 extern void checked_set (wxRadioButton* widget, bool value);
102 extern void checked_set (wxStaticText* widget, std::string value);
103
104 extern int wx_get (wxChoice* widget);
105 extern int wx_get (wxSpinCtrl* widget);
106 extern double wx_get (wxSpinCtrlDouble* widget);
107
108 /* GTK 2.24.17 has a buggy GtkFileChooserButton and it was put in Ubuntu 13.04.
109    This also seems to apply to 2.24.20 in Ubuntu 13.10 and 2.24.23 in Ubuntu 14.04.
110    Use our own dir picker as this is the least bad option I can think of.
111 */
112 #if defined(__WXMSW__) || (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION == 24 && (GTK_MICRO_VERSION == 17 || GTK_MICRO_VERSION == 20 || GTK_MICRO_VERSION == 23))
113 #define DCPOMATIC_USE_OWN_DIR_PICKER
114 #endif
115
116 #endif