#34 clicking outside volume picker should close it

2.x
open
nobody
None
2012-10-04
2012-10-04
M Gagnon
No

clicking outside volume picker should close it (use wxPopupTransientWindow ?)

The following patch almost works, except the slider is not usable, perhaps due to wxOSX/Cocoa bugs

Index: Src/Pickers/VolumeSlider.cpp
===================================================================
--- Src/Pickers/VolumeSlider.cpp    (revision 1588)
+++ Src/Pickers/VolumeSlider.cpp    (working copy)
@@ -25,10 +25,10 @@
 #include "Utils.h"
 #include "AriaCore.h"

-#include <wx/dialog.h>
 #include <wx/event.h>
 #include <wx/slider.h>
 #include <wx/textctrl.h>
+#include <wx/popupwin.h>

 namespace AriaMaestosa
 {
@@ -37,12 +37,11 @@
       * @ingroup pickers
       * @brief small frame used to pick a note volume (velocity)
       */
-    class VolumeSlider : public wxDialog
+    class VolumeSlider : public wxPopupTransientWindow
     {
         wxSlider* m_slider;
         wxTextCtrl* m_value_text;
         wxPanel* m_pane;
-        int m_return_code;

         int m_note_ID;
         Track* m_current_track;
@@ -105,20 +104,20 @@
 const int VOLUME_SLIDER_FRAME_WIDTH = 50;
 const int VOLUME_SLIDER_FRAME_HEIGHT = 160;

-VolumeSlider::VolumeSlider() : wxDialog(NULL, wxNewId(),  _("volume"), wxDefaultPosition,
-                                        wxSize(VOLUME_SLIDER_FRAME_WIDTH, VOLUME_SLIDER_FRAME_HEIGHT),
-                                        wxSTAY_ON_TOP | wxWANTS_CHARS )
+VolumeSlider::VolumeSlider() : wxPopupTransientWindow(getMainFrame())
 {
     m_pane = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(VOLUME_SLIDER_FRAME_WIDTH,
                                                                    VOLUME_SLIDER_FRAME_HEIGHT));
+    m_pane->SetMaxSize( wxSize(VOLUME_SLIDER_FRAME_WIDTH, VOLUME_SLIDER_FRAME_HEIGHT) );
+    SetSize( wxSize(VOLUME_SLIDER_FRAME_WIDTH, VOLUME_SLIDER_FRAME_HEIGHT) );

     m_slider = new wxSlider(m_pane, wxNewId(), 60, 0, 127, wxDefaultPosition, wxSize(50,128),
                             wxSL_VERTICAL | wxSL_INVERSE | wxWANTS_CHARS);

     wxSize smallsize = wxDefaultSize;
-    smallsize.x = 50;
+    smallsize.x = VOLUME_SLIDER_FRAME_WIDTH - 4;

-    m_value_text = new wxTextCtrl(m_pane, wxNewId(), wxT("0"), wxPoint(0,130), smallsize,
+    m_value_text = new wxTextCtrl(m_pane, wxNewId(), wxT("0"), wxPoint(2,130), smallsize,
                                   wxTE_PROCESS_ENTER | wxWANTS_CHARS);
     m_note_ID = -1;
     m_current_track = NULL;
@@ -174,13 +173,16 @@
     m_current_track = track;
     m_note_ID       = noteID;

-    SetPosition(wxPoint(x,y));
+    Position(wxPoint(x,y), wxSize(VOLUME_SLIDER_FRAME_WIDTH, VOLUME_SLIDER_FRAME_HEIGHT));
     m_slider->SetValue(m_current_track->getNoteVolume(noteID));

     m_value_text->SetValue( to_wxString(m_current_track->getNoteVolume(noteID)) );

+    // Necessary to work around wxOSX/Cocoa bug
+    SetPosition(wxPoint(x,y));
+    Popup();
+    
     m_slider->SetFocus();
-    m_return_code = ShowModal();
 }

 // -------------------------------------------------------------------------------------------------------
@@ -263,7 +265,8 @@

 void VolumeSlider::closeWindow()
 {
-    wxDialog::EndModal(m_return_code);
+    //wxDialog::EndModal(m_return_code);
+    Dismiss();
     m_current_track = NULL;
     Display::requestFocus();

Index: Src/AriaCore.cpp
===================================================================
--- Src/AriaCore.cpp    (revision 1588)
+++ Src/AriaCore.cpp    (working copy)
@@ -211,6 +211,16 @@
             *x_out = winCoord.x;
             *y_out = winCoord.y;
         }
+        
+        void mainpaneToMainframe(const int x_in, const int y_in, int* x_out, int* y_out)
+        {
+            wxPoint screenCoord = mainPane->ClientToScreen(wxPoint(x_in,y_in));
+            wxPoint frameCoord = getMainFrame()->ScreenToClient(wxPoint(x_in,y_in));
+
+            *x_out = frameCoord.x;
+            *y_out = frameCoord.y;
+        }
+        
         void screenToClient(const int x_in, const int y_in, int* x_out, int* y_out)
         {
             wxPoint screenCoord = mainPane->ScreenToClient(wxPoint(x_in,y_in));
Index: Src/Editors/Editor.cpp
===================================================================
--- Src/Editors/Editor.cpp  (revision 1588)
+++ Src/Editors/Editor.cpp  (working copy)
@@ -714,6 +714,12 @@
         int screen_x, screen_y;
         Display::clientToScreen(x.getRelativeTo(WINDOW),y, &screen_x, &screen_y);
         showVolumeSlider(screen_x, screen_y, noteID, m_track);
+        
+        //int frame_x, frame_y;
+        //Display::mainpaneToMainframe(x.getRelativeTo(WINDOW),y, &frame_x, &frame_y);
+        //showVolumeSlider(frame_x, frame_y, noteID, m_track);
+        
+        //showVolumeSlider(x.getRelativeTo(WINDOW), y, noteID, m_track);
     }

 }
Index: Src/AriaCore.h
===================================================================
--- Src/AriaCore.h  (revision 1588)
+++ Src/AriaCore.h  (working copy)
@@ -120,7 +120,8 @@

         void clientToScreen(const int x_in, const int y_in, int* x_out, int* y_out);
         void screenToClient(const int x_in, const int y_in, int* x_out, int* y_out);
-        
+        void mainpaneToMainframe(const int x_in, const int y_in, int* x_out, int* y_out);
+
         void getTextExtents(wxString string, const wxFont& font, wxCoord* txw, wxCoord* txh,
                             wxCoord* descent, wxCoord* externalLeading);

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks