Sunday, November 8, 2009

Add behavior to Tree Item

I am a big fan of tree_item and Tree_item is one of the most powerful controls provided by magik language. I can't imagine many Office applications with out a tree_item (very few without a tree_item)


From few days I am trying to develop a Yahoo messenger kind of application in magik using tcp/ip communication.

One of my requirements is to show details on mouse over on the list available. But I think the tree_item doesn’t have mouse over functionality added (at least in my scope of knowledge). I spend couple of minutes to provide a customized behavior like mouse over action to tree_item

Here is the way to add the mouse over behavior to tree_item:
(These changes are to tree_agent.magik didnt tried subclassing it)
1. add a pseudo slot say mouse_over_func and define the slot access to writeable
2. add the mouse_over_func to exported_notifiers and notifier_for_action
3. initilise the handler in init() of agent as below
.mouse_over_func << handler.new(_self, :default_mouse_over|()|)
4. enable the events for the tree in window.enable_event(:move)
5. in default_handle_event(), notify to the desired method as below
_if l_id _is :move
_then

_return _self.notify(:mouse_over_func, l_row, l_row_index, p_event)

_endif
6.
_pragma(classify_level=advanced)
_private _method tree_agent.mouse_over_func << p_new
##
##


.mouse_over_func << handler.new(_self, :default_mouse_over|()|)
>> .mouse_over_func
_endmethod
$

7.
method tree_agent.default_mouse_over(p_tree, l_row_index, p_event)
##
##
#write(p_tree, l_row_index, p_event)

_local l_sel_column << _self.column_at(p_event.x)
#do some thing
write(l_sel_column)
_if l_sel_column _is _unset
_then
_return

_endif


_endmethod
$

I just tried this code and I haven’t tested fully… but this is working. I added my custom method in the class as we do for select notifier or double click notifier.. it is working with few tracebacks.. Those are to be handled in tree_agent. default_mouse_over()

1 comment:

  1. Hi boss have u completed the Yahoo messenger kind of application in magik . I need more help from you can u say me your gmail id.

    ReplyDelete