Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
Conflicts:
	ExampleProject/Example.xcodeproj/project.pbxproj
	lib/UIKit/TUITableView.m
  • Loading branch information
Brian William Wolter committed Aug 12, 2011
2 parents 31cf422 + e99ab84 commit ef6580d
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 44 deletions.
6 changes: 6 additions & 0 deletions ExampleProject/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
5C782FD713A556A900CF69EF /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C782FD613A556A800CF69EF /* QuartzCore.framework */; };
5C78300513A577B100CF69EF /* TUICGAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5C78300413A5778500CF69EF /* TUICGAdditions.m */; };
5C90DB9D13A7C08E00ECDD14 /* ExampleTabBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 5C90DB9C13A7C08D00ECDD14 /* ExampleTabBar.m */; };
5ED06F2C13F4C98800B34CAE /* TUITextViewEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = 5ED06F2B13F4C98800B34CAE /* TUITextViewEditor.m */; };
5ED56678139DC30300031CDF /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5ED56677139DC30300031CDF /* Cocoa.framework */; };
5ED56682139DC30300031CDF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5ED56680139DC30300031CDF /* InfoPlist.strings */; };
5ED56685139DC30300031CDF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5ED56684139DC30300031CDF /* main.m */; };
Expand Down Expand Up @@ -84,6 +85,8 @@
5C78300413A5778500CF69EF /* TUICGAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUICGAdditions.m; sourceTree = "<group>"; };
5C90DB9B13A7C08D00ECDD14 /* ExampleTabBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleTabBar.h; sourceTree = "<group>"; };
5C90DB9C13A7C08D00ECDD14 /* ExampleTabBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleTabBar.m; sourceTree = "<group>"; };
5ED06F2A13F4C98800B34CAE /* TUITextViewEditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUITextViewEditor.h; sourceTree = "<group>"; };
5ED06F2B13F4C98800B34CAE /* TUITextViewEditor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUITextViewEditor.m; sourceTree = "<group>"; };
5ED56673139DC30300031CDF /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
5ED56677139DC30300031CDF /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
5ED5667A139DC30300031CDF /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -357,6 +360,8 @@
5ED566E5139DC35100031CDF /* TUITextView.m */,
5ED566E2139DC35100031CDF /* TUITextRenderer.h */,
5ED566E3139DC35100031CDF /* TUITextRenderer.m */,
5ED06F2A13F4C98800B34CAE /* TUITextViewEditor.h */,
5ED06F2B13F4C98800B34CAE /* TUITextViewEditor.m */,
5ED566DF139DC35100031CDF /* TUITextRenderer+Event.h */,
5ED566E0139DC35100031CDF /* TUITextRenderer+Event.m */,
5ED566E1139DC35100031CDF /* TUITextRenderer+KeyBindings.m */,
Expand Down Expand Up @@ -489,6 +494,7 @@
5C90DB9D13A7C08E00ECDD14 /* ExampleTabBar.m in Sources */,
D3CE671313C6646B00D47B2D /* ExampleSectionHeaderView.m in Sources */,
D3502AAE13EA0FE4007C5CA7 /* TUITableView+Cell.m in Sources */,
5ED06F2C13F4C98800B34CAE /* TUITextViewEditor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
16 changes: 16 additions & 0 deletions TwUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
88CC1F3A13E3684700827793 /* TUIButton+Accessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC1F3613E3684600827793 /* TUIButton+Accessibility.m */; };
88CC1F3B13E3684700827793 /* TUIButton+Accessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC1F3613E3684600827793 /* TUIButton+Accessibility.m */; };
88CC1F3C13E3684700827793 /* TUIButton+Accessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC1F3613E3684600827793 /* TUIButton+Accessibility.m */; };
88EFFB5113F417E200CF91A9 /* TUITextViewEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = 88EFFB4F13F417E200CF91A9 /* TUITextViewEditor.h */; };
88EFFB5213F417E200CF91A9 /* TUITextViewEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = 88EFFB4F13F417E200CF91A9 /* TUITextViewEditor.h */; };
88EFFB5313F417E200CF91A9 /* TUITextViewEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = 88EFFB4F13F417E200CF91A9 /* TUITextViewEditor.h */; };
88EFFB5413F417E200CF91A9 /* TUITextViewEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EFFB5013F417E200CF91A9 /* TUITextViewEditor.m */; };
88EFFB5513F417E200CF91A9 /* TUITextViewEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EFFB5013F417E200CF91A9 /* TUITextViewEditor.m */; };
88EFFB5613F417E200CF91A9 /* TUITextViewEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EFFB5013F417E200CF91A9 /* TUITextViewEditor.m */; };
CB5B265A13BE6DA200579B1E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = CB5B265813BE6DA200579B1E /* InfoPlist.strings */; };
CB5B266313BE6DA300579B1E /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB5B266213BE6DA300579B1E /* SenTestingKit.framework */; };
CB5B266413BE6DA300579B1E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB5B264F13BE6DA200579B1E /* Cocoa.framework */; };
Expand Down Expand Up @@ -258,6 +264,8 @@
88CC1F2E13E365B500827793 /* TUIControl+Accessibility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TUIControl+Accessibility.m"; sourceTree = "<group>"; };
88CC1F3513E3684400827793 /* TUIButton+Accessibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUIButton+Accessibility.h"; sourceTree = "<group>"; };
88CC1F3613E3684600827793 /* TUIButton+Accessibility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TUIButton+Accessibility.m"; sourceTree = "<group>"; };
88EFFB4F13F417E200CF91A9 /* TUITextViewEditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUITextViewEditor.h; sourceTree = "<group>"; };
88EFFB5013F417E200CF91A9 /* TUITextViewEditor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUITextViewEditor.m; sourceTree = "<group>"; };
CB5B264C13BE6DA200579B1E /* TwUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TwUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CB5B264F13BE6DA200579B1E /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
CB5B265213BE6DA200579B1E /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -586,6 +594,8 @@
CBB74C7D13BE6E1900C85CB5 /* TUITextRenderer.m */,
CBB74C7E13BE6E1900C85CB5 /* TUITextView.h */,
CBB74C7F13BE6E1900C85CB5 /* TUITextView.m */,
88EFFB4F13F417E200CF91A9 /* TUITextViewEditor.h */,
88EFFB5013F417E200CF91A9 /* TUITextViewEditor.m */,
CBB74C8013BE6E1900C85CB5 /* TUITooltipWindow.h */,
CBB74C8113BE6E1900C85CB5 /* TUITooltipWindow.m */,
8819794213E26E0200AA39EB /* TUIView+Accessibility.h */,
Expand Down Expand Up @@ -622,6 +632,7 @@
8819794E13E26E5800AA39EB /* TUINSView+Accessibility.h in Headers */,
88CC1F3113E365B600827793 /* TUIControl+Accessibility.h in Headers */,
88CC1F3913E3684700827793 /* TUIButton+Accessibility.h in Headers */,
88EFFB5313F417E200CF91A9 /* TUITextViewEditor.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -675,6 +686,7 @@
8819794C13E26E5800AA39EB /* TUINSView+Accessibility.h in Headers */,
88CC1F2F13E365B600827793 /* TUIControl+Accessibility.h in Headers */,
88CC1F3713E3684700827793 /* TUIButton+Accessibility.h in Headers */,
88EFFB5113F417E200CF91A9 /* TUITextViewEditor.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -687,6 +699,7 @@
8819794D13E26E5800AA39EB /* TUINSView+Accessibility.h in Headers */,
88CC1F3013E365B600827793 /* TUIControl+Accessibility.h in Headers */,
88CC1F3813E3684700827793 /* TUIButton+Accessibility.h in Headers */,
88EFFB5213F417E200CF91A9 /* TUITextViewEditor.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -884,6 +897,7 @@
8819795113E26E5800AA39EB /* TUINSView+Accessibility.m in Sources */,
88CC1F3413E365B600827793 /* TUIControl+Accessibility.m in Sources */,
88CC1F3C13E3684700827793 /* TUIButton+Accessibility.m in Sources */,
88EFFB5613F417E200CF91A9 /* TUITextViewEditor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -942,6 +956,7 @@
8819794F13E26E5800AA39EB /* TUINSView+Accessibility.m in Sources */,
88CC1F3213E365B600827793 /* TUIControl+Accessibility.m in Sources */,
88CC1F3A13E3684700827793 /* TUIButton+Accessibility.m in Sources */,
88EFFB5413F417E200CF91A9 /* TUITextViewEditor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1009,6 +1024,7 @@
8819795013E26E5800AA39EB /* TUINSView+Accessibility.m in Sources */,
88CC1F3313E365B600827793 /* TUIControl+Accessibility.m in Sources */,
88CC1F3B13E3684700827793 /* TUIButton+Accessibility.m in Sources */,
88EFFB5513F417E200CF91A9 /* TUITextViewEditor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 1 addition & 0 deletions lib/UIKit/TUINSView.m
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ - (void)rightMouseDown:(NSEvent *)event
_trackingView = [[self viewForEvent:event] retain];
[_trackingView rightMouseDown:event];
[TUITooltipWindow endTooltip];
[super rightMouseDown:event]; // we need to send this up the responder chain so that -menuForEvent: will get called for two-finger taps
}

- (void)rightMouseUp:(NSEvent *)event
Expand Down
2 changes: 1 addition & 1 deletion lib/UIKit/TUIStringDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#if TARGET_OS_MAC
// for ABRowView
- (CGSize)drawInRect:(CGRect)rect withFont:(TUIFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment;
//- (CGSize)drawInRect:(CGRect)rect withFont:(TUIFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment;
#endif

- (CGSize)ab_drawInRect:(CGRect)rect color:(TUIColor *)color font:(TUIFont *)font;
Expand Down
8 changes: 4 additions & 4 deletions lib/UIKit/TUIStringDrawing.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ - (CGSize)ab_sizeWithFont:(TUIFont *)font constrainedToSize:(CGSize)size
return [s ab_sizeConstrainedToSize:size];
}

- (CGSize)drawInRect:(CGRect)rect withFont:(TUIFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment
{
return [self ab_drawInRect:rect withFont:font lineBreakMode:lineBreakMode alignment:alignment];
}
//- (CGSize)drawInRect:(CGRect)rect withFont:(TUIFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment
//{
// return [self ab_drawInRect:rect withFont:font lineBreakMode:lineBreakMode alignment:alignment];
//}

#endif

Expand Down
8 changes: 6 additions & 2 deletions lib/UIKit/TUITableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef enum {

@optional

- (void)tableView:(TUITableView *)tableView willDisplayCell:(TUITableViewCell *)cell forRowAtIndexPath:(TUIFastIndexPath *)indexPath; // not implemented yet
- (void)tableView:(TUITableView *)tableView willDisplayCell:(TUITableViewCell *)cell forRowAtIndexPath:(TUIFastIndexPath *)indexPath; // called after the cell's frame has been set but before it's added as a subview
- (void)tableView:(TUITableView *)tableView didSelectRowAtIndexPath:(TUIFastIndexPath *)indexPath; // happens on left/right mouse down, key up/down
- (void)tableView:(TUITableView *)tableView didDeselectRowAtIndexPath:(TUIFastIndexPath *)indexPath;
- (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent *)event; // happens on left/right mouse up (can look at clickCount)
Expand Down Expand Up @@ -180,7 +180,11 @@ typedef enum {

@optional

- (TUITableViewCell *)tableView:(TUITableView *)tableView headerViewForSection:(NSInteger)section;
- (TUIView *)tableView:(TUITableView *)tableView headerViewForSection:(NSInteger)section;

// the following are required to support row reordering
- (BOOL)tableView:(TUITableView *)tableView canMoveRowAtIndexPath:(TUIFastIndexPath *)indexPath;
- (void)tableView:(TUITableView *)tableView moveRowAtIndexPath:(TUIFastIndexPath *)fromIndexPath toIndexPath:(TUIFastIndexPath *)toIndexPath;

// the following are required to support row reordering
- (BOOL)tableView:(TUITableView *)tableView canMoveRowAtIndexPath:(TUIFastIndexPath *)indexPath;
Expand Down
64 changes: 37 additions & 27 deletions lib/UIKit/TUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#import "TUITableView+Cell.h"
#import "TUINSView.h"

// header views need to be above the cells at all times
#define HEADER_Z_POSITION 1000

typedef struct {
CGFloat offset; // from beginning of section
CGFloat height;
Expand Down Expand Up @@ -131,6 +134,7 @@ - (TUIView *)headerView
if(_tableView.dataSource != nil && [_tableView.dataSource respondsToSelector:@selector(tableView:headerViewForSection:)]){
_headerView = [[_tableView.dataSource tableView:_tableView headerViewForSection:sectionIndex] retain];
_headerView.autoresizingMask = TUIViewAutoresizingFlexibleWidth;
_headerView.layer.zPosition = HEADER_Z_POSITION;
}
}
return _headerView;
Expand Down Expand Up @@ -662,52 +666,54 @@ - (BOOL)_preLayoutCells
*/
- (void)_layoutSectionHeaders:(BOOL)visibleHeadersNeedRelayout
{
if(visibleHeadersNeedRelayout) {
if(_visibleSectionHeaders != nil){
[_visibleSectionHeaders enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) {
if(index < [_sectionInfo count]) {
TUITableViewSection *section = [_sectionInfo objectAtIndex:index];
if(section.headerView != nil) {
section.headerView.frame = [self rectForHeaderOfSection:index];
[section.headerView setNeedsLayout];
}
}
}];
}
}

CGRect visible = [self visibleRect];

NSIndexSet *oldIndexes = _visibleSectionHeaders;
NSIndexSet *newIndexes = [self indexesOfSectionHeadersInRect:visible];
NSIndexSet *newIndexes = [self indexesOfSectionsInRect:visible];

NSMutableIndexSet *toRemove = [[oldIndexes mutableCopy] autorelease];
[toRemove removeIndexes:newIndexes];
NSMutableIndexSet *toAdd = [[newIndexes mutableCopy] autorelease];
[toAdd removeIndexes:oldIndexes];

// remove offscreen headers
[toRemove enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) {
// update the placement of all visible headers
__block TUIView *pinnedHeader = nil;
[newIndexes enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) {
if(index < [_sectionInfo count]) {
TUITableViewSection *section = [_sectionInfo objectAtIndex:index];
if(section.headerView != nil) {
[section.headerView removeFromSuperview];
CGRect headerFrame = [self rectForHeaderOfSection:index];

// check if this header needs to be pinned
if(CGRectGetMaxY(headerFrame) > CGRectGetMaxY(visible)) {
headerFrame.origin.y = CGRectGetMaxY(visible) - headerFrame.size.height;
pinnedHeader = section.headerView;
}
else if((pinnedHeader != nil) && (CGRectGetMaxY(headerFrame) > pinnedHeader.frame.origin.y)) {
// this header is intersecting with the pinned header, so we push the pinned header upwards.
CGRect pinnedHeaderFrame = pinnedHeader.frame;
pinnedHeaderFrame.origin.y = CGRectGetMaxY(headerFrame);
pinnedHeader.frame = pinnedHeaderFrame;
}

section.headerView.frame = headerFrame;
[section.headerView setNeedsLayout];

if (section.headerView.superview == nil)
[self addSubview:section.headerView];
}
}
[_visibleSectionHeaders removeIndex:index];
[_visibleSectionHeaders addIndex:index];
}];

// add new headers
[toAdd enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) {
if(index < [_sectionInfo count]){
// remove offscreen headers
[toRemove enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) {
if(index < [_sectionInfo count]) {
TUITableViewSection *section = [_sectionInfo objectAtIndex:index];
if(section.headerView != nil) {
section.headerView.frame = [self rectForHeaderOfSection:index];
[section.headerView setNeedsLayout];
[self addSubview:section.headerView];
[section.headerView removeFromSuperview];
}
}
[_visibleSectionHeaders addIndex:index];
[_visibleSectionHeaders removeIndex:index];
}];
}

Expand Down Expand Up @@ -767,6 +773,10 @@ - (void)_layoutCells:(BOOL)visibleCellsNeedRelayout
[cell setSelected:NO animated:NO];
}

if(_tableFlags.delegateTableViewWillDisplayCellForRowAtIndexPath) {
[_delegate tableView:self willDisplayCell:cell forRowAtIndexPath:i];
}

[self addSubview:cell];

if([_indexPathShouldBeFirstResponder isEqual:i]) {
Expand Down
3 changes: 2 additions & 1 deletion lib/UIKit/TUITextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

#import "TUIKit.h"
#import "TUITextField.h"
#import "TUITextViewEditor.h"

@interface TUITextFieldEditor : TUITextEditor
@interface TUITextFieldEditor : TUITextViewEditor
@end

@implementation TUITextField
Expand Down
6 changes: 5 additions & 1 deletion lib/UIKit/TUITextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#import "TUIControl.h"
#import "TUIGeometry.h"
#import "TUIAttributedString.h"
#import "TUITextEditor.h"

@class TUITextEditor;
@class TUIFont;
@class TUIColor;

Expand All @@ -45,6 +45,7 @@

struct {
unsigned int delegateTextViewDidChange:1;
unsigned int delegateDoCommandBySelector:1;
} _textViewFlags;
}

Expand All @@ -66,6 +67,8 @@

- (BOOL)hasText;

- (BOOL)doCommandBySelector:(SEL)selector;

@end


Expand All @@ -74,6 +77,7 @@
@optional

- (void)textViewDidChange:(TUITextView *)textView;
- (BOOL)textView:(TUITextView *)textView doCommandBySelector:(SEL)commandSelector; // return YES if the implementation consumes the selector, NO if it should be passed up to super

@end

Expand Down
29 changes: 21 additions & 8 deletions lib/UIKit/TUITextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#import "TUIKit.h"
#import "TUITextView.h"
#import "TUITextViewEditor.h"

@implementation TUITextView

Expand Down Expand Up @@ -44,7 +45,7 @@ - (void)_updateDefaultAttributes

- (Class)textEditorClass
{
return [TUITextEditor class];
return [TUITextViewEditor class];
}

- (id)initWithFrame:(CGRect)frame
Expand Down Expand Up @@ -101,6 +102,7 @@ - (void)setDelegate:(id <TUITextViewDelegate>)d
{
delegate = d;
_textViewFlags.delegateTextViewDidChange = [delegate respondsToSelector:@selector(textViewDidChange:)];
_textViewFlags.delegateDoCommandBySelector = [delegate respondsToSelector:@selector(textView:doCommandBySelector:)];
}

- (TUIResponder *)initialFirstResponder
Expand Down Expand Up @@ -204,7 +206,7 @@ - (void)drawRect:(CGRect)rect

if(doMask) {
CGContextSaveGState(ctx);
CGContextClipToRoundRect(ctx, rect, floor(rect.size.height / 2));
CGContextClipToRoundRect(ctx, self.bounds, floor(rect.size.height / 2));
}

[renderer draw];
Expand All @@ -227,12 +229,14 @@ - (void)drawRect:(CGRect)rect
renderer.attributedString = fake;
selection = NSMakeRange(0, 0);
}

CGRect r = [renderer firstRectForCharacterRange:ABCFRangeFromNSRange(selection)];
r.size.width = 2.0;
r.size.height = round(r.size.height) - 2; // fudge
r.origin.x = roundf(r.origin.x);
r.origin.y = roundf(r.origin.y);

// Ugh. So this seems to be a decent approximation for the height of the cursor. It doesn't always match the native cursor but what ev.
CGRect r = CGRectIntegral([renderer firstRectForCharacterRange:ABCFRangeFromNSRange(selection)]);
r.size.width = 2.0f;
CGRect fontBoundingBox = CTFontGetBoundingBox(self.font.ctFont);
r.size.height = round(fontBoundingBox.origin.y + fontBoundingBox.size.height);
r.origin.y += floor(self.font.leading);
// NSLog(@"ascent: %f, descent: %f, leading: %f, cap height: %f, x-height: %f, bounding: %@", self.font.ascender, self.font.descender, self.font.leading, self.font.capHeight, self.font.xHeight, NSStringFromRect(CTFontGetBoundingBox(self.font.ctFont)));

[TUIView setAnimationsEnabled:NO block:^{
cursor.frame = r;
Expand Down Expand Up @@ -287,6 +291,15 @@ - (BOOL)acceptsFirstResponder
return YES;
}

- (BOOL)doCommandBySelector:(SEL)selector
{
if(_textViewFlags.delegateDoCommandBySelector) {
return [delegate textView:self doCommandBySelector:selector];
}

return NO;
}

@end

static void TUITextViewDrawRoundedFrame(TUIView *view, CGFloat radius, BOOL overDark)
Expand Down
Loading

0 comments on commit ef6580d

Please sign in to comment.