NvDialog 0.10.1
A cross-platform modal dialogs library for C/C++ that uses the native OS theme.
Loading...
Searching...
No Matches
nvdialog_core.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2025 Aggelos Tselios
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25#pragma once
26
27#ifndef __nvdialog_core_h__
28#define __nvdialog_core_h__ 1
29
30#include "nvdialog_types.h"
31#include "nvdialog_platform.h"
32
33/**
34 * @brief An opaque representation of a window object.
35 * @warning This is not cross platform nor portable. It can be set to almost
36 * anything and nvdialog will accept it. Only use this if you're sure that what
37 * you're giving the library is valid.
38 */
39typedef void *NvdParentWindow;
40
41/**
42 * @brief Initializes NvDialog.
43 *
44 * This function initializes NvDialog. It's the first function that should be
45 * called when you create your program as without it, you cannot create any
46 * dialogs or use the library at all.
47 *
48 * @details Depending on the platform, this function does a series of things (in random order):
49 * - If any optional libraries are to be loaded, they're detected and loaded at this stage.
50 * - All function pointers for each platform are initialized now.
51 * - It initializes some internal state for future use.
52 * - Any backends that need special setup are also initialized now.
53 *
54 * @note You should call this function to the same thread you're creating your
55 * dialogs from. If you also happen to use a library used by NvDialog as the
56 * backend, make sure that the two libraries stay in the same thread to avoid
57 * race conditions.
58 * @since v0.1.0
59 * @ingroup Core
60 * @return 0 on success, else a negative error code indicating failure.
61 */
63
64/**
65 * @brief Sets the application name to use inside NvDialog.
66 * @details This function sets the application name that NvDialog will use if an
67 * application name is needed. By default, the application name is set to
68 * "NvDialog Application". The application name is used in notifications, so it
69 * is important to set the actual application name if you wish to use them.
70 * @note Make sure the given string will not be mutated during the lifetime of the program.
71 * @ingroup Core
72 * @param application_name The application name to use.
73 * @since v0.5.0
74 */
75NVD_API void nvd_set_application_name(const char *application_name);
76
77/**
78 * @brief Returns the application name set inside NvDialog.
79 * @return The application name.
80 * @ingroup Core
81 * @since v0.5.0
82 */
84
85/**
86 * @brief Returns the argv[0] given to nvdialog.
87 * @details This function returns the parameter passed to nvdialog during
88 * nvd_init. It is mainly intended to be used internally.
89 * @deprecated This function is deprecated as of v0.8.1 and will only return NULL
90 * @ingroup Core
91 * @return The argv[0] given to nvdialog on success, otherwise NULL.
92 */
93#if __GNUC__
94 __attribute__((deprecated("Since v0.8.1 this function always returns NULL since the library no longer asks for the command line.")))
95#endif
96NVD_API const char *nvd_get_argv(void);
97
98/**
99 * @brief Sets a window as the parent of all dialogs created from NvDialog.
100 * @details Using the parameter given, a window will be set as the parent of all
101 * dialogs that are created from within the library. The window has to match the
102 * window type used by the backend.
103 * @warning This is a very dangerous operation, and may not work as expected. There are a series of guarantees
104 * you must have to make sure things don't go bad:
105 * - You handle the pointer given so that it matches the backend's expectation. For example, you'll use an HWND pointer on Windows, GtkWindow on Linux, and so on.
106 * - The window lives as long as any dialog will be displayed.
107 * - The window is allowed to be used by the backend at any arbitrary time during the dialog's lifetime, since no guarantees can be made.
108 * @ingroup Core
109 * @param parent The window to set as the parent.
110 * @return 0 on success, otherwise -1, call nvd_get_error() for more.
111 */
113
114/**
115 * @brief Returns the window attached as the parent of all dialogs of NvDialog.
116 * @ingroup Core
117 * @return The currently set parent window, or NULL if no parent window is
118 * currently set.
119 */
121
122/**
123 * @brief Unmarks the window set from @ref nvd_set_parent as the parent window.
124 * @ingroup Core
125 *
126 * This will reset the changes made by @ref nvd_set_parent, by
127 * unmarking the window that is given as the parent from NvDialog.
128 */
130
131/**
132 * @brief Deletes an object creates by NvDialog.
133 * @details Call this function when you are no longer interested in using the
134 * parameter passed anymore, to free up any resources occupied by the object.
135 * Note that calling this in the middle of an operation will cause use after
136 * free.
137 * @ingroup Core
138 * @param object The object to be deleted.
139 * @note @ref object may be NULL, although this will print a small warning on the command line.
140 */
141NVD_API void nvd_free_object(void *object);
142
143#endif /* __nvdialog_core_h__ */
#define NVD_API
Definition nvdialog.h:113
NVD_API const char * nvd_get_argv(void)
Returns the argv[0] given to nvdialog.
NVD_API void nvd_free_object(void *object)
Deletes an object creates by NvDialog.
void * NvdParentWindow
An opaque representation of a window object.
Definition nvdialog_core.h:39
NVD_API const char * nvd_get_application_name()
Returns the application name set inside NvDialog.
NVD_API NvdParentWindow nvd_get_parent(void)
Returns the window attached as the parent of all dialogs of NvDialog.
NVD_API void nvd_delete_parent(void)
Unmarks the window set from nvd_set_parent as the parent window.
NVD_API int nvd_set_parent(NvdParentWindow parent)
Sets a window as the parent of all dialogs created from NvDialog.
NVD_API void nvd_set_application_name(const char *application_name)
Sets the application name to use inside NvDialog.
NVD_API int nvd_init()
Initializes NvDialog.