Skip to content

Commit

Permalink
Add +balloon_eval support
Browse files Browse the repository at this point in the history
The tracking rect code had to be pulled to get tool tips to work.  This
has at least one negative drawback (the mouse cursor does not change
back to an arrow when moved outside the window) and there may be more.

Changes to 'bdlay' are only detected after disabling and re-enabling
'beval'.
  • Loading branch information
b4winckler committed Jul 25, 2010
1 parent b71ce80 commit c1a59b5
Show file tree
Hide file tree
Showing 24 changed files with 480 additions and 172 deletions.
1 change: 1 addition & 0 deletions src/MacVim/MMAtsuiTextView.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum { MMMaxCellsPerChar = 2 };
// MMTextView methods // MMTextView methods
// //
- (void)deleteSign:(NSString *)signName; - (void)deleteSign:(NSString *)signName;
- (void)setToolTipAtMousePoint:(NSString *)string;
- (void)setPreEditRow:(int)row column:(int)col; - (void)setPreEditRow:(int)row column:(int)col;
- (void)setMouseShape:(int)shape; - (void)setMouseShape:(int)shape;
- (void)setAntialias:(BOOL)state; - (void)setAntialias:(BOOL)state;
Expand Down
32 changes: 6 additions & 26 deletions src/MacVim/MMAtsuiTextView.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ - (void)setShouldDrawInsertionPoint:(BOOL)on


- (void)deleteSign:(NSString *)signName - (void)deleteSign:(NSString *)signName
{ {
// ONLY in Core Text!
}

- (void)setToolTipAtMousePoint:(NSString *)string
{
// ONLY in Core Text!
} }


- (void)setPreEditRow:(int)row column:(int)col - (void)setPreEditRow:(int)row column:(int)col
Expand Down Expand Up @@ -481,32 +487,6 @@ - (void)mouseMoved:(NSEvent *)event
[helper mouseMoved:event]; [helper mouseMoved:event];
} }


- (void)mouseEntered:(NSEvent *)event
{
[helper mouseEntered:event];
}

- (void)mouseExited:(NSEvent *)event
{
[helper mouseExited:event];
}

- (void)setFrame:(NSRect)frame
{
[super setFrame:frame];
[helper setFrame:frame];
}

- (void)viewDidMoveToWindow
{
[helper viewDidMoveToWindow];
}

- (void)viewWillMoveToWindow:(NSWindow *)newWindow
{
[helper viewWillMoveToWindow:newWindow];
}

- (NSMenu*)menuForEvent:(NSEvent *)event - (NSMenu*)menuForEvent:(NSEvent *)event
{ {
// HACK! Return nil to disable default popup menus (Vim provides its own). // HACK! Return nil to disable default popup menus (Vim provides its own).
Expand Down
12 changes: 12 additions & 0 deletions src/MacVim/MMBackend.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#import "vim.h" #import "vim.h"




#ifdef FEAT_BEVAL
// Seconds to delay balloon evaluation after mouse event (subtracted from
// p_bdlay).
extern NSTimeInterval MMBalloonEvalInternalDelay;
#endif




@interface MMBackend : NSObject <MMBackendProtocol, MMVimServerProtocol, @interface MMBackend : NSObject <MMBackendProtocol, MMVimServerProtocol,
Expand Down Expand Up @@ -55,6 +60,9 @@
CFRunLoopSourceRef netbeansRunLoopSource; CFRunLoopSourceRef netbeansRunLoopSource;
int winposX; int winposX;
int winposY; int winposY;
#ifdef FEAT_BEVAL
NSString *lastToolTip;
#endif
} }


+ (MMBackend *)sharedInstance; + (MMBackend *)sharedInstance;
Expand Down Expand Up @@ -150,6 +158,10 @@
- (void)messageFromNetbeans; - (void)messageFromNetbeans;
- (void)setNetbeansSocket:(int)socket; - (void)setNetbeansSocket:(int)socket;


#ifdef FEAT_BEVAL
- (void)setLastToolTip:(NSString *)toolTip;
#endif

@end @end




Expand Down
66 changes: 65 additions & 1 deletion src/MacVim/MMBackend.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@


static unsigned MMServerMax = 1000; static unsigned MMServerMax = 1000;


#ifdef FEAT_BEVAL
// Seconds to delay balloon evaluation after mouse event (subtracted from
// p_bdlay so that this effectively becomes the smallest possible delay).
NSTimeInterval MMBalloonEvalInternalDelay = 0.1;
#endif

// TODO: Move to separate file. // TODO: Move to separate file.
static int eventModifierFlagsToVimModMask(int modifierFlags); static int eventModifierFlagsToVimModMask(int modifierFlags);
static int eventModifierFlagsToVimMouseModMask(int modifierFlags); static int eventModifierFlagsToVimMouseModMask(int modifierFlags);
Expand Down Expand Up @@ -152,7 +158,6 @@
extern GuiFont gui_mch_retain_font(GuiFont font); extern GuiFont gui_mch_retain_font(GuiFont font);





@interface NSString (MMServerNameCompare) @interface NSString (MMServerNameCompare)
- (NSComparisonResult)serverNameCompare:(NSString *)string; - (NSComparisonResult)serverNameCompare:(NSString *)string;
@end @end
Expand Down Expand Up @@ -192,6 +197,9 @@ - (BOOL)unusedEditor;
- (void)redrawScreen; - (void)redrawScreen;
- (void)handleFindReplace:(NSDictionary *)args; - (void)handleFindReplace:(NSDictionary *)args;
- (void)handleMarkedText:(NSData *)data; - (void)handleMarkedText:(NSData *)data;
#ifdef FEAT_BEVAL
- (void)bevalCallback:(id)sender;
#endif
@end @end




Expand Down Expand Up @@ -268,6 +276,9 @@ - (void)dealloc
[sysColorDict release]; sysColorDict = nil; [sysColorDict release]; sysColorDict = nil;
[colorDict release]; colorDict = nil; [colorDict release]; colorDict = nil;
[vimServerConnection release]; vimServerConnection = nil; [vimServerConnection release]; vimServerConnection = nil;
#ifdef FEAT_BEVAL
[lastToolTip release]; lastToolTip = nil;
#endif


[super dealloc]; [super dealloc];
} }
Expand Down Expand Up @@ -1669,6 +1680,16 @@ - (void)setNetbeansSocket:(int)socket
kCFRunLoopCommonModes); kCFRunLoopCommonModes);
} }


#ifdef FEAT_BEVAL
- (void)setLastToolTip:(NSString *)toolTip
{
if (toolTip != lastToolTip) {
[lastToolTip release];
lastToolTip = [toolTip copy];
}
}
#endif

@end // MMBackend @end // MMBackend




Expand Down Expand Up @@ -1887,6 +1908,22 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
int col = *((int*)bytes); bytes += sizeof(int); int col = *((int*)bytes); bytes += sizeof(int);


gui_mouse_moved(col, row); gui_mouse_moved(col, row);

#ifdef FEAT_BEVAL
if (p_beval && balloonEval) {
balloonEval->x = col;
balloonEval->y = row;

// Update the balloon eval message after a slight delay (to avoid
// calling it too often).
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(bevalCallback:)
object:nil];
[self performSelector:@selector(bevalCallback:)
withObject:nil
afterDelay:MMBalloonEvalInternalDelay];
}
#endif
} else if (AddInputMsgID == msgid) { } else if (AddInputMsgID == msgid) {
NSString *string = [[NSString alloc] initWithData:data NSString *string = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
Expand Down Expand Up @@ -2890,6 +2927,33 @@ - (void)handleMarkedText:(NSData *)data
} }
} }


#ifdef FEAT_BEVAL
- (void)bevalCallback:(id)sender
{
if (!(p_beval && balloonEval))
return;

if (balloonEval->msgCB != NULL) {
// HACK! We have no way of knowing whether the balloon evaluation
// worked or not, so we keep track of it using a local tool tip
// variable. (The reason we need to know is due to how the Cocoa tool
// tips work: if there is no tool tip we must set it to nil explicitly
// or it might never go away.)
[self setLastToolTip:nil];

(*balloonEval->msgCB)(balloonEval, 0);

[[MMBackend sharedInstance] queueMessage:SetTooltipMsgID properties:
[NSDictionary dictionaryWithObject:(lastToolTip ? lastToolTip : @"")
forKey:@"toolTip"]];

// NOTE: We have to explicitly stop the run loop since timer events do
// not cause CFRunLoopRunInMode() to exit.
CFRunLoopStop(CFRunLoopGetCurrent());
}
}
#endif

@end // MMBackend (Private) @end // MMBackend (Private)




Expand Down
Loading

0 comments on commit c1a59b5

Please sign in to comment.