blob: 111988a719f22f07b911aef57a915fdc5e63644e [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaare37c6112012-02-05 00:48:00 +01002 *
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
Bram Moolenaar071d4272004-06-13 20:20:40 +000017#include "xpm_w32.h"
18
Bram Moolenaare38eab22019-12-05 21:50:01 +010019// Engage Windows support in libXpm
Bram Moolenaar071d4272004-06-13 20:20:40 +000020#define FOR_MSW
21
22#include "xpm.h"
23
24/*
Bram Moolenaare37c6112012-02-05 00:48:00 +010025 * Tries to load an Xpm image from the file "filename".
26 * Returns -1 on failure.
27 * Returns 0 on success and stores image and mask BITMAPS in "hImage" and
28 * "hShape".
Bram Moolenaar071d4272004-06-13 20:20:40 +000029 */
30 int
Bram Moolenaarb638a7b2016-01-30 21:29:58 +010031LoadXpmImage(
32 char *filename,
33 HBITMAP *hImage,
34 HBITMAP *hShape)
Bram Moolenaar071d4272004-06-13 20:20:40 +000035{
Bram Moolenaare38eab22019-12-05 21:50:01 +010036 XImage *img; // loaded image
37 XImage *shp; // shapeimage
Bram Moolenaar071d4272004-06-13 20:20:40 +000038 XpmAttributes attr;
39 int res;
40 HDC hdc = CreateCompatibleDC(NULL);
41
42 attr.valuemask = 0;
43 res = XpmReadFileToImage(&hdc, filename, &img, &shp, &attr);
44 DeleteDC(hdc);
45 if (res < 0)
46 return -1;
Bram Moolenaare37c6112012-02-05 00:48:00 +010047 if (shp == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000048 {
Bram Moolenaar8d4eecc2012-11-20 17:19:01 +010049 if (img)
Bram Moolenaare37c6112012-02-05 00:48:00 +010050 XDestroyImage(img);
51 return -1;
Bram Moolenaar071d4272004-06-13 20:20:40 +000052 }
Bram Moolenaare37c6112012-02-05 00:48:00 +010053 *hImage = img->bitmap;
54 *hShape = shp->bitmap;
55 return 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000056}