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.

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