Example #1
0
void CCalendarCtrl::DrawCells(CDC* pDC)
{
	CRect rc;
	GetClientRect(&rc);
	int ncHeight = (rc.Height()-CALENDAR_HEADER_HEIGHT)/CALENDAR_ROWS;
	int ncWidth = rc.Width()/CALENDAR_COLUMNS;

	CPen whitePen(PS_SOLID, 1, RGB(255,255,255));
	CPen blackPen(PS_SOLID, 1, RGB(0,0,0));

	CFont* pOldFont = pDC->SelectObject(&m_DefaultFont);
	CPen* pOldPen = pDC->SelectObject(&blackPen);

	for(int i=0; i<CALENDAR_ROWS ; i++)
	{
		for(int u=0; u<CALENDAR_COLUMNS ; u++)
		{
			CRect rect;
			if(GetRectFromCell(i, u, rect))
			{
				if(u == CALENDAR_COLUMNS-1) rect.right = rc.right;
				if(i == CALENDAR_ROWS-1) rect.bottom = rc.bottom;

				if((m_bMonthIsOdd &&  !(m_dayCells[i][u].date.GetMonth()%2))
					|| (!m_bMonthIsOdd && (m_dayCells[i][u].date.GetMonth()%2)))
				{
					CBrush br;
					br.CreateSolidBrush(CALENDAR_LIGHTGREY);
					pDC->FillRect(&rect ,&br);
				}

				COleDateTime today(time(NULL));
				bool btoday = false;
				if(today.GetDay() == m_dayCells[i][u].date.GetDay()	&& today.GetMonth() == m_dayCells[i][u].date.GetMonth()	&& today.GetYear() == m_dayCells[i][u].date.GetYear())
				{
					// Draw the frame 
					CRect rcLine(rect);
					rcLine.bottom = rcLine.top+15;
					rcLine.top = rcLine.bottom-1;
					for(int c=0; c<15; c++)
					{
						pDC->FillSolidRect(rcLine, GetFadedBlue(c*6));
						rcLine.bottom--;
						rcLine.top = rcLine.bottom-1;
					}
					btoday = true;
				}

				// Draw the selection
				bool bSelected = false;
				time_t tmax = max(m_SelectionRange[0], m_SelectionRange[1]);
				time_t tmin = min(m_SelectionRange[0], m_SelectionRange[1]);			
				time_t tcur = DateToSeconds(m_dayCells[i][u].date);				
				if(m_RandomSelection.GetCount())
				{	
					POSITION pos = m_RandomSelection.GetStartPosition();	 
					while (pos){
						void* p; DWORD date;
						m_RandomSelection.GetNextAssoc(pos, (void*&)date, p);
						if(date == (DWORD)tcur)
						{							
							CBrush br;
							br.CreateSolidBrush(GetFadedBlue(70));
							CRect selRect(rect);
							if(btoday)	selRect.top += 15;
							pDC->FillRect(&selRect, &br);
							bSelected = true;
						}
					}

					if(m_SelectionRange[2] == tcur)
					{
						rect.left+=2;	rect.right -=1;
						rect.top+=2;	rect.bottom -=1;
						pDC->DrawFocusRect(rect);
					}
				}
				else if((tmax >= tcur) && (tcur >= tmin))
				{						
					CRect selRect(rect);
					CBrush br;
					br.CreateSolidBrush(GetFadedBlue(70));
					if(btoday)	selRect.top += 15;
					pDC->FillRect(&selRect, &br);
					bSelected = true;
				}

				// Out of range
				if( (m_dayCells[i][u].date >= m_BoundUp) || 
					(m_dayCells[i][u].date <= m_BoundDown) )	
				{
					CRect selRect(rect);
					CBrush br;
					br.CreateSolidBrush(RGB(255,225,225));
					pDC->FillRect(&selRect, &br);
				}

				if(m_dayCells[i][u].bMark)
				{
					CBrush br;
					br.CreateSolidBrush(RGB(255,104,4));
					CRect rcMark(rect);
					rcMark.DeflateRect(3,3);
					rcMark.right = rcMark.left +6;
					rcMark.bottom = rcMark.top +6;
					pDC->FillRect(&rcMark, &br);
				}

				// draw inside...
				rect.DeflateRect(1,1);		
				CString csDay;
				int nDay = m_dayCells[i][u].date.GetDay();
				if(nDay == 1 || (i==0 && u==0))
				{
					csDay.Format(_T("%s %d"), m_dayCells[i][u].date.Format(_T("%B")), nDay);
					CSize dtSize(pDC->GetTextExtent(csDay));
					if(dtSize.cx>rect.Width())
						csDay.Format(_T("%s %d"), m_dayCells[i][u].date.Format(_T("%b")), nDay);
				}
				else
					csDay.Format(_T("%d"), nDay);

				unsigned long nColor;
				if(bSelected && !btoday)
					nColor = pDC->SetTextColor(RGB(255,104,4));
				else
					nColor = pDC->SetTextColor(RGB(0,0,0));
				pDC->DrawText(csDay, rect, DT_RIGHT|DT_TOP);
				pDC->SetTextColor(nColor);

				// Draw the cell content if possible
				if(rect.Width() >= 15)
				{
					for (int j=0; j<m_dayCells[i][u].csaLines.GetSize(); j++)
					{
						CRect txtRect(rect);
						CRect dotRect(rect);

						txtRect.left += 9; //CALENDAR_LINE_HEIGHT;
						txtRect.right-= 2;
						txtRect.top += (j+1)*CALENDAR_LINE_HEIGHT; 

						dotRect.top += (j+1)*CALENDAR_LINE_HEIGHT+(CALENDAR_LINE_HEIGHT/2-1); 
						dotRect.bottom = dotRect.top + 3;
						dotRect.left += 3;
						dotRect.right = dotRect.left +3;

						m_dayCells[i][u].bPartial = false;
						if(!m_dayCells[i][u].csaLines[j].IsEmpty() && txtRect.Height() > CALENDAR_LINE_HEIGHT)
						{
							pDC->SetTextColor(RGB(0,0,0));
							pDC->DrawText(m_dayCells[i][u].csaLines[j], txtRect, DT_LEFT|DT_TOP);								
							CBrush br;
							br.CreateSolidBrush(RGB(125,175,255));
							pDC->FillRect(&dotRect, &br);
						}
						else if(!m_dayCells[i][u].csaLines[j].IsEmpty())
						{
							CPen dotPen(PS_SOLID, 1, RGB(170,170,170));
							pDC->SelectObject(&dotPen);
							// Draw a little arrow
							static int t[2][7] = {5,5,8,8,8,5,5,4,3,2,1,2,3,4};
							int n = 0;
							for(int r=7; r>0; r--){
								pDC->MoveTo(rect.right-9+r, rect.bottom-t[0][n]);
								pDC->LineTo(rect.right-9+r, rect.bottom-t[1][n]);
								n++;
							}
							m_dayCells[i][u].bPartial = true;
							break;
						}
					}
				}
			}
		}
	}

	pDC->SelectObject(pOldFont);
	pDC->SelectObject(pOldPen);
}
void CChartAreaWnd::OnPaint() 
{
    int      wx,wy;
    CPaintDC dc(this); 

    CDC* pDC = &dc;

    CRect winrect;

    GetClientRect( &winrect );

    drawWidth  = winrect.right ; 
    drawHeight = winrect.bottom; 

    m_Font.CreateFont( fontSize, 0, 0, 0, FW_NORMAL, 
                        FALSE, FALSE, FALSE,
                        SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS,
                        CLIP_DEFAULT_PRECIS,
                        DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, 
                        "MS 明朝\0" );

    LOGFONT logFont;
    m_Font.GetLogFont( &logFont );
    int fHeight = logFont.lfHeight;    // int lfWidth = logFont.lfWidth;
    
    CFont* oldFont = (CFont *)pDC->SelectObject( m_Font );

    pDC->Rectangle( 0, 0, winrect.right, winrect.bottom );

    for ( int i = 1; ; i++ ){
        wy = itemHeight * i;
        if ( wy >= ( winrect.bottom ) ) break ;
        pDC->MoveTo( 0, wy );
        pDC->LineTo( winrect.right, wy );
    }

    CPen dotPen( PS_DOT,   1, (COLORREF) 0 );
    CPen *oldPen;

    for ( int j = 1; ; j++ ){

        wx = timeWidth * j;
        if ( wx >= drawWidth ) break ;

        oldPen = pDC->SelectObject( &dotPen );
        pDC->MoveTo( wx, 0 );
        pDC->LineTo( wx, drawHeight );
        pDC->SelectObject( oldPen );
    }

    POSITION  pos = _pElemList->GetHeadPosition();
    while ( pos ) {
        Job* job  = _pElemList->GetNext( pos );
        int  itemId    = job->id;

        if( itemId >= m_startItemNo /* && itemId <=m_endItemNo */ ) { 

            CTimeSpan tmSpan1 = job->startTime - m_startTime;
            CTimeSpan tmSpan2 = job->endTime   - m_startTime;
            CTimeSpan tmSpan3 = job->endTime   - job->startTime;

            int startDate = tmSpan1.GetDays();
            int endDate   = tmSpan2.GetDays();
            int tmpDate   = tmSpan3.GetDays();
    
            bwx1 = (startDate) * timeWidth; 
            bwx2 = (endDate    )  * timeWidth ;
            bwy1 = (itemId-m_startItemNo-1)  * itemHeight + barMargin; 
            bwy2 = (itemId-m_startItemNo-1)  * itemHeight + barMargin + barHeight ;

            char* pBuff = (job->name).GetBuffer(BUFF_SIZE);
            DrawTaskBar( pDC, bwx1, bwy1, bwx2-bwx1, bwy2-bwy1, fHeight, pBuff );    
            (job->name).ReleaseBuffer();

            job->x1 = bwx1;
            job->y1 = bwy1;
            job->x2 = bwx2;
            job->y2 = bwy2;

        }

    }

    m_Font.DeleteObject();  //,fontInit=1;

}