Need wxSingleChoiceDialog using wxHtmlListBox?

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
macsinus
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon Feb 22, 2016 12:36 pm
Location: Leipzig, Germany

Need wxSingleChoiceDialog using wxHtmlListBox?

Post by macsinus »

My problem is that my users must choose one of a number of machine states which have short identifiers, not particularly meaningful for them.
However, for each state there are a number of tests to be performed, and for these there are more meaningful descriptions available.
I don't have influence on the identifiers, so I need to present the users with the test descriptions, but they are too long to put them all on one line for a given state.
wxSingleChoiceDialog would be exactly what I need, but it is based upon wxListBox, which doesn't support multi-line items.

Before I do some nasty cut-and-pasting of the source, has anyone done this already or got a better idea?

P.S. I also thought of using a wxTree control instead with the state identifiers at the top level and the test descriptions as branches, but this could confuse the users to think that they are selecting a single test rather than the whole set for the state.
wxWidgets 3.1.0
Boost 1.65
VS 2017
Win 7
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: Need wxSingleChoiceDialog using wxHtmlListBox?

Post by coderrc »

I'd probably put the "more meaningful description" as both a tooltip on mouse over and as a separate text field placed somewhere reasonable on the GUI upon selection of a test.
macsinus
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon Feb 22, 2016 12:36 pm
Location: Leipzig, Germany

Re: Need wxSingleChoiceDialog using wxHtmlListBox?

Post by macsinus »

Thank you coderrc - that's probably the best way to do it.
The tooltip would be a little tricky (to know which item in the ListBox the mouse pointer is over), but I can omit that when I display the description for the selected item prominently (left the list, right the description of the current selection).
Actually a standard pattern, but my thought processes were stuck in a dead-end and I only broke out with your help!
wxWidgets 3.1.0
Boost 1.65
VS 2017
Win 7
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Need wxSingleChoiceDialog using wxHtmlListBox?

Post by eranon »

macsinus wrote:Thank you coderrc - that's probably the best way to do it.
The tooltip would be a little tricky (to know which item in the ListBox the mouse pointer is over) [...]
You just derive from wxSingleChoiceDialog and catch the mouse movements over the inner wxListBox.

Tested adding this in the dialogs.h of dialogs sample:

Code: Select all

class MyChoiceDialog : public wxSingleChoiceDialog
{
	public:
		MyChoiceDialog(wxWindow *parent, const wxString& message, const wxString& caption, int n, 
					 const wxString *choices, void **clientData = NULL, long style = wxCHOICEDLG_STYLE, 
					 const wxPoint& pos = wxDefaultPosition) 
					 : wxSingleChoiceDialog(parent, message, caption, n, choices, clientData, style, pos){
			m_listbox->Connect(wxEVT_MOTION, wxMouseEventHandler(MyChoiceDialog::OnMouseOver), NULL, this);}

	private:
		void OnMouseOver(wxMouseEvent& event){
			wxPoint ptCurr = event.GetPosition();
			wxListBox* pCtrl = static_cast<wxListBox*>(event.GetEventObject());
			long nItem = pCtrl->HitTest(ptCurr);
			if (nItem != wxNOT_FOUND){
				pCtrl->SetToolTip(wxString::Format("Item %ld, Coord. %i x %ipx", nItem, ptCurr.x, ptCurr.y));}}
};
Of course, you have to change the type of the dialog called from wxSingleChoiceDialog to MyChoiceDialog in MyFrame::SingleChoice.

Here is the result:
snap_0005306.png
snap_0005306.png (15.33 KiB) Viewed 3757 times
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
macsinus
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon Feb 22, 2016 12:36 pm
Location: Leipzig, Germany

Re: Need wxSingleChoiceDialog using wxHtmlListBox?

Post by macsinus »

Thank you eranon - that's elegant, I wasn't aware that the item can be identified with the HitTest method.
In my case I'll stick to the 2-pane solution because the user might prefer to work with the keyboard or a touch-screen rather than the mouse, but it's something I'm glad to have learned.
wxWidgets 3.1.0
Boost 1.65
VS 2017
Win 7
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Need wxSingleChoiceDialog using wxHtmlListBox?

Post by eranon »

Of course, it all depends on your user's habits and contexts... And the two-panels way is maybe more "rich" on screen.

Also, an alternative could be to build your choice dialog in HTML relaying on javascript to return the selection, but it would require to go with wxWebView... An overkill for a single dialog (to keep in mind, in case you already use wxWebView elsewhere in your app).
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
macsinus
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon Feb 22, 2016 12:36 pm
Location: Leipzig, Germany

Re: Need wxSingleChoiceDialog using wxHtmlListBox?

Post by macsinus »

I might use HTML for the right-hand panel...
wxWidgets 3.1.0
Boost 1.65
VS 2017
Win 7
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Need wxSingleChoiceDialog using wxHtmlListBox?

Post by eranon »

Yep, but I guess going with wxHtmlWindow (light, self-contained class) rather than wxWebView (relaying on underlying back-end -- Trident or WebKit by default).
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
macsinus
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon Feb 22, 2016 12:36 pm
Location: Leipzig, Germany

Re: Need wxSingleChoiceDialog using wxHtmlListBox?

Post by macsinus »

I've attached my solution as a zip file.
Works for me, no guarantees! ;-)
The fbp file is a wxFormBuilder project which I used to generate the base window class.
Attachments
wxTwoPaneChoiceDialog.zip
(7.18 KiB) Downloaded 112 times
wxWidgets 3.1.0
Boost 1.65
VS 2017
Win 7
Post Reply