embedwndguid.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include "precomp__gen_ff.h"
  2. #include "embedwndguid.h"
  3. #include "wa2wndembed.h"
  4. #include "wa2frontend.h"
  5. #include "wa2cfgitems.h"
  6. #include <bfc/string/stringW.h>
  7. extern void initFFApi();
  8. EmbedWndGuidMgr embedWndGuidMgr;
  9. EmbedWndGuid::EmbedWndGuid(embedWindowState *_ws)
  10. {
  11. hwnd = NULL;
  12. guid = INVALID_GUID;
  13. if (_ws == NULL) return ;
  14. ws = _ws;
  15. hwnd = ws->me;
  16. embedWndGuidMgr.getGuid(this);
  17. }
  18. EmbedWndGuid::EmbedWndGuid(EmbedWndGuid *wg)
  19. {
  20. hwnd = NULL;
  21. guid = INVALID_GUID;
  22. if (wg == NULL) return ;
  23. ws = wg->getEmbedWindowState();
  24. hwnd = ws->me;
  25. guid = wg->getGuid();
  26. }
  27. GUID EmbedWndGuidMgr::getGuid(embedWindowState *ws)
  28. {
  29. foreach(table)
  30. EmbedWndGuid *ewg = table.getfor();
  31. if (ewg->getEmbedWindowState() == ws)
  32. {
  33. return ewg->getGuid();
  34. }
  35. endfor;
  36. return INVALID_GUID;
  37. }
  38. GUID EmbedWndGuidMgr::getGuid(EmbedWndGuid *wg)
  39. {
  40. if (wg == NULL) return INVALID_GUID;
  41. // if we aren't loaded yet, init wasabi, otherwise ignore
  42. initFFApi();
  43. int gotit = 0;
  44. int nowrite = 0;
  45. wchar_t windowTitle[256] = L"";
  46. HWND child;
  47. GUID newGuid = INVALID_GUID;
  48. if (wg->getEmbedWindowState()->flags & EMBED_FLAGS_GUID)
  49. {
  50. newGuid = GET_EMBED_GUID(wg->getEmbedWindowState());
  51. nowrite=1;
  52. goto bypass;
  53. }
  54. if (wa2.isVis(wg->getEmbedWindowState()->me))
  55. {
  56. newGuid = avs_guid;
  57. nowrite = 1;
  58. extern int disable_send_visrandom;
  59. extern _bool visrandom;
  60. wa2.pollVisRandom();
  61. goto bypass;
  62. }
  63. child = GetWindow(wg->getEmbedWindowState()->me, GW_CHILD);
  64. if (child == wa2.getMediaLibrary())
  65. { newGuid = library_guid; nowrite = 1; goto bypass; }
  66. if (!gotit)
  67. {
  68. foreach(table)
  69. EmbedWndGuid *ewg = table.getfor();
  70. if (ewg->getEmbedWindowState() == wg->getEmbedWindowState())
  71. {
  72. wg->setGuid(ewg->getGuid());
  73. gotit = 1;
  74. break;
  75. }
  76. endfor;
  77. }
  78. if (!gotit)
  79. {
  80. // not found, look for window title in saved table
  81. GetWindowTextW(wg->getEmbedWindowState()->me, windowTitle, 256);
  82. if (*windowTitle)
  83. {
  84. wchar_t str[256] = L"";
  85. StringW configString = windowTitle;
  86. configString += L"_guid";
  87. WASABI_API_CONFIG->getStringPrivate(configString, str, 256, L"");
  88. if (*str)
  89. {
  90. wg->setGuid(nsGUID::fromCharW(str));
  91. table.addItem(new EmbedWndGuid(wg));
  92. gotit = 1;
  93. }
  94. }
  95. }
  96. if (!gotit)
  97. {
  98. // not found in saved table, or no title for the window, assign a new guid
  99. if (!_wcsicmp(windowTitle, L"AVS"))
  100. { newGuid = avs_guid; nowrite = 1; }
  101. else
  102. CoCreateGuid(&newGuid);
  103. bypass:
  104. wg->setGuid(newGuid);
  105. // save a copy of the element
  106. table.addItem(new EmbedWndGuid(wg));
  107. // write the guid in the saved table
  108. if (*windowTitle && !nowrite)
  109. {
  110. wchar_t str[256] = {0};
  111. nsGUID::toCharW(newGuid, str);
  112. StringW configString = windowTitle;
  113. configString += L"_guid";
  114. WASABI_API_CONFIG->setStringPrivate(configString, str);
  115. }
  116. }
  117. return wg->getGuid();
  118. }
  119. embedWindowState *EmbedWndGuidMgr::getEmbedWindowState(GUID g)
  120. {
  121. foreach(table)
  122. EmbedWndGuid *ewg = table.getfor();
  123. if (ewg->getGuid() == g)
  124. {
  125. embedWindowState *ews = ewg->getEmbedWindowState();
  126. if (wa2.isValidEmbedWndState(ews))
  127. return ews;
  128. }
  129. endfor;
  130. return NULL;
  131. }
  132. void EmbedWndGuidMgr::retireEmbedWindowState(embedWindowState *ws)
  133. {
  134. foreach(table)
  135. EmbedWndGuid *ewg = table.getfor();
  136. if (ewg->getEmbedWindowState() == ws)
  137. {
  138. delete table.getfor();
  139. table.removeByPos(foreach_index);
  140. break;
  141. }
  142. endfor;
  143. }
  144. int EmbedWndGuidMgr::testGuid(GUID g)
  145. {
  146. // if (g == library_guid) return 1;
  147. // if (g == avs_guid) return 1;
  148. foreach(table)
  149. EmbedWndGuid *ewg = table.getfor();
  150. if (ewg->getGuid() == g)
  151. {
  152. if (!wa2.isValidEmbedWndState(ewg->getEmbedWindowState())) retireEmbedWindowState(ewg->getEmbedWindowState());
  153. else return 1;
  154. }
  155. endfor;
  156. return 0;
  157. }
  158. int EmbedWndGuidMgr::getNumWindowStates()
  159. {
  160. return table.getNumItems();
  161. }
  162. GUID EmbedWndGuidMgr::enumWindowState(int n, embedWindowState **ws)
  163. {
  164. EmbedWndGuid *ewg = table.enumItem(n);
  165. if (ewg)
  166. {
  167. embedWindowState *ews = ewg->getEmbedWindowState();
  168. if (wa2.isValidEmbedWndState(ews))
  169. {
  170. if (ws) *ws = ews;
  171. return ewg->getGuid();
  172. }
  173. }
  174. return INVALID_GUID;
  175. }