From 10d5be9ad3355c955225b88ad1fb0b739bce4a34 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 25 Apr 1999 16:55:03 +0000 Subject: [PATCH] experimental OLE control (the reason for the recent reshuffle) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2283 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- utils/wxOLE/gtk/wxole.cpp | 331 +++++++++++++++++++++ utils/wxOLE/gtk/wxole.h | 108 +++++++ utils/wxOLE/samples/servlet/.cvsignore | 7 + utils/wxOLE/samples/servlet/Makefile | 29 ++ utils/wxOLE/samples/servlet/mondrian.xpm | 44 +++ utils/wxOLE/samples/servlet/servlet.cpp | 135 +++++++++ utils/wxOLE/samples/servlet/servlet.gnorba | 13 + 7 files changed, 667 insertions(+) create mode 100644 utils/wxOLE/gtk/wxole.cpp create mode 100644 utils/wxOLE/gtk/wxole.h create mode 100644 utils/wxOLE/samples/servlet/.cvsignore create mode 100644 utils/wxOLE/samples/servlet/Makefile create mode 100644 utils/wxOLE/samples/servlet/mondrian.xpm create mode 100644 utils/wxOLE/samples/servlet/servlet.cpp create mode 100644 utils/wxOLE/samples/servlet/servlet.gnorba diff --git a/utils/wxOLE/gtk/wxole.cpp b/utils/wxOLE/gtk/wxole.cpp new file mode 100644 index 0000000000..791acc320e --- /dev/null +++ b/utils/wxOLE/gtk/wxole.cpp @@ -0,0 +1,331 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wxole.cpp +// Purpose: wxOLE +// Author: Robert Roebling +// Modified by: +// Created: 20/04/99 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "wxole.h" +#endif + +#include "wx/defs.h" +#include "wxole.h" + +#include "wx/app.h" +#include "wx/menu.h" +#include "wx/statusbr.h" +#include "wx/toolbar.h" + +#include "wx/gtk/win_gtk.h" + + +extern "C" { +#include "gtk/gtk.h" +#include "gdk/gdk.h" + +#include +#include +#include +#include +#include +#include + +} + +//----------------------------------------------------------------------------- +// global data +//----------------------------------------------------------------------------- + +const wxChar *wxOleNameStr = _T("olecontrol"); + +//--------------------------------------------------------------------------- +// wxOleServerEnvPrivate +//--------------------------------------------------------------------------- + +class wxOleServerEnvPrivate +{ +public: + + wxOleServerEnvPrivate() {} + ~wxOleServerEnvPrivate() {} + + CORBA_Environment m_ev; + CORBA_ORB m_orb; +}; + +//--------------------------------------------------------------------------- +// wxOleServerEnv +//--------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxOleServerEnv,wxObject) + +wxOleServerEnv::wxOleServerEnv( const wxString &name, const wxString &version ) +{ + m_serverName = name; + m_serverVersion = version; + + m_priv = new wxOleServerEnvPrivate(); + + CORBA_exception_init( &(m_priv->m_ev) ); + + gnome_CORBA_init( + m_serverName.mb_str(), + m_serverVersion.mb_str(), + &wxTheApp->argc, + wxTheApp->argv, + GNORBA_INIT_SERVER_FUNC, + &(m_priv->m_ev) ); + + if (m_priv->m_ev._major != CORBA_NO_EXCEPTION) + { + return; + } + + m_priv->m_orb = gnome_CORBA_ORB(); + + if (bonobo_init( m_priv->m_orb, NULL, NULL ) == FALSE) + { + return; + } + +} + +wxOleServerEnv::~wxOleServerEnv() +{ + CORBA_exception_free( &(m_priv->m_ev) ); + delete m_priv; +} + +//--------------------------------------------------------------------------- +// wxOleServerPrivate +//--------------------------------------------------------------------------- + +class wxOleServerPrivate +{ +public: + + wxOleServerPrivate() {} + ~wxOleServerPrivate() {} + + GnomeComponentFactory *m_factory; +}; + +//--------------------------------------------------------------------------- +// wxOleServer +//--------------------------------------------------------------------------- + +static GnomeView* +gnome_view_factory_callback( GnomeComponent *WXUNUSED(component), wxOleServer *server ) +{ +/* + printf( "Create OLE control.\n" ); +*/ + + wxOleControl *ctx = server->CreateOleControl(); + + if (!ctx) return (GnomeView*) NULL; + +/* + printf( "Creating OLE control succeeded. Returning as GnomeView\n" ); +*/ + + return gnome_view_new( ctx->m_widget ); +} + +static GnomeComponent* +gnome_component_factory_callback( GnomeComponentFactory *factory, const char *path, wxOleServer *server ) +{ +/* + printf( "new component.\n" ); + if (path) printf( "path is %s.\n", path ); +*/ + + GnomeComponent *component = gnome_component_new( gnome_view_factory_callback, (void*) server ); + +/* + if (!component) + printf( "component creation failed.\n" ); + else + printf( "component creation succeded.\n" ); +*/ + + return component; +} + +IMPLEMENT_CLASS(wxOleServer,wxObject) + +wxOleServer::wxOleServer( const wxString &id ) +{ + m_ID = "component:"; + m_ID += id; + + m_priv = new wxOleServerPrivate(); + +/* + printf( "new component factory.\n" ); +*/ + + m_priv->m_factory = gnome_component_factory_new( m_ID.mb_str(), gnome_component_factory_callback, (void*) this ); +} + +wxOleServer::~wxOleServer() +{ + delete m_priv; +} + +wxOleControl *wxOleServer::CreateOleControl() +{ + return new wxOleControl( -1 ); +} + +//----------------------------------------------------------------------------- +// "size_allocate" +//----------------------------------------------------------------------------- + +static void gtk_olectx_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxOleControl *win ) +{ + if (!win->HasVMT()) return; + +/* + printf( "OnFrameResize from " ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + printf( win->GetClassInfo()->GetClassName() ); + printf( ".\n" ); +*/ + + if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) + { + win->m_sizeSet = FALSE; + win->m_width = alloc->width; + win->m_height = alloc->height; + } +} + +//----------------------------------------------------------------------------- +// "delete_event" +//----------------------------------------------------------------------------- + +static gint gtk_olectx_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxOleControl *win ) +{ +/* + printf( "OnDelete from " ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + printf( win->GetClassInfo()->GetClassName() ); + printf( ".\n" ); +*/ + + win->Close(); + + return TRUE; +} + +//----------------------------------------------------------------------------- +// "configure_event" +//----------------------------------------------------------------------------- + +static gint gtk_olectx_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxOleControl *win ) +{ + if (!win->HasVMT()) return FALSE; + + win->m_x = event->x; + win->m_y = event->y; + + wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() ); + mevent.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( mevent ); + + return FALSE; +} + +//--------------------------------------------------------------------------- +// wxOleControl +//--------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxOleControl,wxFrame) + +wxOleControl::wxOleControl( wxWindowID id, long style, const wxString &name ) +{ + Create( id, style, name ); +} + +bool wxOleControl::Create( wxWindowID id, long style, const wxString &name ) +{ + wxTopLevelWindows.Append( this ); + + m_needParent = FALSE; + + PreCreation( (wxWindow*) NULL, id, wxDefaultPosition, wxDefaultSize, style, name ); + + m_title = _T("wxWindows OLE Server"); + + /* any widget that can contain another widget and resizes it + to its full size */ + m_widget = gtk_hbox_new(0,0); + + GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); + + gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", + GTK_SIGNAL_FUNC(gtk_olectx_delete_callback), (gpointer)this ); + + /* m_mainWidget holds the toolbar, the menubar and the client area */ + m_mainWidget = gtk_myfixed_new(); + gtk_widget_show( m_mainWidget ); + GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS ); + gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); + + /* m_wxwindow only represents the client area without toolbar and menubar */ + m_wxwindow = gtk_myfixed_new(); + gtk_widget_show( m_wxwindow ); + GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); + gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); + + PostCreation(); + + /* the user resized the frame by dragging etc. */ + gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_olectx_size_callback), (gpointer)this ); + + /* the only way to get the window size is to connect to this event */ + gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", + GTK_SIGNAL_FUNC(gtk_olectx_configure_callback), (gpointer)this ); + + gtk_widget_show_all( m_widget ); + + return TRUE; +} + +wxOleControl::~wxOleControl() +{ + if (m_frameMenuBar) delete m_frameMenuBar; + m_frameMenuBar = (wxMenuBar *) NULL; + + if (m_frameStatusBar) delete m_frameStatusBar; + m_frameStatusBar = (wxStatusBar *) NULL; + + if (m_frameToolBar) delete m_frameToolBar; + m_frameToolBar = (wxToolBar *) NULL; + + wxTopLevelWindows.DeleteObject( this ); + + if (wxTheApp->GetTopWindow() == this) + wxTheApp->SetTopWindow( (wxWindow*) NULL ); + + if (wxTopLevelWindows.Number() == 0) + wxTheApp->ExitMainLoop(); +} + + +void wxOleControl::DoSetSize( int x, int y, int width, int height, int sizeFlags ) +{ + // ignore +} + +void wxOleControl::DoSetClientSize(int width, int height) +{ + // ignore +} diff --git a/utils/wxOLE/gtk/wxole.h b/utils/wxOLE/gtk/wxole.h new file mode 100644 index 0000000000..477ac9f9e6 --- /dev/null +++ b/utils/wxOLE/gtk/wxole.h @@ -0,0 +1,108 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wxole.h +// Purpose: wxOLE +// Author: Robert Roebling +// Modified by: +// Created: 17/8/98 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma interface "wxole.h" +#endif + +#ifndef _WX_OLE_H_ +#define _WX_OLE_H_ + +#include "wx/defs.h" +#include "wx/object.h" +#include "wx/frame.h" + +//----------------------------------------------------------------------------- +// global data +//----------------------------------------------------------------------------- + +extern const wxChar *wxOleNameStr; + +//--------------------------------------------------------------------------- +// classes +//--------------------------------------------------------------------------- + +class wxOleServerEnv; +class wxOleServer; +class wxOleControl; + +//--------------------------------------------------------------------------- +// wxOleServerEnv +//--------------------------------------------------------------------------- + +class wxOleServerEnvPrivate; + +class wxOleServerEnv : public wxObject +{ + DECLARE_CLASS(wxOleServerEnv) + +public: + + wxOleServerEnv( const wxString &name, const wxString &version ); + ~wxOleServerEnv(); + +private: + + wxString m_serverName; + wxString m_serverVersion; + +protected: + wxOleServerEnvPrivate *m_priv; +}; + +//--------------------------------------------------------------------------- +// wxOleServer +//--------------------------------------------------------------------------- + +class wxOleServerPrivate; + +class wxOleServer : public wxObject +{ + DECLARE_CLASS(wxOleServer) + +public: + + wxOleServer( const wxString &id ); + ~wxOleServer(); + + virtual wxOleControl *CreateOleControl(); + +private: + + wxString m_ID; + +protected: + wxOleServerPrivate *m_priv; +}; + +//--------------------------------------------------------------------------- +// wxOleControl +//--------------------------------------------------------------------------- + +class wxOleControl : public wxFrame +{ + DECLARE_CLASS(wxOleControl) + +public: + + wxOleControl( wxWindowID id, long style = 0, const wxString &name = wxOleNameStr ); + ~wxOleControl(); + bool Create( wxWindowID id, long style = 0, const wxString &name = wxOleNameStr ); + +protected: + virtual void DoSetSize(int x, int y, + int width, int height, + int sizeFlags = wxSIZE_AUTO); + + virtual void DoSetClientSize(int width, int height); +}; + +#endif diff --git a/utils/wxOLE/samples/servlet/.cvsignore b/utils/wxOLE/samples/servlet/.cvsignore new file mode 100644 index 0000000000..cab85a75c6 --- /dev/null +++ b/utils/wxOLE/samples/servlet/.cvsignore @@ -0,0 +1,7 @@ +Linux +linux-gnu +linux +servelt +test-coontainer +servlet.o +wxole.o diff --git a/utils/wxOLE/samples/servlet/Makefile b/utils/wxOLE/samples/servlet/Makefile new file mode 100644 index 0000000000..eb26fa7a56 --- /dev/null +++ b/utils/wxOLE/samples/servlet/Makefile @@ -0,0 +1,29 @@ +# +# File: Makefile +# Author: Robert Roebling +# Created: 1999 +# Updated: +# Copyright: (c) 1998 Robert Roebling +# +# Makefile for OLE demo (GTK version) +# +# This makefile requires wxWindows/GTK to be +# installed (possibly using "make install") +# on your system. +# + +CC = g++ + +servlet: servlet.o wxole.o + $(CC) -o servlet servlet.o wxole.o \ + `wx-config --libs` -lbonobo `gnome-config --libs gnorba` `gnome-config --libs gnomeui` + +servlet.o: servlet.cpp + $(CC) `wx-config --cflags` `gtk-config --cflags` -I../../gtk -c servlet.cpp + +wxole.o: ../../gtk/wxole.cpp + $(CC) `wx-config --cflags` `gtk-config --cflags` `gnome-config --cflags gnorba` \ + -I../../gtk -c ../../gtk/wxole.cpp + +clean: + rm -f *.o servlet diff --git a/utils/wxOLE/samples/servlet/mondrian.xpm b/utils/wxOLE/samples/servlet/mondrian.xpm new file mode 100644 index 0000000000..409f27a843 --- /dev/null +++ b/utils/wxOLE/samples/servlet/mondrian.xpm @@ -0,0 +1,44 @@ +/* XPM */ +static char *mondrian_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 6 1", +" c Black", +". c Blue", +"X c #00bf00", +"o c Red", +"O c Yellow", +"+ c Gray100", +/* pixels */ +" ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" " +}; diff --git a/utils/wxOLE/samples/servlet/servlet.cpp b/utils/wxOLE/samples/servlet/servlet.cpp new file mode 100644 index 0000000000..9e6b2d6416 --- /dev/null +++ b/utils/wxOLE/samples/servlet/servlet.cpp @@ -0,0 +1,135 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: servlet.cpp +// Purpose: Minimal wxWindows OLE server sample +// Author: Robert Roebling +// Modified by: +// Created: 20/04/99 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ + #pragma implementation "servlet.cpp" + #pragma interface "servlet.cpp" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +// For OLE stuff +#include "wxole.h" + +#if defined(__WXGTK__) || defined(__WXMOTIF__) + #include "mondrian.xpm" +#endif + +//---------------------------------------------------------------------------- +// MyOleControl +//---------------------------------------------------------------------------- + +class MyOleControl : public wxOleControl +{ +public: + + MyOleControl(); + + void OnPaint( wxPaintEvent &event ); + +private: + DECLARE_EVENT_TABLE() +}; + +//---------------------------------------------------------------------------- +// MyOleServer +//---------------------------------------------------------------------------- + +class MyOleServer : public wxOleServer +{ +public: + + MyOleServer() : wxOleServer( "servlet" ) { } + + wxOleControl *CreateOleControl() { return new MyOleControl(); } +}; + +//---------------------------------------------------------------------------- +// MyApp +//---------------------------------------------------------------------------- + +class MyApp : public wxApp +{ +public: + + MyApp(); + ~MyApp(); + + virtual bool OnInit(); + + wxOleServerEnv *m_oleEnv; + MyOleServer *m_oleServer; +}; + +//---------------------------------------------------------------------------- +// main +//---------------------------------------------------------------------------- + +IMPLEMENT_APP(MyApp) + +//---------------------------------------------------------------------------- +// MyApp +//---------------------------------------------------------------------------- + +MyApp::MyApp() +{ +} + +MyApp::~MyApp() +{ + delete m_oleEnv; + delete m_oleServer; +} + +#include "gtk/gtk.h" + +bool MyApp::OnInit() +{ + m_oleEnv = new wxOleServerEnv( "MyServer", "1.0" ); + m_oleServer = new MyOleServer(); + + /* how do we get outta here ? */ + for (;;) wxYield(); + + return TRUE; +} + +//---------------------------------------------------------------------------- +// MyOleControl +//---------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE(MyOleControl, wxOleControl) + EVT_PAINT(MyOleControl::OnPaint) +END_EVENT_TABLE() + +MyOleControl::MyOleControl() : + wxOleControl( -1 ) +{ + (void)new wxButton( this, -1, "Ole, Ole", wxPoint(5,40), wxSize(120,-1) ); + (void)new wxButton( this, -1, "Greetings", wxPoint(5,70), wxSize(120,-1) ); +} + +void MyOleControl::OnPaint( wxPaintEvent &WXUNUSED(event) ) +{ + wxPaintDC dc(this); + dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) ); + dc.DrawText( "wxWindows rules!", 5, 5 ); +} + diff --git a/utils/wxOLE/samples/servlet/servlet.gnorba b/utils/wxOLE/samples/servlet/servlet.gnorba new file mode 100644 index 0000000000..b6ee8b436e --- /dev/null +++ b/utils/wxOLE/samples/servlet/servlet.gnorba @@ -0,0 +1,13 @@ +[component-factory:servlet] +type=exe +repo_id=IDL:GNOME/ComponentFactory:1.0 IDL:GNOME/GenericFactory:1.0 +description=wxOLE test object server factory +location_info=servlet + +[component:servlet] +type=factory +repo_id=IDL:Component/servlet:1.0 IDL:GNOME/Component:1.0 +description=wxOLE Test server component +location_info=component-factory:servlet + + -- 2.45.2