| 1139 | } |
| 1140 | |
| 1141 | void TextareaData::OnPaint() |
| 1142 | { |
| 1143 | // Windows will tell, what part we have to update |
| 1144 | RECT updateRect; |
| 1145 | if(!GetUpdateRect(areaWnd, &updateRect, false)) |
| 1146 | return; |
| 1147 | |
| 1148 | AreaLine *curr = NULL; |
| 1149 | |
| 1150 | // Start drawing |
| 1151 | HDC hdc = BeginPaint(areaWnd, &RichTextarea::areaPS); |
| 1152 | FontStyle currFont = FONT_REGULAR; |
| 1153 | SelectFont(hdc, RichTextarea::areaFont[currFont]); |
| 1154 | |
| 1155 | // Find out the size of a single symbol |
| 1156 | RECT charRect = { 0, 0, 0, 0 }; |
| 1157 | DrawText(hdc, "W", 1, &charRect, DT_CALCRECT); |
| 1158 | RichTextarea::charWidth = charRect.right; |
| 1159 | RichTextarea::charHeight = charRect.bottom; |
| 1160 | |
| 1161 | // Find the length of the longest line in text (should move to someplace that is more appropriate) |
| 1162 | FindLongestLine(); |
| 1163 | |
| 1164 | // Reset horizontal scroll position, if longest line can fit to window |
| 1165 | if(longestLine < areaWidth / RichTextarea::charWidth - 1) |
| 1166 | shiftCharX = 0; |
| 1167 | if(int(lineCount) < areaHeight / RichTextarea::charHeight) |
| 1168 | shiftCharY = 0; |
| 1169 | UpdateScrollBar(); |
| 1170 | |
| 1171 | // Find the first line for current vertical scroll position |
| 1172 | AreaLine *startLine = firstLine; |
| 1173 | for(int i = 0; i < shiftCharY; i++) |
| 1174 | startLine = startLine->next; |
| 1175 | |
| 1176 | // Setup the box of the first symbol |
| 1177 | charRect.left = RichTextarea::padLeft - shiftCharX * RichTextarea::charWidth; |
| 1178 | charRect.right = charRect.left + RichTextarea::charWidth; |
| 1179 | |
| 1180 | // Find the selection range |
| 1181 | unsigned int startX, startY, endX, endY; |
| 1182 | SortSelPoints(startX, endX, startY, endY); |
| 1183 | |
| 1184 | HDC memDC = CreateCompatibleDC(hdc); |
| 1185 | |
| 1186 | curr = startLine; |
| 1187 | unsigned int currLine = shiftCharY; |
| 1188 | // While they are lines and they didn't go out of view |
| 1189 | while(curr && charRect.top < updateRect.bottom) |
| 1190 | { |
| 1191 | // If line box is inside update rect |
| 1192 | if(charRect.bottom > updateRect.top) |
| 1193 | { |
| 1194 | // Draw line symbols |
| 1195 | for(unsigned int i = 0, posInChars = 0; i < curr->length; i++) |
| 1196 | { |
| 1197 | int shift = GetCharShift(curr->data[i].ch, posInChars); |
| 1198 | if(charRect.right > -TAB_SIZE * RichTextarea::charWidth) |
no test coverage detected