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.

257 lines
6.9 KiB

  1. // RemoteSessDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "emshell.h"
  5. #include "RemoteSessDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. const TCHAR* gtcNone = _T("None");
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CRemoteSessDlg dialog
  14. extern PEmObject GetEmObj(BSTR bstrEmObj);
  15. CRemoteSessDlg::CRemoteSessDlg(PSessionSettings pSettings, VARIANT *pVar, CWnd* pParent /*=NULL*/)
  16. : CDialog(CRemoteSessDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CRemoteSessDlg)
  19. m_bRememberSettings = FALSE;
  20. m_strAltSymbolPath = _T("");
  21. m_strPort = _T("");
  22. m_strPassword = _T("");
  23. m_strUsername = _T("");
  24. m_bCommandSet = FALSE;
  25. //}}AFX_DATA_INIT
  26. m_pSettings = pSettings;
  27. m_pECXVariantList = pVar;
  28. }
  29. void CRemoteSessDlg::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CRemoteSessDlg)
  33. DDX_Control(pDX, IDOK, m_btnOK);
  34. DDX_Control(pDX, IDC_LIST_COMMANDSET, m_mainListCtrl);
  35. DDX_Control(pDX, IDC_CK_COMMANDSET, m_btnCommandSet);
  36. DDX_Check(pDX, IDC_CK_REMEMBERSETTINGS, m_bRememberSettings);
  37. DDX_Text(pDX, IDC_EDIT_ALTSYMBOLPATH, m_strAltSymbolPath);
  38. DDX_Text(pDX, IDC_EDIT_PORT, m_strPort);
  39. DDX_Text(pDX, IDC_EDIT_PASSWORD, m_strPassword);
  40. DDX_Text(pDX, IDC_EDIT_USERNAME, m_strUsername);
  41. DDX_Check(pDX, IDC_CK_COMMANDSET, m_bCommandSet);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CRemoteSessDlg, CDialog)
  45. //{{AFX_MSG_MAP(CRemoteSessDlg)
  46. ON_NOTIFY(NM_CLICK, IDC_LIST_COMMANDSET, OnClickListCommandset)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CRemoteSessDlg message handlers
  51. void CRemoteSessDlg::OnOK()
  52. {
  53. // TODO: Add extra validation here
  54. CDialog::OnOK();
  55. //Store off the current settings
  56. UpdateSessionDlgData(FALSE);
  57. }
  58. HRESULT CRemoteSessDlg::DisplayData(PEmObject pEmObject)
  59. {
  60. _ASSERTE(pEmObject != NULL);
  61. HRESULT hr = E_FAIL;
  62. TCHAR szPid[20] = {0};
  63. LONG lRow = 0L;
  64. int nImage = 0;
  65. CString csPROCStatus;
  66. do
  67. {
  68. if( pEmObject == NULL ){
  69. hr = E_INVALIDARG;
  70. break;
  71. }
  72. _ltot(pEmObject->nId, szPid, 10);
  73. lRow = m_mainListCtrl.SetItemText(-1, 0, pEmObject->szName);
  74. if(lRow == -1L){
  75. hr = E_FAIL;
  76. break;
  77. }
  78. if ( pEmObject->dwBucket1 )
  79. lRow = m_mainListCtrl.SetItemText(lRow, 1, pEmObject->szBucket1);
  80. hr = S_OK;
  81. }
  82. while( false );
  83. return hr;
  84. }
  85. void CRemoteSessDlg::OnClickListCommandset(NMHDR* pNMHDR, LRESULT* pResult)
  86. {
  87. // TODO: Add your control notification handler code here
  88. //Set the m_strSelectedCommandSet to the value of the currently selected item
  89. //in the list
  90. //Get the currently selected item
  91. POSITION pos = NULL;
  92. int nIndex = 0;
  93. do {
  94. pos = m_mainListCtrl.GetFirstSelectedItemPosition();
  95. if ( pos != NULL ) {
  96. nIndex = m_mainListCtrl.GetNextSelectedItem(pos);
  97. m_strSelectedCommandSet = m_mainListCtrl.GetItemText(nIndex, 0);
  98. }
  99. //Enable the Okay button
  100. //m
  101. } while ( FALSE );
  102. *pResult = 0;
  103. }
  104. BOOL CRemoteSessDlg::OnInitDialog()
  105. {
  106. CDialog::OnInitDialog();
  107. // TODO: Add extra initialization here
  108. //Populate the list control with the ECX files.
  109. HRESULT hr = E_FAIL;
  110. LONG lLBound = 0;
  111. LONG lUBound = 0;
  112. BSTR bstrEmObj = NULL;
  113. EmObject CurrentObj;
  114. CString strDescription;
  115. CString strName;
  116. do {
  117. //Check mark the command set button, but disable it
  118. m_btnCommandSet.SetCheck(1);
  119. m_btnCommandSet.EnableWindow(FALSE);
  120. //Add the columns to the list control
  121. m_mainListCtrl.BeginSetColumn(2);
  122. strName.LoadString(IDS_AUTOSESSDLG_NAME);
  123. strDescription.LoadString(IDS_AUTOSESSDLG_DESCRIPTION);
  124. m_mainListCtrl.AddColumn(strName);
  125. m_mainListCtrl.AddColumn(strDescription);
  126. m_mainListCtrl.EndSetColumn();
  127. m_mainListCtrl.ResizeColumnsFitScreen();
  128. m_mainListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  129. //Get the lower and upper bounds of the variant array
  130. hr = SafeArrayGetLBound(m_pECXVariantList->parray, 1, &lLBound);
  131. if(FAILED(hr)) break;
  132. hr = SafeArrayGetUBound(m_pECXVariantList->parray, 1, &lUBound);
  133. if(FAILED(hr)) break;
  134. //Add the "None" element to the list
  135. LONG lRow = m_mainListCtrl.SetItemText(-1, 0, gtcNone);
  136. if(lRow == -1L){
  137. hr = E_FAIL;
  138. break;
  139. }
  140. //m_mainListCtrl.SetItemText(lRow, 1, gtcNone);
  141. //There are elements at both the lower bound and upper bound, so include them
  142. for(; lLBound <= lUBound; lLBound++)
  143. {
  144. //Get a BSTR object from the safe array
  145. hr = SafeArrayGetElement(m_pECXVariantList->parray, &lLBound, &bstrEmObj);
  146. if (FAILED(hr)) break;
  147. //Create a local copy of the EmObject. there aren't any pointers in
  148. //EmObject structure, so don't worry about doing a deep copy
  149. CurrentObj = *GetEmObj(bstrEmObj);
  150. SysFreeString( bstrEmObj );
  151. //Convert the BSTR object to an EmObject and pass it to DisplayData
  152. DisplayData(&CurrentObj);
  153. }
  154. //Synchronize the dialog with the view data
  155. UpdateSessionDlgData();
  156. UpdateData(FALSE);
  157. } while (FALSE);
  158. SysFreeString( bstrEmObj );
  159. if (FAILED(hr)) {
  160. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  161. }
  162. return TRUE; // return TRUE unless you set the focus to a control
  163. // EXCEPTION: OCX Property Pages should return FALSE
  164. }
  165. void CRemoteSessDlg::UpdateSessionDlgData(bool bUpdate)
  166. {
  167. LVFINDINFO findInfo;
  168. int nIndex = 0;
  169. //if bUpdate is TRUE, we are loading the dialog settings from m_pSettings
  170. if ( bUpdate ) {
  171. if ( m_pSettings != NULL ) {
  172. m_bCommandSet = m_pSettings->dwCommandSet;
  173. m_strPort = m_pSettings->strPort;
  174. m_strPassword = m_pSettings->strPassword;
  175. m_strUsername = m_pSettings->strUsername;
  176. m_strAltSymbolPath = m_pSettings->strAltSymbolPath;
  177. m_strSelectedCommandSet = m_pSettings->strCommandSet;
  178. //Create and initialize a findInfo object to retrieve the index for the item were looking for
  179. findInfo.flags = LVFI_STRING;
  180. findInfo.psz = m_strSelectedCommandSet;
  181. if ( m_mainListCtrl.GetItemCount() > 0) {
  182. //Search for m_strSelectedCommandSet in the list control and select it.
  183. nIndex = m_mainListCtrl.FindItem(&findInfo);
  184. if ( nIndex != -1 ) {
  185. //We have found it, now hilight it
  186. m_mainListCtrl.SetItemState( nIndex,LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  187. m_strSelectedCommandSet = m_mainListCtrl.GetItemText(nIndex, 0);
  188. } else {
  189. //Select the only item in the list
  190. m_mainListCtrl.SetItemState( 0,LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  191. m_strSelectedCommandSet = m_mainListCtrl.GetItemText(0, 0);
  192. }
  193. }
  194. else {
  195. //We have no items in the list, disable the okay button
  196. m_btnOK.EnableWindow(FALSE);
  197. }
  198. }
  199. }
  200. //if bUpdate is FALSE, we are saving the dialog settings to m_pSettings
  201. else {
  202. m_pSettings->strPort = m_strPort;
  203. m_pSettings->strPassword = m_strPassword;
  204. m_pSettings->strUsername = m_strUsername;
  205. m_pSettings->strAltSymbolPath = m_strAltSymbolPath;
  206. m_pSettings->strCommandSet = m_strSelectedCommandSet;
  207. }
  208. }