Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / tas / xal / SetIcon.c
1 /****************************************************************************/
2 /* */
3 /* ALLIANCE CAD FRAMEWORK */
4 /* */
5 /* Tool : libXal Version 1.01 */
6 /* File : SetIcon.c */
7 /* */
8 /* (c) copyright 1993 MASI Laboratory. CAO & VLSI CAD Team */
9 /* All rights reserved. */
10 /* Support : e-mail cao-vlsi@masi.ibp.fr */
11 /* */
12 /* Author(s) : Nizar ABDALLAH Date : 02/02/1993 */
13 /* */
14 /* Modified by : Date : ../../.... */
15 /* Modified by : Date : ../../.... */
16 /* Modified by : Date : ../../.... */
17 /* */
18 /****************************************************************************/
19 /* */
20 /* This function is to be called by all ALLIANCE tools in order to present */
21 /* the same iconic image. */
22 /* */
23 /****************************************************************************/
24
25
26 /*--------------------------------------------------------------------------*/
27 /* INCLUDE FILES */
28 /*--------------------------------------------------------------------------*/
29
30 /*----------------*/
31 /* Motif includes */
32 /*----------------*/
33 #include <Xm/Xm.h>
34 #include <X11/xpm.h>
35
36 /*-----------------------------*/
37 /* Motif for Alliance includes */
38 /*-----------------------------*/
39
40 #include MUT_H
41
42 #include XAL_H
43
44 #include "Icon.h"
45
46 static Pixmap xal_pixmap;
47
48
49 /*---------------------------------------------------------------------------*/
50 /* */
51 /* FUNCTION : XalForceIcon */
52 /* */
53 /* IN ARGS : .shell_w : The shell widget for whom we want to create the icon*/
54 /* */
55 /* OUT ARGS : ( void ) */
56 /* */
57 /* OBJECT : Forces the WM to execute the set icon. */
58 /* */
59 /*---------------------------------------------------------------------------*/
60 void XalForceIcon( shell_w, dpy )
61 Widget shell_w;
62 Display *dpy;
63 {
64 Window window,root;
65 unsigned int x, y, width, height, border_width, depth;
66
67 XtVaGetValues(shell_w, XmNiconWindow, &window, NULL);
68
69 /*---------------------------------------------------------------------------*/
70 /* If there is no window associated with the shell, create one. Make it at */
71 /* least as big as the pixmap we're going to use. The icon window only needs */
72 /* to be a simple window. */
73 /*---------------------------------------------------------------------------*/
74 if (!window)
75 {
76 if (!XGetGeometry(dpy, xal_pixmap, &root, &x, &y, &width, &height, &border_width, &depth) ||
77 !(window = XCreateSimpleWindow(dpy, root, 0, 0, width, height, (unsigned)0,
78 CopyFromParent, CopyFromParent)))
79 {
80 XtVaSetValues(shell_w, XmNiconPixmap, xal_pixmap, NULL);
81 return;
82 }
83 XtVaSetValues(shell_w, XmNiconWindow, window, NULL);
84 }
85 XSetWindowBackgroundPixmap(dpy, window, xal_pixmap);
86 XClearWindow(dpy, window);
87 }
88
89
90 /*---------------------------------------------------------------------------*/
91 /* */
92 /* FUNCTION : XalSetIcon */
93 /* */
94 /* IN ARGS : .shell_w : The shell widget for whom we want to create the icon*/
95 /* */
96 /* OUT ARGS : ( void ) */
97 /* */
98 /* OBJECT : Icon creation function. */
99 /* */
100 /*---------------------------------------------------------------------------*/
101 void XalSetIcon( shell_w )
102 Widget shell_w;
103 {
104 Display *dpy = XtDisplay(shell_w);
105 Screen *screen = XtScreen(shell_w);
106 XpmAttributes XpmAttr;
107 XpmColorSymbol XpmTransparentColor[1] = {{ NULL, "none", 0 }};
108
109 XpmTransparentColor[0].pixel = WhitePixelOfScreen(screen) ;
110 XpmAttr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
111 XpmAttr.colorsymbols = XpmTransparentColor;
112 XpmAttr.numsymbols = 1;
113 XpmAttr.closeness = 65535;
114 XpmAttr.depth = DefaultDepthOfScreen(screen);
115
116 if ((XpmCreatePixmapFromData(dpy, RootWindowOfScreen(screen),
117 Icon, &xal_pixmap, NULL, &XpmAttr)) != XpmSuccess)
118 {
119
120 xal_pixmap = XCreatePixmapFromBitmapData( dpy,
121 RootWindowOfScreen(screen),
122 Icon_bits, Icon_width, Icon_height,
123 BlackPixelOfScreen(screen),
124 WhitePixelOfScreen(screen),
125 DefaultDepthOfScreen(screen));
126
127 }
128
129 if ( xal_pixmap != XmUNSPECIFIED_PIXMAP )
130 XalForceIcon( shell_w, dpy );
131 }
132
133
134 /*---------------------------------------------------------------------------*/
135 /* */
136 /* FUNCTION : XalCustomIcon */
137 /* */
138 /* IN ARGS : .shell_w : The shell widget for whom we want to create the icon*/
139 /* .pix_file : Bitmap filename containing Icon pixmap. */
140 /* */
141 /* OUT ARGS : ( void ) */
142 /* */
143 /* OBJECT : Icon creation function. */
144 /* */
145 /*---------------------------------------------------------------------------*/
146 void XalCustomIcon( shell_w, pix_file )
147 Widget shell_w;
148 int pix_file;
149 {
150 Display *dpy = XtDisplay(shell_w);
151 Screen *screen = XtScreen(shell_w);
152
153 if(XalBitmaps != NULL)
154 {
155 xal_pixmap = XalGetPixmap( shell_w , pix_file, BlackPixelOfScreen(screen),
156 WhitePixelOfScreen(screen));
157 }
158 else
159 {
160 xal_pixmap = XmUNSPECIFIED_PIXMAP ;
161 }
162
163 if ( xal_pixmap != XmUNSPECIFIED_PIXMAP )
164 XalForceIcon( shell_w, dpy );
165 }
166
167
168 /*---------------------------------------------------------------------------*/
169 /* */
170 /* FUNCTION : XalGetPixmap */
171 /* */
172 /* IN ARGS : .shell_w : The shell widget for whom we want to create the icon*/
173 /* .pix_file : Bitmap filename containing Icon pixmap. */
174 /* */
175 /* OUT ARGS : ( void ) */
176 /* */
177 /* OBJECT : Icon creation function. */
178 /* */
179 /*---------------------------------------------------------------------------*/
180 Pixmap XalGetPixmap (widget, imageindex, foreground, background)
181 Widget widget;
182 int imageindex;
183 Pixel foreground;
184 Pixel background;
185 {
186 Pixmap pixmap;
187
188 pixmap = XmGetPixmap( XtScreen(widget), XalBitmaps[imageindex].name,
189 foreground , background);
190
191 if ( pixmap == XmUNSPECIFIED_PIXMAP )
192 {
193 pixmap = XCreatePixmapFromBitmapData( XtDisplay(widget),
194 RootWindowOfScreen(XtScreen(widget)),
195 XalBitmaps[imageindex].bitmap,
196 XalBitmaps[imageindex].width,
197 XalBitmaps[imageindex].height,
198 foreground, background,
199 DefaultDepthOfScreen(XtScreen(widget)));
200 }
201
202 return ( pixmap) ;
203 }