aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGeoff Voelker1996-05-03 18:45:32 +0000
committerGeoff Voelker1996-05-03 18:45:32 +0000
commit52cf03a10fcddb3534cc87aff14932f13f85858b (patch)
treed746b312ee6829e409ba35149f3710cfd46247ed /src
parent69cddef069c6cc9d2ebdd284936606c69654c90d (diff)
downloademacs-52cf03a10fcddb3534cc87aff14932f13f85858b.tar.gz
emacs-52cf03a10fcddb3534cc87aff14932f13f85858b.zip
(Vwindow_system): Declared.
(win32_fill_rect, dumpglyphs, do_line_dance, x_draw_box): Use Get/ReleaseFrameDC. (pixel_to_glyph_coords): Support tty mode. (w32_read_socket): Explicitly use FALSE. Handle WM_PALLETTECHANGED event. (parse_button): Handle mouse button emulation. (my_show_window, my_set_window_pos): New functions. (x_set_offset, x_set_window_size, x_raise_frame, x_lower_frame): Use my_set_window_pos. (x_make_frame_visible, x_iconify_frame): Use my_show_window. (x_draw_box): Don't trim right and bottom. (x_make_frame_visible): Don't invoke SetForgroundWindow. (win32_term_init): Use GetDC directly. Initialize palette and win32_num_mouse_buttons. (win32_update_begin): Regenerate palette if necessary. (x_delete_display): Free palette. (win32_initialize) [ATTACH_THREADS]: Only AttachThreadInput if conditional is defined.
Diffstat (limited to 'src')
-rw-r--r--src/w32term.c309
1 files changed, 226 insertions, 83 deletions
diff --git a/src/w32term.c b/src/w32term.c
index 2daa30d96cd..3f214a53472 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -15,8 +15,7 @@ GNU General Public License for more details.
15 15
16You should have received a copy of the GNU General Public License 16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to 17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19Boston, MA 02111-1307, USA. */
20 19
21/* Added by Kevin Gallo */ 20/* Added by Kevin Gallo */
22 21
@@ -50,6 +49,8 @@ Boston, MA 02111-1307, USA. */
50 49
51extern void free_frame_menubar (); 50extern void free_frame_menubar ();
52 51
52extern Lisp_Object Vwindow_system;
53
53#define x_any_window_to_frame x_window_to_frame 54#define x_any_window_to_frame x_window_to_frame
54#define x_top_window_to_frame x_window_to_frame 55#define x_top_window_to_frame x_window_to_frame
55 56
@@ -98,6 +99,10 @@ HANDLE hMainThread = NULL;
98static FRAME_PTR last_mouse_frame; 99static FRAME_PTR last_mouse_frame;
99static RECT last_mouse_glyph; 100static RECT last_mouse_glyph;
100 101
102Lisp_Object Vwin32_num_mouse_buttons;
103
104Lisp_Object Vwin32_swap_mouse_buttons;
105
101/* The scroll bar in which the last motion event occurred. 106/* The scroll bar in which the last motion event occurred.
102 107
103 If the last motion event occurred in a scroll bar, we set this 108 If the last motion event occurred in a scroll bar, we set this
@@ -195,7 +200,6 @@ win32_fill_rect (f, _hdc, pix, lprect)
195{ 200{
196 HDC hdc; 201 HDC hdc;
197 HBRUSH hb; 202 HBRUSH hb;
198 HANDLE oldobj;
199 RECT rect; 203 RECT rect;
200 204
201 if (_hdc) 205 if (_hdc)
@@ -203,18 +207,15 @@ win32_fill_rect (f, _hdc, pix, lprect)
203 else 207 else
204 { 208 {
205 if (!f) return; 209 if (!f) return;
206 hdc = my_get_dc (FRAME_WIN32_WINDOW (f)); 210 hdc = get_frame_dc (f);
207 } 211 }
208 212
209 hb = CreateSolidBrush (pix); 213 hb = CreateSolidBrush (pix);
210 oldobj = SelectObject (hdc, hb);
211
212 FillRect (hdc, lprect, hb); 214 FillRect (hdc, lprect, hb);
213 SelectObject (hdc, oldobj);
214 DeleteObject (hb); 215 DeleteObject (hb);
215 216
216 if (!_hdc) 217 if (!_hdc)
217 ReleaseDC (FRAME_WIN32_WINDOW (f), hdc); 218 release_frame_dc (f, hdc);
218} 219}
219 220
220void 221void
@@ -222,7 +223,7 @@ win32_clear_window (f)
222 FRAME_PTR f; 223 FRAME_PTR f;
223{ 224{
224 RECT rect; 225 RECT rect;
225 226
226 GetClientRect (FRAME_WIN32_WINDOW (f), &rect); 227 GetClientRect (FRAME_WIN32_WINDOW (f), &rect);
227 win32_clear_rect (f, NULL, &rect); 228 win32_clear_rect (f, NULL, &rect);
228} 229}
@@ -249,6 +250,14 @@ win32_update_begin (f)
249 250
250 BLOCK_INPUT; 251 BLOCK_INPUT;
251 252
253 /* Regenerate display palette before drawing if list of requested
254 colors has changed. */
255 if (FRAME_WIN32_DISPLAY_INFO (f)->regen_palette)
256 {
257 win32_regenerate_palette (f);
258 FRAME_WIN32_DISPLAY_INFO (f)->regen_palette = FALSE;
259 }
260
252 if (f == FRAME_WIN32_DISPLAY_INFO (f)->mouse_face_mouse_frame) 261 if (f == FRAME_WIN32_DISPLAY_INFO (f)->mouse_face_mouse_frame)
253 { 262 {
254 /* Don't do highlighting for mouse motion during the update. */ 263 /* Don't do highlighting for mouse motion during the update. */
@@ -418,7 +427,7 @@ dumpglyphs (f, left, top, gp, n, hl, just_foreground)
418 int orig_left = left; 427 int orig_left = left;
419 HDC hdc; 428 HDC hdc;
420 429
421 hdc = my_get_dc (window); 430 hdc = get_frame_dc (f);
422 431
423 while (n > 0) 432 while (n > 0)
424 { 433 {
@@ -571,7 +580,7 @@ dumpglyphs (f, left, top, gp, n, hl, just_foreground)
571 } 580 }
572 } 581 }
573 582
574 ReleaseDC (window, hdc); 583 release_frame_dc (f, hdc);
575} 584}
576 585
577 586
@@ -828,7 +837,7 @@ do_line_dance ()
828 837
829 x_display_cursor (updating_frame, 0); 838 x_display_cursor (updating_frame, 0);
830 839
831 hdc = my_get_dc (FRAME_WIN32_WINDOW (f)); 840 hdc = get_frame_dc (f);
832 841
833 for (i = 0; i < ht; ++i) 842 for (i = 0; i < ht; ++i)
834 if (line_dance[i] != -1 && (distance = line_dance[i]-i) > 0) 843 if (line_dance[i] != -1 && (distance = line_dance[i]-i) > 0)
@@ -862,7 +871,7 @@ do_line_dance ()
862 i = j+1; 871 i = j+1;
863 } 872 }
864 873
865 ReleaseDC (FRAME_WIN32_WINDOW (f), hdc); 874 release_frame_dc (f, hdc);
866 875
867 for (i = 0; i < ht; ++i) 876 for (i = 0; i < ht; ++i)
868 if (line_dance[i] == -1) 877 if (line_dance[i] == -1)
@@ -1098,6 +1107,14 @@ pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip)
1098 RECT *bounds; 1107 RECT *bounds;
1099 int noclip; 1108 int noclip;
1100{ 1109{
1110 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
1111 if (NILP (Vwindow_system))
1112 {
1113 *x = pix_x;
1114 *y = pix_y;
1115 return;
1116 }
1117
1101 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down 1118 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
1102 even for negative values. */ 1119 even for negative values. */
1103 if (pix_x < 0) 1120 if (pix_x < 0)
@@ -1139,6 +1156,14 @@ glyph_to_pixel_coords (f, x, y, pix_x, pix_y)
1139 register int x, y; 1156 register int x, y;
1140 register int *pix_x, *pix_y; 1157 register int *pix_x, *pix_y;
1141{ 1158{
1159 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
1160 if (NILP (Vwindow_system))
1161 {
1162 *pix_x = x;
1163 *pix_y = y;
1164 return;
1165 }
1166
1142 *pix_x = CHAR_TO_PIXEL_COL (f, x); 1167 *pix_x = CHAR_TO_PIXEL_COL (f, x);
1143 *pix_y = CHAR_TO_PIXEL_ROW (f, y); 1168 *pix_y = CHAR_TO_PIXEL_ROW (f, y);
1144} 1169}
@@ -1163,19 +1188,31 @@ parse_button (message, pbutton, pup)
1163 up = 1; 1188 up = 1;
1164 break; 1189 break;
1165 case WM_MBUTTONDOWN: 1190 case WM_MBUTTONDOWN:
1166 button = 1; 1191 if (NILP (Vwin32_swap_mouse_buttons))
1192 button = 1;
1193 else
1194 button = 2;
1167 up = 0; 1195 up = 0;
1168 break; 1196 break;
1169 case WM_MBUTTONUP: 1197 case WM_MBUTTONUP:
1170 button = 1; 1198 if (NILP (Vwin32_swap_mouse_buttons))
1199 button = 1;
1200 else
1201 button = 2;
1171 up = 1; 1202 up = 1;
1172 break; 1203 break;
1173 case WM_RBUTTONDOWN: 1204 case WM_RBUTTONDOWN:
1174 button = 2; 1205 if (NILP (Vwin32_swap_mouse_buttons))
1206 button = 2;
1207 else
1208 button = 1;
1175 up = 0; 1209 up = 0;
1176 break; 1210 break;
1177 case WM_RBUTTONUP: 1211 case WM_RBUTTONUP:
1178 button = 2; 1212 if (NILP (Vwin32_swap_mouse_buttons))
1213 button = 2;
1214 else
1215 button = 1;
1179 up = 1; 1216 up = 1;
1180 break; 1217 break;
1181 default: 1218 default:
@@ -1770,6 +1807,36 @@ my_create_scrollbar (f, bar)
1770 return ((HWND) msg.wParam); 1807 return ((HWND) msg.wParam);
1771} 1808}
1772 1809
1810//#define ATTACH_THREADS
1811
1812void
1813my_show_window (HWND hwnd, int how)
1814{
1815#ifndef ATTACH_THREADS
1816 SendMessage (hwnd, WM_EMACS_SHOWWINDOW, (WPARAM) how, 0);
1817#else
1818 ShowWindow (hwnd , how);
1819#endif
1820}
1821
1822void
1823my_set_window_pos (HWND hwnd, HWND hwndAfter,
1824 int x, int y, int cx, int cy, int flags)
1825{
1826#ifndef ATTACH_THREADS
1827 Win32WindowPos pos;
1828 pos.hwndAfter = hwndAfter;
1829 pos.x = x;
1830 pos.y = y;
1831 pos.cx = cx;
1832 pos.cy = cy;
1833 pos.flags = flags;
1834 SendMessage (hwnd, WM_EMACS_SETWINDOWPOS, (WPARAM) &pos, 0);
1835#else
1836 SetWindowPos (hwnd, hwndAfter, x, y, cx, cy, flags);
1837#endif
1838}
1839
1773void 1840void
1774my_destroy_window (f, hwnd) 1841my_destroy_window (f, hwnd)
1775 struct frame * f; 1842 struct frame * f;
@@ -1877,6 +1944,7 @@ x_scroll_bar_move (bar, top, left, width, height)
1877 1944
1878 MoveWindow (w, left, top, width, height, TRUE); 1945 MoveWindow (w, left, top, width, height, TRUE);
1879 SetScrollRange (w, SB_CTL, 0, height, FALSE); 1946 SetScrollRange (w, SB_CTL, 0, height, FALSE);
1947 InvalidateRect (w, NULL, FALSE);
1880 1948
1881 XSETINT (bar->left, left); 1949 XSETINT (bar->left, left);
1882 XSETINT (bar->top, top); 1950 XSETINT (bar->top, top);
@@ -2069,7 +2137,7 @@ win32_judge_scroll_bars (f)
2069 2137
2070 This may be called from a signal handler, so we have to ignore GC 2138 This may be called from a signal handler, so we have to ignore GC
2071 mark bits. */ 2139 mark bits. */
2072static void 2140static int
2073x_scroll_bar_handle_click (bar, msg, emacs_event) 2141x_scroll_bar_handle_click (bar, msg, emacs_event)
2074 struct scroll_bar *bar; 2142 struct scroll_bar *bar;
2075 Win32Msg *msg; 2143 Win32Msg *msg;
@@ -2078,12 +2146,10 @@ x_scroll_bar_handle_click (bar, msg, emacs_event)
2078 if (! GC_WINDOWP (bar->window)) 2146 if (! GC_WINDOWP (bar->window))
2079 abort (); 2147 abort ();
2080 2148
2081 emacs_event->kind = scroll_bar_click; 2149 emacs_event->kind = win32_scroll_bar_click;
2082 emacs_event->code = 0; 2150 emacs_event->code = 0;
2083 emacs_event->modifiers = (msg->dwModifiers 2151 /* not really meaningful to distinguish up/down */
2084 | ((LOWORD (msg->msg.wParam) == SB_ENDSCROLL) 2152 emacs_event->modifiers = msg->dwModifiers;
2085 ? up_modifier
2086 : down_modifier));
2087 emacs_event->frame_or_window = bar->window; 2153 emacs_event->frame_or_window = bar->window;
2088 emacs_event->timestamp = msg->msg.time; 2154 emacs_event->timestamp = msg->msg.time;
2089 2155
@@ -2096,18 +2162,17 @@ x_scroll_bar_handle_click (bar, msg, emacs_event)
2096 2162
2097 switch (LOWORD (msg->msg.wParam)) 2163 switch (LOWORD (msg->msg.wParam))
2098 { 2164 {
2099 case SB_THUMBPOSITION:
2100 case SB_THUMBTRACK: 2165 case SB_THUMBTRACK:
2101 emacs_event->part = scroll_bar_handle; 2166 emacs_event->part = scroll_bar_handle;
2102 if (VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar->height)) <= 0xffff) 2167 if (VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar->height)) <= 0xffff)
2103 y = HIWORD (msg->msg.wParam); 2168 y = HIWORD (msg->msg.wParam);
2104 break; 2169 break;
2105 case SB_LINEDOWN: 2170 case SB_LINEDOWN:
2106 emacs_event->part = scroll_bar_handle; 2171 emacs_event->part = scroll_bar_down_arrow;
2107 if (y < top_range) y++; 2172 if (y < top_range) y++;
2108 break; 2173 break;
2109 case SB_LINEUP: 2174 case SB_LINEUP:
2110 emacs_event->part = scroll_bar_handle; 2175 emacs_event->part = scroll_bar_up_arrow;
2111 if (y) y--; 2176 if (y) y--;
2112 break; 2177 break;
2113 case SB_PAGEUP: 2178 case SB_PAGEUP:
@@ -2124,17 +2189,20 @@ x_scroll_bar_handle_click (bar, msg, emacs_event)
2124 emacs_event->part = scroll_bar_handle; 2189 emacs_event->part = scroll_bar_handle;
2125 y = top_range; 2190 y = top_range;
2126 break; 2191 break;
2127 case SB_ENDSCROLL: 2192 case SB_THUMBPOSITION:
2128 emacs_event->part = scroll_bar_handle; 2193 emacs_event->part = scroll_bar_handle;
2129 x_scroll_bar_set_handle (bar, y , y, 0);
2130 break; 2194 break;
2195 case SB_ENDSCROLL:
2131 default: 2196 default:
2132 emacs_event->part = scroll_bar_handle; 2197 return FALSE;
2133 break;
2134 } 2198 }
2135 2199
2200 x_scroll_bar_set_handle (bar, y , y, 0);
2201
2136 XSETINT (emacs_event->x, y); 2202 XSETINT (emacs_event->x, y);
2137 XSETINT (emacs_event->y, top_range); 2203 XSETINT (emacs_event->y, top_range);
2204
2205 return TRUE;
2138 } 2206 }
2139} 2207}
2140 2208
@@ -2196,13 +2264,34 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
2196x_scroll_bar_clear (f) 2264x_scroll_bar_clear (f)
2197 FRAME_PTR f; 2265 FRAME_PTR f;
2198{ 2266{
2199#if 0
2200 Lisp_Object bar; 2267 Lisp_Object bar;
2201 2268
2202 for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); 2269 for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar);
2203 bar = XSCROLL_BAR (bar)->next) 2270 bar = XSCROLL_BAR (bar)->next)
2204 UpdateWindow (SCROLL_BAR_WIN32_WINDOW (XSCROLL_BAR (bar))); 2271 {
2205#endif 2272 HWND window = SCROLL_BAR_WIN32_WINDOW (XSCROLL_BAR (bar));
2273 HDC hdc = GetDC (window);
2274 RECT rect;
2275
2276 GetClientRect (window, &rect);
2277 select_palette (f, hdc);
2278 win32_clear_rect (f, hdc, &rect);
2279 deselect_palette (f, hdc);
2280 }
2281}
2282
2283show_scroll_bars (f, how)
2284 FRAME_PTR f;
2285 int how;
2286{
2287 Lisp_Object bar;
2288
2289 for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar);
2290 bar = XSCROLL_BAR (bar)->next)
2291 {
2292 HWND window = SCROLL_BAR_WIN32_WINDOW (XSCROLL_BAR (bar));
2293 my_show_window (window, how);
2294 }
2206} 2295}
2207 2296
2208 2297
@@ -2303,7 +2392,7 @@ w32_read_socket (sd, bufp, numchars, waitp, expected)
2303 if (numchars <= 0) 2392 if (numchars <= 0)
2304 abort (); /* Don't think this happens. */ 2393 abort (); /* Don't think this happens. */
2305 2394
2306 while (get_next_msg (&msg, 0)) 2395 while (get_next_msg (&msg, FALSE))
2307 { 2396 {
2308 switch (msg.msg.message) 2397 switch (msg.msg.message)
2309 { 2398 {
@@ -2339,6 +2428,12 @@ w32_read_socket (sd, bufp, numchars, waitp, expected)
2339 } 2428 }
2340 2429
2341 break; 2430 break;
2431 case WM_PALETTECHANGED:
2432 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
2433 if (f)
2434 /* Realize palette - will force update if needed. */
2435 release_frame_dc (f, get_frame_dc (f));
2436 break;
2342 case WM_KEYDOWN: 2437 case WM_KEYDOWN:
2343 case WM_SYSKEYDOWN: 2438 case WM_SYSKEYDOWN:
2344 f = x_window_to_frame (dpyinfo, msg.msg.hwnd); 2439 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
@@ -2350,7 +2445,7 @@ w32_read_socket (sd, bufp, numchars, waitp, expected)
2350 temp_buffer[temp_index++] = msg.msg.wParam; 2445 temp_buffer[temp_index++] = msg.msg.wParam;
2351 bufp->kind = non_ascii_keystroke; 2446 bufp->kind = non_ascii_keystroke;
2352 bufp->code = msg.msg.wParam; 2447 bufp->code = msg.msg.wParam;
2353 bufp->modifiers = win32_kbd_mods_to_emacs (msg.dwModifiers); 2448 bufp->modifiers = win32_kbd_mods_to_emacs (msg.dwModifiers);
2354 XSETFRAME (bufp->frame_or_window, f); 2449 XSETFRAME (bufp->frame_or_window, f);
2355 bufp->timestamp = msg.msg.time; 2450 bufp->timestamp = msg.msg.time;
2356 bufp++; 2451 bufp++;
@@ -2462,10 +2557,12 @@ w32_read_socket (sd, bufp, numchars, waitp, expected)
2462 2557
2463 if (bar && numchars >= 1) 2558 if (bar && numchars >= 1)
2464 { 2559 {
2465 x_scroll_bar_handle_click (bar, &msg, bufp); 2560 if (x_scroll_bar_handle_click (bar, &msg, bufp))
2466 bufp++; 2561 {
2467 count++; 2562 bufp++;
2468 numchars--; 2563 count++;
2564 numchars--;
2565 }
2469 } 2566 }
2470 } 2567 }
2471 2568
@@ -2684,25 +2781,19 @@ x_draw_box (f)
2684 HBRUSH hb; 2781 HBRUSH hb;
2685 HDC hdc; 2782 HDC hdc;
2686 2783
2687 hdc = my_get_dc (FRAME_WIN32_WINDOW (f)); 2784 hdc = get_frame_dc (f);
2688 2785
2689 hb = CreateSolidBrush (f->output_data.win32->cursor_pixel); 2786 hb = CreateSolidBrush (f->output_data.win32->cursor_pixel);
2690 2787
2691 rect.left = CHAR_TO_PIXEL_COL (f, curs_x); 2788 rect.left = CHAR_TO_PIXEL_COL (f, curs_x);
2692 rect.top = CHAR_TO_PIXEL_ROW (f, curs_y); 2789 rect.top = CHAR_TO_PIXEL_ROW (f, curs_y);
2693 rect.right = rect.left + FONT_WIDTH (f->output_data.win32->font) - 1; 2790 rect.right = rect.left + FONT_WIDTH (f->output_data.win32->font);
2694 rect.bottom = rect.top + f->output_data.win32->line_height - 1; 2791 rect.bottom = rect.top + f->output_data.win32->line_height;
2695 2792
2696 /* rect.left++; */
2697 /* rect.top++; */
2698 rect.right--;
2699 rect.bottom--;
2700
2701 FrameRect (hdc, &rect, hb); 2793 FrameRect (hdc, &rect, hb);
2702
2703 DeleteObject (hb); 2794 DeleteObject (hb);
2704 2795
2705 ReleaseDC (FRAME_WIN32_WINDOW (f), hdc); 2796 release_frame_dc (f, hdc);
2706} 2797}
2707 2798
2708/* Clear the cursor of frame F to background color, 2799/* Clear the cursor of frame F to background color,
@@ -3130,11 +3221,11 @@ x_set_offset (f, xoff, yoff, change_gravity)
3130 modified_top += f->output_data.win32->border_width; 3221 modified_top += f->output_data.win32->border_width;
3131 } 3222 }
3132 3223
3133 SetWindowPos (FRAME_WIN32_WINDOW (f), 3224 my_set_window_pos (FRAME_WIN32_WINDOW (f),
3134 NULL, 3225 NULL,
3135 modified_left, modified_top, 3226 modified_left, modified_top,
3136 0,0, 3227 0,0,
3137 SWP_NOZORDER | SWP_NOSIZE); 3228 SWP_NOZORDER | SWP_NOSIZE);
3138 UNBLOCK_INPUT; 3229 UNBLOCK_INPUT;
3139} 3230}
3140 3231
@@ -3177,12 +3268,12 @@ x_set_window_size (f, change_gravity, cols, rows)
3177 3268
3178 /* All windows have an extra pixel */ 3269 /* All windows have an extra pixel */
3179 3270
3180 SetWindowPos (FRAME_WIN32_WINDOW (f), 3271 my_set_window_pos (FRAME_WIN32_WINDOW (f),
3181 NULL, 3272 NULL,
3182 0, 0, 3273 0, 0,
3183 rect.right - rect.left + 1, 3274 rect.right - rect.left + 1,
3184 rect.bottom - rect.top + 1, 3275 rect.bottom - rect.top + 1,
3185 SWP_NOZORDER | SWP_NOMOVE); 3276 SWP_NOZORDER | SWP_NOMOVE);
3186 } 3277 }
3187 3278
3188 /* Now, strictly speaking, we can't be sure that this is accurate, 3279 /* Now, strictly speaking, we can't be sure that this is accurate,
@@ -3272,13 +3363,13 @@ x_unfocus_frame (f)
3272x_raise_frame (f) 3363x_raise_frame (f)
3273 struct frame *f; 3364 struct frame *f;
3274{ 3365{
3275 if (f->async_visible) 3366// if (f->async_visible)
3276 { 3367 {
3277 BLOCK_INPUT; 3368 BLOCK_INPUT;
3278 SetWindowPos (FRAME_WIN32_WINDOW (f), 3369 my_set_window_pos (FRAME_WIN32_WINDOW (f),
3279 HWND_TOP, 3370 HWND_TOP,
3280 0, 0, 0, 0, 3371 0, 0, 0, 0,
3281 SWP_NOSIZE | SWP_NOMOVE); 3372 SWP_NOSIZE | SWP_NOMOVE);
3282 UNBLOCK_INPUT; 3373 UNBLOCK_INPUT;
3283 } 3374 }
3284} 3375}
@@ -3288,13 +3379,13 @@ x_raise_frame (f)
3288x_lower_frame (f) 3379x_lower_frame (f)
3289 struct frame *f; 3380 struct frame *f;
3290{ 3381{
3291 if (f->async_visible) 3382// if (f->async_visible)
3292 { 3383 {
3293 BLOCK_INPUT; 3384 BLOCK_INPUT;
3294 SetWindowPos (FRAME_WIN32_WINDOW (f), 3385 my_set_window_pos (FRAME_WIN32_WINDOW (f),
3295 HWND_BOTTOM, 3386 HWND_BOTTOM,
3296 0, 0, 0, 0, 3387 0, 0, 0, 0,
3297 SWP_NOSIZE | SWP_NOMOVE); 3388 SWP_NOSIZE | SWP_NOMOVE);
3298 UNBLOCK_INPUT; 3389 UNBLOCK_INPUT;
3299 } 3390 }
3300} 3391}
@@ -3331,14 +3422,15 @@ x_make_frame_visible (f)
3331 if we get to x_make_frame_visible a second time 3422 if we get to x_make_frame_visible a second time
3332 before the window gets really visible. */ 3423 before the window gets really visible. */
3333 if (! FRAME_ICONIFIED_P (f) 3424 if (! FRAME_ICONIFIED_P (f)
3334 && ! f->output_data.win32->asked_for_visible) 3425 && ! f->output_data.win32->asked_for_visible)
3335 { 3426 {
3336 x_set_offset (f, f->output_data.win32->left_pos, 3427 x_set_offset (f, f->output_data.win32->left_pos, f->output_data.win32->top_pos, 0);
3337 f->output_data.win32->top_pos, 0); 3428// SetForegroundWindow (FRAME_WIN32_WINDOW (f));
3338 } 3429 }
3339 3430
3340 f->output_data.win32->asked_for_visible = 1; 3431 f->output_data.win32->asked_for_visible = 1;
3341 ShowWindow (FRAME_WIN32_WINDOW (f), SW_SHOW); 3432
3433 my_show_window (FRAME_WIN32_WINDOW (f), SW_SHOWNORMAL);
3342 } 3434 }
3343 3435
3344 /* Synchronize to ensure Emacs knows the frame is visible 3436 /* Synchronize to ensure Emacs knows the frame is visible
@@ -3401,7 +3493,7 @@ x_make_frame_invisible (f)
3401 3493
3402 BLOCK_INPUT; 3494 BLOCK_INPUT;
3403 3495
3404 ShowWindow (FRAME_WIN32_WINDOW (f), SW_HIDE); 3496 my_show_window (FRAME_WIN32_WINDOW (f), SW_HIDE);
3405 3497
3406 /* We can't distinguish this from iconification 3498 /* We can't distinguish this from iconification
3407 just by the event that we get from the server. 3499 just by the event that we get from the server.
@@ -3418,7 +3510,8 @@ x_make_frame_invisible (f)
3418 3510
3419/* Change window state from mapped to iconified. */ 3511/* Change window state from mapped to iconified. */
3420 3512
3421void x_iconify_frame (f) 3513void
3514x_iconify_frame (f)
3422 struct frame *f; 3515 struct frame *f;
3423{ 3516{
3424 int result; 3517 int result;
@@ -3432,7 +3525,9 @@ void x_iconify_frame (f)
3432 3525
3433 BLOCK_INPUT; 3526 BLOCK_INPUT;
3434 3527
3435 ShowWindow (FRAME_WIN32_WINDOW (f), SW_SHOWMINIMIZED); 3528 my_show_window (FRAME_WIN32_WINDOW (f), SW_SHOWMINIMIZED);
3529 /* The frame doesn't seem to be lowered automatically. */
3530 x_lower_frame (f);
3436 3531
3437 f->async_iconified = 1; 3532 f->async_iconified = 1;
3438 3533
@@ -3597,7 +3692,7 @@ win32_term_init (display_name, xrm_option, resource_name)
3597 all versions. */ 3692 all versions. */
3598 dpyinfo->xrdb = xrdb; 3693 dpyinfo->xrdb = xrdb;
3599#endif 3694#endif
3600 hdc = my_get_dc (GetDesktopWindow ()); 3695 hdc = GetDC (GetDesktopWindow ());
3601 3696
3602 dpyinfo->height = GetDeviceCaps (hdc, VERTRES); 3697 dpyinfo->height = GetDeviceCaps (hdc, VERTRES);
3603 dpyinfo->width = GetDeviceCaps (hdc, HORZRES); 3698 dpyinfo->width = GetDeviceCaps (hdc, HORZRES);
@@ -3606,6 +3701,7 @@ win32_term_init (display_name, xrm_option, resource_name)
3606 dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL); 3701 dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL);
3607 dpyinfo->height_in = GetDeviceCaps (hdc, LOGPIXELSX); 3702 dpyinfo->height_in = GetDeviceCaps (hdc, LOGPIXELSX);
3608 dpyinfo->width_in = GetDeviceCaps (hdc, LOGPIXELSY); 3703 dpyinfo->width_in = GetDeviceCaps (hdc, LOGPIXELSY);
3704 dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE;
3609 dpyinfo->grabbed = 0; 3705 dpyinfo->grabbed = 0;
3610 dpyinfo->reference_count = 0; 3706 dpyinfo->reference_count = 0;
3611 dpyinfo->n_fonts = 0; 3707 dpyinfo->n_fonts = 0;
@@ -3627,6 +3723,18 @@ win32_term_init (display_name, xrm_option, resource_name)
3627 3723
3628 ReleaseDC (GetDesktopWindow (), hdc); 3724 ReleaseDC (GetDesktopWindow (), hdc);
3629 3725
3726 /* Determine if there is a middle mouse button, to allow parse_button
3727 to decide whether right mouse events should be mouse-2 or
3728 mouse-3. */
3729 XSETINT (Vwin32_num_mouse_buttons, GetSystemMetrics (SM_CMOUSEBUTTONS));
3730
3731 /* initialise palette with white and black */
3732 {
3733 COLORREF color;
3734 defined_color (0, "white", &color, 1);
3735 defined_color (0, "black", &color, 1);
3736 }
3737
3630#ifndef F_SETOWN_BUG 3738#ifndef F_SETOWN_BUG
3631#ifdef F_SETOWN 3739#ifdef F_SETOWN
3632#ifdef F_SETOWN_SOCK_NEG 3740#ifdef F_SETOWN_SOCK_NEG
@@ -3676,6 +3784,21 @@ x_delete_display (dpyinfo)
3676 } 3784 }
3677 } 3785 }
3678 3786
3787 /* free palette table */
3788 {
3789 struct win32_palette_entry * plist;
3790
3791 plist = dpyinfo->color_list;
3792 while (plist)
3793 {
3794 struct win32_palette_entry * pentry = plist;
3795 plist = plist->next;
3796 xfree(pentry);
3797 }
3798 dpyinfo->color_list = NULL;
3799 if (dpyinfo->palette)
3800 DeleteObject(dpyinfo->palette);
3801 }
3679 xfree (dpyinfo->font_table); 3802 xfree (dpyinfo->font_table);
3680 xfree (dpyinfo->win32_id_name); 3803 xfree (dpyinfo->win32_id_name);
3681} 3804}
@@ -3744,8 +3867,17 @@ win32_initialize ()
3744 GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); 3867 GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE);
3745 } 3868 }
3746 3869
3870 /* It is desirable that mainThread should have the same notion of
3871 focus window and active window as winThread. Unfortunately, the
3872 following call to AttachThreadInput, which should do precisely what
3873 we need, causes major problems when Emacs is linked as a console
3874 program. Unfortunately, we have good reasons for doing that, so
3875 instead we need to send messages to winThread to make some API
3876 calls for us (ones that affect, or depend on, the active/focus
3877 window state. */
3878#ifdef ATTACH_THREADS
3747 AttachThreadInput (dwMainThreadId, dwWinThreadId, TRUE); 3879 AttachThreadInput (dwMainThreadId, dwWinThreadId, TRUE);
3748 3880#endif
3749} 3881}
3750 3882
3751void 3883void
@@ -3759,4 +3891,15 @@ syms_of_win32term ()
3759 3891
3760 staticpro (&Qvendor_specific_keysyms); 3892 staticpro (&Qvendor_specific_keysyms);
3761 Qvendor_specific_keysyms = intern ("vendor-specific-keysyms"); 3893 Qvendor_specific_keysyms = intern ("vendor-specific-keysyms");
3894
3895 DEFVAR_INT ("win32-num-mouse-buttons",
3896 &Vwin32_num_mouse_buttons,
3897 "Number of physical mouse buttons.");
3898 Vwin32_num_mouse_buttons = Qnil;
3899
3900 DEFVAR_LISP ("win32-swap-mouse-buttons",
3901 &Vwin32_swap_mouse_buttons,
3902 "Swap the mapping of middle and right mouse buttons.\n\
3903When nil, middle button is mouse-2 and right button is mouse-3.");
3904 Vwin32_swap_mouse_buttons = Qnil;
3762} 3905}