Beispiel #1
0
        public void RedrawNode(wTreeNode node)
        {
            node.DrawBuffer();
            Graphics g = Graphics.FromImage(ImageTempBufferToDrawForTree);

            node.DrawNode(g, node.Area.X, node.Area.Y);
        }
 /// <summary>
 /// 체크박스의 값을 toggle한다.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="itemIndex"></param>
 internal void SetCheckboxIfItemIsCheckbox(wTreeNode node, int itemIndex)
 {
     if (node.Items[itemIndex] != null && node.Items[itemIndex].ItemType == wTreeNodeItemTypes.CheckBox)
     {
         wTreeNodeItem item  = node.Items[itemIndex];
         bool?         value = (bool?)item.Value;
         if (value == true)
         {
             item.Value = false;
         }
         else if (value == false)
         {
             item.Value = true;
         }
         else
         {
             item.Value = true; //중간상태일 때는 true로 바꿈.
         }
         bool newValue = (bool)item.Value;
         node.ControlChildChecks(itemIndex, newValue);
         node.ControlParentChecks(itemIndex);
         node.DrawBuffer();
         _ownerTree.wDrawHandler.ReDrawTree(false);
         if (E_CheckItemChanged != null)
         {
             E_CheckItemChanged(node, item, newValue);
         }
     }
 }
 /// <summary>
 /// 특정 값으로 체크박스를 셋팅한다.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="itemIndex"></param>
 /// <param name="checkBoxValue"></param>
 internal void SetCheckboxValueIfItemIsCheckbox(wTreeNode node, int itemIndex, bool checkBoxValue)
 {
     if (node.Items[itemIndex] != null && node.Items[itemIndex].ItemType == wTreeNodeItemTypes.CheckBox)
     {
         wTreeNodeItem item = node.Items[itemIndex];
         item.Value = checkBoxValue;
         bool newValue = (bool)item.Value;
         node.ControlChildChecks(itemIndex, newValue);
         node.ControlParentChecks(itemIndex);
         node.DrawBuffer();
         _ownerTree.wDrawHandler.ReDrawTree(false);
         if (E_CheckItemChanged != null)
         {
             E_CheckItemChanged(node, item, newValue);
         }
     }
 }
        /// <summary>
        /// 체크박스의 값을 toggle한다.
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="itemIndex"></param>
        internal void SetCheckboxIfItemIsCheckbox(IwTreeNodeCollectionParent parentNode, int childStart, int childEnd, int itemIndex)
        {
            int min = childStart < childEnd ? childStart : childEnd;
            int max = childStart < childEnd ? childEnd : childStart;
            Dictionary <wTreeNodeItem, bool> itemValues = new Dictionary <wTreeNodeItem, bool>();

            for (int i = min; i <= max; i++)
            {
                if (i == childStart)
                {
                    continue;
                }
                wTreeNode child = parentNode.Children[i];

                if (child.Items[itemIndex] != null && child.Items[itemIndex].ItemType == wTreeNodeItemTypes.CheckBox)
                {
                    wTreeNodeItem item  = child.Items[itemIndex];
                    bool?         value = (bool?)item.Value;
                    if (value == true)
                    {
                        item.Value = false;
                    }
                    else if (value == false)
                    {
                        item.Value = true;
                    }
                    else
                    {
                        item.Value = true; //중간상태일 때는 true로 바꿈.
                    }
                    bool newValue = (bool)item.Value;
                    child.ControlChildChecks(itemIndex, newValue);
                    child.DrawBuffer();
                    itemValues.Add(item, newValue);//toggle이니까 무조건 바뀐다.
                }
            }
            parentNode.Children[0].ControlParentChecks(itemIndex);
            _ownerTree.wDrawHandler.ReDrawTree(false);
            if (itemValues.Count > 0)
            {
                if (E_CheckItemChanged != null)
                {
                    E_CheckItemsChanged(parentNode as wTreeNode, itemValues);
                }
            }
        }
        /// <summary>
        /// 특정 값으로 체크박스를 셋팅한다.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="itemIndex"></param>
        /// <param name="checkBoxValue"></param>
        internal void SetCheckboxValueIfItemIsCheckbox(IwTreeNodeCollectionParent parentNode, int childStart, int childEnd, int itemIndex, bool checkBoxValue)
        {
            int min = childStart < childEnd ? childStart : childEnd;
            int max = childStart < childEnd ? childEnd : childStart;
            Dictionary <wTreeNodeItem, bool> itemValues = new Dictionary <wTreeNodeItem, bool>();

            for (int i = min; i <= max; i++)
            {
                wTreeNode child = parentNode.Children[i];


                if (child.Items[itemIndex] != null && child.Items[itemIndex].ItemType == wTreeNodeItemTypes.CheckBox)
                {
                    wTreeNodeItem item     = child.Items[itemIndex];
                    bool?         oldValue = (bool?)item.Value;
                    if (checkBoxValue != oldValue)
                    {
                        item.Value = checkBoxValue;
                        bool newValue = (bool)item.Value;
                        child.ControlChildChecks(itemIndex, newValue);
                        child.DrawBuffer();
                        if (oldValue != newValue)
                        {
                            itemValues.Add(item, newValue);                      //값이 바뀔 때만 추가한다.
                        }
                    }
                }
            }
            parentNode.Children[0].ControlParentChecks(itemIndex);
            _ownerTree.wDrawHandler.ReDrawTree(false);
            if (itemValues.Count > 0)
            {
                if (E_CheckItemChanged != null)
                {
                    E_CheckItemsChanged(parentNode as wTreeNode, itemValues);
                }
            }
        }
        void _ownerTree_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Clicks != 1)
            {
                return;
            }

            Point pt;

            //= new Point(e.X - Margin.Left, e.Y - Margin.Top);
            wTreeNode              clickedNode = GetNodeFromPoint(e.Location, out pt);// _pressedNode;
            wTreeNodeItem          item        = (clickedNode == null)? null : clickedNode.GetItemFromPoint(pt);
            wTreeNodeItemMouseArgs args        = new wTreeNodeItemMouseArgs(new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));

            if (E_TreeNodeClicked != null)
            {
                E_TreeNodeClicked(clickedNode, item, args);
            }
            if (args.IsCanceled)
            {
                return;
            }

            if (clickedNode != null)
            {
                //selectedNode.IsExpaned = !selectedNode.IsExpaned;

                if (item != null)
                {
                    #region item is not null
                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {
                        if (Control.ModifierKeys == Keys.None)
                        {
                            if (item.ItemType == wTreeNodeItemTypes.CheckBox && (item.CheckBoxActiveAction & CheckboxActiveActions.Click) == CheckboxActiveActions.Click)
                            {
                                SelectionHandler.SetCheckboxIfItemIsCheckbox(clickedNode, item.ItemIndex);
                            }
                            else
                            {
                                if (clickedNode.IsSelected)
                                {
                                    if ((item.EditorActivateAction & EditorActivateActions.ClickOnSelection) == EditorActivateActions.ClickOnSelection)
                                    {
                                        EditorHandler.ShowEditor(item, item.ItemArea);
                                    }
                                    else if ((item.EditorActivateAction & EditorActivateActions.Click) == EditorActivateActions.Click)
                                    {
                                        EditorHandler.ShowEditor(item, item.ItemArea);
                                    }
                                    else if (item.EditorActivateAction == EditorActivateActions.UseBasicSetting)
                                    {
                                        if ((EditorHandler.EditorActivateAction & EditorActivateBasicActions.ClickOnSelection) == EditorActivateBasicActions.ClickOnSelection)
                                        {
                                            EditorHandler.ShowEditor(item, item.ItemArea);
                                        }
                                        else if ((EditorHandler.EditorActivateAction & EditorActivateBasicActions.Click) == EditorActivateBasicActions.Click)
                                        {
                                            EditorHandler.ShowEditor(item, item.ItemArea);
                                        }
                                    }
                                }
                                else
                                {
                                    if ((item.EditorActivateAction & EditorActivateActions.Click) == EditorActivateActions.Click)
                                    {
                                        EditorHandler.ShowEditor(item, item.ItemArea);
                                    }
                                }
                                _isShiftDown = false;

                                SelectionHandler.SelectedNode = clickedNode;
                                SelectionHandler.SetNodeSelected(clickedNode, item);
                            }
                        }
                        else if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                        {
                            if (item.ItemType == wTreeNodeItemTypes.CheckBox && (item.CheckBoxActiveAction & CheckboxActiveActions.Click) == CheckboxActiveActions.Click)
                            {
                                if (clickedNode != null && clickedNode.TreeParent == clickedNode.TreeParent)
                                {
                                    int itemIndex = item.ItemIndex;
                                    int lastIndex = clickedNode.Index;


                                    SelectionHandler.SetCheckboxValueIfItemIsCheckbox(clickedNode.TreeParent, lastIndex, clickedNode.Index, itemIndex, true);
                                }
                                else
                                {
                                    if ((item.CheckBoxActiveAction & CheckboxActiveActions.Click) == CheckboxActiveActions.Click)
                                    {
                                        SelectionHandler.SetCheckboxValueIfItemIsCheckbox(clickedNode, item.ItemIndex, true);
                                    }
                                }
                            }
                            else
                            {
                                if (clickedNode.IsSelected)
                                {
                                    clickedNode.SetSelection(false);
                                    SelectedNode = null;
                                    clickedNode.DrawBuffer();
                                }
                                else
                                {
                                    clickedNode.SetSelection(true);
                                    SelectedNode = null;
                                    clickedNode.DrawBuffer();
                                }

                                if ((item.EditorActivateAction & EditorActivateActions.CtrlClick) == EditorActivateActions.CtrlClick)
                                {
                                    EditorHandler.ShowEditor(item, item.ItemArea);
                                }
                                else if (item.EditorActivateAction == EditorActivateActions.UseBasicSetting)
                                {
                                    if ((EditorHandler.EditorActivateAction & EditorActivateBasicActions.CtrlClick) == EditorActivateBasicActions.CtrlClick)
                                    {
                                        EditorHandler.ShowEditor(item, item.ItemArea);
                                    }
                                }
                            }
                        }
                        else if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
                        {
                            _isShiftDown = true;

                            if (item.ItemType == wTreeNodeItemTypes.CheckBox && (item.CheckBoxActiveAction & CheckboxActiveActions.Click) == CheckboxActiveActions.Click)
                            {
                                if (clickedNode != null && clickedNode.TreeParent == clickedNode.TreeParent)
                                {
                                    int itemIndex = item.ItemIndex;
                                    int lastIndex = (_oldClickedNode == null)? clickedNode.Index : _oldClickedNode.Index;

                                    SelectionHandler.SetCheckboxIfItemIsCheckbox(clickedNode.TreeParent, lastIndex, clickedNode.Index, itemIndex);
                                }
                                else
                                {
                                    if ((item.CheckBoxActiveAction & CheckboxActiveActions.Click) == CheckboxActiveActions.Click)
                                    {
                                        SelectionHandler.SetCheckboxIfItemIsCheckbox(clickedNode, item.ItemIndex);
                                    }
                                }
                            }
                            else
                            {
                                if ((item.EditorActivateAction & EditorActivateActions.ShiftClick) == EditorActivateActions.ShiftClick)
                                {
                                    EditorHandler.ShowEditor(item, item.ItemArea);
                                }
                                else if (item.EditorActivateAction == EditorActivateActions.UseBasicSetting)
                                {
                                    if ((EditorHandler.EditorActivateAction & EditorActivateBasicActions.ShiftClick) == EditorActivateBasicActions.ShiftClick)
                                    {
                                        EditorHandler.ShowEditor(item, item.ItemArea);
                                    }
                                }
                            }
                        }
                        else if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
                        {
                            if (item.ItemType == wTreeNodeItemTypes.CheckBox && (item.CheckBoxActiveAction & CheckboxActiveActions.Click) == CheckboxActiveActions.Click)
                            {
                                if (clickedNode != null && clickedNode.TreeParent == clickedNode.TreeParent)
                                {
                                    int itemIndex = item.ItemIndex;
                                    int lastIndex = clickedNode.Index;
                                    SelectionHandler.SetCheckboxIfItemIsCheckbox(clickedNode.TreeParent, lastIndex, clickedNode.Index, itemIndex);
                                }
                                else
                                {
                                    if ((item.CheckBoxActiveAction & CheckboxActiveActions.Click) == CheckboxActiveActions.Click)
                                    {
                                        SelectionHandler.SetCheckboxValueIfItemIsCheckbox(clickedNode, item.ItemIndex, false);
                                    }
                                }
                            }
                            else
                            {
                                if ((item.EditorActivateAction & EditorActivateActions.AltClick) == EditorActivateActions.AltClick)
                                {
                                    EditorHandler.ShowEditor(item, item.ItemArea);
                                }
                                else if (item.EditorActivateAction == EditorActivateActions.UseBasicSetting)
                                {
                                    if ((EditorHandler.EditorActivateAction & EditorActivateBasicActions.AltClick) == EditorActivateBasicActions.AltClick)
                                    {
                                        EditorHandler.ShowEditor(item, item.ItemArea);
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
                else // item is null
                {
                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {
                        if (Control.ModifierKeys == Keys.None)
                        {
                            _isShiftDown = false;

                            SelectionHandler.SelectedNode = clickedNode;
                            SelectionHandler.SetNodeSelected(clickedNode, item);
                        }
                        else if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                        {
                            if (clickedNode.IsSelected)
                            {
                                clickedNode.SetSelection(false);
                                SelectedNode = null;
                                clickedNode.DrawBuffer();
                            }
                            else
                            {
                                clickedNode.SetSelection(true);
                                SelectedNode = null;
                                clickedNode.DrawBuffer();
                            }
                        }
                        else if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
                        {
                            _isShiftDown = true;
                        }
                        else if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
                        {
                        }
                    }
                }


                _oldClickedNode = clickedNode;
            }
        }
        /// <summary>
        /// 마우스커서가 움직일 때..
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void wTree_MouseMove(object sender, MouseEventArgs e)
        {
            bool isRollOver = (DrawHandler.BasicDrawing & BasicDrawings.RollOver) != BasicDrawings.None;
            bool isMultipleSelection //drag&drop 가능시 drag로 multiple selection은 활성화되면 안된다.
                = IsDragAndDropEnabled == false && (DrawHandler.BasicDrawing & BasicDrawings.MultiSelections) != BasicDrawings.None;


            if (isMultipleSelection ||
                E_TreeNodeMouseDragging != null
                )
            {
                if (Control.MouseButtons == System.Windows.Forms.MouseButtons.Left)
                {
                    wTreeNode hoveredNode = null;
                    Point     pt;
                    //= new Point(e.X - Margin.Left, e.Y - Margin.Top);
                    hoveredNode = GetNodeFromPoint(e.Location, out pt);// _pressedNode;
                    wTreeNodeItem item = (hoveredNode == null)? null : hoveredNode.GetItemFromPoint(pt);

                    if (_pressedNode != null)
                    {
                        wTreeNodeItemMouseArgs args = new wTreeNodeItemMouseArgs(new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
                        bool isNewArea = (RollOverNode == null || RollOverNode.Equals(hoveredNode) == false);
                        if (E_TreeNodeMouseDragging != null)
                        {
                            E_TreeNodeMouseDragging(hoveredNode, item, isNewArea, args);
                        }
                        if (args.IsCanceled)
                        {
                            return;
                        }


                        if (hoveredNode != null && isNewArea)
                        {
                            int tempSelecting      = VisibleNodes.IndexOf(hoveredNode);
                            int tempSelectingStart = VisibleNodes.IndexOf(_pressedNode);
                            SelectionHandler.drawSelectingNodes(tempSelectingStart, tempSelecting);
                            wTreeNode oldRollOver = RollOverNode;
                            RollOverNode = hoveredNode;
                            if ((BasicDrawing & BasicDrawings.RollOver) == BasicDrawings.RollOver)
                            {
                                hoveredNode.DrawBuffer();
                            }


                            DrawHandler.ReDrawTree(false);
                            //if(oldRollOver!=null) ReDrawNode(oldRollOver);
                            //if(RollOverNode!=null) ReDrawNode(RollOverNode);
                        }
                    }
                }
            }
            else if (E_TreeNodeMouseMove != null ||
                     isRollOver
                     )//이벤트가 구현되었을 때만 들어가도록..
            {
                wTreeNode hoveredNode = null;
                Point     pt;
                //= new Point(e.X - Margin.Left, e.Y - Margin.Top);
                hoveredNode = GetNodeFromPoint(e.Location, out pt);// _pressedNode;

                //if (hoveredNode == null) return;

                wTreeNodeItem item = (hoveredNode == null) ? null : hoveredNode.GetItemFromPoint(pt);

                wTreeNodeItemMouseArgs args = new wTreeNodeItemMouseArgs(new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
                bool isNewArea = (RollOverNode == null || RollOverNode.Equals(hoveredNode) == false);
                if (E_TreeNodeMouseMove != null)
                {
                    E_TreeNodeMouseMove(SelectionHandler.SelectedNode, item, isNewArea, args);
                }
                if (args.IsCanceled)
                {
                    return;
                }

                if (hoveredNode != null && isNewArea)
                {//selectedNode가 null이 아니고, 이전 _rollOverNode가 아닐 때, 혹은 처음 rollOver되었을 때..
                 //selectedNode.IsExpaned = !selectedNode.IsExpaned;



                    wTreeNode oldRollOver = RollOverNode;
                    RollOverNode = hoveredNode;

                    //SelectedNode = selectedNode;
                    if ((BasicDrawing & BasicDrawings.RollOver) == BasicDrawings.RollOver)
                    {
                        hoveredNode.DrawBuffer();
                    }

                    //wTreeNodeItem item = hoveredNode.GetItemFromPoint(pt);

                    if ((BasicDrawing & BasicDrawings.RollOver) == BasicDrawings.RollOver)
                    {
                        DrawHandler.ReDrawTree(false);
                    }
                    //if (oldRollOver != null) ReDrawNode(oldRollOver);
                    //if (RollOverNode != null) ReDrawNode(RollOverNode);
                }
            }
            else if (_pressedNode != null && IsDragAndDropEnabled)
            {
                if (E_TreeNodeDraggedOut != null)
                {
                    E_TreeNodeDraggedOut(_pressedNode, null, null);
                }
                _pressedNode = null;
                _pressedItem = null;
            }
        }