wxMoveEvent and wxButton Topic is solved

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
Kvaz1r
Earned some good credits
Earned some good credits
Posts: 125
Joined: Tue Jun 07, 2016 1:07 pm

wxMoveEvent and wxButton

Post by Kvaz1r » Mon Sep 02, 2019 6:07 am

According to the documentation wxMoveEvent is
holds information about wxTopLevelWindow move change events
then why it also generates the event for moving wxButton which isn't wxTopLevelWindow?

MCVE:

Code: Select all

#include <wx/wx.h>
#include <wx/dataview.h>

class MyFrame : public wxFrame
{
public:
	MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title)
	{
		wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);

		m_button = new wxButton(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0);
		m_button->Bind(wxEVT_MOVE, [this](wxMoveEvent& event) {
			m_textCtrl->AppendText("Move");
			event.Skip();
			});

		topSizer->Add(m_button, 0, wxALL, 5);

		m_button2 = new wxButton(this, wxID_ANY, wxT("Click"), wxDefaultPosition, wxDefaultSize, 0);
		m_button2->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
			[&](wxCommandEvent& event)
			{
				m_button->Move(50, 0);
			});

		topSizer->Add(m_button2, 0, wxALL, 5);
		m_textCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
		topSizer->Add(m_textCtrl, 0, wxALL, 5);

		this->SetSizer(topSizer);
		this->Layout();
		this->Centre(wxBOTH);
	}
private:
	wxButton* m_button;
	wxButton* m_button2;
	wxTextCtrl* m_textCtrl;
};

class MyApp : public wxApp
{
public:
	virtual bool OnInit()
	{
		if (!wxApp::OnInit())
			return false;
		MyFrame* frame = new MyFrame("wxWidgets application");
		frame->Show(true);
		return true;
	}
};

wxIMPLEMENT_APP(MyApp);
I got second "Move" text after click on Button with label.

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

Re: wxMoveEvent and wxButton

Post by doublemax » Mon Sep 02, 2019 4:03 pm

I think the documentation is just wrong/outdated. When searching the search code, you can see that the event is also generated under GTK and OSX.
Use the source, Luke!

Kvaz1r
Earned some good credits
Earned some good credits
Posts: 125
Joined: Tue Jun 07, 2016 1:07 pm

Re: wxMoveEvent and wxButton

Post by Kvaz1r » Mon Sep 02, 2019 5:48 pm

Yeah, thanks, now I see. I am going to open ticket on trac.

Post Reply