Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cOleControl.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cOleControl_H
8 #define _INC_cOleControl_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 #include "../WinAPI/WinTypes.h"
13 
14 #if defined(_WIN32) && defined(_MSC_VER)
15 #include "../Windows/cWindow.h"
16 #include "../WinAPI/cWinVariant.h"
17 #include "../Geometry/cRectI.h"
18 #include "../Input/cInputBase.h" // VK_ESCAPE
22 
23 #include <DocObj.h> // IOleCommandTarget
24 #include <mshtmhst.h> // Defines of stuff like IDocHostUIHandler. This is an include file with Visual C 6 and above
25 
26 //MIDL_INTERFACE("00000112-0000-0000-C000-000000000046") IOleObject; // related to USE_DX_SHOW
27 //MIDL_INTERFACE("3AF24292-0C96-11CE-A0CF-00AA00600AB8") IViewObjectEx;
28 //MIDL_INTERFACE("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E") IWebBrowser2;
29 
30 #ifdef USE_DX9 // IDirect3DSurface9
31 MIDL_INTERFACE("0CFBAF3A-9FF6-429a-99B3-A2796AF8B89B") IDirect3DSurface9; // USE_DX9 <d3d9.h>
32 #endif
33 
34 enum tagREADYSTATE;
35 
36 // #define USE_DRAW_RECTDIRTY // try to track dirty parts of the window for optimized drawing.
37 
38 namespace GrayLib
39 {
40  class cOleWebBrowserRedir;
41  class cOleControl;
42  class cOleClientSite;
43 
44  enum OLE_WINDOW_TYPE
45  {
48 
49  OLE_WINDOW_Unknown = 0,
50  OLE_WINDOW_Less,
51  OLE_WINDOW_Proxy,
52  OLE_WINDOW_Child,
53  OLE_WINDOW_Popup,
54  };
55 
56  class GRAYLIB_LINK cOleWindowBase
57  : public cRefBase
58  {
62 
63  protected:
64  cOleControl* m_pParentControl;
65  MSG m_MsgLast;
66 
67  cRectI m_rectDirty;
68 
69  public:
70  cOleWindowBase(cOleControl* pParentControl)
71  : m_pParentControl(pParentControl)
72  {
73  ASSERT(!isDisposed());
74  cMem::Zero(&m_MsgLast, sizeof(m_MsgLast));
75  ASSERT(m_rectDirty.isRectNull());
76  }
77 
78  bool isDisposed() const noexcept
79  {
80  return m_pParentControl == nullptr;
81  }
82  virtual void DisposeThis()
83  {
85  m_pParentControl = nullptr;
86  }
87 
88  bool isRectDirty() const
89  {
91  return(!m_rectDirty.IsRectEmpty());
92  }
93  const cRectI& get_RectDirty() const
94  {
95  return m_rectDirty;
96  }
97  void addRectDirty(const RECT* pRect = nullptr);
98 
99  virtual HRESULT InitInstance() = 0;
100  virtual bool CheckRectDirty()
101  {
102  return isRectDirty();
103  }
104  virtual HRESULT DrawControl(HDC hDC, DWORD dwDrawAspect) = 0;
105  virtual LRESULT OnWindowMessage1(MSG& sMsg);
106  };
107 
108  class GRAYLIB_LINK cOleControl
109  : public cRefBase
110  {
116 
117  friend class cOleWindowless;
118  friend class cOleWindowProxy;
119  friend class cOleClientSite;
120 
121  public:
122  cIUnkPtr<IOleObject> m_pOleObject;
123 
124  HWND m_hWndParent;
125  const INT_PTR m_nChildId;
126  cRectI m_rectClient;
127 
128  protected:
129  cOSModule m_OleLib;
130  THREADID_t m_nThreadIdCreated;
131 
132  // Interfaces derived from m_pOleObject
133  cIUnkPtr<IOleInPlaceObject> m_pInPlaceObject;
134  cIUnkPtr<IViewObjectEx> m_pViewObject;
135  DWORD m_uViewStatus;
136 
137  OLE_WINDOW_TYPE m_eWindowType;
138  cWindow m_wndFrame;
139  cRefPtr<cOleWindowBase> m_pOleWindowBase;
140  cRefPtr<cOleClientSite> m_pOleClientSite;
141 
142  cOleWebBrowserRedir* m_pWebBrowserRedir;
143  OLE_WINDOW_TYPE m_eDesireWindowType;
144  bool m_bDesireTransparent;
145 
146  private:
147  cStringA m_sName;
148 
149  protected:
150  cOleControl(INT_PTR nChildId, cOleWebBrowserRedir* pBrowserRedir);
151  virtual ~cOleControl();
152 
153  HRESULT ActivateOleControl();
154  HRESULT LoadOleControl(const GUID& rguid, const FILECHAR_t* pszDllName);
155  HRESULT CreateWindowFrame(const GChar_t* pszClassName, const GChar_t* pszFullPath);
156 
157  cOleWindowless* get_OleWindowless() const;
158  cOleWindowProxy* get_OleWindowProxy() const;
159 
160  HRESULT ReturnError(HRESULT hRes) const;
161 
162  public:
163  virtual HRESULT InitOleControl(OLE_WINDOW_TYPE eDesireWindowType, bool bDesireTransparent = false) = 0;
164  virtual HRESULT LoadOleContent(const FILECHAR_t* pszFullPath) = 0;
165 
166  virtual bool isDisposed() const = 0;
167  virtual void DisposeThis();
168 
169  cStringA get_Name() const
170  {
172  return m_sName;
173  }
174  virtual void put_Name(const char* pszName);
175  void put_Name(BSTR bsName);
176  void put_Name(VARIANT* pvName);
177 
178  HWND get_WndParent() const
179  {
181  return m_hWndParent;
182  }
183  void put_WndParent(HWND hWndParent);
184 
185  HWND get_WndFrame() const;
186 
187  const cRectI& get_Rect() const
188  {
189  return m_rectClient;
190  }
191  HRESULT SetRect(const cRectI& rectNew, int iForceChange=0);
192  HRESULT put_Rect(const cRectI& rectNew)
193  {
194  return SetRect(rectNew, 1);
195  }
196 
197  bool CheckRectDirty();
198  HRESULT TestViewStatus();
199 
200  virtual tagREADYSTATE get_ReadyState() const;
201  HRESULT WaitForReadyState(TIMESYSD_t nTimeMax, bool bMsgLoop, int eReadyStateMin);
202 
203  virtual HRESULT DrawControl(HDC hDC, DWORD dwDrawAspect = DVASPECT_CONTENT);
204 
205 #ifdef USE_DX9
206  virtual HRESULT DrawControl(IDirect3DSurface9* pSurface);
207 #endif
208 
209  virtual LRESULT OnWindowMessage1(MSG& msg);
210  LRESULT OnWindowMessage(HWND hWndSrc, WINMSG_t msg, WPARAM wParam, LPARAM lParam);
211 
212  bool isMouseHit(const POINT& pt) const;
213  virtual void OnMouseMove(MBUTTON_TYPE button, const POINT& pt);
214 
215  bool isCreationThread() const
216  {
218  if (m_nThreadIdCreated == cThreadId::k_NULL)
219  return true;
220  if (m_nThreadIdCreated == cThreadId::GetCurrentId())
221  return true;
222  return false;
223  }
224  };
225 
226  typedef cRefPtr<cOleControl> cOleControlPtr;
227 }
228 #endif
229 #endif
MIDL_INTERFACE("7ED943DD-52E8-40b5-A8D8-76685C406330") ID3DXBaseMesh
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
UINT WINMSG_t
Supplement _WIN32 "windows.h".
Definition: WinTypes.h:111
#define ASSERT(exp)
Definition: cDebugAssert.h:87
static THREADID_t GetCurrentId() noexcept
Definition: cThreadLock.h:97
static const THREADID_t k_NULL
Not a valid thread Id.
Definition: cThreadLock.h:64
Definition: cMesh.h:22
MBUTTON_TYPE
Definition: cInputBase.h:40
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
cStringT< char > cStringA
Definition: cString.h:635
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
static void Zero(void *pData, size_t nSizeBlock) noexcept
Definition: cMem.h:100
Definition: IUnknown.h:34