Пример #1
0
BOOL CPageToolbars::OnCmdMsg(UINT nID, INT nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	if( !m_bInitComplete ){
		return CPageBase::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
	}
	
	if(		nCode == CN_UPDATE_COMMAND_UI
		||	nCode == CN_COMMAND
		)
	{
		if( nID == ID_MYEXTBTN_SLIDER || nID == ID_MYEXTBTN_SCROLLER ) {
			if( nCode == CN_UPDATE_COMMAND_UI ){
				CCmdUI * pCmdUI = (CCmdUI *)pExtra;
				ASSERT( pCmdUI != NULL );
				pCmdUI->Enable();
			}
			return TRUE;
		}
		
		if(		nID == ID_COMBOBOX_IN_TOOLBAR 
			||	nID == ID_COMBOBOX_IN_MENUBAR 
			||	nID == ID_EDIT_IN_TOOLBAR 
			||	nID == ID_EDIT_IN_MENUBAR 
			||	nID == ID_CHECKBOX_IN_TOOLBAR 
			||	nID == ID_CHECKBOX_IN_MENUBAR 
			||	nID == ID_LINE_WIDTH_0
			||	nID == ID_LINE_WIDTH_1
			||	nID == ID_LINE_WIDTH_2
			||	nID == ID_LINE_WIDTH_3
			||	nID == ID_LINE_WIDTH_4
			||	nID == ID_LINE_WIDTH_5
			||	nID == ID_LINE_WIDTH_6
			||	nID == ID_LINE_WIDTH_7
			||	nID == ID_LINE_WIDTH_8
			||	nID == ID_LINE_WIDTH_9
			||	nID == ID_LINE_WIDTH_10
			||	nID == ID_LINE_WIDTH_OTHER
			)
		{
			if( nCode == CN_UPDATE_COMMAND_UI ){
				CCmdUI * pCmdUI = (CCmdUI *)pExtra;
				ASSERT( pCmdUI != NULL );
				pCmdUI->Enable();
			}
			return TRUE;
		}

		if( nID == IDC_CHECK_SHOW_GRIPPER ) {
			if( nCode == CN_COMMAND ){
				bool bDlgButtonChecked = ( IsDlgButtonChecked( nID ) == BST_CHECKED );
				m_wndToolBarColor.SetBarStyle( 
					bDlgButtonChecked
					? m_wndToolBarColor.GetBarStyle() |  CBRS_GRIPPER 
					: m_wndToolBarColor.GetBarStyle() & ~CBRS_GRIPPER 
					);
				m_wndToolBarPalette.SetBarStyle( 
					bDlgButtonChecked
					? m_wndToolBarPalette.GetBarStyle() |  CBRS_GRIPPER 
					: m_wndToolBarPalette.GetBarStyle() & ~CBRS_GRIPPER 
					);
				m_wndToolBar.SetBarStyle( 
					bDlgButtonChecked
					? m_wndToolBar.GetBarStyle() |  CBRS_GRIPPER 
					: m_wndToolBar.GetBarStyle() & ~CBRS_GRIPPER 
					);
				m_wndMenuBar.SetBarStyle( 
					bDlgButtonChecked
					? m_wndMenuBar.GetBarStyle() |  CBRS_GRIPPER 
					: m_wndMenuBar.GetBarStyle() & ~CBRS_GRIPPER 
					);
				m_wndToolBarControls1.SetBarStyle( 
					bDlgButtonChecked
					? m_wndToolBarControls1.GetBarStyle() |  CBRS_GRIPPER 
					: m_wndToolBarControls1.GetBarStyle() & ~CBRS_GRIPPER 
					);
				m_wndToolBarControls2.SetBarStyle( 
					bDlgButtonChecked
					? m_wndToolBarControls2.GetBarStyle() |  CBRS_GRIPPER 
					: m_wndToolBarControls2.GetBarStyle() & ~CBRS_GRIPPER 
					);
				_Update();
			}
		}

		if( m_wndToolBarColor.GetSafeHwnd() != NULL )
		{
			INT nBtnHeight = 0;
			switch( nID )
			{
			case ID_HEIGHT_8PX: nBtnHeight = 8; break;
			case ID_HEIGHT_10PX: nBtnHeight = 10; break;
			case ID_HEIGHT_12PX: nBtnHeight = 12; break;
			case ID_HEIGHT_14PX: nBtnHeight = 14; break;
			case ID_HEIGHT_16PX: nBtnHeight = 16; break;
			case ID_HEIGHT_18PX: nBtnHeight = 18; break;
			case ID_HEIGHT_20PX: nBtnHeight = 20; break;
			case ID_HEIGHT_22PX: nBtnHeight = 22; break;
			case ID_HEIGHT_24PX: nBtnHeight = 24; break;
			case ID_HEIGHT_26PX: nBtnHeight = 26; break;
			case ID_HEIGHT_28PX: nBtnHeight = 28; break;
			case ID_HEIGHT_30PX: nBtnHeight = 30; break;
			} // switch( nID )

			if( nBtnHeight != 0 )
			{
				if( nCode == CN_UPDATE_COMMAND_UI )
				{
					CCmdUI * pCmdUI = (CCmdUI *)pExtra;
					ASSERT( pCmdUI != NULL );
					pCmdUI->Enable();
					pCmdUI->SetRadio(
						(m_nThinColorBtnHeight == nBtnHeight) ? TRUE : FALSE
						);
				}
				else
				{
					if( m_nThinColorBtnHeight != nBtnHeight  )
					{
						m_nThinColorBtnHeight = nBtnHeight;
						CWnd::RepositionBars(0,0xFFFF,0);
						m_wndToolBarColor.RedrawWindow();
					}
				}
				return TRUE;
			}

			INT nColorCmdIndex =
				m_wndToolBarColor.CommandToIndex( nID );
			if( nColorCmdIndex >= 0 )
			{
				if( nCode == CN_UPDATE_COMMAND_UI )
				{
					CCmdUI * pCmdUI = (CCmdUI *)pExtra;
					ASSERT( pCmdUI != NULL );
					pCmdUI->Enable();
				}
				else
				{
					CWinApp * pApp = ::AfxGetApp();
					ASSERT( pApp != NULL );
					CExtCmdItem * pCmdItem =
						g_CmdManager->CmdGetPtr(
							_T("PageToolbars"),
							nID
							);
					ASSERT( pCmdItem != NULL );
					CString sMsg;
					sMsg.Format(
						_T("Command from the color toolbar:\n\n%s"),
						pCmdItem->m_sMenuText
						);
					::AfxMessageBox( LPCTSTR(sMsg) );
				}
				return TRUE;
			}
		}
	}
	return CPageBase::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
Пример #2
0
/**
 * Show context menu and handle user selection.
 */
void CLocationView::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	if (point.x == -1 && point.y == -1)
	{
		//keystroke invocation
		CRect rect;
		GetClientRect(rect);
		ClientToScreen(rect);

		point = rect.TopLeft();
		point.Offset(5, 5);
	}

	CRect rc;
	CPoint pt = point;
	GetClientRect(rc);
	ScreenToClient(&pt);
	BCMenu menu;
	VERIFY(menu.LoadMenu(IDR_POPUP_LOCATIONBAR));
	theApp.TranslateMenu(menu.m_hMenu);

	BCMenu* pPopup = (BCMenu *) menu.GetSubMenu(0);
	ASSERT(pPopup != NULL);

	CCmdUI cmdUI;
	cmdUI.m_pMenu = pPopup;
	cmdUI.m_nIndexMax = cmdUI.m_pMenu->GetMenuItemCount();
	for (cmdUI.m_nIndex = 0 ; cmdUI.m_nIndex < cmdUI.m_nIndexMax ; ++cmdUI.m_nIndex)
	{
		cmdUI.m_nID = cmdUI.m_pMenu->GetMenuItemID(cmdUI.m_nIndex);
		switch (cmdUI.m_nID)
		{
		case ID_DISPLAY_MOVED_NONE:
			cmdUI.SetRadio(m_displayMovedBlocks == DISPLAY_MOVED_NONE);
			break;
		case ID_DISPLAY_MOVED_ALL:
			cmdUI.SetRadio(m_displayMovedBlocks == DISPLAY_MOVED_ALL);
			break;
		case ID_DISPLAY_MOVED_FOLLOW_DIFF:
			cmdUI.SetRadio(m_displayMovedBlocks == DISPLAY_MOVED_FOLLOW_DIFF);
			break;
		}
	}

	CString strItem;
	CString strNum;
	int nLine = -1;
	int bar = IsInsideBar(rc, pt);

	// If cursor over bar, format string with linenumber, else disable item
	if (bar != BAR_NONE)
	{
		// If outside bar area use left bar
		if (bar == BAR_YAREA)
			bar = BAR_LEFT;
		nLine = GetLineFromYPos(pt.y, bar);
		strNum.Format(_T("%d"), nLine + 1); // Show linenumber not lineindex
	}
	else
		pPopup->EnableMenuItem(ID_LOCBAR_GOTODIFF, MF_GRAYED);
	LangFormatString1(strItem, ID_LOCBAR_GOTOLINE_FMT, strNum);
	pPopup->SetMenuText(ID_LOCBAR_GOTODIFF, strItem, MF_BYCOMMAND);

	// invoke context menu
	// we don't want to use the main application handlers, so we use flags TPM_NONOTIFY | TPM_RETURNCMD
	// and handle the command after TrackPopupMenu
	int command = pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_NONOTIFY  | TPM_RETURNCMD, point.x, point.y, AfxGetMainWnd());

	CMergeDoc* pDoc = GetDocument();
	switch (command)
	{
	case ID_LOCBAR_GOTODIFF:
		m_view[MERGE_VIEW_LEFT]->GotoLine(nLine, true, bar);
	if (bar == BAR_LEFT || bar == BAR_RIGHT)
		m_view[bar]->SetFocus();
		break;
	case ID_EDIT_WMGOTO:
		m_view[MERGE_VIEW_LEFT]->WMGoto();
		break;
	case ID_DISPLAY_MOVED_NONE:
		SetConnectMovedBlocks(DISPLAY_MOVED_NONE);
		pDoc->SetDetectMovedBlocks(FALSE);
		break;
	case ID_DISPLAY_MOVED_ALL:
		SetConnectMovedBlocks(DISPLAY_MOVED_ALL);
		pDoc->SetDetectMovedBlocks(TRUE);
		break;
	case ID_DISPLAY_MOVED_FOLLOW_DIFF:
		SetConnectMovedBlocks(DISPLAY_MOVED_FOLLOW_DIFF);
		pDoc->SetDetectMovedBlocks(TRUE);
		break;
	}
}