annotate src/os_macosx.m @ 2867:d1445b72ddb7 v7.3.207

updated for version 7.3.207 Problem: Can't compile with MSVC with pentium4 and 64 bit. Solution: Only use SSE2 for 32 bit. (Mike Williams)
author Bram Moolenaar <bram@vim.org>
date Sun, 12 Jun 2011 20:31:31 +0200
parents 10ce04af8c5b
children acda456c788a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
11 * os_macosx.m -- Mac specific things for Mac OS/X.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
14 #ifndef MACOS_X_UNIX
574
25a70b1cd2da updated for version 7.0163
vimboss
parents: 492
diff changeset
15 Error: MACOS 9 is no longer supported in Vim 7
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
2598
10ce04af8c5b updated for version 7.3.021
Bram Moolenaar <bram@vim.org>
parents: 2567
diff changeset
18 /* Avoid a conflict for the definition of Boolean between Mac header files and
10ce04af8c5b updated for version 7.3.021
Bram Moolenaar <bram@vim.org>
parents: 2567
diff changeset
19 * X11 header files. */
10ce04af8c5b updated for version 7.3.021
Bram Moolenaar <bram@vim.org>
parents: 2567
diff changeset
20 #define NO_X11_INCLUDES
10ce04af8c5b updated for version 7.3.021
Bram Moolenaar <bram@vim.org>
parents: 2567
diff changeset
21
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
22 #include "vim.h"
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
23 #import <Cocoa/Cocoa.h>
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
24
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
25
2565
4b7929dad28a Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents: 2315
diff changeset
26 /*
4b7929dad28a Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents: 2315
diff changeset
27 * Clipboard support for the console.
4b7929dad28a Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents: 2315
diff changeset
28 * Don't include this when building the GUI version, the functions in
2567
6931da037310 Do include Mac clipboard code for MacVim.
Bram Moolenaar <bram@vim.org>
parents: 2565
diff changeset
29 * gui_mac.c are used then. TODO: remove those instead?
6931da037310 Do include Mac clipboard code for MacVim.
Bram Moolenaar <bram@vim.org>
parents: 2565
diff changeset
30 * But for MacVim we need these ones.
2565
4b7929dad28a Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents: 2315
diff changeset
31 */
2567
6931da037310 Do include Mac clipboard code for MacVim.
Bram Moolenaar <bram@vim.org>
parents: 2565
diff changeset
32 #if defined(FEAT_CLIPBOARD) && (!defined(FEAT_GUI) || defined(FEAT_GUI_MACVIM))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
2315
2e6dbc2fccd4 Remove obsolete Mac code.
Bram Moolenaar <bram@vim.org>
parents: 2314
diff changeset
34 /* Used to identify clipboard data copied from Vim. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
2315
2e6dbc2fccd4 Remove obsolete Mac code.
Bram Moolenaar <bram@vim.org>
parents: 2314
diff changeset
36 NSString *VimPboardType = @"VimPboardType";
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
37
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
38 void
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
39 clip_mch_lose_selection(VimClipboard *cbd)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
40 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
41 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
42
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
43
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
44 int
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
45 clip_mch_own_selection(VimClipboard *cbd)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
46 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
47 /* This is called whenever there is a new selection and 'guioptions'
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
48 * contains the "a" flag (automatically copy selection). Return TRUE, else
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
49 * the "a" flag does nothing. Note that there is no concept of "ownership"
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
50 * of the clipboard in Mac OS X.
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
51 */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
52 return TRUE;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
53 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
54
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
55
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
56 void
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
57 clip_mch_request_selection(VimClipboard *cbd)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
58 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
59 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
60
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
61 NSPasteboard *pb = [NSPasteboard generalPasteboard];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
62 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
63 NSStringPboardType, nil];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
64 NSString *bestType = [pb availableTypeFromArray:supportedTypes];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
65 if (!bestType) goto releasepool;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
66
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
67 int motion_type = MCHAR;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
68 NSString *string = nil;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
69
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
70 if ([bestType isEqual:VimPboardType])
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
71 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
72 /* This type should consist of an array with two objects:
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
73 * 1. motion type (NSNumber)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
74 * 2. text (NSString)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
75 * If this is not the case we fall back on using NSStringPboardType.
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
76 */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
77 id plist = [pb propertyListForType:VimPboardType];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
78 if ([plist isKindOfClass:[NSArray class]] && [plist count] == 2)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
79 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
80 id obj = [plist objectAtIndex:1];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
81 if ([obj isKindOfClass:[NSString class]])
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
82 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
83 motion_type = [[plist objectAtIndex:0] intValue];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
84 string = obj;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
85 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
86 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
87 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
88
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
89 if (!string)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
90 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
91 /* Use NSStringPboardType. The motion type is set to line-wise if the
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
92 * string contains at least one EOL character, otherwise it is set to
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
93 * character-wise (block-wise is never used).
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
94 */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
95 NSMutableString *mstring =
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
96 [[pb stringForType:NSStringPboardType] mutableCopy];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
97 if (!mstring) goto releasepool;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
98
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
99 /* Replace unrecognized end-of-line sequences with \x0a (line feed). */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
100 NSRange range = { 0, [mstring length] };
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
101 unsigned n = [mstring replaceOccurrencesOfString:@"\x0d\x0a"
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
102 withString:@"\x0a" options:0
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
103 range:range];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
104 if (0 == n)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
105 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
106 n = [mstring replaceOccurrencesOfString:@"\x0d" withString:@"\x0a"
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
107 options:0 range:range];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
108 }
2310
3e4574a4b627 Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2309
diff changeset
109
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
110 /* Scan for newline character to decide whether the string should be
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
111 * pasted line-wise or character-wise.
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
112 */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
113 motion_type = MCHAR;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
114 if (0 < n || NSNotFound != [mstring rangeOfString:@"\n"].location)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
115 motion_type = MLINE;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
116
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
117 string = mstring;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
118 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
119
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
120 if (!(MCHAR == motion_type || MLINE == motion_type || MBLOCK == motion_type
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
121 || MAUTO == motion_type))
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
122 motion_type = MCHAR;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
123
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
124 char_u *str = (char_u*)[string UTF8String];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
125 int len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
126
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
127 #ifdef FEAT_MBYTE
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
128 if (input_conv.vc_type != CONV_NONE)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
129 str = string_convert(&input_conv, str, &len);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
130 #endif
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
131
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
132 if (str)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
133 clip_yank_selection(motion_type, str, len, cbd);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
134
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
135 #ifdef FEAT_MBYTE
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
136 if (input_conv.vc_type != CONV_NONE)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
137 vim_free(str);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
138 #endif
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
139
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
140 releasepool:
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
141 [pool release];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
142 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
143
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
144
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
145 /*
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
146 * Send the current selection to the clipboard.
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
147 */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
148 void
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
149 clip_mch_set_selection(VimClipboard *cbd)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
150 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
151 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
152
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
153 /* If the '*' register isn't already filled in, fill it in now. */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
154 cbd->owned = TRUE;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
155 clip_get_selection(cbd);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
156 cbd->owned = FALSE;
2310
3e4574a4b627 Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2309
diff changeset
157
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
158 /* Get the text to put on the pasteboard. */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
159 long_u llen = 0; char_u *str = 0;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
160 int motion_type = clip_convert_selection(&str, &llen, cbd);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
161 if (motion_type < 0)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
162 goto releasepool;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
163
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
164 /* TODO: Avoid overflow. */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
165 int len = (int)llen;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
166 #ifdef FEAT_MBYTE
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
167 if (output_conv.vc_type != CONV_NONE)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
168 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
169 char_u *conv_str = string_convert(&output_conv, str, &len);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
170 if (conv_str)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
171 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
172 vim_free(str);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
173 str = conv_str;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
174 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
175 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
176 #endif
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
177
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
178 if (len > 0)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
179 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
180 NSString *string = [[NSString alloc]
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
181 initWithBytes:str length:len encoding:NSUTF8StringEncoding];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
182
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
183 /* See clip_mch_request_selection() for info on pasteboard types. */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
184 NSPasteboard *pb = [NSPasteboard generalPasteboard];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
185 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
186 NSStringPboardType, nil];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
187 [pb declareTypes:supportedTypes owner:nil];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
188
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
189 NSNumber *motion = [NSNumber numberWithInt:motion_type];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
190 NSArray *plist = [NSArray arrayWithObjects:motion, string, nil];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
191 [pb setPropertyList:plist forType:VimPboardType];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
192
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
193 [pb setString:string forType:NSStringPboardType];
2310
3e4574a4b627 Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2309
diff changeset
194
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
195 [string release];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
196 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
197
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
198 vim_free(str);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
199 releasepool:
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
200 [pool release];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
201 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
202
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
203 #endif /* FEAT_CLIPBOARD */