Skip to content
This repository has been archived by the owner on Nov 1, 2017. It is now read-only.

Commit

Permalink
moved the control event sending into TUIControl
Browse files Browse the repository at this point in the history
  • Loading branch information
joshaber committed Aug 15, 2011
1 parent e4f0d99 commit e623741
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
21 changes: 1 addition & 20 deletions lib/UIKit/TUIButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,7 @@ - (void)drawRect:(CGRect)r
- (void)mouseDown:(NSEvent *)event
{
[super mouseDown:event];
if([event clickCount] < 2) {
[self sendActionsForControlEvents:TUIControlEventTouchDown];
} else {
[self sendActionsForControlEvents:TUIControlEventTouchDownRepeat];
}


if(popUpMenu) { // happens even if clickCount is big
NSMenu *menu = popUpMenu;
NSPoint p = [self frameInNSView].origin;
Expand All @@ -240,20 +235,6 @@ - (void)mouseDown:(NSEvent *)event
}
}

- (void)mouseUp:(NSEvent *)event
{
[super mouseUp:event];
// if([event clickCount] < 2) {
if([self eventInside:event]) {
if(![self didDrag]) {
[self sendActionsForControlEvents:TUIControlEventTouchUpInside];
}
} else {
[self sendActionsForControlEvents:TUIControlEventTouchUpOutside];
}
// }
}

- (void)_update {
_titleView.text = self.currentTitle;
_titleView.textColor = self.currentTitleColor;
Expand Down
29 changes: 16 additions & 13 deletions lib/UIKit/TUIControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ -(BOOL)selected {
*/
-(void)setSelected:(BOOL)selected {
[self _stateWillChange];
_controlFlags.selected = selected;
_controlFlags.selected = selected;
[self _stateDidChange];
[self setNeedsDisplay];
[self setNeedsDisplay];
}

- (BOOL)acceptsFirstMouse
Expand All @@ -124,12 +124,15 @@ - (void)mouseDown:(NSEvent *)event
_controlFlags.tracking = 1;
[self _stateDidChange];

// handle touch down
[self sendActionsForControlEvents:TUIControlEventTouchDown];
// handle touch down
if([event clickCount] < 2) {
[self sendActionsForControlEvents:TUIControlEventTouchDown];
} else {
[self sendActionsForControlEvents:TUIControlEventTouchDownRepeat];
}

// needs display
[self setNeedsDisplay];

}

- (void)mouseUp:(NSEvent *)event
Expand All @@ -141,16 +144,16 @@ - (void)mouseUp:(NSEvent *)event
_controlFlags.tracking = 0;
[self _stateDidChange];

// handle touch up
if([self pointInside:[self localPointForEvent:event] withEvent:event]){
[self sendActionsForControlEvents:TUIControlEventTouchUpInside];
}else{
[self sendActionsForControlEvents:TUIControlEventTouchUpOutside];
}
if([self eventInside:event]) {
if(![self didDrag]) {
[self sendActionsForControlEvents:TUIControlEventTouchUpInside];
}
} else {
[self sendActionsForControlEvents:TUIControlEventTouchUpOutside];
}

// needs display
// needs display
[self setNeedsDisplay];

}

@end

0 comments on commit e623741

Please sign in to comment.