~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Unused/ICSharpCode.TextEditor/src/Document/Selection/DefaultSelection.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// <file>
 
2
//     <copyright see="prj:///doc/copyright.txt"/>
 
3
//     <license see="prj:///doc/license.txt"/>
 
4
//     <owner name="Mike Krger" email="mike@icsharpcode.net"/>
 
5
//     <version value="$version"/>
 
6
// </file>
 
7
 
 
8
using System;
 
9
using System.Drawing;
 
10
 
 
11
namespace MonoDevelop.TextEditor.Document
 
12
{
 
13
        /// <summary>
 
14
        /// Default implementation of the <see cref="MonoDevelop.TextEditor.Document.ISelection"/> interface.
 
15
        /// </summary>
 
16
        public class DefaultSelection : ISelection
 
17
        {
 
18
                IDocument document = null;
 
19
                bool      isRectangularSelection = false;
 
20
                Point     startPosition = new Point(-1, -1);
 
21
                Point     endPosition   = new Point(-1, -1);
 
22
                
 
23
                public Point StartPosition {
 
24
                        get {
 
25
                                return startPosition;
 
26
                        }
 
27
                        set {
 
28
                                startPosition = value;
 
29
                        }
 
30
                }
 
31
                
 
32
                public Point EndPosition {
 
33
                        get {
 
34
                                return endPosition;
 
35
                        }
 
36
                        set {
 
37
                                endPosition = value;
 
38
                        }
 
39
                }
 
40
                
 
41
                public int Offset {
 
42
                        get {
 
43
                                return document.PositionToOffset(startPosition);
 
44
                        }
 
45
                }
 
46
                
 
47
                public int EndOffset {
 
48
                        get {
 
49
                                return document.PositionToOffset(endPosition);
 
50
                        }
 
51
                }
 
52
                
 
53
                public int Length {
 
54
                        get {
 
55
                                return EndOffset - Offset;
 
56
                        }
 
57
                }
 
58
                
 
59
                /// <value>
 
60
                /// Returns true, if the selection is empty
 
61
                /// </value>
 
62
                public bool IsEmpty {
 
63
                        get {
 
64
                                return startPosition == endPosition;
 
65
                        }
 
66
                }
 
67
                
 
68
                /// <value>
 
69
                /// Returns true, if the selection is rectangular
 
70
                /// </value>
 
71
                // TODO : make this unused property used.
 
72
                public bool IsRectangularSelection {
 
73
                        get {
 
74
                                return isRectangularSelection;
 
75
                        }
 
76
                        set {
 
77
                                isRectangularSelection = value;
 
78
                        }
 
79
                }
 
80
                
 
81
                /// <value>
 
82
                /// The text which is selected by this selection.
 
83
                /// </value>
 
84
                public string SelectedText {
 
85
                        get {
 
86
                                if (document != null) {
 
87
                                        if (Length < 0) {
 
88
                                                return null;
 
89
                                        }
 
90
                                        return document.GetText(Offset, Length);
 
91
                                }
 
92
                                return null;
 
93
                        }
 
94
                }
 
95
                
 
96
                /// <summary>
 
97
                /// Creates a new instance of <see cref="DefaultSelection"/>
 
98
                /// </summary>  
 
99
                public DefaultSelection(IDocument document, Point startPosition, Point endPosition)
 
100
                {
 
101
                        this.document      = document;
 
102
                        this.startPosition = startPosition;
 
103
                        this.endPosition   = endPosition;
 
104
                }
 
105
                
 
106
                /// <summary>
 
107
                /// Converts a <see cref="DefaultSelection"/> instance to string (for debug purposes)
 
108
                /// </summary>
 
109
                public override string ToString()
 
110
                {
 
111
                        return String.Format("[DefaultSelection : StartPosition={0}, EndPosition={1}]", startPosition, endPosition);
 
112
                }
 
113
                public bool ContainsPosition(Point position)
 
114
                {
 
115
                        return startPosition.Y < position.Y && position.Y  < endPosition.Y ||
 
116
                               startPosition.Y == position.Y && startPosition.X <= position.X && (startPosition.Y != endPosition.Y || position.X <= endPosition.X) ||
 
117
                               endPosition.Y == position.Y && startPosition.Y != endPosition.Y && position.X <= endPosition.X;
 
118
                }
 
119
                
 
120
                public bool ContainsOffset(int offset)
 
121
                {
 
122
                        return Offset <= offset && offset <= EndOffset;
 
123
                }
 
124
        }
 
125
}