void WMSetFocusToWidget(WMWidget * widget) { W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget)); }
static void destroyView(W_View * view) { W_View *ptr; if (view->flags.alreadyDead) return; view->flags.alreadyDead = 1; /* delete the balloon text for the view, if there's any */ WMSetBalloonTextForView(NULL, view); if (view->nextFocusChain) view->nextFocusChain->prevFocusChain = view->prevFocusChain; if (view->prevFocusChain) view->prevFocusChain->nextFocusChain = view->nextFocusChain; /* Do not leave focus in a inexisting control */ if (W_FocusedViewOfToplevel(W_TopLevelOfView(view)) == view) W_SetFocusOfTopLevel(W_TopLevelOfView(view), NULL); if (view->flags.topLevel) { W_FocusInfo *info = view->screen->focusInfo; /* remove focus information associated to this toplevel */ if (info) { if (info->toplevel == view) { view->screen->focusInfo = info->next; wfree(info); } else { while (info->next) { if (info->next->toplevel == view) break; info = info->next; } if (info->next) { W_FocusInfo *next = info->next->next; wfree(info->next); info->next = next; } /* else the toplevel did not have any focused subview */ } } } /* destroy children recursively */ while (view->childrenList != NULL) { ptr = view->childrenList; ptr->flags.parentDying = 1; W_DestroyView(ptr); if (ptr == view->childrenList) { view->childrenList = ptr->nextSister; ptr->parent = NULL; } } W_CallDestroyHandlers(view); if (view->flags.realized) { XDeleteContext(view->screen->display, view->window, ViewContext); /* if parent is being destroyed, it will die naturaly */ if (!view->flags.parentDying || view->flags.topLevel) XDestroyWindow(view->screen->display, view->window); } /* remove self from parent's children list */ unparentView(view); /* the array has a wfree() destructor that will be called automatically */ WMFreeArray(view->eventHandlers); view->eventHandlers = NULL; WMRemoveNotificationObserver(view); W_FreeViewXdndPart(view); if (view->backColor) WMReleaseColor(view->backColor); wfree(view); }
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); */ }