| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- /*************************************************************************************
- Extended WPF Toolkit
- Copyright (C) 2007-2013 Xceed Software Inc.
- This program is provided to you under the terms of the Microsoft Public
- License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
- For more features, controls, and fast professional support,
- pick up the Plus Edition at http://xceed.com/wpf_toolkit
- Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
- ***********************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Collections.ObjectModel;
- using System.Windows.Controls;
- using System.Windows.Input;
- using Xceed.Wpf.AvalonDock.Layout;
- using System.Reflection;
- using System.Diagnostics;
- namespace Xceed.Wpf.AvalonDock.Controls
- {
- public class LayoutAnchorableTabItem : Control
- {
- static LayoutAnchorableTabItem()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(LayoutAnchorableTabItem), new FrameworkPropertyMetadata(typeof(LayoutAnchorableTabItem)));
- }
- public LayoutAnchorableTabItem()
- {
- }
- #region Model
- /// <summary>
- /// Model Dependency Property
- /// </summary>
- public static readonly DependencyProperty ModelProperty =
- DependencyProperty.Register("Model", typeof(LayoutContent), typeof(LayoutAnchorableTabItem),
- new FrameworkPropertyMetadata((LayoutContent)null,
- new PropertyChangedCallback(OnModelChanged)));
- /// <summary>
- /// Gets or sets the Model property. This dependency property
- /// indicates model attached to the anchorable tab item.
- /// </summary>
- public LayoutContent Model
- {
- get { return (LayoutContent)GetValue(ModelProperty); }
- set { SetValue(ModelProperty, value); }
- }
- /// <summary>
- /// Handles changes to the Model property.
- /// </summary>
- private static void OnModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutAnchorableTabItem)d).OnModelChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the Model property.
- /// </summary>
- protected virtual void OnModelChanged(DependencyPropertyChangedEventArgs e)
- {
- if (Model != null)
- SetLayoutItem(Model.Root.Manager.GetLayoutItemFromModel(Model));
- else
- SetLayoutItem(null);
- //UpdateLogicalParent();
- }
- #endregion
- #region LayoutItem
- /// <summary>
- /// LayoutItem Read-Only Dependency Property
- /// </summary>
- private static readonly DependencyPropertyKey LayoutItemPropertyKey
- = DependencyProperty.RegisterReadOnly("LayoutItem", typeof(LayoutItem), typeof(LayoutAnchorableTabItem),
- new FrameworkPropertyMetadata((LayoutItem)null));
- public static readonly DependencyProperty LayoutItemProperty
- = LayoutItemPropertyKey.DependencyProperty;
- /// <summary>
- /// Gets the LayoutItem property. This dependency property
- /// indicates the LayoutItem attached to this tag item.
- /// </summary>
- public LayoutItem LayoutItem
- {
- get { return (LayoutItem)GetValue(LayoutItemProperty); }
- }
- /// <summary>
- /// Provides a secure method for setting the LayoutItem property.
- /// This dependency property indicates the LayoutItem attached to this tag item.
- /// </summary>
- /// <param name="value">The new value for the property.</param>
- protected void SetLayoutItem(LayoutItem value)
- {
- SetValue(LayoutItemPropertyKey, value);
- }
- #endregion
- bool _isMouseDown = false;
- static LayoutAnchorableTabItem _draggingItem = null;
- internal static bool IsDraggingItem()
- {
- return _draggingItem != null;
- }
- internal static LayoutAnchorableTabItem GetDraggingItem()
- {
- return _draggingItem;
- }
- internal static void ResetDraggingItem()
- {
- _draggingItem = null;
- }
- protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
- {
- base.OnMouseLeftButtonDown(e);
- _isMouseDown = true;
- _draggingItem = this;
- }
- protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
- {
- base.OnMouseMove(e);
- if (e.LeftButton != MouseButtonState.Pressed)
- {
- _isMouseDown = false;
- _draggingItem = null;
- }
- }
- protected override void OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)
- {
- _isMouseDown = false;
- base.OnMouseLeftButtonUp(e);
- Model.IsActive = true;
- }
- protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
- {
- base.OnMouseLeave(e);
- if (_isMouseDown && e.LeftButton == MouseButtonState.Pressed)
- {
- _draggingItem = this;
- }
- _isMouseDown = false;
- }
- protected override void OnMouseEnter(MouseEventArgs e)
- {
- base.OnMouseEnter(e);
- if (_draggingItem != null &&
- _draggingItem != this &&
- e.LeftButton == MouseButtonState.Pressed)
- {
- //Trace.WriteLine("Dragging item from {0} to {1}", _draggingItem, this);
- var model = Model;
- var container = model.Parent as ILayoutContainer;
- var containerPane = model.Parent as ILayoutPane;
- var childrenList = container.Children.ToList();
- containerPane.MoveChild(childrenList.IndexOf(_draggingItem.Model), childrenList.IndexOf(model));
- }
- }
- protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
- {
- base.OnPreviewGotKeyboardFocus(e);
- }
- }
- }
|