/////////////////////////////////////////////////////////////////////////////// // MODULE PanelManagement // PURPOSE Some functions shared by all panels. // Just insert the following in all your panel callbacks // case EVENT_KEYPRESS: // HandlePanelDefaultKeys(panel, eventData1); // break; /////////////////////////////////////////////////////////////////////////////// #include #include #include "PanelManagement.h" /////////////////////////////////////////////////////////////////////////////// // FUNCTION HandlePanelDefaultKeys /// HIFN Handle function keys common between panels /// HIPAR panel/handle of the calling panel /// HIPAR eventData1/In case of EVENT_KEYPRESS /////////////////////////////////////////////////////////////////////////////// void HandlePanelDefaultKeys(int panel, int eventData1) { switch (eventData1) { // Use [Ctrl][Shift][->] or Ctrl-] to navigate to the next panel case VAL_SHIFT_AND_MENUKEY | VAL_LEFT_ARROW_VKEY: case VAL_MENUKEY_MODIFIER | '[': ShowPreviousPanel(panel); break; // Use [Ctrl][Shift][<-] or Ctrl-[ to navigate to the previous panel case VAL_SHIFT_AND_MENUKEY | VAL_RIGHT_ARROW_VKEY: case VAL_MENUKEY_MODIFIER | ']': ShowNextPanel(panel); break; // Use [Ctrl][P] to print the current panel case VAL_MENUKEY_MODIFIER | 'P': PrintPanel (panel, "", 1, VAL_VISIBLE_AREA, 1); break; // Use [Ctrl][0] to center the current panel case VAL_MENUKEY_MODIFIER | '0': CenterPanel(panel); break; } } /////////////////////////////////////////////////////////////////////////////// // FUNCTION: ShowPreviousPanel // PURPOSE: Move to the previous visible panel with the same parent /////////////////////////////////////////////////////////////////////////////// void ShowPreviousPanel(int panel) { int Next, Parent, First, Visible, Current=-1; GetPanelAttribute (panel, ATTR_PANEL_PARENT, &Parent); GetPanelAttribute (Parent, ATTR_FIRST_CHILD, &First); Next=First; do { GetPanelAttribute (Next, ATTR_VISIBLE, &Visible); if (Visible) Current=Next; GetPanelAttribute (Next, ATTR_NEXT_PANEL, &Next); if (Next==0) Next=First; } while (Next!=panel or Current<0); // SetPanelAttribute (Next, ATTR_ZPLANE_POSITION, 0); SetActivePanel(Current); } /////////////////////////////////////////////////////////////////////////////// // FUNCTION: ShowNextPanel // PURPOSE: Move to the next visible panel with the same parent /////////////////////////////////////////////////////////////////////////////// void ShowNextPanel(int panel) { int Next, Parent, Visible; Next=panel; do { GetPanelAttribute (Next, ATTR_NEXT_PANEL, &Next); if (Next==0) { GetPanelAttribute (panel, ATTR_PANEL_PARENT, &Parent); GetPanelAttribute (Parent, ATTR_FIRST_CHILD, &Next); } GetPanelAttribute (Next, ATTR_VISIBLE, &Visible); } while (!Visible); // SetPanelAttribute (Next, ATTR_ZPLANE_POSITION, 0); SetActivePanel(Next); } /////////////////////////////////////////////////////////////////////////////// // FUNCTION: CenterPanel // PURPOSE: Center the panel in the closest monitor /////////////////////////////////////////////////////////////////////////////// void CenterPanel(int panel) { int Monitor, Top, Left, Height, Width, PanelWidth, PanelHeight; GetMonitorFromPanel(panel, &Monitor); GetMonitorAttribute(Monitor, ATTR_TOP, &Top); GetMonitorAttribute(Monitor, ATTR_LEFT, &Left); GetMonitorAttribute(Monitor, ATTR_WIDTH, &Width); GetMonitorAttribute(Monitor, ATTR_HEIGHT, &Height); GetPanelAttribute(panel, ATTR_WIDTH, &PanelWidth); GetPanelAttribute(panel, ATTR_HEIGHT, &PanelHeight); SetPanelPos (panel, Top+(Height-PanelHeight)/2, Left+(Width-PanelWidth)/2); }