File: common.C

package info (click to toggle)
xshisen 1:1.51-4.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,124 kB
  • sloc: cpp: 4,007; sh: 152; perl: 146; makefile: 114
file content (102 lines) | stat: -rw-r--r-- 4,417 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "components.h"

void
PopDownCB(Widget w, XtPointer client_data)
{
#if USE_MOTIF
    XtUnmanageChild(w);
#else /* USE_MOTIF */
    Widget shell = (Widget)client_data;
    XtPopdown(shell);
#endif /* USE_MOTIF */
}

void
Message(Pixmap symbol, const char *message, int timeout,
        XtTimerCallbackProc timeout_proc, XtCallbackProc additional_callback)
{
#if USE_MOTIF
    static Widget w;
    static int created = 0;
    XmString str;

    if (!created) {
        w = XmCreateMessageDialog(toplevel, "message", NULL, 0);
        XtAddCallback(w, XmNokCallback, (XtCallbackProc)PopDownCB, NULL);
        XtUnmanageChild(XmMessageBoxGetChild(w, XmDIALOG_CANCEL_BUTTON));
        XtUnmanageChild(XmMessageBoxGetChild(w, XmDIALOG_HELP_BUTTON));
        created = 1;
    }
    str = XmStringCreateLtoR((char *)message, XmFONTLIST_DEFAULT_TAG);
    XtVaSetValues(w,
                  XmNmessageString, str,
                  XmNsymbolPixmap, symbol,
                  NULL);
    XmStringFree(str);
    if (additional_callback)
        XtAddCallback(w, XmNokCallback, additional_callback, NULL);
    if (timeout > 0)
        XtAppAddTimeOut(app_context, timeout, timeout_proc, w);
    XtManageChild(w);
#else /* USE_MOTIF */
    static Widget shell, mf, mfl, pix, label, button;
    static int created = 0;

    if (!created) {
        Position x, y;
        XtVaGetValues(toplevel, XtNx, &x, XtNy, &y, NULL);
        shell = XtVaCreatePopupShell("message", transientShellWidgetClass, toplevel,
                                     XtNx, x+10,
                                     XtNy, y+10,
                                     NULL);
        mf = XtVaCreateManagedWidget("mf", formWidgetClass, shell,
                                     XtNborderWidth, 0,
                                     NULL);
        mfl = XtVaCreateManagedWidget("mfl", formWidgetClass, mf,
                                      XtNborderWidth, 0,
                                      XtNresizable,   True,
                                      XtNtop,         XawChainTop,
                                      XtNbottom,      XawChainBottom,
                                      XtNleft,        XawChainLeft,
                                      XtNright,       XawChainRight,
                                      NULL);
        pix = XtVaCreateManagedWidget("pix", labelWidgetClass, mfl,
                                      XtNborderWidth, 0,
                                      XtNbitmap,      symbol,
                                      XtNresizable,   True,
                                      XtNtop,         XawChainTop,
                                      XtNbottom,      XawChainTop,
                                      XtNleft,        XawChainLeft,
                                      XtNright,       XawChainLeft,
                                      NULL);
        label = XtVaCreateManagedWidget("label", labelWidgetClass, mfl,
                                        XtNborderWidth, 0,
                                        XtNfromHoriz,   pix,
                                        XtNresizable,   True,
                                        XtNtop,         XawChainTop,
                                        XtNbottom,      XawChainBottom,
                                        XtNleft,        XawChainLeft,
                                        XtNright,       XawChainRight,
                                        NULL);
        button = XtVaCreateManagedWidget("button", commandWidgetClass, mf,
                                         XtNfromVert, mfl,
                                         XtNlabel,    "OK",
                                         XtNtop,      XawChainBottom,
                                         XtNbottom,   XawChainBottom,
                                         XtNleft,     XawChainLeft,
                                         NULL);
        XtAddCallback(button, XtNcallback, (XtCallbackProc)PopDownCB, shell);
    }
    XtVaSetValues(pix,
                  XtNbackgroundPixmap, symbol,
                  NULL);
    XtVaSetValues(label,
                  XtNlabel, message,
                  NULL);
    if (additional_callback)
        XtAddCallback(button, XtNcallback, additional_callback, NULL);
    if (timeout > 0)
        XtAppAddTimeOut(app_context, timeout, timeout_proc, shell);
    XtPopup(shell, XtGrabNone);
#endif /* USE_MOTIF */
}