dialog.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. Dialog box features module for the Midnight Commander
  3. */
  4. /** \file dialog.h
  5. * \brief Header: dialog box features module
  6. */
  7. #ifndef MC__DIALOG_H
  8. #define MC__DIALOG_H
  9. #include <sys/types.h> /* size_t */
  10. #include "lib/global.h"
  11. #include "lib/hook.h" /* hook_t */
  12. #include "lib/keybind.h" /* global_keymap_t */
  13. /*** typedefs(not structures) and defined constants **********************************************/
  14. #define DIALOG(x) ((WDialog *)(x))
  15. /* Common return values */
  16. /* ATTENTION: avoid overlapping with FileProgressStatus values */
  17. #define B_EXIT 0
  18. #define B_CANCEL 1
  19. #define B_ENTER 2
  20. #define B_HELP 3
  21. #define B_USER 100
  22. /*** enums ***************************************************************************************/
  23. /* Dialog color constants */
  24. typedef enum
  25. {
  26. DLG_COLOR_NORMAL,
  27. DLG_COLOR_FOCUS,
  28. DLG_COLOR_HOT_NORMAL,
  29. DLG_COLOR_HOT_FOCUS,
  30. DLG_COLOR_TITLE,
  31. DLG_COLOR_COUNT
  32. } dlg_colors_enum_t;
  33. /*** typedefs(not structures) ********************************************************************/
  34. /* get string representation of shortcut assigned with command */
  35. /* as menu is a widget of dialog, ask dialog about shortcut string */
  36. typedef char *(*dlg_shortcut_str) (long command);
  37. /* get dialog name to show in dialog list */
  38. typedef char *(*dlg_title_str) (const WDialog * h, size_t len);
  39. typedef int dlg_colors_t[DLG_COLOR_COUNT];
  40. /* menu command execution */
  41. typedef cb_ret_t (*menu_exec_fn) (int command);
  42. /*** structures declarations (and typedefs of structures)*****************************************/
  43. struct WDialog
  44. {
  45. Widget widget;
  46. /* Set by the user */
  47. gboolean compact; /* Suppress spaces around the frame */
  48. const char *help_ctx; /* Name of the help entry */
  49. const int *color; /* Color set. Unused in viewer and editor */
  50. char *title; /* Title of the dialog */
  51. /* Set and received by the user */
  52. int ret_value; /* Result of dlg_run() */
  53. /* Internal flags */
  54. gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
  55. int mouse_status; /* For the autorepeat status of the mouse */
  56. /* Internal variables */
  57. GList *widgets; /* widgets list */
  58. GList *current; /* Currently active widget */
  59. unsigned long widget_id; /* maximum id of all widgets */
  60. void *data; /* Data can be passed to dialog */
  61. char *event_group; /* Name of event group for this dialog */
  62. dlg_shortcut_str get_shortcut; /* Shortcut string */
  63. dlg_title_str get_title; /* useless for modal dialogs */
  64. };
  65. /*** global variables defined in .c file *********************************************************/
  66. /* Color styles for normal and error dialogs */
  67. extern dlg_colors_t dialog_colors;
  68. extern dlg_colors_t alarm_colors;
  69. extern dlg_colors_t listbox_colors;
  70. extern GList *top_dlg;
  71. /* A hook list for idle events */
  72. extern hook_t *idle_hook;
  73. extern gboolean fast_refresh;
  74. extern gboolean mouse_close_dialog;
  75. extern const global_keymap_t *dialog_map;
  76. /*** declarations of public functions ************************************************************/
  77. /* Creates a dialog head */
  78. WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
  79. widget_pos_flags_t pos_flags, gboolean compact,
  80. const int *colors, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback,
  81. const char *help_ctx, const char *title);
  82. void dlg_set_default_colors (void);
  83. unsigned long add_widget_autopos (WDialog * dest, void *w, widget_pos_flags_t pos_flags,
  84. const void *before);
  85. unsigned long add_widget (WDialog * dest, void *w);
  86. unsigned long add_widget_before (WDialog * h, void *w, void *before);
  87. void del_widget (void *w);
  88. /* sets size of dialog, leaving positioning to automatic mehtods
  89. according to dialog flags */
  90. void dlg_set_size (WDialog * h, int lines, int cols);
  91. /* this function allows to set dialog position */
  92. void dlg_set_position (WDialog * h, int y, int x, int lines, int cols);
  93. void dlg_init (WDialog * h);
  94. int dlg_run (WDialog * d);
  95. void dlg_destroy (WDialog * h);
  96. void dlg_run_done (WDialog * h);
  97. void dlg_save_history (WDialog * h);
  98. void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
  99. char *dlg_get_title (const WDialog * h, size_t len);
  100. void dlg_redraw (WDialog * h);
  101. void dlg_broadcast_msg (WDialog * h, widget_msg_t message);
  102. /* Default callback for dialogs */
  103. cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
  104. /* Default paint routine for dialogs */
  105. void dlg_default_repaint (WDialog * h);
  106. void dlg_erase (WDialog * h);
  107. void dlg_stop (WDialog * h);
  108. /* Widget selection */
  109. void dlg_select_prev_widget (WDialog * h);
  110. void dlg_select_next_widget (WDialog * h);
  111. Widget *find_widget_type (const WDialog * h, widget_cb_fn callback);
  112. GList *dlg_find (const WDialog * h, const Widget * w);
  113. Widget *dlg_find_by_id (const WDialog * h, unsigned long id);
  114. void dlg_select_by_id (const WDialog * h, unsigned long id);
  115. /* Redraw all dialogs */
  116. void do_refresh (void);
  117. /* Used in load_prompt() */
  118. void update_cursor (WDialog * h);
  119. void dlg_set_current_widget_next (WDialog * h);
  120. void dlg_set_current_widget_prev (WDialog * h);
  121. GList *dlg_get_widget_next_of (GList * w);
  122. GList *dlg_get_widget_prev_of (GList * w);
  123. /* --------------------------------------------------------------------------------------------- */
  124. /*** inline functions ****************************************************************************/
  125. /* --------------------------------------------------------------------------------------------- */
  126. static inline unsigned long
  127. dlg_get_current_widget_id (const WDialog * h)
  128. {
  129. return WIDGET (h->current->data)->id;
  130. }
  131. /* --------------------------------------------------------------------------------------------- */
  132. /**
  133. * Select current widget in the Dialog.
  134. *
  135. * @param h WDialog object
  136. */
  137. static inline void
  138. dlg_select_current_widget (WDialog * h)
  139. {
  140. if (h->current != NULL)
  141. widget_select (WIDGET (h->current->data));
  142. }
  143. /* --------------------------------------------------------------------------------------------- */
  144. #endif /* MC__DIALOG_H */