Change the "length of bstream" data type to be a gsize, since it represents
[pidgin-git.git] / finch / libgnt / gntwindow.c
blobf4ea3c6e700785f46d8ab3541770d9c5ed3c925f
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 "gntinternal.h"
24 #include "gntstyle.h"
25 #include "gntwindow.h"
27 #include <string.h>
29 struct _GntWindowPriv
31 GHashTable *accels; /* key => menuitem-id */
32 GntWindowFlags flags;
35 enum
37 SIG_WORKSPACE_HIDE,
38 SIG_WORKSPACE_SHOW,
39 SIGS,
42 static guint signals[SIGS] = { 0 };
44 static GntBoxClass *parent_class = NULL;
46 static void (*org_destroy)(GntWidget *widget);
48 static gboolean
49 show_menu(GntBindable *bind, GList *null)
51 GntWindow *win = GNT_WINDOW(bind);
52 if (win->menu) {
53 GntMenu *menu = win->menu;
55 gnt_screen_menu_show(menu);
56 if (menu->type == GNT_MENU_TOPLEVEL) {
57 GntMenuItem *item;
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));
63 return TRUE;
65 return FALSE;
68 static void
69 gnt_window_destroy(GntWidget *widget)
71 GntWindow *window = GNT_WINDOW(widget);
72 if (window->menu)
73 gnt_widget_destroy(GNT_WIDGET(window->menu));
74 if (window->priv) {
75 if (window->priv->accels)
76 g_hash_table_destroy(window->priv->accels);
77 g_free(window->priv);
79 org_destroy(widget);
82 static void
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),
95 G_SIGNAL_RUN_LAST,
97 NULL, NULL,
98 g_cclosure_marshal_VOID__VOID,
99 G_TYPE_NONE, 0);
101 signals[SIG_WORKSPACE_SHOW] =
102 g_signal_new("workspace-shown",
103 G_TYPE_FROM_CLASS(klass),
104 G_SIGNAL_RUN_LAST,
106 NULL, NULL,
107 g_cclosure_marshal_VOID__VOID,
108 G_TYPE_NONE, 0);
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);
115 GNTDEBUG;
118 static void
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);
127 GNTDEBUG;
130 /******************************************************************************
131 * GntWindow API
132 *****************************************************************************/
133 GType
134 gnt_window_get_gtype(void)
136 static GType type = 0;
138 if(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 */
147 sizeof(GntWindow),
148 0, /* n_preallocs */
149 gnt_window_init, /* instance_init */
150 NULL /* value_table */
153 type = g_type_register_static(GNT_TYPE_BOX,
154 "GntWindow",
155 &info, 0);
158 return type;
161 GntWidget *gnt_window_new()
163 GntWidget *widget = g_object_new(GNT_TYPE_WINDOW, NULL);
165 return widget;
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;
177 return wid;
180 void
181 gnt_window_workspace_hiding(GntWindow *window)
183 if (window->menu)
184 gnt_widget_hide(GNT_WIDGET(window->menu));
185 g_signal_emit(window, signals[SIG_WORKSPACE_HIDE], 0);
188 void
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));
198 if (window->menu)
199 gnt_widget_destroy(GNT_WIDGET(window->menu));
200 window->menu = 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);
213 return NULL;
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;
220 else
221 window->priv->flags &= ~GNT_WINDOW_MAXIMIZE_X;
223 if (maximize & GNT_WINDOW_MAXIMIZE_Y)
224 window->priv->flags |= GNT_WINDOW_MAXIMIZE_Y;
225 else
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));