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
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
24 #include "gntwindow.h"
30 GHashTable
*accels
; /* key => menuitem-id */
40 static guint signals
[SIGS
] = { 0 };
42 static GntBoxClass
*parent_class
= NULL
;
44 static void (*org_destroy
)(GntWidget
*widget
);
47 show_menu(GntBindable
*bind
, GList
*null
)
49 GntWindow
*win
= GNT_WINDOW(bind
);
51 gnt_screen_menu_show(win
->menu
);
58 gnt_window_destroy(GntWidget
*widget
)
60 GntWindow
*window
= GNT_WINDOW(widget
);
62 g_object_unref(G_OBJECT(window
->menu
));
64 g_hash_table_destroy(window
->priv
->accels
);
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
),
86 g_cclosure_marshal_VOID__VOID
,
89 signals
[SIG_WORKSPACE_SHOW
] =
90 g_signal_new("workspace-shown",
91 G_TYPE_FROM_CLASS(klass
),
95 g_cclosure_marshal_VOID__VOID
,
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
);
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
);
118 /******************************************************************************
120 *****************************************************************************/
122 gnt_window_get_gtype(void)
124 static GType 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 */
137 gnt_window_init
, /* instance_init */
138 NULL
/* value_table */
141 type
= g_type_register_static(GNT_TYPE_BOX
,
149 GntWidget
*gnt_window_new()
151 GntWidget
*widget
= g_object_new(GNT_TYPE_WINDOW
, NULL
);
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
;
169 gnt_window_workspace_hiding(GntWindow
*window
)
172 gnt_widget_hide(GNT_WIDGET(window
->menu
));
173 g_signal_emit(window
, signals
[SIG_WORKSPACE_HIDE
], 0);
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
));
187 g_object_unref(G_OBJECT(window
->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
);
197 g_object_ref(G_OBJECT(menu
));
200 const char * gnt_window_get_accel_item(GntWindow
*window
, const char *key
)
203 return g_hash_table_lookup(window
->priv
->accels
, key
);