Re: Month Calendar control: make dates bold?

new topic     » goto parent     » topic index » view thread      » older message » newer message

>
> posted by: Jonas Temple <jtemple at yhti.net>
>
> danielmoyer wrote:
> >
> > Some questions:
> >
> > > function onNotify_MC1(atom ID,atom hWnd,atom uMsg, atom wParam, atom
> > lParam)
> > >   atom code,cDayState
> > >
> > >   code=uMsg --any other lib use: NMHDR[3]
> > >
> > >   if code=MCN_GETDAYSTATE then
> > >     --note lParam=lpNMDAYSTATE struct
> > >     cDayState=peek4u(lParam+28) --min number of months that need
> > processing
> >
> > if lParam+28 is telling min months, where/when was the struc *given*
that
> > info?
>
> The struc was in the lParam or maybe I don't understand your question.
>
> > > MC:AddEvent(onNotify,MC1,routine_id("onNotify_MC1"))
> >
> > What's that MC, and AddEvent??
> > Using Win32Lib, would I use "setNotifyHandler"?
>
> Dan,
>
> Here's a working MCN_GETDAYSTATE notifier using Win32Lib:
>
> }}}
<eucode>
> --------------------------------------------------------------------------
------
> -- Set day state
> function CalendarCC_onDayState(integer id, atom hWnd, atom wParam, atom
lParam)
> atom hwndFrom, idFrom, code, cDayState, daystates,
> year, month, dayofweek, day, hour, minute,
> second, millisecond
> sequence wrk_states
>
> -- Get the structure data
> hwndFrom = peek4u(lParam)
> idFrom = peek4u(lParam+4)
> code = peek4u(lParam+8)
> year = peek2u(lParam+12)
> month = peek2u(lParam+14)
> dayofweek = peek2u(lParam+16)
> day = peek2u(lParam+18)
> hour = peek2u(lParam+20)
> minute = peek2u(lParam+22)
> second = peek2u(lParam+24)
> millisecond = peek2u(lParam+26)
> cDayState = peek4u(lParam+28)
>
> -- Allocate memory for the day states if not yet done
> if not day_statesx then
>                 free(day_statesx)
>                 day_statesx = 0
> day_statesx = allocate(cDayState*4)
> end if
>
> -- Get a sequence to set the dates
> wrk_states = getDayStateSeq(CalendarCC)
>
> -- Now convert the sequences to atoms and poke into memory
> for i = 0 to cDayState-1 do
>       daystates = bits_to_int(wrk_states[i+1])
> poke4(day_statesx+(i*4),daystates)
> end for
>
> -- Set the return value
> poke4(lParam+32,day_statesx)
>
> return kReturnNow
> end function
> void = setNotifyHandler(MCN_GETDAYSTATE,
routine_id("CalendarCC_onDayState"))
> </eucode>
{{{

>
> Note that this routine doesn't set any dates to bold, it just handles the
> notification.  You could, for example, set the 2nd day of the 2nd month
> to bold by inserting after the call to getDayStates():
>
> wrk_states[2][2] = 1
>
> The getDayStateSeq is a new routine in WIN32EXT.EW that I will upload to
> the contributions page shortly.  What it does is returns a sequence made
> up of one sequence for every month displayed on a calendar control.
>
> >
> > > --Cleanup routine:
> > > procedure Cleanup()
> > >   free(pDSs)
> > > end procedure
> >
> > Call this on close app, or some other time too?
>
> In my example I free/allocate the memory each time.  Why?  Well, you
> shouldn't assume that the first allocation of memory is sufficient to
> subsequent number of months.  Although looking at the calendar control,
> it appears that there is always 3 months displayed, even if the first
> of the month starts on a Sunday.  It starts the month on the second line
> under this condition.  So you could even hard code 3 as the number of
> cdayStates to allocate (3*4=12).
>
> So in my example, you would really need to free() the memory at the end
> of your prog, like on an onClose event.
>
> >
> > I'll have other questions, but maybe not for a couple of days.  However,
if
> > either/both of you had the time to make a full (Win32Lib) demo, I'm
guessing
> > Derek would probably include it as a demo with Win32Lib, which would
help
> > anyone else who wanted to use this aspect of MonthCalendar, as well as
me.
> >
>
> If I find the time, I am actually going to use this technique in my
> timesheet program (available in the archives).  I'd like to show the user
> when they're selecting a from/to date the other from/to date that has
> been selected.  That is, if it's in the visible month.
>
> Jonas Temple
> http://www.yhti.net/~jktemple
>


Jonas,

Experimenting with your code, I copied just a skeleton (below)  of your "set
day state" routine into a stub with the calendar control having the style
"MCS_DAYSTATE" ; I did that in part because I couldn't find the function
"getDayStateSeq", & I could get the skeleton to at least run.

I have these questions/observations (sorry if I'm dense):
1.  what kind of variable is  "day_statesx", & should it be declared outside
the routine?
     (is it atom, & yes, declare outside the routine?)
2.  when I run the skeleton, some days *do* already show up in bold, sort of
semi-randomly; as I change months, the same days are in bold for each month,
unless I click on the "goto todays date thingy", but then changing months
after that they go back to the original set of bold and not bold.
   (routine picking up random data from some internally defined structure
location??)
3.  but where is the structure that is being "interrogated" by the routine
(or, if more accurate to say, "pointer to structure passed in lParam"?), and
where/how is it filled??
   (maybe I'm totally confused about that; I know I have to have some
"outside" list of days to set up so the routine can know them, so as to them
make them bold)
4.  and I don't understand "wrk_states"; you say I could for instance set
2nd day of 2nd month as follows:
> wrk_states[2][2] = 1
but that's a two-level sequence, and you seem to be treating it as a one
level sequence earlier,
>bits_to_int(wrk_states[i+1])


here's the "skeleton" of your code that I ran just to have something to
experiment with:
-- Set day state
function CalendarCC_onDayState(integer id, atom hWnd, atom wParam, atom
lParam)
atom hwndFrom, idFrom, code, cDayState, daystates,
year, month, dayofweek, day, hour, minute,
second, millisecond
sequence wrk_states

-- Get the structure data
hwndFrom = peek4u(lParam)
idFrom = peek4u(lParam+4)
code = peek4u(lParam+8)
year = peek2u(lParam+12)
month = peek2u(lParam+14)
dayofweek = peek2u(lParam+16)
day = peek2u(lParam+18)
hour = peek2u(lParam+20)
minute = peek2u(lParam+22)
second = peek2u(lParam+24)
millisecond = peek2u(lParam+26)
cDayState = peek4u(lParam+28)

puts(1,  "got into day state routine!\n")

return kReturnNow
end function
void = setNotifyHandler(MCN_GETDAYSTATE,
routine_id("CalendarCC_onDayState"))

Dan Moyer
(still confused, but still trying)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu