Example #1
0
// Добавляет закладку, или меняет (при необходимости) заголовок существующей
void CTabPanelWin::AddTabInt(LPCWSTR text, int i, bool bAdmin, int iTabIcon)
{
	if (!IsTabbarCreated())
		return;

	int iIconIdx = mp_Owner->GetTabIcon(bAdmin);

	_ASSERTE(text && *text);

	TCITEM tie;
	// иконку обновляем всегда. она может измениться для таба
	tie.mask = TCIF_TEXT | (mp_Owner->GetTabIcons() ? TCIF_IMAGE : 0);
	tie.pszText = (LPWSTR)text ;
	tie.iImage = (iTabIcon > 0) ? iTabIcon : mp_Owner->GetTabIcon(bAdmin); // Пока иконка только одна - для табов со щитом
	int nCurCount = GetItemCountInt();

	if (i>=nCurCount)
	{
		DEBUGSTRTABS(L"Add", i, text);
		TabCtrl_InsertItem(mh_Tabbar, i, &tie);
	}
	else
	{
		// Проверим, изменился ли текст
		wchar_t sOldTabName[CONEMUTABMAX];
		if (!GetTabText(i, sOldTabName, countof(sOldTabName)) || !wcscmp(sOldTabName, text))
			tie.mask &= ~TCIF_TEXT;
		#ifdef _DEBUG
		else
			DEBUGSTRTABS(L"Set", i, text);
		#endif

		// Изменилась ли иконка
		if (tie.mask & TCIF_IMAGE)
		{
			TCITEM told;
			told.mask = TCIF_IMAGE;
			TabCtrl_GetItem(mh_Tabbar, i, &told);

			if (told.iImage == tie.iImage)
				tie.mask &= ~TCIF_IMAGE;
		}

		// "меняем" только если он реально меняется
		if (tie.mask)
			TabCtrl_SetItem(mh_Tabbar, i, &tie);
	}
}
Example #2
0
void CMDITabs::Update()
  {
  SetRedraw(false);
  
  HWND active = ::GetTopWindow(m_mdiClient); // get active view window (actually the frame of the view)
  
  typedef std::vector<HWND> TWndVec;
  typedef TWndVec::iterator TWndIter;
  
  TWndVec vChild; // put all child windows in a list (actually a vector)
  for (HWND child = active; child; child = ::GetNextWindow(child, GW_HWNDNEXT))
    {
    vChild.push_back(child);
    }
  
  TCITEM item;
//  char text[256];
//  item.pszText = text;
  
  int i;
  for (i = GetItemCount(); i--;)  // for each tab
    {
    item.mask = TCIF_PARAM;
    GetItem(i, &item);
    
    TWndIter it = std::find(vChild.begin(), vChild.end(), HWND(item.lParam));
    if (it == vChild.end()) // associatete view does no longer exist, so delete the tab
      {
      DeleteItem(i);
      if (m_bImages) RemoveImage(i);
      }
    else // update the tab's text, image and selection state
      {
      item.mask = TCIF_TEXT;
//      ::GetWindowText(*it, text, sizeof text);
      CString sText = GetTabText (*it);
      item.pszText = (char *) (LPCTSTR) sText;
      if (m_bImages) 
        m_images.Replace(i, (HICON)::GetClassLong(*it, GCL_HICONSM));
      SetItem(i, &item);
      if (*it == active) 
        SetCurSel(i); // associated view is active => make it the current selection
      vChild.erase(it);                // remove view from list
      }
    }
  
  // all remaining views in vChild have to be added as new tabs
  i = GetItemCount();
  for (TWndIter it = vChild.begin(), end = vChild.end(); it != end; ++it)
    {
    item.mask = TCIF_TEXT|TCIF_PARAM|TCIF_IMAGE;
//    ::GetWindowText(*it, text, sizeof text);
    CString sText = GetTabText (*it);
    item.pszText = (char *) (LPCTSTR) sText;
    if (m_bImages) 
      m_images.Add((HICON)::GetClassLong(*it, GCL_HICONSM));
    item.iImage = i;
    item.lParam = LPARAM(*it);
    InsertItem(i, &item);
    if (*it == active) SetCurSel(i);
    ++i;
    }
  
  // this removes the control when there are no tabs and shows it when there is at least one tab
  bool bShow = GetItemCount() >= m_minViews;
  if ((!bShow && IsWindowVisible()) || (bShow && !IsWindowVisible())) 
    {
    static_cast<CMDIFrameWnd*>(FromHandlePermanent(::GetParent(m_mdiClient)))->RecalcLayout();
    }
  
  RedrawWindow(NULL, NULL, RDW_FRAME|RDW_INVALIDATE|RDW_ERASE);
  SetRedraw(true);
  }