]> git.saurik.com Git - wxWidgets.git/blob - utils/wxOLE/gtk/wxole.cpp
jconfig.h uses configures results
[wxWidgets.git] / utils / wxOLE / gtk / wxole.cpp
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
12 #ifdef __GNUG__
13 #pragma implementation "wxole.h"
14 #endif
15
16 #include "wx/defs.h"
17 #include "wxole.h"
18
19 #include "wx/app.h"
20 #include "wx/menu.h"
21 #include "wx/statusbr.h"
22 #include "wx/toolbar.h"
23
24 #include "wx/gtk/win_gtk.h"
25
26
27 extern "C" {
28 #include "gtk/gtk.h"
29 #include "gdk/gdk.h"
30
31 #include <gnome.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>
37
38 }
39
40 //-----------------------------------------------------------------------------
41 // global data
42 //-----------------------------------------------------------------------------
43
44 const wxChar *wxOleNameStr = _T("olecontrol");
45
46 //---------------------------------------------------------------------------
47 // wxOleServerEnvPrivate
48 //---------------------------------------------------------------------------
49
50 class wxOleServerEnvPrivate
51 {
52 public:
53
54 wxOleServerEnvPrivate() {}
55 ~wxOleServerEnvPrivate() {}
56
57 CORBA_Environment m_ev;
58 CORBA_ORB m_orb;
59 };
60
61 //---------------------------------------------------------------------------
62 // wxOleServerEnv
63 //---------------------------------------------------------------------------
64
65 IMPLEMENT_CLASS(wxOleServerEnv,wxObject)
66
67 wxOleServerEnv::wxOleServerEnv( const wxString &name, const wxString &version )
68 {
69 m_serverName = name;
70 m_serverVersion = version;
71
72 m_priv = new wxOleServerEnvPrivate();
73
74 CORBA_exception_init( &(m_priv->m_ev) );
75
76 gnome_CORBA_init(
77 m_serverName.mb_str(),
78 m_serverVersion.mb_str(),
79 &wxTheApp->argc,
80 wxTheApp->argv,
81 GNORBA_INIT_SERVER_FUNC,
82 &(m_priv->m_ev) );
83
84 if (m_priv->m_ev._major != CORBA_NO_EXCEPTION)
85 {
86 return;
87 }
88
89 m_priv->m_orb = gnome_CORBA_ORB();
90
91 if (bonobo_init( m_priv->m_orb, NULL, NULL ) == FALSE)
92 {
93 return;
94 }
95
96 }
97
98 wxOleServerEnv::~wxOleServerEnv()
99 {
100 CORBA_exception_free( &(m_priv->m_ev) );
101 delete m_priv;
102 }
103
104 //---------------------------------------------------------------------------
105 // wxOleServerPrivate
106 //---------------------------------------------------------------------------
107
108 class wxOleServerPrivate
109 {
110 public:
111
112 wxOleServerPrivate() {}
113 ~wxOleServerPrivate() {}
114
115 GnomeComponentFactory *m_factory;
116 };
117
118 //---------------------------------------------------------------------------
119 // wxOleServer
120 //---------------------------------------------------------------------------
121
122 static GnomeView*
123 gnome_view_factory_callback( GnomeComponent *WXUNUSED(component), wxOleServer *server )
124 {
125 /*
126 printf( "Create OLE control.\n" );
127 */
128
129 wxOleControl *ctx = server->CreateOleControl();
130
131 if (!ctx) return (GnomeView*) NULL;
132
133 /*
134 printf( "Creating OLE control succeeded. Returning as GnomeView\n" );
135 */
136
137 return gnome_view_new( ctx->m_widget );
138 }
139
140 static GnomeComponent*
141 gnome_component_factory_callback( GnomeComponentFactory *factory, const char *path, wxOleServer *server )
142 {
143 /*
144 printf( "new component.\n" );
145 if (path) printf( "path is %s.\n", path );
146 */
147
148 GnomeComponent *component = gnome_component_new( gnome_view_factory_callback, (void*) server );
149
150 /*
151 if (!component)
152 printf( "component creation failed.\n" );
153 else
154 printf( "component creation succeded.\n" );
155 */
156
157 return component;
158 }
159
160 IMPLEMENT_CLASS(wxOleServer,wxObject)
161
162 wxOleServer::wxOleServer( const wxString &id )
163 {
164 m_ID = "component:";
165 m_ID += id;
166
167 m_priv = new wxOleServerPrivate();
168
169 /*
170 printf( "new component factory.\n" );
171 */
172
173 m_priv->m_factory = gnome_component_factory_new( m_ID.mb_str(), gnome_component_factory_callback, (void*) this );
174 }
175
176 wxOleServer::~wxOleServer()
177 {
178 delete m_priv;
179 }
180
181 wxOleControl *wxOleServer::CreateOleControl()
182 {
183 return new wxOleControl( -1 );
184 }
185
186 //-----------------------------------------------------------------------------
187 // "size_allocate"
188 //-----------------------------------------------------------------------------
189
190 static void gtk_olectx_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxOleControl *win )
191 {
192 if (!win->HasVMT()) return;
193
194 /*
195 printf( "OnFrameResize from " );
196 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
197 printf( win->GetClassInfo()->GetClassName() );
198 printf( ".\n" );
199 */
200
201 if ((win->m_width != alloc->width) || (win->m_height != alloc->height))
202 {
203 win->m_sizeSet = FALSE;
204 win->m_width = alloc->width;
205 win->m_height = alloc->height;
206 }
207 }
208
209 //-----------------------------------------------------------------------------
210 // "delete_event"
211 //-----------------------------------------------------------------------------
212
213 static gint gtk_olectx_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxOleControl *win )
214 {
215 /*
216 printf( "OnDelete from " );
217 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
218 printf( win->GetClassInfo()->GetClassName() );
219 printf( ".\n" );
220 */
221
222 win->Close();
223
224 return TRUE;
225 }
226
227 //-----------------------------------------------------------------------------
228 // "configure_event"
229 //-----------------------------------------------------------------------------
230
231 static gint gtk_olectx_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxOleControl *win )
232 {
233 if (!win->HasVMT()) return FALSE;
234
235 win->m_x = event->x;
236 win->m_y = event->y;
237
238 wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() );
239 mevent.SetEventObject( win );
240 win->GetEventHandler()->ProcessEvent( mevent );
241
242 return FALSE;
243 }
244
245 //---------------------------------------------------------------------------
246 // wxOleControl
247 //---------------------------------------------------------------------------
248
249 IMPLEMENT_CLASS(wxOleControl,wxFrame)
250
251 wxOleControl::wxOleControl( wxWindowID id, long style, const wxString &name )
252 {
253 Create( id, style, name );
254 }
255
256 bool wxOleControl::Create( wxWindowID id, long style, const wxString &name )
257 {
258 wxTopLevelWindows.Append( this );
259
260 m_needParent = FALSE;
261
262 PreCreation( (wxWindow*) NULL, id, wxDefaultPosition, wxDefaultSize, style, name );
263
264 m_title = _T("wxWindows OLE Server");
265
266 /* any widget that can contain another widget and resizes it
267 to its full size */
268 m_widget = gtk_hbox_new(0,0);
269
270 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
271
272 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
273 GTK_SIGNAL_FUNC(gtk_olectx_delete_callback), (gpointer)this );
274
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 );
280
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 );
286
287 PostCreation();
288
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 );
292
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 );
296
297 gtk_widget_show_all( m_widget );
298
299 return TRUE;
300 }
301
302 wxOleControl::~wxOleControl()
303 {
304 if (m_frameMenuBar) delete m_frameMenuBar;
305 m_frameMenuBar = (wxMenuBar *) NULL;
306
307 if (m_frameStatusBar) delete m_frameStatusBar;
308 m_frameStatusBar = (wxStatusBar *) NULL;
309
310 if (m_frameToolBar) delete m_frameToolBar;
311 m_frameToolBar = (wxToolBar *) NULL;
312
313 wxTopLevelWindows.DeleteObject( this );
314
315 if (wxTheApp->GetTopWindow() == this)
316 wxTheApp->SetTopWindow( (wxWindow*) NULL );
317
318 if (wxTopLevelWindows.Number() == 0)
319 wxTheApp->ExitMainLoop();
320 }
321
322
323 void wxOleControl::DoSetSize( int x, int y, int width, int height, int sizeFlags )
324 {
325 // ignore
326 }
327
328 void wxOleControl::DoSetClientSize(int width, int height)
329 {
330 // ignore
331 }