dialog.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. /*** defined constants ***************************************************************************/
  14. /* Common return values */
  15. #define B_EXIT 0
  16. #define B_CANCEL 1
  17. #define B_ENTER 2
  18. #define B_HELP 3
  19. #define B_USER 100
  20. #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
  21. /*** enums ***************************************************************************************/
  22. /* Dialog messages */
  23. typedef enum
  24. {
  25. DLG_INIT = 0, /* Initialize dialog */
  26. DLG_IDLE = 1, /* The idle state is active */
  27. DLG_DRAW = 2, /* Draw dialog on screen */
  28. DLG_FOCUS = 3, /* A widget has got focus */
  29. DLG_UNFOCUS = 4, /* A widget has been unfocused */
  30. DLG_RESIZE = 5, /* Window size has changed */
  31. DLG_KEY = 6, /* Key before sending to widget */
  32. DLG_HOTKEY_HANDLED = 7, /* A widget has got the hotkey */
  33. DLG_POST_KEY = 8, /* The key has been handled */
  34. DLG_UNHANDLED_KEY = 9, /* Key that no widget handled */
  35. DLG_ACTION = 10, /* State of check- and radioboxes has changed
  36. * and listbox current entry has changed */
  37. DLG_VALIDATE = 11, /* Dialog is to be closed */
  38. DLG_END = 12 /* Shut down dialog */
  39. } dlg_msg_t;
  40. /* Flags for create_dlg */
  41. typedef enum
  42. {
  43. DLG_REVERSE = (1 << 5), /* Tab order is opposite to the add order */
  44. DLG_WANT_TAB = (1 << 4), /* Should the tab key be sent to the dialog? */
  45. DLG_WANT_IDLE = (1 << 3), /* Dialog wants idle events */
  46. DLG_COMPACT = (1 << 2), /* Suppress spaces around the frame */
  47. DLG_TRYUP = (1 << 1), /* Try to move two lines up the dialog */
  48. DLG_CENTER = (1 << 0), /* Center the dialog */
  49. DLG_NONE = 0 /* No options */
  50. } dlg_flags_t;
  51. /* Dialog state */
  52. typedef enum
  53. {
  54. DLG_ACTIVE = 0, /* Dialog is visible and active */
  55. DLG_SUSPENDED = 1, /* Dialog is suspended */
  56. DLG_CLOSED = 2 /* Dialog is closed */
  57. } dlg_state_t;
  58. /* Dialog color constants */
  59. typedef enum
  60. {
  61. DLG_COLOR_NORMAL,
  62. DLG_COLOR_FOCUS,
  63. DLG_COLOR_HOT_NORMAL,
  64. DLG_COLOR_HOT_FOCUS,
  65. DLG_COLOR_TITLE,
  66. DLG_COLOR_COUNT
  67. } dlg_colors_enum_t;
  68. /*** typedefs(not structures) ********************************************************************/
  69. /* get string representation of shortcut assigned with command */
  70. /* as menu is a widget of dialog, ask dialog about shortcut string */
  71. typedef char *(*dlg_shortcut_str) (unsigned long command);
  72. /* get dialog name to show in dialog list */
  73. typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
  74. typedef int dlg_colors_t[DLG_COLOR_COUNT];
  75. /* Dialog callback */
  76. typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
  77. /* menu command execution */
  78. typedef cb_ret_t (*menu_exec_fn) (int command);
  79. /*** structures declarations (and typedefs of structures)*****************************************/
  80. struct Dlg_head
  81. {
  82. /* Set by the user */
  83. gboolean modal; /* type of dialog: modal or not */
  84. dlg_flags_t flags; /* User flags */
  85. const char *help_ctx; /* Name of the help entry */
  86. dlg_colors_t color; /* Color set. Unused in viewer and editor */
  87. char *title; /* Title of the dialog */
  88. /* Set and received by the user */
  89. int ret_value; /* Result of run_dlg() */
  90. /* Geometry */
  91. int x, y; /* Position relative to screen origin */
  92. int cols, lines; /* Width and height of the window */
  93. /* Internal flags */
  94. dlg_state_t state;
  95. gboolean fullscreen; /* Parents dialogs don't need refresh */
  96. gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
  97. int mouse_status; /* For the autorepeat status of the mouse */
  98. /* Internal variables */
  99. GList *widgets; /* widgets list */
  100. GList *current; /* Curently active widget */
  101. void *data; /* Data can be passed to dialog */
  102. char *event_group; /* Name of event group for this dialog */
  103. dlg_cb_fn callback;
  104. dlg_shortcut_str get_shortcut; /* Shortcut string */
  105. dlg_title_str get_title; /* useless for modal dialogs */
  106. };
  107. /*** global variables defined in .c file *********************************************************/
  108. /* Color styles for normal and error dialogs */
  109. extern dlg_colors_t dialog_colors;
  110. extern dlg_colors_t alarm_colors;
  111. extern GList *top_dlg;
  112. /* A hook list for idle events */
  113. extern hook_t *idle_hook;
  114. extern int fast_refresh;
  115. extern int mouse_close_dialog;
  116. extern const global_keymap_t *dialog_map;
  117. /*** declarations of public functions ************************************************************/
  118. /* draw box in window */
  119. void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
  120. /* Creates a dialog head */
  121. Dlg_head *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
  122. const int *colors, dlg_cb_fn callback,
  123. const char *help_ctx, const char *title, dlg_flags_t flags);
  124. void dlg_set_default_colors (void);
  125. int add_widget_autopos (Dlg_head * dest, void *w, widget_pos_flags_t pos_flags);
  126. int add_widget (Dlg_head * dest, void *w);
  127. /* sets size of dialog, leaving positioning to automatic mehtods
  128. according to dialog flags */
  129. void dlg_set_size (Dlg_head * h, int lines, int cols);
  130. /* this function allows to set dialog position */
  131. void dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2);
  132. void init_dlg (Dlg_head * h);
  133. int run_dlg (Dlg_head * d);
  134. void destroy_dlg (Dlg_head * h);
  135. void dlg_run_done (Dlg_head * h);
  136. void dlg_save_history (Dlg_head * h);
  137. void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event);
  138. char *dlg_get_title (const Dlg_head * h, size_t len);
  139. /* To activate/deactivate the idle message generation */
  140. void set_idle_proc (Dlg_head * d, int enable);
  141. void dlg_redraw (Dlg_head * h);
  142. void dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, gboolean reverse);
  143. /* Default callback for dialogs */
  144. cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
  145. /* Default paint routine for dialogs */
  146. void common_dialog_repaint (Dlg_head * h);
  147. void dlg_replace_widget (Widget * old, Widget * new);
  148. int dlg_overlap (Widget * a, Widget * b);
  149. void dlg_erase (Dlg_head * h);
  150. void dlg_stop (Dlg_head * h);
  151. /* Widget selection */
  152. void dlg_select_widget (void *widget);
  153. void dlg_one_up (Dlg_head * h);
  154. void dlg_one_down (Dlg_head * h);
  155. int dlg_focus (Dlg_head * h);
  156. Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
  157. Widget *dlg_find_by_id (const Dlg_head * h, unsigned int id);
  158. void dlg_select_by_id (const Dlg_head * h, unsigned int id);
  159. /* Redraw all dialogs */
  160. void do_refresh (void);
  161. /* Used in load_prompt() */
  162. void update_cursor (Dlg_head * h);
  163. /*** inline functions ****************************************************************************/
  164. /* Return TRUE if the widget is active, FALSE otherwise */
  165. static inline gboolean
  166. dlg_widget_active (void *w)
  167. {
  168. Widget *w1 = (Widget *) w;
  169. return ((Widget *) w1->owner->current->data == w1);
  170. }
  171. static inline unsigned int
  172. dlg_get_current_widget_id (const struct Dlg_head *h)
  173. {
  174. return ((Widget *) h->current->data)->id;
  175. }
  176. #endif /* MC__DIALOG_H */