1 /*
2  *                           0BSD
3  *
4  *                    BSD Zero Clause License
5  *
6  *  Copyright (c) 2019 Hermann Meyer
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted.
10 
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  *
19  */
20 
21 #pragma once
22 
23 #ifndef XMESSAGE_DIALOG_H_
24 #define XMESSAGE_DIALOG_H_
25 
26 #include "xwidgets.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 enum {
33     INFO_BOX,
34     WARNING_BOX,
35     ERROR_BOX,
36     QUESTION_BOX,
37     SELECTION_BOX,
38     ENTRY_BOX,
39 };
40 
41 typedef struct {
42     int response;
43     int message_type;
44     unsigned int width;
45     unsigned int height;
46     unsigned int lin;
47     Widget_t *text_entry;
48     Pixmap *icon;
49     char **message;
50     unsigned int sel;
51     char **choices;
52 } MessageBox;
53 
54 /**
55  * @brief open_message_dialog  - open a non blocking dialog window,
56  * lines in message chould be separated by the character "|"
57  * choices for the SELECTION_BOX should be separated as well with the
58  * character "|". message and/or choices could be NULL when not needed.
59  * To fetch the response of a dialog, connect to the dialog_callback
60  * supported "styles" been
61  * \n
62  * INFO_BOX - a message dialog display a info text
63  * \n
64  * WARNING_BOX - a message dialog display a warning
65  * \n
66  * ERROR_BOX - a message dialog display a error message
67  * \n
68  * QUESTION_BOX - a no/yes dialog message
69  * \n
70  * SELECTION_BOX - a dialog to select between multiple options
71  * \n
72  * ENTRY_BOX - a dialog to get text input
73  * @return Widget_t*           - pointer to the Widget_t struct
74  */
75 
76 Widget_t *open_message_dialog(Widget_t *w, int style, const char *title,
77                               const char *message, const char *choices);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif //XMESSAGE_DIALOG_H_
84