1 Index: vcl/source/window/menu.cxx
2 ===================================================================
3 RCS file: /cvs/gsl/vcl/source/window/menu.cxx,v
4 retrieving revision 1.96
5 diff -u -p -u -r1.96 menu.cxx
6 --- vcl/source/window/menu.cxx 12 Jun 2003 07:51:30 -0000 1.96
7 +++ vcl/source/window/menu.cxx 6 Aug 2003 16:44:44 -0000
16 +#include <salbtype.hxx>
17 +#include <bmpacc.hxx>
19 +#include "menu-checkbox-off.xpm"
20 +#include "menu-checkbox-on.xpm"
21 +#include "menu-radio-off.xpm"
22 +#include "menu-radio-on.xpm"
25 +rgb_to_hls (double *r,
63 + l = (max + min) / 2;
69 + s = (max - min) / (max + min);
71 + s = (max - min) / (2 - max - min);
75 + h = (green - blue) / delta;
76 + else if (green == max)
77 + h = 2 + (blue - red) / delta;
78 + else if (blue == max)
79 + h = 4 + (red - green) / delta;
92 +hls_to_rgb (double *h,
105 + if (lightness <= 0.5)
106 + m2 = lightness * (1 + saturation);
108 + m2 = lightness + saturation - lightness * saturation;
109 + m1 = 2 * lightness - m2;
111 + if (saturation == 0) {
123 + r = m1 + (m2 - m1) * hue / 60;
124 + else if (hue < 180)
126 + else if (hue < 240)
127 + r = m1 + (m2 - m1) * (240 - hue) / 60;
138 + g = m1 + (m2 - m1) * hue / 60;
139 + else if (hue < 180)
141 + else if (hue < 240)
142 + g = m1 + (m2 - m1) * (240 - hue) / 60;
153 + b = m1 + (m2 - m1) * hue / 60;
154 + else if (hue < 180)
156 + else if (hue < 240)
157 + b = m1 + (m2 - m1) * (240 - hue) / 60;
167 +/* Does some weird shading from the bg and fg colors and puts the result in (ir, ig, ib) */
169 +shade_rgb (int *ir, int *ig, int *ib, const Color &fg_color, const Color &bg_color, double value)
172 + double f_r, f_g, f_b;
174 + r = bg_color.GetRed () / 255.0;
175 + g = bg_color.GetGreen () / 255.0;
176 + b = bg_color.GetBlue () / 255.0;
178 + f_r = fg_color.GetRed () / 255.0;
179 + f_g = fg_color.GetGreen () / 255.0;
180 + f_b = fg_color.GetBlue () / 255.0;
182 + rgb_to_hls (&r, &g, &b);
183 + rgb_to_hls (&f_r, &f_g, &f_b);
185 + /* now green is the lightness */
187 + g = (g - f_g) * value + f_g;
193 + hls_to_rgb (&r, &g, &b);
195 + *ir = (r * 255.0) + 0.5;
196 + *ig = (g * 255.0) + 0.5;
197 + *ib = (b * 255.0) + 0.5;
200 +/* Takes a grayscale XPM and shades it into a Bitmap */
202 +create_shaded_bitmap (char **xpm, const Color &fg_color, const Color &bg_color)
205 + int width, height, n_colors, color_len;
206 + int palette[256]; /* 0xRRGGBBAA */
208 + BitmapWriteAccess *wa;
215 + if (sscanf (line, "%d%d%d%d", &width, &height, &n_colors, &color_len) != 4)
218 + if (color_len != 1)
221 + /* Read the palette */
223 + for (i = 0; i < 256; i++)
226 + for (i = 0; i < n_colors; i++) {
230 + BOOL is_transparent;
237 + while (*p && isspace (*p))
245 + while (*p && isspace (*p))
249 + is_transparent = TRUE;
253 + is_transparent = FALSE;
256 + color = (color << 4);
258 + if (*p >= '0' && *p <= '9')
260 + else if (*p >= 'A' && *p <= 'Z')
261 + color += *p - 'A' + 10;
269 + color = color << 8;
270 + if (!is_transparent)
271 + color = color | 0xFF;
273 + palette[color_id] = color;
276 + /* Create the bitmap */
278 + bitmap = new Bitmap (Size (width, height), 24);
282 + wa = bitmap->AcquireWriteAccess ();
288 + br = bg_color.GetRed ();
289 + bg = bg_color.GetGreen ();
290 + bb = bg_color.GetBlue ();
292 + for (y = 0; y < height; y++) {
295 + line = xpm[y + n_colors + 1];
297 + for (x = 0; x < width; x++) {
303 + color = palette[line[x]];
304 + gray = ((color & 0xFF00) >> 8) / 254.0; /* who knows why that is the maximum value in the files */
307 + shade_rgb (&r, &g, &b, fg_color, bg_color, gray);
309 + tmp = (r - br) * a;
310 + r = br + ((tmp + (tmp >> 8) + 0x80) >> 8);
312 + tmp = (g - bg) * a;
313 + g = bg + ((tmp + (tmp >> 8) + 0x80) >> 8);
315 + tmp = (b - bb) * a;
316 + b = bb + ((tmp + (tmp >> 8) + 0x80) >> 8);
318 + wa->SetPixel (y, x, BitmapColor (r, g, b));
322 + bitmap->ReleaseAccess (wa);
327 +/* Generates the appropriate image for a check or radio menu item */
329 +create_option_bitmap (BOOL is_radio, BOOL is_active, const Color &fg_color, const Color &bg_color)
331 + static char **xpms[] = {
332 + menu_checkbox_off_xpm,
333 + menu_checkbox_on_xpm,
334 + menu_radio_off_xpm,
340 + xpm = xpms[(is_radio ? 2 : 0) | (is_active ? 1 : 0)];
342 + return create_shaded_bitmap (xpm, fg_color, bg_color);
348 @@ -2093,6 +2435,7 @@ void Menu::ImplPaint( Window* pWin, USHO
353 if ( !bLayout && !bIsMenuBar && pData->bChecked )
356 @@ -2116,6 +2459,37 @@ void Menu::ImplPaint( Window* pWin, USHO
358 aDecoView.DrawSymbol( aRect, eSymbol, pWin->GetTextColor(), nSymbolStyle );
362 + && !pData->pSubMenu
363 + && ( pData->bChecked || (pData->nBits & (MIB_RADIOCHECK | MIB_CHECKABLE | MIB_AUTOCHECK)) ) )
368 + const StyleSettings &settings = pWin->GetSettings().GetStyleSettings();
370 + is_radio = (pData->nBits & MIB_RADIOCHECK) != 0;
371 + is_active = pData->bChecked;
373 + bitmap = create_option_bitmap (is_radio,
375 + settings.GetMenuTextColor (),
376 + pWin->GetFillColor ());
382 + text_yofs = (pData->aSz.Height() - nFontHeight) / 2;
384 + p.X () = aPos.X () + nCheckPos;
385 + p.Y () = aPos.Y () + text_yofs + nFontHeight / 2 - bitmap->GetSizePixel ().Height () / 2;
387 + pWin->DrawBitmap (p, *bitmap);
393 if ( !bLayout && !bIsMenuBar && pData->pSubMenu )