1 /*****************************************************************************
2  ** File          : quit.c                                                  **
3  ** Purpose       : Initialise and Realise quit dialogs                     **
4  ** Author        : Ramon Santiago, Lionel Mallet                           **
5  ** Date          : August 1993                                             **
6  ** Documentation : Xdtm Design Folder                                      **
7  ** Related Files :                                                         **
8  ** Changes       :                                                         **
9  ****************************************************************************/
10 
11 #include <stdio.h>
12 #include "xdtm.h"
13 #include <X11/Xlib.h>
14 #include <X11/Xutil.h>
15 #include <X11/Intrinsic.h>
16 #include <X11/Xmu/Drawing.h>
17 
18 #ifdef XPM
19 #include "xpm.h"
20 #endif
21 
22 #if NeedFunctionPrototypes
23            int  XdtmLocateIconFile(Screen *, char *, Pixmap *, Pixmap *, int *, int *, int *, int *);
24     static void XbmErrorMessage(Display *, char *, int ) ;
25     static void XpmErrorMessage(Display *, char *, char *, int) ;
26 #else
27            int  XdtmLocateIconFile();
28     static void XbmErrorMessage() ;
29     static void XpmErrorMessage() ;
30 #endif
31 
32 /* ****************************************************************************
33  * version that reads pixmap data as well as bitmap data
34  * ****************************************************************************
35  */
36 #if NeedFunctionPrototypes
XdtmLocateIconFile(Screen * screen,char * name,Pixmap * iconPixmap,Pixmap * iconMask,int * widthp,int * heightp,int * xhotp,int * yhotp)37 int XdtmLocateIconFile(Screen *screen,
38 		       char *name,
39 		       Pixmap *iconPixmap,
40 		       Pixmap *iconMask,
41 		       int *widthp,
42 		       int *heightp,
43 		       int *xhotp,
44 		       int *yhotp )
45 #else
46 int XdtmLocateIconFile(screen, name, iconPixmap, iconMask,
47 		       widthp, heightp, xhotp, yhotp )
48      Screen *screen;
49      char *name;
50      Pixmap *iconPixmap, *iconMask; /* RETURN */
51      int *widthp, *heightp, *xhotp, *yhotp;  /* RETURN */
52 #endif
53 {
54     Display *dpy = DisplayOfScreen(screen);
55     Window rootWindowOfScreen = RootWindowOfScreen(screen);
56     unsigned int depthOfScreen = DefaultDepth(dpy, DefaultScreen(dpy));
57     Bool tryToRead = True;
58     unsigned int width = 0;
59     unsigned int height = 0;
60     int xhot;
61     int yhot;
62     Pixmap pixmap = None, mask = None;
63 
64 #ifdef XPM
65     /* Try to read in an X Pixmap */
66 
67     if (tryToRead == TRUE)
68     {
69 	XpmAttributes pixmapAttrs ;
70 	int pixmapReadStatus = XpmSuccess ;
71 
72 	pixmapAttrs.visual       = DefaultVisual(dpy, DefaultScreen(dpy));
73 	pixmapAttrs.colormap     = DefaultColormap(dpy, DefaultScreen(dpy));
74 	pixmapAttrs.depth        = depthOfScreen;
75 	pixmapAttrs.colorsymbols = (XpmColorSymbol *)NULL;
76 	pixmapAttrs.numsymbols   = 0;
77 
78 	pixmapAttrs.valuemask    = XpmVisual | XpmColormap |
79 	  XpmDepth | XpmReturnPixels | XpmReturnInfos;
80 
81 	pixmapReadStatus =
82 	  XpmReadFileToPixmap(
83 			      dpy,
84 			      rootWindowOfScreen,
85 			      name,
86 			      &pixmap,
87 			      &mask,
88 			      &pixmapAttrs ) ;
89 
90 	if (pixmapReadStatus == XpmSuccess)
91 	{
92 	    tryToRead = FALSE;
93 	    width = pixmapAttrs.width;
94 	    height = pixmapAttrs.height;
95 	}
96 #ifdef DEBUG
97 	else
98 	{
99 	    XpmErrorMessage(
100 			    dpy,
101 			    "PseudoColor",
102 			    name, pixmapReadStatus ) ;
103 	}
104 #endif
105     }
106 #endif
107     /* Try to read in an X Bitmap */
108 
109     if (tryToRead == TRUE)
110     {
111 	unsigned int bitmapWidth = 0 ;
112 	unsigned int bitmapHeight = 0 ;
113 	unsigned char *bitmapData = (unsigned char *) NULL;
114 	int bitmapReadStatus = BitmapSuccess ;
115 
116 	bitmapReadStatus =
117 	  XmuReadBitmapDataFromFile(
118 				    name,
119 				    &bitmapWidth,
120 				    &bitmapHeight,
121 				    &bitmapData,
122 				    &xhot,
123 				    &yhot ) ;
124 
125 	if (bitmapReadStatus == BitmapSuccess)
126 	{
127 	    tryToRead = FALSE ;
128 
129 	    pixmap =
130 	      XCreatePixmapFromBitmapData(
131 					  dpy,
132 					  rootWindowOfScreen,
133 					  bitmapData,
134 					  bitmapWidth,
135 					  bitmapHeight,
136 					  BlackPixelOfScreen(screen),
137 					  WhitePixelOfScreen(screen),
138 					  depthOfScreen) ;
139 
140 	}
141 #ifdef DEBUG
142 	else
143 	{
144 	    XbmErrorMessage( dpy, name, bitmapReadStatus ) ;
145 	}
146 #endif
147     }
148 
149     if (pixmap != None)
150     {
151 	*iconPixmap = pixmap;
152 	*iconMask = mask;
153 
154 	if (widthp)
155 	{
156 	    *widthp = (int) width ;
157 	}
158 	if (heightp)
159 	{
160 	    *heightp = (int) height ;
161 	}
162 	if (xhotp)
163 	{
164 	    *xhotp = xhot ;
165 	}
166 	if (yhotp)
167 	{
168 	    *yhotp = yhot ;
169 	}
170 	return 0;
171     }
172 
173     return 1 ;
174 }
175 
176 /* ***************************************************************************
177  *
178  * ****************************************************************************
179  */
180 
181 
182 
183 /* ***************************************************************************
184  *
185  * ****************************************************************************
186  */
187 #if NeedFunctionPrototypes
XbmErrorMessage(Display * dpy,char * fn,int bitmapReadStatus)188 static void XbmErrorMessage(Display *dpy, char *fn, int bitmapReadStatus )
189 #else
190 static void XbmErrorMessage( dpy, fn, bitmapReadStatus )
191      Display *dpy ;
192      char *fn ;
193      int bitmapReadStatus ;
194 #endif
195 {
196     XtAppContext appContext = XtDisplayToApplicationContext( dpy ) ;
197     char warningMsg[256] ;
198 
199     switch( bitmapReadStatus )
200     {
201     case BitmapOpenFailed :
202       (void) sprintf( warningMsg,
203 		     "BitmapOpenFailed \"%s\" could not be opened.", fn ) ;
204       XtAppWarning( appContext, warningMsg ) ;
205       break ;
206 
207   case BitmapFileInvalid :
208     (void) sprintf( warningMsg,
209 		   "BitmapFileInvalid \"%s\" bad bitmap file format.", fn ) ;
210       XtAppWarning( appContext, warningMsg ) ;
211       break ;
212 
213   case BitmapNoMemory :
214     (void) sprintf( warningMsg,
215 		   "BitmapNoMemory \"%s\" insufficient memory.", fn ) ;
216       XtAppWarning( appContext, warningMsg ) ;
217       break ;
218   }
219 }
220 
221 /* ***************************************************************************
222  *
223  * ****************************************************************************
224  */
225 #ifdef XPM
226 #if NeedFunctionPrototypes
XpmErrorMessage(Display * dpy,char * visualName,char * fn,int pixmapReadStatus)227 static void XpmErrorMessage(Display *dpy, char *visualName, char *fn, int pixmapReadStatus )
228 #else
229 static void XpmErrorMessage( dpy, visualName, fn, pixmapReadStatus )
230      Display *dpy ;
231      char *visualName ;
232      char *fn ;
233      int pixmapReadStatus ;
234 #endif
235 {
236     XtAppContext appContext = XtDisplayToApplicationContext( dpy ) ;
237     char warningMsg[256] ;
238 
239     switch( pixmapReadStatus )
240     {
241     case XpmColorError :
242 	(void) sprintf( warningMsg,
243 		       "XpmColorError[%s] \"%s\".", visualName, fn ) ;
244 	XtAppWarning( appContext, warningMsg ) ;
245 	break ;
246 
247     case XpmOpenFailed :
248       (void) sprintf( warningMsg,
249 		     "XpmOpenFailed[%s] \"%s\" could not be opened.",
250 		     visualName, fn ) ;
251 	XtAppWarning( appContext, warningMsg ) ;
252 	break ;
253 
254     case XpmFileInvalid :
255       (void) sprintf( warningMsg,
256 		     "XpmFileInvalid[%s] \"%s\" bad pixmap file format.",
257 		     visualName, fn ) ;
258 	XtAppWarning( appContext, warningMsg ) ;
259 	break ;
260 
261     case XpmNoMemory :
262       (void) sprintf( warningMsg,
263 		     "XpmNoMemory[%s] \"%s\" insufficient memory.",
264 		     visualName, fn ) ;
265 	XtAppWarning( appContext, warningMsg ) ;
266 	break ;
267 
268     case XpmColorFailed :
269       (void) sprintf( warningMsg,
270 		     "XpmColorFailed[%s] \"%s\" not enough colors.",
271 		     visualName, fn ) ;
272 	XtAppWarning( appContext, warningMsg ) ;
273 	break ;
274     }
275 }
276 
277 #endif
278 
279