This Question is Answered

1 "correct" answer available (5 pts) 15 "helpful" answers available (3 pts)
4 Replies Last post: Jun 17, 2008 1:40 AM by varshuj

Regarding Calendarcontrol

Jun 16, 2008 3:09 AM

Click to view varshuj's profile Level 3 varshuj 44 posts since
Mar 6, 2008

How can i display Calendar Control with a single day view along with Time

and all other days are not visible.

And should navigate to next/previous day.


Thanks ,

Varsha

Click to view mgordon's profile Curl mgordon 47 posts since
Oct 17, 2007
1. Re: Regarding Calendarcontrol Jun 16, 2008 6:14 AM
CalendarControl is designed to let you select a date. You'll have to build a little UI to do what you describe.
Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
2. Re: Regarding Calendarcontrol Jun 16, 2008 7:01 AM
Here is some code that you can extend on to achieve your goal. It is just a quick hack to show how you can subclass the StandardCalendarControlUI (for Skinnable UI you will need to take a slightly different approach). In any case, I will suggest reading the code for the CalendarControl and its UIs that you will have downloaded in our m/c already if you have downloaded Curl IDE.

In the code below, you can use the "Arrow" to navigate.If you will click on the "lime" day frame, the date will be selected (although it does not currently show it with some kind of selection scheme).


{curl 6.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
 
{import * from CURL.GUI.SHAPES}
 
{define-class public open CustomCalendarControlUI  {inherits StandardCalendarControlUI}
  field private month-year-frame:Frame
  field private day-frame:#Frame
  field private display-day:int = 1
  {constructor public {default
                          control:#CalendarControl = null,
                          ...
                      }
     set self.month-year-frame = 
         {Frame halign = "center", width = {make-elastic}}
    {construct-super control = control, ...}
  }
 
  {method private {make-arrow point-left?:bool = true}:Graphic
    let arrow:ArrowShape =
        {ArrowShape
            {Distance2d 0cm, 0cm}, {Distance2d 1cm, 0cm},
            arrow-body-width = 1px,
            arrow-head-width = 11px,
            arrow-tail-width = 11px,
            arrow-head-style = 
                {if point-left? then 
                    ArrowStyle.none 
                 else 
                    ArrowStyle.solid
                },
            arrow-tail-style = 
                {if point-left? then
                    ArrowStyle.solid
                 else
                    ArrowStyle.none
                }
        }
    
    {return
        {Frame
            opaque-to-events? = true,
            arrow,
            {on e:PointerPress do
                {e.consume}
                def cc = self.calendar-control
                def day = self.display-day
 
                let new-date:DateTime = 
                    {if point-left? then
                         {DateTime.date  year = cc.display-year, month = cc.display-month, day = day - 1}
                     else
                         {DateTime.date  year = cc.display-year, month = cc.display-month, day = day + 1}
                    }
 
                {if new-date < cc.min-value then
                    set new-date = cc.min-value
                 elseif new-date > cc.max-value then
                    set new-date = cc.max-value
                }
                set self.display-day = new-date.info.day
                {self.day-frame.add self.display-day, replace? = true}
                {if cc.navigation-changes-value? then
                    {cc.set-value-with-events new-date}
                 else
                    {cc.set-display-month-year
                        month = new-date.info.month,
                        year = new-date.info.year
                    }
                }
            }
        }
    }
  }
 
  {method protected open {create-day-chooser}:Graphic
    def cc = self.calendar-control
    {if-non-null date = cc.value then
        set self.display-day = date.info.day 
    }
    def day-frame =
        {Frame
            background = "lime",
            valign = "center", halign = "center",
            height = 2in, width = 2in,
            self.display-day,
            {on e:PointerPress at frm:Frame do
                {cc.set-value-with-events 
                    {DateTime.date
                        year = cc.display-year, month = cc.display-month, day = self.display-day
                    }
                }
            }
        }
    set self.day-frame = day-frame
    {return day-frame}
  }
 
  {method protected open {create-main-panel}:Graphic
    let constant g:Grid = 
        {Grid control-appearance-changeable? = true}
    let constant cc:CalendarControl = self.calendar-control
 
    let constant day-chooser:Graphic = {self.create-day-chooser}
    {if not cc.show-date-controls? then
        {g.add
            day-chooser,
            left = {g.left},
            top = {g.top},
            right = {g.right},
            bottom = {g.bottom},
            vorigin = {g.vorigin-fiducial}
        }
        {return g}
    }
 
    let constant h-fid:GridFiducial =
        {GridFiducial g, horizontal? = true}
 
    {g.add
        {spaced-hbox
            valign = "center",
            {self.make-arrow},
            self.month-year-frame,
            {self.make-arrow point-left? = false}
        },
        left={g.left},
        top = {g.top},
        right={g.right},
        bottom = h-fid,
        vorigin = {g.vorigin-fiducial}
    }
 
    {g.add
        day-chooser,
        left = {g.left},
        top = h-fid,
        right = {g.right},
        bottom = {g.bottom}
    }
    {return g}
  }
 
  {method public {react-to-state-change}:void
    {super.react-to-state-change}
    let cc:CalendarControl = self.calendar-control
    let month:String = cc.month-names[http://cc.display-month - 1|http://cc.display-month - 1]
    {self.month-year-frame.add
        {bold {value month}, {value cc.display-year}},
        replace? = true
    }
  }
  
}
 
{CalendarControl}
 
{def frm = {Frame}}
 
 
{CalendarControl
    ui-object = {CustomCalendarControlUI},
    {on e:ValueFinished at cc:CalendarControl do
        {frm.add cc.value, replace? = true} 
    }
}
 
{value frm}
 


Message was edited by: Kamal

Message was edited by: Kamal
Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
3. Re: Regarding Calendarcontrol Jun 16, 2008 7:03 AM
in response to: Kamal
Note that in the example code above "replace"

let month:String = cc.month-nameshttp://cc.display-month - 1

by

let month:String = cc.month-nameshttp://cc.display-month - 1

For some reason the "code" tag that I am using to display the code above is making the above change, although the preview shows it correctly.

--Kamal

Click to view varshuj's profile Level 3 varshuj 44 posts since
Mar 6, 2008
4. Re: Regarding Calendarcontrol Jun 17, 2008 1:40 AM
in response to: Kamal
Thank you Kamal for your help.