lwlib-utils.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* Defines some widget utility functions.
  2. Copyright (C) 1992 Lucid, Inc.
  3. Copyright (C) 1994, 2001-2012 Free Software Foundation, Inc.
  4. This file is part of the Lucid Widget Library.
  5. The Lucid Widget Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 1, or (at your option)
  8. any later version.
  9. The Lucid Widget Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Emacs; see the file COPYING. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA. */
  17. #ifdef HAVE_CONFIG_H
  18. #include <config.h>
  19. #endif
  20. #include <setjmp.h>
  21. #include <lisp.h>
  22. #include <X11/Xatom.h>
  23. #include <X11/IntrinsicP.h>
  24. #include <X11/ObjectP.h>
  25. #include "lwlib-utils.h"
  26. #include "lwlib.h"
  27. /* Redisplay the contents of the widget, without first clearing it. */
  28. void
  29. XtNoClearRefreshWidget (Widget widget)
  30. {
  31. XEvent event;
  32. event.type = Expose;
  33. event.xexpose.serial = 0;
  34. event.xexpose.send_event = 0;
  35. event.xexpose.display = XtDisplay (widget);
  36. event.xexpose.window = XtWindow (widget);
  37. event.xexpose.x = 0;
  38. event.xexpose.y = 0;
  39. event.xexpose.width = widget->core.width;
  40. event.xexpose.height = widget->core.height;
  41. event.xexpose.count = 0;
  42. (*widget->core.widget_class->core_class.expose)
  43. (widget, &event, (Region)NULL);
  44. }
  45. /*
  46. * Apply a function to all the subwidgets of a given widget recursively.
  47. */
  48. void
  49. XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
  50. {
  51. if (XtIsComposite (w))
  52. {
  53. CompositeWidget cw = (CompositeWidget) w;
  54. /* We have to copy the children list before mapping over it, because
  55. the procedure might add/delete elements, which would lose badly.
  56. */
  57. int nkids = cw->composite.num_children;
  58. Widget *kids = (Widget *) xmalloc (sizeof (Widget) * nkids);
  59. int i;
  60. memcpy ((char *) kids, (char *) cw->composite.children,
  61. sizeof (Widget) * nkids);
  62. for (i = 0; i < nkids; i++)
  63. /* This prevent us from using gadgets, why is it here? */
  64. /* if (XtIsWidget (kids [i])) */
  65. {
  66. /* do the kiddies first in case we're destroying */
  67. XtApplyToWidgets (kids [i], proc, arg);
  68. proc (kids [i], arg);
  69. }
  70. xfree (kids);
  71. }
  72. }
  73. /*
  74. * Apply a function to all the subwidgets of a given widget recursively.
  75. * Stop as soon as the function returns non NULL and returns this as a value.
  76. */
  77. void *
  78. XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
  79. {
  80. void* result;
  81. if (XtIsComposite (w))
  82. {
  83. CompositeWidget cw = (CompositeWidget)w;
  84. int i;
  85. for (i = 0; i < cw->composite.num_children; i++)
  86. if (XtIsWidget (cw->composite.children [i])){
  87. result = proc (cw->composite.children [i], arg);
  88. if (result)
  89. return result;
  90. result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
  91. arg);
  92. if (result)
  93. return result;
  94. }
  95. }
  96. return NULL;
  97. }
  98. /*
  99. * Returns a copy of the list of all children of a composite widget
  100. */
  101. Widget *
  102. XtCompositeChildren (Widget widget, unsigned int *number)
  103. {
  104. CompositeWidget cw = (CompositeWidget)widget;
  105. Widget* result;
  106. int n;
  107. int i;
  108. if (!XtIsComposite (widget))
  109. {
  110. *number = 0;
  111. return NULL;
  112. }
  113. n = cw->composite.num_children;
  114. result = (Widget*)(void*)XtMalloc (n * sizeof (Widget));
  115. *number = n;
  116. for (i = 0; i < n; i++)
  117. result [i] = cw->composite.children [i];
  118. return result;
  119. }
  120. Boolean
  121. XtWidgetBeingDestroyedP (Widget widget)
  122. {
  123. return widget->core.being_destroyed;
  124. }