![]() |
How to select date/time under the cursor |
Post Reply ![]() |
Author | |
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() 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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
Check by code the way we show tooltip - there is no selection need to show tooltip - you just move your mouse over |
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
Right - but you have source code so look for tooltip support
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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)
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
Yes, but that's not what I need ![]() |
|
// W7 64 Ultimate SP1
// VS 2008 // CodeJock 16.2.3 (MFC) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
I see - but why don't put set focus call inside your case of your contextmenu / rightbuttonmouse code? And what block means? Time Interval?
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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?
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
I'm trying the day view for now... thanks!
|
|
// W7 64 Ultimate SP1
// VS 2008 // CodeJock 16.2.3 (MFC) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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:
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
I run it now directly from archive - switch to DayView and click Right Mouse button in TimeScale
![]() |
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
We seem to be talking about 2 different things in this whole thread
![]() 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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
try to simulate left click in your handler
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
mouse_event(MOUSEEVENTF_LEFTDOWN, ptHit.x, ptHit.y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, ptHit.x, ptHit.y, 0, 0);
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
Yep, that did the trick, thanks :)
|
|
// W7 64 Ultimate SP1
// VS 2008 // CodeJock 16.2.3 (MFC) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
Good. Send me your solution - may be we can use it as option
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
So you did not find a way to do it on right buton down event only - hightlight + context menu in one action...
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
btw - did you try this sample http://forum.codejock.com/forum_posts.asp?TID=14354 today? Check DayView (or WorkWeekView...) PrintPreview and Print
|
|
![]() |
|
dennisV ![]() Senior Member ![]() ![]() Joined: 07 October 2004 Location: Australia Status: Offline Points: 242 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |