2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
24 * (c) Copyright 1989, 1990, 1991, 1992, 1993 OPEN SOFTWARE FOUNDATION, INC.
31 * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
37 #include "WmResNames.h"
39 #define MWM_NEED_TIME16
43 #include <X11/Shell.h>
45 #include <Xm/DialogS.h>
46 #include <Xm/BulletinB.h>
47 #include <Xm/MessageB.h>
49 #define MOVE_OUTLINE_WIDTH 2
50 #define FEEDBACK_BEVEL 2
52 #define DEFAULT_POSITION_STRING "(0000x0000)"
54 #define CB_HIGHLIGHT_THICKNESS 3
57 * include extern functions
59 #include "WmFeedback.h"
60 #include "WmFunction.h"
61 #include "WmGraphics.h"
62 #include "WmPanelP.h" /* for typedef in WmManage.h */
64 #include "WmColormap.h"
71 static Cursor waitCursor = (Cursor)0L;
73 /* see WmGlobal.h for index defines: */
75 #ifndef NO_MESSAGE_CATALOG
76 static char *confirm_mesg[4] = {"Switch to Default Behavior?",
77 "Switch to Custom Behavior?",
89 * catgets returns a pointer to an area that is over written
90 * on each call to catgets.
93 tmpString = ((char *)GETMESSAGE(22, 12, "Switch to Default Behavior?"));
94 if ((confirm_mesg[0] =
95 (char *)XtMalloc ((unsigned int) (strlen(tmpString) + 1))) == NULL)
97 Warning (((char *)GETMESSAGE(22, 2, "Insufficient memory for local message string")));
98 confirm_mesg[0] = "Switch to Default Behavior?";
102 strcpy(confirm_mesg[0], tmpString);
105 tmpString = ((char *)GETMESSAGE(22, 13, "Switch to Custom Behavior?"));
106 if ((confirm_mesg[1] =
107 (char *)XtMalloc ((unsigned int) (strlen(tmpString) + 1))) == NULL)
109 Warning (((char *)GETMESSAGE(22, 2, "Insufficient memory for local message string")));
110 confirm_mesg[1] = "Switch to Custom Behavior?";
114 strcpy(confirm_mesg[1], tmpString);
119 tmpString = ((char *)GETMESSAGE(22, 3, "Restart Mwm?"));
123 tmpString = ((char *)GETMESSAGE(22, 10, "Restart Workspace Manager?"));
125 if ((confirm_mesg[2] =
126 (char *)XtMalloc ((unsigned int) (strlen(tmpString) + 1))) == NULL)
128 Warning (((char *)GETMESSAGE(22, 5, "Insufficient memory for local message string")));
131 confirm_mesg[2] = "Restart Mwm?";
135 confirm_mesg[2] = "Restart Workspace Manager?";
140 strcpy(confirm_mesg[2], tmpString);
147 tmpString = ((char *)GETMESSAGE(22, 6, "QUIT Mwm?"));
153 tmpString = ((char *)GETMESSAGE(22, 9, "Log out?"));
157 tmpString = ((char *)GETMESSAGE(22, 11, "QUIT Workspace Manager?"));
161 if ((confirm_mesg[3] =
162 (char *)XtMalloc ((unsigned int) (strlen(tmpString) + 1))) == NULL)
164 Warning (((char *)GETMESSAGE(22, 8, "Insufficient memory for local message string")));
167 confirm_mesg[3] = "QUIT Mwm?";
172 confirm_mesg[3] = "Log out?";
176 confirm_mesg[3] = "QUIT Workspace Manager?";
181 strcpy(confirm_mesg[3], tmpString);
187 static char *confirm_mesg[4] = {"Toggle to Default Behavior?",
188 "Toggle to Custom Behavior?",
193 static char *confirm_widget[4] = {"confirmDefaultBehavior",
194 "confirmCustomBehavior",
199 typedef void (*ConfirmFunc)(Boolean);
200 static ConfirmFunc confirm_func[4] = {Do_Set_Behavior,
206 /*************************************<->*************************************
208 * ShowFeedbackWindow(pSD, x, y, width, height, style)
213 * Pop up the window for moving and sizing feedback
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
232 *************************************<->***********************************/
233 void ShowFeedbackWindow (WmScreenData *pSD, int x, int y, unsigned int width, unsigned int height, unsigned long style)
235 unsigned long mask = 0;
236 XSetWindowAttributes win_attribs;
237 XWindowChanges win_changes;
238 int direction, ascent, descent;
239 XCharStruct xcsLocation;
243 if ( (pSD->fbStyle = style) == FB_OFF)
248 pSD->fbLastWidth = width;
249 pSD->fbLastHeight = height;
252 * Derive the size and position of the window from the text extents
253 * Set starting position of each string
255 XTextExtents(pSD->feedbackAppearance.font, DEFAULT_POSITION_STRING,
256 strlen(DEFAULT_POSITION_STRING), &direction, &ascent,
257 &descent, &xcsLocation);
259 pSD->fbWinWidth = xcsLocation.width + 4*FEEDBACK_BEVEL;
261 switch (pSD->fbStyle)
264 pSD->fbSizeY = 2*FEEDBACK_BEVEL + ascent;
265 pSD->fbWinHeight = (ascent + descent) + 4*FEEDBACK_BEVEL;
269 pSD->fbLocY = 2*FEEDBACK_BEVEL + ascent;
270 pSD->fbWinHeight = (ascent + descent) + 4*FEEDBACK_BEVEL;
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;
281 if (pSD->feedbackGeometry) /* set by user */
283 unsigned int junkWidth, junkHeight;
285 mask = XParseGeometry(pSD->feedbackGeometry, &tmpX, &tmpY,
286 &junkWidth, &junkHeight);
289 if (mask & (XValue|YValue))
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;
298 winX = (DisplayWidth(DISPLAY, pSD->screen) - pSD->fbWinWidth)/2;
299 winY = (DisplayHeight(DISPLAY, pSD->screen) -pSD->fbWinHeight)/2;
303 * Put new text into the feedback strings
305 UpdateFeedbackText (pSD, x, y, width, height);
308 * bevel the window border for a 3-D look
310 if ( (pSD->fbTop && pSD->fbBottom) ||
311 ((pSD->fbTop = AllocateRList((unsigned)2*FEEDBACK_BEVEL)) &&
312 (pSD->fbBottom = AllocateRList((unsigned)2*FEEDBACK_BEVEL))) )
314 pSD->fbTop->used = 0;
315 pSD->fbBottom->used = 0;
316 BevelRectangle (pSD->fbTop,
319 pSD->fbWinWidth, pSD->fbWinHeight,
320 FEEDBACK_BEVEL, FEEDBACK_BEVEL,
321 FEEDBACK_BEVEL, FEEDBACK_BEVEL);
325 * Create window if not yet created, otherwise fix size and position
328 if (!pSD->feedbackWin)
335 mask = CWEventMask | CWOverrideRedirect | CWSaveUnder;
336 win_attribs.event_mask = ExposureMask;
337 win_attribs.override_redirect = TRUE;
338 win_attribs.save_under = TRUE;
341 * Use background pixmap if one is specified, otherwise set the
342 * appropriate background color.
345 if (pSD->feedbackAppearance.backgroundPixmap)
347 mask |= CWBackPixmap;
348 win_attribs.background_pixmap =
349 pSD->feedbackAppearance.backgroundPixmap;
354 win_attribs.background_pixel =
355 pSD->feedbackAppearance.background;
358 pSD->feedbackWin = XCreateWindow (DISPLAY, pSD->rootWindow,
363 InputOutput, CopyFromParent,
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;
374 mask = CWX | CWY | CWWidth | CWHeight | CWStackMode;
376 XConfigureWindow(DISPLAY, pSD->feedbackWin, (unsigned int) mask,
382 * Make the feedback window visible (map it)
385 if (pSD && pSD->feedbackWin)
387 /* Make sure the feedback window doesn't get buried */
388 XRaiseWindow(DISPLAY, pSD->feedbackWin);
389 XMapWindow (DISPLAY, pSD->feedbackWin);
390 PaintFeedbackWindow(pSD);
393 } /* END OF FUNCTION ShowFeedbackWindow */
397 /*************************************<->*************************************
399 * PaintFeedbackWindow(pSD)
404 * Repaints the feedback window in response to exposure events
409 * pSD - pointer to screen data
417 *************************************<->***********************************/
418 void PaintFeedbackWindow (WmScreenData *pSD)
420 if (pSD->feedbackWin)
425 if (pSD->fbTop && pSD->fbTop->used > 0)
427 XFillRectangles (DISPLAY, pSD->feedbackWin,
428 pSD->feedbackAppearance.inactiveTopShadowGC,
429 pSD->fbTop->prect, pSD->fbTop->used);
431 if (pSD->fbBottom && pSD->fbBottom->used > 0)
433 XFillRectangles (DISPLAY, pSD->feedbackWin,
434 pSD->feedbackAppearance.inactiveBottomShadowGC,
435 pSD->fbBottom->prect,
436 pSD->fbBottom->used);
442 XClearArea (DISPLAY, pSD->feedbackWin,
443 FEEDBACK_BEVEL, FEEDBACK_BEVEL,
444 pSD->fbWinWidth-2*FEEDBACK_BEVEL,
445 pSD->fbWinHeight-2*FEEDBACK_BEVEL,
451 if (pSD->fbStyle & FB_POSITION)
453 WmDrawString (DISPLAY, pSD->feedbackWin,
454 pSD->feedbackAppearance.inactiveGC,
455 pSD->fbLocX, pSD->fbLocY,
456 pSD->fbLocation, strlen(pSD->fbLocation));
458 if (pSD->fbStyle & FB_SIZE)
460 WmDrawString (DISPLAY, pSD->feedbackWin,
461 pSD->feedbackAppearance.inactiveGC,
462 pSD->fbSizeX, pSD->fbSizeY,
463 pSD->fbSize, strlen(pSD->fbSize));
470 /*************************************<->*************************************
472 * HideFeedbackWindow (pSD)
477 * Hide the feedback window
482 * pDS - pointer to screen data
491 *************************************<->***********************************/
492 void HideFeedbackWindow (WmScreenData *pSD)
494 if (pSD->feedbackWin)
496 XUnmapWindow (DISPLAY, pSD->feedbackWin);
498 ForceColormapFocus (ACTIVE_PSD, ACTIVE_PSD->colormapFocus);
501 pSD->fbStyle = FB_OFF;
507 /*************************************<->*************************************
509 * UpdateFeedbackInfo (pSD, x, y, width, height)
514 * Update the information in the feedback window
519 * pSD - pointer to screen info
522 * width - width value
523 * height - height value
533 *************************************<->***********************************/
534 void UpdateFeedbackInfo (WmScreenData *pSD, int x, int y, unsigned int width, unsigned int height)
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.
546 pSD->fbLastWidth = width;
547 pSD->fbLastHeight = height;
549 UpdateFeedbackText (pSD, x, y, width, height);
551 PaintFeedbackWindow(pSD);
557 /*************************************<->*************************************
559 * UpdateFeedbackText (pSD, x, y, width, height)
564 * Update the information in the feedback strings
569 * pSD - pointer to screen data
572 * width - width value
573 * height - height value
583 *************************************<->***********************************/
584 void UpdateFeedbackText (WmScreenData *pSD, int x, int y, unsigned int width, unsigned int height)
586 int direction, ascent, descent;
589 if (pSD->fbStyle & FB_POSITION)
591 sprintf (pSD->fbLocation, "(%4d,%-4d)", x, y);
592 XTextExtents(pSD->feedbackAppearance.font, pSD->fbLocation,
593 strlen(pSD->fbLocation), &direction, &ascent,
595 pSD->fbLocX = (pSD->fbWinWidth - xcs.width)/2;
598 if (pSD->fbStyle & FB_SIZE)
600 sprintf (pSD->fbSize, "%4dx%-4d", width, height);
601 XTextExtents(pSD->feedbackAppearance.font, pSD->fbSize,
602 strlen(pSD->fbSize), &direction, &ascent,
604 pSD->fbSizeX = (pSD->fbWinWidth - xcs.width)/2;
610 /*************************************<->*************************************
613 * OkCB (w, client_data, call_data)
618 * QuestionBox Ok callback.
635 *************************************<->***********************************/
637 static void OkCB (Widget w, caddr_t client_data, caddr_t call_data)
641 confirm_func[((WmScreenData *)client_data)->actionNbr] (False);
643 wmGD.confirmDialogMapped = False;
645 } /* END OF FUNCTION OkCB */
648 /*************************************<->*************************************
651 * CancelCB (w, client_data, call_data)
656 * QuestionBox Cancel callback.
673 *************************************<->***********************************/
675 static void CancelCB (Widget w, caddr_t client_data, caddr_t call_data)
679 wmGD.confirmDialogMapped = False;
681 } /* END OF FUNCTION CancelCB */
685 /*************************************<->*************************************
688 * ConfirmAction (pSD,nbr)
693 * Post a QuestionBox and ask for confirmation. If so, executes the
694 * appropriate action.
699 * nbr = action number
701 * pSD->screenTopLevel
706 * actionNbr = current QuestionBox widget index.
707 * confirmW[actionNbr] = QuestionBox widget.
713 *************************************<->***********************************/
715 void ConfirmAction (WmScreenData *pSD, int nbr)
720 Dimension width, height;
721 Widget dialogShellW = NULL;
722 XmString messageString;
723 static XmString defaultMessageString = NULL;
727 * If there is a system modal window, don't post another
728 * one. We need to think about a way to let a new system
729 * modal window be posted, and when unposted, restore the
730 * modal state of the current system modal window.
733 if(wmGD.systemModalActive)
738 if (pSD->confirmboxW[nbr] == NULL)
739 /* First time for this one */
741 #ifndef NO_MESSAGE_CATALOG
743 * Initialize messages
749 * Create a dialog popup shell with explicit keyboard policy.
753 XtSetArg(args[n], XmNx, (XtArgVal)
754 (DisplayWidth (DISPLAY, pSD->screen)/2)); n++;
755 XtSetArg(args[n], XmNy, (XtArgVal)
756 (DisplayHeight (DISPLAY, pSD->screen)/2)); n++;
757 XtSetArg(args[n], XtNallowShellResize, (XtArgVal) TRUE); n++;
758 XtSetArg(args[n], XtNkeyboardFocusPolicy, (XtArgVal) XmEXPLICIT); n++;
759 XtSetArg(args[n], XtNdepth,
760 (XtArgVal) DefaultDepth(DISPLAY, pSD->screen)); n++;
761 XtSetArg(args[n], XtNscreen,
762 (XtArgVal) ScreenOfDisplay(DISPLAY, pSD->screen)); n++;
765 XtCreatePopupShell ((String) WmNfeedback,
766 transientShellWidgetClass,
767 pSD->screenTopLevelW, args, n);
770 * Create a QuestionBox as a child of the popup shell.
771 * Set traversalOn and add callbacks for the OK and CANCEL buttons.
772 * Unmanage the HELP button.
776 XtSetArg(args[n], XmNdialogType, (XtArgVal) XmDIALOG_QUESTION); n++;
777 XtSetArg(args[n], XmNmessageAlignment, (XtArgVal) XmALIGNMENT_CENTER);
779 XtSetArg(args[n], XmNtraversalOn, (XtArgVal) TRUE); n++;
782 * In 1.2 confirmbox's widget name changed from the generic
783 * WmNconfirmbox (ie. 'confirmbox') to a more descriptive name
784 * so that each confirm dialog can be customized separately (e.g.
785 * "Mwm*confirmRestart*messageString: restart it?").
788 pSD->confirmboxW[nbr] =
789 XtCreateManagedWidget (confirm_widget[nbr], xmMessageBoxWidgetClass,
790 dialogShellW, args, n);
793 XtSetArg(args[n], XmNmessageString, &messageString); n++;
794 XtGetValues(pSD->confirmboxW[nbr], (ArgList) args, n);
796 if (defaultMessageString == NULL)
798 defaultMessageString = XmStringCreateLocalized ("");
804 * If the message string is the default, then put something
805 * 'reasonable' in instead.
808 if (XmStringCompare( messageString, defaultMessageString ))
810 messageString = XmStringCreateLocalized(confirm_mesg[nbr]);
811 XtSetArg(args[n], XmNmessageString, (XtArgVal) messageString); n++;
812 XtSetValues(pSD->confirmboxW[nbr], (ArgList) args, n);
813 XmStringFree(messageString);
817 XtSetArg (args[n], XmNtraversalOn, (XtArgVal) TRUE); n++;
818 XtSetArg (args[n], XmNhighlightThickness,
819 (XtArgVal) CB_HIGHLIGHT_THICKNESS); n++;
820 #ifndef NO_MESSAGE_CATALOG
821 XtSetArg(args[n], XmNlabelString, wmGD.okLabel); n++;
823 XtSetValues ( XmMessageBoxGetChild (pSD->confirmboxW[nbr],
824 XmDIALOG_OK_BUTTON), args, n);
825 #ifndef NO_MESSAGE_CATALOG
827 XtSetArg(args[n], XmNlabelString, wmGD.cancelLabel); n++;
829 XtSetValues ( XmMessageBoxGetChild (pSD->confirmboxW[nbr],
830 XmDIALOG_CANCEL_BUTTON), args, n);
831 XtAddCallback (pSD->confirmboxW[nbr], XmNokCallback,
832 (XtCallbackProc)OkCB, (XtPointer)pSD);
833 XtAddCallback (pSD->confirmboxW[nbr], XmNcancelCallback,
834 (XtCallbackProc)CancelCB, (XtPointer)NULL);
837 (XmMessageBoxGetChild (pSD->confirmboxW[nbr],
838 XmDIALOG_HELP_BUTTON));
840 XtRealizeWidget (dialogShellW);
843 * Center the DialogShell in the display.
847 XtSetArg(args[n], XmNheight, &height); n++;
848 XtSetArg(args[n], XmNwidth, &width); n++;
849 XtGetValues (dialogShellW, (ArgList) args, n);
851 x = (DisplayWidth (DISPLAY, pSD->screen) - ((int) width))/2;
852 y = (DisplayHeight (DISPLAY, pSD->screen) - ((int) height))/2;
854 XtSetArg(args[n], XmNx, (XtArgVal) x); n++;
855 XtSetArg(args[n], XmNy, (XtArgVal) y); n++;
856 XtSetValues (dialogShellW, (ArgList) args, n);
858 ManageWindow (pSD, XtWindow(dialogShellW), MANAGEW_CONFIRM_BOX);
862 ReManageDialog (pSD, pSD->confirmboxW[nbr]);
865 pSD->actionNbr = nbr;
869 wmGD.confirmDialogMapped = True;
871 } /* END OF FUNCTION ConfirmAction */
875 /*************************************<->*************************************
877 * ShowWaitState (flag)
882 * Enter/Leave the wait state.
887 * flag = TRUE for Enter, FALSE for Leave.
899 *************************************<->***********************************/
901 void ShowWaitState (Boolean flag)
907 unsigned int xHotspot;
908 unsigned int yHotspot;
916 if (wmGD.useLargeCursors)
918 width = time32_width;
919 height = time32_height;
920 bits = (char *)time32_bits;
921 maskBits = (char *)time32m_bits;
922 xHotspot = time32_x_hot;
923 yHotspot = time32_y_hot;
926 #endif /* LARGECURSORS */
929 width = time16_width;
930 height = time16_height;
931 bits = (char *)time16_bits;
932 maskBits = (char *)time16m_bits;
933 xHotspot = time16_x_hot;
934 yHotspot = time16_y_hot;
937 pixmap = XCreateBitmapFromData (DISPLAY,
938 DefaultRootWindow(DISPLAY), bits,
941 maskPixmap = XCreateBitmapFromData (DISPLAY,
942 DefaultRootWindow(DISPLAY), maskBits,
944 #ifdef INTEGRATION_TESTING_
945 xcolors[1].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(DISPLAY));
946 xcolors[0].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(DISPLAY));
947 #else /* INTEGRATION_TESTING */
949 xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(DISPLAY));
950 xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(DISPLAY));
952 #endif /* INTEGRATION_TESTING */
953 XQueryColors (DISPLAY,
954 DefaultColormapOfScreen(DefaultScreenOfDisplay
957 waitCursor = XCreatePixmapCursor (DISPLAY, pixmap, maskPixmap,
958 &(xcolors[0]), &(xcolors[1]),
960 XFreePixmap (DISPLAY, pixmap);
961 XFreePixmap (DISPLAY, maskPixmap);
966 XGrabPointer (DISPLAY, DefaultRootWindow(DISPLAY), FALSE,
967 0, GrabModeAsync, GrabModeAsync, None,
968 waitCursor, CurrentTime);
969 XGrabKeyboard (DISPLAY, DefaultRootWindow(DISPLAY), FALSE,
970 GrabModeAsync, GrabModeAsync, CurrentTime);
974 XUngrabPointer (DISPLAY, CurrentTime);
975 XUngrabKeyboard (DISPLAY, CurrentTime);
978 } /* END OF FUNCTION ShowWaitState */
982 /*************************************<->*************************************
989 * This function determines whether a server supports large cursors. It it
990 * does large feedback cursors are used in some cases (wait state and
991 * system modal state); otherwise smaller (16x16) standard cursors are used.
995 * wmGD.useLargeCusors = set to True if larger cursors are supported.
997 *************************************<->***********************************/
999 void InitCursorInfo (void)
1001 unsigned int cWidth;
1002 unsigned int cHeight;
1004 wmGD.useLargeCursors = False;
1006 if (XQueryBestCursor (DISPLAY, DefaultRootWindow(DISPLAY),
1007 32, 32, &cWidth, &cHeight))
1009 if ((cWidth >= 32) && (cHeight >= 32))
1011 wmGD.useLargeCursors = True;
1015 } /* END OF FUNCTION InitCursorInfo */