Exemplo n.º 1
0
        /// <summary>
        /// Handle keys related to scrolling.
        /// </summary>
        /// <param name="key">The key to handle.</param>
        /// <returns>A value indicating whether the key was handled.</returns>
        private bool HandleScrollKeys(Key key)
        {
            ScrollViewer scrollHost = ItemsControlHelper.ScrollHost;

            if (scrollHost != null)
            {
                switch (key)
                {
                case Key.PageUp:
                    // Move horizontally if we've run out of room vertically
                    if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageLeft();
                    }
                    else
                    {
                        scrollHost.PageUp();
                    }
                    return(true);

                case Key.PageDown:
                    // Move horizontally if we've run out of room vertically
                    if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageRight();
                    }
                    else
                    {
                        scrollHost.PageDown();
                    }
                    return(true);

                case Key.Home:
                    scrollHost.ScrollToTop();
                    return(true);

                case Key.End:
                    scrollHost.ScrollToBottom();
                    return(true);

                case Key.Left:
                    scrollHost.LineLeft();
                    return(true);

                case Key.Right:
                    scrollHost.LineRight();
                    return(true);

                case Key.Up:
                    scrollHost.LineUp();
                    return(true);

                case Key.Down:
                    scrollHost.LineDown();
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private bool HandleScrollKeys(Key key)
        {
            ScrollViewer scroller = ScrollHost;

            if (scroller != null)
            {
                bool invert = (FlowDirection == FlowDirection.RightToLeft);
                switch (key)
                {
                case Key.Up:
                    scroller.LineUp();
                    return(true);

                case Key.Down:
                    scroller.LineDown();
                    return(true);

                case Key.Left:
                    if (invert)
                    {
                        scroller.LineRight();
                    }
                    else
                    {
                        scroller.LineLeft();
                    }
                    return(true);

                case Key.Right:
                    if (invert)
                    {
                        scroller.LineLeft();
                    }
                    else
                    {
                        scroller.LineRight();
                    }
                    return(true);

                case Key.Home:
                    scroller.ScrollToTop();
                    return(true);

                case Key.End:
                    scroller.ScrollToBottom();
                    return(true);

                case Key.PageUp:
                    //if vertically scrollable - go vertical, otherwise horizontal
                    if (DoubleUtil.GreaterThan(scroller.ExtentHeight, scroller.ViewportHeight))
                    {
                        scroller.PageUp();
                    }
                    else
                    {
                        scroller.PageLeft();
                    }
                    return(true);

                case Key.PageDown:
                    //if vertically scrollable - go vertical, otherwise horizontal
                    if (DoubleUtil.GreaterThan(scroller.ExtentHeight, scroller.ViewportHeight))
                    {
                        scroller.PageDown();
                    }
                    else
                    {
                        scroller.PageRight();
                    }
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // ScrollViewer を取得する
            Func<DependencyObject, ScrollViewer> getChildVisual = null;
            getChildVisual = dobj =>
            {
                if (dobj is ScrollViewer) return dobj as ScrollViewer;
                int count = VisualTreeHelper.GetChildrenCount(dobj);
                for (int i = 0; i < count; i++)
                {
                    var ret = getChildVisual(VisualTreeHelper.GetChild(dobj, i));
                    if (ret != null) return ret;
                }
                return null;
            };
            var sv = getChildVisual(TimelineTabControl);
            if (sv == null) return;

            _mainViewer = sv;
            _mainViewer.PreviewMouseWheel += (_, __) =>
                {
                    __.Handled = true;

                    if (__.Delta < 0)
                    {
                        _mainViewer.LineDown();
                    }
                    else
                    {
                        _mainViewer.LineUp();
                    }
                };

            if ((string.IsNullOrEmpty(Settings.Default.Username) || string.IsNullOrEmpty(Settings.Default.Password)) && (string.IsNullOrEmpty(Settings.Default.Token) || string.IsNullOrEmpty(Settings.Default.TokenSecret)))
            {
                SettingButton_Click(null, null);
            }
            else
            {
                // Twitter へログイン
                Login();
            }
            this.Topmost = Settings.Default.AlwaysOnTop;
            APILimitRemainText.SetBinding(TextBlock.TextProperty, new Binding("TClient.RateLimitRemain") { Source = this, FallbackValue = 0, StringFormat = "API请求剩余:\t{0}", Mode = BindingMode.OneWay, TargetNullValue = 0 });
            APILimitTotalText.SetBinding(TextBlock.TextProperty, new Binding("TClient.TotalRateLimit") { Source = this, FallbackValue = 0, StringFormat = "API请求总量:\t{0}", Mode = BindingMode.OneWay, TargetNullValue = 0 });
            APILimitResetText.SetBinding(TextBlock.TextProperty, new Binding("TClient.ResetTimeString") { Source = this, FallbackValue = 0, StringFormat = "下次重置时间:\t{0}", Mode = BindingMode.OneWay, TargetNullValue = 0 });
            //this.client.PropertyChanged+=new PropertyChangedEventHandler((Sender,eventArg)=>
            //{
            //    if (eventArg.PropertyName=="RateLimitRemain")
            //    {
            //        this.AsyncInvoke(() => { this.APILimitRemainText.Text = string.Format("API请求剩余:\t{0}", client.RateLimitRemain); });
            //    }
            //    else if (eventArg.PropertyName=="TotalRateLimit")
            //    {
            //        this.AsyncInvoke(() => { this.APILimitTotalText.Text = string.Format("API请求总量:\t{0}", client.TotalRateLimit); });
            //    }
            //    else if (eventArg.PropertyName=="ResetTimeString")
            //    {
            //        this.AsyncInvoke(() => { this.APILimitResetText.Text = string.Format("下次重置时间:\t{0}", client.ResetTimeString); });
            //    }
            //});
        }
Exemplo n.º 4
0
    private static void Scroll(ScrollViewer scrollViewer, DragEventArgs e)
    {
      if (scrollViewer != null) {
        var position = e.GetPosition(scrollViewer);
        var scrollMargin = Math.Min(scrollViewer.FontSize * 2, scrollViewer.ActualHeight / 2);

        if (position.X >= scrollViewer.ActualWidth - scrollMargin &&
            scrollViewer.HorizontalOffset < scrollViewer.ExtentWidth - scrollViewer.ViewportWidth) {
          scrollViewer.LineRight();
        } else if (position.X < scrollMargin && scrollViewer.HorizontalOffset > 0) {
          scrollViewer.LineLeft();
        } else if (position.Y >= scrollViewer.ActualHeight - scrollMargin &&
                   scrollViewer.VerticalOffset < scrollViewer.ExtentHeight - scrollViewer.ViewportHeight) {
          scrollViewer.LineDown();
        } else if (position.Y < scrollMargin && scrollViewer.VerticalOffset > 0) {
          scrollViewer.LineUp();
        }
      }
    }
Exemplo n.º 5
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown)
            {
                if (DateTime.UtcNow > lastScrollTime.AddMilliseconds(100))
                {
                    Point currentPointWin = Mouse.GetPosition(scrollViewer);
                    if (currentPointWin.Y < 16)
                    {
                        scrollViewer.LineUp();
                        scrollViewer.UpdateLayout();
                        lastScrollTime = DateTime.UtcNow;
                    }
                    if (currentPointWin.Y > scrollViewer.ActualHeight - 16)
                    {
                        scrollViewer.LineDown();
                        scrollViewer.UpdateLayout();
                        lastScrollTime = DateTime.UtcNow;
                    }
                }

                Point  currentPoint = Mouse.GetPosition(content);
                double width        = currentPoint.X - startPoint.X + 1;
                double height       = currentPoint.Y - startPoint.Y + 1;
                double left         = startPoint.X;
                double top          = startPoint.Y;

                if (isFirstMove)
                {
                    if (Math.Abs(width) <= SystemParameters.MinimumHorizontalDragDistance &&
                        Math.Abs(height) <= SystemParameters.MinimumVerticalDragDistance)
                    {
                        return;
                    }

                    isFirstMove = false;
                    if (!SelectionMultiple.IsControlKeyDown)
                    {
                        if (!treeView.ClearSelectionByRectangle())
                        {
                            EndAction();
                            return;
                        }
                    }
                }

                // Debug.WriteLine(string.Format("Drawing: {0};{1};{2};{3}",startPoint.X,startPoint.Y,width,height));
                if (width < 1)
                {
                    width = Math.Abs(width - 1) + 1;
                    left  = startPoint.X - width + 1;
                }

                if (height < 1)
                {
                    height = Math.Abs(height - 1) + 1;
                    top    = startPoint.Y - height + 1;
                }

                border.Width = width;
                Canvas.SetLeft(border, left);
                border.Height = height;
                Canvas.SetTop(border, top);

                border.Visibility = Visibility.Visible;

                double right  = left + width - 1;
                double bottom = top + height - 1;

                // Debug.WriteLine(string.Format("left:{1};right:{2};top:{3};bottom:{4}", null, left, right, top, bottom));
                SelectionMultiple selection = (SelectionMultiple)treeView.Selection;
                bool foundFocusItem         = false;
                foreach (var item in items)
                {
                    FrameworkElement itemContent = (FrameworkElement)item.Template.FindName("PART_Header", item);
                    if (itemContent == null)
                    {
                        continue;
                    }

                    Point  p          = ((FrameworkElement)itemContent.Parent).TransformToAncestor(content).Transform(new Point());
                    double itemLeft   = p.X;
                    double itemRight  = p.X + itemContent.ActualWidth - 1;
                    double itemTop    = p.Y;
                    double itemBottom = p.Y + itemContent.ActualHeight - 1;

                    // Debug.WriteLine(string.Format("element:{0};itemleft:{1};itemright:{2};itemtop:{3};itembottom:{4}",item.DataContext,itemLeft,itemRight,itemTop,itemBottom));

                    // Compute the current input states for determining the new selection state of the item
                    bool intersect       = !(itemLeft > right || itemRight <left || itemTop> bottom || itemBottom < top);
                    bool initialSelected = initialSelection != null && initialSelection.Contains(item.DataContext);
                    bool ctrl            = SelectionMultiple.IsControlKeyDown;

                    // Decision matrix:
                    // If the Ctrl key is pressed, each intersected item will be toggled from its initial selection.
                    // Without the Ctrl key, each intersected item is selected, others are deselected.
                    //
                    // newSelected
                    // ─────────┬───────────────────────
                    //          │ intersect
                    //          │  0        │  1
                    //          ├───────────┴───────────
                    //          │ initial
                    //          │  0  │  1  │  0  │  1
                    // ─────────┼─────┼─────┼─────┼─────
                    // ctrl  0  │  0  │  0  │  1  │  1   = intersect
                    // ─────────┼─────┼─────┼─────┼─────
                    //       1  │  0  │  1  │  1  │  0   = intersect XOR initial
                    //
                    bool newSelected = intersect ^ (initialSelected && ctrl);

                    // The new selection state for this item has been determined. Apply it.
                    if (newSelected)
                    {
                        // The item shall be selected
                        if (!treeView.SelectedItems.Contains(item.DataContext))
                        {
                            // The item is not currently selected. Try to select it.
                            if (!selection.SelectByRectangle(item))
                            {
                                if (selection.LastCancelAll)
                                {
                                    EndAction();
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        // The item shall be deselected
                        if (treeView.SelectedItems.Contains(item.DataContext))
                        {
                            // The item is currently selected. Try to deselect it.
                            if (!selection.DeselectByRectangle(item))
                            {
                                if (selection.LastCancelAll)
                                {
                                    EndAction();
                                    return;
                                }
                            }
                        }
                    }

                    // Always focus and bring into view the item under the mouse cursor
                    if (!foundFocusItem &&
                        currentPoint.X >= itemLeft && currentPoint.X <= itemRight &&
                        currentPoint.Y >= itemTop && currentPoint.Y <= itemBottom)
                    {
                        FocusHelper.Focus(item, true);
                        scrollViewer.UpdateLayout();
                        foundFocusItem = true;
                    }
                }

                if (e != null)
                {
                    e.Handled = true;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handle keys related to scrolling.
        /// </summary>
        /// <param name="key">The key to handle.</param>
        /// <returns>A value indicating whether the key was handled.</returns>
        private bool HandleScrollKeys(Key key)
        {
            ScrollViewer scrollHost = ItemsControlHelper.ScrollHost;

            if (scrollHost != null)
            {
                // Some keys (e.g. Left/Right) need to be translated in RightToLeft mode
                Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, key);

                switch (invariantKey)
                {
                case Key.PageUp:
                    // Move horizontally if we've run out of room vertically
                    if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageLeft();
                    }
                    else
                    {
                        scrollHost.PageUp();
                    }
                    return(true);

                case Key.PageDown:
                    // Move horizontally if we've run out of room vertically
                    if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageRight();
                    }
                    else
                    {
                        scrollHost.PageDown();
                    }
                    return(true);

                case Key.Home:
                    scrollHost.ScrollToTop();
                    return(true);

                case Key.End:
                    scrollHost.ScrollToBottom();
                    return(true);

                case Key.Left:
                    scrollHost.LineLeft();
                    return(true);

                case Key.Right:
                    scrollHost.LineRight();
                    return(true);

                case Key.Up:
                    scrollHost.LineUp();
                    return(true);

                case Key.Down:
                    scrollHost.LineDown();
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 7
0
        // Token: 0x060058E9 RID: 22761 RVA: 0x00189730 File Offset: 0x00187930
        private bool HandleScrollKeys(Key key)
        {
            ScrollViewer scrollHost = base.ScrollHost;

            if (scrollHost != null)
            {
                bool flag = base.FlowDirection == FlowDirection.RightToLeft;
                switch (key)
                {
                case Key.Prior:
                    if (DoubleUtil.GreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageUp();
                    }
                    else
                    {
                        scrollHost.PageLeft();
                    }
                    return(true);

                case Key.Next:
                    if (DoubleUtil.GreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageDown();
                    }
                    else
                    {
                        scrollHost.PageRight();
                    }
                    return(true);

                case Key.End:
                    scrollHost.ScrollToBottom();
                    return(true);

                case Key.Home:
                    scrollHost.ScrollToTop();
                    return(true);

                case Key.Left:
                    if (flag)
                    {
                        scrollHost.LineRight();
                    }
                    else
                    {
                        scrollHost.LineLeft();
                    }
                    return(true);

                case Key.Up:
                    scrollHost.LineUp();
                    return(true);

                case Key.Right:
                    if (flag)
                    {
                        scrollHost.LineLeft();
                    }
                    else
                    {
                        scrollHost.LineRight();
                    }
                    return(true);

                case Key.Down:
                    scrollHost.LineDown();
                    return(true);
                }
            }
            return(false);
        }