MCPcopy Create free account
hub / github.com/WheretIB/nullc / AreaCursorUpdate

Method AreaCursorUpdate

GUI/RichTextarea.cpp:1284–1337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1282// Reset is used so that cursor will always be visible after key or mouse events
1283int ibarState = 0;
1284VOID CALLBACK RichTextarea::AreaCursorUpdate(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
1285{
1286 if(!hwnd || (GetFocus() != hwnd && ibarState != 0))
1287 return;
1288
1289 TextareaData *data = GetData(hwnd);
1290
1291 (void)dwTime;
1292 (void)uMsg;
1293 // Ticks go more frequently than I-bar cursor switches its state
1294 HPEN currPen = ibarState % 16 < 8 ? areaPenBlack1px : areaPenWhite1px;
1295
1296 // Must be used so that painting could be done
1297 InvalidateRect(hwnd, NULL, false);
1298 HDC hdc = BeginPaint(hwnd, &areaPS);
1299
1300 // Find cursor position in characters
1301 int posInChars = 0;
1302 for(unsigned int i = 0; i < data->cursorCharX; i++)
1303 posInChars += GetCharShift(data->currLine->data[i].ch, posInChars);
1304 // Calculate cursor position in pixels
1305 int xPos = padLeft - data->shiftCharX * charWidth + posInChars * charWidth;
1306 int chWidth = data->cursorCharX == data->currLine->length ? charWidth : GetCharShift(data->currLine->data[data->cursorCharX].ch, posInChars) * charWidth;
1307
1308 // While selecting pen, we check if our window is active. Cursor shouldn't blink if focus is on some other window
1309 SelectPen(hdc, idEvent ? currPen : areaPenWhite1px);
1310
1311 MoveToEx(hdc, xPos, (data->cursorCharY - data->shiftCharY) * charHeight, NULL);
1312 LineTo(hdc, xPos, (data->cursorCharY - data->shiftCharY) * charHeight + charHeight);
1313
1314 if(insertionMode)
1315 {
1316 // Draw full box
1317 LineTo(hdc, xPos + chWidth, (data->cursorCharY - data->shiftCharY) * charHeight + charHeight);
1318 LineTo(hdc, xPos + chWidth, (data->cursorCharY - data->shiftCharY) * charHeight);
1319 LineTo(hdc, xPos, (data->cursorCharY - data->shiftCharY) * charHeight);
1320 }
1321 EndPaint(hwnd, &areaPS);
1322
1323 if(areaStatus)
1324 {
1325 char buf[256];
1326 sprintf(buf, "Ln %d", data->cursorCharY + 1);
1327 SendMessage(areaStatus, (WM_USER+1), 1, (LPARAM)buf);
1328 sprintf(buf, "Col %d", posInChars + 1);
1329 SendMessage(areaStatus, (WM_USER+1), 2, (LPARAM)buf);
1330 sprintf(buf, "Ch %d", data->cursorCharX + 1);
1331 SendMessage(areaStatus, (WM_USER+1), 3, (LPARAM)buf);
1332 sprintf(buf, "%s", insertionMode ? "OVR" : "INS");
1333 SendMessage(areaStatus, (WM_USER+1), 4, (LPARAM)buf);
1334 }
1335
1336 ibarState++;
1337}
1338
1339// Function for single char insertion at the cursor position
1340void TextareaData::InputChar(char ch)

Callers

nothing calls this directly

Calls 2

GetCharShiftFunction · 0.85
GetDataFunction · 0.70

Tested by

no test coverage detected