| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- // EditConversationListDialog.cpp : implementation file
- //
- #include "stdafx.h"
- #include "leveledit.h"
- #include "editconversationlistdialog.h"
- #include "conversationmgr.h"
- #include "editconversationdialog.h"
- #include "conversation.h"
- #include "utils.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- //
- // EditConversationListDialogClass
- //
- /////////////////////////////////////////////////////////////////////////////
- EditConversationListDialogClass::EditConversationListDialogClass(CWnd* pParent /*=NULL*/)
- : CDialog(EditConversationListDialogClass::IDD, pParent)
- {
- //{{AFX_DATA_INIT(EditConversationListDialogClass)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // DoDataExchange
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- EditConversationListDialogClass::DoDataExchange (CDataExchange *pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(EditConversationListDialogClass)
- DDX_Control(pDX, IDC_CONVERSATION_LIST, m_ListCtrl);
- //}}AFX_DATA_MAP
- return ;
- }
- BEGIN_MESSAGE_MAP(EditConversationListDialogClass, CDialog)
- //{{AFX_MSG_MAP(EditConversationListDialogClass)
- ON_BN_CLICKED(IDC_ADD, OnAdd)
- ON_NOTIFY(NM_DBLCLK, IDC_CONVERSATION_LIST, OnDblclkConversationList)
- ON_NOTIFY(LVN_DELETEITEM, IDC_CONVERSATION_LIST, OnDeleteitemConversationList)
- ON_NOTIFY(LVN_KEYDOWN, IDC_CONVERSATION_LIST, OnKeydownConversationList)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnInitDialog
- //
- /////////////////////////////////////////////////////////////////////////////
- BOOL
- EditConversationListDialogClass::OnInitDialog (void)
- {
- CDialog::OnInitDialog ();
- //
- // Configure the columns
- //
- m_ListCtrl.InsertColumn (0, "Name");
- m_ListCtrl.SetExtendedStyle (m_ListCtrl.GetExtendedStyle () | LVS_EX_FULLROWSELECT);
-
- //
- // Choose an appropriate size for the columns
- //
- CRect rect;
- m_ListCtrl.GetClientRect (&rect);
- rect.right -= ::GetSystemMetrics (SM_CXVSCROLL);
- m_ListCtrl.SetColumnWidth (0, rect.Width ());
- //
- // Add all the conversations to the list control
- //
- int count = ConversationMgrClass::Get_Conversation_Count ();
- for (int index = 0; index < count; index ++) {
- ConversationClass *conversation = ConversationMgrClass::Peek_Conversation (index);
- Add_Conversation (conversation);
- }
-
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnAdd
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- EditConversationListDialogClass::OnAdd (void)
- {
- //
- // Let the user create a new conversation
- //
- EditConversationDialogClass dialog (this);
- if (dialog.DoModal () == IDOK) {
-
- //
- // Add this new conversation to the list control
- //
- ConversationClass *conversation = dialog.Peek_Conversation ();
- if (conversation != NULL) {
- Add_Conversation (conversation);
- }
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnOK
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- EditConversationListDialogClass::OnOK (void)
- {
- //
- // Start fresh
- //
- ConversationMgrClass::Reset ();
- //
- // Get all the conversations from the list control and add them to the
- // conversation manager
- //
- for (int index = 0; index < m_ListCtrl.GetItemCount (); index ++) {
- ConversationClass *conversation = (ConversationClass *)m_ListCtrl.GetItemData (index);
- if (conversation != NULL) {
- ConversationMgrClass::Add_Conversation (conversation);
- }
- }
- ::Set_Modified (true);
- CDialog::OnOK ();
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Add_Conversation
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- EditConversationListDialogClass::Add_Conversation (ConversationClass *conversation)
- {
- ASSERT (conversation != NULL);
- if (conversation == NULL) {
- return ;
- }
-
- //
- // Insert this conversation into the list control
- //
- int item_index = m_ListCtrl.InsertItem (0xFFFF, conversation->Get_Name ());
- if (item_index != -1) {
- conversation->Add_Ref ();
- m_ListCtrl.SetItemData (item_index, (DWORD)conversation);
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Update_Conversation
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- EditConversationListDialogClass::Update_Conversation (int index)
- {
- //
- // Update the conversation's name in the list control
- //
- ConversationClass *conversation = (ConversationClass *)m_ListCtrl.GetItemData (index);
- if (conversation != NULL) {
- m_ListCtrl.SetItemText (index, 0, conversation->Get_Name ());
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnDblclkConversationList
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- EditConversationListDialogClass::OnDblclkConversationList
- (
- NMHDR * pNMHDR,
- LRESULT * pResult
- )
- {
- (*pResult) = 0;
- //
- // Lookup the conversation object associated with the entry the user
- // double clicked on
- //
- int sel_index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
- if (sel_index >= 0) {
- ConversationClass *conversation = (ConversationClass *)m_ListCtrl.GetItemData (sel_index);
- if (conversation != NULL) {
- //
- // Allow the user to edit this entry
- //
- EditConversationDialogClass dialog (this);
- dialog.Set_Conversation (conversation);
- if (dialog.DoModal () == IDOK) {
- Update_Conversation (sel_index);
- }
- }
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnDeleteitemConversationList
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- EditConversationListDialogClass::OnDeleteitemConversationList
- (
- NMHDR * pNMHDR,
- LRESULT* pResult
- )
- {
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
- (*pResult) = 0;
- //
- // Release our hold on this conversation object
- //
- ConversationClass *conversation = (ConversationClass *)m_ListCtrl.GetItemData (pNMListView->iItem);
- REF_PTR_RELEASE (conversation);
- m_ListCtrl.SetItemData (pNMListView->iItem, 0L);
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnDeleteitemConversationList
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- EditConversationListDialogClass::OnKeydownConversationList
- (
- NMHDR * pNMHDR,
- LRESULT * pResult
- )
- {
- LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
- (*pResult) = 0;
- if (pLVKeyDow->wVKey == VK_DELETE) {
-
- //
- // Delete all the selected items
- //
- int index = -1;
- while ((index = m_ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL)) >= 0) {
- m_ListCtrl.DeleteItem (index);
- }
- }
- return ;
- }
|