FormatRange.cs :  » Game » Balder » Fireball » Syntax » 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 » Game » Balder 
Balder » Fireball » Syntax » FormatRange.cs
using System;
using System.Windows;
using System.Windows.Media;

namespace Fireball.Syntax{
  /// <summary>
  /// Format ranges can be applied to a syntaxdocument to mark sections such as breakpoints or errors
  /// </summary>
  public class FormatRange
  {
    #region PUBLIC PROPERTY BACKCOLOR

    private Color _BackColor = new Color();

    public Color BackColor
    {
      get { return _BackColor; }
      set
      {
        _BackColor = value;
        Apply();
      }
    }

    #endregion

    #region PUBLIC PROPERTY FORECOLOR

    private Color _ForeColor = new Color();

    public Color ForeColor
    {
      get { return _ForeColor; }
      set
      {
        _ForeColor = value;
        Apply();
      }
    }

    #endregion

    #region PUBLIC PROPERTY WAVECOLOR

    private Color _WaveColor = new Color();

    public Color WaveColor
    {
      get { return _WaveColor; }
      set
      {
        _WaveColor = value;
        Apply();
      }
    }

    #endregion

    #region PUBLIC PROPERTY INFOTIP

    private string _InfoTip = "";

    public string InfoTip
    {
      get { return _InfoTip; }
      set
      {
        _InfoTip = value;
        Apply();
      }
    }

    #endregion

    #region PUBLIC PROPERTY BOUNDS

    private TextRange _Bounds;
    private TextRange _OldBounds = new TextRange();

    public TextRange Bounds
    {
      get { return _Bounds; }
      set { _Bounds = value; }
    }

    #endregion

    #region PUBLIC PROPERTY TAG

    private object _Tag;

    public object Tag
    {
      get { return _Tag; }
      set { _Tag = value; }
    }

    #endregion

    #region PUBLIC PROPERTY DOCUMENT

    private SyntaxDocument _Document;

    internal SyntaxDocument Document
    {
      get { return _Document; }
      set { _Document = value; }
    }

    #endregion

    public FormatRange()
    {
      this.Bounds = new TextRange();
      this.Bounds.Change += new EventHandler(this.BoundsChanged);
    }

    public FormatRange(TextRange Bounds, Color ForeColor, Color BackColor)
    {
      this.BackColor = BackColor;
      this.ForeColor = ForeColor;
      this.Bounds = Bounds;
      this.Bounds.Change += new EventHandler(this.BoundsChanged);
    }

    public FormatRange(TextRange Bounds, Color ForeColor, Color BackColor, Color WaveColor)
    {
      this.BackColor = BackColor;
      this.ForeColor = ForeColor;
      this.WaveColor = WaveColor;
      this.Bounds = Bounds;
      this.Bounds.Change += new EventHandler(this.BoundsChanged);
    }

    public FormatRange(TextRange Bounds, Color WaveColor)
    {
      this.WaveColor = WaveColor;
      this.Bounds = Bounds;
      this.Bounds.Change += new EventHandler(this.BoundsChanged);
    }

    public int Contains(TextPoint tp)
    {
      return this.Contains(tp.X, tp.Y);
    }

    public int Contains(int x, int y)
    {
      if (y < this.Bounds.FirstRow)
        return -1;

      if (y > this.Bounds.LastRow)
        return 1;

      if (y == this.Bounds.FirstRow && x < this.Bounds.FirstColumn)
        return -1;

      if (y == this.Bounds.LastRow && x > this.Bounds.LastColumn)
        return 1;

      return 0;
    }

    public int Contains2(TextPoint tp)
    {
      return this.Contains2(tp.X, tp.Y);
    }

    public int Contains2(int x, int y)
    {
      if (y < this.Bounds.FirstRow)
        return -1;

      if (y > this.Bounds.LastRow)
        return 1;

      if (y == this.Bounds.FirstRow && x <= this.Bounds.FirstColumn)
        return -1;

      if (y == this.Bounds.LastRow && x > this.Bounds.LastColumn)
        return 1;

      return 0;
    }

    public void Apply()
    {
      if (this.Document == null)
        return;

      ApplyOld();
      for (int i = this.Bounds.FirstRow; i <= this.Bounds.LastRow; i++)
      {
        if (i < 0 || i >= this.Document.Count)
          return;

        Row r = this.Document[i];

        if (r == null)
          return;

        if (r.RowState == RowState.AllParsed)
        {
          r.AddToParseQueue();
        }
      }
    }

    public void ApplyOld()
    {
      for (int i = this._OldBounds.FirstRow; i <= this._OldBounds.LastRow; i++)
      {
        if (i < 0 || i >= this.Document.Count)
          return;

        Row r = this.Document[i];

        if (r == null)
          return;

        if (r.RowState == RowState.AllParsed)
        {
          r.AddToParseQueue();
        }
      }
    }

    protected virtual void BoundsChanged(object s, EventArgs e)
    {
      Apply();
      _OldBounds.FirstColumn = _Bounds.FirstColumn;
      _OldBounds.LastColumn = _Bounds.LastColumn;
      _OldBounds.FirstRow = _Bounds.FirstRow;
      _OldBounds.LastRow = _Bounds.LastRow;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.