void CBCommandTable::Draw ( JXWindowPainter& p, const JRect& rect ) { JXEditTable::Draw(p, rect); if (itsDNDRowIndex > 0) { p.ResetClipRect(); const JSize origLineWidth = p.GetLineWidth(); p.SetLineWidth(3); const JRect b = GetBounds(); if (RowIndexValid(itsDNDRowIndex)) { const JRect r = GetCellRect(JPoint(1, itsDNDRowIndex)); p.Line(b.left, r.top, b.right, r.top); } else { const JRect r = GetCellRect(JPoint(1, GetRowCount())); p.Line(b.left, r.bottom, b.right, r.bottom); } p.SetLineWidth(origLineWidth); } }
void JXTextMenuTable::Draw ( JXWindowPainter& p, const JRect& rect ) { JXMenuTable::Draw(p, rect); const JCoordinate w = GetApertureWidth(); const JSize rowCount = GetRowCount(); for (JIndex i=1; i<rowCount; i++) // ignore separator after last item { if (itsTextMenuData->HasSeparator(i)) { JRect r = GetCellRect(JPoint(1,i)); r.top = r.bottom - kSeparatorHeight; r.right = r.left + w; // JXDrawDownFrame(p, r, kSeparatorHeight/2); r.top = r.ycenter() - 1; r.bottom = r.top + 2; JXDrawDownFrame(p, r, 1); } } if (itsHilightRow != 0) { const JRect r = GetCellRect(JPoint(1, itsHilightRow)); JRect r1 = AdjustRectForSeparator(itsHilightRow, r); r1.right = r1.left + w; JXDrawUpFrame(p, r1, kHilightBorderWidth); } }
void GMFilterNameTable::Draw ( JXWindowPainter& p, const JRect& rect ) { JXEditTable::Draw(p, rect); if (itsDNDIsValid) { p.ResetClipRect(); p.SetLineWidth(kDragLineWidth); if (itsCurrentDNDIndex == 0) { JRect crect = GetCellRect(JPoint(1, GetRowCount())); p.Line(0, crect.bottom, GetBoundsWidth(), crect.bottom); } else { JRect crect = GetCellRect(JPoint(1, itsCurrentDNDIndex)); p.Line(0, crect.top, GetBoundsWidth(), crect.top); } } }
// 鼠标左键单击列表某一点事件 void CMyListCtrl::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default //刷新! CRect rect; ////////////////////////////////////////////////// if(m_nCurSelected!=-1) { GetItemRect(m_nCurSelected,&rect,LVIR_BOUNDS); this->InvalidateRect(&rect); } ////////////////////////////////////////////////// //找出选中的是哪一行 for(int i=0;i<this->GetItemCount();i++) { this->GetItemRect(i,&rect,LVIR_BOUNDS); if(rect.PtInRect(point)) { ////////////////////////// //上一次选中的行号 m_nPrevSelected=m_nCurSelected; //当前选中的行号 m_nCurSelected=i; //判断是否设置了行选中模式 if(m_bLineSelectedMode) m_bLineSelected=TRUE; else { //////////////////////////////////////////// //非行选中模式时,还要在找出选中的是哪一列 GetCellRect(i,0,rect); if(rect.PtInRect(point)) m_bLineSelected=TRUE; else { m_bLineSelected=FALSE; CPoint pt; ::GetCursorPos(&pt); ::ScreenToClient(this->m_hWnd,&pt); for(int j=0;j<this->GetHeaderCtrl()->GetItemCount();j++) { GetCellRect(i,j,rect); if(rect.PtInRect(pt)) { m_nCurSelCol=j; break; } } } } ////////////////////////////// break; } } CListCtrl::OnLButtonDown(nFlags, point); }
void EditableListCtrl::OnMouseEvent(wxMouseEvent& event) { // Double-clicking/right-clicking on a cell lets the user edit it. // The editing method depends on what column the cell is in. if (event.LeftDClick() || event.RightDown()) { // Work out what cell was clicked on: wxPoint pt = event.GetPosition(); int col = GetColumnAtPosition(pt); wxCHECK2(col >= 0 && col < (int)m_ColumnTypes.size(), return); int flags; long row = HitTest(pt, flags); if (row != wxNOT_FOUND && (flags & wxLIST_HITTEST_ONITEM)) { // Calculate the exact positioning of the clicked cell wxRect rect; GetCellRect(row, col, rect); // Execute the appropriate FieldEditCtrl FieldEditCtrl* editor = (FieldEditCtrl*)m_ColumnTypes[col].ctrl; editor->StartEdit(this, rect, row, col); } }
JBoolean JXRowHeaderWidget::InDragRegion ( const JPoint& pt, JPoint* cell ) const { JCoordinate width; JColorIndex color; GetRowBorderInfo(&width, &color); const JCoordinate halfWidth = kDragRegionHalfWidth + (width+1)/2; JPoint virtualPt(pt.x, pt.y - halfWidth); if (GetCell(virtualPt, cell)) { JRect cellRect = GetCellRect(*cell); if (cellRect.bottom - halfWidth <= pt.y && pt.y <= cellRect.bottom + halfWidth) { return kJTrue; } } return kJFalse; }
void CBCommandTable::HandleDNDHere ( const JPoint& pt, const JXWidget* source ) { JIndex newRowIndex = itsDNDRowIndex; JPoint cell; if (GetCell(JPinInRect(pt, GetBounds()), &cell)) { const JRect r = GetCellRect(cell); if (pt.y <= r.ycenter()) { newRowIndex = cell.y; } else { newRowIndex = cell.y + 1; } } if (newRowIndex != itsDNDRowIndex) { itsDNDRowIndex = newRowIndex; Refresh(); } }
void CuEditableListCtrlGeneric::OnRButtonDown(UINT nFlags, CPoint point) { int index, iColumnNumber = 1; int iItem = -1, iSubItem = -1; int iNumMin = 0; int iNumMax = 400; CRect rect, rCell; UINT flags; index = HitTest (point, &flags); if (index < 0) return; GetItemRect (index, rect, LVIR_BOUNDS); if (!GetCellRect (rect, point, rCell, iColumnNumber)) return; if (rect.PtInRect (point)) CuListCtrl::OnRButtonDown(nFlags, point); rCell.top -= 2; rCell.bottom += 2; HideProperty(); if (iColumnNumber != 1) return; EditValue (index, iColumnNumber, rCell); }
//***************************************************************************** // // Function Name: RGridCtrlBase::GetItemRect(int nIndex, LPRECT lpRect) // // Description: Retrieves the dimensions of the rectangle that // bounds a grid control item as it is currently // displayed in the list-box window. // // Returns: LB_ERR if an error occurs. // // Exceptions: None // //***************************************************************************** int RGridCtrlBase::GetItemRect( int nIndex, LPRECT lpRect ) const { if (nIndex < GetCount()) { nIndex -= GetTopIndex() ; GetCellRect( nIndex / m_nNumCols, nIndex % m_nNumCols, lpRect ) ; CRect rect, rectSect ; GetClientRect( rect ) ; if (m_uiFlags & kAddSpacing) { RECT& rect = *lpRect ; rect.top += 2 ; rect.left += 2 ; // rect.right -= 2 ; // rect.bottom -= 2 ; } if (rectSect.IntersectRect (&rect, lpRect)) { // // If the integral flag is set, make sure the entire // item is visible; otherwise we need to return an error. // if (!(m_uiFlags & kIntegral) || rectSect == *lpRect) { return 0 ; } } } return LB_ERR ; }
void TicTacToeGame::PlayGame(int index, HWND hWnd, HDC hdc) { if (index != -1) { RECT rc; if ((arrayGameBoard[index] == 0) && GetCellRect(hWnd, index, &rc)) { //FillRect(hdc, &rc, (intPlayerTurn == 1) ? hbPlayerOne : hbPlayerTwo); DrawIconCentered(hdc, &rc, (intPlayerTurn == 1) ? hiPlayerOne : hiPlayerTwo); arrayGameBoard[index] = intPlayerTurn; winner = GetWinner(wins); if (winner == 1 || winner == 2) { ShowWinner(hWnd, hdc); MessageBox(hWnd, (winner == 1) ? L"Player 1 is the winner" : L"Player 2 is the winner", L"You Win", MB_OK | MB_ICONINFORMATION); intPlayerTurn = 0; } else if (winner == 3) { MessageBox(hWnd, L"it's a draw", L"Draw", MB_OK | MB_ICONINFORMATION); intPlayerTurn = 0; } else { intPlayerTurn = (intPlayerTurn == 1) ? 2 : 1; } ShowTurn(hWnd, hdc); } } }
//清除上次选中行 void QuoteTableCtrlGeneralSort::RefreshWnd() { COLORREF color = GetGridBkColor(); CRect rectCell, rectRow; CCellID cell = GetCellFromPt(m_LastDownPoint); CGridCellBase* pCell = GetCell(cell.row, cell.col); BOOL bInTextArea = FALSE; if (pCell) { if (GetCellRect(cell.row, cell.col, rectCell) && pCell->GetTextRect(rectCell)) { bInTextArea = rectCell.PtInRect(m_LastDownPoint); } } if ( bInTextArea ) { for (int i=0; i<GetColumnCount(); i++) { pCell = GetCell(cell.row, i); /* pCell->GetBackClr();*/ if (pCell) { pCell->SetState(/*pCell->GetState() | */m_iColProp->GetColumnMask(GetHeadID(i))); pCell->SetBackClr(color); } } } Invalidate(); }
void DlgPalette::DrawCell(CDC *pDC, long index) { CRect rect; if (!GetCellRect(index, rect)) return; CBrush brush; if (m_editalpha){ brush.CreateSolidBrush(RGB(m_pal[index].rgbReserved, m_pal[index].rgbReserved , m_pal[index].rgbReserved )); }else{ brush.CreateSolidBrush(RGB(m_pal[index].rgbRed , m_pal[index].rgbGreen , m_pal[index].rgbBlue )); } CPen pen; if (index==m_selected) pen.CreatePen(PS_SOLID, 2, ::GetSysColor(COLOR_3DDKSHADOW)); else pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); CPen* pOldPen = (CPen*) pDC->SelectObject(&pen); // Draw the cell colour pDC->Rectangle(rect); // restore DC and cleanup pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); brush.DeleteObject(); pen.DeleteObject(); }
void CGridDocs::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { int iSelectRow; iSelectRow = iSelRow; if((nChar >= VK_NUMPAD0)&&(nChar <= VK_NUMPAD9)) { nChar = nChar - VK_NUMPAD0; nChar = nChar +'0'; } if((nChar >='0')&&(nChar <= '9')) { CRect rect; if (!GetCellRect(0, 1, rect)) return; tr = new CFilterEdit(WS_VISIBLE|WS_BORDER, rect,(CWnd*)this, Mess_Filter_Edit); CString a; a.Format(_T("%c"),nChar); tr->SetWindowTextW(a); tr->SetSel(2,1); return; } if (nChar == VK_DOWN) { iSelectRow++; } else if (nChar == VK_UP) { iSelectRow--; } if(iSelectRow < GetFixedRowCount()) iSelectRow = GetFixedRowCount(); if(iSelectRow > GetRowCount()-1) iSelectRow = GetRowCount() -1; if(iSelectRow < GetFixedRowCount()) return; CCellID cell; cell.col = 0; cell.row = iSelectRow; if (!IsCellVisible(cell)) { switch (nChar) { case VK_DOWN: SendMessage(WM_VSCROLL, SB_LINEDOWN, 0); break; case VK_UP: SendMessage(WM_VSCROLL, SB_LINEUP, 0); break; } } SelectItem(iSelectRow); }
/*********************************************** QuickRedrawCell The QuickRedrawCell function is used to quickly and effectively redraw a cell. This function will directly add draw hints to the CUGGrid and use PaintDrawHintsNow to quickly redraw a cell. ***********************************************/ void CRealTimeGrid::QuickRedrawCell( int col, long row ) { CRect rect; GetCellRect( col, row, rect ); m_CUGGrid->m_drawHint.AddHint( col, row, col, row ); if( GetCurrentRow() != row || GetCurrentCol() != col ) TempDisableFocusRect(); m_CUGGrid->PaintDrawHintsNow( rect ); }
void TicTacToeGame::ShowWinner(HWND hWnd, HDC hdc) { RECT rcClient; for (int i = 0; i < ARRAYSIZE(wins); i++) { if (GetCellRect(hWnd, wins[i], &rcClient)) { FillRect(hdc, &rcClient, CreateSolidBrush(RGB(255, 0, 0))); DrawIconCentered(hdc, &rcClient, (winner == 1) ? hiPlayerOne : hiPlayerTwo); } } }
void JXTextMenuTable::GetSubmenuPoints ( const JIndex itemIndex, JPoint* leftPt, JPoint* rightPt ) { const JRect cellRect = GetCellRect(JPoint(1,itemIndex)); const JRect ap = GetAperture(); *leftPt = JPoint(ap.left+1, cellRect.top); *rightPt = JPoint(ap.right-1, cellRect.top); }
void CColourPopup::CreateToolTips() { // Create the tool tip if (!m_ToolTip.Create(this)) return; // Add a tool for each cell for (int i = 0; i < m_nNumColours; i++) { CRect rect; if (!GetCellRect(i, rect)) continue; m_ToolTip.AddTool(this, GetColourName(i), rect, 1); } }
void CuEditableListCtrlComponent::OnOpenCellEditor(UINT nFlags, CPoint point) { int index, iColumnNumber; int iItem = -1, iSubItem = -1; int iNumMin = 0; int iNumMax = UD_MAXVAL; CRect rect, rCell; UINT flags; index = HitTest (point, &flags); if (index < 0) return; GetItemRect (index, rect, LVIR_BOUNDS); if (!GetCellRect (rect, point, rCell, iColumnNumber)) return; rCell.top -= 2; rCell.bottom += 2; // Emb Sept 24, 97: modify for preliminary test at low level side CuCbfListViewItem* pItemData = (CuCbfListViewItem*)GetItemData(index); LPCOMPONENTINFO lpComponentInfo = &pItemData->m_componentInfo; BOOL bCanEditName = VCBFllCanNameBeEdited(lpComponentInfo); BOOL bCanEditCount = VCBFllCanCountBeEdited(lpComponentInfo); HideProperty(); switch (iColumnNumber) { case 1: if (bCanEditName) SetEditText (index, iColumnNumber, rCell); else MessageBeep(MB_ICONEXCLAMATION); break; case 2: if (bCanEditCount) SetEditSpin (index, iColumnNumber, rCell, iNumMin, iNumMax); else MessageBeep(MB_ICONEXCLAMATION); break; default: break; } }
void JXRowHeaderWidget::HandleMouseDown ( const JPoint& pt, const JXMouseButton button, const JSize clickCount, const JXButtonStates& buttonStates, const JXKeyModifiers& modifiers ) { itsDragType = kInvalidDrag; if (!itsAllowRowResizingFlag) { return; } const JBoolean inDragRegion = InDragRegion(pt, &itsDragCell); if (inDragRegion && button == kJXLeftButton) { itsDragCellRect = GetCellRect(itsDragCell); if (modifiers.meta()) { itsDragType = kDragAllRows; } else { itsDragType = kDragOneRow; } JPainter* p = CreateDragOutsidePainter(); JRect defClipRect = p->GetDefaultClipRect(); JRect apG = GetApertureGlobal(); defClipRect.top = apG.top; defClipRect.bottom = apG.bottom; p->SetDefaultClipRect(defClipRect); const JRect enclAp = JXContainer::GlobalToLocal((GetEnclosure())->GetApertureGlobal()); p->Line(enclAp.left, pt.y, enclAp.right, pt.y); itsPrevPt = pt; } }
void CIconSelector::OnPaint() { CPaintDC dc(this); // device context for painting CMemDC memDC(&dc); CRect rc, rcClip; int i, j; GetClientRect(rc); memDC.FillSolidRect(rc, ICONSEL_COLOR_BACK); for(i = 0; i < (int)m_nRowCount; i++) { for(j = 0; j < (int)m_nColCount; j++) { GetCellRect(i, j, rcClip); DrawCell((CDC *)&memDC, i, j, rcClip); } } DrawCellLine((CDC *)&memDC); }
void CuEditableListCtrlDuplicateDbSelectLocation::OnLButtonDblClk(UINT nFlags, CPoint point) { int index, iColumnNumber; int iItem = -1, iSubItem = -1; int iNumMin = 0; int iNumMax = 400; CRect rect, rCell; UINT flags; index = HitTest (point, &flags); if (index < 0) return; GetItemRect (index, rect, LVIR_BOUNDS); if (!GetCellRect (rect, point, rCell, iColumnNumber)) return; rCell.top -= 2; rCell.bottom += 2; HideProperty(); EditValue (index, iColumnNumber, rCell); }
void QuoteTableCtrlGeneralSort::OnLButtonDown(UINT nFlags, CPoint point) { /*CHSGridCtrl::OnLButtonDown(nFlags, point);*/ SetFocus(); RefreshWnd(); RefreashOtherWnd(g_LastSelectWnd); g_LastSelectWnd = m_pTableFlag->nIndex; CRect rectCell, rectRow; CCellID cell = GetCellFromPt(point); if (cell.row == 0) return; CGridCellBase* pCell = GetCell(cell.row, cell.col); BOOL bInTextArea = FALSE; if (pCell) { if (GetCellRect(cell.row, cell.col, rectCell) && pCell->GetTextRect(rectCell)) { bInTextArea = rectCell.PtInRect(point); } } COLORREF selectbk = RGB(100,100,100); if ( bInTextArea ) { for (int i=0; i<GetColumnCount(); i++) { pCell = GetCell(cell.row, i); if (pCell) { pCell->SetState(pCell->GetState() | m_iColProp->GetColumnMask(GetHeadID(i))| GVIS_SELECTED); pCell->SetSelectColor(selectbk); } } } Invalidate(); m_LastDownPoint = point; }
JBoolean JXTextMenuTable::CellToItemIndex ( const JPoint& pt, const JPoint& cell, JIndex* itemIndex ) const { if (JIndex(cell.y) < GetRowCount() && itsTextMenuData->HasSeparator(cell.y)) { const JRect r = GetCellRect(cell); if (r.bottom - kSeparatorHeight <= pt.y && pt.y <= r.bottom) { *itemIndex = 0; return kJFalse; } } *itemIndex = cell.y; return kJTrue; }
void COptionTreeColorPopUp::CreateToolTips() { // Create the tool tip if (!m_ttToolTip.Create(this)) { return; } // Add a tool for each cell for (int i = 0; i < m_nNumColors; i++) { CRect rect; if (!GetCellRect(i, rect)) { continue; } m_ttToolTip.AddTool(this, GetColorName(i), rect, 1); } // Create inactive m_ttToolTip.Activate(TRUE); }
/*---------------------------------------------------------------------------------------------- Draw an individualbutton cell ----------------------------------------------------------------------------------------------*/ void IconComboPopup::DrawCell(HDC hdc, int ival, bool fHot, bool fOld) { Rect rc; GetCellRect(ival, rc); COLORREF clrBackBtn; switch (((uint)fHot << 1) | (uint)fOld) { case 1: // old // REVIEW (JeffG) ShonK: This is not the right color. There must be some inbetween shade // of gray that is darker then COLOR_3DHIGHLIGHT clrBackBtn = ::GetSysColor(COLOR_3DLIGHT); if (clrBackBtn == ::GetSysColor(COLOR_3DFACE)) clrBackBtn = ::GetSysColor(COLOR_3DHIGHLIGHT); AfGfx::FillSolidRect(hdc, rc, clrBackBtn, false); ::DrawEdge(hdc, &rc, EDGE_ETCHED, BF_RECT); break; case 2: // hot clrBackBtn = ::GetSysColor(COLOR_3DFACE); AfGfx::FillSolidRect(hdc, rc, clrBackBtn); ::DrawEdge(hdc, &rc, m_fMouseDown ? EDGE_SUNKEN : EDGE_RAISED, BF_RECT); break; case 3: // hot and old clrBackBtn = ::GetSysColor(COLOR_3DFACE); AfGfx::FillSolidRect(hdc, rc, clrBackBtn); ::DrawEdge(hdc, &rc, EDGE_ETCHED, BF_RECT); break; default: // neither clrBackBtn = ::GetSysColor(COLOR_3DFACE); AfGfx::FillSolidRect(hdc, rc, clrBackBtn); break; } rc.Inflate(-m_dzsBorder - 1, -m_dzsBorder - 1); ::ImageList_Draw(m_himl, ival, hdc, rc.left, rc.top, ILD_TRANSPARENT); }
void TicTacToeGame::DrawGame(HDC hdc, RECT rc, HWND hWnd) { for (int i = 0; i < 4; i++) { DrawLine(hdc, rc.left + TicTacToeGame::CELL_SIZE * i, rc.top, rc.left + TicTacToeGame::CELL_SIZE * i, rc.bottom); DrawLine(hdc, rc.left, rc.top + TicTacToeGame::CELL_SIZE * i, rc.right, rc.top + TicTacToeGame::CELL_SIZE * i); } RECT rcCell; for (int i = 0; i < ARRAYSIZE(arrayGameBoard); i++) { if ((arrayGameBoard[i] != 0) && GetCellRect(hWnd, i, &rcCell)) { DrawIconCentered(hdc, &rcCell, (arrayGameBoard[i] == 1) ? hiPlayerOne : hiPlayerTwo); } } if (winner != 0 && winner != 3) { ShowWinner(hWnd, hdc); } ShowTurn(hWnd, hdc); }
void CMyListCtrl::SetItemImage(int row, int col, UINT nIDResource) { CELLVALUE* pCell; CELLVALUE cell; memset(&cell,0,sizeof(CELLVALUE)); pCell=m_val.GetAt(row,col); if(pCell) { pCell->nIDResource=nIDResource; } else { cell.dwRow=row; cell.dwCol=col; cell.nIDResource=nIDResource; m_val.Add(cell); } //////////////////////////// //刷新 CRect rect; GetCellRect(row,col,rect); this->InvalidateRect(&rect,FALSE); }
void clRowEntry::Render(wxWindow* win, wxDC& dc, const clColours& c, int row_index, clSearchText* searcher) { wxUnusedVar(searcher); wxRect rowRect = GetItemRect(); bool zebraColouring = (m_tree->HasStyle(wxTR_ROW_LINES) || m_tree->HasStyle(wxDV_ROW_LINES)); bool even_row = ((row_index % 2) == 0); // Define the clipping region bool hasHeader = (m_tree->GetHeader() && !m_tree->GetHeader()->empty()); // Not cell related clColours colours = c; if(zebraColouring) { // Set Zebra colouring, only if no user colour was provided for the given line colours.SetItemBgColour(even_row ? c.GetAlternateColour() : c.GetBgColour()); } // Override default item bg colour with the user's one if(GetBgColour().IsOk()) { colours.SetItemBgColour(GetBgColour()); } wxRect selectionRect = rowRect; wxPoint deviceOrigin = dc.GetDeviceOrigin(); selectionRect.SetX(-deviceOrigin.x); if(IsSelected()) { DrawSimpleSelection(win, dc, selectionRect, colours); } else if(IsHovered()) { dc.SetPen(colours.GetHoverBgColour()); dc.SetBrush(colours.GetHoverBgColour()); dc.DrawRectangle(selectionRect); } else if(colours.GetItemBgColour().IsOk()) { dc.SetBrush(colours.GetItemBgColour()); dc.SetPen(colours.GetItemBgColour()); dc.DrawRectangle(selectionRect); } // Per cell drawings for(size_t i = 0; i < m_cells.size(); ++i) { bool last_cell = (i == (m_cells.size() - 1)); colours = c; // reset the colours wxFont f = clScrolledPanel::GetDefaultFont(); clCellValue& cell = GetColumn(i); if(cell.GetFont().IsOk()) { f = cell.GetFont(); } if(cell.GetTextColour().IsOk()) { colours.SetItemTextColour(cell.GetTextColour()); } if(cell.GetBgColour().IsOk()) { colours.SetItemBgColour(cell.GetBgColour()); } dc.SetFont(f); wxColour buttonColour = IsSelected() ? colours.GetSelbuttonColour() : colours.GetButtonColour(); wxRect cellRect = GetCellRect(i); // We use a helper class to clip the drawings this ensures that if we exit the scope // the clipping region is restored properly clClipperHelper clipper(dc); if(hasHeader) { clipper.Clip(cellRect); } int textXOffset = cellRect.GetX(); if((i == 0) && !IsListItem()) { // The expand button is only make sense for the first cell if(HasChildren()) { wxRect buttonRect = GetButtonRect(); buttonRect.Deflate(1); textXOffset += buttonRect.GetWidth(); if(m_tree->IsNativeTheme() && !IS_OSX) { int flags = wxCONTROL_CURRENT; if(IsExpanded()) { flags |= wxCONTROL_EXPANDED; } int button_width = wxSystemSettings::GetMetric(wxSYS_SMALLICON_X); wxRect modButtonRect = buttonRect; modButtonRect.SetWidth(button_width); modButtonRect.SetHeight(button_width); modButtonRect = modButtonRect.CenterIn(buttonRect); wxRendererNative::Get().DrawTreeItemButton(win, dc, modButtonRect, flags); } else { wxRect buttonRect = GetButtonRect(); if(textXOffset >= cellRect.GetWidth()) { // if we cant draw the button (off screen etc) SetRects(GetItemRect(), wxRect()); continue; } buttonRect.Deflate((buttonRect.GetWidth() / 3), (buttonRect.GetHeight() / 3)); wxRect tribtn = buttonRect; dc.SetPen(wxPen(buttonColour, 2)); if(IsExpanded()) { tribtn.SetHeight(tribtn.GetHeight() - tribtn.GetHeight() / 2); tribtn = tribtn.CenterIn(buttonRect); wxPoint middleLeft = wxPoint((tribtn.GetLeft() + tribtn.GetWidth() / 2), tribtn.GetBottom()); dc.DrawLine(tribtn.GetTopLeft(), middleLeft); dc.DrawLine(tribtn.GetTopRight(), middleLeft); } else { tribtn.SetWidth(tribtn.GetWidth() - tribtn.GetWidth() / 2); tribtn = tribtn.CenterIn(buttonRect); wxPoint middleLeft = wxPoint(tribtn.GetRight(), (tribtn.GetY() + (tribtn.GetHeight() / 2))); wxPoint p1 = tribtn.GetTopLeft(); wxPoint p2 = tribtn.GetBottomLeft(); dc.DrawLine(p1, middleLeft); dc.DrawLine(middleLeft, p2); } } } else { wxRect buttonRect(rowRect); buttonRect.SetWidth(rowRect.GetHeight()); buttonRect.Deflate(1); textXOffset += buttonRect.GetWidth(); if(textXOffset >= cellRect.GetWidth()) { SetRects(GetItemRect(), wxRect()); continue; } } } int itemIndent = IsListItem() ? clHeaderItem::X_SPACER : (GetIndentsCount() * m_tree->GetIndent()); int bitmapIndex = cell.GetBitmapIndex(); if(IsExpanded() && HasChildren() && cell.GetBitmapSelectedIndex() != wxNOT_FOUND) { bitmapIndex = cell.GetBitmapSelectedIndex(); } // Draw checkbox if(cell.IsBool()) { // Render the checkbox textXOffset += X_SPACER; int checkboxSize = GetCheckBoxWidth(win); wxRect checkboxRect = wxRect(textXOffset, rowRect.GetY(), checkboxSize, checkboxSize); checkboxRect = checkboxRect.CenterIn(rowRect, wxVERTICAL); dc.SetPen(colours.GetItemTextColour()); RenderCheckBox(win, dc, colours, checkboxRect, cell.GetValueBool()); cell.SetCheckboxRect(checkboxRect); textXOffset += checkboxRect.GetWidth(); textXOffset += X_SPACER; } else { cell.SetCheckboxRect(wxRect()); // clear the checkbox rect } // Draw the bitmap if(bitmapIndex != wxNOT_FOUND) { const wxBitmap& bmp = m_tree->GetBitmap(bitmapIndex); if(bmp.IsOk()) { textXOffset += IsListItem() ? 0 : X_SPACER; int bitmapY = rowRect.GetY() + ((rowRect.GetHeight() - bmp.GetScaledHeight()) / 2); // if((textXOffset + bmp.GetScaledWidth()) >= cellRect.GetWidth()) { continue; } dc.DrawBitmap(bmp, itemIndent + textXOffset, bitmapY, true); textXOffset += bmp.GetScaledWidth(); textXOffset += X_SPACER; } } // Draw the text wxRect textRect(dc.GetTextExtent(cell.GetValueString())); textRect = textRect.CenterIn(rowRect, wxVERTICAL); int textY = textRect.GetY(); int textX = (i == 0 ? itemIndent : clHeaderItem::X_SPACER) + textXOffset; RenderText(win, dc, colours, cell.GetValueString(), textX, textY, i); textXOffset += textRect.GetWidth(); textXOffset += X_SPACER; if(cell.IsChoice()) { // draw the drop down arrow. Make it aligned to the right wxRect dropDownRect(cellRect.GetTopRight().x - rowRect.GetHeight(), rowRect.GetY(), rowRect.GetHeight(), rowRect.GetHeight()); dropDownRect = dropDownRect.CenterIn(rowRect, wxVERTICAL); DrawingUtils::DrawDropDownArrow(win, dc, dropDownRect, wxNullColour); // Keep the rect to test clicks cell.SetDropDownRect(dropDownRect); textXOffset += dropDownRect.GetWidth(); textXOffset += X_SPACER; // Draw a separator line between the drop down arrow and the rest of the cell content dropDownRect.Deflate(3); dropDownRect = dropDownRect.CenterIn(rowRect, wxVERTICAL); dc.SetPen(wxPen(colours.GetHeaderVBorderColour(), 1, PEN_STYLE)); dc.DrawLine(dropDownRect.GetTopLeft(), dropDownRect.GetBottomLeft()); } else { cell.SetDropDownRect(wxRect()); } if(!last_cell) { cellRect.SetHeight(rowRect.GetHeight()); dc.SetPen(wxPen(colours.GetHeaderVBorderColour(), 1, PEN_STYLE)); dc.DrawLine(cellRect.GetTopRight(), cellRect.GetBottomRight()); } } }
//*************************************************************** void CColorListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if (!lpDrawItemStruct) return; IsCreated=TRUE; CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CMyLParam* pMyLParam = GetMyLParam(lpDrawItemStruct->itemID); CRect rcItem; if (!pMyLParam) return; int x=0; typedef enum {R_NOTHINGS=0, R_FOCUS, R_SELECT, R_NORMAL, R_SEL_NOFOCUS} redrawmode; redrawmode redraw=R_NORMAL; // Get item image and state info LV_ITEM lvi; lvi.mask = LVIF_IMAGE | LVIF_STATE; lvi.iItem = lpDrawItemStruct->itemID; lvi.iSubItem = 0; lvi.stateMask = 0xFFFF; // get all state flags GetItem(&lvi); BOOL bHighlight = ( (lvi.state & LVIS_DROPHILITED) || ( (lvi.state & LVIS_SELECTED) && ( ( GetFocus() == this ) || ( GetStyle() & LVS_SHOWSELALWAYS ) ) ) ); BOOL bLostFocus=(GetFocus()!=this); if ( (lpDrawItemStruct->itemAction&ODA_FOCUS)==ODA_FOCUS) { //the control gains or loses input focus if (bLostFocus) redraw=R_SEL_NOFOCUS; else if ((lvi.state&LVIS_FOCUSED)==LVIS_FOCUSED) redraw=R_FOCUS; else { if (bHighlight) redraw=R_SELECT; else redraw=R_NORMAL; } } else if ((lpDrawItemStruct->itemAction&ODA_SELECT)==ODA_SELECT) { //the selection status has changed if (bHighlight) { if (bLostFocus) redraw=R_SEL_NOFOCUS; else redraw=R_SELECT; } else redraw=R_NORMAL; } else { //redraw the item if (bLostFocus) { if (bHighlight) redraw=R_SEL_NOFOCUS; else redraw=R_NORMAL; } else { if ((lvi.state&LVIS_FOCUSED)==LVIS_FOCUSED) redraw=R_FOCUS; else { if (bHighlight) redraw=R_SELECT; else redraw=R_NORMAL; } } } CPen *pOldPen; CPen pen; CGdiObject *pOldBrush; switch(redraw) { case R_FOCUS: rcItem=GetFullCellRect(lpDrawItemStruct->itemID, TRUE); pDC->FillSolidRect(rcItem, GetColorRef(DEF_SELBACKGROUND)); pDC->SetTextColor(GetColorRef(DEF_SELTEXT)); if (m_BigFocusRect) { pen.CreatePen( PS_DOT, 0, GetColorRef(DEF_SELTEXT) ); pOldPen =pDC->SelectObject(&pen); pOldBrush=pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(rcItem); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); } else pDC->DrawFocusRect(rcItem); for (x=0; x<m_columnSize; x++) { rcItem = GetCellRect(lpDrawItemStruct->itemID, x, FALSE); pDC->DrawText(CListCtrl::GetItemText(lpDrawItemStruct->itemID,x), rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER ); } break; case R_SELECT: rcItem=GetFullCellRect(lpDrawItemStruct->itemID, TRUE); pDC->FillSolidRect(rcItem, GetColorRef(DEF_SELBACKGROUND)); pDC->SetTextColor(GetColorRef(DEF_SELTEXT)); for (x=0; x<m_columnSize; x++) { rcItem = GetCellRect(lpDrawItemStruct->itemID, x, FALSE); pDC->DrawText(CListCtrl::GetItemText(lpDrawItemStruct->itemID,x), rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); } break; case R_SEL_NOFOCUS: rcItem=GetFullCellRect(lpDrawItemStruct->itemID, TRUE); pDC->FillSolidRect(rcItem, GetColorRef(DEF_DESELBACKGROUND)); pDC->SetTextColor(pMyLParam->GetTextColor(DEF_DESELTEXT)); pen.CreatePen( PS_DOT, 0, GetColorRef(DEF_DESELBACKGROUND) ); pOldPen =pDC->SelectObject(&pen); pOldBrush=pDC->SelectStockObject(NULL_BRUSH); if (!m_withSingleRect) pDC->Rectangle(rcItem); for (x=0; x<m_columnSize; x++) { rcItem = GetCellRect(lpDrawItemStruct->itemID, x, FALSE); pDC->DrawText(CListCtrl::GetItemText(lpDrawItemStruct->itemID,x), rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); } pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); break; case R_NORMAL: for (x=0; x<m_columnSize; x++) { rcItem = GetCellRect(lpDrawItemStruct->itemID, x, TRUE); pDC->FillSolidRect(rcItem, pMyLParam->GetBackColor(x)); pDC->SetTextColor(pMyLParam->GetTextColor(x)); if (m_withSingleRect) { pOldBrush=pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(rcItem); pDC->SelectObject(pOldBrush); } rcItem = GetCellRect(lpDrawItemStruct->itemID, x, FALSE); pDC->DrawText(CListCtrl::GetItemText(lpDrawItemStruct->itemID,x), rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); } break; } return; }
void CColourPopup::DrawCell(CDC* pDC, int nIndex) { // For the Custom Text area if (m_strCustomText.GetLength() && nIndex == CUSTOM_BOX_VALUE) { // The extent of the actual text button CRect TextButtonRect = m_CustomTextRect; TextButtonRect.top += 2*m_nMargin; // Fill background pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw horizontal line pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top, m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DSHADOW)); pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top+1, m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DHILIGHT)); TextButtonRect.DeflateRect(1,1); // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT)); else pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT); // Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strCustomText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SelectObject(pOldFont); return; } // For the Default Text area if (m_strDefaultText.GetLength() && nIndex == DEFAULT_BOX_VALUE) { // Fill background pDC->FillSolidRect(m_DefaultTextRect, ::GetSysColor(COLOR_3DFACE)); // The extent of the actual text button CRect TextButtonRect = m_DefaultTextRect; TextButtonRect.DeflateRect(1,1); // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT)); else pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw thin line around text CRect LineRect = TextButtonRect; LineRect.DeflateRect(2*m_nMargin,2*m_nMargin); CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CPen* pOldPen = pDC->SelectObject(&pen); pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(LineRect); pDC->SelectObject(pOldPen); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT); // Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strDefaultText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SelectObject(pOldFont); return; } CRect rect; if (!GetCellRect(nIndex, rect)) return; // Select and realize the palette CPalette* pOldPalette = NULL; if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pOldPalette = pDC->SelectPalette(&m_Palette, FALSE); pDC->RealizePalette(); } // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DHILIGHT)); else pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE)); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(rect, BDR_SUNKENOUTER, BF_RECT); CBrush brush(PALETTERGB(GetRValue(GetColour(nIndex)), GetGValue(GetColour(nIndex)), GetBValue(GetColour(nIndex)) )); CPen pen; pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); CPen* pOldPen = (CPen*) pDC->SelectObject(&pen); // Draw the cell colour rect.DeflateRect(m_nMargin+1, m_nMargin+1); pDC->Rectangle(rect); // restore DC and cleanup pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); brush.DeleteObject(); pen.DeleteObject(); if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) pDC->SelectPalette(pOldPalette, FALSE); }