]> git.lyx.org Git - lyx.git/blob - src/graphics/XPM_Renderer.C
Forgot to add this files.
[lyx.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 XPM_Renderer::XPM_Renderer()
28         : Renderer()
29 {}
30
31 XPM_Renderer::~XPM_Renderer()
32 {}
33
34 bool XPM_Renderer::renderImage()
35 {
36         Pixmap pixmap;
37         Pixmap mask;
38         XpmAttributes attrib;
39         attrib.valuemask = 0;
40         
41         Display * display = fl_get_display();
42
43 //(BE 2000-08-05)
44 #warning This might be a dirty thing, but I dont know any other solution.
45         Screen * screen = DefaultScreenOfDisplay(display);
46
47         int status = XpmReadFileToPixmap(
48                         display, 
49                         XRootWindowOfScreen(screen), 
50                         const_cast<char *>(getFilename().c_str()), 
51                         &pixmap, &mask, &attrib);
52
53         if (status != XpmSuccess) {
54                 lyxerr << "Error reading XPM file '" 
55                         << XpmGetErrorString(status) 
56                         << endl;
57                 return false;
58         }
59         
60         // This should have been set by the XpmReadFileToPixmap call!
61         Assert(attrib.valuemask & XpmSize);
62
63         setPixmap(pixmap, attrib.width, attrib.height);
64
65         XpmFreeAttributes(&attrib);
66
67         return true;
68 }
69
70 bool XPM_Renderer::isImageFormatOK(string const & filename) const
71 {
72         std::ifstream is(filename.c_str(), ios::in | ios::nocreate);
73
74         // The signature of the file without the spaces.
75         static const char str[] = "/*XPM*/";
76         const char * ptr = str;
77
78         do {
79                 char c;
80                 is >> c;
81
82                 if (c != *ptr)
83                         return false;
84                 
85                 ++ptr;
86         } while (*ptr != '\0');
87
88         return true;
89 }