wtools.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, const char *history_name,
  48. const char *def_text, input_complete_t completion_flags);
  49. char *input_dialog_help (const char *header, const char *text, const char *help,
  50. const char *history_name, const char *def_text, gboolean strip_password,
  51. input_complete_t completion_flags);
  52. char *input_expand_dialog (const char *header, const char *text, const char *history_name,
  53. const char *def_text, input_complete_t completion_flags);
  54. int query_dialog (const char *header, const char *text, int flags, int count, ...);
  55. void query_set_sel (int new_sel);
  56. /* Create message box but don't dismiss it yet, not background safe */
  57. /* *INDENT-OFF* */
  58. WDialog *create_message (int flags, const char *title, const char *text, ...) G_GNUC_PRINTF (3, 4);
  59. /* Show message box, background safe */
  60. void message (int flags, const char *title, const char *text, ...) G_GNUC_PRINTF (3, 4);
  61. /* *INDENT-ON* */
  62. gboolean mc_error_message (GError **mcerror, int *code);
  63. status_msg_t *status_msg_create (const char *title, double delay, status_msg_cb init_cb,
  64. status_msg_update_cb update_cb, status_msg_cb deinit_cb);
  65. void status_msg_destroy (status_msg_t *sm);
  66. void status_msg_init (status_msg_t *sm, 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_deinit (status_msg_t *sm);
  69. int status_msg_common_update (status_msg_t *sm);
  70. void simple_status_msg_init_cb (status_msg_t *sm);
  71. /*** inline functions ****************************************************************************/
  72. #endif /* MC__WTOOLS_H */