comparison src/audacious/ui_skinned_window.c @ 2494:59661bd074b4 trunk

[svn] Try to put some skinned window code in a common place.
author nenolod
date Sat, 10 Feb 2007 17:01:44 -0800
parents
children 71bee08db1c6
comparison
equal deleted inserted replaced
2493:b7f48f00a342 2494:59661bd074b4
1 /*
2 * Audacious: A cross-platform multimedia player
3 * Copyright (c) 2007 William Pitcock <nenolod -at- sacredspiral.co.uk>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; under version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 #include "platform/smartinclude.h"
21
22 #include <gtk/gtkmain.h>
23 #include <glib-object.h>
24 #include <glib/gmacros.h>
25 #include <gtk/gtkmarshal.h>
26 #include <gtk/gtkwindow.h>
27
28 #include "main.h"
29 #include "dock.h"
30 #include "ui_skinned_window.h"
31 #include "ui_skinned_cursor.h"
32
33 static void ui_skinned_window_class_init(SkinnedWindowClass *klass);
34 static void ui_skinned_window_init(GtkWidget *widget);
35 static GtkWindowClass *parent = NULL;
36
37 GType
38 ui_skinned_window_get_type(void)
39 {
40 static GType window_type = 0;
41
42 if (!window_type)
43 {
44 static const GTypeInfo window_info =
45 {
46 sizeof (SkinnedWindowClass),
47 NULL, /* base_init */
48 NULL, /* base_finalize */
49 (GClassInitFunc) ui_skinned_window_class_init,
50 NULL, /* class_finalize */
51 NULL, /* class_data */
52 sizeof (SkinnedWindow),
53 0, /* n_preallocs */
54 (GInstanceInitFunc) ui_skinned_window_init
55 };
56
57 window_type =
58 g_type_register_static (GTK_TYPE_WINDOW, "SkinnedWindow",
59 &window_info, 0);
60 }
61
62 return window_type;
63 }
64
65 static gboolean
66 ui_skinned_window_configure(GtkWidget *widget,
67 GdkEventConfigure *event)
68 {
69 GtkWidgetClass *widget_class;
70 SkinnedWindow *window = SKINNED_WINDOW(widget);
71
72 widget_class = (GtkWidgetClass*) parent;
73
74 if (widget_class->configure_event != NULL)
75 widget_class->configure_event(widget, event);
76
77 window->x = event->x;
78 window->y = event->y;
79
80 return FALSE;
81 }
82
83 static gboolean
84 ui_skinned_window_motion_notify_event(GtkWidget *widget,
85 GdkEventMotion *event)
86 {
87 GtkWidgetClass *widget_class;
88
89 widget_class = (GtkWidgetClass*) parent;
90
91 if (widget_class->motion_notify_event != NULL)
92 widget_class->motion_notify_event(widget, event);
93
94 if (dock_is_moving(GTK_WINDOW(widget)))
95 dock_move_motion(GTK_WINDOW(widget), event);
96
97 return FALSE;
98 }
99
100 static void
101 ui_skinned_window_class_init(SkinnedWindowClass *klass)
102 {
103 GtkWidgetClass *widget_class;
104
105 widget_class = (GtkWidgetClass*) klass;
106
107 parent = gtk_type_class(gtk_window_get_type());
108
109 widget_class->configure_event = ui_skinned_window_configure;
110 widget_class->motion_notify_event = ui_skinned_window_motion_notify_event;
111 }
112
113 void
114 ui_skinned_window_hide(SkinnedWindow *window)
115 {
116 g_return_if_fail(SKINNED_CHECK_WINDOW(window));
117
118 gtk_window_get_position(GTK_WINDOW(window), &window->x, &window->y);
119 gtk_widget_hide(GTK_WIDGET(window));
120 }
121
122 void
123 ui_skinned_window_show(SkinnedWindow *window)
124 {
125 g_return_if_fail(SKINNED_CHECK_WINDOW(window));
126
127 gtk_window_move(GTK_WINDOW(window), window->x, window->y);
128 gtk_widget_show_all(GTK_WIDGET(window));
129 }
130
131 static void
132 ui_skinned_window_init(GtkWidget *widget)
133 {
134 SkinnedWindow *window;
135 window = SKINNED_WINDOW(widget);
136 }
137
138 GtkWidget *
139 ui_skinned_window_new(GtkWindowType type)
140 {
141 GtkWidget *widget = g_object_new(ui_skinned_window_get_type(), NULL);
142
143 gtk_widget_add_events(GTK_WIDGET(widget),
144 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_MOTION_MASK |
145 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
146 GDK_SCROLL_MASK | GDK_KEY_PRESS_MASK |
147 GDK_VISIBILITY_NOTIFY_MASK);
148 gtk_widget_realize(GTK_WIDGET(widget));
149
150 dock_window_list = dock_window_set_decorated(dock_window_list,
151 GTK_WINDOW(widget), cfg.show_wm_decorations);
152 gtk_widget_set_app_paintable(GTK_WIDGET(widget), TRUE);
153
154 ui_skinned_cursor_set(GTK_WIDGET(widget));
155
156 return widget;
157 }