void CTabCtrlSSL::DrawItem(LPDRAWITEMSTRUCT lpdis) { TC_ITEM tci; CDC* pDC = CDC::FromHandle(lpdis->hDC); HIMAGELIST hilTabs = (HIMAGELIST)TabCtrl_GetImageList(GetSafeHwnd()); BOOL bSelected = (lpdis->itemID == (UINT)GetCurSel()); CRect rItem(lpdis->rcItem); UINT itemID = lpdis->itemID; if (bSelected) rItem.bottom -= 1; else rItem.bottom += 2; // tab // blend from back color to COLOR_3DFACE if 16 bit mode or better COLORREF crFrom; crFrom = ::GetSysColor(COLOR_3DFACE); if(itemID == (UINT)m_hColorTabID) pDC->FillSolidRect(rItem, crTabColor); else pDC->FillSolidRect(rItem, crFrom); // text & icon rItem.left += 3; rItem.top += 3 + (bSelected ? 1 : 0); pDC->SetBkMode(TRANSPARENT); CString sTemp; tci.mask = TCIF_TEXT | TCIF_IMAGE; tci.pszText = sTemp.GetBuffer(100); tci.cchTextMax = 99; GetItem(lpdis->itemID, &tci); sTemp.ReleaseBuffer(); // icon if (hilTabs) { ImageList_Draw(hilTabs, tci.iImage, *pDC, rItem.left, rItem.top, ILD_TRANSPARENT); rItem.left += 16 + 3; } // text rItem.right -= 3; pDC->DrawText(sTemp, rItem, DT_NOPREFIX | DT_CENTER); }
/* Sets a tabs icon. Normally, this icon is the folders icon, however if the tab is locked, the icon will be a lock. */ void Explorerplusplus::SetTabIcon(int iIndex,int iTabId,LPITEMIDLIST pidlDirectory) { TCITEM tcItem; SHFILEINFO shfi; ICONINFO IconInfo; int iImage; int iRemoveImage; /* If the tab is locked, use a lock icon. */ if(m_TabInfo[iTabId].bAddressLocked || m_TabInfo[iTabId].bLocked) { iImage = TAB_ICON_LOCK_INDEX; } else { SHGetFileInfo((LPCTSTR)pidlDirectory,0,&shfi,sizeof(shfi), SHGFI_PIDL|SHGFI_ICON|SHGFI_SMALLICON); /* TODO: The proxy icon may also be the lock icon, if the tab is locked. */ SetTabProxyIcon(iTabId,shfi.hIcon); GetIconInfo(shfi.hIcon,&IconInfo); iImage = ImageList_Add(TabCtrl_GetImageList(m_hTabCtrl), IconInfo.hbmColor,IconInfo.hbmMask); DeleteObject(IconInfo.hbmColor); DeleteObject(IconInfo.hbmMask); DestroyIcon(shfi.hIcon); } /* Get the index of the current image. This image will be removed after the new image is set. */ tcItem.mask = TCIF_IMAGE; TabCtrl_GetItem(m_hTabCtrl,iIndex,&tcItem); iRemoveImage = tcItem.iImage; /* Set the new image. */ tcItem.mask = TCIF_IMAGE; tcItem.iImage = iImage; TabCtrl_SetItem(m_hTabCtrl,iIndex,&tcItem); if(iRemoveImage != TAB_ICON_LOCK_INDEX) { /* Remove the old image. */ TabCtrl_RemoveImage(m_hTabCtrl,iRemoveImage); } }
bool RemoveTab(HWND TabWindow, int Index) { assert(IsWindow(TabWindow)); assert(Index >= 0); assert(Index < TabCtrl_GetItemCount(TabWindow)); TC_ITEM TabData; TabData.mask = TCIF_IMAGE | TCIF_PARAM; if(TabCtrl_GetItem(TabWindow, Index, &TabData)) { int CurIndex = TabCtrl_GetCurSel(TabWindow); assert(CurIndex >= -1); if(CurIndex != -1 && TabCtrl_DeleteItem(TabWindow, Index)) { if(TabData.iImage != -1) TabCtrl_RemoveImage(TabWindow, TabData.iImage); int Count = TabCtrl_GetItemCount(TabWindow); assert(Count >= 0); if(Count == 0) // We just removed the last one, do some addition cleanup { ShowWindow(reinterpret_cast<HWND>(TabData.lParam), SW_HIDE); HIMAGELIST ImageList = TabCtrl_GetImageList(TabWindow); if(ImageList) { ImageList_Destroy(ImageList); TabCtrl_SetImageList(TabWindow, NULL); } RemoveProp(TabWindow, PropName); } else if(Index == CurIndex) // We're deleting the currently visible tab { if(Index == Count) // Last tab Index--; TabToFront(TabWindow, Index); } SetTabThemeTexture(reinterpret_cast<HWND>(TabData.lParam), false); return true; } } return false; }
//---------------------------------------------------------------------------------------------------------- // draw tab item context: possible icon and text void CXPTabCtrl::DrawTabItem(CDC* pDC, int ixItem, const CRect& rcItemC, UINT uiFlags) { TC_ITEM tci; CString sText; tci.mask =TCIF_TEXT | TCIF_IMAGE; tci.pszText =sText.GetBuffer(128); tci.cchTextMax=127; GetItem(ixItem,&tci); sText.ReleaseBuffer(); BOOL bSel =(uiFlags&2)?TRUE:FALSE; BOOL bBottom=(uiFlags&8)?TRUE:FALSE; CRect rcItem=rcItemC; if(bSel) rcItem.bottom -= 1; else rcItem.bottom += 2; rcItem.left+=(bBottom?3:6); // text & icon rcItem.top +=(bBottom?3:2) + (bSel ? 1 : (bBottom?0:3)); int nOldMode=pDC->SetBkMode(TRANSPARENT); HIMAGELIST hilTabs = (HIMAGELIST)TabCtrl_GetImageList(GetSafeHwnd()); // icon if(hilTabs && tci.iImage>=0) { ImageList_Draw(hilTabs, tci.iImage, *pDC, rcItem.left+(bSel?2:0), rcItem.top+(bSel?0:-2), ILD_TRANSPARENT); rcItem.left+=19; } else rcItem.OffsetRect(-2,0); if(sText.GetLength()) { CFont* pOldFont=pDC->SelectObject(GetFont()); // prepare dc rcItem.right-=3; // text CRect rect(0,0,rcItem.Width(),20); ::DrawText(pDC->GetSafeHdc(),sText.GetBuffer(sText.GetLength()+4),-1,rect,DT_CALCRECT|DT_SINGLELINE|DT_MODIFYSTRING|DT_END_ELLIPSIS); sText.ReleaseBuffer(); rcItem.OffsetRect((bBottom?-1:0),(bSel?1:-1)); pDC->DrawText(sText, rcItem, DT_NOPREFIX|DT_CENTER); pDC->SelectObject(pOldFont); } pDC->SetBkMode(nOldMode); }
bool SetTabIcon(HWND TabWindow, int Index, HICON Icon) { assert(IsWindow(TabWindow)); assert(Index >= 0); assert(Index < TabCtrl_GetItemCount(TabWindow)); HIMAGELIST ImageList = TabCtrl_GetImageList(TabWindow); if(!ImageList) // Create a new image list { ImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1); TabCtrl_SetImageList(TabWindow, ImageList); } TC_ITEM TabData; TabData.mask = TCIF_IMAGE; if(TabCtrl_GetItem(TabWindow, Index, &TabData)) { if(Icon) // Add icon { if(TabData.iImage == -1) // There is no icon yet TabData.iImage = ImageList_AddIcon(ImageList, Icon); else TabData.iImage = ImageList_ReplaceIcon(ImageList, TabData.iImage, Icon); } else // Remove icon { if(TabData.iImage != -1) // Skip if there is no icon { TabCtrl_RemoveImage(TabWindow, TabData.iImage); TabData.iImage = -1; } } return TabCtrl_SetItem(TabWindow, Index, &TabData); } return false; }