void COXDragDockContext::Move(CPoint pt) { CPoint ptOffset = pt - m_ptLast; #ifdef _MAC // prevent dragging the floating window completely under the menu bar GDHandle hgd = _AfxFindDevice(pt.x, pt.y); if (hgd == NULL || hgd == GetMainDevice() || TestDeviceAttribute(hgd, hasAuxMenuBar)) { CRect rect; if ((HORZF(m_dwStyle) && !m_bFlip) || (VERTF(m_dwStyle) && m_bFlip)) rect = m_rectFrameDragHorz; else rect = m_rectFrameDragVert; // determine our new position rect.OffsetRect(ptOffset); // keep us on the screen if we were getting too close to the menu bar int yMBarBottom = (*hgd)->gdRect.top + GetMBarHeight() + 4; if (rect.bottom < yMBarBottom) { pt.y += yMBarBottom - rect.bottom; ptOffset.y += yMBarBottom - rect.bottom; } } #endif // offset all drag rects to new position m_rectDragHorz.OffsetRect(ptOffset); m_rectFrameDragHorz.OffsetRect(ptOffset); m_rectDragVert.OffsetRect(ptOffset); m_rectFrameDragVert.OffsetRect(ptOffset); // these rectangles only move in 1 direction m_rectDragHorzAlone.top += ptOffset.y; m_rectDragHorzAlone.bottom += ptOffset.y; m_rectDragVertAlone.left += ptOffset.x; m_rectDragVertAlone.right += ptOffset.x; m_ptLast = pt; // if control key is down don't dock m_dwOverDockStyle = m_bForceFrame ? 0 : CanDock(); // update feedback DrawFocusRect(); }
void CControlBar::ShowToolTip(CPoint point, UINT nHit) { EnterCriticalSection(_afxCriticalSection); ASSERT(m_bDelayDone); // delay should have been done if (nHit != m_nHitLast || m_pBarLast != this) { // always destroy the tooltip and re-create so CS_SAVEBITS works DestroyToolTip(FALSE, FALSE); ASSERT(m_pToolTip == NULL); if (m_dwStyle & CBRS_TOOLTIPS) m_pToolTip = CreateToolTip(); m_nHitLast = nHit; m_pBarLast = this; if (m_pToolTip != NULL) { // get tooltip text with WM_NOTIFY, TTN_NEEDTEXT TOOLTIPTEXT tooltext = { NULL, NULL, TTN_NEEDTEXT, NULL, _T(""), NULL, 0 }; tooltext.hdr.hwndFrom = m_hWnd; tooltext.hdr.idFrom = nHit; GetOwner()->SendMessage(WM_NOTIFY, nHit, (LPARAM)&tooltext); if (tooltext.hinst != NULL) { ::LoadString(tooltext.hinst, (WORD)(DWORD)tooltext.lpszText, tooltext.szText, _countof(tooltext.szText)); tooltext.lpszText = tooltext.szText; } else if (tooltext.lpszText == NULL) tooltext.lpszText = tooltext.szText; if (lstrlen(tooltext.lpszText) != 0) { // tooltip window will adjust its size during WM_SETTEXT m_pToolTip->SetWindowText(tooltext.lpszText); CRect rect; m_pToolTip->GetWindowRect(rect); // allow the bar to determine the center point of the hit CPoint ptCenter(SHRT_MIN, SHRT_MIN); ScreenToClient(&point); VERIFY(nHit == OnCmdHitTest(point, &ptCenter)); ClientToScreen(&point); if (ptCenter.x != SHRT_MIN) point.x = ptCenter.x - rect.Width()/2; if (ptCenter.y != SHRT_MIN) point.y = ptCenter.y - rect.Height()/2; // should be below mouse pointer int yAdjust = +(::GetSystemMetrics(SM_CYMENU) * 5) / 4; if (ptCenter.y == SHRT_MIN) point.y += yAdjust; // make sure the window is not off the screen int xScreenRight = ::GetSystemMetrics(SM_CXSCREEN); int yScreenBottom = ::GetSystemMetrics(SM_CYSCREEN); #ifdef _MAC GDHandle hgd = _AfxFindDevice(point.x, point.y); if (hgd != NULL) { xScreenRight = (*hgd)->gdRect.right; yScreenBottom = (*hgd)->gdRect.bottom; } #endif if (point.x + rect.Width() > xScreenRight) point.x -= point.x + rect.Width() - xScreenRight; if (point.y + rect.Height() > yScreenBottom) point.y -= yAdjust + yAdjust/2 + rect.Height(); // show it and update it m_pToolTip->SetWindowPos(NULL, point.x, point.y, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW|SWP_NOACTIVATE); m_pToolTip->UpdateWindow(); } } if (m_dwStyle & CBRS_FLYBY) { // finally, update message line status GetOwner()->SendMessage(WM_SETMESSAGESTRING, nHit); m_bStatusSet = TRUE; } } LeaveCriticalSection(_afxCriticalSection); }