1 | // Copyright (c) 2004 - 2005 Kai Bader <baderk@in.tum.de> |
---|
2 | // |
---|
3 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
4 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
5 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
6 | // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
---|
7 | // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
---|
8 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
---|
9 | |
---|
10 | // CVS REVISION TAG -- $Revision: 3986 $ |
---|
11 | |
---|
12 | #include <Xm/XmAll.h> |
---|
13 | #include "msgbox.hxx" |
---|
14 | #include "xm_defs.hxx" |
---|
15 | #include "dialog.hxx" |
---|
16 | |
---|
17 | |
---|
18 | /**************************************************************************** |
---|
19 | * CALLBACK FUNCTION - CREATS A RETURNVALUE ACCORDING TO THE SELECTED BUTTON |
---|
20 | ****************************************************************************/ |
---|
21 | void OkCancelResponse(Widget, XtPointer client, XtPointer call) |
---|
22 | { |
---|
23 | int *answer= (int *)client; |
---|
24 | XmAnyCallbackStruct *reason= (XmAnyCallbackStruct *)call; |
---|
25 | switch(reason->reason) |
---|
26 | { |
---|
27 | case XmCR_OK: |
---|
28 | *answer= 1; |
---|
29 | break; |
---|
30 | case XmCR_CANCEL: |
---|
31 | *answer= 2; |
---|
32 | break; |
---|
33 | default: |
---|
34 | return; |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | /**************************************************************************** |
---|
40 | * A SIMPLE MESSAGEBOX, ONLY WITH AN OK-BUTTON |
---|
41 | ****************************************************************************/ |
---|
42 | void ShowMessageBox(Widget w, const char *title, const char *text, const char *xpm_path) |
---|
43 | { |
---|
44 | // PREDEFINED VALUES... |
---|
45 | Widget msgBox; |
---|
46 | Arg args[8]; |
---|
47 | int n= 0; |
---|
48 | |
---|
49 | // CREATE X11 TITLE- AND TEXT-STRING |
---|
50 | XmString xm_text= PGT_XmStringCreateLocalized(text); |
---|
51 | XmString xm_title= PGT_XmStringCreateLocalized(title); |
---|
52 | |
---|
53 | // ADD A PIXMAP IF AVAILABLE |
---|
54 | if(xpm_path) |
---|
55 | { |
---|
56 | Pixel fg, bg; |
---|
57 | XtVaGetValues(w, XmNforeground, &fg, XmNbackground, &bg, NULL); |
---|
58 | Pixmap xpm= PGT_LoadPixmap("msg.xpm", XtScreen(w), fg, bg); |
---|
59 | XtSetArg(args[n], XmNsymbolPixmap, xpm); n++; |
---|
60 | } |
---|
61 | |
---|
62 | // SET MESSAGE TEXT |
---|
63 | XtSetArg(args[n], XmNmessageString, xm_text); n++; |
---|
64 | msgBox= XmCreateMessageDialog(w, const_cast<char*>("messageBox"), args, n); |
---|
65 | |
---|
66 | XtUnmanageChild(XmMessageBoxGetChild(msgBox, XmDIALOG_HELP_BUTTON)); |
---|
67 | XtUnmanageChild(XmMessageBoxGetChild(msgBox, XmDIALOG_CANCEL_BUTTON)); |
---|
68 | |
---|
69 | XtVaSetValues(msgBox, XmNdialogTitle, xm_title, NULL); |
---|
70 | |
---|
71 | XtManageChild(msgBox); |
---|
72 | |
---|
73 | // FREE STRINGS |
---|
74 | XmStringFree(xm_text); |
---|
75 | XmStringFree(xm_title); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | /**************************************************************************** |
---|
80 | * A MESSAGEBOX WITH AN OK- AND CANCEL-BUTTON |
---|
81 | ****************************************************************************/ |
---|
82 | int OkCancelDialog(Widget w, const char *title, const char *text, const char *xpm_path) |
---|
83 | { |
---|
84 | // PREDEFINED VALUES... |
---|
85 | int answer= 0; |
---|
86 | Widget dialog; |
---|
87 | Arg args[8]; |
---|
88 | int n= 0; |
---|
89 | XtAppContext context; |
---|
90 | |
---|
91 | // CREATE X11 TITLE- AND TEXT-STRING |
---|
92 | XmString xm_text= XmStringCreateLtoR(const_cast<char*>(text), XmSTRING_DEFAULT_CHARSET); |
---|
93 | XmString xm_title= PGT_XmStringCreateLocalized(title); |
---|
94 | |
---|
95 | // ADD A PIXMAP IF AVAILABLE |
---|
96 | if(xpm_path) |
---|
97 | { |
---|
98 | Pixel fg, bg; |
---|
99 | XtVaGetValues(w, XmNforeground, &fg, XmNbackground, &bg, NULL); |
---|
100 | Pixmap xpm= PGT_LoadPixmap("msg.xpm", XtScreen(w), fg, bg); |
---|
101 | XtSetArg(args[n], XmNsymbolPixmap, xpm); n++; |
---|
102 | } |
---|
103 | |
---|
104 | // SET MESSAGE TEXT AND DIALOG STYLE (MODAL) |
---|
105 | XtSetArg(args[n], XmNmessageString, xm_text); n++; |
---|
106 | XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); n++; |
---|
107 | |
---|
108 | // CREATE QUESTION DIALOG |
---|
109 | dialog = XmCreateQuestionDialog(XtParent(w), const_cast<char*>(text), args, n); |
---|
110 | XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON)); |
---|
111 | XtVaSetValues(dialog, XmNdialogTitle, xm_title, NULL); |
---|
112 | |
---|
113 | // ADD CALLBACK FUNCTION |
---|
114 | XtAddCallback(dialog, XmNokCallback, OkCancelResponse, &answer); |
---|
115 | XtAddCallback(dialog, XmNcancelCallback, OkCancelResponse, &answer); |
---|
116 | XtManageChild(dialog); |
---|
117 | |
---|
118 | context= XtWidgetToApplicationContext(w); |
---|
119 | while (answer == 0 || XtAppPending(context)) |
---|
120 | { |
---|
121 | XtAppProcessEvent (context, XtIMAll); |
---|
122 | } |
---|
123 | |
---|
124 | // FREE STRINGS |
---|
125 | XmStringFree(xm_text); |
---|
126 | XmStringFree(xm_title); |
---|
127 | |
---|
128 | XtDestroyWidget(dialog); |
---|
129 | |
---|
130 | return answer; |
---|
131 | } |
---|