]> git.lyx.org Git - lyx.git/blob - src/graphics/XPM_Renderer.C
use the new sstream return non-pods as const, use string instead of char * in a lot...
[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 using std::endl;
28 using std::ios;
29
30
31 XPM_Renderer::XPM_Renderer()
32         : Renderer()
33 {}
34
35
36 bool XPM_Renderer::renderImage()
37 {
38         Pixmap pixmap;
39         Pixmap mask;
40         XpmAttributes attrib;
41         attrib.valuemask = 0;
42         
43         Display * display = fl_get_display();
44
45 //(BE 2000-08-05)
46 #warning This might be a dirty thing, but I dont know any other solution.
47         Screen * screen = DefaultScreenOfDisplay(display);
48
49         int status = XpmReadFileToPixmap(
50                         display, 
51                         XRootWindowOfScreen(screen), 
52                         const_cast<char *>(getFilename().c_str()), 
53                         &pixmap, &mask, &attrib);
54
55         if (status != XpmSuccess) {
56                 lyxerr << "Error reading XPM file '" 
57                         << XpmGetErrorString(status) 
58                         << endl;
59                 return false;
60         }
61         
62         // This should have been set by the XpmReadFileToPixmap call!
63         Assert(attrib.valuemask & XpmSize);
64
65         setPixmap(pixmap, attrib.width, attrib.height);
66
67         XpmFreeAttributes(&attrib);
68
69         return true;
70 }
71
72
73 bool XPM_Renderer::isImageFormatOK(string const & filename) const
74 {
75         std::ifstream is(filename.c_str());
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 }