deargui-vpl/ref/virtools/Samples/Virtools Interface SDK/ShaderEditor/ShaderEditorFileDialog.cpp

202 lines
5.1 KiB
C++

// ShaderEditorFileDialog.cpp : implementation file
//
#include "stdafx.h"
#include "ShaderEditorFileDialog.h"
#include "afxpriv.h"
#include "Resource.h"
#ifdef _MFCDEBUGNEW
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#endif
LRESULT CALLBACK m_newWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK m_newDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT OnCustomDraw(HWND hWnd,WPARAM wParam,LPARAM lParam);
CMapPtrToPtr m_wndProcMap;
CMapPtrToPtr m_dlgProcMap;
CMapPtrToPtr m_wndBackgroundColorMap;
#define CUIKFILEDIALOG_BUFFERMAXCHAR 512
/////////////////////////////////////////////////////////////////////////////
// ShaderEditorFileDialog
IMPLEMENT_DYNAMIC(ShaderEditorFileDialog, CFileDialog)
ShaderEditorFileDialog::ShaderEditorFileDialog(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
m_ofn.nMaxFile = _MAX_PATH;
m_ofn.Flags |= OFN_EXPLORER;
m_ofn.Flags &= ~OFN_SHOWHELP;
m_ofn.Flags |= OFN_ENABLETEMPLATE;
m_ofn.Flags |= OFN_ENABLESIZING;
m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_SHADERCUSTOMFILEDIALOG);
m_UpdateText = FALSE;
}
BEGIN_MESSAGE_MAP(ShaderEditorFileDialog, CFileDialog)
//{{AFX_MSG_MAP(ShaderEditorFileDialog)
ON_WM_HELPINFO()
ON_WM_CONTEXTMENU()
ON_WM_DESTROY()
ON_WM_NCPAINT()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_COMMAND(ID_HELP, OnHelp)
END_MESSAGE_MAP()
void ShaderEditorFileDialog::DoDataExchange(CDataExchange* pDX)
{
CFileDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCustomFileDialog)
DDX_Control(pDX, IDC_SAVESCRIPTSGRAPHS, m_updateTextButton);
//}}AFX_DATA_MAP
}
BOOL ShaderEditorFileDialog::OnInitDialog()
{
CWnd * parent=GetParent();
CFileDialog::OnInitDialog();
parent=GetParent();
//style
long style=GetWindowLong(parent->m_hWnd,GWL_STYLE);
style&=~WS_SYSMENU;
SetWindowLong(parent->m_hWnd,GWL_STYLE,style);
//font
parent->SetFont(GetVIFont(VIFONT_NORMAL));
SetFont(GetVIFont(VIFONT_NORMAL));
//m_saveScriptButton.SetFont(parent->GetFont());
m_updateTextButton.SetFont(GetVIFont(VIFONT_NORMAL));
m_updateTextButton.SetCheck(0);
m_updateTextButton.ShowWindow(SW_SHOW);
{
RECT r;
GetWindowRect(&r);
SetWindowPos(0,0,0,r.right-r.left,r.bottom-r.top,SWP_NOMOVE|SWP_NOZORDER);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL ShaderEditorFileDialog::UpdateTextOnly()
{
return m_UpdateText;
}
BOOL ShaderEditorFileDialog::OnFileNameOK() {
return CFileDialog::OnFileNameOK();
}
void ShaderEditorFileDialog::OnDestroy()
{
m_UpdateText = m_updateTextButton.GetCheck();
CFileDialog::OnDestroy();
m_wndProcMap.RemoveAll();
m_dlgProcMap.RemoveAll();
}
void ShaderEditorFileDialog::OnSize(UINT nType, int cx, int cy)
{
CFileDialog::OnSize(nType, cx, cy);
}
LRESULT ShaderEditorFileDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
return CFileDialog::WindowProc(message, wParam, lParam);
}
int ShaderEditorFileDialog::DoModal()
{
ASSERT_VALID(this);
ASSERT(m_ofn.Flags & OFN_ENABLEHOOK);
ASSERT(m_ofn.lpfnHook != NULL); // can still be a user hook
// zero out the file buffer for consistent parsing later
ASSERT(AfxIsValidAddress(m_ofn.lpstrFile, m_ofn.nMaxFile));
DWORD nOffset = lstrlen(m_ofn.lpstrFile)+1;
ASSERT(nOffset <= m_ofn.nMaxFile);
memset(m_ofn.lpstrFile+nOffset, 0, (m_ofn.nMaxFile-nOffset)*sizeof(TCHAR));
// WINBUG: This is a special case for the file open/save dialog,
// which sometimes pumps while it is coming up but before it has
// disabled the main window.
HWND hWndFocus = ::GetFocus();
BOOL bEnableParent = FALSE;
m_ofn.hwndOwner = PreModal();
AfxUnhookWindowCreate();
if (m_ofn.hwndOwner != NULL && ::IsWindowEnabled(m_ofn.hwndOwner))
{
bEnableParent = TRUE;
::EnableWindow(m_ofn.hwndOwner, FALSE);
}
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
ASSERT(pThreadState->m_pAlternateWndInit == NULL);
if (m_ofn.Flags & OFN_EXPLORER)
pThreadState->m_pAlternateWndInit = this;
else
AfxHookWindowCreate(this);
#if _MSC_VER < 1300
memset(&m_ofnEx, 0, sizeof(m_ofnEx));
memcpy(&m_ofnEx, &m_ofn, sizeof(m_ofn));
//Works only on W2K and later
#pragma TODO(Todo : Do not start Cuik not on W2K and later)
m_ofnEx.lStructSize = sizeof(m_ofnEx);
#endif
int nResult;
if (m_bOpenFileDialog) {
#if _MSC_VER < 1300
nResult = ::GetOpenFileName(&m_ofnEx);
#else
nResult = ::GetOpenFileName(&m_ofn);
#endif
} else {
#if _MSC_VER < 1300
nResult = ::GetSaveFileName(&m_ofnEx);
#else
nResult = ::GetSaveFileName(&m_ofn);
#endif
}
if (nResult)
ASSERT(pThreadState->m_pAlternateWndInit == NULL);
pThreadState->m_pAlternateWndInit = NULL;
// WINBUG: Second part of special case for file open/save dialog.
if (bEnableParent)
::EnableWindow(m_ofn.hwndOwner, TRUE);
if (::IsWindow(hWndFocus))
::SetFocus(hWndFocus);
PostModal();
//Copy the resuult back in the classic OFN
#if _MSC_VER < 1300
memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn));
#endif
return nResult ? nResult : IDCANCEL;
}