Mercurial > vim
annotate src/gui_mac.c @ 20792:88d71b6fbae0 v8.2.0948
patch 8.2.0948: spell test fails
Commit: https://github.com/vim/vim/commit/d281b7c227bc4c78813fdc297ccee4b2cad7e605
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jun 10 16:39:32 2020 +0200
patch 8.2.0948: spell test fails
Problem: Spell test fails.
Solution: Adjust expected text of the prompt.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 10 Jun 2020 16:45:03 +0200 |
parents | c2570baa2e4c |
children | fcccc29bd386 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * GUI/Motif support by Robert Webb | |
5 * Macintosh port by Dany St-Amant | |
6 * and Axel Kielhorn | |
1106 | 7 * Port to MPW by Bernhard Pruemmer |
7 | 8 * Initial Carbon port by Ammon Skidmore |
9 * | |
10 * Do ":help uganda" in Vim to read copying and usage conditions. | |
11 * Do ":help credits" in Vim to see a list of people who contributed. | |
12 * See README.txt for an overview of the Vim source code. | |
13 */ | |
14 | |
15 /* | |
593 | 16 * NOTES: - Vim 7+ does not support classic MacOS. Please use Vim 6.x |
856 | 17 * - Comments mentioning FAQ refer to the book: |
18 * "Macworld Mac Programming FAQs" from "IDG Books" | |
7 | 19 */ |
20 | |
21 /* | |
22 * TODO: Change still to merge from the macvim's iDisk | |
23 * | |
24 * error_ga, mch_errmsg, Navigation's changes in gui_mch_browse | |
25 * uses of MenuItemIndex, changes in gui_mch_set_shellsize, | |
26 * ScrapManager error handling. | |
27 * Comments about function remaining to Carbonize. | |
28 * | |
29 */ | |
30 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
31 /* |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
32 * TODO (Jussi) |
1107 | 33 * * Clipboard does not work (at least some cases) |
34 * * ATSU font rendering has some problems | |
35 * * Investigate and remove dead code (there is still lots of that) | |
36 */ | |
7 | 37 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
38 #include <Devices.h> // included first to avoid CR problems |
7 | 39 #include "vim.h" |
40 | |
593 | 41 #define USE_CARBONIZED |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
42 #define USE_AEVENT // Enable AEVENT |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
43 #undef USE_OFFSETED_WINDOW // Debugging feature: start Vim window OFFSETed |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
44 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
45 // Compile as CodeWarrior External Editor |
7 | 46 #if defined(FEAT_CW_EDITOR) && !defined(USE_AEVENT) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
47 # define USE_AEVENT // Need Apple Event Support |
7 | 48 #endif |
49 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
50 // Vim's Scrap flavor. |
9 | 51 #define VIMSCRAPFLAVOR 'VIM!' |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
52 #define SCRAPTEXTFLAVOR kScrapFlavorTypeUnicode |
9 | 53 |
7 | 54 static EventHandlerUPP mouseWheelHandlerUPP = NULL; |
593 | 55 SInt32 gMacSystemVersion; |
56 | |
766 | 57 #ifdef MACOS_CONVERT |
58 # define USE_CARBONKEYHANDLER | |
1562 | 59 |
60 static int im_is_active = FALSE; | |
13950
741b1feeac9f
patch 8.0.1845: various comment updates needed, missing white space
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
61 # if 0 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
62 // TODO: Implement me! |
1562 | 63 static int im_start_row = 0; |
64 static int im_start_col = 0; | |
13950
741b1feeac9f
patch 8.0.1845: various comment updates needed, missing white space
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
65 # endif |
741b1feeac9f
patch 8.0.1845: various comment updates needed, missing white space
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
66 |
741b1feeac9f
patch 8.0.1845: various comment updates needed, missing white space
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
67 # define NR_ELEMS(x) (sizeof(x) / sizeof(x[0])) |
1562 | 68 |
69 static TSMDocumentID gTSMDocument; | |
70 | |
71 static void im_on_window_switch(int active); | |
168 | 72 static EventHandlerUPP keyEventHandlerUPP = NULL; |
1562 | 73 static EventHandlerUPP winEventHandlerUPP = NULL; |
74 | |
75 static pascal OSStatus gui_mac_handle_window_activate( | |
76 EventHandlerCallRef nextHandler, EventRef theEvent, void *data); | |
77 | |
78 static pascal OSStatus gui_mac_handle_text_input( | |
79 EventHandlerCallRef nextHandler, EventRef theEvent, void *data); | |
80 | |
81 static pascal OSStatus gui_mac_update_input_area( | |
82 EventHandlerCallRef nextHandler, EventRef theEvent); | |
83 | |
84 static pascal OSStatus gui_mac_unicode_key_event( | |
85 EventHandlerCallRef nextHandler, EventRef theEvent); | |
86 | |
168 | 87 #endif |
88 | |
7 | 89 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
90 // Include some file. TODO: move into os_mac.h |
7 | 91 #include <Menus.h> |
92 #include <Resources.h> | |
93 #include <Processes.h> | |
94 #ifdef USE_AEVENT | |
95 # include <AppleEvents.h> | |
96 # include <AERegistry.h> | |
97 #endif | |
98 # include <Gestalt.h> | |
99 #if UNIVERSAL_INTERFACES_VERSION >= 0x0330 | |
100 # include <ControlDefinitions.h> | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
101 # include <Navigation.h> // Navigation only part of ?? |
7 | 102 #endif |
103 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
104 // Help Manager (balloon.h, HM prefixed functions) are not supported |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
105 // under Carbon (Jussi) |
593 | 106 # if 0 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
107 // New Help Interface for Mac, not implemented yet. |
593 | 108 # include <MacHelp.h> |
109 # endif | |
7 | 110 |
111 /* | |
593 | 112 * These seem to be rectangle options. Why are they not found in |
113 * headers? (Jussi) | |
7 | 114 */ |
115 #define kNothing 0 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
116 #define kCreateEmpty 2 //1 |
7 | 117 #define kCreateRect 2 |
118 #define kDestroy 3 | |
119 | |
120 /* | |
121 * Dany: Don't like those... | |
122 */ | |
123 #define topLeft(r) (((Point*)&(r))[0]) | |
124 #define botRight(r) (((Point*)&(r))[1]) | |
125 | |
126 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
127 // Time of last mouse click, to detect double-click |
7 | 128 static long lastMouseTick = 0; |
129 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
130 // ??? |
7 | 131 static RgnHandle cursorRgn; |
132 static RgnHandle dragRgn; | |
133 static Rect dragRect; | |
134 static short dragRectEnbl; | |
135 static short dragRectControl; | |
136 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
137 // This variable is set when waiting for an event, which is the only moment |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
138 // scrollbar dragging can be done directly. It's not allowed while commands |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
139 // are executed, because it may move the cursor and that may cause unexpected |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
140 // problems (e.g., while ":s" is working). |
7 | 141 static int allow_scrollbar = FALSE; |
142 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
143 // Last mouse click caused contextual menu, (to provide proper release) |
7 | 144 static short clickIsPopup; |
145 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
146 // Feedback Action for Scrollbar |
7 | 147 ControlActionUPP gScrollAction; |
148 ControlActionUPP gScrollDrag; | |
149 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
150 // Keeping track of which scrollbar is being dragged |
7 | 151 static ControlHandle dragged_sb = NULL; |
152 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
153 // Vector of char_u --> control index for hotkeys in dialogs |
1572 | 154 static short *gDialogHotKeys; |
155 | |
13 | 156 static struct |
157 { | |
158 FMFontFamily family; | |
159 FMFontSize size; | |
160 FMFontStyle style; | |
161 Boolean isPanelVisible; | |
162 } gFontPanelInfo = { 0, 0, 0, false }; | |
593 | 163 |
766 | 164 #ifdef MACOS_CONVERT |
168 | 165 # define USE_ATSUI_DRAWING |
1562 | 166 int p_macatsui_last; |
168 | 167 ATSUStyle gFontStyle; |
1562 | 168 ATSUStyle gWideFontStyle; |
168 | 169 Boolean gIsFontFallbackSet; |
2327
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
170 UInt32 useAntialias_cached = 0x0; |
168 | 171 #endif |
172 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
173 // Colors Macros |
7 | 174 #define RGB(r,g,b) ((r) << 16) + ((g) << 8) + (b) |
175 #define Red(c) ((c & 0x00FF0000) >> 16) | |
176 #define Green(c) ((c & 0x0000FF00) >> 8) | |
177 #define Blue(c) ((c & 0x000000FF) >> 0) | |
178 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
179 // Key mapping |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
180 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
181 #define vk_Esc 0x35 // -> 1B |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
182 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
183 #define vk_F1 0x7A // -> 10 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
184 #define vk_F2 0x78 //0x63 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
185 #define vk_F3 0x63 //0x76 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
186 #define vk_F4 0x76 //0x60 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
187 #define vk_F5 0x60 //0x61 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
188 #define vk_F6 0x61 //0x62 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
189 #define vk_F7 0x62 //0x63 ? |
7 | 190 #define vk_F8 0x64 |
191 #define vk_F9 0x65 | |
192 #define vk_F10 0x6D | |
193 #define vk_F11 0x67 | |
194 #define vk_F12 0x6F | |
195 #define vk_F13 0x69 | |
196 #define vk_F14 0x6B | |
197 #define vk_F15 0x71 | |
198 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
199 #define vk_Clr 0x47 // -> 1B (ESC) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
200 #define vk_Enter 0x4C // -> 03 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
201 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
202 #define vk_Space 0x31 // -> 20 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
203 #define vk_Tab 0x30 // -> 09 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
204 #define vk_Return 0x24 // -> 0D |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
205 // This is wrong for OSX, what is it for? |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
206 #define vk_Delete 0X08 // -> 08 BackSpace |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
207 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
208 #define vk_Help 0x72 // -> 05 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
209 #define vk_Home 0x73 // -> 01 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
210 #define vk_PageUp 0x74 // -> 0D |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
211 #define vk_FwdDelete 0x75 // -> 7F |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
212 #define vk_End 0x77 // -> 04 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
213 #define vk_PageDown 0x79 // -> 0C |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
214 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
215 #define vk_Up 0x7E // -> 1E |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
216 #define vk_Down 0x7D // -> 1F |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
217 #define vk_Left 0x7B // -> 1C |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
218 #define vk_Right 0x7C // -> 1D |
7 | 219 |
220 #define vk_Undo vk_F1 | |
221 #define vk_Cut vk_F2 | |
222 #define vk_Copy vk_F3 | |
223 #define vk_Paste vk_F4 | |
224 #define vk_PrintScreen vk_F13 | |
225 #define vk_SCrollLock vk_F14 | |
226 #define vk_Pause vk_F15 | |
227 #define vk_NumLock vk_Clr | |
228 #define vk_Insert vk_Help | |
229 | |
230 #define KeySym char | |
231 | |
232 static struct | |
233 { | |
234 KeySym key_sym; | |
235 char_u vim_code0; | |
236 char_u vim_code1; | |
237 } special_keys[] = | |
238 { | |
239 {vk_Up, 'k', 'u'}, | |
240 {vk_Down, 'k', 'd'}, | |
241 {vk_Left, 'k', 'l'}, | |
242 {vk_Right, 'k', 'r'}, | |
243 | |
244 {vk_F1, 'k', '1'}, | |
245 {vk_F2, 'k', '2'}, | |
246 {vk_F3, 'k', '3'}, | |
247 {vk_F4, 'k', '4'}, | |
248 {vk_F5, 'k', '5'}, | |
249 {vk_F6, 'k', '6'}, | |
250 {vk_F7, 'k', '7'}, | |
251 {vk_F8, 'k', '8'}, | |
252 {vk_F9, 'k', '9'}, | |
253 {vk_F10, 'k', ';'}, | |
254 | |
255 {vk_F11, 'F', '1'}, | |
256 {vk_F12, 'F', '2'}, | |
257 {vk_F13, 'F', '3'}, | |
258 {vk_F14, 'F', '4'}, | |
259 {vk_F15, 'F', '5'}, | |
260 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
261 // {XK_Help, '%', '1'}, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
262 // {XK_Undo, '&', '8'}, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
263 // {XK_BackSpace, 'k', 'b'}, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
264 // {vk_Delete, 'k', 'b'}, |
7 | 265 {vk_Insert, 'k', 'I'}, |
266 {vk_FwdDelete, 'k', 'D'}, | |
267 {vk_Home, 'k', 'h'}, | |
268 {vk_End, '@', '7'}, | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
269 // {XK_Prior, 'k', 'P'}, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
270 // {XK_Next, 'k', 'N'}, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
271 // {XK_Print, '%', '9'}, |
7 | 272 |
273 {vk_PageUp, 'k', 'P'}, | |
274 {vk_PageDown, 'k', 'N'}, | |
275 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
276 // End of list marker: |
7 | 277 {(KeySym)0, 0, 0} |
278 }; | |
279 | |
280 /* | |
281 * ------------------------------------------------------------ | |
282 * Forward declaration (for those needed) | |
283 * ------------------------------------------------------------ | |
284 */ | |
285 | |
286 #ifdef USE_AEVENT | |
9 | 287 OSErr HandleUnusedParms(const AppleEvent *theAEvent); |
7 | 288 #endif |
289 | |
1106 | 290 #ifdef FEAT_GUI_TABLINE |
291 static void initialise_tabline(void); | |
292 static WindowRef drawer = NULL; // TODO: put into gui.h | |
293 #endif | |
294 | |
1562 | 295 #ifdef USE_ATSUI_DRAWING |
296 static void gui_mac_set_font_attributes(GuiFont font); | |
297 #endif | |
298 | |
7 | 299 /* |
300 * ------------------------------------------------------------ | |
301 * Conversion Utility | |
302 * ------------------------------------------------------------ | |
303 */ | |
304 | |
305 /* | |
306 * C2Pascal_save | |
307 * | |
308 * Allocate memory and convert the C-String passed in | |
309 * into a pascal string | |
310 * | |
311 */ | |
312 | |
593 | 313 char_u * |
314 C2Pascal_save(char_u *Cstring) | |
7 | 315 { |
316 char_u *PascalString; | |
317 int len; | |
318 | |
319 if (Cstring == NULL) | |
320 return NULL; | |
321 | |
322 len = STRLEN(Cstring); | |
323 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
324 if (len > 255) // Truncate if necessary |
7 | 325 len = 255; |
326 | |
327 PascalString = alloc(len + 1); | |
328 if (PascalString != NULL) | |
329 { | |
330 mch_memmove(PascalString + 1, Cstring, len); | |
331 PascalString[0] = len; | |
332 } | |
333 | |
334 return PascalString; | |
335 } | |
336 | |
337 /* | |
338 * C2Pascal_save_and_remove_backslash | |
339 * | |
340 * Allocate memory and convert the C-String passed in | |
341 * into a pascal string. Also remove the backslash at the same time | |
342 * | |
343 */ | |
344 | |
593 | 345 char_u * |
346 C2Pascal_save_and_remove_backslash(char_u *Cstring) | |
7 | 347 { |
348 char_u *PascalString; | |
349 int len; | |
350 char_u *p, *c; | |
351 | |
352 len = STRLEN(Cstring); | |
353 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
354 if (len > 255) // Truncate if necessary |
7 | 355 len = 255; |
356 | |
357 PascalString = alloc(len + 1); | |
358 if (PascalString != NULL) | |
359 { | |
360 for (c = Cstring, p = PascalString+1, len = 0; (*c != 0) && (len < 255); c++) | |
361 { | |
362 if ((*c == '\\') && (c[1] != 0)) | |
363 c++; | |
364 *p = *c; | |
365 p++; | |
366 len++; | |
367 } | |
368 PascalString[0] = len; | |
369 } | |
370 | |
371 return PascalString; | |
372 } | |
373 | |
374 /* | |
375 * Convert the modifiers of an Event into vim's modifiers (mouse) | |
376 */ | |
377 | |
378 int_u | |
379 EventModifiers2VimMouseModifiers(EventModifiers macModifiers) | |
380 { | |
381 int_u vimModifiers = 0x00; | |
382 | |
383 if (macModifiers & (shiftKey | rightShiftKey)) | |
384 vimModifiers |= MOUSE_SHIFT; | |
385 if (macModifiers & (controlKey | rightControlKey)) | |
386 vimModifiers |= MOUSE_CTRL; | |
387 if (macModifiers & (optionKey | rightOptionKey)) | |
388 vimModifiers |= MOUSE_ALT; | |
389 #if 0 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
390 // Not yet supported |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
391 if (macModifiers & (cmdKey)) // There's no rightCmdKey |
7 | 392 vimModifiers |= MOUSE_CMD; |
393 #endif | |
394 return (vimModifiers); | |
395 } | |
396 | |
397 /* | |
398 * Convert the modifiers of an Event into vim's modifiers (keys) | |
399 */ | |
400 | |
401 static int_u | |
402 EventModifiers2VimModifiers(EventModifiers macModifiers) | |
403 { | |
404 int_u vimModifiers = 0x00; | |
405 | |
406 if (macModifiers & (shiftKey | rightShiftKey)) | |
407 vimModifiers |= MOD_MASK_SHIFT; | |
408 if (macModifiers & (controlKey | rightControlKey)) | |
409 vimModifiers |= MOD_MASK_CTRL; | |
410 if (macModifiers & (optionKey | rightOptionKey)) | |
411 vimModifiers |= MOD_MASK_ALT; | |
412 #ifdef USE_CMD_KEY | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
413 if (macModifiers & (cmdKey)) // There's no rightCmdKey |
7 | 414 vimModifiers |= MOD_MASK_CMD; |
415 #endif | |
416 return (vimModifiers); | |
417 } | |
418 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
419 /* |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
420 * Convert a string representing a point size into pixels. The string should |
7 | 421 * be a positive decimal number, with an optional decimal point (eg, "12", or |
422 * "10.5"). The pixel value is returned, and a pointer to the next unconverted | |
423 * character is stored in *end. The flag "vertical" says whether this | |
424 * calculation is for a vertical (height) size or a horizontal (width) one. | |
425 * | |
426 * From gui_w48.c | |
427 */ | |
428 static int | |
429 points_to_pixels(char_u *str, char_u **end, int vertical) | |
430 { | |
431 int pixels; | |
432 int points = 0; | |
433 int divisor = 0; | |
434 | |
435 while (*str) | |
436 { | |
437 if (*str == '.' && divisor == 0) | |
438 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
439 // Start keeping a divisor, for later |
7 | 440 divisor = 1; |
441 continue; | |
442 } | |
443 | |
444 if (!isdigit(*str)) | |
445 break; | |
446 | |
447 points *= 10; | |
448 points += *str - '0'; | |
449 divisor *= 10; | |
450 | |
451 ++str; | |
452 } | |
453 | |
454 if (divisor == 0) | |
455 divisor = 1; | |
456 | |
457 pixels = points/divisor; | |
458 *end = str; | |
459 return pixels; | |
460 } | |
461 | |
766 | 462 #ifdef MACOS_CONVERT |
168 | 463 /* |
464 * Deletes all traces of any Windows-style mnemonic text (including any | |
465 * parentheses) from a menu item and returns the cleaned menu item title. | |
466 * The caller is responsible for releasing the returned string. | |
467 */ | |
468 static CFStringRef | |
593 | 469 menu_title_removing_mnemonic(vimmenu_T *menu) |
168 | 470 { |
471 CFStringRef name; | |
472 size_t menuTitleLen; | |
473 CFIndex displayLen; | |
474 CFRange mnemonicStart; | |
475 CFRange mnemonicEnd; | |
476 CFMutableStringRef cleanedName; | |
477 | |
478 menuTitleLen = STRLEN(menu->dname); | |
1621 | 479 name = (CFStringRef) mac_enc_to_cfstring(menu->dname, menuTitleLen); |
168 | 480 |
481 if (name) | |
482 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
483 // Simple mnemonic-removal algorithm, assumes single parenthesized |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
484 // mnemonic character towards the end of the menu text |
168 | 485 mnemonicStart = CFStringFind(name, CFSTR("("), kCFCompareBackwards); |
486 displayLen = CFStringGetLength(name); | |
487 | |
488 if (mnemonicStart.location != kCFNotFound | |
489 && (mnemonicStart.location + 2) < displayLen | |
490 && CFStringGetCharacterAtIndex(name, | |
491 mnemonicStart.location + 1) == (UniChar)menu->mnemonic) | |
492 { | |
493 if (CFStringFindWithOptions(name, CFSTR(")"), | |
494 CFRangeMake(mnemonicStart.location + 1, | |
495 displayLen - mnemonicStart.location - 1), | |
496 kCFCompareBackwards, &mnemonicEnd) && | |
497 (mnemonicStart.location + 2) == mnemonicEnd.location) | |
498 { | |
499 cleanedName = CFStringCreateMutableCopy(NULL, 0, name); | |
500 if (cleanedName) | |
501 { | |
502 CFStringDelete(cleanedName, | |
503 CFRangeMake(mnemonicStart.location, | |
504 mnemonicEnd.location + 1 - | |
505 mnemonicStart.location)); | |
506 | |
507 CFRelease(name); | |
508 name = cleanedName; | |
509 } | |
510 } | |
511 } | |
512 } | |
513 | |
514 return name; | |
515 } | |
516 #endif | |
517 | |
7 | 518 /* |
519 * Convert a list of FSSpec aliases into a list of fullpathname | |
520 * character strings. | |
521 */ | |
522 | |
593 | 523 char_u ** |
524 new_fnames_from_AEDesc(AEDesc *theList, long *numFiles, OSErr *error) | |
7 | 525 { |
526 char_u **fnames = NULL; | |
527 OSErr newError; | |
528 long fileCount; | |
529 FSSpec fileToOpen; | |
530 long actualSize; | |
531 AEKeyword dummyKeyword; | |
532 DescType dummyType; | |
533 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
534 // Get number of files in list |
7 | 535 *error = AECountItems(theList, numFiles); |
536 if (*error) | |
1107 | 537 return fnames; |
7 | 538 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
539 // Allocate the pointer list |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
540 fnames = ALLOC_MULT(char_u *, *numFiles); |
7 | 541 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
542 // Empty out the list |
7 | 543 for (fileCount = 0; fileCount < *numFiles; fileCount++) |
544 fnames[fileCount] = NULL; | |
545 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
546 // Scan the list of FSSpec |
7 | 547 for (fileCount = 1; fileCount <= *numFiles; fileCount++) |
548 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
549 // Get the alias for the nth file, convert to an FSSpec |
7 | 550 newError = AEGetNthPtr(theList, fileCount, typeFSS, |
551 &dummyKeyword, &dummyType, | |
552 (Ptr) &fileToOpen, sizeof(FSSpec), &actualSize); | |
553 if (newError) | |
554 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
555 // Caller is able to clean up |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
556 // TODO: Should be clean up or not? For safety. |
1107 | 557 return fnames; |
7 | 558 } |
559 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
560 // Convert the FSSpec to a pathname |
9 | 561 fnames[fileCount - 1] = FullPathFromFSSpec_save(fileToOpen); |
7 | 562 } |
563 | |
564 return (fnames); | |
565 } | |
566 | |
567 /* | |
568 * ------------------------------------------------------------ | |
569 * CodeWarrior External Editor Support | |
570 * ------------------------------------------------------------ | |
571 */ | |
572 #ifdef FEAT_CW_EDITOR | |
573 | |
574 /* | |
575 * Handle the Window Search event from CodeWarrior | |
576 * | |
577 * Description | |
578 * ----------- | |
579 * | |
580 * The IDE sends the Window Search AppleEvent to the editor when it | |
581 * needs to know whether a particular file is open in the editor. | |
582 * | |
583 * Event Reply | |
584 * ----------- | |
585 * | |
586 * None. Put data in the location specified in the structure received. | |
587 * | |
588 * Remarks | |
589 * ------- | |
590 * | |
591 * When the editor receives this event, determine whether the specified | |
592 * file is open. If it is, return the modification date/time for that file | |
593 * in the appropriate location specified in the structure. If the file is | |
9 | 594 * not opened, put the value fnfErr(file not found) in that location. |
7 | 595 * |
596 */ | |
597 | |
598 typedef struct WindowSearch WindowSearch; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
599 struct WindowSearch // for handling class 'KAHL', event 'SRCH', keyDirectObject typeChar |
7 | 600 { |
601 FSSpec theFile; // identifies the file | |
602 long *theDate; // where to put the modification date/time | |
603 }; | |
604 | |
9 | 605 pascal OSErr |
593 | 606 Handle_KAHL_SRCH_AE( |
607 const AppleEvent *theAEvent, | |
608 AppleEvent *theReply, | |
609 long refCon) | |
7 | 610 { |
611 OSErr error = noErr; | |
612 buf_T *buf; | |
613 int foundFile = false; | |
614 DescType typeCode; | |
615 WindowSearch SearchData; | |
616 Size actualSize; | |
617 | |
618 error = AEGetParamPtr(theAEvent, keyDirectObject, typeChar, &typeCode, (Ptr) &SearchData, sizeof(WindowSearch), &actualSize); | |
619 if (error) | |
1107 | 620 return error; |
7 | 621 |
9 | 622 error = HandleUnusedParms(theAEvent); |
7 | 623 if (error) |
1107 | 624 return error; |
7 | 625 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
626 FOR_ALL_BUFFERS(buf) |
7 | 627 if (buf->b_ml.ml_mfp != NULL |
628 && SearchData.theFile.parID == buf->b_FSSpec.parID | |
629 && SearchData.theFile.name[0] == buf->b_FSSpec.name[0] | |
630 && STRNCMP(SearchData.theFile.name, buf->b_FSSpec.name, buf->b_FSSpec.name[0] + 1) == 0) | |
631 { | |
632 foundFile = true; | |
633 break; | |
634 } | |
635 | |
636 if (foundFile == false) | |
637 *SearchData.theDate = fnfErr; | |
638 else | |
639 *SearchData.theDate = buf->b_mtime; | |
640 | |
641 return error; | |
642 }; | |
643 | |
644 /* | |
645 * Handle the Modified (from IDE to Editor) event from CodeWarrior | |
646 * | |
647 * Description | |
648 * ----------- | |
649 * | |
650 * The IDE sends this event to the external editor when it wants to | |
651 * know which files that are open in the editor have been modified. | |
652 * | |
653 * Parameters None. | |
654 * ---------- | |
655 * | |
656 * Event Reply | |
657 * ----------- | |
658 * The reply for this event is: | |
659 * | |
660 * keyDirectObject typeAEList required | |
661 * each element in the list is a structure of typeChar | |
662 * | |
663 * Remarks | |
664 * ------- | |
665 * | |
666 * When building the reply event, include one element in the list for | |
667 * each open file that has been modified. | |
668 * | |
669 */ | |
670 | |
671 typedef struct ModificationInfo ModificationInfo; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
672 struct ModificationInfo // for replying to class 'KAHL', event 'MOD ', keyDirectObject typeAEList |
7 | 673 { |
674 FSSpec theFile; // identifies the file | |
675 long theDate; // the date/time the file was last modified | |
676 short saved; // set this to zero when replying, unused | |
677 }; | |
678 | |
9 | 679 pascal OSErr |
593 | 680 Handle_KAHL_MOD_AE( |
681 const AppleEvent *theAEvent, | |
682 AppleEvent *theReply, | |
683 long refCon) | |
7 | 684 { |
685 OSErr error = noErr; | |
686 AEDescList replyList; | |
687 long numFiles; | |
688 ModificationInfo theFile; | |
689 buf_T *buf; | |
690 | |
691 theFile.saved = 0; | |
692 | |
9 | 693 error = HandleUnusedParms(theAEvent); |
7 | 694 if (error) |
1107 | 695 return error; |
7 | 696 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
697 // Send the reply |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
698 // replyObject.descriptorType = typeNull; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
699 // replyObject.dataHandle = nil; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
700 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
701 // AECreateDesc(typeChar, (Ptr)&title[1], title[0], &data) |
7 | 702 error = AECreateList(nil, 0, false, &replyList); |
703 if (error) | |
1107 | 704 return error; |
7 | 705 |
706 #if 0 | |
707 error = AECountItems(&replyList, &numFiles); | |
9 | 708 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
709 // AEPutKeyDesc(&replyList, keyAEPnject, &aDesc) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
710 // AEPutKeyPtr(&replyList, keyAEPosition, typeChar, (Ptr)&theType, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
711 // sizeof(DescType)) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
712 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
713 // AEPutDesc |
7 | 714 #endif |
715 | |
716 numFiles = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
717 FOR_ALL_BUFFERS(buf) |
7 | 718 if (buf->b_ml.ml_mfp != NULL) |
719 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
720 // Add this file to the list |
7 | 721 theFile.theFile = buf->b_FSSpec; |
722 theFile.theDate = buf->b_mtime; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
723 // theFile.theDate = time(NULL) & (time_t) 0xFFFFFFF0; |
9 | 724 error = AEPutPtr(&replyList, numFiles, typeChar, (Ptr) &theFile, sizeof(theFile)); |
7 | 725 }; |
726 | |
727 #if 0 | |
728 error = AECountItems(&replyList, &numFiles); | |
729 #endif | |
730 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
731 // We can add data only if something to reply |
9 | 732 error = AEPutParamDesc(theReply, keyDirectObject, &replyList); |
7 | 733 |
734 if (replyList.dataHandle) | |
735 AEDisposeDesc(&replyList); | |
736 | |
737 return error; | |
738 }; | |
739 | |
740 /* | |
741 * Handle the Get Text event from CodeWarrior | |
742 * | |
743 * Description | |
744 * ----------- | |
745 * | |
746 * The IDE sends the Get Text AppleEvent to the editor when it needs | |
747 * the source code from a file. For example, when the user issues a | |
748 * Check Syntax or Compile command, the compiler needs access to | |
749 * the source code contained in the file. | |
750 * | |
751 * Event Reply | |
752 * ----------- | |
753 * | |
754 * None. Put data in locations specified in the structure received. | |
755 * | |
756 * Remarks | |
757 * ------- | |
758 * | |
759 * When the editor receives this event, it must set the size of the handle | |
760 * in theText to fit the data in the file. It must then copy the entire | |
761 * contents of the specified file into the memory location specified in | |
762 * theText. | |
763 * | |
764 */ | |
765 | |
766 typedef struct CW_GetText CW_GetText; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
767 struct CW_GetText // for handling class 'KAHL', event 'GTTX', keyDirectObject typeChar |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
768 { |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
769 FSSpec theFile; // identifies the file |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
770 Handle theText; // the location where you return the text (must be resized properly) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
771 long *unused; // 0 (not used) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
772 long *theDate; // where to put the modification date/time |
7 | 773 }; |
774 | |
9 | 775 pascal OSErr |
593 | 776 Handle_KAHL_GTTX_AE( |
777 const AppleEvent *theAEvent, | |
778 AppleEvent *theReply, | |
779 long refCon) | |
7 | 780 { |
781 OSErr error = noErr; | |
782 buf_T *buf; | |
783 int foundFile = false; | |
784 DescType typeCode; | |
785 CW_GetText GetTextData; | |
786 Size actualSize; | |
787 char_u *line; | |
788 char_u *fullbuffer = NULL; | |
789 long linesize; | |
790 long lineStart; | |
791 long BufferSize; | |
792 long lineno; | |
793 | |
794 error = AEGetParamPtr(theAEvent, keyDirectObject, typeChar, &typeCode, (Ptr) &GetTextData, sizeof(GetTextData), &actualSize); | |
795 | |
796 if (error) | |
1107 | 797 return error; |
7 | 798 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
799 FOR_ALL_BUFFERS(buf) |
7 | 800 if (buf->b_ml.ml_mfp != NULL) |
801 if (GetTextData.theFile.parID == buf->b_FSSpec.parID) | |
802 { | |
803 foundFile = true; | |
804 break; | |
805 } | |
806 | |
807 if (foundFile) | |
808 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
809 BufferSize = 0; // GetHandleSize(GetTextData.theText); |
7 | 810 for (lineno = 0; lineno <= buf->b_ml.ml_line_count; lineno++) |
811 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
812 // Must use the right buffer |
7 | 813 line = ml_get_buf(buf, (linenr_T) lineno, FALSE); |
814 linesize = STRLEN(line) + 1; | |
815 lineStart = BufferSize; | |
816 BufferSize += linesize; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
817 // Resize handle to linesize+1 to include the linefeed |
9 | 818 SetHandleSize(GetTextData.theText, BufferSize); |
819 if (GetHandleSize(GetTextData.theText) != BufferSize) | |
7 | 820 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
821 break; // Simple handling for now |
7 | 822 } |
823 else | |
824 { | |
9 | 825 HLock(GetTextData.theText); |
7 | 826 fullbuffer = (char_u *) *GetTextData.theText; |
9 | 827 STRCPY((char_u *)(fullbuffer + lineStart), line); |
7 | 828 fullbuffer[BufferSize-1] = '\r'; |
9 | 829 HUnlock(GetTextData.theText); |
7 | 830 } |
831 } | |
832 if (fullbuffer != NULL) | |
833 { | |
9 | 834 HLock(GetTextData.theText); |
7 | 835 fullbuffer[BufferSize-1] = 0; |
9 | 836 HUnlock(GetTextData.theText); |
7 | 837 } |
838 if (foundFile == false) | |
839 *GetTextData.theDate = fnfErr; | |
840 else | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
841 // *GetTextData.theDate = time(NULL) & (time_t) 0xFFFFFFF0; |
7 | 842 *GetTextData.theDate = buf->b_mtime; |
843 } | |
9 | 844 |
845 error = HandleUnusedParms(theAEvent); | |
1107 | 846 |
847 return error; | |
7 | 848 } |
849 | |
850 /* | |
851 * | |
852 */ | |
853 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
854 /* |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
855 * Taken from MoreAppleEvents:ProcessHelpers |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
856 */ |
593 | 857 pascal OSErr |
858 FindProcessBySignature( | |
859 const OSType targetType, | |
860 const OSType targetCreator, | |
861 ProcessSerialNumberPtr psnPtr) | |
7 | 862 { |
863 OSErr anErr = noErr; | |
864 Boolean lookingForProcess = true; | |
865 | |
866 ProcessInfoRec infoRec; | |
867 | |
9 | 868 infoRec.processInfoLength = sizeof(ProcessInfoRec); |
7 | 869 infoRec.processName = nil; |
870 infoRec.processAppSpec = nil; | |
871 | |
872 psnPtr->lowLongOfPSN = kNoProcess; | |
873 psnPtr->highLongOfPSN = kNoProcess; | |
874 | |
9 | 875 while (lookingForProcess) |
7 | 876 { |
9 | 877 anErr = GetNextProcess(psnPtr); |
878 if (anErr != noErr) | |
7 | 879 lookingForProcess = false; |
880 else | |
881 { | |
9 | 882 anErr = GetProcessInformation(psnPtr, &infoRec); |
883 if ((anErr == noErr) | |
884 && (infoRec.processType == targetType) | |
885 && (infoRec.processSignature == targetCreator)) | |
7 | 886 lookingForProcess = false; |
887 } | |
888 } | |
889 | |
890 return anErr; | |
891 }//end FindProcessBySignature | |
892 | |
9 | 893 void |
894 Send_KAHL_MOD_AE(buf_T *buf) | |
7 | 895 { |
9 | 896 OSErr anErr = noErr; |
897 AEDesc targetAppDesc = { typeNull, nil }; | |
7 | 898 ProcessSerialNumber psn = { kNoProcess, kNoProcess }; |
899 AppleEvent theReply = { typeNull, nil }; | |
900 AESendMode sendMode; | |
901 AppleEvent theEvent = {typeNull, nil }; | |
902 AEIdleUPP idleProcUPP = nil; | |
903 ModificationInfo ModData; | |
904 | |
905 | |
9 | 906 anErr = FindProcessBySignature('APPL', 'CWIE', &psn); |
907 if (anErr == noErr) | |
7 | 908 { |
9 | 909 anErr = AECreateDesc(typeProcessSerialNumber, &psn, |
910 sizeof(ProcessSerialNumber), &targetAppDesc); | |
911 | |
912 if (anErr == noErr) | |
7 | 913 { |
914 anErr = AECreateAppleEvent( 'KAHL', 'MOD ', &targetAppDesc, | |
915 kAutoGenerateReturnID, kAnyTransactionID, &theEvent); | |
916 } | |
917 | |
9 | 918 AEDisposeDesc(&targetAppDesc); |
7 | 919 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
920 // Add the parms |
7 | 921 ModData.theFile = buf->b_FSSpec; |
922 ModData.theDate = buf->b_mtime; | |
923 | |
924 if (anErr == noErr) | |
9 | 925 anErr = AEPutParamPtr(&theEvent, keyDirectObject, typeChar, &ModData, sizeof(ModData)); |
926 | |
927 if (idleProcUPP == nil) | |
7 | 928 sendMode = kAENoReply; |
929 else | |
930 sendMode = kAEWaitReply; | |
931 | |
9 | 932 if (anErr == noErr) |
933 anErr = AESend(&theEvent, &theReply, sendMode, kAENormalPriority, kNoTimeOut, idleProcUPP, nil); | |
934 if (anErr == noErr && sendMode == kAEWaitReply) | |
7 | 935 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
936 // anErr = AEHGetHandlerError(&theReply); |
7 | 937 } |
9 | 938 (void) AEDisposeDesc(&theReply); |
7 | 939 } |
940 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
941 #endif // FEAT_CW_EDITOR |
7 | 942 |
943 /* | |
944 * ------------------------------------------------------------ | |
945 * Apple Event Handling procedure | |
946 * ------------------------------------------------------------ | |
947 */ | |
948 #ifdef USE_AEVENT | |
949 | |
950 /* | |
951 * Handle the Unused parms of an AppleEvent | |
952 */ | |
953 | |
9 | 954 OSErr |
955 HandleUnusedParms(const AppleEvent *theAEvent) | |
7 | 956 { |
957 OSErr error; | |
958 long actualSize; | |
959 DescType dummyType; | |
960 AEKeyword missedKeyword; | |
961 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
962 // Get the "missed keyword" attribute from the AppleEvent. |
7 | 963 error = AEGetAttributePtr(theAEvent, keyMissedKeywordAttr, |
964 typeKeyword, &dummyType, | |
965 (Ptr)&missedKeyword, sizeof(missedKeyword), | |
966 &actualSize); | |
967 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
968 // If the descriptor isn't found, then we got the required parameters. |
7 | 969 if (error == errAEDescNotFound) |
970 { | |
971 error = noErr; | |
972 } | |
973 else | |
974 { | |
975 #if 0 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
976 // Why is this removed? |
7 | 977 error = errAEEventNotHandled; |
978 #endif | |
979 } | |
980 | |
981 return error; | |
982 } | |
983 | |
984 | |
985 /* | |
986 * Handle the ODoc AppleEvent | |
987 * | |
988 * Deals with all files dragged to the application icon. | |
989 * | |
990 */ | |
991 | |
992 typedef struct SelectionRange SelectionRange; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
993 struct SelectionRange // for handling kCoreClassEvent:kOpenDocuments:keyAEPosition typeChar |
7 | 994 { |
995 short unused1; // 0 (not used) | |
996 short lineNum; // line to select (<0 to specify range) | |
997 long startRange; // start of selection range (if line < 0) | |
998 long endRange; // end of selection range (if line < 0) | |
999 long unused2; // 0 (not used) | |
1000 long theDate; // modification date/time | |
1001 }; | |
1002 | |
14428
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1003 static long drop_numFiles; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1004 static short drop_gotPosition; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1005 static SelectionRange drop_thePosition; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1006 |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1007 static void |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1008 drop_callback(void *cookie UNUSED) |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1009 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1010 // TODO: Handle the goto/select line more cleanly |
14428
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1011 if ((drop_numFiles == 1) & (drop_gotPosition)) |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1012 { |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1013 if (drop_thePosition.lineNum >= 0) |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1014 { |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1015 lnum = drop_thePosition.lineNum + 1; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1016 // oap->motion_type = MLINE; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1017 // setpcmark(); |
14428
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1018 if (lnum < 1L) |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1019 lnum = 1L; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1020 else if (lnum > curbuf->b_ml.ml_line_count) |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1021 lnum = curbuf->b_ml.ml_line_count; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1022 curwin->w_cursor.lnum = lnum; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1023 curwin->w_cursor.col = 0; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1024 // beginline(BL_SOL | BL_FIX); |
14428
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1025 } |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1026 else |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1027 goto_byte(drop_thePosition.startRange + 1); |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1028 } |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1029 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1030 // Update the screen display |
14428
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1031 update_screen(NOT_VALID); |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1032 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1033 // Select the text if possible |
14428
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1034 if (drop_gotPosition) |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1035 { |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1036 VIsual_active = TRUE; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1037 VIsual_select = FALSE; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1038 VIsual = curwin->w_cursor; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1039 if (drop_thePosition.lineNum < 0) |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1040 { |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1041 VIsual_mode = 'v'; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1042 goto_byte(drop_thePosition.endRange); |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1043 } |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1044 else |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1045 { |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1046 VIsual_mode = 'V'; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1047 VIsual.col = 0; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1048 } |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1049 } |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1050 } |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1051 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1052 /* |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1053 * The IDE uses the optional keyAEPosition parameter to tell the ed- |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1054 * itor the selection range. If lineNum is zero or greater, scroll the text |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1055 * to the specified line. If lineNum is less than zero, use the values in |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1056 * startRange and endRange to select the specified characters. Scroll |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1057 * the text to display the selection. If lineNum, startRange, and |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1058 * endRange are all negative, there is no selection range specified. |
7 | 1059 */ |
9 | 1060 pascal OSErr |
1061 HandleODocAE(const AppleEvent *theAEvent, AppleEvent *theReply, long refCon) | |
7 | 1062 { |
1063 /* | |
1064 * TODO: Clean up the code with convert the AppleEvent into | |
1065 * a ":args" | |
1066 */ | |
1067 OSErr error = noErr; | |
1068 // OSErr firstError = noErr; | |
1069 // short numErrors = 0; | |
1070 AEDesc theList; | |
1071 DescType typeCode; | |
1072 long numFiles; | |
1073 // long fileCount; | |
1074 char_u **fnames; | |
1075 // char_u fname[256]; | |
1076 Size actualSize; | |
1077 SelectionRange thePosition; | |
1078 short gotPosition = false; | |
1079 long lnum; | |
1080 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1081 // the direct object parameter is the list of aliases to files (one or more) |
7 | 1082 error = AEGetParamDesc(theAEvent, keyDirectObject, typeAEList, &theList); |
1083 if (error) | |
1107 | 1084 return error; |
7 | 1085 |
1086 | |
1087 error = AEGetParamPtr(theAEvent, keyAEPosition, typeChar, &typeCode, (Ptr) &thePosition, sizeof(SelectionRange), &actualSize); | |
1088 if (error == noErr) | |
1089 gotPosition = true; | |
1090 if (error == errAEDescNotFound) | |
1091 error = noErr; | |
1092 if (error) | |
1107 | 1093 return error; |
7 | 1094 |
1095 /* | |
1096 error = AEGetParamDesc(theAEvent, keyAEPosition, typeChar, &thePosition); | |
1097 | |
1098 if (^error) then | |
1099 { | |
1100 if (thePosition.lineNum >= 0) | |
1101 { | |
1102 // Goto this line | |
1103 } | |
1104 else | |
1105 { | |
1106 // Set the range char wise | |
1107 } | |
1108 } | |
1109 */ | |
1110 | |
1111 reset_VIsual(); | |
1112 fnames = new_fnames_from_AEDesc(&theList, &numFiles, &error); | |
1113 | |
1114 if (error) | |
1115 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1116 // TODO: empty fnames[] first |
7 | 1117 vim_free(fnames); |
1118 return (error); | |
1119 } | |
1120 | |
1121 if (starting > 0) | |
1122 { | |
1123 int i; | |
1124 char_u *p; | |
1409 | 1125 int fnum = -1; |
7 | 1126 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1127 // these are the initial files dropped on the Vim icon |
7 | 1128 for (i = 0 ; i < numFiles; i++) |
1129 { | |
1130 if (ga_grow(&global_alist.al_ga, 1) == FAIL | |
1131 || (p = vim_strsave(fnames[i])) == NULL) | |
1132 mch_exit(2); | |
1133 else | |
1134 alist_add(&global_alist, p, 2); | |
1409 | 1135 if (fnum == -1) |
1136 fnum = GARGLIST[GARGCOUNT - 1].ae_fnum; | |
1137 } | |
1138 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1139 // If the file name was already in the buffer list we need to switch |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1140 // to it. |
1409 | 1141 if (curbuf->b_fnum != fnum) |
1142 { | |
1143 char_u cmd[30]; | |
1144 | |
1145 vim_snprintf((char *)cmd, 30, "silent %dbuffer", fnum); | |
1146 do_cmdline_cmd(cmd); | |
7 | 1147 } |
816 | 1148 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1149 // Change directory to the location of the first file. |
13170
6559e98f3e74
patch 8.0.1459: cannot handle change of directory
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
1150 if (GARGCOUNT > 0 |
6559e98f3e74
patch 8.0.1459: cannot handle change of directory
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
1151 && vim_chdirfile(alist_name(&GARGLIST[0]), "drop") == OK) |
816 | 1152 shorten_fnames(TRUE); |
1153 | |
7 | 1154 goto finished; |
1155 } | |
1156 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1157 // Handle the drop, :edit to get to the file |
14428
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1158 drop_numFiles = numFiles; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1159 drop_gotPosition = gotPosition; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1160 drop_thePosition = thePosition; |
aab5947be7c5
patch 8.1.0228: dropping files is ignored while Vim is busy
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1161 handle_drop(numFiles, fnames, FALSE, drop_callback, NULL); |
5735 | 1162 |
7 | 1163 setcursor(); |
1164 out_flush(); | |
1165 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1166 // Fake mouse event to wake from stall |
37 | 1167 PostEvent(mouseUp, 0); |
1168 | |
1107 | 1169 finished: |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1170 AEDisposeDesc(&theList); // dispose what we allocated |
7 | 1171 |
9 | 1172 error = HandleUnusedParms(theAEvent); |
1107 | 1173 return error; |
7 | 1174 } |
1175 | |
1176 /* | |
1177 * | |
1178 */ | |
9 | 1179 pascal OSErr |
593 | 1180 Handle_aevt_oapp_AE( |
1181 const AppleEvent *theAEvent, | |
1182 AppleEvent *theReply, | |
1183 long refCon) | |
7 | 1184 { |
1185 OSErr error = noErr; | |
1186 | |
9 | 1187 error = HandleUnusedParms(theAEvent); |
1107 | 1188 return error; |
7 | 1189 } |
1190 | |
1191 /* | |
1192 * | |
1193 */ | |
9 | 1194 pascal OSErr |
593 | 1195 Handle_aevt_quit_AE( |
1196 const AppleEvent *theAEvent, | |
1197 AppleEvent *theReply, | |
1198 long refCon) | |
7 | 1199 { |
1200 OSErr error = noErr; | |
1201 | |
9 | 1202 error = HandleUnusedParms(theAEvent); |
7 | 1203 if (error) |
1107 | 1204 return error; |
7 | 1205 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1206 // Need to fake a :confirm qa |
7 | 1207 do_cmdline_cmd((char_u *)"confirm qa"); |
1208 | |
1107 | 1209 return error; |
7 | 1210 } |
1211 | |
1212 /* | |
1213 * | |
1214 */ | |
9 | 1215 pascal OSErr |
593 | 1216 Handle_aevt_pdoc_AE( |
1217 const AppleEvent *theAEvent, | |
1218 AppleEvent *theReply, | |
1219 long refCon) | |
7 | 1220 { |
1221 OSErr error = noErr; | |
1222 | |
9 | 1223 error = HandleUnusedParms(theAEvent); |
1107 | 1224 |
1225 return error; | |
7 | 1226 } |
1227 | |
1228 /* | |
1229 * Handling of unknown AppleEvent | |
1230 * | |
1231 * (Just get rid of all the parms) | |
1232 */ | |
9 | 1233 pascal OSErr |
593 | 1234 Handle_unknown_AE( |
1235 const AppleEvent *theAEvent, | |
1236 AppleEvent *theReply, | |
1237 long refCon) | |
7 | 1238 { |
1239 OSErr error = noErr; | |
1240 | |
9 | 1241 error = HandleUnusedParms(theAEvent); |
1107 | 1242 |
1243 return error; | |
7 | 1244 } |
1245 | |
1246 | |
1247 /* | |
1248 * Install the various AppleEvent Handlers | |
1249 */ | |
9 | 1250 OSErr |
1251 InstallAEHandlers(void) | |
7 | 1252 { |
1253 OSErr error; | |
1254 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1255 // install open application handler |
7 | 1256 error = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, |
593 | 1257 NewAEEventHandlerUPP(Handle_aevt_oapp_AE), 0, false); |
7 | 1258 if (error) |
1259 return error; | |
1260 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1261 // install quit application handler |
7 | 1262 error = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, |
593 | 1263 NewAEEventHandlerUPP(Handle_aevt_quit_AE), 0, false); |
7 | 1264 if (error) |
1265 return error; | |
1266 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1267 // install open document handler |
7 | 1268 error = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, |
593 | 1269 NewAEEventHandlerUPP(HandleODocAE), 0, false); |
7 | 1270 if (error) |
1271 return error; | |
1272 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1273 // install print document handler |
7 | 1274 error = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, |
593 | 1275 NewAEEventHandlerUPP(Handle_aevt_pdoc_AE), 0, false); |
7 | 1276 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1277 // Install Core Suite |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1278 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1279 error = AEInstallEventHandler(kAECoreSuite, kAEClone, |
593 | 1280 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1281 |
1282 error = AEInstallEventHandler(kAECoreSuite, kAEClose, | |
593 | 1283 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1284 |
1285 error = AEInstallEventHandler(kAECoreSuite, kAECountElements, | |
593 | 1286 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1287 |
1288 error = AEInstallEventHandler(kAECoreSuite, kAECreateElement, | |
593 | 1289 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1290 |
1291 error = AEInstallEventHandler(kAECoreSuite, kAEDelete, | |
593 | 1292 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1293 |
1294 error = AEInstallEventHandler(kAECoreSuite, kAEDoObjectsExist, | |
593 | 1295 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1296 |
1297 error = AEInstallEventHandler(kAECoreSuite, kAEGetData, | |
593 | 1298 NewAEEventHandlerUPP(Handle_unknown_AE), kAEGetData, false); |
7 | 1299 |
1300 error = AEInstallEventHandler(kAECoreSuite, kAEGetDataSize, | |
593 | 1301 NewAEEventHandlerUPP(Handle_unknown_AE), kAEGetDataSize, false); |
7 | 1302 |
1303 error = AEInstallEventHandler(kAECoreSuite, kAEGetClassInfo, | |
593 | 1304 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1305 |
1306 error = AEInstallEventHandler(kAECoreSuite, kAEGetEventInfo, | |
593 | 1307 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1308 |
1309 error = AEInstallEventHandler(kAECoreSuite, kAEMove, | |
593 | 1310 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1311 |
1312 error = AEInstallEventHandler(kAECoreSuite, kAESave, | |
593 | 1313 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
7 | 1314 |
1315 error = AEInstallEventHandler(kAECoreSuite, kAESetData, | |
593 | 1316 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1317 #endif |
7 | 1318 |
1319 #ifdef FEAT_CW_EDITOR | |
1320 /* | |
1321 * Bind codewarrior support handlers | |
1322 */ | |
1323 error = AEInstallEventHandler('KAHL', 'GTTX', | |
593 | 1324 NewAEEventHandlerUPP(Handle_KAHL_GTTX_AE), 0, false); |
7 | 1325 if (error) |
1326 return error; | |
1327 error = AEInstallEventHandler('KAHL', 'SRCH', | |
593 | 1328 NewAEEventHandlerUPP(Handle_KAHL_SRCH_AE), 0, false); |
7 | 1329 if (error) |
1330 return error; | |
1331 error = AEInstallEventHandler('KAHL', 'MOD ', | |
593 | 1332 NewAEEventHandlerUPP(Handle_KAHL_MOD_AE), 0, false); |
7 | 1333 #endif |
1334 | |
1335 return error; | |
1336 | |
1337 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1338 #endif // USE_AEVENT |
7 | 1339 |
13 | 1340 |
1341 /* | |
1342 * Callback function, installed by InstallFontPanelHandler(), below, | |
1343 * to handle Font Panel events. | |
1344 */ | |
1345 static OSStatus | |
593 | 1346 FontPanelHandler( |
1347 EventHandlerCallRef inHandlerCallRef, | |
1348 EventRef inEvent, | |
1349 void *inUserData) | |
13 | 1350 { |
1351 if (GetEventKind(inEvent) == kEventFontPanelClosed) | |
1352 { | |
1353 gFontPanelInfo.isPanelVisible = false; | |
1354 return noErr; | |
1355 } | |
1356 | |
1357 if (GetEventKind(inEvent) == kEventFontSelection) | |
1358 { | |
1359 OSStatus status; | |
1360 FMFontFamily newFamily; | |
1361 FMFontSize newSize; | |
1362 FMFontStyle newStyle; | |
1363 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1364 // Retrieve the font family ID number. |
13 | 1365 status = GetEventParameter(inEvent, kEventParamFMFontFamily, |
1366 /*inDesiredType=*/typeFMFontFamily, /*outActualType=*/NULL, | |
1367 /*inBufferSize=*/sizeof(FMFontFamily), /*outActualSize=*/NULL, | |
1368 &newFamily); | |
1369 if (status == noErr) | |
1370 gFontPanelInfo.family = newFamily; | |
1371 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1372 // Retrieve the font size. |
13 | 1373 status = GetEventParameter(inEvent, kEventParamFMFontSize, |
1374 typeFMFontSize, NULL, sizeof(FMFontSize), NULL, &newSize); | |
1375 if (status == noErr) | |
1376 gFontPanelInfo.size = newSize; | |
1377 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1378 // Retrieve the font style (bold, etc.). Currently unused. |
13 | 1379 status = GetEventParameter(inEvent, kEventParamFMFontStyle, |
1380 typeFMFontStyle, NULL, sizeof(FMFontStyle), NULL, &newStyle); | |
1381 if (status == noErr) | |
1382 gFontPanelInfo.style = newStyle; | |
1383 } | |
1384 return noErr; | |
1385 } | |
1386 | |
1387 | |
1388 static void | |
593 | 1389 InstallFontPanelHandler(void) |
13 | 1390 { |
1391 EventTypeSpec eventTypes[2]; | |
1392 EventHandlerUPP handlerUPP; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1393 // EventHandlerRef handlerRef; |
13 | 1394 |
1395 eventTypes[0].eventClass = kEventClassFont; | |
1396 eventTypes[0].eventKind = kEventFontSelection; | |
1397 eventTypes[1].eventClass = kEventClassFont; | |
1398 eventTypes[1].eventKind = kEventFontPanelClosed; | |
1399 | |
1400 handlerUPP = NewEventHandlerUPP(FontPanelHandler); | |
1401 | |
1402 InstallApplicationEventHandler(handlerUPP, /*numTypes=*/2, eventTypes, | |
1403 /*userData=*/NULL, /*handlerRef=*/NULL); | |
1404 } | |
1405 | |
1406 | |
1407 /* | |
1408 * Fill the buffer pointed to by outName with the name and size | |
1409 * of the font currently selected in the Font Panel. | |
1410 */ | |
168 | 1411 #define FONT_STYLE_BUFFER_SIZE 32 |
13 | 1412 static void |
501 | 1413 GetFontPanelSelection(char_u *outName) |
13 | 1414 { |
168 | 1415 Str255 buf; |
1416 ByteCount fontNameLen = 0; | |
1417 ATSUFontID fid; | |
1418 char_u styleString[FONT_STYLE_BUFFER_SIZE]; | |
13 | 1419 |
1420 if (!outName) | |
1421 return; | |
1422 | |
168 | 1423 if (FMGetFontFamilyName(gFontPanelInfo.family, buf) == noErr) |
1424 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1425 // Canonicalize localized font names |
168 | 1426 if (FMGetFontFromFontFamilyInstance(gFontPanelInfo.family, |
1427 gFontPanelInfo.style, &fid, NULL) != noErr) | |
1428 return; | |
1429 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1430 // Request font name with Mac encoding (otherwise we could |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1431 // get an unwanted utf-16 name) |
168 | 1432 if (ATSUFindFontName(fid, kFontFullName, kFontMacintoshPlatform, |
1433 kFontNoScriptCode, kFontNoLanguageCode, | |
501 | 1434 255, (char *)outName, &fontNameLen, NULL) != noErr) |
168 | 1435 return; |
1436 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1437 // Only encode font size, because style (bold, italic, etc) is |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1438 // already part of the font full name |
501 | 1439 vim_snprintf((char *)styleString, FONT_STYLE_BUFFER_SIZE, ":h%d", |
168 | 1440 gFontPanelInfo.size/*, |
1441 ((gFontPanelInfo.style & bold)!=0 ? ":b" : ""), | |
1442 ((gFontPanelInfo.style & italic)!=0 ? ":i" : ""), | |
1443 ((gFontPanelInfo.style & underline)!=0 ? ":u" : "")*/); | |
1444 | |
1445 if ((fontNameLen + STRLEN(styleString)) < 255) | |
1446 STRCPY(outName + fontNameLen, styleString); | |
1447 } | |
1448 else | |
1449 { | |
501 | 1450 *outName = NUL; |
168 | 1451 } |
13 | 1452 } |
1453 | |
1454 | |
7 | 1455 /* |
1456 * ------------------------------------------------------------ | |
1457 * Unfiled yet | |
1458 * ------------------------------------------------------------ | |
1459 */ | |
1460 | |
1461 /* | |
1462 * gui_mac_get_menu_item_index | |
1463 * | |
4352 | 1464 * Returns the index inside the menu where |
7 | 1465 */ |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1466 short // Should we return MenuItemIndex? |
593 | 1467 gui_mac_get_menu_item_index(vimmenu_T *pMenu) |
7 | 1468 { |
1469 short index; | |
1470 short itemIndex = -1; | |
1471 vimmenu_T *pBrother; | |
1472 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1473 // Only menu without parent are the: |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1474 // -menu in the menubar |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1475 // -popup menu |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1476 // -toolbar (guess) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1477 // |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1478 // Which are not items anyway. |
7 | 1479 if (pMenu->parent) |
1480 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1481 // Start from the Oldest Brother |
7 | 1482 pBrother = pMenu->parent->children; |
1483 index = 1; | |
1484 while ((pBrother) && (itemIndex == -1)) | |
1485 { | |
1486 if (pBrother == pMenu) | |
1487 itemIndex = index; | |
1488 index++; | |
1489 pBrother = pBrother->next; | |
1490 } | |
1491 } | |
1492 return itemIndex; | |
1493 } | |
1494 | |
1495 static vimmenu_T * | |
593 | 1496 gui_mac_get_vim_menu(short menuID, short itemIndex, vimmenu_T *pMenu) |
7 | 1497 { |
1498 short index; | |
1499 vimmenu_T *pChildMenu; | |
1500 vimmenu_T *pElder = pMenu->parent; | |
1501 | |
1502 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1503 // Only menu without parent are the: |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1504 // -menu in the menubar |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1505 // -popup menu |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1506 // -toolbar (guess) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1507 // |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1508 // Which are not items anyway. |
7 | 1509 |
1510 if ((pElder) && (pElder->submenu_id == menuID)) | |
1511 { | |
1512 for (index = 1; (index != itemIndex) && (pMenu != NULL); index++) | |
1513 pMenu = pMenu->next; | |
1514 } | |
1515 else | |
1516 { | |
1517 for (; pMenu != NULL; pMenu = pMenu->next) | |
1518 { | |
1519 if (pMenu->children != NULL) | |
1520 { | |
1521 pChildMenu = gui_mac_get_vim_menu | |
1522 (menuID, itemIndex, pMenu->children); | |
1523 if (pChildMenu) | |
1524 { | |
1525 pMenu = pChildMenu; | |
1526 break; | |
1527 } | |
1528 } | |
1529 } | |
1530 } | |
1531 return pMenu; | |
1532 } | |
1533 | |
1534 /* | |
1535 * ------------------------------------------------------------ | |
1536 * MacOS Feedback procedures | |
1537 * ------------------------------------------------------------ | |
1538 */ | |
1539 pascal | |
1540 void | |
9 | 1541 gui_mac_drag_thumb(ControlHandle theControl, short partCode) |
7 | 1542 { |
1543 scrollbar_T *sb; | |
1544 int value, dragging; | |
1545 ControlHandle theControlToUse; | |
1546 int dont_scroll_save = dont_scroll; | |
1547 | |
1548 theControlToUse = dragged_sb; | |
1549 | |
9 | 1550 sb = gui_find_scrollbar((long) GetControlReference(theControlToUse)); |
7 | 1551 |
1552 if (sb == NULL) | |
1553 return; | |
1554 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1555 // Need to find value by diff between Old Poss New Pos |
9 | 1556 value = GetControl32BitValue(theControlToUse); |
7 | 1557 dragging = (partCode != 0); |
1558 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1559 // When "allow_scrollbar" is FALSE still need to remember the new |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1560 // position, but don't actually scroll by setting "dont_scroll". |
7 | 1561 dont_scroll = !allow_scrollbar; |
1562 gui_drag_scrollbar(sb, value, dragging); | |
1563 dont_scroll = dont_scroll_save; | |
1564 } | |
1565 | |
1566 pascal | |
1567 void | |
9 | 1568 gui_mac_scroll_action(ControlHandle theControl, short partCode) |
7 | 1569 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1570 // TODO: have live support |
7 | 1571 scrollbar_T *sb, *sb_info; |
1572 long data; | |
1573 long value; | |
1574 int page; | |
1575 int dragging = FALSE; | |
1576 int dont_scroll_save = dont_scroll; | |
1577 | |
9 | 1578 sb = gui_find_scrollbar((long)GetControlReference(theControl)); |
7 | 1579 |
1580 if (sb == NULL) | |
1581 return; | |
1582 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1583 if (sb->wp != NULL) // Left or right scrollbar |
7 | 1584 { |
1585 /* | |
1586 * Careful: need to get scrollbar info out of first (left) scrollbar | |
1587 * for window, but keep real scrollbar too because we must pass it to | |
1588 * gui_drag_scrollbar(). | |
1589 */ | |
1590 sb_info = &sb->wp->w_scrollbars[0]; | |
1591 | |
1592 if (sb_info->size > 5) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1593 page = sb_info->size - 2; // use two lines of context |
7 | 1594 else |
1595 page = sb_info->size; | |
1596 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1597 else // Bottom scrollbar |
7 | 1598 { |
1599 sb_info = sb; | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
1600 page = curwin->w_width - 5; |
7 | 1601 } |
1602 | |
1603 switch (partCode) | |
1604 { | |
1605 case kControlUpButtonPart: data = -1; break; | |
1606 case kControlDownButtonPart: data = 1; break; | |
1607 case kControlPageDownPart: data = page; break; | |
1608 case kControlPageUpPart: data = -page; break; | |
1609 default: data = 0; break; | |
1610 } | |
1611 | |
1612 value = sb_info->value + data; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1613 // if (value > sb_info->max) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1614 // value = sb_info->max; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1615 // else if (value < 0) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1616 // value = 0; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1617 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1618 // When "allow_scrollbar" is FALSE still need to remember the new |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1619 // position, but don't actually scroll by setting "dont_scroll". |
7 | 1620 dont_scroll = !allow_scrollbar; |
1621 gui_drag_scrollbar(sb, value, dragging); | |
1622 dont_scroll = dont_scroll_save; | |
1623 | |
1624 out_flush(); | |
1625 gui_mch_set_scrollbar_thumb(sb, value, sb_info->size, sb_info->max); | |
1626 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1627 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1628 if (sb_info->wp != NULL) |
7 | 1629 { |
1630 win_T *wp; | |
1631 int sb_num; | |
1632 | |
1633 sb_num = 0; | |
1634 for (wp = firstwin; wp != sb->wp && wp != NULL; wp = W_NEXT(wp)) | |
1635 sb_num++; | |
1636 | |
1637 if (wp != NULL) | |
1638 { | |
1639 current_scrollbar = sb_num; | |
1640 scrollbar_value = value; | |
1641 gui_do_scroll(); | |
1642 gui_mch_set_scrollbar_thumb(sb, value, sb_info->size, sb_info->max); | |
1643 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1644 } |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1645 #endif |
7 | 1646 } |
1647 | |
1648 /* | |
1649 * ------------------------------------------------------------ | |
1650 * MacOS Click Handling procedures | |
1651 * ------------------------------------------------------------ | |
1652 */ | |
1653 | |
1654 | |
1655 /* | |
1656 * Handle a click inside the window, it may happens in the | |
1657 * scrollbar or the contents. | |
1658 * | |
1659 * TODO: Add support for potential TOOLBAR | |
1660 */ | |
1661 void | |
593 | 1662 gui_mac_doInContentClick(EventRecord *theEvent, WindowPtr whichWindow) |
7 | 1663 { |
1664 Point thePoint; | |
1665 int_u vimModifiers; | |
1666 short thePortion; | |
1667 ControlHandle theControl; | |
1668 int vimMouseButton; | |
1669 short dblClick; | |
1670 | |
1671 thePoint = theEvent->where; | |
9 | 1672 GlobalToLocal(&thePoint); |
1673 SelectWindow(whichWindow); | |
1674 | |
1675 thePortion = FindControl(thePoint, whichWindow, &theControl); | |
7 | 1676 |
1677 if (theControl != NUL) | |
1678 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1679 // We hit a scrollbar |
7 | 1680 |
1681 if (thePortion != kControlIndicatorPart) | |
1682 { | |
1683 dragged_sb = theControl; | |
1684 TrackControl(theControl, thePoint, gScrollAction); | |
1685 dragged_sb = NULL; | |
1686 } | |
1687 else | |
1688 { | |
1689 dragged_sb = theControl; | |
1690 #if 1 | |
1691 TrackControl(theControl, thePoint, gScrollDrag); | |
1692 #else | |
1693 TrackControl(theControl, thePoint, NULL); | |
1694 #endif | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1695 // pass 0 as the part to tell gui_mac_drag_thumb, that the mouse |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1696 // button has been released |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1697 gui_mac_drag_thumb(theControl, 0); // Should it be thePortion ? (Dany) |
7 | 1698 dragged_sb = NULL; |
1699 } | |
1700 } | |
1701 else | |
1702 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1703 // We are inside the contents |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1704 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1705 // Convert the CTRL, OPTION, SHIFT and CMD key |
7 | 1706 vimModifiers = EventModifiers2VimMouseModifiers(theEvent->modifiers); |
1707 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1708 // Defaults to MOUSE_LEFT as there's only one mouse button |
7 | 1709 vimMouseButton = MOUSE_LEFT; |
1710 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1711 // Convert the CTRL_MOUSE_LEFT to MOUSE_RIGHT |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1712 // TODO: NEEDED? |
7 | 1713 clickIsPopup = FALSE; |
1714 | |
1292 | 1715 if (mouse_model_popup() && IsShowContextualMenuClick(theEvent)) |
1716 { | |
1717 vimMouseButton = MOUSE_RIGHT; | |
1718 vimModifiers &= ~MOUSE_CTRL; | |
1719 clickIsPopup = TRUE; | |
1720 } | |
7 | 1721 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1722 // Is it a double click ? |
7 | 1723 dblClick = ((theEvent->when - lastMouseTick) < GetDblTime()); |
1724 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1725 // Send the mouse click to Vim |
7 | 1726 gui_send_mouse_event(vimMouseButton, thePoint.h, |
1727 thePoint.v, dblClick, vimModifiers); | |
1728 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1729 // Create the rectangle around the cursor to detect |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1730 // the mouse dragging |
7 | 1731 #if 0 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1732 // TODO: Do we need to this even for the contextual menu? |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1733 // It may be require for popup_setpos, but for popup? |
7 | 1734 if (vimMouseButton == MOUSE_LEFT) |
1735 #endif | |
1736 { | |
9 | 1737 SetRect(&dragRect, FILL_X(X_2_COL(thePoint.h)), |
7 | 1738 FILL_Y(Y_2_ROW(thePoint.v)), |
1739 FILL_X(X_2_COL(thePoint.h)+1), | |
1740 FILL_Y(Y_2_ROW(thePoint.v)+1)); | |
1741 | |
1742 dragRectEnbl = TRUE; | |
1743 dragRectControl = kCreateRect; | |
1744 } | |
1745 } | |
1746 } | |
1747 | |
1748 /* | |
1749 * Handle the click in the titlebar (to move the window) | |
1750 */ | |
1751 void | |
593 | 1752 gui_mac_doInDragClick(Point where, WindowPtr whichWindow) |
7 | 1753 { |
1754 Rect movingLimits; | |
1755 Rect *movingLimitsPtr = &movingLimits; | |
1756 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1757 // TODO: may try to prevent move outside screen? |
9 | 1758 movingLimitsPtr = GetRegionBounds(GetGrayRgn(), &movingLimits); |
1759 DragWindow(whichWindow, where, movingLimitsPtr); | |
7 | 1760 } |
1761 | |
1762 /* | |
1763 * Handle the click in the grow box | |
1764 */ | |
1765 void | |
593 | 1766 gui_mac_doInGrowClick(Point where, WindowPtr whichWindow) |
7 | 1767 { |
1768 | |
1769 long newSize; | |
1770 unsigned short newWidth; | |
1771 unsigned short newHeight; | |
1772 Rect resizeLimits; | |
1773 Rect *resizeLimitsPtr = &resizeLimits; | |
1774 Rect NewContentRect; | |
1775 | |
9 | 1776 resizeLimitsPtr = GetRegionBounds(GetGrayRgn(), &resizeLimits); |
7 | 1777 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1778 // Set the minimum size |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1779 // TODO: Should this come from Vim? |
7 | 1780 resizeLimits.top = 100; |
1781 resizeLimits.left = 100; | |
1782 | |
1783 newSize = ResizeWindow(whichWindow, where, &resizeLimits, &NewContentRect); | |
1784 newWidth = NewContentRect.right - NewContentRect.left; | |
1785 newHeight = NewContentRect.bottom - NewContentRect.top; | |
1786 gui_resize_shell(newWidth, newHeight); | |
1787 gui_mch_set_bg_color(gui.back_pixel); | |
812 | 1788 gui_set_shellsize(TRUE, FALSE, RESIZE_BOTH); |
7 | 1789 } |
1790 | |
1791 /* | |
1792 * Handle the click in the zoom box | |
1793 */ | |
1794 static void | |
593 | 1795 gui_mac_doInZoomClick(EventRecord *theEvent, WindowPtr whichWindow) |
7 | 1796 { |
1797 Rect r; | |
1798 Point p; | |
1799 short thePart; | |
1800 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1801 // ideal width is current |
7 | 1802 p.h = Columns * gui.char_width + 2 * gui.border_offset; |
1803 if (gui.which_scrollbars[SBAR_LEFT]) | |
1804 p.h += gui.scrollbar_width; | |
1805 if (gui.which_scrollbars[SBAR_RIGHT]) | |
1806 p.h += gui.scrollbar_width; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1807 // ideal height is as high as we can get |
7 | 1808 p.v = 15 * 1024; |
1809 | |
1810 thePart = IsWindowInStandardState(whichWindow, &p, &r) | |
1811 ? inZoomIn : inZoomOut; | |
1812 | |
1813 if (!TrackBox(whichWindow, theEvent->where, thePart)) | |
1814 return; | |
1815 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1816 // use returned width |
7 | 1817 p.h = r.right - r.left; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1818 // adjust returned height |
7 | 1819 p.v = r.bottom - r.top - 2 * gui.border_offset; |
1820 if (gui.which_scrollbars[SBAR_BOTTOM]) | |
1821 p.v -= gui.scrollbar_height; | |
1822 p.v -= p.v % gui.char_height; | |
1823 p.v += 2 * gui.border_width; | |
2869 | 1824 if (gui.which_scrollbars[SBAR_BOTTOM]) |
7 | 1825 p.v += gui.scrollbar_height; |
1826 | |
1827 ZoomWindowIdeal(whichWindow, thePart, &p); | |
1828 | |
1829 GetWindowBounds(whichWindow, kWindowContentRgn, &r); | |
1830 gui_resize_shell(r.right - r.left, r.bottom - r.top); | |
1831 gui_mch_set_bg_color(gui.back_pixel); | |
812 | 1832 gui_set_shellsize(TRUE, FALSE, RESIZE_BOTH); |
7 | 1833 } |
1834 | |
1835 /* | |
1836 * ------------------------------------------------------------ | |
1837 * MacOS Event Handling procedure | |
1838 * ------------------------------------------------------------ | |
1839 */ | |
1840 | |
1841 /* | |
1842 * Handle the Update Event | |
1843 */ | |
1844 | |
1845 void | |
593 | 1846 gui_mac_doUpdateEvent(EventRecord *event) |
7 | 1847 { |
1848 WindowPtr whichWindow; | |
1849 GrafPtr savePort; | |
1850 RgnHandle updateRgn; | |
1851 Rect updateRect; | |
1852 Rect *updateRectPtr; | |
1853 Rect rc; | |
1854 Rect growRect; | |
1855 RgnHandle saveRgn; | |
1856 | |
1857 | |
1858 updateRgn = NewRgn(); | |
1859 if (updateRgn == NULL) | |
1860 return; | |
1861 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1862 // This could be done by the caller as we |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1863 // don't require anything else out of the event |
7 | 1864 whichWindow = (WindowPtr) event->message; |
1865 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1866 // Save Current Port |
9 | 1867 GetPort(&savePort); |
7 | 1868 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1869 // Select the Window's Port |
9 | 1870 SetPortWindowPort(whichWindow); |
7 | 1871 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1872 // Let's update the window |
9 | 1873 BeginUpdate(whichWindow); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1874 // Redraw the biggest rectangle covering the area |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1875 // to be updated. |
7 | 1876 GetPortVisibleRegion(GetWindowPort(whichWindow), updateRgn); |
1877 # if 0 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1878 // Would be more appropriate to use the following but doesn't |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1879 // seem to work under MacOS X (Dany) |
7 | 1880 GetWindowRegion(whichWindow, kWindowUpdateRgn, updateRgn); |
1881 # endif | |
593 | 1882 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1883 // Use the HLock useless in Carbon? Is it harmful? |
9 | 1884 HLock((Handle) updateRgn); |
593 | 1885 |
9 | 1886 updateRectPtr = GetRegionBounds(updateRgn, &updateRect); |
7 | 1887 # if 0 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1888 // Code from original Carbon Port (using GetWindowRegion. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1889 // I believe the UpdateRgn is already in local (Dany) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1890 GlobalToLocal(&topLeft(updateRect)); // preCarbon? |
7 | 1891 GlobalToLocal(&botRight(updateRect)); |
1892 # endif | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1893 // Update the content (i.e. the text) |
7 | 1894 gui_redraw(updateRectPtr->left, updateRectPtr->top, |
1895 updateRectPtr->right - updateRectPtr->left, | |
1896 updateRectPtr->bottom - updateRectPtr->top); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1897 // Clear the border areas if needed |
7 | 1898 gui_mch_set_bg_color(gui.back_pixel); |
1899 if (updateRectPtr->left < FILL_X(0)) | |
1900 { | |
9 | 1901 SetRect(&rc, 0, 0, FILL_X(0), FILL_Y(Rows)); |
1902 EraseRect(&rc); | |
7 | 1903 } |
1904 if (updateRectPtr->top < FILL_Y(0)) | |
1905 { | |
9 | 1906 SetRect(&rc, 0, 0, FILL_X(Columns), FILL_Y(0)); |
1907 EraseRect(&rc); | |
7 | 1908 } |
1909 if (updateRectPtr->right > FILL_X(Columns)) | |
1910 { | |
9 | 1911 SetRect(&rc, FILL_X(Columns), 0, |
7 | 1912 FILL_X(Columns) + gui.border_offset, FILL_Y(Rows)); |
9 | 1913 EraseRect(&rc); |
7 | 1914 } |
1915 if (updateRectPtr->bottom > FILL_Y(Rows)) | |
1916 { | |
9 | 1917 SetRect(&rc, 0, FILL_Y(Rows), FILL_X(Columns) + gui.border_offset, |
7 | 1918 FILL_Y(Rows) + gui.border_offset); |
9 | 1919 EraseRect(&rc); |
7 | 1920 } |
9 | 1921 HUnlock((Handle) updateRgn); |
1922 DisposeRgn(updateRgn); | |
7 | 1923 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1924 // Update scrollbars |
9 | 1925 DrawControls(whichWindow); |
7 | 1926 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1927 // Update the GrowBox |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1928 // Taken from FAQ 33-27 |
7 | 1929 saveRgn = NewRgn(); |
1930 GetWindowBounds(whichWindow, kWindowGrowRgn, &growRect); | |
9 | 1931 GetClip(saveRgn); |
1932 ClipRect(&growRect); | |
1933 DrawGrowIcon(whichWindow); | |
1934 SetClip(saveRgn); | |
1935 DisposeRgn(saveRgn); | |
1936 EndUpdate(whichWindow); | |
7 | 1937 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1938 // Restore original Port |
9 | 1939 SetPort(savePort); |
7 | 1940 } |
1941 | |
1942 /* | |
1943 * Handle the activate/deactivate event | |
1944 * (apply to a window) | |
1945 */ | |
1946 void | |
593 | 1947 gui_mac_doActivateEvent(EventRecord *event) |
7 | 1948 { |
1949 WindowPtr whichWindow; | |
1950 | |
1951 whichWindow = (WindowPtr) event->message; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1952 // Dim scrollbars |
1292 | 1953 if (whichWindow == gui.VimWindow) |
7 | 1954 { |
1562 | 1955 ControlRef rootControl; |
1956 GetRootControl(gui.VimWindow, &rootControl); | |
1957 if ((event->modifiers) & activeFlag) | |
1958 ActivateControl(rootControl); | |
1959 else | |
1960 DeactivateControl(rootControl); | |
7 | 1961 } |
1292 | 1962 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1963 // Activate |
1292 | 1964 gui_focus_change((event->modifiers) & activeFlag); |
7 | 1965 } |
1966 | |
1967 | |
1968 /* | |
1969 * Handle the suspend/resume event | |
1970 * (apply to the application) | |
1971 */ | |
1972 void | |
593 | 1973 gui_mac_doSuspendEvent(EventRecord *event) |
7 | 1974 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1975 // The frontmost application just changed |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1976 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1977 // NOTE: the suspend may happen before the deactivate |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1978 // seen on MacOS X |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1979 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1980 // May not need to change focus as the window will |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1981 // get an activate/deactivate event |
7 | 1982 if (event->message & 1) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1983 // Resume |
7 | 1984 gui_focus_change(TRUE); |
1985 else | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
1986 // Suspend |
7 | 1987 gui_focus_change(FALSE); |
1988 } | |
1989 | |
1990 /* | |
1991 * Handle the key | |
1992 */ | |
168 | 1993 #ifdef USE_CARBONKEYHANDLER |
1562 | 1994 static pascal OSStatus |
1995 gui_mac_handle_window_activate( | |
1996 EventHandlerCallRef nextHandler, | |
1997 EventRef theEvent, | |
1998 void *data) | |
1999 { | |
2000 UInt32 eventClass = GetEventClass(theEvent); | |
2001 UInt32 eventKind = GetEventKind(theEvent); | |
2002 | |
2003 if (eventClass == kEventClassWindow) | |
2004 { | |
2005 switch (eventKind) | |
2006 { | |
2007 case kEventWindowActivated: | |
2008 im_on_window_switch(TRUE); | |
2009 return noErr; | |
2010 | |
2011 case kEventWindowDeactivated: | |
2012 im_on_window_switch(FALSE); | |
2013 return noErr; | |
2014 } | |
2015 } | |
2016 | |
2017 return eventNotHandledErr; | |
2018 } | |
2019 | |
2020 static pascal OSStatus | |
2021 gui_mac_handle_text_input( | |
2022 EventHandlerCallRef nextHandler, | |
2023 EventRef theEvent, | |
2024 void *data) | |
2025 { | |
2026 UInt32 eventClass = GetEventClass(theEvent); | |
2027 UInt32 eventKind = GetEventKind(theEvent); | |
2028 | |
2029 if (eventClass != kEventClassTextInput) | |
2030 return eventNotHandledErr; | |
2031 | |
2032 if ((kEventTextInputUpdateActiveInputArea != eventKind) && | |
2033 (kEventTextInputUnicodeForKeyEvent != eventKind) && | |
2034 (kEventTextInputOffsetToPos != eventKind) && | |
2035 (kEventTextInputPosToOffset != eventKind) && | |
2036 (kEventTextInputGetSelectedText != eventKind)) | |
2037 return eventNotHandledErr; | |
2038 | |
2039 switch (eventKind) | |
2040 { | |
2041 case kEventTextInputUpdateActiveInputArea: | |
2042 return gui_mac_update_input_area(nextHandler, theEvent); | |
2043 case kEventTextInputUnicodeForKeyEvent: | |
2044 return gui_mac_unicode_key_event(nextHandler, theEvent); | |
2045 | |
2046 case kEventTextInputOffsetToPos: | |
2047 case kEventTextInputPosToOffset: | |
2048 case kEventTextInputGetSelectedText: | |
2049 break; | |
2050 } | |
2051 | |
2052 return eventNotHandledErr; | |
2053 } | |
2054 | |
2055 static pascal | |
2056 OSStatus gui_mac_update_input_area( | |
2057 EventHandlerCallRef nextHandler, | |
2058 EventRef theEvent) | |
2059 { | |
2060 return eventNotHandledErr; | |
2061 } | |
2062 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2063 static int dialog_busy = FALSE; // TRUE when gui_mch_dialog() wants the |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2064 // keys |
857 | 2065 |
168 | 2066 # define INLINE_KEY_BUFFER_SIZE 80 |
2067 static pascal OSStatus | |
1562 | 2068 gui_mac_unicode_key_event( |
593 | 2069 EventHandlerCallRef nextHandler, |
1562 | 2070 EventRef theEvent) |
168 | 2071 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2072 // Multibyte-friendly key event handler |
1012 | 2073 OSStatus err = -1; |
168 | 2074 UInt32 actualSize; |
2075 UniChar *text; | |
2076 char_u result[INLINE_KEY_BUFFER_SIZE]; | |
2077 short len = 0; | |
2078 UInt32 key_sym; | |
2079 char charcode; | |
2080 int key_char; | |
1012 | 2081 UInt32 modifiers, vimModifiers; |
168 | 2082 size_t encLen; |
2083 char_u *to = NULL; | |
2084 Boolean isSpecial = FALSE; | |
2085 int i; | |
1562 | 2086 EventRef keyEvent; |
168 | 2087 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2088 // Mask the mouse (as per user setting) |
168 | 2089 if (p_mh) |
2090 ObscureCursor(); | |
2091 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2092 // Don't use the keys when the dialog wants them. |
1012 | 2093 if (dialog_busy) |
1562 | 2094 return eventNotHandledErr; |
1012 | 2095 |
2096 if (noErr != GetEventParameter(theEvent, kEventParamTextInputSendText, | |
1562 | 2097 typeUnicodeText, NULL, 0, &actualSize, NULL)) |
2098 return eventNotHandledErr; | |
1012 | 2099 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
2100 text = alloc(actualSize); |
1012 | 2101 if (!text) |
1562 | 2102 return eventNotHandledErr; |
1012 | 2103 |
2104 err = GetEventParameter(theEvent, kEventParamTextInputSendText, | |
1562 | 2105 typeUnicodeText, NULL, actualSize, NULL, text); |
1012 | 2106 require_noerr(err, done); |
2107 | |
2108 err = GetEventParameter(theEvent, kEventParamTextInputSendKeyboardEvent, | |
1562 | 2109 typeEventRef, NULL, sizeof(EventRef), NULL, &keyEvent); |
1012 | 2110 require_noerr(err, done); |
2111 | |
2112 err = GetEventParameter(keyEvent, kEventParamKeyModifiers, | |
1562 | 2113 typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); |
1012 | 2114 require_noerr(err, done); |
2115 | |
2116 err = GetEventParameter(keyEvent, kEventParamKeyCode, | |
1562 | 2117 typeUInt32, NULL, sizeof(UInt32), NULL, &key_sym); |
1012 | 2118 require_noerr(err, done); |
2119 | |
2120 err = GetEventParameter(keyEvent, kEventParamKeyMacCharCodes, | |
1562 | 2121 typeChar, NULL, sizeof(char), NULL, &charcode); |
1012 | 2122 require_noerr(err, done); |
2123 | |
168 | 2124 #ifndef USE_CMD_KEY |
1012 | 2125 if (modifiers & cmdKey) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2126 goto done; // Let system handle Cmd+... |
168 | 2127 #endif |
1012 | 2128 |
2129 key_char = charcode; | |
2130 vimModifiers = EventModifiers2VimModifiers(modifiers); | |
2131 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2132 // Find the special key (eg., for cursor keys) |
1012 | 2133 if (actualSize <= sizeof(UniChar) && |
1562 | 2134 ((text[0] < 0x20) || (text[0] == 0x7f))) |
2135 { | |
2136 for (i = 0; special_keys[i].key_sym != (KeySym)0; ++i) | |
2137 if (special_keys[i].key_sym == key_sym) | |
2138 { | |
2139 key_char = TO_SPECIAL(special_keys[i].vim_code0, | |
2140 special_keys[i].vim_code1); | |
2141 key_char = simplify_key(key_char, | |
2142 (int *)&vimModifiers); | |
2143 isSpecial = TRUE; | |
2144 break; | |
2145 } | |
168 | 2146 } |
1012 | 2147 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2148 // Intercept CMD-. and CTRL-c |
1012 | 2149 if (((modifiers & controlKey) && key_char == 'c') || |
1562 | 2150 ((modifiers & cmdKey) && key_char == '.')) |
2151 got_int = TRUE; | |
1012 | 2152 |
2153 if (!isSpecial) | |
2154 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2155 // remove SHIFT for keys that are already shifted, e.g., |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2156 // '(' and '*' |
1562 | 2157 if (key_char < 0x100 && !isalpha(key_char) && isprint(key_char)) |
2158 vimModifiers &= ~MOD_MASK_SHIFT; | |
2159 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2160 // remove CTRL from keys that already have it |
1562 | 2161 if (key_char < 0x20) |
2162 vimModifiers &= ~MOD_MASK_CTRL; | |
2163 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2164 // don't process unicode characters here |
1562 | 2165 if (!IS_SPECIAL(key_char)) |
2166 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2167 // Following code to simplify and consolidate vimModifiers |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2168 // taken liberally from gui_w48.c |
1562 | 2169 key_char = simplify_key(key_char, (int *)&vimModifiers); |
2170 | |
20421
8590a462ad46
patch 8.2.0765: In the GUI can't use all the modifiers.
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2171 // Unify modifiers somewhat. No longer use ALT to set the 8th bit. |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
2172 key_char = extract_modifiers(key_char, (int *)&vimModifiers, |
20421
8590a462ad46
patch 8.2.0765: In the GUI can't use all the modifiers.
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2173 FALSE, NULL); |
1562 | 2174 if (key_char == CSI) |
2175 key_char = K_CSI; | |
2176 | |
2177 if (IS_SPECIAL(key_char)) | |
2178 isSpecial = TRUE; | |
2179 } | |
1012 | 2180 } |
2181 | |
2182 if (vimModifiers) | |
2183 { | |
1562 | 2184 result[len++] = CSI; |
2185 result[len++] = KS_MODIFIER; | |
2186 result[len++] = vimModifiers; | |
1012 | 2187 } |
2188 | |
2189 if (isSpecial && IS_SPECIAL(key_char)) | |
2190 { | |
1562 | 2191 result[len++] = CSI; |
2192 result[len++] = K_SECOND(key_char); | |
2193 result[len++] = K_THIRD(key_char); | |
1012 | 2194 } |
2195 else | |
2196 { | |
1562 | 2197 encLen = actualSize; |
2198 to = mac_utf16_to_enc(text, actualSize, &encLen); | |
2199 if (to) | |
2200 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2201 // This is basically add_to_input_buf_csi() |
1562 | 2202 for (i = 0; i < encLen && len < (INLINE_KEY_BUFFER_SIZE-1); ++i) |
2203 { | |
2204 result[len++] = to[i]; | |
2205 if (to[i] == CSI) | |
2206 { | |
2207 result[len++] = KS_EXTRA; | |
2208 result[len++] = (int)KE_CSI; | |
2209 } | |
2210 } | |
2211 vim_free(to); | |
2212 } | |
1012 | 2213 } |
2214 | |
2215 add_to_input_buf(result, len); | |
2216 err = noErr; | |
2217 | |
2218 done: | |
2219 vim_free(text); | |
2220 if (err == noErr) | |
2221 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2222 // Fake event to wake up WNE (required to get |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2223 // key repeat working |
1562 | 2224 PostEvent(keyUp, 0); |
2225 return noErr; | |
1012 | 2226 } |
2227 | |
2228 return eventNotHandledErr; | |
168 | 2229 } |
2230 #else | |
7 | 2231 void |
2232 gui_mac_doKeyEvent(EventRecord *theEvent) | |
2233 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2234 // TODO: add support for COMMAND KEY |
7 | 2235 long menu; |
2236 unsigned char string[20]; | |
2237 short num, i; | |
2238 short len = 0; | |
2239 KeySym key_sym; | |
2240 int key_char; | |
2241 int modifiers; | |
26 | 2242 int simplify = FALSE; |
7 | 2243 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2244 // Mask the mouse (as per user setting) |
7 | 2245 if (p_mh) |
2246 ObscureCursor(); | |
2247 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2248 // Get the key code and its ASCII representation |
7 | 2249 key_sym = ((theEvent->message & keyCodeMask) >> 8); |
2250 key_char = theEvent->message & charCodeMask; | |
2251 num = 1; | |
2252 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2253 // Intercept CTRL-C |
7 | 2254 if (theEvent->modifiers & controlKey) |
9 | 2255 { |
7 | 2256 if (key_char == Ctrl_C && ctrl_c_interrupts) |
2257 got_int = TRUE; | |
9 | 2258 else if ((theEvent->modifiers & ~(controlKey|shiftKey)) == 0 |
2259 && (key_char == '2' || key_char == '6')) | |
2260 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2261 // CTRL-^ and CTRL-@ don't work in the normal way. |
9 | 2262 if (key_char == '2') |
2263 key_char = Ctrl_AT; | |
2264 else | |
2265 key_char = Ctrl_HAT; | |
2266 theEvent->modifiers = 0; | |
2267 } | |
2268 } | |
7 | 2269 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2270 // Intercept CMD-. |
7 | 2271 if (theEvent->modifiers & cmdKey) |
2272 if (key_char == '.') | |
2273 got_int = TRUE; | |
2274 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2275 // Handle command key as per menu |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2276 // TODO: should override be allowed? Require YAO or could use 'winaltkey' |
7 | 2277 if (theEvent->modifiers & cmdKey) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2278 // Only accept CMD alone or with CAPLOCKS and the mouse button. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2279 // Why the mouse button? |
7 | 2280 if ((theEvent->modifiers & (~(cmdKey | btnState | alphaLock))) == 0) |
2281 { | |
2282 menu = MenuKey(key_char); | |
2283 if (HiWord(menu)) | |
2284 { | |
2285 gui_mac_handle_menu(menu); | |
2286 return; | |
2287 } | |
2288 } | |
2289 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2290 // Convert the modifiers |
7 | 2291 modifiers = EventModifiers2VimModifiers(theEvent->modifiers); |
2292 | |
2293 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2294 // Handle special keys. |
7 | 2295 #if 0 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2296 // Why has this been removed? |
7 | 2297 if (!(theEvent->modifiers & (cmdKey | controlKey | rightControlKey))) |
2298 #endif | |
2299 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2300 // Find the special key (for non-printable keyt_char) |
7 | 2301 if ((key_char < 0x20) || (key_char == 0x7f)) |
2302 for (i = 0; special_keys[i].key_sym != (KeySym)0; i++) | |
2303 if (special_keys[i].key_sym == key_sym) | |
2304 { | |
2305 # if 0 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2306 // We currently don't have not so special key |
7 | 2307 if (special_keys[i].vim_code1 == NUL) |
2308 key_char = special_keys[i].vim_code0; | |
2309 else | |
2310 # endif | |
9 | 2311 key_char = TO_SPECIAL(special_keys[i].vim_code0, |
2312 special_keys[i].vim_code1); | |
26 | 2313 simplify = TRUE; |
7 | 2314 break; |
2315 } | |
2316 } | |
2317 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2318 // For some keys the modifier is included in the char itself. |
26 | 2319 if (simplify || key_char == TAB || key_char == ' ') |
2320 key_char = simplify_key(key_char, &modifiers); | |
7 | 2321 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2322 // Add the modifier to the input bu if needed |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2323 // Do not want SHIFT-A or CTRL-A with modifier |
7 | 2324 if (!IS_SPECIAL(key_char) |
2325 && key_sym != vk_Space | |
2326 && key_sym != vk_Tab | |
2327 && key_sym != vk_Return | |
2328 && key_sym != vk_Enter | |
2329 && key_sym != vk_Esc) | |
2330 { | |
2331 #if 1 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2332 // Clear modifiers when only one modifier is set |
9 | 2333 if ((modifiers == MOD_MASK_SHIFT) |
2334 || (modifiers == MOD_MASK_CTRL) | |
2335 || (modifiers == MOD_MASK_ALT)) | |
7 | 2336 modifiers = 0; |
2337 #else | |
9 | 2338 if (modifiers & MOD_MASK_CTRL) |
7 | 2339 modifiers = modifiers & ~MOD_MASK_CTRL; |
9 | 2340 if (modifiers & MOD_MASK_ALT) |
7 | 2341 modifiers = modifiers & ~MOD_MASK_ALT; |
9 | 2342 if (modifiers & MOD_MASK_SHIFT) |
7 | 2343 modifiers = modifiers & ~MOD_MASK_SHIFT; |
2344 #endif | |
2345 } | |
9 | 2346 if (modifiers) |
7 | 2347 { |
9 | 2348 string[len++] = CSI; |
2349 string[len++] = KS_MODIFIER; | |
2350 string[len++] = modifiers; | |
7 | 2351 } |
2352 | |
9 | 2353 if (IS_SPECIAL(key_char)) |
7 | 2354 { |
9 | 2355 string[len++] = CSI; |
2356 string[len++] = K_SECOND(key_char); | |
2357 string[len++] = K_THIRD(key_char); | |
7 | 2358 } |
2359 else | |
2360 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2361 // Convert characters when needed (e.g., from MacRoman to latin1). |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2362 // This doesn't work for the NUL byte. |
9 | 2363 if (input_conv.vc_type != CONV_NONE && key_char > 0) |
7 | 2364 { |
2365 char_u from[2], *to; | |
2366 int l; | |
2367 | |
2368 from[0] = key_char; | |
2369 from[1] = NUL; | |
2370 l = 1; | |
2371 to = string_convert(&input_conv, from, &l); | |
2372 if (to != NULL) | |
2373 { | |
2374 for (i = 0; i < l && len < 19; i++) | |
2375 { | |
2376 if (to[i] == CSI) | |
2377 { | |
2378 string[len++] = KS_EXTRA; | |
2379 string[len++] = KE_CSI; | |
2380 } | |
2381 else | |
2382 string[len++] = to[i]; | |
2383 } | |
2384 vim_free(to); | |
2385 } | |
2386 else | |
2387 string[len++] = key_char; | |
2388 } | |
2389 else | |
2390 string[len++] = key_char; | |
2391 } | |
2392 | |
2393 if (len == 1 && string[0] == CSI) | |
2394 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2395 // Turn CSI into K_CSI. |
7 | 2396 string[ len++ ] = KS_EXTRA; |
2397 string[ len++ ] = KE_CSI; | |
2398 } | |
2399 | |
2400 add_to_input_buf(string, len); | |
2401 } | |
168 | 2402 #endif |
7 | 2403 |
2404 /* | |
2405 * Handle MouseClick | |
2406 */ | |
2407 void | |
593 | 2408 gui_mac_doMouseDownEvent(EventRecord *theEvent) |
7 | 2409 { |
2410 short thePart; | |
2411 WindowPtr whichWindow; | |
2412 | |
9 | 2413 thePart = FindWindow(theEvent->where, &whichWindow); |
7 | 2414 |
1106 | 2415 #ifdef FEAT_GUI_TABLINE |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2416 // prevent that the vim window size changes if it's activated by a |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2417 // click into the tab pane |
1106 | 2418 if (whichWindow == drawer) |
1562 | 2419 return; |
1106 | 2420 #endif |
2421 | |
7 | 2422 switch (thePart) |
2423 { | |
2424 case (inDesk): | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2425 // TODO: what to do? |
7 | 2426 break; |
2427 | |
2428 case (inMenuBar): | |
9 | 2429 gui_mac_handle_menu(MenuSelect(theEvent->where)); |
7 | 2430 break; |
2431 | |
2432 case (inContent): | |
9 | 2433 gui_mac_doInContentClick(theEvent, whichWindow); |
7 | 2434 break; |
2435 | |
2436 case (inDrag): | |
9 | 2437 gui_mac_doInDragClick(theEvent->where, whichWindow); |
7 | 2438 break; |
2439 | |
2440 case (inGrow): | |
9 | 2441 gui_mac_doInGrowClick(theEvent->where, whichWindow); |
7 | 2442 break; |
2443 | |
2444 case (inGoAway): | |
2445 if (TrackGoAway(whichWindow, theEvent->where)) | |
2446 gui_shell_closed(); | |
2447 break; | |
2448 | |
2449 case (inZoomIn): | |
2450 case (inZoomOut): | |
2451 gui_mac_doInZoomClick(theEvent, whichWindow); | |
2452 break; | |
2453 } | |
2454 } | |
2455 | |
2456 /* | |
2457 * Handle MouseMoved | |
2458 * [this event is a moving in and out of a region] | |
2459 */ | |
2460 void | |
593 | 2461 gui_mac_doMouseMovedEvent(EventRecord *event) |
7 | 2462 { |
2463 Point thePoint; | |
2464 int_u vimModifiers; | |
2465 | |
2466 thePoint = event->where; | |
9 | 2467 GlobalToLocal(&thePoint); |
7 | 2468 vimModifiers = EventModifiers2VimMouseModifiers(event->modifiers); |
2469 | |
2470 if (!Button()) | |
9 | 2471 gui_mouse_moved(thePoint.h, thePoint.v); |
7 | 2472 else |
2473 if (!clickIsPopup) | |
2474 gui_send_mouse_event(MOUSE_DRAG, thePoint.h, | |
2475 thePoint.v, FALSE, vimModifiers); | |
2476 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2477 // Reset the region from which we move in and out |
9 | 2478 SetRect(&dragRect, FILL_X(X_2_COL(thePoint.h)), |
7 | 2479 FILL_Y(Y_2_ROW(thePoint.v)), |
2480 FILL_X(X_2_COL(thePoint.h)+1), | |
2481 FILL_Y(Y_2_ROW(thePoint.v)+1)); | |
2482 | |
2483 if (dragRectEnbl) | |
2484 dragRectControl = kCreateRect; | |
2485 | |
2486 } | |
2487 | |
2488 /* | |
2489 * Handle the mouse release | |
2490 */ | |
2491 void | |
593 | 2492 gui_mac_doMouseUpEvent(EventRecord *theEvent) |
7 | 2493 { |
2494 Point thePoint; | |
2495 int_u vimModifiers; | |
2496 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2497 // TODO: Properly convert the Contextual menu mouse-up |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2498 // Potential source of the double menu |
7 | 2499 lastMouseTick = theEvent->when; |
2500 dragRectEnbl = FALSE; | |
2501 dragRectControl = kCreateEmpty; | |
2502 thePoint = theEvent->where; | |
9 | 2503 GlobalToLocal(&thePoint); |
7 | 2504 |
2505 vimModifiers = EventModifiers2VimMouseModifiers(theEvent->modifiers); | |
2506 if (clickIsPopup) | |
2507 { | |
2508 vimModifiers &= ~MOUSE_CTRL; | |
2509 clickIsPopup = FALSE; | |
2510 } | |
9 | 2511 gui_send_mouse_event(MOUSE_RELEASE, thePoint.h, thePoint.v, FALSE, vimModifiers); |
7 | 2512 } |
2513 | |
2514 static pascal OSStatus | |
2515 gui_mac_mouse_wheel(EventHandlerCallRef nextHandler, EventRef theEvent, | |
2516 void *data) | |
2517 { | |
2518 Point point; | |
2519 Rect bounds; | |
2520 UInt32 mod; | |
2521 SInt32 delta; | |
2522 int_u vim_mod; | |
939 | 2523 EventMouseWheelAxis axis; |
2524 | |
2525 if (noErr == GetEventParameter(theEvent, kEventParamMouseWheelAxis, | |
2526 typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis) | |
2527 && axis != kEventMouseWheelAxisY) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2528 goto bail; // Vim only does up-down scrolling |
7 | 2529 |
2530 if (noErr != GetEventParameter(theEvent, kEventParamMouseWheelDelta, | |
2531 typeSInt32, NULL, sizeof(SInt32), NULL, &delta)) | |
2532 goto bail; | |
2533 if (noErr != GetEventParameter(theEvent, kEventParamMouseLocation, | |
2534 typeQDPoint, NULL, sizeof(Point), NULL, &point)) | |
2535 goto bail; | |
2536 if (noErr != GetEventParameter(theEvent, kEventParamKeyModifiers, | |
2537 typeUInt32, NULL, sizeof(UInt32), NULL, &mod)) | |
2538 goto bail; | |
2539 | |
2540 vim_mod = 0; | |
2541 if (mod & shiftKey) | |
2542 vim_mod |= MOUSE_SHIFT; | |
2543 if (mod & controlKey) | |
2544 vim_mod |= MOUSE_CTRL; | |
2545 if (mod & optionKey) | |
2546 vim_mod |= MOUSE_ALT; | |
2547 | |
2548 if (noErr == GetWindowBounds(gui.VimWindow, kWindowContentRgn, &bounds)) | |
2549 { | |
2550 point.h -= bounds.left; | |
2551 point.v -= bounds.top; | |
2552 } | |
2553 | |
2554 gui_send_mouse_event((delta > 0) ? MOUSE_4 : MOUSE_5, | |
2555 point.h, point.v, FALSE, vim_mod); | |
2556 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2557 // post a bogus event to wake up WaitNextEvent |
1668 | 2558 PostEvent(keyUp, 0); |
2559 | |
7 | 2560 return noErr; |
2561 | |
1107 | 2562 bail: |
7 | 2563 /* |
2564 * when we fail give any additional callback handler a chance to perform | |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2565 * its actions |
7 | 2566 */ |
2567 return CallNextEventHandler(nextHandler, theEvent); | |
2568 } | |
2569 | |
2565
4b7929dad28a
Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
2570 void |
4b7929dad28a
Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
2571 gui_mch_mousehide(int hide) |
4b7929dad28a
Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
2572 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2573 // TODO |
2565
4b7929dad28a
Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
2574 } |
4b7929dad28a
Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents:
2338
diff
changeset
|
2575 |
7 | 2576 #if 0 |
2577 | |
2578 /* | |
2579 * This would be the normal way of invoking the contextual menu | |
2580 * but the Vim API doesn't seem to a support a request to get | |
2581 * the menu that we should display | |
2582 */ | |
2583 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
2584 gui_mac_handle_contextual_menu(EventRecord *event) |
7 | 2585 { |
2586 /* | |
2587 * Clone PopUp to use menu | |
2588 * Create a object descriptor for the current selection | |
2589 * Call the procedure | |
2590 */ | |
2591 | |
2592 // Call to Handle Popup | |
2593 OSStatus status = ContextualMenuSelect(CntxMenu, event->where, false, kCMHelpItemNoHelp, "", NULL, &CntxType, &CntxMenuID, &CntxMenuItem); | |
2594 | |
2595 if (status != noErr) | |
2596 return; | |
2597 | |
2598 if (CntxType == kCMMenuItemSelected) | |
2599 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2600 // Handle the menu CntxMenuID, CntxMenuItem |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2601 // The submenu can be handle directly by gui_mac_handle_menu |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2602 // But what about the current menu, is the many changed by ContextualMenuSelect |
9 | 2603 gui_mac_handle_menu((CntxMenuID << 16) + CntxMenuItem); |
7 | 2604 } |
2605 else if (CntxMenuID == kCMShowHelpSelected) | |
2606 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2607 // Should come up with the help |
7 | 2608 } |
2609 | |
2610 } | |
2611 #endif | |
2612 | |
2613 /* | |
2614 * Handle menubar selection | |
2615 */ | |
2616 void | |
593 | 2617 gui_mac_handle_menu(long menuChoice) |
7 | 2618 { |
2619 short menu = HiWord(menuChoice); | |
2620 short item = LoWord(menuChoice); | |
2621 vimmenu_T *theVimMenu = root_menu; | |
2622 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2623 if (menu == 256) // TODO: use constant or gui.xyz |
7 | 2624 { |
2625 if (item == 1) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2626 gui_mch_beep(); // TODO: Popup dialog or do :intro |
7 | 2627 } |
2628 else if (item != 0) | |
2629 { | |
2630 theVimMenu = gui_mac_get_vim_menu(menu, item, root_menu); | |
2631 | |
2632 if (theVimMenu) | |
2633 gui_menu_cb(theVimMenu); | |
2634 } | |
9 | 2635 HiliteMenu(0); |
7 | 2636 } |
2637 | |
2638 /* | |
2639 * Dispatch the event to proper handler | |
2640 */ | |
2641 | |
2642 void | |
593 | 2643 gui_mac_handle_event(EventRecord *event) |
7 | 2644 { |
2645 OSErr error; | |
2646 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2647 // Handle contextual menu right now (if needed) |
1292 | 2648 if (IsShowContextualMenuClick(event)) |
2649 { | |
7 | 2650 # if 0 |
1562 | 2651 gui_mac_handle_contextual_menu(event); |
7 | 2652 # else |
1562 | 2653 gui_mac_doMouseDownEvent(event); |
7 | 2654 # endif |
1562 | 2655 return; |
1292 | 2656 } |
7 | 2657 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2658 // Handle normal event |
7 | 2659 switch (event->what) |
2660 { | |
168 | 2661 #ifndef USE_CARBONKEYHANDLER |
7 | 2662 case (keyDown): |
2663 case (autoKey): | |
9 | 2664 gui_mac_doKeyEvent(event); |
7 | 2665 break; |
168 | 2666 #endif |
7 | 2667 case (keyUp): |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2668 // We don't care about when the key is released |
7 | 2669 break; |
2670 | |
2671 case (mouseDown): | |
2672 gui_mac_doMouseDownEvent(event); | |
2673 break; | |
2674 | |
2675 case (mouseUp): | |
2676 gui_mac_doMouseUpEvent(event); | |
2677 break; | |
2678 | |
2679 case (updateEvt): | |
9 | 2680 gui_mac_doUpdateEvent(event); |
7 | 2681 break; |
2682 | |
2683 case (diskEvt): | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2684 // We don't need special handling for disk insertion |
7 | 2685 break; |
2686 | |
2687 case (activateEvt): | |
9 | 2688 gui_mac_doActivateEvent(event); |
7 | 2689 break; |
2690 | |
2691 case (osEvt): | |
2692 switch ((event->message >> 24) & 0xFF) | |
2693 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2694 case (0xFA): // mouseMovedMessage |
9 | 2695 gui_mac_doMouseMovedEvent(event); |
7 | 2696 break; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2697 case (0x01): // suspendResumeMessage |
9 | 2698 gui_mac_doSuspendEvent(event); |
7 | 2699 break; |
2700 } | |
2701 break; | |
2702 | |
2703 #ifdef USE_AEVENT | |
2704 case (kHighLevelEvent): | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2705 // Someone's talking to us, through AppleEvents |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2706 error = AEProcessAppleEvent(event); // TODO: Error Handling |
7 | 2707 break; |
2708 #endif | |
2709 } | |
2710 } | |
2711 | |
2712 /* | |
2713 * ------------------------------------------------------------ | |
2714 * Unknown Stuff | |
2715 * ------------------------------------------------------------ | |
2716 */ | |
2717 | |
2718 | |
2719 GuiFont | |
593 | 2720 gui_mac_find_font(char_u *font_name) |
7 | 2721 { |
2722 char_u c; | |
2723 char_u *p; | |
2724 char_u pFontName[256]; | |
2725 Str255 systemFontname; | |
2726 short font_id; | |
2727 short size=9; | |
2728 GuiFont font; | |
2729 #if 0 | |
2730 char_u *fontNamePtr; | |
2731 #endif | |
2732 | |
2733 for (p = font_name; ((*p != 0) && (*p != ':')); p++) | |
2734 ; | |
2735 | |
2736 c = *p; | |
2737 *p = 0; | |
2738 | |
2739 #if 1 | |
2740 STRCPY(&pFontName[1], font_name); | |
2741 pFontName[0] = STRLEN(font_name); | |
2742 *p = c; | |
2743 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2744 // Get the font name, minus the style suffix (:h, etc) |
168 | 2745 char_u fontName[256]; |
2746 char_u *styleStart = vim_strchr(font_name, ':'); | |
2747 size_t fontNameLen = styleStart ? styleStart - font_name : STRLEN(fontName); | |
2748 vim_strncpy(fontName, font_name, fontNameLen); | |
2749 | |
2750 ATSUFontID fontRef; | |
2751 FMFontStyle fontStyle; | |
2752 font_id = 0; | |
2753 | |
2754 if (ATSUFindFontFromName(&pFontName[1], pFontName[0], kFontFullName, | |
2755 kFontMacintoshPlatform, kFontNoScriptCode, kFontNoLanguageCode, | |
2756 &fontRef) == noErr) | |
2757 { | |
2758 if (FMGetFontFamilyInstanceFromFont(fontRef, &font_id, &fontStyle) != noErr) | |
2759 font_id = 0; | |
2760 } | |
13 | 2761 |
2762 if (font_id == 0) | |
2763 { | |
2764 /* | |
2765 * Try again, this time replacing underscores in the font name | |
2766 * with spaces (:set guifont allows the two to be used | |
2767 * interchangeably; the Font Manager doesn't). | |
2768 */ | |
2769 int i, changed = FALSE; | |
2770 | |
2771 for (i = pFontName[0]; i > 0; --i) | |
2772 { | |
2773 if (pFontName[i] == '_') | |
2774 { | |
2775 pFontName[i] = ' '; | |
2776 changed = TRUE; | |
2777 } | |
2778 } | |
2779 if (changed) | |
168 | 2780 if (ATSUFindFontFromName(&pFontName[1], pFontName[0], |
2781 kFontFullName, kFontNoPlatformCode, kFontNoScriptCode, | |
2782 kFontNoLanguageCode, &fontRef) == noErr) | |
2783 { | |
2784 if (FMGetFontFamilyInstanceFromFont(fontRef, &font_id, &fontStyle) != noErr) | |
2785 font_id = 0; | |
2786 } | |
13 | 2787 } |
2788 | |
7 | 2789 #else |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2790 // name = C2Pascal_save(menu->dname); |
7 | 2791 fontNamePtr = C2Pascal_save_and_remove_backslash(font_name); |
2792 | |
9 | 2793 GetFNum(fontNamePtr, &font_id); |
7 | 2794 #endif |
2795 | |
2796 | |
2797 if (font_id == 0) | |
2798 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2799 // Oups, the system font was it the one the user want |
7 | 2800 |
168 | 2801 if (FMGetFontFamilyName(systemFont, systemFontname) != noErr) |
2802 return NOFONT; | |
7 | 2803 if (!EqualString(pFontName, systemFontname, false, false)) |
2804 return NOFONT; | |
2805 } | |
2806 if (*p == ':') | |
2807 { | |
2808 p++; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2809 // Set the values found after ':' |
7 | 2810 while (*p) |
2811 { | |
2812 switch (*p++) | |
2813 { | |
2814 case 'h': | |
2815 size = points_to_pixels(p, &p, TRUE); | |
2816 break; | |
2817 /* | |
2818 * TODO: Maybe accept width and styles | |
2819 */ | |
2820 } | |
2821 while (*p == ':') | |
2822 p++; | |
2823 } | |
2824 } | |
2825 | |
2826 if (size < 1) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2827 size = 1; // Avoid having a size of 0 with system font |
7 | 2828 |
2829 font = (size << 16) + ((long) font_id & 0xFFFF); | |
2830 | |
2831 return font; | |
2832 } | |
2833 | |
2834 /* | |
2835 * ------------------------------------------------------------ | |
1212 | 2836 * GUI_MCH functionality |
7 | 2837 * ------------------------------------------------------------ |
2838 */ | |
2839 | |
2840 /* | |
2841 * Parse the GUI related command-line arguments. Any arguments used are | |
2842 * deleted from argv, and *argc is decremented accordingly. This is called | |
2843 * when vim is started, whether or not the GUI has been started. | |
2844 */ | |
2845 void | |
593 | 2846 gui_mch_prepare(int *argc, char **argv) |
7 | 2847 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2848 // TODO: Move most of this stuff toward gui_mch_init |
7 | 2849 #ifdef USE_EXE_NAME |
2850 FSSpec applDir; | |
2851 # ifndef USE_FIND_BUNDLE_PATH | |
2852 short applVRefNum; | |
2853 long applDirID; | |
2854 Str255 volName; | |
2855 # else | |
2856 ProcessSerialNumber psn; | |
2857 FSRef applFSRef; | |
2858 # endif | |
2859 #endif | |
2860 | |
2861 #if 0 | |
2862 InitCursor(); | |
2863 | |
2864 RegisterAppearanceClient(); | |
2865 | |
2866 #ifdef USE_AEVENT | |
2867 (void) InstallAEHandlers(); | |
2868 #endif | |
2869 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2870 pomme = NewMenu(256, "\p\024"); // 0x14= = Apple Menu |
9 | 2871 |
2872 AppendMenu(pomme, "\pAbout VIM"); | |
2873 | |
2874 InsertMenu(pomme, 0); | |
7 | 2875 |
2876 DrawMenuBar(); | |
2877 | |
2878 | |
2879 #ifndef USE_OFFSETED_WINDOW | |
9 | 2880 SetRect(&windRect, 10, 48, 10+80*7 + 16, 48+24*11); |
7 | 2881 #else |
9 | 2882 SetRect(&windRect, 300, 40, 300+80*7 + 16, 40+24*11); |
7 | 2883 #endif |
2884 | |
2885 | |
2886 CreateNewWindow(kDocumentWindowClass, | |
2887 kWindowResizableAttribute | kWindowCollapseBoxAttribute, | |
9 | 2888 &windRect, &gui.VimWindow); |
2889 SetPortWindowPort(gui.VimWindow); | |
7 | 2890 |
2891 gui.char_width = 7; | |
2892 gui.char_height = 11; | |
2893 gui.char_ascent = 6; | |
2894 gui.num_rows = 24; | |
2895 gui.num_cols = 80; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2896 gui.in_focus = TRUE; // For the moment -> syn. of front application |
7 | 2897 |
9 | 2898 gScrollAction = NewControlActionUPP(gui_mac_scroll_action); |
2899 gScrollDrag = NewControlActionUPP(gui_mac_drag_thumb); | |
7 | 2900 |
2901 dragRectEnbl = FALSE; | |
2902 dragRgn = NULL; | |
2903 dragRectControl = kCreateEmpty; | |
2904 cursorRgn = NewRgn(); | |
2905 #endif | |
2906 #ifdef USE_EXE_NAME | |
2907 # ifndef USE_FIND_BUNDLE_PATH | |
9 | 2908 HGetVol(volName, &applVRefNum, &applDirID); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2909 // TN2015: mention a possible bad VRefNum |
9 | 2910 FSMakeFSSpec(applVRefNum, applDirID, "\p", &applDir); |
7 | 2911 # else |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2912 // OSErr GetApplicationBundleFSSpec(FSSpecPtr theFSSpecPtr) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2913 // of TN2015 |
9 | 2914 (void)GetCurrentProcess(&psn); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2915 // if (err != noErr) return err; |
7 | 2916 |
9 | 2917 (void)GetProcessBundleLocation(&psn, &applFSRef); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2918 // if (err != noErr) return err; |
7 | 2919 |
9 | 2920 (void)FSGetCatalogInfo(&applFSRef, kFSCatInfoNone, NULL, NULL, &applDir, NULL); |
7 | 2921 |
19195
2ef19eed524a
patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents:
18788
diff
changeset
|
2922 // This technique returns NIL when we disallow_gui |
7 | 2923 # endif |
9 | 2924 exe_name = FullPathFromFSSpec_save(applDir); |
7 | 2925 #endif |
2926 } | |
2927 | |
2928 #ifndef ALWAYS_USE_GUI | |
2929 /* | |
2930 * Check if the GUI can be started. Called before gvimrc is sourced. | |
2931 * Return OK or FAIL. | |
2932 */ | |
2933 int | |
2934 gui_mch_init_check(void) | |
2935 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2936 // TODO: For MacOS X find a way to return FAIL, if the user logged in |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2937 // using the >console |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2938 if (disallow_gui) // see main.c for reason to disallow |
7 | 2939 return FAIL; |
2940 return OK; | |
2941 } | |
2942 #endif | |
2943 | |
2944 static OSErr | |
1107 | 2945 receiveHandler(WindowRef theWindow, void *handlerRefCon, DragRef theDrag) |
7 | 2946 { |
2947 int x, y; | |
2948 int_u modifiers; | |
2949 char_u **fnames = NULL; | |
2950 int count; | |
2951 int i, j; | |
2952 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2953 // Get drop position, modifiers and count of items |
7 | 2954 { |
2955 Point point; | |
2956 SInt16 mouseUpModifiers; | |
2957 UInt16 countItem; | |
2958 | |
2959 GetDragMouse(theDrag, &point, NULL); | |
2960 GlobalToLocal(&point); | |
2961 x = point.h; | |
2962 y = point.v; | |
2963 GetDragModifiers(theDrag, NULL, NULL, &mouseUpModifiers); | |
2964 modifiers = EventModifiers2VimMouseModifiers(mouseUpModifiers); | |
2965 CountDragItems(theDrag, &countItem); | |
2966 count = countItem; | |
2967 } | |
2968 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
2969 fnames = ALLOC_MULT(char_u *, count); |
7 | 2970 if (fnames == NULL) |
2971 return dragNotAcceptedErr; | |
2972 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2973 // Get file names dropped |
7 | 2974 for (i = j = 0; i < count; ++i) |
2975 { | |
2976 DragItemRef item; | |
2977 OSErr err; | |
2978 Size size; | |
2979 FlavorType type = flavorTypeHFS; | |
2980 HFSFlavor hfsFlavor; | |
2981 | |
2982 fnames[i] = NULL; | |
2983 GetDragItemReferenceNumber(theDrag, i + 1, &item); | |
2984 err = GetFlavorDataSize(theDrag, item, type, &size); | |
2985 if (err != noErr || size > sizeof(hfsFlavor)) | |
2986 continue; | |
2987 err = GetFlavorData(theDrag, item, type, &hfsFlavor, &size, 0); | |
2988 if (err != noErr) | |
2989 continue; | |
2990 fnames[j++] = FullPathFromFSSpec_save(hfsFlavor.fileSpec); | |
2991 } | |
2992 count = j; | |
2993 | |
2994 gui_handle_drop(x, y, modifiers, fnames, count); | |
37 | 2995 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2996 // Fake mouse event to wake from stall |
37 | 2997 PostEvent(mouseUp, 0); |
2998 | |
7 | 2999 return noErr; |
3000 } | |
3001 | |
3002 /* | |
3003 * Initialise the GUI. Create all the windows, set up all the call-backs | |
3004 * etc. | |
3005 */ | |
3006 int | |
593 | 3007 gui_mch_init(void) |
7 | 3008 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3009 // TODO: Move most of this stuff toward gui_mch_init |
1565 | 3010 Rect windRect; |
3011 MenuHandle pomme; | |
7 | 3012 EventHandlerRef mouseWheelHandlerRef; |
1562 | 3013 EventTypeSpec eventTypeSpec; |
1565 | 3014 ControlRef rootControl; |
168 | 3015 |
3016 if (Gestalt(gestaltSystemVersion, &gMacSystemVersion) != noErr) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3017 gMacSystemVersion = 0x1000; // TODO: Default to minimum sensible value |
168 | 3018 |
7 | 3019 #if 1 |
3020 InitCursor(); | |
3021 | |
3022 RegisterAppearanceClient(); | |
3023 | |
3024 #ifdef USE_AEVENT | |
3025 (void) InstallAEHandlers(); | |
3026 #endif | |
3027 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3028 pomme = NewMenu(256, "\p\024"); // 0x14= = Apple Menu |
9 | 3029 |
3030 AppendMenu(pomme, "\pAbout VIM"); | |
3031 | |
3032 InsertMenu(pomme, 0); | |
7 | 3033 |
3034 DrawMenuBar(); | |
3035 | |
3036 | |
3037 #ifndef USE_OFFSETED_WINDOW | |
9 | 3038 SetRect(&windRect, 10, 48, 10+80*7 + 16, 48+24*11); |
7 | 3039 #else |
9 | 3040 SetRect(&windRect, 300, 40, 300+80*7 + 16, 40+24*11); |
7 | 3041 #endif |
3042 | |
3043 gui.VimWindow = NewCWindow(nil, &windRect, "\pgVim on Macintosh", true, | |
3044 zoomDocProc, | |
3045 (WindowPtr)-1L, true, 0); | |
1292 | 3046 CreateRootControl(gui.VimWindow, &rootControl); |
7 | 3047 InstallReceiveHandler((DragReceiveHandlerUPP)receiveHandler, |
3048 gui.VimWindow, NULL); | |
9 | 3049 SetPortWindowPort(gui.VimWindow); |
7 | 3050 |
3051 gui.char_width = 7; | |
3052 gui.char_height = 11; | |
3053 gui.char_ascent = 6; | |
3054 gui.num_rows = 24; | |
3055 gui.num_cols = 80; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3056 gui.in_focus = TRUE; // For the moment -> syn. of front application |
7 | 3057 |
9 | 3058 gScrollAction = NewControlActionUPP(gui_mac_scroll_action); |
3059 gScrollDrag = NewControlActionUPP(gui_mac_drag_thumb); | |
593 | 3060 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3061 // Install Carbon event callbacks. |
13 | 3062 (void)InstallFontPanelHandler(); |
7 | 3063 |
3064 dragRectEnbl = FALSE; | |
3065 dragRgn = NULL; | |
3066 dragRectControl = kCreateEmpty; | |
3067 cursorRgn = NewRgn(); | |
3068 #endif | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3069 // Display any pending error messages |
7 | 3070 display_errors(); |
3071 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3072 // Get background/foreground colors from system |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3073 // TODO: do the appropriate call to get real defaults |
7 | 3074 gui.norm_pixel = 0x00000000; |
3075 gui.back_pixel = 0x00FFFFFF; | |
3076 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3077 // Get the colors from the "Normal" group (set in syntax.c or in a vimrc |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3078 // file). |
7 | 3079 set_normal_colors(); |
3080 | |
3081 /* | |
3082 * Check that none of the colors are the same as the background color. | |
3083 * Then store the current values as the defaults. | |
3084 */ | |
3085 gui_check_colors(); | |
3086 gui.def_norm_pixel = gui.norm_pixel; | |
3087 gui.def_back_pixel = gui.back_pixel; | |
3088 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3089 // Get the colors for the highlight groups (gui_check_colors() might have |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3090 // changed them) |
7 | 3091 highlight_gui_started(); |
3092 | |
3093 /* | |
3094 * Setting the gui constants | |
3095 */ | |
3096 #ifdef FEAT_MENU | |
3097 gui.menu_height = 0; | |
3098 #endif | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3099 gui.scrollbar_height = gui.scrollbar_width = 15; // cheat 1 overlap |
7 | 3100 gui.border_offset = gui.border_width = 2; |
3101 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3102 // If Quartz-style text anti aliasing is available (see |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3103 // gui_mch_draw_string() below), enable it for all font sizes. |
7 | 3104 vim_setenv((char_u *)"QDTEXT_MINSIZE", (char_u *)"1"); |
593 | 3105 |
7 | 3106 eventTypeSpec.eventClass = kEventClassMouse; |
3107 eventTypeSpec.eventKind = kEventMouseWheelMoved; | |
3108 mouseWheelHandlerUPP = NewEventHandlerUPP(gui_mac_mouse_wheel); | |
3109 if (noErr != InstallApplicationEventHandler(mouseWheelHandlerUPP, 1, | |
3110 &eventTypeSpec, NULL, &mouseWheelHandlerRef)) | |
3111 { | |
3112 mouseWheelHandlerRef = NULL; | |
3113 DisposeEventHandlerUPP(mouseWheelHandlerUPP); | |
3114 mouseWheelHandlerUPP = NULL; | |
3115 } | |
3116 | |
168 | 3117 #ifdef USE_CARBONKEYHANDLER |
1562 | 3118 InterfaceTypeList supportedServices = { kUnicodeDocument }; |
3119 NewTSMDocument(1, supportedServices, &gTSMDocument, 0); | |
3120 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3121 // We don't support inline input yet, use input window by default |
1562 | 3122 UseInputWindow(gTSMDocument, TRUE); |
3123 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3124 // Should we activate the document by default? |
1562 | 3125 // ActivateTSMDocument(gTSMDocument); |
3126 | |
3127 EventTypeSpec textEventTypes[] = { | |
3128 { kEventClassTextInput, kEventTextInputUpdateActiveInputArea }, | |
3129 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, | |
3130 { kEventClassTextInput, kEventTextInputPosToOffset }, | |
3131 { kEventClassTextInput, kEventTextInputOffsetToPos }, | |
3132 }; | |
3133 | |
3134 keyEventHandlerUPP = NewEventHandlerUPP(gui_mac_handle_text_input); | |
3135 if (noErr != InstallApplicationEventHandler(keyEventHandlerUPP, | |
3136 NR_ELEMS(textEventTypes), | |
3137 textEventTypes, NULL, NULL)) | |
3138 { | |
168 | 3139 DisposeEventHandlerUPP(keyEventHandlerUPP); |
3140 keyEventHandlerUPP = NULL; | |
3141 } | |
1562 | 3142 |
3143 EventTypeSpec windowEventTypes[] = { | |
3144 { kEventClassWindow, kEventWindowActivated }, | |
3145 { kEventClassWindow, kEventWindowDeactivated }, | |
3146 }; | |
3147 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3148 // Install window event handler to support TSMDocument activate and |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3149 // deactivate |
1562 | 3150 winEventHandlerUPP = NewEventHandlerUPP(gui_mac_handle_window_activate); |
3151 if (noErr != InstallWindowEventHandler(gui.VimWindow, | |
3152 winEventHandlerUPP, | |
3153 NR_ELEMS(windowEventTypes), | |
3154 windowEventTypes, NULL, NULL)) | |
3155 { | |
3156 DisposeEventHandlerUPP(winEventHandlerUPP); | |
3157 winEventHandlerUPP = NULL; | |
3158 } | |
168 | 3159 #endif |
3160 | |
1106 | 3161 #ifdef FEAT_GUI_TABLINE |
3162 /* | |
3163 * Create the tabline | |
3164 */ | |
3165 initialise_tabline(); | |
3166 #endif | |
3167 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3168 // TODO: Load bitmap if using TOOLBAR |
7 | 3169 return OK; |
3170 } | |
3171 | |
3172 /* | |
3173 * Called when the foreground or background color has been changed. | |
3174 */ | |
3175 void | |
593 | 3176 gui_mch_new_colors(void) |
7 | 3177 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3178 // TODO: |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3179 // This proc is called when Normal is set to a value |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3180 // so what must be done? I don't know |
7 | 3181 } |
3182 | |
3183 /* | |
3184 * Open the GUI window which was created by a call to gui_mch_init(). | |
3185 */ | |
3186 int | |
593 | 3187 gui_mch_open(void) |
7 | 3188 { |
3189 ShowWindow(gui.VimWindow); | |
3190 | |
3191 if (gui_win_x != -1 && gui_win_y != -1) | |
3192 gui_mch_set_winpos(gui_win_x, gui_win_y); | |
3193 | |
3194 /* | |
3195 * Make the GUI the foreground process (in case it was launched | |
3196 * from the Terminal or via :gui). | |
3197 */ | |
3198 { | |
3199 ProcessSerialNumber psn; | |
3200 if (GetCurrentProcess(&psn) == noErr) | |
3201 SetFrontProcess(&psn); | |
3202 } | |
3203 | |
3204 return OK; | |
3205 } | |
3206 | |
1562 | 3207 #ifdef USE_ATSUI_DRAWING |
3208 static void | |
3209 gui_mac_dispose_atsui_style(void) | |
3210 { | |
3211 if (p_macatsui && gFontStyle) | |
3212 ATSUDisposeStyle(gFontStyle); | |
3213 if (p_macatsui && gWideFontStyle) | |
3214 ATSUDisposeStyle(gWideFontStyle); | |
3215 } | |
3216 #endif | |
3217 | |
7 | 3218 void |
3219 gui_mch_exit(int rc) | |
3220 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3221 // TODO: find out all what is missing here? |
7 | 3222 DisposeRgn(cursorRgn); |
3223 | |
168 | 3224 #ifdef USE_CARBONKEYHANDLER |
3225 if (keyEventHandlerUPP) | |
3226 DisposeEventHandlerUPP(keyEventHandlerUPP); | |
3227 #endif | |
3228 | |
7 | 3229 if (mouseWheelHandlerUPP != NULL) |
3230 DisposeEventHandlerUPP(mouseWheelHandlerUPP); | |
3231 | |
168 | 3232 #ifdef USE_ATSUI_DRAWING |
1562 | 3233 gui_mac_dispose_atsui_style(); |
3234 #endif | |
3235 | |
3236 #ifdef USE_CARBONKEYHANDLER | |
3237 FixTSMDocument(gTSMDocument); | |
3238 DeactivateTSMDocument(gTSMDocument); | |
3239 DeleteTSMDocument(gTSMDocument); | |
168 | 3240 #endif |
3241 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3242 // Exit to shell? |
7 | 3243 exit(rc); |
3244 } | |
3245 | |
3246 /* | |
3247 * Get the position of the top left corner of the window. | |
3248 */ | |
3249 int | |
3250 gui_mch_get_winpos(int *x, int *y) | |
3251 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3252 // TODO |
7 | 3253 Rect bounds; |
3254 OSStatus status; | |
3255 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3256 // Carbon >= 1.0.2, MacOS >= 8.5 |
9 | 3257 status = GetWindowBounds(gui.VimWindow, kWindowStructureRgn, &bounds); |
7 | 3258 |
3259 if (status != noErr) | |
3260 return FAIL; | |
3261 *x = bounds.left; | |
3262 *y = bounds.top; | |
3263 return OK; | |
3264 } | |
3265 | |
3266 /* | |
3267 * Set the position of the top left corner of the window to the given | |
3268 * coordinates. | |
3269 */ | |
3270 void | |
3271 gui_mch_set_winpos(int x, int y) | |
3272 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3273 // TODO: Should make sure the window is move within range |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3274 // e.g.: y > ~16 [Menu bar], x > 0, x < screen width |
1377 | 3275 MoveWindowStructure(gui.VimWindow, x, y); |
7 | 3276 } |
3277 | |
3278 void | |
3279 gui_mch_set_shellsize( | |
3280 int width, | |
3281 int height, | |
3282 int min_width, | |
3283 int min_height, | |
3284 int base_width, | |
812 | 3285 int base_height, |
3286 int direction) | |
7 | 3287 { |
3288 CGrafPtr VimPort; | |
3289 Rect VimBound; | |
3290 | |
3291 if (gui.which_scrollbars[SBAR_LEFT]) | |
3292 { | |
9 | 3293 VimPort = GetWindowPort(gui.VimWindow); |
3294 GetPortBounds(VimPort, &VimBound); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3295 VimBound.left = -gui.scrollbar_width; // + 1; |
9 | 3296 SetPortBounds(VimPort, &VimBound); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3297 // GetWindowBounds(gui.VimWindow, kWindowGlobalPortRgn, &winPortRect); ?? |
7 | 3298 } |
3299 else | |
3300 { | |
9 | 3301 VimPort = GetWindowPort(gui.VimWindow); |
3302 GetPortBounds(VimPort, &VimBound); | |
7 | 3303 VimBound.left = 0; |
9 | 3304 SetPortBounds(VimPort, &VimBound); |
7 | 3305 } |
3306 | |
3307 SizeWindow(gui.VimWindow, width, height, TRUE); | |
3308 | |
3309 gui_resize_shell(width, height); | |
3310 } | |
3311 | |
3312 /* | |
3313 * Get the screen dimensions. | |
3314 * Allow 10 pixels for horizontal borders, 40 for vertical borders. | |
3315 * Is there no way to find out how wide the borders really are? | |
1212 | 3316 * TODO: Add live update of those value on suspend/resume. |
7 | 3317 */ |
3318 void | |
593 | 3319 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) |
7 | 3320 { |
3321 GDHandle dominantDevice = GetMainDevice(); | |
3322 Rect screenRect = (**dominantDevice).gdRect; | |
3323 | |
3324 *screen_w = screenRect.right - 10; | |
3325 *screen_h = screenRect.bottom - 40; | |
3326 } | |
3327 | |
3328 | |
13 | 3329 /* |
3330 * Open the Font Panel and wait for the user to select a font and | |
3331 * close the panel. Then fill the buffer pointed to by font_name with | |
3332 * the name and size of the selected font and return the font's handle, | |
3333 * or NOFONT in case of an error. | |
3334 */ | |
3335 static GuiFont | |
3336 gui_mac_select_font(char_u *font_name) | |
3337 { | |
3338 GuiFont selected_font = NOFONT; | |
3339 OSStatus status; | |
3340 FontSelectionQDStyle curr_font; | |
3341 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3342 // Initialize the Font Panel with the current font. |
13 | 3343 curr_font.instance.fontFamily = gui.norm_font & 0xFFFF; |
3344 curr_font.size = (gui.norm_font >> 16); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3345 // TODO: set fontStyle once styles are supported in gui_mac_find_font() |
13 | 3346 curr_font.instance.fontStyle = 0; |
3347 curr_font.hasColor = false; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3348 curr_font.version = 0; // version number of the style structure |
13 | 3349 status = SetFontInfoForSelection(kFontSelectionQDType, |
3350 /*numStyles=*/1, &curr_font, /*eventTarget=*/NULL); | |
3351 | |
3352 gFontPanelInfo.family = curr_font.instance.fontFamily; | |
3353 gFontPanelInfo.style = curr_font.instance.fontStyle; | |
3354 gFontPanelInfo.size = curr_font.size; | |
3355 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3356 // Pop up the Font Panel. |
13 | 3357 status = FPShowHideFontPanel(); |
3358 if (status == noErr) | |
3359 { | |
3360 /* | |
3361 * The Font Panel is modeless. We really need it to be modal, | |
3362 * so we spin in an event loop until the panel is closed. | |
3363 */ | |
3364 gFontPanelInfo.isPanelVisible = true; | |
3365 while (gFontPanelInfo.isPanelVisible) | |
3366 { | |
3367 EventRecord e; | |
3368 WaitNextEvent(everyEvent, &e, /*sleep=*/20, /*mouseRgn=*/NULL); | |
3369 } | |
3370 | |
3371 GetFontPanelSelection(font_name); | |
3372 selected_font = gui_mac_find_font(font_name); | |
3373 } | |
3374 return selected_font; | |
3375 } | |
3376 | |
1562 | 3377 #ifdef USE_ATSUI_DRAWING |
3378 static void | |
3379 gui_mac_create_atsui_style(void) | |
3380 { | |
3381 if (p_macatsui && gFontStyle == NULL) | |
3382 { | |
3383 if (ATSUCreateStyle(&gFontStyle) != noErr) | |
3384 gFontStyle = NULL; | |
3385 } | |
3386 if (p_macatsui && gWideFontStyle == NULL) | |
3387 { | |
3388 if (ATSUCreateStyle(&gWideFontStyle) != noErr) | |
3389 gWideFontStyle = NULL; | |
3390 } | |
3391 | |
3392 p_macatsui_last = p_macatsui; | |
3393 } | |
3394 #endif | |
7 | 3395 |
3396 /* | |
3397 * Initialise vim to use the font with the given name. Return FAIL if the font | |
3398 * could not be loaded, OK otherwise. | |
3399 */ | |
3400 int | |
593 | 3401 gui_mch_init_font(char_u *font_name, int fontset) |
7 | 3402 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3403 // TODO: Add support for bold italic underline proportional etc... |
7 | 3404 Str255 suggestedFont = "\pMonaco"; |
170 | 3405 int suggestedSize = 10; |
7 | 3406 FontInfo font_info; |
3407 short font_id; | |
3408 GuiFont font; | |
37 | 3409 char_u used_font_name[512]; |
7 | 3410 |
168 | 3411 #ifdef USE_ATSUI_DRAWING |
1562 | 3412 gui_mac_create_atsui_style(); |
168 | 3413 #endif |
3414 | |
7 | 3415 if (font_name == NULL) |
3416 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3417 // First try to get the suggested font |
7 | 3418 GetFNum(suggestedFont, &font_id); |
3419 | |
3420 if (font_id == 0) | |
3421 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3422 // Then pickup the standard application font |
7 | 3423 font_id = GetAppFont(); |
37 | 3424 STRCPY(used_font_name, "default"); |
7 | 3425 } |
37 | 3426 else |
3427 STRCPY(used_font_name, "Monaco"); | |
7 | 3428 font = (suggestedSize << 16) + ((long) font_id & 0xFFFF); |
3429 } | |
13 | 3430 else if (STRCMP(font_name, "*") == 0) |
3431 { | |
37 | 3432 char_u *new_p_guifont; |
3433 | |
3434 font = gui_mac_select_font(used_font_name); | |
13 | 3435 if (font == NOFONT) |
3436 return FAIL; | |
3437 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3438 // Set guifont to the name of the selected font. |
37 | 3439 new_p_guifont = alloc(STRLEN(used_font_name) + 1); |
13 | 3440 if (new_p_guifont != NULL) |
3441 { | |
37 | 3442 STRCPY(new_p_guifont, used_font_name); |
13 | 3443 vim_free(p_guifont); |
3444 p_guifont = new_p_guifont; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3445 // Replace spaces in the font name with underscores. |
13 | 3446 for ( ; *new_p_guifont; ++new_p_guifont) |
3447 { | |
3448 if (*new_p_guifont == ' ') | |
3449 *new_p_guifont = '_'; | |
3450 } | |
3451 } | |
3452 } | |
7 | 3453 else |
3454 { | |
9 | 3455 font = gui_mac_find_font(font_name); |
418 | 3456 vim_strncpy(used_font_name, font_name, sizeof(used_font_name) - 1); |
7 | 3457 |
3458 if (font == NOFONT) | |
3459 return FAIL; | |
3460 } | |
37 | 3461 |
7 | 3462 gui.norm_font = font; |
3463 | |
37 | 3464 hl_set_font_name(used_font_name); |
3465 | |
9 | 3466 TextSize(font >> 16); |
3467 TextFont(font & 0xFFFF); | |
3468 | |
189 | 3469 GetFontInfo(&font_info); |
3470 | |
3471 gui.char_ascent = font_info.ascent; | |
3472 gui.char_width = CharWidth('_'); | |
3473 gui.char_height = font_info.ascent + font_info.descent + p_linespace; | |
3474 | |
168 | 3475 #ifdef USE_ATSUI_DRAWING |
842 | 3476 if (p_macatsui && gFontStyle) |
1562 | 3477 gui_mac_set_font_attributes(font); |
168 | 3478 #endif |
3479 | |
7 | 3480 return OK; |
3481 } | |
3482 | |
444 | 3483 /* |
3484 * Adjust gui.char_height (after 'linespace' was changed). | |
3485 */ | |
7 | 3486 int |
593 | 3487 gui_mch_adjust_charheight(void) |
7 | 3488 { |
3489 FontInfo font_info; | |
3490 | |
9 | 3491 GetFontInfo(&font_info); |
7 | 3492 gui.char_height = font_info.ascent + font_info.descent + p_linespace; |
3493 gui.char_ascent = font_info.ascent + p_linespace / 2; | |
3494 return OK; | |
3495 } | |
3496 | |
3497 /* | |
3498 * Get a font structure for highlighting. | |
3499 */ | |
3500 GuiFont | |
593 | 3501 gui_mch_get_font(char_u *name, int giveErrorIfMissing) |
7 | 3502 { |
3503 GuiFont font; | |
3504 | |
3505 font = gui_mac_find_font(name); | |
3506 | |
3507 if (font == NOFONT) | |
3508 { | |
3509 if (giveErrorIfMissing) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15134
diff
changeset
|
3510 semsg(_(e_font), name); |
7 | 3511 return NOFONT; |
3512 } | |
3513 /* | |
3514 * TODO : Accept only monospace | |
3515 */ | |
3516 | |
3517 return font; | |
3518 } | |
3519 | |
44 | 3520 #if defined(FEAT_EVAL) || defined(PROTO) |
7 | 3521 /* |
37 | 3522 * Return the name of font "font" in allocated memory. |
3523 * Don't know how to get the actual name, thus use the provided name. | |
3524 */ | |
3525 char_u * | |
593 | 3526 gui_mch_get_fontname(GuiFont font, char_u *name) |
37 | 3527 { |
3528 if (name == NULL) | |
3529 return NULL; | |
3530 return vim_strsave(name); | |
3531 } | |
44 | 3532 #endif |
37 | 3533 |
1562 | 3534 #ifdef USE_ATSUI_DRAWING |
3535 static void | |
3536 gui_mac_set_font_attributes(GuiFont font) | |
3537 { | |
3538 ATSUFontID fontID; | |
3539 Fixed fontSize; | |
3540 Fixed fontWidth; | |
3541 | |
3542 fontID = font & 0xFFFF; | |
3543 fontSize = Long2Fix(font >> 16); | |
3544 fontWidth = Long2Fix(gui.char_width); | |
3545 | |
3546 ATSUAttributeTag attribTags[] = | |
3547 { | |
3548 kATSUFontTag, kATSUSizeTag, kATSUImposeWidthTag, | |
3549 kATSUMaxATSUITagValue + 1 | |
3550 }; | |
3551 | |
3552 ByteCount attribSizes[] = | |
3553 { | |
3554 sizeof(ATSUFontID), sizeof(Fixed), sizeof(fontWidth), | |
3555 sizeof(font) | |
3556 }; | |
3557 | |
3558 ATSUAttributeValuePtr attribValues[] = | |
3559 { | |
3560 &fontID, &fontSize, &fontWidth, &font | |
3561 }; | |
3562 | |
3563 if (FMGetFontFromFontFamilyInstance(fontID, 0, &fontID, NULL) == noErr) | |
3564 { | |
3565 if (ATSUSetAttributes(gFontStyle, | |
3566 (sizeof attribTags) / sizeof(ATSUAttributeTag), | |
3567 attribTags, attribSizes, attribValues) != noErr) | |
3568 { | |
3569 # ifndef NDEBUG | |
3570 fprintf(stderr, "couldn't set font style\n"); | |
3571 # endif | |
3572 ATSUDisposeStyle(gFontStyle); | |
3573 gFontStyle = NULL; | |
3574 } | |
3575 | |
3576 if (has_mbyte) | |
3577 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3578 // FIXME: we should use a more mbyte sensitive way to support |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3579 // wide font drawing |
1562 | 3580 fontWidth = Long2Fix(gui.char_width * 2); |
3581 | |
3582 if (ATSUSetAttributes(gWideFontStyle, | |
3583 (sizeof attribTags) / sizeof(ATSUAttributeTag), | |
3584 attribTags, attribSizes, attribValues) != noErr) | |
3585 { | |
3586 ATSUDisposeStyle(gWideFontStyle); | |
3587 gWideFontStyle = NULL; | |
3588 } | |
3589 } | |
3590 } | |
3591 } | |
3592 #endif | |
3593 | |
37 | 3594 /* |
7 | 3595 * Set the current text font. |
3596 */ | |
3597 void | |
593 | 3598 gui_mch_set_font(GuiFont font) |
7 | 3599 { |
168 | 3600 #ifdef USE_ATSUI_DRAWING |
3601 GuiFont currFont; | |
3602 ByteCount actualFontByteCount; | |
3603 | |
842 | 3604 if (p_macatsui && gFontStyle) |
168 | 3605 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3606 // Avoid setting same font again |
1562 | 3607 if (ATSUGetAttribute(gFontStyle, kATSUMaxATSUITagValue + 1, |
3608 sizeof(font), &currFont, &actualFontByteCount) == noErr | |
3609 && actualFontByteCount == (sizeof font)) | |
168 | 3610 { |
3611 if (currFont == font) | |
3612 return; | |
3613 } | |
3614 | |
1562 | 3615 gui_mac_set_font_attributes(font); |
168 | 3616 } |
3617 | |
842 | 3618 if (p_macatsui && !gIsFontFallbackSet) |
168 | 3619 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3620 // Setup automatic font substitution. The user's guifontwide |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3621 // is tried first, then the system tries other fonts. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3622 #if 0 |
168 | 3623 ATSUAttributeTag fallbackTags[] = { kATSULineFontFallbacksTag }; |
3624 ByteCount fallbackSizes[] = { sizeof(ATSUFontFallbacks) }; | |
3625 ATSUCreateFontFallbacks(&gFontFallbacks); | |
3626 ATSUSetObjFontFallbacks(gFontFallbacks, ); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3627 #endif |
168 | 3628 if (gui.wide_font) |
3629 { | |
3630 ATSUFontID fallbackFonts; | |
3631 gIsFontFallbackSet = TRUE; | |
3632 | |
3633 if (FMGetFontFromFontFamilyInstance( | |
3634 (gui.wide_font & 0xFFFF), | |
3635 0, | |
3636 &fallbackFonts, | |
3637 NULL) == noErr) | |
3638 { | |
1562 | 3639 ATSUSetFontFallbacks((sizeof fallbackFonts)/sizeof(ATSUFontID), |
3640 &fallbackFonts, | |
3641 kATSUSequentialFallbacksPreferred); | |
168 | 3642 } |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3643 // ATSUAttributeValuePtr fallbackValues[] = { }; |
168 | 3644 } |
3645 } | |
3646 #endif | |
7 | 3647 TextSize(font >> 16); |
3648 TextFont(font & 0xFFFF); | |
3649 } | |
3650 | |
3651 /* | |
3652 * If a font is not going to be used, free its structure. | |
3653 */ | |
3654 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
3655 gui_mch_free_font(GuiFont font) |
7 | 3656 { |
3657 /* | |
3658 * Free font when "font" is not 0. | |
3659 * Nothing to do in the current implementation, since | |
3660 * nothing is allocated for each font used. | |
3661 */ | |
3662 } | |
3663 | |
3664 /* | |
3665 * Return the Pixel value (color) for the given color name. This routine was | |
3666 * pretty much taken from example code in the Silicon Graphics OSF/Motif | |
3667 * Programmer's Guide. | |
3668 * Return INVALCOLOR when failed. | |
3669 */ | |
3670 guicolor_T | |
593 | 3671 gui_mch_get_color(char_u *name) |
7 | 3672 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3673 // TODO: Add support for the new named color of MacOS 8 |
7 | 3674 RGBColor MacColor; |
9013
22c29a515b53
commit https://github.com/vim/vim/commit/ab3022196ea4f1496e79b8ee85996e31c45d02f1
Christian Brabandt <cb@256bit.org>
parents:
8269
diff
changeset
|
3675 |
22c29a515b53
commit https://github.com/vim/vim/commit/ab3022196ea4f1496e79b8ee85996e31c45d02f1
Christian Brabandt <cb@256bit.org>
parents:
8269
diff
changeset
|
3676 if (STRICMP(name, "hilite") == 0) |
7 | 3677 { |
9013
22c29a515b53
commit https://github.com/vim/vim/commit/ab3022196ea4f1496e79b8ee85996e31c45d02f1
Christian Brabandt <cb@256bit.org>
parents:
8269
diff
changeset
|
3678 LMGetHiliteRGB(&MacColor); |
22c29a515b53
commit https://github.com/vim/vim/commit/ab3022196ea4f1496e79b8ee85996e31c45d02f1
Christian Brabandt <cb@256bit.org>
parents:
8269
diff
changeset
|
3679 return (RGB(MacColor.red >> 8, MacColor.green >> 8, MacColor.blue >> 8)); |
7 | 3680 } |
9013
22c29a515b53
commit https://github.com/vim/vim/commit/ab3022196ea4f1496e79b8ee85996e31c45d02f1
Christian Brabandt <cb@256bit.org>
parents:
8269
diff
changeset
|
3681 return gui_get_color_cmn(name); |
7 | 3682 } |
3683 | |
11745
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3684 guicolor_T |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3685 gui_mch_get_rgb_color(int r, int g, int b) |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3686 { |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3687 return gui_get_rgb_color_cmn(r, g, b); |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3688 } |
5a5709918a98
patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3689 |
7 | 3690 /* |
3691 * Set the current text foreground color. | |
3692 */ | |
3693 void | |
593 | 3694 gui_mch_set_fg_color(guicolor_T color) |
7 | 3695 { |
3696 RGBColor TheColor; | |
3697 | |
3698 TheColor.red = Red(color) * 0x0101; | |
3699 TheColor.green = Green(color) * 0x0101; | |
3700 TheColor.blue = Blue(color) * 0x0101; | |
3701 | |
9 | 3702 RGBForeColor(&TheColor); |
7 | 3703 } |
3704 | |
3705 /* | |
3706 * Set the current text background color. | |
3707 */ | |
3708 void | |
593 | 3709 gui_mch_set_bg_color(guicolor_T color) |
7 | 3710 { |
3711 RGBColor TheColor; | |
3712 | |
3713 TheColor.red = Red(color) * 0x0101; | |
3714 TheColor.green = Green(color) * 0x0101; | |
3715 TheColor.blue = Blue(color) * 0x0101; | |
3716 | |
9 | 3717 RGBBackColor(&TheColor); |
7 | 3718 } |
3719 | |
563 | 3720 RGBColor specialColor; |
3721 | |
212 | 3722 /* |
563 | 3723 * Set the current text special color. |
212 | 3724 */ |
3725 void | |
593 | 3726 gui_mch_set_sp_color(guicolor_T color) |
212 | 3727 { |
563 | 3728 specialColor.red = Red(color) * 0x0101; |
3729 specialColor.green = Green(color) * 0x0101; | |
3730 specialColor.blue = Blue(color) * 0x0101; | |
3731 } | |
3732 | |
3733 /* | |
3734 * Draw undercurl at the bottom of the character cell. | |
3735 */ | |
3736 static void | |
3737 draw_undercurl(int flags, int row, int col, int cells) | |
3738 { | |
856 | 3739 int x; |
3740 int offset; | |
3741 const static int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; | |
3742 int y = FILL_Y(row + 1) - 1; | |
563 | 3743 |
3744 RGBForeColor(&specialColor); | |
3745 | |
3746 offset = val[FILL_X(col) % 8]; | |
3747 MoveTo(FILL_X(col), y - offset); | |
3748 | |
593 | 3749 for (x = FILL_X(col); x < FILL_X(col + cells); ++x) |
563 | 3750 { |
593 | 3751 offset = val[x % 8]; |
3752 LineTo(x, y - offset); | |
563 | 3753 } |
212 | 3754 } |
3755 | |
593 | 3756 |
3757 static void | |
3758 draw_string_QD(int row, int col, char_u *s, int len, int flags) | |
7 | 3759 { |
3760 char_u *tofree = NULL; | |
3761 | |
3762 if (output_conv.vc_type != CONV_NONE) | |
3763 { | |
3764 tofree = string_convert(&output_conv, s, &len); | |
3765 if (tofree != NULL) | |
3766 s = tofree; | |
3767 } | |
593 | 3768 |
7 | 3769 /* |
3770 * On OS X, try using Quartz-style text antialiasing. | |
3771 */ | |
189 | 3772 if (gMacSystemVersion >= 0x1020) |
7 | 3773 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3774 // Quartz antialiasing is available only in OS 10.2 and later. |
7 | 3775 UInt32 qd_flags = (p_antialias ? |
3776 kQDUseCGTextRendering | kQDUseCGTextMetrics : 0); | |
168 | 3777 QDSwapTextFlags(qd_flags); |
7 | 3778 } |
3779 | |
36 | 3780 /* |
3781 * When antialiasing we're using srcOr mode, we have to clear the block | |
3782 * before drawing the text. | |
3783 * Also needed when 'linespace' is non-zero to remove the cursor and | |
3784 * underlining. | |
3785 * But not when drawing transparently. | |
3786 * The following is like calling gui_mch_clear_block(row, col, row, col + | |
3787 * len - 1), but without setting the bg color to gui.back_pixel. | |
3788 */ | |
189 | 3789 if (((gMacSystemVersion >= 0x1020 && p_antialias) || p_linespace != 0) |
36 | 3790 && !(flags & DRAW_TRANSP)) |
3791 { | |
3792 Rect rc; | |
3793 | |
3794 rc.left = FILL_X(col); | |
3795 rc.top = FILL_Y(row); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3796 // Multibyte computation taken from gui_w32.c |
168 | 3797 if (has_mbyte) |
3798 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3799 // Compute the length in display cells. |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2327
diff
changeset
|
3800 rc.right = FILL_X(col + mb_string2cells(s, len)); |
168 | 3801 } |
3802 else | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3803 rc.right = FILL_X(col + len) + (col + len == Columns); |
36 | 3804 rc.bottom = FILL_Y(row + 1); |
3805 EraseRect(&rc); | |
3806 } | |
3807 | |
189 | 3808 if (gMacSystemVersion >= 0x1020 && p_antialias) |
7 | 3809 { |
3810 StyleParameter face; | |
3811 | |
3812 face = normal; | |
3813 if (flags & DRAW_BOLD) | |
3814 face |= bold; | |
3815 if (flags & DRAW_UNDERL) | |
3816 face |= underline; | |
3817 TextFace(face); | |
3818 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3819 // Quartz antialiasing works only in srcOr transfer mode. |
7 | 3820 TextMode(srcOr); |
3821 | |
3822 MoveTo(TEXT_X(col), TEXT_Y(row)); | |
3823 DrawText((char*)s, 0, len); | |
3824 } | |
3825 else | |
3826 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3827 // Use old-style, non-antialiased QuickDraw text rendering. |
9 | 3828 TextMode(srcCopy); |
3829 TextFace(normal); | |
7 | 3830 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3831 // SelectFont(hdc, gui.currFont); |
7 | 3832 |
3833 if (flags & DRAW_TRANSP) | |
9 | 3834 TextMode(srcOr); |
7 | 3835 |
9 | 3836 MoveTo(TEXT_X(col), TEXT_Y(row)); |
593 | 3837 DrawText((char *)s, 0, len); |
3838 | |
3839 if (flags & DRAW_BOLD) | |
3840 { | |
3841 TextMode(srcOr); | |
3842 MoveTo(TEXT_X(col) + 1, TEXT_Y(row)); | |
3843 DrawText((char *)s, 0, len); | |
3844 } | |
3845 | |
3846 if (flags & DRAW_UNDERL) | |
3847 { | |
3848 MoveTo(FILL_X(col), FILL_Y(row + 1) - 1); | |
3849 LineTo(FILL_X(col + len) - 1, FILL_Y(row + 1) - 1); | |
3850 } | |
12317
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
11745
diff
changeset
|
3851 if (flags & DRAW_STRIKE) |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
11745
diff
changeset
|
3852 { |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
11745
diff
changeset
|
3853 MoveTo(FILL_X(col), FILL_Y(row + 1) - gui.char_height/2); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
11745
diff
changeset
|
3854 LineTo(FILL_X(col + len) - 1, FILL_Y(row + 1) - gui.char_height/2); |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
11745
diff
changeset
|
3855 } |
593 | 3856 } |
3857 | |
3858 if (flags & DRAW_UNDERC) | |
3859 draw_undercurl(flags, row, col, len); | |
3860 | |
3861 vim_free(tofree); | |
3862 } | |
3863 | |
842 | 3864 #ifdef USE_ATSUI_DRAWING |
593 | 3865 |
3866 static void | |
3867 draw_string_ATSUI(int row, int col, char_u *s, int len, int flags) | |
3868 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3869 // ATSUI requires utf-16 strings |
593 | 3870 UniCharCount utf16_len; |
3871 UniChar *tofree = mac_enc_to_utf16(s, len, (size_t *)&utf16_len); | |
3872 utf16_len /= sizeof(UniChar); | |
3873 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3874 // - ATSUI automatically antialiases text (Someone) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3875 // - for some reason it does not work... (Jussi) |
1562 | 3876 #ifdef MAC_ATSUI_DEBUG |
3877 fprintf(stderr, "row = %d, col = %d, len = %d: '%c'\n", | |
3878 row, col, len, len == 1 ? s[0] : ' '); | |
3879 #endif | |
593 | 3880 /* |
3881 * When antialiasing we're using srcOr mode, we have to clear the block | |
3882 * before drawing the text. | |
3883 * Also needed when 'linespace' is non-zero to remove the cursor and | |
3884 * underlining. | |
3885 * But not when drawing transparently. | |
3886 * The following is like calling gui_mch_clear_block(row, col, row, col + | |
3887 * len - 1), but without setting the bg color to gui.back_pixel. | |
3888 */ | |
3889 if ((flags & DRAW_TRANSP) == 0) | |
3890 { | |
3891 Rect rc; | |
3892 | |
3893 rc.left = FILL_X(col); | |
3894 rc.top = FILL_Y(row); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3895 // Multibyte computation taken from gui_w32.c |
593 | 3896 if (has_mbyte) |
3897 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3898 // Compute the length in display cells. |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2327
diff
changeset
|
3899 rc.right = FILL_X(col + mb_string2cells(s, len)); |
593 | 3900 } |
3901 else | |
3902 rc.right = FILL_X(col + len) + (col + len == Columns); | |
3903 | |
3904 rc.bottom = FILL_Y(row + 1); | |
3905 EraseRect(&rc); | |
3906 } | |
3907 | |
3908 { | |
3909 TextMode(srcCopy); | |
3910 TextFace(normal); | |
3911 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3912 // SelectFont(hdc, gui.currFont); |
593 | 3913 if (flags & DRAW_TRANSP) |
3914 TextMode(srcOr); | |
3915 | |
3916 MoveTo(TEXT_X(col), TEXT_Y(row)); | |
1562 | 3917 |
3918 if (gFontStyle && flags & DRAW_BOLD) | |
3919 { | |
3920 Boolean attValue = true; | |
3921 ATSUAttributeTag attribTags[] = { kATSUQDBoldfaceTag }; | |
3922 ByteCount attribSizes[] = { sizeof(Boolean) }; | |
3923 ATSUAttributeValuePtr attribValues[] = { &attValue }; | |
3924 | |
3925 ATSUSetAttributes(gFontStyle, 1, attribTags, attribSizes, attribValues); | |
3926 } | |
3927 | |
2327
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3928 UInt32 useAntialias = p_antialias ? kATSStyleApplyAntiAliasing |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3929 : kATSStyleNoAntiAliasing; |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3930 if (useAntialias != useAntialias_cached) |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3931 { |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3932 ATSUAttributeTag attribTags[] = { kATSUStyleRenderingOptionsTag }; |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3933 ByteCount attribSizes[] = { sizeof(UInt32) }; |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3934 ATSUAttributeValuePtr attribValues[] = { &useAntialias }; |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3935 |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3936 if (gFontStyle) |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3937 ATSUSetAttributes(gFontStyle, 1, attribTags, |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3938 attribSizes, attribValues); |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3939 if (gWideFontStyle) |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3940 ATSUSetAttributes(gWideFontStyle, 1, attribTags, |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3941 attribSizes, attribValues); |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3942 |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3943 useAntialias_cached = useAntialias; |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3944 } |
02cf6d461e3f
Mac: Support disabling antialias. (LC Mi)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3945 |
1562 | 3946 if (has_mbyte) |
168 | 3947 { |
1562 | 3948 int n, width_in_cell, last_width_in_cell; |
3949 UniCharArrayOffset offset = 0; | |
3950 UniCharCount yet_to_draw = 0; | |
3951 ATSUTextLayout textLayout; | |
3952 ATSUStyle textStyle; | |
3953 | |
3954 last_width_in_cell = 1; | |
3955 ATSUCreateTextLayout(&textLayout); | |
3956 ATSUSetTextPointerLocation(textLayout, tofree, | |
3957 kATSUFromTextBeginning, | |
3958 kATSUToTextEnd, utf16_len); | |
3959 /* | |
3960 ATSUSetRunStyle(textLayout, gFontStyle, | |
3961 kATSUFromTextBeginning, kATSUToTextEnd); */ | |
3962 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3963 // Compute the length in display cells. |
1562 | 3964 for (n = 0; n < len; n += MB_BYTE2LEN(s[n])) |
3965 { | |
3966 width_in_cell = (*mb_ptr2cells)(s + n); | |
3967 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3968 // probably we are switching from single byte character |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3969 // to multibyte characters (which requires more than one |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3970 // cell to draw) |
1562 | 3971 if (width_in_cell != last_width_in_cell) |
3972 { | |
3973 #ifdef MAC_ATSUI_DEBUG | |
3974 fprintf(stderr, "\tn = %2d, (%d-%d), offset = %d, yet_to_draw = %d\n", | |
3975 n, last_width_in_cell, width_in_cell, offset, yet_to_draw); | |
3976 #endif | |
3977 textStyle = last_width_in_cell > 1 ? gWideFontStyle | |
3978 : gFontStyle; | |
3979 | |
3980 ATSUSetRunStyle(textLayout, textStyle, offset, yet_to_draw); | |
3981 offset += yet_to_draw; | |
3982 yet_to_draw = 0; | |
3983 last_width_in_cell = width_in_cell; | |
3984 } | |
3985 | |
3986 yet_to_draw++; | |
3987 } | |
3988 | |
3989 if (yet_to_draw) | |
3990 { | |
3991 #ifdef MAC_ATSUI_DEBUG | |
3992 fprintf(stderr, "\tn = %2d, (%d-%d), offset = %d, yet_to_draw = %d\n", | |
3993 n, last_width_in_cell, width_in_cell, offset, yet_to_draw); | |
3994 #endif | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3995 // finish the rest style |
1562 | 3996 textStyle = width_in_cell > 1 ? gWideFontStyle : gFontStyle; |
3997 ATSUSetRunStyle(textLayout, textStyle, offset, kATSUToTextEnd); | |
3998 } | |
3999 | |
168 | 4000 ATSUSetTransientFontMatching(textLayout, TRUE); |
4001 ATSUDrawText(textLayout, | |
1562 | 4002 kATSUFromTextBeginning, kATSUToTextEnd, |
4003 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | |
168 | 4004 ATSUDisposeTextLayout(textLayout); |
4005 } | |
1562 | 4006 else |
4007 { | |
4008 ATSUTextLayout textLayout; | |
4009 | |
4010 if (ATSUCreateTextLayoutWithTextPtr(tofree, | |
4011 kATSUFromTextBeginning, kATSUToTextEnd, | |
4012 utf16_len, | |
4013 (gFontStyle ? 1 : 0), &utf16_len, | |
4014 (gFontStyle ? &gFontStyle : NULL), | |
4015 &textLayout) == noErr) | |
4016 { | |
4017 ATSUSetTransientFontMatching(textLayout, TRUE); | |
4018 | |
4019 ATSUDrawText(textLayout, | |
4020 kATSUFromTextBeginning, kATSUToTextEnd, | |
4021 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | |
4022 | |
4023 ATSUDisposeTextLayout(textLayout); | |
4024 } | |
4025 } | |
4026 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4027 // drawing is done, now reset bold to normal |
1562 | 4028 if (gFontStyle && flags & DRAW_BOLD) |
4029 { | |
4030 Boolean attValue = false; | |
4031 | |
4032 ATSUAttributeTag attribTags[] = { kATSUQDBoldfaceTag }; | |
4033 ByteCount attribSizes[] = { sizeof(Boolean) }; | |
4034 ATSUAttributeValuePtr attribValues[] = { &attValue }; | |
4035 | |
4036 ATSUSetAttributes(gFontStyle, 1, attribTags, attribSizes, | |
4037 attribValues); | |
4038 } | |
7 | 4039 } |
4040 | |
563 | 4041 if (flags & DRAW_UNDERC) |
4042 draw_undercurl(flags, row, col, len); | |
4043 | |
7 | 4044 vim_free(tofree); |
593 | 4045 } |
4046 #endif | |
4047 | |
4048 void | |
4049 gui_mch_draw_string(int row, int col, char_u *s, int len, int flags) | |
4050 { | |
4051 #if defined(USE_ATSUI_DRAWING) | |
1562 | 4052 if (p_macatsui == 0 && p_macatsui_last != 0) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4053 // switch from macatsui to nomacatsui |
1562 | 4054 gui_mac_dispose_atsui_style(); |
4055 else if (p_macatsui != 0 && p_macatsui_last == 0) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4056 // switch from nomacatsui to macatsui |
1562 | 4057 gui_mac_create_atsui_style(); |
4058 | |
842 | 4059 if (p_macatsui) |
4060 draw_string_ATSUI(row, col, s, len, flags); | |
4061 else | |
7 | 4062 #endif |
842 | 4063 draw_string_QD(row, col, s, len, flags); |
7 | 4064 } |
4065 | |
4066 /* | |
4067 * Return OK if the key with the termcap name "name" is supported. | |
4068 */ | |
4069 int | |
593 | 4070 gui_mch_haskey(char_u *name) |
7 | 4071 { |
4072 int i; | |
4073 | |
4074 for (i = 0; special_keys[i].key_sym != (KeySym)0; i++) | |
4075 if (name[0] == special_keys[i].vim_code0 && | |
4076 name[1] == special_keys[i].vim_code1) | |
4077 return OK; | |
4078 return FAIL; | |
4079 } | |
4080 | |
4081 void | |
593 | 4082 gui_mch_beep(void) |
7 | 4083 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4084 SysBeep(1); // Should this be 0? (????) |
7 | 4085 } |
4086 | |
4087 void | |
593 | 4088 gui_mch_flash(int msec) |
7 | 4089 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4090 // Do a visual beep by reversing the foreground and background colors |
7 | 4091 Rect rc; |
4092 | |
4093 /* | |
4094 * Note: InvertRect() excludes right and bottom of rectangle. | |
4095 */ | |
4096 rc.left = 0; | |
4097 rc.top = 0; | |
4098 rc.right = gui.num_cols * gui.char_width; | |
4099 rc.bottom = gui.num_rows * gui.char_height; | |
4100 InvertRect(&rc); | |
4101 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4102 ui_delay((long)msec, TRUE); // wait for some msec |
7 | 4103 |
4104 InvertRect(&rc); | |
4105 } | |
4106 | |
4107 /* | |
4108 * Invert a rectangle from row r, column c, for nr rows and nc columns. | |
4109 */ | |
4110 void | |
593 | 4111 gui_mch_invert_rectangle(int r, int c, int nr, int nc) |
7 | 4112 { |
4113 Rect rc; | |
4114 | |
4115 /* | |
4116 * Note: InvertRect() excludes right and bottom of rectangle. | |
4117 */ | |
4118 rc.left = FILL_X(c); | |
4119 rc.top = FILL_Y(r); | |
4120 rc.right = rc.left + nc * gui.char_width; | |
4121 rc.bottom = rc.top + nr * gui.char_height; | |
4122 InvertRect(&rc); | |
4123 } | |
4124 | |
4125 /* | |
4126 * Iconify the GUI window. | |
4127 */ | |
4128 void | |
593 | 4129 gui_mch_iconify(void) |
7 | 4130 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4131 // TODO: find out what could replace iconify |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4132 // -window shade? |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4133 // -hide application? |
7 | 4134 } |
4135 | |
4136 #if defined(FEAT_EVAL) || defined(PROTO) | |
4137 /* | |
4138 * Bring the Vim window to the foreground. | |
4139 */ | |
4140 void | |
593 | 4141 gui_mch_set_foreground(void) |
7 | 4142 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4143 // TODO |
7 | 4144 } |
4145 #endif | |
4146 | |
4147 /* | |
4148 * Draw a cursor without focus. | |
4149 */ | |
4150 void | |
593 | 4151 gui_mch_draw_hollow_cursor(guicolor_T color) |
7 | 4152 { |
4153 Rect rc; | |
4154 | |
4155 /* | |
4156 * Note: FrameRect() excludes right and bottom of rectangle. | |
4157 */ | |
4158 rc.left = FILL_X(gui.col); | |
4159 rc.top = FILL_Y(gui.row); | |
4160 rc.right = rc.left + gui.char_width; | |
168 | 4161 if (mb_lefthalve(gui.row, gui.col)) |
4162 rc.right += gui.char_width; | |
7 | 4163 rc.bottom = rc.top + gui.char_height; |
4164 | |
4165 gui_mch_set_fg_color(color); | |
4166 | |
9 | 4167 FrameRect(&rc); |
7 | 4168 } |
4169 | |
4170 /* | |
4171 * Draw part of a cursor, only w pixels wide, and h pixels high. | |
4172 */ | |
4173 void | |
593 | 4174 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) |
7 | 4175 { |
4176 Rect rc; | |
4177 | |
4178 #ifdef FEAT_RIGHTLEFT | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4179 // vertical line should be on the right of current point |
7 | 4180 if (CURSOR_BAR_RIGHT) |
4181 rc.left = FILL_X(gui.col + 1) - w; | |
4182 else | |
4183 #endif | |
4184 rc.left = FILL_X(gui.col); | |
4185 rc.top = FILL_Y(gui.row) + gui.char_height - h; | |
4186 rc.right = rc.left + w; | |
4187 rc.bottom = rc.top + h; | |
4188 | |
4189 gui_mch_set_fg_color(color); | |
4190 | |
168 | 4191 FrameRect(&rc); |
4192 // PaintRect(&rc); | |
7 | 4193 } |
4194 | |
4195 | |
4196 | |
4197 /* | |
4198 * Catch up with any queued X events. This may put keyboard input into the | |
4199 * input buffer, call resize call-backs, trigger timers etc. If there is | |
4200 * nothing in the X event queue (& no timers pending), then we return | |
4201 * immediately. | |
4202 */ | |
4203 void | |
593 | 4204 gui_mch_update(void) |
7 | 4205 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4206 // TODO: find what to do |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4207 // maybe call gui_mch_wait_for_chars (0) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4208 // more like look at EventQueue then |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4209 // call heart of gui_mch_wait_for_chars; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4210 // |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4211 // if (eventther) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4212 // gui_mac_handle_event(&event); |
7 | 4213 EventRecord theEvent; |
4214 | |
9 | 4215 if (EventAvail(everyEvent, &theEvent)) |
7 | 4216 if (theEvent.what != nullEvent) |
4217 gui_mch_wait_for_chars(0); | |
4218 } | |
4219 | |
4220 /* | |
4221 * Simple wrapper to neglect more easily the time | |
4222 * spent inside WaitNextEvent while profiling. | |
4223 */ | |
4224 | |
4225 pascal | |
4226 Boolean | |
9 | 4227 WaitNextEventWrp(EventMask eventMask, EventRecord *theEvent, UInt32 sleep, RgnHandle mouseRgn) |
7 | 4228 { |
4229 if (((long) sleep) < -1) | |
4230 sleep = 32767; | |
4231 return WaitNextEvent(eventMask, theEvent, sleep, mouseRgn); | |
4232 } | |
4233 | |
4234 /* | |
4235 * GUI input routine called by gui_wait_for_chars(). Waits for a character | |
4236 * from the keyboard. | |
4237 * wtime == -1 Wait forever. | |
4238 * wtime == 0 This should never happen. | |
4239 * wtime > 0 Wait wtime milliseconds for a character. | |
4240 * Returns OK if a character was found to be available within the given time, | |
4241 * or FAIL otherwise. | |
4242 */ | |
4243 int | |
593 | 4244 gui_mch_wait_for_chars(int wtime) |
7 | 4245 { |
4246 EventMask mask = (everyEvent); | |
4247 EventRecord event; | |
4248 long entryTick; | |
4249 long currentTick; | |
4250 long sleeppyTick; | |
4251 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4252 // If we are providing life feedback with the scrollbar, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4253 // we don't want to try to wait for an event, or else |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4254 // there won't be any life feedback. |
7 | 4255 if (dragged_sb != NULL) |
4256 return FAIL; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4257 // TODO: Check if FAIL is the proper return code |
7 | 4258 |
4259 entryTick = TickCount(); | |
4260 | |
4261 allow_scrollbar = TRUE; | |
4262 | |
4263 do | |
4264 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4265 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4266 if (dragRectControl == kCreateEmpty) |
7 | 4267 { |
4268 dragRgn = NULL; | |
4269 dragRectControl = kNothing; | |
4270 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4271 else |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4272 #endif |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4273 if (dragRectControl == kCreateRect) |
7 | 4274 { |
4275 dragRgn = cursorRgn; | |
9 | 4276 RectRgn(dragRgn, &dragRect); |
7 | 4277 dragRectControl = kNothing; |
4278 } | |
4279 /* | |
4280 * Don't use gui_mch_update() because then we will spin-lock until a | |
4281 * char arrives, instead we use WaitNextEventWrp() to hang until an | |
4282 * event arrives. No need to check for input_buf_full because we are | |
4283 * returning as soon as it contains a single char. | |
4284 */ | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4285 // TODO: reduce wtime accordingly??? |
7 | 4286 if (wtime > -1) |
1562 | 4287 sleeppyTick = 60 * wtime / 1000; |
7 | 4288 else |
4289 sleeppyTick = 32767; | |
1562 | 4290 |
9 | 4291 if (WaitNextEventWrp(mask, &event, sleeppyTick, dragRgn)) |
7 | 4292 { |
1562 | 4293 gui_mac_handle_event(&event); |
7 | 4294 if (input_available()) |
4295 { | |
4296 allow_scrollbar = FALSE; | |
4297 return OK; | |
4298 } | |
4299 } | |
4300 currentTick = TickCount(); | |
4301 } | |
4302 while ((wtime == -1) || ((currentTick - entryTick) < 60*wtime/1000)); | |
4303 | |
4304 allow_scrollbar = FALSE; | |
4305 return FAIL; | |
4306 } | |
4307 | |
4308 /* | |
4309 * Output routines. | |
4310 */ | |
4311 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4312 /* |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4313 * Flush any output to the screen |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4314 */ |
7 | 4315 void |
593 | 4316 gui_mch_flush(void) |
7 | 4317 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4318 // TODO: Is anything needed here? |
7 | 4319 } |
4320 | |
4321 /* | |
4322 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
4323 * (row2, col2) inclusive. | |
4324 */ | |
4325 void | |
593 | 4326 gui_mch_clear_block(int row1, int col1, int row2, int col2) |
7 | 4327 { |
4328 Rect rc; | |
4329 | |
4330 /* | |
4331 * Clear one extra pixel at the far right, for when bold characters have | |
4332 * spilled over to the next column. | |
4333 */ | |
4334 rc.left = FILL_X(col1); | |
4335 rc.top = FILL_Y(row1); | |
4336 rc.right = FILL_X(col2 + 1) + (col2 == Columns - 1); | |
4337 rc.bottom = FILL_Y(row2 + 1); | |
4338 | |
4339 gui_mch_set_bg_color(gui.back_pixel); | |
9 | 4340 EraseRect(&rc); |
7 | 4341 } |
4342 | |
4343 /* | |
4344 * Clear the whole text window. | |
4345 */ | |
4346 void | |
593 | 4347 gui_mch_clear_all(void) |
7 | 4348 { |
4349 Rect rc; | |
4350 | |
4351 rc.left = 0; | |
4352 rc.top = 0; | |
4353 rc.right = Columns * gui.char_width + 2 * gui.border_width; | |
4354 rc.bottom = Rows * gui.char_height + 2 * gui.border_width; | |
4355 | |
4356 gui_mch_set_bg_color(gui.back_pixel); | |
4357 EraseRect(&rc); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4358 // gui_mch_set_fg_color(gui.norm_pixel); |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4359 // FrameRect(&rc); |
7 | 4360 } |
4361 | |
4362 /* | |
4363 * Delete the given number of lines from the given row, scrolling up any | |
4364 * text further down within the scroll region. | |
4365 */ | |
4366 void | |
593 | 4367 gui_mch_delete_lines(int row, int num_lines) |
7 | 4368 { |
4369 Rect rc; | |
4370 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4371 // changed without checking! |
7 | 4372 rc.left = FILL_X(gui.scroll_region_left); |
4373 rc.right = FILL_X(gui.scroll_region_right + 1); | |
4374 rc.top = FILL_Y(row); | |
4375 rc.bottom = FILL_Y(gui.scroll_region_bot + 1); | |
4376 | |
4377 gui_mch_set_bg_color(gui.back_pixel); | |
9 | 4378 ScrollRect(&rc, 0, -num_lines * gui.char_height, (RgnHandle) nil); |
7 | 4379 |
4380 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
4381 gui.scroll_region_left, | |
4382 gui.scroll_region_bot, gui.scroll_region_right); | |
4383 } | |
4384 | |
4385 /* | |
4386 * Insert the given number of lines before the given row, scrolling down any | |
4387 * following text within the scroll region. | |
4388 */ | |
4389 void | |
593 | 4390 gui_mch_insert_lines(int row, int num_lines) |
7 | 4391 { |
4392 Rect rc; | |
4393 | |
4394 rc.left = FILL_X(gui.scroll_region_left); | |
4395 rc.right = FILL_X(gui.scroll_region_right + 1); | |
4396 rc.top = FILL_Y(row); | |
4397 rc.bottom = FILL_Y(gui.scroll_region_bot + 1); | |
4398 | |
4399 gui_mch_set_bg_color(gui.back_pixel); | |
4400 | |
9 | 4401 ScrollRect(&rc, 0, gui.char_height * num_lines, (RgnHandle) nil); |
7 | 4402 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4403 // Update gui.cursor_row if the cursor scrolled or copied over |
7 | 4404 if (gui.cursor_row >= gui.row |
4405 && gui.cursor_col >= gui.scroll_region_left | |
4406 && gui.cursor_col <= gui.scroll_region_right) | |
4407 { | |
4408 if (gui.cursor_row <= gui.scroll_region_bot - num_lines) | |
4409 gui.cursor_row += num_lines; | |
4410 else if (gui.cursor_row <= gui.scroll_region_bot) | |
4411 gui.cursor_is_valid = FALSE; | |
4412 } | |
4413 | |
4414 gui_clear_block(row, gui.scroll_region_left, | |
4415 row + num_lines - 1, gui.scroll_region_right); | |
4416 } | |
4417 | |
4418 /* | |
4419 * TODO: add a vim format to the clipboard which remember | |
4420 * LINEWISE, CHARWISE, BLOCKWISE | |
4421 */ | |
4422 | |
4423 void | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4424 clip_mch_request_selection(Clipboard_T *cbd) |
7 | 4425 { |
4426 | |
4427 Handle textOfClip; | |
19 | 4428 int flavor = 0; |
7 | 4429 Size scrapSize; |
4430 ScrapFlavorFlags scrapFlags; | |
4431 ScrapRef scrap = nil; | |
4432 OSStatus error; | |
4433 int type; | |
4434 char *searchCR; | |
4435 char_u *tempclip; | |
4436 | |
4437 | |
9 | 4438 error = GetCurrentScrap(&scrap); |
7 | 4439 if (error != noErr) |
4440 return; | |
4441 | |
9 | 4442 error = GetScrapFlavorFlags(scrap, VIMSCRAPFLAVOR, &scrapFlags); |
4443 if (error == noErr) | |
4444 { | |
4445 error = GetScrapFlavorSize(scrap, VIMSCRAPFLAVOR, &scrapSize); | |
4446 if (error == noErr && scrapSize > 1) | |
4447 flavor = 1; | |
4448 } | |
4449 | |
4450 if (flavor == 0) | |
4451 { | |
838 | 4452 error = GetScrapFlavorFlags(scrap, SCRAPTEXTFLAVOR, &scrapFlags); |
9 | 4453 if (error != noErr) |
4454 return; | |
4455 | |
838 | 4456 error = GetScrapFlavorSize(scrap, SCRAPTEXTFLAVOR, &scrapSize); |
9 | 4457 if (error != noErr) |
4458 return; | |
4459 } | |
4460 | |
4461 ReserveMem(scrapSize); | |
593 | 4462 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4463 // In CARBON we don't need a Handle, a pointer is good |
838 | 4464 textOfClip = NewHandle(scrapSize); |
4465 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4466 // tempclip = alloc(scrapSize+1); |
838 | 4467 HLock(textOfClip); |
4468 error = GetScrapFlavorData(scrap, | |
4469 flavor ? VIMSCRAPFLAVOR : SCRAPTEXTFLAVOR, | |
4470 &scrapSize, *textOfClip); | |
4471 scrapSize -= flavor; | |
4472 | |
4473 if (flavor) | |
4474 type = **textOfClip; | |
4475 else | |
2896 | 4476 type = MAUTO; |
838 | 4477 |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4478 tempclip = alloc(scrapSize + 1); |
838 | 4479 mch_memmove(tempclip, *textOfClip + flavor, scrapSize); |
4480 tempclip[scrapSize] = 0; | |
7 | 4481 |
766 | 4482 #ifdef MACOS_CONVERT |
838 | 4483 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4484 // Convert from utf-16 (clipboard) |
168 | 4485 size_t encLen = 0; |
4486 char_u *to = mac_utf16_to_enc((UniChar *)tempclip, scrapSize, &encLen); | |
838 | 4487 |
4488 if (to != NULL) | |
7 | 4489 { |
168 | 4490 scrapSize = encLen; |
4491 vim_free(tempclip); | |
4492 tempclip = to; | |
7 | 4493 } |
838 | 4494 } |
7 | 4495 #endif |
502 | 4496 |
838 | 4497 searchCR = (char *)tempclip; |
4498 while (searchCR != NULL) | |
4499 { | |
4500 searchCR = strchr(searchCR, '\r'); | |
4501 if (searchCR != NULL) | |
4502 *searchCR = '\n'; | |
7 | 4503 } |
838 | 4504 |
4505 clip_yank_selection(type, tempclip, scrapSize, cbd); | |
4506 | |
4507 vim_free(tempclip); | |
4508 HUnlock(textOfClip); | |
4509 | |
4510 DisposeHandle(textOfClip); | |
7 | 4511 } |
4512 | |
4513 void | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4514 clip_mch_lose_selection(Clipboard_T *cbd) |
7 | 4515 { |
4516 /* | |
4517 * TODO: Really nothing to do? | |
4518 */ | |
4519 } | |
4520 | |
4521 int | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4522 clip_mch_own_selection(Clipboard_T *cbd) |
7 | 4523 { |
4524 return OK; | |
4525 } | |
4526 | |
4527 /* | |
4528 * Send the current selection to the clipboard. | |
4529 */ | |
4530 void | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4531 clip_mch_set_selection(Clipboard_T *cbd) |
7 | 4532 { |
4533 Handle textOfClip; | |
4534 long scrapSize; | |
4535 int type; | |
4536 ScrapRef scrap; | |
4537 | |
4538 char_u *str = NULL; | |
4539 | |
4540 if (!cbd->owned) | |
4541 return; | |
4542 | |
4543 clip_get_selection(cbd); | |
4544 | |
4545 /* | |
4546 * Once we set the clipboard, lose ownership. If another application sets | |
4547 * the clipboard, we don't want to think that we still own it. | |
4548 */ | |
4549 cbd->owned = FALSE; | |
4550 | |
838 | 4551 type = clip_convert_selection(&str, (long_u *)&scrapSize, cbd); |
7 | 4552 |
766 | 4553 #ifdef MACOS_CONVERT |
168 | 4554 size_t utf16_len = 0; |
4555 UniChar *to = mac_enc_to_utf16(str, scrapSize, &utf16_len); | |
4556 if (to) | |
7 | 4557 { |
168 | 4558 scrapSize = utf16_len; |
4559 vim_free(str); | |
4560 str = (char_u *)to; | |
7 | 4561 } |
4562 #endif | |
4563 | |
4564 if (type >= 0) | |
4565 { | |
4566 ClearCurrentScrap(); | |
593 | 4567 |
9 | 4568 textOfClip = NewHandle(scrapSize + 1); |
7 | 4569 HLock(textOfClip); |
4570 | |
9 | 4571 **textOfClip = type; |
168 | 4572 mch_memmove(*textOfClip + 1, str, scrapSize); |
9 | 4573 GetCurrentScrap(&scrap); |
838 | 4574 PutScrapFlavor(scrap, SCRAPTEXTFLAVOR, kScrapFlavorMaskNone, |
9 | 4575 scrapSize, *textOfClip + 1); |
4576 PutScrapFlavor(scrap, VIMSCRAPFLAVOR, kScrapFlavorMaskNone, | |
4577 scrapSize + 1, *textOfClip); | |
7 | 4578 HUnlock(textOfClip); |
4579 DisposeHandle(textOfClip); | |
4580 } | |
4581 | |
4582 vim_free(str); | |
4583 } | |
4584 | |
4585 void | |
593 | 4586 gui_mch_set_text_area_pos(int x, int y, int w, int h) |
7 | 4587 { |
4588 Rect VimBound; | |
4589 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4590 // HideWindow(gui.VimWindow); |
7 | 4591 GetWindowBounds(gui.VimWindow, kWindowGlobalPortRgn, &VimBound); |
4592 | |
4593 if (gui.which_scrollbars[SBAR_LEFT]) | |
4594 VimBound.left = -gui.scrollbar_width + 1; | |
4595 else | |
4596 VimBound.left = 0; | |
4597 | |
4598 SetWindowBounds(gui.VimWindow, kWindowGlobalPortRgn, &VimBound); | |
4599 | |
9 | 4600 ShowWindow(gui.VimWindow); |
7 | 4601 } |
4602 | |
4603 /* | |
4604 * Menu stuff. | |
4605 */ | |
4606 | |
4607 void | |
593 | 4608 gui_mch_enable_menu(int flag) |
7 | 4609 { |
4610 /* | |
444 | 4611 * Menu is always active. |
7 | 4612 */ |
4613 } | |
4614 | |
4615 void | |
593 | 4616 gui_mch_set_menu_pos(int x, int y, int w, int h) |
7 | 4617 { |
4618 /* | |
444 | 4619 * The menu is always at the top of the screen. |
7 | 4620 */ |
4621 } | |
4622 | |
4623 /* | |
4624 * Add a sub menu to the menu bar. | |
4625 */ | |
4626 void | |
593 | 4627 gui_mch_add_menu(vimmenu_T *menu, int idx) |
7 | 4628 { |
4629 /* | |
4630 * TODO: Try to use only menu_id instead of both menu_id and menu_handle. | |
4631 * TODO: use menu->mnemonic and menu->actext | |
4632 * TODO: Try to reuse menu id | |
4633 * Carbon Help suggest to use only id between 1 and 235 | |
4634 */ | |
4635 static long next_avail_id = 128; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4636 long menu_after_me = 0; // Default to the end |
168 | 4637 CFStringRef name; |
7 | 4638 short index; |
4639 vimmenu_T *parent = menu->parent; | |
4640 vimmenu_T *brother = menu->next; | |
4641 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4642 // Cannot add a menu if ... |
7 | 4643 if ((parent != NULL && parent->submenu_id == 0)) |
4644 return; | |
4645 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4646 // menu ID greater than 1024 are reserved for ??? |
7 | 4647 if (next_avail_id == 1024) |
4648 return; | |
4649 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4650 // My brother could be the PopUp, find my real brother |
7 | 4651 while ((brother != NULL) && (!menu_is_menubar(brother->name))) |
4652 brother = brother->next; | |
4653 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4654 // Find where to insert the menu (for MenuBar) |
7 | 4655 if ((parent == NULL) && (brother != NULL)) |
4656 menu_after_me = brother->submenu_id; | |
4657 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4658 // If the menu is not part of the menubar (and its submenus), add it 'nowhere' |
7 | 4659 if (!menu_is_menubar(menu->name)) |
4660 menu_after_me = hierMenu; | |
4661 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4662 // Convert the name |
766 | 4663 #ifdef MACOS_CONVERT |
168 | 4664 name = menu_title_removing_mnemonic(menu); |
4665 #else | |
7 | 4666 name = C2Pascal_save(menu->dname); |
168 | 4667 #endif |
7 | 4668 if (name == NULL) |
4669 return; | |
4670 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4671 // Create the menu unless it's the help menu |
7 | 4672 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4673 // Carbon suggest use of |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4674 // OSStatus CreateNewMenu(MenuID, MenuAttributes, MenuRef *); |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4675 // OSStatus SetMenuTitle(MenuRef, ConstStr255Param title); |
7 | 4676 menu->submenu_id = next_avail_id; |
168 | 4677 if (CreateNewMenu(menu->submenu_id, 0, (MenuRef *)&menu->submenu_handle) == noErr) |
4678 SetMenuTitleWithCFString((MenuRef)menu->submenu_handle, name); | |
7 | 4679 next_avail_id++; |
4680 } | |
4681 | |
4682 if (parent == NULL) | |
4683 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4684 // Adding a menu to the menubar, or in the no mans land (for PopUp) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4685 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4686 // TODO: Verify if we could only Insert Menu if really part of the |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4687 // menubar The Inserted menu are scanned or the Command-key combos |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4688 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4689 // Insert the menu |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4690 InsertMenu(menu->submenu_handle, menu_after_me); // insert before |
7 | 4691 #if 1 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4692 // Vim should normally update it. TODO: verify |
7 | 4693 DrawMenuBar(); |
4694 #endif | |
4695 } | |
4696 else | |
4697 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4698 // Adding as a submenu |
7 | 4699 |
9 | 4700 index = gui_mac_get_menu_item_index(menu); |
7 | 4701 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4702 // Call InsertMenuItem followed by SetMenuItemText |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4703 // to avoid special character recognition by InsertMenuItem |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4704 InsertMenuItem(parent->submenu_handle, "\p ", idx); // afterItem |
168 | 4705 SetMenuItemTextWithCFString(parent->submenu_handle, idx+1, name); |
7 | 4706 SetItemCmd(parent->submenu_handle, idx+1, 0x1B); |
4707 SetItemMark(parent->submenu_handle, idx+1, menu->submenu_id); | |
4708 InsertMenu(menu->submenu_handle, hierMenu); | |
4709 } | |
4710 | |
168 | 4711 CFRelease(name); |
7 | 4712 |
4713 #if 0 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4714 // Done by Vim later on |
7 | 4715 DrawMenuBar(); |
4716 #endif | |
4717 } | |
4718 | |
4719 /* | |
4720 * Add a menu item to a menu | |
4721 */ | |
4722 void | |
593 | 4723 gui_mch_add_menu_item(vimmenu_T *menu, int idx) |
7 | 4724 { |
168 | 4725 CFStringRef name; |
7 | 4726 vimmenu_T *parent = menu->parent; |
4727 int menu_inserted; | |
4728 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4729 // Cannot add item, if the menu have not been created |
7 | 4730 if (parent->submenu_id == 0) |
4731 return; | |
4732 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4733 // Could call SetMenuRefCon [CARBON] to associate with the Menu, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4734 // for older OS call GetMenuItemData (menu, item, isCommandID?, data) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4735 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4736 // Convert the name |
766 | 4737 #ifdef MACOS_CONVERT |
168 | 4738 name = menu_title_removing_mnemonic(menu); |
4739 #else | |
7 | 4740 name = C2Pascal_save(menu->dname); |
168 | 4741 #endif |
7 | 4742 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4743 // Where are just a menu item, so no handle, no id |
7 | 4744 menu->submenu_id = 0; |
4745 menu->submenu_handle = NULL; | |
4746 | |
4747 menu_inserted = 0; | |
4748 if (menu->actext) | |
4749 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4750 // If the accelerator text for the menu item looks like it describes |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4751 // a command key (e.g., "<D-S-t>" or "<C-7>"), display it as the |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4752 // item's command equivalent. |
7 | 4753 int key = 0; |
4754 int modifiers = 0; | |
4755 char_u *p_actext; | |
4756 | |
4757 p_actext = menu->actext; | |
20603
c2570baa2e4c
patch 8.2.0855: GUI tests fail because the test doesn't use a modifier
Bram Moolenaar <Bram@vim.org>
parents:
20421
diff
changeset
|
4758 key = find_special_key(&p_actext, &modifiers, FSK_SIMPLIFY, NULL); |
7 | 4759 if (*p_actext != 0) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4760 key = 0; // error: trailing text |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4761 // find_special_key() returns a keycode with as many of the |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4762 // specified modifiers as appropriate already applied (e.g., for |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4763 // "<D-C-x>" it returns Ctrl-X as the keycode and MOD_MASK_CMD |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4764 // as the only modifier). Since we want to display all of the |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4765 // modifiers, we need to convert the keycode back to a printable |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4766 // character plus modifiers. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4767 // TODO: Write an alternative find_special_key() that doesn't |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4768 // apply modifiers. |
7 | 4769 if (key > 0 && key < 32) |
4770 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4771 // Convert a control key to an uppercase letter. Note that |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4772 // by this point it is no longer possible to distinguish |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4773 // between, e.g., Ctrl-S and Ctrl-Shift-S. |
7 | 4774 modifiers |= MOD_MASK_CTRL; |
4775 key += '@'; | |
4776 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4777 // If the keycode is an uppercase letter, set the Shift modifier. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4778 // If it is a lowercase letter, don't set the modifier, but convert |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4779 // the letter to uppercase for display in the menu. |
7 | 4780 else if (key >= 'A' && key <= 'Z') |
4781 modifiers |= MOD_MASK_SHIFT; | |
4782 else if (key >= 'a' && key <= 'z') | |
4783 key += 'A' - 'a'; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4784 // Note: keycodes below 0x22 are reserved by Apple. |
7 | 4785 if (key >= 0x22 && vim_isprintc_strict(key)) |
4786 { | |
4787 int valid = 1; | |
4788 char_u mac_mods = kMenuNoModifiers; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4789 // Convert Vim modifier codes to Menu Manager equivalents. |
7 | 4790 if (modifiers & MOD_MASK_SHIFT) |
4791 mac_mods |= kMenuShiftModifier; | |
4792 if (modifiers & MOD_MASK_CTRL) | |
4793 mac_mods |= kMenuControlModifier; | |
4794 if (!(modifiers & MOD_MASK_CMD)) | |
4795 mac_mods |= kMenuNoCommandModifier; | |
4796 if (modifiers & MOD_MASK_ALT || modifiers & MOD_MASK_MULTI_CLICK) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4797 valid = 0; // TODO: will Alt someday map to Option? |
7 | 4798 if (valid) |
4799 { | |
4800 char_u item_txt[10]; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4801 // Insert the menu item after idx, with its command key. |
7 | 4802 item_txt[0] = 3; item_txt[1] = ' '; item_txt[2] = '/'; |
4803 item_txt[3] = key; | |
4804 InsertMenuItem(parent->submenu_handle, item_txt, idx); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4805 // Set the modifier keys. |
7 | 4806 SetMenuItemModifiers(parent->submenu_handle, idx+1, mac_mods); |
4807 menu_inserted = 1; | |
4808 } | |
4809 } | |
4810 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4811 // Call InsertMenuItem followed by SetMenuItemText |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4812 // to avoid special character recognition by InsertMenuItem |
7 | 4813 if (!menu_inserted) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4814 InsertMenuItem(parent->submenu_handle, "\p ", idx); // afterItem |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4815 // Set the menu item name. |
168 | 4816 SetMenuItemTextWithCFString(parent->submenu_handle, idx+1, name); |
7 | 4817 |
4818 #if 0 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4819 // Called by Vim |
7 | 4820 DrawMenuBar(); |
4821 #endif | |
4822 | |
168 | 4823 CFRelease(name); |
7 | 4824 } |
4825 | |
4826 void | |
593 | 4827 gui_mch_toggle_tearoffs(int enable) |
7 | 4828 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4829 // no tearoff menus |
7 | 4830 } |
4831 | |
4832 /* | |
4833 * Destroy the machine specific menu widget. | |
4834 */ | |
4835 void | |
593 | 4836 gui_mch_destroy_menu(vimmenu_T *menu) |
7 | 4837 { |
9 | 4838 short index = gui_mac_get_menu_item_index(menu); |
7 | 4839 |
4840 if (index > 0) | |
4841 { | |
4842 if (menu->parent) | |
4843 { | |
4844 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4845 // For now just don't delete help menu items. (Huh? Dany) |
9 | 4846 DeleteMenuItem(menu->parent->submenu_handle, index); |
7 | 4847 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4848 // Delete the Menu if it was a hierarchical Menu |
7 | 4849 if (menu->submenu_id != 0) |
4850 { | |
9 | 4851 DeleteMenu(menu->submenu_id); |
4852 DisposeMenu(menu->submenu_handle); | |
7 | 4853 } |
4854 } | |
4855 } | |
4856 #ifdef DEBUG_MAC_MENU | |
4857 else | |
4858 { | |
9 | 4859 printf("gmdm 2\n"); |
7 | 4860 } |
4861 #endif | |
4862 } | |
4863 else | |
4864 { | |
4865 { | |
9 | 4866 DeleteMenu(menu->submenu_id); |
4867 DisposeMenu(menu->submenu_handle); | |
7 | 4868 } |
4869 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4870 // Shouldn't this be already done by Vim. TODO: Check |
7 | 4871 DrawMenuBar(); |
4872 } | |
4873 | |
4874 /* | |
4875 * Make a menu either grey or not grey. | |
4876 */ | |
4877 void | |
593 | 4878 gui_mch_menu_grey(vimmenu_T *menu, int grey) |
7 | 4879 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4880 // TODO: Check if menu really exists |
9 | 4881 short index = gui_mac_get_menu_item_index(menu); |
7 | 4882 /* |
4883 index = menu->index; | |
4884 */ | |
4885 if (grey) | |
4886 { | |
4887 if (menu->children) | |
4888 DisableMenuItem(menu->submenu_handle, index); | |
4889 if (menu->parent) | |
4890 if (menu->parent->submenu_handle) | |
4891 DisableMenuItem(menu->parent->submenu_handle, index); | |
4892 } | |
4893 else | |
4894 { | |
4895 if (menu->children) | |
4896 EnableMenuItem(menu->submenu_handle, index); | |
4897 if (menu->parent) | |
4898 if (menu->parent->submenu_handle) | |
4899 EnableMenuItem(menu->parent->submenu_handle, index); | |
4900 } | |
4901 } | |
4902 | |
4903 /* | |
4904 * Make menu item hidden or not hidden | |
4905 */ | |
4906 void | |
593 | 4907 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) |
7 | 4908 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4909 // There's no hidden mode on MacOS |
9 | 4910 gui_mch_menu_grey(menu, hidden); |
7 | 4911 } |
4912 | |
4913 | |
4914 /* | |
4915 * This is called after setting all the menus to grey/hidden or not. | |
4916 */ | |
4917 void | |
593 | 4918 gui_mch_draw_menubar(void) |
7 | 4919 { |
4920 DrawMenuBar(); | |
4921 } | |
4922 | |
4923 | |
4924 /* | |
4925 * Scrollbar stuff. | |
4926 */ | |
4927 | |
4928 void | |
593 | 4929 gui_mch_enable_scrollbar( |
4930 scrollbar_T *sb, | |
4931 int flag) | |
7 | 4932 { |
4933 if (flag) | |
4934 ShowControl(sb->id); | |
4935 else | |
4936 HideControl(sb->id); | |
4937 | |
4938 #ifdef DEBUG_MAC_SB | |
9 | 4939 printf("enb_sb (%x) %x\n",sb->id, flag); |
7 | 4940 #endif |
4941 } | |
4942 | |
4943 void | |
593 | 4944 gui_mch_set_scrollbar_thumb( |
4945 scrollbar_T *sb, | |
4946 long val, | |
4947 long size, | |
4948 long max) | |
7 | 4949 { |
4950 SetControl32BitMaximum (sb->id, max); | |
4951 SetControl32BitMinimum (sb->id, 0); | |
4952 SetControl32BitValue (sb->id, val); | |
1107 | 4953 SetControlViewSize (sb->id, size); |
7 | 4954 #ifdef DEBUG_MAC_SB |
9199
665d10cb3e6b
commit https://github.com/vim/vim/commit/ea0345901cc2af29f9c5dd0d9d8a818d5f96a63b
Christian Brabandt <cb@256bit.org>
parents:
9013
diff
changeset
|
4955 printf("thumb_sb (%x) %lx, %lx,%lx\n",sb->id, val, size, max); |
7 | 4956 #endif |
4957 } | |
4958 | |
4959 void | |
593 | 4960 gui_mch_set_scrollbar_pos( |
4961 scrollbar_T *sb, | |
4962 int x, | |
4963 int y, | |
4964 int w, | |
4965 int h) | |
7 | 4966 { |
4967 gui_mch_set_bg_color(gui.back_pixel); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4968 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4969 if (gui.which_scrollbars[SBAR_LEFT]) |
7 | 4970 { |
9 | 4971 MoveControl(sb->id, x-16, y); |
4972 SizeControl(sb->id, w + 1, h); | |
7 | 4973 } |
4974 else | |
4975 { | |
9 | 4976 MoveControl(sb->id, x, y); |
4977 SizeControl(sb->id, w + 1, h); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4978 } |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4979 #endif |
7 | 4980 if (sb == &gui.bottom_sbar) |
4981 h += 1; | |
4982 else | |
4983 w += 1; | |
4984 | |
4985 if (gui.which_scrollbars[SBAR_LEFT]) | |
4986 x -= 15; | |
4987 | |
9 | 4988 MoveControl(sb->id, x, y); |
4989 SizeControl(sb->id, w, h); | |
7 | 4990 #ifdef DEBUG_MAC_SB |
9 | 4991 printf("size_sb (%x) %x, %x, %x, %x\n",sb->id, x, y, w, h); |
7 | 4992 #endif |
4993 } | |
4994 | |
4995 void | |
593 | 4996 gui_mch_create_scrollbar( |
4997 scrollbar_T *sb, | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4998 int orient) // SBAR_VERT or SBAR_HORIZ |
7 | 4999 { |
5000 Rect bounds; | |
5001 | |
5002 bounds.top = -16; | |
5003 bounds.bottom = -10; | |
5004 bounds.right = -10; | |
5005 bounds.left = -16; | |
5006 | |
9 | 5007 sb->id = NewControl(gui.VimWindow, |
7 | 5008 &bounds, |
5009 "\pScrollBar", | |
5010 TRUE, | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5011 0, // current |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5012 0, // top |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5013 0, // bottom |
7 | 5014 kControlScrollBarLiveProc, |
5015 (long) sb->ident); | |
5016 #ifdef DEBUG_MAC_SB | |
9 | 5017 printf("create_sb (%x) %x\n",sb->id, orient); |
7 | 5018 #endif |
5019 } | |
5020 | |
5021 void | |
593 | 5022 gui_mch_destroy_scrollbar(scrollbar_T *sb) |
7 | 5023 { |
5024 gui_mch_set_bg_color(gui.back_pixel); | |
9 | 5025 DisposeControl(sb->id); |
7 | 5026 #ifdef DEBUG_MAC_SB |
9 | 5027 printf("dest_sb (%x) \n",sb->id); |
7 | 5028 #endif |
5029 } | |
5030 | |
9213
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5031 int |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5032 gui_mch_is_blinking(void) |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5033 { |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5034 return FALSE; |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5035 } |
7 | 5036 |
9428
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5037 int |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5038 gui_mch_is_blink_off(void) |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5039 { |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5040 return FALSE; |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5041 } |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5042 |
7 | 5043 /* |
5044 * Cursor blink functions. | |
5045 * | |
5046 * This is a simple state machine: | |
5047 * BLINK_NONE not blinking at all | |
5048 * BLINK_OFF blinking, cursor is not shown | |
5049 * BLINK_ON blinking, cursor is shown | |
5050 */ | |
5051 void | |
5052 gui_mch_set_blinking(long wait, long on, long off) | |
5053 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5054 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5055 // TODO: TODO: TODO: TODO: |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5056 blink_waittime = wait; |
7 | 5057 blink_ontime = on; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5058 blink_offtime = off; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5059 #endif |
7 | 5060 } |
5061 | |
5062 /* | |
5063 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
5064 */ | |
5065 void | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5066 gui_mch_stop_blink(int may_call_gui_update_cursor) |
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5067 { |
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5068 if (may_call_gui_update_cursor) |
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5069 gui_update_cursor(TRUE, FALSE); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5070 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5071 // TODO: TODO: TODO: TODO: |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5072 gui_w32_rm_blink_timer(); |
7 | 5073 if (blink_state == BLINK_OFF) |
5074 gui_update_cursor(TRUE, FALSE); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5075 blink_state = BLINK_NONE; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5076 #endif |
7 | 5077 } |
5078 | |
5079 /* | |
5080 * Start the cursor blinking. If it was already blinking, this restarts the | |
5081 * waiting time and shows the cursor. | |
5082 */ | |
5083 void | |
593 | 5084 gui_mch_start_blink(void) |
7 | 5085 { |
5086 gui_update_cursor(TRUE, FALSE); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5087 // TODO: TODO: TODO: TODO: |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5088 // gui_w32_rm_blink_timer(); |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5089 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5090 // Only switch blinking on if none of the times is zero |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5091 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5092 if (blink_waittime && blink_ontime && blink_offtime) |
7 | 5093 { |
5094 blink_timer = SetTimer(NULL, 0, (UINT)blink_waittime, | |
5095 (TIMERPROC)_OnBlinkTimer); | |
5096 blink_state = BLINK_ON; | |
5097 gui_update_cursor(TRUE, FALSE); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5098 } |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5099 #endif |
7 | 5100 } |
5101 | |
5102 /* | |
5103 * Return the RGB value of a pixel as long. | |
5104 */ | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9869
diff
changeset
|
5105 guicolor_T |
7 | 5106 gui_mch_get_rgb(guicolor_T pixel) |
5107 { | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9869
diff
changeset
|
5108 return (guicolor_T)((Red(pixel) << 16) + (Green(pixel) << 8) + Blue(pixel)); |
7 | 5109 } |
5110 | |
5111 | |
5112 | |
5113 #ifdef FEAT_BROWSE | |
5114 /* | |
5115 * Pop open a file browser and return the file selected, in allocated memory, | |
5116 * or NULL if Cancel is hit. | |
5117 * saving - TRUE if the file will be saved to, FALSE if it will be opened. | |
5118 * title - Title message for the file browser dialog. | |
5119 * dflt - Default name of file. | |
5120 * ext - Default extension to be added to files without extensions. | |
5121 * initdir - directory in which to open the browser (NULL = current dir) | |
5122 * filter - Filter for matched files to choose from. | |
5123 * Has a format like this: | |
5124 * "C Files (*.c)\0*.c\0" | |
5125 * "All Files\0*.*\0\0" | |
5126 * If these two strings were concatenated, then a choice of two file | |
5127 * filters will be selectable to the user. Then only matching files will | |
5128 * be shown in the browser. If NULL, the default allows all files. | |
5129 * | |
5130 * *NOTE* - the filter string must be terminated with TWO nulls. | |
5131 */ | |
5132 char_u * | |
5133 gui_mch_browse( | |
5134 int saving, | |
5135 char_u *title, | |
5136 char_u *dflt, | |
5137 char_u *ext, | |
5138 char_u *initdir, | |
5139 char_u *filter) | |
5140 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5141 // TODO: Add Ammon's safety check (Dany) |
7 | 5142 NavReplyRecord reply; |
5143 char_u *fname = NULL; | |
5144 char_u **fnames = NULL; | |
5145 long numFiles; | |
5146 NavDialogOptions navOptions; | |
5147 OSErr error; | |
5148 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5149 // Get Navigation Service Defaults value |
9 | 5150 NavGetDefaultDialogOptions(&navOptions); |
7 | 5151 |
5152 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5153 // TODO: If we get a :browse args, set the Multiple bit. |
7 | 5154 navOptions.dialogOptionFlags = kNavAllowInvisibleFiles |
5155 | kNavDontAutoTranslate | |
5156 | kNavDontAddTranslateItems | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5157 // | kNavAllowMultipleFiles |
7 | 5158 | kNavAllowStationery; |
5159 | |
9 | 5160 (void) C2PascalString(title, &navOptions.message); |
5161 (void) C2PascalString(dflt, &navOptions.savedFileName); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5162 // Could set clientName? |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5163 // windowTitle? (there's no title bar?) |
7 | 5164 |
5165 if (saving) | |
5166 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5167 // Change first parm AEDesc (typeFSS) *defaultLocation to match dflt |
9 | 5168 NavPutFile(NULL, &reply, &navOptions, NULL, 'TEXT', 'VIM!', NULL); |
7 | 5169 if (!reply.validRecord) |
5170 return NULL; | |
5171 } | |
5172 else | |
5173 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5174 // Change first parm AEDesc (typeFSS) *defaultLocation to match dflt |
7 | 5175 NavGetFile(NULL, &reply, &navOptions, NULL, NULL, NULL, NULL, NULL); |
5176 if (!reply.validRecord) | |
5177 return NULL; | |
5178 } | |
5179 | |
5180 fnames = new_fnames_from_AEDesc(&reply.selection, &numFiles, &error); | |
5181 | |
9 | 5182 NavDisposeReply(&reply); |
7 | 5183 |
5184 if (fnames) | |
5185 { | |
5186 fname = fnames[0]; | |
5187 vim_free(fnames); | |
5188 } | |
5189 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5190 // TODO: Shorten the file name if possible |
7 | 5191 return fname; |
5192 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5193 #endif // FEAT_BROWSE |
7 | 5194 |
5195 #ifdef FEAT_GUI_DIALOG | |
5196 /* | |
5197 * Stuff for dialogues | |
5198 */ | |
5199 | |
5200 /* | |
5201 * Create a dialogue dynamically from the parameter strings. | |
5202 * type = type of dialogue (question, alert, etc.) | |
5203 * title = dialogue title. may be NULL for default title. | |
5204 * message = text to display. Dialogue sizes to accommodate it. | |
5205 * buttons = '\n' separated list of button captions, default first. | |
5206 * dfltbutton = number of default button. | |
5207 * | |
5208 * This routine returns 1 if the first button is pressed, | |
5209 * 2 for the second, etc. | |
5210 * | |
5211 * 0 indicates Esc was pressed. | |
5212 * -1 for unexpected error | |
5213 * | |
5214 * If stubbing out this fn, return 1. | |
5215 */ | |
5216 | |
5217 typedef struct | |
5218 { | |
5219 short idx; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5220 short width; // Size of the text in pixel |
7 | 5221 Rect box; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5222 } vgmDlgItm; // Vim Gui_Mac.c Dialog Item |
7 | 5223 |
5224 #define MoveRectTo(r,x,y) OffsetRect(r,x-r->left,y-r->top) | |
5225 | |
5226 static void | |
5227 macMoveDialogItem( | |
5228 DialogRef theDialog, | |
5229 short itemNumber, | |
5230 short X, | |
5231 short Y, | |
5232 Rect *inBox) | |
5233 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5234 #if 0 // USE_CARBONIZED |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5235 // Untested |
9 | 5236 MoveDialogItem(theDialog, itemNumber, X, Y); |
7 | 5237 if (inBox != nil) |
9 | 5238 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, inBox); |
7 | 5239 #else |
5240 short itemType; | |
5241 Handle itemHandle; | |
5242 Rect localBox; | |
5243 Rect *itemBox = &localBox; | |
5244 | |
5245 if (inBox != nil) | |
5246 itemBox = inBox; | |
5247 | |
9 | 5248 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, itemBox); |
5249 OffsetRect(itemBox, -itemBox->left, -itemBox->top); | |
5250 OffsetRect(itemBox, X, Y); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5251 // To move a control (like a button) we need to call both |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5252 // MoveControl and SetDialogItem. FAQ 6-18 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5253 if (1) //(itemType & kControlDialogItem) |
9 | 5254 MoveControl((ControlRef) itemHandle, X, Y); |
5255 SetDialogItem(theDialog, itemNumber, itemType, itemHandle, itemBox); | |
7 | 5256 #endif |
5257 } | |
5258 | |
5259 static void | |
5260 macSizeDialogItem( | |
5261 DialogRef theDialog, | |
5262 short itemNumber, | |
5263 short width, | |
5264 short height) | |
5265 { | |
5266 short itemType; | |
5267 Handle itemHandle; | |
5268 Rect itemBox; | |
5269 | |
9 | 5270 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, &itemBox); |
7 | 5271 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5272 // When width or height is zero do not change it |
7 | 5273 if (width == 0) |
5274 width = itemBox.right - itemBox.left; | |
5275 if (height == 0) | |
5276 height = itemBox.bottom - itemBox.top; | |
5277 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5278 #if 0 // USE_CARBONIZED |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5279 SizeDialogItem(theDialog, itemNumber, width, height); // Untested |
7 | 5280 #else |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5281 // Resize the bounding box |
7 | 5282 itemBox.right = itemBox.left + width; |
5283 itemBox.bottom = itemBox.top + height; | |
5284 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5285 // To resize a control (like a button) we need to call both |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5286 // SizeControl and SetDialogItem. (deducted from FAQ 6-18) |
7 | 5287 if (itemType & kControlDialogItem) |
9 | 5288 SizeControl((ControlRef) itemHandle, width, height); |
7 | 5289 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5290 // Configure back the item |
9 | 5291 SetDialogItem(theDialog, itemNumber, itemType, itemHandle, &itemBox); |
7 | 5292 #endif |
5293 } | |
5294 | |
5295 static void | |
5296 macSetDialogItemText( | |
5297 DialogRef theDialog, | |
5298 short itemNumber, | |
5299 Str255 itemName) | |
5300 { | |
5301 short itemType; | |
5302 Handle itemHandle; | |
5303 Rect itemBox; | |
5304 | |
9 | 5305 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, &itemBox); |
7 | 5306 |
5307 if (itemType & kControlDialogItem) | |
9 | 5308 SetControlTitle((ControlRef) itemHandle, itemName); |
7 | 5309 else |
9 | 5310 SetDialogItemText(itemHandle, itemName); |
7 | 5311 } |
5312 | |
1572 | 5313 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5314 /* |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5315 * ModalDialog() handler for message dialogs that have hotkey accelerators. |
1572 | 5316 * Expects a mapping of hotkey char to control index in gDialogHotKeys; |
5317 * setting gDialogHotKeys to NULL disables any hotkey handling. | |
5318 */ | |
5319 static pascal Boolean | |
5320 DialogHotkeyFilterProc ( | |
5321 DialogRef theDialog, | |
5322 EventRecord *event, | |
5323 DialogItemIndex *itemHit) | |
5324 { | |
5325 char_u keyHit; | |
5326 | |
5327 if (event->what == keyDown || event->what == autoKey) | |
5328 { | |
5329 keyHit = (event->message & charCodeMask); | |
5330 | |
5331 if (gDialogHotKeys && gDialogHotKeys[keyHit]) | |
5332 { | |
5333 #ifdef DEBUG_MAC_DIALOG_HOTKEYS | |
5334 printf("user pressed hotkey '%c' --> item %d\n", keyHit, gDialogHotKeys[keyHit]); | |
5335 #endif | |
5336 *itemHit = gDialogHotKeys[keyHit]; | |
5337 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5338 // When handing off to StdFilterProc, pretend that the user |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5339 // clicked the control manually. Note that this is also supposed |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5340 // to cause the button to hilite briefly (to give some user |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5341 // feedback), but this seems not to actually work (or it's too |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5342 // fast to be seen). |
1572 | 5343 event->what = kEventControlSimulateHit; |
5344 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5345 return true; // we took care of it |
1572 | 5346 } |
5347 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5348 // Defer to the OS's standard behavior for this event. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5349 // This ensures that Enter will still activate the default button. |
1572 | 5350 return StdFilterProc(theDialog, event, itemHit); |
5351 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5352 return false; // Let ModalDialog deal with it |
1572 | 5353 } |
5354 | |
5355 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5356 /* |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5357 * TODO: There have been some crashes with dialogs, check your inbox |
593 | 5358 * (Jussi) |
5359 */ | |
7 | 5360 int |
5361 gui_mch_dialog( | |
5362 int type, | |
5363 char_u *title, | |
5364 char_u *message, | |
5365 char_u *buttons, | |
5366 int dfltbutton, | |
2684 | 5367 char_u *textfield, |
5368 int ex_cmd) | |
7 | 5369 { |
5370 Handle buttonDITL; | |
5371 Handle iconDITL; | |
5372 Handle inputDITL; | |
5373 Handle messageDITL; | |
5374 Handle itemHandle; | |
5375 Handle iconHandle; | |
5376 DialogPtr theDialog; | |
5377 char_u len; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5378 char_u PascalTitle[256]; // place holder for the title |
7 | 5379 char_u name[256]; |
5380 GrafPtr oldPort; | |
5381 short itemHit; | |
5382 char_u *buttonChar; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5383 short hotKeys[256]; // map of hotkey -> control ID |
1572 | 5384 char_u aHotKey; |
7 | 5385 Rect box; |
5386 short button; | |
5387 short lastButton; | |
5388 short itemType; | |
5389 short useIcon; | |
5390 short width; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5391 short totalButtonWidth = 0; // the width of all buttons together |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5392 // including spacing |
7 | 5393 short widestButton = 0; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5394 short dfltButtonEdge = 20; // gut feeling |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5395 short dfltElementSpacing = 13; // from IM:V.2-29 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5396 short dfltIconSideSpace = 23; // from IM:V.2-29 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5397 short maximumWidth = 400; // gut feeling |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5398 short maxButtonWidth = 175; // gut feeling |
7 | 5399 |
5400 short vertical; | |
5401 short dialogHeight; | |
5402 short messageLines = 3; | |
5403 FontInfo textFontInfo; | |
5404 | |
5405 vgmDlgItm iconItm; | |
5406 vgmDlgItm messageItm; | |
5407 vgmDlgItm inputItm; | |
5408 vgmDlgItm buttonItm; | |
5409 | |
5410 WindowRef theWindow; | |
5411 | |
1572 | 5412 ModalFilterUPP dialogUPP; |
5413 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5414 // Check 'v' flag in 'guioptions': vertical button placement. |
7 | 5415 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL); |
5416 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5417 // Create a new Dialog Box from template. |
9 | 5418 theDialog = GetNewDialog(129, nil, (WindowRef) -1); |
7 | 5419 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5420 // Get the WindowRef |
7 | 5421 theWindow = GetDialogWindow(theDialog); |
5422 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5423 // Hide the window. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5424 // 1. to avoid seeing slow drawing |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5425 // 2. to prevent a problem seen while moving dialog item |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5426 // within a visible window. (non-Carbon MacOS 9) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5427 // Could be avoided by changing the resource. |
9 | 5428 HideWindow(theWindow); |
7 | 5429 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5430 // Change the graphical port to the dialog, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5431 // so we can measure the text with the proper font |
9 | 5432 GetPort(&oldPort); |
5433 SetPortDialogPort(theDialog); | |
7 | 5434 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5435 // Get the info about the default text, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5436 // used to calculate the height of the message |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5437 // and of the text field |
7 | 5438 GetFontInfo(&textFontInfo); |
5439 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5440 // Set the dialog title |
7 | 5441 if (title != NULL) |
5442 { | |
9 | 5443 (void) C2PascalString(title, &PascalTitle); |
5444 SetWTitle(theWindow, PascalTitle); | |
7 | 5445 } |
5446 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5447 // Creates the buttons and add them to the Dialog Box. |
9 | 5448 buttonDITL = GetResource('DITL', 130); |
7 | 5449 buttonChar = buttons; |
5450 button = 0; | |
5451 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5452 // initialize the hotkey mapping |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
5453 CLEAR_FIELD(hotKeys); |
1572 | 5454 |
7 | 5455 for (;*buttonChar != 0;) |
5456 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5457 // Get the name of the button |
7 | 5458 button++; |
5459 len = 0; | |
5460 for (;((*buttonChar != DLG_BUTTON_SEP) && (*buttonChar != 0) && (len < 255)); buttonChar++) | |
5461 { | |
5462 if (*buttonChar != DLG_HOTKEY_CHAR) | |
5463 name[++len] = *buttonChar; | |
1572 | 5464 else |
5465 { | |
5466 aHotKey = (char_u)*(buttonChar+1); | |
5467 if (aHotKey >= 'A' && aHotKey <= 'Z') | |
5468 aHotKey = (char_u)((int)aHotKey + (int)'a' - (int)'A'); | |
5469 hotKeys[aHotKey] = button; | |
5470 #ifdef DEBUG_MAC_DIALOG_HOTKEYS | |
5471 printf("### hotKey for button %d is '%c'\n", button, aHotKey); | |
5472 #endif | |
5473 } | |
7 | 5474 } |
1572 | 5475 |
7 | 5476 if (*buttonChar != 0) |
5477 buttonChar++; | |
5478 name[0] = len; | |
5479 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5480 // Add the button |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5481 AppendDITL(theDialog, buttonDITL, overlayDITL); // appendDITLRight); |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5482 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5483 // Change the button's name |
9 | 5484 macSetDialogItemText(theDialog, button, name); |
7 | 5485 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5486 // Resize the button to fit its name |
9 | 5487 width = StringWidth(name) + 2 * dfltButtonEdge; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5488 // Limit the size of any button to an acceptable value. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5489 // TODO: Should be based on the message width |
7 | 5490 if (width > maxButtonWidth) |
5491 width = maxButtonWidth; | |
9 | 5492 macSizeDialogItem(theDialog, button, width, 0); |
7 | 5493 |
5494 totalButtonWidth += width; | |
5495 | |
5496 if (width > widestButton) | |
5497 widestButton = width; | |
5498 } | |
9 | 5499 ReleaseResource(buttonDITL); |
7 | 5500 lastButton = button; |
5501 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5502 // Add the icon to the Dialog Box. |
7 | 5503 iconItm.idx = lastButton + 1; |
9 | 5504 iconDITL = GetResource('DITL', 131); |
7 | 5505 switch (type) |
5506 { | |
2585 | 5507 case VIM_GENERIC: |
5508 case VIM_INFO: | |
5509 case VIM_QUESTION: useIcon = kNoteIcon; break; | |
5510 case VIM_WARNING: useIcon = kCautionIcon; break; | |
5511 case VIM_ERROR: useIcon = kStopIcon; break; | |
3935 | 5512 default: useIcon = kStopIcon; |
2585 | 5513 } |
9 | 5514 AppendDITL(theDialog, iconDITL, overlayDITL); |
5515 ReleaseResource(iconDITL); | |
5516 GetDialogItem(theDialog, iconItm.idx, &itemType, &itemHandle, &box); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5517 // TODO: Should the item be freed? |
9 | 5518 iconHandle = GetIcon(useIcon); |
5519 SetDialogItem(theDialog, iconItm.idx, itemType, iconHandle, &box); | |
7 | 5520 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5521 // Add the message to the Dialog box. |
7 | 5522 messageItm.idx = lastButton + 2; |
9 | 5523 messageDITL = GetResource('DITL', 132); |
5524 AppendDITL(theDialog, messageDITL, overlayDITL); | |
5525 ReleaseResource(messageDITL); | |
5526 GetDialogItem(theDialog, messageItm.idx, &itemType, &itemHandle, &box); | |
5527 (void) C2PascalString(message, &name); | |
5528 SetDialogItemText(itemHandle, name); | |
5529 messageItm.width = StringWidth(name); | |
7 | 5530 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5531 // Add the input box if needed |
7 | 5532 if (textfield != NULL) |
5533 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5534 // Cheat for now reuse the message and convert to text edit |
7 | 5535 inputItm.idx = lastButton + 3; |
9 | 5536 inputDITL = GetResource('DITL', 132); |
5537 AppendDITL(theDialog, inputDITL, overlayDITL); | |
5538 ReleaseResource(inputDITL); | |
5539 GetDialogItem(theDialog, inputItm.idx, &itemType, &itemHandle, &box); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5540 // SetDialogItem(theDialog, inputItm.idx, kEditTextDialogItem, itemHandle, &box); |
9 | 5541 (void) C2PascalString(textfield, &name); |
5542 SetDialogItemText(itemHandle, name); | |
5543 inputItm.width = StringWidth(name); | |
1572 | 5544 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5545 // Hotkeys don't make sense if there's a text field |
1572 | 5546 gDialogHotKeys = NULL; |
7 | 5547 } |
1572 | 5548 else |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5549 // Install hotkey table |
1572 | 5550 gDialogHotKeys = (short *)&hotKeys; |
7 | 5551 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5552 // Set the <ENTER> and <ESC> button. |
9 | 5553 SetDialogDefaultItem(theDialog, dfltbutton); |
5554 SetDialogCancelItem(theDialog, 0); | |
7 | 5555 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5556 // Reposition element |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5557 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5558 // Check if we need to force vertical |
7 | 5559 if (totalButtonWidth > maximumWidth) |
5560 vertical = TRUE; | |
5561 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5562 // Place icon |
9 | 5563 macMoveDialogItem(theDialog, iconItm.idx, dfltIconSideSpace, dfltElementSpacing, &box); |
7 | 5564 iconItm.box.right = box.right; |
5565 iconItm.box.bottom = box.bottom; | |
5566 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5567 // Place Message |
7 | 5568 messageItm.box.left = iconItm.box.right + dfltIconSideSpace; |
9 | 5569 macSizeDialogItem(theDialog, messageItm.idx, 0, messageLines * (textFontInfo.ascent + textFontInfo.descent)); |
5570 macMoveDialogItem(theDialog, messageItm.idx, messageItm.box.left, dfltElementSpacing, &messageItm.box); | |
7 | 5571 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5572 // Place Input |
7 | 5573 if (textfield != NULL) |
5574 { | |
5575 inputItm.box.left = messageItm.box.left; | |
5576 inputItm.box.top = messageItm.box.bottom + dfltElementSpacing; | |
9 | 5577 macSizeDialogItem(theDialog, inputItm.idx, 0, textFontInfo.ascent + textFontInfo.descent); |
5578 macMoveDialogItem(theDialog, inputItm.idx, inputItm.box.left, inputItm.box.top, &inputItm.box); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5579 // Convert the static text into a text edit. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5580 // For some reason this change need to be done last (Dany) |
9 | 5581 GetDialogItem(theDialog, inputItm.idx, &itemType, &itemHandle, &inputItm.box); |
5582 SetDialogItem(theDialog, inputItm.idx, kEditTextDialogItem, itemHandle, &inputItm.box); | |
7 | 5583 SelectDialogItemText(theDialog, inputItm.idx, 0, 32767); |
5584 } | |
5585 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5586 // Place Button |
7 | 5587 if (textfield != NULL) |
5588 { | |
5589 buttonItm.box.left = inputItm.box.left; | |
5590 buttonItm.box.top = inputItm.box.bottom + dfltElementSpacing; | |
5591 } | |
5592 else | |
5593 { | |
5594 buttonItm.box.left = messageItm.box.left; | |
5595 buttonItm.box.top = messageItm.box.bottom + dfltElementSpacing; | |
5596 } | |
5597 | |
5598 for (button=1; button <= lastButton; button++) | |
5599 { | |
5600 | |
9 | 5601 macMoveDialogItem(theDialog, button, buttonItm.box.left, buttonItm.box.top, &box); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5602 // With vertical, it's better to have all buttons the same length |
7 | 5603 if (vertical) |
5604 { | |
9 | 5605 macSizeDialogItem(theDialog, button, widestButton, 0); |
5606 GetDialogItem(theDialog, button, &itemType, &itemHandle, &box); | |
7 | 5607 } |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5608 // Calculate position of next button |
7 | 5609 if (vertical) |
5610 buttonItm.box.top = box.bottom + dfltElementSpacing; | |
5611 else | |
5612 buttonItm.box.left = box.right + dfltElementSpacing; | |
5613 } | |
5614 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5615 // Resize the dialog box |
7 | 5616 dialogHeight = box.bottom + dfltElementSpacing; |
5617 SizeWindow(theWindow, maximumWidth, dialogHeight, TRUE); | |
5618 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5619 // Magic resize |
9 | 5620 AutoSizeDialog(theDialog); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5621 // Need a horizontal resize anyway so not that useful |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5622 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5623 // Display it |
7 | 5624 ShowWindow(theWindow); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5625 // BringToFront(theWindow); |
7 | 5626 SelectWindow(theWindow); |
5627 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5628 // DrawDialog(theDialog); |
7 | 5629 #if 0 |
9 | 5630 GetPort(&oldPort); |
5631 SetPortDialogPort(theDialog); | |
7 | 5632 #endif |
5633 | |
857 | 5634 #ifdef USE_CARBONKEYHANDLER |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5635 // Avoid that we use key events for the main window. |
857 | 5636 dialog_busy = TRUE; |
5637 #endif | |
5638 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5639 // Prepare the shortcut-handling filterProc for handing to the dialog |
1572 | 5640 dialogUPP = NewModalFilterUPP(DialogHotkeyFilterProc); |
5641 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5642 // Hang until one of the button is hit |
7 | 5643 do |
1572 | 5644 ModalDialog(dialogUPP, &itemHit); |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
5645 while ((itemHit < 1) || (itemHit > lastButton)); |
7 | 5646 |
857 | 5647 #ifdef USE_CARBONKEYHANDLER |
5648 dialog_busy = FALSE; | |
5649 #endif | |
5650 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5651 // Copy back the text entered by the user into the param |
7 | 5652 if (textfield != NULL) |
5653 { | |
9 | 5654 GetDialogItem(theDialog, inputItm.idx, &itemType, &itemHandle, &box); |
5655 GetDialogItemText(itemHandle, (char_u *) &name); | |
7 | 5656 #if IOSIZE < 256 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5657 // Truncate the name to IOSIZE if needed |
7 | 5658 if (name[0] > IOSIZE) |
5659 name[0] = IOSIZE - 1; | |
5660 #endif | |
418 | 5661 vim_strncpy(textfield, &name[1], name[0]); |
7 | 5662 } |
5663 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5664 // Restore the original graphical port |
9 | 5665 SetPort(oldPort); |
7 | 5666 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5667 // Free the modal filterProc |
1572 | 5668 DisposeRoutineDescriptor(dialogUPP); |
5669 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5670 // Get ride of the dialog (free memory) |
9 | 5671 DisposeDialog(theDialog); |
7 | 5672 |
5673 return itemHit; | |
5674 /* | |
2585 | 5675 * Useful thing which could be used |
7 | 5676 * SetDialogTimeout(): Auto click a button after timeout |
5677 * SetDialogTracksCursor() : Get the I-beam cursor over input box | |
5678 * MoveDialogItem(): Probably better than SetDialogItem | |
5679 * SizeDialogItem(): (but is it Carbon Only?) | |
1373 | 5680 * AutoSizeDialog(): Magic resize of dialog based on text length |
7 | 5681 */ |
5682 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5683 #endif // FEAT_DIALOG_GUI |
7 | 5684 |
5685 /* | |
5686 * Display the saved error message(s). | |
5687 */ | |
5688 #ifdef USE_MCH_ERRMSG | |
5689 void | |
593 | 5690 display_errors(void) |
7 | 5691 { |
5692 char *p; | |
5693 char_u pError[256]; | |
5694 | |
593 | 5695 if (error_ga.ga_data == NULL) |
5696 return; | |
5697 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5698 // avoid putting up a message box with blanks only |
593 | 5699 for (p = (char *)error_ga.ga_data; *p; ++p) |
5700 if (!isspace(*p)) | |
5701 { | |
5702 if (STRLEN(p) > 255) | |
5703 pError[0] = 255; | |
5704 else | |
5705 pError[0] = STRLEN(p); | |
5706 | |
5707 STRNCPY(&pError[1], p, pError[0]); | |
5708 ParamText(pError, nil, nil, nil); | |
5709 Alert(128, nil); | |
5710 break; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5711 // TODO: handled message longer than 256 chars |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5712 // use auto-sizeable alert |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5713 // or dialog with scrollbars (TextEdit zone) |
593 | 5714 } |
5715 ga_clear(&error_ga); | |
7 | 5716 } |
5717 #endif | |
5718 | |
5719 /* | |
87 | 5720 * Get current mouse coordinates in text window. |
7 | 5721 */ |
95 | 5722 void |
5723 gui_mch_getmouse(int *x, int *y) | |
7 | 5724 { |
5725 Point where; | |
5726 | |
5727 GetMouse(&where); | |
5728 | |
87 | 5729 *x = where.h; |
5730 *y = where.v; | |
7 | 5731 } |
5732 | |
5733 void | |
593 | 5734 gui_mch_setmouse(int x, int y) |
7 | 5735 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5736 // TODO |
7 | 5737 #if 0 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5738 // From FAQ 3-11 |
7 | 5739 |
5740 CursorDevicePtr myMouse; | |
5741 Point where; | |
5742 | |
9 | 5743 if ( NGetTrapAddress(_CursorDeviceDispatch, ToolTrap) |
5744 != NGetTrapAddress(_Unimplemented, ToolTrap)) | |
7 | 5745 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5746 // New way |
7 | 5747 |
5748 /* | |
4352 | 5749 * Get first device with one button. |
5750 * This will probably be the standard mouse | |
5751 * start at head of cursor dev list | |
7 | 5752 * |
5753 */ | |
5754 | |
5755 myMouse = nil; | |
5756 | |
5757 do | |
5758 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5759 // Get the next cursor device |
7 | 5760 CursorDeviceNextDevice(&myMouse); |
5761 } | |
9 | 5762 while ((myMouse != nil) && (myMouse->cntButtons != 1)); |
5763 | |
5764 CursorDeviceMoveTo(myMouse, x, y); | |
7 | 5765 } |
5766 else | |
5767 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5768 // Old way |
7 | 5769 where.h = x; |
5770 where.v = y; | |
5771 | |
5772 *(Point *)RawMouse = where; | |
5773 *(Point *)MTemp = where; | |
5774 *(Ptr) CrsrNew = 0xFFFF; | |
5775 } | |
5776 #endif | |
5777 } | |
5778 | |
5779 void | |
593 | 5780 gui_mch_show_popupmenu(vimmenu_T *menu) |
7 | 5781 { |
5782 /* | |
5783 * Clone PopUp to use menu | |
5784 * Create a object descriptor for the current selection | |
5785 * Call the procedure | |
5786 */ | |
5787 | |
5788 MenuHandle CntxMenu; | |
5789 Point where; | |
5790 OSStatus status; | |
5791 UInt32 CntxType; | |
5792 SInt16 CntxMenuID; | |
5793 UInt16 CntxMenuItem; | |
5794 Str255 HelpName = ""; | |
5795 GrafPtr savePort; | |
5796 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5797 // Save Current Port: On MacOS X we seem to lose the port |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5798 GetPort(&savePort); //OSX |
9 | 5799 |
5800 GetMouse(&where); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5801 LocalToGlobal(&where); //OSX |
7 | 5802 CntxMenu = menu->submenu_handle; |
5803 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5804 // TODO: Get the text selection from Vim |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5805 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5806 // Call to Handle Popup |
1089 | 5807 status = ContextualMenuSelect(CntxMenu, where, false, kCMHelpItemRemoveHelp, |
1012 | 5808 HelpName, NULL, &CntxType, &CntxMenuID, &CntxMenuItem); |
7 | 5809 |
5810 if (status == noErr) | |
5811 { | |
5812 if (CntxType == kCMMenuItemSelected) | |
5813 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5814 // Handle the menu CntxMenuID, CntxMenuItem |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5815 // The submenu can be handle directly by gui_mac_handle_menu |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5816 // But what about the current menu, is the menu changed by |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5817 // ContextualMenuSelect |
9 | 5818 gui_mac_handle_menu((CntxMenuID << 16) + CntxMenuItem); |
7 | 5819 } |
5820 else if (CntxMenuID == kCMShowHelpSelected) | |
5821 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5822 // Should come up with the help |
7 | 5823 } |
5824 } | |
5825 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5826 // Restore original Port |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5827 SetPort(savePort); //OSX |
7 | 5828 } |
5829 | |
5830 #if defined(FEAT_CW_EDITOR) || defined(PROTO) | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5831 // TODO: Is it need for MACOS_X? (Dany) |
7 | 5832 void |
5833 mch_post_buffer_write(buf_T *buf) | |
5834 { | |
9 | 5835 GetFSSpecFromPath(buf->b_ffname, &buf->b_FSSpec); |
5836 Send_KAHL_MOD_AE(buf); | |
7 | 5837 } |
5838 #endif | |
5839 | |
5840 #ifdef FEAT_TITLE | |
5841 /* | |
5842 * Set the window title and icon. | |
5843 * (The icon is not taken care of). | |
5844 */ | |
5845 void | |
593 | 5846 gui_mch_settitle(char_u *title, char_u *icon) |
7 | 5847 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5848 // TODO: Get vim to make sure maxlen (from p_titlelen) is smaller |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5849 // that 256. Even better get it to fit nicely in the titlebar. |
766 | 5850 #ifdef MACOS_CONVERT |
168 | 5851 CFStringRef windowTitle; |
5852 size_t windowTitleLen; | |
5853 #else | |
7 | 5854 char_u *pascalTitle; |
168 | 5855 #endif |
7 | 5856 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5857 if (title == NULL) // nothing to do |
7 | 5858 return; |
5859 | |
766 | 5860 #ifdef MACOS_CONVERT |
168 | 5861 windowTitleLen = STRLEN(title); |
1621 | 5862 windowTitle = (CFStringRef)mac_enc_to_cfstring(title, windowTitleLen); |
168 | 5863 |
5864 if (windowTitle) | |
5865 { | |
5866 SetWindowTitleWithCFString(gui.VimWindow, windowTitle); | |
5867 CFRelease(windowTitle); | |
5868 } | |
5869 #else | |
7 | 5870 pascalTitle = C2Pascal_save(title); |
5871 if (pascalTitle != NULL) | |
5872 { | |
5873 SetWTitle(gui.VimWindow, pascalTitle); | |
5874 vim_free(pascalTitle); | |
5875 } | |
168 | 5876 #endif |
7 | 5877 } |
5878 #endif | |
5879 | |
5880 /* | |
2585 | 5881 * Transferred from os_mac.c for MacOS X using os_unix.c prep work |
7 | 5882 */ |
5883 | |
5884 int | |
593 | 5885 C2PascalString(char_u *CString, Str255 *PascalString) |
7 | 5886 { |
5887 char_u *PascalPtr = (char_u *) PascalString; | |
5888 int len; | |
5889 int i; | |
5890 | |
5891 PascalPtr[0] = 0; | |
5892 if (CString == NULL) | |
5893 return 0; | |
5894 | |
5895 len = STRLEN(CString); | |
5896 if (len > 255) | |
5897 len = 255; | |
5898 | |
5899 for (i = 0; i < len; i++) | |
5900 PascalPtr[i+1] = CString[i]; | |
5901 | |
5902 PascalPtr[0] = len; | |
5903 | |
5904 return 0; | |
5905 } | |
5906 | |
5907 int | |
593 | 5908 GetFSSpecFromPath(char_u *file, FSSpec *fileFSSpec) |
7 | 5909 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5910 // From FAQ 8-12 |
7 | 5911 Str255 filePascal; |
5912 CInfoPBRec myCPB; | |
5913 OSErr err; | |
5914 | |
9 | 5915 (void) C2PascalString(file, &filePascal); |
7 | 5916 |
5917 myCPB.dirInfo.ioNamePtr = filePascal; | |
5918 myCPB.dirInfo.ioVRefNum = 0; | |
5919 myCPB.dirInfo.ioFDirIndex = 0; | |
5920 myCPB.dirInfo.ioDrDirID = 0; | |
5921 | |
9 | 5922 err= PBGetCatInfo(&myCPB, false); |
7 | 5923 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5924 // vRefNum, dirID, name |
9 | 5925 FSMakeFSSpec(0, 0, filePascal, fileFSSpec); |
7 | 5926 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5927 // TODO: Use an error code mechanism |
7 | 5928 return 0; |
5929 } | |
5930 | |
5931 /* | |
4352 | 5932 * Convert a FSSpec to a full path |
7 | 5933 */ |
5934 | |
9 | 5935 char_u *FullPathFromFSSpec_save(FSSpec file) |
7 | 5936 { |
5937 /* | |
5938 * TODO: Add protection for 256 char max. | |
5939 */ | |
5940 | |
5941 CInfoPBRec theCPB; | |
5942 char_u fname[256]; | |
5943 char_u *filenamePtr = fname; | |
5944 OSErr error; | |
5945 int folder = 1; | |
5946 #ifdef USE_UNIXFILENAME | |
5947 SInt16 dfltVol_vRefNum; | |
5948 SInt32 dfltVol_dirID; | |
5949 FSRef refFile; | |
5950 OSStatus status; | |
5951 UInt32 pathSize = 256; | |
5952 char_u pathname[256]; | |
5953 char_u *path = pathname; | |
5954 #else | |
5955 Str255 directoryName; | |
5956 char_u temporary[255]; | |
5957 char_u *temporaryPtr = temporary; | |
5958 #endif | |
5959 | |
5960 #ifdef USE_UNIXFILENAME | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5961 // Get the default volume |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5962 // TODO: Remove as this only work if Vim is on the Boot Volume |
9 | 5963 error=HGetVol(NULL, &dfltVol_vRefNum, &dfltVol_dirID); |
7 | 5964 |
5965 if (error) | |
5966 return NULL; | |
5967 #endif | |
5968 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5969 // Start filling fname with file.name |
418 | 5970 vim_strncpy(filenamePtr, &file.name[1], file.name[0]); |
7 | 5971 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5972 // Get the info about the file specified in FSSpec |
7 | 5973 theCPB.dirInfo.ioFDirIndex = 0; |
5974 theCPB.dirInfo.ioNamePtr = file.name; | |
5975 theCPB.dirInfo.ioVRefNum = file.vRefNum; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5976 //theCPB.hFileInfo.ioDirID = 0; |
7 | 5977 theCPB.dirInfo.ioDrDirID = file.parID; |
5978 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5979 // As ioFDirIndex = 0, get the info of ioNamePtr, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5980 // which is relative to ioVrefNum, ioDirID |
9 | 5981 error = PBGetCatInfo(&theCPB, false); |
7 | 5982 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5983 // If we are called for a new file we expect fnfErr |
7 | 5984 if ((error) && (error != fnfErr)) |
5985 return NULL; | |
5986 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5987 // Check if it's a file or folder |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5988 // default to file if file don't exist |
7 | 5989 if (((theCPB.hFileInfo.ioFlAttrib & ioDirMask) == 0) || (error)) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5990 folder = 0; // It's not a folder |
7 | 5991 else |
5992 folder = 1; | |
5993 | |
5994 #ifdef USE_UNIXFILENAME | |
5995 /* | |
4352 | 5996 * The functions used here are available in Carbon, but do nothing on |
5997 * MacOS 8 and 9. | |
7 | 5998 */ |
5999 if (error == fnfErr) | |
6000 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6001 // If the file to be saved does not already exist, it isn't possible |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6002 // to convert its FSSpec into an FSRef. But we can construct an |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6003 // FSSpec for the file's parent folder (since we have its volume and |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6004 // directory IDs), and since that folder does exist, we can convert |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6005 // that FSSpec into an FSRef, convert the FSRef in turn into a path, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6006 // and, finally, append the filename. |
7 | 6007 FSSpec dirSpec; |
6008 FSRef dirRef; | |
6009 Str255 emptyFilename = "\p"; | |
6010 error = FSMakeFSSpec(theCPB.dirInfo.ioVRefNum, | |
6011 theCPB.dirInfo.ioDrDirID, emptyFilename, &dirSpec); | |
6012 if (error) | |
6013 return NULL; | |
6014 | |
6015 error = FSpMakeFSRef(&dirSpec, &dirRef); | |
6016 if (error) | |
6017 return NULL; | |
6018 | |
6019 status = FSRefMakePath(&dirRef, (UInt8*)path, pathSize); | |
6020 if (status) | |
6021 return NULL; | |
6022 | |
6023 STRCAT(path, "/"); | |
6024 STRCAT(path, filenamePtr); | |
6025 } | |
6026 else | |
6027 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6028 // If the file to be saved already exists, we can get its full path |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6029 // by converting its FSSpec into an FSRef. |
9 | 6030 error=FSpMakeFSRef(&file, &refFile); |
7 | 6031 if (error) |
6032 return NULL; | |
6033 | |
9 | 6034 status=FSRefMakePath(&refFile, (UInt8 *) path, pathSize); |
7 | 6035 if (status) |
6036 return NULL; | |
6037 } | |
6038 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6039 // Add a slash at the end if needed |
7 | 6040 if (folder) |
9 | 6041 STRCAT(path, "/"); |
6042 | |
6043 return (vim_strsave(path)); | |
7 | 6044 #else |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6045 // TODO: Get rid of all USE_UNIXFILENAME below |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6046 // Set ioNamePtr, it's the same area which is always reused. |
7 | 6047 theCPB.dirInfo.ioNamePtr = directoryName; |
6048 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6049 // Trick for first entry, set ioDrParID to the first value |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6050 // we want for ioDrDirID |
7 | 6051 theCPB.dirInfo.ioDrParID = file.parID; |
6052 theCPB.dirInfo.ioDrDirID = file.parID; | |
6053 | |
9 | 6054 if ((TRUE) && (file.parID != fsRtDirID /*fsRtParID*/)) |
7 | 6055 do |
6056 { | |
6057 theCPB.dirInfo.ioFDirIndex = -1; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6058 // theCPB.dirInfo.ioNamePtr = directoryName; Already done above. |
7 | 6059 theCPB.dirInfo.ioVRefNum = file.vRefNum; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6060 // theCPB.dirInfo.ioDirID = irrelevant when ioFDirIndex = -1 |
7 | 6061 theCPB.dirInfo.ioDrDirID = theCPB.dirInfo.ioDrParID; |
6062 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6063 // As ioFDirIndex = -1, get the info of ioDrDirID, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6064 // *ioNamePtr[0 TO 31] will be updated |
9 | 6065 error = PBGetCatInfo(&theCPB,false); |
7 | 6066 |
6067 if (error) | |
6068 return NULL; | |
6069 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6070 // Put the new directoryName in front of the current fname |
7 | 6071 STRCPY(temporaryPtr, filenamePtr); |
418 | 6072 vim_strncpy(filenamePtr, &directoryName[1], directoryName[0]); |
7 | 6073 STRCAT(filenamePtr, ":"); |
6074 STRCAT(filenamePtr, temporaryPtr); | |
6075 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6076 #if 1 // def USE_UNIXFILENAME |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6077 while ((theCPB.dirInfo.ioDrParID != fsRtDirID) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6078 /* && (theCPB.dirInfo.ioDrDirID != fsRtDirID)*/); |
7 | 6079 #else |
6080 while (theCPB.dirInfo.ioDrDirID != fsRtDirID); | |
6081 #endif | |
6082 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6083 // Get the information about the volume on which the file reside |
7 | 6084 theCPB.dirInfo.ioFDirIndex = -1; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6085 // theCPB.dirInfo.ioNamePtr = directoryName; Already done above. |
7 | 6086 theCPB.dirInfo.ioVRefNum = file.vRefNum; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6087 // theCPB.dirInfo.ioDirID = irrelevant when ioFDirIndex = -1 |
7 | 6088 theCPB.dirInfo.ioDrDirID = theCPB.dirInfo.ioDrParID; |
6089 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6090 // As ioFDirIndex = -1, get the info of ioDrDirID, |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6091 // *ioNamePtr[0 TO 31] will be updated |
9 | 6092 error = PBGetCatInfo(&theCPB,false); |
7 | 6093 |
6094 if (error) | |
6095 return NULL; | |
6096 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6097 // For MacOS Classic always add the volume name |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6098 // For MacOS X add the volume name preceded by "Volumes" |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6099 // when we are not referring to the boot volume |
7 | 6100 #ifdef USE_UNIXFILENAME |
6101 if (file.vRefNum != dfltVol_vRefNum) | |
6102 #endif | |
6103 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6104 // Add the volume name |
7 | 6105 STRCPY(temporaryPtr, filenamePtr); |
418 | 6106 vim_strncpy(filenamePtr, &directoryName[1], directoryName[0]); |
7 | 6107 STRCAT(filenamePtr, ":"); |
6108 STRCAT(filenamePtr, temporaryPtr); | |
6109 | |
6110 #ifdef USE_UNIXFILENAME | |
6111 STRCPY(temporaryPtr, filenamePtr); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6112 filenamePtr[0] = 0; // NULL terminate the string |
7 | 6113 STRCAT(filenamePtr, "Volumes:"); |
6114 STRCAT(filenamePtr, temporaryPtr); | |
6115 #endif | |
6116 } | |
6117 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6118 // Append final path separator if it's a folder |
7 | 6119 if (folder) |
9 | 6120 STRCAT(fname, ":"); |
7 | 6121 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6122 // As we use Unix File Name for MacOS X convert it |
7 | 6123 #ifdef USE_UNIXFILENAME |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6124 // Need to insert leading / |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6125 // TODO: get the above code to use directly the / |
7 | 6126 STRCPY(&temporaryPtr[1], filenamePtr); |
6127 temporaryPtr[0] = '/'; | |
6128 STRCPY(filenamePtr, temporaryPtr); | |
6129 { | |
6130 char *p; | |
6131 for (p = fname; *p; p++) | |
6132 if (*p == ':') | |
6133 *p = '/'; | |
6134 } | |
6135 #endif | |
6136 | |
9 | 6137 return (vim_strsave(fname)); |
7 | 6138 #endif |
6139 } | |
6140 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6141 #if defined(USE_CARBONKEYHANDLER) || defined(PROTO) |
7 | 6142 /* |
6143 * Input Method Control functions. | |
6144 */ | |
6145 | |
6146 /* | |
6147 * Notify cursor position to IM. | |
6148 */ | |
6149 void | |
6150 im_set_position(int row, int col) | |
6151 { | |
13950
741b1feeac9f
patch 8.0.1845: various comment updates needed, missing white space
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6152 # if 0 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6153 // TODO: Implement me! |
1562 | 6154 im_start_row = row; |
6155 im_start_col = col; | |
13950
741b1feeac9f
patch 8.0.1845: various comment updates needed, missing white space
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6156 # endif |
1562 | 6157 } |
6158 | |
6159 static ScriptLanguageRecord gTSLWindow; | |
6160 static ScriptLanguageRecord gTSLInsert; | |
6161 static ScriptLanguageRecord gTSLDefault = { 0, 0 }; | |
6162 | |
6163 static Component gTSCWindow; | |
6164 static Component gTSCInsert; | |
6165 static Component gTSCDefault; | |
6166 | |
6167 static int im_initialized = 0; | |
6168 | |
6169 static void | |
6170 im_on_window_switch(int active) | |
6171 { | |
6172 ScriptLanguageRecord *slptr = NULL; | |
6173 OSStatus err; | |
6174 | |
6175 if (! gui.in_use) | |
6176 return; | |
6177 | |
6178 if (im_initialized == 0) | |
6179 { | |
6180 im_initialized = 1; | |
6181 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6182 // save default TSM component (should be U.S.) to default |
1562 | 6183 GetDefaultInputMethodOfClass(&gTSCDefault, &gTSLDefault, |
6184 kKeyboardInputMethodClass); | |
6185 } | |
6186 | |
6187 if (active == TRUE) | |
6188 { | |
6189 im_is_active = TRUE; | |
6190 ActivateTSMDocument(gTSMDocument); | |
6191 slptr = &gTSLWindow; | |
6192 | |
6193 if (slptr) | |
6194 { | |
6195 err = SetDefaultInputMethodOfClass(gTSCWindow, slptr, | |
6196 kKeyboardInputMethodClass); | |
6197 if (err == noErr) | |
6198 err = SetTextServiceLanguage(slptr); | |
6199 | |
6200 if (err == noErr) | |
6201 KeyScript(slptr->fScript | smKeyForceKeyScriptMask); | |
6202 } | |
6203 } | |
6204 else | |
6205 { | |
6206 err = GetTextServiceLanguage(&gTSLWindow); | |
6207 if (err == noErr) | |
6208 slptr = &gTSLWindow; | |
6209 | |
6210 if (slptr) | |
6211 GetDefaultInputMethodOfClass(&gTSCWindow, slptr, | |
6212 kKeyboardInputMethodClass); | |
6213 | |
6214 im_is_active = FALSE; | |
6215 DeactivateTSMDocument(gTSMDocument); | |
6216 } | |
7 | 6217 } |
6218 | |
6219 /* | |
6220 * Set IM status on ("active" is TRUE) or off ("active" is FALSE). | |
6221 */ | |
6222 void | |
6223 im_set_active(int active) | |
6224 { | |
1562 | 6225 ScriptLanguageRecord *slptr = NULL; |
6226 OSStatus err; | |
6227 | |
12924
85a601f985ab
patch 8.0.1338: USE_IM_CONTROL is confusing and incomplete
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
6228 if (!gui.in_use) |
1562 | 6229 return; |
6230 | |
6231 if (im_initialized == 0) | |
6232 { | |
6233 im_initialized = 1; | |
6234 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6235 // save default TSM component (should be U.S.) to default |
1562 | 6236 GetDefaultInputMethodOfClass(&gTSCDefault, &gTSLDefault, |
6237 kKeyboardInputMethodClass); | |
6238 } | |
6239 | |
6240 if (active == TRUE) | |
6241 { | |
6242 im_is_active = TRUE; | |
6243 ActivateTSMDocument(gTSMDocument); | |
6244 slptr = &gTSLInsert; | |
6245 | |
6246 if (slptr) | |
6247 { | |
6248 err = SetDefaultInputMethodOfClass(gTSCInsert, slptr, | |
6249 kKeyboardInputMethodClass); | |
6250 if (err == noErr) | |
6251 err = SetTextServiceLanguage(slptr); | |
6252 | |
6253 if (err == noErr) | |
6254 KeyScript(slptr->fScript | smKeyForceKeyScriptMask); | |
6255 } | |
6256 } | |
6257 else | |
6258 { | |
6259 err = GetTextServiceLanguage(&gTSLInsert); | |
6260 if (err == noErr) | |
6261 slptr = &gTSLInsert; | |
6262 | |
6263 if (slptr) | |
6264 GetDefaultInputMethodOfClass(&gTSCInsert, slptr, | |
6265 kKeyboardInputMethodClass); | |
6266 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6267 // restore to default when switch to normal mode, so than we could |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6268 // enter commands easier |
1562 | 6269 SetDefaultInputMethodOfClass(gTSCDefault, &gTSLDefault, |
6270 kKeyboardInputMethodClass); | |
6271 SetTextServiceLanguage(&gTSLDefault); | |
6272 | |
6273 im_is_active = FALSE; | |
6274 DeactivateTSMDocument(gTSMDocument); | |
6275 } | |
7 | 6276 } |
6277 | |
6278 /* | |
6279 * Get IM status. When IM is on, return not 0. Else return 0. | |
6280 */ | |
6281 int | |
593 | 6282 im_get_status(void) |
7 | 6283 { |
1562 | 6284 if (! gui.in_use) |
6285 return 0; | |
6286 | |
6287 return im_is_active; | |
7 | 6288 } |
1106 | 6289 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6290 #endif |
1106 | 6291 |
6292 | |
6293 | |
6294 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) | |
6295 // drawer implementation | |
6296 static MenuRef contextMenu = NULL; | |
6297 enum | |
6298 { | |
8269
553a4c8dd796
commit https://github.com/vim/vim/commit/43acbce1bb0a33edc67496b220cae629ad95d2d8
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
6299 kTabContextMenuId = 42 |
1106 | 6300 }; |
6301 | |
6302 // the caller has to CFRelease() the returned string | |
6303 static CFStringRef | |
6304 getTabLabel(tabpage_T *page) | |
6305 { | |
6306 get_tabline_label(page, FALSE); | |
6307 #ifdef MACOS_CONVERT | |
1621 | 6308 return (CFStringRef)mac_enc_to_cfstring(NameBuff, STRLEN(NameBuff)); |
1106 | 6309 #else |
6310 // TODO: check internal encoding? | |
6311 return CFStringCreateWithCString(kCFAllocatorDefault, (char *)NameBuff, | |
6312 kCFStringEncodingMacRoman); | |
6313 #endif | |
6314 } | |
6315 | |
6316 | |
6317 #define DRAWER_SIZE 150 | |
6318 #define DRAWER_INSET 16 | |
6319 | |
6320 static ControlRef dataBrowser = NULL; | |
6321 | |
6322 // when the tabline is hidden, vim doesn't call update_tabline(). When | |
2585 | 6323 // the tabline is shown again, show_tabline() is called before update_tabline(), |
4352 | 6324 // and because of this, the tab labels and vim's internal tabs are out of sync |
1106 | 6325 // for a very short time. to prevent inconsistent state, we store the labels |
6326 // of the tabs, not pointers to the tabs (which are invalid for a short time). | |
6327 static CFStringRef *tabLabels = NULL; | |
6328 static int tabLabelsSize = 0; | |
6329 | |
6330 enum | |
6331 { | |
6332 kTabsColumn = 'Tabs' | |
6333 }; | |
6334 | |
6335 static int | |
6336 getTabCount(void) | |
6337 { | |
6338 tabpage_T *tp; | |
6339 int numTabs = 0; | |
6340 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
6341 FOR_ALL_TABPAGES(tp) |
1562 | 6342 ++numTabs; |
1106 | 6343 return numTabs; |
6344 } | |
6345 | |
6346 // data browser item display callback | |
6347 static OSStatus | |
6348 dbItemDataCallback(ControlRef browser, | |
6349 DataBrowserItemID itemID, | |
1562 | 6350 DataBrowserPropertyID property /* column id */, |
6351 DataBrowserItemDataRef itemData, | |
1106 | 6352 Boolean changeValue) |
6353 { | |
6354 OSStatus status = noErr; | |
6355 | |
6356 // assert(property == kTabsColumn); // why is this violated?? | |
6357 | |
4352 | 6358 // changeValue is true if we have a modifiable list and data was changed. |
1106 | 6359 // In our case, it's always false. |
6360 // (that is: if (changeValue) updateInternalData(); else return | |
6361 // internalData(); | |
6362 if (!changeValue) | |
6363 { | |
6364 CFStringRef str; | |
6365 | |
6366 assert(itemID - 1 >= 0 && itemID - 1 < tabLabelsSize); | |
6367 str = tabLabels[itemID - 1]; | |
6368 status = SetDataBrowserItemDataText(itemData, str); | |
6369 } | |
6370 else | |
6371 status = errDataBrowserPropertyNotSupported; | |
6372 | |
6373 return status; | |
6374 } | |
6375 | |
6376 // data browser action callback | |
6377 static void | |
6378 dbItemNotificationCallback(ControlRef browser, | |
6379 DataBrowserItemID item, | |
6380 DataBrowserItemNotification message) | |
6381 { | |
6382 switch (message) | |
6383 { | |
6384 case kDataBrowserItemSelected: | |
6385 send_tabline_event(item); | |
6386 break; | |
6387 } | |
6388 } | |
6389 | |
6390 // callbacks needed for contextual menu: | |
6391 static void | |
6392 dbGetContextualMenuCallback(ControlRef browser, | |
6393 MenuRef *menu, | |
1562 | 6394 UInt32 *helpType, |
1106 | 6395 CFStringRef *helpItemString, |
1562 | 6396 AEDesc *selection) |
1106 | 6397 { |
6398 // on mac os 9: kCMHelpItemNoHelp, but it's not the same | |
6399 *helpType = kCMHelpItemRemoveHelp; // OS X only ;-) | |
6400 *helpItemString = NULL; | |
6401 | |
6402 *menu = contextMenu; | |
6403 } | |
6404 | |
6405 static void | |
6406 dbSelectContextualMenuCallback(ControlRef browser, | |
6407 MenuRef menu, | |
6408 UInt32 selectionType, | |
6409 SInt16 menuID, | |
6410 MenuItemIndex menuItem) | |
6411 { | |
6412 if (selectionType == kCMMenuItemSelected) | |
6413 { | |
6414 MenuCommand command; | |
6415 GetMenuItemCommandID(menu, menuItem, &command); | |
6416 | |
6417 // get tab that was selected when the context menu appeared | |
6418 // (there is always one tab selected). TODO: check if the context menu | |
6419 // isn't opened on an item but on empty space (has to be possible some | |
6420 // way, the finder does it too ;-) ) | |
6421 Handle items = NewHandle(0); | |
6422 if (items != NULL) | |
6423 { | |
6424 int numItems; | |
6425 | |
6426 GetDataBrowserItems(browser, kDataBrowserNoItem, false, | |
6427 kDataBrowserItemIsSelected, items); | |
6428 numItems = GetHandleSize(items) / sizeof(DataBrowserItemID); | |
6429 if (numItems > 0) | |
6430 { | |
6431 int idx; | |
6432 DataBrowserItemID *itemsPtr; | |
6433 | |
6434 HLock(items); | |
6435 itemsPtr = (DataBrowserItemID *)*items; | |
6436 idx = itemsPtr[0]; | |
6437 HUnlock(items); | |
6438 send_tabline_menu_event(idx, command); | |
6439 } | |
6440 DisposeHandle(items); | |
6441 } | |
6442 } | |
6443 } | |
6444 | |
6445 // focus callback of the data browser to always leave focus in vim | |
6446 static OSStatus | |
6447 dbFocusCallback(EventHandlerCallRef handler, EventRef event, void *data) | |
6448 { | |
6449 assert(GetEventClass(event) == kEventClassControl | |
6450 && GetEventKind(event) == kEventControlSetFocusPart); | |
6451 | |
6452 return paramErr; | |
6453 } | |
6454 | |
6455 | |
6456 // drawer callback to resize data browser to drawer size | |
6457 static OSStatus | |
6458 drawerCallback(EventHandlerCallRef handler, EventRef event, void *data) | |
6459 { | |
6460 switch (GetEventKind(event)) | |
6461 { | |
6462 case kEventWindowBoundsChanged: // move or resize | |
6463 { | |
6464 UInt32 attribs; | |
6465 GetEventParameter(event, kEventParamAttributes, typeUInt32, | |
6466 NULL, sizeof(attribs), NULL, &attribs); | |
6467 if (attribs & kWindowBoundsChangeSizeChanged) // resize | |
6468 { | |
6469 Rect r; | |
6470 GetWindowBounds(drawer, kWindowContentRgn, &r); | |
6471 SetRect(&r, 0, 0, r.right - r.left, r.bottom - r.top); | |
6472 SetControlBounds(dataBrowser, &r); | |
6473 SetDataBrowserTableViewNamedColumnWidth(dataBrowser, | |
6474 kTabsColumn, r.right); | |
6475 } | |
6476 } | |
6477 break; | |
6478 } | |
6479 | |
6480 return eventNotHandledErr; | |
6481 } | |
6482 | |
6483 // Load DataBrowserChangeAttributes() dynamically on tiger (and better). | |
6484 // This way the code works on 10.2 and 10.3 as well (it doesn't have the | |
6485 // blue highlights in the list view on these systems, though. Oh well.) | |
6486 | |
6487 | |
6488 #import <mach-o/dyld.h> | |
6489 | |
6490 enum { kMyDataBrowserAttributeListViewAlternatingRowColors = (1 << 1) }; | |
6491 | |
6492 static OSStatus | |
6493 myDataBrowserChangeAttributes(ControlRef inDataBrowser, | |
6494 OptionBits inAttributesToSet, | |
6495 OptionBits inAttributesToClear) | |
6496 { | |
6497 long osVersion; | |
6498 char *symbolName; | |
6499 NSSymbol symbol = NULL; | |
6500 OSStatus (*dataBrowserChangeAttributes)(ControlRef inDataBrowser, | |
6501 OptionBits inAttributesToSet, OptionBits inAttributesToClear); | |
6502 | |
6503 Gestalt(gestaltSystemVersion, &osVersion); | |
6504 if (osVersion < 0x1040) // only supported for 10.4 (and up) | |
6505 return noErr; | |
6506 | |
6507 // C name mangling... | |
6508 symbolName = "_DataBrowserChangeAttributes"; | |
6509 if (!NSIsSymbolNameDefined(symbolName) | |
6510 || (symbol = NSLookupAndBindSymbol(symbolName)) == NULL) | |
6511 return noErr; | |
6512 | |
6513 dataBrowserChangeAttributes = NSAddressOfSymbol(symbol); | |
6514 if (dataBrowserChangeAttributes == NULL) | |
6515 return noErr; // well... | |
6516 return dataBrowserChangeAttributes(inDataBrowser, | |
6517 inAttributesToSet, inAttributesToClear); | |
6518 } | |
6519 | |
6520 static void | |
6521 initialise_tabline(void) | |
6522 { | |
6523 Rect drawerRect = { 0, 0, 0, DRAWER_SIZE }; | |
6524 DataBrowserCallbacks dbCallbacks; | |
6525 EventTypeSpec focusEvent = {kEventClassControl, kEventControlSetFocusPart}; | |
6526 EventTypeSpec resizeEvent = {kEventClassWindow, kEventWindowBoundsChanged}; | |
6527 DataBrowserListViewColumnDesc colDesc; | |
6528 | |
6529 // drawers have to have compositing enabled | |
6530 CreateNewWindow(kDrawerWindowClass, | |
6531 kWindowStandardHandlerAttribute | |
6532 | kWindowCompositingAttribute | |
6533 | kWindowResizableAttribute | |
6534 | kWindowLiveResizeAttribute, | |
6535 &drawerRect, &drawer); | |
6536 | |
6537 SetThemeWindowBackground(drawer, kThemeBrushDrawerBackground, true); | |
6538 SetDrawerParent(drawer, gui.VimWindow); | |
6539 SetDrawerOffsets(drawer, kWindowOffsetUnchanged, DRAWER_INSET); | |
6540 | |
6541 | |
6542 // create list view embedded in drawer | |
6543 CreateDataBrowserControl(drawer, &drawerRect, kDataBrowserListView, | |
6544 &dataBrowser); | |
6545 | |
6546 dbCallbacks.version = kDataBrowserLatestCallbacks; | |
6547 InitDataBrowserCallbacks(&dbCallbacks); | |
6548 dbCallbacks.u.v1.itemDataCallback = | |
6549 NewDataBrowserItemDataUPP(dbItemDataCallback); | |
6550 dbCallbacks.u.v1.itemNotificationCallback = | |
6551 NewDataBrowserItemNotificationUPP(dbItemNotificationCallback); | |
6552 dbCallbacks.u.v1.getContextualMenuCallback = | |
6553 NewDataBrowserGetContextualMenuUPP(dbGetContextualMenuCallback); | |
6554 dbCallbacks.u.v1.selectContextualMenuCallback = | |
6555 NewDataBrowserSelectContextualMenuUPP(dbSelectContextualMenuCallback); | |
6556 | |
6557 SetDataBrowserCallbacks(dataBrowser, &dbCallbacks); | |
6558 | |
6559 SetDataBrowserListViewHeaderBtnHeight(dataBrowser, 0); // no header | |
6560 SetDataBrowserHasScrollBars(dataBrowser, false, true); // only vertical | |
6561 SetDataBrowserSelectionFlags(dataBrowser, | |
6562 kDataBrowserSelectOnlyOne | kDataBrowserNeverEmptySelectionSet); | |
6563 SetDataBrowserTableViewHiliteStyle(dataBrowser, | |
6564 kDataBrowserTableViewFillHilite); | |
6565 Boolean b = false; | |
6566 SetControlData(dataBrowser, kControlEntireControl, | |
6567 kControlDataBrowserIncludesFrameAndFocusTag, sizeof(b), &b); | |
6568 | |
6569 // enable blue background in data browser (this is only in 10.4 and vim | |
6570 // has to support older osx versions as well, so we have to load this | |
6571 // function dynamically) | |
6572 myDataBrowserChangeAttributes(dataBrowser, | |
6573 kMyDataBrowserAttributeListViewAlternatingRowColors, 0); | |
6574 | |
6575 // install callback that keeps focus in vim and away from the data browser | |
6576 InstallControlEventHandler(dataBrowser, dbFocusCallback, 1, &focusEvent, | |
6577 NULL, NULL); | |
6578 | |
6579 // install callback that keeps data browser at the size of the drawer | |
6580 InstallWindowEventHandler(drawer, drawerCallback, 1, &resizeEvent, | |
6581 NULL, NULL); | |
6582 | |
6583 // add "tabs" column to data browser | |
6584 colDesc.propertyDesc.propertyID = kTabsColumn; | |
6585 colDesc.propertyDesc.propertyType = kDataBrowserTextType; | |
6586 | |
6587 // add if items can be selected (?): kDataBrowserListViewSelectionColumn | |
6588 colDesc.propertyDesc.propertyFlags = kDataBrowserDefaultPropertyFlags; | |
6589 | |
6590 colDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; | |
6591 colDesc.headerBtnDesc.minimumWidth = 100; | |
6592 colDesc.headerBtnDesc.maximumWidth = 150; | |
6593 colDesc.headerBtnDesc.titleOffset = 0; | |
6594 colDesc.headerBtnDesc.titleString = CFSTR("Tabs"); | |
6595 colDesc.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing; | |
6596 colDesc.headerBtnDesc.btnFontStyle.flags = 0; // use default font | |
6597 colDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly; | |
6598 | |
6599 AddDataBrowserListViewColumn(dataBrowser, &colDesc, 0); | |
6600 | |
6601 // create tabline popup menu required by vim docs (see :he tabline-menu) | |
6602 CreateNewMenu(kTabContextMenuId, 0, &contextMenu); | |
15134
f2972ff144ab
patch 8.1.0577: tabpage right-click menu never shows "Close tab"
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
6603 AppendMenuItemTextWithCFString(contextMenu, CFSTR("Close Tab"), 0, |
1106 | 6604 TABLINE_MENU_CLOSE, NULL); |
6605 AppendMenuItemTextWithCFString(contextMenu, CFSTR("New Tab"), 0, | |
6606 TABLINE_MENU_NEW, NULL); | |
6607 AppendMenuItemTextWithCFString(contextMenu, CFSTR("Open Tab..."), 0, | |
6608 TABLINE_MENU_OPEN, NULL); | |
6609 } | |
6610 | |
6611 | |
6612 /* | |
6613 * Show or hide the tabline. | |
6614 */ | |
6615 void | |
6616 gui_mch_show_tabline(int showit) | |
6617 { | |
6618 if (showit == 0) | |
1562 | 6619 CloseDrawer(drawer, true); |
1106 | 6620 else |
1562 | 6621 OpenDrawer(drawer, kWindowEdgeRight, true); |
1106 | 6622 } |
6623 | |
6624 /* | |
6625 * Return TRUE when tabline is displayed. | |
6626 */ | |
6627 int | |
6628 gui_mch_showing_tabline(void) | |
6629 { | |
6630 WindowDrawerState state = GetDrawerState(drawer); | |
6631 | |
6632 return state == kWindowDrawerOpen || state == kWindowDrawerOpening; | |
6633 } | |
6634 | |
6635 /* | |
6636 * Update the labels of the tabline. | |
6637 */ | |
6638 void | |
6639 gui_mch_update_tabline(void) | |
6640 { | |
6641 tabpage_T *tp; | |
6642 int numTabs = getTabCount(); | |
6643 int nr = 1; | |
6644 int curtabidx = 1; | |
6645 | |
6646 // adjust data browser | |
6647 if (tabLabels != NULL) | |
6648 { | |
1562 | 6649 int i; |
6650 | |
6651 for (i = 0; i < tabLabelsSize; ++i) | |
6652 CFRelease(tabLabels[i]); | |
6653 free(tabLabels); | |
1106 | 6654 } |
6655 tabLabels = (CFStringRef *)malloc(numTabs * sizeof(CFStringRef)); | |
6656 tabLabelsSize = numTabs; | |
6657 | |
6658 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | |
6659 { | |
6660 if (tp == curtab) | |
6661 curtabidx = nr; | |
1562 | 6662 tabLabels[nr-1] = getTabLabel(tp); |
1106 | 6663 } |
6664 | |
6665 RemoveDataBrowserItems(dataBrowser, kDataBrowserNoItem, 0, NULL, | |
6666 kDataBrowserItemNoProperty); | |
6667 // data browser uses ids 1, 2, 3, ... numTabs per default, so we | |
6668 // can pass NULL for the id array | |
6669 AddDataBrowserItems(dataBrowser, kDataBrowserNoItem, numTabs, NULL, | |
6670 kDataBrowserItemNoProperty); | |
6671 | |
6672 DataBrowserItemID item = curtabidx; | |
6673 SetDataBrowserSelectedItems(dataBrowser, 1, &item, kDataBrowserItemsAssign); | |
6674 } | |
6675 | |
6676 /* | |
6677 * Set the current tab to "nr". First tab is 1. | |
6678 */ | |
6679 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
6680 gui_mch_set_curtab(int nr) |
1106 | 6681 { |
6682 DataBrowserItemID item = nr; | |
6683 SetDataBrowserSelectedItems(dataBrowser, 1, &item, kDataBrowserItemsAssign); | |
6684 | |
6685 // TODO: call something like this?: (or restore scroll position, or...) | |
6686 RevealDataBrowserItem(dataBrowser, item, kTabsColumn, | |
6687 kDataBrowserRevealOnly); | |
6688 } | |
6689 | |
6690 #endif // FEAT_GUI_TABLINE |