EditableControl.cs :  » GUI » TreeViewAdv » Aga » Controls » Tree » NodeControls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » TreeViewAdv 
TreeViewAdv » Aga » Controls » Tree » NodeControls » EditableControl.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace Aga.Controls.Tree.NodeControls{
  public abstract class EditableControl : InteractiveControl
  {
    private Timer _timer;
    private bool _editFlag;

    #region Properties

    private bool _editOnClick = false;
    [DefaultValue(false)]
    public bool EditOnClick
    {
      get { return _editOnClick; }
      set { _editOnClick = value; }
    }

    #endregion

    protected EditableControl()
    {
      _timer = new Timer();
      _timer.Interval = 500;
      _timer.Tick += new EventHandler(TimerTick);
    }

    private void TimerTick(object sender, EventArgs e)
    {
      _timer.Stop();
      if (_editFlag)
        BeginEdit();
      _editFlag = false;
    }

    public void SetEditorBounds(EditorContext context)
    {
      Size size = CalculateEditorSize(context);
      context.Editor.Bounds = new Rectangle(context.Bounds.X, context.Bounds.Y,
        Math.Min(size.Width, context.Bounds.Width),
        Math.Min(size.Height, Parent.ClientSize.Height - context.Bounds.Y)
      );
    }

    protected abstract Size CalculateEditorSize(EditorContext context);

    protected virtual bool CanEdit(TreeNodeAdv node)
    {
      return (node.Tag != null) && IsEditEnabled(node);
    }

    public void BeginEdit()
    {
      if (Parent != null && Parent.CurrentNode != null && CanEdit(Parent.CurrentNode))
      {
        CancelEventArgs args = new CancelEventArgs();
        OnEditorShowing(args);
        if (!args.Cancel)
        {
          var editor = CreateEditor(Parent.CurrentNode);
          Parent.DisplayEditor(editor, this);
        }
      }
    }

    public void EndEdit(bool applyChanges)
    {
      if (Parent != null)
        if (Parent.HideEditor(applyChanges))
          OnEditorHided();
    }

    public virtual void UpdateEditor(Control control)
    {
    }

    internal void ApplyChanges(TreeNodeAdv node, Control editor)
    {
      DoApplyChanges(node, editor);
      OnChangesApplied();
    }

    internal void DoDisposeEditor(Control editor)
    {
      DisposeEditor(editor);
    }

    protected abstract void DoApplyChanges(TreeNodeAdv node, Control editor);

    protected abstract Control CreateEditor(TreeNodeAdv node);

    protected abstract void DisposeEditor(Control editor);

    public virtual void Cut(Control control)
    {
    }

    public virtual void Copy(Control control)
    {
    }

    public virtual void Paste(Control control)
    {
    }

    public virtual void Delete(Control control)
    {
    }

    public override void MouseDown(TreeNodeAdvMouseEventArgs args)
    {
      _editFlag = (!EditOnClick && args.Button == MouseButtons.Left
        && args.ModifierKeys == Keys.None && args.Node.IsSelected);
    }

    public override void MouseUp(TreeNodeAdvMouseEventArgs args)
    {
      if (args.Node.IsSelected)
      {
        if (EditOnClick && args.Button == MouseButtons.Left && args.ModifierKeys == Keys.None)
        {
          Parent.ItemDragMode = false;
          BeginEdit();
          args.Handled = true;
        }
        else if (_editFlag)// && args.Node.IsSelected)
          _timer.Start();
      }
    }

    public override void MouseDoubleClick(TreeNodeAdvMouseEventArgs args)
    {
      _editFlag = false;
      _timer.Stop();
    }

    protected override void Dispose(bool disposing)
    {
      base.Dispose(disposing);
      if (disposing)
        _timer.Dispose();
    }

    #region Events

    public event CancelEventHandler EditorShowing;
    protected void OnEditorShowing(CancelEventArgs args)
    {
      if (EditorShowing != null)
        EditorShowing(this, args);
    }

    public event EventHandler EditorHided;
    protected void OnEditorHided()
    {
      if (EditorHided != null)
        EditorHided(this, EventArgs.Empty);
    }

    public event EventHandler ChangesApplied;
    protected void OnChangesApplied()
    {
      if (ChangesApplied != null)
        ChangesApplied(this, EventArgs.Empty);
    }

    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.