~ubuntu-branches/debian/sid/gnome-main-menu/sid

« back to all changes in this revision

Viewing changes to libslab/shell-window.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2009-11-08 21:22:49 UTC
  • mto: (5.1.3 squeeze)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20091108212249-9cql8cptajeua2eh
Tags: upstream-0.9.13
ImportĀ upstreamĀ versionĀ 0.9.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of libslab.
3
 
 *
4
 
 * Copyright (c) 2006 Novell, Inc.
5
 
 *
6
 
 * Libslab is free software; you can redistribute it and/or modify it under the
7
 
 * terms of the GNU Lesser General Public License as published by the Free
8
 
 * Software Foundation; either version 2 of the License, or (at your option)
9
 
 * any later version.
10
 
 *
11
 
 * Libslab is distributed in the hope that it will be useful, but WITHOUT ANY
12
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
14
 
 * more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public License
17
 
 * along with libslab; if not, write to the Free Software Foundation, Inc., 51
18
 
 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include "shell-window.h"
22
 
 
23
 
#include <gtk/gtkhbox.h>
24
 
#include <gtk/gtkalignment.h>
25
 
#include <gtk/gtkbin.h>
26
 
#include <gtk/gtkframe.h>
27
 
#include <gtk/gtklayout.h>
28
 
#include <gtk/gtkscrolledwindow.h>
29
 
 
30
 
#include "app-resizer.h"
31
 
 
32
 
static GtkWindowClass *parent_class = NULL;
33
 
 
34
 
static void shell_window_class_init (ShellWindowClass *);
35
 
static void shell_window_init (ShellWindow *);
36
 
static void shell_window_destroy (GtkObject *);
37
 
static void shell_window_handle_size_request (GtkWidget * widget, GtkRequisition * requisition,
38
 
        AppShellData * data);
39
 
 
40
 
gboolean shell_window_paint_window (GtkWidget * widget, GdkEventExpose * event, gpointer data);
41
 
 
42
 
#define SHELL_WINDOW_BORDER_WIDTH 6
43
 
 
44
 
GType
45
 
shell_window_get_type (void)
46
 
{
47
 
        static GType object_type = 0;
48
 
 
49
 
        if (!object_type)
50
 
        {
51
 
                static const GTypeInfo object_info = {
52
 
                        sizeof (ShellWindowClass),
53
 
                        NULL,
54
 
                        NULL,
55
 
                        (GClassInitFunc) shell_window_class_init,
56
 
                        NULL,
57
 
                        NULL,
58
 
                        sizeof (ShellWindow),
59
 
                        0,
60
 
                        (GInstanceInitFunc) shell_window_init
61
 
                };
62
 
 
63
 
                object_type = g_type_register_static (
64
 
                        GTK_TYPE_FRAME, "ShellWindow", &object_info, 0);
65
 
        }
66
 
 
67
 
        return object_type;
68
 
}
69
 
 
70
 
static void
71
 
shell_window_class_init (ShellWindowClass * klass)
72
 
{
73
 
        parent_class = g_type_class_peek_parent (klass);
74
 
 
75
 
        ((GtkObjectClass *) klass)->destroy = shell_window_destroy;
76
 
}
77
 
 
78
 
static void
79
 
shell_window_init (ShellWindow * window)
80
 
{
81
 
        window->_hbox = NULL;
82
 
        window->_left_pane = NULL;
83
 
        window->_right_pane = NULL;
84
 
}
85
 
 
86
 
GtkWidget *
87
 
shell_window_new (AppShellData * app_data)
88
 
{
89
 
        ShellWindow *window = g_object_new (SHELL_WINDOW_TYPE, NULL);
90
 
 
91
 
        gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
92
 
        gtk_frame_set_shadow_type(GTK_FRAME(window), GTK_SHADOW_NONE);
93
 
 
94
 
        window->_hbox = GTK_BOX (gtk_hbox_new (FALSE, 0));
95
 
        gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (window->_hbox));
96
 
 
97
 
        g_signal_connect (G_OBJECT (window), "expose-event", G_CALLBACK (shell_window_paint_window),
98
 
                NULL);
99
 
        window->resize_handler_id =
100
 
                g_signal_connect (G_OBJECT (window), "size-request",
101
 
                G_CALLBACK (shell_window_handle_size_request), app_data);
102
 
 
103
 
        return GTK_WIDGET (window);
104
 
}
105
 
 
106
 
static void
107
 
shell_window_destroy (GtkObject * obj)
108
 
{
109
 
}
110
 
 
111
 
void
112
 
shell_window_clear_resize_handler (ShellWindow * win)
113
 
{
114
 
        if (win->resize_handler_id)
115
 
        {
116
 
                g_signal_handler_disconnect (win, win->resize_handler_id);
117
 
                win->resize_handler_id = 0;
118
 
        }
119
 
}
120
 
 
121
 
/* We want the window to come up with proper runtime calculated width ( ie taking into account font size, locale, ...) so
122
 
   we can't hard code a size. But since ScrolledWindow returns basically zero for it's size request we need to
123
 
   grab the "real" desired width. Once it's shown though we want to allow the user to size down if they want too, so
124
 
   we unhook this function
125
 
*/
126
 
static void
127
 
shell_window_handle_size_request (GtkWidget * widget, GtkRequisition * requisition,
128
 
        AppShellData * app_data)
129
 
{
130
 
        gint height;
131
 
 
132
 
        /*
133
 
        Fixme - counting on this being called after the real size request is done.
134
 
        seems to be that way but I don't know why. I would think I would need to explictly call it here first
135
 
        printf("Enter - shell_window_handle_size_request\n");
136
 
        printf("passed in width:%d, height:%d\n", requisition->width, requisition->height);
137
 
        printf("left side width:%d\n", SHELL_WINDOW(widget)->_left_pane->requisition.width);
138
 
        printf("right side width:%d\n", GTK_WIDGET(APP_RESIZER(app_data->category_layout)->child)->requisition.width);
139
 
        */
140
 
 
141
 
        requisition->width +=
142
 
                GTK_WIDGET (APP_RESIZER (app_data->category_layout)->child)->requisition.width;
143
 
 
144
 
        /* use the left side as a minimum height, if the right side is taller,
145
 
           use it up to SIZING_HEIGHT_PERCENT of the screen height
146
 
        */
147
 
        height =
148
 
                GTK_WIDGET (APP_RESIZER (app_data->category_layout)->child)->requisition.height +
149
 
                10;
150
 
        if (height > requisition->height)
151
 
        {
152
 
                requisition->height =
153
 
                        MIN (((gfloat) gdk_screen_height () * SIZING_HEIGHT_PERCENT), height);
154
 
        }
155
 
}
156
 
 
157
 
void
158
 
shell_window_set_contents (ShellWindow * shell, GtkWidget * left_pane, GtkWidget * right_pane)
159
 
{
160
 
        shell->_left_pane = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
161
 
        shell->_right_pane = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
162
 
 
163
 
        gtk_alignment_set_padding (GTK_ALIGNMENT (shell->_left_pane), 15, 15, 15, 15);
164
 
        gtk_alignment_set_padding (GTK_ALIGNMENT (shell->_right_pane), 0, 0, 0, 0);     /* space for vertical line */
165
 
 
166
 
        gtk_box_pack_start (shell->_hbox, shell->_left_pane, FALSE, FALSE, 0);
167
 
        gtk_box_pack_start (shell->_hbox, shell->_right_pane, TRUE, TRUE, 0);   /* this one takes any extra space */
168
 
 
169
 
        gtk_container_add (GTK_CONTAINER (shell->_left_pane), left_pane);
170
 
        gtk_container_add (GTK_CONTAINER (shell->_right_pane), right_pane);
171
 
}
172
 
 
173
 
gboolean
174
 
shell_window_paint_window (GtkWidget * widget, GdkEventExpose * event, gpointer data)
175
 
{
176
 
        GtkWidget *left_pane, *right_pane;
177
 
 
178
 
        left_pane = SHELL_WINDOW (widget)->_left_pane;
179
 
        right_pane = SHELL_WINDOW (widget)->_right_pane;
180
 
 
181
 
        /* draw left pane background */
182
 
        gtk_paint_flat_box (widget->style, widget->window, widget->state, GTK_SHADOW_NONE, NULL, widget, "",
183
 
                left_pane->allocation.x, left_pane->allocation.y, left_pane->allocation.width,
184
 
                left_pane->allocation.height);
185
 
 
186
 
        return FALSE;
187
 
}