comparison src/w32term.c @ 55026:08e4e7c06ffc

(w32_draw_relief_rect): Add top_p and bot_p args. (x_draw_glyph_string_box): Fix call to x_draw_relief_rect. (x_draw_image_foreground, x_draw_image_relief) (w32_draw_image_foreground_1, x_draw_image_glyph_string): Draw sliced images.
author Kim F. Storm <storm@cua.dk>
date Tue, 20 Apr 2004 22:17:56 +0000
parents 4031909001d5
children b4bf3dd67827 30dd490f06f2
comparison
equal deleted inserted replaced
55025:5cbecea4d4ad 55026:08e4e7c06ffc
1218 static void x_draw_image_foreground P_ ((struct glyph_string *)); 1218 static void x_draw_image_foreground P_ ((struct glyph_string *));
1219 static void w32_draw_image_foreground_1 P_ ((struct glyph_string *, HBITMAP)); 1219 static void w32_draw_image_foreground_1 P_ ((struct glyph_string *, HBITMAP));
1220 static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int, 1220 static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int,
1221 int, int, int)); 1221 int, int, int));
1222 static void w32_draw_relief_rect P_ ((struct frame *, int, int, int, int, 1222 static void w32_draw_relief_rect P_ ((struct frame *, int, int, int, int,
1223 int, int, int, int, RECT *)); 1223 int, int, int, int, int, int,
1224 RECT *));
1224 static void w32_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, 1225 static void w32_draw_box_rect P_ ((struct glyph_string *, int, int, int, int,
1225 int, int, int, RECT *)); 1226 int, int, int, RECT *));
1226 1227
1227 #if GLYPH_DEBUG 1228 #if GLYPH_DEBUG
1228 static void x_check_font P_ ((struct frame *, XFontStruct *)); 1229 static void x_check_font P_ ((struct frame *, XFontStruct *));
1799 side of the rectangle. CLIP_RECT is the clipping rectangle to use 1800 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1800 when drawing. */ 1801 when drawing. */
1801 1802
1802 static void 1803 static void
1803 w32_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, 1804 w32_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
1804 raised_p, left_p, right_p, clip_rect) 1805 raised_p, top_p, bot_p, left_p, right_p, clip_rect)
1805 struct frame *f; 1806 struct frame *f;
1806 int left_x, top_y, right_x, bottom_y, width, left_p, right_p, raised_p; 1807 int left_x, top_y, right_x, bottom_y, width;
1808 int top_p, bot_p, left_p, right_p, raised_p;
1807 RECT *clip_rect; 1809 RECT *clip_rect;
1808 { 1810 {
1809 int i; 1811 int i;
1810 XGCValues gc; 1812 XGCValues gc;
1811 HDC hdc = get_frame_dc (f); 1813 HDC hdc = get_frame_dc (f);
1816 gc.foreground = f->output_data.w32->black_relief.gc->foreground; 1818 gc.foreground = f->output_data.w32->black_relief.gc->foreground;
1817 1819
1818 w32_set_clip_rectangle (hdc, clip_rect); 1820 w32_set_clip_rectangle (hdc, clip_rect);
1819 1821
1820 /* Top. */ 1822 /* Top. */
1821 for (i = 0; i < width; ++i) 1823 if (top_p)
1822 w32_fill_area (f, hdc, gc.foreground, 1824 for (i = 0; i < width; ++i)
1823 left_x + i * left_p, top_y + i, 1825 w32_fill_area (f, hdc, gc.foreground,
1824 right_x - left_x - i * (left_p + right_p ) + 1, 1); 1826 left_x + i * left_p, top_y + i,
1827 right_x - left_x - i * (left_p + right_p ) + 1, 1);
1825 1828
1826 /* Left. */ 1829 /* Left. */
1827 if (left_p) 1830 if (left_p)
1828 for (i = 0; i < width; ++i) 1831 for (i = 0; i < width; ++i)
1829 w32_fill_area (f, hdc, gc.foreground, 1832 w32_fill_area (f, hdc, gc.foreground,
1834 gc.foreground = f->output_data.w32->black_relief.gc->foreground; 1837 gc.foreground = f->output_data.w32->black_relief.gc->foreground;
1835 else 1838 else
1836 gc.foreground = f->output_data.w32->white_relief.gc->foreground; 1839 gc.foreground = f->output_data.w32->white_relief.gc->foreground;
1837 1840
1838 /* Bottom. */ 1841 /* Bottom. */
1839 for (i = 0; i < width; ++i) 1842 if (bot_p)
1840 w32_fill_area (f, hdc, gc.foreground, 1843 for (i = 0; i < width; ++i)
1841 left_x + i * left_p, bottom_y - i, 1844 w32_fill_area (f, hdc, gc.foreground,
1842 right_x - left_x - i * (left_p + right_p) + 1, 1); 1845 left_x + i * left_p, bottom_y - i,
1846 right_x - left_x - i * (left_p + right_p) + 1, 1);
1843 1847
1844 /* Right. */ 1848 /* Right. */
1845 if (right_p) 1849 if (right_p)
1846 for (i = 0; i < width; ++i) 1850 for (i = 0; i < width; ++i)
1847 w32_fill_area (f, hdc, gc.foreground, 1851 w32_fill_area (f, hdc, gc.foreground,
1947 left_p, right_p, &clip_rect); 1951 left_p, right_p, &clip_rect);
1948 else 1952 else
1949 { 1953 {
1950 x_setup_relief_colors (s); 1954 x_setup_relief_colors (s);
1951 w32_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y, 1955 w32_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y,
1952 width, raised_p, left_p, right_p, &clip_rect); 1956 width, raised_p, 1, 1, left_p, right_p, &clip_rect);
1953 } 1957 }
1954 } 1958 }
1955 1959
1956 1960
1957 /* Draw foreground of image glyph string S. */ 1961 /* Draw foreground of image glyph string S. */
1958 1962
1959 static void 1963 static void
1960 x_draw_image_foreground (s) 1964 x_draw_image_foreground (s)
1961 struct glyph_string *s; 1965 struct glyph_string *s;
1962 { 1966 {
1963 int x; 1967 int x = s->x;
1964 int y = s->ybase - image_ascent (s->img, s->face); 1968 int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
1965 1969
1966 /* If first glyph of S has a left box line, start drawing it to the 1970 /* If first glyph of S has a left box line, start drawing it to the
1967 right of that line. */ 1971 right of that line. */
1968 if (s->face->box != FACE_NO_BOX 1972 if (s->face->box != FACE_NO_BOX
1969 && s->first_glyph->left_box_line_p) 1973 && s->first_glyph->left_box_line_p
1970 x = s->x + abs (s->face->box_line_width); 1974 && s->slice.x == 0)
1971 else 1975 x += abs (s->face->box_line_width);
1972 x = s->x;
1973 1976
1974 /* If there is a margin around the image, adjust x- and y-position 1977 /* If there is a margin around the image, adjust x- and y-position
1975 by that margin. */ 1978 by that margin. */
1976 x += s->img->hmargin; 1979 if (s->slice.x == 0)
1977 y += s->img->vmargin; 1980 x += s->img->hmargin;
1981 if (s->slice.y == 0)
1982 y += s->img->vmargin;
1978 1983
1979 SaveDC (s->hdc); 1984 SaveDC (s->hdc);
1980 1985
1981 if (s->img->pixmap) 1986 if (s->img->pixmap)
1982 { 1987 {
1994 HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask); 1999 HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask);
1995 2000
1996 SetTextColor (s->hdc, RGB (255, 255, 255)); 2001 SetTextColor (s->hdc, RGB (255, 255, 255));
1997 SetBkColor (s->hdc, RGB (0, 0, 0)); 2002 SetBkColor (s->hdc, RGB (0, 0, 0));
1998 2003
1999 BitBlt (s->hdc, x, y, s->img->width, s->img->height, 2004 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2000 compat_hdc, 0, 0, SRCINVERT); 2005 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2001 BitBlt (s->hdc, x, y, s->img->width, s->img->height, 2006 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2002 mask_dc, 0, 0, SRCAND); 2007 mask_dc, s->slice.x, s->slice.y, SRCAND);
2003 BitBlt (s->hdc, x, y, s->img->width, s->img->height, 2008 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2004 compat_hdc, 0, 0, SRCINVERT); 2009 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2005 2010
2006 SelectObject (mask_dc, mask_orig_obj); 2011 SelectObject (mask_dc, mask_orig_obj);
2007 DeleteDC (mask_dc); 2012 DeleteDC (mask_dc);
2008 } 2013 }
2009 else 2014 else
2010 { 2015 {
2011 SetTextColor (s->hdc, s->gc->foreground); 2016 SetTextColor (s->hdc, s->gc->foreground);
2012 SetBkColor (s->hdc, s->gc->background); 2017 SetBkColor (s->hdc, s->gc->background);
2013 2018
2014 BitBlt (s->hdc, x, y, s->img->width, s->img->height, 2019 BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
2015 compat_hdc, 0, 0, SRCCOPY); 2020 compat_hdc, s->slice.x, s->slice.y, SRCCOPY);
2016 2021
2017 /* When the image has a mask, we can expect that at 2022 /* When the image has a mask, we can expect that at
2018 least part of a mouse highlight or a block cursor will 2023 least part of a mouse highlight or a block cursor will
2019 be visible. If the image doesn't have a mask, make 2024 be visible. If the image doesn't have a mask, make
2020 a block cursor visible by drawing a rectangle around 2025 a block cursor visible by drawing a rectangle around
2023 if (s->hl == DRAW_CURSOR) 2028 if (s->hl == DRAW_CURSOR)
2024 { 2029 {
2025 int r = s->img->relief; 2030 int r = s->img->relief;
2026 if (r < 0) r = -r; 2031 if (r < 0) r = -r;
2027 w32_draw_rectangle (s->hdc, s->gc, x - r, y - r , 2032 w32_draw_rectangle (s->hdc, s->gc, x - r, y - r ,
2028 s->img->width + r*2 - 1, s->img->height + r*2 - 1); 2033 s->slice.width + r*2 - 1,
2034 s->slice.height + r*2 - 1);
2029 } 2035 }
2030 } 2036 }
2031 2037
2032 w32_set_clip_rectangle (s->hdc, NULL); 2038 w32_set_clip_rectangle (s->hdc, NULL);
2033 SelectObject (s->hdc, orig_brush); 2039 SelectObject (s->hdc, orig_brush);
2034 DeleteObject (fg_brush); 2040 DeleteObject (fg_brush);
2035 SelectObject (compat_hdc, orig_obj); 2041 SelectObject (compat_hdc, orig_obj);
2036 DeleteDC (compat_hdc); 2042 DeleteDC (compat_hdc);
2037 } 2043 }
2038 else 2044 else
2039 w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width -1, 2045 w32_draw_rectangle (s->hdc, s->gc, x, y,
2040 s->img->height - 1); 2046 s->slice.width - 1, s->slice.height - 1);
2041 2047
2042 RestoreDC (s->hdc ,-1); 2048 RestoreDC (s->hdc ,-1);
2043 } 2049 }
2044 2050
2045 2051
2050 x_draw_image_relief (s) 2056 x_draw_image_relief (s)
2051 struct glyph_string *s; 2057 struct glyph_string *s;
2052 { 2058 {
2053 int x0, y0, x1, y1, thick, raised_p; 2059 int x0, y0, x1, y1, thick, raised_p;
2054 RECT r; 2060 RECT r;
2055 int x; 2061 int x = s->x;
2056 int y = s->ybase - image_ascent (s->img, s->face); 2062 int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
2057 2063
2058 /* If first glyph of S has a left box line, start drawing it to the 2064 /* If first glyph of S has a left box line, start drawing it to the
2059 right of that line. */ 2065 right of that line. */
2060 if (s->face->box != FACE_NO_BOX 2066 if (s->face->box != FACE_NO_BOX
2061 && s->first_glyph->left_box_line_p) 2067 && s->first_glyph->left_box_line_p
2062 x = s->x + abs (s->face->box_line_width); 2068 && s->slice.x == 0)
2063 else 2069 x += abs (s->face->box_line_width);
2064 x = s->x;
2065 2070
2066 /* If there is a margin around the image, adjust x- and y-position 2071 /* If there is a margin around the image, adjust x- and y-position
2067 by that margin. */ 2072 by that margin. */
2068 x += s->img->hmargin; 2073 if (s->slice.x == 0)
2069 y += s->img->vmargin; 2074 x += s->img->hmargin;
2075 if (s->slice.y == 0)
2076 y += s->img->vmargin;
2070 2077
2071 if (s->hl == DRAW_IMAGE_SUNKEN 2078 if (s->hl == DRAW_IMAGE_SUNKEN
2072 || s->hl == DRAW_IMAGE_RAISED) 2079 || s->hl == DRAW_IMAGE_RAISED)
2073 { 2080 {
2074 thick = tool_bar_button_relief >= 0 ? tool_bar_button_relief : DEFAULT_TOOL_BAR_BUTTON_RELIEF; 2081 thick = tool_bar_button_relief >= 0 ? tool_bar_button_relief : DEFAULT_TOOL_BAR_BUTTON_RELIEF;
2080 raised_p = s->img->relief > 0; 2087 raised_p = s->img->relief > 0;
2081 } 2088 }
2082 2089
2083 x0 = x - thick; 2090 x0 = x - thick;
2084 y0 = y - thick; 2091 y0 = y - thick;
2085 x1 = x + s->img->width + thick - 1; 2092 x1 = x + s->slice.width + thick - 1;
2086 y1 = y + s->img->height + thick - 1; 2093 y1 = y + s->slice.height + thick - 1;
2087 2094
2088 x_setup_relief_colors (s); 2095 x_setup_relief_colors (s);
2089 get_glyph_string_clip_rect (s, &r); 2096 get_glyph_string_clip_rect (s, &r);
2090 w32_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p, 1, 1, &r); 2097 w32_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p,
2098 s->slice.y == 0,
2099 s->slice.y + s->slice.height == s->img->height,
2100 s->slice.x == 0,
2101 s->slice.x + s->slice.width == s->img->width,
2102 &r);
2091 } 2103 }
2092 2104
2093 2105
2094 /* Draw the foreground of image glyph string S to PIXMAP. */ 2106 /* Draw the foreground of image glyph string S to PIXMAP. */
2095 2107
2098 struct glyph_string *s; 2110 struct glyph_string *s;
2099 HBITMAP pixmap; 2111 HBITMAP pixmap;
2100 { 2112 {
2101 HDC hdc = CreateCompatibleDC (s->hdc); 2113 HDC hdc = CreateCompatibleDC (s->hdc);
2102 HGDIOBJ orig_hdc_obj = SelectObject (hdc, pixmap); 2114 HGDIOBJ orig_hdc_obj = SelectObject (hdc, pixmap);
2103 int x; 2115 int x = 0;
2104 int y = s->ybase - s->y - image_ascent (s->img, s->face); 2116 int y = s->ybase - s->y - image_ascent (s->img, s->face, &s->slice);
2105 2117
2106 /* If first glyph of S has a left box line, start drawing it to the 2118 /* If first glyph of S has a left box line, start drawing it to the
2107 right of that line. */ 2119 right of that line. */
2108 if (s->face->box != FACE_NO_BOX 2120 if (s->face->box != FACE_NO_BOX
2109 && s->first_glyph->left_box_line_p) 2121 && s->first_glyph->left_box_line_p
2110 x = abs (s->face->box_line_width); 2122 && s->slice.x == 0)
2111 else 2123 x += abs (s->face->box_line_width);
2112 x = 0;
2113 2124
2114 /* If there is a margin around the image, adjust x- and y-position 2125 /* If there is a margin around the image, adjust x- and y-position
2115 by that margin. */ 2126 by that margin. */
2116 x += s->img->hmargin; 2127 if (s->slice.x == 0)
2117 y += s->img->vmargin; 2128 x += s->img->hmargin;
2129 if (s->slice.y == 0)
2130 y += s->img->vmargin;
2118 2131
2119 if (s->img->pixmap) 2132 if (s->img->pixmap)
2120 { 2133 {
2121 HDC compat_hdc = CreateCompatibleDC (hdc); 2134 HDC compat_hdc = CreateCompatibleDC (hdc);
2122 HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); 2135 HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
2128 HDC mask_dc = CreateCompatibleDC (hdc); 2141 HDC mask_dc = CreateCompatibleDC (hdc);
2129 HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask); 2142 HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask);
2130 2143
2131 SetTextColor (hdc, RGB (0, 0, 0)); 2144 SetTextColor (hdc, RGB (0, 0, 0));
2132 SetBkColor (hdc, RGB (255, 255, 255)); 2145 SetBkColor (hdc, RGB (255, 255, 255));
2133 BitBlt (hdc, x, y, s->img->width, s->img->height, 2146 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2134 compat_hdc, 0, 0, SRCINVERT); 2147 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2135 BitBlt (hdc, x, y, s->img->width, s->img->height, 2148 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2136 mask_dc, 0, 0, SRCAND); 2149 mask_dc, s->slice.x, s->slice.y, SRCAND);
2137 BitBlt (hdc, x, y, s->img->width, s->img->height, 2150 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2138 compat_hdc, 0, 0, SRCINVERT); 2151 compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
2139 2152
2140 SelectObject (mask_dc, mask_orig_obj); 2153 SelectObject (mask_dc, mask_orig_obj);
2141 DeleteDC (mask_dc); 2154 DeleteDC (mask_dc);
2142 } 2155 }
2143 else 2156 else
2144 { 2157 {
2145 SetTextColor (hdc, s->gc->foreground); 2158 SetTextColor (hdc, s->gc->foreground);
2146 SetBkColor (hdc, s->gc->background); 2159 SetBkColor (hdc, s->gc->background);
2147 2160
2148 BitBlt (hdc, x, y, s->img->width, s->img->height, 2161 BitBlt (hdc, x, y, s->slice.width, s->slice.height,
2149 compat_hdc, 0, 0, SRCCOPY); 2162 compat_hdc, s->slice.x, s->slice.y, SRCCOPY);
2150 2163
2151 /* When the image has a mask, we can expect that at 2164 /* When the image has a mask, we can expect that at
2152 least part of a mouse highlight or a block cursor will 2165 least part of a mouse highlight or a block cursor will
2153 be visible. If the image doesn't have a mask, make 2166 be visible. If the image doesn't have a mask, make
2154 a block cursor visible by drawing a rectangle around 2167 a block cursor visible by drawing a rectangle around
2156 nothing here for mouse-face. */ 2169 nothing here for mouse-face. */
2157 if (s->hl == DRAW_CURSOR) 2170 if (s->hl == DRAW_CURSOR)
2158 { 2171 {
2159 int r = s->img->relief; 2172 int r = s->img->relief;
2160 if (r < 0) r = -r; 2173 if (r < 0) r = -r;
2161 w32_draw_rectangle (hdc, s->gc, x - r, y - r , 2174 w32_draw_rectangle (hdc, s->gc, x - r, y - r,
2162 s->img->width + r*2 - 1, s->img->height + r*2 - 1); 2175 s->slice.width + r*2 - 1,
2176 s->slice.height + r*2 - 1);
2163 } 2177 }
2164 } 2178 }
2165 2179
2166 SelectObject (hdc, orig_brush); 2180 SelectObject (hdc, orig_brush);
2167 DeleteObject (fg_brush); 2181 DeleteObject (fg_brush);
2168 SelectObject (compat_hdc, orig_obj); 2182 SelectObject (compat_hdc, orig_obj);
2169 DeleteDC (compat_hdc); 2183 DeleteDC (compat_hdc);
2170 } 2184 }
2171 else 2185 else
2172 w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1, 2186 w32_draw_rectangle (hdc, s->gc, x, y,
2173 s->img->height - 1); 2187 s->slice.width - 1, s->slice.height - 1);
2174 2188
2175 SelectObject (hdc, orig_hdc_obj); 2189 SelectObject (hdc, orig_hdc_obj);
2176 DeleteDC (hdc); 2190 DeleteDC (hdc);
2177 } 2191 }
2178 2192
2227 2241
2228 /* Fill background with face under the image. Do it only if row is 2242 /* Fill background with face under the image. Do it only if row is
2229 taller than image or if image has a clip mask to reduce 2243 taller than image or if image has a clip mask to reduce
2230 flickering. */ 2244 flickering. */
2231 s->stippled_p = s->face->stipple != 0; 2245 s->stippled_p = s->face->stipple != 0;
2232 if (height > s->img->height 2246 if (height > s->slice.height
2233 || s->img->hmargin 2247 || s->img->hmargin
2234 || s->img->vmargin 2248 || s->img->vmargin
2235 || s->img->mask 2249 || s->img->mask
2236 || s->img->pixmap == 0 2250 || s->img->pixmap == 0
2237 || s->width != s->background_width) 2251 || s->width != s->background_width)
2238 { 2252 {
2239 if (box_line_hwidth && s->first_glyph->left_box_line_p) 2253 x = s->x;
2240 x = s->x + box_line_hwidth; 2254 if (s->first_glyph->left_box_line_p
2241 else 2255 && s->slice.x == 0)
2242 x = s->x; 2256 x += box_line_hwidth;
2243 2257
2244 y = s->y + box_line_vwidth; 2258 y = s->y;
2259 if (s->slice.y == 0)
2260 y += box_line_vwidth;
2261
2245 #if 0 /* TODO: figure out if we need to do this on Windows. */ 2262 #if 0 /* TODO: figure out if we need to do this on Windows. */
2246 if (s->img->mask) 2263 if (s->img->mask)
2247 { 2264 {
2248 /* Create a pixmap as large as the glyph string. Fill it 2265 /* Create a pixmap as large as the glyph string. Fill it
2249 with the background color. Copy the image to it, using 2266 with the background color. Copy the image to it, using