[vlc-devel] commit: wxwidgets: Replace Volume Bar's wxGauge subclass by a wxSlider. ( Dominique Leuenberger )

git version control git at videolan.org
Sat Apr 12 20:10:42 CEST 2008


vlc | branch: master | Dominique Leuenberger <dominique at leuenberger.net> | Sun Apr  6 20:59:24 2008 +0300| [756b42166e316a1b767d3d3f66d5e8f0497c5568]

wxwidgets: Replace Volume Bar's wxGauge subclass by a wxSlider.

This ensure compatibility with wxGTK 2.8. The idea is to replace VLCVolCtrl with standard controls.

Signed-off-by: Pierre d'Herbemont <pdherbemont at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=756b42166e316a1b767d3d3f66d5e8f0497c5568
---

 modules/gui/wxwidgets/interface.cpp |  198 +++++++++++------------------------
 modules/gui/wxwidgets/interface.hpp |    3 +
 2 files changed, 63 insertions(+), 138 deletions(-)

diff --git a/modules/gui/wxwidgets/interface.cpp b/modules/gui/wxwidgets/interface.cpp
index 8a5577f..f3135e6 100644
--- a/modules/gui/wxwidgets/interface.cpp
+++ b/modules/gui/wxwidgets/interface.cpp
@@ -69,7 +69,7 @@
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
+ static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
                              vlc_value_t, void *);
 
 /*****************************************************************************
@@ -95,33 +95,6 @@ private:
 
 };
 
-class wxVolCtrl;
-class VLCVolCtrl : public wxControl
-{
-public:
-    VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
-    virtual ~VLCVolCtrl() {};
-
-    virtual void OnPaint( wxPaintEvent &event );
-    void OnChange( wxMouseEvent& event );
-    void UpdateVolume();
-
-  private:
-    DECLARE_EVENT_TABLE()
-
-    wxVolCtrl *gauge;
-    int i_y_offset;
-    vlc_bool_t b_mute;
-    intf_thread_t *p_intf;
-};
-
-BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
-    EVT_PAINT(VLCVolCtrl::OnPaint)
-
-    /* Mouse events */
-    EVT_LEFT_UP(VLCVolCtrl::OnChange)
-END_EVENT_TABLE()
-
 class Splitter : public wxSplitterWindow
 {
 public:
@@ -293,6 +266,8 @@ enum
     NextStream_Event,
     SlowStream_Event,
     FastStream_Event,
+    ToggleMute_Event,
+    SlideVolume_Event,
 
     /* it is important for the id corresponding to the "About" command to have
      * this standard value as otherwise it won't be handled properly under Mac
@@ -354,6 +329,8 @@ BEGIN_EVENT_TABLE(Interface, wxFrame)
     EVT_MENU(NextStream_Event, Interface::OnNextStream)
     EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
     EVT_MENU(FastStream_Event, Interface::OnFastStream)
+    EVT_MENU(ToggleMute_Event, Interface::OnToggleMute)
+    EVT_COMMAND_SCROLL(SlideVolume_Event, Interface::OnSlideVolume)
 
     /* Custom events */
     EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
@@ -540,7 +517,7 @@ void Interface::Init()
 void Interface::Update()
 {
     /* Misc updates */
-    if( !(i_update_counter % 10) ) ((VLCVolCtrl *)volctrl)->UpdateVolume();
+//    if( !(i_update_counter % 10) ) ((VLCVolCtrl *)volctrl)->UpdateVolume();
 
     if( playlist_manager ) playlist_manager->Update();
 
@@ -699,6 +676,7 @@ void Interface::CreateOurToolBar()
 #define HELP_PLN N_("Next playlist item")
 #define HELP_SLOW N_("Play slower")
 #define HELP_FAST N_("Play faster")
+#define HELP_VOL N_("Toggle mute/unmute of the audio")
 
 #define LABEL_OPEN N_("Open")
 #define LABEL_STOP N_("Stop")
@@ -710,6 +688,8 @@ void Interface::CreateOurToolBar()
 #define LABEL_PLN N_("Next")
 #define LABEL_SLOW N_("Slower")
 #define LABEL_FAST N_("Faster")
+#define LABEL_VOL N_("Mute")
+
     int minimal = config_GetInt( p_intf, "wx-minimal" );
     bool label = config_GetInt( p_intf, "wx-labels" );
 
@@ -756,14 +736,15 @@ void Interface::CreateOurToolBar()
                           wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
     }
 
-    wxControl *p_dummy_ctrl =
-        new wxControl( toolbar, -1, wxDefaultPosition,
-                       wxSize(16, 16 ), wxBORDER_NONE );
+    wxToolBarToolBase *v_tool = toolbar->AddTool( ToggleMute_Event,
+                         wxU(LABEL_VOL), wxBitmap( speaker_xpm ),
+                         wxU(_(HELP_VOL)), wxITEM_CHECK );
+    v_tool->SetClientData( v_tool );
 
-    toolbar->AddControl( p_dummy_ctrl );
-
-    volctrl = new VLCVolCtrl( p_intf, toolbar );
-    toolbar->AddControl( volctrl );
+    wxSlider *v_gauge = new wxSlider(toolbar, SlideVolume_Event, 256, 0,
+                            AOUT_VOLUME_MAX, wxDefaultPosition,
+                            wxSize(64,TOOLBAR_BMP_HEIGHT), wxSL_HORIZONTAL);
+    toolbar->AddControl(v_gauge);
 
     toolbar->Realize();
 
@@ -1226,6 +1207,49 @@ void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
     }
 }
 
+void Interface::OnToggleMute ( wxCommandEvent& WXUNUSED(event) )
+{
+    aout_VolumeMute(p_intf, NULL);
+    SyncVolume();
+
+}
+
+void Interface::SyncVolume()
+{
+    wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
+        GetToolBar()->GetToolClientData( ToggleMute_Event );
+    if ( !p_tool) return;
+
+    audio_volume_t i_volume;
+    aout_VolumeGet(p_intf, &i_volume);
+
+// Updating the Mute Button... IF the slider is completely moved to the left,
+// the mute icon is shown too.
+    p_tool->SetNormalBitmap( wxBitmap( i_volume ? speaker_xpm : speaker_mute_xpm ) );
+    GetToolBar()->Realize();
+#if defined( __WXMSW__ )
+    /* Needed to work around a bug in wxToolBar::Realize() */
+    GetToolBar()->SetSize( GetSize().GetWidth(),
+                           GetToolBar()->GetSize().GetHeight() );
+    GetToolBar()->Update();
+#endif
+// the Toggle to true and false is nescessary; otherwise, the Icon is not repainted
+    GetToolBar()->ToggleTool( ToggleMute_Event, true );
+    GetToolBar()->ToggleTool( ToggleMute_Event, false );
+    GetToolBar()->Update();
+}
+
+void Interface::OnSlideVolume( wxScrollEvent& WXUNUSED(event))
+{
+    wxSlider *p_tool = (wxSlider *)
+        GetToolBar()->FindControl( SlideVolume_Event );
+    if ( !p_tool) return;
+
+    aout_VolumeSet(p_intf , p_tool->GetValue());
+    SyncVolume();
+
+}
+
 void Interface::TogglePlayButton( int i_playing_status )
 {
     wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
@@ -1346,108 +1370,6 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
 #endif
 
 /*****************************************************************************
- * Definition of VolCtrl class.
- *****************************************************************************/
-class wxVolCtrl: public wxGauge
-{
-public:
-    /* Constructor */
-    wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
-               wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
-    virtual ~wxVolCtrl() {};
-
-    void UpdateVolume();
-    int GetVolume();
-
-    void OnChange( wxMouseEvent& event );
-
-private:
-    intf_thread_t *p_intf;
-
-    DECLARE_EVENT_TABLE();
-};
-
-BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
-    /* Mouse events */
-    EVT_LEFT_DOWN(wxVolCtrl::OnChange)
-    EVT_MOTION(wxVolCtrl::OnChange)
-END_EVENT_TABLE()
-
-wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
-                      wxPoint point, wxSize size )
-  : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
-{
-    p_intf = _p_intf;
-    UpdateVolume();
-}
-
-void wxVolCtrl::OnChange( wxMouseEvent& event )
-{
-    if( !event.LeftDown() && !event.LeftIsDown() ) return;
-
-    int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
-    aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
-    UpdateVolume();
-}
-
-void wxVolCtrl::UpdateVolume()
-{
-    audio_volume_t i_volume;
-    aout_VolumeGet( p_intf, &i_volume );
-
-    int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
-    if( i_gauge_volume == GetValue() ) return;
-
-    SetValue( i_gauge_volume );
-    SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
-                i_gauge_volume / 2 ) );
-}
-
-#if defined(__WXGTK__)
-#define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
-#else
-#define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
-#endif
-VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
-  :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
-              wxBORDER_NONE ),
-   i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
-   b_mute(0), p_intf(_p_intf)
-{
-    gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
-                           wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
-}
-
-void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
-{
-    wxPaintDC dc( this );
-    wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
-    dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
-}
-
-void VLCVolCtrl::OnChange( wxMouseEvent& event )
-{
-    if( event.GetX() < TOOLBAR_BMP_WIDTH )
-    {
-        int i_volume;
-        aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
-
-        b_mute = !b_mute;
-        Refresh();
-    }
-}
-
-void VLCVolCtrl::UpdateVolume()
-{
-    gauge->UpdateVolume();
-
-    int i_volume = gauge->GetValue();
-    if( !!i_volume == !b_mute ) return;
-    b_mute = !b_mute;
-    Refresh();
-}
-
-/*****************************************************************************
  * Systray class.
  *****************************************************************************/
 
diff --git a/modules/gui/wxwidgets/interface.hpp b/modules/gui/wxwidgets/interface.hpp
index fa55880..3f145a3 100644
--- a/modules/gui/wxwidgets/interface.hpp
+++ b/modules/gui/wxwidgets/interface.hpp
@@ -149,6 +149,9 @@ namespace wxvlc
         void OnNextStream( wxCommandEvent& event );
         void OnSlowStream( wxCommandEvent& event );
         void OnFastStream( wxCommandEvent& event );
+	void OnToggleMute( wxCommandEvent& event );
+	void OnSlideVolume( wxScrollEvent& event );
+        void SyncVolume( );
 
         void OnInteraction( wxCommandEvent& event );
 




More information about the vlc-devel mailing list