]> code.delx.au - gnu-emacs/blobdiff - src/w32fns.c
(digest_single_submenu): Declare all args.
[gnu-emacs] / src / w32fns.c
index 6be0521dc24bacc726df92a9eadc70858b9e9ebb..b0f485ce698cd2254f015c5ddb69e26129eaf8c7 100644 (file)
@@ -55,6 +55,9 @@ Boston, MA 02111-1307, USA.  */
 #include <dlgs.h>
 #define FILE_NAME_TEXT_FIELD edt1
 
+void syms_of_w32fns ();
+void globals_of_w32fns ();
+
 extern void free_frame_menubar ();
 extern void x_compute_fringe_widths P_ ((struct frame *, int));
 extern double atof ();
@@ -283,7 +286,12 @@ static unsigned mouse_move_timer = 0;
 
 /* Window that is tracking the mouse.  */
 static HWND track_mouse_window;
-FARPROC track_mouse_event_fn;
+
+typedef BOOL (WINAPI * TrackMouseEvent_Proc) (
+    IN OUT LPTRACKMOUSEEVENT lpEventTrack
+    );
+
+TrackMouseEvent_Proc track_mouse_event_fn=NULL;
 
 /* W95 mousewheel handler */
 unsigned int msh_mousewheel = 0;
@@ -5893,9 +5901,7 @@ w32_load_system_font (f,fontname,size)
            ended up with. */
       return NULL;
 
-    /* Specify anti-aliasing to prevent Cleartype fonts being used,
-       since those fonts leave garbage behind.  */
-    lf.lfQuality = ANTIALIASED_QUALITY;
+    lf.lfQuality = DEFAULT_QUALITY;
 
     font = (XFontStruct *) xmalloc (sizeof (XFontStruct));
     bzero (font, sizeof (*font));
@@ -9158,7 +9164,7 @@ lookup_image (f, spec)
       else
        {
          /* Handle image type independent image attributes
-            `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF',
+            `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF',
             `:background COLOR'.  */
          Lisp_Object ascent, margin, relief, bg;
 
@@ -9972,6 +9978,38 @@ xbm_read_bitmap_data (contents, end, width, height, data)
 #undef expect_ident
 }
 
+static void convert_mono_to_color_image (f, img, foreground, background)
+     struct frame *f;
+     struct image *img;
+     COLORREF foreground, background;
+{
+  HDC hdc, old_img_dc, new_img_dc;
+  HGDIOBJ old_prev, new_prev;
+  HBITMAP new_pixmap;
+
+  hdc = get_frame_dc (f);
+  old_img_dc = CreateCompatibleDC (hdc);
+  new_img_dc = CreateCompatibleDC (hdc);
+  new_pixmap = CreateCompatibleBitmap (hdc, img->width, img->height);
+  release_frame_dc (f, hdc);
+  old_prev = SelectObject (old_img_dc, img->pixmap);
+  new_prev = SelectObject (new_img_dc, new_pixmap);
+  SetTextColor (new_img_dc, foreground);
+  SetBkColor (new_img_dc, background);
+
+  BitBlt (new_img_dc, 0, 0, img->width, img->height, old_img_dc,
+         0, 0, SRCCOPY);
+
+  SelectObject (old_img_dc, old_prev);
+  SelectObject (new_img_dc, new_prev);   
+  DeleteDC (old_img_dc);
+  DeleteDC (new_img_dc);
+  DeleteObject (img->pixmap);
+  if (new_pixmap == 0)
+    fprintf (stderr, "Failed to convert image to color.\n");
+  else
+    img->pixmap = new_pixmap;
+}
 
 /* Load XBM image IMG which will be displayed on frame F from buffer
    CONTENTS.  END is the end of the buffer. Value is non-zero if
@@ -9992,6 +10030,7 @@ xbm_load_image (f, img, contents, end)
     {
       unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);
       unsigned long background = FRAME_BACKGROUND_PIXEL (f);
+      int non_default_colors = 0;
       Lisp_Object value;
 
       xassert (img->width > 0 && img->height > 0);
@@ -9999,17 +10038,25 @@ xbm_load_image (f, img, contents, end)
       /* Get foreground and background colors, maybe allocate colors.  */
       value = image_spec_value (img->spec, QCforeground, NULL);
       if (!NILP (value))
-       foreground = x_alloc_image_color (f, img, value, foreground);
+       {
+         foreground = x_alloc_image_color (f, img, value, foreground);
+         non_default_colors = 1;
+       }
       value = image_spec_value (img->spec, QCbackground, NULL);
       if (!NILP (value))
        {
          background = x_alloc_image_color (f, img, value, background);
          img->background = background;
          img->background_valid = 1;
+         non_default_colors = 1;
        }
       img->pixmap
        = w32_create_pixmap_from_bitmap_data (img->width, img->height, data);
 
+      /* If colors were specified, transfer the bitmap to a color one.  */
+      if (non_default_colors)
+       convert_mono_to_color_image (f, img, foreground, background);
+
       xfree (data);
 
       if (img->pixmap == 0)
@@ -10090,6 +10137,7 @@ xbm_load (f, img)
       Lisp_Object data;
       unsigned long foreground = FRAME_FOREGROUND_PIXEL (f);
       unsigned long background = FRAME_BACKGROUND_PIXEL (f);
+      int non_default_colors = 0;
       char *bits;
       int parsed_p;
       int in_memory_file_p = 0;
@@ -10114,12 +10162,19 @@ xbm_load (f, img)
       /* Get foreground and background colors, maybe allocate colors.  */
       if (fmt[XBM_FOREGROUND].count
          && STRINGP (fmt[XBM_FOREGROUND].value))
-       foreground = x_alloc_image_color (f, img, fmt[XBM_FOREGROUND].value,
-                                         foreground);
+       {
+         foreground = x_alloc_image_color (f, img, fmt[XBM_FOREGROUND].value,
+                                           foreground);
+         non_default_colors = 1;
+       }
+
       if (fmt[XBM_BACKGROUND].count
          && STRINGP (fmt[XBM_BACKGROUND].value))
-       background = x_alloc_image_color (f, img, fmt[XBM_BACKGROUND].value,
-                                         background);
+       {
+         background = x_alloc_image_color (f, img, fmt[XBM_BACKGROUND].value,
+                                           background);
+         non_default_colors = 1;
+       }
 
       if (in_memory_file_p)
        success_p = xbm_load_image (f, img, SDATA (data),
@@ -10153,6 +10208,10 @@ xbm_load (f, img)
            = w32_create_pixmap_from_bitmap_data (img->width, img->height,
                                                  bits);
 
+         /* If colors were specified, transfer the bitmap to a color one.  */
+         if (non_default_colors)
+           convert_mono_to_color_image (f, img, foreground, background);
+
          if (img->pixmap)
            success_p = 1;
          else
@@ -10211,7 +10270,7 @@ static struct image_keyword xpm_format[XPM_LAST] =
   {":type",            IMAGE_SYMBOL_VALUE,                     1},
   {":file",            IMAGE_STRING_VALUE,                     0},
   {":data",            IMAGE_STRING_VALUE,                     0},
-  {":ascent",          IMAGE_NON_NEGATIVE_INTEGER_VALUE,       0},
+  {":ascent",          IMAGE_ASCENT_VALUE,                     0},
   {":margin",          IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,   0},
   {":relief",          IMAGE_INTEGER_VALUE,                    0},
   {":conversion",      IMAGE_DONT_CHECK_VALUE_TYPE,            0},
@@ -10269,9 +10328,7 @@ xpm_image_p (object)
          /* Either no `:color-symbols' or it's a list of conses
             whose car and cdr are strings.  */
          && (fmt[XPM_COLOR_SYMBOLS].count == 0
-             || xpm_valid_color_symbols_p (fmt[XPM_COLOR_SYMBOLS].value))
-         && (fmt[XPM_ASCENT].count == 0
-             || XFASTINT (fmt[XPM_ASCENT].value) < 100));
+             || xpm_valid_color_symbols_p (fmt[XPM_COLOR_SYMBOLS].value)));
 }
 
 
@@ -10722,9 +10779,10 @@ static void XPutPixel (ximg, x, y, color)
     rowbytes += 4 - (rowbytes % 4);
 
   pixel = ximg->data + y * rowbytes + x * 3;
-  *pixel = GetRValue (color);
+  /* Windows bitmaps are in BGR order.  */
+  *pixel = GetBValue (color);
   *(pixel + 1) = GetGValue (color);
-  *(pixel + 2) = GetBValue (color);
+  *(pixel + 2) = GetRValue (color);
 }
 
 
@@ -11034,7 +11092,8 @@ x_build_heuristic_mask (f, img, how)
        {
          char color_name[30];
          sprintf (color_name, "#%04x%04x%04x", rgb[0], rgb[1], rgb[2]);
-         bg = x_alloc_image_color (f, img, build_string (color_name), 0);
+         bg = x_alloc_image_color (f, img, build_string (color_name), 0)
+           & 0x00ffffff; /* Filter out palette info.  */
          use_img_background = 0;
        }
     }
@@ -11108,7 +11167,7 @@ static struct image_keyword pbm_format[PBM_LAST] =
   {":type",            IMAGE_SYMBOL_VALUE,                     1},
   {":file",            IMAGE_STRING_VALUE,                     0},
   {":data",            IMAGE_STRING_VALUE,                     0},
-  {":ascent",          IMAGE_NON_NEGATIVE_INTEGER_VALUE,       0},
+  {":ascent",          IMAGE_ASCENT_VALUE,                     0},
   {":margin",          IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,   0},
   {":relief",          IMAGE_INTEGER_VALUE,                    0},
   {":conversion",      IMAGE_DONT_CHECK_VALUE_TYPE,            0},
@@ -11140,9 +11199,7 @@ pbm_image_p (object)
 
   bcopy (pbm_format, fmt, sizeof fmt);
 
-  if (!parse_image_spec (object, fmt, PBM_LAST, Qpbm)
-      || (fmt[PBM_ASCENT].count
-         && XFASTINT (fmt[PBM_ASCENT].value) > 100))
+  if (!parse_image_spec (object, fmt, PBM_LAST, Qpbm))
     return 0;
 
   /* Must specify either :data or :file.  */
@@ -11488,7 +11545,7 @@ static struct image_keyword png_format[PNG_LAST] =
   {":type",            IMAGE_SYMBOL_VALUE,                     1},
   {":data",            IMAGE_STRING_VALUE,                     0},
   {":file",            IMAGE_STRING_VALUE,                     0},
-  {":ascent",          IMAGE_NON_NEGATIVE_INTEGER_VALUE,       0},
+  {":ascent",          IMAGE_ASCENT_VALUE,                     0},
   {":margin",          IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,   0},
   {":relief",          IMAGE_INTEGER_VALUE,                    0},
   {":conversion",      IMAGE_DONT_CHECK_VALUE_TYPE,            0},
@@ -11518,9 +11575,7 @@ png_image_p (object)
   struct image_keyword fmt[PNG_LAST];
   bcopy (png_format, fmt, sizeof fmt);
 
-  if (!parse_image_spec (object, fmt, PNG_LAST, Qpng)
-      || (fmt[PNG_ASCENT].count
-         && XFASTINT (fmt[PNG_ASCENT].value) > 100))
+  if (!parse_image_spec (object, fmt, PNG_LAST, Qpng))
     return 0;
 
   /* Must specify either the :data or :file keyword.  */
@@ -12008,7 +12063,7 @@ static struct image_keyword jpeg_format[JPEG_LAST] =
   {":type",            IMAGE_SYMBOL_VALUE,                     1},
   {":data",            IMAGE_STRING_VALUE,                     0},
   {":file",            IMAGE_STRING_VALUE,                     0},
-  {":ascent",          IMAGE_NON_NEGATIVE_INTEGER_VALUE,       0},
+  {":ascent",          IMAGE_ASCENT_VALUE,                     0},
   {":margin",          IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,   0},
   {":relief",          IMAGE_INTEGER_VALUE,                    0},
   {":conversions",     IMAGE_DONT_CHECK_VALUE_TYPE,            0},
@@ -12039,9 +12094,7 @@ jpeg_image_p (object)
 
   bcopy (jpeg_format, fmt, sizeof fmt);
 
-  if (!parse_image_spec (object, fmt, JPEG_LAST, Qjpeg)
-      || (fmt[JPEG_ASCENT].count
-         && XFASTINT (fmt[JPEG_ASCENT].value) > 100))
+  if (!parse_image_spec (object, fmt, JPEG_LAST, Qjpeg))
     return 0;
 
   /* Must specify either the :data or :file keyword.  */
@@ -12371,7 +12424,7 @@ static struct image_keyword tiff_format[TIFF_LAST] =
   {":type",            IMAGE_SYMBOL_VALUE,                     1},
   {":data",            IMAGE_STRING_VALUE,                     0},
   {":file",            IMAGE_STRING_VALUE,                     0},
-  {":ascent",          IMAGE_NON_NEGATIVE_INTEGER_VALUE,       0},
+  {":ascent",          IMAGE_ASCENT_VALUE,                     0},
   {":margin",          IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,   0},
   {":relief",          IMAGE_INTEGER_VALUE,                    0},
   {":conversions",     IMAGE_DONT_CHECK_VALUE_TYPE,            0},
@@ -12401,9 +12454,7 @@ tiff_image_p (object)
   struct image_keyword fmt[TIFF_LAST];
   bcopy (tiff_format, fmt, sizeof fmt);
 
-  if (!parse_image_spec (object, fmt, TIFF_LAST, Qtiff)
-      || (fmt[TIFF_ASCENT].count
-         && XFASTINT (fmt[TIFF_ASCENT].value) > 100))
+  if (!parse_image_spec (object, fmt, TIFF_LAST, Qtiff))
     return 0;
 
   /* Must specify either the :data or :file keyword.  */
@@ -12726,7 +12777,7 @@ static struct image_keyword gif_format[GIF_LAST] =
   {":type",            IMAGE_SYMBOL_VALUE,                     1},
   {":data",            IMAGE_STRING_VALUE,                     0},
   {":file",            IMAGE_STRING_VALUE,                     0},
-  {":ascent",          IMAGE_NON_NEGATIVE_INTEGER_VALUE,       0},
+  {":ascent",          IMAGE_ASCENT_VALUE,                     0},
   {":margin",          IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,   0},
   {":relief",          IMAGE_INTEGER_VALUE,                    0},
   {":conversion",      IMAGE_DONT_CHECK_VALUE_TYPE,            0},
@@ -12756,9 +12807,7 @@ gif_image_p (object)
   struct image_keyword fmt[GIF_LAST];
   bcopy (gif_format, fmt, sizeof fmt);
 
-  if (!parse_image_spec (object, fmt, GIF_LAST, Qgif)
-      || (fmt[GIF_ASCENT].count
-         && XFASTINT (fmt[GIF_ASCENT].value) > 100))
+  if (!parse_image_spec (object, fmt, GIF_LAST, Qgif))
     return 0;
 
   /* Must specify either the :data or :file keyword.  */
@@ -13045,7 +13094,7 @@ static struct image_keyword gs_format[GS_LAST] =
   {":file",            IMAGE_STRING_VALUE,                     1},
   {":loader",          IMAGE_FUNCTION_VALUE,                   0},
   {":bounding-box",    IMAGE_DONT_CHECK_VALUE_TYPE,            1},
-  {":ascent",          IMAGE_NON_NEGATIVE_INTEGER_VALUE,       0},
+  {":ascent",          IMAGE_ASCENT_VALUE,                     0},
   {":margin",          IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,   0},
   {":relief",          IMAGE_INTEGER_VALUE,                    0},
   {":conversion",      IMAGE_DONT_CHECK_VALUE_TYPE,            0},
@@ -13092,9 +13141,7 @@ gs_image_p (object)
 
   bcopy (gs_format, fmt, sizeof fmt);
 
-  if (!parse_image_spec (object, fmt, GS_LAST, Qpostscript)
-      || (fmt[GS_ASCENT].count
-         && XFASTINT (fmt[GS_ASCENT].value) > 100))
+  if (!parse_image_spec (object, fmt, GS_LAST, Qpostscript))
     return 0;
 
   /* Bounding box must be a list or vector containing 4 integers.  */
@@ -14838,14 +14885,9 @@ If the underlying system call fails, value is nil.  */)
 void
 syms_of_w32fns ()
 {
-  HMODULE user32_lib = GetModuleHandle ("user32.dll");
-
-  /* This is zero if not using MS-Windows.  */
+       globals_of_w32fns ();
+       /* This is zero if not using MS-Windows.  */
   w32_in_use = 0;
-
-  /* TrackMouseEvent not available in all versions of Windows, so must load
-     it dynamically.  Do it once, here, instead of every time it is used.  */
-  track_mouse_event_fn = GetProcAddress (user32_lib, "TrackMouseEvent");
   track_mouse_window = NULL;
 
   w32_visible_system_caret_hwnd = NULL;
@@ -15093,7 +15135,7 @@ system to handle them.  */);
   init_x_parm_symbols ();
 
   DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path,
-              doc: /* List of directories to search for bitmap files for w32.  */);
+              doc: /* List of directories to search for window system bitmap files.  */);
   Vx_bitmap_file_path = decode_env_path ((char *) 0, "PATH");
 
   DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape,
@@ -15428,7 +15470,26 @@ versions of Windows) characters.  */);
   defsubr (&Sx_file_dialog);
 }
 
+       
+/*
+       globals_of_w32fns is used to initialize those global variables that
+       must always be initialized on startup even when the global variable
+       initialized is non zero (see the function main in emacs.c).
+       globals_of_w32fns is called from syms_of_w32fns when the global
+       variable initialized is 0 and directly from main when initialized
+       is non zero.
+ */
+void globals_of_w32fns ()
+{
+  HMODULE user32_lib = GetModuleHandle ("user32.dll");
+       /*
+               TrackMouseEvent not available in all versions of Windows, so must load
+               it dynamically.  Do it once, here, instead of every time it is used.
+  */
+  track_mouse_event_fn = (TrackMouseEvent_Proc) GetProcAddress (user32_lib, "TrackMouseEvent");
+}
 
+       
 void
 init_xfns ()
 {