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.

278 lines
8.2 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: FileExt.cpp
  7. //
  8. // Contents: file extension property page
  9. //
  10. // Classes: CFileExt
  11. //
  12. // History: 03-14-1998 stevebl Commented
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "precomp.hxx"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CFileExt property page
  23. IMPLEMENT_DYNCREATE(CFileExt, CPropertyPage)
  24. CFileExt::CFileExt() : CPropertyPage(CFileExt::IDD)
  25. {
  26. //{{AFX_DATA_INIT(CFileExt)
  27. // NOTE: the ClassWizard will add member initialization here
  28. //}}AFX_DATA_INIT
  29. m_pIClassAdmin = NULL;
  30. }
  31. CFileExt::~CFileExt()
  32. {
  33. *m_ppThis = NULL;
  34. if (m_pIClassAdmin)
  35. {
  36. m_pIClassAdmin->Release();
  37. }
  38. }
  39. void CFileExt::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CPropertyPage::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CFileExt)
  43. // NOTE: the ClassWizard will add DDX and DDV calls here
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CFileExt, CPropertyPage)
  47. //{{AFX_MSG_MAP(CFileExt)
  48. ON_BN_CLICKED(IDC_BUTTON1, OnMoveUp)
  49. ON_BN_CLICKED(IDC_BUTTON2, OnMoveDown)
  50. ON_CBN_SELCHANGE(IDC_COMBO1, OnExtensionChanged)
  51. ON_WM_CONTEXTMENU()
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CFileExt message handlers
  56. void CFileExt::OnMoveUp()
  57. {
  58. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  59. int i = pList->GetCurSel();
  60. if (i != LB_ERR && i > 0)
  61. {
  62. // change the selection
  63. CComboBox * pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  64. CString sz;
  65. pCombo->GetLBText(pCombo->GetCurSel(), sz);
  66. EXT & Ext = m_Extensions[sz];
  67. Ext.fDirty = TRUE;
  68. EXTEL t = Ext.v[i-1];
  69. Ext.v[i-1] = Ext.v[i];
  70. Ext.v[i] = t;
  71. pList->GetText(i, sz);
  72. pList->DeleteString(i);
  73. pList->InsertString(i-1, sz);
  74. pList->SetCurSel(i-1);
  75. SetModified();
  76. }
  77. }
  78. void CFileExt::OnMoveDown()
  79. {
  80. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  81. int i = pList->GetCurSel();
  82. if (i != LB_ERR && i < pList->GetCount()-1)
  83. {
  84. // change the selection
  85. CComboBox * pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  86. CString sz;
  87. pCombo->GetLBText(pCombo->GetCurSel(), sz);
  88. EXT & Ext = m_Extensions[sz];
  89. Ext.fDirty = TRUE;
  90. EXTEL t = Ext.v[i+1];
  91. Ext.v[i+1] = Ext.v[i];
  92. Ext.v[i] = t;
  93. pList->GetText(i+1, sz);
  94. pList->DeleteString(i+1);
  95. pList->InsertString(i, sz);
  96. pList->SetCurSel(i+1);
  97. SetModified();
  98. }
  99. }
  100. void CFileExt::OnExtensionChanged()
  101. {
  102. CComboBox * pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  103. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  104. CString szExt;
  105. pCombo->GetLBText(pCombo->GetCurSel(), szExt);
  106. pList->ResetContent();
  107. pList->SetHorizontalExtent(0);
  108. if (szExt.IsEmpty())
  109. {
  110. return; // nothing to do if there are no entries
  111. }
  112. // First check to see if we already have set up our own data for this extension.
  113. if (m_Extensions.end() == m_Extensions.find(szExt))
  114. {
  115. // need to set up our list
  116. EXT Ext;
  117. Ext.fDirty = FALSE;
  118. EXTLIST::iterator i;
  119. EXTLIST & ExtList = m_pScopePane->m_Extensions[szExt];
  120. for (i = ExtList.begin(); i != ExtList.end(); i++)
  121. {
  122. EXTEL ExtEl;
  123. ExtEl.lCookie = *i;
  124. // look for the entry that matches this file extension
  125. CAppData & data = m_pScopePane->m_AppData[*i];
  126. UINT n2 = data.m_pDetails->pActInfo->cShellFileExt;
  127. while (n2--)
  128. {
  129. if (0 == szExt.CompareNoCase(data.m_pDetails->pActInfo->prgShellFileExt[n2]))
  130. {
  131. break;
  132. }
  133. }
  134. ExtEl.lPriority = data.m_pDetails->pActInfo->prgPriority[n2];
  135. Ext.v.push_back(ExtEl);
  136. }
  137. order_EXTEL func;
  138. sort(Ext.v.begin(), Ext.v.end(), func);
  139. m_Extensions[szExt] = Ext;
  140. }
  141. vector<EXTEL>::iterator i;
  142. EXT & Ext = m_Extensions[szExt];
  143. for (i = Ext.v.begin(); i != Ext.v.end(); i++)
  144. {
  145. CString sz = m_pScopePane->m_AppData[i->lCookie].m_pDetails->pszPackageName;
  146. pList->AddString(sz);
  147. CDC * pDC = pList->GetDC();
  148. CSize size = pDC->GetTextExtent(sz);
  149. pDC->LPtoDP(&size);
  150. pList->ReleaseDC(pDC);
  151. if (pList->GetHorizontalExtent() < size.cx)
  152. {
  153. pList->SetHorizontalExtent(size.cx);
  154. }
  155. }
  156. pList->SetCurSel(0);
  157. int n = pList->GetCount();
  158. GetDlgItem(IDC_BUTTON1)->EnableWindow(n > 1);
  159. GetDlgItem(IDC_BUTTON2)->EnableWindow(n > 1);
  160. if (NULL == GetFocus())
  161. {
  162. GetParent()->GetDlgItem(IDOK)->SetFocus();
  163. }
  164. }
  165. BOOL CFileExt::OnInitDialog()
  166. {
  167. RefreshData();
  168. CPropertyPage::OnInitDialog();
  169. return TRUE; // return TRUE unless you set the focus to a control
  170. // EXCEPTION: OCX Property Pages should return FALSE
  171. }
  172. BOOL CFileExt::OnApply()
  173. {
  174. HRESULT hr = S_OK;
  175. map <CString, EXT>::iterator iExt;
  176. // walk the list looking for dirty entries
  177. for (iExt = m_Extensions.begin(); iExt != m_Extensions.end(); iExt++)
  178. {
  179. if (iExt->second.fDirty)
  180. {
  181. ULONG uPriority = iExt->second.v.size();
  182. vector<EXTEL>::iterator i;
  183. for (i = iExt->second.v.begin(); i != iExt->second.v.end(); i++)
  184. {
  185. CAppData & data = m_pScopePane->m_AppData[i->lCookie];
  186. CString sz = data.m_pDetails->pszPackageName;
  187. ASSERT(m_pIClassAdmin);
  188. hr = m_pIClassAdmin->SetPriorityByFileExt((LPOLESTR)((LPCOLESTR)sz), (LPOLESTR)((LPCOLESTR)iExt->first), --uPriority);
  189. // look for the entry that matches this file extension
  190. UINT n2 = data.m_pDetails->pActInfo->cShellFileExt;
  191. while (n2--)
  192. {
  193. if (0 == iExt->first.CompareNoCase(data.m_pDetails->pActInfo->prgShellFileExt[n2]))
  194. {
  195. break;
  196. }
  197. }
  198. data.m_pDetails->pActInfo->prgPriority[n2] = uPriority;
  199. }
  200. iExt->second.fDirty = FALSE;
  201. }
  202. }
  203. if (FAILED(hr))
  204. {
  205. CString sz;
  206. sz.LoadString(IDS_CHANGEFAILED);
  207. ReportGeneralPropertySheetError(m_hWnd, sz, hr);
  208. return FALSE;
  209. }
  210. return CPropertyPage::OnApply();
  211. }
  212. LRESULT CFileExt::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  213. {
  214. switch (message)
  215. {
  216. case WM_HELP:
  217. StandardHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, IDD);
  218. return 0;
  219. case WM_USER_REFRESH:
  220. RefreshData();
  221. return 0;
  222. case WM_USER_CLOSE:
  223. return GetOwner()->SendMessage(WM_CLOSE);
  224. default:
  225. return CPropertyPage::WindowProc(message, wParam, lParam);
  226. }
  227. }
  228. void CFileExt::RefreshData(void)
  229. {
  230. CComboBox * pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  231. pCombo->ResetContent();
  232. if (m_pIClassAdmin)
  233. {
  234. // only populate the extension list when we have an IClassAdmin interface
  235. map <CString, EXTLIST>::iterator iExt;
  236. for (iExt=m_pScopePane->m_Extensions.begin(); iExt != m_pScopePane->m_Extensions.end(); iExt++)
  237. {
  238. pCombo->AddString(iExt->first);
  239. }
  240. }
  241. pCombo->SetCurSel(0);
  242. // clear the record of extension changes
  243. m_Extensions.erase(m_Extensions.begin(), m_Extensions.end());
  244. // and populate the list box
  245. SetModified(FALSE);
  246. OnExtensionChanged();
  247. }
  248. void CFileExt::OnContextMenu(CWnd* pWnd, CPoint point)
  249. {
  250. StandardContextMenu(pWnd->m_hWnd, IDD_FILE_EXT);
  251. }