comparison src/frame.c @ 269:b2472a1930f2 r20-5b33

Import from CVS: tag r20-5b33
author cvs
date Mon, 13 Aug 2007 10:27:19 +0200
parents 966663fcf606
children c5d627a313b1
comparison
equal deleted inserted replaced
268:6ced69ccd85f 269:b2472a1930f2
2295 See `set-frame-properties' for the built-in property names. 2295 See `set-frame-properties' for the built-in property names.
2296 */ 2296 */
2297 (frame, property, default_)) 2297 (frame, property, default_))
2298 { 2298 {
2299 struct frame *f = decode_frame (frame); 2299 struct frame *f = decode_frame (frame);
2300 int width, height;
2300 2301
2301 XSETFRAME (frame, f); 2302 XSETFRAME (frame, f);
2302 2303
2303 property = get_property_alias (property); 2304 property = get_property_alias (property);
2304 2305
2307 if (EQ (property, propprop)) \ 2308 if (EQ (property, propprop)) \
2308 return value; \ 2309 return value; \
2309 } while (0) 2310 } while (0)
2310 2311
2311 FROB (Qname, f->name); 2312 FROB (Qname, f->name);
2312 FROB (Qheight, make_int (FRAME_HEIGHT (f))); 2313
2313 FROB (Qwidth, make_int (FRAME_WIDTH (f))); 2314 if (window_system_pixelated_geometry (frame))
2315 {
2316 pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
2317 &width, &height);
2318 }
2319 else
2320 {
2321 height = FRAME_HEIGHT (f);
2322 width = FRAME_WIDTH (f);
2323 }
2324 FROB (Qheight, make_int (height));
2325 FROB (Qwidth, make_int (width));
2326
2314 /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P. 2327 /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P.
2315 This is over-the-top bogosity, because it's inconsistent with 2328 This is over-the-top bogosity, because it's inconsistent with
2316 the semantics of `minibuffer' when passed to `make-frame'. 2329 the semantics of `minibuffer' when passed to `make-frame'.
2317 Returning Qt makes things consistent. */ 2330 Returning Qt makes things consistent. */
2318 FROB (Qminibuffer, (FRAME_MINIBUF_ONLY_P (f) ? Qonly : 2331 FROB (Qminibuffer, (FRAME_MINIBUF_ONLY_P (f) ? Qonly :
2363 (frame)) 2376 (frame))
2364 { 2377 {
2365 struct frame *f = decode_frame (frame); 2378 struct frame *f = decode_frame (frame);
2366 Lisp_Object result = Qnil; 2379 Lisp_Object result = Qnil;
2367 struct gcpro gcpro1; 2380 struct gcpro gcpro1;
2381 int width, height;
2368 2382
2369 GCPRO1 (result); 2383 GCPRO1 (result);
2384
2385 XSETFRAME (frame, f);
2370 2386
2371 #define FROB(propprop, value) \ 2387 #define FROB(propprop, value) \
2372 do { \ 2388 do { \
2373 Lisp_Object temtem = (value); \ 2389 Lisp_Object temtem = (value); \
2374 if (!NILP (temtem)) \ 2390 if (!NILP (temtem)) \
2375 /* backwards order; we reverse it below */ \ 2391 /* backwards order; we reverse it below */ \
2376 result = Fcons (temtem, Fcons (propprop, result)); \ 2392 result = Fcons (temtem, Fcons (propprop, result)); \
2377 } while (0) 2393 } while (0)
2378 2394
2379 FROB (Qname, f->name); 2395 FROB (Qname, f->name);
2380 FROB (Qheight, make_int (FRAME_HEIGHT (f))); 2396
2381 FROB (Qwidth, make_int (FRAME_WIDTH (f))); 2397 if (window_system_pixelated_geometry (frame))
2398 {
2399 pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
2400 &width, &height);
2401 }
2402 else
2403 {
2404 height = FRAME_HEIGHT (f);
2405 width = FRAME_WIDTH (f);
2406 }
2407 FROB (Qheight, make_int (height));
2408 FROB (Qwidth, make_int (width));
2409
2382 /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P. 2410 /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P.
2383 This is over-the-top bogosity, because it's inconsistent with 2411 This is over-the-top bogosity, because it's inconsistent with
2384 the semantics of `minibuffer' when passed to `make-frame'. 2412 the semantics of `minibuffer' when passed to `make-frame'.
2385 Returning Qt makes things consistent. */ 2413 Returning Qt makes things consistent. */
2386 FROB (Qminibuffer, (FRAME_MINIBUF_ONLY_P (f) ? Qonly : 2414 FROB (Qminibuffer, (FRAME_MINIBUF_ONLY_P (f) ? Qonly :
2465 but that the idea of the actual height of the frame should not be changed. 2493 but that the idea of the actual height of the frame should not be changed.
2466 */ 2494 */
2467 (frame, rows, pretend)) 2495 (frame, rows, pretend))
2468 { 2496 {
2469 struct frame *f = decode_frame (frame); 2497 struct frame *f = decode_frame (frame);
2498 int height, width;
2470 XSETFRAME (frame, f); 2499 XSETFRAME (frame, f);
2471 CHECK_INT (rows); 2500 CHECK_INT (rows);
2472 2501
2473 internal_set_frame_size (f, FRAME_WIDTH (f), XINT (rows), 2502 if (window_system_pixelated_geometry (frame))
2474 !NILP (pretend)); 2503 {
2504 char_to_real_pixel_size (f, 0, XINT (rows), 0, &height);
2505 width = FRAME_PIXWIDTH (f);
2506 }
2507 else
2508 {
2509 height = XINT (rows);
2510 width = FRAME_WIDTH (f);
2511 }
2512
2513 internal_set_frame_size (f, width, height, !NILP (pretend));
2475 return frame; 2514 return frame;
2476 } 2515 }
2477 2516
2478 DEFUN ("set-frame-width", Fset_frame_width, 2, 3, 0, /* 2517 DEFUN ("set-frame-width", Fset_frame_width, 2, 3, 0, /*
2479 Specify that the frame FRAME has COLS columns. 2518 Specify that the frame FRAME has COLS columns.
2481 but that the idea of the actual width of the frame should not be changed. 2520 but that the idea of the actual width of the frame should not be changed.
2482 */ 2521 */
2483 (frame, cols, pretend)) 2522 (frame, cols, pretend))
2484 { 2523 {
2485 struct frame *f = decode_frame (frame); 2524 struct frame *f = decode_frame (frame);
2525 int width, height;
2486 XSETFRAME (frame, f); 2526 XSETFRAME (frame, f);
2487 CHECK_INT (cols); 2527 CHECK_INT (cols);
2488 2528
2489 internal_set_frame_size (f, XINT (cols), FRAME_HEIGHT (f), 2529 if (window_system_pixelated_geometry (frame))
2490 !NILP (pretend)); 2530 {
2531 char_to_real_pixel_size (f, XINT (cols), 0, &width, 0);
2532 height = FRAME_PIXHEIGHT (f);
2533 }
2534 else
2535 {
2536 width = XINT (cols);
2537 height = FRAME_HEIGHT (f);
2538 }
2539
2540 internal_set_frame_size (f, width, height, !NILP (pretend));
2491 return frame; 2541 return frame;
2492 } 2542 }
2493 2543
2494 DEFUN ("set-frame-size", Fset_frame_size, 3, 4, 0, /* 2544 DEFUN ("set-frame-size", Fset_frame_size, 3, 4, 0, /*
2495 Sets size of FRAME to COLS by ROWS. 2545 Sets size of FRAME to COLS by ROWS.
2497 but that the idea of the actual size of the frame should not be changed. 2547 but that the idea of the actual size of the frame should not be changed.
2498 */ 2548 */
2499 (frame, cols, rows, pretend)) 2549 (frame, cols, rows, pretend))
2500 { 2550 {
2501 struct frame *f = decode_frame (frame); 2551 struct frame *f = decode_frame (frame);
2552 int height, width;
2502 XSETFRAME (frame, f); 2553 XSETFRAME (frame, f);
2503 CHECK_INT (cols); 2554 CHECK_INT (cols);
2504 CHECK_INT (rows); 2555 CHECK_INT (rows);
2505 2556
2506 internal_set_frame_size (f, XINT (cols), XINT (rows), !NILP (pretend)); 2557 if (window_system_pixelated_geometry (frame))
2558 char_to_real_pixel_size (f, XINT (cols), XINT (rows), &width, &height);
2559 else
2560 {
2561 height = XINT (rows);
2562 width = XINT (cols);
2563 }
2564
2565 internal_set_frame_size (f, width, height, !NILP (pretend));
2507 return frame; 2566 return frame;
2508 } 2567 }
2509 2568
2510 DEFUN ("set-frame-position", Fset_frame_position, 3, 3, 0, /* 2569 DEFUN ("set-frame-position", Fset_frame_position, 3, 3, 0, /*
2511 Sets position of FRAME in pixels to XOFFSET by YOFFSET. 2570 Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2531 Function get_default_char_pixel_size() removed because it's 2590 Function get_default_char_pixel_size() removed because it's
2532 exactly the same as default_face_height_and_width(). */ 2591 exactly the same as default_face_height_and_width(). */
2533 static void 2592 static void
2534 frame_conversion_internal (struct frame *f, int pixel_to_char, 2593 frame_conversion_internal (struct frame *f, int pixel_to_char,
2535 int *pixel_width, int *pixel_height, 2594 int *pixel_width, int *pixel_height,
2536 int *char_width, int *char_height) 2595 int *char_width, int *char_height,
2596 int real_face)
2537 { 2597 {
2538 int cpw; 2598 int cpw;
2539 int cph; 2599 int cph;
2540 int egw; 2600 int egw;
2541 int obw, obh, bdr; 2601 int obw, obh, bdr;
2542 Lisp_Object frame, window; 2602 Lisp_Object frame, window;
2543 2603
2544 XSETFRAME (frame, f); 2604 XSETFRAME (frame, f);
2545 default_face_height_and_width (frame, &cph, &cpw); 2605 if (real_face)
2606 default_face_height_and_width (frame, &cph, &cpw);
2607 else
2608 default_face_height_and_width_1 (frame, &cph, &cpw);
2609
2546 window = FRAME_SELECTED_WINDOW (f); 2610 window = FRAME_SELECTED_WINDOW (f);
2547 2611
2548 egw = max (glyph_width (Vcontinuation_glyph, Vdefault_face, 0, window), 2612 egw = max (glyph_width (Vcontinuation_glyph, Vdefault_face, 0, window),
2549 glyph_width (Vtruncation_glyph, Vdefault_face, 0, window)); 2613 glyph_width (Vtruncation_glyph, Vdefault_face, 0, window));
2550 egw = max (egw, cpw); 2614 egw = max (egw, cpw);
2558 2 * FRAME_THEORETICAL_TOP_TOOLBAR_BORDER_WIDTH (f) + 2622 2 * FRAME_THEORETICAL_TOP_TOOLBAR_BORDER_WIDTH (f) +
2559 2 * FRAME_THEORETICAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f); 2623 2 * FRAME_THEORETICAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f);
2560 2624
2561 if (pixel_to_char) 2625 if (pixel_to_char)
2562 { 2626 {
2563 *char_width = 1 + ((*pixel_width - egw) - bdr - obw) / cpw; 2627 if (char_width)
2564 *char_height = (*pixel_height - bdr - obh) / cph; 2628 *char_width = 1 + ((*pixel_width - egw) - bdr - obw) / cpw;
2629 if (char_height)
2630 *char_height = (*pixel_height - bdr - obh) / cph;
2565 } 2631 }
2566 else 2632 else
2567 { 2633 {
2568 *pixel_width = (*char_width - 1) * cpw + egw + bdr + obw; 2634 if (pixel_width)
2569 *pixel_height = *char_height * cph + bdr + obh; 2635 *pixel_width = (*char_width - 1) * cpw + egw + bdr + obw;
2636 if (pixel_height)
2637 *pixel_height = *char_height * cph + bdr + obh;
2570 } 2638 }
2571 } 2639 }
2572 2640
2573 /* This takes the size in pixels of the text area, and returns the number 2641 /* This takes the size in pixels of the text area, and returns the number
2574 of characters that will fit there, taking into account the internal 2642 of characters that will fit there, taking into account the internal
2584 void 2652 void
2585 pixel_to_char_size (struct frame *f, int pixel_width, int pixel_height, 2653 pixel_to_char_size (struct frame *f, int pixel_width, int pixel_height,
2586 int *char_width, int *char_height) 2654 int *char_width, int *char_height)
2587 { 2655 {
2588 frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width, 2656 frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width,
2589 char_height); 2657 char_height, 0);
2590 } 2658 }
2591 2659
2592 /* Given a character size, this returns the minimum number of pixels 2660 /* Given a character size, this returns the minimum number of pixels
2593 necessary to display that many characters, taking into account the 2661 necessary to display that many characters, taking into account the
2594 internal border width, scrollbar height and width, toolbar heights and 2662 internal border width, scrollbar height and width, toolbar heights and
2600 void 2668 void
2601 char_to_pixel_size (struct frame *f, int char_width, int char_height, 2669 char_to_pixel_size (struct frame *f, int char_width, int char_height,
2602 int *pixel_width, int *pixel_height) 2670 int *pixel_width, int *pixel_height)
2603 { 2671 {
2604 frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width, 2672 frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width,
2605 &char_height); 2673 &char_height, 0);
2606 } 2674 }
2607 2675
2608 /* Given a pixel size, rounds DOWN to the smallest size in pixels necessary 2676 /* Given a pixel size, rounds DOWN to the smallest size in pixels necessary
2609 to display the same number of characters as are displayable now. 2677 to display the same number of characters as are displayable now.
2610 */ 2678 */
2616 int char_height; 2684 int char_height;
2617 pixel_to_char_size (f, in_width, in_height, &char_width, &char_height); 2685 pixel_to_char_size (f, in_width, in_height, &char_width, &char_height);
2618 char_to_pixel_size (f, char_width, char_height, out_width, out_height); 2686 char_to_pixel_size (f, char_width, char_height, out_width, out_height);
2619 } 2687 }
2620 2688
2689 /* Versions of the above which always account for real font metrics.
2690 */
2691 void
2692 pixel_to_real_char_size (struct frame *f, int pixel_width, int pixel_height,
2693 int *char_width, int *char_height)
2694 {
2695 frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width,
2696 char_height, 1);
2697 }
2698
2699 void
2700 char_to_real_pixel_size (struct frame *f, int char_width, int char_height,
2701 int *pixel_width, int *pixel_height)
2702 {
2703 frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width,
2704 &char_height, 1);
2705 }
2706
2707 void
2708 round_size_to_real_char (struct frame *f, int in_width, int in_height,
2709 int *out_width, int *out_height)
2710 {
2711 int char_width;
2712 int char_height;
2713 pixel_to_real_char_size (f, in_width, in_height, &char_width, &char_height);
2714 char_to_real_pixel_size (f, char_width, char_height, out_width, out_height);
2715 }
2716
2621 /* Change the frame height and/or width. Values may be given as zero to 2717 /* Change the frame height and/or width. Values may be given as zero to
2622 indicate no change is to take place. */ 2718 indicate no change is to take place. */
2623 static void 2719 static void
2624 change_frame_size_1 (struct frame *f, int newheight, int newwidth) 2720 change_frame_size_1 (struct frame *f, int newheight, int newwidth)
2625 { 2721 {
2626 Lisp_Object frame; 2722 Lisp_Object frame;
2627 int new_pixheight, new_pixwidth; 2723 int new_pixheight, new_pixwidth;
2628 int font_height, font_width; 2724 int font_height, real_font_height, font_width;
2629 2725
2630 /* #### Chuck -- shouldn't we be checking to see if the frame 2726 /* #### Chuck -- shouldn't we be checking to see if the frame
2631 is being "changed" to its existing size, and do nothing if so? */ 2727 is being "changed" to its existing size, and do nothing if so? */
2632 /* No, because it would hose toolbar updates. The toolbar 2728 /* No, because it would hose toolbar updates. The toolbar
2633 update code relies on this function to cause window `top' and 2729 update code relies on this function to cause window `top' and
2636 if (in_display) 2732 if (in_display)
2637 abort (); 2733 abort ();
2638 2734
2639 XSETFRAME (frame, f); 2735 XSETFRAME (frame, f);
2640 2736
2641 default_face_height_and_width (frame, &font_height, &font_width); 2737 default_face_height_and_width (frame, &real_font_height, 0);
2738 default_face_height_and_width_1 (frame, &font_height, &font_width);
2642 2739
2643 /* This size-change overrides any pending one for this frame. */ 2740 /* This size-change overrides any pending one for this frame. */
2644 FRAME_NEW_HEIGHT (f) = 0; 2741 FRAME_NEW_HEIGHT (f) = 0;
2645 FRAME_NEW_WIDTH (f) = 0; 2742 FRAME_NEW_WIDTH (f) = 0;
2646 2743
2709 * other frame size changes, which seems reasonable. 2806 * other frame size changes, which seems reasonable.
2710 */ 2807 */
2711 int old_minibuf_height = 2808 int old_minibuf_height =
2712 XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height; 2809 XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
2713 int minibuf_height = 2810 int minibuf_height =
2714 f->init_finished && (old_minibuf_height % font_height) == 0 ? 2811 f->init_finished && (old_minibuf_height % real_font_height) == 0 ?
2715 max(old_minibuf_height, font_height) : 2812 max(old_minibuf_height, real_font_height) :
2716 font_height; 2813 real_font_height;
2717 set_window_pixheight (FRAME_ROOT_WINDOW (f), 2814 set_window_pixheight (FRAME_ROOT_WINDOW (f),
2718 /* - font_height for minibuffer */ 2815 /* - font_height for minibuffer */
2719 new_pixheight - minibuf_height, 0); 2816 new_pixheight - minibuf_height, 0);
2720 2817
2721 XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_top = 2818 XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_top =