]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/wxwidgets.hpp
Merge branch 'master' of git@git.videolan.org:vlc
[vlc] / modules / gui / wxwidgets / wxwidgets.hpp
1 /*****************************************************************************
2  * wxwidgets.hpp: Common headers for the wxwidgets 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 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #ifndef _WXVLC_WIDGETS_H_
29 #define _WXVLC_WIDGETS_H_
30
31 #ifdef WIN32                                                 /* mingw32 hack */
32 #undef Yield
33 #undef CreateDialog
34 #endif
35
36 #ifdef _MSC_VER
37 // turn off 'identifier was truncated to '255' characters in the debug info'
38 #   pragma warning( disable:4786 )
39 #endif
40
41 /* Let vlc take care of the i18n stuff */
42 #define WXINTL_NO_GETTEXT_MACRO
43
44 #include <vlc/vlc.h>
45 #include <vlc_interface.h>
46 #include "vlc_charset.h"
47 #include <vlc_playlist.h>
48 #include <wx/wx.h>
49 #define SLIDER_MAX_POS 10000
50
51 /*
52 #include <wx/listctrl.h>
53 #include <wx/textctrl.h>
54 #include <wx/notebook.h>
55 #include <wx/spinctrl.h>
56 #include <wx/dnd.h>
57 #include <wx/treectrl.h>
58 #include <wx/gauge.h>
59 #include <wx/accel.h>
60 #include <wx/checkbox.h>
61 #include <wx/wizard.h>
62 #include <wx/taskbar.h>
63 #include "vlc_keys.h"
64 */
65 #if (!wxCHECK_VERSION(2,5,0))
66 typedef long wxTreeItemIdValue;
67 #endif
68
69 DECLARE_LOCAL_EVENT_TYPE( wxEVT_DIALOG, 0 );
70 DECLARE_LOCAL_EVENT_TYPE( wxEVT_INTF, 1 );
71
72 /***************************************************************************
73  * I18N macros
74  ***************************************************************************/
75
76 /*
77  * wxU() is used to convert UTF-8 strings (typically from gettext)
78  * to unicode strings (wchar_t).
79  */
80 #if wxUSE_UNICODE
81 #   define wxU(utf8) wxString(utf8, wxConvUTF8)
82 #else
83 #   define wxU(utf8) wxString(wxConvUTF8.cMB2WC(utf8), *wxConvCurrent)
84 #endif
85
86 /*
87  * wxL2U() use to convert localized “data” strings (while wxU() would convert
88  * strings from gettext messages). Nowadays, the core use UTF-8 internally
89  * and wxL2U() is only an obsoleted name for wxU().
90  */
91 #define wxL2U(utf8) wxU(utf8)
92
93 /*
94  * wxFromLocale() is a replacement for LibVLC FromLocale() that accepts
95  * a wxString.
96  *
97  * Note that if you want to use non-ANSI code page characters on Windows,
98  * you MUST build WxWidgets in “Unicode” mode. wxConvUTF8
99  */
100 static inline char *wxFromLocale (const wxString& string)
101 {
102 #if defined( wxUSE_UNICODE )
103 # if defined( WIN32 )
104     return FromWide ((const wchar_t *)string.c_str());
105 #  define wxLocaleFree free
106 # else
107     return FromLocaleDup (string.mb_str());
108 #  define wxLocaleFree free
109 # endif
110 #else
111 # warning Please use WxWidgets with Unicode.
112     return FromLocale (string.c_str());
113 # define wxLocaleFree LocaleFree
114 #endif
115 }
116     
117 /* From Locale functions to use for File Drop targets ... go figure */
118 #if defined( wxUSE_UNICODE ) && !defined( WIN32 )
119 static inline char *wxDnDFromLocale( const wxChar *stupid )
120 {
121     /*
122      * In Unicode mode, wxWidgets will encode file names in the locale
123      * encoding with each **bytes** (rather than characters) represented
124      * by a 32 bits unsigned integer. If you are lucky enough to be using
125      * ISO-8859-1 as your local character encoding, that lame encoding
126      * scheme happens to be identical to UTF-32 with your arch native
127      * byte-endianess. If you are using anything else, including not only
128      * UTF-8 but also Windows-1252(!) and ISO-8859-15(!) or any
129      * non-western encoding, it obviously fails.
130      */
131     size_t n = 0;
132     while (stupid[n])
133         n++;
134
135     char psz_local[n + 1];
136     for (size_t i = 0; i <= n; i++)
137         psz_local[i] = stupid[i];
138
139     // Kludge for (broken?) apps that adds a LF at the end of DnD
140     if ((n >= 1) && (strchr ("\n\r", stupid[n - 1]) != NULL))
141         psz_local[n - 1] = '\0';
142
143     return FromLocaleDup( psz_local );
144 }
145 #   define wxDnDLocaleFree free
146 #else
147 #   define wxDnDFromLocale wxFromLocale
148 #   define wxDnDLocaleFree wxLocaleFree
149 #endif
150
151 #define WRAPCOUNT 80
152
153 #define OPEN_NORMAL 0
154 #define OPEN_STREAM 1
155
156 enum
157 {
158   ID_CONTROLS_TIMER,
159   ID_SLIDER_TIMER,
160 };
161
162 namespace wxvlc {
163     class WindowSettings;
164     class VideoWindow;
165 };
166
167 using namespace wxvlc;
168
169 /*****************************************************************************
170  * intf_sys_t: description and status of wxwindows interface
171  *****************************************************************************/
172 struct intf_sys_t
173 {
174     /* the wx parent window */
175     wxWindow            *p_wxwindow;
176     wxIcon              *p_icon;
177
178     /* window settings */
179     WindowSettings      *p_window_settings;
180
181     /* special actions */
182     bool          b_playing;
183     bool          b_intf_show;                /* interface to be shown */
184
185     /* The input thread */
186     input_thread_t *    p_input;
187
188     /* The messages window */
189     msg_subscription_t* p_sub;                  /* message bank subscription */
190
191     /* Playlist management */
192     int                 i_playing;                 /* playlist selected item */
193     unsigned            i_playlist_usage;
194
195     /* Send an event to show a dialog */
196     void (*pf_show_dialog) ( intf_thread_t *p_intf, int i_dialog, int i_arg,
197                              intf_dialog_args_t *p_arg );
198
199     /* Popup menu */
200     wxMenu              *p_popup_menu;
201
202     /* Hotkeys */
203     int                 i_first_hotkey_event;
204     int                 i_hotkeys;
205
206     /* Embedded vout */
207     VideoWindow         *p_video_window;
208     wxBoxSizer          *p_video_sizer;
209     bool          b_video_autosize;
210
211     /* Aout */
212     aout_instance_t     *p_aout;
213 };
214
215
216
217 wxArrayString SeparateEntries( wxString );
218 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
219
220 /*
221  * wxWindows keeps dead locking because the timer tries to lock the playlist
222  * when it's already locked somewhere else in the very wxWindows interface
223  * module. Unless someone implements a "vlc_mutex_trylock", we need that.
224  */
225 inline void LockPlaylist( intf_sys_t *p_sys, playlist_t *p_pl )
226 {
227     if( p_sys->i_playlist_usage++ == 0)
228         vlc_mutex_lock( &p_pl->object_lock );
229 }
230
231 inline void UnlockPlaylist( intf_sys_t *p_sys, playlist_t *p_pl )
232 {
233     if( --p_sys->i_playlist_usage == 0)
234         vlc_mutex_unlock( &p_pl->object_lock );
235 }
236
237 #endif