void FocusHandler::requestFocus(const Widget *const widget) { if (!widget || widget == mFocusedWidget) return; int toBeFocusedIndex = -1; for (unsigned int i = 0, fsz = CAST_U32( mWidgets.size()); i < fsz; ++i) { if (mWidgets[i] == widget) { toBeFocusedIndex = i; break; } } if (toBeFocusedIndex < 0) return; Widget *const oldFocused = mFocusedWidget; if (oldFocused != widget) { mFocusedWidget = mWidgets.at(toBeFocusedIndex); if (oldFocused) { Event focusEvent(oldFocused); distributeFocusLostEvent(focusEvent); } Event focusEvent(mWidgets.at(toBeFocusedIndex)); distributeFocusGainedEvent(focusEvent); } }
void FocusHandler::focusPrevious() { if (mWidgets.size() == 0) { mFocusedWidget = NULL; return; } int i; int focusedWidget = -1; for (i = 0; i < (int)mWidgets.size(); ++i) { if (mWidgets[i] == mFocusedWidget) { focusedWidget = i; } } int focused = focusedWidget; // i is a counter that ensures that the following loop // won't get stuck in an infinite loop i = (int)mWidgets.size(); do { --focusedWidget; if (i==0) { focusedWidget = -1; break; } --i; if (focusedWidget <= 0) { focusedWidget = mWidgets.size() - 1; } if (focusedWidget == focused) { return; } } while (!mWidgets.at(focusedWidget)->isFocusable()); if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } }
void FocusHandler::focusPrevious() { if (mWidgets.empty()) { mFocusedWidget = nullptr; return; } int i; int focusedWidget = -1; const int sz = CAST_S32(mWidgets.size()); for (i = 0; i < sz; ++ i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; } const int focused = focusedWidget; // i is a counter that ensures that the following loop // won't get stuck in an infinite loop i = sz; do { -- focusedWidget; if (i == 0) { focusedWidget = -1; break; } -- i; if (focusedWidget <= 0) focusedWidget = sz - 1; if (focusedWidget == focused) return; } while (!mWidgets.at(focusedWidget)->isFocusable()); if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } }
void FocusHandler::focusNext() { int i; int focusedWidget = -1; const int sz = static_cast<int>(mWidgets.size()); for (i = 0; i < sz; ++i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; } const int focused = focusedWidget; // i is a counter that ensures that the following loop // won't get stuck in an infinite loop i = sz; do { ++ focusedWidget; if (i == 0) { focusedWidget = -1; break; } -- i; if (focusedWidget >= sz) focusedWidget = 0; if (focusedWidget == focused) return; } while (!mWidgets.at(focusedWidget)->isFocusable()); if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } }
bool CodeEditorAndSearchPaneWidget::eventFilter(QObject *obj, QEvent *event) { if(event->type()==QEvent::FocusIn){ emit focusEvent(this, true); } return QWidget::eventFilter(obj, event); }
void FocusHandler::focusNone() { if (mFocusedWidget != NULL) { Widget* focused = mFocusedWidget; mFocusedWidget = NULL; Event focusEvent(focused); distributeFocusLostEvent(focusEvent); } }
void FocusHandler::focusNone() { if (mFocusedWidget) { Widget *const focused = mFocusedWidget; mFocusedWidget = nullptr; Event focusEvent(focused); distributeFocusLostEvent(focusEvent); } }
void FocusHandler::FocusNone() { if (mFocusedWidget != NULL) { WidgetPtr focused = mFocusedWidget; mFocusedWidget.reset(); Event focusEvent(focused); distributeFocusLostEvent(focusEvent); } }
void QDeclarativeTextEdit::setCursorVisible(bool on) { Q_D(QDeclarativeTextEdit); if (d->cursorVisible == on) return; d->cursorVisible = on; QFocusEvent focusEvent(on ? QEvent::FocusIn : QEvent::FocusOut); if (!on && !d->persistentSelection) d->control->setCursorIsFocusIndicator(true); d->control->processEvent(&focusEvent, QPointF(0, 0)); emit cursorVisibleChanged(d->cursorVisible); }
void FocusHandler::requestFocus(Widget* widget) { if (widget == NULL || widget == mFocusedWidget) { return; } unsigned int i = 0; int toBeFocusedIndex = -1; for (i = 0; i < mWidgets.size(); ++i) { if (mWidgets[i] == widget) { toBeFocusedIndex = i; break; } } if (toBeFocusedIndex < 0) { throw FCN_EXCEPTION("Trying to focus a none existing widget."); } Widget *oldFocused = mFocusedWidget; if (oldFocused != widget) { mFocusedWidget = mWidgets.at(toBeFocusedIndex); if (oldFocused != NULL) { Event focusEvent(oldFocused); distributeFocusLostEvent(focusEvent); } Event focusEvent(mWidgets.at(toBeFocusedIndex)); distributeFocusGainedEvent(focusEvent); } }
WSettings::WSettings() { ui.setupUi(this); m_networkManager = new QNetworkAccessManager(); connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(searchFinished(QNetworkReply*))); QFocusEvent focusEvent(QEvent::FocusOut); eventFilter(ui.searchEdit, &focusEvent); ui.searchEdit->installEventFilter(this); lookForWidgetState(ui.intervalBox); lookForWidgetState(ui.showStatusBox); lookForWidgetState(ui.themeNameBox); }
void XDebugStopCmdHandler::Process(const wxXmlNode* response) { CL_DEBUG("CodeLite: Stop command completed."); wxString status = response->GetAttribute("status"); if ( status == "stopping" ) { CL_DEBUG("CodeLite: xdebug entered status 'stopping'"); // Notify about control XDebugEvent focusEvent(wxEVT_XDEBUG_STOPPED); EventNotifier::Get()->AddPendingEvent( focusEvent ); } else if ( status == "stopped" ) { CL_DEBUG("CodeLite: xdebug entered status 'stopped'"); m_mgr->SendStopCommand(); } else { // default m_mgr->CloseDebugSession(); } }
void FocusHandler::tabPrevious() { if (mFocusedWidget) { if (!mFocusedWidget->isTabOutEnabled()) return; } if (mWidgets.empty()) { mFocusedWidget = nullptr; return; } int i; int focusedWidget = -1; const int sz = CAST_S32(mWidgets.size()); for (i = 0; i < sz; ++ i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; } const int focused = focusedWidget; bool done = false; // i is a counter that ensures that the following loop // won't get stuck in an infinite loop i = sz; do { -- focusedWidget; if (i == 0) { focusedWidget = -1; break; } -- i; if (focusedWidget <= 0) focusedWidget = sz - 1; if (focusedWidget == focused) return; const Widget *const widget = mWidgets.at(focusedWidget); if (widget->isFocusable() && widget->isTabInEnabled() && (!mModalFocusedWidget || widget->isModalFocused())) { done = true; } } while (!done); if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } checkForWindow(); }
void tst_QQuickAccessible::checkableTest() { QScopedPointer<QQuickView> window(new QQuickView()); window->setSource(testFileUrl("checkbuttons.qml")); window->show(); QQuickItem *contentItem = window->contentItem(); QVERIFY(contentItem); QQuickItem *rootItem = contentItem->childItems().first(); QVERIFY(rootItem); // the window becomes active QAccessible::State activatedChange; activatedChange.active = true; QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(window.data()); QVERIFY(iface); QAccessibleInterface *root = iface->child(0); QAccessibleInterface *button1 = root->child(0); QCOMPARE(button1->role(), QAccessible::Button); QVERIFY(!(button1->state().checked)); QVERIFY(!(button1->state().checkable)); QVERIFY(button1->state().focusable); QVERIFY(!button1->state().focused); QTestAccessibility::clearEvents(); // set properties QQuickItem *button1item = qobject_cast<QQuickItem*>(rootItem->childItems().at(0)); QVERIFY(button1item); QCOMPARE(button1item->objectName(), QLatin1String("button1")); button1item->forceActiveFocus(); QVERIFY(button1->state().focusable); QVERIFY(button1->state().focused); QAccessibleEvent focusEvent(button1item, QAccessible::Focus); QVERIFY_EVENT(&focusEvent); QAccessibleInterface *button2 = root->child(1); QVERIFY(!(button2->state().checked)); QVERIFY(button2->state().checkable); QQuickItem *button2item = qobject_cast<QQuickItem*>(rootItem->childItems().at(1)); QVERIFY(button2item); QCOMPARE(button2item->objectName(), QLatin1String("button2")); QAccessibleInterface *button3 = root->child(2); QVERIFY(button3->state().checked); QVERIFY(button3->state().checkable); QAccessibleInterface *checkBox1 = root->child(3); QCOMPARE(checkBox1->role(), QAccessible::CheckBox); QVERIFY(checkBox1->state().checked); QVERIFY(checkBox1->state().checkable); QQuickItem *checkbox1item = qobject_cast<QQuickItem*>(rootItem->childItems().at(3)); QVERIFY(checkbox1item); QCOMPARE(checkbox1item->objectName(), QLatin1String("checkbox1")); checkbox1item->setProperty("checked", false); QVERIFY(!checkBox1->state().checked); QAccessible::State checkState; checkState.checked = true; QAccessibleStateChangeEvent checkChanged(checkbox1item, checkState); QVERIFY_EVENT(&checkChanged); checkbox1item->setProperty("checked", true); QVERIFY(checkBox1->state().checked); QVERIFY_EVENT(&checkChanged); QAccessibleInterface *checkBox2 = root->child(4); QVERIFY(!(checkBox2->state().checked)); QVERIFY(checkBox2->state().checkable); QTestAccessibility::clearEvents(); }
bool wxApp::ProcessXEvent(WXEvent* _event) { XEvent* event = (XEvent*) _event; wxWindow* win = NULL; Window window = XEventGetWindow(event); #if 0 Window actualWindow = window; #endif // Find the first wxWindow that corresponds to this event window // Because we're receiving events after a window // has been destroyed, assume a 1:1 match between // Window and wxWindow, so if it's not in the table, // it must have been destroyed. win = wxGetWindowFromTable(window); if (!win) { #if wxUSE_TWO_WINDOWS win = wxGetClientWindowFromTable(window); if (!win) #endif return false; } switch (event->type) { case Expose: { #if wxUSE_TWO_WINDOWS && !wxUSE_NANOX if (event->xexpose.window != (Window)win->GetClientAreaWindow()) { XEvent tmp_event; wxExposeInfo info; info.window = event->xexpose.window; info.found_non_matching = false; while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, wxX11ExposePredicate, (XPointer) &info )) { // Don't worry about optimizing redrawing the border etc. } win->NeedUpdateNcAreaInIdle(); } else #endif { win->GetUpdateRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event), XExposeEventGetWidth(event), XExposeEventGetHeight(event)); win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event), XExposeEventGetWidth(event), XExposeEventGetHeight(event)); #if !wxUSE_NANOX XEvent tmp_event; wxExposeInfo info; info.window = event->xexpose.window; info.found_non_matching = false; while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, wxX11ExposePredicate, (XPointer) &info )) { win->GetUpdateRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y, tmp_event.xexpose.width, tmp_event.xexpose.height ); win->GetClearRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y, tmp_event.xexpose.width, tmp_event.xexpose.height ); } #endif // This simplifies the expose and clear areas to simple // rectangles. win->GetUpdateRegion() = win->GetUpdateRegion().GetBox(); win->GetClearRegion() = win->GetClearRegion().GetBox(); // If we only have one X11 window, always indicate // that borders might have to be redrawn. if (win->X11GetMainWindow() == win->GetClientAreaWindow()) win->NeedUpdateNcAreaInIdle(); // Only erase background, paint in idle time. win->SendEraseEvents(); // EXPERIMENT //win->Update(); } return true; } #if !wxUSE_NANOX case GraphicsExpose: { wxLogTrace( wxT("expose"), wxT("GraphicsExpose from %s"), win->GetName().c_str()); win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y, event->xgraphicsexpose.width, event->xgraphicsexpose.height); win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y, event->xgraphicsexpose.width, event->xgraphicsexpose.height); if (event->xgraphicsexpose.count == 0) { // Only erase background, paint in idle time. win->SendEraseEvents(); // win->Update(); } return true; } #endif case KeyPress: { if (!win->IsEnabled()) return false; wxKeyEvent keyEvent(wxEVT_KEY_DOWN); wxTranslateKeyEvent(keyEvent, win, window, event); // wxLogDebug( "OnKey from %s", win->GetName().c_str() ); // We didn't process wxEVT_KEY_DOWN, so send wxEVT_CHAR if (win->HandleWindowEvent( keyEvent )) return true; keyEvent.SetEventType(wxEVT_CHAR); // Do the translation again, retaining the ASCII // code. if (wxTranslateKeyEvent(keyEvent, win, window, event, true) && win->HandleWindowEvent( keyEvent )) return true; if ( (keyEvent.m_keyCode == WXK_TAB) && win->GetParent() && (win->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) { wxNavigationKeyEvent new_event; new_event.SetEventObject( win->GetParent() ); /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ new_event.SetDirection( (keyEvent.m_keyCode == WXK_TAB) ); /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ new_event.SetWindowChange( keyEvent.ControlDown() ); new_event.SetCurrentFocus( win ); return win->GetParent()->HandleWindowEvent( new_event ); } return false; } case KeyRelease: { if (!win->IsEnabled()) return false; wxKeyEvent keyEvent(wxEVT_KEY_UP); wxTranslateKeyEvent(keyEvent, win, window, event); return win->HandleWindowEvent( keyEvent ); } case ConfigureNotify: { #if wxUSE_NANOX if (event->update.utype == GR_UPDATE_SIZE) #endif { wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow); if ( tlw ) { tlw->SetConfigureGeometry( XConfigureEventGetX(event), XConfigureEventGetY(event), XConfigureEventGetWidth(event), XConfigureEventGetHeight(event) ); } if ( tlw && tlw->IsShown() ) { tlw->SetNeedResizeInIdle(); } else { wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() ); sizeEvent.SetEventObject( win ); return win->HandleWindowEvent( sizeEvent ); } } return false; } #if !wxUSE_NANOX case PropertyNotify: return HandlePropertyChange(_event); case ClientMessage: { if (!win->IsEnabled()) return false; Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True); Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True); if (event->xclient.message_type == wm_protocols) { if ((Atom) (event->xclient.data.l[0]) == wm_delete_window) { win->Close(false); return true; } } return false; } #if 0 case DestroyNotify: { printf( "destroy from %s\n", win->GetName().c_str() ); break; } case CreateNotify: { printf( "create from %s\n", win->GetName().c_str() ); break; } case MapRequest: { printf( "map request from %s\n", win->GetName().c_str() ); break; } case ResizeRequest: { printf( "resize request from %s\n", win->GetName().c_str() ); Display *disp = (Display*) wxGetDisplay(); XEvent report; // to avoid flicker report = * event; while( XCheckTypedWindowEvent (disp, actualWindow, ResizeRequest, &report)); wxSize sz = win->GetSize(); wxSizeEvent sizeEvent(sz, win->GetId()); sizeEvent.SetEventObject(win); return win->HandleWindowEvent( sizeEvent ); } #endif #endif #if wxUSE_NANOX case GR_EVENT_TYPE_CLOSE_REQ: { if (win) { win->Close(false); return true; } return false; break; } #endif case EnterNotify: case LeaveNotify: case ButtonPress: case ButtonRelease: case MotionNotify: { if (!win->IsEnabled()) return false; // Here we check if the top level window is // disabled, which is one aspect of modality. wxWindow *tlw = win; while (tlw && !tlw->IsTopLevel()) tlw = tlw->GetParent(); if (tlw && !tlw->IsEnabled()) return false; if (event->type == ButtonPress) { if ((win != wxWindow::FindFocus()) && win->CanAcceptFocus()) { // This might actually be done in wxWindow::SetFocus() // and not here. TODO. g_prevFocus = wxWindow::FindFocus(); g_nextFocus = win; wxLogTrace( wxT("focus"), wxT("About to call SetFocus on %s of type %s due to button press"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() ); // Record the fact that this window is // getting the focus, because we'll need to // check if its parent is getting a bogus // focus and duly ignore it. // TODO: may need to have this code in SetFocus, too. extern wxWindow* g_GettingFocus; g_GettingFocus = win; win->SetFocus(); } } #if !wxUSE_NANOX if (event->type == LeaveNotify || event->type == EnterNotify) { // Throw out NotifyGrab and NotifyUngrab if (event->xcrossing.mode != NotifyNormal) return false; } #endif wxMouseEvent wxevent; wxTranslateMouseEvent(wxevent, win, window, event); return win->HandleWindowEvent( wxevent ); } case FocusIn: #if !wxUSE_NANOX if ((event->xfocus.detail != NotifyPointer) && (event->xfocus.mode == NotifyNormal)) #endif { wxLogTrace( wxT("focus"), wxT("FocusIn from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() ); extern wxWindow* g_GettingFocus; if (g_GettingFocus && g_GettingFocus->GetParent() == win) { // Ignore this, this can be a spurious FocusIn // caused by a child having its focus set. g_GettingFocus = NULL; wxLogTrace( wxT("focus"), wxT("FocusIn from %s of type %s being deliberately ignored"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() ); return true; } else { wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId()); focusEvent.SetEventObject(win); focusEvent.SetWindow( g_prevFocus ); g_prevFocus = NULL; return win->HandleWindowEvent(focusEvent); } } return false; case FocusOut: #if !wxUSE_NANOX if ((event->xfocus.detail != NotifyPointer) && (event->xfocus.mode == NotifyNormal)) #endif { wxLogTrace( wxT("focus"), wxT("FocusOut from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() ); wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId()); focusEvent.SetEventObject(win); focusEvent.SetWindow( g_nextFocus ); g_nextFocus = NULL; return win->HandleWindowEvent(focusEvent); } return false; } return false; }
void WindowEventHandler::handleEvent(WindowEvent & event) { if (!event.window()) return; switch (event.type()) { case WindowEvent::Resize: resizeEvent(static_cast<ResizeEvent&>(event)); break; case WindowEvent::FrameBufferResize: framebufferResizeEvent(static_cast<ResizeEvent&>(event)); break; case WindowEvent::Move: moveEvent(static_cast<MoveEvent&>(event)); break; case WindowEvent::Paint: paintEvent(static_cast<PaintEvent&>(event)); break; case WindowEvent::KeyPress: keyPressEvent(static_cast<KeyEvent&>(event)); break; case WindowEvent::KeyRelease: keyReleaseEvent(static_cast<KeyEvent&>(event)); break; case WindowEvent::MousePress: mousePressEvent(static_cast<MouseEvent&>(event)); break; case WindowEvent::MouseRelease: mouseReleaseEvent(static_cast<MouseEvent&>(event)); break; case WindowEvent::MouseMove: mouseMoveEvent(static_cast<MouseEvent&>(event)); break; case WindowEvent::MouseEnter: break; case WindowEvent::MouseLeave: break; case WindowEvent::Scroll: scrollEvent(static_cast<ScrollEvent&>(event)); break; case WindowEvent::Focus: focusEvent(static_cast<FocusEvent&>(event)); break; case WindowEvent::Iconify: iconifyEvent(static_cast<IconifyEvent&>(event)); break; case WindowEvent::Timer: timerEvent(static_cast<TimerEvent&>(event)); break; default: break; } }
void FocusHandler::tabPrevious() { if (mFocusedWidget != NULL) { if (!mFocusedWidget->isTabOutEnabled()) { return; } } if (mWidgets.size() == 0) { mFocusedWidget = NULL; return; } int i; int focusedWidget = -1; for (i = 0; i < (int)mWidgets.size(); ++i) { if (mWidgets[i] == mFocusedWidget) { focusedWidget = i; } } int focused = focusedWidget; bool done = false; // i is a counter that ensures that the following loop // won't get stuck in an infinite loop i = (int)mWidgets.size(); do { --focusedWidget; if (i==0) { focusedWidget = -1; break; } --i; if (focusedWidget <= 0) { focusedWidget = mWidgets.size() - 1; } if (focusedWidget == focused) { return; } if (mWidgets.at(focusedWidget)->isFocusable() && mWidgets.at(focusedWidget)->isTabInEnabled() && (mModalFocusedWidget == NULL || mWidgets.at(focusedWidget)->isModalFocused())) { done = true; } } while (!done); if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } }
bool Console::keyboardEvent(int key, int /* scancode */, int action, int modifiers) { if (focused()) { if (action == GLFW_PRESS || action == GLFW_REPEAT) { if (key == GLFW_KEY_LEFT) { if (modifiers == GLFW_MOD_SHIFT) mCaret.startSelection(); else mCaret.resetSelection(); mCaret.moveLeft(); } else if (key == GLFW_KEY_RIGHT) { if (modifiers == GLFW_MOD_SHIFT) mCaret.startSelection(); else mCaret.resetSelection(); mCaret.moveRight(); } else if (key == GLFW_KEY_UP) { if (modifiers == GLFW_MOD_SHIFT) mCaret.startSelection(); else mCaret.resetSelection(); mCaret.moveUp(); } else if (key == GLFW_KEY_DOWN) { if (modifiers == GLFW_MOD_SHIFT) mCaret.startSelection(); else mCaret.resetSelection(); mCaret.moveDown(); // } else if (key == GLFW_KEY_HOME) { // if (modifiers == GLFW_MOD_SHIFT) { // if (mSelectionPos == -1) // mSelectionPos = mCursorPos; // } else { // mSelectionPos = -1; // } // // mCursorPos = 0; // } else if (key == GLFW_KEY_END) { // if (modifiers == GLFW_MOD_SHIFT) { // if (mSelectionPos == -1) // mSelectionPos = mCursorPos; // } else { // mSelectionPos = -1; // } // // mCursorPos = (int) mValueTemp.size(); // } else if (key == GLFW_KEY_BACKSPACE) { // if (!deleteSelection()) { // if (mCursorPos > 0) { // mValueTemp.erase(mValueTemp.begin() + mCursorPos - 1); // mCursorPos--; // } // } // } else if (key == GLFW_KEY_DELETE) { // if (!deleteSelection()) { // if (mCursorPos < (int) mValueTemp.length()) // mValueTemp.erase(mValueTemp.begin() + mCursorPos); // } } else if (key == GLFW_KEY_ENTER) { if (!mCommitted) focusEvent(false); // } else if (key == GLFW_KEY_A && modifiers == SYSTEM_COMMAND_MOD) { // mCursorPos = (int) mValueTemp.length(); // mSelectionPos = 0; // } else if (key == GLFW_KEY_X && modifiers == SYSTEM_COMMAND_MOD) { // copySelection(); // deleteSelection(); // } else if (key == GLFW_KEY_C && modifiers == SYSTEM_COMMAND_MOD) { // copySelection(); // } else if (key == GLFW_KEY_V && modifiers == SYSTEM_COMMAND_MOD) { // deleteSelection(); // pasteFromClipboard(); } } return true; } return false; }
bool TextBox::keyboardEvent(int key, int /* scancode */, int action, int modifiers) { if (mEditable && focused()) { if (action == GLFW_PRESS || action == GLFW_REPEAT) { if (key == GLFW_KEY_LEFT) { if (modifiers == GLFW_MOD_SHIFT) { if (mSelectionPos == -1) mSelectionPos = mCursorPos; } else { mSelectionPos = -1; } if (mCursorPos > 0) mCursorPos--; } else if (key == GLFW_KEY_RIGHT) { if (modifiers == GLFW_MOD_SHIFT) { if (mSelectionPos == -1) mSelectionPos = mCursorPos; } else { mSelectionPos = -1; } if (mCursorPos < (int) mValueTemp.length()) mCursorPos++; } else if (key == GLFW_KEY_HOME) { if (modifiers == GLFW_MOD_SHIFT) { if (mSelectionPos == -1) mSelectionPos = mCursorPos; } else { mSelectionPos = -1; } mCursorPos = 0; } else if (key == GLFW_KEY_END) { if (modifiers == GLFW_MOD_SHIFT) { if (mSelectionPos == -1) mSelectionPos = mCursorPos; } else { mSelectionPos = -1; } mCursorPos = (int) mValueTemp.size(); } else if (key == GLFW_KEY_BACKSPACE) { if (!deleteSelection()) { if (mCursorPos > 0) { mValueTemp.erase(mValueTemp.begin() + mCursorPos - 1); mCursorPos--; } } } else if (key == GLFW_KEY_DELETE) { if (!deleteSelection()) { if (mCursorPos < (int) mValueTemp.length()) mValueTemp.erase(mValueTemp.begin() + mCursorPos); } } else if (key == GLFW_KEY_ENTER) { if (!mCommitted) focusEvent(false); } else if (key == GLFW_KEY_A && modifiers == SYSTEM_COMMAND_MOD) { mCursorPos = (int) mValueTemp.length(); mSelectionPos = 0; } else if (key == GLFW_KEY_X && modifiers == SYSTEM_COMMAND_MOD) { copySelection(); deleteSelection(); } else if (key == GLFW_KEY_C && modifiers == SYSTEM_COMMAND_MOD) { copySelection(); } else if (key == GLFW_KEY_V && modifiers == SYSTEM_COMMAND_MOD) { deleteSelection(); pasteFromClipboard(); } mValidFormat = (mValueTemp == "") || checkFormat(mValueTemp, mFormat); } return true; } return false; }
bool TextBox::keyboardEvent(int key, int /* scancode */, int action, int modifiers) { if (mEditable && focused()) { if (action == SDL_KEYDOWN /*|| action == GLFW_REPEAT*/) { if (key == SDLK_LEFT ) { if (modifiers == SDLK_LSHIFT) { if (mSelectionPos == -1) mSelectionPos = mCursorPos; } else { mSelectionPos = -1; } if (mCursorPos > 0) mCursorPos--; } else if (key == SDLK_RIGHT) { if (modifiers == SDLK_LSHIFT) { if (mSelectionPos == -1) mSelectionPos = mCursorPos; } else { mSelectionPos = -1; } if (mCursorPos < (int) mValueTemp.length()) mCursorPos++; } else if (key == SDLK_HOME) { if (modifiers == SDLK_LSHIFT) { if (mSelectionPos == -1) mSelectionPos = mCursorPos; } else { mSelectionPos = -1; } mCursorPos = 0; } else if (key == SDLK_END) { if (modifiers == SDLK_LSHIFT) { if (mSelectionPos == -1) mSelectionPos = mCursorPos; } else { mSelectionPos = -1; } mCursorPos = (int) mValueTemp.size(); } else if (key == SDLK_BACKSPACE) { if (!deleteSelection()) { if (mCursorPos > 0) { mValueTemp.erase(mValueTemp.begin() + mCursorPos - 1); mCursorPos--; } } } else if (key == SDLK_DELETE) { if (!deleteSelection()) { if (mCursorPos < (int) mValueTemp.length()) mValueTemp.erase(mValueTemp.begin() + mCursorPos); } } else if (key == SDLK_RETURN) { if (!mCommitted) focusEvent(false); } else if (key == SDLK_a && modifiers == SDLK_RCTRL) { mCursorPos = (int) mValueTemp.length(); mSelectionPos = 0; } else if (key == SDLK_x && modifiers == SDLK_RCTRL) { copySelection(); deleteSelection(); } else if (key == SDLK_c && modifiers == SDLK_RCTRL) { copySelection(); } else if (key == SDLK_v && modifiers == SDLK_RCTRL) { deleteSelection(); pasteFromClipboard(); } mValidFormat = (mValueTemp == "") || checkFormat(mValueTemp, mFormat); } return true; } return false; }