1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * Bonobo Desktop Window Control implementation. |
---|
4 | * Enables applications to export their geometry control through CORBA. |
---|
5 | * |
---|
6 | * Author: |
---|
7 | * Miguel de Icaza (miguel@kernel.org) |
---|
8 | * |
---|
9 | * Copyright 1999 Helix Code, Inc. |
---|
10 | */ |
---|
11 | #include <config.h> |
---|
12 | #include <gtk/gtkplug.h> |
---|
13 | #include <bonobo/bonobo-exception.h> |
---|
14 | #include <bonobo/bonobo-main.h> |
---|
15 | #include <bonobo/bonobo-desktop-window.h> |
---|
16 | #include <gdk/gdkprivate.h> |
---|
17 | #include <gdk/gdkx.h> |
---|
18 | |
---|
19 | #define PARENT_TYPE BONOBO_X_OBJECT_TYPE |
---|
20 | |
---|
21 | /** |
---|
22 | * bonobo_desktop_window_construct: |
---|
23 | * @desk_win: The BonoboDesktopWindow object to be initialized. |
---|
24 | * @toplevel: Window we will have control over. |
---|
25 | * |
---|
26 | * Returns: the intialized BonoboDesktopWindow object. |
---|
27 | */ |
---|
28 | BonoboDesktopWindow * |
---|
29 | bonobo_desktop_window_construct (BonoboDesktopWindow *desk_win, |
---|
30 | GtkWindow *toplevel) |
---|
31 | { |
---|
32 | g_return_val_if_fail (GTK_IS_WINDOW (toplevel), NULL); |
---|
33 | g_return_val_if_fail (BONOBO_IS_DESKTOP_WINDOW (desk_win), NULL); |
---|
34 | |
---|
35 | desk_win->window = toplevel; |
---|
36 | |
---|
37 | return desk_win; |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * bonobo_desktop_window_new: |
---|
42 | * @toplevel: The toplevel Gtk window to control |
---|
43 | * container process. |
---|
44 | * |
---|
45 | * Returns: a new BonoboDesktopWindow |
---|
46 | */ |
---|
47 | BonoboDesktopWindow * |
---|
48 | bonobo_desktop_window_new (GtkWindow *toplevel) |
---|
49 | { |
---|
50 | BonoboDesktopWindow *desktop_window; |
---|
51 | |
---|
52 | g_return_val_if_fail (GTK_IS_WINDOW (toplevel), NULL); |
---|
53 | |
---|
54 | desktop_window = gtk_type_new (bonobo_desktop_window_get_type ()); |
---|
55 | |
---|
56 | return bonobo_desktop_window_construct (desktop_window, toplevel); |
---|
57 | } |
---|
58 | |
---|
59 | static CORBA_char * |
---|
60 | impl_Desktop_Window_get_title (PortableServer_Servant servant, CORBA_Environment * ev) |
---|
61 | { |
---|
62 | BonoboDesktopWindow *desk_win = BONOBO_DESKTOP_WINDOW (bonobo_object_from_servant (servant)); |
---|
63 | |
---|
64 | return CORBA_string_dup (desk_win->window->title); |
---|
65 | } |
---|
66 | |
---|
67 | static void |
---|
68 | impl_Desktop_Window_set_title (PortableServer_Servant servant, |
---|
69 | const CORBA_char *value, |
---|
70 | CORBA_Environment * ev) |
---|
71 | { |
---|
72 | BonoboDesktopWindow *desk_win = BONOBO_DESKTOP_WINDOW (bonobo_object_from_servant (servant)); |
---|
73 | |
---|
74 | gtk_window_set_title (desk_win->window, value); |
---|
75 | } |
---|
76 | |
---|
77 | static Bonobo_Desktop_Window_Geometry |
---|
78 | impl_Desktop_Window_getGeometry (PortableServer_Servant servant, |
---|
79 | CORBA_Environment * ev) |
---|
80 | { |
---|
81 | BonoboDesktopWindow *desk_win = BONOBO_DESKTOP_WINDOW (bonobo_object_from_servant (servant)); |
---|
82 | Bonobo_Desktop_Window_Geometry geo; |
---|
83 | gint x, y; |
---|
84 | |
---|
85 | gdk_window_get_origin (GTK_WIDGET (desk_win->window)->window, &x, &y); |
---|
86 | geo.x = x; |
---|
87 | geo.y = y; |
---|
88 | geo.width = GTK_WIDGET (desk_win->window)->allocation.width; |
---|
89 | geo.height = GTK_WIDGET (desk_win->window)->allocation.height; |
---|
90 | |
---|
91 | return geo; |
---|
92 | } |
---|
93 | |
---|
94 | static void |
---|
95 | impl_Desktop_Window_setGeometry (PortableServer_Servant servant, |
---|
96 | const Bonobo_Desktop_Window_Geometry *geo, |
---|
97 | CORBA_Environment *ev) |
---|
98 | { |
---|
99 | BonoboDesktopWindow *desk_win = BONOBO_DESKTOP_WINDOW (bonobo_object_from_servant (servant)); |
---|
100 | |
---|
101 | gtk_widget_set_uposition (GTK_WIDGET (desk_win->window), geo->x, geo->y); |
---|
102 | gtk_widget_set_usize (GTK_WIDGET (desk_win->window), geo->width, geo->height); |
---|
103 | } |
---|
104 | |
---|
105 | static CORBA_unsigned_long |
---|
106 | impl_Desktop_Window_getWindowId (PortableServer_Servant servant, CORBA_Environment * ev) |
---|
107 | { |
---|
108 | BonoboDesktopWindow *desk_win = BONOBO_DESKTOP_WINDOW (bonobo_object_from_servant (servant)); |
---|
109 | |
---|
110 | return GDK_WINDOW_XWINDOW (GTK_WIDGET (desk_win->window)->window); |
---|
111 | } |
---|
112 | |
---|
113 | static void |
---|
114 | bonobo_desktop_window_class_init (BonoboDesktopWindowClass *klass) |
---|
115 | { |
---|
116 | POA_Bonobo_Desktop_Window__epv *epv = &klass->epv; |
---|
117 | |
---|
118 | epv->_get_title = impl_Desktop_Window_get_title; |
---|
119 | epv->_set_title = impl_Desktop_Window_set_title; |
---|
120 | epv->getGeometry = impl_Desktop_Window_getGeometry; |
---|
121 | epv->setGeometry = impl_Desktop_Window_setGeometry; |
---|
122 | epv->getWindowId = impl_Desktop_Window_getWindowId; |
---|
123 | } |
---|
124 | |
---|
125 | static void |
---|
126 | bonobo_desktop_window_init (GtkObject *object) |
---|
127 | { |
---|
128 | /* nothing to do */ |
---|
129 | } |
---|
130 | |
---|
131 | BONOBO_X_TYPE_FUNC_FULL (BonoboDesktopWindow, |
---|
132 | Bonobo_Desktop_Window, |
---|
133 | PARENT_TYPE, |
---|
134 | bonobo_desktop_window); |
---|
135 | |
---|
136 | /** |
---|
137 | * bonobo_desktop_window_control: |
---|
138 | * @object: Object to be aggregated. |
---|
139 | * @win: Window to be controled. |
---|
140 | * |
---|
141 | * Attaches a Bonobo::Desktop::Window corba handler to a Bonobo |
---|
142 | * object controlling the window @win. |
---|
143 | */ |
---|
144 | void |
---|
145 | bonobo_desktop_window_control (BonoboObject *object, GtkWindow *win) |
---|
146 | { |
---|
147 | BonoboObject *win_control_object; |
---|
148 | |
---|
149 | g_return_if_fail (object != NULL); |
---|
150 | g_return_if_fail (win != NULL); |
---|
151 | g_return_if_fail (BONOBO_IS_OBJECT (object)); |
---|
152 | g_return_if_fail (GTK_IS_WINDOW (win)); |
---|
153 | |
---|
154 | win_control_object = BONOBO_OBJECT (bonobo_desktop_window_new (win)); |
---|
155 | bonobo_object_add_interface (object, win_control_object); |
---|
156 | } |
---|