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

📄 getnbox.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 2 页
字号:
	}
	void	OnSetFocusFrom(Control ctrl)
	{
		m_dataRange.OnSetFocus(true);
	}
	void	OnSetFocusTo(Control ctrl)
	{
		m_dataRange.OnSetFocus(false);
	}
	void	OnKillFocusFrom(Control ctrl)
	{
		m_dataRange.OnKillFocus(true);
	}
	void	OnKillFocusTo(Control ctrl)
	{
		m_dataRange.OnKillFocus(false);
	}
	void	OnFullRange(Control ctrl)
	{
		m_dataRange.OnSetFullRange();
	}
	///////////// end Range Control related ////////////

	

	//////////// local utilities/helper functions
private:

	// return -1, 0 1, -1 if not applicable
	int	getShiftShowStatus()
	{
		if(m_strClassName.IsEmpty())
			return -1;
		
		return shiftShow();
	}
	void updateShiftShowStatus()
	{
		if(!m_strClassName.IsEmpty() && m_nShiftShowCheck >= 0)
			shiftShow(false, m_nShiftShowCheck);
	}
	bool shiftShow(bool bGet = true, bool bVal = false)
	{
		Registry reg(HKEY_CURRENT_USER);
		string strKey = GetRegKey() + "\\Classes\\" + m_strClassName;
		string strVal = "GUI"; // we use just one dword
		DWORD	dwShiftShowBit = 0x00000001;
		
		DWORD dwVal = 0;
		if(bGet)
		{
			reg.GetValue(strKey, strVal, dwVal);
			return (dwVal & dwShiftShowBit)? true:false;
		}
		else
		{
			reg.GetValue(strKey, strVal, dwVal);
			if(bVal)
				dwVal |= dwShiftShowBit;
			else
				dwVal &=~dwShiftShowBit;
			
			reg.SetValue(strKey, strVal, dwVal);
		}
		return true;
	}
	void	saveDefaultGUI()
	{
		if(!m_strClassName.IsEmpty())
			save_default_settings(m_input_tr, m_strClassName, SETTINGS_GUI);
	}
	
	bool isUseCurveRange() { return m_strCuveNode.IsEmpty()? false:true;}
	
	PEVENT_FUNC getEventHandler()
	{
		PEVENT_FUNC temp_pEventFunc = m_pEventFunc;// wait until we can call member function pointer directly
		TreeNode trNode = THE_TREE_NODE;

		if(trNode)
			return temp_pEventFunc;
		
		return NULL;
	}
	PAPPLY_FUNC getApplyFunction()
	{
		PAPPLY_FUNC temp_pApplyFunc = m_pApplyFunc;// wait until we can call member function pointer directly
		TreeNode trNode = THE_TREE_NODE;

		if(trNode)
			return temp_pApplyFunc;
		
		return NULL;
	}
	
	void enableButton(uint nBtnID, bool bEnable)
	{
		Control cBtn = GetItem(nBtnID);
		cBtn.Enable = bEnable;
	}
	void resizeDlgToFit()
	{
		uint nBtnIds[] = {
			IDC_APPLY,
			IDCANCEL,
			IDOK,
			0};
	
		uint nBtnNoApply[] = {
			IDCANCEL,
			IDOK,
			0};
		
		if(m_pApplyFunc)	
			resizeDialog(nBtnIds);
		else
			resizeDialog(nBtnNoApply);
	}
	// assume grid as top control underneath a caption and other controls follows in a row
	// we assume the caption top position is unchanged
	void resizeDialog(uint* pIntIDs, int nCaptionID = IDC_PARAMS_DESCRIPTION)
	{
		int nEdge = GetControlGap();
		int nGap = 8;
		int nyCaptionAndEdge = nEdge;
				
		int nxGrid, nyGrid;
		
		m_treeEditCntrl.GetGridSize(nxGrid, nyGrid);
			
		RECT r1, r2;
		Button btn = GetItem(pIntIDs[0]);
		btn.GetWindowRect(&r1);
		int nBtnWidth = r1.right - r1.left;
		int nBtnHeight= r1.bottom - r1.top;
		
		// next we caculate the size of dialog
		int cx = nEdge + nxGrid + nEdge;
		
		m_wndDlg.GetClientRect(&r1);
		int nOldDlgW = r1.right - r1.left;
		int nOldDlgH = (r1.bottom - r1.top);
		if(cx < nOldDlgW)
			cx = nOldDlgW;
	
		Control cCaption = GetItem(nCaptionID);
		if(cCaption)
		{
			cCaption.GetWindowRect(&r2);
			m_wndDlg.ScreenToClient(&r2);
			int nyCaption = r2.top;
			if(cCaption.Visible)
				nyCaption = r2.bottom;
				
			r2.left = nEdge;
			r2.right = cx - nEdge;
			cCaption.MoveWindow(&r2);
			nyCaptionAndEdge = nyCaption + nEdge;
		}
		//---- CPY 5/22/03 v7.0589 SHIFT_SHOW_FOR_CLASSES
		int nCheckBoxes = 0;
		int nCheckBoxHeight = 0;
		if(m_chkShiftShow.Visible)
		{
			RECT rCheckBox;
			m_chkShiftShow.GetWindowRect(&rCheckBox);
			nCheckBoxHeight = rCheckBox.bottom - rCheckBox.top;
			nCheckBoxes = nEdge + nCheckBoxHeight + nEdge; 
		}
		//----
		int cy = nyCaptionAndEdge + nyGrid + nEdge + nCheckBoxes + nBtnHeight + nEdge;
		// we need to resize the dialog
		int nxDiff = cx - nOldDlgW;
		int nyDiff = cy - nOldDlgH;
		m_wndDlg.GetWindowRect(&r1);
		r1.right += nxDiff;
		r1.bottom += nyDiff;
		m_wndDlg.MoveWindow(&r1);
		
		
		r2.top = nyCaptionAndEdge;
		r2.left = nEdge;
		r2.right = cx - nEdge;
		r2.bottom = cy - 2*nEdge - nBtnHeight - nCheckBoxes;
		
		m_treeEditCntrl.MoveWindow(r2);	

		//---- CPY 5/22/03 v7.0589 SHIFT_SHOW_FOR_CLASSES
		if(nCheckBoxHeight)
		{
			r2.top = nyCaptionAndEdge + nyGrid + nEdge;
			r2.left = nEdge;
			r2.right = cx - nEdge;
			r2.bottom = r2.top + nCheckBoxHeight;
			m_chkShiftShow.MoveWindow(&r2);
		}
		//---- end 

		// now move the buttons to all along the bottom
		ArrangeControlsRightLeft(pIntIDs, cx, r2.bottom + nEdge);
	}
};


// has to write own function as GetTokens
static string get_combo_str_by_index(int nIndex, LPCSTR lpcsz)
{
	int nPos = 0;
	if(lpcsz[0] == '|')
		lpcsz++; // skip, usually should not be allowed
	
	string strSrc = lpcsz;
	return strSrc.GetToken(nIndex, '|');
}

static string get_node_val_as_str(TreeNode& trNode)
{
	string strTemp;
	int	nIndex;
	trNode.GetAttribute(STR_COMBO_ATTRIB, strTemp);
	nIndex = atoi(trNode.Text);
	return get_combo_str_by_index(nIndex, strTemp);
}

static string get_node_combo_str(TreeNode& trNode)
{
	string strTemp;
	// only some node type can support combo
	int nNodeID = trNode.ID;
	if(TRGP_ENUM_COMBO == nNodeID || TRGP_STR_LIST == nNodeID || TRGP_RANGE == nNodeID || TRGP_STR_BUTTON == nNodeID)
	{
		trNode.GetAttribute(STR_COMBO_ATTRIB, strTemp);
	}

	// the following code is used for customized list with numeric value on each entry
	// we don't need this for now
	/*
	switch(trNode.ID)
	{
	case TRGP_STR_LIST:
		break;
	default:
		return strTemp;
	}
	//TRGP_STR_LIST
	StringArray sa;
	int nItems = strTemp.GetTokens(sa, '|');
	if(nItems > 1)
	{
		int nIndex = 0;
		strTemp = "";
		for(int ii = 0; ii < nItems; ii++)
		{
			strTemp += "#" + nIndex++ + ";";
			strTemp += sa[ii];
			if(ii < nItems - 1)
				strTemp += "|";
		}
	}
	//out_str(strTemp);
	*/
	return strTemp;
}

static bool is_node_need_numeric_validation(TreeNode& trNode)
{
	switch(trNode.ID)
	{
	case TRGP_ENUM_COMBO:
		{
			string str = get_node_combo_str(trNode);
			if(str[0] != '|')
				return false;
		}
		// fall through
	case TRGP_DOUBLE:
		return true;
	}
	return false;
}




static void SetRect(RECT& rect, int nLeft, int nTop, int nRight, int nBottom)
{
	rect.left = nLeft;
	rect.top = nTop;
	rect.right = nRight;
	rect.bottom = nBottom;
}



// global functin for displaying the tree
bool out_params(TreeNode& tr)
{
	TreeNode cNode = tr.FirstNode;
	
	if(cNode == NULL)
		return false;
	
	string strLabel;
	string strVal;
	
	while(cNode)
	{
		//--- 
		if(!cNode.GetAttribute(STR_LABEL_ATTRIB, strLabel))
			strLabel = cNode.tagName;
		
		strVal = cNode.Text;
		
		printf("%s->%s\n", strLabel, strVal);
		
		//----
		cNode = cNode.NextNode;
	}
	return true;
}

//nSetShow = 0,1 will force all child nodes to set Show to same
static void tree_get_shows(TreeNode& tr, vector<int>& vv, int nSetShow = -1)
{
	int nVal;
	foreach(TreeNode cNode in tr.Children)
	{
		if(nSetShow >= 0)
			cNode.Show = nSetShow;
		
		nVal = cNode.Show;
		vv.Add(nVal);
		if(cNode.GetNodeCount() > 0) // branch node
			tree_get_shows(cNode, vv, nVal);
	}
}

//nSetEnable = 0,1 will force all child nodes to set Enable to same
static void tree_get_enables(TreeNode& tr, vector<int>& vv, int nSetEnable = -1)
{
	int nVal;
	foreach(TreeNode cNode in tr.Children)
	{
		if(nSetEnable >= 0)
			cNode.Enable = nSetEnable;
		
		nVal = cNode.Enable;
		vv.Add(nVal);
		if(cNode.GetNodeCount() > 0) // branch node
			tree_get_enables(cNode, vv, nVal);
	}
}

static void out_v(LPCSTR lpcsz, vector<int>& vv)
{
	//printf("%s:", lpcsz);
	for(int ii = 0; ii < vv.GetSize(); ii++)
		printf(" %d,", vv[ii]);
	
	out_str("");
}
		
static bool is_same(const vector<int>& v1, const vector<int>& v2)
{
	//----
	//out_v("New", v1);
	//out_v("Old", v2);
	//----
	
	uint nSize = v1.GetSize();
	if(nSize != v2.GetSize())
		return false;
	
	for(int ii = 0; ii < nSize; ii++)
	{
		if(v1[ii] != v2[ii])
			return false;
	}
	return true;
}

	

//--------------------- vsFlex routines that might be used in other dialogs --------


int TwipsToPixels(Window wndDlg, int twips, bool bX=true)
{
	DeviceContext dc = wndDlg.GetDC();
	
	double vv = 0.5 + dc.GetDeviceCaps(bX? LOGPIXELSX : LOGPIXELSY) * (double)twips / 1440.0;
	return vv;
}





/////////////////////////////////////////
// utilities for GetNBox handling
// convert i1 0-offset and i2 to notation "12 - 34" that is one offset and contains at least 1 point
// pass in values of -1 to indicate Auto
string range_to_str(int i1, int i2)
{
	string strAuto = "Auto";
	string str1 = (i1+1);
	string str2 = i2;

	if(i1<0)
		str1 = strAuto;
	if(i2<0)
		str2 = strAuto;
	
	return str1 + " - " + str2;
}

static int atoi_check_auto(const string& str)
{
	if(str.IsEmpty())
		return -1;
	str.TrimLeft();
	if(str[0] >= '0' && str[0] <= '9')
		return atoi(str);
	
	return -1;
}

bool str_to_range(LPCSTR lpcszRange, int& i1, int& i2)
{
	string strTemp = lpcszRange;
	int nPos = strTemp.Find('-');
	i1 = i2 = -1;
	if(nPos < 0)
		return false;
	
	i1 = atoi_check_auto(strTemp.Left(nPos));
	i2 = atoi_check_auto(strTemp.Mid(nPos+1));
	return true;
}

⌨️ 快捷键说明

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