]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/wxwidgets.hpp
playlist.cpp, playlist.hpp: fix segfault when destroying playlist drop target (and...
[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
43 #include <wx/wx.h>
44 #define SLIDER_MAX_POS 10000
45
46 /*
47 #include <wx/listctrl.h>
48 #include <wx/textctrl.h>
49 #include <wx/notebook.h>
50 #include <wx/spinctrl.h>
51 #include <wx/dnd.h>
52 #include <wx/treectrl.h>
53 #include <wx/gauge.h>
54 #include <wx/accel.h>
55 #include <wx/checkbox.h>
56 #include <wx/wizard.h>
57 #include <wx/taskbar.h>
58 #include "vlc_keys.h"
59 */
60 #if (!wxCHECK_VERSION(2,5,0))
61 typedef long wxTreeItemIdValue;
62 #endif
63
64 DECLARE_LOCAL_EVENT_TYPE( wxEVT_DIALOG, 0 );
65 DECLARE_LOCAL_EVENT_TYPE( wxEVT_INTF, 1 );
66
67 /***************************************************************************
68  * I18N macros
69  ***************************************************************************/
70
71 /* wxU is used to convert ansi/utf8 strings to unicode strings (wchar_t) */
72 #if defined( ENABLE_NLS )
73 #if wxUSE_UNICODE
74 #   define wxU(utf8) wxString(utf8, wxConvUTF8)
75 #else
76 #   define wxU(utf8) wxString(wxConvUTF8.cMB2WC(utf8), *wxConvCurrent)
77 #endif
78 #else // ENABLE_NLS
79 #if wxUSE_UNICODE
80 #   define wxU(ansi) wxString(ansi, wxConvLocal)
81 #else
82 #   define wxU(ansi) (ansi)
83 #endif
84 #endif
85
86 /* wxL2U (locale to unicode) is used to convert ansi strings to unicode
87  * strings (wchar_t) */
88 #define wxL2U(ansi) wxU(ansi)
89
90 #if wxUSE_UNICODE
91 #   define wxFromLocale(wxstring) FromUTF32(wxstring.wc_str())
92 #   define wxLocaleFree(string) free(string)
93 #else
94 #   define wxFromLocale(wxstring) FromLocale(wxstring.mb_str())
95 #   define wxLocaleFree(string) LocaleFree(string)
96 #endif
97
98 /* From Locale functions to use for File Drop targets ... go figure */
99 #ifdef wxUSE_UNICODE
100 inline const char *wxDnDFromLocale( const wxChar *stupid )
101 {
102     /*
103      * FIXME: this is yet another awful and ugly bug-to-bug work-around
104      * for the painfully broken and brain-dead wxWidgets character
105      * encoding internals. Maybe, one day the wxWidgets team will find out
106      * and we will have to remove (phew) this kludge or autodetect whether
107      * to trigger it (damn).
108      *
109      * In Unicode mode, wxWidgets will encode file names in the locale
110      * encoding with each **bytes** (rather than characters) represented
111      * by a 32 bits unsigned integer. If you are lucky enough to be using
112      * ISO-8859-1 as your local character encoding, that lame encoding
113      * scheme happens to be identical to UTF-32 with your arch native
114      * byte-endianess. If you are using anything else, including not only
115      * UTF-8 but also Windows-1252(!) and ISO-8859-15(!) or any
116      * non-western encoding, it obviously fails.
117      */
118     const wxChar *braindead;
119     for (braindead = stupid; *braindead; braindead++);
120
121     size_t i = (braindead - stupid);
122     char *psz_local = (char *)malloc( i + 1 );
123     do
124         psz_local[i] = (char)stupid[i];
125     while (i--);
126
127     const char *psz_utf8 = FromLocale( psz_local );
128     free( psz_local );
129     return psz_utf8;
130 }
131 #else
132 #   define wxDnDFromLocale( string ) wxFromLocale( string )
133 #endif
134 #define wxDnDLocaleFree(string) LocaleFree( string )
135
136 #define WRAPCOUNT 80
137
138 #define OPEN_NORMAL 0
139 #define OPEN_STREAM 1
140
141 enum
142 {
143   ID_CONTROLS_TIMER,
144   ID_SLIDER_TIMER,
145 };
146
147 namespace wxvlc {
148     class WindowSettings;
149     class VideoWindow;
150 };
151
152 using namespace wxvlc;
153
154 class DialogsProvider;
155 class PrefsTreeCtrl;
156 class AutoBuiltPanel;
157
158 /*****************************************************************************
159  * intf_sys_t: description and status of wxwindows interface
160  *****************************************************************************/
161 struct intf_sys_t
162 {
163     /* the wx parent window */
164     wxWindow            *p_wxwindow;
165     wxIcon              *p_icon;
166
167     /* window settings */
168     WindowSettings      *p_window_settings;
169
170     /* special actions */
171     vlc_bool_t          b_playing;
172     vlc_bool_t          b_intf_show;                /* interface to be shown */
173
174     /* The input thread */
175     input_thread_t *    p_input;
176
177     /* The messages window */
178     msg_subscription_t* p_sub;                  /* message bank subscription */
179
180     /* Playlist management */
181     int                 i_playing;                 /* playlist selected item */
182     unsigned            i_playlist_usage;
183
184     /* Send an event to show a dialog */
185     void (*pf_show_dialog) ( intf_thread_t *p_intf, int i_dialog, int i_arg,
186                              intf_dialog_args_t *p_arg );
187
188     /* Popup menu */
189     wxMenu              *p_popup_menu;
190
191     /* Hotkeys */
192     int                 i_first_hotkey_event;
193     int                 i_hotkeys;
194
195     /* Embedded vout */
196     VideoWindow         *p_video_window;
197     wxBoxSizer          *p_video_sizer;
198     vlc_bool_t          b_video_autosize;
199
200     /* Aout */
201     aout_instance_t     *p_aout;
202 };
203
204
205
206 wxArrayString SeparateEntries( wxString );
207 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
208
209 /*
210  * wxWindows keeps dead locking because the timer tries to lock the playlist
211  * when it's already locked somewhere else in the very wxWindows interface
212  * module. Unless someone implements a "vlc_mutex_trylock", we need that.
213  */
214 inline void LockPlaylist( intf_sys_t *p_sys, playlist_t *p_pl )
215 {
216     if( p_sys->i_playlist_usage++ == 0)
217         vlc_mutex_lock( &p_pl->object_lock );
218 }
219
220 inline void UnlockPlaylist( intf_sys_t *p_sys, playlist_t *p_pl )
221 {
222     if( --p_sys->i_playlist_usage == 0)
223         vlc_mutex_unlock( &p_pl->object_lock );
224 }
225
226 #endif