]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/wxwidgets.hpp
15c2c9c6d06f67e51a584ea5e9c4624137e16aab
[vlc] / modules / gui / wxwidgets / wxwidgets.hpp
1 /*****************************************************************************
2  * wxwidgets.hpp: Common headers for the wxwidges interface
3  *****************************************************************************
4  * Copyright (C) 1999-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef _WXVLC_WIDGETS_H_
25 #define _WXVLC_WIDGETS_H_
26
27 #ifdef WIN32                                                 /* mingw32 hack */
28 #undef Yield
29 #undef CreateDialog
30 #endif
31
32 #ifdef _MSC_VER
33 // turn off 'identifier was truncated to '255' characters in the debug info'
34 #   pragma warning( disable:4786 )
35 #endif
36
37 /* Let vlc take care of the i18n stuff */
38 #define WXINTL_NO_GETTEXT_MACRO
39
40 #include <vlc/vlc.h>
41 #include <vlc/intf.h>
42 #include "charset.h"
43
44 #include <wx/wx.h>
45 #define SLIDER_MAX_POS 10000
46
47 /*
48 #include <wx/listctrl.h>
49 #include <wx/textctrl.h>
50 #include <wx/notebook.h>
51 #include <wx/spinctrl.h>
52 #include <wx/dnd.h>
53 #include <wx/treectrl.h>
54 #include <wx/gauge.h>
55 #include <wx/accel.h>
56 #include <wx/checkbox.h>
57 #include <wx/wizard.h>
58 #include <wx/taskbar.h>
59 #include "vlc_keys.h"
60 */
61 #if (!wxCHECK_VERSION(2,5,0))
62 typedef long wxTreeItemIdValue;
63 #endif
64
65 DECLARE_LOCAL_EVENT_TYPE( wxEVT_DIALOG, 0 );
66 DECLARE_LOCAL_EVENT_TYPE( wxEVT_INTF, 1 );
67
68 /***************************************************************************
69  * I18N macros
70  ***************************************************************************/
71
72 /*
73  * wxU() is used to convert UTF-8 strings (typically from gettext)
74  * to unicode strings (wchar_t).
75  */
76 #if wxUSE_UNICODE
77 #   define wxU(utf8) wxString(utf8, wxConvUTF8)
78 #else
79 #   define wxU(utf8) wxString(wxConvUTF8.cMB2WC(utf8), *wxConvCurrent)
80 #endif
81
82 /*
83  * wxL2U() use to convert localized “data” strings (while wxU() would convert
84  * strings from gettext messages). Nowadays, the core use UTF-8 internally
85  * and wxL2U() is only an obsoloted name for wxU().
86  */
87 #define wxL2U(utf8) wxU(utf8)
88
89 #if wxUSE_UNICODE
90 /*
91  * Whoops, we assume that wchar_t is 32-bits and wide character encoding is
92  * UTF-32 (ok, both assumptions should de identical). This is not true on all
93  * platforms.
94  *
95  * On Windows, and possibly some other operating systems wchar_t is 16-bits,
96  * which means code points outside the Basic Multilingual Plane are encoded
97  * with surrogates as two subsequent wchar_t.
98  */
99 #   ifdef WIN32
100 /*
101  * Removing this #error without fixing the underlying problem is stricly
102  * FORBIDDEN. It would result in a _really_ completely unusable wxWidgets
103  * interface: all string operations would fail.
104  *
105  * Corrolary: Think twice, if not more, before you compile wxWidgets with
106  * Unicode on Windows.
107  */
108 #       error FIXME: this is not **REALLY** going to work at all.
109 #   endif
110 #   define wxFromLocale(wxstring) FromUTF32(wxstring.wc_str())
111 #   define wxLocaleFree(string) free(string)
112 #else
113 #   define wxFromLocale(wxstring) FromLocale(wxstring.mb_str())
114 #   define wxLocaleFree(string) LocaleFree(string)
115 #endif
116
117 /* From Locale functions to use for File Drop targets ... go figure */
118 #ifdef wxUSE_UNICODE
119 static inline char *wxDnDFromLocale( const wxChar *stupid )
120 {
121     /*
122      * FIXME: this is yet another awful and ugly bug-to-bug work-around
123      * for the painfully broken and brain-dead wxWidgets character
124      * encoding internals. Maybe, one day the wxWidgets team will find out
125      * and we will have to remove (phew) this kludge or autodetect whether
126      * to trigger it (damn).
127      *
128      * In Unicode mode, wxWidgets will encode file names in the locale
129      * encoding with each **bytes** (rather than characters) represented
130      * by a 32 bits unsigned integer. If you are lucky enough to be using
131      * ISO-8859-1 as your local character encoding, that lame encoding
132      * scheme happens to be identical to UTF-32 with your arch native
133      * byte-endianess. If you are using anything else, including not only
134      * UTF-8 but also Windows-1252(!) and ISO-8859-15(!) or any
135      * non-western encoding, it obviously fails.
136      */
137     const wxChar *braindead;
138     for (braindead = stupid; *braindead; braindead++);
139
140     size_t i = (braindead - stupid);
141     char psz_local[i + 1];
142     do
143         psz_local[i] = (char)stupid[i];
144     while (i--);
145
146     return FromLocaleDup( psz_local );
147 }
148 #   define wxDnDLocaleFree( string ) free( string )
149 #else
150 #   define wxDnDFromLocale( string ) wxFromLocale( string )
151 #   define wxDnDLocaleFree( string ) wxLocaleFree( string )
152 #endif
153
154 #define WRAPCOUNT 80
155
156 #define OPEN_NORMAL 0
157 #define OPEN_STREAM 1
158
159 enum
160 {
161   ID_CONTROLS_TIMER,
162   ID_SLIDER_TIMER,
163 };
164
165 namespace wxvlc {
166     class WindowSettings;
167     class VideoWindow;
168 };
169
170 using namespace wxvlc;
171
172 class DialogsProvider;
173 class PrefsTreeCtrl;
174 class AutoBuiltPanel;
175
176 /*****************************************************************************
177  * intf_sys_t: description and status of wxwindows interface
178  *****************************************************************************/
179 struct intf_sys_t
180 {
181     /* the wx parent window */
182     wxWindow            *p_wxwindow;
183     wxIcon              *p_icon;
184
185     /* window settings */
186     WindowSettings      *p_window_settings;
187
188     /* special actions */
189     vlc_bool_t          b_playing;
190     vlc_bool_t          b_intf_show;                /* interface to be shown */
191
192     /* The input thread */
193     input_thread_t *    p_input;
194
195     /* The messages window */
196     msg_subscription_t* p_sub;                  /* message bank subscription */
197
198     /* Playlist management */
199     int                 i_playing;                 /* playlist selected item */
200     unsigned            i_playlist_usage;
201
202     /* Send an event to show a dialog */
203     void (*pf_show_dialog) ( intf_thread_t *p_intf, int i_dialog, int i_arg,
204                              intf_dialog_args_t *p_arg );
205
206     /* Popup menu */
207     wxMenu              *p_popup_menu;
208
209     /* Hotkeys */
210     int                 i_first_hotkey_event;
211     int                 i_hotkeys;
212
213     /* Embedded vout */
214     VideoWindow         *p_video_window;
215     wxBoxSizer          *p_video_sizer;
216     vlc_bool_t          b_video_autosize;
217
218     /* Aout */
219     aout_instance_t     *p_aout;
220 };
221
222
223
224 wxArrayString SeparateEntries( wxString );
225 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
226
227 /*
228  * wxWindows keeps dead locking because the timer tries to lock the playlist
229  * when it's already locked somewhere else in the very wxWindows interface
230  * module. Unless someone implements a "vlc_mutex_trylock", we need that.
231  */
232 inline void LockPlaylist( intf_sys_t *p_sys, playlist_t *p_pl )
233 {
234     if( p_sys->i_playlist_usage++ == 0)
235         vlc_mutex_lock( &p_pl->object_lock );
236 }
237
238 inline void UnlockPlaylist( intf_sys_t *p_sys, playlist_t *p_pl )
239 {
240     if( --p_sys->i_playlist_usage == 0)
241         vlc_mutex_unlock( &p_pl->object_lock );
242 }
243
244 #endif