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

📄 gridcontrol.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------*
 * File Name:GridControl.h														*
 * Creation: CPY 6/12/2003														*
 * Purpose: OriginC Header file for general vsFlexGrid control					*
 * Copyright (c) Originlab Corp. 2003, 2004, 2005, 2006, 						*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 *------------------------------------------------------------------------------*/

#ifndef _GRID_CONTROL_H_
#define _GRID_CONTROL_H_

#include <vsFlexGrid.h>
#include "ResizeControl.h"

#define _DBINT(_STR, _INT)	//out_int(_STR, _INT);
#define _DBSTR(_STR)		//out_str(_STR);
#define _DBTREE(_STR)		//tree_dump(m_trEdit, _STR);

#define	SHIFT_DOWN	(GetKeyState(VK_SHIFT) < 0 )
#define CNTRL_DOWN	(GetKeyState(VK_CONTROL) < 0 ) /* restrict to vertical movement */
#define ALTER_DOWN	(GetKeyState(VK_MENU) < 0 )		/* restrict to horizontal movement */


class GridControl : public ResizeControl
{
public:
	GridControl() : ResizeControl()
	{
		_DBSTR("calling GridControl constructor");
		m_bMouseDownToggleCheck = true;//---- CPY 7/5/03 CHECK_BOX_CLICK_OUTSIDE_CHECK_TO_TOGGLE
	}
	~GridControl()
	{
		_DBSTR("calling GridControl Destructor");
	}
	void Init(int nID, Dialog& dlg)
	{
		InitControl(nID, dlg);
		Control* pCntrl = GetControl();
		if(pCntrl)
			m_flx = pCntrl->GetActiveXControl();
		
		SetFont();
		
//		m_flx.FormatString = lpcszColHeadings;
//		m_flx.Cols = nCols;
		m_flx.Rows = 1;
		m_flx.FixedRows = 1;
		
		m_flx.FixedCols = 0;//hide the Row heading
		m_flx.ExtendLastCol = true;
		
		m_nHaldGridLineWidth = m_flx.GridLineWidth/2;
		
		m_nLastRow = -1;
		m_nLastCol = -1;
	}
	bool HasRows()
	{
		int nRows = m_flx.Rows - m_flx.FixedRows;
		return nRows > 0? true:false;
	}
	// nx, ny in screen pixels
	// return false if not inside grid data area
	bool FindCell(int nx, int ny, int& nRow, int& nCol)
	{
		if(nx < 0 || ny < 0) // from keyboard
			return false;
		ScreenToClient(nx, ny);
		for(nCol = m_flx.LeftCol; nCol <= m_flx.RightCol; nCol++)
		{
			for(nRow = m_flx.TopRow; nRow <= m_flx.BottomRow; nRow++)
			{
				if(isInCell(nx, ny, nRow, nCol))
					return true;
			}
		}
		return false;
	}
	// return row number if found otherwise return -1
	int FindRow(LPCSTR lpcszRowText, int nCol = 0, bool bCaseSensitive = false, bool bFullmatch = true)
	{
		/*
		for(int nRow = m_flx.FixedRows; nRow < m_flx.Rows; nRow++)
		{
			string strTemp = m_flx.Cell(flexcpText, nRow, nCol);
			if(bCaseSensitive && strTemp.Compare(lpcszRowText) == 0)
				return nRow;
			if(!bCaseSensitive && strTemp.CompareNoCase(lpcszRowText) == 0)
				return nRow;
		}
		*/
		
		return m_flx.FindRow(lpcszRowText, m_flx.FixedRows, nCol, bCaseSensitive, bFullmatch);
	}
	int FindRow(DWORD dwData)
	{
		int nRowRet = m_flx.FindRow(dwData, m_flx.FixedRows, -1);
		if(nRowRet < 0)
		{
			for(int nRow = m_flx.FixedRows; nRow < m_flx.Rows; nRow++)
			{
				DWORD dw = m_flx.RowData(nRow);
				//printf("%d: %d\n", nRow, dw);
				if(dw == dwData)
					return nRow;
			}
		}
		return nRowRet;
	}		
	// return false if not selected
	// this function is used to obtained screen location of selected cell
	bool GetSelCell(int& nx, int& ny, int& nRow, int& nCol)
	{
		bool bRet = false;
		RECT rect;
		if(m_flx.Row >= 0 && m_flx.Col >= 0)
		{
			nRow = m_flx.Row;
			nCol = m_flx.Col;
			getCellRect(nRow, nCol, rect);
			bRet = true;
		}
		else
		{
			getCellRect(m_flx.TopRow, m_flx.LeftCol, rect);
			nRow = -1;
			nCol = -1;
		}
		nx = RECT_X(rect); nx = XTwipsToPixels(nx);
		ny = RECT_Y(rect); ny = YTwipsToPixels(ny);
		ClientToScreen(nx, ny);
		return bRet;
	}
	/////////////////////////////////////////////
	/////////////////////////////////////////////
	// return false if same location as last call
	bool GetMouseCell(int& nRow, int& nCol)
	{
		nRow = m_flx.MouseRow;
		nCol = m_flx.MouseCol;
		if(nRow == m_nLastRow && nCol == m_nLastCol)
			return false;

		m_nLastRow = nRow;
		m_nLastCol = nCol;
		return true;
	}
	bool GetMousePixel(float X, float Y, int& nRow, int& nCol, int& nx, int& ny)
	{
		nRow = m_flx.MouseRow;
		nCol = m_flx.MouseCol;
		nx = XTwipsToPixels(X);
		ny = YTwipsToPixels(Y);
		ClientToScreen(nx, ny);
		if(nRow < 0 || nCol < 0)
			return false;
		return true;
	}
	//for given pixel location, find best interpretation on grid, nx and ny both [in] and [out]
	// if ny/nx < 0, then we will need to look at grid Current position for location info
	bool ConvertPixelLocation(int& nRow, int& nCol, int& nx, int& ny)
	{
		// for now, only consider
		return false;
	}
	bool HideRow(int nRow = -1, bool bHide = true)
	{
		if(nRow < 0) // to all
		{
			for(int ii = 0; ii < m_flx.Rows; ii++)
				m_flx.RowHidden(ii) = bHide;
			
			return true;
		}
		if(nRow >= m_flx.Rows)
			return false;

		m_flx.RowHidden(nRow) = bHide;
		return true;
	}
	bool HideCol(int nCol = -1, bool bHide = true)
	{
		if(nCol < 0) // to all
		{
			for(int ii = 0; ii < m_flx.Cols; ii++)
				m_flx.ColHidden(ii) = bHide;
			
			return true;
		}
		if(nCol >= m_flx.Cols)
			return false;

		m_flx.ColHidden(nCol) = bHide;
		return true;
	}
	bool IsColHidden(int nCol)
	{
		if(nCol < 0 || nCol >= m_flx.Cols)
			return false;
		
		bool bHidden = m_flx.ColHidden(nCol);
		return bHidden;
	}
	bool IsColHeadingRow(int nRow)
	{
		return (nRow < m_flx.FixedRows)? true:false;
	}
	bool IsInGrid(int nRow, int nCol)
	{
		if(nRow < 0 || nRow >= m_flx.Rows)
			return false;
		if(nCol < 0 || nCol >= m_flx.Cols)
			return false;
		return true;
	}
	int GetRowRange(int& nRow1, int& nRow2)
	{
		nRow1 = m_flx.FixedRows;
		nRow2 = m_flx.Rows-1;
		return m_flx.Rows;
	}
	bool SetCheck(int nRow, int nCol, bool bCheck)
	{
		if(!IsInGrid(nRow, nCol))
			return false;
		m_flx.Cell(flexcpChecked, nRow, nCol) = bCheck? flexChecked: flexUnchecked;
		return true;
	}		
	bool GetCheck(int nRow, int nCol)
	{
		if(!IsInGrid(nRow, nCol))
			return false;
		
		int nVal = m_flx.Cell(flexcpChecked, nRow, nCol);
		bool bCheck = flexUnchecked == nVal? 0:1;
		return bCheck;
	}		
	DWORD GetCellData(int nRow, int nCol)
	{
		if(!IsInGrid(nRow, nCol))
			return 0;
		
		DWORD dw = m_flx.Cell(flexcpData, nRow, nCol);
		return dw;
	}
	bool SetCellData(int nRow, int nCol, DWORD dwData)
	{
		if(!IsInGrid(nRow, nCol))
			return false;
		m_flx.Cell(flexcpData, nRow, nCol) = dwData;
		return true;
	}
	string GetCell(int nRow, int nCol)
	{
		string strRet;
		if(!IsInGrid(nRow, nCol))
			return strRet;
		
		strRet = m_flx.Cell(flexcpText, nRow, nCol);
		return strRet;
	}
	bool SetCell(int nRow, int nCol, const string& str)
	{
		if(!IsInGrid(nRow, nCol))
			return false;
					
		m_flx.Cell(flexcpText, nRow, nCol) = str;
		return true;
	}
	bool SetCell(int nRow, int nCol, int nVal)
	{
		string strTemp = nVal;
		return SetCell(nRow, nCol, strTemp);
	}
	bool SetBold(int nRow, int nCol, bool bSet = true) {return SetCellState(nRow, nCol, bSet);}
	bool SetItalic(int nRow, int nCol, bool bSet = true) {return SetCellState(nRow, nCol, bSet, flexcpFontItalic);}
	bool IsItalic(int nRow, int nCol) {return IsCellState(nRow, nCol, flexcpFontItalic);}
	bool IsBold(int nRow, int nCol) {return IsCellState(nRow, nCol);}
	// nCol = -1 to set all cols, return last state of last col
	// nRow = -1 to set all rows, reutrn last state of last row
	// otherwise return last state of the specified cell
	bool SetCellState(int nRow, int nCol, bool bSet = true, int nStateType = flexcpFontBold)
	{
		if(nCol < 0)
		{
			bool bRet = false;
			for(int ii = 0; ii < m_flx.Cols; ii++)
				bRet = SetCellState(nRow, ii, bSet, nStateType);
			
			return bRet;
		}
		if(nRow < 0)
		{
			bool bRet = false;
			for(int ii = 0; ii < m_flx.Rows; ii++)
				bRet = SetCellState(ii, nCol, bSet, nStateType);
			
			return bRet;
		}
		if(!IsInGrid(nRow, nCol))
			return false;
		bool bWasBold = m_flx.Cell(nStateType, nRow, nCol);
		m_flx.Cell(nStateType, nRow, nCol) = bSet;
		return bWasBold;
	}
	bool IsCellState(int nRow, int nCol, int nStateType = flexcpFontBold)
	{
		if(!IsInGrid(nRow, nCol))
			return false;
		bool bIsBold = m_flx.Cell(nStateType, nRow, nCol);
		return bIsBold;
	}
	bool IsEnable() 
	{
		bool bEnable = m_flx.Enabled;
		return bEnable;
	}
	bool SetEnable(bool bSet = true)
	{
		bool bOldVal = IsEnable();
		m_flx.Enabled = bSet;
		return bOldVal;
	}
	void SetColHeading(int nCol, LPCSTR lpcszText)
	{
		if(nCol >= 0)
			//m_flx.Cell(flexcpText, 0, nCol) = lpcszText;
			m_flx.TextMatrix(0, nCol) = lpcszText;
	}
protected:
	 // assume format str in standard form, and we convert into new str with localization if needed
	int GetFormatStrAsArray(LPCSTR lpcszHeadings, vector<string>& vsHeadings, LPCSTR lpcszCategory = NULL, bool bCvtToLocal = true)
	{
		string strHeadings = lpcszHeadings;
		int nCount = strHeadings.GetTokens(vsHeadings, '|');
		if(!bCvtToLocal)
			return nCount;
		ASSERT(vsHeadings.GetSize() == nCount);
		for(int ii = 0; ii < nCount; ii++)
		{
			vsHeadings[ii] = _LC(vsHeadings[ii], lpcszCategory);
		}
		return nCount;
	}
	void SetFormatStrLocal(LPCSTR lpcszHeadings, LPCSTR lpcszCategory = NULL)
	{
		vector<string> vsHeadings;
		int nSize = GetFormatStrAsArray(lpcszHeadings, vsHeadings, lpcszCategory);
		ASSERT(vsHeadings.GetSize() == nSize);
		string strFormat;
		for(int ii = 0; ii < nSize; ii++)
		{
			if(ii > 0)
				strFormat += "|";
			strFormat += vsHeadings[ii];
		}
		m_flx.FormatString = strFormat;
	}
	LoadHideCols(LPCSTR lpcszDlgName, LPCSTR lpcszValName, vector<byte>* pvbColsDefault = NULL) // from registry
	{
		m_strHideColsRegValName = lpcszValName;
		m_strHideColsRegDlgName = lpcszDlgName;
		vector<byte> vbCols;
		if(load_default_checkboxes(m_strHideColsRegDlgName, vbCols, m_strHideColsRegValName))
			SetHiddenCols(vbCols);
		else if(pvbColsDefault)
			SetHiddenCols(*pvbColsDefault);
	}
	SaveHideCols() // to registry
	{
		if(m_strHideColsRegValName.IsEmpty() || m_strHideColsRegDlgName.IsEmpty())
			return;
		
		vector<byte> vbCols;
		GetHiddenCols(vbCols);
		save_default_checkboxes(m_strHideColsRegDlgName, vbCols, m_strHideColsRegValName);
	}
	//--- CPY 9/6/03 v7.5686 RESIZEING_CLEAN_UP move all m_cntrl and m_wndDlg related code to base class from GridControl
public:
	//virtual 
	int	GetPanelHeight(bool bGetMin = false)
	{
		return 50;
	}
	//virtual 
	int GetPanelWidth(bool bGetMin = false)
	{
		return 150;
	}
	//virtual 
	int GetMinHeight(bool bKeepFunctional = false) 
	{
		if(bKeepFunctional) // Min height that is still good to use the grid
			return YTwipsToPixels(m_nRowHeight * 4);
		
		return ResizeControl::GetMinHeight(bKeepFunctional);
	}
	//virtual 
	int GetMaxHeight(bool bKeepFunctional = false)
	{
		if(bKeepFunctional) // Min height that is still good to use the grid
			return YTwipsToPixels(m_nRowHeight * 6);
			
		return ResizeControl::GetMaxHeight(bKeepFunctional);
	}
	//---
private:
	string m_strHideColsRegValName;
	string m_strHideColsRegDlgName;
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	// local helper functions
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	
	// nx ny in Twips in client coordinates
	bool isInCell(int nx, int ny, int nRow, int nCol)
	{
		RECT rect;
		if(!getCellRect(nRow, nCol, rect))
			return false;
		if(nx >= rect.left && nx <= rect.right && ny >= rect.top && ny <= rect.bottom)
			return true;
		
		return false;
	}
	bool	getCellRect(int nRow, int nCol, RECT& rect)
	{
		if(nRow < 0 || nCol < 0)
			return false;
	
		rect.left = m_flx.Cell(flexcpLeft, nRow, nCol);
		rect.top = 	m_flx.Cell(flexcpTop, nRow, nCol);
		rect.right = rect.left + m_flx.Cell(flexcpWidth, nRow, nCol);
		rect.bottom = rect.top + m_flx.Cell(flexcpHeight, nRow, nCol);
		return true;
	}
	
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
		
private:
	int	m_nLastRow;
	int m_nLastCol;
	bool m_bMouseDownToggleCheck; //CPY 5/20/03 CHECK_BOX_CLICK_OUTSIDE_CHECK_TO_TOGGLE

⌨️ 快捷键说明

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