2 * Copyright (c) 2005 Massachusetts Institute of Technology
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 #ifndef __KHIMAIRA_KHALERTS_H
28 #define __KHIMAIRA_KHALERTS_H
30 /*********************************************************************
31 Alerter and error reporting
32 **********************************************************************/
37 /*!\defgroup khui_alert Alerter and Error Reporting
40 #define KHUI_MAX_ALERT_COMMANDS 4
44 Describes an alert message that will be shown to the user in a
45 variety of ways depending on the state of the NetIDMgr
48 typedef struct tag_khui_alert {
49 khm_int32 magic; /*!< Magic number. Always set to
52 khm_int32 severity; /*!< The severity of the alert. One
53 of KHERR_ERROR, KHERR_WARNING or
54 KHERR_INFO. The default is
55 KHERR_INFO. Do not set directly.
56 Use khui_alert_set_severity(). */
58 khm_int32 alert_commands[KHUI_MAX_ALERT_COMMANDS];
59 /*!< The command buttons associated
61 khui_alert_add_command() to add a
62 command. The buttons will appear in
63 the order in which they were added.
64 The first button will be the
65 default. Each command should be a
66 known action identifier. */
67 khm_int32 n_alert_commands;
69 wchar_t * title; /*!< The title of the alert. Subject
70 to ::KHUI_MAXCCH_TITLE. Use
71 khui_alert_set_title() to set. Do
72 not modify directly. */
74 wchar_t * message; /*!< The main message of the alert.
75 Subject to ::KHUI_MAXCCH_MESSAGE.
76 Use khui_alert_set_message() to
77 set. Do not modify direcly. */
79 wchar_t * suggestion; /*!< A suggestion. Appears below
81 khui_alert_set_suggestion() to
82 set. Do not modify directly. */
88 khm_int32 flags; /*!< combination of
89 ::khui_alert_flags. Do not modify
92 kherr_context * err_context;
93 /*!< If non-NULL at the time the alert
94 window is shown, this indicates that
95 the alert window should provide an
96 error viewer for the given error
99 kherr_event * err_event;
100 /*!< If non-NULL at the time the alert
101 window is shown, this indicates that
102 the alert window should provide an
103 error viewer for the given error
104 event. If an \a err_context is also
105 given, the error viewer for the
106 context will be below this error. */
109 /*!< Once the alert is displayed to
110 the user, when the user clicks one
111 of the command buttons, the command
112 ID will be assigned here. */
114 int refcount; /* internal */
116 LDCL(struct tag_khui_alert); /* internal */
119 #define KHUI_ALERT_MAGIC 0x48c39ce9
121 /*! \brief Maximum number of characters in title including terminating NULL
123 #define KHUI_MAXCCH_TITLE 256
125 /*! \brief Maximum number of bytes in title including terminating NULL
127 #define KHUI_MAXCB_TITLE (KHUI_MAXCCH_TITLE * sizeof(wchar_t))
129 /*! \brief Maximum number of characters in message including terminating NULL
131 #define KHUI_MAXCCH_MESSAGE 1024
133 /*! \brief Maximum number of bytes in message including terminating NULL
135 #define KHUI_MAXCB_MESSAGE (KHUI_MAXCCH_MESSAGE * sizeof(wchar_t))
137 /*! \brief Maxumum number of characters in a suggestion including terminating NULL */
138 #define KHUI_MAXCCH_SUGGESTION 1024
140 /*! \brief Maximum number of bytes in a suggestion, including terminating NULL */
141 #define KHUI_MAXCB_SUGGESTION (KHUI_MAXCCH_SUGGESTION * sizeof(wchar_t))
143 /*! \brief Flags for an alert */
144 enum khui_alert_flags {
145 KHUI_ALERT_FLAG_FREE_STRUCT =0x00000001,
146 /*!< Internal. Free the structure once the alert is done. */
148 KHUI_ALERT_FLAG_FREE_TITLE =0x00000002,
149 /*!< Internal. Free the \a title field when the alert is done.*/
151 KHUI_ALERT_FLAG_FREE_MESSAGE =0x00000004,
152 /*!< Internal. Free the \a message field when the alert is done. */
154 KHUI_ALERT_FLAG_FREE_SUGGEST =0x00000008,
155 /*!< Internal. Free the \a suggest field when the alert is done */
157 KHUI_ALERT_FLAG_DEFACTION =0x00000010,
158 /*!< If the message is displayed as a balloon prompt, then perform
159 the default action when it is clicked. The default action is
160 the first action added to the alert. Cannot be used if there
161 are no actions or if ::KHUI_ALERT_FLAG_REQUEST_WINDOW is
164 KHUI_ALERT_FLAG_VALID_TARGET =0x00010000,
165 /*!< There is a valid target for the alert */
167 KHUI_ALERT_FLAG_VALID_ERROR =0x00020000,
168 /*!< There is a valid error context associated with the alert */
170 KHUI_ALERT_FLAG_DISPLAY_WINDOW =0x01000000,
171 /*!< The alert has been displayed in a window */
173 KHUI_ALERT_FLAG_DISPLAY_BALLOON =0x02000000,
174 /*!< The alert has been displayed in a ballon */
176 KHUI_ALERT_FLAG_REQUEST_WINDOW =0x04000000,
177 /*!< The alert should be displayed in a window */
179 KHUI_ALERT_FLAG_REQUEST_BALLOON =0x08000000,
180 /*!< The alert should be displayed in a balloon */
182 KHUI_ALERT_FLAG_MODAL =0x10000000,
183 /*!< Modal alert. Do not set direclty. */
185 KHUI_ALERT_FLAGMASK_RDWR =0x0C000010,
186 /*!< Bit mask of flags that can be set by khui_alert_set_flags() */
189 /*! \brief Create an empty alert object
191 The returned result is a held pointer to a ::khui_alert object.
192 Use khui_alert_release() to release the object.
194 KHMEXP khm_int32 KHMAPI
195 khui_alert_create_empty(khui_alert ** result);
197 /*! \brief Create a simple alert object
199 The returned result is a held pointer to a ::khui_alert object.
200 Use khui_alert_release() to release the object.
202 \param[in] title The title of the alert. (Required, Localized)
203 Limited by ::KHUI_MAXCCH_TITLE.
205 \param[in] message The message. (Required. Localized). Limited
206 by ::KHUI_MAXCCH_MESSAGE.
208 \param[in] severity One of ::tag_kherr_severity
210 \param[out] result Receives a held pointer to a ::khui_alert
211 object upon successful completion.
213 KHMEXP khm_int32 KHMAPI
214 khui_alert_create_simple(const wchar_t * title,
215 const wchar_t * message,
217 khui_alert ** result);
219 /*! \brief Set the title of an alert object
221 The title is limited by ::KHUI_MAXCCH_TITLE.
223 KHMEXP khm_int32 KHMAPI
224 khui_alert_set_title(khui_alert * alert,
225 const wchar_t * title);
227 /*! \brief Set the message of an alert object
229 The message is limited by ::KHUI_MAXCCH_MESSAGE.
231 KHMEXP khm_int32 KHMAPI
232 khui_alert_set_message(khui_alert * alert,
233 const wchar_t * message);
235 /*! \brief Set the suggestion of an alert object
237 The suggestion is limited by ::KHUI_MAXCCH_SUGGESTION
239 KHMEXP khm_int32 KHMAPI
240 khui_alert_set_suggestion(khui_alert * alert,
241 const wchar_t * suggestion);
243 /*! \brief Set the severity of the alert object
245 The severity value is one of ::tag_kherr_severity
247 KHMEXP khm_int32 KHMAPI
248 khui_alert_set_severity(khui_alert * alert,
251 /*! \brief Sets the flags of the alert
253 The flags are as defined in ::khui_alert_flags. The bits that are
254 on in \a mask will be set to the corresponding values in \a flags.
255 Only the bits specified in ::KHUI_ALERT_FLAGMASK_RDWR can be
256 specified in \a mask.
258 KHMEXP khm_int32 KHMAPI
259 khui_alert_set_flags(khui_alert * alert, khm_int32 mask, khm_int32 flags);
261 /*! \brief Clear all the commands from an alert object
263 \see khui_alert_add_command()
265 KHMEXP khm_int32 KHMAPI
266 khui_alert_clear_commands(khui_alert * alert);
268 /*! \brief Add a command to an alert object
270 The command ID should be a valid registered command.
272 KHMEXP khm_int32 KHMAPI
273 khui_alert_add_command(khui_alert * alert,
274 khm_int32 command_id);
276 /*! \brief Display an alert
278 The alert must have a valid \a severity, \a title and a \a message
279 to be displayed. Otherwise the function immediately returns with
282 The method used to display the alert is as follows:
284 - A balloon alert will be shown if one of the following is true:
285 - The NetIDMgr application is minimized or in the background.
286 - ::KHUI_ALERT_FLAG_REQUEST_BALLOON is specified in \a flags.
287 - Otherwise an alert window will be shown.
289 If the message, title of the alert is too long to fit in a balloon
290 prompt, there's a suggestion or if there are custom commands then
291 a placeholder balloon prompt will be shown which when clicked on,
292 shows the actual alert in an alert window.
294 An exception is when ::KHUI_ALERT_FLAG_DEFACTION is specified in
295 flags. In this case instead of a placeholder balloon prompt, one
296 will be shown with the actual title and message (truncated if
297 necessary). Clicking on the balloon will have the same effect as
298 choosing the first command in the action.
300 The placeholder balloon prompt will have a title derived from the
301 first 63 characters of the \a title field in the alert and a
302 message notifying the user that they should click the balloon
303 prompt for more information.
305 To this end, it is beneficial to limit the length of the title to
306 63 characters (64 counting the terminating NULL). This limit is
307 enforced on Windows. Also, try to make the title descriptive.
309 KHMEXP khm_int32 KHMAPI
310 khui_alert_show(khui_alert * alert);
312 /*! \brief Display a modal alert
314 Similar to khui_alert_show(), but shows a modal alert dialog. The
315 function does not return until the user has closed the alert.
317 This function always opens an alert window (never shows a
320 \note Should only be called from the UI thread.
322 KHMEXP khm_int32 KHMAPI
323 khui_alert_show_modal(khui_alert * alert);
325 /*! \brief Queue an alert
327 Instead of displaying the alert immediately, the alert is queued
328 and the status bar updated to notify the user that there is a
329 pending alert. Once the user activates the pending alert, it will
330 be displayed as if khui_alert_show() was called.
332 KHMEXP khm_int32 KHMAPI
333 khui_alert_queue(khui_alert * alert);
335 /*! \brief Display a simple alert
337 \see khui_alert_show()
339 KHMEXP khm_int32 KHMAPI
340 khui_alert_show_simple(const wchar_t * title,
341 const wchar_t * message,
344 /*! \brief Obtain a hold on the alert
346 An alert structure is only considered valid for the duration that
347 there is a hold on it.
349 Use khui_alert_release() to release the hold.
351 KHMEXP khm_int32 KHMAPI
352 khui_alert_hold(khui_alert * alert);
354 /*! \brief Release the hold on the alert
356 Holds obtained on an alert using any of the functions that either
357 return a held pointer to an alert or implicitly obtains a hold on
358 it need to be undone through a call to khui_alert_release().
360 KHMEXP khm_int32 KHMAPI
361 khui_alert_release(khui_alert * alert);
363 /*! \brief Lock an alert
365 Locking an alert disallows any other thread from accessing the
366 alert at the same time. NetIDMgr keeps a global list of all alert
367 objects and the user interface may access any of them at various
368 points in time. Locking the alert allows a thread to modify an
369 alert without causing another thread to be exposed to an
372 Once a thread obtains a lock on the alert, it must call
373 khui_alert_unlock() to unlock it. Otherwise no other thread will
374 be able to access the alert.
376 \note Currently the alert lock is global. Locking one alert
377 disallows access to all other alerts as well.
379 \note Calling khui_alert_lock() is only necessary if you are
380 modifying the ::khui_alert structure directly. Calling any of
381 the khui_alert_* functions to modify the alert does not
382 require obtaining a lock, as they perform synchronization
386 khui_alert_lock(khui_alert * alert);
388 /*! \brief Unlock an alert
390 \see khui_alert_lock()
393 khui_alert_unlock(khui_alert * alert);