Changeset 2257 for trunk/src/user32/edit.cpp
- Timestamp:
- Dec 29, 1999, 11:54:04 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/edit.cpp
r2228 r2257 1 /* $Id: edit.cpp,v 1.2 8 1999-12-28 17:04:22cbratschi Exp $ */1 /* $Id: edit.cpp,v 1.29 1999-12-29 22:53:59 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 - too many redraws and recalculations! 25 23 */ 26 24 … … 154 152 * Helper functions only valid for one type of control 155 153 */ 156 static void EDIT_BuildLineDefs_ML(HWND hwnd, 154 static void EDIT_BuildLineDefs_ML(HWND hwnd,EDITSTATE *es); 157 155 static LPSTR EDIT_GetPasswordPointer_SL(HWND hwnd, EDITSTATE *es); 158 156 static void EDIT_MoveDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend); … … 167 165 static INT EDIT_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap); 168 166 static void EDIT_ConfinePoint(HWND hwnd, EDITSTATE *es, LPINT x, LPINT y); 169 static void EDIT_GetLineRect(HWND hwnd, 167 static void EDIT_GetLineRect(HWND hwnd,HDC dc,EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc); 170 168 static void EDIT_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end); 171 169 static void EDIT_LockBuffer(HWND hwnd, EDITSTATE *es); … … 208 206 static INT EDIT_EM_LineLength(HWND hwnd, EDITSTATE *es, INT index); 209 207 static BOOL EDIT_EM_LineScroll(HWND hwnd, EDITSTATE *es, INT dx, INT dy); 210 static LRESULT EDIT_EM_PosFromChar(HWND hwnd, EDITSTATE *es, INT index, BOOL after_wrap);208 static LRESULT EDIT_EM_PosFromChar(HWND hwnd,HDC dc, EDITSTATE *es, INT index, BOOL after_wrap); 211 209 static void EDIT_EM_ReplaceSel(HWND hwnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace); 212 210 static LRESULT EDIT_EM_Scroll(HWND hwnd, EDITSTATE *es, INT action); … … 565 563 case EM_POSFROMCHAR: 566 564 //DPRINTF_EDIT_MSG32("EM_POSFROMCHAR"); 567 result = EDIT_EM_PosFromChar(hwnd, es, (INT)wParam, FALSE);565 result = EDIT_EM_PosFromChar(hwnd,0, es, (INT)wParam, FALSE); 568 566 break; 569 567 … … 768 766 * 769 767 */ 770 static void EDIT_BuildLineDefs_ML(HWND hwnd, 771 { 772 HDC dc = 0;768 static void EDIT_BuildLineDefs_ML(HWND hwnd,EDITSTATE *es) 769 { 770 HDC hdc = 0; 773 771 HFONT old_font = 0; 774 772 LPSTR start, cp; … … 809 807 } 810 808 811 if (! dc)809 if (!hdc) 812 810 { 813 dc = GetDC(hwnd);811 hdc = GetDC(hwnd); 814 812 if (es->font) 815 old_font = SelectObject( dc, es->font);813 old_font = SelectObject(hdc, es->font); 816 814 } 817 815 818 current_def->width = (INT)LOWORD(GetTabbedTextExtentA( dc,816 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, 819 817 start, current_def->net_length, 820 818 es->tabs_count, es->tabs)); … … 827 825 next = EDIT_CallWordBreakProc(hwnd, es, start - es->text, 828 826 prev + 1, current_def->net_length, WB_RIGHT); 829 current_def->width = (INT)LOWORD(GetTabbedTextExtentA( dc,827 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, 830 828 start, next, es->tabs_count, es->tabs)); 831 829 } while (current_def->width <= fw); … … 835 833 prev = next; 836 834 next++; 837 current_def->width = (INT)LOWORD(GetTabbedTextExtentA( dc,835 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, 838 836 start, next, es->tabs_count, es->tabs)); 839 837 } while (current_def->width <= fw); … … 843 841 current_def->net_length = prev; 844 842 current_def->ending = END_WRAP; 845 current_def->width = (INT)LOWORD(GetTabbedTextExtentA( dc, start,843 current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, start, 846 844 current_def->net_length, es->tabs_count, es->tabs)); 847 845 } … … 864 862 es->line_count++; 865 863 } while (current_def->ending != END_0); 866 if ( dc)864 if (hdc) 867 865 { 868 866 if (es->font) 869 SelectObject( dc, old_font);870 ReleaseDC(hwnd, dc);867 SelectObject(hdc, old_font); 868 ReleaseDC(hwnd, hdc); 871 869 } 872 870 EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE); … … 1058 1056 * 1059 1057 */ 1060 static void EDIT_GetLineRect(HWND hwnd, 1058 static void EDIT_GetLineRect(HWND hwnd,HDC dc,EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc) 1061 1059 { 1062 1060 INT line_index = EDIT_EM_LineIndex(hwnd, es, line); … … 1068 1066 rc->bottom = rc->top + es->line_height; 1069 1067 1070 rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(hwnd, es, line_index + scol, TRUE));1071 rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(hwnd, es, line_index + ecol, TRUE))+1;1068 rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(hwnd,dc, es, line_index + scol, TRUE)); 1069 rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(hwnd,dc, es, line_index + ecol, TRUE))+1; 1072 1070 } 1073 1071 … … 1134 1132 RECT rc; 1135 1133 1136 EDIT_GetLineRect(hwnd, es, 0, start, end, &line_rect);1134 EDIT_GetLineRect(hwnd,0, es, 0, start, end, &line_rect); 1137 1135 1138 1136 if (IntersectRect(&rc, &line_rect, &es->format_rect)) … … 1183 1181 HideCaret(hwnd); 1184 1182 if (sl == el) { 1185 EDIT_GetLineRect(hwnd, es, sl, sc, ec, &rcLine);1183 EDIT_GetLineRect(hwnd,0, es, sl, sc, ec, &rcLine); 1186 1184 1187 1185 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) 1188 1186 InvalidateRect(hwnd, &rcUpdate, TRUE); 1189 1187 } else { 1190 EDIT_GetLineRect(hwnd, es, sl, sc,1188 EDIT_GetLineRect(hwnd,0, es, sl, sc, 1191 1189 EDIT_EM_LineLength(hwnd, es, 1192 1190 EDIT_EM_LineIndex(hwnd, es, sl)), … … 1195 1193 InvalidateRect(hwnd, &rcUpdate, TRUE); 1196 1194 for (l = sl + 1 ; l < el ; l++) { 1197 EDIT_GetLineRect(hwnd, es, l, 0,1195 EDIT_GetLineRect(hwnd,0, es, l, 0, 1198 1196 EDIT_EM_LineLength(hwnd, es, 1199 1197 EDIT_EM_LineIndex(hwnd, es, l)), … … 1202 1200 InvalidateRect(hwnd, &rcUpdate, TRUE); 1203 1201 } 1204 EDIT_GetLineRect(hwnd, es, el, 0, ec, &rcLine);1202 EDIT_GetLineRect(hwnd,0, es, el, 0, ec, &rcLine); 1205 1203 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) 1206 1204 InvalidateRect(hwnd, &rcUpdate, TRUE); … … 1353 1351 INT e = es->selection_end; 1354 1352 BOOL after_wrap = (es->flags & EF_AFTER_WRAP); 1355 LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap);1353 LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap); 1356 1354 INT x = SLOWORD(pos); 1357 1355 INT y = SHIWORD(pos); … … 1378 1376 if (es->style & ES_MULTILINE) 1379 1377 e = EDIT_CharFromPos(hwnd, es, 0x3fffffff, 1380 HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);1378 HIWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap); 1381 1379 else 1382 1380 e = lstrlenA(es->text); … … 1423 1421 if (es->style & ES_MULTILINE) 1424 1422 e = EDIT_CharFromPos(hwnd, es, -es->x_offset, 1425 HIWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);1423 HIWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL); 1426 1424 else 1427 1425 e = 0; … … 1445 1443 INT e = es->selection_end; 1446 1444 BOOL after_wrap = (es->flags & EF_AFTER_WRAP); 1447 LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap);1445 LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap); 1448 1446 INT x = SLOWORD(pos); 1449 1447 INT y = SHIWORD(pos); … … 1473 1471 INT e = es->selection_end; 1474 1472 BOOL after_wrap = (es->flags & EF_AFTER_WRAP); 1475 LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap);1473 LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap); 1476 1474 INT x = SLOWORD(pos); 1477 1475 INT y = SHIWORD(pos); … … 1501 1499 INT e = es->selection_end; 1502 1500 BOOL after_wrap = (es->flags & EF_AFTER_WRAP); 1503 LRESULT pos = EDIT_EM_PosFromChar(hwnd, es, e, after_wrap);1501 LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap); 1504 1502 INT x = SLOWORD(pos); 1505 1503 INT y = SHIWORD(pos); … … 1599 1597 //TRACE_(edit)("line=%d\n", line); 1600 1598 1601 pos = EDIT_EM_PosFromChar(hwnd, es, EDIT_EM_LineIndex(hwnd, es, line), FALSE);1599 pos = EDIT_EM_PosFromChar(hwnd,dc, es, EDIT_EM_LineIndex(hwnd, es, line), FALSE); 1602 1600 x = SLOWORD(pos); 1603 1601 y = SHIWORD(pos); … … 1718 1716 BOOL after_wrap) 1719 1717 { 1720 LRESULT res = EDIT_EM_PosFromChar(hwnd, es, pos, after_wrap);1718 LRESULT res = EDIT_EM_PosFromChar(hwnd,0, es, pos, after_wrap); 1721 1719 INT x = SLOWORD(res); 1722 1720 INT y = SHIWORD(res); … … 1764 1762 es->format_rect.bottom = es->format_rect.top + es->line_height; 1765 1763 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) 1766 EDIT_BuildLineDefs_ML(hwnd, 1764 EDIT_BuildLineDefs_ML(hwnd,es); 1767 1765 EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE); 1768 1766 } … … 2226 2224 IntersectRect(&rc, &rc1, &es->format_rect); 2227 2225 2228 ScrollWindowEx(hwnd, -dx, dy, 2229 NULL, &rc, (HRGN)NULL, NULL, SW_INVALIDATE); 2226 ScrollWindowEx(hwnd,-dx,dy,NULL,&rc,(HRGN)NULL,NULL,SW_INVALIDATE); 2230 2227 es->y_offset = nyoff; 2231 2228 es->x_offset += dx; … … 2242 2239 * 2243 2240 */ 2244 static LRESULT EDIT_EM_PosFromChar(HWND hwnd, EDITSTATE *es, INT index, BOOL after_wrap)2241 static LRESULT EDIT_EM_PosFromChar(HWND hwnd,HDC dc, EDITSTATE *es, INT index, BOOL after_wrap) 2245 2242 { 2246 2243 INT len = lstrlenA(es->text); … … 2249 2246 INT x; 2250 2247 INT y = 0; 2251 HDC dc = 0;2248 BOOL createdDC = FALSE; 2252 2249 HFONT old_font = 0; 2253 2250 SIZE size; … … 2259 2256 if (es->font) 2260 2257 old_font = SelectObject(dc, es->font); 2258 createdDC = TRUE; 2261 2259 } 2262 2260 if (es->style & ES_MULTILINE) { … … 2296 2294 x += es->format_rect.left; 2297 2295 y += es->format_rect.top; 2298 if (es->font) 2299 SelectObject(dc, old_font); 2300 ReleaseDC(hwnd, dc); 2296 if (createdDC) 2297 { 2298 if (es->font) 2299 SelectObject(dc, old_font); 2300 ReleaseDC(hwnd, dc); 2301 } 2301 2302 return MAKELONG((INT16)x, (INT16)y); 2302 2303 } … … 2424 2425 /* FIXME: really inefficient */ 2425 2426 if (es->style & ES_MULTILINE) 2426 EDIT_BuildLineDefs_ML(hwnd, 2427 EDIT_BuildLineDefs_ML(hwnd,es); 2427 2428 2428 2429 EDIT_EM_SetSel(hwnd, es, s, s, FALSE); … … 2498 2499 l = EDIT_EM_LineFromChar(hwnd, es, es->selection_end); 2499 2500 li = EDIT_EM_LineIndex(hwnd, es, l); 2500 x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, es->flags & EF_AFTER_WRAP));2501 x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)); 2501 2502 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; 2502 2503 if (l >= es->y_offset + vlc) … … 2519 2520 return; 2520 2521 2521 x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE));2522 x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE)); 2522 2523 format_width = es->format_rect.right - es->format_rect.left; 2523 2524 if (x < es->format_rect.left) … … 2526 2527 do { 2527 2528 es->x_offset--; 2528 x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE));2529 x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE)); 2529 2530 } while ((x < goal) && es->x_offset); 2530 2531 /* FIXME: use ScrollWindow() somehow to improve performance */ … … 2538 2539 do { 2539 2540 es->x_offset++; 2540 x = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, es->selection_end, FALSE));2541 x_last = SLOWORD(EDIT_EM_PosFromChar(hwnd, es, len, FALSE));2541 x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE)); 2542 x_last = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, len, FALSE)); 2542 2543 } while ((x > goal) && (x_last > es->format_rect.right)); 2543 2544 /* FIXME: use ScrollWindow() somehow to improve performance */ … … 2606 2607 es->flags &= ~EF_MODIFIED; 2607 2608 es->flags &= ~EF_UPDATE; 2608 EDIT_BuildLineDefs_ML(hwnd, 2609 EDIT_BuildLineDefs_ML(hwnd,es); 2609 2610 EDIT_Refresh(hwnd,es,FALSE); 2610 2611 EDIT_EM_ScrollCaret(hwnd, es); … … 2671 2672 EDIT_SetRectNP(hwnd, es, &r); 2672 2673 if (es->style & ES_MULTILINE) 2673 EDIT_BuildLineDefs_ML(hwnd, 2674 EDIT_BuildLineDefs_ML(hwnd,es); 2674 2675 2675 2676 EDIT_Refresh(hwnd,es,FALSE); … … 2840 2841 es->word_break_procA = wbp; 2841 2842 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { 2842 EDIT_BuildLineDefs_ML(hwnd, 2843 EDIT_BuildLineDefs_ML(hwnd,es); 2843 2844 EDIT_Refresh(hwnd,es,FALSE); 2844 2845 } … … 3739 3740 for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) 3740 3741 { 3741 EDIT_GetLineRect(hwnd, es, i, 0, -1, &rcLine);3742 EDIT_GetLineRect(hwnd,hdc, es, i, 0, -1, &rcLine); 3742 3743 if (IntersectRect(&rc, &rcRgn, &rcLine)) 3743 3744 EDIT_PaintLine(hwnd, es, hdc, i, rev); … … 3745 3746 } else 3746 3747 { 3747 EDIT_GetLineRect(hwnd, es, 0, 0, -1, &rcLine);3748 EDIT_GetLineRect(hwnd,hdc, es, 0, 0, -1, &rcLine); 3748 3749 if (IntersectRect(&rc, &rcRgn, &rcLine)) 3749 3750 EDIT_PaintLine(hwnd, es, hdc, 0, rev); … … 3890 3891 EDIT_SetRectNP(hwnd, es, &r); 3891 3892 if (es->style & ES_MULTILINE) 3892 EDIT_BuildLineDefs_ML(hwnd, 3893 EDIT_BuildLineDefs_ML(hwnd,es); 3893 3894 3894 3895 if (redraw)
Note:
See TracChangeset
for help on using the changeset viewer.