1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "wxole.h"
21 #include "wx/statusbr.h"
22 #include "wx/toolbar.h"
24 #include "wx/gtk/win_gtk.h"
32 #include <libgnorba/gnorba.h>
33 #include <bonobo/bonobo.h>
34 #include <bonobo/gnome-main.h>
35 #include <bonobo/gnome-component.h>
36 #include <bonobo/gnome-component-factory.h>
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 const wxChar
*wxOleNameStr
= _T("olecontrol");
46 //---------------------------------------------------------------------------
47 // wxOleServerEnvPrivate
48 //---------------------------------------------------------------------------
50 class wxOleServerEnvPrivate
54 wxOleServerEnvPrivate() {}
55 ~wxOleServerEnvPrivate() {}
57 CORBA_Environment m_ev
;
61 //---------------------------------------------------------------------------
63 //---------------------------------------------------------------------------
65 IMPLEMENT_CLASS(wxOleServerEnv
,wxObject
)
67 wxOleServerEnv::wxOleServerEnv( const wxString
&name
, const wxString
&version
)
70 m_serverVersion
= version
;
72 m_priv
= new wxOleServerEnvPrivate();
74 CORBA_exception_init( &(m_priv
->m_ev
) );
77 m_serverName
.mb_str(),
78 m_serverVersion
.mb_str(),
81 GNORBA_INIT_SERVER_FUNC
,
84 if (m_priv
->m_ev
._major
!= CORBA_NO_EXCEPTION
)
89 m_priv
->m_orb
= gnome_CORBA_ORB();
91 if (bonobo_init( m_priv
->m_orb
, NULL
, NULL
) == FALSE
)
98 wxOleServerEnv::~wxOleServerEnv()
100 CORBA_exception_free( &(m_priv
->m_ev
) );
104 //---------------------------------------------------------------------------
105 // wxOleServerPrivate
106 //---------------------------------------------------------------------------
108 class wxOleServerPrivate
112 wxOleServerPrivate() {}
113 ~wxOleServerPrivate() {}
115 GnomeComponentFactory
*m_factory
;
118 //---------------------------------------------------------------------------
120 //---------------------------------------------------------------------------
123 gnome_view_factory_callback( GnomeComponent
*WXUNUSED(component
), wxOleServer
*server
)
126 printf( "Create OLE control.\n" );
129 wxOleControl
*ctx
= server
->CreateOleControl();
131 if (!ctx
) return (GnomeView
*) NULL
;
134 printf( "Creating OLE control succeeded. Returning as GnomeView\n" );
137 return gnome_view_new( ctx
->m_widget
);
140 static GnomeComponent
*
141 gnome_component_factory_callback( GnomeComponentFactory
*factory
, const char *path
, wxOleServer
*server
)
144 printf( "new component.\n" );
145 if (path) printf( "path is %s.\n", path );
148 GnomeComponent
*component
= gnome_component_new( gnome_view_factory_callback
, (void*) server
);
152 printf( "component creation failed.\n" );
154 printf( "component creation succeded.\n" );
160 IMPLEMENT_CLASS(wxOleServer
,wxObject
)
162 wxOleServer::wxOleServer( const wxString
&id
)
167 m_priv
= new wxOleServerPrivate();
170 printf( "new component factory.\n" );
173 m_priv
->m_factory
= gnome_component_factory_new( m_ID
.mb_str(), gnome_component_factory_callback
, (void*) this );
176 wxOleServer::~wxOleServer()
181 wxOleControl
*wxOleServer::CreateOleControl()
183 return new wxOleControl( -1 );
186 //-----------------------------------------------------------------------------
188 //-----------------------------------------------------------------------------
190 static void gtk_olectx_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxOleControl
*win
)
192 if (!win
->HasVMT()) return;
195 printf( "OnFrameResize from " );
196 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
197 printf( win->GetClassInfo()->GetClassName() );
201 if ((win
->m_width
!= alloc
->width
) || (win
->m_height
!= alloc
->height
))
203 win
->m_sizeSet
= FALSE
;
204 win
->m_width
= alloc
->width
;
205 win
->m_height
= alloc
->height
;
209 //-----------------------------------------------------------------------------
211 //-----------------------------------------------------------------------------
213 static gint
gtk_olectx_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxOleControl
*win
)
216 printf( "OnDelete from " );
217 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
218 printf( win->GetClassInfo()->GetClassName() );
227 //-----------------------------------------------------------------------------
229 //-----------------------------------------------------------------------------
231 static gint
gtk_olectx_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*event
, wxOleControl
*win
)
233 if (!win
->HasVMT()) return FALSE
;
238 wxMoveEvent
mevent( wxPoint(win
->m_x
,win
->m_y
), win
->GetId() );
239 mevent
.SetEventObject( win
);
240 win
->GetEventHandler()->ProcessEvent( mevent
);
245 //---------------------------------------------------------------------------
247 //---------------------------------------------------------------------------
249 IMPLEMENT_CLASS(wxOleControl
,wxFrame
)
251 wxOleControl::wxOleControl( wxWindowID id
, long style
, const wxString
&name
)
253 Create( id
, style
, name
);
256 bool wxOleControl::Create( wxWindowID id
, long style
, const wxString
&name
)
258 wxTopLevelWindows
.Append( this );
260 m_needParent
= FALSE
;
262 PreCreation( (wxWindow
*) NULL
, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);
264 m_title
= _T("wxWindows OLE Server");
266 /* any widget that can contain another widget and resizes it
268 m_widget
= gtk_hbox_new(0,0);
270 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
272 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
273 GTK_SIGNAL_FUNC(gtk_olectx_delete_callback
), (gpointer
)this );
275 /* m_mainWidget holds the toolbar, the menubar and the client area */
276 m_mainWidget
= gtk_myfixed_new();
277 gtk_widget_show( m_mainWidget
);
278 GTK_WIDGET_UNSET_FLAGS( m_mainWidget
, GTK_CAN_FOCUS
);
279 gtk_container_add( GTK_CONTAINER(m_widget
), m_mainWidget
);
281 /* m_wxwindow only represents the client area without toolbar and menubar */
282 m_wxwindow
= gtk_myfixed_new();
283 gtk_widget_show( m_wxwindow
);
284 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
285 gtk_container_add( GTK_CONTAINER(m_mainWidget
), m_wxwindow
);
289 /* the user resized the frame by dragging etc. */
290 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_allocate",
291 GTK_SIGNAL_FUNC(gtk_olectx_size_callback
), (gpointer
)this );
293 /* the only way to get the window size is to connect to this event */
294 gtk_signal_connect( GTK_OBJECT(m_widget
), "configure_event",
295 GTK_SIGNAL_FUNC(gtk_olectx_configure_callback
), (gpointer
)this );
297 gtk_widget_show_all( m_widget
);
302 wxOleControl::~wxOleControl()
304 if (m_frameMenuBar
) delete m_frameMenuBar
;
305 m_frameMenuBar
= (wxMenuBar
*) NULL
;
307 if (m_frameStatusBar
) delete m_frameStatusBar
;
308 m_frameStatusBar
= (wxStatusBar
*) NULL
;
310 if (m_frameToolBar
) delete m_frameToolBar
;
311 m_frameToolBar
= (wxToolBar
*) NULL
;
313 wxTopLevelWindows
.DeleteObject( this );
315 if (wxTheApp
->GetTopWindow() == this)
316 wxTheApp
->SetTopWindow( (wxWindow
*) NULL
);
318 if (wxTopLevelWindows
.Number() == 0)
319 wxTheApp
->ExitMainLoop();
323 void wxOleControl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
328 void wxOleControl::DoSetClientSize(int width
, int height
)