1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // dfn_dialog.cpp : implementation file
24 #include "georges_edit.h"
25 #include "georges_edit_view.h"
26 #include "georges_edit_doc.h"
27 #include "dfn_dialog.h"
28 #include "left_view.h"
31 #include "nel/misc/path.h"
32 #include "nel/georges/type.h"
35 using namespace NLMISC
;
36 using namespace NLGEORGES
;
39 // ***************************************************************************
41 CDfnDialog::CDfnDialog () : CBaseDialog (IDR_MAINFRAME
)
43 //{{AFX_DATA_INIT(CDfnDialog)
44 // NOTE: the ClassWizard will add member initialization here
49 // ***************************************************************************
51 void CDfnDialog::DoDataExchange(CDataExchange
* pDX
)
53 CDialog::DoDataExchange(pDX
);
54 //{{AFX_DATA_MAP(CDfnDialog)
55 // NOTE: the ClassWizard will add DDX and DDV calls here
59 // ***************************************************************************
61 BEGIN_MESSAGE_MAP(CDfnDialog
, CDialog
)
62 //{{AFX_MSG_MAP(CDfnDialog)
67 // ***************************************************************************
69 void CDfnDialog::OnSize(UINT nType
, int cx
, int cy
)
71 CBaseDialog::OnSize(nType
, cx
, cy
);
73 // TODO: Add your message handler code here
77 // ***************************************************************************
79 BOOL
CDfnDialog::OnInitDialog()
81 CBaseDialog::OnInitDialog();
84 View
->GetClientRect (&viewRect
);
85 uint virtualWidth
= std::max ((uint
)MinViewWidth
, (uint
)(viewRect
.right
-viewRect
.left
));
88 CBaseDialog::resizeWidgets (virtualWidth
, 0);
90 // Get first item coordinate
92 getFirstItemPos (currentPos
);
94 // Create the type combo
95 setStaticSize (currentPos
);
96 LabelParents
.Create (_T("Parents:"), WS_VISIBLE
, currentPos
, this);
97 initWidget (LabelParents
);
98 getNextPosLabel (currentPos
);
100 setListSize (currentPos
, SmallWidget
, ParentHeight
);
101 Parents
.create (WS_TABSTOP
, currentPos
, this, LtParents
);
102 Parents
.insertColumn (0, _T("Parent Dfn"));
103 Parents
.Dialog
= this;
104 Parents
.recalcColumn ();
105 initWidget (Parents
);
106 getNextPos (currentPos
);
109 // Create the type combo
110 setStaticSize (currentPos
);
111 LabelStruct
.Create (_T("Structure:"), WS_VISIBLE
, currentPos
, this);
112 initWidget (LabelStruct
);
113 getNextPosLabel (currentPos
);
115 setListSize (currentPos
, Width
, DfnHeight
);
116 Struct
.create (WS_TABSTOP
, currentPos
, this, LtStruct
);
117 Struct
.insertColumn (0, _T("Name"));
118 Struct
.insertColumn (1, _T("Type"));
119 Struct
.insertColumn (2, _T("Value"));
120 Struct
.insertColumn (3, _T("Default"));
121 Struct
.insertColumn (4, _T("FilenameExt"));
122 Struct
.Dialog
= this;
123 Struct
.recalcColumn ();
125 getNextPos (currentPos
);
127 registerLastControl ();
133 return TRUE
; // return TRUE unless you set the focus to a control
134 // EXCEPTION: OCX Property Pages should return FALSE
137 // ***************************************************************************
139 void CDfnDialog::OnOK ()
141 Parents
.UpdateData ();
142 Struct
.UpdateData ();
144 CWnd
*focusWnd
= CWnd::GetFocus ();
147 focusWnd
= focusWnd
->GetParent ();
150 if (focusWnd
->m_hWnd
== Parents
.m_hWnd
)
154 else if (focusWnd
->m_hWnd
== Struct
.m_hWnd
)
162 // ***************************************************************************
164 void CDfnDialog::OnCancel ()
166 CWnd
*focusWnd
= CWnd::GetFocus ();
169 focusWnd
= focusWnd
->GetParent ();
172 if (focusWnd
->m_hWnd
== Parents
.m_hWnd
)
177 else if (focusWnd
->m_hWnd
== Struct
.m_hWnd
)
184 CBaseDialog::OnCancel ();
187 // ***************************************************************************
189 void CDfnDialog::getFromDocument (const NLGEORGES::CFormDfn
&dfn
)
194 Parents
.ListCtrl
.DeleteAllItems ();
196 for (parent
=0; parent
<dfn
.getNumParent (); parent
++)
198 // Add the label and value
199 Parents
.ListCtrl
.InsertItem(parent
, nlUtf8ToTStr(dfn
.getParentFilename(parent
)));
202 // Add the struct element
203 Struct
.ListCtrl
.DeleteAllItems ();
205 for (elm
=0; elm
<dfn
.getNumEntry (); elm
++)
207 // Add the label and value
208 Struct
.ListCtrl
.InsertItem(elm
, nlUtf8ToTStr(dfn
.getEntry(elm
).getName()));
209 switch (elm
, dfn
.getEntry (elm
).getType ())
211 case UFormDfn::EntryType
:
212 Struct
.ListCtrl
.SetItemText (elm
, 1, dfn
.getEntry (elm
).getArrayFlag () ? _T("Type array") : _T("Type"));
213 Struct
.ListCtrl
.SetItemText(elm
, 4, nlUtf8ToTStr(dfn
.getEntry(elm
).getFilenameExt()));
215 case UFormDfn::EntryDfn
:
216 Struct
.ListCtrl
.SetItemText (elm
, 1, dfn
.getEntry (elm
).getArrayFlag () ? _T("Dfn array") : _T("Dfn"));
218 case UFormDfn::EntryVirtualDfn
:
219 Struct
.ListCtrl
.SetItemText (elm
, 1, _T("Virtual Dfn"));
222 Struct
.ListCtrl
.SetItemText(elm
, 2, nlUtf8ToTStr(dfn
.getEntry(elm
).getFilename()));
223 Struct
.ListCtrl
.SetItemText(elm
, 3, nlUtf8ToTStr(dfn
.getEntry(elm
).getDefault()));
228 // ***************************************************************************
230 void CDfnDialog::setParentsToDocument ()
232 CGeorgesEditDoc
*doc
= View
->GetDocument ();
235 // Build a vector of string
236 vector
<string
> vectValue (Parents
.ListCtrl
.GetItemCount ());
240 for (parent
=0; parent
<(uint
)Parents
.ListCtrl
.GetItemCount (); parent
++)
242 // Add the label and value
243 CString str
= Parents
.ListCtrl
.GetItemText ( parent
, 0);
244 vectValue
[parent
] = tStrToUtf8(str
);
247 // Modify the document
248 if (!doc
->modify (new CActionStringVector (IAction::DfnParents
, vectValue
, *doc
, "", doc
->getLeftView ()->getCurrentSelectionId (), 0)))
249 getFromDocument (*doc
->getDfnPtr ());
253 // ***************************************************************************
255 void CDfnDialog::setStructToDocument ()
257 CGeorgesEditDoc
*doc
= View
->GetDocument ();
261 vector
<vector
<string
> > stringVector (Struct
.ListCtrl
.GetItemCount ());
263 for (elm
=0; elm
<stringVector
.size (); elm
++)
266 stringVector
[elm
].resize (5);
269 for (subElm
= 0; subElm
<5; subElm
++)
272 CString name
= Struct
.ListCtrl
.GetItemText (elm
, subElm
);
273 stringVector
[elm
][subElm
] = tStrToUtf8(name
);
276 doc
->modify (new CActionStringVectorVector (IAction::DfnStructure
, stringVector
, *doc
, doc
->getLeftView ()->getCurrentSelectionId (), 0));
280 // ***************************************************************************
282 LRESULT
CDfnDialog::WindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
287 if (wParam
== LtParents
)
288 setParentsToDocument ();
290 setStructToDocument ();
294 return CDialog::WindowProc(message
, wParam
, lParam
);
297 // ***************************************************************************
299 CEditListCtrl::TItemEdit
CDfnEditListCtrl::getItemEditMode (uint item
, uint subItem
)
302 return CEditListCtrl::EditMemCombo
;
303 else if (subItem
== 1)
304 return CEditListCtrl::EditFixedCombo
;
305 else if (subItem
== 2)
307 string type
= tStrToUtf8(ListCtrl
.GetItemText (item
, 1));
308 if (type
!= "Virtual Dfn")
309 return CEditListCtrl::EditMemCombo
;
311 else if (subItem
== 3)
313 string type
= tStrToUtf8(ListCtrl
.GetItemText (item
, 1));
314 if ((type
== "Type") || (type
== "Type array"))
315 return CEditListCtrl::EditMemCombo
;
317 else if (subItem
== 4)
319 string type
= tStrToUtf8(ListCtrl
.GetItemText (item
, 1));
320 if ((type
== "Type") || (type
== "Type array"))
321 return CEditListCtrl::EditMemCombo
;
323 return CEditListCtrl::NoEdit
;
326 // ***************************************************************************
328 void CDfnEditListCtrl::getComboBoxStrings (uint item
, uint subItem
, std::vector
<std::string
> &retStrings
)
332 retStrings
.reserve (5);
333 retStrings
.push_back ("Type");
334 retStrings
.push_back ("Dfn");
335 retStrings
.push_back ("Virtual Dfn");
336 retStrings
.push_back ("Type array");
337 retStrings
.push_back ("Dfn array");
341 // ***************************************************************************
343 void CDfnEditListCtrl::getMemComboBoxProp (uint item
, uint subItem
, std::string
®Adr
, bool &browse
)
348 regAdr
= tStrToUtf8(GEORGES_EDIT_BASE_REG_KEY
_T("\\Label MemCombo"));
350 else if (subItem
== 2)
355 string type
= tStrToUtf8(ListCtrl
.GetItemText (item
, 1));
356 if ((type
== "Type") || (type
== "Type array"))
357 regAdr
= tStrToUtf8(GEORGES_EDIT_BASE_REG_KEY
_T("\\Type MemCombo"));
358 else if ((type
== "Dfn") || (type
== "Dfn array"))
359 regAdr
= tStrToUtf8(GEORGES_EDIT_BASE_REG_KEY
_T("\\Dfn MemCombo"));
361 else if (subItem
== 3)
364 regAdr
= tStrToUtf8(GEORGES_EDIT_BASE_REG_KEY
_T("\\Default MemCombo"));
366 else if (subItem
== 3)
369 regAdr
= tStrToUtf8(GEORGES_EDIT_BASE_REG_KEY
_T("\\FilenameExt MemCombo"));
373 // ***************************************************************************
375 void CDfnEditListCtrl::getNewItemText (uint item
, uint subItem
, std::string
&ret
)
379 else if (subItem
== 1)
381 else if (subItem
== 2)
382 ret
= theApp
.DefaultType
;
383 else if (subItem
== 3)
385 else if (subItem
== 4)
389 // ***************************************************************************
391 void CDfnEditListCtrl::getBrowseInfo (uint item
, uint subItem
, std::string
&defExt
, std::string
&defFilename
, std::string
&defDir
, NLMISC::tstring
&filter
)
396 string type
= tStrToUtf8(ListCtrl
.GetItemText (item
, 1));
397 if ((type
== "Type") || (type
== "Type array"))
400 defDir
= theApp
.RootSearchPath
;
401 defFilename
= "*.typ";
404 else if ((type
== "Dfn") || (type
== "Dfn array"))
407 defDir
= theApp
.RootSearchPath
;
408 defFilename
= "*.dfn";
414 // ***************************************************************************
416 void CDfnEditListCtrl::onItemChanged (uint item
, uint subItem
)
421 string type
= tStrToUtf8(ListCtrl
.GetItemText (item
, 1));
422 if ((type
== "Type") || (type
== "Type array"))
425 str
= Dialog
->Struct
.ListCtrl
.GetItemText (item
, 2);
426 std::string ext
= NLMISC::CFile::getExtension(tStrToUtf8(str
));
428 Dialog
->Struct
.ListCtrl
.SetItemText(item
, 2, nlUtf8ToTStr(theApp
.DefaultType
));
430 else if ((type
== "Dfn") || (type
== "Dfn array"))
433 str
= Dialog
->Struct
.ListCtrl
.GetItemText (item
, 2);
434 std::string ext
= NLMISC::CFile::getExtension(tStrToUtf8(str
));
436 Dialog
->Struct
.ListCtrl
.SetItemText(item
, 2, nlUtf8ToTStr(theApp
.DefaultDfn
));
438 // Clear default value
439 Dialog
->Struct
.ListCtrl
.SetItemText (item
, 3, _T(""));
441 else if (type
== "Virtual Dfn")
444 Dialog
->Struct
.ListCtrl
.SetItemText (item
, 2, _T(""));
446 // Clear default value
447 Dialog
->Struct
.ListCtrl
.SetItemText (item
, 3, _T(""));
452 // ***************************************************************************
454 void CDfnDialog::onOpenSelected ()
456 Parents
.UpdateData ();
457 Struct
.UpdateData ();
459 CWnd
*focusWnd
= CWnd::GetFocus ();
462 focusWnd
= focusWnd
->GetParent ();
465 if (focusWnd
->m_hWnd
== Parents
.m_hWnd
)
468 POSITION pos
= Parents
.ListCtrl
.GetFirstSelectedItemPosition();
471 int nItem
= Parents
.ListCtrl
.GetNextSelectedItem(pos
);
474 CString str
= Parents
.ListCtrl
.GetItemText (nItem
, 0);
478 CString name
= nlUtf8ToTStr(CPath::lookup(tStrToUtf8(str
), false, false));
483 theApp
.OpenDocumentFile(name
);
487 else if (focusWnd
->m_hWnd
== Struct
.m_hWnd
)
490 POSITION pos
= Struct
.ListCtrl
.GetFirstSelectedItemPosition();
493 int nItem
= Struct
.ListCtrl
.GetNextSelectedItem(pos
);
496 CString str
= Struct
.ListCtrl
.GetItemText (nItem
, 2);
500 CString name
= nlUtf8ToTStr(CPath::lookup(tStrToUtf8(str
), false, false));
505 theApp
.OpenDocumentFile(name
);
513 // ***************************************************************************
515 void CDfnDialog::OnSetFocus(CWnd
* pOldWnd
)
517 CBaseDialog::OnSetFocus(pOldWnd
);
520 // ***************************************************************************
522 CWnd
* CDfnDialog::GetNextDlgTabItem( CWnd
* pWndCtl
, BOOL bPrevious
) const
527 // ***************************************************************************
529 void CDfnDialog::onFirstFocus ()
534 // ***************************************************************************
536 void CDfnDialog::onLastFocus ()
538 View
->setFocusLeftView ();
541 // ***************************************************************************
543 void CDfnDialog::resizeWidgets ()
546 View
->GetClientRect (&viewRect
);
547 uint virtualWidth
= std::max ((uint
)MinViewWidth
, (uint
)(viewRect
.right
-viewRect
.left
));
550 CBaseDialog::resizeWidgets (virtualWidth
, 0);
552 // Get first item coordinate
554 getFirstItemPos (currentPos
);
555 setStaticSize (currentPos
);
556 getNextPosLabel (currentPos
);
557 setListSize (currentPos
, SmallWidget
, ParentHeight
);
558 getNextPos (currentPos
);
559 setStaticSize (currentPos
);
560 getNextPosLabel (currentPos
);
561 setListSize (currentPos
, Width
, DfnHeight
);
562 getNextPos (currentPos
);
565 CBaseDialog::resizeWidgets (virtualWidth
, currentPos
.bottom
);
567 // Get first item coordinate
569 getFirstItemPos (currentPos
);
571 // Create the type combo
572 setStaticSize (currentPos
);
573 LabelParents
.SetWindowPos (NULL
, currentPos
.left
, currentPos
.top
, currentPos
.right
- currentPos
.left
,
574 currentPos
.bottom
- currentPos
.top
, SWP_NOZORDER
|SWP_NOOWNERZORDER
);
575 getNextPosLabel (currentPos
);
577 setListSize (currentPos
, SmallWidget
, ParentHeight
);
578 Parents
.SetWindowPos (NULL
, currentPos
.left
, currentPos
.top
, currentPos
.right
- currentPos
.left
,
579 currentPos
.bottom
- currentPos
.top
, SWP_NOZORDER
|SWP_NOOWNERZORDER
);
580 Parents
.recalcColumn ();
581 getNextPos (currentPos
);
583 // Create the type combo
584 setStaticSize (currentPos
);
585 LabelStruct
.SetWindowPos (NULL
, currentPos
.left
, currentPos
.top
, currentPos
.right
- currentPos
.left
,
586 currentPos
.bottom
- currentPos
.top
, SWP_NOZORDER
|SWP_NOOWNERZORDER
);
587 getNextPosLabel (currentPos
);
589 setListSize (currentPos
, Width
, DfnHeight
+ AdjusteHeight
);
590 Struct
.SetWindowPos (NULL
, currentPos
.left
, currentPos
.top
, currentPos
.right
- currentPos
.left
,
591 currentPos
.bottom
- currentPos
.top
, SWP_NOZORDER
|SWP_NOOWNERZORDER
);
592 Struct
.recalcColumn ();
593 getNextPos (currentPos
);
595 // Resize the current view
598 currentPos
.bottom
+CGeorgesEditView::WidgetTopMargin
+CGeorgesEditView::WidgetBottomMargin
);
601 // ***************************************************************************
602 // CDfnParentEditListCtrl
603 // ***************************************************************************
605 CEditListCtrl::TItemEdit
CDfnParentEditListCtrl::getItemEditMode (uint item
, uint subItem
)
607 return CEditListCtrl::EditMemCombo
;
610 // ***************************************************************************
612 void CDfnParentEditListCtrl::getMemComboBoxProp (uint item
, uint subItem
, std::string
®Adr
, bool &browse
)
615 regAdr
= tStrToUtf8(GEORGES_EDIT_BASE_REG_KEY
_T("\\Dfn MemCombo"));
618 // ***************************************************************************
620 void CDfnParentEditListCtrl::getNewItemText (uint item
, uint subItem
, std::string
&ret
)
622 ret
= theApp
.DefaultDfn
;
625 // ***************************************************************************
627 void CDfnParentEditListCtrl::getBrowseInfo (uint item
, uint subItem
, std::string
&defExt
, std::string
&defFilename
, std::string
&defDir
, NLMISC::tstring
&filter
)
630 defDir
= theApp
.RootSearchPath
;
631 defFilename
= "*.dfn";