Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
6.7 KiB

  1. #include "stdinc.h"
  2. #include <string>
  3. #include "ihost.h"
  4. #include "ithunk.h"
  5. #include "idsource.h"
  6. #include "iuiview.h"
  7. #include "atlhost.h"
  8. #include "SxApwHandle.h"
  9. #include "SxApwCreate.h"
  10. #include "HostFrame.h"
  11. #include "host2.h"
  12. #include "create.h"
  13. #include "resource.h"
  14. using namespace std;
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. static ATL::CComModule Module;
  21. _ATL_FUNC_INFO s_OnClickSignature = {CC_STDCALL, VT_EMPTY, 0 };
  22. BEGIN_OBJECT_MAP(ObjectMap)
  23. OBJECT_ENTRY(__uuidof(CSxApwHost), CSxApwHost)
  24. OBJECT_ENTRY(__uuidof(CSxApwHostThunk), CSxApwHostThunk)
  25. OBJECT_ENTRY(__uuidof(CSxApwDataSourceThunk), CSxApwDataSourceThunk)
  26. OBJECT_ENTRY(__uuidof(CSxApwUiViewThunk), CSxApwUiViewThunk)
  27. END_OBJECT_MAP()
  28. ATL::CComModule* GetModule() { return &Module; }
  29. ATL::_ATL_OBJMAP_ENTRY* GetObjectMap() { return ObjectMap; }
  30. const CLSID* GetTypeLibraryId() { return NULL; }
  31. STDMETHODIMP
  32. CSxApwHost::OnRowCountEstimateAvailable(
  33. int nRows
  34. )
  35. {
  36. /*
  37. just multiplex/broadcast the data across all the views..
  38. */
  39. for (CViews::const_iterator i = m_views.begin(); i != m_views.end() ; ++i)
  40. {
  41. i->m_iuiview->OnRowCountEstimateAvailable(nRows);
  42. }
  43. return S_OK;
  44. }
  45. STDMETHODIMP
  46. CSxApwHost::OnNextRow(
  47. int nColumns,
  48. const PCWSTR* columns
  49. )
  50. {
  51. /*
  52. just multiplex/broadcast the data across all the views..
  53. */
  54. for (CViews::const_iterator i = m_views.begin(); i != m_views.end() ; ++i)
  55. {
  56. i->m_iuiview->OnNextRow(nColumns, columns);
  57. }
  58. return S_OK;
  59. }
  60. HRESULT STDMETHODCALLTYPE
  61. CSxApwHost::InformSchema(
  62. const SxApwColumnInfo rgColumnInfo[],
  63. int nColumnCount
  64. )
  65. {
  66. /*
  67. just multiplex/broadcast the data across all the views..
  68. */
  69. for (CViews::const_iterator i = m_views.begin(); i != m_views.end() ; ++i)
  70. {
  71. i->m_iuiview->InformSchema(rgColumnInfo, nColumnCount);
  72. }
  73. return S_OK;
  74. }
  75. STDMETHODIMP
  76. CSxApwHost::SetDataSource(
  77. LPCWSTR datasource
  78. )
  79. {
  80. HRESULT hr;
  81. if (FAILED(hr = SxApwHostCreateObject(datasource, SXAPW_CREATEOBJECT_WRAP, m_dataSource)))
  82. goto Exit;
  83. if (FAILED(hr = m_dataSource->SetSite(this)))
  84. goto Exit;
  85. Exit:
  86. return hr;
  87. }
  88. STDMETHODIMP
  89. CSxApwHost::DestroyView(
  90. LPCWSTR viewstr
  91. )
  92. {
  93. HRESULT hr = S_OK;
  94. CView key;
  95. key.m_string = viewstr;
  96. CViews::iterator i = m_views.find(key);
  97. if (i == m_views.end())
  98. {
  99. hr = S_OK;
  100. goto Exit;
  101. }
  102. i->m_axMdiChild.DestroyWindow();
  103. m_views.erase(i);
  104. MdiTile();
  105. hr = S_OK;
  106. Exit:
  107. return hr;
  108. }
  109. void CSxApwHost::MdiTile()
  110. {
  111. SendMessageW(m_mdiClient, WM_MDITILE, MDITILE_VERTICAL, 0);
  112. //SendMessageW(m_mdiClient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
  113. }
  114. STDMETHODIMP
  115. CSxApwHost::CreateView(
  116. LPCWSTR viewstr
  117. )
  118. {
  119. HRESULT hr = 0;
  120. RECT rc = { 0 };
  121. MDICREATESTRUCT mdiCreateStruct = { 0 };
  122. CREATESTRUCT createStruct = { 0 };
  123. wstring sTemp;
  124. wstring sTitle;
  125. sTemp.assign( viewstr );
  126. if (sTemp.find( L"comctl32_v6") != wstring::npos )
  127. {
  128. sTitle.assign(L"ComCtl32 v6");
  129. }
  130. else
  131. if (sTemp.find( L"comctl32_v5") != wstring::npos )
  132. {
  133. sTitle.assign(L"ComCtl32 v5");
  134. }
  135. else
  136. if (sTemp.find( L"comctl32") != wstring::npos )
  137. {
  138. sTitle.assign(L"ComCtl32");
  139. }
  140. else
  141. if (sTemp.find( L"sxapwedit") != wstring::npos )
  142. {
  143. sTitle.assign(L"SxS ApW Edit");
  144. }
  145. else
  146. if (sTemp.find( L"sxapwstdout") != wstring::npos )
  147. {
  148. sTitle.assign(L"SxS ApW StdOut");
  149. }
  150. else
  151. {
  152. sTitle.assign(L"Views and Sources");
  153. }
  154. CView key;
  155. key.m_string = viewstr;
  156. CViewsConditionalInsertPair p = m_views.insert(key);
  157. if (!p.second)
  158. {
  159. hr = S_OK;
  160. goto Exit;
  161. }
  162. CView& view = *p.first;
  163. IFFALSE_WIN32TOHR_EXIT(hr, m_mdiClient.GetClientRect(&rc));
  164. createStruct.lpCreateParams = &mdiCreateStruct;
  165. IFFALSE_WIN32TOHR_EXIT(hr, view.m_axMdiChild.Create(m_mdiClient, rc, sTitle.c_str(), 0, 0, 0, &createStruct));
  166. view.m_axMdiChild.ShowWindow(SW_SHOWDEFAULT);
  167. if (FAILED(hr = SxApwHostCreateObject(viewstr, SXAPW_CREATEOBJECT_WRAP, view.m_iuiview)))
  168. goto Exit;
  169. if (FAILED(hr = view.m_iuiview->SetSite(this)))
  170. goto Exit;
  171. if (FAILED(hr = view.m_iuiview->CreateWindow(view.m_axMdiChild)))
  172. goto Exit;
  173. MdiTile();
  174. Exit:
  175. return hr;
  176. }
  177. STDMETHODIMP
  178. CSxApwHost::OnQueryDone(
  179. )
  180. {
  181. HRESULT hr = S_OK;
  182. for (CViews::const_iterator i = m_views.begin(); i != m_views.end() ; ++i)
  183. i->m_iuiview->OnQueryDone();
  184. return hr;
  185. }
  186. STDMETHODIMP
  187. CSxApwHost::RunQuery(
  188. LPCWSTR query
  189. )
  190. {
  191. HRESULT hr = S_OK;
  192. for (CViews::const_iterator i = m_views.begin(); i != m_views.end() ; ++i)
  193. i->m_iuiview->OnQueryStart();
  194. if (FAILED(hr = m_dataSource->RunQuery(query)))
  195. goto Exit;
  196. Exit:
  197. return hr;
  198. }
  199. HRESULT CSxApwHost::Main()
  200. {
  201. HRESULT hr = 0;
  202. RECT rc = { 0 };
  203. CREATESTRUCT createStruct = { 0 };
  204. CLIENTCREATESTRUCT clientCreateStruct = { 0 };
  205. int bRet = 0;
  206. MSG msg = { 0 };
  207. CSxApwHostFrame frameWindow;
  208. CoInitialize(NULL);
  209. GetComModule()->Init(ObjectMap, GetModuleHandleW(NULL));
  210. IFFALSE_WIN32TOHR_EXIT(hr, frameWindow.Create(NULL, ATL::CWindow::rcDefault, L"Fusion Win32 App Team AppWeek"));
  211. frameWindow.AddMenu();
  212. frameWindow.ShowWindow(SW_SHOWDEFAULT);
  213. IFFALSE_WIN32TOHR_EXIT(hr, frameWindow.GetClientRect(&rc));
  214. IFFALSE_WIN32TOHR_EXIT(hr, m_mdiClient.Create(frameWindow, rc, L"2", 0, 0, 0, &clientCreateStruct));
  215. frameWindow.m_hClient = m_mdiClient.m_hWnd;
  216. m_mdiClient.ShowWindow(SW_SHOWDEFAULT);
  217. if (FAILED(hr = CreateView(CLSID_CSxApwControllerView_brace_stringW)))
  218. goto Exit;
  219. while ((bRet = GetMessageW(&msg, NULL, 0, 0)) != 0
  220. && bRet != -1
  221. && msg.message != WM_QUIT
  222. )
  223. {
  224. TranslateMessage(&msg);
  225. DispatchMessageW(&msg);
  226. }
  227. hr = S_OK;
  228. Exit:
  229. return hr;
  230. }
  231. int __cdecl main()
  232. {
  233. // leak for now..
  234. ATL::CComObject<CSxApwHost>* host = new ATL::CComObject<CSxApwHost>;
  235. host->AddRef();
  236. host->Main();
  237. return 0;
  238. }