-
-
Save chamons/cc82b52b1bd5266252aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Drawing; | |
using MonoMac.Foundation; | |
using MonoMac.AppKit; | |
using MonoMac.ObjCRuntime; | |
using System.Runtime.InteropServices; | |
using System.Linq; | |
namespace ClassicTest | |
{ | |
public static class NSLayoutManagerPatch | |
{ | |
// - (NSRectArray)rectArrayForGlyphRange:(NSRange)glyphRange withinSelectedGlyphRange:(NSRange)selGlyphRange inTextContainer:(NSTextContainer *)container rectCount:(NSUInteger *)rectCount | |
static IntPtr sel = Selector.GetHandle ("rectArrayForGlyphRange:withinSelectedGlyphRange:inTextContainer:rectCount:"); | |
[DllImport ("/usr/lib/libobjc.dylib", EntryPoint="objc_msgSend")] | |
public extern static IntPtr IntPtr_objc_msgSend (IntPtr receiver, IntPtr selector, NSRange glyphRange, NSRange selectedGlyphRange, IntPtr textContainerHandle, out uint rectCount); | |
public unsafe static RectangleF [] RectArrayForGlyphRange (this NSLayoutManager manager, NSRange glyphRange, NSRange selectedGlyphRange, NSTextContainer textContainer) | |
{ | |
uint rectCount; | |
IntPtr retHandle = IntPtr_objc_msgSend (manager.Handle, sel, glyphRange, selectedGlyphRange, textContainer.Handle, out rectCount); | |
RectangleF[] returnArray = new RectangleF [rectCount]; | |
float * ptr = (float*)retHandle; | |
for (int i = 0; i < rectCount; ++i) { | |
returnArray [i] = new RectangleF (ptr [0], ptr [1], ptr [2], ptr [3]); | |
ptr += 4; | |
} | |
return returnArray; | |
} | |
} | |
public partial class AppDelegate : NSApplicationDelegate | |
{ | |
MainWindowController mainWindowController; | |
public AppDelegate () | |
{ | |
} | |
public override void DidFinishLaunching (NSNotification notification) | |
{ | |
mainWindowController = new MainWindowController (); | |
mainWindowController.Window.MakeKeyAndOrderFront (this); | |
NSTextView v = new NSTextView (new RectangleF (0, 0, 100, 100)); | |
v.InsertText ((NSString)"Hello world"); | |
NSTextView v2 = new NSTextView (new RectangleF (0, 0, 100, 100)); | |
v2.InsertText ((NSString)"Goodbye world"); | |
mainWindowController.Window.ContentView.AddSubview (v); | |
mainWindowController.Window.ContentView.AddSubview (v2); | |
NSTextContainer first = v.TextContainer; | |
NSTextContainer second = v2.TextContainer; | |
NSLayoutManager mgr = v.LayoutManager; | |
mgr.AddTextContainer (first); | |
mgr.InsertTextContainer (second, 1); | |
RectangleF [] vals = mgr.RectArrayForGlyphRange (new NSRange (1, 3), new NSRange (2, 4), first); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment