~ubuntu-branches/debian/jessie/mate-control-center/jessie

« back to all changes in this revision

Viewing changes to libslab/shell-window.c

  • Committer: Package Import Robot
  • Author(s): Mike Gabriel
  • Date: 2014-05-02 23:20:06 UTC
  • Revision ID: package-import@ubuntu.com-20140502232006-9626h14ggaz2hc9h
Tags: upstream-1.8.1+dfsg1
ImportĀ upstreamĀ versionĀ 1.8.1+dfsg1

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/gtk.h>
 
24
 
 
25
#include "app-resizer.h"
 
26
 
 
27
static void shell_window_class_init (ShellWindowClass *);
 
28
static void shell_window_init (ShellWindow *);
 
29
static void shell_window_handle_size_request (GtkWidget * widget, GtkRequisition * requisition,
 
30
        AppShellData * data);
 
31
 
 
32
#if GTK_CHECK_VERSION (3, 0, 0)
 
33
gboolean shell_window_paint_window (GtkWidget * widget, cairo_t * cr, gpointer data);
 
34
#else
 
35
gboolean shell_window_paint_window (GtkWidget * widget, GdkEventExpose * event, gpointer data);
 
36
#endif
 
37
 
 
38
#define SHELL_WINDOW_BORDER_WIDTH 6
 
39
 
 
40
G_DEFINE_TYPE (ShellWindow, shell_window, GTK_TYPE_FRAME);
 
41
 
 
42
static void
 
43
shell_window_class_init (ShellWindowClass * klass)
 
44
{
 
45
}
 
46
 
 
47
static void
 
48
shell_window_init (ShellWindow * window)
 
49
{
 
50
        window->_hbox = NULL;
 
51
        window->_left_pane = NULL;
 
52
        window->_right_pane = NULL;
 
53
}
 
54
 
 
55
GtkWidget *
 
56
shell_window_new (AppShellData * app_data)
 
57
{
 
58
        ShellWindow *window = g_object_new (SHELL_WINDOW_TYPE, NULL);
 
59
 
 
60
        gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
 
61
        gtk_frame_set_shadow_type(GTK_FRAME(window), GTK_SHADOW_NONE);
 
62
 
 
63
        window->_hbox = GTK_BOX (gtk_hbox_new (FALSE, 0));
 
64
        gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (window->_hbox));
 
65
 
 
66
#if GTK_CHECK_VERSION (3, 0, 0)
 
67
        g_signal_connect (G_OBJECT (window), "draw", G_CALLBACK (shell_window_paint_window),
 
68
#else
 
69
        g_signal_connect (G_OBJECT (window), "expose-event", G_CALLBACK (shell_window_paint_window),
 
70
#endif
 
71
                NULL);
 
72
#if GTK_CHECK_VERSION (3, 0, 0)
 
73
        /* FIXME */
 
74
#else
 
75
        window->resize_handler_id =
 
76
                g_signal_connect (G_OBJECT (window), "size-request",
 
77
                G_CALLBACK (shell_window_handle_size_request), app_data);
 
78
#endif
 
79
 
 
80
        return GTK_WIDGET (window);
 
81
}
 
82
 
 
83
void
 
84
shell_window_clear_resize_handler (ShellWindow * win)
 
85
{
 
86
        if (win->resize_handler_id)
 
87
        {
 
88
                g_signal_handler_disconnect (win, win->resize_handler_id);
 
89
                win->resize_handler_id = 0;
 
90
        }
 
91
}
 
92
 
 
93
/* We want the window to come up with proper runtime calculated width ( ie taking into account font size, locale, ...) so
 
94
   we can't hard code a size. But since ScrolledWindow returns basically zero for it's size request we need to
 
95
   grab the "real" desired width. Once it's shown though we want to allow the user to size down if they want too, so
 
96
   we unhook this function
 
97
*/
 
98
static void
 
99
shell_window_handle_size_request (GtkWidget * widget, GtkRequisition * requisition,
 
100
        AppShellData * app_data)
 
101
{
 
102
        gint height;
 
103
        GtkRequisition child_requisiton;
 
104
 
 
105
#if GTK_CHECK_VERSION (3, 0, 0)
 
106
        gtk_widget_get_preferred_size (GTK_WIDGET (APP_RESIZER (app_data->category_layout)->child), &child_requisiton, NULL);
 
107
#else
 
108
        child_requisiton = GTK_WIDGET (APP_RESIZER (app_data->category_layout)->child)->requisition;
 
109
#endif
 
110
 
 
111
        /*
 
112
        Fixme - counting on this being called after the real size request is done.
 
113
        seems to be that way but I don't know why. I would think I would need to explictly call it here first
 
114
        printf("Enter - shell_window_handle_size_request\n");
 
115
        printf("passed in width:%d, height:%d\n", requisition->width, requisition->height);
 
116
        printf("left side width:%d\n", SHELL_WINDOW(widget)->_left_pane->requisition.width);
 
117
        printf("right side width:%d\n", GTK_WIDGET(APP_RESIZER(app_data->category_layout)->child)->requisition.width);
 
118
        */
 
119
 
 
120
        requisition->width += child_requisiton.width;
 
121
 
 
122
        /* use the left side as a minimum height, if the right side is taller,
 
123
           use it up to SIZING_HEIGHT_PERCENT of the screen height
 
124
        */
 
125
        height = child_requisiton.height + 10;
 
126
        if (height > requisition->height)
 
127
        {
 
128
                requisition->height =
 
129
                        MIN (((gfloat) gdk_screen_height () * SIZING_HEIGHT_PERCENT), height);
 
130
        }
 
131
}
 
132
 
 
133
void
 
134
shell_window_set_contents (ShellWindow * shell, GtkWidget * left_pane, GtkWidget * right_pane)
 
135
{
 
136
        shell->_left_pane = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
 
137
        shell->_right_pane = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
 
138
 
 
139
        gtk_alignment_set_padding (GTK_ALIGNMENT (shell->_left_pane), 15, 15, 15, 15);
 
140
        gtk_alignment_set_padding (GTK_ALIGNMENT (shell->_right_pane), 0, 0, 0, 0);     /* space for vertical line */
 
141
 
 
142
        gtk_box_pack_start (shell->_hbox, shell->_left_pane, FALSE, FALSE, 0);
 
143
        gtk_box_pack_start (shell->_hbox, shell->_right_pane, TRUE, TRUE, 0);   /* this one takes any extra space */
 
144
 
 
145
        gtk_container_add (GTK_CONTAINER (shell->_left_pane), left_pane);
 
146
        gtk_container_add (GTK_CONTAINER (shell->_right_pane), right_pane);
 
147
}
 
148
 
 
149
gboolean
 
150
#if GTK_CHECK_VERSION (3, 0, 0)
 
151
shell_window_paint_window (GtkWidget * widget, cairo_t * cr, gpointer data)
 
152
#else
 
153
shell_window_paint_window (GtkWidget * widget, GdkEventExpose * event, gpointer data)
 
154
#endif
 
155
{
 
156
        GtkWidget *left_pane, *right_pane;
 
157
        GtkAllocation allocation;
 
158
 
 
159
        left_pane = SHELL_WINDOW (widget)->_left_pane;
 
160
        right_pane = SHELL_WINDOW (widget)->_right_pane;
 
161
 
 
162
        gtk_widget_get_allocation (left_pane, &allocation);
 
163
 
 
164
        /* draw left pane background */
 
165
        gtk_paint_flat_box (
 
166
                gtk_widget_get_style (widget),
 
167
#if GTK_CHECK_VERSION (3, 0, 0)
 
168
                cr,
 
169
#else
 
170
                gtk_widget_get_window (widget),
 
171
#endif
 
172
                gtk_widget_get_state (widget),
 
173
                GTK_SHADOW_NONE,
 
174
#if !GTK_CHECK_VERSION (3, 0, 0)
 
175
                NULL,
 
176
#endif
 
177
                widget,
 
178
                "",
 
179
                allocation.x,
 
180
                allocation.y,
 
181
                allocation.width,
 
182
                allocation.height);
 
183
 
 
184
        return FALSE;
 
185
}