raise.c 2.8 KB

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