gui_util.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* gui_util.c - GUI utility functions. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2008 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/mm.h>
  20. #include <grub/misc.h>
  21. #include <grub/gui.h>
  22. #include <grub/gui_string_util.h>
  23. struct find_by_id_state
  24. {
  25. const char *match_id;
  26. grub_gui_component_callback match_callback;
  27. void *match_userdata;
  28. };
  29. static void
  30. find_by_id_recursively (grub_gui_component_t component, void *userdata)
  31. {
  32. struct find_by_id_state *state;
  33. const char *id;
  34. state = (struct find_by_id_state *) userdata;
  35. id = component->ops->get_id (component);
  36. if (id && grub_strcmp (id, state->match_id) == 0)
  37. state->match_callback (component, state->match_userdata);
  38. if (component->ops->is_instance (component, "container"))
  39. {
  40. grub_gui_container_t container;
  41. container = (grub_gui_container_t) component;
  42. container->ops->iterate_children (container,
  43. find_by_id_recursively,
  44. state);
  45. }
  46. }
  47. void
  48. grub_gui_find_by_id (grub_gui_component_t root,
  49. const char *id,
  50. grub_gui_component_callback cb,
  51. void *userdata)
  52. {
  53. struct find_by_id_state state;
  54. state.match_id = id;
  55. state.match_callback = cb;
  56. state.match_userdata = userdata;
  57. find_by_id_recursively (root, &state);
  58. }
  59. struct iterate_recursively_state
  60. {
  61. grub_gui_component_callback callback;
  62. void *userdata;
  63. };
  64. static
  65. void iterate_recursively_cb (grub_gui_component_t component, void *userdata)
  66. {
  67. struct iterate_recursively_state *state;
  68. state = (struct iterate_recursively_state *) userdata;
  69. state->callback (component, state->userdata);
  70. if (component->ops->is_instance (component, "container"))
  71. {
  72. grub_gui_container_t container;
  73. container = (grub_gui_container_t) component;
  74. container->ops->iterate_children (container,
  75. iterate_recursively_cb,
  76. state);
  77. }
  78. }
  79. void
  80. grub_gui_iterate_recursively (grub_gui_component_t root,
  81. grub_gui_component_callback cb,
  82. void *userdata)
  83. {
  84. struct iterate_recursively_state state;
  85. state.callback = cb;
  86. state.userdata = userdata;
  87. iterate_recursively_cb (root, &state);
  88. }