summaryrefslogtreecommitdiff
path: root/iup/srcole
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-11-04 11:56:41 -0800
committerPixel <pixel@nobis-crew.org>2009-11-04 11:59:33 -0800
commitd577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch)
tree590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/srcole
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/srcole')
-rwxr-xr-xiup/srcole/config.mak17
-rwxr-xr-xiup/srcole/iup_olecontrol.cpp200
-rwxr-xr-xiup/srcole/iupole.def3
-rwxr-xr-xiup/srcole/make_uname.bat4
-rwxr-xr-xiup/srcole/tAmbientProperties.cpp157
-rwxr-xr-xiup/srcole/tAmbientProperties.h47
-rwxr-xr-xiup/srcole/tDispatch.cpp236
-rwxr-xr-xiup/srcole/tDispatch.h40
-rwxr-xr-xiup/srcole/tLegacy.cpp240
-rwxr-xr-xiup/srcole/tLegacy.h550
-rwxr-xr-xiup/srcole/tOleClientSite.cpp148
-rwxr-xr-xiup/srcole/tOleClientSite.h40
-rwxr-xr-xiup/srcole/tOleControlSite.cpp301
-rwxr-xr-xiup/srcole/tOleControlSite.h39
-rwxr-xr-xiup/srcole/tOleHandler.cpp1123
-rwxr-xr-xiup/srcole/tOleHandler.h139
-rwxr-xr-xiup/srcole/tOleInPlaceFrame.cpp429
-rwxr-xr-xiup/srcole/tOleInPlaceFrame.h67
-rwxr-xr-xiup/srcole/tOleInPlaceSite.cpp485
-rwxr-xr-xiup/srcole/tOleInPlaceSite.h47
20 files changed, 4312 insertions, 0 deletions
diff --git a/iup/srcole/config.mak b/iup/srcole/config.mak
new file mode 100755
index 0000000..af0ef50
--- /dev/null
+++ b/iup/srcole/config.mak
@@ -0,0 +1,17 @@
+PROJNAME = iup
+LIBNAME = iupole
+OPT = YES
+
+INCLUDES = ../include ../src
+LDIR = ../lib/$(TEC_UNAME)
+LIBS = iup
+
+SRC = iup_olecontrol.cpp \
+ tLegacy.cpp \
+ tAmbientProperties.cpp \
+ tDispatch.cpp \
+ tOleClientSite.cpp \
+ tOleControlSite.cpp \
+ tOleHandler.cpp \
+ tOleInPlaceFrame.cpp \
+ tOleInPlaceSite.cpp
diff --git a/iup/srcole/iup_olecontrol.cpp b/iup/srcole/iup_olecontrol.cpp
new file mode 100755
index 0000000..20431c5
--- /dev/null
+++ b/iup/srcole/iup_olecontrol.cpp
@@ -0,0 +1,200 @@
+/*
+ * iupolectl.cpp
+ *
+ * CPI que implementa um container OLE
+ */
+
+#include "tOleHandler.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "iup.h"
+#include "iupole.h"
+
+#include "iup_object.h"
+#include "iup_register.h"
+#include "iup_attrib.h"
+#include "iup_stdcontrols.h"
+#include "iup_str.h"
+#include "iup_layout.h"
+
+
+struct _IcontrolData
+{
+ iupCanvas canvas; /* from IupCanvas (must reserve it) */
+
+ tOleHandler* olehandler;
+};
+
+static char* iOleControlGetDesignModeAttrib(Ihandle* ih)
+{
+ if (ih->data->olehandler->m_ambientProp.getDesignMode())
+ return "YES";
+ else
+ return "NO";
+}
+
+static int iOleControlSetDesignModeAttrib(Ihandle* ih, const char* value)
+{
+ if (iupStrBoolean(value))
+ ih->data->olehandler->m_ambientProp.setDesignMode(true, true);
+ else
+ ih->data->olehandler->m_ambientProp.setDesignMode(false, true);
+ return 1;
+}
+
+static int iOleControlSetDesignModeDontNotifyAttrib(Ihandle* ih, const char* value)
+{
+ if (iupStrBoolean(value))
+ ih->data->olehandler->m_ambientProp.setDesignMode(true, false);
+ else
+ ih->data->olehandler->m_ambientProp.setDesignMode(false, false);
+ return 1;
+}
+
+static char* iOleControlGetIUnknownAttrib(Ihandle* ih)
+{
+ IUnknown *punk = NULL;
+ ih->data->olehandler->ObjectGet(&punk);
+ return (char*)punk;
+}
+
+static int iOleControlResize_CB(Ihandle *ih)
+{
+ if (!ih->data->olehandler->m_hWnd)
+ return IUP_DEFAULT;
+
+ ih->data->olehandler->OnShow();
+
+ return IUP_DEFAULT;
+}
+
+static void iOleControlComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand)
+{
+ long natural_w = 0, natural_h = 0;
+ (void)expand; /* unset if not a container */
+
+ ih->data->olehandler->GetNaturalSize(&natural_w, &natural_h);
+
+ *w = natural_w;
+ *h = natural_h;
+}
+
+static void iOleControlLayoutUpdateMethod(Ihandle* ih)
+{
+ SIZEL szl;
+ szl.cx = ih->currentwidth;
+ szl.cy = ih->currentheight;
+ ih->data->olehandler->SizeSet(&szl, TRUE, TRUE);
+ ih->data->olehandler->UpdateInPlaceObjectRects(NULL, TRUE);
+}
+
+static int iOleControlMapMethod(Ihandle* ih)
+{
+ /* reset the canvas BGCOLOR */
+ IupSetAttribute(ih, "BACKGROUND", NULL);
+
+ ih->data->olehandler->m_hWnd = ih->handle;
+
+ return IUP_NOERROR;
+}
+
+static int iOleControlCreateMethod(Ihandle* ih, void **params)
+{
+ CLSID clsid;
+
+ if (!params || !(params[0]))
+ return IUP_ERROR;
+
+ char *progID = (char*)params[0];
+
+ /* free the data alocated by IupCanvas */
+ if (ih->data) free(ih->data);
+ ih->data = iupALLOCCTRLDATA();
+
+ /* change the IupCanvas default values */
+ iupAttribSetStr(ih, "BORDER", "NO");
+
+ /* IupCanvas callbacks */
+ IupSetCallback(ih,"RESIZE_CB",(Icallback)iOleControlResize_CB);
+
+ size_t len = strlen(progID)+1;
+ wchar_t* wcProgId = (wchar_t*) malloc(len * sizeof(wchar_t));
+ mbstowcs(wcProgId, progID, len);
+ HRESULT hr = CLSIDFromProgID(wcProgId, &clsid);
+ free(wcProgId);
+ if(FAILED(hr))
+ return IUP_ERROR;
+
+ ih->data->olehandler = new tOleHandler();
+ if (ih->data->olehandler->Create(&clsid) == CREATE_FAILED)
+ return IUP_ERROR;
+
+ return IUP_NOERROR;
+}
+
+static void iOleControlDestroyMethod(Ihandle* ih)
+{
+ ih->data->olehandler->Close(true);
+ delete ih->data->olehandler;
+}
+
+static void iOleControlRelease(Iclass* ic)
+{
+ (void)ic;
+ OleUninitialize();
+}
+
+static Iclass* iOleControlGetClass(void)
+{
+ Iclass* ic = iupClassNew(iupCanvasGetClass());
+
+ ic->name = "olecontrol";
+ ic->format = "s"; /* one string */
+ ic->nativetype = IUP_TYPECANVAS;
+ ic->childtype = IUP_CHILDNONE;
+ ic->is_interactive = 1;
+
+ /* Class functions */
+ ic->Create = iOleControlCreateMethod;
+ ic->Destroy = iOleControlDestroyMethod;
+ ic->Release = iOleControlRelease;
+ ic->Map = iOleControlMapMethod;
+ ic->LayoutUpdate = iOleControlLayoutUpdateMethod;
+ ic->ComputeNaturalSize = iOleControlComputeNaturalSizeMethod;
+
+ iupClassRegisterAttribute(ic, "DESIGNMODE", iOleControlGetDesignModeAttrib, iOleControlSetDesignModeAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT);
+ iupClassRegisterAttribute(ic, "DESIGNMODE_DONT_NOTIFY", iOleControlGetDesignModeAttrib, iOleControlSetDesignModeDontNotifyAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT);
+ iupClassRegisterAttribute(ic, "IUNKNOWN", iOleControlGetIUnknownAttrib, NULL, NULL, NULL, IUPAF_READONLY|IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT|IUPAF_NO_STRING);
+
+ /* Overwrite the canvas implementation */
+ iupClassRegisterAttribute(ic, "BGCOLOR", NULL, NULL, NULL, NULL, IUPAF_NOT_MAPPED);
+
+ return ic;
+}
+
+Ihandle *IupOleControl(const char *ProgID)
+{
+ void *params[2];
+ params[0] = (void*)ProgID;
+ params[1] = NULL;
+ return IupCreatev("olecontrol", params);
+}
+
+int IupOleControlOpen(void)
+{
+ if (IupGetGlobal("_IUP_OLECONTROL_OPEN"))
+ return IUP_OPENED;
+
+ HRESULT retval = OleInitialize(NULL);
+ if (retval != S_OK && retval != S_FALSE)
+ return IUP_ERROR;
+
+ iupRegisterClass(iOleControlGetClass());
+
+ IupSetGlobal("_IUP_OLECONTROL_OPEN", "1");
+ return IUP_NOERROR;
+}
diff --git a/iup/srcole/iupole.def b/iup/srcole/iupole.def
new file mode 100755
index 0000000..d5fd72a
--- /dev/null
+++ b/iup/srcole/iupole.def
@@ -0,0 +1,3 @@
+EXPORTS
+IupOleControl
+IupOleControlOpen
diff --git a/iup/srcole/make_uname.bat b/iup/srcole/make_uname.bat
new file mode 100755
index 0000000..f0a0722
--- /dev/null
+++ b/iup/srcole/make_uname.bat
@@ -0,0 +1,4 @@
+@echo off
+REM This builds all the libraries of the folder for 1 uname
+
+call tecmake %1 %2 %3 %4 %5 %6
diff --git a/iup/srcole/tAmbientProperties.cpp b/iup/srcole/tAmbientProperties.cpp
new file mode 100755
index 0000000..c9968a7
--- /dev/null
+++ b/iup/srcole/tAmbientProperties.cpp
@@ -0,0 +1,157 @@
+// tAmbientProperties.cpp: implementation of the tAmbientProperties class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include <assert.h>
+
+#include "tAmbientProperties.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+tAmbientProperties::tAmbientProperties()
+{
+ //0x80000000 in OLE_COLOR indicates low byte is color index.
+ m_clrBack=0x80000000+COLOR_WINDOW;
+ m_clrFore=0x80000000+COLOR_WINDOWTEXT;
+ m_lcid=LOCALE_USER_DEFAULT;
+ m_fDesignMode = TRUE;
+
+ m_pIOleControl = NULL;
+
+#if 0
+ {
+ int cy=MulDiv(-14, LOMETRIC_PER_INCH, 72);
+ //CHAPTER24MOD
+ //End CHAPTER24MOD
+
+ HFONT m_hFont=CreateFont(cy, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE
+ , ANSI_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY
+ , VARIABLE_PITCH | FF_SWISS, TEXT("Arial"));
+
+
+ //m_hFont=(HFONT)GetStockObject(ANSI_VAR_FONT);
+
+ //Need a standard font object for ambient properties
+
+ FONTDESC fd={sizeof(FONTDESC), L"Arial"
+ , FONTSIZE(14), FW_NORMAL, DEFAULT_CHARSET
+ , FALSE, FALSE, FALSE};
+
+ OleCreateFontIndirect(
+ &fd, IID_IFontDisp, (void **)&m_pIFont
+ );
+#endif
+ m_pIFont = NULL;
+}
+
+tAmbientProperties::~tAmbientProperties()
+{
+ if(m_pIOleControl)
+ m_pIOleControl->Release();
+
+ if(m_pIFont)
+ m_pIFont->Release();
+}
+
+void tAmbientProperties::setDesignMode(bool value, bool notify)
+{
+ switch(value)
+ {
+ case true:
+ m_fDesignMode = FALSE;
+ break;
+
+ case false:
+ m_fDesignMode = FALSE;
+ break;
+ }
+
+ assert(m_pIOleControl);
+ if(m_pIOleControl == NULL)
+ return;
+
+
+ // Notifica controle da mudanca
+
+ if(notify)
+ m_pIOleControl->OnAmbientPropertyChange(DISPID_AMBIENT_USERMODE);
+}
+
+OLE_COLOR tAmbientProperties::getBackColor()
+{
+ return m_clrBack;
+}
+
+OLE_COLOR tAmbientProperties::getForeColor()
+{
+ return m_clrFore;
+}
+
+bool tAmbientProperties::has_font()
+{
+ if(m_pIFont != NULL)
+ return true;
+ else
+ return false;
+}
+
+IFontDisp * tAmbientProperties::getFontRef()
+{
+ m_pIFont->AddRef();
+ return m_pIFont;
+}
+
+LCID tAmbientProperties::getLCID()
+{
+ return m_lcid;
+}
+
+BOOL tAmbientProperties::getDesignMode()
+{
+ return m_fDesignMode;
+}
+
+void tAmbientProperties::setForeColor(int red,
+ int green,
+ int blue,
+ bool notify)
+{
+ m_clrFore = blue << 16 | green << 8 | red;
+
+ assert(m_pIOleControl);
+ if(m_pIOleControl == NULL)
+ return;
+
+ if(notify)
+ m_pIOleControl->
+ OnAmbientPropertyChange(DISPID_AMBIENT_FORECOLOR);
+}
+
+void tAmbientProperties::setBackColor(int red,
+ int green,
+ int blue,
+ bool notify)
+{
+ m_clrBack = blue << 16 | green << 8 | red;
+
+ assert(m_pIOleControl);
+ if(m_pIOleControl == NULL)
+ return;
+
+ if(notify)
+ m_pIOleControl->
+ OnAmbientPropertyChange(DISPID_AMBIENT_BACKCOLOR);
+}
+
+void tAmbientProperties::setControl(IOleControl * olecontrol)
+{
+ assert(olecontrol && m_pIOleControl == NULL);
+
+ if(m_pIOleControl != NULL)
+ return;
+
+ olecontrol->AddRef();
+ m_pIOleControl = olecontrol;
+}
diff --git a/iup/srcole/tAmbientProperties.h b/iup/srcole/tAmbientProperties.h
new file mode 100755
index 0000000..359e733
--- /dev/null
+++ b/iup/srcole/tAmbientProperties.h
@@ -0,0 +1,47 @@
+// tAmbientProperties.h: interface for the tAmbientProperties class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_TAMBIENTPROPERTIES_H__FC01B4C7_4918_11D4_9DF5_0000B45D6611__INCLUDED_)
+#define AFX_TAMBIENTPROPERTIES_H__FC01B4C7_4918_11D4_9DF5_0000B45D6611__INCLUDED_
+
+#if _MSC_VER >= 1000
+#pragma once
+#endif // _MSC_VER >= 1000
+
+#include <windows.h>
+#include <olectl.h>
+
+
+class tAmbientProperties
+{
+public:
+ void setControl(IOleControl *olecontrol);
+ void setBackColor(int red, int green, int blue, bool notify);
+ void setForeColor(int red, int green, int blue, bool notify);
+ BOOL getDesignMode(void);
+ LCID getLCID(void);
+ IFontDisp * getFontRef(void);
+ bool has_font(void);
+ OLE_COLOR getForeColor(void);
+ OLE_COLOR getBackColor(void);
+ void setDesignMode(bool value, bool notify);
+ tAmbientProperties();
+ virtual ~tAmbientProperties();
+
+protected:
+
+ // Utilizado para notificar mudancas nas propriedades
+ LPOLECONTROL m_pIOleControl;
+
+ // propriedades
+ OLE_COLOR m_clrBack;
+ OLE_COLOR m_clrFore;
+ IFontDisp *m_pIFont;
+ LCID m_lcid;
+ BOOL m_fDesignMode;
+ BOOL m_fUIDead;
+ BOOL m_fHatchHandles;
+};
+
+#endif // !defined(AFX_TAMBIENTPROPERTIES_H__FC01B4C7_4918_11D4_9DF5_0000B45D6611__INCLUDED_)
diff --git a/iup/srcole/tDispatch.cpp b/iup/srcole/tDispatch.cpp
new file mode 100755
index 0000000..9db30a3
--- /dev/null
+++ b/iup/srcole/tDispatch.cpp
@@ -0,0 +1,236 @@
+// tDispatch.cpp: implementation of the tDispatch class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "tDispatch.h"
+#include "tOleHandler.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+
+/*
+ * tDispatch::tDispatch
+ * tDispatch::~tDispatch
+ *
+ * Parameters (Constructor):
+ * pTen PCTenant of the tenant we're in.
+ * pUnkOuter LPUNKNOWN to which we delegate.
+ */
+
+tDispatch::tDispatch(tOleHandler *pTen, LPUNKNOWN pUnkOuter)
+ {
+ m_cRef=0;
+ m_pTen=pTen;
+ m_pUnkOuter=pUnkOuter;
+ return;
+ }
+
+tDispatch::~tDispatch(void)
+ {
+ return;
+ }
+
+
+
+
+/*
+ * tDispatch::QueryInterface
+ * tDispatch::AddRef
+ * tDispatch::Release
+ */
+
+STDMETHODIMP tDispatch::QueryInterface(REFIID riid, PPVOID ppv)
+ {
+ return m_pUnkOuter->QueryInterface(riid, ppv);
+ }
+
+STDMETHODIMP_(ULONG) tDispatch::AddRef(void)
+ {
+ ++m_cRef;
+ return m_pUnkOuter->AddRef();
+ }
+
+STDMETHODIMP_(ULONG) tDispatch::Release(void)
+ {
+ m_cRef--;
+ return m_pUnkOuter->Release();
+ }
+
+
+
+
+/*
+ * tDispatch::GetTypeInfoCount
+ * tDispatch::GetTypeInfo
+ * tDispatch::GetIDsOfNames
+ *
+ * Unimplemented members, not needed for ambient properties.
+ */
+
+STDMETHODIMP tDispatch::GetTypeInfoCount(UINT *pctInfo)
+ {
+ *pctInfo=0;
+ return NOERROR;
+ }
+
+STDMETHODIMP tDispatch::GetTypeInfo(UINT itinfo
+ , LCID lcid, ITypeInfo **pptInfo)
+ {
+ *pptInfo=NULL;
+ return ResultFromScode(E_NOTIMPL);
+ }
+
+STDMETHODIMP tDispatch::GetIDsOfNames(REFIID riid
+ , OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID *rgDispID)
+ {
+ *rgszNames=NULL;
+ *rgDispID=NULL;
+ return ResultFromScode(E_NOTIMPL);
+ }
+
+
+
+
+/*
+ * tDispatch::Invoke
+ *
+ * Purpose:
+ * Calls a method in the dispatch interface or manipulates a
+ * property.
+ *
+ * Parameters:
+ * dispIDMember DISPID of the method or property of interest.
+ * riid REFIID reserved, must be NULL.
+ * lcid LCID of the locale.
+ * wFlags USHORT describing the context of the invocation.
+ * pDispParams DISPPARAMS * to the array of arguments.
+ * pVarResult VARIANT * in which to store the result. Is
+ * NULL if the caller is not interested.
+ * pExcepInfo EXCEPINFO * to exception information.
+ * puArgErr UINT * in which to store the index of an
+ * invalid parameter if DISP_E_TYPEMISMATCH
+ * is returned.
+ *
+ * Return Value:
+ * HRESULT NOERROR or a general error code.
+ */
+
+
+STDMETHODIMP tDispatch::Invoke(DISPID dispIDMember, REFIID riid
+ , LCID lcid, unsigned short wFlags, DISPPARAMS *pDispParams
+ , VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
+ {
+ HRESULT hr;
+ VARIANT varResult;
+
+ if (IID_NULL!=riid)
+ return ResultFromScode(E_INVALIDARG);
+
+ /*
+ * We ignore lcid in this function. A multilingual application
+ * might use it to determine the meaning of certain parameters
+ * or perhaps as an indication of how to format data like
+ * time, date, and currency or any other language or locale-
+ * sensitive data.
+ */
+
+ /*
+ * Variable handling: since ambient properties is just a
+ * collection of singular read-only values, we don't have to
+ * worry about input parameters.
+ */
+
+ /*
+ * If the caller is not interested in the return value, then
+ * pVarResult is NULL. But since we're dealing with ambient
+ * properties, there should always be an interest. In any case,
+ * if we're given a NULL, we'll point it to a dummy structure so
+ * the rest of the code can assume that pVarResult is non-NULL.
+ */
+ if(NULL==pVarResult)
+ pVarResult=&varResult;
+
+ VariantInit(pVarResult);
+
+ //The most common case is boolean, use as an initial type
+ V_VT(pVarResult)=VT_BOOL;
+
+ /*
+ * Process the requested ambient property. Anything but a
+ * request for a property is invalid, so we can check that
+ * before looking at the specific ID. We can only get away
+ * with this because all properties are read-only.
+ */
+
+ if (!(DISPATCH_PROPERTYGET & wFlags))
+ return ResultFromScode(DISP_E_MEMBERNOTFOUND);
+
+ hr=NOERROR;
+
+ switch (dispIDMember)
+ {
+ case DISPID_AMBIENT_BACKCOLOR:
+ V_I4(pVarResult)=m_pTen->m_ambientProp.getBackColor();
+ V_VT(pVarResult)=VT_I4;
+ break;
+
+ case DISPID_AMBIENT_FORECOLOR:
+ V_I4(pVarResult)=m_pTen->m_ambientProp.getForeColor();
+ V_VT(pVarResult)=VT_I4;
+ break;
+
+ case DISPID_AMBIENT_FONT:
+ /*
+ * If we failed to create the font, act like we
+ * don't support it.
+ */
+ if (!m_pTen->m_ambientProp.has_font())
+ return ResultFromScode(DISP_E_MEMBERNOTFOUND);
+
+ //The correct type is an IFontDisp pointer
+ V_DISPATCH(pVarResult)=m_pTen->m_ambientProp.getFontRef();
+ V_VT(pVarResult)=VT_FONT;
+ break;
+
+ case DISPID_AMBIENT_LOCALEID:
+ V_I4(pVarResult)=m_pTen->m_ambientProp.getLCID();
+ V_VT(pVarResult)=VT_I4;
+ break;
+
+ case DISPID_AMBIENT_USERMODE:
+ V_BOOL(pVarResult)=!m_pTen->m_ambientProp.getDesignMode();
+ V_VT(pVarResult) = VT_BOOL;
+ break;
+
+ case DISPID_AMBIENT_UIDEAD:
+ //V_BOOL(pVarResult)=m_pTen->m_ambientProp.getUIDead();
+ V_BOOL(pVarResult)=FALSE;
+ V_VT(pVarResult) = VT_BOOL;
+
+ break;
+
+ case DISPID_AMBIENT_SUPPORTSMNEMONICS:
+ V_BOOL(pVarResult)=TRUE;
+ break;
+
+ case DISPID_AMBIENT_SHOWGRABHANDLES:
+ //V_BOOL(pVarResult)=m_pTen->m_ambientProp.m_fHatchHandles;
+ V_BOOL(pVarResult)=FALSE;
+ V_VT(pVarResult) = VT_BOOL;
+ break;
+
+ case DISPID_AMBIENT_SHOWHATCHING:
+// V_BOOL(pVarResult)=m_pTen->m_ambientProp.m_fHatchHandles;
+ V_BOOL(pVarResult)=FALSE;
+ V_VT(pVarResult) = VT_BOOL;
+ break;
+
+ default:
+ hr=ResultFromScode(DISP_E_MEMBERNOTFOUND);
+ break;
+ }
+
+ return hr;
+ }
diff --git a/iup/srcole/tDispatch.h b/iup/srcole/tDispatch.h
new file mode 100755
index 0000000..c061d75
--- /dev/null
+++ b/iup/srcole/tDispatch.h
@@ -0,0 +1,40 @@
+// tDispatch.h: interface for the tDispatch class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_TDISPATCH_H__37A5ADED_91FB_11D3_A906_0004AC252223__INCLUDED_)
+#define AFX_TDISPATCH_H__37A5ADED_91FB_11D3_A906_0004AC252223__INCLUDED_
+
+#if _MSC_VER >= 1000
+#pragma once
+#endif // _MSC_VER >= 1000
+
+#include <windows.h>
+
+class tDispatch : public IDispatch
+{
+public:
+ protected:
+ ULONG m_cRef;
+ class tOleHandler *m_pTen;
+ LPUNKNOWN m_pUnkOuter;
+
+ public:
+ tDispatch(class tOleHandler *, LPUNKNOWN);
+ ~tDispatch(void);
+
+ STDMETHODIMP QueryInterface(REFIID, LPVOID *);
+ STDMETHODIMP_(ULONG) AddRef(void);
+ STDMETHODIMP_(ULONG) Release(void);
+
+ STDMETHODIMP GetTypeInfoCount(UINT *);
+ STDMETHODIMP GetTypeInfo(UINT, LCID, ITypeInfo **);
+ STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR **, UINT
+ , LCID, DISPID *);
+ STDMETHODIMP Invoke(DISPID, REFIID, LCID, USHORT
+ , DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
+
+
+};
+
+#endif // !defined(AFX_TDISPATCH_H__37A5ADED_91FB_11D3_A906_0004AC252223__INCLUDED_)
diff --git a/iup/srcole/tLegacy.cpp b/iup/srcole/tLegacy.cpp
new file mode 100755
index 0000000..c310865
--- /dev/null
+++ b/iup/srcole/tLegacy.cpp
@@ -0,0 +1,240 @@
+// legacy.cpp
+
+#include <windows.h>
+#include "tLegacy.h"
+
+
+/*
+ * RectConvertMappings
+ *
+ * Purpose:
+ * Converts the contents of a rectangle from device to logical
+ * coordinates where the hDC defines the logical coordinates.
+ *
+ * Parameters:
+ * pRect LPRECT containing the rectangle to convert.
+ * hDC HDC describing the logical coordinate system.
+ * if NULL, uses a screen DC in MM_LOMETRIC.
+ * fToDevice BOOL TRUE to convert from uConv to device,
+ * FALSE to convert device to uConv.
+ *
+ * Return Value:
+ * None
+ */
+
+
+void RectConvertMappings(LPRECT pRect, HDC hDC, BOOL fToDevice)
+ {
+ POINT rgpt[2];
+ BOOL fSysDC=FALSE;
+
+ if (NULL==pRect)
+ return;
+
+ rgpt[0].x=pRect->left;
+ rgpt[0].y=pRect->top;
+ rgpt[1].x=pRect->right;
+ rgpt[1].y=pRect->bottom;
+
+ if (NULL==hDC)
+ {
+ hDC=GetDC(NULL);
+ SetMapMode(hDC, MM_LOMETRIC);
+ fSysDC=TRUE;
+ }
+
+ if (fToDevice)
+ LPtoDP(hDC, rgpt, 2);
+ else
+ DPtoLP(hDC, rgpt, 2);
+
+ if (fSysDC)
+ ReleaseDC(NULL, hDC);
+
+ pRect->left=rgpt[0].x;
+ pRect->top=rgpt[0].y;
+ pRect->right=rgpt[1].x;
+ pRect->bottom=rgpt[1].y;
+
+ return;
+ }
+
+STDAPI_(void) XformRectInHimetricToPixels(HDC hDC, LPRECT prcHiMetric
+ , LPRECT prcPix)
+ {
+ int iXppli; //Pixels per logical inch along width
+ int iYppli; //Pixels per logical inch along height
+ int iXextInHiMetric=(prcHiMetric->right-prcHiMetric->left);
+ int iYextInHiMetric=(prcHiMetric->bottom-prcHiMetric->top);
+ BOOL fSystemDC=FALSE;
+
+ if (NULL==hDC || GetDeviceCaps(hDC, LOGPIXELSX) == 0)
+ {
+ hDC=GetDC(NULL);
+ fSystemDC=TRUE;
+ }
+
+ iXppli=GetDeviceCaps (hDC, LOGPIXELSX);
+ iYppli=GetDeviceCaps (hDC, LOGPIXELSY);
+
+ //We got pixel units, convert them to logical HIMETRIC along the display
+ prcPix->right=MAP_LOGHIM_TO_PIX(iXextInHiMetric, iXppli);
+ prcPix->top =MAP_LOGHIM_TO_PIX(iYextInHiMetric, iYppli);
+
+ prcPix->left =0;
+ prcPix->bottom= 0;
+
+ if (fSystemDC)
+ ReleaseDC(NULL, hDC);
+
+ return;
+ }
+/*
+ * INOLE_SetIconInCache
+ *
+ * Purpose:
+ * Stores an iconic presentation metafile in the cache.
+ *
+ * Parameters:
+ * pObj IUnknown * of the object.
+ * hMetaPict HGLOBAL containing the presentation.
+ *
+ * Return Value:
+ * HRESULT From IOleCache::SetData.
+ */
+
+#if 0
+STDAPI INOLE_SetIconInCache(IUnknown *pObj, HGLOBAL hMetaPict)
+ {
+ IOleCache *pCache;
+ FORMATETC fe;
+ STGMEDIUM stm;
+ HRESULT hr;
+
+ if (NULL==hMetaPict)
+ return ResultFromScode(E_INVALIDARG);
+
+ if (FAILED(pObj->QueryInterface(IID_IOleCache, (void **)&pCache)))
+ return ResultFromScode(E_NOINTERFACE);
+
+ SETFormatEtc(fe, CF_METAFILEPICT, DVASPECT_ICON, NULL
+ , TYMED_MFPICT, -1);
+
+ stm.tymed=TYMED_MFPICT;
+ stm.hGlobal=hMetaPict;
+ stm.pUnkForRelease=NULL;
+
+ hr=pCache->SetData(&fe, &stm, FALSE);
+ pCache->Release();
+
+ return hr;
+ }
+#endif
+
+
+
+/*
+ * XformRectInPixelsToHimetric
+ * XformRectInHimetricToPixels
+ *
+ * Purpose:
+ * Convert a rectangle between pixels of a given hDC and HIMETRIC units
+ * as manipulated in OLE. If the hDC is NULL, then a screen DC is used
+ * and assumes the MM_TEXT mapping mode.
+ *
+ * Parameters:
+ * hDC HDC providing reference to the pixel mapping. If
+ * NULL, a screen DC is used.
+ * prcPix LPRECT containng the rectangles to convert.
+ * prcHiMetric
+ *
+ * Return Value:
+ * None
+ *
+ * NOTE:
+ * When displaying on the screen, Window apps display everything enlarged
+ * from its actual size so that it is easier to read. For example, if an
+ * app wants to display a 1in. horizontal line, that when printed is
+ * actually a 1in. line on the printed page, then it will display the line
+ * on the screen physically larger than 1in. This is described as a line
+ * that is "logically" 1in. along the display width. Windows maintains as
+ * part of the device-specific information about a given display device:
+ * LOGPIXELSX -- no. of pixels per logical in along the display width
+ * LOGPIXELSY -- no. of pixels per logical in along the display height
+ *
+ * The following formula converts a distance in pixels into its equivalent
+ * logical HIMETRIC units:
+ *
+ * DistInHiMetric=(HIMETRIC_PER_INCH * DistInPix)
+ * -------------------------------
+ * PIXELS_PER_LOGICAL_IN
+ *
+ * Rect in Pixels (MM_TEXT):
+ *
+ * 0---------- X
+ * |
+ * | 1) ------------------ ( 2 P1=(rc.left, rc.top)
+ * | | | P2=(rc.right, rc.top)
+ * | | | P3=(rc.left, rc.bottom)
+ * | | | P4=(rc.right, rc.bottom)
+ * | |
+ * Y | |
+ * 3) ------------------ ( 4
+ *
+ * NOTE: Origin =(P1x, P1y)
+ * X extent=P4x - P1x
+ * Y extent=P4y - P1y
+ *
+ *
+ * Rect in Himetric (MM_HIMETRIC):
+ *
+ *
+ * 1) ------------------ ( 2 P1=(rc.left, rc.top)
+ * Y | | P2=(rc.right, rc.top)
+ * | | P3=(rc.left, rc.bottom)
+ * | | | P4=(rc.right, rc.bottom)
+ * | | |
+ * | | |
+ * | 3) ------------------ ( 4
+ * |
+ * 0---------- X
+ *
+ * NOTE: Origin =(P3x, P3y)
+ * X extent=P2x - P3x
+ * Y extent=P2y - P3y
+ *
+ *
+ */
+
+STDAPI_(void) XformRectInPixelsToHimetric(HDC hDC, LPRECT prcPix
+ , LPRECT prcHiMetric)
+ {
+ int iXppli; //Pixels per logical inch along width
+ int iYppli; //Pixels per logical inch along height
+ int iXextInPix=(prcPix->right-prcPix->left);
+ int iYextInPix=(prcPix->bottom-prcPix->top);
+ BOOL fSystemDC=FALSE;
+
+ if (NULL==hDC || GetDeviceCaps(hDC, LOGPIXELSX) == 0)
+ {
+ hDC=GetDC(NULL);
+ fSystemDC=TRUE;
+ }
+
+ iXppli=GetDeviceCaps (hDC, LOGPIXELSX);
+ iYppli=GetDeviceCaps (hDC, LOGPIXELSY);
+
+ //We got pixel units, convert them to logical HIMETRIC along the display
+ prcHiMetric->right=MAP_PIX_TO_LOGHIM(iXextInPix, iXppli);
+ prcHiMetric->top =MAP_PIX_TO_LOGHIM(iYextInPix, iYppli);
+
+ prcHiMetric->left =0;
+ prcHiMetric->bottom =0;
+
+ if (fSystemDC)
+ ReleaseDC(NULL, hDC);
+
+ return;
+ }
+
+
diff --git a/iup/srcole/tLegacy.h b/iup/srcole/tLegacy.h
new file mode 100755
index 0000000..3294e20
--- /dev/null
+++ b/iup/srcole/tLegacy.h
@@ -0,0 +1,550 @@
+/*
+ * INOLE.H
+ *
+ * Master header file for all Inside OLE samples.
+ *
+ * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
+ *
+ * Kraig Brockschmidt, Microsoft
+ * Internet : kraigb@microsoft.com
+ * Compuserve: >INTERNET:kraigb@microsoft.com
+ */
+
+
+#ifndef _INOLE_H_
+#define _INOLE_H_
+
+#define INC_OLE2
+#include <windows.h>
+#include <ole2.h>
+#include <ole2ver.h>
+
+#ifdef INC_OLEUI
+#ifdef WIN32
+/*
+ * Comment the next line and remove the comment from the
+ * line after it to compile for Windows NT 3.5.
+ */
+#include <oledlg.h>
+//#include <ole2ui.h>
+#else
+#include <ole2ui.h>
+#endif
+#endif
+
+#ifdef INC_CONTROLS
+#define INC_AUTOMATION
+#endif
+
+#ifdef INC_AUTOMATION
+#ifndef WIN32
+#include <dispatch.h>
+#include <olenls.h>
+#else
+#include <oleauto.h>
+#endif
+#endif
+
+#ifdef INC_CONTROLS
+#include <olectl.h>
+#ifndef INITGUIDS
+#include <olectlid.h>
+#endif
+#endif
+
+#ifdef WIN32
+#include <tchar.h>
+#ifdef UNICODE
+#include <wchar.h>
+#endif
+#endif
+
+#ifndef WIN32
+#include <shellapi.h>
+#include <malloc.h>
+#endif
+
+#ifdef INC_CLASSLIB
+extern "C"
+ {
+ #include <commdlg.h>
+ #ifndef WIN32
+ #include <print.h>
+ #include <dlgs.h>
+ #endif
+ }
+
+#include <classlib.h>
+#endif
+
+
+//Types that OLE2.H et. al. leave out
+
+#ifndef PPVOID
+typedef LPVOID * PPVOID;
+#endif //PPVOID
+
+
+#ifdef _OLE2_H_ //May not include ole2.h at all times.
+
+#ifndef PPOINTL
+typedef POINTL * PPOINTL;
+#endif //PPOINTL
+
+
+#ifndef _WIN32
+#ifndef OLECHAR
+typedef char OLECHAR;
+typedef OLECHAR FAR* LPOLESTR;
+typedef const OLECHAR FAR* LPCOLESTR;
+#endif //OLECHAR
+#endif //_WIN32
+
+
+//Useful macros.
+#define SETFormatEtc(fe, cf, asp, td, med, li) \
+ {\
+ (fe).cfFormat=cf;\
+ (fe).dwAspect=asp;\
+ (fe).ptd=td;\
+ (fe).tymed=med;\
+ (fe).lindex=li;\
+ }
+
+#define SETDefFormatEtc(fe, cf, med) \
+ {\
+ (fe).cfFormat=cf;\
+ (fe).dwAspect=DVASPECT_CONTENT;\
+ (fe).ptd=NULL;\
+ (fe).tymed=med;\
+ (fe).lindex=-1;\
+ }
+
+
+#define SETRECTL(rcl, l, t, r, b) \
+ {\
+ (rcl).left=l;\
+ (rcl).top=t;\
+ (rcl).right=r;\
+ (rcl).bottom=b;\
+ }
+
+#define SETSIZEL(szl, h, v) \
+ {\
+ (szl).cx=h;\
+ (szl).cy=v;\
+ }
+
+
+#define RECTLFROMRECT(rcl, rc)\
+ {\
+ (rcl).left=(long)(rc).left;\
+ (rcl).top=(long)(rc).top;\
+ (rcl).right=(long)(rc).right;\
+ (rcl).bottom=(long)(rc).bottom;\
+ }
+
+
+#define RECTFROMRECTL(rc, rcl)\
+ {\
+ (rc).left=(int)(rcl).left;\
+ (rc).top=(int)(rcl).top;\
+ (rc).right=(int)(rcl).right;\
+ (rc).bottom=(int)(rcl).bottom;\
+ }
+
+
+#define POINTLFROMPOINT(ptl, pt) \
+ { \
+ (ptl).x=(long)(pt).x; \
+ (ptl).y=(long)(pt).y; \
+ }
+
+
+#define POINTFROMPOINTL(pt, ptl) \
+ { \
+ (pt).x=(int)(ptl).x; \
+ (pt).y=(int)(ptl).y; \
+ }
+
+//Here's one that should be in windows.h
+#define SETPOINT(pt, h, v) \
+ {\
+ (pt).x=h;\
+ (pt).y=v;\
+ }
+
+#define SETPOINTL(ptl, h, v) \
+ {\
+ (ptl).x=h;\
+ (ptl).y=v;\
+ }
+
+#endif //_OLE2_H_
+
+#ifdef INC_AUTOMATION
+
+//Macros for setting DISPPARAMS structures
+#define SETDISPPARAMS(dp, numArgs, pvArgs, numNamed, pNamed) \
+ {\
+ (dp).cArgs=numArgs;\
+ (dp).rgvarg=pvArgs;\
+ (dp).cNamedArgs=numNamed;\
+ (dp).rgdispidNamedArgs=pNamed;\
+ }
+
+#define SETNOPARAMS(dp) SETDISPPARAMS(dp, 0, NULL, 0, NULL)
+
+//Macros for setting EXCEPINFO structures
+#define SETEXCEPINFO(ei, excode, src, desc, file, ctx, func, scd) \
+ {\
+ (ei).wCode=excode;\
+ (ei).wReserved=0;\
+ (ei).bstrSource=src;\
+ (ei).bstrDescription=desc;\
+ (ei).bstrHelpFile=file;\
+ (ei).dwHelpContext=ctx;\
+ (ei).pvReserved=NULL;\
+ (ei).pfnDeferredFillIn=func;\
+ (ei).scode=scd;\
+ }
+
+
+#define INITEXCEPINFO(ei) \
+ SETEXCEPINFO(ei,0,NULL,NULL,NULL,0L,NULL,S_OK)
+
+#endif
+
+
+/*
+ * State flags for IPersistStorage implementations. These
+ * are kept here to avoid repeating the code in all samples.
+ */
+
+typedef enum
+ {
+ PSSTATE_UNINIT, //Uninitialized
+ PSSTATE_SCRIBBLE, //Scribble
+ PSSTATE_ZOMBIE, //No scribble
+ PSSTATE_HANDSOFF //Hand-off
+ } PSSTATE;
+
+
+/*
+ * Identifers to describe which persistence model an object
+ * is using, along with a union type that holds on the the
+ * appropriate pointers that a client may need.
+ */
+typedef enum
+ {
+ PERSIST_UNKNOWN=0,
+ PERSIST_STORAGE,
+ PERSIST_STREAM,
+ PERSIST_STREAMINIT,
+ PERSIST_FILE
+ } PERSIST_MODEL;
+
+typedef struct
+ {
+ PERSIST_MODEL psModel;
+ union
+ {
+ IPersistStorage *pIPersistStorage;
+ IPersistStream *pIPersistStream;
+ #ifdef INC_CONTROLS
+ IPersistStreamInit *pIPersistStreamInit;
+ #endif
+ IPersistFile *pIPersistFile;
+ } pIP;
+
+ } PERSISTPOINTER, *PPERSISTPOINTER;
+
+
+//To identify a storage in which to save, load, or create.
+typedef struct
+ {
+ PERSIST_MODEL psModel;
+ union
+ {
+ IStorage *pIStorage;
+ IStream *pIStream;
+ } pIS;
+
+ } STGPOINTER, *PSTGPOINTER;
+
+
+
+//Type for an object-destroyed callback
+typedef void (*PFNDESTROYED)(void);
+
+
+//DeleteInterfaceImp calls 'delete' and NULLs the pointer
+#define DeleteInterfaceImp(p)\
+ {\
+ if (NULL!=p)\
+ {\
+ delete p;\
+ p=NULL;\
+ }\
+ }
+
+
+//ReleaseInterface calls 'Release' and NULLs the pointer
+#define ReleaseInterface(p)\
+ {\
+ IUnknown *pt=(IUnknown *)p;\
+ p=NULL;\
+ if (NULL!=pt)\
+ pt->Release();\
+ }
+
+
+//OLE Documents Clipboard Formats
+
+#define CFSTR_EMBEDSOURCE TEXT("Embed Source")
+#define CFSTR_EMBEDDEDOBJECT TEXT("Embedded Object")
+#define CFSTR_LINKSOURCE TEXT("Link Source")
+#define CFSTR_CUSTOMLINKSOURCE TEXT("Custom Link Source")
+#define CFSTR_OBJECTDESCRIPTOR TEXT("Object Descriptor")
+#define CFSTR_LINKSRCDESCRIPTOR TEXT("Link Source Descriptor")
+
+
+
+//Functions in the helper DLL, INOLE.DLL
+
+//UI Effects
+STDAPI_(void) UIDrawHandles(LPRECT, HDC, DWORD, UINT, BOOL);
+STDAPI_(void) UIDrawShading(LPRECT, HDC, DWORD, UINT);
+STDAPI_(void) UIShowObject(LPCRECT, HDC, BOOL);
+
+//For UIDrawHandles
+#define UI_HANDLES_USEINVERSE 0x00000001L
+#define UI_HANDLES_NOBORDER 0x00000002L
+#define UI_HANDLES_INSIDE 0x00000004L
+#define UI_HANDLES_OUTSIDE 0x00000008L
+
+//For UIDrawShading
+#define UI_SHADE_FULLRECT 1
+#define UI_SHADE_BORDERIN 2
+#define UI_SHADE_BORDEROUT 3
+
+//Coordinate Munging
+STDAPI_(int) XformWidthInHimetricToPixels(HDC, int);
+STDAPI_(int) XformWidthInPixelsToHimetric(HDC, int);
+STDAPI_(int) XformHeightInHimetricToPixels(HDC, int);
+STDAPI_(int) XformHeightInPixelsToHimetric(HDC, int);
+
+STDAPI_(void) XformRectInPixelsToHimetric(HDC, LPRECT, LPRECT);
+STDAPI_(void) XformRectInHimetricToPixels(HDC, LPRECT, LPRECT);
+STDAPI_(void) XformSizeInPixelsToHimetric(HDC, LPSIZEL, LPSIZEL);
+STDAPI_(void) XformSizeInHimetricToPixels(HDC, LPSIZEL, LPSIZEL);
+
+
+//Helpers
+STDAPI_(void) INOLE_MetafilePictIconFree(HGLOBAL);
+STDAPI INOLE_SetIconInCache(IUnknown *, HGLOBAL);
+STDAPI_(UINT) INOLE_GetUserTypeOfClass(REFCLSID, UINT, LPTSTR
+ , UINT);
+STDAPI INOLE_DoConvert(IStorage *, REFCLSID);
+STDAPI_(LPTSTR) INOLE_CopyString(LPTSTR);
+STDAPI_(HGLOBAL) INOLE_ObjectDescriptorFromOleObject(IOleObject *
+ , DWORD, POINTL, LPSIZEL);
+STDAPI_(HGLOBAL) INOLE_AllocObjectDescriptor(CLSID, DWORD
+ , SIZEL, POINTL, DWORD, LPTSTR, LPTSTR);
+STDAPI_(IStorage *) INOLE_CreateStorageOnHGlobal(DWORD);
+STDAPI INOLE_GetLinkSourceData(IMoniker *, LPCLSID
+ , LPFORMATETC, LPSTGMEDIUM);
+STDAPI_(void) INOLE_RegisterAsRunning(IUnknown *, IMoniker *
+ , DWORD, LPDWORD);
+STDAPI_(void) INOLE_RevokeAsRunning(LPDWORD);
+STDAPI_(void) INOLE_NoteChangeTime(DWORD, FILETIME *, LPTSTR);
+
+
+
+/*
+ * These are for ANSI compilations on Win32. Source code assumes
+ * a Win32 Unicode environment (or Win16 Ansi). These macros
+ * route Win32 ANSI compiled functions to wrappers which do the
+ * proper Unicode conversion.
+ */
+
+
+#ifdef WIN32ANSI
+STDAPI INOLE_ConvertStringToANSI(LPCWSTR, LPSTR *);
+STDAPI INOLE_StringFromCLSID(REFCLSID, LPSTR *);
+STDAPI INOLE_StringFromGUID2(REFGUID, LPSTR, int);
+STDAPI INOLE_ProgIDFromCLSID(REFCLSID, LPSTR *);
+
+STDAPI INOLE_ReadFmtUserTypeStg(IStorage *, CLIPFORMAT *, LPSTR *);
+STDAPI INOLE_WriteFmtUserTypeStg(IStorage *, CLIPFORMAT, LPSTR);
+
+STDAPI INOLE_StgIsStorageFile(LPCSTR);
+STDAPI INOLE_StgCreateDocfile(LPCSTR, DWORD, DWORD, IStorage **);
+STDAPI INOLE_StgOpenStorage(LPCSTR, IStorage *, DWORD, SNB
+ , DWORD, IStorage **);
+
+
+STDAPI INOLE_CreateFileMoniker(LPCSTR, LPMONIKER *);
+STDAPI INOLE_CreateItemMoniker(LPCSTR, LPCSTR, LPMONIKER *);
+STDAPI INOLE_MkParseDisplayName(LPBC, LPCSTR, ULONG *, LPMONIKER *);
+
+STDAPI INOLE_OleCreateLinkToFile(LPCSTR, REFIID, DWORD, LPFORMATETC
+ , LPOLECLIENTSITE, LPSTORAGE, LPVOID *);
+STDAPI INOLE_OleCreateFromFile(REFCLSID, LPCSTR, REFIID
+ , DWORD, LPFORMATETC, LPOLECLIENTSITE, LPSTORAGE, LPVOID *);
+
+
+#ifndef NOMACROREDIRECT
+#undef StringFromCLSID
+#define StringFromCLSID(c, pp) INOLE_StringFromCLSID(c, pp)
+
+#undef StringFromGUID2
+#define StringFromGUID2(r, p, i) INOLE_StringFromGUID2(r, p, i)
+
+#undef ProgIDFromCLSID
+#define ProgIDFromCLSID(c, pp) INOLE_ProgIDFromCLSID(c, pp)
+
+#undef ReadFmtUserTypeStg
+#define ReadFmtUserTypeStg(p, c, s) INOLE_ReadFmtUserTypeStg(p, c, s)
+
+#undef WriteFmtUserTypeStg
+#define WriteFmtUserTypeStg(p, c, s) INOLE_WriteFmtUserTypeStg(p, c, s)
+
+#undef StgIsStorageFile
+#define StgIsStorageFile(s) INOLE_StgIsStorageFile(s)
+
+#undef StgCreateDocfile
+#define StgCreateDocfile(a, b, c, d) INOLE_StgCreateDocfile(a, b, c, d)
+
+#undef StgOpenStorage
+#define StgOpenStorage(a,b,c,d,e,f) INOLE_StgOpenStorage(a,b,c,d,e,f)
+
+#undef CreateFileMoniker
+#define CreateFileMoniker(p, i) INOLE_CreateFileMoniker(p, i)
+
+#undef CreateItemMoniker
+#define CreateItemMoniker(p1, p2, i) INOLE_CreateItemMoniker(p1, p2, i)
+
+#undef MkParseDisplayName
+#define MkParseDisplayName(b, p, u, i) INOLE_MkParseDisplayName(b, p, u, i)
+
+#undef OleCreateLinkToFile
+#define OleCreateLinkToFile(s, i, d, fe, cs, st, pv) INOLE_OleCreateLinkToFile(s, i, d, fe, cs, st, pv)
+
+#undef OleCreateFromFile
+#define OleCreateFromFile(c, s, i, d, fe, cs, st, pv) INOLE_OleCreateFromFile(c, s, i, d, fe, cs, st, pv)
+
+
+#endif
+
+#endif
+
+//Versioning.
+#define VERSIONMAJOR 2
+#define VERSIONMINOR 0
+#define VERSIONCURRENT 0x00020000
+
+#define HIMETRIC_PER_INCH 2540
+#define LOMETRIC_PER_INCH 254
+#define LOMETRIC_BORDER 60 //Border around page
+
+#define CREATE_FAILED 0
+#define CREATE_GRAPHICONLY 1
+
+//State flags
+//CHAPTER24MOD
+//Switched #defines to an enum
+enum
+ {
+ TENANTSTATE_DEFAULT =0x00000000,
+ TENANTSTATE_SELECTED=0x00000001,
+ TENANTSTATE_OPEN =0x00000002,
+ TENANTSTATE_SHOWTYPE=0x00000004,
+
+ //New ones for controls.
+ TENANTSTATE_CONTROL =0x00000100,
+ TENANTSTATE_EVENTS =0x00000200,
+ TENANTSTATE_BUTTON =0x00000400,
+ TENANTSTATE_LABEL =0x00000800,
+ TENANTSTATE_DEFBUTTON =0x00001000,
+ TENANTSTATE_CANCELBUTTON=0x00002000
+ };
+
+//To mask off non-control flags
+#define STATEMASK_CONTROLS 0xFFFFFF00
+
+
+
+/*
+ * Structures to save with the document describing the device
+ * configuration and pages that we have. This is followed by
+ * a list of DWORD IDs for the individual pages.
+ */
+
+typedef struct tagDEVICECONFIG
+ {
+ DWORD cb; //Size of structure
+ TCHAR szDriver[CCHDEVICENAME];
+ TCHAR szDevice[CCHDEVICENAME];
+ TCHAR szPort[CCHDEVICENAME];
+ DWORD cbDevMode; //Size of actual DEVMODE
+ DEVMODE dm; //Variable
+ } DEVICECONFIG, *PDEVICECONFIG;
+
+//Offset to cbDevMode
+#define CBSEEKOFFSETCBDEVMODE (sizeof(DWORD) \
+ +(3*CCHDEVICENAME*sizeof(TCHAR)))
+
+//Combined OLE and Patron device structures.
+typedef struct tagCOMBINEDEVICE
+ {
+ DVTARGETDEVICE td;
+ DEVICECONFIG dc;
+ } COMBINEBDEVICE, *PCOMBINEDEVICE;
+
+
+
+void RectConvertMappings(LPRECT, HDC, BOOL);
+
+
+//CHAPTER24MOD
+
+
+#ifdef WIN32
+#define PROP_POINTER TEXT("Pointer")
+#else
+#define PROP_SELECTOR "Selector"
+#define PROP_OFFSET "Offset"
+#endif
+
+//End CHAPTER24MOD
+
+BOOL ObjectEventsIID(LPUNKNOWN pObj, IID *piid);
+BOOL InterfaceConnect(LPUNKNOWN pObj, REFIID riid
+ , LPUNKNOWN pIUnknownSink, LPDWORD pdwConn);
+BOOL InterfaceDisconnect(LPUNKNOWN pObj, REFIID riid
+ , LPDWORD pdwConn);
+BOOL ObjectTypeInfo(LPUNKNOWN pObj, LPTYPEINFO *ppITypeInfo);
+BOOL ObjectTypeInfoEvents(LPUNKNOWN pObj, LPTYPEINFO *ppITypeInfo);
+BOOL ObjectEventsIID(LPUNKNOWN pObj, IID *piid);
+
+#define HIMETRIC_PER_INCH 2540 //Number HIMETRIC units per inch
+#define PTS_PER_INCH 72 //Number points (font size) per inch
+
+#define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
+#define MAP_LOGHIM_TO_PIX(x,ppli) MulDiv((ppli), (x), HIMETRIC_PER_INCH)
+
+//Useful macros.
+#define SETFormatEtc(fe, cf, asp, td, med, li) \
+ {\
+ (fe).cfFormat=cf;\
+ (fe).dwAspect=asp;\
+ (fe).ptd=td;\
+ (fe).tymed=med;\
+ (fe).lindex=li;\
+ }
+
+STDAPI_(void) XformRectInHimetricToPixels(HDC hDC, LPRECT prcHiMetric
+ , LPRECT prcPix);
+
+#endif //_INOLE_H_
diff --git a/iup/srcole/tOleClientSite.cpp b/iup/srcole/tOleClientSite.cpp
new file mode 100755
index 0000000..314b172
--- /dev/null
+++ b/iup/srcole/tOleClientSite.cpp
@@ -0,0 +1,148 @@
+//////////////////////////////////////////////////////////////////////
+//
+// tOleClientSite.cpp: implementation of the tOleClientSite class.
+//
+//////////////////////////////////////////////////////////////////////
+
+
+#include <windows.h>
+#include <assert.h>
+
+#include "tOleClientSite.h"
+#include "tOleHandler.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+tOleClientSite::tOleClientSite(LPUNKNOWN pUnkOuter,
+ tOleHandler *olehandler)
+{
+ m_cRef=0;
+ m_pUnkOuter = pUnkOuter;
+ handler = olehandler;
+ return;
+}
+
+tOleClientSite::~tOleClientSite()
+{
+
+}
+
+STDMETHODIMP tOleClientSite::QueryInterface(REFIID riid,
+ LPVOID *ppv)
+{
+ return m_pUnkOuter->QueryInterface(riid, ppv);
+}
+
+
+STDMETHODIMP_(ULONG) tOleClientSite::AddRef(void)
+{
+ ++m_cRef;
+ return m_pUnkOuter->AddRef();
+}
+
+STDMETHODIMP_(ULONG) tOleClientSite::Release(void)
+{
+ --m_cRef;
+ return m_pUnkOuter->Release();
+}
+
+STDMETHODIMP tOleClientSite::SaveObject(void)
+{
+ // persistencia ainda nao suportada
+ return E_FAIL;
+}
+
+
+STDMETHODIMP tOleClientSite::GetMoniker(DWORD dwAssign,
+ DWORD dwWhich,
+ LPMONIKER *ppmk)
+{
+ // Linking nao suportado
+ return E_FAIL;
+}
+
+
+STDMETHODIMP tOleClientSite::GetContainer(LPOLECONTAINER * ppContainer)
+{
+
+ *ppContainer=NULL;
+
+ return E_NOINTERFACE;
+}
+
+
+/*
+ * tOleClientSite::ShowObject
+ *
+ * Purpose:
+ * Tells the container to bring the object fully into view as much
+ * as possible, that is, scroll the document.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT Standard.
+ */
+
+STDMETHODIMP tOleClientSite::ShowObject(void)
+{
+ return NOERROR;
+}
+
+
+STDMETHODIMP tOleClientSite::OnShowWindow(BOOL fShow)
+{
+ return NOERROR;
+}
+
+/*
+ * tOleClientSite::RequestNewObjectLayout
+ *
+ * Purpose:
+ * Called when the object would like to have its layout
+ * reinitialized. This is used by OLE Controls.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT Standard.
+ */
+
+STDMETHODIMP tOleClientSite::RequestNewObjectLayout(void)
+{
+ RECT rc, rcT;
+ SIZEL szl;
+ HRESULT hr;
+
+ /*
+ * This function is called by a control that is not in-place
+ * active or UI active and therefore doesn't have our
+ * IOleInPlaceSite interface in which to call OnPosRectChange.
+ * Therefore we do pretty much the same thing we do in that
+ * function although we ask the control for the size it wants.
+ */
+
+ if (!handler->m_pIViewObject2)
+ return E_FAIL;
+
+ //Get the size from the control
+ hr=handler->m_pIViewObject2->GetExtent(handler->m_fe.dwAspect, -1, NULL, &szl);
+ if (FAILED(hr))
+ return hr;
+
+ //Add these extents to the existing tenant position.
+ SetRect(&rcT, 0, 0, szl.cx*10, -szl.cy*10);
+ RectConvertMappings(&rcT, NULL, TRUE);
+
+ rc=handler->m_rcPos;
+ rc.right=rc.left+rcT.right;
+ rc.bottom=rc.top+rcT.bottom;
+
+ handler->UpdateInPlaceObjectRects(&rc, FALSE);
+ return NOERROR;
+}
+
diff --git a/iup/srcole/tOleClientSite.h b/iup/srcole/tOleClientSite.h
new file mode 100755
index 0000000..1525b9e
--- /dev/null
+++ b/iup/srcole/tOleClientSite.h
@@ -0,0 +1,40 @@
+// tOleClientSite.h: interface for the tOleClientSite class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_TOLECLIENTSITE_H__49B97C0A_8DEB_11D3_A906_0004ACE655F9__INCLUDED_)
+#define AFX_TOLECLIENTSITE_H__49B97C0A_8DEB_11D3_A906_0004ACE655F9__INCLUDED_
+
+#if _MSC_VER >= 1000
+#pragma once
+#endif // _MSC_VER >= 1000
+
+#include <windows.h>
+
+class tOleHandler;
+
+class tOleClientSite : public IOleClientSite
+{
+public:
+ tOleClientSite(LPUNKNOWN pUnkOuter, tOleHandler *olehandler);
+ virtual ~tOleClientSite();
+
+ STDMETHODIMP QueryInterface(REFIID, LPVOID *);
+ STDMETHODIMP_(ULONG) AddRef(void);
+ STDMETHODIMP_(ULONG) Release(void);
+
+ STDMETHODIMP SaveObject(void);
+ STDMETHODIMP GetMoniker(DWORD, DWORD, LPMONIKER *);
+ STDMETHODIMP GetContainer(LPOLECONTAINER *);
+ STDMETHODIMP ShowObject(void);
+ STDMETHODIMP OnShowWindow(BOOL);
+ STDMETHODIMP RequestNewObjectLayout(void);
+
+protected:
+ tOleHandler * handler;
+ ULONG m_cRef;
+ //class CTenant *m_pTen;
+ LPUNKNOWN m_pUnkOuter;
+};
+
+#endif // !defined(AFX_TOLECLIENTSITE_H__49B97C0A_8DEB_11D3_A906_0004ACE655F9__INCLUDED_)
diff --git a/iup/srcole/tOleControlSite.cpp b/iup/srcole/tOleControlSite.cpp
new file mode 100755
index 0000000..71f3519
--- /dev/null
+++ b/iup/srcole/tOleControlSite.cpp
@@ -0,0 +1,301 @@
+// tOleControlSite.cpp: implementation of the tOleControlSite class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "tOleControlSite.h"
+#include "tOleHandler.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+/*
+ * tOleControlSite::tOleControlSite
+ * tOleControlSite::~tOleControlSite
+ *
+ * Parameters (Constructor):
+ * pTen PCTenant of the object we're in.
+ * pUnkOuter LPUNKNOWN to which we delegate.
+ */
+
+tOleControlSite::tOleControlSite(tOleHandler *pTen
+ , LPUNKNOWN pUnkOuter)
+ {
+ m_cRef=0;
+ m_pTen=pTen;
+ m_pUnkOuter=pUnkOuter;
+ return;
+ }
+
+tOleControlSite::~tOleControlSite(void)
+ {
+ return;
+ }
+
+
+
+
+/*
+ * tOleControlSite::QueryInterface
+ * tOleControlSite::AddRef
+ * tOleControlSite::Release
+ *
+ * Purpose:
+ * Delegating IUnknown members for tOleControlSite.
+ */
+
+STDMETHODIMP tOleControlSite::QueryInterface(REFIID riid
+ , LPVOID *ppv)
+ {
+ return m_pUnkOuter->QueryInterface(riid, ppv);
+ }
+
+
+STDMETHODIMP_(ULONG) tOleControlSite::AddRef(void)
+ {
+ ++m_cRef;
+ return m_pUnkOuter->AddRef();
+ }
+
+STDMETHODIMP_(ULONG) tOleControlSite::Release(void)
+ {
+ --m_cRef;
+ return m_pUnkOuter->Release();
+ }
+
+
+
+
+
+/*
+ * tOleControlSite::OnControlInfoChanged
+ *
+ * Purpose:
+ * Informs the site that the CONTROLINFO for the control has
+ * changed and we thus need to reload the data.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleControlSite::OnControlInfoChanged(void)
+ {
+ //We also update our "have info" flag here.
+ if(m_pTen->m_pIOleControl != NULL)
+ {
+ m_pTen->m_fHaveControlInfo=SUCCEEDED(m_pTen->m_pIOleControl
+ ->GetControlInfo(&m_pTen->m_ctrlInfo));
+ }
+
+ return NOERROR;
+ }
+
+
+
+
+
+/*
+ * tOleControlSite::LockInPlaceActive
+ *
+ * Purpose:
+ * Forces the container to keep this control in-place active
+ * (but not UI active) regardless of other considerations, or
+ * removes this lock.
+ *
+ * Parameters:
+ * fLock BOOL indicating to lock (TRUE) or unlock (FALSE)
+ * in-place activation.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleControlSite::LockInPlaceActive(BOOL fLock)
+ {
+ if (fLock)
+ m_pTen->m_cLockInPlace++;
+ else
+ {
+ if (0==--m_pTen->m_cLockInPlace)
+ {
+ //If there's a pending deactivate, do it now.
+ if (m_pTen->m_fPendingDeactivate)
+ m_pTen->DeactivateInPlaceObject(TRUE);
+ }
+ }
+
+ return NOERROR;
+ }
+
+
+
+
+
+/*
+ * tOleControlSite::GetExtendedControl
+ *
+ * Purpose:
+ * Returns a pointer to the container's extended control that wraps
+ * the actual control in this site, if one exists.
+ *
+ * Parameters:
+ * ppDispatch LPDISPATCH * in which to return the pointer
+ * to the extended control's IDispatch interface.
+ *
+ * Return Value:
+ * HRESULT NOERROR or a general error value.
+ */
+
+STDMETHODIMP tOleControlSite::GetExtendedControl(LPDISPATCH
+ * ppDispatch)
+ {
+ *ppDispatch=NULL;
+ return ResultFromScode(E_NOTIMPL);
+ }
+
+
+
+
+
+
+/*
+ * tOleControlSite::TransformCoords
+ *
+ * Purpose:
+ * Converts coordinates in HIMETRIC units into those used by the
+ * container.
+ *
+ * Parameters:
+ * pptlHiMet POINTL * containing either the coordinates to
+ * transform to container or where to store the
+ * transformed container coordinates.
+ * pptlCont POINTF * containing the container coordinates.
+ * dwFlags DWORD containing instructional flags.
+ *
+ * Return Value:
+ * HRESULT NOERROR or a general error value.
+ */
+
+STDMETHODIMP tOleControlSite::TransformCoords(POINTL *pptlHiMet
+ , POINTF *pptlCont, DWORD dwFlags)
+ {
+ if (NULL==pptlHiMet || NULL==pptlCont)
+ return ResultFromScode(E_POINTER);
+
+ /*
+ * Convert coordinates. We use MM_LOMETRIC which means that
+ * to convert from HIMETRIC we divide by 10 and negate the y
+ * coordinate. Conversion to HIMETRIC means negate the y
+ * and multiply by 10. Note that size and position are
+ * considered the same thing, that is, we don't differentiate
+ * the two.
+ */
+
+ if (XFORMCOORDS_HIMETRICTOCONTAINER & dwFlags)
+ {
+ pptlCont->x=(float)(pptlHiMet->x/10);
+ pptlCont->y=(float)-(pptlHiMet->y/10);
+ }
+ else
+ {
+ pptlHiMet->x=(long)(pptlCont->x*10);
+ pptlHiMet->y=(long)-(pptlCont->y*10);
+ }
+
+ return NOERROR;
+ }
+
+
+
+
+
+/*
+ * tOleControlSite::TranslateAccelerator
+ *
+ * Purpose:
+ * Instructs the container to translate a keyboard accelerator
+ * message that the control has picked up instead.
+ *
+ * Parameters:
+ * pMsg LPMSG to the message to translate.
+ * grfModifiers DWORD flags with additional instructions.
+ *
+ * Return Value:
+ * HRESULT NOERROR or a general error value.
+ */
+
+STDMETHODIMP tOleControlSite::TranslateAccelerator(LPMSG pMsg
+ , DWORD grfModifiers)
+ {
+ /*
+ * The control has picked up a keystroke through its own
+ * TranslateAccelerator and is now giving us the change to
+ * play with it. Currently there are no flags for
+ * grfModifiers, so we ignore them. Especially since
+ * we have nothing to do here ourselves anyway.
+ */
+ return ResultFromScode(S_FALSE);
+ }
+
+
+
+
+/*
+ * tOleControlSite::OnFocus
+ *
+ * Purpose:
+ * Informs the container that focus has either been lost or
+ * gained in the control.
+ *
+ * Parameters:
+ * fGotFocus BOOL indicating that the control gained (TRUE)
+ * or lost (FALSE) focus.
+ *
+ * Return Value:
+ * HRESULT NOERROR or a general error value.
+ */
+
+STDMETHODIMP tOleControlSite::OnFocus(BOOL fGotFocus)
+ {
+ /*
+ * Patron doesn't do this, but to handle the default
+ * and cancel buttons properly, we normally process RETURN
+ * and ESC accelerators to press the right button.
+ * This behavior must be disabled when the control with
+ * the focus has either CTRLINFO_EATS_RETURN or
+ * CTRLINFO_EATS_ESCAPE set. We tell the frame as
+ * we need to when a new control gets the focus. We
+ * do nothing when a control loses the focus.
+ */
+ return NOERROR;
+ }
+
+
+
+/*
+ * tOleControlSite::ShowPropertyFrame
+ *
+ * Purpose:
+ * Instructs the container to show the property frame if
+ * this is an extended object and requires its own property
+ * pages.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT NOERROR or a general error value.
+ */
+
+STDMETHODIMP tOleControlSite::ShowPropertyFrame(void)
+ {
+ /*
+ * Returning an error here means that the container has
+ * no property pages itself for the control, so the
+ * control should display its own.
+ */
+ return ResultFromScode(E_NOTIMPL);
+ }
diff --git a/iup/srcole/tOleControlSite.h b/iup/srcole/tOleControlSite.h
new file mode 100755
index 0000000..8e805d3
--- /dev/null
+++ b/iup/srcole/tOleControlSite.h
@@ -0,0 +1,39 @@
+// tOleControlSite.h: interface for the tOleControlSite class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_TOLECONTROLSITE_H__37A5ADEC_91FB_11D3_A906_0004AC252223__INCLUDED_)
+#define AFX_TOLECONTROLSITE_H__37A5ADEC_91FB_11D3_A906_0004AC252223__INCLUDED_
+
+#if _MSC_VER >= 1000
+#pragma once
+#endif // _MSC_VER >= 1000
+
+#include <windows.h>
+#include <olectl.h>
+
+class tOleControlSite : public IOleControlSite
+{
+ protected:
+ ULONG m_cRef;
+ class tOleHandler *m_pTen;
+ LPUNKNOWN m_pUnkOuter;
+
+ public:
+ tOleControlSite(class tOleHandler *, LPUNKNOWN);
+ ~tOleControlSite(void);
+
+ STDMETHODIMP QueryInterface(REFIID, LPVOID *);
+ STDMETHODIMP_(ULONG) AddRef(void);
+ STDMETHODIMP_(ULONG) Release(void);
+
+ STDMETHODIMP OnControlInfoChanged(void);
+ STDMETHODIMP LockInPlaceActive(BOOL);
+ STDMETHODIMP GetExtendedControl(LPDISPATCH *);
+ STDMETHODIMP TransformCoords(POINTL *, POINTF *, DWORD);
+ STDMETHODIMP TranslateAccelerator(LPMSG, DWORD);
+ STDMETHODIMP OnFocus(BOOL);
+ STDMETHODIMP ShowPropertyFrame(void);
+};
+
+#endif // !defined(AFX_TOLECONTROLSITE_H__37A5ADEC_91FB_11D3_A906_0004AC252223__INCLUDED_)
diff --git a/iup/srcole/tOleHandler.cpp b/iup/srcole/tOleHandler.cpp
new file mode 100755
index 0000000..688ba30
--- /dev/null
+++ b/iup/srcole/tOleHandler.cpp
@@ -0,0 +1,1123 @@
+// tOleHandler.cpp: implementation of the tOleHandler class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include <ole2.h>
+#include <assert.h>
+
+#ifndef _OLE2_H_
+#define _OLE2_H_
+#endif
+
+#include "tOleHandler.h"
+#include "tDispatch.h"
+
+/*
+ * tOleHandler::tOleHandler
+ * tOleHandler::~tOleHandler
+ *
+ */
+
+tOleHandler::tOleHandler()
+{
+ natural_width = 0;
+ natural_height = 0;
+
+ m_hWnd=NULL;
+
+ m_fInitialized=0;
+ m_cOpens=0;
+
+ m_pObj=NULL;
+ m_clsID=CLSID_NULL;
+ m_fSetExtent=FALSE;
+
+ m_cRef=0;
+ m_pIOleObject=NULL;
+ m_pIViewObject2=NULL;
+ m_grfMisc=0;
+
+ m_rcl.right = m_rcl.left = 0;
+ m_rcl.top = m_rcl.bottom = 0;
+
+ m_pImpIOleClientSite=NULL;
+
+ m_fRepaintEnabled=TRUE;
+
+
+ m_pImpIOleIPSite=NULL;
+ m_pIOleIPObject=NULL;
+ m_rcPos.left=-1;
+ m_fInRectSet=FALSE;
+
+ //CHAPTER24MOD
+ m_pImpIOleControlSite=NULL;
+ m_pImpIDispatch=NULL;
+
+ m_pIOleControl=NULL;
+
+ m_fHaveControlInfo=FALSE;
+ m_cLockInPlace=0;
+ m_fPendingDeactivate=FALSE;
+ //End CHAPTER24MOD
+
+ return;
+}
+
+
+tOleHandler::~tOleHandler(void)
+ {
+
+ //Object pointers cleaned up in Close.
+
+ //CHAPTER24MOD
+
+ DeleteInterfaceImp(m_pImpIOleControlSite);
+ DeleteInterfaceImp(m_pImpIDispatch);
+
+ //End CHAPTER24MOD
+
+ DeleteInterfaceImp(m_pImpIOleIPSite);
+ DeleteInterfaceImp(m_pImpIOleClientSite);
+ return;
+ }
+
+
+
+
+/*
+ * tOleHandler::QueryInterface
+ * tOleHandler::AddRef
+ * tOleHandler::Release
+ *
+ * Purpose:
+ * IUnknown members for tOleHandler object.
+ */
+
+STDMETHODIMP tOleHandler::QueryInterface(REFIID riid, LPVOID *ppv)
+ {
+ *ppv=NULL;
+
+ if (IID_IUnknown==riid)
+ *ppv=this;
+
+ if (IID_IOleClientSite==riid)
+ *ppv=m_pImpIOleClientSite;
+
+ if (IID_IOleWindow==riid || IID_IOleInPlaceSite==riid)
+ *ppv=m_pImpIOleIPSite;
+
+ //CHAPTER24MOD
+ if (IID_IOleControlSite==riid)
+ *ppv=m_pImpIOleControlSite;
+
+ //Queries for IDispatch return the ambient properties interface
+ if (IID_IDispatch==riid)
+ *ppv=m_pImpIDispatch;
+ //End CHAPTER24MOD
+
+ if (NULL!=*ppv)
+ {
+ ((LPUNKNOWN)*ppv)->AddRef();
+ return NOERROR;
+ }
+
+ return ResultFromScode(E_NOINTERFACE);
+ }
+
+
+STDMETHODIMP_(ULONG) tOleHandler::AddRef(void)
+ {
+ return ++m_cRef;
+ }
+
+STDMETHODIMP_(ULONG) tOleHandler::Release(void)
+ {
+ if (0!=--m_cRef)
+ return m_cRef;
+
+ delete this;
+ return 0;
+ }
+
+
+
+
+
+
+/*
+ * tOleHandler::Create
+ *
+ * Purpose:
+ * Creates a new tenant of the given CLSID, which can be either a
+ * static bitmap or metafile or any compound document object.
+ *
+ * Parameters:
+ * tType TENANTTYPE to create, either a static metafile,
+ * bitmap, or some kind of compound document object
+ * This determines which OleCreate* call we use.
+ * pvType LPVOID providing the relevant pointer from which
+ * to create the tenant, depending on iType.
+ * pFE LPFORMATETC specifying the type of renderings
+ * to use.
+ * pptl PPOINTL in which we store offset coordinates.
+ * pszl LPSIZEL where this object should store its
+ * lometric extents.
+ * pIStorage LPSTORAGE of the page we live in. We have to
+ * create another storage in this for the tenant.
+ * ppo PPATRONOBJECT containing placement data.
+ * dwData DWORD with extra data, sensitive to iType.
+ *
+ * Return Value:
+ * UINT A CREATE_* value depending on what we
+ * actually do.
+ */
+
+UINT tOleHandler::Create(LPVOID pvType)
+ {
+ HRESULT hr;
+ LPUNKNOWN pObj;
+ UINT uRet=CREATE_GRAPHICONLY;
+ DWORD dwMode=STGM_READWRITE
+ | STGM_SHARE_EXCLUSIVE
+ | STGM_DELETEONRELEASE;
+
+
+ IPersistStorage *persist_storage = NULL;
+
+ StgCreateDocfile(NULL, dwMode, 0, &m_pIStorage);
+
+ if(m_pIStorage == NULL)
+ return CREATE_FAILED;
+
+ if (NULL==pvType)
+ return CREATE_FAILED;
+
+ hr=ResultFromScode(E_FAIL);
+
+ Open(NULL);
+
+ //CHAPTER24MOD
+ /*
+ * The OLE Control specifications mention that a
+ * a control might implement IPersistStream[Init]
+ * instead of IPersistStorage. In that case you
+ * cannot use OleCreate on a control but must rather
+ * use CoCreateInstance since OleCreate assumes
+ * that IPersistStorage is available. With a control,
+ * you would have to create the object first, then
+ * check if OLEMISC_SETCLIENTSITEFIRST is set, then
+ * send it your IOleClientSite first. Then you check
+ * for IPersistStorage and failing that, try
+ * IPersistStream[Init].
+ *
+ * For simplicity we'll assume storage-based
+ * controls in this sample.
+ */
+ //End CHAPTER24MOD
+
+ hr = CoCreateInstance(*((LPCLSID)pvType), NULL,
+ CLSCTX_ALL, IID_IUnknown, (LPVOID *)&pObj);
+
+ if(FAILED(hr))
+ return CREATE_FAILED;
+
+ if(pObj->QueryInterface(IID_IPersistStorage, (void **) &persist_storage) != S_OK)
+ return CREATE_FAILED;
+
+ //We need an IOleObject most of the time, so get one here.
+ m_pIOleObject=NULL;
+ hr = pObj->QueryInterface(IID_IOleObject, (LPVOID*)&m_pIOleObject);
+
+ if(FAILED(hr))
+ return CREATE_FAILED;
+
+ // seta o client site
+ m_pIOleObject->SetClientSite(m_pImpIOleClientSite);
+
+ // inicializa o objeto
+ hr = persist_storage->InitNew(m_pIStorage);
+
+ if(FAILED(hr))
+ return CREATE_FAILED;
+
+
+ //We don't get the size if PatronObject data was seen already.
+ if (!ObjectInitialize(pObj))
+ {
+ return CREATE_FAILED;
+ }
+
+ SIZEL szl;
+
+ hr=ResultFromScode(E_FAIL);
+
+ CalcNaturalSize();
+
+ //CHAPTER24MOD
+ //Make sure this happens
+ /*if ((OLEMISC_ACTIVATEWHENVISIBLE & m_grfMisc))
+ Activate(OLEIVERB_INPLACEACTIVATE, NULL);*/
+ //End CHAPTER24MOD
+
+ return uRet;
+ }
+
+
+
+
+
+
+
+/*
+ * tOleHandler::ObjectInitialize
+ * (Protected)
+ *
+ * Purpose:
+ * Performs operations necessary after creating an object or
+ * reloading one from storage.
+ *
+ * Parameters:
+ * pObj LPUNKNOWN of the object in this tenant.
+ * pFE LPFORMATETC describing the graphic here.
+ * dwData DWORD extra data. If pFE->dwAspect==
+ * DVASPECT_ICON then this is the iconic metafile.
+ *
+ * Return Value:
+ * BOOL TRUE if the function succeeded, FALSE otherwise.
+ */
+
+BOOL tOleHandler::ObjectInitialize(LPUNKNOWN pObj)
+ {
+ HRESULT hr;
+ FORMATETC fe;
+
+ SETDefFormatEtc(fe, 0, TYMED_NULL);
+ LPFORMATETC pFE = &fe;
+
+
+ if (NULL==pObj || NULL==pFE)
+ return FALSE;
+
+ m_pObj=pObj;
+ m_fe=*pFE;
+ m_fe.ptd=NULL;
+ m_dwState=TENANTSTATE_DEFAULT;
+
+ m_pIViewObject2=NULL;
+ hr=pObj->QueryInterface(IID_IViewObject2
+ , (LPVOID*)&m_pIViewObject2);
+
+ if (FAILED(hr))
+ return FALSE;
+
+ /*
+ * Get the MiscStatus bits and check for OLEMISC_ONLYICONIC.
+ * If set, force dwAspect in m_fe to DVASPECT_ICON so we
+ * remember to draw it properly and do extents right.
+ */
+ m_pIOleObject->GetMiscStatus(m_fe.dwAspect, &m_grfMisc);
+
+
+ //CHAPTER24MOD
+ //Run the object if it says to do so
+ if (OLEMISC_ALWAYSRUN & m_grfMisc)
+ OleRun(pObj);
+ //End CHAPTER24MOD
+
+
+
+ //CHAPTER24MOD
+ //Go try initializing control-related things.
+ ControlInitialize();
+ //End CHAPTER24MOD
+
+ return TRUE;
+ }
+
+
+
+
+/*
+ * tOleHandler::Open
+ *
+ * Purpose:
+ * Retrieves the IStorage associated with this tenant. The
+ * IStorage is owned by the tenant and thus the tenant always
+ * holds a reference count.
+ *
+ * If the storage is already open for this tenant, then this
+ * function will AddRef it; therefore the caller must always
+ * match an Open with a Close.
+ *
+ * Parameters:
+ * pIStorage LPSTORAGE above this tenant (which has its
+ * own storage).
+ *
+ * Return Value:
+ * BOOL TRUE if opening succeeds, FALSE otherwise.
+ */
+
+BOOL tOleHandler::Open(LPSTORAGE pIStorage)
+ {
+ HRESULT hr=NOERROR;
+ DWORD dwMode=STGM_TRANSACTED | STGM_READWRITE
+ | STGM_SHARE_EXCLUSIVE;
+
+
+ //Create these if we don't have them already.
+ if (NULL==m_pImpIOleClientSite)
+ {
+ m_pImpIOleClientSite=new tOleClientSite(this, this);
+ m_pImpIOleIPSite=new tOleInPlaceSite(this, this);
+
+ //CHAPTER24MOD
+ m_pImpIOleControlSite=new tOleControlSite(this, this);
+ m_pImpIDispatch=new tDispatch(this, this);
+
+ if (NULL==m_pImpIOleClientSite
+ || NULL==m_pImpIOleIPSite || NULL==m_pImpIOleControlSite
+ || NULL==m_pImpIDispatch)
+ return FALSE;
+ //End CHAPTER24MOD
+ }
+
+ return TRUE;
+ }
+
+
+
+
+/*
+ * tOleHandler::Close
+ *
+ * Purpose:
+ * Possibly commits the storage, then releases it reversing the
+ * reference count from Open. If the reference on the storage
+ * goes to zero, the storage is forgotten. However, the object we
+ * contain is still held and as long as it's active the storage
+ * remains alive.
+ *
+ * Parameters:
+ * fCommit BOOL indicating if we're to commit.
+ *
+ * Return Value:
+ * None
+ */
+
+void tOleHandler::Close(BOOL fCommit)
+ {
+ /*
+ * We can't use a zero reference count to know when to NULL
+ * this since other things might have AddRef'd the storage.
+ */
+ //OnInPlaceDeactivate releases this pointer.
+ if (NULL!=m_pIOleIPObject)
+ m_pIOleIPObject->InPlaceDeactivate();
+
+ //Close the object saving if necessary
+ if (NULL!=m_pIOleObject)
+ {
+ m_pIOleObject->Close(OLECLOSE_SAVEIFDIRTY);
+ ReleaseInterface(m_pIOleObject);
+ }
+
+ //Release all other held pointers
+ //CHAPTER24MOD
+ ReleaseInterface(m_pIOleControl);
+
+ //End CHAPTER24MOD
+
+ //Release all other held pointers
+ if (NULL!=m_pIViewObject2)
+ {
+ m_pIViewObject2->SetAdvise(m_fe.dwAspect, 0, NULL);
+ ReleaseInterface(m_pIViewObject2);
+ }
+
+ //We know we only hold one ref from Create or Load
+ ReleaseInterface(m_pObj);
+
+ return;
+ }
+
+
+/*
+ * tOleHandler::Activate
+ *
+ * Purpose:
+ * Activates a verb on the object living in the tenant. Does
+ * nothing for static objects.
+ *
+ * Parameters:
+ * iVerb LONG of the verb to execute.
+ * pMSG LPMSG to the message causing the invocation.
+ *
+ * Return Value:
+ * BOOL TRUE if the object changed due to this verb
+ * execution.
+ */
+
+BOOL tOleHandler::Activate(LONG iVerb, LPMSG pMSG)
+ {
+ RECT rc, rcH;
+ SIZEL szl;
+
+ //Can't activate statics.
+/* if (TENANTTYPE_STATIC==m_tType || NULL==m_pIOleObject)
+ {
+ MessageBeep(0);
+ return FALSE;
+ }*/
+
+ RECTFROMRECTL(rc, m_rcl);
+ RectConvertMappings(&rc, NULL, TRUE);
+ XformRectInPixelsToHimetric(NULL, &rc, &rcH);
+
+ //Get the server running first, then do a SetExtent, then show it
+ OleRun(m_pIOleObject);
+
+ if (m_fSetExtent)
+ {
+ SETSIZEL(szl, rcH.right-rcH.left, rcH.top-rcH.bottom);
+ m_pIOleObject->SetExtent(m_fe.dwAspect, &szl);
+ m_fSetExtent=FALSE;
+ }
+
+ //CHAPTER24MOD
+ /*
+ * If we have a pending deactivation, but we're activating
+ * again, clear the pending flag.
+ */
+ if (OLEIVERB_UIACTIVATE==iVerb
+ || OLEIVERB_INPLACEACTIVATE==iVerb)
+ m_fPendingDeactivate=FALSE;
+ //End CHAPTER24MOD
+
+ m_pIOleObject->DoVerb(iVerb, pMSG, m_pImpIOleClientSite, 0
+ , m_hWnd, &rcH);
+
+ //If object changes, IAdviseSink::OnViewChange will see it.
+ return FALSE;
+ }
+
+
+
+
+
+
+/*
+ * tOleHandler::ObjectGet
+ *
+ * Purpose:
+ * Retrieves the LPUNKNOWN of the object in use by this tenant
+ *
+ * Parameters:
+ * ppUnk LPUNKNOWN * in which to return the object
+ * pointer.
+ *
+ * Return Value:
+ * None
+ */
+
+void tOleHandler::ObjectGet(LPUNKNOWN *ppUnk)
+ {
+ if (NULL!=ppUnk)
+ {
+ *ppUnk=m_pObj;
+ m_pObj->AddRef();
+ }
+
+ return;
+ }
+
+
+
+
+
+/*
+ * tOleHandler::SizeGet
+ * tOleHandler::SizeSet
+ * tOleHandler::RectGet
+ * tOleHandler::RectSet
+ *
+ * Purpose:
+ * Returns or sets the size/position of the object contained here.
+ *
+ * Parameters:
+ * pszl/prcl LPSIZEL (Size) or LPRECTL (Rect) with the
+ * extents of interest. In Get situations,
+ * this will receive the extents; in Set it
+ * contains the extents.
+ * fDevice BOOL indicating that pszl/prcl is expressed
+ * in device units. Otherwise it's LOMETRIC.
+ * fInformObj (Set Only) BOOL indicating if we need to inform
+ * the object all.
+ *
+ * Return Value:
+ * None
+ */
+
+void tOleHandler::SizeGet(LPSIZEL pszl, BOOL fDevice)
+ {
+ if (!fDevice)
+ {
+ pszl->cx=m_rcl.right-m_rcl.left;
+ pszl->cy=m_rcl.bottom-m_rcl.top;
+ }
+ else
+ {
+ RECT rc;
+
+ SetRect(&rc, (int)(m_rcl.right-m_rcl.left)
+ , (int)(m_rcl.bottom-m_rcl.top), 0, 0);
+
+ RectConvertMappings(&rc, NULL, TRUE);
+
+ pszl->cx=(long)rc.left;
+ pszl->cy=(long)rc.top;
+ }
+
+ return;
+ }
+
+
+void tOleHandler::SizeSet(LPSIZEL pszl, BOOL fDevice, BOOL fInformObj)
+ {
+ SIZEL szl;
+
+ if (!fDevice)
+ {
+ szl=*pszl;
+ m_rcl.right =pszl->cx+m_rcl.left;
+ m_rcl.bottom=pszl->cy+m_rcl.top;
+ }
+ else
+ {
+ RECT rc;
+
+ SetRect(&rc, (int)pszl->cx, (int)pszl->cy, 0, 0);
+ RectConvertMappings(&rc, NULL, FALSE);
+
+ m_rcl.right =(long)rc.left+m_rcl.left;
+ m_rcl.bottom=(long)rc.top+m_rcl.top;
+
+ SETSIZEL(szl, (long)rc.left, (long)rc.top);
+ }
+
+ //Tell OLE that this object was resized.
+ if (NULL!=m_pIOleObject && fInformObj)
+ {
+ HRESULT hr;
+ BOOL fRun=FALSE;
+
+ //Convert our LOMETRIC into HIMETRIC by *=10
+ szl.cx*=10;
+ szl.cy*=-10; //Our size is stored negative.
+
+ /*
+ * If the MiscStatus bit of OLEMISC_RECOMPOSEONRESIZE
+ * is set, then we need to run the object before calling
+ * SetExtent to make sure it has a real chance to
+ * re-render the object. We have to update and close
+ * the object as well after this happens.
+ */
+
+ if (OLEMISC_RECOMPOSEONRESIZE & m_grfMisc)
+ {
+ if (!OleIsRunning(m_pIOleObject))
+ {
+ OleRun(m_pIOleObject);
+ fRun=TRUE;
+ }
+ }
+
+ hr=m_pIOleObject->SetExtent(m_fe.dwAspect, &szl);
+
+ /*
+ * If the object is not running and it does not have
+ * RECOMPOSEONRESIZE, then SetExtent fails. Make
+ * sure that we call SetExtent again (by just calling
+ * SizeSet here again) when we next run the object.
+ */
+ if (SUCCEEDED(hr))
+ {
+ m_fSetExtent=FALSE;
+
+ if (fRun)
+ {
+ m_pIOleObject->Update();
+ m_pIOleObject->Close(OLECLOSE_SAVEIFDIRTY);
+ }
+ }
+ else
+ {
+ if (OLE_E_NOTRUNNING==GetScode(hr))
+ m_fSetExtent=TRUE;
+ }
+ }
+
+ return;
+ }
+
+
+void tOleHandler::RectGet(LPRECTL prcl, BOOL fDevice)
+ {
+ if (!fDevice)
+ *prcl=m_rcl;
+ else
+ {
+ RECT rc;
+
+ RECTFROMRECTL(rc, m_rcl);
+ RectConvertMappings(&rc, NULL, TRUE);
+ RECTLFROMRECT(*prcl, rc);
+ }
+
+ return;
+ }
+
+
+void tOleHandler::RectSet(LPRECTL prcl, BOOL fDevice, BOOL fInformObj)
+ {
+ SIZEL szl;
+ LONG cx, cy;
+
+ /*
+ * Prevent reentrant calls that may come from calling
+ * UpdateInPlaceObjectRects here and elsewhere.
+ */
+ if (m_fInRectSet)
+ return;
+
+ m_fInRectSet=TRUE;
+
+ cx=m_rcl.right-m_rcl.left;
+ cy=m_rcl.bottom-m_rcl.top;
+
+ if (!fDevice)
+ m_rcl=*prcl;
+ else
+ {
+ RECT rc;
+
+ RECTFROMRECTL(rc, *prcl);
+ RectConvertMappings(&rc, NULL, FALSE);
+ RECTLFROMRECT(m_rcl, rc);
+ }
+
+ /*
+ * Tell ourselves that the size changed, if it did. SizeSet
+ * will call IOleObject::SetExtent for us.
+ */
+ if ((m_rcl.right-m_rcl.left)!=cx || (m_rcl.bottom-m_rcl.top)!=cy)
+ {
+ SETSIZEL(szl, m_rcl.right-m_rcl.left, m_rcl.bottom-m_rcl.top);
+ SizeSet(&szl, FALSE, fInformObj);
+ }
+
+ //Tell an in-place active object it moved too
+ UpdateInPlaceObjectRects(NULL, TRUE);
+ m_fInRectSet=FALSE;
+ return;
+ }
+
+
+
+
+
+
+
+
+/*
+ * tOleHandler::DeactivateInPlaceObject
+ *
+ * Purpose:
+ * Deactivates an in-place object if there is one in this tenant.
+ *
+ * Parameters:
+ * fFull BOOL indicating full deactivation of UI
+ * deactivate only.
+ *
+ * Return Value:
+ * None
+ */
+
+void tOleHandler::DeactivateInPlaceObject(BOOL fFull)
+ {
+ if (NULL!=m_pIOleIPObject)
+ {
+ /*
+ * Activate-when-visible objects only UI deactivate
+ * unless we're fully deactivating on purpose.
+ */
+ if ((OLEMISC_ACTIVATEWHENVISIBLE & m_grfMisc) && !fFull)
+ m_pIOleIPObject->UIDeactivate();
+ else
+ {
+ //CHAPTER24MOD
+ /*
+ * Only deactivate when there's no locks. If there
+ * is a lock, then remember that we need to deactivate
+ * when all the locks go away.
+ */
+ if (0==m_cLockInPlace)
+ m_pIOleIPObject->InPlaceDeactivate();
+ else
+ m_fPendingDeactivate=TRUE;
+ //End CHAPTER24MOD
+ }
+ }
+
+ return;
+ }
+
+
+
+/*
+ * tOleHandler::UpdateInPlaceObjectRects
+ *
+ * Purpose:
+ * Generates a call to IOleInPlaceObject::SetObjectRects to allow
+ * it to show it's shading and its object adornments properly.
+ * This function deals in HIMETRIC units.
+ *
+ * Parameters:
+ * prcPos LPCRECT to the size the object wants. Ignored
+ * if NULL in which case we use the size of the
+ * tenant. This rect is in client coordinates of
+ * the pages window.
+ * fUseTenantRect BOOL indicating if we need to use the tenant
+ * rectangle offset for scrolling regardless.
+ *
+ * Return Value:
+ * None
+ */
+
+void tOleHandler::UpdateInPlaceObjectRects(LPCRECT prcPos
+ , BOOL fUseTenantRect)
+ {
+ RECTL rcl;
+ RECT rc;
+ RECT rcClip;
+ BOOL fResizeTenant=TRUE;
+
+ //We don't clip special anywhere in our window.
+ SetRect(&rcClip, 0, 0, 32767, 32767);
+
+ /*
+ * Note that if the object here is activate-when-visible
+ * we'll always have this pointer.
+ */
+ if (NULL!=m_pIOleIPObject)
+ {
+ /*
+ * This uses the last position rectangle from
+ * IOleInPlaceSite::OnPosRectChange if it's been
+ * initialized
+ */
+ if (NULL==prcPos && -1!=m_rcPos.left && !fUseTenantRect)
+ prcPos=&m_rcPos;
+
+ //This code is normally called from OnPosRectChange direct.
+ if (NULL!=prcPos && !fUseTenantRect)
+ {
+ rc=*prcPos;
+
+ //Calculate the boundaries of the full page
+ //m_pPG->CalcBoundingRect(&rcClip, FALSE);
+
+ //Make sure we limit object to page boundaries.
+ IntersectRect(&rc, &rc, &rcClip);
+ }
+ else
+ {
+ /*
+ * We have no rectangle of the object on which to
+ * base the position, so just use the tenant rectangle.
+ * This code is also used when scrolling objects.
+ */
+ RectGet(&rcl, TRUE);
+ RECTFROMRECTL(rc, rcl);
+
+ //Account for scrolling
+// OffsetRect(&rc, -(int)m_pPG->m_xPos, -(int)m_pPG->m_yPos);
+ fResizeTenant=FALSE;
+ }
+
+
+ /*
+ * NOTE: The rectangles to SetObjectRects is in client
+ * coordinates of the pages window.
+ */
+ if (NULL!=m_pIOleIPObject)
+ m_pIOleIPObject->SetObjectRects(&rc, &rcClip);
+
+ if (fResizeTenant)
+ {
+ //Need to tell the tenant to change position too
+ RECTLFROMRECT(rcl, rc);
+ RectSet(&rcl, TRUE, FALSE);
+ }
+ }
+
+ return;
+ }
+
+
+/*
+ * tOleHandler::ObjectWindow
+ *
+ * Purpose:
+ * Returns the window handle of the in-place object.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HWND Handle of the object window.
+ */
+
+HWND tOleHandler::ObjectWindow(void)
+ {
+ HWND hWnd=NULL;
+
+ if (NULL!=m_pIOleIPObject)
+ m_pIOleIPObject->GetWindow(&hWnd);
+
+ return hWnd;
+ }
+
+
+
+
+/*
+ * tOleHandler::ControlInitialize
+ *
+ * Purpose:
+ * Initializes the control if that's the type of object we have
+ * in the site.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * BOOL TRUE if initialization worked, FALSE otherwise.
+ */
+
+BOOL tOleHandler::ControlInitialize(void)
+ {
+ HRESULT hr;
+ BOOL fEvents;
+
+ if (NULL==m_pObj)
+ return FALSE;
+
+ hr=m_pObj->QueryInterface(IID_IOleControl
+ , (PPVOID)&m_pIOleControl);
+
+ //Failure means not a control.
+ if (FAILED(hr))
+ return FALSE;
+
+ m_ambientProp.setControl(m_pIOleControl);
+
+ m_dwState |= TENANTSTATE_CONTROL;
+
+ if (OLEMISC_ACTSLIKEBUTTON & m_grfMisc)
+ m_dwState |= TENANTSTATE_BUTTON;
+
+ //We don't use this, but might as well store it.
+ if (OLEMISC_ACTSLIKELABEL & m_grfMisc)
+ m_dwState |= TENANTSTATE_LABEL;
+
+ /*
+ * Call IOleControl::GetControlInfo to retrieve the keyboard
+ * information for this control. We have to reload this
+ * information in IOleControlSite::OnControlInfoChanged.
+ */
+ /*m_fHaveControlInfo=SUCCEEDED(m_pIOleControl
+ ->GetControlInfo(&m_ctrlInfo));*/ //!!!
+
+
+ /*
+ * If you wanted to receive IPropertyNotifySink notifications
+ * for a control, establish that advisory connection here
+ * through the object's IConnectionPointContainer and
+ * IConnectionPoint.
+ */
+
+ return TRUE;
+ }
+
+
+
+/*
+ * tOleHandler::GetControlFlags
+ *
+ * Purpose:
+ * Requests flags describing the control inside this tenant
+ * if there is, in fact a control.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * DWORD Flags describing the control from the
+ * TENANT
+ */
+
+DWORD tOleHandler::GetControlFlags(void)
+ {
+ return m_dwState & STATEMASK_CONTROLS;
+ }
+
+
+
+
+
+/*
+ * tOleHandler::TryMnemonic
+ *
+ * Purpose:
+ * Asks the tenant to check the given keyboard message against
+ * one that its control might want, passing it to
+ * IOleControl::OnMnemonic if there is a match.
+ *
+ * Parameters:
+ * pMsg LPMSG containing the message to check.
+ *
+ * Return Value:
+ * BOOL TRUE if the mnemonic was a match,
+ * FALSE otherwise.
+ */
+
+BOOL tOleHandler::TryMnemonic(LPMSG pMsg)
+ {
+ UINT i;
+ BOOL fRet=FALSE;
+ LPACCEL pACC;
+ BYTE fVirt=FVIRTKEY;
+
+ if (!m_fHaveControlInfo) //False for non-controls
+ return FALSE;
+
+ if (0==m_ctrlInfo.cAccel)
+ return FALSE;
+
+ pACC=(LPACCEL)GlobalLock(m_ctrlInfo.hAccel);
+
+ if (NULL==pACC)
+ return FALSE;
+
+ /*
+ * We'll come here on WM_KEYDOWN messages and WM_SYSKEYDOWN
+ * messages. The control's accelerator table will contain
+ * entries that each have the desired key and the various
+ * modifier flags. We the create the current modifier flags
+ * then look for entries that match those flags and the key
+ * that is in the message itself.
+ */
+
+ fVirt |= (WM_SYSKEYDOWN==pMsg->message) ? FALT : 0;
+
+ //GetKeyState works on the last message
+ fVirt |= (0x8000 & GetKeyState(VK_CONTROL)) ? FCONTROL : 0;
+ fVirt |= (0x8000 & GetKeyState(VK_SHIFT)) ? FSHIFT : 0;
+
+ for (i=0; i < m_ctrlInfo.cAccel; i++)
+ {
+ if (pACC[i].key==pMsg->wParam && pACC[i].fVirt==fVirt)
+ {
+ m_pIOleControl->OnMnemonic(pMsg);
+ fRet=TRUE;
+ break;
+ }
+ }
+
+ GlobalUnlock(m_ctrlInfo.hAccel);
+ return fRet;
+ }
+
+
+
+
+
+/*
+ * tOleHandler::AmbientChange
+ *
+ * Purpose:
+ * Notifes a control that an ambient property has changed in
+ * the control site.
+ *
+ * Parameters:
+ * dispID DISPID of the property that changed.
+ *
+ * Return Value:
+ * None
+ */
+
+void tOleHandler::AmbientChange(DISPID dispID)
+ {
+ if (NULL!=m_pIOleControl)
+ m_pIOleControl->OnAmbientPropertyChange(dispID);
+
+ return;
+ }
+
+//End CHAPTER24MOD
+
+void tOleHandler::OnShow()
+{
+ // Se objeto ja' tive sido ativado, ignora chamada
+ // Alguns controles reagem mal quando ativados
+ // mais de uma vez
+ if(m_pIOleIPObject != NULL)
+ return;
+
+ if ((OLEMISC_ACTIVATEWHENVISIBLE & m_grfMisc))
+ Activate(OLEIVERB_INPLACEACTIVATE, NULL);
+}
+
+
+void tOleHandler::GetNaturalSize(long *pWidth, long *pHeight)
+{
+ assert(pWidth && pHeight);
+ if(!pWidth || !pHeight)
+ return;
+
+ *pWidth = natural_width;
+ *pHeight = natural_height;
+}
+
+/*
+ * CalcNaturalSize
+ * Obtem o tamanho desejado pelo objeto
+ */
+
+void tOleHandler::CalcNaturalSize()
+{
+ HRESULT hr;
+ SIZEL sizel;
+ RECTL rcl;
+
+ assert(m_pIViewObject2 != NULL);
+
+ if(!m_pIViewObject2)
+ return;
+
+ hr = m_pIViewObject2->GetExtent(m_fe.dwAspect, -1, NULL, &sizel);
+
+ if(FAILED(hr))
+ return;
+
+ SETRECTL(rcl, 0, 0, sizel.cx/10, -sizel.cy/10);
+ RectSet(&rcl, FALSE, TRUE);
+
+ // Obtem medidas ja' convertidas para pixels
+ SizeGet(&sizel, TRUE);
+
+ natural_width = sizel.cx;
+ natural_height = sizel.cy;
+}
+
diff --git a/iup/srcole/tOleHandler.h b/iup/srcole/tOleHandler.h
new file mode 100755
index 0000000..966cb30
--- /dev/null
+++ b/iup/srcole/tOleHandler.h
@@ -0,0 +1,139 @@
+// tOleHandler.h: interface for the tOleHandler class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_TOLEHANDLER_H__49B97C12_8DEB_11D3_A906_0004ACE655F9__INCLUDED_)
+#define AFX_TOLEHANDLER_H__49B97C12_8DEB_11D3_A906_0004ACE655F9__INCLUDED_
+
+#if _MSC_VER >= 1000
+#pragma once
+#endif // _MSC_VER >= 1000
+
+#include <windows.h>
+#include <olectl.h>
+
+#include "tOleClientSite.h"
+#include "tOleInPlaceSite.h"
+#include "tOleControlSite.h"
+#include "tDispatch.h"
+#include "tAmbientProperties.h"
+#include "tLegacy.h"
+
+#ifndef LPOLEINPLACEOBJECT
+typedef interface IOleInPlaceObject *LPOLEINPLACEOBJECT;
+#endif
+
+class tOleClientSite;
+
+class tOleHandler : public IUnknown
+{
+public:
+ friend class tOleClientSite;
+ friend class tOleInPlaceSite;
+ friend class tOleControlSite;
+ friend class tDispatch;
+ tOleHandler();
+ virtual ~tOleHandler();
+ tAmbientProperties m_ambientProp;
+
+ HWND m_hWnd;
+private:
+
+ DWORD m_cOpens; //Count calls to Open
+
+ BOOL m_fInitialized; //Something here?
+ LPUNKNOWN m_pObj; //The object here
+ LPSTORAGE m_pIStorage; //Sub-storage for tenant
+
+ FORMATETC m_fe; //Used to create the object
+ DWORD m_dwState; //State flags
+ RECTL m_rcl; //Space of this object
+ CLSID m_clsID; //Object class (for statics)
+ BOOL m_fSetExtent; //Call SetExtent on next run
+
+ ULONG m_cRef; //We're an object now
+ LPOLEOBJECT m_pIOleObject; //IOleObject on m_pObj
+ LPVIEWOBJECT2 m_pIViewObject2; //IViewObject2 on m_pObj
+ ULONG m_grfMisc; //OLEMISC flags
+ BOOL m_fRepaintEnabled; //No redundant paints
+
+ //Our interfaces
+ tOleClientSite *m_pImpIOleClientSite;
+
+ tOleInPlaceSite *m_pImpIOleIPSite; //Our interface
+ LPOLEINPLACEOBJECT m_pIOleIPObject; //The object
+ RECT m_rcPos; //Last object rect
+ BOOL m_fInRectSet; //Prevent reentrancy
+
+ //CHAPTER24MOD
+ tOleControlSite *m_pImpIOleControlSite; //Implemented
+ tDispatch *m_pImpIDispatch; //Implemented
+
+ //Control interfaces
+ LPOLECONTROL m_pIOleControl; //Used
+
+ //Other state information
+ BOOL m_fHaveControlInfo;
+ CONTROLINFO m_ctrlInfo;
+ ULONG m_cLockInPlace;
+ BOOL m_fPendingDeactivate;
+ //End CHAPTER24MOD
+
+
+/*
+* This flag is used exculsively by the implementation of
+* IOleUILinkContainer on the page we're in for the Links
+* Dialog. Since we never use it ourselves, public here
+* is no big deal.
+*/
+public:
+ BOOL m_fLinkAvail;
+
+protected:
+ void CalcNaturalSize(void);
+ long natural_height;
+ long natural_width;
+ BOOL ObjectInitialize(LPUNKNOWN);
+
+ //CHAPTER24MOD
+ BOOL ControlInitialize(void);
+ //End CHAPTER24MOD
+
+public:
+ void setDesignMode(bool value, bool notify);
+ void GetNaturalSize(long *pWidth, long *pHeight);
+ void OnShow(void);
+ //Gotta have an IUnknown for delegation
+ STDMETHODIMP QueryInterface(REFIID, LPVOID *);
+ STDMETHODIMP_(ULONG) AddRef(void);
+ STDMETHODIMP_(ULONG) Release(void);
+
+ UINT Create(LPVOID);
+ BOOL Open(LPSTORAGE);
+ void Close(BOOL);
+
+
+ BOOL Activate(LONG, LPMSG);
+
+ void EnableRepaint(BOOL);
+
+ void ObjectGet(LPUNKNOWN *);
+ void SizeGet(LPSIZEL, BOOL);
+ void SizeSet(LPSIZEL, BOOL, BOOL);
+ void RectGet(LPRECTL, BOOL);
+ void RectSet(LPRECTL, BOOL, BOOL);
+
+ void DeactivateInPlaceObject(BOOL);
+ void UpdateInPlaceObjectRects(LPCRECT, BOOL);
+ HWND ObjectWindow(void);
+
+ //CHAPTER24MOD
+ DWORD GetControlFlags();
+ BOOL TryMnemonic(LPMSG);
+ void AmbientChange(DISPID);
+ //End CHAPTER24MOD
+
+
+};
+
+#endif // !defined(AFX_TOLEHANDLER_H__49B97C12_8DEB_11D3_A906_0004ACE655F9__INCLUDED_)
diff --git a/iup/srcole/tOleInPlaceFrame.cpp b/iup/srcole/tOleInPlaceFrame.cpp
new file mode 100755
index 0000000..15fc9b4
--- /dev/null
+++ b/iup/srcole/tOleInPlaceFrame.cpp
@@ -0,0 +1,429 @@
+// tOleInPlaceFrame.cpp: implementation of the tOleInPlaceFrame class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "tOleInPlaceFrame.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+/*
+ * tOleInPlaceFrame::tOleInPlaceFrame
+ * tOleInPlaceFrame::~tOleInPlaceFrame
+ *
+ * Constructor Parameters:
+ * hInst HINSTANCE from WinMain
+ * hInstPrev HINSTANCE from WinMain
+ * pszCmdLine LPSTR from WinMain
+ * nCmdShow int from WInMain
+ */
+
+tOleInPlaceFrame::tOleInPlaceFrame(HWND hwnd)
+ {
+ m_cRef=0;
+ m_hAccelIP=NULL;
+ m_fInContextHelp=FALSE;
+ m_pIOleIPActiveObject=NULL;
+ m_hWnd = hwnd;
+
+ return;
+ }
+
+
+tOleInPlaceFrame::~tOleInPlaceFrame(void)
+ {
+ }
+
+
+/*
+ * tOleInPlaceFrame::QueryInterface
+ * tOleInPlaceFrame::AddRef
+ * tOleInPlaceFrame::Release
+ */
+
+STDMETHODIMP tOleInPlaceFrame::QueryInterface(REFIID riid, PPVOID ppv)
+ {
+ //We only know IUnknown and IOleInPlaceFrame
+ *ppv=NULL;
+
+ if (IID_IUnknown==riid || IID_IOleInPlaceUIWindow==riid
+ || IID_IOleWindow==riid || IID_IOleInPlaceFrame==riid)
+ *ppv=(LPOLEINPLACEFRAME)this;
+
+ if (NULL!=*ppv)
+ {
+ ((LPUNKNOWN)*ppv)->AddRef();
+ return NOERROR;
+ }
+
+ return ResultFromScode(E_NOINTERFACE);
+ }
+
+
+STDMETHODIMP_(ULONG) tOleInPlaceFrame::AddRef(void)
+ {
+ return ++m_cRef;
+ }
+
+STDMETHODIMP_(ULONG) tOleInPlaceFrame::Release(void)
+ {
+ /*
+ * We don't do anything with this since we're not controlled
+ * by a reference count as far as in-place stuff is concerned.
+ */
+ return --m_cRef;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::GetWindow
+ *
+ * Purpose:
+ * Retrieves the handle of the window associated with the object
+ * on which this interface is implemented.
+ *
+ * Parameters:
+ * phWnd HWND * in which to store the window handle.
+ *
+ * Return Value:
+ * HRESULT NOERROR if successful, E_FAIL if there is no
+ * window.
+ */
+
+STDMETHODIMP tOleInPlaceFrame::GetWindow(HWND *phWnd)
+ {
+ *phWnd=m_hWnd;
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::ContextSensitiveHelp
+ *
+ * Purpose:
+ * Instructs the object on which this interface is implemented to
+ * enter or leave a context-sensitive help mode.
+ *
+ * Parameters:
+ * fEnterMode BOOL TRUE to enter the mode, FALSE otherwise.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceFrame::ContextSensitiveHelp(BOOL fEnterMode)
+ {
+ /*
+ * Don't bother if there is no active object since we don't do
+ * context help on our own.
+ */
+ if (NULL==m_pIOleIPActiveObject)
+ return NOERROR;
+
+ /*
+ * If the state changes, an MDI frame should call the same
+ * function in all documents. An SDI frame should just call
+ * the active object, if it has one.
+ */
+
+ if (m_fInContextHelp!=fEnterMode)
+ {
+ m_fInContextHelp=fEnterMode;
+
+ m_pIOleIPActiveObject->ContextSensitiveHelp(fEnterMode);
+
+ }
+
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::GetBorder
+ *
+ * Purpose:
+ * Returns the rectangle in which the container is willing to
+ * negotiate about an object's adornments.
+ *
+ * Parameters:
+ * prcBorder LPRECT in which to store the rectangle.
+ *
+ * Return Value:
+ * HRESULT NOERROR if all is well, INPLACE_E_NOTOOLSPACE
+ * if there is no negotiable space.
+ */
+
+STDMETHODIMP tOleInPlaceFrame::GetBorder(LPRECT prcBorder)
+ {
+ if (NULL==prcBorder)
+ return ResultFromScode(E_INVALIDARG);
+
+ /*
+ * We return all the client area space sans the StatStrip,
+ * which we control
+ */
+ GetClientRect(m_hWnd, prcBorder);
+
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::RequestBorderSpace
+ *
+ * Purpose:
+ * Asks the container if it can surrender the amount of space
+ * in pBW that the object would like for it's adornments. The
+ * container does nothing but validate the spaces on this call.
+ *
+ * Parameters:
+ * pBW LPCBORDERWIDTHS containing the requested space.
+ * The values are the amount of space requested
+ * from each side of the relevant window.
+ *
+ * Return Value:
+ * HRESULT NOERROR if we can give up space,
+ * INPLACE_E_NOTOOLSPACE otherwise.
+ */
+
+STDMETHODIMP tOleInPlaceFrame::RequestBorderSpace(LPCBORDERWIDTHS pBW)
+ {
+ //Everything is fine with us, so always return an OK.
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::SetBorderSpace
+ *
+ * Purpose:
+ * Called when the object now officially requests that the
+ * container surrender border space it previously allowed
+ * in RequestBorderSpace. The container should resize windows
+ * appropriately to surrender this space.
+ *
+ * Parameters:
+ * pBW LPCBORDERWIDTHS containing the amount of space
+ * from each side of the relevant window that the
+ * object is now reserving.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceFrame::SetBorderSpace(LPCBORDERWIDTHS pBW)
+ {
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::SetActiveObject
+ *
+ * Purpose:
+ * Provides the container with the object's IOleInPlaceActiveObject
+ * pointer
+ *
+ * Parameters:
+ * pIIPActiveObj LPOLEINPLACEACTIVEOBJECT of interest.
+ * pszObj LPCOLESTR naming the object. Not used.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceFrame::SetActiveObject
+ (LPOLEINPLACEACTIVEOBJECT pIIPActiveObj, LPCOLESTR pszObj)
+ {
+ if (NULL!=m_pIOleIPActiveObject)
+ m_pIOleIPActiveObject->Release();
+
+ //NULLs m_pIOleIPActiveObject if pIIPActiveObj is NULL
+ m_pIOleIPActiveObject=pIIPActiveObj;
+
+ if (NULL!=m_pIOleIPActiveObject)
+ m_pIOleIPActiveObject->AddRef();
+
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::InsertMenus
+ *
+ * Purpose:
+ * Instructs the container to place its in-place menu items where
+ * necessary in the given menu and to fill in elements 0, 2, and 4
+ * of the OLEMENUGROUPWIDTHS array to indicate how many top-level
+ * items are in each group.
+ *
+ * Parameters:
+ * hMenu HMENU in which to add popups.
+ * pMGW LPOLEMENUGROUPWIDTHS in which to store the
+ * width of each container menu group.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceFrame::InsertMenus(HMENU hMenu
+ , LPOLEMENUGROUPWIDTHS pMGW)
+ {
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::SetMenu
+ *
+ * Purpose:
+ * Instructs the container to replace whatever menu it's currently
+ * using with the given menu and to call OleSetMenuDescritor so OLE
+ * knows to whom to dispatch messages.
+ *
+ * Parameters:
+ * hMenu HMENU to show.
+ * hOLEMenu HOLEMENU to the menu descriptor.
+ * hWndObj HWND of the active object to which messages are
+ * dispatched.
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceFrame::SetMenu(HMENU hMenu
+ , HOLEMENU hOLEMenu, HWND hWndObj)
+ {
+ HRESULT hr;
+
+ /*
+ * Our responsibilities here are to put the menu on the frame
+ * window and call OleSetMenuDescriptor.
+ * CPatronClient::SetMenu which we call here takes care of
+ * MDI/SDI differences.
+ *
+ * We also want to save the object's hWnd for use in WM_SETFOCUS
+ * processing.
+ */
+
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::RemoveMenus
+ *
+ * Purpose:
+ * Asks the container to remove any menus it put into hMenu in
+ * InsertMenus.
+ *
+ * Parameters:
+ * hMenu HMENU from which to remove the container's
+ * items.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceFrame::RemoveMenus(HMENU hMenu)
+ {
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::SetStatusText
+ *
+ * Purpose:
+ * Asks the container to place some text in a status line, if one
+ * exists. If the container does not have a status line it
+ * should return E_FAIL here in which case the object could
+ * display its own.
+ *
+ * Parameters:
+ * pszText LPCOLESTR to display.
+ *
+ * Return Value:
+ * HRESULT NOERROR if successful, S_TRUNCATED if not all
+ * of the text could be displayed, or E_FAIL if
+ * the container has no status line.
+ */
+
+STDMETHODIMP tOleInPlaceFrame::SetStatusText(LPCOLESTR pszText)
+ {
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::EnableModeless
+ *
+ * Purpose:
+ * Instructs the container to show or hide any modeless popup
+ * windows that it may be using.
+ *
+ * Parameters:
+ * fEnable BOOL indicating to enable/show the windows
+ * (TRUE) or to hide them (FALSE).
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceFrame::EnableModeless(BOOL fEnable)
+ {
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceFrame::TranslateAccelerator
+ *
+ * Purpose:
+ * When dealing with an in-place object from an EXE server, this
+ * is called to give the container a chance to process accelerators
+ * after the server has looked at the message.
+ *
+ * Parameters:
+ * pMSG LPMSG for the container to examine.
+ * wID WORD the identifier in the container's
+ * accelerator table (from IOleInPlaceSite
+ * ::GetWindowContext) for this message (OLE does
+ * some translation before calling).
+ *
+ * Return Value:
+ * HRESULT NOERROR if the keystroke was used,
+ * S_FALSE otherwise.
+ */
+
+STDMETHODIMP tOleInPlaceFrame::TranslateAccelerator(LPMSG pMSG, WORD wID)
+ {
+ SCODE sc;
+
+ sc=S_OK;
+ return ResultFromScode(sc);
+ }
diff --git a/iup/srcole/tOleInPlaceFrame.h b/iup/srcole/tOleInPlaceFrame.h
new file mode 100755
index 0000000..4048f12
--- /dev/null
+++ b/iup/srcole/tOleInPlaceFrame.h
@@ -0,0 +1,67 @@
+// tOleInPlaceFrame.h: interface for the tOleInPlaceFrame class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_TOLEINPLACEFRAME_H__76ABD328_9D90_11D3_A906_0004ACE655F9__INCLUDED_)
+#define AFX_TOLEINPLACEFRAME_H__76ABD328_9D90_11D3_A906_0004ACE655F9__INCLUDED_
+
+#if _MSC_VER >= 1000
+#pragma once
+#endif // _MSC_VER >= 1000
+
+#include "tLegacy.h"
+
+/*
+ * UINT value such that adding one produces zero. Portable to Win32.
+ * This is used to represent a non-existent zero-based UINT value
+ */
+#define NOVALUE ((UINT)-1)
+
+
+//PATRON.CPP: Frame object that creates a main window
+
+class tOleInPlaceFrame : public IOleInPlaceFrame
+ {
+ private:
+ BOOL m_fInitialized; //OleInitialize worked
+
+ DWORD m_cRef;
+ HWND m_hWnd; //Object window
+
+ BOOL m_fInContextHelp; //In context help mode?
+
+ LPOLEINPLACEACTIVEOBJECT m_pIOleIPActiveObject;
+
+ //This is for access from IOleInPlaceSite::GetWindowContext
+ public:
+ HACCEL m_hAccelIP; //Accelerators for in-place
+
+ protected:
+
+ public:
+ tOleInPlaceFrame(HWND);
+ virtual ~tOleInPlaceFrame(void);
+
+ //IOleInPlaceFrame implementation
+ STDMETHODIMP QueryInterface(REFIID, LPVOID *);
+ STDMETHODIMP_(ULONG) AddRef(void);
+ STDMETHODIMP_(ULONG) Release(void);
+
+ STDMETHODIMP GetWindow(HWND *);
+ STDMETHODIMP ContextSensitiveHelp(BOOL);
+ STDMETHODIMP GetBorder(LPRECT);
+ STDMETHODIMP RequestBorderSpace(LPCBORDERWIDTHS);
+ STDMETHODIMP SetBorderSpace(LPCBORDERWIDTHS);
+ STDMETHODIMP SetActiveObject(LPOLEINPLACEACTIVEOBJECT
+ , LPCOLESTR);
+ STDMETHODIMP InsertMenus(HMENU, LPOLEMENUGROUPWIDTHS);
+ STDMETHODIMP SetMenu(HMENU, HOLEMENU, HWND);
+ STDMETHODIMP RemoveMenus(HMENU);
+ STDMETHODIMP SetStatusText(LPCOLESTR);
+ STDMETHODIMP EnableModeless(BOOL);
+ STDMETHODIMP TranslateAccelerator(LPMSG, WORD);
+ };
+
+
+
+#endif // !defined(AFX_TOLEINPLACEFRAME_H__76ABD328_9D90_11D3_A906_0004ACE655F9__INCLUDED_)
diff --git a/iup/srcole/tOleInPlaceSite.cpp b/iup/srcole/tOleInPlaceSite.cpp
new file mode 100755
index 0000000..977777c
--- /dev/null
+++ b/iup/srcole/tOleInPlaceSite.cpp
@@ -0,0 +1,485 @@
+// tOleInPlaceSite.cpp: implementation of the tOleInPlaceSite class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "tOleInPlaceSite.h"
+#include "tOleHandler.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+BOOL g_fSwitchingActive=FALSE;
+
+/*
+ * tOleInPlaceSite::tOleInPlaceSite
+ * tOleInPlaceSite::~tOleInPlaceSite
+ *
+ * Parameters (Constructor):
+ * pTen PCTenant of the tenant we're in.
+ * pUnkOuter LPUNKNOWN to which we delegate.
+ */
+
+tOleInPlaceSite::tOleInPlaceSite(class tOleHandler *pTen
+ , LPUNKNOWN pUnkOuter)
+ {
+ m_cRef=0;
+ m_pTen=pTen;
+ m_pUnkOuter=pUnkOuter;
+ m_oleinplaceframe = new tOleInPlaceFrame(m_pTen->m_hWnd);
+ return;
+ }
+
+tOleInPlaceSite::~tOleInPlaceSite(void)
+ {
+ return;
+ }
+
+
+
+/*
+ * tOleInPlaceSite::QueryInterface
+ * tOleInPlaceSite::AddRef
+ * tOleInPlaceSite::Release
+ *
+ * Purpose:
+ * IUnknown members for tOleInPlaceSite object.
+ */
+
+STDMETHODIMP tOleInPlaceSite::QueryInterface(REFIID riid
+ , LPVOID *ppv)
+ {
+ return m_pUnkOuter->QueryInterface(riid, ppv);
+ }
+
+
+STDMETHODIMP_(ULONG) tOleInPlaceSite::AddRef(void)
+ {
+ ++m_cRef;
+ return m_pUnkOuter->AddRef();
+ }
+
+STDMETHODIMP_(ULONG) tOleInPlaceSite::Release(void)
+ {
+ --m_cRef;
+ return m_pUnkOuter->Release();
+ }
+
+
+
+
+/*
+ * tOleInPlaceActiveObject::GetWindow
+ *
+ * Purpose:
+ * Retrieves the handle of the window associated with the object
+ * on which this interface is implemented.
+ *
+ * Parameters:
+ * phWnd HWND * in which to store the window handle.
+ *
+ * Return Value:
+ * HRESULT NOERROR if successful, E_FAIL if there is no
+ * window.
+ */
+
+STDMETHODIMP tOleInPlaceSite::GetWindow(HWND *phWnd)
+ {
+ *phWnd=m_pTen->m_hWnd;
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceActiveObject::ContextSensitiveHelp
+ *
+ * Purpose:
+ * Instructs the object on which this interface is implemented to
+ * enter or leave a context-sensitive help mode.
+ *
+ * Parameters:
+ * fEnterMode BOOL TRUE to enter the mode, FALSE otherwise.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceSite::ContextSensitiveHelp
+ (BOOL fEnterMode)
+ {
+ return E_NOTIMPL;
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::CanInPlaceActivate
+ *
+ * Purpose:
+ * Answers the server whether or not we can currently in-place
+ * activate its object. By implementing this interface we say
+ * that we support in-place activation, but through this function
+ * we indicate whether the object can currently be activated
+ * in-place. Iconic aspects, for example, cannot, meaning we
+ * return S_FALSE.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT NOERROR if we can in-place activate the object
+ * in this site, S_FALSE if not.
+ */
+
+STDMETHODIMP tOleInPlaceSite::CanInPlaceActivate(void)
+ {
+ if (DVASPECT_CONTENT!=m_pTen->m_fe.dwAspect)
+ return ResultFromScode(S_FALSE);
+
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::OnInPlaceActivate
+ *
+ * Purpose:
+ * Informs the container that an object is being activated in-place
+ * such that the container can prepare appropriately. The
+ * container does not, however, make any user interface changes at
+ * this point. See OnUIActivate.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT NOERROR or an appropriate error code.
+ */
+
+STDMETHODIMP tOleInPlaceSite::OnInPlaceActivate(void)
+ {
+ //CHAPTER24MOD
+ m_pTen->m_fPendingDeactivate=FALSE;
+ //End CHAPTER24MOD
+
+ //m_pIOleIPObject is our in-place flag.
+ m_pTen->m_pObj->QueryInterface(IID_IOleInPlaceObject
+ , (PPVOID)&m_pTen->m_pIOleIPObject);
+
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::OnInPlaceDeactivate
+ *
+ * Purpose:
+ * Notifies the container that the object has deactivated itself
+ * from an in-place state. Opposite of OnInPlaceActivate. The
+ * container does not change any UI at this point.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT NOERROR or an appropriate error code.
+ */
+
+STDMETHODIMP tOleInPlaceSite::OnInPlaceDeactivate(void)
+ {
+ /*
+ * Since we don't have an Undo command, we can tell the object
+ * right away to discard its Undo state.
+ */
+ m_pTen->Activate(OLEIVERB_DISCARDUNDOSTATE, NULL);
+ ReleaseInterface(m_pTen->m_pIOleIPObject);
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::OnUIActivate
+ *
+ * Purpose:
+ * Informs the container that the object is going to start munging
+ * around with user interface, like replacing the menu. The
+ * container should remove any relevant UI in preparation.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT NOERROR or an appropriate error code.
+ */
+
+STDMETHODIMP tOleInPlaceSite::OnUIActivate(void)
+ {
+ //CHAPTER24MOD
+ m_pTen->m_fPendingDeactivate=FALSE;
+ //End CHAPTER24MOD
+
+ /*
+ * Change the currently selected tenant in the page. This
+ * will UIDeactivate the currently UI Active tenant.
+ */
+ g_fSwitchingActive=TRUE;
+ //m_pTen->m_pPG->m_pPageCur->SwitchActiveTenant(m_pTen);
+ g_fSwitchingActive=FALSE;
+
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::OnUIDeactivate
+ *
+ * Purpose:
+ * Informs the container that the object is deactivating its
+ * in-place user interface at which time the container may
+ * reinstate its own. Opposite of OnUIActivate.
+ *
+ * Parameters:
+ * fUndoable BOOL indicating if the object will actually
+ * perform an Undo if the container calls
+ * ReactivateAndUndo.
+ *
+ * Return Value:
+ * HRESULT NOERROR or an appropriate error code.
+ */
+
+STDMETHODIMP tOleInPlaceSite::OnUIDeactivate(BOOL fUndoable)
+ {
+ MSG msg;
+
+ /*
+ * Ignore this notification if we're switching between
+ * multiple active objects.
+ */
+ if (g_fSwitchingActive)
+ return NOERROR;
+
+ //If in shutdown (NULL storage), don't check messages.
+/* if (NULL==m_pTen->m_pIStorage)
+ {
+ g_pFR->ReinstateUI();
+ return NOERROR;
+ }*/
+
+ //If there's a pending double-click, delay showing our UI
+/* if (!PeekMessage(&msg, pDoc->Window(), WM_LBUTTONDBLCLK
+ , WM_LBUTTONDBLCLK, PM_NOREMOVE | PM_NOYIELD))
+ {
+ //Turn everything back on.
+ g_pFR->ReinstateUI();
+ }
+ else*/
+
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::DeactivateAndUndo
+ *
+ * Purpose:
+ * If immediately after activation the object does an Undo, the
+ * action being undone is the activation itself, and this call
+ * informs the container that this is, in fact, what happened.
+ * The container should call IOleInPlaceObject::UIDeactivate.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT NOERROR or an appropriate error code.
+ */
+
+STDMETHODIMP tOleInPlaceSite::DeactivateAndUndo(void)
+ {
+ //CHAPTER24MOD
+ /*
+ * Note that we don't pay attention to the locking
+ * from IOleControlSite::LockInPlaceActive since only
+ * the object calls this function and should know
+ * that it's going to be deactivated.
+ */
+ //End CHAPTER24MOD
+
+ m_pTen->m_pIOleIPObject->InPlaceDeactivate();
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::DiscardUndoState
+ *
+ * Purpose:
+ * Informs the container that something happened in the object
+ * that means the container should discard any undo information
+ * it currently maintains for the object.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * HRESULT NOERROR or an appropriate error code.
+ */
+
+STDMETHODIMP tOleInPlaceSite::DiscardUndoState(void)
+ {
+ return ResultFromScode(E_NOTIMPL);
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::GetWindowContext
+ *
+ * Purpose:
+ * Provides an in-place object with pointers to the frame and
+ * document level in-place interfaces (IOleInPlaceFrame and
+ * IOleInPlaceUIWindow) such that the object can do border
+ * negotiation and so forth. Also requests the position and
+ * clipping rectangles of the object in the container and a
+ * pointer to an OLEINPLACEFRAME info structure which contains
+ * accelerator information.
+ *
+ * Note that the two interfaces this call returns are not
+ * available through QueryInterface on IOleInPlaceSite since they
+ * live with the frame and document, but not the site.
+ *
+ * Parameters:
+ * ppIIPFrame LPOLEINPLACEFRAME * in which to return the
+ * AddRef'd pointer to the container's
+ * IOleInPlaceFrame.
+ * ppIIPUIWindow LPOLEINPLACEUIWINDOW * in which to return
+ * the AddRef'd pointer to the container document's
+ * IOleInPlaceUIWindow.
+ * prcPos LPRECT in which to store the object's position.
+ * prcClip LPRECT in which to store the object's visible
+ * region.
+ * pFI LPOLEINPLACEFRAMEINFO to fill with accelerator
+ * stuff.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceSite::GetWindowContext
+ (LPOLEINPLACEFRAME *ppIIPFrame, LPOLEINPLACEUIWINDOW
+ *ppIIPUIWindow, LPRECT prcPos, LPRECT prcClip
+ , LPOLEINPLACEFRAMEINFO pFI)
+ {
+ RECTL rcl;
+
+ *ppIIPUIWindow=NULL;
+ *ppIIPFrame=m_oleinplaceframe;
+ m_oleinplaceframe->AddRef();
+
+ GetClientRect(m_pTen->m_hWnd, prcPos);
+ GetClientRect(m_pTen->m_hWnd, prcClip);
+
+/* *ppIIPFrame=(LPOLEINPLACEFRAME)g_pFR;
+ g_pFR->AddRef();*/
+
+/* if (NULL!=pDoc)
+ {
+ pDoc->QueryInterface(IID_IOleInPlaceUIWindow
+ , (PPVOID)ppIIPUIWindow);
+ }*/
+
+ //Now get the rectangles and frame information.
+ /*m_pTen->RectGet(&rcl, TRUE);
+ RECTFROMRECTL(*prcPos, rcl);
+ 0
+ //Include scroll position here.
+ OffsetRect(prcPos, -(int)m_pTen->m_pPG->m_xPos
+ , -(int)m_pTen->m_pPG->m_yPos);
+
+ SetRect(prcClip, 0, 0, 32767, 32767);
+*/
+ pFI->cb=sizeof(OLEINPLACEFRAMEINFO);
+ pFI->fMDIApp=FALSE;
+
+ pFI->hwndFrame=m_pTen->m_hWnd;
+
+ pFI->haccel=NULL;
+ pFI->cAccelEntries=0;
+
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::Scroll
+ *
+ * Purpose:
+ * Asks the container to scroll the document, and thus the object,
+ * by the given amounts in the sz parameter.
+ *
+ * Parameters:
+ * sz SIZE containing signed horizontal and vertical
+ * extents by which the container should scroll.
+ * These are in device units.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceSite::Scroll(SIZE sz)
+ {
+ /*int x, y;
+
+ x=m_pTen->m_pPG->m_xPos+sz.cx;
+ y=m_pTen->m_pPG->m_yPos+sz.cy;
+
+ SendScrollPosition(m_pTen->m_hWnd, WM_HSCROLL, x);
+ SendScrollPosition(m_pTen->m_hWnd, WM_VSCROLL, y);*/
+ return NOERROR;
+ }
+
+
+
+
+/*
+ * tOleInPlaceSite::OnPosRectChange
+ *
+ * Purpose:
+ * Informs the container that the in-place object was resized.
+ * The container must call IOleInPlaceObject::SetObjectRects.
+ * This does not change the site's rectangle in any case.
+ *
+ * Parameters:
+ * prcPos LPCRECT containing the new size of the object.
+ *
+ * Return Value:
+ * HRESULT NOERROR
+ */
+
+STDMETHODIMP tOleInPlaceSite::OnPosRectChange(LPCRECT prcPos)
+ {
+ if (NULL!=prcPos)
+ m_pTen->m_rcPos=*prcPos;
+
+ m_pTen->UpdateInPlaceObjectRects(prcPos, FALSE);
+ return NOERROR;
+ }
+
diff --git a/iup/srcole/tOleInPlaceSite.h b/iup/srcole/tOleInPlaceSite.h
new file mode 100755
index 0000000..d559df2
--- /dev/null
+++ b/iup/srcole/tOleInPlaceSite.h
@@ -0,0 +1,47 @@
+// tOleInPlaceSite.h: interface for the tOleInPlaceSite class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_TOLEINPLACESITE_H__37A5ADEB_91FB_11D3_A906_0004AC252223__INCLUDED_)
+#define AFX_TOLEINPLACESITE_H__37A5ADEB_91FB_11D3_A906_0004AC252223__INCLUDED_
+
+#if _MSC_VER >= 1000
+#pragma once
+#endif // _MSC_VER >= 1000
+
+#include <windows.h>
+#include "tOleInPlaceFrame.h"
+
+class tOleInPlaceSite : public IOleInPlaceSite
+{
+protected:
+ ULONG m_cRef;
+ class tOleHandler *m_pTen;
+ LPUNKNOWN m_pUnkOuter;
+
+public:
+ tOleInPlaceFrame * m_oleinplaceframe;
+ tOleInPlaceSite(class tOleHandler *, LPUNKNOWN);
+ ~tOleInPlaceSite(void);
+
+ STDMETHODIMP QueryInterface(REFIID, LPVOID*);
+ STDMETHODIMP_(ULONG) AddRef(void);
+ STDMETHODIMP_(ULONG) Release(void);
+
+ STDMETHODIMP GetWindow(HWND *);
+ STDMETHODIMP ContextSensitiveHelp(BOOL);
+ STDMETHODIMP CanInPlaceActivate(void);
+ STDMETHODIMP OnInPlaceActivate(void);
+ STDMETHODIMP OnUIActivate(void);
+ STDMETHODIMP GetWindowContext(LPOLEINPLACEFRAME *
+ , LPOLEINPLACEUIWINDOW *, LPRECT, LPRECT
+ , LPOLEINPLACEFRAMEINFO);
+ STDMETHODIMP Scroll(SIZE);
+ STDMETHODIMP OnUIDeactivate(BOOL);
+ STDMETHODIMP OnInPlaceDeactivate(void);
+ STDMETHODIMP DiscardUndoState(void);
+ STDMETHODIMP DeactivateAndUndo(void);
+ STDMETHODIMP OnPosRectChange(LPCRECT);
+};
+
+#endif // !defined(AFX_TOLEINPLACESITE_H__37A5ADEB_91FB_11D3_A906_0004AC252223__INCLUDED_)