// OffsetPropDlg.cpp : implementation file // #include "stdafx.h" #include "imgconvw.h" #include "OffsetPropDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // COffsetPropDlg dialog COffsetPropDlg::COffsetPropDlg(LImageViewer * pImageViewer, CWnd* pParent /*=NULL*/) : CDialog(COffsetPropDlg::IDD, pParent) { m_pImageViewer = pImageViewer; memset(&m_OffsetProp, 0, sizeof(DISPOFFSETACTIONPROPS)); m_OffsetProp.DispContainerActionProps.uStructSize = sizeof(DISPOFFSETACTIONPROPS); //{{AFX_DATA_INIT(COffsetPropDlg) m_uSensitivity = 0; m_bCircleMouse = FALSE; //}}AFX_DATA_INIT } void COffsetPropDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(COffsetPropDlg) DDX_Control(pDX, IDEDT_OFFSET_Y, m_edtYOffset); DDX_Control(pDX, IDEDT_OFFSET_X, m_edtXOffset); DDX_Control(pDX, IDEDT_OFFSET_CELLINDEX, m_edtCellIndex); DDX_Control(pDX, IDCMB_OFFSET_UPKEY, m_cmbUpKey); DDX_Control(pDX, IDCMB_OFFSET_DOWNKEY, m_cmbDownKey); DDX_Control(pDX, IDBTN_OFFSET_CUR, m_ActionCursor); DDX_Control(pDX, IDCMB_OFFSET_CELLINDEX, m_cmbCell); DDX_Control(pDX, IDCMB_OFFSET_MOD, m_cmbModifier); DDX_Control(pDX, IDCMB_OFFSET_RIGHTKEY, m_cmbRightKey); DDX_Control(pDX, IDCMB_OFFSET_LEFTKEY, m_cmbLeftKey); DDX_Text(pDX, IDEDT_OFFSET_SEN, m_uSensitivity); DDX_Check(pDX, IDCHK_OFFSET_CIRCLE, m_bCircleMouse); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(COffsetPropDlg, CDialog) //{{AFX_MSG_MAP(COffsetPropDlg) ON_BN_CLICKED(IDBTN_OFFSET_CUR, OnOffsetCur) ON_BN_CLICKED(IDAPPLY, OnApply) ON_EN_CHANGE(IDEDT_OFFSET_CELLINDEX, OnChangeOffsetCellIndex) ON_CBN_SELCHANGE(IDCMB_OFFSET_CELLINDEX, OnSelchangeOffsetCellIndex) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // COffsetPropDlg message handlers BOOL COffsetPropDlg::OnInitDialog() { CDialog::OnInitDialog(); L_INT nIndex; L_INT nCount =0; CString strVal; nCount = (m_pImageViewer ? m_pImageViewer->GetCellCount(0) : 0); for (nIndex = 0; nIndex < nCount; nIndex++) { if(m_pImageViewer) { if (m_pImageViewer->IsCellSelected(nIndex,0)) break; } } if (nIndex == nCount) nIndex = -1; m_pImageViewer->GetActionProperties(CONTAINER_ACTION_OFFSET, nIndex, 0, (LONG)&m_OffsetProp, CONTAINER_ACTION_CONTAINERLEVEL); m_pImageViewer->GetActionProperties(CONTAINER_ACTION_OFFSET, nIndex, 0, (LONG)&m_OffsetProp, CONTAINER_ACTION_CELLLEVEL); nCount = m_pImageViewer->GetCellCount(0); if (nCount) { strVal.Format(TEXT("%d"), max(0, nIndex)); m_edtCellIndex.SetWindowText(strVal); strVal.Format(TEXT("%d"), m_OffsetProp.nXOffset); m_edtXOffset.SetWindowText(strVal); strVal.Format(TEXT("%d"), m_OffsetProp.nXOffset); m_edtYOffset.SetWindowText(strVal); m_edtCellIndex.SetNumericEditBox(0, nCount - 1, 1, 0, 0); } m_cmbCell.AddString(TEXT("None")); m_cmbCell.AddString(TEXT("All")); m_cmbCell.AddString(TEXT("Custom")); m_cmbCell.SetCurSel(0); if(!nCount) { m_cmbCell.EnableWindow(FALSE); } m_edtCellIndex.EnableWindow(FALSE); m_edtXOffset.EnableWindow(FALSE); m_edtYOffset.EnableWindow(FALSE); CImgConVwApp::AddSupString(&m_cmbModifier); CImgConVwApp::AddVirtualKeyString(&m_cmbUpKey); CImgConVwApp::AddVirtualKeyString(&m_cmbDownKey); CImgConVwApp::AddVirtualKeyString(&m_cmbLeftKey); CImgConVwApp::AddVirtualKeyString(&m_cmbRightKey); GetKeyboardAction(&m_cmbUpKey, &m_cmbModifier, CONTAINER_ACTION_OFFSET, CONTAINER_MOUSEMOVE_UP); GetKeyboardAction(&m_cmbLeftKey, &m_cmbModifier, CONTAINER_ACTION_OFFSET, CONTAINER_MOUSEMOVE_LEFT); GetKeyboardAction(&m_cmbRightKey, &m_cmbModifier, CONTAINER_ACTION_OFFSET, CONTAINER_MOUSEMOVE_RIGHT); GetKeyboardAction(&m_cmbDownKey, &m_cmbModifier, CONTAINER_ACTION_OFFSET, CONTAINER_MOUSEMOVE_DOWN); m_uSensitivity = m_OffsetProp.DispContainerActionProps.nChange; m_bCircleMouse = m_OffsetProp.DispContainerActionProps.bCircularMouseMove; m_ActionCursor.SetIcon(m_OffsetProp.DispContainerActionProps.hCursor ? m_OffsetProp.DispContainerActionProps.hCursor : LoadCursor(NULL, IDC_ARROW)); m_hOldCursor = m_OffsetProp.DispContainerActionProps.hCursor; m_edtXOffset.SetNumericEditBox(-1000000, 1000000, 1, 0, 0); m_edtYOffset.SetNumericEditBox(-1000000, 1000000, 1, 0, 0); UpdateData(FALSE); return TRUE; } L_VOID COffsetPropDlg::GetKeyboardAction(CComboBox * pVComboBox, CComboBox * pModComboBox, L_INT nAction, L_INT nMouseDirection) { L_UINT uVk, uModifier; m_pImageViewer->GetKeyboardAction(nAction, nMouseDirection, &uVk, &uModifier, 0); for(int i=0;i< pVComboBox->GetCount(); ++i) { if(pVComboBox->GetItemData(i) == uVk) { pVComboBox->SetCurSel(i); break; } } pModComboBox->SetCurSel(min(3, uModifier)); } int COffsetPropDlg::GetIconFileName(L_TCHAR * m_FileName) { L_INT nRet; OPENFILENAME OpenFileName; memset(&OpenFileName, 0, sizeof(OPENFILENAME)); memset(m_FileName, 0, MAX_PATH * sizeof(TCHAR)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.lpstrFilter = TEXT("Cursors(*.cur)\0 *.cur"); OpenFileName.nMaxCustFilter = 12; OpenFileName.hwndOwner = this->GetSafeHwnd(); OpenFileName.lpstrTitle = TEXT("Open a File"); OpenFileName.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT; OpenFileName.lpstrFile = m_FileName; OpenFileName.nMaxFile = MAX_PATH; nRet = GetOpenFileName(&OpenFileName); return nRet; } void COffsetPropDlg::OnOffsetCur() { TCHAR strFileName[MAX_PATH]; if(GetIconFileName(strFileName)) { m_ActionCursor.SetCursor(LoadCursorFromFile(strFileName)); } } void COffsetPropDlg::OnOK() { OnApply(); CDialog::OnOK(); } void COffsetPropDlg::OnApply() { CString strVal; L_INT nRet; L_INT nVk; L_UINT uState = (8 >> (4 - m_cmbModifier.GetCurSel())); L_INT nIndex=0; L_INT nSubIndex=0; UpdateData(TRUE); m_OffsetProp.DispContainerActionProps.bCircularMouseMove = m_bCircleMouse; m_OffsetProp.DispContainerActionProps.nChange = m_uSensitivity; m_OffsetProp.DispContainerActionProps.hCursor = m_ActionCursor.GetIcon(); nRet = m_pImageViewer->SetActionProperties(CONTAINER_ACTION_OFFSET, 0, 0, (LONG)&m_OffsetProp, CONTAINER_ACTION_CONTAINERLEVEL); nRet = m_cmbCell.GetCurSel(); if (nRet != 0) { m_edtXOffset.GetWindowText(strVal); m_OffsetProp.nXOffset = _ttoi(strVal); m_edtYOffset.GetWindowText(strVal); m_OffsetProp.nYOffset = _ttoi(strVal); if (nRet == 1) { nIndex = -1; } else { m_edtCellIndex.GetWindowText(strVal); nIndex = _ttoi(strVal); } nRet = m_pImageViewer->SetActionProperties(CONTAINER_ACTION_OFFSET, nIndex, 0, (LONG)&m_OffsetProp, CONTAINER_ACTION_CELLLEVEL); } nVk = CImgConVwApp::GetVirtualKey(&m_cmbUpKey); if (nVk != 0) m_pImageViewer->SetKeyboardAction(CONTAINER_ACTION_OFFSET, CONTAINER_MOUSEMOVE_UP, nVk, uState); nVk = CImgConVwApp::GetVirtualKey(&m_cmbDownKey); if (nVk != 0) m_pImageViewer->SetKeyboardAction(CONTAINER_ACTION_OFFSET, CONTAINER_MOUSEMOVE_DOWN, nVk, uState); nVk = CImgConVwApp::GetVirtualKey(&m_cmbLeftKey); if (nVk != 0) m_pImageViewer->SetKeyboardAction(CONTAINER_ACTION_OFFSET, CONTAINER_MOUSEMOVE_LEFT, nVk, uState); nVk = CImgConVwApp::GetVirtualKey(&m_cmbRightKey); if (nVk != 0) m_pImageViewer->SetKeyboardAction(CONTAINER_ACTION_OFFSET, CONTAINER_MOUSEMOVE_RIGHT, nVk, uState); UpdateData(FALSE); } void COffsetPropDlg::OnChangeOffsetCellIndex() { L_INT nCellIndex =0, nSubCellIndex =0; CString strVal; m_edtCellIndex.GetWindowText(strVal); nCellIndex = _ttoi(strVal); m_pImageViewer->GetActionProperties(CONTAINER_ACTION_ALPHA, nCellIndex, nSubCellIndex, (LONG)&m_OffsetProp, CONTAINER_ACTION_CELLLEVEL); strVal.Format(TEXT("%d"), m_OffsetProp.nXOffset); m_edtXOffset.SetWindowText(strVal); strVal.Format(TEXT("%d"), m_OffsetProp.nYOffset); m_edtYOffset.SetWindowText(strVal); UpdateData(FALSE); } void COffsetPropDlg::OnSelchangeOffsetCellIndex() { L_INT nRet = m_cmbCell.GetCurSel(); m_edtCellIndex.EnableWindow(nRet == 2); m_edtXOffset.EnableWindow(nRet != 0); m_edtYOffset.EnableWindow(nRet != 0); }