dlgmpwolignorelist.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/dlgmpwolignorelist.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/30/01 12:06p $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dlgmpwolignorelist.h"
  36. #include "dlgmpwoladdignoreentry.h"
  37. #include "listctrl.h"
  38. #include "dlgmpwoldeleteignoreentry.h"
  39. ////////////////////////////////////////////////////////////////
  40. //
  41. // MPWolIgnoreListPopupClass
  42. //
  43. ////////////////////////////////////////////////////////////////
  44. MPWolIgnoreListPopupClass::MPWolIgnoreListPopupClass (void) :
  45. PopupDialogClass (IDD_MP_WOL_IGNORE_LIST)
  46. {
  47. WWDEBUG_SAY(("MPWolIgnoreListPopupClass: Instantiated\n"));
  48. mBuddyMgr = WOLBuddyMgr::GetInstance(false);
  49. WWASSERT_PRINT(mBuddyMgr, "WOLBuddyMgr not instantiated!");
  50. }
  51. MPWolIgnoreListPopupClass::~MPWolIgnoreListPopupClass()
  52. {
  53. WWDEBUG_SAY(("MPWolIgnoreListPopupClass: Destroyed\n"));
  54. if (mBuddyMgr) {
  55. mBuddyMgr->Release_Ref();
  56. }
  57. }
  58. ////////////////////////////////////////////////////////////////
  59. //
  60. // On_Init_Dialog
  61. //
  62. ////////////////////////////////////////////////////////////////
  63. void
  64. MPWolIgnoreListPopupClass::On_Init_Dialog (void)
  65. {
  66. Observer<WOLBuddyMgrEvent>::NotifyMe(*mBuddyMgr);
  67. //
  68. // Get a pointer to the list control
  69. //
  70. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_BUDDY_LIST_CTRL);
  71. if (list_ctrl != NULL) {
  72. // Configure the columns
  73. list_ctrl->Add_Column(L"", 1.0F, Vector3 (1, 1, 1));
  74. // Populate the list
  75. Refresh_List ();
  76. }
  77. PopupDialogClass::On_Init_Dialog ();
  78. }
  79. ////////////////////////////////////////////////////////////////
  80. //
  81. // On_Command
  82. //
  83. ////////////////////////////////////////////////////////////////
  84. void
  85. MPWolIgnoreListPopupClass::On_Command (int ctrl_id, int message_id, DWORD param)
  86. {
  87. switch (ctrl_id) {
  88. case IDC_ADD_BUTTON:
  89. MPWolAddIgnoreEntry::DoDialog(NULL);
  90. break;
  91. case IDC_REMOVE_BUTTON: {
  92. // Get the name of the selected user
  93. WideStringClass name(0, true);
  94. Get_Selected_Entry(name);
  95. // Display a confirmation dialog to the user.
  96. if (name.Is_Empty () == false) {
  97. MPWolDeleteIgnoreEntryPopupClass* dialog = new MPWolDeleteIgnoreEntryPopupClass;
  98. dialog->Set_User_Name(name);
  99. dialog->Start_Dialog();
  100. REF_PTR_RELEASE(dialog);
  101. }
  102. break;
  103. }
  104. }
  105. PopupDialogClass::On_Command (ctrl_id, message_id, param);
  106. }
  107. ////////////////////////////////////////////////////////////////
  108. //
  109. // Refresh_List
  110. //
  111. ////////////////////////////////////////////////////////////////
  112. void
  113. MPWolIgnoreListPopupClass::Refresh_List (void)
  114. {
  115. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_BUDDY_LIST_CTRL);
  116. if (list_ctrl == NULL) {
  117. return ;
  118. }
  119. // Get the name of the currently selected entry
  120. WideStringClass selected_user(0, true);
  121. int curr_sel = list_ctrl->Get_Curr_Sel();
  122. if (curr_sel != -1) {
  123. selected_user = list_ctrl->Get_Entry_Text (curr_sel, 0);
  124. }
  125. // Start fresh
  126. list_ctrl->Delete_All_Entries ();
  127. bool is_selection_set = false;
  128. // Loop over the entries
  129. const WOLBuddyMgr::IgnoreList& ignore = mBuddyMgr->GetIngoreList();
  130. for (unsigned int index = 0; index < ignore.size(); index++) {
  131. const WideStringClass& name = ignore[index];
  132. int pos = list_ctrl->Insert_Entry(0xFFFF, name);
  133. if (!is_selection_set && selected_user.Compare_No_Case(name) == 0) {
  134. list_ctrl->Set_Curr_Sel(pos);
  135. is_selection_set = true;
  136. }
  137. }
  138. if (is_selection_set == false && index > 0) {
  139. list_ctrl->Set_Curr_Sel(0);
  140. }
  141. }
  142. ////////////////////////////////////////////////////////////////
  143. //
  144. // Get_Selected_Entry
  145. //
  146. ////////////////////////////////////////////////////////////////
  147. void MPWolIgnoreListPopupClass::Get_Selected_Entry(WideStringClass& user_name)
  148. {
  149. // Get the index of the currently selected user in the list control
  150. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_BUDDY_LIST_CTRL);
  151. if (list_ctrl) {
  152. int curr_sel = list_ctrl->Get_Curr_Sel ();
  153. if (curr_sel != -1) {
  154. // Return the user name to the caller
  155. user_name = list_ctrl->Get_Entry_Text(curr_sel, 0);
  156. }
  157. }
  158. }
  159. void MPWolIgnoreListPopupClass::HandleNotification(WOLBuddyMgrEvent& event)
  160. {
  161. if (event.GetAction() == IGNORELIST_CHANGED) {
  162. Refresh_List();
  163. }
  164. }