Changeset 3280 for trunk/src/comctl32/treeview.cpp
- Timestamp:
- Mar 30, 2000, 5:39:10 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/treeview.cpp
r3182 r3280 1 /* $Id: treeview.cpp,v 1. 4 2000-03-21 17:30:46cbratschi Exp $ */1 /* $Id: treeview.cpp,v 1.5 2000-03-30 15:39:10 cbratschi Exp $ */ 2 2 /* Treeview control 3 3 * … … 33 33 - bug in SetScrollInfo/ShowScrollBar: WM_SIZE and WM_NCPAINT problems (i.e. RegEdit) 34 34 - VK_LEFT in WinHlp32 displays expanded icon 35 - tooltips not finished36 35 - expand not finished 37 36 - TVS_FULLROWSELECT … … 84 83 static LRESULT TREEVIEW_EnsureVisible(HWND hwnd,HTREEITEM hItem); 85 84 static VOID TREEVIEW_ISearch(HWND hwnd,CHAR ch); 85 static VOID TREEVIEW_CheckInfoTip(HWND hwnd); 86 86 87 87 static LRESULT CALLBACK TREEVIEW_Edit_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); … … 1030 1030 INT iItem,len; 1031 1031 BOOL mustRefresh = FALSE; 1032 BOOL mustRepaint = FALSE; 1032 BOOL mustRepaintItem = FALSE; 1033 BOOL refreshFullLine = FALSE; 1033 1034 1034 1035 if (infoPtr->hwndEdit) SetFocus(hwnd); … … 1049 1050 { 1050 1051 wineItem->iImage = tvItem->iImage; 1051 mustRepaint = TRUE;1052 mustRepaintItem = TRUE; 1052 1053 } 1053 1054 … … 1064 1065 { 1065 1066 wineItem->iSelectedImage = tvItem->iSelectedImage; 1066 mustRepaint = TRUE;1067 mustRepaintItem = TRUE; 1067 1068 } 1068 1069 … … 1074 1075 wineItem->state |= (tvItem->state & tvItem->stateMask); 1075 1076 wineItem->stateMask |= tvItem->stateMask; 1076 mustRepaint = (oldState != wineItem->state) || (oldMask != wineItem->stateMask);1077 mustRepaintItem = (oldState != wineItem->state) || (oldMask != wineItem->stateMask); 1077 1078 } 1078 1079 … … 1085 1086 len = lstrlenW(tvItem->pszText)+1; 1086 1087 1088 mustRepaintItem = ((wineItem->pszText == LPSTR_TEXTCALLBACKW) || (lstrcmpW(wineItem->pszText,tvItem->pszText) != 0)); 1087 1089 if (len > wineItem->cchTextMax) 1088 1090 { … … 1094 1096 } else 1095 1097 { 1096 if (wineItem->cchTextMax) 1097 { 1098 if (wineItem->pszText != LPSTR_TEXTCALLBACKW) COMCTL32_Free (wineItem->pszText); 1099 wineItem->cchTextMax = 0; 1100 } 1098 if (wineItem->pszText != LPSTR_TEXTCALLBACKW) COMCTL32_Free(wineItem->pszText); 1099 wineItem->cchTextMax = 0; 1101 1100 wineItem->pszText = LPSTR_TEXTCALLBACKW; 1101 mustRepaintItem = TRUE; 1102 1102 } 1103 1103 } else … … 1105 1105 if ((LPSTR)tvItem->pszText != LPSTR_TEXTCALLBACKA) 1106 1106 { 1107 mustRepaintItem = ((wineItem->pszText == LPSTR_TEXTCALLBACKW) || (lstrcmpAtoW((CHAR*)tvItem->pszText,wineItem->pszText) != 0)); 1107 1108 len = lstrlenA((LPSTR)tvItem->pszText)+1; 1108 1109 if (len > wineItem->cchTextMax) … … 1115 1116 } else 1116 1117 { 1117 if (wineItem->cchTextMax) 1118 { 1119 if (wineItem->pszText != LPSTR_TEXTCALLBACKW) COMCTL32_Free(wineItem->pszText); 1120 wineItem->cchTextMax = 0; 1121 } 1118 if (wineItem->pszText != LPSTR_TEXTCALLBACKW) COMCTL32_Free(wineItem->pszText); 1119 wineItem->cchTextMax = 0; 1122 1120 wineItem->pszText = LPSTR_TEXTCALLBACKW; 1121 mustRepaintItem = TRUE; 1123 1122 } 1124 1123 } 1125 mustRepaint= TRUE;1124 refreshFullLine = TRUE; 1126 1125 } 1127 1126 … … 1129 1128 { 1130 1129 wineItem->mask |= tvItem->mask; 1131 mustRepaint = TRUE;1132 } 1133 1134 if (mustRepaint || mustRefresh)1130 mustRepaintItem = TRUE; 1131 } 1132 1133 if (mustRepaintItem || mustRefresh) 1135 1134 { 1136 1135 wineItem->calculated = FALSE; … … 1138 1137 TREEVIEW_QueueRefresh(hwnd); 1139 1138 else 1140 TREEVIEW_RefreshItem(hwnd,wineItem, FALSE);1139 TREEVIEW_RefreshItem(hwnd,wineItem,refreshFullLine); 1141 1140 } 1142 1141 … … 1686 1685 KillTimer(hwnd,TV_ISEARCH_TIMER); 1687 1686 infoPtr->Timer &= ~TV_ISEARCH_TIMER_SET; 1687 return 0; 1688 1689 case TV_INFOTIP_TIMER: 1690 TREEVIEW_CheckInfoTip(hwnd); 1688 1691 return 0; 1689 1692 } … … 3063 3066 if (tvdi.item.mask & TVIF_DI_SETITEM) 3064 3067 { 3065 wineItem->pszText = tvdi.item.pszText;3066 3068 if (buf == tvdi.item.pszText) 3067 3069 { 3070 wineItem->pszText = tvdi.item.pszText; 3068 3071 wineItem->cchTextMax = 128; 3069 3072 } else 3070 { 3071 //user-supplied buffer 3073 { //user-supplied buffer 3074 INT len = lstrlenW(tvdi.item.pszText); 3075 3072 3076 COMCTL32_Free(buf); 3073 wineItem->cchTextMax = 0; 3077 if (len > 0) 3078 { 3079 len++; 3080 wineItem->pszText = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR)); 3081 lstrcpyW(wineItem->pszText,tvdi.item.pszText); 3082 wineItem->cchTextMax = len; 3083 } else 3084 { 3085 wineItem->pszText = NULL; 3086 wineItem->cchTextMax = len; 3087 } 3074 3088 } 3075 3089 *mustFree = FALSE; … … 3095 3109 COMCTL32_Free(buf); 3096 3110 } else 3097 { 3098 //user-supplied buffer 3111 { //user-supplied buffer 3112 INT len = lstrlenA((CHAR*)tvdi.item.pszText); 3113 3099 3114 COMCTL32_Free(buf); 3100 wineItem->cchTextMax = 0; 3115 if (len > 0) 3116 { 3117 len++; 3118 wineItem->pszText = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR)); 3119 lstrcpyAtoW(wineItem->pszText,(CHAR*)tvdi.item.pszText); 3120 wineItem->cchTextMax = len; 3121 } else 3122 { 3123 wineItem->pszText = NULL; 3124 wineItem->cchTextMax = len; 3125 } 3101 3126 } 3102 3127 *mustFree = FALSE; … … 3354 3379 } 3355 3380 3356 static LRESULT TREEVIEW_HitTest(HWND hwnd,LPTVHITTESTINFO lpht )3381 static LRESULT TREEVIEW_HitTest(HWND hwnd,LPTVHITTESTINFO lpht,BOOL ignoreClientRect) 3357 3382 { 3358 3383 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd); … … 3363 3388 3364 3389 if (!lpht) return 0; 3365 GetClientRect (hwnd, &rect); 3390 3366 3391 status = 0; 3367 3392 x = lpht->pt.x; 3368 3393 y = lpht->pt.y; 3369 if (x < rect.left) status |= TVHT_TOLEFT; 3370 if (x > rect.right) status |= TVHT_TORIGHT; 3371 if (y < rect.top ) status |= TVHT_ABOVE; 3372 if (y > rect.bottom) status |= TVHT_BELOW; 3373 3374 if (status) 3375 { 3376 lpht->flags = status; 3377 lpht->hItem = 0; 3378 3379 return 0; 3394 3395 if (!ignoreClientRect) 3396 { 3397 GetClientRect (hwnd, &rect); 3398 3399 if (x < rect.left) status |= TVHT_TOLEFT; 3400 if (x > rect.right) status |= TVHT_TORIGHT; 3401 if (y < rect.top ) status |= TVHT_ABOVE; 3402 if (y > rect.bottom) status |= TVHT_BELOW; 3403 3404 if (status) 3405 { 3406 lpht->flags = status; 3407 lpht->hItem = 0; 3408 3409 return 0; 3410 } 3380 3411 } 3381 3412 … … 3597 3628 { 3598 3629 tvdi.item.pszText = textW; 3599 tvdi.item.cchTextMax = lstrlenW(textW) ;3630 tvdi.item.cchTextMax = lstrlenW(textW)+1; 3600 3631 } else 3601 3632 { 3602 3633 tvdi.item.pszText = (LPWSTR)textA; 3603 tvdi.item.cchTextMax = lstrlenA(textA) ;3634 tvdi.item.cchTextMax = lstrlenA(textA)+1; 3604 3635 } 3605 3636 … … 3713 3744 } 3714 3745 3715 if (!TREEVIEW_HitTest(hwnd,&hitinfo ) || !(hitinfo.flags & TVHT_ONITEM)) return FALSE;3746 if (!TREEVIEW_HitTest(hwnd,&hitinfo,FALSE) || !(hitinfo.flags & TVHT_ONITEM)) return FALSE; 3716 3747 wineItem = &infoPtr->items [(INT)hitinfo.hItem]; 3717 3748 … … 3723 3754 } 3724 3755 3756 VOID TREEVIEW_ShowInfoTip(HWND hwnd,TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item) 3757 { 3758 LPWSTR text; 3759 BOOL mustFree = FALSE; 3760 TTTOOLINFOW ti; 3761 POINT pt; 3762 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 3763 3764 if(dwStyle & TVS_INFOTIP) 3765 { 3766 NMTVGETINFOTIPW tvgit; 3767 WCHAR* buf = (WCHAR*)COMCTL32_Alloc(isUnicodeNotify(&infoPtr->header) ? INFOTIPSIZE*sizeof(WCHAR):INFOTIPSIZE*sizeof(CHAR)); 3768 3769 tvgit.pszText = buf; 3770 tvgit.cchTextMax = INFOTIPSIZE; 3771 tvgit.hItem = item->hItem; 3772 tvgit.lParam = item->lParam; 3773 3774 sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_GETINFOTIPW:TVN_GETINFOTIPA,&tvgit.hdr); 3775 if (isUnicodeNotify(&infoPtr->header)) 3776 { 3777 if (buf != tvgit.pszText) COMCTL32_Free(buf); else mustFree = TRUE; 3778 text = tvgit.pszText; 3779 } else 3780 { 3781 text = (WCHAR*)COMCTL32_Alloc(tvgit.cchTextMax*sizeof(WCHAR)); 3782 lstrcpyAtoW(text,(LPSTR)tvgit.pszText); 3783 COMCTL32_Free(buf); 3784 } 3785 } else 3786 { 3787 if (item->pszText == LPSTR_TEXTCALLBACKW) 3788 text = TREEVIEW_CallbackText(hwnd,item,&mustFree); 3789 else 3790 text = item->pszText; 3791 } 3792 3793 infoPtr->tipItem = item->hItem; 3794 SetTimer(hwnd,TV_INFOTIP_TIMER,TV_INFOTIP_DELAY,0); 3795 infoPtr->Timer |= TV_INFOTIP_TIMER_SET; 3796 3797 ti.cbSize = sizeof(ti); 3798 ti.uId = 0; 3799 ti.hwnd = hwnd; 3800 ti.hinst = 0; 3801 ti.lpszText = text; 3802 pt.x = item->text.left; 3803 pt.y = item->text.top; 3804 ClientToScreen(hwnd,&pt); 3805 SendMessageA(infoPtr->hwndToolTip,TTM_TRACKPOSITION,0,(LPARAM)MAKELPARAM(pt.x,pt.y)); 3806 SendMessageA(infoPtr->hwndToolTip,TTM_UPDATETIPTEXTW,0,(LPARAM)&ti); 3807 SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)TRUE,(LPARAM)&ti); 3808 3809 if (mustFree) COMCTL32_Free(text); 3810 } 3811 3812 VOID TREEVIEW_HideInfoTip(HWND hwnd,TREEVIEW_INFO *infoPtr) 3813 { 3814 if (infoPtr->tipItem) 3815 { 3816 TTTOOLINFOA ti; 3817 3818 infoPtr->tipItem = 0; 3819 KillTimer(hwnd,TV_INFOTIP_TIMER); 3820 infoPtr->Timer &= ~TV_INFOTIP_TIMER_SET; 3821 3822 ti.cbSize = sizeof(TTTOOLINFOA); 3823 ti.uId = 0; 3824 ti.hwnd = (UINT)hwnd; 3825 3826 SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)FALSE,(LPARAM)&ti); 3827 } 3828 } 3829 3830 static VOID TREEVIEW_CheckInfoTip(HWND hwnd) 3831 { 3832 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd); 3833 TVHITTESTINFO ht; 3834 3835 GetCursorPos(&ht.pt); 3836 ScreenToClient(hwnd,&ht.pt); 3837 TREEVIEW_HitTest(hwnd,&ht,TRUE); 3838 3839 if ((ht.hItem != infoPtr->tipItem) || !(ht.flags & TVHT_ONITEMLABEL)) 3840 TREEVIEW_HideInfoTip(hwnd,infoPtr); 3841 } 3842 3725 3843 static LRESULT TREEVIEW_MouseMove(HWND hwnd,WPARAM wParam,LPARAM lParam) 3726 3844 { … … 3732 3850 ht.pt.y = (INT)HIWORD(lParam); 3733 3851 3734 TREEVIEW_HitTest(hwnd,&ht );3852 TREEVIEW_HitTest(hwnd,&ht,FALSE); 3735 3853 3736 3854 if (ht.hItem) … … 3740 3858 item = &infoPtr->items[(INT)ht.hItem]; 3741 3859 3742 if (infoPtr->hwndToolTip && ((item->text.left < 0) || (item->text.right > infoPtr->uVisibleWidth)) && (infoPtr->tipItem != item->hItem)) 3743 { 3744 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 3745 LPWSTR text; 3746 BOOL mustFree = FALSE; 3747 TTTOOLINFOW ti; 3748 POINT pt; 3749 3750 if(dwStyle & TVS_INFOTIP) 3751 { 3752 NMTVGETINFOTIPW tvgit; 3753 WCHAR* buf = (WCHAR*)COMCTL32_Alloc(isUnicodeNotify(&infoPtr->header) ? INFOTIPSIZE*sizeof(WCHAR):INFOTIPSIZE*sizeof(CHAR)); 3754 3755 tvgit.pszText = buf; 3756 tvgit.cchTextMax = INFOTIPSIZE; 3757 tvgit.hItem = item->hItem; 3758 tvgit.lParam = item->lParam; 3759 3760 sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_GETINFOTIPW:TVN_GETINFOTIPA,&tvgit.hdr); 3761 if (isUnicodeNotify(&infoPtr->header)) 3762 { 3763 if (buf != tvgit.pszText) COMCTL32_Free(buf); else mustFree = TRUE; 3764 text = tvgit.pszText; 3765 } else 3766 { 3767 text = (WCHAR*)COMCTL32_Alloc(tvgit.cchTextMax*sizeof(WCHAR)); 3768 lstrcpyAtoW(text,(LPSTR)tvgit.pszText); 3769 COMCTL32_Free(buf); 3770 } 3771 } else 3772 { 3773 if (item->pszText == LPSTR_TEXTCALLBACKW) 3774 text = TREEVIEW_CallbackText(hwnd,item,&mustFree); 3775 else 3776 text = item->pszText; 3777 } 3778 #if 0 //CB: not yet 3779 infoPtr->tipItem = item->hItem; 3780 ti.cbSize = sizeof(ti); 3781 ti.uId = 0; 3782 ti.hwnd = hwnd; 3783 ti.hinst = 0; 3784 ti.lpszText = text; 3785 pt.x = ti.rect.left; 3786 pt.y = ti.rect.top; 3787 ClientToScreen(hwnd,&pt); 3788 SendMessageA(infoPtr->hwndToolTip,TTM_TRACKPOSITION,0,(LPARAM)MAKELPARAM(pt.x,pt.y)); 3789 SendMessageA(infoPtr->hwndToolTip,TTM_UPDATETIPTEXTW,0,(LPARAM)&ti); 3790 SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)TRUE,(LPARAM)&ti); 3791 #endif 3792 if (mustFree) COMCTL32_Free(text); 3793 } 3860 if (infoPtr->hwndToolTip && (ht.flags & TVHT_ONITEMLABEL) && 3861 ((item->text.left < 0) || (item->text.right > infoPtr->uVisibleWidth) || (item->text.top < 0) || (item->text.bottom > infoPtr->uVisibleHeight)) && 3862 (infoPtr->tipItem != item->hItem)) 3863 TREEVIEW_ShowInfoTip(hwnd,infoPtr,item); 3864 else 3865 TREEVIEW_HideInfoTip(hwnd,infoPtr); 3794 3866 3795 3867 if (dwStyle & TVS_TRACKSELECT) … … 3824 3896 ht.pt.y = (INT)HIWORD(lParam); 3825 3897 3826 TREEVIEW_HitTest (hwnd,&ht );3898 TREEVIEW_HitTest (hwnd,&ht,FALSE); 3827 3899 3828 3900 bTrack = (ht.flags & TVHT_ONITEM) && !(dwStyle & TVS_DISABLEDRAGDROP); … … 3907 3979 ht.pt.y = (INT)HIWORD(lParam); 3908 3980 3909 TREEVIEW_HitTest(hwnd,&ht );3981 TREEVIEW_HitTest(hwnd,&ht,FALSE); 3910 3982 3911 3983 if (TREEVIEW_TrackMouse(hwnd, ht.pt)) … … 4731 4803 } 4732 4804 4805 static LRESULT TREEVIEW_Notify(HWND hwnd,WPARAM wParam,LPARAM lParam) 4806 { 4807 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd); 4808 LPNMHDR hdr = (LPNMHDR)lParam; 4809 4810 if (hdr->hwndFrom == infoPtr->hwndToolTip) 4811 { 4812 LPARAM lp = (LPARAM)GetMessagePos(); 4813 POINT pt; 4814 4815 pt.x = (INT)LOWORD(lp); 4816 pt.y = (INT)HIWORD(lp); 4817 ScreenToClient(hwnd,&pt); 4818 lp = MAKELONG(pt.x,pt.y); 4819 4820 if (hdr->code == (UINT)NM_CLICK) 4821 TREEVIEW_LButtonDown(hwnd,0,lp); 4822 else if (hdr->code == (UINT)NM_RCLICK) 4823 TREEVIEW_RButtonDown(hwnd,0,lp); 4824 else if (hdr->code == (UINT)NM_DBLCLK) 4825 TREEVIEW_LButtonDoubleClick(hwnd,0,lp); 4826 else if (hdr->code == (UINT)NM_RDBLCLK) 4827 TREEVIEW_RButtonDoubleClick(hwnd,0,lp); 4828 } 4829 4830 return 0; 4831 } 4832 4733 4833 static LRESULT WINAPI 4734 4834 TREEVIEW_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) … … 4803 4903 4804 4904 case TVM_HITTEST: 4805 return TREEVIEW_HitTest(hwnd,(LPTVHITTESTINFO)lParam );4905 return TREEVIEW_HitTest(hwnd,(LPTVHITTESTINFO)lParam,FALSE); 4806 4906 4807 4907 case TVM_CREATEDRAGIMAGE: … … 4924 5024 case WM_RBUTTONDBLCLK: 4925 5025 return TREEVIEW_RButtonDoubleClick(hwnd,wParam,lParam); 5026 5027 case WM_NOTIFY: 5028 return TREEVIEW_Notify(hwnd,wParam,lParam); 4926 5029 4927 5030 case WM_STYLECHANGED:
Note:
See TracChangeset
for help on using the changeset viewer.