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

📄 tabbarwnd.cpp

📁 TabBars的开源源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
          bStr = _T("Properties");
          m_pApplication->ExecuteCommand(bStr);
          break;
        }
        case IDC_HEADERFLIP:
        {
          m_pCommands->DoHeaderFlip(cFullPath);
          break;
        }
        case IDC_OPENASTEXT:
        {
          m_pCommands->DoOpenAsText(cFullPath);
          break;
        }
        case IDC_SETCURRDIR:
        {
          m_pCommands->DoSetCurrDir(cFullPath);
          break;
        }

        case IDC_ROATTR:
        {
					DWORD attr;
					if (!cFullPath.IsEmpty())
					{
						attr = GetFileAttributes(cFullPath);
						SetFileAttributes(cFullPath,attr ^ FILE_ATTRIBUTE_READONLY);
					}
					break;
        }
      }
    }
  }
  
  VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));
}

void CTabBarsWnd::OnDbClickTabCtrl(int nTabIdx,LPARAM lParam)
{
  CComQIPtr<IGenericWindow, &IID_IGenericWindow>      pWindow;//

  if (nTabIdx < 0)
    return;

  if(!FindDSWindow(nTabIdx, pWindow))
    return;

	CloseDSWindow(pWindow);
}

// The tool tip handler displays the full path of a document.
// All open documents are scanned, looking for a the respective window's
// document.  Once the document is found, the full path is extracted.
// This function demonstrates enumeration of both documents and windows.
void CTabBarsWnd::OnToolTipTabCtrl(NMHDR* pNMHDR, LRESULT* pResult) 
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    LPTOOLTIPTEXT   lpttt = (LPTOOLTIPTEXT)pNMHDR;
    TCHITTESTINFO   hti;
    int             iTab;
    static CString  cStr; // safe - there can be only one tip at a time

    *pResult = 0;
/*
    if (lpttt->hdr.idFrom == IDC_MENU)
    {
        cStr.LoadString(IDS_MENU_TT);
    }
    else
*/    
	{
        hti.pt = CPoint(GetMessagePos());
        m_TabCtrl.ScreenToClient(&hti.pt);
        iTab = m_TabCtrl.HitTest(&hti);

        if (iTab >= 0)
        {
            CComQIPtr<IGenericWindow, &IID_IGenericWindow> pWindow;
            CComQIPtr<IGenericDocument, &IID_IGenericDocument> pDoc;
            CComBSTR bstrCaption;

            FindDSWindow(iTab, pWindow);
            if (GetDocumentObject(pWindow, pDoc))
            {
                pDoc->get_FullName(&bstrCaption);
                cStr = bstrCaption;

                if (cStr.IsEmpty())
                {
                    // no name?  it's a text editor without an associated 
                    // file
                    cStr.LoadString(IDS_UNSAVED_TT);
                }
            }
            else
            {
                cStr.LoadString(IDS_DSWIN_TT);
            }
        }
    }
    // variation on original fix by Christian Rodemeyer 
    // (Christian.Rodemeyer@t-online.de): use lpszText instead of szText so 
    // strings over 80 chars will be handled properly.
    lpttt->lpszText = LPTSTR(LPCTSTR(cStr));//it drive orbit faint!
}


/////////////////////////////////////////////////////////////////////////////
// CTabBarsWnd commands


// Updates the tabs by enumerating DevStudio's windows
// This method demonstrates enumeration using the "Item" property.
void CTabBarsWnd::UpdateTabs()
{
	long                cWindows;
	HWND                hWnd, hWndActive;
	BSTR                bStr;
	CString             cStr, cPath, cFile, cOther;
	CComVariant         index;
	CComPtr<IDispatch>  pDisp;
	HICON               hIcon;
	CTypedPtrArray      <CPtrArray, tabdata_t *> TabList;
	CTypedPtrList       <CPtrList,  tabdata_t *> TabsNotInList;
	tabdata_t           *pData, *pOldData;
	POSITION            p;
	int                 iIndex, iTabListCount = 0;
	BOOL                bHasAsterisk, bIsRC;
    
	if (!this)
		return;

	if (m_iLockUpdates)
	{
		m_iLockUpdates--;
		return;
	}

	hWndActive = pGlobalActiveDSWindow->GetSaferHwnd();

	CComQIPtr<IWindows, &IID_IWindows> pWindows;
	m_pApplication->get_Windows(&pDisp);
	pWindows = pDisp;
	pDisp = NULL;

	pWindows->get_Count(&cWindows);

  // set verified flag to FALSE for all items
  p = m_TabData.GetStartPosition();
  while (p)
  {
		m_TabData.GetNextAssoc(p, hWnd, pData);
		if (pData)
		{
			pData->bVerified = FALSE;
		}
  }

  // original addition by: Anatoly Sennov [a_s@softhome.net]
  // list all windows that potentially could be closed
  if( cfg_bUseWindowLimit ) 
	{
		CTypedPtrArray <CPtrArray, CString *> CloseList;
		int cIgnored = 0;
		for (int i = 0; i < cWindows; i++) 
		{
			index = i + 1;
			CComQIPtr<IGenericWindow, &IID_IGenericWindow> pWindow;
			pWindows->Item(index, &pDisp);
			pWindow = pDisp;
			pDisp = NULL;
  
			pWindow->get_Caption(&bStr);
			cPath = bStr;

			// windows which have been modified should not be closed
			if( cPath.Right(2) != " *" ) 
			{
				CString * record = new CString(cPath);
				CloseList.InsertAt(0, record);
			}
			else
					cIgnored++;
		}
		int windowsToClose = min(cWindows - (long)cfg_iWindowLimit,CloseList.GetSize());

		// make sure user can open at least one window when all the documents
		// have been modified
		while (windowsToClose && (cWindows - windowsToClose - cIgnored < 1))
		{
			windowsToClose--;
		}

		// close them!
		for(i = 0; i < windowsToClose; i++ ) 
		{
			if((hWnd = GetHWND(*CloseList[i])) != NULL) 
			{
				m_iLockUpdates++;
				::SendMessage(hWnd, WM_CLOSE, 0, 0);
				cWindows--;
			}
		}

		// cleanup
		for( i = 0; i < CloseList.GetSize(); i++)
				delete CloseList[i];
		CloseList.RemoveAll(); 
  }

  // enumerate the windows
  for (int i = 0; i < cWindows; i++)
  {
    index = i + 1;
    CComQIPtr<IGenericWindow, &IID_IGenericWindow> pWindow;
    pWindows->Item(index, &pDisp);
    pWindow = pDisp;
    pDisp = NULL;

    pWindow->get_Caption(&bStr);
    cPath = bStr;

    if ((hWnd = GetHWND(cPath)) == NULL)
        return;
    pData = m_TabData[hWnd];
    if (pData)
    {
//            if (!cfg_bPreserveOrder) 
//				pData->iNumber = i;
      TabList.SetAtGrow(pData->iIndex, pData);
      {
          iTabListCount++;
      }
      m_TabData[hWnd] = NULL;
    }
    else
    {
      pData = new tabdata_t;
      pData->hWnd = hWnd;
//            if (cfg_bPreserveOrder)
//           {
      TabsNotInList.AddTail(pData);
//            }
//            else
//            {
//                pData->iNumber = i;
//                TabList.SetAtGrow(i, pData);
//                iTabListCount++;
//            }
    }

    // if the user modified the document, there will be a asterisk
    // appended to the window title (removed if the file was just
    // saved), so we'll make sure we have the latest title:
    pData->cPath = cPath;

    // mark this tab so as not to delete it
    pData->bVerified = TRUE;    
  }

  m_TabCtrl.SetRedraw(FALSE);

  if (ImageList_GetImageCount(m_TabImages) < cWindows)
  {    
		m_TabCtrl.SetImageList(NULL);
		ImageList_SetImageCount(m_TabImages, cWindows + 5);
		m_TabCtrl.SetImageList(&m_TabImages);
  }
  
  // items with their verified flag set to FALSE should be deleted
  p = m_TabData.GetStartPosition();
  while (p)
  {
    m_TabData.GetNextAssoc(p, hWnd, pData);
    if (!pData  ||  !pData->bVerified)
    {
      m_TabData.RemoveKey(hWnd);
      delete pData;
    }
  }
  // create the actual tabs
  TC_ITEM     newTabItem, oldTabItem;
  int         iCurrTabIndex  = 0;    // the index of the inserted tab
  
  iIndex = 0;
  newTabItem.mask = TCIF_PARAM | TCIF_TEXT;
  oldTabItem.mask = TCIF_PARAM;

  while (1)
  {
    p = TabsNotInList.GetHeadPosition();
    if (!iTabListCount || (cfg_iAddOrder == aoFront && p))
    {
      if(!p) 
				break;
      pData = TabsNotInList.GetAt(p);
      TabsNotInList.RemoveAt(p);

      if (!iTabListCount)
      {
        pData->iIndex = iCurrTabIndex;
      }
    }
    else
    {
      iTabListCount--;
      do
      {
        pData = TabList[iIndex++];
      } while (!pData);
    }

    cStr = pData->cPath;
 		//dfgthsthswtr
//		iCurrTabNumber = pData->iNumber;
    
		if (cStr.Right(2) == " *")
    {
      cStr = cStr.Left(cStr.GetLength() - 2);
      bHasAsterisk = TRUE;
    }
    else
    {
      bHasAsterisk = FALSE;
    }

  // process .rc files
    CString cStrRC = cStr;
    cStrRC.MakeUpper();
    int nPos, nRight;
    if (cStrRC.Find(".RC") >= 0  &&  cStrRC.Find(" - ") >= 0)
    {
      bIsRC = TRUE;

      if (!cfg_bDispRID)
      {
        nPos   = cStr.Find("- ");
        cStrRC = cStr.Left(nPos + 2);
        cStr   = cStr.Mid(nPos + 2);
        nPos   = cStr.Find(' ');
        cStr   = cStrRC + cStr.Mid(nPos + 1);
      }

      if (!cfg_bDispResType)
      {
        nPos = cStr.ReverseFind('(');
        cStr = cStr.Left(nPos);
      }

      if (!cfg_bDispResLang)
      {
        nPos   = cStr.Find('[');
        nRight = cStr.Find(']');

        // fix by Mark Cooke [mark.cooke@oxinst.co.uk]:
        // DevStudio cal ommit the language part, so check for this
        if( (0 <= nPos)  &&  (0 <= nRight) )
        {
          cStrRC = cStr.Mid(nRight + 2);
          cStr   = cStr.Left(nPos);
          cStr  += cStrRC;
        }
      }

      nPos = cStr.Find(" - ");
      if (!cfg_bDispRC)
      {
        cOther = cStr.Mid(nPos + 2);
        cFile = "";
      }
      else
      {
        cFile = cStr.Left(nPos);
        if (nPos == cStr.GetLength() - 3)
        {
	        cOther = "";
        }
        else
        {
          cOther = cStr.Mid(nPos);
        }
      }
    }
    else
    {
      bIsRC = FALSE;
      cFile = cStr;
      cOther = "";
    }

    hIcon = (HICON)GetClassLong(pData->hWnd, GCL_HICONSM);
      
    if (cfg_bShowIcons  &&  hIcon)
    {
      newTabItem.mask |= TCIF_IMAGE;
      m_TabImages.Replace(iCurrTabIndex, hIcon);
      newTabItem.iImage = iCurrTabIndex;
    }
    else
    {
      newTabItem.mask &= ~TCIF_IMAGE;
    }

    if (bHasAsterisk)
    {
      cStr += " *";
    }

    newTabItem.pszText = cStr.GetBuffer(0);
    newTabItem.lParam = (LPARAM)(pData);

    pOldData = m_TabData[pData->hWnd];
    if (pOldData  &&  pOldData != pData)
      delete pOldData;
    m_TabData[pData->hWnd] = pData;
                                    

⌨️ 快捷键说明

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