예제 #1
0
void CDocSelector::ResizeButtons(int NewSize)
{
//	Yogesh Jagota
//	if (NewSize < MINWIDTH || NewSize > DS_WIDTH)
//		return;
//	End Yogesh Jagota

	// Yogesh Jagota
	// We are having good space to draw the buttons...
	if ( NewSize > DS_WIDTH )
	{
		m_btnMenuButton.ShowWindow( SW_HIDE );
		return;
	}

	// Oh no! we are not...
	if ( NewSize < MINWIDTH )
	{
		m_btnMenuButton.ShowWindow( SW_SHOW );
		return;
	}

	CRect rRect;
	GetClientRect( &rRect );

	int nShow = SW_HIDE;
	// End Yogesh Jagota

	m_iButtonWidth = NewSize;
	m_iNextButtonStart = DS_LEFT_MARGIN;

	m_nDisplayedButtons = 0; // Yogesh Jagota
	for (register int x = 0; x < m_Buttons.GetSize(); x++)
	{
		CSwitcherButton* btn = (CSwitcherButton*)m_Buttons.GetAt(x);
		btn->SetWindowPos(NULL, m_iNextButtonStart, 3, 
			m_iButtonWidth, DS_HEIGHT - 2, SWP_NOZORDER|SWP_NOCOPYBITS);

		m_iNextButtonStart += m_iButtonWidth + DS_SEPERATER_MARGIN;

		// Yogesh Jagota
		btn->ShowWindow( SW_SHOW );

		if ( m_iNextButtonStart > ( rRect.Width() - DS_MENU_BUTTON_WIDTH ) )
		{
			for ( int i = x; i < m_Buttons.GetSize(); i++)
			{
				CSwitcherButton* btn = ( CSwitcherButton *) m_Buttons.GetAt( i );

				btn->ShowWindow( SW_HIDE );
			}

			nShow = SW_SHOW;
			break;
		}

		m_nDisplayedButtons++;
		// End Yogesh Jagota
	}

	RedrawWindow();

	m_btnMenuButton.ShowWindow( nShow ); // Yogesh Jagota
}
예제 #2
0
/////////////////////////////////////////////////////////////////////////////
// CDocSelector message handlers
BOOL CDocSelector::AddButton( CWnd* wnd, WORD wIcon ,HICON hIcon )
{
	CRect rect;
	GetClientRect(&rect);

	// Yogesh Jagota
	CDocument* pDoc = ((CView *) wnd)->GetDocument();

	CString sPath = pDoc->GetPathName();
	CString sFileName;
	
	if ( sPath.IsEmpty() )
		sPath = pDoc->GetTitle();

	// Can be only the filename, like Noname01
	if ( sPath.Find( _T('\\') ) != -1 )
		sFileName = sPath.Mid( sPath.ReverseFind( _T('\\') ) + 1 );
	else
		sFileName = sPath;

	// If there is no space left to display extra buttons...
	int nNewSize = ( ( rect.Width() - DS_MENU_BUTTON_WIDTH ) 
		/ ( m_Buttons.GetSize() + 1 ) ) - DS_SEPERATER_MARGIN;

	bool bShowButton = true;
	if ( nNewSize <= MINWIDTH )
	{
		// Check if the menu button is displayed, if not, display it...
		m_btnMenuButton.ShowWindow( SW_SHOW );

		// Don't show the button...
		bShowButton = false;
	}
	else
		m_nDisplayedButtons++;

	// End Yogesh Jagota

	CSwitcherButton* newbutton = new CSwitcherButton();

	 // Yogesh Jagota
	newbutton->m_AttachedView = wnd;

	// I am saving the frame to make life easier in case
	// of activation in selection process...
	CMDIFrameWnd *pFrame = (CMDIFrameWnd *)AfxGetMainWnd();
	CWnd * pWnd = pFrame->GetWindow( GW_CHILD );
	ASSERT (pWnd);
	pWnd = pWnd->GetWindow( GW_CHILD );
	while (pWnd)
	{
		if ( ((CFrameWnd *)pWnd)->GetActiveView() == (CView*)wnd )
			newbutton->m_FrameWnd = (CFrameWnd *)pWnd;

		pWnd = pWnd->GetWindow( GW_HWNDNEXT );
	}

	// Load the icon....
	if ( hIcon)
	{
		newbutton->m_iIcon=hIcon;
		newbutton->m_iIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	}
	
	else

	if ( wIcon != -1 )
		newbutton->m_iIcon = ::LoadIcon( AfxGetInstanceHandle(), 
			MAKEINTRESOURCE( wIcon ) );
	// End Yogesh Jagota

	newbutton->m_iID = m_Buttons.GetSize();
	if (!newbutton->DoCreate(this, m_iNextButtonStart, 
		rect.top + 3, m_iButtonWidth, DS_HEIGHT - 2, 
		sFileName, sPath )) // Yogesh Jagota
	{
		return FALSE;
	}

	if ( !bShowButton )
		newbutton->ShowWindow( SW_HIDE );

	m_Buttons.Add((void*)newbutton);
	m_iNextButtonStart += m_iButtonWidth + DS_SEPERATER_MARGIN;

	if (m_iNextButtonStart - DS_SEPERATER_MARGIN > rect.Width())
	{
		// this loop makes a neat little animation
		int newsize = ((rect.Width() - DS_MENU_BUTTON_WIDTH ) 
			/ (m_Buttons.GetSize())) - DS_SEPERATER_MARGIN;

//		Yogesh Jagota. Removed animation because did'nt liked it.
//		Remove if you want animated addition or removal of buttons.
//
//		register int y;
//		for (y = m_iButtonWidth; y >= newsize; y-=3)
//		{
//			ResizeButtons(y);
//			Sleep(15);
//		}
//
//		if (y != newsize)
//			/* ResizeButtons(newsize); */ <- this is the next line...
//		End Yogesh Jagota

		ResizeButtons(newsize);

		if (m_iButtonWidth < MINWIDTH)
		{
			// the smallest allowable button size has been reached...
			// in this version, we can't handle this
			ASSERT(0);
			return FALSE;
		}
	}
	else
		m_btnMenuButton.ShowWindow( SW_HIDE );

	// Yogesh Jagota
	if ( m_iSelectedButton != -1 )
		((CSwitcherButton *) m_Buttons.GetAt( m_iSelectedButton ))->Unselect();

	m_iSelectedButton = newbutton->m_iID;
	((CSwitcherButton *) m_Buttons.GetAt( m_iSelectedButton ))->Select();
	// End Yogesh Jagota

	return TRUE;
}