diff --git a/common/project.cpp b/common/project.cpp index fc20c36d..8031fcde 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -4052,6 +4052,13 @@ void Project::HandleCommand(LC_COMMANDS id) { lcImageDialogOptions Options; + int ImageOptions = lcGetProfileInt(LC_PROFILE_IMAGE_OPTIONS); + + Options.Format = (LC_IMAGE_FORMAT)(ImageOptions & ~(LC_IMAGE_MASK)); + Options.Transparent = (ImageOptions & LC_IMAGE_TRANSPARENT) != 0; + Options.Width = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH); + Options.Height = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); + if (m_strPathName[0]) strcpy(Options.FileName, m_strPathName); else if (m_strTitle[0]) @@ -4078,13 +4085,6 @@ void Project::HandleCommand(LC_COMMANDS id) } } - int ImageOptions = lcGetProfileInt(LC_PROFILE_IMAGE_OPTIONS); - - Options.Format = (LC_IMAGE_FORMAT)(ImageOptions & ~(LC_IMAGE_MASK)); - Options.Transparent = (ImageOptions & LC_IMAGE_TRANSPARENT) != 0; - Options.Width = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH); - Options.Height = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); - if (m_bAnimation) { Options.Start = 1; @@ -4112,60 +4112,60 @@ void Project::HandleCommand(LC_COMMANDS id) strcpy(Options.FileName, "Image"); char* Ext = strrchr(Options.FileName, '.'); - if (Ext) - { + if (Ext) + { if (!strcmp(Ext, ".jpg") || !strcmp(Ext, ".jpeg") || !strcmp(Ext, ".bmp") || !strcmp(Ext, ".png")) - *Ext = 0; - } + *Ext = 0; + } - const char* ext; + const char* ext; switch (Options.Format) - { + { case LC_IMAGE_BMP: ext = ".bmp"; break; case LC_IMAGE_JPG: ext = ".jpg"; break; - default: + default: case LC_IMAGE_PNG: ext = ".png"; break; - } + } - if (m_bAnimation) + if (m_bAnimation) Options.End = lcMin(Options.End, m_nTotalFrames); - else + else Options.End = lcMin(Options.End, 255); Options.Start = lcMax(1, Options.Start); if (Options.Start > Options.End) - { + { if (Options.Start > Options.End) - { + { int Temp = Options.Start; Options.Start = Options.End; Options.End = Temp; - } } + } Image* images = new Image[Options.End - Options.Start + 1]; CreateImages(images, Options.Width, Options.Height, Options.Start, Options.End, false); for (int i = 0; i <= Options.End - Options.Start; i++) - { - char filename[LC_MAXPATH]; + { + char filename[LC_MAXPATH]; if (Options.Start != Options.End) - { + { sprintf(filename, "%s%02d%s", Options.FileName, i+1, ext); - } - else - { + } + else + { strcat(Options.FileName, ext); strcpy(filename, Options.FileName); - } + } images[i].FileSave(filename, Options.Format, Options.Transparent); - } - delete []images; + } + delete []images; } break; case LC_FILE_EXPORT_3DS: diff --git a/qt/lc_qimagedialog.cpp b/qt/lc_qimagedialog.cpp index 10c918cf..3b7b076c 100644 --- a/qt/lc_qimagedialog.cpp +++ b/qt/lc_qimagedialog.cpp @@ -96,3 +96,29 @@ void lcQImageDialog::on_fileNameBrowse_clicked() if (!result.isEmpty()) ui->fileName->setText(QDir::toNativeSeparators(result)); } + +void lcQImageDialog::on_format_currentIndexChanged(int index) +{ + QString fileName = ui->fileName->text(); + QString extension = QFileInfo(fileName).suffix().toLower(); + + QString newExtension; + switch (index) + { + case LC_IMAGE_BMP: newExtension = "bmp"; + break; + case LC_IMAGE_JPG: newExtension = "jpg"; + break; + default: + case LC_IMAGE_PNG: newExtension = "png"; + break; + } + + if (extension == newExtension) + return; + + if (extension == "bmp" || extension == "png" || extension == "jpg" || extension == "jpeg") + fileName = fileName.left(fileName.length() - extension.length()) + newExtension; + + ui->fileName->setText(fileName); +} diff --git a/qt/lc_qimagedialog.h b/qt/lc_qimagedialog.h index 2b522472..a4677c5a 100644 --- a/qt/lc_qimagedialog.h +++ b/qt/lc_qimagedialog.h @@ -21,6 +21,7 @@ public: public slots: void accept(); void on_fileNameBrowse_clicked(); + void on_format_currentIndexChanged(int index); private: Ui::lcQImageDialog *ui; diff --git a/win/Teropdlg.cpp b/win/Teropdlg.cpp deleted file mode 100644 index 84af3cac..00000000 --- a/win/Teropdlg.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "lc_global.h" -#include "leocad.h" -#include "TerOpDlg.h" -#include "Terrain.h" -#include "Tools.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CTerrainOptionsDlg dialog - - -CTerrainOptionsDlg::CTerrainOptionsDlg(CWnd* pParent /*=NULL*/) - : CDialog(CTerrainOptionsDlg::IDD, pParent) -{ - //{{AFX_DATA_INIT(CTerrainOptionsDlg) - m_nXPatches = 0; - m_nYPatches = 0; - m_fXSize = 0.0f; - m_fYSize = 0.0f; - m_bFlat = FALSE; - m_bTexture = FALSE; - m_strTexture = _T(""); - m_bSmooth = FALSE; - //}}AFX_DATA_INIT -} - - -void CTerrainOptionsDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CTerrainOptionsDlg) - DDX_Control(pDX, IDC_TEROPT_COLOR, m_btnColor); - DDX_Text(pDX, IDC_TEROPT_XPAT, m_nXPatches); - DDV_MinMaxInt(pDX, m_nXPatches, 1, 1024); - DDX_Text(pDX, IDC_TEROPT_YPAT, m_nYPatches); - DDV_MinMaxInt(pDX, m_nYPatches, 1, 1024); - DDX_Text(pDX, IDC_TEROPT_XSIZE, m_fXSize); - DDV_MinMaxFloat(pDX, m_fXSize, 1.f, 1024.f); - DDX_Text(pDX, IDC_TEROPT_YSIZE, m_fYSize); - DDV_MinMaxFloat(pDX, m_fYSize, 1.f, 1024.f); - DDX_Check(pDX, IDC_TEROPT_FLAT, m_bFlat); - DDX_Check(pDX, IDC_TEROPT_TEXTURE, m_bTexture); - DDX_Text(pDX, IDC_TEROPT_TEXTURENAME, m_strTexture); - DDX_Check(pDX, IDC_TEROPT_SMOOTH, m_bSmooth); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CTerrainOptionsDlg, CDialog) - //{{AFX_MSG_MAP(CTerrainOptionsDlg) - ON_BN_CLICKED(IDC_TEROPT_COLOR, OnTeroptColor) - ON_BN_CLICKED(IDC_TEROPT_TEXTUREBROWSE, OnTeroptTexturebrowse) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CTerrainOptionsDlg message handlers - -void CTerrainOptionsDlg::OnTeroptColor() -{ - CColorDialog dlg(m_crTerrain); - if (dlg.DoModal() == IDOK) - { - m_crTerrain = dlg.GetColor(); - DeleteObject(m_btnColor.SetBitmap(CreateColorBitmap (20, 10, m_crTerrain))); - } -} - -void CTerrainOptionsDlg::OnTeroptTexturebrowse() -{ - CFileDialog dlg(TRUE, NULL, m_strTexture, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, - "All Image Files|*.bmp;*.gif;*.jpg;*.png|JPEG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|BMP Files (*.bmp)|*.bmp|PNG Files (*.png)|*.png|All Files (*.*)|*.*||", this); - if (dlg.DoModal() == IDOK) - { - UpdateData(TRUE); - m_strTexture = dlg.GetPathName(); - UpdateData(FALSE); - } -} - -void CTerrainOptionsDlg::SetOptions(Terrain* pTerrain) -{ - pTerrain->GetPatchCount(&m_nXPatches, &m_nYPatches); - pTerrain->GetSize(&m_fXSize, &m_fYSize); - m_crTerrain = RGB(pTerrain->m_fColor[0]*255, pTerrain->m_fColor[1]*255, pTerrain->m_fColor[2]*255); - m_strTexture = pTerrain->m_strTexture; - m_bFlat = (pTerrain->m_nOptions & LC_TERRAIN_FLAT) != 0; - m_bTexture = (pTerrain->m_nOptions & LC_TERRAIN_TEXTURE) != 0; - m_bSmooth = (pTerrain->m_nOptions & LC_TERRAIN_SMOOTH) != 0; -} - -void CTerrainOptionsDlg::GetOptions(Terrain* pTerrain) -{ - pTerrain->SetSize(m_fXSize, m_fYSize); - pTerrain->SetPatchCount(m_nXPatches, m_nYPatches); - pTerrain->m_fColor[0] = (float)GetRValue(m_crTerrain)/255; - pTerrain->m_fColor[1] = (float)GetGValue(m_crTerrain)/255; - pTerrain->m_fColor[2] = (float)GetBValue(m_crTerrain)/255; - pTerrain->m_nOptions = 0; - strcpy(pTerrain->m_strTexture, m_strTexture); - - if (m_bFlat) pTerrain->m_nOptions |= LC_TERRAIN_FLAT; - if (m_bTexture) pTerrain->m_nOptions |= LC_TERRAIN_TEXTURE; - if (m_bSmooth) pTerrain->m_nOptions |= LC_TERRAIN_SMOOTH; -} - -BOOL CTerrainOptionsDlg::OnInitDialog() -{ - CDialog::OnInitDialog(); - - DeleteObject(m_btnColor.SetBitmap(CreateColorBitmap (20, 10, m_crTerrain))); - - return TRUE; -} diff --git a/win/Teropdlg.h b/win/Teropdlg.h deleted file mode 100644 index d1f6ca8b..00000000 --- a/win/Teropdlg.h +++ /dev/null @@ -1,60 +0,0 @@ -#if !defined(AFX_TEROPDLG_H__16D85803_DBE0_11D2_8204_C46524CA8617__INCLUDED_) -#define AFX_TEROPDLG_H__16D85803_DBE0_11D2_8204_C46524CA8617__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 -// TerOpDlg.h : header file -// - -class Terrain; - -///////////////////////////////////////////////////////////////////////////// -// CTerrainOptionsDlg dialog - -class CTerrainOptionsDlg : public CDialog -{ -// Construction -public: - void GetOptions(Terrain* pTerrain); - void SetOptions(Terrain* pTerrain); - CTerrainOptionsDlg(CWnd* pParent = NULL); // standard constructor - COLORREF m_crTerrain; - -// Dialog Data - //{{AFX_DATA(CTerrainOptionsDlg) - enum { IDD = IDD_TERRAIN_OPTIONS }; - CButton m_btnColor; - int m_nXPatches; - int m_nYPatches; - float m_fXSize; - float m_fYSize; - BOOL m_bFlat; - BOOL m_bTexture; - CString m_strTexture; - BOOL m_bSmooth; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CTerrainOptionsDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - // Generated message map functions - //{{AFX_MSG(CTerrainOptionsDlg) - afx_msg void OnTeroptColor(); - afx_msg void OnTeroptTexturebrowse(); - virtual BOOL OnInitDialog(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_TEROPDLG_H__16D85803_DBE0_11D2_8204_C46524CA8617__INCLUDED_) diff --git a/win/glwindow.cpp b/win/glwindow.cpp deleted file mode 100644 index 73831886..00000000 --- a/win/glwindow.cpp +++ /dev/null @@ -1,571 +0,0 @@ -#include "lc_global.h" -#include "opengl.h" -#include "glwindow.h" -#include "system.h" -#include "tools.h" -#include "resource.h" - -#ifndef WGL_ARB_extensions_string -#define WGL_ARB_extensions_string 1 - -typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc); - -PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = NULL; - -#endif // WGL_ARB_extensions_string - -#ifndef WGL_ARB_multisample -#define WGL_SAMPLE_BUFFERS_ARB 0x2041 -#define WGL_SAMPLES_ARB 0x2042 -#endif - -#ifndef WGL_ARB_pixel_format -#define WGL_ARB_pixel_format 1 - -#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 -#define WGL_DRAW_TO_WINDOW_ARB 0x2001 -#define WGL_DRAW_TO_BITMAP_ARB 0x2002 -#define WGL_ACCELERATION_ARB 0x2003 -#define WGL_NEED_PALETTE_ARB 0x2004 -#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 -#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 -#define WGL_SWAP_METHOD_ARB 0x2007 -#define WGL_NUMBER_OVERLAYS_ARB 0x2008 -#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 -#define WGL_TRANSPARENT_ARB 0x200A -#define WGL_SHARE_DEPTH_ARB 0x200C -#define WGL_SHARE_STENCIL_ARB 0x200D -#define WGL_SHARE_ACCUM_ARB 0x200E -#define WGL_SUPPORT_GDI_ARB 0x200F -#define WGL_SUPPORT_OPENGL_ARB 0x2010 -#define WGL_DOUBLE_BUFFER_ARB 0x2011 -#define WGL_STEREO_ARB 0x2012 -#define WGL_PIXEL_TYPE_ARB 0x2013 -#define WGL_COLOR_BITS_ARB 0x2014 -#define WGL_RED_BITS_ARB 0x2015 -#define WGL_RED_SHIFT_ARB 0x2016 -#define WGL_GREEN_BITS_ARB 0x2017 -#define WGL_GREEN_SHIFT_ARB 0x2018 -#define WGL_BLUE_BITS_ARB 0x2019 -#define WGL_BLUE_SHIFT_ARB 0x201A -#define WGL_ALPHA_BITS_ARB 0x201B -#define WGL_ALPHA_SHIFT_ARB 0x201C -#define WGL_ACCUM_BITS_ARB 0x201D -#define WGL_ACCUM_RED_BITS_ARB 0x201E -#define WGL_ACCUM_GREEN_BITS_ARB 0x201F -#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 -#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 -#define WGL_DEPTH_BITS_ARB 0x2022 -#define WGL_STENCIL_BITS_ARB 0x2023 -#define WGL_AUX_BUFFERS_ARB 0x2024 -#define WGL_NO_ACCELERATION_ARB 0x2025 -#define WGL_GENERIC_ACCELERATION_ARB 0x2026 -#define WGL_FULL_ACCELERATION_ARB 0x2027 -#define WGL_SWAP_EXCHANGE_ARB 0x2028 -#define WGL_SWAP_COPY_ARB 0x2029 -#define WGL_SWAP_UNDEFINED_ARB 0x202A -#define WGL_TYPE_RGBA_ARB 0x202B -#define WGL_TYPE_COLORINDEX_ARB 0x202C -#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 -#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 -#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 -#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A -#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B - -typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); -typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, FLOAT *pfValues); -typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, int *piValues); - -PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = NULL; -PFNWGLGETPIXELFORMATATTRIBFVARBPROC wglGetPixelFormatAttribfvARB = NULL; -PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = NULL; - -#endif // WGL_ARB_pixel_format - -struct GLWindowPrivate -{ - HGLRC m_hrc; - CDC* m_pDC; - CPalette* m_pPal; - HWND m_hWnd; - HCURSOR Cursor; - bool Multisample; -}; - -// ============================================================================ - -BOOL GLWindowPreTranslateMessage(GLWindow *wnd, MSG *pMsg) -{ - switch (pMsg->message) - { - case WM_PAINT: - { - GLWindowPrivate* prv = (GLWindowPrivate*)wnd->GetData(); - PAINTSTRUCT ps; - BeginPaint(prv->m_hWnd, &ps); - wnd->MakeCurrent(); - wnd->OnDraw(); - SwapBuffers(prv->m_pDC->m_hDC); - EndPaint(prv->m_hWnd, &ps); - } break; - case WM_SIZE: - wnd->OnSize(LOWORD(pMsg->lParam), HIWORD(pMsg->lParam)); - break; - case WM_LBUTTONDOWN: - wnd->OnLeftButtonDown((SHORT)LOWORD(pMsg->lParam), wnd->GetHeight() - (SHORT)HIWORD(pMsg->lParam) - 1, - (pMsg->wParam & MK_CONTROL) != 0, (pMsg->wParam & MK_SHIFT) != 0); - break; - case WM_LBUTTONUP: - wnd->OnLeftButtonUp((SHORT)LOWORD(pMsg->lParam), wnd->GetHeight() - (SHORT)HIWORD(pMsg->lParam) - 1, - (pMsg->wParam & MK_CONTROL) != 0, (pMsg->wParam & MK_SHIFT) != 0); - break; - case WM_LBUTTONDBLCLK: - wnd->OnLeftButtonDoubleClick((SHORT)LOWORD(pMsg->lParam), wnd->GetHeight() - (SHORT)HIWORD(pMsg->lParam) - 1, - (pMsg->wParam & MK_CONTROL) != 0, (pMsg->wParam & MK_SHIFT) != 0); - break; - case WM_MBUTTONDOWN: - wnd->OnMiddleButtonDown((SHORT)LOWORD(pMsg->lParam), wnd->GetHeight() - (SHORT)HIWORD(pMsg->lParam) - 1, - (pMsg->wParam & MK_CONTROL) != 0, (pMsg->wParam & MK_SHIFT) != 0); - break; - case WM_MBUTTONUP: - wnd->OnMiddleButtonUp((SHORT)LOWORD(pMsg->lParam), wnd->GetHeight() - (SHORT)HIWORD(pMsg->lParam) - 1, - (pMsg->wParam & MK_CONTROL) != 0, (pMsg->wParam & MK_SHIFT) != 0); - break; - case WM_RBUTTONDOWN: - wnd->OnRightButtonDown((SHORT)LOWORD(pMsg->lParam), wnd->GetHeight() - (SHORT)HIWORD(pMsg->lParam) - 1, - (pMsg->wParam & MK_CONTROL) != 0, (pMsg->wParam & MK_SHIFT) != 0); - break; - case WM_RBUTTONUP: - wnd->OnRightButtonUp((SHORT)LOWORD(pMsg->lParam), wnd->GetHeight() - (SHORT)HIWORD(pMsg->lParam) - 1, - (pMsg->wParam & MK_CONTROL) != 0, (pMsg->wParam & MK_SHIFT) != 0); - break; - case WM_MOUSEMOVE: - wnd->OnMouseMove((SHORT)LOWORD(pMsg->lParam), wnd->GetHeight() - (SHORT)HIWORD(pMsg->lParam) - 1, - (pMsg->wParam & MK_CONTROL) != 0, (pMsg->wParam & MK_SHIFT) != 0); - break; - case WM_MOUSEWHEEL: - wnd->OnMouseWheel((SHORT)LOWORD(pMsg->lParam), wnd->GetHeight() - (SHORT)HIWORD(pMsg->lParam) - 1, (float)(short)HIWORD(pMsg->wParam) / (float)WHEEL_DELTA, - (pMsg->wParam & MK_CONTROL) != 0, (pMsg->wParam & MK_SHIFT) != 0); - break; - case WM_ERASEBKGND: - return TRUE; - case WM_CREATE: - wnd->OnInitialUpdate(); - break; - case WM_DESTROY: - wnd->DestroyContext(); - return FALSE; - break; - case WM_SETCURSOR: - { - GLWindowPrivate *prv = (GLWindowPrivate*)wnd->GetData(); - - if (prv->Cursor) - { - SetCursor(prv->Cursor); - return TRUE; - } - - return FALSE; - } break; - case WM_PALETTECHANGED: - if ((HWND)pMsg->wParam == pMsg->hwnd) // Responding to own message. - break; - case WM_QUERYNEWPALETTE: - { - GLWindowPrivate *prv = (GLWindowPrivate*)wnd->GetData(); - - if (prv->m_pPal) - { - prv->m_pDC->SelectPalette(prv->m_pPal, FALSE); - if (prv->m_pDC->RealizePalette() != 0) - { - // Some colors changed, so we need to do a repaint. - InvalidateRect(prv->m_hWnd, NULL, TRUE); - } - } - } break; - - default: - return FALSE; - } - - return TRUE; -} - -LRESULT CALLBACK GLWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - static CMapPtrToPtr WindowMap; - GLWindow *wnd; - - if (uMsg == WM_CREATE) - { - LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam; - - wnd = (GLWindow*)cs->lpCreateParams; - wnd->CreateFromWindow(hwnd); - - WindowMap.SetAt(hwnd, wnd); - } - - wnd = (GLWindow*)WindowMap[hwnd]; - - if (wnd) - { - MSG msg; - msg.hwnd = hwnd; - msg.message = uMsg; - msg.wParam = wParam; - msg.lParam = lParam; - - GLWindowPreTranslateMessage(wnd, &msg); - - if (uMsg == WM_DESTROY) - { - WindowMap.RemoveKey(hwnd); - } - } - - return DefWindowProc(hwnd, uMsg, wParam, lParam); -} - -static LRESULT CALLBACK TempWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - if (uMsg != WM_CREATE) - return DefWindowProc(hWnd, uMsg, wParam, lParam); - - HDC hDC = GetDC(hWnd); - - PIXELFORMATDESCRIPTOR pfd; - memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); - - pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); - pfd.nVersion = 1; - pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 24; - pfd.cDepthBits = 24; - pfd.iLayerType = PFD_MAIN_PLANE; - - int PixelFormat = ChoosePixelFormat(hDC, &pfd); - if (PixelFormat == 0) - return 0; - - if (!SetPixelFormat(hDC, PixelFormat, &pfd)) - return 0; - - HGLRC hGLRC = wglCreateContext(hDC); - wglMakeCurrent(hDC, hGLRC); - - const GLubyte* Extensions; - - wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); - - if (wglGetExtensionsStringARB) - Extensions = (GLubyte*)wglGetExtensionsStringARB(wglGetCurrentDC()); - else - Extensions = glGetString(GL_EXTENSIONS); - - GL_InitializeSharedExtensions(); - - if (GL_ExtensionSupported(Extensions, "WGL_ARB_pixel_format")) - { - wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); - wglGetPixelFormatAttribfvARB = (PFNWGLGETPIXELFORMATATTRIBFVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribfvARB"); - wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB"); - } - - wglMakeCurrent(NULL, NULL); - wglDeleteContext(hGLRC); - - ReleaseDC(hWnd, hDC); - - return 0; -} - -void GL_InitializeExtensions() -{ - HINSTANCE hInstance; - WNDCLASS wc; - - hInstance = GetModuleHandle(NULL); - - wc.style = CS_OWNDC; - wc.lpfnWndProc = TempWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wc.lpszMenuName = NULL; - wc.lpszClassName = "LeoCADGLTempWindow"; - - RegisterClass(&wc); - - HWND hWnd = CreateWindow(wc.lpszClassName, "LeoCAD Temp Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); - - if (hWnd) - DestroyWindow(hWnd); -} - -// ============================================================================ -// GLWindow class - -GLWindow::GLWindow(GLWindow *share) -{ - m_pShare = share; - m_pData = (GLWindowPrivate*)malloc(sizeof(GLWindowPrivate)); - memset(m_pData, 0, sizeof(GLWindowPrivate)); -} - -GLWindow::~GLWindow() -{ - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - - delete prv->m_pDC; - - free(m_pData); -} - -bool GLWindow::CreateFromWindow(void* data) -{ - GLWindowPrivate* prv = (GLWindowPrivate*)m_pData; - - prv->m_hWnd = (HWND)data; - prv->m_pDC = new CClientDC(CWnd::FromHandle(prv->m_hWnd)); - ASSERT(prv->m_pDC != NULL); - - // Fill in the Pixel Format Descriptor - PIXELFORMATDESCRIPTOR pfd; - memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); - - pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); - pfd.nVersion = 1; - pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 24; - pfd.cDepthBits = 24; - pfd.iLayerType = PFD_MAIN_PLANE; - - int PixelFormat = 0; - int AASamples = Sys_ProfileLoadInt("Default", "AASamples", 1); - - if (wglChoosePixelFormatARB && AASamples > 1) - { - // Choose a Pixel Format Descriptor (PFD) with multisampling support. - int iAttributes[] = - { - WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, - WGL_SUPPORT_OPENGL_ARB, GL_TRUE, - WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, - WGL_COLOR_BITS_ARB, 24, - WGL_DEPTH_BITS_ARB, 24, - WGL_STENCIL_BITS_ARB, 0, - WGL_DOUBLE_BUFFER_ARB, GL_TRUE, - WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, - WGL_SAMPLES_ARB, AASamples, - 0, 0 - }; - float fAttributes[] = {0,0}; - UINT NumFormats; - int MultisamplePixelFormat; - - int Status = wglChoosePixelFormatARB(prv->m_pDC->m_hDC, iAttributes, fAttributes, 1, &MultisamplePixelFormat, &NumFormats); - - if (Status && NumFormats > 0) - { - PixelFormat = MultisamplePixelFormat; - prv->Multisample = true; - } - } - - if (!PixelFormat) - PixelFormat = ChoosePixelFormat(prv->m_pDC->m_hDC, &pfd); - - if (!PixelFormat) - return false; - - if (!SetPixelFormat(prv->m_pDC->m_hDC, PixelFormat, &pfd)) - return false; - - prv->m_pPal = new CPalette; - - if (CreateRGBPalette(prv->m_pDC->m_hDC, &prv->m_pPal)) - { - prv->m_pDC->SelectPalette(prv->m_pPal, FALSE); - prv->m_pDC->RealizePalette(); - } - else - { - delete prv->m_pPal; - prv->m_pPal = NULL; - } - - // Create a rendering context. - prv->m_hrc = wglCreateContext(prv->m_pDC->m_hDC); - if (!prv->m_hrc) - return false; - - if (m_pShare) - { - GLWindowPrivate *share = (GLWindowPrivate*)m_pShare->m_pData; - wglShareLists(share->m_hrc, prv->m_hrc); - } - - return true; -} - -bool GLWindow::CreateFromBitmap(void* Data) -{ - GLWindowPrivate* prv = (GLWindowPrivate*)m_pData; - - prv->m_pDC = new CDC; - prv->m_pDC->Attach((HDC)Data); - ASSERT(prv->m_pDC != NULL); - - // Fill in the Pixel Format Descriptor - PIXELFORMATDESCRIPTOR pfd; - memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); - - pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 24; - pfd.cDepthBits = 16; - pfd.iLayerType = PFD_MAIN_PLANE; - - int nPixelFormat = ChoosePixelFormat(prv->m_pDC->m_hDC, &pfd); - if (nPixelFormat == 0) - return false; - - if (!SetPixelFormat(prv->m_pDC->m_hDC, nPixelFormat, &pfd)) - return false; - - prv->m_pPal = new CPalette; - - if (CreateRGBPalette(prv->m_pDC->m_hDC, &prv->m_pPal)) - { - prv->m_pDC->SelectPalette(prv->m_pPal, FALSE); - prv->m_pDC->RealizePalette(); - } - else - { - delete prv->m_pPal; - prv->m_pPal = NULL; - } - - // Create a rendering context. - prv->m_hrc = wglCreateContext(prv->m_pDC->m_hDC); - if (!prv->m_hrc) - return false; - - if (m_pShare) - { - GLWindowPrivate *share = (GLWindowPrivate*)m_pShare->m_pData; - wglShareLists(share->m_hrc, prv->m_hrc); - } - - return true; -} - -void GLWindow::DestroyContext() -{ - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - - if (prv->m_pPal) - { - CPalette palDefault; - palDefault.CreateStockObject(DEFAULT_PALETTE); - prv->m_pDC->SelectPalette(&palDefault, FALSE); - delete prv->m_pPal; - prv->m_pPal = NULL; - } - - if (prv->m_hrc) - wglDeleteContext(prv->m_hrc); - prv->m_hrc = NULL; - - if (prv->m_pDC) - delete prv->m_pDC; - prv->m_pDC = NULL; -} - -void GLWindow::OnInitialUpdate() -{ - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - - MakeCurrent(); - - if (prv->Multisample) - glEnable(GL_MULTISAMPLE_ARB); -} - -bool GLWindow::MakeCurrent() -{ - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - - if (prv->m_pPal) - { - prv->m_pDC->SelectPalette(prv->m_pPal, FALSE); - prv->m_pDC->RealizePalette(); - } - - return (wglMakeCurrent(prv->m_pDC->m_hDC, prv->m_hrc) != 0); -} - -void GLWindow::Redraw(bool ForceRedraw) -{ - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - - InvalidateRect(prv->m_hWnd, NULL, FALSE); - - if (ForceRedraw) - UpdateWindow(prv->m_hWnd); -} - -void GLWindow::CaptureMouse() -{ - GLWindowPrivate* prv = (GLWindowPrivate*)m_pData; - SetCapture(prv->m_hWnd); -} - -void GLWindow::ReleaseMouse() -{ - ReleaseCapture(); -} - -void GLWindow::SetCursor(LC_CURSOR_TYPE Cursor) -{ - const UINT CursorResources[LC_CURSOR_COUNT] = - { - 0, // LC_CURSOR_DEFAULT - IDC_BRICK, // LC_CURSOR_BRICK - IDC_LIGHT, // LC_CURSOR_LIGHT - IDC_SPOTLIGHT, // LC_CURSOR_SPOTLIGHT - IDC_CAMERA, // LC_CURSOR_CAMERA - IDC_SELECT, // LC_CURSOR_SELECT - IDC_SELECT_GROUP, // LC_CURSOR_SELECT_GROUP - IDC_MOVE, // LC_CURSOR_MOVE - IDC_ROTATE, // LC_CURSOR_ROTATE - IDC_ROTX, // LC_CURSOR_ROTATEX - IDC_ROTY, // LC_CURSOR_ROTATEY - IDC_ERASER, // LC_CURSOR_DELETE - IDC_PAINT, // LC_CURSOR_PAINT - IDC_ZOOM, // LC_CURSOR_ZOOM - IDC_ZOOM_REGION, // LC_CURSOR_ZOOM_REGION - IDC_PAN, // LC_CURSOR_PAN - IDC_ROLL, // LC_CURSOR_ROLL - IDC_ANGLE, // LC_CURSOR_ROTATE_VIEW - }; - - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - - if (CursorResources[Cursor]) - prv->Cursor = AfxGetApp()->LoadCursor(CursorResources[Cursor]); - else - prv->Cursor = NULL; - - ::SetCursor(prv->Cursor); -} diff --git a/win/ipedit.cpp b/win/ipedit.cpp deleted file mode 100644 index 85085400..00000000 --- a/win/ipedit.cpp +++ /dev/null @@ -1,222 +0,0 @@ -#include "lc_global.h" -#include "IPEdit.h" -#include "TerrCtrl.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CInPlaceEdit - -CInPlaceEdit::CInPlaceEdit(CWnd* pParent, CRect& rect, DWORD dwStyle, UINT nID, - float* pHeight, CString sInitText, - UINT nFirstChar) -{ - m_sInitText = sInitText; - m_pHeight = pHeight; - m_nLastChar = 0; - // If mouse click brought us here, - // then no exit on arrows - m_bExitOnArrows = (nFirstChar != VK_LBUTTON); - - DWORD dwEditStyle = WS_BORDER|WS_CHILD|WS_VISIBLE| ES_AUTOHSCROLL //|ES_MULTILINE - | dwStyle; - if (!Create(dwEditStyle, rect, pParent, nID)) return; - - SetFont(pParent->GetFont()); - - SetWindowText(sInitText); - SetFocus(); - ResizeControl(); - - switch (nFirstChar) - { - case VK_LBUTTON: - case VK_RETURN: SetSel((int)_tcslen(m_sInitText), -1); return; - case VK_BACK: SetSel((int)_tcslen(m_sInitText), -1); break; - case VK_DOWN: - case VK_UP: - case VK_RIGHT: - case VK_LEFT: - case VK_NEXT: - case VK_PRIOR: - case VK_HOME: - case VK_SPACE: - case VK_END: SetSel(0,-1); return; - default: SetSel(0,-1); - } - - SendMessage(WM_CHAR, nFirstChar); -} - -CInPlaceEdit::~CInPlaceEdit() -{ -} - -BEGIN_MESSAGE_MAP(CInPlaceEdit, CEdit) - //{{AFX_MSG_MAP(CInPlaceEdit) - ON_WM_KILLFOCUS() - ON_WM_CHAR() - ON_WM_KEYDOWN() - ON_WM_KEYUP() - ON_WM_CREATE() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -//////////////////////////////////////////////////////////////////////////// -// CInPlaceEdit message handlers - -// If an arrow key (or associated) is pressed, then exit if -// a) The Ctrl key was down, or -// b) m_bExitOnArrows == TRUE -void CInPlaceEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) -{ - if ((nChar == VK_PRIOR || nChar == VK_NEXT || - nChar == VK_DOWN || nChar == VK_UP || - nChar == VK_RIGHT || nChar == VK_LEFT) && - (m_bExitOnArrows || GetKeyState(VK_CONTROL) < 0)) - { - m_nLastChar = nChar; - GetParent()->SetFocus(); - return; - } - - if (nChar == VK_ESCAPE) - { - SetWindowText(m_sInitText); // restore previous text - m_nLastChar = nChar; - GetParent()->SetFocus(); - return; - } - - CEdit::OnKeyDown(nChar, nRepCnt, nFlags); -} - -// Need to keep a lookout for Tabs, Esc and Returns. These send a -// "KeyUp" message, but no "KeyDown". That's why I didn't put their -// code in OnKeyDown. (I will never understand windows...) -void CInPlaceEdit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) -{ - if (nChar == VK_TAB || nChar == VK_RETURN || nChar == VK_ESCAPE) - { - m_nLastChar = nChar; - GetParent()->SetFocus(); // This will destroy this window - return; - } - - CEdit::OnKeyUp(nChar, nRepCnt, nFlags); -} - -// As soon as this edit loses focus, kill it. -void CInPlaceEdit::OnKillFocus(CWnd* pNewWnd) -{ - CEdit::OnKillFocus(pNewWnd); - EndEdit(); -} - -void CInPlaceEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) -{ - // Prevent beeping - if (nChar != VK_TAB && nChar != VK_RETURN && nChar != VK_ESCAPE) - { - CEdit::OnChar(nChar, nRepCnt, nFlags); - - // Resize edit control if needed - ResizeControl(); - } -} - -//////////////////////////////////////////////////////////////////////////// -// CInPlaceEdit overrides - -// Stoopid win95 accelerator key problem workaround - Matt Weagle. -BOOL CInPlaceEdit::PreTranslateMessage(MSG* pMsg) -{ - // Make sure that the keystrokes continue to the appropriate handlers - if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP) - { - ::TranslateMessage(pMsg); - ::DispatchMessage(pMsg); - return TRUE; - } - - // Catch the Alt key so we don't choke if focus is going to an owner drawn button - if (pMsg->message == WM_SYSCHAR) - return TRUE; - - return CWnd::PreTranslateMessage(pMsg); -} - -// Auto delete -void CInPlaceEdit::PostNcDestroy() -{ - CEdit::PostNcDestroy(); - - delete this; -} - -//////////////////////////////////////////////////////////////////////////// -// CInPlaceEdit implementation - -void CInPlaceEdit::EndEdit() -{ - CString str; - GetWindowText(str); - BOOL bModified = FALSE; - - float f; - if (sscanf(str, "%f", &f)) - { - if (*m_pHeight != f) - { - *m_pHeight = f; - bModified = TRUE; - } - } - - CWnd* pOwner = GetOwner(); - if (pOwner) - pOwner->SendMessage(WM_LC_EDIT_CLOSED, m_nLastChar, bModified); - - // Close this window (PostNcDestroy will delete this) - PostMessage(WM_CLOSE, 0, 0); -} - -void CInPlaceEdit::ResizeControl() -{ - // Get text extent - CString str; - GetWindowText(str); - str += "0"; - - CWindowDC dc(this); - CFont *pFontDC = dc.SelectObject(GetFont()); - CSize size = dc.GetTextExtent(str); - dc.SelectObject(pFontDC); - - size.cx += 5; // add some extra buffer - - // Get client rect - CRect rect, parentrect; - GetClientRect(&rect); - GetParent()->GetClientRect(&parentrect); - - // Transform rect to parent coordinates - ClientToScreen(&rect); - GetParent()->ScreenToClient(&rect); - - // Check whether control needs to be resized - // and whether there is space to grow - if (size.cx > rect.Width()) - { - if (size.cx + rect.left < parentrect.right) - rect.right = rect.left + size.cx; - else - rect.right = parentrect.right; - rect.bottom = rect.top + size.cy + 4; - MoveWindow(&rect); - } -} diff --git a/win/ipedit.h b/win/ipedit.h deleted file mode 100644 index a16ed446..00000000 --- a/win/ipedit.h +++ /dev/null @@ -1,64 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// InPlaceEdit.h : header file - -#if !defined(AFX_INPLACEEDIT_H__ECD42821_16DF_11D1_992F_895E185F9C72__INCLUDED_) -#define AFX_INPLACEEDIT_H__ECD42821_16DF_11D1_992F_895E185F9C72__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 - - -///////////////////////////////////////////////////////////////////////////// -// CInPlaceEdit window - -class CInPlaceEdit : public CEdit -{ -// Construction -public: - CInPlaceEdit(CWnd* pParent, CRect& rect, DWORD dwStyle, UINT nID, - float* pHeight, CString sInitText, UINT nFirstChar); - -// Attributes -public: - -// Operations -public: - void EndEdit(); - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CInPlaceEdit) - public: - virtual BOOL PreTranslateMessage(MSG* pMsg); - protected: - virtual void PostNcDestroy(); - //}}AFX_VIRTUAL - -// Implementation -public: - virtual ~CInPlaceEdit(); - -// Generated message map functions -protected: - void ResizeControl(); - //{{AFX_MSG(CInPlaceEdit) - afx_msg void OnKillFocus(CWnd* pNewWnd); - afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); - afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); - afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() - - float* m_pHeight; - CString m_sInitText; - UINT m_nLastChar; - BOOL m_bExitOnArrows; -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_INPLACEEDIT_H__ECD42821_16DF_11D1_992F_895E185F9C72__INCLUDED_) diff --git a/win/propertiesgridctrl.cpp b/win/propertiesgridctrl.cpp deleted file mode 100644 index ee2be198..00000000 --- a/win/propertiesgridctrl.cpp +++ /dev/null @@ -1,206 +0,0 @@ -#include "lc_global.h" -#include "lc_colors.h" -#include "propertiesgridctrl.h" -#include "clrpopup.h" -#include "globals.h" - -void CLeoCADMFCPropertyGridCtrl::SetColor(int ColorIndex) -{ - ASSERT_VALID(this); - ASSERT_VALID(m_pSel); - - CLeoCADMFCPropertyGridColorProperty* pColorProp = DYNAMIC_DOWNCAST(CLeoCADMFCPropertyGridColorProperty, m_pSel); - if (pColorProp == NULL) - { - ASSERT(FALSE); - return; - } - - BOOL bChanged = ColorIndex != pColorProp->GetColor(); - pColorProp->SetColor(ColorIndex, false); - - if (bChanged) - { - OnPropertyChanged(pColorProp); - } -} - -void CLeoCADMFCPropertyGridCtrl::UpdateColor(COLORREF color) -{ - ASSERT_VALID(this); - ASSERT_VALID(m_pSel); - - CLeoCADMFCPropertyGridColorProperty* pColorProp = DYNAMIC_DOWNCAST(CLeoCADMFCPropertyGridColorProperty, m_pSel); - if (pColorProp == NULL) - { - ASSERT(FALSE); - return; - } - - int ColorIdx; - for (ColorIdx = 0; ColorIdx < gNumUserColors; ColorIdx++) - if (color == RGB(gColorList[ColorIdx].Value[0] * 255, gColorList[ColorIdx].Value[1] * 255, gColorList[ColorIdx].Value[2] * 255)) - break; - - if (ColorIdx == gNumUserColors) - return; - - BOOL bChanged = ColorIdx != pColorProp->GetColor(); - pColorProp->SetColor(ColorIdx, false); - - if (bChanged) - { - OnPropertyChanged(pColorProp); - } -} - -void CLeoCADMFCPropertyGridCtrl::CloseColorPopup() -{ - ASSERT_VALID(this); - ASSERT_VALID(m_pSel); - - CLeoCADMFCPropertyGridColorProperty* pColorProp = DYNAMIC_DOWNCAST(CLeoCADMFCPropertyGridColorProperty, m_pSel); - if (pColorProp == NULL) - { - ASSERT(FALSE); - return; - } - - pColorProp->m_pPopup = NULL; - - pColorProp->m_bButtonIsDown = FALSE; - pColorProp->Redraw(); - - if (pColorProp->m_pWndInPlace != NULL) - { - pColorProp->m_pWndInPlace->SetFocus(); - } -} - -IMPLEMENT_DYNAMIC(CLeoCADMFCPropertyGridColorProperty, CMFCPropertyGridProperty) - -CLeoCADMFCPropertyGridColorProperty::CLeoCADMFCPropertyGridColorProperty(const CString& strName, LPCTSTR lpszDescr, DWORD_PTR dwData) - : CMFCPropertyGridProperty(strName, COleVariant(), lpszDescr, dwData) -{ - m_Color = 0; - m_ColorOrig = 0; - - m_varValue = (_variant_t)(UINT)m_Color; - m_varValueOrig = (_variant_t)(UINT)m_ColorOrig; - - m_dwFlags = 1; // AFX_PROP_HAS_LIST - m_pPopup = NULL; -} - -CLeoCADMFCPropertyGridColorProperty::~CLeoCADMFCPropertyGridColorProperty() -{ -} - -void CLeoCADMFCPropertyGridColorProperty::OnDrawValue(CDC* pDC, CRect rect) -{ - CRect rectColor = rect; - - rect.left += rect.Height(); - CMFCPropertyGridProperty::OnDrawValue(pDC, rect); - - rectColor.right = rectColor.left + rectColor.Height(); - rectColor.DeflateRect(1, 1); - rectColor.top++; - rectColor.left++; - - CBrush br(RGB(gColorList[m_Color].Value[0] * 255, gColorList[m_Color].Value[1] * 255, gColorList[m_Color].Value[2] * 255)); - pDC->FillRect(rectColor, &br); - pDC->Draw3dRect(rectColor, 0, 0); - - if (lcIsColorTranslucent(m_Color)) - { - rectColor.DeflateRect(1, 1); - rectColor.bottom -= 1; - - for (int x = rectColor.left; x < rectColor.right; x++) - { - for (int y = rectColor.top + x % 4; y < rectColor.bottom; y+=4) - pDC->SetPixel(x, y, RGB(255,255,255)); - - for (int y = rectColor.bottom - x % 4; y > rectColor.top; y-=4) - pDC->SetPixel(x, y, RGB(255,255,255)); - } - } -} - -void CLeoCADMFCPropertyGridColorProperty::OnClickButton(CPoint /*point*/) -{ - ASSERT_VALID(this); - ASSERT_VALID(m_pWndList); - - m_bButtonIsDown = TRUE; - Redraw(); - - CPoint pt(m_pWndList->GetListRect().left + m_pWndList->GetLeftColumnWidth() + 1, m_rectButton.bottom + 1); - m_pWndList->ClientToScreen(&pt); - - new CColorPopup(pt, m_Color, m_pWndList, true); -} - -BOOL CLeoCADMFCPropertyGridColorProperty::OnEdit(LPPOINT /*lptClick*/) -{ - m_pWndInPlace = NULL; - - CRect rectEdit; - CRect rectSpin; - - rectEdit.SetRectEmpty(); - rectSpin.SetRectEmpty(); - - CMFCMaskedEdit* pWndEdit = new CMFCMaskedEdit; - - pWndEdit->Create(WS_CHILD, rectEdit, m_pWndList, AFX_PROPLIST_ID_INPLACE); - m_pWndInPlace = pWndEdit; - - m_pWndInPlace->SetWindowText(FormatProperty()); - - m_pWndInPlace->SetFocus(); - - m_bInPlaceEdit = TRUE; - - return TRUE; -} - -void CLeoCADMFCPropertyGridColorProperty::ResetOriginalValue() -{ - CMFCPropertyGridProperty::ResetOriginalValue(); - m_Color = m_ColorOrig; -} - -CString CLeoCADMFCPropertyGridColorProperty::FormatProperty() -{ - ASSERT_VALID(this); - - return gColorList[m_Color].Name; -} - -void CLeoCADMFCPropertyGridColorProperty::SetColor(int color, bool original) -{ - ASSERT_VALID(this); - - if (m_Color == color) - return; - - m_Color = color; - m_varValue = (_variant_t)(UINT)m_Color; - - if (original) - { - m_ColorOrig = color; - m_varValueOrig = (_variant_t)(UINT)m_ColorOrig; - } - - if (::IsWindow(m_pWndList->GetSafeHwnd())) - { - CRect rect = m_Rect; - rect.DeflateRect(0, 1); - - m_pWndList->InvalidateRect(rect); - m_pWndList->UpdateWindow(); - } -} diff --git a/win/propertiesgridctrl.h b/win/propertiesgridctrl.h deleted file mode 100644 index 127319d6..00000000 --- a/win/propertiesgridctrl.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef _PROPERTIESGRIDCTRL_H_ -#define _PROPERTIESGRIDCTRL_H_ - -class CLeoCADMFCPropertyGridCtrl : public CMFCPropertyGridCtrl -{ -public: - virtual void CloseColorPopup(); - virtual void UpdateColor(COLORREF color); - void SetColor(int ColorIndex); -}; - -class CLeoCADMFCPropertyGridColorProperty : public CMFCPropertyGridProperty -{ - friend class CLeoCADMFCPropertyGridCtrl; - - DECLARE_DYNAMIC(CLeoCADMFCPropertyGridColorProperty) - -// Construction -public: - CLeoCADMFCPropertyGridColorProperty(const CString& strName, LPCTSTR lpszDescr = NULL, DWORD_PTR dwData = 0); - virtual ~CLeoCADMFCPropertyGridColorProperty(); - -// Overrides -public: - virtual void OnDrawValue(CDC* pDC, CRect rect); - virtual void OnClickButton(CPoint point); - virtual BOOL OnEdit(LPPOINT lptClick); - virtual CString FormatProperty(); - -protected: - virtual BOOL OnKillFocus(CWnd* pNewWnd) { return pNewWnd->GetSafeHwnd() != m_pPopup->GetSafeHwnd(); } - virtual BOOL OnEditKillFocus() { return m_pPopup == NULL; } - virtual BOOL IsValueChanged() const { return m_Color != m_ColorOrig; } - - virtual void ResetOriginalValue(); - -// Attributes -public: - int GetColor() const { return m_Color; } - void SetColor(int color, bool original); - -// Attributes -protected: - int m_Color; - int m_ColorOrig; - - CMFCColorPopupMenu* m_pPopup; - CArray m_Colors; -}; - -#endif // _PROPERTIESGRIDCTRL_H_ diff --git a/win/propertiespane.cpp b/win/propertiespane.cpp deleted file mode 100644 index dbd10f66..00000000 --- a/win/propertiespane.cpp +++ /dev/null @@ -1,458 +0,0 @@ -#include "lc_global.h" -#include "propertiespane.h" - -#include "project.h" -#include "piece.h" -#include "camera.h" -#include "light.h" -#include "lc_application.h" - -BEGIN_MESSAGE_MAP(CPropertiesPane, CDockablePane) - ON_WM_CREATE() - ON_WM_SIZE() - ON_REGISTERED_MESSAGE(AFX_WM_PROPERTY_CHANGED, OnPropertyChanged) -END_MESSAGE_MAP() - -inline void UpdateProperty(CMFCPropertyGridProperty* Property, float Value) -{ - const COleVariant& Var = Property->GetValue(); - - if (Var.vt != VT_EMPTY && Var.vt != VT_R4) - { - ASSERT(FALSE); - return; - } - - if ((float)Var.fltVal != Value) - Property->SetValue((_variant_t)Value); -} - -inline void UpdateProperty(CMFCPropertyGridProperty* Property, lcuint32 Value) -{ - const COleVariant& Var = Property->GetValue(); - - if (Var.vt != VT_EMPTY && Var.vt != VT_UINT) - { - ASSERT(FALSE); - return; - } - - if (Var.ulVal != Value) - Property->SetValue((_variant_t)Value); -} - -inline void UpdateProperty(CMFCPropertyGridProperty* Property, bool Value) -{ - const COleVariant& Var = Property->GetValue(); - - if (Var.vt != VT_EMPTY && Var.vt != VT_BOOL) - { - ASSERT(FALSE); - return; - } - - if (Var.boolVal != (VARIANT_BOOL)Value) - Property->SetValue((_variant_t)Value); -} - -CPropertiesPane::CPropertiesPane() -{ - mObject = NULL; -} - -CPropertiesPane::~CPropertiesPane() -{ -} - -void CPropertiesPane::AdjustLayout() -{ - if (GetSafeHwnd() == NULL) - return; - CRect rectClient; - GetClientRect(rectClient); - m_wndPropList.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), rectClient.Height(), SWP_NOACTIVATE | SWP_NOZORDER); -} - -int CPropertiesPane::OnCreate(LPCREATESTRUCT lpCreateStruct) -{ - if (CDockablePane::OnCreate(lpCreateStruct) == -1) - return -1; - - CRect rectDummy; - rectDummy.SetRectEmpty(); - - if (!m_wndPropList.Create(WS_VISIBLE | WS_CHILD, rectDummy, this, 2)) - { - TRACE0("Failed to create Properties Grid \n"); - return -1; // fail to create - } - - InitPropList(); - - AdjustLayout(); - return 0; -} - -void CPropertiesPane::OnSize(UINT nType, int cx, int cy) -{ - CDockablePane::OnSize(nType, cx, cy); - AdjustLayout(); -} - -void CPropertiesPane::InitPropList() -{ - SetPropListFont(); - - m_wndPropList.EnableHeaderCtrl(FALSE); - m_wndPropList.EnableDescriptionArea(); - m_wndPropList.SetVSDotNetLook(); - m_wndPropList.MarkModifiedProperties(); - - SetEmpty(true); -} - -void CPropertiesPane::Update(Object* Focus) -{ - if (!Focus) - SetEmpty(); - else - { - switch (Focus->GetType()) - { - case LC_OBJECT_PIECE: - SetPiece(Focus); - break; - - case LC_OBJECT_CAMERA: - SetCamera(Focus); - break; - - case LC_OBJECT_CAMERA_TARGET: - SetCamera(((CameraTarget*)Focus)->GetParent()); - break; - - case LC_OBJECT_LIGHT: - SetLight(Focus); - break; - - case LC_OBJECT_LIGHT_TARGET: - SetLight(((LightTarget*)Focus)->GetParent()); - break; - } - } -} - -void CPropertiesPane::SetEmpty(bool Force) -{ - if (!mObject && !Force) - return; - - mObject = NULL; - m_wndPropList.RemoveAll(); - - CMFCPropertyGridProperty* Empty = new CMFCPropertyGridProperty(_T("Nothing selected")); - - m_wndPropList.AddProperty(Empty); -} - -void CPropertiesPane::SetPiece(Object* Focus) -{ - if (!mObject || mObject->GetType() != LC_OBJECT_PIECE) - { - mObject = NULL; - m_wndPropList.RemoveAll(); - - CMFCPropertyGridProperty* Position = new CMFCPropertyGridProperty(_T("Position")); - - CMFCPropertyGridProperty* PosX = new CMFCPropertyGridProperty(_T("X"), (_variant_t)0.0f, _T("The object's X coordinate")); - Position->AddSubItem(PosX); - - CMFCPropertyGridProperty* PosY = new CMFCPropertyGridProperty(_T("Y"), (_variant_t)0.0f, _T("The object's Y coordinate")); - Position->AddSubItem(PosY); - - CMFCPropertyGridProperty* PosZ = new CMFCPropertyGridProperty(_T("Z"), (_variant_t)0.0f, _T("The object's Z coordinate")); - Position->AddSubItem(PosZ); - - m_wndPropList.AddProperty(Position); - - CMFCPropertyGridProperty* Rotation = new CMFCPropertyGridProperty(_T("Rotation")); - - CMFCPropertyGridProperty* RotX = new CMFCPropertyGridProperty(_T("X"), (_variant_t)0.0f, _T("The object's rotation around the X axis")); - Rotation->AddSubItem(RotX); - - CMFCPropertyGridProperty* RotY = new CMFCPropertyGridProperty(_T("Y"), (_variant_t)0.0f, _T("The object's rotation around the Y axis")); - Rotation->AddSubItem(RotY); - - CMFCPropertyGridProperty* RotZ = new CMFCPropertyGridProperty(_T("Z"), (_variant_t)0.0f, _T("The object's rotation around the Z axis")); - Rotation->AddSubItem(RotZ); - - m_wndPropList.AddProperty(Rotation); - - CMFCPropertyGridProperty* Appearence = new CMFCPropertyGridProperty(_T("Appearance")); - - CMFCPropertyGridProperty* Show = new CMFCPropertyGridProperty(_T("Show"), (_variant_t)(lcuint32)0, _T("The time when this object becomes visible")); - Appearence->AddSubItem(Show); - - CMFCPropertyGridProperty* Hide = new CMFCPropertyGridProperty(_T("Hide"), (_variant_t)(lcuint32)0, _T("The time when this object is hidden")); - Appearence->AddSubItem(Hide); - - CLeoCADMFCPropertyGridColorProperty* Color = new CLeoCADMFCPropertyGridColorProperty(_T("Color"), _T("The object's color")); - Appearence->AddSubItem(Color); - - m_wndPropList.AddProperty(Appearence); - } - - Piece* pPiece = (Piece*)Focus; - lcVector3 Pos = pPiece->mPosition; - lcVector3 Angles = lcMatrix44ToEulerAngles(pPiece->mModelWorld) * LC_RTOD; - - lcGetActiveProject()->ConvertToUserUnits(Pos); - - CMFCPropertyGridProperty* Position = m_wndPropList.GetProperty(0); - UpdateProperty(Position->GetSubItem(0), Pos[0]); - UpdateProperty(Position->GetSubItem(1), Pos[1]); - UpdateProperty(Position->GetSubItem(2), Pos[2]); - - CMFCPropertyGridProperty* Rotation = m_wndPropList.GetProperty(1); - UpdateProperty(Rotation->GetSubItem(0), Angles[0]); - UpdateProperty(Rotation->GetSubItem(1), Angles[1]); - UpdateProperty(Rotation->GetSubItem(2), Angles[2]); - - lcuint32 From, To; - if (lcGetActiveProject()->IsAnimation()) - { - From = pPiece->GetFrameShow(); - To = pPiece->GetFrameHide(); - } - else - { - From = pPiece->GetStepShow(); - To = pPiece->GetStepHide(); - } - - CMFCPropertyGridProperty* Appearence = m_wndPropList.GetProperty(2); - UpdateProperty(Appearence->GetSubItem(0), From); - UpdateProperty(Appearence->GetSubItem(1), To); - ((CLeoCADMFCPropertyGridColorProperty*)Appearence->GetSubItem(2))->SetColor(pPiece->mColorIndex, true); - - mObject = Focus; -} - -void CPropertiesPane::ModifyPiece() -{ - LC_PIECE_MODIFY Modify; - - Modify.piece = (Piece*)mObject; - - CMFCPropertyGridProperty* Position = m_wndPropList.GetProperty(0); - Modify.Position = lcVector3(Position->GetSubItem(0)->GetValue().fltVal, Position->GetSubItem(1)->GetValue().fltVal, Position->GetSubItem(2)->GetValue().fltVal); - lcGetActiveProject()->ConvertFromUserUnits(Modify.Position); - - CMFCPropertyGridProperty* Rotation = m_wndPropList.GetProperty(1); - Modify.Rotation = lcVector3(Rotation->GetSubItem(0)->GetValue().fltVal, Rotation->GetSubItem(1)->GetValue().fltVal, Rotation->GetSubItem(2)->GetValue().fltVal); - - CMFCPropertyGridProperty* Appearence = m_wndPropList.GetProperty(2); - Modify.from = Appearence->GetSubItem(0)->GetValue().ulVal; - Modify.to = Appearence->GetSubItem(1)->GetValue().ulVal; - Modify.hidden = false; - Modify.color = ((CLeoCADMFCPropertyGridColorProperty*)Appearence->GetSubItem(2))->GetColor(); - strcpy(Modify.name, Modify.piece->GetName()); - - lcGetActiveProject()->HandleNotify(LC_PIECE_MODIFIED, (unsigned long)&Modify); -} - -void CPropertiesPane::SetCamera(Object* Focus) -{ - if (!mObject || mObject->GetType() != LC_OBJECT_CAMERA) - { - mObject = NULL; - m_wndPropList.RemoveAll(); - - CMFCPropertyGridProperty* Position = new CMFCPropertyGridProperty(_T("Position")); - - CMFCPropertyGridProperty* PosX = new CMFCPropertyGridProperty(_T("X"), (_variant_t)0.0f, _T("The camera's X coordinate")); - Position->AddSubItem(PosX); - - CMFCPropertyGridProperty* PosY = new CMFCPropertyGridProperty(_T("Y"), (_variant_t)0.0f, _T("The camera's Y coordinate")); - Position->AddSubItem(PosY); - - CMFCPropertyGridProperty* PosZ = new CMFCPropertyGridProperty(_T("Z"), (_variant_t)0.0f, _T("The camera's Z coordinate")); - Position->AddSubItem(PosZ); - - m_wndPropList.AddProperty(Position); - - CMFCPropertyGridProperty* Target = new CMFCPropertyGridProperty(_T("Target")); - - CMFCPropertyGridProperty* TargetX = new CMFCPropertyGridProperty(_T("X"), (_variant_t)0.0f, _T("The camera target's X coordinate")); - Target->AddSubItem(TargetX); - - CMFCPropertyGridProperty* TargetY = new CMFCPropertyGridProperty(_T("Y"), (_variant_t)0.0f, _T("The camera target's Y coordinate")); - Target->AddSubItem(TargetY); - - CMFCPropertyGridProperty* TargetZ = new CMFCPropertyGridProperty(_T("Z"), (_variant_t)0.0f, _T("The camera target's Z coordinate")); - Target->AddSubItem(TargetZ); - - m_wndPropList.AddProperty(Target); - - CMFCPropertyGridProperty* Up = new CMFCPropertyGridProperty(_T("Up")); - - CMFCPropertyGridProperty* UpX = new CMFCPropertyGridProperty(_T("X"), (_variant_t)0.0f, _T("The camera's up vector X")); - Up->AddSubItem(UpX); - - CMFCPropertyGridProperty* UpY = new CMFCPropertyGridProperty(_T("Y"), (_variant_t)0.0f, _T("The camera's up vector Y")); - Up->AddSubItem(UpY); - - CMFCPropertyGridProperty* UpZ = new CMFCPropertyGridProperty(_T("Z"), (_variant_t)0.0f, _T("The camera's up vector Z")); - Up->AddSubItem(UpZ); - - m_wndPropList.AddProperty(Up); - - CMFCPropertyGridProperty* Settings = new CMFCPropertyGridProperty(_T("Settings")); - - CMFCPropertyGridProperty* FOV = new CMFCPropertyGridProperty(_T("FOV"), (_variant_t)0.0f, _T("The camera's field of view")); - Settings->AddSubItem(FOV); - - CMFCPropertyGridProperty* Near = new CMFCPropertyGridProperty(_T("Near"), (_variant_t)0.0f, _T("The camera's near plane")); - Settings->AddSubItem(Near); - - CMFCPropertyGridProperty* Far = new CMFCPropertyGridProperty(_T("Far"), (_variant_t)0.0f, _T("The camera's far plane")); - Settings->AddSubItem(Far); - - CMFCPropertyGridProperty* Visible = new CMFCPropertyGridProperty(_T("Visible"), (_variant_t)true, _T("Draw the camera")); - Settings->AddSubItem(Visible); - - m_wndPropList.AddProperty(Settings); - } - - Camera* pCamera = (Camera*)Focus; - - lcVector3 Pos = pCamera->mPosition; - lcGetActiveProject()->ConvertToUserUnits(Pos); - - CMFCPropertyGridProperty* Position = m_wndPropList.GetProperty(0); - UpdateProperty(Position->GetSubItem(0), Pos[0]); - UpdateProperty(Position->GetSubItem(1), Pos[1]); - UpdateProperty(Position->GetSubItem(2), Pos[2]); - - lcVector3 Target = pCamera->mTargetPosition; - lcGetActiveProject()->ConvertToUserUnits(Target); - - CMFCPropertyGridProperty* TargetProp = m_wndPropList.GetProperty(1); - UpdateProperty(TargetProp->GetSubItem(0), Target[0]); - UpdateProperty(TargetProp->GetSubItem(1), Target[1]); - UpdateProperty(TargetProp->GetSubItem(2), Target[2]); - - lcVector3 Up = pCamera->mUpVector; - - CMFCPropertyGridProperty* UpProp = m_wndPropList.GetProperty(2); - UpdateProperty(UpProp->GetSubItem(0), Up[0]); - UpdateProperty(UpProp->GetSubItem(1), Up[1]); - UpdateProperty(UpProp->GetSubItem(2), Up[2]); - - CMFCPropertyGridProperty* SettingsProp = m_wndPropList.GetProperty(3); - UpdateProperty(SettingsProp->GetSubItem(0), pCamera->m_fovy); - UpdateProperty(SettingsProp->GetSubItem(1), pCamera->m_zNear); - UpdateProperty(SettingsProp->GetSubItem(2), pCamera->m_zFar); - UpdateProperty(SettingsProp->GetSubItem(3), pCamera->IsVisible()); - - mObject = Focus; -} - -void CPropertiesPane::ModifyCamera() -{ - LC_CAMERA_MODIFY Modify; - - Modify.camera = (Camera*)mObject; - - CMFCPropertyGridProperty* PositionProp = m_wndPropList.GetProperty(0); - Modify.Eye = lcVector3(PositionProp->GetSubItem(0)->GetValue().fltVal, PositionProp->GetSubItem(1)->GetValue().fltVal, PositionProp->GetSubItem(2)->GetValue().fltVal); - lcGetActiveProject()->ConvertFromUserUnits(Modify.Eye); - - CMFCPropertyGridProperty* TargetProp = m_wndPropList.GetProperty(1); - Modify.Target = lcVector3(TargetProp->GetSubItem(0)->GetValue().fltVal, TargetProp->GetSubItem(1)->GetValue().fltVal, TargetProp->GetSubItem(2)->GetValue().fltVal); - lcGetActiveProject()->ConvertFromUserUnits(Modify.Target); - - CMFCPropertyGridProperty* UpProp = m_wndPropList.GetProperty(2); - Modify.Up = lcVector3(UpProp->GetSubItem(0)->GetValue().fltVal, UpProp->GetSubItem(1)->GetValue().fltVal, UpProp->GetSubItem(2)->GetValue().fltVal); - - CMFCPropertyGridProperty* SettingsProp = m_wndPropList.GetProperty(3); - Modify.fovy = SettingsProp->GetSubItem(0)->GetValue().fltVal; - Modify.znear = SettingsProp->GetSubItem(1)->GetValue().fltVal; - Modify.zfar = SettingsProp->GetSubItem(2)->GetValue().fltVal; - Modify.hidden = false; - - lcGetActiveProject()->HandleNotify(LC_CAMERA_MODIFIED, (unsigned long)&Modify); -} - -void CPropertiesPane::SetLight(Object* Focus) -{ - if (!mObject || mObject->GetType() != LC_OBJECT_LIGHT) - { - m_wndPropList.RemoveAll(); - - CMFCPropertyGridProperty* Position = new CMFCPropertyGridProperty(_T("Position")); - - CMFCPropertyGridProperty* PosX = new CMFCPropertyGridProperty(_T("X"), (_variant_t)0.0f, _T("The object's X coordinate")); - Position->AddSubItem(PosX); - - CMFCPropertyGridProperty* PosY = new CMFCPropertyGridProperty(_T("Y"), (_variant_t)0.0f, _T("The object's Y coordinate")); - Position->AddSubItem(PosY); - - CMFCPropertyGridProperty* PosZ = new CMFCPropertyGridProperty(_T("Z"), (_variant_t)0.0f, _T("The object's Z coordinate")); - Position->AddSubItem(PosZ); - - m_wndPropList.AddProperty(Position); - } -} - -void CPropertiesPane::ModifyLight() -{ -} - -void CPropertiesPane::SetPropListFont() -{ - ::DeleteObject(m_fntPropList.Detach()); - - LOGFONT lf; - afxGlobalData.fontRegular.GetLogFont(&lf); - - NONCLIENTMETRICS info; - info.cbSize = sizeof(info); - - afxGlobalData.GetNonClientMetrics(info); - - lf.lfHeight = info.lfMenuFont.lfHeight; - lf.lfWeight = info.lfMenuFont.lfWeight; - lf.lfItalic = info.lfMenuFont.lfItalic; - - m_fntPropList.CreateFontIndirect(&lf); - - m_wndPropList.SetFont(&m_fntPropList); -} - -LRESULT CPropertiesPane::OnPropertyChanged(WPARAM wParam, LPARAM lParam ) -{ - CMFCPropertyGridProperty* Property = (CMFCPropertyGridProperty*)lParam; - - if (!mObject) - return 0; - - switch (mObject->GetType()) - { - case LC_OBJECT_PIECE: - ModifyPiece(); - break; - - case LC_OBJECT_CAMERA: - case LC_OBJECT_CAMERA_TARGET: - ModifyCamera(); - break; - - case LC_OBJECT_LIGHT: - case LC_OBJECT_LIGHT_TARGET: - ModifyLight(); - break; - } - - return 0; -} diff --git a/win/propertiespane.h b/win/propertiespane.h deleted file mode 100644 index 1f51aa2d..00000000 --- a/win/propertiespane.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "propertiesgridctrl.h" - -class Object; - -class CPropertiesPane : public CDockablePane -{ -public: - CPropertiesPane(); - virtual ~CPropertiesPane(); - - void Update(Object* Focus); - -protected: - CFont m_fntPropList; - CLeoCADMFCPropertyGridCtrl m_wndPropList; - - void AdjustLayout(); - - void InitPropList(); - void SetPropListFont(); - - void SetEmpty(bool Force = false); - void SetPiece(Object* Focus); - void SetCamera(Object* Focus); - void SetLight(Object* Focus); - - void ModifyPiece(); - void ModifyCamera(); - void ModifyLight(); - - Object* mObject; - -protected: - afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg LRESULT OnPropertyChanged(WPARAM wParam, LPARAM lParam); - - DECLARE_MESSAGE_MAP() -}; - - diff --git a/win/resource.hm b/win/resource.hm deleted file mode 100644 index 49f44a56..00000000 --- a/win/resource.hm +++ /dev/null @@ -1,7 +0,0 @@ -// Microsoft Developer Studio generated Help ID include file. -// Used by LeoCAD.rc -// -#define HIDC_POVDLG_LGEO 0x80c6047c // IDD_EXPORTPOV -#define HIDC_POVDLG_OUTPOV 0x80c60481 // IDD_EXPORTPOV -#define HIDC_POVDLG_POVRAY 0x80c6047d // IDD_EXPORTPOV -#define HIDC_POVDLG_RENDER 0x80c6047e // IDD_EXPORTPOV diff --git a/win/terrctrl.cpp b/win/terrctrl.cpp deleted file mode 100644 index c9c4dec0..00000000 --- a/win/terrctrl.cpp +++ /dev/null @@ -1,1850 +0,0 @@ -#include "lc_global.h" -#include "LeoCAD.h" -#include "TerrCtrl.h" -#include "IPEdit.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -#define IDC_INPLACE_EDIT 8 // ID of inplace edit control -#define GRIDSIZE 28 - -#define ControlPoint(row, col) m_pControl[row-1][(col-1)*3+2] - -#define GetFixedRowHeight() GRIDSIZE -#define GetFixedColumnWidth() GRIDSIZE -#define m_nFixedRows 1 -#define m_nFixedCols 1 -#define GetRowHeight(a) GRIDSIZE -#define GetColumnWidth(a) GRIDSIZE -#define GetVirtualWidth() m_nCols*GRIDSIZE -#define GetVirtualHeight() m_nRows*GRIDSIZE -#define m_nMargin 1 -#define GetFixedRowCount() 1 -#define GetFixedColumnCount() 1 -#define GetColumnCount() m_nCols -#define GetRowCount() m_nRows - -///////////////////////////////////////////////////////////////////////////// -// CTerrainCtrl - -CTerrainCtrl::CTerrainCtrl() -{ - RegisterWindowClass(); - - m_nRows = 0; - m_nCols = 0; - m_nVScrollMax = 0; // Scroll position - m_nHScrollMax = 0; - m_MouseMode = MOUSE_NOTHING; - m_pControl = NULL; -/* - m_nMargin = 0; // cell padding - m_nRowsPerWheelNotch = GetMouseScrollLines(); // Get the number of lines - // per mouse wheel notch to scroll - - m_bHandleTabKey = TRUE; - m_bTitleTips = TRUE; // show cell title tips - - m_nTimerID = 0; // For drag-selection - m_nTimerInterval = 25; // (in milliseconds) - - m_crShadow = ::GetSysColor(COLOR_3DSHADOW); - m_crGridColour = RGB(0,0,0); - SetTextColor(m_crWindowText); - SetBkColor(m_crShadow); - - SetTextBkColor(RGB(0xFF, 0xFF, 0xE0)); -*/ - // Set the colours - m_crFixedBkColour = GetSysColor(COLOR_3DFACE); - m_crFixedTextColour = GetSysColor(COLOR_WINDOWTEXT); - m_crTextBkColour = GetSysColor(COLOR_WINDOW); - - // Initially use the system message font for the GridCtrl font - NONCLIENTMETRICS ncm; - LOGFONT lf; - ncm.cbSize = sizeof(NONCLIENTMETRICS); - VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)); - memcpy(&lf, &(ncm.lfMessageFont), sizeof(LOGFONT)); -// lf.lfWeight = SELECTED_CELL_FONT_WEIGHT; - m_Font.CreateFontIndirect(&lf); - - // Set up the initial grid size - SetRowCount(5); - SetColumnCount(5); - -/* - // set initial selection range (ie. none) - m_SelectedCellMap.RemoveAll(); - m_PrevSelectedCellMap.RemoveAll(); -*/ -} - -CTerrainCtrl::~CTerrainCtrl() -{ -/* - DeleteAllItems(); -*/ - DestroyWindow(); - m_Font.DeleteObject(); -} - -// Register the window class if it has not already been registered. -BOOL CTerrainCtrl::RegisterWindowClass() -{ - WNDCLASS wndcls; - HINSTANCE hInst = AfxGetResourceHandle(); - - if (!(::GetClassInfo(hInst, TERRAINCTRL_CLASSNAME, &wndcls))) - { - // otherwise we need to register a new class - wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; - wndcls.lpfnWndProc = ::DefWindowProc; - wndcls.cbClsExtra = wndcls.cbWndExtra = 0; - wndcls.hInstance = hInst; - wndcls.hIcon = NULL; - wndcls.hCursor = LoadCursor(NULL,IDC_ARROW); - wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1); - wndcls.lpszMenuName = NULL; - wndcls.lpszClassName = TERRAINCTRL_CLASSNAME; - - if (!AfxRegisterClass(&wndcls)) { - AfxThrowResourceException(); - return FALSE; - } - } - - return TRUE; -} - -BEGIN_MESSAGE_MAP(CTerrainCtrl, CWnd) - //{{AFX_MSG_MAP(CTerrainCtrl) - ON_WM_PAINT() - ON_WM_ERASEBKGND() - ON_WM_SIZE() - ON_WM_GETDLGCODE() - ON_WM_HSCROLL() - ON_WM_VSCROLL() - ON_WM_LBUTTONDOWN() - ON_WM_LBUTTONUP() - ON_WM_MOUSEMOVE() - ON_WM_KEYDOWN() - ON_WM_CHAR() - //}}AFX_MSG_MAP - ON_MESSAGE(WM_GETFONT, OnGetFont) - ON_MESSAGE(WM_LC_EDIT_CLOSED, OnEditClosed) -END_MESSAGE_MAP() - - -///////////////////////////////////////////////////////////////////////////// -// CTerrainCtrl message handlers - -BOOL CTerrainCtrl::Create(const RECT& rect, CWnd* pParentWnd, UINT nID, DWORD dwStyle) -{ - ASSERT(pParentWnd->GetSafeHwnd()); - - if (!CWnd::Create(TERRAINCTRL_CLASSNAME, NULL, dwStyle, rect, pParentWnd, nID)) - return FALSE; - - // Create titletips -#ifdef GRIDCONTROL_USE_TITLETIPS - if (m_bTitleTips) - m_TitleTip.Create(this); -#endif - - ResetScrollBars(); - return TRUE; -} - -void CTerrainCtrl::PreSubclassWindow() -{ - CWnd::PreSubclassWindow(); -/* - HFONT hFont = ::CreateFontIndirect(&m_Logfont); - OnSetFont((LPARAM)hFont, 0); - DeleteObject(hFont); -*/ - ResetScrollBars(); -} - -BOOL CTerrainCtrl::SubclassWindow(HWND hWnd) -{ - if (!CWnd::SubclassWindow(hWnd)) - return FALSE; - -#ifdef GRIDCONTROL_USE_TITLETIPS - if (m_bTitleTips && !IsWindow(m_TitleTip.m_hWnd)) - m_TitleTip.Create(this); -#endif - - return TRUE; -} - -LRESULT CTerrainCtrl::OnGetFont(WPARAM /*wParam*/, LPARAM /*lParam*/) -{ - return (LRESULT) (HFONT) m_Font; -} - -void CTerrainCtrl::OnPaint() -{ - CPaintDC dc(this); // device context for painting - - CDC MemDC; - CRect rect; - CBitmap bitmap, *pOldBitmap; - dc.GetClipBox(&rect); - MemDC.CreateCompatibleDC(&dc); - bitmap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height()); - pOldBitmap = MemDC.SelectObject(&bitmap); - MemDC.SetWindowOrg(rect.left, rect.top); - OnDraw(&MemDC); - dc.BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &MemDC, rect.left, rect.top, SRCCOPY); - MemDC.SelectObject(pOldBitmap); -} - -BOOL CTerrainCtrl::OnEraseBkgnd(CDC* pDC) -{ - return TRUE; // Don't erase the background. -} - -// Custom background erasure. This gets called from within the OnDraw function, -// since we will (most likely) be using a memory DC to stop flicker. If we just -// erase the background normally through OnEraseBkgnd, and didn't fill the memDC's -// selected bitmap with colour, then all sorts of vis problems would occur -void CTerrainCtrl::EraseBkgnd(CDC* pDC) -{ - - CRect VisRect, ClipRect, rect; - CBrush FixedBack(m_crFixedBkColour), TextBack(m_crTextBkColour); - - if (pDC->GetClipBox(ClipRect) == ERROR) - return; - - int nFixedColumnWidth = GetFixedColumnWidth(); - int nFixedRowHeight = GetFixedRowHeight(); - GetClientRect(VisRect); - VisRect.top = nFixedRowHeight; - VisRect.left = nFixedColumnWidth; - - // Draw Fixed columns background - if (ClipRect.left < nFixedColumnWidth && ClipRect.top < VisRect.bottom) - pDC->FillRect(CRect(ClipRect.left, ClipRect.top, nFixedColumnWidth, VisRect.bottom), - &FixedBack); - - // Draw Fixed rows background - if (ClipRect.top < nFixedRowHeight && - ClipRect.right > nFixedColumnWidth && ClipRect.left < VisRect.right) - pDC->FillRect(CRect(nFixedColumnWidth-1, ClipRect.top, VisRect.right, nFixedRowHeight), - &FixedBack); - - // Draw non-fixed cell background - if (rect.IntersectRect(VisRect, ClipRect)) - { - CRect CellRect(max(nFixedColumnWidth, rect.left), max(nFixedRowHeight, rect.top), - rect.right, rect.bottom); - pDC->FillRect(CellRect, &TextBack); - } -} - -void CTerrainCtrl::OnSize(UINT nType, int cx, int cy) -{ - if (::IsWindow(GetSafeHwnd()) && GetFocus()->GetSafeHwnd() != GetSafeHwnd()) - SetFocus(); // Auto-destroy any InPlaceEdit's - - CWnd::OnSize(nType, cx, cy); - ResetScrollBars(); -} - -UINT CTerrainCtrl::OnGetDlgCode() -{ - UINT nCode = DLGC_WANTARROWS | DLGC_WANTCHARS; -/* - if (m_bHandleTabKey && !IsCTRLpressed()) - nCode |= DLGC_WANTTAB; -*/ - return nCode; -} - -// wParam = key pressed, lParam = modified -LRESULT CTerrainCtrl::OnEditClosed(WPARAM wParam, LPARAM lParam) -{ - // In case OnEndInPlaceEdit called as window is being destroyed - if (!IsWindow(GetSafeHwnd())) - return TRUE; - - // Only set as modified if it actually was, and ESC was not hit. - if ((wParam != VK_ESCAPE) && (lParam == TRUE)) - { - CWnd* pParent = GetOwner(); - if (pParent) - pParent->SendMessage(WM_LC_EDIT_CLOSED); -// SetModified(TRUE); - } - - switch (wParam) - { - case VK_DOWN: - case VK_UP: - case VK_RIGHT: - case VK_LEFT: - case VK_NEXT: - case VK_PRIOR: - case VK_HOME: - case VK_END: - OnKeyDown(wParam, 0, 0); - EditCell(m_idCurrentCell.row, m_idCurrentCell.col, wParam); - } - - return TRUE; -} - -// Handle horz scrollbar notifications -void CTerrainCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) -{ - if (GetFocus()->GetSafeHwnd() != GetSafeHwnd()) - SetFocus(); // Auto-destroy any InPlaceEdit's - -#ifdef GRIDCONTROL_USE_TITLETIPS - m_TitleTip.Hide(); // hide any titletips -#endif - - int scrollPos = GetScrollPos32(SB_HORZ); - - CELLID idTopLeft = GetTopleftNonFixedCell(); - - CRect rect; - GetClientRect(rect); - - switch (nSBCode) - { - case SB_LINERIGHT: - if (scrollPos < m_nHScrollMax) - { - int xScroll = GetColumnWidth(nTopLeftCol); - SetScrollPos32(SB_HORZ, scrollPos + xScroll); - if (GetScrollPos32(SB_HORZ) == scrollPos) - break; // didn't work - - rect.left = GetFixedColumnWidth() + xScroll; - ScrollWindow(-xScroll, 0, rect); - rect.left = rect.right - xScroll; - InvalidateRect(rect); - } break; - - case SB_LINELEFT: - if (scrollPos > 0 && idTopLeft.col > GetFixedColumnCount()) - { - int xScroll = GetColumnWidth(nTopLeftCol-1); - SetScrollPos32(SB_HORZ, max(0,scrollPos - xScroll)); - rect.left = GetFixedColumnWidth(); - ScrollWindow(xScroll, 0, rect); - rect.right = rect.left + xScroll; - InvalidateRect(rect); - } break; - - case SB_PAGERIGHT: - if (scrollPos < m_nHScrollMax) - { - rect.left = GetFixedColumnWidth(); - int offset = rect.Width(); - int pos = min(m_nHScrollMax, scrollPos + offset); - SetScrollPos32(SB_HORZ, pos); - rect.left = GetFixedColumnWidth(); - InvalidateRect(rect); - } break; - - case SB_PAGELEFT: - if (scrollPos > 0) - { - rect.left = GetFixedColumnWidth(); - int offset = -rect.Width(); - int pos = max(0, scrollPos + offset); - SetScrollPos32(SB_HORZ, pos); - rect.left = GetFixedColumnWidth(); - InvalidateRect(rect); - } break; - - case SB_THUMBPOSITION: - case SB_THUMBTRACK: - { - SetScrollPos32(SB_HORZ, GetScrollPos32(SB_HORZ, TRUE)); - rect.left = GetFixedColumnWidth(); - InvalidateRect(rect); - } break; - - case SB_LEFT: - if (scrollPos > 0) - { - SetScrollPos32(SB_HORZ, 0); - Invalidate(); - } break; - - case SB_RIGHT: - if (scrollPos < m_nHScrollMax) - { - SetScrollPos32(SB_HORZ, m_nHScrollMax); - Invalidate(); - } break; - } -} - -// Handle vert scrollbar notifications -void CTerrainCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) -{ - if (GetFocus()->GetSafeHwnd() != GetSafeHwnd()) - SetFocus(); // Auto-destroy any InPlaceEdit's - -#ifdef GRIDCONTROL_USE_TITLETIPS - m_TitleTip.Hide(); // hide any titletips -#endif - - // Get the scroll position ourselves to ensure we get a 32 bit value - int scrollPos = GetScrollPos32(SB_VERT); - - CELLID idTopLeft = GetTopleftNonFixedCell(); - - CRect rect; - GetClientRect(rect); - - switch (nSBCode) - { - case SB_LINEDOWN: - if (scrollPos < m_nVScrollMax) - { - int yScroll = GetRowHeight(nTopLeftRow); - SetScrollPos32(SB_VERT, scrollPos + yScroll); - if (GetScrollPos32(SB_VERT) == scrollPos) - break; // didn't work - - rect.top = GetFixedRowHeight() + yScroll; - ScrollWindow( 0, -yScroll, rect); - rect.top = rect.bottom - yScroll; - InvalidateRect(rect); - } break; - - case SB_LINEUP: - if (scrollPos > 0 && idTopLeft.row > GetFixedRowCount()) - { - int yScroll = GetRowHeight(nTopLeftRow-1); - SetScrollPos32(SB_VERT, max(0, scrollPos - yScroll)); - rect.top = GetFixedRowHeight(); - ScrollWindow(0, yScroll, rect); - rect.bottom = rect.top + yScroll; - InvalidateRect(rect); - } break; - - case SB_PAGEDOWN: - if (scrollPos < m_nVScrollMax) - { - rect.top = GetFixedRowHeight(); - scrollPos = min(m_nVScrollMax, scrollPos + rect.Height()); - SetScrollPos32(SB_VERT, scrollPos); - rect.top = GetFixedRowHeight(); - InvalidateRect(rect); - } break; - - case SB_PAGEUP: - if (scrollPos > 0) - { - rect.top = GetFixedRowHeight(); - int offset = -rect.Height(); - int pos = max(0, scrollPos + offset); - SetScrollPos32(SB_VERT, pos); - rect.top = GetFixedRowHeight(); - InvalidateRect(rect); - } break; - - case SB_THUMBPOSITION: - case SB_THUMBTRACK: - { - SetScrollPos32(SB_VERT, GetScrollPos32(SB_VERT, TRUE)); - rect.top = GetFixedRowHeight(); - InvalidateRect(rect); - } break; - - case SB_TOP: - if (scrollPos > 0) - { - SetScrollPos32(SB_VERT, 0); - Invalidate(); - } break; - - case SB_BOTTOM: - if (scrollPos < m_nVScrollMax) - { - SetScrollPos32(SB_VERT, m_nVScrollMax); - Invalidate(); - } - } -} - -void CTerrainCtrl::OnDraw(CDC* pDC) -{ - int row,col; - CRect clientRect; - GetClientRect(clientRect); - - CRect clipRect; - if (pDC->GetClipBox(&clipRect) == ERROR) - return; - - // OnEraseBkgnd does nothing, so erase bkgnd here. - // This necessary since we may be using a Memory DC. - EraseBkgnd(pDC); - - int nFixedRowHeight = GetFixedRowHeight(); - int nFixedColWidth = GetFixedColumnWidth(); - - CELLID idTopLeft = GetTopleftNonFixedCell(); -/* - CRect VisRect; - CCellRange VisCellRange = GetVisibleNonFixedCellRange(VisRect); - int maxVisibleRow = VisCellRange.GetMaxRow(), - maxVisibleCol = VisCellRange.GetMaxCol(); -*/ - // calc bottom - int i, bottom = GetFixedRowHeight(); - for (i = idTopLeft.row; i < m_nRows; i++) - { - bottom += GetRowHeight(i); - if (bottom >= clientRect.bottom) - { - bottom = clientRect.bottom; - break; - } - } - int maxVisibleRow = min(i, m_nRows - 1); - - // calc right - int right = GetFixedColumnWidth(); - for (i = idTopLeft.col; i < m_nCols; i++) - { - right += GetColumnWidth(i); - if (right >= clientRect.right) - { - right = clientRect.right; - break; - } - } - int maxVisibleCol = min(i, m_nCols - 1); - - // draw top-left cell - CRect rect; - rect.top = 0; - rect.bottom = GetRowHeight(0)-1; - rect.left = 0; - rect.right = GetColumnWidth(0)-1; - DrawFixedCell(pDC, 0, 0, rect); - - // draw fixed column cells - rect.bottom = nFixedRowHeight-1; - for (row = idTopLeft.row; row <= maxVisibleRow; row++) - { - rect.top = rect.bottom+1; - rect.bottom = rect.top + GetRowHeight(row)-1; - - // rect.bottom = bottom pixel of previous row - if (rect.top > clipRect.bottom) break; // Gone past cliprect - if (rect.bottom < clipRect.top) continue; // Reached cliprect yet? - - rect.left = 0; - rect.right = GetColumnWidth(0)-1; - - if (rect.left > clipRect.right) break; // gone past cliprect - if (rect.right < clipRect.left) continue; // Reached cliprect yet? - - DrawFixedCell(pDC, row, 0, rect); - } - - // draw end of column - if (rect.bottom < clientRect.bottom) - { - rect.top = rect.bottom+1; - rect.bottom = clientRect.bottom-1; - - if (rect.top < clipRect.bottom) - if (rect.bottom > clipRect.top) - if (rect.left < clipRect.right) - if (rect.right > clipRect.left) - DrawFixedCell(pDC, 0, 0, rect); - } - - // draw fixed row cells 0..m_nFixedRows, m_nFixedCols..n - rect.top = 0; - rect.bottom = GetRowHeight(0)-1; - - // rect.bottom = bottom pixel of previous row - if (rect.top < clipRect.bottom) // Gone past cliprect - if (rect.bottom > clipRect.top) // Reached cliprect yet? - { - rect.right = nFixedColWidth-1; - for (col = idTopLeft.col; col <= maxVisibleCol; col++) - { - rect.left = rect.right+1; - rect.right = rect.left + GetColumnWidth(col)-1; - - if (rect.left > clipRect.right) break; // gone past cliprect - if (rect.right < clipRect.left) continue; // Reached cliprect yet? - - DrawFixedCell(pDC, 0, col, rect); - } - } - - // draw end of row - if (rect.right < clientRect.right) - { - rect.left = rect.right+1; - rect.right = clientRect.right - 1; - - if (rect.top < clipRect.bottom) - if (rect.bottom > clipRect.top) - if (rect.left < clipRect.right) - if (rect.right > clipRect.left) - DrawFixedCell(pDC, 0, 0, rect); - - } - - // draw rest of non-fixed cells - rect.bottom = nFixedRowHeight-1; - for (row = idTopLeft.row; row <= maxVisibleRow; row++) - { - rect.top = rect.bottom+1; - rect.bottom = rect.top + GetRowHeight(row)-1; - - // rect.bottom = bottom pixel of previous row - if (rect.top > clipRect.bottom) break; // Gone past cliprect - if (rect.bottom < clipRect.top) continue; // Reached cliprect yet? - - rect.right = nFixedColWidth-1; - for (col = idTopLeft.col; col <= maxVisibleCol; col++) - { - rect.left = rect.right+1; - rect.right = rect.left + GetColumnWidth(col)-1; - - if (rect.left > clipRect.right) break; // gone past cliprect - if (rect.right < clipRect.left) continue; // Reached cliprect yet? - - DrawCell(pDC, row, col, rect); - } - } -} - -// Get/Set scroll position using 32 bit functions -int CTerrainCtrl::GetScrollPos32(int nBar, BOOL bGetTrackPos /* = FALSE */) -{ - SCROLLINFO si; - si.cbSize = sizeof(SCROLLINFO); - - if (bGetTrackPos) - { - if (GetScrollInfo(nBar, &si, SIF_TRACKPOS)) - return si.nTrackPos; - } - else - { - if (GetScrollInfo(nBar, &si, SIF_POS)) - return si.nPos; - } - - return 0; -} - -BOOL CTerrainCtrl::SetScrollPos32(int nBar, int nPos, BOOL bRedraw /* = TRUE */) -{ - SCROLLINFO si; - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_POS; - si.nPos = nPos; - return SetScrollInfo(nBar, &si, bRedraw); -} - -void CTerrainCtrl::ResetScrollBars() -{ - if (!::IsWindow(GetSafeHwnd())) - return; - - CRect rect; - GetClientRect(rect); - rect.left += GetFixedColumnWidth(); - rect.top += GetFixedRowHeight(); - if (rect.left >= rect.right || rect.top >= rect.bottom) - return; - - CRect VisibleRect(GetFixedColumnWidth(), GetFixedRowHeight(), rect.right, rect.bottom); - CRect VirtualRect(GetFixedColumnWidth(), GetFixedRowHeight(), GetVirtualWidth(), GetVirtualHeight()); -/* - CCellRange visibleCells = GetUnobstructedNonFixedCellRange(); - if (!IsValid(visibleCells)) return; -*/ - SCROLLINFO si; - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_PAGE; - si.nPage = VisibleRect.Width(); - SetScrollInfo(SB_HORZ, &si, FALSE); - si.nPage = VisibleRect.Height(); - SetScrollInfo(SB_VERT, &si, FALSE); - - if (VisibleRect.Height() < VirtualRect.Height()) - m_nVScrollMax = VirtualRect.Height()-1;//-VisibleRect.Height();//+GetRowHeight(0); - else - m_nVScrollMax = 0; - - if (VisibleRect.Width() < VirtualRect.Width()) - m_nHScrollMax = VirtualRect.Width()-1;//-VisibleRect.Width();//+GetColumnWidth(0); - else - m_nHScrollMax = 0; - - ASSERT(m_nVScrollMax < INT_MAX && m_nHScrollMax < INT_MAX); // This should be fine :) - SetScrollRange(SB_VERT, 0, m_nVScrollMax, TRUE); - SetScrollRange(SB_HORZ, 0, m_nHScrollMax, TRUE); -} - -BOOL CTerrainCtrl::DrawFixedCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk) -{ - if (bEraseBk) - { - CBrush brush(m_crFixedBkColour); - pDC->FillRect(rect, &brush); - } - pDC->SetTextColor(m_crFixedTextColour); - - int nSavedDC = pDC->SaveDC(); -/* - // Create the appropriate font and select into DC - LOGFONT lf, *pLF = GetItemFont(nRow, nCol); - if (pLF) - memcpy(&lf, pLF, sizeof(LOGFONT)); - else - memcpy(&lf, &m_Logfont, sizeof(LOGFONT)); - - CCellID FocusCell = GetFocusCell(); - if (FocusCell.row == nRow || FocusCell.col == nCol) - lf.lfWeight = SELECTED_CELL_FONT_WEIGHT; - - CFont Font; - Font.CreateFontIndirect(&lf); - pDC->SelectObject(&Font); - - if (IsValid(FocusCell) && (FocusCell.row == nRow || FocusCell.col == nCol)) - { - rect.right++; rect.bottom++; - pDC->DrawEdge(rect, EDGE_RAISED, BF_RECT); - rect.DeflateRect(1,1); - } - else -*/ { - CPen lightpen(PS_SOLID, 1, ::GetSysColor(COLOR_3DHIGHLIGHT)), - darkpen(PS_SOLID, 1, ::GetSysColor(COLOR_3DDKSHADOW)), - *pOldPen = pDC->GetCurrentPen(); - - pDC->SelectObject(&lightpen); - pDC->MoveTo(rect.right, rect.top); - pDC->LineTo(rect.left, rect.top); - pDC->LineTo(rect.left, rect.bottom); - - pDC->SelectObject(&darkpen); - pDC->MoveTo(rect.right, rect.top); - pDC->LineTo(rect.right, rect.bottom); - pDC->LineTo(rect.left, rect.bottom); - - pDC->SelectObject(pOldPen); - rect.DeflateRect(1,1); - } - - pDC->SetBkMode(TRANSPARENT); - rect.DeflateRect(m_nMargin, 0); - - if ((nRow != 0 || nCol != 0) && nRow < m_nRows && nCol < m_nCols) - { - char szText[10]; - sprintf(szText, "%d", nRow == 0 ? nCol : nRow); - DrawText(pDC->m_hDC, szText, -1, rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); - } - - pDC->RestoreDC(nSavedDC); - return TRUE; -} - -BOOL CTerrainCtrl::DrawCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk) -{ - COLORREF TextClr = m_crFixedTextColour; - - int nSavedDC = pDC->SaveDC(); - - pDC->SetBkMode(TRANSPARENT); - - if (m_RowData[nRow][nCol].state & GS_FOCUSED) - { - rect.right++; rect.bottom++; // FillRect doesn't draw RHS or bottom - if (bEraseBk) - { - CBrush brush(m_crTextBkColour); - pDC->FillRect(rect, &brush); - } - rect.right--; rect.bottom--; - pDC->SelectStockObject(BLACK_PEN); - pDC->SelectStockObject(NULL_BRUSH); - pDC->Rectangle(rect); - pDC->SetTextColor(TextClr); - - rect.DeflateRect(1,1); - - } - else if (m_RowData[nRow][nCol].state & GS_SELECTED) - { - rect.right++; rect.bottom++; // FillRect doesn't draw RHS or bottom - pDC->FillSolidRect(rect, ::GetSysColor(COLOR_HIGHLIGHT)); - rect.right--; rect.bottom--; - pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); - } - else - { - rect.right++; rect.bottom++; // FillRect doesn't draw RHS or bottom - if (bEraseBk) - { - CBrush brush(m_crTextBkColour); - pDC->FillRect(rect, &brush); - } - rect.right--; rect.bottom--; - pDC->SetTextColor(TextClr); - } -/* - if (Item.state & GVIS_DROPHILITED) - { - pDC->SelectStockObject(BLACK_PEN); - pDC->SelectStockObject(NULL_BRUSH); - pDC->Rectangle(rect); - } -*/ - - CPen lightpen(PS_SOLID, 1, RGB(0xE0, 0xE0, 0xE0)), - darkpen(PS_SOLID, 1, RGB(0,0,0)), - *pOldPen = pDC->GetCurrentPen(); - - int left = nCol == 1 ? GRIDSIZE/2-1 : 0; - int top = nRow == 1 ? GRIDSIZE/2-1 : 0; - int right = nCol == m_nCols-1 ? GRIDSIZE/2-1 : -1; - int bottom = nRow == m_nRows-1 ? GRIDSIZE/2-1 : -1; - - if ((nRow-1) % 3) - { - pDC->SelectObject(&lightpen); - pDC->MoveTo(rect.left + left, (rect.top + rect.bottom)/2); - pDC->LineTo(rect.right - right, (rect.top + rect.bottom)/2); - } - - if ((nCol-1) % 3) - { - pDC->SelectObject(&lightpen); - pDC->MoveTo((rect.left + rect.right)/2, rect.top + top); - pDC->LineTo((rect.left + rect.right)/2, rect.bottom - bottom); - } - - if ((nRow-1) % 3 == 0) - { - pDC->SelectObject(&darkpen); - pDC->MoveTo(rect.left + left, (rect.top + rect.bottom)/2); - pDC->LineTo(rect.right - right, (rect.top + rect.bottom)/2); - } - - if ((nCol-1) % 3 == 0) - { - pDC->SelectObject(&darkpen); - pDC->MoveTo((rect.left + rect.right)/2, rect.top + top); - pDC->LineTo((rect.left + rect.right)/2, rect.bottom - bottom); - } - - pDC->SelectObject(pOldPen); - -/* // Create the appropriate font and select into DC - CFont Font; - LOGFONT *pLF = GetItemFont(nRow, nCol); - if (pLF) - Font.CreateFontIndirect(pLF); - else - Font.CreateFontIndirect(&m_Logfont); -*/ - CFont *pOldFont = pDC->SelectObject(&m_Font); - rect.DeflateRect(m_nMargin, 0); - rect.OffsetRect(GRIDSIZE/2, GRIDSIZE/4+2); - - char szText[10]; - sprintf(szText, "%.0f", ControlPoint(nRow, nCol)); - - DrawText(pDC->m_hDC, szText, -1, rect, DT_LEFT|DT_VCENTER|DT_SINGLELINE); - - pDC->SelectObject(pOldFont); - - pDC->RestoreDC(nSavedDC); - return TRUE; -} - -BOOL CTerrainCtrl::SetRowCount(int nRows) -{ - ASSERT(nRows > 0); - if (nRows == m_nRows) - return TRUE; - - if (m_idCurrentCell.row >= nRows) - SetFocusCell(-1,-1); - - int addedRows = nRows - m_nRows; - - // Change the number of rows. - m_nRows = nRows; - m_RowData.SetSize(m_nRows); - - // If we have just added rows, we need to construct new elements for each cell - // and set the default row height - if (addedRows > 0) - { - // initialize row heights and data - int startRow = nRows - addedRows; - for (int row = startRow; row < m_nRows; row++) - { - m_RowData[row].SetSize(m_nCols); - for (int col = 0; col < m_nCols; col++) - m_RowData[row][col].state = 0; - } - } - - if (GetSafeHwnd()) - { - ResetScrollBars(); - Invalidate(); - } - - return TRUE; -} - -BOOL CTerrainCtrl::SetColumnCount(int nCols) -{ - ASSERT(nCols > 0); - - if (nCols == m_nCols) - return TRUE; - - if (m_idCurrentCell.col >= nCols) - SetFocusCell(-1,-1); - - int addedCols = nCols - m_nCols; - - // Change the number of columns. - m_nCols = nCols; - - // Change the number of columns in each row. - for (int i = 0; i < m_nRows; i++) - m_RowData[i].SetSize(nCols); - - // If we have just added columns, we need to construct new elements for each cell - // and set the default column width - if (addedCols > 0) - { - int startCol = nCols - addedCols; - - for (int row = 0; row < m_nRows; row++) - for (int col = startCol; col < m_nCols; col++) - m_RowData[row][col].state = 0; - } - - if (GetSafeHwnd()) - { - ResetScrollBars(); - Invalidate(); - } - return TRUE; -} - -CELLID CTerrainCtrl::GetTopleftNonFixedCell() -{ - CELLID cell; - - int nVertScroll = GetScrollPos(SB_VERT), nHorzScroll = GetScrollPos(SB_HORZ); - - int nColumn = m_nFixedCols, nRight = 0; - while (nRight < nHorzScroll && nColumn < (m_nCols-1)) - { - nColumn++; - nRight += GetColumnWidth(nColumn); - } - - int nRow = m_nFixedRows, nTop = 0; - while (nTop < nVertScroll && nRow < (m_nRows-1)) - { - nRow++; - nTop += GetRowHeight(nRow); - } - - cell.row = nRow; - cell.col = nColumn; - - return cell; -} - -void CTerrainCtrl::SetControlPoints(int uCount, int vCount, float** pControl) -{ - SetRowCount(uCount+1); - SetColumnCount(vCount+1); - m_pControl = pControl; - InvalidateRect(NULL, FALSE); -} - -void CTerrainCtrl::OnLButtonDown(UINT nFlags, CPoint point) -{ -/* - HWND hOldFocusWnd = ::GetFocus(); -*/ - m_LeftClickDownPoint = point; - m_LeftClickDownCell = GetCellFromPt(point); - if (!IsValid(m_LeftClickDownCell)) - return; -/* - m_SelectionStartCell = (nFlags & MK_SHIFT)? m_idCurrentCell : m_LeftClickDownCell; -*/ - SetFocus(); // Auto-destroy any InPlaceEdit's - - // If the user clicks on the current cell, then prepare to edit it. - // (If the user moves the mouse, then dragging occurs) - if (m_LeftClickDownCell == m_idCurrentCell) - { - m_MouseMode = MOUSE_PREPARE_EDIT; - return; - } - else - { - SetFocusCell(-1,-1); - SetFocusCell(max(m_LeftClickDownCell.row, 1), - max(m_LeftClickDownCell.col, 1)); - } -/* - // If the user clicks on a selected cell, then prepare to drag it. - // (If the user moves the mouse, then dragging occurs) - if (m_bAllowDragAndDrop && hOldFocusWnd == GetSafeHwnd() && - GetItemState(m_LeftClickDownCell.row, m_LeftClickDownCell.col) & GVNI_SELECTED) - { - m_MouseMode = MOUSE_PREPARE_DRAG; - return; - } -*/ - SetCapture(); - - // If Ctrl pressed, save the current cell selection. This will get added -/* // to the new cell selection at the end of the cell selection process - m_PrevSelectedCellMap.RemoveAll(); - if (nFlags & MK_CONTROL) - { - for (POSITION pos = m_SelectedCellMap.GetStartPosition(); pos != NULL; ) - { - DWORD key; - CCellID cell; - m_SelectedCellMap.GetNextAssoc(pos, key, (CCellID&)cell); - m_PrevSelectedCellMap.SetAt(key, cell); - } - } - - if (m_LeftClickDownCell.row < GetFixedRowCount()) - OnFixedRowClick(m_LeftClickDownCell); - else if (m_LeftClickDownCell.col < GetFixedColumnCount()) - OnFixedColumnClick(m_LeftClickDownCell); - else - { - m_MouseMode = m_bListMode? MOUSE_SELECT_ROW : MOUSE_SELECT_CELLS; - OnSelecting(m_LeftClickDownCell); - } - - m_nTimerID = SetTimer(WM_LBUTTONDOWN, m_nTimerInterval, 0); - - m_LastMousePoint = point; -*/ -} - -void CTerrainCtrl::OnLButtonUp(UINT nFlags, CPoint point) -{ - CWnd::OnLButtonUp(nFlags, point); - ClipCursor(NULL); - - if (GetCapture()->GetSafeHwnd() == GetSafeHwnd()) - { - ReleaseCapture(); -/* KillTimer(m_nTimerID); - m_nTimerID = 0; -*/ } - - // m_MouseMode == MOUSE_PREPARE_EDIT only if user clicked down on current cell - // and then didn't move mouse before clicking up (releasing button) - if (m_MouseMode == MOUSE_PREPARE_EDIT) - { - EditCell(m_idCurrentCell.row, m_idCurrentCell.col, VK_LBUTTON); - } - // m_MouseMode == MOUSE_PREPARE_DRAG only if user clicked down on a selected cell -/* // and then didn't move mouse before clicking up (releasing button) - else if (m_MouseMode == MOUSE_PREPARE_DRAG) - { - ResetSelectedRange(); - } -*/ - m_MouseMode = MOUSE_NOTHING; - SetCursor(::LoadCursor(NULL, IDC_ARROW)); - - if (!IsValid(m_LeftClickDownCell)) - return; -/* - CWnd *pOwner = GetOwner(); - if (pOwner && IsWindow(pOwner->m_hWnd)) - pOwner->PostMessage(WM_COMMAND, MAKELONG(GetDlgCtrlID(), BN_CLICKED), - (LPARAM) GetSafeHwnd()); -*/ -} - -void CTerrainCtrl::OnMouseMove(UINT nFlags, CPoint point) -{ - CRect rect; - GetClientRect(rect); -/* - // If outside client area, return (unless we are drag n dropping) - if (m_MouseMode != MOUSE_DRAGGING && !rect.PtInRect(point)) - return; - - // If the left mouse button is up, then test to see if row/column sizing is imminent - if (!(nFlags & MK_LBUTTON)) - { - if (point.y < GetFixedRowHeight() && m_bAllowColumnResize) - { - CCellID idCurrentCell = GetCellFromPt(point); - CPoint start; - if (!GetCellOrigin(idCurrentCell, &start)) return; - - int endx = start.x + GetColumnWidth(idCurrentCell.col); - - if ((point.x - start.x <= m_nResizeCaptureRange && idCurrentCell.col != 0) || - endx - point.x <= m_nResizeCaptureRange) - { - if (m_MouseMode != MOUSE_OVER_COL_DIVIDE) - SetCursor(::LoadCursor(NULL, IDC_SIZEWE)); - m_MouseMode = MOUSE_OVER_COL_DIVIDE; - } - else - { - if (m_MouseMode != MOUSE_NOTHING) - SetCursor(::LoadCursor(NULL, IDC_ARROW)); - m_MouseMode = MOUSE_NOTHING; - } - } - else if (point.x < GetFixedColumnWidth() && m_bAllowRowResize) - { - CCellID idCurrentCell = GetCellFromPt(point); - CPoint start; - if (!GetCellOrigin(idCurrentCell, &start)) return; - - int endy = start.y + GetRowHeight(idCurrentCell.row); - - if ((point.y - start.y <= m_nResizeCaptureRange && idCurrentCell.row != 0) || - endy - point.y <= m_nResizeCaptureRange) - { - if (m_MouseMode != MOUSE_OVER_ROW_DIVIDE) - SetCursor(::LoadCursor(NULL, IDC_SIZENS)); - m_MouseMode = MOUSE_OVER_ROW_DIVIDE; - } - else - { - if (m_MouseMode != MOUSE_NOTHING) - SetCursor(::LoadCursor(NULL, IDC_ARROW)); - m_MouseMode = MOUSE_NOTHING; - } - } - else - { - if (m_MouseMode != MOUSE_NOTHING) - SetCursor(::LoadCursor(NULL, IDC_ARROW)); - m_MouseMode = MOUSE_NOTHING; - } - -#ifdef GRIDCONTROL_USE_TITLETIPS - if (m_MouseMode == MOUSE_NOTHING && m_bTitleTips) - { - CCellID idCurrentCell = GetCellFromPt(point); - CRect rect; - if (GetCellRect(idCurrentCell.row, idCurrentCell.col, rect)) - m_TitleTip.Show( rect, GetItemText(idCurrentCell.row, idCurrentCell.col), 0); - } -#endif - - m_LastMousePoint = point; - return; - } - - if (!IsValid(m_LeftClickDownCell)) - { - m_LastMousePoint = point; - return; - } - - // If the left mouse button is down, the process appropriately - if (nFlags & MK_LBUTTON) - { - switch(m_MouseMode) - { - case MOUSE_SELECT_ALL: - break; - - case MOUSE_SELECT_COL: - case MOUSE_SELECT_ROW: - case MOUSE_SELECT_CELLS: - { - CCellID idCurrentCell = GetCellFromPt(point); - if (!IsValid(idCurrentCell)) - return; - OnSelecting(idCurrentCell); -// SetFocusCell(max(idCurrentCell.row, m_nFixedRows), -// max(idCurrentCell.col, m_nFixedCols)); - if (idCurrentCell.row >= m_nFixedRows && - idCurrentCell.col >= m_nFixedCols) - SetFocusCell(idCurrentCell); - break; - } - - case MOUSE_PREPARE_DRAG: - OnBeginDrag(); - break; - } - } - - m_LastMousePoint = point; -*/ -} - -// Sets the currently selected cell -void CTerrainCtrl::SetFocusCell(CELLID cell) -{ - SetFocusCell(cell.row, cell.col); -} - -void CTerrainCtrl::SetFocusCell(int nRow, int nCol) -{ - CELLID cell(nRow, nCol); - - if (cell == m_idCurrentCell) - return; - - CELLID idPrev = m_idCurrentCell; - m_idCurrentCell = cell; - - if (IsValid(idPrev)) - { -/* SendMessageToParent(idPrev.row, idPrev.col, GVN_SELCHANGING); -*/ - m_RowData[idPrev.row][idPrev.col].state &= ~GS_FOCUSED; - - RedrawCell(idPrev); -/* - if (idPrev.col != m_idCurrentCell.col) - for (int row = 0; row < m_nFixedRows; row++) - RedrawCell(row, idPrev.col); - if (idPrev.row != m_idCurrentCell.row) - for (int col = 0; col < m_nFixedCols; col++) - RedrawCell(idPrev.row, col); -*/ } - - if (IsValid(m_idCurrentCell)) - { - m_RowData[nRow][nCol].state |= GS_FOCUSED; - - RedrawCell(m_idCurrentCell); -/* - if (idPrev.col != m_idCurrentCell.col) - for (int row = 0; row < m_nFixedRows; row++) - RedrawCell(row, m_idCurrentCell.col); - if (idPrev.row != m_idCurrentCell.row) - for (int col = 0; col < m_nFixedCols; col++) - RedrawCell(m_idCurrentCell.row, col); - - SendMessageToParent(m_idCurrentCell.row, m_idCurrentCell.col, GVN_SELCHANGED); -*/ } -} - -BOOL CTerrainCtrl::IsValid(int nRow, int nCol) -{ - return (nRow >= 0 && nRow < m_nRows && nCol >= 0 && nCol < m_nCols); -} - -BOOL CTerrainCtrl::IsValid(CELLID cell) -{ - return IsValid(cell.row, cell.col); -} - -// Get cell from point -CELLID CTerrainCtrl::GetCellFromPt(CPoint point, BOOL bAllowFixedCellCheck) -{ - CELLID idTopLeft = GetTopleftNonFixedCell(); - CELLID cellID; // return value - - // calculate column index - int fixedColWidth = GetFixedColumnWidth(); - - if (point.x < 0 || (!bAllowFixedCellCheck && point.x < fixedColWidth)) // not in window - cellID.col = -1; - else if (point.x < fixedColWidth) // in fixed col - { - int col, xpos = 0; - for (col = 0; col < m_nFixedCols; col++) - { - xpos += GetColumnWidth(col); - if (xpos > point.x) break; - } - cellID.col = col; - } - else // in non-fixed col - { - int col, xpos = fixedColWidth; - for (col = idTopLeft.col; col < m_nCols; col++) - { - xpos += GetColumnWidth(col); - if (xpos > point.x) break; - } - - if (col >= GetColumnCount()) - cellID.col = -1; - else - cellID.col = col; - } - - // calculate row index - int fixedRowHeight = GetFixedRowHeight(); - if (point.y < 0 || (!bAllowFixedCellCheck && point.y < fixedRowHeight)) // not in window - cellID.row = -1; - else if (point.y < fixedRowHeight) // in fixed col - { - int row, ypos = 0; - for (row = 0; row < m_nFixedRows; row++) - { - ypos += GetRowHeight(row); - if (ypos > point.y) break; - } - cellID.row = row; - } - else - { - int row, ypos = fixedRowHeight; - for (row = idTopLeft.row; row < GetRowCount(); row++) - { - ypos += GetRowHeight(row); - if (ypos > point.y) break; - } - - if (row >= GetRowCount()) - cellID.row = -1; - else - cellID.row = row; - } - - return cellID; -} - -// Forces a redraw of a cell immediately using a direct -// DC construction, or the supplied DC -BOOL CTerrainCtrl::RedrawCell(CELLID cell, CDC* pDC) -{ - return RedrawCell(cell.row, cell.col, pDC); -} - -BOOL CTerrainCtrl::RedrawCell(int nRow, int nCol, CDC* pDC) -{ - BOOL bResult = TRUE; - BOOL bMustReleaseDC = FALSE; - - if (!IsCellVisible(nRow, nCol)) - return FALSE; - - CRect rect; - if (!GetCellRect(nRow, nCol, rect)) - return FALSE; - - if (!pDC) - { - pDC = GetDC(); - if (pDC) - bMustReleaseDC = TRUE; - } - - if (pDC) - { - // Redraw cells directly - if (nRow < m_nFixedRows || nCol < m_nFixedCols) - bResult = DrawFixedCell(pDC, nRow, nCol, rect, TRUE); - else - bResult = DrawCell(pDC, nRow, nCol, rect, TRUE); -/* - // Since we have erased the background, we will need to redraw the gridlines - CPen pen; - try { - pen.CreatePen(PS_SOLID, 0, m_crGridColour); - } catch (...) {} - - CPen* pOldPen = (CPen*) pDC->SelectObject(&pen); - if (m_nGridLines == GVL_BOTH || m_nGridLines == GVL_HORZ) - { - pDC->MoveTo(rect.left, rect.bottom); - pDC->LineTo(rect.right+1, rect.bottom); - } - if (m_nGridLines == GVL_BOTH || m_nGridLines == GVL_VERT) - { - pDC->MoveTo(rect.right, rect.top); - pDC->LineTo(rect.right, rect.bottom+1); - } - pDC->SelectObject(pOldPen); -*/ - } else - InvalidateRect(rect, TRUE); // Could not get a DC - invalidate it anyway - // and hope that OnPaint manages to get one - - if (bMustReleaseDC) - ReleaseDC(pDC); - - return bResult; -} - -// returns the top left point of the cell. Returns FALSE if cell not visible. -BOOL CTerrainCtrl::GetCellOrigin(CELLID cell, LPPOINT p) -{ - return GetCellOrigin(cell.row, cell.col, p); -} - -BOOL CTerrainCtrl::GetCellOrigin(int nRow, int nCol, LPPOINT p) -{ - int i; - - if (!IsValid(nRow, nCol)) - return FALSE; - - CELLID idTopLeft; - if (nCol >= m_nFixedCols || nRow >= m_nFixedRows) - idTopLeft = GetTopleftNonFixedCell(); - - if ((nRow >= m_nFixedRows && nRow < idTopLeft.row) || - (nCol>= m_nFixedCols && nCol < idTopLeft.col)) - return FALSE; - - p->x = 0; - if (nCol < m_nFixedCols) // is a fixed column - for (i = 0; i < nCol; i++) - p->x += GetColumnWidth(i); - else // is a scrollable data column - { - for (i = 0; i < m_nFixedCols; i++) - p->x += GetColumnWidth(i); - for (i = idTopLeft.col; i < nCol; i++) - p->x += GetColumnWidth(i); - } - - p->y = 0; - if (nRow < m_nFixedRows) // is a fixed row - for (i = 0; i < nRow; i++) - p->y += GetRowHeight(i); - else // is a scrollable data row - { - for (i = 0; i < m_nFixedRows; i++) - p->y += GetRowHeight(i); - for (i = idTopLeft.row; i < nRow; i++) - p->y += GetRowHeight(i); - } - - return TRUE; -} - -// Returns the bounding box of the cell -BOOL CTerrainCtrl::GetCellRect(CELLID cell, LPRECT pRect) -{ - return GetCellRect(cell.row, cell.col, pRect); -} - -BOOL CTerrainCtrl::GetCellRect(int nRow, int nCol, LPRECT pRect) -{ - CPoint CellOrigin; - if (!GetCellOrigin(nRow, nCol, &CellOrigin)) - return FALSE; - - pRect->left = CellOrigin.x; - pRect->top = CellOrigin.y; - pRect->right = CellOrigin.x + GetColumnWidth(nCol)-1; - pRect->bottom = CellOrigin.y + GetRowHeight(nRow)-1; - - return TRUE; -} - -BOOL CTerrainCtrl::IsCellVisible(CELLID cell) -{ - return IsCellVisible(cell.row, cell.col); -} - -BOOL CTerrainCtrl::IsCellVisible(int nRow, int nCol) -{ - if (!IsWindow(m_hWnd)) - return FALSE; - - int x,y; - - CELLID TopLeft; - if (nCol >= GetFixedColumnCount() || nRow >= GetFixedRowCount()) - { - TopLeft = GetTopleftNonFixedCell(); - if (nCol >= GetFixedColumnCount() && nCol < TopLeft.col) return FALSE; - if (nRow >= GetFixedRowCount() && nRow < TopLeft.row) return FALSE; - } - - CRect rect; - GetClientRect(rect); - if (nCol < GetFixedColumnCount()) - { - x = 0; - for (int i = 0; i <= nCol; i++) - { - if (x >= rect.right) return FALSE; - x += GetColumnWidth(i); - } - } - else - { - x = GetFixedColumnWidth(); - for (int i = TopLeft.col; i <= nCol; i++) - { - if (x >= rect.right) return FALSE; - x += GetColumnWidth(i); - } - } - - if (nRow < GetFixedRowCount()) - { - y = 0; - for (int i = 0; i <= nRow; i++) - { - if (y >= rect.bottom) return FALSE; - y += GetRowHeight(i); - } - } - else - { - if (nRow < TopLeft.row) return FALSE; - y = GetFixedRowHeight(); - for (int i = TopLeft.row; i <= nRow; i++) - { - if (y >= rect.bottom) return FALSE; - y += GetRowHeight(i); - } - } - - return TRUE; -} - -// move about with keyboard -void CTerrainCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) -{ - if (!IsValid(m_idCurrentCell)) - { - CWnd::OnKeyDown(nChar, nRepCnt, nFlags); - return; - } - - CELLID next = m_idCurrentCell; - BOOL bChangeLine = FALSE; -/* - if (IsCTRLpressed()) - { - switch (nChar) - { - case 'A': OnEditSelectAll(); break; - } - } -*/ - switch (nChar) - { -/* - case VK_DELETE: - if (IsCellEditable(m_idCurrentCell.row, m_idCurrentCell.col)) - { - SetItemText(m_idCurrentCell.row, m_idCurrentCell.col, _T("")); - RedrawCell(m_idCurrentCell); - SetModified(TRUE); - } - break; - - case VK_TAB: - if (IsSHIFTpressed()) - { - if (next.col > m_nFixedCols) - next.col--; - else if (next.col == m_nFixedCols && next.row > m_nFixedRows) - { - next.row--; - next.col = GetColumnCount() - 1; - bChangeLine = TRUE; - } - else - CWnd::OnKeyDown(nChar, nRepCnt, nFlags); - } - else - { - if (next.col < (GetColumnCount() - 1)) - next.col++; - else if (next.col == (GetColumnCount() - 1) && - next.row < (GetRowCount() - 1) ) - { - next.row++; - next.col = m_nFixedCols; - bChangeLine = TRUE; - } - else - CWnd::OnKeyDown(nChar, nRepCnt, nFlags); - } - break; -*/ - case VK_DOWN: - if (next.row < (GetRowCount() - 1)) - next.row++; - break; - - case VK_UP: - if (next.row > 1) - next.row--; - break; - - case VK_RIGHT: - if (next.col < (GetColumnCount() - 1)) - next.col++; - break; - - case VK_LEFT: - if (next.col > 1) - next.col--; - break; - - case VK_NEXT: - { - CELLID idOldTopLeft = GetTopleftNonFixedCell(); - SendMessage(WM_VSCROLL, SB_PAGEDOWN, 0); - CELLID idNewTopLeft = GetTopleftNonFixedCell(); - - int increment = idNewTopLeft.row - idOldTopLeft.row; - if (increment) - { - next.row += increment; - if (next.row > (GetRowCount() - 1)) - next.row = GetRowCount() - 1; - } - else - next.row = GetRowCount() - 1; - break; - } - - case VK_PRIOR: - { - CELLID idOldTopLeft = GetTopleftNonFixedCell(); - SendMessage(WM_VSCROLL, SB_PAGEUP, 0); - CELLID idNewTopLeft = GetTopleftNonFixedCell(); - - int increment = idNewTopLeft.row - idOldTopLeft.row; - if (increment) - { - next.row += increment; - if (next.row < m_nFixedRows) - next.row = m_nFixedRows; - } - else - next.row = m_nFixedRows; - break; - } - - case VK_HOME: - SendMessage(WM_VSCROLL, SB_TOP, 0); - next.row = m_nFixedRows; - break; - - case VK_END: - SendMessage(WM_VSCROLL, SB_BOTTOM, 0); - next.row = GetRowCount() - 1; - break; - - default: - CWnd::OnKeyDown(nChar, nRepCnt, nFlags); - } - - if (next != m_idCurrentCell) - { - // While moving with the Cursorkeys the current ROW/CELL will get selected - // OR Selection will get expanded when SHIFT is pressed - // Cut n paste from OnLButtonDown - Franco Bez -/* // Added check for NULL mouse mode - Chris Maunder. - if (m_MouseMode == MOUSE_NOTHING) - { - m_PrevSelectedCellMap.RemoveAll(); - m_MouseMode = m_bListMode? MOUSE_SELECT_ROW : MOUSE_SELECT_CELLS; - if (!IsSHIFTpressed() || nChar == VK_TAB) - m_SelectionStartCell = next; - OnSelecting(next); - m_MouseMode = MOUSE_NOTHING; - } -*/ - SetFocusCell(next); - - if (!IsCellVisible(next)) - { - EnsureVisible(next); // Make sure cell is visible - - switch (nChar) - { - case VK_RIGHT: - SendMessage(WM_HSCROLL, SB_LINERIGHT, 0); - break; - - case VK_LEFT: - SendMessage(WM_HSCROLL, SB_LINELEFT, 0); - break; - - case VK_DOWN: - SendMessage(WM_VSCROLL, SB_LINEDOWN, 0); - break; - - case VK_UP: - SendMessage(WM_VSCROLL, SB_LINEUP, 0); - break; -/* - case VK_TAB: - if (IsSHIFTpressed()) - { - if (bChangeLine) - { - SendMessage(WM_VSCROLL, SB_LINEUP, 0); - SetScrollPos32(SB_HORZ, m_nHScrollMax); - break; - } - else - SendMessage(WM_HSCROLL, SB_LINELEFT, 0); - } - else - { - if (bChangeLine) - { - SendMessage(WM_VSCROLL, SB_LINEDOWN, 0); - SetScrollPos32(SB_HORZ, 0); - break; - } - else - SendMessage(WM_HSCROLL, SB_LINERIGHT, 0); - } - break; -*/ - } - Invalidate(); - } - } -} - -void CTerrainCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) -{ - if ( - /* !IsCTRLpressed() && - */ - m_MouseMode == MOUSE_NOTHING) - { -/* if (!m_bHandleTabKey || (m_bHandleTabKey && nChar != VK_TAB)) -*/ EditCell(m_idCurrentCell.row, m_idCurrentCell.col, nChar); - } - - CWnd::OnChar(nChar, nRepCnt, nFlags); -} - -// Instant editing of cells when keys are pressed -void CTerrainCtrl::EditCell(int nRow, int nCol, UINT nChar) -{ - EnsureVisible(nRow, nCol); - - if (!IsValid(nRow, nCol) || !IsCellVisible(nRow, nCol)) - return; - - CRect rect; - if (!GetCellRect(nRow, nCol, rect)) - return; -/* - SendMessageToParent(nRow, nCol, GVN_BEGINLABELEDIT); -*/ - char szText[20]; - sprintf(szText, "%.2f", ControlPoint(nRow, nCol)); - new CInPlaceEdit(this, rect, ES_LEFT, IDC_INPLACE_EDIT, &ControlPoint(nRow, nCol), szText, nChar); -} - -void CTerrainCtrl::EnsureVisible(CELLID cell) -{ - EnsureVisible(cell.row, cell.col); -} - -void CTerrainCtrl::EnsureVisible(int nRow, int nCol) -{ -// CCellRange VisibleCells = GetVisibleNonFixedCellRange(); - CRect rect; - GetClientRect(rect); - CELLID idTopLeft = GetTopleftNonFixedCell(); - - // calc bottom - int i, bottom = GetFixedRowHeight(); - for (i = idTopLeft.row; i < m_nRows; i++) - { - bottom += GetRowHeight(i); - if (bottom >= rect.bottom) - { - bottom = rect.bottom; - break; - } - } - int maxVisibleRow = min(i, m_nRows - 1); - - // calc right - int right = GetFixedColumnWidth(); - for (i = idTopLeft.col; i < m_nCols; i++) - { - right += GetColumnWidth(i); - if (right >= rect.right) - { - right = rect.right; - break; - } - } - int maxVisibleCol = min(i, m_nCols - 1); - - right = nCol - maxVisibleCol; - int left = idTopLeft.col - nCol; - int down = nRow - maxVisibleRow; - int up = idTopLeft.row - nRow; - - while (right > 0) - { - SendMessage(WM_HSCROLL, SB_LINERIGHT, 0); - right--; - } - while (left > 0) - { - SendMessage(WM_HSCROLL, SB_LINELEFT, 0); - left--; - } - while (down > 0) - { - SendMessage(WM_VSCROLL, SB_LINEDOWN, 0); - down--; - } - while (up > 0) - { - SendMessage(WM_VSCROLL, SB_LINEUP, 0); - up--; - } - - // Move one more if we only see a small bit of the cell - CRect rectCell, rectWindow; - GetCellRect(nRow, nCol, rectCell); - GetClientRect(rectWindow); - if (rectCell.right > rectWindow.right) - SendMessage(WM_HSCROLL, SB_LINERIGHT, 0); - if (rectCell.bottom > rectWindow.bottom) - SendMessage(WM_VSCROLL, SB_LINEDOWN, 0); -} diff --git a/win/terrctrl.h b/win/terrctrl.h deleted file mode 100644 index ee6f16f1..00000000 --- a/win/terrctrl.h +++ /dev/null @@ -1,153 +0,0 @@ -#if !defined(AFX_TERRCTRL_H__15B2D2A1_D2FF_11D2_8204_EEB0809D9016__INCLUDED_) -#define AFX_TERRCTRL_H__15B2D2A1_D2FF_11D2_8204_EEB0809D9016__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 -// TerrCtrl.h : header file -// - -#include - -#define TERRAINCTRL_CLASSNAME _T("TerrainCtrl") - -typedef struct { - UINT state; // Cell state (selected/focus etc) -// float height; -} GRIDCELL; - -typedef struct CELLID { - int row, col; - CELLID(int nRow = -1, int nCol = -1) - : row(nRow), col(nCol) {} - BOOL operator==(const CELLID rhs) - { return (row == rhs.row && col == rhs.col); } - BOOL operator!=(const CELLID rhs) - { return (row != rhs.row || col != rhs.col); } -} CELLID; - - -// Cell states -#define GS_FOCUSED 0x0001 -#define GS_SELECTED 0x0002 -#define GS_DROPHILITED 0x0004 -#define GS_READONLY 0x0008 - -// storage typedef for each row in the grid -typedef CArray GRID_ROW; - -///////////////////////////////////////////////////////////////////////////// -// CTerrainCtrl window - -class CTerrainCtrl : public CWnd -{ -// Construction -public: - CTerrainCtrl(); - BOOL Create(const RECT& rect, CWnd* pParentWnd, UINT nID, DWORD dwStyle = WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE); - BOOL SubclassWindow(HWND hWnd); - -// Attributes -public: - -// Operations -public: - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CTerrainCtrl) - protected: - virtual void PreSubclassWindow(); - //}}AFX_VIRTUAL - -// Implementation -public: - void SetControlPoints(int uCount, int vCount, float** pControl); - virtual ~CTerrainCtrl(); - - // Generated message map functions -protected: - void EditCell(int nRow, int nCol, UINT nChar); - BOOL GetCellRect(int nRow, int nCol, LPRECT pRect); - BOOL GetCellRect(CELLID cell, LPRECT pRect); - BOOL GetCellOrigin(int nRow, int nCol, LPPOINT p); - BOOL GetCellOrigin(CELLID cell, LPPOINT p); - BOOL RedrawCell(int nRow, int nCol, CDC* pDC = NULL); - BOOL RedrawCell(CELLID cell, CDC* pDC = NULL); - BOOL IsValid(CELLID cell); - BOOL IsValid(int nRow, int nCol); - BOOL IsCellVisible(CELLID cell); - BOOL IsCellVisible(int nRow, int nCol); - void EnsureVisible(CELLID cell); - void EnsureVisible(int nRow, int nCol); - void SetFocusCell(CELLID cell); - void SetFocusCell(int nRow, int nCol); - BOOL SetRowCount(int nRows); - BOOL SetColumnCount(int nCols); - - CELLID GetCellFromPt(CPoint point, BOOL bAllowFixedCellCheck = TRUE); - CELLID GetTopleftNonFixedCell(); - BOOL RegisterWindowClass(); - - void OnDraw(CDC* pDC); - void EraseBkgnd(CDC* pDC); - BOOL DrawCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk = FALSE); - BOOL DrawFixedCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk = FALSE); - - void ResetScrollBars(); - int GetScrollPos32(int nBar, BOOL bGetTrackPos = FALSE); - BOOL SetScrollPos32(int nBar, int nPos, BOOL bRedraw = TRUE); - - CFont m_Font; - - COLORREF m_crFixedBkColour; - COLORREF m_crFixedTextColour; - COLORREF m_crTextBkColour; - -// m_crTextColour, m_crGridColour; - - int m_nRows; - int m_nCols; - int m_nVScrollMax; - int m_nHScrollMax; - - float** m_pControl; - - int m_MouseMode; - - CELLID m_idCurrentCell; - CELLID m_LeftClickDownCell; - CPoint m_LeftClickDownPoint; - - // Cell data - CArray m_RowData; - - //{{AFX_MSG(CTerrainCtrl) - afx_msg void OnPaint(); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg UINT OnGetDlgCode(); - afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); - afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); - afx_msg void OnLButtonDown(UINT nFlags, CPoint point); - afx_msg void OnLButtonUp(UINT nFlags, CPoint point); - afx_msg void OnMouseMove(UINT nFlags, CPoint point); - afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); - afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); - //}}AFX_MSG - afx_msg LRESULT OnGetFont(WPARAM hFont, LPARAM lParam); - afx_msg LRESULT OnEditClosed(WPARAM hFont, LPARAM lParam); - - DECLARE_MESSAGE_MAP() - - enum eMouseModes { MOUSE_NOTHING, MOUSE_SELECT_ALL, MOUSE_SELECT_COL, MOUSE_SELECT_ROW, - MOUSE_SELECT_CELLS, MOUSE_SCROLLING_CELLS, - MOUSE_PREPARE_EDIT, MOUSE_PREPARE_DRAG, MOUSE_DRAGGING }; -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_TERRCTRL_H__15B2D2A1_D2FF_11D2_8204_EEB0809D9016__INCLUDED_)