]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/wxwindows.h
First part of code to allow configurable hotkeys.
[vlc] / modules / gui / wxwindows / wxwindows.h
1 /*****************************************************************************
2  * wxwindows.h: private wxWindows interface description
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: wxwindows.h,v 1.52 2003/08/14 19:25:56 sigmunau Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include <wx/listctrl.h>
25 #include <wx/textctrl.h>
26 #include <wx/notebook.h>
27 #include <wx/spinctrl.h>
28 #include <wx/dnd.h>
29 #include <wx/treectrl.h>
30 #include <wx/gauge.h>
31 #include <wx/accel.h>
32 #include "vlc_keys.h"
33
34 DECLARE_LOCAL_EVENT_TYPE( wxEVT_DIALOG, 0 );
35
36 enum
37 {
38     FILE_ACCESS,
39     DISC_ACCESS,
40     NET_ACCESS,
41     SAT_ACCESS,
42     FILE_SIMPLE_ACCESS
43 };
44
45 class OpenDialog;
46 class Playlist;
47 class Messages;
48 class FileInfo;
49
50 #define SLIDER_MAX_POS 10000
51
52 /* wxU is used to convert ansi/utf8 strings to unicode strings (wchar_t) */
53 #if defined( ENABLE_NLS ) && defined( HAVE_GETTEXT ) && \
54     defined( WIN32 ) && !defined( HAVE_INCLUDED_GETTEXT )
55 #if wxUSE_UNICODE
56 #   define wxU(utf8) wxString(utf8, wxConvUTF8)
57 #else
58 #   define wxU(utf8) wxString(wxConvUTF8.cMB2WC(utf8), *wxConvCurrent)
59 #endif
60
61 #else // ENABLE_NLS && HAVE_GETTEXT && WIN32 && !HAVE_INCLUDED_GETTEXT
62 #if wxUSE_UNICODE
63 #   define wxU(ansi) wxString(ansi, *wxConvCurrent)
64 #else
65 #   define wxU(ansi) ansi
66 #endif
67
68 #endif
69
70 wxArrayString SeparateEntries( wxString );
71
72 /*****************************************************************************
73  * intf_sys_t: description and status of wxwindows interface
74  *****************************************************************************/
75 struct intf_sys_t
76 {
77     /* the wx parent window */
78     wxWindow            *p_wxwindow;
79     wxIcon              *p_icon;
80
81     /* special actions */
82     vlc_bool_t          b_playing;
83
84     /* The input thread */
85     input_thread_t *    p_input;
86
87     /* The slider */
88     int                 i_slider_pos;                     /* slider position */
89     int                 i_slider_oldpos;                /* previous position */
90     vlc_bool_t          b_slider_free;                      /* slider status */
91
92     /* The messages window */
93     msg_subscription_t* p_sub;                  /* message bank subscription */
94
95     /* Playlist management */
96     int                 i_playing;                 /* playlist selected item */
97
98     /* Send an event to show a dialog */
99     void (*pf_show_dialog) ( intf_thread_t *p_intf, int i_dialog, int i_arg,
100                              intf_dialog_args_t *p_arg );
101
102     /* Popup menu */
103     wxMenu              *p_popup_menu;
104
105 };
106
107 /*****************************************************************************
108  * Prototypes
109  *****************************************************************************/
110
111 /*****************************************************************************
112  * Classes declarations.
113  *****************************************************************************/
114 class Interface;
115
116 /* Timer */
117 class Timer: public wxTimer
118 {
119 public:
120     /* Constructor */
121     Timer( intf_thread_t *p_intf, Interface *p_main_interface );
122     virtual ~Timer();
123
124     virtual void Notify();
125
126 private:
127     intf_thread_t *p_intf;
128     Interface *p_main_interface;
129     int i_old_playing_status;
130     int i_old_rate;
131 };
132
133 /* Main Interface */
134 class Interface: public wxFrame
135 {
136 public:
137     /* Constructor */
138     Interface( intf_thread_t *p_intf );
139     virtual ~Interface();
140     void TogglePlayButton( int i_playing_status );
141
142     wxBoxSizer  *frame_sizer;
143     wxStatusBar *statusbar;
144
145     wxSlider    *slider;
146     wxWindow    *slider_frame;
147     wxStaticBox *slider_box;
148
149     wxGauge     *volctrl;
150
151 private:
152     void UpdateAcceleratorTable();
153     void CreateOurMenuBar();
154     void CreateOurToolBar();
155     void CreateOurSlider();
156     void Open( int i_access_method );
157
158     /* Event handlers (these functions should _not_ be virtual) */
159     void OnExit( wxCommandEvent& event );
160     void OnAbout( wxCommandEvent& event );
161
162     void OnShowDialog( wxCommandEvent& event );
163
164     void OnPlayStream( wxCommandEvent& event );
165     void OnStopStream( wxCommandEvent& event );
166     void OnSliderUpdate( wxScrollEvent& event );
167     void OnPrevStream( wxCommandEvent& event );
168     void OnNextStream( wxCommandEvent& event );
169     void OnSlowStream( wxCommandEvent& event );
170     void OnFastStream( wxCommandEvent& event );
171
172     void OnMenuOpen( wxMenuEvent& event );
173
174 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
175     void OnContextMenu2(wxContextMenuEvent& event);
176 #endif
177     void OnContextMenu(wxMouseEvent& event);
178
179     DECLARE_EVENT_TABLE();
180
181     Timer *timer;
182     intf_thread_t *p_intf;
183
184 private:
185     int i_old_playing_status;
186
187     /* For auto-generated menus */
188     wxMenu *p_audio_menu;
189     vlc_bool_t b_audio_menu;
190     wxMenu *p_video_menu;
191     vlc_bool_t b_video_menu;
192     wxMenu *p_navig_menu;
193     vlc_bool_t b_navig_menu;
194 };
195
196 /* Dialogs Provider */
197 class DialogsProvider: public wxFrame
198 {
199 public:
200     /* Constructor */
201     DialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
202     virtual ~DialogsProvider();
203
204 private:
205     void Open( int i_access_method, int i_arg );
206
207     /* Event handlers (these functions should _not_ be virtual) */
208     void OnExit( wxCommandEvent& event );
209     void OnPlaylist( wxCommandEvent& event );
210     void OnMessages( wxCommandEvent& event );
211     void OnFileInfo( wxCommandEvent& event );
212     void OnPreferences( wxCommandEvent& event );
213
214     void OnOpenFileGeneric( wxCommandEvent& event );
215     void OnOpenFileSimple( wxCommandEvent& event );
216     void OnOpenFile( wxCommandEvent& event );
217     void OnOpenDisc( wxCommandEvent& event );
218     void OnOpenNet( wxCommandEvent& event );
219     void OnOpenSat( wxCommandEvent& event );
220
221     void OnPopupMenu( wxCommandEvent& event );
222
223     void OnIdle( wxIdleEvent& event );
224
225     void OnExitThread( wxCommandEvent& event );
226
227     DECLARE_EVENT_TABLE();
228
229     intf_thread_t *p_intf;
230
231 public:
232     /* Secondary windows */
233     OpenDialog          *p_open_dialog;
234     wxFileDialog        *p_file_dialog;
235     Playlist            *p_playlist_dialog;
236     Messages            *p_messages_dialog;
237     FileInfo            *p_fileinfo_dialog;
238     wxFrame             *p_prefs_dialog;
239     wxFileDialog        *p_file_generic_dialog;
240 };
241
242 /* Open Dialog */
243 class SoutDialog;
244 class SubsFileDialog;
245 class OpenDialog: public wxFrame
246 {
247 public:
248     /* Constructor */
249     OpenDialog( intf_thread_t *p_intf, wxWindow *p_parent,
250                 int i_access_method, int i_arg = 0 );
251     virtual ~OpenDialog();
252
253     int Show();
254     int Show( int i_access_method, int i_arg = 0 );
255
256     wxArrayString mrl;
257
258 private:
259     wxPanel *FilePanel( wxWindow* parent );
260     wxPanel *DiscPanel( wxWindow* parent );
261     wxPanel *NetPanel( wxWindow* parent );
262     wxPanel *SatPanel( wxWindow* parent );
263
264     void UpdateMRL( int i_access_method );
265
266     /* Event handlers (these functions should _not_ be virtual) */
267     void OnOk( wxCommandEvent& event );
268     void OnCancel( wxCommandEvent& event );
269
270     void OnPageChange( wxNotebookEvent& event );
271     void OnMRLChange( wxCommandEvent& event );
272
273     /* Event handlers for the file page */
274     void OnFilePanelChange( wxCommandEvent& event );
275     void OnFileBrowse( wxCommandEvent& event );
276
277     /* Event handlers for the disc page */
278     void OnDiscPanelChange( wxCommandEvent& event );
279     void OnDiscTypeChange( wxCommandEvent& event );
280
281     /* Event handlers for the net page */
282     void OnNetPanelChange( wxCommandEvent& event );
283     void OnNetTypeChange( wxCommandEvent& event );
284
285     /* Event handlers for the stream output */
286     void OnSubsFileEnable( wxCommandEvent& event );
287     void OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) );
288
289     /* Event handlers for the stream output */
290     void OnSoutEnable( wxCommandEvent& event );
291     void OnSoutSettings( wxCommandEvent& WXUNUSED(event) );
292
293     /* Event handlers for the demux dump */
294     void OnDemuxDumpEnable( wxCommandEvent& event );
295     void OnDemuxDumpBrowse( wxCommandEvent& event );
296     void OnDemuxDumpChange( wxCommandEvent& event );
297
298     DECLARE_EVENT_TABLE();
299
300     intf_thread_t *p_intf;
301     wxWindow *p_parent;
302     int i_current_access_method;
303
304     wxComboBox *mrl_combo;
305     wxNotebook *notebook;
306
307     /* Controls for the file panel */
308     wxComboBox *file_combo;
309     wxFileDialog *file_dialog;
310
311     /* Controls for the disc panel */
312     wxRadioBox *disc_type;
313     wxTextCtrl *disc_device;
314     wxSpinCtrl *disc_title;
315     int        i_disc_title;
316     wxSpinCtrl *disc_chapter;
317     int        i_disc_chapter;
318
319     /* Controls for the net panel */
320     wxRadioBox *net_type;
321     int i_net_type;
322     wxPanel *net_subpanels[4];
323     wxRadioButton *net_radios[4];
324     wxSpinCtrl *net_ports[4];
325     int        i_net_ports[4];
326     wxTextCtrl *net_addrs[4];
327
328     /* Controls for the subtitles file */
329     wxButton *subsfile_button;
330     wxCheckBox *subsfile_checkbox;
331     SubsFileDialog *subsfile_dialog;
332     wxArrayString subsfile_mrl;
333
334     /* Controls for the stream output */
335     wxButton *sout_button;
336     wxCheckBox *sout_checkbox;
337     SoutDialog *sout_dialog;
338     wxArrayString sout_mrl;
339
340     /* Controls for the demux dump */
341     wxTextCtrl *demuxdump_textctrl;
342     wxButton *demuxdump_button;
343     wxCheckBox *demuxdump_checkbox;
344     wxFileDialog *demuxdump_dialog;
345 };
346
347 /* Stream output Dialog */
348 class SoutDialog: public wxDialog
349 {
350 public:
351     /* Constructor */
352     SoutDialog( intf_thread_t *p_intf, wxWindow *p_parent );
353     virtual ~SoutDialog();
354
355     wxArrayString GetOptions();
356
357 private:
358     void UpdateMRL();
359     wxPanel *AccessPanel( wxWindow* parent );
360     wxPanel *MiscPanel( wxWindow* parent );
361     wxPanel *EncapsulationPanel( wxWindow* parent );
362     wxPanel *TranscodingPanel( wxWindow* parent );
363     void    ParseMRL();
364
365     /* Event handlers (these functions should _not_ be virtual) */
366     void OnOk( wxCommandEvent& event );
367     void OnCancel( wxCommandEvent& event );
368     void OnMRLChange( wxCommandEvent& event );
369     void OnAccessTypeChange( wxCommandEvent& event );
370
371     /* Event handlers for the file access output */
372     void OnFileChange( wxCommandEvent& event );
373     void OnFileBrowse( wxCommandEvent& event );
374
375     /* Event handlers for the net access output */
376     void OnNetChange( wxCommandEvent& event );
377
378     /* Event specific to the sap address */
379     void OnSAPAddrChange( wxCommandEvent& event );
380     
381     /* Event handlers for the encapsulation panel */
382     void OnEncapsulationChange( wxCommandEvent& event );
383
384     /* Event handlers for the transcoding panel */
385     void OnTranscodingEnable( wxCommandEvent& event );
386     void OnTranscodingChange( wxCommandEvent& event );
387
388     /* Event handlers for the misc panel */
389     void OnSAPMiscChange( wxCommandEvent& event );
390
391     DECLARE_EVENT_TABLE();
392
393     intf_thread_t *p_intf;
394     wxWindow *p_parent;
395
396     wxComboBox *mrl_combo;
397
398     /* Controls for the access outputs */
399     wxPanel *access_subpanels[5];
400     wxCheckBox *access_checkboxes[5];
401
402     int i_access_type;
403
404     wxComboBox *file_combo;
405     wxSpinCtrl *net_ports[5];
406     wxTextCtrl *net_addrs[5];
407
408     /* Controls for the SAP announces */
409     wxPanel *misc_subpanels[1];
410     wxCheckBox *sap_checkbox;
411     wxTextCtrl *sap_addr;
412                             
413     /* Controls for the encapsulation */
414     wxRadioButton *encapsulation_radios[5];
415     int i_encapsulation_type;
416
417     /* Controls for transcoding */
418     wxCheckBox *video_transc_checkbox;
419     wxComboBox *video_codec_combo;
420     wxComboBox *audio_codec_combo;
421     wxCheckBox *audio_transc_checkbox;
422     wxComboBox *video_bitrate_combo;
423     wxComboBox *audio_bitrate_combo;
424     wxComboBox *audio_channels_combo;
425 };
426
427 /* Subtitles File Dialog */
428 class SubsFileDialog: public wxDialog
429 {
430 public:
431     /* Constructor */
432     SubsFileDialog( intf_thread_t *p_intf, wxWindow *p_parent );
433     virtual ~SubsFileDialog();
434
435     wxComboBox *file_combo;
436     wxComboBox *encoding_combo;
437     wxSpinCtrl *delay_spinctrl;
438     wxSpinCtrl *fps_spinctrl;
439
440 private:
441     /* Event handlers (these functions should _not_ be virtual) */
442     void OnOk( wxCommandEvent& event );
443     void OnCancel( wxCommandEvent& event );
444     void OnFileBrowse( wxCommandEvent& event );
445
446     DECLARE_EVENT_TABLE();
447
448     intf_thread_t *p_intf;
449     wxWindow *p_parent;
450 };
451
452 /* Preferences Dialog */
453 class PrefsTreeCtrl;
454 class PrefsDialog: public wxFrame
455 {
456 public:
457     /* Constructor */
458     PrefsDialog( intf_thread_t *p_intf, wxWindow *p_parent );
459     virtual ~PrefsDialog();
460
461 private:
462     wxPanel *PrefsPanel( wxWindow* parent );
463
464     /* Event handlers (these functions should _not_ be virtual) */
465     void OnOk( wxCommandEvent& event );
466     void OnCancel( wxCommandEvent& event );
467     void OnSave( wxCommandEvent& event );
468     void OnResetAll( wxCommandEvent& event );
469
470     DECLARE_EVENT_TABLE();
471
472     intf_thread_t *p_intf;
473
474     PrefsTreeCtrl *prefs_tree;
475 };
476
477 /* Messages */
478 class Messages: public wxFrame
479 {
480 public:
481     /* Constructor */
482     Messages( intf_thread_t *p_intf, wxWindow *p_parent );
483     virtual ~Messages();
484     void UpdateLog();
485
486 private:
487     /* Event handlers (these functions should _not_ be virtual) */
488     void OnClose( wxCommandEvent& event );
489     void OnVerbose( wxCommandEvent& event );
490     void OnClear( wxCommandEvent& event );
491     void OnSaveLog( wxCommandEvent& event );
492
493     DECLARE_EVENT_TABLE();
494
495     intf_thread_t *p_intf;
496     wxTextCtrl *textctrl;
497     wxTextAttr *info_attr;
498     wxTextAttr *err_attr;
499     wxTextAttr *warn_attr;
500     wxTextAttr *dbg_attr;
501
502     wxFileDialog *save_log_dialog;
503     
504     vlc_bool_t b_verbose;
505 };
506
507 /* Playlist */
508 class Playlist: public wxFrame
509 {
510 public:
511     /* Constructor */
512     Playlist( intf_thread_t *p_intf, wxWindow *p_parent );
513     virtual ~Playlist();
514
515     void UpdatePlaylist();
516     void ShowPlaylist( bool show );
517
518     bool b_need_update;
519     vlc_mutex_t lock;
520
521 private:
522     void DeleteItem( int item );
523
524     /* Event handlers (these functions should _not_ be virtual) */
525     void OnAddFile( wxCommandEvent& event );
526     void OnAddMRL( wxCommandEvent& event );
527     void OnClose( wxCommandEvent& event );
528     void OnOpen( wxCommandEvent& event );
529     void OnSave( wxCommandEvent& event );
530     void OnInvertSelection( wxCommandEvent& event );
531     void OnDeleteSelection( wxCommandEvent& event );
532     void OnSelectAll( wxCommandEvent& event );
533     void OnActivateItem( wxListEvent& event );
534     void OnKeyDown( wxListEvent& event );
535     void Rebuild();
536
537     DECLARE_EVENT_TABLE();
538
539     intf_thread_t *p_intf;
540     wxListView *listview;
541     int i_update_counter;
542 };
543
544 /* File Info */
545 class FileInfo: public wxFrame
546 {
547 public:
548     /* Constructor */
549     FileInfo( intf_thread_t *p_intf, wxWindow *p_parent );
550     virtual ~FileInfo();
551     void UpdateFileInfo();
552
553 private:
554     void OnClose( wxCommandEvent& event );
555
556     DECLARE_EVENT_TABLE();
557    
558     intf_thread_t *p_intf;
559     wxTreeCtrl *fileinfo_tree;
560     wxTreeItemId fileinfo_root;
561     wxString fileinfo_root_label;
562
563 };
564
565 #if !defined(__WXX11__)
566 /* Drag and Drop class */
567 class DragAndDrop: public wxFileDropTarget
568 {
569 public:
570     DragAndDrop( intf_thread_t *_p_intf );
571
572     virtual bool OnDropFiles( wxCoord x, wxCoord y,
573                               const wxArrayString& filenames );
574
575 private:
576     intf_thread_t *p_intf;
577 };
578 #endif
579
580 /* Menus */
581 void PopupMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
582                 const wxPoint& pos );
583 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent );
584 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent );
585 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent );
586
587 class MenuEvtHandler : public wxEvtHandler
588 {
589 public:
590     MenuEvtHandler( intf_thread_t *p_intf, Interface *p_main_interface );
591     virtual ~MenuEvtHandler();
592
593     void OnMenuEvent( wxCommandEvent& event );
594     void OnShowDialog( wxCommandEvent& event );
595
596 private:
597
598     DECLARE_EVENT_TABLE()
599
600     intf_thread_t *p_intf;
601     Interface *p_main_interface;
602 };
603
604 class Menu: public wxMenu
605 {
606 public:
607     /* Constructor */
608     Menu( intf_thread_t *p_intf, wxWindow *p_parent, int i_count,
609           char **ppsz_names, int *pi_objects, int i_start_id );
610     virtual ~Menu();
611
612 private:
613     /* Event handlers (these functions should _not_ be virtual) */
614     void OnClose( wxCommandEvent& event );
615     void OnShowDialog( wxCommandEvent& event );
616     void OnEntrySelected( wxCommandEvent& event );
617
618     wxMenu *Menu::CreateDummyMenu();
619     void   Menu::CreateMenuItem( wxMenu *, char *, vlc_object_t * );
620     wxMenu *Menu::CreateChoicesMenu( char *, vlc_object_t * );
621
622     DECLARE_EVENT_TABLE();
623
624     intf_thread_t *p_intf;
625
626     int  i_item_id;
627 };
628
629 static inline int ConvertHotkeyModifiers( int i_hotkey )
630 {
631     int i_accel_flags = 0;
632     if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
633     if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
634     if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
635     return i_accel_flags;
636 }
637
638 static inline int ConvertHotkey( int i_hotkey )
639 {
640     int i_key = i_hotkey & ~KEY_MODIFIER;
641     if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
642     else if( i_key & KEY_SPECIAL )
643     {
644         switch ( i_key )
645         {
646         case KEY_LEFT: return WXK_LEFT;
647         case KEY_RIGHT: return WXK_RIGHT;
648         case KEY_UP: return WXK_UP;
649         case KEY_DOWN: return WXK_DOWN;
650         case KEY_SPACE: return WXK_SPACE;
651         case KEY_ENTER: return WXK_RETURN;
652         case KEY_F1: return WXK_F1;
653         case KEY_F2: return WXK_F2;
654         case KEY_F3: return WXK_F3;
655         case KEY_F4: return WXK_F4;
656         case KEY_F5: return WXK_F5;
657         case KEY_F6: return WXK_F6;
658         case KEY_F7: return WXK_F7;
659         case KEY_F8: return WXK_F8;
660         case KEY_F9: return WXK_F9;
661         case KEY_F10: return WXK_F10;
662         case KEY_F11: return WXK_F11;
663         case KEY_F12: return WXK_F12;
664         case KEY_HOME: return WXK_HOME;
665         case KEY_END: return WXK_HOME;
666         case KEY_MENU: return WXK_MENU;
667         case KEY_ESC: return WXK_ESCAPE;
668         case KEY_PAGEUP: return WXK_PRIOR;
669         case KEY_PAGEDOWN: return WXK_NEXT;
670         case KEY_TAB: return WXK_TAB;
671         case KEY_BACKSPACE: return WXK_BACK;
672         default:
673             return 0;
674         }
675     }             
676 }