dialog.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. typedef struct WDialog WDialog;
  35. /* get string representation of shortcut assigned with command */
  36. /* as menu is a widget of dialog, ask dialog about shortcut string */
  37. typedef char *(*dlg_shortcut_str) (long command);
  38. /* get dialog name to show in dialog list */
  39. typedef char *(*dlg_title_str) (const WDialog * h, size_t len);
  40. typedef int dlg_colors_t[DLG_COLOR_COUNT];
  41. /* menu command execution */
  42. typedef cb_ret_t (*menu_exec_fn) (int command);
  43. /*** structures declarations (and typedefs of structures)*****************************************/
  44. struct WDialog
  45. {
  46. WGroup group; /* base class */
  47. /* Set by the user */
  48. gboolean compact; /* Suppress spaces around the frame */
  49. const char *help_ctx; /* Name of the help entry */
  50. const int *color; /* Color set. Unused in viewer and editor */
  51. /* Set and received by the user */
  52. int ret_value; /* Result of dlg_run() */
  53. /* Internal variables */
  54. void *data; /* Data can be passed to dialog */
  55. char *event_group; /* Name of event group for this dialog */
  56. Widget *bg; /* WFrame or WBackground */
  57. dlg_shortcut_str get_shortcut; /* Shortcut string */
  58. dlg_title_str get_title; /* useless for modal dialogs */
  59. };
  60. /*** global variables defined in .c file *********************************************************/
  61. /* Color styles for normal and error dialogs */
  62. extern dlg_colors_t dialog_colors;
  63. extern dlg_colors_t alarm_colors;
  64. extern dlg_colors_t listbox_colors;
  65. extern GList *top_dlg;
  66. /* A hook list for idle events */
  67. extern hook_t *idle_hook;
  68. extern gboolean fast_refresh;
  69. extern gboolean mouse_close_dialog;
  70. extern const global_keymap_t *dialog_map;
  71. /*** declarations of public functions ************************************************************/
  72. /* Creates a dialog head */
  73. WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
  74. widget_pos_flags_t pos_flags, gboolean compact,
  75. const int *colors, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback,
  76. const char *help_ctx, const char *title);
  77. void dlg_set_default_colors (void);
  78. void dlg_init (WDialog * h);
  79. int dlg_run (WDialog * d);
  80. void dlg_destroy (WDialog * h);
  81. void dlg_run_done (WDialog * h);
  82. void dlg_save_history (WDialog * h);
  83. void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
  84. char *dlg_get_title (const WDialog * h, size_t len);
  85. /* Default callbacks for dialogs */
  86. cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
  87. void dlg_default_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event);
  88. void dlg_stop (WDialog * h);
  89. /* Redraw all dialogs */
  90. void do_refresh (void);
  91. /* --------------------------------------------------------------------------------------------- */
  92. /*** inline functions ****************************************************************************/
  93. /* --------------------------------------------------------------------------------------------- */
  94. #endif /* MC__DIALOG_H */