-
Notifications
You must be signed in to change notification settings - Fork 21
/
osdialog.h
122 lines (87 loc) · 3.32 KB
/
osdialog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
#ifndef OSDIALOG_MALLOC
#define OSDIALOG_MALLOC malloc
#endif
#ifndef OSDIALOG_FREE
#define OSDIALOG_FREE free
#endif
char* osdialog_strdup(const char* s);
char* osdialog_strndup(const char* s, size_t n);
typedef enum {
OSDIALOG_INFO,
OSDIALOG_WARNING,
OSDIALOG_ERROR,
} osdialog_message_level;
typedef enum {
OSDIALOG_OK,
OSDIALOG_OK_CANCEL,
OSDIALOG_YES_NO,
} osdialog_message_buttons;
/** Launches a message box.
Returns 1 if the "OK" or "Yes" button was pressed.
*/
int osdialog_message(osdialog_message_level level, osdialog_message_buttons buttons, const char* message);
/** Launches an input prompt with an "OK" and "Cancel" button.
`text` is the default string to fill the input box.
Returns the entered text, or NULL if the dialog was cancelled.
If the returned result is not NULL, caller must free() it.
*/
char* osdialog_prompt(osdialog_message_level level, const char* message, const char* text);
/** Linked list of patterns. */
typedef struct osdialog_filter_patterns {
char* pattern;
struct osdialog_filter_patterns* next;
} osdialog_filter_patterns;
/** Linked list of file filters. */
typedef struct osdialog_filters {
char* name;
osdialog_filter_patterns* patterns;
struct osdialog_filters* next;
} osdialog_filters;
/** Parses a filter string.
Example: "Source:c,cpp,m;Header:h,hpp"
Caller must eventually free with osdialog_filters_free().
*/
osdialog_filters* osdialog_filters_parse(const char* str);
void osdialog_filter_patterns_free(osdialog_filter_patterns* patterns);
void osdialog_filters_free(osdialog_filters* filters);
typedef enum {
OSDIALOG_OPEN,
OSDIALOG_OPEN_DIR,
OSDIALOG_SAVE,
} osdialog_file_action;
/** Launches a file dialog and returns the selected path or NULL if nothing was selected.
`path` is the default folder the file dialog will attempt to open in, or NULL for the OS's default.
`filename` is the default text that will appear in the filename input, or NULL for the OS's default. Relevant to save dialog only.
`filters` is a list of patterns to filter the file selection, or NULL.
Returns the selected file, or NULL if the dialog was cancelled.
If the return result is not NULL, caller must free() it.
*/
char* osdialog_file(osdialog_file_action action, const char* path, const char* filename, osdialog_filters* filters);
typedef struct {
uint8_t r, g, b, a;
} osdialog_color;
/** Launches an RGBA color picker dialog and sets `color` to the selected color.
Returns 1 if "OK" was pressed.
`color` should be set to the initial color before calling. It is only overwritten if the user selects "OK".
`opacity` enables the opacity slider by setting to 1. Not supported on Windows.
*/
int osdialog_color_picker(osdialog_color* color, int opacity);
typedef void* (*osdialog_save_callback)();
typedef void (*osdialog_restore_callback)(void* ptr);
/** Sets callback that is called before each dialog is opened.
This is useful for saving/restoring global state that an OS dialog might modify.
*/
void osdialog_set_save_callback(osdialog_save_callback cb);
/** Sets callback that is called after each dialog is closed.
The pointer returned by osdialog_save_callback() is passed as an argument to osdialog_restore_callback().
*/
void osdialog_set_restore_callback(osdialog_restore_callback cb);
#ifdef __cplusplus
}
#endif