// Ryzom - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . // type_dialog.cpp : implementation file // #include "stdafx.h" #include "georges_edit.h" #include "georges_edit_view.h" #include "georges_edit_doc.h" #include "type_dialog.h" #include "action.h" #include "left_view.h" #include "georges/type.h" using namespace std; using namespace NLMISC; using namespace NLGEORGES; ///////////////////////////////////////////////////////////////////////////// // CTypeDialog dialog CTypeDialog::CTypeDialog () : CBaseDialog (IDR_MAINFRAME) { //{{AFX_DATA_INIT(CTypeDialog) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT View = NULL; } void CTypeDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTypeDialog) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTypeDialog, CDialog) //{{AFX_MSG_MAP(CTypeDialog) ON_WM_SIZE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTypeDialog message handlers void CTypeDialog::OnSize(UINT nType, int cx, int cy) { CBaseDialog::OnSize(nType, cx, cy); // TODO: Add your message handler code here } BOOL CTypeDialog::OnInitDialog() { CBaseDialog::OnInitDialog(); RECT viewRect; View->GetClientRect (&viewRect); uint virtualWidth = std::max ((uint)MinViewWidth, (uint)(viewRect.right-viewRect.left)); // Refresh sizes CBaseDialog::resizeWidgets (virtualWidth, 0); // Get first item coordinate RECT currentPos; RECT pos; getFirstItemPos (currentPos); // Create the type combo setStaticSize (currentPos); LabelType.Create ("Type:", WS_VISIBLE, currentPos, this); initWidget (LabelType); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); pos = currentPos; adjusteComboSize (pos); ComboType.Create (WS_VISIBLE|CBS_DROPDOWNLIST|WS_TABSTOP, pos, this, CbType); // Insert type string uint item; ComboType.ResetContent (); for (item=0; itemGetClientRect (&viewRect); uint virtualWidth = std::max ((uint)MinViewWidth, (uint)(viewRect.right-viewRect.left)); // Refresh sizes CBaseDialog::resizeWidgets (virtualWidth, 0); // Get first item coordinate RECT currentPos; getFirstItemPos (currentPos); setStaticSize (currentPos); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); getNextPos (currentPos); setStaticSize (currentPos); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); getNextPos (currentPos); setStaticSize (currentPos); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); getNextPos (currentPos); setStaticSize (currentPos); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); getNextPos (currentPos); setStaticSize (currentPos); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); getNextPos (currentPos); setStaticSize (currentPos); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); getNextPos (currentPos); setStaticSize (currentPos); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); getNextColumn (currentPos); setStaticSize (currentPos); getNextPosLabel (currentPos); setListSize (currentPos, SmallWidgetNotLimited, 250); getNextPos (currentPos); // Refresh sizes CBaseDialog::resizeWidgets (virtualWidth, currentPos.bottom); getFirstItemPos (currentPos); // Create the type combo setStaticSize (currentPos); LabelType.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); RECT pos = currentPos; adjusteComboSize (pos); ComboType.SetWindowPos (NULL, pos.left, pos.top, pos.right - pos.left, pos.bottom - pos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPos (currentPos); // Create the type combo setStaticSize (currentPos); LabelUIType.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); pos = currentPos; adjusteComboSize (pos); ComboUIType.SetWindowPos (NULL, pos.left, pos.top, pos.right - pos.left, pos.bottom - pos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPos (currentPos); // Default value setStaticSize (currentPos); LabelDefault.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); Default.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPos (currentPos); // Min value setStaticSize (currentPos); LabelMin.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); Min.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPos (currentPos); // Max value setStaticSize (currentPos); LabelMax.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); Max.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPos (currentPos); // Increment value setStaticSize (currentPos); LabelIncrement.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPosLabel (currentPos); setComboSize (currentPos, SmallWidget); Increment.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextColumn (currentPos); // Predef list value setStaticSize (currentPos); LabelPreDef.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); getNextPosLabel (currentPos); setListSize (currentPos, SmallWidgetNotLimited, 250 + AdjusteHeight); Predef.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left, currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER); Predef.recalcColumn (); getNextPos (currentPos); // Resize the current view View->setViewSize ( virtualWidth, currentPos.bottom+CGeorgesEditView::WidgetTopMargin+CGeorgesEditView::WidgetBottomMargin); } void CTypeDialog::OnOK () { Predef.onOK (); if (Default.haveFocus ()) Default.onOK (); if (Min.haveFocus ()) Min.onOK (); if (Max.haveFocus ()) Max.onOK (); if (Increment.haveFocus ()) Increment.onOK (); } void CTypeDialog::OnCancel () { Predef.onCancel (); } void CTypeDialog::getFromDocument (const NLGEORGES::CType &type) { if (View) { uint item; // Insert type string ComboType.ResetContent (); for (item=0; itemGetDocument (); if (doc) { CGeorgesEditDocSub *current = doc->getSelectedObject (); doc->modify (new CActionString (IAction::TypeType, toString (ComboType.GetCurSel ()).c_str (), *doc, "", "", doc->getLeftView ()->getCurrentSelectionId (), 0)); } } void CTypeDialog::setUIToDocument () { CGeorgesEditDoc *doc = View->GetDocument (); if (doc) { CGeorgesEditDocSub *current = doc->getSelectedObject (); int curSel = ComboUIType.GetCurSel (); if (curSel != CB_ERR) { curSel = (CType::TUI)ComboUIType.GetItemData (curSel); } else { curSel = CType::Edit; } doc->modify (new CActionString (IAction::TypeUI, toString (curSel).c_str (), *doc, "", "", doc->getLeftView ()->getCurrentSelectionId (), 0)); } } void CTypeDialog::setDefaultToDocument () { CGeorgesEditDoc *doc = View->GetDocument (); if (doc) { CGeorgesEditDocSub *current = doc->getSelectedObject (); if (current) { CString str; Default.UpdateData (); Default.GetWindowText (str); doc->modify (new CActionString (IAction::TypeDefault, str, *doc, "", "", doc->getLeftView ()->getCurrentSelectionId (), 0)); } } } void CTypeDialog::setMinToDocument () { CGeorgesEditDoc *doc = View->GetDocument (); if (doc) { CGeorgesEditDocSub *current = doc->getSelectedObject (); if (current) { CString str; Min.UpdateData (); Min.GetWindowText (str); doc->modify (new CActionString (IAction::TypeMin, str, *doc, "", "", doc->getLeftView ()->getCurrentSelectionId (), 0)); } } } void CTypeDialog::setMaxToDocument () { CGeorgesEditDoc *doc = View->GetDocument (); if (doc) { CGeorgesEditDocSub *current = doc->getSelectedObject (); CString str; Max.UpdateData (); Max.GetWindowText (str); doc->modify (new CActionString (IAction::TypeMax, str, *doc, "", "", doc->getLeftView ()->getCurrentSelectionId (), 0)); } } void CTypeDialog::setIncrementToDocument () { CGeorgesEditDoc *doc = View->GetDocument (); if (doc) { CGeorgesEditDocSub *current = doc->getSelectedObject (); CString str; Increment.UpdateData (); Increment.GetWindowText (str); doc->modify (new CActionString (IAction::TypeIncrement, str, *doc, "", "", doc->getLeftView ()->getCurrentSelectionId (), 0)); } } void CTypeDialog::setPredefToDocument () { CGeorgesEditDoc *doc = View->GetDocument (); if (doc) { CGeorgesEditDocSub *current = doc->getSelectedObject (); CString str; // Add the predef vector > stringVector; stringVector.resize (Predef.ListCtrl.GetItemCount()); uint predef; for (predef=0; predef<(uint)Predef.ListCtrl.GetItemCount(); predef++) { stringVector[predef].resize (2); // Add the label and value str = Predef.ListCtrl.GetItemText (predef, 0); stringVector[predef][0] = (const char*)str; str = Predef.ListCtrl.GetItemText (predef, 1); stringVector[predef][1] = (const char*)str; } doc->modify (new CActionStringVectorVector (IAction::TypePredef, stringVector, *doc, doc->getLeftView ()->getCurrentSelectionId (), 0)); } } BOOL CTypeDialog::OnCommand(WPARAM wParam, LPARAM lParam) { switch (HIWORD(wParam)) { case CBN_SELCHANGE: { // identifier switch (LOWORD(wParam)) { case CbType: setTypeToDocument (); break; case CbUI: setUIToDocument (); break; } } break; } return CWnd::OnCommand(wParam, lParam); } LRESULT CTypeDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case LC_CHANGE: setPredefToDocument (); break; case MC_STRINGCHANGE: { // identifier switch (LOWORD(wParam)) { case EdDefault: setDefaultToDocument (); break; case EdMin: setMinToDocument (); break; case EdMax: setMaxToDocument (); break; case EdIncrement: setIncrementToDocument (); break; } } break; } return CDialog::WindowProc(message, wParam, lParam); } void CTypeDialog::onLastFocus () { View->setFocusLeftView (); } void CTypeDialog::onFirstFocus () { View->SetFocus (); } CEditListCtrl::TItemEdit CTypeParentEditListCtrl::getItemEditMode (uint item, uint subItem) { return CEditListCtrl::EditMemCombo; } void CTypeParentEditListCtrl::getMemComboBoxProp (uint item, uint subItem, std::string ®Adr, bool &browse) { browse = false; if (subItem == 0) regAdr = GEORGES_EDIT_BASE_REG_KEY"\\Type Label MemCombo"; else regAdr = GEORGES_EDIT_BASE_REG_KEY"\\Type Name MemCombo"; }