Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/Tools/3dsmaxExport/LEXIExporter/LexiExport/Sources/LexiDialogProperties.cpp @ 45

Last change on this file since 45 was 6, checked in by anonymous, 18 years ago

=…

File size: 20.5 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of LEXIExporter
4
5Copyright 2006 NDS Limited
6
7Author(s):
8Mark Folkenberg,
9Bo Krohn
10
11This program is free software; you can redistribute it and/or modify it under
12the terms of the GNU Lesser General Public License as published by the Free Software
13Foundation; either version 2 of the License, or (at your option) any later
14version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
19
20You should have received a copy of the GNU Lesser General Public License along with
21this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22Place - Suite 330, Boston, MA 02111-1307, USA, or go to
23http://www.gnu.org/copyleft/lesser.txt.
24-----------------------------------------------------------------------------
25*/
26
27#include "LexiStdAfx.h"
28#include "LexiMaxExport.h"
29#include "LexiDialogProperties.h"
30#include "LexiDialogObjectProperties.h"
31#include "LexiDialogAddMultiple.h"
32
33#include "..\Res\resource.h"
34
35//
36
37CExporterPropertiesDlg::CExporterPropertiesDlg(Window* pParent, Interface* pMax, IUtil* pMaxUtil, CExportObjectRoot *pRoot) : Dialog(IDD_DIALOG_EXPORT, DlgProc, pParent)
38{
39        m_pMax = pMax;
40        m_pMaxUtil = pMaxUtil;
41
42        m_pRoot=pRoot; 
43        m_pCurrent=m_pRoot;
44
45        m_bChanges = false;
46        m_pCurrentEditWindow=0;
47        m_pLastEditObject=0;
48
49        // Create icon image list
50        m_hImageList = ImageList_Create(16, 16, ILC_COLOR16 | ILC_MASK, 0, 64);
51
52        // Enumerate all supported export types
53        std::vector<CExportObject::Desc> objlist;
54        CExportObject::EnumObjects(objlist);   
55
56        for(unsigned int x = 0; x < objlist.size(); x++)
57        {
58                m_ImageListMap[objlist[x].m_pszType] = x;
59                ImageList_AddIcon(m_hImageList, objlist[x].m_hIcon);
60
61                // Construct a type stub. This is used for testing parent/child compability
62                CDDObject *pTemp=new CDDObject();
63                pTemp->SetString("Type", objlist[x].m_pszType);
64                CExportObject *pStub=CExportObject::Construct(pTemp);
65                if(pStub!=NULL) m_lTypeCache.push_back(pStub);
66                pTemp->Release();
67        }
68
69        memset(&m_OrgClientRect, 0, sizeof(RECT));     
70}
71
72CExporterPropertiesDlg::~CExporterPropertiesDlg()
73{
74        ImageList_Destroy(m_hImageList);
75
76        try 
77        {
78                for(unsigned int i=0;i<m_lTypeCache.size();i++)
79                        m_lTypeCache[i]->Release();
80                m_lTypeCache.clear();
81        } catch(...)
82        {
83        }
84}
85
86//
87
88INT_PTR CALLBACK CExporterPropertiesDlg::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
89{
90        CExporterPropertiesDlg* pThis = (CExporterPropertiesDlg*)Window::GetMapping(hWnd);
91
92        switch(message)
93        {
94                case WM_INITDIALOG:
95                {
96                        pThis = (CExporterPropertiesDlg*)lParam;
97                        Window::AddMapping(pThis, hWnd);
98
99                        pThis->OnInitDialog();
100
101                }       return 1;
102
103                case WM_SIZE:
104                {
105                        pThis->OnSize();
106                } break;
107
108                case WM_GETMINMAXINFO:
109                {
110                        MINMAXINFO *pInfo=(MINMAXINFO*)lParam;
111                        pInfo->ptMinTrackSize.x=680;
112                        pInfo->ptMinTrackSize.y=300;
113                } break;
114       
115                case WM_CLOSE:
116                {
117                        if(!pThis->OnValidate()) return 0;
118                        pThis->EndDialog(0);
119                }       break;
120
121                case WM_NOTIFY_MESSAGE_ID:
122                        pThis->OnDataChange();
123                        break;
124
125                case WM_NOTIFY:
126                {
127                        const NMHDR* pHdr = (const NMHDR*)lParam;
128                        switch(pHdr->idFrom)
129                        {
130                                case IDC_EXPORTTREE:   
131                                        if(pHdr->code == TVN_SELCHANGED)
132                                        {
133                                                pThis->OnSelChange();
134                                        }
135                                        else if(pHdr->code == NM_CLICK)
136                                        {
137                                                TVHITTESTINFO ht = {0};
138
139                                                GetCursorPos(&ht.pt);
140                                                pThis->m_ExportTree.ScreenToClient(ht.pt);
141
142                                                HTREEITEM hItem=pThis->m_ExportTree.HitTest(&ht);         
143                                                if(hItem!=NULL && (TVHT_ONITEMSTATEICON & ht.flags))
144                                                {
145                                                        pThis->OnCheckChange(hItem);
146                                                }                                               
147                                        }
148                                        else if(pHdr->code == NM_RCLICK)
149                                        {
150                                                pThis->OnRClickTree();
151                                        }
152                                        else if(pHdr->code == TVN_KEYDOWN)
153                                        {
154                                                const NMTVKEYDOWN* pKey = (const NMTVKEYDOWN*)pHdr;
155                                                if(pKey->wVKey == VK_DELETE)
156                                                {
157                                                        pThis->OnConfigButtonRemove();
158                                                } else if(pKey->wVKey==VK_SPACE)
159                                                {
160                                                        pThis->OnCheckChange(pThis->m_ExportTree.GetSelectedItem());
161                                                }
162                                        }
163                                        break;
164                        }
165                }       break;
166
167                case WM_COMMAND:
168                {
169                        switch(LOWORD(wParam))
170                        {
171                                case IDOK:
172                                        break;
173
174                                case IDCANCEL:
175                                case IDC_CLOSE:
176                                        if(!pThis->OnValidate()) return 0;
177                                        pThis->EndDialog(0);
178                                        break;
179
180                                case IDC_ADD:
181                                        pThis->OnConfigButtonAdd();
182                                        break;
183
184                                case IDC_ADDSELECTED:
185                                        pThis->OnConfigButtonAddSelected();
186                                        break;
187
188                                case IDC_REMOVE:
189                                        pThis->OnConfigButtonRemove();
190                                        break;
191
192                                case IDC_LOADSELECTION:
193                                        pThis->OnLoadSelection();
194                                        break;
195
196                                case IDC_VIEWLOG:
197                                        pThis->OnViewLog();
198                                        break;
199
200                                case IDC_SETTINGS:
201                                        pThis->OnConfigButtonSettings();
202                                        break;
203
204                                case IDC_EXPORT:
205                                        pThis->OnConfigButtonExport();
206                                        break;
207
208                                case IDC_EXPORTSELECTED:
209                                        pThis->OnConfigButtonExportSelected();
210                                        break;
211                        }
212                }       return 1;
213        }
214
215        return 0;
216}
217
218//
219
220void CExporterPropertiesDlg::OnInitDialog()
221{
222        Bind(IDC_EXPORTTREE, m_ExportTree);     
223        m_ExportTree.SetImageList(m_hImageList, TVSIL_NORMAL);
224        m_ExportTree.SetBkColor(::GetSysColor(COLOR_WINDOW));
225
226        Bind(IDC_ADD, m_ButtonAdd);
227        Bind(IDC_ADDSELECTED, m_ButtonAddSelected);
228        Bind(IDC_REMOVE, m_ButtonRemove);
229        Bind(IDC_SETTINGS, m_ButtonSettings);
230        Bind(IDC_EXPORTSELECTED, m_ButtonExportSelected);
231        Bind(IDC_EXPORT, m_ButtonExport);
232        Bind(IDC_LOADSELECTION, m_ButtonLoadSelection);
233
234        GetClientRect(m_OrgClientRect);
235
236        //
237        CenterWindow(); 
238        PopulateExportTree();
239
240        //
241        OnSelChange();
242}
243
244//
245bool CExporterPropertiesDlg::OnValidate()
246{
247        if(m_pCurrent && m_pCurrentEditWindow)
248        {
249                m_pCurrent->CloseEditWindow();
250                m_pCurrentEditWindow=NULL;
251                m_pLastEditObject=0;
252        }
253        return true;
254}
255
256//
257void CExporterPropertiesDlg::OnSize()
258{
259        // Check if have initialized dialog
260        if(m_OrgClientRect.right==0) return;
261
262        RECT rNewMain;
263        GetClientRect(rNewMain);
264        int iDeltaY=rNewMain.bottom-m_OrgClientRect.bottom;
265        int iDeltaX=rNewMain.right-m_OrgClientRect.right;
266
267        // Get original client rect in screen coordinates
268        RECT rScreenRect;
269        memcpy(&rScreenRect, &m_OrgClientRect, sizeof(RECT));
270        ClientToScreen(rScreenRect);   
271
272        // Begin resize/move of all the controls
273        HDWP hdwp=::BeginDeferWindowPos(8);
274
275        RECT rTemp;
276        Window *pItem;
277        // Move Add button
278        m_ButtonAdd.GetWindowRect(rTemp);
279        ScreenToClient(rTemp);
280        hdwp=::DeferWindowPos(hdwp, m_ButtonAdd.m_hWnd, NULL, rTemp.left, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
281
282        // Move AddSelected button
283        m_ButtonAddSelected.GetWindowRect(rTemp);
284        ScreenToClient(rTemp);
285        hdwp=::DeferWindowPos(hdwp, m_ButtonAddSelected.m_hWnd, NULL, rTemp.left, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
286
287        // Move Remove button
288        m_ButtonRemove.GetWindowRect(rTemp);
289        ScreenToClient(rTemp);
290        hdwp=::DeferWindowPos(hdwp, m_ButtonRemove.m_hWnd, NULL, rTemp.left, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
291
292        // Move LoadSelection button
293        m_ButtonLoadSelection.GetWindowRect(rTemp);
294        ScreenToClient(rTemp);
295        hdwp=::DeferWindowPos(hdwp, m_ButtonLoadSelection.m_hWnd, NULL, rTemp.left, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
296
297        // Move Settings button
298        m_ButtonSettings.GetWindowRect(rTemp);
299        ScreenToClient(rTemp);
300        hdwp=::DeferWindowPos(hdwp, m_ButtonSettings.m_hWnd, NULL, rTemp.left, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
301
302        // Move ExportSelected button
303        m_ButtonExportSelected.GetWindowRect(rTemp);
304        ScreenToClient(rTemp);
305        hdwp=::DeferWindowPos(hdwp, m_ButtonExportSelected.m_hWnd, NULL, rTemp.left, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
306
307        // Move Export button
308        m_ButtonExport.GetWindowRect(rTemp);
309        ScreenToClient(rTemp);
310        hdwp=::DeferWindowPos(hdwp, m_ButtonExport.m_hWnd, NULL, rTemp.left, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
311
312        // Move Export button
313        pItem=GetDlgItem(IDC_CLOSE);
314        pItem->GetWindowRect(rTemp);
315        ScreenToClient(rTemp);
316        hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, rTemp.left, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
317
318        // Move Export button
319        pItem=GetDlgItem(IDC_VIEWLOG);
320        pItem->GetWindowRect(rTemp);
321        ScreenToClient(rTemp);
322        hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, rTemp.left, rTemp.top+iDeltaY, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
323
324        // Resize export tree
325        m_ExportTree.GetWindowRect(rTemp);
326        ScreenToClient(rTemp);
327        hdwp=::DeferWindowPos(hdwp, m_ExportTree.m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left), (rTemp.bottom-rTemp.top)+iDeltaY, SWP_NOZORDER|SWP_NOMOVE);
328
329        // Resize object property frame
330        pItem=GetDlgItem(IDC_LIST_GROUP);
331        pItem->GetWindowRect(rTemp);
332        hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left), (rTemp.bottom-rTemp.top)+iDeltaY, SWP_NOZORDER|SWP_NOMOVE);
333       
334        ::EndDeferWindowPos(hdwp);
335        memcpy(&m_OrgClientRect, &rNewMain, sizeof(RECT));
336        UpdateEditWindow();
337}
338
339void CExporterPropertiesDlg::UpdateEditWindow()
340{
341        if(m_pCurrentEditWindow==NULL) return;
342
343        RECT rTemp;
344        Window *pItem;
345        pItem=GetDlgItem(IDC_LIST_GROUP);
346        pItem->GetWindowRect(rTemp);   
347        ScreenToClient(rTemp);
348               
349        m_pCurrentEditWindow->SetWindowPos(NULL, rTemp.right+10, rTemp.top, m_OrgClientRect.right-(rTemp.right+rTemp.left+10), rTemp.bottom, SWP_NOZORDER);
350}
351
352void CExporterPropertiesDlg::OnConfigButtonAdd()
353{
354        OnButtonAdd(&m_ButtonAdd, 0xFFFFFFFF);
355}
356
357void CExporterPropertiesDlg::OnConfigButtonAddSelected()
358{
359        unsigned int iSelCount = m_pMax->GetSelNodeCount();
360        if(iSelCount != 1) 
361        {
362                if(iSelCount>0)
363                {
364                        // Get currently selected tree control item (this would be parent item)
365                        HTREEITEM hParent=m_ExportTree.GetSelectedItem();
366                        if(hParent==NULL) hParent=m_hRootItem;
367                        CExportObject *pParent=m_pCurrent;
368
369                        CAddMultipleDlg dlg(this, this, pParent);
370                        if(dlg.DoModal()==IDOK)
371                        {
372                                vector<CAddMultipleDlg::SListItem*> lExportItems=dlg.GetExportItems();
373
374                                // Iterate all export items and add them
375                                for(int i=0;i<lExportItems.size();i++)
376                                {
377                                        m_pCurrent=pParent;
378                                        InternalCreate(lExportItems[i]->ExportType, hParent, lExportItems[i]->pNode->GetHandle());
379                                }
380                        }
381                }
382                return;
383        }
384
385        OnButtonAdd(&m_ButtonAddSelected, m_pMax->GetSelNode(0)->GetHandle());
386}
387
388void CExporterPropertiesDlg::OnButtonAdd(GDI::Button* pButton, unsigned int iSelectedID)
389{       
390        // Create pop menu with all allowed types in
391        HMENU hMenu = CreatePopupMenu();       
392
393        for(unsigned int x = 0; x < m_lTypeCache.size(); x++) 
394        {
395                // Check if the export object type supports currently selected parent           
396                if(m_lTypeCache[x]->SupportsParentType(m_pCurrent))
397                {
398                        AppendMenu(hMenu, MF_STRING, x + 1024, m_lTypeCache[x]->GetTypeName());
399                }
400        }
401
402        RECT rc;
403        pButton->GetWindowRect(rc);
404
405        int iCmd = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_LEFTBUTTON | TPM_LEFTALIGN | TPM_BOTTOMALIGN, rc.left, rc.top, NULL, m_hWnd, NULL);
406        DestroyMenu(hMenu);
407
408        // On abort, just bail out
409        if(iCmd == 0) return;
410
411        // Get currently selected tree control item (this would be parent item)
412        HTREEITEM hParent=m_ExportTree.GetSelectedItem();
413        if(hParent==NULL) hParent=m_hRootItem;
414
415        InternalCreate(iCmd-1024, hParent, iSelectedID);
416}
417
418void CExporterPropertiesDlg::InternalCreate(int iTypeIndex, HTREEITEM hParent, unsigned int iSelectedID)
419{
420        // Create config object for ExportObject
421        CDDObject *pNewConfig=new CDDObject();
422        pNewConfig->SetString("Type", m_lTypeCache[iTypeIndex]->GetType());
423
424        // Construct new ExportObject
425        CExportObject* pObj = CExportObject::Construct(pNewConfig);
426        if(!pObj) 
427        {
428                MessageBox("Failed to create new ExportObject", NDS_EXPORTER_TITLE, MB_ICONERROR);
429                return;
430        }
431
432        // Setup parent
433        pObj->SetParent(m_pCurrent);
434        // Setup selected MAX Node
435        pObj->SetMAXNodeID(iSelectedID);
436
437        // Initial create function
438        if(!pObj->OnCreate(this))
439        {
440                // Object would not create, release
441                pObj->Release();
442                return;
443        }
444
445        // Create new treecontrol item
446        int iIcon=m_ImageListMap[pObj->GetType()];
447        HTREEITEM hItem=m_ExportTree.InsertItem(pObj->GetName(), iIcon, iIcon, hParent);
448        m_ExportTree.SetItemData(hItem, (DWORD_PTR)pObj);
449        m_ExportTree.SetCheck(hItem, pObj->GetEnabled());
450        m_ExportTree.SelectItem(hItem);
451        m_ExportTree.EnsureVisible(hItem);
452
453        //
454        m_bChanges = true;
455}
456
457void CExporterPropertiesDlg::InternalRemove(HTREEITEM hItem)
458{
459        /*      char text[256];
460        sprintf(text, "Remove selected item%s?", iNumSel > 1 ? "s" : "");
461
462        int rs = MessageBox(text, NDS_EXPORTER_TITLE, MB_YESNO | MB_ICONWARNING);
463        if(rs != IDYES) return;
464*/
465
466        CExportObject *pSel=(CExportObject*)m_ExportTree.GetItemData(hItem);
467        HTREEITEM hNextSel=m_ExportTree.GetPrevSiblingItem(hItem);
468        if(hNextSel==NULL) 
469        {
470                hNextSel=m_ExportTree.GetParentItem(hItem);
471                if(hNextSel==NULL) hNextSel=m_hRootItem;
472        }
473
474        m_ExportTree.SelectItem(hNextSel);
475
476        m_ExportTree.DeleteItem(hItem);
477        if(pSel==m_pCurrent) m_pCurrent=NULL;
478        if(pSel==m_pLastEditObject) 
479        {
480                m_pLastEditObject->CloseEditWindow();
481                m_pLastEditObject=NULL;
482        }
483        pSel->Release();               
484        m_bChanges = true;
485}
486
487void CExporterPropertiesDlg::GetSubItems(HTREEITEM hParent, std::vector<HTREEITEM> &lList)
488{
489        HTREEITEM hChild=m_ExportTree.GetChildItem(hParent);
490        if(hChild==NULL) return;
491
492        while(hChild!=NULL)
493        {
494                lList.push_back(hChild);
495                GetSubItems(hChild, lList);     // Recurse
496                hChild=m_ExportTree.GetNextSiblingItem(hChild);
497        }
498}
499
500void CExporterPropertiesDlg::OnLoadSelection()
501{
502        // Create pop menu with all allowed types in
503        HMENU hMenu = CreatePopupMenu();       
504
505        for(unsigned int x = 0; x < m_lTypeCache.size(); x++) 
506        {
507                if(stricmp(m_lTypeCache[x]->GetType(), "root")==0) continue;
508
509                std::string sText="All of type '";
510                sText+=m_lTypeCache[x]->GetTypeName();
511                sText+="'";
512
513                AppendMenu(hMenu, MF_STRING, x + 1024, sText.c_str());
514        }
515
516        AppendMenu(hMenu, MF_STRING, 100, "All");       
517        AppendMenu(hMenu, MF_STRING, 101, "None");
518
519        RECT rc;
520        m_ButtonLoadSelection.GetWindowRect(rc);
521
522        int iCmd = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_LEFTBUTTON | TPM_LEFTALIGN | TPM_BOTTOMALIGN, rc.left, rc.top, NULL, m_hWnd, NULL);
523        DestroyMenu(hMenu);
524
525        std::vector<HTREEITEM> lAllItems;
526        GetSubItems(TVI_ROOT, lAllItems);
527        if(iCmd>=1024)
528        {
529                const char *pszType=m_lTypeCache[iCmd-1024]->GetType();
530
531                for(unsigned i=0;i<lAllItems.size();i++)
532                {
533                        CExportObject *pObj=(CExportObject*)m_ExportTree.GetItemData(lAllItems[i]);
534                        if(pObj==NULL || pObj==m_pRoot) continue;
535                        bool bCheck=stricmp(pObj->GetType(), pszType)==0;
536                        m_ExportTree.SetCheck(lAllItems[i], bCheck);
537                        pObj->SetEnabled(bCheck);
538                }
539        } else
540        {
541                switch(iCmd)
542                {
543                        case 100:                               
544                                for(unsigned i=0;i<lAllItems.size();i++)
545                                {
546                                        CExportObject *pObj=(CExportObject*)m_ExportTree.GetItemData(lAllItems[i]);
547                                        if(pObj==NULL || pObj==m_pRoot) continue;
548                                        m_ExportTree.SetCheck(lAllItems[i], true);
549                                        pObj->SetEnabled(true);
550                                }
551                                break;
552                        case 101:
553                                for(unsigned i=0;i<lAllItems.size();i++)
554                                {
555                                        CExportObject *pObj=(CExportObject*)m_ExportTree.GetItemData(lAllItems[i]);
556                                        if(pObj==NULL || pObj==m_pRoot) continue;
557                                        m_ExportTree.SetCheck(lAllItems[i], false);
558                                        pObj->SetEnabled(false);
559                                }
560                                break;
561                        // On abort, just bail out
562                        default:
563                                return;
564                }
565        }       
566}
567
568void CExporterPropertiesDlg::OnConfigButtonRemove()
569{
570        HTREEITEM hSel=m_ExportTree.GetSelectedItem();
571        if(hSel==NULL || hSel==m_hRootItem) return;
572       
573        InternalRemove(hSel);   
574}
575
576void CExporterPropertiesDlg::OnConfigButtonSettings()
577{
578        MessageBox("Export settings", NDS_EXPORTER_TITLE, MB_ICONINFORMATION);
579}
580
581void CExporterPropertiesDlg::OnViewLog()
582{
583        CExporter::Get()->ShowLog();
584}
585
586void CExporterPropertiesDlg::OnConfigButtonExport()
587{
588        if(!OnValidate()) return;
589        EndDialog(100);
590}
591
592void CExporterPropertiesDlg::OnConfigButtonExportSelected()
593{
594/*      // Check if have any top-level items selected
595        bool bEnabledChildren=false;
596        HTREEITEM hChild=m_ExportTree.GetChildItem(m_hRootItem);       
597        while(hChild!=NULL)
598        {
599                if(m_ExportTree.GetCheck(hChild))
600                {
601                        bEnabledChildren=true;
602                        break;
603                }
604                hChild=m_ExportTree.GetNextSiblingItem(hChild);         
605        }
606        if(*/
607        if(!OnValidate()) return;
608        EndDialog(101);
609}
610
611void CExporterPropertiesDlg::OnCheckChange(HTREEITEM hItem)
612{
613        m_pCurrent=(CExportObject*)m_ExportTree.GetItemData(hItem);
614        if(m_pCurrent)
615        {
616                m_pCurrent->SetEnabled(!m_ExportTree.GetCheck(hItem)); 
617        }
618}
619
620//
621void CExporterPropertiesDlg::OnSelChange()
622{
623        HTREEITEM hSel=m_ExportTree.GetSelectedItem();
624        if(hSel==NULL) hSel=m_hRootItem;       
625       
626        // Check for root item
627        if(hSel!=m_hRootItem)
628        {
629                m_ButtonRemove.EnableWindow(true);      // All objects other than root can be removed
630                m_pCurrent=(CExportObject*)m_ExportTree.GetItemData(hSel);
631                if(!m_pCurrent) m_pCurrent=m_pRoot;
632        } else
633        {
634                m_ButtonRemove.EnableWindow(false);     // Root cannot be removed
635                m_pCurrent=m_pRoot;
636        }
637
638        // Retrieve edit window for current selected control
639        GDI::Window *pNew=m_pCurrent->GetEditWindow(this);
640        if(pNew!=m_pCurrentEditWindow)
641        {                       
642                // If another edit window was open, close it using the ExportObject
643                // it came from
644                if(m_pLastEditObject!=NULL && m_pCurrentEditWindow!=NULL) m_pLastEditObject->CloseEditWindow();         
645
646                // Store the new edit window
647                m_pCurrentEditWindow=pNew;
648
649                if(m_pCurrentEditWindow!=NULL)
650                {
651                        // Save the last ExportObject we have gotten Edit window from
652                        m_pLastEditObject=m_pCurrent;
653
654                        // Move edit window into place
655                        UpdateEditWindow();
656
657                        // Make sure the edit window is visible
658                        m_pCurrentEditWindow->ShowWindow(SW_SHOW);
659                }               
660        }
661
662/*      INode *pNode=0;
663        if(m_pMax->GetSelNodeCount() == 1)
664        {
665                pNode=m_pMax->GetSelNode(0);           
666        }*/
667
668        // Check if have any available types   
669        bool bCanAdd=false, bCanAddSel=false;
670        for(unsigned i=0;i<m_lTypeCache.size();i++)
671        {
672                if(m_lTypeCache[i]->SupportsParentType(m_pCurrent))
673                {
674                        bCanAdd=true;
675                        for(int iSelNode=0;iSelNode<m_pMax->GetSelNodeCount();iSelNode++)
676                        {
677                                if(m_lTypeCache[i]->SupportsMAXNode(m_pMax->GetSelNode(iSelNode)))
678                                {
679                                        bCanAddSel=true;
680                                        break;
681                                }
682                        }
683                        if(bCanAddSel) break;
684                }
685        }
686        m_ButtonAdd.EnableWindow(bCanAdd);
687        m_ButtonAddSelected.EnableWindow(bCanAddSel);
688
689        m_ButtonExport.EnableWindow(m_pRoot->HasChildren());
690        m_ButtonExportSelected.EnableWindow(m_pRoot->HasChildren());
691}
692
693//
694void CExporterPropertiesDlg::OnRClickTree()
695{               
696        POINT ptMouse;
697       
698        // Get cursor position
699        if(!GetCursorPos(&ptMouse)) return;
700
701        // Create hittest structure with local coordinates
702        TVHITTESTINFO hitInfo;
703        hitInfo.pt=ptMouse;
704        m_ExportTree.ScreenToClient(hitInfo.pt);
705
706        // Check if we hit an item
707        HTREEITEM hSelItem=m_ExportTree.HitTest(&hitInfo);
708        if(hSelItem==NULL) return;     
709       
710        m_pCurrent=(CExportObject*)m_ExportTree.GetItemData(hSelItem);
711        if(!m_pCurrent) m_pCurrent=m_pRoot;
712       
713        // Create pop menu with all allowed types in
714        HMENU hMenu = CreatePopupMenu();
715
716        // If we add any "Add Xx" items, we must add a separator
717        bool bHasSeparator=false;
718        std::string sText;
719
720        // We do not want to remove root item
721        if(m_pCurrent!=m_pRoot)
722        {
723                // Add option to remove currently selected item
724                sText="Remove ";
725                sText+=m_pCurrent->GetName();
726                AppendMenu(hMenu, MF_STRING, 512, sText.c_str());       
727        } else
728        {
729                bHasSeparator=true;     // This will omit the separator
730        }
731       
732        for(unsigned int x = 0; x < m_lTypeCache.size(); x++) 
733        {
734                // Check if the export object type supports currently selected parent           
735                if(m_lTypeCache[x]->SupportsParentType(m_pCurrent))
736                {
737                        // Check if an separator should be inserted
738                        if(!bHasSeparator)
739                        {
740                                AppendMenu(hMenu, MF_SEPARATOR, 0, 0);
741                                bHasSeparator=true;
742                        }
743
744                        // Add option to create this type
745                        sText="Add ";
746                        sText+=m_lTypeCache[x]->GetTypeName();
747                        AppendMenu(hMenu, MF_STRING, x + 1024, sText.c_str());
748                }
749        }
750
751        // Create menu
752        int iCmd = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_LEFTBUTTON | TPM_LEFTALIGN | TPM_BOTTOMALIGN, ptMouse.x, ptMouse.y, NULL, m_hWnd, NULL);
753        DestroyMenu(hMenu);
754
755        // On abort, just bail out
756        if(iCmd == 0) return;
757       
758        if(iCmd==512)
759        {
760                // Remove current item
761                InternalRemove(hSelItem);
762        } else
763        {
764                // Create new sub item
765                InternalCreate(iCmd-1024, hSelItem, 0xFFFFFFFF);
766        }
767}
768
769//
770void CExporterPropertiesDlg::OnDataChange()
771{
772        std::vector<HTREEITEM> lAllItems;
773        GetSubItems(TVI_ROOT, lAllItems);
774        for(unsigned i=0;i<lAllItems.size();i++)
775        {
776                CExportObject *pInstance=(CExportObject*)m_ExportTree.GetItemData(lAllItems[i]);
777                if(pInstance==NULL) return;
778
779                m_ExportTree.SetItemText(lAllItems[i], pInstance->GetName());
780        }
781
782        m_bChanges = true;
783}
784
785//
786void CExporterPropertiesDlg::PopulateExportTree()
787{
788        m_ExportTree.DeleteAllItems();         
789        AddObjectToTree(m_pRoot, TVI_ROOT);
790        m_ExportTree.Expand(m_hRootItem, TVE_EXPAND);
791}
792
793//
794void CExporterPropertiesDlg::AddObjectToTree(CExportObject *pObject, HTREEITEM hParent)
795{
796        int iIcon=m_ImageListMap[pObject->GetType()];
797        HTREEITEM hItem=m_ExportTree.InsertItem(pObject->GetName(), iIcon, iIcon, hParent);     
798        m_ExportTree.SetItemData(hItem, (DWORD_PTR)pObject);
799
800        if(hParent==TVI_ROOT) 
801        {
802                m_hRootItem=hItem;
803                m_ExportTree.SetCheck(hItem, true);
804        } else
805        {
806                m_ExportTree.SetCheck(hItem, pObject->GetEnabled());
807        }
808       
809        std::vector<CExportObject*> lList=pObject->GetChildren();
810        for(unsigned i=0;i<lList.size();i++)
811        {
812                AddObjectToTree(lList[i], hItem);
813        }
814}
Note: See TracBrowser for help on using the repository browser.