Ejemplo n.º 1
0
        /* XXX: Uncomment when ximian bug #81343 is closed and usable.
         * protected override void OnActivate ()
         * {
         *      foreach (IPlot plot in plots)
         *      {
         *              plot.UnselectAll ();
         *      }
         *
         *      foreach (IPlot plot in plots)
         *      {
         *              if (plot.HasFocus) {
         *                      int x, y;
         *                      plot.GetFocusedPoint (axes, out x, out y);
         *                      plot.SelectPoint (axes, x, y);
         *                      break;
         *              }
         *      }
         * }
         */

        protected override bool OnFocused(DirectionType dir)
        {
            if (plots.Count < 1)
            {
                return(false);
            }

            if (!HasFocus)
            {
                GrabFocus();
                return(true);
            }

            int visits;
            int focused_x = -1, focused_y = -1;

            switch (dir)
            {
            case DirectionType.Left:
                ((IPlot)plots[focused_plot_index]).FocusPrev();
                return(true);

            case DirectionType.Right:
                ((IPlot)plots[focused_plot_index]).FocusNext();
                return(true);

            case DirectionType.Up:
                // Don't move selection if there is only one
                // plot
                if (plots.Count <= 1)
                {
                    return(true);
                }

                // get the currently focused point
                ((IPlot)plots[focused_plot_index]).GetFocusedPoint(out focused_x,
                                                                   out focused_y);

                // Iterate through the plots in the zorder,
                // looking for the next plot which CanFocus.
                // Also, make sure we don't see plots twice, or
                // infinite loop.
                visits = 0;
                do
                {
                    // move to the next plot in the z-order
                    focused_plot_index--;
                    if (focused_plot_index < 0)
                    {
                        focused_plot_index = plots.Count - 1;
                    }

                    visits++;

                    IPlot plot = (IPlot)plots[focused_plot_index];
                    if (!plot.CanFocus)
                    {
                        continue;
                    }

                    // clear focus on all the plots
                    foreach (IPlot p in plots)
                    {
                        if (p.HasFocus)
                        {
                            p.ReleaseFocus();
                        }
                    }

                    // focus the nearest to the last
                    // focused point
                    plot.FocusNearest(focused_x, focused_y);
                    break;
                } while (visits <= plots.Count);

                return(true);

            case DirectionType.Down:
                // Don't move selection if there is only one
                // plot
                if (plots.Count <= 1)
                {
                    return(true);
                }

                // get the currently focused point
                ((IPlot)plots[focused_plot_index]).GetFocusedPoint(out focused_x,
                                                                   out focused_y);

                // Iterate through the plots in the zorder,
                // looking for the next plot which CanFocus.
                // Also, make sure we don't see plots more than
                // once, or worse, infinite loop.
                visits = 0;
                do
                {
                    // move to the previous plot in the z-order
                    focused_plot_index++;
                    if (focused_plot_index >= plots.Count)
                    {
                        focused_plot_index = 0;
                    }


                    visits++;

                    IPlot plot = (IPlot)plots[focused_plot_index];
                    if (!plot.CanFocus)
                    {
                        continue;
                    }

                    // clear focus on all the plots
                    foreach (IPlot p in plots)
                    {
                        if (p.HasFocus)
                        {
                            p.ReleaseFocus();
                        }
                    }

                    // focus the nearest to the last
                    // focused point
                    plot.FocusNearest(focused_x, focused_y);
                    break;
                } while (visits <= plots.Count);

                return(true);

            case DirectionType.TabForward:
            default:
                // let focus jump to the next widget
                return(false);
            }
        }