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
23 #include "gntinternal.h"
25 #include "gntwindow.h"
31 GHashTable
*accels
; /* key => menuitem-id */
42 static guint signals
[SIGS
] = { 0 };
44 static GntBoxClass
*parent_class
= NULL
;
46 static void (*org_destroy
)(GntWidget
*widget
);
49 show_menu(GntBindable
*bind
, GList
*null
)
51 GntWindow
*win
= GNT_WINDOW(bind
);
53 GntMenu
*menu
= win
->menu
;
55 gnt_screen_menu_show(menu
);
56 if (menu
->type
== GNT_MENU_TOPLEVEL
) {
58 item
= g_list_nth_data(menu
->list
, menu
->selected
);
59 if (item
&& gnt_menuitem_get_submenu(item
)) {
60 gnt_widget_activate(GNT_WIDGET(menu
));
69 gnt_window_destroy(GntWidget
*widget
)
71 GntWindow
*window
= GNT_WINDOW(widget
);
73 gnt_widget_destroy(GNT_WIDGET(window
->menu
));
75 if (window
->priv
->accels
)
76 g_hash_table_destroy(window
->priv
->accels
);
83 gnt_window_class_init(GntWindowClass
*klass
)
85 GntBindableClass
*bindable
= GNT_BINDABLE_CLASS(klass
);
86 GntWidgetClass
*wid_class
= GNT_WIDGET_CLASS(klass
);
87 parent_class
= GNT_BOX_CLASS(klass
);
89 org_destroy
= wid_class
->destroy
;
90 wid_class
->destroy
= gnt_window_destroy
;
92 signals
[SIG_WORKSPACE_HIDE
] =
93 g_signal_new("workspace-hidden",
94 G_TYPE_FROM_CLASS(klass
),
98 g_cclosure_marshal_VOID__VOID
,
101 signals
[SIG_WORKSPACE_SHOW
] =
102 g_signal_new("workspace-shown",
103 G_TYPE_FROM_CLASS(klass
),
107 g_cclosure_marshal_VOID__VOID
,
110 gnt_bindable_class_register_action(bindable
, "show-menu", show_menu
,
111 GNT_KEY_CTRL_O
, NULL
);
112 gnt_bindable_register_binding(bindable
, "show-menu", GNT_KEY_F10
, NULL
);
113 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass
), bindable
);
119 gnt_window_init(GTypeInstance
*instance
, gpointer
class)
121 GntWidget
*widget
= GNT_WIDGET(instance
);
122 GntWindow
*win
= GNT_WINDOW(widget
);
123 GNT_WIDGET_UNSET_FLAGS(widget
, GNT_WIDGET_NO_BORDER
| GNT_WIDGET_NO_SHADOW
);
124 GNT_WIDGET_SET_FLAGS(widget
, GNT_WIDGET_CAN_TAKE_FOCUS
);
125 win
->priv
= g_new0(GntWindowPriv
, 1);
126 win
->priv
->accels
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, g_free
);
130 /******************************************************************************
132 *****************************************************************************/
134 gnt_window_get_gtype(void)
136 static GType type
= 0;
140 static const GTypeInfo info
= {
141 sizeof(GntWindowClass
),
142 NULL
, /* base_init */
143 NULL
, /* base_finalize */
144 (GClassInitFunc
)gnt_window_class_init
,
145 NULL
, /* class_finalize */
146 NULL
, /* class_data */
149 gnt_window_init
, /* instance_init */
150 NULL
/* value_table */
153 type
= g_type_register_static(GNT_TYPE_BOX
,
161 GntWidget
*gnt_window_new()
163 GntWidget
*widget
= g_object_new(GNT_TYPE_WINDOW
, NULL
);
168 GntWidget
*gnt_window_box_new(gboolean homo
, gboolean vert
)
170 GntWidget
*wid
= gnt_window_new();
171 GntBox
*box
= GNT_BOX(wid
);
173 box
->homogeneous
= homo
;
174 box
->vertical
= vert
;
175 box
->alignment
= vert
? GNT_ALIGN_LEFT
: GNT_ALIGN_MID
;
181 gnt_window_workspace_hiding(GntWindow
*window
)
184 gnt_widget_hide(GNT_WIDGET(window
->menu
));
185 g_signal_emit(window
, signals
[SIG_WORKSPACE_HIDE
], 0);
189 gnt_window_workspace_showing(GntWindow
*window
)
191 g_signal_emit(window
, signals
[SIG_WORKSPACE_SHOW
], 0);
194 void gnt_window_set_menu(GntWindow
*window
, GntMenu
*menu
)
196 /* If a menu already existed, then destroy that first. */
197 const char *name
= gnt_widget_get_name(GNT_WIDGET(window
));
199 gnt_widget_destroy(GNT_WIDGET(window
->menu
));
201 if (name
&& window
->priv
) {
202 if (!gnt_style_read_menu_accels(name
, window
->priv
->accels
)) {
203 g_hash_table_destroy(window
->priv
->accels
);
204 window
->priv
->accels
= NULL
;
209 const char * gnt_window_get_accel_item(GntWindow
*window
, const char *key
)
211 if (window
->priv
->accels
)
212 return g_hash_table_lookup(window
->priv
->accels
, key
);
216 void gnt_window_set_maximize(GntWindow
*window
, GntWindowFlags maximize
)
218 if (maximize
& GNT_WINDOW_MAXIMIZE_X
)
219 window
->priv
->flags
|= GNT_WINDOW_MAXIMIZE_X
;
221 window
->priv
->flags
&= ~GNT_WINDOW_MAXIMIZE_X
;
223 if (maximize
& GNT_WINDOW_MAXIMIZE_Y
)
224 window
->priv
->flags
|= GNT_WINDOW_MAXIMIZE_Y
;
226 window
->priv
->flags
&= ~GNT_WINDOW_MAXIMIZE_Y
;
229 GntWindowFlags
gnt_window_get_maximize(GntWindow
*window
)
231 return (window
->priv
->flags
& (GNT_WINDOW_MAXIMIZE_X
| GNT_WINDOW_MAXIMIZE_Y
));