wxWidgets widget IDs - c++

I'm a little bit confused about how the IDs work in wxWidgets, do I have to ensure that all ids across all windows that I create are unique to each of their own functions? Like if I have two wxID_OK's for two different dialog boxes are they going to start firing off events in other windows just because they share the same id?
Currently I've been maintaining a huge enum to grab my IDs from, this seems a bit silly though, and was wondering if I just had a misunderstanding of what is actually going on.

I nerver use id's nowadays. I use wxID_ANY for all widgets and use the widget pointer for identification. This works just as well and so there is no reason for two id's for the same widget. There might be some corner cases where real id's are required but i have not found any.

It's a good idea to use unique IDs inside each top level window (i.e. a wxFrame or a wxDialog) because the controls include their ID in the wxCommandEvents they generate and as command events are propagated upwards the window hierarchy until they reach the first top level window, it could be confusing to have 2 controls with the same ID as any handler defined in their common parent window would need to be careful to distinguish between them.
There are no restrictions on the reuse of IDs in different dialog boxes however.
And an even better idea is to not use any non standard IDs at all but just let wxWidgets generate them for you by specifying wxID_ANY when creating controls and using Bind() to connect your event handlers instead of the IDs in the event tables.

Related

Menu designed for use without mouse. What is the best way to implement?

I'm writing a GUI using QT for embedded system with linux. This device has no mouse. Only display and specific keyboard with keys: up, down, return and 7 number keys.
The software will be used to set some parameters of device and read them (some charts also).
Example of how menu could look:
after OPTION 1 selected
After SUBOPTION 1 selected some table with data is loaded.
Sometimes after selecting option i need to load specific widget and sometimes just another set of options.
I think it is possible to implement custom labels and kind of list widget that aligns them.
I guess it is also possible to use Qt's MVC classes for it. They are highly customizable, but i never made custom views and delegates.
Maybe i just need to create QtListView with stringlist model and apply stylesheet to it so it gets look more like buttons. And based on selection in list load next widget.
Which way is better and why?
Is there any easier ways to accomplish this?
Any ideas would be appreciated.

Is it possible to create multi column combobox by subclassing only its listbox?

In MFC, is it possible to create multi column combobox by subclassing only its listbox.
In Codeproject and Codeguru websites I got samples only with derived CComboBox with ownerdraw style.
The "list" part of a combo-box control is NOT a list-box control. Apart from this, combo-box controls do not really have "columns", and this means that you cannot store column-level data (there is just one string or "item" per row), and subsequently any solution visually imitating "columns" can only be owner-drawn-based. So, if your app's specs have changed (now requiring column formatting) you should rather consider using another control type. Still, an owner-draw implementation isn't really that hard, esp if you have fixed height items; it shouldn't really require extensive changes to your app, as it concerns this specific control only.

PopUp Menus in a custom GUI API?

I have made my own GUI API for games. One assumption that must be made is the user may want to use a derived version of a Widget I have made.
An example of how I dealt with this with ToolTips is, the user allocates a new ToolTip and sets a global one for the GUI. Ex: getGui().setToolTip(customToolTip);
The GUI then calls toolTip->show() when necessary. The problem with menus in general is that you can have many of them appearing at a given time.
I also would hate to have the user implement an interface:
PopUpFactory::createPopUp()
PopUpFactory::destroyPopup()
How is this usually dealt with? Who or how is the memory also managed for these?
There is always the option of limiting to something like 9 nested menus and have the user set an array of 9 PopUps but that seems messy.
Thanks

Unlimited number of checkboxes

I wonder how to create mechanism which create new checkbox below previous when you click on button. Number of checkboxes are unlimited.
I don't think that table of objects work well, so I think about implementation in list of objects.
Any suggestions?
Here is what I would do:
Create an event for clicking that button (let's call it OnBtnClick)
Use a vector/list to hold all the checkboxes
When OnBtnClick is called you do:
create a checkbox with the desired position and size and make sure it receives an unique id (this will help you differentiate between checkboxes when they are clicked/checked/etc).
add the checkbox to the list (to get its status: checked or not checked)
add the checkbox to the desired window, the parent window (though this may happen automatically when you create it)
if you want to add an event for the added checkbox you should check the manual of your GUI framework (you will probably use the same event handler for all checkboxes and treat them separately based on their id)
Depending on the GUI framework used the bottom details may vary but the idea remains the same. I did this with wxWidgets, QT and MFC but I don't know which framework you use. You should be able to find code samples for each framework.
What would you do with unlimited number of check boxes - confuse the user? So, that he/she wouldn't attempt to use it again? Bad idea, as you can guess now.
You may (should) limit the number of check boxes (or better, limit the number of controls on form/dialog). IMO, more than 10-12 CBs would be cumbersome for the end user. Therefore, better idea is to have all of them on dialog/dialog-resource, and make all of them invisible/disabled. When user does some action, make them visible/enabled - so that end user may do something with it.
Still demand N number of CBs, where N is not determined beforehand? Then you may have checkboxes under Combo box, or use check-boxes under List Control. List Control already hosts this feature, but for CBs under Combo, you may need to write your own class.See this article as an example.

DataExchange for many variables

I'm new to MFC and creating basically a "preferences" tool. This of course means that there is a lot of input from the user. I have several "pages", each filled with a combination of text boxes and combo boxes, and I'm trying to figure out the best way to execute the DoDataExchange methods for each dialog class.
Of course, I could just go one by one, within each class for the different dialogs, but there must be a better/faster way. I really don't want to have to write hundreds upon hundreds of DDX_... lines to set up my variables.
Any ideas? I could class them out and then just use a for-loop to pull the variables from an array or list, but I'm not sure how to do that with CWnd and stuff.
Just use the wizard, it will automatically map the variable name to the dialog: right click on the dialog and Add variable, no need to write them manually.