dialog.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. #include "lib/tty/mouse.h" /* mouse_h */
  14. /*** typedefs(not structures) and defined constants **********************************************/
  15. #define DIALOG(x) ((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. /* Flags for dlg_create */
  25. typedef enum
  26. {
  27. DLG_NONE = 0, /* No options */
  28. DLG_CENTER = (1 << 0), /* Center the dialog */
  29. DLG_TRYUP = (1 << 1), /* Try to move two lines up the dialog */
  30. DLG_COMPACT = (1 << 2), /* Suppress spaces around the frame */
  31. DLG_WANT_TAB = (1 << 3) /* Should the tab key be sent to the dialog? */
  32. } dlg_flags_t;
  33. /* Dialog state */
  34. typedef enum
  35. {
  36. DLG_CONSTRUCT = 0, /* Dialog has been constructed but not run yet */
  37. DLG_ACTIVE = 1, /* Dialog is visible and active */
  38. DLG_SUSPENDED = 2, /* Dialog is suspended */
  39. DLG_CLOSED = 3 /* Dialog is closed */
  40. } dlg_state_t;
  41. /* Dialog color constants */
  42. typedef enum
  43. {
  44. DLG_COLOR_NORMAL,
  45. DLG_COLOR_FOCUS,
  46. DLG_COLOR_HOT_NORMAL,
  47. DLG_COLOR_HOT_FOCUS,
  48. DLG_COLOR_TITLE,
  49. DLG_COLOR_COUNT
  50. } dlg_colors_enum_t;
  51. /*** typedefs(not structures) ********************************************************************/
  52. /* get string representation of shortcut assigned with command */
  53. /* as menu is a widget of dialog, ask dialog about shortcut string */
  54. typedef char *(*dlg_shortcut_str) (unsigned long command);
  55. /* get dialog name to show in dialog list */
  56. typedef char *(*dlg_title_str) (const WDialog * h, size_t len);
  57. typedef int dlg_colors_t[DLG_COLOR_COUNT];
  58. /* menu command execution */
  59. typedef cb_ret_t (*menu_exec_fn) (int command);
  60. /*** structures declarations (and typedefs of structures)*****************************************/
  61. struct WDialog
  62. {
  63. Widget widget;
  64. /* Set by the user */
  65. gboolean modal; /* type of dialog: modal or not */
  66. dlg_flags_t flags; /* User flags */
  67. const char *help_ctx; /* Name of the help entry */
  68. const int *color; /* Color set. Unused in viewer and editor */
  69. char *title; /* Title of the dialog */
  70. /* Set and received by the user */
  71. int ret_value; /* Result of dlg_run() */
  72. /* Internal flags */
  73. dlg_state_t state;
  74. gboolean fullscreen; /* Parents dialogs don't need refresh */
  75. gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
  76. int mouse_status; /* For the autorepeat status of the mouse */
  77. /* Internal variables */
  78. GList *widgets; /* widgets list */
  79. GList *current; /* Currently active widget */
  80. unsigned long widget_id; /* maximum id of all widgets */
  81. void *data; /* Data can be passed to dialog */
  82. char *event_group; /* Name of event group for this dialog */
  83. dlg_shortcut_str get_shortcut; /* Shortcut string */
  84. dlg_title_str get_title; /* useless for modal dialogs */
  85. };
  86. /*** global variables defined in .c file *********************************************************/
  87. /* Color styles for normal and error dialogs */
  88. extern dlg_colors_t dialog_colors;
  89. extern dlg_colors_t alarm_colors;
  90. extern dlg_colors_t listbox_colors;
  91. extern GList *top_dlg;
  92. /* A hook list for idle events */
  93. extern hook_t *idle_hook;
  94. extern int fast_refresh;
  95. extern int mouse_close_dialog;
  96. extern const global_keymap_t *dialog_map;
  97. /*** declarations of public functions ************************************************************/
  98. /* Creates a dialog head */
  99. WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
  100. const int *colors, widget_cb_fn callback, mouse_h mouse_handler,
  101. const char *help_ctx, const char *title, dlg_flags_t flags);
  102. void dlg_set_default_colors (void);
  103. unsigned long add_widget_autopos (WDialog * dest, void *w, widget_pos_flags_t pos_flags,
  104. const void *before);
  105. unsigned long add_widget (WDialog * dest, void *w);
  106. unsigned long add_widget_before (WDialog * h, void *w, void *before);
  107. void del_widget (void *w);
  108. /* sets size of dialog, leaving positioning to automatic mehtods
  109. according to dialog flags */
  110. void dlg_set_size (WDialog * h, int lines, int cols);
  111. /* this function allows to set dialog position */
  112. void dlg_set_position (WDialog * h, int y1, int x1, int y2, int x2);
  113. void dlg_init (WDialog * h);
  114. int dlg_run (WDialog * d);
  115. void dlg_destroy (WDialog * h);
  116. void dlg_run_done (WDialog * h);
  117. void dlg_save_history (WDialog * h);
  118. void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
  119. char *dlg_get_title (const WDialog * h, size_t len);
  120. void dlg_redraw (WDialog * h);
  121. void dlg_broadcast_msg (WDialog * h, widget_msg_t message);
  122. /* Default callback for dialogs */
  123. cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
  124. /* Default paint routine for dialogs */
  125. void dlg_default_repaint (WDialog * h);
  126. void dlg_erase (WDialog * h);
  127. void dlg_stop (WDialog * h);
  128. /* Widget selection */
  129. void dlg_select_widget (void *w);
  130. void dlg_set_top_widget (void *w);
  131. void dlg_one_up (WDialog * h);
  132. void dlg_one_down (WDialog * h);
  133. gboolean dlg_focus (WDialog * h);
  134. Widget *find_widget_type (const WDialog * h, widget_cb_fn callback);
  135. Widget *dlg_find_by_id (const WDialog * h, unsigned long id);
  136. void dlg_select_by_id (const WDialog * h, unsigned long id);
  137. /* Redraw all dialogs */
  138. void do_refresh (void);
  139. /* Used in load_prompt() */
  140. void update_cursor (WDialog * h);
  141. /* --------------------------------------------------------------------------------------------- */
  142. /*** inline functions ****************************************************************************/
  143. /* --------------------------------------------------------------------------------------------- */
  144. static inline unsigned long
  145. dlg_get_current_widget_id (const struct WDialog *h)
  146. {
  147. return WIDGET (h->current->data)->id;
  148. }
  149. /* --------------------------------------------------------------------------------------------- */
  150. #endif /* MC__DIALOG_H */