-Bug Description
When I click the context sensitive help button, the cursor turns into the correct ("?") one. If I click on a button that is NOT on the toolbar with this cursor, the resulting id for that button is correctly returned in the event.GetId() of my wxEVT_HELP handler. However, when I click on a toolbar button, the event.GetId() returns the ID of the TOOLBAR and NOT the ID of the clicked button.
-Expected vs observed behavior
I expect the ID of the toolbar button to be returned by the event.GetId(), and NOT the ID of the toolbar. This would be consistent with the button event handler invoked when clicking the button with the ordinary (not the context help) cursor.
-Details
I wrote a simple app with a main frame containing a sizer (with a single button) and a toolbar (with id = ID_Toolbar). The toolbar has a few buttons as shown here:
void MyFrame::LoadToolBars()
{
wxToolBar *toolbar = new wxToolBar(this, ID_Toolbar, wxDefaultPosition, wxSize(16, 16));
toolbar->AddTool(wxID_OPEN, "Open", wxBitmap("open.png", wxBITMAP_TYPE_PNG), "Open an existing file");
toolbar->AddTool(wxID_HELP, "Help", wxBitmap("help.png", wxBITMAP_TYPE_PNG), "Open help");
toolbar->AddTool(wxID_CONTEXT_HELP, "Context Help", wxBitmap("context.png", wxBITMAP_TYPE_PNG), "Open context help");
toolbar->Realize();
SetToolBar(toolbar);
}
The event handlers are bound as follows:
Bind(wxEVT_HELP, &MyFrame::OnHelpContext, this);
Bind(wxEVT_TOOL, &MyFrame::OnHelp, this, wxID_HELP);
Bind(wxEVT_TOOL, &MyFrame::OnContextButtonClicked, this, wxID_CONTEXT_HELP);
Bind(wxEVT_TOOL, &MyFrame::OnOpen, this, wxID_OPEN);
-Modification needed to get the button id when the context cursor clicks on the toolbar
Note in the code below for the wxEVT_HELP handler. when the toolbar button is clicked the event returns the ID_Toolbar for the toolbar. I added the code segment for the nID == ID_Toolbar if test to get the toolbar button ID. I don't think this should be necessary - the event.GetId() should return the button Id to be consistent with clicking with the non-context cursor.
void MyFrame::OnHelpContext(wxHelpEvent& event)
{
//wxEVT_HELP handler - gets called by wxContextHelp when item clicked
int nID = event.GetId();
if (nID == ID_Toolbar)
{
wxPoint pt = event.GetPosition();
wxToolBar *tb = GetToolBar();
wxPoint pt1 = tb->ScreenToClient(pt);
wxToolBarToolBase *base = tb->FindToolForPosition(pt1.x, pt1.y);
if (base) nID = base->GetId();
}
wxString str = wxString::Format("OnHelpContext called: %d", nID);
wxMessageBox(str);
}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I agree that it would be more useful to provide the ID of the tool in this event. We would probably need something like your code does in the event handler right now as I don't think Windows provides this information in HELPINFO
struct we receive.
And this would probably need to be done for all platforms, as I suspect all of them behave like this right now.
PRs improving this would be welcome!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I agree it would be useful to fix it for all platforms. In addition to the problem with the toolbar buttons that I mentioned, there is another problem which I don’t know how to fix. Namely, if you click one of the file menu headers with the context cursor, it won’t open to allow you to continue seeking context help for the menu items.
I don't think we can do anything about this. It used to be common to show context help for the menu items in the status bar when they're highlighted, but now applications don't even have a status bar, typically, so I don't know what are you supposed to do.
As noted, neither of these work now in that way. What would you suggestion I submit as a PR? I don’t think my “fix” is all that great for the general case.
We need to add a virtual function, something like wxWindow::GetHelpIdAtPoint()
, which would just return GetId()
by default but could be overridden in wxToolBar
using the code you showed to find the button at the given position and return its ID. I don't see any other/better way to do it.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Sorry, I don't have any plans to work on this myself in the observable future, all I can do is apply PRs improving this.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Closed #25802 as completed via cd5e67f.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.