How to prevent auto-selection of radio buttons - radio-button

When adding an instance of the Gtk# RadioButton class to a GUI, it is automatically checked ("activated") as the first member of its radio button group.
For Gtk, this has been discussed to some extent in another question, with the main point of the selected answer being that users expect one radio button to be selected at all times.
I do not dispute that.
However, I am automatically generating my user interface in a way so each radio button is linked to a data model, but none of the radio buttons can, at any time, get a reference to any of the other RadioButton instances. The data model ensures that one radio button is checked at all times.
Beside being sufficient to match user expectations, I consider this good practice, as like this, data integrity is ensured by the data model, not by the GUI.
Unfortunately, Gtk# will automatically check all radio buttons like this, as it considers each radio button to be the first in its group. For adding the various radio buttons to the same group, I would have to pass the first radio button in the group to the constructor of the other radio buttons - which I cannot, as pointed out above, as I do not have any way to get the reference to that first radio button when instantiating the others.
Setting the Active property of the radio button to false does not help, nor does invoking the Toggle method.
Is there any way to suppress this automatical selection, possibly by subclassing and overriding something I could not find yet? Alternatively, is it somehow possible to force a CheckButton to look like a radio button for this purpose?
If there is really no other solution, I will try and implement the solution suggested in another answer that involves adding a second hidden radio button for each of my radio buttons, but I would find that extremely hacky for production code.

Extension to Josip's solution: Create your own radio button widget, actually containing nothing else than two gtk radio buttons, one of which always is hidden. Your factory then creates this one instead of the original gtk button...

Radio buttons are similar to check buttons except they are grouped so that only one may be selected/depressed at a time.
They require a group to perform their duty properly.
Try the solution from the down, it's not so hacky, just try to add one hidden radio button that is always selected.

Related

Is it possible to use NSButton as a radio while setting images through the storyboard?

I have a collection of radio buttons created through the storyboard:
Since these are all connected to the same outlet, they behave correctly as radio buttons, i.e. only one can be set to On state at once.
However, as soon as I add images (Image and Alternate properties) via the Attributes Inspector, Xcode switches these from Radio / Radio to Bevel / Switch. At this point, they no longer act as radio buttons but rather act as simple checkboxes, i.e. each has an independent On/Off state that doesn't affect the other states in the collection. No other change is made than adding images.
I've tried manually changing the Style and Type of each button, hoping to find some magical combination that allows both radio behavior and images to co-exist. But that doesn't appear to be an option.
Am I missing something? Is this possible? My goal is to do this purely through the storyboard to prevent extensive code refactoring.

OSX: Move keyboard focus between textfields and buttons using tab key

I am trying to toggle between textfields and buttons on my view using keyboard's tab button. The switching between textfields work but it does not switch between buttons. The view is shown as below.I did not find enough resources online to proceed further. Does anyone know how to resolve this?
There is nothing you can do with that issue.
It turns out that in the System Preferences > Keyboard > Shortcuts there is a checkbox, where you can change behaviour of the whole system:
To move keyboard focus only between text boxes and lists
To move keyboard between any of controls
And by default first checkbox is pressed.
As an addition. By default, NSWindow assigns an initial first responder and constructs a key view loop with the objects it finds. You can also change key view loop by calling this method: setNextKeyView.
For example,
[firstTextBox setNextKeyView:secondTextBox];
[secondTextBox setNextKeyView:secondButton];
[secondButton setNextKeyView:firstButton];
[firstButton setNextKeyView:firstTextBox];
This means that for users who expect moving control focus through all controls, this will work. And for those who have disabled this feature in settings, this won't work.
You can right-click on text field, drag "nextKeyView" and drop on another text field that you want to focus next when user press tab. Look like my picture below:
To add to #mjonka's answer, To move focus between controls is dependent on user's keyboard-shortcuts settings. What could be alternate solution is to just selecting your desired action button in your xib file and setting "Key Equivalent" value field to "enter" key in Attributes inspector as shown below. Same thing can be done for cancel button by setting "Key Equivalent" value to "Esc" key.

Button in UserControl in main page not reacting to pointer in Windows Store apps

To share a common display layout in a Split template Windows Store app, I put a Back button, title TextBlock, and another button in a UserControl, and then use that control in most of my pages. My problem is that in the main page, neither of the buttons will react to pointer activity, be it pointer over or clicking. However, it works fine in any other page. To isolate it, I created a blank app and duplicated the UserControl, but it works in that case.
How can I debug this?
Thanks.
-John
In an "ItemView" page of a "Split" template app, the Grid containing the back button and title must be below the GridView and ListView in the XAML code. Apparently the GridView, with no Grid.Row, and a Grid.RowSpan="2" needs to overlay the first and second rows, and if the button is beneath the GridView, it must assume it is not visible and doesn't need to respond to events. I moved my new user control instance to below the GridView, and the buttons work now.
This whole scheme of overlaying both rows makes no sense to me, but without the Grid.RowSpan="2", the items don't split nicely into two rows for me. I think such odd layout should have a comment explaining it in the template. Perhaps it could save someone else from this same kind of issue.

How to create toggle buttons in Windows 8?

I need to create a group of 5 buttons. Only one can be pressed, like Radio Button, but I do not want to show the circle. I would like to use the button look.
Somebody do know which is the best way to do it?
I have found for WPF:
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" />
but it does not work for Windows 8.
Thank you
Is this a group of actual buttons with an action assigned to the click event of each, or are you just trying to remove the circle form a RadioButton type control?
Please note that the user will likely expect a RadioButton control to look and feel like a RadioButton. Changing this just for the sake of it may not be a good idea, but if you want to go ahead with it you could try one of the following options.
1) Edit the template for a radiobutton control to hide the selcetion circle. (I don't know if that's even possible in all honesty, but in theory, it should be)
or
2) Emulate the behaviour with a ListView with SelctionMode set to "Single"
Things get a little more complicated if you want to handle click events on each "button", but it is not impossible. In your ItemTemplate, add a button (presumable with a style of "TextButtonStyle") and set the event handler of the Click event to check which button was pressed and act accordingly.
There is a control called ToggleButton, why don't you use that?

How can I keep an NSPopUpButton open after the user selects a menu item?

I have an NSPopUpButton providing the NSMenu for a status item with a custom view. The popup button displays a list of links. When the user selects a link from the list, the link is displayed in the user's browser (in the background).
Naturally, the menu closes every time the user selects a link.
I would like to change this: I want the menu to stay open while the user clicks on various links, all of which can be opened in the background. The menu can then go away when the user clicks elsewhere.
How can this be accomplished? Should I subclass NSMenuItem and intercept the mouse clicks somehow? Overlay a transparent NSView on the popped-up menu and, again, intercept the clicks somehow? I make these suggestions blithely, but I would have trouble implementing either of these...pointers to the right methods for override would be appreciated.
Instead of using a menu, one might use a collapsible box.I have seen that in many apps ( also provided by Apple) , so I guess this is the recommended style guide for multiple selections.
The collapsible box expands when you click the disclosure button, and it gives free all items desired - like a tableview with checkboxes.
Views below this box must move down in this case, not to interfere with the box.
Clicking again on the disclosure button will shrink the box back to its origin. The effect is similar to closing a menu.
Usually you should not bend a control too far past it's original intent. Users expect pop up buttons to close after making a selection. I don't think you should, or can, force NSPopUpButtonCell to behave in this way. If you do, you'll be subclassing and modifying the control so heavily that it might change/break with a future version of Mac OS X. You'd also have to worry about the usability problem of users thinking the menu will close after making a selection.
You might consider writing you're own subclass of NSView to work like the menu button you're describing. After the user clicks on the button. You'll want to create a new NSWindow, with no border by using NSBorderlessWindowMask as the style mask. The content view of that window should be another custom view of yours that you implement the menu selection in.