public void KeyDown(Control c, KeyEventArgs e)
{
ViewBase newView = null;
Keys keyData = e.KeyData;
// When there is no selected tab then tab and shift+tab become right and left
if (_ribbon.SelectedTab == null)
{
if (keyData == Keys.Tab)
keyData = Keys.Right;
if (keyData == (Keys.Tab | Keys.Shift))
keyData = Keys.Left;
}
switch (keyData)
{
case Keys.Right:
// Get the next visible tab page
newView = _target.ViewLayoutRibbonTabs.GetViewForNextRibbonTab(_target.RibbonTab);
// Move across to any far defined buttons
if (newView == null)
newView = _ribbon.TabsArea.ButtonSpecManager.GetFirstVisibleViewButton(PaletteRelativeEdgeAlign.Far);
// Move across to any inherit defined buttons
if (newView == null)
newView = _ribbon.TabsArea.ButtonSpecManager.GetFirstVisibleViewButton(PaletteRelativeEdgeAlign.Inherit);
// Rotate around to application button
if (newView == null)
{
if (_ribbon.TabsArea.LayoutAppButton.Visible)
newView = _ribbon.TabsArea.LayoutAppButton.AppButton;
else if (_ribbon.TabsArea.LayoutAppTab.Visible)
newView = _ribbon.TabsArea.LayoutAppTab.AppTab;
}
break;
case Keys.Left:
// Get the previous visible tab page
newView = _target.ViewLayoutRibbonTabs.GetViewForPreviousRibbonTab(_target.RibbonTab);
// Move across to any near defined buttons
if (newView == null)
newView = _ribbon.TabsArea.ButtonSpecManager.GetFirstVisibleViewButton(PaletteRelativeEdgeAlign.Near);
// Get the last qat button
if (newView == null)
newView = _ribbon.GetLastQATView();
// Rotate around to application button
if (newView == null)
{
if (_ribbon.TabsArea.LayoutAppButton.Visible)
newView = _ribbon.TabsArea.LayoutAppButton.AppButton;
else if (_ribbon.TabsArea.LayoutAppTab.Visible)
newView = _ribbon.TabsArea.LayoutAppTab.AppTab;
}
break;
case Keys.Tab | Keys.Shift:
// Move across to any near defined buttons
newView = _ribbon.TabsArea.ButtonSpecManager.GetFirstVisibleViewButton(PaletteRelativeEdgeAlign.Near);
// Get the last qat button
if (newView == null)
newView = _ribbon.GetLastQATView();
// Rotate around to application button
if (newView == null)
{
if (_ribbon.TabsArea.LayoutAppButton.Visible)
newView = _ribbon.TabsArea.LayoutAppButton.AppButton;
else if (_ribbon.TabsArea.LayoutAppTab.Visible)
newView = _ribbon.TabsArea.LayoutAppTab.AppTab;
}
break;
case Keys.Down:
// Get the first focus item for the currently selected page
newView = _ribbon.GroupsArea.ViewGroups.GetFirstFocusItem();
break;
case Keys.Tab:
// Get the first focus item for the currently selected page
newView = _ribbon.GroupsArea.ViewGroups.GetFirstFocusItem();
// Move across to any near defined buttons
if (newView == null)
newView = _ribbon.TabsArea.ButtonSpecManager.GetFirstVisibleViewButton(PaletteRelativeEdgeAlign.Near);
// Get the last qat button
if (newView == null)
newView = _ribbon.GetLastQATView();
// Rotate around to application button
if (newView == null)
{
if (_ribbon.TabsArea.LayoutAppButton.Visible)
newView = _ribbon.TabsArea.LayoutAppButton.AppButton;
else if (_ribbon.TabsArea.LayoutAppTab.Visible)
newView = _ribbon.TabsArea.LayoutAppTab.AppTab;
}
break;
case Keys.Enter:
case Keys.Space:
// When minimize, pressing enter will select the tab and pop it up
if ((_ribbon.RealMinimizedMode) && (_ribbon.SelectedTab != _target.RibbonTab))
{
// Select the tab will automatically create a popup for it
_ribbon.SelectedTab = _target.RibbonTab;
// Get access to the popup for the group
if ((VisualPopupManager.Singleton.CurrentPopup != null) &&
(VisualPopupManager.Singleton.CurrentPopup is VisualPopupMinimized))
{
// Cast to correct type
VisualPopupMinimized popupMinimized = (VisualPopupMinimized)VisualPopupManager.Singleton.CurrentPopup;
popupMinimized.SetFirstFocusItem();
}
}
break;
}
// If we have a new view to focus and it is not ourself...
if ((newView != null) && (newView != _target))
{
// If the new view is a tab then select that tab
if ((newView is ViewDrawRibbonTab) && !_ribbon.RealMinimizedMode)
_ribbon.SelectedTab = ((ViewDrawRibbonTab)newView).RibbonTab;
// Finally we switch focus to new view
_ribbon.FocusView = newView;
}
}