-
Notifications
You must be signed in to change notification settings - Fork 11
/
RegEdit.c
1784 lines (1495 loc) · 46.8 KB
/
RegEdit.c
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $XConsortium: RegEdit.c /main/5 1995/07/15 20:44:04 drk $ */
/*
* Motif
*
* Copyright (c) 1987-2012, The Open Group. All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*
*/
/*
* HISTORY
*/
#include <stdio.h>
#include <stddef.h>
#include <Xm/XmP.h>
#include <X11/ShellP.h>
#include "RegEdit.h"
#include "RegEditI.h"
/* static forward. move from global in the original Editres code */
static void _XEditResCheckMessages();
static void _XEditResPutString8();
static void _XEditResPut8();
static void _XEditResPut16();
static void _XEditResPut32();
static void _XEditResPutWidgetInfo();
static void _XEditResResetStream();
static Boolean _XEditResGet8();
static Boolean _XEditResGet16();
static Boolean _XEditResGetSigned16();
static Boolean _XEditResGet32();
static Boolean _XEditResGetString8();
static Boolean _XEditResGetWidgetInfo();
/* the only entry point here */
void
XmdRegisterEditres(Widget toplevel)
{
XtAddEventHandler(toplevel, (EventMask) 0, TRUE,
_XEditResCheckMessages, NULL);
}
/************************************************************
*
* Dump the content of the R5 lib/Xmu/EditresCom.c module.
* just move global as static.
*
************************************************************/
#define _XEditResPutBool _XEditResPut8
#define _XEditResPutResourceType _XEditResPut8
/************************************************************
*
* Local structure definitions.
*
************************************************************/
typedef enum { BlockNone, BlockSetValues, BlockAll } EditresBlock;
typedef struct _SetValuesEvent {
EditresCommand type; /* first field must be type. */
WidgetInfo * widgets;
unsigned short num_entries; /* number of set values requests. */
char * name;
char * res_type;
XtPointer value;
unsigned short value_len;
} SetValuesEvent;
typedef struct _SVErrorInfo {
SetValuesEvent * event;
ProtocolStream * stream;
unsigned short * count;
WidgetInfo * entry;
} SVErrorInfo;
typedef struct _FindChildEvent {
EditresCommand type; /* first field must be type. */
WidgetInfo * widgets;
short x, y;
} FindChildEvent;
typedef struct _GenericGetEvent {
EditresCommand type; /* first field must be type. */
WidgetInfo * widgets;
unsigned short num_entries; /* number of set values requests. */
} GenericGetEvent, GetResEvent, GetGeomEvent;
/*
* Things that are common to all events.
*/
typedef struct _AnyEvent {
EditresCommand type; /* first field must be type. */
WidgetInfo * widgets;
} AnyEvent;
/*
* The event union.
*/
typedef union _EditresEvent {
AnyEvent any_event;
SetValuesEvent set_values_event;
GetResEvent get_resources_event;
GetGeomEvent get_geometry_event;
FindChildEvent find_child_event;
} EditresEvent;
typedef struct _Globals {
EditresBlock block;
SVErrorInfo error_info;
ProtocolStream stream;
ProtocolStream * command_stream; /* command stream. */
} Globals;
#define CURRENT_PROTOCOL_VERSION 4L
#define streq(a,b) (strcmp( (a), (b) ) == 0)
static Atom res_editor_command, res_editor_protocol, client_value;
static Globals globals;
static void SendFailure(), SendCommand(), InsertWidget(), ExecuteCommand();
static void FreeEvent(), ExecuteSetValues(), ExecuteGetGeometry();
static void ExecuteGetResources();
static void GetCommand();
static void LoadResources();
static Boolean IsChild();
static void DumpChildren();
static char *DumpWidgets(), *DoSetValues(), *DoFindChild();
static char *DoGetGeometry(), *DoGetResources();
/************************************************************
*
* Resource Editor Communication Code
*
************************************************************/
/* Function Name: _XEditResCheckMessages
* Description: This callback routine is set on all shell widgets,
* and checks to see if a client message event
* has come from the resource editor.
* Arguments: w - the shell widget.
* data - *** UNUSED ***
* event - The X Event that triggered this handler.
* cont - *** UNUSED ***.
* Returns: none.
*/
/* ARGSUSED */
static void
_XEditResCheckMessages(w, data, event, cont)
Widget w;
XtPointer data;
XEvent *event;
Boolean *cont;
{
Time time;
ResIdent ident;
static Boolean first_time = FALSE;
static Atom res_editor, res_comm;
Display * dpy;
if (event->type == ClientMessage) {
XClientMessageEvent * c_event = (XClientMessageEvent *) event;
dpy = XtDisplay(w);
if (!first_time) {
first_time = TRUE;
res_editor = XInternAtom(dpy, EDITRES_NAME, False);
res_editor_command = XInternAtom(dpy, EDITRES_COMMAND_ATOM, False);
res_editor_protocol = XInternAtom(dpy, EDITRES_PROTOCOL_ATOM,
False);
/* Used in later procedures. */
client_value = XInternAtom(dpy, EDITRES_CLIENT_VALUE, False);
LoadResources(w);
}
if ((c_event->message_type != res_editor) ||
(c_event->format != EDITRES_SEND_EVENT_FORMAT))
return;
time = c_event->data.l[0];
res_comm = c_event->data.l[1];
ident = (ResIdent) c_event->data.l[2];
if (c_event->data.l[3] != CURRENT_PROTOCOL_VERSION) {
_XEditResResetStream(&globals.stream);
_XEditResPut8(&globals.stream, CURRENT_PROTOCOL_VERSION);
SendCommand(w, res_comm, ident, ProtocolMismatch, &globals.stream);
return;
}
XtGetSelectionValue(w, res_comm, res_editor_command,
GetCommand, (XtPointer) (long) ident, time);
}
}
/* Function Name: BuildEvent
* Description: Takes the info out the protocol stream an constructs
* the proper event structure.
* Arguments: w - widget to own selection, in case of error.
* sel - selection to send error message beck in.
* data - the data for the request.
* ident - the id number we are looking for.
* length - length of request.
* Returns: the event, or NULL.
*/
#define ERROR_MESSAGE ("Client: Improperly formatted protocol request")
static EditresEvent *
BuildEvent(w, sel, data, ident, length)
Widget w;
Atom sel;
XtPointer data;
ResIdent ident;
unsigned long length;
{
EditresEvent * event;
ProtocolStream alloc_stream, *stream;
unsigned char temp;
register unsigned int i;
stream = &alloc_stream; /* easier to think of it this way... */
stream->current = stream->top = (unsigned char *) data;
stream->size = HEADER_SIZE; /* size of header. */
/*
* Retrieve the Header.
*/
if (length < HEADER_SIZE) {
SendFailure(w, sel, ident, Failure, ERROR_MESSAGE);
return(NULL);
}
(void) _XEditResGet8(stream, &temp);
if (temp != ident) /* Id's don't match, ignore request. */
return(NULL);
event = (EditresEvent *) XtCalloc(sizeof(EditresEvent), 1);
(void) _XEditResGet8(stream, &temp);
event->any_event.type = (EditresCommand) temp;
(void) _XEditResGet32(stream, &(stream->size));
stream->top = stream->current; /* reset stream to top of value.*/
/*
* Now retrieve the data segment.
*/
switch(event->any_event.type) {
case SendWidgetTree:
break; /* no additional info */
case SetValues:
{
SetValuesEvent * sv_event = (SetValuesEvent *) event;
if ( !(_XEditResGetString8(stream, &(sv_event->name)) &&
_XEditResGetString8(stream, &(sv_event->res_type))))
{
goto done;
}
/*
* Since we need the value length, we have to pull the
* value out by hand.
*/
if (!_XEditResGet16(stream, &(sv_event->value_len)))
goto done;
sv_event->value = XtMalloc(sizeof(char) *
(sv_event->value_len + 1));
for (i = 0; i < sv_event->value_len; i++) {
if (!_XEditResGet8(stream,
(unsigned char *) sv_event->value + i))
{
goto done;
}
}
((char*)sv_event->value)[i] = '\0'; /* NULL terminate that sucker. */
if (!_XEditResGet16(stream, &(sv_event->num_entries)))
goto done;
sv_event->widgets = (WidgetInfo *)
XtCalloc(sizeof(WidgetInfo), sv_event->num_entries);
for (i = 0; i < sv_event->num_entries; i++) {
if (!_XEditResGetWidgetInfo(stream, sv_event->widgets + i))
goto done;
}
}
break;
case FindChild:
{
FindChildEvent * find_event = (FindChildEvent *) event;
find_event->widgets = (WidgetInfo *)
XtCalloc(sizeof(WidgetInfo), 1);
if (!(_XEditResGetWidgetInfo(stream, find_event->widgets) &&
_XEditResGetSigned16(stream, &(find_event->x)) &&
_XEditResGetSigned16(stream, &(find_event->y))))
{
goto done;
}
}
break;
case GetGeometry:
case GetResources:
{
GenericGetEvent * get_event = (GenericGetEvent *) event;
if (!_XEditResGet16(stream, &(get_event->num_entries)))
goto done;
get_event->widgets = (WidgetInfo *)
XtCalloc(sizeof(WidgetInfo), get_event->num_entries);
for (i = 0; i < get_event->num_entries; i++) {
if (!_XEditResGetWidgetInfo(stream, get_event->widgets + i))
goto done;
}
}
break;
default:
{
char buf[BUFSIZ];
sprintf(buf, "Unknown Protocol request %d.",event->any_event.type);
SendFailure(w, sel, ident, buf);
return(NULL);
}
}
return(event);
done:
SendFailure(w, sel, ident, ERROR_MESSAGE);
FreeEvent(event);
return(NULL);
}
/* Function Name: FreeEvent
* Description: Frees the event structure and any other pieces
* in it that need freeing.
* Arguments: event - the event to free.
* Returns: none.
*/
static void
FreeEvent(event)
EditresEvent * event;
{
if (event->any_event.widgets != NULL) {
XtFree((char *)event->any_event.widgets->ids);
XtFree((char *)event->any_event.widgets);
}
if (event->any_event.type == SetValues) {
XtFree(event->set_values_event.name); /* XtFree does not free if */
XtFree(event->set_values_event.res_type); /* value is NULL. */
}
XtFree((char *)event);
}
/* Function Name: GetCommand
* Description: Gets the Command out of the selection asserted by the
* resource manager.
* Arguments: (See Xt XtConvertSelectionProc)
* data - contains the ident number for the command.
* Returns: none.
*/
/* ARGSUSED */
static void
GetCommand(w, data, selection, type, value, length, format)
Widget w;
XtPointer data, value;
Atom *selection, *type;
unsigned long *length;
int * format;
{
ResIdent ident = (ResIdent) (long) data;
EditresEvent * event;
if ( (*type != res_editor_protocol) || (*format != EDITRES_FORMAT) )
return;
if ((event = BuildEvent(w, *selection, value, ident, *length)) != NULL) {
ExecuteCommand(w, *selection, ident, event);
FreeEvent(event);
}
}
/* Function Name: ExecuteCommand
* Description: Executes a command string received from the
* resource editor.
* Arguments: w - a widget.
* command - the command to execute.
* value - the associated with the command.
* Returns: none.
*
* NOTES: munges str
*/
/* ARGSUSED */
static void
ExecuteCommand(w, sel, ident, event)
Widget w;
Atom sel;
ResIdent ident;
EditresEvent * event;
{
char * (*func)();
char * str;
if (globals.block == BlockAll) {
SendFailure(w, sel, ident,
"This client has blocked all Editres commands.");
return;
}
else if ((globals.block == BlockSetValues) &&
(event->any_event.type == SetValues)) {
SendFailure(w, sel, ident,
"This client has blocked all SetValues requests.");
return;
}
switch(event->any_event.type) {
case SendWidgetTree:
func = DumpWidgets;
break;
case SetValues:
func = DoSetValues;
break;
case FindChild:
func = DoFindChild;
break;
case GetGeometry:
func = DoGetGeometry;
break;
case GetResources:
func = DoGetResources;
break;
default:
{
char buf[BUFSIZ];
sprintf(buf,"Unknown Protocol request %d.",event->any_event.type);
SendFailure(w, sel, ident, buf);
return;
}
}
_XEditResResetStream(&globals.stream);
if ((str = (*func)(w, event, &globals.stream)) == NULL)
SendCommand(w, sel, ident, PartialSuccess, &globals.stream);
else {
SendFailure(w, sel, ident, str);
XtFree(str);
}
}
/* Function Name: ConvertReturnCommand
* Description: Converts a selection.
* Arguments: w - the widget that owns the selection.
* selection - selection to convert.
* target - target type for this selection.
* type_ret - type of the selection.
* value_ret - selection value;
* length_ret - lenght of this selection.
* format_ret - the format the selection is in.
* Returns: True if conversion was sucessful.
*/
/* ARGSUSED */
static Boolean
ConvertReturnCommand(w, selection, target,
type_ret, value_ret, length_ret, format_ret)
Widget w;
Atom * selection, * target, * type_ret;
XtPointer *value_ret;
unsigned long * length_ret;
int * format_ret;
{
/*
* I assume the intrinsics give me the correct selection back.
*/
if ((*target != client_value))
return(FALSE);
*type_ret = res_editor_protocol;
*value_ret = (XtPointer) globals.command_stream->real_top;
*length_ret = globals.command_stream->size + HEADER_SIZE;
*format_ret = EDITRES_FORMAT;
return(TRUE);
}
/* Function Name: CommandDone
* Description: done with the selection.
* Arguments: *** UNUSED ***
* Returns: none.
*/
/* ARGSUSED */
static void
CommandDone(widget, selection, target)
Widget widget;
Atom *selection;
Atom *target;
{
/* Keep the toolkit from automaticaly freeing the selection value */
}
/* Function Name: SendFailure
* Description: Sends a failure message.
* Arguments: w - the widget to own the selection.
* sel - the selection to assert.
* ident - the identifier.
* str - the error message.
* Returns: none.
*/
static void
SendFailure(w, sel, ident, str)
Widget w;
Atom sel;
ResIdent ident;
char * str;
{
_XEditResResetStream(&globals.stream);
_XEditResPutString8(&globals.stream, str);
SendCommand(w, sel, ident, Failure, &globals.stream);
}
/* Function Name: BuildReturnPacket
* Description: Builds a return packet, given the data to send.
* Arguments: ident - the identifier.
* command - the command code.
* stream - the protocol stream.
* Returns: packet - the packet to send.
*/
static XtPointer
BuildReturnPacket(ident, command, stream)
ResIdent ident;
EditresCommand command;
ProtocolStream * stream;
{
long old_alloc, old_size;
unsigned char * old_current;
/*
* We have cleverly keep enough space at the top of the header
* for the return protocol stream, so all we have to do is
* fill in the space.
*/
/*
* Fool the insert routines into putting the header in the right
* place while being damn sure not to realloc (that would be very bad.
*/
old_current = stream->current;
old_alloc = stream->alloc;
old_size = stream->size;
stream->current = stream->real_top;
stream->alloc = stream->size + (2 * HEADER_SIZE);
_XEditResPut8(stream, ident);
_XEditResPut8(stream, (unsigned char) command);
_XEditResPut32(stream, old_size);
stream->alloc = old_alloc;
stream->current = old_current;
stream->size = old_size;
return((XtPointer) stream->real_top);
}
/* Function Name: SendCommand
* Description: Builds a return command line.
* Arguments: w - the widget to own the selection.
* sel - the selection to assert.
* ident - the identifier.
* command - the command code.
* stream - the protocol stream.
* Returns: none.
*/
static void
SendCommand(w, sel, ident, command, stream)
Widget w;
Atom sel;
ResIdent ident;
EditresCommand command;
ProtocolStream * stream;
{
BuildReturnPacket(ident, command, stream);
globals.command_stream = stream;
/*
* I REALLY want to own the selection. Since this was not triggered
* by a user action, and I am the only one using this atom it is safe to
* use CurrentTime.
*/
XtOwnSelection(w, sel, CurrentTime,
ConvertReturnCommand, NULL, CommandDone);
}
/************************************************************
*
* Generic Utility Functions.
*
************************************************************/
/* Function Name: FindChildren
* Description: Retuns all children (popup, normal and otherwise)
* of this widget
* Arguments: parent - the parent widget.
* children - the list of children.
* normal - return normal children.
* popup - return popup children.
* Returns: the number of children.
*/
static int
FindChildren(parent, children, normal, popup)
Widget parent, **children;
Boolean normal, popup;
{
CompositeWidget cw = (CompositeWidget) parent;
int i, num_children, current = 0;
num_children = 0;
if (XtIsWidget(parent) && popup)
num_children += parent->core.num_popups;
if (XtIsComposite(parent) && normal)
num_children += cw->composite.num_children;
if (num_children == 0) {
*children = NULL;
return(0);
}
*children =(Widget*) XtMalloc((Cardinal) sizeof(Widget) * num_children);
if (XtIsComposite(parent) && normal)
for (i = 0; i < cw->composite.num_children; i++,current++)
(*children)[current] = cw->composite.children[i];
if (XtIsWidget(parent) && popup)
for ( i = 0; i < parent->core.num_popups; i++, current++)
(*children)[current] = parent->core.popup_list[i];
return(num_children);
}
/* Function Name: IsChild
* Description: check to see of child is a child of parent.
* Arguments: top - the top of the tree.
* parent - the parent widget.
* child - the child.
* Returns: none.
*/
static Boolean
IsChild(top, parent, child)
Widget top, parent, child;
{
int i, num_children;
Widget * children;
if (parent == NULL)
return(top == child);
num_children = FindChildren(parent, &children, TRUE, TRUE);
for (i = 0; i < num_children; i++) {
if (children[i] == child) {
XtFree((char *)children);
return(TRUE);
}
}
XtFree((char *)children);
return(FALSE);
}
/* Function Name: VerifyWidget
* Description: Makes sure all the widgets still exist.
* Arguments: w - any widget in the tree.
* info - the info about the widget to verify.
* Returns: an error message or NULL.
*/
static char *
VerifyWidget(w, info)
Widget w;
WidgetInfo *info;
{
Widget top;
register int count;
register Widget parent;
register unsigned long * child;
for (top = w; XtParent(top) != NULL; top = XtParent(top)) {}
parent = NULL;
child = info->ids;
count = 0;
while (TRUE) {
if (!IsChild(top, parent, (Widget) *child))
return(XtNewString("This widget no longer exists in the client."));
if (++count == info->num_widgets)
break;
parent = (Widget) *child++;
}
info->real_widget = (Widget) *child;
return(NULL);
}
/************************************************************
*
* Code to Perform SetValues operations.
*
************************************************************/
/* Function Name: DoSetValues
* Description: performs the setvalues requested.
* Arguments: w - a widget in the tree.
* event - the event that caused this action.
* stream - the protocol stream to add.
* Returns: NULL.
*/
static char *
DoSetValues(w, event, stream)
Widget w;
EditresEvent * event;
ProtocolStream * stream;
{
char * str;
register unsigned i;
unsigned short count = 0;
SetValuesEvent * sv_event = (SetValuesEvent *) event;
_XEditResPut16(stream, count); /* insert 0, will be overwritten later. */
for (i = 0 ; i < sv_event->num_entries; i++) {
if ((str = VerifyWidget(w, &(sv_event->widgets[i]))) != NULL) {
_XEditResPutWidgetInfo(stream, &(sv_event->widgets[i]));
_XEditResPutString8(stream, str);
XtFree(str);
count++;
}
else
ExecuteSetValues(sv_event->widgets[i].real_widget,
sv_event, sv_event->widgets + i, stream, &count);
}
/*
* Overwrite the first 2 bytes with the real count.
*/
*(stream->top) = count >> XER_NBBY;
*(stream->top + 1) = count;
return(NULL);
}
/* Function Name: HandleToolkitErrors
* Description: Handles X Toolkit Errors.
* Arguments: name - name of the error.
* type - type of the error.
* class - class of the error.
* msg - the default message.
* params, num_params - the extra parameters for this message.
* Returns: none.
*/
/* ARGSUSED */
static void
HandleToolkitErrors(name, type, class, msg, params, num_params)
String name, type, class, msg, *params;
Cardinal * num_params;
{
SVErrorInfo * info = &globals.error_info;
char buf[BUFSIZ];
if ( streq(name, "unknownType") )
sprintf(buf, "The `%s' resource is not used by this widget.",
info->event->name);
else if ( streq(name, "noColormap") )
sprintf(buf, msg, params[0]);
else if (streq(name, "conversionFailed") || streq(name, "conversionError"))
{
if (streq(info->event->value, XtRString))
sprintf(buf,
"Could not convert the string '%s' for the `%s' resource.",
(char*)info->event->value, info->event->name);
else
sprintf(buf, "Could not convert the `%s' resource.",
info->event->name);
}
else
sprintf(buf, "Name: %s, Type: %s, Class: %s, Msg: %s",
name, type, class, msg);
/*
* Insert this info into the protocol stream, and update the count.
*/
(*(info->count))++;
_XEditResPutWidgetInfo(info->stream, info->entry);
_XEditResPutString8(info->stream, buf);
}
/* Function Name: ExecuteSetValues
* Description: Performs a setvalues for a given command.
* Arguments: w - the widget to perform the set_values on.
* sv_event - the set values event.
* sv_info - the set_value info.
* Returns: none.
*/
static void
ExecuteSetValues(w, sv_event, entry, stream, count)
Widget w;
SetValuesEvent * sv_event;
WidgetInfo * entry;
ProtocolStream * stream;
unsigned short * count;
{
XtErrorMsgHandler old;
SVErrorInfo * info = &globals.error_info;
info->event = sv_event; /* No data can be passed to */
info->stream = stream; /* an error handler, so we */
info->count = count; /* have to use a global, YUCK... */
info->entry = entry;
old = XtAppSetWarningMsgHandler(XtWidgetToApplicationContext(w),
HandleToolkitErrors);
XtVaSetValues(w, XtVaTypedArg,
sv_event->name, sv_event->res_type,
sv_event->value, sv_event->value_len,
NULL);
(void)XtAppSetWarningMsgHandler(XtWidgetToApplicationContext(w), old);
}
/************************************************************
*
* Code for Creating and dumping widget tree.
*
************************************************************/
/* Function Name: DumpWidgets
* Description: Given a widget it builds a protocol packet
* containing the entire widget heirarchy.
* Arguments: w - a widget in the tree.
* event - the event that caused this action.
* stream - the protocol stream to add.
* Returns: NULL
*/
/* ARGSUSED */
static char *
DumpWidgets(w, event, stream)
Widget w;
EditresEvent * event; /* UNUSED */
ProtocolStream * stream;
{
unsigned short count = 0;
/* Find Tree's root. */
for ( ; XtParent(w) != NULL; w = XtParent(w)) {}
/*
* hold space for count, overwritten later.
*/
_XEditResPut16(stream, (unsigned int) 0);
DumpChildren(w, stream, &count);
/*
* Overwrite the first 2 bytes with the real count.
*/
*(stream->top) = count >> XER_NBBY;
*(stream->top + 1) = count;
return(NULL);
}
/* Function Name: DumpChildren
* Description: Adds a child's name to the list.
* Arguments: w - the widget to dump.
* stream - the stream to dump to.
* count - number of dumps we have performed.
* Returns: none.
*/
/* This is a trick/kludge. To make shared libraries happier (linking
* against Xmu but not linking against Xt, and apparently even work
* as we desire on SVR4, we need to avoid an explicit data reference
* to applicationShellWidgetClass. XtIsTopLevelShell is known
* (implementation dependent assumption!) to use a bit flag. So we
* go that far. Then, we test whether it is an applicationShellWidget
* class by looking for an explicit class name. Seems pretty safe.
*/
static Bool isApplicationShell(w)
Widget w;
{
register WidgetClass c;
if (!XtIsTopLevelShell(w))
return False;
for (c = XtClass(w); c; c = c->core_class.superclass) {
if (!strcmp(c->core_class.class_name, "ApplicationShell"))
return True;
}
return False;
}
static void
DumpChildren(w, stream, count)
Widget w;
ProtocolStream * stream;
unsigned short *count;
{
int i, num_children;
Widget *children;
unsigned long window;
char * class;
(*count)++;
InsertWidget(stream, w); /* Insert the widget into the stream. */
_XEditResPutString8(stream, XtName(w)); /* Insert name */
if (isApplicationShell(w))
class = ((ApplicationShellWidget) w)->application.class;
else
class = XtClass(w)->core_class.class_name;
_XEditResPutString8(stream, class); /* Insert class */
if (XtIsWidget(w))
if (XtIsRealized(w))
window = XtWindow(w);
else
window = EDITRES_IS_UNREALIZED;
else
window = EDITRES_IS_OBJECT;
_XEditResPut32(stream, window); /* Insert window id. */