2 * @file gntbindable.h Bindable API
6 * GNT - The GLib Ncurses Toolkit
8 * GNT is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This library is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #ifndef GNT_BINDABLE_H
28 #define GNT_BINDABLE_H
32 #include <glib-object.h>
35 #define GNT_TYPE_BINDABLE (gnt_bindable_get_gtype())
36 #define GNT_BINDABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_BINDABLE, GntBindable))
37 #define GNT_BINDABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_BINDABLE, GntBindableClass))
38 #define GNT_IS_BINDABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_BINDABLE))
39 #define GNT_IS_BINDABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_BINDABLE))
40 #define GNT_BINDABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_BINDABLE, GntBindableClass))
44 typedef struct _GntBindable GntBindable
;
45 typedef struct _GntBindableClass GntBindableClass
;
52 struct _GntBindableClass
56 GHashTable
*remaps
; /* Key remaps */
57 GHashTable
*actions
; /* name -> Action */
58 GHashTable
*bindings
; /* key -> ActionParam */
60 GntBindable
* help_window
;
62 void (*gnt_reserved2
)(void);
63 void (*gnt_reserved3
)(void);
64 void (*gnt_reserved4
)(void);
74 GType
gnt_bindable_get_gtype(void);
79 const char * gnt_bindable_remap_keys(GntBindable
*bindable
, const char *text
);
82 /* Bindable Actions */
84 typedef gboolean (*GntBindableActionCallback
) (GntBindable
*bindable
, GList
*params
);
85 typedef gboolean (*GntBindableActionCallbackNoParam
)(GntBindable
*bindable
);
87 typedef struct _GntBindableAction GntBindableAction
;
88 typedef struct _GntBindableActionParam GntBindableActionParam
;
90 struct _GntBindableAction
92 char *name
; /* The name of the action */
94 gboolean (*action
)(GntBindable
*bindable
, GList
*params
);
95 gboolean (*action_noparam
)(GntBindable
*bindable
);
99 struct _GntBindableActionParam
101 GntBindableAction
*action
;
105 /*GntBindableAction *gnt_bindable_action_parse(const char *name);*/
108 * Free a bindable action.
110 * @param action The bindable action.
112 void gnt_bindable_action_free(GntBindableAction
*action
);
115 * Free a GntBindableActionParam.
117 * @param param The GntBindableActionParam to free.
119 void gnt_bindable_action_param_free(GntBindableActionParam
*param
);
122 * Register a bindable action for a class.
124 * @param klass The class the binding is for.
125 * @param name The name of the binding.
126 * @param callback The callback for the binding.
127 * @param trigger The default trigger for the binding, or @c NULL, followed by a NULL-terminated
128 * list of default parameters.
130 void gnt_bindable_class_register_action(GntBindableClass
*klass
, const char *name
, GntBindableActionCallback callback
, const char *trigger
, ...);
133 * Register a key-binding to an existing action.
135 * @param klass The class the binding is for.
136 * @param name The name of the binding.
137 * @param trigger A new trigger for the binding, followed by a @c NULL-terminated list of parameters for the callback.
139 void gnt_bindable_register_binding(GntBindableClass
*klass
, const char *name
, const char *trigger
, ...);
142 * Perform an action from a keybinding.
144 * @param bindable The bindable object.
145 * @param keys The key to trigger the action.
147 * @return @c TRUE if the action was performed successfully, @c FALSE otherwise.
149 gboolean
gnt_bindable_perform_action_key(GntBindable
*bindable
, const char *keys
);
152 * Perform an action on a bindable object.
154 * @param bindable The bindable object.
155 * @param name The action to perform, followed by a @c NULL-terminated list of parameters.
157 * @return @c TRUE if the action was performed successfully, @c FALSE otherwise.
159 gboolean
gnt_bindable_perform_action_named(GntBindable
*bindable
, const char *name
, ...);
162 * Returns a GntTree populated with "key" -> "binding" for the widget.
164 * @param bind The object to list the bindings for.
166 * @return The GntTree.
168 GntBindable
* gnt_bindable_bindings_view(GntBindable
*bind
);
171 * Builds a window that list the key bindings for a GntBindable object.
172 * From this window a user can select a listing to rebind a new key for the given action.
174 * @param bindable The object to list the bindings for.
179 gboolean
gnt_bindable_build_help_window(GntBindable
*bindable
);
183 #endif /* GNT_BINDABLE_H */