mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-11 15:37:29 +02:00
Add support for graphical signs
This commit is contained in:
committed by
Bjorn Winckler
parent
fb3590e751
commit
3b984bfba1
@@ -68,6 +68,7 @@ enum { MMMaxCellsPerChar = 2 };
|
||||
//
|
||||
// MMTextView methods
|
||||
//
|
||||
- (void)deleteSign:(NSString *)signName;
|
||||
- (void)setPreEditRow:(int)row column:(int)col;
|
||||
- (void)setMouseShape:(int)shape;
|
||||
- (void)setAntialias:(BOOL)state;
|
||||
|
||||
@@ -336,6 +336,10 @@ defaultLineHeightForFont(NSFont *font)
|
||||
{
|
||||
}
|
||||
|
||||
- (void)deleteSign:(NSString *)signName
|
||||
{
|
||||
}
|
||||
|
||||
- (void)setPreEditRow:(int)row column:(int)col
|
||||
{
|
||||
[helper setPreEditRow:row column:col];
|
||||
|
||||
@@ -85,6 +85,11 @@
|
||||
fraction:(int)percent color:(int)color;
|
||||
- (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nr
|
||||
numColumns:(int)nc invert:(int)invert;
|
||||
- (void)drawSign:(NSString *)imgName
|
||||
atRow:(int)row
|
||||
column:(int)col
|
||||
width:(int)width
|
||||
height:(int)height;
|
||||
- (void)update;
|
||||
- (void)flushQueue:(BOOL)force;
|
||||
- (BOOL)waitForInput:(int)milliseconds;
|
||||
|
||||
@@ -589,6 +589,26 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
|
||||
[drawData appendBytes:&invert length:sizeof(int)];
|
||||
}
|
||||
|
||||
- (void)drawSign:(NSString *)imgName
|
||||
atRow:(int)row
|
||||
column:(int)col
|
||||
width:(int)width
|
||||
height:(int)height
|
||||
{
|
||||
int type = DrawSignDrawType;
|
||||
[drawData appendBytes:&type length:sizeof(int)];
|
||||
|
||||
const char* utf8String = [imgName UTF8String];
|
||||
int strSize = (int)strlen(utf8String) + 1;
|
||||
[drawData appendBytes:&strSize length:sizeof(int)];
|
||||
[drawData appendBytes:utf8String length:strSize];
|
||||
|
||||
[drawData appendBytes:&col length:sizeof(int)];
|
||||
[drawData appendBytes:&row length:sizeof(int)];
|
||||
[drawData appendBytes:&width length:sizeof(int)];
|
||||
[drawData appendBytes:&height length:sizeof(int)];
|
||||
}
|
||||
|
||||
- (void)update
|
||||
{
|
||||
// Keep running the run-loop until there is no more input to process.
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
//
|
||||
// MMTextView methods
|
||||
//
|
||||
- (void)deleteSign:(NSString *)signName;
|
||||
- (void)setShouldDrawInsertionPoint:(BOOL)on;
|
||||
- (void)setPreEditRow:(int)row column:(int)col;
|
||||
- (void)setMouseShape:(int)shape;
|
||||
|
||||
@@ -47,14 +47,6 @@
|
||||
#define DRAW_CURSOR 0x20
|
||||
#define DRAW_WIDE 0x40 /* draw wide text */
|
||||
|
||||
|
||||
#define BLUE(argb) ((argb & 0xff)/255.0f)
|
||||
#define GREEN(argb) (((argb>>8) & 0xff)/255.0f)
|
||||
#define RED(argb) (((argb>>16) & 0xff)/255.0f)
|
||||
#define ALPHA(argb) (((argb>>24) & 0xff)/255.0f)
|
||||
|
||||
|
||||
|
||||
@interface MMCoreTextView (Private)
|
||||
- (MMWindowController *)windowController;
|
||||
- (MMVimController *)vimController;
|
||||
@@ -377,6 +369,11 @@ defaultAdvanceForFont(CTFontRef fontRef)
|
||||
|
||||
|
||||
|
||||
- (void)deleteSign:(NSString *)signName
|
||||
{
|
||||
[helper deleteImage:signName];
|
||||
}
|
||||
|
||||
- (void)setShouldDrawInsertionPoint:(BOOL)on
|
||||
{
|
||||
}
|
||||
@@ -907,6 +904,26 @@ defaultAdvanceForFont(CTFontRef fontRef)
|
||||
[self deleteLinesFromRow:row lineCount:count
|
||||
scrollBottom:bot left:left right:right
|
||||
color:color];
|
||||
} else if (DrawSignDrawType == type) {
|
||||
int strSize = *((int*)bytes); bytes += sizeof(int);
|
||||
NSString *imgName =
|
||||
[NSString stringWithUTF8String:(const char*)bytes];
|
||||
bytes += strSize;
|
||||
|
||||
int col = *((int*)bytes); bytes += sizeof(int);
|
||||
int row = *((int*)bytes); bytes += sizeof(int);
|
||||
int width = *((int*)bytes); bytes += sizeof(int);
|
||||
int height = *((int*)bytes); bytes += sizeof(int);
|
||||
|
||||
NSImage *signImg = [helper signImageForName:imgName];
|
||||
NSRect r = [self rectForRow:row
|
||||
column:col
|
||||
numRows:height
|
||||
numColumns:width];
|
||||
[signImg drawInRect:r
|
||||
fromRect:NSZeroRect
|
||||
operation:NSCompositeSourceOver
|
||||
fraction:1.0];
|
||||
} else if (DrawStringDrawType == type) {
|
||||
int bg = *((int*)bytes); bytes += sizeof(int);
|
||||
int fg = *((int*)bytes); bytes += sizeof(int);
|
||||
|
||||
@@ -59,10 +59,10 @@
|
||||
- (NSSize)desiredSize;
|
||||
- (NSSize)minSize;
|
||||
|
||||
|
||||
- (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column;
|
||||
- (NSPoint)pointForRow:(int)row column:(int)col;
|
||||
- (NSRect)rectForRow:(int)row column:(int)col numRows:(int)nr
|
||||
numColumns:(int)nc;
|
||||
|
||||
- (void)deleteSign:(NSString *)signName;
|
||||
@end
|
||||
|
||||
@@ -492,6 +492,10 @@
|
||||
return rect;
|
||||
}
|
||||
|
||||
- (void)deleteSign:(NSString *)signName
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL)isOpaque
|
||||
{
|
||||
return NO;
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define BLUE(argb) ((argb & 0xff)/255.0f)
|
||||
#define GREEN(argb) (((argb>>8) & 0xff)/255.0f)
|
||||
#define RED(argb) (((argb>>16) & 0xff)/255.0f)
|
||||
#define ALPHA(argb) (((argb>>24) & 0xff)/255.0f)
|
||||
|
||||
|
||||
enum {
|
||||
// These values are chosen so that the min text view size is not too small
|
||||
// with the default font (they only affect resizing with the mouse, you can
|
||||
@@ -38,12 +44,13 @@ enum {
|
||||
NSColor *insertionPointColor;
|
||||
BOOL interpretKeyEventsSwallowedKey;
|
||||
NSEvent *currentEvent;
|
||||
NSMutableDictionary *signImages;
|
||||
|
||||
// Input Manager
|
||||
NSRange imRange;
|
||||
NSRange markedRange;
|
||||
NSDictionary *markedTextAttributes;
|
||||
NSMutableAttributedString *markedText;
|
||||
NSMutableAttributedString *markedText;
|
||||
int preEditRow;
|
||||
int preEditColumn;
|
||||
BOOL imControl;
|
||||
@@ -54,6 +61,7 @@ enum {
|
||||
#endif
|
||||
}
|
||||
|
||||
- (id)init;
|
||||
- (void)setTextView:(id)view;
|
||||
- (void)setInsertionPointColor:(NSColor *)color;
|
||||
- (NSColor *)insertionPointColor;
|
||||
@@ -77,6 +85,8 @@ enum {
|
||||
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
|
||||
- (void)setMouseShape:(int)shape;
|
||||
- (void)changeFont:(id)sender;
|
||||
- (NSImage *)signImageForName:(NSString *)imgName;
|
||||
- (void)deleteImage:(NSString *)imgName;
|
||||
|
||||
// Input Manager
|
||||
- (BOOL)hasMarkedText;
|
||||
|
||||
@@ -70,6 +70,16 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
|
||||
|
||||
@implementation MMTextViewHelper
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
signImages = [[NSMutableDictionary alloc] init];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
ASLogDebug(@"");
|
||||
@@ -77,6 +87,7 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
|
||||
[insertionPointColor release]; insertionPointColor = nil;
|
||||
[markedText release]; markedText = nil;
|
||||
[markedTextAttributes release]; markedTextAttributes = nil;
|
||||
[signImages release]; signImages = nil;
|
||||
|
||||
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
|
||||
if (asciiImSource) {
|
||||
@@ -607,6 +618,26 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
|
||||
}
|
||||
}
|
||||
|
||||
- (NSImage *)signImageForName:(NSString *)imgName
|
||||
{
|
||||
NSImage *img = [signImages objectForKey:imgName];
|
||||
if (img)
|
||||
return img;
|
||||
|
||||
img = [[NSImage alloc] initWithContentsOfFile:imgName];
|
||||
if (img) {
|
||||
[signImages setObject:img forKey:imgName];
|
||||
[img autorelease];
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
- (void)deleteImage:(NSString *)imgName
|
||||
{
|
||||
[signImages removeObjectForKey:imgName];
|
||||
}
|
||||
|
||||
- (BOOL)hasMarkedText
|
||||
{
|
||||
return markedRange.length > 0 ? YES : NO;
|
||||
|
||||
@@ -97,6 +97,7 @@ static BOOL isUnsafeMessage(int msgid);
|
||||
- (void)scheduleClose;
|
||||
- (void)handleBrowseForFile:(NSDictionary *)attr;
|
||||
- (void)handleShowDialog:(NSDictionary *)attr;
|
||||
- (void)handleDeleteSign:(NSDictionary *)attr;
|
||||
@end
|
||||
|
||||
|
||||
@@ -819,6 +820,10 @@ static BOOL isUnsafeMessage(int msgid);
|
||||
NSDictionary *dict = [NSDictionary dictionaryWithData:data];
|
||||
if (dict)
|
||||
[self handleShowDialog:dict];
|
||||
} else if (DeleteSignMsgID == msgid) {
|
||||
NSDictionary *dict = [NSDictionary dictionaryWithData:data];
|
||||
if (dict)
|
||||
[self handleDeleteSign:dict];
|
||||
} else if (ZoomMsgID == msgid) {
|
||||
const void *bytes = [data bytes];
|
||||
int rows = *((int*)bytes); bytes += sizeof(int);
|
||||
@@ -1438,6 +1443,11 @@ static BOOL isUnsafeMessage(int msgid);
|
||||
[alert release];
|
||||
}
|
||||
|
||||
- (void)handleDeleteSign:(NSDictionary *)attr
|
||||
{
|
||||
MMTextView *view = [[windowController vimView] textView];
|
||||
[view deleteSign:[attr objectForKey:@"imgName"]];
|
||||
}
|
||||
|
||||
@end // MMVimController (Private)
|
||||
|
||||
|
||||
@@ -192,6 +192,7 @@ enum {
|
||||
SetMarkedTextMsgID,
|
||||
ZoomMsgID,
|
||||
SetWindowPositionMsgID,
|
||||
DeleteSignMsgID,
|
||||
LastMsgID // NOTE: MUST BE LAST MESSAGE IN ENUM!
|
||||
};
|
||||
|
||||
@@ -205,6 +206,7 @@ enum {
|
||||
DrawCursorDrawType,
|
||||
SetCursorPosDrawType,
|
||||
DrawInvertedRectDrawType,
|
||||
DrawSignDrawType,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
||||
@@ -95,6 +95,7 @@ char *MessageStrings[] =
|
||||
"SetMarkedTextMsgID",
|
||||
"ZoomMsgID",
|
||||
"SetWindowPositionMsgID",
|
||||
"DeleteSignMsgID",
|
||||
"END OF MESSAGE IDs" // NOTE: Must be last!
|
||||
};
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
// HACK! Used in gui.c to determine which string drawing code to use.
|
||||
int use_gui_macvim_draw_string = 1;
|
||||
|
||||
static int use_graphical_sign = 0;
|
||||
|
||||
// NOTE: The default font is bundled with the application.
|
||||
static NSString *MMDefaultFontName = @"DejaVu Sans Mono";
|
||||
@@ -149,6 +150,10 @@ gui_macvim_after_fork_init()
|
||||
if (keyValid) {
|
||||
ASLogInfo(@"Use renderer=%d", val);
|
||||
use_gui_macvim_draw_string = (val != MMRendererCoreText);
|
||||
|
||||
// For now only the Core Text renderer knows how to render graphical
|
||||
// signs.
|
||||
use_graphical_sign = (val == MMRendererCoreText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2283,3 +2288,69 @@ gui_macvim_set_netbeans_socket(int socket)
|
||||
}
|
||||
|
||||
#endif // FEAT_NETBEANS_INTG
|
||||
|
||||
|
||||
|
||||
// -- Graphical Sign Support ------------------------------------------------
|
||||
|
||||
#if defined(FEAT_SIGN_ICONS)
|
||||
void
|
||||
gui_mch_drawsign(int row, int col, int typenr)
|
||||
{
|
||||
if (!gui.in_use)
|
||||
return;
|
||||
|
||||
NSString *imgName = (NSString *)sign_get_image(typenr);
|
||||
if (!imgName)
|
||||
return;
|
||||
|
||||
char_u *txt = sign_get_text(typenr);
|
||||
int txtSize = txt ? strlen((char*)txt) : 2;
|
||||
|
||||
[[MMBackend sharedInstance] drawSign:imgName
|
||||
atRow:row
|
||||
column:col
|
||||
width:txtSize
|
||||
height:1];
|
||||
}
|
||||
|
||||
void *
|
||||
gui_mch_register_sign(char_u *signfile)
|
||||
{
|
||||
if (!use_graphical_sign)
|
||||
return NULL;
|
||||
|
||||
NSString *imgName = [NSString stringWithVimString:signfile];
|
||||
NSImage *img = [[NSImage alloc] initWithContentsOfFile:imgName];
|
||||
if (!img) {
|
||||
EMSG(_(e_signdata));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
[img release];
|
||||
|
||||
return (void*)[imgName retain];
|
||||
}
|
||||
|
||||
void
|
||||
gui_mch_destroy_sign(void *sign)
|
||||
{
|
||||
NSString *imgName = (NSString *)sign;
|
||||
if (!imgName)
|
||||
return;
|
||||
|
||||
[[MMBackend sharedInstance]
|
||||
queueMessage:DeleteSignMsgID
|
||||
properties:[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
imgName, @"imgName", nil]];
|
||||
[imgName release];
|
||||
}
|
||||
|
||||
# ifdef FEAT_NETBEANS_INTG
|
||||
void
|
||||
netbeans_draw_multisign_indicator(int row)
|
||||
{
|
||||
}
|
||||
# endif // FEAT_NETBEANS_INTG
|
||||
|
||||
#endif // FEAT_SIGN_ICONS
|
||||
|
||||
@@ -1227,6 +1227,7 @@
|
||||
# if ((defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) \
|
||||
&& defined(HAVE_X11_XPM_H)) \
|
||||
|| defined(FEAT_GUI_GTK) \
|
||||
|| defined(FEAT_GUI_MACVIM) \
|
||||
|| (defined(WIN32) && defined(FEAT_GUI))
|
||||
# define FEAT_SIGN_ICONS
|
||||
# endif
|
||||
|
||||
@@ -224,3 +224,13 @@ im_set_control(int enable);
|
||||
|
||||
void
|
||||
gui_macvim_set_netbeans_socket(int socket);
|
||||
|
||||
void
|
||||
gui_mch_drawsign(int row, int col, int typenr);
|
||||
|
||||
void *
|
||||
gui_mch_register_sign(char_u *signfile);
|
||||
|
||||
void
|
||||
gui_mch_destroy_sign(void *sign);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user