comparison src/frame.c @ 1125:ecb17ab2f7ab

[xemacs-hg @ 2002-11-28 12:30:09 by michaels] 2002-11-25 Mike Sperber <mike@xemacs.org> * frame.c (frame_conversion_internal): Convert pixel_to_char argument to an enum; allow additional option CHAR_TO_DISPLAYABLE_PIXEL. * frame.c (Fset_frame_pixel_height): Make `set-frame-pixel-height' conform to `frame-pixel-height'. (Fset_frame_displayable_pixel_height): New function, equivalent to old `set-frame-pixel-height'. (Fset_frame_width): Make `set-frame-pixel-width conform to `frame-pixel-width'. (Fset_frame_displayable_pixel_width): New function, equivalent to old `set-frame-pixel-width'. (Fset_frame_pixel_size): Make `set-frame-pixel-size conform to `frame-pixel-height' and `frame-pixel-width'. (Fset_frame_displayable_pixel_size): New function, equivalent to old `set-frame-size'.
author michaels
date Thu, 28 Nov 2002 12:30:09 +0000
parents 37bdd24225ef
children 8e95979f01c6
comparison
equal deleted inserted replaced
1124:56d2fe0796c0 1125:ecb17ab2f7ab
116 other way of getting it if it isn't the selected frame. */ 116 other way of getting it if it isn't the selected frame. */
117 Lisp_Object Vframe_being_created; 117 Lisp_Object Vframe_being_created;
118 Lisp_Object Qframe_being_created; 118 Lisp_Object Qframe_being_created;
119 119
120 static void store_minibuf_frame_prop (struct frame *f, Lisp_Object val); 120 static void store_minibuf_frame_prop (struct frame *f, Lisp_Object val);
121 static void frame_conversion_internal (struct frame *f, int pixel_to_char, 121
122 typedef enum {
123 DISPLAYABLE_PIXEL_TO_CHAR,
124 TOTAL_PIXEL_TO_CHAR,
125 CHAR_TO_TOTAL_PIXEL,
126 CHAR_TO_DISPLAYABLE_PIXEL,
127 } pixel_to_char_mode_t;
128
129 static void frame_conversion_internal (struct frame *f,
130 pixel_to_char_mode_t pixel_to_char,
122 int *pixel_width, int *pixel_height, 131 int *pixel_width, int *pixel_height,
123 int *char_width, int *char_height, 132 int *char_width, int *char_height,
124 int real_face); 133 int real_face);
125 static struct display_line title_string_display_line; 134 static struct display_line title_string_display_line;
126 /* Used by generate_title_string. Global because they get used so much that 135 /* Used by generate_title_string. Global because they get used so much that
2649 return result; 2658 return result;
2650 } 2659 }
2651 2660
2652 2661
2653 DEFUN ("frame-pixel-height", Fframe_pixel_height, 0, 1, 0, /* 2662 DEFUN ("frame-pixel-height", Fframe_pixel_height, 0, 1, 0, /*
2654 Return the height in pixels of FRAME. 2663 Return the total height in pixels of FRAME.
2655 */ 2664 */
2656 (frame)) 2665 (frame))
2657 { 2666 {
2658 return make_int (decode_frame (frame)->pixheight); 2667 return make_int (decode_frame (frame)->pixheight);
2659 } 2668 }
2660 2669
2670 DEFUN ("frame-displayable-pixel-height", Fframe_displayable_pixel_height, 0, 1, 0, /*
2671 Return the height of the displayable area in pixels of FRAME.
2672 */
2673 (frame))
2674 {
2675 struct frame *f = decode_frame (frame);
2676 int height, pheight;
2677 frame = wrap_frame (f);
2678
2679 if (!window_system_pixelated_geometry (frame))
2680 {
2681 height = FRAME_HEIGHT (f);
2682
2683 frame_conversion_internal (f, CHAR_TO_DISPLAYABLE_PIXEL,
2684 0, &pheight, 0, &height, 0);
2685 }
2686 else
2687 pheight = FRAME_PIXHEIGHT (f);
2688
2689 return make_int (pheight);
2690 }
2691
2661 DEFUN ("frame-pixel-width", Fframe_pixel_width, 0, 1, 0, /* 2692 DEFUN ("frame-pixel-width", Fframe_pixel_width, 0, 1, 0, /*
2662 Return the width in pixels of FRAME. 2693 Return the total width in pixels of FRAME.
2663 */ 2694 */
2664 (frame)) 2695 (frame))
2665 { 2696 {
2666 return make_int (decode_frame (frame)->pixwidth); 2697 return make_int (decode_frame (frame)->pixwidth);
2698 }
2699
2700 DEFUN ("frame-displayable-pixel-width", Fframe_displayable_pixel_width, 0, 1, 0, /*
2701 Return the width of the displayable area in pixels of FRAME.
2702 */
2703 (frame))
2704 {
2705 struct frame *f = decode_frame (frame);
2706 int width, pwidth;
2707 frame = wrap_frame (f);
2708
2709 if (!window_system_pixelated_geometry (frame))
2710 {
2711 width = FRAME_WIDTH (f);
2712
2713 frame_conversion_internal (f, CHAR_TO_DISPLAYABLE_PIXEL,
2714 &pwidth, 0, &width, 0, 0);
2715 }
2716 else
2717 pwidth = FRAME_PIXWIDTH (f);
2718
2719 return make_int (pwidth);
2667 } 2720 }
2668 2721
2669 DEFUN ("frame-name", Fframe_name, 0, 1, 0, /* 2722 DEFUN ("frame-name", Fframe_name, 0, 1, 0, /*
2670 Return the name of FRAME (defaulting to the selected frame). 2723 Return the name of FRAME (defaulting to the selected frame).
2671 This is not the same as the `title' of the frame. 2724 This is not the same as the `title' of the frame.
2727 internal_set_frame_size (f, width, height, !NILP (pretend)); 2780 internal_set_frame_size (f, width, height, !NILP (pretend));
2728 return frame; 2781 return frame;
2729 } 2782 }
2730 2783
2731 DEFUN ("set-frame-pixel-height", Fset_frame_pixel_height, 2, 3, 0, /* 2784 DEFUN ("set-frame-pixel-height", Fset_frame_pixel_height, 2, 3, 0, /*
2732 Specify that the frame FRAME is HEIGHT pixels tall. 2785 Specify that the frame FRAME is a total of HEIGHT pixels tall.
2733 Optional third arg non-nil means that redisplay should be HEIGHT pixels tall 2786 Optional third arg non-nil means that redisplay should be HEIGHT pixels tall
2734 but that the idea of the actual height of the frame should not be changed. 2787 but that the idea of the actual height of the frame should not be changed.
2735 */ 2788 */
2736 (frame, height, pretend)) 2789 (frame, height, pretend))
2737 { 2790 {
2742 2795
2743 if (!window_system_pixelated_geometry (frame)) 2796 if (!window_system_pixelated_geometry (frame))
2744 { 2797 {
2745 int h = XINT (height); 2798 int h = XINT (height);
2746 width = FRAME_WIDTH (f); 2799 width = FRAME_WIDTH (f);
2747 /* Simply using pixel_to_real_char_size here is not good 2800
2748 enough since we end up with a total frame size of HEIGHT 2801 frame_conversion_internal (f, TOTAL_PIXEL_TO_CHAR, 0, &h, 0, &pheight, 0);
2749 rather than a displayable height of HEIGHT. */
2750 frame_conversion_internal (f, 2, 0, &h, 0, &pheight, 0);
2751 } 2802 }
2752 else 2803 else
2753 { 2804 {
2754 width = FRAME_PIXWIDTH (f); 2805 width = FRAME_PIXWIDTH (f);
2755 pheight = XINT (height); 2806 pheight = XINT (height);
2756 } 2807 }
2757 2808
2758 internal_set_frame_size (f, width, pheight, !NILP (pretend)); 2809 internal_set_frame_size (f, width, pheight, !NILP (pretend));
2759 return frame; 2810 return frame;
2760 } 2811 }
2812
2813 DEFUN ("set-frame-displayable-pixel-height", Fset_frame_displayable_pixel_height, 2, 3, 0, /*
2814 Specify that the displayable area of frame FRAME is HEIGHT pixels tall.
2815 Optional third arg non-nil means that redisplay should be HEIGHT pixels tall
2816 but that the idea of the actual height of the frame should not be changed.
2817 */
2818 (frame, height, pretend))
2819 {
2820 struct frame *f = decode_frame (frame);
2821 int pheight, width;
2822 frame = wrap_frame (f);
2823 CHECK_INT (height);
2824
2825 if (!window_system_pixelated_geometry (frame))
2826 {
2827 int h = XINT (height);
2828 width = FRAME_WIDTH (f);
2829 frame_conversion_internal (f, DISPLAYABLE_PIXEL_TO_CHAR, 0, &h, 0, &pheight, 0);
2830 }
2831 else
2832 {
2833 width = FRAME_PIXWIDTH (f);
2834 pheight = XINT (height);
2835 }
2836
2837 internal_set_frame_size (f, width, pheight, !NILP (pretend));
2838 return frame;
2839 }
2840
2761 2841
2762 DEFUN ("set-frame-width", Fset_frame_width, 2, 3, 0, /* 2842 DEFUN ("set-frame-width", Fset_frame_width, 2, 3, 0, /*
2763 Specify that the frame FRAME has COLS columns. 2843 Specify that the frame FRAME has COLS columns.
2764 Optional third arg non-nil means that redisplay should use COLS columns 2844 Optional third arg non-nil means that redisplay should use COLS columns
2765 but that the idea of the actual width of the frame should not be changed. 2845 but that the idea of the actual width of the frame should not be changed.
2785 internal_set_frame_size (f, width, height, !NILP (pretend)); 2865 internal_set_frame_size (f, width, height, !NILP (pretend));
2786 return frame; 2866 return frame;
2787 } 2867 }
2788 2868
2789 DEFUN ("set-frame-pixel-width", Fset_frame_pixel_width, 2, 3, 0, /* 2869 DEFUN ("set-frame-pixel-width", Fset_frame_pixel_width, 2, 3, 0, /*
2790 Specify that the frame FRAME is WIDTH pixels wide. 2870 Specify that the frame FRAME is a total of WIDTH pixels wide.
2791 Optional third arg non-nil means that redisplay should be WIDTH wide 2871 Optional third arg non-nil means that redisplay should be WIDTH wide
2792 but that the idea of the actual height of the frame should not be changed. 2872 but that the idea of the actual height of the frame should not be changed.
2793 */ 2873 */
2794 (frame, width, pretend)) 2874 (frame, width, pretend))
2795 { 2875 {
2800 2880
2801 if (!window_system_pixelated_geometry (frame)) 2881 if (!window_system_pixelated_geometry (frame))
2802 { 2882 {
2803 int w = XINT (width); 2883 int w = XINT (width);
2804 height = FRAME_HEIGHT (f); 2884 height = FRAME_HEIGHT (f);
2805 /* Simply using pixel_to_real_char_size here is not good 2885 frame_conversion_internal (f, TOTAL_PIXEL_TO_CHAR, &w, 0, &pwidth, 0, 0);
2806 enough since we end up with a total frame size of WIDTH 2886 }
2807 rather than a displayable height of WIDTH. */ 2887 else
2808 frame_conversion_internal (f, 2, &w, 0, &pwidth, 0, 0); 2888 {
2889 height = FRAME_PIXHEIGHT (f);
2890 pwidth = XINT (width);
2891 }
2892
2893 internal_set_frame_size (f, pwidth, height, !NILP (pretend));
2894 return frame;
2895 }
2896
2897 DEFUN ("set-frame-displayable-pixel-width", Fset_frame_displayable_pixel_width, 2, 3, 0, /*
2898 Specify that the displayable area of frame FRAME is WIDTH pixels wide.
2899 Optional third arg non-nil means that redisplay should be WIDTH wide
2900 but that the idea of the actual height of the frame should not be changed.
2901 */
2902 (frame, width, pretend))
2903 {
2904 struct frame *f = decode_frame (frame);
2905 int height, pwidth;
2906 frame = wrap_frame (f);
2907 CHECK_INT (width);
2908
2909 if (!window_system_pixelated_geometry (frame))
2910 {
2911 int w = XINT (width);
2912 height = FRAME_HEIGHT (f);
2913 frame_conversion_internal (f, DISPLAYABLE_PIXEL_TO_CHAR, &w, 0, &pwidth, 0, 0);
2809 } 2914 }
2810 else 2915 else
2811 { 2916 {
2812 height = FRAME_PIXHEIGHT (f); 2917 height = FRAME_PIXHEIGHT (f);
2813 pwidth = XINT (width); 2918 pwidth = XINT (width);
2841 internal_set_frame_size (f, width, height, !NILP (pretend)); 2946 internal_set_frame_size (f, width, height, !NILP (pretend));
2842 return frame; 2947 return frame;
2843 } 2948 }
2844 2949
2845 DEFUN ("set-frame-pixel-size", Fset_frame_pixel_size, 3, 4, 0, /* 2950 DEFUN ("set-frame-pixel-size", Fset_frame_pixel_size, 3, 4, 0, /*
2846 Set the size of FRAME to WIDTH by HEIGHT, measured in pixels. 2951 Set the total size of FRAME to WIDTH by HEIGHT, measured in pixels.
2847 Optional fourth arg non-nil means that redisplay should use WIDTH by HEIGHT 2952 Optional fourth arg non-nil means that redisplay should use WIDTH by HEIGHT
2848 but that the idea of the actual size of the frame should not be changed. 2953 but that the idea of the actual size of the frame should not be changed.
2849 */ 2954 */
2850 (frame, width, height, pretend)) 2955 (frame, width, height, pretend))
2851 { 2956 {
2857 2962
2858 if (!window_system_pixelated_geometry (frame)) 2963 if (!window_system_pixelated_geometry (frame))
2859 { 2964 {
2860 int w = XINT (width); 2965 int w = XINT (width);
2861 int h = XINT (height); 2966 int h = XINT (height);
2862 /* Simply using pixel_to_real_char_size here is not good enough 2967 frame_conversion_internal (f, TOTAL_PIXEL_TO_CHAR, &w, &h, &pwidth, &pheight, 0);
2863 since we end up with a total frame size of WIDTH x HEIGHT 2968 }
2864 rather than a displayable height of WIDTH x HEIGHT. */ 2969 else
2865 frame_conversion_internal (f, 2, &w, &h, &pwidth, &pheight, 0); 2970 {
2971 pheight = XINT (height);
2972 pwidth = XINT (width);
2973 }
2974
2975 internal_set_frame_size (f, pwidth, pheight, !NILP (pretend));
2976 return frame;
2977 }
2978
2979 DEFUN ("set-frame-displayable-pixel-size", Fset_frame_displayable_pixel_size, 3, 4, 0, /*
2980 Set the displayable size of FRAME to WIDTH by HEIGHT, measured in pixels.
2981 Optional fourth arg non-nil means that redisplay should use WIDTH by HEIGHT
2982 but that the idea of the actual size of the frame should not be changed.
2983 */
2984 (frame, width, height, pretend))
2985 {
2986 struct frame *f = decode_frame (frame);
2987 int pheight, pwidth;
2988 frame = wrap_frame (f);
2989 CHECK_INT (width);
2990 CHECK_INT (height);
2991
2992 if (!window_system_pixelated_geometry (frame))
2993 {
2994 int w = XINT (width);
2995 int h = XINT (height);
2996 frame_conversion_internal (f, DISPLAYABLE_PIXEL_TO_CHAR, &w, &h, &pwidth, &pheight, 0);
2866 } 2997 }
2867 else 2998 else
2868 { 2999 {
2869 pheight = XINT (height); 3000 pheight = XINT (height);
2870 pwidth = XINT (width); 3001 pwidth = XINT (width);
2896 /* Frame size conversion functions moved here from EmacsFrame.c 3027 /* Frame size conversion functions moved here from EmacsFrame.c
2897 because they're generic and really don't belong in that file. 3028 because they're generic and really don't belong in that file.
2898 Function get_default_char_pixel_size() removed because it's 3029 Function get_default_char_pixel_size() removed because it's
2899 exactly the same as default_face_height_and_width(). */ 3030 exactly the same as default_face_height_and_width(). */
2900 static void 3031 static void
2901 frame_conversion_internal (struct frame *f, int pixel_to_char, 3032 frame_conversion_internal (struct frame *f,
3033 pixel_to_char_mode_t pixel_to_char,
2902 int *pixel_width, int *pixel_height, 3034 int *pixel_width, int *pixel_height,
2903 int *char_width, int *char_height, 3035 int *char_width, int *char_height,
2904 int real_face) 3036 int real_face)
2905 { 3037 {
2906 int cpw; 3038 int cpw;
2933 /* Convert to chars so that the displayable area is pixel_width x 3065 /* Convert to chars so that the displayable area is pixel_width x
2934 pixel_height. 3066 pixel_height.
2935 3067
2936 #### Consider rounding up to 0.5 characters to avoid adding too 3068 #### Consider rounding up to 0.5 characters to avoid adding too
2937 much space. */ 3069 much space. */
2938 if (pixel_to_char > 1) 3070 switch (pixel_to_char)
2939 { 3071 {
3072 case DISPLAYABLE_PIXEL_TO_CHAR:
2940 if (char_width) 3073 if (char_width)
2941 *char_width = ROUND_UP (*pixel_width, cpw) / cpw; 3074 *char_width = ROUND_UP (*pixel_width, cpw) / cpw;
2942 if (char_height) 3075 if (char_height)
2943 *char_height = ROUND_UP (*pixel_height, cph) / cph; 3076 *char_height = ROUND_UP (*pixel_height, cph) / cph;
2944 } 3077 break;
2945 /* Convert to chars so that the total frame size is pixel_width x 3078 case TOTAL_PIXEL_TO_CHAR:
2946 pixel_height. */ 3079 /* Convert to chars so that the total frame size is pixel_width x
2947 else if (pixel_to_char) 3080 pixel_height. */
2948 {
2949 if (char_width) 3081 if (char_width)
2950 *char_width = 1 + ((*pixel_width - egw) - bdr - obw) / cpw; 3082 *char_width = 1 + ((*pixel_width - egw) - bdr - obw) / cpw;
2951 if (char_height) 3083 if (char_height)
2952 *char_height = (*pixel_height - bdr - obh) / cph; 3084 *char_height = (*pixel_height - bdr - obh) / cph;
2953 } 3085 break;
2954 else 3086 case CHAR_TO_TOTAL_PIXEL:
2955 {
2956 if (pixel_width) 3087 if (pixel_width)
2957 *pixel_width = (*char_width - 1) * cpw + egw + bdr + obw; 3088 *pixel_width = (*char_width - 1) * cpw + egw + bdr + obw;
2958 if (pixel_height) 3089 if (pixel_height)
2959 *pixel_height = *char_height * cph + bdr + obh; 3090 *pixel_height = *char_height * cph + bdr + obh;
3091 break;
3092 case CHAR_TO_DISPLAYABLE_PIXEL:
3093 if (pixel_width)
3094 *pixel_width = *char_width * cpw;
3095 if (pixel_height)
3096 *pixel_height = *char_height * cph;
3097 break;
2960 } 3098 }
2961 } 3099 }
2962 3100
2963 /* This takes the size in pixels of the text area, and returns the number 3101 /* This takes the size in pixels of the text area, and returns the number
2964 of characters that will fit there, taking into account the internal 3102 of characters that will fit there, taking into account the internal
2973 particular. */ 3111 particular. */
2974 void 3112 void
2975 pixel_to_char_size (struct frame *f, int pixel_width, int pixel_height, 3113 pixel_to_char_size (struct frame *f, int pixel_width, int pixel_height,
2976 int *char_width, int *char_height) 3114 int *char_width, int *char_height)
2977 { 3115 {
2978 frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width, 3116 frame_conversion_internal (f, TOTAL_PIXEL_TO_CHAR,
3117 &pixel_width, &pixel_height, char_width,
2979 char_height, 0); 3118 char_height, 0);
2980 } 3119 }
2981 3120
2982 /* Given a character size, this returns the minimum number of pixels 3121 /* Given a character size, this returns the minimum number of pixels
2983 necessary to display that many characters, taking into account the 3122 necessary to display that many characters, taking into account the
2989 particular. */ 3128 particular. */
2990 void 3129 void
2991 char_to_pixel_size (struct frame *f, int char_width, int char_height, 3130 char_to_pixel_size (struct frame *f, int char_width, int char_height,
2992 int *pixel_width, int *pixel_height) 3131 int *pixel_width, int *pixel_height)
2993 { 3132 {
2994 frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width, 3133 frame_conversion_internal (f, CHAR_TO_TOTAL_PIXEL,
3134 pixel_width, pixel_height, &char_width,
2995 &char_height, 0); 3135 &char_height, 0);
2996 } 3136 }
2997 3137
2998 /* Given a pixel size, rounds DOWN to the smallest size in pixels necessary 3138 /* Given a pixel size, rounds DOWN to the smallest size in pixels necessary
2999 to display the same number of characters as are displayable now. 3139 to display the same number of characters as are displayable now.
3012 */ 3152 */
3013 void 3153 void
3014 pixel_to_real_char_size (struct frame *f, int pixel_width, int pixel_height, 3154 pixel_to_real_char_size (struct frame *f, int pixel_width, int pixel_height,
3015 int *char_width, int *char_height) 3155 int *char_width, int *char_height)
3016 { 3156 {
3017 frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width, 3157 frame_conversion_internal (f, TOTAL_PIXEL_TO_CHAR,
3158 &pixel_width, &pixel_height, char_width,
3018 char_height, 1); 3159 char_height, 1);
3019 } 3160 }
3020 3161
3021 void 3162 void
3022 char_to_real_pixel_size (struct frame *f, int char_width, int char_height, 3163 char_to_real_pixel_size (struct frame *f, int char_width, int char_height,
3023 int *pixel_width, int *pixel_height) 3164 int *pixel_width, int *pixel_height)
3024 { 3165 {
3025 frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width, 3166 frame_conversion_internal (f, CHAR_TO_TOTAL_PIXEL,
3167 pixel_width, pixel_height, &char_width,
3026 &char_height, 1); 3168 &char_height, 1);
3027 } 3169 }
3028 3170
3029 void 3171 void
3030 round_size_to_real_char (struct frame *f, int in_width, int in_height, 3172 round_size_to_real_char (struct frame *f, int in_width, int in_height,
3498 DEFSUBR (Fenable_frame); 3640 DEFSUBR (Fenable_frame);
3499 DEFSUBR (Fframe_property); 3641 DEFSUBR (Fframe_property);
3500 DEFSUBR (Fframe_properties); 3642 DEFSUBR (Fframe_properties);
3501 DEFSUBR (Fset_frame_properties); 3643 DEFSUBR (Fset_frame_properties);
3502 DEFSUBR (Fframe_pixel_height); 3644 DEFSUBR (Fframe_pixel_height);
3645 DEFSUBR (Fframe_displayable_pixel_height);
3503 DEFSUBR (Fframe_pixel_width); 3646 DEFSUBR (Fframe_pixel_width);
3647 DEFSUBR (Fframe_displayable_pixel_width);
3504 DEFSUBR (Fframe_name); 3648 DEFSUBR (Fframe_name);
3505 DEFSUBR (Fframe_modified_tick); 3649 DEFSUBR (Fframe_modified_tick);
3506 DEFSUBR (Fset_frame_height); 3650 DEFSUBR (Fset_frame_height);
3507 DEFSUBR (Fset_frame_width); 3651 DEFSUBR (Fset_frame_width);
3508 DEFSUBR (Fset_frame_size); 3652 DEFSUBR (Fset_frame_size);
3509 DEFSUBR (Fset_frame_pixel_height); 3653 DEFSUBR (Fset_frame_pixel_height);
3654 DEFSUBR (Fset_frame_displayable_pixel_height);
3510 DEFSUBR (Fset_frame_pixel_width); 3655 DEFSUBR (Fset_frame_pixel_width);
3656 DEFSUBR (Fset_frame_displayable_pixel_width);
3511 DEFSUBR (Fset_frame_pixel_size); 3657 DEFSUBR (Fset_frame_pixel_size);
3658 DEFSUBR (Fset_frame_displayable_pixel_size);
3512 DEFSUBR (Fset_frame_position); 3659 DEFSUBR (Fset_frame_position);
3513 DEFSUBR (Fset_frame_pointer); 3660 DEFSUBR (Fset_frame_pointer);
3514 DEFSUBR (Fprint_job_page_number); 3661 DEFSUBR (Fprint_job_page_number);
3515 DEFSUBR (Fprint_job_eject_page); 3662 DEFSUBR (Fprint_job_eject_page);
3516 } 3663 }