Mercurial > vim
annotate src/gui_mac.c @ 19683:dd028abdde0f v8.2.0398
patch 8.2.0398: profile test fails when two functions take same time
Commit: https://github.com/vim/vim/commit/a21df1db3ca619afdcb47931af042508a6bbc8e5
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Mar 17 20:57:09 2020 +0100
patch 8.2.0398: profile test fails when two functions take same time
Problem: Profile test fails when two functions take same time.
Solution: Add a short sleep in once function. (closes https://github.com/vim/vim/issues/5797)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 17 Mar 2020 21:00:06 +0100 |
parents | 2ef19eed524a |
children | aadd1cae2ff5 |
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 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2171 // Interpret META, include SHIFT, etc. |
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, |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
2173 TRUE, 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; | |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
4758 key = find_special_key(&p_actext, &modifiers, FALSE, FALSE, FALSE, |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
4759 TRUE, NULL); |
7 | 4760 if (*p_actext != 0) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4761 key = 0; // error: trailing text |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4762 // 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
|
4763 // 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
|
4764 // "<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
|
4765 // 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
|
4766 // 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
|
4767 // character plus modifiers. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4768 // 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
|
4769 // apply modifiers. |
7 | 4770 if (key > 0 && key < 32) |
4771 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4772 // 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
|
4773 // 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
|
4774 // between, e.g., Ctrl-S and Ctrl-Shift-S. |
7 | 4775 modifiers |= MOD_MASK_CTRL; |
4776 key += '@'; | |
4777 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4778 // 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
|
4779 // 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
|
4780 // the letter to uppercase for display in the menu. |
7 | 4781 else if (key >= 'A' && key <= 'Z') |
4782 modifiers |= MOD_MASK_SHIFT; | |
4783 else if (key >= 'a' && key <= 'z') | |
4784 key += 'A' - 'a'; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4785 // Note: keycodes below 0x22 are reserved by Apple. |
7 | 4786 if (key >= 0x22 && vim_isprintc_strict(key)) |
4787 { | |
4788 int valid = 1; | |
4789 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
|
4790 // Convert Vim modifier codes to Menu Manager equivalents. |
7 | 4791 if (modifiers & MOD_MASK_SHIFT) |
4792 mac_mods |= kMenuShiftModifier; | |
4793 if (modifiers & MOD_MASK_CTRL) | |
4794 mac_mods |= kMenuControlModifier; | |
4795 if (!(modifiers & MOD_MASK_CMD)) | |
4796 mac_mods |= kMenuNoCommandModifier; | |
4797 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
|
4798 valid = 0; // TODO: will Alt someday map to Option? |
7 | 4799 if (valid) |
4800 { | |
4801 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
|
4802 // Insert the menu item after idx, with its command key. |
7 | 4803 item_txt[0] = 3; item_txt[1] = ' '; item_txt[2] = '/'; |
4804 item_txt[3] = key; | |
4805 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
|
4806 // Set the modifier keys. |
7 | 4807 SetMenuItemModifiers(parent->submenu_handle, idx+1, mac_mods); |
4808 menu_inserted = 1; | |
4809 } | |
4810 } | |
4811 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4812 // Call InsertMenuItem followed by SetMenuItemText |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4813 // to avoid special character recognition by InsertMenuItem |
7 | 4814 if (!menu_inserted) |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4815 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
|
4816 // Set the menu item name. |
168 | 4817 SetMenuItemTextWithCFString(parent->submenu_handle, idx+1, name); |
7 | 4818 |
4819 #if 0 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4820 // Called by Vim |
7 | 4821 DrawMenuBar(); |
4822 #endif | |
4823 | |
168 | 4824 CFRelease(name); |
7 | 4825 } |
4826 | |
4827 void | |
593 | 4828 gui_mch_toggle_tearoffs(int enable) |
7 | 4829 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4830 // no tearoff menus |
7 | 4831 } |
4832 | |
4833 /* | |
4834 * Destroy the machine specific menu widget. | |
4835 */ | |
4836 void | |
593 | 4837 gui_mch_destroy_menu(vimmenu_T *menu) |
7 | 4838 { |
9 | 4839 short index = gui_mac_get_menu_item_index(menu); |
7 | 4840 |
4841 if (index > 0) | |
4842 { | |
4843 if (menu->parent) | |
4844 { | |
4845 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4846 // For now just don't delete help menu items. (Huh? Dany) |
9 | 4847 DeleteMenuItem(menu->parent->submenu_handle, index); |
7 | 4848 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4849 // Delete the Menu if it was a hierarchical Menu |
7 | 4850 if (menu->submenu_id != 0) |
4851 { | |
9 | 4852 DeleteMenu(menu->submenu_id); |
4853 DisposeMenu(menu->submenu_handle); | |
7 | 4854 } |
4855 } | |
4856 } | |
4857 #ifdef DEBUG_MAC_MENU | |
4858 else | |
4859 { | |
9 | 4860 printf("gmdm 2\n"); |
7 | 4861 } |
4862 #endif | |
4863 } | |
4864 else | |
4865 { | |
4866 { | |
9 | 4867 DeleteMenu(menu->submenu_id); |
4868 DisposeMenu(menu->submenu_handle); | |
7 | 4869 } |
4870 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4871 // Shouldn't this be already done by Vim. TODO: Check |
7 | 4872 DrawMenuBar(); |
4873 } | |
4874 | |
4875 /* | |
4876 * Make a menu either grey or not grey. | |
4877 */ | |
4878 void | |
593 | 4879 gui_mch_menu_grey(vimmenu_T *menu, int grey) |
7 | 4880 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4881 // TODO: Check if menu really exists |
9 | 4882 short index = gui_mac_get_menu_item_index(menu); |
7 | 4883 /* |
4884 index = menu->index; | |
4885 */ | |
4886 if (grey) | |
4887 { | |
4888 if (menu->children) | |
4889 DisableMenuItem(menu->submenu_handle, index); | |
4890 if (menu->parent) | |
4891 if (menu->parent->submenu_handle) | |
4892 DisableMenuItem(menu->parent->submenu_handle, index); | |
4893 } | |
4894 else | |
4895 { | |
4896 if (menu->children) | |
4897 EnableMenuItem(menu->submenu_handle, index); | |
4898 if (menu->parent) | |
4899 if (menu->parent->submenu_handle) | |
4900 EnableMenuItem(menu->parent->submenu_handle, index); | |
4901 } | |
4902 } | |
4903 | |
4904 /* | |
4905 * Make menu item hidden or not hidden | |
4906 */ | |
4907 void | |
593 | 4908 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) |
7 | 4909 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4910 // There's no hidden mode on MacOS |
9 | 4911 gui_mch_menu_grey(menu, hidden); |
7 | 4912 } |
4913 | |
4914 | |
4915 /* | |
4916 * This is called after setting all the menus to grey/hidden or not. | |
4917 */ | |
4918 void | |
593 | 4919 gui_mch_draw_menubar(void) |
7 | 4920 { |
4921 DrawMenuBar(); | |
4922 } | |
4923 | |
4924 | |
4925 /* | |
4926 * Scrollbar stuff. | |
4927 */ | |
4928 | |
4929 void | |
593 | 4930 gui_mch_enable_scrollbar( |
4931 scrollbar_T *sb, | |
4932 int flag) | |
7 | 4933 { |
4934 if (flag) | |
4935 ShowControl(sb->id); | |
4936 else | |
4937 HideControl(sb->id); | |
4938 | |
4939 #ifdef DEBUG_MAC_SB | |
9 | 4940 printf("enb_sb (%x) %x\n",sb->id, flag); |
7 | 4941 #endif |
4942 } | |
4943 | |
4944 void | |
593 | 4945 gui_mch_set_scrollbar_thumb( |
4946 scrollbar_T *sb, | |
4947 long val, | |
4948 long size, | |
4949 long max) | |
7 | 4950 { |
4951 SetControl32BitMaximum (sb->id, max); | |
4952 SetControl32BitMinimum (sb->id, 0); | |
4953 SetControl32BitValue (sb->id, val); | |
1107 | 4954 SetControlViewSize (sb->id, size); |
7 | 4955 #ifdef DEBUG_MAC_SB |
9199
665d10cb3e6b
commit https://github.com/vim/vim/commit/ea0345901cc2af29f9c5dd0d9d8a818d5f96a63b
Christian Brabandt <cb@256bit.org>
parents:
9013
diff
changeset
|
4956 printf("thumb_sb (%x) %lx, %lx,%lx\n",sb->id, val, size, max); |
7 | 4957 #endif |
4958 } | |
4959 | |
4960 void | |
593 | 4961 gui_mch_set_scrollbar_pos( |
4962 scrollbar_T *sb, | |
4963 int x, | |
4964 int y, | |
4965 int w, | |
4966 int h) | |
7 | 4967 { |
4968 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
|
4969 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4970 if (gui.which_scrollbars[SBAR_LEFT]) |
7 | 4971 { |
9 | 4972 MoveControl(sb->id, x-16, y); |
4973 SizeControl(sb->id, w + 1, h); | |
7 | 4974 } |
4975 else | |
4976 { | |
9 | 4977 MoveControl(sb->id, x, y); |
4978 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
|
4979 } |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4980 #endif |
7 | 4981 if (sb == &gui.bottom_sbar) |
4982 h += 1; | |
4983 else | |
4984 w += 1; | |
4985 | |
4986 if (gui.which_scrollbars[SBAR_LEFT]) | |
4987 x -= 15; | |
4988 | |
9 | 4989 MoveControl(sb->id, x, y); |
4990 SizeControl(sb->id, w, h); | |
7 | 4991 #ifdef DEBUG_MAC_SB |
9 | 4992 printf("size_sb (%x) %x, %x, %x, %x\n",sb->id, x, y, w, h); |
7 | 4993 #endif |
4994 } | |
4995 | |
4996 void | |
593 | 4997 gui_mch_create_scrollbar( |
4998 scrollbar_T *sb, | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
4999 int orient) // SBAR_VERT or SBAR_HORIZ |
7 | 5000 { |
5001 Rect bounds; | |
5002 | |
5003 bounds.top = -16; | |
5004 bounds.bottom = -10; | |
5005 bounds.right = -10; | |
5006 bounds.left = -16; | |
5007 | |
9 | 5008 sb->id = NewControl(gui.VimWindow, |
7 | 5009 &bounds, |
5010 "\pScrollBar", | |
5011 TRUE, | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5012 0, // current |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5013 0, // top |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5014 0, // bottom |
7 | 5015 kControlScrollBarLiveProc, |
5016 (long) sb->ident); | |
5017 #ifdef DEBUG_MAC_SB | |
9 | 5018 printf("create_sb (%x) %x\n",sb->id, orient); |
7 | 5019 #endif |
5020 } | |
5021 | |
5022 void | |
593 | 5023 gui_mch_destroy_scrollbar(scrollbar_T *sb) |
7 | 5024 { |
5025 gui_mch_set_bg_color(gui.back_pixel); | |
9 | 5026 DisposeControl(sb->id); |
7 | 5027 #ifdef DEBUG_MAC_SB |
9 | 5028 printf("dest_sb (%x) \n",sb->id); |
7 | 5029 #endif |
5030 } | |
5031 | |
9213
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5032 int |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5033 gui_mch_is_blinking(void) |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5034 { |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5035 return FALSE; |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9199
diff
changeset
|
5036 } |
7 | 5037 |
9428
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5038 int |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5039 gui_mch_is_blink_off(void) |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5040 { |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5041 return FALSE; |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5042 } |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
5043 |
7 | 5044 /* |
5045 * Cursor blink functions. | |
5046 * | |
5047 * This is a simple state machine: | |
5048 * BLINK_NONE not blinking at all | |
5049 * BLINK_OFF blinking, cursor is not shown | |
5050 * BLINK_ON blinking, cursor is shown | |
5051 */ | |
5052 void | |
5053 gui_mch_set_blinking(long wait, long on, long off) | |
5054 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5055 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5056 // TODO: TODO: TODO: TODO: |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5057 blink_waittime = wait; |
7 | 5058 blink_ontime = on; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5059 blink_offtime = off; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5060 #endif |
7 | 5061 } |
5062 | |
5063 /* | |
5064 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
5065 */ | |
5066 void | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5067 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
|
5068 { |
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
5069 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
|
5070 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
|
5071 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5072 // TODO: TODO: TODO: TODO: |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5073 gui_w32_rm_blink_timer(); |
7 | 5074 if (blink_state == BLINK_OFF) |
5075 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
|
5076 blink_state = BLINK_NONE; |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5077 #endif |
7 | 5078 } |
5079 | |
5080 /* | |
5081 * Start the cursor blinking. If it was already blinking, this restarts the | |
5082 * waiting time and shows the cursor. | |
5083 */ | |
5084 void | |
593 | 5085 gui_mch_start_blink(void) |
7 | 5086 { |
5087 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
|
5088 // TODO: TODO: TODO: TODO: |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5089 // gui_w32_rm_blink_timer(); |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5090 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5091 // 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
|
5092 #if 0 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5093 if (blink_waittime && blink_ontime && blink_offtime) |
7 | 5094 { |
5095 blink_timer = SetTimer(NULL, 0, (UINT)blink_waittime, | |
5096 (TIMERPROC)_OnBlinkTimer); | |
5097 blink_state = BLINK_ON; | |
5098 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
|
5099 } |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5100 #endif |
7 | 5101 } |
5102 | |
5103 /* | |
5104 * Return the RGB value of a pixel as long. | |
5105 */ | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9869
diff
changeset
|
5106 guicolor_T |
7 | 5107 gui_mch_get_rgb(guicolor_T pixel) |
5108 { | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9869
diff
changeset
|
5109 return (guicolor_T)((Red(pixel) << 16) + (Green(pixel) << 8) + Blue(pixel)); |
7 | 5110 } |
5111 | |
5112 | |
5113 | |
5114 #ifdef FEAT_BROWSE | |
5115 /* | |
5116 * Pop open a file browser and return the file selected, in allocated memory, | |
5117 * or NULL if Cancel is hit. | |
5118 * saving - TRUE if the file will be saved to, FALSE if it will be opened. | |
5119 * title - Title message for the file browser dialog. | |
5120 * dflt - Default name of file. | |
5121 * ext - Default extension to be added to files without extensions. | |
5122 * initdir - directory in which to open the browser (NULL = current dir) | |
5123 * filter - Filter for matched files to choose from. | |
5124 * Has a format like this: | |
5125 * "C Files (*.c)\0*.c\0" | |
5126 * "All Files\0*.*\0\0" | |
5127 * If these two strings were concatenated, then a choice of two file | |
5128 * filters will be selectable to the user. Then only matching files will | |
5129 * be shown in the browser. If NULL, the default allows all files. | |
5130 * | |
5131 * *NOTE* - the filter string must be terminated with TWO nulls. | |
5132 */ | |
5133 char_u * | |
5134 gui_mch_browse( | |
5135 int saving, | |
5136 char_u *title, | |
5137 char_u *dflt, | |
5138 char_u *ext, | |
5139 char_u *initdir, | |
5140 char_u *filter) | |
5141 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5142 // TODO: Add Ammon's safety check (Dany) |
7 | 5143 NavReplyRecord reply; |
5144 char_u *fname = NULL; | |
5145 char_u **fnames = NULL; | |
5146 long numFiles; | |
5147 NavDialogOptions navOptions; | |
5148 OSErr error; | |
5149 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5150 // Get Navigation Service Defaults value |
9 | 5151 NavGetDefaultDialogOptions(&navOptions); |
7 | 5152 |
5153 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5154 // TODO: If we get a :browse args, set the Multiple bit. |
7 | 5155 navOptions.dialogOptionFlags = kNavAllowInvisibleFiles |
5156 | kNavDontAutoTranslate | |
5157 | kNavDontAddTranslateItems | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5158 // | kNavAllowMultipleFiles |
7 | 5159 | kNavAllowStationery; |
5160 | |
9 | 5161 (void) C2PascalString(title, &navOptions.message); |
5162 (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
|
5163 // Could set clientName? |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5164 // windowTitle? (there's no title bar?) |
7 | 5165 |
5166 if (saving) | |
5167 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5168 // Change first parm AEDesc (typeFSS) *defaultLocation to match dflt |
9 | 5169 NavPutFile(NULL, &reply, &navOptions, NULL, 'TEXT', 'VIM!', NULL); |
7 | 5170 if (!reply.validRecord) |
5171 return NULL; | |
5172 } | |
5173 else | |
5174 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5175 // Change first parm AEDesc (typeFSS) *defaultLocation to match dflt |
7 | 5176 NavGetFile(NULL, &reply, &navOptions, NULL, NULL, NULL, NULL, NULL); |
5177 if (!reply.validRecord) | |
5178 return NULL; | |
5179 } | |
5180 | |
5181 fnames = new_fnames_from_AEDesc(&reply.selection, &numFiles, &error); | |
5182 | |
9 | 5183 NavDisposeReply(&reply); |
7 | 5184 |
5185 if (fnames) | |
5186 { | |
5187 fname = fnames[0]; | |
5188 vim_free(fnames); | |
5189 } | |
5190 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5191 // TODO: Shorten the file name if possible |
7 | 5192 return fname; |
5193 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5194 #endif // FEAT_BROWSE |
7 | 5195 |
5196 #ifdef FEAT_GUI_DIALOG | |
5197 /* | |
5198 * Stuff for dialogues | |
5199 */ | |
5200 | |
5201 /* | |
5202 * Create a dialogue dynamically from the parameter strings. | |
5203 * type = type of dialogue (question, alert, etc.) | |
5204 * title = dialogue title. may be NULL for default title. | |
5205 * message = text to display. Dialogue sizes to accommodate it. | |
5206 * buttons = '\n' separated list of button captions, default first. | |
5207 * dfltbutton = number of default button. | |
5208 * | |
5209 * This routine returns 1 if the first button is pressed, | |
5210 * 2 for the second, etc. | |
5211 * | |
5212 * 0 indicates Esc was pressed. | |
5213 * -1 for unexpected error | |
5214 * | |
5215 * If stubbing out this fn, return 1. | |
5216 */ | |
5217 | |
5218 typedef struct | |
5219 { | |
5220 short idx; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5221 short width; // Size of the text in pixel |
7 | 5222 Rect box; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5223 } vgmDlgItm; // Vim Gui_Mac.c Dialog Item |
7 | 5224 |
5225 #define MoveRectTo(r,x,y) OffsetRect(r,x-r->left,y-r->top) | |
5226 | |
5227 static void | |
5228 macMoveDialogItem( | |
5229 DialogRef theDialog, | |
5230 short itemNumber, | |
5231 short X, | |
5232 short Y, | |
5233 Rect *inBox) | |
5234 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5235 #if 0 // USE_CARBONIZED |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5236 // Untested |
9 | 5237 MoveDialogItem(theDialog, itemNumber, X, Y); |
7 | 5238 if (inBox != nil) |
9 | 5239 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, inBox); |
7 | 5240 #else |
5241 short itemType; | |
5242 Handle itemHandle; | |
5243 Rect localBox; | |
5244 Rect *itemBox = &localBox; | |
5245 | |
5246 if (inBox != nil) | |
5247 itemBox = inBox; | |
5248 | |
9 | 5249 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, itemBox); |
5250 OffsetRect(itemBox, -itemBox->left, -itemBox->top); | |
5251 OffsetRect(itemBox, X, Y); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5252 // 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
|
5253 // 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
|
5254 if (1) //(itemType & kControlDialogItem) |
9 | 5255 MoveControl((ControlRef) itemHandle, X, Y); |
5256 SetDialogItem(theDialog, itemNumber, itemType, itemHandle, itemBox); | |
7 | 5257 #endif |
5258 } | |
5259 | |
5260 static void | |
5261 macSizeDialogItem( | |
5262 DialogRef theDialog, | |
5263 short itemNumber, | |
5264 short width, | |
5265 short height) | |
5266 { | |
5267 short itemType; | |
5268 Handle itemHandle; | |
5269 Rect itemBox; | |
5270 | |
9 | 5271 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, &itemBox); |
7 | 5272 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5273 // When width or height is zero do not change it |
7 | 5274 if (width == 0) |
5275 width = itemBox.right - itemBox.left; | |
5276 if (height == 0) | |
5277 height = itemBox.bottom - itemBox.top; | |
5278 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5279 #if 0 // USE_CARBONIZED |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5280 SizeDialogItem(theDialog, itemNumber, width, height); // Untested |
7 | 5281 #else |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5282 // Resize the bounding box |
7 | 5283 itemBox.right = itemBox.left + width; |
5284 itemBox.bottom = itemBox.top + height; | |
5285 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5286 // 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
|
5287 // SizeControl and SetDialogItem. (deducted from FAQ 6-18) |
7 | 5288 if (itemType & kControlDialogItem) |
9 | 5289 SizeControl((ControlRef) itemHandle, width, height); |
7 | 5290 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5291 // Configure back the item |
9 | 5292 SetDialogItem(theDialog, itemNumber, itemType, itemHandle, &itemBox); |
7 | 5293 #endif |
5294 } | |
5295 | |
5296 static void | |
5297 macSetDialogItemText( | |
5298 DialogRef theDialog, | |
5299 short itemNumber, | |
5300 Str255 itemName) | |
5301 { | |
5302 short itemType; | |
5303 Handle itemHandle; | |
5304 Rect itemBox; | |
5305 | |
9 | 5306 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, &itemBox); |
7 | 5307 |
5308 if (itemType & kControlDialogItem) | |
9 | 5309 SetControlTitle((ControlRef) itemHandle, itemName); |
7 | 5310 else |
9 | 5311 SetDialogItemText(itemHandle, itemName); |
7 | 5312 } |
5313 | |
1572 | 5314 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5315 /* |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5316 * ModalDialog() handler for message dialogs that have hotkey accelerators. |
1572 | 5317 * Expects a mapping of hotkey char to control index in gDialogHotKeys; |
5318 * setting gDialogHotKeys to NULL disables any hotkey handling. | |
5319 */ | |
5320 static pascal Boolean | |
5321 DialogHotkeyFilterProc ( | |
5322 DialogRef theDialog, | |
5323 EventRecord *event, | |
5324 DialogItemIndex *itemHit) | |
5325 { | |
5326 char_u keyHit; | |
5327 | |
5328 if (event->what == keyDown || event->what == autoKey) | |
5329 { | |
5330 keyHit = (event->message & charCodeMask); | |
5331 | |
5332 if (gDialogHotKeys && gDialogHotKeys[keyHit]) | |
5333 { | |
5334 #ifdef DEBUG_MAC_DIALOG_HOTKEYS | |
5335 printf("user pressed hotkey '%c' --> item %d\n", keyHit, gDialogHotKeys[keyHit]); | |
5336 #endif | |
5337 *itemHit = gDialogHotKeys[keyHit]; | |
5338 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5339 // 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
|
5340 // 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
|
5341 // 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
|
5342 // 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
|
5343 // fast to be seen). |
1572 | 5344 event->what = kEventControlSimulateHit; |
5345 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5346 return true; // we took care of it |
1572 | 5347 } |
5348 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5349 // 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
|
5350 // This ensures that Enter will still activate the default button. |
1572 | 5351 return StdFilterProc(theDialog, event, itemHit); |
5352 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5353 return false; // Let ModalDialog deal with it |
1572 | 5354 } |
5355 | |
5356 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5357 /* |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5358 * TODO: There have been some crashes with dialogs, check your inbox |
593 | 5359 * (Jussi) |
5360 */ | |
7 | 5361 int |
5362 gui_mch_dialog( | |
5363 int type, | |
5364 char_u *title, | |
5365 char_u *message, | |
5366 char_u *buttons, | |
5367 int dfltbutton, | |
2684 | 5368 char_u *textfield, |
5369 int ex_cmd) | |
7 | 5370 { |
5371 Handle buttonDITL; | |
5372 Handle iconDITL; | |
5373 Handle inputDITL; | |
5374 Handle messageDITL; | |
5375 Handle itemHandle; | |
5376 Handle iconHandle; | |
5377 DialogPtr theDialog; | |
5378 char_u len; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5379 char_u PascalTitle[256]; // place holder for the title |
7 | 5380 char_u name[256]; |
5381 GrafPtr oldPort; | |
5382 short itemHit; | |
5383 char_u *buttonChar; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5384 short hotKeys[256]; // map of hotkey -> control ID |
1572 | 5385 char_u aHotKey; |
7 | 5386 Rect box; |
5387 short button; | |
5388 short lastButton; | |
5389 short itemType; | |
5390 short useIcon; | |
5391 short width; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5392 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
|
5393 // including spacing |
7 | 5394 short widestButton = 0; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5395 short dfltButtonEdge = 20; // gut feeling |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5396 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
|
5397 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
|
5398 short maximumWidth = 400; // gut feeling |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5399 short maxButtonWidth = 175; // gut feeling |
7 | 5400 |
5401 short vertical; | |
5402 short dialogHeight; | |
5403 short messageLines = 3; | |
5404 FontInfo textFontInfo; | |
5405 | |
5406 vgmDlgItm iconItm; | |
5407 vgmDlgItm messageItm; | |
5408 vgmDlgItm inputItm; | |
5409 vgmDlgItm buttonItm; | |
5410 | |
5411 WindowRef theWindow; | |
5412 | |
1572 | 5413 ModalFilterUPP dialogUPP; |
5414 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5415 // Check 'v' flag in 'guioptions': vertical button placement. |
7 | 5416 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL); |
5417 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5418 // Create a new Dialog Box from template. |
9 | 5419 theDialog = GetNewDialog(129, nil, (WindowRef) -1); |
7 | 5420 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5421 // Get the WindowRef |
7 | 5422 theWindow = GetDialogWindow(theDialog); |
5423 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5424 // Hide the window. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5425 // 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
|
5426 // 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
|
5427 // 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
|
5428 // Could be avoided by changing the resource. |
9 | 5429 HideWindow(theWindow); |
7 | 5430 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5431 // 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
|
5432 // so we can measure the text with the proper font |
9 | 5433 GetPort(&oldPort); |
5434 SetPortDialogPort(theDialog); | |
7 | 5435 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5436 // 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
|
5437 // 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
|
5438 // and of the text field |
7 | 5439 GetFontInfo(&textFontInfo); |
5440 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5441 // Set the dialog title |
7 | 5442 if (title != NULL) |
5443 { | |
9 | 5444 (void) C2PascalString(title, &PascalTitle); |
5445 SetWTitle(theWindow, PascalTitle); | |
7 | 5446 } |
5447 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5448 // Creates the buttons and add them to the Dialog Box. |
9 | 5449 buttonDITL = GetResource('DITL', 130); |
7 | 5450 buttonChar = buttons; |
5451 button = 0; | |
5452 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5453 // initialize the hotkey mapping |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1776
diff
changeset
|
5454 vim_memset(hotKeys, 0, sizeof(hotKeys)); |
1572 | 5455 |
7 | 5456 for (;*buttonChar != 0;) |
5457 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5458 // Get the name of the button |
7 | 5459 button++; |
5460 len = 0; | |
5461 for (;((*buttonChar != DLG_BUTTON_SEP) && (*buttonChar != 0) && (len < 255)); buttonChar++) | |
5462 { | |
5463 if (*buttonChar != DLG_HOTKEY_CHAR) | |
5464 name[++len] = *buttonChar; | |
1572 | 5465 else |
5466 { | |
5467 aHotKey = (char_u)*(buttonChar+1); | |
5468 if (aHotKey >= 'A' && aHotKey <= 'Z') | |
5469 aHotKey = (char_u)((int)aHotKey + (int)'a' - (int)'A'); | |
5470 hotKeys[aHotKey] = button; | |
5471 #ifdef DEBUG_MAC_DIALOG_HOTKEYS | |
5472 printf("### hotKey for button %d is '%c'\n", button, aHotKey); | |
5473 #endif | |
5474 } | |
7 | 5475 } |
1572 | 5476 |
7 | 5477 if (*buttonChar != 0) |
5478 buttonChar++; | |
5479 name[0] = len; | |
5480 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5481 // Add the button |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5482 AppendDITL(theDialog, buttonDITL, overlayDITL); // appendDITLRight); |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5483 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5484 // Change the button's name |
9 | 5485 macSetDialogItemText(theDialog, button, name); |
7 | 5486 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5487 // Resize the button to fit its name |
9 | 5488 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
|
5489 // 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
|
5490 // TODO: Should be based on the message width |
7 | 5491 if (width > maxButtonWidth) |
5492 width = maxButtonWidth; | |
9 | 5493 macSizeDialogItem(theDialog, button, width, 0); |
7 | 5494 |
5495 totalButtonWidth += width; | |
5496 | |
5497 if (width > widestButton) | |
5498 widestButton = width; | |
5499 } | |
9 | 5500 ReleaseResource(buttonDITL); |
7 | 5501 lastButton = button; |
5502 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5503 // Add the icon to the Dialog Box. |
7 | 5504 iconItm.idx = lastButton + 1; |
9 | 5505 iconDITL = GetResource('DITL', 131); |
7 | 5506 switch (type) |
5507 { | |
2585 | 5508 case VIM_GENERIC: |
5509 case VIM_INFO: | |
5510 case VIM_QUESTION: useIcon = kNoteIcon; break; | |
5511 case VIM_WARNING: useIcon = kCautionIcon; break; | |
5512 case VIM_ERROR: useIcon = kStopIcon; break; | |
3935 | 5513 default: useIcon = kStopIcon; |
2585 | 5514 } |
9 | 5515 AppendDITL(theDialog, iconDITL, overlayDITL); |
5516 ReleaseResource(iconDITL); | |
5517 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
|
5518 // TODO: Should the item be freed? |
9 | 5519 iconHandle = GetIcon(useIcon); |
5520 SetDialogItem(theDialog, iconItm.idx, itemType, iconHandle, &box); | |
7 | 5521 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5522 // Add the message to the Dialog box. |
7 | 5523 messageItm.idx = lastButton + 2; |
9 | 5524 messageDITL = GetResource('DITL', 132); |
5525 AppendDITL(theDialog, messageDITL, overlayDITL); | |
5526 ReleaseResource(messageDITL); | |
5527 GetDialogItem(theDialog, messageItm.idx, &itemType, &itemHandle, &box); | |
5528 (void) C2PascalString(message, &name); | |
5529 SetDialogItemText(itemHandle, name); | |
5530 messageItm.width = StringWidth(name); | |
7 | 5531 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5532 // Add the input box if needed |
7 | 5533 if (textfield != NULL) |
5534 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5535 // Cheat for now reuse the message and convert to text edit |
7 | 5536 inputItm.idx = lastButton + 3; |
9 | 5537 inputDITL = GetResource('DITL', 132); |
5538 AppendDITL(theDialog, inputDITL, overlayDITL); | |
5539 ReleaseResource(inputDITL); | |
5540 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
|
5541 // SetDialogItem(theDialog, inputItm.idx, kEditTextDialogItem, itemHandle, &box); |
9 | 5542 (void) C2PascalString(textfield, &name); |
5543 SetDialogItemText(itemHandle, name); | |
5544 inputItm.width = StringWidth(name); | |
1572 | 5545 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5546 // Hotkeys don't make sense if there's a text field |
1572 | 5547 gDialogHotKeys = NULL; |
7 | 5548 } |
1572 | 5549 else |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5550 // Install hotkey table |
1572 | 5551 gDialogHotKeys = (short *)&hotKeys; |
7 | 5552 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5553 // Set the <ENTER> and <ESC> button. |
9 | 5554 SetDialogDefaultItem(theDialog, dfltbutton); |
5555 SetDialogCancelItem(theDialog, 0); | |
7 | 5556 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5557 // Reposition element |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5558 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5559 // Check if we need to force vertical |
7 | 5560 if (totalButtonWidth > maximumWidth) |
5561 vertical = TRUE; | |
5562 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5563 // Place icon |
9 | 5564 macMoveDialogItem(theDialog, iconItm.idx, dfltIconSideSpace, dfltElementSpacing, &box); |
7 | 5565 iconItm.box.right = box.right; |
5566 iconItm.box.bottom = box.bottom; | |
5567 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5568 // Place Message |
7 | 5569 messageItm.box.left = iconItm.box.right + dfltIconSideSpace; |
9 | 5570 macSizeDialogItem(theDialog, messageItm.idx, 0, messageLines * (textFontInfo.ascent + textFontInfo.descent)); |
5571 macMoveDialogItem(theDialog, messageItm.idx, messageItm.box.left, dfltElementSpacing, &messageItm.box); | |
7 | 5572 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5573 // Place Input |
7 | 5574 if (textfield != NULL) |
5575 { | |
5576 inputItm.box.left = messageItm.box.left; | |
5577 inputItm.box.top = messageItm.box.bottom + dfltElementSpacing; | |
9 | 5578 macSizeDialogItem(theDialog, inputItm.idx, 0, textFontInfo.ascent + textFontInfo.descent); |
5579 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
|
5580 // 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
|
5581 // For some reason this change need to be done last (Dany) |
9 | 5582 GetDialogItem(theDialog, inputItm.idx, &itemType, &itemHandle, &inputItm.box); |
5583 SetDialogItem(theDialog, inputItm.idx, kEditTextDialogItem, itemHandle, &inputItm.box); | |
7 | 5584 SelectDialogItemText(theDialog, inputItm.idx, 0, 32767); |
5585 } | |
5586 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5587 // Place Button |
7 | 5588 if (textfield != NULL) |
5589 { | |
5590 buttonItm.box.left = inputItm.box.left; | |
5591 buttonItm.box.top = inputItm.box.bottom + dfltElementSpacing; | |
5592 } | |
5593 else | |
5594 { | |
5595 buttonItm.box.left = messageItm.box.left; | |
5596 buttonItm.box.top = messageItm.box.bottom + dfltElementSpacing; | |
5597 } | |
5598 | |
5599 for (button=1; button <= lastButton; button++) | |
5600 { | |
5601 | |
9 | 5602 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
|
5603 // With vertical, it's better to have all buttons the same length |
7 | 5604 if (vertical) |
5605 { | |
9 | 5606 macSizeDialogItem(theDialog, button, widestButton, 0); |
5607 GetDialogItem(theDialog, button, &itemType, &itemHandle, &box); | |
7 | 5608 } |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5609 // Calculate position of next button |
7 | 5610 if (vertical) |
5611 buttonItm.box.top = box.bottom + dfltElementSpacing; | |
5612 else | |
5613 buttonItm.box.left = box.right + dfltElementSpacing; | |
5614 } | |
5615 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5616 // Resize the dialog box |
7 | 5617 dialogHeight = box.bottom + dfltElementSpacing; |
5618 SizeWindow(theWindow, maximumWidth, dialogHeight, TRUE); | |
5619 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5620 // Magic resize |
9 | 5621 AutoSizeDialog(theDialog); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5622 // 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
|
5623 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5624 // Display it |
7 | 5625 ShowWindow(theWindow); |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5626 // BringToFront(theWindow); |
7 | 5627 SelectWindow(theWindow); |
5628 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5629 // DrawDialog(theDialog); |
7 | 5630 #if 0 |
9 | 5631 GetPort(&oldPort); |
5632 SetPortDialogPort(theDialog); | |
7 | 5633 #endif |
5634 | |
857 | 5635 #ifdef USE_CARBONKEYHANDLER |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5636 // Avoid that we use key events for the main window. |
857 | 5637 dialog_busy = TRUE; |
5638 #endif | |
5639 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5640 // Prepare the shortcut-handling filterProc for handing to the dialog |
1572 | 5641 dialogUPP = NewModalFilterUPP(DialogHotkeyFilterProc); |
5642 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5643 // Hang until one of the button is hit |
7 | 5644 do |
1572 | 5645 ModalDialog(dialogUPP, &itemHit); |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
5646 while ((itemHit < 1) || (itemHit > lastButton)); |
7 | 5647 |
857 | 5648 #ifdef USE_CARBONKEYHANDLER |
5649 dialog_busy = FALSE; | |
5650 #endif | |
5651 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5652 // Copy back the text entered by the user into the param |
7 | 5653 if (textfield != NULL) |
5654 { | |
9 | 5655 GetDialogItem(theDialog, inputItm.idx, &itemType, &itemHandle, &box); |
5656 GetDialogItemText(itemHandle, (char_u *) &name); | |
7 | 5657 #if IOSIZE < 256 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5658 // Truncate the name to IOSIZE if needed |
7 | 5659 if (name[0] > IOSIZE) |
5660 name[0] = IOSIZE - 1; | |
5661 #endif | |
418 | 5662 vim_strncpy(textfield, &name[1], name[0]); |
7 | 5663 } |
5664 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5665 // Restore the original graphical port |
9 | 5666 SetPort(oldPort); |
7 | 5667 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5668 // Free the modal filterProc |
1572 | 5669 DisposeRoutineDescriptor(dialogUPP); |
5670 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5671 // Get ride of the dialog (free memory) |
9 | 5672 DisposeDialog(theDialog); |
7 | 5673 |
5674 return itemHit; | |
5675 /* | |
2585 | 5676 * Useful thing which could be used |
7 | 5677 * SetDialogTimeout(): Auto click a button after timeout |
5678 * SetDialogTracksCursor() : Get the I-beam cursor over input box | |
5679 * MoveDialogItem(): Probably better than SetDialogItem | |
5680 * SizeDialogItem(): (but is it Carbon Only?) | |
1373 | 5681 * AutoSizeDialog(): Magic resize of dialog based on text length |
7 | 5682 */ |
5683 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5684 #endif // FEAT_DIALOG_GUI |
7 | 5685 |
5686 /* | |
5687 * Display the saved error message(s). | |
5688 */ | |
5689 #ifdef USE_MCH_ERRMSG | |
5690 void | |
593 | 5691 display_errors(void) |
7 | 5692 { |
5693 char *p; | |
5694 char_u pError[256]; | |
5695 | |
593 | 5696 if (error_ga.ga_data == NULL) |
5697 return; | |
5698 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5699 // avoid putting up a message box with blanks only |
593 | 5700 for (p = (char *)error_ga.ga_data; *p; ++p) |
5701 if (!isspace(*p)) | |
5702 { | |
5703 if (STRLEN(p) > 255) | |
5704 pError[0] = 255; | |
5705 else | |
5706 pError[0] = STRLEN(p); | |
5707 | |
5708 STRNCPY(&pError[1], p, pError[0]); | |
5709 ParamText(pError, nil, nil, nil); | |
5710 Alert(128, nil); | |
5711 break; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5712 // 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
|
5713 // use auto-sizeable alert |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5714 // or dialog with scrollbars (TextEdit zone) |
593 | 5715 } |
5716 ga_clear(&error_ga); | |
7 | 5717 } |
5718 #endif | |
5719 | |
5720 /* | |
87 | 5721 * Get current mouse coordinates in text window. |
7 | 5722 */ |
95 | 5723 void |
5724 gui_mch_getmouse(int *x, int *y) | |
7 | 5725 { |
5726 Point where; | |
5727 | |
5728 GetMouse(&where); | |
5729 | |
87 | 5730 *x = where.h; |
5731 *y = where.v; | |
7 | 5732 } |
5733 | |
5734 void | |
593 | 5735 gui_mch_setmouse(int x, int y) |
7 | 5736 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5737 // TODO |
7 | 5738 #if 0 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5739 // From FAQ 3-11 |
7 | 5740 |
5741 CursorDevicePtr myMouse; | |
5742 Point where; | |
5743 | |
9 | 5744 if ( NGetTrapAddress(_CursorDeviceDispatch, ToolTrap) |
5745 != NGetTrapAddress(_Unimplemented, ToolTrap)) | |
7 | 5746 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5747 // New way |
7 | 5748 |
5749 /* | |
4352 | 5750 * Get first device with one button. |
5751 * This will probably be the standard mouse | |
5752 * start at head of cursor dev list | |
7 | 5753 * |
5754 */ | |
5755 | |
5756 myMouse = nil; | |
5757 | |
5758 do | |
5759 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5760 // Get the next cursor device |
7 | 5761 CursorDeviceNextDevice(&myMouse); |
5762 } | |
9 | 5763 while ((myMouse != nil) && (myMouse->cntButtons != 1)); |
5764 | |
5765 CursorDeviceMoveTo(myMouse, x, y); | |
7 | 5766 } |
5767 else | |
5768 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5769 // Old way |
7 | 5770 where.h = x; |
5771 where.v = y; | |
5772 | |
5773 *(Point *)RawMouse = where; | |
5774 *(Point *)MTemp = where; | |
5775 *(Ptr) CrsrNew = 0xFFFF; | |
5776 } | |
5777 #endif | |
5778 } | |
5779 | |
5780 void | |
593 | 5781 gui_mch_show_popupmenu(vimmenu_T *menu) |
7 | 5782 { |
5783 /* | |
5784 * Clone PopUp to use menu | |
5785 * Create a object descriptor for the current selection | |
5786 * Call the procedure | |
5787 */ | |
5788 | |
5789 MenuHandle CntxMenu; | |
5790 Point where; | |
5791 OSStatus status; | |
5792 UInt32 CntxType; | |
5793 SInt16 CntxMenuID; | |
5794 UInt16 CntxMenuItem; | |
5795 Str255 HelpName = ""; | |
5796 GrafPtr savePort; | |
5797 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5798 // 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
|
5799 GetPort(&savePort); //OSX |
9 | 5800 |
5801 GetMouse(&where); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5802 LocalToGlobal(&where); //OSX |
7 | 5803 CntxMenu = menu->submenu_handle; |
5804 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5805 // 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
|
5806 |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5807 // Call to Handle Popup |
1089 | 5808 status = ContextualMenuSelect(CntxMenu, where, false, kCMHelpItemRemoveHelp, |
1012 | 5809 HelpName, NULL, &CntxType, &CntxMenuID, &CntxMenuItem); |
7 | 5810 |
5811 if (status == noErr) | |
5812 { | |
5813 if (CntxType == kCMMenuItemSelected) | |
5814 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5815 // Handle the menu CntxMenuID, CntxMenuItem |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5816 // 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
|
5817 // 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
|
5818 // ContextualMenuSelect |
9 | 5819 gui_mac_handle_menu((CntxMenuID << 16) + CntxMenuItem); |
7 | 5820 } |
5821 else if (CntxMenuID == kCMShowHelpSelected) | |
5822 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5823 // Should come up with the help |
7 | 5824 } |
5825 } | |
5826 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5827 // Restore original Port |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5828 SetPort(savePort); //OSX |
7 | 5829 } |
5830 | |
5831 #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
|
5832 // TODO: Is it need for MACOS_X? (Dany) |
7 | 5833 void |
5834 mch_post_buffer_write(buf_T *buf) | |
5835 { | |
9 | 5836 GetFSSpecFromPath(buf->b_ffname, &buf->b_FSSpec); |
5837 Send_KAHL_MOD_AE(buf); | |
7 | 5838 } |
5839 #endif | |
5840 | |
5841 #ifdef FEAT_TITLE | |
5842 /* | |
5843 * Set the window title and icon. | |
5844 * (The icon is not taken care of). | |
5845 */ | |
5846 void | |
593 | 5847 gui_mch_settitle(char_u *title, char_u *icon) |
7 | 5848 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5849 // 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
|
5850 // that 256. Even better get it to fit nicely in the titlebar. |
766 | 5851 #ifdef MACOS_CONVERT |
168 | 5852 CFStringRef windowTitle; |
5853 size_t windowTitleLen; | |
5854 #else | |
7 | 5855 char_u *pascalTitle; |
168 | 5856 #endif |
7 | 5857 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5858 if (title == NULL) // nothing to do |
7 | 5859 return; |
5860 | |
766 | 5861 #ifdef MACOS_CONVERT |
168 | 5862 windowTitleLen = STRLEN(title); |
1621 | 5863 windowTitle = (CFStringRef)mac_enc_to_cfstring(title, windowTitleLen); |
168 | 5864 |
5865 if (windowTitle) | |
5866 { | |
5867 SetWindowTitleWithCFString(gui.VimWindow, windowTitle); | |
5868 CFRelease(windowTitle); | |
5869 } | |
5870 #else | |
7 | 5871 pascalTitle = C2Pascal_save(title); |
5872 if (pascalTitle != NULL) | |
5873 { | |
5874 SetWTitle(gui.VimWindow, pascalTitle); | |
5875 vim_free(pascalTitle); | |
5876 } | |
168 | 5877 #endif |
7 | 5878 } |
5879 #endif | |
5880 | |
5881 /* | |
2585 | 5882 * Transferred from os_mac.c for MacOS X using os_unix.c prep work |
7 | 5883 */ |
5884 | |
5885 int | |
593 | 5886 C2PascalString(char_u *CString, Str255 *PascalString) |
7 | 5887 { |
5888 char_u *PascalPtr = (char_u *) PascalString; | |
5889 int len; | |
5890 int i; | |
5891 | |
5892 PascalPtr[0] = 0; | |
5893 if (CString == NULL) | |
5894 return 0; | |
5895 | |
5896 len = STRLEN(CString); | |
5897 if (len > 255) | |
5898 len = 255; | |
5899 | |
5900 for (i = 0; i < len; i++) | |
5901 PascalPtr[i+1] = CString[i]; | |
5902 | |
5903 PascalPtr[0] = len; | |
5904 | |
5905 return 0; | |
5906 } | |
5907 | |
5908 int | |
593 | 5909 GetFSSpecFromPath(char_u *file, FSSpec *fileFSSpec) |
7 | 5910 { |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5911 // From FAQ 8-12 |
7 | 5912 Str255 filePascal; |
5913 CInfoPBRec myCPB; | |
5914 OSErr err; | |
5915 | |
9 | 5916 (void) C2PascalString(file, &filePascal); |
7 | 5917 |
5918 myCPB.dirInfo.ioNamePtr = filePascal; | |
5919 myCPB.dirInfo.ioVRefNum = 0; | |
5920 myCPB.dirInfo.ioFDirIndex = 0; | |
5921 myCPB.dirInfo.ioDrDirID = 0; | |
5922 | |
9 | 5923 err= PBGetCatInfo(&myCPB, false); |
7 | 5924 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5925 // vRefNum, dirID, name |
9 | 5926 FSMakeFSSpec(0, 0, filePascal, fileFSSpec); |
7 | 5927 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5928 // TODO: Use an error code mechanism |
7 | 5929 return 0; |
5930 } | |
5931 | |
5932 /* | |
4352 | 5933 * Convert a FSSpec to a full path |
7 | 5934 */ |
5935 | |
9 | 5936 char_u *FullPathFromFSSpec_save(FSSpec file) |
7 | 5937 { |
5938 /* | |
5939 * TODO: Add protection for 256 char max. | |
5940 */ | |
5941 | |
5942 CInfoPBRec theCPB; | |
5943 char_u fname[256]; | |
5944 char_u *filenamePtr = fname; | |
5945 OSErr error; | |
5946 int folder = 1; | |
5947 #ifdef USE_UNIXFILENAME | |
5948 SInt16 dfltVol_vRefNum; | |
5949 SInt32 dfltVol_dirID; | |
5950 FSRef refFile; | |
5951 OSStatus status; | |
5952 UInt32 pathSize = 256; | |
5953 char_u pathname[256]; | |
5954 char_u *path = pathname; | |
5955 #else | |
5956 Str255 directoryName; | |
5957 char_u temporary[255]; | |
5958 char_u *temporaryPtr = temporary; | |
5959 #endif | |
5960 | |
5961 #ifdef USE_UNIXFILENAME | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5962 // Get the default volume |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5963 // TODO: Remove as this only work if Vim is on the Boot Volume |
9 | 5964 error=HGetVol(NULL, &dfltVol_vRefNum, &dfltVol_dirID); |
7 | 5965 |
5966 if (error) | |
5967 return NULL; | |
5968 #endif | |
5969 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5970 // Start filling fname with file.name |
418 | 5971 vim_strncpy(filenamePtr, &file.name[1], file.name[0]); |
7 | 5972 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5973 // Get the info about the file specified in FSSpec |
7 | 5974 theCPB.dirInfo.ioFDirIndex = 0; |
5975 theCPB.dirInfo.ioNamePtr = file.name; | |
5976 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
|
5977 //theCPB.hFileInfo.ioDirID = 0; |
7 | 5978 theCPB.dirInfo.ioDrDirID = file.parID; |
5979 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5980 // 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
|
5981 // which is relative to ioVrefNum, ioDirID |
9 | 5982 error = PBGetCatInfo(&theCPB, false); |
7 | 5983 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5984 // If we are called for a new file we expect fnfErr |
7 | 5985 if ((error) && (error != fnfErr)) |
5986 return NULL; | |
5987 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
5988 // 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
|
5989 // default to file if file don't exist |
7 | 5990 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
|
5991 folder = 0; // It's not a folder |
7 | 5992 else |
5993 folder = 1; | |
5994 | |
5995 #ifdef USE_UNIXFILENAME | |
5996 /* | |
4352 | 5997 * The functions used here are available in Carbon, but do nothing on |
5998 * MacOS 8 and 9. | |
7 | 5999 */ |
6000 if (error == fnfErr) | |
6001 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6002 // 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
|
6003 // 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
|
6004 // 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
|
6005 // 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
|
6006 // 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
|
6007 // and, finally, append the filename. |
7 | 6008 FSSpec dirSpec; |
6009 FSRef dirRef; | |
6010 Str255 emptyFilename = "\p"; | |
6011 error = FSMakeFSSpec(theCPB.dirInfo.ioVRefNum, | |
6012 theCPB.dirInfo.ioDrDirID, emptyFilename, &dirSpec); | |
6013 if (error) | |
6014 return NULL; | |
6015 | |
6016 error = FSpMakeFSRef(&dirSpec, &dirRef); | |
6017 if (error) | |
6018 return NULL; | |
6019 | |
6020 status = FSRefMakePath(&dirRef, (UInt8*)path, pathSize); | |
6021 if (status) | |
6022 return NULL; | |
6023 | |
6024 STRCAT(path, "/"); | |
6025 STRCAT(path, filenamePtr); | |
6026 } | |
6027 else | |
6028 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6029 // 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
|
6030 // by converting its FSSpec into an FSRef. |
9 | 6031 error=FSpMakeFSRef(&file, &refFile); |
7 | 6032 if (error) |
6033 return NULL; | |
6034 | |
9 | 6035 status=FSRefMakePath(&refFile, (UInt8 *) path, pathSize); |
7 | 6036 if (status) |
6037 return NULL; | |
6038 } | |
6039 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6040 // Add a slash at the end if needed |
7 | 6041 if (folder) |
9 | 6042 STRCAT(path, "/"); |
6043 | |
6044 return (vim_strsave(path)); | |
7 | 6045 #else |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6046 // 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
|
6047 // Set ioNamePtr, it's the same area which is always reused. |
7 | 6048 theCPB.dirInfo.ioNamePtr = directoryName; |
6049 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6050 // 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
|
6051 // we want for ioDrDirID |
7 | 6052 theCPB.dirInfo.ioDrParID = file.parID; |
6053 theCPB.dirInfo.ioDrDirID = file.parID; | |
6054 | |
9 | 6055 if ((TRUE) && (file.parID != fsRtDirID /*fsRtParID*/)) |
7 | 6056 do |
6057 { | |
6058 theCPB.dirInfo.ioFDirIndex = -1; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6059 // theCPB.dirInfo.ioNamePtr = directoryName; Already done above. |
7 | 6060 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
|
6061 // theCPB.dirInfo.ioDirID = irrelevant when ioFDirIndex = -1 |
7 | 6062 theCPB.dirInfo.ioDrDirID = theCPB.dirInfo.ioDrParID; |
6063 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6064 // 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
|
6065 // *ioNamePtr[0 TO 31] will be updated |
9 | 6066 error = PBGetCatInfo(&theCPB,false); |
7 | 6067 |
6068 if (error) | |
6069 return NULL; | |
6070 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6071 // Put the new directoryName in front of the current fname |
7 | 6072 STRCPY(temporaryPtr, filenamePtr); |
418 | 6073 vim_strncpy(filenamePtr, &directoryName[1], directoryName[0]); |
7 | 6074 STRCAT(filenamePtr, ":"); |
6075 STRCAT(filenamePtr, temporaryPtr); | |
6076 } | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6077 #if 1 // def USE_UNIXFILENAME |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6078 while ((theCPB.dirInfo.ioDrParID != fsRtDirID) |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6079 /* && (theCPB.dirInfo.ioDrDirID != fsRtDirID)*/); |
7 | 6080 #else |
6081 while (theCPB.dirInfo.ioDrDirID != fsRtDirID); | |
6082 #endif | |
6083 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6084 // Get the information about the volume on which the file reside |
7 | 6085 theCPB.dirInfo.ioFDirIndex = -1; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6086 // theCPB.dirInfo.ioNamePtr = directoryName; Already done above. |
7 | 6087 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
|
6088 // theCPB.dirInfo.ioDirID = irrelevant when ioFDirIndex = -1 |
7 | 6089 theCPB.dirInfo.ioDrDirID = theCPB.dirInfo.ioDrParID; |
6090 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6091 // 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
|
6092 // *ioNamePtr[0 TO 31] will be updated |
9 | 6093 error = PBGetCatInfo(&theCPB,false); |
7 | 6094 |
6095 if (error) | |
6096 return NULL; | |
6097 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6098 // 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
|
6099 // 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
|
6100 // when we are not referring to the boot volume |
7 | 6101 #ifdef USE_UNIXFILENAME |
6102 if (file.vRefNum != dfltVol_vRefNum) | |
6103 #endif | |
6104 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6105 // Add the volume name |
7 | 6106 STRCPY(temporaryPtr, filenamePtr); |
418 | 6107 vim_strncpy(filenamePtr, &directoryName[1], directoryName[0]); |
7 | 6108 STRCAT(filenamePtr, ":"); |
6109 STRCAT(filenamePtr, temporaryPtr); | |
6110 | |
6111 #ifdef USE_UNIXFILENAME | |
6112 STRCPY(temporaryPtr, filenamePtr); | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6113 filenamePtr[0] = 0; // NULL terminate the string |
7 | 6114 STRCAT(filenamePtr, "Volumes:"); |
6115 STRCAT(filenamePtr, temporaryPtr); | |
6116 #endif | |
6117 } | |
6118 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6119 // Append final path separator if it's a folder |
7 | 6120 if (folder) |
9 | 6121 STRCAT(fname, ":"); |
7 | 6122 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6123 // As we use Unix File Name for MacOS X convert it |
7 | 6124 #ifdef USE_UNIXFILENAME |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6125 // Need to insert leading / |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6126 // TODO: get the above code to use directly the / |
7 | 6127 STRCPY(&temporaryPtr[1], filenamePtr); |
6128 temporaryPtr[0] = '/'; | |
6129 STRCPY(filenamePtr, temporaryPtr); | |
6130 { | |
6131 char *p; | |
6132 for (p = fname; *p; p++) | |
6133 if (*p == ':') | |
6134 *p = '/'; | |
6135 } | |
6136 #endif | |
6137 | |
9 | 6138 return (vim_strsave(fname)); |
7 | 6139 #endif |
6140 } | |
6141 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6142 #if defined(USE_CARBONKEYHANDLER) || defined(PROTO) |
7 | 6143 /* |
6144 * Input Method Control functions. | |
6145 */ | |
6146 | |
6147 /* | |
6148 * Notify cursor position to IM. | |
6149 */ | |
6150 void | |
6151 im_set_position(int row, int col) | |
6152 { | |
13950
741b1feeac9f
patch 8.0.1845: various comment updates needed, missing white space
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6153 # if 0 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6154 // TODO: Implement me! |
1562 | 6155 im_start_row = row; |
6156 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
|
6157 # endif |
1562 | 6158 } |
6159 | |
6160 static ScriptLanguageRecord gTSLWindow; | |
6161 static ScriptLanguageRecord gTSLInsert; | |
6162 static ScriptLanguageRecord gTSLDefault = { 0, 0 }; | |
6163 | |
6164 static Component gTSCWindow; | |
6165 static Component gTSCInsert; | |
6166 static Component gTSCDefault; | |
6167 | |
6168 static int im_initialized = 0; | |
6169 | |
6170 static void | |
6171 im_on_window_switch(int active) | |
6172 { | |
6173 ScriptLanguageRecord *slptr = NULL; | |
6174 OSStatus err; | |
6175 | |
6176 if (! gui.in_use) | |
6177 return; | |
6178 | |
6179 if (im_initialized == 0) | |
6180 { | |
6181 im_initialized = 1; | |
6182 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6183 // save default TSM component (should be U.S.) to default |
1562 | 6184 GetDefaultInputMethodOfClass(&gTSCDefault, &gTSLDefault, |
6185 kKeyboardInputMethodClass); | |
6186 } | |
6187 | |
6188 if (active == TRUE) | |
6189 { | |
6190 im_is_active = TRUE; | |
6191 ActivateTSMDocument(gTSMDocument); | |
6192 slptr = &gTSLWindow; | |
6193 | |
6194 if (slptr) | |
6195 { | |
6196 err = SetDefaultInputMethodOfClass(gTSCWindow, slptr, | |
6197 kKeyboardInputMethodClass); | |
6198 if (err == noErr) | |
6199 err = SetTextServiceLanguage(slptr); | |
6200 | |
6201 if (err == noErr) | |
6202 KeyScript(slptr->fScript | smKeyForceKeyScriptMask); | |
6203 } | |
6204 } | |
6205 else | |
6206 { | |
6207 err = GetTextServiceLanguage(&gTSLWindow); | |
6208 if (err == noErr) | |
6209 slptr = &gTSLWindow; | |
6210 | |
6211 if (slptr) | |
6212 GetDefaultInputMethodOfClass(&gTSCWindow, slptr, | |
6213 kKeyboardInputMethodClass); | |
6214 | |
6215 im_is_active = FALSE; | |
6216 DeactivateTSMDocument(gTSMDocument); | |
6217 } | |
7 | 6218 } |
6219 | |
6220 /* | |
6221 * Set IM status on ("active" is TRUE) or off ("active" is FALSE). | |
6222 */ | |
6223 void | |
6224 im_set_active(int active) | |
6225 { | |
1562 | 6226 ScriptLanguageRecord *slptr = NULL; |
6227 OSStatus err; | |
6228 | |
12924
85a601f985ab
patch 8.0.1338: USE_IM_CONTROL is confusing and incomplete
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
6229 if (!gui.in_use) |
1562 | 6230 return; |
6231 | |
6232 if (im_initialized == 0) | |
6233 { | |
6234 im_initialized = 1; | |
6235 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6236 // save default TSM component (should be U.S.) to default |
1562 | 6237 GetDefaultInputMethodOfClass(&gTSCDefault, &gTSLDefault, |
6238 kKeyboardInputMethodClass); | |
6239 } | |
6240 | |
6241 if (active == TRUE) | |
6242 { | |
6243 im_is_active = TRUE; | |
6244 ActivateTSMDocument(gTSMDocument); | |
6245 slptr = &gTSLInsert; | |
6246 | |
6247 if (slptr) | |
6248 { | |
6249 err = SetDefaultInputMethodOfClass(gTSCInsert, slptr, | |
6250 kKeyboardInputMethodClass); | |
6251 if (err == noErr) | |
6252 err = SetTextServiceLanguage(slptr); | |
6253 | |
6254 if (err == noErr) | |
6255 KeyScript(slptr->fScript | smKeyForceKeyScriptMask); | |
6256 } | |
6257 } | |
6258 else | |
6259 { | |
6260 err = GetTextServiceLanguage(&gTSLInsert); | |
6261 if (err == noErr) | |
6262 slptr = &gTSLInsert; | |
6263 | |
6264 if (slptr) | |
6265 GetDefaultInputMethodOfClass(&gTSCInsert, slptr, | |
6266 kKeyboardInputMethodClass); | |
6267 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
6268 // 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
|
6269 // enter commands easier |
1562 | 6270 SetDefaultInputMethodOfClass(gTSCDefault, &gTSLDefault, |
6271 kKeyboardInputMethodClass); | |
6272 SetTextServiceLanguage(&gTSLDefault); | |
6273 | |
6274 im_is_active = FALSE; | |
6275 DeactivateTSMDocument(gTSMDocument); | |
6276 } | |
7 | 6277 } |
6278 | |
6279 /* | |
6280 * Get IM status. When IM is on, return not 0. Else return 0. | |
6281 */ | |
6282 int | |
593 | 6283 im_get_status(void) |
7 | 6284 { |
1562 | 6285 if (! gui.in_use) |
6286 return 0; | |
6287 | |
6288 return im_is_active; | |
7 | 6289 } |
1106 | 6290 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6291 #endif |
1106 | 6292 |
6293 | |
6294 | |
6295 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) | |
6296 // drawer implementation | |
6297 static MenuRef contextMenu = NULL; | |
6298 enum | |
6299 { | |
8269
553a4c8dd796
commit https://github.com/vim/vim/commit/43acbce1bb0a33edc67496b220cae629ad95d2d8
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
6300 kTabContextMenuId = 42 |
1106 | 6301 }; |
6302 | |
6303 // the caller has to CFRelease() the returned string | |
6304 static CFStringRef | |
6305 getTabLabel(tabpage_T *page) | |
6306 { | |
6307 get_tabline_label(page, FALSE); | |
6308 #ifdef MACOS_CONVERT | |
1621 | 6309 return (CFStringRef)mac_enc_to_cfstring(NameBuff, STRLEN(NameBuff)); |
1106 | 6310 #else |
6311 // TODO: check internal encoding? | |
6312 return CFStringCreateWithCString(kCFAllocatorDefault, (char *)NameBuff, | |
6313 kCFStringEncodingMacRoman); | |
6314 #endif | |
6315 } | |
6316 | |
6317 | |
6318 #define DRAWER_SIZE 150 | |
6319 #define DRAWER_INSET 16 | |
6320 | |
6321 static ControlRef dataBrowser = NULL; | |
6322 | |
6323 // when the tabline is hidden, vim doesn't call update_tabline(). When | |
2585 | 6324 // the tabline is shown again, show_tabline() is called before update_tabline(), |
4352 | 6325 // and because of this, the tab labels and vim's internal tabs are out of sync |
1106 | 6326 // for a very short time. to prevent inconsistent state, we store the labels |
6327 // of the tabs, not pointers to the tabs (which are invalid for a short time). | |
6328 static CFStringRef *tabLabels = NULL; | |
6329 static int tabLabelsSize = 0; | |
6330 | |
6331 enum | |
6332 { | |
6333 kTabsColumn = 'Tabs' | |
6334 }; | |
6335 | |
6336 static int | |
6337 getTabCount(void) | |
6338 { | |
6339 tabpage_T *tp; | |
6340 int numTabs = 0; | |
6341 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
6342 FOR_ALL_TABPAGES(tp) |
1562 | 6343 ++numTabs; |
1106 | 6344 return numTabs; |
6345 } | |
6346 | |
6347 // data browser item display callback | |
6348 static OSStatus | |
6349 dbItemDataCallback(ControlRef browser, | |
6350 DataBrowserItemID itemID, | |
1562 | 6351 DataBrowserPropertyID property /* column id */, |
6352 DataBrowserItemDataRef itemData, | |
1106 | 6353 Boolean changeValue) |
6354 { | |
6355 OSStatus status = noErr; | |
6356 | |
6357 // assert(property == kTabsColumn); // why is this violated?? | |
6358 | |
4352 | 6359 // changeValue is true if we have a modifiable list and data was changed. |
1106 | 6360 // In our case, it's always false. |
6361 // (that is: if (changeValue) updateInternalData(); else return | |
6362 // internalData(); | |
6363 if (!changeValue) | |
6364 { | |
6365 CFStringRef str; | |
6366 | |
6367 assert(itemID - 1 >= 0 && itemID - 1 < tabLabelsSize); | |
6368 str = tabLabels[itemID - 1]; | |
6369 status = SetDataBrowserItemDataText(itemData, str); | |
6370 } | |
6371 else | |
6372 status = errDataBrowserPropertyNotSupported; | |
6373 | |
6374 return status; | |
6375 } | |
6376 | |
6377 // data browser action callback | |
6378 static void | |
6379 dbItemNotificationCallback(ControlRef browser, | |
6380 DataBrowserItemID item, | |
6381 DataBrowserItemNotification message) | |
6382 { | |
6383 switch (message) | |
6384 { | |
6385 case kDataBrowserItemSelected: | |
6386 send_tabline_event(item); | |
6387 break; | |
6388 } | |
6389 } | |
6390 | |
6391 // callbacks needed for contextual menu: | |
6392 static void | |
6393 dbGetContextualMenuCallback(ControlRef browser, | |
6394 MenuRef *menu, | |
1562 | 6395 UInt32 *helpType, |
1106 | 6396 CFStringRef *helpItemString, |
1562 | 6397 AEDesc *selection) |
1106 | 6398 { |
6399 // on mac os 9: kCMHelpItemNoHelp, but it's not the same | |
6400 *helpType = kCMHelpItemRemoveHelp; // OS X only ;-) | |
6401 *helpItemString = NULL; | |
6402 | |
6403 *menu = contextMenu; | |
6404 } | |
6405 | |
6406 static void | |
6407 dbSelectContextualMenuCallback(ControlRef browser, | |
6408 MenuRef menu, | |
6409 UInt32 selectionType, | |
6410 SInt16 menuID, | |
6411 MenuItemIndex menuItem) | |
6412 { | |
6413 if (selectionType == kCMMenuItemSelected) | |
6414 { | |
6415 MenuCommand command; | |
6416 GetMenuItemCommandID(menu, menuItem, &command); | |
6417 | |
6418 // get tab that was selected when the context menu appeared | |
6419 // (there is always one tab selected). TODO: check if the context menu | |
6420 // isn't opened on an item but on empty space (has to be possible some | |
6421 // way, the finder does it too ;-) ) | |
6422 Handle items = NewHandle(0); | |
6423 if (items != NULL) | |
6424 { | |
6425 int numItems; | |
6426 | |
6427 GetDataBrowserItems(browser, kDataBrowserNoItem, false, | |
6428 kDataBrowserItemIsSelected, items); | |
6429 numItems = GetHandleSize(items) / sizeof(DataBrowserItemID); | |
6430 if (numItems > 0) | |
6431 { | |
6432 int idx; | |
6433 DataBrowserItemID *itemsPtr; | |
6434 | |
6435 HLock(items); | |
6436 itemsPtr = (DataBrowserItemID *)*items; | |
6437 idx = itemsPtr[0]; | |
6438 HUnlock(items); | |
6439 send_tabline_menu_event(idx, command); | |
6440 } | |
6441 DisposeHandle(items); | |
6442 } | |
6443 } | |
6444 } | |
6445 | |
6446 // focus callback of the data browser to always leave focus in vim | |
6447 static OSStatus | |
6448 dbFocusCallback(EventHandlerCallRef handler, EventRef event, void *data) | |
6449 { | |
6450 assert(GetEventClass(event) == kEventClassControl | |
6451 && GetEventKind(event) == kEventControlSetFocusPart); | |
6452 | |
6453 return paramErr; | |
6454 } | |
6455 | |
6456 | |
6457 // drawer callback to resize data browser to drawer size | |
6458 static OSStatus | |
6459 drawerCallback(EventHandlerCallRef handler, EventRef event, void *data) | |
6460 { | |
6461 switch (GetEventKind(event)) | |
6462 { | |
6463 case kEventWindowBoundsChanged: // move or resize | |
6464 { | |
6465 UInt32 attribs; | |
6466 GetEventParameter(event, kEventParamAttributes, typeUInt32, | |
6467 NULL, sizeof(attribs), NULL, &attribs); | |
6468 if (attribs & kWindowBoundsChangeSizeChanged) // resize | |
6469 { | |
6470 Rect r; | |
6471 GetWindowBounds(drawer, kWindowContentRgn, &r); | |
6472 SetRect(&r, 0, 0, r.right - r.left, r.bottom - r.top); | |
6473 SetControlBounds(dataBrowser, &r); | |
6474 SetDataBrowserTableViewNamedColumnWidth(dataBrowser, | |
6475 kTabsColumn, r.right); | |
6476 } | |
6477 } | |
6478 break; | |
6479 } | |
6480 | |
6481 return eventNotHandledErr; | |
6482 } | |
6483 | |
6484 // Load DataBrowserChangeAttributes() dynamically on tiger (and better). | |
6485 // This way the code works on 10.2 and 10.3 as well (it doesn't have the | |
6486 // blue highlights in the list view on these systems, though. Oh well.) | |
6487 | |
6488 | |
6489 #import <mach-o/dyld.h> | |
6490 | |
6491 enum { kMyDataBrowserAttributeListViewAlternatingRowColors = (1 << 1) }; | |
6492 | |
6493 static OSStatus | |
6494 myDataBrowserChangeAttributes(ControlRef inDataBrowser, | |
6495 OptionBits inAttributesToSet, | |
6496 OptionBits inAttributesToClear) | |
6497 { | |
6498 long osVersion; | |
6499 char *symbolName; | |
6500 NSSymbol symbol = NULL; | |
6501 OSStatus (*dataBrowserChangeAttributes)(ControlRef inDataBrowser, | |
6502 OptionBits inAttributesToSet, OptionBits inAttributesToClear); | |
6503 | |
6504 Gestalt(gestaltSystemVersion, &osVersion); | |
6505 if (osVersion < 0x1040) // only supported for 10.4 (and up) | |
6506 return noErr; | |
6507 | |
6508 // C name mangling... | |
6509 symbolName = "_DataBrowserChangeAttributes"; | |
6510 if (!NSIsSymbolNameDefined(symbolName) | |
6511 || (symbol = NSLookupAndBindSymbol(symbolName)) == NULL) | |
6512 return noErr; | |
6513 | |
6514 dataBrowserChangeAttributes = NSAddressOfSymbol(symbol); | |
6515 if (dataBrowserChangeAttributes == NULL) | |
6516 return noErr; // well... | |
6517 return dataBrowserChangeAttributes(inDataBrowser, | |
6518 inAttributesToSet, inAttributesToClear); | |
6519 } | |
6520 | |
6521 static void | |
6522 initialise_tabline(void) | |
6523 { | |
6524 Rect drawerRect = { 0, 0, 0, DRAWER_SIZE }; | |
6525 DataBrowserCallbacks dbCallbacks; | |
6526 EventTypeSpec focusEvent = {kEventClassControl, kEventControlSetFocusPart}; | |
6527 EventTypeSpec resizeEvent = {kEventClassWindow, kEventWindowBoundsChanged}; | |
6528 DataBrowserListViewColumnDesc colDesc; | |
6529 | |
6530 // drawers have to have compositing enabled | |
6531 CreateNewWindow(kDrawerWindowClass, | |
6532 kWindowStandardHandlerAttribute | |
6533 | kWindowCompositingAttribute | |
6534 | kWindowResizableAttribute | |
6535 | kWindowLiveResizeAttribute, | |
6536 &drawerRect, &drawer); | |
6537 | |
6538 SetThemeWindowBackground(drawer, kThemeBrushDrawerBackground, true); | |
6539 SetDrawerParent(drawer, gui.VimWindow); | |
6540 SetDrawerOffsets(drawer, kWindowOffsetUnchanged, DRAWER_INSET); | |
6541 | |
6542 | |
6543 // create list view embedded in drawer | |
6544 CreateDataBrowserControl(drawer, &drawerRect, kDataBrowserListView, | |
6545 &dataBrowser); | |
6546 | |
6547 dbCallbacks.version = kDataBrowserLatestCallbacks; | |
6548 InitDataBrowserCallbacks(&dbCallbacks); | |
6549 dbCallbacks.u.v1.itemDataCallback = | |
6550 NewDataBrowserItemDataUPP(dbItemDataCallback); | |
6551 dbCallbacks.u.v1.itemNotificationCallback = | |
6552 NewDataBrowserItemNotificationUPP(dbItemNotificationCallback); | |
6553 dbCallbacks.u.v1.getContextualMenuCallback = | |
6554 NewDataBrowserGetContextualMenuUPP(dbGetContextualMenuCallback); | |
6555 dbCallbacks.u.v1.selectContextualMenuCallback = | |
6556 NewDataBrowserSelectContextualMenuUPP(dbSelectContextualMenuCallback); | |
6557 | |
6558 SetDataBrowserCallbacks(dataBrowser, &dbCallbacks); | |
6559 | |
6560 SetDataBrowserListViewHeaderBtnHeight(dataBrowser, 0); // no header | |
6561 SetDataBrowserHasScrollBars(dataBrowser, false, true); // only vertical | |
6562 SetDataBrowserSelectionFlags(dataBrowser, | |
6563 kDataBrowserSelectOnlyOne | kDataBrowserNeverEmptySelectionSet); | |
6564 SetDataBrowserTableViewHiliteStyle(dataBrowser, | |
6565 kDataBrowserTableViewFillHilite); | |
6566 Boolean b = false; | |
6567 SetControlData(dataBrowser, kControlEntireControl, | |
6568 kControlDataBrowserIncludesFrameAndFocusTag, sizeof(b), &b); | |
6569 | |
6570 // enable blue background in data browser (this is only in 10.4 and vim | |
6571 // has to support older osx versions as well, so we have to load this | |
6572 // function dynamically) | |
6573 myDataBrowserChangeAttributes(dataBrowser, | |
6574 kMyDataBrowserAttributeListViewAlternatingRowColors, 0); | |
6575 | |
6576 // install callback that keeps focus in vim and away from the data browser | |
6577 InstallControlEventHandler(dataBrowser, dbFocusCallback, 1, &focusEvent, | |
6578 NULL, NULL); | |
6579 | |
6580 // install callback that keeps data browser at the size of the drawer | |
6581 InstallWindowEventHandler(drawer, drawerCallback, 1, &resizeEvent, | |
6582 NULL, NULL); | |
6583 | |
6584 // add "tabs" column to data browser | |
6585 colDesc.propertyDesc.propertyID = kTabsColumn; | |
6586 colDesc.propertyDesc.propertyType = kDataBrowserTextType; | |
6587 | |
6588 // add if items can be selected (?): kDataBrowserListViewSelectionColumn | |
6589 colDesc.propertyDesc.propertyFlags = kDataBrowserDefaultPropertyFlags; | |
6590 | |
6591 colDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; | |
6592 colDesc.headerBtnDesc.minimumWidth = 100; | |
6593 colDesc.headerBtnDesc.maximumWidth = 150; | |
6594 colDesc.headerBtnDesc.titleOffset = 0; | |
6595 colDesc.headerBtnDesc.titleString = CFSTR("Tabs"); | |
6596 colDesc.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing; | |
6597 colDesc.headerBtnDesc.btnFontStyle.flags = 0; // use default font | |
6598 colDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly; | |
6599 | |
6600 AddDataBrowserListViewColumn(dataBrowser, &colDesc, 0); | |
6601 | |
6602 // create tabline popup menu required by vim docs (see :he tabline-menu) | |
6603 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
|
6604 AppendMenuItemTextWithCFString(contextMenu, CFSTR("Close Tab"), 0, |
1106 | 6605 TABLINE_MENU_CLOSE, NULL); |
6606 AppendMenuItemTextWithCFString(contextMenu, CFSTR("New Tab"), 0, | |
6607 TABLINE_MENU_NEW, NULL); | |
6608 AppendMenuItemTextWithCFString(contextMenu, CFSTR("Open Tab..."), 0, | |
6609 TABLINE_MENU_OPEN, NULL); | |
6610 } | |
6611 | |
6612 | |
6613 /* | |
6614 * Show or hide the tabline. | |
6615 */ | |
6616 void | |
6617 gui_mch_show_tabline(int showit) | |
6618 { | |
6619 if (showit == 0) | |
1562 | 6620 CloseDrawer(drawer, true); |
1106 | 6621 else |
1562 | 6622 OpenDrawer(drawer, kWindowEdgeRight, true); |
1106 | 6623 } |
6624 | |
6625 /* | |
6626 * Return TRUE when tabline is displayed. | |
6627 */ | |
6628 int | |
6629 gui_mch_showing_tabline(void) | |
6630 { | |
6631 WindowDrawerState state = GetDrawerState(drawer); | |
6632 | |
6633 return state == kWindowDrawerOpen || state == kWindowDrawerOpening; | |
6634 } | |
6635 | |
6636 /* | |
6637 * Update the labels of the tabline. | |
6638 */ | |
6639 void | |
6640 gui_mch_update_tabline(void) | |
6641 { | |
6642 tabpage_T *tp; | |
6643 int numTabs = getTabCount(); | |
6644 int nr = 1; | |
6645 int curtabidx = 1; | |
6646 | |
6647 // adjust data browser | |
6648 if (tabLabels != NULL) | |
6649 { | |
1562 | 6650 int i; |
6651 | |
6652 for (i = 0; i < tabLabelsSize; ++i) | |
6653 CFRelease(tabLabels[i]); | |
6654 free(tabLabels); | |
1106 | 6655 } |
6656 tabLabels = (CFStringRef *)malloc(numTabs * sizeof(CFStringRef)); | |
6657 tabLabelsSize = numTabs; | |
6658 | |
6659 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | |
6660 { | |
6661 if (tp == curtab) | |
6662 curtabidx = nr; | |
1562 | 6663 tabLabels[nr-1] = getTabLabel(tp); |
1106 | 6664 } |
6665 | |
6666 RemoveDataBrowserItems(dataBrowser, kDataBrowserNoItem, 0, NULL, | |
6667 kDataBrowserItemNoProperty); | |
6668 // data browser uses ids 1, 2, 3, ... numTabs per default, so we | |
6669 // can pass NULL for the id array | |
6670 AddDataBrowserItems(dataBrowser, kDataBrowserNoItem, numTabs, NULL, | |
6671 kDataBrowserItemNoProperty); | |
6672 | |
6673 DataBrowserItemID item = curtabidx; | |
6674 SetDataBrowserSelectedItems(dataBrowser, 1, &item, kDataBrowserItemsAssign); | |
6675 } | |
6676 | |
6677 /* | |
6678 * Set the current tab to "nr". First tab is 1. | |
6679 */ | |
6680 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
6681 gui_mch_set_curtab(int nr) |
1106 | 6682 { |
6683 DataBrowserItemID item = nr; | |
6684 SetDataBrowserSelectedItems(dataBrowser, 1, &item, kDataBrowserItemsAssign); | |
6685 | |
6686 // TODO: call something like this?: (or restore scroll position, or...) | |
6687 RevealDataBrowserItem(dataBrowser, item, kTabsColumn, | |
6688 kDataBrowserRevealOnly); | |
6689 } | |
6690 | |
6691 #endif // FEAT_GUI_TABLINE |