EditConversationListDialog.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. // EditConversationListDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "editconversationlistdialog.h"
  23. #include "conversationmgr.h"
  24. #include "editconversationdialog.h"
  25. #include "conversation.h"
  26. #include "utils.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. //
  34. // EditConversationListDialogClass
  35. //
  36. /////////////////////////////////////////////////////////////////////////////
  37. EditConversationListDialogClass::EditConversationListDialogClass(CWnd* pParent /*=NULL*/)
  38. : CDialog(EditConversationListDialogClass::IDD, pParent)
  39. {
  40. //{{AFX_DATA_INIT(EditConversationListDialogClass)
  41. // NOTE: the ClassWizard will add member initialization here
  42. //}}AFX_DATA_INIT
  43. return ;
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. //
  47. // DoDataExchange
  48. //
  49. /////////////////////////////////////////////////////////////////////////////
  50. void
  51. EditConversationListDialogClass::DoDataExchange (CDataExchange *pDX)
  52. {
  53. CDialog::DoDataExchange(pDX);
  54. //{{AFX_DATA_MAP(EditConversationListDialogClass)
  55. DDX_Control(pDX, IDC_CONVERSATION_LIST, m_ListCtrl);
  56. //}}AFX_DATA_MAP
  57. return ;
  58. }
  59. BEGIN_MESSAGE_MAP(EditConversationListDialogClass, CDialog)
  60. //{{AFX_MSG_MAP(EditConversationListDialogClass)
  61. ON_BN_CLICKED(IDC_ADD, OnAdd)
  62. ON_NOTIFY(NM_DBLCLK, IDC_CONVERSATION_LIST, OnDblclkConversationList)
  63. ON_NOTIFY(LVN_DELETEITEM, IDC_CONVERSATION_LIST, OnDeleteitemConversationList)
  64. ON_NOTIFY(LVN_KEYDOWN, IDC_CONVERSATION_LIST, OnKeydownConversationList)
  65. //}}AFX_MSG_MAP
  66. END_MESSAGE_MAP()
  67. /////////////////////////////////////////////////////////////////////////////
  68. //
  69. // OnInitDialog
  70. //
  71. /////////////////////////////////////////////////////////////////////////////
  72. BOOL
  73. EditConversationListDialogClass::OnInitDialog (void)
  74. {
  75. CDialog::OnInitDialog ();
  76. //
  77. // Configure the columns
  78. //
  79. m_ListCtrl.InsertColumn (0, "Name");
  80. m_ListCtrl.SetExtendedStyle (m_ListCtrl.GetExtendedStyle () | LVS_EX_FULLROWSELECT);
  81. //
  82. // Choose an appropriate size for the columns
  83. //
  84. CRect rect;
  85. m_ListCtrl.GetClientRect (&rect);
  86. rect.right -= ::GetSystemMetrics (SM_CXVSCROLL);
  87. m_ListCtrl.SetColumnWidth (0, rect.Width ());
  88. //
  89. // Add all the conversations to the list control
  90. //
  91. int count = ConversationMgrClass::Get_Conversation_Count ();
  92. for (int index = 0; index < count; index ++) {
  93. ConversationClass *conversation = ConversationMgrClass::Peek_Conversation (index);
  94. Add_Conversation (conversation);
  95. }
  96. return TRUE;
  97. }
  98. /////////////////////////////////////////////////////////////////////////////
  99. //
  100. // OnAdd
  101. //
  102. /////////////////////////////////////////////////////////////////////////////
  103. void
  104. EditConversationListDialogClass::OnAdd (void)
  105. {
  106. //
  107. // Let the user create a new conversation
  108. //
  109. EditConversationDialogClass dialog (this);
  110. if (dialog.DoModal () == IDOK) {
  111. //
  112. // Add this new conversation to the list control
  113. //
  114. ConversationClass *conversation = dialog.Peek_Conversation ();
  115. if (conversation != NULL) {
  116. Add_Conversation (conversation);
  117. }
  118. }
  119. return ;
  120. }
  121. /////////////////////////////////////////////////////////////////////////////
  122. //
  123. // OnOK
  124. //
  125. /////////////////////////////////////////////////////////////////////////////
  126. void
  127. EditConversationListDialogClass::OnOK (void)
  128. {
  129. //
  130. // Start fresh
  131. //
  132. ConversationMgrClass::Reset ();
  133. //
  134. // Get all the conversations from the list control and add them to the
  135. // conversation manager
  136. //
  137. for (int index = 0; index < m_ListCtrl.GetItemCount (); index ++) {
  138. ConversationClass *conversation = (ConversationClass *)m_ListCtrl.GetItemData (index);
  139. if (conversation != NULL) {
  140. ConversationMgrClass::Add_Conversation (conversation);
  141. }
  142. }
  143. ::Set_Modified (true);
  144. CDialog::OnOK ();
  145. return ;
  146. }
  147. /////////////////////////////////////////////////////////////////////////////
  148. //
  149. // Add_Conversation
  150. //
  151. /////////////////////////////////////////////////////////////////////////////
  152. void
  153. EditConversationListDialogClass::Add_Conversation (ConversationClass *conversation)
  154. {
  155. ASSERT (conversation != NULL);
  156. if (conversation == NULL) {
  157. return ;
  158. }
  159. //
  160. // Insert this conversation into the list control
  161. //
  162. int item_index = m_ListCtrl.InsertItem (0xFFFF, conversation->Get_Name ());
  163. if (item_index != -1) {
  164. conversation->Add_Ref ();
  165. m_ListCtrl.SetItemData (item_index, (DWORD)conversation);
  166. }
  167. return ;
  168. }
  169. /////////////////////////////////////////////////////////////////////////////
  170. //
  171. // Update_Conversation
  172. //
  173. /////////////////////////////////////////////////////////////////////////////
  174. void
  175. EditConversationListDialogClass::Update_Conversation (int index)
  176. {
  177. //
  178. // Update the conversation's name in the list control
  179. //
  180. ConversationClass *conversation = (ConversationClass *)m_ListCtrl.GetItemData (index);
  181. if (conversation != NULL) {
  182. m_ListCtrl.SetItemText (index, 0, conversation->Get_Name ());
  183. }
  184. return ;
  185. }
  186. /////////////////////////////////////////////////////////////////////////////
  187. //
  188. // OnDblclkConversationList
  189. //
  190. /////////////////////////////////////////////////////////////////////////////
  191. void
  192. EditConversationListDialogClass::OnDblclkConversationList
  193. (
  194. NMHDR * pNMHDR,
  195. LRESULT * pResult
  196. )
  197. {
  198. (*pResult) = 0;
  199. //
  200. // Lookup the conversation object associated with the entry the user
  201. // double clicked on
  202. //
  203. int sel_index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  204. if (sel_index >= 0) {
  205. ConversationClass *conversation = (ConversationClass *)m_ListCtrl.GetItemData (sel_index);
  206. if (conversation != NULL) {
  207. //
  208. // Allow the user to edit this entry
  209. //
  210. EditConversationDialogClass dialog (this);
  211. dialog.Set_Conversation (conversation);
  212. if (dialog.DoModal () == IDOK) {
  213. Update_Conversation (sel_index);
  214. }
  215. }
  216. }
  217. return ;
  218. }
  219. /////////////////////////////////////////////////////////////////////////////
  220. //
  221. // OnDeleteitemConversationList
  222. //
  223. /////////////////////////////////////////////////////////////////////////////
  224. void
  225. EditConversationListDialogClass::OnDeleteitemConversationList
  226. (
  227. NMHDR * pNMHDR,
  228. LRESULT* pResult
  229. )
  230. {
  231. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  232. (*pResult) = 0;
  233. //
  234. // Release our hold on this conversation object
  235. //
  236. ConversationClass *conversation = (ConversationClass *)m_ListCtrl.GetItemData (pNMListView->iItem);
  237. REF_PTR_RELEASE (conversation);
  238. m_ListCtrl.SetItemData (pNMListView->iItem, 0L);
  239. return ;
  240. }
  241. /////////////////////////////////////////////////////////////////////////////
  242. //
  243. // OnDeleteitemConversationList
  244. //
  245. /////////////////////////////////////////////////////////////////////////////
  246. void
  247. EditConversationListDialogClass::OnKeydownConversationList
  248. (
  249. NMHDR * pNMHDR,
  250. LRESULT * pResult
  251. )
  252. {
  253. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  254. (*pResult) = 0;
  255. if (pLVKeyDow->wVKey == VK_DELETE) {
  256. //
  257. // Delete all the selected items
  258. //
  259. int index = -1;
  260. while ((index = m_ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL)) >= 0) {
  261. m_ListCtrl.DeleteItem (index);
  262. }
  263. }
  264. return ;
  265. }