Update to 24f58c58bb8d22c0e8e6c5ce43c536c47b719bc6
[gnt.git] / gntwindow.c
blob1423b71fa8c0bc0ffaa982c3ef66271dbda1e303
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 */
31 GntWindowFlags flags;
34 enum
36 SIG_WORKSPACE_HIDE,
37 SIG_WORKSPACE_SHOW,
38 SIGS,
41 static guint signals[SIGS] = { 0 };
43 static GntBoxClass *parent_class = NULL;
45 static void (*org_destroy)(GntWidget *widget);
47 static gboolean
48 show_menu(GntBindable *bind, GList *null)
50 GntWindow *win = GNT_WINDOW(bind);
51 if (win->menu) {
52 gnt_screen_menu_show(win->menu);
53 return TRUE;
55 return FALSE;
58 static void
59 gnt_window_destroy(GntWidget *widget)
61 GntWindow *window = GNT_WINDOW(widget);
62 if (window->menu)
63 gnt_widget_destroy(GNT_WIDGET(window->menu));
64 if (window->priv) {
65 if (window->priv->accels)
66 g_hash_table_destroy(window->priv->accels);
67 g_free(window->priv);
69 org_destroy(widget);
72 static void
73 gnt_window_class_init(GntWindowClass *klass)
75 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
76 GntWidgetClass *wid_class = GNT_WIDGET_CLASS(klass);
77 parent_class = GNT_BOX_CLASS(klass);
79 org_destroy = wid_class->destroy;
80 wid_class->destroy = gnt_window_destroy;
82 signals[SIG_WORKSPACE_HIDE] =
83 g_signal_new("workspace-hidden",
84 G_TYPE_FROM_CLASS(klass),
85 G_SIGNAL_RUN_LAST,
87 NULL, NULL,
88 g_cclosure_marshal_VOID__VOID,
89 G_TYPE_NONE, 0);
91 signals[SIG_WORKSPACE_SHOW] =
92 g_signal_new("workspace-shown",
93 G_TYPE_FROM_CLASS(klass),
94 G_SIGNAL_RUN_LAST,
96 NULL, NULL,
97 g_cclosure_marshal_VOID__VOID,
98 G_TYPE_NONE, 0);
100 gnt_bindable_class_register_action(bindable, "show-menu", show_menu,
101 GNT_KEY_CTRL_O, NULL);
102 gnt_bindable_register_binding(bindable, "show-menu", GNT_KEY_F10, NULL);
103 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable);
105 GNTDEBUG;
108 static void
109 gnt_window_init(GTypeInstance *instance, gpointer class)
111 GntWidget *widget = GNT_WIDGET(instance);
112 GntWindow *win = GNT_WINDOW(widget);
113 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
114 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_CAN_TAKE_FOCUS);
115 win->priv = g_new0(GntWindowPriv, 1);
116 win->priv->accels = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
117 GNTDEBUG;
120 /******************************************************************************
121 * GntWindow API
122 *****************************************************************************/
123 GType
124 gnt_window_get_gtype(void)
126 static GType type = 0;
128 if(type == 0)
130 static const GTypeInfo info = {
131 sizeof(GntWindowClass),
132 NULL, /* base_init */
133 NULL, /* base_finalize */
134 (GClassInitFunc)gnt_window_class_init,
135 NULL, /* class_finalize */
136 NULL, /* class_data */
137 sizeof(GntWindow),
138 0, /* n_preallocs */
139 gnt_window_init, /* instance_init */
140 NULL /* value_table */
143 type = g_type_register_static(GNT_TYPE_BOX,
144 "GntWindow",
145 &info, 0);
148 return type;
151 GntWidget *gnt_window_new()
153 GntWidget *widget = g_object_new(GNT_TYPE_WINDOW, NULL);
155 return widget;
158 GntWidget *gnt_window_box_new(gboolean homo, gboolean vert)
160 GntWidget *wid = gnt_window_new();
161 GntBox *box = GNT_BOX(wid);
163 box->homogeneous = homo;
164 box->vertical = vert;
165 box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID;
167 return wid;
170 void
171 gnt_window_workspace_hiding(GntWindow *window)
173 if (window->menu)
174 gnt_widget_hide(GNT_WIDGET(window->menu));
175 g_signal_emit(window, signals[SIG_WORKSPACE_HIDE], 0);
178 void
179 gnt_window_workspace_showing(GntWindow *window)
181 g_signal_emit(window, signals[SIG_WORKSPACE_SHOW], 0);
184 void gnt_window_set_menu(GntWindow *window, GntMenu *menu)
186 /* If a menu already existed, then destroy that first. */
187 const char *name = gnt_widget_get_name(GNT_WIDGET(window));
188 if (window->menu)
189 gnt_widget_destroy(GNT_WIDGET(window->menu));
190 window->menu = menu;
191 if (name && window->priv) {
192 if (!gnt_style_read_menu_accels(name, window->priv->accels)) {
193 g_hash_table_destroy(window->priv->accels);
194 window->priv->accels = NULL;
199 const char * gnt_window_get_accel_item(GntWindow *window, const char *key)
201 if (window->priv->accels)
202 return g_hash_table_lookup(window->priv->accels, key);
203 return NULL;
206 void gnt_window_set_maximize(GntWindow *window, GntWindowFlags maximize)
208 if (maximize & GNT_WINDOW_MAXIMIZE_X)
209 window->priv->flags |= GNT_WINDOW_MAXIMIZE_X;
210 else
211 window->priv->flags &= ~GNT_WINDOW_MAXIMIZE_X;
213 if (maximize & GNT_WINDOW_MAXIMIZE_Y)
214 window->priv->flags |= GNT_WINDOW_MAXIMIZE_Y;
215 else
216 window->priv->flags &= ~GNT_WINDOW_MAXIMIZE_Y;
219 GntWindowFlags gnt_window_get_maximize(GntWindow *window)
221 return (window->priv->flags & (GNT_WINDOW_MAXIMIZE_X | GNT_WINDOW_MAXIMIZE_Y));