File: pattern.c

package info (click to toggle)
xbae 4.60.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,452 kB
  • ctags: 2,046
  • sloc: ansic: 21,858; sh: 8,195; makefile: 577; tcl: 1
file content (275 lines) | stat: -rw-r--r-- 6,848 bytes parent folder | download | duplicates (7)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * Copyright(c) 1999 Andrew Lister
 *                        All rights reserved
 *
 * Copyright  2001 by the LessTif Developers
 *
 * Permission to use, copy, modify and distribute this material for
 * any purpose and without fee is hereby granted, provided that the
 * above copyright notice and this permission notice appear in all
 * copies, and that the name of the author not be used in advertising
 * or publicity pertaining to this material without the specific,
 * prior written permission of an authorized representative of
 * the author.
 *
 * THE AUTHOR MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES, EX-
 * PRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST IN-
 * FRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  THE
 * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL THE AUTHOR OR
 * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
 * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELAT-
 * ING TO THE SOFTWARE.
 *
 * $Id: pattern.c,v 1.1 2003/10/20 19:12:46 dannybackx Exp $
*/

#ifdef HAVE_CONFIG_H
#include <XbaeConfig.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef USE_EDITRES
#include <X11/Intrinsic.h>
#include <X11/Xmu/Editres.h>
#endif
#include <Xm/TextF.h>
#include <Xm/RowColumn.h>
#include <Xm/Frame.h>
#include <Xbae/Matrix.h>
#include <Xbae/Input.h>
#include <Xbae/Caption.h>

static String fallback[] = {
	"Input*XmRowColumn.orientation:		vertical",
	"Input*XmRowColumn.numColumns:		2",
	"Input*XmRowColumn.packing:		pack_column",
	"Input*XbaeCaption.labelPosition:	Top",
	"Input*XbaeCaption.labelAlignment:	Center",
	NULL
};

Widget input;

void
validateCB(Widget w, XtPointer cd, XtPointer cb)
{
    XbaeInputValidateCallbackStruct *cbs =
	(XbaeInputValidateCallbackStruct *)cb;

    (void)printf("Validate '%s' = %s\n", cbs->value, 
		 cbs->doit ? "OK" : "Nope");
}

void
autoFillToggle(Widget w, XtPointer cd, XtPointer cb)
{
    int which = (int)cd;

    if (which)
	XtVaSetValues(input, XmNautoFill, True, NULL);
    else
	XtVaSetValues(input, XmNautoFill, False, NULL);
}

void
convertCaseToggle(Widget w, XtPointer cd, XtPointer cb)
{
    int which = (int)cd;

    if (which)
	XtVaSetValues(input, XmNconvertCase, True, NULL);
    else
	XtVaSetValues(input, XmNconvertCase, False, NULL);
}

void
overwriteModeToggle(Widget w, XtPointer cd, XtPointer cb)
{
    int which = (int)cd;

    if (which)
	XtVaSetValues(input, XmNoverwriteMode, True, NULL);
    else
	XtVaSetValues(input, XmNoverwriteMode, False, NULL);
}

void
alignmentToggle(Widget w, XtPointer cd, XtPointer cb)
{
    int which = (int)cd;

    if (which == 0)
	XtVaSetValues(input, XmNalignment, XmALIGNMENT_BEGINNING, NULL);
    else if (which == 1)
	XtVaSetValues(input, XmNalignment, XmALIGNMENT_CENTER, NULL);
    else
	XtVaSetValues(input, XmNalignment, XmALIGNMENT_END, NULL);
}

void
patternCB(Widget w, XtPointer cd, XtPointer cb)
{
#if 0
    char *pattern = XmTextFieldGetString(w);

    if (*pattern == '\0')	
	XtVaSetValues(input, XmNpattern, NULL, NULL);
    else
	XtVaSetValues(input, XmNpattern, pattern, NULL);

    XtFree(pattern);
#endif
}

int
main(int argc, char *argv[])
{
    Widget toplevel, rc, pattern, cw, radio, frame;
    XtAppContext app;
    XmString true, false, begin, centre, end;

    toplevel = XtVaAppInitialize(&app, "Input",
				 NULL, 0,
				 &argc, argv,
				 fallback,
				 NULL);
#ifdef USE_EDITRES
    XtAddEventHandler( toplevel, (EventMask)0, True,
                       _XEditResCheckMessages, NULL);
#endif
    /*
     * Create a Form to hold everything
     */
    rc = XtVaCreateManagedWidget(
	"rc", xmRowColumnWidgetClass, toplevel,
	NULL);

    cw = XtVaCreateManagedWidget(
	"Enter string", xbaeCaptionWidgetClass, rc,
	NULL);

    frame = XtVaCreateManagedWidget(
	"frame", xmFrameWidgetClass, cw,
	NULL);

    input = XtVaCreateManagedWidget(
	"input", xbaeInputWidgetClass, frame,
	XmNtopAttachment, XmATTACH_FORM,
	XmNleftAttachment, XmATTACH_FORM,
	NULL);

    XtAddCallback(input, XmNvalidateCallback, validateCB, NULL);
    XtVaSetValues(input,
		XmNpattern,		"[-]d[d][d][d][d]",
		XmNautoFill,		True,
		XmNoverwriteMode,	False,
		NULL);

    true = XmStringCreateSimple("True");
    false = XmStringCreateSimple("False");

    cw = XtVaCreateManagedWidget(
	"XmNautofill", xbaeCaptionWidgetClass, rc,
	NULL);

    frame = XtVaCreateManagedWidget(
	"frame", xmFrameWidgetClass, cw,
	NULL);

    radio = XmVaCreateSimpleRadioBox(
	frame, "XmNautoFill", 0, autoFillToggle,
	XmVaRADIOBUTTON, false, NULL, NULL, NULL,
	XmVaRADIOBUTTON, true, NULL, NULL, NULL,
	NULL);

    XtVaSetValues(radio, XmNtraversalOn, False, NULL);

    XtManageChild(radio);

    cw = XtVaCreateManagedWidget(
	"XmNconvertCase", xbaeCaptionWidgetClass, rc,
	NULL);

    frame = XtVaCreateManagedWidget(
	"frame", xmFrameWidgetClass, cw,
	NULL);

    radio = XmVaCreateSimpleRadioBox(
	frame, "XmNconvertCase", 1, convertCaseToggle,
	XmVaRADIOBUTTON, false, NULL, NULL, NULL,
	XmVaRADIOBUTTON, true, NULL, NULL, NULL,
	NULL);

    XtVaSetValues(radio, XmNtraversalOn, False, NULL);

    XtManageChild(radio);

    cw = XtVaCreateManagedWidget(
	"XmNpattern", xbaeCaptionWidgetClass, rc,
	NULL);

    frame = XtVaCreateManagedWidget(
	"frame", xmFrameWidgetClass, cw,
	NULL);

    pattern = XtVaCreateManagedWidget(
	"XmNpattern", xmTextFieldWidgetClass, frame,
	NULL);

    XtAddCallback(pattern, XmNactivateCallback, patternCB, NULL);
    XtAddCallback(pattern, XmNlosingFocusCallback, patternCB, NULL);

    cw = XtVaCreateManagedWidget(
	"XmNoverwriteMode", xbaeCaptionWidgetClass, rc,
	NULL);

    frame = XtVaCreateManagedWidget(
	"frame", xmFrameWidgetClass, cw,
	NULL);

    radio = XmVaCreateSimpleRadioBox(
	frame, "XmNoverwriteMode", 0, overwriteModeToggle,
	XmVaRADIOBUTTON, false, NULL, NULL, NULL,
	XmVaRADIOBUTTON, true, NULL, NULL, NULL,
	NULL);

    XtVaSetValues(radio, XmNtraversalOn, False, NULL);

    XtManageChild(radio);

    cw = XtVaCreateManagedWidget(
	"XmNalignment", xbaeCaptionWidgetClass, rc,
	NULL);

    frame = XtVaCreateManagedWidget(
	"frame", xmFrameWidgetClass, cw,
	NULL);

    begin = XmStringCreateSimple("Begin");
    centre = XmStringCreateSimple("Centre");
    end = XmStringCreateSimple("End");

    radio = XmVaCreateSimpleRadioBox(
	frame, "XmNalignment", 0, alignmentToggle,
	XmVaRADIOBUTTON, begin, NULL, NULL, NULL,
	XmVaRADIOBUTTON, end, NULL, NULL, NULL,
	NULL);

    XtVaSetValues(radio, XmNtraversalOn, False, NULL);

    XtManageChild(radio);

    XmStringFree(true);
    XmStringFree(false);
    XmStringFree(begin);
    XmStringFree(centre);
    XmStringFree(end);

    XtRealizeWidget(toplevel);
    XtAppMainLoop(app);

    /*NOTREACHED*/
    return 0;
}