aboutsummaryrefslogtreecommitdiffstats
path: root/src/macterm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/macterm.c')
-rw-r--r--src/macterm.c337
1 files changed, 194 insertions, 143 deletions
diff --git a/src/macterm.c b/src/macterm.c
index e1b8d49ddfa..2d09a2e93e9 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -50,6 +50,7 @@ Boston, MA 02111-1307, USA. */
50#include <TextUtils.h> 50#include <TextUtils.h>
51#include <LowMem.h> 51#include <LowMem.h>
52#include <Controls.h> 52#include <Controls.h>
53#include <Windows.h>
53#if defined (__MRC__) || (__MSL__ >= 0x6000) 54#if defined (__MRC__) || (__MSL__ >= 0x6000)
54#include <ControlDefinitions.h> 55#include <ControlDefinitions.h>
55#endif 56#endif
@@ -1292,9 +1293,8 @@ x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p)
1292 output_cursor.vpos, 1293 output_cursor.vpos,
1293 output_cursor.x, output_cursor.y); 1294 output_cursor.x, output_cursor.y);
1294 1295
1295 x_draw_vertical_border (w); 1296 if (draw_window_fringes (w, 1))
1296 1297 x_draw_vertical_border (w);
1297 draw_window_fringes (w);
1298 1298
1299 UNBLOCK_INPUT; 1299 UNBLOCK_INPUT;
1300 } 1300 }
@@ -3893,18 +3893,21 @@ remember_mouse_glyph (f1, gx, gy)
3893 3893
3894 3894
3895static WindowPtr 3895static WindowPtr
3896mac_front_window () 3896front_emacs_window ()
3897{ 3897{
3898#if TARGET_API_MAC_CARBON 3898#if TARGET_API_MAC_CARBON
3899 return GetFrontWindowOfClass (kDocumentWindowClass, true); 3899 WindowPtr wp = GetFrontWindowOfClass (kDocumentWindowClass, true);
3900
3901 while (wp && !is_emacs_window (wp))
3902 wp = GetNextWindowOfClass (wp, kDocumentWindowClass, true);
3900#else 3903#else
3901 WindowPtr front_window = FrontWindow (); 3904 WindowPtr wp = FrontWindow ();
3902 3905
3903 if (tip_window && front_window == tip_window) 3906 while (wp && (wp == tip_window || !is_emacs_window (wp)))
3904 return GetNextWindow (front_window); 3907 wp = GetNextWindow (wp);
3905 else
3906 return front_window;
3907#endif 3908#endif
3909
3910 return wp;
3908} 3911}
3909 3912
3910#define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP) 3913#define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
@@ -3940,7 +3943,7 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
3940{ 3943{
3941 Point mouse_pos; 3944 Point mouse_pos;
3942 int ignore1, ignore2; 3945 int ignore1, ignore2;
3943 WindowPtr wp = mac_front_window (); 3946 WindowPtr wp = front_emacs_window ();
3944 struct frame *f; 3947 struct frame *f;
3945 Lisp_Object frame, tail; 3948 Lisp_Object frame, tail;
3946 3949
@@ -4557,7 +4560,7 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
4557 unsigned long *time; 4560 unsigned long *time;
4558{ 4561{
4559 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); 4562 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
4560 WindowPtr wp = mac_front_window (); 4563 WindowPtr wp = front_emacs_window ();
4561 Point mouse_pos; 4564 Point mouse_pos;
4562 struct frame *f = mac_window_to_frame (wp); 4565 struct frame *f = mac_window_to_frame (wp);
4563 int win_y, top_range; 4566 int win_y, top_range;
@@ -5053,6 +5056,26 @@ xim_close_dpy (dpyinfo)
5053 */ 5056 */
5054 5057
5055 5058
5059void
5060mac_get_window_bounds (f, inner, outer)
5061 struct frame *f;
5062 Rect *inner, *outer;
5063{
5064#if TARGET_API_MAC_CARBON
5065 GetWindowBounds (FRAME_MAC_WINDOW (f), kWindowContentRgn, inner);
5066 GetWindowBounds (FRAME_MAC_WINDOW (f), kWindowStructureRgn, outer);
5067#else /* not TARGET_API_MAC_CARBON */
5068 RgnHandle region = NewRgn ();
5069
5070 GetWindowRegion (FRAME_MAC_WINDOW (f), kWindowContentRgn, region);
5071 *inner = (*region)->rgnBBox;
5072 GetWindowRegion (FRAME_MAC_WINDOW (f), kWindowStructureRgn, region);
5073 *outer = (*region)->rgnBBox;
5074 DisposeRgn (region);
5075#endif /* not TARGET_API_MAC_CARBON */
5076}
5077
5078
5056/* Calculate the absolute position in frame F 5079/* Calculate the absolute position in frame F
5057 from its current recorded position values and gravity. */ 5080 from its current recorded position values and gravity. */
5058 5081
@@ -5060,47 +5083,36 @@ void
5060x_calc_absolute_position (f) 5083x_calc_absolute_position (f)
5061 struct frame *f; 5084 struct frame *f;
5062{ 5085{
5063 Point pt; 5086 int width_diff = 0, height_diff = 0;
5064 int flags = f->size_hint_flags; 5087 int flags = f->size_hint_flags;
5088 Rect inner, outer;
5065 5089
5066 pt.h = pt.v = 0; 5090 /* We have nothing to do if the current position
5091 is already for the top-left corner. */
5092 if (! ((flags & XNegative) || (flags & YNegative)))
5093 return;
5067 5094
5068 /* Find the position of the outside upper-left corner of 5095 /* Find the offsets of the outside upper-left corner of
5069 the inner window, with respect to the outer window. */ 5096 the inner window, with respect to the outer window. */
5070 if (f->output_data.mac->parent_desc != FRAME_MAC_DISPLAY_INFO (f)->root_window) 5097 mac_get_window_bounds (f, &inner, &outer);
5071 {
5072 GrafPtr savePort;
5073 GetPort (&savePort);
5074 5098
5075 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 5099 width_diff = (outer.right - outer.left) - (inner.right - inner.left);
5076 5100 height_diff = (outer.bottom - outer.top) - (inner.bottom - inner.top);
5077#if TARGET_API_MAC_CARBON
5078 {
5079 Rect r;
5080
5081 GetWindowPortBounds (FRAME_MAC_WINDOW (f), &r);
5082 SetPt(&pt, r.left, r.top);
5083 }
5084#else /* not TARGET_API_MAC_CARBON */
5085 SetPt(&pt, FRAME_MAC_WINDOW (f)->portRect.left, FRAME_MAC_WINDOW (f)->portRect.top);
5086#endif /* not TARGET_API_MAC_CARBON */
5087 LocalToGlobal (&pt);
5088 SetPort (savePort);
5089 }
5090 5101
5091 /* Treat negative positions as relative to the leftmost bottommost 5102 /* Treat negative positions as relative to the leftmost bottommost
5092 position that fits on the screen. */ 5103 position that fits on the screen. */
5093 if (flags & XNegative) 5104 if (flags & XNegative)
5094 f->left_pos = (FRAME_MAC_DISPLAY_INFO (f)->width 5105 f->left_pos = (FRAME_MAC_DISPLAY_INFO (f)->width
5095 - 2 * f->border_width - pt.h 5106 - width_diff
5096 - FRAME_PIXEL_WIDTH (f) 5107 - FRAME_PIXEL_WIDTH (f)
5097 + f->left_pos); 5108 + f->left_pos);
5098 /* NTEMACS_TODO: Subtract menubar height? */ 5109
5099 if (flags & YNegative) 5110 if (flags & YNegative)
5100 f->top_pos = (FRAME_MAC_DISPLAY_INFO (f)->height 5111 f->top_pos = (FRAME_MAC_DISPLAY_INFO (f)->height
5101 - 2 * f->border_width - pt.v 5112 - height_diff
5102 - FRAME_PIXEL_HEIGHT (f) 5113 - FRAME_PIXEL_HEIGHT (f)
5103 + f->top_pos); 5114 + f->top_pos);
5115
5104 /* The left_pos and top_pos 5116 /* The left_pos and top_pos
5105 are now relative to the top and left screen edges, 5117 are now relative to the top and left screen edges,
5106 so the flags should correspond. */ 5118 so the flags should correspond. */
@@ -5119,8 +5131,6 @@ x_set_offset (f, xoff, yoff, change_gravity)
5119 register int xoff, yoff; 5131 register int xoff, yoff;
5120 int change_gravity; 5132 int change_gravity;
5121{ 5133{
5122 int modified_top, modified_left;
5123
5124 if (change_gravity > 0) 5134 if (change_gravity > 0)
5125 { 5135 {
5126 f->top_pos = yoff; 5136 f->top_pos = yoff;
@@ -5137,11 +5147,55 @@ x_set_offset (f, xoff, yoff, change_gravity)
5137 BLOCK_INPUT; 5147 BLOCK_INPUT;
5138 x_wm_set_size_hint (f, (long) 0, 0); 5148 x_wm_set_size_hint (f, (long) 0, 0);
5139 5149
5140 modified_left = f->left_pos; 5150#if TARGET_API_MAC_CARBON
5141 modified_top = f->top_pos; 5151 MoveWindowStructure (FRAME_MAC_WINDOW (f), f->left_pos, f->top_pos);
5142 5152 /* If the title bar is completely outside the screen, adjust the
5143 MoveWindow (FRAME_MAC_WINDOW (f), modified_left + 6, 5153 position. */
5144 modified_top + 42, false); 5154 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn,
5155 kWindowConstrainMoveRegardlessOfFit
5156 | kWindowConstrainAllowPartial, NULL, NULL);
5157 x_real_positions (f, &f->left_pos, &f->top_pos);
5158#else
5159 {
5160 Rect inner, outer, screen_rect, dummy;
5161 RgnHandle region = NewRgn ();
5162
5163 mac_get_window_bounds (f, &inner, &outer);
5164 f->x_pixels_diff = inner.left - outer.left;
5165 f->y_pixels_diff = inner.top - outer.top;
5166 MoveWindow (FRAME_MAC_WINDOW (f), f->left_pos + f->x_pixels_diff,
5167 f->top_pos + f->y_pixels_diff, false);
5168
5169 /* If the title bar is completely outside the screen, adjust the
5170 position. The variable `outer' holds the title bar rectangle.
5171 The variable `inner' holds slightly smaller one than `outer',
5172 so that the calculation of overlapping may not become too
5173 strict. */
5174 GetWindowRegion (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, region);
5175 outer = (*region)->rgnBBox;
5176 DisposeRgn (region);
5177 inner = outer;
5178 InsetRect (&inner, 8, 8);
5179 screen_rect = qd.screenBits.bounds;
5180 screen_rect.top += GetMBarHeight ();
5181
5182 if (!SectRect (&inner, &screen_rect, &dummy))
5183 {
5184 if (inner.right <= screen_rect.left)
5185 f->left_pos = screen_rect.left;
5186 else if (inner.left >= screen_rect.right)
5187 f->left_pos = screen_rect.right - (outer.right - outer.left);
5188
5189 if (inner.bottom <= screen_rect.top)
5190 f->top_pos = screen_rect.top;
5191 else if (inner.top >= screen_rect.bottom)
5192 f->top_pos = screen_rect.bottom - (outer.bottom - outer.top);
5193
5194 MoveWindow (FRAME_MAC_WINDOW (f), f->left_pos + f->x_pixels_diff,
5195 f->top_pos + f->y_pixels_diff, false);
5196 }
5197 }
5198#endif
5145 5199
5146 UNBLOCK_INPUT; 5200 UNBLOCK_INPUT;
5147} 5201}
@@ -5280,7 +5334,11 @@ x_raise_frame (f)
5280 struct frame *f; 5334 struct frame *f;
5281{ 5335{
5282 if (f->async_visible) 5336 if (f->async_visible)
5283 SelectWindow (FRAME_MAC_WINDOW (f)); 5337 {
5338 BLOCK_INPUT;
5339 SelectWindow (FRAME_MAC_WINDOW (f));
5340 UNBLOCK_INPUT;
5341 }
5284} 5342}
5285 5343
5286/* Lower frame F. */ 5344/* Lower frame F. */
@@ -5289,7 +5347,11 @@ x_lower_frame (f)
5289 struct frame *f; 5347 struct frame *f;
5290{ 5348{
5291 if (f->async_visible) 5349 if (f->async_visible)
5292 SendBehind (FRAME_MAC_WINDOW (f), nil); 5350 {
5351 BLOCK_INPUT;
5352 SendBehind (FRAME_MAC_WINDOW (f), nil);
5353 UNBLOCK_INPUT;
5354 }
5293} 5355}
5294 5356
5295static void 5357static void
@@ -6926,6 +6988,7 @@ x_find_ccl_program (fontp)
6926/* true when cannot handle any Mac OS events */ 6988/* true when cannot handle any Mac OS events */
6927static int handling_window_update = 0; 6989static int handling_window_update = 0;
6928 6990
6991#if 0
6929/* the flag appl_is_suspended is used both for determining the sleep 6992/* the flag appl_is_suspended is used both for determining the sleep
6930 time to be passed to WaitNextEvent and whether the cursor should be 6993 time to be passed to WaitNextEvent and whether the cursor should be
6931 drawn when updating the display. The cursor is turned off when 6994 drawn when updating the display. The cursor is turned off when
@@ -6935,6 +6998,7 @@ static int handling_window_update = 0;
6935 suspended. */ 6998 suspended. */
6936static Boolean app_is_suspended = false; 6999static Boolean app_is_suspended = false;
6937static long app_sleep_time = WNE_SLEEP_AT_RESUME; 7000static long app_sleep_time = WNE_SLEEP_AT_RESUME;
7001#endif
6938 7002
6939#define EXTRA_STACK_ALLOC (256 * 1024) 7003#define EXTRA_STACK_ALLOC (256 * 1024)
6940 7004
@@ -7261,11 +7325,13 @@ is_emacs_window (WindowPtr win)
7261static void 7325static void
7262do_app_resume () 7326do_app_resume ()
7263{ 7327{
7328 /* Window-activate events will do the job. */
7329#if 0
7264 WindowPtr wp; 7330 WindowPtr wp;
7265 struct frame *f; 7331 struct frame *f;
7266 7332
7267 wp = mac_front_window (); 7333 wp = front_emacs_window ();
7268 if (is_emacs_window (wp)) 7334 if (wp)
7269 { 7335 {
7270 f = mac_window_to_frame (wp); 7336 f = mac_window_to_frame (wp);
7271 7337
@@ -7278,16 +7344,19 @@ do_app_resume ()
7278 7344
7279 app_is_suspended = false; 7345 app_is_suspended = false;
7280 app_sleep_time = WNE_SLEEP_AT_RESUME; 7346 app_sleep_time = WNE_SLEEP_AT_RESUME;
7347#endif
7281} 7348}
7282 7349
7283static void 7350static void
7284do_app_suspend () 7351do_app_suspend ()
7285{ 7352{
7353 /* Window-deactivate events will do the job. */
7354#if 0
7286 WindowPtr wp; 7355 WindowPtr wp;
7287 struct frame *f; 7356 struct frame *f;
7288 7357
7289 wp = mac_front_window (); 7358 wp = front_emacs_window ();
7290 if (is_emacs_window (wp)) 7359 if (wp)
7291 { 7360 {
7292 f = mac_window_to_frame (wp); 7361 f = mac_window_to_frame (wp);
7293 7362
@@ -7300,6 +7369,7 @@ do_app_suspend ()
7300 7369
7301 app_is_suspended = true; 7370 app_is_suspended = true;
7302 app_sleep_time = WNE_SLEEP_AT_SUSPEND; 7371 app_sleep_time = WNE_SLEEP_AT_SUSPEND;
7372#endif
7303} 7373}
7304 7374
7305 7375
@@ -7308,10 +7378,10 @@ do_mouse_moved (mouse_pos, f)
7308 Point mouse_pos; 7378 Point mouse_pos;
7309 FRAME_PTR *f; 7379 FRAME_PTR *f;
7310{ 7380{
7311 WindowPtr wp = mac_front_window (); 7381 WindowPtr wp = front_emacs_window ();
7312 struct x_display_info *dpyinfo; 7382 struct x_display_info *dpyinfo;
7313 7383
7314 if (is_emacs_window (wp)) 7384 if (wp)
7315 { 7385 {
7316 *f = mac_window_to_frame (wp); 7386 *f = mac_window_to_frame (wp);
7317 dpyinfo = FRAME_MAC_DISPLAY_INFO (*f); 7387 dpyinfo = FRAME_MAC_DISPLAY_INFO (*f);
@@ -7373,7 +7443,7 @@ do_menu_choice (SInt32 menu_choice)
7373 7443
7374 default: 7444 default:
7375 { 7445 {
7376 struct frame *f = mac_window_to_frame (mac_front_window ()); 7446 struct frame *f = mac_window_to_frame (front_emacs_window ());
7377 MenuHandle menu = GetMenuHandle (menu_id); 7447 MenuHandle menu = GetMenuHandle (menu_id);
7378 if (menu) 7448 if (menu)
7379 { 7449 {
@@ -7426,41 +7496,43 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
7426 GrafPtr save_port; 7496 GrafPtr save_port;
7427 Rect zoom_rect, port_rect; 7497 Rect zoom_rect, port_rect;
7428 Point top_left; 7498 Point top_left;
7429 int w_title_height, columns, rows, width, height, dummy, x, y; 7499 int w_title_height, columns, rows;
7430 struct frame *f = mac_window_to_frame (w); 7500 struct frame *f = mac_window_to_frame (w);
7431 7501
7432 GetPort (&save_port);
7433
7434 SetPortWindowPort (w);
7435
7436 /* Clear window to avoid flicker. */
7437#if TARGET_API_MAC_CARBON 7502#if TARGET_API_MAC_CARBON
7438 { 7503 {
7439 Rect r; 7504 Point standard_size;
7440 BitMap bm;
7441 7505
7442 GetWindowPortBounds (w, &r); 7506 standard_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS);
7443 EraseRect (&r); 7507 standard_size.v = FRAME_MAC_DISPLAY_INFO (f)->height;
7444 7508
7445 if (zoom_in_or_out == inZoomOut) 7509 if (IsWindowInStandardState (w, &standard_size, &zoom_rect))
7510 zoom_in_or_out = inZoomIn;
7511 else
7446 { 7512 {
7447 /* calculate height of window's title bar (hard card it for now). */ 7513 /* Adjust the standard size according to character boundaries. */
7448 w_title_height = 20 + GetMBarHeight (); 7514
7449 7515 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, zoom_rect.right - zoom_rect.left);
7450 /* get maximum height of window into zoom_rect.bottom - 7516 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, zoom_rect.bottom - zoom_rect.top);
7451 zoom_rect.top */ 7517 standard_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, columns);
7452 GetQDGlobalsScreenBits (&bm); 7518 standard_size.v = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows);
7453 zoom_rect = bm.bounds; 7519 GetWindowBounds (w, kWindowContentRgn, &port_rect);
7454 zoom_rect.top += w_title_height; 7520 if (IsWindowInStandardState (w, &standard_size, &zoom_rect)
7455 InsetRect (&zoom_rect, 8, 4); /* not too tight */ 7521 && port_rect.left == zoom_rect.left
7456 7522 && port_rect.top == zoom_rect.top)
7457 zoom_rect.right = zoom_rect.left 7523 zoom_in_or_out = inZoomIn;
7458 + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS); 7524 else
7459 7525 zoom_in_or_out = inZoomOut;
7460 SetWindowStandardState (w, &zoom_rect);
7461 } 7526 }
7527
7528 ZoomWindowIdeal (w, zoom_in_or_out, &standard_size);
7462 } 7529 }
7463#else /* not TARGET_API_MAC_CARBON */ 7530#else /* not TARGET_API_MAC_CARBON */
7531 GetPort (&save_port);
7532
7533 SetPortWindowPort (w);
7534
7535 /* Clear window to avoid flicker. */
7464 EraseRect (&(w->portRect)); 7536 EraseRect (&(w->portRect));
7465 if (zoom_in_or_out == inZoomOut) 7537 if (zoom_in_or_out == inZoomOut)
7466 { 7538 {
@@ -7479,12 +7551,19 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
7479 zoom_rect.right = zoom_rect.left 7551 zoom_rect.right = zoom_rect.left
7480 + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS); 7552 + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS);
7481 7553
7554 /* Adjust the standard size according to character boundaries. */
7555 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, zoom_rect.bottom - zoom_rect.top);
7556 zoom_rect.bottom =
7557 zoom_rect.top + FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows);
7558
7482 (**((WStateDataHandle) ((WindowPeek) w)->dataHandle)).stdState 7559 (**((WStateDataHandle) ((WindowPeek) w)->dataHandle)).stdState
7483 = zoom_rect; 7560 = zoom_rect;
7484 } 7561 }
7485#endif /* not TARGET_API_MAC_CARBON */
7486 7562
7487 ZoomWindow (w, zoom_in_or_out, w == mac_front_window ()); 7563 ZoomWindow (w, zoom_in_or_out, w == front_emacs_window ());
7564
7565 SetPort (save_port);
7566#endif /* not TARGET_API_MAC_CARBON */
7488 7567
7489 /* retrieve window size and update application values */ 7568 /* retrieve window size and update application values */
7490#if TARGET_API_MAC_CARBON 7569#if TARGET_API_MAC_CARBON
@@ -7495,8 +7574,7 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
7495 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, port_rect.bottom - port_rect.top); 7574 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, port_rect.bottom - port_rect.top);
7496 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, port_rect.right - port_rect.left); 7575 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, port_rect.right - port_rect.left);
7497 x_set_window_size (f, 0, columns, rows); 7576 x_set_window_size (f, 0, columns, rows);
7498 7577 x_real_positions (f, &f->left_pos, &f->top_pos);
7499 SetPort (save_port);
7500} 7578}
7501 7579
7502/* Initialize Drag And Drop to allow files to be dropped onto emacs frames */ 7580/* Initialize Drag And Drop to allow files to be dropped onto emacs frames */
@@ -8046,19 +8124,15 @@ XTread_socket (sd, expected, hold_quit)
8046 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop))) 8124 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop)))
8047 event_mask -= highLevelEventMask; 8125 event_mask -= highLevelEventMask;
8048 8126
8049 while (WaitNextEvent (event_mask, &er, 8127 while (WaitNextEvent (event_mask, &er, 0L, NULL))
8050 (expected ? app_sleep_time : 0L), NULL)) 8128#else /* USE_CARBON_EVENTS */
8051#else 8129 while (!ReceiveNextEvent (0, NULL, kEventDurationNoWait,
8052 while (!ReceiveNextEvent (0, NULL,
8053 (expected ? TicksToEventTime (app_sleep_time) : 0),
8054 kEventRemoveFromQueue, &eventRef)) 8130 kEventRemoveFromQueue, &eventRef))
8055#endif /* !USE_CARBON_EVENTS */ 8131#endif /* USE_CARBON_EVENTS */
8056 { 8132 {
8057 int do_help = 0; 8133 int do_help = 0;
8058 struct frame *f; 8134 struct frame *f;
8059 8135
8060 expected = 0;
8061
8062 /* It is necessary to set this (additional) argument slot of an 8136 /* It is necessary to set this (additional) argument slot of an
8063 event to nil because keyboard.c protects incompletely 8137 event to nil because keyboard.c protects incompletely
8064 processed event from being garbage collected by placing them 8138 processed event from being garbage collected by placing them
@@ -8073,7 +8147,7 @@ XTread_socket (sd, expected, hold_quit)
8073 switch (GetEventClass (eventRef)) 8147 switch (GetEventClass (eventRef))
8074 { 8148 {
8075 case kEventClassWindow: 8149 case kEventClassWindow:
8076 if (GetEventKind (eventRef) == kEventWindowBoundsChanged) 8150 if (GetEventKind (eventRef) == kEventWindowBoundsChanged)
8077 { 8151 {
8078 WindowPtr window_ptr; 8152 WindowPtr window_ptr;
8079 GetEventParameter(eventRef, kEventParamDirectObject, 8153 GetEventParameter(eventRef, kEventParamDirectObject,
@@ -8081,13 +8155,7 @@ XTread_socket (sd, expected, hold_quit)
8081 NULL, &window_ptr); 8155 NULL, &window_ptr);
8082 f = mac_window_to_frame (window_ptr); 8156 f = mac_window_to_frame (window_ptr);
8083 if (f && !f->async_iconified) 8157 if (f && !f->async_iconified)
8084 { 8158 x_real_positions (f, &f->left_pos, &f->top_pos);
8085 int x, y;
8086
8087 x_real_positions (f, &x, &y);
8088 f->left_pos = x;
8089 f->top_pos = y;
8090 }
8091 SendEventToEventTarget (eventRef, toolbox_dispatcher); 8159 SendEventToEventTarget (eventRef, toolbox_dispatcher);
8092 } 8160 }
8093 break; 8161 break;
@@ -8096,7 +8164,7 @@ XTread_socket (sd, expected, hold_quit)
8096 { 8164 {
8097 SInt32 delta; 8165 SInt32 delta;
8098 Point point; 8166 Point point;
8099 WindowPtr window_ptr = mac_front_window (); 8167 WindowPtr window_ptr = front_emacs_window ();
8100 8168
8101 if (!IsValidWindowPtr (window_ptr)) 8169 if (!IsValidWindowPtr (window_ptr))
8102 { 8170 {
@@ -8158,33 +8226,28 @@ XTread_socket (sd, expected, hold_quit)
8158 } 8226 }
8159 else 8227 else
8160 { 8228 {
8161 window_ptr = FrontWindow (); 8229 part_code = FindWindow (er.where, &window_ptr);
8162 if (tip_window && window_ptr == tip_window) 8230 if (tip_window && window_ptr == tip_window)
8163 { 8231 {
8164 HideWindow (tip_window); 8232 HideWindow (tip_window);
8165 window_ptr = FrontWindow (); 8233 part_code = FindWindow (er.where, &window_ptr);
8166 } 8234 }
8167
8168 if (!is_emacs_window (window_ptr))
8169 break;
8170
8171 part_code = FindWindow (er.where, &window_ptr);
8172 } 8235 }
8173 8236
8237 if (er.what != mouseDown && part_code != inContent)
8238 break;
8239
8174 switch (part_code) 8240 switch (part_code)
8175 { 8241 {
8176 case inMenuBar: 8242 case inMenuBar:
8177 if (er.what == mouseDown) 8243 f = mac_window_to_frame (front_emacs_window ());
8178 { 8244 saved_menu_event_location = er.where;
8179 f = mac_window_to_frame (mac_front_window ()); 8245 inev.kind = MENU_BAR_ACTIVATE_EVENT;
8180 saved_menu_event_location = er.where; 8246 XSETFRAME (inev.frame_or_window, f);
8181 inev.kind = MENU_BAR_ACTIVATE_EVENT;
8182 XSETFRAME (inev.frame_or_window, f);
8183 }
8184 break; 8247 break;
8185 8248
8186 case inContent: 8249 case inContent:
8187 if (window_ptr != mac_front_window ()) 8250 if (window_ptr != front_emacs_window ())
8188 SelectWindow (window_ptr); 8251 SelectWindow (window_ptr);
8189 else 8252 else
8190 { 8253 {
@@ -8281,7 +8344,7 @@ XTread_socket (sd, expected, hold_quit)
8281 } 8344 }
8282 else 8345 else
8283 { 8346 {
8284 if (dpyinfo->grabbed & (1 << inev.code) == 0) 8347 if ((dpyinfo->grabbed & (1 << inev.code)) == 0)
8285 /* If a button is released though it was not 8348 /* If a button is released though it was not
8286 previously pressed, that would be because 8349 previously pressed, that would be because
8287 of multi-button emulation. */ 8350 of multi-button emulation. */
@@ -8304,27 +8367,16 @@ XTread_socket (sd, expected, hold_quit)
8304 8367
8305 case inDrag: 8368 case inDrag:
8306#if TARGET_API_MAC_CARBON 8369#if TARGET_API_MAC_CARBON
8307 if (er.what == mouseDown) 8370 DragWindow (window_ptr, er.where, NULL);
8308 {
8309 BitMap bm;
8310
8311 GetQDGlobalsScreenBits (&bm);
8312 DragWindow (window_ptr, er.where, &bm.bounds);
8313 }
8314#else /* not TARGET_API_MAC_CARBON */ 8371#else /* not TARGET_API_MAC_CARBON */
8315 DragWindow (window_ptr, er.where, &qd.screenBits.bounds); 8372 DragWindow (window_ptr, er.where, &qd.screenBits.bounds);
8316#endif /* not TARGET_API_MAC_CARBON */ 8373#endif /* not TARGET_API_MAC_CARBON */
8317 /* Update the frame parameters. */ 8374 /* Update the frame parameters. */
8318 { 8375 {
8319 struct frame *f = mac_window_to_frame (window_ptr); 8376 struct frame *f = mac_window_to_frame (window_ptr);
8377
8320 if (f && !f->async_iconified) 8378 if (f && !f->async_iconified)
8321 { 8379 x_real_positions (f, &f->left_pos, &f->top_pos);
8322 int x, y;
8323
8324 x_real_positions (f, &x, &y);
8325 f->left_pos = x;
8326 f->top_pos = y;
8327 }
8328 } 8380 }
8329 break; 8381 break;
8330 8382
@@ -8339,11 +8391,8 @@ XTread_socket (sd, expected, hold_quit)
8339 8391
8340 /* window resize handling added --ben */ 8392 /* window resize handling added --ben */
8341 case inGrow: 8393 case inGrow:
8342 if (er.what == mouseDown) 8394 do_grow_window (window_ptr, &er);
8343 { 8395 break;
8344 do_grow_window(window_ptr, &er);
8345 break;
8346 }
8347 8396
8348 /* window zoom handling added --ben */ 8397 /* window zoom handling added --ben */
8349 case inZoomIn: 8398 case inZoomIn:
@@ -8415,7 +8464,7 @@ XTread_socket (sd, expected, hold_quit)
8415 8464
8416 if (!is_emacs_window (window_ptr)) 8465 if (!is_emacs_window (window_ptr))
8417 break; 8466 break;
8418 8467
8419 f = mac_window_to_frame (window_ptr); 8468 f = mac_window_to_frame (window_ptr);
8420 8469
8421 if ((er.modifiers & activeFlag) != 0) 8470 if ((er.modifiers & activeFlag) != 0)
@@ -8486,7 +8535,7 @@ XTread_socket (sd, expected, hold_quit)
8486#endif 8535#endif
8487 8536
8488#if TARGET_API_MAC_CARBON 8537#if TARGET_API_MAC_CARBON
8489 if (!IsValidWindowPtr (mac_front_window ())) 8538 if (!IsValidWindowPtr (front_emacs_window ()))
8490 { 8539 {
8491 SysBeep (1); 8540 SysBeep (1);
8492 break; 8541 break;
@@ -8590,7 +8639,7 @@ XTread_socket (sd, expected, hold_quit)
8590 inev.modifiers = mac_to_emacs_modifiers (er.modifiers); 8639 inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
8591#endif 8640#endif
8592 XSETFRAME (inev.frame_or_window, 8641 XSETFRAME (inev.frame_or_window,
8593 mac_window_to_frame (mac_front_window ())); 8642 mac_window_to_frame (front_emacs_window ()));
8594 inev.timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ 8643 inev.timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
8595 break; 8644 break;
8596 8645
@@ -8607,16 +8656,16 @@ XTread_socket (sd, expected, hold_quit)
8607 WindowPtr wp; 8656 WindowPtr wp;
8608 Lisp_Object frame; 8657 Lisp_Object frame;
8609 8658
8610 wp = mac_front_window (); 8659 wp = front_emacs_window ();
8611 8660
8612 if (!wp) 8661 if (!wp)
8613 { 8662 {
8614 struct frame *f = XFRAME (XCAR (Vframe_list)); 8663 struct frame *f = XFRAME (XCAR (Vframe_list));
8615 CollapseWindow (FRAME_MAC_WINDOW (f), false); 8664 CollapseWindow (FRAME_MAC_WINDOW (f), false);
8616 wp = mac_front_window (); 8665 wp = front_emacs_window ();
8617 } 8666 }
8618 8667
8619 if (wp && is_emacs_window (wp)) 8668 if (wp)
8620 f = mac_window_to_frame (wp); 8669 f = mac_window_to_frame (wp);
8621 8670
8622 inev.kind = DRAG_N_DROP_EVENT; 8671 inev.kind = DRAG_N_DROP_EVENT;
@@ -8742,6 +8791,7 @@ make_mac_frame (FRAME_PTR fp)
8742 8791
8743 mwp = fp->output_data.mac; 8792 mwp = fp->output_data.mac;
8744 8793
8794 BLOCK_INPUT;
8745 if (making_terminal_window) 8795 if (making_terminal_window)
8746 { 8796 {
8747 if (!(mwp->mWP = GetNewCWindow (TERM_WINDOW_RESOURCE, NULL, 8797 if (!(mwp->mWP = GetNewCWindow (TERM_WINDOW_RESOURCE, NULL,
@@ -8769,9 +8819,8 @@ make_mac_frame (FRAME_PTR fp)
8769 /* so that update events can find this mac_output struct */ 8819 /* so that update events can find this mac_output struct */
8770 mwp->mFP = fp; /* point back to emacs frame */ 8820 mwp->mFP = fp; /* point back to emacs frame */
8771 8821
8772 SetPortWindowPort (mwp->mWP);
8773
8774 SizeWindow (mwp->mWP, FRAME_PIXEL_WIDTH (fp), FRAME_PIXEL_HEIGHT (fp), false); 8822 SizeWindow (mwp->mWP, FRAME_PIXEL_WIDTH (fp), FRAME_PIXEL_HEIGHT (fp), false);
8823 UNBLOCK_INPUT;
8775} 8824}
8776 8825
8777 8826
@@ -9073,7 +9122,7 @@ mac_check_for_quit_char ()
9073 e.arg = Qnil; 9122 e.arg = Qnil;
9074 e.modifiers = NULL; 9123 e.modifiers = NULL;
9075 e.timestamp = EventTimeToTicks (GetEventTime (event)) * (1000/60); 9124 e.timestamp = EventTimeToTicks (GetEventTime (event)) * (1000/60);
9076 XSETFRAME (e.frame_or_window, mac_window_to_frame (mac_front_window ())); 9125 XSETFRAME (e.frame_or_window, mac_window_to_frame (front_emacs_window ()));
9077 /* Remove event from queue to prevent looping. */ 9126 /* Remove event from queue to prevent looping. */
9078 RemoveEventFromQueue (GetMainEventQueue (), event); 9127 RemoveEventFromQueue (GetMainEventQueue (), event);
9079 ReleaseEvent (event); 9128 ReleaseEvent (event);
@@ -9194,6 +9243,7 @@ mac_initialize ()
9194 signal (SIGPIPE, x_connection_signal); 9243 signal (SIGPIPE, x_connection_signal);
9195#endif 9244#endif
9196 9245
9246 BLOCK_INPUT;
9197 mac_initialize_display_info (); 9247 mac_initialize_display_info ();
9198 9248
9199#if TARGET_API_MAC_CARBON 9249#if TARGET_API_MAC_CARBON
@@ -9212,6 +9262,7 @@ mac_initialize ()
9212 if (!inhibit_window_system) 9262 if (!inhibit_window_system)
9213 MakeMeTheFrontProcess (); 9263 MakeMeTheFrontProcess ();
9214#endif 9264#endif
9265 UNBLOCK_INPUT;
9215} 9266}
9216 9267
9217 9268