dialog.h 4.0 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. char *event_group; /* Name of event group for this dialog */
  54. Widget *bg; /* WFrame or WBackground */
  55. /* Data can be passed to dialog */
  56. union
  57. {
  58. void *p;
  59. int i;
  60. } data;
  61. dlg_shortcut_str get_shortcut; /* Shortcut string */
  62. dlg_title_str get_title; /* useless for modal dialogs */
  63. };
  64. /*** global variables defined in .c file *********************************************************/
  65. /* Color styles for normal and error dialogs */
  66. extern dlg_colors_t dialog_colors;
  67. extern dlg_colors_t alarm_colors;
  68. extern dlg_colors_t listbox_colors;
  69. /* A hook list for idle events */
  70. extern hook_t *idle_hook;
  71. extern gboolean mouse_close_dialog;
  72. extern const global_keymap_t *dialog_map;
  73. /*** declarations of public functions ************************************************************/
  74. /* Creates a dialog head */
  75. WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
  76. widget_pos_flags_t pos_flags, gboolean compact,
  77. const int *colors, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback,
  78. const char *help_ctx, const char *title);
  79. void dlg_set_default_colors (void);
  80. void dlg_init (WDialog * h);
  81. int dlg_run (WDialog * d);
  82. void dlg_run_done (WDialog * h);
  83. void dlg_save_history (WDialog * h);
  84. void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
  85. char *dlg_get_title (const WDialog * h, size_t len);
  86. /* Default callbacks for dialogs */
  87. cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
  88. void dlg_default_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event);
  89. void dlg_close (WDialog * h);
  90. /* --------------------------------------------------------------------------------------------- */
  91. /*** inline functions ****************************************************************************/
  92. /* --------------------------------------------------------------------------------------------- */
  93. #endif /* MC__DIALOG_H */