group.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Widget group features module for Midnight Commander
  3. */
  4. /** \file group.h
  5. * \brief Header: widget group features module
  6. */
  7. #ifndef MC__GROUP_H
  8. #define MC__GROUP_H
  9. #include "lib/global.h"
  10. /*** typedefs(not structures) and defined constants **********************************************/
  11. #define GROUP(x) ((WGroup *)(x))
  12. #define CONST_GROUP(x) ((const WGroup *)(x))
  13. /*** enums ***************************************************************************************/
  14. /*** typedefs(not structures) ********************************************************************/
  15. /*** structures declarations (and typedefs of structures)*****************************************/
  16. struct WGroup
  17. {
  18. Widget widget;
  19. /* Group members */
  20. GList *widgets; /* widgets list */
  21. GList *current; /* Currently active widget */
  22. gboolean winch_pending; /* SIGWINCH signal has been got. Resize group after rise */
  23. int mouse_status; /* For the autorepeat status of the mouse */
  24. };
  25. /*** global variables defined in .c file *********************************************************/
  26. /*** declarations of public functions ************************************************************/
  27. void group_init (WGroup * g, const WRect * r, widget_cb_fn callback,
  28. widget_mouse_cb_fn mouse_callback);
  29. /* Default callback for groups */
  30. cb_ret_t group_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
  31. void *data);
  32. cb_ret_t group_default_set_state (Widget * w, widget_state_t state, gboolean enable);
  33. int group_handle_mouse_event (Widget * w, Gpm_Event * event);
  34. unsigned long group_add_widget_autopos (WGroup * g, void *w, widget_pos_flags_t pos_flags,
  35. const void *before);
  36. void group_remove_widget (void *w);
  37. void group_set_current_widget_next (WGroup * g);
  38. void group_set_current_widget_prev (WGroup * g);
  39. GList *group_get_widget_next_of (GList * w);
  40. GList *group_get_widget_prev_of (GList * w);
  41. void group_select_next_widget (WGroup * g);
  42. void group_select_prev_widget (WGroup * g);
  43. void group_select_widget_by_id (const WGroup * g, unsigned long id);
  44. void group_send_broadcast_msg (WGroup * g, widget_msg_t message);
  45. /* --------------------------------------------------------------------------------------------- */
  46. /*** inline functions ****************************************************************************/
  47. /* --------------------------------------------------------------------------------------------- */
  48. /**
  49. * Add widget to group before current widget.
  50. *
  51. * @param g WGroup object
  52. * @param w widget to be added
  53. *
  54. * @return widget ID
  55. */
  56. static inline unsigned long
  57. group_add_widget (WGroup *g, void *w)
  58. {
  59. return group_add_widget_autopos (g, w, WPOS_KEEP_DEFAULT,
  60. g->current != NULL ? g->current->data : NULL);
  61. }
  62. /* --------------------------------------------------------------------------------------------- */
  63. /**
  64. * Add widget to group before specified widget.
  65. *
  66. * @param g WGroup object
  67. * @param w widget to be added
  68. * @param before add @w before this widget
  69. *
  70. * @return widget ID
  71. */
  72. static inline unsigned long
  73. group_add_widget_before (WGroup *g, void *w, void *before)
  74. {
  75. return group_add_widget_autopos (g, w, WPOS_KEEP_DEFAULT, before);
  76. }
  77. /* --------------------------------------------------------------------------------------------- */
  78. /**
  79. * Select current widget in the Dialog.
  80. *
  81. * @param h WDialog object
  82. */
  83. static inline void
  84. group_select_current_widget (WGroup *g)
  85. {
  86. if (g->current != NULL)
  87. widget_select (WIDGET (g->current->data));
  88. }
  89. /* --------------------------------------------------------------------------------------------- */
  90. static inline unsigned long
  91. group_get_current_widget_id (const WGroup *g)
  92. {
  93. return WIDGET (g->current->data)->id;
  94. }
  95. #endif /* MC__GROUP_H */