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.

252 lines
5.4 KiB

  1. #include "mbftpch.h"
  2. #include "combotb.h"
  3. const static COLORREF EditBack = RGB(255, 255, 255);
  4. const static COLORREF EditFore = RGB(0, 0, 0 );
  5. const static int FtTBHMargin = 5;
  6. const static int FtTBVMargin = 5;
  7. const static int FtHGap = 3;
  8. CComboToolbar::CComboToolbar() :
  9. m_Combobox(NULL),
  10. m_iCount(0),
  11. m_Buttons(NULL),
  12. m_iNumButtons(0)
  13. {
  14. m_nAlignment = Center;
  15. }
  16. CComboToolbar::~CComboToolbar()
  17. {
  18. delete [] m_Buttons;
  19. }
  20. typedef CBitmapButton * LPBITMAPBTN;
  21. BOOL CComboToolbar::Create(HWND hwndParent, struct Buttons *buttons,
  22. int iNumButtons, LPVOID pOwner)
  23. {
  24. int i;
  25. BOOL fRet;
  26. m_pOwner = pOwner;
  27. if (!CToolbar::Create(hwndParent))
  28. {
  29. return FALSE;
  30. }
  31. m_iNumButtons = iNumButtons;
  32. m_hMargin = FtTBHMargin;
  33. m_vMargin = FtTBVMargin;
  34. m_gap = FtHGap;
  35. m_bMinDesiredSize = TRUE;
  36. m_bHasCenterChild = TRUE;
  37. m_uRightIndex = m_iNumButtons + 1;
  38. DBG_SAVE_FILE_LINE
  39. m_Buttons = (CGenWindow**) new LPBITMAPBTN [m_iNumButtons];
  40. if (NULL != m_Buttons)
  41. {
  42. ::ZeroMemory(m_Buttons, m_iNumButtons * sizeof(LPBITMAPBTN));
  43. for (i = 0; i < m_iNumButtons; i++)
  44. {
  45. if (buttons[i].idCommand)
  46. {
  47. DBG_SAVE_FILE_LINE
  48. m_Buttons[i] = new CBitmapButton();
  49. if (NULL != m_Buttons[i])
  50. {
  51. fRet = ((CBitmapButton*)m_Buttons[i])->Create(GetWindow(), buttons[i].idCommand,
  52. g_hDllInst, buttons[i].idbStates, TRUE,
  53. buttons[i].nInputStates, buttons[i].nCustomStates, NULL);
  54. m_Buttons[i]->SetTooltip(buttons[i].pszTooltip);
  55. ASSERT(fRet);
  56. }
  57. }
  58. else
  59. {
  60. DBG_SAVE_FILE_LINE
  61. CSeparator *pSep = new CSeparator();
  62. m_Buttons[i] = pSep;
  63. if (NULL != pSep)
  64. {
  65. fRet = pSep->Create(GetWindow(), CSeparator::Blank);
  66. ASSERT (fRet);
  67. }
  68. }
  69. m_Buttons[i]->Release();
  70. }
  71. }
  72. DBG_SAVE_FILE_LINE
  73. m_Combobox = new CComboBox();
  74. if (NULL != m_Combobox)
  75. {
  76. if (m_Combobox->Create(GetWindow(), 100, CBS_AUTOHSCROLL|CBS_DROPDOWNLIST,
  77. NULL, NULL))
  78. {
  79. m_Combobox->SetColors(CreateSolidBrush(EditBack), EditBack, EditFore);
  80. m_Combobox->SetTooltip((LPSTR)IDS_RECEIVER_TT);
  81. m_Combobox->SetFont((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
  82. m_Combobox->Release();
  83. }
  84. }
  85. return TRUE;
  86. }
  87. void CComboToolbar::OnDesiredSizeChanged()
  88. {
  89. ScheduleLayout();
  90. }
  91. LRESULT CComboToolbar::ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  92. {
  93. switch(message)
  94. {
  95. HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
  96. default:
  97. break;
  98. }
  99. return (CToolbar::ProcessMessage(hwnd, message, wParam, lParam));
  100. }
  101. void CComboToolbar::OnCommand(HWND hwnd, int wId, HWND hwndCtl, UINT codeNotify)
  102. {
  103. if (m_pOwner)
  104. {
  105. CAppletWindow *pWindow = (CAppletWindow*)m_pOwner;
  106. pWindow->OnCommand((WORD)wId, hwndCtl, (WORD)codeNotify);
  107. return;
  108. }
  109. else
  110. {
  111. WARNING_OUT(("CComboToolbar::OnCommand--Received unhandlable message.\n"));
  112. }
  113. }
  114. void CComboToolbar::HandlePeerNotification(T120ConfID confID, T120NodeID nodeID,
  115. PeerMsg *pMsg)
  116. {
  117. int iLen, iIndex, iCount;
  118. char szName[MAX_PATH];
  119. if (pMsg->m_NodeID != nodeID)
  120. {
  121. iLen = T120_GetNodeName(confID, pMsg->m_NodeID, szName, MAX_PATH);
  122. if (iLen)
  123. {
  124. ASSERT (iLen < MAX_PATH);
  125. MEMBER_ID nMemberID = MAKE_MEMBER_ID(pMsg->m_MBFTPeerID, pMsg->m_NodeID);
  126. if (pMsg->m_bPeerAdded)
  127. {
  128. if (m_iCount == 0)
  129. {
  130. char szAll[MAX_PATH];
  131. ::LoadString(g_hDllInst, IDS_ALL_RECEIVER, szAll, MAX_PATH);
  132. m_Combobox->AddText(TEXT(szAll));
  133. WARNING_OUT(("Insert ALL"));
  134. }
  135. m_Combobox->AddText(szName, nMemberID);
  136. WARNING_OUT(("Insert %s.\n", szName));
  137. m_iCount++;
  138. }
  139. else
  140. {
  141. // Scan through the whole list to find the user
  142. iCount = m_Combobox->GetNumItems();
  143. for (iIndex = 0; iIndex < iCount; iIndex++)
  144. {
  145. if (nMemberID == (MEMBER_ID)m_Combobox->GetUserData(iIndex))
  146. break;
  147. }
  148. if (iIndex < iCount)
  149. { // found
  150. m_Combobox->RemoveItem(iIndex);
  151. WARNING_OUT(("delete %s", szName));
  152. m_iCount--;
  153. if (0 == m_iCount)
  154. {
  155. ASSERT (m_Combobox->GetNumItems() == 1);
  156. m_Combobox->RemoveItem(0);
  157. WARNING_OUT(("delete ALL"));
  158. }
  159. }
  160. else
  161. {
  162. WARNING_OUT(("Can't find to be deleted peer, %s.\n", szName));
  163. }
  164. }
  165. }
  166. else
  167. {
  168. WARNING_OUT(("Can't find node name for nConfID=%d, nNodeID=%d.\n",
  169. (UINT) confID, (UINT) pMsg->m_NodeID));
  170. }
  171. }
  172. else
  173. { // delete all items. Bacause MBFTEngine does not explicitly send PeerNotify message for every peer
  174. // when the node leaves message, so it is up to the host to remove all the peers during its close.
  175. if (!pMsg->m_bPeerAdded)
  176. {
  177. iCount = m_Combobox->GetNumItems();
  178. for (iIndex = iCount - 1; iIndex >= 0; iIndex--)
  179. {
  180. m_Combobox->RemoveItem(iIndex);
  181. }
  182. m_iCount = 0;
  183. }
  184. }
  185. if (m_iCount)
  186. {
  187. // Default select "ALL"
  188. m_Combobox->SetSelectedIndex(0);
  189. }
  190. else
  191. {
  192. // Deselect
  193. m_Combobox->SetSelectedIndex(-1);
  194. }
  195. }
  196. //
  197. // Return item selected and its associated itemdata
  198. //
  199. UINT CComboToolbar::GetSelectedItem(LPARAM *ItemData)
  200. {
  201. int iIndex = m_Combobox->GetSelectedIndex();
  202. if (iIndex >= 0)
  203. {
  204. *ItemData = m_Combobox->GetUserData(iIndex);
  205. }
  206. return iIndex;
  207. }
  208. static const int c_iCommands[] =
  209. { IDM_ADD_FILES, IDM_REMOVE_FILES, IDM_SEND_ALL, IDM_SEND_ONE, IDM_STOP_SENDING,
  210. IDM_OPEN_RECV_FOLDER};
  211. void CComboToolbar::UpdateButton(int *iFlags)
  212. {
  213. for (int iIndex = 0; iIndex < m_iNumButtons; iIndex++)
  214. {
  215. if (NULL != m_Buttons[iIndex])
  216. {
  217. ::EnableWindow(m_Buttons[iIndex]->GetWindow(), iFlags[iIndex]);
  218. }
  219. }
  220. }
  221.