dtcm: Coverity 88353
[oweals/cde.git] / cde / programs / dtwm / WmFeedback.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* 
24  * (c) Copyright 1989, 1990, 1991, 1992, 1993 OPEN SOFTWARE FOUNDATION, INC. 
25  * ALL RIGHTS RESERVED 
26 */ 
27 /* 
28  * Motif Release 1.2.3
29 */
30 /*
31  * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
32
33 /*
34  * Included Files:
35  */
36 #include "WmGlobal.h"
37 #include "WmResNames.h"
38
39 #define MWM_NEED_TIME16
40 #include "WmBitmap.h"
41 #include "WmError.h"
42 #include <Xm/Xm.h>
43 #include <X11/Shell.h>
44 #include <Xm/Label.h>
45 #include <Xm/DialogS.h>
46 #include <Xm/BulletinB.h>
47 #include <Xm/MessageB.h>
48
49 #define MOVE_OUTLINE_WIDTH      2
50 #define FEEDBACK_BEVEL          2
51
52 #define DEFAULT_POSITION_STRING "(0000x0000)"
53
54 #define  CB_HIGHLIGHT_THICKNESS  3
55
56 /*
57  * include extern functions
58  */
59 #include "WmFeedback.h"
60 #include "WmFunction.h"
61 #include "WmGraphics.h"
62 #include "WmPanelP.h"  /* for typedef in WmManage.h */
63 #include "WmManage.h"
64 #include "WmColormap.h"
65 #include "stdio.h"
66
67
68 /*
69  * Global Variables:
70  */
71 static Cursor  waitCursor = (Cursor)0L;
72
73 /* see WmGlobal.h for index defines: */
74
75 #ifndef NO_MESSAGE_CATALOG
76 static char *confirm_mesg[4] = {"Switch to Default Behavior?",
77                                 "Switch to Custom Behavior?",
78                                 "Restart Mwm?",
79                                 "QUIT Mwm?"};
80
81
82 void
83 initMesg(void)
84 {
85
86     char * tmpString;
87
88     /*
89      * catgets returns a pointer to an area that is over written
90      * on each call to catgets.  
91      */
92
93     tmpString = ((char *)GETMESSAGE(22, 12, "Switch to Default Behavior?"));
94     if ((confirm_mesg[0] =
95          (char *)XtMalloc ((unsigned int) (strlen(tmpString) + 1))) == NULL)
96     {
97         Warning (((char *)GETMESSAGE(22, 2, "Insufficient memory for local message string")));
98         confirm_mesg[0] = "Switch to Default Behavior?";
99     }
100     else
101     {
102         strcpy(confirm_mesg[0], tmpString);
103     }
104
105     tmpString = ((char *)GETMESSAGE(22, 13, "Switch to Custom Behavior?"));
106     if ((confirm_mesg[1] =
107          (char *)XtMalloc ((unsigned int) (strlen(tmpString) + 1))) == NULL)
108     {
109         Warning (((char *)GETMESSAGE(22, 2, "Insufficient memory for local message string")));
110         confirm_mesg[1] = "Switch to Custom Behavior?";
111     }
112     else
113     {
114         strcpy(confirm_mesg[1], tmpString);
115     }
116
117     if (MwmBehavior)
118     {
119         tmpString = ((char *)GETMESSAGE(22, 3, "Restart Mwm?"));
120     }
121     else
122     {
123         tmpString = ((char *)GETMESSAGE(22, 10, "Restart Workspace Manager?"));
124     }
125     if ((confirm_mesg[2] =
126          (char *)XtMalloc ((unsigned int) (strlen(tmpString) + 1))) == NULL)
127     {
128         Warning (((char *)GETMESSAGE(22, 5, "Insufficient memory for local message string")));
129         if (MwmBehavior)
130         {
131             confirm_mesg[2] = "Restart Mwm?";
132         }
133         else
134         {
135             confirm_mesg[2] = "Restart Workspace Manager?";
136         }
137     }
138     else
139     {
140         strcpy(confirm_mesg[2], tmpString);
141     }
142
143
144
145     if (MwmBehavior)
146     {
147         tmpString = ((char *)GETMESSAGE(22, 6, "QUIT Mwm?"));
148     }
149     else
150     {
151         if (wmGD.dtLite)
152         {
153             tmpString = ((char *)GETMESSAGE(22, 9, "Log out?"));
154         }
155         else
156         {
157             tmpString = ((char *)GETMESSAGE(22, 11, "QUIT Workspace Manager?"));
158         }
159     }
160     
161     if ((confirm_mesg[3] =
162          (char *)XtMalloc ((unsigned int) (strlen(tmpString) + 1))) == NULL)
163     {
164         Warning (((char *)GETMESSAGE(22, 8, "Insufficient memory for local message string")));
165         if (MwmBehavior)
166         {
167             confirm_mesg[3] = "QUIT Mwm?";
168         }
169         else
170         if (wmGD.dtLite)
171         {
172             confirm_mesg[3] = "Log out?";
173         }
174         else
175         {
176             confirm_mesg[3] = "QUIT Workspace Manager?";
177         }
178     }
179     else
180     {
181         strcpy(confirm_mesg[3], tmpString);
182     }
183
184
185 }
186 #else
187 static char *confirm_mesg[4] = {"Toggle to Default Behavior?",
188                                 "Toggle to Custom Behavior?",
189                                 "Restart Mwm?",
190                                 "QUIT Mwm?"};
191
192 #endif
193 static char *confirm_widget[4] = {"confirmDefaultBehavior",
194                                   "confirmCustomBehavior",
195                                   "confirmRestart",
196                                   "confirmQuit"};
197
198
199 typedef void (*ConfirmFunc)(Boolean);
200 static ConfirmFunc confirm_func[4] = {Do_Set_Behavior,
201                                       Do_Set_Behavior,
202                                       Do_Restart,
203                                       Do_Quit_Mwm};
204
205 \f
206 /*************************************<->*************************************
207  *
208  *  ShowFeedbackWindow(pSD, x, y, width, height, style)
209  *
210  *
211  *  Description:
212  *  -----------
213  *  Pop up the window for moving and sizing feedback
214  *
215  *
216  *  Inputs:
217  *  ------
218  *  pSD         - pointer to screen data
219  *  x           - initial x-value
220  *  y           - initial y-value
221  *  width       - initial width value
222  *  height      - initial height value
223  *  style       - show size, position, or both
224  *  
225  * 
226  *  Outputs:
227  *  -------
228  *
229  *
230  *  Comments:
231  *  --------
232  *************************************<->***********************************/
233 void ShowFeedbackWindow (WmScreenData *pSD, int x, int y, unsigned int width, unsigned int height, unsigned long style)
234 {
235     unsigned long        mask = 0;
236     XSetWindowAttributes win_attribs;
237     XWindowChanges       win_changes;
238     int                  direction, ascent, descent;
239     XCharStruct          xcsLocation;
240     int                  winX, winY;
241     int                  tmpX, tmpY;
242
243     if ( (pSD->fbStyle = style) == FB_OFF)
244         return;
245
246     pSD->fbLastX = x;
247     pSD->fbLastY = y;
248     pSD->fbLastWidth = width;
249     pSD->fbLastHeight = height;
250
251     /*
252      * Derive the size and position of the window from the text extents
253      * Set starting position of each string 
254      */
255     XTextExtents(pSD->feedbackAppearance.font, DEFAULT_POSITION_STRING, 
256                  strlen(DEFAULT_POSITION_STRING), &direction, &ascent, 
257                  &descent, &xcsLocation);
258     
259     pSD->fbWinWidth = xcsLocation.width + 4*FEEDBACK_BEVEL;
260
261     switch (pSD->fbStyle) 
262     {
263         case FB_SIZE:
264             pSD->fbSizeY = 2*FEEDBACK_BEVEL + ascent;
265             pSD->fbWinHeight = (ascent + descent) + 4*FEEDBACK_BEVEL;
266             break;
267
268         case FB_POSITION:
269             pSD->fbLocY = 2*FEEDBACK_BEVEL + ascent;
270             pSD->fbWinHeight = (ascent + descent) + 4*FEEDBACK_BEVEL;
271             break;
272
273         default:
274         case (FB_SIZE | FB_POSITION):
275             pSD->fbLocY = 2*FEEDBACK_BEVEL + ascent;
276             pSD->fbSizeY = pSD->fbLocY + ascent + descent;
277             pSD->fbWinHeight = 2*(ascent + descent) + 4*FEEDBACK_BEVEL;
278             break;
279     }
280
281     if (pSD->feedbackGeometry) /* set by user */
282     {
283         unsigned int junkWidth, junkHeight;
284
285         mask = XParseGeometry(pSD->feedbackGeometry, &tmpX, &tmpY,
286                               &junkWidth, &junkHeight);
287     }
288
289     if (mask & (XValue|YValue))
290     {
291         winX = (mask & XNegative) ? 
292             DisplayWidth(DISPLAY, pSD->screen)  + tmpX - pSD->fbWinWidth : tmpX;
293         winY = (mask & YNegative) ? 
294             DisplayHeight(DISPLAY, pSD->screen) + tmpY -pSD->fbWinHeight : tmpY;
295     }
296     else
297     {
298         winX = (DisplayWidth(DISPLAY, pSD->screen) - pSD->fbWinWidth)/2;
299         winY = (DisplayHeight(DISPLAY, pSD->screen) -pSD->fbWinHeight)/2;
300     }
301
302     /* 
303      * Put new text into the feedback strings
304      */
305     UpdateFeedbackText (pSD, x, y, width, height);
306
307     /*
308      * bevel the window border for a 3-D look
309      */
310     if ( (pSD->fbTop && pSD->fbBottom) ||
311          ((pSD->fbTop = AllocateRList((unsigned)2*FEEDBACK_BEVEL)) &&
312           (pSD->fbBottom = AllocateRList((unsigned)2*FEEDBACK_BEVEL))) )
313     {
314         pSD->fbTop->used = 0;
315         pSD->fbBottom->used = 0;
316         BevelRectangle (pSD->fbTop,
317                         pSD->fbBottom,
318                         0, 0, 
319                         pSD->fbWinWidth, pSD->fbWinHeight,
320                         FEEDBACK_BEVEL, FEEDBACK_BEVEL,
321                         FEEDBACK_BEVEL, FEEDBACK_BEVEL);
322     }
323
324     /*
325      * Create window if not yet created, otherwise fix size and position
326      */
327
328     if (!pSD->feedbackWin)
329     {
330
331         /*
332          * Create the window
333          */
334
335         mask = CWEventMask | CWOverrideRedirect | CWSaveUnder;
336         win_attribs.event_mask = ExposureMask;
337         win_attribs.override_redirect = TRUE;
338         win_attribs.save_under = TRUE;
339
340         /* 
341          * Use background pixmap if one is specified, otherwise set the
342          * appropriate background color. 
343          */
344
345         if (pSD->feedbackAppearance.backgroundPixmap)
346         {
347             mask |= CWBackPixmap;
348             win_attribs.background_pixmap =
349                                 pSD->feedbackAppearance.backgroundPixmap;
350         }
351         else
352         {
353             mask |= CWBackPixel;
354             win_attribs.background_pixel =
355                                 pSD->feedbackAppearance.background;
356         }
357
358         pSD->feedbackWin = XCreateWindow (DISPLAY, pSD->rootWindow, 
359                                           winX, winY,
360                                           pSD->fbWinWidth, 
361                                           pSD->fbWinHeight,
362                                           0, CopyFromParent, 
363                                           InputOutput, CopyFromParent, 
364                                           mask, &win_attribs);
365     }
366     else
367     {
368         win_changes.x = winX;
369         win_changes.y = winY;
370         win_changes.width = pSD->fbWinWidth;
371         win_changes.height = pSD->fbWinHeight;
372         win_changes.stack_mode = Above;
373
374         mask = CWX | CWY | CWWidth | CWHeight | CWStackMode;
375
376         XConfigureWindow(DISPLAY, pSD->feedbackWin, (unsigned int) mask, 
377             &win_changes);
378     }
379
380
381     /*
382      * Make the feedback window visible (map it)
383      */
384
385     if (pSD && pSD->feedbackWin)
386     {
387         /* Make sure the feedback window doesn't get buried */
388         XRaiseWindow(DISPLAY, pSD->feedbackWin);
389         XMapWindow (DISPLAY, pSD->feedbackWin);
390         PaintFeedbackWindow(pSD);
391     }
392
393 } /* END OF FUNCTION ShowFeedbackWindow */
394
395
396 \f
397 /*************************************<->*************************************
398  *
399  *  PaintFeedbackWindow(pSD)
400  *
401  *
402  *  Description:
403  *  -----------
404  *  Repaints the feedback window in response to exposure events
405  *
406  *
407  *  Inputs:
408  *  ------
409  *  pSD         - pointer to screen data
410  * 
411  *  Outputs:
412  *  -------
413  *
414  *
415  *  Comments:
416  *  --------
417  *************************************<->***********************************/
418 void PaintFeedbackWindow (WmScreenData *pSD)
419 {
420     if (pSD->feedbackWin)
421     {
422         /* 
423          * draw beveling 
424          */
425         if (pSD->fbTop && pSD->fbTop->used > 0) 
426         {
427             XFillRectangles (DISPLAY, pSD->feedbackWin, 
428                              pSD->feedbackAppearance.inactiveTopShadowGC,
429                              pSD->fbTop->prect, pSD->fbTop->used);
430         }
431         if (pSD->fbBottom && pSD->fbBottom->used > 0) 
432         {
433             XFillRectangles (DISPLAY, pSD->feedbackWin, 
434                              pSD->feedbackAppearance.inactiveBottomShadowGC,
435                              pSD->fbBottom->prect, 
436                              pSD->fbBottom->used);
437         }
438
439         /*
440          * clear old text 
441          */
442         XClearArea (DISPLAY, pSD->feedbackWin, 
443                     FEEDBACK_BEVEL, FEEDBACK_BEVEL,
444                     pSD->fbWinWidth-2*FEEDBACK_BEVEL, 
445                     pSD->fbWinHeight-2*FEEDBACK_BEVEL,
446                     FALSE);
447
448         /*
449          * put up new text
450          */
451         if (pSD->fbStyle & FB_POSITION) 
452         {
453             WmDrawString (DISPLAY, pSD->feedbackWin, 
454                          pSD->feedbackAppearance.inactiveGC,
455                          pSD->fbLocX, pSD->fbLocY, 
456                          pSD->fbLocation, strlen(pSD->fbLocation));
457         }
458         if (pSD->fbStyle & FB_SIZE) 
459         {
460             WmDrawString (DISPLAY, pSD->feedbackWin, 
461                          pSD->feedbackAppearance.inactiveGC,
462                          pSD->fbSizeX, pSD->fbSizeY, 
463                          pSD->fbSize, strlen(pSD->fbSize));
464         }
465     }
466 }
467
468
469 \f
470 /*************************************<->*************************************
471  *
472  *  HideFeedbackWindow (pSD)
473  *
474  *
475  *  Description:
476  *  -----------
477  *  Hide the feedback window
478  *
479  *
480  *  Inputs:
481  *  ------
482  *  pDS         - pointer to screen data
483  * 
484  *  Outputs:
485  *  -------
486  *
487  *
488  *  Comments:
489  *  --------
490  * 
491  *************************************<->***********************************/
492 void HideFeedbackWindow (WmScreenData *pSD)
493 {
494     if (pSD->feedbackWin)
495     {
496         XUnmapWindow (DISPLAY, pSD->feedbackWin);
497 #ifndef OLD_COLORMAP
498         ForceColormapFocus (ACTIVE_PSD, ACTIVE_PSD->colormapFocus);
499 #endif
500     }
501     pSD->fbStyle = FB_OFF;
502 }
503
504
505
506 \f
507 /*************************************<->*************************************
508  *
509  *  UpdateFeedbackInfo (pSD, x, y, width, height)
510  *
511  *
512  *  Description:
513  *  -----------
514  *  Update the information in the feedback window
515  *
516  *
517  *  Inputs:
518  *  ------
519  *  pSD         - pointer to screen info
520  *  x           - x-value
521  *  y           - y-value
522  *  width       - width value
523  *  height      - height value
524  *
525  * 
526  *  Outputs:
527  *  -------
528  *
529  *
530  *  Comments:
531  *  --------
532  * 
533  *************************************<->***********************************/
534 void UpdateFeedbackInfo (WmScreenData *pSD, int x, int y, unsigned int width, unsigned int height)
535 {
536     /*
537      * Currently the feedback window must always be redrawn to (potentially)
538      * repair damage done by moving the configuration outline.  The feedback
539      * repainting generally only needs to be done when the information
540      * changes or the feedback window is actually overwritten by the
541      * configuration outline.
542      */
543
544 #ifdef NOTDONE
545     /* only update if something changed */
546     if (((pSD->fbStyle & FB_POSITION) &&
547          ((pSD->fbLastX != x) || (pSD->fbLastY != y))) || 
548         ((pSD->fbStyle & FB_SIZE) &&
549          ((pSD->fbLastWidth != width) || (pSD->fbLastHeight != height))))
550 #endif /* NOTDONE */
551     {
552         pSD->fbLastX = x;
553         pSD->fbLastY = y;
554         pSD->fbLastWidth = width;
555         pSD->fbLastHeight = height;
556
557         UpdateFeedbackText (pSD, x, y, width, height);
558
559         PaintFeedbackWindow(pSD);
560     }
561 }
562
563
564
565 \f
566 /*************************************<->*************************************
567  *
568  *  UpdateFeedbackText (pSD, x, y, width, height)
569  *
570  *
571  *  Description:
572  *  -----------
573  *  Update the information in the feedback strings
574  *
575  *
576  *  Inputs:
577  *  ------
578  *  pSD         - pointer to screen data
579  *  x           - x-value
580  *  y           - y-value
581  *  width       - width value
582  *  height      - height value
583  *
584  * 
585  *  Outputs:
586  *  -------
587  *
588  *
589  *  Comments:
590  *  --------
591  * 
592  *************************************<->***********************************/
593 void UpdateFeedbackText (WmScreenData *pSD, int x, int y, unsigned int width, unsigned int height)
594 {
595     int         direction, ascent, descent;
596     XCharStruct xcs;
597
598     if (pSD->fbStyle & FB_POSITION) 
599     {
600         sprintf (pSD->fbLocation, "(%4d,%-4d)", x, y);
601         XTextExtents(pSD->feedbackAppearance.font, pSD->fbLocation,
602                  strlen(pSD->fbLocation), &direction, &ascent, 
603                  &descent, &xcs);
604         pSD->fbLocX = (pSD->fbWinWidth - xcs.width)/2;
605     }
606
607     if (pSD->fbStyle & FB_SIZE) 
608     {
609         sprintf (pSD->fbSize,     "%4dx%-4d", width, height);
610         XTextExtents(pSD->feedbackAppearance.font, pSD->fbSize,
611                  strlen(pSD->fbSize), &direction, &ascent, 
612                  &descent, &xcs);
613         pSD->fbSizeX = (pSD->fbWinWidth - xcs.width)/2;
614     }
615 }
616
617
618 \f
619 /*************************************<->*************************************
620  *
621  *  static void
622  *  OkCB (w, client_data, call_data)
623  *
624  *
625  *  Description:
626  *  -----------
627  *  QuestionBox Ok callback.
628  *
629  *
630  *  Inputs:
631  *  ------
632  *  None.
633  *
634  * 
635  *  Outputs:
636  *  -------
637  *  None.
638  *
639  *
640  *  Comments:
641  *  --------
642  *  None.
643  * 
644  *************************************<->***********************************/
645
646 static void OkCB (Widget w, caddr_t client_data, caddr_t call_data)
647 {
648     WithdrawDialog (w);
649
650     confirm_func[((WmScreenData *)client_data)->actionNbr] (False);
651
652     wmGD.confirmDialogMapped = False;
653
654 } /* END OF FUNCTION OkCB */
655
656 \f
657 /*************************************<->*************************************
658  *
659  *  static void
660  *  CancelCB (w, client_data, call_data)
661  *
662  *
663  *  Description:
664  *  -----------
665  *  QuestionBox Cancel callback.
666  *
667  *
668  *  Inputs:
669  *  ------
670  *  None.
671  *
672  * 
673  *  Outputs:
674  *  -------
675  *  None.
676  *
677  *
678  *  Comments:
679  *  --------
680  *  None.
681  * 
682  *************************************<->***********************************/
683
684 static void CancelCB (Widget w, caddr_t client_data, caddr_t call_data)
685 {
686     WithdrawDialog (w);
687
688     wmGD.confirmDialogMapped = False;
689
690 } /* END OF FUNCTION CancelCB */
691
692
693 \f
694 /*************************************<->*************************************
695  *
696  *  void
697  *  ConfirmAction (pSD,nbr)
698  *
699  *
700  *  Description:
701  *  -----------
702  *  Post a QuestionBox and ask for confirmation.  If so, executes the
703  *  appropriate action.
704  *
705  *
706  *  Inputs:
707  *  ------
708  *  nbr = action number
709  *  pSD->screen
710  *  pSD->screenTopLevel
711  *
712  * 
713  *  Outputs:
714  *  -------
715  *  actionNbr = current QuestionBox widget index.
716  *  confirmW[actionNbr]  = QuestionBox widget.
717  *
718  *
719  *  Comments:
720  *  --------
721  * 
722  *************************************<->***********************************/
723
724 void ConfirmAction (WmScreenData *pSD, int nbr)
725 {
726     Arg           args[8];
727     int  n;
728     int           x, y;
729     Dimension     width, height;
730     Widget        dialogShellW = NULL;
731     XmString      messageString;
732     static XmString       defaultMessageString = NULL;
733
734
735     /*
736      * If there is a system modal window, don't post another
737      * one.  We need to think about a way to let a new system
738      * modal window be posted, and when unposted, restore the
739      * modal state of the current system modal window.  
740      */
741
742     if(wmGD.systemModalActive)
743     {
744         return ;
745     }
746
747     if (pSD->confirmboxW[nbr] == NULL)
748     /* First time for this one */
749     {
750 #ifndef NO_MESSAGE_CATALOG
751         /*
752          * Initialize messages
753          */
754         initMesg();
755 #endif
756
757         /* 
758          * Create a dialog popup shell with explicit keyboard policy.
759          */
760
761         n = 0;
762         XtSetArg(args[n], XmNx, (XtArgVal)
763                  (DisplayWidth (DISPLAY, pSD->screen)/2)); n++;
764         XtSetArg(args[n], XmNy, (XtArgVal)
765                  (DisplayHeight (DISPLAY, pSD->screen)/2)); n++;
766         XtSetArg(args[n], XtNallowShellResize, (XtArgVal) TRUE);  n++;
767         XtSetArg(args[n], XtNkeyboardFocusPolicy, (XtArgVal) XmEXPLICIT);  n++;
768         XtSetArg(args[n], XtNdepth, 
769                 (XtArgVal) DefaultDepth(DISPLAY, pSD->screen));  n++;
770         XtSetArg(args[n], XtNscreen, 
771                 (XtArgVal) ScreenOfDisplay(DISPLAY, pSD->screen));  n++;
772
773         dialogShellW =
774                 XtCreatePopupShell ((String) WmNfeedback, 
775                                     transientShellWidgetClass,
776                                     pSD->screenTopLevelW, args, n);
777
778         /* 
779          * Create a QuestionBox as a child of the popup shell.
780          * Set traversalOn and add callbacks for the OK and CANCEL buttons.
781          * Unmanage the HELP button.
782          */
783
784         n = 0;
785         XtSetArg(args[n], XmNdialogType, (XtArgVal) XmDIALOG_QUESTION); n++;
786         XtSetArg(args[n], XmNmessageAlignment, (XtArgVal) XmALIGNMENT_CENTER);
787            n++;
788         XtSetArg(args[n], XmNtraversalOn, (XtArgVal) TRUE); n++;
789
790         /*
791          * In 1.2 confirmbox's widget name changed from the generic
792          * WmNconfirmbox (ie. 'confirmbox') to a more descriptive name
793          * so that each confirm dialog can be customized separately (e.g.
794          * "Mwm*confirmRestart*messageString: restart it?").
795          */
796
797         pSD->confirmboxW[nbr] = 
798             XtCreateManagedWidget (confirm_widget[nbr], xmMessageBoxWidgetClass,
799                                    dialogShellW, args, n);
800
801         n = 0;
802         XtSetArg(args[n], XmNmessageString, &messageString); n++;
803         XtGetValues(pSD->confirmboxW[nbr], (ArgList) args, n);
804
805         if (defaultMessageString == NULL)
806         {
807             defaultMessageString = XmStringCreateLocalized ("");
808         }
809
810         n = 0;
811
812         /*
813          * If the message string is the default, then put something
814          * 'reasonable' in instead.
815          */
816
817         if (XmStringCompare( messageString, defaultMessageString ))
818         {
819             messageString = XmStringCreateLocalized(confirm_mesg[nbr]);
820             XtSetArg(args[n], XmNmessageString, (XtArgVal) messageString); n++;
821             XtSetValues(pSD->confirmboxW[nbr], (ArgList) args, n);
822             XmStringFree(messageString);
823         }
824
825         n = 0;
826         XtSetArg (args[n], XmNtraversalOn, (XtArgVal) TRUE); n++;
827         XtSetArg (args[n], XmNhighlightThickness, 
828                   (XtArgVal) CB_HIGHLIGHT_THICKNESS); n++;
829 #ifndef NO_MESSAGE_CATALOG
830         XtSetArg(args[n], XmNlabelString, wmGD.okLabel); n++;
831 #endif
832         XtSetValues ( XmMessageBoxGetChild (pSD->confirmboxW[nbr], 
833                             XmDIALOG_OK_BUTTON), args, n);
834 #ifndef NO_MESSAGE_CATALOG
835         n--;
836         XtSetArg(args[n], XmNlabelString, wmGD.cancelLabel); n++;
837 #endif
838         XtSetValues ( XmMessageBoxGetChild (pSD->confirmboxW[nbr], 
839                             XmDIALOG_CANCEL_BUTTON), args, n);
840         XtAddCallback (pSD->confirmboxW[nbr], XmNokCallback, 
841             (XtCallbackProc)OkCB, (XtPointer)pSD); 
842         XtAddCallback (pSD->confirmboxW[nbr], XmNcancelCallback, 
843             (XtCallbackProc)CancelCB, (XtPointer)NULL); 
844
845         XtUnmanageChild
846             (XmMessageBoxGetChild (pSD->confirmboxW[nbr], 
847                 XmDIALOG_HELP_BUTTON));
848
849         XtRealizeWidget (dialogShellW);
850
851         /* 
852          * Center the DialogShell in the display.
853          */
854
855         n = 0;
856         XtSetArg(args[n], XmNheight, &height); n++;
857         XtSetArg(args[n], XmNwidth, &width); n++;
858         XtGetValues (dialogShellW, (ArgList) args, n);
859
860         x = (DisplayWidth (DISPLAY, pSD->screen) - ((int) width))/2;
861         y = (DisplayHeight (DISPLAY, pSD->screen) - ((int) height))/2;
862         n = 0;
863         XtSetArg(args[n], XmNx, (XtArgVal) x); n++;
864         XtSetArg(args[n], XmNy, (XtArgVal) y); n++;
865         XtSetValues (dialogShellW, (ArgList) args, n);
866
867         ManageWindow (pSD, XtWindow(dialogShellW), MANAGEW_CONFIRM_BOX);
868     }
869     else
870     {
871         ReManageDialog (pSD, pSD->confirmboxW[nbr]);
872     }
873
874     pSD->actionNbr = nbr;
875
876     XFlush(DISPLAY);
877
878     wmGD.confirmDialogMapped = True;
879
880 } /* END OF FUNCTION ConfirmAction */
881
882
883 \f
884 /*************************************<->*************************************
885  *
886  *  ShowWaitState (flag)
887  *
888  *
889  *  Description:
890  *  -----------
891  *  Enter/Leave the wait state.
892  *
893  *
894  *  Inputs:
895  *  ------
896  *  flag = TRUE for Enter, FALSE for Leave.
897  *
898  * 
899  *  Outputs:
900  *  -------
901  *  None.
902  *
903  *
904  *  Comments:
905  *  --------
906  *  None.
907  * 
908  *************************************<->***********************************/
909
910 void ShowWaitState (Boolean flag)
911 {
912     char        *bits;
913     char        *maskBits;
914     unsigned int width;
915     unsigned int height;
916     unsigned int xHotspot;
917     unsigned int yHotspot;
918     Pixmap       pixmap;
919     Pixmap       maskPixmap;
920     XColor       xcolors[2];
921
922     if (!waitCursor)
923     {
924 #ifdef LARGECURSORS
925         if (wmGD.useLargeCursors)
926         {
927             width = time32_width;
928             height = time32_height;
929             bits = (char *)time32_bits;
930             maskBits = (char *)time32m_bits;
931             xHotspot = time32_x_hot;
932             yHotspot = time32_y_hot;
933         }
934         else
935 #endif /* LARGECURSORS */
936
937         {
938             width = time16_width;
939             height = time16_height;
940             bits = (char *)time16_bits;
941             maskBits = (char *)time16m_bits;
942             xHotspot = time16_x_hot;
943             yHotspot = time16_y_hot;
944         }
945
946         pixmap = XCreateBitmapFromData (DISPLAY, 
947                          DefaultRootWindow(DISPLAY), bits, 
948                          width, height);
949
950         maskPixmap = XCreateBitmapFromData (DISPLAY, 
951                          DefaultRootWindow(DISPLAY), maskBits, 
952                          width, height);
953 #ifdef INTEGRATION_TESTING_
954         xcolors[1].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(DISPLAY));
955         xcolors[0].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(DISPLAY));
956 #else /* INTEGRATION_TESTING */
957
958         xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(DISPLAY));
959         xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(DISPLAY));
960
961 #endif /* INTEGRATION_TESTING */
962         XQueryColors (DISPLAY, 
963                       DefaultColormapOfScreen(DefaultScreenOfDisplay
964                                               (DISPLAY)), 
965                       xcolors, 2);
966         waitCursor = XCreatePixmapCursor (DISPLAY, pixmap, maskPixmap,
967                                           &(xcolors[0]), &(xcolors[1]),
968                                           xHotspot, yHotspot);
969         XFreePixmap (DISPLAY, pixmap);
970         XFreePixmap (DISPLAY, maskPixmap);
971     }
972
973     if (flag)
974     {
975         XGrabPointer (DISPLAY, DefaultRootWindow(DISPLAY), FALSE, 
976                         0, GrabModeAsync, GrabModeAsync, None, 
977                         waitCursor, CurrentTime);
978         XGrabKeyboard (DISPLAY, DefaultRootWindow(DISPLAY), FALSE, 
979                         GrabModeAsync, GrabModeAsync, CurrentTime);
980     }
981     else
982     {
983         XUngrabPointer (DISPLAY, CurrentTime);
984         XUngrabKeyboard (DISPLAY, CurrentTime);
985     }
986
987 } /* END OF FUNCTION ShowWaitState */
988
989
990 \f
991 /*************************************<->*************************************
992  *
993  *  InitCursorInfo ()
994  *
995  *
996  *  Description:
997  *  -----------
998  *  This function determines whether a server supports large cursors.  It it
999  *  does large feedback cursors are used in some cases (wait state and
1000  *  system modal state); otherwise smaller (16x16) standard cursors are used.
1001  *
1002  *  Outputs:
1003  *  -------
1004  *  wmGD.useLargeCusors = set to True if larger cursors are supported.
1005  * 
1006  *************************************<->***********************************/
1007
1008 void InitCursorInfo (void)
1009 {
1010     unsigned int cWidth;
1011     unsigned int cHeight;
1012
1013     wmGD.useLargeCursors = False;
1014
1015     if (XQueryBestCursor (DISPLAY, DefaultRootWindow(DISPLAY), 
1016         32, 32, &cWidth, &cHeight))
1017     {
1018         if ((cWidth >= 32) && (cHeight >= 32))
1019         {
1020             wmGD.useLargeCursors = True;
1021         }
1022     }
1023
1024 } /* END OF FUNCTION InitCursorInfo */
1025
1026
1027
1028
1029
1030