1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 prompt.h for the Openbox window manager
4 Copyright (c) 2008 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
24 #include "render/render.h"
28 typedef struct _ObPrompt ObPrompt;
29 typedef struct _ObPromptElement ObPromptElement;
30 typedef struct _ObPromptAnswer ObPromptAnswer;
32 typedef gboolean (*ObPromptCallback)(ObPrompt *p, gint result, gpointer data);
33 typedef void (*ObPromptCleanup)(ObPrompt *p, gpointer data);
35 struct _ObPromptElement {
39 gint x, y, width, height;
51 /* keep a copy of this because we re-render things that may need it
61 /* one for each answer */
62 ObPromptElement *button;
65 /* points to the button with the focus */
66 ObPromptElement *focus;
67 /* the default button to have selected */
69 /* the cancel result if the dialog is closed */
72 ObPromptCallback func;
73 ObPromptCleanup cleanup;
77 struct _ObPromptAnswer {
82 void prompt_startup(gboolean reconfig);
83 void prompt_shutdown(gboolean reconfig);
85 /*! Create a new prompt
86 @param answers A number of ObPromptAnswers which define the buttons which
87 will appear in the dialog from left to right, and the result
88 returned when they are selected.
89 @param n_answers The number of answers
90 @param default_result The result for the answer button selected by default
91 @param cancel_result The result that is given if the dialog is closed instead
92 of having a button presssed
93 @param func The callback function which is called when the dialog is closed
94 or a button is pressed
95 @param cleanup The cleanup function which is called if the prompt system
96 is shutting down, and someone is still holding a reference to the
97 prompt. This callback should cause the prompt's refcount to go to
98 zero so it can be freed, and free any other memory associated with
99 the prompt. The cleanup function is also called if the prompt's
100 callback function returns TRUE.
101 @param data User defined data which will be passed to the callback
103 ObPrompt* prompt_new(const gchar *msg, const gchar *title,
104 const ObPromptAnswer *answers, gint n_answers,
105 gint default_result, gint cancel_result,
106 ObPromptCallback func, ObPromptCleanup cleanup,
108 void prompt_ref(ObPrompt *self);
109 void prompt_unref(ObPrompt *self);
111 /*! Show the prompt. It will be centered within the given area rectangle */
112 void prompt_show(ObPrompt *self, struct _ObClient *parent, gboolean modal);
113 void prompt_hide(ObPrompt *self);
115 gboolean prompt_key_event(ObPrompt *self, XEvent *e);
116 gboolean prompt_mouse_event(ObPrompt *self, XEvent *e);
117 void prompt_cancel(ObPrompt *self);
119 ObPrompt* prompt_show_message(const gchar *msg, const gchar *title,
120 const gchar *answer);