dialog.h 6.5 KB

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