void COptionListBox::OnLButtonDown(UINT nFlags, CPoint point)
{
    int idx;
    int curIdx;
    BOOL bResult;


    curIdx = GetCurSel();

    idx = ItemFromPoint(point, bResult);
    if(FALSE == bResult) {
        CRect rect;
        GetItemRect(idx, rect);
        if(	point.x >= rect.left && point.x < rect.right &&
                point.y >= rect.top && point.y < rect.bottom) {

            SetCurSel(idx);
            UpdateWindow();

            bResult = NotifyParentOfSelChanging();
            if(FALSE == bResult) {
                SetCurSel(curIdx);

                return;
            }
            SetCapture();
        }
    }

    //CListBox::OnLButtonDown(nFlags, point);
}
Exemple #2
0
//*****************************************************************************
//
// Function Name: RGridCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
//
// Description:   Message handler for WM_LBUTTONDOWN.
//
// Returns:		   None
//
// Exceptions:	   None
//
//*****************************************************************************
void RGridCtrlBase::OnLButtonDown(UINT, CPoint point) 
{
	BOOL fOutsideRect ;
	int  nIndex = ItemFromPoint( point, fOutsideRect ) ;

//	CRect rect ;
//	GetItemRect( nIndex, rect ) ;

	if (!fOutsideRect /*rect.PtInRect( point )*/)
	{
		if (LB_ERR != nIndex)
		{
			SetCurSel( nIndex ) ;
		}

		if (GetStyle() & LBS_NOTIFY)
		{
			GetParent()->PostMessage(WM_COMMAND,
				MAKEWPARAM( GetDlgCtrlID(), LBN_SELCHANGE ), 
				(LPARAM) GetSafeHwnd()) ;
		}
	}

	if ((GetStyle() & WS_TABSTOP) && ((CWnd *) this != GetFocus()))
	{
		SetFocus() ;
	}
}
//
/// Handle the DRAGLISTMSGSTRING notification by calling virtual functions
/// based on the notification message.
//
/// Responds to the DL_BEGINDRAG, DL_DRAGGING, DL_DROPPED, and DL_CANCELDRAG
/// messages by calling the BeginDrag, Dragging, Dropped, and CancelDrag functions
/// respectively.
//
TResult
TDragList::DragNotify(TParam1, TParam2 lp)
{
  DRAGLISTINFO * info = (DRAGLISTINFO *)lp;
  if (info) {
    TPoint p = info->ptCursor;
    int item = ItemFromPoint(p);

    switch (info->uNotification) {
      case DL_BEGINDRAG:
        return BeginDrag(item, p);

      case DL_DRAGGING:
        return Dragging(item, p);

      case DL_DROPPED:
        Dropped(item, p);
        break;

      case DL_CANCELDRAG:
        CancelDrag(item, p);
        break;

      default:
        // Should not ever happen.
        ///TH perhaps throw an exception?
        break;
    }
  }
  return 0;
}
Exemple #4
0
void CUndoListBox::OnMouseMove(UINT nFlags, CPoint point)
{
	CListBox::OnMouseMove(nFlags, point);

	BOOL bOutside;
	int iItem = ItemFromPoint(point, bOutside);

	if (!bOutside)
	{
		SelItemRange(FALSE, iItem + 1, GetCount() - 1);

		if (iItem == 0)
		{
			SetSel(0);
		}
		else
		{
			SelItemRange(TRUE, 0, iItem);
		}

		CString strLabel;
		strLabel.Format(_T("Undo %d Actions"), iItem + 1);

		m_Bar.SetLabel(strLabel);
	}
}
Exemple #5
0
void CPlugToolBar::OnMouseMove(UINT nFlags, CPoint point)
{
    BOOL bOutside;
    int i;

    i = ItemFromPoint (point, bOutside);

    if (bOutside)
    {
        if (m_iMayBeSelected != -1)
        {
            InvalidateItem (m_iMayBeSelected);
            ReleaseCapture ();
        }

        m_iMayBeSelected = m_iPressed = -1;
        return;
    }

    CRect rcItem;
    GetItemRect (i, &rcItem);
    CPoint pt (rcItem.left + (rcItem.right - rcItem.left) / 2 - 32/2, rcItem.top + 5);


    rcItem.left = pt.x;
    rcItem.top  = pt.y;
    rcItem.right = pt.x + 32;
    rcItem.bottom = pt.y + 32;


    if (!PtInRect (&rcItem, point))
    {
        if (m_iMayBeSelected != -1)
        {
            InvalidateItem (m_iMayBeSelected);
            ReleaseCapture ();
        }

        m_iMayBeSelected = m_iPressed = -1;
        return;
    }

    if (m_iMayBeSelected == i)
        return;
    else if (m_iMayBeSelected != -1)
    {
        InvalidateItem (m_iMayBeSelected);
        ReleaseCapture ();
    }

    m_iMayBeSelected = i;
    m_iPressed = -1;

    InvalidateItem (i);

    SetCapture ();

    CListBox::OnMouseMove(nFlags, point);
}
void CXTPShortcutListBox::RedrawItem(CPoint point)
{
    BOOL bOutSide;
    int nIndex = ItemFromPoint(point, bOutSide);

    if (!bOutSide)
    {
        RedrawItem(nIndex);
    }
}
Exemple #7
0
void CPngListBox::DrawClient(CDC* pDC)
{
	CRect rcClient;
	GetClientRect(rcClient);

	MemPaintParentPng(this, *pDC, rcClient, m_pImgParentBk, m_bFillOrTitleParentPng);

	if(IsWindowEnabled())
	{
		::SetTextColor(pDC->GetSafeHdc(), m_textColor);
		MemPaintPng(*pDC, rcClient, m_pImgBk);
	}
	else
	{
		::SetTextColor(pDC->GetSafeHdc(), RGB(128, 128, 128));
		MemPaintPng(*pDC, rcClient, m_pImgDisable);
	}

	CRect	rcItem;
	CString	szItemString;
	BOOL	bOutSide = FALSE;
	int		itemCount = GetCount();

	CPoint	ptCursor;
	GetCursorPos(&ptCursor);
	ScreenToClient(&ptCursor);

	for (int pos = rcClient.top; pos < rcClient.bottom;)
	{
		UINT index = ItemFromPoint(CPoint(rcClient.left, pos), bOutSide);

		if(bOutSide)
			break;

		GetText(index, szItemString);
		GetItemRect(index, &rcItem);

		//左右边框除外
		CRect desRc = rcItem;

		if (GetSel(index) || rcItem.PtInRect(ptCursor))
		{	//上下边框除外
			MemPaintPng(*pDC, desRc, m_pImgListSel);
		}
		else
		{
			//MemPaintPng(memDC, desRc, m_pImgListCenter);
		}

		desRc.left += m_nTextOffsetX;
		MemDrawText(*pDC, desRc, szItemString, m_textAlignMode);

		pos += GetItemHeight(index);
	}
}
Exemple #8
0
///////////////////////////////////////////////////////////////////////////////
// OnMouseMove
void CXTipListBox::OnMouseMove(UINT nFlags, CPoint point) 
{
	CRect rectClient;
	GetClientRect(&rectClient);

	if (rectClient.PtInRect(point))
	{
		CPoint pointScreen;
		::GetCursorPos(&pointScreen);
		BOOL bOutside = FALSE;
		int nItem = ItemFromPoint(point, bOutside);  // calculate listbox item number (if any)

		if (!bOutside && (nItem >= 0))
		{
			CString strText = _T("");
			GetText(nItem, strText);
			m_ToolInfo.lpszText = (LPTSTR)(LPCTSTR)strText;

			CRect rect;
			GetItemRect(nItem, &rect);
			ClientToScreen(&rect);

			HDC hDC = ::GetDC(m_hWnd);
			ASSERT(hDC);

			CFont *pFont = GetFont();
			HFONT hOldFont = (HFONT) ::SelectObject(hDC, (HFONT) *pFont);

			SIZE size;
			::GetTextExtentPoint32(hDC, strText, strText.GetLength(), &size);
			::SelectObject(hDC, hOldFont);
			::ReleaseDC(m_hWnd, hDC);

			//TRACE(_T("<%s>  cx=%d  width=%d\n"), strText, size.cx, rect.Width());
			if (size.cx > (rect.Width() - 3))
			{
				::SendMessage(m_hWndToolTip, TTM_UPDATETIPTEXT, 0, (LPARAM) &m_ToolInfo);
				::SendMessage(m_hWndToolTip, TTM_TRACKPOSITION, 0, 
					(LPARAM) MAKELONG(rect.left, rect.top));
				::SendMessage(m_hWndToolTip, TTM_TRACKACTIVATE, TRUE, (LPARAM)(LPTOOLINFO) &m_ToolInfo);
				SetTimer(1, 80, NULL);	// set timer for out-of-rect detection
			}
			else
			{
				::SendMessage(m_hWndToolTip, TTM_TRACKACTIVATE, FALSE, (LPARAM)(LPTOOLINFO) &m_ToolInfo);
			}
		}
	}
	else
	{
		::SendMessage(m_hWndToolTip, TTM_TRACKACTIVATE, FALSE, (LPARAM)(LPTOOLINFO) &m_ToolInfo);
	}
	
	CListBox::OnMouseMove(nFlags, point);
}
Exemple #9
0
BOOL CListBoxST::OnReflectedDblclk() 
{
	UINT			nIndex = LB_ERR;
	BOOL			bOutside = FALSE;
	DWORD			dwPos = ::GetMessagePos();
	CPoint			Point(((int)(short)LOWORD(dwPos)), ((int)(short)HIWORD(dwPos)));

	ScreenToClient(&Point);
	nIndex = ItemFromPoint(Point, bOutside);
	if (!bOutside)	return !IsItemEnabled(nIndex);

	return FALSE;
} // End of OnReflectedDblclk
void CXTPPropertyGridInplaceList::OnMouseMove(UINT nFlags, CPoint point)
{
	CListBox::OnMouseMove(nFlags, point);

	if (m_bTrackSelection)
	{
		BOOL bOutsize = FALSE;
		int nItem = ItemFromPoint(point, bOutsize);
		if (nItem != -1 && !bOutsize && nItem != GetCurSel())
		{
			SetCurSel(nItem);
		}
	}
}
void CListBoxEx::OnLButtonDown(UINT nFlags, CPoint point)
{
    BOOL bOutside;
    int iItem = ItemFromPoint(point, bOutside);
    LBEXTITEMSTRUCT& lbis = Items[iItem];

    if(lbis.iDataType == lbdBool)
    {
        // toggle bool field
        lbis.iDataValue = !lbis.iDataValue;
    }

    CListBox::OnLButtonDown(nFlags, point);
}
Exemple #12
0
INT_PTR CShaderListBox::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
    BOOL out = FALSE;
    UINT item = ItemFromPoint(point, out);
    if (out) {
        return -1;
    }
    pTI->uFlags |= TTF_ALWAYSTIP;
    pTI->hwnd = m_hWnd;
    pTI->uId = item;
    VERIFY(GetItemRect(item, &pTI->rect) != LB_ERR);
    pTI->lpszText = LPSTR_TEXTCALLBACK;
    return pTI->uId;
}
Exemple #13
0
void CUndoListBox::OnLButtonUp(UINT nFlags, CPoint point)
{
	BOOL bOutside;
	ItemFromPoint(point, bOutside);

	if (!bOutside)
	{
		m_Bar.DoUndo();
	}

	if (IsWindow(GetSafeHwnd()))
	{
		CListBox::OnLButtonUp(nFlags, point);
	}
}
Exemple #14
0
//*****************************************************************************
//
// Function Name: RGridCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) 
//
// Description:   Message handler for WM_LBUTTONDBLCLK.
//
// Returns:		   None
//
// Exceptions:	   None
//
//*****************************************************************************
void RGridCtrlBase::OnLButtonDblClk(UINT, CPoint point) 
{
	if (GetStyle() & LBS_NOTIFY)
	{
		BOOL fOutsideRect ;
		int  nIndex = ItemFromPoint( point, fOutsideRect ) ;

		if (nIndex == GetCurSel())
		{
			GetParent()->PostMessage(WM_COMMAND, 
				MAKEWPARAM( GetDlgCtrlID(), LBN_DBLCLK ), 
				(LPARAM) GetSafeHwnd()) ;
		}
	}
}
Exemple #15
0
void CListBoxExtn::OnMouseMove(UINT nFlags, CPoint point)
{
  if (!m_bUseToolTips) {
    goto exit;
  } else {
    CRect rectClient;
    GetClientRect(&rectClient);
    BOOL bOutside(FALSE);
    int nItem = -2;

    if (rectClient.PtInRect(point)) {
      CPoint pointScreen;
      ::GetCursorPos(&pointScreen);
      nItem = ItemFromPoint(point, bOutside);  // calculate listbox item number (if any)
    }

    if (m_nHoverLBTimerID) {
      if (!bOutside && m_HoverLBnItem == nItem)
        return;
      KillTimer(m_nHoverLBTimerID);
      m_nHoverLBTimerID = 0;
    }

    if (m_nShowLBTimerID) {
      if (!bOutside && m_HoverLBnItem == nItem)
        return;
      KillTimer(m_nShowLBTimerID);
      m_nShowLBTimerID = 0;
      ShowToolTip(m_HoverLBnItem, false);
    }

    if (!m_bMouseInWindow) {
      m_bMouseInWindow = true;
      TRACKMOUSEEVENT tme = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd, 0};
      VERIFY(TrackMouseEvent(&tme));
    }

    m_nHoverLBTimerID = SetTimer(TIMER_LB_HOVER, HOVER_TIME_LB, NULL);
    m_HoverLBPoint = point;
    m_HoverLBnItem = nItem;
  }

exit:
  CListBox::OnMouseMove(nFlags, point);
}
int CXTPSyntaxEditTipListBox::HitTest(LPPOINT pPoint /*= NULL*/) const
{
	CPoint point;
	if (pPoint == NULL)
	{
		::GetCursorPos(&point);
		ScreenToClient(&point);
		pPoint = &point;
	}

	BOOL bOutside;
	int iIndex = (int)ItemFromPoint(*pPoint, bOutside);

	if (bOutside)
		return LB_ERR;

	return iIndex;
}
INT_PTR CPPageInternalFiltersListBox::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
    BOOL b = FALSE;
    int row = ItemFromPoint(point, b);
    if (row < 0) {
        return -1;
    }

    CRect r;
    GetItemRect(row, r);
    pTI->rect = r;
    pTI->hwnd = m_hWnd;
    pTI->uId = (UINT)row;
    pTI->lpszText = LPSTR_TEXTCALLBACK;
    pTI->uFlags |= TTF_ALWAYSTIP;

    return pTI->uId;
}
int CClipboardListBox::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
{
    int row;
    RECT cellrect;   // cellrect        - to hold the bounding rect
    BOOL tmp = FALSE;
    row  = ItemFromPoint(point,tmp);  //we call the ItemFromPoint function to determine the row,
    //note that in NT this function may fail  use the ItemFromPointNT member function

    if ( row == -1 ) 
        return -1;

    //set up the TOOLINFO structure. GetItemRect(row,&cellrect);
    GetItemRect(row,&cellrect);
    pTI->rect = cellrect;
    pTI->hwnd = m_hWnd;
    pTI->uId = (UINT)((row));   //The ¡¥uId¡¦ is assigned a value according to the row value.
    pTI->lpszText = LPSTR_TEXTCALLBACK;
    return pTI->uId;
}
void CXTPShortcutListBox::OnMouseMove(UINT /*nFlags*/, CPoint point)
{
    BOOL bOutSide;
    int nIndex = ItemFromPoint (point, bOutSide);

    CRect rcItem;
    GetItemRect(nIndex, &rcItem);

    if ((m_nPrevIndex != -1) && (m_nPrevIndex != nIndex))
    {
        RedrawItem(m_nPrevIndex);
    }

    if (bOutSide || !rcItem.PtInRect(point))
    {
        RedrawItem(nIndex);
        nIndex = -1;
    }

    if (nIndex != GetCurSel())
    {
        SetCurSel(nIndex);

        if (nIndex != -1)
        {
            RedrawItem(nIndex);

            TRACKMOUSEEVENT tme =
            {
                sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd, 0
            };
            _TrackMouseEvent(&tme);
        }
    }

    m_nPrevIndex = nIndex;
}
Exemple #20
0
// Sets the hilite flag based on cursor position.
void CCJOutlookBar::OnTimer(UINT nIDEvent) 
{
    BOOL   bOutSide;
    CRect  rItem;
	CRect  rWindow;
	CPoint pt;
    int    nIndex;

    // Get the rect of the current window,
	// get the current cursor position.
	GetWindowRect (rWindow);
    GetCursorPos (&pt);

    // If the mouse is in the rect of this window,
	// set hilite flag to true, get the item that
	// the mouse is over.
	if (rWindow.PtInRect (pt)) {
		m_bHilight = true;
		nIndex = ItemFromPoint (m_point, bOutSide);

		if (nIndex != GetCurSel() && !bOutSide) {
			SetCurSel( nIndex );
		}
    }

    // If the mouse is not in the rect of
	// this window, kill the timer, set hilite flag
	// to false, and return.
	else {
		m_bHilight = false;
        if( !m_bLBDown ) {
          SetCurSel (-1);
        }
        KillTimer(1);
	}
}
void CPPageInternalFiltersListBox::OnContextMenu(CWnd* pWnd, CPoint point)
{
    if (point.x == -1 && point.y == -1) {
        // The context menu was triggered using the keyboard,
        // get the coordinates of the currently selected item.
        int iSel = GetCurSel();
        CRect r;
        if (iSel != LB_ERR && GetItemRect(iSel, &r) != LB_ERR) {
            point = r.TopLeft();
        }
    } else {
        ScreenToClient(&point);
    }

    // Check that we really inside the list
    BOOL bOutside = TRUE;
    ItemFromPoint(point, bOutside);
    if (bOutside) {
        // Trigger the default behavior
        ClientToScreen(&point);
        __super::OnContextMenu(pWnd, point);
        return;
    }

    CMenu m;
    m.CreatePopupMenu();

    enum {
        ENABLE_ALL = 1,
        DISABLE_ALL,
        ENABLE_VIDEO,
        DISABLE_VIDEO,
        ENABLE_AUDIO,
        DISABLE_AUDIO
    };

    int totalFilters = 0, totalChecked = 0;
    for (int i = 0; i < FILTER_TYPE_NB; i++) {
        totalFilters += m_nbFiltersPerType[i];
        totalChecked += m_nbChecked[i];
    }

    UINT state = (totalChecked != totalFilters) ? MF_ENABLED : MF_GRAYED;
    m.AppendMenu(MF_STRING | state, ENABLE_ALL, ResStr(IDS_ENABLE_ALL_FILTERS));
    state = (totalChecked != 0) ? MF_ENABLED : MF_GRAYED;
    m.AppendMenu(MF_STRING | state, DISABLE_ALL, ResStr(IDS_DISABLE_ALL_FILTERS));

    if (m_n == 1) {
        m.AppendMenu(MF_SEPARATOR);
        state = (m_nbChecked[AUDIO_DECODER] != m_nbFiltersPerType[AUDIO_DECODER]) ? MF_ENABLED : MF_GRAYED;
        m.AppendMenu(MF_STRING | state, ENABLE_AUDIO, ResStr(IDS_ENABLE_AUDIO_FILTERS));
        state = (m_nbChecked[AUDIO_DECODER] != 0) ? MF_ENABLED : MF_GRAYED;
        m.AppendMenu(MF_STRING | state, DISABLE_AUDIO, ResStr(IDS_DISABLE_AUDIO_FILTERS));

        m.AppendMenu(MF_SEPARATOR);
        state = (m_nbChecked[VIDEO_DECODER] != m_nbFiltersPerType[VIDEO_DECODER]) ? MF_ENABLED : MF_GRAYED;
        m.AppendMenu(MF_STRING | state, ENABLE_VIDEO, ResStr(IDS_ENABLE_VIDEO_FILTERS));
        state = (m_nbChecked[VIDEO_DECODER] != 0) ? MF_ENABLED : MF_GRAYED;
        m.AppendMenu(MF_STRING | state, DISABLE_VIDEO, ResStr(IDS_DISABLE_VIDEO_FILTERS));
    }

    ClientToScreen(&point);
    UINT id = m.TrackPopupMenu(TPM_LEFTBUTTON | TPM_RETURNCMD, point.x, point.y, this);

    if (id == 0) {
        return;
    }

    int index = 0;
    for (int i = 0; i < m_filters.GetCount(); i++) {
        switch (m_filters[i].type) {
            case SOURCE_FILTER:
                if (m_n == 1) {
                    continue;
                }
                break;
            case AUDIO_DECODER:
            case VIDEO_DECODER:
                if (m_n == 0) {
                    continue;
                }
                break;
            default:
                continue;
        }

        switch (id) {
            case ENABLE_ALL:
                SetCheck(index, TRUE);
                break;
            case DISABLE_ALL:
                SetCheck(index, FALSE);
                break;
            case ENABLE_AUDIO:
                if (m_filters[i].type == AUDIO_DECODER) {
                    SetCheck(index, TRUE);
                }
                break;
            case DISABLE_AUDIO:
                if (m_filters[i].type == AUDIO_DECODER) {
                    SetCheck(index, FALSE);
                }
                break;
            case ENABLE_VIDEO:
                if (m_filters[i].type == VIDEO_DECODER) {
                    SetCheck(index, TRUE);
                }
                break;
            case DISABLE_VIDEO:
                if (m_filters[i].type == VIDEO_DECODER) {
                    SetCheck(index, FALSE);
                }
                break;
        }
        index++;
    }

    GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), CLBN_CHKCHANGE), (LPARAM)m_hWnd);
}
int COXListPopup::Pick(CRect rect, CRect rectParent)
{
	AdjustDisplayRectangle(rect, rectParent);

	MoveWindow(rect);
	ShowWindow(SW_SHOWNA);
	SetCapture();

	// init message loop
	bool bBreak = false;
	int iReturnItemIdx = -1;
	while (!bBreak)
	{
		MSG msg;
		VERIFY(::GetMessage(&msg, NULL, 0, 0));
		if (msg.message == WM_LBUTTONUP)
		{
			// Get the item under the mouse cursor
			int xPos = GET_X_LPARAM(msg.lParam); 
			int yPos = GET_Y_LPARAM(msg.lParam);

			BOOL bOutside;
			UINT nIndex = ItemFromPoint(CPoint(xPos, yPos), bOutside);
			if (!bOutside)
				iReturnItemIdx = (int) nIndex;
			bBreak = true;
		}
		else if (msg.message == WM_KEYDOWN)
		{
			// Handle ESCAPE, UP, DOWN and ENTER
			if (msg.wParam == VK_ESCAPE)
				bBreak = true;
			else if (msg.wParam == VK_UP)
			{
				int iSel = GetCurSel();
				if (iSel == -1 || iSel == 0)
					SetCurSel(0);
				else
					SetCurSel(iSel - 1);
			}
			else if (msg.wParam == VK_DOWN)
			{
				// Move the selection 1 item down
				int iSel = GetCurSel();
				if (iSel == -1)
					SetCurSel(0);
				else if (iSel == GetCount() - 1)
				{
					// Do nothing
				}
				else
					SetCurSel(iSel + 1);
			}
			else if (msg.wParam == VK_RETURN)
			{
				iReturnItemIdx = GetCurSel();
				bBreak = true;
			}
		}
		else if (msg.message == WM_LBUTTONDOWN)
		{
			// Do nothing				
		}
		else if (msg.message == WM_MOUSEMOVE)
		{
			// Select the item under the mouse cursor
			int xPos = GET_X_LPARAM(msg.lParam); 
			int yPos = GET_Y_LPARAM(msg.lParam);

			BOOL bOutside;
			UINT nIndex = ItemFromPoint(CPoint(xPos, yPos), bOutside);
			if (!bOutside)
				SetCurSel((int) nIndex);
		}
		else
		{
			DispatchMessage(&msg);
		}
	}

	ReleaseCapture();
	ShowWindow(SW_HIDE);

	return iReturnItemIdx;
}
Exemple #23
0
/* This function intercepts messages for the out-basket list box window
 * so that we can handle the right mouse button.
 */
LRESULT EXPORT FAR PASCAL OutBaskListProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
   switch( msg )
      {
      case WM_ERASEBKGND: {
         RECT rc;

         GetClientRect( hwnd, &rc );
         FillRect( (HDC)wParam, &rc, hbrOutBaskWnd );
         return( TRUE );
         }

      case WM_CONTEXTMENU: /*!!SM!!*/
      case WM_RBUTTONDOWN:
         {
         POINT pt;
         LPOB lpob;
         HWND hwndOpen;
         HMENU hPopupMenu;
         int index;
         AEPOPUP aep;

         /* Make sure this window is active and select the item
          * at the cursor.
          */
         if( hwndActive != GetParent( hwnd ) )
            SendMessage( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)hwndOutBasket, 0L );

         /* Select the item under the cursor only if nothing is
          * currently selected.
          */
         index = ItemFromPoint( hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam) );
         if( ListBox_GetSel( hwnd, index ) == 0 )
            {
            CallWindowProc( lpProcListCtl, hwnd, WM_LBUTTONDOWN, wParam, lParam );
            CallWindowProc( lpProcListCtl, hwnd, WM_LBUTTONUP, wParam, lParam );
            }

         /* Get the out-basket menu.
          */
         hPopupMenu = GetSubMenu( hPopupMenus, IPOP_OBASKWINDOW );
         hwndOpen = GetDlgItem( GetParent( hwnd ), IDOK );
         MenuEnable( hPopupMenu, IDOK, IsWindowEnabled( hwndOpen ) );

         /* If we have any selected items, use the attributes
          * of the first item to determine the menu items.
          */
         if( ListBox_GetSelCount( hwnd ) > 0 )
            {
            OBINFO obinfo;

            ListBox_GetSelItems( hwnd, 1, &index );
            lpob = (LPOB)ListBox_GetItemData( hwnd, index );
            Amob_GetObInfo( lpob, &obinfo );
            if( TestF(obinfo.obHdr.wFlags, OBF_HOLD) )
               MenuString( hPopupMenu, IDD_HOLD, GS(IDS_STR275) );
            else
               MenuString( hPopupMenu, IDD_HOLD, GS(IDS_STR277) );
            if( TestF(obinfo.obHdr.wFlags, OBF_KEEP) )
               MenuString( hPopupMenu, IDD_KEEP, GS(IDS_STR440) );
            else
               MenuString( hPopupMenu, IDD_KEEP, GS(IDS_STR439) );
            MenuEnable( hPopupMenu, IDOK, !fInitiatingBlink && Amob_IsEditable( obinfo.obHdr.clsid ) && !TestF(obinfo.obHdr.wFlags, OBF_PENDING) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ) );
            MenuEnable( hPopupMenu, IDD_DELETE, !fInitiatingBlink && !TestF(obinfo.obHdr.wFlags, OBF_PENDING ) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ) );
            MenuEnable( hPopupMenu, IDD_KEEP, !fInitiatingBlink && !TestF(obinfo.obHdr.wFlags, OBF_PENDING ) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ) );
            MenuEnable( hPopupMenu, IDD_HOLD, !fInitiatingBlink && !TestF(obinfo.obHdr.wFlags, OBF_PENDING ) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ) );
            }
         else
            {
            MenuEnable( hPopupMenu, IDOK, FALSE );
            MenuEnable( hPopupMenu, IDD_KEEP, FALSE );
            MenuEnable( hPopupMenu, IDD_HOLD, FALSE );
            MenuEnable( hPopupMenu, IDD_DELETE, FALSE );
            }
            /* Call the AE_POPUP event.
             */
         aep.wType = WIN_OUTBASK;
         aep.pFolder = NULL;
         aep.pSelectedText = NULL;
         aep.cchSelectedText = 0;
         aep.hMenu = hPopupMenu;
         aep.nInsertPos = 2;
         Amuser_CallRegistered( AE_POPUP, (LPARAM)(LPSTR)&aep, 0L );

         GetCursorPos( &pt );
         TrackPopupMenu( hPopupMenu, TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwndFrame, NULL );
         return( 0 );
         }

      case WM_KEYDOWN:
         /* Trap the Delete and Shift+Delete key in the outbasket
          * list box to handle the Delete command.
          */
         if( wParam == VK_DELETE ) 
            {
            PostDlgCommand( GetParent( hwnd ), IDD_DELETE, 0 );
            return( 0 );
            }

         /* Trap the Pause and Shift+Pause key in the outbasket
          * list box to handle the Hold command.
          */
         if( wParam == VK_PAUSE )
            {
            PostDlgCommand( GetParent( hwnd ), IDD_HOLD, 1 );
            return( 0 );
            }
         break;
      }
   return( CallWindowProc( lpProcListCtl, hwnd, msg, wParam, lParam ) );
}
Exemple #24
0
void CCalcListBox::OnMouseMove(UINT nFlags, CPoint point) 
{
	CRect rectClient;
	GetClientRect(&rectClient);

	if (rectClient.PtInRect(point))
	{
		BOOL bOutside = FALSE;
		int nItem = ItemFromPoint(point, bOutside);  // listbox item number we're over (if any)

		if (!bOutside && (nItem >= 0))
		{
			// If we are now hovering over a different item
			if (nItem != curr_)
			{
				// Display expression and/or result string in the tip window
				tip_.Clear();

				CString ss;
				GetText(nItem, ss);   // This assumes combo box strings are not long (ie truncated)

				CString * ps = (CString *)GetItemDataPtr(nItem);
				CString radix_str;
				if (ps != NULL && ps->GetLength() > 0 && (*ps)[0] != ' ')
				{
					char buf[2];
					buf[0] = (*ps)[0];
					buf[1] = '\0';
					long rr = strtol(buf, NULL, 36);

					// Only display nthe radix if it is different from the current calculator radix
					if (pp_ != NULL && rr != pp_->radix_)
						radix_str.Format(" (radix %d)", rr);
				}
				if (ps == NULL)
				{
					// Expression only
					tip_.AddString(ss);
				}
				else if (ps->GetLength() < 100)
				{
					// "Expression = result"
					ss += " = " + CString((const char *)(*ps) + 1) + radix_str;
					tip_.AddString(ss);
				}
				else
				{
					CString tmpStr = ps->Mid(1);

					// Add "Expression ="  then multiple lines of result
					tip_.AddString(ss + " =");

					// Work out the width of the result string in pixels
					CSize sz;
					{
						CClientDC dc(&tip_);
						int nSave = dc.SaveDC();
						dc.SelectObject(tip_.GetFont());
						sz = dc.GetTextExtent(tmpStr);
						dc.RestoreDC(nSave);
					}

					// Check if string fits within this monitor - and work out how many times to wrap if not
					int wrap = 0;
					CRect rctMon = MonitorMouse();   // rect of current monitor
					if (sz.cx > rctMon.Width())
						wrap = sz.cx / (rctMon.Width()*3/4);

					// Add the text to the tip window
					if (wrap > 0)
					{
						// First work out roughly how many characters to put on each line
						int len = tmpStr.GetLength() / (wrap+1);
						char * start = tmpStr.GetBuffer();
						char * end = start + tmpStr.GetLength();

						int ii;
						for (ii = 0; ii < 10 && start + len < end; ++ii)
						{
							char * pp;
							for (pp = start + len*3/4; pp > start + len/2; pp--)
							{
								if (*pp == ' ')
									break;
							}
							char tmp = *pp;
							*pp = '\0';
							tip_.AddString(start);
							*pp = tmp;
							start = pp;
						}
						if (ii < 10)
						{
							tip_.AddString(start);      // remainder left after last "full" line
							tip_.AddString(radix_str);  // radix
						}
						else
							tip_.AddString("...   " + radix_str);
					}
					else
						tip_.AddString(tmpStr + radix_str);
				}

				// Move the tip window just below the mouse and make visible
				CRect rct;
				tip_.GetWindowRect(&rct);
				CPoint pt;
				::GetCursorPos(&pt);
				pt.x -= rct.Width()/2;
				pt.y += rct.Height()/2;
				tip_.Move(pt, false);
				tip_.Show();

				SetTimer(CCALCLISTBOX_TIMER_ID, 100, NULL);  // allows check after window closed/moved off
				curr_ = nItem;  // remember which item we are now showing tip for
			}
			CListBox::OnMouseMove(nFlags, point);
			return;
		}
	}

	// If we didn't return above then we are not over an item
	// Close any tip window that is open
	if (tip_.IsWindowVisible() && !tip_.FadingOut())
		tip_.Hide(300);
	curr_ = -1;

	CListBox::OnMouseMove(nFlags, point);
}