]> git.sesse.net Git - vlc/commitdiff
* modules/gui/wxwindows/*: hotkeys support.
authorGildas Bazin <gbazin@videolan.org>
Fri, 30 Apr 2004 23:21:44 +0000 (23:21 +0000)
committerGildas Bazin <gbazin@videolan.org>
Fri, 30 Apr 2004 23:21:44 +0000 (23:21 +0000)
modules/gui/wxwindows/interface.cpp
modules/gui/wxwindows/menus.cpp
modules/gui/wxwindows/wxwindows.cpp
modules/gui/wxwindows/wxwindows.h

index e86587379d9a81da30b393562d927defb4c2e482..7f759c2ceccefb92e9c27660a401e7c792e3de5b 100644 (file)
@@ -280,7 +280,7 @@ Interface::Interface( intf_thread_t *_p_intf ):
     SetDropTarget( new DragAndDrop( p_intf ) );
 #endif
 
-    UpdateAcceleratorTable();
+    SetupHotkeys();
 
     /* Start timer */
     timer = new Timer( p_intf, this );
@@ -702,43 +702,38 @@ void Interface::CreateOurExtendedPanel()
     extra_frame->Hide();
 }
 
-void Interface::UpdateAcceleratorTable()
+void Interface::SetupHotkeys()
 {
-    /* Set some hotkeys */
-    wxAcceleratorEntry entries[7];
-    vlc_value_t val;
-    int i = 0;
-
-    var_Get( p_intf->p_vlc, "key-quit", &val );
-    entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
-                      ConvertHotkey( val.i_int ), Exit_Event );
-    var_Get( p_intf->p_vlc, "key-stop", &val );
-    entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
-                      ConvertHotkey( val.i_int ), StopStream_Event );
-    var_Get( p_intf->p_vlc, "key-play-pause", &val );
-    entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
-                      ConvertHotkey( val.i_int ), PlayStream_Event );
-    var_Get( p_intf->p_vlc, "key-next", &val );
-    entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
-                      ConvertHotkey( val.i_int ), NextStream_Event );
-    var_Get( p_intf->p_vlc, "key-prev", &val );
-    entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
-                      ConvertHotkey( val.i_int ), PrevStream_Event );
-    var_Get( p_intf->p_vlc, "key-faster", &val );
-    entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
-                      ConvertHotkey( val.i_int ), FastStream_Event );
-    var_Get( p_intf->p_vlc, "key-slower", &val );
-    entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
-                      ConvertHotkey( val.i_int ), SlowStream_Event );
-
-    wxAcceleratorTable accel( 7, entries );
+    struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
+    int i_hotkeys;
 
-    if( !accel.Ok() )
-        msg_Err( p_intf, "invalid accelerator table" );
+    /* Count number of hoteys */
+    for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
+
+    p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
+    p_intf->p_sys->i_hotkeys = i_hotkeys;
+
+    wxAcceleratorEntry p_entries[i_hotkeys];
+
+    /* Setup the hotkeys as accelerators */
+    for( int i = 0; p_hotkeys[i].psz_action != NULL; i++ )
+    {
+        p_entries[i].Set( ConvertHotkeyModifiers( p_hotkeys[i].i_key ),
+                          ConvertHotkey( p_hotkeys[i].i_key ),
+                          p_intf->p_sys->i_first_hotkey_event + i );
+    }
 
-    SetAcceleratorTable( accel );
-    msg_Dbg( p_intf, "accelerator table loaded" );
+    wxAcceleratorTable accel( i_hotkeys, p_entries );
 
+    if( !accel.Ok() )
+    {
+        msg_Err( p_intf, "invalid accelerator table" );
+    }
+    else
+    {
+        SetAcceleratorTable( accel );
+        msg_Dbg( p_intf, "accelerator table loaded" );
+    }
 }
 
 /*****************************************************************************
index 108e021d0a15f497f6f324221c2e2da90c052689..f711c4a30432cfcf3cc2786b2234dc470fb04741 100644 (file)
@@ -97,7 +97,8 @@ enum
     AudioMenu_Events = wxID_HIGHEST + 2000,
     VideoMenu_Events = wxID_HIGHEST + 3000,
     NavigMenu_Events = wxID_HIGHEST + 4000,
-    PopupMenu_Events = wxID_HIGHEST + 6000
+    PopupMenu_Events = wxID_HIGHEST + 6000,
+    Hotkeys_Events = wxID_HIGHEST + 7000
 };
 
 BEGIN_EVENT_TABLE(Menu, wxMenu)
@@ -847,6 +848,8 @@ void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
 {
     wxMenuItem *p_menuitem = NULL;
+    int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
+    int i_hotkeys = p_intf->p_sys->i_hotkeys;
 
     /* Check if this is an auto generated menu item */
     if( event.GetId() < FirstAutoGenerated_Event )
@@ -855,6 +858,20 @@ void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
         return;
     }
 
+    /* Check if this is an hotkey event */
+    if( event.GetId() >= i_hotkey_event &&
+        event.GetId() < i_hotkey_event + i_hotkeys )
+    {
+        vlc_value_t val;
+
+        val.i_int =
+            p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
+
+        /* Get the key combination and send it to the hotkey handler */
+        var_Set( p_intf->p_vlc, "key-pressed", val );
+        return;
+    }
+
     if( !p_main_interface ||
         (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
         == NULL )
index fa57af8115d5f1ae30ddd502f7a067abc89c200e..85e9cd32247a7391525b1d4919b123bb990febfe 100644 (file)
@@ -130,6 +130,7 @@ static int Open( vlc_object_t *p_this )
         msg_Err( p_intf, "out of memory" );
         return VLC_ENOMEM;
     }
+    memset( p_intf->p_sys, 0, sizeof( intf_sys_t ) );
 
     p_intf->pf_run = Run;
 
index ef11a89c5953cccc17be85b59becc66ebea62f75..4afb973ac77981401172e7c00ba60fd33bafbede 100644 (file)
@@ -130,6 +130,11 @@ struct intf_sys_t
     /* Popup menu */
     wxMenu              *p_popup_menu;
 
+    /* Hotkeys */
+    int                 i_first_hotkey_event;
+    int                 i_hotkeys;
+
+    /* Embedded vout */
     VideoWindow         *p_video_window;
     wxBoxSizer          *p_video_sizer;
 };
@@ -209,7 +214,7 @@ public:
     wxGauge     *volctrl;
 
 private:
-    void UpdateAcceleratorTable();
+    void SetupHotkeys();
     void CreateOurMenuBar();
     void CreateOurToolBar();
     void CreateOurExtendedPanel();