2 /* This file is part of
3 * =================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich.
7 * Copyright 1995-2000 The LyX Team.
9 * This file Copyright 2000 Baruch Even
10 * ================================================= */
13 #pragma implementation
17 #include "XPM_Renderer.h"
18 #include "frontends/support/LyXImage.h"
20 #include FORMS_H_LOCATION
21 #include XPM_H_LOCATION
25 #include "support/LAssert.h"
32 XPM_Renderer::XPM_Renderer()
37 bool XPM_Renderer::renderImage()
44 Display * display = fl_get_display();
47 //#warning This might be a dirty thing, but I dont know any other solution.
48 Screen * screen = ScreenOfDisplay(display, fl_screen);
50 int status = XpmReadFileToPixmap(
52 XRootWindowOfScreen(screen),
53 const_cast<char *>(getFilename().c_str()),
54 &pixmap, &mask, &attrib);
56 if (status != XpmSuccess) {
57 lyxerr << "Error reading XPM file '"
58 << XpmGetErrorString(status)
63 // This should have been set by the XpmReadFileToPixmap call!
64 Assert(attrib.valuemask & XpmSize);
66 setPixmap(new LyXImage(pixmap), attrib.width, attrib.height);
68 XpmFreeAttributes(&attrib);
74 bool XPM_Renderer::isImageFormatOK(string const & filename) const
76 std::ifstream is(filename.c_str(), ios::in);
78 // The signature of the file without the spaces.
79 static const char str[] = "/*XPM*/";
80 const char * ptr = str;
90 } while (*ptr != '\0');