raise.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Handle any events in application.
  3. Raise events.
  4. Copyright (C) 2011-2024
  5. Free Software Foundation, Inc.
  6. Written by:
  7. Slava Zanko <slavazanko@gmail.com>, 2011.
  8. This file is part of the Midnight Commander.
  9. The Midnight Commander is free software: you can redistribute it
  10. and/or modify it under the terms of the GNU General Public License as
  11. published by the Free Software Foundation, either version 3 of the License,
  12. or (at your option) any later version.
  13. The Midnight Commander is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include "lib/global.h"
  22. #include "lib/event.h"
  23. #include "internal.h"
  24. /*** global variables ****************************************************************************/
  25. /*** file scope macro definitions ****************************************************************/
  26. /*** file scope type declarations ****************************************************************/
  27. /*** file scope variables ************************************************************************/
  28. /*** file scope functions ************************************************************************/
  29. /* --------------------------------------------------------------------------------------------- */
  30. /*** public functions ****************************************************************************/
  31. /* --------------------------------------------------------------------------------------------- */
  32. gboolean
  33. mc_event_raise (const gchar *event_group_name, const gchar *event_name, gpointer event_data)
  34. {
  35. GTree *event_group;
  36. GPtrArray *callbacks;
  37. guint array_index;
  38. if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL)
  39. return FALSE;
  40. event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL);
  41. if (event_group == NULL)
  42. return FALSE;
  43. callbacks = mc_event_get_event_by_name (event_group, event_name, FALSE, NULL);
  44. if (callbacks == NULL)
  45. return FALSE;
  46. for (array_index = callbacks->len; array_index > 0; array_index--)
  47. {
  48. mc_event_callback_t *cb = g_ptr_array_index (callbacks, array_index - 1);
  49. if (!(*cb->callback) (event_group_name, event_name, cb->init_data, event_data))
  50. break;
  51. }
  52. return TRUE;
  53. }
  54. /* --------------------------------------------------------------------------------------------- */