⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getnbox.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------*
 * File Name: ParamBox.c														*
 * Creation: CPY 1/27/03														*
 * Purpose: Origin C support for a general parameters edit box					*
 * Copyright (c) OriginLab Corp.2003											*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 *	CPY 4/23/03 v7.0568 OPERATION_CLASS_NEED_TRY_AND_AUTO_UPDATE				*
 *	CPY 5/20/03 CHECK_BOX_CLICK_OUTSIDE_CHECK_TO_TOGGLE							*
 *	CPY 5/22/03 v7.0589 SHIFT_SHOW_FOR_CLASSES									*
 *	CPY 5/30/03 QA70-4577 EVENT_HANDLER_NEED_DIALOG_AND_VALUE_UPDATE			*
 *	CPY 6/11/03 QA70-4450 v7.0601 TTILE_KEY_TO_BECOME_MODLESS					*
 *	CPY 7/8/03 QA70-4796 v7.0620 GET_N_BOX_EVENT_FUNC_MOVE_WIN					*
 *	CPY 8/24/03 v7.5674 QA70-5061 ADD_DISPLAY_OPTIONS							*
 *	CPY 10/11/03 QA70-5332 HELP_CUSTOMIZED										*
 *------------------------------------------------------------------------------*/
 
////////////////////////////////////////////////////////////////////////////////////
#include <Origin.h>
//#include <Project.h>
//#include <sys_utils.h> // basic routines implemeted through Origin C, see sys_utils.c
//#include <utilities.h>
#include <Settings.h>
#include <Dialog.h>
#include <tree_utils.h>

#include <vsFlexGrid.h>
#include <GetNbox.h>
#include "Odlg.h"
#include "HelpID.h"
//#include "local.h"

#include "theme_utils.h" // some theme related utility functions, will move into separate utils file later
#include <RangeControl.h>
#include "ResizeDialog.h"
#include "TreeEditControl.h"
#include <Profiler.h>

#define THE_TREE_NODE	m_paramTree.FirstNode
enum {
	GRID_CHANGE_SHOW = 0x0001,
	GRID_CHANGE_ENABLE = 0x0002,
	GRID_CHANGE_VALUE = 0x0004,
	GRID_CHANGE_SIZE = 0x0008
};


bool GetNBox(TreeNode& tr, LPCSTR lpcszTitle, LPCSTR lpcszDescription, PAPPLY_FUNC pfn, PEVENT_FUNC pEvtFn, HWND hWndParent) //=NULL,NULL,NULL, NULL, NULL
{
	int nID = IDD_GET_N_BOX_TREE;//IDD_GET_N_BOX;
	// we have two GetNBox dialog, one support ActiveCurve with range control and the other does not
	// and the decision is coming from the tree attribute
	string strCurveNode;
	if(tr.GetAttribute(STR_ACTIVE_CURVE, strCurveNode))
		nID = IDD_GET_N_BOX_RANGE;
	else if(tr.tagName == "GetNBox")
		nID = IDD_GET_N_BOX;
		
	
	GetNBoxDlg myDlg(nID, tr, lpcszTitle, lpcszDescription, pfn, pEvtFn, strCurveNode);
	int nRet = myDlg.DoModalEx(hWndParent);
	if(IDOK == nRet)
	{
		myDlg.UpdateEditTreeNode(tr);
		return true;
	}
	return false;
}


//------------------------- utilities ----------------------


class GetNBoxDlg : public ResizeDialog
{
private:
	Tree		m_paramTree;
	TreeNode	m_input_tr; //CPY 4/23/03 v7.0568 OPERATION_CLASS_NEED_TRY_AND_AUTO_UPDATE
	PAPPLY_FUNC m_pApplyFunc;
	PEVENT_FUNC m_pEventFunc;
	bool		m_bUseTryForApply;//CPY 4/23/03 v7.0568 OPERATION_CLASS_NEED_TRY_AND_AUTO_UPDATE

	bool		m_bApply1stTime;
	string		m_strTitle;
	string		m_strDescription;
	//
	string		m_strCuveNode;
	string		m_strClassName;
	
	RangeControl m_dataRange;
	
	Button		m_chkShiftShow;
	int			m_nShiftShowCheck;
	Button		m_chkAutoUpdate;
	int			m_nDlgID;
	
	TreeEditControl		m_treeEditCntrl;
		
public:
	GetNBoxDlg(int nID, TreeNode& tr, LPCSTR lpcszTitle, LPCSTR lpcszDescription, PAPPLY_FUNC pfn, PEVENT_FUNC pEvtFn, LPCSTR lpcszCurveNode) : ResizeDialog(nID, "ODlg")
	{
		m_input_tr = tr;//CPY 4/23/03 v7.0568 OPERATION_CLASS_NEED_TRY_AND_AUTO_UPDATE
		
		m_paramTree.AddNode(tr.Clone());
	
		m_pApplyFunc = pfn;
		m_pEventFunc = pEvtFn;
		m_bApply1stTime = true;
		
		m_strTitle = lpcszTitle;
		m_strDescription = lpcszDescription;
		
		m_strCuveNode = lpcszCurveNode;
		
		m_bUseTryForApply = false;
		m_bUseTryForApply = false;
		//---  CPY 5/22/03 v7.0589 SHIFT_SHOW_FOR_CLASSES
		tr.GetAttribute(STR_CLASS_NAME, m_strClassName);
		//---
		m_nDlgID = nID; 
		//m_bIsFlatDialogDisplay = IDD_GET_N_BOX == nID? true:false;
	}
	void UpdateEditTreeNode(TreeNode& tr) { tr = m_input_tr;}
	
	
	int DoModalEx(HWND hWndParent = NULL)
	{
		InitMsgMap();// will be called from internal later
		
		DWORD dwDlgOptions = 0;
		//--- CPY 7/8/03 QA70-4796 v7.0620 GET_N_BOX_EVENT_FUNC_MOVE_WIN
		if(hWndParent)
			dwDlgOptions |= DLG_NO_DEFAULT_REPOSITION;
		//---
			
		
		if(isUseCurveRange())
		{
			TreeNode trCurve = THE_TREE_NODE.GetNode(m_strCuveNode);
			if(trCurve)
			{
				TreeNode trCurveOnMain = m_paramTree.AddNode(m_strCuveNode);
				trCurveOnMain.Replace(trCurve.Clone());
				THE_TREE_NODE.RemoveChild(m_strCuveNode); // to be consistent, so we will always add it back later
				string strYdata = trCurveOnMain.Range1.Ydata.strVal;
				string strXdata = trCurveOnMain.Range1.Xdata.strVal;
				Curve	cuv(strXdata, strYdata);
				m_dataRange.InitRange(cuv, trCurveOnMain, false);
			}
			else
			{
				trCurve = m_paramTree.AddNode(m_strCuveNode);
				m_dataRange.InitRange(Project.ActiveCurveBase(), trCurve);
			}
			//dwDlgOptions |= DLG_MODAL_WITH_KEY;//---- CPY 6/11/03 QA70-4450 v7.0601 TTILE_KEY_TO_BECOME_MODLESS
		}
		
		//CPY, we can only use the info from Construct
		//load_default_getnbox_gui(m_input_tr, m_strClassName);
		
		int nRet = DoModal(hWndParent, dwDlgOptions);
		if(nRet != IDCANCEL)
		{
			m_input_tr.Replace(THE_TREE_NODE);
				
			if(isUseCurveRange())
			{
				TreeNode trCurve = m_dataRange.GetCurveRange();
				m_input_tr.AddNode(trCurve.Clone());
			}
			updateShiftShowStatus();
			saveDefaultGUI();
		}
		// the following are no longer needed since we are no longer static
		//s_paramTree.Reset();
		//s_pApplyFunc = NULL;
		//s_pEventFunc = NULL;
		return nRet;
	}
		

//#define THE_GRID MyDlg.GetItem(IDC_PARAMS_GRID).GetActiveXControl()
protected:
	
EVENTS_BEGIN
	ON_INIT(OnInitDialog) 
	ON_DESTROY(OnDestroy)
	ON_BN_CLICKED(IDC_APPLY, OnApplyButton)
	ON_EVENT(EN_SETFOCUS, IDC_PARAMS_GRID, OnSetFocus)
	ON_USER_MSG(WM_USER_ON_CHILD_KILL_FOCUS, OnEditorKillFocus)
	ON_USER_MSG(WM_USER_RECONSTRUCT, OnReconstructGrid)
	//ON_SIZE(OnResize)
	ON_GRID_BEFORE_EDIT(IDC_PARAMS_GRID, OnBeforeEdit)
	ON_GRID_VALIDATE_EDIT(IDC_PARAMS_GRID, OnValidateEdit)
	ON_GRID_AFTER_EDIT(IDC_PARAMS_GRID, OnAfterEdit)
	ON_GRID_ROW_COL_CHANGE(IDC_PARAMS_GRID, OnRowColChange)
	ON_GRID_COMBO_CLOSEUP(IDC_PARAMS_GRID, OnComboCloseUp)
	ON_GRID_BEFORE_MOUSE_DOWN(IDC_PARAMS_GRID, OnBeforeMouseDown)
	ON_GRID_DRAW_CELL(IDC_PARAMS_GRID, OnDrawCell)
	ON_GRID_BUTTON_CLICK(IDC_PARAMS_GRID, OnButtonClick)
	ON_GRID_AFTER_COLLAPSE(IDC_PARAMS_GRID, OnAfterCollapse)
	
	ON_CLICK_KEY(OnKey) //CPY 6/11/03 QA70-4450 v7.0601 TTILE_KEY_TO_BECOME_MODLESS

	ON_HELPINFO(OnHelp) //CPY 10/11/03 QA70-5332 HELP_CUSTOMIZED
	
	///////////// Range Control related ////////////
	ON_SLIDE_BEFORE(IDC_PARAMS_RANGE_SLIDER, OnRangeSlide)
	ON_EVENT(EN_SETFOCUS, IDC_PARAMS_X_FROM, OnSetFocusFrom)
	ON_EVENT(EN_SETFOCUS, IDC_PARAMS_X_TO, OnSetFocusTo)
	ON_EVENT(EN_KILLFOCUS, IDC_PARAMS_X_FROM, OnKillFocusFrom)
	ON_EVENT(EN_KILLFOCUS, IDC_PARAMS_X_TO, OnKillFocusTo)
	ON_BN_CLICKED(IDC_PARAMS_RANGE_FULL, OnFullRange)
	///////////// end Range Control related ////////////
EVENTS_END

//------------ Event Handlers ------------------------
//private:
	BOOL OnInitDialog()
	{
		waitCursor junk;
		//Profiler jj;
		
		ResizeDialog::OnInitDialog();
		
		if(isUseCurveRange())
			m_dataRange.InitControls(*this, 
			IDC_PARAMS_RANGE_FROM, IDC_PARAMS_RANGE_TO, IDC_PARAMS_RANGE_SLIDER, 
			IDC_PARAMS_RANGE_FULL,IDC_PARAMS_X_FROM, IDC_PARAMS_X_TO, IDC_PARAMS_DATASET );

		//---  CPY 5/22/03 v7.0589 SHIFT_SHOW_FOR_CLASSES
		m_chkShiftShow = GetItem(IDC_PARAMS_SHIFTSHOW);
//		m_chkAutoUpdate = GetItem(
		int nIsShiftShow = getShiftShowStatus();
		if(nIsShiftShow >= 0)
		{
			m_chkShiftShow.Visible = true;
			m_chkShiftShow.Check = nIsShiftShow;
		}
		//--- end SHIFT_SHOW_FOR_CLASSES
		
		
		//check if we need Outline tree
		int nSubBranchs = 0;
		tree_count_items(THE_TREE_NODE, &nSubBranchs);
		
		PEVENT_FUNC pfn = getEventHandler();
		m_treeEditCntrl.Init(IDC_PARAMS_GRID, IDD_GET_N_BOX == m_nDlgID? true:false, nSubBranchs>0? true:false, pfn, *this);
		
		// if there is event handler, we will need to call that too
		if(pfn)
		{
			int nCntrlTypes[] = {
				ONODETYPE_CHECKBOX,
				ONODETYPE_DROPDOWN_NUMERIC_FLOAT,
				ONODETYPE_DROPLIST_STRINGS,
				ONODETYPE_DROPLIST_COLORS,
				0
			};
			int ii = 0;			
			while(nCntrlTypes[ii] > 0)
			{
				//m_pEventFunc(THE_TREE_NODE, -1, nCntrlTypes[ii]);
				pfn(THE_TREE_NODE, -1, nCntrlTypes[ii], *this); //CPY 5/30/03 QA70-4577 EVENT_HANDLER_NEED_DIALOG_AND_VALUE_UPDATE, added *this
				ii++;
			}
		}

		int nCaptionID = 0;
		Control cCaption = GetItem(IDC_PARAMS_DESCRIPTION);
		if(!m_strDescription.IsEmpty())
		{
			nCaptionID = IDC_PARAMS_DESCRIPTION;
			cCaption.Text = m_strDescription;
			cCaption.Visible = true;
		}
		else
			cCaption.Visible = false;		
			
		Button cApplyBtn = GetItem(IDC_APPLY);
		m_bUseTryForApply = false;
		if(m_pApplyFunc)
		{
			//CPY 4/23/03 v7.0568 OPERATION_CLASS_NEED_TRY_AND_AUTO_UPDATE
			string strApplyButtonText;
			if(THE_TREE_NODE.GetAttribute(STR_OPERATION_TRY, strApplyButtonText))
			{
				m_bUseTryForApply = true;
				cApplyBtn.Text = strApplyButtonText;
			}
		}
		else
		{
			cApplyBtn.Visible = false;
		}
		
		m_treeEditCntrl.Update(THE_TREE_NODE, true, true);
		
		enableButton(IDC_APPLY, m_pApplyFunc? true:false);
		if(!m_strTitle.IsEmpty())
			m_wndDlg.Text = m_strTitle;
		
		resizeDlgToFit();
		return true;
	}
	
	//----- CPY 10/11/03 QA70-5332 HELP_CUSTOMIZED
	BOOL OnHelp(int &nHelpID, int nIdCtrlFocus)
	{
		/*
		PEVENT_FUNC pfn = getEventHandler();
		if(pfn)
		{
			pfn(THE_TREE_NODE, -2, -1, *this); //CPY 5/30/03 QA70-4577 EVENT_HANDLER_NEED_DIALOG_AND_VALUE_UPDATE, added *this
		}
		*/
		return FALSE; // do no call default help
	}
	//----- end QA70-5332
	
	BOOL OnDestroy(void)
	{
		m_treeEditCntrl.OnDestroy();
		m_nShiftShowCheck = m_chkShiftShow.Visible? m_chkShiftShow.Check : -1;
		return true;
	}

	BOOL OnApplyButton(Control cntrl)
	{
		PAPPLY_FUNC pfn = getApplyFunction();

		if(pfn)
		{
			//---- CPY 4/23/03 v7.0568 OPERATION_CLASS_NEED_TRY_AND_AUTO_UPDATE
			//bool bResult = s_pApplyFunc(THE_TREE_NODE);
			if(m_bUseTryForApply) // for Operation class Try case, use can still Cancel and can still OK
			{
				m_input_tr.Replace(THE_TREE_NODE);		
				pfn(m_input_tr); // must pass original treenode for operation to get_parent to get real tree
				return TRUE;
			}
			else
				pfn(THE_TREE_NODE);	
			//---- end OPERATION_CLASS_NEED_TRY_AND_AUTO_UPDATE
			
			enableButton(IDOK, false); // already apply, no need to do OK
			if(m_bApply1stTime)
			{
				Button cBtn = GetItem(IDCANCEL);
				cBtn.Text = "Close";
				m_bApply1stTime = false;
			}
		}
		return TRUE;
	}


	//------- CPY 6/11/03 QA70-4450 v7.0601 TTILE_KEY_TO_BECOME_MODLESS
	BOOL OnKey(BOOL bRollingUp)
	{
		if(!bRollingUp && isUseCurveRange())
		{
			TreeNode trInput = m_paramTree.GetNode(m_strCuveNode);
			if(trInput)
			{
				GraphPage gpg = Project.Pages();
				if(gpg)
				{
					if(trInput.Page.strVal.CompareNoCase(gpg.GetName()) == 0 )
						return TRUE;
				}
			}
			return FALSE;
		}
		return TRUE;
	}
	//------- end TTILE_KEY_TO_BECOME_MODLESS
	
	
	//------------ vcFlex Grid Event Handlers ------------
	BOOL OnSetFocus(Control cntrl)
	{
		return m_treeEditCntrl.OnSetFocus();
	}
	void OnBeforeEdit(Control cntrl, long nRow, long nCol, BOOL* pCancel)
	{		
		m_treeEditCntrl.OnBeforeEdit(nRow, nCol, pCancel);
	}
	void OnValidateEdit(Control cntrl, int nRow, int nCol, BOOL* pCancel)
	{
		m_treeEditCntrl.OnValidateEdit(nRow, nCol, pCancel);
	}
	void OnAfterEdit(Control flxControl, int nRow, int nCol)
	{
		m_treeEditCntrl.OnAfterEdit(nRow, nCol);
	}
	void OnButtonClick(Control cntrl, int nRow, int nCol)
	{
		m_treeEditCntrl.OnButtonClick(nRow, nCol);
	}
	void OnAfterCollapse(Control cntrl, int nRow, short nState)
	{
		if(m_treeEditCntrl.IsResizeOnCollapse(nRow, nState))	//----CPY 8/24/03 v7.5674 QA70-5061 ADD_DISPLAY_OPTIONS
			resizeDlgToFit();
	}
	void OnRowColChange(Control cntrl)
	{
		m_treeEditCntrl.OnRowColChange();
	}	
	void OnDrawCell(Control cntrl, UINT hDC, int nRow, int nCol, int nLeft, int nTop, int nRight, int nBottom, BOOL* pDone)
	{
		m_treeEditCntrl.OnDrawCell(hDC, nRow, nCol, nLeft, nTop, nRight, nBottom, pDone);
	}
	void OnComboCloseUp(Control cntrl, int nRow, int nCol, BOOL* pFinishEdit)
	{
		m_treeEditCntrl.OnComboCloseUp(nRow, nCol, pFinishEdit);
	}
	void OnBeforeMouseDown(Control cntrl, short nButton, short nShift, float X, float Y, BOOL* pCancel)
	{
		m_treeEditCntrl.OnBeforeMouseDown(nButton, nShift, X, Y, pCancel);
	}
	//------------ WM_USER messages ------------
	BOOL OnEditorKillFocus(uint wParam, uint lParam)
	{
		return m_treeEditCntrl.OnEditorKillFocus(wParam, lParam);
	}
	BOOL OnReconstructGrid(uint wParam, uint lParam)
	{
		if(m_treeEditCntrl.OnReconstructGrid(wParam, lParam))
			resizeDlgToFit();

		return TRUE;
	}
	
	
	
	///////////// Range Control related ////////////
	void OnRangeSlide(Control ctrl, UINT nCode, UINT nPos)
	{
		m_dataRange.OnSlide();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -