Leaked source code of windows server 2003
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.

137 lines
3.1 KiB

  1. //
  2. // autocmpl.cpp: provides autocomplete functionality to and edit box
  3. //
  4. // Copyright Microsoft Corporation 2000
  5. //
  6. // nadima
  7. #include "stdafx.h"
  8. #ifndef OS_WINCE
  9. #define TRC_GROUP TRC_GROUP_UI
  10. #define TRC_FILE "proplocalres"
  11. #include <atrcapi.h>
  12. #include "autocmpl.h"
  13. #include "enumsrvmru.h"
  14. #include "shldisp.h"
  15. #include "shlguid.h"
  16. #include "sh.h"
  17. HRESULT CAutoCompl::EnableServerAutoComplete(CTscSettings* pTscSet, HWND hwndEdit)
  18. {
  19. DC_BEGIN_FN("EnableAutoComplete");
  20. HRESULT hr = E_FAIL;
  21. IAutoComplete* pac = NULL;
  22. IAutoComplete2* pac2 = NULL;
  23. IUnknown* punkSource = NULL;
  24. CEnumSrvMru* penSrvMru = NULL;
  25. if(!pTscSet || !hwndEdit)
  26. {
  27. return E_INVALIDARG;
  28. }
  29. //
  30. // Enable server autocomplete on the edit box
  31. // this invloves setting up a custom autocomplete source
  32. //
  33. hr = CoCreateInstance(CLSID_AutoComplete, NULL, CLSCTX_INPROC_SERVER,
  34. IID_IAutoComplete, (LPVOID*)&pac);
  35. if(FAILED(hr))
  36. {
  37. TRC_ERR((TB,(_T("create CLSID_AutoComplete failed"))));
  38. DC_QUIT;
  39. }
  40. hr = pac->QueryInterface(IID_IAutoComplete2, (LPVOID*)&pac2);
  41. if(FAILED(hr))
  42. {
  43. TRC_ERR((TB,_T("QI for IID_IAutoComplete2 failed 0x%x"),
  44. hr));
  45. //
  46. // It is CRITICAL to bail out of we can't get this interface
  47. // because lower platforms seem to mess up completely
  48. // and corrupt everything if they don't have the full support
  49. // for IAutoComplete2.
  50. //
  51. DC_QUIT;
  52. }
  53. //
  54. // Create custom autocomplete source
  55. //
  56. penSrvMru = new CEnumSrvMru();
  57. if(!penSrvMru)
  58. {
  59. hr = E_OUTOFMEMORY;
  60. DC_QUIT;
  61. }
  62. if(!penSrvMru->InitializeFromTscSetMru( pTscSet))
  63. {
  64. TRC_ERR((TB,(_T("InitializeFromTscSetMru failed"))));
  65. hr = E_FAIL;
  66. DC_QUIT;
  67. }
  68. hr = penSrvMru->QueryInterface(IID_IUnknown, (void**) &punkSource);
  69. if(FAILED(hr))
  70. {
  71. TRC_ERR((TB,(_T("QI custom autocomplete src for IUnknown failed"))));
  72. DC_QUIT;
  73. }
  74. //We're done with penSrvMru we'll just use the IUnknown interface
  75. //from now one
  76. penSrvMru->Release();
  77. penSrvMru = NULL;
  78. hr = pac->Init( hwndEdit, punkSource, NULL, NULL);
  79. if(FAILED(hr))
  80. {
  81. TRC_ERR((TB,(_T("Autocomplete Init failed"))));
  82. DC_QUIT;
  83. }
  84. hr = pac2->SetOptions(ACO_AUTOSUGGEST | ACO_AUTOAPPEND);
  85. if(FAILED(hr))
  86. {
  87. TRC_ERR((TB,_T("IAutoComplete2::SetOptions failed 0x%x"),
  88. hr));
  89. DC_QUIT;
  90. }
  91. //Success
  92. TRC_NRM((TB,(_T("Autocomplete Init SUCCEEDED"))));
  93. hr = S_OK;
  94. DC_EXIT_POINT:
  95. DC_END_FN();
  96. if(pac2)
  97. {
  98. pac2->Release();
  99. pac2 = NULL;
  100. }
  101. if(pac)
  102. {
  103. pac->Release();
  104. pac = NULL;
  105. }
  106. if(penSrvMru)
  107. {
  108. penSrvMru->Release();
  109. penSrvMru = NULL;
  110. }
  111. if(punkSource)
  112. {
  113. punkSource->Release();
  114. punkSource = NULL;
  115. }
  116. return hr;
  117. }
  118. #endif //OS_WINCE