wtools.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /** \file wtools.h
  2. * \brief Header: widget based utility functions
  3. */
  4. #ifndef MC__WTOOLS_H
  5. #define MC__WTOOLS_H
  6. /*** typedefs(not structures) and defined constants **********************************************/
  7. /* Pass this as def_text to request a password */
  8. #define INPUT_PASSWORD ((char *) -1)
  9. /* Use this as header for message() - it expands to "Error" */
  10. #define MSG_ERROR ((char *) -1)
  11. typedef struct status_msg_t status_msg_t;
  12. #define STATUS_MSG(x) ((status_msg_t *)(x))
  13. typedef struct simple_status_msg_t simple_status_msg_t;
  14. #define SIMPLE_STATUS_MSG(x) ((simple_status_msg_t *)(x))
  15. typedef void (*status_msg_cb) (status_msg_t * sm);
  16. typedef int (*status_msg_update_cb) (status_msg_t * sm);
  17. /*** enums ***************************************************************************************/
  18. /* flags for message() and query_dialog() */
  19. enum
  20. {
  21. D_NORMAL = 0,
  22. D_ERROR = (1 << 0),
  23. D_CENTER = (1 << 1)
  24. } /* dialog options */ ;
  25. /*** structures declarations (and typedefs of structures)*****************************************/
  26. /* Base class for status message of long-time operations.
  27. Useful to show progress of long-time operations and interrupt it. */
  28. struct status_msg_t
  29. {
  30. WDialog *dlg; /* pointer to status message dialog */
  31. gint64 start; /* start time in microseconds */
  32. gint64 delay; /* delay before raise the 'dlg' in microseconds */
  33. gboolean block; /* how to get event using tty_get_event() */
  34. status_msg_cb init; /* callback to init derived classes */
  35. status_msg_update_cb update; /* callback to update dlg */
  36. status_msg_cb deinit; /* callback to deinit derived classes */
  37. };
  38. /* Simple status message with label and 'Abort' button */
  39. struct simple_status_msg_t
  40. {
  41. status_msg_t status_msg; /* base class */
  42. WLabel *label;
  43. };
  44. /*** global variables defined in .c file *********************************************************/
  45. /*** declarations of public functions ************************************************************/
  46. /* The input dialogs */
  47. char *input_dialog (const char *header, const char *text,
  48. const char *history_name, const char *def_text,
  49. input_complete_t completion_flags);
  50. char *input_dialog_help (const char *header, const char *text, const char *help,
  51. const char *history_name, const char *def_text, gboolean strip_password,
  52. input_complete_t completion_flags);
  53. char *input_expand_dialog (const char *header, const char *text, const char *history_name,
  54. const char *def_text, input_complete_t completion_flags);
  55. int query_dialog (const char *header, const char *text, int flags, int count, ...);
  56. void query_set_sel (int new_sel);
  57. /* Create message box but don't dismiss it yet, not background safe */
  58. /* *INDENT-OFF* */
  59. WDialog *create_message (int flags, const char *title, const char *text, ...)
  60. G_GNUC_PRINTF (3, 4);
  61. /* Show message box, background safe */
  62. void message (int flags, const char *title, const char *text, ...) G_GNUC_PRINTF (3, 4);
  63. /* *INDENT-ON* */
  64. gboolean mc_error_message (GError ** mcerror, int *code);
  65. status_msg_t *status_msg_create (const char *title, double delay, status_msg_cb init_cb,
  66. status_msg_update_cb update_cb, status_msg_cb deinit_cb);
  67. void status_msg_destroy (status_msg_t * sm);
  68. void status_msg_init (status_msg_t * sm, const char *title, double delay, status_msg_cb init_cb,
  69. status_msg_update_cb update_cb, status_msg_cb deinit_cb);
  70. void status_msg_deinit (status_msg_t * sm);
  71. int status_msg_common_update (status_msg_t * sm);
  72. void simple_status_msg_init_cb (status_msg_t * sm);
  73. /*** inline functions ****************************************************************************/
  74. #endif /* MC__WTOOLS_H */