1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of LEXIExporter |
---|
4 | |
---|
5 | Copyright 2006 NDS Limited |
---|
6 | |
---|
7 | Author(s): |
---|
8 | Mark Folkenberg, |
---|
9 | Bo Krohn |
---|
10 | Lasse Tassing |
---|
11 | |
---|
12 | This program is free software; you can redistribute it and/or modify it under |
---|
13 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
14 | Foundation; either version 2 of the License, or (at your option) any later |
---|
15 | version. |
---|
16 | |
---|
17 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
19 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
20 | |
---|
21 | You should have received a copy of the GNU Lesser General Public License along with |
---|
22 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
23 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
24 | http://www.gnu.org/copyleft/lesser.txt. |
---|
25 | ----------------------------------------------------------------------------- |
---|
26 | */ |
---|
27 | |
---|
28 | #include "LexiStdAfx.h" |
---|
29 | #include "LexiMaxExport.h" |
---|
30 | #include "LexiDialogObjectProperties.h" |
---|
31 | #include "LexiExportObject.h" |
---|
32 | #include "LexiDialogSelectNode.h" |
---|
33 | |
---|
34 | #include "..\Res\resource.h" |
---|
35 | |
---|
36 | #define _PRINT_DEBUG_INFO_ |
---|
37 | // |
---|
38 | |
---|
39 | CObjectPropertiesDlg::CObjectPropertiesDlg(Window* pParent) : Dialog(IDD_DIALOG_OBJECTPROPERTIES, DlgProc, pParent) |
---|
40 | { |
---|
41 | memset(&m_OrgClientRect, 0, sizeof(RECT)); |
---|
42 | m_pMetaCtrl=0; |
---|
43 | m_pObj=0; |
---|
44 | m_pData=0; |
---|
45 | } |
---|
46 | |
---|
47 | CObjectPropertiesDlg::~CObjectPropertiesDlg() |
---|
48 | { |
---|
49 | // Destroy meta windows |
---|
50 | m_pMetaCtrl->Detach(); |
---|
51 | ::DestroyWindow(m_hMetaWnd); |
---|
52 | delete m_pMetaCtrl; |
---|
53 | } |
---|
54 | |
---|
55 | // Initialize controls from object |
---|
56 | void CObjectPropertiesDlg::Init(CDDObject *pMeta, const char *pszDefExt) |
---|
57 | { |
---|
58 | // Hookup data |
---|
59 | m_sDefExt=pszDefExt; |
---|
60 | |
---|
61 | if(!m_pMetaCtrl) |
---|
62 | { |
---|
63 | RECT mainrc; |
---|
64 | GetClientRect(mainrc); |
---|
65 | ClientToScreen(mainrc); |
---|
66 | |
---|
67 | // -- animation list created |
---|
68 | |
---|
69 | RECT childrc; |
---|
70 | |
---|
71 | GetDlgItem(IDC_OBJECT_CHILD)->GetClientRect(childrc); |
---|
72 | GetDlgItem(IDC_OBJECT_CHILD)->ClientToScreen(childrc); |
---|
73 | |
---|
74 | int iChildWidth = childrc.right - childrc.left; |
---|
75 | int iChildHeight = childrc.bottom - childrc.top; |
---|
76 | |
---|
77 | int iChildX = childrc.left - mainrc.left; |
---|
78 | int iChildY = childrc.top - mainrc.top; |
---|
79 | |
---|
80 | m_hMetaWnd = ::CreateWindow("MetaControl", NULL, WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, iChildX, iChildY, iChildWidth, iChildHeight, m_hWnd, NULL, CExporter::m_hInstance, NULL); |
---|
81 | |
---|
82 | m_pMetaCtrl = new GDI::MetaControl; |
---|
83 | m_pMetaCtrl->Attach(m_hMetaWnd); |
---|
84 | m_pMetaCtrl->SetDataNotify(this); |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | // Setup meta data and object data |
---|
90 | m_pMetaCtrl->CreateFromMeta(pMeta); |
---|
91 | |
---|
92 | // Select default control |
---|
93 | GotoDlgCtrl(IDC_NODE); |
---|
94 | } |
---|
95 | |
---|
96 | void CObjectPropertiesDlg::SetInstance(CDDObject *pData, CExportObject* pObj) |
---|
97 | { |
---|
98 | m_pData=pData; |
---|
99 | m_pObj=pObj; |
---|
100 | |
---|
101 | // Setup defaults |
---|
102 | GetDlgItem(IDC_NAME)->SetWindowText(pData->GetString("Name", "<unnamed>")); |
---|
103 | GetDlgItem(IDC_FILENAME)->SetWindowText(pData->GetString("FileName", "<unknown>")); |
---|
104 | GetDlgItem(IDC_NODE)->SetWindowText(GetNameFromID(pData->GetInt("NodeID"))); |
---|
105 | m_pMetaCtrl->SetData(m_pData); |
---|
106 | } |
---|
107 | |
---|
108 | // |
---|
109 | INT_PTR CALLBACK CObjectPropertiesDlg::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
---|
110 | { |
---|
111 | CObjectPropertiesDlg* pThis = (CObjectPropertiesDlg*)Window::GetMapping(hWnd); |
---|
112 | |
---|
113 | switch(message) |
---|
114 | { |
---|
115 | case WM_INITDIALOG: |
---|
116 | { |
---|
117 | pThis = (CObjectPropertiesDlg*)lParam; |
---|
118 | Window::AddMapping(pThis, hWnd); |
---|
119 | pThis->OnInitDialog(); |
---|
120 | } return 0; |
---|
121 | |
---|
122 | case WM_SIZE: |
---|
123 | { |
---|
124 | pThis->OnSize(); |
---|
125 | } break; |
---|
126 | |
---|
127 | case WM_COMMAND: |
---|
128 | { |
---|
129 | switch(LOWORD(wParam)) |
---|
130 | { |
---|
131 | case IDC_NAME: |
---|
132 | if(HIWORD(wParam)==EN_CHANGE) |
---|
133 | pThis->OnNameChange(); |
---|
134 | break; |
---|
135 | case IDC_FILENAME: |
---|
136 | if(HIWORD(wParam)==EN_CHANGE) |
---|
137 | pThis->OnFileNameChange(); |
---|
138 | break; |
---|
139 | |
---|
140 | case IDC_BROWSEFILE: |
---|
141 | pThis->BrowseOutput(); |
---|
142 | break; |
---|
143 | |
---|
144 | case IDC_BROWSENODE: |
---|
145 | pThis->BrowseNode(); |
---|
146 | break; |
---|
147 | } |
---|
148 | } break; |
---|
149 | } |
---|
150 | return 0; |
---|
151 | } |
---|
152 | |
---|
153 | // |
---|
154 | void CObjectPropertiesDlg::OnInitDialog() |
---|
155 | { |
---|
156 | GetClientRect(m_OrgClientRect); |
---|
157 | } |
---|
158 | |
---|
159 | void CObjectPropertiesDlg::OnSize() |
---|
160 | { |
---|
161 | // Check if have initialized dialog |
---|
162 | if(m_OrgClientRect.right==0) return; |
---|
163 | |
---|
164 | RECT rNewMain; |
---|
165 | GetClientRect(rNewMain); |
---|
166 | int iDeltaY=rNewMain.bottom-m_OrgClientRect.bottom; |
---|
167 | int iDeltaX=rNewMain.right-m_OrgClientRect.right; |
---|
168 | |
---|
169 | // Get original client rect in screen coordinates |
---|
170 | RECT rScreenRect; |
---|
171 | memcpy(&rScreenRect, &m_OrgClientRect, sizeof(RECT)); |
---|
172 | ClientToScreen(rScreenRect); |
---|
173 | |
---|
174 | // Begin resize/move of all the controls |
---|
175 | HDWP hdwp=::BeginDeferWindowPos(8); |
---|
176 | |
---|
177 | RECT rTemp; |
---|
178 | Window *pItem; |
---|
179 | m_pMetaCtrl->GetWindowRect(rTemp); |
---|
180 | hdwp=::DeferWindowPos(hdwp, m_pMetaCtrl->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top)+iDeltaY, SWP_NOZORDER|SWP_NOMOVE); |
---|
181 | |
---|
182 | // Resize object property frame |
---|
183 | pItem=GetDlgItem(IDC_GROUPBOX_TITLE); |
---|
184 | pItem->GetWindowRect(rTemp); |
---|
185 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top)+iDeltaY, SWP_NOZORDER|SWP_NOMOVE); |
---|
186 | |
---|
187 | if(iDeltaX!=0) |
---|
188 | { |
---|
189 | // Move browse node button |
---|
190 | pItem=GetDlgItem(IDC_BROWSENODE); |
---|
191 | pItem->GetWindowRect(rTemp); |
---|
192 | ScreenToClient(rTemp); |
---|
193 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, rTemp.left+iDeltaX, rTemp.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE); |
---|
194 | |
---|
195 | // Move browse filename button |
---|
196 | pItem=GetDlgItem(IDC_BROWSEFILE); |
---|
197 | pItem->GetWindowRect(rTemp); |
---|
198 | ScreenToClient(rTemp); |
---|
199 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, rTemp.left+iDeltaX, rTemp.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE); |
---|
200 | |
---|
201 | // Resize node window |
---|
202 | pItem=GetDlgItem(IDC_NODE); |
---|
203 | pItem->GetWindowRect(rTemp); |
---|
204 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top), SWP_NOZORDER|SWP_NOMOVE); |
---|
205 | |
---|
206 | // Resize name window |
---|
207 | pItem=GetDlgItem(IDC_NAME); |
---|
208 | pItem->GetWindowRect(rTemp); |
---|
209 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top), SWP_NOZORDER|SWP_NOMOVE); |
---|
210 | |
---|
211 | // Resize filename window |
---|
212 | pItem=GetDlgItem(IDC_FILENAME); |
---|
213 | pItem->GetWindowRect(rTemp); |
---|
214 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top), SWP_NOZORDER|SWP_NOMOVE); |
---|
215 | } |
---|
216 | |
---|
217 | ::EndDeferWindowPos(hdwp); |
---|
218 | memcpy(&m_OrgClientRect, &rNewMain, sizeof(RECT)); |
---|
219 | } |
---|
220 | |
---|
221 | // |
---|
222 | void CObjectPropertiesDlg::OnNameChange() |
---|
223 | { |
---|
224 | std::string sValue=GetDlgItem(IDC_NAME)->GetWindowText(); |
---|
225 | m_pData->SetString("Name", sValue.c_str()); |
---|
226 | } |
---|
227 | |
---|
228 | // |
---|
229 | void CObjectPropertiesDlg::OnFileNameChange() |
---|
230 | { |
---|
231 | std::string sValue=GetDlgItem(IDC_FILENAME)->GetWindowText(); |
---|
232 | m_pData->SetString("FileName", sValue.c_str()); |
---|
233 | } |
---|
234 | |
---|
235 | // |
---|
236 | void CObjectPropertiesDlg::OnChanged(const CDDObject *pInstance, const char *pszKey) |
---|
237 | { |
---|
238 | ::SendMessage(m_hParent, WM_NOTIFY_MESSAGE_ID, 0, 0); |
---|
239 | } |
---|
240 | |
---|
241 | // |
---|
242 | void CObjectPropertiesDlg::BrowseNode() |
---|
243 | { |
---|
244 | // We need to have a valid instance |
---|
245 | if(!m_pObj || !m_pData) return; |
---|
246 | |
---|
247 | // Create node browser dialog |
---|
248 | CSelectNodeDlg dlg(this, m_pObj); |
---|
249 | // dlg.m_iNode = m_pData->GetInt("NodeID"); |
---|
250 | |
---|
251 | if(dlg.DoModal() != IDOK) return; |
---|
252 | |
---|
253 | // m_pData->SetInt("NodeID", dlg.m_iNode); |
---|
254 | GetDlgItem(IDC_NODE)->SetWindowText(GetNameFromID(m_pObj->GetMAXNodeID())); |
---|
255 | } |
---|
256 | |
---|
257 | // |
---|
258 | void CObjectPropertiesDlg::BrowseOutput() |
---|
259 | { |
---|
260 | // We need to have a valid instance |
---|
261 | if(!m_pObj || !m_pData) return; |
---|
262 | OPENFILENAME ofn; |
---|
263 | |
---|
264 | // Allocate filename buffer and fill out default |
---|
265 | char *pNameBuffer=new char[_MAX_PATH]; |
---|
266 | std::string sDefault=GetDlgItem(IDC_FILENAME)->GetWindowText(); |
---|
267 | strcpy(pNameBuffer, sDefault.c_str()); |
---|
268 | |
---|
269 | memset(&ofn, 0, sizeof(OPENFILENAME)); |
---|
270 | ofn.lStructSize = sizeof(OPENFILENAME); |
---|
271 | ofn.hwndOwner = m_hWnd; |
---|
272 | ofn.lpstrFilter = m_sDefExt.c_str(); |
---|
273 | ofn.lpstrFile= pNameBuffer; |
---|
274 | ofn.nMaxFile = _MAX_PATH; |
---|
275 | ofn.lpstrInitialDir = (LPSTR)NULL; |
---|
276 | ofn.Flags = OFN_OVERWRITEPROMPT; |
---|
277 | ofn.lpstrTitle = "Save As..."; |
---|
278 | |
---|
279 | if(GetSaveFileName(&ofn)==TRUE) |
---|
280 | { |
---|
281 | GetDlgItem(IDC_FILENAME)->SetWindowText(pNameBuffer); |
---|
282 | } |
---|
283 | } |
---|