dialog.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* Dialog box features module for the Midnight Commander
  2. Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
  3. 2005, 2007, 2009, 2010 Free Software Foundation
  4. Authors: 1994, 1995 Radek Doulik, Miguel de Icaza
  5. 2009, 2010 Andrew Borodin
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. /** \file dialog.h
  19. * \brief Header: dialog box features module
  20. */
  21. #ifndef MC__DIALOG_H
  22. #define MC__DIALOG_H
  23. #include <sys/types.h> /* size_t */
  24. #include "lib/global.h"
  25. #include "lib/hook.h" /* hook_t */
  26. #include "lib/keybind.h" /* global_keymap_t */
  27. /*** defined constants ***************************************************************************/
  28. /* Common return values */
  29. #define B_EXIT 0
  30. #define B_CANCEL 1
  31. #define B_ENTER 2
  32. #define B_HELP 3
  33. #define B_USER 100
  34. #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
  35. /*** enums ***************************************************************************************/
  36. /* Dialog messages */
  37. typedef enum
  38. {
  39. DLG_INIT = 0, /* Initialize dialog */
  40. DLG_IDLE = 1, /* The idle state is active */
  41. DLG_DRAW = 2, /* Draw dialog on screen */
  42. DLG_FOCUS = 3, /* A widget has got focus */
  43. DLG_UNFOCUS = 4, /* A widget has been unfocused */
  44. DLG_RESIZE = 5, /* Window size has changed */
  45. DLG_KEY = 6, /* Key before sending to widget */
  46. DLG_HOTKEY_HANDLED = 7, /* A widget has got the hotkey */
  47. DLG_POST_KEY = 8, /* The key has been handled */
  48. DLG_UNHANDLED_KEY = 9, /* Key that no widget handled */
  49. DLG_ACTION = 10, /* State of check- and radioboxes has changed
  50. * and listbox current entry has changed */
  51. DLG_VALIDATE = 11, /* Dialog is to be closed */
  52. DLG_END = 12 /* Shut down dialog */
  53. } dlg_msg_t;
  54. /* Flags for create_dlg */
  55. typedef enum
  56. {
  57. DLG_REVERSE = (1 << 5), /* Tab order is opposite to the add order */
  58. DLG_WANT_TAB = (1 << 4), /* Should the tab key be sent to the dialog? */
  59. DLG_WANT_IDLE = (1 << 3), /* Dialog wants idle events */
  60. DLG_COMPACT = (1 << 2), /* Suppress spaces around the frame */
  61. DLG_TRYUP = (1 << 1), /* Try to move two lines up the dialog */
  62. DLG_CENTER = (1 << 0), /* Center the dialog */
  63. DLG_NONE = 0 /* No options */
  64. } dlg_flags_t;
  65. /* Dialog state */
  66. typedef enum
  67. {
  68. DLG_ACTIVE = 0, /* Dialog is visible and active */
  69. DLG_SUSPENDED = 1, /* Dialog is suspended */
  70. DLG_CLOSED = 2 /* Dialog is closed */
  71. } dlg_state_t;
  72. /* Dialog color constants */
  73. typedef enum
  74. {
  75. DLG_COLOR_NORMAL,
  76. DLG_COLOR_FOCUS,
  77. DLG_COLOR_HOT_NORMAL,
  78. DLG_COLOR_HOT_FOCUS,
  79. DLG_COLOR_TITLE,
  80. DLG_COLOR_COUNT
  81. } dlg_colors_enum_t;
  82. /*** typedefs(not structures) ********************************************************************/
  83. /* get string representation of shortcut assigned with command */
  84. /* as menu is a widget of dialog, ask dialog about shortcut string */
  85. typedef char *(*dlg_shortcut_str) (unsigned long command);
  86. /* get dialog name to show in dialog list */
  87. typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
  88. typedef int dlg_colors_t[DLG_COLOR_COUNT];
  89. /* Dialog callback */
  90. typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
  91. /* menu command execution */
  92. typedef cb_ret_t (*menu_exec_fn) (int command);
  93. /*** structures declarations (and typedefs of structures)*****************************************/
  94. struct Dlg_head
  95. {
  96. /* Set by the user */
  97. gboolean modal; /* type of dialog: modal or not */
  98. dlg_flags_t flags; /* User flags */
  99. const char *help_ctx; /* Name of the help entry */
  100. dlg_colors_t color; /* Color set. Unused in viewer and editor */
  101. char *title; /* Title of the dialog */
  102. /* Set and received by the user */
  103. int ret_value; /* Result of run_dlg() */
  104. /* Geometry */
  105. int x, y; /* Position relative to screen origin */
  106. int cols, lines; /* Width and height of the window */
  107. /* Internal flags */
  108. dlg_state_t state;
  109. gboolean fullscreen; /* Parents dialogs don't need refresh */
  110. gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
  111. int mouse_status; /* For the autorepeat status of the mouse */
  112. /* Internal variables */
  113. GList *widgets; /* widgets list */
  114. GList *current; /* Curently active widget */
  115. void *data; /* Data can be passed to dialog */
  116. char *event_group; /* Name of event group for this dialog */
  117. dlg_cb_fn callback;
  118. dlg_shortcut_str get_shortcut; /* Shortcut string */
  119. dlg_title_str get_title; /* useless for modal dialogs */
  120. };
  121. /*** global variables defined in .c file *********************************************************/
  122. /* Color styles for normal and error dialogs */
  123. extern dlg_colors_t dialog_colors;
  124. extern dlg_colors_t alarm_colors;
  125. /* some widget decoration */
  126. extern char *widget_btn_left_sign;
  127. extern char *widget_btn_right_sign;
  128. extern char *widget_btn_left_default_sign;
  129. extern char *widget_btn_right_default_sign;
  130. extern int widget_edit_tab_first;
  131. extern int widget_edit_tab_middle;
  132. extern int widget_edit_tab_last;
  133. extern int widget_edit_eol_char;
  134. extern GList *top_dlg;
  135. /* A hook list for idle events */
  136. extern hook_t *idle_hook;
  137. extern int fast_refresh;
  138. extern int mouse_close_dialog;
  139. extern const global_keymap_t *dialog_map;
  140. /*** declarations of public functions ************************************************************/
  141. /* draw box in window */
  142. void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
  143. /* Creates a dialog head */
  144. Dlg_head *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
  145. const int *colors, dlg_cb_fn callback,
  146. const char *help_ctx, const char *title, dlg_flags_t flags);
  147. void dlg_set_default_colors (void);
  148. void dlg_load_skin_decor (void);
  149. int add_widget_autopos (Dlg_head * dest, void *w, widget_pos_flags_t pos_flags);
  150. int add_widget (Dlg_head * dest, void *w);
  151. /* sets size of dialog, leaving positioning to automatic mehtods
  152. according to dialog flags */
  153. void dlg_set_size (Dlg_head * h, int lines, int cols);
  154. /* this function allows to set dialog position */
  155. void dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2);
  156. void init_dlg (Dlg_head * h);
  157. int run_dlg (Dlg_head * d);
  158. void destroy_dlg (Dlg_head * h);
  159. void dlg_run_done (Dlg_head * h);
  160. void dlg_save_history (Dlg_head * h);
  161. void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event);
  162. char *dlg_get_title (const Dlg_head * h, size_t len);
  163. /* To activate/deactivate the idle message generation */
  164. void set_idle_proc (Dlg_head * d, int enable);
  165. void dlg_redraw (Dlg_head * h);
  166. void dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, gboolean reverse);
  167. /* Default callback for dialogs */
  168. cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
  169. /* Default paint routine for dialogs */
  170. void common_dialog_repaint (Dlg_head * h);
  171. void dlg_replace_widget (Widget * old, Widget * new);
  172. int dlg_overlap (Widget * a, Widget * b);
  173. void dlg_erase (Dlg_head * h);
  174. void dlg_stop (Dlg_head * h);
  175. /* Widget selection */
  176. void dlg_select_widget (void *widget);
  177. void dlg_one_up (Dlg_head * h);
  178. void dlg_one_down (Dlg_head * h);
  179. int dlg_focus (Dlg_head * h);
  180. Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
  181. Widget *dlg_find_by_id (const Dlg_head * h, unsigned int id);
  182. void dlg_select_by_id (const Dlg_head * h, unsigned int id);
  183. /* Redraw all dialogs */
  184. void do_refresh (void);
  185. /* Used in load_prompt() */
  186. void update_cursor (Dlg_head * h);
  187. /*** inline functions ****************************************************************************/
  188. /* Return TRUE if the widget is active, FALSE otherwise */
  189. static inline gboolean
  190. dlg_widget_active (void *w)
  191. {
  192. Widget *w1 = (Widget *) w;
  193. return ((Widget *) w1->owner->current->data == w1);
  194. }
  195. static inline unsigned int
  196. dlg_get_current_widget_id (const struct Dlg_head *h)
  197. {
  198. return ((Widget *) h->current->data)->id;
  199. }
  200. #endif /* MC__DIALOG_H */