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.

222 lines
6.4 KiB

  1. // FileExt.cpp : implementation file
  2. //
  3. #include "precomp.hxx"
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #undef THIS_FILE
  7. static char THIS_FILE[] = __FILE__;
  8. #endif
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CFileExt property page
  11. IMPLEMENT_DYNCREATE(CFileExt, CPropertyPage)
  12. CFileExt::CFileExt() : CPropertyPage(CFileExt::IDD)
  13. {
  14. //{{AFX_DATA_INIT(CFileExt)
  15. // NOTE: the ClassWizard will add member initialization here
  16. //}}AFX_DATA_INIT
  17. }
  18. CFileExt::~CFileExt()
  19. {
  20. *m_ppThis = NULL;
  21. }
  22. void CFileExt::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CPropertyPage::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CFileExt)
  26. // NOTE: the ClassWizard will add DDX and DDV calls here
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(CFileExt, CPropertyPage)
  30. //{{AFX_MSG_MAP(CFileExt)
  31. ON_BN_CLICKED(IDC_BUTTON1, OnMoveUp)
  32. ON_BN_CLICKED(IDC_BUTTON2, OnMoveDown)
  33. ON_CBN_SELCHANGE(IDC_COMBO1, OnExtensionChanged)
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CFileExt message handlers
  38. void CFileExt::OnMoveUp()
  39. {
  40. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  41. int i = pList->GetCurSel();
  42. if (i > 0)
  43. {
  44. // change the selection
  45. CComboBox * pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  46. CString sz;
  47. pCombo->GetLBText(pCombo->GetCurSel(), sz);
  48. EXT & Ext = m_Extensions[sz];
  49. Ext.fDirty = TRUE;
  50. EXTEL t = Ext.v[i-1];
  51. Ext.v[i-1] = Ext.v[i];
  52. Ext.v[i] = t;
  53. pList->GetText(i, sz);
  54. pList->DeleteString(i);
  55. pList->InsertString(i-1, sz);
  56. pList->SetCurSel(i-1);
  57. SetModified();
  58. }
  59. }
  60. void CFileExt::OnMoveDown()
  61. {
  62. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  63. int i = pList->GetCurSel();
  64. if (i < pList->GetCount()-1)
  65. {
  66. // change the selection
  67. CComboBox * pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  68. CString sz;
  69. pCombo->GetLBText(pCombo->GetCurSel(), sz);
  70. EXT & Ext = m_Extensions[sz];
  71. Ext.fDirty = TRUE;
  72. EXTEL t = Ext.v[i+1];
  73. Ext.v[i+1] = Ext.v[i];
  74. Ext.v[i] = t;
  75. pList->GetText(i+1, sz);
  76. pList->DeleteString(i+1);
  77. pList->InsertString(i, sz);
  78. pList->SetCurSel(i+1);
  79. SetModified();
  80. }
  81. }
  82. void CFileExt::OnExtensionChanged()
  83. {
  84. CComboBox * pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  85. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  86. CString szExt;
  87. pCombo->GetLBText(pCombo->GetCurSel(), szExt);
  88. pList->ResetContent();
  89. // First check to see if we already have set up our own data for this extension.
  90. if (m_Extensions.end() == m_Extensions.find(szExt))
  91. {
  92. // need to set up our list
  93. EXT Ext;
  94. Ext.fDirty = FALSE;
  95. EXTLIST::iterator i;
  96. EXTLIST & ExtList = m_pCDI->m_Extensions[szExt];
  97. for (i = ExtList.begin(); i != ExtList.end(); i++)
  98. {
  99. EXTEL ExtEl;
  100. ExtEl.lCookie = *i;
  101. // look for the entry that matches this file extension
  102. APP_DATA & data = m_pCDI->m_AppData[*i];
  103. UINT n2 = data.pDetails->pActInfo->cShellFileExt;
  104. while (n2--)
  105. {
  106. if (0 == szExt.CompareNoCase(data.pDetails->pActInfo->prgShellFileExt[n2]))
  107. {
  108. break;
  109. }
  110. }
  111. ExtEl.lPriority = data.pDetails->pActInfo->prgPriority[n2];
  112. Ext.v.push_back(ExtEl);
  113. }
  114. order_EXTEL func;
  115. std::sort(Ext.v.begin(), Ext.v.end(), func);
  116. m_Extensions[szExt] = Ext;
  117. }
  118. std::vector<EXTEL>::iterator i;
  119. EXT & Ext = m_Extensions[szExt];
  120. for (i = Ext.v.begin(); i != Ext.v.end(); i++)
  121. {
  122. CString sz = m_pCDI->m_AppData[i->lCookie].pDetails->pszPackageName;
  123. pList->AddString(sz);
  124. }
  125. pList->SetCurSel(0);
  126. }
  127. BOOL CFileExt::OnInitDialog()
  128. {
  129. RefreshData();
  130. CPropertyPage::OnInitDialog();
  131. // unmarshal the IClassAdmin interface
  132. HRESULT hr = CoGetInterfaceAndReleaseStream(m_pIStream, IID_IClassAdmin, (void **) &m_pIClassAdmin);
  133. return TRUE; // return TRUE unless you set the focus to a control
  134. // EXCEPTION: OCX Property Pages should return FALSE
  135. }
  136. BOOL CFileExt::OnApply()
  137. {
  138. std::map <CString, EXT>::iterator iExt;
  139. // walk the list looking for dirty entries
  140. for (iExt = m_Extensions.begin(); iExt != m_Extensions.end(); iExt++)
  141. {
  142. if (iExt->second.fDirty)
  143. {
  144. ULONG uPriority = iExt->second.v.size();
  145. std::vector<EXTEL>::iterator i;
  146. for (i = iExt->second.v.begin(); i != iExt->second.v.end(); i++)
  147. {
  148. APP_DATA & data = m_pCDI->m_AppData[i->lCookie];
  149. CString sz = data.pDetails->pszPackageName;
  150. m_pIClassAdmin->SetPriorityByFileExt((LPOLESTR)((LPCOLESTR)sz), (LPOLESTR)((LPCOLESTR)iExt->first), --uPriority);
  151. // look for the entry that matches this file extension
  152. UINT n2 = data.pDetails->pActInfo->cShellFileExt;
  153. while (n2--)
  154. {
  155. if (0 == iExt->first.CompareNoCase(data.pDetails->pActInfo->prgShellFileExt[n2]))
  156. {
  157. break;
  158. }
  159. }
  160. data.pDetails->pActInfo->prgPriority[n2] = uPriority;
  161. }
  162. iExt->second.fDirty = FALSE;
  163. }
  164. }
  165. return CPropertyPage::OnApply();
  166. }
  167. LRESULT CFileExt::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  168. {
  169. switch (message)
  170. {
  171. case WM_USER_REFRESH:
  172. RefreshData();
  173. return 0;
  174. case WM_USER_CLOSE:
  175. return GetOwner()->SendMessage(WM_CLOSE);
  176. default:
  177. return CPropertyPage::WindowProc(message, wParam, lParam);
  178. }
  179. }
  180. void CFileExt::RefreshData(void)
  181. {
  182. CComboBox * pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  183. pCombo->ResetContent();
  184. std::map <CString, EXTLIST>::iterator iExt;
  185. for (iExt=m_pCDI->m_Extensions.begin(); iExt != m_pCDI->m_Extensions.end(); iExt++)
  186. {
  187. pCombo->AddString(iExt->first);
  188. }
  189. pCombo->SetCurSel(0);
  190. // clear the record of extension changes
  191. m_Extensions.erase(m_Extensions.begin(), m_Extensions.end());
  192. // and populate the list box
  193. SetModified(FALSE);
  194. OnExtensionChanged();
  195. }