Gtk events differences - gtk

Can someone tell me the difference of the events in GTK:
on_treeview_button_press_event()
on_treeview_key_press_event()
on_treeview_cursor_changed()

"The differences?" They are different events, i.e. they are generated for different reasons.
Also, those names are confusing, as only the last one is local to the GtkTreeView widget, the first two are generic GtkWidget-level signals.
The documentation states:
GtkWidget's button-press-event:
The ::button-press-event signal will be emitted when a button (typically from a mouse) is pressed.
GtkWidget's key-press-event:
The ::key-press-event signal is emitted when a key is pressed.
GtkTreeView's cursor-changed:
The position of the cursor (focused cell) has changed.

Related

Slickgrid; handle mouseover/hover events on elements in cell myself

In a very special slickgrid scenario (see https://serenity.is/demo/BasicSamples/DragDropInTreeGrid) I need to handle hover / Mouseover events on the Tree elements (links) myself.
However, Slickgrid is hijacking/disabling my registered hover/mouseover events.
What I already have tried:
(1)
Using slickgrid's mouseEnter event routine which in normal slickgrids give you back the cell on which the mouseover event has occured.
--> this works basically but for an unknown reason this is very unreliable in my special scenario above (the event always fires but sometimes it comes directly from the <a href..> (which is what I want) - but most of the time it comes from a <div>... which is useless in my scenario).
(As I could successfully register a contextmenu event on the tree elements and this always works reliably on the elements), I also would like the same principle for the hover/mouseover events).
(2)
Prevent the mouseenter events from the tree elements to propagate - like this:
this.slickGrid.onMouseEnter.subscribe((e, dd) => {
e.stopImmediatePropagation();
});
--> This had no effect.
Question:
How can I stop slickgrid from hijacking/unregister my registered mouseover/hover events on the tree elements so that I can handle them myself?

matlab KeyPressFcn for holding a key

I would like to allow the user to zoom only while the control key is held (depressed). I have implemented this as follows within a WindowKeyPressFcn callback function:
function keypress_callback(obj, evd, hZoom)
switch evd.Key
case 'control'
set(hZoom,'Enable','on');
end
%disp(evd); % used for debugging purposes
This function accepts a zoom object handle (hZoom) that is passed from the main program at the moment the callback function is activated (set(hFigure,'WindowKeyPressFcn',{#keypress_callback,hZoom});). I have written a similar WindowKeyReleaseFcn (set via set(hFigure,'WindowKeyReleaseFcn',{#keyrelease_callback,hZoom});) to disable zooming when control is released.
function keyrelease_callback(obj, evd, hZoom)
switch evd.Key
case 'control'
set(hZoom,'Enable','off');
end
%disp(evd); % used for debugging purposes
The goal is to allow normal zooming behavior (click to zoom in by a factor; shift-click to zoom out by a factor; drag clicking to zoom in on a selected region) only while the Ctrl key is depressed. As soon as this modifier key is released, zooming ability should be disabled.
However, this behavior does not work as intended. Simply testing (by disp(evd)) whether a key is pressed reveals that any number of key presses can be made with arbitrary keys; however, if the pressed key is Ctrl, only one such press can be made, and all subsequent presses of Ctrl are ignored, while all subsequent presses of any other key cause the key to appear in the Matab command window instead of triggering the keypress_callback function. Thus, pressing Ctrl appears to somehow inactivate the keypress_callback function, perhaps because focus is shifted from the figure to the zoom object? As a corollary question, the WindowKeyReleaseFcn seems to work fine for non-modifier keys (the evd shows the correct released key), but the key in evd is empty if the released key is a non-modifier key.
I would be grateful if someone could demonstrate the correct implementation of the control-dependent zoom behavior as envisaged.
The more modern way to do things seems to be:
gca
zoom on
z = zoom(gcf);
set(z, 'ButtonDownFilter', #ZoomGate)
where ZoomGate.m contains something like:
function inhibitZoom = ZoomGate(varargin)
if ismember('control', get(gcbo,'currentModifier'))
inhibitZoom = 0;
else
inhibitZoom = 1;
end
EDIT in response to questioner's comments:
My first suggestion was to use a WindowButtonDownFcn callback which then calls zoom itself if it detects the control modifier. This is fine provided you have control over the zoom implementation. Looking back at my code (I did something like this anything up to 15 years ago) I find that it used to be simple — zoom was an m-file and had an obvious way of calling it: zoom down meant "the button has just been pressed". Then, in that way that they do, MathWorks moved the goal posts and changed zoom. It looks like my response at the time was to re-implement my own zoom in the older, simpler style. Doesn't help you, unless you actually want that code (let me know).

VB Datarepeater control in Visual Studio 2010 - currentItemIndex updated before textbox leave event when using mouse

I'm using a datarepeater control, version 10.0 in visual studio 2010. The CurrentItemIndex seems to update before the textbox leave event when I use the mouse to move to the next row. So, when I retrieve the value from the textbox, I don't now what ItemIndex it is associated with. This doesn't happen when the keyboard is used to move to the next row. Anyone see this happen. Version 9.0 on the datarepeater did work this way.
To answer you directly, here are some C# snippets. I'm assuming that you already have the TextBox object (or other control) as implied in your question. I will also assume that you're inside an event handler (e.g. TextChanged). If you haven't already done it, you need to use the object sender parameter and not the design-time declared TextBox control (i.e. do not use TextBox1, or similar object) because it will just refer to the DataRepeaterItem template control and not the individual control for the data row you're interested in.
TextBox itemTextBox = sender as TextBox;
//* DataRepeaterItem is a control which contains other controls for each data "row"
DataRepeaterItem drItem = itemTextBox.Parent as DataRepeaterItem;
//* Retrieve the particular data item
int idx = drItem.ItemIndex;
//* If DataRepeater is bound to a BindingSource, for example,
//* one can retrieve the underlying data item
object dataItem = myBindingSource.List[idx];
I've experienced various bugs and challenges with control focus and data updates with the DataRepeater. There is no guarantee of exactly which order the events fire: Leave, LostFocus, CurrentItemChanged, etc. And as you've observed, it differs depending on whether you use the mouse within the DataRepeater or to/from another control on the form or using the keyboard. There may indeed be an established algorithm, but I have observed differences from documentation. The situation is complicated when the data-handling framework (e.g. BindingSource, CurrencyManager) also subscribes to these events and updates things out of order from what you might expect or want. I don't have a suggestion on how to handle these issues, but I hope the code above can at least get you access to the particular index and data for the control you're in.

Is 'Ctrl' key pressed while clicking a button?

I need to know whether the user is holding down the ctrl key while clicking a button. Since it's a button and not a figure I cannot use 'selectionType' on the figure etc.
How about this:
modifiers = get(gcf,'currentModifier'); %(Use an actual figure number if known)
ctrlIsPressed = ismember('control',modifiers);
The figure class has a number of useful Current* properties which are useful when handling callbacks. This is how to retrieve current mouse position, selected graphics object, and (as here) pressed keys. These include: CurrentAxes, CurrentCharacter, CurrentKey, CurrentModifier, CurrentObject, and CurrentPosition.
Pressing the escape key reinitializes CurrentModifier. My solution so far has been to instruct my users (right in the GUI) to press the escape key to revert to default behavior.
Overall, Matlab's CurrentModifier behavior seems to be that the modifier key "sticks" until one of the following occurs: a different modifier is pressed, a different window is selected, or the escape key is pressed.

DataGridViewComboBoxCell selectioindexchange event

I have a data-grid and three column in it. one column is type of DataGridViewComboBoxCell, three items are in this grid combo box, now i have to invoke selection index changed event to change value according to combo value change in grid.
also help me to make a new event ....
please help...
thanks
I really can't understand your question.
But maybe these informations can help:
A ComboBoxColumn has always two kinds of controls. A presenting one (in most cases a label) which is individually for each row. And a editing one that will be shared for the whole column. So take a look into this documentation and the IDataGridViewEditingControl Interface.
Maybe these will give you a starting point on how to solve your problem.
In the Load event for the form, you need to get the cell that you want to add the handler to and cast it as a regular combo box. You can then add the event handler on SelectedIndexChanged, but it must be done programmatically, and depending on the language you are using.