This Question is Answered

13 "helpful" answers available (3 pts)
9 Replies Last post: Aug 26, 2008 7:16 PM by taor

how to let DateField control response the pointerpress and valuechange event?

Aug 20, 2008 7:17 PM

Click to view taor's profile Level 2 taor 29 posts since
Jul 9, 2008

hello,heros!

how to let DateField control response the pointerpress and valuechange event?

waitting for answers~

Click to view taor's profile Level 2 taor 29 posts since
Jul 9, 2008
1. Re: how to let DateField control response the pointerpress and valuechanged event? Aug 20, 2008 7:26 PM
I have known how to response the ValueChanged event.
Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
2. Re: how to let DateField control response the pointerpress and valuechange event? Aug 20, 2008 7:40 PM
DateField defines ValueChanged somewhat differently than a regular TextField, as you have noticed. A DateField will fire a ValueChanged when the value of the string is a valid date, so the intermediate displayed strings don't count.

If you want to see all of the base text character changes, you'll need to add an event handler to the internal text field. Both StandardDateFieldUI and SkinnableDateFieldUI use a SpinControl internally, which in turn uses a TextField internally. So you would need to add a ValueChanged handler to the TextField of the SpinControl of the DateField. You could do this by subclassing whichever of the UIs you were using. In a somewhat less correct way that is however easier to experiment with, if you were careful to notice all UI changes, you could search down through the DateField's graphical hierarchy for the TextField and simply add-event-handler to it.

PointerPress is not coming up on the DateField for similar reasons: it's being consumed by one of the subcontrols that make up the DateField. If you wanted to see all PointerPresses coming into the DateField, you could add a handler for PointerEnvelopeEvent, which is the wrapper for PointerPress and other pointer events as they work their way down to their destination. If you checked the contents field, you can look for a PointerPress and react in those cases. Just be careful about consuming it as that would affect the operation of the DateField. Also, this will actually give you the information about the PointerPress simply before it would actually be unwrapped, in case that timing matters for whatever operation you are planning.

Alternatively, if you are subclassing one of the UIs, or using the search technique above, you can simply add a PointerPress handler to whichever subcontrol you need to, but that is again potentially disruptive if you will be consuming the event.

In any case, you can look at the OPEN-CONTROLS code to see exactly what is happening with the internal event handling in these cases.
Click to view taor's profile Level 2 taor 29 posts since
Jul 9, 2008
3. Re: how to let DateField control response the pointerpress and valuechange event? Aug 21, 2008 11:11 PM
in response to: carl

Can you tell me how to get the internal TextField of DateField which i will add-event-handler to .
Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
4. Re: how to let DateField control response the pointerpress and valuechange event? Aug 22, 2008 6:41 AM
in response to: taor
The best way to do it is by sub classing the DateFieldUI. Here is another way of doing this.


{curl 6.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
 
{define-proc package {find-child
                         box:Box,
                         filter:{proc-type {Visual}:bool}
                 }:#Visual
    {for child in box.ordered-children do
        {if {filter child} then 
            {return child}
        }
        {type-switch child
         case box:Box do
            {find-child box, filter}
        }
    }
 
    {return null}
}
 
 
{DateField
    {on e:KeyPress do
        {popup-message e}
    },
    {on e:AttachEvent at df:DateField do
        let v:#Visual =
            {find-child
                df,
                {proc {v:Visual}:bool
                    {return v isa TextFieldUI}
                }
            }
        {if-non-null v then
            {v.add-event-handler
                    {on e:RawKeyRelease do
                        {popup-message e}
                    }
            }
        }
    }
}
 
Click to view taor's profile Level 2 taor 29 posts since
Jul 9, 2008
5. Re: how to let DateField control response the pointerpress and valuechange event? Aug 25, 2008 6:01 PM
in response to: Kamal

Thank you !

I just do it like you tell me,but the event still can't be catched.I think your answer is right. Maybe there are some other reasions in my program.

Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
6. Re: how to let DateField control response the pointerpress and valuechange event? Aug 26, 2008 5:55 AM
in response to: taor
If you could add your code here I will quickly take a look.

Did you subclass the DateFieldUI or did you use the code that I suggested as a workaround? By the way if you are using the workaround put a dump where you add the RawKeyPress handler to see if it at all gets added.
Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
7. Re: how to let DateField control response the pointerpress and valuechange event? Aug 26, 2008 6:29 AM
in response to: taor
I just tried my workaround and it did not work for me too. Sorry for the confusion. I guess I should have tested it before positing it.

I have tested this version of my workaround with the StandardDateFieldUIs.

There where a few problems in my earlier code.

1. The find-child proc was missing a "return".
2. The DateField and other controls too make their UIs lazily, if they do not have one. They do it when they are attached to a graphical hierarchy. So we should wait till after the AttachEvent to see navigate the graphical hierarchy. To fix this I wrapped the AttachEvent handler code in "after 0s".
3. Note that I had a KeyPress handler that had a popup-message. The KeyPress comes before the RawKeyRelease. But because of the pupup the DateFiel'd TextFieldUI will loose the focus and hence will not get a RawKeyRelease.


{curl 6.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
 
{define-proc package {find-child
                         box:Box,
                         filter:{proc-type {Visual}:bool}
                 }:#Visual
    {for child in box.ordered-children do
        {if {filter child} then 
            {return child}
        }
        {type-switch child
         case box:Box do
            {return {find-child box, filter}}
        }
    }
 
    {return null}
}
 
 
{DateField
    {on e:AttachEvent at df:DateField do
        {after 0s do
            let v:#Visual =
                {find-child
                    df,
                    {proc {v:Visual}:bool
                        {return v isa TextFieldUI}
                    }
                }
            
            {if-non-null v then
                {v.add-event-handler
                    {on e:RawKeyRelease do
                        {popup-message e}
                    }
                }
            }
        }
    }
}
 
Click to view Duke's profile Curl Duke 154 posts since
Oct 17, 2007
8. Re: how to let DateField control response the pointerpress and valuechange event? Aug 26, 2008 2:13 PM
in response to: Kamal
Not relevant to the main topic, but I thought I would point out a new feature in the 6.0 API. There is a macro named fn which can be used for anonymous procedures. So you could use the alternative syntax {fn v => v isa TextFieldUI} and in the case of your example it would be able to infer the types.
Click to view taor's profile Level 2 taor 29 posts since
Jul 9, 2008
9. Re: how to let DateField control response the pointerpress and valuechange event? Aug 26, 2008 7:16 PM
in response to: Kamal

Thank you ! I try it and it just OK!