Kamal 149 posts since
Oct 17, 2007
5.
Re: Regarding CalendarControl Jul 8, 2008 7:52 AM

in response to:
varshuj
There are two approaches to fix this. The better solution will be to subclass the UI. Unfortunately the UI that is used for displaying the Day is not public. However all the source code is open so you can use the open source to change the UI as you want.
However you can use one of these two approaches. Both of these use the fact that you can provide your own Graphic to display as a Day number.
Note that in the first approach, one right clicking on top of the number is going to work.
{CalendarControl
day-proc =
{proc {cc:CalendarControl, date:DateTime}:(#Graphic, bool)
let constant info:DateTimeInfo = date.info
{return
{Frame
opaque-to-events? = true,
{value info.day},
{context-popup
menu-pane =
{MenuPane
{MenuAction label ="select current Date",
{on Action at mc:MenuAction do
{popup-message "The date is " & date }
}
}
}
}
},
true
}
},
{on e:ContextMenuEvent do
{e.consume}
}
}
In the second approach, I am adding these event handlers to the parent of my day graphic. This may not work for all the UIs. It is assuming that all the day Graphics are inside another graphic that contains a single day. By doing this now you can click anywhere in the parent cell of the day.
{CalendarControl
day-proc =
{proc {cc:CalendarControl, date:DateTime}:(#Graphic, bool)
let constant info:DateTimeInfo = date.info
{return
{Frame
opaque-to-events? = true,
{value info.day},
{on e:AttachEvent at frm:Frame do
def parent = frm.parent
def context-handler =
{on e:ContextMenuEvent at df:Graphic do
{if e.consumed? then {return}}
{e.consume}
{{MenuPane
{MenuAction label ="select current Date",
{on Action at mc:MenuAction do
{popup-message "The date is " & date }
}
}
}.popup df, e.x, e.y}
}
{parent.add-event-handler context-handler}
{frm.add-event-handler
{on e:DetachEvent at outer-frame:Frame do
{parent.remove-event-handler context-handler}
}
}
}
},
true
}
},
{on e:ContextMenuEvent do
{e.consume}
}
}