[PATCH] compatibility to wxGTK 2.8; VLCVolCtrl has been replaced wi=

Dominique Leuenberger dominique at leuenberger.net
Sun Apr 6 19:59:24 CEST 2008


th standard
 controls. Replaced wxGauge for VolumeBar by wxSlider.

---
 modules/gui/wxwidgets/interface.cpp |  200 +++++++++++---------------------=
---
 modules/gui/wxwidgets/interface.hpp |    3 +
 2 files changed, 64 insertions(+), 139 deletions(-)

diff --git a/modules/gui/wxwidgets/interface.cpp b/modules/gui/wxwidgets/int=
erface.cpp
index 8a5577f..f54f89d 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 *);
=20
 /**************************************************************************=
***
@@ -95,33 +95,6 @@ private:
=20
 };
=20
-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,
=20
     /* it is important for the id corresponding to the "About" command to h=
ave
      * 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)
=20
     /* 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(=
);
=20
     if( playlist_manager ) playlist_manager->Update();
=20
@@ -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")
=20
 #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 =3D config_GetInt( p_intf, "wx-minimal" );
     bool label =3D config_GetInt( p_intf, "wx-labels" );
=20
@@ -756,14 +736,15 @@ void Interface::CreateOurToolBar()
                           wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO))=
 );
     }
=20
-    wxControl *p_dummy_ctrl =3D
-        new wxControl( toolbar, -1, wxDefaultPosition,
-                       wxSize(16, 16 ), wxBORDER_NONE );
-
-    toolbar->AddControl( p_dummy_ctrl );
-
-    volctrl =3D new VLCVolCtrl( p_intf, toolbar );
-    toolbar->AddControl( volctrl );
+    wxToolBarToolBase *v_tool =3D toolbar->AddTool( ToggleMute_Event,
+                         wxU(LABEL_VOL), wxBitmap( speaker_xpm ),
+                         wxU(_(HELP_VOL)), wxITEM_CHECK );
+    v_tool->SetClientData( v_tool );
+
+    wxSlider *v_gauge =3D new wxSlider(toolbar, SlideVolume_Event, 256, 0,
+                            AOUT_VOLUME_MAX, wxDefaultPosition,
+                            wxSize(64,TOOLBAR_BMP_HEIGHT), wxSL_HORIZONTAL)=
;
+    toolbar->AddControl(v_gauge);
=20
     toolbar->Realize();
=20
@@ -1226,6 +1207,49 @@ void Interface::OnFastStream( wxCommandEvent& WXUNUSE=
D(event) )
     }
 }
=20
+void Interface::OnToggleMute ( wxCommandEvent& WXUNUSED(event) )
+{
+    aout_VolumeMute(p_intf, NULL);
+    SyncVolume();
+
+}
+
+void Interface::SyncVolume()
+{
+    wxToolBarToolBase *p_tool =3D (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 lef=
t,
+// the mute icon is shown too.
+    p_tool->SetNormalBitmap( wxBitmap( i_volume ? speaker_xpm : speaker_mut=
e_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 r=
epainted
+    GetToolBar()->ToggleTool( ToggleMute_Event, true );
+    GetToolBar()->ToggleTool( ToggleMute_Event, false );
+    GetToolBar()->Update();
+}
+
+void Interface::OnSlideVolume( wxScrollEvent& WXUNUSED(event))
+{
+    wxSlider *p_tool =3D (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 =3D (wxToolBarToolBase *)
@@ -1346,108 +1370,6 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
 #endif
=20
 /**************************************************************************=
***
- * Definition of VolCtrl class.
- **************************************************************************=
***/
-class wxVolCtrl: public wxGauge
-{
-public:
-    /* Constructor */
-    wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
-               wxPoint =3D wxDefaultPosition, wxSize =3D 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 =3D _p_intf;
-    UpdateVolume();
-}
-
-void wxVolCtrl::OnChange( wxMouseEvent& event )
-{
-    if( !event.LeftDown() && !event.LeftIsDown() ) return;
-
-    int i_volume =3D 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 =3D i_volume * 200 * 2 / AOUT_VOLUME_MAX;
-    if( i_gauge_volume =3D=3D 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 =3D 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 =3D !b_mute;
-        Refresh();
-    }
-}
-
-void VLCVolCtrl::UpdateVolume()
-{
-    gauge->UpdateVolume();
-
-    int i_volume =3D gauge->GetValue();
-    if( !!i_volume =3D=3D !b_mute ) return;
-    b_mute =3D !b_mute;
-    Refresh();
-}
-
-/**************************************************************************=
***
  * Systray class.
  **************************************************************************=
***/
=20
diff --git a/modules/gui/wxwidgets/interface.hpp b/modules/gui/wxwidgets/int=
erface.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 );
+=09void OnToggleMute( wxCommandEvent& event );
+=09void OnSlideVolume( wxScrollEvent& event );
+        void SyncVolume( );
=20
         void OnInteraction( wxCommandEvent& event );
=20
--=20
1.5.4.4

--=_2mn0sfwwrz6s--

--=_4r4czx3ty5q8
Content-Type: application/pgp-signature
Content-Description: PGP Digital Signature
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQBH+mqz5p8iCJtJfJkRAh+NAKDGiQ4kCVBRDoGBPm55O+NOUed4wQCfXHgi
ZF/6QBafKL4q6eovJTIH6mQ=
=7P5Y
-----END PGP SIGNATURE-----

--=_4r4czx3ty5q8--


More information about the vlc-devel mailing list