]> git.lyx.org Git - features.git/blob - src/graphics/XPM_Renderer.C
Angus's insetref-patch and a small fix.
[features.git] / src / graphics / XPM_Renderer.C
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  * 
5  *          LyX, The Document Processor
6  *          Copyright 1995 Matthias Ettrich.
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  *          This file Copyright 2000 Baruch Even
10  * ================================================= */
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include <config.h>
17 #include "XPM_Renderer.h"
18
19 #include FORMS_H_LOCATION
20 #include XPM_H_LOCATION
21 #include <iostream>
22 #include <fstream>
23
24 #include "support/LAssert.h"
25 #include "debug.h"
26
27 using std::endl;
28 using std::ios;
29
30 XPM_Renderer::XPM_Renderer()
31         : Renderer()
32 {}
33
34 XPM_Renderer::~XPM_Renderer()
35 {}
36
37 bool XPM_Renderer::renderImage()
38 {
39         Pixmap pixmap;
40         Pixmap mask;
41         XpmAttributes attrib;
42         attrib.valuemask = 0;
43         
44         Display * display = fl_get_display();
45
46 //(BE 2000-08-05)
47 #warning This might be a dirty thing, but I dont know any other solution.
48         Screen * screen = DefaultScreenOfDisplay(display);
49
50         int status = XpmReadFileToPixmap(
51                         display, 
52                         XRootWindowOfScreen(screen), 
53                         const_cast<char *>(getFilename().c_str()), 
54                         &pixmap, &mask, &attrib);
55
56         if (status != XpmSuccess) {
57                 lyxerr << "Error reading XPM file '" 
58                         << XpmGetErrorString(status) 
59                         << endl;
60                 return false;
61         }
62         
63         // This should have been set by the XpmReadFileToPixmap call!
64         Assert(attrib.valuemask & XpmSize);
65
66         setPixmap(pixmap, attrib.width, attrib.height);
67
68         XpmFreeAttributes(&attrib);
69
70         return true;
71 }
72
73 bool XPM_Renderer::isImageFormatOK(string const & filename) const
74 {
75         std::ifstream is(filename.c_str(), ios::in);
76
77         // The signature of the file without the spaces.
78         static const char str[] = "/*XPM*/";
79         const char * ptr = str;
80
81         do {
82                 char c;
83                 is >> c;
84
85                 if (c != *ptr)
86                         return false;
87                 
88                 ++ptr;
89         } while (*ptr != '\0');
90
91         return true;
92 }