group.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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, void *data);
  31. cb_ret_t group_default_set_state (Widget *w, widget_state_t state, gboolean enable);
  32. int group_handle_mouse_event (Widget *w, Gpm_Event *event);
  33. unsigned long group_add_widget_autopos (WGroup *g, void *w, widget_pos_flags_t pos_flags,
  34. const void *before);
  35. void group_remove_widget (void *w);
  36. void group_set_current_widget_next (WGroup *g);
  37. void group_set_current_widget_prev (WGroup *g);
  38. GList *group_get_widget_next_of (GList *w);
  39. GList *group_get_widget_prev_of (GList *w);
  40. void group_select_next_widget (WGroup *g);
  41. void group_select_prev_widget (WGroup *g);
  42. void group_select_widget_by_id (const WGroup *g, unsigned long id);
  43. void group_send_broadcast_msg (WGroup *g, widget_msg_t message);
  44. /* --------------------------------------------------------------------------------------------- */
  45. /*** inline functions ****************************************************************************/
  46. /* --------------------------------------------------------------------------------------------- */
  47. /**
  48. * Add widget to group before current widget.
  49. *
  50. * @param g WGroup object
  51. * @param w widget to be added
  52. *
  53. * @return widget ID
  54. */
  55. static inline unsigned long
  56. group_add_widget (WGroup *g, void *w)
  57. {
  58. return group_add_widget_autopos (g, w, WPOS_KEEP_DEFAULT,
  59. g->current != NULL ? g->current->data : NULL);
  60. }
  61. /* --------------------------------------------------------------------------------------------- */
  62. /**
  63. * Add widget to group before specified widget.
  64. *
  65. * @param g WGroup object
  66. * @param w widget to be added
  67. * @param before add @w before this widget
  68. *
  69. * @return widget ID
  70. */
  71. static inline unsigned long
  72. group_add_widget_before (WGroup *g, void *w, void *before)
  73. {
  74. return group_add_widget_autopos (g, w, WPOS_KEEP_DEFAULT, before);
  75. }
  76. /* --------------------------------------------------------------------------------------------- */
  77. /**
  78. * Select current widget in the Dialog.
  79. *
  80. * @param h WDialog object
  81. */
  82. static inline void
  83. group_select_current_widget (WGroup *g)
  84. {
  85. if (g->current != NULL)
  86. widget_select (WIDGET (g->current->data));
  87. }
  88. /* --------------------------------------------------------------------------------------------- */
  89. static inline unsigned long
  90. group_get_current_widget_id (const WGroup *g)
  91. {
  92. return WIDGET (g->current->data)->id;
  93. }
  94. #endif /* MC__GROUP_H */