| 发表于:2007-09-14 23:30:2914楼 得分:0 |
/**********************************************************************************************/ /*function name: oncustomdraw */ /*function definition: draw list items */ /*function author: carlos andre sanches de souza */ /*function creation date: 08/08/2007 */ /**********************************************************************************************/ void cmultilinelistctrl::oncustomdraw(nmhdr* pnmhdr, lresult* presult) { *presult = cdrf_dodefault; lpnmlvcustomdraw lplvcd = (lpnmlvcustomdraw)pnmhdr; switch(lplvcd-> nmcd.dwdrawstage) { case cdds_prepaint : *presult = cdrf_notifyitemdraw; return; case cdds_itemprepaint: *presult = cdrf_notifysubitemdraw; return; case cdds_subitem ¦ cdds_prepaint ¦ cdds_item: { int nitem = lplvcd-> nmcd.dwitemspec; int nsubitem = lplvcd-> isubitem; int nnumlines = (int)getitemdata(nitem); int ncurrentselection; bool changeselection = false; position posselection; hdc hdc = lplvcd-> nmcd.hdc; cstring str; crect boxrect, bounds, rect; cdc* pdc = cdc::fromhandle(hdc); // get background box boxrect = lplvcd-> nmcd.rc; getitemrect( lplvcd-> nmcd.dwitemspec, &bounds, lvir_bounds ); boxrect.top = bounds.top; boxrect.bottom = bounds.bottom; if( nsubitem == 0 ) { crect lrect; getitemrect( lplvcd-> nmcd.dwitemspec, &lrect, lvir_label ); boxrect.left = lrect.left; boxrect.right = lrect.right; } else { boxrect.right += bounds.left; boxrect.left += bounds.left; } // get selection posselection = getfirstselecteditemposition(); if (posselection) ncurrentselection = getnextselecteditem(posselection); else ncurrentselection = -1; if (ncurrentselection != m_selected) { m_lastselected = m_selected; m_selected = ncurrentselection; changeselection = true; } // fill background box if ( m_selected == nitem ¦ ¦ (nnumlines> 1 && nitem <getitemcount()-1 && (int)getitemdata(nitem+1) <1 && m_selected> nitem && m_selected <nitem+nnumlines) ¦ ¦ (nnumlines <1 && m_selected> =nitem+nnumlines && m_selected <nitem+nnumlines+(int)getitemdata(nitem+nnumlines))) { pdc-> fillrect(boxrect, &cbrush(::getsyscolor(color_highlight))); pdc-> settextcolor(getsyscolor(color_highlighttext)) ; } else { pdc-> fillrect(boxrect, &cbrush(::getsyscolor(color_window))); pdc-> settextcolor(getsyscolor(color_windowtext)) ; } // get text string str = getitemtext( nitem, nsubitem ); // get text box rect = boxrect; rect.left += nsubitem?6:2; // draw symbol [+] if (nnumlines> 1 && getitemtext(nitem, nsubitem).find( '\n ')> -1 ) { cpen light(ps_solid, 1, colorsymbol); pdc-> selectobject(light); pdc-> moveto(rect.left,rect.top+2); pdc-> lineto(rect.left+8,rect.top+2); pdc-> lineto(rect.left+8,rect.top+10); pdc-> lineto(rect.left,rect.top+10); pdc-> lineto(rect.left,rect.top+2); pdc-> moveto(rect.left+2,rect.top+6); pdc-> lineto(rect.left+7,rect.top+6); if (nitem <getitemcount()-1 && (int)getitemdata(nitem+1) <1) { pdc-> selectobject(dot); pdc-> moveto(rect.left+4,rect.top+10); pdc-> lineto(rect.left+4,rect.bottom); } else { pdc-> moveto(rect.left+4,rect.top+4); pdc-> lineto(rect.left+4,rect.top+9); } if (!m_minimized ¦ ¦ (nitem <getitemcount()-1 && (int)getitemdata(nitem+1) <1)) { if (str.find( '\n ')> -1) str = str.left(str.find( '\n ')); if (str.find( '\r ')> -1) str = str.left(str.find( '\r ')); } else { str.replace( "\r\n ", " ¦ "); str.replace( "\n ", " ¦ "); } rect.left += 12; } // draw dot lines if (nnumlines <1 && getitemtext(nitem+nnumlines, nsubitem).find( '\n ')> -1) { int countlines = 1; cstring text = getitemtext(nitem+nnumlines, nsubitem); for (int k=0;k <text.getlength();k++) if (text.getat(k)== '\n ') countlines++; if (countlines> -nnumlines) { pdc-> selectobject(dot); pdc-> moveto(rect.left+4,rect.top); if (countlines-1==-nnumlines) { pdc-> lineto(rect.left+4,rect.top+6); pdc-> lineto(rect.left+8,rect.top+6); } else pdc-> lineto(rect.left+4,rect.bottom); } rect.left += 12; } // draw text pdc-> drawtext( str, rect, dt_singleline ¦dt_noprefix ¦dt_left ¦dt_vcenter ¦dt_end_ellipsis); // draw grid if (m_grid) { cpen gridline(ps_solid, 1, m_gridcolor); pdc-> selectobject(gridline); if (nsubitem> 0) { pdc-> moveto(boxrect.left, boxrect.top); pdc-> lineto(boxrect.left, boxrect.bottom); } if (nnumlines==1 ¦ ¦ nitem==getitemcount()-1 ¦ ¦ (int)getitemdata(nitem+1)> =1) { pdc-> moveto(boxrect.left, boxrect.bottom-1); pdc-> lineto(boxrect.right, boxrect.bottom-1); } } *presult = cdrf_skipdefault; // invalidate if (changeselection) { int topsel = m_selected+((m_selected> -1 && (int)getitemdata(m_selected) <1)?(int)getitemdata(m_selected):0); int toplast = m_lastselected+((m_lastselected> -1 && (int)getitemdata(m_lastselected) <1)?(int)getitemdata(m_lastselected):0); crect clean; if (topsel != toplast) { if (topsel > -1) { getitemrect(topsel, &clean, lvir_bounds); if ((int)getitemdata(topsel)> 1 && topsel <getitemcount()-1 && (int)getitemdata(topsel+1) <1) { getitemrect(topsel+getitemdata(topsel)-1, &bounds, lvir_bounds); clean.bottom = bounds.bottom; invalidaterect(clean, false); } } if (toplast > -1) { getitemrect(toplast, &clean, lvir_bounds); if ((int)getitemdata(toplast)> 1 && toplast <getitemcount()-1 && (int)getitemdata(toplast+1) <1) { getitemrect(toplast+getitemdata(toplast)-1, &bounds, lvir_bounds); clean.bottom = bounds.bottom; invalidaterect(clean, false); } } } } return; } } } | | |
|