dialog.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #define CONST_DIALOG(x) ((const WDialog *)(x))
  16. /* Common return values */
  17. /* ATTENTION: avoid overlapping with FileProgressStatus values */
  18. #define B_EXIT 0
  19. #define B_CANCEL 1
  20. #define B_ENTER 2
  21. #define B_HELP 3
  22. #define B_USER 100
  23. /*** enums ***************************************************************************************/
  24. /* Dialog color constants */
  25. typedef enum
  26. {
  27. DLG_COLOR_NORMAL,
  28. DLG_COLOR_FOCUS,
  29. DLG_COLOR_HOT_NORMAL,
  30. DLG_COLOR_HOT_FOCUS,
  31. DLG_COLOR_TITLE,
  32. DLG_COLOR_COUNT
  33. } dlg_colors_enum_t;
  34. /*** typedefs(not structures) ********************************************************************/
  35. typedef struct WDialog WDialog;
  36. /* get string representation of shortcut assigned with command */
  37. /* as menu is a widget of dialog, ask dialog about shortcut string */
  38. typedef char *(*dlg_shortcut_str) (long command);
  39. /* get dialog name to show in dialog list */
  40. typedef char *(*dlg_title_str) (const WDialog * h, size_t len);
  41. typedef int dlg_colors_t[DLG_COLOR_COUNT];
  42. /*** structures declarations (and typedefs of structures)*****************************************/
  43. struct WDialog
  44. {
  45. WGroup group; /* base class */
  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 *colors; /* Color set. Unused in viewer and editor */
  50. /* Set and received by the user */
  51. int ret_value; /* Result of dlg_run() */
  52. /* Internal variables */
  53. void *data; /* Data can be passed to dialog */
  54. char *event_group; /* Name of event group for this dialog */
  55. Widget *bg; /* WFrame or WBackground */
  56. dlg_shortcut_str get_shortcut; /* Shortcut string */
  57. dlg_title_str get_title; /* useless for modal dialogs */
  58. };
  59. /*** global variables defined in .c file *********************************************************/
  60. /* Color styles for normal and error dialogs */
  61. extern dlg_colors_t dialog_colors;
  62. extern dlg_colors_t alarm_colors;
  63. extern dlg_colors_t listbox_colors;
  64. extern GList *top_dlg;
  65. /* A hook list for idle events */
  66. extern hook_t *idle_hook;
  67. extern gboolean fast_refresh;
  68. extern gboolean mouse_close_dialog;
  69. extern const global_keymap_t *dialog_map;
  70. /*** declarations of public functions ************************************************************/
  71. /* Creates a dialog head */
  72. WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
  73. widget_pos_flags_t pos_flags, gboolean compact,
  74. const int *colors, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback,
  75. const char *help_ctx, const char *title);
  76. void dlg_set_default_colors (void);
  77. void dlg_init (WDialog * h);
  78. int dlg_run (WDialog * d);
  79. void dlg_run_done (WDialog * h);
  80. void dlg_save_history (WDialog * h);
  81. void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
  82. char *dlg_get_title (const WDialog * h, size_t len);
  83. /* Default callbacks for dialogs */
  84. cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
  85. void dlg_default_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event);
  86. void dlg_stop (WDialog * h);
  87. /* Redraw all dialogs */
  88. void do_refresh (void);
  89. /* --------------------------------------------------------------------------------------------- */
  90. /*** inline functions ****************************************************************************/
  91. /* --------------------------------------------------------------------------------------------- */
  92. #endif /* MC__DIALOG_H */