Ejemplo n.º 1
0
        public void TestStaticCreation()
        {
            NSPoint refPoint = new NSPoint(1, 2);
            NSValue val = NSValue.ValueWithPoint(refPoint);
            Check(val);
            NSPoint point = val.PointValue;
            Assert.AreEqual(refPoint, point, "Points must be equal");

            NSRange refRange = new NSRange(3, 4);
            val = NSValue.ValueWithRange(refRange);
            Check(val);
            NSRange range = val.RangeValue;
            Assert.AreEqual(refRange, range, "Ranges must be equal");

            NSRect refRect = new NSRect(5, 6, 789, 789);
            val = NSValue.ValueWithRect(refRect);
            Check(val);
            NSRect rect = val.RectValue;
            Assert.AreEqual(refRect, rect, "Rectangles must be equal");

            NSSize refSize = new NSSize(456, 789);
            val = NSValue.ValueWithSize(refSize);
            Check(val);
            NSSize size = val.SizeValue;
            Assert.AreEqual(refSize, size, "Sizes must be equal");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the intersection of the specified ranges.
        /// </summary>
        /// <remarks>Original declaration is : NSRange NSIntersectionRange(NSRange range1, NSRange range2)</remarks>
        public static NSRange NSIntersectionRange(NSRange range1, NSRange range2)
        {
            uint max1 = NSMaxRange(range1);
            uint max2 = NSMaxRange(range1);

            uint max = (max1 < max2) ? max1 : max2;
            uint location = (range1.location > range2.location) ? range1.location : range2.location;

            return max < location ? NSZeroRange : new NSRange(location, max-location);
        }
Ejemplo n.º 3
0
 public static void SetTextColor(this NSButton button, NSColor textColor)
 {
     NSMutableAttributedString attrTitle = new NSMutableAttributedString(button.AttributedTitle);
     NSUInteger len = attrTitle.Length;
     NSRange range = new NSRange(0, len);
     attrTitle.AddAttributeValueRange(NSAttributedString_AppKitAdditions.NSForegroundColorAttributeName, textColor, range);
     attrTitle.FixAttributesInRange(range);
     button.AttributedTitle = attrTitle;
     attrTitle.Release();
 }
Ejemplo n.º 4
0
 public static NSColor TextColor(this NSButton button)
 {
     NSAttributedString attrTitle = button.AttributedTitle;
     NSUInteger len = attrTitle.Length;
     NSRange range = new NSRange(0, Math.Min((uint)len, 1));
     NSDictionary attrs = attrTitle.AttributesAtIndexEffectiveRange(0, ref range);
     NSColor textColor = NSColor.ControlTextColor;
     if (attrs != null) {
         textColor = attrs.ValueForKey<NSColor>(NSAttributedString_AppKitAdditions.NSForegroundColorAttributeName);
     }
     return textColor;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns the number 1 greater than the maximum value within the range.
 /// </summary>
 /// <remarks>Original declaration is : unsigned int NSMaxRange(NSRange range)</remarks>
 public static uint NSMaxRange(NSRange range)
 {
     return (range.location + range.length);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns a Boolean value that indicates whether a specified position is in a given range.
        /// </summary>
        /// <remarks>Original declaration is : BOOL NSLocationInRange(unsigned int index, NSRange aRange)</remarks>
		public static bool NSLocationInRange(NSUInteger index, NSRange aRange)
        {
            return ((index >= aRange.location) && (index < (aRange.location + aRange.length)));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns a Boolean value that indicates whether two given ranges are equal.
 /// </summary>
 /// <remarks>Original declaration is : BOOL NSEqualRanges(NSRange range1, NSRange range2)</remarks>
 public static bool NSEqualRanges(NSRange range1,
                                  NSRange range2)
 {
     return Equals(range1, range2);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns the intersection of the specified ranges.
        /// </summary>
        /// <remarks>Original declaration is : NSRange NSUnionRange(NSRange range1, NSRange range2)</remarks>
        public static NSRange NSUnionRange(NSRange range1, NSRange range2)
        {
            uint max1 = NSMaxRange(range1);
            uint max2 = NSMaxRange(range1);

            uint max = (max1 > max2) ? max1 : max2;
            uint location = (range1.location < range2.location) ? range1.location : range2.location;

            return new NSRange(location, max - location);
        }
Ejemplo n.º 9
0
 public static extern NSString NSStringFromRange(NSRange aRange);
        public void SpeechSynthesizerWillSpeakWordOfString(NSSpeechSynthesizer sender, NSRange characterRange, NSString str)
        {
            UInt32 selectionPosition = characterRange.location + this._offsetToSpokenText;
            UInt32 wordLength = characterRange.length;

            this._textToSpeechExampleTextView.ScrollRangeToVisible(NSRange.NSMakeRange(selectionPosition, wordLength));
            this._textToSpeechExampleTextView.SelectedRange = NSRange.NSMakeRange(selectionPosition, wordLength);
            this._textToSpeechExampleTextView.Display();
        }
        public void StartSpeakingTextViewToURL(NSURL url)
        {
            if (this._speechSynthesizer.IsSpeaking)
            {
                this._speechSynthesizer.StopSpeaking();
            }
            else
            {
                // Grab the selection substring, or if no selection then grab entire text.
                this._orgSelectionRange = this._textToSpeechExampleTextView.SelectedRange;

                NSString theViewText;
                if (this._orgSelectionRange.length == 0)
                {
                    theViewText = this._textToSpeechExampleTextView.String;
                    this._offsetToSpokenText = 0;
                }
                else
                {
                    theViewText = this._textToSpeechExampleTextView.String.SubstringWithRange(this._orgSelectionRange);
                    this._offsetToSpokenText = this._orgSelectionRange.location;
                }

                if (this._voicePop.IndexOfSelectedItem == 0)
                {
                    // Pass NULL as the voice to use the system voice.
                    this._speechSynthesizer.SetVoice(null);
                }
                else
                {
                    this._speechSynthesizer.SetVoice(NSSpeechSynthesizer.AvailableVoices.ObjectAtIndex((uint) this._voicePop.IndexOfSelectedItem - kNumOfFixedMenuItemsInVoicePopup).CastTo<NSString>());
                }

                if (url != null)
                {
                    this._speechSynthesizer.StartSpeakingStringToURL(theViewText, url);
                    this._textToSpeechExampleSpeakButton.IsEnabled = false;
                    this._saveButton.Title = FoundationFramework.NSLocalizedString("Stop Saving", "Save file button name (stop)");
                }
                else
                {
                    this._speechSynthesizer.StartSpeakingString(theViewText);
                    this._textToSpeechExampleSpeakButton.Title = FoundationFramework.NSLocalizedString("Stop Speaking", "Speaking button name (stop)");
                    this._saveButton.IsEnabled = false;
                }
                this._voicePop.IsEnabled = false;
            }
        }
Ejemplo n.º 12
0
        public NSArray ControlTextViewCompletionsForPartialWordRangeIndexOfSelectedItem(NSControl control, NSTextView textView, NSArray words, NSRange charRange, ref int index)
        {
            NSMutableArray matches;
            NSString partialString;
            NSArray keywords;
            int i;
            uint count;
            NSString str;

            partialString = textView.String.SubstringWithRange(charRange);
            keywords = this.AllKeywords();
            count = keywords.Count;
            matches = new NSMutableArray();

            // find any match in our keyword array against what was typed
            for (i = 0; i < count; i++)
            {
                str = keywords[i].CastTo<NSString>();
                if (str.RangeOfStringOptionsRange(partialString, NSStringCompareOptions.NSAnchoredSearch | NSStringCompareOptions.NSCaseInsensitiveSearch, NSRange.NSMakeRange(0, str.Length)).location != NSUInteger.NSNotFound)
                {
                    matches.AddObject(str);
                }
            }
            matches.SortUsingSelector(ObjectiveCRuntime.Selector("compare:"));

            return matches;
        }