// 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 .
// header_dialog.cpp : implementation file
//
#include "stdafx.h"
#include "georges_edit.h"
#include "georges_edit_view.h"
#include "georges_edit_doc.h"
#include "header_dialog.h"
#include "action.h"
#include "left_view.h"
#include "nel/georges/type.h"
using namespace NLGEORGES;
using namespace NLMISC;
/////////////////////////////////////////////////////////////////////////////
// CHeaderDialog dialog
CHeaderDialog::CHeaderDialog () : CBaseDialog (IDR_MAINFRAME)
{
//{{AFX_DATA_INIT(CHeaderDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
View = NULL;
}
void CHeaderDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHeaderDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHeaderDialog, CDialog)
//{{AFX_MSG_MAP(CHeaderDialog)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHeaderDialog message handlers
void CHeaderDialog::OnSize(UINT nType, int cx, int cy)
{
CBaseDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
BOOL CHeaderDialog::OnInitDialog()
{
CBaseDialog::OnInitDialog();
// Refresh sizes
RECT viewRect;
View->GetClientRect (&viewRect);
uint virtualWidth = std::max ((uint)MinViewWidth, (uint)(viewRect.right-viewRect.left));
CBaseDialog::resizeWidgets (virtualWidth, 0);
// Get first item coordinate
RECT currentPos;
getFirstItemPos (currentPos);
// Create the version
setStaticSize (currentPos);
CString versionText;
versionText.Format(_T("Version %d.%d"), 0, 0);
LabelVersion.Create (versionText, WS_VISIBLE, currentPos, this);
initWidget (LabelVersion);
getNextPosLabel (currentPos);
setButtonSize (currentPos, SmallWidget);
IncrementVersion.Create (_T("Increment Version"), WS_VISIBLE|WS_TABSTOP, currentPos, this, BtIncrement);
initWidget (IncrementVersion);
getNextPos (currentPos);
// Create the state combo
setStaticSize (currentPos);
LabelState.Create (_T("State:"), WS_VISIBLE, currentPos, this);
initWidget (LabelState);
getNextPosLabel (currentPos);
setComboSize (currentPos, SmallWidget);
RECT pos = currentPos;
adjusteComboSize (pos);
ComboState.Create (WS_VISIBLE|CBS_DROPDOWNLIST|WS_TABSTOP, pos, this, CbState);
uint item;
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);
setButtonSize (currentPos, SmallWidget);
getNextPos (currentPos);
setStaticSize (currentPos);
getNextPosLabel (currentPos);
setComboSize (currentPos, SmallWidget);
getNextPos (currentPos);
setStaticSize (currentPos);
getNextPosLabel (currentPos);
setBigEditSize (currentPos, Width, BigEditHeight);
getNextPos (currentPos);
setStaticSize (currentPos);
getNextPosLabel (currentPos);
setBigEditSize (currentPos, Width, BigEditHeight);
getNextPos (currentPos);
// Refresh sizes
CBaseDialog::resizeWidgets (virtualWidth, currentPos.bottom);
// Get first item coordinate
currentPos;
getFirstItemPos (currentPos);
uint adjust = AdjusteHeight / 2;
// Resize
setStaticSize (currentPos);
LabelVersion.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
getNextPosLabel (currentPos);
// Resize
setButtonSize (currentPos, SmallWidget);
IncrementVersion.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
getNextPos (currentPos);
// Resize
setStaticSize (currentPos);
LabelState.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
getNextPosLabel (currentPos);
// Resize
setComboSize (currentPos, SmallWidget);
RECT pos = currentPos;
adjusteComboSize (pos);
ComboState.SetWindowPos (NULL, pos.left, pos.top, pos.right - pos.left,
pos.bottom - pos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
getNextPos (currentPos);
// Resize
setStaticSize (currentPos);
LabelComments.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
getNextPosLabel (currentPos);
// Resize
setBigEditSize (currentPos, Width, BigEditHeight + adjust);
Comments.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
getNextPos (currentPos);
// Resize
setStaticSize (currentPos);
LabelLog.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
getNextPosLabel (currentPos);
// Resize
setBigEditSize (currentPos, Width, BigEditHeight + AdjusteHeight - adjust);
Log.SetWindowPos (NULL, currentPos.left, currentPos.top, currentPos.right - currentPos.left,
currentPos.bottom - currentPos.top, SWP_NOZORDER|SWP_NOOWNERZORDER);
getNextPos (currentPos);
// Resize the current view
View->setViewSize (
virtualWidth,
currentPos.bottom+CGeorgesEditView::WidgetTopMargin+CGeorgesEditView::WidgetBottomMargin);
}
void CHeaderDialog::getFromDocument (const NLGEORGES::CFileHeader &header)
{
if (View)
{
// Nel standard version number
ComboState.SetCurSel (header.State);
CString name;
name.Format(_T("Version %d.%d"), header.MajorVersion, header.MinorVersion);
LabelVersion.SetWindowText (name);
// Set comments
setEditTextMultiLine (Comments, header.Comments.c_str());
// Set logs
setEditTextMultiLine (Log, header.Log.c_str());
}
}
void CHeaderDialog::setStateToDocument ()
{
CGeorgesEditDoc *doc = View->GetDocument ();
if (doc)
{
CGeorgesEditDocSub *current = doc->getSelectedObject ();
CFileHeader *header = doc->getHeaderPtr ();
doc->modify (new CActionString (IAction::HeaderState, toString ((int)(CFileHeader::TState)ComboState.GetCurSel ()).c_str (),
*doc, "", "", doc->getLeftView ()->getCurrentSelectionId (), 0), true, false);
}
}
void CHeaderDialog::setVersionToDocument ()
{
CGeorgesEditDoc *doc = View->GetDocument ();
if (doc)
{
uint v0, v1;
CString str;
LabelVersion.GetWindowText (str);
if (sscanf (tStrToUtf8(str).c_str(), "Version %d.%d", &v0, &v1)==2)
{
v0++;
v1=0;
CString name;
name.Format(_T("Version %d.%d"), v0, v1);
LabelVersion.SetWindowText (name);
// Modify docuemnt
doc->modify(new CActionString(IAction::HeaderVersion, tStrToUtf8(name).c_str(), *doc, "", "",
doc->getLeftView ()->getCurrentSelectionId (), 0));
}
}
}
void CHeaderDialog::setCommentsToDocument ()
{
CGeorgesEditDoc *doc = View->GetDocument ();
if (doc)
{
CGeorgesEditDocSub *current = doc->getSelectedObject ();
CString str;
Comments.GetWindowText (str);
doc->modify(new CActionString(IAction::HeaderComments, tStrToUtf8(str).c_str(), *doc, "", "",
doc->getLeftView ()->getCurrentSelectionId (), 0));
}
}
BOOL CHeaderDialog::OnCommand(WPARAM wParam, LPARAM lParam)
{
switch (HIWORD(wParam))
{
case EN_CHANGE:
{
// identifier
switch (LOWORD(wParam))
{
case EdComments:
setCommentsToDocument ();
break;
}
}
break;
case CBN_SELCHANGE:
{
// identifier
switch (LOWORD(wParam))
{
case CbState:
setStateToDocument ();
break;
}
}
break;
case BN_CLICKED:
{
// identifier
switch (LOWORD(wParam))
{
case BtIncrement:
setVersionToDocument ();
break;
}
}
}
return CWnd::OnCommand(wParam, lParam);
}
void CHeaderDialog::onFirstFocus ()
{
View->SetFocus ();
}
void CHeaderDialog::onLastFocus ()
{
View->setFocusLeftView ();
}