Click here to Skip to main content
15,892,746 members
Articles / Desktop Programming / MFC

A Java Language IDE

Rate me:
Please Sign up or sign in to vote.
4.33/5 (26 votes)
13 May 2004CPOL3 min read 80.6K   3.4K   41  
This is a partially implemented IDE for the Java platform.
// SheetWnd.cpp : implementation file
//

#include "stdafx.h"
#include "SheetWnd.h"
#include "resource.h"
#include "XPDrawLayer.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSheetWnd
#define ID_HSCROLLBAR_     0x44
#define ID_LEFTSCROLLBAR   0x45

#define TAB_HEIGHT         18

#define ALIGN_LEFT         0x01
#define ALIGN_RIGHT        0x02
#define ALIGN_UP           0x03
#define ALIGN_DOWN         0x04


static  BOOL m_bInit = TRUE;
static  BOOL m_bScrolled = FALSE;

CSheetWnd::CSheetWnd():m_GripperRect(0,0,3,0)
{
  m_pCurItem = NULL;
  m_bTracking = FALSE;
}

CSheetWnd::~CSheetWnd()
{
  for(int pos =0; pos<m_lItems.GetSize();pos++)
	 delete m_lItems[pos];
}


BEGIN_MESSAGE_MAP(CSheetWnd, CWnd)
	//{{AFX_MSG_MAP(CSheetWnd)
	ON_WM_PAINT()
	ON_WM_CREATE()
	ON_WM_LBUTTONDOWN()
	ON_WM_SIZE()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_WM_SETCURSOR()
	ON_WM_VSCROLL()
	ON_WM_HSCROLL()
	ON_WM_NCCALCSIZE()
	//}}AFX_MSG_MAP
	ON_WM_NCPAINT()
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CSheetWnd message handlers

void CSheetWnd::OnNcPaint()
{
    // get window DC that is clipped to the non-client area
    CWindowDC dc(this);

    CRect rcClient, rcBar;
    GetClientRect(rcClient);
    ClientToScreen(rcClient);
    GetWindowRect(rcBar);
    rcClient.OffsetRect(-rcBar.TopLeft());
    rcBar.OffsetRect(-rcBar.TopLeft());

    CDC mdc;
    mdc.CreateCompatibleDC(&dc);
    
    CBitmap bm;
    bm.CreateCompatibleBitmap(&dc, rcBar.Width(), rcBar.Height());
    CBitmap* pOldBm = mdc.SelectObject(&bm);

    // client area is not our bussiness :)


    dc.ExcludeClipRect(rcClient);

    // draw borders in non-client area
    CRect rcDraw = rcBar;
    mdc.FillRect(rcDraw,&m_brBackground);

	
	rcDraw.DeflateRect(0,0,0,17);
    //mdc.FillRect(rcDraw,&m_brBackground);


	/*
    CPen nPen(PS_SOLID,1,RGB(0,0,0));
	CPen* pOldPen = mdc.SelectObject(&nPen);
	mdc.MoveTo(0,rcDraw.bottom-18);
	mdc.LineTo(0,rcDraw.bottom);
	mdc.SelectObject(pOldPen);
    */
	
	// erase parts not drawn
    //mdc.IntersectClipRect(rcDraw);

    // erase the NC background
	mdc.FillSolidRect(rcDraw,RGB(0,0,0));



    dc.BitBlt(0, 0, rcBar.Width(), rcBar.Height(), &mdc, 0, 0, SRCCOPY);

    ReleaseDC(&dc);

    mdc.SelectObject(pOldBm);
    bm.DeleteObject();
    mdc.DeleteDC();
}


void CSheetWnd::OnPaint() 
{
  //CWnd::OnPaint();
  CPaintDC dc(this); // device context for painting
  CDC mdc;
  CRect rc;

  /*
  if(m_bInit)
  {
	CRect rt;
	GetParent()->GetClientRect(&rt);
    CRect rt1(rt.left,rt.bottom-18,rt.right,rt.bottom);
    MoveWindow(rt1);
	m_bInit = FALSE;
  }
  

  {
    CRect rt;
    GetParent()->GetClientRect(&rt);
	CRect rc(0,rt.bottom-18,rt.right,rt.bottom);
	MoveWindow(&rc);
  }
  */

  GetClientRect(&rc);

  mdc.CreateCompatibleDC(&dc);
  CBitmap bm;
  bm.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
  CBitmap* pOldBm = mdc.SelectObject(&bm);

  CBrush br;
  br.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  mdc.FillRect(rc,&br);//draw bk
  br.DeleteObject();

  if(m_lItems.GetSize()>0)
     DrawItemsEx(&mdc);
  dc.BitBlt(0, 0, rc.Width(), rc.Height(), &mdc, 0, 0, SRCCOPY);

  mdc.SelectObject(pOldBm);
  ReleaseDC(&dc);
  bm.DeleteObject();
  mdc.DeleteDC();
}

void CSheetWnd::DrawItem(CDC *pDC)
{
	CRect rt1;
	GetClientRect(&rt1);

	pDC->FillRect(rt1,&m_brBackground);//draw bk


	SHEETITEM* pPrev = NULL;
	for(int pos = 0; pos<m_lItems.GetSize(); pos++)
	{
	    SHEETITEM* pItem = m_lItems[pos];
		CSize sz = pDC->GetTextExtent(pItem->m_pszLabel);

        if(pPrev != NULL)
		{
           int x1 = pPrev->m_nRect.right+2;
		   int x2 = x1+sz.cx+5;
           pItem->m_nRect.SetRect(x1,(rt1.bottom-sz.cy)-5,x2,rt1.bottom);
		}
		else
		{
          pItem->m_nRect.SetRect(rt1.left+32,
	                    (rt1.bottom-sz.cy)-5,
						rt1.left+32+sz.cx+5,
						rt1.bottom);

		}
       if((m_pCurItem != NULL)&&(m_pCurItem == pItem))
	       DrawSelection(pDC,pItem);	   
	   
	   //DrawTabBtn(pDC,pItem);
         DrawVcppStyle(pDC,pItem);
       CString pszLabel = pItem->m_pszLabel;
       	   
	   CFont* def_font = pDC->SelectObject(&font);
	   CRect rc(pItem->m_nRect);
	   rc.DeflateRect(5,5,0,0);
       int nPrevMode = pDC->SetBkMode(TRANSPARENT);
	   pDC->TextOut(rc.left,rc.top,pszLabel);
	   pDC->SelectObject(def_font);
	   pDC->SetBkMode(nPrevMode);
 	   
	   pPrev = pItem;
	}

	if(m_GripperRect.IsRectEmpty())
	{
	    m_GripperRect.SetRect(rt1.right/2,rt1.top,(rt1.right/2)+3,rt1.bottom);
		CRect sRt(m_GripperRect.right+1,rt1.top,rt1.right-14,rt1.bottom);
		m_wndHScrollBar.MoveWindow(sRt);
	}
	else
	if(!m_bScrolled&&(pPrev!=NULL))
	{
		if((pPrev->m_nRect.right > m_GripperRect.left))
		{
          int x1 = pPrev->m_nRect.right;
	      m_GripperRect.SetRect(x1+20,rt1.top,x1+23,rt1.bottom);
		  CRect sRt(m_GripperRect.right+1,rt1.top,rt1.right-14,rt1.bottom);
		  m_wndHScrollBar.MoveWindow(sRt);
		}
	}

    //draw gripper
	pDC->Draw3dRect(m_GripperRect,RGB(255,255,255),RGB(0,0,0));
}

void CSheetWnd::GetClientRect(LPRECT lpRect) const
{
	CWnd::GetClientRect(lpRect);
}

void CSheetWnd::DrawItemsEx(CDC* pDC)
{
	CRect rt1;
	GetClientRect(&rt1);
	rt1.DeflateRect(0,rt1.Height()-18,0,0);//normalize

    //draw scrollers
	CRect rcScrollRect(0,rt1.top+1,17,rt1.bottom);
	CRect rcLeftScrollArrow(rcScrollRect);
	

	//******************super left scroller*******************//
	COLORREF rfArrow = RGB(0,0,0);
	rcLeftScrollArrow.DeflateRect(8,2,2,2);
	CRect rcDef(rcLeftScrollArrow);
	//rcDef.DeflateRect(0,0,1,0);
    //pDC->Draw3dRect(rcDef,RGB(255,255,255),RGB(243,255,23));

    DrawArrow(pDC,rcLeftScrollArrow,rfArrow,ALIGN_LEFT);
	rcLeftScrollArrow.DeflateRect(0,2,rcLeftScrollArrow.Width()+1,2);
	pDC->FillSolidRect(rcLeftScrollArrow,rfArrow);


	//******************left scroller*************************//
    rcScrollRect.OffsetRect(rcScrollRect.Width(),0);
	rcLeftScrollArrow.SetRect(rcScrollRect.TopLeft(),rcScrollRect.BottomRight());
	
	rcLeftScrollArrow.DeflateRect(8,2,2,2);
    //pDC->Draw3dRect(rcScrollRect,RGB(255,255,255),RGB(243,255,23));
    DrawArrow(pDC,rcLeftScrollArrow,rfArrow,ALIGN_LEFT);

    //*****************right scroller*************************//
    rcScrollRect.OffsetRect(rcScrollRect.Width(),0);
	rcLeftScrollArrow.SetRect(rcScrollRect.TopLeft(),rcScrollRect.BottomRight());
	
	rcLeftScrollArrow.DeflateRect(2,2,8,2);
    //pDC->Draw3dRect(rcScrollRect,RGB(255,255,255),RGB(243,255,23));
    DrawArrow(pDC,rcLeftScrollArrow,rfArrow,ALIGN_RIGHT);

	//******************super right scroller******************//
    rcScrollRect.OffsetRect(rcScrollRect.Width(),0);
	rcLeftScrollArrow.SetRect(rcScrollRect.TopLeft(),rcScrollRect.BottomRight());
	
	rcLeftScrollArrow.DeflateRect(2,2,8,2);
    //pDC->Draw3dRect(rcScrollRect,RGB(255,255,255),RGB(243,255,23));

    DrawArrow(pDC,rcLeftScrollArrow,rfArrow,ALIGN_RIGHT);
	rcLeftScrollArrow.DeflateRect(rcLeftScrollArrow.Width()+1,2,0,2);
	pDC->FillSolidRect(rcLeftScrollArrow,rfArrow);



	SHEETITEM* pPrev = NULL;
	for(int pos =0;pos< m_lItems.GetSize();pos++)
	{
	    SHEETITEM* pItem = m_lItems[pos];


        if(m_pCurItem != pItem)
		{
          DrawVcppStyle(pDC,pItem);
       	   
	      CFont* def_font = pDC->SelectObject(&font);

          int nPrevMode = pDC->SetBkMode(TRANSPARENT);
		  CString strText = pItem->m_pszLabel;
		  CRect rcText(pItem->m_nRect);
		  rcText.InflateRect(5,0,5,0);

	      CSize sz  = pDC->GetTextExtent(pItem->m_pszLabel);
	      int xShrink  = (rcText.Width()-sz.cx)/2;
	      int yShrink  = (rcText.Height()-sz.cy)/2;
	      pDC->TextOut(rcText.left+xShrink,rcText.top+yShrink,strText);


	      pDC->SelectObject(def_font);
	      pDC->SetBkMode(nPrevMode);
	   }
 	   
	   pPrev = pItem;
	}
        //draw selection
	   DrawVcppStyle(pDC,m_pCurItem);

	   //DrawSelVCppStype(pDC,m_pCurItem);
       DrawSelVCppStype3d(pDC,m_pCurItem);
	   CFont bold;
	   bold.CreatePointFont(70,"Arial Black");
	   CFont* def_font = pDC->SelectObject(&bold);

       int nPrevMode = pDC->SetBkMode(TRANSPARENT);
	   //center text
	   {
		 CString strText = m_pCurItem->m_pszLabel;
		 CRect rcText(m_pCurItem->m_nRect);
		 rcText.InflateRect(5,0,5,0);

	     CSize sz  = pDC->GetTextExtent(m_pCurItem->m_pszLabel);
	     int xShrink  = (rcText.Width()-sz.cx)/2;
	     int yShrink  = (rcText.Height()-sz.cy)/2;
	     pDC->TextOut(rcText.left+xShrink,rcText.top+yShrink,strText);
	   }
	   pDC->SelectObject(def_font);
	   pDC->SetBkMode(nPrevMode);

	//TO THE LEFT
	{
      CPen nPen(PS_SOLID,1,RGB(0,0,0));
	  CPen* pOldPen = pDC->SelectObject(&nPen);
	  pDC->MoveTo(0,rt1.top);
	  pDC->LineTo(m_pCurItem->m_nRect.left-1,rt1.top);
	  pDC->SelectObject(pOldPen);
	}

    //TO THE RIGHT
	{
	   //draw styler
       CPen nPen(PS_SOLID,1,RGB(0,0,0));
	   CPen* pOldPen = pDC->SelectObject(&nPen);
	   pDC->MoveTo(m_pCurItem->m_nRect.right+1,rt1.top);
	   pDC->LineTo(m_GripperRect.right,rt1.top);
	   pDC->SelectObject(pOldPen);
	}

    //draw gripper
	pDC->Draw3dRect(m_GripperRect,RGB(255,255,255),RGB(0,0,0));
}

BOOL CSheetWnd::SetItem(CWnd* pwndItem,CString pszLabel,int nIndex,
						                                int nScrollBar /*= -1*/)
{
   if(nIndex != -1&& nIndex<m_lItems.GetSize())
   {
     m_lItems[nIndex]->m_nScrollBar = nScrollBar;
     m_lItems[nIndex]->m_pszLabel   = pszLabel;
     m_lItems[nIndex]->m_pwndItem   = pwndItem;
	 return TRUE;
   }
   return FALSE;
}

BOOL CSheetWnd::RemoveItem(int nIndex)
{
  if(nIndex<m_lItems.GetSize())
  {
    delete m_lItems[nIndex];
    m_lItems.RemoveAt(nIndex);
    Invalidate();
    UpdateWindow();
	return TRUE;
  }
  return FALSE;
}

int  CSheetWnd::SetCurSel(int nSelect)
{
  if(nSelect < m_lItems.GetSize())
  {
    m_pCurItem = m_lItems[nSelect];
	TabSelChanged(nSelect);
	Invalidate();UpdateWindow();
	return nSelect;
  }return -1;
}


int  CSheetWnd::GetCurSel()
{
  if(m_pCurItem != NULL)
	return m_pCurItem->m_nPos;
  else
 	return -1;
}


BOOL CSheetWnd::AddItem(CWnd* pwndItem,CString pszLabel,int nScrollBar /*= -1*/)
{
   CRect rcClt;
   GetClientRect(&rcClt);
   CDC *pDC = GetDC();

   if(pwndItem != NULL)
   {
     SHEETITEM* pItem = new SHEETITEM;

     pItem->m_nScrollBar = nScrollBar;
     pItem->m_nPos       = m_lItems.GetSize();
     pItem->m_pszLabel   = pszLabel;
     pItem->m_pwndItem   = pwndItem; 
  
	 if(m_lItems.GetSize() == 0)
	 {
		CSize sz = pDC->GetTextExtent(pItem->m_pszLabel);
        pItem->m_nRect.SetRect(68,rcClt.top,78+sz.cx,rcClt.bottom-5);

	    m_pCurItem = pItem;//select first item
	    m_pCurItem->m_pwndItem->BringWindowToTop();
	 }
     else
	 {
	    SHEETITEM* pTailItem = m_lItems[m_lItems.GetSize()-1];
		CRect rcTail = pTailItem->m_nRect;
		CSize sz = pDC->GetTextExtent(pItem->m_pszLabel);
        pItem->m_nRect.SetRect(rcTail.right,rcClt.top,rcTail.right+sz.cx+10,rcClt.bottom-5);
	 }
     m_GripperRect.OffsetRect(pItem->m_nRect.Width()+30,0);


	 m_bInit = TRUE;
     m_lItems.Add(pItem);
	 //Invalidate();
	 //UpdateWindow();
	 return TRUE;
   }
   return FALSE;
}


int CSheetWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
   m_wndHScrollBar.Create(WS_CHILD| SBS_HORZ|WS_VISIBLE,CRect(),this,ID_HSCROLLBAR_);
   SCROLLINFO info;
   info.cbSize = sizeof(SCROLLINFO);     
   info.fMask  = SIF_ALL;     
   info.nMin   = 0;     
   info.nMax   = 100; 
   info.nPage  = 0;     
   info.nPos   = 0;    
   info.nTrackPos = 2; 
   m_wndHScrollBar.SetScrollInfo(&info);

   m_brBackground.CreateSolidBrush(GetSysColor(COLOR_3DFACE)/*GuiDrawLayer::GetRGBColorXP()*/);
   VERIFY(font.CreatePointFont(100, "Times New Roman", GetDC()));
   return 0;
}

void CSheetWnd::OnLButtonDown(UINT nFlags, CPoint point) 
{
	
   if(!m_bTracking&&m_GripperRect.PtInRect(point)&&!GetCapture())
   {
	 SetCapture();
	 m_bTracking = TRUE;
     return;
   }

   SHEETITEM* temp = GetCurItem(point);
   if(temp != m_pCurItem&&temp!=NULL)
   {
	 /*TabSelChanged(temp->m_nPos);
     CString szpBuff;
	 temp->m_pwndItem->GetWindowText(szpBuff);
	 CString szpBuff1;
	 m_pCurItem->m_pwndItem->GetWindowText(szpBuff1);
		
	 if(szpBuff.IsEmpty()&&szpBuff1.IsEmpty())
	 {
		m_pCurItem = temp; 	Invalidate();
	    SendMessage(WM_PAINT);return;
	 }*/
		/*
	    SetParent(temp->m_pwndItem);
	    temp->m_pwndItem->ShowWindow(SW_SHOW);
	    temp->m_pwndItem->SetFocus();
	    m_bInit = TRUE;

		//hide previous item
	    m_pCurItem->m_pwndItem->ShowWindow(SW_HIDE);
		//set new selection
		*/
	    temp->m_pwndItem->BringWindowToTop();
        temp->m_pwndItem->SetFocus();
        m_pCurItem = temp;
		
		Invalidate();
		UpdateWindow();
        temp->m_pwndItem->Invalidate();
        temp->m_pwndItem->UpdateWindow();
	}
	Invalidate();
	UpdateWindow();
	//SendMessage(WM_NCPAINT);
}

SHEETITEM* CSheetWnd::GetCurItem(CPoint pt)
{
  for(int npos =0; npos<m_lItems.GetSize(); npos++)
  {
      SHEETITEM* pItem = m_lItems[npos];
	  if(pItem->m_nRect.PtInRect(pt))
		  return pItem;
  }
  return NULL;
}


void CSheetWnd::OnSize(UINT nType, int cx, int cy) 
{
	CWnd::OnSize(nType,cx,cy);
    RecalcLayout();

    


	/*
	//update gripper
	CRect rcClient;
	GetClientRect(&rcClient);
    

    /*if(!m_GripperRect.IsRectEmpty())
	{
	   int nOffset = m_GripperRect.right-rcClient.right;
	   m_GripperRect.OffsetRect(nOffset,0);
	   //if(nW<50)
	   //{
       //  m_GripperRect.OffsetRect(nW-50,0);
	   //}

	   m_wndHScrollBar.MoveWindow
	   (m_GripperRect.right+1,rcClient.bottom-18,rcClient.right-16,rcClient.bottom);
	}
	else*
	{
	   CRect rcStart(0,0,0,0);
       if(size>0)
         rcStart = m_lItems[size-1]->m_nRect;

	   CRect rcGrip(rcStart.right+5,cy-16,rcStart.right+7,cy-2);
       m_wndHScrollBar.MoveWindow(rcGrip.right+2,cy-18,cx-18,cy-2);
	}
	*/
}



void CSheetWnd::DrawTabBtn(CDC* pDC, SHEETITEM *pItem)
{
  int x1 = pItem->m_nRect.left;
  int x2 = pItem->m_nRect.right;
  int y1 = pItem->m_nRect.top;
  int y2 = pItem->m_nRect.bottom;

   // create and select a thick, black pen
   CPen penBlack;
   penBlack.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
   CPen* pOldPen = pDC->SelectObject(&penBlack);

   //left line
   pDC->MoveTo(x1,y1);
   pDC->LineTo(x1,y2-2);

   //draw left corner with this diagonal
   pDC->SetPixel(x1+1,y2-2,RGB(0,0,0));
   pDC->SetPixel(x1+2,y2-1,RGB(0,0,0));
   pDC->SetPixel(x1+3,y2,RGB(0,0,0));

   //rigt line
   pDC->MoveTo(x2,y1);
   pDC->LineTo(x2,y2-2);

   //draw right corner with this diagonal
   pDC->SetPixel(x2-1,y2-2,RGB(0,0,0));
   pDC->SetPixel(x2-2,y2-1,RGB(0,0,0));
   pDC->SetPixel(x2-3,y2,RGB(0,0,0));


   //bottom line
   pDC->MoveTo(x1+3,y2-1);
   pDC->LineTo(x2-3,y2-1);

   // put back the old objects
   pDC->SelectObject(pOldPen);
}

void CSheetWnd::DrawSelection(CDC *pDC, SHEETITEM *pItem)
{
   //create and select a solid blue brush
   CBrush brush(RGB(255,255,255));
   CBrush* pOldBrush = pDC->SelectObject(&brush);
   CRect rc(pItem->m_nRect);
   rc.DeflateRect(3,0,3,3);
   pDC->FillRect(&rc,&brush);
   pDC->SelectObject(pOldBrush);

   CRect rc1;
   GetClientRect(&rc1);

   CPen penBlack;
   penBlack.CreatePen(PS_SOLID,1, RGB(0,0,0));
   CPen* pOldPen = pDC->SelectObject(&penBlack);
   //draw to the left
   pDC->MoveTo(CPoint(rc1.left,rc1.top));
   pDC->LineTo(rc.left-4,rc1.top);
   //draw to the right
   pDC->MoveTo(rc.right+4,rc1.top);
   pDC->LineTo(m_GripperRect.left,rc1.top);
   pDC->SelectObject(pOldPen);
}


void CSheetWnd::OnMouseMove(UINT nFlags, CPoint point) 
{
    if(m_bTracking)
	ResizePane(point);
	CWnd::OnMouseMove(nFlags, point);
}

void CSheetWnd::OnLButtonUp(UINT nFlags, CPoint point) 
{
    if(m_bTracking)
      ReleaseCapture();

	m_bTracking = FALSE;
	CWnd::OnLButtonUp(nFlags, point);
}

BOOL CSheetWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	CPoint pCursor;
	if(GetCursorPos(&pCursor))
	{
		ScreenToClient(&pCursor);
		if (m_GripperRect.PtInRect(pCursor))
		{
			::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_MOVE));	
			return TRUE;
		}
	}	
	return CWnd::OnSetCursor(pWnd, nHitTest, message);
}

void CSheetWnd::ResizePane(CPoint pt)
{
  CRect rt;
  GetClientRect(&rt);

  CRect sr;
  m_wndHScrollBar.GetClientRect(&sr);
  if(pt.x>=rt.left+32&&pt.x<=rt.right-60)
  {
     m_GripperRect.OffsetRect(pt.x-m_GripperRect.left,0);
     CRect sRt(m_GripperRect.right+1,rt.bottom-18,rt.right-18,rt.bottom);
     
	 m_wndHScrollBar.MoveWindow(sRt);
	 m_wndHScrollBar.UpdateWindow();
	 	
	 Invalidate();
	 UpdateWindow();
     m_bScrolled = TRUE;
  }
}



void CSheetWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
    	
	CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CSheetWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
  // Get the minimum and maximum scroll-bar positions.
   int minpos;
   int maxpos;
   m_wndHScrollBar.GetScrollRange(&minpos, &maxpos); 
   maxpos = m_wndHScrollBar.GetScrollLimit();

   // Get the current position of scroll box.
   int curpos = pScrollBar->GetScrollPos();

   // Determine the new position of scroll box.
   switch (nSBCode)
   {
   case SB_LEFT:      // Scroll to far left.
      curpos = minpos;
      break;

   case SB_RIGHT:      // Scroll to far right.
      curpos = maxpos;
      break;

   case SB_ENDSCROLL:   // End scroll.
      break;

   case SB_LINELEFT:      // Scroll left.
      if (curpos > minpos)
         curpos--;
      break;

   case SB_LINERIGHT:   // Scroll right.
      if (curpos < maxpos)
         curpos++;
      break;

   case SB_PAGELEFT:    // Scroll one page left.
   {
      // Get the page size. 
      SCROLLINFO   info;
      m_wndHScrollBar.GetScrollInfo(&info, SIF_ALL);
   
      if (curpos > minpos)
      curpos = max(minpos, curpos - (int) info.nPage);
   }
      break;

   case SB_PAGERIGHT:      // Scroll one page right.
   {
      // Get the page size. 
      SCROLLINFO   info;
      m_wndHScrollBar.GetScrollInfo(&info, SIF_ALL);

      if (curpos < maxpos)
         curpos = min(maxpos, curpos + (int) info.nPage);
   }
      break;

   case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
      curpos = nPos;      // of the scroll box at the end of the drag operation.
      break;

   case SB_THUMBTRACK:   // Drag scroll box to specified position. nPos is the
      curpos = nPos;     // position that the scroll box has been dragged to.
      break;
   }

   // Set the new position of the thumb (scroll box).
   m_wndHScrollBar.SetScrollPos(curpos);

   CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CSheetWnd::ResizeItems(CRect rc)
{
  for(int pos =0;pos< m_lItems.GetSize(); pos++)
  {
    SHEETITEM *pItem = m_lItems[pos];
	pItem->m_pwndItem->MoveWindow(0,0,rc.right,rc.bottom);
  }
}



void CSheetWnd::OnNcCalcSize(BOOL bCalcValidRects,NCCALCSIZE_PARAMS* lpncsp)
{
  CRect rc(lpncsp->rgrc[0]); // save the window rect
  rc.DeflateRect(1,1,1,0);
  lpncsp->rgrc[0] = rc;
}

void CSheetWnd::DrawBorders(CDC *pDC, CRect rc)
{

}

void CSheetWnd::DrawVcppStyle(CDC *pDC,SHEETITEM *pItem)
{
  int x1 = pItem->m_nRect.left;
  int x2 = pItem->m_nRect.right;
  int y1 = pItem->m_nRect.top;
  int y2 = pItem->m_nRect.bottom;

   // create and select a thick, black pen
   CPen penBlack;
   penBlack.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
   CPen* pOldPen = pDC->SelectObject(&penBlack);

   //left line
   pDC->MoveTo(x1-5,y1);
   //draw a diagonal line downwards
   pDC->LineTo(x1+3,y2-2);


   //right line
   pDC->MoveTo(x2+5,y1);
   pDC->LineTo(x2-3,y2-2);



   //bottom line
   pDC->MoveTo(x1+3,y2-2);
   pDC->LineTo(x2-2,y2-2);

   // put back the old objects
   pDC->SelectObject(pOldPen);

   int nwidth  = x2+4;
   int nheight = y2-2;
   x1 = x1-4;

   for(int y =y1;y<nheight;y++)
   {
     for(int x=x1;x<nwidth;x++)
	 {
	   CPoint pt(x,y);
	   if(pItem != m_pCurItem)
         pDC->SetPixel(pt,GuiDrawLayer::GetRGBColorXP());
	   else
		 pDC->SetPixel(pt,GuiDrawLayer::GetRGBPressBXP());
	 }

	 if(y%2 == 0)
	 {
	   ++x1;--nwidth;
	 }
   }

}

void CSheetWnd::DrawVcpp3DStyle(CDC *pDC,SHEETITEM *pItem)
{

}

void CSheetWnd::TabSelChanged(int nSel)
{
  SHEETITEM* pitem = m_lItems[nSel];
  if(pitem->m_nScrollBar != -1)
  {
    if(pitem->m_nScrollBar & BOTH_SB)
	{
      m_wndHScrollBar.ShowWindow(SW_SHOW);
	  m_wndVScrollBar.ShowWindow(SW_SHOW);
	}
	else
	if(pitem->m_nScrollBar & HORZ_SB)
	{
      m_wndHScrollBar.ShowWindow(SW_SHOW);
	  m_wndVScrollBar.ShowWindow(SW_HIDE);
	}
	else
	{
      m_wndHScrollBar.ShowWindow(SW_HIDE);
	  m_wndVScrollBar.ShowWindow(SW_SHOW);
	}
  }
}

void CSheetWnd::DrawSelVCppStype(CDC* pDC, SHEETITEM *pItem)
{
   int x1 = pItem->m_nRect.left;
   int x2 = pItem->m_nRect.right;
   int y1 = pItem->m_nRect.top;
   int y2 = pItem->m_nRect.bottom;
  
  
   int nwidth  = x2+5;
   int nheight = y2-2;
   x1 = x1-4;

   for(int y =y1;y<nheight;y++)
   {
     for(int x=x1;x<nwidth;x++)
	 {
	   CPoint pt(x,y);
       pDC->SetPixel(pt,RGB(255,255,255));
	 }
	 if(y%2 == 0)
	 {
		 ++x1;--nwidth;
	 }
   }
   
   CPen blackPen;
   blackPen.CreatePen(PS_SOLID,2, RGB(0,0,0));
   CPen* pOldPen = pDC->SelectObject(&blackPen);	   
   
   CRect rc1;
   GetClientRect(&rc1);
   CRect rc(pItem->m_nRect);rc.DeflateRect(3,0,3,3);
   //draw to the left
   pDC->MoveTo(rc1.left,rc1.top);
   pDC->LineTo(rc.left-6,rc1.top);
   //draw to the right
   pDC->MoveTo(rc.right+7,rc1.top);
   pDC->LineTo(m_GripperRect.left,rc1.top);
   pDC->SelectObject(pOldPen);
}

void CSheetWnd::DrawSelVCppStype3d(CDC* pDC, SHEETITEM *pItem)
{

   CRect rc(pItem->m_nRect);
   rc.DeflateRect(3,0,3,3);
   int x1 = rc.left;
   int x2 = rc.right;
   int y1 = rc.top;
   int y2 = rc.bottom;


   int nwidth  = x2+5;
   int nheight = y2-2;
   int xx1 = x1-4;

   for(int y =y1;y<nheight;y++)
   {
     for(int x=xx1;x<nwidth;x++)
	 {
	   CPoint pt(x,y);
       pDC->SetPixel(pt,RGB(255,255,255));
	 }

	 if(y%2 == 0)
	 {
		 ++xx1;--nwidth;}
   }

   // create and select a thick, black pen
   CPen penBlack;
   penBlack.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
   CPen* pOldPen = pDC->SelectObject(&penBlack);

   //left line
   pDC->MoveTo(x1-3,y1);
   //draw a diagonal line downwards
   pDC->LineTo(x1+3,y2-2);


   //right line
   pDC->MoveTo(x2+3,y1);
   //draw a diagonal line downwards
   pDC->LineTo(x2-3,y2-2);


   //bottom line
   pDC->MoveTo(x1+3,y2-2);
   pDC->LineTo(x2-2,y2-2);

   // put back the old objects
   pDC->SelectObject(pOldPen);



   CPen blackPen;
   blackPen.CreatePen(PS_SOLID,2, RGB(0,0,0));
   pOldPen = pDC->SelectObject(&blackPen);	   
   
   CRect rc1;
   GetClientRect(&rc1);
   CRect rx(pItem->m_nRect);rx.DeflateRect(3,0,3,3);
   //draw to the left
   pDC->MoveTo(rc1.left,rc1.top);
   pDC->LineTo(rx.left-6,rc1.top);
   //draw to the right
   pDC->MoveTo(rx.right+7,rc1.top);
   pDC->LineTo(m_GripperRect.left,rc1.top);
   pDC->SelectObject(pOldPen);
}

void CSheetWnd::DrawArrow(CDC* pDC,CRect rcSrc/*this must have odd dimensions*/
			   ,COLORREF cfColor,UINT nAlign)
{
  switch(nAlign)
  {
    case ALIGN_LEFT:
	{
	  CPen taPen(PS_SOLID,1,cfColor);
	  CPen* pOldPen = pDC->SelectObject(&taPen);
      int nStartPexil = (rcSrc.Height()/2);
      
	  int y = rcSrc.top+nStartPexil;
	  for(int x = rcSrc.left+1; x<rcSrc.right-2; x++)
	  {
		pDC->SetPixel(x,y,RGB(0,0,0)/*cfColor*/);
		--y;
	  }

	  y = rcSrc.bottom-nStartPexil;
	  for(x = rcSrc.left+1; x<rcSrc.right-2; x++)
	  {
        pDC->SetPixel(x,y,RGB(0,0,0)/*cfColor*/);
		++y;
	  }

	  
	  int ty = rcSrc.top+nStartPexil;
	  int by = rcSrc.bottom-nStartPexil;

	  for(x = rcSrc.left+1; x<rcSrc.right-2; x++)
	  {
        for(y =ty; y<by; y++)
		pDC->SetPixel(x,y,cfColor);
		++by;
		--ty;
	  }

	  //very peek of triangle
	  //pDC->SetPixel(rcSrc.left,rcSrc.top+nStartPexil,cfColor);
	  pDC->SelectObject(pOldPen);
	  taPen.DeleteObject();
	  return;
	}
	case ALIGN_RIGHT:
	{
	  CPen taPen(PS_SOLID,1,cfColor);
	  CPen* pOldPen = pDC->SelectObject(&taPen);
      int nStartPexil = (rcSrc.Height()/2);
      
	  int y = rcSrc.top+nStartPexil;
	  for(int x = rcSrc.right-2; x>rcSrc.left+1; x--)
	  {
		pDC->SetPixel(x,y,RGB(0,0,0)/*cfColor*/);
		--y;
	  }

	  y = rcSrc.bottom-nStartPexil;
	  for(x = rcSrc.right-2; x>rcSrc.left+1; x--)
	  {
        pDC->SetPixel(x,y,RGB(0,0,0)/*cfColor*/);
		++y;
	  }

	  int ty = rcSrc.top+nStartPexil;
	  int by = rcSrc.bottom-nStartPexil;

	  for(x = rcSrc.right-2; x>rcSrc.left+1; x--)
	  {
        for(y =ty; y<by; y++)
		pDC->SetPixel(x,y,cfColor);
		++by;
		--ty;
	  }

	  //very peek of triangle
	  //pDC->SetPixel(rcSrc.right,rcSrc.top+nStartPexil,cfColor);
	  pDC->SelectObject(pOldPen);
	  taPen.DeleteObject();
	  return;
	}
	case ALIGN_UP:
	{


	}
	case ALIGN_DOWN:
	{


	}
  }
}



void CSheetWnd::AdjustTabs()
{

}

void CSheetWnd::RecalcLayout()
{
   CRect rcClient;
   GetClientRect(&rcClient);
   int size = m_lItems.GetSize();
   if(size>0)
   {
     for(int i=0; i<size; i++)
	 {
       m_lItems[i]->m_pwndItem->MoveWindow(0,0,rcClient.Width(),rcClient.Height()-18);
	   m_lItems[i]->m_nRect.top    = rcClient.bottom-TAB_HEIGHT;
       m_lItems[i]->m_nRect.bottom = rcClient.bottom;
	 }
   }

   m_GripperRect.top    = (rcClient.bottom-TAB_HEIGHT);
   m_GripperRect.bottom = rcClient.bottom;

   CRect rcScrll(m_GripperRect.right+1,rcClient.bottom -TAB_HEIGHT,
	             rcClient.right-TAB_HEIGHT,rcClient.bottom);
   m_wndHScrollBar.MoveWindow(&rcScrll);
}

BOOL CSheetWnd::OnEraseBkgnd(CDC* pDC)
{
  return TRUE;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
biography? I am not that old yet.

Comments and Discussions