1 /***************************************************************************/
2 /* This code is part of X-toolkit widget library called Nws */
3 /* Copyright (c) 1997,1998,1999 Ondrejicka Stefan */
4 /* (ondrej@idata.sk) */
5 /* Distributed under GPL 2 or later */
6 /***************************************************************************/
7
8 #include <stdio.h>
9
10 #include <X11/IntrinsicP.h>
11 #include <X11/Xlib.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <X11/ShellP.h>
15 #include "MwUtils.h"
16 #include "MwXutils.h"
17
18 #include "MwNws.h"
19 #include "MwBaseMEP.h"
20
21 #include "MwUtils.h"
22
23 static char stiple_bitmap[] = {0x01, 0x02};
24
25 /* Draws a 3D frame with an extra line inside if the environment
26 variable XAWM_FRAME is set to "soft". The colour of the extra line
27 is the average between the bevel colour and the background.
28 In addition, draws the frame IN if thickness is negative and OUT
29 if thickness is positive.
30 */
X_DrawSoft3DFrame(Display * dpy,Drawable win,int x,int y,int width,int height,int thickness,Pixel top_left_color,Pixel bottom_right_color,Pixel bg)31 void X_DrawSoft3DFrame(Display *dpy, Drawable win, int x, int y,
32 int width, int height, int thickness,
33 Pixel top_left_color, Pixel bottom_right_color, Pixel bg)
34 {
35 char *theme = getenv("XAWM_THEME");
36 int soft = (theme != NULL);
37 unsigned long vm = 0;
38 XGCValues v;
39 XColor color1, color2;
40 GC gc = XCreateGC(dpy, win, vm, &v);
41 int red, green, blue;
42
43 color1.pixel = bottom_right_color;
44 color2.pixel = bg;
45 MwQueryColor(dpy, None, &color1);
46 MwQueryColor(dpy, None, &color2);
47 red = color1.red+color2.red;
48 green = color1.green+color2.green;
49 blue = color1.blue+color2.blue;
50 color1.red = red/2;
51 color1.green = green/2;
52 color1.blue = blue/2;
53 MwAllocColor(dpy, None, &color1);
54 XSetForeground(dpy, gc, color1.pixel);
55
56 if (thickness < 0) {
57 X_DrawSimple3DFrame(dpy, win, x, y, width, height,
58 -thickness, bottom_right_color, top_left_color);
59 if (soft) {
60 int x1 = x-thickness;
61 int x2 = x+width+thickness-1;
62 int y1 = y-thickness;
63 int y2 = y+height+thickness-1;
64 XDrawLine(dpy, win, gc, x1, y2, x1, y1);
65 XDrawLine(dpy, win, gc, x1, y1, x2, y1);
66 }
67 } else {
68 X_DrawSimple3DFrame(dpy, win, x, y, width, height,
69 thickness, top_left_color, bottom_right_color);
70 if (soft) {
71 int x1 = x+thickness+1;
72 int x2 = x+width-thickness-1;
73 int y1 = y+thickness+1;
74 int y2 = y+height-thickness-1;
75 XDrawLine(dpy, win, gc, x1, y2, x2, y2);
76 XDrawLine(dpy, win, gc, x2, y2, x2, y1);
77 }
78 }
79
80 XFreeGC(dpy, gc);
81 }
82
83 void
X_DrawSimple3DFrame(dpy,win,x,y,width,height,thickness,top_left_color,bottom_right_color)84 X_DrawSimple3DFrame(dpy,win,x,y,width,height,thickness,top_left_color,bottom_right_color)
85 Display *dpy;
86 Drawable win;
87 int x;
88 int y;
89 int width;
90 int height;
91 int thickness;
92 Pixel top_left_color;
93 Pixel bottom_right_color;
94 {
95
96 if (thickness == 0) return;
97 else {
98 XPoint top_leftPoints[6];
99
100 XPoint bottom_rightPoints[6];
101
102 GC gc;
103 XGCValues gc_res;
104 XtGCMask gc_mask;
105
106 top_leftPoints[0].x = x;
107 top_leftPoints[0].y = y;
108 top_leftPoints[1].x = x + width;
109 top_leftPoints[1].y = y;
110 top_leftPoints[2].x = x + width - thickness;
111 top_leftPoints[2].y = y + thickness;
112 top_leftPoints[3].x = x + thickness;
113 top_leftPoints[3].y = y + thickness;
114 top_leftPoints[4].x = x + thickness;
115 top_leftPoints[4].y = y + height - thickness;
116 top_leftPoints[5].x = x;
117 top_leftPoints[5].y = y + height;
118
119 bottom_rightPoints[0].x = x + width;
120 bottom_rightPoints[0].y = y + height;
121 bottom_rightPoints[1].x = x;
122 bottom_rightPoints[1].y = y + height;
123 bottom_rightPoints[2].x = x + thickness;
124 bottom_rightPoints[2].y = y + height - thickness;
125 bottom_rightPoints[3].x = x + width - thickness;
126 bottom_rightPoints[3].y = y + height - thickness;
127 bottom_rightPoints[4].x = x + width - thickness;
128 bottom_rightPoints[4].y = y + thickness;
129 bottom_rightPoints[5].x = x + width;
130 bottom_rightPoints[5].y = y;
131
132
133 gc_res.foreground = top_left_color;
134 gc_mask = GCForeground ;
135 gc = XCreateGC(dpy , win , gc_mask , &gc_res);
136
137 XFillPolygon(dpy , win , gc , top_leftPoints ,
138 XtNumber(top_leftPoints) , Nonconvex , CoordModeOrigin);
139
140 XSetForeground(dpy , gc , bottom_right_color);
141
142 XFillPolygon(dpy, win , gc , bottom_rightPoints ,
143 XtNumber(bottom_rightPoints), Nonconvex, CoordModeOrigin);
144
145 XFreeGC(dpy , gc);
146 }
147 }
148
149
X_DrawSimpleRawFrame(dpy,win,x,y,width,height,thickness,color)150 void X_DrawSimpleRawFrame(dpy,win,x,y,width,height,thickness,color)
151 Display *dpy;
152 Drawable win;
153 int x;
154 int y;
155 int width;
156 int height;
157 int thickness;
158 Pixel color;
159 {
160 if (thickness == 0) return;
161 else
162 {
163 XPoint points[10];
164
165 GC gc;
166 XGCValues gc_res;
167 XtGCMask gc_mask;
168
169 points[0].x = x;
170 points[0].y = y;
171 points[1].x = x + width;
172 points[1].y = y;
173 points[2].x = x + width;
174 points[2].y = y + height;
175 points[3].x = x;
176 points[3].y = y + height;
177 points[4].x = x;
178 points[4].y = y + thickness;
179 points[5].x = x + thickness;
180 points[5].y = y + thickness;
181 points[6].x = x + thickness;
182 points[6].y = y + height - thickness;
183 points[7].x = x + width - thickness;
184 points[7].y = y + height - thickness;
185 points[8].x = x + width - thickness;
186 points[8].y = y + thickness;
187 points[9].x = x;
188 points[9].y = y + thickness;
189
190 gc_res.foreground = color;
191 gc_mask = GCForeground ;
192 gc = XCreateGC(dpy , win , gc_mask , &gc_res);
193
194 XFillPolygon(dpy , win , gc , points ,
195 XtNumber(points) , Nonconvex , CoordModeOrigin);
196
197 XFreeGC(dpy , gc);
198 }
199 }
200
X_DrawIcon(dpy,win,icon,x,y)201 void X_DrawIcon(dpy,win,icon,x,y)
202 Display *dpy;
203 Drawable win;
204 Icon *icon;
205 int x;
206 int y;
207 {
208 GC gc;
209 XGCValues gc_res;
210 XtGCMask gc_mask;
211
212 if (icon == NULL) return;
213
214 gc_res.fill_style = FillTiled;
215 gc_res.fill_style = FillTiled;
216 gc_res.tile = icon->pixmap;
217 gc_res.clip_mask = icon->shape;
218 gc_res.ts_x_origin = x;
219 gc_res.ts_y_origin = y;
220 gc_res.clip_x_origin = x;
221 gc_res.clip_y_origin = y;
222
223 gc_mask = GCTile | GCClipMask | GCFillStyle | GCTileStipXOrigin |
224 GCTileStipYOrigin | GCClipXOrigin | GCClipYOrigin;
225
226 gc = XCreateGC(dpy,DefaultRootWindow(dpy),gc_mask, &gc_res);
227
228 XFillRectangle(dpy , win , gc , x , y , icon->width , icon->height);
229
230 XFreeGC(dpy , gc);
231 }
232
X_Draw3DArrow(dpy,win,x,y,width,height,type,top,bottom,normal)233 void X_Draw3DArrow(dpy , win , x , y , width , height , type , top , bottom , normal)
234 Display * dpy;
235 Window win;
236 int x;
237 int y;
238 int width;
239 int height;
240 int type;
241 Pixel top;
242 Pixel bottom;
243 Pixel normal;
244 {
245 GC gc;
246 XGCValues gc_res;
247
248 gc_res.foreground = normal;
249
250 gc = XCreateGC(dpy , win , GCForeground, &gc_res );
251
252 switch (type)
253 {
254 case XtCtop:
255 {
256 XPoint poly[3];
257
258 poly[0].x = x;
259 poly[0].y = y + height;
260 poly[1].x = x + width / 2;
261 poly[1].y = y;
262 poly[2].x = x + width;
263 poly[2].y = y + height;
264
265 XFillPolygon(dpy , win , gc , poly , XtNumber(poly) ,
266 Nonconvex , CoordModeOrigin);
267
268 XSetForeground(dpy , gc , top);
269 XDrawLine(dpy , win , gc , x , y + height , x + width / 2 , y);
270 XSetForeground(dpy , gc , bottom);
271 XDrawLine(dpy , win , gc , x , y + height , x + width ,
272 y + height);
273 XDrawLine(dpy , win , gc , x + width , y + height ,
274 x+ width / 2 , y);
275 }
276 break;
277 case XtCbottom:
278 {
279 XPoint poly[3];
280
281 poly[0].x = x;
282 poly[0].y = y;
283 poly[1].x = x + width / 2;
284 poly[1].y = y + height;
285 poly[2].x = x + width;
286 poly[2].y = y;
287
288 XFillPolygon(dpy , win , gc , poly , XtNumber(poly) ,
289 Nonconvex , CoordModeOrigin);
290
291 XSetForeground(dpy , gc , top);
292 XDrawLine(dpy , win , gc , x , y , x + width , y);
293 XDrawLine(dpy , win , gc , x , y , x + width / 2 ,
294 y + height);
295 XSetForeground(dpy , gc , bottom);
296 XDrawLine(dpy , win , gc , x + width , y ,
297 x + width / 2 , y + height);
298
299 }
300 break;
301 case XtCright:
302 {
303 XPoint poly[3];
304
305 poly[0].x = x;
306 poly[0].y = y;
307 poly[1].x = x + width;
308 poly[1].y = y + height / 2;
309 poly[2].x = x;
310 poly[2].y = y + height;
311
312 XFillPolygon(dpy , win , gc , poly , XtNumber(poly) ,
313 Nonconvex , CoordModeOrigin);
314
315 XSetForeground(dpy , gc , top);
316 XDrawLine(dpy , win , gc , x , y , x , y + height);
317 XDrawLine(dpy , win , gc , x , y , x + width ,
318 y + height / 2);
319 XSetForeground(dpy , gc , bottom);
320 XDrawLine(dpy , win , gc , x + width , y + height / 2 ,
321 x , y + height);
322
323 }
324 break;
325 case XtCleft:
326 default:
327 {
328
329 XPoint poly[3];
330
331 poly[0].x = x + width;
332 poly[0].y = y;
333 poly[1].x = x;
334 poly[1].y = y + height / 2;
335 poly[2].x = x + width;
336 poly[2].y = y + height;
337
338 XFillPolygon(dpy , win , gc , poly , XtNumber(poly) ,
339 Nonconvex , CoordModeOrigin);
340
341 XSetForeground(dpy , gc , bottom);
342 XDrawLine(dpy , win , gc , x , y + height / 2 ,
343 x + width , y + height);
344 XDrawLine(dpy , win , gc , x + width , y , x + width ,
345 y + height );
346 XSetForeground(dpy , gc , top);
347 XDrawLine(dpy , win , gc , x , y + height / 2 ,
348 x + width , y );
349 }
350 }
351 XFreeGC(dpy , gc);
352 }
353
X_Draw3DRectangle(dpy,win,x,y,width,height,thickness,top,bottom,normal)354 void X_Draw3DRectangle(dpy,win,x,y,width,height,thickness,top,bottom,normal)
355 Display *dpy;
356 Drawable win;
357 int x;
358 int y;
359 int width;
360 int height;
361 int thickness;
362 Pixel top;
363 Pixel bottom;
364 Pixel normal;
365 {
366 GC gc;
367 XGCValues gc_res;
368
369 gc_res.foreground = normal;
370
371 gc = XCreateGC(dpy , win , GCForeground, &gc_res );
372
373 XFillRectangle(dpy , win , gc , x + thickness , y + thickness ,
374 width - 2 * thickness , height - 2 * thickness);
375
376 XFreeGC(dpy , gc);
377
378 X_DrawSimple3DFrame(dpy , win , x , y , width , height , thickness ,
379 top , bottom);
380
381 }
382
X_Draw3DString(dpy,win,font,x,y,offset,text,length,normal,shadow)383 void X_Draw3DString(dpy,win,font,x,y,offset,text,length,normal,shadow)
384 Display *dpy;
385 Drawable win;
386 XFontStruct *font;
387 int x;
388 int y;
389 int offset;
390 String text;
391 int length;
392 Pixel normal;
393 Pixel shadow;
394 {
395 GC gc;
396 XGCValues gc_res;
397
398 gc_res.foreground = shadow;
399 gc_res.font = font->fid;
400 gc = XCreateGC(dpy , win , GCForeground | GCFont , &gc_res );
401
402 XDrawString(dpy , win , gc , x + offset , y + offset , text , length);
403
404 XSetForeground(dpy , gc , normal);
405
406 XDrawString(dpy , win , gc , x , y , text , length);
407
408 XFreeGC(dpy , gc);
409 }
410
X_DrawTextCursor(dpy,win,x,y,height,color)411 void X_DrawTextCursor(dpy , win , x , y , height , color)
412 Display *dpy;
413 Window win;
414 int x;
415 int y;
416 int height;
417 Pixel color;
418 {
419 GC gc;
420 XGCValues gc_res;
421
422 gc_res.foreground = color;
423
424 gc = XCreateGC(dpy , win , GCForeground , &gc_res );
425
426 XDrawLine(dpy , win , gc , x , y , x , y + height);
427 XDrawLine(dpy, win , gc , x - 2 , y , x + 2 , y);
428 XDrawLine(dpy , win , gc, x - 2 , y + height , x + 2 ,y + height);
429
430 XFreeGC(dpy , gc);
431
432 }
433
X_XpmDataToIcon(dpy,data)434 Icon *X_XpmDataToIcon(dpy , data)
435 Display *dpy;
436 char **data;
437 {
438 int status;
439 Icon *icon = MwMalloc(sizeof(Icon));
440 unsigned int b_width,depth;
441 int x,y;
442
443 status = XpmCreatePixmapFromData(dpy , DefaultRootWindow(dpy) , data ,
444 &icon->pixmap , &icon->shape , NULL);
445
446 switch (status) {
447 case XpmOpenFailed:
448 case XpmFileInvalid:
449 case XpmNoMemory:
450 XtWarning("Unable to create icon from data");
451 break;
452
453 case XpmColorError:
454 case XpmColorFailed:
455 XtWarning("Could not get (all) colors for icon");
456 case XpmSuccess:
457 if (icon->pixmap)
458 status=XGetGeometry(dpy , icon->pixmap , &DefaultRootWindow(dpy) ,
459 &x , &y , &icon->width , &icon->height ,
460 &b_width , &depth);
461 else
462 {
463 free(icon);
464 icon = NULL;
465 XtWarning("Unable to create icon from data");
466 }
467 }
468
469 return icon;
470 }
471
X_ClipWindowByParent(Display * dpy,Window win)472 Region X_ClipWindowByParent(Display *dpy , Window win)
473 {
474 XPoint clipb[4];
475 unsigned int pw,ph,bw,dpt,ww,wh;
476 int wx,wy,px,py;
477 Window root , parent , *childs ;
478 unsigned int nchilds;
479
480 XQueryTree(dpy , win , &root , &parent , &childs , &nchilds);
481 if (childs) MwFree(childs);
482
483 XGetGeometry(dpy , parent , &root , &px , &py , &pw , &ph , &bw , &dpt);
484 XGetGeometry(dpy , win , &root , &wx , &wy , &ww , &wh , &bw , &dpt);
485
486 clipb[0].x = 0;
487 clipb[0].y = (wy < 0) ? -wy : 0;
488 clipb[1].x = ww;
489 clipb[1].y = (wy < 0) ? -wy : 0;
490 clipb[2].x = 0;
491 clipb[2].y = (wy + wh > ph) ? ph - wy : wh;
492 clipb[1].x = ww;
493 clipb[2].y = (wy + wh > ph) ? ph - wy : wh;
494
495 return XPolygonRegion(clipb , 4 , EvenOddRule);
496 }
497
X_GetWindowRootPosition(dpy,win,x,y)498 void X_GetWindowRootPosition(dpy , win , x , y)
499 Display *dpy;
500 Window win;
501 int *x;
502 int *y;
503 {
504 Window root , parent , *childs ;
505 unsigned int nchilds;
506 unsigned int bw,dpt,ww,wh;
507 int wx,wy;
508 int rx = 0 , ry = 0;
509
510 XQueryTree(dpy , win , &root , &parent , &childs , &nchilds);
511 MwFree(childs);
512
513 while(win != root)
514 {
515 XGetGeometry(dpy , win , &root , &wx , &wy , &ww , &wh , &bw , &dpt);
516 rx += wx;
517 ry +=wy;
518 XQueryTree(dpy , win , &root , &parent , &childs , &nchilds);
519 MwFree(childs);
520 win = parent;
521 }
522
523 *x = rx;
524 *y = ry;
525 }
526
Xt_SetInsensitive(w)527 void Xt_SetInsensitive(w)
528 Widget w;
529 {
530 Pixmap p;
531 GC gc;
532 XGCValues gc_res;
533 Display *dpy;
534 Window win;
535
536
537 if (!XtIsRealized(w)) return;
538
539 if (XtIsSubclass(w , coreWidgetClass))
540 {
541 dpy = XtDisplay(w);
542 win = XtWindow(w);
543 }
544 else
545 {
546 dpy = XtDisplayOfObject(w);
547 win = XtWindowOfObject(w);
548 }
549
550 p = XCreateBitmapFromData(dpy,win,stiple_bitmap,2,2);
551
552 if (XtIsSubclass(w , coreWidgetClass))
553 {
554 gc_res.foreground = w->core.background_pixel;
555 }
556 else
557 {
558 gc_res.foreground = ((MwBaseMEObject) w)->baseME.background;
559 }
560
561 gc_res.fill_style = FillStippled;
562 gc_res.stipple = p;
563
564 gc = XCreateGC(dpy , win ,
565 GCForeground | GCStipple | GCFillStyle , &gc_res );
566
567 if (XtIsSubclass(w , coreWidgetClass))
568 {
569 XFillRectangle(dpy , win , gc , 0 , 0 ,
570 w->core.width , w->core.height);
571 }
572 else
573 {
574 XFillRectangle(dpy , win , gc , w->core.x , w->core.y ,
575 w->core.width , w->core.height);
576 }
577
578 XFreeGC(dpy , gc);
579 XFreePixmap(dpy , p);
580 }
581
Xt_GetShell(w)582 Widget Xt_GetShell(w)
583 Widget w;
584 {
585 Widget pw;
586
587 pw = w;
588
589 while(pw && !XtIsShell(pw)) pw = XtParent(pw);
590
591 return pw;
592 }
593
Xt_IsUp(w)594 Boolean Xt_IsUp(w)
595 Widget w;
596 {
597 ShellWidget sw = (ShellWidget) Xt_GetShell(w);
598
599 return sw ? sw->shell.popped_up : False;
600 }
601 /* $XConsortium: Vendor.c,v 1.21 91/07/30 15:29:56 rws Exp $ */
602
603 /***********************************************************
604 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
605 and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
606
607 All Rights Reserved
608
609 Permission to use, copy, modify, and distribute this software and its
610 documentation for any purpose and without fee is hereby granted,
611 provided that the above copyright notice appear in all copies and that
612 both that copyright notice and this permission notice appear in
613 supporting documentation, and that the names of Digital or MIT not be
614 used in advertising or publicity pertaining to distribution of the
615 software without specific, written prior permission.
616
617 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
618 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
619 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
620 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
621 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
622 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
623 SOFTWARE.
624
625 ******************************************************************/
626
627 /*
628 * This is a copy of Xt/Vendor.c with an additional ClassInitialize
629 * procedure to register Xmu resource type converters.
630 *
631 */
632
633 /* Make sure all wm properties can make it out of the resource manager */
634
635 /* I stole this from Xaw sources */
636
637 #include <stdio.h>
638
639 #include <X11/IntrinsicP.h>
640 #include <X11/StringDefs.h>
641 #include <X11/Shell.h>
642 #include <X11/ShellP.h>
643 #include <X11/Vendor.h>
644 #include <X11/VendorP.h>
645 #include <X11/Xmu/Converters.h>
646 #include <X11/Xmu/Editres.h>
647
648 static XtResource resources[] = {
649 {XtNinput, XtCInput, XtRBool, sizeof(Bool),
650 XtOffsetOf(VendorShellRec, wm.wm_hints.input),
651 XtRImmediate, (XtPointer)True}
652 };
653
654 /***************************************************************************
655 *
656 * Vendor shell class record
657 *
658 ***************************************************************************/
659
660 static void VendorShellClassInitialize();
661 static void VendorShellInitialize();
662 static void ChangeManaged();
663 static XtGeometryResult QueryGeometry();
664
665 #define SuperClass (&wmShellClassRec)
666 externaldef(vendorshellclassrec) VendorShellClassRec vendorShellClassRec = {
667 {
668 /* superclass */ (WidgetClass)SuperClass,
669 /* class_name */ "VendorShell",
670 /* size */ sizeof(VendorShellRec),
671 /* class_initialize */ VendorShellClassInitialize,
672 /* class_part_initialize*/ NULL,
673 /* Class init'ed ? */ FALSE,
674 /* initialize */ VendorShellInitialize,
675 /* initialize_hook */ NULL,
676 /* realize */ XtInheritRealize,
677 /* actions */ NULL,
678 /* num_actions */ 0,
679 /* resources */ resources,
680 /* resource_count */ XtNumber(resources),
681 /* xrm_class */ NULLQUARK,
682 /* compress_motion */ FALSE,
683 /* compress_exposure */ TRUE,
684 /* compress_enterleave*/ FALSE,
685 /* visible_interest */ FALSE,
686 /* destroy */ NULL,
687 /* resize */ XtInheritResize,
688 /* expose */ NULL,
689 /* set_values */ NULL,
690 /* set_values_hook */ NULL,
691 /* set_values_almost */ XtInheritSetValuesAlmost,
692 /* get_values_hook */ NULL,
693 /* accept_focus */ NULL,
694 /* intrinsics version */ XtVersion,
695 /* callback offsets */ NULL,
696 /* tm_table */ NULL,
697 /* query_geometry */ QueryGeometry,
698 /* display_accelerator*/ NULL,
699 /* extension */ NULL
700 },{
701 /* geometry_manager */ XtInheritGeometryManager,
702 /* change_managed */ ChangeManaged,
703 /* insert_child */ XtInheritInsertChild,
704 /* delete_child */ XtInheritDeleteChild,
705 /* extension */ NULL
706 },{
707 /* extension */ NULL
708 },{
709 /* extension */ NULL
710 },{
711 /* extension */ NULL
712 }
713 };
714
715 externaldef(vendorshellwidgetclass) WidgetClass vendorShellWidgetClass =
716 (WidgetClass) (&vendorShellClassRec);
717
VendorShellClassInitialize()718 static void VendorShellClassInitialize()
719 {
720 static XtConvertArgRec screenConvertArg[] = {
721 {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
722 sizeof(Screen *)}
723 };
724
725 XtAddConverter(XtRString, XtRCursor, XmuCvtStringToCursor,
726 screenConvertArg, XtNumber(screenConvertArg));
727
728 XtAddConverter(XtRString, XtRBitmap, XmuCvtStringToBitmap,
729 screenConvertArg, XtNumber(screenConvertArg));
730 }
731
732 /* ARGSUSED */
VendorShellInitialize(req,new)733 static void VendorShellInitialize(req, new)
734 Widget req, new;
735 {
736 XtAddEventHandler(new, (EventMask) 0, TRUE, _XEditResCheckMessages, NULL);
737 }
738
ChangeManaged(wid)739 static void ChangeManaged(wid)
740 Widget wid;
741 {
742 ShellWidget w = (ShellWidget) wid;
743 Widget* childP;
744 int i;
745 XtWidgetGeometry intended , preferred;
746
747 (*SuperClass->composite_class.change_managed)(wid);
748 for (i = w->composite.num_children, childP = w->composite.children;
749 i; i--, childP++) {
750 if (XtIsManaged(*childP)) {
751 XtSetKeyboardFocus(wid, *childP);
752 break;
753 }
754 }
755
756 if (w->composite.num_children)
757 {
758 preferred.request_mode = CWWidth | CWHeight;
759 preferred.width = w->core.width;
760 preferred.height = w->core.height;
761
762 intended.request_mode = CWWidth | CWHeight;
763 intended.width = w->core.width;
764 intended.height = w->core.height;
765
766 XtQueryGeometry(w->composite.children[0] , &intended , &preferred);
767
768 if (!preferred.width) preferred.width = 30;
769 if (!preferred.height) preferred.height = 30;
770
771 XtResizeWidget(wid , preferred.width , preferred.height , w->core.border_width);
772 }
773 }
774
QueryGeometry(w,intended,preferred)775 static XtGeometryResult QueryGeometry(w, intended , preferred)
776 Widget w;
777 XtWidgetGeometry *intended;
778 XtWidgetGeometry *preferred;
779 {
780 ShellWidget cw = (ShellWidget)w;
781
782 if (cw->composite.num_children)
783 {
784 XtQueryGeometry(cw->composite.children[0] , intended , preferred);
785 }
786 return XtGeometryAlmost;
787 }
788
_InitializeWidgetSet()789 void _InitializeWidgetSet ()
790 {
791 static int firsttime = 1;
792
793 if (firsttime) {
794 firsttime = 0;
795 XtInitializeWidgetClass (vendorShellWidgetClass);
796 }
797 }
798 /***************************************************************************/
799 /* This code is part of X-toolkit widget library called Nws */
800 /* Copyright (c) 1997,1998,1999 Ondrejicka Stefan */
801 /* (ondrej@idata.sk) */
802 /* Distributed under GPL 2 or later */
803 /***************************************************************************/
804
805 #include <X11/Intrinsic.h>
806 #include <X11/Xmu/CharSet.h>
807 #include <stdlib.h>
808 #include <ctype.h>
809 #include "MwUtils.h"
810 #include "MwNws.h"
811
cvtStringToBoxType(display,args,num_args,from,to,converter_data)812 Boolean cvtStringToBoxType (display,args,num_args,from,to,converter_data)
813 Display * display;
814 XrmValuePtr args;
815 Cardinal * num_args;
816 XrmValuePtr from;
817 XrmValuePtr to;
818 XtPointer * converter_data;
819 {
820 int a = 0;
821 char c, *t, *s = (char*) from->addr;
822
823 if (*num_args != 0)
824 XtAppErrorMsg(XtDisplayToApplicationContext(display),
825 "cvtStringToBoxType", "wrongParameters",
826 "XtToolkitError",
827 "String to BoxType conversion needs no arguments",
828 (String*) NULL, (Cardinal*) NULL);
829
830 while (*s) {
831 /* vynechaj medzery */
832 for (; isspace(*s); s++) ;
833 for (t = s; *t && ! isspace(*t); t++) ;
834 c = *t;
835 *t = '\0';
836 if (XmuCompareISOLatin1(s, "no") == 0) a = XtCno_box;
837 else if (XmuCompareISOLatin1(s, "simple") == 0) a = XtCsimple_box;
838 else if (XmuCompareISOLatin1(s, "up") == 0) a = XtCup_box;
839 else if (XmuCompareISOLatin1(s, "down") == 0) a = XtCdown_box;
840 else if (XmuCompareISOLatin1(s, "framein") == 0) a = XtCframein_box;
841 else if (XmuCompareISOLatin1(s, "frameout") == 0) a = XtCframeout_box;
842 else if (XmuCompareISOLatin1(s, "shadow") == 0) a = XtCshadow_box;
843
844 else {
845 XtDisplayStringConversionWarning(display, (char*) from->addr,
846 XtRBox_type);
847 break;
848 }
849 *t = c;
850 s = t;
851 }
852 MwNwsDone(int, a);
853 }
854
cvtBoxTypeToString(display,args,num_args,from,to,converter_data)855 Boolean cvtBoxTypeToString(display,args,num_args,from,to,converter_data)
856 Display * display;
857 XrmValuePtr args;
858 Cardinal * num_args;
859 XrmValuePtr from;
860 XrmValuePtr to;
861 XtPointer * converter_data;
862 {
863 int *a = (int*) from->addr;
864
865 if (*num_args != 0)
866 XtAppErrorMsg(XtDisplayToApplicationContext(display),
867 "cvtBoxTypeToString", "wrongParameters",
868 "XtToolkitError",
869 "BoxType to String conversion needs no arguments",
870 (String*) NULL, (Cardinal*) NULL);
871 switch (*a) {
872 case XtCno_box: MwNwsDone(String, "no");
873 case XtCsimple_box: MwNwsDone(String , "simple");
874 case XtCup_box: MwNwsDone(String, "up");
875 case XtCdown_box: MwNwsDone(String, "down");
876 case XtCframein_box: MwNwsDone(String, "framein");
877 case XtCframeout_box: MwNwsDone(String, "frameout");
878 case XtCshadow_box: MwNwsDone(String , "shadow");
879 default: MwNwsDone(String, "unknown");
880 }
881 }
882
cvtStringToJustify(display,args,num_args,from,to,converter_data)883 Boolean cvtStringToJustify (display,args,num_args,from,to,converter_data)
884 Display * display;
885 XrmValuePtr args;
886 Cardinal * num_args;
887 XrmValuePtr from;
888 XrmValuePtr to;
889 XtPointer * converter_data;
890 {
891 int a = 0;
892 char c, *t, *s = (char*) from->addr;
893
894
895 if (*num_args != 0)
896 XtAppErrorMsg(XtDisplayToApplicationContext(display),
897 "cvtStringToJustify", "wrongParameters",
898 "XtToolkitError",
899 "String to Justify conversion needs no arguments",
900 (String*) NULL, (Cardinal*) NULL);
901
902 while (*s) {
903 /* vynechaj medzery */
904 for (; isspace(*s); s++) ;
905 for (t = s; *t && ! isspace(*t); t++) ;
906 c = *t;
907 *t = '\0';
908 if (XmuCompareISOLatin1(s, "center") == 0) a = XtCcenter;
909 else if (XmuCompareISOLatin1(s, "left") == 0) a = XtCleft;
910 else if (XmuCompareISOLatin1(s, "right") == 0) a = XtCright;
911 else if (XmuCompareISOLatin1(s, "bottom") == 0) a = XtCbottom;
912 else if (XmuCompareISOLatin1(s, "top") == 0) a = XtCtop;
913 else {
914 XtDisplayStringConversionWarning(display, (char*) from->addr,
915 XtRNwsJustify);
916 break;
917 }
918 *t = c;
919 s = t;
920 }
921 MwNwsDone(int, a);
922 }
923
cvtStringToIcon(dpy,args,num_args,from,to,converter_data)924 Boolean cvtStringToIcon(dpy,args,num_args,from,to,converter_data)
925 Display * dpy;
926 XrmValuePtr args;
927 Cardinal * num_args;
928 XrmValuePtr from;
929 XrmValuePtr to;
930 XtPointer * converter_data;
931 {
932 Icon *icon = MwMalloc(sizeof(Icon));
933 char *s = (char*) from->addr;
934 char *name , *t;
935 int status;
936 Cardinal n_arg = 1;
937 unsigned int b_width,depth;
938 int x,y;
939
940 for (; isspace(*s); s++) ;
941 for (t = s; *t && ! isspace(*t); t++) ;
942 *t = '\0';
943 name = s;
944
945 status = XpmReadFileToPixmap(dpy , DefaultRootWindow(dpy) , name ,
946 &icon->pixmap , &icon->shape , NULL);
947
948 switch (status) {
949 case XpmOpenFailed:
950 case XpmFileInvalid:
951 case XpmNoMemory:
952 XtAppWarningMsg
953 (XtDisplayToApplicationContext(dpy),
954 "cvtStringToPixmap", "fileError",
955 "XtToolkitError",
956 "Failed to read pixmap from \"%s\"",
957 &name, &n_arg);
958 break;
959
960 case XpmColorError:
961 case XpmColorFailed:
962 XtAppWarningMsg
963 (XtDisplayToApplicationContext(dpy),
964 "cvtStringToPixmap", "allocColor",
965 "XtToolkitError",
966 "Could not get (all) colors for pixmap \"%s\"",
967 &name, &n_arg);
968 case XpmSuccess:
969 if (icon->pixmap)
970 status=XGetGeometry(dpy , icon->pixmap , &DefaultRootWindow(dpy) ,
971 &x , &y , &icon->width , &icon->height ,
972 &b_width , &depth);
973 else
974 {
975 MwFree(icon);
976 icon = NULL;
977 XtAppWarningMsg
978 (XtDisplayToApplicationContext(dpy),
979 "cvtStringToPixmap", "allocColor",
980 "XtToolkitError",
981 "Could not create pixmap \"%s\"",
982 &name, &n_arg);
983 }
984 MwNwsDone(Icon*,icon);
985 }
986 return False;
987 }
988
cvtStringToCheckType(display,args,num_args,from,to,converter_data)989 Boolean cvtStringToCheckType (display,args,num_args,from,to,converter_data)
990 Display * display;
991 XrmValuePtr args;
992 Cardinal * num_args;
993 XrmValuePtr from;
994 XrmValuePtr to;
995 XtPointer * converter_data;
996 {
997 int a = 0;
998 char c, *t, *s = (char*) from->addr;
999
1000 if (*num_args != 0)
1001 XtAppErrorMsg(XtDisplayToApplicationContext(display),
1002 "cvtStringToCheckType", "wrongParameters",
1003 "XtToolkitError",
1004 "String to CheckType conversion needs no arguments",
1005 (String*) NULL, (Cardinal*) NULL);
1006
1007 while (*s) {
1008 /* vynechaj medzery */
1009 for (; isspace(*s); s++) ;
1010 for (t = s; *t && ! isspace(*t); t++) ;
1011 c = *t;
1012 *t = '\0';
1013 if (XmuCompareISOLatin1(s, "check") == 0) a = XtCcheck;
1014 else if (XmuCompareISOLatin1(s, "rectangle") == 0) a = XtCrectangle;
1015 else if (XmuCompareISOLatin1(s, "diamond") == 0) a = XtCdiamond;
1016 else if (XmuCompareISOLatin1(s, "circle") == 0) a = XtCcircle;
1017 else if (XmuCompareISOLatin1(s, "cross") == 0) a = XtCcross;
1018 else if (XmuCompareISOLatin1(s, "circle2") == 0) a = XtCcircle2;
1019 else {
1020 XtDisplayStringConversionWarning(display, (char*) from->addr,
1021 XtRCheck_type);
1022 break;
1023 }
1024 *t = c;
1025 s = t;
1026 }
1027 MwNwsDone(int, a);
1028 }
1029
cvtStringToObjectType(display,args,num_args,from,to,converter_data)1030 Boolean cvtStringToObjectType (display,args,num_args,from,to,converter_data)
1031 Display * display;
1032 XrmValuePtr args;
1033 Cardinal * num_args;
1034 XrmValuePtr from;
1035 XrmValuePtr to;
1036 XtPointer * converter_data;
1037 {
1038 int a = 0;
1039 char c, *t, *s = (char*) from->addr;
1040
1041 if (*num_args != 0)
1042 XtAppErrorMsg(XtDisplayToApplicationContext(display),
1043 "cvtStringToObjectType", "wrongParameters",
1044 "XtToolkitError",
1045 "String to ObjectType conversion needs no arguments",
1046 (String*) NULL, (Cardinal*) NULL);
1047
1048 while (*s) {
1049 /* vynechaj medzery */
1050 for (; isspace(*s); s++) ;
1051 for (t = s; *t && ! isspace(*t); t++) ;
1052 c = *t;
1053 *t = '\0';
1054 if (XmuCompareISOLatin1(s, "left_arrow") == 0) a = XtCleft_arrow;
1055 else if (XmuCompareISOLatin1(s, "right_arrow") == 0) a = XtCright_arrow;
1056 else if (XmuCompareISOLatin1(s, "top_arrow") == 0) a = XtCtop_arrow;
1057 else if (XmuCompareISOLatin1(s, "bottom_arrow") == 0) a = XtCbottom_arrow;
1058 else {
1059 XtDisplayStringConversionWarning(display, (char*) from->addr,
1060 XtRObject_type);
1061 break;
1062 }
1063 *t = c;
1064 s = t;
1065 }
1066 MwNwsDone(int, a);
1067 }
1068
cvtStringToOrientation(display,args,num_args,from,to,converter_data)1069 Boolean cvtStringToOrientation (display,args,num_args,from,to,converter_data)
1070 Display * display;
1071 XrmValuePtr args;
1072 Cardinal * num_args;
1073 XrmValuePtr from;
1074 XrmValuePtr to;
1075 XtPointer * converter_data;
1076 {
1077 int a = 0;
1078 char c, *t, *s = (char*) from->addr;
1079
1080
1081 if (*num_args != 0)
1082 XtAppErrorMsg(XtDisplayToApplicationContext(display),
1083 "cvtStringToOrientation", "wrongParameters",
1084 "XtToolkitError",
1085 "String to Orientation conversion needs no arguments",
1086 (String*) NULL, (Cardinal*) NULL);
1087
1088 while (*s) {
1089 /* vynechaj medzery */
1090 for (; isspace(*s); s++) ;
1091 for (t = s; *t && ! isspace(*t); t++) ;
1092 c = *t;
1093 *t = '\0';
1094 if (XmuCompareISOLatin1(s, "vertical") == 0) a = XtCvertical;
1095 else if (XmuCompareISOLatin1(s, "horizontal") == 0) a = XtChorizontal;
1096 else {
1097 XtDisplayStringConversionWarning(display, (char*) from->addr,
1098 XtROrientation);
1099 break;
1100 }
1101 *t = c;
1102 s = t;
1103 }
1104 MwNwsDone(int, a);
1105 }
1106
cvtStringToListStruct(display,args,num_args,from,to,converter_data)1107 Boolean cvtStringToListStruct(display,args,num_args,from,to,converter_data)
1108 Display * display;
1109 XrmValuePtr args;
1110 Cardinal * num_args;
1111 XrmValuePtr from;
1112 XrmValuePtr to;
1113 XtPointer * converter_data;
1114 {
1115 ListStruct *list = NULL;
1116 Boolean koniec = 0;
1117 long len , cnt = 0;
1118 char *st , *en , *s = (char*) from->addr;
1119
1120 if (*num_args != 0)
1121 XtAppErrorMsg(XtDisplayToApplicationContext(display),
1122 "cvtStringToListStruct", "wrongParameters",
1123 "XtToolkitError",
1124 "String to ListStruct conversion needs no arguments",
1125 (String*) NULL, (Cardinal*) NULL);
1126
1127 while (!koniec)
1128 {
1129 cnt ++;
1130
1131 st = strchr(s , '\"');
1132 st ++;
1133 en = strchr(st , '\"');
1134 len = en - st;
1135
1136 list = MwRealloc((void *) list , cnt * sizeof(ListStruct));
1137
1138 list[cnt - 1].label = MwMalloc(len + 1);
1139 strncpy(list[cnt - 1].label , st , len);
1140 *(list[cnt - 1].label + len) = '\0';
1141 list[cnt - 1].left_icon = None;
1142 list[cnt - 1].right_icon = None;
1143 list[cnt - 1].related_info = NULL;
1144 list[cnt - 1].index = cnt;
1145
1146 s = en + 1;
1147
1148 koniec = ( strchr(s , '\"') == NULL);
1149 }
1150
1151 MwNwsDone(ListStruct * , list);
1152 }
1153
cvtStringToButtonMode(display,args,num_args,from,to,converter_data)1154 Boolean cvtStringToButtonMode(display,args,num_args,from,to,converter_data)
1155 Display * display;
1156 XrmValuePtr args;
1157 Cardinal * num_args;
1158 XrmValuePtr from;
1159 XrmValuePtr to;
1160 XtPointer * converter_data;
1161 {
1162 int a = 0;
1163 char c, *t, *s = (char*) from->addr;
1164
1165 if (*num_args != 0)
1166 XtAppErrorMsg(XtDisplayToApplicationContext(display),
1167 "cvtStringToButtonMode", "wrongParameters",
1168 "XtToolkitError",
1169 "String to ButtonMode conversion needs no arguments",
1170 (String*) NULL, (Cardinal*) NULL);
1171
1172 while (*s) {
1173 /* vynechaj medzery */
1174 for (; isspace(*s); s++) ;
1175 for (t = s; *t && ! isspace(*t); t++) ;
1176 c = *t;
1177 *t = '\0';
1178 if (XmuCompareISOLatin1(s, "normal") == 0) a = XtCnormalMode;
1179 else if (XmuCompareISOLatin1(s, "cyclic") == 0) a = XtCcyclicMode;
1180 else if (XmuCompareISOLatin1(s, "toggle") == 0) a = XtCtoggleMode;
1181 else {
1182 XtDisplayStringConversionWarning(display, (char*) from->addr,
1183 XtRObject_type);
1184 break;
1185 }
1186 *t = c;
1187 s = t;
1188 }
1189 MwNwsDone(int, a);
1190 }
1191
cvtStringToStringList(display,args,num_args,from,to,converter_data)1192 Boolean cvtStringToStringList(display,args,num_args,from,to,converter_data)
1193 Display * display;
1194 XrmValuePtr args;
1195 Cardinal * num_args;
1196 XrmValuePtr from;
1197 XrmValuePtr to;
1198 XtPointer * converter_data;
1199 {
1200 char **list;
1201 Boolean koniec = 0;
1202 long len , cnt = 0;
1203 char *st , *en , *s = (char*) from->addr;
1204
1205 list = MwMalloc(sizeof(char *));
1206 list[0] = NULL;
1207
1208 if (*num_args != 0)
1209 XtAppErrorMsg(XtDisplayToApplicationContext(display),
1210 "cvtStringToStringList", "wrongParameters",
1211 "XtToolkitError",
1212 "String to StringList conversion needs no arguments",
1213 (String*) NULL, (Cardinal*) NULL);
1214
1215 while (!koniec)
1216 {
1217 cnt ++;
1218
1219 st = strchr(s , '\"');
1220 st ++;
1221 en = strchr(st , '\"');
1222 len = en - st;
1223
1224 list = MwRealloc((void *) list , (cnt + 1) * sizeof(char *));
1225
1226 list[cnt - 1] = MwMalloc(len + 1);
1227 strncpy(list[cnt - 1] , st , len);
1228 *(list[cnt - 1] + len) = '\0';
1229 list[cnt] = NULL;
1230
1231 s = en + 1;
1232
1233 koniec = (strchr(s , '\"') == NULL);
1234 }
1235
1236 MwNwsDone(char ** , list);
1237 }
1238 /***************************************************************************/
1239 /* This code is part of X-toolkit widget library called Nws */
1240 /* Copyright (c) 1997,1998,1999 Ondrejicka Stefan */
1241 /* (ondrej@idata.sk) */
1242 /* Distributed under GPL 2 or later */
1243 /***************************************************************************/
1244
1245 #include <X11/Intrinsic.h>
1246 #include <stdlib.h>
1247 #include <stdio.h>
1248 #include <unistd.h>
1249 #include <ctype.h>
1250 #include <errno.h>
1251
cnt_lines(in_text)1252 int cnt_lines(in_text)
1253 char *in_text;
1254 {
1255 char *p,*s1,*s;
1256 int i=0;
1257
1258 if (in_text)
1259 {
1260 p=s=s1=MwMalloc(strlen(in_text)+1);
1261 strcpy(s,in_text);
1262 for(i=1; ;i++)
1263 {
1264 p=strchr(s,'\n');
1265 if (p==NULL) break;
1266 s=++p;
1267 }
1268 MwFree(s1);
1269 }
1270
1271 return i;
1272 }
1273
max_line_width(in_text,font)1274 int max_line_width(in_text,font)
1275 char *in_text;
1276 XFontStruct *font;
1277 {
1278 char *p,*s1,*s;
1279 int i=0,maxw=0,pom;
1280
1281 if (in_text)
1282 {
1283 p=s=s1=MwMalloc(strlen(in_text)+1);
1284 strcpy(s,in_text);
1285 for(i=1; ;i++)
1286 {
1287 p=strchr(s,'\n');
1288 if (p!=NULL) *p=0;
1289
1290 pom = XTextWidth(font,s,strlen(s));
1291
1292 if (pom > maxw) maxw = pom;
1293 if (p==NULL) break;
1294 s=++p;
1295 }
1296 MwFree(s1);
1297 }
1298 return maxw;
1299 }
1300
get_abs_path(path)1301 char *get_abs_path(path)
1302 char *path;
1303 {
1304 char *p,pom[MAX_PATH_LEN],*tmp,result[MAX_PATH_LEN]="/";
1305
1306
1307
1308 for(p = path; isspace(*p) && *p ; p++);
1309
1310 if (! (*p == '/'))
1311 {
1312 tmp = (char *) getcwd(NULL,MAX_PATH_LEN);
1313 sprintf(pom , "%s/%s" , tmp ,p);
1314 }
1315 else
1316 {
1317 sprintf(pom , "%s" , p);
1318 }
1319
1320 p = strtok(pom , "/");
1321
1322 while(p)
1323 {
1324 if (strcmp(p , "."))
1325 {
1326 if (strcmp(p , ".."))
1327 {
1328 if (result[strlen(result) - 1] != '/') strcat(result , "/");
1329 strcat(result , p);
1330 }
1331 else
1332 {
1333 tmp = strrchr(result , '/');
1334 *(tmp + 1 - (tmp != result) ) = '\0';
1335 }
1336 }
1337 p = strtok(NULL , "/");
1338 }
1339 if (result[strlen(result) - 1] != '/') strcat(result , "/");
1340
1341 tmp = MwMalloc(strlen(result) + 1);
1342 strcpy(tmp , result);
1343
1344 return tmp;
1345 }
1346
x_atoi(str)1347 int x_atoi(str)
1348 char *str;
1349 {
1350 char *__eptr__;
1351 int rv;
1352
1353 rv = strtol(str , (char **) &__eptr__ , 10);
1354 if (*__eptr__ != '\0') errno = ERANGE;
1355 else errno = 0;
1356
1357 return rv;
1358 }
1359