ZK-Why Zk drop getFocus() or isFocus()? - focus

I was trying to get if Window is focused or not so i gone through available method of Window class ,did not get any getFocus(); or isFocus(); method. Is there any reason to ZK drop this method ? There is only focus() method with void type.
I have a complex problem ,In my application single page have two parts left hand side contain a.zul and right part b.zul and have tabs. I have to fire CTRL key event something like this if focus on a.zul then fire event on A.Java class and When focus on b.zul then fire event in B.Java class. But as i am not able to get focus its hard to determine which window or zul is focused now? ANy one know any other solution of this problem?

Lots of elements (dom level elements) cannot receive focus, e.g., div, span, ul/li, table, tr, td, ..., etc
Also lots of widgets (ZK widgets) cannot receive (and do not handle) focus, e.g., window, div, label, grid, ..., etc
This is why there is no getFocus/isFocus methods by default since they are not that 'common' for a component, lots of components cannot receive focus, some of components work with 'default' focus (e.g., a, textbox) and some of components work with 'hand made' focus (e.g., listbox contains a dom element 'a' and play around it for focus).
You can try to listen to onFocus event or onClick event at server side to know which component is focused/clicked(selected), or override doFocus_(evt) method of widget and log the focused widget at client side for further processing.
But why do you need to fire onCtrlKey event manually? It will be fired from client to server automatically by default.

Related

how to respond to a key press when focused on a radiogroup in delphi

In delphi:
How can you respond to a key press when the current focus is on a radiogroup which does not have an onkeypress event. I was hoping to use the forms onkeypress event but it doesnt see to fire.
You can make this possible by setting the form's KeyPreview property to True.
However, I'm not sure you are actually doing things right, since this is a fairly uncommon problem.
You didn't write what keyboard shortcut you want to respond to. But please remember that
Letters are used to navigate the GUI. For instance, pressing A might select the &All radio button or click the &Add push button. Similarly, Alt+A does the same if the current control allows character input, allows you to open the &Add-ons menu item, etc.
If you want to add a proper shortcut like Ctrl+O, it is much better to use a TActionList with an action having this shortcut. This action can be mapped to menu items, buttons, etc., or simply exist in the background not being attached to any visual control. In very simple applications, you might want to use a stand-alone menu item with such a shortcut instead.

How can I detect when a TTreeViewItem node was expanded inside a TTreeView?

I have a TTreeView on a form, and it has a lot of TTreeViewItem nodes.
I would like to call some function only when the user expands one of the TTreeViewItem nodes (which does not necessarily mean the user "selected" one of the nodes).
I have tried catching this event with the following handlers:
TTreeView.OnChange
TTreeView.OnClick
TTreeView.OnMouseDown
TTreeViewItem.OnClick
TTreeViewItem.OnMouseDown
But none of these seem to be triggered when I only click the cute little arrow to the left of the expandable node.
Is there a way to be notified when the user expands a TTreeViewItem?
Unfortunately, TTreeView and TTreeViewItem in FireMonkey do not expose any public events when nodes are expanded/collapsed.
The only thing I see are the private TTreeViewItem.DoButtonClick() event handler when the node's expand/collapse button is clicked, and StartTriggerAnimation('IsExpanded') notifications that are sent to that same button when the node's IsExpanded property changes value.
The actual button object is obtained from the TTreeView's Style, so maybe there is a way to subclass that object so you can override StartTriggerAnimation(), or at least add a hidden child to it as the default TFmxObject.StartTriggerAnimation() implementation notifies child controls of the same trigger that is sent to the parent control.

Is there a workaround for something like "Form1.MousePreview:=true"?

I have two 100% overlapping panels with different contents on a form.
The first (static display of information) should be visible by default, but the other (user interaction) should replace it if the user moves the mouse near the two - and if the mouse moves away, it should switch back.
Something like this:
if (*the mouse is near*) then
begin
Panel1.Hide;
Panel2.Show;
end
else
begin
Panel2.Hide;
Panel1.Show;
end;
My problem is: where to capture mouse movement?
Each component has its own OnMouseMove handler - of course I could forward each of them to the forms handler, but I'd rather have something a bit more elegant (and easier to maintain).
The perfect solution would be something like Form1.MousePreview := true;.
Another solution would be assigning a generic handler that translates coordinates and calls the forms handler; The assigning could be done in FormCreate.
But that's not as easy as it seems, because one TImage already has its own mouse event handlers.
I have tried OnMouseEnter and OnMouseLeave of the two panels but it didn't work; #1 disappeared, but #2 did not appear. I guess that's because if the mouse leaves Panel2, it should disappear - but it also leaves it if it enters a button on it.
That's why I'd like to use a coordinate based approach to make the check more reliable.
Maybe the two panel method is completely wrong?
Update: Yes, it is, as Remy said.
I am now using a TJVPageList because a TPageControl has visual tabs.
The OnMouseEnter handler of the PageList sets one page, the OnMouseLeave sets the other; But once the mouse moves over the PageList, both pages start flickering.
I have tried adding the event handlers to each page, too, but that made no difference.
Should I check all OnMouseEnter / Leave events to filter out the PageList, the two pages and all components sitting on the pages?
Another update: I am using a TPageControl now, but the behaviour is similar.
It doesn't flicker, but if I move the mouse ontop the TPageControl, no TTabSheet is displayed at all.
Only if I press down the left mousebutton, the UI sheet is displayed. The other sheet is displayed normally if I move away the mouse. (The TJVPageList displays the UI page if I press the left mousebutton, too.)
I have used the mouse event handlers (enter/leave) of the TPageControl and both TTabSheets.
Update 3:
Done it.
The static Panel / TabSheet / JvStandardPage (#1) must not trigger the OnMouseLeave handler.
What you describe might be better served using a single TPageControl instead of two TPanel controls. Use the TPageControl's own OnMouseEnter/Leave events (or intercept the CM_MOUSEENTER/LEAVE messages) to switch the TPageControl.ActivePage as needed.

Handle changes to a big form. Alert before closing modal

I am currently working on a Customer Management application made in SmartGWT 2.0.
The Add Customer form is a fairly big one with multiple tabs and each tab has lot of fields. This form is opened in a modal window which have a save and a close button at the bottom.
Since this is a huge form, sometimes the rep accidentally hits Close without noticing that there is some information in one of the tabs.
We want to add some kind of alert when user tries to close the form after he has made changes to it.
I saw that there is ChangeHandler on text items which can flag a change which can be evaluated before firing the close event. However currently doing this for so many fields is a little bit cumbersome. Is there a way of achieving this on a DynamicForm level or even better on the Window level?
I am looking for a SmartGWT equivalent of this jquery code:
$("input:text, select, input:checkbox, input:radio, input:password").change(function(){
unloadRoutineFlag = true;
});
Take a closer look at this handler at the dynamicForm level.
addItemChangedHandler(ItemChangedHandler handler)
Handler fired when there is a changed() event fired on a FormItem
within this form.
Typically, when a formItem fires the changed() event, the form gets notified. Let us know if this works.

Prevent an element within header from expanding

I'm using jQueryUI Accordion, and genereate the elements on the fly. I need to prevent accordion expanding if we click Remove action link inside the header.
To stop further handlers from executing after one bound using .live(), the handler must return false. Calling .stopPropagation() will not accomplish this.
No luck with return false. Please see the demo.
I don't think you will have too much luck achieving what you want with live(), as jQuery only supports event bubbling and not event capturing. The design decision was probably due to the fact the IE does not support event capturing, even though W3C's speicification has the flexibility for both.
Your best bet is to attach a click event to the remove button right after it is inserted into the DOM (to stop the event propagation) before you re-initiate the accordion. You may need to take care not to bind click event to the existing remove buttons multiple times.
The pseudocode would look something like this:
call .accordion('destory') on the current accordion
create the new element, i.e. <h2>...<a class="revmoe">...</a></h2><div>...</div>
insert the new element to the existing accordion
bind a click event to the remove button in the new element to stop event propagation
initiate the accordion, i.e. .accordion({..})
SO posts on event capturing in jQuery:
event capturing with jQuery
Event Capturing vs Event Bubbling
Just use the given functions by the plugin:
$('#accordion').accordion({active:8, disabled:true});
jQuery('.remove').click(function(){
$('#accordion').accordion('disable');
})
I chose the option "active:8" because this way no header is opened from the beginning (index -1 does not work for IE). Check the function and options out at: http://docs.jquery.com/UI/Accordion
Hope this is what you were looking for :-)

Resources