1 /*---------------------------------------------------------------------------- 2 -- 3 -- Module: xitIconWin 4 -- 5 -- Project: Xtools 6 -- System: <> 7 -- Subsystem: <> 8 -- Function block: <> 9 -- 10 -- Description: 11 -- Put a pixmap in an icon window. Iconify a toplevel window. 12 -- 13 -- Filename: xitIconWin.c 14 -- 15 -- Authors: Roger Larsson, Ulrika Bornetun 16 -- Creation date: 1991-12-11 17 -- 18 -- 19 -- (C) Copyright Ulrika Bornetun, Roger Larsson (1995) 20 -- All rights reserved 21 -- 22 -- Permission to use, copy, modify, and distribute this software and its 23 -- documentation for any purpose and without fee is hereby granted, 24 -- provided that the above copyright notice appear in all copies. Ulrika 25 -- Bornetun and Roger Larsson make no representations about the usability 26 -- of this software for any purpose. It is provided "as is" without express 27 -- or implied warranty. 28 ----------------------------------------------------------------------------*/ 29 30 /* SCCS module identifier. */ 31 static char SCCSID[] = "@(#) Module: xitIconWin.c, Version: 1.1, Date: 95/02/18 15:10:34"; 32 33 34 /*---------------------------------------------------------------------------- 35 -- Include files 36 ----------------------------------------------------------------------------*/ 37 38 #include <X11/Intrinsic.h> 39 #include <X11/Shell.h> 40 41 #include <Xm/Xm.h> 42 43 #include "Standard.h" 44 45 #include "xitTools.h" 46 47 48 /*---------------------------------------------------------------------------- 49 -- Macro definitions 50 ----------------------------------------------------------------------------*/ 51 52 53 /*---------------------------------------------------------------------------- 54 -- Type declarations 55 ----------------------------------------------------------------------------*/ 56 57 58 /*---------------------------------------------------------------------------- 59 -- Global definitions 60 ----------------------------------------------------------------------------*/ 61 62 63 /*---------------------------------------------------------------------------- 64 -- Function prototypes 65 ----------------------------------------------------------------------------*/ 66 67 68 69 /*---------------------------------------------------------------------------- 70 -- Functions 71 ----------------------------------------------------------------------------*/ 72 73 void xitIconify(Widget widget)74 xitIconify( Widget widget ) 75 { 76 77 /* Variables. */ 78 Atom xa_WM_CHANGE_STATE; 79 Display *display; 80 Window window; 81 XClientMessageEvent event; 82 83 84 /* Code. */ 85 86 display = XtDisplay( widget ); 87 window = XtWindow( widget ); 88 89 xa_WM_CHANGE_STATE = XInternAtom( display, "WM_CHANGE_STATE", False ); 90 91 event.type = ClientMessage; 92 event.display = display; 93 event.message_type = xa_WM_CHANGE_STATE; 94 event.format = 32; 95 event.data.l[ 0 ] = IconicState; 96 event.window = window; 97 98 XSendEvent( display, RootWindow( display, DefaultScreen( display ) ), 99 True, 100 (SubstructureRedirectMask | SubstructureNotifyMask), 101 (XEvent *) &event ); 102 103 XFlush( display ); 104 105 106 return; 107 108 } /* xitIconify */ 109 110 111 /*----------------------------------------------------------------------*/ 112 113 void xitSetIconWindow(Widget shell,XIT_ICON_WINDOW * icon_win,Window * window,GC * gc)114 xitSetIconWindow( Widget shell, 115 XIT_ICON_WINDOW *icon_win, 116 Window *window, 117 GC *gc ) 118 { 119 120 /* Variables. */ 121 UINT32 border_width; 122 UINT32 depth; 123 UINT32 height; 124 UINT32 width; 125 INT32 x; 126 INT32 y; 127 Arg args[ 10 ]; 128 Cardinal n; 129 Display *display = XtDisplay( shell ); 130 Window root; 131 XGCValues gc_values; 132 133 134 135 /* Code. */ 136 137 /* Size of pixmap to use. */ 138 XGetGeometry( display, icon_win -> image, 139 &root, &x, &y, &width, &height, 140 &border_width, &depth ); 141 142 143 /* Fetch the icon window (if it exists). */ 144 n = 0; 145 XtSetArg( args[ n ], XmNiconWindow, window ); n++; 146 XtGetValues( shell, args, n ); 147 148 /* If there is no icon window, create one. */ 149 if( ! *window ) { 150 151 UINT32 value_mask; 152 XSetWindowAttributes wa; 153 154 wa.background_pixel = icon_win -> icon_bg; 155 wa.border_pixel = icon_win -> icon_fg; 156 wa.override_redirect = True; 157 wa.event_mask = ExposureMask; 158 159 if( icon_win -> report_expose_events ) 160 value_mask = CWBackPixel|CWBorderPixel|CWOverrideRedirect|CWEventMask; 161 else 162 value_mask = CWBackPixel|CWBorderPixel|CWOverrideRedirect; 163 164 *window = XCreateWindow( display, root, 165 0, 0, width, height, 1, depth, InputOutput, 166 CopyFromParent, value_mask, &wa ); 167 168 /* If the window could not be created, try to set the pixmap as is. */ 169 if( ! *window ) { 170 n = 0; 171 XtSetArg( args[ n ], XmNiconPixmap, icon_win -> image ); n++; 172 XtSetValues( shell, args, n ); 173 174 return; 175 } 176 177 /* Now when the window is created, set it. */ 178 n = 0; 179 XtSetArg( args[ n ], XmNiconWindow, *window ); n++; 180 XtSetValues( shell, args, n ); 181 182 } /* if */ 183 184 185 /* Create a GC to use? */ 186 if( *gc == NULL ) { 187 188 gc_values.font = XLoadFont( display, "fixed" ); 189 190 *gc = XCreateGC( display, *window, GCFont, &gc_values ); 191 } 192 193 194 /* Set the window's background pixmap to the image. */ 195 XSetWindowBackgroundPixmap( display, *window, icon_win -> image ); 196 XClearWindow( display, *window ); 197 198 199 /* Set the label in the icon? */ 200 if( icon_win -> label != NULL ) { 201 202 Dimension str_height; 203 Dimension str_width; 204 205 /* Background and foreground colors. */ 206 gc_values.foreground = icon_win -> label_fg; 207 gc_values.background = icon_win -> icon_bg; 208 209 XChangeGC( display, *gc, (GCForeground|GCBackground), &gc_values ); 210 211 212 XmStringExtent( icon_win -> font_list, icon_win -> label, 213 &str_width, &str_height ); 214 215 x = width / 2 - (int) str_width / 2 + icon_win -> x_offset; 216 y = height / 2 - (int) str_height / 2 + icon_win -> y_offset; 217 218 XmStringDrawImage( display, *window, 219 icon_win -> font_list, icon_win -> label, *gc, 220 (Position) x, (Position) y + 4, str_width, 221 XmALIGNMENT_CENTER, XmSTRING_DIRECTION_L_TO_R, 222 NULL ); 223 224 } /* if */ 225 226 227 return; 228 229 } /* xitSetIconWindow */ 230