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.

939 lines
23 KiB

  1. // ActionDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Resource.h"
  5. #include "ActDlg.h"
  6. #include "FrSpace.h"
  7. #include "FTManDef.h"
  8. #include "Item.h"
  9. #include "LogVol.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. extern LV_COLUMN_CONFIG ColumnsConfig[];
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CActionDlg dialog
  18. CActionDlg::CActionDlg( CObArray* parrVolumeData, UINT nIDTemplate /* =IDD_GENERIC_ACTION */ ,
  19. BOOL bChangeOrder /* =TRUE */ , CWnd* pParent /* =NULL */)
  20. : CDialog(nIDTemplate, pParent), m_parrVolumeData( parrVolumeData ), m_bChangeOrder( bChangeOrder )
  21. {
  22. //{{AFX_DATA_INIT(CActionDlg)
  23. // NOTE: the ClassWizard will add member initialization here
  24. //}}AFX_DATA_INIT
  25. ASSERT( parrVolumeData );
  26. }
  27. void CActionDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CActionDlg)
  31. if( m_bChangeOrder )
  32. {
  33. DDX_Control(pDX, IDC_BUTTON_DOWN, m_buttonDown);
  34. DDX_Control(pDX, IDC_BUTTON_UP, m_buttonUp);
  35. }
  36. DDX_Control(pDX, IDC_LIST_VOLUMES, m_listVol);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CActionDlg, CDialog)
  40. //{{AFX_MSG_MAP(CActionDlg)
  41. ON_WM_DESTROY()
  42. ON_BN_CLICKED(IDC_BUTTON_UP, OnButtonUp)
  43. ON_BN_CLICKED(IDC_BUTTON_DOWN, OnButtonDown)
  44. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_VOLUMES, OnItemchangedListVolumes)
  45. ON_NOTIFY(LVN_KEYDOWN, IDC_LIST_VOLUMES, OnKeydownListVolumes)
  46. ON_NOTIFY(NM_CLICK, IDC_LIST_VOLUMES, OnClickListVolumes)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////////////////////
  50. // Protected methods
  51. // Insert a item ( with the given data ) at a certain position in the given list ctrl
  52. BOOL CActionDlg::InsertItem( CListCtrl& listCtrl, int iIndex, CItemData* pData )
  53. {
  54. MY_TRY
  55. ASSERT(pData);
  56. LVITEM lvitem;
  57. CString strDisplay;
  58. // 1. Insert the item
  59. lvitem.iItem = iIndex;
  60. ASSERT(LVC_Name==0); // The first SubItem must be zero
  61. lvitem.iSubItem = 0;
  62. pData->GetDisplayExtendedName(strDisplay);
  63. lvitem.pszText = (LPTSTR)(LPCTSTR)strDisplay;
  64. lvitem.iImage = pData->GetImageIndex();
  65. lvitem.lParam = (LPARAM)pData;
  66. lvitem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM ;
  67. int iActualItem = listCtrl.InsertItem( &lvitem );
  68. if( iActualItem < 0 )
  69. return FALSE;
  70. // 2. Set all subitems
  71. lvitem.iItem = iActualItem;
  72. lvitem.mask = LVIF_TEXT;
  73. // Disks set
  74. lvitem.iSubItem = 1;
  75. pData->GetDisplayDisksSet(strDisplay);
  76. lvitem.pszText = (LPTSTR)(LPCTSTR)strDisplay;
  77. listCtrl.SetItem( &lvitem );
  78. // Size
  79. lvitem.iSubItem = 2;
  80. pData->GetDisplaySize(strDisplay);
  81. lvitem.pszText = (LPTSTR)(LPCTSTR)strDisplay;
  82. listCtrl.SetItem( &lvitem );
  83. return TRUE;
  84. MY_CATCH_AND_THROW
  85. }
  86. // Move an item from the old index to a new index in the given list ctrl
  87. BOOL CActionDlg::MoveItem( CListCtrl& listCtrl, int iOldIndex, int iNewIndex )
  88. {
  89. MY_TRY
  90. ASSERT( ( iOldIndex >= 0 ) && ( iOldIndex < listCtrl.GetItemCount() ) );
  91. ASSERT( ( iNewIndex >= 0 ) && ( iNewIndex < listCtrl.GetItemCount() ) );
  92. if( iOldIndex == iNewIndex )
  93. return TRUE;
  94. // 1. Get the item information
  95. LVITEM lvitem;
  96. lvitem.iItem = iOldIndex;
  97. lvitem.iSubItem = 0;
  98. lvitem.mask = LVIF_PARAM;
  99. if( !listCtrl.GetItem(&lvitem) )
  100. return FALSE;
  101. CItemData* pData = (CItemData*)(lvitem.lParam);
  102. // 2. Delete the item at the old position
  103. if( !listCtrl.DeleteItem(iOldIndex) )
  104. return FALSE;
  105. // 3. Insert the item at the new position
  106. if ( !InsertItem( listCtrl, iNewIndex, pData ) )
  107. return FALSE;
  108. // 4. Select and focus again the item
  109. m_listVol.SetItemState( iNewIndex, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED );
  110. return TRUE;
  111. MY_CATCH_AND_THROW
  112. }
  113. // Prepare the given control list to display volume information
  114. void CActionDlg::ConfigureList ( CListCtrl& listCtrl )
  115. {
  116. MY_TRY
  117. if( m_ImageListSmall.GetSafeHandle() != NULL )
  118. listCtrl.SetImageList(&m_ImageListSmall, LVSIL_SMALL);
  119. // Insert columns (REPORT mode)
  120. CRect rect;
  121. listCtrl.GetWindowRect(&rect);
  122. // Add some columns ( not all columns from ColumnConfig are necessary in the dialog )
  123. // The name
  124. PLV_COLUMN_CONFIG pColumn = &(ColumnsConfig[LVC_Name]);
  125. CString str;
  126. if( !str.LoadString(pColumn->dwTitleID) )
  127. ASSERT(FALSE);
  128. listCtrl.InsertColumn( 0, str, pColumn->nFormat ,
  129. rect.Width() * 1/2, 0);
  130. // The disks set
  131. pColumn = &(ColumnsConfig[LVC_DiskNumber]);
  132. if( !str.LoadString(pColumn->dwTitleID) )
  133. ASSERT(FALSE);
  134. listCtrl.InsertColumn( 1, str, pColumn->nFormat ,
  135. rect.Width() * 1/6, 1);
  136. // The size
  137. pColumn = &(ColumnsConfig[LVC_Size]);
  138. if( !str.LoadString(pColumn->dwTitleID) )
  139. ASSERT(FALSE);
  140. listCtrl.InsertColumn( 2, str, pColumn->nFormat ,
  141. rect.Width() * 4/15, 2);
  142. MY_CATCH_AND_THROW
  143. }
  144. // Populate the given control list with the given volumes data
  145. // parrData should point to an array of CLVTreeItemData objects
  146. void CActionDlg::PopulateList ( CListCtrl& listCtrl, CObArray* parrData )
  147. {
  148. MY_TRY
  149. for( int i = 0; i < parrData->GetSize(); i++ )
  150. {
  151. CItemData* pData = (CItemData*)(parrData->GetAt(i));
  152. ASSERT(pData);
  153. InsertItem( listCtrl, i, pData );
  154. }
  155. MY_CATCH_AND_THROW
  156. }
  157. /////////////////////////////////////////////////////////////////////////////
  158. // CActionDlg message handlers
  159. BOOL CActionDlg::OnInitDialog()
  160. {
  161. MY_TRY
  162. CDialog::OnInitDialog();
  163. // TODO: Add extra initialization here
  164. // Set caption
  165. CString str;
  166. str.LoadString(IDS_ACTION_DLG_CAPTION);
  167. SetWindowText(str);
  168. // Create the image list small icons
  169. // The background color for mask is pink. All image's pixels of this color will take
  170. // the view's background color.
  171. if( !m_ImageListSmall.Create( IDB_IMAGELIST_SMALL, 16, 16, RGB( 255, 0, 255 ) ) )
  172. AfxMessageBox( IDS_ERR_CREATE_IMAGELIST, MB_ICONSTOP );
  173. // Configure and populate the list ctrl
  174. ConfigureList( m_listVol );
  175. ASSERT( m_parrVolumeData->GetSize() > 0 );
  176. PopulateList( m_listVol, m_parrVolumeData );
  177. // Select and focus the first item in the list ctrl
  178. if( m_listVol.GetItemCount() > 0 )
  179. m_listVol.SetItemState( 0, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED );
  180. MY_CATCH_REPORT_AND_CANCEL
  181. return TRUE; // return TRUE unless you set the focus to a control
  182. // EXCEPTION: OCX Property Pages should return FALSE
  183. }
  184. void CActionDlg::OnDestroy()
  185. {
  186. // Delete the image list
  187. m_ImageListSmall.DeleteImageList();
  188. CDialog::OnDestroy();
  189. }
  190. void CActionDlg::OnButtonUp()
  191. {
  192. MY_TRY
  193. ASSERT( m_bChangeOrder );
  194. int iItem = m_listVol.GetNextItem(-1, LVNI_SELECTED);
  195. if (iItem < 0 )
  196. {
  197. TRACE(_T("No items were selected!\n"));
  198. return;
  199. }
  200. if( iItem > 0 )
  201. {
  202. MoveItem( m_listVol, iItem, iItem-1 );
  203. m_listVol.EnsureVisible(iItem-1, FALSE);
  204. m_listVol.SetFocus();
  205. }
  206. MY_CATCH_REPORT_AND_CANCEL
  207. }
  208. void CActionDlg::OnButtonDown()
  209. {
  210. MY_TRY
  211. ASSERT( m_bChangeOrder );
  212. int iItem = m_listVol.GetNextItem(-1, LVNI_SELECTED);
  213. if (iItem < 0 )
  214. {
  215. TRACE(_T("No items were selected!\n"));
  216. return;
  217. }
  218. if( iItem < m_listVol.GetItemCount()-1 )
  219. {
  220. MoveItem( m_listVol, iItem, iItem+1 );
  221. m_listVol.EnsureVisible(iItem+1, FALSE);
  222. m_listVol.SetFocus();
  223. }
  224. MY_CATCH_REPORT_AND_CANCEL
  225. }
  226. void CActionDlg::OnItemchangedListVolumes(NMHDR* pNMHDR, LRESULT* pResult)
  227. {
  228. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  229. // TODO: Add your control notification handler code here
  230. // We are interested on items who received focus
  231. if( m_bChangeOrder &&
  232. ( pNMListView->uChanged & LVIF_STATE ) &&
  233. ( pNMListView->uNewState & LVIS_FOCUSED ) &&
  234. !( pNMListView->uOldState & LVIS_FOCUSED ) )
  235. {
  236. m_buttonUp.EnableWindow( pNMListView->iItem > 0 );
  237. m_buttonDown.EnableWindow( pNMListView->iItem < m_listVol.GetItemCount() - 1 );
  238. }
  239. *pResult = 0;
  240. }
  241. void CActionDlg::OnClickListVolumes(NMHDR* pNMHDR, LRESULT* pResult)
  242. {
  243. // TODO: Add your control notification handler code here
  244. POINT pt;
  245. GetCursorPos( &pt );
  246. LVHITTESTINFO lvhittestinfo;
  247. lvhittestinfo.pt = pt;
  248. m_listVol.ScreenToClient( &(lvhittestinfo.pt) );
  249. lvhittestinfo.pt.x = 4;
  250. int iItem = ListView_SubItemHitTest( m_listVol.GetSafeHwnd(), &lvhittestinfo );
  251. if( iItem >= 0 )
  252. m_listVol.SetItemState( iItem, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED );
  253. else
  254. {
  255. if( m_bChangeOrder )
  256. {
  257. // Disable buttons Up and Down because no item will be selected
  258. m_buttonUp.EnableWindow( FALSE );
  259. m_buttonDown.EnableWindow( FALSE );
  260. }
  261. }
  262. }
  263. void CActionDlg::OnOK()
  264. {
  265. MY_TRY
  266. // Just read the new order of members
  267. if( m_bChangeOrder )
  268. {
  269. m_parrVolumeData->RemoveAll();
  270. for( int i = 0; i < m_listVol.GetItemCount(); i++ )
  271. {
  272. LVITEM lvitem;
  273. lvitem.iItem = i;
  274. lvitem.iSubItem = 0;
  275. lvitem.mask = LVIF_PARAM;
  276. if( !m_listVol.GetItem(&lvitem) )
  277. return;
  278. CItemData* pData = (CItemData*)(lvitem.lParam);
  279. ASSERT(pData);
  280. m_parrVolumeData->Add( pData );
  281. }
  282. }
  283. CDialog::OnOK();
  284. MY_CATCH_REPORT_AND_CANCEL
  285. }
  286. void CActionDlg::OnKeydownListVolumes(NMHDR* pNMHDR, LRESULT* pResult)
  287. {
  288. if( !m_bChangeOrder )
  289. {
  290. *pResult = 0;
  291. return;
  292. }
  293. #pragma message("TODO: A keyboard hook would be more useful here")
  294. LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR;
  295. // TODO: Add your control notification handler code here
  296. // We are interested on:
  297. // SHIFT-UP or U equivalent with pressing button "Up"
  298. // SHIFT_DOWN or D equivalent with pressing button "Down"
  299. BOOL bIsShiftPressed = ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 );
  300. if( ( ( pLVKeyDown->wVKey == VK_DOWN ) && bIsShiftPressed ) ||
  301. ( pLVKeyDown->wVKey == 'D') )
  302. {
  303. OnButtonDown();
  304. *pResult = 1;
  305. return;
  306. }
  307. if( ( ( pLVKeyDown->wVKey == VK_UP ) && bIsShiftPressed ) ||
  308. ( pLVKeyDown->wVKey == 'U') )
  309. {
  310. OnButtonUp();
  311. *pResult = 1;
  312. return;
  313. }
  314. *pResult = 0;
  315. }
  316. /////////////////////////////////////////////////////////////////////////////
  317. // CCreateStripeDlg dialog
  318. CCreateStripeDlg::CCreateStripeDlg( CObArray* parrVolumeData,
  319. UINT nIDTemplate /* =IDD_CREATE_STRIPE */ ,CWnd* pParent /* =NULL */)
  320. : CActionDlg( parrVolumeData, nIDTemplate, TRUE, pParent)
  321. {
  322. //{{AFX_DATA_INIT(CCreateStripeDlg)
  323. // NOTE: the ClassWizard will add member initialization here
  324. //}}AFX_DATA_INIT
  325. m_ulStripeSize = 0x10000; // 64KB
  326. }
  327. void CCreateStripeDlg::DoDataExchange(CDataExchange* pDX)
  328. {
  329. CActionDlg::DoDataExchange(pDX);
  330. //{{AFX_DATA_MAP(CCreateStripeDlg)
  331. DDX_Control(pDX, IDC_COMBO_STRIPE_SIZE, m_comboStripeSize);
  332. //}}AFX_DATA_MAP
  333. }
  334. BEGIN_MESSAGE_MAP(CCreateStripeDlg, CActionDlg)
  335. //{{AFX_MSG_MAP(CCreateStripeDlg)
  336. //}}AFX_MSG_MAP
  337. END_MESSAGE_MAP()
  338. /////////////////////////////////////////////////////////////////////////////
  339. // CActionDlg message handlers
  340. BOOL CCreateStripeDlg::OnInitDialog()
  341. {
  342. MY_TRY
  343. CActionDlg::OnInitDialog();
  344. // Fill the stripe size combo with all powers of 2 between 8KB and 4MB
  345. for( ULONG ulStripeSize = 0x2000; ulStripeSize <= 0x400000; ulStripeSize = ( ulStripeSize << 1 ) )
  346. {
  347. CString strStripeSize;
  348. FormatVolumeSize( strStripeSize, ulStripeSize );
  349. int nIndex = m_comboStripeSize.AddString( strStripeSize );
  350. if( nIndex != CB_ERR )
  351. {
  352. m_comboStripeSize.SetItemData(nIndex, ulStripeSize );
  353. if( ulStripeSize == m_ulStripeSize )
  354. m_comboStripeSize.SetCurSel(nIndex);
  355. }
  356. }
  357. MY_CATCH_REPORT_AND_CANCEL
  358. return TRUE; // return TRUE unless you set the focus to a control
  359. // EXCEPTION: OCX Property Pages should return FALSE
  360. }
  361. void CCreateStripeDlg::OnOK()
  362. {
  363. // TODO: Add extra validation here
  364. int nIndex = m_comboStripeSize.GetCurSel();
  365. ASSERT( nIndex >= 0 );
  366. m_ulStripeSize = (ULONG)(m_comboStripeSize.GetItemData(nIndex));
  367. CActionDlg::OnOK();
  368. }
  369. /////////////////////////////////////////////////////////////////////////////
  370. // CBreakDlg dialog
  371. CBreakDlg::CBreakDlg( CLogicalVolumeData *pSetData, CObArray* parrMembersData,
  372. UINT nIDTemplate /* =IDD_BREAK */ , CWnd* pParent /* =NULL */ )
  373. : CActionDlg( parrMembersData, nIDTemplate, FALSE, pParent),
  374. m_pSetData(pSetData), m_nWinnerIndex(-1), m_nFocusedItem(-1)
  375. {
  376. MY_TRY
  377. //{{AFX_DATA_INIT(CBreakDlg)
  378. m_staticSetName = _T("");
  379. //}}AFX_DATA_INIT
  380. ASSERT( pSetData );
  381. m_pSetData->GetDisplayExtendedName(m_staticSetName);
  382. MY_CATCH_AND_REPORT
  383. }
  384. void CBreakDlg::DoDataExchange(CDataExchange* pDX)
  385. {
  386. CActionDlg::DoDataExchange(pDX);
  387. //{{AFX_DATA_MAP(CBreakDlg)
  388. DDX_Text(pDX, IDC_STATIC_SET_NAME, m_staticSetName);
  389. //}}AFX_DATA_MAP
  390. }
  391. BEGIN_MESSAGE_MAP(CBreakDlg, CActionDlg)
  392. //{{AFX_MSG_MAP(CBreakDlg)
  393. ON_NOTIFY(LVN_ITEMCHANGING, IDC_LIST_VOLUMES, OnItemchangingListVolumes)
  394. ON_NOTIFY(NM_CLICK, IDC_LIST_VOLUMES, OnClickListVolumes)
  395. //}}AFX_MSG_MAP
  396. END_MESSAGE_MAP()
  397. /////////////////////////////////////////////////////////////////////////////
  398. // CBreakDlg message handlers
  399. BOOL CBreakDlg::OnInitDialog()
  400. {
  401. CActionDlg::OnInitDialog();
  402. // Select and focus the first healthy member
  403. for( int i = 0; i < m_listVol.GetItemCount(); i++ )
  404. {
  405. CItemData* pData = (CItemData*)(m_listVol.GetItemData(i));
  406. ASSERT(pData);
  407. if( pData->GetMemberStatus() == FtMemberHealthy )
  408. {
  409. m_listVol.SetItemState( i, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED );
  410. break;
  411. }
  412. }
  413. return TRUE; // return TRUE unless you set the focus to a control
  414. // EXCEPTION: OCX Property Pages should return FALSE
  415. }
  416. void CBreakDlg::OnOK()
  417. {
  418. // Get the winner
  419. int iItem = m_listVol.GetNextItem(-1, LVNI_SELECTED);
  420. if (iItem < 0 )
  421. {
  422. TRACE(_T("No items were selected!\n"));
  423. return;
  424. }
  425. m_nWinnerIndex = iItem;
  426. CActionDlg::OnOK();
  427. }
  428. void CBreakDlg::OnItemchangingListVolumes(NMHDR* pNMHDR, LRESULT* pResult)
  429. {
  430. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  431. // TODO: Add your control notification handler code here
  432. if( pNMListView->uChanged & LVIF_STATE )
  433. {
  434. // If the item receives focus check whether the item is healthy or not
  435. if( ( pNMListView->uNewState & LVIS_FOCUSED ) &&
  436. !( pNMListView->uOldState & LVIS_FOCUSED ) )
  437. {
  438. CItemData* pMemberData = (CItemData*)(pNMListView->lParam);
  439. if( pMemberData->GetMemberStatus() == FtMemberHealthy )
  440. {
  441. // The member is healthy so proceed with item changing
  442. m_nFocusedItem = pNMListView->iItem;
  443. *pResult = 0;
  444. return;
  445. }
  446. else
  447. {
  448. // The member is not healthy so prevent item changing
  449. if( m_nFocusedItem >= 0 )
  450. {
  451. m_listVol.SetItemState( m_nFocusedItem, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED );
  452. m_listVol.RedrawItems( m_nFocusedItem, m_nFocusedItem );
  453. }
  454. *pResult = 1;
  455. return;
  456. }
  457. }
  458. // If the item has the focus but looses selection then prevent this to happen
  459. if( !( pNMListView->uNewState & LVIS_SELECTED ) &&
  460. ( pNMListView->uOldState & LVIS_SELECTED ) )
  461. {
  462. if( m_listVol.GetItemState( pNMListView->iItem, LVIS_FOCUSED ) & LVIS_FOCUSED )
  463. {
  464. *pResult = 1;
  465. return;
  466. }
  467. }
  468. }
  469. *pResult = 0;
  470. }
  471. void CBreakDlg::OnClickListVolumes(NMHDR* pNMHDR, LRESULT* pResult)
  472. {
  473. *pResult = 0;
  474. POINT pt;
  475. GetCursorPos( &pt );
  476. LVHITTESTINFO lvhittestinfo;
  477. lvhittestinfo.pt = pt;
  478. m_listVol.ScreenToClient( &(lvhittestinfo.pt) );
  479. lvhittestinfo.pt.x = 4;
  480. int iItem = ListView_SubItemHitTest( m_listVol.GetSafeHwnd(), &lvhittestinfo );
  481. if( iItem < 0 )
  482. return;
  483. CItemData* pMemberData = (CItemData*)(m_listVol.GetItemData( iItem ) );
  484. if( pMemberData->GetMemberStatus() == FtMemberHealthy )
  485. {
  486. int iFocusedItem = m_nFocusedItem;
  487. m_listVol.SetItemState( iItem, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED );
  488. m_listVol.SetItemState( iFocusedItem, 0, LVIS_SELECTED | LVIS_FOCUSED );
  489. }
  490. }
  491. /////////////////////////////////////////////////////////////////////////////
  492. // CSwapDlg dialog
  493. CSwapDlg::CSwapDlg( CLogicalVolumeData *pParentData, CLogicalVolumeData *pMemberData,
  494. CObArray* parrVolumeData, UINT nIDTemplate /* =IDD_SWAP */ , CWnd* pParent /* =NULL */ )
  495. : CActionDlg( parrVolumeData, nIDTemplate, FALSE, pParent),
  496. m_pParentData(pParentData), m_pMemberData(pMemberData), m_nReplacementIndex(-1)
  497. {
  498. MY_TRY
  499. //{{AFX_DATA_INIT(CBreakDlg)
  500. m_staticTitle = _T("");
  501. //}}AFX_DATA_INIT
  502. ASSERT( pParentData );
  503. ASSERT( pMemberData );
  504. CString strParentName, strMemberName;
  505. pParentData->GetDisplayExtendedName( strParentName );
  506. pMemberData->GetDisplayExtendedName( strMemberName );
  507. AfxFormatString2( m_staticTitle, IDS_SWAP_DLG_TITLE, strMemberName, strParentName );
  508. MY_CATCH_AND_REPORT
  509. }
  510. void CSwapDlg::DoDataExchange(CDataExchange* pDX)
  511. {
  512. CActionDlg::DoDataExchange(pDX);
  513. //{{AFX_DATA_MAP(CSwapDlg)
  514. DDX_Text(pDX, IDC_STATIC_TITLE, m_staticTitle);
  515. //}}AFX_DATA_MAP
  516. }
  517. BEGIN_MESSAGE_MAP(CSwapDlg, CActionDlg)
  518. //{{AFX_MSG_MAP(CSwapDlg)
  519. //}}AFX_MSG_MAP
  520. END_MESSAGE_MAP()
  521. /////////////////////////////////////////////////////////////////////////////
  522. // CSwapDlg message handlers
  523. BOOL CSwapDlg::OnInitDialog()
  524. {
  525. CActionDlg::OnInitDialog();
  526. return TRUE; // return TRUE unless you set the focus to a control
  527. // EXCEPTION: OCX Property Pages should return FALSE
  528. }
  529. void CSwapDlg::OnOK()
  530. {
  531. // Get the replacement index
  532. int iItem = m_listVol.GetNextItem(-1, LVNI_SELECTED);
  533. if (iItem < 0 )
  534. {
  535. TRACE(_T("No items were selected!\n"));
  536. return;
  537. }
  538. m_nReplacementIndex = iItem;
  539. CActionDlg::OnOK();
  540. }
  541. /////////////////////////////////////////////////////////////////////////////
  542. // CAssignDlg dialog
  543. CAssignDlg::CAssignDlg( CItemData* pVolumeData, CWnd* pParent /*=NULL*/)
  544. : CDialog(CAssignDlg::IDD, pParent), m_pVolumeData( pVolumeData )
  545. {
  546. MY_TRY
  547. //{{AFX_DATA_INIT(CAssignDlg)
  548. m_staticName = _T("");
  549. m_radioAssign = pVolumeData->GetDriveLetter() ? 0 : 1;
  550. //}}AFX_DATA_INIT
  551. ASSERT( pVolumeData );
  552. pVolumeData->GetDisplayExtendedName(m_staticName );
  553. MY_CATCH_AND_REPORT
  554. }
  555. void CAssignDlg::DoDataExchange(CDataExchange* pDX)
  556. {
  557. CDialog::DoDataExchange(pDX);
  558. //{{AFX_DATA_MAP(CAssignDlg)
  559. DDX_Control(pDX, IDC_COMBO_DRIVE_LETTERS, m_comboDriveLetters);
  560. DDX_Text(pDX, IDC_STATIC_SET_NAME, m_staticName);
  561. DDX_Radio(pDX, IDC_RADIO_ASSIGN, m_radioAssign);
  562. //}}AFX_DATA_MAP
  563. }
  564. BEGIN_MESSAGE_MAP(CAssignDlg, CDialog)
  565. //{{AFX_MSG_MAP(CAssignDlg)
  566. ON_BN_CLICKED(IDC_RADIO_ASSIGN, OnRadioAssign)
  567. ON_BN_CLICKED(IDC_RADIO_DO_NOT_ASSIGN, OnRadioDoNotAssign)
  568. //}}AFX_MSG_MAP
  569. END_MESSAGE_MAP()
  570. BOOL CAssignDlg::FillDriveLettersCombo()
  571. {
  572. MY_TRY
  573. DWORD bitmask, bit;
  574. TCHAR cDriveLetter;
  575. bitmask = GetLogicalDrives();
  576. if( bitmask == 0 )
  577. {
  578. DisplaySystemErrorMessage( IDS_ERR_GET_LOGICAL_DRIVES );
  579. return FALSE;
  580. }
  581. for( cDriveLetter = _T('C'), bit = 4 ; cDriveLetter <= _T('Z'); cDriveLetter++, bit = bit<<1 )
  582. {
  583. if( ( cDriveLetter == m_pVolumeData->GetDriveLetter() ) ||
  584. !( bitmask&bit ) )
  585. {
  586. CString str;
  587. str.Format( _T("%c:"), cDriveLetter );
  588. int nIndex = m_comboDriveLetters.AddString(str);
  589. if( nIndex == CB_ERR )
  590. return FALSE;
  591. if( !m_comboDriveLetters.SetItemData(nIndex, (DWORD)cDriveLetter ) )
  592. return FALSE;
  593. if( cDriveLetter == m_pVolumeData->GetDriveLetter() )
  594. m_comboDriveLetters.SetCurSel(nIndex);
  595. }
  596. }
  597. return TRUE;
  598. MY_CATCH_AND_THROW
  599. }
  600. /////////////////////////////////////////////////////////////////////////////
  601. // CAssignDlg message handlers
  602. BOOL CAssignDlg::OnInitDialog()
  603. {
  604. MY_TRY
  605. CDialog::OnInitDialog();
  606. if( !FillDriveLettersCombo() )
  607. OnCancel();
  608. if( m_comboDriveLetters.GetCount() == 0 )
  609. {
  610. ASSERT( !m_pVolumeData->GetDriveLetter() );
  611. GetDlgItem(IDC_RADIO_ASSIGN)->EnableWindow(FALSE);
  612. }
  613. else if ( m_comboDriveLetters.GetCurSel() == CB_ERR )
  614. m_comboDriveLetters.SetCurSel(0);
  615. if( m_radioAssign != 0 )
  616. m_comboDriveLetters.EnableWindow(FALSE);
  617. MY_CATCH_REPORT_AND_CANCEL
  618. return TRUE; // return TRUE unless you set the focus to a control
  619. // EXCEPTION: OCX Property Pages should return FALSE
  620. }
  621. void CAssignDlg::OnOK()
  622. {
  623. // TODO: Add extra validation here
  624. UpdateData(TRUE);
  625. m_bAssign = ( m_radioAssign == 0 );
  626. if( m_bAssign )
  627. {
  628. int nIndex = m_comboDriveLetters.GetCurSel();
  629. ASSERT( nIndex != CB_ERR );
  630. m_cDriveLetter = (TCHAR)(m_comboDriveLetters.GetItemData(nIndex));
  631. }
  632. else
  633. m_cDriveLetter = _T('\0');
  634. CDialog::OnOK();
  635. }
  636. void CAssignDlg::OnRadioAssign()
  637. {
  638. // Enable the drive letters combo
  639. m_comboDriveLetters.EnableWindow(TRUE);
  640. }
  641. void CAssignDlg::OnRadioDoNotAssign()
  642. {
  643. // Disable the drive letters combo
  644. m_comboDriveLetters.EnableWindow(FALSE);
  645. }
  646. /////////////////////////////////////////////////////////////////////////////
  647. // CCreatePartitionDlg dialog
  648. CCreatePartitionDlg::CCreatePartitionDlg( CFreeSpaceData* pFreeData, LONGLONG llPartStartOffset,
  649. BOOL bExtendedPartition /* = FALSE */, CWnd* pParent /*=NULL*/)
  650. : CDialog(CCreatePartitionDlg::IDD, pParent), m_pFreeData( pFreeData ),
  651. m_llPartStartOffset( llPartStartOffset), m_bExtendedPartition( bExtendedPartition)
  652. {
  653. //{{AFX_DATA_INIT(CCreatePartitionDlg)
  654. //}}AFX_DATA_INIT
  655. ASSERT( pFreeData );
  656. ASSERT( llPartStartOffset >= pFreeData->m_llOffset );
  657. // The partition size should be greater than or equal with the cylinder size
  658. ASSERT( llPartStartOffset + pFreeData->m_llCylinderSize <= pFreeData->m_llOffset + pFreeData->m_llSize );
  659. }
  660. void CCreatePartitionDlg::DoDataExchange(CDataExchange* pDX)
  661. {
  662. CDialog::DoDataExchange(pDX);
  663. //{{AFX_DATA_MAP(CCreatePartitionDlg)
  664. DDX_Control(pDX, IDC_STATIC_PARTITION_TYPE, m_staticPartitionType);
  665. DDX_Control(pDX, IDC_EDIT_PARTITION_SIZE, m_editPartitionSize);
  666. DDX_Control(pDX, IDC_STATIC_MINIMUM_SIZE, m_staticMinimumSize);
  667. DDX_Control(pDX, IDC_STATIC_MAXIMUM_SIZE, m_staticMaximumSize);
  668. //}}AFX_DATA_MAP
  669. }
  670. BEGIN_MESSAGE_MAP(CCreatePartitionDlg, CDialog)
  671. //{{AFX_MSG_MAP(CCreatePartitionDlg)
  672. //}}AFX_MSG_MAP
  673. END_MESSAGE_MAP()
  674. /////////////////////////////////////////////////////////////////////////////
  675. // CCreatePartitionDlg message handlers
  676. BOOL CCreatePartitionDlg::OnInitDialog()
  677. {
  678. MY_TRY
  679. CDialog::OnInitDialog();
  680. // TODO: Add extra initialization here
  681. CString str;
  682. if( m_bExtendedPartition )
  683. {
  684. ASSERT( m_pFreeData->m_wFreeSpaceType == FST_Primary );
  685. str.LoadString( IDS_TYPE_EXTENDED_PARTITION );
  686. }
  687. else
  688. {
  689. if( m_pFreeData->m_wFreeSpaceType == FST_Primary )
  690. str.LoadString( IDS_TYPE_PRIMARY_PARTITION );
  691. else
  692. str.LoadString( IDS_TYPE_PARTITION_IN_EXTENDED_PARTITION );
  693. }
  694. m_staticPartitionType.SetWindowText( str);
  695. ASSERT( m_pFreeData->m_llCylinderSize <= m_pFreeData->m_llSize );
  696. str.Format(_T("%I64u"), (LONGLONG)(m_pFreeData->m_llCylinderSize / 0x100000) );
  697. m_staticMinimumSize.SetWindowText(str);
  698. str.Format(_T("%I64u"),
  699. (LONGLONG)( ( m_pFreeData->m_llOffset + m_pFreeData->m_llSize - m_llPartStartOffset ) / 0x100000 ) );
  700. m_staticMaximumSize.SetWindowText(str);
  701. m_editPartitionSize.SetWindowText(str);
  702. // The number input in the edit-box must be less than 2^63 / 2^20 = 8796093022208
  703. m_editPartitionSize.LimitText(13);
  704. MY_CATCH_REPORT_AND_CANCEL
  705. return TRUE; // return TRUE unless you set the focus to a control
  706. // EXCEPTION: OCX Property Pages should return FALSE
  707. }
  708. void CCreatePartitionDlg::OnOK()
  709. {
  710. MY_TRY
  711. // TODO: Add extra validation here
  712. CString str;
  713. m_editPartitionSize.GetWindowText(str);
  714. LONGLONG llSizeInMB = _ttoi64(str);
  715. if( ( llSizeInMB < (LONGLONG)( m_pFreeData->m_llCylinderSize / 0x100000 ) ) ||
  716. ( llSizeInMB > (LONGLONG)( ( m_pFreeData->m_llOffset + m_pFreeData->m_llSize - m_llPartStartOffset ) / 0x100000 ) ) )
  717. {
  718. AfxMessageBox(IDS_ERR_INVALID_SIZE, MB_ICONSTOP );
  719. return;
  720. }
  721. m_llPartitionSize = llSizeInMB * 0x100000;
  722. CDialog::OnOK();
  723. MY_CATCH_REPORT_AND_CANCEL
  724. }