wxFileDialog and dbl clicking to open a file

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
DudeWonder
In need of some credit
In need of some credit
Posts: 3
Joined: Thu May 19, 2005 3:56 pm

wxFileDialog and dbl clicking to open a file

Post by DudeWonder » Thu May 19, 2005 4:08 pm

The problem I have is when I dbl click on a file to open it in the open file dialog of wxFileDialog. What it does is that the panel behind where I dbl clicked receives an OnMouseMove and OnMouseButtonUp event. This causes my application to do undesired things. It works fine when I click the file and click the open button.

To set you guys in context a bit, the panel behind the FileDialog is a map and clicking on it does various actions such as set waypoints or move the map around.

What I want to know is how do I stop the MouseEvent from getting processed by the panel behind the file dialog. Also, if there's a way to remove dbl clicking to open a file then that will be a quick and easy solution. I tried with a boolean that would omit any processing on first pass but because I process OnMouseMove and OnMouseButtonUp events, it doesn't work because one will set the boolean to true and then the other mouse event is called screwing stuff up again. I can't put 2 booleans because sometimes the dbl click doesn't land on the panel because of different user resolution or other factors so I don't want the user to be unable to set a waypoint for example on first pass.

Any help is much appreciated.

Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler » Thu May 19, 2005 4:16 pm

I have always found

Code: Select all

	panel->SetEvtHandlerEnabled(false);
	// ...
        // ... code that triggers unwanted events for panel ...
        // ...
	panel->SetEvtHandlerEnabled(true);
to be helpful. Perhaps you can surround your "open dialog" code with these calls?

DudeWonder
In need of some credit
In need of some credit
Posts: 3
Joined: Thu May 19, 2005 3:56 pm

Post by DudeWonder » Thu May 19, 2005 7:03 pm

Seemed like a good idea but unfortunately it isn't working. The event seems to be processed after the FileOpen is done and even after the function(OnMenuFileOpen in my case) is done thus produces the same results as I had before. Maybe there's a way to discard last event or something.

Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler » Thu May 19, 2005 8:06 pm

DudeWonder wrote:Seemed like a good idea but unfortunately it isn't working. The event seems to be processed after the FileOpen is done and even after the function(OnMenuFileOpen in my case) is done thus produces the same results as I had before. Maybe there's a way to discard last event or something.
If you don't mind posting some code, I could look at it more for ya.

leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio » Sat May 21, 2005 1:04 am

What platform are we talking about?
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/

DudeWonder
In need of some credit
In need of some credit
Posts: 3
Joined: Thu May 19, 2005 3:56 pm

Post by DudeWonder » Thu May 26, 2005 3:30 pm

Sorry for the late reply but I got put on another project for the last week or so. We are talking about Windows2000 plateform with Visual Studio .NET. WxWindows version 2.4.2. I can't upgrade for the moment since the project is sticking with 2.4.2 atm so any help is appreciated. I'll try to post some code if I can later today.

jflatt
Knows some wx things
Knows some wx things
Posts: 32
Joined: Fri May 26, 2006 12:55 am

Post by jflatt » Wed Mar 21, 2007 6:37 pm

I'm seeing the same thing with 2.8.2

MAIN.H

Code: Select all

#include "wx/app.h"
#include "frame.h"

class MyApp : public wxApp
{
public:
	virtual bool OnInit(); //called on application startup
};
MAIN.CPP

Code: Select all

#include "main.h"
DECLARE_APP(MyApp) //implements MyApp& for wxGetApp()
IMPLEMENT_APP(MyApp) //give wxWidgets the means to create MyApp object

bool MyApp::OnInit()
{
	Frame* frameMain = new Frame(NULL, wxID_ANY, wxT("Test"));
	frameMain->Show();
	return true; //start event loop
}
FRAME.H

Code: Select all

#include "wx/frame.h"
#include "wx/panel.h"
#include "wx/button.h"
#include "wx/filedlg.h"

class Frame : public wxFrame
{
public:
	Frame(wxWindow*, wxWindowID, const wxString&);
	~Frame();
private:
	wxPanel* m_backing;
	wxButton* m_button;
	void OnPanelClick(wxMouseEvent&);
	void OnButtonClick(wxCommandEvent&);
	void FileOpen();
};
FRAME.CPP

Code: Select all

#include "frame.h"

Frame::Frame(wxWindow* parent, wxWindowID id, const wxString& title) : wxFrame(parent, id, title, wxDefaultPosition, wxSize(1024, 768))
{
	m_backing = new wxPanel(this, wxID_ANY);
	m_button = new wxButton(m_backing, wxID_ANY, wxT("Open..."));
	m_backing->SetBackgroundColour(*wxRED);
	m_backing->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(Frame::OnPanelClick), NULL, this);
	m_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(Frame::OnButtonClick), NULL, this);
}

Frame::~Frame()
{
	wxDELETE(m_button);
	wxDELETE(m_backing);
}

void Frame::OnPanelClick(wxMouseEvent& event)
{
	static int click = 0;
	if (click % 3 == 0)
		m_backing->SetBackgroundColour(*wxRED);
	else if (click % 3 == 1)
		m_backing->SetBackgroundColour(*wxGREEN);
	else if (click % 3 == 2)
		m_backing->SetBackgroundColour(*wxBLUE);
	m_backing->Refresh();
	click++;
}

void Frame::OnButtonClick(wxCommandEvent& event)
{
	FileOpen();
}

void Frame::FileOpen()
{
	wxFileDialog ofd(this, wxT("Open"), wxT(""), wxT(""),
		wxT("All Files (*.*)|*.*"),
		wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR);
	if (ofd.ShowModal() == wxID_OK) //else cancel pressed
	{
		wxString file = ofd.GetPath();
	}
}

jflatt
Knows some wx things
Knows some wx things
Posts: 32
Joined: Fri May 26, 2006 12:55 am

Post by jflatt » Wed Mar 21, 2007 6:41 pm

This may seem obvious, but when the wxFileDialog file is double-clicked, and the dialog is not sitting on top of the window, the window doesn't seem to exhibit this behaviour.

jflatt
Knows some wx things
Knows some wx things
Posts: 32
Joined: Fri May 26, 2006 12:55 am

Post by jflatt » Wed Mar 21, 2007 10:45 pm

OK, it looks like:

Code: Select all

::wxSafeYield();
After returning from the modal wxFileDialog fixes it.

mentat
Knows some wx things
Knows some wx things
Posts: 30
Joined: Thu Mar 20, 2008 4:03 pm

Post by mentat » Mon Oct 13, 2008 8:52 pm

I am having exactly the same problem and suggested solutions above don't help at all..

This has been reported as bug here in wx trac years ago and seem to be ignored.

I suspect it is a win32 bug as some non-wx users reported similar things like here and here. First one hasn't been responded and second one I cannot see, needs membership..

I could only come up with ignoring ButtonUp events in the panel below wxFileDialog and only process ButtonDown events!! And this is not a solution... Any help will be appreciated.

Using wx-2.8.9 on Vista with VC++ 2008 Express..

User avatar
doublemax
Moderator
Moderator
Posts: 14514
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Mon Oct 13, 2008 9:49 pm

i just made some small modifications to the wxWidgets "dialogs" sample to test it, but could not reproduce the bug.

So it must depend on special circumstances.
Use the source, Luke!

mentat
Knows some wx things
Knows some wx things
Posts: 30
Joined: Thu Mar 20, 2008 4:03 pm

Post by mentat » Tue Oct 14, 2008 6:42 am

Thanks for the reply but 3 (or should I say 5) people report the same circumstance, and you cannot reproduce can also mean you have a special circumstance or you missed something to reproduce..

I just modified dialogs sample as follows and reproduced the problem:
1. Add a mouse event handler to MyCanvas as follows:

Code: Select all

BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
    EVT_PAINT(MyCanvas::OnPaint)
    EVT_MOUSE_EVENTS(MyCanvas::OnMouse) //HERE
END_EVENT_TABLE()
2. Add following OnMouse method to MyCanvas:

Code: Select all

void MyCanvas::OnMouse(wxMouseEvent& event)
{
	if(event.ButtonUp(wxMOUSE_BTN_LEFT))
		wxLogMessage("hello");
}

3. Then comment out the message box shown after file dialog in MyFrame::FileOpen method:

Code: Select all

if (dialog.ShowModal() == wxID_OK)
    {
    /*    wxString info;
        info.Printf(_T("Full file name: %s\n")
                    _T("Path: %s\n")
                    _T("Name: %s"),
                    dialog.GetPath().c_str(),
                    dialog.GetDirectory().c_str(),
                    dialog.GetFilename().c_str());
        wxMessageDialog dialog2(this, info, _T("Selected file"));
        dialog2.ShowModal();
		*/
    }

If I don't remove the message dialog code, the problem cannot be reproduced.

4. Now when I execute the app, and choose a file by "double clicking" when the mouse is exactly above the canvas also, I get a "Hello" message.

Can you please try to reproduce like this, thanks in advance.

Post Reply