dialog.h 8.5 KB

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