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
|
/*
Copyright 1990, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.
*/
/*
* This file contains the code to communicate with the client that is
* being edited.
*/
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h> /* Get standard string definitions. */
#include <X11/Xatom.h>
#include <X11/cursorfont.h> /* For crosshair cursor. */
#include <X11/Xproto.h>
#include <X11/Xos.h> /* for XtNewString */
#include <stdio.h>
#include <X11/Xmu/Error.h>
#include <X11/Xmu/WinUtil.h>
#include "editresP.h"
/*
* static Globals.
*/
static Atom atom_comm, atom_command, atom_resource_editor, atom_client_value;
static Atom atom_editres_protocol;
extern Widget CM_entries[NUM_CM_ENTRIES], TM_entries[NUM_TM_ENTRIES];
static void ClientTimedOut ( XtPointer data, XtIntervalId * id );
static void TellUserAboutMessage ( Widget label, ResCommand command );
static Boolean ConvertCommand ( Widget w, Atom * selection, Atom * target,
Atom * type_ret, XtPointer *value_ret,
unsigned long * length_ret, int * format_ret );
static void SelectionDone ( Widget w, Atom *sel, Atom *targ );
static void LoseSelection ( Widget w, Atom * sel );
static void GetClientValue ( Widget w, XtPointer data, Atom *selection,
Atom *type, XtPointer value,
unsigned long *length, int * format );
static void BuildHeader ( CurrentClient * client_data );
static Event * BuildEvent ( ProtocolStream * stream );
static void FreeEvent ( Event * event );
static char * DispatchEvent ( Event * event );
/* Function Name: ClientTimedOut
* Description: Called if the client takes too long to take our selection.
* Arguments: data - The widget that owns the client
* communication selection.
* id - *** UNUSED ***
* Returns: none.
*/
/* ARGSUSED */
static void
ClientTimedOut(XtPointer data, XtIntervalId *id)
{
char msg[BUFSIZ];
Widget w = (Widget) data;
global_client.ident = NO_IDENT;
XtDisownSelection(w, global_client.atom,
XtLastTimestampProcessed(XtDisplay(w)));
snprintf(msg, sizeof(msg), res_labels[4], "the Editres Protocol.");
SetMessage(global_screen_data.info_label, msg);
}
/* Function Name: GetClientWindow
* Description: Gets the Client's window by asking the user.
* Arguments: w - a widget.
* Returns: a clients window, or None.
*/
Window
GetClientWindow(Widget w, int *x, int *y)
{
int status;
Cursor cursor;
XEvent event;
int buttons = 0;
Display * dpy = XtDisplayOfObject(w);
Window target_win = None, root = RootWindowOfScreen(XtScreenOfObject(w));
XtAppContext app = XtWidgetToApplicationContext(w);
/* Make the target cursor */
cursor = XCreateFontCursor(dpy, XC_crosshair);
/* Grab the pointer using target cursor, letting it room all over */
status = XGrabPointer(dpy, root, False,
ButtonPressMask|ButtonReleaseMask, GrabModeSync,
GrabModeAsync, root, cursor, CurrentTime);
if (status != GrabSuccess) {
SetMessage(global_screen_data.info_label, res_labels[5]);
return(None);
}
/* Let the user select a window... */
while ((target_win == None) || (buttons != 0)) {
/* allow one more event */
XAllowEvents(dpy, SyncPointer, CurrentTime);
XtAppNextEvent(app, &event);
switch (event.type) {
case ButtonPress:
if (event.xbutton.window != root) {
XtDispatchEvent(&event);
break;
}
if (target_win == None) {
target_win = event.xbutton.subwindow; /* window selected */
if (x != NULL)
*x = event.xbutton.x_root;
if (y != NULL)
*y = event.xbutton.y_root;
}
buttons++;
break;
case ButtonRelease:
if (event.xbutton.window != root) {
XtDispatchEvent(&event);
break;
}
if (buttons > 0) /* There may have been some
down before we started */
buttons--;
break;
default:
XtDispatchEvent(&event);
break;
}
}
XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
return(XmuClientWindow(dpy, target_win));
}
/* Function Name: SetCommand
* Description: Causes this widget to own the resource editor's
* command selection.
* Arguments: w - the widget that will own the selection.
* command - command to send to client.
* msg - message to prompt the user to select a client.
* Returns: none.
*/
/* ARGSUSED */
void
SetCommand(Widget w, ResCommand command, char *msg)
{
XClientMessageEvent client_event;
Display * dpy = XtDisplay(w);
if (msg == NULL)
msg = res_labels[6];
SetMessage(global_screen_data.info_label, msg);
if (global_client.window == None)
if ( (global_client.window = GetClientWindow(w, NULL, NULL)) == None)
return;
global_client.ident = GetNewIdent();
global_client.command = command;
global_client.atom = atom_comm;
BuildHeader(&(global_client));
if (!XtOwnSelection(w, global_client.atom, CurrentTime, ConvertCommand,
LoseSelection, SelectionDone))
SetMessage(global_screen_data.info_label,
res_labels[7]);
client_event.window = global_client.window;
client_event.type = ClientMessage;
client_event.message_type = atom_resource_editor;
client_event.format = EDITRES_SEND_EVENT_FORMAT;
client_event.data.l[0] = XtLastTimestampProcessed(dpy);
client_event.data.l[1] = global_client.atom;
client_event.data.l[2] = (long) global_client.ident;
client_event.data.l[3] = global_effective_protocol_version;
global_error_code = NO_ERROR; /* Reset Error code. */
global_old_error_handler = XSetErrorHandler(HandleXErrors);
global_serial_num = NextRequest(dpy);
XSendEvent(dpy, global_client.window, FALSE, (long) 0,
(XEvent *) &client_event);
XSync(dpy, FALSE);
XSetErrorHandler(global_old_error_handler);
if (global_error_code == NO_WINDOW) {
char error_buf[BUFSIZ] =
"The communication window with the"
" application is no longer available\n"
"Please select a new widget tree.";
global_error_code = NO_ERROR; /* Reset Error code. */
global_client.window = None;
SetCommand(w, LocalSendWidgetTree, error_buf);
return;
}
TellUserAboutMessage(global_screen_data.info_label, command);
global_client.timeout = XtAppAddTimeOut(XtWidgetToApplicationContext(w),
CLIENT_TIME_OUT,
ClientTimedOut, (XtPointer) w);
}
/* Function Name: TellUserAboutMessage
* Description: Informs the user that we have sent a message to the client
* Arguments: label - the info label.
* command - command that we have executed.
* Returns: none.
*/
static void
TellUserAboutMessage(Widget label, ResCommand command)
{
char msg[BUFSIZ], *str;
switch(command) {
case LocalSendWidgetTree:
str = " asking for widget tree";
break;
case LocalSetValues:
str = " asking it to perform SetValues()";
break;
case LocalFlashWidget:
case LocalGetGeometry:
str = " asking it to perform GetGeometry()";
break;
case LocalGetResources:
str = " asking it to get a widget's resource list";
break;
case LocalFindChild:
str = " asking it to find the child Widget.";
break;
default:
str = "";
break;
}
snprintf(msg, sizeof(msg), res_labels[8], str);
SetMessage(label, msg);
}
/* Function Name: ConvertCommand
* Description: Converts the command string into a selection that can
* be sent to the client.
* Arguments: (see Xt)
* Returns: TRUE if we could convert the selection and target asked for.
*/
/* ARGSUSED */
static Boolean
ConvertCommand(Widget w, Atom *selection, Atom *target, Atom *type_ret,
XtPointer *value_ret, unsigned long *length_ret, int *format_ret)
{
if ((*selection != atom_comm) || (*target != atom_command))
return(FALSE);
*type_ret = atom_editres_protocol;
*value_ret = (XtPointer) global_client.stream.real_top;
*length_ret = global_client.stream.size + HEADER_SIZE;
*format_ret = EDITRES_FORMAT;
return(TRUE);
}
/* Function Name: SelectionDone
* Description: done with the selection.
* Arguments: *** UNUSED ***
* Returns: none.
*/
/* ARGSUSED */
static void
SelectionDone(Widget w, Atom *sel, Atom *targ)
{
/* Keep the toolkit from automaticaly freeing the selection value */
}
/* Function Name: LoseSelection
* Description: Called when we have lost the selection, asks client
* for the selection value.
* Arguments: w - the widget that just lost the selection.
* sel - the selection.
* Returns: none.
*/
static void
LoseSelection(Widget w, Atom *sel)
{
if (global_client.timeout != 0) {
XtRemoveTimeOut(global_client.timeout);
global_client.timeout = 0;
}
XtGetSelectionValue(w, *sel, atom_client_value, GetClientValue,
NULL, XtLastTimestampProcessed(XtDisplay(w)));
}
/* Function Name: GetClientValue
* Description: Gets the value out of the client, and does good things
* to it.
* Arguments: w - the widget that asked for the selection.
* data - client_data *** UNUSED ***.
* sel - the selection.
* type - the type of the selection.
* value - the selection's value.
* length - the length of the selection's value.
* format - the format of the selection.
* Returns: none.
*/
static Boolean reset_protocol_level = True;
/* ARGSUSED */
static void
GetClientValue(Widget w, XtPointer data, Atom *selection, Atom *type,
XtPointer value, unsigned long *length, int *format)
{
Event * event;
ProtocolStream alloc_stream, *stream;
unsigned char ident, error_code;
char * error_str = NULL, msg[BUFSIZ];
if (*length == 0)
return;
stream = &alloc_stream; /* easier to think of it this way... */
stream->current = stream->top = (unsigned char *) value;
stream->size = HEADER_SIZE; /* size of header. */
/*
* Retrieve the Header.
*/
if (*length < HEADER_SIZE) {
SetMessage(global_screen_data.info_label,
res_labels[9]);
return;
}
(void) _XEditResGet8(stream, &ident);
if (global_client.ident != ident) {
#ifdef DEBUG
if (global_resources.debug)
printf("Incorrect ident from client.\n");
#endif
if (!XtOwnSelection(w, *selection, CurrentTime, ConvertCommand,
LoseSelection, SelectionDone))
SetMessage(global_screen_data.info_label,
res_labels[10]);
return;
}
(void) _XEditResGet8(stream, &error_code);
(void) _XEditResGet32(stream, &(stream->size));
stream->top = stream->current; /* reset stream to top of value.*/
switch ((int) error_code) {
case PartialSuccess:
/*****
if (global_client.command == LocalSendWidgetTree &&
global_effective_protocol_version < CURRENT_PROTOCOL_VERSION)
++global_effective_protocol_version;
*****/
if ((event = BuildEvent(stream)) != NULL) {
error_str = DispatchEvent(event);
FreeEvent(event);
}
else {
snprintf(msg, sizeof(msg), "Unable to unpack protocol request.");
error_str = XtNewString(msg);
}
break;
case Failure:
error_str = GetFailureMessage(stream);
break;
case ProtocolMismatch:
error_str = ProtocolFailure(stream);
--global_effective_protocol_version;
/* normaly protocol version is reset to current during a SendWidgetTree
* request, however, after a protocol failure this is skiped once for
* a retry.
*/
reset_protocol_level = False;
SetCommand(w, LocalSendWidgetTree, NULL);
break;
default:
snprintf(msg, sizeof(msg), res_labels[11], (int) error_code);
SetMessage(global_screen_data.info_label, msg);
break;
}
if (error_str == NULL) {
WNode * top;
if (global_tree_info == NULL)
return;
top = global_tree_info->top_node;
snprintf(msg, sizeof(msg), res_labels[12], top->name, top->class);
SetMessage(global_screen_data.info_label, msg);
return;
}
SetMessage(global_screen_data.info_label, error_str);
XtFree(error_str);
}
/* Function Name: BuildHeader
* Description: Puts the header into the message.
* Arguments: client_data - the client data.
* Returns: none.
*/
static void
BuildHeader(CurrentClient *client_data)
{
unsigned long old_alloc, old_size;
unsigned char * old_current;
EditresCommand command;
ProtocolStream * stream = &(client_data->stream);
/*
* 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, client_data->ident);
switch(client_data->command) {
case LocalSendWidgetTree:
if (reset_protocol_level) global_effective_protocol_version =
CURRENT_PROTOCOL_VERSION;
reset_protocol_level = True;
command = SendWidgetTree;
break;
case LocalSetValues:
command = SetValues;
break;
case LocalFlashWidget:
command = GetGeometry;
break;
case LocalGetResources:
command = GetResources;
break;
case LocalFindChild:
command = FindChild;
break;
case LocalGetValues:
command = GetValues;
break;
default:
command = SendWidgetTree;
break;
}
_XEditResPut8(stream, (unsigned char) command);
_XEditResPut32(stream, old_size);
stream->alloc = old_alloc;
stream->current = old_current;
stream->size = old_size;
}
/* Function Name: BuildEvent
* Description: Builds the event structure from the
* Arguments: stream - the protocol data stream.
* Returns: event - the event.
*/
static Event *
BuildEvent(ProtocolStream *stream)
{
int i;
Event * event = (Event *) XtCalloc(sizeof(Event), 1);
/*
* The return value will be different depending upon the
* request sent out.
*/
switch(global_client.command) {
case LocalSendWidgetTree:
{
SendWidgetTreeEvent * send_event = (SendWidgetTreeEvent *) event;
send_event->type = SendWidgetTree;
if (!_XEditResGet16(stream, &(send_event->num_entries)))
goto done;
send_event->info = (WidgetTreeInfo *)
XtCalloc(sizeof(WidgetTreeInfo),
send_event->num_entries);
for (i = 0; i < (int)send_event->num_entries; i++) {
WidgetTreeInfo * info = send_event->info + i;
if (!(_XEditResGetWidgetInfo(stream, &(info->widgets)) &&
_XEditResGetString8(stream, &(info->name)) &&
_XEditResGetString8(stream, &(info->class)) &&
_XEditResGet32(stream, &(info->window))))
{
goto done;
}
}
if (global_effective_protocol_version ==
CURRENT_PROTOCOL_VERSION) {
/* get toolkit type and reset if necessary */
if (!_XEditResGetString8(stream, &(send_event->toolkit)))
goto done;
}
/* set the command menu entries senitive */
SetEntriesSensitive(&CM_entries[CM_OFFSET], CM_NUM, True);
/* set the tree menu entries senitive */
SetEntriesSensitive(TM_entries, TM_NUM, True);
if (global_effective_protocol_version ==
CURRENT_PROTOCOL_VERSION) {
if (!strcmp(send_event->toolkit, "InterViews"))
RebuildMenusAndLabel("iv");
}
else
RebuildMenusAndLabel("xt");
}
break;
case LocalSetValues:
{
SetValuesEvent * sv_event = (SetValuesEvent *) event;
sv_event->type = SetValues;
if (!_XEditResGet16(stream, &(sv_event->num_entries)))
goto done;
sv_event->info = (SetValuesInfo *) XtCalloc(sizeof(SetValuesInfo),
sv_event->num_entries);
for (i = 0; i < (int)sv_event->num_entries; i++) {
SetValuesInfo * info = sv_event->info + i;
if (!(_XEditResGetWidgetInfo(stream, &(info->widgets)) &&
_XEditResGetString8(stream, &(info->message))))
{
goto done;
}
}
}
break;
case LocalGetResources:
{
GetResourcesEvent * res_event = (GetResourcesEvent *) event;
res_event->type = GetGeometry;
if (!_XEditResGet16(stream, &(res_event->num_entries)))
goto done;
res_event->info = (GetResourcesInfo *)
XtCalloc(sizeof(GetResourcesInfo),
res_event->num_entries);
for (i = 0; i < (int)res_event->num_entries; i++) {
GetResourcesInfo * res_info = res_event->info + i;
if (!(_XEditResGetWidgetInfo(stream, &(res_info->widgets)) &&
_XEditResGetBoolean(stream, &(res_info->error))))
{
goto done;
}
if (res_info->error) {
if (!_XEditResGetString8(stream, &(res_info->message)))
goto done;
}
else {
unsigned int j;
if (!_XEditResGet16(stream, &(res_info->num_resources)))
goto done;
res_info->res_info = (ResourceInfo *)
XtCalloc(sizeof(ResourceInfo),
res_info->num_resources);
for (j = 0; j < res_info->num_resources; j++) {
unsigned char temp;
ResourceInfo * info = res_info->res_info + j;
if (!(_XEditResGetResType(stream, &(temp)) &&
_XEditResGetString8(stream, &(info->name)) &&
_XEditResGetString8(stream, &(info->class)) &&
_XEditResGetString8(stream, &(info->type))))
{
goto done;
}
else
info->res_type = (ResourceType) temp;
} /* for */
} /* else */
} /* for */
}
break;
case LocalFlashWidget:
case LocalGetGeometry:
{
GetGeomEvent * geom_event = (GetGeomEvent *) event;
geom_event->type = GetGeometry;
if (!_XEditResGet16(stream, &(geom_event->num_entries)))
goto done;
geom_event->info = (GetGeomInfo *) XtCalloc(sizeof(GetGeomInfo),
geom_event->num_entries);
for (i = 0; i < (int)geom_event->num_entries; i++) {
GetGeomInfo * info = geom_event->info + i;
if (!(_XEditResGetWidgetInfo(stream, &(info->widgets)) &&
_XEditResGetBoolean(stream, &(info->error))))
{
goto done;
}
if (info->error) {
if (!_XEditResGetString8(stream, &(info->message)))
goto done;
}
else {
if (!(_XEditResGetBoolean(stream, &(info->visable)) &&
_XEditResGetSigned16(stream, &(info->x)) &&
_XEditResGetSigned16(stream, &(info->y)) &&
_XEditResGet16(stream, &(info->width)) &&
_XEditResGet16(stream, &(info->height)) &&
_XEditResGet16(stream, &(info->border_width))))
{
goto done;
}
}
}
}
break;
case LocalFindChild:
{
FindChildEvent * find_event = (FindChildEvent *) event;
find_event->type = FindChild;
if (!_XEditResGetWidgetInfo(stream, &(find_event->widgets)))
goto done;
}
break;
case LocalGetValues: /* This is for REPLY... */
{
Arg args[1];
GetValuesEvent * gv_event = (GetValuesEvent *) event;
gv_event->type = GetValues;
if (!_XEditResGet16(stream, &(gv_event->num_entries)))
goto done;
gv_event->info = (GetValuesInfo*)XtCalloc(sizeof(GetValuesInfo),1);
{
GetValuesInfo * info = gv_event->info;
if (!(_XEditResGetString8(stream, &(info->value))))
{
goto done;
}
/* set the string value of the asciitext widget. note that only
* one active node is dealt with here. This is ok because only
* one node can be active when the resource box is up.
*/
XtSetArg (args[0], XtNstring, info->value);
XtSetValues(
global_tree_info->active_nodes[0]->resources->res_box->value_wid,
args, 1
);
}
}
break;
default:
goto done;
}
return(event);
done:
FreeEvent(event);
return(NULL);
}
/* Function Name: FreeEvent
* Description: Frees all memory associated with the event.
* Arguments: event - the event.
* Returns: none.
*
* NOTE: XtFree() returns w/o freeing if ptr is NULL.
*/
static void
FreeEvent(Event *event)
{
unsigned int i;
switch(event->any_event.type) {
case SendWidgetTree:
{
SendWidgetTreeEvent * send_event = (SendWidgetTreeEvent *) event;
WidgetTreeInfo * info = send_event->info;
if (info != NULL) {
for (i = 0; i < send_event->num_entries; i++, info++) {
XtFree((char *)info->widgets.ids);
XtFree(info->name);
XtFree(info->class);
}
XtFree((char *)send_event->info);
}
}
break;
case SetValues:
{
SetValuesEvent * sv_event = (SetValuesEvent *) event;
SetValuesInfo * info = sv_event->info;
if (info != NULL) {
for (i = 0; i < sv_event->num_entries; i++, info++) {
XtFree((char *)info->widgets.ids);
XtFree(info->message);
}
XtFree((char *)sv_event->info);
}
}
break;
case GetResources:
{
GetResourcesEvent * get_event = (GetResourcesEvent *) event;
GetResourcesInfo * info = get_event->info;
if (info != NULL) {
for (i = 0; i < get_event->num_entries; i++, info++) {
XtFree((char *)info->widgets.ids);
if (info->error)
XtFree(info->message);
else {
unsigned int j;
ResourceInfo * res_info = info->res_info;
if (res_info != NULL) {
for (j = 0;
j < info->num_resources; j++, res_info++)
{
XtFree(res_info->name);
XtFree(res_info->class);
XtFree(res_info->type);
}
XtFree((char *)info->res_info);
}
}
}
XtFree((char *)get_event->info);
}
}
break;
case GetGeometry:
{
GetGeomEvent * geom_event = (GetGeomEvent *) event;
GetGeomInfo * info = geom_event->info;
if (info != NULL) {
for (i = 0; i < geom_event->num_entries; i++, info++) {
XtFree((char *)info->widgets.ids);
if (info->error)
XtFree(info->message);
}
XtFree((char *)geom_event->info);
}
}
break;
case FindChild:
{
FindChildEvent * find_event = (FindChildEvent *) event;
XtFree((char *)find_event->widgets.ids);
}
break;
default:
break;
}
}
/* Function Name: DispatchEvent
* Description: Handles the event, calling the proper function.
* Arguments: event - the event.
* Returns: one.
*/
static char *
DispatchEvent(Event *event)
{
char * error = NULL;
switch(global_client.command) {
case LocalSendWidgetTree:
BuildVisualTree(global_tree_parent, event);
break;
case LocalSetValues:
error = PrintSetValuesError(event);
break;
case LocalFlashWidget:
error = HandleFlashWidget(event);
break;
case LocalGetResources:
error = HandleGetResources(event);
break;
case LocalFindChild:
DisplayChild(event);
break;
case LocalGetValues:
break;
default:
{
char msg[BUFSIZ];
snprintf(msg, sizeof(msg), "Internal error: Unknown command %d.",
global_client.command);
error = XtNewString(msg);
}
break;
}
return(error);
}
/* Function Name: InternAtoms
* Description: interns all static atoms.
* Arguments: display - the current display.
* Returns: none.
*/
void
InternAtoms(Display * dpy)
{
atom_comm = XInternAtom(dpy, EDITRES_COMM_ATOM, False);
atom_command = XInternAtom(dpy, EDITRES_COMMAND_ATOM, False);
atom_resource_editor = XInternAtom(dpy, EDITRES_NAME, False);
atom_client_value = XInternAtom(dpy, EDITRES_CLIENT_VALUE, False);
atom_editres_protocol = XInternAtom(dpy, EDITRES_PROTOCOL_ATOM, False);
}
ResIdent
GetNewIdent(void)
{
static ResIdent ident = 1;
return(ident++);
}
|