Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / widgets.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001
9d2e6ef9 scottc1998-09-29 22:36:29 +00002#include "WINGsP.h"
882b9a8e kojima2001-07-23 20:31:32 +00003#include "wconfig.h"
9d2e6ef9 scottc1998-09-29 22:36:29 +00004
0c09179f dan2004-10-14 23:05:20 +00005#include <X11/Xft/Xft.h>
2b2fecac dan2002-10-13 18:25:36 +00006
9d2e6ef9 scottc1998-09-29 22:36:29 +00007#include <X11/Xutil.h>
128403b4 dan2001-05-19 23:07:10 +00008#include <X11/Xatom.h>
05f2a74e kojima2001-02-09 16:03:09 +00009#include <X11/keysym.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000010#include <X11/cursorfont.h>
11
9aca0d5f dan2004-10-12 01:34:32 +000012#include <X11/Xlocale.h>
13
9d2e6ef9 scottc1998-09-29 22:36:29 +000014/********** data ************/
15
9d2e6ef9 scottc1998-09-29 22:36:29 +000016#define CHECK_BUTTON_ON_WIDTH 16
17#define CHECK_BUTTON_ON_HEIGHT 16
18
19static char *CHECK_BUTTON_ON[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020020 " %",
21 " .............%#",
22 " ........... .%#",
23 " .......... #.%#",
24 " ......... #%.%#",
25 " ........ #%..%#",
26 " ... #.. #%...%#",
27 " ... #% #%....%#",
28 " ... % #%.....%#",
29 " ... #%......%#",
30 " ... #%.......%#",
31 " ...#%........%#",
32 " .............%#",
33 " .............%#",
34 " %%%%%%%%%%%%%%#",
35 "%###############"
36};
9d2e6ef9 scottc1998-09-29 22:36:29 +000037
38#define CHECK_BUTTON_OFF_WIDTH 16
39#define CHECK_BUTTON_OFF_HEIGHT 16
40
41static char *CHECK_BUTTON_OFF[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020042 " %",
43 " .............%#",
44 " .............%#",
45 " .............%#",
46 " .............%#",
47 " .............%#",
48 " .............%#",
49 " .............%#",
50 " .............%#",
51 " .............%#",
52 " .............%#",
53 " .............%#",
54 " .............%#",
55 " .............%#",
56 " %%%%%%%%%%%%%%#",
57 "%###############"
58};
9d2e6ef9 scottc1998-09-29 22:36:29 +000059
60#define RADIO_BUTTON_ON_WIDTH 15
61#define RADIO_BUTTON_ON_HEIGHT 15
62static char *RADIO_BUTTON_ON[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020063 ".....%%%%%.....",
64 "...%%#####%%...",
65 "..%##.....%.%..",
66 ".%#%.. .....",
67 ".%#. ...",
68 "%#.. .. ",
69 "%#. . ",
70 "%#. . ",
71 "%#. . ",
72 "%#. . ",
73 ".%%. . .",
74 ".%.. . .",
75 "..%... .. ..",
76 ".... ..... ...",
77 "..... .....",
9d2e6ef9 scottc1998-09-29 22:36:29 +000078};
79
80#define RADIO_BUTTON_OFF_WIDTH 15
81#define RADIO_BUTTON_OFF_HEIGHT 15
82static char *RADIO_BUTTON_OFF[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020083 ".....%%%%%.....",
84 "...%%#####%%...",
85 "..%##.......%..",
86 ".%#%...........",
87 ".%#............",
88 "%#............ ",
89 "%#............ ",
90 "%#............ ",
91 "%#............ ",
92 "%#............ ",
93 ".%%.......... .",
94 ".%........... .",
95 "..%......... ..",
96 ".... ..... ...",
97 "..... .....",
9d2e6ef9 scottc1998-09-29 22:36:29 +000098};
99
9d2e6ef9 scottc1998-09-29 22:36:29 +0000100static char *BUTTON_ARROW[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200101 "..................",
102 "....##....#### ...",
103 "...#.%....#... ...",
104 "..#..%#####... ...",
105 ".#............ ...",
106 "#............. ...",
107 ".#............ ...",
108 "..#.. ...",
109 "...#. ............",
110 "....# ............"
9d2e6ef9 scottc1998-09-29 22:36:29 +0000111};
112
113#define BUTTON_ARROW_WIDTH 18
114#define BUTTON_ARROW_HEIGHT 10
115
9d2e6ef9 scottc1998-09-29 22:36:29 +0000116static char *BUTTON_ARROW2[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200117 " ",
118 " ## ####. ",
119 " # % # . ",
120 " # %##### . ",
121 " # . ",
122 "# . ",
123 " # . ",
124 " # .......... ",
125 " # . ",
126 " #. "
9d2e6ef9 scottc1998-09-29 22:36:29 +0000127};
128
129#define BUTTON_ARROW2_WIDTH 18
130#define BUTTON_ARROW2_HEIGHT 10
131
9d2e6ef9 scottc1998-09-29 22:36:29 +0000132static char *SCROLLER_DIMPLE[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200133 ".%###.",
134 "%#%%%%",
135 "#%%...",
136 "#%.. ",
137 "#%. ",
138 ".%. ."
9d2e6ef9 scottc1998-09-29 22:36:29 +0000139};
140
141#define SCROLLER_DIMPLE_WIDTH 6
142#define SCROLLER_DIMPLE_HEIGHT 6
143
9d2e6ef9 scottc1998-09-29 22:36:29 +0000144static char *SCROLLER_ARROW_UP[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200145 "....%....",
146 "....#....",
147 "...%#%...",
148 "...###...",
149 "..%###%..",
150 "..#####..",
151 ".%#####%.",
152 ".#######.",
153 "%#######%"
9d2e6ef9 scottc1998-09-29 22:36:29 +0000154};
155
156static char *HI_SCROLLER_ARROW_UP[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200157 " % ",
158 " % ",
159 " %%% ",
160 " %%% ",
161 " %%%%% ",
162 " %%%%% ",
163 " %%%%%%% ",
164 " %%%%%%% ",
165 "%%%%%%%%%"
9d2e6ef9 scottc1998-09-29 22:36:29 +0000166};
167
168#define SCROLLER_ARROW_UP_WIDTH 9
169#define SCROLLER_ARROW_UP_HEIGHT 9
170
9d2e6ef9 scottc1998-09-29 22:36:29 +0000171static char *SCROLLER_ARROW_DOWN[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200172 "%#######%",
173 ".#######.",
174 ".%#####%.",
175 "..#####..",
176 "..%###%..",
177 "...###...",
178 "...%#%...",
179 "....#....",
180 "....%...."
9d2e6ef9 scottc1998-09-29 22:36:29 +0000181};
182
183static char *HI_SCROLLER_ARROW_DOWN[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200184 "%%%%%%%%%",
185 " %%%%%%% ",
186 " %%%%%%% ",
187 " %%%%% ",
188 " %%%%% ",
189 " %%% ",
190 " %%% ",
191 " % ",
192 " % "
9d2e6ef9 scottc1998-09-29 22:36:29 +0000193};
194
195#define SCROLLER_ARROW_DOWN_WIDTH 9
196#define SCROLLER_ARROW_DOWN_HEIGHT 9
197
9d2e6ef9 scottc1998-09-29 22:36:29 +0000198static char *SCROLLER_ARROW_LEFT[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200199 "........%",
200 "......%##",
201 "....%####",
202 "..%######",
203 "%########",
204 "..%######",
205 "....%####",
206 "......%##",
207 "........%"
9d2e6ef9 scottc1998-09-29 22:36:29 +0000208};
209
210static char *HI_SCROLLER_ARROW_LEFT[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200211 " %",
212 " %%%",
213 " %%%%%",
214 " %%%%%%%",
215 "%%%%%%%%%",
216 " %%%%%%%",
217 " %%%%%",
218 " %%%",
219 " %"
9d2e6ef9 scottc1998-09-29 22:36:29 +0000220};
221
222#define SCROLLER_ARROW_LEFT_WIDTH 9
223#define SCROLLER_ARROW_LEFT_HEIGHT 9
224
9d2e6ef9 scottc1998-09-29 22:36:29 +0000225static char *SCROLLER_ARROW_RIGHT[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200226 "%........",
227 "##%......",
228 "####%....",
229 "######%..",
230 "########%",
231 "######%..",
232 "####%....",
233 "##%......",
234 "%........"
9d2e6ef9 scottc1998-09-29 22:36:29 +0000235};
236
237static char *HI_SCROLLER_ARROW_RIGHT[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200238 "% ",
239 "%%% ",
240 "%%%%% ",
241 "%%%%%%% ",
242 "%%%%%%%%%",
243 "%%%%%%% ",
244 "%%%%% ",
245 "%%% ",
246 "% "
9d2e6ef9 scottc1998-09-29 22:36:29 +0000247};
248
249#define SCROLLER_ARROW_RIGHT_WIDTH 9
250#define SCROLLER_ARROW_RIGHT_HEIGHT 9
251
9d2e6ef9 scottc1998-09-29 22:36:29 +0000252static char *POPUP_INDICATOR[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200253 " #==",
254 " ......%#==",
255 " ......%#%%",
256 " ......%#%%",
257 " %%%%%%%#%%",
258 "#########%%",
259 "==%%%%%%%%%",
260 "==%%%%%%%%%"
9d2e6ef9 scottc1998-09-29 22:36:29 +0000261};
262
263#define POPUP_INDICATOR_WIDTH 11
264#define POPUP_INDICATOR_HEIGHT 8
265
9d2e6ef9 scottc1998-09-29 22:36:29 +0000266static char *PULLDOWN_INDICATOR[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200267 "=#######=",
268 "=%===== =",
269 "==%=== ==",
270 "==%=== ==",
271 "===%= ===",
272 "===%= ===",
273 "====%===="
9d2e6ef9 scottc1998-09-29 22:36:29 +0000274};
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200275
9d2e6ef9 scottc1998-09-29 22:36:29 +0000276#define PULLDOWN_INDICATOR_WIDTH 9
277#define PULLDOWN_INDICATOR_HEIGHT 7
278
0261c326 dan1999-01-06 15:22:33 +0000279#define CHECK_MARK_WIDTH 8
280#define CHECK_MARK_HEIGHT 10
281
282static char *CHECK_MARK[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200283 "======== ",
284 "======= #",
285 "====== #%",
286 "===== #%=",
287 " #== #%==",
288 " #% #%===",
289 " % #%====",
290 " #%=====",
291 " #%======",
292 "#%======="
293};
0261c326 dan1999-01-06 15:22:33 +0000294
d3609d34 kojima1999-04-25 21:43:50 +0000295#define STIPPLE_WIDTH 8
296#define STIPPLE_HEIGHT 8
c0317dda dan2005-08-22 23:58:19 +0000297static char STIPPLE_BITS[] = {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200298 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
d3609d34 kojima1999-04-25 21:43:50 +0000299};
300
0261c326 dan1999-01-06 15:22:33 +0000301extern void W_ReadConfigurations(void);
302
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200303static int userWidgetCount = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000304
305/***** end data ******/
306
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200307static void renderPixmap(W_Screen * screen, Pixmap d, Pixmap mask, char **data, int width, int height)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000308{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200309 int x, y;
310 GC whiteGC = WMColorGC(screen->white);
311 GC blackGC = WMColorGC(screen->black);
312 GC lightGC = WMColorGC(screen->gray);
313 GC darkGC = WMColorGC(screen->darkGray);
314
315 if (mask)
316 XSetForeground(screen->display, screen->monoGC, 0);
317
318 for (y = 0; y < height; y++) {
319 for (x = 0; x < width; x++) {
320 switch (data[y][x]) {
321 case ' ':
322 case 'w':
323 XDrawPoint(screen->display, d, whiteGC, x, y);
324 break;
325
326 case '=':
327 if (mask)
328 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
329
330 case '.':
331 case 'l':
332 XDrawPoint(screen->display, d, lightGC, x, y);
333 break;
334
335 case '%':
336 case 'd':
337 XDrawPoint(screen->display, d, darkGC, x, y);
338 break;
339
340 case '#':
341 case 'b':
342 default:
343 XDrawPoint(screen->display, d, blackGC, x, y);
344 break;
345 }
346 }
347 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000348}
349
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200350static WMPixmap *makePixmap(W_Screen * sPtr, char **data, int width, int height, int masked)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000351{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200352 Pixmap pixmap, mask = None;
e7d0c5d9 dan2004-04-07 02:50:52 +0000353
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200354 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, sPtr->depth);
e7d0c5d9 dan2004-04-07 02:50:52 +0000355
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200356 if (masked) {
357 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
358 XSetForeground(sPtr->display, sPtr->monoGC, 1);
359 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
360 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000361
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200362 renderPixmap(sPtr, pixmap, mask, data, width, height);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000363
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200364 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height, sPtr->depth);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000365}
366
e7495baf dan1999-02-17 11:06:40 +0000367#define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
368#define T_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
369
370#define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
371#define X_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
372
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200373static Bool loadPixmaps(WMScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000374{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200375 RImage *image, *tmp;
376 RColor gray;
377 RColor white;
378
379 gray.red = 0xae;
380 gray.green = 0xaa;
381 gray.blue = 0xae;
382
383 white.red = 0xff;
384 white.green = 0xff;
385 white.blue = 0xff;
386
387 image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
388 if (!image)
389 image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
390 if (!image) {
391 wwarning(_("WINGs: could not load widget images file: %s"), RMessageForError(RErrorCode));
392 return False;
393 }
394 /* home icon */
395 /* make it have a gray background */
396 tmp = RGetSubImage(image, 0, 0, 24, 24);
397 RCombineImageWithColor(tmp, &gray);
398 scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
399 RReleaseImage(tmp);
400 /* make it have a white background */
401 tmp = RGetSubImage(image, 0, 0, 24, 24);
402 RCombineImageWithColor(tmp, &white);
403 scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
404 RReleaseImage(tmp);
405
406 /* trash can */
407 tmp = RGetSubImage(image, 104, 0, 24, 24);
408 RCombineImageWithColor(tmp, &white);
409 scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
410 RReleaseImage(tmp);
411 tmp = RGetSubImage(image, 104, 0, 24, 24);
412 RCombineImageWithColor(tmp, &white);
413 scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
414 RReleaseImage(tmp);
415 /* create dir */
416 tmp = RGetSubImage(image, 104, 24, 24, 24);
417 RCombineImageWithColor(tmp, &white);
418 scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
419 RReleaseImage(tmp);
420 tmp = RGetSubImage(image, 104, 24, 24, 24);
421 RCombineImageWithColor(tmp, &white);
422 scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
423 RReleaseImage(tmp);
424 /* diskettes */
425 tmp = RGetSubImage(image, 24, 80, 24, 24);
426 RCombineImageWithColor(tmp, &white);
427 scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
428 RReleaseImage(tmp);
429 tmp = RGetSubImage(image, 24, 80, 24, 24);
430 RCombineImageWithColor(tmp, &white);
431 scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
432 RReleaseImage(tmp);
433 /* unmount */
434 tmp = RGetSubImage(image, 0, 80, 24, 24);
435 RCombineImageWithColor(tmp, &white);
436 scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
437 RReleaseImage(tmp);
438 tmp = RGetSubImage(image, 0, 80, 24, 24);
439 RCombineImageWithColor(tmp, &white);
440 scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
441 RReleaseImage(tmp);
442
443 /* Magnifying Glass Icon for ColorPanel */
444 tmp = RGetSubImage(image, 24, 0, 40, 32);
445 RCombineImageWithColor(tmp, &gray);
446 scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
447 RReleaseImage(tmp);
448 /* ColorWheel Icon for ColorPanel */
449 tmp = RGetSubImage(image, 0, 25, 24, 24);
450 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
451 RReleaseImage(tmp);
452 /* GrayScale Icon for ColorPanel */
453 tmp = RGetSubImage(image, 65, 0, 40, 24);
454 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
455 RReleaseImage(tmp);
456 /* RGB Icon for ColorPanel */
457 tmp = RGetSubImage(image, 25, 33, 40, 24);
458 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
459 RReleaseImage(tmp);
460 /* CMYK Icon for ColorPanel */
461 tmp = RGetSubImage(image, 65, 25, 40, 24);
462 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
463 RReleaseImage(tmp);
464 /* HSB Icon for ColorPanel */
465 tmp = RGetSubImage(image, 0, 57, 40, 24);
466 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
467 RReleaseImage(tmp);
468 /* CustomColorPalette Icon for ColorPanel */
469 tmp = RGetSubImage(image, 81, 57, 40, 24);
470 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
471 RReleaseImage(tmp);
472 /* ColorList Icon for ColorPanel */
473 tmp = RGetSubImage(image, 41, 57, 40, 24);
474 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
475 RReleaseImage(tmp);
476
477 RReleaseImage(image);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000478
479#if 0
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200480 scr->defaultObjectIcon = WMCreatePixmapFromFile(scr, T_DEFAULT_OBJECT_ICON_FILE);
481 if (!scr->defaultObjectIcon) {
482 scr->defaultObjectIcon = WMCreatePixmapFromFile(scr, X_DEFAULT_OBJECT_ICON_FILE);
483 }
484 if (!scr->defaultObjectIcon) {
485 wwarning("WINGs: could not load default icon file");
486 return False;
487 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000488#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200489 return True;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000490}
491
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200492WMScreen *WMOpenScreen(const char *display)
05f2a74e kojima2001-02-09 16:03:09 +0000493{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200494 Display *dpy = XOpenDisplay(display);
e7d0c5d9 dan2004-04-07 02:50:52 +0000495
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200496 if (!dpy) {
497 wwarning("WINGs: could not open display %s", XDisplayName(display));
498 return NULL;
499 }
e7d0c5d9 dan2004-04-07 02:50:52 +0000500
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200501 return WMCreateSimpleApplicationScreen(dpy);
05f2a74e kojima2001-02-09 16:03:09 +0000502}
503
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200504WMScreen *WMCreateSimpleApplicationScreen(Display * display)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000505{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200506 WMScreen *scr;
e7d0c5d9 dan2004-04-07 02:50:52 +0000507
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200508 scr = WMCreateScreen(display, DefaultScreen(display));
e7d0c5d9 dan2004-04-07 02:50:52 +0000509
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200510 scr->aflags.hasAppIcon = 0;
511 scr->aflags.simpleApplication = 1;
e7d0c5d9 dan2004-04-07 02:50:52 +0000512
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200513 return scr;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000514}
515
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200516WMScreen *WMCreateScreen(Display * display, int screen)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000517{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200518 return WMCreateScreenWithRContext(display, screen, RCreateContext(display, screen, NULL));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000519}
520
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200521WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * context)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000522{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200523 W_Screen *scrPtr;
524 XGCValues gcv;
525 Pixmap stipple;
526 static int initialized = 0;
527 static char *atomNames[] = {
528 "_GNUSTEP_WM_ATTR",
529 "WM_DELETE_WINDOW",
530 "WM_PROTOCOLS",
531 "CLIPBOARD",
532 "XdndAware",
533 "XdndSelection",
534 "XdndEnter",
535 "XdndLeave",
536 "XdndPosition",
537 "XdndDrop",
538 "XdndFinished",
539 "XdndTypeList",
540 "XdndActionList",
541 "XdndActionDescription",
542 "XdndStatus",
543 "XdndActionCopy",
544 "XdndActionMove",
545 "XdndActionLink",
546 "XdndActionAsk",
547 "XdndActionPrivate",
548 "_WINGS_DND_MOUSE_OFFSET",
549 "WM_STATE",
550 "UTF8_STRING",
551 "_NET_WM_NAME",
552 "_NET_WM_ICON_NAME",
553 "_NET_WM_ICON",
554 };
555 Atom atoms[sizeof(atomNames) / sizeof(char *)];
556 int i;
557
558 if (!initialized) {
559
560 initialized = 1;
561
562 W_ReadConfigurations();
563
564 assert(W_ApplicationInitialized());
565 }
566
567 scrPtr = malloc(sizeof(W_Screen));
568 if (!scrPtr)
569 return NULL;
570 memset(scrPtr, 0, sizeof(W_Screen));
571
572 scrPtr->aflags.hasAppIcon = 1;
573
574 scrPtr->display = display;
575 scrPtr->screen = screen;
576 scrPtr->rcontext = context;
577
578 scrPtr->depth = context->depth;
579
580 scrPtr->visual = context->visual;
581 scrPtr->lastEventTime = 0;
582
583 scrPtr->colormap = context->cmap;
584
585 scrPtr->rootWin = RootWindow(display, screen);
586
587 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
588
589 scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr), scrPtr->visual, scrPtr->colormap);
590
591 /* Create missing CUT_BUFFERs */
592 {
593 Atom *rootWinProps;
594 int exists[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
595 int count;
596
597 rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
598 for (i = 0; i < count; i++) {
599 switch (rootWinProps[i]) {
600 case XA_CUT_BUFFER0:
601 exists[0] = 1;
602 break;
603 case XA_CUT_BUFFER1:
604 exists[1] = 1;
605 break;
606 case XA_CUT_BUFFER2:
607 exists[2] = 1;
608 break;
609 case XA_CUT_BUFFER3:
610 exists[3] = 1;
611 break;
612 case XA_CUT_BUFFER4:
613 exists[4] = 1;
614 break;
615 case XA_CUT_BUFFER5:
616 exists[5] = 1;
617 break;
618 case XA_CUT_BUFFER6:
619 exists[6] = 1;
620 break;
621 case XA_CUT_BUFFER7:
622 exists[7] = 1;
623 break;
624 default:
625 break;
626 }
627 }
628 if (rootWinProps) {
629 XFree(rootWinProps);
630 }
631 for (i = 0; i < 8; i++) {
632 if (!exists[i]) {
633 XStoreBuffer(display, "", 0, i);
634 }
635 }
636 }
637
638 scrPtr->ignoredModifierMask = 0;
639 {
640 int i;
641 XModifierKeymap *modmap;
642 KeyCode nlock, slock;
643 static int mask_table[8] = {
644 ShiftMask, LockMask, ControlMask, Mod1Mask,
645 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
646 };
647 unsigned int numLockMask = 0, scrollLockMask = 0;
648
649 nlock = XKeysymToKeycode(display, XK_Num_Lock);
650 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
651
652 /*
653 * Find out the masks for the NumLock and ScrollLock modifiers,
654 * so that we can bind the grabs for when they are enabled too.
655 */
656 modmap = XGetModifierMapping(display);
657
658 if (modmap != NULL && modmap->max_keypermod > 0) {
659 for (i = 0; i < 8 * modmap->max_keypermod; i++) {
660 if (modmap->modifiermap[i] == nlock && nlock != 0)
661 numLockMask = mask_table[i / modmap->max_keypermod];
662 else if (modmap->modifiermap[i] == slock && slock != 0)
663 scrollLockMask = mask_table[i / modmap->max_keypermod];
664 }
665 }
666
667 if (modmap)
668 XFreeModifiermap(modmap);
669
670 scrPtr->ignoredModifierMask = numLockMask | scrollLockMask | LockMask;
671 }
672
673 /* initially allocate some colors */
674 WMWhiteColor(scrPtr);
675 WMBlackColor(scrPtr);
676 WMGrayColor(scrPtr);
677 WMDarkGrayColor(scrPtr);
678
679 gcv.graphics_exposures = False;
680
681 gcv.function = GXxor;
682 gcv.foreground = W_PIXEL(scrPtr->white);
683 if (gcv.foreground == 0)
684 gcv.foreground = 1;
685 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
686 | GCGraphicsExposures | GCForeground, &gcv);
687
688 gcv.function = GXxor;
689 gcv.foreground = W_PIXEL(scrPtr->gray);
690 gcv.subwindow_mode = IncludeInferiors;
691 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
692 | GCGraphicsExposures | GCForeground | GCSubwindowMode, &gcv);
693
694 gcv.function = GXcopy;
695 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
696
697 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
698
699 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
700 gcv.foreground = W_PIXEL(scrPtr->darkGray);
701 gcv.background = W_PIXEL(scrPtr->gray);
702 gcv.fill_style = FillStippled;
703 gcv.stipple = stipple;
704 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
705 GCForeground | GCBackground | GCStipple
706 | GCFillStyle | GCGraphicsExposures, &gcv);
707
708 scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
709 scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
710
711 /* we need a 1bpp drawable for the monoGC, so borrow this one */
712 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
713
714 scrPtr->stipple = stipple;
0261c326 dan1999-01-06 15:22:33 +0000715
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200716 scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
0261c326 dan1999-01-06 15:22:33 +0000717
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200718 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
0261c326 dan1999-01-06 15:22:33 +0000719
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200720 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
ca616755 dan2004-10-28 04:17:18 +0000721
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200722 if (!scrPtr->boldFont)
723 scrPtr->boldFont = scrPtr->normalFont;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000724
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200725 if (!scrPtr->normalFont) {
726 wwarning(_("could not load any fonts. Make sure your font installation"
727 " and locale settings are correct."));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000728
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200729 return NULL;
730 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000731
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200732 /* create input method stuff */
733 W_InitIM(scrPtr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000734
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200735 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
736 CHECK_BUTTON_ON_WIDTH, CHECK_BUTTON_ON_HEIGHT, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000737
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200738 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
739 CHECK_BUTTON_OFF_WIDTH, CHECK_BUTTON_OFF_HEIGHT, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000740
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200741 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
742 RADIO_BUTTON_ON_WIDTH, RADIO_BUTTON_ON_HEIGHT, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000743
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200744 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
745 RADIO_BUTTON_OFF_WIDTH, RADIO_BUTTON_OFF_HEIGHT, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000746
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200747 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW, BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000748
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200749 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
750 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000751
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200752 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
753 SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000754
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200755 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
756 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000757
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200758 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
759 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000760
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200761 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
762 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000763
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200764 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
765 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000766
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200767 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
768 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000769
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200770 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
771 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000772
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200773 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
774 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000775
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200776 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
777 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
0261c326 dan1999-01-06 15:22:33 +0000778
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200779 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
780 POPUP_INDICATOR_WIDTH, POPUP_INDICATOR_HEIGHT, True);
0261c326 dan1999-01-06 15:22:33 +0000781
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200782 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
783 PULLDOWN_INDICATOR_WIDTH, PULLDOWN_INDICATOR_HEIGHT, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000784
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200785 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK, CHECK_MARK_WIDTH, CHECK_MARK_HEIGHT, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000786
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200787 loadPixmaps(scrPtr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000788
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200789 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
74ba4f8e dan2003-08-07 00:26:21 +0000790
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200791 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
e50b7e9c kojima1999-04-28 23:50:52 +0000792
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200793 {
794 XColor bla;
795 Pixmap blank;
796
797 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
798 XSetForeground(display, scrPtr->monoGC, 0);
799 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
800
801 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank, &bla, &bla, 0, 0);
802 XFreePixmap(display, blank);
803 }
e50b7e9c kojima1999-04-28 23:50:52 +0000804
5b05c960 kojima2000-04-01 02:12:25 +0000805#ifdef HAVE_XINTERNATOMS
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200806 XInternAtoms(display, atomNames, sizeof(atomNames) / sizeof(char *), False, atoms);
5b05c960 kojima2000-04-01 02:12:25 +0000807#else
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200808 for (i = 0; i < sizeof(atomNames) / sizeof(char *); i++) {
809 atoms[i] = XInternAtom(display, atomNames[i], False);
810 }
5b05c960 kojima2000-04-01 02:12:25 +0000811#endif
6672180d kojima2000-03-28 02:30:13 +0000812
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200813 i = 0;
814 scrPtr->attribsAtom = atoms[i++];
60a247f2 kojima2000-04-03 03:10:20 +0000815
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200816 scrPtr->deleteWindowAtom = atoms[i++];
60a247f2 kojima2000-04-03 03:10:20 +0000817
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200818 scrPtr->protocolsAtom = atoms[i++];
e7d0c5d9 dan2004-04-07 02:50:52 +0000819
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200820 scrPtr->clipboardAtom = atoms[i++];
60a247f2 kojima2000-04-03 03:10:20 +0000821
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200822 scrPtr->xdndAwareAtom = atoms[i++];
823 scrPtr->xdndSelectionAtom = atoms[i++];
824 scrPtr->xdndEnterAtom = atoms[i++];
825 scrPtr->xdndLeaveAtom = atoms[i++];
826 scrPtr->xdndPositionAtom = atoms[i++];
827 scrPtr->xdndDropAtom = atoms[i++];
828 scrPtr->xdndFinishedAtom = atoms[i++];
829 scrPtr->xdndTypeListAtom = atoms[i++];
830 scrPtr->xdndActionListAtom = atoms[i++];
831 scrPtr->xdndActionDescriptionAtom = atoms[i++];
832 scrPtr->xdndStatusAtom = atoms[i++];
60a247f2 kojima2000-04-03 03:10:20 +0000833
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200834 scrPtr->xdndActionCopy = atoms[i++];
835 scrPtr->xdndActionMove = atoms[i++];
836 scrPtr->xdndActionLink = atoms[i++];
837 scrPtr->xdndActionAsk = atoms[i++];
838 scrPtr->xdndActionPrivate = atoms[i++];
60a247f2 kojima2000-04-03 03:10:20 +0000839
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200840 scrPtr->wmIconDragOffsetAtom = atoms[i++];
11bf9c80 kojima2000-04-05 00:29:10 +0000841
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200842 scrPtr->wmStateAtom = atoms[i++];
9d2e6ef9 scottc1998-09-29 22:36:29 +0000843
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200844 scrPtr->utf8String = atoms[i++];
845 scrPtr->netwmName = atoms[i++];
846 scrPtr->netwmIconName = atoms[i++];
847 scrPtr->netwmIcon = atoms[i++];
7f018497 kojima1999-04-24 20:08:20 +0000848
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200849 scrPtr->rootView = W_CreateRootView(scrPtr);
7f018497 kojima1999-04-24 20:08:20 +0000850
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200851 scrPtr->balloon = W_CreateBalloon(scrPtr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000852
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200853 W_InitApplication(scrPtr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000854
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200855 return scrPtr;
856}
79ae37a3 kojima2000-05-21 23:56:33 +0000857
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200858void WMSetWidgetDefaultFont(WMScreen * scr, WMFont * font)
79ae37a3 kojima2000-05-21 23:56:33 +0000859{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200860 WMReleaseFont(scr->normalFont);
861 scr->normalFont = WMRetainFont(font);
79ae37a3 kojima2000-05-21 23:56:33 +0000862}
863
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200864void WMSetWidgetDefaultBoldFont(WMScreen * scr, WMFont * font)
79ae37a3 kojima2000-05-21 23:56:33 +0000865{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200866 WMReleaseFont(scr->boldFont);
867 scr->boldFont = WMRetainFont(font);
79ae37a3 kojima2000-05-21 23:56:33 +0000868}
869
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200870void WMHangData(WMWidget * widget, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000871{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200872 W_VIEW(widget)->hangedData = data;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000873}
874
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200875void *WMGetHangedData(WMWidget * widget)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000876{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200877 return W_VIEW(widget)->hangedData;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000878}
879
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200880void WMDestroyWidget(WMWidget * widget)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000881{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200882 W_UnmapView(W_VIEW(widget));
883 W_DestroyView(W_VIEW(widget));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000884}
885
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200886void WMSetFocusToWidget(WMWidget * widget)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000887{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200888 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000889}
890
9d2e6ef9 scottc1998-09-29 22:36:29 +0000891/*
892 * WMRealizeWidget-
893 * Realizes the widget and all it's children.
e7d0c5d9 dan2004-04-07 02:50:52 +0000894 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000895 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200896void WMRealizeWidget(WMWidget * w)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000897{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200898 W_RealizeView(W_VIEW(w));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000899}
900
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200901void WMMapWidget(WMWidget * w)
e7d0c5d9 dan2004-04-07 02:50:52 +0000902{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200903 W_MapView(W_VIEW(w));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000904}
905
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200906void WMReparentWidget(WMWidget * w, WMWidget * newParent, int x, int y)
e29fce43 kojima2000-07-10 22:37:39 +0000907{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200908 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
e29fce43 kojima2000-07-10 22:37:39 +0000909}
910
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200911static void makeChildrenAutomap(W_View * view, int flag)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000912{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200913 view = view->childrenList;
e7d0c5d9 dan2004-04-07 02:50:52 +0000914
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200915 while (view) {
916 view->flags.mapWhenRealized = flag;
917 makeChildrenAutomap(view, flag);
e7d0c5d9 dan2004-04-07 02:50:52 +0000918
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200919 view = view->nextSister;
920 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000921}
922
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200923void WMMapSubwidgets(WMWidget * w)
e7d0c5d9 dan2004-04-07 02:50:52 +0000924{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200925 /* make sure that subwidgets created after the parent was realized
926 * are mapped too */
927 if (!W_VIEW(w)->flags.realized) {
928 makeChildrenAutomap(W_VIEW(w), True);
929 } else {
930 W_MapSubviews(W_VIEW(w));
931 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000932}
933
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200934void WMUnmapSubwidgets(WMWidget * w)
e7d0c5d9 dan2004-04-07 02:50:52 +0000935{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200936 if (!W_VIEW(w)->flags.realized) {
937 makeChildrenAutomap(W_VIEW(w), False);
938 } else {
939 W_UnmapSubviews(W_VIEW(w));
940 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000941}
942
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200943void WMUnmapWidget(WMWidget * w)
e7d0c5d9 dan2004-04-07 02:50:52 +0000944{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200945 W_UnmapView(W_VIEW(w));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000946}
947
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200948Bool WMWidgetIsMapped(WMWidget * w)
edc57cf7 kojima2000-09-25 19:21:45 +0000949{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200950 return W_VIEW(w)->flags.mapped;
edc57cf7 kojima2000-09-25 19:21:45 +0000951}
952
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200953void WMSetWidgetBackgroundColor(WMWidget * w, WMColor * color)
2b2fecac dan2002-10-13 18:25:36 +0000954{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200955 W_SetViewBackgroundColor(W_VIEW(w), color);
956 if (W_VIEW(w)->flags.mapped)
957 WMRedisplayWidget(w);
e29fce43 kojima2000-07-10 22:37:39 +0000958}
959
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200960WMColor *WMGetWidgetBackgroundColor(WMWidget * w)
0fe70d2b dan2002-11-25 04:46:00 +0000961{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200962 return W_VIEW(w)->backColor;
0fe70d2b dan2002-11-25 04:46:00 +0000963}
964
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200965void WMRaiseWidget(WMWidget * w)
e29fce43 kojima2000-07-10 22:37:39 +0000966{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200967 W_RaiseView(W_VIEW(w));
e29fce43 kojima2000-07-10 22:37:39 +0000968}
969
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200970void WMLowerWidget(WMWidget * w)
e29fce43 kojima2000-07-10 22:37:39 +0000971{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200972 W_LowerView(W_VIEW(w));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000973}
974
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200975void WMMoveWidget(WMWidget * w, int x, int y)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000976{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200977 W_MoveView(W_VIEW(w), x, y);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000978}
979
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200980void WMResizeWidget(WMWidget * w, unsigned int width, unsigned int height)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000981{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200982 W_ResizeView(W_VIEW(w), width, height);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000983}
984
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200985W_Class W_RegisterUserWidget(void)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000986{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200987 userWidgetCount++;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000988
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200989 return userWidgetCount + WC_UserWidget - 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000990}
991
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200992RContext *WMScreenRContext(WMScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000993{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200994 return scr->rcontext;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000995}
996
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200997unsigned int WMWidgetWidth(WMWidget * w)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000998{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200999 return W_VIEW(w)->size.width;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001000}
1001
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001002unsigned int WMWidgetHeight(WMWidget * w)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001003{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001004 return W_VIEW(w)->size.height;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001005}
1006
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001007Window WMWidgetXID(WMWidget * w)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001008{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001009 return W_VIEW(w)->window;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001010}
1011
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001012WMScreen *WMWidgetScreen(WMWidget * w)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001013{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001014 return W_VIEW(w)->screen;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001015}
1016
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001017void WMScreenMainLoop(WMScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001018{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001019 XEvent event;
e7d0c5d9 dan2004-04-07 02:50:52 +00001020
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001021 while (1) {
1022 WMNextEvent(scr->display, &event);
1023 WMHandleEvent(&event);
1024 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001025}
1026
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001027void WMBreakModalLoop(WMScreen * scr)
22eb14c9 kojima2001-01-09 16:45:14 +00001028{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001029 scr->modalLoop = 0;
22eb14c9 kojima2001-01-09 16:45:14 +00001030}
1031
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001032void WMRunModalLoop(WMScreen * scr, WMView * view)
22eb14c9 kojima2001-01-09 16:45:14 +00001033{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001034 /* why is scr passed if is determined from the view? */
1035 /*WMScreen *scr = view->screen; */
1036 int oldModalLoop = scr->modalLoop;
1037 WMView *oldModalView = scr->modalView;
1b41d56a dan2001-01-10 04:24:11 +00001038
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001039 scr->modalView = view;
22eb14c9 kojima2001-01-09 16:45:14 +00001040
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001041 scr->modalLoop = 1;
1042 while (scr->modalLoop) {
1043 XEvent event;
e7d0c5d9 dan2004-04-07 02:50:52 +00001044
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001045 WMNextEvent(scr->display, &event);
1046 WMHandleEvent(&event);
1047 }
1b41d56a dan2001-01-10 04:24:11 +00001048
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001049 scr->modalView = oldModalView;
1050 scr->modalLoop = oldModalLoop;
1b41d56a dan2001-01-10 04:24:11 +00001051}
22eb14c9 kojima2001-01-09 16:45:14 +00001052
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001053Display *WMScreenDisplay(WMScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001054{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001055 return scr->display;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001056}
1057
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001058int WMScreenDepth(WMScreen * scr)
9af1c6c4 dan1998-10-21 14:43:47 +00001059{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001060 return scr->depth;
9af1c6c4 dan1998-10-21 14:43:47 +00001061}
1062
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001063unsigned int WMScreenWidth(WMScreen * scr)
62240a0f dan1999-07-03 23:50:05 +00001064{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001065 return scr->rootView->size.width;
62240a0f dan1999-07-03 23:50:05 +00001066}
1067
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001068unsigned int WMScreenHeight(WMScreen * scr)
62240a0f dan1999-07-03 23:50:05 +00001069{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001070 return scr->rootView->size.height;
62240a0f dan1999-07-03 23:50:05 +00001071}
1072
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001073void WMRedisplayWidget(WMWidget * w)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001074{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001075 W_RedisplayView(W_VIEW(w));
9d2e6ef9 scottc1998-09-29 22:36:29 +00001076}