Add missing AUTHORS and ChangeLog.
[gnt.git] / gntwindow.c
blob24b6255cb8a84f925049b47e77edcd0aac36c9d9
1 /**
2 * GNT - The GLib Ncurses Toolkit
4 * GNT is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "gntstyle.h"
24 #include "gntwindow.h"
26 #include <string.h>
28 struct _GntWindowPriv
30 GHashTable *accels; /* key => menuitem-id */
33 enum
35 SIG_WORKSPACE_HIDE,
36 SIG_WORKSPACE_SHOW,
37 SIGS,
40 static guint signals[SIGS] = { 0 };
42 static GntBoxClass *parent_class = NULL;
44 static void (*org_destroy)(GntWidget *widget);
46 static gboolean
47 show_menu(GntBindable *bind, GList *null)
49 GntWindow *win = GNT_WINDOW(bind);
50 if (win->menu) {
51 gnt_screen_menu_show(win->menu);
52 return TRUE;
54 return FALSE;
57 static void
58 gnt_window_destroy(GntWidget *widget)
60 GntWindow *window = GNT_WINDOW(widget);
61 if (window->menu)
62 g_object_unref(G_OBJECT(window->menu));
63 if (window->priv) {
64 g_hash_table_destroy(window->priv->accels);
65 g_free(window->priv);
67 org_destroy(widget);
70 static void
71 gnt_window_class_init(GntWindowClass *klass)
73 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
74 GntWidgetClass *wid_class = GNT_WIDGET_CLASS(klass);
75 parent_class = GNT_BOX_CLASS(klass);
77 org_destroy = wid_class->destroy;
78 wid_class->destroy = gnt_window_destroy;
80 signals[SIG_WORKSPACE_HIDE] =
81 g_signal_new("workspace-hidden",
82 G_TYPE_FROM_CLASS(klass),
83 G_SIGNAL_RUN_LAST,
85 NULL, NULL,
86 g_cclosure_marshal_VOID__VOID,
87 G_TYPE_NONE, 0);
89 signals[SIG_WORKSPACE_SHOW] =
90 g_signal_new("workspace-shown",
91 G_TYPE_FROM_CLASS(klass),
92 G_SIGNAL_RUN_LAST,
94 NULL, NULL,
95 g_cclosure_marshal_VOID__VOID,
96 G_TYPE_NONE, 0);
98 gnt_bindable_class_register_action(bindable, "show-menu", show_menu,
99 GNT_KEY_CTRL_O, NULL);
100 gnt_bindable_register_binding(bindable, "show-menu", GNT_KEY_F10, NULL);
101 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable);
103 GNTDEBUG;
106 static void
107 gnt_window_init(GTypeInstance *instance, gpointer class)
109 GntWidget *widget = GNT_WIDGET(instance);
110 GntWindow *win = GNT_WINDOW(widget);
111 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
112 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS);
113 win->priv = g_new0(GntWindowPriv, 1);
114 win->priv->accels = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
115 GNTDEBUG;
118 /******************************************************************************
119 * GntWindow API
120 *****************************************************************************/
121 GType
122 gnt_window_get_gtype(void)
124 static GType type = 0;
126 if(type == 0)
128 static const GTypeInfo info = {
129 sizeof(GntWindowClass),
130 NULL, /* base_init */
131 NULL, /* base_finalize */
132 (GClassInitFunc)gnt_window_class_init,
133 NULL, /* class_finalize */
134 NULL, /* class_data */
135 sizeof(GntWindow),
136 0, /* n_preallocs */
137 gnt_window_init, /* instance_init */
138 NULL /* value_table */
141 type = g_type_register_static(GNT_TYPE_BOX,
142 "GntWindow",
143 &info, 0);
146 return type;
149 GntWidget *gnt_window_new()
151 GntWidget *widget = g_object_new(GNT_TYPE_WINDOW, NULL);
153 return widget;
156 GntWidget *gnt_window_box_new(gboolean homo, gboolean vert)
158 GntWidget *wid = gnt_window_new();
159 GntBox *box = GNT_BOX(wid);
161 box->homogeneous = homo;
162 box->vertical = vert;
163 box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID;
165 return wid;
168 void
169 gnt_window_workspace_hiding(GntWindow *window)
171 if (window->menu)
172 gnt_widget_hide(GNT_WIDGET(window->menu));
173 g_signal_emit(window, signals[SIG_WORKSPACE_HIDE], 0);
176 void
177 gnt_window_workspace_showing(GntWindow *window)
179 g_signal_emit(window, signals[SIG_WORKSPACE_SHOW], 0);
182 void gnt_window_set_menu(GntWindow *window, GntMenu *menu)
184 /* If a menu already existed, then destroy that first. */
185 const char *name = gnt_widget_get_name(GNT_WIDGET(window));
186 if (window->menu)
187 g_object_unref(G_OBJECT(window->menu));
188 window->menu = menu;
189 if (name && window->priv) {
190 if (!gnt_style_read_menu_accels(name, window->priv->accels)) {
191 g_hash_table_destroy(window->priv->accels);
192 g_free(window->priv);
193 window->priv = NULL;
196 if (menu)
197 g_object_ref(G_OBJECT(menu));
200 const char * gnt_window_get_accel_item(GntWindow *window, const char *key)
202 if (window->priv)
203 return g_hash_table_lookup(window->priv->accels, key);
204 return NULL;