public void AddTest3()
 {
     var c = new RangeCollection();
     var ranges = c.Ranges;
     c.Add(new AddressRange(0, 100));
     c.Add(new AddressRange(200, 300));
     c.Add(new AddressRange(150, 600));
     Assert.Equal(2, ranges.Count);
     Assert.Equal(new AddressRange(0, 100), ranges[0]);
     Assert.Equal(new AddressRange(150, 600), ranges[1]);
     c.Add(new AddressRange(102, 500));
     Assert.Equal(2, ranges.Count);
     Assert.Equal(new AddressRange(102, 600), ranges[1]);
     c.Add(new AddressRange(400, 700));
     Assert.Equal(2, ranges.Count);
     Assert.Equal(new AddressRange(102, 700), ranges[1]);
 }
 public void AddTest3()
 {
     RangeCollection c = new RangeCollection();
     List<AddressRange> ranges = c.Ranges;
     c.Add(new AddressRange(0, 100));
     c.Add(new AddressRange(200, 300));
     c.Add(new AddressRange(150, 600));
     Assert.AreEqual(2, ranges.Count, "#1");
     Assert.AreEqual(new AddressRange(0, 100), ranges[0], "#1b");
     Assert.AreEqual(new AddressRange(150, 600), ranges[1], "#1c");
     c.Add(new AddressRange(102, 500));
     Assert.AreEqual(2, ranges.Count, "#2");
     Assert.AreEqual(new AddressRange(102, 600), ranges[1], "#2b");
     c.Add(new AddressRange(400, 700));
     Assert.AreEqual(2, ranges.Count, "#3");
     Assert.AreEqual(new AddressRange(102, 700), ranges[1], "#3b");
 }
Esempio n. 3
0
        public void LargeSequentialContains ()
        {
            RangeCollection range = new RangeCollection ();
            int i, n = 1000000;

            for (i = 0; i < n; i++) {
                range.Add (i);
            }

            for (i = 0; i < n; i++) {
                Assert.AreEqual (true, range.Contains (i));
            }
        }
        public static void AddRangeSpecifier(this RangeCollection self, string specifier)
        {
            if (self == null)
                throw new ArgumentNullException("self");

            if (specifier == null)
                throw new ArgumentNullException("specifier");

            string[] list = specifier.Split(',');

            RangeCollection staging = new RangeCollection(self.Minimum, self.Maximum);

            foreach (string i in list)
            {
                Match match = rangeRegex.Match(i);

                if (!match.Success)
                    ThrowBadRangeSpecifier(specifier);

                if (match.Groups["single"].Success)
                {
                    staging.Add(int.Parse(match.Groups["single"].Value));
                }
                else
                {
                    int start = self.Minimum;
                    int end = self.Maximum;
                    int step = 1;

                    if (match.Groups["step"].Success)
                        step = int.Parse(match.Groups["step"].Value);

                    if (match.Groups["start"].Success)
                    {
                        start = int.Parse(match.Groups["start"].Value);
                        end = int.Parse(match.Groups["end"].Value);
                    }

                    if (end < start)
                        ThrowBadRangeSpecifier(specifier);

                    for (int j = start; j <= end; j += step)
                        staging.Add(j);
                }
            }

            foreach (int i in staging)
                self.Add(i);
        }
 public void AddTest()
 {
     var c = new RangeCollection();
     c.Add(new AddressRange(50, 50));
     c.Add(new AddressRange(50, 50));
     Assert.Equal(1, c.Ranges.Count);
     c.Add(new AddressRange(50, 51));
     Assert.Equal(1, c.Ranges.Count);
     c.Add(new AddressRange(51, 51));
     Assert.Equal(new AddressRange(50, 51), c.Ranges[0]);
     c.Add(new AddressRange(50, 50));
     c.Add(new AddressRange(49, 50));
     Assert.Equal(1, c.Ranges.Count);
     Assert.Equal(new AddressRange(49, 51), c.Ranges[0]);
     c.Add(new AddressRange(45, 47));
     Assert.Equal(2, c.Ranges.Count);
     Assert.Equal(new AddressRange(49, 51), c.Ranges[1]);
     c.Add(new AddressRange(47, 49));
     Assert.Equal(1, c.Ranges.Count);
     Assert.Equal(new AddressRange(45, 51), c.Ranges[0]);
 }
 public void AddTest()
 {
     RangeCollection c = new RangeCollection();
     c.Add(new AddressRange(50, 50));
     c.Add(new AddressRange(50, 50));
     Assert.AreEqual(1, c.Ranges.Count, "#1");
     c.Add(new AddressRange(50, 51));
     Assert.AreEqual(1, c.Ranges.Count, "#2");
     c.Add(new AddressRange(51, 51));
     Assert.AreEqual(new AddressRange(50, 51), c.Ranges[0], "#2b");
     c.Add(new AddressRange(50, 50));
     c.Add(new AddressRange(49, 50));
     Assert.AreEqual(1, c.Ranges.Count, "#3");
     Assert.AreEqual(new AddressRange(49, 51), c.Ranges[0], "#3b");
     c.Add(new AddressRange(45, 47));
     Assert.AreEqual(2, c.Ranges.Count, "#4");
     Assert.AreEqual(new AddressRange(49, 51), c.Ranges[1], "#4b");
     c.Add(new AddressRange(47, 49));
     Assert.AreEqual(1, c.Ranges.Count, "#5");
     Assert.AreEqual(new AddressRange(45, 51), c.Ranges[0], "#4b");
 }
        public void LargeSequential()
        {
            RangeCollection range = new RangeCollection();
            int             i, n = 1000000;

            for (i = 0; i < n; i++)
            {
                range.Add(i);
                Assert.AreEqual(1, range.RangeCount);
            }

            Assert.AreEqual(n, range.Count);

            i = 0;
            foreach (int j in range)
            {
                Assert.AreEqual(i++, j);
            }

            Assert.AreEqual(n, i);
        }
    /// <summary>
    /// Method for displying values in the range slider
    /// </summary>
    public void PopulateScaleValues()
    {
        _sectionValue = Minimum;
        bool isDivFound = false;

        for (int i = MaximumInteraval; i >= MinimumInterval; i--)
        {
            if (!isDivFound)
            {
                if (0 == Math.IEEERemainder(Maximum, i))
                {
                    _interval  = i;
                    isDivFound = true;
                    continue;
                }
            }
        }
        _interval_width = Maximum / _interval;
        var totalSize = this.ActualWidth;

        Division = totalSize / _interval;
        this._scaleValueControl.Tag = Division;
        if (RangeCollection == null)
        {
            RangeCollection = new List <Range>();
        }
        RangeCollection.Add(new Range {
            RangeValue = _sectionValue
        });
        for (int i = 0; i < _interval; i++)
        {
            _sectionValue = _sectionValue + _interval_width;
            RangeCollection.Add(new Range {
                RangeValue = _sectionValue
            });
        }
        this._scaleValueControl.ItemsSource = RangeCollection;
        LastMark = (_sectionValue + _interval_width).ToString();
        this._lastmarkTextblock.Text = RangeCollection[_interval].RangeValue.ToString();
    }
 public void AddTest2()
 {
     var c = new RangeCollection();
     var ranges = c.Ranges;
     c.Add(new AddressRange(0, 100));
     c.Add(new AddressRange(101, 200));
     Assert.Equal(1, ranges.Count);
     Assert.Equal(new AddressRange(0, 200), ranges[0]);
     c.Add(new AddressRange(300, 400));
     c.Add(new AddressRange(500, 600));
     Assert.Equal(3, ranges.Count);
     c.Add(new AddressRange(50, 205));
     Assert.Equal(3, ranges.Count);
     Assert.Equal(new AddressRange(0, 205), ranges[0]);
     c.Add(new AddressRange(-100, -1));
     Assert.Equal(3, ranges.Count);
     Assert.Equal(new AddressRange(-100, 205), ranges[0]);
     c.Add(new AddressRange(206, 299));
     Assert.Equal(2, ranges.Count);
     Assert.Equal(new AddressRange(-100, 400), ranges[0]);
     c.Add(new AddressRange(0, 600));
     Assert.Equal(1, ranges.Count);
     Assert.Equal(new AddressRange(-100, 600), ranges[0]);
 }
 public void AddTest2()
 {
     RangeCollection c = new RangeCollection();
     List<AddressRange> ranges = c.Ranges;
     c.Add(new AddressRange(0, 100));
     c.Add(new AddressRange(101, 200));
     Assert.AreEqual(1, ranges.Count, "#1");
     Assert.AreEqual(new AddressRange(0, 200), ranges[0], "#1b");
     c.Add(new AddressRange(300, 400));
     c.Add(new AddressRange(500, 600));
     Assert.AreEqual(3, ranges.Count, "#2");
     c.Add(new AddressRange(50, 205));
     Assert.AreEqual(3, ranges.Count, "#3");
     Assert.AreEqual(new AddressRange(0, 205), ranges[0], "#3b");
     c.Add(new AddressRange(-100, -1));
     Assert.AreEqual(3, ranges.Count, "#4");
     Assert.AreEqual(new AddressRange(-100, 205), ranges[0], "#4b");
     c.Add(new AddressRange(206, 299));
     Assert.AreEqual(2, ranges.Count, "#5");
     Assert.AreEqual(new AddressRange(-100, 400), ranges[0], "#5b");
     c.Add(new AddressRange(0, 600));
     Assert.AreEqual(1, ranges.Count, "#6");
     Assert.AreEqual(new AddressRange(-100, 600), ranges[0], "#6b");
 }
Esempio n. 11
0
        public void Refresh ()
        {
            int index = current_track == null ? Count : TrackModel.IndexOf (current_track);

            // If the current track is not playing refresh it too.
            if (current_track != null && !ServiceManager.PlayerEngine.IsPlaying (current_track)) {
                index--;
            }

            if (index + 1 < Count) {
                // Get the ViewOrder of the current_track
                long current_view_order = CurrentTrackViewOrder;

                // Get the list of generated tracks.
                var generated = new HashSet<long> ();
                foreach (long trackID in ServiceManager.DbConnection.QueryEnumerable<long> ( @"
                    SELECT TrackID
                    FROM CorePlaylistEntries
                    WHERE PlaylistID = ? AND Generated = 1 AND ViewOrder >= ?",
                    DbId, current_view_order)) {

                    generated.Add (trackID);
                }

                // Collect the indices of all generated tracks.
                var ranges = new RangeCollection ();
                for (int i = index + 1; i < Count; i++) {
                    if (generated.Contains (((DatabaseTrackInfo)TrackModel[i]).TrackId)) {
                        ranges.Add (i);
                    }
                }

                bool removed = false;
                foreach (var range in ranges.Ranges) {
                    RemoveTrackRange (DatabaseTrackModel, range);
                    removed = true;
                }

                if (removed) {
                    OnTracksRemoved ();
                }
            } else if (Count == 0 || current_track == null) {
                UpdatePlayQueue ();
            }
        }
Esempio n. 12
0
		void MoveExistingItems (int index, int offset)
		{
			// This is a little horrible. I should really collapse the existing
			// RangeCollection so that every > the current index is decremented by 1.
			// This is easier for now though. I may think of a better way later on.
			RangeCollection newRanges = new RangeCollection ();
			List <int> list = new List<int> ();
			for (int i = 0; i < RealizedElements.Count; i++)
				list.Add (RealizedElements [i]);
			
			if (offset > 0)
				list.Reverse ();

			foreach (int i in list) {
				int oldIndex = i;
				if (oldIndex < index) {
					newRanges.Add (oldIndex);
				} else {
					newRanges.Add (oldIndex + offset);
					var container = ContainerIndexMap [oldIndex];
					ContainerIndexMap.Remove (container, oldIndex);
					ContainerIndexMap.Add (container, oldIndex + offset);
				}
			}

			RealizedElements = newRanges;
		}
Esempio n. 13
0
        public void Refresh()
        {
            int index = current_track == null ? Count : TrackModel.IndexOf(current_track);

            // If the current track is not playing refresh it too.
            if (current_track != null && !ServiceManager.PlayerEngine.IsPlaying(current_track))
            {
                index--;
            }

            if (index + 1 < Count)
            {
                // Get the ViewOrder of the current_track
                long current_view_order = current_track == null?
                                          ServiceManager.DbConnection.Query <long> (@"
                        SELECT MAX(ViewOrder) + 1
                        FROM CorePlaylistEntries
                        WHERE PlaylistID = ?",
                                                                                    DbId
                                                                                    ) :
                                              ServiceManager.DbConnection.Query <long> (@"
                        SELECT ViewOrder
                        FROM CorePlaylistEntries
                        WHERE PlaylistID = ? AND EntryID = ?",
                                                                                        DbId, Convert.ToInt64(current_track.CacheEntryId)
                                                                                        );

                // Get the list of generated tracks.
                var generated = new HashSet <long> ();
                foreach (long trackID in ServiceManager.DbConnection.QueryEnumerable <long> (@"
                    SELECT TrackID
                    FROM CorePlaylistEntries
                    WHERE PlaylistID = ? AND Generated = 1 AND ViewOrder >= ?",
                                                                                             DbId, current_view_order))
                {
                    generated.Add(trackID);
                }

                // Collect the indices of all generated tracks.
                var ranges = new RangeCollection();
                for (int i = index + 1; i < Count; i++)
                {
                    if (generated.Contains(((DatabaseTrackInfo)TrackModel[i]).TrackId))
                    {
                        ranges.Add(i);
                    }
                }

                bool removed = false;
                foreach (var range in ranges.Ranges)
                {
                    RemoveTrackRange(DatabaseTrackModel, range);
                    removed = true;
                }

                if (removed)
                {
                    OnTracksRemoved();
                }
            }
            else if (Count == 0 || current_track == null)
            {
                UpdatePlayQueue();
            }
        }
Esempio n. 14
0
        public void LargeSequential ()
        {
            RangeCollection range = new RangeCollection ();
            int i, n = 1000000;

            for (i = 0; i < n; i++) {
                range.Add (i);
                Assert.AreEqual (1, range.RangeCount);
            }

            Assert.AreEqual (n, range.Count);

            i = 0;
            foreach (int j in range) {
                Assert.AreEqual (i++, j);
            }

            Assert.AreEqual (n, i);
        }
 public void ContainsTest()
 {
     var c = new RangeCollection();
     c.Add(new AddressRange(1, 100));
     c.Add(new AddressRange(-10, -1));
     for (var i = -15; i < 120; i++)
     {
         var shouldContain = (i >= -10 && i <= -1) || (i >= 1 && i <= 100);
         Assert.Equal(shouldContain, c.Contains(new AddressRange(i, i)));
     }
 }
Esempio n. 16
0
        public void LargeNonAdjacent ()
        {
            RangeCollection range = new RangeCollection ();
            int i, n = 1000000;

            for (i = 0; i < n; i += 2) {
                range.Add (i);
            }

            Assert.AreEqual (n / 2, range.Count);

            i = 0;
            foreach (int j in range) {
                Assert.AreEqual (i, j);
                i += 2;
            }

            Assert.AreEqual (n, i);
        }
Esempio n. 17
0
        public void RemoveSingles ()
        {
            RangeCollection range = new RangeCollection ();
            int [] indexes = new int [] { 0, 2, 4, 6, 8, 10, 12, 14 };
            foreach (int index in indexes) {
                range.Add (index);
            }

            foreach (int index in indexes) {
                Assert.AreEqual (true, range.Remove (index));
            }
        }
        public void RemoveTest()
        {
            RangeCollection c = new RangeCollection();
            c.Add(new AddressRange(0,100));
            c.Remove(new AddressRange(50, 50));
            Assert.AreEqual(2, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(0, 49), c.Ranges[0], "#2");
            Assert.AreEqual(new AddressRange(51, 100), c.Ranges[1], "#3");

            c.Remove(new AddressRange(50, 55));
            Assert.AreEqual(2, c.Ranges.Count, "#4");
            Assert.AreEqual(new AddressRange(0, 49), c.Ranges[0], "#5");
            Assert.AreEqual(new AddressRange(56, 100), c.Ranges[1], "#6");

            c.Remove(new AddressRange(45, 60));
            Assert.AreEqual(2, c.Ranges.Count, "#7");
            Assert.AreEqual(new AddressRange(0, 44), c.Ranges[0], "#8");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#9");

            c.Remove(new AddressRange(45, 60));
            Assert.AreEqual(2, c.Ranges.Count, "#10");
            Assert.AreEqual(new AddressRange(0, 44), c.Ranges[0], "#11");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#12");

            c.Remove(new AddressRange(-100, 5));
            Assert.AreEqual(2, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(6, 44), c.Ranges[0], "#1");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#1");

            c.Remove(new AddressRange(6, 15));
            Assert.AreEqual(2, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(16, 44), c.Ranges[0], "#1");
            Assert.AreEqual(new AddressRange(61, 100), c.Ranges[1], "#1");

            c.Remove(new AddressRange(70, 80));
            Assert.AreEqual(3, c.Ranges.Count, "#1");
            Assert.AreEqual(new AddressRange(16, 44), c.Ranges[0], "#1");
            Assert.AreEqual(new AddressRange(61,69), c.Ranges[1], "#1");
            Assert.AreEqual(new AddressRange(81, 100), c.Ranges[2], "#1");
        }
        public void RemoveTest()
        {
            var c = new RangeCollection();
            c.Add(new AddressRange(0, 100));
            c.Remove(new AddressRange(50, 50));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 49), c.Ranges[0]);
            Assert.Equal(new AddressRange(51, 100), c.Ranges[1]);

            c.Remove(new AddressRange(50, 55));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 49), c.Ranges[0]);
            Assert.Equal(new AddressRange(56, 100), c.Ranges[1]);

            c.Remove(new AddressRange(45, 60));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(45, 60));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(-100, 5));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(6, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(6, 15));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(16, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(70, 80));
            Assert.Equal(3, c.Ranges.Count);
            Assert.Equal(new AddressRange(16, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 69), c.Ranges[1]);
            Assert.Equal(new AddressRange(81, 100), c.Ranges[2]);
        }
 public void ContainsTest()
 {
     RangeCollection c = new RangeCollection();
     c.Add(new AddressRange(1, 100));
     c.Add(new AddressRange(-10, -1));
     for (int i = -15; i < 120; i++)
     {
         bool shouldContain = (i >= -10 && i <= -1) || (i >= 1 && i <= 100);
         Assert.AreEqual(shouldContain, c.Contains(new AddressRange(i, i)), "#1." + i);
     }
 }
Esempio n. 21
0
        public void IndexerForGoodIndexes ()
        {
            RangeCollection range = new RangeCollection ();

            /*
            Range  Idx  Value
            0-2    0 -> 0
                   1 -> 1
                   2 -> 2

            7-9    3 -> 7
                   4 -> 8
                   5 -> 9

            11-13  6 -> 11
                   7 -> 12
                   8 -> 13
            */

            range.Add (0);
            range.Add (1);
            range.Add (2);
            range.Add (7);
            range.Add (8);
            range.Add (9);
            range.Add (11);
            range.Add (12);
            range.Add (13);

            Assert.AreEqual (0, range[0]);
            Assert.AreEqual (1, range[1]);
            Assert.AreEqual (2, range[2]);
            Assert.AreEqual (7, range[3]);
            Assert.AreEqual (8, range[4]);
            Assert.AreEqual (9, range[5]);
            Assert.AreEqual (11, range[6]);
            Assert.AreEqual (12, range[7]);
            Assert.AreEqual (13, range[8]);
        }
Esempio n. 22
0
        public void IndexOf ()
        {
            RangeCollection range = new RangeCollection ();

            range.Add (0);
            range.Add (2);
            range.Add (3);
            range.Add (5);
            range.Add (6);
            range.Add (7);
            range.Add (8);
            range.Add (11);
            range.Add (12);
            range.Add (13);

            Assert.AreEqual (0, range.IndexOf (0));
            Assert.AreEqual (1, range.IndexOf (2));
            Assert.AreEqual (2, range.IndexOf (3));
            Assert.AreEqual (3, range.IndexOf (5));
            Assert.AreEqual (4, range.IndexOf (6));
            Assert.AreEqual (5, range.IndexOf (7));
            Assert.AreEqual (6, range.IndexOf (8));
            Assert.AreEqual (7, range.IndexOf (11));
            Assert.AreEqual (8, range.IndexOf (12));
            Assert.AreEqual (9, range.IndexOf (13));
            Assert.AreEqual (-1, range.IndexOf (99));
        }
Esempio n. 23
0
        public void IndexesCacheGeneration ()
        {
            RangeCollection range = new RangeCollection ();
            int [] index_cache = range.Indexes;

            Assert.AreSame (index_cache, range.Indexes);

            range.Add (0);
            range.Add (5);

            if (index_cache == range.Indexes) {
                Assert.Fail ("Indexes Cache not regenerated after change");
            }

            index_cache = range.Indexes;
            range.Remove (0);
            range.Add (3);

            if (index_cache == range.Indexes) {
                Assert.Fail ("Indexes Cache not regenerated after change");
            }
        }
Esempio n. 24
0
        private static RangeCollection _SetupTestRemoveMerges ()
        {
            RangeCollection range = new RangeCollection ();
            int [] indexes = new int [] {
                0,
                2, 3, 4, 5,
                7, 8, 9, 10, 11,
                14, 15,
                17, 18, 19
            };

            foreach (int index in indexes) {
                range.Add (index);
            }

            int i = 0;
            foreach (RangeCollection.Range r in range.Ranges) {
                switch (i++) {
                    case 0:
                        Assert.AreEqual (0, r.Start);
                        Assert.AreEqual (0, r.End);
                        break;
                    case 1:
                        Assert.AreEqual (2, r.Start);
                        Assert.AreEqual (5, r.End);
                        break;
                    case 2:
                        Assert.AreEqual (7, r.Start);
                        Assert.AreEqual (11, r.End);
                        break;
                    case 3:
                        Assert.AreEqual (14, r.Start);
                        Assert.AreEqual (15, r.End);
                        break;
                    case 4:
                        Assert.AreEqual (17, r.Start);
                        Assert.AreEqual (19, r.End);
                        break;
                    default:
                        Assert.Fail ("Should never reach here");
                        break;
                }
            }

            return range;
        }
Esempio n. 25
0
		protected override void OnPrintPage(PrintPageEventArgs e)
		{
			base.OnPrintPage(e);
			if (m_PageCount == 0)
			{
				m_HeaderHeight = this.GetHeaderHeight(e.Graphics);
				m_TitleHeight = this.GetTitleHeight(e.Graphics);
				m_FooterHeight = this.GetFooterHeight(e.Graphics);
				m_PageCount = this.PrecalculatePageCount(e);
				m_PageNo = 1;
			}

			if (m_RangeToPrint.IsEmpty())
				return;

			if ( m_BorderPen == null )
				m_BorderPen = new Pen(Color.Black);

			RectangleF area = new RectangleF(e.MarginBounds.Left,
			                                 e.MarginBounds.Top + m_HeaderHeight + (m_NextRowToPrint == RangeToPrint.Start.Row ? m_TitleHeight : 0),
			                                 e.MarginBounds.Width,
			                                 e.MarginBounds.Height - m_HeaderHeight - (m_NextRowToPrint == RangeToPrint.Start.Row ? m_TitleHeight : 0) - m_FooterHeight);

			this.DrawHeader(e.Graphics, new RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, m_HeaderHeight),
			                m_PageNo, m_PageCount);

			if ( m_PageNo == 1 )
				this.DrawTitle(e.Graphics, new RectangleF(e.MarginBounds.Left, e.MarginBounds.Top + m_HeaderHeight, e.MarginBounds.Width, m_TitleHeight),
				               m_PageNo, m_PageCount);

			List<int> columnHasTopBorder = new List<int>();
			List<int> rowHasLeftBorder = new List<int>();
			RangeCollection printedRanges = new RangeCollection();

			int pageFirstRow = m_NextRowToPrint;
			int pageFirstColumn = m_NextColumnToPrint;
			int pageLastColumn = RangeToPrint.End.Column;

			// Pre-calculate width of the table in current page
			float pageColumnWidth = 0;
			for ( int i = m_NextColumnToPrint; i <= RangeToPrint.End.Column; i++ )
			{
				float colWidth = this.GetColumnWidth(e.Graphics, i);
				if ( i == m_NextColumnToPrint && colWidth > area.Width )
					colWidth = area.Width;
				if ( pageColumnWidth + colWidth <= area.Width )
					pageColumnWidth += colWidth;
				else
					break;
			}

			// Support for fixed row repeat
			if ( RepeatFixedRows && m_Grid.ActualFixedRows > RangeToPrint.Start.Row )
				m_NextRowToPrint = RangeToPrint.Start.Row;

			float curY = area.Top;
			while (m_NextRowToPrint <= RangeToPrint.End.Row)
			{
				// If repeated rows are printed, resume printing next rows
				if ( RepeatFixedRows && m_NextRowToPrint >= m_Grid.ActualFixedRows && m_NextRowToPrint < pageFirstRow )
					m_NextRowToPrint = pageFirstRow;
				float rowHeight = this.GetRowHeight(e.Graphics, m_NextRowToPrint);
				// Check if row fits in current page
				if ( curY + rowHeight > area.Bottom )
					break;
				float curX = area.Left;
				while (m_NextColumnToPrint <= pageLastColumn)
				{
					float colWidth = this.GetColumnWidth(e.Graphics, m_NextColumnToPrint);
					// Check if column fits in current page
					if ( curX + colWidth > area.Right )
					{
						// If single column does not fit in page, force it
						if ( m_NextColumnToPrint == pageFirstColumn )
							colWidth = area.Right - curX;
						else
						{
							pageLastColumn = m_NextColumnToPrint - 1;
							break;
						}
					}
					RectangleF cellRectangle;
					Position pos = new Position(m_NextRowToPrint, m_NextColumnToPrint);
					Range range = m_Grid.PositionToCellRange(pos);

					// Check if cell is spanned
					if ( range.ColumnsCount > 1 || range.RowsCount > 1 )
					{
						Size rangeSize = m_Grid.RangeToSize(range);
						// Is the first position, draw allways
						if ( range.Start == pos )
						{
							cellRectangle = new RectangleF(curX, curY, rangeSize.Width, rangeSize.Height);
							printedRanges.Add(range);
						}
						else
						{
							// Draw only if this cell is not already drawn on current page
							if ( ! printedRanges.ContainsCell(pos) )
							{
								// Calculate offset
								float sX = curX;
								for (int i = pos.Column - 1; i >= range.Start.Column; i--)
								{
									float cw = this.GetColumnWidth(e.Graphics, i);
									sX -= cw;
								}
								float sY = curY;
								for ( int i = pos.Row - 1; i >= range.Start.Row; i-- )
								{
									float cw = this.GetRowHeight(e.Graphics, i);
									sY -= cw;
								}
								cellRectangle = new RectangleF(sX, sY, rangeSize.Width, rangeSize.Height);
								printedRanges.Add(range);
							}
							else
								cellRectangle = RectangleF.Empty;
						}
					}
					else
					{
						cellRectangle = new RectangleF(curX, curY, colWidth, rowHeight);
					}

					if ( ! cellRectangle.IsEmpty )
					{
						SourceGrid.Cells.ICellVirtual cell = this.m_Grid.GetCell(pos);
						if ( cell != null )
						{
							CellContext ctx = new CellContext(m_Grid, pos, cell);
							RectangleF clip = new RectangleF(Math.Max(cellRectangle.Left, area.Left),
							                                 Math.Max(cellRectangle.Top, area.Top),
							                                 Math.Min(cellRectangle.Right, area.Left + pageColumnWidth) - Math.Max(cellRectangle.Left, area.Left),
							                                 Math.Min(cellRectangle.Bottom, area.Bottom) - Math.Max(cellRectangle.Top, area.Top));
							Region prevClip = e.Graphics.Clip;
							try
							{
								e.Graphics.Clip = new Region(clip);
								this.DrawCell(e.Graphics, ctx, cellRectangle);
							}
							finally
							{
								// Restore clip region
								e.Graphics.Clip = prevClip;
							}
							// Check if left border can be drawn in current page
							if ( ! ContainsInRange(rowHasLeftBorder, range.Start.Row, range.End.Row)
							    && cellRectangle.Left >= area.Left )
							{
								e.Graphics.DrawLine(m_BorderPen, cellRectangle.Left, clip.Top, cellRectangle.Left, clip.Bottom);
								AddRange(rowHasLeftBorder, range.Start.Row, range.End.Row);
							}
							// Check if top border can be drawn in current page
							if ( ! ContainsInRange(columnHasTopBorder, range.Start.Column, range.End.Column)
							    && cellRectangle.Top >= area.Top )
							{
								e.Graphics.DrawLine(m_BorderPen, clip.Left,	cellRectangle.Top, clip.Right, cellRectangle.Top);
								AddRange(columnHasTopBorder, range.Start.Column, range.End.Column);
							}
							// Check if right border can be drawn in current page
							if ( cellRectangle.Right <= area.Right )
								e.Graphics.DrawLine(m_BorderPen, cellRectangle.Right, clip.Top, cellRectangle.Right, clip.Bottom);
							// Check if bottom border can be drawn in current page
							if ( cellRectangle.Bottom <= area.Bottom )
								e.Graphics.DrawLine(m_BorderPen, clip.Left, cellRectangle.Bottom, clip.Right, cellRectangle.Bottom);
						}
					}
					// Set next column position
					curX += colWidth;
					m_NextColumnToPrint++;
				}
				// Set next row Y position
				curY += rowHeight;
				m_NextRowToPrint++;
				m_NextColumnToPrint = pageFirstColumn;
			}
			// If we have not reached last column, we will continue on next page
			if ( pageLastColumn != RangeToPrint.End.Column )
			{
				m_NextRowToPrint = pageFirstRow;
				m_NextColumnToPrint = pageLastColumn + 1;
			}
			else
				m_NextColumnToPrint = RangeToPrint.Start.Column;

			this.DrawFooter(e.Graphics, new RectangleF(e.MarginBounds.Left, e.MarginBounds.Bottom - m_FooterHeight, e.MarginBounds.Width, m_FooterHeight),
			                m_PageNo, m_PageCount);
			
			// If we have not reached last row we will continue on next page
			e.HasMorePages = (m_NextRowToPrint <= RangeToPrint.End.Row);
			// If there are no more pages, release resources
			if ( e.HasMorePages )
				m_PageNo++;
		}
Esempio n. 26
0
        public void ExplicitInterface ()
        {
            ICollection<int> range = new RangeCollection ();
            range.Add (1);
            range.Add (2);
            range.Add (5);
            range.Add (6);

            Assert.AreEqual (4, range.Count);
        }
Esempio n. 27
0
        private static void _TestRanges (RangeCollection range, int [] indexes)
        {
            foreach (int index in indexes) {
                range.Add (index);
            }

            Assert.AreEqual (indexes.Length, range.Count);

            Array.Sort (indexes);

            int i = 0;
            foreach (int index in range) {
                Assert.AreEqual (indexes[i++], index);
            }

            #pragma warning disable 0618

            i = 0;
            foreach (int index in range.Indexes) {
                Assert.AreEqual (indexes[i++], index);
            }

            for (i = 0; i < range.Indexes.Length; i++) {
                Assert.AreEqual (indexes[i], range.Indexes[i]);
            }

            #pragma warning restore 0618

        }
Esempio n. 28
0
        public void NegativeIndices ()
        {
            RangeCollection c = new RangeCollection ();
            c.Add (-10);
            c.Add (-5);
            c.Add (5);
            c.Add (-8);
            c.Add (10);
            c.Add (-9);
            c.Add (-11);

            Assert.IsTrue (c.Contains(-10), "#1");
            Assert.IsTrue (c.Contains(-5), "#2");
            Assert.IsTrue (c.Contains(5), "#3");
            Assert.IsTrue (c.Contains(-8), "#4");
            Assert.AreEqual (4, c.RangeCount, "#5");
            Assert.AreEqual (new RangeCollection.Range (-11, -8), c.Ranges[0], "#6");
            Assert.AreEqual (new RangeCollection.Range (-5, -5), c.Ranges[1], "#7");
            Assert.AreEqual (new RangeCollection.Range (5, 5), c.Ranges[2], "#8");
            Assert.AreEqual (new RangeCollection.Range (10, 10), c.Ranges[3], "#9");

            Assert.AreEqual (0, c.FindRangeIndexForValue (-9), "#10");
            Assert.IsTrue (c.FindRangeIndexForValue (-7) < 0, "#11");
        }
Esempio n. 29
0
        public void IPAddressRanges ()
        {
            RangeCollection ranges = new RangeCollection ();

            int start = GetAddress ("127.0.0.1");
            int end = GetAddress ("127.0.0.50");

            for (int i = start; i <= end; i++) {
                ranges.Add (i);
            }

            Assert.IsTrue (ranges.Contains (GetAddress ("127.0.0.15")));
            Assert.IsFalse (ranges.Contains (GetAddress ("127.0.0.0")));
            Assert.IsFalse (ranges.Contains (GetAddress ("127.0.0.51")));
        }
Esempio n. 30
0
        public void StressForGoodIndexes ()
        {
            Random random = new Random (0xbeef);
            RangeCollection ranges = new RangeCollection ();
            List<int> indexes = new List<int> ();

            for (int i = 0, n = 75000; i < n; i++) {
                int value = random.Next (n);
                if (ranges.Add (value)) {
                    CollectionExtensions.SortedInsert (indexes, value);
                }
            }

            Assert.AreEqual (indexes.Count, ranges.Count);
            for (int i = 0; i < indexes.Count; i++) {
                Assert.AreEqual (indexes[i], ranges[i]);
            }
        }
Esempio n. 31
0
        private static void _TestRanges (RangeCollection range, int [] indexes)
        {
            foreach (int index in indexes) {
                range.Add (index);
            }

            Assert.AreEqual (indexes.Length, range.Count);

            Array.Sort (indexes);

            int i = 0;
            foreach (int index in range) {
                Assert.AreEqual (indexes[i++], index);
            }
        }
Esempio n. 32
0
        protected override void OnPrintPage(PrintPageEventArgs e)
        {
            base.OnPrintPage(e);
            if (m_PageCount == 0)
            {
                m_HeaderHeight = this.GetHeaderHeight(e.Graphics);
                m_TitleHeight  = this.GetTitleHeight(e.Graphics);
                m_FooterHeight = this.GetFooterHeight(e.Graphics);
                m_PageCount    = this.PrecalculatePageCount(e);
                m_PageNo       = 1;
            }

            if (m_RangeToPrint.IsEmpty())
            {
                return;
            }

            if (m_BorderPen == null)
            {
                m_BorderPen = new Pen(Color.Black);
            }

            RectangleF area = new RectangleF(e.MarginBounds.Left,
                                             e.MarginBounds.Top + m_HeaderHeight + (m_NextRowToPrint == RangeToPrint.Start.Row ? m_TitleHeight : 0),
                                             e.MarginBounds.Width,
                                             e.MarginBounds.Height - m_HeaderHeight - (m_NextRowToPrint == RangeToPrint.Start.Row ? m_TitleHeight : 0) - m_FooterHeight);

            this.DrawHeader(e.Graphics, new RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, m_HeaderHeight),
                            m_PageNo, m_PageCount);

            if (m_PageNo == 1)
            {
                this.DrawTitle(e.Graphics, new RectangleF(e.MarginBounds.Left, e.MarginBounds.Top + m_HeaderHeight, e.MarginBounds.Width, m_TitleHeight),
                               m_PageNo, m_PageCount);
            }

            List <int>      columnHasTopBorder = new List <int>();
            List <int>      rowHasLeftBorder   = new List <int>();
            RangeCollection printedRanges      = new RangeCollection();

            int pageFirstRow    = m_NextRowToPrint;
            int pageFirstColumn = m_NextColumnToPrint;
            int pageLastColumn  = RangeToPrint.End.Column;

            // Pre-calculate width of the table in current page
            float pageColumnWidth = 0;

            for (int i = m_NextColumnToPrint; i <= RangeToPrint.End.Column; i++)
            {
                float colWidth = this.GetColumnWidth(e.Graphics, i);
                if (i == m_NextColumnToPrint && colWidth > area.Width)
                {
                    colWidth = area.Width;
                }
                if (pageColumnWidth + colWidth <= area.Width)
                {
                    pageColumnWidth += colWidth;
                }
                else
                {
                    break;
                }
            }

            // Support for fixed row repeat
            if (RepeatFixedRows && m_Grid.ActualFixedRows > RangeToPrint.Start.Row)
            {
                m_NextRowToPrint = RangeToPrint.Start.Row;
            }

            float curY = area.Top;

            while (m_NextRowToPrint <= RangeToPrint.End.Row)
            {
                // If repeated rows are printed, resume printing next rows
                if (RepeatFixedRows && m_NextRowToPrint >= m_Grid.ActualFixedRows && m_NextRowToPrint < pageFirstRow)
                {
                    m_NextRowToPrint = pageFirstRow;
                }
                float rowHeight = this.GetRowHeight(e.Graphics, m_NextRowToPrint);
                // Check if row fits in current page
                if (curY + rowHeight > area.Bottom)
                {
                    break;
                }
                float curX = area.Left;
                while (m_NextColumnToPrint <= pageLastColumn)
                {
                    float colWidth = this.GetColumnWidth(e.Graphics, m_NextColumnToPrint);
                    // Check if column fits in current page
                    if (curX + colWidth > area.Right)
                    {
                        // If single column does not fit in page, force it
                        if (m_NextColumnToPrint == pageFirstColumn)
                        {
                            colWidth = area.Right - curX;
                        }
                        else
                        {
                            pageLastColumn = m_NextColumnToPrint - 1;
                            break;
                        }
                    }
                    RectangleF cellRectangle;
                    Position   pos   = new Position(m_NextRowToPrint, m_NextColumnToPrint);
                    GridRange  range = m_Grid.PositionToCellRange(pos);

                    // Check if cell is spanned
                    if (range.ColumnsCount > 1 || range.RowsCount > 1)
                    {
                        Size rangeSize = m_Grid.RangeToSize(range);
                        // Is the first position, draw allways
                        if (range.Start == pos)
                        {
                            cellRectangle = new RectangleF(curX, curY, rangeSize.Width, rangeSize.Height);
                            printedRanges.Add(range);
                        }
                        else
                        {
                            // Draw only if this cell is not already drawn on current page
                            if (!printedRanges.ContainsCell(pos))
                            {
                                // Calculate offset
                                float sX = curX;
                                for (int i = pos.Column - 1; i >= range.Start.Column; i--)
                                {
                                    float cw = this.GetColumnWidth(e.Graphics, i);
                                    sX -= cw;
                                }
                                float sY = curY;
                                for (int i = pos.Row - 1; i >= range.Start.Row; i--)
                                {
                                    float cw = this.GetRowHeight(e.Graphics, i);
                                    sY -= cw;
                                }
                                cellRectangle = new RectangleF(sX, sY, rangeSize.Width, rangeSize.Height);
                                printedRanges.Add(range);
                            }
                            else
                            {
                                cellRectangle = RectangleF.Empty;
                            }
                        }
                    }
                    else
                    {
                        cellRectangle = new RectangleF(curX, curY, colWidth, rowHeight);
                    }

                    if (!cellRectangle.IsEmpty)
                    {
                        SourceGrid.Cells.ICellVirtual cell = this.m_Grid.GetCell(pos);
                        if (cell != null)
                        {
                            CellContext ctx  = new CellContext(m_Grid, pos, cell);
                            RectangleF  clip = new RectangleF(Math.Max(cellRectangle.Left, area.Left),
                                                              Math.Max(cellRectangle.Top, area.Top),
                                                              Math.Min(cellRectangle.Right, area.Left + pageColumnWidth) - Math.Max(cellRectangle.Left, area.Left),
                                                              Math.Min(cellRectangle.Bottom, area.Bottom) - Math.Max(cellRectangle.Top, area.Top));
                            Region prevClip = e.Graphics.Clip;
                            try
                            {
                                e.Graphics.Clip = new Region(clip);
                                this.DrawCell(e.Graphics, ctx, cellRectangle);
                            }
                            finally
                            {
                                // Restore clip region
                                e.Graphics.Clip = prevClip;
                            }
                            // Check if left border can be drawn in current page
                            if (!ContainsInRange(rowHasLeftBorder, range.Start.Row, range.End.Row) &&
                                cellRectangle.Left >= area.Left)
                            {
                                e.Graphics.DrawLine(m_BorderPen, cellRectangle.Left, clip.Top, cellRectangle.Left, clip.Bottom);
                                AddRange(rowHasLeftBorder, range.Start.Row, range.End.Row);
                            }
                            // Check if top border can be drawn in current page
                            if (!ContainsInRange(columnHasTopBorder, range.Start.Column, range.End.Column) &&
                                cellRectangle.Top >= area.Top)
                            {
                                e.Graphics.DrawLine(m_BorderPen, clip.Left, cellRectangle.Top, clip.Right, cellRectangle.Top);
                                AddRange(columnHasTopBorder, range.Start.Column, range.End.Column);
                            }
                            // Check if right border can be drawn in current page
                            if (cellRectangle.Right <= area.Right)
                            {
                                e.Graphics.DrawLine(m_BorderPen, cellRectangle.Right, clip.Top, cellRectangle.Right, clip.Bottom);
                            }
                            // Check if bottom border can be drawn in current page
                            if (cellRectangle.Bottom <= area.Bottom)
                            {
                                e.Graphics.DrawLine(m_BorderPen, clip.Left, cellRectangle.Bottom, clip.Right, cellRectangle.Bottom);
                            }
                        }
                    }
                    // Set next column position
                    curX += colWidth;
                    m_NextColumnToPrint++;
                }
                // Set next row Y position
                curY += rowHeight;
                m_NextRowToPrint++;
                m_NextColumnToPrint = pageFirstColumn;
            }
            // If we have not reached last column, we will continue on next page
            if (pageLastColumn != RangeToPrint.End.Column)
            {
                m_NextRowToPrint    = pageFirstRow;
                m_NextColumnToPrint = pageLastColumn + 1;
            }
            else
            {
                m_NextColumnToPrint = RangeToPrint.Start.Column;
            }

            this.DrawFooter(e.Graphics, new RectangleF(e.MarginBounds.Left, e.MarginBounds.Bottom - m_FooterHeight, e.MarginBounds.Width, m_FooterHeight),
                            m_PageNo, m_PageCount);

            // If we have not reached last row we will continue on next page
            e.HasMorePages = (m_NextRowToPrint <= RangeToPrint.End.Row);
            // If there are no more pages, release resources
            if (e.HasMorePages)
            {
                m_PageNo++;
            }
        }
Esempio n. 33
0
 public void IndexerForPositiveBadIndex ()
 {
     RangeCollection range = new RangeCollection ();
     range.Add (1);
     Assert.AreEqual (0, range[1]);
 }