annotate src/os_macosx.m @ 44:8f4b4c298247

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