⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcgpopupmenu.cpp

📁 用bcg库编写的java IDE 源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	}
}
//****************************************************************************************
void CBCGPopupMenu::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CRect rectClient;	// Client area rectangle
	GetClientRect(&rectClient);

	BOOL bDrawShadows = m_iShadowSize != 0 &&
						m_bAnimationIsDone && 
						!CBCGToolBar::IsCustomizeMode ();

	if(bDrawShadows)
	{
	  rectClient.right -= m_iShadowSize;
	  rectClient.bottom -= m_iShadowSize;
	}

	//CRect rcWindow;
	//GetWindowRect(rcWindow);
	//GuiDrawLayer::DrawShade(rcWindow,rcWindow.TopLeft(),&dc);
	//if(bDrawShadows)
	//  DrawShadows(dc,rectClient);

	
	//dc.Draw3dRect (rectClient,
	//				globalData.clrBtnLight, 
	//				globalData.clrBtnDkShadow);
    //
	//dc.Draw3dRect(rectClient,GuiDrawLayer::GetRGBCaptionXP(),GuiDrawLayer::GetRGBCaptionXP());
	rectClient.DeflateRect(1,0,0,0);
	//dc.Draw3dRect (rectClient,
	//				globalData.clrBtnHilite,
	//				globalData.clrBtnShadow);

	dc.Draw3dRect(rectClient,GuiDrawLayer::GetRGBCaptionXP(),GuiDrawLayer::GetRGBCaptionXP());

	CBCGToolbarMenuButton* pBtn = GetParentButton();
	
    if(/*pBtn != NULL*/false)
	{
	  CPen pen(PS_SOLID,1,GuiDrawLayer::GetRGBMenuItemBackGrnd());
	  CPen* pOldPen = dc.SelectObject(&pen);
      dc.MoveTo(rectClient.left+2,rectClient.top);
	  dc.LineTo(pBtn->Rect().Width()-4,rectClient.top);
      dc.SelectObject(pOldPen);
	}
	

	//rectClient.DeflateRect(1,1);
	//dc.FillSolidRect(rectClient,/*GetSysColor(CNewMenu::cCOLOR_MENUBAR)*/RGB(255,255,255));

	if(m_bScrollable)
	{
		DrawImage (&dc, m_rectScrollUp, 
			IsScrollUpAvailable () ? CMenuImages::IdArowUp : CMenuImages::IdArowUpDisabled, 
					m_iScrollMode < 0);
		DrawImage (&dc, m_rectScrollDn, 
					IsScrollDnAvailable () ? CMenuImages::IdArowDown : CMenuImages::IdArowDownDsbl,
					m_iScrollMode > 0);
	}

	m_bShown = TRUE;
}
//****************************************************************************************
int CBCGPopupMenu::OnMouseActivate(CWnd* /*pDesktopWnd*/, UINT /*nHitTest*/, UINT /*message*/) 
{
	return MA_NOACTIVATE;
}
//****************************************************************************************
void CBCGPopupMenu::RecalcLayout (BOOL /*bNotify*/) 
{
#ifdef _DEBUG
	if (m_pParentBtn != NULL)
	{
		ASSERT_VALID (m_pParentBtn);
		ASSERT (m_pParentBtn->m_pPopupMenu == this);
	}
#endif // _DEBUG

	CBCGPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	if (!::IsWindow (m_hWnd) ||
		!::IsWindow (pMenuBar->m_hWnd))
	{
		return;
	}

	CRect rectScreen;
	::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0);

	CSize size = pMenuBar->CalcSize ();
	size.cx += iBorderSize * 2;
	size.cy += iBorderSize * 2;

	if (m_pMenuCustomizationPage != NULL)
	{
		size.cy += ::GetSystemMetrics (SM_CYSMCAPTION);
		size.cy += 2 * ::GetSystemMetrics (SM_CYBORDER) + 5;
	}

	//---------------------------------------------
	// Adjust the menu position by the screen size:
	//---------------------------------------------
	if (m_ptLocation.x + size.cx > rectScreen.right)
	{
		//-----------------------------------------------------
		// Menu can't be overlapped with the parent popup menu!
		//-----------------------------------------------------
		CBCGPopupMenu* pParentMenu = GetParentPopupMenu ();
		CBCGMenuBar* pParentMenuBar = m_pParentBtn == NULL ? NULL :
			DYNAMIC_DOWNCAST (CBCGMenuBar, m_pParentBtn->m_pWndParent);

		if (pParentMenu != NULL)
		{
			CRect rectParent;
			pParentMenu->GetWindowRect (rectParent);

			m_ptLocation.x = rectParent.left - size.cx;
		}
		else if (pParentMenuBar != NULL && 
			(pParentMenuBar->m_dwStyle & CBRS_ORIENT_HORZ) == 0)
		{
			//------------------------------------------------
			// Parent menu bar is docked vertical, place menu 
			// in the left or right side of the parent frame:
			//------------------------------------------------
			CRect rectParent;
			pParentMenuBar->GetWindowRect (rectParent);

			m_ptLocation.x = rectParent.left - size.cx;
		}
		else
		{
			m_ptLocation.x = rectScreen.right - size.cx - 1;
		}

		if (m_ptLocation.x < rectScreen.left)
		{
			m_ptLocation.x = rectScreen.left;
		}

		if (m_AnimationType == UNFOLD)
		{
			m_bIsAnimRight = FALSE;
		}
	}

	if (m_ptLocation.y + size.cy > rectScreen.bottom)
	{
		if (m_bScrollable)
		{
			size.cy = rectScreen.bottom - m_ptLocation.y;
		}
		else
		{
			if (m_pParentBtn != NULL && m_pParentBtn->GetParentWnd () != NULL)
			{
				CPoint ptRight (m_pParentBtn->Rect ().right, 0);
                m_pParentBtn->GetParentWnd ()->ClientToScreen (&ptRight);

                CPoint ptTop (0, m_pParentBtn->Rect ().top - size.cy);
				m_pParentBtn->GetParentWnd ()->ClientToScreen (&ptTop);

                if (ptTop.y < 0)
                {
                    m_ptLocation.y = 0;
                    m_ptLocation.x = ptRight.x;
                }
                else
                {
                    m_ptLocation.y = ptTop.y;
                }
			}
			else
			{
				m_ptLocation.y -= size.cy;
			}

			if (m_ptLocation.y < rectScreen.top)
			{
				m_ptLocation.y = rectScreen.top;
			}
		}

		if (m_ptLocation.y + size.cy > rectScreen.bottom)
		{
			EnableScrolling ();
		}

		m_bIsAnimDown = FALSE;
	}

	m_FinalSize = size;

	//----------------------------------------------------------------
	// If the final size is more, that half-screen (in either x or y),
	// CS_SAVEBITS may not save a screen content under the menu. So,
	// we need to save a area under the shadows:
	//---------------------------------------------------------------
	m_bSaveShadows =	(m_FinalSize.cx >= rectScreen.Width ()) ||
						(m_FinalSize.cy >= rectScreen.Height ());

	if (m_bAnimationIsDone || CBCGToolBar::IsCustomizeMode ())
	{
		if (!CBCGToolBar::IsCustomizeMode ())
		{
			size.cx += m_iShadowSize;
			size.cy += m_iShadowSize;
		}

		if (m_pMenuCustomizationPage != NULL)
		{
			SetWindowPos (NULL, -1, -1, size.cx, size.cy,
						SWP_NOMOVE | SWP_NOZORDER |
						SWP_NOACTIVATE);
		}
		else
		{
			SetWindowPos (NULL, m_ptLocation.x, m_ptLocation.y, size.cx, size.cy,
						SWP_NOZORDER | SWP_NOACTIVATE);
		}
	}

	if (CBCGToolBar::IsCustomizeMode ())
	{
		pMenuBar->AdjustLocations ();
	}

	//---------------------------------------------------
	// Parent button maybe covered by shadow, repaint it:
	//---------------------------------------------------
	if (m_iShadowSize != 0 &&
		m_bAnimationIsDone && 
		!CBCGToolBar::IsCustomizeMode () &&
		m_pParentBtn != NULL &&
		m_pParentBtn->GetParentWnd () != NULL)
	{
		CWnd* pWndParent = m_pParentBtn->GetParentWnd ();

		CRect rectInter;

		CRect rectMenu;
		GetWindowRect (rectMenu);

		CRect rectShadowRight (CPoint (rectMenu.right + 1, rectMenu.top), 
					CSize (m_iShadowSize, rectMenu.Height () + m_iShadowSize));
		pWndParent->ScreenToClient (rectShadowRight);
		if (rectInter.IntersectRect (rectShadowRight, m_pParentBtn->m_rect))
		{
			pWndParent->InvalidateRect (m_pParentBtn->m_rect);
			pWndParent->UpdateWindow ();
		}
		else
		{
			CRect rectShadowBottom (CPoint (rectMenu.left, rectMenu.bottom + 1),
						CSize (rectMenu.Width () + m_iShadowSize, m_iShadowSize));
			pWndParent->ScreenToClient (rectShadowBottom);
			if (rectInter.IntersectRect (rectShadowBottom, m_pParentBtn->m_rect))
			{
				pWndParent->InvalidateRect (m_pParentBtn->m_rect);
				pWndParent->UpdateWindow ();
			}
		}
	}
}
//****************************************************************************************
void CBCGPopupMenu::OnDestroy() 
{
	if(m_pwndContainer != NULL)
	{
	   m_pwndContainer->ShowWindow(SW_HIDE);
       m_pwndContainer->SetParent(m_pwndPrevParent);
       m_pwndContainer = NULL;
	}

	CBCGPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	//---------------------------------------------------------
	// First, maybe we have a dragged menu item. Remove it now:
	//---------------------------------------------------------
	if (pMenuBar->m_pDragButton != NULL &&
		!pMenuBar->m_bIsDragCopy)
	{
		pMenuBar->RemoveButton (
			pMenuBar->ButtonToIndex (pMenuBar->m_pDragButton));
		pMenuBar->m_pDragButton = NULL;
	}

	if (m_pParentBtn != NULL)
	{
		ASSERT (m_pParentBtn->m_pPopupMenu == this);

		SaveState ();

		m_pParentBtn->m_pPopupMenu = NULL;
		m_pParentBtn->m_bClickedOnMenu = FALSE;

		CBCGPopupMenu* pParentMenu = GetParentPopupMenu ();
		if (pParentMenu != NULL)
		{
			if (m_bAutoDestroyParent && !CBCGToolBar::IsCustomizeMode ())
			{
				//-------------------------------------------
				// Automatically close the parent popup menu:
				//-------------------------------------------
				pParentMenu->SendMessage (WM_CLOSE);
				m_pParentBtn = NULL;
			}
			else if (pParentMenu->m_iShadowSize > 0 &&
				m_AnimationType != NO_ANIMATION)
			{
				//--------------------
				// Redraw parent menu:
				//--------------------
				pParentMenu->ShowWindow (SW_HIDE);
				pParentMenu->UpdateBottomWindows ();
				pParentMenu->ShowWindow (SW_SHOWNOACTIVATE);
			}
		}
		else
		{
			CBCGMenuBar* pParentMenuBar = m_pParentBtn == NULL ? NULL :
				DYNAMIC_DOWNCAST (CBCGMenuBar, m_pParentBtn->m_pWndParent);

			if (pParentMenuBar == NULL)
			{
				CBCGMenuBar::SetShowAllCommands (FALSE);
			}
		}
	}
	else
	{
		CBCGMenuBar::SetShowAllCommands (FALSE);
	}

	if (m_pMenuCustomizationPage != NULL)
	{
		m_pMenuCustomizationPage->CloseContextMenu (this);
	}
				
	//------------------------------------------------
	// Inform the main frame about the menu detsroyng:
	//------------------------------------------------
	CFrameWnd* pWndMain = GetTopLevelFrame ();

	CBCGMDIFrameWnd* pMainFrame = DYNAMIC_DOWNCAST (CBCGMDIFrameWnd, pWndMain);
	if (pMainFrame != NULL)
	{
		pMainFrame->OnClosePopupMenu (this);
	}
	else	// Maybe, SDI frame...
	{
		CBCGFrameWnd* pFrame = DYNAMIC_DOWNCAST (CBCGFrameWnd, pWndMain);
		if (pFrame != NULL)
		{
			pFrame->OnClosePopupMenu (this);
		}
		else	// Maybe, OLE frame...
		{
			CBCGOleIPFrameWnd* pOleFrame = 
				DYNAMIC_DOWNCAST (CBCGOleIPFrameWnd, pWndMain);
			if (pOleFrame != NULL)
			{
				pOleFrame->OnClosePopupMenu (this);
			}
		}
	}

	CMiniFrameWnd::OnDestroy();
}
//****************************************************************************************
void CBCGPopupMenu::PostNcDestroy() 
{
	if (m_pParentBtn != NULL)
	{
		m_pParentBtn->OnCancelMode ();
	}
		
	CMiniFrameWnd::PostNcDestroy();
}
//****************************************************************************************
void CBCGPopupMenu::SaveState ()
{
	if (!CBCGToolBar::IsCustomizeMode ())
	{
		return;
	}

	if (m_pParentBtn == NULL)
	{
		return;
	}

	ASSERT_VALID (m_pParentBtn);

	CBCGPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	HMENU hmenu = pMenuBar->ExportToMenu ();
	ASSERT (hmenu != NULL);

	m_pParentBtn->CreateFromMenu (hmenu);
	::DestroyMenu (hmenu);

	CBCGPopupMenu* pParentMenu = GetParentPopupMenu ();
	if (pParentMenu != NULL)
	{
		pParentMenu->SaveState ();
	}
}
//****************************************************************************************
void CBCGPopupMenu::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	ASSERT_VALID (this);

	CBCGPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

#ifdef _DEBUG
	if (m_pParentBtn != NULL)
	{
		ASSERT_VALID (m_pParentBtn);
		ASSERT (m_pParentBtn->m_pPopupMenu == this);
	}
#endif // _DEBUG

	BOOL bHightlightWasChanged = FALSE;

	switch (nChar)
	{
	case VK_RIGHT:
		{
			//-------------------------------------------
			// Save animation type and disable animation:
			//-------------------------------------------
			ANIMATION_TYPE animType = m_AnimationType;
			m_AnimationType = NO_ANIMATION;

			//-------------------------------
			// Try to open next cascade menu:
			//-------------------------------
			CBCGToolbarMenuButton* pSelItem = GetSelItem ();
			if (pSelItem != NULL && 
				(pSelItem->m_nID == (UINT) -1 || pSelItem->m_nID == 0) &&
				pSelItem->OpenPopupMenu ())
			{
				if (pSelItem->m_pPopupMenu != NULL)
				{
					//--------------------------
					// Select a first menu item:
					//--------------------------
					if (GetSelItem () == pSelItem)
					{
						pSelItem->m_pPopupMenu->OnKeyDown (VK_HOME, 0, 0);
					}
				}
			}
			else
			{
				//------------------------------------------------------
				// No next menu, first try to go to the parent menu bar:
				//------------------------------------------------------
				CBCGToolBar* pToolBar = GetParentToolBar ();
				if (pToolBar != NULL && 
					!pToolBar->IsKindOf (RUNTIME_CLASS (CBCGPopupMenuBar)))
				{
					pToolBar->NextMenu ();
				}
				else
				{
					//------------------------------------------------------
					// Close the current menu and move control to the parent
					// popup menu:
					//------------------------------------------------------
					CBCGPopupMenu* pParenMenu = GetParentPopupMenu ();
					if (pParenMenu != NULL)
					{
						pParenMenu->SendMessage (WM_KEYDOWN, VK_RIGHT);
					}
				}
			}

			//------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -