diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /odk/examples/OLE | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/OLE')
25 files changed, 2607 insertions, 0 deletions
diff --git a/odk/examples/OLE/activex/Makefile b/odk/examples/OLE/activex/Makefile new file mode 100644 index 000000000..15167bc93 --- /dev/null +++ b/odk/examples/OLE/activex/Makefile @@ -0,0 +1,121 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the OLE activex C++ component example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +COMPONENT_NAME=so_activex +COMPONENT_IMPL_NAME=$(SHAREDLIB_PRE)$(COMPONENT_NAME).$(SHAREDLIB_EXT) +COMPONENT_IMPL=$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(COMPONENT_NAME).$(SHAREDLIB_EXT) +OUT_COMP_INC = $(OUT_INC)/$(COMPONENT_NAME) +OUT_COMP_GEN = $(OUT_MISC)/$(COMPONENT_NAME) +OUT_COMP_SLO=$(OUT_SLO)/$(COMPONENT_NAME) + +MIDLFILES = so_activex.idl + +CXXFILES = SOActiveX.cpp \ + SOComWindowPeer.cpp \ + so_activex.cpp \ + StdAfx2.cpp + +SLOFILES = $(patsubst %.cpp,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES)) + +# Targets +.PHONY: ALL +ALL : \ + OleActvieXComponentExample + +include $(SETTINGS)/stdtarget.mk + +# Attention: so_activex.idl is no UNOIDL file! +$(OUT_COMP_INC)/so_activex.h : so_activex.idl + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) + midl.exe /tlb $(OUT_COMP_GEN)/so_activex.tlb /h $(OUT_COMP_INC)/so_activex.h \ + /iid $(OUT_COMP_INC)/so_activex_i.c /proxy $(OUT_COMP_INC)/so_activex_p.c \ + /dlldata $(OUT_COMP_INC)/dlldata.c /Oicf $< + +$(OUT_COMP_GEN)/so_activex.res : so_activex.rc $(OUT_COMP_INC)/so_activex.h + -$(MKDIR) $(subst /,$(PS),$(@D)) + rc $(CC_INCLUDES) /R /FO$@ so_activex.rc + +$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cpp + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + + +# Note: If you don't use the MS Visual Studio .Net, please comment out the next line. +CL_NEW_LIB=atls.lib + +$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)%.$(SHAREDLIB_EXT) : $(SLOFILES) $(OUT_COMP_GEN)/so_activex.res so_activex.def + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_LIB)) + @echo . + @echo ----------------------------------------------------------------------------------- + @echo ATTENTION: If you have problems with linking the library and if you do not use the + @echo MS .Net compiler please check the makefile and comment out the variable CL_NEW_LIB. + @echo ----------------------------------------------------------------------------------- + @echo . + $(LINK) $(LIBRARY_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) \ + /DEF:so_activex.def /IMPLIB:$(OUT_LIB)/iso_activex.lib $(SLOFILES) \ + $(LIBO_SDK_LDFLAGS_STDLIBS) user32.lib uuid.lib advapi32.lib ole32.lib oleaut32.lib gdi32.lib \ + urlmon.lib Shlwapi.lib oldnames.lib $(CL_NEW_LIB) $(OUT_COMP_GEN)/so_activex.res + $(LINK_MANIFEST) + +ifeq "$(OS)" "WIN" +OleActvieXComponentExample : $(COMPONENT_IMPL) + @echo -------------------------------------------------------------------------------- + @echo The activex control was created, please load the "$(QM)example.html$(QM)" file + @echo in your InternetExplorer to use the activex control. + @echo -------------------------------------------------------------------------------- +else +OleActvieXComponentExample : + @echo -------------------------------------------------------------------------------- + @echo This example works only under Windows! + @echo -------------------------------------------------------------------------------- +endif + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_LIB)/*$(COMPONENT_NAME).*)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(COMPONENT_NAME).*)) diff --git a/odk/examples/OLE/activex/README.txt b/odk/examples/OLE/activex/README.txt new file mode 100644 index 000000000..6528c528f --- /dev/null +++ b/odk/examples/OLE/activex/README.txt @@ -0,0 +1,40 @@ +* Compile. + +Warning: Before the control can be built user has to add path to MS ATL headers + into Makefile. + +If you use the build environment of the SDK you have to check which MS compiler +do you use. It you use the MS Visual Studio .NET compiler everything should work +fine with the SDK. If you use an older MS compiler please edit the Makefile and +uncomment or remove the line 'CL_NEW_LIB=atls.lib'. + +* Description. + +The LibreOffice ActiveX control shows an example of access to UNO through COM technology. +It requires a properly installed LibreOffice version 4.0 or later +This is a Lite ActiveX control so it can be used only in containers that +allows to use such controls. It can be activated with an <OBJECT> tag from +a html-page to embed a document. Without any parameters a new writer document will be +opened for editing. Possible parameters are + src - full URL to the file that should be edited/viewed; + it can contain "private:factory/..." URLs to open new documents + for edit, for example "private:factory/swriter" + readonly - if it is set to "true" the document will be opened readonly, + otherwise the document will be opened for editing. + +The control can be extended easily, for example it can be changed +to allow scripting to load different documents. + +As any ActiveX control this one should be registered. +To let MSIE register it itself the "CODEBASE" parameter +for the "OBJECT" tag should be specified +with a URL to the library "so_activex.dll". + +Also it can be done using regsvr32 application. +To do it please write +<Path to Windows installation>\System32\regsvr32 so_activex.dll + +To unregister the control please use /u option: +<Path to Windows installation>\system32\regsvr32 so_activex.dll /u + + diff --git a/odk/examples/OLE/activex/SOActiveX.cpp b/odk/examples/OLE/activex/SOActiveX.cpp new file mode 100644 index 000000000..f98e2ddb1 --- /dev/null +++ b/odk/examples/OLE/activex/SOActiveX.cpp @@ -0,0 +1,645 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// SOActiveX.cpp : Implementation of CSOActiveX + +#include "stdafx2.h" +#include "so_activex.h" +#include "SOActiveX.h" +#include "SOComWindowPeer.h" + +#define STAROFFICE_WINDOWCLASS "SOParentWindow" + +#define BARS_NUMBER 3 +#define BARS_TO_SHOW 2 + +OLECHAR* pSlotUrl[BARS_NUMBER] = + {L"slot:5910" // SID_TOGGLEFUNCTIONBAR + ,L"slot:5920" // SID_TOGGLESTATUSBAR + ,L"slot:6661" // SID_TOGGLE_MENUBAR + }; + +OLECHAR* pSlotName[BARS_NUMBER] = + {L"FunctionBarVisible" // SID_TOGGLEFUNCTIONBAR + ,L"StatusBarVisible" // SID_TOGGLESTATUSBAR + ,L"MenuBarVisible" // SID_TOGGLE_MENUBAR + }; + + + + + +HRESULT ExecuteFunc( IDispatch* idispUnoObject, + OLECHAR* sFuncName, + CComVariant* params, + unsigned int count, + CComVariant* pResult ) +{ + if( !idispUnoObject ) + return E_FAIL; + + DISPID id; + HRESULT hr = idispUnoObject->GetIDsOfNames( IID_NULL, &sFuncName, 1, LOCALE_USER_DEFAULT, &id); + if( !SUCCEEDED( hr ) ) return hr; + + DISPPARAMS dispparams= { params, 0, count, 0}; + + // DEBUG + EXCEPINFO myInfo; + return idispUnoObject->Invoke( id, IID_NULL,LOCALE_USER_DEFAULT, DISPATCH_METHOD, + &dispparams, pResult, &myInfo, 0); +} + +HRESULT GetIDispByFunc( IDispatch* idispUnoObject, + OLECHAR* sFuncName, + CComVariant* params, + unsigned int count, + CComPtr<IDispatch>& pdispResult ) +{ + if( !idispUnoObject ) + return E_FAIL; + + CComVariant result; + HRESULT hr = ExecuteFunc( idispUnoObject, sFuncName, params, count, &result ); + if( !SUCCEEDED( hr ) ) return hr; + + if( result.vt != VT_DISPATCH || result.pdispVal == NULL ) + return hr; + + pdispResult = CComPtr<IDispatch>( result.pdispVal ); + + return S_OK; +} + +HRESULT PutPropertiesToIDisp( IDispatch* pdispObject, + OLECHAR** sMemberNames, + CComVariant* pVariant, + unsigned int count ) +{ + for( unsigned int ind = 0; ind < count; ind++ ) + { + DISPID id; + HRESULT hr = pdispObject->GetIDsOfNames( IID_NULL, &sMemberNames[ind], 1, LOCALE_USER_DEFAULT, &id ); + if( !SUCCEEDED( hr ) ) return hr; + + hr = CComDispatchDriver::PutProperty( pdispObject, id, &pVariant[ind] ); + if( !SUCCEEDED( hr ) ) return hr; + } + + return S_OK; +} + + +// CSOActiveX + +CSOActiveX::CSOActiveX() +: mCookie(0) +, mCurFileUrl( L"private:factory/swriter" ) +, mbLoad( FALSE ) +, mParentWin( NULL ) +, mOffWin( NULL ) +, mbViewOnly( FALSE ) +{ + CLSID clsFactory = {0x82154420,0x0FBF,0x11d4,{0x83, 0x13,0x00,0x50,0x04,0x52,0x6A,0xB4}}; + HRESULT hr = CoCreateInstance( clsFactory, NULL, CLSCTX_ALL, __uuidof(IDispatch), (void**)&mpDispFactory); + + mPWinClass.style = CS_HREDRAW|CS_VREDRAW; + mPWinClass.lpfnWndProc = ::DefWindowProc; + mPWinClass.cbClsExtra = 0; + mPWinClass.cbWndExtra = 0; + mPWinClass.hInstance = (HINSTANCE) GetModuleHandle(NULL); //myInstance; + mPWinClass.hIcon = NULL; + mPWinClass.hCursor = NULL; + mPWinClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND; + mPWinClass.lpszMenuName = NULL; + mPWinClass.lpszClassName = STAROFFICE_WINDOWCLASS; + + RegisterClass(&mPWinClass); +} + +CSOActiveX::~CSOActiveX() +{ + Cleanup(); + +} + +HRESULT CSOActiveX::Cleanup() +{ + if( mpDispFrame && mbViewOnly ) + { + ShowSomeBars(); + mbViewOnly = FALSE; + } + + if( mpDispFrame ) + { + // mpDispFrame->dispose(); + CComVariant dummyResult; + ExecuteFunc( mpDispFrame, L"dispose", NULL, 0, &dummyResult ); + mpDispFrame = CComPtr< IDispatch >(); + } + + if( ::IsWindow( mOffWin ) ) + ::DestroyWindow( mOffWin ); + + return S_OK; +} + + +STDMETHODIMP CSOActiveX::InitNew () +{ + mbLoad = TRUE; + return S_OK; +} + +STDMETHODIMP CSOActiveX::Load ( LPSTREAM pStm ) +{ + mbLoad = TRUE; + + // may be later? + // for now just ignore + + return S_OK; +} + +STDMETHODIMP CSOActiveX::Load( LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog ) +{ + IPropertyBag2* pPropBag2; + HRESULT hr = pPropBag->QueryInterface( IID_IPropertyBag2, (void**)&pPropBag2 ); + ATLASSERT( hr >= 0 ); + + if( !SUCCEEDED( hr ) ) + return hr; + + unsigned long aNum; + hr = pPropBag2->CountProperties( &aNum ); + ATLASSERT( hr >= 0 ); + if( !SUCCEEDED( hr ) ) + return hr; + + PROPBAG2* aPropNames = new PROPBAG2[aNum]; + unsigned long aReaded; + + hr = pPropBag2->GetPropertyInfo( 0, + aNum, + aPropNames, + &aReaded ); + ATLASSERT( hr >= 0 ); + if( !SUCCEEDED( hr ) ) + { + delete[] aPropNames; + return hr; + } + + CComVariant* aVal = new CComVariant[aNum]; + HRESULT* hvs = new HRESULT[aNum]; + hr = pPropBag2->Read( aNum, + aPropNames, + NULL, + aVal, + hvs ); + ATLASSERT( hr >= 0 ); + if( !SUCCEEDED( hr ) ) + { + delete[] hvs; + delete[] aVal; + delete[] aPropNames; + return hr; + } + + USES_CONVERSION; + for( unsigned long ind = 0; ind < aNum; ind++ ) + { + // all information from the 'object' tag is in strings + if( aVal[ind].vt == VT_BSTR && !strcmp( OLE2T( aPropNames[ind].pstrName ), "src" ) ) + { + mCurFileUrl = wcsdup( aVal[ind].bstrVal ); + } + else if( aVal[ind].vt == VT_BSTR + && !strcmp( OLE2T( aPropNames[ind].pstrName ), "readonly" ) ) + { + if( !strcmp( OLE2T( aVal[ind].bstrVal ), "true" ) ) + { + mbViewOnly = TRUE; + } + else + { + // the default value + mbViewOnly = FALSE; + } + } + } + + delete[] hvs; + delete[] aVal; + delete[] aPropNames; + + if( !mpDispFactory ) + return hr; + + mbLoad = TRUE; + + Invalidate(); + UpdateWindow(); + + return hr; +} + +HRESULT CSOActiveX::GetUnoStruct( OLECHAR* sStructName, CComPtr<IDispatch>& pdispResult ) +{ + return GetIDispByFunc( mpDispFactory, L"Bridge_GetStruct", &CComVariant( sStructName ), 1, pdispResult ); +} + +HRESULT CSOActiveX::GetUrlStruct( OLECHAR* sUrl, CComPtr<IDispatch>& pdispUrl ) +{ + HRESULT hr = GetUnoStruct( L"com.sun.star.util.URL", pdispUrl ); + if( !SUCCEEDED( hr ) ) return hr; + + OLECHAR* sURLMemberName = L"Complete"; + DISPID nURLID; + hr = pdispUrl->GetIDsOfNames( IID_NULL, &sURLMemberName, 1, LOCALE_USER_DEFAULT, &nURLID ); + if( !SUCCEEDED( hr ) ) return hr; + hr = CComDispatchDriver::PutProperty( pdispUrl, nURLID, &CComVariant( sUrl ) ); + if( !SUCCEEDED( hr ) ) return hr; + + CComPtr<IDispatch> pdispTransformer; + hr = GetIDispByFunc( mpDispFactory, + L"createInstance", + &CComVariant( L"com.sun.star.util.URLTransformer" ), + 1, + pdispTransformer ); + if( !SUCCEEDED( hr ) ) return hr; + + CComVariant dummyResult; + CComVariant aInOutParam; + aInOutParam.ppdispVal = &pdispUrl; + aInOutParam.vt = VT_DISPATCH | VT_BYREF; + hr = ExecuteFunc( pdispTransformer, L"parseStrict", &aInOutParam, 1, &dummyResult ); + if( !SUCCEEDED( hr ) || dummyResult.vt != VT_BOOL || !dummyResult.boolVal ) return hr; + + return S_OK; +} + + +HRESULT CSOActiveX::CreateFrameOldWay( HWND hwnd, int width, int height ) +{ + if( !mpDispFactory ) + return E_FAIL; + + // create window handle holder + CComPtr< CComObject< SOComWindowPeer > > pPeerToSend = new CComObject<SOComWindowPeer>( hwnd ); + pPeerToSend->SetHWNDInternally( hwnd ); + CComQIPtr< IDispatch, &IID_IDispatch > pIDispToSend( pPeerToSend ); + + // create rectangle structure + CComPtr<IDispatch> pdispRectangle; + HRESULT hr = GetUnoStruct( L"com.sun.star.awt.Rectangle", pdispRectangle ); + if( !SUCCEEDED( hr ) ) return hr; + + OLECHAR* sRectMemberNames[4] = { L"X", + L"Y", + L"Width", + L"Height" }; + CComVariant pRectVariant[4]; + pRectVariant[0] = pRectVariant[1] = pRectVariant[2] = pRectVariant[3] = CComVariant( 0 ); + + hr = PutPropertiesToIDisp( pdispRectangle, sRectMemberNames, pRectVariant, 4 ); + if( !SUCCEEDED( hr ) ) return hr; + + // create WindowDescriptor structure + CComPtr<IDispatch> pdispWinDescr; + hr = GetUnoStruct( L"com.sun.star.awt.WindowDescriptor", pdispWinDescr ); + if( !SUCCEEDED( hr ) ) return hr; + + // fill in descriptor with info + OLECHAR* sDescriptorMemberNames[6] = { L"Type", + L"WindowServiceName", + L"ParentIndex", + L"Parent", + L"Bounds", + L"WindowAttributes" }; + CComVariant pDescriptorVar[6]; + pDescriptorVar[0] = CComVariant( 0 ); + pDescriptorVar[1] = CComVariant( L"workwindow" ); + pDescriptorVar[2] = CComVariant( 1 ); + pDescriptorVar[3] = CComVariant( pIDispToSend ); + pDescriptorVar[4] = CComVariant( pdispRectangle ); + pDescriptorVar[5] = CComVariant( 33 ); + hr = PutPropertiesToIDisp( pdispWinDescr, sDescriptorMemberNames, pDescriptorVar, 6 ); + if( !SUCCEEDED( hr ) ) return hr; + + // create XToolkit instance + CComPtr<IDispatch> pdispToolkit; + hr = GetIDispByFunc( mpDispFactory, L"createInstance", &CComVariant( L"com.sun.star.awt.Toolkit" ), 1, pdispToolkit ); + if( !SUCCEEDED( hr ) ) return hr; + + // create window with toolkit + hr = GetIDispByFunc( pdispToolkit, L"createWindow", &CComVariant( pdispWinDescr ), 1, mpDispWin ); + if( !SUCCEEDED( hr ) ) return hr; + + // create frame + hr = GetIDispByFunc( mpDispFactory, L"createInstance", &CComVariant( L"com.sun.star.frame.Task" ), 1, mpDispFrame ); + if( !SUCCEEDED( hr ) || !mpDispFrame ) + { + // the interface com.sun.star.frame.Task is removed in 6.1 + // but the interface com.sun.star.frame.Frame has some bugs in 6.0 + hr = GetIDispByFunc( mpDispFactory, L"createInstance", &CComVariant( L"com.sun.star.frame.Frame" ), 1, mpDispFrame ); + if( !SUCCEEDED( hr ) ) return hr; + } + + // initialize frame + CComVariant dummyResult; + hr = ExecuteFunc( mpDispFrame, L"initialize", &CComVariant( mpDispWin ), 1, &dummyResult ); + if( !SUCCEEDED( hr ) ) return hr; + + // create desktop + CComPtr<IDispatch> pdispDesktop; + hr = GetIDispByFunc( mpDispFactory, L"createInstance", &CComVariant( L"com.sun.star.frame.Desktop" ), 1, pdispDesktop ); + if( !SUCCEEDED( hr ) ) return hr; + + // create tree of frames + CComPtr<IDispatch> pdispChildren; + hr = GetIDispByFunc( pdispDesktop, L"getFrames", NULL, 0, pdispChildren ); + if( !SUCCEEDED( hr ) ) return hr; + + // insert new frame into desktop hierarchy + hr = ExecuteFunc( pdispChildren, L"append", &CComVariant( mpDispFrame ), 1, &dummyResult ); + if( !SUCCEEDED( hr ) ) return hr; + + // initialize window + hr = ExecuteFunc( mpDispWin, L"setBackground", &CComVariant( (long)0xFFFFFFFF ), 1, &dummyResult ); + if( !SUCCEEDED( hr ) ) return hr; + + hr = ExecuteFunc( mpDispWin, L"setVisible", &CComVariant( TRUE ), 1, &dummyResult ); + if( !SUCCEEDED( hr ) ) return hr; + + CComVariant aPosArgs[5]; + aPosArgs[4] = CComVariant( 0 ); + aPosArgs[3] = CComVariant( 0 ); + aPosArgs[2] = CComVariant( width ); + aPosArgs[1] = CComVariant( height ); + aPosArgs[0] = CComVariant( 12 ); + hr = ExecuteFunc( mpDispWin, L"setPosSize", aPosArgs, 5, &dummyResult ); + if( !SUCCEEDED( hr ) ) return hr; + + + return S_OK; +} + +HRESULT CSOActiveX::CallDispatch1PBool( OLECHAR* sUrl, OLECHAR* sArgName, BOOL sArgVal ) +{ + CComPtr<IDispatch> pdispURL; + HRESULT hr = GetUrlStruct( sUrl, pdispURL ); + if( !SUCCEEDED( hr ) ) return hr; + + CComPtr<IDispatch> pdispXDispatch; + CComVariant aArgs[3]; + aArgs[2] = CComVariant( pdispURL ); + aArgs[1] = CComVariant( L"" ); + aArgs[0] = CComVariant( (int)0 ); + hr = GetIDispByFunc( mpDispFrame, + L"queryDispatch", + aArgs, + 3, + pdispXDispatch ); + if( !SUCCEEDED( hr ) ) return hr; + + SAFEARRAY FAR* pPropVals = SafeArrayCreateVector( VT_DISPATCH, 0, 1 ); + long ix = 0; + CComPtr<IDispatch> pdispPropVal; + hr = GetUnoStruct( L"com.sun.star.beans.PropertyValue", pdispPropVal ); + if( !SUCCEEDED( hr ) ) return hr; + + OLECHAR* sPropMemberNames[2] = { L"Name", L"Value" }; + CComVariant pPropVar[2]; + pPropVar[0] = CComVariant( sArgName ); + pPropVar[1] = CComVariant(); pPropVar[1].vt = VT_BOOL; pPropVar[1].boolVal = sArgVal ? VARIANT_TRUE : VARIANT_FALSE ; + hr = PutPropertiesToIDisp( pdispPropVal, sPropMemberNames, pPropVar, 2 ); + if( !SUCCEEDED( hr ) ) return hr; + + SafeArrayPutElement( pPropVals, &ix, pdispPropVal ); + + CComVariant aDispArgs[2]; + aDispArgs[1] = CComVariant( pdispURL ); + // aDispArgs[0] = CComVariant( pPropVals ); such constructor is not defined ??! + aDispArgs[0] = CComVariant(); aDispArgs[0].vt = VT_ARRAY | VT_DISPATCH; aDispArgs[0].parray = pPropVals; + + CComVariant dummyResult; + hr = ExecuteFunc( pdispXDispatch, L"dispatch", aDispArgs, 2, &dummyResult ); + if( !SUCCEEDED( hr ) ) return hr; + + return S_OK; +} + +HRESULT CSOActiveX::ShowSomeBars() +{ + // show FunctionBar and StatusBar + for( int ind = 0; ind < BARS_TO_SHOW; ind ++ ) + { + HRESULT hr = CallDispatch1PBool( pSlotUrl[ind], pSlotName[ind], TRUE ); + if( !SUCCEEDED( hr ) ) return hr; + } + + return S_OK; +} + +HRESULT CSOActiveX::HideAllBars() +{ + for( int ind = 0; ind < BARS_NUMBER; ind ++ ) + { + HRESULT hr = CallDispatch1PBool( pSlotUrl[ind], pSlotName[ind], FALSE ); + if( !SUCCEEDED( hr ) ) return hr; + } + + return S_OK; +} + +HRESULT CSOActiveX::LoadURLToFrame( ) +{ + HRESULT hr = CallDispatch1PBool( mCurFileUrl, L"ReadOnly", mbViewOnly ); + if( !SUCCEEDED( hr ) ) return hr; + + if( mbViewOnly ) + HideAllBars(); + + return S_OK; +} + +HRESULT CSOActiveX::OnDrawAdvanced( ATL_DRAWINFO& di ) +{ + if( m_spInPlaceSite && mCurFileUrl ) + { + HWND hwnd; + HRESULT hr = m_spInPlaceSite->GetWindow( &hwnd ); + if( !SUCCEEDED( hr ) ) return hr; + + if( mParentWin != hwnd || !mOffWin ) + { + if( mpDispFrame ) + { + CComVariant dummyResult; + ExecuteFunc( mpDispFrame, L"dispose", NULL, 0, &dummyResult ); + mpDispFrame = CComPtr<IDispatch>(); + } + + mParentWin = hwnd; + mOffWin = CreateWindow( + STAROFFICE_WINDOWCLASS, + "OfficeContainer", + WS_CHILD | WS_CLIPCHILDREN | WS_BORDER, + di.prcBounds->left, + di.prcBounds->top, + di.prcBounds->right - di.prcBounds->left, + di.prcBounds->bottom - di.prcBounds->top, + mParentWin, + NULL, + NULL, + NULL ); + + ::ShowWindow( mOffWin, SW_SHOW ); + } + else + { + RECT aRect; + ::GetWindowRect( mOffWin, &aRect ); + + if( aRect.left != di.prcBounds->left || aRect.top != di.prcBounds->top + || aRect.right != di.prcBounds->right || aRect.bottom != di.prcBounds->bottom ) + { + // on this state the office window should exist already + ::SetWindowPos( mOffWin, + HWND_TOP, + di.prcBounds->left, + di.prcBounds->top, + di.prcBounds->right - di.prcBounds->left, + di.prcBounds->bottom - di.prcBounds->top, + SWP_NOZORDER ); + + CComVariant aPosArgs[5]; + aPosArgs[4] = CComVariant( 0 ); + aPosArgs[3] = CComVariant( 0 ); + aPosArgs[2] = CComVariant( int(di.prcBounds->right - di.prcBounds->left) ); + aPosArgs[1] = CComVariant( int(di.prcBounds->bottom - di.prcBounds->top) ); + aPosArgs[0] = CComVariant( 12 ); + CComVariant dummyResult; + hr = ExecuteFunc( mpDispWin, L"setPosSize", aPosArgs, 5, &dummyResult ); + if( !SUCCEEDED( hr ) ) return hr; + } + } + + if( ! mpDispFrame ) + { + hr = CreateFrameOldWay( mOffWin, + di.prcBounds->right - di.prcBounds->left, + di.prcBounds->bottom - di.prcBounds->top ); + if( !SUCCEEDED( hr ) ) return hr; + } + + if( mbLoad ) + { + hr = LoadURLToFrame(); + if( !SUCCEEDED( hr ) ) return hr; + mbLoad = FALSE; + } + } + + return S_OK; +} + + +STDMETHODIMP CSOActiveX::SetClientSite( IOleClientSite* aClientSite ) +{ + HRESULT hr = IOleObjectImpl<CSOActiveX>::SetClientSite( aClientSite ); + + if( !aClientSite ) + { + ATLASSERT( mWebBrowser2 ); + if( mWebBrowser2 ) + AtlUnadvise( mWebBrowser2, DIID_DWebBrowserEvents2, mCookie ); + return hr; + } + + CComPtr<IOleContainer> aContainer; + m_spClientSite->GetContainer( &aContainer ); + ATLASSERT( aContainer ); + + if( SUCCEEDED( hr ) && aContainer ) + { + CComQIPtr<IServiceProvider, &IID_IServiceProvider> aServiceProvider( aContainer ); + ATLASSERT( aServiceProvider ); + + if( aServiceProvider ) + { + aServiceProvider->QueryService( SID_SInternetExplorer, + IID_IWebBrowser, + (void**)&mWebBrowser2 ); + ATLASSERT( mWebBrowser2 ); + if( mWebBrowser2 ) + AtlAdvise( mWebBrowser2, GetUnknown(), DIID_DWebBrowserEvents2, &mCookie ); + } + } + + return hr; +} + +STDMETHODIMP CSOActiveX::Invoke(DISPID dispidMember, + REFIID riid, + LCID lcid, + WORD wFlags, + DISPPARAMS* pDispParams, + VARIANT* pvarResult, + EXCEPINFO* pExcepInfo, + UINT* puArgErr) +{ + if (riid != IID_NULL) + return DISP_E_UNKNOWNINTERFACE; + + if (!pDispParams) + return DISP_E_PARAMNOTOPTIONAL; + + if ( dispidMember == DISPID_ONQUIT ) + Cleanup(); + + IDispatchImpl<ISOActiveX, &IID_ISOActiveX, + &LIBID_SO_ACTIVEXLib>::Invoke( + dispidMember, riid, lcid, wFlags, pDispParams, + pvarResult, pExcepInfo, puArgErr); + + return S_OK; +} + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/OLE/activex/SOActiveX.h b/odk/examples/OLE/activex/SOActiveX.h new file mode 100644 index 000000000..2057e43f4 --- /dev/null +++ b/odk/examples/OLE/activex/SOActiveX.h @@ -0,0 +1,168 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// SOActiveX.h : Declaration of the CSOActiveX + +#ifndef INCLUDED_EXAMPLES_ACTIVEX_SOACTIVEX_H +#define INCLUDED_EXAMPLES_ACTIVEX_SOACTIVEX_H + +#include "resource.h" +#include <ExDispID.h> +#include <ExDisp.h> +#include <shlguid.h> +#include <atlctl.h> + +#include "so_activex.h" + + +// CSOActiveX +class ATL_NO_VTABLE CSOActiveX : + public CComObjectRootEx<CComSingleThreadModel>, + public IDispatchImpl<ISOActiveX, &IID_ISOActiveX, &LIBID_SO_ACTIVEXLib>, + public CComControl<CSOActiveX>, + public IPersistStreamInitImpl<CSOActiveX>, + public IOleControlImpl<CSOActiveX>, + public IOleObjectImpl<CSOActiveX>, + public IOleInPlaceActiveObjectImpl<CSOActiveX>, + public IViewObjectExImpl<CSOActiveX>, + public IOleInPlaceObjectWindowlessImpl<CSOActiveX>, +// public IConnectionPointContainerImpl<CSOActiveX>, + public CComCoClass<CSOActiveX, &CLSID_SOActiveX>, +// public CProxy_ItryPluginEvents< CSOActiveX >, + public IPersistPropertyBagImpl< CSOActiveX >, + public IProvideClassInfo2Impl< &CLSID_SOActiveX, + &DIID__ISOActiveXEvents, + &LIBID_SO_ACTIVEXLib >, + public IObjectSafetyImpl< CSOActiveX, + INTERFACESAFE_FOR_UNTRUSTED_DATA > +{ +protected: + CComPtr<IWebBrowser2> mWebBrowser2; + DWORD mCookie; + + CComPtr<IDispatch> mpDispFactory; + CComPtr<IDispatch> mpDispFrame; + CComPtr<IDispatch> mpDispWin; + OLECHAR* mCurFileUrl; + BOOL mbLoad; + BOOL mbViewOnly; + WNDCLASS mPWinClass; + HWND mParentWin; + HWND mOffWin; +public: + CSOActiveX(); + ~CSOActiveX(); + +DECLARE_REGISTRY_RESOURCEID(IDR_SOACTIVEX) + +DECLARE_PROTECT_FINAL_CONSTRUCT() + +BEGIN_COM_MAP(CSOActiveX) + COM_INTERFACE_ENTRY(ISOActiveX) + COM_INTERFACE_ENTRY(IDispatch) + COM_INTERFACE_ENTRY(IViewObjectEx) + COM_INTERFACE_ENTRY(IViewObject2) + COM_INTERFACE_ENTRY(IViewObject) + COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless) + COM_INTERFACE_ENTRY(IOleInPlaceObject) + COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless) + COM_INTERFACE_ENTRY(IOleInPlaceActiveObject) + COM_INTERFACE_ENTRY(IOleControl) + COM_INTERFACE_ENTRY(IOleObject) + COM_INTERFACE_ENTRY(IPersistStreamInit) + COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit) +// COM_INTERFACE_ENTRY(IConnectionPointContainer) + COM_INTERFACE_ENTRY(IProvideClassInfo) + COM_INTERFACE_ENTRY(IProvideClassInfo2) + COM_INTERFACE_ENTRY(IPersistPropertyBag) + COM_INTERFACE_ENTRY(IObjectSafety) +END_COM_MAP() + +BEGIN_PROP_MAP(CSOActiveX) + PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4) + PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4) + // Example entries + // PROP_ENTRY("Property Description", dispid, clsid) + // PROP_PAGE(CLSID_StockColorPage) +END_PROP_MAP() + +BEGIN_CONNECTION_POINT_MAP(CSOActiveX) +END_CONNECTION_POINT_MAP() + +BEGIN_MSG_MAP(CSOActiveX) + CHAIN_MSG_MAP(CComControl<CSOActiveX>) + DEFAULT_REFLECTION_HANDLER() +END_MSG_MAP() +// Handler prototypes: +// LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); +// LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); +// LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled); + + + +// IViewObjectEx + DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE) + +// ISOActiveX +public: + + STDMETHOD(SetClientSite)( IOleClientSite* aClientSite ); + STDMETHOD(Invoke)( DISPID dispidMember, + REFIID riid, + LCID lcid, + WORD wFlags, + DISPPARAMS* pDispParams, + VARIANT* pvarResult, + EXCEPINFO* pExcepInfo, + UINT* puArgErr); + STDMETHOD(Load) ( LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog ); + STDMETHOD(Load) ( LPSTREAM pStm ); + STDMETHOD(InitNew) (); + HRESULT OnDrawAdvanced(ATL_DRAWINFO& di); + HRESULT OnDraw(ATL_DRAWINFO& di) { return S_OK; } + + HRESULT CreateFrameOldWay( HWND hwnd, int width, int height ); + HRESULT GetUnoStruct( OLECHAR* sStructName, CComPtr<IDispatch>& pdispResult ); + HRESULT LoadURLToFrame(); + HRESULT ShowSomeBars(); + HRESULT HideAllBars(); + HRESULT CallDispatch1PBool( OLECHAR* sUrl, OLECHAR* sArgName, BOOL sArgVal ); + HRESULT GetUrlStruct( OLECHAR* sUrl, CComPtr<IDispatch>& pdispUrl ); + HRESULT Cleanup(); +}; + +#endif // INCLUDED_EXAMPLES_ACTIVEX_SOACTIVEX_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/OLE/activex/SOActiveX.rgs b/odk/examples/OLE/activex/SOActiveX.rgs new file mode 100644 index 000000000..d3814df3b --- /dev/null +++ b/odk/examples/OLE/activex/SOActiveX.rgs @@ -0,0 +1,33 @@ +HKCR +{ + so_activex.SOActiveX.1 = s 'SOActiveX Class' + { + CLSID = s '{67F2A879-82D5-4A6D-8CC5-FFB3C114B69D}' + } + so_activex.SOActiveX = s 'SOActiveX Class' + { + CLSID = s '{67F2A879-82D5-4A6D-8CC5-FFB3C114B69D}' + CurVer = s 'so_activex.SOActiveX.1' + } + NoRemove CLSID + { + ForceRemove {67F2A879-82D5-4A6D-8CC5-FFB3C114B69D} = s 'SOActiveX Class' + { + ProgID = s 'so_activex.SOActiveX.1' + VersionIndependentProgID = s 'so_activex.SOActiveX' + ForceRemove 'Programmable' + InprocServer32 = s '%MODULE%' + { + val ThreadingModel = s 'Apartment' + } + ForceRemove 'Control' + ForceRemove 'ToolboxBitmap32' = s '%MODULE%, 101' + 'MiscStatus' = s '0' + { + '1' = s '131473' + } + 'TypeLib' = s '{61FA3F13-8061-4796-B055-3697ED28CB38}' + 'Version' = s '1.0' + } + } +} diff --git a/odk/examples/OLE/activex/SOComWindowPeer.cpp b/odk/examples/OLE/activex/SOComWindowPeer.cpp new file mode 100644 index 000000000..0045014fe --- /dev/null +++ b/odk/examples/OLE/activex/SOComWindowPeer.cpp @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// SOComWindowPeer.cpp : Implementation of CHelpApp and DLL registration. + +#include "stdafx2.h" +#include "so_activex.h" +#include "SOComWindowPeer.h" +#include <sal/macros.h> + + + + +STDMETHODIMP SOComWindowPeer::InterfaceSupportsErrorInfo(REFIID riid) +{ + static const IID* arr[] = + { + &IID_ISOComWindowPeer, + }; + + for (int i=0;i<SAL_N_ELEMENTS(arr);i++) + { + if (InlineIsEqualGUID(*arr[i],riid)) + return S_OK; + } + return S_FALSE; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/OLE/activex/SOComWindowPeer.h b/odk/examples/OLE/activex/SOComWindowPeer.h new file mode 100644 index 000000000..cd5857159 --- /dev/null +++ b/odk/examples/OLE/activex/SOComWindowPeer.h @@ -0,0 +1,156 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// SOComWindowPeer.h: Definition of the SOComWindowPeer class + +#ifndef INCLUDED_EXAMPLES_ACTIVEX_SOCOMWINDOWPEER_H +#define INCLUDED_EXAMPLES_ACTIVEX_SOCOMWINDOWPEER_H + +#include "resource.h" +#include <ExDispID.h> +#include <ExDisp.h> +#include <shlguid.h> +#include <atlctl.h> + +#include "so_activex.h" + +class SOComWindowPeer : + public IDispatchImpl<ISOComWindowPeer, &IID_ISOComWindowPeer, &LIBID_SO_ACTIVEXLib>, + public ISupportErrorInfo, + public CComObjectRoot, + public CComCoClass<SOComWindowPeer,&CLSID_SOComWindowPeer> +{ + HWND m_hwnd; +public: + SOComWindowPeer() : m_hwnd( NULL ) {} + +BEGIN_COM_MAP(SOComWindowPeer) + COM_INTERFACE_ENTRY(IDispatch) + COM_INTERFACE_ENTRY(ISOComWindowPeer) + COM_INTERFACE_ENTRY(ISupportErrorInfo) +END_COM_MAP() +DECLARE_NOT_AGGREGATABLE(SOComWindowPeer) +// Remove the comment from the line above if you don't want your object to +// support aggregation. + +DECLARE_REGISTRY_RESOURCEID(IDR_SOCOMWINDOWPEER) + +// ISupportsErrorInfo + STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid); + +// ISOComWindowPeer + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE getWindowHandle( + /* [in] */ SAFEARRAY __RPC_FAR * procId, + /* [in] */ short s, + /* [retval][out] */ long __RPC_FAR *ret) + { + *ret = (long) m_hwnd; + return S_OK; + } + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE getToolkit( + /* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *retVal) + { + *retVal = NULL; + return S_OK; + } + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE setPointer( + /* [in] */ IDispatch __RPC_FAR *xPointer) + { + return S_OK; + } + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE setBackground( + /* [in] */ int nColor) + { + return S_OK; + } + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE invalidate( + /* [in] */ short __MIDL_0015) + { + return S_OK; + } + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE invalidateRect( + /* [in] */ IDispatch __RPC_FAR *aRect, + /* [in] */ short nFlags) + { + return S_OK; + } + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE dispose( void) + { + return S_OK; + } + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE addEventListener( + /* [in] */ IDispatch __RPC_FAR *xListener) + { + return S_OK; + } + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE removeEventListener( + /* [in] */ IDispatch __RPC_FAR *xListener) + { + return S_OK; + } + + virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_Bridge_implementedInterfaces( + /* [retval][out] */ SAFEARRAY __RPC_FAR * __RPC_FAR *pVal) + { + *pVal = SafeArrayCreateVector( VT_BSTR, 0, 2 ); + + if( !*pVal ) + return E_FAIL; + + long ix = 0; + CComBSTR aInterface( OLESTR( "com.sun.star.awt.XSystemDependentWindowPeer" ) ); + SafeArrayPutElement( *pVal, &ix, aInterface ); + + ix = 1; + aInterface = CComBSTR( OLESTR( "com.sun.star.awt.XWindowPeer" ) ); + SafeArrayPutElement( *pVal, &ix, aInterface ); + + return S_OK; + } + + void SetHWNDInternally( HWND hwnd ) { m_hwnd = hwnd; } +}; + +#endif // INCLUDED_EXAMPLES_ACTIVEX_SOCOMWINDOWPEER_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/OLE/activex/SOComWindowPeer.rgs b/odk/examples/OLE/activex/SOComWindowPeer.rgs new file mode 100644 index 000000000..42e985a31 --- /dev/null +++ b/odk/examples/OLE/activex/SOComWindowPeer.rgs @@ -0,0 +1,23 @@ +HKCR +{ + so_activex.SOComWindowPeer.1 = s 'SOComWindowPeer Class' + { + CLSID = s '{EE51BD3E-8BB6-4FB8-B319-F65B1BE3B21D}' + } + so_activex.SOComWindowPeer = s 'SOComWindowPeer Class' + { + CLSID = s '{EE51BD3E-8BB6-4FB8-B319-F65B1BE3B21D}' + } + NoRemove CLSID + { + ForceRemove {EE51BD3E-8BB6-4FB8-B319-F65B1BE3B21D} = s 'SOComWindowPeer Class' + { + ProgID = s 'so_activex.SOComWindowPeer.1' + VersionIndependentProgID = s 'so_activex.SOComWindowPeer' + InprocServer32 = s '%MODULE%' + { + val ThreadingModel = s 'both' + } + } + } +} diff --git a/odk/examples/OLE/activex/StdAfx2.cpp b/odk/examples/OLE/activex/StdAfx2.cpp new file mode 100644 index 000000000..3911bcf24 --- /dev/null +++ b/odk/examples/OLE/activex/StdAfx2.cpp @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// stdafx1.cpp : source file that includes just the standard includes +// stdafx1.pch will be the pre-compiled header +// stdafx1.obj will contain the pre-compiled type information + +#include "stdafx2.h" + +#ifdef _ATL_STATIC_REGISTRY +#include <statreg.h> +#include <statreg.cpp> +#endif + +#include <atlimpl.cpp> + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/OLE/activex/StdAfx2.h b/odk/examples/OLE/activex/StdAfx2.h new file mode 100644 index 000000000..df14ccf94 --- /dev/null +++ b/odk/examples/OLE/activex/StdAfx2.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// stdafx1.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#ifndef INCLUDED_EXAMPLES_ACTIVEX_STDAFX2_H +#define INCLUDED_EXAMPLES_ACTIVEX_STDAFX2_H + +#define STRICT +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0502 +#endif +#define _ATL_APARTMENT_THREADED +#define _ATL_STATIC_REGISTRY + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +#include <atlbase.h> +//You may derive a class from CComModule and use it if you want to override +//something, but do not change the name of _Module +extern CComModule _Module; +#include <atlcom.h> +#include <atlctl.h> + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // INCLUDED_EXAMPLES_ACTIVEX_STDAFX2_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/OLE/activex/example.html b/odk/examples/OLE/activex/example.html new file mode 100644 index 000000000..f9843f0dd --- /dev/null +++ b/odk/examples/OLE/activex/example.html @@ -0,0 +1,44 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<HTML> +<HEAD> +<TITLE>Document Title</TITLE> +</HEAD> +<BODY> + +<center> +First you should edit the example.html file!!! +</center> +<center> +<!-- Please edit CODEBASE parameter --> +<!-- In case ActiveX control is already registered the parameter can be removed --> +<OBJECT CLASSID="clsid:67F2A879-82D5-4A6D-8CC5-FFB3C114B69D" width="500" height="500" + CODEBASE="<path_to_the_sdk_sample_output_dir>\bin\so_activex.dll"> +<!-- Full URL to a document + <PARAM NAME="src" VALUE="file:///d:/tmp/test.odt"> +--> +<!-- Just view the document, do not edit + <PARAM NAME="readonly" VALUE="true"> +--> +</OBJECT> + +</center> + +</BODY> +</HTML> diff --git a/odk/examples/OLE/activex/resource.h b/odk/examples/OLE/activex/resource.h new file mode 100644 index 000000000..88480036f --- /dev/null +++ b/odk/examples/OLE/activex/resource.h @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by so_activex.rc + +#define IDS_PROJNAME 100 +#define IDB_SOACTIVEX 101 +#define IDR_SOACTIVEX 102 +#define IDB_SOCOMWINDOWPEER 103 +#define IDR_SOCOMWINDOWPEER 104 + +// Next default values for new objects + +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 201 +#define _APS_NEXT_COMMAND_VALUE 32768 +#define _APS_NEXT_CONTROL_VALUE 201 +#define _APS_NEXT_SYMED_VALUE 105 +#endif +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/OLE/activex/so_activex.cpp b/odk/examples/OLE/activex/so_activex.cpp new file mode 100644 index 000000000..e546aeff5 --- /dev/null +++ b/odk/examples/OLE/activex/so_activex.cpp @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// so_activex.cpp : Implementation of DLL Exports. + + +// Note: Proxy/Stub Information +// To build a separate proxy/stub DLL, +// run nmake -f so_activexps.mk in the project directory. + +#include "stdafx2.h" +#include "resource.h" +#include <initguid.h> +#include "so_activex.h" + +#include "so_activex_i.c" +#include "SOActiveX.h" + + +CComModule _Module; + +BEGIN_OBJECT_MAP(ObjectMap) +OBJECT_ENTRY(CLSID_SOActiveX, CSOActiveX) +END_OBJECT_MAP() + + +// DLL Entry Point + +extern "C" +BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +{ + if (dwReason == DLL_PROCESS_ATTACH) + { + _Module.Init(ObjectMap, hInstance, &LIBID_SO_ACTIVEXLib); + DisableThreadLibraryCalls(hInstance); + } + else if (dwReason == DLL_PROCESS_DETACH) + _Module.Term(); + return TRUE; // ok +} + + +// Used to determine whether the DLL can be unloaded by OLE + +STDAPI DllCanUnloadNow(void) +{ + return (_Module.GetLockCount()==0) ? S_OK : S_FALSE; +} + + +// Returns a class factory to create an object of the requested type + +STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) +{ + return _Module.GetClassObject(rclsid, riid, ppv); +} + + +// DllRegisterServer - Adds entries to the system registry + +STDAPI DllRegisterServer(void) +{ + HRESULT aResult = _Module.RegisterServer(TRUE); + + return aResult; +} + + +// DllUnregisterServer - Removes entries from the system registry + +STDAPI DllUnregisterServer(void) +{ + HRESULT aResult = _Module.UnregisterServer(TRUE); + + return aResult; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/OLE/activex/so_activex.def b/odk/examples/OLE/activex/so_activex.def new file mode 100644 index 000000000..68939efa1 --- /dev/null +++ b/odk/examples/OLE/activex/so_activex.def @@ -0,0 +1,5 @@ +EXPORTS
+ DllCanUnloadNow PRIVATE
+ DllGetClassObject PRIVATE
+ DllRegisterServer PRIVATE
+ DllUnregisterServer PRIVATE
diff --git a/odk/examples/OLE/activex/so_activex.idl b/odk/examples/OLE/activex/so_activex.idl new file mode 100644 index 000000000..6013b7e55 --- /dev/null +++ b/odk/examples/OLE/activex/so_activex.idl @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// so_activex.idl : IDL source for so_activex.dll + + +// This file will be processed by the MIDL tool to +// produce the type library (so_activex.tlb) and marshalling code. + +import "oaidl.idl"; +import "ocidl.idl"; +#include <olectl.h> + + + [ + object, + uuid(DACF7E3F-626B-4BF9-964B-F4910C843711), + dual, + helpstring("ISOActiveX Interface"), + pointer_default(unique) + ] + interface ISOActiveX : IDispatch + { + }; + +[ + object, + uuid(BF5D10F3-8A10-4A0B-B150-2B6AA2D7E118), + dual, + helpstring("ISOComWindowPeer Interface"), + pointer_default(unique) +] +interface ISOComWindowPeer : IDispatch +{ + [id(1), helpstring("method getWindowHandle")] + HRESULT getWindowHandle( [in] SAFEARRAY(VARIANT) procId, + [in] short s, + [out,retval] long* ret); + + [id(2), helpstring("method getToolkit")] + HRESULT getToolkit( [out,retval] IDispatch** retVal ); + + [id(3), helpstring("method setPointer")] + HRESULT setPointer( [in] IDispatch* xPointer ); + + [id(4), helpstring("method setBackground")] + HRESULT setBackground( [in] int nColor ); + + [id(5), helpstring("method invalidate")] + HRESULT invalidate( [in] short ); + + [id(6), helpstring("method invalidateRect")] + HRESULT invalidateRect( [in] IDispatch* aRect, [in] short nFlags ); + + [id(7), helpstring("method dispose")] + HRESULT dispose(); + + [id(8), helpstring("method addEventListener")] + HRESULT addEventListener( [in] IDispatch* xListener ); + + [id(9), helpstring("method removeEventListener")] + HRESULT removeEventListener( [in] IDispatch* xListener ); + + [propget, id(10), helpstring("property_implementedInterfaces")] + HRESULT Bridge_implementedInterfaces([out, retval] SAFEARRAY(BSTR) *pVal); +}; + +[ + uuid(61FA3F13-8061-4796-B055-3697ED28CB38), + version(1.0), + helpstring("so_activex 1.0 Type Library") +] +library SO_ACTIVEXLib +{ + importlib("stdole32.tlb"); + importlib("stdole2.tlb"); + + [ + uuid(7F760565-5719-4F04-BA86-112C474B10EA), + helpstring("_ISOActiveXEvents Interface") + ] + dispinterface _ISOActiveXEvents + { + properties: + methods: + }; + + [ + uuid(67F2A879-82D5-4A6D-8CC5-FFB3C114B69D), + helpstring("SOActiveX Class") + ] + coclass SOActiveX + { + [default] interface ISOActiveX; + [default, source] dispinterface _ISOActiveXEvents; + }; + + [ + uuid(EE51BD3E-8BB6-4FB8-B319-F65B1BE3B21D), + helpstring("SOComWindowPeer Class") + ] + coclass SOComWindowPeer + { + [default] interface ISOComWindowPeer; + }; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/OLE/activex/so_activex.rc b/odk/examples/OLE/activex/so_activex.rc new file mode 100644 index 000000000..1141e1044 --- /dev/null +++ b/odk/examples/OLE/activex/so_activex.rc @@ -0,0 +1,136 @@ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +//Microsoft Developer Studio generated resource script. + +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + + +// Generated from the TEXTINCLUDE 2 resource. + +#include "winres.h" + + +#undef APSTUDIO_READONLY_SYMBOLS + + +// Russian resources + +//#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) +//#ifdef _WIN32 +//LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT +//#pragma code_page(1251) +//#endif //_WIN32 + + + +// Bitmap + + +//IDB_SOACTIVEX BITMAP DISCARDABLE "soacti.bmp" + + + + +// REGISTRY + + +IDR_SOACTIVEX REGISTRY DISCARDABLE "SOActiveX.rgs" +IDR_SOCOMWINDOWPEER REGISTRY DISCARDABLE "SOComWindowPeer.rgs" +//#endif // Russian resources + + + + +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED + + +// TEXTINCLUDE + + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "1 TYPELIB ""so_activex.tlb""\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + + +// String Table + + +STRINGTABLE DISCARDABLE +BEGIN + IDS_PROJNAME "so_activex" +END + +#endif // English (U.S.) resources + + + + +#ifndef APSTUDIO_INVOKED + + +// Generated from the TEXTINCLUDE 3 resource. + + +1 TYPELIB .\..\..\..\WINexample.out\misc\so_activex\so_activex.tlb + + +#endif // not APSTUDIO_INVOKED + diff --git a/odk/examples/OLE/delphi/InsertTables/Project1.dpr b/odk/examples/OLE/delphi/InsertTables/Project1.dpr new file mode 100644 index 000000000..9f2bd2fd5 --- /dev/null +++ b/odk/examples/OLE/delphi/InsertTables/Project1.dpr @@ -0,0 +1,14 @@ +program Project1; + +uses + Forms, + SampleUI in 'SampleUI.pas' {OKBottomDlg}, + SampleCode in 'SampleCode.pas'; + +{$R *.RES} + +begin + Application.Initialize; + Application.CreateForm(TOKBottomDlg, OKBottomDlg); + Application.Run; +end. diff --git a/odk/examples/OLE/delphi/InsertTables/Project1.res b/odk/examples/OLE/delphi/InsertTables/Project1.res new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/odk/examples/OLE/delphi/InsertTables/Project1.res diff --git a/odk/examples/OLE/delphi/InsertTables/SampleCode.pas b/odk/examples/OLE/delphi/InsertTables/SampleCode.pas new file mode 100644 index 000000000..f314f7ea6 --- /dev/null +++ b/odk/examples/OLE/delphi/InsertTables/SampleCode.pas @@ -0,0 +1,393 @@ +{*********************************************************************** + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************} +unit SampleCode; + +interface + +uses + Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, + StdCtrls, ComObj, Variants; + + type + TSampleCode = class + + function Connect() : boolean; + procedure Disconnect(); + + function CreateDocument(bReadOnly : boolean) : boolean; + + procedure InsertTable(sTableName : String; dbPointer : String); + + procedure InsertDatabaseTable( + oDoc : Variant; + sTableName : String; + oCursor : Variant; + iRows : Integer; + iColumns : Integer; + dbPointer : String ); + function CreateTextTable( + oDoc : Variant; + oCursor : Variant; + sName : String; + iRow : Integer; + iColumn : Integer) : Variant; + function getCellContent( + sBookmarkName : String ) : Variant; + function getDatabasePointer( + sTableName : String; + sCellname : String ) : String; + procedure InsertBookmark( + oDoc : Variant; + oTextCursor : Variant; + sBookmarkName : String ); + function CreateBookmarkName( + sTableName : String; + sCellName : String; + sDatabasepointer : String ) : String; + procedure ChangeCellContent( + oDoc : Variant; + sTableName : String; + sCellName : String; + dValue : Double ); + function GetBookmarkFromDBPointer( + oDoc : Variant; + sBookmarkName : String) : Variant; + function GetBookmarkFromAdress( + oDoc : Variant; + sTableName : String; + sCellAdress : String) : Variant; + function JumpToBookmark( + oBookmark : Variant) : Variant; + function CreateUniqueTablename(oDoc : Variant) : String; + + private + StarOffice : Variant; + Document : Variant; + + { Private-Deklarationen } + public + { Public-Deklarationen } + end; + +implementation + +{ Insert a table texttable and insert in each cell a Bookmark with the address + of the cell and database pointer +} + +function TSampleCode.Connect() : boolean; +begin + if VarIsEmpty(StarOffice) then + StarOffice := CreateOleObject('com.sun.star.ServiceManager'); + + Connect := not (VarIsEmpty(StarOffice) or VarIsNull(StarOffice)); +end; + +procedure TSampleCode.Disconnect(); +begin + StarOffice := Unassigned; +end; + +function TSampleCode.CreateDocument(bReadOnly : boolean) : boolean; +var + StarDesktop : Variant; + LoadParams : Variant; + CoreReflection : Variant; + PropertyValue : Variant; +begin + StarDesktop := StarOffice.createInstance('com.sun.star.frame.Desktop'); + + if (bReadOnly) then begin + LoadParams := VarArrayCreate([0, 0], varVariant); + CoreReflection := StarOffice.createInstance('com.sun.star.reflection.CoreReflection'); + + CoreReflection + .forName('com.sun.star.beans.PropertyValue') + .createObject(PropertyValue); + + PropertyValue.Name := 'ReadOnly'; + PropertyValue.Value := true; + + LoadParams[0] := PropertyValue; + end + else + LoadParams := VarArrayCreate([0, -1], varVariant); + + Document := StarDesktop.LoadComponentFromURL( 'private:factory/swriter', '_blank', 0, LoadParams); + + CreateDocument := not (VarIsEmpty(Document) or VarIsNull(Document)); +end; + + +function TSampleCode.getCellContent( + sBookmarkName : String ) : Variant; +var + oBookmark : Variant; + oTextCursor : Variant; +begin + oBookmark := GetBookmarkFromDBPointer( Document, sBookmarkName ); + oTextCursor := JumpToBookmark( oBookmark ); + + getCellContent := oTextCursor.Cell.Value; + +end; + + +function TSampleCode.getDatabasePointer( + sTableName : String; + sCellname : String ) : String; +var + oBookmark : Variant; + sBookmarkName : String; + iPos : Integer; +begin + oBookmark := GetBookmarkFromAdress( Document, sTableName, sCellName ); + + sBookmarkName := oBookmark.getName(); + + iPos := Pos('/%', sBookmarkName); + while Pos('/%', sBookmarkName) > 0 do + begin + iPos := Pos('/%', sBookmarkName); + sBookmarkName[iPos] := '%'; + end; + + Delete( sBookmarkName, 1, iPos+1); + getDatabasePointer := sBookmarkName; +end; + + +procedure TSampleCode.InsertTable(sTableName : String; dbPointer : String); +var + oCursor : Variant; +begin + { create a cursor object on the current position in the document } + oCursor := Document.Text.CreateTextCursor(); + + { Create for each table a unique database name } + if (sTableName = '') then + sTableName := createUniqueTablename(Document); + + InsertDatabaseTable( Document, sTableName, oCursor, 4, 2, dbPointer ); + + ChangeCellContent( Document, sTableName, 'B2', 1.12 ); +end; + +procedure TSampleCode.InsertDatabaseTable( + oDoc : Variant; + sTableName : String; + oCursor : Variant; + iRows : Integer; + iColumns : Integer; + dbPointer : String); +var + oTable : Variant; + sCellnames : Variant; + iCellcounter : Integer; + oCellCursor : Variant; + oTextCursor : Variant; + sCellName : String; +begin + oTable := CreateTextTable( oDoc, oCursor, sTableName, iRows, iColumns ); + sCellnames := oTable.getCellNames(); + + For iCellcounter := VarArrayLowBound( sCellnames, 1) to VarArrayHighBound(sCellnames, 1) do + begin + sCellName := sCellnames[iCellcounter]; + + oCellCursor := oTable.getCellByName(sCellName); + oCellCursor.Value := iCellcounter; + oTextCursor := oCellCursor.getEnd(); + InsertBookmark( + oDoc, + oTextCursor, + createBookmarkName(sTableName, sCellName, dbPointer)); + end; +end; + +{ + +' Change the content of a cell +} + +procedure TSampleCode.ChangeCellContent( + oDoc : Variant; + sTableName : String; + sCellName : String; + dValue : Double ); +var + oBookmark : Variant; + oTextCursor : Variant; + sBookmarkName : String; +begin + oBookmark := GetBookmarkFromAdress( oDoc, sTableName, sCellName ); + oTextCursor := JumpToBookmark( oBookmark ); + oTextCursor.Cell.Value := dValue; + + { create a new bookmark for the new number } + sBookmarkName := oBookmark.getName(); + oBookmark.dispose(); + InsertBookmark( oDoc, oTextCursor, sBookmarkName ); +end; + + +{ ' Jump to Bookmark and return for this position the cursor } + +function TSampleCode.JumpToBookmark( + oBookmark : Variant) : Variant; + +begin + JumpToBookmark := oBookmark.Anchor.Text.createTextCursorByRange( + oBookmark.Anchor ); +end; + + +{ ' Create a Texttable on a Textdocument } +function TSampleCode.CreateTextTable( + oDoc : Variant; + oCursor : Variant; + sName : String; + iRow : Integer; + iColumn : Integer) : Variant; +var + ret : Variant; +begin + ret := oDoc.createInstance( 'com.sun.star.text.TextTable' ); + + ret.setName( sName ); + ret.initialize( iRow, iColumn ); + oDoc.Text.InsertTextContent( oCursor, ret, False ); + + CreateTextTable := ret; +end; + + +{ 'create a unique name for the Texttables } +function TSampleCode.CreateUniqueTablename(oDoc : Variant) : String; +var + iHighestNumber : Integer; + sTableNames : Variant; + iTableCounter : Integer; + sTableName : String; + iTableNumber : Integer; + i : Integer; +begin + sTableNames := oDoc.getTextTables.getElementNames(); + iHighestNumber := 0; + For iTableCounter := VarArrayLowBound(sTableNames, 1) to VarArrayHighBound(sTableNames, 1) do + begin + sTableName := sTableNames[iTableCounter]; + i := Pos( '$$', sTableName ); + iTableNumber := strtoint( Copy(sTableName, i + 2, Length( sTableName ) - i - 1 ) ); + + If iTableNumber > iHighestNumber then + iHighestNumber := iTableNumber; + end; + createUniqueTablename := 'DBTable$$' + inttostr(iHighestNumber + 1); +end; + + +{' Insert a Bookmark on the cursor } +procedure TSampleCode.InsertBookmark( + oDoc : Variant; + oTextCursor : Variant; + sBookmarkName : String); +var + oBookmarkInst : Variant; +begin + oBookmarkInst := oDoc.createInstance('com.sun.star.text.Bookmark'); + + oBookmarkInst.Name := sBookmarkName; + oTextCursor.gotoStart( true ); + oTextCursor.text.InsertTextContent( oTextCursor, oBookmarkInst, true ); +end; + + +function TSampleCode.CreateBookmarkName( + sTableName : String; + sCellName : String; + sDatabasepointer : String ) : String; +begin + createBookmarkName := '//' + sTableName + '/%' + sCellName + '/%' + sDatabasePointer + ':' + sCellName; +end; + +{ ' Returns the Bookmark the Tablename and Cellname } +function TSampleCode.GetBookmarkFromAdress( + oDoc : Variant; + sTableName : String; + sCellAdress : String) : Variant; +var + sTableAddress : String; + iTableNameLength : Integer; + sBookNames : Variant; + iBookCounter : Integer; +begin + sTableAddress := '//' + sTableName + '/%' + sCellAdress; + iTableNameLength := Length( sTableAddress ); + + sBookNames := oDoc.Bookmarks.getElementNames; + + for iBookCounter := VarArrayLowBound(sBookNames, 1) to VarArrayHighBound(sBookNames, 1) do + begin + If sTableAddress = Copy( sBookNames[iBookCounter], 1, iTableNameLength) then + begin + GetBookmarkFromAdress := oDoc.Bookmarks.getByName(sBookNames[iBookCounter]); + exit; + end; + end; +end; + +{ ' Returns the Bookmark the Tablename and Cellname } +function TSampleCode.GetBookmarkFromDBPointer( + oDoc : Variant; + sBookmarkName : String) : Variant; +var + sBookNames : Variant; + iBookCounter : Integer; +begin + sBookNames := oDoc.Bookmarks.getElementNames; + + for iBookCounter := VarArrayLowBound(sBookNames, 1) to VarArrayHighBound(sBookNames, 1) do + begin + If Pos(sBookmarkName, sBookNames[iBookCounter]) = (1 + Length(sBookNames[iBookCounter]) - Length(sBookmarkName)) then + begin + GetBookmarkFromDBPointer := oDoc.Bookmarks.getByName(sBookNames[iBookCounter]); + exit; + end; + end; +end; + +end. + + diff --git a/odk/examples/OLE/delphi/InsertTables/SampleUI.dfm b/odk/examples/OLE/delphi/InsertTables/SampleUI.dfm new file mode 100644 index 000000000..082fce7b7 --- /dev/null +++ b/odk/examples/OLE/delphi/InsertTables/SampleUI.dfm @@ -0,0 +1,4 @@ +ÿ +ParentFont OldCreateOrder PositionpoScreenCenter
PixelsPerInch` +TextHeight
Table NameTable namedisconnectEnabledTabOrderOnClickOnDisconnectTStatusBar +StatusBar1LeftSimpleTextReady
\ No newline at end of file diff --git a/odk/examples/OLE/delphi/InsertTables/SampleUI.pas b/odk/examples/OLE/delphi/InsertTables/SampleUI.pas new file mode 100644 index 000000000..fcd4f4301 --- /dev/null +++ b/odk/examples/OLE/delphi/InsertTables/SampleUI.pas @@ -0,0 +1,168 @@ +{*********************************************************************** + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************} +unit SampleUI; + +interface + +uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, + Buttons, ExtCtrls, SampleCode, ComCtrls; + +type + TOKBottomDlg = class(TForm) + Bevel1: TBevel; + Button1: TButton; + Button2: TButton; + Button3: TButton; + Button4: TButton; + Edit1: TEdit; + Label1: TLabel; + Edit2: TEdit; + Label2: TLabel; + Button5: TButton; + Button6: TButton; + Edit3: TEdit; + Label3: TLabel; + Label4: TLabel; + Label6: TLabel; + Edit6: TEdit; + Bevel2: TBevel; + Bevel3: TBevel; + Bevel4: TBevel; + StatusBar1: TStatusBar; + Edit4: TEdit; + Label7: TLabel; + procedure OnConnect(Sender: TObject); + procedure OnDisconnect(Sender: TObject); + procedure OnCreateDocument(Sender: TObject); + procedure OnInsertTable(Sender: TObject); + procedure OnGetDatabasePointer(Sender: TObject); + procedure OnGetCellContent(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + OKBottomDlg: TOKBottomDlg; + Sample : TSampleCode; +implementation + +{$R *.DFM} + +procedure TOKBottomDlg.OnConnect(Sender: TObject); +begin + StatusBar1.SimpleText := 'Connection to StarOffice ...'; + Sample := TSampleCode.Create(); + if Sample.Connect() then + begin + Button1.Enabled := false; + Button2.Enabled := true; + Button3.Enabled := true; + Button4.Enabled := false; + Button5.Enabled := false; + Button6.Enabled := false; + end; + StatusBar1.SimpleText := 'Ready'; +end; + +procedure TOKBottomDlg.OnDisconnect(Sender: TObject); +begin + StatusBar1.SimpleText := 'Disconnection from StarOffice ...'; + Sample.Disconnect(); + Button1.Enabled := true; + Button2.Enabled := false; + Button3.Enabled := false; + Button4.Enabled := false; + Button5.Enabled := false; + Button6.Enabled := false; + StatusBar1.SimpleText := 'Ready'; +end; + +procedure TOKBottomDlg.OnCreateDocument(Sender: TObject); +begin + StatusBar1.SimpleText := 'Creating new text document ...'; + try + if Sample.CreateDocument(false) then + begin + Button4.Enabled := true; + Button5.Enabled := true; + Button6.Enabled := true; + end; + StatusBar1.SimpleText := 'Ready'; + except + StatusBar1.SimpleText := 'Error'; + end; +end; + +procedure TOKBottomDlg.OnInsertTable(Sender: TObject); +begin + try + StatusBar1.SimpleText := 'Inserting Table ...'; + Sample.InsertTable(Edit2.Text, Edit1.Text); + StatusBar1.SimpleText := 'Ready'; + except + StatusBar1.SimpleText := 'Error'; + end; +end; + +procedure TOKBottomDlg.OnGetDatabasePointer(Sender: TObject); +var + res : String; +begin + try + StatusBar1.SimpleText := 'Getting database pointer ...'; + res := Sample.getDatabasePointer(Edit4.Text, Edit3.Text); + Application.MessageBox(PChar('the pointer: ' + res), PChar('Result'), ID_OK); + StatusBar1.SimpleText := 'Ready'; + except + StatusBar1.SimpleText := 'Error'; + end; +end; + +procedure TOKBottomDlg.OnGetCellContent(Sender: TObject); +var + res : String; +begin + try + StatusBar1.SimpleText := 'Getting cell content ...'; + res := Sample.getCellContent(Edit6.Text); + Application.MessageBox(PChar('the content: ' + res), PChar('Result'), ID_OK); + StatusBar1.SimpleText := 'Ready'; + except + StatusBar1.SimpleText := 'Error'; + end; +end; + +end. diff --git a/odk/examples/OLE/delphi/StarOffice_Delphi.sxw b/odk/examples/OLE/delphi/StarOffice_Delphi.sxw Binary files differnew file mode 100644 index 000000000..77ccc4b77 --- /dev/null +++ b/odk/examples/OLE/delphi/StarOffice_Delphi.sxw diff --git a/odk/examples/OLE/delphi/StarOffice_and_Delphi.pdf b/odk/examples/OLE/delphi/StarOffice_and_Delphi.pdf Binary files differnew file mode 100644 index 000000000..92eee437f --- /dev/null +++ b/odk/examples/OLE/delphi/StarOffice_and_Delphi.pdf diff --git a/odk/examples/OLE/vbscript/WriterDemo.vbs b/odk/examples/OLE/vbscript/WriterDemo.vbs new file mode 100644 index 000000000..71d011e4f --- /dev/null +++ b/odk/examples/OLE/vbscript/WriterDemo.vbs @@ -0,0 +1,172 @@ +'*********************************************************************** +'* +'* The Contents of this file are made available subject to the terms of +'* the BSD license. +'* +'* Copyright 2000, 2010 Oracle and/or its affiliates. +'* All rights reserved. +'* +'* Redistribution and use in source and binary forms, with or without +'* modification, are permitted provided that the following conditions +'* are met: +'* 1. Redistributions of source code must retain the above copyright +'* notice, this list of conditions and the following disclaimer. +'* 2. Redistributions in binary form must reproduce the above copyright +'* notice, this list of conditions and the following disclaimer in the +'* documentation and/or other materials provided with the distribution. +'* 3. Neither the name of Sun Microsystems, Inc. nor the names of its +'* contributors may be used to endorse or promote products derived +'* from this software without specific prior written permission. +'* +'* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +'* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +'* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +'* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +'* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +'* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +'* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +'* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +'* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +'* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +'* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +'* +'************************************************************************* + +'The service manager is always the starting point +'If there is no office running then an office is started up +Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager") + +'Create the CoreReflection service that is later used to create structs +Set objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection") + +'Create the Desktop +Set objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop") + +'Open a new empty writer document +Dim args() +Set objDocument= objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args) + +'Create a text object +Set objText= objDocument.getText + +'Create a cursor object +Set objCursor= objText.createTextCursor + +'Inserting some Text +objText.insertString objCursor, "The first line in the newly created text document." & vbLf, false + +'Inserting a second line +objText.insertString objCursor, "Now we're in the second line", false + +'Create instance of a text table with 4 columns and 4 rows +Set objTable= objDocument.createInstance( "com.sun.star.text.TextTable") +objTable.initialize 4, 4 + +'Insert the table +objText.insertTextContent objCursor, objTable, false + +'Get first row +Set objRows= objTable.getRows +Set objRow= objRows.getByIndex( 0) + +'Set the table background color +objTable.setPropertyValue "BackTransparent", false +objTable.setPropertyValue "BackColor", 13421823 + +'Set a different background color for the first row +objRow.setPropertyValue "BackTransparent", false +objRow.setPropertyValue "BackColor", 6710932 + +'Fill the first table row +insertIntoCell "A1","FirstColumn", objTable +insertIntoCell "B1","SecondColumn", objTable +insertIntoCell "C1","ThirdColumn", objTable +insertIntoCell "D1","SUM", objTable + +objTable.getCellByName("A2").setValue 22.5 +objTable.getCellByName("B2").setValue 5615.3 +objTable.getCellByName("C2").setValue -2315.7 +objTable.getCellByName("D2").setFormula"sum <A2:C2>" + +objTable.getCellByName("A3").setValue 21.5 +objTable.getCellByName("B3").setValue 615.3 +objTable.getCellByName("C3").setValue -315.7 +objTable.getCellByName("D3").setFormula "sum <A3:C3>" + +objTable.getCellByName("A4").setValue 121.5 +objTable.getCellByName("B4").setValue -615.3 +objTable.getCellByName("C4").setValue 415.7 +objTable.getCellByName("D4").setFormula "sum <A4:C4>" + +'Change the CharColor and add a Shadow +objCursor.setPropertyValue "CharColor", 255 +objCursor.setPropertyValue "CharShadowed", true + +'Create a paragraph break +'The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant +objText.insertControlCharacter objCursor, 0 , false + +'Inserting colored Text. +objText.insertString objCursor, " This is a colored Text - blue with shadow" & vbLf, false + +'Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK). +objText.insertControlCharacter objCursor, 0, false + +'Create a TextFrame. +Set objTextFrame= objDocument.createInstance("com.sun.star.text.TextFrame") + +'Create a Size struct. +Set objSize= createStruct("com.sun.star.awt.Size") +objSize.Width= 15000 +objSize.Height= 400 +objTextFrame.setSize( objSize) + +' TextContentAnchorType.AS_CHARACTER = 1 +objTextFrame.setPropertyValue "AnchorType", 1 + +'insert the frame +objText.insertTextContent objCursor, objTextFrame, false + +'Get the text object of the frame +Set objFrameText= objTextFrame.getText + + +'Create a cursor object +Set objFrameTextCursor= objFrameText.createTextCursor + +'Inserting some Text +objFrameText.insertString objFrameTextCursor, "The first line in the newly created text frame.", _ + false +objFrameText.insertString objFrameTextCursor, _ + vbLf & "With this second line the height of the frame raises.", false + +'Create a paragraph break +'The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant +objFrameText.insertControlCharacter objCursor, 0 , false + +'Change the CharColor and add a Shadow +objCursor.setPropertyValue "CharColor", 65536 +objCursor.setPropertyValue "CharShadowed", false + +'Insert another string +objText.insertString objCursor, " That's all for now !!", false + +On Error Resume Next +If Err Then + MsgBox "An error occurred" +End If + + +Sub insertIntoCell( strCellName, strText, objTable) + Set objCellText= objTable.getCellByName( strCellName) + Set objCellCursor= objCellText.createTextCursor + objCellCursor.setPropertyValue "CharColor",16777215 + objCellText.insertString objCellCursor, strText, false +End Sub + +Function createStruct( strTypeName) + Set classSize= objCoreReflection.forName( strTypeName) + Dim aStruct + classSize.createObject aStruct + Set createStruct= aStruct +End Function diff --git a/odk/examples/OLE/vbscript/readme.txt b/odk/examples/OLE/vbscript/readme.txt new file mode 100644 index 000000000..45a982a13 --- /dev/null +++ b/odk/examples/OLE/vbscript/readme.txt @@ -0,0 +1,4 @@ +Run the script in WriterDemo.vbs with Windows Script Host. +Command line: + +cscript WriterDemo.vbs |