1 /* $XConsortium: GetPixData.c /main/6 1995/10/25 20:05:46 cde-sun $ */
2 /*
3  * Motif
4  *
5  * Copyright (c) 1987-2012, The Open Group. All rights reserved.
6  *
7  * These libraries and programs are free software; you can
8  * redistribute them and/or modify them under the terms of the GNU
9  * Lesser General Public License as published by the Free Software
10  * Foundation; either version 2 of the License, or (at your option)
11  * any later version.
12  *
13  * These libraries and programs are distributed in the hope that
14  * they will be useful, but WITHOUT ANY WARRANTY; without even the
15  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16  * PURPOSE. See the GNU Lesser General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with these librararies and programs; if not, write
21  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
22  * Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 /*
26  * HISTORY
27  */
28 
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 
33 
34 #include <Xm/XmP.h>
35 #include "ImageCachI.h"
36 #include "XmI.h"
37 
38 /*******************************************************************
39  *
40  * XmeGetPixmapData.
41  *   see if this pixmap is in the cache. If it is then return all the
42  *   gory details about it. If not put it in the cache first.
43  *   The RETURN pointers can be NULL.
44  *   This function never fails (unless pixmap bad id) and always returns
45  *   valid information for depth, with, height, etc .
46  *   It returns True if the pixmap was in the cache to start with
47  *   and True if it had to fetch it to the server first.
48  *
49  *******************************************************************/
50 Boolean
XmeGetPixmapData(Screen * screen,Pixmap pixmap,char ** image_name,int * depth,Pixel * foreground,Pixel * background,int * hot_x,int * hot_y,unsigned int * width,unsigned int * height)51 XmeGetPixmapData(
52     Screen *screen,
53     Pixmap pixmap,
54     char **image_name,
55     int *depth,
56     Pixel *foreground,
57     Pixel *background,
58     int *hot_x,
59     int *hot_y,
60     unsigned int *width,
61     unsigned int *height)
62 {
63     char *loc_image_name;
64     int loc_depth;
65     Pixel loc_foreground;
66     Pixel loc_background;
67     int loc_hot_x;
68     int loc_hot_y;
69     unsigned int loc_width = 0;
70     unsigned int loc_height;
71     XtAppContext app;
72 
73     app = XtDisplayToApplicationContext(DisplayOfScreen(screen));
74 
75     _XmAppLock(app);
76 
77     /* support passed NULL argument */
78     if (!image_name) image_name = &loc_image_name ;
79     if (!depth) depth = &loc_depth ;
80     if (!background) background = &loc_background ;
81     if (!foreground) foreground = &loc_foreground ;
82     if (!hot_x) hot_x = &loc_hot_x ;
83     if (!hot_y) hot_y = &loc_hot_y ;
84     if (!width) width = &loc_width ;
85     if (!height) height = &loc_height ;
86 
87     if (_XmGetPixmapData(screen, pixmap, image_name, depth, foreground,
88 			 background, hot_x, hot_y, width, height)) {
89 	_XmAppUnlock(app);
90 	return True ;
91     }
92 
93 
94     /* not in the cache, generate an incomplete entry in the pixmap cache */
95     /* Use a magic name, which will have _XmCachePixmap not cache this
96        one in the pixmap_data name based cache */
97 
98     if (_XmCachePixmap(pixmap, screen, DIRECT_PIXMAP_CACHED, 1, 0, 0, 0, 0)) {
99 	/* and query again */
100 	_XmGetPixmapData(screen, pixmap, image_name, depth, foreground,
101 			 background, hot_x, hot_y, width, height);
102     }
103 
104     _XmAppUnlock(app);
105 
106     return (False);
107 }
108 
109