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

📄 gridcontrol.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 2 页
字号:
	
	int	toggleCheck(int nVal)
	{
		switch(nVal)
		{
		case flexChecked:
			return flexUnchecked;
		case flexUnchecked:
			return flexChecked;
		case flexTSChecked:
			return flexTSUnchecked;
		case flexTSUnchecked:
			return flexTSChecked;
		}
		ASSERT(FALSE);
		return flexTSGrayed;
	}
	void resizeAllCols(int nExtraPixcels = 8)
	{
		bool bAllColSameWidth = false;
		int nExtra = PixelsToTwips(nExtraPixcels);
		m_flx.AutoSize(0, m_flx.Cols - 1, bAllColSameWidth, nExtra);
	}
	bool is_WindowJapanese()
	{
		int nCharSet;
		string str = get_system_font_name(GSFI_TYPE_DEFAULT, &nCharSet);
		if(SHIFTJIS_CHARSET == nCharSet)
			return true;
		
		return false;
	}
public:	
	virtual string GetRuntimeClass()
	{
		return "GridControl";
	}
	void SetFont()
	{
		//---- CPY v7.5699 QA70-5000 9/19/03 GET_WINDOW_MENU_FONT 
		/*
		//---- we try to set the grid to use same font as dialog, this is needed to support
		// Japanese etc.
		if(is_win2k(false) && is_WindowJapanese())
			m_flx.FontName = get_system_font_name(SYSTEM_FONT); //"俵俽 柧挬"; // somehow setting to dlg font still won't work
		else
			m_flx.FontName = FontName();
		
		m_flx.FontSize = FontSize();
		//----
		*/
		// temp code, need clean up later, some codes need to goto base class
		if(is_WindowJapanese())
		{
			int nFontSize;
			m_flx.FontName = GetFontName(ORIGIN_MENU_FONT,&nFontSize);
			if(nFontSize < 0) // convert to pt
			{
				double vv = - PixelsToTwips(nFontSize);
				vv = vv * 72.0 / 1440.0;
				nFontSize = 0.5 + vv;
			}
			
			m_flx.FontSize = nFontSize;
		}
		else
		{
			m_flx.FontName = FontName();
			m_flx.FontSize = FontSize();
		}
		//---- end CPY QA70-5000 9/19/03 
		m_nFontSize = m_flx.CellFontSize;
		
		m_nRowHeight= m_flx.RowHeight(0);
	}	
	virtual void ClearAll() 
	{
		m_flx.Rows = m_flx.FixedRows;
	}
	//OnAfterEdit call base method first 
	virtual void OnAfterEdit(int nRow, int nCol) 
	{
		_DBINT("OnAfterEdit bToggleCheck =", m_bMouseDownToggleCheck);
		
		m_bMouseDownToggleCheck = false;//---- CPY 5/20/03 CHECK_BOX_CLICK_OUTSIDE_CHECK_TO_TOGGLE
	}
	
	// OnBeforeMouseDown call base class method last	
	void OnBeforeMouseDown(short nButton, short nShift, float X, float Y, BOOL* pCancel)
	{
		int iRow = m_flx.MouseRow;
		int iCol = m_flx.MouseCol;
		if(iRow < 0 || iCol < 0)
		{
			*pCancel = TRUE;
			return;
		}
		//---- CPY 5/20/03 CHECK_BOX_CLICK_OUTSIDE_CHECK_TO_TOGGLE
		int nVal = m_flx.Cell(flexcpChecked, iRow, iCol);// cannot use COM in == test directly
		_DBINT("OnBeforeMouseDown bToggleCheck =", m_bMouseDownToggleCheck);
		if(m_bMouseDownToggleCheck && nVal != flexNoCheckbox)
		{
			m_flx.Cell(flexcpChecked, iRow, iCol) = toggleCheck(nVal);//bWasCheck? flexUnchecked : flexChecked;

			OnAfterEdit(iRow, iCol);
		}
		m_bMouseDownToggleCheck = true;
		//---- end CPY 5/20/03 CHECK_BOX_CLICK_OUTSIDE_CHECK_TO_TOGGLE
	}
	
	//nMaxColSizeFactor = 0 will not consider max col width
	// nMaxColSizeFactor = 2 will set each col no bigger then 1/2 the width of the control width
	void ResizeCols(int nMaxColSizeFactor = 0, int nExtraPixcels = 8)
	{
		int nMaxColWidth = 0;
		
		if(nMaxColSizeFactor)
		{
			RECT rect;
			GetWindowRect(rect);
			nMaxColWidth = PixelsToTwips(RECT_WIDTH(rect)/(double)nMaxColSizeFactor);
		}
		m_flx.ColWidthMax = nMaxColWidth;
		if(nMaxColWidth)
			m_flx.ColWidthMin = PixelsToTwips(5); // ,min width

		resizeAllCols(nExtraPixcels);
	}
	// min col by row height as a factor, max col by screen width as a divider
	void ResizeCols(double dbMinColRowFactor, double dbMaxColDivScreen, int nExtraPixcels = 8)
	{		
		m_flx.ColWidthMin = 0.5 + m_nRowHeight * dbMinColRowFactor;
		int nScreenW = PixelsToTwips(GetSystemMetrics(SM_CXSCREEN));
		m_flx.ColWidthMax = 0.5 + nScreenW /dbMaxColDivScreen;

		resizeAllCols(nExtraPixcels);
	}

	void RemoveSelection()
	{
		m_flx.Col = 0;
		m_flx.Row = -1;
	}
	
	int XTwipsToPixels(int nx)	{return TwipsToPixels(nx);}
	int YTwipsToPixels(int ny)	{return TwipsToPixels(ny, false);}

	void	GridToDlgOffsets(int& dx, int &dy)
	{
		RECT rectGrid;
		GetRect(rectGrid);
	
		dx = rectGrid.left;
		dy = rectGrid.top;
	}
	bool	GetCellRect(int iRow, int iCol, RECT& rect, bool bCvtToFrame = true, bool bCvtToScree = false)
	{
		if(!getCellRect(iRow, iCol, rect))
			return false;
	
		rect.left = XTwipsToPixels(rect.left);
		rect.top = 	YTwipsToPixels(rect.top);
		rect.right = XTwipsToPixels(rect.right);
		rect.bottom = YTwipsToPixels(rect.bottom);
		InflateRect(&rect, -m_nHaldGridLineWidth, -m_nHaldGridLineWidth);
		
		if(bCvtToFrame) // convert
		{
			int dx, dy;
			GridToDlgOffsets(dx, dy);
			OffsetRect(&rect, dx, dy);
		}
		if(bCvtToScree)
		{
			ClientToScreen(rect);
		}
		return true;
	}
	void GetGridSize(int& nx, int& ny)
	{
		int nCellH;
		ny = 0;
		nx = 0;
		for(int nRow = 0; nRow < m_flx.Rows; nRow++)
		{
			nCellH = m_flx.Cell(flexcpHeight, nRow);
			ny += nCellH;
		}
		ny = TwipsToPixels(ny);
		
		int nn = 0;
		for(int nCol = 0; nCol < m_flx.Cols; nCol++)
		{
			nn += m_flx.ColWidth(nCol); //flx.Cell(flexcpWidth, 0, nCol);
		}
			
		nx = TwipsToPixels(nn);
		// gain 1 more pixels
		nx++;
		ny++;
	}
	void ClientToScreen(int &nx, int &ny, bool bCvtToFrame = true)
	{
		RECT rect;
		rect.left = rect.right = nx;
		rect.top = rect.bottom = ny;
		if(bCvtToFrame)
		{
			int dx, dy;
			GridToDlgOffsets(dx, dy);
			OffsetRect(&rect, dx, dy);
		}
		ClientToScreen(rect);
		nx = rect.left;
		ny = rect.top;
	}
	void ScreenToClient(int &nx, int &ny, bool bCvtToTwips = true, bool bCvtToFrame = true)
	{
		RECT rect;
		rect.left = rect.right = nx;
		rect.top = rect.bottom = ny;
		ScreenToClient(rect);
		if(bCvtToFrame)
		{
			int dx, dy;
			GridToDlgOffsets(dx, dy);
			OffsetRect(&rect, -dx, -dy);
		}		
		nx = rect.left;
		ny = rect.top;
		if(bCvtToTwips)
		{
			nx = PixelsToTwips(nx);
			ny = PixelsToTwips(ny, false);
		}
	}
	// nx ny in Twips in clint coordinates
	virtual void GetHiddenCols(vector<byte>& vbCols)
	{
		vbCols.SetSize(0);
		for(int nCol = 0; nCol < m_flx.Cols; nCol++)
		{
			vbCols.Add(IsColHidden(nCol));
		}
	}
	virtual void SetHiddenCols(const vector<byte>& vbCols, bool bDefault = true)
	{
		for(int nCol = 0; nCol < m_flx.Cols; nCol++)
		{
			bool bHide = bDefault;
			if(nCol < vbCols.GetSize())
				bHide = vbCols[nCol];
			HideCol(nCol, bHide);
		}
	}
protected:
	Object		m_flx;
	int			m_nRowHeight;
	int 		m_nFontSize;
	int			m_nHaldGridLineWidth;
};


// a vsFlexGrid that is used like a list control
class GridListControl : public GridControl
{
public:
	void Init(int nID, Dialog& dlg)
	{
		GridControl::Init(nID, dlg);
		m_flx.SelectionMode = flexSelectionByRow;
		m_flx.AllowSelection = false;
		//m_flx.ExplorerBar = flexExSortShow;
		m_flx.AllowUserResizing = flexResizeColumns;
	}
	// return false if no change, otherwise check if sel consistent, otherwise set to specified row/col
	bool CheckSelRow(int nRow, bool bOnlyInsideGrid = true)
	{
		if(bOnlyInsideGrid && nRow < 0)
			return false;
		
		if(m_flx.SelectionMode == flexSelectionListBox)
		{
			//--- CPY 8/19/03
			if(SHIFT_DOWN || CNTRL_DOWN)
				return false;
			//---
			int nNumSelected = m_flx.SelectedRows;

			for(int ii = 0; ii < nNumSelected; ii++)
			{
				if( nRow == m_flx.SelectedRow(ii) )
					return false;
			}
		}
		else
		{
			if(m_flx.Row == nRow)
				return false;
		}
		
		m_flx.Row = nRow;
		return true;
	}
	
	bool GetSelRows(vector<uint>& vnRows)
	{
		vnRows.SetSize(0);// empty first
		if(m_flx.SelectionMode == flexSelectionListBox)
		{
			int nNumSelected = m_flx.SelectedRows;
			if(nNumSelected > 0)
			{
				int nRow;
				for(int ii = 0; ii < nNumSelected; ii++)
				{
					nRow = m_flx.SelectedRow(ii);
					vnRows.Add(nRow);
				}
				return true;
			}
		}
		else
		{
			if(m_flx.Col >= 0)
			{
				int nSel = m_flx.Row;
				if(nSel >= m_flx.FixedRows)
				{
					vnRows.Add(nSel);
					return true;
				}
			}
		}
		return false;
	}
	// vn = [out] array of 1 = collapsed and 0 = open of all outline nodes
	// return -1 if not applicable, otherwise return number of branches
	int GetCollapsed(vector<byte>& vn)
	{
		if(m_flx.OutlineBar == flexOutlineBarNone)
			return -1;
		vn.SetSize(0);
		int nCounts = 0;
		for(int nRow = m_flx.FixedRows; nRow < m_flx.Rows; nRow++)
		{
			if(m_flx.IsSubtotal(nRow) )//&& m_flx.RowOutlineLevel(nRow) < 3)
			{
				nCounts++;
				int nCollapsed = m_flx.IsCollapsed(nRow);
				if(flexOutlineCollapsed == nCollapsed)
				{
					vn.Add(1);
				}
				else
					vn.Add(0);
			}
		}
		return nCounts;
	}
	bool SetCollapsed(const vector<byte>& vn)
	{
		if(m_flx.OutlineBar == flexOutlineBarNone)
			return false;
		int nn = 0;
		for(int nRow = m_flx.FixedRows; nRow < m_flx.Rows; nRow++)
		{
			if(m_flx.IsSubtotal(nRow))// && m_flx.RowOutlineLevel(nRow) < 3)
			{
				if(nn >= vn.GetSize())
					return false;
				
				int nCollapsed = vn[nn++]?flexOutlineCollapsed : flexOutlineSubtotals;//flexOutlineExpanded;
				m_flx.IsCollapsed(nRow) = nCollapsed;
			}
		}
		return true;
	}
protected:
	void SetAlternateRowColors()
	{
		m_flx.BackColorAlternate = RGB(0xF0,0xF0,0xF0);
	}
	bool GetSelItems(int nCol, vector<string>& vsItems)
	{
		vector<uint> vnRows;
		vsItems.SetSize(0);
		string strTemp;
		if(GetSelRows(vnRows))
		{
			for(int ii = 0; ii < vnRows.GetSize(); ii++)
			{
				strTemp = m_flx.Cell(flexcpText, vnRows[ii], nCol);
				vsItems.Add(strTemp);
			}
			return true;
		}
		return false;
	}
public:
	// return -1 if none selected, reutrn 1st sel Row if multiple
	int  GetSelectedRow()
	{
		vector<uint> vnRows;
		if(GetSelRows(vnRows))
			return vnRows[0];
		
		return -1;
	}
	void SelRow(int nRow, bool bSelLast = false) // -1 to sel last row
	{
		if(bSelLast)
			nRow = m_flx.Rows-1;
		
		m_flx.Row = nRow;
		
		if(nRow >= 0)
		{
			m_flx.ShowCell(nRow, 0);
		}
	}
	bool SelRows(const vector<int> nRows)
	{
		if(nRows.GetSize() == 1)
		{
			SelRow(nRows[0]);
			return true;
		}
		if(m_flx.SelectionMode != flexSelectionListBox)
			return false;
		m_flx.Row = -1;
		for(int ii = 0; ii < nRows.GetSize(); ii++)
			m_flx.IsSelected(nRows[ii]) = true;
		
		return true;
	}
	//virtual 
	string GetRuntimeClass()
	{
		return "GridListControl";
	}
	
private:

};


#endif //_GRID_CONTROL_H_

⌨️ 快捷键说明

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