1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of LEXIExporter |
---|
4 | |
---|
5 | Copyright 2006 NDS Limited |
---|
6 | |
---|
7 | Author(s): |
---|
8 | Lasse Tassing |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | ----------------------------------------------------------------------------- |
---|
24 | */ |
---|
25 | |
---|
26 | #include "LexiStdAfx.h" |
---|
27 | #include "LexiMaxExport.h" |
---|
28 | #include "LexiDialogProperties.h" |
---|
29 | #include "LexiDialogAddMultiple.h" |
---|
30 | |
---|
31 | #include "..\Res\resource.h" |
---|
32 | |
---|
33 | // |
---|
34 | |
---|
35 | CAddMultipleDlg::CAddMultipleDlg(Window* pParent, CExporterPropertiesDlg *pOwner, CExportObject *pRootObject) : Dialog(IDD_DIALOG_ADDMULTIPLE, DlgProc, pParent) |
---|
36 | { |
---|
37 | m_pOwner=pOwner; |
---|
38 | m_pRootObject=pRootObject; |
---|
39 | m_pEditItem=NULL; |
---|
40 | memset(&m_OrgClientRect, 0, sizeof(RECT)); |
---|
41 | |
---|
42 | m_hImageList = ImageList_Create(16, 16, ILC_COLOR16 | ILC_MASK, 0, 64); |
---|
43 | |
---|
44 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_SCENEROOT))); |
---|
45 | |
---|
46 | m_ImageListMap[NULL] = 1; |
---|
47 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_UNKNOWN))); |
---|
48 | |
---|
49 | m_ImageListMap[LIGHT_CLASS_ID] = 2; |
---|
50 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_LIGHT))); |
---|
51 | |
---|
52 | m_ImageListMap[GEOMOBJECT_CLASS_ID] = 3; |
---|
53 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_MODEL))); |
---|
54 | |
---|
55 | // m_ImageListMap[IGAME_SPLINE] = 4; |
---|
56 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_UNKNOWN))); |
---|
57 | |
---|
58 | m_ImageListMap[CAMERA_CLASS_ID] = 5; |
---|
59 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_CAMERA))); |
---|
60 | |
---|
61 | m_ImageListMap[HELPER_CLASS_ID] = 6; |
---|
62 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_MODEL))); |
---|
63 | |
---|
64 | // m_ImageListMap[IGAME_BONE] = 7; |
---|
65 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_UNKNOWN))); |
---|
66 | |
---|
67 | // m_ImageListMap[IGAME_IKCHAIN] = 8; |
---|
68 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_UNKNOWN))); |
---|
69 | } |
---|
70 | |
---|
71 | CAddMultipleDlg::~CAddMultipleDlg() |
---|
72 | { |
---|
73 | ImageList_Destroy(m_hImageList); |
---|
74 | } |
---|
75 | |
---|
76 | // If dialog returns IDOK, a list of export items can be retrieved from this function |
---|
77 | vector<CAddMultipleDlg::SListItem*> CAddMultipleDlg::GetExportItems() |
---|
78 | { |
---|
79 | return m_lSelectedItems; |
---|
80 | } |
---|
81 | |
---|
82 | // |
---|
83 | |
---|
84 | INT_PTR CALLBACK CAddMultipleDlg::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
---|
85 | { |
---|
86 | CAddMultipleDlg* pThis = (CAddMultipleDlg*)Window::GetMapping(hWnd); |
---|
87 | |
---|
88 | switch(message) |
---|
89 | { |
---|
90 | case WM_INITDIALOG: |
---|
91 | { |
---|
92 | pThis = (CAddMultipleDlg*)lParam; |
---|
93 | Window::AddMapping(pThis, hWnd); |
---|
94 | pThis->OnInitDialog(); |
---|
95 | } return 1; |
---|
96 | |
---|
97 | case WM_SIZE: |
---|
98 | { |
---|
99 | pThis->OnSize(); |
---|
100 | } break; |
---|
101 | |
---|
102 | case WM_PARENTNOTIFY: |
---|
103 | if(LOWORD(wParam)==WM_LBUTTONDOWN && pThis->m_TypePopup.m_hWnd==NULL) |
---|
104 | { |
---|
105 | POINT pt; |
---|
106 | lParam=GetMessagePos(); |
---|
107 | pt.x=LOWORD(lParam); |
---|
108 | pt.y=HIWORD(lParam); |
---|
109 | pThis->OnChildClick(pt); |
---|
110 | } |
---|
111 | return 0; |
---|
112 | |
---|
113 | case WM_LBUTTONDOWN: |
---|
114 | if(pThis->m_TypePopup.m_hWnd!=NULL) |
---|
115 | { |
---|
116 | pThis->CloseTypePopup(); |
---|
117 | } |
---|
118 | break; |
---|
119 | |
---|
120 | case WM_COMMAND: |
---|
121 | { |
---|
122 | if((HWND)lParam==pThis->m_TypePopup.m_hWnd && pThis->m_TypePopup.m_hWnd!=NULL && HIWORD(wParam)==LBN_SELCHANGE) |
---|
123 | { |
---|
124 | pThis->OnTypeSelChange(); |
---|
125 | |
---|
126 | } |
---|
127 | |
---|
128 | switch(LOWORD(wParam)) |
---|
129 | { |
---|
130 | case IDOK: |
---|
131 | pThis->MakeResult(); |
---|
132 | pThis->EndDialog(IDOK); |
---|
133 | return 0; |
---|
134 | |
---|
135 | case IDCANCEL: |
---|
136 | pThis->EndDialog(IDCANCEL); |
---|
137 | return 0; |
---|
138 | } |
---|
139 | } break; |
---|
140 | |
---|
141 | case WM_CLOSE: |
---|
142 | { |
---|
143 | pThis->EndDialog(IDCANCEL); |
---|
144 | } break; |
---|
145 | |
---|
146 | case WM_MEASUREITEM: |
---|
147 | { |
---|
148 | LPMEASUREITEMSTRUCT lpMeasureItem = (LPMEASUREITEMSTRUCT) lParam; |
---|
149 | lpMeasureItem->itemHeight=20; |
---|
150 | }break; |
---|
151 | |
---|
152 | case WM_DRAWITEM: |
---|
153 | return pThis->OnDrawItem((LPDRAWITEMSTRUCT)lParam); |
---|
154 | } |
---|
155 | |
---|
156 | return 0; |
---|
157 | } |
---|
158 | |
---|
159 | // Handle size changes |
---|
160 | void CAddMultipleDlg::OnSize() |
---|
161 | { |
---|
162 | // Check if have initialized dialog |
---|
163 | if(m_OrgClientRect.right==0) return; |
---|
164 | |
---|
165 | RECT rNewMain; |
---|
166 | GetClientRect(rNewMain); |
---|
167 | int iDeltaY=rNewMain.bottom-m_OrgClientRect.bottom; |
---|
168 | int iDeltaX=rNewMain.right-m_OrgClientRect.right; |
---|
169 | |
---|
170 | // Get original client rect in screen coordinates |
---|
171 | RECT rScreenRect; |
---|
172 | memcpy(&rScreenRect, &m_OrgClientRect, sizeof(RECT)); |
---|
173 | ClientToScreen(rScreenRect); |
---|
174 | |
---|
175 | // Begin resize/move of all the controls |
---|
176 | HDWP hdwp=::BeginDeferWindowPos(3); |
---|
177 | |
---|
178 | RECT rTemp; |
---|
179 | Window *pItem; |
---|
180 | |
---|
181 | // Move OK button |
---|
182 | pItem=GetDlgItem(IDOK); |
---|
183 | pItem->GetWindowRect(rTemp); |
---|
184 | ScreenToClient(rTemp); |
---|
185 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, rTemp.left+iDeltaX, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE); |
---|
186 | |
---|
187 | // Move OK button |
---|
188 | pItem=GetDlgItem(IDCANCEL); |
---|
189 | pItem->GetWindowRect(rTemp); |
---|
190 | ScreenToClient(rTemp); |
---|
191 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, rTemp.left+iDeltaX, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE); |
---|
192 | |
---|
193 | // Resize export tree |
---|
194 | m_ListBox.GetWindowRect(rTemp); |
---|
195 | ScreenToClient(rTemp); |
---|
196 | hdwp=::DeferWindowPos(hdwp, m_ListBox.m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top)+iDeltaY, SWP_NOZORDER|SWP_NOMOVE); |
---|
197 | |
---|
198 | ::EndDeferWindowPos(hdwp); |
---|
199 | InvalidateRect(m_ListBox.m_hWnd, NULL, false); |
---|
200 | memcpy(&m_OrgClientRect, &rNewMain, sizeof(RECT)); |
---|
201 | } |
---|
202 | |
---|
203 | // |
---|
204 | void CAddMultipleDlg::CloseTypePopup() |
---|
205 | { |
---|
206 | // Remove popup listbox and re-enable the list control |
---|
207 | m_TypePopup.DestroyWindow(); |
---|
208 | m_TypePopup.m_hWnd=NULL; |
---|
209 | m_pEditItem=NULL; |
---|
210 | m_ListBox.EnableWindow(true); |
---|
211 | } |
---|
212 | |
---|
213 | // |
---|
214 | void CAddMultipleDlg::OnTypeSelChange() |
---|
215 | { |
---|
216 | // If we have an valid edit item pointer, we set the value |
---|
217 | if(m_pEditItem!=NULL) |
---|
218 | { |
---|
219 | int iTypeSel=m_TypePopup.GetCurSel(); |
---|
220 | m_pEditItem->ExportType=m_TypePopup.GetItemData(iTypeSel); |
---|
221 | } |
---|
222 | |
---|
223 | CloseTypePopup(); |
---|
224 | } |
---|
225 | |
---|
226 | // |
---|
227 | void CAddMultipleDlg::MakeResult() |
---|
228 | { |
---|
229 | // Just to make sure |
---|
230 | m_lSelectedItems.clear(); |
---|
231 | |
---|
232 | // Iterate all items |
---|
233 | int iCount=m_ListBox.GetCount(); |
---|
234 | for(int i=0;i<iCount;i++) |
---|
235 | { |
---|
236 | // Get item and skip it, if flagged -1 |
---|
237 | SListItem* pItem=(SListItem*)m_ListBox.GetItemDataPtr(i); |
---|
238 | if(pItem->ExportType==-1) continue; |
---|
239 | |
---|
240 | m_lSelectedItems.push_back(pItem); |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | INT_PTR CAddMultipleDlg::OnDrawItem(LPDRAWITEMSTRUCT pCD) |
---|
245 | { |
---|
246 | if(pCD==NULL) return 0; |
---|
247 | |
---|
248 | /* // Select right background and textcolor, based on selection state |
---|
249 | if(pCD->itemState&ODS_SELECTED) |
---|
250 | { |
---|
251 | ::SetBkColor(pCD->hDC, ::GetSysColor(COLOR_HIGHLIGHT)); |
---|
252 | ::SetTextColor(pCD->hDC,::GetSysColor(COLOR_HIGHLIGHTTEXT)); |
---|
253 | } else |
---|
254 | { |
---|
255 | ::SetBkColor(pCD->hDC, GetCustSysColor(COLOR_WINDOW)); |
---|
256 | ::SetTextColor(pCD->hDC,::GetSysColor(COLOR_WINDOWTEXT)); |
---|
257 | }*/ |
---|
258 | ::SetBkColor(pCD->hDC, GetCustSysColor(COLOR_WINDOW)); |
---|
259 | ::SetTextColor(pCD->hDC,::GetSysColor(COLOR_WINDOWTEXT)); |
---|
260 | |
---|
261 | // Fill background (this is the Micro$oft way of doing it..) |
---|
262 | ::ExtTextOut(pCD->hDC, 0, 0, ETO_OPAQUE, &pCD->rcItem, NULL, 0, NULL); |
---|
263 | |
---|
264 | // Get item data |
---|
265 | SListItem *pItem=(SListItem *)pCD->itemData; |
---|
266 | if(pItem==NULL) return 0; |
---|
267 | |
---|
268 | // Calculate MAX node name text rectangle |
---|
269 | RECT rLeft=pCD->rcItem; |
---|
270 | rLeft.right/=2; |
---|
271 | int iHeight=rLeft.bottom-rLeft.top; |
---|
272 | |
---|
273 | // Calculate exporttype frame and button size |
---|
274 | RECT rRight=rLeft; |
---|
275 | rRight.left+=rLeft.right; |
---|
276 | RECT rButton=rRight; |
---|
277 | rButton.right+=rLeft.right; |
---|
278 | rButton.left=rButton.right-iHeight; |
---|
279 | rRight.right+=rLeft.right-iHeight; |
---|
280 | |
---|
281 | // Draw MAX node icon |
---|
282 | ImageList_Draw(m_hImageList, m_ImageListMap[pItem->NodeClassID], pCD->hDC, rLeft.left+1, rLeft.top+2, ILD_TRANSPARENT); |
---|
283 | rLeft.left+=20; |
---|
284 | |
---|
285 | // Draw MAX node name |
---|
286 | ::DrawText(pCD->hDC, pItem->sNodeName.c_str() , -1, &rLeft, DT_LEFT|DT_VCENTER|DT_SINGLELINE); |
---|
287 | |
---|
288 | // Draw "combobox" frame |
---|
289 | ::DrawEdge(pCD->hDC, &rRight, EDGE_SUNKEN, BF_ADJUST|BF_RECT); |
---|
290 | rRight.left++; // Just make some space |
---|
291 | |
---|
292 | // Draw selected export type string |
---|
293 | if(pItem->ExportType>=0) |
---|
294 | ::DrawText(pCD->hDC, m_pOwner->m_lTypeCache[pItem->ExportType]->GetTypeName() , -1, &rRight, DT_LEFT|DT_VCENTER|DT_SINGLELINE); |
---|
295 | else |
---|
296 | ::DrawText(pCD->hDC, "Do not add" , -1, &rRight, DT_LEFT|DT_VCENTER|DT_SINGLELINE); |
---|
297 | |
---|
298 | // Draw combobox pushbutton in right state |
---|
299 | if(pItem==m_pEditItem) |
---|
300 | ::DrawFrameControl(pCD->hDC, &rButton, DFC_SCROLL, DFCS_SCROLLCOMBOBOX|DFCS_PUSHED); |
---|
301 | else |
---|
302 | { |
---|
303 | if(pItem->bCanEdit) |
---|
304 | ::DrawFrameControl(pCD->hDC, &rButton, DFC_SCROLL, DFCS_SCROLLCOMBOBOX); |
---|
305 | else |
---|
306 | ::DrawFrameControl(pCD->hDC, &rButton, DFC_SCROLL, DFCS_SCROLLCOMBOBOX|DFCS_INACTIVE); |
---|
307 | } |
---|
308 | return 0; |
---|
309 | } |
---|
310 | |
---|
311 | void CAddMultipleDlg::OnChildClick(POINT &pt) |
---|
312 | { |
---|
313 | RECT r; |
---|
314 | m_ListBox.GetClientRect(r); |
---|
315 | POINT pLocal=pt; |
---|
316 | m_ListBox.ScreenToClient(pLocal); |
---|
317 | |
---|
318 | // If we did not click on "combobox" button, we dont care |
---|
319 | if(pLocal.x<(r.right-20)) return; |
---|
320 | |
---|
321 | // Find out which item was clicked |
---|
322 | int iIndex=m_ListBox.GetItemFromPoint(pLocal); |
---|
323 | if(HIWORD(iIndex)) return; // Bail, if we was outside ListBox area |
---|
324 | |
---|
325 | // Get selected item data |
---|
326 | m_pEditItem=(SListItem*)m_ListBox.GetItemDataPtr(iIndex); |
---|
327 | if(!m_pEditItem->bCanEdit) |
---|
328 | { |
---|
329 | m_pEditItem=NULL; // Abort edit |
---|
330 | return; |
---|
331 | } |
---|
332 | |
---|
333 | m_ListBox.GetItemRect(iIndex, &r); |
---|
334 | int iWidth=(r.right/2)-20; |
---|
335 | r.left=r.right/2; |
---|
336 | |
---|
337 | m_ListBox.ClientToScreen(r); |
---|
338 | ScreenToClient(r); |
---|
339 | |
---|
340 | if(m_TypePopup.m_hWnd!=NULL) |
---|
341 | { |
---|
342 | CloseTypePopup(); |
---|
343 | } else |
---|
344 | { |
---|
345 | HWND hListView=::CreateWindow("LISTBOX", "TypePopup", WS_BORDER|WS_CHILD|LBS_NOTIFY, r.left, r.bottom, iWidth, 150, m_hWnd, (HMENU)0x80, CExporter::m_hInstance, NULL); |
---|
346 | m_TypePopup.Attach(hListView); |
---|
347 | SetWindowFont(hListView, GetWindowFont(m_hWnd), false); |
---|
348 | |
---|
349 | LONG lStyle=GetWindowLong(hListView, GWL_EXSTYLE); |
---|
350 | lStyle |= WS_EX_TRANSPARENT; |
---|
351 | SetWindowLong(hListView, GWL_EXSTYLE, lStyle); |
---|
352 | |
---|
353 | int iItemIndex=m_TypePopup.AddString("Do not add"); |
---|
354 | m_TypePopup.SetItemData(iItemIndex, -1); |
---|
355 | if(m_pEditItem->ExportType==-1) m_TypePopup.SetCurSel(iItemIndex); |
---|
356 | |
---|
357 | for(unsigned int x = 0; x < m_pOwner->m_lTypeCache.size(); x++) |
---|
358 | { |
---|
359 | // Check if the export object type supports currently selected parent |
---|
360 | if( m_pOwner->m_lTypeCache[x]->SupportsParentType(m_pRootObject) && |
---|
361 | m_pOwner->m_lTypeCache[x]->SupportsMAXNode(m_pEditItem->pNode)) |
---|
362 | { |
---|
363 | int iIndex=m_TypePopup.AddString( m_pOwner->m_lTypeCache[x]->GetTypeName()); |
---|
364 | m_TypePopup.SetItemData(iIndex, x); |
---|
365 | if(x==m_pEditItem->ExportType) m_TypePopup.SetCurSel(iIndex); |
---|
366 | } |
---|
367 | } |
---|
368 | int iTotal=m_TypePopup.GetCount(); |
---|
369 | int iHeight=m_TypePopup.GetItemHeight(); |
---|
370 | |
---|
371 | m_ListBox.EnableWindow(false); |
---|
372 | m_TypePopup.SetWindowPos(NULL, 0, 0, iWidth, (iTotal*iHeight)+5, SWP_NOMOVE|SWP_NOZORDER); |
---|
373 | ::ShowWindow(hListView, SW_SHOW); |
---|
374 | GotoDlgCtrl(0x80); |
---|
375 | } |
---|
376 | } |
---|
377 | |
---|
378 | // |
---|
379 | |
---|
380 | void CAddMultipleDlg::OnInitDialog() |
---|
381 | { |
---|
382 | CenterWindow(); |
---|
383 | |
---|
384 | m_TypePopup.m_hWnd=NULL; |
---|
385 | GetClientRect(m_OrgClientRect); |
---|
386 | |
---|
387 | // |
---|
388 | Bind(IDC_LIST, m_ListBox); |
---|
389 | LONG lStyle=GetWindowLong(m_ListBox.m_hWnd, GWL_EXSTYLE); |
---|
390 | lStyle &= ~WS_EX_NOPARENTNOTIFY; |
---|
391 | SetWindowLong(m_ListBox.m_hWnd, GWL_EXSTYLE, lStyle); |
---|
392 | |
---|
393 | PopulateView(); |
---|
394 | } |
---|
395 | |
---|
396 | void CAddMultipleDlg::PopulateView() |
---|
397 | { |
---|
398 | int iCount=m_ListBox.GetCount(); |
---|
399 | for(int i=0;i<iCount;i++) |
---|
400 | { |
---|
401 | SListItem* pItem=(SListItem*)m_ListBox.GetItemDataPtr(i); |
---|
402 | if(pItem!=NULL) delete pItem; |
---|
403 | } |
---|
404 | m_ListBox.ResetContent(); |
---|
405 | |
---|
406 | iCount=m_pOwner->m_pMax->GetSelNodeCount(); |
---|
407 | for(int i=0;i<iCount;i++) |
---|
408 | { |
---|
409 | INode* pNode=m_pOwner->m_pMax->GetSelNode(i); |
---|
410 | if(pNode==NULL || pNode->IsNodeHidden()) continue; |
---|
411 | |
---|
412 | SListItem* pItem=new SListItem; |
---|
413 | pItem->pNode=pNode; |
---|
414 | pItem->sNodeName=pNode->GetName(); |
---|
415 | pItem->NodeClassID=GetClassIDFromNode(pNode); |
---|
416 | pItem->ExportType=-1; |
---|
417 | |
---|
418 | int iTypeCount=0; |
---|
419 | for(unsigned int x = 0; x < m_pOwner->m_lTypeCache.size(); x++) |
---|
420 | { |
---|
421 | // Check if the export object type supports currently selected parent |
---|
422 | if( m_pOwner->m_lTypeCache[x]->SupportsParentType(m_pRootObject) && |
---|
423 | m_pOwner->m_lTypeCache[x]->SupportsMAXNode(pNode)) |
---|
424 | { |
---|
425 | pItem->ExportType=x; |
---|
426 | iTypeCount++; |
---|
427 | } |
---|
428 | } |
---|
429 | pItem->bCanEdit=iTypeCount>0; // We can only edit if type count>0 |
---|
430 | |
---|
431 | m_ListBox.AddString((const char*)pItem); |
---|
432 | } |
---|
433 | } |
---|
434 | |
---|