Beispiel #1
0
        /// <summary>
        /// 保存--遍历树结构
        /// </summary>
        /// <param name="item_first"></param>
        /// <param name="mySheet"></param>
        /// <param name="p_rowNum"></param>
        /// <param name="p_level"></param>
        /// <returns></returns>
        private int getchildValue(TreeListViewItem item_first, Excel.Worksheet mySheet, int p_rowNum, int p_level)
        {
            int    rowNum = p_rowNum + 1;
            string sp     = "";

            for (int i = 0; i < item_first.SubItems.Count; i++)
            {
                if (i == 0)
                {
                    for (int k = 1; k < p_level; k++)
                    {
                        sp += "  ";
                    }
                    mySheet.Cells[rowNum, i + 1] = sp + item_first.SubItems[i].Text;
                }
                else
                {
                    mySheet.Cells[rowNum, i + 1] = item_first.SubItems[i].Text;
                }
            }
            for (int j = 0; j < item_first.Items.Count; j++)
            {
                rowNum = getchildValue(item_first.Items[j], mySheet, rowNum, p_level + 1);
            }
            return(rowNum);
        }
Beispiel #2
0
        public void LoadChildren(TreeListViewItem node, string fsFullPath, bool Recursive = false)
        {
            try
            {
                string[] strChildren = Directory.GetDirectories(fsFullPath + "\\");
                if (strChildren.LongLength > 0)
                {
                    node.SubItems[Columns.Count + 1].Text = "1";
                }
                foreach (string strChild in strChildren)
                {
                    AddFolder(node, strChild, Recursive);
                }
            }
            catch { }

            try
            {
                string[] strChildren = Directory.GetFiles(fsFullPath + "\\");
                if (node.SubItems[Columns.Count + 1].Text == "0")
                {
                    node.SubItems[Columns.Count + 1].Text = strChildren.LongLength > 0 ? "1" : "-1";
                }
                foreach (string strChild in strChildren)
                {
                    AddFile(node, strChild);
                }
            }
            catch { }

            // 排序
            //try { node.Items.Sort(Recursive); }
            //catch { }
        }
Beispiel #3
0
        public void AddFolder(TreeListViewItem node, string fsFullPath, bool Recursive = false)
        {
            try
            {
                DirectoryInfo    diChild = new DirectoryInfo(fsFullPath);
                TreeListViewItem ndChild = new TreeListViewItem(diChild.Name);
                node.Items.Add(ndChild);
                if (node.CheckStatus != CheckState.Indeterminate)
                {
                    ndChild.Checked = node.Checked;
                }
                Apq.DllImports.Shell32.SHFILEINFO shFolderInfo = new DllImports.Shell32.SHFILEINFO();
                Apq.Windows.Forms.IconChache.GetFileSystemIcon(fsFullPath, ref shFolderInfo);
                ndChild.ImageKey = "文件夹收起";
                ndChild.SubItems.Add("0");
                ndChild.SubItems.Add(Apq.GlobalObject.UILang["文件夹"]);
                ndChild.SubItems.Add(diChild.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"));
                ndChild.SubItems.Add(diChild.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"));

                ndChild.SubItems.Add(diChild.FullName);
                ndChild.SubItems.Add("0");
                ndChild.SubItems.Add("2");                //类型{1:Drive,2:Folder,3:File}

                if (Recursive)
                {
                    LoadChildren(ndChild, ndChild.FullPath, Recursive);
                }
            }
            catch { }
        }
        private void _treeView_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if (_treeView.SelectedItems.Count > 0)
                {
                    TreeListViewItem node = _treeView.SelectedItems[0];
                    YmlItem          item = (YmlItem)node.Tag;

                    TreeListViewItem preNode  = getSameLevelPreNode(node, node);
                    bool             isenable = false;
                    if (preNode != null)
                    {
                        isenable = true;
                    }
                    else
                    {
                        TreeListViewItem nextNode = getSameLevelNextNode(node, node);
                        if (nextNode != null)
                        {
                            isenable = true;
                        }
                    }
                    降级ToolStripMenuItem.Enabled = isenable;
                    升级ToolStripMenuItem.Enabled = item.Level > 0;
                }
            }
        }
Beispiel #5
0
        // 选择选中类型的数据库
        private void tsmiSelect_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem tsmi = sender as ToolStripMenuItem;

            if (tsmi != null)
            {
                tsmi.Checked = !tsmi.Checked;

                // 获取类型值
                int DBIType = Apq.Convert.ChangeType <int>(tsmi.Tag, -1);

                DataView dv = new DataView(dsDBC.DBI);
                dv.RowFilter = "DBIType = " + DBIType;
                if (DBIType == 0)
                {
                    dv.RowFilter = dv.RowFilter + " OR DBIType IS NULL";
                }

                foreach (DataRowView drv in dv)
                {
                    string           strDBIID = Apq.Convert.ChangeType <string>(drv["DBIID"]);
                    TreeListViewItem node     = tlvHelper.FindNodeByKey(strDBIID);
                    node.Checked = tsmi.Checked;
                }
            }
        }
        private void 降级ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_treeView.SelectedItems.Count > 0)
            {
                TreeListViewItem node = _treeView.SelectedItems[0];
                YmlItem          item = (YmlItem)node.Tag;

                TreeListViewItem preNode = getSameLevelPreNode(node, node);
                if (preNode != null)
                {
                    node.Parent.Items.Remove(node);
                    preNode.Items.Add(node);

                    item.Level            = item.Level + 1;
                    item.Parent           = (YmlItem)preNode.Tag;
                    node.SubItems[2].Text = "" + item.Level;
                }
                else
                {
                    TreeListViewItem nextNode = getSameLevelNextNode(node, node);
                    if (nextNode != null)
                    {
                        node.Parent.Items.Remove(node);
                        nextNode.Items.Add(node);

                        item.Level            = item.Level + 1;
                        item.Parent           = (YmlItem)nextNode.Tag;
                        node.SubItems[2].Text = "" + item.Level;
                    }
                }
            }
            btn_save.Enabled = true;
        }
        private void 升级ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_treeView.SelectedItems.Count > 0)
            {
                TreeListViewItem node = _treeView.SelectedItems[0];
                YmlItem          item = (YmlItem)node.Tag;
                if (node.Parent != null && item.Level > 0)
                {
                    TreeListViewItem parentNode = node.Parent;
                    YmlItem          parentItem = (YmlItem)parentNode.Tag;

                    node.Parent.Items.Remove(node);
                    if (parentNode.Parent == null)
                    {
                        _treeView.Items.Add(node);
                    }
                    else
                    {
                        parentNode.Parent.Items.Add(node);
                    }

                    item.Level  = parentItem.Level;
                    item.Parent = parentItem.Parent;

                    node.SubItems[2].Text = "" + item.Level;
                }
            }
            btn_save.Enabled = true;
        }
        private void 添加顶级节点ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            TreeListViewItem viewItem = new TreeListViewItem();
            YmlItem          obj      = new YmlItem()
            {
                Key        = "",
                Value      = "",
                Level      = 0,
                Common     = "",
                Uuid       = Guid.NewGuid().ToString("N"),
                ImageIndex = 3,
                Parent     = null,
                SpcCount   = 0
            };

            viewItem.Tag        = obj;
            viewItem.Text       = obj.Key;
            viewItem.ImageIndex = obj.ImageIndex;

            viewItem.SubItems.Add(obj.Value);
            viewItem.SubItems.Add("" + obj.Level);
            viewItem.SubItems.Add(obj.Common);

            _treeView.Items.Add(viewItem);

            YmlNodeForm form = new YmlNodeForm(viewItem, null, null, 2);

            form.ShowDialog(this);
            btn_save.Enabled = true;
        }
Beispiel #9
0
        void fsw_Created(object sender, FileSystemEventArgs e)
        {
            Apq.Windows.Delegates.Action_UI <FSExplorer>(this, this, delegate(FSExplorer ctrl)
            {
                try
                {
                    TreeListViewItem ndFolder = null;
                    string strFolder          = e.FullPath;

                    strFolder = Path.GetDirectoryName(e.FullPath);
                    ndFolder  = tlvHelper.FindNodeByFullPath(strFolder);
                    if (ndFolder != null)
                    {
                        // 首次加载时Load,否则Add
                        int HasChildren = Apq.Convert.ChangeType <int>(ndFolder.SubItems[Columns.Count + 1].Text);
                        if (HasChildren == 0)
                        {
                            LoadChildren(ndFolder, strFolder, false);
                        }
                        else
                        {
                            if (File.Exists(e.FullPath))
                            {
                                AddFile(ndFolder, e.FullPath);
                            }
                            else if (Directory.Exists(e.FullPath))
                            {
                                AddFolder(ndFolder, e.FullPath, false);
                            }
                        }
                    }
                }
                catch { }
            });
        }
Beispiel #10
0
        /// <summary>
        /// 插入产品结构
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStructInsert_Click(object sender, EventArgs e)
        {
            //1.找到插入的节点的位置
            PDM_STRUCT       t_struct = new PDM_STRUCT();
            TreeListViewItem item = this.list_productTreeStruct.Items[0];
            int count = 0; int index = 0;

            for (int i = 0; i < item.Items.Count; i++)
            {
                if (item.Items[i].CheckStatus == CheckState.Checked)
                {
                    count++;
                    index = i;
                }
            }
            if (count != 1)
            {
                MessageBox.Show("只能选择一条记录且子结构无法更改!");
                return;
            }
            t_struct.OBJECTID    = this.m_product.PRODUCTID;
            t_struct.ASSOBJECTID = item.Items[index].Tag.ToString();

            //2.打开产品添加界面传递(产品对象,关联对象ID,操作类型--插入)参数
            ProductsStructAddForm o = new ProductsStructAddForm(this.m_product, t_struct.ASSOBJECTID, Enum_AssOpType.INSERT);

            o.StartPosition = FormStartPosition.CenterParent;
            o.ShowDialog();

            //3.清空产品结构树,并重新构造树
            this.list_productTreeStruct.Items.Clear();
            list_productTreeStruct_init();
        }
Beispiel #11
0
 /// <summary>
 /// 改变行背景色
 /// </summary>
 /// <param name="item"></param>
 /// <param name="c"></param>
 private void changeColor(TreeListViewItem item, Color c)
 {
     for (int j = 0; j < item.SubItems.Count; j++)
     {
         item.SubItems[j].BackColor = c;
     }
 }
Beispiel #12
0
        private void treeListView1_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.TreeListView TreeListView = (System.Windows.Forms.TreeListView)sender;
            try
            {
                this.Cursor = PubStaticFun.WaitCursor();
                TreeListViewItem item = (TreeListViewItem)TreeListView.SelectedItems[0];

                int id  = item.ImageIndex == 0 ? 0 : Convert.ToInt32(item.Tag);
                int pid = item.ImageIndex == 0 ? Convert.ToInt32(item.Tag) : 0;

                string Event  = item.Text;
                int    finish = this.radioButton1.Checked == true ? 0 : 1;
                handle.GetEventlog(id, pid, this.dateTimePicker1.Value.ToString("yyyy-MM-dd").ToString() + " 00:00:00",
                                   this.dateTimePicker2.Value.ToString("yyyy-MM-dd").ToString() + " 23:59:59", txtevent.Text.Trim(), txtbizid.Text.Trim(), false, finish, this.dgveventlog);
            }
            catch (System.Exception err)
            {
                MessageBox.Show(err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
Beispiel #13
0
        /// <summary>
        /// 初始化树列表子节点
        /// </summary>
        /// <param name="node"></param>
        /// <param name="p_objectId"></param>
        private void treeCreater(TreeListViewItem node, string p_objectId)
        {
            DataTable dt_parts = m_StructService.GetStructPartList(p_objectId);
            int       len      = dt_parts.Rows.Count;

            for (int i = 0; i < len; i++)
            {
                TreeListViewItem item = new TreeListViewItem(dt_parts.Rows[i]["PRODUCTNO"].ToString(), 0);
                node.Items.Add(item);
                //item.Expand();
                item.SubItems.Add(dt_parts.Rows[i]["VERSION"].ToString());
                item.SubItems.Add(dt_parts.Rows[i]["ASSONUM"].ToString());
                item.SubItems.Add(dt_parts.Rows[i]["MODELTYPE"].ToString());
                item.SubItems.Add(dt_parts.Rows[i]["SORTNUM"].ToString());
                item.SubItems.Add(dt_parts.Rows[i]["MEMO"].ToString());
                item.Tag = dt_parts.Rows[i]["ASSOBJECTID"].ToString();
                treeCreater(item, dt_parts.Rows[i]["ASSOBJECTID"].ToString());
            }

            DataTable dt_Materail = m_StructService.GetStructMaterailList(p_objectId);
            int       len2        = dt_Materail.Rows.Count;

            for (int i = 0; i < len2; i++)
            {
                TreeListViewItem item = new TreeListViewItem(dt_Materail.Rows[i]["MATERIALNO"].ToString(), 0);
                node.Items.Add(item);
                // item.Expand();
                item.SubItems.Add(dt_Materail.Rows[i]["VERSION"].ToString());
                item.SubItems.Add(dt_Materail.Rows[i]["ASSONUM"].ToString());
                item.SubItems.Add(dt_Materail.Rows[i]["MODELTYPE"].ToString());
                item.SubItems.Add(dt_Materail.Rows[i]["SORTNUM"].ToString());
                item.Tag = dt_Materail.Rows[i]["ASSOBJECTID"].ToString();
                item.SubItems.Add(dt_Materail.Rows[i]["MEMO"].ToString());
            }
        }
        private void excludeFromProjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (solutionExplorerTreeView.SelectedItems.Count > 0)
            {
                TreeListViewItem[] selectedItems = new TreeListViewItem[0];
                Array.Resize <TreeListViewItem>(ref selectedItems, solutionExplorerTreeView.SelectedItems.Count);
                solutionExplorerTreeView.SelectedItems.CopyTo(selectedItems, 0);

                foreach (TreeListViewItem tlvi in selectedItems)
                {
                    ILuaEditDocument doc = tlvi.Tag as ILuaEditDocument;

                    if (doc != null && doc.ParentDocument != null)
                    {
                        ILuaEditDocument currentDoc = doc;

                        while (!(currentDoc.ParentDocument is ILuaEditDocumentProject))
                        {
                            currentDoc = currentDoc.ParentDocument;
                        }

                        doc.ParentDocument.RemoveDocument(doc);
                    }
                }
            }
        }
Beispiel #15
0
        public void ChangeFolder(TreeListViewItem node)
        {
            DirectoryInfo diFolder = new DirectoryInfo(node.FullPath);

            node.Text             = diFolder.Name;
            node.SubItems[3].Text = diFolder.CreationTime.ToString("yyyy-MM-dd HH:mm:ss");
            node.SubItems[4].Text = diFolder.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
        }
Beispiel #16
0
        /// <summary>
        /// 初始化树列表根节点
        /// </summary>
        private void list_productTreeStruct_init()
        {
            TreeListViewItem root = new TreeListViewItem(this.m_product.PRODUCTNO, 0);

            root.Expand(); root.SubItems.Add(this.m_product.VERSION);
            this.list_productTreeStruct.Items.Add(root);
            treeCreater(root, this.m_product.PRODUCTID);
        }
Beispiel #17
0
 /// <summary>
 /// 切换指定节点下级的选中状态
 /// </summary>
 public static void ChgCheckedParentNodes(TreeListViewItem node)
 {
     if (node.Parent != null)
     {
         node.Parent.Checked = !node.Parent.Checked;
         ChgCheckedParentNodes(node.Parent);
     }
 }
Beispiel #18
0
 /// <summary>
 /// 设置指定节点上级的选中状态
 /// </summary>
 public static void SetCheckedParentNodes(TreeListViewItem node, bool Checked)
 {
     if (node.Parent != null)
     {
         node.Parent.Checked = Checked;
         SetCheckedParentNodes(node.Parent, Checked);
     }
 }
Beispiel #19
0
 /// <summary>
 /// 设置指定节点下级的选中状态
 /// </summary>
 public static void SetCheckedChildNodes(TreeListViewItem node, bool Checked)
 {
     foreach (TreeListViewItem tln in node.Items)
     {
         tln.Checked = Checked;
         SetCheckedChildNodes(tln, Checked);
     }
 }
Beispiel #20
0
 /// <summary>
 /// 切换指定节点下级的选中状态
 /// </summary>
 public static void ChgCheckedChildNodes(TreeListViewItem node)
 {
     foreach (TreeListViewItem tln in node.Items)
     {
         tln.Checked = !tln.Checked;
         ChgCheckedChildNodes(tln);
     }
 }
Beispiel #21
0
 private void SubUpdateDictionary(TreeListViewItem tn, ref Dictionary <string, TreeListViewItem> dictTreeNode)
 {
     dictTreeNode.Add(tn.Name, tn);
     foreach (TreeListViewItem tnChild in tn.Items)
     {
         SubUpdateDictionary(tnChild, ref dictTreeNode);
     }
 }
        private TreeListViewItem GetTreeListViewItem(Priv _res)
        {
            TreeListViewItem _child = new TreeListViewItem(_res.Name, 5);

            _child.SubItems.AddRange(new string[] { _res.Id, _res.Description });
            _child.Tag = _res;
            return(_child);
        }
Beispiel #23
0
 private void AddLuaVariablesToItem(TreeListViewItem item, LuaVariable[] vars)
 {
     foreach (LuaVariable luaVar in vars)
     {
         TreeListViewItem tlvi = LuaVariableToTreeListViewItem(luaVar);
         item.Items.Add(tlvi);
     }
 }
Beispiel #24
0
        private static bool isValidEditableLog(TreeListViewItem item)
        {
            if (item.Parent != null)
            {
                return(false);
            }

            return(true);
        }
        private void Tasks_TasksRowDeleting(Tasks.TaskChangeEventArgs e)
        {
            TreeListViewItem node = FindTaskNode(e.Task.Id);

            if (node != null && node.ListView != null)
            {
                node.Remove();
            }
        }
        private TreeListViewItem GetChildSamelevelNode(TreeListViewItem currentItem, TreeListViewItem childItem)
        {
            while (currentItem.Level != childItem.Level)
            {
                childItem = childItem.NextVisibleItem;
            }

            return(childItem);
        }
        private TreeListViewItem GetParentSamelevelNode(TreeListViewItem currentItem, TreeListViewItem parentItem)
        {
            while (currentItem.Level != parentItem.Level)
            {
                parentItem = parentItem.Parent;
            }

            return(parentItem);
        }
        public void LoadTree()
        {
            treeView.Items.Clear();
            TreeListViewItem nodeParent = CreateNode(Tasks.RootTask);

            this.treeView.Items.Add(nodeParent);
            AddChildNodes(Tasks.RootTask, nodeParent);
            nodeParent.Expand();
        }
Beispiel #29
0
        public virtual void ToTreeListViewItem(TreeListViewItem parentItem)
        {
            int imageIndex        = DocumentFactory.Instance.GetDocumentSmallImageIndex(this.DocumentType);
            TreeListViewItem node = new TreeListViewItem(this, imageIndex);

            node.ToolTip = _fileName;
            node.Tag     = this;
            parentItem.Items.Add(node);
        }
Beispiel #30
0
        /// <summary>m
        /// 构造树根节点
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="p_productId"></param>
        private void treeRootCreate(TreeListView tree, string p_productId, string name)
        {
            TreeListViewItem root = new TreeListViewItem(name, 0);

            root.Expand();
            tree.Items.Add(root);
            treeChildCreate(root, p_productId);
            // this.list_productTreeStruct;
        }
Beispiel #31
0
        private void DecideDropTarget(DragEventArgs e)
        {
            int targetItemsControlCount = this.targetItemsControl.Items.Count;
            object draggedItem = e.Data.GetData(this.format.Name);

            Visual visual = e.OriginalSource as Visual;

            targetOverItem = DranDropUtilities.FindAncestor(typeof(TreeListViewItem), visual) as TreeListViewItem;
            if (targetOverItem == null)
            {
                this.targetItemContainer = null;
                this.insertionIndex = -1;
                e.Effects = DragDropEffects.None;
                return;
            }

            bool newDragOverNote = false;
            OutlinerNote dragOverNote = null;
            if (targetOverItem != null)
            {
                dragOverNote = targetOverItem.DataContext as OutlinerNote;
                if (dragOverNote != null)
                {
                    if (__DragOverNote != dragOverNote)
                    {
                        if (__DragOverNote != null)
                            __DragOverNote.DragOverNote = false;

                        newDragOverNote = true;
                    }
                }
            }

            ItemsControl parentItemsControl = targetOverItem.ParentItemsControl;
            if (parentItemsControl == null)
            {
                this.targetItemContainer = null;
                this.insertionIndex = -1;
                e.Effects = DragDropEffects.None;
                return;
            }

            if (targetItemsControlCount > 0)
            {
                this.hasVerticalOrientation = DranDropUtilities.HasVerticalOrientation(this.targetItemsControl.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement);
                this.targetItemContainer = parentItemsControl;
                this.insertionIndex = parentItemsControl.ItemContainerGenerator.IndexFromContainer(targetOverItem);
                if (this.insertionIndex == -1)
                {
                    this.targetItemContainer = null;
                    this.insertionIndex = -1;
                    e.Effects = DragDropEffects.None;
                    return;
                }

                if (IsParent(this.targetItemContainer as TreeListViewItem, this.sourceItemContainer))
                {
                    this.targetItemContainer = null;
                    this.insertionIndex = -1;
                    e.Effects = DragDropEffects.None;
                    return;
                }

                if (newDragOverNote && dragOverNote != null)
                {
                    dragOverNote.DragOverNote = true;
                    __DragOverNote = dragOverNote;
                }
            }
            else
            {
                this.targetItemContainer = null;
                this.insertionIndex = 0;
            }
        }
Beispiel #32
0
 /// <summary>
 /// Get SubItem rectangle
 /// </summary>
 /// <param name="item"></param>
 /// <param name="column"></param>
 /// <returns></returns>
 public Rectangle GetSubItemRect(TreeListViewItem item, int column)
 {
     ListViewItem lvitem = (ListViewItem) item;
     return GetSubItemRect(lvitem.Index, column);
 }
Beispiel #33
0
        private void treeView_DragOver(object sender, DragEventArgs e)
        {
            // Compute drag position and move image
            Point formP = this.PointToClient(new Point(e.X, e.Y));
            ImageList_DragMove(formP.X - this.treeView.Left, formP.Y - this.treeView.Top);

            // Get actual drop node
            TreeListViewItem dropNode = this.treeView.GetItemAt(this.treeView.PointToClient(new Point(e.X, e.Y)));
            if (dropNode == null)
            {
                e.Effect = DragDropEffects.None;
                return;
            }

            e.Effect = DragDropEffects.Move;

            // if mouse is on a new node select it
            if (this.tempDropNode != dropNode)
            {
                ImageList_DragShowNolock(false);

                if (tempDropNode != null)
                {
                    this.treeView.Refresh();
                }
                dropNode.DrawInsertionLine();

                ImageList_DragShowNolock(true);
                tempDropNode = dropNode;
            }

            // Avoid that drop node is child of drag node
            TreeListViewItem tmpNode = dropNode;
            while (tmpNode.Parent != null)
            {
                if (tmpNode.Parent == this.dragNode) e.Effect = DragDropEffects.None;
                tmpNode = tmpNode.Parent;
            }
        }
 /// <summary>
 /// Returns true if this collection contains an item
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public virtual bool Contains(TreeListViewItem item)
 {
     //			if(TreeListView != null)
     //				if(TreeListView.InvokeRequired)
     //					throw(new Exception("Invoke required"));
     bool res = false;
     foreach(TreeListViewItem elt in this)
         if(item == elt)
         {
             res = true;
             break;
         }
     return(res);
 }
 /// <summary>
 /// Create a new instance of TreeListViewCancelEvent arguments
 /// </summary>
 /// <param name="item"></param>
 /// <param name="action"></param>
 public TreeListViewCancelEventArgs(TreeListViewItem item, TreeListViewAction action)
     : base(item, action)
 {
 }
 /// <summary>
 /// Returns true if the specified item is in the collection
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Contains(TreeListViewItem item)
 {
     return(base.Contains((ListViewItem) item));
 }
Beispiel #37
0
 /// <summary>
 /// Raises the KeyDown event
 /// </summary>
 /// <param name="e"></param>
 protected override void OnKeyDown(KeyEventArgs e)
 {
     Keys key = e.KeyCode;
         if(FocusedItem == null)
         {
             if(base.Items.Count > 0 &&
                 (key == Keys.Down || key == Keys.Up || key == Keys.Left || key == Keys.Right))
             {
                 base.Items[0].Selected = true;
                 base.Items[0].Focused = true;
                 base.Items[0].EnsureVisible();
             }
             base.OnKeyDown(e);
             return;
         }
         TreeListViewItem item = FocusedItem;
         switch(key)
         {
             case Keys.Down:
                 if(item.NextVisibleItem != null)
                 {
                     TreeListViewItem nextitem = item.NextVisibleItem;
                     if((Control.ModifierKeys & Keys.Shift) == Keys.Shift &&
                         MultiSelect)
                     {
                         if(item.Parent != nextitem.Parent && item.Selected)
                         {
                             while((nextitem = nextitem.NextVisibleItem) != null)
                                 if(nextitem.Parent == item.Parent)
                                     break;
                         }
                         if(nextitem != null)
                             SetSelectedItemsRange(_selectionMark, nextitem);
                         else
                             nextitem = item.NextVisibleItem;
                     }
                     else if((Control.ModifierKeys & Keys.Control) != Keys.Control)
                     {
                         SetSelectedItemsRange(nextitem, nextitem);
                         _selectionMark = nextitem;
                     }
                     nextitem.Focused = true;
                     nextitem.EnsureVisible();
                 }
                 break;
             case Keys.Up:
                 if(item.PrevVisibleItem != null)
                 {
                     TreeListViewItem previtem = item.PrevVisibleItem;
                     if((Control.ModifierKeys & Keys.Shift) == Keys.Shift &&
                         MultiSelect)
                     {
                         if(item.Parent != previtem.Parent && item.Selected)
                         {
                             while((previtem = previtem.PrevVisibleItem) != null)
                                 if(previtem.Parent == item.Parent)
                                     break;
                         }
                         if(previtem != null)
                             SetSelectedItemsRange(_selectionMark, previtem);
                         else
                             previtem = item.PrevVisibleItem;
                     }
                     else if((Control.ModifierKeys & Keys.Control) != Keys.Control)
                     {
                         SetSelectedItemsRange(previtem, previtem);
                         _selectionMark = previtem;
                     }
                     previtem.Focused = true;
                     previtem.EnsureVisible();
                 }
                 break;
             case Keys.Enter:
                 base.SelectedItems.Clear();
                 if(item.IsExpanded) item.Collapse();
                 else item.Expand();
                 item.Selected = true;
                 item.EnsureVisible();
                 break;
             case Keys.Left:
                 if(item.IsExpanded)
                 {
                     base.SelectedItems.Clear();
                     item.Selected = true;
                     item.Collapse();
                     item.EnsureVisible();
                 }
                 else if(item.Parent != null)
                 {
                     base.SelectedItems.Clear();
                     item.Parent.Selected = true;
                     item.Parent.Focused = true;
                     item.Parent.EnsureVisible();
                 }
                 break;
             case Keys.Right:
                 if(item.Items.Count == 0) break;
                 if(!item.IsExpanded)
                 {
                     base.SelectedItems.Clear();
                     item.Selected = true;
                     item.Expand();
                     item.EnsureVisible();
                 }
                 else
                 {
                     base.SelectedItems.Clear();
                     item.Items[item.Items.Count-1].Selected = true;
                     item.Items[item.Items.Count-1].Focused = true;
                     item.Items[item.Items.Count-1].EnsureVisible();
                 }
                 break;
             case Keys.Space:
                 if(base.CheckBoxes) item.Checked = !item.Checked;
                 break;
         }
         base.OnKeyDown(e);
 }
 /// <summary>
 /// Gets the index of an item in the collection
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public int GetIndexOf(TreeListViewItem item)
 {
     //			if(TreeListView != null)
     //				if(TreeListView.InvokeRequired)
     //					throw(new Exception("Invoke required"));
     int index = -1;
     for(int i = 0 ; i < this.Count ; i++)
         if(this[i] == item) {index = i; break;}
     return(index);
 }
 private bool ListViewContains(TreeListViewItem item)
 {
     if(TreeListView == null) return(false);
     //			if(TreeListView.InvokeRequired)
     //				throw(new Exception("Invoke required"));
     ListView listview = (ListView) TreeListView;
     ListViewItem listviewitem = (ListViewItem) item;
     //			try{
     //				foreach(ListViewItem temp in listview.Items)
     //					if(temp == listviewitem) return(true);}
     //			catch{}
     //			return(false);
     return listview.Items.Contains(listviewitem);
 }
 private int GetInsertTreeListViewIndex(TreeListViewItem item, int collectionindex)
 {
     if(TreeListView == null) return(-1);
     //			if(TreeListView.InvokeRequired)
     //				throw(new Exception("Invoke required"));
     if(Owner != null)
         {
             int a = 0;
             a++;
         }
     int index = -1;
     // First level item (no parent)
     if(Owner != null && collectionindex != -1)
     {
         if(collectionindex == 0) index = 0;
         else index =
                  this[collectionindex - 1].LastChildIndexInListView + 1;
     }
     else if(Parent != null && collectionindex != -1)
     {
         if(!Parent.Visible || !Parent.IsExpanded) index = -1;
         else
         {
             if(collectionindex == 0) index = Parent.Index + 1;
             else index =
                      Parent.Items[collectionindex - 1].LastChildIndexInListView + 1;
         }
     }
     return(index);
 }
 /// <summary>
 /// Create a collection within a TreeListViewItem
 /// </summary>
 /// <param name="parent"></param>
 public TreeListViewItemCollection(TreeListViewItem parent)
 {
     _parent = parent;
 }
 /// <summary>
 /// Adds an item in the collection and in the TreeListView
 /// </summary>
 /// <param name="item"></param>
 /// <returns>Index of the item in the collection</returns>
 public virtual TreeListViewItem Insert(int index, TreeListViewItem item)
 {
     //			if(TreeListView != null)
     //				if(TreeListView.InvokeRequired)
     //					throw(new Exception("Invoke required"));
     // Do not add the item if the collection owns a TreeListView recursively
     // and the item already owns a TreeListView
     if(TreeListView != null && item.ListView != null)
         throw(new Exception("The Item is already in a TreeListView"));
     //int index = GetInsertCollectionIndex(item);
     //if(index == -1) return(-1);
     if(Parent != null) item.SetParent(Parent);
     item.Items.Comparer = this.Comparer;
     int treelistviewindex = GetInsertTreeListViewIndex(item, index);
     // Insert in the ListView
     if(treelistviewindex > -1)
     {
         ListView listview = (ListView) TreeListView;
         listview.Items.Insert(treelistviewindex, (ListViewItem) item);
         if(item.IsExpanded) item.Expand();
         item.SetIndentation();
     }
     // Insert in this collection
     if(index > -1) List.Insert(index, item);
     if(index > -1) OnItemAdded(new TreeListViewEventArgs(item, TreeListViewAction.Unknown));
     if(Count == 1 && TreeListView != null && Parent != null)
         if(Parent.Visible) Parent.Redraw();
     return(item);
 }
Beispiel #43
0
        private void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.sourceItemsControl = (ItemsControl)sender;
            TreeListView tlv = (TreeListView)this.sourceItemsControl;

            this.topWindow = (Window)DranDropUtilities.FindAncestor(typeof(Window), this.sourceItemsControl);
            this.initialMousePosition = e.GetPosition(this.topWindow);

            Visual visual = e.OriginalSource as Visual;

            this.sourceItemContainer = DranDropUtilities.GetItemContainer(this.sourceItemsControl, visual);
            if (this.sourceItemContainer != null)
                this.draggedData = sourceItemContainer.DataContext;
        }
Beispiel #44
0
        /// <summary>
        /// WndProc
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref Message m)
        {
            #region View messages
            /*if(false)
            {
                string val;
                val = Enum.GetName(typeof(APIsEnums.ListViewMessages), (APIsEnums.ListViewMessages) m.Msg);
                if(val != "" && val != null)
                    Debug.WriteLine(val);
                else
                {
                    val = Enum.GetName(typeof(APIsEnums.WindowMessages), (APIsEnums.WindowMessages) m.Msg);
                    if(val != "" && val != null)
                    Debug.WriteLine(val);
                }
                if(val != "" && val != null)
                    Debug.WriteLine(m.Msg.ToString(CultureInfo.InvariantCulture));
                if(val == "LBUTTONDOWN")
                {
                    int a= 0;
                    a++;
                }
            }*/
            #endregion

            TreeListViewItem item = null; Rectangle rec;
            switch((APIsEnums.WindowMessages) m.Msg)
            {
                #region NOTIFY
                case APIsEnums.WindowMessages.NOTIFY:
                case (APIsEnums.WindowMessages) APIsEnums.ReflectedMessages.NOTIFY:
                    APIsStructs.NMHDR nmhdr = (APIsStructs.NMHDR) m.GetLParam(typeof(APIsStructs.NMHDR));
                    //APIsStructs.NMHEADER nmheader =(APIsStructs.NMHEADER) m.GetLParam(typeof(APIsStructs.NMHEADER));
                    switch((APIsEnums.ListViewNotifications) nmhdr.code)
                    {
                        #region APIsEnums.ListViewNotifications.MARQUEEBEGIN
                        case APIsEnums.ListViewNotifications.MARQUEEBEGIN:
                            if((MouseButtons & MouseButtons.Left) != MouseButtons.Left)
                                m.Result = (IntPtr)1;
                            else
                                _hasMarquee = true;
                            break;
                        #endregion
                        #region APIsEnums.ListViewNotifications.ITEMCHANGING
                        case APIsEnums.ListViewNotifications.ITEMCHANGING:
                            APIsStructs.NMLISTVIEW nmlistview = (APIsStructs.NMLISTVIEW) m.GetLParam(typeof(APIsStructs.NMLISTVIEW));
                            if(nmlistview.iItem < 0) break;
                            if((item = GetTreeListViewItemFromIndex(nmlistview.iItem)) == null) break;
                            bool cancel = false;
                            if(nmlistview.Select)
                            {
                                if(_selectionMark == null) _selectionMark = item;
                                else if(!_selectionMark.Visible) _selectionMark = item;
                                if(HasMarquee) item.Focused = true;
                            }
                            else if(nmlistview.UnSelect && HasMarquee)
                            {
                                if(item.NextVisibleItem != null)
                                    if(item.NextVisibleItem.Selected)
                                        item.NextVisibleItem.Focused = true;
                                if(item.PrevVisibleItem != null)
                                    if(item.PrevVisibleItem.Selected)
                                        item.PrevVisibleItem.Focused = true;
                            }
                            #region Select after dbl click
                            // Disable the selection after a double click (normaly, if the control scrolls after
                            // a collapse, the new item under the cursor is automatically selected...)
                            if(_dblclicktime.AddMilliseconds(500).CompareTo(DateTime.Now) > 0 &&
                                (nmlistview.Select || nmlistview.Focus) &&
                                FocusedItem != item)
                                cancel = true;
                            #endregion
                            #region Wrong Level Select
                            if(((APIsEnums.ListViewItemStates)nmlistview.uNewState & APIsEnums.ListViewItemStates.SELECTED) == APIsEnums.ListViewItemStates.SELECTED &&
                                MultiSelect)
                                if(SelectedIndices.Count > 0)
                                    if(GetTreeListViewItemFromIndex(nmlistview.iItem).Parent != SelectedItems[0].Parent)
                                        cancel = true;
                            #endregion
                            #region Check during selection
                            // Disable check boxes check when :
                            // - the Marquee selection tool is being used
                            // - the Ctrl or Shift keys are down
                            bool state = (nmlistview.uChanged & (uint)APIsEnums.ListViewItemFlags.STATE) == (uint)APIsEnums.ListViewItemFlags.STATE;
                            bool ctrlKeyDown = (ModifierKeys & Keys.Control) == Keys.Control;
                            bool shiftKeyDown = (ModifierKeys & Keys.Shift) == Keys.Shift;
                            if((nmlistview.Check || nmlistview.UnCheck) &&
                                (HasMarquee || ctrlKeyDown || shiftKeyDown))
                            {
            //									MessageBox.Show(this,
            //										"uChanged = " + nmlistview->uChanged.ToString(CultureInfo.InvariantCulture) + "\n\n" +
            //										"uOld = " + nmlistview->uOldState.ToString(CultureInfo.InvariantCulture) + "\n" +
            //										"uNew = " + nmlistview->uChanged.ToString(CultureInfo.InvariantCulture) + "\n\n" +
            //										"OldCheck : " + (oldCheck ? "true" : "false") + "\n" +
            //										"NewCheck : " + (newCheck ? "true" : "false"));
                                cancel = true;
                            }
                            #endregion
                            if (_dragging)
                                cancel=true;
                            if(cancel)
                            {
                                m.Result = (IntPtr)1;
                                return;
                            }
                            break;
                        #endregion

                        #region APIsEnums.ListViewNotifications.BEGINLABELEDIT
                        case APIsEnums.ListViewNotifications.BEGINLABELEDIT:
                            // Cancel label edit if the message is sent just after a double click
                            if(_lastdoubleclick.AddMilliseconds(450) > DateTime.Now)
                            {
                                Message canceledit = Message.Create(Handle, (int) APIsEnums.ListViewMessages.CANCELEDITLABEL, IntPtr.Zero, IntPtr.Zero);
                                WndProc(ref canceledit);
                                m.Result = (IntPtr) 1;
                                return;
                            }
                            item = _lastitemclicked.Item;
                            item.EnsureVisible();
                            // Add subitems if needed
                            while(item.SubItems.Count-1 < _lastitemclicked.ColumnIndex) item.SubItems.Add("");
                            TreeListViewBeforeLabelEditEventArgs beforeed = new TreeListViewBeforeLabelEditEventArgs(
                                FocusedItem, _lastitemclicked.ColumnIndex, item.SubItems[_lastitemclicked.ColumnIndex].Text);
                            OnBeforeLabelEdit(beforeed);
                            if(beforeed.Cancel)
                            {
                                Message canceledit = Message.Create(Handle, (int) APIsEnums.ListViewMessages.CANCELEDITLABEL, IntPtr.Zero, IntPtr.Zero);
                                WndProc(ref canceledit);
                                m.Result = (IntPtr) 1;
                                return;
                            }
                            _inedit = true;
                            // Get edit handle
                            Message mess = Message.Create(Handle, (int)APIsEnums.ListViewMessages.GETEDITCONTROL, IntPtr.Zero, IntPtr.Zero);
                            WndProc(ref mess);
                            IntPtr edithandle = mess.Result;
                            _customedit = new CustomEdit(edithandle, this, beforeed.Editor);
                            _editeditem = new EditItemInformations(
                                FocusedItem, beforeed.ColumnIndex, FocusedItem.SubItems[beforeed.ColumnIndex].Text);
                            m.Result = IntPtr.Zero;
                            return;
                        #endregion
                        #region APIsEnums.ListViewNotifications.ENDLABELEDIT
                        case APIsEnums.ListViewNotifications.ENDLABELEDIT:
                            if(_customedit != null)
                                _customedit.HideEditControl();
                            _customedit = null;
                            _inedit = false;
                            _editeditem = new EditItemInformations();
                            m.Result = IntPtr.Zero;
                            return;
                        #endregion

                        #region CUSTOMDRAW
                        case (APIsEnums.ListViewNotifications) APIsEnums.NotificationMessages.CUSTOMDRAW:
                            base.WndProc(ref m);
                            CustomDraw(ref m);
                            return;
                        #endregion

                        #region BEGINSCROLL
                        case APIsEnums.ListViewNotifications.BEGINSCROLL:
                            _updating = true;
                            break;
                        #endregion
                        #region ENDSCROLL
                        case APIsEnums.ListViewNotifications.ENDSCROLL:
                            _updating = false;
                            // Disable display bug with vertical lines (slow...)
            //							if(ShowPlusMinus)
            //							{
            //								DrawPlusMinusItemsLines();
            //								DrawPlusMinusItems();
            //							}
                            break;
                        #endregion

                        #region APIsEnums.HeaderControlNotifications.BEGINDRAG
                        case (APIsEnums.ListViewNotifications) APIsEnums.HeaderControlNotifications.BEGINDRAG:
                            APIsStructs.NMHEADER nmheader =(APIsStructs.NMHEADER) m.GetLParam(typeof(APIsStructs.NMHEADER));
                            if(nmheader.iItem == 0)
                            {
                                m.Result = (IntPtr)1;
                                return;
                            }
                            break;
                        #endregion
                        #region APIsEnums.HeaderControlNotifications.ENDDRAG
                        case (APIsEnums.ListViewNotifications) APIsEnums.HeaderControlNotifications.ENDDRAG:
                            nmheader =(APIsStructs.NMHEADER) m.GetLParam(typeof(APIsStructs.NMHEADER));
                            // Get mouse position in header coordinates
                            IntPtr headerHandle = (IntPtr) APIsUser32.SendMessage(new HandleRef(this,  Handle), (int) APIsEnums.ListViewMessages.GETHEADER, IntPtr.Zero, IntPtr.Zero);
                            APIsStructs.POINTAPI pointapi = new APIsStructs.POINTAPI(MousePosition);
                            APIsUser32.ScreenToClient(headerHandle, ref pointapi);
                            // HeaderItem Rect
                            APIsStructs.RECT headerItemRect = new APIsStructs.RECT();

                            //APIsUser32.SendMessage(headerHandle, (int)APIsEnums.HeaderControlMessages.GETITEMRECT, IntPtr.Zero, ref headerItemRect);
                            APIsUser32.SendMessage(new HandleRef(this, headerHandle), (int)APIsEnums.HeaderControlMessages.GETITEMRECT, IntPtr.Zero, ref headerItemRect);
                            int headerItemWidth = headerItemRect.right - headerItemRect.left;
                            // Cancel the drag operation if the first column is moved
                            // or destination is the first column
                            if(pointapi.x <= headerItemRect.left + headerItemWidth / 2 ||
                                nmheader.iItem == 0)
                            {
                                m.Result = (IntPtr)1;
                                return;
                            }
                            break;
                        #endregion
                        #region APIsEnums.HeaderControlNotifications.TRACK / ENDTRACK
            //						case (APIsEnums.ListViewNotifications)APIsEnums.HeaderControlNotifications.TRACK:
                        case (APIsEnums.ListViewNotifications)APIsEnums.HeaderControlNotifications.ENDTRACK:
                            Invalidate();
                            break;
                        #endregion
                    }
                    break;
                #endregion

                #region LBUTTONDOWN
                    // Cancel the click on checkboxes if the item is not "checkable"
                    case APIsEnums.WindowMessages.LBUTTONDOWN:
                        if(Columns.Count == 0) break;
                        // Set the clickeditem and column
                        int colclicked = GetColumnAt(MousePosition);
                        if(colclicked == -1) colclicked = 0;
                        item = GetItemAtFullRow(PointToClient(MousePosition));
                        _lastitemclicked = new EditItemInformations(item, colclicked, "");
                        if(_selectionMark == null || !_selectionMark.Visible) _selectionMark = item;
                        if (item == null)
                        {
                            break;
                        }
                        if(((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.SHIFT) != APIsEnums.KeyStatesMasks.SHIFT &&
                            !(((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.CONTROL) == APIsEnums.KeyStatesMasks.CONTROL &&
                            item.Parent != _selectionMark.Parent))
                            _selectionMark = item;
                        // Get where the mouse has clicked
                    APIsStructs.LVHITTESTINFO lvhittest = new APIsStructs.LVHITTESTINFO();
                        lvhittest.pt = new APIsStructs.POINTAPI(PointToClient(MousePosition));
                        APIsUser32.SendMessage(new HandleRef(this, Handle), (Int32) APIsEnums.ListViewMessages.HITTEST, IntPtr.Zero, ref lvhittest);
                        if(item == null) break;
                        // Plus / Minus click
                        if(item.GetBounds(TreeListViewItemBoundsPortion.PlusMinus).Contains(PointToClient(MousePosition)) &&
                            ShowPlusMinus && item.Items.Count > 0 &&
                            Columns[0].Width > (item.Level+1)*SystemInformation.SmallIconSize.Width)
                        {
                            Focus();
                            if(item.IsExpanded) item.Collapse();
                            else item.Expand();
                            OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, PointToClient(MousePosition).X, PointToClient(MousePosition).Y, 0));
                            return;
                        }
                        // Cancel mouse click if multiselection on a wrong item
                        if(SelectedIndices.Count > 0 &&
                            (((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.SHIFT) == APIsEnums.KeyStatesMasks.SHIFT ||
                            ((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.CONTROL) == APIsEnums.KeyStatesMasks.CONTROL) &&
                            MultiSelect)
                        {
                            if(_selectionMark.Parent == item.Parent &&
                                ((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.SHIFT) == APIsEnums.KeyStatesMasks.SHIFT)
                            {
                                _updating = true;
                                SetSelectedItemsRange(item, _selectionMark);
                                // Prevent all item at the wrong level of being selected
                                m.WParam = (IntPtr) APIsEnums.KeyStatesMasks.CONTROL;
                                base.WndProc(ref m);
                                item.Selected = true;
                                _updating = false;
                                DrawSelectedItemsFocusCues();
                                return;
                            }
                        }
                        break;
                #endregion
                #region LBUTTONDBLCLK
                    // Disable this notification to remove the auto-check when
                    // the user double-click on an item and append the expand / collapse function
                case APIsEnums.WindowMessages.LBUTTONDBLCLK:
                    _lastdoubleclick = DateTime.Now;
                    if(FocusedItem != null)
                    {
                        item = FocusedItem;
                        bool doExpColl = false;
                        switch(ExpandMethod)
                        {
                            case TreeListViewExpandMethod.IconDbleClick:
                                rec = item.GetBounds(ItemBoundsPortion.Icon);
                                if(rec.Contains(PointToClient(MousePosition))) doExpColl = true;
                                break;
                            case TreeListViewExpandMethod.ItemOnlyDbleClick:
                                rec = item.GetBounds(ItemBoundsPortion.ItemOnly);
                                if(rec.Contains(PointToClient(MousePosition))) doExpColl = true;
                                break;
                            case TreeListViewExpandMethod.EntireItemDbleClick:
                                rec = item.GetBounds(ItemBoundsPortion.Entire);
                                if(rec.Contains(PointToClient(MousePosition))) doExpColl = true;
                                break;
                            default:
                                break;
                        }
                        if(doExpColl)
                        {
                            _dblclicktime = DateTime.Now;
                            bool switchCursor = true;
                            if(this.Cursor == Cursors.WaitCursor)
                                switchCursor = false;
                            else
                                Cursor = Cursors.WaitCursor;
                            BeginUpdate();
                            if(item.IsExpanded) item.Collapse();
                            else item.Expand();
                            EndUpdate();
                            if(switchCursor)
                                Cursor = Cursors.Default;
                        }
                    }
                    OnDoubleClick(new EventArgs());
                    return;
                #endregion
                #region MOUSEMOVE
                case APIsEnums.WindowMessages.MOUSEMOVE:
                    if((MouseButtons & MouseButtons.Left) != MouseButtons.Left && HasMarquee)
                        _hasMarquee = false;
                    break;
                #endregion
                #region UNICHAR, CHAR, KEYDOWN
                case APIsEnums.WindowMessages.UNICHAR:
                case APIsEnums.WindowMessages.CHAR:
                    CharPressed((char) m.WParam);
                    return;
                case APIsEnums.WindowMessages.KEYDOWN:
                    OnKeyDown(new KeyEventArgs((Keys)(int) m.WParam));
                    return;
                #endregion
                #region PAINT
                case APIsEnums.WindowMessages.PAINT:
                    if(InEdit && EditedItem.Item != null)
                    {
                        APIsStructs.RECT rect = new APIsStructs.RECT(
                            EditedItem.Item.GetBounds(ItemBoundsPortion.Entire));
                        APIsUser32.ValidateRect(Handle, ref rect);
                    }
                    base.WndProc(ref m);
                    DrawIntermediateStateItems();
                    DrawSelectedItemsFocusCues();
                    return;
                #endregion
                #region VSCROLL, HSCROLL, ENSUREVISIBLE
                case APIsEnums.WindowMessages.VSCROLL:
                case APIsEnums.WindowMessages.HSCROLL:
                case (APIsEnums.WindowMessages)APIsEnums.ListViewMessages.ENSUREVISIBLE:
                    if(!Scrollable)
                    {
                        m.Result = (IntPtr)0;
                        return;
                    }
                    break;
                #endregion
            }
            base.WndProc(ref m);
        }
Beispiel #45
0
        private bool IsParent(TreeListViewItem child, ItemsControl parent)
        {
            if (child == null)
                return false;

            if (child == parent)
                return true;

            return IsParent(child.ParentItemsControl as TreeListViewItem, parent);
        }
Beispiel #46
0
 /// <summary>
 /// Creates a new instance of EditItemInformations
 /// </summary>
 /// <param name="item"></param>
 /// <param name="column"></param>
 /// <param name="label"></param>
 public EditItemInformations(TreeListViewItem item, int column, string label)
 {
     _item = item; _colindex = column; _label = label; CreationTime = DateTime.Now;
 }
 /// <summary>
 /// Index of an item
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public int IndexOf(TreeListViewItem item)
 {
     return(base.IndexOf((ListViewItem) item));
 }
Beispiel #48
0
 private void SetSelectedItemsRange(TreeListViewItem item1, TreeListViewItem item2)
 {
     if(InvokeRequired)
             throw(new Exception("Invoke required"));
         if(item1 == null || item2 == null) return;
         if(!item1.Visible || !item2.Visible) return;
         if(item1.Parent != item2.Parent) return;
         TreeListViewItemCollection items = item1.Container;
         int index1 = items.GetIndexOf(item1);
         int index2 = items.GetIndexOf(item2);
         ListViewItem[] selItems = new ListViewItem[base.SelectedItems.Count];
         base.SelectedItems.CopyTo(selItems, 0);
         foreach(ListViewItem selItem in selItems)
         {
             int selItemIndex = items.GetIndexOf((TreeListViewItem)selItem);
             if(selItemIndex < Math.Min(index1, index2) ||
                 selItemIndex > Math.Max(index1, index2))
                 selItem.Selected = false;
         }
         for(int i = Math.Min(index1, index2); i <= Math.Max(index1, index2); i++)
             if(!items[i].Selected) items[i].Selected = true;
 }
 /// <summary>
 /// Create a new instance of TreeListViewEvent arguments
 /// </summary>
 /// <param name="item"></param>
 /// <param name="action"></param>
 public TreeListViewEventArgs(TreeListViewItem item, TreeListViewAction action)
 {
     _item = item;
       _action = action;
 }
Beispiel #50
0
 /// <summary>
 /// Creates a new instance of TreeListViewBeforeLabelEditEventArgs
 /// </summary>
 /// <param name="item"></param>
 /// <param name="column"></param>
 /// <param name="label"></param>
 public TreeListViewBeforeLabelEditEventArgs(TreeListViewItem item, int column, string label)
     : base(item, column, label)
 {
 }
Beispiel #51
0
 private void GetTaskDetails(TaskStatisticsResult result)
 {
     try
     {
         this.applicationsList.BeginUpdate();
         this.applicationsList.Items.Clear();
         int appActiveTime = 0;
         foreach (ApplicationSummary applicationsSummaryRow in result.AppsSummaryList)
         {
             appActiveTime += (int) applicationsSummaryRow.TotalActiveTime;
         }
         foreach (ApplicationSummary applicationsSummaryRow in result.AppsSummaryList)
         {
             TimeSpan active = new TimeSpan(0, 0, (int) applicationsSummaryRow.TotalActiveTime);
             string activeTime = ViewHelper.TimeSpanToTimeString(active);
             double percent = 0;
             if (appActiveTime > 0)
                 percent = applicationsSummaryRow.TotalActiveTime/appActiveTime;
             TreeListViewItem lvi =
                 new TreeListViewItem(applicationsSummaryRow.Name,
                                      new string[]
                                      	{
                                      		activeTime, percent.ToString("0.0%", CultureInfo.InvariantCulture),
                                      		applicationsSummaryRow.TaskId.ToString(CultureInfo.InvariantCulture)
                                      	});
             lvi.ImageIndex = IconsManager.GetIconFromFile(applicationsSummaryRow.ApplicationFullPath);
             this.applicationsList.Items.Add(lvi);
         }
         AppsActiveTimeValue.Text = ViewHelper.TimeSpanToTimeString(new TimeSpan(0, 0, appActiveTime));
     }
     finally
     {
         this.applicationsList.EndUpdate();
         SetReadyState();
     }
 }
Beispiel #52
0
 /// <summary>
 /// Creates a new instance of TreeListViewLabelEditEventArgs
 /// </summary>
 /// <param name="item"></param>
 /// <param name="column"></param>
 /// <param name="label"></param>
 public TreeListViewLabelEditEventArgs(TreeListViewItem item, int column, string label)
     : base()
 {
     _item = item; _colindex = column; _label = label;
 }
 /// <summary>
 /// Remove an item from the collection and the TreeListView
 /// </summary>
 /// <param name="item"></param>
 public virtual void Remove(TreeListViewItem item)
 {
     TreeListView treelistview = this.TreeListView;
     if(treelistview != null) treelistview.BeginUpdate();
     RemoveInternal(item);
     if(treelistview != null) treelistview.EndUpdate();
 }
Beispiel #54
0
 private void AddChildNodes(Task parentRow, TreeListViewItem nodeParent)
 {
     Task[] childTasks = Tasks.GetChildTasks(parentRow.Id);
     foreach (Task task in childTasks)
     {
         if (task.Id == Tasks.IdleTask.Id)
             continue;
         if(task.Hidden && !this.showHidden)
             continue;
         TreeListViewItem nodeChild = CreateNode(task);
         nodeParent.Items.Add(nodeChild);
         AddChildNodes(task, nodeChild);
     }
 }
Beispiel #55
0
 private static TreeListViewItem CreateNode(Task task)
 {
     TreeListViewItem node; // = new TreeListViewItem(task.Description, task.IconId);
     string priority = task.Priority > 0 ? task.Priority.ToString() : String.Empty;
     node = new TreeListViewItem(task.Description, new string[] { priority });
     node.ImageIndex = task.IconId;
     node.Tag = task.Id;
     return node;
 }
 /// <summary>
 /// Transforms the collection to an array
 /// </summary>
 public TreeListViewItem[] ToArray()
 {
     //			if(TreeListView != null)
     //				if(TreeListView.InvokeRequired)
     //					throw(new Exception("Invoke required"));
     int size = this.Count;
     TreeListViewItem[] eltsArray = new TreeListViewItem[size];
     for(int i = 0 ; i < size ; i++)
         eltsArray[i] = this[i];
     return(eltsArray);
 }
Beispiel #57
0
        private void treeView_DragDrop(object sender, DragEventArgs e)
        {
            // Unlock updates
            ImageList_DragLeave(this.treeView.Handle);

            // Get drop node
            TreeListViewItem dropNode = this.treeView.GetItemAt(this.treeView.PointToClient(new Point(e.X, e.Y)));

            // If drop node isn't equal to drag node, add drag node as child of drop node
            if (this.dragNode != dropNode)
            {
                // Remove drag node from parent
                if (this.dragNode.Parent == null)
                {
                    this.treeView.Items.Remove(this.dragNode);
                }
                else
                {
                    this.dragNode.Parent.Items.Remove(this.dragNode);
                }

                // Add drag node to drop node
                dropNode.Items.Add(this.dragNode);
                dropNode.Expand();

                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    Tasks.UpdateParentTask((int)this.dragNode.Tag, (int)dropNode.Tag);
                }
                catch (ApplicationException aex)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show(aex.Message, this.ParentForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }

                // Set drag node to null
                this.dragNode = null;

                // Disable scroll timer
                this.timer.Enabled = false;
            }
            this.treeView.Refresh();
        }
 internal void RemoveInternal(TreeListViewItem item)
 {
     //			if(TreeListView != null)
     //				if(TreeListView.InvokeRequired)
     //					throw(new Exception("Invoke required"));
     int index = GetIndexOf(item);
     if(index == -1) return;
     RemoveAtInternal(index);
 }
Beispiel #59
0
        private void treeView_ItemDrag(object sender, ItemDragEventArgs e)
        {
            // Get drag node and select it
            this.dragNode = (TreeListViewItem)e.Item;
            if((int)dragNode.Tag == Tasks.RootTask.Id)
                return;
            // Reset image list used for drag image
            this.imageListDrag.Images.Clear();
            this.imageListDrag.ImageSize =
            new Size(Math.Min(this.dragNode.Bounds.Size.Width + TREE_VIEW_INDENT, 256), this.dragNode.Bounds.Height);

            // Create new bitmap
            // This bitmap will contain the tree node image to be dragged
            Bitmap bmp = new Bitmap(Math.Min(this.dragNode.Bounds.Width + TREE_VIEW_INDENT, 256), this.dragNode.Bounds.Height);

            // Get graphics from bitmap
            using (Graphics gfx = Graphics.FromImage(bmp))
            {
                // Draw node icon into the bitmap
                gfx.DrawImage(IconsManager.IconsList.Images[dragNode.ImageIndex], 0, 0);

                // Draw node label into bitmap
                gfx.DrawString(this.dragNode.Text,
                               this.treeView.Font,
                               new SolidBrush(this.treeView.ForeColor),
                               TREE_VIEW_INDENT, 1.0f);
            }

            // Add bitmap to imagelist
            this.imageListDrag.Images.Add(bmp);

            // Get mouse position in client coordinates
            Point p = this.treeView.PointToClient(MousePosition);
            // Compute delta between mouse position and node bounds
            //			int dx = p.X + this.treeView.Indent - this.dragNode.Bounds.Left;
            //			int dy = p.Y - this.dragNode.Bounds.Top;

            int dx = p.X - this.dragNode.GetBounds(ItemBoundsPortion.Label).Left - this.treeView.Location.X;
            int dy = p.Y - this.dragNode.Bounds.Top - this.treeView.Location.Y;

            // Begin dragging image
            if (ImageList_BeginDrag(this.imageListDrag.Handle, 0, dx, dy))
            {
                // Begin dragging
                this.treeView.DoDragDrop(bmp, DragDropEffects.Move);
                // End dragging image
                ImageList_EndDrag();
            }
        }
        private int GetInsertCollectionIndex(TreeListViewItem item)
        {
            //			if(TreeListView != null)
            //				if(TreeListView.InvokeRequired)
            //					throw(new Exception("Invoke required"));
            int index = -1;
            if(!_sortable) index = Count;
            else if(!Contains(item) && !ListViewContains(item))
            {
                switch(SortOrder)
                {
                        // No sortorder -> at the end of the collection
                    case SortOrder.None:
                        index = this.Count;
                        break;
                    default:
                        for(int i = 0 ; i < this.Count ; i++)
                        {
                            // Change the index for the compare if the order is descending
                            int indexcompare = i;
                            int comp = Comparer.Compare(item, this[indexcompare]);
                            if(comp <= 0)
                            {
                                index = indexcompare;
                                break;
                            }
                        }
                        index = index == -1 ? this.Count : index;
                        break;
                }
            }

            return(index);
        }