From 846d11d79cf0022b91a759c4e1a701767a5b3099 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Thu, 9 Aug 2007 09:12:47 +0000 Subject: [PATCH] Added support for font panel. git-svn-id: http://macvim.googlecode.com/svn/trunk@106 96c4425d-ca35-0410-94e5-3396d5c13a8f --- Actions.plist | 2 ++ MMBackend.m | 22 +++++++++++++++++++++- MMTextView.m | 26 ++++++++++++++++++++++++++ gvimrc | 1 + 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Actions.plist b/Actions.plist index 22c4c7012f..3f8093cd06 100644 --- a/Actions.plist +++ b/Actions.plist @@ -16,6 +16,8 @@ orderFrontCharacterPalette: + orderFrontFontPanel: + performClose: performMiniaturize: diff --git a/MMBackend.m b/MMBackend.m index a80a635f85..934acef1c2 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -906,6 +906,25 @@ static int specialKeyToNSKey(int key); } } } + } else if (SetFontMsgID == msgid) { + if (!data) return; + const void *bytes = [data bytes]; + float pointSize = *((float*)bytes); bytes += sizeof(float); + //unsigned len = *((unsigned*)bytes); bytes += sizeof(unsigned); + bytes += sizeof(unsigned); // len not used + + NSMutableString *name = [NSMutableString stringWithUTF8String:bytes]; + [name appendString:[NSString stringWithFormat:@":h%f", pointSize]]; + + gui_init_font((char_u*)[name UTF8String], FALSE); + + // Force screen redraw (does it have to be this complicated?). + redraw_all_later(CLEAR); + update_screen(NOT_VALID); + setcursor(); + out_flush(); + gui_update_cursor(FALSE, FALSE); + gui_mch_flush(); } else if (VimShouldCloseMsgID == msgid) { gui_shell_closed(); } else if (DropFilesMsgID == msgid) { @@ -960,7 +979,8 @@ static int specialKeyToNSKey(int key); do_cmdline_cmd((char_u*)[cmd UTF8String]); - // This code was taken from the end of gui_handle_drop(). + // Force screen redraw (does it have to be this complicated?). + // (This code was taken from the end of gui_handle_drop().) update_screen(NOT_VALID); setcursor(); out_flush(); diff --git a/MMTextView.m b/MMTextView.m index f4c2fd4a28..0f39be8baa 100644 --- a/MMTextView.m +++ b/MMTextView.m @@ -334,6 +334,32 @@ return NSDragOperationNone; } +- (void)changeFont:(id)sender +{ + MMTextStorage *ts = (MMTextStorage*)[self textStorage]; + if (!ts) return; + + NSFont *oldFont = [ts font]; + NSFont *newFont = [sender convertFont:oldFont]; + + if (newFont) { + NSString *name = [newFont displayName]; + unsigned len = [name lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + if (len > 0) { + NSMutableData *data = [NSMutableData data]; + float pointSize = [newFont pointSize]; + + [data appendBytes:&pointSize length:sizeof(float)]; + + ++len; // include NUL byte + [data appendBytes:&len length:sizeof(unsigned)]; + [data appendBytes:[name UTF8String] length:len]; + + [[self vimController] sendMessage:SetFontMsgID data:data wait:NO]; + } + } +} + @end // MMTextView diff --git a/gvimrc b/gvimrc index 47ff6fcfc8..b504fa37dd 100644 --- a/gvimrc +++ b/gvimrc @@ -26,6 +26,7 @@ an 10.330 File.Close:q :confirm q "an 10.331 File.Close\ Tab :tabclose an 20.460 Edit.-SEP4- +an 20.465 Edit.Show\ Fonts\.\.\. :action orderFrontFontPanel: an 20.470 Edit.Special\ Characters\.\.\. :action orderFrontCharacterPalette: