Exemplo n.º 1
0
        /// <summary>
        /// Arranges the content of the <see cref="T:Avalonia.Controls.Primitives.DataGridColumnHeadersPresenter" />.
        /// </summary>
        /// <returns>
        /// The actual size used by the <see cref="T:Avalonia.Controls.Primitives.DataGridColumnHeadersPresenter" />.
        /// </returns>
        /// <param name="finalSize">
        /// The final area within the parent that this element should use to arrange itself and its children.
        /// </param>
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (OwningGrid == null)
            {
                return(base.ArrangeOverride(finalSize));
            }

            if (OwningGrid.AutoSizingColumns)
            {
                // When we initially load an auto-column, we have to wait for all the rows to be measured
                // before we know its final desired size.  We need to trigger a new round of measures now
                // that the final sizes have been calculated.
                OwningGrid.AutoSizingColumns = false;
                return(base.ArrangeOverride(finalSize));
            }

            double dragIndicatorLeftEdge = 0;
            double frozenLeftEdge        = 0;
            double scrollingLeftEdge     = -OwningGrid.HorizontalOffset;

            foreach (DataGridColumn dataGridColumn in OwningGrid.ColumnsInternal.GetVisibleColumns())
            {
                DataGridColumnHeader columnHeader = dataGridColumn.HeaderCell;
                Debug.Assert(columnHeader.OwningColumn == dataGridColumn);

                if (dataGridColumn.IsFrozen)
                {
                    columnHeader.Arrange(new Rect(frozenLeftEdge, 0, dataGridColumn.LayoutRoundedWidth, finalSize.Height));
                    columnHeader.Clip = null; // The layout system could have clipped this becaues it's not aware of our render transform
                    if (DragColumn == dataGridColumn && DragIndicator != null)
                    {
                        dragIndicatorLeftEdge = frozenLeftEdge + DragIndicatorOffset;
                    }
                    frozenLeftEdge += dataGridColumn.ActualWidth;
                }
                else
                {
                    columnHeader.Arrange(new Rect(scrollingLeftEdge, 0, dataGridColumn.LayoutRoundedWidth, finalSize.Height));
                    EnsureColumnHeaderClip(columnHeader, dataGridColumn.ActualWidth, finalSize.Height, frozenLeftEdge, scrollingLeftEdge);
                    if (DragColumn == dataGridColumn && DragIndicator != null)
                    {
                        dragIndicatorLeftEdge = scrollingLeftEdge + DragIndicatorOffset;
                    }
                }
                scrollingLeftEdge += dataGridColumn.ActualWidth;
            }
            if (DragColumn != null)
            {
                if (DragIndicator != null)
                {
                    EnsureColumnReorderingClip(DragIndicator, finalSize.Height, frozenLeftEdge, dragIndicatorLeftEdge);

                    var height = DragIndicator.Bounds.Height;
                    if (height <= 0)
                    {
                        height = DragIndicator.DesiredSize.Height;
                    }

                    DragIndicator.Arrange(new Rect(dragIndicatorLeftEdge, 0, DragIndicator.Bounds.Width, height));
                }
                if (DropLocationIndicator != null)
                {
                    if (DropLocationIndicator is Control element)
                    {
                        EnsureColumnReorderingClip(element, finalSize.Height, frozenLeftEdge, DropLocationIndicatorOffset);
                    }

                    DropLocationIndicator.Arrange(new Rect(DropLocationIndicatorOffset, 0, DropLocationIndicator.Bounds.Width, DropLocationIndicator.Bounds.Height));
                }
            }

            // Arrange filler
            OwningGrid.OnFillerColumnWidthNeeded(finalSize.Width);
            DataGridFillerColumn fillerColumn = OwningGrid.ColumnsInternal.FillerColumn;

            if (fillerColumn.FillerWidth > 0)
            {
                fillerColumn.HeaderCell.IsVisible = true;
                fillerColumn.HeaderCell.Arrange(new Rect(scrollingLeftEdge, 0, fillerColumn.FillerWidth, finalSize.Height));
            }
            else
            {
                fillerColumn.HeaderCell.IsVisible = false;
            }

            // This needs to be updated after the filler column is configured
            DataGridColumn lastVisibleColumn = OwningGrid.ColumnsInternal.LastVisibleColumn;

            if (lastVisibleColumn != null)
            {
                lastVisibleColumn.HeaderCell.UpdateSeparatorVisibility(lastVisibleColumn);
            }
            return(finalSize);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Measures the children of a <see cref="T:Avalonia.Controls.Primitives.DataGridColumnHeadersPresenter" /> to
        /// prepare for arranging them during the <see cref="M:System.Windows.FrameworkElement.ArrangeOverride(System.Windows.Size)" /> pass.
        /// </summary>
        /// <param name="availableSize">
        /// The available size that this element can give to child elements. Indicates an upper limit that child elements should not exceed.
        /// </param>
        /// <returns>
        /// The size that the <see cref="T:Avalonia.Controls.Primitives.DataGridColumnHeadersPresenter" /> determines it needs during layout, based on its calculations of child object allocated sizes.
        /// </returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            if (OwningGrid == null)
            {
                return(base.MeasureOverride(availableSize));
            }
            if (!OwningGrid.AreColumnHeadersVisible)
            {
                return(Size.Empty);
            }
            double height = OwningGrid.ColumnHeaderHeight;
            bool   autoSizeHeight;

            if (double.IsNaN(height))
            {
                // No explicit height values were set so we can autosize
                height         = 0;
                autoSizeHeight = true;
            }
            else
            {
                autoSizeHeight = false;
            }

            double totalDisplayWidth = 0;

            OwningGrid.ColumnsInternal.EnsureVisibleEdgedColumnsWidth();
            DataGridColumn lastVisibleColumn = OwningGrid.ColumnsInternal.LastVisibleColumn;

            foreach (DataGridColumn column in OwningGrid.ColumnsInternal.GetVisibleColumns())
            {
                // Measure each column header
                bool autoGrowWidth = column.Width.IsAuto || column.Width.IsSizeToHeader;
                DataGridColumnHeader columnHeader = column.HeaderCell;
                if (column != lastVisibleColumn)
                {
                    columnHeader.UpdateSeparatorVisibility(lastVisibleColumn);
                }

                // If we're not using star sizing or the current column can't be resized,
                // then just set the display width according to the column's desired width
                if (!OwningGrid.UsesStarSizing || (!column.ActualCanUserResize && !column.Width.IsStar))
                {
                    // In the edge-case where we're given infinite width and we have star columns, the
                    // star columns grow to their predefined limit of 10,000 (or their MaxWidth)
                    double newDisplayWidth = column.Width.IsStar ?
                                             Math.Min(column.ActualMaxWidth, DataGrid.DATAGRID_maximumStarColumnWidth) :
                                             Math.Max(column.ActualMinWidth, Math.Min(column.ActualMaxWidth, column.Width.DesiredValue));
                    column.SetWidthDisplayValue(newDisplayWidth);
                }

                // If we're auto-growing the column based on the header content, we want to measure it at its maximum value
                if (autoGrowWidth)
                {
                    columnHeader.Measure(new Size(column.ActualMaxWidth, double.PositiveInfinity));
                    OwningGrid.AutoSizeColumn(column, columnHeader.DesiredSize.Width);
                    column.ComputeLayoutRoundedWidth(totalDisplayWidth);
                }
                else if (!OwningGrid.UsesStarSizing)
                {
                    column.ComputeLayoutRoundedWidth(totalDisplayWidth);
                    columnHeader.Measure(new Size(column.LayoutRoundedWidth, double.PositiveInfinity));
                }

                // We need to track the largest height in order to auto-size
                if (autoSizeHeight)
                {
                    height = Math.Max(height, columnHeader.DesiredSize.Height);
                }
                totalDisplayWidth += column.ActualWidth;
            }

            // If we're using star sizing (and we're not waiting for an auto-column to finish growing)
            // then we will resize all the columns to fit the available space.
            if (OwningGrid.UsesStarSizing && !OwningGrid.AutoSizingColumns)
            {
                double adjustment = Double.IsPositiveInfinity(availableSize.Width) ? OwningGrid.CellsWidth : availableSize.Width - totalDisplayWidth;
                totalDisplayWidth += adjustment - OwningGrid.AdjustColumnWidths(0, adjustment, false);

                // Since we didn't know the final widths of the columns until we resized,
                // we waited until now to measure each header
                double leftEdge = 0;
                foreach (DataGridColumn column in OwningGrid.ColumnsInternal.GetVisibleColumns())
                {
                    column.ComputeLayoutRoundedWidth(leftEdge);
                    column.HeaderCell.Measure(new Size(column.LayoutRoundedWidth, double.PositiveInfinity));
                    if (autoSizeHeight)
                    {
                        height = Math.Max(height, column.HeaderCell.DesiredSize.Height);
                    }
                    leftEdge += column.ActualWidth;
                }
            }

            // Add the filler column if it's not represented.  We won't know whether we need it or not until Arrange
            DataGridFillerColumn fillerColumn = OwningGrid.ColumnsInternal.FillerColumn;

            if (!fillerColumn.IsRepresented)
            {
                Debug.Assert(!Children.Contains(fillerColumn.HeaderCell));
                fillerColumn.HeaderCell.AreSeparatorsVisible = false;
                Children.Insert(OwningGrid.ColumnsInternal.Count, fillerColumn.HeaderCell);
                fillerColumn.IsRepresented = true;
                // Optimize for the case where we don't need the filler cell
                fillerColumn.HeaderCell.IsVisible = false;
            }
            fillerColumn.HeaderCell.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            if (DragIndicator != null)
            {
                DragIndicator.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            }
            if (DropLocationIndicator != null)
            {
                DropLocationIndicator.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            }

            OwningGrid.ColumnsInternal.EnsureVisibleEdgedColumnsWidth();
            return(new Size(OwningGrid.ColumnsInternal.VisibleEdgedColumnsWidth, height));
        }
Exemplo n.º 3
0
        public void Init()
        {
            EmailList.AddNewEmailAddress      += EmailList_AddNewEmailAddress;
            EmailTreeList.SelectedNodeChanged += EmailTree_SelectedNodeChanged;
            MessagesGrid.SelectionMode         = DataGridSelectionMode.Single;
            SmallToolBarWideButton removeButton = new SmallToolBarWideButton("Usuń");

            removeButton.Click += (s, ea) =>
            {
                EmailModel email = (EmailModel)EmailTreeList.SelectedNode.ChildObject;

                DisplayedMessage message = (DisplayedMessage)MessagesGrid.SelectedItem;

                if (message != null)
                {
                    int index = MessagesGrid.SelectedIndex;

                    email.UnhandledMessages.Remove(message.Message);
                    ObservableCollection <DisplayedMessage> messages =
                        (ObservableCollection <DisplayedMessage>)MessagesGrid.ItemsSource;

                    messages.Remove(message);

                    MessagesGrid.ItemsSource = messages;
                    MessagesGrid.Items.Refresh();

                    _client.HandleMessage(email.Id, message.Message.UId.ToString());

                    MessagesGrid.SelectedIndex = index == 0 ? index : index - 1;

                    if (MessagesGrid.Items.Count == 0)
                    {
                        MessagesGrid.Visibility    = Visibility.Collapsed;
                        NoMessagesLabel.Visibility = Visibility.Visible;

                        MessageContainer.Visibility        = Visibility.Collapsed;
                        MessageDetailsContainer.Visibility = Visibility.Collapsed;
                    }
                }

                _parent.NewEmailAddress += _parent_NewEmailAddress;
            };

            SmallToolBarWideButton removeFromServerButton = new SmallToolBarWideButton("Usuń całkowicie");

            removeFromServerButton.Click += (s, ea) =>
            {
                EmailModel email = (EmailModel)EmailTreeList.SelectedNode.ChildObject;

                DisplayedMessage message = (DisplayedMessage)MessagesGrid.SelectedItem;

                if (message != null)
                {
                    message.Message.Remove();

                    int index = MessagesGrid.SelectedIndex;

                    email.UnhandledMessages.Remove(message.Message);
                    ObservableCollection <DisplayedMessage> messages =
                        (ObservableCollection <DisplayedMessage>)MessagesGrid.ItemsSource;

                    messages.Remove(message);

                    MessagesGrid.ItemsSource = messages;
                    MessagesGrid.Items.Refresh();

                    _client.HandleMessage(email.Id, message.Message.UId.ToString());

                    MessagesGrid.SelectedIndex = index == 0 ? index : index - 1;
                }

                if (MessagesGrid.Items.Count == 0)
                {
                    MessagesGrid.Visibility    = Visibility.Collapsed;
                    NoMessagesLabel.Visibility = Visibility.Visible;

                    MessageContainer.Visibility        = Visibility.Collapsed;
                    MessageDetailsContainer.Visibility = Visibility.Collapsed;
                }
            };

            MessageDetailsMenuStrip.Children.Add(removeButton);

            MessageDetailsContainer.Visibility = Visibility.Collapsed;
            MessageDetailsMenuStrip.Children.Add(removeFromServerButton);

            ConversationList.DisplayItemContextMenus = false;

            _dragIndicator = new DragIndicator();
            _dragAddCursor = new Cursor(new FileStream("../../resources/addMessage_cursor.cur", FileMode.Open));


            _messageWorker.WorkerSupportsCancellation = true;
            _messageWorker.DoWork             += MessageWorker_DoWork;
            _messageWorker.RunWorkerCompleted += MessageWorker_RunWorkerCompleted;

            Unloaded += Email_Unloaded;

            _parent = (MainWindow)Window.GetWindow(this);
            _client = _parent.Client;

            if (_parent.EmailClients != null)
            {
                _emailClients = _parent.EmailClients;
                LoadFolders(_emailClients);
            }

            _parent.EmailWorker.RunWorkerCompleted += _emailWorker_RunWorkerCompleted;

            if (_parent.ConversationWorker.IsBusy)
            {
                _parent.ConversationWorker.RunWorkerCompleted += ConversationWorker_RunWorkerCompleted;
            }
            else
            {
                if (_parent.Conversations != null)
                {
                    _conversations = _parent.Conversations;
                    LoadConversations();
                }
            }

            MessagesGrid.Items.IsLiveSorting = true;
            // MessagesGrid.SelectionMode = DataGridSelectionMode.Extended;


            MessagesGrid.PreviewMouseLeftButtonDown += MessagesGrid_PreviewMouseLeftButtonDown;
            MessagesGrid.GiveFeedback += MessagesGrid_GiveFeedback;

            _processingWorker.DoWork += _processingWorker_DoWork;

            ConversationList.AllowDrop = true;

            WindowInitialized = true;
        }