~ubuntu-branches/ubuntu/gutsy/xlogo/gutsy

« back to all changes in this revision

Viewing changes to xlogo.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2005-08-19 10:26:16 UTC
  • Revision ID: james.westby@ubuntu.com-20050819102616-yt7k7wyhk8c1egfb
Tags: upstream-0.99.0
ImportĀ upstreamĀ versionĀ 0.99.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Xorg: xlogo.c,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $
 
3
 *
 
4
Copyright 1989, 1998  The Open Group
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software and its
 
7
documentation for any purpose is hereby granted without fee, provided that
 
8
the above copyright notice appear in all copies and that both that
 
9
copyright notice and this permission notice appear in supporting
 
10
documentation.
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
Except as contained in this notice, the name of The Open Group shall not be
 
23
used in advertising or otherwise to promote the sale, use or other dealings
 
24
in this Software without prior written authorization from The Open Group.
 
25
 *
 
26
 */
 
27
 
 
28
/* $XFree86: xc/programs/xlogo/xlogo.c,v 3.7 2001/07/25 15:05:26 dawes Exp $ */
 
29
 
 
30
#include <X11/Intrinsic.h>
 
31
#include <X11/StringDefs.h>
 
32
#include <X11/Shell.h>
 
33
#include "xlogo.h"
 
34
#include "Logo.h"
 
35
#include <X11/Xaw/Cardinals.h>
 
36
#ifdef INCLUDE_XPRINT_SUPPORT
 
37
#include "print.h"
 
38
#endif /* INCLUDE_XPRINT_SUPPORT */
 
39
#ifdef XKB
 
40
#include <X11/extensions/XKBbells.h>
 
41
#endif
 
42
#include <stdio.h>
 
43
#include <stdlib.h>
 
44
 
 
45
/* Global vars*/
 
46
const char *ProgramName;    /* program name (from argv[0]) */
 
47
 
 
48
static void quit(Widget w,  XEvent *event, String *params, Cardinal *num_params);
 
49
#ifdef INCLUDE_XPRINT_SUPPORT
 
50
static void print(Widget w, XEvent *event, String *params, Cardinal *num_params);
 
51
#endif /* INCLUDE_XPRINT_SUPPORT */
 
52
 
 
53
static XrmOptionDescRec options[] = {
 
54
{ "-shape", "*shapeWindow", XrmoptionNoArg, (XPointer) "on" },
 
55
#ifdef XRENDER
 
56
{"-render", "*render",XrmoptionNoArg, "TRUE"},
 
57
{"-sharp", "*sharp", XrmoptionNoArg, "TRUE"},
 
58
#endif
 
59
{"-v",         "Verbose",     XrmoptionNoArg,  "TRUE"},
 
60
{"-q",         "Quiet",       XrmoptionNoArg,  "TRUE"},
 
61
#ifdef INCLUDE_XPRINT_SUPPORT
 
62
{"-print",     "Print",       XrmoptionNoArg,  "TRUE"},
 
63
{"-printer",   "printer",     XrmoptionSepArg, NULL},
 
64
{"-printfile", "printFile",   XrmoptionSepArg, NULL},
 
65
#endif /* INCLUDE_XPRINT_SUPPORT */
 
66
};
 
67
 
 
68
static XtActionsRec actions[] = {
 
69
    {"quit",    quit },
 
70
#ifdef INCLUDE_XPRINT_SUPPORT
 
71
    {"print",   print}
 
72
#endif /* INCLUDE_XPRINT_SUPPORT */
 
73
};
 
74
 
 
75
static Atom wm_delete_window;
 
76
 
 
77
/* See xlogo.h */
 
78
XLogoResourceData userOptions;
 
79
 
 
80
#define Offset(field) XtOffsetOf(XLogoResourceData, field)
 
81
 
 
82
XtResource resources[] = {
 
83
  {"verbose",   "Verbose",   XtRBoolean, sizeof(Boolean), Offset(verbose),      XtRImmediate, (XtPointer)False},
 
84
  {"quiet",     "Quiet",     XtRBoolean, sizeof(Boolean), Offset(quiet),        XtRImmediate, (XtPointer)False},
 
85
#ifdef INCLUDE_XPRINT_SUPPORT
 
86
  {"print",     "Print",     XtRBoolean, sizeof(Boolean), Offset(printAndExit), XtRImmediate, (XtPointer)False},
 
87
  {"printer",   "Printer",   XtRString,  sizeof(String),  Offset(printername),  XtRImmediate, (XtPointer)NULL},
 
88
  {"printFile", "PrintFile", XtRString,  sizeof(String),  Offset(printfile),    XtRImmediate, (XtPointer)NULL}
 
89
#endif /* INCLUDE_XPRINT_SUPPORT */
 
90
};
 
91
 
 
92
 
 
93
String fallback_resources[] = {
 
94
    "*iconPixmap:    xlogo32",
 
95
    "*iconMask:      xlogo32",
 
96
    "*baseTranslations: #override \\"
 
97
#ifdef INCLUDE_XPRINT_SUPPORT
 
98
                        "\t<Key>q: quit()\\n\\"
 
99
                        "\t<Key>p: print()",
 
100
#else /* !INCLUDE_XPRINT_SUPPORT */
 
101
                        "\t<Key>q: quit()",
 
102
#endif /* !INCLUDE_XPRINT_SUPPORT */
 
103
    NULL,
 
104
};
 
105
 
 
106
static void 
 
107
die(Widget w, XtPointer client_data, XtPointer call_data)
 
108
{
 
109
    XtAppSetExitFlag(XtWidgetToApplicationContext(w));
 
110
}
 
111
 
 
112
static void 
 
113
save(Widget w, XtPointer client_data, XtPointer call_data)
 
114
{
 
115
    return;
 
116
}
 
117
 
 
118
/*
 
119
 * Report the syntax for calling xlogo.
 
120
 */
 
121
 
 
122
static void 
 
123
Syntax(Widget toplevel)
 
124
{
 
125
    Arg arg;
 
126
    SmcConn connection;
 
127
    String reasons[10];
 
128
    int i, n = 0;
 
129
 
 
130
    reasons[n++] = "Usage: ";
 
131
    reasons[n++] = (String)ProgramName;
 
132
    reasons[n++] = " [-fg <color>] [-bg <color>] [-rv] [-bw <pixels>] [-bd <color>]\n";
 
133
    reasons[n++] = "             [-v] [-q]\n";
 
134
    reasons[n++] = "             [-d [<host>]:[<vs>]]\n";
 
135
    reasons[n++] = "             [-g [<width>][x<height>][<+-><xoff>[<+-><yoff>]]]\n";
 
136
#ifdef INCLUDE_XPRINT_SUPPORT
 
137
    reasons[n++] = "             [-print] [-printname <name>] [-printfile <file>]\n";
 
138
#endif /* INCLUDE_XPRINT_SUPPORT */
 
139
#ifdef XRENDER
 
140
    reasons[n++] = "             [-render] [-sharp]\n";
 
141
#endif /* XRENDER */
 
142
    reasons[n++] = "             [-shape]\n\n";
 
143
 
 
144
    XtSetArg(arg, XtNconnection, &connection);
 
145
    XtGetValues(toplevel, &arg, (Cardinal)1);
 
146
    if (connection) 
 
147
        SmcCloseConnection(connection, n, reasons);
 
148
    else {
 
149
        for (i=0; i < n; i++)
 
150
            printf(reasons[i]);
 
151
    }
 
152
    exit(EXIT_FAILURE);
 
153
}
 
154
 
 
155
int 
 
156
main(int argc, char *argv[])
 
157
{
 
158
    Widget toplevel;
 
159
    XtAppContext app_con;
 
160
 
 
161
    ProgramName = argv[0];
 
162
 
 
163
    toplevel = XtOpenApplication(&app_con, "XLogo",
 
164
                                 options, XtNumber(options), 
 
165
                                 &argc, argv, fallback_resources,
 
166
                                 sessionShellWidgetClass, NULL, ZERO);
 
167
    if (argc != 1)
 
168
        Syntax(toplevel);
 
169
 
 
170
    XtGetApplicationResources(toplevel, (XtPointer)&userOptions, resources, 
 
171
                              XtNumber(resources), NULL, 0);
 
172
 
 
173
    XtAppAddActions(app_con, actions, XtNumber(actions));
 
174
 
 
175
#ifdef INCLUDE_XPRINT_SUPPORT
 
176
    if (userOptions.printAndExit) {
 
177
        XtCallActionProc(toplevel, "print", NULL, NULL, 0);
 
178
    }
 
179
    else
 
180
#endif /* INCLUDE_XPRINT_SUPPORT */
 
181
    {
 
182
        XtAddCallback(toplevel, XtNsaveCallback, save, NULL);
 
183
        XtAddCallback(toplevel, XtNdieCallback,  die,  NULL);
 
184
        XtOverrideTranslations
 
185
          (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
 
186
        XtCreateManagedWidget("xlogo", logoWidgetClass, toplevel, NULL, ZERO);
 
187
        XtRealizeWidget(toplevel);
 
188
        wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW",
 
189
                                       False);
 
190
        (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
 
191
                                &wm_delete_window, 1);
 
192
    }
 
193
 
 
194
    XtAppMainLoop(app_con);
 
195
 
 
196
    return EXIT_SUCCESS;
 
197
}
 
198
 
 
199
/*ARGSUSED*/
 
200
static void 
 
201
quit(Widget w, XEvent *event, String *params, Cardinal *num_params)
 
202
{
 
203
    Arg arg;
 
204
    
 
205
    if (event->type == ClientMessage && 
 
206
        (Atom)event->xclient.data.l[0] != wm_delete_window) {
 
207
#ifdef XKB
 
208
        XkbStdBell(XtDisplay(w), XtWindow(w), 0, XkbBI_BadValue);
 
209
#else
 
210
        XBell(XtDisplay(w), 0);
 
211
#endif
 
212
    } else {
 
213
        /* resign from the session */
 
214
        XtSetArg(arg, XtNjoinSession, False);
 
215
        XtSetValues(w, &arg, ONE);
 
216
        die(w, NULL, NULL);
 
217
    }
 
218
}
 
219
 
 
220
#ifdef INCLUDE_XPRINT_SUPPORT
 
221
/*ARGSUSED*/
 
222
static void 
 
223
print(Widget w, XEvent *event, String *params, Cardinal *num_params)
 
224
{
 
225
    DoPrint(w, userOptions.printername, userOptions.printfile);
 
226
}
 
227
#endif /* INCLUDE_XPRINT_SUPPORT */