]> git.saurik.com Git - wxWidgets.git/blame - utils/wxOLE/gtk/wxole.cpp
Compile corrections
[wxWidgets.git] / utils / wxOLE / gtk / wxole.cpp
CommitLineData
10d5be9a
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: wxole.cpp
3// Purpose: wxOLE
4// Author: Robert Roebling
5// Modified by:
6// Created: 20/04/99
7// RCS-ID: $Id$
8// Copyright: (c) Robert Roebling
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
10d5be9a
RR
12#include "wx/defs.h"
13#include "wxole.h"
14
15#include "wx/app.h"
16#include "wx/menu.h"
17#include "wx/statusbr.h"
18#include "wx/toolbar.h"
86fdd27b 19#include "wx/stream.h"
10d5be9a
RR
20
21#include "wx/gtk/win_gtk.h"
22
10d5be9a
RR
23extern "C" {
24#include "gtk/gtk.h"
25#include "gdk/gdk.h"
26
27#include <gnome.h>
28#include <libgnorba/gnorba.h>
29#include <bonobo/bonobo.h>
30#include <bonobo/gnome-main.h>
31#include <bonobo/gnome-component.h>
32#include <bonobo/gnome-component-factory.h>
86fdd27b
RR
33#include <bonobo/gnome-persist-stream.h>
34#include <bonobo/gtk-interfaces.h>
10d5be9a
RR
35}
36
86fdd27b 37
10d5be9a
RR
38//-----------------------------------------------------------------------------
39// global data
40//-----------------------------------------------------------------------------
41
42const wxChar *wxOleNameStr = _T("olecontrol");
43
44//---------------------------------------------------------------------------
45// wxOleServerEnvPrivate
46//---------------------------------------------------------------------------
47
48class wxOleServerEnvPrivate
49{
50public:
51
52 wxOleServerEnvPrivate() {}
53 ~wxOleServerEnvPrivate() {}
54
55 CORBA_Environment m_ev;
56 CORBA_ORB m_orb;
57};
58
86fdd27b
RR
59//---------------------------------------------------------------------------
60// wxOleInputStream
61//---------------------------------------------------------------------------
62
63class wxOleInputStream : public wxInputStream
64{
65public:
66
67 wxOleInputStream( GNOME_Stream stream );
68 ~wxOleInputStream();
69
70 bool Ok() const { return m_error; }
71
72protected:
73
74 bool m_error;
75 GNOME_Stream m_gstream;
76
77 size_t OnSysRead(void *buffer, size_t size);
78 off_t OnSysSeek(off_t pos, wxSeekMode mode);
79 off_t OnSysTell() const;
80};
81
10d5be9a
RR
82//---------------------------------------------------------------------------
83// wxOleServerEnv
84//---------------------------------------------------------------------------
85
86IMPLEMENT_CLASS(wxOleServerEnv,wxObject)
87
88wxOleServerEnv::wxOleServerEnv( const wxString &name, const wxString &version )
89{
90 m_serverName = name;
91 m_serverVersion = version;
92
93 m_priv = new wxOleServerEnvPrivate();
94
95 CORBA_exception_init( &(m_priv->m_ev) );
96
97 gnome_CORBA_init(
98 m_serverName.mb_str(),
99 m_serverVersion.mb_str(),
100 &wxTheApp->argc,
101 wxTheApp->argv,
102 GNORBA_INIT_SERVER_FUNC,
103 &(m_priv->m_ev) );
104
105 if (m_priv->m_ev._major != CORBA_NO_EXCEPTION)
106 {
107 return;
108 }
109
110 m_priv->m_orb = gnome_CORBA_ORB();
111
112 if (bonobo_init( m_priv->m_orb, NULL, NULL ) == FALSE)
113 {
114 return;
115 }
116
117}
118
119wxOleServerEnv::~wxOleServerEnv()
120{
121 CORBA_exception_free( &(m_priv->m_ev) );
122 delete m_priv;
123}
124
86fdd27b
RR
125//---------------------------------------------------------------------------
126// wxOleInputStream
127//---------------------------------------------------------------------------
128
129wxOleInputStream::wxOleInputStream( GNOME_Stream stream )
130{
131 m_gstream = stream;
132 m_error = (m_gstream);
133}
134
135wxOleInputStream::~wxOleInputStream()
136{
137 /* we don't create the stream so we
138 don't destroy it either. */
139}
140
141size_t wxOleInputStream::OnSysRead( void *buffer, size_t size )
142{
143 GNOME_Stream_iobuf *gbuffer = GNOME_Stream_iobuf__alloc();
144
145 CORBA_Environment ev;
146 CORBA_exception_init( &ev );
147
148 GNOME_Stream_read( m_gstream, size, &gbuffer, &ev );
149
150 CORBA_exception_free( &ev );
151
152 memcpy( buffer, gbuffer->_buffer, gbuffer->_length );
153
154 m_error = (gbuffer->_length != size);
155
156 CORBA_free( gbuffer );
157}
158
159off_t wxOleInputStream::OnSysSeek( off_t pos, wxSeekMode mode )
160{
161 CORBA_Environment ev;
162 CORBA_exception_init( &ev );
163
164 GNOME_Stream_seek( m_gstream, pos /* offset */, 0 /* whence */, &ev );
165
166 CORBA_exception_free( &ev );
167}
168
169off_t wxOleInputStream::OnSysTell() const
170{
171 return 0; /* oh well */
172}
173
174
10d5be9a
RR
175//---------------------------------------------------------------------------
176// wxOleServerPrivate
177//---------------------------------------------------------------------------
178
179class wxOleServerPrivate
180{
181public:
182
183 wxOleServerPrivate() {}
184 ~wxOleServerPrivate() {}
185
186 GnomeComponentFactory *m_factory;
187};
188
189//---------------------------------------------------------------------------
190// wxOleServer
191//---------------------------------------------------------------------------
192
193static GnomeView*
86fdd27b 194gnome_view_factory_callback( GnomeComponent *component, wxOleServer *server )
10d5be9a
RR
195{
196/*
197 printf( "Create OLE control.\n" );
198*/
199
200 wxOleControl *ctx = server->CreateOleControl();
201
202 if (!ctx) return (GnomeView*) NULL;
203
204/*
205 printf( "Creating OLE control succeeded. Returning as GnomeView\n" );
206*/
207
208 return gnome_view_new( ctx->m_widget );
209}
210
86fdd27b
RR
211static int
212gnome_load_from_stream_callback( GnomePersistStream *ps, GNOME_Stream stream, GnomeComponent* component )
213{
214 wxOleInputStream wxstream( stream );
215
216
217}
218
10d5be9a
RR
219static GnomeComponent*
220gnome_component_factory_callback( GnomeComponentFactory *factory, const char *path, wxOleServer *server )
221{
222/*
223 printf( "new component.\n" );
224 if (path) printf( "path is %s.\n", path );
225*/
226
86fdd27b
RR
227 GnomeComponent *component =
228 gnome_component_new( gnome_view_factory_callback, (void*) server );
10d5be9a
RR
229
230/*
231 if (!component)
232 printf( "component creation failed.\n" );
233 else
234 printf( "component creation succeded.\n" );
235*/
86fdd27b
RR
236
237 GnomePersistStream *stream =
238 gnome_persist_stream_new( gnome_load_from_stream_callback, NULL /*save*/, (void*) component );
239
240/*
241 if (!stream)
242 printf( "stream creation failed.\n" );
243 else
244 printf( "stream creation succeded.\n" );
245*/
246
247 gtk_object_add_interface( GTK_OBJECT(component), GTK_OBJECT(stream) );
248
10d5be9a
RR
249 return component;
250}
251
252IMPLEMENT_CLASS(wxOleServer,wxObject)
253
254wxOleServer::wxOleServer( const wxString &id )
255{
256 m_ID = "component:";
257 m_ID += id;
258
259 m_priv = new wxOleServerPrivate();
260
261/*
262 printf( "new component factory.\n" );
263*/
264
86fdd27b
RR
265 m_priv->m_factory =
266 gnome_component_factory_new( m_ID.mb_str(), gnome_component_factory_callback, (void*) this );
10d5be9a
RR
267}
268
269wxOleServer::~wxOleServer()
270{
271 delete m_priv;
272}
273
274wxOleControl *wxOleServer::CreateOleControl()
275{
276 return new wxOleControl( -1 );
277}
278
279//-----------------------------------------------------------------------------
280// "size_allocate"
281//-----------------------------------------------------------------------------
282
283static void gtk_olectx_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxOleControl *win )
284{
86fdd27b 285 if (!win->m_hasVMT) return;
10d5be9a
RR
286
287/*
288 printf( "OnFrameResize from " );
289 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
290 printf( win->GetClassInfo()->GetClassName() );
291 printf( ".\n" );
292*/
293
294 if ((win->m_width != alloc->width) || (win->m_height != alloc->height))
295 {
296 win->m_sizeSet = FALSE;
297 win->m_width = alloc->width;
298 win->m_height = alloc->height;
299 }
300}
301
302//-----------------------------------------------------------------------------
303// "delete_event"
304//-----------------------------------------------------------------------------
305
306static gint gtk_olectx_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxOleControl *win )
307{
308/*
309 printf( "OnDelete from " );
310 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
311 printf( win->GetClassInfo()->GetClassName() );
312 printf( ".\n" );
313*/
314
315 win->Close();
316
317 return TRUE;
318}
319
320//-----------------------------------------------------------------------------
321// "configure_event"
322//-----------------------------------------------------------------------------
323
324static gint gtk_olectx_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxOleControl *win )
325{
86fdd27b 326 if (!win->m_hasVMT) return FALSE;
10d5be9a
RR
327
328 win->m_x = event->x;
329 win->m_y = event->y;
330
331 wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() );
332 mevent.SetEventObject( win );
333 win->GetEventHandler()->ProcessEvent( mevent );
334
335 return FALSE;
336}
337
338//---------------------------------------------------------------------------
339// wxOleControl
340//---------------------------------------------------------------------------
341
342IMPLEMENT_CLASS(wxOleControl,wxFrame)
343
344wxOleControl::wxOleControl( wxWindowID id, long style, const wxString &name )
345{
346 Create( id, style, name );
347}
348
349bool wxOleControl::Create( wxWindowID id, long style, const wxString &name )
350{
351 wxTopLevelWindows.Append( this );
352
353 m_needParent = FALSE;
354
355 PreCreation( (wxWindow*) NULL, id, wxDefaultPosition, wxDefaultSize, style, name );
356
be5a51fb 357 m_title = _T("wxWidgets OLE Server");
10d5be9a
RR
358
359 /* any widget that can contain another widget and resizes it
360 to its full size */
361 m_widget = gtk_hbox_new(0,0);
362
363 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
364
365 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
366 GTK_SIGNAL_FUNC(gtk_olectx_delete_callback), (gpointer)this );
367
368 /* m_mainWidget holds the toolbar, the menubar and the client area */
369 m_mainWidget = gtk_myfixed_new();
370 gtk_widget_show( m_mainWidget );
371 GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS );
372 gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget );
373
374 /* m_wxwindow only represents the client area without toolbar and menubar */
375 m_wxwindow = gtk_myfixed_new();
376 gtk_widget_show( m_wxwindow );
377 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
378 gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow );
379
380 PostCreation();
381
382 /* the user resized the frame by dragging etc. */
383 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
384 GTK_SIGNAL_FUNC(gtk_olectx_size_callback), (gpointer)this );
385
386 /* the only way to get the window size is to connect to this event */
387 gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event",
388 GTK_SIGNAL_FUNC(gtk_olectx_configure_callback), (gpointer)this );
389
390 gtk_widget_show_all( m_widget );
391
392 return TRUE;
393}
394
395wxOleControl::~wxOleControl()
396{
397 if (m_frameMenuBar) delete m_frameMenuBar;
398 m_frameMenuBar = (wxMenuBar *) NULL;
399
400 if (m_frameStatusBar) delete m_frameStatusBar;
401 m_frameStatusBar = (wxStatusBar *) NULL;
402
403 if (m_frameToolBar) delete m_frameToolBar;
404 m_frameToolBar = (wxToolBar *) NULL;
405
406 wxTopLevelWindows.DeleteObject( this );
407
408 if (wxTheApp->GetTopWindow() == this)
409 wxTheApp->SetTopWindow( (wxWindow*) NULL );
410
411 if (wxTopLevelWindows.Number() == 0)
412 wxTheApp->ExitMainLoop();
413}
414
415
416void wxOleControl::DoSetSize( int x, int y, int width, int height, int sizeFlags )
417{
418 // ignore
419}
420
421void wxOleControl::DoSetClientSize(int width, int height)
422{
423 // ignore
424}