win32listview.cpp
来自「这是VCF框架的代码」· C++ 代码 · 共 2,606 行 · 第 1/5 页
CPP
2,606 行
} } } } }}bool Win32Listview::handleEventMessages( UINT message, WPARAM wParam, LPARAM lParam, LRESULT& wndProcResult, WNDPROC defaultWndProc ){ bool result = false; wndProcResult = 0; switch ( message ) { case WM_CONTEXTMENU : { //HACK ALERT !!! if ( Component::csNormal == listviewControl_->getComponentState() ) { PopupMenu* popup = listviewControl_->getPopupMenu(); if ( NULL != popup ) { POINT pt = {0,0}; pt.x = LOWORD(lParam); pt.y = HIWORD(lParam); ::ScreenToClient( hwnd_, &pt ); popup->popup( &Point(pt.x, pt.y ) ); } } } break; case WM_ERASEBKGND :{ /* Color* color = listviewControl_->getColor(); if ( (backColor_.getRed() != color->getRed()) || (backColor_.getGreen() != color->getGreen()) || (backColor_.getBlue() != color->getBlue()) ) { COLORREF backColor = color->getColorRef32(); ListView_SetBkColor( hwnd_, backColor ); backColor_.copy( color ); } */ wndProcResult = 0; result= true; } break; case WM_NCCALCSIZE: { wndProcResult = handleNCCalcSize( wParam, lParam ); result= true; } break; case WM_NCPAINT: { wndProcResult = handleNCPaint( wParam, lParam ); result= true; } break; case WM_DRAWITEM : { wndProcResult = TRUE; result = true; DRAWITEMSTRUCT* drawItem = (DRAWITEMSTRUCT*)lParam; if ( ODT_HEADER == drawItem->CtlType ) { ulong32 index = drawItem->itemID; ColumnItem* item = NULL; if ( listviewControl_->getColumnModel()->getCount() > 0 ) { HWND header = ListView_GetHeader( hwnd_ ); if ( NULL != header ) { HDITEM headerItem; memset( &headerItem, 0, sizeof(HDITEM) ); headerItem.mask = HDI_FORMAT | HDI_LPARAM; if ( Header_GetItem( header, index, &headerItem ) ) { item = (ColumnItem*)headerItem.lParam; } } } if ( NULL != item ) { String caption = item->getCaption(); //::SelectObject( drawItem->hDC, ::GetStockObject(DEFAULT_GUI_FONT) ); UINT format = 0; RECT textRect = drawItem->rcItem; InflateRect( &textRect, -5, -2 ); switch( item->getCaptionAlignment() ) { case taTextLeft: { format = DT_LEFT; } break; case taTextCenter: { format = DT_CENTER; } break; case taTextRight: { format = DT_RIGHT; } break; } format |= DT_SINGLELINE | DT_WORD_ELLIPSIS; if ( System::isUnicodeEnabled() ) { ::DrawTextW(drawItem->hDC, caption.c_str(), caption.size(), &textRect, format); } else { AnsiString tmp = caption; ::DrawTextA(drawItem->hDC, tmp.c_str(), tmp.size(), &textRect, format); } //::SelectObject( drawItem->hDC, ::GetStockObject(SYSTEM_FONT) ); if ( true == item->canPaint() ) { if ( (drawItem->itemState & ODS_SELECTED) != 0 ) { } else { } GraphicsContext gc( (OSHandleID)drawItem->hDC ); Rect rect( drawItem->rcItem.left, drawItem->rcItem.top, drawItem->rcItem.right, drawItem->rcItem.bottom ); item->paint( &gc, &rect ); gc.getPeer()->setContextID( 0 ); } } } } break; case WM_PAINT:{ PAINTSTRUCT ps; HDC dc = BeginPaint( hwnd_, &ps ); RECT r; GetClientRect( hwnd_, &r ); HWND header = GetDlgItem( hwnd_, 0 ); RECT headerRect = {0}; if ( NULL != header ) { GetWindowRect( header, &headerRect ); POINT pt; pt.x = headerRect.left; pt.y = headerRect.top; ScreenToClient( hwnd_, &pt ); headerRect.left = pt.x; headerRect.top = pt.y; pt.x = headerRect.right; pt.y = headerRect.bottom; ScreenToClient( hwnd_, &pt ); headerRect.right = pt.x; headerRect.bottom = pt.y; ExcludeClipRect( dc, headerRect.left, headerRect.top, headerRect.right, headerRect.bottom ); r.top = headerRect.bottom; } if ( NULL == memDC_ ) { //create here HDC dc = ::GetDC(0); memDC_ = ::CreateCompatibleDC( dc ); ::ReleaseDC( 0, dc ); } memBMP_ = ::CreateCompatibleBitmap( dc, r.right - r.left, r.bottom - r.top ); memDCState_ = ::SaveDC( memDC_ ); originalMemBMP_ = (HBITMAP)::SelectObject( memDC_, memBMP_ ); ::SetViewportOrgEx( memDC_, -r.left, -r.top, NULL ); Color* color = listviewControl_->getColor(); COLORREF backColor = color->getColorRef32(); HBRUSH bkBrush = CreateSolidBrush( backColor ); FillRect( memDC_, &r, bkBrush ); DeleteObject( bkBrush ); ::SetViewportOrgEx( memDC_, -r.left, -r.top, NULL ); VCF::GraphicsContext* ctx = peerControl_->getContext(); ctx->setViewableBounds( Rect(r.left, r.top, r.right, r.bottom ) ); ctx->getPeer()->setContextID( (OSHandleID)memDC_ ); ((ControlGraphicsContext*)ctx)->setOwningControl( NULL ); defaultWndProcedure( WM_PAINT, (WPARAM)memDC_, 0 ); ((ControlGraphicsContext*)ctx)->setOwningControl( peerControl_ ); ::BitBlt( dc, r.left, r.top, r.right - r.left, r.bottom - r.top, memDC_, r.left, r.top, SRCCOPY ); ::RestoreDC ( memDC_, memDCState_ ); ::DeleteObject( memBMP_ ); EndPaint( hwnd_, &ps ); wndProcResult = 1; result = true; } break; case WM_CREATE:{ result = AbstractWin32Component::handleEventMessages( message, wParam, lParam, wndProcResult ); } break; case LVN_BEGINDRAG:{ NMLISTVIEW* lvNotificationHdr = (LPNMLISTVIEW)lParam; } break; case LVN_BEGINLABELEDIT:{ } break; case LVN_BEGINRDRAG:{ } break; case NM_DBLCLK : { StringUtils::trace( "NM_DBLCLK\n" ); } break; case LVN_COLUMNCLICK:{ NMLISTVIEW* nmlistView = (NMLISTVIEW*)lParam; ColumnItem* item = listviewControl_->getColumnModel()->getItemFromIndex( (ulong32)nmlistView->iSubItem ); if ( NULL != item ) { POINT pt = {0,0}; ::GetCursorPos( &pt ); ::ScreenToClient( hwnd_, &pt ); MouseEvent event( item, ListViewControl::COLUMN_MOUSE_EVENT_CLICK, Win32UIUtils::translateButtonMask( MK_LBUTTON ), Win32UIUtils::translateKeyMask( 0 ), &Point(pt.x, pt.y) ); listviewControl_->handleEvent( &event ); } result = true; } break; case HDN_BEGINTRACK : { headerControlIsTracking_ = true; wndProcResult = FALSE; result = true; } break; case HDN_ITEMCHANGINGW: { if ( true == headerControlIsTracking_ ) { NMHEADERW* nmHeader = (NMHEADERW*)lParam; if ( nmHeader->pitem->mask & HDI_WIDTH ) { ColumnItem* item = listviewControl_->getColumnModel()->getItemFromIndex( (ulong32)nmHeader->iItem ); if ( NULL != item ) { item->setWidth( nmHeader->pitem->cxy ); InvalidateRect( hwnd_, NULL, TRUE ); } } } wndProcResult = FALSE; result = true; } break; case HDN_ITEMCHANGINGA: { if ( true == headerControlIsTracking_ ) { NMHEADERA* nmHeader = (NMHEADERA*)lParam; if ( nmHeader->pitem->mask & HDI_WIDTH ) { ColumnItem* item = listviewControl_->getColumnModel()->getItemFromIndex( (ulong32)nmHeader->iItem ); if ( NULL != item ) { item->setWidth( nmHeader->pitem->cxy ); InvalidateRect( hwnd_, NULL, TRUE ); } } } wndProcResult = FALSE; result = true; } break; case HDN_ENDTRACKW : { NMHEADERW* nmHeader = (NMHEADERW*)lParam; headerControlIsTracking_ = false; if ( (nmHeader->pitem->mask & HDI_WIDTH) && (listviewControl_->getColumnModel()->getCount() > 0) ) { ColumnItem* item = listviewControl_->getColumnModel()->getItemFromIndex( (ulong32)nmHeader->iItem ); if ( NULL != item ) { item->setWidth( nmHeader->pitem->cxy ); InvalidateRect( hwnd_, NULL, TRUE ); } } wndProcResult = FALSE; result = true; } break; case HDN_ENDTRACKA : { NMHEADERA* nmHeader = (NMHEADERA*)lParam; headerControlIsTracking_ = false; if ( (nmHeader->pitem->mask & HDI_WIDTH) && (listviewControl_->getColumnModel()->getCount() > 0) ) { ColumnItem* item = listviewControl_->getColumnModel()->getItemFromIndex( (ulong32)nmHeader->iItem ); if ( NULL != item ) { item->setWidth( nmHeader->pitem->cxy ); InvalidateRect( hwnd_, NULL, TRUE ); } } wndProcResult = FALSE; result = true; } break; case LVN_DELETEALLITEMS:{ } break; case LVN_DELETEITEM:{ } break; case LVN_ENDLABELEDITW:{ NMLVDISPINFOW* displayInfo = (NMLVDISPINFOW*)lParam; wndProcResult = (NULL != displayInfo->item.pszText) ? TRUE : FALSE;; result = true; if ( NULL != displayInfo->item.pszText ){ String newCaption = displayInfo->item.pszText; ListItem* item = (ListItem*)displayInfo->item.lParam; if ( NULL != item ){ item->setCaption( newCaption ); item->setSelected( true ); } } } break; case LVN_ENDLABELEDITA:{ NMLVDISPINFOA* displayInfo = (NMLVDISPINFOA*)lParam; wndProcResult = (NULL != displayInfo->item.pszText) ? TRUE : FALSE;; result = true; if ( NULL != displayInfo->item.pszText ){ String newCaption = displayInfo->item.pszText; ListItem* item = (ListItem*)displayInfo->item.lParam; if ( NULL != item ){ item->setCaption( newCaption ); item->setSelected( true ); } } } break; case LVN_GETDISPINFOW:{ NMLVDISPINFOW* displayInfo = (NMLVDISPINFOW*)lParam; if ( displayInfo->hdr.hwndFrom == hwnd_ ) { ListItem* item = (ListItem*)displayInfo->item.lParam; if ( NULL != item ) { String caption; if ( displayInfo->item.iSubItem > 0 ) { ListItem::SubItem* subItem = item->getSubItem( displayInfo->item.iSubItem - 1 ); if ( NULL != subItem ) { caption = subItem->getCaption(); } } else{ caption = item->getCaption(); } // changed to unsigned ints after discussion with Jim, // but he seemed uncertain so it'd be worth checking - ACH unsigned int size = VCF::minVal<unsigned int>( caption.size(), displayInfo->item.cchTextMax ); caption.copy( displayInfo->item.pszText, size ); if ( size < displayInfo->item.cchTextMax ) { displayInfo->item.pszText[size] = '\0'; } } } } break; case LVN_GETDISPINFOA:{ NMLVDISPINFOA* displayInfo = (NMLVDISPINFOA*)lParam; if ( displayInfo->hdr.hwndFrom == hwnd_ ) { ListItem* item = (ListItem*)displayInfo->item.lParam; if ( NULL != item ) { AnsiString caption; if ( displayInfo->item.iSubItem > 0 ) { ListItem::SubItem* subItem = item->getSubItem( displayInfo->item.iSubItem - 1 ); if ( NULL != subItem ) { caption = subItem->getCaption(); } } else{ caption = item->getCaption(); } // changed to unsigned ints after discussion with Jim, // but he seemed uncertain so it'd be worth checking - ACH unsigned int size = VCF::minVal<unsigned int>( caption.size(), displayInfo->item.cchTextMax ); caption.copy( displayInfo->item.pszText, size ); if ( size < displayInfo->item.cchTextMax ) { displayInfo->item.pszText[size] = '\0'; } } } } break; case LVN_GETINFOTIPW:{ } break; case LVN_GETINFOTIPA:{ } break; case LVN_HOTTRACK:{ } break; case LVN_ITEMACTIVATE:{ } break; case LVN_MARQUEEBEGIN:{ } break; case LVN_ODCACHEHINT:{ } break; case LVN_ODFINDITEM:{ } break; case LVN_ODSTATECHANGED:{ } break; case LVN_INSERTITEM:{ } break; case LVN_ITEMCHANGED:{ NMLISTVIEW* lvNotificationHdr = (LPNMLISTVIEW)lParam; if ( -1 != lvNotificationHdr->iItem ){ ListItem* item = (ListItem*)lvNotificationHdr->lParam; if ( NULL != item ){ if ( (lvNotificationHdr->uChanged & LVIF_STATE) != 0 ) { internalMessage_ = true; if ( (lvNotificationHdr->uNewState & LVIS_SELECTED) != 0 ){ item->setSelected( true ); POINT tmpPt = {0,0};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?