Changeset 2228 for trunk/src/user32/edit.cpp
- Timestamp:
- Dec 28, 1999, 6:04:24 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/edit.cpp
r2221 r2228 1 /* $Id: edit.cpp,v 1.2 7 1999-12-27 22:53:52 cbratschi Exp $ */1 /* $Id: edit.cpp,v 1.28 1999-12-28 17:04:22 cbratschi Exp $ */ 2 2 /* 3 3 * Edit control … … 20 20 new in Win98, Win2k: for single line too 21 21 - WinNT/Win2k: higher size limits (single: 0x7FFFFFFE, multi: none) 22 - too many GetDC/ReleaseDC calls -> GetDC is very slow! 23 EM_REPLACESEL: calls more than 10 times GetDC/ReleaseDC! 24 add HDC parameter 22 25 */ 23 26 … … 182 185 static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action); 183 186 static VOID EDIT_Draw(HWND hwnd,EDITSTATE *es,HDC hdc); 184 static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es );187 static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es,BOOL useCache); 185 188 186 189 /* … … 623 626 //DPRINTF_EDIT_MSG32("WM_ENABLE"); 624 627 es->bEnableState = (BOOL)wParam; 625 EDIT_Refresh(hwnd,es );628 EDIT_Refresh(hwnd,es,FALSE); 626 629 break; 627 630 … … 767 770 static void EDIT_BuildLineDefs_ML(HWND hwnd, EDITSTATE *es) 768 771 { 769 HDC dc ;772 HDC dc = 0; 770 773 HFONT old_font = 0; 771 774 LPSTR start, cp; … … 782 785 es->line_count = 0; 783 786 es->text_width = 0; 784 785 dc = GetDC(hwnd);786 if (es->font)787 old_font = SelectObject(dc, es->font);788 787 789 788 fw = es->format_rect.right - es->format_rect.left; … … 809 808 current_def->net_length = cp - start; 810 809 } 810 811 if (!dc) 812 { 813 dc = GetDC(hwnd); 814 if (es->font) 815 old_font = SelectObject(dc, es->font); 816 } 817 811 818 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc, 812 819 start, current_def->net_length, … … 857 864 es->line_count++; 858 865 } while (current_def->ending != END_0); 859 if (es->font) 860 SelectObject(dc, old_font); 861 ReleaseDC(hwnd, dc); 866 if (dc) 867 { 868 if (es->font) 869 SelectObject(dc, old_font); 870 ReleaseDC(hwnd, dc); 871 } 862 872 EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE); 863 873 } … … 905 915 { 906 916 INT index; 907 HDC dc ;917 HDC dc = 0; 908 918 HFONT old_font = 0; 909 919 … … 929 939 return line_index; 930 940 } 931 dc = GetDC(hwnd); 932 if (es->font) 933 old_font = SelectObject(dc, es->font); 934 low = line_index + 1; 935 high = line_index + line_def->net_length + 1; 936 while (low < high - 1) 937 { 938 INT mid = (low + high) / 2; 939 if (LOWORD(GetTabbedTextExtentA(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid; 940 else low = mid; 941 } 942 index = low; 941 low = line_index + 1; 942 high = line_index + line_def->net_length + 1; 943 if (low < high-1) 944 { 945 if (!dc) 946 { 947 dc = GetDC(hwnd); 948 if (es->font) 949 old_font = SelectObject(dc, es->font); 950 } 951 952 while (low < high-1) 953 { 954 INT mid = (low + high) / 2; 955 if (LOWORD(GetTabbedTextExtentA(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid; 956 else low = mid; 957 } 958 } 959 index = low; 943 960 944 961 if (after_wrap) … … 954 971 return es->x_offset; 955 972 text = EDIT_GetPasswordPointer_SL(hwnd, es); 956 dc = GetDC(hwnd);957 if (es->font)958 old_font = SelectObject(dc, es->font);959 973 if (x < 0) 960 974 { 961 INT low = 0; 962 INT high = es->x_offset; 963 while (low < high - 1) 975 INT low = 0; 976 INT high = es->x_offset; 977 978 if (low < high-1) 979 { 980 if (!dc) 964 981 { 965 INT mid = (low + high) / 2; 966 GetTextExtentPoint32A( dc, text + mid, 967 es->x_offset - mid, &size ); 968 if (size.cx > -x) low = mid; 969 else high = mid; 982 dc = GetDC(hwnd); 983 if (es->font) 984 old_font = SelectObject(dc, es->font); 970 985 } 971 index = low; 972 } 973 else 986 987 while (low < high-1) 988 { 989 INT mid = (low + high) / 2; 990 991 GetTextExtentPoint32A( dc, text + mid, 992 es->x_offset - mid, &size ); 993 if (size.cx > -x) low = mid; 994 else high = mid; 995 } 996 } 997 index = low; 998 } else 974 999 { 975 INT low = es->x_offset; 976 INT high = lstrlenA(es->text) + 1; 977 while (low < high - 1) 1000 INT low = es->x_offset; 1001 INT high = lstrlenA(es->text) + 1; 1002 1003 if (low < high-1) 1004 { 1005 if (!dc) 978 1006 { 979 INT mid = (low + high) / 2; 980 GetTextExtentPoint32A( dc, text + es->x_offset, 981 mid - es->x_offset, &size ); 982 if (size.cx > x) high = mid; 983 else low = mid; 1007 dc = GetDC(hwnd); 1008 if (es->font) 1009 old_font = SelectObject(dc, es->font); 984 1010 } 985 index = low; 1011 1012 while (low < high-1) 1013 { 1014 INT mid = (low + high) / 2; 1015 1016 GetTextExtentPoint32A( dc, text + es->x_offset, 1017 mid - es->x_offset, &size ); 1018 if (size.cx > x) high = mid; 1019 else low = mid; 1020 } 1021 } 1022 index = low; 986 1023 } 987 1024 if (es->style & ES_PASSWORD) 988 1025 HeapFree(es->heap, 0 ,text); 989 1026 } 990 if (es->font) 991 SelectObject(dc, old_font); 992 ReleaseDC(hwnd, dc); 1027 if (dc) 1028 { 1029 if (es->font) 1030 SelectObject(dc, old_font); 1031 ReleaseDC(hwnd, dc); 1032 } 993 1033 return index; 994 1034 } … … 1099 1139 { 1100 1140 HideCaret(hwnd); 1101 InvalidateRect(hwnd, &rc, FALSE);1141 InvalidateRect(hwnd, &rc, TRUE); 1102 1142 ShowCaret(hwnd); 1103 1143 } … … 2209 2249 INT x; 2210 2250 INT y = 0; 2211 HDC dc ;2251 HDC dc = 0; 2212 2252 HFONT old_font = 0; 2213 2253 SIZE size; 2214 2254 2215 2255 index = MIN(index, len); 2216 dc = GetDC(hwnd); 2217 if (es->font) 2218 old_font = SelectObject(dc, es->font); 2256 if (!dc) 2257 { 2258 dc = GetDC(hwnd); 2259 if (es->font) 2260 old_font = SelectObject(dc, es->font); 2261 } 2219 2262 if (es->style & ES_MULTILINE) { 2220 2263 l = EDIT_EM_LineFromChar(hwnd, es, index); … … 2384 2427 2385 2428 EDIT_EM_SetSel(hwnd, es, s, s, FALSE); 2429 2386 2430 es->flags |= EF_MODIFIED; 2387 2431 es->flags |= EF_UPDATE; 2388 2432 EDIT_EM_ScrollCaret(hwnd, es); 2389 2390 2433 EDIT_NOTIFY_PARENT(hwnd,EN_UPDATE); 2391 2434 /* FIXME: really inefficient */ 2392 EDIT_Refresh(hwnd,es );2435 EDIT_Refresh(hwnd,es,TRUE); 2393 2436 } 2394 2437 … … 2486 2529 } while ((x < goal) && es->x_offset); 2487 2530 /* FIXME: use ScrollWindow() somehow to improve performance */ 2488 EDIT_Refresh(hwnd,es );2531 EDIT_Refresh(hwnd,es,TRUE); 2489 2532 EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE); 2490 2533 } else if (x > es->format_rect.right) … … 2499 2542 } while ((x > goal) && (x_last > es->format_rect.right)); 2500 2543 /* FIXME: use ScrollWindow() somehow to improve performance */ 2501 EDIT_Refresh(hwnd,es );2544 EDIT_Refresh(hwnd,es,TRUE); 2502 2545 EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE); 2503 2546 } … … 2564 2607 es->flags &= ~EF_UPDATE; 2565 2608 EDIT_BuildLineDefs_ML(hwnd, es); 2566 EDIT_Refresh(hwnd,es );2609 EDIT_Refresh(hwnd,es,FALSE); 2567 2610 EDIT_EM_ScrollCaret(hwnd, es); 2568 2611 EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE); … … 2630 2673 EDIT_BuildLineDefs_ML(hwnd, es); 2631 2674 2632 EDIT_Refresh(hwnd,es );2675 EDIT_Refresh(hwnd,es,FALSE); 2633 2676 if (es->flags & EF_FOCUSED) { 2634 2677 DestroyCaret(); … … 2670 2713 es->style &= ~ES_PASSWORD; 2671 2714 } 2672 EDIT_Refresh(hwnd,es );2715 EDIT_Refresh(hwnd,es,FALSE); 2673 2716 } 2674 2717 … … 2693 2736 { 2694 2737 EDIT_SetRectNP(hwnd,es,lprc); 2695 EDIT_Refresh(hwnd,es );2738 EDIT_Refresh(hwnd,es,FALSE); 2696 2739 } 2697 2740 } … … 2798 2841 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { 2799 2842 EDIT_BuildLineDefs_ML(hwnd, es); 2800 EDIT_Refresh(hwnd,es );2843 EDIT_Refresh(hwnd,es,FALSE); 2801 2844 } 2802 2845 } … … 3719 3762 } 3720 3763 3721 static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es )3764 static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es,BOOL useCache) 3722 3765 { 3723 3766 HDC hdc,hdcCompatible; … … 3726 3769 3727 3770 if (!IsWindowVisible(hwnd)) return; 3771 3772 if (!useCache) 3773 { 3774 InvalidateRect(hwnd,NULL,TRUE); 3775 return; 3776 } 3728 3777 3729 3778 //CB: original controls redraws many times, cache drawing … … 3844 3893 3845 3894 if (redraw) 3846 EDIT_Refresh(hwnd,es );3895 EDIT_Refresh(hwnd,es,FALSE); 3847 3896 if (es->flags & EF_FOCUSED) { 3848 3897 DestroyCaret(); … … 3902 3951 SetRect(&rc, 0, 0, width, height); 3903 3952 EDIT_SetRectNP(hwnd, es, &rc); 3904 EDIT_Refresh(hwnd,es );3953 EDIT_Refresh(hwnd,es,FALSE); 3905 3954 } 3906 3955 }
Note:
See TracChangeset
for help on using the changeset viewer.