wtools.h 3.8 KB

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