static void blinkCursor(void *data) { TextField *tPtr = (TextField *) data; if (tPtr->flags.cursorOn) { tPtr->timerID = WMAddTimerHandler(CURSOR_BLINK_OFF_DELAY, blinkCursor, data); } else { tPtr->timerID = WMAddTimerHandler(CURSOR_BLINK_ON_DELAY, blinkCursor, data); } paintCursor(tPtr); tPtr->flags.cursorOn = !tPtr->flags.cursorOn; }
STATUS drawCursor(pSurface suf) { BOOL isEnabled = FALSE; cursorProp* prop = NULL; RETURN_IF(settingManager_getBool("cursor", &isEnabled)); if (isEnabled) { RETURN_IF(settingManager_getProperty("cursor", (void**)(&prop))); cursorTheme = prop->ThemeColor; shape = prop->shape; paintCursor(suf); } return OK; }
long MyText::onTextCursor(FXObject*o, FXSelector sel, void*p) { if (hasFocus()||(p==this)) { static FXint oldpos=0; FXint newpos=getCursorPos(); if (oldpos!=newpos) { ClearCursor(oldpos); oldpos=newpos; } FXDCWindow dc(this); paintCursor(dc); getApp()->addTimeout(this,ID_TEXT_CURSOR,ONE_SECOND/30); } else { getApp()->addTimeout(this,ID_TEXT_CURSOR,ONE_SECOND); } return 1; }
void FastWorldDrawer::Draw() { clearView(); configureCamera(); paintGround(); paintDecorations(); paintCorpses(); paintProjectiles(); paintMonsters(); paintHeroes(); paintEffects(); paintCursor(); }
void DisassemblyView::paintEvent(QPaintEvent * evt) { if (_needRepaint == true) { _cache = QPixmap(viewport()->size()); QPainter cachedPainter(&_cache); paintBackground(cachedPainter); paintSelection(cachedPainter); cachedPainter.setRenderHint(QPainter::TextAntialiasing); cachedPainter.setFont(font()); paintText(cachedPainter); _needRepaint = false; } QPainter p(viewport()); p.drawPixmap(0, 0, _cache); paintCursor(p); }
static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event) { char buffer[64]; KeySym ksym; char *textEvent = NULL; void *data = NULL; int count, refresh = 0; int control_pressed = 0; int cancelSelection = 1; Bool shifted, controled, modified; Bool relay = True; /*printf("(%d,%d) -> ", tPtr->selection.position, tPtr->selection.count); */ if (((XKeyEvent *) event)->state & WM_EMACSKEYMASK) control_pressed = 1; shifted = (event->xkey.state & ShiftMask ? True : False); controled = (event->xkey.state & ControlMask ? True : False); modified = shifted || controled; count = W_LookupString(tPtr->view, &event->xkey, buffer, 63, &ksym, NULL); //count = XLookupString(&event->xkey, buffer, 63, &ksym, NULL); buffer[count] = '\0'; switch (ksym) { case XK_Tab: #ifdef XK_ISO_Left_Tab case XK_ISO_Left_Tab: #endif if (!controled) { if (shifted) { if (tPtr->view->prevFocusChain) { W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view), tPtr->view->prevFocusChain); tPtr->flags.notIllegalMovement = 1; } data = (void *)WMBacktabTextMovement; } else { if (tPtr->view->nextFocusChain) { W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view), tPtr->view->nextFocusChain); tPtr->flags.notIllegalMovement = 1; } data = (void *)WMTabTextMovement; } textEvent = WMTextDidEndEditingNotification; cancelSelection = 0; relay = False; } break; case XK_Escape: if (!modified) { data = (void *)WMEscapeTextMovement; textEvent = WMTextDidEndEditingNotification; relay = False; } break; case XK_Return: if (!modified) { data = (void *)WMReturnTextMovement; textEvent = WMTextDidEndEditingNotification; relay = False; } break; case WM_EMACSKEY_LEFT: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_Left case XK_KP_Left: #endif case XK_Left: if (tPtr->cursorPosition > 0) { int i; paintCursor(tPtr); i = tPtr->cursorPosition; i += oneUTF8CharBackward(&tPtr->text[i], i); if (controled) { while (i > 0 && tPtr->text[i] != ' ') i--; while (i > 0 && tPtr->text[i] == ' ') i--; tPtr->cursorPosition = (i > 0) ? i + 1 : 0; } else tPtr->cursorPosition = i; if (tPtr->cursorPosition < tPtr->viewPosition) { tPtr->viewPosition = tPtr->cursorPosition; refresh = 1; } else paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; break; case WM_EMACSKEY_RIGHT: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_Right case XK_KP_Right: #endif case XK_Right: if (tPtr->cursorPosition < tPtr->textLen) { int i; paintCursor(tPtr); i = tPtr->cursorPosition; if (controled) { while (tPtr->text[i] && tPtr->text[i] != ' ') i++; while (tPtr->text[i] == ' ') i++; } else { i += oneUTF8CharForward(&tPtr->text[i], tPtr->textLen - i); } tPtr->cursorPosition = i; refresh = incrToFit2(tPtr); if (!refresh) paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; break; case WM_EMACSKEY_HOME: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_Home case XK_KP_Home: #endif case XK_Home: if (!controled) { if (tPtr->cursorPosition > 0) { paintCursor(tPtr); tPtr->cursorPosition = 0; if (tPtr->viewPosition > 0) { tPtr->viewPosition = 0; refresh = 1; } else paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; } break; case WM_EMACSKEY_END: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_End case XK_KP_End: #endif case XK_End: if (!controled) { if (tPtr->cursorPosition < tPtr->textLen) { paintCursor(tPtr); tPtr->cursorPosition = tPtr->textLen; tPtr->viewPosition = 0; refresh = incrToFit(tPtr); if (!refresh) paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; } break; case WM_EMACSKEY_BS: if (!control_pressed) goto normal_key; else modified = False; case XK_BackSpace: if (!modified) { if (tPtr->selection.count) { WMDeleteTextFieldRange(tPtr, tPtr->selection); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } else if (tPtr->cursorPosition > 0) { int i = oneUTF8CharBackward(&tPtr->text[tPtr->cursorPosition], tPtr->cursorPosition); WMRange range; range.position = tPtr->cursorPosition + i; range.count = -i; WMDeleteTextFieldRange(tPtr, range); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } relay = False; } break; case WM_EMACSKEY_DEL: if (!control_pressed) goto normal_key; else modified = False; #ifdef XK_KP_Delete case XK_KP_Delete: #endif case XK_Delete: if (!modified) { if (tPtr->selection.count) { WMDeleteTextFieldRange(tPtr, tPtr->selection); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } else if (tPtr->cursorPosition < tPtr->textLen) { WMRange range; range.position = tPtr->cursorPosition; range.count = oneUTF8CharForward(&tPtr->text[tPtr->cursorPosition], tPtr->textLen - tPtr->cursorPosition); WMDeleteTextFieldRange(tPtr, range); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } relay = False; } break; normal_key: default: if (!controled) { if (count > 0 && !iscntrl(buffer[0])) { if (tPtr->selection.count) WMDeleteTextFieldRange(tPtr, tPtr->selection); WMInsertTextFieldText(tPtr, buffer, tPtr->cursorPosition); data = (void *)WMInsertTextEvent; textEvent = WMTextDidChangeNotification; relay = False; } } break; } if (relay) { WMRelayToNextResponder(W_VIEW(tPtr), event); return; } /* Do not allow text selection in secure text fields */ if (cancelSelection || tPtr->flags.secure) { lostSelection(tPtr->view, XA_PRIMARY, NULL); if (tPtr->selection.count) { tPtr->selection.count = 0; refresh = 1; } tPtr->selection.position = tPtr->cursorPosition; } else { if (tPtr->selection.count != tPtr->cursorPosition - tPtr->selection.position) { tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position; refresh = 1; } } /*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */ if (textEvent) { WMNotification *notif = WMCreateNotification(textEvent, tPtr, data); if (tPtr->delegate) { if (textEvent == WMTextDidBeginEditingNotification && tPtr->delegate->didBeginEditing) (*tPtr->delegate->didBeginEditing) (tPtr->delegate, notif); else if (textEvent == WMTextDidEndEditingNotification && tPtr->delegate->didEndEditing) (*tPtr->delegate->didEndEditing) (tPtr->delegate, notif); else if (textEvent == WMTextDidChangeNotification && tPtr->delegate->didChange) (*tPtr->delegate->didChange) (tPtr->delegate, notif); } WMPostNotification(notif); WMReleaseNotification(notif); } if (refresh) paintTextField(tPtr); /*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */ }
static void paintTextField(TextField * tPtr) { W_Screen *screen = tPtr->view->screen; W_View *view = tPtr->view; W_View viewbuffer; int tx, ty, tw; int rx; int bd; int totalWidth; char *text; Pixmap drawbuffer; WMColor *color; if (!view->flags.realized || !view->flags.mapped) return; if (!tPtr->flags.bordered) { bd = 0; } else { bd = 2; } if (tPtr->flags.secure) { text = makeHiddenString(strlen(tPtr->text)); } else { text = tPtr->text; } totalWidth = tPtr->view->size.width - 2 * bd; drawbuffer = XCreatePixmap(screen->display, view->window, view->size.width, view->size.height, screen->depth); XFillRectangle(screen->display, drawbuffer, WMColorGC(screen->white), 0, 0, view->size.width, view->size.height); /* this is quite dirty */ viewbuffer.screen = view->screen; viewbuffer.size = view->size; viewbuffer.window = drawbuffer; if (tPtr->textLen > 0) { tw = WMWidthOfString(tPtr->font, &(text[tPtr->viewPosition]), tPtr->textLen - tPtr->viewPosition); ty = tPtr->offsetWidth; switch (tPtr->flags.alignment) { case WALeft: tx = tPtr->offsetWidth + 1; if (tw < tPtr->usableWidth) XFillRectangle(screen->display, drawbuffer, WMColorGC(screen->white), bd + tw, bd, totalWidth - tw, view->size.height - 2 * bd); break; case WACenter: tx = tPtr->offsetWidth + (tPtr->usableWidth - tw) / 2; if (tw < tPtr->usableWidth) XClearArea(screen->display, view->window, bd, bd, totalWidth, view->size.height - 2 * bd, False); break; default: case WARight: tx = tPtr->offsetWidth + tPtr->usableWidth - tw - 1; if (tw < tPtr->usableWidth) XClearArea(screen->display, view->window, bd, bd, totalWidth - tw, view->size.height - 2 * bd, False); break; } color = tPtr->flags.enabled ? screen->black : screen->darkGray; WMDrawImageString(screen, drawbuffer, color, screen->white, tPtr->font, tx, ty, &(text[tPtr->viewPosition]), tPtr->textLen - tPtr->viewPosition); if (tPtr->selection.count) { int count, count2; count = tPtr->selection.count < 0 ? tPtr->selection.position + tPtr->selection.count : tPtr->selection.position; count2 = abs(tPtr->selection.count); if (count < tPtr->viewPosition) { count2 = abs(count2 - abs(tPtr->viewPosition - count)); count = tPtr->viewPosition; } rx = tPtr->offsetWidth + 1 + WMWidthOfString(tPtr->font, text, count) - WMWidthOfString(tPtr->font, text, tPtr->viewPosition); WMDrawImageString(screen, drawbuffer, color, screen->gray, tPtr->font, rx, ty, &(text[count]), count2); } } else { XFillRectangle(screen->display, drawbuffer, WMColorGC(screen->white), bd, bd, totalWidth, view->size.height - 2 * bd); } /* draw relief */ if (tPtr->flags.bordered) { drawRelief(&viewbuffer, tPtr->flags.beveled); } if (tPtr->flags.secure) wfree(text); XCopyArea(screen->display, drawbuffer, view->window, screen->copyGC, 0, 0, view->size.width, view->size.height, 0, 0); XFreePixmap(screen->display, drawbuffer); /* draw cursor */ if (tPtr->flags.focused && tPtr->flags.enabled && tPtr->flags.cursorOn) { paintCursor(tPtr); } }
static void handleTextFieldActionEvents(XEvent * event, void *data) { TextField *tPtr = (TextField *) data; static Time lastButtonReleasedEvent = 0; static Time lastButtonReleasedEvent2 = 0; Display *dpy = event->xany.display; CHECK_CLASS(data, WC_TextField); switch (event->type) { case KeyPress: if (tPtr->flags.waitingSelection) { return; } if (tPtr->flags.enabled && tPtr->flags.focused) { handleTextFieldKeyPress(tPtr, event); XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->invisibleCursor); tPtr->flags.pointerGrabbed = 1; } break; case MotionNotify: if (tPtr->flags.pointerGrabbed) { tPtr->flags.pointerGrabbed = 0; XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->textCursor); } if (tPtr->flags.waitingSelection) { return; } if (tPtr->flags.enabled && (event->xmotion.state & Button1Mask)) { if (tPtr->viewPosition < tPtr->textLen && event->xmotion.x > tPtr->usableWidth) { if (WMWidthOfString(tPtr->font, &(tPtr->text[tPtr->viewPosition]), tPtr->cursorPosition - tPtr->viewPosition) > tPtr->usableWidth) { tPtr->viewPosition += oneUTF8CharForward(&tPtr->text[tPtr->viewPosition], tPtr->textLen - tPtr->viewPosition); } } else if (tPtr->viewPosition > 0 && event->xmotion.x < 0) { paintCursor(tPtr); tPtr->viewPosition += oneUTF8CharBackward(&tPtr->text[tPtr->viewPosition], tPtr->viewPosition); } tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x); /* Do not allow text selection in secure textfields */ if (tPtr->flags.secure) { tPtr->selection.position = tPtr->cursorPosition; } tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position; paintCursor(tPtr); paintTextField(tPtr); } break; case ButtonPress: if (tPtr->flags.pointerGrabbed) { tPtr->flags.pointerGrabbed = 0; XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->textCursor); break; } if (tPtr->flags.waitingSelection) { break; } switch (tPtr->flags.alignment) { int textWidth; case WARight: textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen); if (tPtr->flags.enabled && !tPtr->flags.focused) { WMSetFocusToWidget(tPtr); } if (tPtr->flags.focused) { tPtr->selection.position = tPtr->cursorPosition; tPtr->selection.count = 0; } if (textWidth < tPtr->usableWidth) { tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x - tPtr->usableWidth + textWidth); } else tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x); paintTextField(tPtr); break; case WALeft: if (tPtr->flags.enabled && !tPtr->flags.focused) { WMSetFocusToWidget(tPtr); } if (tPtr->flags.focused && event->xbutton.button == Button1) { tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x); tPtr->selection.position = tPtr->cursorPosition; tPtr->selection.count = 0; paintTextField(tPtr); } if (event->xbutton.button == Button2 && tPtr->flags.enabled) { char *text; int n; if (!WMRequestSelection(tPtr->view, XA_PRIMARY, XA_STRING, event->xbutton.time, pasteText, NULL)) { text = XFetchBuffer(tPtr->view->screen->display, &n, 0); if (text) { text[n] = 0; WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition); XFree(text); NOTIFY(tPtr, didChange, WMTextDidChangeNotification, (void *)WMInsertTextEvent); } } else { tPtr->flags.waitingSelection = 1; } } break; default: break; } break; case ButtonRelease: if (tPtr->flags.pointerGrabbed) { tPtr->flags.pointerGrabbed = 0; XDefineCursor(dpy, W_VIEW(tPtr)->window, W_VIEW(tPtr)->screen->textCursor); } if (tPtr->flags.waitingSelection) { break; } if (!tPtr->flags.secure && tPtr->selection.count != 0) { int start, count; XRotateBuffers(dpy, 1); count = abs(tPtr->selection.count); if (tPtr->selection.count < 0) start = tPtr->selection.position - count; else start = tPtr->selection.position; XStoreBuffer(dpy, &tPtr->text[start], count, 0); } if (!tPtr->flags.secure && event->xbutton.time - lastButtonReleasedEvent <= WINGsConfiguration.doubleClickDelay) { if (event->xbutton.time - lastButtonReleasedEvent2 <= 2 * WINGsConfiguration.doubleClickDelay) { tPtr->selection.position = 0; tPtr->selection.count = tPtr->textLen; } else { int pos, cnt; char *txt; pos = tPtr->selection.position; cnt = tPtr->selection.count; txt = tPtr->text; while (pos >= 0) { if (txt[pos] == ' ' || txt[pos] == '\t') break; pos--; } pos++; while (pos + cnt < tPtr->textLen) { if (txt[pos + cnt] == ' ' || txt[pos + cnt] == '\t') break; cnt++; } tPtr->selection.position = pos; tPtr->selection.count = cnt; } paintTextField(tPtr); if (!tPtr->flags.ownsSelection) { tPtr->flags.ownsSelection = WMCreateSelectionHandler(tPtr->view, XA_PRIMARY, event->xbutton.time, &selectionHandler, NULL); } } else if (!tPtr->flags.secure && tPtr->selection.count != 0 && !tPtr->flags.ownsSelection) { tPtr->flags.ownsSelection = WMCreateSelectionHandler(tPtr->view, XA_PRIMARY, event->xbutton.time, &selectionHandler, NULL); } lastButtonReleasedEvent2 = lastButtonReleasedEvent; lastButtonReleasedEvent = event->xbutton.time; break; } }