2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 /** @file src/wx/wx_util.h
21 * @brief Some utility functions and classes.
24 #ifndef DCPOMATIC_WX_UTIL_H
25 #define DCPOMATIC_WX_UTIL_H
28 #include <wx/gbsizer.h>
29 #include <boost/function.hpp>
30 #include <boost/thread.hpp>
31 #include <boost/signals2.hpp>
36 class wxFilePickerCtrl;
38 class wxSpinCtrlDouble;
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
46 /** Spacing to use between buttons in a vertical line */
48 #define DCPOMATIC_BUTTON_STACK_GAP 2
50 #define DCPOMATIC_BUTTON_STACK_GAP 0
53 /** i18n macro to support strings like Context|String
54 * so that `String' can be translated to different things
55 * in different contexts.
57 #define S_(x) context_translation(x)
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);
69 /** @class ThreadedStaticText
71 * @brief A wxStaticText whose content is computed in a separate thread, to avoid holding
72 * up the GUI while work is done.
74 class ThreadedStaticText : public wxStaticText
77 ThreadedStaticText (wxWindow* parent, wxString initial, boost::function<std::string ()> fn);
78 ~ThreadedStaticText ();
80 /** Emitted in the UI thread when the text has been set up */
81 boost::signals2::signal<void()> Finished;
84 void run (boost::function<std::string ()> fn);
85 void thread_finished (wxCommandEvent& ev);
87 /** Thread to do our work in */
88 boost::thread* _thread;
90 static const int _update_event_id;
93 extern std::string string_client_data (wxClientData* o);
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);
105 extern int wx_get (wxChoice* widget);
106 extern int wx_get (wxSpinCtrl* widget);
107 extern double wx_get (wxSpinCtrlDouble* widget);
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.
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