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 */
41 static guint signals
[SIGS
] = { 0 };
43 static GntBoxClass
*parent_class
= NULL
;
45 static void (*org_destroy
)(GntWidget
*widget
);
48 show_menu(GntBindable
*bind
, GList
*null
)
50 GntWindow
*win
= GNT_WINDOW(bind
);
52 gnt_screen_menu_show(win
->menu
);
59 gnt_window_destroy(GntWidget
*widget
)
61 GntWindow
*window
= GNT_WINDOW(widget
);
63 gnt_widget_destroy(GNT_WIDGET(window
->menu
));
65 if (window
->priv
->accels
)
66 g_hash_table_destroy(window
->priv
->accels
);
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
),
88 g_cclosure_marshal_VOID__VOID
,
91 signals
[SIG_WORKSPACE_SHOW
] =
92 g_signal_new("workspace-shown",
93 G_TYPE_FROM_CLASS(klass
),
97 g_cclosure_marshal_VOID__VOID
,
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
);
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
);
120 /******************************************************************************
122 *****************************************************************************/
124 gnt_window_get_gtype(void)
126 static GType 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 */
139 gnt_window_init
, /* instance_init */
140 NULL
/* value_table */
143 type
= g_type_register_static(GNT_TYPE_BOX
,
151 GntWidget
*gnt_window_new()
153 GntWidget
*widget
= g_object_new(GNT_TYPE_WINDOW
, NULL
);
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
;
171 gnt_window_workspace_hiding(GntWindow
*window
)
174 gnt_widget_hide(GNT_WIDGET(window
->menu
));
175 g_signal_emit(window
, signals
[SIG_WORKSPACE_HIDE
], 0);
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
));
189 gnt_widget_destroy(GNT_WIDGET(window
->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
);
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
;
211 window
->priv
->flags
&= ~GNT_WINDOW_MAXIMIZE_X
;
213 if (maximize
& GNT_WINDOW_MAXIMIZE_Y
)
214 window
->priv
->flags
|= GNT_WINDOW_MAXIMIZE_Y
;
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
));