Add include of cairo.h when using librsvg
[dana/openbox.git] / openbox / prompt.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    prompt.h for the Openbox window manager
4    Copyright (c) 2008        Dana Jansens
5
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.
10
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.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #ifndef ob__prompt_h
20 #define ob__prompt_h
21
22 #include "window.h"
23 #include "geom.h"
24 #include "obrender/render.h"
25 #include "obt/keyboard.h"
26 #include <glib.h>
27 #include <X11/Xlib.h>
28
29 typedef struct _ObPrompt       ObPrompt;
30 typedef struct _ObPromptElement ObPromptElement;
31 typedef struct _ObPromptAnswer ObPromptAnswer;
32
33 typedef gboolean (*ObPromptCallback)(ObPrompt *p, gint result, gpointer data);
34 typedef void (*ObPromptCleanup)(ObPrompt *p, gpointer data);
35
36 struct _ObPromptElement {
37     gchar *text;
38     Window window;
39
40     gint x, y, width, height;
41     gboolean pressed;
42     gboolean hover;
43     gint result;
44 };
45
46 struct _ObPrompt
47 {
48     ObInternalWindow super;
49     gint ref;
50
51     ObtIC *ic;
52     guint event_mask;
53
54     /* keep a copy of this because we re-render things that may need it
55        (i.e. the buttons) */
56     RrAppearance *a_bg;
57
58     gboolean mapped;
59     gint width, height;
60     gint msg_wbound;
61
62     ObPromptElement msg;
63
64     /* one for each answer */
65     ObPromptElement *button;
66     gint n_buttons;
67
68     /* points to the button with the focus */
69     ObPromptElement *focus;
70     /* the default button to have selected */
71     gint default_result;
72     /* the cancel result if the dialog is closed */
73     gint cancel_result;
74
75     ObPromptCallback func;
76     ObPromptCleanup cleanup;
77     gpointer data;
78 };
79
80 struct _ObPromptAnswer {
81     const gchar *text;
82     gint result;
83 };
84
85 void prompt_startup(gboolean reconfig);
86 void prompt_shutdown(gboolean reconfig);
87
88 /*! Create a new prompt
89   @param answers A number of ObPromptAnswers which define the buttons which
90                  will appear in the dialog from left to right, and the result
91                  returned when they are selected.
92   @param n_answers The number of answers
93   @param default_result The result for the answer button selected by default
94   @param cancel_result The result that is given if the dialog is closed instead
95          of having a button presssed
96   @param func The callback function which is called when the dialog is closed
97          or a button is pressed
98   @param cleanup The cleanup function which is called if the prompt system
99          is shutting down, and someone is still holding a reference to the
100          prompt.  This callback should cause the prompt's refcount to go to
101          zero so it can be freed, and free any other memory associated with
102          the prompt.  The cleanup function is also called if the prompt's
103          callback function returns TRUE.
104   @param data User defined data which will be passed to the callback
105 */
106 ObPrompt* prompt_new(const gchar *msg, const gchar *title,
107                      const ObPromptAnswer *answers, gint n_answers,
108                      gint default_result, gint cancel_result,
109                      ObPromptCallback func, ObPromptCleanup cleanup,
110                      gpointer data);
111 void prompt_ref(ObPrompt *self);
112 void prompt_unref(ObPrompt *self);
113
114 /*! Show the prompt.  It will be centered within the given area rectangle */
115 void prompt_show(ObPrompt *self, struct _ObClient *parent, gboolean modal);
116 void prompt_hide(ObPrompt *self);
117
118 gboolean prompt_key_event(ObPrompt *self, XEvent *e);
119 gboolean prompt_mouse_event(ObPrompt *self, XEvent *e);
120 void prompt_cancel(ObPrompt *self);
121
122 ObPrompt* prompt_show_message(const gchar *msg, const gchar *title,
123                               const gchar *answer);
124
125 #endif