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

📄 listctrlstyled.cpp

📁 网络分析工具
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	if(nSubItem > 0)
		 lpLS_item = lpLS_root->subitems[nSubItem - 1];

	if(m_item_selected)
	{
		if(lpLS_item)
			lpLS_item = lpLS_item->selected_style;

		if(lpLS_row)
			lpLS_row = lpLS_row->selected_style;

		if(lpLS_col)
			lpLS_col = lpLS_col->selected_style;
	}

	// Set if style of columns & rows are enable or not
	//
	bool enable_col_style = true;
	bool enable_row_style = true;

	if(lpLS_item)
	{	enable_col_style = (lpLS_item->StyleFlag & LIS_NO_COL_STYLE) == 0;
		enable_row_style = (lpLS_item->StyleFlag & LIS_NO_ROW_STYLE) == 0;
	}

	if(lpLS_row && enable_col_style && enable_row_style)
		enable_col_style = (lpLS_row->StyleFlag & LIS_NO_COL_STYLE) == 0 ;

	if(lpLS_col && enable_row_style && enable_col_style)
		enable_row_style = (lpLS_col->StyleFlag & LIS_NO_ROW_STYLE) == 0;

	// ---------------------------
	// -- Text Color Management --
	// ---------------------------
	{	// Default
		//
		bool set = false;

		if(m_item_selected)
			pNMLVCUSTOMDRAW->clrText = m_highlighttext;
		else
			pNMLVCUSTOMDRAW->clrText = CListCtrl::GetTextColor();

		// Try ITEM color
		//
		if(lpLS_item)
		{	if(lpLS_item->StyleFlag & LIS_TXTCOLOR)
			{	pNMLVCUSTOMDRAW->clrText = lpLS_item->txtColor;
				set = true;
			}
		}

		// Try LINE color
		//
		if(lpLS_row && !set && enable_row_style)
		{	if(lpLS_row->StyleFlag & LIS_TXTCOLOR)
			{	pNMLVCUSTOMDRAW->clrText = lpLS_row->txtColor;
				set = true;
			}
		}

		// Try COLUMN color
		//
		if(lpLS_col && !set && enable_col_style)
		{	if(lpLS_col->StyleFlag & LIS_TXTCOLOR)
				pNMLVCUSTOMDRAW->clrText = lpLS_col->txtColor;
		}
	}

	// ---------------------------------
	// -- BackGround Color Management --
	// ---------------------------------
	{	// Default
		//
		bool set = false;
		if(!m_item_selected)
			pNMLVCUSTOMDRAW->clrTextBk = CListCtrl::GetTextBkColor();
		else
			pNMLVCUSTOMDRAW->clrTextBk = m_highlight;

		// Try ITEM color
		//
		if(lpLS_item)
		{	if(lpLS_item->StyleFlag & LIS_BGCOLOR)
			{	pNMLVCUSTOMDRAW->clrTextBk = lpLS_item->bgColor;
				set = true;
			}
		}

		// Try LINE color
		//
	   	if(lpLS_row && !set)
		{	if(lpLS_row->StyleFlag & LIS_BGCOLOR && enable_row_style)
			{	pNMLVCUSTOMDRAW->clrTextBk = lpLS_row->bgColor;
				set = true;
			}
		}

		// Try COLUMN color
		//
		if(lpLS_col	&& !set)
		{	if(lpLS_col->StyleFlag & LIS_BGCOLOR && enable_col_style)
				pNMLVCUSTOMDRAW->clrTextBk = lpLS_col->bgColor;
		}
	}

	// Adjusting LS_Structure item for take orignal style if no style is defined for the selected case
	//
	if(m_item_selected)
	{	bool back;

		back = true;
		if(lpLS_item)
			back = !lpLS_item->in_use;

		if(back)
		{	lpLS_item = lpLS_root;
			if(nSubItem > 0)
				lpLS_item = lpLS_root->subitems[nSubItem - 1];
		}

		back = true;
		if(lpLS_row)
			back = !lpLS_row->in_use;

		if(back)
			lpLS_row = lpLS_root->row_style;

		back = true;
		if(lpLS_col)
			back = !lpLS_col->in_use;

		if(back)
			lpLS_col = this->columns[nSubItem];

		// Recompute if style of columns & rows are enable or not
		//
		enable_col_style = true;
		enable_row_style = true;

		if(lpLS_item)
		{	enable_col_style = (lpLS_item->StyleFlag & LIS_NO_COL_STYLE) == 0;
			enable_row_style = (lpLS_item->StyleFlag & LIS_NO_ROW_STYLE) == 0;
		}

		if(lpLS_row && enable_col_style && enable_row_style)
			enable_col_style = (lpLS_row->StyleFlag & LIS_NO_COL_STYLE) == 0 ;

		if(lpLS_col && enable_row_style && enable_col_style)
			enable_row_style = (lpLS_col->StyleFlag & LIS_NO_ROW_STYLE) == 0;
	}

	// ---------------------------
	// -- Fonts Initialisations --
	// ---------------------------
	CFont * pCFontItem = NULL;			// Item Font
	CFont * pCFontRow = NULL;			// Row Font
	CFont * pCFontCol = NULL;			// Column Font

	// -- If a font is created, then the existing merged font can't be available
	// -- This flag prevent this use if it's not permitted
	// --
	bool must_erase_merged_font = false;


	// ---------------
	// -- Item Font --
	// ---------------
	if(lpLS_item)
	{
		if(lpLS_item->cfont != NULL)
			pCFontItem = lpLS_item->cfont;
		else
		{	// Create it if necessary
			//
			if((lpLS_item->StyleFlag & mask) != 0)
			{	pCFontItem = CreateFont(lpLS_item->StyleFlag);
				lpLS_item->cfont = pCFontItem;
				lpLS_item->ifont = true;
				must_erase_merged_font = true;
			}
		}
	}

	// --------------
	// -- Row Font --
	// --------------
	if(lpLS_row && enable_row_style)
	{
		if(lpLS_row->cfont != NULL)
			pCFontRow = lpLS_row->cfont;
		else
		{	// Create it if necessary
			//
			if((lpLS_row->StyleFlag & mask) != 0)
			{	pCFontRow = CreateFont(lpLS_row->StyleFlag);
				lpLS_row->cfont = pCFontRow;
				lpLS_row->ifont = true;
				must_erase_merged_font = true;
			}
		}
	}

	// -----------------
	// -- Column Font --
	// -----------------
	if(lpLS_col && enable_col_style)
	{
		if(lpLS_col->cfont != NULL)
			pCFontCol =	lpLS_col->cfont;
		else
		{	// Create it if necessary
			//
			if((lpLS_col->StyleFlag & mask) != 0)
			{	pCFontCol = CreateFont(lpLS_col->StyleFlag);
				lpLS_col->cfont = pCFontCol;
				lpLS_col->ifont = true;
				must_erase_merged_font = true;
			}
		}
	}

	// -- See if a font is define or not (if not, use default font)
	// --
	if(pCFontItem == NULL && pCFontRow == NULL && pCFontCol == NULL)
		return NULL;

	// Delete the merged font if needed
	//
	if(lpLS_item)
	{	if(lpLS_item->merged_font != NULL && must_erase_merged_font)
			this->Free_LS_font(lpLS_item,FONT_MERGED);
	}

	// -- At least One Font is required, Find it if only one is required
	// --
	CFont * pFont = this->SelectFont(pCFontItem,pCFontRow,pCFontCol);

	// -- If a Font can be selected, then we can return it !! no melting font was needed
	// --
	if(pFont != NULL)
		return pFont;

	// -- Test if a merged font exist, if it's the case, we can directly return it
	// --
	if(lpLS_item)
	{	if(lpLS_item->merged_font != NULL)
			return lpLS_item->merged_font;
	}
	else
		return NULL;

	// -- So, if we can't select a Font, it's because we must created a melted Font from all fonts
	// --
	CFont * pFontMelted = this->MergeFont(pCFontItem,pCFontRow,pCFontCol);

	// -- Attach the melted font
	// --
	lpLS_item->merged_font = pFontMelted;

	// -- Return
	// --
	return pFontMelted;
}

CFont * CListCtrlStyled::SelectFont(CFont * pCFont1,CFont * pCFont2,CFont * pCFont3)
{	if(pCFont1)
	{	if(!pCFont2 && ! pCFont3)
			return pCFont1;
		else
			return NULL;
	}

	if(pCFont2)
	{	if(!pCFont3)
			return pCFont2;
		else
			return NULL;
	}

	return (pCFont3);
}

CFont * CListCtrlStyled::MergeFont(CFont * pCFont1,CFont * pCFont2,CFont * pCFont3)
{	LOGFONT merge_logfont;

	// -- Set Base Font Informations
	// --
	merge_logfont = this->m_Default_LOGFONT;

	if(pCFont3)
	{	LOGFONT logfont;
		pCFont3->GetLogFont(&logfont);
		this->MergeLogFont(&logfont,&merge_logfont);
	}

	if(pCFont2)
	{	LOGFONT logfont;
		pCFont2->GetLogFont(&logfont);
		this->MergeLogFont(&logfont,&merge_logfont);
	}

	if(pCFont1)
	{	LOGFONT logfont;
		pCFont1->GetLogFont(&logfont);
		this->MergeLogFont(&logfont,&merge_logfont);
	}

	// -- So now we have the logfont corresponding at our merged font
	// --

	CFont * pCFontMerged;
	pCFontMerged = new(CFont);
	pCFontMerged->CreateFontIndirect(&merge_logfont);

	return pCFontMerged;
}

void CListCtrlStyled::MergeLogFont(LOGFONT * font,LOGFONT * dest)
{
	/*	typedef struct tagLOGFONT {
  		LONG lfHeight;
  		LONG lfWidth;
  		LONG lfEscapement;
  		LONG lfOrientation;
  		LONG lfWeight;
  		BYTE lfItalic;
  		BYTE lfUnderline;
  		BYTE lfStrikeOut;
  		BYTE lfCharSet;
  		BYTE lfOutPrecision;
  		BYTE lfClipPrecision;
  		BYTE lfQuality;
  		BYTE lfPitchAndFamily;
  		TCHAR lfFaceName[LF_FACESIZE];
		} LOGFONT, *PLOGFONT;
	*/

	if(font->lfHeight != this->m_Default_LOGFONT.lfHeight)
		dest->lfHeight = font->lfHeight;

	if(font->lfWidth != this->m_Default_LOGFONT.lfWidth)
		dest->lfWidth = font->lfWidth;

	if(font->lfEscapement != this->m_Default_LOGFONT.lfEscapement)
		dest->lfEscapement = font->lfEscapement;

	if(font->lfOrientation != this->m_Default_LOGFONT.lfOrientation)
		dest->lfOrientation = font->lfOrientation;

	if(font->lfWeight != this->m_Default_LOGFONT.lfWeight)
		dest->lfWeight = font->lfWeight;

	if(font->lfItalic != this->m_Default_LOGFONT.lfItalic)
		dest->lfItalic = font->lfItalic;

	if(font->lfUnderline != this->m_Default_LOGFONT.lfUnderline)
		dest->lfUnderline = font->lfUnderline;

	if(font->lfStrikeOut != this->m_Default_LOGFONT.lfStrikeOut)
		dest->lfStrikeOut = font->lfStrikeOut;

	if(font->lfCharSet != this->m_Default_LOGFONT.lfCharSet)
		dest->lfCharSet = font->lfCharSet;

	if(font->lfOutPrecision != this->m_Default_LOGFONT.lfOutPrecision)
		dest->lfOutPrecision = font->lfOutPrecision;

	if(font->lfClipPrecision != this->m_Default_LOGFONT.lfClipPrecision)
		dest->lfClipPrecision = font->lfClipPrecision;

	if(font->lfQuality != this->m_Default_LOGFONT.lfQuality)
		dest->lfQuality = font->lfQuality;

	if(font->lfPitchAndFamily != this->m_Default_LOGFONT.lfPitchAndFamily)
		dest->lfPitchAndFamily = font->lfPitchAndFamily;

	if(strcmp(font->lfFaceName,this->m_Default_LOGFONT.lfFaceName) != 0)
		strcpy_s(dest->lfFaceName, 32, font->lfFaceName);

}

CFont * CListCtrlStyled::CreateFont(DWORD StyleFlag)
{
	// Retrieve informations about the current font of this item
	//
	LOGFONT logfont = this->m_Default_LOGFONT;					// Information about our new font

	// Update the logfont structure for prepare our new font
	//
    /*	typedef struct tagLOGFONT {
  		LONG lfHeight;
  		LONG lfWidth;
  		LONG lfEscapement;
  		LONG lfOrientation;
  		LONG lfWeight;
  		BYTE lfItalic;
  		BYTE lfUnderline;
  		BYTE lfStrikeOut;
  		BYTE lfCharSet;
  		BYTE lfOutPrecision;
  		BYTE lfClipPrecision;
  		BYTE lfQuality;
  		BYTE lfPitchAndFamily;
  		TCHAR lfFaceName[LF_FACESIZE];
		} LOGFONT, *PLOGFONT;
	*/

	if(StyleFlag & LIS_BOLD)
		logfont.lfWeight = FW_BOLD;
	else
		logfont.lfWeight = FW_NORMAL;

	logfont.lfItalic = (StyleFlag & LIS_ITALIC) > 0;
	logfont.lfUnderline = (StyleFlag & LIS_UNDERLINE) > 0;
	logfont.lfStrikeOut = (StyleFlag & LIS_STROKE) > 0;

	CFont * lpCFont;
	lpCFont = new(CFont);

	// Create the font
	//
	lpCFont->CreateFontIndirect(&logfont);

	return (lpCFont);
}

// **************************************
// ** Internal INITIALISATIONS Methods **
// **************************************
void CListCtrlStyled::Init_LS_item(LS_item * lpLS_item,bool allow_subitems)
{	// lParam Init
	//
	lpLS_item->lParam = 0;
	lpLS_item->mParam = false;

	// Set Default Style
	//
	lpLS_item->StyleFlag = 0;
	lpLS_item->in_use = false;

	lpLS_item->txtColor = 0;
	lpLS_item->bgColor = 0;
	lpLS_item->cfont = NULL;
	lpLS_item->ifont = false;
	lpLS_item->merged_font = NULL;
	lpLS_item->row_style = NULL;
	lpLS_item->selected_style = NULL;

	// Init the Array for hold SubItems Style
	//
	if(allow_subitems)
	{	int nSubItems = this->GetHeaderCtrl()->GetItemCount();
		if(nSubItems > 0) nSubItems--;
		lpLS_item->subitems.SetSize( nSubItems );
	}
	else
		lpLS_item->subitems.SetSize(0);

	lpLS_item->subitems.RemoveAll();
}

void CListCtrlStyled::Free_LS_font(LS_item* lpLS_item,DWORD mask)
{
	// Free his font object if needed (if it's an internal font)
	//
	if(lpLS_item->cfont != NULL && lpLS_item->ifont && (mask & FONT_NORMAL))
	{	delete lpLS_item->cfont;
		lpLS_item->cfont = NULL;
		lpLS_item->ifont = false;
	}

	// Free Merged Font
	//
	if(lpLS_item->merged_font != NULL && (mask & FONT_MERGED))
	{	delete lpLS_item->merged_font;
		lpLS_item->merged_font = NULL;
	}

}

void CListCtrlStyled::Free_LS_item(LS_item* lpLS_item)
{
	if(lpLS_item == NULL)
		return;

	if(lpLS_item->subitems.GetSize() > 0)
	{	// We must delete the subitems structure also
		//
		int nSubItems = (int)lpLS_item->subitems.GetSize();

		for(int nSubItem = 0; nSubItem < nSubItems; nSubItem++)
			this->Free_LS_item(lpLS_item->subitems[nSubItem]);
	}

	// We can reset the list of subitems style
	//
	lpLS_item->subitems.RemoveAll();
	lpLS_item->subitems.SetSize(0);


	// Free CFont objects
	//
	this->Free_LS_font(lpLS_item);

	// Delete the Row Style if needed
	//
	if(lpLS_item->row_style != NULL)
		this->Free_LS_item(lpLS_item->row_style);

	// Delete the Selected Style if needed
	//
	if(lpLS_item->selected_style != NULL)
		this->Free_LS_item(lpLS_item->selected_style);

	// Delete the item structure
	//
	delete lpLS_item;
	lpLS_item = NULL;
}

void CListCtrlStyled::InitLVITEM(int nItem,int nSubItem,LVITEM * pItem)
{ /*
  typedef struct _LV_ITEM {
    UINT   mask;         // see below
    int    iItem;        // see below
    int    iSubItem;     // see below
    UINT   state;        // see below
    UINT   stateMask;    // see below
    LPSTR  pszText;      // see below
    int    cchTextMax;   // see below
    int    iImage;       // see below
    LPARAM lParam;       // 32-bit value to associate with item
   } LV_ITEM;
  */
	pItem->mask = LVIF_PARAM;
	pItem->iItem = nItem;
	pItem->iSubItem = nSubItem;
	pItem->state = NULL;
	pItem->stateMask = NULL;
	pItem->pszText = NULL;
	pItem->cchTextMax = NULL;
	pItem->iImage = NULL;
	pItem->lParam = NULL;
	CListCtrl::GetItem(pItem);
}

⌨️ 快捷键说明

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