Disable SWT Button highlighting and selection - swt

How can I achieve an SWT Button which does not get highlighted on mouse hover nor clicks?
I tried to cancel the SWT.HOT, SWT.SELECTED and SWT.FOCUSED bits on the detail attribute of several SWT events, but achieved nothing.
Eg.:
swtButton.addListener(SWT.PaintEvent, (e) -> {
e.detail &= ~SWT.SELECTED;
e.detail &= ~SWT.HOT;
e.detail &= ~SWT.FOCUSED;
});

Related

Detect CTRL+Click on SWT ToolItem

Is there a way to detect a CTRL-click on a ToolItem? I want to distinguish between CTRL+Click and normal mouse click.
ToolBar toolbar= new ToolBar(parent, SWT.NONE);
ToolItem saveToolItem = new ToolItem(toolbar, SWT.PUSH);
...
saveToolItem.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
// if CTRL+Click {
// specialSave();
// } else
normalSave();
}));
The SelectionEvent passed to the event (in e in your code) has a stateMask field including the modifier keys being pressed. The SWT.CTRL constant for Ctrl.
So:
if ((e.stateMask & SWT.CTRL) == SWT.CTRL)
Tests for the Ctrl key being pressed

GWT CellTable highlighted row

So I have a cell table with click event selection model working fine.
I later found out you can press UP and DOWN arrows to get the highlighted row to change, but the awful thing is you have to press Space for it to actually call the SelectionChangeEvent.
I am trying to cheat my way a little, by catching the UP and DOWN events and firing the SPACE event. Sadly it doesn't work :(
Here is my code any help would be appreciated!
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
table.sinkEvents(Event.KEYUP);
table.sinkEvents(Event.KEYDOWN);
table.sinkEvents(32);
table.addHandler(new KeyUpHandler(){
#Override
public void onKeyUp(KeyUpEvent event)
{
System.out.println(event.getNativeKeyCode());
if(event.getNativeEvent().getKeyCode() == 40)
{
// down is pressed
int i = rows.getFilterList().indexOf(selectionModel.getLastSelectedObject())+1;
if(i >= 0 && i < rows.getFilterList().size())
{
// selectionModel.setSelected(selectionModel.getLastSelectedObject(), false);
// selectionModel.setSelected(rows.getFilterList().get(i), true);
// SelectionChangeEvent.fire(selectionModel);
System.out.println("firing native event space");
DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, 32), table);
}
}
else if(event.getNativeEvent().getKeyCode() == 38)
{
// up is pressed
int i = rows.getFilterList().indexOf(selectionModel.getLastSelectedObject())-1;
if(i >= 0 && i < rows.getFilterList().size())
{
// selectionModel.setSelected(selectionModel.getLastSelectedObject(), false);
// selectionModel.setSelected(rows.getFilterList().get(i), true);
// SelectionChangeEvent.fire(selectionModel);
System.out.println("firing native event space");
DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, 32), table);
}
}
}
}, KeyUpEvent.getType());
32 is assumingly the NativeEvent for space, my console prints something like:
40
firing native event space
32
so assumingly the event type 32 is being called for the object table.
I check if the object is selected, because on the right hand side of the screen I have additional information being pulled out from a list, since the cell table doesn't show all the information. I want it so when I press UP and DOWN the RHS information changes and I dont have to press SPACE to prompt the info change
Ideally you would poke into the selection internals. Specifically the DefaultKeyboardSelectionHandler is the default implementation of keyboard navigation and the DefaultSelectionEventManager is the default implementation of selection actions using spacebar/clicks (they are both CellPreviewEvent.Handlers).
Anyway, you can force the keyboard selection to be bound to the underlying SelectionModel by using setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION). It should be fine for your use case. Much like what is done for the CellList showcase sample (the selection API is the same across cell widgets).

Blackberry 10 ListView - multiselect

I am in need of a bit of help regarding cascades ListView, I found some code a few weeks ago from this great site and have used it to show a tiled ListView in an application.
I have tried to go one step further now and have multiselect in the context menu - this is working ok apart from one issue which is when I select more in the context menu after pressing on a ListItem for a couple of seconds the highlighted ListItem doesn't remain highlighted any longer. So then the user will think they have to press it again to highlight it.
void CustomImageView::select(bool b) {
qDebug() << "select isselected=" << b;
if (b)
{
mHighlightContainer->setOpacity(0.9f);
}
else
{
mHighlightContainer->setOpacity(0.0f);
}
}
void CustomImageView::reset(bool selected, bool activated)
{
Q_UNUSED(activated);
qDebug() << "reset";
select(selected);
}
void CustomImageView::activate(bool activate)
{
qDebug() << "activate ";
select(activate);
}
Here is the output when I press select more in the menu (at which point the listitem is highlighted as required)
activate
select isselected= true
activate
select isselected= false
If I comment out select(activate); from activate function then the multiselect seems to work as required (it will highlight the item i long press) and stay highlighted but then when i just press (not long press) an item in the list it won't highlight any longer so there is no feedback for the user when tapping an item - it seems i can't have both!
Anybody know what I can do to solve this please?

How to catch click on QMenuBar

I want to catch the click on my QMenuBar that is in QMainWindow, so I have subclassed QMenuBar and I have overrided the mousePressEvent function, but now when I click on menu, the submenus doesn't display them.
An idea ?
In the end of your mousePressEvent function you should pass the event to the base class, which will do its own operations on mouse click:
void MyMenu::mousePressEvent(QMouseEvent *event)
{
// do your stuff
QMenu::mousePressEvent(event);
}
Here you can read about the Qt Event System.

detecting right mouse double click with Bing maps

I don't see an event in the Bing map API v7 that will surface a double click event. Is there a way to do this? Assuming there isn't native support that I missed, I think I will have to write my own double click handler with a timer.
I had also a problem with the click-events. In facts, the normal click-event also fires during a double-click event. That is why I had to implement my own double-click handler. My approach can be translated to the rigth click, because I am only using the single-click event, which is also available for the right mouse button.
//Set up my Handler (of course every object can be the target)
Microsoft.Maps.Events.addHandler(map, 'click', Click);
//count variable, that counts the amount of clicks that belong together
myClick=0;
//A click fires this function
function click (e)
{
//If it is the first click of a "series", than start the timeout after which the clicks are handled
if (myClick == 0)
{
//Target have to be buffered
target= e;
//accumulate the clicks for 200ms and react afterwards
setTimeout("reaction(target)", 200);
}
//count the clicks
myClick = myClick+1;
}
//At the end of timeout check how often a click has been performed and react
function reaction(e)
{
if (myClick==1)
{
alert("Single Click!");
}
else (myClick==2)
{
alert("Double click!");
}
else (myClick==3)
{
alert("Tripple click");
}
//reset ClickCount to zero for the next clicks
myClick = 0;
}
Moreover it might be interesting to remove the standart double-click behaviour of Bing-Maps, to zoom in. This can be realized by the following code:
Microsoft.Maps.Events.addHandler(map, 'dblclick', function(e){
e.handled = true;
});
If you only use double click event
Microsoft.Maps.Events.addHandler(this.map, 'dblclick', functionHandler)
should solve the problem