dlgmpwoladdbuddy.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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/dlgmpwoladdbuddy.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 12/14/01 5:40p $*
  29. * *
  30. * $Revision:: 9 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "DlgMPWOLAddBuddy.h"
  36. #include "WOLBuddyMgr.h"
  37. #include "WOLLogonMgr.h"
  38. #include "DlgMessageBox.h"
  39. #include <WWUI\EditCtrl.h>
  40. #include <WWDebug\WWDebug.h>
  41. #include "translatedb.h"
  42. #include "string_ids.h"
  43. ////////////////////////////////////////////////////////////////
  44. //
  45. // MPWolAddBuddyPopupClass
  46. //
  47. ////////////////////////////////////////////////////////////////
  48. MPWolAddBuddyPopupClass::MPWolAddBuddyPopupClass (void) :
  49. PopupDialogClass (IDD_MP_WOL_ADD_BUDDY)
  50. {
  51. WWDEBUG_SAY(("MPWolAddBuddyPopupClass: Instantiated\n"));
  52. mBuddyMgr = WOLBuddyMgr::GetInstance(false);
  53. WWASSERT_PRINT(mBuddyMgr, "WOLBuddyMgr not instantiated!");
  54. return ;
  55. }
  56. MPWolAddBuddyPopupClass::~MPWolAddBuddyPopupClass()
  57. {
  58. WWDEBUG_SAY(("MPWolAddBuddyPopupClass: Destroyed\n"));
  59. if (mBuddyMgr) {
  60. mBuddyMgr->Release_Ref();
  61. }
  62. }
  63. ////////////////////////////////////////////////////////////////
  64. //
  65. // On_Init_Dialog
  66. //
  67. ////////////////////////////////////////////////////////////////
  68. void
  69. MPWolAddBuddyPopupClass::On_Init_Dialog (void)
  70. {
  71. EditCtrlClass* edit = (EditCtrlClass*)Get_Dlg_Item(IDC_BUDDY_NAME_EDIT);
  72. if (edit) {
  73. // WOL logins have a 9 character maximum.
  74. edit->Set_Text_Limit(9);
  75. edit->Set_Text(DefaultUserName);
  76. }
  77. // Disable the add button if the default user is empty.
  78. if (DefaultUserName.Is_Empty()) {
  79. Enable_Dlg_Item(IDC_ADD_BUTTON, false);
  80. }
  81. PopupDialogClass::On_Init_Dialog ();
  82. return ;
  83. }
  84. void MPWolAddBuddyPopupClass::On_Activate (bool onoff)
  85. {
  86. PopupDialogClass::On_Activate(onoff);
  87. if (onoff == true) {
  88. EditCtrlClass* edit = (EditCtrlClass*)Get_Dlg_Item(IDC_BUDDY_NAME_EDIT);
  89. if (edit) {
  90. edit->Set_Focus();
  91. }
  92. }
  93. }
  94. ////////////////////////////////////////////////////////////////
  95. //
  96. // On_Command
  97. //
  98. ////////////////////////////////////////////////////////////////
  99. void
  100. MPWolAddBuddyPopupClass::On_Command (int ctrl_id, int message_id, DWORD param)
  101. {
  102. switch (ctrl_id)
  103. {
  104. case IDC_ADD_BUTTON:
  105. Add_Buddy();
  106. break;
  107. }
  108. PopupDialogClass::On_Command (ctrl_id, message_id, param);
  109. return ;
  110. }
  111. ////////////////////////////////////////////////////////////////
  112. //
  113. // Add_Buddy
  114. //
  115. ////////////////////////////////////////////////////////////////
  116. void
  117. MPWolAddBuddyPopupClass::Add_Buddy (void)
  118. {
  119. WideStringClass buddy_name(0, true);
  120. buddy_name = Get_Dlg_Item_Text(IDC_BUDDY_NAME_EDIT);
  121. buddy_name.Trim();
  122. if (buddy_name.Is_Empty() == false) {
  123. WideStringClass loginName(0, true);
  124. WOLLogonMgr::GetLoginName(loginName);
  125. if (buddy_name.Compare_No_Case(loginName) != 0) {
  126. mBuddyMgr->AddBuddy(buddy_name);
  127. End_Dialog();
  128. } else {
  129. Set_Dlg_Item_Text(IDC_BUDDY_NAME_EDIT, L"");
  130. Enable_Dlg_Item(IDC_ADD_BUTTON, false);
  131. DlgMsgBox::DoDialog(TRANSLATE (IDS_MENU_ERROR), TRANSLATE (IDS_MENU_CANT_ADD_AS_BUDDY_MESSAGE));
  132. }
  133. }
  134. return ;
  135. }
  136. void MPWolAddBuddyPopupClass::On_EditCtrl_Change(EditCtrlClass* edit, int id)
  137. {
  138. if (IDC_BUDDY_NAME_EDIT == id) {
  139. // Do not allow leading or trailing whitespace
  140. WideStringClass text(0, true);
  141. text = edit->Get_Text();
  142. text.Trim();
  143. edit->Set_Text(text);
  144. bool enable (edit->Get_Text_Length() > 0);
  145. Enable_Dlg_Item(IDC_ADD_BUTTON, enable);
  146. }
  147. }
  148. void MPWolAddBuddyPopupClass::On_EditCtrl_Enter_Pressed(EditCtrlClass* edit, int id)
  149. {
  150. if (IDC_BUDDY_NAME_EDIT == id) {
  151. Add_Buddy();
  152. }
  153. }