1
0
forked from aniani/vim

Add clipboard support in Mac console. (Bjorn Winckler)

This commit is contained in:
Bram Moolenaar
2010-07-14 13:58:07 +02:00
parent 7abcaab78d
commit 164fca39bd
11 changed files with 238 additions and 52 deletions

View File

@@ -37,7 +37,8 @@
# USEDLL no or yes: set to yes to use the Runtime library DLL (no)
# For USEDLL=yes the cygwin1.dll is required to run Vim.
# "no" does not work with latest version of Cygwin, use
# Make_ming.mak instead. Or set CC to gcc-3.
# Make_ming.mak instead. Or set CC to gcc-3 and add
# -L/lib/w32api to EXTRA_LIBS.
# POSTSCRIPT no or yes: set to yes for PostScript printing (no)
# FEATURES TINY, SMALL, NORMAL, BIG or HUGE (BIG)
# WINVER Lowest Win32 version to support. (0x0400)

View File

@@ -2511,8 +2511,8 @@ objects/os_beos.o: os_beos.c
objects/os_qnx.o: os_qnx.c
$(CCC) -o $@ os_qnx.c
objects/os_macosx.o: os_macosx.c
$(CCC) -o $@ os_macosx.c
objects/os_macosx.o: os_macosx.m
$(CCC) -o $@ os_macosx.m
objects/os_mac_conv.o: os_mac_conv.c
$(CCC) -o $@ os_mac_conv.c

34
src/auto/configure vendored
View File

@@ -4004,7 +4004,7 @@ fi
$as_echo "no" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if Darwin files are there" >&5
$as_echo_n "checking if Darwin files are there... " >&6; }
if test -f os_macosx.c; then
if test -f os_macosx.m; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
@@ -4160,14 +4160,9 @@ rm -f core conftest.err conftest.$ac_objext \
if test "$enable_darwin" = "yes"; then
MACOSX=yes
OS_EXTRA_SRC="os_macosx.c os_mac_conv.c";
OS_EXTRA_SRC="os_macosx.m os_mac_conv.c";
OS_EXTRA_OBJ="objects/os_macosx.o objects/os_mac_conv.o"
CPPFLAGS="$CPPFLAGS -DMACOS_X_UNIX -no-cpp-precomp"
if test "x$MACARCH" = "xboth"; then
CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon"
else
CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/Headers/FlatCarbon"
fi
# On IRIX 5.3, sys/types and inttypes.h are conflicting.
for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
@@ -7025,8 +7020,9 @@ $as_echo "no GUI support" >&6; }
SKIP_CARBON=YES ;;
yes|"") { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes - automatic GUI support" >&5
$as_echo "yes - automatic GUI support" >&6; } ;;
auto) { $as_echo "$as_me:${as_lineno-$LINENO}: result: auto - automatic GUI support" >&5
$as_echo "auto - automatic GUI support" >&6; } ;;
auto) { $as_echo "$as_me:${as_lineno-$LINENO}: result: auto - Carbon GUI is outdated - disable GUI support" >&5
$as_echo "auto - Carbon GUI is outdated - disable GUI support" >&6; }
SKIP_CARBON=YES ;;
carbon) { $as_echo "$as_me:${as_lineno-$LINENO}: result: Carbon GUI support" >&5
$as_echo "Carbon GUI support" >&6; } ;;
*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: Sorry, $enable_gui GUI is not supported" >&5
@@ -7184,6 +7180,12 @@ $as_echo "yes" >&6; };
VIMNAME=Vim
fi
if test "x$MACARCH" = "xboth"; then
CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon"
else
CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/Headers/FlatCarbon"
fi
if test x$prefix = xNONE; then
prefix=/Applications
fi
@@ -11774,13 +11776,11 @@ if test "x$MACOSX" = "xyes" -a -n "$PERL"; then
fi
fi
if test "x$MACOSX" = "xyes" && test "x$CARBON" = "xyes" \
&& test "x$GUITYPE" != "xCARBONGUI"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we need -framework Carbon" >&5
$as_echo_n "checking whether we need -framework Carbon... " >&6; }
if test "x$enable_multibyte" = "xyes" || test "x$features" = "xbig" \
|| test "x$features" = "xhuge"; then
LIBS="$LIBS -framework Carbon"
if test "x$MACOSX" = "xyes"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we need -framework Cocoa" >&5
$as_echo_n "checking whether we need -framework Cocoa... " >&6; }
if test "x$features" != "xtiny" || test "x$enable_multibyte" = "xyes"; then
LIBS=$"$LIBS -framework Cocoa"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
@@ -11788,7 +11788,7 @@ $as_echo "yes" >&6; }
$as_echo "no" >&6; }
fi
fi
if test "x$MACARCH" = "xboth"; then
if test "x$MACARCH" = "xboth" && test "x$GUITYPE" = "xCARBONGUI"; then
LDFLAGS="$LDFLAGS -isysroot $DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
fi

View File

@@ -101,7 +101,7 @@ if test "`(uname) 2>/dev/null`" = Darwin; then
if test "$enable_darwin" = "yes"; then
AC_MSG_RESULT(no)
AC_MSG_CHECKING(if Darwin files are there)
if test -f os_macosx.c; then
if test -f os_macosx.m; then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT([no, Darwin support disabled])
@@ -168,15 +168,10 @@ if test "`(uname) 2>/dev/null`" = Darwin; then
if test "$enable_darwin" = "yes"; then
MACOSX=yes
OS_EXTRA_SRC="os_macosx.c os_mac_conv.c";
OS_EXTRA_SRC="os_macosx.m os_mac_conv.c";
OS_EXTRA_OBJ="objects/os_macosx.o objects/os_mac_conv.o"
dnl TODO: use -arch i386 on Intel machines
CPPFLAGS="$CPPFLAGS -DMACOS_X_UNIX -no-cpp-precomp"
if test "x$MACARCH" = "xboth"; then
CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon"
else
CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/Headers/FlatCarbon"
fi
dnl If Carbon is found, assume we don't want X11
dnl unless it was specifically asked for (--with-x)
@@ -1325,7 +1320,8 @@ elif test "x$MACOSX" = "xyes" -a "x$with_x" = "xno" ; then
no) AC_MSG_RESULT(no GUI support)
SKIP_CARBON=YES ;;
yes|"") AC_MSG_RESULT(yes - automatic GUI support) ;;
auto) AC_MSG_RESULT(auto - automatic GUI support) ;;
auto) AC_MSG_RESULT(auto - Carbon GUI is outdated - disable GUI support)
SKIP_CARBON=YES ;;
carbon) AC_MSG_RESULT(Carbon GUI support) ;;
*) AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported])
SKIP_CARBON=YES ;;
@@ -1436,6 +1432,12 @@ if test "x$MACOSX" = "xyes" -a -z "$SKIP_CARBON" -a "x$CARBON" = "xyes"; then
VIMNAME=Vim
fi
if test "x$MACARCH" = "xboth"; then
CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon"
else
CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/Headers/FlatCarbon"
fi
dnl Default install directory is not /usr/local
if test x$prefix = xNONE; then
prefix=/Applications
@@ -3109,19 +3111,18 @@ if test "x$MACOSX" = "xyes" -a -n "$PERL"; then
fi
fi
if test "x$MACOSX" = "xyes" && test "x$CARBON" = "xyes" \
&& test "x$GUITYPE" != "xCARBONGUI"; then
AC_MSG_CHECKING(whether we need -framework Carbon)
dnl check for MACOSX without Carbon GUI, but with FEAT_MBYTE
if test "x$enable_multibyte" = "xyes" || test "x$features" = "xbig" \
|| test "x$features" = "xhuge"; then
LIBS="$LIBS -framework Carbon"
if test "x$MACOSX" = "xyes"; then
AC_MSG_CHECKING(whether we need -framework Cocoa)
dnl Cocoa is needed with FEAT_CLIPBOARD or FEAT_MBYTE (the former is
dnl disabled during tiny build)
if test "x$features" != "xtiny" || test "x$enable_multibyte" = "xyes"; then
LIBS=$"$LIBS -framework Cocoa"
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
fi
if test "x$MACARCH" = "xboth"; then
if test "x$MACARCH" = "xboth" && test "x$GUITYPE" = "xCARBONGUI"; then
LDFLAGS="$LDFLAGS -isysroot $DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
fi

View File

@@ -22,7 +22,7 @@
* Include the Mac header files, unless also compiling with X11 (the header
* files have many conflicts).
*/
#ifndef FEAT_X11
#ifdef FEAT_GUI_MAC
# include <Quickdraw.h> /* Apple calls it QuickDraw.h... */
# include <ToolUtils.h>
# include <LowMem.h>

View File

@@ -15,8 +15,13 @@
#define NO_X11_INCLUDES
#include "vim.h"
#ifndef FEAT_GUI_MAC
# include <CoreServices/CoreServices.h>
#endif
#if defined(MACOS_CONVERT) || defined(PROTO)
# ifdef PROTO
/* A few dummy types to be able to generate function prototypes. */
typedef int UniChar;

View File

@@ -8,19 +8,20 @@
*/
/*
* os_macosx.c -- Mac specific things for Mac OS/X.
* os_macosx.m -- Mac specific things for Mac OS/X.
*/
#ifdef MACOS_X_UNIX
# ifdef HAVE_CONFIG_H /* Using Makefile. */
# include "vim.h"
# else
# include "os_unix.c" /* Using Project Builder */
# endif
#else
#ifndef MACOS_X_UNIX
Error: MACOS 9 is no longer supported in Vim 7
#endif
#include "vim.h"
#import <Cocoa/Cocoa.h>
NSString *VimPboardType = @"VimPboardType";
#ifdef _DEBUG
void
Trace(char* fmt, ...)
@@ -609,3 +610,174 @@ mch_textdomain(const char *domain)
return (char*)domain;
}
#endif
#ifdef FEAT_CLIPBOARD
void
clip_mch_lose_selection(VimClipboard *cbd)
{
}
int
clip_mch_own_selection(VimClipboard *cbd)
{
/* This is called whenever there is a new selection and 'guioptions'
* contains the "a" flag (automatically copy selection). Return TRUE, else
* the "a" flag does nothing. Note that there is no concept of "ownership"
* of the clipboard in Mac OS X.
*/
return TRUE;
}
void
clip_mch_request_selection(VimClipboard *cbd)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
NSStringPboardType, nil];
NSString *bestType = [pb availableTypeFromArray:supportedTypes];
if (!bestType) goto releasepool;
int motion_type = MCHAR;
NSString *string = nil;
if ([bestType isEqual:VimPboardType])
{
/* This type should consist of an array with two objects:
* 1. motion type (NSNumber)
* 2. text (NSString)
* If this is not the case we fall back on using NSStringPboardType.
*/
id plist = [pb propertyListForType:VimPboardType];
if ([plist isKindOfClass:[NSArray class]] && [plist count] == 2)
{
id obj = [plist objectAtIndex:1];
if ([obj isKindOfClass:[NSString class]])
{
motion_type = [[plist objectAtIndex:0] intValue];
string = obj;
}
}
}
if (!string)
{
/* Use NSStringPboardType. The motion type is set to line-wise if the
* string contains at least one EOL character, otherwise it is set to
* character-wise (block-wise is never used).
*/
NSMutableString *mstring =
[[pb stringForType:NSStringPboardType] mutableCopy];
if (!mstring) goto releasepool;
/* Replace unrecognized end-of-line sequences with \x0a (line feed). */
NSRange range = { 0, [mstring length] };
unsigned n = [mstring replaceOccurrencesOfString:@"\x0d\x0a"
withString:@"\x0a" options:0
range:range];
if (0 == n)
{
n = [mstring replaceOccurrencesOfString:@"\x0d" withString:@"\x0a"
options:0 range:range];
}
/* Scan for newline character to decide whether the string should be
* pasted line-wise or character-wise.
*/
motion_type = MCHAR;
if (0 < n || NSNotFound != [mstring rangeOfString:@"\n"].location)
motion_type = MLINE;
string = mstring;
}
if (!(MCHAR == motion_type || MLINE == motion_type || MBLOCK == motion_type
|| MAUTO == motion_type))
motion_type = MCHAR;
char_u *str = (char_u*)[string UTF8String];
int len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
#ifdef FEAT_MBYTE
if (input_conv.vc_type != CONV_NONE)
str = string_convert(&input_conv, str, &len);
#endif
if (str)
clip_yank_selection(motion_type, str, len, cbd);
#ifdef FEAT_MBYTE
if (input_conv.vc_type != CONV_NONE)
vim_free(str);
#endif
releasepool:
[pool release];
}
/*
* Send the current selection to the clipboard.
*/
void
clip_mch_set_selection(VimClipboard *cbd)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
/* If the '*' register isn't already filled in, fill it in now. */
cbd->owned = TRUE;
clip_get_selection(cbd);
cbd->owned = FALSE;
/* Get the text to put on the pasteboard. */
long_u llen = 0; char_u *str = 0;
int motion_type = clip_convert_selection(&str, &llen, cbd);
if (motion_type < 0)
goto releasepool;
/* TODO: Avoid overflow. */
int len = (int)llen;
#ifdef FEAT_MBYTE
if (output_conv.vc_type != CONV_NONE)
{
char_u *conv_str = string_convert(&output_conv, str, &len);
if (conv_str)
{
vim_free(str);
str = conv_str;
}
}
#endif
if (len > 0)
{
NSString *string = [[NSString alloc]
initWithBytes:str length:len encoding:NSUTF8StringEncoding];
/* See clip_mch_request_selection() for info on pasteboard types. */
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
NSStringPboardType, nil];
[pb declareTypes:supportedTypes owner:nil];
NSNumber *motion = [NSNumber numberWithInt:motion_type];
NSArray *plist = [NSArray arrayWithObjects:motion, string, nil];
[pb setPropertyList:plist forType:VimPboardType];
[pb setString:string forType:NSStringPboardType];
[string release];
}
vim_free(str);
releasepool:
[pool release];
}
#endif /* FEAT_CLIPBOARD */

View File

@@ -93,6 +93,9 @@
# ifndef HAVE_CONFIG_H
# define UNIX
# endif
# ifndef FEAT_CLIPBOARD
# define FEAT_CLIPBOARD
# endif
#endif
#if defined(MACOS_X) || defined(MACOS_CLASSIC)
# define MACOS