comparison src/w32term.c @ 83569:86395c339701

(w32_set_terminal_modes, w32_reset_terminal_modes): Add terminal arg. (x_clear_frame, x_delete_glyphs, w32_ring_bell, x_ins_del_lines): Add frame arg. (x_delete_terminal, w32_create_terminal): New functions. (w32_term_init): Create a terminal. (w32_initialize): Move terminal specific initialization to w32_create_terminal.
author Jason Rumney <jasonr@gnu.org>
date Tue, 15 May 2007 22:59:04 +0000
parents 07774e5c3ff5
children 91cab9b5f774
comparison
equal deleted inserted replaced
83568:21e8c3e3274f 83569:86395c339701
233 void w32_initialize P_ ((void)); 233 void w32_initialize P_ ((void));
234 static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); 234 static void x_font_min_bounds P_ ((XFontStruct *, int *, int *));
235 int x_compute_min_glyph_bounds P_ ((struct frame *)); 235 int x_compute_min_glyph_bounds P_ ((struct frame *));
236 static void x_update_end P_ ((struct frame *)); 236 static void x_update_end P_ ((struct frame *));
237 static void w32_frame_up_to_date P_ ((struct frame *)); 237 static void w32_frame_up_to_date P_ ((struct frame *));
238 static void w32_set_terminal_modes P_ ((void)); 238 static void w32_set_terminal_modes P_ ((struct terminal *));
239 static void w32_reset_terminal_modes P_ ((void)); 239 static void w32_reset_terminal_modes P_ ((struct terminal *));
240 static void x_clear_frame P_ ((void)); 240 static void x_clear_frame P_ ((struct frame *));
241 static void frame_highlight P_ ((struct frame *)); 241 static void frame_highlight P_ ((struct frame *));
242 static void frame_unhighlight P_ ((struct frame *)); 242 static void frame_unhighlight P_ ((struct frame *));
243 static void x_new_focus_frame P_ ((struct w32_display_info *, 243 static void x_new_focus_frame P_ ((struct w32_display_info *,
244 struct frame *)); 244 struct frame *));
245 static void x_focus_changed P_ ((int, int, struct w32_display_info *, 245 static void x_focus_changed P_ ((int, int, struct w32_display_info *,
799 suspend. When starting Emacs, no window is mapped. And nothing 799 suspend. When starting Emacs, no window is mapped. And nothing
800 must be done to Emacs's own window if it is suspended (though that 800 must be done to Emacs's own window if it is suspended (though that
801 rarely happens). */ 801 rarely happens). */
802 802
803 static void 803 static void
804 w32_set_terminal_modes (void) 804 w32_set_terminal_modes (struct terminal *term)
805 { 805 {
806 } 806 }
807 807
808 /* This is called when exiting or suspending Emacs. Exiting will make 808 /* This is called when exiting or suspending Emacs. Exiting will make
809 the W32 windows go away, and suspending requires no action. */ 809 the W32 windows go away, and suspending requires no action. */
810 810
811 static void 811 static void
812 w32_reset_terminal_modes (void) 812 w32_reset_terminal_modes (struct terminal *term)
813 { 813 {
814 } 814 }
815 815
816 816
817 817
2606 2606
2607 /* Delete N glyphs at the nominal cursor position. Not implemented 2607 /* Delete N glyphs at the nominal cursor position. Not implemented
2608 for X frames. */ 2608 for X frames. */
2609 2609
2610 static void 2610 static void
2611 x_delete_glyphs (n) 2611 x_delete_glyphs (f, n)
2612 struct frame *f;
2612 register int n; 2613 register int n;
2613 { 2614 {
2614 struct frame *f;
2615
2616 if (updating_frame)
2617 f = updating_frame;
2618 else
2619 f = SELECTED_FRAME ();
2620
2621 if (! FRAME_W32_P (f)) 2615 if (! FRAME_W32_P (f))
2622 return; 2616 return;
2623 2617
2624 abort (); 2618 abort ();
2625 } 2619 }
2627 2621
2628 /* Clear entire frame. If updating_frame is non-null, clear that 2622 /* Clear entire frame. If updating_frame is non-null, clear that
2629 frame. Otherwise clear the selected frame. */ 2623 frame. Otherwise clear the selected frame. */
2630 2624
2631 static void 2625 static void
2632 x_clear_frame () 2626 x_clear_frame (struct frame *f)
2633 { 2627 {
2634 struct frame *f;
2635
2636 if (updating_frame)
2637 f = updating_frame;
2638 else
2639 f = SELECTED_FRAME ();
2640
2641 if (! FRAME_W32_P (f)) 2628 if (! FRAME_W32_P (f))
2642 return; 2629 return;
2643 2630
2644 /* Clearing the frame will erase any cursor, so mark them all as no 2631 /* Clearing the frame will erase any cursor, so mark them all as no
2645 longer visible. */ 2632 longer visible. */
2662 2649
2663 2650
2664 /* Make audible bell. */ 2651 /* Make audible bell. */
2665 2652
2666 static void 2653 static void
2667 w32_ring_bell (void) 2654 w32_ring_bell (struct frame *f)
2668 { 2655 {
2669 struct frame *f;
2670
2671 f = SELECTED_FRAME ();
2672
2673 BLOCK_INPUT; 2656 BLOCK_INPUT;
2674 2657
2675 if (FRAME_W32_P (f) && visible_bell) 2658 if (FRAME_W32_P (f) && visible_bell)
2676 { 2659 {
2677 int i; 2660 int i;
2678 HWND hwnd = FRAME_W32_WINDOW (SELECTED_FRAME ()); 2661 HWND hwnd = FRAME_W32_WINDOW (f);
2679 2662
2680 for (i = 0; i < 5; i++) 2663 for (i = 0; i < 5; i++)
2681 { 2664 {
2682 FlashWindow (hwnd, TRUE); 2665 FlashWindow (hwnd, TRUE);
2683 Sleep (10); 2666 Sleep (10);
2684 } 2667 }
2685 FlashWindow (hwnd, FALSE); 2668 FlashWindow (hwnd, FALSE);
2686 } 2669 }
2687 else 2670 else
2688 w32_sys_ring_bell (); 2671 w32_sys_ring_bell (f);
2689 2672
2690 UNBLOCK_INPUT; 2673 UNBLOCK_INPUT;
2691 } 2674 }
2692 2675
2693 2676
2710 2693
2711 /* Perform an insert-lines or delete-lines operation, inserting N 2694 /* Perform an insert-lines or delete-lines operation, inserting N
2712 lines or deleting -N lines at vertical position VPOS. */ 2695 lines or deleting -N lines at vertical position VPOS. */
2713 2696
2714 static void 2697 static void
2715 x_ins_del_lines (vpos, n) 2698 x_ins_del_lines (f, vpos, n)
2699 struct frame *f;
2716 int vpos, n; 2700 int vpos, n;
2717 { 2701 {
2718 struct frame *f;
2719
2720 if (updating_frame)
2721 f = updating_frame;
2722 else
2723 f = SELECTED_FRAME ();
2724
2725 if (! FRAME_W32_P (f)) 2702 if (! FRAME_W32_P (f))
2726 return; 2703 return;
2727 2704
2728 abort (); 2705 abort ();
2729 } 2706 }
5908 UNBLOCK_INPUT; 5885 UNBLOCK_INPUT;
5909 } 5886 }
5910 5887
5911 5888
5912 /* Destroy the window of frame F. */ 5889 /* Destroy the window of frame F. */
5913 5890 void
5914 x_destroy_window (f) 5891 x_destroy_window (f)
5915 struct frame *f; 5892 struct frame *f;
5916 { 5893 {
5917 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); 5894 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
5918 5895
5919 x_free_frame_resources (f); 5896 x_free_frame_resources (f);
5920
5921 dpyinfo->reference_count--; 5897 dpyinfo->reference_count--;
5922 } 5898 }
5923 5899
5924 5900
5925 /* Setting window manager hints. */ 5901 /* Setting window manager hints. */
6175 *current = '\0'; 6151 *current = '\0';
6176 6152
6177 return buffer; 6153 return buffer;
6178 } 6154 }
6179 6155
6180 struct w32_display_info *
6181 w32_term_init (display_name, xrm_option, resource_name)
6182 Lisp_Object display_name;
6183 char *xrm_option;
6184 char *resource_name;
6185 {
6186 struct w32_display_info *dpyinfo;
6187 HDC hdc;
6188
6189 BLOCK_INPUT;
6190
6191 if (!w32_initialized)
6192 {
6193 w32_initialize ();
6194 w32_initialized = 1;
6195 }
6196
6197 w32_initialize_display_info (display_name);
6198
6199 dpyinfo = &one_w32_display_info;
6200
6201 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
6202
6203 /* Put this display on the chain. */
6204 dpyinfo->next = x_display_list;
6205 x_display_list = dpyinfo;
6206
6207 hdc = GetDC (GetDesktopWindow ());
6208
6209 dpyinfo->height = GetDeviceCaps (hdc, VERTRES);
6210 dpyinfo->width = GetDeviceCaps (hdc, HORZRES);
6211 dpyinfo->root_window = GetDesktopWindow ();
6212 dpyinfo->n_planes = GetDeviceCaps (hdc, PLANES);
6213 dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL);
6214 dpyinfo->resx = GetDeviceCaps (hdc, LOGPIXELSX);
6215 dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY);
6216 dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE;
6217 dpyinfo->image_cache = make_image_cache ();
6218 dpyinfo->height_in = dpyinfo->height / dpyinfo->resx;
6219 dpyinfo->width_in = dpyinfo->width / dpyinfo->resy;
6220 ReleaseDC (GetDesktopWindow (), hdc);
6221
6222 /* initialise palette with white and black */
6223 {
6224 XColor color;
6225 w32_defined_color (0, "white", &color, 1);
6226 w32_defined_color (0, "black", &color, 1);
6227 }
6228
6229 /* Create Fringe Bitmaps and store them for later use.
6230
6231 On W32, bitmaps are all unsigned short, as Windows requires
6232 bitmap data to be Word aligned. For some reason they are
6233 horizontally reflected compared to how they appear on X, so we
6234 need to bitswap and convert to unsigned shorts before creating
6235 the bitmaps. */
6236 w32_init_fringe ();
6237
6238 #ifndef F_SETOWN_BUG
6239 #ifdef F_SETOWN
6240 #ifdef F_SETOWN_SOCK_NEG
6241 /* stdin is a socket here */
6242 fcntl (connection, F_SETOWN, -getpid ());
6243 #else /* ! defined (F_SETOWN_SOCK_NEG) */
6244 fcntl (connection, F_SETOWN, getpid ());
6245 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
6246 #endif /* ! defined (F_SETOWN) */
6247 #endif /* F_SETOWN_BUG */
6248
6249 #ifdef SIGIO
6250 if (interrupt_input)
6251 init_sigio (connection);
6252 #endif /* ! defined (SIGIO) */
6253
6254 UNBLOCK_INPUT;
6255
6256 return dpyinfo;
6257 }
6258
6259 /* Get rid of display DPYINFO, assuming all frames are already gone. */
6260
6261 void
6262 x_delete_display (dpyinfo)
6263 struct w32_display_info *dpyinfo;
6264 {
6265 /* Discard this display from w32_display_name_list and w32_display_list.
6266 We can't use Fdelq because that can quit. */
6267 if (! NILP (w32_display_name_list)
6268 && EQ (XCAR (w32_display_name_list), dpyinfo->name_list_element))
6269 w32_display_name_list = XCDR (w32_display_name_list);
6270 else
6271 {
6272 Lisp_Object tail;
6273
6274 tail = w32_display_name_list;
6275 while (CONSP (tail) && CONSP (XCDR (tail)))
6276 {
6277 if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element))
6278 {
6279 XSETCDR (tail, XCDR (XCDR (tail)));
6280 break;
6281 }
6282 tail = XCDR (tail);
6283 }
6284 }
6285
6286 /* free palette table */
6287 {
6288 struct w32_palette_entry * plist;
6289
6290 plist = dpyinfo->color_list;
6291 while (plist)
6292 {
6293 struct w32_palette_entry * pentry = plist;
6294 plist = plist->next;
6295 xfree (pentry);
6296 }
6297 dpyinfo->color_list = NULL;
6298 if (dpyinfo->palette)
6299 DeleteObject(dpyinfo->palette);
6300 }
6301 xfree (dpyinfo->font_table);
6302 xfree (dpyinfo->w32_id_name);
6303
6304 w32_reset_fringes ();
6305 }
6306
6307 /* Set up use of W32. */
6308
6309 DWORD WINAPI w32_msg_worker (void * arg);
6310
6311 void 6156 void
6312 x_flush (struct frame * f) 6157 x_flush (struct frame * f)
6313 { /* Nothing to do */ } 6158 { /* Nothing to do */ }
6159
6314 6160
6315 extern frame_parm_handler w32_frame_parm_handlers[]; 6161 extern frame_parm_handler w32_frame_parm_handlers[];
6316 6162
6317 static struct redisplay_interface w32_redisplay_interface = 6163 static struct redisplay_interface w32_redisplay_interface =
6318 { 6164 {
6343 w32_draw_window_cursor, 6189 w32_draw_window_cursor,
6344 w32_draw_vertical_window_border, 6190 w32_draw_vertical_window_border,
6345 w32_shift_glyphs_for_insert 6191 w32_shift_glyphs_for_insert
6346 }; 6192 };
6347 6193
6194 static void x_delete_terminal (struct terminal *term);
6195
6196 static struct terminal *
6197 w32_create_terminal (struct w32_display_info *dpyinfo)
6198 {
6199 struct terminal *terminal;
6200
6201 terminal = create_terminal ();
6202
6203 terminal->type = output_w32;
6204 terminal->display_info.w32 = dpyinfo;
6205 dpyinfo->terminal = terminal;
6206
6207 /* MSVC does not type K&R functions with no arguments correctly, and
6208 so we must explicitly cast them. */
6209 terminal->clear_frame_hook = x_clear_frame;
6210 terminal->ins_del_lines_hook = x_ins_del_lines;
6211 terminal->delete_glyphs_hook = x_delete_glyphs;
6212 terminal->ring_bell_hook = w32_ring_bell;
6213 terminal->reset_terminal_modes_hook = w32_reset_terminal_modes;
6214 terminal->set_terminal_modes_hook = w32_set_terminal_modes;
6215 terminal->update_begin_hook = x_update_begin;
6216 terminal->update_end_hook = x_update_end;
6217 terminal->set_terminal_window_hook = w32_set_terminal_window;
6218 terminal->read_socket_hook = w32_read_socket;
6219 terminal->frame_up_to_date_hook = w32_frame_up_to_date;
6220 terminal->mouse_position_hook = w32_mouse_position;
6221 terminal->frame_rehighlight_hook = w32_frame_rehighlight;
6222 terminal->frame_raise_lower_hook = w32_frame_raise_lower;
6223 // terminal->fullscreen_hook = XTfullscreen_hook;
6224 terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar;
6225 terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars;
6226 terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar;
6227 terminal->judge_scroll_bars_hook = w32_judge_scroll_bars;
6228
6229 terminal->delete_frame_hook = x_destroy_window;
6230 terminal->delete_terminal_hook = x_delete_terminal;
6231
6232 terminal->rif = &w32_redisplay_interface;
6233 terminal->scroll_region_ok = 1; /* We'll scroll partial frames. */
6234 terminal->char_ins_del_ok = 1;
6235 terminal->line_ins_del_ok = 1; /* We'll just blt 'em. */
6236 terminal->fast_clear_end_of_line = 1; /* X does this well. */
6237 terminal->memory_below_frame = 0; /* We don't remember what scrolls
6238 off the bottom. */
6239
6240 return terminal;
6241 }
6242
6243 static void
6244 x_delete_terminal (struct terminal *terminal)
6245 {
6246 struct w32_display_info *dpyinfo = terminal->display_info.w32;
6247 int i;
6248
6249 /* Protect against recursive calls. Fdelete_frame in
6250 delete_terminal calls us back when it deletes our last frame. */
6251 if (terminal->deleted)
6252 return;
6253
6254 BLOCK_INPUT;
6255 /* Free the fonts in the font table. */
6256 for (i = 0; i < dpyinfo->n_fonts; i++)
6257 if (dpyinfo->font_table[i].name)
6258 {
6259 DeleteObject (((XFontStruct*)(dpyinfo->font_table[i].font))->hfont);
6260 }
6261
6262 x_delete_display (dpyinfo);
6263 UNBLOCK_INPUT;
6264 }
6265
6266 struct w32_display_info *
6267 w32_term_init (display_name, xrm_option, resource_name)
6268 Lisp_Object display_name;
6269 char *xrm_option;
6270 char *resource_name;
6271 {
6272 struct w32_display_info *dpyinfo;
6273 struct terminal *terminal;
6274 HDC hdc;
6275
6276 BLOCK_INPUT;
6277
6278 if (!w32_initialized)
6279 {
6280 w32_initialize ();
6281 w32_initialized = 1;
6282 }
6283
6284 w32_initialize_display_info (display_name);
6285
6286 dpyinfo = &one_w32_display_info;
6287 terminal = w32_create_terminal (dpyinfo);
6288
6289 /* Set the name of the terminal. */
6290 terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
6291 strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
6292 terminal->name[SBYTES (display_name)] = 0;
6293
6294 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
6295
6296 /* Put this display on the chain. */
6297 dpyinfo->next = x_display_list;
6298 x_display_list = dpyinfo;
6299
6300 hdc = GetDC (GetDesktopWindow ());
6301
6302 dpyinfo->height = GetDeviceCaps (hdc, VERTRES);
6303 dpyinfo->width = GetDeviceCaps (hdc, HORZRES);
6304 dpyinfo->root_window = GetDesktopWindow ();
6305 dpyinfo->n_planes = GetDeviceCaps (hdc, PLANES);
6306 dpyinfo->n_cbits = GetDeviceCaps (hdc, BITSPIXEL);
6307 dpyinfo->resx = GetDeviceCaps (hdc, LOGPIXELSX);
6308 dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY);
6309 dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE;
6310 dpyinfo->image_cache = make_image_cache ();
6311 dpyinfo->height_in = dpyinfo->height / dpyinfo->resx;
6312 dpyinfo->width_in = dpyinfo->width / dpyinfo->resy;
6313 ReleaseDC (GetDesktopWindow (), hdc);
6314
6315 /* initialise palette with white and black */
6316 {
6317 XColor color;
6318 w32_defined_color (0, "white", &color, 1);
6319 w32_defined_color (0, "black", &color, 1);
6320 }
6321
6322 /* Create Fringe Bitmaps and store them for later use.
6323
6324 On W32, bitmaps are all unsigned short, as Windows requires
6325 bitmap data to be Word aligned. For some reason they are
6326 horizontally reflected compared to how they appear on X, so we
6327 need to bitswap and convert to unsigned shorts before creating
6328 the bitmaps. */
6329 w32_init_fringe ();
6330
6331 #ifndef F_SETOWN_BUG
6332 #ifdef F_SETOWN
6333 #ifdef F_SETOWN_SOCK_NEG
6334 /* stdin is a socket here */
6335 fcntl (connection, F_SETOWN, -getpid ());
6336 #else /* ! defined (F_SETOWN_SOCK_NEG) */
6337 fcntl (connection, F_SETOWN, getpid ());
6338 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
6339 #endif /* ! defined (F_SETOWN) */
6340 #endif /* F_SETOWN_BUG */
6341
6342 #ifdef SIGIO
6343 if (interrupt_input)
6344 init_sigio (connection);
6345 #endif /* ! defined (SIGIO) */
6346
6347 UNBLOCK_INPUT;
6348
6349 return dpyinfo;
6350 }
6351
6352 /* Get rid of display DPYINFO, assuming all frames are already gone. */
6353 void
6354 x_delete_display (dpyinfo)
6355 struct w32_display_info *dpyinfo;
6356 {
6357 /* Discard this display from w32_display_name_list and w32_display_list.
6358 We can't use Fdelq because that can quit. */
6359 if (! NILP (w32_display_name_list)
6360 && EQ (XCAR (w32_display_name_list), dpyinfo->name_list_element))
6361 w32_display_name_list = XCDR (w32_display_name_list);
6362 else
6363 {
6364 Lisp_Object tail;
6365
6366 tail = w32_display_name_list;
6367 while (CONSP (tail) && CONSP (XCDR (tail)))
6368 {
6369 if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element))
6370 {
6371 XSETCDR (tail, XCDR (XCDR (tail)));
6372 break;
6373 }
6374 tail = XCDR (tail);
6375 }
6376 }
6377
6378 /* free palette table */
6379 {
6380 struct w32_palette_entry * plist;
6381
6382 plist = dpyinfo->color_list;
6383 while (plist)
6384 {
6385 struct w32_palette_entry * pentry = plist;
6386 plist = plist->next;
6387 xfree (pentry);
6388 }
6389 dpyinfo->color_list = NULL;
6390 if (dpyinfo->palette)
6391 DeleteObject(dpyinfo->palette);
6392 }
6393 xfree (dpyinfo->font_table);
6394 xfree (dpyinfo->w32_id_name);
6395
6396 w32_reset_fringes ();
6397 }
6398
6399 /* Set up use of W32. */
6400
6401 DWORD WINAPI w32_msg_worker (void * arg);
6402
6348 void 6403 void
6349 w32_initialize () 6404 w32_initialize ()
6350 { 6405 {
6351 rif = &w32_redisplay_interface;
6352
6353 /* MSVC does not type K&R functions with no arguments correctly, and
6354 so we must explicitly cast them. */
6355 clear_frame_hook = (void (*)(void)) x_clear_frame;
6356 ring_bell_hook = (void (*)(void)) w32_ring_bell;
6357 update_begin_hook = x_update_begin;
6358 update_end_hook = x_update_end;
6359
6360 read_socket_hook = w32_read_socket;
6361
6362 frame_up_to_date_hook = w32_frame_up_to_date;
6363
6364 mouse_position_hook = w32_mouse_position;
6365 frame_rehighlight_hook = w32_frame_rehighlight;
6366 frame_raise_lower_hook = w32_frame_raise_lower;
6367 set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar;
6368 condemn_scroll_bars_hook = w32_condemn_scroll_bars;
6369 redeem_scroll_bar_hook = w32_redeem_scroll_bar;
6370 judge_scroll_bars_hook = w32_judge_scroll_bars;
6371
6372 TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */
6373 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1;
6374 TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */
6375 TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */
6376 TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what
6377 scrolls off the
6378 bottom */
6379 baud_rate = 19200; 6406 baud_rate = 19200;
6380 6407
6381 w32_system_caret_hwnd = NULL; 6408 w32_system_caret_hwnd = NULL;
6382 w32_system_caret_height = 0; 6409 w32_system_caret_height = 0;
6383 w32_system_caret_x = 0; 6410 w32_system_caret_x = 0;