Debian Codegraph @

editor/TableFileEdit.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
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 // TableFileEdit.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23 #include "editor.h"
24 #include "TableFileEdit.h"
25 #include "TableManage.h"
26
27 #ifdef _DEBUG
28 #define new DEBUG_NEW
29 #undef THIS_FILE
30 static char THIS_FILE[] = __FILE__;
31 #endif
32
33 /////////////////////////////////////////////////////////////////////////////
34 // CTableFileEdit dialog
35
36 CTableFileEdit::CTableFileEdit(CWnd *pParent /*=NULL*/) : CDialog(CTableFileEdit::IDD, pParent) {
37 //{{AFX_DATA_INIT(CTableFileEdit)
38 //}}AFX_DATA_INIT
39 }
40
41 void CTableFileEdit::DoDataExchange(CDataExchange *pDX) {
42 CDialog::DoDataExchange(pDX);
43 //{{AFX_DATA_MAP(CTableFileEdit)
44 DDX_Control(pDX, IDC_TABLEEDIT_SCREEN_NAME_EDIT, m_ScreenNameBox);
45 DDX_Control(pDX, IDC_TABLEEDIT_DESCRIPTION_EDIT, m_DescriptionBox);
46 DDX_Control(pDX, IDC_TABLEEDIT_NAME_LIST, m_NameList);
47 //}}AFX_DATA_MAP
48 }
49
50 BEGIN_MESSAGE_MAP(CTableFileEdit, CDialog)
51 //{{AFX_MSG_MAP(CTableFileEdit)
52 ON_COMMAND(ID_TABLEEDIT_FILE_LOAD, OnTableEditFileLoad)
53 ON_COMMAND(ID_TABLEEDIT_FILE_EXIT, OnTableEditFileExit)
54 ON_CBN_SELCHANGE(IDC_TABLEEDIT_NAME_LIST, OnSelChangeTableEditNameList)
55 ON_BN_CLICKED(IDC_TABLEEDIT_BTN_NEXT, OnTableEditBtnNext)
56 ON_BN_CLICKED(IDC_TABLEEDIT_BTN_PREVIOUS, OnTableEditBtnPrevious)
57 ON_COMMAND(ID_TABLEEDIT_FILE_SAVE, OnTableEditFileSave)
58 ON_COMMAND(ID_TABLEEDIT_FILE_SAVE_AS, OnTableEditFileSaveAs)
59 ON_UPDATE_COMMAND_UI(ID_TABLEEDIT_FILE_SAVE, OnUpdateTableEditFileSave)
60 ON_UPDATE_COMMAND_UI(ID_TABLEEDIT_FILE_SAVE_AS, OnUpdateTableEditFileSaveAs)
61 ON_WM_CLOSE()
62 ON_EN_CHANGE(IDC_TABLEEDIT_DESCRIPTION_EDIT, OnChangeTableEditDescriptionEdit)
63 //}}AFX_MSG_MAP
64 END_MESSAGE_MAP()
65
66 /////////////////////////////////////////////////////////////////////////////
67 // CTableFileEdit message handlers
68
69 void CTableFileEdit::OnTableEditFileLoad() {
70 // TODO: Add your command handler code here
71 if (m_PageList.ModifiedPrompt(this) == IDNO)
72 return;
73
74 CString filters = "Outrage Table File (*.loc)|*.loc|All Files (*.*)|*.*||";
75
76 CFileDialog dlg_open(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, (LPCTSTR)filters, this);
77 if (dlg_open.DoModal() == IDCANCEL) {
78 return;
79 }
80
81 if (!m_PageList.LoadTable(dlg_open.GetPathName().GetBuffer(0))) {
82 MessageBox("Out of Memory Error: LoadTable()\n", "Load Table Error!");
83 m_PageList.ClearList();
84 return;
85 }
86
87 m_PageList.FillFromList(&m_NameList);
88 EnableAll(TRUE);
89
90 m_PageList.DisplaySelected(&m_NameList, &m_DescriptionBox);
91 m_PageList.SetTitleString(this);
92 }
93
94 void CTableFileEdit::OnTableEditFileExit() {
95 // TODO: Add your command handler code here
96 if (m_PageList.ModifiedPrompt(this) == IDYES)
97 EndDialog(0);
98 }
99
100 void CTableFileEdit::OnSelChangeTableEditNameList() {
101 // TODO: Add your control notification handler code here
102 int new_object_index;
103
104 m_PageList.SaveSelected(&m_DescriptionBox);
105 new_object_index = m_NameList.GetCurSel();
106 m_PageList.SelectNode(new_object_index);
107 m_PageList.DisplaySelected(&m_NameList, &m_DescriptionBox);
108 }
109
110 void CTableFileEdit::OnTableEditBtnNext() {
111 // TODO: Add your control notification handler code here
112 m_PageList.SaveSelected(&m_DescriptionBox);
113 m_PageList.SelectNext();
114 m_PageList.DisplaySelected(&m_NameList, &m_DescriptionBox);
115 }
116
117 void CTableFileEdit::OnTableEditBtnPrevious() {
118 // TODO: Add your control notification handler code here
119 m_PageList.SaveSelected(&m_DescriptionBox);
120 m_PageList.SelectPrev();
121 m_PageList.DisplaySelected(&m_NameList, &m_DescriptionBox);
122 }
123
124 BOOL CTableFileEdit::OnInitDialog() {
125 CDialog::OnInitDialog();
126
127 // TODO: Add extra initialization here
128 m_ScreenNameBox.LimitText(0);
129 m_DescriptionBox.LimitText(0);
130
131 // Disable all items until a table file has been loaded
132 EnableAll(FALSE);
133
134 return TRUE; // return TRUE unless you set the focus to a control
135 // EXCEPTION: OCX Property Pages should return FALSE
136 }
137
138 void CTableFileEdit::OnTableEditFileSave() {
139 // TODO: Add your command handler code here
140 m_PageList.SaveSelected(&m_DescriptionBox);
141
142 if (!m_PageList.SaveTable(NULL)) {
143 MessageBox("The save was unsuccessfull", "Save Table Error!");
144 return;
145 }
146 m_PageList.SetTitleString(this);
147 }
148
149 void CTableFileEdit::OnTableEditFileSaveAs() {
150 // TODO: Add your command handler code here
151 m_PageList.SaveSelected(&m_DescriptionBox);
152
153 CString filters = "Outrage Table File (*.loc)|*.loc|All Files (*.*)|*.*||";
154
155 CFileDialog dlg_open(FALSE, NULL, NULL, 0, (LPCTSTR)filters, this);
156 if (dlg_open.DoModal() == IDCANCEL) {
157 return;
158 }
159
160 if (!m_PageList.SaveTable(dlg_open.GetPathName().GetBuffer(0))) {
161 MessageBox("The save was unsuccessfull", "Save Table Error!");
162 return;
163 }
164 m_PageList.SetTitleString(this);
165 }
166
167 void CTableFileEdit::OnUpdateTableEditFileSave(CCmdUI *pCmdUI) {
168 // TODO: Add your command update UI handler code here
169 pCmdUI->Enable(m_PageList.IsLoaded() && m_PageList.IsModified());
170 }
171
172 void CTableFileEdit::OnUpdateTableEditFileSaveAs(CCmdUI *pCmdUI) {
173 // TODO: Add your command update UI handler code here
174 pCmdUI->Enable(m_PageList.IsLoaded());
175 }
176
177 void CTableFileEdit::OnClose() {
178 // TODO: Add your message handler code here and/or call default
179 if (m_PageList.ModifiedPrompt(this) == IDYES)
180 CDialog::OnClose();
181 }
182
183 void CTableFileEdit::OnChangeTableEditDescriptionEdit() {
184 // TODO: If this is a RICHEDIT control, the control will not
185 // send this notification unless you override the CDialog::OnInitDialog()
186 // function to send the EM_SETEVENTMASK message to the control
187 // with the ENM_CHANGE flag ORed into the lParam mask.
188
189 // TODO: Add your control notification handler code here
190 m_PageList.SetModified(TRUE);
191 m_PageList.SetTitleString(this);
192 }
193
194 void CTableFileEdit::EnableAll(bool flag) {
195 ((CButton *)GetDlgItem(IDC_TABLEEDIT_NAME_LIST))->EnableWindow(flag);
196 ((CButton *)GetDlgItem(IDC_TABLEEDIT_BTN_PREVIOUS))->EnableWindow(flag);
197 ((CButton *)GetDlgItem(IDC_TABLEEDIT_BTN_NEXT))->EnableWindow(flag);
198 ((CButton *)GetDlgItem(IDC_TABLEEDIT_SCREEN_NAME_EDIT))->EnableWindow(flag);
199 ((CButton *)GetDlgItem(IDC_TABLEEDIT_DESCRIPTION_EDIT))->EnableWindow(flag);
200 }