comparison src/frame.c @ 5044:e84a30b0e4a2

remove duplicative code in change_frame_size() -------------------- ChangeLog entries follow: -------------------- src/ChangeLog addition: 2010-02-15 Ben Wing <ben@xemacs.org> * frame.c (change_frame_size_1): Simplify the logic in this function. (1) Don't allow 0 as the value of height or width. The old code that tried to allow this was totally broken, anyway, so obviously this never happens any more. (2) Don't duplicate the code in frame_conversion_internal() that converts displayable pixel size to total pixel size -- just call that function.
author Ben Wing <ben@xemacs.org>
date Mon, 15 Feb 2010 22:58:10 -0600
parents d0c14ea98592
children c3cc3fa503a2
comparison
equal deleted inserted replaced
5043:d0c14ea98592 5044:e84a30b0e4a2
3557 /* Change the frame height and/or width. Values may be given as zero to 3557 /* Change the frame height and/or width. Values may be given as zero to
3558 indicate no change is to take place. */ 3558 indicate no change is to take place. */
3559 static void 3559 static void
3560 change_frame_size_1 (struct frame *f, int newwidth, int newheight) 3560 change_frame_size_1 (struct frame *f, int newwidth, int newheight)
3561 { 3561 {
3562 Lisp_Object frame;
3563 int new_pixheight, new_pixwidth; 3562 int new_pixheight, new_pixwidth;
3564 int real_font_height, real_font_width; 3563 int real_font_height, real_font_width;
3565 3564
3566 /* #### Chuck -- shouldn't we be checking to see if the frame 3565 /* #### Chuck -- shouldn't we be checking to see if the frame
3567 is being "changed" to its existing size, and do nothing if so? */ 3566 is being "changed" to its existing size, and do nothing if so? */
3570 `left' coordinates to be recomputed even though no frame size 3569 `left' coordinates to be recomputed even though no frame size
3571 change occurs. --kyle */ 3570 change occurs. --kyle */
3572 if (in_display || hold_frame_size_changes) 3571 if (in_display || hold_frame_size_changes)
3573 ABORT (); 3572 ABORT ();
3574 3573
3575 /* If we don't have valid values, exit. */ 3574 /* We no longer allow bogus values passed in. */
3576 if (!newheight && !newwidth) 3575 assert (newheight && newwidth);
3577 return; 3576
3578 3577 default_face_height_and_width (wrap_frame (f), &real_font_height,
3579 frame = wrap_frame (f); 3578 &real_font_width);
3580 3579
3581 default_face_height_and_width (frame, &real_font_height, &real_font_width); 3580 frame_conversion_internal (f, SIZE_FRAME_UNIT, newwidth, newheight,
3582 if (window_system_pixelated_geometry (frame)) 3581 SIZE_TOTAL_PIXEL, &new_pixwidth,
3583 { 3582 &new_pixheight);
3584 new_pixheight = newheight;
3585 new_pixwidth = newwidth - real_font_width;
3586 }
3587 else
3588 {
3589 new_pixheight = newheight * real_font_height;
3590 new_pixwidth = (newwidth - 1) * real_font_width;
3591 }
3592 3583
3593 /* This size-change overrides any pending one for this frame. */ 3584 /* This size-change overrides any pending one for this frame. */
3594 f->size_change_pending = 0; 3585 f->size_change_pending = 0;
3595 FRAME_NEW_HEIGHT (f) = 0; 3586 FRAME_NEW_HEIGHT (f) = 0;
3596 FRAME_NEW_WIDTH (f) = 0; 3587 FRAME_NEW_WIDTH (f) = 0;
3597
3598
3599 /* #### dependency on FRAME_WIN_P should be removed. */
3600 if (FRAME_WIN_P (f))
3601 {
3602 new_pixheight += FRAME_SCROLLBAR_HEIGHT (f);
3603 new_pixwidth += FRAME_SCROLLBAR_WIDTH (f);
3604 }
3605 3588
3606 /* when frame_conversion_internal() calculated the number of rows/cols 3589 /* when frame_conversion_internal() calculated the number of rows/cols
3607 in the frame, the theoretical toolbar sizes were subtracted out. 3590 in the frame, the theoretical toolbar sizes were subtracted out.
3608 The calculations below adjust for real toolbar height/width in 3591 The calculations below adjust for real toolbar height/width in
3609 frame, which may be different from frame spec, taking the above 3592 frame, which may be different from frame spec, taking the above
3610 fact into account */ 3593 fact into account */
3611 new_pixheight += 3594 new_pixheight +=
3612 + FRAME_THEORETICAL_TOP_TOOLBAR_HEIGHT (f)
3613 + 2 * FRAME_THEORETICAL_TOP_TOOLBAR_BORDER_WIDTH (f)
3614 - FRAME_REAL_TOP_TOOLBAR_HEIGHT (f) 3595 - FRAME_REAL_TOP_TOOLBAR_HEIGHT (f)
3615 - 2 * FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f); 3596 - 2 * FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f);
3616 3597
3617 new_pixheight += 3598 new_pixheight +=
3618 + FRAME_THEORETICAL_BOTTOM_TOOLBAR_HEIGHT (f)
3619 + 2 * FRAME_THEORETICAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f)
3620 - FRAME_REAL_BOTTOM_TOOLBAR_HEIGHT (f) 3599 - FRAME_REAL_BOTTOM_TOOLBAR_HEIGHT (f)
3621 - 2 * FRAME_REAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f); 3600 - 2 * FRAME_REAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f);
3622 3601
3623 new_pixwidth += 3602 new_pixwidth +=
3624 + FRAME_THEORETICAL_LEFT_TOOLBAR_WIDTH (f)
3625 + 2 * FRAME_THEORETICAL_LEFT_TOOLBAR_BORDER_WIDTH (f)
3626 - FRAME_REAL_LEFT_TOOLBAR_WIDTH (f) 3603 - FRAME_REAL_LEFT_TOOLBAR_WIDTH (f)
3627 - 2 * FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f); 3604 - 2 * FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f);
3628 3605
3629 new_pixwidth += 3606 new_pixwidth +=
3630 + FRAME_THEORETICAL_RIGHT_TOOLBAR_WIDTH (f)
3631 + 2 * FRAME_THEORETICAL_RIGHT_TOOLBAR_BORDER_WIDTH (f)
3632 - FRAME_REAL_RIGHT_TOOLBAR_WIDTH (f) 3607 - FRAME_REAL_RIGHT_TOOLBAR_WIDTH (f)
3633 - 2 * FRAME_REAL_RIGHT_TOOLBAR_BORDER_WIDTH (f); 3608 - 2 * FRAME_REAL_RIGHT_TOOLBAR_BORDER_WIDTH (f);
3634 3609
3635 /* Adjust the width for the end glyph which may be a different width 3610 /* Adjust for gutters here so that we always get set
3636 than the default character width. */ 3611 properly. */
3637 { 3612 new_pixheight -=
3638 int adjustment, trunc_width, cont_width; 3613 (FRAME_TOP_GUTTER_BOUNDS (f)
3639 3614 + FRAME_BOTTOM_GUTTER_BOUNDS (f));
3640 trunc_width = glyph_width (Vtruncation_glyph, 3615
3641 FRAME_SELECTED_WINDOW (f)); 3616 /* Adjust for gutters here so that we always get set
3642 cont_width = glyph_width (Vcontinuation_glyph, 3617 properly. */
3643 FRAME_SELECTED_WINDOW (f)); 3618 new_pixwidth -=
3644 adjustment = max (trunc_width, cont_width); 3619 (FRAME_LEFT_GUTTER_BOUNDS (f)
3645 adjustment = max (adjustment, real_font_width); 3620 + FRAME_RIGHT_GUTTER_BOUNDS (f));
3646 3621
3647 new_pixwidth += adjustment; 3622 XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top
3648 } 3623 = FRAME_TOP_BORDER_END (f) + FRAME_TOP_GUTTER_BOUNDS (f);
3649 3624
3650 if (newheight) 3625 if (FRAME_HAS_MINIBUF_P (f)
3651 { 3626 && ! FRAME_MINIBUF_ONLY_P (f))
3652 /* Adjust for gutters here so that we always get set 3627 /* Frame has both root and minibuffer. */
3653 properly. */ 3628 {
3654 new_pixheight -= 3629 /*
3655 (FRAME_TOP_GUTTER_BOUNDS (f) 3630 * Leave the minibuffer height the same if the frame has
3656 + FRAME_BOTTOM_GUTTER_BOUNDS (f)); 3631 * been initialized, and the minibuffer height is tall
3657 3632 * enough to display at least one line of text in the default
3658 XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top 3633 * font, and the old minibuffer height is a multiple of the
3659 = FRAME_TOP_BORDER_END (f) + FRAME_TOP_GUTTER_BOUNDS (f); 3634 * default font height. This should cause the minibuffer
3660 3635 * height to be recomputed on font changes but not for
3661 if (FRAME_HAS_MINIBUF_P (f) 3636 * other frame size changes, which seems reasonable.
3662 && ! FRAME_MINIBUF_ONLY_P (f)) 3637 */
3663 /* Frame has both root and minibuffer. */ 3638 int old_minibuf_height =
3664 { 3639 XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
3665 /* 3640 int minibuf_height =
3666 * Leave the minibuffer height the same if the frame has 3641 f->init_finished && (old_minibuf_height % real_font_height) == 0 ?
3667 * been initialized, and the minibuffer height is tall 3642 max(old_minibuf_height, real_font_height) :
3668 * enough to display at least one line of text in the default 3643 real_font_height;
3669 * font, and the old minibuffer height is a multiple of the 3644 set_window_pixheight (FRAME_ROOT_WINDOW (f),
3670 * default font height. This should cause the minibuffer 3645 /* - font_height for minibuffer */
3671 * height to be recomputed on font changes but not for 3646 new_pixheight - minibuf_height, 0);
3672 * other frame size changes, which seems reasonable. 3647
3673 */ 3648 XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_top =
3674 int old_minibuf_height = 3649 FRAME_TOP_BORDER_END (f) +
3675 XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height; 3650 FRAME_TOP_GUTTER_BOUNDS (f) +
3676 int minibuf_height = 3651 FRAME_BOTTOM_GUTTER_BOUNDS (f) +
3677 f->init_finished && (old_minibuf_height % real_font_height) == 0 ? 3652 new_pixheight - minibuf_height;
3678 max(old_minibuf_height, real_font_height) : 3653
3679 real_font_height; 3654 set_window_pixheight (FRAME_MINIBUF_WINDOW (f), minibuf_height, 0);
3680 set_window_pixheight (FRAME_ROOT_WINDOW (f), 3655 }
3681 /* - font_height for minibuffer */ 3656 else
3682 new_pixheight - minibuf_height, 0); 3657 /* Frame has just one top-level window. */
3683 3658 set_window_pixheight (FRAME_ROOT_WINDOW (f), new_pixheight, 0);
3684 XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_top = 3659
3685 FRAME_TOP_BORDER_END (f) + 3660 FRAME_HEIGHT (f) = newheight;
3686 FRAME_TOP_GUTTER_BOUNDS (f) + 3661 if (FRAME_TTY_P (f))
3687 FRAME_BOTTOM_GUTTER_BOUNDS (f) + 3662 f->pixheight = newheight;
3688 new_pixheight - minibuf_height; 3663
3689 3664 XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left =
3690 set_window_pixheight (FRAME_MINIBUF_WINDOW (f), minibuf_height, 0); 3665 FRAME_LEFT_BORDER_END (f) + FRAME_LEFT_GUTTER_BOUNDS (f);
3691 } 3666 set_window_pixwidth (FRAME_ROOT_WINDOW (f), new_pixwidth, 0);
3692 else 3667
3693 /* Frame has just one top-level window. */ 3668 if (FRAME_HAS_MINIBUF_P (f))
3694 set_window_pixheight (FRAME_ROOT_WINDOW (f), new_pixheight, 0); 3669 {
3695 3670 XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_left =
3696 FRAME_HEIGHT (f) = newheight;
3697 if (FRAME_TTY_P (f))
3698 f->pixheight = newheight;
3699 }
3700
3701 if (newwidth)
3702 {
3703 /* Adjust for gutters here so that we always get set
3704 properly. */
3705 new_pixwidth -=
3706 (FRAME_LEFT_GUTTER_BOUNDS (f)
3707 + FRAME_RIGHT_GUTTER_BOUNDS (f));
3708
3709 XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left =
3710 FRAME_LEFT_BORDER_END (f) + FRAME_LEFT_GUTTER_BOUNDS (f); 3671 FRAME_LEFT_BORDER_END (f) + FRAME_LEFT_GUTTER_BOUNDS (f);
3711 set_window_pixwidth (FRAME_ROOT_WINDOW (f), new_pixwidth, 0); 3672 set_window_pixwidth (FRAME_MINIBUF_WINDOW (f), new_pixwidth, 0);
3712 3673 }
3713 if (FRAME_HAS_MINIBUF_P (f)) 3674
3714 { 3675 FRAME_WIDTH (f) = newwidth;
3715 XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_left = 3676 if (FRAME_TTY_P (f))
3716 FRAME_LEFT_BORDER_END (f) + FRAME_LEFT_GUTTER_BOUNDS (f); 3677 f->pixwidth = newwidth;
3717 set_window_pixwidth (FRAME_MINIBUF_WINDOW (f), new_pixwidth, 0);
3718 }
3719
3720 FRAME_WIDTH (f) = newwidth;
3721 if (FRAME_TTY_P (f))
3722 f->pixwidth = newwidth;
3723 }
3724 3678
3725 get_frame_char_size (f, &FRAME_CHARWIDTH (f), &FRAME_CHARHEIGHT (f)); 3679 get_frame_char_size (f, &FRAME_CHARWIDTH (f), &FRAME_CHARHEIGHT (f));
3726 3680
3727 MARK_FRAME_TOOLBARS_CHANGED (f); 3681 MARK_FRAME_TOOLBARS_CHANGED (f);
3728 MARK_FRAME_GUTTERS_CHANGED (f); 3682 MARK_FRAME_GUTTERS_CHANGED (f);