blob: 2ec32ed9f03aaf9d44168b9c356a703ffc06d6e4 [file] [log] [blame]
Bram Moolenaare37c6112012-02-05 00:48:00 +01001/* vi:set ts=8 sts=4 sw=4:
2 *
Bram Moolenaar071d4272004-06-13 20:20:40 +00003 * Load XPM image.
4 *
5 * This function is placed in separate file because Xpm headers conflict with
6 * Vim ones :(
7 *
8 * Written by Sergey Khorev.
9 * http://iamphet.nm.ru/vim/index.html
10 */
11
12#ifndef WIN32_LEAN_AND_MEAN
13# define WIN32_LEAN_AND_MEAN
14#endif
15#include <windows.h>
16
17/* reduced def from Vim.h */
18#ifndef __ARGS
19# if defined(__STDC__) || defined(__GNUC__) || defined(WIN3264)
20# define __ARGS(x) x
21# else
22# define __ARGS(x) ()
23# endif
24#endif
25
26#include "xpm_w32.h"
27
28/* Engage Windows support in libXpm */
29#define FOR_MSW
30
31#include "xpm.h"
32
33/*
Bram Moolenaare37c6112012-02-05 00:48:00 +010034 * Tries to load an Xpm image from the file "filename".
35 * Returns -1 on failure.
36 * Returns 0 on success and stores image and mask BITMAPS in "hImage" and
37 * "hShape".
Bram Moolenaar071d4272004-06-13 20:20:40 +000038 */
39 int
40LoadXpmImage(filename, hImage, hShape)
41 char *filename;
42 HBITMAP *hImage;
43 HBITMAP *hShape;
44{
Bram Moolenaare37c6112012-02-05 00:48:00 +010045 XImage *img; /* loaded image */
Bram Moolenaar071d4272004-06-13 20:20:40 +000046 XImage *shp; /* shapeimage */
47 XpmAttributes attr;
48 int res;
49 HDC hdc = CreateCompatibleDC(NULL);
50
51 attr.valuemask = 0;
52 res = XpmReadFileToImage(&hdc, filename, &img, &shp, &attr);
53 DeleteDC(hdc);
54 if (res < 0)
55 return -1;
Bram Moolenaare37c6112012-02-05 00:48:00 +010056 if (shp == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000057 {
Bram Moolenaare37c6112012-02-05 00:48:00 +010058 if (img)
59 XDestroyImage(img);
60 return -1;
Bram Moolenaar071d4272004-06-13 20:20:40 +000061 }
Bram Moolenaare37c6112012-02-05 00:48:00 +010062 *hImage = img->bitmap;
63 *hShape = shp->bitmap;
64 return 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000065}