Permalink
Browse files

Add +balloon_eval support

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...
1 parent b71ce80 commit c1a59b534a9a80e5997f23b692645ae652e2f7b9 @b4winckler committed Jul 25, 2010
@@ -69,6 +69,7 @@ enum { MMMaxCellsPerChar = 2 };
// MMTextView methods
//
- (void)deleteSign:(NSString *)signName;
+- (void)setToolTipAtMousePoint:(NSString *)string;
- (void)setPreEditRow:(int)row column:(int)col;
- (void)setMouseShape:(int)shape;
- (void)setAntialias:(BOOL)state;
@@ -338,6 +338,12 @@ - (void)setShouldDrawInsertionPoint:(BOOL)on
- (void)deleteSign:(NSString *)signName
{
+ // ONLY in Core Text!
+}
+
+- (void)setToolTipAtMousePoint:(NSString *)string
+{
+ // ONLY in Core Text!
}
- (void)setPreEditRow:(int)row column:(int)col
@@ -481,32 +487,6 @@ - (void)mouseMoved:(NSEvent *)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
{
// HACK! Return nil to disable default popup menus (Vim provides its own).
View
@@ -13,6 +13,11 @@
#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,
@@ -55,6 +60,9 @@
CFRunLoopSourceRef netbeansRunLoopSource;
int winposX;
int winposY;
+#ifdef FEAT_BEVAL
+ NSString *lastToolTip;
+#endif
}
+ (MMBackend *)sharedInstance;
@@ -150,6 +158,10 @@
- (void)messageFromNetbeans;
- (void)setNetbeansSocket:(int)socket;
+#ifdef FEAT_BEVAL
+- (void)setLastToolTip:(NSString *)toolTip;
+#endif
+
@end
View
@@ -46,6 +46,12 @@
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.
static int eventModifierFlagsToVimModMask(int modifierFlags);
static int eventModifierFlagsToVimMouseModMask(int modifierFlags);
@@ -152,7 +158,6 @@
extern GuiFont gui_mch_retain_font(GuiFont font);
-
@interface NSString (MMServerNameCompare)
- (NSComparisonResult)serverNameCompare:(NSString *)string;
@end
@@ -192,6 +197,9 @@ - (BOOL)unusedEditor;
- (void)redrawScreen;
- (void)handleFindReplace:(NSDictionary *)args;
- (void)handleMarkedText:(NSData *)data;
+#ifdef FEAT_BEVAL
+- (void)bevalCallback:(id)sender;
+#endif
@end
@@ -268,6 +276,9 @@ - (void)dealloc
[sysColorDict release]; sysColorDict = nil;
[colorDict release]; colorDict = nil;
[vimServerConnection release]; vimServerConnection = nil;
+#ifdef FEAT_BEVAL
+ [lastToolTip release]; lastToolTip = nil;
+#endif
[super dealloc];
}
@@ -1669,6 +1680,16 @@ - (void)setNetbeansSocket:(int)socket
kCFRunLoopCommonModes);
}
+#ifdef FEAT_BEVAL
+- (void)setLastToolTip:(NSString *)toolTip
+{
+ if (toolTip != lastToolTip) {
+ [lastToolTip release];
+ lastToolTip = [toolTip copy];
+ }
+}
+#endif
+
@end // MMBackend
@@ -1887,6 +1908,22 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
int col = *((int*)bytes); bytes += sizeof(int);
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) {
NSString *string = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
@@ -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)
Oops, something went wrong.

0 comments on commit c1a59b5

Please sign in to comment.