1 /* Copyright (C) 2000 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
10 #include <X11/Xutil.h>
13 #include <gnu/gcj/xlib/Visual.h>
14 #include <gnu/gcj/xlib/Screen.h>
15 #include <gnu/gcj/xlib/Display.h>
16 #include <gnu/gcj/xlib/XException.h>
17 #include <gnu/gcj/RawData.h>
19 using namespace gnu::gcj
;
21 void gnu::gcj::xlib::Visual::init(RawData
* visual
, jint depth
)
23 XVisualInfo
* info
= new XVisualInfo
;
24 xVisualInfo
= reinterpret_cast<gnu::gcj::RawData
*>(info
);
29 ::Visual
* visualStructure
= (::Visual
*) visual
;
30 info
->visual
= visualStructure
;
31 info
->visualid
= XVisualIDFromVisual(visualStructure
);
32 infoMask
|= MASK_ID
| MASK_VISUAL_STRUCTURE
;
38 infoMask
|= MASK_DEPTH
;
42 void gnu::gcj::xlib::Visual::finalize()
51 RawData
* gnu::gcj::xlib::Visual::getVisualStructure()
53 ensureXVisualInfo(MASK_ALL
); // Make sure structure is set
54 XVisualInfo
* info
= (XVisualInfo
*) xVisualInfo
;
55 return reinterpret_cast<gnu::gcj::RawData
*>(info
->visual
);
58 jint
gnu::gcj::xlib::Visual::getRedMask()
60 ensureXVisualInfo(MASK_RED
);
61 XVisualInfo
* info
= (XVisualInfo
*) xVisualInfo
;
62 return info
->red_mask
;
65 jint
gnu::gcj::xlib::Visual::getGreenMask()
67 ensureXVisualInfo(MASK_GREEN
);
68 XVisualInfo
* info
= (XVisualInfo
*) xVisualInfo
;
69 return info
->green_mask
;
72 jint
gnu::gcj::xlib::Visual::getBlueMask()
74 ensureXVisualInfo(MASK_BLUE
);
75 XVisualInfo
* info
= (XVisualInfo
*) xVisualInfo
;
76 return info
->blue_mask
;
79 jint
gnu::gcj::xlib::Visual::getScreenNumber()
82 return screen
->getScreenNumber();
84 ensureXVisualInfo(MASK_SCREEN
);
85 XVisualInfo
* info
= (XVisualInfo
*) xVisualInfo
;
89 jint
gnu::gcj::xlib::Visual::getDepth()
91 ensureXVisualInfo(MASK_DEPTH
);
93 XVisualInfo
* info
= (XVisualInfo
*) xVisualInfo
;
97 jint
gnu::gcj::xlib::Visual::getVisualClass()
99 ensureXVisualInfo(MASK_CLASS
);
100 ::XVisualInfo
* info
= (::XVisualInfo
*) xVisualInfo
;
101 return info
->c_class
;
104 void gnu::gcj::xlib::Visual::ensureXVisualInfo(jint requiredMask
)
106 int missingInformation
= ~infoMask
;
107 if ((missingInformation
& requiredMask
) == 0)
110 // We need more info...
112 XVisualInfo
* info
= (XVisualInfo
*) xVisualInfo
;
114 // Store everything we know into template
117 info
->screen
= screen
->getScreenNumber();
118 infoMask
|= MASK_SCREEN
;
121 // Aquire info using the current info as template for matching
122 ::Display
* dpy
= (::Display
*) display
->display
;
125 long mask
= infoMask
& MASK_ALL
& (~MASK_VISUAL_STRUCTURE
);
126 XVisualInfo
* matches
= XGetVisualInfo(dpy
, mask
,
127 info
, &visualInfoCount
);
130 (*info
) = matches
[0];
133 xVisualInfo
= reinterpret_cast<gnu::gcj::RawData
*>(info
);
135 infoMask
= ~0; // ALL
141 "XGetVisualInfo failed to find any matching visuals. The template "
142 "describes a combination of properties that does not exist on "
144 throw new XException(JvNewStringLatin1(msg
));