nautilus-adapter-embeddable-embed-strategy.c 8.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/*
 * Nautilus
 *
 * Copyright (C) 2000 Eazel, Inc.
 *
 * Nautilus is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * Nautilus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; see the file COPYING.  If not,
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Maciej Stachowiak <mjs@eazel.com>
 */


/* nautilus-adapter-embeddable-embed-strategy.c - 
 */


#include <config.h>

#include "nautilus-adapter-embeddable-embed-strategy.h"
#include "nautilus-adapter-embed-strategy-private.h"
35
#include "nautilus-zoomable-proxy.h"
36

37
38
39
#include <bonobo/bonobo-client-site.h>
#include <bonobo/bonobo-item-container.h>
#include <gtk/gtksignal.h>
Ramiro Estrugo's avatar
Ramiro Estrugo committed
40
#include <eel/eel-gtk-macros.h>
41
42
43
#include <libnautilus/nautilus-view.h>

struct NautilusAdapterEmbeddableEmbedStrategyDetails {
44
	BonoboItemContainer *container;
45
46
47
      	BonoboClientSite   *client_site;
	BonoboViewFrame    *view_frame;
	GtkWidget          *client_widget;
48
	BonoboObject       *zoomable;
49
50
51
};


52
53
static void nautilus_adapter_embeddable_embed_strategy_class_init (NautilusAdapterEmbeddableEmbedStrategyClass *klass);
static void nautilus_adapter_embeddable_embed_strategy_init       (NautilusAdapterEmbeddableEmbedStrategy      *strategy);
54
static void nautilus_adapter_embeddable_embed_strategy_destroy          (GtkObject                              *object);
55
56
57
58
static void nautilus_adapter_embeddable_embed_strategy_activate         (NautilusAdapterEmbedStrategy                *object,
									 gpointer                                     ui_container);
static void nautilus_adapter_embeddable_embed_strategy_deactivate       (NautilusAdapterEmbedStrategy                *object);

59
60

static GtkWidget *nautilus_adapter_embeddable_embed_strategy_get_widget (NautilusAdapterEmbedStrategy *strategy);
61
static BonoboObject *nautilus_adapter_embeddable_embed_strategy_get_zoomable (NautilusAdapterEmbedStrategy *strategy);
62
63


64
EEL_CLASS_BOILERPLATE (NautilusAdapterEmbeddableEmbedStrategy, nautilus_adapter_embeddable_embed_strategy, NAUTILUS_TYPE_ADAPTER_EMBED_STRATEGY)
65
66
67


static void
68
nautilus_adapter_embeddable_embed_strategy_class_init (NautilusAdapterEmbeddableEmbedStrategyClass *klass)
69
70
71
72
73
74
75
76
77
78
79
{
	GtkObjectClass                    *object_class;
	NautilusAdapterEmbedStrategyClass *adapter_embed_strategy_class;

	object_class = GTK_OBJECT_CLASS (klass);

	object_class->destroy = nautilus_adapter_embeddable_embed_strategy_destroy;

	adapter_embed_strategy_class = NAUTILUS_ADAPTER_EMBED_STRATEGY_CLASS (klass);

	adapter_embed_strategy_class->get_widget = nautilus_adapter_embeddable_embed_strategy_get_widget;
80
	adapter_embed_strategy_class->get_zoomable = nautilus_adapter_embeddable_embed_strategy_get_zoomable;
81
82
	adapter_embed_strategy_class->activate = nautilus_adapter_embeddable_embed_strategy_activate;
	adapter_embed_strategy_class->deactivate = nautilus_adapter_embeddable_embed_strategy_deactivate;
83
84
85
}

static void
86
nautilus_adapter_embeddable_embed_strategy_init (NautilusAdapterEmbeddableEmbedStrategy *strategy)
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{
	strategy->details = g_new0 (NautilusAdapterEmbeddableEmbedStrategyDetails, 1);
}

static void
nautilus_adapter_embeddable_embed_strategy_destroy (GtkObject *object)
{
	NautilusAdapterEmbeddableEmbedStrategy *strategy;

	strategy = NAUTILUS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (object);

 	if (strategy->details->view_frame != NULL) {
		bonobo_object_unref (BONOBO_OBJECT (strategy->details->view_frame));
	}
 	if (strategy->details->client_site != NULL) {
		bonobo_object_unref (BONOBO_OBJECT (strategy->details->client_site));
	}
 	if (strategy->details->container != NULL) {
		bonobo_object_unref (BONOBO_OBJECT (strategy->details->container));
	}

	g_free (strategy->details);

Ramiro Estrugo's avatar
Ramiro Estrugo committed
110
	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
111
112
113
}


114
115
116
117
118
119
120
121
122
123
124
125
126
static void 
nautilus_adapter_embeddable_embed_strategy_activate (NautilusAdapterEmbedStrategy *object,
						     gpointer                      ui_container)
{
	NautilusAdapterEmbeddableEmbedStrategy *strategy;
	Bonobo_UIContainer corba_container = ui_container;

	g_return_if_fail (object != NULL);
	g_return_if_fail (NAUTILUS_IS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (object));

	strategy = NAUTILUS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (object);

	bonobo_control_frame_set_ui_container (BONOBO_CONTROL_FRAME (strategy->details->view_frame),
127
					       corba_container, NULL);
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

	bonobo_control_frame_control_activate (BONOBO_CONTROL_FRAME (strategy->details->view_frame));
}

static void 
nautilus_adapter_embeddable_embed_strategy_deactivate (NautilusAdapterEmbedStrategy *object)
{
	NautilusAdapterEmbeddableEmbedStrategy *strategy;

	g_return_if_fail (object != NULL);
	g_return_if_fail (NAUTILUS_IS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (object));

	strategy = NAUTILUS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (object);

	/* This is not strictly necessary, but it makes sure that the component's menus
	 * and toolbars are really unmerged even if our component is badly behaving or
	 * leaking a reference somewhere. */
	bonobo_control_frame_control_deactivate (BONOBO_CONTROL_FRAME (strategy->details->view_frame));
}

148
149
150
151
152
153
154
155
156
157
158
159
160
161
static void
activate_uri_callback (BonoboControlFrame *frame,
		       const char *uri, 
		       gboolean relative,
		       NautilusAdapterEmbeddableEmbedStrategy *strategy)
{
	/* FIXME: ignoring `relative' parameter as the concept is kind
           of broken. */

	nautilus_adapter_embed_strategy_emit_open_location (NAUTILUS_ADAPTER_EMBED_STRATEGY (strategy), 
							    uri);
}

NautilusAdapterEmbedStrategy *
162
163
nautilus_adapter_embeddable_embed_strategy_new (Bonobo_Embeddable embeddable,
						Bonobo_UIContainer ui_container)
164
165
{
	NautilusAdapterEmbeddableEmbedStrategy *strategy;
166
	BonoboObjectClient *embeddable_wrapper;
167
168
169
	Bonobo_Zoomable corba_zoomable;
	Bonobo_View corba_view;
	CORBA_Environment ev;
170

171
	strategy = NAUTILUS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (g_object_new (NAUTILUS_TYPE_ADAPTER_EMBEDDABLE_EMBED_STRATEGY, NULL));
172
	g_object_ref (G_OBJECT (strategy));
173
	gtk_object_sink (GTK_OBJECT (strategy));
174

175
176
	embeddable_wrapper = bonobo_object_client_from_corba
		(bonobo_object_dup_ref (embeddable, NULL));
177

178
	strategy->details->container = bonobo_item_container_new ();
179
180
      	strategy->details->client_site = bonobo_client_site_new (strategy->details->container);

181
182
183
	bonobo_client_site_bind_embeddable (strategy->details->client_site, embeddable_wrapper);

	bonobo_object_unref (BONOBO_OBJECT (embeddable_wrapper));
184

185
	strategy->details->view_frame = bonobo_client_site_new_view (strategy->details->client_site, ui_container);
186
187
	strategy->details->client_widget = bonobo_view_frame_get_wrapper (strategy->details->view_frame);

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
	CORBA_exception_init (&ev);
	corba_view = bonobo_view_frame_get_view (strategy->details->view_frame);

	corba_zoomable = Bonobo_Unknown_queryInterface (corba_view,
							"IDL:Bonobo/Zoomable:1.0",
							&ev);
	if ((ev._major == CORBA_NO_EXCEPTION) &&
	    !CORBA_Object_is_nil (corba_zoomable, &ev)) {
		strategy->details->zoomable = nautilus_zoomable_proxy_get
			(corba_zoomable);
	}

	CORBA_exception_free (&ev);


203
204
205
     	bonobo_wrapper_set_visibility (BONOBO_WRAPPER (strategy->details->client_widget), FALSE);
	bonobo_view_frame_set_covered (strategy->details->view_frame, FALSE); 

206
	g_signal_connect (strategy->details->view_frame,
207
			    "activate_uri", G_CALLBACK (activate_uri_callback), strategy);
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

	gtk_widget_show (strategy->details->client_widget);

	return NAUTILUS_ADAPTER_EMBED_STRATEGY (strategy);
}

static GtkWidget *
nautilus_adapter_embeddable_embed_strategy_get_widget (NautilusAdapterEmbedStrategy *abstract_strategy)
{
	NautilusAdapterEmbeddableEmbedStrategy *strategy;

	strategy = NAUTILUS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (abstract_strategy);
	return strategy->details->client_widget;
}

223
224
225
226
227
228
229
230
231
static BonoboObject *
nautilus_adapter_embeddable_embed_strategy_get_zoomable (NautilusAdapterEmbedStrategy *abstract_strategy)
{
	NautilusAdapterEmbeddableEmbedStrategy *strategy;

	strategy = NAUTILUS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (abstract_strategy);

	return strategy->details->zoomable;
}
232
233