My MacPorts
Revision | 73f93849bfc3218c011e5126a680b06e4d057b6a (tree) |
---|---|
Time | 2009-03-25 23:17:47 |
Author | Kazuki Sakamoto <sakamoto@splh...> |
Commiter | Kazuki Sakamoto |
vim-app with kaoriya
@@ -0,0 +1,165 @@ | ||
1 | +# $Id: Portfile 48326 2009-03-19 09:31:11Z raimue@macports.org $ | |
2 | + | |
3 | +PortSystem 1.0 | |
4 | + | |
5 | +name vim-app | |
6 | +set realname vim | |
7 | +set vim_version 7.2 | |
8 | +set vim_patchlevel 147 | |
9 | +version ${vim_version}.${vim_patchlevel} | |
10 | +revision 0 | |
11 | +categories editors | |
12 | +maintainers nomaintainer | |
13 | +description Vim.app is a GUI version of the famous editor vim. | |
14 | +long_description This port provides Vim.app, a GUI version of the famous editor vim. \ | |
15 | + Vim is a highly configurable text editor built to enable efficient text editing. | |
16 | +homepage http://www.vim.org/ | |
17 | +platforms darwin | |
18 | + | |
19 | +use_bzip2 yes | |
20 | + | |
21 | +distfiles \ | |
22 | + [suffix ${realname}-${vim_version}]:vim \ | |
23 | + ${realname}-${vim_version}-extra.tar.gz:extra \ | |
24 | + ${realname}-${vim_version}-lang.tar.gz:extra \ | |
25 | + app-bm.tar.gz:app_aqua \ | |
26 | + doc.tar.gz:doc_aqua | |
27 | + | |
28 | +checksums \ | |
29 | + [suffix ${realname}-${vim_version}] \ | |
30 | + md5 f0901284b338e448bfd79ccca0041254 \ | |
31 | + sha1 a4b6641ca528fada71ea77c998a441495ed4984c \ | |
32 | + rmd160 eaff64d0fec09d725addf8de569f508b80a5766e \ | |
33 | + ${realname}-${vim_version}-extra.tar.gz \ | |
34 | + md5 35e04482f07c57221c9a751aaa3b8dac \ | |
35 | + sha1 6a17629093e59958bff336b6c122dea1b8b1b649 \ | |
36 | + rmd160 05976466c8a6c1bd2fb2b1d58eb4613947de07df \ | |
37 | + ${realname}-${vim_version}-lang.tar.gz \ | |
38 | + md5 d8884786979e0e520c112faf2e176f05 \ | |
39 | + sha1 970e0dda7e5b2308cf33488be1ea33d593d951cb \ | |
40 | + rmd160 946bd64fbf030b341cc13bee7101f2c0acb26ce2 \ | |
41 | + app-bm.tar.gz \ | |
42 | + md5 418b9e615a34ae5aad918f5c5a694a44 \ | |
43 | + doc.tar.gz \ | |
44 | + md5 692f7874fc617162d0fe110daf39a98a | |
45 | + | |
46 | +patchfiles patch-src_auto_configure.diff | |
47 | + | |
48 | +distname ${realname}[strsed ${vim_version} {g/\.//}] | |
49 | +dist_subdir ${distname} | |
50 | + | |
51 | +master_sites-append \ | |
52 | + http://www.douglas.stebila.ca/files/code/vim/app/:app_aqua \ | |
53 | + http://www.douglas.stebila.ca/files/code/vim/doc/:doc_aqua | |
54 | + | |
55 | +depends_build bin:gnutar:gnutar \ | |
56 | + bin:grep:grep | |
57 | +depends_lib port:ncurses \ | |
58 | + port:gettext \ | |
59 | + port:libiconv \ | |
60 | + port:ctags | |
61 | + | |
62 | +configure.pre_args --prefix=${applications_dir} | |
63 | +configure.args --without-x \ | |
64 | + --disable-gpm \ | |
65 | + --mandir=${prefix}/share/man \ | |
66 | + --with-tlib=ncurses \ | |
67 | + --enable-multibyte \ | |
68 | + --with-features=huge | |
69 | +configure.env CPPFLAGS="-DSYS_VIMRC_FILE=\"${prefix}/etc/vimrc\" -I${prefix}/include" \ | |
70 | + LDFLAGS="-L${prefix}/lib" | |
71 | + | |
72 | +extract.only [suffix ${realname}-${vim_version}] | |
73 | +post-extract { | |
74 | + system "gnutar xvfz ${distpath}/${realname}-${vim_version}-extra.tar.gz -C \ | |
75 | + ${workpath}" | |
76 | + system "gnutar xvfz ${distpath}/${realname}-${vim_version}-lang.tar.gz -C \ | |
77 | + ${workpath}" | |
78 | + system "gnutar xvfz ${distpath}/app-bm.tar.gz -C ${workpath}" | |
79 | + system "gnutar xvfz ${distpath}/doc.tar.gz -C ${workpath}" | |
80 | +} | |
81 | + | |
82 | +use_parallel_build yes | |
83 | + | |
84 | +test.run yes | |
85 | + | |
86 | +pre-destroot { | |
87 | + xinstall -d ${destroot}${applications_dir} | |
88 | +} | |
89 | + | |
90 | +destroot { | |
91 | + # copy Vim.app | |
92 | + file copy ${worksrcpath}/src/Vim.app ${destroot}${applications_dir} | |
93 | + xinstall -m 644 ${filespath}/vimrc ${filespath}/gvimrc \ | |
94 | + ${destroot}${applications_dir}/Vim.app | |
95 | + xinstall -m 644 ${workpath}/doc-txt.icns \ | |
96 | + ${destroot}${applications_dir}/Vim.app/Contents/Resources | |
97 | + xinstall -m 644 ${workpath}/app.icns \ | |
98 | + ${destroot}${applications_dir}/Vim.app/Contents/Resources/gui_mac.icns | |
99 | + # remove the broken link to 'runtime', copy the folder instead | |
100 | + set runtimePath \ | |
101 | + "${destroot}${applications_dir}/Vim.app/Contents/Resources/vim/runtime" | |
102 | + file delete ${runtimePath} | |
103 | + file copy ${worksrcpath}/runtime ${runtimePath} | |
104 | + # fix permissions | |
105 | + foreach f [glob ${runtimePath}/autoload/*.vim] { | |
106 | + file attributes ${f} -permissions 0644 | |
107 | + } | |
108 | + # install launchscript | |
109 | + xinstall -m 755 ${filespath}/gvim.sh ${destroot}/${prefix}/bin/gvim | |
110 | + reinplace "s|@APPPATH@|${applications_dir}|g" ${destroot}/${prefix}/bin/gvim | |
111 | + | |
112 | + # allow for Vim.App to open .nfo, .vim, .latex, .tex, .diff files | |
113 | + system "patch -d ${destroot}${applications_dir}/Vim.app/Contents/ -p0 < ${filespath}/patch-Info.plist" | |
114 | +} | |
115 | + | |
116 | +# general vim variants | |
117 | + | |
118 | +variant big description {Build big feature set} conflicts huge { | |
119 | + configure.args-append --with-features=big | |
120 | +} | |
121 | +variant huge description {Build huge feature set} conflicts big { | |
122 | + configure.args-append --with-features=huge | |
123 | +} | |
124 | +variant xim description {Build with support for X Input Method} { | |
125 | + configure.args-append --with-xim | |
126 | +} | |
127 | + | |
128 | +variant perl description {Enable Perl scripting} { | |
129 | + configure.args-append --enable-perlinterp | |
130 | + depends_lib-append path:bin/perl:perl5 | |
131 | +} | |
132 | +variant python description {Enable Python scripting} { | |
133 | + configure.args-append --enable-pythoninterp | |
134 | + depends_lib-append bin:python:python25 | |
135 | +} | |
136 | +variant ruby description {Enable Ruby scripting} { | |
137 | + configure.args-append --enable-rubyinterp | |
138 | + configure.env-append RC_ARCHS= | |
139 | + depends_lib-append bin:ruby:ruby | |
140 | +} | |
141 | +variant tcl description {Enable Tcl scripting} { | |
142 | + configure.args-append --enable-tclinterp | |
143 | + depends_lib-append port:tcl | |
144 | +} | |
145 | + | |
146 | +variant cscope description {Enable source code browsing with cscope} { | |
147 | + configure.args-append --enable-cscope | |
148 | +} | |
149 | + | |
150 | +platform darwin ppc { | |
151 | + post-destroot { | |
152 | + system "gnutar xvfz ${filespath}/GVim_app.tar.gz -C ${destroot}${applications_dir}/" | |
153 | + xinstall -m 644 ${workpath}/app.icns ${destroot}${applications_dir}/Vim.app/Contents/Resources/appIcon.icns | |
154 | + } | |
155 | +} | |
156 | + | |
157 | +include serverlist | |
158 | +include patchlist | |
159 | + | |
160 | +livecheck.check regex | |
161 | +livecheck.url http://ftp.vim.org/pub/${realname}/patches/${vim_version}/?O=D | |
162 | +livecheck.regex (${vim_version}\.\\d+) | |
163 | + | |
164 | +include gdb | |
165 | +include kaoriya |
@@ -0,0 +1,24 @@ | ||
1 | +set gdbdistfile vimgdb72-1.14.tar.gz | |
2 | +variant gdb description {Enable GDB integration} { | |
3 | + master_sites-append sourceforge:clewn:gdb | |
4 | + distfiles-append ${gdbdistfile}:gdb | |
5 | + checksums-append ${gdbdistfile} md5 e406c64d29a3152a3f5d0fffe3d2bba8 | |
6 | + configure.args-append --enable-gdb | |
7 | + patchfiles-append patch-gdb.c | |
8 | + post-extract { | |
9 | + system "gnutar xvfz ${distpath}/${gdbdistfile} -C ${workpath}" | |
10 | + } | |
11 | + pre-patch { | |
12 | + system "patch -d ${worksrcpath} -p0 < \ | |
13 | + ${workpath}/vimgdb/${distname}.diff" | |
14 | + } | |
15 | + post-destroot { | |
16 | + set runtimePath \ | |
17 | + "${destroot}${applications_dir}/Vim.app/Contents/Resources/vim/runtime" | |
18 | + system "gnutar xvfz ${workpath}/vimgdb/vimgdb_runtime.tgz \ | |
19 | + -C ${runtimePath}" | |
20 | + system "${destroot}${applications_dir}/Vim.app/Contents/MacOS/Vim \ | |
21 | + --cmd \"helptag ${runtimePath}/doc\" \ | |
22 | + --cmd exit" | |
23 | + } | |
24 | +} |
@@ -0,0 +1,58 @@ | ||
1 | +#!/bin/sh | |
2 | +# | |
3 | +# This shell script passes all its arguments to the binary inside the Vim.app | |
4 | +# application bundle. If you make links to this script as view, gvim, etc., | |
5 | +# then it will peek at the name used to call it and set options appropriately. | |
6 | +# | |
7 | +# Based on a script by Wout Mertens and suggestions from Laurent Bihanic. | |
8 | +# This version is the fault of Benji Fisher, 16 May 2005. | |
9 | + | |
10 | +# First, check "All the Usual Suspects" for the location of the Vim.app bundle. | |
11 | +# You can short-circuit this by setting the VIM_APP_DIR environment variable | |
12 | +# or by un-commenting and editing the following line: | |
13 | +# VIM_APP_DIR=/Applications | |
14 | + | |
15 | +binary="@APPPATH@/Vim.app/Contents/MacOS/Vim" | |
16 | + | |
17 | +# Next, peek at the name used to invoke this script, and set options | |
18 | +# accordingly. | |
19 | + | |
20 | +name="`basename "$0"`" | |
21 | +gui= | |
22 | +opts= | |
23 | + | |
24 | +# GUI mode, implies forking | |
25 | +case "$name" in g*|rg*) gui=true ;; esac | |
26 | + | |
27 | +# Restricted mode | |
28 | +case "$name" in r*) opts="$opts -Z";; esac | |
29 | + | |
30 | +# vimdiff and view | |
31 | +case "$name" in | |
32 | + *vimdiff) | |
33 | + opts="$opts -dO" | |
34 | + ;; | |
35 | + *view) | |
36 | + opts="$opts -R" | |
37 | + ;; | |
38 | +esac | |
39 | + | |
40 | +# Last step: fire up vim. | |
41 | +# GUI mode will always create a new Vim instance, because Vim can't have | |
42 | +# more than one graphic window yet. | |
43 | +# The program should fork by default when started in GUI mode, but it does | |
44 | +# not; we work around this when this script is invoked as "gvim" or "rgview" | |
45 | +# etc., but not when it is invoked as "vim -g". | |
46 | +if [ "$gui" ]; then | |
47 | + # Note: this isn't perfect, because any error output goes to the | |
48 | + # terminal instead of the console log. | |
49 | + # But if you use open instead, you will need to fully qualify the | |
50 | + # path names for any filenames you specify, which is hard. | |
51 | + if [[ "$1" == "-" ]]; then | |
52 | + cat | exec "$binary" -g $opts ${1:+"$@"} & | |
53 | + else | |
54 | + exec "$binary" -g $opts ${1:+"$@"} & | |
55 | + fi | |
56 | +else | |
57 | + exec "$binary" $opts ${1:+"$@"} | |
58 | +fi |
@@ -0,0 +1,200 @@ | ||
1 | +" System gvimrc file for Mac OS X | |
2 | +" Author: Benji Fisher <benji@member.AMS.org> | |
3 | +" Last modified: 10 February 2003 | |
4 | + | |
5 | +" If you want to get more Mac-like behavior, leave the "finish" line | |
6 | +" commented out. For vim-standard menus, uncomment this line so that the rest | |
7 | +" of the file will be ignored. | |
8 | + | |
9 | +" finish | |
10 | + | |
11 | +" TODO: Decide whether to leave it in non-compatible mode. | |
12 | +" For now, save and restore. | |
13 | +let s:save_cpo = &cpo | |
14 | +set cpo&vim | |
15 | + | |
16 | +" Define mac-standard menu items and keyboard shortcuts. | |
17 | + | |
18 | +aunmenu &File.&New | |
19 | +amenu 10.325 &File.&New<Tab><D-n> <D-n> | |
20 | +nmap <D-n> :confirm enew<CR> | |
21 | +vmap <D-n> <Esc><D-n>gv | |
22 | +imap <D-n> <C-O><D-n> | |
23 | +cmap <D-n> <C-C><D-n> | |
24 | +omap <D-n> <Esc><D-n> | |
25 | +aunmenu &File.&Open\.\.\. | |
26 | +amenu 10.310 &File.&Open\.\.\.<Tab><D-o> <D-o> | |
27 | +nmap <D-o> :browse confirm e<CR> | |
28 | +vmap <D-o> <Esc><D-o>gv | |
29 | +imap <D-o> <C-O><D-o> | |
30 | +cmap <D-o> <C-C><D-o> | |
31 | +omap <D-o> <Esc><D-o> | |
32 | +aunmenu &File.&Close | |
33 | +amenu 10.330 &File.&Close<Tab><D-w> <D-w> | |
34 | +nmap <silent> <D-w> :if winheight(2) < 0 <Bar> | |
35 | + \ confirm enew <Bar> | |
36 | + \ else <Bar> | |
37 | + \ confirm close <Bar> | |
38 | + \ endif<CR> | |
39 | +vmap <D-w> <Esc><D-w>gv | |
40 | +imap <D-w> <C-O><D-w> | |
41 | +cmap <D-w> <C-C><D-w> | |
42 | +omap <D-w> <Esc><D-w> | |
43 | +aunmenu &File.&Save | |
44 | +amenu 10.340 &File.&Save<Tab><D-s> <D-s> | |
45 | +nmap <silent> <D-s> :if expand("%") == ""<Bar>browse confirm w<Bar> | |
46 | + \ else<Bar>confirm w<Bar>endif<CR> | |
47 | +vmap <D-s> <Esc><D-s>gv | |
48 | +imap <D-s> <C-O><D-s> | |
49 | +cmap <D-s> <C-C><D-s> | |
50 | +omap <D-s> <Esc><D-s> | |
51 | +aunmenu &File.Save\ &As\.\.\. | |
52 | +amenu 10.350 &File.Save\ &As\.\.\.<Tab><D-S> <D-S-s> | |
53 | +nmap <D-S-s> :browse confirm saveas<CR> | |
54 | +vmap <D-S-s> <Esc><D-s>gv | |
55 | +imap <D-S-s> <C-O><D-s> | |
56 | +cmap <D-S-s> <C-C><D-s> | |
57 | +omap <D-S-s> <Esc><D-s> | |
58 | +" map <D-p> ?? | |
59 | +" <D-q> is handled by the OS. | |
60 | +"amenu File.Quit<Tab><D-q> <D-q> | |
61 | +"nmap <D-q> :confirm qall<CR> | |
62 | +"vmap <D-q> <Esc><D-q>gv | |
63 | +"imap <D-q> <C-O><D-q> | |
64 | +"cmap <D-q> <C-C><D-q> | |
65 | +"omap <D-q> <Esc><D-q> | |
66 | +" From the Edit menu of SimpleText: | |
67 | +aunmenu &Edit.&Undo | |
68 | +amenu 20.310 &Edit.&Undo<Tab><D-z> <D-z> | |
69 | +nmap <D-z> u | |
70 | +vmap <D-z> <Esc><D-z>gv | |
71 | +imap <D-z> <C-O><D-z> | |
72 | +cmap <D-z> <C-C><D-z> | |
73 | +omap <D-z> <Esc><D-z> | |
74 | +vunmenu &Edit.Cu&t | |
75 | +vmenu 20.340 &Edit.Cu&t<Tab><D-x> <D-x> | |
76 | +vmap <D-x> "+x | |
77 | +vunmenu &Edit.&Copy | |
78 | +vmenu 20.350 &Edit.&Copy<Tab><D-c> <D-c> | |
79 | +vmap <D-c> "+y | |
80 | +cunmenu &Edit.&Copy | |
81 | +cmenu 20.350 &Edit.&Copy<Tab><D-c> <D-c> | |
82 | +cmap <D-c> <C-Y> | |
83 | +aunmenu &Edit.&Paste | |
84 | +nmenu 20.360 &Edit.&Paste<Tab><D-v> <D-v> | |
85 | +nmap <D-v> "+gP | |
86 | +cmenu &Edit.&Paste<Tab><D-v> <D-v> | |
87 | +cmap <D-v> <C-R>+ | |
88 | +vmenu &Edit.&Paste<Tab><D-v> <D-v> | |
89 | +imenu &Edit.&Paste<Tab><D-v> <D-v> | |
90 | +if has("virtualedit") | |
91 | + vmap <D-v> "-c<Esc><SID>Paste | |
92 | + imap <D-v> <Esc><SID>Pastegi | |
93 | +else | |
94 | + vmap <D-v> "-c<Esc>gix<Esc><SID>Paste"_x | |
95 | + imap <D-v> x<Esc><SID>Paste"_s | |
96 | +endif | |
97 | +aunmenu &Edit.&Select\ All | |
98 | +amenu 20.400 &Edit.Select\ &All<Tab><D-a> <D-a> | |
99 | +nmap <silent> <D-a> :if &slm != ""<Bar>exe ":norm gggH<C-O>G"<Bar> | |
100 | + \ else<Bar>exe ":norm ggVG"<Bar>endif<CR> | |
101 | +vmap <D-a> <Esc><D-a> | |
102 | +imap <D-a> <Esc><D-a> | |
103 | +cmap <D-a> <C-C><D-a> | |
104 | +omap <D-a> <Esc><D-a> | |
105 | +aunmenu &Edit.&Find | |
106 | +amenu 20.410 &Edit.&Find<Tab><D-f> <D-f> | |
107 | +nmap <D-f> / | |
108 | +vmap <D-f> <Esc><D-f> | |
109 | +imap <D-f> <Esc><D-f> | |
110 | +cmap <D-f> <C-C><D-f> | |
111 | +omap <D-f> <Esc><D-f> | |
112 | +amenu 20.420 &Edit.&Next<Tab><D-g> <D-g> | |
113 | +nmap <D-g> n | |
114 | +vmap <D-g> <Esc><D-g> | |
115 | +imap <D-g> <C-O><D-g> | |
116 | +cmap <D-g> <C-C><D-g> | |
117 | +omap <D-g> <Esc><D-g> | |
118 | +vmenu <silent> 20.420 &Edit.Find\ &Selection "9y/<C-R>9<CR> | |
119 | + \:if strlen(@9) > 1 <Bar> | |
120 | + \ exe 'norm!v/' . @9 . '/e' . "<Bslash><lt>CR>"<Bar> | |
121 | + \ else <Bar> exe "norm!v" <Bar> endif<CR> | |
122 | + | |
123 | +" Copied from $VIMRUNTIME/menu.vim: | |
124 | +" Pasting blockwise and linewise selections is not possible in Insert and | |
125 | +" Visual mode without the +virtualedit feature. They are pasted as if they | |
126 | +" were characterwise instead. Add to that some tricks to leave the cursor in | |
127 | +" the right position, also for "gi". | |
128 | +if has("virtualedit") | |
129 | + nnoremap <silent> <script> <SID>Paste :call <SID>Paste()<CR> | |
130 | + func! <SID>Paste() | |
131 | + let ove = &ve | |
132 | + set ve=all | |
133 | + normal `^ | |
134 | + if @+ != '' | |
135 | + normal "+gP | |
136 | + endif | |
137 | + let c = col(".") | |
138 | + normal i | |
139 | + if col(".") < c " compensate for i<ESC> moving the cursor left | |
140 | + normal l | |
141 | + endif | |
142 | + let &ve = ove | |
143 | + endfunc | |
144 | +else | |
145 | + nnoremap <silent> <script> <SID>Paste "=@+.'xy'<CR>gPFx"_2x | |
146 | +endif | |
147 | + | |
148 | +" Add a Preferences... menu item to the Edit menu. | |
149 | +amenu Edit.-SepPrefs- : | |
150 | +amenu Edit.Preferences\.\.\. :call <SID>Preferences()<CR> | |
151 | + | |
152 | +fun! <SID>Preferences() | |
153 | + let prompt = "Choose one of the following:" | |
154 | + let prompt = prompt . "\r1 Set options for the current session." | |
155 | + let prompt = prompt . "\r2 Edit ~/.vimrc for future sessions." | |
156 | + let prompt = prompt . "\r3 Do 1 and 2, in split windows." | |
157 | + let prompt = prompt . "\r4 Edit ~/.gvimrc for future sessions." | |
158 | + let response = inputdialog(prompt, "1") | |
159 | + if response == 1 | |
160 | + options | |
161 | + elseif response == 2 | |
162 | + call s:EditVimrc("vimrc") | |
163 | + elseif response == 3 | |
164 | + call s:EditVimrc() | |
165 | + options | |
166 | + elseif response == 4 | |
167 | + call s:EditVimrc("gvimrc") | |
168 | + else | |
169 | + echohl WarningMsg | |
170 | + echo "Sorry: 1 or 2 or 3 or 4 expected." | |
171 | + echohl None | |
172 | + endif | |
173 | +endfun | |
174 | + | |
175 | +fun! s:EditVimrc(rcfile) | |
176 | + if filewritable($HOME . "/." . a:rcfile) | |
177 | + let vimrc = $HOME . "/." . a:rcfile | |
178 | + elseif filewritable($HOME . "/_" . a:rcfile) | |
179 | + let vimrc = $HOME . "/_" . a:rcfile | |
180 | + else | |
181 | + let prompt = "Create a vimrc file in your home directory:" | |
182 | + let prompt = prompt . "\r." . a:rcfile . " is the Vim standard." | |
183 | + let prompt = prompt . "\r_" . a:rcfile . " is visible from Finder." | |
184 | + let prompt = prompt . "\rLeave blank to cancel:" | |
185 | + let vimrc = inputdialog(prompt, "." . a:rcfile) | |
186 | + if vimrc == "" | |
187 | + return | |
188 | + endif | |
189 | + let vimrc = $HOME . "/" . vimrc | |
190 | + let prompt = "Start with " a:rcfile . "_example.vim ?" | |
191 | + let template = inputdialog(prompt, "Yes") | |
192 | + endif | |
193 | + execute "split" vimrc | |
194 | + if exists("template") && template ==? "Yes" | |
195 | + execute "read" $VIMRUNTIME . "/" . a:rcfile . "_example.vim" | |
196 | + 0put='\" Copied from $VIMRUNTIME/' . a:rcfile . '_example.vim' | |
197 | + endif | |
198 | +endfun | |
199 | + | |
200 | +let &cpo = s:save_cpo |
@@ -0,0 +1,71 @@ | ||
1 | +# apply KaoriYa's patches and enable migemo | |
2 | +# see http://2xup.org/log/2006/09/13-0220 | |
3 | +# http://kimuraw.txt-nifty.com/d/2006/11/vim_portfile.html | |
4 | +set kaoriya_patch vim72-20090321-kaoriya-w32j.exe | |
5 | + | |
6 | +#depends_lib-append lib:libmigemo:cmigemo | |
7 | +master_sites-append http://www.kaoriya.net/dist/:kaoriya | |
8 | +distfiles-append ${kaoriya_patch}:kaoriya | |
9 | +checksums-append ${kaoriya_patch} md5 8c59bb9cb13d43548ca729097ccbb245 | |
10 | +depends_build-append bin:7za:p7zip | |
11 | +post-patch { | |
12 | + system "7za x ${distpath}/${kaoriya_patch}" | |
13 | + if {[variant_isset cocoa]} { | |
14 | + file delete ${worksrcpath}/vim72-kaoriya-w32j/patches/0016-transparency_option.diff | |
15 | + } | |
16 | + system "cat vim72-kaoriya-w32j/patches/*| patch -p0" | |
17 | + system "cat ${portpath}/${filesdir}/patch-fileio.c| patch -p0" | |
18 | +} | |
19 | + | |
20 | +pre-configure { | |
21 | + system "cd src; make autoconf" | |
22 | +} | |
23 | +configure.args-append --enable-migemo | |
24 | + | |
25 | +variant aqua conflicts cocoa { | |
26 | + configure.args-append --enable-gui=carbon | |
27 | + post-patch { | |
28 | + # http://iplab.naist.jp/member/mio-su/dist/vim/inline0.2.diff | |
29 | + # http://wiki.macvim.org/wiki/VimPatches/Transparency | |
30 | + foreach file {configure.in gui_mac.c option.c syntax.c vim.h mbyte.c} { | |
31 | + system "cat ${portpath}/${filesdir}/patch-${file}| patch -p0" | |
32 | + } | |
33 | + } | |
34 | +} | |
35 | + | |
36 | +variant cocoa conflicts aqua { | |
37 | + configure.args-append --enable-gui=cocoa | |
38 | + post-patch { | |
39 | + system "gnutar xvfj ${filespath}/vim-cocoa-mac-20081128.tbz2 -C ${worksrcpath}/src/" | |
40 | + system "cat ${portpath}/${filesdir}/patch-vim-cocoa-20081128 | patch -p1" | |
41 | + foreach file {configure.in Makefile gui_mac.m option.c option-cocoa.c syntax.c vim.h mbyte.c} { | |
42 | + system "cat ${portpath}/${filesdir}/patch-${file}| patch -p0" | |
43 | + } | |
44 | + } | |
45 | + pre-build { | |
46 | + system "cd ${worksrcpath}/src/mac/PSMTabBarControl; xcodebuild" | |
47 | + } | |
48 | +} | |
49 | + | |
50 | +if {![variant_isset aqua] && ![variant_isset cocoa]} {default_variants +aqua} | |
51 | + | |
52 | +post-destroot { | |
53 | + set runtimePath \ | |
54 | + "${destroot}${applications_dir}/Vim.app/Contents/Resources/vim/runtime" | |
55 | + file copy ${prefix}/share/migemo/tools/migemo.vim \ | |
56 | + ${runtimePath}/plugin/migemo.vim | |
57 | + reinplace "s|dict/migemo-dict|dict/\".\\&encoding.\"/migemo-dict|" \ | |
58 | + ${runtimePath}/plugin/migemo.vim | |
59 | + file mkdir ${runtimePath}/dict | |
60 | + set dicts {migemo-dict han2zen.dat hira2kata.dat roma2hira.dat zen2han.dat} | |
61 | + foreach encodePath [glob ${prefix}/share/migemo/*] { | |
62 | + set encode [file tail $encodePath] | |
63 | + if {${encode} != "tools"} { | |
64 | + file mkdir ${runtimePath}/dict/${encode} | |
65 | + foreach dict ${dicts} { | |
66 | + file link -hard ${runtimePath}/dict/${encode}/${dict} \ | |
67 | + ${encodePath}/${dict} | |
68 | + } | |
69 | + } | |
70 | + } | |
71 | +} |
@@ -0,0 +1,14 @@ | ||
1 | +--- Info.plist.orig 2007-03-03 19:46:34.000000000 +0100 | |
2 | ++++ Info.plist 2007-03-03 19:52:37.000000000 +0100 | |
3 | +@@ -36,6 +36,11 @@ | |
4 | + <array> | |
5 | + <string>txt</string> | |
6 | + <string>text</string> | |
7 | ++ <string>nfo</string> | |
8 | ++ <string>vim</string> | |
9 | ++ <string>latex</string> | |
10 | ++ <string>tex</string> | |
11 | ++ <string>diff</string> | |
12 | + </array> | |
13 | + <key>CFBundleTypeMIMETypes</key> | |
14 | + <array> |
@@ -0,0 +1,11 @@ | ||
1 | +--- src/Makefile.orig | |
2 | ++++ src/Makefile | |
3 | +@@ -1254,7 +1254,7 @@ | |
4 | + -mdynamic-no-pic -pipe | |
5 | + COCOAGUI_IPATH = -I. -Iproto -F$(COCOAFMWK_DIR) | |
6 | + COCOAGUI_LIBS_DIR = | |
7 | +-COCOAGUI_LIBS1 = -framework Cocoa -framework PSMTabBarControl -F$(COCOAFMWK_DIR) | |
8 | ++COCOAGUI_LIBS1 = -framework Carbon -framework Cocoa -framework PSMTabBarControl -F$(COCOAFMWK_DIR) | |
9 | + COCOAGUI_LIBS2 = | |
10 | + COCOAGUI_INSTALL = install_macosx | |
11 | + COCOAGUI_TARGETS = |
@@ -0,0 +1,11 @@ | ||
1 | +--- src/configure.in.orig | |
2 | ++++ src/configure.in | |
3 | +@@ -2894,7 +2894,7 @@ | |
4 | + if test "$enable_migemo" = "yes"; then | |
5 | + AC_MSG_RESULT(no) | |
6 | + AC_CHECK_LIB(migemo, migemo_open, | |
7 | +- [LIBS="$LIBS -lmigemo" AC_DEFINE(HAVE_MIGEMO)],,) | |
8 | ++ [LIBS="$LIBS -lmigemo"; AC_DEFINE(HAVE_MIGEMO)],,) | |
9 | + else | |
10 | + AC_MSG_RESULT(yes) | |
11 | + fi |
@@ -0,0 +1,10 @@ | ||
1 | +--- src/fileio.c.orig | |
2 | ++++ src/fileio.c | |
3 | +@@ -358,6 +358,7 @@ | |
4 | + pstate = &enc_table[j]; | |
5 | + if (!pstate->enable || !pstate->check) | |
6 | + continue; | |
7 | ++ #undef check | |
8 | + switch (pstate->check(pstate, d)) | |
9 | + { | |
10 | + case 0: /* keep "alive" state */ |
@@ -0,0 +1,29 @@ | ||
1 | +--- src/gdb.c.orig | |
2 | ++++ src/gdb.c | |
3 | +@@ -1605,7 +1605,7 @@ | |
4 | + if (this->buf == NULL) | |
5 | + { | |
6 | + p_mm = MAXMEM; /* buffer max virtual memory */ | |
7 | +- (void)do_ecmd(0, name, NULL, NULL, ECMD_ONE, ECMD_HIDE); | |
8 | ++ (void)do_ecmd(0, name, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); | |
9 | + p_mm = s_mm; | |
10 | + | |
11 | + vim_free(name); /* free name with vim_free */ | |
12 | +@@ -1665,7 +1665,7 @@ | |
13 | + if (win_split(0, WSP_BOT) == OK) | |
14 | + { | |
15 | + /* create the asm buffer empty */ | |
16 | +- (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE); | |
17 | ++ (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); | |
18 | + gdb_as_setname(name); | |
19 | + # ifdef FEAT_AUTOCMD | |
20 | + /* allow autocommands for loading syntax */ | |
21 | +@@ -1972,7 +1972,7 @@ | |
22 | + } | |
23 | + | |
24 | + (void)do_ecmd(0, fpn, NULL, NULL, lnum, | |
25 | +- (P_HID(curbuf) ? ECMD_HIDE : 0) + ECMD_OLDBUF); | |
26 | ++ (P_HID(curbuf) ? ECMD_HIDE : 0) + ECMD_OLDBUF, NULL); | |
27 | + } | |
28 | + else if (buf != curbuf) | |
29 | + set_curbuf(buf, DOBUF_GOTO); |
@@ -0,0 +1,434 @@ | ||
1 | +--- src/gui_mac.c.orig | |
2 | ++++ src/gui_mac.c | |
3 | +@@ -58,7 +58,8 @@ | |
4 | + SInt32 gMacSystemVersion; | |
5 | + | |
6 | + #ifdef MACOS_CONVERT | |
7 | +-# define USE_CARBONKEYHANDLER | |
8 | ++//# define USE_CARBONKEYHANDLER | |
9 | ++#ifdef USE_CARBONKEYHANDLER | |
10 | + | |
11 | + static int im_is_active = FALSE; | |
12 | + #if 0 | |
13 | +@@ -86,6 +87,7 @@ | |
14 | + static pascal OSStatus gui_mac_unicode_key_event( | |
15 | + EventHandlerCallRef nextHandler, EventRef theEvent); | |
16 | + | |
17 | ++#endif // USE_CARBONKEYHANDLER | |
18 | + #endif | |
19 | + | |
20 | + | |
21 | +@@ -156,6 +158,13 @@ | |
22 | + /* Vector of char_u --> control index for hotkeys in dialogs */ | |
23 | + static short *gDialogHotKeys; | |
24 | + | |
25 | ++/* INLINE IM */ | |
26 | ++#ifdef USE_IM_CONTROL | |
27 | ++TSMDocumentID s_TSMDocID = 0; | |
28 | ++TSMTERecHandle s_TSMTERecHandle = 0; | |
29 | ++TEHandle s_TEHandle = 0; | |
30 | ++#endif /* USE_IM_CONTROL */ | |
31 | ++ | |
32 | + static struct | |
33 | + { | |
34 | + FMFontFamily family; | |
35 | +@@ -167,6 +176,7 @@ | |
36 | + #ifdef MACOS_CONVERT | |
37 | + # define USE_ATSUI_DRAWING | |
38 | + int p_macatsui_last; | |
39 | ++int p_antialias_last = -1; | |
40 | + ATSUStyle gFontStyle; | |
41 | + # ifdef FEAT_MBYTE | |
42 | + ATSUStyle gWideFontStyle; | |
43 | +@@ -301,8 +311,14 @@ | |
44 | + #ifdef USE_ATSUI_DRAWING | |
45 | + static void gui_mac_set_font_attributes(GuiFont font); | |
46 | + static void gui_mac_dispose_atsui_style(void); | |
47 | ++static void gui_mac_change_antialias(); | |
48 | + #endif | |
49 | + | |
50 | ++#ifdef USE_IM_CONTROL | |
51 | ++static pascal void tsmproc_pre(TEHandle textH, SInt32 refCon); | |
52 | ++static pascal void tsmproc_post(TEHandle textH, SInt32 fixLen, SInt32 inputAreaStart, SInt32 inputAreaEnd, SInt32 pinStart, SInt32 pinEnd, SInt32 refCon); | |
53 | ++#endif /* USE_IM_CONTROL */ | |
54 | ++ | |
55 | + /* | |
56 | + * ------------------------------------------------------------ | |
57 | + * Conversion Utility | |
58 | +@@ -1975,11 +1991,26 @@ | |
59 | + { | |
60 | + ControlRef rootControl; | |
61 | + GetRootControl(gui.VimWindow, &rootControl); | |
62 | +- if ((event->modifiers) & activeFlag) | |
63 | ++ if ((event->modifiers) & activeFlag) { | |
64 | + ActivateControl(rootControl); | |
65 | +- else | |
66 | ++#ifdef USE_IM_CONTROL | |
67 | ++ /* INLINE IM */ | |
68 | ++ if (s_TSMDocID) { | |
69 | ++ TEActivate(s_TEHandle); | |
70 | ++ ActivateTSMDocument(s_TSMDocID); | |
71 | ++ } | |
72 | ++#endif /* USE_IM_CONTROL */ | |
73 | ++ } else { | |
74 | + DeactivateControl(rootControl); | |
75 | ++#ifdef USE_IM_CONTROL | |
76 | ++ if (s_TSMDocID) { | |
77 | ++ FixTSMDocument(s_TSMDocID); | |
78 | ++ DeactivateTSMDocument(s_TSMDocID); | |
79 | ++ TEDeactivate(s_TEHandle); | |
80 | ++ } | |
81 | ++#endif /* USE_IM_CONTROL */ | |
82 | + } | |
83 | ++ } | |
84 | + | |
85 | + /* Activate */ | |
86 | + gui_focus_change((event->modifiers) & activeFlag); | |
87 | +@@ -3132,6 +3163,38 @@ | |
88 | + gui.scrollbar_height = gui.scrollbar_width = 15; /* cheat 1 overlap */ | |
89 | + gui.border_offset = gui.border_width = 2; | |
90 | + | |
91 | ++ /* INLINE IM */ | |
92 | ++#ifdef USE_IM_CONTROL | |
93 | ++ if (!s_TSMDocID) | |
94 | ++ { | |
95 | ++ OSErr err; | |
96 | ++ Rect rect; | |
97 | ++ InterfaceTypeList supportedInterfaces; | |
98 | ++ | |
99 | ++ memset(&rect, 0, sizeof(rect)); /* Just dummy initialization */ | |
100 | ++ s_TEHandle = TEStyleNew(&rect, &rect); | |
101 | ++ supportedInterfaces[0] = kTSMTEInterfaceType; | |
102 | ++ err = NewTSMDocument(1, supportedInterfaces, &s_TSMDocID, | |
103 | ++ (SInt32)&s_TSMTERecHandle); | |
104 | ++ if (err == noErr && s_TSMDocID && s_TSMTERecHandle) | |
105 | ++ { | |
106 | ++ TSMTERecPtr prec = *(s_TSMTERecHandle); | |
107 | ++ | |
108 | ++ prec->textH = s_TEHandle; | |
109 | ++ prec->preUpdateProc = NewTSMTEPreUpdateUPP(tsmproc_pre); | |
110 | ++ prec->postUpdateProc = NewTSMTEPostUpdateUPP(tsmproc_post); | |
111 | ++ prec->updateFlag = kTSMTEAutoScroll; | |
112 | ++ prec->refCon = (SInt32)gui.VimWindow; | |
113 | ++ | |
114 | ++ err = UseInputWindow(s_TSMDocID, FALSE); | |
115 | ++ if (err != noErr) | |
116 | ++ printf("UseInputWindow() error %d\n", err); | |
117 | ++ } | |
118 | ++ else | |
119 | ++ printf("NewTSMDocument() error %d\n", err); | |
120 | ++ } | |
121 | ++#endif /* USE_IM_CONTROL */ | |
122 | ++ | |
123 | + /* If Quartz-style text anti aliasing is available (see | |
124 | + gui_mch_draw_string() below), enable it for all font sizes. */ | |
125 | + vim_setenv((char_u *)"QDTEXT_MINSIZE", (char_u *)"1"); | |
126 | +@@ -3227,6 +3290,9 @@ | |
127 | + gui_mch_open(void) | |
128 | + { | |
129 | + ShowWindow(gui.VimWindow); | |
130 | ++#ifdef USE_TRANSPARENCY | |
131 | ++ gui_mch_set_transparency(p_transparency); | |
132 | ++#endif // USE_TRANSPARENCY | |
133 | + | |
134 | + if (gui_win_x != -1 && gui_win_y != -1) | |
135 | + gui_mch_set_winpos(gui_win_x, gui_win_y); | |
136 | +@@ -3260,6 +3326,22 @@ | |
137 | + void | |
138 | + gui_mch_exit(int rc) | |
139 | + { | |
140 | ++ /* INLINE IM */ | |
141 | ++#ifdef USE_IM_CONTROL | |
142 | ++ if (s_TSMDocID) | |
143 | ++ { | |
144 | ++ OSErr err; | |
145 | ++ | |
146 | ++ err = DeactivateTSMDocument(s_TSMDocID); | |
147 | ++ if (err != noErr) | |
148 | ++ printf("DeactivateTSMDocument() error %d\n", err); | |
149 | ++ err = DeleteTSMDocument(s_TSMDocID); | |
150 | ++ if (err != noErr) | |
151 | ++ printf("DeleteTSMDocument() error %d\n", err); | |
152 | ++ s_TSMDocID = NULL; | |
153 | ++ } | |
154 | ++#endif | |
155 | ++ | |
156 | + /* TODO: find out all what is missing here? */ | |
157 | + DisposeRgn(cursorRgn); | |
158 | + | |
159 | +@@ -3369,6 +3451,45 @@ | |
160 | + *screen_h = screenRect.bottom - 40; | |
161 | + } | |
162 | + | |
163 | ++#ifdef USE_ATSUI_DRAWING | |
164 | ++ static void | |
165 | ++gui_mac_change_antialias() | |
166 | ++{ | |
167 | ++ ATSStyleRenderingOptions renderingOptions; | |
168 | ++ | |
169 | ++ if (gMacSystemVersion >= 0x1020) { | |
170 | ++ renderingOptions = p_antialias ? kATSStyleApplyAntiAliasing : kATSStyleNoAntiAliasing;; | |
171 | ++ } else { | |
172 | ++ renderingOptions = kATSStyleNoOptions; | |
173 | ++ } | |
174 | ++ | |
175 | ++ ATSUAttributeTag attribTags[] = | |
176 | ++ { | |
177 | ++ kATSUStyleRenderingOptionsTag, | |
178 | ++ }; | |
179 | ++ | |
180 | ++ ByteCount attribSizes[] = | |
181 | ++ { | |
182 | ++ sizeof(ATSStyleRenderingOptions), | |
183 | ++ }; | |
184 | ++ | |
185 | ++ ATSUAttributeValuePtr attribValues[] = | |
186 | ++ { | |
187 | ++ &renderingOptions, | |
188 | ++ }; | |
189 | ++ | |
190 | ++ if (gFontStyle) | |
191 | ++ ATSUSetAttributes(gFontStyle, | |
192 | ++ (sizeof attribTags) / sizeof(ATSUAttributeTag), | |
193 | ++ attribTags, attribSizes, attribValues); | |
194 | ++ if (gWideFontStyle) | |
195 | ++ ATSUSetAttributes(gWideFontStyle, | |
196 | ++ (sizeof attribTags) / sizeof(ATSUAttributeTag), | |
197 | ++ attribTags, attribSizes, attribValues); | |
198 | ++ | |
199 | ++ p_antialias_last = p_antialias; | |
200 | ++} | |
201 | ++#endif | |
202 | + | |
203 | + /* | |
204 | + * Open the Font Panel and wait for the user to select a font and | |
205 | +@@ -4245,6 +4366,9 @@ | |
206 | + /* switch from nomacatsui to macatsui */ | |
207 | + gui_mac_create_atsui_style(); | |
208 | + | |
209 | ++ if (p_antialias != p_antialias_last) | |
210 | ++ gui_mac_change_antialias(); | |
211 | ++ | |
212 | + if (p_macatsui) | |
213 | + draw_string_ATSUI(row, col, s, len, flags); | |
214 | + else | |
215 | +@@ -6352,10 +6476,12 @@ | |
216 | + #endif | |
217 | + } | |
218 | + | |
219 | +-#if (defined(USE_IM_CONTROL) || defined(PROTO)) && defined(USE_CARBONKEYHANDLER) | |
220 | ++#if (defined(USE_IM_CONTROL) || defined(PROTO)) | |
221 | + /* | |
222 | + * Input Method Control functions. | |
223 | + */ | |
224 | ++static int im_row = 0; | |
225 | ++static int im_col = 0; | |
226 | + | |
227 | + /* | |
228 | + * Notify cursor position to IM. | |
229 | +@@ -6363,13 +6489,11 @@ | |
230 | + void | |
231 | + im_set_position(int row, int col) | |
232 | + { | |
233 | +-#if 0 | |
234 | +- /* TODO: Implement me! */ | |
235 | +- im_start_row = row; | |
236 | +- im_start_col = col; | |
237 | +-#endif | |
238 | ++ im_row = row; | |
239 | ++ im_col = col; | |
240 | + } | |
241 | + | |
242 | ++#if defined(USE_CARBONKEYHANDLER) | |
243 | + static ScriptLanguageRecord gTSLWindow; | |
244 | + static ScriptLanguageRecord gTSLInsert; | |
245 | + static ScriptLanguageRecord gTSLDefault = { 0, 0 }; | |
246 | +@@ -6429,78 +6553,127 @@ | |
247 | + DeactivateTSMDocument(gTSMDocument); | |
248 | + } | |
249 | + } | |
250 | ++#endif // USE_CARBONKEYHANDLER | |
251 | + | |
252 | + /* | |
253 | + * Set IM status on ("active" is TRUE) or off ("active" is FALSE). | |
254 | + */ | |
255 | + void | |
256 | ++#if defined(FEAT_UIMFEP) | |
257 | ++gui_im_set_active(int active) | |
258 | ++#else // FEAT_UIMFEP | |
259 | + im_set_active(int active) | |
260 | ++#endif // FEAT_UIMFEP | |
261 | + { | |
262 | +- ScriptLanguageRecord *slptr = NULL; | |
263 | +- OSStatus err; | |
264 | ++ KeyScript(active ? smKeySysScript : smKeyRoman); | |
265 | ++} | |
266 | + | |
267 | +- if (! gui.in_use) | |
268 | +- return; | |
269 | ++/* | |
270 | ++ * Get IM status. When IM is on, return not 0. Else return 0. | |
271 | ++ */ | |
272 | ++ int | |
273 | ++#if defined(FEAT_UIMFEP) | |
274 | ++gui_im_get_status(void) | |
275 | ++#else // FEAT_UIMFEP | |
276 | ++im_get_status(void) | |
277 | ++#endif // FEAT_UIMFEP | |
278 | ++{ | |
279 | ++ SInt32 script = GetScriptManagerVariable(smKeyScript); | |
280 | ++ return (script != smRoman | |
281 | ++ && script == GetScriptManagerVariable(smSysScript)) ? 1 : 0; | |
282 | ++} | |
283 | + | |
284 | +- if (im_initialized == 0) | |
285 | +- { | |
286 | +- im_initialized = 1; | |
287 | ++static RGBColor s_saved_fg; | |
288 | ++static RGBColor s_saved_bg; | |
289 | + | |
290 | +- /* save default TSM component (should be U.S.) to default */ | |
291 | +- GetDefaultInputMethodOfClass(&gTSCDefault, &gTSLDefault, | |
292 | +- kKeyboardInputMethodClass); | |
293 | +- } | |
294 | ++/* INLINE IM */ | |
295 | ++ static pascal void | |
296 | ++tsmproc_pre(TEHandle textH, SInt32 refCon) | |
297 | ++{ | |
298 | ++ Rect rect; | |
299 | ++ TextStyle style; | |
300 | ++ RGBColor fore; | |
301 | ++ int idx = syn_name2id((char_u *)"IMLine"); | |
302 | + | |
303 | +- if (active == TRUE) | |
304 | ++ /* Save current color and set IM color */ | |
305 | ++ GetForeColor(&s_saved_fg); | |
306 | ++ GetBackColor(&s_saved_bg); | |
307 | ++ gui_mch_set_fg_color(highlight_gui_color_rgb(idx, TRUE)); | |
308 | ++ gui_mch_set_bg_color(highlight_gui_color_rgb(idx, FALSE)); | |
309 | ++ GetForeColor(&fore); | |
310 | ++ style.tsColor = fore; | |
311 | ++ | |
312 | ++ /* Set IME font and color */ | |
313 | ++ style.tsFont = gui.norm_font & 0xFFFF; | |
314 | ++ style.tsSize = gui.norm_font >> 16; | |
315 | ++ TESetStyle(doFont | doSize | doColor, &style, false, textH); | |
316 | ++ | |
317 | ++ /* Set IME's rectangle */ | |
318 | + { | |
319 | +- im_is_active = TRUE; | |
320 | +- ActivateTSMDocument(gTSMDocument); | |
321 | +- slptr = &gTSLInsert; | |
322 | ++ int row = im_row, col = im_col; | |
323 | + | |
324 | +- if (slptr) | |
325 | ++ if (col * 4 > gui.num_cols * 3) | |
326 | + { | |
327 | +- err = SetDefaultInputMethodOfClass(gTSCInsert, slptr, | |
328 | +- kKeyboardInputMethodClass); | |
329 | +- if (err == noErr) | |
330 | +- err = SetTextServiceLanguage(slptr); | |
331 | +- | |
332 | +- if (err == noErr) | |
333 | +- KeyScript(slptr->fScript | smKeyForceKeyScriptMask); | |
334 | ++ /* Slide inline area to 1 line down or up */ | |
335 | ++ if (row > gui.num_rows / 2) | |
336 | ++ --row; | |
337 | ++ else | |
338 | ++ ++row; | |
339 | ++ col = 0; | |
340 | + } | |
341 | ++ rect.top = FILL_Y(row); | |
342 | ++ rect.left = FILL_X(col); | |
343 | ++ rect.right = FILL_X(screen_Columns); | |
344 | ++ rect.bottom = rect.top + gui.char_height; | |
345 | ++ (**textH).destRect = rect; | |
346 | ++ (**textH).viewRect = rect; | |
347 | ++ TECalText(textH); | |
348 | + } | |
349 | +- else | |
350 | +- { | |
351 | +- err = GetTextServiceLanguage(&gTSLInsert); | |
352 | +- if (err == noErr) | |
353 | +- slptr = &gTSLInsert; | |
354 | ++} | |
355 | + | |
356 | +- if (slptr) | |
357 | +- GetDefaultInputMethodOfClass(&gTSCInsert, slptr, | |
358 | +- kKeyboardInputMethodClass); | |
359 | ++ static pascal void | |
360 | ++tsmproc_post(TEHandle textH, SInt32 fixLen, SInt32 inputAreaStart, | |
361 | ++ SInt32 inputAreaEnd, SInt32 pinStart, SInt32 pinEnd, SInt32 refCon) | |
362 | ++{ | |
363 | ++ char_u *to = NULL; | |
364 | ++ vimconv_T conv; | |
365 | ++ int convlen = 0; | |
366 | + | |
367 | +- /* restore to default when switch to normal mode, so than we could | |
368 | +- * enter commands easier */ | |
369 | +- SetDefaultInputMethodOfClass(gTSCDefault, &gTSLDefault, | |
370 | +- kKeyboardInputMethodClass); | |
371 | +- SetTextServiceLanguage(&gTSLDefault); | |
372 | ++ Rect rect = (**textH).viewRect; | |
373 | + | |
374 | +- im_is_active = FALSE; | |
375 | +- DeactivateTSMDocument(gTSMDocument); | |
376 | +- } | |
377 | +-} | |
378 | ++ /* Restore color */ | |
379 | ++ RGBForeColor(&s_saved_fg); | |
380 | ++ RGBBackColor(&s_saved_bg); | |
381 | ++ | |
382 | ++ /* Add IME's result string to input buffer */ | |
383 | ++ if (fixLen > 0) | |
384 | ++ { | |
385 | ++ CharsHandle ch = TEGetText(textH); | |
386 | ++ conv.vc_type = CONV_NONE; | |
387 | ++ convlen = fixLen; | |
388 | ++ convert_setup(&conv, (char_u *)"sjis", p_enc? p_enc: (char_u *)"utf-8"); | |
389 | ++ to = string_convert(&conv, (char_u *)*ch, &convlen); | |
390 | ++ if (to != NULL) | |
391 | ++ add_to_input_buf_csi(to, convlen); | |
392 | ++ else | |
393 | ++ add_to_input_buf_csi(*ch, fixLen); | |
394 | + | |
395 | +-/* | |
396 | +- * Get IM status. When IM is on, return not 0. Else return 0. | |
397 | +- */ | |
398 | +- int | |
399 | +-im_get_status(void) | |
400 | +-{ | |
401 | +- if (! gui.in_use) | |
402 | +- return 0; | |
403 | ++ if (conv.vc_type != CONV_NONE) | |
404 | ++ vim_free(to); | |
405 | ++ convert_setup(&conv, NULL, NULL); | |
406 | ++ } | |
407 | + | |
408 | +- return im_is_active; | |
409 | ++ if (inputAreaEnd < 0) | |
410 | ++ { | |
411 | ++ TESetText("", 0, textH); | |
412 | ++ /* Remove TSMTE garbage */ | |
413 | ++ gui_redraw(rect.left, rect.top, rect.right - rect.left + 1, | |
414 | ++ rect.bottom - rect.top + 1); | |
415 | ++ gui_update_cursor(TRUE, FALSE); | |
416 | ++ } | |
417 | + } | |
418 | + | |
419 | ++ | |
420 | + #endif /* defined(USE_IM_CONTROL) || defined(PROTO) */ | |
421 | + | |
422 | + | |
423 | +@@ -6904,3 +7077,11 @@ | |
424 | + } | |
425 | + | |
426 | + #endif // FEAT_GUI_TABLINE | |
427 | ++ | |
428 | ++#if defined(USE_TRANSPARENCY) | |
429 | ++ void | |
430 | ++gui_mch_set_transparency(int alpha) | |
431 | ++{ | |
432 | ++ SetWindowAlpha(gui.VimWindow, (float)alpha / 255.0f); | |
433 | ++} | |
434 | ++#endif // USE_TRANSPARENCY |
@@ -0,0 +1,71 @@ | ||
1 | +--- src/gui_mac.m.orig | |
2 | ++++ src/gui_mac.m | |
3 | +@@ -21,6 +21,7 @@ | |
4 | + | |
5 | + #include "vim.h" | |
6 | + #import <Cocoa/Cocoa.h> | |
7 | ++#import <Carbon/Carbon.h> | |
8 | + #import <PSMTabBarControl/PSMTabBarControl.h> | |
9 | + | |
10 | + #define GUI_MAC_DEBUG 1 | |
11 | +@@ -102,7 +102,7 @@ | |
12 | + | |
13 | + #define FF_Y(row) (gui_mac.main_height - FILL_Y(row)) | |
14 | + #define FT_Y(row) (gui_mac.main_height - TEXT_Y(row)) | |
15 | +-#define VIM_BG_ALPHA ((100 - p_transp) / 100.0) | |
16 | ++#define VIM_BG_ALPHA ((p_transp - 255) / 255.0) | |
17 | + | |
18 | + /* A simple view to make setting text area, scrollbar position inside | |
19 | + * vim window easier */ | |
20 | +@@ -546,16 +547,24 @@ | |
21 | + | |
22 | + /* Input Method Handling {{{ */ | |
23 | + | |
24 | ++#if defined(FEAT_UIMFEP) | |
25 | ++int gui_im_get_status() | |
26 | ++#else // FEAT_UIMFEP | |
27 | + int im_get_status() | |
28 | ++#endif // FEAT_UIMFEP | |
29 | + { | |
30 | +- if (! gui.in_use) | |
31 | +- return 0; | |
32 | +- | |
33 | +- return 0; | |
34 | ++ SInt32 script = GetScriptManagerVariable(smKeyScript); | |
35 | ++ return (script != smRoman | |
36 | ++ && script == GetScriptManagerVariable(smSysScript)) ? 1 : 0; | |
37 | + } | |
38 | + | |
39 | ++#if defined(FEAT_UIMFEP) | |
40 | ++void gui_im_set_active(int active) | |
41 | ++#else // FEAT_UIMFEP | |
42 | + void im_set_active(int active) | |
43 | ++#endif // FEAT_UIMFEP | |
44 | + { | |
45 | ++ KeyScript(active ? smKeySysScript : smKeyRoman); | |
46 | + } | |
47 | + | |
48 | + void im_set_position(int row, int col) | |
49 | +@@ -2835,6 +2844,13 @@ | |
50 | + | |
51 | + if (markedRange.length > 0) | |
52 | + { | |
53 | ++ int idx = syn_name2id((char_u *)"IMLine"); | |
54 | ++ [self setMarkedTextAttribute:NSColorFromGuiColor( | |
55 | ++ highlight_gui_color_rgb(idx, TRUE), 1.0) | |
56 | ++ forKey:NSBackgroundColorAttributeName]; | |
57 | ++ [self setMarkedTextAttribute:NSColorFromGuiColor( | |
58 | ++ highlight_gui_color_rgb(idx, FALSE), 1.0) | |
59 | ++ forKey:NSForegroundColorAttributeName]; | |
60 | + } else | |
61 | + { | |
62 | + // gui_mac_msg(MSG_DEBUG, @"clear markedText"); | |
63 | +@@ -3244,6 +3260,8 @@ | |
64 | + default: | |
65 | + if (vim_modifiers & MOD_MASK_CTRL) | |
66 | + { | |
67 | ++ if (original_char == 'h' && [self hasMarkedText]) | |
68 | ++ goto insert_text; | |
69 | + result[len++] = modified_char; | |
70 | + add_to_input_buf(result, len); | |
71 | + // gui_mac_msg(MSG_DEBUG, @"CTRL-%c, add_to_input_buf: %d", original_char, len); |
@@ -0,0 +1,30 @@ | ||
1 | +--- src/mbyte.c.orig | |
2 | ++++ src/mbyte.c | |
3 | +@@ -6194,13 +6194,27 @@ | |
4 | + void | |
5 | + im_set_active(int active) | |
6 | + { | |
7 | ++# if defined(FEAT_GUI_MAC) || defined(FEAT_GUI_MACVIM) | |
8 | ++ if (gui.in_use) | |
9 | ++ gui_im_set_active(active); | |
10 | ++ else | |
11 | ++ uimfep_set_active(active); | |
12 | ++# else // FEAT_GUI_MAC || FEAT_GUI_MACVIM | |
13 | + uimfep_set_active(active); | |
14 | ++# endif // FEAT_GUI_MAC || FEAT_GUI_MACVIM | |
15 | + } | |
16 | + | |
17 | + int | |
18 | + im_get_status(void) | |
19 | + { | |
20 | ++# if defined(FEAT_GUI_MAC) || defined(FEAT_GUI_MACVIM) | |
21 | ++ if (gui.in_use) | |
22 | ++ return gui_im_get_status(); | |
23 | ++ else | |
24 | ++ return uimfep_get_status(); | |
25 | ++# else // FEAT_GUI_MAC || FEAT_GUI_MACVIM | |
26 | + return uimfep_get_status(); | |
27 | ++# endif // FEAT_GUI_MAC || FEAT_GUI_MACVIM | |
28 | + } | |
29 | + # endif | |
30 | + |
@@ -0,0 +1,24 @@ | ||
1 | +--- src/option.c.orig | |
2 | ++++ src/option.c | |
3 | +@@ -2563,7 +2563,7 @@ | |
4 | + #else | |
5 | + (char_u *)NULL, PV_NONE, | |
6 | + #endif | |
7 | +- {(char_u *)0L, (char_u *)0L} }, | |
8 | ++ {(char_u *)255L, (char_u *)0L} }, | |
9 | + {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM, | |
10 | + (char_u *)&p_ttimeout, PV_NONE, | |
11 | + {(char_u *)FALSE, (char_u *)0L}}, | |
12 | +@@ -8004,10 +8004,10 @@ | |
13 | + #endif | |
14 | + | |
15 | + #if defined(FEAT_GUI_COCOA) | |
16 | +- /* 'transparency' is a number between 0 and 100 */ | |
17 | ++ /* 'transparency' is a number between 0 and 255 */ | |
18 | + else if (pp == &p_transp) | |
19 | + { | |
20 | +- if (p_transp < 0 || p_transp > 100) | |
21 | ++ if (p_transp < 0 || p_transp > 255) | |
22 | + { | |
23 | + errmsg = e_invarg; | |
24 | + p_transp = old_value; |
@@ -0,0 +1,11 @@ | ||
1 | +--- src/option.c | |
2 | ++++ src/option.c | |
3 | +@@ -446,7 +446,7 @@ | |
4 | + #if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \ | |
5 | + || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \ | |
6 | + || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) | |
7 | +-# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine" | |
8 | ++# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,j:IMLine" | |
9 | + #else | |
10 | + # define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill" | |
11 | + #endif |
@@ -0,0 +1,11 @@ | ||
1 | +--- src/auto/configure.orig 2008-07-24 06:40:36.000000000 -0600 | |
2 | ++++ src/auto/configure 2009-01-18 21:15:03.000000000 -0700 | |
3 | +@@ -15458,7 +15458,7 @@ | |
4 | + if test "$enable_multibyte" = "yes"; then | |
5 | + cflags_save=$CFLAGS | |
6 | + ldflags_save=$LDFLAGS | |
7 | +- if test -n "$x_includes" ; then | |
8 | ++ if test -n "$x_includes" && test "$x_includes" != "NONE"; then | |
9 | + CFLAGS="$CFLAGS -I$x_includes" | |
10 | + LDFLAGS="$X_LIBS $LDFLAGS -lX11" | |
11 | + { $as_echo "$as_me:$LINENO: checking whether X_LOCALE needed" >&5 |
@@ -0,0 +1,12 @@ | ||
1 | +--- src/syntax.c | |
2 | ++++ src/syntax.c | |
3 | +@@ -6144,6 +6144,9 @@ | |
4 | + "Cursor guibg=fg guifg=bg", | |
5 | + "lCursor guibg=fg guifg=bg", /* should be different, but what? */ | |
6 | + #endif | |
7 | ++#ifdef USE_IM_CONTROL | |
8 | ++ "IMLine guibg=White guifg=Black", | |
9 | ++#endif | |
10 | + NULL | |
11 | + }; | |
12 | + |
@@ -0,0 +1,4470 @@ | ||
1 | +diff --git a/src/Makefile b/src/Makefile | |
2 | +index e27a6ce..fb70481 100644 | |
3 | +--- a/src/Makefile | |
4 | ++++ b/src/Makefile | |
5 | +@@ -290,7 +290,7 @@ CC= | |
6 | + # (X) How to include auto/config.mk depends on the version of "make" you have, | |
7 | + # if the current choice doesn't work, try the other one. | |
8 | + | |
9 | +-include auto/config.mk | |
10 | ++-include auto/config.mk | |
11 | + #.include "auto/config.mk" | |
12 | + CClink = $(CC) | |
13 | + | |
14 | +@@ -1011,7 +1011,7 @@ INSTALL_PROG = cp | |
15 | + | |
16 | + # Program to install the data in the target directory. Cannot be "mv"! | |
17 | + INSTALL_DATA = cp | |
18 | +-INSTALL_DATA_R = cp -r | |
19 | ++INSTALL_DATA_R = cp -R | |
20 | + | |
21 | + ### Program to run on installed binary | |
22 | + #STRIP = strip | |
23 | +@@ -1225,7 +1225,7 @@ PHOTONGUI_BUNDLE = | |
24 | + # CARBON GUI | |
25 | + CARBONGUI_SRC = gui.c gui_mac.c | |
26 | + CARBONGUI_OBJ = objects/gui.o objects/gui_mac.o objects/pty.o | |
27 | +-CARBONGUI_DEFS = -DFEAT_GUI_MAC -fno-common -fpascal-strings \ | |
28 | ++CARBONGUI_DEFS = -DFEAT_GUI_MAC -DFEAT_GUI_CARBON -fno-common -fpascal-strings \ | |
29 | + -Wall -Wno-unknown-pragmas \ | |
30 | + -mdynamic-no-pic -pipe | |
31 | + CARBONGUI_IPATH = -I. -Iproto | |
32 | +@@ -1240,6 +1240,26 @@ CARBONGUI_BUNDLE = gui_bundle | |
33 | + APPDIR = $(VIMNAME).app | |
34 | + CARBONGUI_TESTARG = VIMPROG=../$(APPDIR)/Contents/MacOS/$(VIMTARGET) | |
35 | + | |
36 | ++# COCOA GUI | |
37 | ++COCOAGUI_SRC = gui.c gui_mac.m | |
38 | ++PSMTBC_SRC = mac/PSMTabBarControl | |
39 | ++COCOAFMWK_DIR = mac/build/Release | |
40 | ++PSMTBC = $(COCOAFMWK_DIR)/PSMTabBarControl.framework | |
41 | ++COCOAGUI_OBJ = objects/gui.o objects/gui_nmac.o objects/pty.o | |
42 | ++COCOAGUI_DEFS = -DFEAT_GUI_MAC -DFEAT_GUI_COCOA -fno-common -fpascal-strings \ | |
43 | ++ -Wall -Wno-unknown-pragmas \ | |
44 | ++ -mdynamic-no-pic -pipe | |
45 | ++COCOAGUI_IPATH = -I. -Iproto -F$(COCOAFMWK_DIR) | |
46 | ++COCOAGUI_LIBS_DIR = | |
47 | ++COCOAGUI_LIBS1 = -framework Cocoa -framework PSMTabBarControl -F$(COCOAFMWK_DIR) | |
48 | ++COCOAGUI_LIBS2 = | |
49 | ++COCOAGUI_INSTALL = install_macosx | |
50 | ++COCOAGUI_TARGETS = | |
51 | ++COCOAGUI_MAN_TARGETS = | |
52 | ++COCOAGUI_TESTTARGET = gui | |
53 | ++COCOAGUI_BUNDLE = gui_bundle | |
54 | ++COCOAGUI_TESTARG = VIMPROG=../$(APPDIR)/Contents/MacOS/$(VIMTARGET) | |
55 | ++ | |
56 | + # All GUI files | |
57 | + ALL_GUI_SRC = gui.c gui_gtk.c gui_gtk_f.c gui_motif.c gui_xmdlg.c gui_xmebw.c gui_athena.c gui_gtk_x11.c gui_x11.c gui_at_sb.c gui_at_fs.c pty.c | |
58 | + ALL_GUI_PRO = gui.pro gui_gtk.pro gui_motif.pro gui_xmdlg.pro gui_athena.pro gui_gtk_x11.pro gui_x11.pro gui_w16.pro gui_w32.pro gui_photon.pro | |
59 | +@@ -1800,7 +1820,7 @@ installrtbase: $(HELPSOURCE)/vim.1 $(DEST_VIM) $(DEST_RT) \ | |
60 | + -$(SHELL) ./installman.sh install $(DEST_MAN) "" $(INSTALLMANARGS) | |
61 | + @echo generating help tags | |
62 | + # Generate the help tags with ":helptags" to handle all languages. | |
63 | +- -@cd $(HELPSOURCE); $(MAKE) VIMEXE=$(DEST_BIN)/$(VIMTARGET) vimtags | |
64 | ++ -@srcdir=`pwd`; cd $(HELPSOURCE); $(MAKE) VIMEXE=$$srcdir/$(APPDIR)/Contents/MacOS/$(VIMTARGET) vimtags | |
65 | + cd $(HELPSOURCE); \ | |
66 | + files=`ls *.txt tags`; \ | |
67 | + files="$$files `ls *.??x tags-?? 2>/dev/null || true`"; \ | |
68 | +@@ -2411,6 +2431,9 @@ objects/gui_photon.o: gui_photon.c | |
69 | + objects/gui_mac.o: gui_mac.c | |
70 | + $(CCC) -o $@ gui_mac.c | |
71 | + | |
72 | ++objects/gui_nmac.o: gui_mac.m | |
73 | ++ $(CCC) -ObjC -o $@ gui_mac.m | |
74 | ++ | |
75 | + objects/hangulin.o: hangulin.c | |
76 | + $(CCC) -o $@ hangulin.c | |
77 | + | |
78 | +@@ -2568,6 +2591,7 @@ Makefile: | |
79 | + | |
80 | + REZ = /Developer/Tools/Rez | |
81 | + RESDIR = $(APPDIR)/Contents/Resources | |
82 | ++FMWKDIR = $(APPDIR)/Contents/Frameworks | |
83 | + VERSION = $(VIMMAJOR).$(VIMMINOR) | |
84 | + | |
85 | + ### Common flags | |
86 | +@@ -2579,7 +2603,7 @@ install_macosx: gui_bundle | |
87 | + -rm $(RESDIR)/vim/runtime | |
88 | + $(INSTALL_DATA_R) $(APPDIR) $(DESTDIR)$(prefix) | |
89 | + # Generate the help tags file now, it won't work with "make installruntime". | |
90 | +- -@srcdir=`pwd`; cd $(HELPSOURCE); $(MAKE) VIMEXE=$$srcdir/$(VIMTARGET) vimtags | |
91 | ++ -@srcdir=`pwd`; cd $(HELPSOURCE); $(MAKE) VIMEXE=$$srcdir/$(APPDIR)/Contents/MacOS/$(VIMTARGET) vimtags | |
92 | + # Install the runtime files. Recursive! | |
93 | + -mkdir -p $(DESTDIR)$(prefix)/$(RESDIR)/vim/runtime | |
94 | + # -mkdir $(DESTDIR)$(prefix)/$(APPDIR)/bin | |
95 | +@@ -2597,11 +2621,14 @@ install_macosx: gui_bundle | |
96 | + # TODO: Create the vimtutor and/or gvimtutor application. | |
97 | + | |
98 | + gui_bundle: $(RESDIR) bundle-dir bundle-executable bundle-info bundle-resource \ | |
99 | +- bundle-language | |
100 | ++ bundle-language bundle-framework | |
101 | + | |
102 | + $(RESDIR): | |
103 | + mkdir -p $@ | |
104 | + | |
105 | ++$(FMWKDIR): | |
106 | ++ mkdir -p $@ | |
107 | ++ | |
108 | + bundle-dir: $(APPDIR)/Contents $(VIMTARGET) | |
109 | + # Make a link to the runtime directory, so that we can try out the executable | |
110 | + # without installing it. | |
111 | +@@ -2618,7 +2645,7 @@ bundle-info: bundle-dir | |
112 | + @echo "Creating Info.plist" | |
113 | + m4 $(M4FLAGSX) infplist.xml > $(APPDIR)/Contents/Info.plist | |
114 | + | |
115 | +-bundle-resource: bundle-dir bundle-rsrc | |
116 | ++bundle-resource: bundle-dir | |
117 | + cp -f $(RSRC_DIR)/*.icns $(RESDIR) | |
118 | + | |
119 | + ### Classic resources | |
120 | +@@ -2639,6 +2666,14 @@ bundle-rsrc: os_mac.rsr.hqx | |
121 | + # cd po && perl Make_osx.pl --outdir ../$(RESDIR) $(MULTILANG) | |
122 | + bundle-language: bundle-dir | |
123 | + | |
124 | ++$(PSMTBC): | |
125 | ++ @echo "Creating $(PSMTBC)" | |
126 | ++ cd $(PSMTBC_SRC); xcodebuild | |
127 | ++ | |
128 | ++bundle-framework: $(FMWKDIR) $(PSMTBC) | |
129 | ++ rm -rf $(FMWKDIR)/PSMTabBarControl.framework | |
130 | ++ cp -Rf $(PSMTBC) $(FMWKDIR) | |
131 | ++ | |
132 | + $(APPDIR)/Contents: | |
133 | + -$(SHELL) ./mkinstalldirs $(APPDIR)/Contents/MacOS | |
134 | + -$(SHELL) ./mkinstalldirs $(RESDIR)/English.lproj | |
135 | +diff --git a/src/configure.in b/src/configure.in | |
136 | +index ff1bd0c..b911b81 100644 | |
137 | +--- a/src/configure.in | |
138 | ++++ b/src/configure.in | |
139 | +@@ -127,7 +127,7 @@ if test "`(uname) 2>/dev/null`" = Darwin; then | |
140 | + save_cppflags="$CPPFLAGS" | |
141 | + save_cflags="$CFLAGS" | |
142 | + save_ldflags="$LDFLAGS" | |
143 | +- CFLAGS="$CFLAGS -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc" | |
144 | ++ CFLAGS="$CFLAGS -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc -mmacosx-version-min=10.4" | |
145 | + AC_TRY_LINK([ ], [ ], | |
146 | + AC_MSG_RESULT(found, will make universal binary), | |
147 | + | |
148 | +@@ -162,11 +162,20 @@ if test "`(uname) 2>/dev/null`" = Darwin; then | |
149 | + CPPFLAGS="$CPPFLAGS -I/Developer/Headers/FlatCarbon" | |
150 | + fi | |
151 | + | |
152 | +- dnl If Carbon is found, assume we don't want X11 | |
153 | +- dnl unless it was specifically asked for (--with-x) | |
154 | ++ dnl If Carbon or Cocoa is found, assume we don't want | |
155 | ++ dnl X11 unless it was specifically asked for (--with-x) | |
156 | + dnl or Motif, Athena or GTK GUI is used. | |
157 | + AC_CHECK_HEADER(Carbon/Carbon.h, CARBON=yes) | |
158 | +- if test "x$CARBON" = "xyes"; then | |
159 | ++ | |
160 | ++ SAVE_CPPFLAGS=$CPPFLAGS | |
161 | ++ SAVE_CFLAGS=$CFLAGS | |
162 | ++ CPPFLAGS="$CPPFLAGS -ObjC" | |
163 | ++ CFLAGS="$CFLAGS -ObjC" | |
164 | ++ AC_CHECK_HEADER(Cocoa/Cocoa.h, COCOA=yes) | |
165 | ++ CPPFLAGS=$SAVE_CPPFLAGS | |
166 | ++ CFLAGS=$SAVE_CFLAGS | |
167 | ++ | |
168 | ++ if test "x$CARBON" = "xyes" -o "x$COCOA" = "xyes"; then | |
169 | + if test -z "$with_x" -a "X$enable_gui" != Xmotif -a "X$enable_gui" != Xathena -a "X$enable_gui" != Xgtk -a "X$enable_gui" != Xgtk2; then | |
170 | + with_x=no | |
171 | + fi | |
172 | +@@ -1200,7 +1209,7 @@ test "x$with_x" = xno -a "x$MACOSX" != "xyes" -a "x$QNX" != "xyes" && enable_gui | |
173 | + | |
174 | + AC_MSG_CHECKING(--enable-gui argument) | |
175 | + AC_ARG_ENABLE(gui, | |
176 | +- [ --enable-gui[=OPTS] X11 GUI [default=auto] [OPTS=auto/no/gtk/gtk2/gnome/gnome2/motif/athena/neXtaw/photon/carbon]], , enable_gui="auto") | |
177 | ++ [ --enable-gui[=OPTS] X11 GUI [default=auto] [OPTS=auto/no/gtk/gtk2/gnome/gnome2/motif/athena/neXtaw/photon/carbon/cocoa]], , enable_gui="auto") | |
178 | + | |
179 | + dnl Canonicalize the --enable-gui= argument so that it can be easily compared. | |
180 | + dnl Do not use character classes for portability with old tools. | |
181 | +@@ -1216,6 +1225,7 @@ SKIP_ATHENA=YES | |
182 | + SKIP_NEXTAW=YES | |
183 | + SKIP_PHOTON=YES | |
184 | + SKIP_CARBON=YES | |
185 | ++SKIP_COCOA=YES | |
186 | + GUITYPE=NONE | |
187 | + | |
188 | + if test "x$QNX" = "xyes" -a "x$with_x" = "xno" ; then | |
189 | +@@ -1232,14 +1242,20 @@ if test "x$QNX" = "xyes" -a "x$with_x" = "xno" ; then | |
190 | + | |
191 | + elif test "x$MACOSX" = "xyes" -a "x$with_x" = "xno" ; then | |
192 | + SKIP_CARBON= | |
193 | ++ SKIP_COCOA= | |
194 | + case "$enable_gui_canon" in | |
195 | + no) AC_MSG_RESULT(no GUI support) | |
196 | +- SKIP_CARBON=YES ;; | |
197 | ++ SKIP_CARBON=YES | |
198 | ++ SKIP_COCOA=YES ;; | |
199 | + yes|"") AC_MSG_RESULT(yes - automatic GUI support) ;; | |
200 | + auto) AC_MSG_RESULT(auto - automatic GUI support) ;; | |
201 | +- carbon) AC_MSG_RESULT(Carbon GUI support) ;; | |
202 | +- *) AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported]) | |
203 | ++ carbon) AC_MSG_RESULT(Carbon GUI support) | |
204 | ++ SKIP_COCOA=YES ;; | |
205 | ++ cocoa) AC_MSG_RESULT(Cocoa GUI support) | |
206 | + SKIP_CARBON=YES ;; | |
207 | ++ *) AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported]) | |
208 | ++ SKIP_CARBON=YES | |
209 | ++ SKIP_COCOA=YES ;; | |
210 | + esac | |
211 | + | |
212 | + else | |
213 | +@@ -1253,6 +1269,7 @@ else | |
214 | + SKIP_MOTIF= | |
215 | + SKIP_ATHENA= | |
216 | + SKIP_NEXTAW= | |
217 | ++ SKIP_COCOA= | |
218 | + SKIP_CARBON=;; | |
219 | + gtk) AC_MSG_RESULT(GTK+ 1.x GUI support) | |
220 | + SKIP_GTK=;; | |
221 | +@@ -1357,12 +1374,30 @@ if test "x$SKIP_CARBON" != "xYES" -a "$enable_gui_canon" != "carbon"; then | |
222 | + fi | |
223 | + fi | |
224 | + | |
225 | ++if test "x$SKIP_COCOA" != "xYES" -a "$enable_gui_canon" != "cocoa"; then | |
226 | ++ AC_MSG_CHECKING(whether or not to look for Cocoa) | |
227 | ++ AC_ARG_ENABLE(cocoa-check, | |
228 | ++ [ --enable-cocoa-check If auto-select GUI, check for Cocoa [default=yes]], | |
229 | ++ , enable_cocoa_check="yes") | |
230 | ++ AC_MSG_RESULT($enable_cocoa_check); | |
231 | ++ if test "x$enable_cocoa_check" = "xno"; then | |
232 | ++ SKIP_COCOA=YES | |
233 | ++ fi | |
234 | ++fi | |
235 | ++ | |
236 | ++if test "x$MACOSX" = "xyes"; then | |
237 | ++ if test -z "$SKIP_CARBON" -a "x$CARBON" = "xyes"; then | |
238 | ++ AC_MSG_CHECKING(for Carbon GUI) | |
239 | ++ dnl already did the check, just give the message | |
240 | ++ AC_MSG_RESULT(yes); | |
241 | ++ GUITYPE=CARBONGUI | |
242 | ++ elif test -z "$SKIP_COCOA" -a "x$COCOA" = "xyes"; then | |
243 | ++ AC_MSG_CHECKING(for Cocoa GUI) | |
244 | ++ dnl already did the check, just give the message | |
245 | ++ AC_MSG_RESULT(yes); | |
246 | ++ GUITYPE=COCOAGUI | |
247 | ++ fi | |
248 | + | |
249 | +-if test "x$MACOSX" = "xyes" -a -z "$SKIP_CARBON" -a "x$CARBON" = "xyes"; then | |
250 | +- AC_MSG_CHECKING(for Carbon GUI) | |
251 | +- dnl already did the check, just give the message | |
252 | +- AC_MSG_RESULT(yes); | |
253 | +- GUITYPE=CARBONGUI | |
254 | + if test "$VIMNAME" = "vim"; then | |
255 | + VIMNAME=Vim | |
256 | + fi | |
257 | +@@ -1383,6 +1418,7 @@ if test "x$MACOSX" = "xyes" -a -z "$SKIP_CARBON" -a "x$CARBON" = "xyes"; then | |
258 | + SKIP_ATHENA=YES; | |
259 | + SKIP_NEXTAW=YES; | |
260 | + SKIP_PHOTON=YES; | |
261 | ++ SKIP_COCOA=YES; | |
262 | + SKIP_CARBON=YES | |
263 | + fi | |
264 | + | |
265 | +@@ -3133,7 +3169,7 @@ if test "x$MACOSX" = "xyes" -a -n "$PERL"; then | |
266 | + fi | |
267 | + | |
268 | + if test "x$MACOSX" = "xyes" && test "x$CARBON" = "xyes" \ | |
269 | +- && test "x$GUITYPE" != "xCARBONGUI"; then | |
270 | ++ && test "x$GUITYPE" != "xCARBONGUI" && test "x$GUITYPE" != "xCOCOAGUI"; then | |
271 | + AC_MSG_CHECKING(whether we need -framework Carbon) | |
272 | + dnl check for MACOSX without Carbon GUI, but with FEAT_MBYTE | |
273 | + if test "x$enable_multibyte" = "xyes" || test "x$features" = "xbig" \ | |
274 | +diff --git a/src/feature.h b/src/feature.h | |
275 | +index ae16750..dd10bc8 100644 | |
276 | +--- a/src/feature.h | |
277 | ++++ b/src/feature.h | |
278 | +@@ -760,7 +760,7 @@ | |
279 | + #if defined(FEAT_WINDOWS) && defined(FEAT_NORMAL) \ | |
280 | + && (defined(FEAT_GUI_GTK) \ | |
281 | + || (defined(FEAT_GUI_MOTIF) && defined(HAVE_XM_NOTEBOOK_H)) \ | |
282 | +- || defined(FEAT_GUI_MAC) \ | |
283 | ++ || defined(FEAT_GUI_COCOA) \ | |
284 | + || (defined(FEAT_GUI_MSWIN) && (!defined(_MSC_VER) || _MSC_VER > 1020))) | |
285 | + # define FEAT_GUI_TABLINE | |
286 | + #endif | |
287 | +@@ -807,7 +807,7 @@ | |
288 | + #endif | |
289 | + | |
290 | + /* Mac specific thing: Codewarrior interface. */ | |
291 | +-#ifdef FEAT_GUI_MAC | |
292 | ++#ifdef FEAT_GUI_CARBON | |
293 | + # define FEAT_CW_EDITOR | |
294 | + #endif | |
295 | + | |
296 | +@@ -1087,7 +1087,7 @@ | |
297 | + /* | |
298 | + * +dnd Drag'n'drop support. Always used for the GTK+ GUI. | |
299 | + */ | |
300 | +-#if defined(FEAT_CLIPBOARD) && defined(FEAT_GUI_GTK) | |
301 | ++#if defined(FEAT_CLIPBOARD) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_COCOA)) | |
302 | + # define FEAT_DND | |
303 | + #endif | |
304 | + | |
305 | +diff --git a/src/gui.c b/src/gui.c | |
306 | +index bcc3c68..ad30eb9 100644 | |
307 | +--- a/src/gui.c | |
308 | ++++ b/src/gui.c | |
309 | +@@ -1167,7 +1167,7 @@ gui_position_components(total_width) | |
310 | + #endif | |
311 | + | |
312 | + # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \ | |
313 | +- || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_MAC)) | |
314 | ++ || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_COCOA)) | |
315 | + if (gui_has_tabline()) | |
316 | + text_area_y += gui.tabline_height; | |
317 | + #endif | |
318 | +@@ -1254,7 +1254,7 @@ gui_get_base_height() | |
319 | + # endif | |
320 | + # endif | |
321 | + # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \ | |
322 | +- || defined(FEAT_GUI_MOTIF)) | |
323 | ++ || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_COCOA)) | |
324 | + if (gui_has_tabline()) | |
325 | + base_height += gui.tabline_height; | |
326 | + # endif | |
327 | +@@ -2161,7 +2161,7 @@ gui_outstr_nowrap(s, len, flags, fg, bg, back) | |
328 | + if (back != 0 && ((draw_flags & DRAW_BOLD) || (highlight_mask & HL_ITALIC))) | |
329 | + return FAIL; | |
330 | + | |
331 | +-#if defined(RISCOS) || defined(HAVE_GTK2) | |
332 | ++#if defined(RISCOS) || defined(HAVE_GTK2) || defined(FEAT_GUI_COCOA) | |
333 | + /* If there's no italic font, then fake it. | |
334 | + * For GTK2, we don't need a different font for italic style. */ | |
335 | + if (hl_mask_todo & HL_ITALIC) | |
336 | +@@ -2281,7 +2281,7 @@ gui_outstr_nowrap(s, len, flags, fg, bg, back) | |
337 | + /* Draw a composing char on top of the previous char. */ | |
338 | + if (comping) | |
339 | + { | |
340 | +-# if (defined(__APPLE_CC__) || defined(__MRC__)) && TARGET_API_MAC_CARBON | |
341 | ++# if defined(FEAT_GUI_CARBON) | |
342 | + /* Carbon ATSUI autodraws composing char over previous char */ | |
343 | + gui_mch_draw_string(gui.row, scol, s + i, cl, | |
344 | + draw_flags | DRAW_TRANSP); | |
345 | +@@ -4027,7 +4027,7 @@ gui_update_scrollbars(force) | |
346 | + # endif | |
347 | + #endif | |
348 | + | |
349 | +-#if defined(FEAT_GUI_TABLINE) && defined(FEAT_GUI_MSWIN) | |
350 | ++#if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_COCOA)) | |
351 | + if (gui_has_tabline()) | |
352 | + y += gui.tabline_height; | |
353 | + #endif | |
354 | +diff --git a/src/gui.h b/src/gui.h | |
355 | +index 875b5e4..4bbd803 100644 | |
356 | +--- a/src/gui.h | |
357 | ++++ b/src/gui.h | |
358 | +@@ -34,6 +34,7 @@ | |
359 | + #endif | |
360 | + | |
361 | + #ifdef FEAT_GUI_MAC | |
362 | ++#ifndef FEAT_GUI_COCOA | |
363 | + # include <Types.h> | |
364 | + /*# include <Memory.h>*/ | |
365 | + # include <Quickdraw.h> | |
366 | +@@ -51,6 +52,7 @@ | |
367 | + # include <ToolUtils.h> | |
368 | + # include <SegLoad.h>*/ | |
369 | + #endif | |
370 | ++#endif | |
371 | + | |
372 | + #ifdef RISCOS | |
373 | + # include "gui_riscos.h" | |
374 | +@@ -151,7 +153,7 @@ | |
375 | + #define DRAW_BOLD 0x02 /* draw bold text */ | |
376 | + #define DRAW_UNDERL 0x04 /* draw underline text */ | |
377 | + #define DRAW_UNDERC 0x08 /* draw undercurl text */ | |
378 | +-#if defined(RISCOS) || defined(HAVE_GTK2) | |
379 | ++#if defined(RISCOS) || defined(HAVE_GTK2) || defined(FEAT_GUI_COCOA) | |
380 | + # define DRAW_ITALIC 0x10 /* draw italic text */ | |
381 | + #endif | |
382 | + #define DRAW_CURSOR 0x20 /* drawing block cursor (win32) */ | |
383 | +@@ -216,9 +218,13 @@ typedef struct GuiScrollbar | |
384 | + scroll_shift is set to the number of shifts | |
385 | + to reduce the count. */ | |
386 | + #endif | |
387 | +-#ifdef FEAT_GUI_MAC | |
388 | ++#ifdef FEAT_GUI_CARBON | |
389 | + ControlHandle id; /* A handle to the scrollbar */ | |
390 | + #endif | |
391 | ++#ifdef FEAT_GUI_COCOA | |
392 | ++ void *scroller; /* instance of NSScroller */ | |
393 | ++ int enabled; | |
394 | ++#endif | |
395 | + #ifdef RISCOS | |
396 | + int id; /* Window handle of scrollbar window */ | |
397 | + #endif | |
398 | +@@ -457,12 +463,14 @@ typedef struct Gui | |
399 | + #endif | |
400 | + | |
401 | + #ifdef FEAT_GUI_MAC | |
402 | ++#ifndef FEAT_GUI_COCOA | |
403 | + WindowPtr VimWindow; | |
404 | + MenuHandle MacOSHelpMenu; /* Help menu provided by the MacOS */ | |
405 | + int MacOSHelpItems; /* Nr of help-items supplied by MacOS */ | |
406 | + WindowPtr wid; /* Window id of text area */ | |
407 | + int visibility; /* Is window partially/fully obscured? */ | |
408 | + #endif | |
409 | ++#endif | |
410 | + | |
411 | + #ifdef RISCOS | |
412 | + int window_handle; | |
413 | +diff --git a/src/gui_mac.m b/src/gui_mac.m | |
414 | +new file mode 100755 | |
415 | +index 0000000..dff19bc | |
416 | +--- /dev/null | |
417 | ++++ b/src/gui_mac.m | |
418 | +@@ -0,0 +1,3777 @@ | |
419 | ++/* vi:set ts=4 sts=4 sw=4 foldmethod=marker: | |
420 | ++ * | |
421 | ++ * VIM - Vi IMproved by Bram Moolenaar | |
422 | ++ * GUI/Motif support by Robert Webb | |
423 | ++ * Macintosh port by Dany St-Amant | |
424 | ++ * and Axel Kielhorn | |
425 | ++ * Port to MPW by Bernhard Pruemmer | |
426 | ++ * Initial Carbon port by Ammon Skidmore | |
427 | ++ * Initial Cocoa port by Jjgod Jiang | |
428 | ++ * | |
429 | ++ * Do ":help uganda" in Vim to read copying and usage conditions. | |
430 | ++ * Do ":help credits" in Vim to see a list of people who contributed. | |
431 | ++ * See README.txt for an overview of the Vim source code. | |
432 | ++ * | |
433 | ++ * TODO: | |
434 | ++ * | |
435 | ++ * 1. Toolbar. | |
436 | ++ * 2. GUI Tab. | |
437 | ++ * 3. Multiple Windows. | |
438 | ++ */ | |
439 | ++ | |
440 | ++#include "vim.h" | |
441 | ++#import <Cocoa/Cocoa.h> | |
442 | ++#import <PSMTabBarControl/PSMTabBarControl.h> | |
443 | ++ | |
444 | ++#define GUI_MAC_DEBUG 1 | |
445 | ++ | |
446 | ++/* Internal Data Structures {{{ */ | |
447 | ++ | |
448 | ++#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 | |
449 | ++typedef long NSInteger; | |
450 | ++#endif | |
451 | ++ | |
452 | ++/* Key mapping {{{2 */ | |
453 | ++ | |
454 | ++static struct | |
455 | ++{ | |
456 | ++ UniChar function_key; | |
457 | ++ int vim_key; | |
458 | ++} function_key_mapping[] = | |
459 | ++{ | |
460 | ++ { NSUpArrowFunctionKey, K_UP }, | |
461 | ++ { NSDownArrowFunctionKey, K_DOWN }, | |
462 | ++ { NSLeftArrowFunctionKey, K_LEFT }, | |
463 | ++ { NSRightArrowFunctionKey, K_RIGHT }, | |
464 | ++ | |
465 | ++ { NSF1FunctionKey, K_F1 }, | |
466 | ++ { NSF2FunctionKey, K_F2 }, | |
467 | ++ { NSF3FunctionKey, K_F3 }, | |
468 | ++ { NSF4FunctionKey, K_F4 }, | |
469 | ++ { NSF5FunctionKey, K_F5 }, | |
470 | ++ { NSF6FunctionKey, K_F6 }, | |
471 | ++ { NSF7FunctionKey, K_F7 }, | |
472 | ++ { NSF8FunctionKey, K_F8 }, | |
473 | ++ { NSF9FunctionKey, K_F9 }, | |
474 | ++ { NSF10FunctionKey, K_F10 }, | |
475 | ++ | |
476 | ++ { NSF11FunctionKey, K_F11 }, | |
477 | ++ { NSF12FunctionKey, K_F12 }, | |
478 | ++ { NSF13FunctionKey, K_F13 }, | |
479 | ++ { NSF14FunctionKey, K_F14 }, | |
480 | ++ { NSF15FunctionKey, K_F15 }, | |
481 | ++ | |
482 | ++ { NSInsertFunctionKey, K_INS }, | |
483 | ++ { NSDeleteFunctionKey, K_DEL }, | |
484 | ++ { NSHomeFunctionKey, K_HOME }, | |
485 | ++ { NSEndFunctionKey, K_END }, | |
486 | ++ | |
487 | ++ { NSPageUpFunctionKey, K_PAGEUP }, | |
488 | ++ { NSPageDownFunctionKey, K_PAGEDOWN }, | |
489 | ++ | |
490 | ++ { '\t', '\t' }, /* tab */ | |
491 | ++ { '\r', '\r' }, /* return */ | |
492 | ++ { '\003', '\003' }, /* enter */ | |
493 | ++ { '\031', K_S_TAB }, /* backtab */ | |
494 | ++ { '\033', '\033' }, /* escape */ | |
495 | ++ { '\177', K_BS }, /* backspace */ | |
496 | ++ | |
497 | ++ /* End of list marker: */ | |
498 | ++ { 0, 0 }, | |
499 | ++}; | |
500 | ++ | |
501 | ++/* 2}}} */ | |
502 | ++ | |
503 | ++#define VIM_MAX_COL_LEN 1024 | |
504 | ++#define VIM_MAX_FONT_NAME_LEN 256 | |
505 | ++#define VIM_MAX_BUTTON_TITLE 256 | |
506 | ++#define VIM_DEFAULT_FONT_SIZE 9 | |
507 | ++#define VIM_DEFAULT_FONT_NAME (char_u *) "Monaco:h12" | |
508 | ++#define VIM_MAX_CHAR_WIDTH 2 | |
509 | ++ | |
510 | ++#define GUI_MAC_DELAY_OPEN 1 | |
511 | ++#define VIM_UNDERLINE_OFFSET 0 | |
512 | ++#define VIM_UNDERLINE_HEIGHT 1 | |
513 | ++#define VIM_UNDERCURL_HEIGHT 2 | |
514 | ++#define VIM_UNDERCURL_OFFSET (-2) | |
515 | ++#define VIM_UNDERCURL_DOT_WIDTH 2 | |
516 | ++#define VIM_UNDERCURL_DOT_DISTANCE 2 | |
517 | ++ | |
518 | ++#define VIMDropFilesEventSubtype 10001 | |
519 | ++ | |
520 | ++#define FF_Y(row) (gui_mac.main_height - FILL_Y(row)) | |
521 | ++#define FT_Y(row) (gui_mac.main_height - TEXT_Y(row)) | |
522 | ++#define VIM_BG_ALPHA ((100 - p_transp) / 100.0) | |
523 | ++ | |
524 | ++/* A simple view to make setting text area, scrollbar position inside | |
525 | ++ * vim window easier */ | |
526 | ++@interface VIMContentView: NSView { | |
527 | ++ NSTabView *tabView; | |
528 | ++ PSMTabBarControl *tabBarControl; | |
529 | ++} | |
530 | ++ | |
531 | ++- (PSMTabBarControl *) tabBarControl; | |
532 | ++- (NSTabViewItem *) addNewTabViewItem; | |
533 | ++- (NSTabView *) tabView; | |
534 | ++ | |
535 | ++@end | |
536 | ++ | |
537 | ++@interface VIMTextView: NSView <NSTextInput> | |
538 | ++{ | |
539 | ++ NSRange markedRange; | |
540 | ++ NSRange selectedRange; | |
541 | ++ NSAttributedString *markedText; | |
542 | ++ NSMutableDictionary *markedTextAttributes; | |
543 | ++ | |
544 | ++ NSImage *contentImage; | |
545 | ++ NSString *lastSetTitle; | |
546 | ++} | |
547 | ++ | |
548 | ++- (NSAttributedString *) markedText; | |
549 | ++- (void) setMarkedTextAttribute:(id)value forKey:(NSString *)key; | |
550 | ++- (void) mouseAction:(int)button repeated:(bool)repeated event:(NSEvent *)event; | |
551 | ++ | |
552 | ++- (void) synchronizeContentImage; | |
553 | ++- (void) beginDrawing; | |
554 | ++- (void) endDrawing; | |
555 | ++ | |
556 | ++- (void) clearAll; | |
557 | ++ | |
558 | ++@end | |
559 | ++ | |
560 | ++@interface NSWindow (Private) | |
561 | ++- (void) setBottomCornerRounded: (bool) rounded; | |
562 | ++- (void) _setContentHasShadow: (BOOL) has; | |
563 | ++@end | |
564 | ++ | |
565 | ++@interface VIMWindow: NSWindow { | |
566 | ++ VIMTextView *textView; | |
567 | ++} | |
568 | ++ | |
569 | ++- (VIMTextView *) textView; | |
570 | ++- (void) setTextView: (VIMTextView *) view; | |
571 | ++ | |
572 | ++@end | |
573 | ++ | |
574 | ++@interface VIMScroller : NSScroller | |
575 | ++{ | |
576 | ++ scrollbar_T *vimScrollBar; | |
577 | ++} | |
578 | ++ | |
579 | ++- (id)initWithVimScrollbar:(scrollbar_T *)scrollBar | |
580 | ++ orientation:(int)orientation; | |
581 | ++- (scrollbar_T *) vimScrollBar; | |
582 | ++- (void) setThumbValue:(long)value size:(long)size max:(long)max; | |
583 | ++ | |
584 | ++@end | |
585 | ++ | |
586 | ++static int VIMAlertTextFieldHeight = 22; | |
587 | ++ | |
588 | ++@interface VIMAlert : NSAlert { | |
589 | ++ NSTextField *textField; | |
590 | ++} | |
591 | ++ | |
592 | ++- (void) setTextFieldString:(NSString *)textFieldString; | |
593 | ++- (NSTextField *) textField; | |
594 | ++ | |
595 | ++@end | |
596 | ++ | |
597 | ++@interface VimAppController: NSObject | |
598 | ++- (void) alertDidEnd:(VIMAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo; | |
599 | ++- (void) panelDidEnd:(NSSavePanel *)panel code:(int)code context:(void *)context; | |
600 | ++- (void) initializeApplicationTimer:(NSTimer *)timer; | |
601 | ++- (void) blinkCursorTimer:(NSTimer *)timer; | |
602 | ++- (void) menuAction:(id)sender; | |
603 | ++@end | |
604 | ++ | |
605 | ++enum gui_mac_debug_level { | |
606 | ++ MSG_INFO = 0, | |
607 | ++ MSG_DEBUG = 1, | |
608 | ++ MSG_WARN = 2, | |
609 | ++ MSG_ERROR = 3 | |
610 | ++}; | |
611 | ++ | |
612 | ++struct gui_mac_data { | |
613 | ++ NSColor *fg_color, *bg_color, *sp_color; | |
614 | ++ | |
615 | ++ VIMWindow *current_window; | |
616 | ++ | |
617 | ++ NSFont *current_font; | |
618 | ++ NSFont *selected_font; | |
619 | ++ | |
620 | ++ int app_is_running; | |
621 | ++ CGFloat main_height; | |
622 | ++ | |
623 | ++ int blink_state; | |
624 | ++ long blink_wait; | |
625 | ++ long blink_on; | |
626 | ++ long blink_off; | |
627 | ++ NSTimer *blink_timer; | |
628 | ++ | |
629 | ++ bool input_received; | |
630 | ++ bool initialized; | |
631 | ++ | |
632 | ++ int dialog_button; | |
633 | ++ NSString *selected_file; | |
634 | ++ | |
635 | ++ int im_row, im_col; | |
636 | ++ NSEvent *last_mouse_down_event; | |
637 | ++ | |
638 | ++ int debug_level; | |
639 | ++ BOOL showing_tabline; | |
640 | ++ BOOL selecting_tab; | |
641 | ++ BOOL window_opened; | |
642 | ++ | |
643 | ++ CGSize single_advances[VIM_MAX_COL_LEN]; | |
644 | ++ CGSize double_advances[VIM_MAX_COL_LEN]; | |
645 | ++ | |
646 | ++ VimAppController *app_delegate; | |
647 | ++ NSAutoreleasePool *app_pool; | |
648 | ++} gui_mac; | |
649 | ++ | |
650 | ++#define FLIPPED_RECT(view, rect) NSMakeRect(rect.origin.x, \ | |
651 | ++ [view frame].size.height - \ | |
652 | ++ rect.origin.y - rect.size.height, \ | |
653 | ++ rect.size.width, \ | |
654 | ++ rect.size.height) | |
655 | ++#define FLIPPED_POINT(view, point) NSMakePoint(point.x, \ | |
656 | ++ [view frame].size.height - point.y) | |
657 | ++ | |
658 | ++#define gui_mac_run_app() gui_mac.app_is_running = TRUE | |
659 | ++#define gui_mac_stop_app(yn) { gui_mac.input_received = yn; gui_mac.app_is_running = FALSE; } | |
660 | ++#define gui_mac_app_is_running() (gui_mac.app_is_running == TRUE) | |
661 | ++#define gui_mac_get_scroller(sb) ((VIMScroller *) sb->scroller) | |
662 | ++ | |
663 | ++/* Data Structures }}}*/ | |
664 | ++ | |
665 | ++/* Internal functions prototypes {{{ */ | |
666 | ++ | |
667 | ++@interface NSApplication (VimAdditions) | |
668 | ++- (void) setAppleMenu:(NSMenu *)aMenu; | |
669 | ++@end | |
670 | ++ | |
671 | ++@interface NSFont (AppKitPrivate) | |
672 | ++- (ATSUFontID) _atsFontID; | |
673 | ++@end | |
674 | ++ | |
675 | ++NSColor *NSColorFromGuiColor(guicolor_T color, float alpha); | |
676 | ++NSAlertStyle NSAlertStyleFromVim(int type); | |
677 | ++#define NSStringFromVim(str) ([NSString stringWithUTF8String: (const char *) str]) | |
678 | ++NSRect NSRectFromVim(int row1, int col1, int row2, int col2); | |
679 | ++ | |
680 | ++GuiFont gui_mac_create_related_font(GuiFont font, bool italic, bool bold); | |
681 | ++NSWindow *gui_mac_get_window(NSRect rect); | |
682 | ++int gui_mac_create_window(NSRect rect); | |
683 | ++void gui_mac_open_window(); | |
684 | ++void gui_mac_set_application_menu(); | |
685 | ++void gui_mac_send_dummy_event(); | |
686 | ++void gui_mac_update(); | |
687 | ++ | |
688 | ++#define currentView ([gui_mac.current_window textView]) | |
689 | ++#define gui_mac_begin_drawing() [currentView beginDrawing] | |
690 | ++#define gui_mac_end_drawing() [currentView endDrawing] | |
691 | ++#define gui_mac_begin_tab_action() (gui_mac.selecting_tab = YES) | |
692 | ++#define gui_mac_end_tab_action() (gui_mac.selecting_tab = NO) | |
693 | ++ | |
694 | ++int gui_mac_hex_digit(int c); | |
695 | ++void gui_mac_redraw(); | |
696 | ++void gui_mac_scroll_rect(NSRect rect, int lines); | |
697 | ++ | |
698 | ++void print_vim_modifiers(unsigned int vim_modifiers); | |
699 | ++unsigned int gui_mac_key_modifiers_to_vim(unsigned int mac_modifiers); | |
700 | ++unsigned int gui_mac_mouse_modifiers_to_vim(unsigned int mac_modifiers); | |
701 | ++int gui_mac_function_key_to_vim(UniChar key_char, unsigned int vim_modifiers); | |
702 | ++int gui_mac_mouse_button_to_vim(int mac_button); | |
703 | ++ | |
704 | ++GuiFont gui_mac_find_font(char_u *font_name); | |
705 | ++int gui_mac_points_to_pixels(char_u *str, char_u **end); | |
706 | ++NSFont *gui_mac_get_font(char_u *font_name, int size); | |
707 | ++ | |
708 | ++int gui_mac_select_from_font_panel(char_u *font_name); | |
709 | ++void gui_mac_update_scrollbar(scrollbar_T *sb); | |
710 | ++void gui_mac_msg(int level, NSString *fmt, ...); | |
711 | ++ | |
712 | ++#define NSShowRect(msg, rect) gui_mac_msg(MSG_DEBUG, @"%s: %g %g %g %g", msg, \ | |
713 | ++ rect.origin.x, rect.origin.y, \ | |
714 | ++ rect.size.width, rect.size.height) | |
715 | ++ | |
716 | ++/* Internal functions prototypes }}} */ | |
717 | ++ | |
718 | ++/* Initializtion and Finalization {{{ */ | |
719 | ++ | |
720 | ++int gui_mch_init() | |
721 | ++{ | |
722 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_init: %s", exe_name); | |
723 | ++ | |
724 | ++ gui_mac.app_pool = [NSAutoreleasePool new]; | |
725 | ++ | |
726 | ++ [NSApplication sharedApplication]; | |
727 | ++ | |
728 | ++ gui_mac.app_delegate = [VimAppController new]; | |
729 | ++ [NSApp setDelegate: gui_mac.app_delegate]; | |
730 | ++ | |
731 | ++ [NSApp setMainMenu: [[NSMenu new] autorelease]]; | |
732 | ++ gui_mac_set_application_menu(); | |
733 | ++ | |
734 | ++ gui.char_width = 0; | |
735 | ++ gui.char_height = 0; | |
736 | ++ gui.char_ascent = 0; | |
737 | ++ gui.num_rows = 24; | |
738 | ++ gui.num_cols = 80; | |
739 | ++ gui.tabline_height = 22; | |
740 | ++ gui.in_focus = TRUE; | |
741 | ++ | |
742 | ++ gui.norm_pixel = 0x00000000; | |
743 | ++ gui.back_pixel = 0x00FFFFFF; | |
744 | ++ set_normal_colors(); | |
745 | ++ | |
746 | ++ gui_check_colors(); | |
747 | ++ gui.def_norm_pixel = gui.norm_pixel; | |
748 | ++ gui.def_back_pixel = gui.back_pixel; | |
749 | ++ | |
750 | ++ /* Get the colors for the highlight groups (gui_check_colors() might have | |
751 | ++ * changed them) */ | |
752 | ++ highlight_gui_started(); | |
753 | ++ | |
754 | ++#ifdef FEAT_MENU | |
755 | ++ gui.menu_height = 0; | |
756 | ++#endif | |
757 | ++ gui.scrollbar_height = gui.scrollbar_width = [VIMScroller scrollerWidth]; | |
758 | ++ gui.border_offset = gui.border_width = 2; | |
759 | ++ | |
760 | ++ gui_mac.current_window = nil; | |
761 | ++ gui_mac.input_received = NO; | |
762 | ++ gui_mac.initialized = NO; | |
763 | ++ gui_mac.showing_tabline = NO; | |
764 | ++ gui_mac.selecting_tab = NO; | |
765 | ++ gui_mac.window_opened = NO; | |
766 | ++ | |
767 | ++ return OK; | |
768 | ++} | |
769 | ++ | |
770 | ++int gui_mch_init_check() | |
771 | ++{ | |
772 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_init_check"); | |
773 | ++ | |
774 | ++ /* see main.c for reason to disallow */ | |
775 | ++ if (disallow_gui) | |
776 | ++ return FAIL; | |
777 | ++ | |
778 | ++ return OK; | |
779 | ++} | |
780 | ++ | |
781 | ++void gui_mch_exit(int rc) | |
782 | ++{ | |
783 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_exit\n"); | |
784 | ++ | |
785 | ++ [gui_mac.last_mouse_down_event release]; | |
786 | ++ [gui_mac.selected_file release]; | |
787 | ++ [gui_mac.app_delegate release]; | |
788 | ++ [gui_mac.app_pool release]; | |
789 | ++ | |
790 | ++ [[NSUserDefaults standardUserDefaults] synchronize]; | |
791 | ++ | |
792 | ++ exit(rc); | |
793 | ++} | |
794 | ++ | |
795 | ++int gui_mch_open() | |
796 | ++{ | |
797 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_open: %d %d", gui_win_x, gui_win_y); | |
798 | ++ | |
799 | ++#if GUI_MAC_DELAY_OPEN | |
800 | ++#else | |
801 | ++ gui_mac_open_window(); | |
802 | ++ | |
803 | ++ if (gui_win_x != -1 && gui_win_y != -1) | |
804 | ++ gui_mch_set_winpos(gui_win_x, gui_win_y); | |
805 | ++#endif | |
806 | ++ return OK; | |
807 | ++} | |
808 | ++ | |
809 | ++void gui_mch_prepare(int *argc, char **argv) | |
810 | ++{ | |
811 | ++ NSAutoreleasePool *pool = [NSAutoreleasePool new]; | |
812 | ++ | |
813 | ++ NSString *path = [[NSBundle mainBundle] executablePath]; | |
814 | ++ | |
815 | ++ gui_mac.debug_level = MSG_DEBUG; | |
816 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_prepare: %@", path); | |
817 | ++ | |
818 | ++ exe_name = vim_strsave((char_u *) [path fileSystemRepresentation]); | |
819 | ++ | |
820 | ++ [pool release]; | |
821 | ++} | |
822 | ++ | |
823 | ++void gui_mch_set_shellsize( | |
824 | ++ int width, | |
825 | ++ int height, | |
826 | ++ int min_width, | |
827 | ++ int min_height, | |
828 | ++ int base_width, | |
829 | ++ int base_height, | |
830 | ++ int direction) | |
831 | ++{ | |
832 | ++ NSWindow *window = gui_mac_get_window(NSMakeRect(0, 0, width, height)); | |
833 | ++ NSRect contentRect = [window contentRectForFrameRect: [window frame]]; | |
834 | ++ | |
835 | ++ /* keep the top left corner not change */ | |
836 | ++ contentRect.origin.y += contentRect.size.height - height; | |
837 | ++ contentRect.size.width = width; | |
838 | ++ contentRect.size.height = height; | |
839 | ++ | |
840 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_set_shellsize: " | |
841 | ++ "(%d, %d, %d, %d, %d, %d, %d)\n", | |
842 | ++ width, height, min_width, min_height, | |
843 | ++ base_width, base_height, direction); | |
844 | ++ | |
845 | ++ gui_mac_msg(MSG_INFO, @"gui.num_rows (%d) * gui.char_height (%d) = %d", | |
846 | ++ gui.num_rows, gui.char_height, gui.num_rows * gui.char_height); | |
847 | ++ | |
848 | ++ gui_mac_msg(MSG_INFO, @"gui.num_cols (%d) * gui.char_width (%d) = %d", | |
849 | ++ gui.num_cols, gui.char_width, gui.num_cols * gui.char_width); | |
850 | ++ | |
851 | ++ NSRect frame = [window frameRectForContentRect: contentRect]; | |
852 | ++ [window setFrame: frame display: NO]; | |
853 | ++} | |
854 | ++ | |
855 | ++void gui_mch_set_text_area_pos(int x, int y, int w, int h) | |
856 | ++{ | |
857 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_set_text_area_pos: " | |
858 | ++ "%d, %d, %d, %d", x, y, w, h); | |
859 | ++ | |
860 | ++ NSRect viewRect = NSMakeRect(x, y, w, h); | |
861 | ++ // If we don't have a text view yet, allocate it first | |
862 | ++ if (! currentView) | |
863 | ++ { | |
864 | ++ // NSShowRect("create textView: ", viewRect); | |
865 | ++ VIMTextView *textView = [[VIMTextView alloc] initWithFrame: viewRect]; | |
866 | ++ [textView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; | |
867 | ++ | |
868 | ++ [gui_mac.current_window setTextView: textView]; | |
869 | ++ [textView release]; | |
870 | ++ } | |
871 | ++ else | |
872 | ++ { | |
873 | ++ if (! NSEqualRects([currentView frame], viewRect)) | |
874 | ++ [currentView setFrame: viewRect]; | |
875 | ++ | |
876 | ++ [currentView synchronizeContentImage]; | |
877 | ++ | |
878 | ++ if ([currentView inLiveResize]) | |
879 | ++ [gui_mac.current_window setTitle: | |
880 | ++ [NSString stringWithFormat: @"VIM - %d×%d", gui.num_cols, gui.num_rows]]; | |
881 | ++ } | |
882 | ++} | |
883 | ++ | |
884 | ++/* Initializtion and Finalization }}} */ | |
885 | ++ | |
886 | ++/* Event related {{{ */ | |
887 | ++ | |
888 | ++void gui_mch_update() | |
889 | ++{ | |
890 | ++ // gui_mch_wait_for_chars(0); | |
891 | ++} | |
892 | ++ | |
893 | ++/* wtime < 0: wait forever | |
894 | ++ * wtime > 0: wait wtime milliseconds | |
895 | ++ * wtime = 0: don't wait, only poll existing events | |
896 | ++ */ | |
897 | ++int gui_mch_wait_for_chars(int wtime) | |
898 | ++{ | |
899 | ++ NSEvent *event; | |
900 | ++ NSAutoreleasePool *pool; | |
901 | ++ NSDate *date; | |
902 | ++ | |
903 | ++ pool = [[NSAutoreleasePool alloc] init]; | |
904 | ++ | |
905 | ++ // TODO: only redraw modified part | |
906 | ++ if (wtime != 0) | |
907 | ++ gui_mac_redraw(); | |
908 | ++ | |
909 | ++ if (wtime == 0) | |
910 | ++ { | |
911 | ++ // gui_mac_msg(MSG_DEBUG, @"gui_mch_wait_for_chars: don't wait"); | |
912 | ++ date = [NSDate distantPast]; | |
913 | ++ } | |
914 | ++ else if (wtime > 0) | |
915 | ++ { | |
916 | ++ // gui_mac_msg(MSG_DEBUG, @"gui_mch_wait_for_chars: wait for %d ms", wtime); | |
917 | ++ date = [NSDate dateWithTimeIntervalSinceNow: (double) wtime / 1000.0]; | |
918 | ++ } | |
919 | ++ /* wtime < 0, wait forever */ | |
920 | ++ else | |
921 | ++ { | |
922 | ++ // gui_mac_msg(MSG_DEBUG, @"gui_mch_wait_for_chars: wait forever"); | |
923 | ++ date = [NSDate distantFuture]; | |
924 | ++ } | |
925 | ++ | |
926 | ++ /* It's tricky here: we don't want to use -[NSApplication run:] | |
927 | ++ * all the time, but we need it to do some initialization for | |
928 | ++ * the first time this app starts. So we install a timer to | |
929 | ++ * stop: NSApp just after it runs. | |
930 | ++ */ | |
931 | ++ if (gui_mac.initialized == NO) | |
932 | ++ { | |
933 | ++ // gui_mac_msg(MSG_DEBUG, @"first time, begin initialization..."); | |
934 | ++ [NSTimer scheduledTimerWithTimeInterval: 0.1 | |
935 | ++ target: gui_mac.app_delegate | |
936 | ++ selector: @selector(initializeApplicationTimer:) | |
937 | ++ userInfo: 0 | |
938 | ++ repeats: NO]; | |
939 | ++ [NSApp run]; | |
940 | ++ | |
941 | ++ gui_mac.initialized = YES; | |
942 | ++ // gui_mac_msg(MSG_DEBUG, @"end initialization."); | |
943 | ++ } | |
944 | ++ | |
945 | ++ gui_mac_run_app(); | |
946 | ++ while (gui_mac_app_is_running() && | |
947 | ++ (event = [NSApp nextEventMatchingMask: NSAnyEventMask | |
948 | ++ untilDate: date | |
949 | ++ inMode: NSDefaultRunLoopMode | |
950 | ++ dequeue: YES]) != nil) | |
951 | ++ { | |
952 | ++ [NSApp sendEvent: event]; | |
953 | ++ } | |
954 | ++ | |
955 | ++ BOOL last_received = gui_mac.input_received; | |
956 | ++ | |
957 | ++ gui_mac.input_received = NO; | |
958 | ++ | |
959 | ++ [pool release]; | |
960 | ++ return last_received; | |
961 | ++} | |
962 | ++ | |
963 | ++/* Event related }}} */ | |
964 | ++ | |
965 | ++/* Input Method Handling {{{ */ | |
966 | ++ | |
967 | ++int im_get_status() | |
968 | ++{ | |
969 | ++ if (! gui.in_use) | |
970 | ++ return 0; | |
971 | ++ | |
972 | ++ return 0; | |
973 | ++} | |
974 | ++ | |
975 | ++void im_set_active(int active) | |
976 | ++{ | |
977 | ++} | |
978 | ++ | |
979 | ++void im_set_position(int row, int col) | |
980 | ++{ | |
981 | ++ gui_mac_msg(MSG_INFO, @"im_set_position: (%d, %d)", row, col); | |
982 | ++ gui_mac.im_row = row; | |
983 | ++ gui_mac.im_col = col; | |
984 | ++} | |
985 | ++ | |
986 | ++/* Input Method Handling }}} */ | |
987 | ++ | |
988 | ++/* Misc Stuff {{{ */ | |
989 | ++ | |
990 | ++void gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) | |
991 | ++{ | |
992 | ++ CGRect rect; | |
993 | ++ | |
994 | ++ rect = CGDisplayBounds(CGMainDisplayID()); | |
995 | ++ | |
996 | ++ *screen_w = (int) rect.size.width; | |
997 | ++ *screen_h = (int) rect.size.height; | |
998 | ++ | |
999 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_get_screen_dimensions: %d, %d", | |
1000 | ++ *screen_w, *screen_h); | |
1001 | ++} | |
1002 | ++ | |
1003 | ++#ifdef USE_MCH_ERRMSG | |
1004 | ++ | |
1005 | ++void display_errors() | |
1006 | ++{ | |
1007 | ++ fflush(stderr); | |
1008 | ++} | |
1009 | ++ | |
1010 | ++#endif | |
1011 | ++ | |
1012 | ++int gui_mch_haskey(char_u *name) | |
1013 | ++{ | |
1014 | ++ return OK; | |
1015 | ++} | |
1016 | ++ | |
1017 | ++void gui_mch_beep() | |
1018 | ++{ | |
1019 | ++ NSBeep(); | |
1020 | ++} | |
1021 | ++ | |
1022 | ++void gui_mch_toggle_tearoffs(int enable) | |
1023 | ++{ | |
1024 | ++ /* no tearoff menus */ | |
1025 | ++} | |
1026 | ++ | |
1027 | ++/* Misc Stuff }}} */ | |
1028 | ++ | |
1029 | ++/* Font Handling {{{ */ | |
1030 | ++ | |
1031 | ++int gui_mch_init_font(char_u *font_name, int fontset) | |
1032 | ++{ | |
1033 | ++ NSAutoreleasePool *pool; | |
1034 | ++ NSFont *mac_font; | |
1035 | ++ CTFontRef ctFont; | |
1036 | ++ GuiFont vim_font; | |
1037 | ++ int i; | |
1038 | ++ NSSize advance; | |
1039 | ++ char_u used_font_name[VIM_MAX_FONT_NAME_LEN]; | |
1040 | ++ | |
1041 | ++ if (font_name == NULL) | |
1042 | ++ font_name = VIM_DEFAULT_FONT_NAME; | |
1043 | ++ | |
1044 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_init_font: %s", font_name); | |
1045 | ++ | |
1046 | ++ if (STRCMP(font_name, "*") == 0) | |
1047 | ++ { | |
1048 | ++ char_u *new_p_guifont; | |
1049 | ++ | |
1050 | ++ if (gui_mac_select_from_font_panel(font_name) != OK) | |
1051 | ++ return FAIL; | |
1052 | ++ | |
1053 | ++ /* Set guifont to the name of the selected font. */ | |
1054 | ++ new_p_guifont = alloc(STRLEN(font_name) + 1); | |
1055 | ++ if (new_p_guifont != NULL) | |
1056 | ++ { | |
1057 | ++ STRCPY(new_p_guifont, font_name); | |
1058 | ++ vim_free(p_guifont); | |
1059 | ++ p_guifont = new_p_guifont; | |
1060 | ++ /* Replace spaces in the font name with underscores. */ | |
1061 | ++ for ( ; *new_p_guifont; ++new_p_guifont) | |
1062 | ++ { | |
1063 | ++ if (*new_p_guifont == ' ') | |
1064 | ++ *new_p_guifont = '_'; | |
1065 | ++ } | |
1066 | ++ } | |
1067 | ++ } | |
1068 | ++ | |
1069 | ++ pool = [NSAutoreleasePool new]; | |
1070 | ++ vim_font = gui_mac_find_font(font_name); | |
1071 | ++ | |
1072 | ++ if (vim_font == NOFONT) | |
1073 | ++ { | |
1074 | ++ gui_mac_msg(MSG_WARN, @"find_font failed"); | |
1075 | ++ return FAIL; | |
1076 | ++ } | |
1077 | ++ | |
1078 | ++ gui.norm_font = vim_font; | |
1079 | ++ gui.ital_font = gui_mac_create_related_font(vim_font, true, false); | |
1080 | ++ gui.bold_font = gui_mac_create_related_font(vim_font, false, true); | |
1081 | ++ gui.boldital_font = gui_mac_create_related_font(vim_font, true, true); | |
1082 | ++ | |
1083 | ++ // NSLog(@"i(%@), b(%@), ib(%@)", gui.ital_font, gui.bold_font, gui.boldital_font); | |
1084 | ++ vim_strncpy(used_font_name, font_name, sizeof(used_font_name) - 1); | |
1085 | ++ | |
1086 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_init_font: font_name: '%s'", font_name); | |
1087 | ++ | |
1088 | ++ hl_set_font_name(used_font_name); | |
1089 | ++ | |
1090 | ++ mac_font = (NSFont *) vim_font; | |
1091 | ++ ctFont = (CTFontRef) mac_font; | |
1092 | ++ advance = [mac_font advancementForGlyph: (NSGlyph) '_']; | |
1093 | ++ | |
1094 | ++ /* in 72 DPI, 1 point = 1 pixel */ | |
1095 | ++ gui.char_ascent = roundf(CTFontGetAscent(ctFont)); | |
1096 | ++ gui.char_width = roundf(advance.width); | |
1097 | ++ | |
1098 | ++ // Initialize advances array, it's a pre-mature optimization, evil | |
1099 | ++ for (i = 0; i < VIM_MAX_COL_LEN; i++) | |
1100 | ++ { | |
1101 | ++ gui_mac.single_advances[i] = CGSizeMake(gui.char_width, 0); | |
1102 | ++ gui_mac.double_advances[i] = CGSizeMake(gui.char_width * 2, 0); | |
1103 | ++ } | |
1104 | ++ | |
1105 | ++ /* Character placement in a line: | |
1106 | ++ * | |
1107 | ++ * +-----------------------+ <- top | |
1108 | ++ * | p_linespace | |
1109 | ++ * +-------------- | |
1110 | ++ * | Ascent | |
1111 | ++ * +---------------- <- origin.y | |
1112 | ++ * | Descent | |
1113 | ++ * +------------------ | |
1114 | ++ * | Leading | |
1115 | ++ * +------------------------+ <- bottom | |
1116 | ++ * | |
1117 | ++ * The real situation is a bit complicated than we thought, | |
1118 | ++ * basically, some fonts may find the Descent + Leading not | |
1119 | ++ * enough to put every details of their characters (i.e. the | |
1120 | ++ * descent part of a 'g' or 'y' may exceeds the bottom line). | |
1121 | ++ * However, we must fill the entire rectangle ranged from | |
1122 | ++ * top to bottom. So in consequence, the rect of the next | |
1123 | ++ * line can overwrites some of the descent part of the upper | |
1124 | ++ * line, which is bad, but no better solutions. */ | |
1125 | ++ | |
1126 | ++ float height = CTFontGetAscent(ctFont) + | |
1127 | ++ CTFontGetDescent(ctFont) + | |
1128 | ++ CTFontGetLeading(ctFont); | |
1129 | ++ // NSLog(@"Ascent = %g, Descent = %g, Leading = %g", | |
1130 | ++ // CTFontGetAscent(ctFont), CTFontGetDescent(ctFont), CTFontGetLeading(ctFont)); | |
1131 | ++ gui.char_height = roundf(height) + p_linespace; | |
1132 | ++ | |
1133 | ++ [gui_mac.current_window setResizeIncrements: NSMakeSize(gui.char_width, gui.char_height)]; | |
1134 | ++ | |
1135 | ++#if 0 | |
1136 | ++ gui_mac_msg(MSG_INFO, @"ascent = %d, width = %d, height = %d, %f, %f", | |
1137 | ++ gui.char_ascent, gui.char_width, gui.char_height, | |
1138 | ++ [mac_font ascender], [mac_font descender]); | |
1139 | ++#endif | |
1140 | ++ [pool release]; | |
1141 | ++ | |
1142 | ++ return OK; | |
1143 | ++} | |
1144 | ++ | |
1145 | ++void gui_mch_free_font(GuiFont font) | |
1146 | ++{ | |
1147 | ++ [(NSFont *) font release]; | |
1148 | ++} | |
1149 | ++ | |
1150 | ++void gui_mch_set_font(GuiFont font) | |
1151 | ++{ | |
1152 | ++ gui_mac.current_font = (NSFont *) font; | |
1153 | ++ [currentView setMarkedTextAttribute: gui_mac.current_font | |
1154 | ++ forKey: NSFontAttributeName]; | |
1155 | ++} | |
1156 | ++ | |
1157 | ++GuiFont gui_mch_get_font(char_u *name, int giveErrorIfMissing) | |
1158 | ++{ | |
1159 | ++ GuiFont font; | |
1160 | ++ | |
1161 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_get_font: %s", name); | |
1162 | ++ font = gui_mac_find_font(name); | |
1163 | ++ | |
1164 | ++ if (font == NOFONT) | |
1165 | ++ { | |
1166 | ++ if (giveErrorIfMissing) | |
1167 | ++ EMSG2(_(e_font), name); | |
1168 | ++ return NOFONT; | |
1169 | ++ } | |
1170 | ++ /* | |
1171 | ++ * TODO : Accept only monospace | |
1172 | ++ */ | |
1173 | ++ | |
1174 | ++ return font; | |
1175 | ++} | |
1176 | ++ | |
1177 | ++char_u *gui_mch_get_fontname(GuiFont font, char_u *name) | |
1178 | ++{ | |
1179 | ++ if (name == NULL) | |
1180 | ++ return NULL; | |
1181 | ++ | |
1182 | ++ return vim_strsave(name); | |
1183 | ++} | |
1184 | ++ | |
1185 | ++int gui_mch_adjust_charheight() | |
1186 | ++{ | |
1187 | ++ CTFontRef mac_font = (CTFontRef) gui_mac.current_font; | |
1188 | ++ | |
1189 | ++ if (mac_font == nil) | |
1190 | ++ return OK; | |
1191 | ++ | |
1192 | ++ /* in 72 DPI, 1 point = 1 pixel */ | |
1193 | ++ gui.char_ascent = roundf(CTFontGetAscent(mac_font)); | |
1194 | ++ gui.char_height = roundf(CTFontGetAscent(mac_font) + | |
1195 | ++ CTFontGetDescent(mac_font) + | |
1196 | ++ CTFontGetLeading(mac_font)) + p_linespace; | |
1197 | ++ return OK; | |
1198 | ++} | |
1199 | ++ | |
1200 | ++/* Font Handling }}} */ | |
1201 | ++ | |
1202 | ++/* Window Handling {{{ */ | |
1203 | ++ | |
1204 | ++@implementation VIMWindow | |
1205 | ++ | |
1206 | ++- (id) initWithContentRect:(NSRect)contentRect | |
1207 | ++{ | |
1208 | ++ unsigned int windowStyle = NSTitledWindowMask | | |
1209 | ++ NSMiniaturizableWindowMask | | |
1210 | ++ NSClosableWindowMask | | |
1211 | ++ NSResizableWindowMask | | |
1212 | ++ NSUnifiedTitleAndToolbarWindowMask | | |
1213 | ++ NSTexturedBackgroundWindowMask; | |
1214 | ++ | |
1215 | ++ // NSShowRect("VIMWindow initWithContentRect", contentRect); | |
1216 | ++ if ([super initWithContentRect: contentRect | |
1217 | ++ styleMask: windowStyle | |
1218 | ++ backing: NSBackingStoreBuffered | |
1219 | ++ defer: YES]) | |
1220 | ++ { | |
1221 | ++ // [self setBackgroundColor: [NSColor clearColor]]; | |
1222 | ++ // [self setOpaque: YES]; | |
1223 | ++ [self setViewsNeedDisplay: NO]; | |
1224 | ++ [self setTitle: @"gVIM on Macintosh"]; | |
1225 | ++ [self setResizeIncrements: NSMakeSize(gui.char_width, gui.char_height)]; | |
1226 | ++ [self setDelegate: gui_mac.app_delegate]; | |
1227 | ++ | |
1228 | ++ [self _setContentHasShadow: NO]; | |
1229 | ++ [self setOpaque: NO]; | |
1230 | ++ | |
1231 | ++ textView = nil; | |
1232 | ++ | |
1233 | ++ VIMContentView *contentView = [[VIMContentView alloc] initWithFrame: contentRect]; | |
1234 | ++ [self setContentView: contentView]; | |
1235 | ++ [contentView release]; | |
1236 | ++ | |
1237 | ++ if ([self respondsToSelector: @selector(setBottomCornerRounded:)]) | |
1238 | ++ [self setBottomCornerRounded: NO]; | |
1239 | ++ | |
1240 | ++ [self makeFirstResponder: textView]; | |
1241 | ++ } | |
1242 | ++ | |
1243 | ++ return self; | |
1244 | ++} | |
1245 | ++ | |
1246 | ++- (VIMTextView *) textView | |
1247 | ++{ | |
1248 | ++ return textView; | |
1249 | ++} | |
1250 | ++ | |
1251 | ++- (void) setTextView: (VIMTextView *) view | |
1252 | ++{ | |
1253 | ++ if (textView) | |
1254 | ++ [textView removeFromSuperview]; | |
1255 | ++ | |
1256 | ++ textView = view; | |
1257 | ++ [[self contentView] addSubview: textView]; | |
1258 | ++ // [textView setHidden: YES]; | |
1259 | ++} | |
1260 | ++ | |
1261 | ++@end | |
1262 | ++ | |
1263 | ++void gui_mch_set_foreground() | |
1264 | ++{ | |
1265 | ++ // gui_mac_msg(MSG_DEBUG, @"gui_mch_set_foreground"); | |
1266 | ++ [gui_mac.current_window orderFront: nil]; | |
1267 | ++} | |
1268 | ++ | |
1269 | ++void gui_mch_set_winpos(int x, int y) | |
1270 | ++{ | |
1271 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_set_winpos: %d, %d", x, y); | |
1272 | ++ | |
1273 | ++ /* Get the visiable area (excluding menubar and dock) of screen */ | |
1274 | ++ NSRect visibleFrame = [[NSScreen mainScreen] visibleFrame]; | |
1275 | ++ NSPoint topLeft = NSMakePoint(x + visibleFrame.origin.x, | |
1276 | ++ visibleFrame.origin.y + visibleFrame.size.height - y); | |
1277 | ++ [gui_mac.current_window setFrameTopLeftPoint: topLeft]; | |
1278 | ++} | |
1279 | ++ | |
1280 | ++int gui_mch_get_winpos(int *x, int *y) | |
1281 | ++{ | |
1282 | ++ NSRect windowRect = [gui_mac.current_window frame]; | |
1283 | ++ NSRect visibleFrame = [[NSScreen mainScreen] visibleFrame]; | |
1284 | ++ | |
1285 | ++ // NSShowRect("windowRect", windowRect); | |
1286 | ++ | |
1287 | ++ float X_vim = windowRect.origin.x - visibleFrame.origin.x; | |
1288 | ++ float Y_vim = visibleFrame.origin.y + visibleFrame.size.height - | |
1289 | ++ (windowRect.origin.y + windowRect.size.height); | |
1290 | ++ | |
1291 | ++ gui_mac_msg(MSG_INFO, @"X_vim = %g - %g = %g", windowRect.origin.x, | |
1292 | ++ visibleFrame.origin.x, X_vim); | |
1293 | ++ gui_mac_msg(MSG_INFO, @"Y_vim = %g + %g - (%g + %g) = %g", visibleFrame.origin.y, | |
1294 | ++ visibleFrame.size.height, windowRect.origin.y, windowRect.size.height, | |
1295 | ++ Y_vim); | |
1296 | ++ | |
1297 | ++ if (X_vim < 0) | |
1298 | ++ X_vim = 0; | |
1299 | ++ if (X_vim > visibleFrame.size.width) | |
1300 | ++ X_vim = visibleFrame.size.width; | |
1301 | ++ | |
1302 | ++ if (Y_vim < 0) | |
1303 | ++ Y_vim = 0; | |
1304 | ++ if (Y_vim > visibleFrame.size.height) | |
1305 | ++ Y_vim = visibleFrame.size.height; | |
1306 | ++ | |
1307 | ++ *x = (int) X_vim; | |
1308 | ++ *y = (int) Y_vim; | |
1309 | ++ | |
1310 | ++ return OK; | |
1311 | ++} | |
1312 | ++ | |
1313 | ++void gui_mch_settitle(char_u *title, char_u *icon) | |
1314 | ++{ | |
1315 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_set_title: (%s, %s)", title, icon); | |
1316 | ++ | |
1317 | ++ [gui_mac.current_window setTitle: NSStringFromVim(title)]; | |
1318 | ++} | |
1319 | ++ | |
1320 | ++void gui_mch_iconify() | |
1321 | ++{ | |
1322 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_iconify"); | |
1323 | ++} | |
1324 | ++ | |
1325 | ++/* Window Handling }}} */ | |
1326 | ++ | |
1327 | ++/* Menu Handling {{{ */ | |
1328 | ++ | |
1329 | ++NSMenuItem *gui_mac_insert_menu_item(vimmenu_T *menu) | |
1330 | ++{ | |
1331 | ++ vimmenu_T *parent, *brother; | |
1332 | ++ NSMenu *parent_menu = nil; | |
1333 | ++ NSMenuItem *mac_menu_item, *item; | |
1334 | ++ int alloc = 0, index, len; | |
1335 | ++ | |
1336 | ++ brother = menu->next; | |
1337 | ++ /* My brother could be the PopUp, find my real brother */ | |
1338 | ++ while ((brother != NULL) && (! menu_is_menubar(brother->name))) | |
1339 | ++ brother = brother->next; | |
1340 | ++ | |
1341 | ++ len = STRLEN(menu->dname); | |
1342 | ++ // A menu separator must starts with a '-' and ends with a '-' | |
1343 | ++ if (len > 2 && menu->dname[0] == '-' && menu->dname[len - 1] == '-') | |
1344 | ++ mac_menu_item = [NSMenuItem separatorItem]; | |
1345 | ++ else | |
1346 | ++ { | |
1347 | ++ NSString *title = NSStringFromVim(menu->dname); | |
1348 | ++ mac_menu_item = [[NSMenuItem alloc] initWithTitle: title | |
1349 | ++ action: @selector(menuAction:) | |
1350 | ++ keyEquivalent: @""]; | |
1351 | ++ [mac_menu_item setTarget: gui_mac.app_delegate]; | |
1352 | ++ [mac_menu_item setTag: (int) menu]; | |
1353 | ++ alloc = 1; | |
1354 | ++ | |
1355 | ++ if (menu->actext != NULL) | |
1356 | ++ { | |
1357 | ++ NSString *tooltip = NSStringFromVim(menu->actext); | |
1358 | ++ | |
1359 | ++ [mac_menu_item setToolTip: tooltip]; | |
1360 | ++ } | |
1361 | ++ } | |
1362 | ++ menu->item_handle = (void *) mac_menu_item; | |
1363 | ++ | |
1364 | ++ parent = menu->parent; | |
1365 | ++ if (parent == NULL) | |
1366 | ++ { | |
1367 | ++ if (menu_is_menubar(menu->name)) | |
1368 | ++ parent_menu = [NSApp mainMenu]; | |
1369 | ++ } | |
1370 | ++ else | |
1371 | ++ parent_menu = (NSMenu *) parent->menu_handle; | |
1372 | ++ | |
1373 | ++ if (parent_menu) | |
1374 | ++ { | |
1375 | ++ /* If index == -1, means in parent menu we cannot find | |
1376 | ++ * this menu item, must be something wrong, but we still | |
1377 | ++ * need to handle this gracefully */ | |
1378 | ++ if (brother != NULL && | |
1379 | ++ (item = (NSMenuItem *) brother->item_handle) != NULL && | |
1380 | ++ (index = [parent_menu indexOfItem: item]) != -1) | |
1381 | ++ [parent_menu insertItem: mac_menu_item | |
1382 | ++ atIndex: index]; | |
1383 | ++ else | |
1384 | ++ [parent_menu addItem: mac_menu_item]; | |
1385 | ++ } else | |
1386 | ++ [mac_menu_item retain]; | |
1387 | ++ | |
1388 | ++ if (alloc) | |
1389 | ++ [mac_menu_item release]; | |
1390 | ++ | |
1391 | ++ return mac_menu_item; | |
1392 | ++} | |
1393 | ++ | |
1394 | ++void gui_mch_add_menu(vimmenu_T *menu, int idx) | |
1395 | ++{ | |
1396 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_add_menu: %s, %d", menu->dname, idx); | |
1397 | ++ | |
1398 | ++ NSString *title = NSStringFromVim(menu->dname); | |
1399 | ++ NSMenu *mac_menu = [[NSMenu alloc] initWithTitle: title]; | |
1400 | ++ NSMenuItem *mac_menu_item = gui_mac_insert_menu_item(menu); | |
1401 | ++ | |
1402 | ++ [mac_menu_item setSubmenu: mac_menu]; | |
1403 | ++ menu->menu_handle = (void *) mac_menu; | |
1404 | ++ | |
1405 | ++ [mac_menu release]; | |
1406 | ++} | |
1407 | ++ | |
1408 | ++void gui_mch_add_menu_item(vimmenu_T *menu, int idx) | |
1409 | ++{ | |
1410 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_add_menu_item: %s, %d", menu->dname, idx); | |
1411 | ++ | |
1412 | ++ gui_mac_insert_menu_item(menu); | |
1413 | ++} | |
1414 | ++ | |
1415 | ++void gui_mch_destroy_menu(vimmenu_T *menu) | |
1416 | ++{ | |
1417 | ++ NSMenu *parent_menu = nil; | |
1418 | ++ | |
1419 | ++ if (menu == NULL) | |
1420 | ++ return; | |
1421 | ++ | |
1422 | ++ if (menu->parent == NULL) | |
1423 | ++ { | |
1424 | ++ if (menu_is_menubar(menu->name)) | |
1425 | ++ parent_menu = [NSApp mainMenu]; | |
1426 | ++ else | |
1427 | ++ [(NSMenu *) menu->menu_handle release]; | |
1428 | ++ } | |
1429 | ++ else | |
1430 | ++ parent_menu = (NSMenu *) menu->parent->menu_handle; | |
1431 | ++ | |
1432 | ++ if (parent_menu) | |
1433 | ++ [parent_menu removeItem: (NSMenuItem *) menu->item_handle]; | |
1434 | ++ | |
1435 | ++ menu->item_handle = NULL; | |
1436 | ++} | |
1437 | ++ | |
1438 | ++void gui_mch_draw_menubar() | |
1439 | ++{ | |
1440 | ++} | |
1441 | ++ | |
1442 | ++void gui_mch_menu_grey(vimmenu_T *menu, int grey) | |
1443 | ++{ | |
1444 | ++ NSMenuItem *item; | |
1445 | ++ | |
1446 | ++ if (menu == NULL) | |
1447 | ++ return; | |
1448 | ++ | |
1449 | ++ item = (NSMenuItem *) menu->item_handle; | |
1450 | ++ [item setEnabled: grey ? NO : YES]; | |
1451 | ++} | |
1452 | ++ | |
1453 | ++void gui_mch_menu_hidden(vimmenu_T *menu, int hidden) | |
1454 | ++{ | |
1455 | ++ /* There's no hidden mode on MacOS */ | |
1456 | ++ gui_mch_menu_grey(menu, hidden); | |
1457 | ++} | |
1458 | ++ | |
1459 | ++void gui_mch_show_popupmenu(vimmenu_T *menu) | |
1460 | ++{ | |
1461 | ++ NSMenu *mac_menu = (NSMenu *) menu->menu_handle; | |
1462 | ++ NSEvent *event = gui_mac.last_mouse_down_event; | |
1463 | ++ | |
1464 | ++ gui_update_cursor(TRUE, TRUE); | |
1465 | ++ gui_mac_redraw(); | |
1466 | ++ | |
1467 | ++ [NSMenu popUpContextMenu: mac_menu | |
1468 | ++ withEvent: event | |
1469 | ++ forView: currentView]; | |
1470 | ++} | |
1471 | ++ | |
1472 | ++void gui_make_popup(char_u *path_name, int mouse_pos) | |
1473 | ++{ | |
1474 | ++ vimmenu_T *menu = gui_find_menu(path_name); | |
1475 | ++ | |
1476 | ++ if (menu == NULL) | |
1477 | ++ return; | |
1478 | ++ | |
1479 | ++ NSMenu *mac_menu = (NSMenu *) menu->menu_handle; | |
1480 | ++ NSEvent *event; | |
1481 | ++ NSPoint point; | |
1482 | ++ | |
1483 | ++ if (mouse_pos) | |
1484 | ++ point = [gui_mac.current_window convertScreenToBase: [NSEvent mouseLocation]]; | |
1485 | ++ else | |
1486 | ++ { | |
1487 | ++ int row = curwin->w_wrow; | |
1488 | ++ int col = curwin->w_wcol; | |
1489 | ++ | |
1490 | ++ point = NSMakePoint(FILL_X(col), FILL_Y(row)); | |
1491 | ++ point = [currentView convertPoint: point toView: nil]; | |
1492 | ++ } | |
1493 | ++ | |
1494 | ++ event = [NSEvent mouseEventWithType: NSRightMouseDown | |
1495 | ++ location: point | |
1496 | ++ modifierFlags: 0 | |
1497 | ++ timestamp: 0 | |
1498 | ++ windowNumber: [gui_mac.current_window windowNumber] | |
1499 | ++ context: nil | |
1500 | ++ eventNumber: 0 | |
1501 | ++ clickCount: 0 | |
1502 | ++ pressure: 1.0]; | |
1503 | ++ | |
1504 | ++ [NSMenu popUpContextMenu: mac_menu | |
1505 | ++ withEvent: event | |
1506 | ++ forView: currentView]; | |
1507 | ++} | |
1508 | ++ | |
1509 | ++void gui_mch_enable_menu(int flag) | |
1510 | ++{ | |
1511 | ++ /* menu is always active */ | |
1512 | ++} | |
1513 | ++ | |
1514 | ++void gui_mch_set_menu_pos(int x, int y, int w, int h) | |
1515 | ++{ | |
1516 | ++ /* menu position is fixed, always at the top */ | |
1517 | ++} | |
1518 | ++ | |
1519 | ++/* Menu Handling }}} */ | |
1520 | ++ | |
1521 | ++/* Dialog related {{{ */ | |
1522 | ++ | |
1523 | ++char_u *gui_mch_browse( | |
1524 | ++ int saving, | |
1525 | ++ char_u *title, | |
1526 | ++ char_u *dflt, | |
1527 | ++ char_u *ext, | |
1528 | ++ char_u *initdir, | |
1529 | ++ char_u *filter) | |
1530 | ++{ | |
1531 | ++ NSString *dir = nil, *file = nil; | |
1532 | ++ | |
1533 | ++ if (initdir != NULL) | |
1534 | ++ dir = NSStringFromVim(initdir); | |
1535 | ++ | |
1536 | ++ if (dflt != NULL) | |
1537 | ++ file = NSStringFromVim(dflt); | |
1538 | ++ | |
1539 | ++ gui_mac.selected_file = nil; | |
1540 | ++ if (saving) | |
1541 | ++ { | |
1542 | ++ NSSavePanel *panel = [NSSavePanel savePanel]; | |
1543 | ++ | |
1544 | ++ [panel setTitle: NSStringFromVim(title)]; | |
1545 | ++ [panel beginSheetForDirectory: dir | |
1546 | ++ file: file | |
1547 | ++ modalForWindow: gui_mac.current_window | |
1548 | ++ modalDelegate: gui_mac.app_delegate | |
1549 | ++ didEndSelector: @selector(panelDidEnd:code:context:) | |
1550 | ++ contextInfo: NULL]; | |
1551 | ++ } else | |
1552 | ++ { | |
1553 | ++ NSOpenPanel *panel = [NSOpenPanel openPanel]; | |
1554 | ++ | |
1555 | ++ [panel setTitle: NSStringFromVim(title)]; | |
1556 | ++ [panel setAllowsMultipleSelection: NO]; | |
1557 | ++ | |
1558 | ++ [panel beginSheetForDirectory: dir | |
1559 | ++ file: file | |
1560 | ++ types: nil | |
1561 | ++ modalForWindow: gui_mac.current_window | |
1562 | ++ modalDelegate: gui_mac.app_delegate | |
1563 | ++ didEndSelector: @selector(panelDidEnd:code:context:) | |
1564 | ++ contextInfo: NULL]; | |
1565 | ++ } | |
1566 | ++ | |
1567 | ++ [NSApp run]; | |
1568 | ++ [gui_mac.current_window makeKeyAndOrderFront: nil]; | |
1569 | ++ | |
1570 | ++ if (! gui_mac.selected_file) | |
1571 | ++ return NULL; | |
1572 | ++ | |
1573 | ++ char_u *s = vim_strsave((char_u *) [gui_mac.selected_file fileSystemRepresentation]); | |
1574 | ++ [gui_mac.selected_file release]; | |
1575 | ++ gui_mac.selected_file = nil; | |
1576 | ++ | |
1577 | ++ return s; | |
1578 | ++} | |
1579 | ++ | |
1580 | ++int gui_mch_dialog( | |
1581 | ++ int type, | |
1582 | ++ char_u *title, | |
1583 | ++ char_u *message, | |
1584 | ++ char_u *buttons, | |
1585 | ++ int dfltbutton, | |
1586 | ++ char_u *textfield) | |
1587 | ++{ | |
1588 | ++ gui_mac_redraw(); | |
1589 | ++ | |
1590 | ++ VIMAlert *alert = [[VIMAlert alloc] init]; | |
1591 | ++ char_u *p, button_title[VIM_MAX_BUTTON_TITLE]; | |
1592 | ++ int len; | |
1593 | ++ NSString *textFieldString = @"", *messageString; | |
1594 | ++ | |
1595 | ++ if (textfield) | |
1596 | ++ { | |
1597 | ++ if (textfield[0] != '\0') | |
1598 | ++ textFieldString = NSStringFromVim(textfield); | |
1599 | ++ | |
1600 | ++ [alert setTextFieldString: textFieldString]; | |
1601 | ++ } | |
1602 | ++ | |
1603 | ++ [alert setAlertStyle: NSAlertStyleFromVim(type)]; | |
1604 | ++ | |
1605 | ++ if (title) | |
1606 | ++ [alert setMessageText: NSStringFromVim(title)]; | |
1607 | ++ | |
1608 | ++ if (message) | |
1609 | ++ { | |
1610 | ++ messageString = NSStringFromVim(message); | |
1611 | ++ | |
1612 | ++ if (! title) | |
1613 | ++ { | |
1614 | ++ // HACK! If there is a '\n\n' or '\n' sequence in the message, then | |
1615 | ++ // make the part up to there into the title. We only do this | |
1616 | ++ // because Vim has lots of dialogs without a title and they look | |
1617 | ++ // ugly that way. | |
1618 | ++ // TODO: Fix the actual dialog texts. | |
1619 | ++ NSRange eolRange = [messageString rangeOfString: @"\n\n"]; | |
1620 | ++ if (eolRange.location == NSNotFound) | |
1621 | ++ eolRange = [messageString rangeOfString: @"\n"]; | |
1622 | ++ | |
1623 | ++ if (eolRange.location != NSNotFound) | |
1624 | ++ { | |
1625 | ++ [alert setMessageText: [messageString substringToIndex: eolRange.location]]; | |
1626 | ++ | |
1627 | ++ messageString = [messageString substringFromIndex: NSMaxRange(eolRange)]; | |
1628 | ++ } | |
1629 | ++ } | |
1630 | ++ | |
1631 | ++ [alert setInformativeText: messageString]; | |
1632 | ++ } else if (textFieldString) | |
1633 | ++ { | |
1634 | ++ // Make sure there is always room for the input text field. | |
1635 | ++ [alert setInformativeText: @""]; | |
1636 | ++ } | |
1637 | ++ | |
1638 | ++ for (p = buttons; *p != 0; p++) | |
1639 | ++ { | |
1640 | ++ len = 0; | |
1641 | ++ | |
1642 | ++ for (; *p != DLG_BUTTON_SEP && *p != '\0' && len < VIM_MAX_BUTTON_TITLE - 1; p++) | |
1643 | ++ if (*p != DLG_HOTKEY_CHAR) | |
1644 | ++ button_title[len++] = *p; | |
1645 | ++ | |
1646 | ++ button_title[len] = '\0'; | |
1647 | ++ [alert addButtonWithTitle: NSStringFromVim(button_title)]; | |
1648 | ++ | |
1649 | ++ if (*p == '\0') | |
1650 | ++ break; | |
1651 | ++ } | |
1652 | ++ | |
1653 | ++ [alert beginSheetModalForWindow: gui_mac.current_window | |
1654 | ++ modalDelegate: gui_mac.app_delegate | |
1655 | ++ didEndSelector: @selector(alertDidEnd:returnCode:contextInfo:) | |
1656 | ++ contextInfo: (void *) textfield]; | |
1657 | ++ | |
1658 | ++ /* Because vim runs it's own event loop, when it's calling gui_mch_dialog(), | |
1659 | ++ * maybe the event loop is stopped, then no one will receive and dispatch | |
1660 | ++ * events during the modal dialog opens, then button clicked event won't be | |
1661 | ++ * received, so here we must run an event loop and try to receive that event | |
1662 | ++ * inside this loop. */ | |
1663 | ++ [NSApp run]; | |
1664 | ++ [gui_mac.current_window makeKeyAndOrderFront: nil]; | |
1665 | ++ | |
1666 | ++ [alert release]; | |
1667 | ++ | |
1668 | ++ gui_mac_redraw(); | |
1669 | ++ /* The result vim expected start from 1 */ | |
1670 | ++ return gui_mac.dialog_button; | |
1671 | ++} | |
1672 | ++ | |
1673 | ++/* Dialog related }}} */ | |
1674 | ++ | |
1675 | ++/* Color related {{{ */ | |
1676 | ++ | |
1677 | ++/* Colors Macros */ | |
1678 | ++#define RGB(r,g,b) ((r) << 16) + ((g) << 8) + (b) | |
1679 | ++#define Red(c) ((c & 0x00FF0000) >> 16) | |
1680 | ++#define Green(c) ((c & 0x0000FF00) >> 8) | |
1681 | ++#define Blue(c) ((c & 0x000000FF) >> 0) | |
1682 | ++ | |
1683 | ++long_u gui_mch_get_rgb(guicolor_T pixel) | |
1684 | ++{ | |
1685 | ++ return (Red(pixel) << 16) + (Green(pixel) << 8) + Blue(pixel); | |
1686 | ++} | |
1687 | ++ | |
1688 | ++void gui_mch_new_colors() | |
1689 | ++{ | |
1690 | ++} | |
1691 | ++ | |
1692 | ++guicolor_T gui_mch_get_color(char_u *name) | |
1693 | ++{ | |
1694 | ++ typedef struct guicolor_tTable | |
1695 | ++ { | |
1696 | ++ char *name; | |
1697 | ++ guicolor_T color; | |
1698 | ++ } guicolor_tTable; | |
1699 | ++ | |
1700 | ++ /* | |
1701 | ++ * The comment at the end of each line is the source | |
1702 | ++ * (Mac, Window, Unix) and the number is the unix rgb.txt value | |
1703 | ++ */ | |
1704 | ++ static guicolor_tTable table[] = | |
1705 | ++ { | |
1706 | ++ { "Black", RGB(0x00, 0x00, 0x00) }, | |
1707 | ++ { "darkgray", RGB(0x80, 0x80, 0x80) }, /*W*/ | |
1708 | ++ { "darkgrey", RGB(0x80, 0x80, 0x80) }, /*W*/ | |
1709 | ++ { "Gray", RGB(0xC0, 0xC0, 0xC0) }, /*W*/ | |
1710 | ++ { "Grey", RGB(0xC0, 0xC0, 0xC0) }, /*W*/ | |
1711 | ++ { "lightgray", RGB(0xE0, 0xE0, 0xE0) }, /*W*/ | |
1712 | ++ { "lightgrey", RGB(0xE0, 0xE0, 0xE0) }, /*W*/ | |
1713 | ++ { "gray10", RGB(0x1A, 0x1A, 0x1A) }, /*W*/ | |
1714 | ++ { "grey10", RGB(0x1A, 0x1A, 0x1A) }, /*W*/ | |
1715 | ++ { "gray20", RGB(0x33, 0x33, 0x33) }, /*W*/ | |
1716 | ++ { "grey20", RGB(0x33, 0x33, 0x33) }, /*W*/ | |
1717 | ++ { "gray30", RGB(0x4D, 0x4D, 0x4D) }, /*W*/ | |
1718 | ++ { "grey30", RGB(0x4D, 0x4D, 0x4D) }, /*W*/ | |
1719 | ++ { "gray40", RGB(0x66, 0x66, 0x66) }, /*W*/ | |
1720 | ++ { "grey40", RGB(0x66, 0x66, 0x66) }, /*W*/ | |
1721 | ++ { "gray50", RGB(0x7F, 0x7F, 0x7F) }, /*W*/ | |
1722 | ++ { "grey50", RGB(0x7F, 0x7F, 0x7F) }, /*W*/ | |
1723 | ++ { "gray60", RGB(0x99, 0x99, 0x99) }, /*W*/ | |
1724 | ++ { "grey60", RGB(0x99, 0x99, 0x99) }, /*W*/ | |
1725 | ++ { "gray70", RGB(0xB3, 0xB3, 0xB3) }, /*W*/ | |
1726 | ++ { "grey70", RGB(0xB3, 0xB3, 0xB3) }, /*W*/ | |
1727 | ++ { "gray80", RGB(0xCC, 0xCC, 0xCC) }, /*W*/ | |
1728 | ++ { "grey80", RGB(0xCC, 0xCC, 0xCC) }, /*W*/ | |
1729 | ++ { "gray90", RGB(0xE5, 0xE5, 0xE5) }, /*W*/ | |
1730 | ++ { "grey90", RGB(0xE5, 0xE5, 0xE5) }, /*W*/ | |
1731 | ++ { "white", RGB(0xFF, 0xFF, 0xFF) }, | |
1732 | ++ { "darkred", RGB(0x80, 0x00, 0x00) }, /*W*/ | |
1733 | ++ { "red", RGB(0xDD, 0x08, 0x06) }, /*M*/ | |
1734 | ++ { "lightred", RGB(0xFF, 0xA0, 0xA0) }, /*W*/ | |
1735 | ++ { "DarkBlue", RGB(0x00, 0x00, 0x80) }, /*W*/ | |
1736 | ++ { "Blue", RGB(0x00, 0x00, 0xD4) }, /*M*/ | |
1737 | ++ { "lightblue", RGB(0xA0, 0xA0, 0xFF) }, /*W*/ | |
1738 | ++ { "DarkGreen", RGB(0x00, 0x80, 0x00) }, /*W*/ | |
1739 | ++ { "Green", RGB(0x00, 0x64, 0x11) }, /*M*/ | |
1740 | ++ { "lightgreen", RGB(0xA0, 0xFF, 0xA0) }, /*W*/ | |
1741 | ++ { "DarkCyan", RGB(0x00, 0x80, 0x80) }, /*W ?0x307D7E */ | |
1742 | ++ { "cyan", RGB(0x02, 0xAB, 0xEA) }, /*M*/ | |
1743 | ++ { "lightcyan", RGB(0xA0, 0xFF, 0xFF) }, /*W*/ | |
1744 | ++ { "darkmagenta",RGB(0x80, 0x00, 0x80) }, /*W*/ | |
1745 | ++ { "magenta", RGB(0xF2, 0x08, 0x84) }, /*M*/ | |
1746 | ++ { "lightmagenta",RGB(0xF0, 0xA0, 0xF0) }, /*W*/ | |
1747 | ++ { "brown", RGB(0x80, 0x40, 0x40) }, /*W*/ | |
1748 | ++ { "yellow", RGB(0xFC, 0xF3, 0x05) }, /*M*/ | |
1749 | ++ { "lightyellow",RGB(0xFF, 0xFF, 0xA0) }, /*M*/ | |
1750 | ++ { "darkyellow", RGB(0xBB, 0xBB, 0x00) }, /*U*/ | |
1751 | ++ { "SeaGreen", RGB(0x2E, 0x8B, 0x57) }, /*W 0x4E8975 */ | |
1752 | ++ { "orange", RGB(0xFC, 0x80, 0x00) }, /*W 0xF87A17 */ | |
1753 | ++ { "Purple", RGB(0xA0, 0x20, 0xF0) }, /*W 0x8e35e5 */ | |
1754 | ++ { "SlateBlue", RGB(0x6A, 0x5A, 0xCD) }, /*W 0x737CA1 */ | |
1755 | ++ { "Violet", RGB(0x8D, 0x38, 0xC9) }, /*U*/ | |
1756 | ++ }; | |
1757 | ++ | |
1758 | ++ int r, g, b; | |
1759 | ++ int i; | |
1760 | ++ | |
1761 | ++ if (name[0] == '#' && strlen((char *) name) == 7) | |
1762 | ++ { | |
1763 | ++ /* Name is in "#rrggbb" format */ | |
1764 | ++ r = gui_mac_hex_digit(name[1]) * 16 + gui_mac_hex_digit(name[2]); | |
1765 | ++ g = gui_mac_hex_digit(name[3]) * 16 + gui_mac_hex_digit(name[4]); | |
1766 | ++ b = gui_mac_hex_digit(name[5]) * 16 + gui_mac_hex_digit(name[6]); | |
1767 | ++ if (r < 0 || g < 0 || b < 0) | |
1768 | ++ return INVALCOLOR; | |
1769 | ++ return RGB(r, g, b); | |
1770 | ++ } | |
1771 | ++ else | |
1772 | ++ { | |
1773 | ++ if (STRICMP(name, "hilite") == 0) | |
1774 | ++ { | |
1775 | ++ float red, green, blue, alpha; | |
1776 | ++ [[NSColor highlightColor] getRed: &red | |
1777 | ++ green: &green | |
1778 | ++ blue: &blue | |
1779 | ++ alpha: &alpha]; | |
1780 | ++ return (RGB(r, g, b)); | |
1781 | ++ } | |
1782 | ++ | |
1783 | ++ /* Check if the name is one of the colors we know */ | |
1784 | ++ for (i = 0; i < sizeof(table) / sizeof(table[0]); i++) | |
1785 | ++ if (STRICMP(name, table[i].name) == 0) | |
1786 | ++ return table[i].color; | |
1787 | ++ } | |
1788 | ++ | |
1789 | ++ /* | |
1790 | ++ * Last attempt. Look in the file "$VIM/rgb.txt". | |
1791 | ++ */ | |
1792 | ++#define LINE_LEN 100 | |
1793 | ++ FILE *fd; | |
1794 | ++ char line[LINE_LEN]; | |
1795 | ++ char_u *fname; | |
1796 | ++ | |
1797 | ++ fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt"); | |
1798 | ++ if (fname == NULL) | |
1799 | ++ return INVALCOLOR; | |
1800 | ++ | |
1801 | ++ fd = fopen((char *)fname, "rt"); | |
1802 | ++ vim_free(fname); | |
1803 | ++ if (fd == NULL) | |
1804 | ++ return INVALCOLOR; | |
1805 | ++ | |
1806 | ++ while (! feof(fd)) | |
1807 | ++ { | |
1808 | ++ int len; | |
1809 | ++ int pos; | |
1810 | ++ char *color; | |
1811 | ++ | |
1812 | ++ fgets(line, LINE_LEN, fd); | |
1813 | ++ len = strlen(line); | |
1814 | ++ | |
1815 | ++ if (len <= 1 || line[len-1] != '\n') | |
1816 | ++ continue; | |
1817 | ++ | |
1818 | ++ line[len-1] = '\0'; | |
1819 | ++ | |
1820 | ++ i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos); | |
1821 | ++ if (i != 3) | |
1822 | ++ continue; | |
1823 | ++ | |
1824 | ++ color = line + pos; | |
1825 | ++ | |
1826 | ++ if (STRICMP(color, name) == 0) | |
1827 | ++ { | |
1828 | ++ fclose(fd); | |
1829 | ++ return (guicolor_T) RGB(r, g, b); | |
1830 | ++ } | |
1831 | ++ } | |
1832 | ++ | |
1833 | ++ fclose(fd); | |
1834 | ++ | |
1835 | ++ return INVALCOLOR; | |
1836 | ++} | |
1837 | ++ | |
1838 | ++void gui_mch_set_fg_color(guicolor_T color) | |
1839 | ++{ | |
1840 | ++ gui_mac.fg_color = NSColorFromGuiColor(color, 1.0); | |
1841 | ++ | |
1842 | ++ // TODO: should set for all views | |
1843 | ++ [currentView setMarkedTextAttribute: gui_mac.fg_color | |
1844 | ++ forKey: NSForegroundColorAttributeName]; | |
1845 | ++} | |
1846 | ++ | |
1847 | ++void gui_mch_set_bg_color(guicolor_T color) | |
1848 | ++{ | |
1849 | ++ gui_mac.bg_color = NSColorFromGuiColor(color, VIM_BG_ALPHA); | |
1850 | ++ | |
1851 | ++ // TODO: should set for all views | |
1852 | ++ [currentView setMarkedTextAttribute: gui_mac.bg_color | |
1853 | ++ forKey: NSBackgroundColorAttributeName]; | |
1854 | ++} | |
1855 | ++ | |
1856 | ++void gui_mch_set_sp_color(guicolor_T color) | |
1857 | ++{ | |
1858 | ++ gui_mac.sp_color = NSColorFromGuiColor(color, 1.0); | |
1859 | ++} | |
1860 | ++ | |
1861 | ++/* Color related }}} */ | |
1862 | ++ | |
1863 | ++/* Drawing related {{{ */ | |
1864 | ++ | |
1865 | ++void gui_mch_flush() | |
1866 | ++{ | |
1867 | ++ // gui_mac_msg(MSG_DEBUG, @"gui_mch_flush"); | |
1868 | ++ // gui_mac_redraw(); | |
1869 | ++} | |
1870 | ++ | |
1871 | ++static inline CGRect CGRectFromNSRect(NSRect nsRect) { return *(CGRect*)&nsRect; } | |
1872 | ++ | |
1873 | ++void gui_mch_invert_rectangle(int r, int c, int nr, int nc) | |
1874 | ++{ | |
1875 | ++ NSRect rect; | |
1876 | ++ | |
1877 | ++ gui_mac_begin_drawing(); | |
1878 | ++ | |
1879 | ++ rect = NSRectFromVim(r, c, r + nr, c + nc); | |
1880 | ++ | |
1881 | ++ CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | |
1882 | ++ CGContextSaveGState (context); | |
1883 | ++ CGContextSetBlendMode(context, kCGBlendModeDifference); | |
1884 | ++ CGContextSetRGBFillColor (context, 1.0, 1.0, 1.0, 1.0); | |
1885 | ++ CGContextFillRect (context, CGRectFromNSRect(rect)); | |
1886 | ++ CGContextRestoreGState (context); | |
1887 | ++ | |
1888 | ++ gui_mac_end_drawing();; | |
1889 | ++} | |
1890 | ++ | |
1891 | ++void gui_mch_flash(int msec) | |
1892 | ++{ | |
1893 | ++} | |
1894 | ++ | |
1895 | ++void gui_mch_clear_all() | |
1896 | ++{ | |
1897 | ++ [currentView clearAll]; | |
1898 | ++#if GUI_MAC_DELAY_OPEN | |
1899 | ++ if (! gui_mac.window_opened) | |
1900 | ++ gui_mac_open_window(); | |
1901 | ++#endif | |
1902 | ++} | |
1903 | ++ | |
1904 | ++void gui_mch_clear_block(int row1, int col1, int row2, int col2) | |
1905 | ++{ | |
1906 | ++ NSRect rect; | |
1907 | ++ | |
1908 | ++ // NSLog(@"clearBlock: (%d, %d) - (%d, %d)", row1, col1, row2, col2); | |
1909 | ++ | |
1910 | ++ gui_mch_set_bg_color(gui.back_pixel); | |
1911 | ++ | |
1912 | ++ gui_mac_begin_drawing(); | |
1913 | ++ | |
1914 | ++ rect = NSRectFromVim(row1, col1, row2, col2); | |
1915 | ++ // NSShowRect("clearBlock", rect); | |
1916 | ++ | |
1917 | ++ [gui_mac.bg_color set]; | |
1918 | ++ NSRectFill(rect); | |
1919 | ++ | |
1920 | ++ gui_mac_end_drawing(); | |
1921 | ++} | |
1922 | ++ | |
1923 | ++void gui_mch_delete_lines(int row, int num_lines) | |
1924 | ++{ | |
1925 | ++ NSRect src_rect; | |
1926 | ++ | |
1927 | ++ // NSLog(@"deleteLines: (%d, %d)", row, num_lines); | |
1928 | ++ src_rect = NSRectFromVim(row + num_lines, // row1 | |
1929 | ++ gui.scroll_region_left, // col1 | |
1930 | ++ gui.scroll_region_bot, // row2 | |
1931 | ++ gui.scroll_region_right); // col2 | |
1932 | ++ | |
1933 | ++ // NSShowRect("src_rect", src_rect); | |
1934 | ++ // move src_dest up for numlines | |
1935 | ++ gui_mac_scroll_rect(src_rect, -num_lines); | |
1936 | ++ | |
1937 | ++ gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
1938 | ++ gui.scroll_region_left, | |
1939 | ++ gui.scroll_region_bot, | |
1940 | ++ gui.scroll_region_right); | |
1941 | ++} | |
1942 | ++ | |
1943 | ++void gui_mch_insert_lines(int row, int num_lines) | |
1944 | ++{ | |
1945 | ++ NSRect src_rect; | |
1946 | ++ | |
1947 | ++ // NSLog(@"insertLines: (%d, %d)", row, num_lines); | |
1948 | ++ src_rect = NSRectFromVim(row, // row1 | |
1949 | ++ gui.scroll_region_left, // col1 | |
1950 | ++ gui.scroll_region_bot - num_lines, // row2 | |
1951 | ++ gui.scroll_region_right); // col2 | |
1952 | ++ | |
1953 | ++ // move src_dest down for num_lines | |
1954 | ++ gui_mac_scroll_rect(src_rect, num_lines); | |
1955 | ++ | |
1956 | ++ /* Update gui.cursor_row if the cursor scrolled or copied over */ | |
1957 | ++ if (gui.cursor_row >= gui.row | |
1958 | ++ && gui.cursor_col >= gui.scroll_region_left | |
1959 | ++ && gui.cursor_col <= gui.scroll_region_right) | |
1960 | ++ { | |
1961 | ++ if (gui.cursor_row <= gui.scroll_region_bot - num_lines) | |
1962 | ++ gui.cursor_row += num_lines; | |
1963 | ++ else if (gui.cursor_row <= gui.scroll_region_bot) | |
1964 | ++ gui.cursor_is_valid = FALSE; | |
1965 | ++ } | |
1966 | ++ | |
1967 | ++ gui_clear_block(row, gui.scroll_region_left, | |
1968 | ++ row + num_lines - 1, | |
1969 | ++ gui.scroll_region_right); | |
1970 | ++} | |
1971 | ++ | |
1972 | ++void gui_mch_draw_hollow_cursor(guicolor_T color) | |
1973 | ++{ | |
1974 | ++} | |
1975 | ++ | |
1976 | ++void gui_mch_draw_part_cursor(int w, int h, guicolor_T color) | |
1977 | ++{ | |
1978 | ++ NSRect rect; | |
1979 | ++ int left; | |
1980 | ++ | |
1981 | ++#ifdef FEAT_RIGHTLEFT | |
1982 | ++ /* vertical line should be on the right of current point */ | |
1983 | ++ if (CURSOR_BAR_RIGHT) | |
1984 | ++ left = FILL_X(gui.col + 1) - w; | |
1985 | ++ else | |
1986 | ++#endif | |
1987 | ++ left = FILL_X(gui.col); | |
1988 | ++ | |
1989 | ++ rect = NSMakeRect(left, FF_Y(gui.row + 2) + h, w, h); | |
1990 | ++ | |
1991 | ++ gui_mac_begin_drawing(); | |
1992 | ++ [NSColorFromGuiColor(color, 1.0) set]; | |
1993 | ++ // gui_mac_msg(MSG_DEBUG, @"rect = %g %g %g %g", | |
1994 | ++ // rect.origin.x, rect.origin.y, | |
1995 | ++ // rect.size.width, rect.size.height); | |
1996 | ++ [NSBezierPath fillRect: rect]; | |
1997 | ++ gui_mac_end_drawing(); | |
1998 | ++} | |
1999 | ++ | |
2000 | ++void print_draw_flags(int flags) | |
2001 | ++{ | |
2002 | ++ if (flags & DRAW_BOLD) | |
2003 | ++ fprintf(stderr, "bold, "); | |
2004 | ++ | |
2005 | ++ if (flags & DRAW_ITALIC) | |
2006 | ++ fprintf(stderr, "italic, "); | |
2007 | ++ | |
2008 | ++ if (flags & DRAW_UNDERL) | |
2009 | ++ fprintf(stderr, "underline"); | |
2010 | ++ | |
2011 | ++ if (flags & DRAW_UNDERC) | |
2012 | ++ fprintf(stderr, "undercurl"); | |
2013 | ++ | |
2014 | ++ if (flags && ! (flags & DRAW_TRANSP)) | |
2015 | ++ fprintf(stderr, "\n"); | |
2016 | ++} | |
2017 | ++ | |
2018 | ++void gui_mac_draw_ct_line(CGContextRef context, CTLineRef line, | |
2019 | ++ NSPoint origin, int row); | |
2020 | ++ | |
2021 | ++void gui_mch_draw_string(int row, int col, char_u *s, int len, int flags) | |
2022 | ++{ | |
2023 | ++ // gui_mac_msg(MSG_DEBUG, @"gui_mch_draw_string: %d, %d, %d", row, col, len); | |
2024 | ++ CTLineRef line; | |
2025 | ++ CFStringRef string; | |
2026 | ++ CFDictionaryRef attributes; | |
2027 | ++ CFAttributedStringRef attrString; | |
2028 | ++ CTFontRef font = (CTFontRef) gui_mac.current_font; | |
2029 | ++ | |
2030 | ++ CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName }; | |
2031 | ++ CFTypeRef values[] = { font, gui_mac.fg_color }; | |
2032 | ++ | |
2033 | ++ // Create a CFString from the original UTF-8 string 's' | |
2034 | ++ string = CFStringCreateWithBytes(kCFAllocatorDefault, | |
2035 | ++ s, len, | |
2036 | ++ kCFStringEncodingUTF8, | |
2037 | ++ false); | |
2038 | ++ | |
2039 | ++ // Create the attribute for Core Text layout | |
2040 | ++ attributes = CFDictionaryCreate(kCFAllocatorDefault, | |
2041 | ++ (const void **) &keys, | |
2042 | ++ (const void **) &values, | |
2043 | ++ sizeof(keys) / sizeof(keys[0]), | |
2044 | ++ &kCFTypeDictionaryKeyCallBacks, | |
2045 | ++ &kCFTypeDictionaryValueCallBacks); | |
2046 | ++ | |
2047 | ++ attrString = CFAttributedStringCreate(kCFAllocatorDefault, | |
2048 | ++ string, | |
2049 | ++ attributes); | |
2050 | ++ CFRelease(string); | |
2051 | ++ CFRelease(attributes); | |
2052 | ++ | |
2053 | ++ line = CTLineCreateWithAttributedString(attrString); | |
2054 | ++ if (! line) | |
2055 | ++ return; | |
2056 | ++ | |
2057 | ++ NSRect rect = NSMakeRect(FILL_X(col), FF_Y(row + 1), | |
2058 | ++ gui.char_width * len, gui.char_height); | |
2059 | ++ if (has_mbyte) | |
2060 | ++ { | |
2061 | ++ int cell_len = 0; | |
2062 | ++ int n; | |
2063 | ++ | |
2064 | ++ /* Compute the length in display cells. */ | |
2065 | ++ for (n = 0; n < len; n += MB_BYTE2LEN(s[n])) | |
2066 | ++ cell_len += (*mb_ptr2cells)(s + n); | |
2067 | ++ | |
2068 | ++ rect.size.width = gui.char_width * cell_len; | |
2069 | ++ } | |
2070 | ++ | |
2071 | ++ gui_mac_begin_drawing(); | |
2072 | ++ | |
2073 | ++ CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; | |
2074 | ++ CGAffineTransform transform = CGAffineTransformIdentity; | |
2075 | ++ | |
2076 | ++ /* NOTE: Since we already set 'gui.ital_font' and 'gui.boldital_font', | |
2077 | ++ * then if gui.c really called us with DRAW_ITALIC flags, it means | |
2078 | ++ * there is no italic font available, we must faking the italic by | |
2079 | ++ * slant the upright (norm_font) to the right in a small angle, that's | |
2080 | ++ * what we are doing in the next line. | |
2081 | ++ * | |
2082 | ++ * However, things get complicated when a character is slanted, it | |
2083 | ++ * may (almost sure will) expand to the space on the right side of | |
2084 | ++ * that character. There is no problem when a whole bunch of chars | |
2085 | ++ * are drawn with this flag, but if the next call still ask us to | |
2086 | ++ * draw on the same line, following the slanted texts, the new part | |
2087 | ++ * will overwrite some part of the slanted characters we've drawn | |
2088 | ++ * before, it's ugly, but I haven't found a better solution. */ | |
2089 | ++ transform.c = (flags & DRAW_ITALIC) ? Fix2X(kATSItalicQDSkew) : 0.0; | |
2090 | ++ | |
2091 | ++ CGContextSetTextMatrix(context, transform); | |
2092 | ++ CGContextSetAllowsAntialiasing(context, p_antialias); | |
2093 | ++ | |
2094 | ++ if (! (flags & DRAW_TRANSP)) | |
2095 | ++ { | |
2096 | ++ [gui_mac.bg_color set]; | |
2097 | ++ NSRectFill(rect); | |
2098 | ++ } | |
2099 | ++ | |
2100 | ++ CGContextSetRGBFillColor(context, | |
2101 | ++ [gui_mac.fg_color redComponent], | |
2102 | ++ [gui_mac.fg_color greenComponent], | |
2103 | ++ [gui_mac.fg_color blueComponent], | |
2104 | ++ 1.0); | |
2105 | ++ | |
2106 | ++ NSPoint textOrigin = NSMakePoint(rect.origin.x, | |
2107 | ++ FT_Y(row) - p_linespace); | |
2108 | ++ CGContextSetTextPosition(context, textOrigin.x, textOrigin.y); | |
2109 | ++ | |
2110 | ++ gui_mac_draw_ct_line(context, line, textOrigin, row); | |
2111 | ++ | |
2112 | ++ if (flags & DRAW_UNDERL) | |
2113 | ++ { | |
2114 | ++ [gui_mac.sp_color set]; | |
2115 | ++ NSRectFill(NSMakeRect(rect.origin.x, | |
2116 | ++ rect.origin.y + VIM_UNDERLINE_OFFSET, | |
2117 | ++ rect.size.width, VIM_UNDERLINE_HEIGHT)); | |
2118 | ++ } | |
2119 | ++ | |
2120 | ++ if (flags & DRAW_UNDERC) | |
2121 | ++ { | |
2122 | ++ [gui_mac.sp_color set]; | |
2123 | ++ | |
2124 | ++ float line_end_x = rect.origin.x + rect.size.width; | |
2125 | ++ int i = 0; | |
2126 | ++ NSRect line_rect = NSMakeRect(rect.origin.x, | |
2127 | ++ rect.origin.y, | |
2128 | ++ VIM_UNDERCURL_DOT_WIDTH, | |
2129 | ++ VIM_UNDERCURL_HEIGHT); | |
2130 | ++ | |
2131 | ++ while (line_rect.origin.x < line_end_x) | |
2132 | ++ { | |
2133 | ++ if (i % 2) | |
2134 | ++ NSRectFill(line_rect); | |
2135 | ++ | |
2136 | ++ line_rect.origin.x += VIM_UNDERCURL_DOT_DISTANCE; | |
2137 | ++ i++; | |
2138 | ++ } | |
2139 | ++ } | |
2140 | ++ | |
2141 | ++ gui_mac_end_drawing(); | |
2142 | ++ | |
2143 | ++ CFRelease(line); | |
2144 | ++} | |
2145 | ++ | |
2146 | ++void gui_mac_draw_ct_line(CGContextRef context, CTLineRef line, NSPoint origin, int row) | |
2147 | ++{ | |
2148 | ++ CFArrayRef runArray = CTLineGetGlyphRuns(line); | |
2149 | ++ CFIndex runCount = CFArrayGetCount(runArray); | |
2150 | ++ CFIndex i, glyphOffset; | |
2151 | ++ CGFloat x; | |
2152 | ++ | |
2153 | ++ for (i = 0, x = origin.x, glyphOffset = 0; i < runCount; i++) | |
2154 | ++ { | |
2155 | ++ CTRunRef run = (CTRunRef) CFArrayGetValueAtIndex(runArray, i); | |
2156 | ++ CFDictionaryRef attrDict = CTRunGetAttributes(run); | |
2157 | ++ CTFontRef runFont = (CTFontRef) CFDictionaryGetValue(attrDict, | |
2158 | ++ kCTFontAttributeName); | |
2159 | ++ bool isDouble = (runFont != (CTFontRef) gui_mac.current_font); | |
2160 | ++ CFIndex len = CTRunGetGlyphCount(run); | |
2161 | ++ CGFloat advance = len * gui.char_width; | |
2162 | ++ if (isDouble) | |
2163 | ++ advance *= 2; | |
2164 | ++ | |
2165 | ++ CGContextSetTextPosition(context, x, origin.y); | |
2166 | ++ | |
2167 | ++ // NSLog(@"r%d, %d, %g, (%g, %g), run[%d] len = %d, font = %@", | |
2168 | ++ // row, isDouble, advance, x, origin.y, i, len, [runFont fontName]); | |
2169 | ++ x += advance; | |
2170 | ++ CGFontRef cgFont = CTFontCopyGraphicsFont(runFont, NULL); | |
2171 | ++ CGContextSetFont(context, cgFont); | |
2172 | ++ CGContextSetFontSize(context, CTFontGetSize(runFont)); | |
2173 | ++ | |
2174 | ++ const CGGlyph *glyphs = CTRunGetGlyphsPtr(run); | |
2175 | ++ | |
2176 | ++ CGContextShowGlyphsWithAdvances(context, glyphs, | |
2177 | ++ isDouble ? gui_mac.double_advances | |
2178 | ++ : gui_mac.single_advances, | |
2179 | ++ len); | |
2180 | ++ CFRelease(cgFont); | |
2181 | ++ } | |
2182 | ++} | |
2183 | ++ | |
2184 | ++/* Drawing related }}} */ | |
2185 | ++ | |
2186 | ++/* Clipboard related {{{ */ | |
2187 | ++ | |
2188 | ++void clip_mch_lose_selection(VimClipboard *cbd) | |
2189 | ++{ | |
2190 | ++} | |
2191 | ++ | |
2192 | ++int clip_mch_own_selection(VimClipboard *cbd) | |
2193 | ++{ | |
2194 | ++ return OK; | |
2195 | ++} | |
2196 | ++ | |
2197 | ++/* copy from system clipboard, paste to vim */ | |
2198 | ++void clip_mch_set_selection(VimClipboard *cbd) | |
2199 | ++{ | |
2200 | ++ // If the '*' register isn't already filled in, fill it in now. | |
2201 | ++ cbd->owned = TRUE; | |
2202 | ++ clip_get_selection(cbd); | |
2203 | ++ cbd->owned = FALSE; | |
2204 | ++ | |
2205 | ++ // Get the text to put on the pasteboard. | |
2206 | ++ long_u len = 0; char_u *str = 0; | |
2207 | ++ int type = clip_convert_selection(&str, &len, cbd); | |
2208 | ++ if (type < 0) | |
2209 | ++ return; | |
2210 | ++ | |
2211 | ++ NSString *string = [[NSString alloc] initWithBytes: str | |
2212 | ++ length: len | |
2213 | ++ encoding: NSUTF8StringEncoding]; | |
2214 | ++ | |
2215 | ++ NSPasteboard *pb = [NSPasteboard generalPasteboard]; | |
2216 | ++ | |
2217 | ++ [pb declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil]; | |
2218 | ++ [pb setString: string | |
2219 | ++ forType: NSStringPboardType]; | |
2220 | ++ | |
2221 | ++ [string release]; | |
2222 | ++ vim_free(str); | |
2223 | ++} | |
2224 | ++ | |
2225 | ++/* copy from vim, paste to system clipboard */ | |
2226 | ++void clip_mch_request_selection(VimClipboard *cbd) | |
2227 | ++{ | |
2228 | ++ NSPasteboard *pb = [NSPasteboard generalPasteboard]; | |
2229 | ++ NSString *type = [pb availableTypeFromArray: [NSArray arrayWithObject: NSStringPboardType]]; | |
2230 | ++ | |
2231 | ++ if (type) | |
2232 | ++ { | |
2233 | ++ NSMutableString *string = [[pb stringForType: NSStringPboardType] mutableCopy]; | |
2234 | ++ | |
2235 | ++ // Replace unrecognized end-of-line sequences with \x0a (line feed). | |
2236 | ++ NSRange range = NSMakeRange(0, [string length]); | |
2237 | ++ unsigned n = [string replaceOccurrencesOfString: @"\x0d\x0a" | |
2238 | ++ withString: @"\x0a" | |
2239 | ++ options: 0 | |
2240 | ++ range: range]; | |
2241 | ++ if (n == 0) | |
2242 | ++ n = [string replaceOccurrencesOfString: @"\x0d" | |
2243 | ++ withString: @"\x0a" | |
2244 | ++ options: 0 | |
2245 | ++ range: range]; | |
2246 | ++ | |
2247 | ++ // Scan for newline character to decide whether the string should be | |
2248 | ++ // pasted linewise or characterwise. | |
2249 | ++ int char_type = MCHAR; | |
2250 | ++ if (0 < n || NSNotFound != [string rangeOfString: @"\n"].location) | |
2251 | ++ char_type = MLINE; | |
2252 | ++ | |
2253 | ++ const char *utf8chars = [string UTF8String]; | |
2254 | ++ clip_yank_selection(char_type, (char_u*) utf8chars, strlen(utf8chars), cbd); | |
2255 | ++ } | |
2256 | ++} | |
2257 | ++ | |
2258 | ++/* Clipboard related }}} */ | |
2259 | ++ | |
2260 | ++/* Scrollbar related {{{ */ | |
2261 | ++ | |
2262 | ++const char *scrollbar_desc(scrollbar_T *sb) | |
2263 | ++{ | |
2264 | ++ switch (sb->type) | |
2265 | ++ { | |
2266 | ++ case SBAR_LEFT: | |
2267 | ++ return "LEFT"; | |
2268 | ++ | |
2269 | ++ case SBAR_RIGHT: | |
2270 | ++ return "RIGHT"; | |
2271 | ++ | |
2272 | ++ case SBAR_BOTTOM: | |
2273 | ++ return "BOTTOM"; | |
2274 | ++ | |
2275 | ++ default: | |
2276 | ++ return "NONE"; | |
2277 | ++ } | |
2278 | ++} | |
2279 | ++ | |
2280 | ++void gui_mch_create_scrollbar(scrollbar_T *sb, int orient) | |
2281 | ++{ | |
2282 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_create_scrollbar: ident = %ld, " | |
2283 | ++ "type = %s, value = %ld, size = %ld, " | |
2284 | ++ "max = %ld, top = %d, height = %d, " | |
2285 | ++ "width = %d, status_height = %d, %s", | |
2286 | ++ sb->ident, scrollbar_desc(sb), | |
2287 | ++ sb->value, sb->size, sb->max, | |
2288 | ++ sb->top, sb->height, sb->width, sb->status_height, | |
2289 | ++ orient == SBAR_HORIZ ? "H" : "V"); | |
2290 | ++ VIMScroller *scroller; | |
2291 | ++ | |
2292 | ++ scroller = [[VIMScroller alloc] initWithVimScrollbar: sb | |
2293 | ++ orientation: orient]; | |
2294 | ++ sb->scroller = (void *) scroller; | |
2295 | ++} | |
2296 | ++ | |
2297 | ++void gui_mch_destroy_scrollbar(scrollbar_T *sb) | |
2298 | ++{ | |
2299 | ++ VIMScroller *scroller = gui_mac_get_scroller(sb); | |
2300 | ++ | |
2301 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_destroy_scrollbar: %s (%ld)", | |
2302 | ++ scrollbar_desc(sb), sb->ident); | |
2303 | ++ | |
2304 | ++ sb->enabled = FALSE; | |
2305 | ++ gui_mac_update_scrollbar(sb); | |
2306 | ++ | |
2307 | ++ if (scroller != nil) | |
2308 | ++ [scroller release]; | |
2309 | ++ | |
2310 | ++ sb->scroller = NULL; | |
2311 | ++} | |
2312 | ++ | |
2313 | ++void gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) | |
2314 | ++{ | |
2315 | ++ gui_mac_msg(MSG_INFO, @"%s scrollbar: %s (%d)", | |
2316 | ++ flag == TRUE ? "enable" : "disable", scrollbar_desc(sb), | |
2317 | ++ sb->ident); | |
2318 | ++ | |
2319 | ++ sb->enabled = flag; | |
2320 | ++ gui_mac_update_scrollbar(sb); | |
2321 | ++ | |
2322 | ++ VIMScroller *scroller = gui_mac_get_scroller(sb); | |
2323 | ++ [scroller setHidden: flag == TRUE ? NO : YES]; | |
2324 | ++} | |
2325 | ++ | |
2326 | ++void gui_mch_set_scrollbar_pos( | |
2327 | ++ scrollbar_T *sb, | |
2328 | ++ int x, | |
2329 | ++ int y, | |
2330 | ++ int w, | |
2331 | ++ int h) | |
2332 | ++{ | |
2333 | ++ gui_mac_msg(MSG_INFO, @"set scrollbar pos: %s (%ld), (%d, %d, %d, %d)", | |
2334 | ++ scrollbar_desc(sb), sb->ident, x, y, w, h); | |
2335 | ++ | |
2336 | ++ gui_mac_update_scrollbar(sb); | |
2337 | ++ | |
2338 | ++ VIMScroller *scroller = gui_mac_get_scroller(sb); | |
2339 | ++ [scroller setFrame: NSMakeRect(x, y, w, h)]; | |
2340 | ++} | |
2341 | ++ | |
2342 | ++void gui_mch_set_scrollbar_thumb( | |
2343 | ++ scrollbar_T *sb, | |
2344 | ++ long val, | |
2345 | ++ long size, | |
2346 | ++ long max) | |
2347 | ++{ | |
2348 | ++ VIMScroller *scroller = (VIMScroller *) sb->scroller; | |
2349 | ++ [scroller setThumbValue: val | |
2350 | ++ size: size | |
2351 | ++ max: max]; | |
2352 | ++} | |
2353 | ++ | |
2354 | ++/* Scrollbar related }}} */ | |
2355 | ++ | |
2356 | ++/* Mouse related {{{ */ | |
2357 | ++ | |
2358 | ++void gui_mch_getmouse(int *x, int *y) | |
2359 | ++{ | |
2360 | ++ | |
2361 | ++} | |
2362 | ++ | |
2363 | ++void gui_mch_setmouse(int x, int y) | |
2364 | ++{ | |
2365 | ++} | |
2366 | ++ | |
2367 | ++/* Mouse related }}} */ | |
2368 | ++ | |
2369 | ++/* Cursor blinking stuff {{{ */ | |
2370 | ++ | |
2371 | ++enum blink_state { | |
2372 | ++ BLINK_NONE, /* not blinking at all */ | |
2373 | ++ BLINK_OFF, /* blinking, cursor is not shown */ | |
2374 | ++ BLINK_ON /* blinking, cursor is shown */ | |
2375 | ++}; | |
2376 | ++ | |
2377 | ++void gui_mch_set_blinking(long wait, long on, long off) | |
2378 | ++{ | |
2379 | ++ gui_mac.blink_wait = wait; | |
2380 | ++ gui_mac.blink_on = on; | |
2381 | ++ gui_mac.blink_off = off; | |
2382 | ++} | |
2383 | ++ | |
2384 | ++void gui_mch_stop_blink() | |
2385 | ++{ | |
2386 | ++ return; | |
2387 | ++ | |
2388 | ++ [gui_mac.blink_timer invalidate]; | |
2389 | ++ | |
2390 | ++ if (gui_mac.blink_state == BLINK_OFF) | |
2391 | ++ gui_update_cursor(TRUE, FALSE); | |
2392 | ++ | |
2393 | ++ gui_mac.blink_state = BLINK_NONE; | |
2394 | ++ gui_mac.blink_timer = nil; | |
2395 | ++} | |
2396 | ++ | |
2397 | ++void gui_mch_start_blink() | |
2398 | ++{ | |
2399 | ++ return; | |
2400 | ++ | |
2401 | ++ if (gui_mac.blink_timer != nil) | |
2402 | ++ [gui_mac.blink_timer invalidate]; | |
2403 | ++ | |
2404 | ++ if (gui_mac.blink_wait && gui_mac.blink_on && | |
2405 | ++ gui_mac.blink_off && gui.in_focus) | |
2406 | ++ { | |
2407 | ++ gui_mac.blink_timer = [NSTimer scheduledTimerWithTimeInterval: gui_mac.blink_wait / 1000.0 | |
2408 | ++ target: gui_mac.app_delegate | |
2409 | ++ selector: @selector(blinkCursorTimer:) | |
2410 | ++ userInfo: nil | |
2411 | ++ repeats: NO]; | |
2412 | ++ gui_mac.blink_state = BLINK_ON; | |
2413 | ++ gui_update_cursor(TRUE, FALSE); | |
2414 | ++ } | |
2415 | ++} | |
2416 | ++ | |
2417 | ++/* Cursor blinking stuff }}} */ | |
2418 | ++ | |
2419 | ++/* GUI tab stuff {{{ */ | |
2420 | ++ | |
2421 | ++void gui_mch_set_curtab(int nr) | |
2422 | ++{ | |
2423 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_set_curtab(%d)", nr); | |
2424 | ++} | |
2425 | ++ | |
2426 | ++void gui_mch_show_tabline(int showit) | |
2427 | ++{ | |
2428 | ++ VIMContentView *view; | |
2429 | ++ | |
2430 | ++ gui_mac.showing_tabline = showit; | |
2431 | ++ | |
2432 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_show_tabline: %s", showit ? "YES" : "NO"); | |
2433 | ++ view = [gui_mac.current_window contentView]; | |
2434 | ++ [[view tabBarControl] setHidden: (showit ? NO : YES)]; | |
2435 | ++ // NSShowRect("tabBarControl", [[view tabBarControl] frame]); | |
2436 | ++} | |
2437 | ++ | |
2438 | ++int gui_mch_showing_tabline() | |
2439 | ++{ | |
2440 | ++ return gui_mac.showing_tabline == YES; | |
2441 | ++} | |
2442 | ++ | |
2443 | ++void gui_mch_update_tabline() | |
2444 | ++{ | |
2445 | ++ tabpage_T *tp; | |
2446 | ++ VIMContentView *view = [gui_mac.current_window contentView]; | |
2447 | ++ NSTabView *tabView = [view tabView]; | |
2448 | ++ NSArray *tabViewItems = [[view tabBarControl] representedTabViewItems]; | |
2449 | ++ int i, j, originalTabCount = [tabViewItems count]; | |
2450 | ++ NSTabViewItem *item; | |
2451 | ++ int currentTabIndex = tabpage_index(curtab) - 1; | |
2452 | ++ | |
2453 | ++ gui_mac_msg(MSG_INFO, @"gui_mch_update_tabline: cti = %d, otc = %d", | |
2454 | ++ currentTabIndex, originalTabCount); | |
2455 | ++ | |
2456 | ++ for (tp = first_tabpage, i = 0; | |
2457 | ++ tp != NULL; | |
2458 | ++ tp = tp->tp_next, i++) | |
2459 | ++ { | |
2460 | ++ // This function puts the label of the tab in the global 'NameBuff'. | |
2461 | ++ get_tabline_label(tp, FALSE); | |
2462 | ++ char_u *s = NameBuff; | |
2463 | ++ int len = STRLEN(s); | |
2464 | ++ if (len <= 0) continue; | |
2465 | ++ | |
2466 | ++ s = CONVERT_TO_UTF8(s); | |
2467 | ++ // gui_mac_msg(MSG_DEBUG, @"label (%d): %s", i, s); | |
2468 | ++ if (i >= originalTabCount) | |
2469 | ++ { | |
2470 | ++ gui_mac_begin_tab_action(); | |
2471 | ++ item = [view addNewTabViewItem]; | |
2472 | ++ gui_mac_end_tab_action(); | |
2473 | ++ } | |
2474 | ++ else | |
2475 | ++ item = [tabViewItems objectAtIndex: i]; | |
2476 | ++ | |
2477 | ++ [item setLabel: NSStringFromVim(s)]; | |
2478 | ++ | |
2479 | ++ CONVERT_TO_UTF8_FREE(s); | |
2480 | ++ } | |
2481 | ++ | |
2482 | ++ // gui_mac_msg(MSG_DEBUG, @"total tab count = %d", i); | |
2483 | ++ for (j = originalTabCount - 1; j >= i; j--) | |
2484 | ++ { | |
2485 | ++ NSTabViewItem *item = [tabViewItems objectAtIndex: i]; | |
2486 | ++ [tabView removeTabViewItem: item]; | |
2487 | ++ } | |
2488 | ++ | |
2489 | ++ tabViewItems = [[view tabBarControl] representedTabViewItems]; | |
2490 | ++ if (currentTabIndex < [tabViewItems count]) | |
2491 | ++ { | |
2492 | ++ item = [tabViewItems objectAtIndex: currentTabIndex]; | |
2493 | ++ | |
2494 | ++ gui_mac_begin_tab_action(); | |
2495 | ++ [tabView selectTabViewItem: item]; | |
2496 | ++ gui_mac_end_tab_action(); | |
2497 | ++ } | |
2498 | ++} | |
2499 | ++ | |
2500 | ++/* GUI tab stuff }}} */ | |
2501 | ++ | |
2502 | ++/* GUI popup menu stuff {{{ */ | |
2503 | ++ | |
2504 | ++void gui_mch_pum_display(pumitem_T *array, int size, int selected) | |
2505 | ++{ | |
2506 | ++ | |
2507 | ++} | |
2508 | ++ | |
2509 | ++/* GUI popup menu stuff }}} */ | |
2510 | ++ | |
2511 | ++/* Private Functions {{{1 */ | |
2512 | ++ | |
2513 | ++int gui_mac_hex_digit(int c) | |
2514 | ++{ | |
2515 | ++ if (isdigit(c)) | |
2516 | ++ return c - '0'; | |
2517 | ++ | |
2518 | ++ c = TOLOWER_ASC(c); | |
2519 | ++ | |
2520 | ++ if (c >= 'a' && c <= 'f') | |
2521 | ++ return c - 'a' + 10; | |
2522 | ++ | |
2523 | ++ return -1000; | |
2524 | ++} | |
2525 | ++ | |
2526 | ++NSAlertStyle NSAlertStyleFromVim(int type) | |
2527 | ++{ | |
2528 | ++ switch (type) | |
2529 | ++ { | |
2530 | ++ case VIM_GENERIC: | |
2531 | ++ case VIM_INFO: | |
2532 | ++ case VIM_QUESTION: | |
2533 | ++ return NSInformationalAlertStyle; | |
2534 | ++ | |
2535 | ++ case VIM_WARNING: | |
2536 | ++ return NSWarningAlertStyle; | |
2537 | ++ | |
2538 | ++ case VIM_ERROR: | |
2539 | ++ return NSCriticalAlertStyle; | |
2540 | ++ | |
2541 | ++ default: | |
2542 | ++ return NSInformationalAlertStyle; | |
2543 | ++ } | |
2544 | ++} | |
2545 | ++ | |
2546 | ++NSColor *NSColorFromGuiColor(guicolor_T color, float alpha) | |
2547 | ++{ | |
2548 | ++ float red, green, blue; | |
2549 | ++ | |
2550 | ++ red = (float) Red(color) / (float) 0xFF; | |
2551 | ++ green = (float) Green(color) / (float) 0xFF; | |
2552 | ++ blue = (float) Blue(color) / (float) 0xFF; | |
2553 | ++ | |
2554 | ++ return [NSColor colorWithDeviceRed: red | |
2555 | ++ green: green | |
2556 | ++ blue: blue | |
2557 | ++ alpha: alpha]; | |
2558 | ++} | |
2559 | ++ | |
2560 | ++NSRect NSRectFromVim(int row1, int col1, int row2, int col2) | |
2561 | ++{ | |
2562 | ++ return NSMakeRect(FILL_X(col1), FF_Y(row2 + 1), | |
2563 | ++ FILL_X(col2 + 1) - FILL_X(col1), | |
2564 | ++ FILL_Y(row2 + 1) - FILL_Y(row1)); | |
2565 | ++} | |
2566 | ++ | |
2567 | ++void gui_mac_msg(int level, NSString *fmt, ...) | |
2568 | ++{ | |
2569 | ++#if GUI_MAC_DEBUG | |
2570 | ++ if (level >= gui_mac.debug_level) | |
2571 | ++ { | |
2572 | ++ va_list ap; | |
2573 | ++ | |
2574 | ++ va_start(ap, fmt); | |
2575 | ++ NSLogv(fmt, ap); | |
2576 | ++ va_end(ap); | |
2577 | ++ } | |
2578 | ++#endif | |
2579 | ++} | |
2580 | ++ | |
2581 | ++/* Application Related Utilities {{{2 */ | |
2582 | ++ | |
2583 | ++/* Force it to update instantly */ | |
2584 | ++void gui_mac_update() | |
2585 | ++{ | |
2586 | ++ gui_mac_send_dummy_event(); | |
2587 | ++ gui_mac_stop_app(YES); | |
2588 | ++} | |
2589 | ++ | |
2590 | ++void gui_mac_send_dummy_event() | |
2591 | ++{ | |
2592 | ++ NSEvent *event; | |
2593 | ++ event = [NSEvent otherEventWithType: NSApplicationDefined | |
2594 | ++ location: NSZeroPoint | |
2595 | ++ modifierFlags: 0 | |
2596 | ++ timestamp: 0 | |
2597 | ++ windowNumber: 0 | |
2598 | ++ context: nil | |
2599 | ++ subtype: 0 | |
2600 | ++ data1: 0 | |
2601 | ++ data2: 0]; | |
2602 | ++ [NSApp postEvent: event atStart: YES]; | |
2603 | ++} | |
2604 | ++ | |
2605 | ++unsigned int has_fname(char_u *fname) | |
2606 | ++{ | |
2607 | ++ int i; | |
2608 | ++ | |
2609 | ++ for (i = 0; i < global_alist.al_ga.ga_len; i++) | |
2610 | ++ if (STRCMP(AARGLIST(&global_alist)[i].ae_fname, fname) == 0) | |
2611 | ++ return 1; | |
2612 | ++ return 0; | |
2613 | ++} | |
2614 | ++ | |
2615 | ++@implementation VimAppController | |
2616 | ++ | |
2617 | ++- (void) application:(NSApplication *)sender openFiles:(NSArray *)filenames | |
2618 | ++{ | |
2619 | ++ char_u **fnames; | |
2620 | ++ unsigned int i, count; | |
2621 | ++ | |
2622 | ++ count = [filenames count]; | |
2623 | ++ fnames = (char_u **) alloc(count * sizeof(char_u *)); | |
2624 | ++ | |
2625 | ++ for (i = 0; i < count; i++) | |
2626 | ++ { | |
2627 | ++ NSString *filename = [filenames objectAtIndex: i]; | |
2628 | ++ | |
2629 | ++ fnames[i] = vim_strsave((char_u *) [filename fileSystemRepresentation]); | |
2630 | ++ } | |
2631 | ++ | |
2632 | ++ shorten_filenames(fnames, count); | |
2633 | ++ | |
2634 | ++ /* if vim is starting, we can not use handle_drop, instead, we | |
2635 | ++ * put files into global alist, vim will open those files later | |
2636 | ++ * at appropriate time */ | |
2637 | ++ if (starting > 0) | |
2638 | ++ { | |
2639 | ++ int i; | |
2640 | ++ char_u *p; | |
2641 | ++ | |
2642 | ++ /* these are the initial files dropped on the Vim icon */ | |
2643 | ++ for (i = 0; i < count; i++) | |
2644 | ++ { | |
2645 | ++ if (has_fname(fnames[i])) | |
2646 | ++ continue; | |
2647 | ++ | |
2648 | ++ if (ga_grow(&global_alist.al_ga, 1) == FAIL || | |
2649 | ++ (p = vim_strsave(fnames[i])) == NULL) | |
2650 | ++ mch_exit(2); | |
2651 | ++ else | |
2652 | ++ alist_add(&global_alist, p, 2); | |
2653 | ++ } | |
2654 | ++ | |
2655 | ++ /* Change directory to the location of the first file. */ | |
2656 | ++ if (GARGCOUNT > 0 && vim_chdirfile(alist_name(&GARGLIST[0])) == OK) | |
2657 | ++ shorten_fnames(TRUE); | |
2658 | ++ | |
2659 | ++ goto finish; | |
2660 | ++ } | |
2661 | ++ | |
2662 | ++ char_u *p = vim_strsave(fnames[0]); | |
2663 | ++ handle_drop(count, fnames, FALSE); | |
2664 | ++ | |
2665 | ++ if (p != NULL) | |
2666 | ++ { | |
2667 | ++ if (mch_isdir(p)) | |
2668 | ++ { | |
2669 | ++ if (mch_chdir((char *)p) == 0) | |
2670 | ++ shorten_fnames(TRUE); | |
2671 | ++ } | |
2672 | ++ else if (vim_chdirfile(p) == OK) | |
2673 | ++ shorten_fnames(TRUE); | |
2674 | ++ | |
2675 | ++ vim_free(p); | |
2676 | ++ } | |
2677 | ++ | |
2678 | ++ /* Update the screen display */ | |
2679 | ++ update_screen(NOT_VALID); | |
2680 | ++#ifdef FEAT_MENU | |
2681 | ++ gui_update_menus(0); | |
2682 | ++#endif | |
2683 | ++ setcursor(); | |
2684 | ++ out_flush(); | |
2685 | ++ | |
2686 | ++ gui_mac_redraw(); | |
2687 | ++ | |
2688 | ++finish: | |
2689 | ++ [NSApp replyToOpenOrPrint: NSApplicationDelegateReplySuccess]; | |
2690 | ++} | |
2691 | ++ | |
2692 | ++- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender | |
2693 | ++{ | |
2694 | ++ return YES; | |
2695 | ++} | |
2696 | ++ | |
2697 | ++- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender | |
2698 | ++{ | |
2699 | ++ int reply = NSTerminateNow; | |
2700 | ++ BOOL modifiedBuffers = NO; | |
2701 | ++ | |
2702 | ++ buf_T *buf; | |
2703 | ++ for (buf = firstbuf; buf != NULL; buf = buf->b_next) | |
2704 | ++ { | |
2705 | ++ if (bufIsChanged(buf)) | |
2706 | ++ { | |
2707 | ++ modifiedBuffers = YES; | |
2708 | ++ break; | |
2709 | ++ } | |
2710 | ++ } | |
2711 | ++ | |
2712 | ++ if (modifiedBuffers) { | |
2713 | ++ NSAlert *alert = [[NSAlert alloc] init]; | |
2714 | ++ [alert addButtonWithTitle: @"Quit"]; | |
2715 | ++ [alert addButtonWithTitle: @"Cancel"]; | |
2716 | ++ [alert setMessageText: @"Quit without saving?"]; | |
2717 | ++ [alert setInformativeText: @"There are modified buffers, " | |
2718 | ++ " if you quit now all changes will be lost. Quit anyway?"]; | |
2719 | ++ [alert setAlertStyle: NSWarningAlertStyle]; | |
2720 | ++ | |
2721 | ++ [alert beginSheetModalForWindow: gui_mac.current_window | |
2722 | ++ modalDelegate: gui_mac.app_delegate | |
2723 | ++ didEndSelector: @selector(alertDidEnd:returnCode:contextInfo:) | |
2724 | ++ contextInfo: NULL]; | |
2725 | ++ [NSApp run]; | |
2726 | ++ | |
2727 | ++ if (gui_mac.dialog_button != 1) { | |
2728 | ++ reply = NSTerminateCancel; | |
2729 | ++ [gui_mac.current_window makeKeyAndOrderFront: nil]; | |
2730 | ++ } | |
2731 | ++ | |
2732 | ++ [alert release]; | |
2733 | ++ } | |
2734 | ++ | |
2735 | ++ return reply; | |
2736 | ++} | |
2737 | ++ | |
2738 | ++- (void) applicationDidFinishLaunching:(NSNotification *)aNotification | |
2739 | ++{ | |
2740 | ++} | |
2741 | ++ | |
2742 | ++- (BOOL) windowShouldClose:(id)sender | |
2743 | ++{ | |
2744 | ++ if ([sender isEqual: gui_mac.current_window]) | |
2745 | ++ { | |
2746 | ++ gui_shell_closed(); | |
2747 | ++ return NO; | |
2748 | ++ } | |
2749 | ++ | |
2750 | ++ return YES; | |
2751 | ++} | |
2752 | ++ | |
2753 | ++- (void) alertDidEnd:(VIMAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo | |
2754 | ++{ | |
2755 | ++ gui_mac.dialog_button = returnCode - NSAlertFirstButtonReturn + 1; | |
2756 | ++ | |
2757 | ++ if ([alert isKindOfClass: [VIMAlert class]] && | |
2758 | ++ [alert textField] && contextInfo) | |
2759 | ++ STRCPY((char_u *) contextInfo, [[[alert textField] stringValue] UTF8String]); | |
2760 | ++ | |
2761 | ++ [NSApp stop: self]; | |
2762 | ++} | |
2763 | ++ | |
2764 | ++- (void) panelDidEnd:(NSSavePanel *)panel code:(int)code context:(void *)context | |
2765 | ++{ | |
2766 | ++ NSString *string = (code == NSOKButton) ? [panel filename] : nil; | |
2767 | ++ gui_mac.selected_file = [string copy]; | |
2768 | ++ | |
2769 | ++ [NSApp stop: self]; | |
2770 | ++} | |
2771 | ++ | |
2772 | ++- (void) initializeApplicationTimer:(NSTimer *)timer | |
2773 | ++{ | |
2774 | ++ [NSApp stop: self]; | |
2775 | ++ | |
2776 | ++ gui_mac_send_dummy_event(); | |
2777 | ++} | |
2778 | ++ | |
2779 | ++- (void) blinkCursorTimer:(NSTimer *)timer | |
2780 | ++{ | |
2781 | ++ NSTimeInterval on_time, off_time; | |
2782 | ++ | |
2783 | ++ gui_mac_msg(MSG_DEBUG, @"blinkCursorTimer: %s", | |
2784 | ++ gui_mac.blink_state == BLINK_ON ? "BLINK_ON" | |
2785 | ++ : (gui_mac.blink_state == BLINK_OFF ? "BLINK_OFF" | |
2786 | ++ : "BLINK_NONE")); | |
2787 | ++ | |
2788 | ++ [gui_mac.blink_timer invalidate]; | |
2789 | ++ if (gui_mac.blink_state == BLINK_ON) | |
2790 | ++ { | |
2791 | ++ gui_undraw_cursor(); | |
2792 | ++ gui_mac.blink_state = BLINK_OFF; | |
2793 | ++ | |
2794 | ++ off_time = gui_mac.blink_off / 1000.0; | |
2795 | ++ gui_mac.blink_timer = [NSTimer scheduledTimerWithTimeInterval: off_time | |
2796 | ++ target: gui_mac.app_delegate | |
2797 | ++ selector: @selector(blinkCursorTimer:) | |
2798 | ++ userInfo: nil | |
2799 | ++ repeats: NO]; | |
2800 | ++ } | |
2801 | ++ else if (gui_mac.blink_state == BLINK_OFF) | |
2802 | ++ { | |
2803 | ++ gui_update_cursor(TRUE, FALSE); | |
2804 | ++ gui_mac.blink_state = BLINK_ON; | |
2805 | ++ | |
2806 | ++ on_time = gui_mac.blink_on / 1000.0; | |
2807 | ++ gui_mac.blink_timer = [NSTimer scheduledTimerWithTimeInterval: on_time | |
2808 | ++ target: gui_mac.app_delegate | |
2809 | ++ selector: @selector(blinkCursorTimer:) | |
2810 | ++ userInfo: nil | |
2811 | ++ repeats: NO]; | |
2812 | ++ } | |
2813 | ++} | |
2814 | ++ | |
2815 | ++- (void) menuAction:(id)sender | |
2816 | ++{ | |
2817 | ++ NSMenuItem *item = (NSMenuItem *) sender; | |
2818 | ++ vimmenu_T *menu; | |
2819 | ++ | |
2820 | ++ /* NSMenuItem does not have a specifically | |
2821 | ++ * made "user data" to contain vimmenu_T, | |
2822 | ++ * so we have to use this trick, cast an | |
2823 | ++ * int to a pointer, hopefully in all Macs | |
2824 | ++ * they are in the same length */ | |
2825 | ++ if ((menu = (vimmenu_T *)[item tag]) == NULL) | |
2826 | ++ return; | |
2827 | ++ | |
2828 | ++ if (menu->cb != NULL) | |
2829 | ++ gui_menu_cb(menu); | |
2830 | ++ | |
2831 | ++ // gui_mac_redraw(); | |
2832 | ++ | |
2833 | ++ /* HACK: NSApp won't react directly until some event comes, | |
2834 | ++ * while clicking a menu item does not send any event */ | |
2835 | ++ gui_mac_update(); | |
2836 | ++} | |
2837 | ++ | |
2838 | ++- (void) applicationWillTerminate:(NSNotification *)aNotification | |
2839 | ++{ | |
2840 | ++ // [gui_mac.app_pool release]; | |
2841 | ++ mch_exit(0); | |
2842 | ++} | |
2843 | ++ | |
2844 | ++- (void) windowWillClose:(NSNotification *)aNotification | |
2845 | ++{ | |
2846 | ++ if ([aNotification object] != [NSFontPanel sharedFontPanel]) | |
2847 | ++ return; | |
2848 | ++ | |
2849 | ++ NSFont *selected_font = [[NSFontManager sharedFontManager] selectedFont]; | |
2850 | ++ // gui_mac_msg(MSG_DEBUG, @"font panel will close: %@", selected_font); | |
2851 | ++ | |
2852 | ++ gui_mac.selected_font = selected_font; | |
2853 | ++ [NSApp stop: self]; | |
2854 | ++} | |
2855 | ++ | |
2856 | ++- (void) windowDidResize:(NSNotification *)aNotification | |
2857 | ++{ | |
2858 | ++ NSSize size; | |
2859 | ++ int width, height; | |
2860 | ++ | |
2861 | ++ if ([aNotification object] != gui_mac.current_window) | |
2862 | ++ return; | |
2863 | ++ | |
2864 | ++ // if the textView is not allocated yet, it means initialization | |
2865 | ++ // code from vim is not executed, so we don't need to pass this | |
2866 | ++ // windowDidResize event to vim | |
2867 | ++ if (! [gui_mac.current_window textView]) | |
2868 | ++ return; | |
2869 | ++ | |
2870 | ++ size = [[gui_mac.current_window contentView] frame].size; | |
2871 | ++ width = (int) size.width; | |
2872 | ++ height = (int) size.height; | |
2873 | ++ | |
2874 | ++ // gui_mac_msg(MSG_DEBUG, @"windowDidResize: (%d, %d)", width, height); | |
2875 | ++ gui_resize_shell(width, height); | |
2876 | ++ | |
2877 | ++ gui_mac_update(); | |
2878 | ++} | |
2879 | ++ | |
2880 | ++- (void) windowDidMove:(NSNotification *)notification | |
2881 | ++{ | |
2882 | ++ NSRect frame = [gui_mac.current_window frame]; | |
2883 | ++ NSPoint topLeft = NSMakePoint(frame.origin.x, NSMaxY(frame)); | |
2884 | ++ NSString *topLeftString = NSStringFromPoint(topLeft); | |
2885 | ++ | |
2886 | ++ [[NSUserDefaults standardUserDefaults] | |
2887 | ++ setObject: topLeftString forKey: @"VIMTopLeftPoint"]; | |
2888 | ++} | |
2889 | ++ | |
2890 | ++@end | |
2891 | ++ | |
2892 | ++/* Application Related Utilities 2}}} */ | |
2893 | ++ | |
2894 | ++/* Menu Related Utilities {{{2 */ | |
2895 | ++ | |
2896 | ++void gui_mac_set_application_menu() | |
2897 | ++{ | |
2898 | ++ NSMenu *appleMenu, *services; | |
2899 | ++ NSMenuItem *menuItem; | |
2900 | ++ NSString *title; | |
2901 | ++ NSString *appName; | |
2902 | ++ | |
2903 | ++ appName = @"Vim"; | |
2904 | ++ appleMenu = [[NSMenu alloc] initWithTitle: @""]; | |
2905 | ++ | |
2906 | ++ /* Add menu items */ | |
2907 | ++ title = [@"About " stringByAppendingString: appName]; | |
2908 | ++ [appleMenu addItemWithTitle: title | |
2909 | ++ action: @selector(orderFrontStandardAboutPanel:) | |
2910 | ++ keyEquivalent: @""]; | |
2911 | ++ | |
2912 | ++ [appleMenu addItem:[NSMenuItem separatorItem]]; | |
2913 | ++ | |
2914 | ++ // Services Menu | |
2915 | ++ services = [[[NSMenu alloc] init] autorelease]; | |
2916 | ++ [appleMenu addItemWithTitle: @"Services" | |
2917 | ++ action: nil | |
2918 | ++ keyEquivalent: @""]; | |
2919 | ++ [appleMenu setSubmenu: services forItem: [appleMenu itemWithTitle: @"Services"]]; | |
2920 | ++ | |
2921 | ++ // Hide AppName | |
2922 | ++ title = [@"Hide " stringByAppendingString:appName]; | |
2923 | ++ [appleMenu addItemWithTitle: title action: @selector(hide:) keyEquivalent: @"h"]; | |
2924 | ++ | |
2925 | ++ // Hide Others | |
2926 | ++ menuItem = (NSMenuItem *)[appleMenu addItemWithTitle: @"Hide Others" | |
2927 | ++ action: @selector(hideOtherApplications:) | |
2928 | ++ keyEquivalent: @"h"]; | |
2929 | ++ [menuItem setKeyEquivalentModifierMask: (NSAlternateKeyMask | NSCommandKeyMask)]; | |
2930 | ++ | |
2931 | ++ // Show All | |
2932 | ++ [appleMenu addItemWithTitle: @"Show All" | |
2933 | ++ action: @selector(unhideAllApplications:) | |
2934 | ++ keyEquivalent: @""]; | |
2935 | ++ | |
2936 | ++ [appleMenu addItem: [NSMenuItem separatorItem]]; | |
2937 | ++ | |
2938 | ++ // Quit AppName | |
2939 | ++ title = [@"Quit " stringByAppendingString: appName]; | |
2940 | ++ [appleMenu addItemWithTitle: title | |
2941 | ++ action: @selector(terminate:) | |
2942 | ++ keyEquivalent: @"q"]; | |
2943 | ++ | |
2944 | ++ /* Put menu into the menubar */ | |
2945 | ++ menuItem = [[NSMenuItem alloc] initWithTitle: @"" | |
2946 | ++ action: nil | |
2947 | ++ keyEquivalent: @""]; | |
2948 | ++ [menuItem setSubmenu: appleMenu]; | |
2949 | ++ [[NSApp mainMenu] addItem: menuItem]; | |
2950 | ++ | |
2951 | ++ /* Tell the application object that this is now the application menu */ | |
2952 | ++ [NSApp setAppleMenu: appleMenu]; | |
2953 | ++ [NSApp setServicesMenu: services]; | |
2954 | ++ | |
2955 | ++ /* Finally give up our references to the objects */ | |
2956 | ++ [appleMenu release]; | |
2957 | ++ [menuItem release]; | |
2958 | ++} | |
2959 | ++ | |
2960 | ++/* Menu Related Utilities 2}}} */ | |
2961 | ++ | |
2962 | ++/* Window related Utilities {{{2 */ | |
2963 | ++ | |
2964 | ++int gui_mac_create_window(NSRect rect) | |
2965 | ++{ | |
2966 | ++ VIMWindow *window; | |
2967 | ++ | |
2968 | ++ window = [[VIMWindow alloc] initWithContentRect: rect]; | |
2969 | ++ gui_mac.current_window = window; | |
2970 | ++ | |
2971 | ++ [NSApp activateIgnoringOtherApps: YES]; | |
2972 | ++ | |
2973 | ++ return OK; | |
2974 | ++} | |
2975 | ++ | |
2976 | ++NSWindow *gui_mac_get_window(NSRect rect) | |
2977 | ++{ | |
2978 | ++ if (gui_mac.current_window == nil) | |
2979 | ++ gui_mac_create_window(rect); | |
2980 | ++ | |
2981 | ++ return gui_mac.current_window; | |
2982 | ++} | |
2983 | ++ | |
2984 | ++void gui_mac_open_window() | |
2985 | ++{ | |
2986 | ++ NSWindow *window = gui_mac.current_window; | |
2987 | ++ NSPoint topLeft = NSZeroPoint; | |
2988 | ++ | |
2989 | ++ NSString *topLeftString = | |
2990 | ++ [[NSUserDefaults standardUserDefaults] stringForKey: @"VIMTopLeftPoint"]; | |
2991 | ++ if (topLeftString) | |
2992 | ++ topLeft = NSPointFromString(topLeftString); | |
2993 | ++ | |
2994 | ++ if (NSEqualPoints(topLeft, NSZeroPoint)) | |
2995 | ++ [window center]; | |
2996 | ++ else | |
2997 | ++ [window setFrameTopLeftPoint: topLeft]; | |
2998 | ++ | |
2999 | ++ [window makeKeyAndOrderFront: nil]; | |
3000 | ++ gui_mac.window_opened = YES; | |
3001 | ++} | |
3002 | ++ | |
3003 | ++/* Window related Utilities 2}}} */ | |
3004 | ++ | |
3005 | ++/* View related Utilities 2{{{ */ | |
3006 | ++ | |
3007 | ++@implementation VIMContentView | |
3008 | ++ | |
3009 | ++- (id) initWithFrame:(NSRect)rect | |
3010 | ++{ | |
3011 | ++ if ([super initWithFrame: rect]) | |
3012 | ++ { | |
3013 | ++ // NSShowRect("VIMContentView initWithFrame", rect); | |
3014 | ++ tabView = [[NSTabView alloc] initWithFrame:NSZeroRect]; | |
3015 | ++ NSRect tabFrame = NSMakeRect(0, 0, | |
3016 | ++ rect.size.width, gui.tabline_height); | |
3017 | ++ tabBarControl = [[PSMTabBarControl alloc] initWithFrame: tabFrame]; | |
3018 | ++ [tabView setDelegate: tabBarControl]; | |
3019 | ++ | |
3020 | ++ [tabBarControl setTabView: tabView]; | |
3021 | ++ [tabBarControl setDelegate: self]; | |
3022 | ++ [tabBarControl setHidden: YES]; | |
3023 | ++ | |
3024 | ++ [tabBarControl setCellMinWidth: 64]; | |
3025 | ++ [tabBarControl setCellMaxWidth: 64 * 6]; | |
3026 | ++ [tabBarControl setCellOptimumWidth: 132]; | |
3027 | ++ | |
3028 | ++ [tabBarControl setAutoresizingMask: NSViewWidthSizable | NSViewMaxYMargin]; | |
3029 | ++ | |
3030 | ++ [tabBarControl awakeFromNib]; | |
3031 | ++ [self addSubview: tabBarControl]; | |
3032 | ++ } | |
3033 | ++ | |
3034 | ++ return self; | |
3035 | ++} | |
3036 | ++ | |
3037 | ++- (void) dealloc | |
3038 | ++{ | |
3039 | ++ [tabBarControl release]; | |
3040 | ++ [tabView release]; | |
3041 | ++ | |
3042 | ++ [super dealloc]; | |
3043 | ++} | |
3044 | ++ | |
3045 | ++- (PSMTabBarControl *) tabBarControl | |
3046 | ++{ | |
3047 | ++ return tabBarControl; | |
3048 | ++} | |
3049 | ++ | |
3050 | ++- (NSTabView *) tabView | |
3051 | ++{ | |
3052 | ++ return tabView; | |
3053 | ++} | |
3054 | ++ | |
3055 | ++- (NSTabViewItem *) addNewTabViewItem | |
3056 | ++{ | |
3057 | ++ NSTabViewItem *item = [[NSTabViewItem alloc] initWithIdentifier: nil]; | |
3058 | ++ [tabView addTabViewItem: item]; | |
3059 | ++ [item release]; | |
3060 | ++ return item; | |
3061 | ++} | |
3062 | ++ | |
3063 | ++- (BOOL) isFlipped | |
3064 | ++{ | |
3065 | ++ return YES; | |
3066 | ++} | |
3067 | ++ | |
3068 | ++- (void) drawRect:(NSRect)rect | |
3069 | ++{ | |
3070 | ++ [[NSColor whiteColor] set]; | |
3071 | ++ NSRectFill(rect); | |
3072 | ++} | |
3073 | ++ | |
3074 | ++/* PSMTabBarControl delegate {{{2 */ | |
3075 | ++ | |
3076 | ++- (BOOL) tabView: (NSTabView *) theTabView | |
3077 | ++shouldSelectTabViewItem: (NSTabViewItem *) tabViewItem | |
3078 | ++{ | |
3079 | ++ gui_mac_msg(MSG_INFO, @"tabView:shouldSelectTabViewItem: %@, %s", | |
3080 | ++ tabViewItem, gui_mac.selecting_tab == YES ? "YES" : "NO"); | |
3081 | ++ | |
3082 | ++ if (gui_mac.selecting_tab == NO) | |
3083 | ++ { | |
3084 | ++ NSArray *tabViewItems = [tabBarControl representedTabViewItems]; | |
3085 | ++ int idx = [tabViewItems indexOfObject: tabViewItem] + 1; | |
3086 | ++ | |
3087 | ++ send_tabline_event(idx); | |
3088 | ++ gui_mac_update(); | |
3089 | ++ } | |
3090 | ++ | |
3091 | ++ return gui_mac.selecting_tab; | |
3092 | ++} | |
3093 | ++ | |
3094 | ++- (BOOL) tabView: (NSTabView *) theTabView | |
3095 | ++shouldCloseTabViewItem: (NSTabViewItem *) tabViewItem | |
3096 | ++{ | |
3097 | ++ NSArray *tabViewItems = [tabBarControl representedTabViewItems]; | |
3098 | ++ int idx = [tabViewItems indexOfObject: tabViewItem] + 1; | |
3099 | ++ | |
3100 | ++ send_tabline_menu_event(idx, TABLINE_MENU_CLOSE); | |
3101 | ++ gui_mac_update(); | |
3102 | ++ | |
3103 | ++ return NO; | |
3104 | ++} | |
3105 | ++ | |
3106 | ++- (void) tabView: (NSTabView *) theTabView | |
3107 | ++didDragTabViewItem: (NSTabViewItem *) tabViewItem | |
3108 | ++ toIndex: (int) idx | |
3109 | ++{ | |
3110 | ++ gui_mac_msg(MSG_INFO, @"tabView:didDragTabViewItem: %@ toIndex: %d", | |
3111 | ++ tabViewItem, idx); | |
3112 | ++ tabpage_move(idx); | |
3113 | ++ gui_mac_update(); | |
3114 | ++} | |
3115 | ++ | |
3116 | ++/* PSMTabBarControl delegate 2}}} */ | |
3117 | ++ | |
3118 | ++@end | |
3119 | ++ | |
3120 | ++@implementation VIMTextView | |
3121 | ++ | |
3122 | ++- (id) initWithFrame:(NSRect)rect | |
3123 | ++{ | |
3124 | ++ if ((self = [super initWithFrame: rect])) { | |
3125 | ++ markedText = nil; | |
3126 | ++ markedTextAttributes = [[NSMutableDictionary dictionaryWithObjectsAndKeys: | |
3127 | ++ [NSNumber numberWithInt: (NSUnderlineStyleSingle | | |
3128 | ++ NSUnderlinePatternSolid)], | |
3129 | ++ NSUnderlineStyleAttributeName, | |
3130 | ++ nil] retain]; | |
3131 | ++ | |
3132 | ++ [self registerForDraggedTypes: [NSArray arrayWithObjects: | |
3133 | ++ NSFilenamesPboardType, NSStringPboardType, nil]]; | |
3134 | ++ | |
3135 | ++ if (! NSEqualRects(rect, NSZeroRect)) | |
3136 | ++ { | |
3137 | ++ contentImage = [[NSImage alloc] initWithSize: rect.size]; | |
3138 | ++ gui_mac.main_height = rect.size.height; | |
3139 | ++ } | |
3140 | ++ | |
3141 | ++ else contentImage = nil; | |
3142 | ++ } | |
3143 | ++ | |
3144 | ++ return self; | |
3145 | ++} | |
3146 | ++ | |
3147 | ++- (void) synchronizeContentImage | |
3148 | ++{ | |
3149 | ++ NSSize size = [self frame].size; | |
3150 | ++ | |
3151 | ++ if (! NSEqualSizes([contentImage size], size)) | |
3152 | ++ { | |
3153 | ++ gui_mac_msg(MSG_INFO, @"REALLOCATE content image to: (%g, %g)", | |
3154 | ++ size.width, size.height); | |
3155 | ++ [contentImage release]; | |
3156 | ++ contentImage = [[NSImage alloc] initWithSize: size]; | |
3157 | ++ gui_mac.main_height = size.height; | |
3158 | ++ } | |
3159 | ++} | |
3160 | ++ | |
3161 | ++- (void) viewWillStartLiveResize | |
3162 | ++{ | |
3163 | ++ lastSetTitle = [[gui_mac.current_window title] retain]; | |
3164 | ++ [super viewWillStartLiveResize]; | |
3165 | ++} | |
3166 | ++ | |
3167 | ++- (void) viewDidEndLiveResize | |
3168 | ++{ | |
3169 | ++ [gui_mac.current_window setTitle: lastSetTitle]; | |
3170 | ++ [lastSetTitle release]; | |
3171 | ++ lastSetTitle = nil; | |
3172 | ++ | |
3173 | ++ [super viewDidEndLiveResize]; | |
3174 | ++} | |
3175 | ++ | |
3176 | ++- (void) dealloc | |
3177 | ++{ | |
3178 | ++ [markedTextAttributes release]; | |
3179 | ++ [markedText release]; | |
3180 | ++ [contentImage release]; | |
3181 | ++ [lastSetTitle release]; | |
3182 | ++ | |
3183 | ++ [super dealloc]; | |
3184 | ++} | |
3185 | ++ | |
3186 | ++- (void) beginDrawing | |
3187 | ++{ | |
3188 | ++ [contentImage lockFocus]; | |
3189 | ++} | |
3190 | ++ | |
3191 | ++- (void) endDrawing | |
3192 | ++{ | |
3193 | ++ [contentImage unlockFocus]; | |
3194 | ++} | |
3195 | ++ | |
3196 | ++- (void) clearAll | |
3197 | ++{ | |
3198 | ++ gui_mch_set_bg_color(gui.back_pixel); | |
3199 | ++ | |
3200 | ++ [contentImage lockFocus]; | |
3201 | ++ | |
3202 | ++ [gui_mac.bg_color set]; | |
3203 | ++ NSRectFill([self bounds]); | |
3204 | ++ | |
3205 | ++ [contentImage unlockFocus]; | |
3206 | ++} | |
3207 | ++ | |
3208 | ++- (NSAttributedString *) markedText | |
3209 | ++{ | |
3210 | ++ return markedText; | |
3211 | ++} | |
3212 | ++ | |
3213 | ++- (void) setMarkedTextAttribute:(id)value forKey:(NSString *)key | |
3214 | ++{ | |
3215 | ++ [markedTextAttributes setObject: value | |
3216 | ++ forKey: key]; | |
3217 | ++} | |
3218 | ++ | |
3219 | ++- (BOOL) isOpaque | |
3220 | ++{ | |
3221 | ++ return YES; | |
3222 | ++} | |
3223 | ++ | |
3224 | ++- (BOOL) hasMarkedText | |
3225 | ++{ | |
3226 | ++ return markedRange.length > 0 ? YES : NO; | |
3227 | ++} | |
3228 | ++ | |
3229 | ++- (NSRange) markedRange | |
3230 | ++{ | |
3231 | ++ return markedRange; | |
3232 | ++} | |
3233 | ++ | |
3234 | ++- (NSRange) selectedRange | |
3235 | ++{ | |
3236 | ++ return NSMakeRange(NSNotFound, 0); | |
3237 | ++} | |
3238 | ++ | |
3239 | ++- (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange | |
3240 | ++{ | |
3241 | ++ // gui_mac_msg(MSG_DEBUG, @"setMarkedText: %@ (%u, %u)", aString, | |
3242 | ++ // selRange.location, selRange.length); | |
3243 | ++ | |
3244 | ++ markedRange = NSMakeRange(0, [aString length]); | |
3245 | ++ | |
3246 | ++ [markedText release]; | |
3247 | ++ if ([aString isKindOfClass: [NSAttributedString class]]) | |
3248 | ++ markedText = [[NSAttributedString alloc] initWithString: [aString string] | |
3249 | ++ attributes: markedTextAttributes]; | |
3250 | ++ else | |
3251 | ++ markedText = [[NSAttributedString alloc] initWithString: aString | |
3252 | ++ attributes: markedTextAttributes]; | |
3253 | ++ | |
3254 | ++ if (markedRange.length > 0) | |
3255 | ++ { | |
3256 | ++ } else | |
3257 | ++ { | |
3258 | ++ // gui_mac_msg(MSG_DEBUG, @"clear markedText"); | |
3259 | ++ gui_update_cursor(TRUE, FALSE); | |
3260 | ++ } | |
3261 | ++ | |
3262 | ++ gui_mac_redraw(); | |
3263 | ++} | |
3264 | ++ | |
3265 | ++- (void) unmarkText | |
3266 | ++{ | |
3267 | ++ markedRange = NSMakeRange(NSNotFound, 0); | |
3268 | ++ | |
3269 | ++ // gui_mac_msg(MSG_DEBUG, @"unmarkText"); | |
3270 | ++} | |
3271 | ++ | |
3272 | ++- (NSArray *) validAttributesForMarkedText | |
3273 | ++{ | |
3274 | ++ return nil; | |
3275 | ++} | |
3276 | ++ | |
3277 | ++- (NSAttributedString *) attributedSubstringFromRange:(NSRange)theRange | |
3278 | ++{ | |
3279 | ++ return nil; | |
3280 | ++} | |
3281 | ++ | |
3282 | ++- (unsigned int) characterIndexForPoint:(NSPoint)thePoint | |
3283 | ++{ | |
3284 | ++ // gui_mac_msg(MSG_DEBUG, @"characterIndexForPoint: x = %g, y = %g", thePoint.x, thePoint.y); | |
3285 | ++ return NSNotFound; | |
3286 | ++} | |
3287 | ++ | |
3288 | ++- (NSRect) firstRectForCharacterRange:(NSRange)theRange | |
3289 | ++{ | |
3290 | ++ NSRect rect = NSMakeRect(FILL_X(gui_mac.im_col), | |
3291 | ++ FILL_Y(gui_mac.im_row + 1), | |
3292 | ++ theRange.length * gui.char_width, | |
3293 | ++ gui.char_height); | |
3294 | ++ | |
3295 | ++ rect.origin = FLIPPED_POINT(self, rect.origin); | |
3296 | ++ rect.origin = [[self window] convertBaseToScreen: | |
3297 | ++ [self convertPoint: rect.origin toView: nil]]; | |
3298 | ++ | |
3299 | ++ return rect; | |
3300 | ++} | |
3301 | ++ | |
3302 | ++- (NSInteger) conversationIdentifier | |
3303 | ++{ | |
3304 | ++ return (NSInteger) self; | |
3305 | ++} | |
3306 | ++ | |
3307 | ++- (void) doCommandBySelector:(SEL)aSelector | |
3308 | ++{ | |
3309 | ++ | |
3310 | ++} | |
3311 | ++ | |
3312 | ++#define INLINE_KEY_BUFFER_SIZE 256 | |
3313 | ++#define add_to_key_buffer(buf, len, k1, k2, k3) { buf[len++] = k1; buf[len++] = k2; buf[len++] = k3; } | |
3314 | ++ | |
3315 | ++- (void) insertText:(id)aString | |
3316 | ++{ | |
3317 | ++ char_u *to; | |
3318 | ++ unichar *text; | |
3319 | ++ int i; | |
3320 | ++ size_t u16_len, enc_len, result_len = 0; | |
3321 | ++ char_u result[INLINE_KEY_BUFFER_SIZE]; | |
3322 | ++ | |
3323 | ++ // gui_mac_msg(MSG_DEBUG, @"insertText: %@", aString); | |
3324 | ++ | |
3325 | ++ u16_len = [aString length] * 2; | |
3326 | ++ text = (unichar *) alloc(u16_len); | |
3327 | ++ if (! text) | |
3328 | ++ return; | |
3329 | ++ | |
3330 | ++ [aString getCharacters: text]; | |
3331 | ++ to = mac_utf16_to_enc(text, u16_len, &enc_len); | |
3332 | ++ | |
3333 | ++ if (! to) | |
3334 | ++ return; | |
3335 | ++ | |
3336 | ++ /* This is basically add_to_input_buf_csi() */ | |
3337 | ++ for (i = 0; i < enc_len && result_len < (INLINE_KEY_BUFFER_SIZE - 1); ++i) | |
3338 | ++ { | |
3339 | ++ result[result_len++] = to[i]; | |
3340 | ++ if (to[i] == CSI) | |
3341 | ++ { | |
3342 | ++ result[result_len++] = KS_EXTRA; | |
3343 | ++ result[result_len++] = (int)KE_CSI; | |
3344 | ++ } | |
3345 | ++ } | |
3346 | ++ vim_free(to); | |
3347 | ++ | |
3348 | ++ /* clear marked text */ | |
3349 | ++ markedRange = NSMakeRange(NSNotFound, 0); | |
3350 | ++ [markedText release]; | |
3351 | ++ markedText = nil; | |
3352 | ++ | |
3353 | ++ if (result_len > 0) | |
3354 | ++ { | |
3355 | ++ add_to_input_buf(result, result_len); | |
3356 | ++ gui_mac_stop_app(YES); | |
3357 | ++ } | |
3358 | ++} | |
3359 | ++ | |
3360 | ++#define LIGHT_WEIGHT_LIVE_RESIZE 0 | |
3361 | ++ | |
3362 | ++- (void) drawRect:(NSRect)rect | |
3363 | ++{ | |
3364 | ++#if 0 | |
3365 | ++ gui_mac_msg(MSG_INFO, @"drawRect: (%f, %f), (%f, %f)", | |
3366 | ++ rect.origin.x, rect.origin.y, | |
3367 | ++ rect.size.width, rect.size.height); | |
3368 | ++#endif | |
3369 | ++#if LIGHTWEIDHT_LIVE_RESIZE | |
3370 | ++ if ([self inLiveResize]) | |
3371 | ++ { | |
3372 | ++ NSFont *font; | |
3373 | ++ NSString *size_desc; | |
3374 | ++ NSDictionary *attrib; | |
3375 | ++ | |
3376 | ++ [NSColorFromGuiColor(gui.back_pixel, VIM_BG_ALPHA) set]; | |
3377 | ++ [NSBezierPath fillRect: rect]; | |
3378 | ++ | |
3379 | ++ font = [NSFont boldSystemFontOfSize: 48.0]; | |
3380 | ++ | |
3381 | ++ size_desc = [NSString stringWithFormat: @"%d x %d (%d x %d)", | |
3382 | ++ (int) rect.size.width, | |
3383 | ++ (int) rect.size.height, | |
3384 | ++ (int) rect.size.width / gui.char_width, | |
3385 | ++ (int) rect.size.height / gui.char_height]; | |
3386 | ++ attrib = [NSDictionary dictionaryWithObjectsAndKeys: | |
3387 | ++ [NSColor whiteColor], NSForegroundColorAttributeName, | |
3388 | ++ font, NSFontAttributeName, nil]; | |
3389 | ++ | |
3390 | ++ NSSize desc_size = [size_desc sizeWithAttributes: attrib]; | |
3391 | ++ | |
3392 | ++ [size_desc drawAtPoint: NSMakePoint(rect.size.width / 2 - desc_size.width / 2, | |
3393 | ++ rect.size.height / 2 - desc_size.height / 2) | |
3394 | ++ withAttributes: attrib]; | |
3395 | ++ return; | |
3396 | ++ } | |
3397 | ++ else | |
3398 | ++ { | |
3399 | ++#endif | |
3400 | ++ [contentImage compositeToPoint: rect.origin | |
3401 | ++ fromRect: rect | |
3402 | ++ operation: NSCompositeCopy]; | |
3403 | ++ | |
3404 | ++ if ([self hasMarkedText]) | |
3405 | ++ { | |
3406 | ++ // gui_mac_msg(MSG_DEBUG, @"redraw: %@", markedText); | |
3407 | ++ NSPoint cursorPoint = NSMakePoint(FILL_X(gui_mac.im_col), FILL_Y(gui_mac.im_row + 1)); | |
3408 | ++ [markedText drawAtPoint: FLIPPED_POINT(self, cursorPoint)]; | |
3409 | ++ } | |
3410 | ++#if LIGHTWEIDHT_LIVE_RESIZE | |
3411 | ++ } | |
3412 | ++#endif | |
3413 | ++} | |
3414 | ++ | |
3415 | ++- (BOOL) wantsDefaultClipping | |
3416 | ++{ | |
3417 | ++ return NO; | |
3418 | ++} | |
3419 | ++ | |
3420 | ++- (BOOL) isFlipped | |
3421 | ++{ | |
3422 | ++ return NO; | |
3423 | ++} | |
3424 | ++ | |
3425 | ++- (BOOL) acceptsFirstResponder | |
3426 | ++{ | |
3427 | ++ return YES; | |
3428 | ++} | |
3429 | ++ | |
3430 | ++- (void) scrollWheel:(NSEvent *)event | |
3431 | ++{ | |
3432 | ++ if ([event deltaY] == 0) | |
3433 | ++ return; | |
3434 | ++ | |
3435 | ++ [self mouseAction: [event deltaY] > 0 ? MOUSE_4 : MOUSE_5 | |
3436 | ++ repeated: NO | |
3437 | ++ event: event]; | |
3438 | ++} | |
3439 | ++ | |
3440 | ++- (void) mouseAction:(int)button repeated:(bool)repeated event:(NSEvent *)event | |
3441 | ++{ | |
3442 | ++ NSPoint point = [self convertPoint: [event locationInWindow] | |
3443 | ++ fromView: nil]; | |
3444 | ++ | |
3445 | ++ point = FLIPPED_POINT(self, point); | |
3446 | ++ | |
3447 | ++ int flags = gui_mac_mouse_modifiers_to_vim([event modifierFlags]); | |
3448 | ++ gui_send_mouse_event(button, point.x, point.y, repeated, flags); | |
3449 | ++ gui_mac_stop_app(YES); | |
3450 | ++} | |
3451 | ++ | |
3452 | ++- (void) mouseDown:(NSEvent *)event | |
3453 | ++{ | |
3454 | ++ int button = gui_mac_mouse_button_to_vim([event buttonNumber]); | |
3455 | ++ | |
3456 | ++ gui_mac.last_mouse_down_event = [event copy]; | |
3457 | ++ | |
3458 | ++ // gui_mac_msg(MSG_DEBUG, @"mouseDown: %s", | |
3459 | ++ // button == MOUSE_LEFT ? "MOUSE_LEFT" : "MOUSE_RIGHT"); | |
3460 | ++ | |
3461 | ++ [self mouseAction: button | |
3462 | ++ repeated: [event clickCount] != 0 | |
3463 | ++ event: event]; | |
3464 | ++} | |
3465 | ++ | |
3466 | ++- (void) rightMouseDown:(NSEvent *)event | |
3467 | ++{ | |
3468 | ++ [self mouseDown: event]; | |
3469 | ++} | |
3470 | ++ | |
3471 | ++- (void) otherMouseDown:(NSEvent *)event | |
3472 | ++{ | |
3473 | ++ [self mouseDown: event]; | |
3474 | ++} | |
3475 | ++ | |
3476 | ++- (void) mouseUp:(NSEvent *)event | |
3477 | ++{ | |
3478 | ++ [self mouseAction: MOUSE_RELEASE | |
3479 | ++ repeated: NO | |
3480 | ++ event: event]; | |
3481 | ++} | |
3482 | ++ | |
3483 | ++- (void) rightMouseUp:(NSEvent *)event | |
3484 | ++{ | |
3485 | ++ [self mouseUp: event]; | |
3486 | ++} | |
3487 | ++ | |
3488 | ++- (void) otherMouseUp:(NSEvent *)event | |
3489 | ++{ | |
3490 | ++ [self mouseUp: event]; | |
3491 | ++} | |
3492 | ++ | |
3493 | ++- (void) mouseDragged:(NSEvent *)event | |
3494 | ++{ | |
3495 | ++ [self mouseAction: MOUSE_DRAG | |
3496 | ++ repeated: NO | |
3497 | ++ event: event]; | |
3498 | ++} | |
3499 | ++ | |
3500 | ++- (void) rightMouseDragged:(NSEvent *)event | |
3501 | ++{ | |
3502 | ++ [self mouseDragged: event]; | |
3503 | ++} | |
3504 | ++ | |
3505 | ++- (void) otherMouseDragged:(NSEvent *)event | |
3506 | ++{ | |
3507 | ++ [self mouseDragged: event]; | |
3508 | ++} | |
3509 | ++ | |
3510 | ++- (NSDragOperation) draggingEntered:(id <NSDraggingInfo>)sender | |
3511 | ++{ | |
3512 | ++ NSDragOperation sourceDragMask = [sender draggingSourceOperationMask]; | |
3513 | ++ NSPasteboard *pboard = [sender draggingPasteboard]; | |
3514 | ++ | |
3515 | ++ if (([[pboard types] containsObject: NSFilenamesPboardType] || | |
3516 | ++ [[pboard types] containsObject: NSStringPboardType]) && | |
3517 | ++ (sourceDragMask & NSDragOperationCopy)) | |
3518 | ++ return NSDragOperationCopy; | |
3519 | ++ | |
3520 | ++ return NSDragOperationNone; | |
3521 | ++} | |
3522 | ++ | |
3523 | ++- (NSDragOperation) draggingUpdated:(id <NSDraggingInfo>)sender | |
3524 | ++{ | |
3525 | ++ return [self draggingEntered: sender]; | |
3526 | ++} | |
3527 | ++ | |
3528 | ++- (BOOL) performDragOperation:(id <NSDraggingInfo>)sender | |
3529 | ++{ | |
3530 | ++ NSPasteboard *pboard = [sender draggingPasteboard]; | |
3531 | ++ | |
3532 | ++ if ([[pboard types] containsObject: NSFilenamesPboardType]) | |
3533 | ++ { | |
3534 | ++ NSArray *files = [pboard propertyListForType: NSFilenamesPboardType]; | |
3535 | ++ int i, count = [files count]; | |
3536 | ++ NSPoint point = [self convertPoint: [sender draggingLocation] | |
3537 | ++ fromView: nil]; | |
3538 | ++ | |
3539 | ++ point = FLIPPED_POINT(self, point); | |
3540 | ++ | |
3541 | ++ char_u **fnames = (char_u **) alloc(count * sizeof(char_u *)); | |
3542 | ++ for (i = 0; i < count; ++i) | |
3543 | ++ { | |
3544 | ++ NSString *file = [files objectAtIndex: i]; | |
3545 | ++ | |
3546 | ++ fnames[i] = vim_strsave((char_u *)[file fileSystemRepresentation]); | |
3547 | ++ } | |
3548 | ++ | |
3549 | ++ gui_handle_drop(point.x, point.y, 0, fnames, count); | |
3550 | ++ gui_mac_update(); | |
3551 | ++ return YES; | |
3552 | ++ } | |
3553 | ++ | |
3554 | ++ else if ([[pboard types] containsObject: NSStringPboardType]) | |
3555 | ++ { | |
3556 | ++#ifdef FEAT_DND | |
3557 | ++ NSString *dragString = [pboard stringForType: NSStringPboardType]; | |
3558 | ++ char_u dropkey[3] = { CSI, KS_EXTRA, (char_u) KE_DROP }; | |
3559 | ++ | |
3560 | ++ NSMutableString *string = [NSMutableString stringWithString: dragString]; | |
3561 | ++ | |
3562 | ++ // Replace unrecognized end-of-line sequences with \x0a (line feed). | |
3563 | ++ NSRange range = NSMakeRange(0, [string length]); | |
3564 | ++ unsigned n = [string replaceOccurrencesOfString: @"\x0d\x0a" | |
3565 | ++ withString: @"\x0a" | |
3566 | ++ options: 0 | |
3567 | ++ range: range]; | |
3568 | ++ if (n == 0) | |
3569 | ++ [string replaceOccurrencesOfString: @"\x0d" | |
3570 | ++ withString: @"\x0a" | |
3571 | ++ options: 0 | |
3572 | ++ range: range]; | |
3573 | ++ | |
3574 | ++ dnd_yank_drag_data((char_u *)[string UTF8String], | |
3575 | ++ [string lengthOfBytesUsingEncoding: NSUTF8StringEncoding]); | |
3576 | ++ add_to_input_buf(dropkey, sizeof(dropkey)); | |
3577 | ++ | |
3578 | ++ gui_mac_redraw(); | |
3579 | ++ gui_mac_update(); | |
3580 | ++#endif | |
3581 | ++ return YES; | |
3582 | ++ } | |
3583 | ++ | |
3584 | ++ return NO; | |
3585 | ++} | |
3586 | ++ | |
3587 | ++- (BOOL) performKeyEquivalent:(NSEvent *)event | |
3588 | ++{ | |
3589 | ++ // Called for Cmd+key keystrokes, function keys, arrow keys, page | |
3590 | ++ // up/down, home, end. | |
3591 | ++ if ([event type] != NSKeyDown) | |
3592 | ++ return NO; | |
3593 | ++ | |
3594 | ++ // HACK! Let the main menu try to handle any key down event, before | |
3595 | ++ // passing it on to vim, otherwise key equivalents for menus will | |
3596 | ++ // effectively be disabled. | |
3597 | ++ if ([[NSApp mainMenu] performKeyEquivalent: event]) | |
3598 | ++ return YES; | |
3599 | ++ | |
3600 | ++ // HACK! KeyCode 50 represent the key which switches between windows | |
3601 | ++ // within an application (like Cmd+Tab is used to switch between | |
3602 | ++ // applications). Return NO here, else the window switching does not work. | |
3603 | ++ // | |
3604 | ++ // Will this hack work for all languages / keyboard layouts? | |
3605 | ++ if ([event keyCode] == 50) | |
3606 | ++ return NO; | |
3607 | ++ | |
3608 | ++ if ([event modifierFlags] & NSCommandKeyMask) | |
3609 | ++ { | |
3610 | ++ [self keyDown: event]; | |
3611 | ++ return YES; | |
3612 | ++ } | |
3613 | ++ | |
3614 | ++ return NO; | |
3615 | ++} | |
3616 | ++ | |
3617 | ++- (void) keyDown:(NSEvent *)event | |
3618 | ++{ | |
3619 | ++ UniChar modified_char, original_char; | |
3620 | ++ unsigned int mac_modifiers, vim_modifiers; | |
3621 | ++ char_u result[INLINE_KEY_BUFFER_SIZE]; | |
3622 | ++ int len = 0; | |
3623 | ++ int vim_key_char; | |
3624 | ++ | |
3625 | ++ [NSCursor setHiddenUntilMouseMoves: YES]; | |
3626 | ++ | |
3627 | ++ /* get key code and modifier flags from event */ | |
3628 | ++ mac_modifiers = [event modifierFlags]; | |
3629 | ++ | |
3630 | ++ /* convert NS* style modifier flags to vim style */ | |
3631 | ++ vim_modifiers = gui_mac_key_modifiers_to_vim(mac_modifiers); | |
3632 | ++ | |
3633 | ++ // gui_mac_msg(MSG_DEBUG, @"keyDown: characters = %d", [[event characters] length]); | |
3634 | ++ | |
3635 | ++ if ([[event characters] length] == 1) | |
3636 | ++ { | |
3637 | ++ modified_char = [[event characters] characterAtIndex: 0]; | |
3638 | ++ original_char = [[event charactersIgnoringModifiers] characterAtIndex: 0]; | |
3639 | ++ | |
3640 | ++ /* Intercept CMD-. and CTRL-c */ | |
3641 | ++ if ((modified_char == Ctrl_C && ctrl_c_interrupts) || | |
3642 | ++ (modified_char == intr_char && intr_char != Ctrl_C)) | |
3643 | ++ { | |
3644 | ++ trash_input_buf(); | |
3645 | ++ got_int = TRUE; | |
3646 | ++ } | |
3647 | ++ | |
3648 | ++ // gui_mac_msg(MSG_DEBUG, @"original_char %d, modified_char: %d", | |
3649 | ++ // original_char, modified_char); | |
3650 | ++ | |
3651 | ++ vim_key_char = gui_mac_function_key_to_vim(original_char, vim_modifiers); | |
3652 | ++ // gui_mac_msg(MSG_DEBUG, @"vim_key_char: %d", vim_key_char); | |
3653 | ++ | |
3654 | ++ switch (vim_modifiers) | |
3655 | ++ { | |
3656 | ++ case MOD_MASK_ALT: | |
3657 | ++ case MOD_MASK_SHIFT: | |
3658 | ++ if (vim_key_char == 0) | |
3659 | ++ goto insert_text; | |
3660 | ++ break; | |
3661 | ++ | |
3662 | ++ default: | |
3663 | ++ if (vim_modifiers & MOD_MASK_CTRL) | |
3664 | ++ { | |
3665 | ++ result[len++] = modified_char; | |
3666 | ++ add_to_input_buf(result, len); | |
3667 | ++ // gui_mac_msg(MSG_DEBUG, @"CTRL-%c, add_to_input_buf: %d", original_char, len); | |
3668 | ++ | |
3669 | ++ gui_mac_stop_app(YES); | |
3670 | ++ return; | |
3671 | ++ } | |
3672 | ++ } | |
3673 | ++ | |
3674 | ++ /* if it's normal key, not special one, then Shift is already applied */ | |
3675 | ++ if (vim_key_char == 0 || | |
3676 | ++ ! (vim_key_char == ' ' || | |
3677 | ++ vim_key_char == 0xa0 || | |
3678 | ++ (vim_modifiers & MOD_MASK_CMD) || | |
3679 | ++ vim_key_char == 0x9 || | |
3680 | ++ vim_key_char == 0xd || | |
3681 | ++ vim_key_char == ESC)) | |
3682 | ++ vim_modifiers &= ~MOD_MASK_SHIFT; | |
3683 | ++ | |
3684 | ++ if (vim_modifiers) | |
3685 | ++ { | |
3686 | ++ add_to_key_buffer(result, len, CSI, KS_MODIFIER, vim_modifiers); | |
3687 | ++ | |
3688 | ++ // gui_mac_msg(MSG_DEBUG, "vim_modifiers: "); | |
3689 | ++ // print_vim_modifiers(vim_modifiers); | |
3690 | ++ } | |
3691 | ++ | |
3692 | ++ if (IS_SPECIAL(vim_key_char) || vim_key_char > 0) | |
3693 | ++ { | |
3694 | ++ if ([self hasMarkedText]) | |
3695 | ++ goto insert_text; | |
3696 | ++ | |
3697 | ++ /* must be enter, esc, backspace, tab, add to input buffer directly */ | |
3698 | ++ if (vim_key_char > 0) | |
3699 | ++ result[len++] = vim_key_char; | |
3700 | ++ | |
3701 | ++ else | |
3702 | ++ add_to_key_buffer(result, len, CSI, | |
3703 | ++ K_SECOND(vim_key_char), | |
3704 | ++ K_THIRD(vim_key_char)); | |
3705 | ++ | |
3706 | ++ // gui_mac_msg(MSG_DEBUG, @"IS_SPECIAL, add_to_input_buf: %d", len); | |
3707 | ++ } | |
3708 | ++ | |
3709 | ++ /* now here are normal characters */ | |
3710 | ++ else if (vim_modifiers) | |
3711 | ++ { | |
3712 | ++ result[len++] = original_char; | |
3713 | ++ // gui_mac_msg(MSG_DEBUG, @"original_char %c, add_to_input_buf: %d", | |
3714 | ++ // original_char, len); | |
3715 | ++ } | |
3716 | ++ | |
3717 | ++ if (len > 0) | |
3718 | ++ { | |
3719 | ++ add_to_input_buf(result, len); | |
3720 | ++ gui_mac_stop_app(YES); | |
3721 | ++ return; | |
3722 | ++ } | |
3723 | ++ } | |
3724 | ++ | |
3725 | ++insert_text: | |
3726 | ++ [self interpretKeyEvents: [NSArray arrayWithObject: event]]; | |
3727 | ++} | |
3728 | ++ | |
3729 | ++@end | |
3730 | ++ | |
3731 | ++/* View related Utilities 2}}} */ | |
3732 | ++ | |
3733 | ++/* Drawing related Utilities {{{2 */ | |
3734 | ++ | |
3735 | ++void gui_mac_scroll_rect(NSRect rect, int lines) | |
3736 | ++{ | |
3737 | ++ NSPoint dest_point = rect.origin; | |
3738 | ++ dest_point.y -= lines * gui.char_height; | |
3739 | ++ | |
3740 | ++ gui_mac_begin_drawing(); | |
3741 | ++ NSCopyBits(0, rect, dest_point); | |
3742 | ++ gui_mac_end_drawing(); | |
3743 | ++} | |
3744 | ++ | |
3745 | ++void gui_mac_redraw() | |
3746 | ++{ | |
3747 | ++ [currentView setNeedsDisplay: YES]; | |
3748 | ++} | |
3749 | ++ | |
3750 | ++/* Drawing related Utilities 2}}} */ | |
3751 | ++ | |
3752 | ++/* Keyboard Related Utilities 2{{{ */ | |
3753 | ++ | |
3754 | ++int gui_mac_function_key_to_vim(UniChar key_char, unsigned int vim_modifiers) | |
3755 | ++{ | |
3756 | ++ int i; | |
3757 | ++ | |
3758 | ++ for (i = 0; function_key_mapping[i].function_key != 0; i++) | |
3759 | ++ if (key_char == function_key_mapping[i].function_key) | |
3760 | ++ return simplify_key(function_key_mapping[i].vim_key, | |
3761 | ++ (int *) &vim_modifiers); | |
3762 | ++ | |
3763 | ++ return 0; | |
3764 | ++} | |
3765 | ++ | |
3766 | ++unsigned int gui_mac_key_modifiers_to_vim(unsigned int mac_modifiers) | |
3767 | ++{ | |
3768 | ++ unsigned int vim_modifiers = 0; | |
3769 | ++ | |
3770 | ++ if (mac_modifiers & NSShiftKeyMask) | |
3771 | ++ vim_modifiers |= MOD_MASK_SHIFT; | |
3772 | ++ if (mac_modifiers & NSControlKeyMask) | |
3773 | ++ vim_modifiers |= MOD_MASK_CTRL; | |
3774 | ++ if (mac_modifiers & NSAlternateKeyMask) | |
3775 | ++ vim_modifiers |= MOD_MASK_ALT; | |
3776 | ++ if (mac_modifiers & NSCommandKeyMask) | |
3777 | ++ vim_modifiers |= MOD_MASK_CMD; | |
3778 | ++ | |
3779 | ++ return vim_modifiers; | |
3780 | ++} | |
3781 | ++ | |
3782 | ++void print_vim_modifiers(unsigned int vim_modifiers) | |
3783 | ++{ | |
3784 | ++ if (vim_modifiers & MOD_MASK_SHIFT) | |
3785 | ++ fprintf(stderr, "SHIFT-"); | |
3786 | ++ | |
3787 | ++ if (vim_modifiers & MOD_MASK_CMD) | |
3788 | ++ fprintf(stderr, "CMD-"); | |
3789 | ++ | |
3790 | ++ if (vim_modifiers & MOD_MASK_ALT) | |
3791 | ++ fprintf(stderr, "ALT-"); | |
3792 | ++ | |
3793 | ++ if (vim_modifiers & MOD_MASK_CTRL) | |
3794 | ++ fprintf(stderr, "CTRL-"); | |
3795 | ++} | |
3796 | ++ | |
3797 | ++unsigned int gui_mac_mouse_modifiers_to_vim(unsigned int mac_modifiers) | |
3798 | ++{ | |
3799 | ++ unsigned int vim_modifiers = 0; | |
3800 | ++ | |
3801 | ++ if (mac_modifiers & NSShiftKeyMask) | |
3802 | ++ vim_modifiers |= MOUSE_SHIFT; | |
3803 | ++ if (mac_modifiers & NSControlKeyMask) | |
3804 | ++ vim_modifiers |= MOUSE_CTRL; | |
3805 | ++ if (mac_modifiers & NSAlternateKeyMask) | |
3806 | ++ vim_modifiers |= MOUSE_ALT; | |
3807 | ++ | |
3808 | ++ return vim_modifiers; | |
3809 | ++} | |
3810 | ++ | |
3811 | ++int gui_mac_mouse_button_to_vim(int mac_button) | |
3812 | ++{ | |
3813 | ++ static int vim_buttons[] = { MOUSE_LEFT, MOUSE_RIGHT, | |
3814 | ++ MOUSE_MIDDLE, MOUSE_X1, | |
3815 | ++ MOUSE_X2 }; | |
3816 | ++ | |
3817 | ++ return vim_buttons[mac_button < 5 ? mac_button : 0]; | |
3818 | ++} | |
3819 | ++ | |
3820 | ++/* Keyboard Related Utilities 2}}} */ | |
3821 | ++ | |
3822 | ++/* Font Related Utilities 2{{{ */ | |
3823 | ++ | |
3824 | ++NSFont *gui_mac_get_font(char_u *font_name, int size) | |
3825 | ++{ | |
3826 | ++ // gui_mac_msg(MSG_DEBUG, @"get_font: %s", font_name); | |
3827 | ++ NSString *mac_font_name = NSStringFromVim(font_name); | |
3828 | ++ | |
3829 | ++ // gui_mac_msg(MSG_DEBUG, @"fontWithName: %@, %d", mac_font_name, size); | |
3830 | ++ | |
3831 | ++ return [NSFont fontWithName: mac_font_name | |
3832 | ++ size: size]; | |
3833 | ++} | |
3834 | ++ | |
3835 | ++GuiFont gui_mac_find_font(char_u *font_spec) | |
3836 | ++{ | |
3837 | ++ int len = 0, size = VIM_DEFAULT_FONT_SIZE; | |
3838 | ++ NSFont *font; | |
3839 | ++ char_u *font_style, *p; | |
3840 | ++ char_u font_name[VIM_MAX_FONT_NAME_LEN]; | |
3841 | ++ | |
3842 | ++ // gui_mac_msg(MSG_DEBUG, @"find_font: %s", font_spec); | |
3843 | ++ | |
3844 | ++ font_style = vim_strchr(font_spec, ':'); | |
3845 | ++ len = font_style - font_spec; | |
3846 | ++ | |
3847 | ++ if (len < 0 || len >= VIM_MAX_FONT_NAME_LEN) | |
3848 | ++ return NOFONT; | |
3849 | ++ | |
3850 | ++ vim_strncpy(font_name, font_spec, len); | |
3851 | ++ font_name[len] = '\0'; | |
3852 | ++ | |
3853 | ++ if (*font_style == ':') | |
3854 | ++ { | |
3855 | ++ p = font_style + 1; | |
3856 | ++ /* Set the values found after ':' */ | |
3857 | ++ while (*p) | |
3858 | ++ { | |
3859 | ++ switch (*p++) | |
3860 | ++ { | |
3861 | ++ case 'h': | |
3862 | ++ size = gui_mac_points_to_pixels(p, &p); | |
3863 | ++ break; | |
3864 | ++ /* | |
3865 | ++ * TODO: Maybe accept width and styles | |
3866 | ++ */ | |
3867 | ++ } | |
3868 | ++ | |
3869 | ++ while (*p == ':') | |
3870 | ++ p++; | |
3871 | ++ } | |
3872 | ++ } | |
3873 | ++ | |
3874 | ++ font = gui_mac_get_font(font_name, size); | |
3875 | ++ if (font == nil) | |
3876 | ++ { | |
3877 | ++ /* | |
3878 | ++ * Try again, this time replacing underscores in the font name | |
3879 | ++ * with spaces (:set guifont allows the two to be used | |
3880 | ++ * interchangeably; the Font Manager doesn't). | |
3881 | ++ */ | |
3882 | ++ int i, changed = FALSE; | |
3883 | ++ | |
3884 | ++ for (i = font_name[0]; i > 0; --i) | |
3885 | ++ { | |
3886 | ++ if (font_name[i] == '_') | |
3887 | ++ { | |
3888 | ++ font_name[i] = ' '; | |
3889 | ++ changed = TRUE; | |
3890 | ++ } | |
3891 | ++ } | |
3892 | ++ | |
3893 | ++ if (changed) | |
3894 | ++ font = gui_mac_get_font(font_name, size); | |
3895 | ++ } | |
3896 | ++ | |
3897 | ++ if (font == nil) | |
3898 | ++ return NOFONT; | |
3899 | ++ | |
3900 | ++ [font retain]; | |
3901 | ++ return (long_u) font; | |
3902 | ++} | |
3903 | ++ | |
3904 | ++int gui_mac_points_to_pixels(char_u *str, char_u **end) | |
3905 | ++{ | |
3906 | ++ int pixels; | |
3907 | ++ int points = 0; | |
3908 | ++ int divisor = 0; | |
3909 | ++ | |
3910 | ++ while (*str) | |
3911 | ++ { | |
3912 | ++ if (*str == '.' && divisor == 0) | |
3913 | ++ { | |
3914 | ++ /* Start keeping a divisor, for later */ | |
3915 | ++ divisor = 1; | |
3916 | ++ continue; | |
3917 | ++ } | |
3918 | ++ | |
3919 | ++ if (! isdigit(*str)) | |
3920 | ++ break; | |
3921 | ++ | |
3922 | ++ points *= 10; | |
3923 | ++ points += *str - '0'; | |
3924 | ++ divisor *= 10; | |
3925 | ++ | |
3926 | ++ ++str; | |
3927 | ++ } | |
3928 | ++ | |
3929 | ++ if (divisor == 0) | |
3930 | ++ divisor = 1; | |
3931 | ++ | |
3932 | ++ pixels = points / divisor; | |
3933 | ++ *end = str; | |
3934 | ++ return pixels; | |
3935 | ++} | |
3936 | ++ | |
3937 | ++GuiFont gui_mac_create_related_font(GuiFont font, bool italic, bool bold) | |
3938 | ++{ | |
3939 | ++ CTFontSymbolicTraits traitMask; | |
3940 | ++ | |
3941 | ++ traitMask = italic ? kCTFontItalicTrait : 0; | |
3942 | ++ traitMask |= bold ? kCTFontBoldTrait : 0; | |
3943 | ++ | |
3944 | ++ return (GuiFont) CTFontCreateCopyWithSymbolicTraits((CTFontRef) font, | |
3945 | ++ 0.0, NULL, | |
3946 | ++ traitMask, traitMask); | |
3947 | ++} | |
3948 | ++ | |
3949 | ++/* Font Related Utilities 2}}} */ | |
3950 | ++ | |
3951 | ++/* Dialog Related Utilities {{{2 */ | |
3952 | ++ | |
3953 | ++int gui_mac_select_from_font_panel(char_u *font_name) | |
3954 | ++{ | |
3955 | ++ char fontSizeString[VIM_MAX_FONT_NAME_LEN]; | |
3956 | ++ NSFontPanel *fontPanel = [NSFontPanel sharedFontPanel]; | |
3957 | ++ | |
3958 | ++ if (gui_mac.current_font) | |
3959 | ++ [[NSFontManager sharedFontManager] setSelectedFont: gui_mac.current_font | |
3960 | ++ isMultiple: NO];; | |
3961 | ++ | |
3962 | ++ [fontPanel setDelegate: gui_mac.app_delegate]; | |
3963 | ++ [fontPanel orderFront: nil]; | |
3964 | ++ | |
3965 | ++ gui_mac.selected_font = nil; | |
3966 | ++ [NSApp run]; | |
3967 | ++ if (! gui_mac.selected_font) | |
3968 | ++ return FAIL; | |
3969 | ++ | |
3970 | ++ STRCPY(font_name, [[gui_mac.selected_font fontName] UTF8String]); | |
3971 | ++ STRCAT(font_name, ":h"); | |
3972 | ++ sprintf(fontSizeString, "%d", (int) [gui_mac.selected_font pointSize]); | |
3973 | ++ STRCAT(font_name, fontSizeString); | |
3974 | ++ | |
3975 | ++ return OK; | |
3976 | ++} | |
3977 | ++ | |
3978 | ++@implementation VIMAlert | |
3979 | ++ | |
3980 | ++- (void) dealloc | |
3981 | ++{ | |
3982 | ++ [textField release]; | |
3983 | ++ [super dealloc]; | |
3984 | ++} | |
3985 | ++ | |
3986 | ++- (void) setTextFieldString: (NSString *)textFieldString | |
3987 | ++{ | |
3988 | ++ [textField release]; | |
3989 | ++ textField = [[NSTextField alloc] init]; | |
3990 | ++ [textField setStringValue: textFieldString]; | |
3991 | ++} | |
3992 | ++ | |
3993 | ++- (NSTextField *) textField | |
3994 | ++{ | |
3995 | ++ return textField; | |
3996 | ++} | |
3997 | ++ | |
3998 | ++- (void) setInformativeText:(NSString *)text | |
3999 | ++{ | |
4000 | ++ if (textField) | |
4001 | ++ { | |
4002 | ++ // HACK! Add some space for the text field. | |
4003 | ++ [super setInformativeText: [text stringByAppendingString: @"\n\n\n"]]; | |
4004 | ++ } else | |
4005 | ++ { | |
4006 | ++ [super setInformativeText: text]; | |
4007 | ++ } | |
4008 | ++} | |
4009 | ++ | |
4010 | ++- (void) beginSheetModalForWindow:(NSWindow *)window | |
4011 | ++ modalDelegate:(id)delegate | |
4012 | ++ didEndSelector:(SEL)didEndSelector | |
4013 | ++ contextInfo:(void *)contextInfo | |
4014 | ++{ | |
4015 | ++ [super beginSheetModalForWindow: window | |
4016 | ++ modalDelegate: delegate | |
4017 | ++ didEndSelector: didEndSelector | |
4018 | ++ contextInfo: contextInfo]; | |
4019 | ++ | |
4020 | ++ // HACK! Place the input text field at the bottom of the informative text | |
4021 | ++ // (which has been made a bit larger by adding newline characters). | |
4022 | ++ NSView *contentView = [[self window] contentView]; | |
4023 | ++ NSRect rect = [contentView frame]; | |
4024 | ++ rect.origin.y = rect.size.height; | |
4025 | ++ | |
4026 | ++ NSArray *subviews = [contentView subviews]; | |
4027 | ++ unsigned i, count = [subviews count]; | |
4028 | ++ for (i = 0; i < count; ++i) | |
4029 | ++ { | |
4030 | ++ NSView *view = [subviews objectAtIndex: i]; | |
4031 | ++ | |
4032 | ++ if ([view isKindOfClass: [NSTextField class]] && | |
4033 | ++ [view frame].origin.y < rect.origin.y) { | |
4034 | ++ // NOTE: The informative text field is the lowest NSTextField in | |
4035 | ++ // the alert dialog. | |
4036 | ++ rect = [view frame]; | |
4037 | ++ } | |
4038 | ++ } | |
4039 | ++ | |
4040 | ++ rect.size.height = VIMAlertTextFieldHeight; | |
4041 | ++ [textField setFrame: rect]; | |
4042 | ++ [contentView addSubview: textField]; | |
4043 | ++ [textField becomeFirstResponder]; | |
4044 | ++} | |
4045 | ++ | |
4046 | ++@end | |
4047 | ++ | |
4048 | ++/* Dialog Related Utilities 2}}} */ | |
4049 | ++ | |
4050 | ++/* Scroll Bar Related Utilities {{{2 */ | |
4051 | ++ | |
4052 | ++@implementation VIMScroller | |
4053 | ++ | |
4054 | ++- (id)initWithVimScrollbar:(scrollbar_T *)scrollBar | |
4055 | ++ orientation:(int)orientation | |
4056 | ++{ | |
4057 | ++ unsigned int mask = 0; | |
4058 | ++ NSRect frame = orientation == SBAR_HORIZ ? NSMakeRect(0, 0, 1, 0) | |
4059 | ++ : NSMakeRect(0, 0, 0, 1); | |
4060 | ++ | |
4061 | ++ if ((self = [super initWithFrame: frame])) | |
4062 | ++ { | |
4063 | ++ vimScrollBar = scrollBar; | |
4064 | ++ | |
4065 | ++ [self setEnabled: YES]; | |
4066 | ++ [self setAction: @selector(scroll:)]; | |
4067 | ++ [self setTarget: self]; | |
4068 | ++ | |
4069 | ++ switch (vimScrollBar->type) | |
4070 | ++ { | |
4071 | ++ case SBAR_LEFT: | |
4072 | ++ mask = NSViewHeightSizable | NSViewMaxXMargin; | |
4073 | ++ break; | |
4074 | ++ | |
4075 | ++ case SBAR_RIGHT: | |
4076 | ++ mask = NSViewHeightSizable | NSViewMinXMargin; | |
4077 | ++ break; | |
4078 | ++ | |
4079 | ++ case SBAR_BOTTOM: | |
4080 | ++ mask = NSViewWidthSizable | NSViewMaxYMargin; | |
4081 | ++ break; | |
4082 | ++ } | |
4083 | ++ | |
4084 | ++ [self setAutoresizingMask: mask]; | |
4085 | ++ } | |
4086 | ++ | |
4087 | ++ return self; | |
4088 | ++} | |
4089 | ++ | |
4090 | ++- (void) scroll:(id)sender | |
4091 | ++{ | |
4092 | ++ scrollbar_T *sb = [sender vimScrollBar]; | |
4093 | ++ int hitPart = [sender hitPart]; | |
4094 | ++ float fval = [sender floatValue]; | |
4095 | ++ | |
4096 | ++ if (sb == NULL) | |
4097 | ++ return; | |
4098 | ++ | |
4099 | ++ scrollbar_T *sb_info = sb->wp ? &sb->wp->w_scrollbars[0] : sb; | |
4100 | ++ long value = sb_info->value; | |
4101 | ++ long size = sb_info->size; | |
4102 | ++ long max = sb_info->max; | |
4103 | ++ BOOL isStillDragging = NO; | |
4104 | ++ BOOL updateKnob = YES; | |
4105 | ++ | |
4106 | ++ switch (hitPart) { | |
4107 | ++ case NSScrollerDecrementPage: | |
4108 | ++ value -= (size > 2 ? size - 2 : 1); | |
4109 | ++ break; | |
4110 | ++ case NSScrollerIncrementPage: | |
4111 | ++ value += (size > 2 ? size - 2 : 1); | |
4112 | ++ break; | |
4113 | ++ case NSScrollerDecrementLine: | |
4114 | ++ --value; | |
4115 | ++ break; | |
4116 | ++ case NSScrollerIncrementLine: | |
4117 | ++ ++value; | |
4118 | ++ break; | |
4119 | ++ case NSScrollerKnob: | |
4120 | ++ isStillDragging = YES; | |
4121 | ++ // fall through ... | |
4122 | ++ case NSScrollerKnobSlot: | |
4123 | ++ value = (long)(fval * (max - size + 1)); | |
4124 | ++ // fall through ... | |
4125 | ++ default: | |
4126 | ++ updateKnob = NO; | |
4127 | ++ break; | |
4128 | ++ } | |
4129 | ++ | |
4130 | ++ //gui_mac_msg(MSG_DEBUG, @"value %d -> %d", sb_info->value, value); | |
4131 | ++ gui_drag_scrollbar(sb, value, isStillDragging); | |
4132 | ++ gui_mac_redraw(); | |
4133 | ++ if (updateKnob) | |
4134 | ++ { | |
4135 | ++ // Dragging the knob or option + clicking automatically updates | |
4136 | ++ // the knob position (on the actual NSScroller), so we only | |
4137 | ++ // need to set the knob position in the other cases. | |
4138 | ++ if (sb->wp) | |
4139 | ++ { | |
4140 | ++ // Update both the left & right vertical scrollbars. | |
4141 | ++ VIMScroller *leftScroller = (VIMScroller *) sb->wp->w_scrollbars[SBAR_LEFT].scroller; | |
4142 | ++ VIMScroller *rightScroller = (VIMScroller *) sb->wp->w_scrollbars[SBAR_RIGHT].scroller; | |
4143 | ++ [leftScroller setThumbValue: value size: size max: max]; | |
4144 | ++ [rightScroller setThumbValue: value size: size max: max]; | |
4145 | ++ } else | |
4146 | ++ { | |
4147 | ++ // Update the horizontal scrollbar. | |
4148 | ++ VIMScroller *scroller = (VIMScroller *) sb->scroller; | |
4149 | ++ [scroller setThumbValue: value size: size max: max]; | |
4150 | ++ } | |
4151 | ++ } | |
4152 | ++} | |
4153 | ++ | |
4154 | ++- (void) setThumbValue:(long)value size:(long)size max:(long)max | |
4155 | ++{ | |
4156 | ++ float fval = max - size + 1 > 0 ? (float) value / (max - size + 1) : 0; | |
4157 | ++ float prop = (float) size / (max + 1); | |
4158 | ++ | |
4159 | ++ if (fval < 0) fval = 0; | |
4160 | ++ else if (fval > 1.0f) fval = 1.0f; | |
4161 | ++ if (prop < 0) prop = 0; | |
4162 | ++ else if (prop > 1.0f) prop = 1.0f; | |
4163 | ++ | |
4164 | ++ [self setFloatValue: fval knobProportion: prop]; | |
4165 | ++} | |
4166 | ++ | |
4167 | ++- (scrollbar_T *) vimScrollBar | |
4168 | ++{ | |
4169 | ++ return vimScrollBar; | |
4170 | ++} | |
4171 | ++ | |
4172 | ++@end | |
4173 | ++ | |
4174 | ++void gui_mac_update_scrollbar(scrollbar_T *sb) | |
4175 | ++{ | |
4176 | ++ VIMScroller *scroller = gui_mac_get_scroller(sb); | |
4177 | ++ | |
4178 | ++ /* check if we need to add this scroller onto content view */ | |
4179 | ++ if (sb->enabled == TRUE && [scroller superview] != [gui_mac.current_window contentView]) | |
4180 | ++ { | |
4181 | ++ [[gui_mac.current_window contentView] addSubview: scroller]; | |
4182 | ++ // gui_mac_msg(MSG_DEBUG, @"addSubview: %s", scrollbar_desc(sb)); | |
4183 | ++ } | |
4184 | ++ | |
4185 | ++ if (sb->enabled == FALSE && [scroller superview] == [gui_mac.current_window contentView]) | |
4186 | ++ { | |
4187 | ++ [scroller removeFromSuperview]; | |
4188 | ++ // gui_mac_msg(MSG_DEBUG, @"removeFromSuperview: %s", scrollbar_desc(sb)); | |
4189 | ++ } | |
4190 | ++} | |
4191 | ++ | |
4192 | ++/* Scroll Bar Related Utilities 2}}} */ | |
4193 | ++ | |
4194 | ++/* Private Functions 1}}} */ | |
4195 | ++ | |
4196 | +diff --git a/src/main.c b/src/main.c | |
4197 | +index 9f56e88..8a5aa98 100644 | |
4198 | +--- a/src/main.c | |
4199 | ++++ b/src/main.c | |
4200 | +@@ -1847,7 +1847,7 @@ command_line_scan(parmp) | |
4201 | + break; | |
4202 | + | |
4203 | + case 'p': /* "-p[N]" open N tab pages */ | |
4204 | +-#ifdef TARGET_API_MAC_OSX | |
4205 | ++#ifdef FEAT_GUI_COCOA | |
4206 | + /* For some reason on MacOS X, an argument like: | |
4207 | + -psn_0_10223617 is passed in when invoke from Finder | |
4208 | + or with the 'open' command */ | |
4209 | +diff --git a/src/menu.c b/src/menu.c | |
4210 | +index 7d4839f..79189c7 100644 | |
4211 | +--- a/src/menu.c | |
4212 | ++++ b/src/menu.c | |
4213 | +@@ -2261,6 +2261,7 @@ ex_emenu(eap) | |
4214 | + } | |
4215 | + | |
4216 | + #if defined(FEAT_GUI_MSWIN) \ | |
4217 | ++ || (defined(FEAT_GUI_COCOA) && defined(FEAT_MENU)) \ | |
4218 | + || (defined(FEAT_GUI_GTK) && defined(FEAT_MENU)) \ | |
4219 | + || defined(FEAT_BEVAL_TIP) || defined(PROTO) | |
4220 | + /* | |
4221 | +diff --git a/src/option.c b/src/option.c | |
4222 | +index fcac415..d6ef662 100644 | |
4223 | +--- a/src/option.c | |
4224 | ++++ b/src/option.c | |
4225 | +@@ -481,7 +481,7 @@ static struct vimoption | |
4226 | + {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR, | |
4227 | + #if defined(FEAT_GUI) && defined(MACOS_X) | |
4228 | + (char_u *)&p_antialias, PV_NONE, | |
4229 | +- {(char_u *)FALSE, (char_u *)FALSE} | |
4230 | ++ {(char_u *)TRUE, (char_u *)TRUE} | |
4231 | + #else | |
4232 | + (char_u *)NULL, PV_NONE, | |
4233 | + {(char_u *)FALSE, (char_u *)FALSE} | |
4234 | +@@ -2525,6 +2525,13 @@ static struct vimoption | |
4235 | + (char_u *)&p_tbis, PV_NONE, | |
4236 | + {(char_u *)"small", (char_u *)0L}}, | |
4237 | + #endif | |
4238 | ++ {"transparency", "transp", P_NUM|P_VIM|P_RCLR, | |
4239 | ++#if defined(FEAT_GUI_COCOA) | |
4240 | ++ (char_u *)&p_transp, PV_NONE, | |
4241 | ++#else | |
4242 | ++ (char_u *)NULL, PV_NONE, | |
4243 | ++#endif | |
4244 | ++ {(char_u *)0L, (char_u *)0L} }, | |
4245 | + {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM, | |
4246 | + (char_u *)&p_ttimeout, PV_NONE, | |
4247 | + {(char_u *)FALSE, (char_u *)0L}}, | |
4248 | +@@ -7933,6 +7940,20 @@ set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags) | |
4249 | + } | |
4250 | + #endif | |
4251 | + | |
4252 | ++#if defined(FEAT_GUI_COCOA) | |
4253 | ++ /* 'transparency' is a number between 0 and 100 */ | |
4254 | ++ else if (pp == &p_transp) | |
4255 | ++ { | |
4256 | ++ if (p_transp < 0 || p_transp > 100) | |
4257 | ++ { | |
4258 | ++ errmsg = e_invarg; | |
4259 | ++ p_transp = old_value; | |
4260 | ++ } | |
4261 | ++ else if (gui.in_use) | |
4262 | ++ gui_mch_new_colors(); | |
4263 | ++ } | |
4264 | ++#endif | |
4265 | ++ | |
4266 | + /* | |
4267 | + * Check the bounds for numeric options here | |
4268 | + */ | |
4269 | +diff --git a/src/option.h b/src/option.h | |
4270 | +index 00374d7..73337d6 100644 | |
4271 | +--- a/src/option.h | |
4272 | ++++ b/src/option.h | |
4273 | +@@ -775,6 +775,9 @@ EXTERN char_u *p_titlestring; /* 'titlestring' */ | |
4274 | + #ifdef FEAT_INS_EXPAND | |
4275 | + EXTERN char_u *p_tsr; /* 'thesaurus' */ | |
4276 | + #endif | |
4277 | ++#ifdef FEAT_GUI_COCOA | |
4278 | ++EXTERN long p_transp; /* 'transparency' */ | |
4279 | ++#endif | |
4280 | + EXTERN int p_ttimeout; /* 'ttimeout' */ | |
4281 | + EXTERN long p_ttm; /* 'ttimeoutlen' */ | |
4282 | + EXTERN int p_tbi; /* 'ttybuiltin' */ | |
4283 | +diff --git a/src/os_mac.h b/src/os_mac.h | |
4284 | +index 7a54ee5..2e4c627 100644 | |
4285 | +--- a/src/os_mac.h | |
4286 | ++++ b/src/os_mac.h | |
4287 | +@@ -23,6 +23,7 @@ | |
4288 | + * files have many conflicts). | |
4289 | + */ | |
4290 | + #ifndef FEAT_X11 | |
4291 | ++#if 0 | |
4292 | + # include <Quickdraw.h> /* Apple calls it QuickDraw.h... */ | |
4293 | + # include <ToolUtils.h> | |
4294 | + # include <LowMem.h> | |
4295 | +@@ -36,6 +37,7 @@ | |
4296 | + # include <Script.h> | |
4297 | + # endif | |
4298 | + #endif | |
4299 | ++#endif | |
4300 | + | |
4301 | + /* | |
4302 | + * Unix interface | |
4303 | +diff --git a/src/os_mac_conv.c b/src/os_mac_conv.c | |
4304 | +index 7930189..6a7a6de 100644 | |
4305 | +--- a/src/os_mac_conv.c | |
4306 | ++++ b/src/os_mac_conv.c | |
4307 | +@@ -22,6 +22,9 @@ | |
4308 | + typedef int UniChar; | |
4309 | + typedef int *TECObjectRef; | |
4310 | + typedef int CFStringRef; | |
4311 | ++# else | |
4312 | ++typedef unsigned short UniChar; | |
4313 | ++#include <CoreServices/CoreServices.h> | |
4314 | + # endif | |
4315 | + | |
4316 | + static char_u *mac_utf16_to_utf8 __ARGS((UniChar *from, size_t fromLen, size_t *actualLen)); | |
4317 | +diff --git a/src/proto.h b/src/proto.h | |
4318 | +index 85f4937..d61171d 100644 | |
4319 | +--- a/src/proto.h | |
4320 | ++++ b/src/proto.h | |
4321 | +@@ -211,9 +211,12 @@ extern char_u *vimpty_getenv __ARGS((const char_u *string)); /* from pty.c */ | |
4322 | + extern char *vim_SelFile __ARGS((Widget toplevel, char *prompt, char *init_path, int (*show_entry)(), int x, int y, guicolor_T fg, guicolor_T bg, guicolor_T scroll_fg, guicolor_T scroll_bg)); | |
4323 | + # endif | |
4324 | + # endif | |
4325 | +-# ifdef FEAT_GUI_MAC | |
4326 | ++# ifdef FEAT_GUI_CARBON | |
4327 | + # include "gui_mac.pro" | |
4328 | + # endif | |
4329 | ++# ifdef FEAT_GUI_COCOA | |
4330 | ++# include "gui_cocoa.pro" | |
4331 | ++# endif | |
4332 | + # ifdef FEAT_GUI_X11 | |
4333 | + # include "gui_x11.pro" | |
4334 | + # endif | |
4335 | +diff --git a/src/proto/gui_cocoa.pro b/src/proto/gui_cocoa.pro | |
4336 | +new file mode 100755 | |
4337 | +index 0000000..69436af | |
4338 | +--- /dev/null | |
4339 | ++++ b/src/proto/gui_cocoa.pro | |
4340 | +@@ -0,0 +1,89 @@ | |
4341 | ++/* gui_cocoa.pro */ | |
4342 | ++ | |
4343 | ++/* | |
4344 | ++ * Mac specific prototypes | |
4345 | ++ */ | |
4346 | ++ | |
4347 | ++void gui_mch_set_blinking __ARGS((long wait, long on, long off)); | |
4348 | ++void gui_mch_stop_blink __ARGS((void)); | |
4349 | ++void gui_mch_start_blink __ARGS((void)); | |
4350 | ++void gui_mch_getmouse __ARGS((int *x, int *y)); | |
4351 | ++void gui_mch_setmouse __ARGS((int x, int y)); | |
4352 | ++void gui_mch_prepare __ARGS((int *argc, char **argv)); | |
4353 | ++int gui_mch_init_check __ARGS((void)); | |
4354 | ++int gui_mch_init __ARGS((void)); | |
4355 | ++void gui_mch_new_colors __ARGS((void)); | |
4356 | ++int gui_mch_open __ARGS((void)); | |
4357 | ++void gui_mch_exit __ARGS((int)); | |
4358 | ++void gui_mch_set_winsize __ARGS((int width, int height, int min_width, int min_height, int base_width, int base_height)); | |
4359 | ++int gui_mch_get_winpos __ARGS((int *x, int *y)); | |
4360 | ++void gui_mch_set_winpos __ARGS((int x, int y)); | |
4361 | ++void gui_mch_set_shellsize __ARGS((int width, int height, int min_width, int min_height, int base_width, int base_height, int direction)); | |
4362 | ++void gui_mch_get_screen_dimensions __ARGS((int *screen_w, int *screen_h)); | |
4363 | ++void gui_mch_set_text_area_pos __ARGS((int x, int y, int w, int h)); | |
4364 | ++void gui_mch_enable_scrollbar __ARGS((scrollbar_T *sb, int flag)); | |
4365 | ++void gui_mch_set_scrollbar_thumb __ARGS((scrollbar_T *sb, long val, long size, long max)); | |
4366 | ++void gui_mch_set_scrollbar_pos __ARGS((scrollbar_T *sb, int x, int y, int w, int h)); | |
4367 | ++void gui_mch_create_scrollbar __ARGS((scrollbar_T *sb, int orient)); | |
4368 | ++void gui_mch_destroy_scrollbar __ARGS((scrollbar_T *sb)); | |
4369 | ++int gui_mch_adjust_charheight __ARGS((void)); | |
4370 | ++int gui_mch_init_font __ARGS((char_u *font_name, int fontset)); | |
4371 | ++GuiFont gui_mch_get_font __ARGS((char_u *name, int giveErrorIfMissing)); | |
4372 | ++char_u *gui_mch_get_fontname __ARGS((GuiFont font, char_u *name)); | |
4373 | ++GuiFont gui_mac_find_font __ARGS((char_u *font_name)); | |
4374 | ++void gui_mch_set_font __ARGS((GuiFont font)); | |
4375 | ++int gui_mch_same_font __ARGS((GuiFont f1, GuiFont f2)); | |
4376 | ++void gui_mch_free_font __ARGS((GuiFont font)); | |
4377 | ++guicolor_T gui_mch_get_color __ARGS((char_u *name)); | |
4378 | ++void gui_mch_set_fg_color __ARGS((guicolor_T color)); | |
4379 | ++void gui_mch_set_bg_color __ARGS((guicolor_T color)); | |
4380 | ++void gui_mch_set_sp_color __ARGS((guicolor_T color)); | |
4381 | ++void gui_mch_draw_string __ARGS((int row, int col, char_u *s, int len, int flags)); | |
4382 | ++int gui_mch_haskey __ARGS((char_u *name)); | |
4383 | ++void gui_mch_beep __ARGS((void)); | |
4384 | ++void gui_mch_flash __ARGS((int msec)); | |
4385 | ++void gui_mch_invert_rectangle __ARGS((int r, int c, int nr, int nc)); | |
4386 | ++void gui_mch_iconify __ARGS((void)); | |
4387 | ++void gui_mch_settitle __ARGS((char_u *title, char_u *icon)); | |
4388 | ++void gui_mch_draw_hollow_cursor __ARGS((guicolor_T color)); | |
4389 | ++void gui_mch_draw_part_cursor __ARGS((int w, int h, guicolor_T color)); | |
4390 | ++void gui_mch_update __ARGS((void)); | |
4391 | ++int gui_mch_wait_for_chars __ARGS((int wtime)); | |
4392 | ++void gui_mch_flush __ARGS((void)); | |
4393 | ++void gui_mch_clear_block __ARGS((int row1, int col1, int row2, int col2)); | |
4394 | ++void gui_mch_clear_all __ARGS((void)); | |
4395 | ++void gui_mch_delete_lines __ARGS((int row, int num_lines)); | |
4396 | ++void gui_mch_insert_lines __ARGS((int row, int num_lines)); | |
4397 | ++void gui_mch_enable_menu __ARGS((int flag)); | |
4398 | ++void gui_mch_set_menu_pos __ARGS((int x, int y, int w, int h)); | |
4399 | ++void gui_mch_add_menu __ARGS((vimmenu_T *menu, int pos)); | |
4400 | ++void gui_mch_add_menu_item __ARGS((vimmenu_T *menu, int idx)); | |
4401 | ++void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu)); | |
4402 | ++void gui_mch_destroy_menu __ARGS((vimmenu_T *menu)); | |
4403 | ++void gui_mch_menu_grey __ARGS((vimmenu_T *menu, int grey)); | |
4404 | ++void gui_mch_menu_hidden __ARGS((vimmenu_T *menu, int hidden)); | |
4405 | ++void gui_mch_draw_menubar __ARGS((void)); | |
4406 | ++int gui_mch_get_lightness __ARGS((guicolor_T pixel)); | |
4407 | ++long_u gui_mch_get_rgb __ARGS((guicolor_T pixel)); | |
4408 | ++int gui_mch_get_mouse_x __ARGS((void)); | |
4409 | ++int gui_mch_get_mouse_y __ARGS((void)); | |
4410 | ++void gui_mch_setmouse __ARGS((int x, int y)); | |
4411 | ++void gui_mch_show_popupmenu __ARGS((vimmenu_T *menu)); | |
4412 | ++int gui_mch_dialog __ARGS((int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield)); | |
4413 | ++char_u *gui_mch_browse __ARGS((int saving, char_u *title, char_u *dflt, char_u *ext, char_u *initdir, char_u *filter)); | |
4414 | ++void gui_mch_set_foreground __ARGS((void)); | |
4415 | ++void gui_mch_show_tabline __ARGS((int showit)); | |
4416 | ++int gui_mch_showing_tabline __ARGS((void)); | |
4417 | ++void gui_mch_update_tabline __ARGS((void)); | |
4418 | ++void gui_mch_set_curtab __ARGS((int nr)); | |
4419 | ++ | |
4420 | ++void gui_mch_lose_selection __ARGS((void)); | |
4421 | ++int gui_mch_own_selection __ARGS((void)); | |
4422 | ++void gui_mch_clear_selection __ARGS((void)); | |
4423 | ++ | |
4424 | ++void clip_mch_lose_selection __ARGS((VimClipboard *cbd)); | |
4425 | ++void clip_mch_request_selection __ARGS((VimClipboard *cbd)); | |
4426 | ++void clip_mch_set_selection __ARGS((VimClipboard *cbd)); | |
4427 | ++int clip_mch_own_selection __ARGS((VimClipboard *cbd)); | |
4428 | ++ | |
4429 | ++/* vim: set ft=c : */ | |
4430 | +diff --git a/src/structs.h b/src/structs.h | |
4431 | +index 329676e..18724fb 100644 | |
4432 | +--- a/src/structs.h | |
4433 | ++++ b/src/structs.h | |
4434 | +@@ -2244,7 +2244,7 @@ struct VimMenu | |
4435 | + HMENU submenu_id; /* If this is submenu, add children here */ | |
4436 | + HWND tearoff_handle; /* hWnd of tearoff if created */ | |
4437 | + #endif | |
4438 | +-#ifdef FEAT_GUI_MAC | |
4439 | ++#ifdef FEAT_GUI_CARBON | |
4440 | + /* MenuHandle id; */ | |
4441 | + /* short index; */ /* the item index within the father menu */ | |
4442 | + short menu_id; /* the menu id to which this item belong */ | |
4443 | +@@ -2253,6 +2253,10 @@ struct VimMenu | |
4444 | + MenuHandle menu_handle; | |
4445 | + MenuHandle submenu_handle; | |
4446 | + #endif | |
4447 | ++#ifdef FEAT_GUI_COCOA | |
4448 | ++ void *menu_handle; /* NSMenu *, only for menus with submenus */ | |
4449 | ++ void *item_handle; /* NSMenuItem *, for all menus */ | |
4450 | ++#endif | |
4451 | + #ifdef RISCOS | |
4452 | + int *id; /* Not used, but gui.c needs it */ | |
4453 | + int greyed_out; /* Flag */ | |
4454 | +diff --git a/src/version.c b/src/version.c | |
4455 | +index cdd069b..bb2cf9f 100644 | |
4456 | +--- a/src/version.c | |
4457 | ++++ b/src/version.c | |
4458 | +@@ -1205,10 +1205,10 @@ list_version() | |
4459 | + # if defined(MSWIN) | |
4460 | + MSG_PUTS(_("with GUI.")); | |
4461 | + # else | |
4462 | +-# if defined (TARGET_API_MAC_CARBON) && TARGET_API_MAC_CARBON | |
4463 | ++# ifdef FEAT_GUI_CARBON | |
4464 | + MSG_PUTS(_("with Carbon GUI.")); | |
4465 | + # else | |
4466 | +-# if defined (TARGET_API_MAC_OSX) && TARGET_API_MAC_OSX | |
4467 | ++# ifdef FEAT_GUI_COCOA | |
4468 | + MSG_PUTS(_("with Cocoa GUI.")); | |
4469 | + # else | |
4470 | + # if defined (MACOS) |
@@ -0,0 +1,18 @@ | ||
1 | +--- src/vim.h | |
2 | ++++ src/vim.h | |
3 | +@@ -479,6 +479,15 @@ | |
4 | + # define USE_AMBIWIDTH_AUTO | |
5 | + #endif | |
6 | + | |
7 | ++#if defined(FEAT_GUI_MAC) | |
8 | ++# if !defined(USE_IM_CONTROL) | |
9 | ++# define USE_IM_CONTROL | |
10 | ++# endif | |
11 | ++# if !defined(USE_TRANSPARENCY) | |
12 | ++# define USE_TRANSPARENCY | |
13 | ++# endif | |
14 | ++#endif | |
15 | ++ | |
16 | + /* | |
17 | + * For dynamically loaded gettext library. Currently, only for Win32. | |
18 | + */ |
@@ -0,0 +1,66 @@ | ||
1 | +eval { | |
2 | + set low 1 | |
3 | + set patchlevel [string trimleft $vim_patchlevel 0] | |
4 | + set files {} | |
5 | + | |
6 | + while {$low <= $patchlevel} { | |
7 | + set high [expr $low + 99]; | |
8 | + if {$high < $patchlevel} { | |
9 | + patchfiles-append [format "%s.%03d-%03d.gz" $vim_version $low $high] | |
10 | + incr low 100 | |
11 | + } else { | |
12 | + patchfiles-append [format "%s.%03d" $vim_version $low] | |
13 | + incr low 1 | |
14 | + } | |
15 | + } | |
16 | +} | |
17 | + | |
18 | +checksums-append \ | |
19 | + 7.2.001-100.gz md5 ba91b19374cee90f71b8f4ab1d92dc0f \ | |
20 | + 7.2.101 md5 65e59923311b136306284319521d70d7 \ | |
21 | + 7.2.102 md5 42e2274c6a3152279720d8623f7916ad \ | |
22 | + 7.2.103 md5 654ba716e77d092c1c314fed18c7486d \ | |
23 | + 7.2.104 md5 b839c2c957eb3bb7511ace0b61d5d5fe \ | |
24 | + 7.2.105 md5 7f37ad0b1573be8bc39a817a21422a4e \ | |
25 | + 7.2.106 md5 4801df8c2833a683cd1b2a5870565e41 \ | |
26 | + 7.2.107 md5 e6801b619d40efe81428399e26e0486f \ | |
27 | + 7.2.108 md5 76f17428d216ec6b29036e22397c2765 \ | |
28 | + 7.2.109 md5 db97daa4f1e56440a988e7f5272997c7 \ | |
29 | + 7.2.110 md5 b8752c88429f869dec05232db89018e2 \ | |
30 | + 7.2.111 md5 e8cdc1e862b60215c12265e44b38239d \ | |
31 | + 7.2.112 md5 e933dd778c6f8687cf1f9f3e550e6cc0 \ | |
32 | + 7.2.113 md5 861729d9d4dc422e45c22bd8e006fc32 \ | |
33 | + 7.2.114 md5 5da3a29b3184af1780a82499343e7587 \ | |
34 | + 7.2.115 md5 b35c7b1cfa2a5f7b45829cd09ac27b7a \ | |
35 | + 7.2.116 md5 1355cc34fbc7be7eb48fa777e8f49dfb \ | |
36 | + 7.2.117 md5 8b9c839ec7448691b0a88475f0d0d4f9 \ | |
37 | + 7.2.118 md5 74d97a563ec1b1f1606705097396c391 \ | |
38 | + 7.2.119 md5 2ddd84423b902a2b3594c64c567be0b4 \ | |
39 | + 7.2.120 md5 5394e442f011d47b6d69a7b03984cdf4 \ | |
40 | + 7.2.121 md5 6bdb5e63ca3d79d3dcb7127e14ae3949 \ | |
41 | + 7.2.122 md5 36554c0103cafc8759f3e71ccd56c56f \ | |
42 | + 7.2.123 md5 841c74d1f3cb8380fa5713d5b9ca2c98 \ | |
43 | + 7.2.124 md5 2489ebcb72280dd50b8756e4ab7d36ed \ | |
44 | + 7.2.125 md5 10b15d637133b73d825650363d863b58 \ | |
45 | + 7.2.126 md5 b31534667bb741e21479b1e3757c9e21 \ | |
46 | + 7.2.127 md5 71e87e78bea69d8876ff7f6d824c8986 \ | |
47 | + 7.2.128 md5 21da01d371757282bfd402ddd91005ba \ | |
48 | + 7.2.129 md5 e890b630efa3847c8cdee2f197145b6c \ | |
49 | + 7.2.130 md5 d3fe3bf37d5c0940f3e751f41d92e817 \ | |
50 | + 7.2.131 md5 3c2aaa22914d06a65bf0f212e43c3ace \ | |
51 | + 7.2.132 md5 379aa718df5dbcde8215fc4d94062d9f \ | |
52 | + 7.2.133 md5 6d51f9deb4c2604692f532c118b73ef8 \ | |
53 | + 7.2.134 md5 4acae77b2a217e1cb47040c08e28180d \ | |
54 | + 7.2.135 md5 4d30bf2c9d2973f5dd1c12468123dc41 \ | |
55 | + 7.2.136 md5 f2ae8cc595933938ee608e040d1256a5 \ | |
56 | + 7.2.137 md5 c613c1e0fac319f05ffe1fa7e27d6600 \ | |
57 | + 7.2.138 md5 e7d02c3dea47fa579366bb1cd025ce5e \ | |
58 | + 7.2.139 md5 04f7131164b3f46d6365a8faea0e32c6 \ | |
59 | + 7.2.140 md5 e1c0e4fbd985f5a2e5a24a4cfab1112c \ | |
60 | + 7.2.141 md5 e5a9c7ef44a38057c0c5c1191d9cdf77 \ | |
61 | + 7.2.142 md5 f08f7f966749c2ef20ff87dfeb9bef62 \ | |
62 | + 7.2.143 md5 6b132dad3ad947662d1c370193a14218 \ | |
63 | + 7.2.144 md5 4e2a1d1cb12198a783759f88e6c64fc4 \ | |
64 | + 7.2.145 md5 38877e2ac720e45e5d62cd1089167db3 \ | |
65 | + 7.2.146 md5 cb97aca73a1f4fdd2fac894bba7e43ae \ | |
66 | + 7.2.147 md5 4219afedebf0172118f2d078d9012995 |
@@ -0,0 +1,31 @@ | ||
1 | +set serverList { | |
2 | + http://ftp.vim.org/pub/vim/ \ | |
3 | + ftp://ftp.vim.org/pub/vim/ \ | |
4 | + ftp://ftp.us.vim.org/pub/vim/ \ | |
5 | + ftp://ftp.ca.vim.org/pub/vim/ \ | |
6 | + ftp://ftp.nl.vim.org/pub/vim/ \ | |
7 | + ftp://ftp.uk.vim.org/pub/vim/ \ | |
8 | + ftp://ftp.ie.vim.org/pub/vim/ \ | |
9 | + ftp://ftp.is.vim.org/pub/vim/ \ | |
10 | + ftp://ftp.pl.vim.org/pub/vim/ \ | |
11 | + ftp://ftp.ro.vim.org/pub/vim/ \ | |
12 | + ftp://ftp.cz.vim.org/pub/vim/ \ | |
13 | + ftp://ftp.sk.vim.org/pub/vim/ \ | |
14 | + ftp://ftp.jp.vim.org/pub/vim/ \ | |
15 | + ftp://ftp.kr.vim.org/pub/vim/ \ | |
16 | + ftp://ftp2.us.vim.org/pub/vim/ \ | |
17 | + ftp://ftp9.us.vim.org/pub/vim/ \ | |
18 | + ftp://ftp2.nl.vim.org/pub/vim/ \ | |
19 | + ftp://ftp3.nl.vim.org/pub/vim/ \ | |
20 | + ftp://ftp3.de.vim.org/pub/vim/ \ | |
21 | + ftp://ftp2.tw.vim.org/pub/vim/ \ | |
22 | + ftp://miroir-francais.fr/pub/vim/ \ | |
23 | + ftp://ftp.tw.vim.org/pub/Unix/Editors/Vim/ | |
24 | +} | |
25 | + | |
26 | +# create list of locations for source, extras, patches from serverList | |
27 | +foreach server ${serverList} { | |
28 | + master_sites-append ${server}unix/:vim | |
29 | + master_sites-append ${server}extra/:extra | |
30 | + patch_sites-append ${server}patches/${vim_version} | |
31 | +} |
@@ -0,0 +1,21 @@ | ||
1 | +" System vimrc file for Mac OS X | |
2 | +" Author: Benji Fisher <benji@member.AMS.org> | |
3 | +" Last modified: 23 February 2004 | |
4 | + | |
5 | +" TODO: Is there any way to test whether Vim.app was started from the Finder? | |
6 | +if has("gui_running") | |
7 | + " Get the value of $PATH from a login shell. | |
8 | + " If your shell is not on this list, it may be just because we have not | |
9 | + " tested it. Try adding it to the list and see if it works. If so, | |
10 | + " please post a note to the vim-mac list! | |
11 | + if $SHELL =~ '/\(sh\|csh\|bash\|tcsh\|zsh\)$' | |
12 | + let s:path = system("echo echo VIMPATH'${PATH}' | $SHELL -l") | |
13 | + let $PATH = matchstr(s:path, 'VIMPATH\zs.\{-}\ze\n') | |
14 | + endif | |
15 | + " Change directory on startup. | |
16 | + autocmd VimEnter * if getcwd()=="/" | if strlen(@%) | cd %:p:h | else | cd | endif | endif | |
17 | +" If running in a Terminal window, set the terminal type to allow syntax | |
18 | +" highlighting. | |
19 | +" else | |
20 | +" set term=ansi | |
21 | +endif |