Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Calendar
  New Posts New Posts RSS Feed - How to select date/time under the cursor
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to select date/time under the cursor

 Post Reply Post Reply
Author
Message
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Topic: How to select date/time under the cursor
    Posted: 14 April 2009 at 5:32pm
Hi!

Just wanted to ask what's the proper way to select the time/day block under the mouse pointer on a right mouse button click. Let's say, I've got this:

    CPoint ptHit(wParam);
    XTP_CALENDAR_HITTESTINFO hitInfo;
    BOOL bHitTest = GetCalendarCtrl().GetActiveView()->HitTest(ptHit, &hitInfo);

    if (XTP_NC_CALENDARCONTEXTMENU == Event || XTP_NC_CALENDARRBUTTONDOWN == Event)
    {
        CXTPCalendarViewEvents* selectedEvents = GetCalendarCtrl().GetActiveView()->GetSelectedViewEvents();
        selectedEvents->RemoveAll();

        CXTPCalendarControl::CUpdateContext updateContext(&GetCalendarCtrl(), xtpCalendarUpdateRedraw);
        GetCalendarCtrl().GetActiveView()->SetSelection(hitInfo.dt, hitInfo.dt);
        GetCalendarCtrl().RedrawControl();
    }

But this has 2 problems:

1) if the focus wasn't in the control, then it's not updated/redrawn properly to reflect the new selection
2) if an event is selected and you click anywhere else, the event is still selected till the next click (at least it appear to be drawn selected, maybe it's all one problem)

Thanks in advance,

   Dennis

// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 9:28am

Check by code the way we show tooltip - there is no selection need to show tooltip - you just move your mouse over

Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 4:58pm
Sorry, I'm not sure how that helps - I'm looking at the CalendarDemo sample, right?
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 5:04pm
Right - but you have source code so look for tooltip support
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 5:12pm
Originally posted by mdoubson mdoubson wrote:

Right - but you have source code so look for tooltip support

Hmm, but what I want is to *select* the time slot under the cursor. And it works, except the control is not redrawn till I select something else. Tooltips only show me a hit test?
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 5:39pm
Right - but this hit test fill tooltip with some event-related data - so this is example of data retriving on fly (or more precise - on mouse move)
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 5:45pm
Originally posted by mdoubson mdoubson wrote:

Right - but this hit test fill tooltip with some event-related data - so this is example of data retriving on fly (or more precise - on mouse move)

Yes, but that's not what I need I need to select a block in the calendar control that doesn't have an event. Just an empty slot. And I can do that using the code I show above, however, the control is not updating that block (doesn't repaint it) until I force and invalidate or similar. The block is selected ok though, because I can see that the time/date combination is correct (in my editor).
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 5:54pm
I see - but why don't put set focus call inside your case of your contextmenu / rightbuttonmouse code? And what block means? Time Interval?
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 6:05pm
Originally posted by mdoubson mdoubson wrote:

I see - but why don't put set focus call inside your case of your contextmenu / rightbuttonmouse code? And what block means? Time Interval?

Ok, just to illustrate - change CalendarDemoView.cpp around line 757 to:

    else if (XTP_NC_CALENDARCONTEXTMENU == Event)
    {
        CXTPCalendarControl::CUpdateContext updateContext(&GetCalendarCtrl(), xtpCalendarUpdateRedraw);
        GetCalendarCtrl().GetActiveView()->SetSelection(hitInfo.dt, hitInfo.dt);
        GetCalendarCtrl().RedrawControl();

        if (bHitTest)
        {

and then try right-clicking in the control and adding a new event. See, the time is picked up correctly, but the control is not redrawn properly.
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 7:17pm
OK - I am ready to try it - but need more details: which mode you use in this case - MonthView / Week / ...? Cause in DayView you can count on hit test point to give you time but in month view - only day? The best place to use your approach - Timeline mode. Did you try it?
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 8:13pm
I'm trying the day view for now... thanks!
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 8:44pm
In DayView if i click on selected strip - and after call by menu New Event - my initial date-time settings matched selected strip (in the TimeScale term - if it 10 min - you will have 10 min between start and end as predefined). Same to double-click in same way - select strip and double click.
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 16 April 2009 at 9:45pm
I think that the best for DayView is - click on timescale on desired interval and after this - right click - and select add new event on menu.
 
I think we can also extend double-click support for this timescale area (at least for empty strip - when there is no events on strip to select)
 
You can do it yourself on app level - see:

void CCalendarDemoView::OnEvent_Calendar(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam) {

UNREFERENCED_PARAMETER(lParam);

if (!GetCalendarCtrl().GetActiveView()) return;

CPoint ptHit(wParam);

XTP_CALENDAR_HITTESTINFO hitInfo;

BOOL bHitTest = GetCalendarCtrl().GetActiveView()->HitTest(ptHit, &hitInfo);

................................................................

else if (XTP_NC_CALENDARLBUTTONDBLCLICK == Event) {

if (bHitTest && hitInfo.pViewEvent) { // mouse double clicked - show event edit dialog }

//We come here but need to extend this case to cover TimeScale area (now it covers DayArea and DayHeader only!)
else if (bHitTest && (hitInfo.uHitCode &
// (xtpCalendarHitTestDayArea|xtpCalendarHitTestDayHeader))) { AddNewEvent(&ptHit); } //OLD CODE

(xtpCalendarHitTestDayArea|xtpCalendarHitTestDayHeader|xtpCalendarHitTestDayViewTimeScale))){ AddNewEvent(&ptHit); } //NEW CODE

...........................

I tried it - working precise in the term of timescale interval - I updated my static demo so you can play yourself with this case:
 
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 17 April 2009 at 6:37pm
The sample above doesn't work with the right mouse button (as that's my original problem) - can you please show me how to update the control properly after the code that I provided above is executed (in CalendarDemoView.cpp)?

Thanks :)
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 20 April 2009 at 1:55pm
I run it now directly from archive - switch to DayView and click Right Mouse button in TimeScale
 
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 21 April 2009 at 8:59am
Yes, but I don't need it in *timescale* - I need it in the view itself. When you right-click in the *view* (the largest area in the centre of the control), that's when I need the time slot under the cursor to be selected. So, imagine clicking right in the middle of your screenshot with the right mouse button. It will be around 11 o'clock, so I'd like the time slot between 11 and 11:10 to be highlighted.
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 21 April 2009 at 9:44am
If you have event - you can select it inside cell. But if you don't have event - pick time interval on timescale is very user-friendly and intuitive.
Other way - use Left button click to select strip in view + Right mouse to show menu OR double click - it should work inside cell. And you can change some behaviour on app level - e.g. know right mouse click point - force to pass related time interval to event editor for AddEvent call
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 21 April 2009 at 4:34pm
Originally posted by mdoubson mdoubson wrote:

If you have event - you can select it inside cell. But if you don't have event - pick time interval on timescale is very user-friendly and intuitive.
Other way - use Left button click to select strip in view + Right mouse to show menu OR double click - it should work inside cell. And you can change some behaviour on app level - e.g. know right mouse click point - force to pass related time interval to event editor for AddEvent call

Yes, I'm doing all of that (passing the related time interval to AddEvent, showing the menu on Right click), but I want to select a strip in view under the mouse cursor when right-clicking as well. There's no event there at this point.
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 22 April 2009 at 11:58am
in MFC:

void CCalendarDemoView::OnEvent_Calendar(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam) {

CPoint ptHit(wParam);

XTP_CALENDAR_HITTESTINFO hitInfo;

BOOL bHitTest = GetCalendarCtrl().GetActiveView()->HitTest(ptHit, &hitInfo);

..........................................
else if (GetCalendarCtrl().GetActiveView()->IsKindOf(RUNTIME_CLASS(CXTPCalendarDayView)))

{

AfxMessageBox(hitInfo.dt.Format(_T("%H:%M:%S A, %B %d, %Y")));

..........................................
So you need to pass it to editor
 
Sure you can use same in VB
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 22 April 2009 at 4:51pm
We seem to be talking about 2 different things in this whole thread . Can you please read this carefully to understand my problem:

When a user clicks right mouse button in the day view (not on the timescale, not anywhere else, but right inside the view, where appointments are normally shown), I need to highlight the strip of time that's under the cursor - just like it's highlighted when you left-click in the view. Nothing else.

I've shown you a piece of code from the CalendarDemo in a previous message:

Change CalendarDemoView.cpp around line 757 to:

    else if (XTP_NC_CALENDARCONTEXTMENU == Event)
    {
// this does not update the view properly
        CXTPCalendarControl::CUpdateContext updateContext(&GetCalendarCtrl(), xtpCalendarUpdateRedraw);
        GetCalendarCtrl().GetActiveView()->SetSelection(hitInfo.dt, hitInfo.dt);
        GetCalendarCtrl().RedrawControl();
// I need some code between these comment lines that does

        if (bHitTest)
        {


Hopefully we can solve this problem
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 28 April 2009 at 12:08am
try to simulate left click in your handler
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 19 May 2009 at 4:51pm
I've added the following code, but it doesn't help either:

        DWORD dwPoint = MAKELONG(ptHit.x, ptHit.y);
        GetCalendarCtrl().SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, dwPoint);


// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 19 May 2009 at 6:00pm

mouse_event(MOUSEEVENTF_LEFTDOWN, ptHit.x, ptHit.y, 0, 0);

mouse_event(MOUSEEVENTF_LEFTUP, ptHit.x, ptHit.y, 0, 0);

Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2009 at 6:19pm
Yep, that did the trick, thanks :)
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2009 at 6:21pm
Good. Send me your solution - may be we can use it as option
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2009 at 6:37pm
there isn't much code really :) All I've got is the following (in the OnEvent_Calendar function):

    else if (XTP_NC_CALENDARRBUTTONDOWN == Event)
    {
        mouse_event(MOUSEEVENTF_LEFTDOWN, ptHit.x, ptHit.y, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, ptHit.x, ptHit.y, 0, 0);
    }
    else if (XTP_NC_CALENDARCONTEXTMENU == Event)
    {
        if (bHitTest)
        {
            CPoint ptMenu = ptHit;
            GetCalendarCtrl().ClientToScreen(&ptMenu);

            if(hitInfo.pViewEvent)
            {
                hitInfo.pViewEvent->SetSelected(TRUE);
                GetCalendarCtrl().RedrawControl();
            }

            CMenu menu;
            VERIFY(menu.LoadMenu(IDR_MENU_CONTEXT_PLANNER));
           
            CMenu * popupMenu = menu.GetSubMenu(0);

            // track menu
            int nMenuResult = CXTPCommandBars::TrackPopupMenu(popupMenu,
                /*TPM_NONOTIFY |*/ TPM_RETURNCMD | TPM_LEFTALIGN |TPM_RIGHTBUTTON,
                ptMenu.x, ptMenu.y, this, NULL);

// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2009 at 6:44pm
So you did not find a way to do it on right buton down event only - hightlight + context menu in one action...
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2009 at 7:01pm
The code above actually does that. What I found is that after the XTP_NC_CALENDARRBUTTONDOWN is processed, the XTP_NC_CALENDARCONTEXTMENU is sent, so everything works as I want - a user presses the right mouse button, a spot in the view is selected and the context menu comes up.
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2009 at 8:16pm
You can also make this (Highlighting) action optional if use extra condition (both mouse buttons pressed)

if ( GetKeyState(VK_LBUTTON) == 1) { -- DO YOUR HIGHLIGHTING }

-- NOW POPUP YOUR MENU

 

Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2009 at 8:49pm
btw - did you try this sample http://forum.codejock.com/forum_posts.asp?TID=14354 today? Check DayView (or WorkWeekView...) PrintPreview and Print
Back to Top
dennisV View Drop Down
Senior Member
Senior Member
Avatar

Joined: 07 October 2004
Location: Australia
Status: Offline
Points: 242
Post Options Post Options   Thanks (0) Thanks(0)   Quote dennisV Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2009 at 9:05pm
No, I haven't tried the sample, but looks good :) I'm waiting for 13.1...
// W7 64 Ultimate SP1
// VS 2008
// CodeJock 16.2.3 (MFC)
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.250 seconds.