void Entry::selectText(int from, int to) { int end = lastCaretPos(); m_select = from; setCaretPos(from); // to move scroll setCaretPos((to >= 0)? to: end+to+1); invalidate(); }
void Entry::selectText(int from, int to) { int end = base::utf8_length(getText()); m_select = from; setCaretPos(from); // to move scroll setCaretPos((to >= 0)? to: end+to+1); invalidate(); }
void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) { // First remove caret if (_caretVisible) drawCaret(true); x += _editScrollOffset; int width = 0; uint i; uint last = 0; for (i = 0; i < _editString.size(); ++i) { const uint cur = _editString[i]; width += g_gui.getCharWidth(cur, _font) + g_gui.getKerningOffset(last, cur, _font); if (width >= x) break; last = cur; } if (setCaretPos(i)) draw(); #ifdef TIZEN // Display the virtual keypad to allow text entry. Samsung app-store testers expected // the keypad to be displayed when clicking the filter edit control in the laucher gui. g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true); #endif }
void MemoryViewer::OnLButtonDown(UINT nFlags, CPoint point) { int x = point.x; int y = point.y; int line = (y-3)/fontSize.cy; int beforeAscii = beginHex; int inc = 1; int sub = 3*fontSize.cx; switch(dataSize) { case 0: beforeAscii += 47*fontSize.cx; break; case 1: beforeAscii += 39*fontSize.cx; inc = 2; sub = 5*fontSize.cx; break; case 2: beforeAscii += 35*fontSize.cx; inc = 4; sub = 9*fontSize.cx; break; } editAddress = address + (line<<4); if(x >= beginHex && x < beforeAscii) { x -= beginHex; editNibble = 0; while(x > 0) { x -= sub; if(x >= 0) editAddress += inc; else { editNibble = (x + sub)/fontSize.cx; } } editAscii = false; } else if(x >= beginAscii) { int afterAscii = beginAscii+16*fontSize.cx; if(x >= afterAscii) x = afterAscii-1; editAddress += (x-beginAscii)/fontSize.cx; editNibble = 0; editAscii = true; } else { return; } if(editNibble > maxNibble) editNibble = maxNibble; SetFocus(); setCaretPos(); }
void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) { // First remove caret if (_caretVisible) drawCaret(true); x += _editScrollOffset; int width = 0; uint i; for (i = 0; i < _editString.size(); ++i) { width += g_gui.theme()->getCharWidth(_editString[i], _font); if (width >= x) break; } if (setCaretPos(i)) draw(); }
void MemoryViewer::setAddress(u32 a) { address = a; if(displayedLines) { if(addressSize) { u16 addr = address; if((u16)(addr+(displayedLines<<4)) < addr) { address = 0xffff - (displayedLines<<4) + 1; } } else { if((address+(displayedLines<<4)) < address) { address = 0xffffffff - (displayedLines<<4) + 1; } } } if(addressSize) address &= 0xffff; setCaretPos(); InvalidateRect(NULL, TRUE); }
void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) { // First remove caret if (_caretVisible) drawCaret(true); x += _editScrollOffset; int width = 0; uint i; uint last = 0; for (i = 0; i < _editString.size(); ++i) { const uint cur = _editString[i]; width += g_gui.getCharWidth(cur, _font) + g_gui.getKerningOffset(last, cur, _font); if (width >= x) break; last = cur; } if (setCaretPos(i)) draw(); }
void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed) { std::wstring text = base::from_utf8(getText()); int c, selbeg, selend; getEntryThemeInfo(NULL, NULL, NULL, &selbeg, &selend); switch (cmd) { case EntryCmd::NoOp: break; case EntryCmd::InsertChar: // delete the entire selection if (selbeg >= 0) { text.erase(selbeg, selend-selbeg+1); m_caret = selbeg; } // put the character if (text.size() < m_maxsize) { ASSERT((size_t)m_caret <= text.size()); text.insert(m_caret++, 1, unicodeChar); } m_select = -1; break; case EntryCmd::BackwardChar: case EntryCmd::BackwardWord: // selection if (shift_pressed) { if (m_select < 0) m_select = m_caret; } else m_select = -1; // backward word if (cmd == EntryCmd::BackwardWord) { backwardWord(); } // backward char else if (m_caret > 0) { m_caret--; } break; case EntryCmd::ForwardChar: case EntryCmd::ForwardWord: // selection if (shift_pressed) { if (m_select < 0) m_select = m_caret; } else m_select = -1; // forward word if (cmd == EntryCmd::ForwardWord) { forwardWord(); } // forward char else if (m_caret < (int)text.size()) { m_caret++; } break; case EntryCmd::BeginningOfLine: // selection if (shift_pressed) { if (m_select < 0) m_select = m_caret; } else m_select = -1; m_caret = 0; break; case EntryCmd::EndOfLine: // selection if (shift_pressed) { if (m_select < 0) m_select = m_caret; } else m_select = -1; m_caret = text.size(); break; case EntryCmd::DeleteForward: case EntryCmd::Cut: // delete the entire selection if (selbeg >= 0) { // *cut* text! if (cmd == EntryCmd::Cut) { std::wstring selected = text.substr(selbeg, selend - selbeg + 1); clipboard::set_text(base::to_utf8(selected).c_str()); } // remove text text.erase(selbeg, selend-selbeg+1); m_caret = selbeg; } // delete the next character else { if (m_caret < (int)text.size()) text.erase(m_caret, 1); } m_select = -1; break; case EntryCmd::Paste: { const char* clipboard_str; if ((clipboard_str = clipboard::get_text())) { std::string clipboard(clipboard_str); // delete the entire selection if (selbeg >= 0) { text.erase(selbeg, selend-selbeg+1); m_caret = selbeg; m_select = -1; } // paste text for (c=0; c<base::utf8_length(clipboard); c++) { if (text.size() < m_maxsize) text.insert(m_caret+c, 1, *(base::utf8_const_iterator(clipboard.begin())+c)); else break; } setCaretPos(m_caret+c); } break; } case EntryCmd::Copy: if (selbeg >= 0) { std::wstring selected = text.substr(selbeg, selend - selbeg + 1); clipboard::set_text(base::to_utf8(selected).c_str()); } break; case EntryCmd::DeleteBackward: // delete the entire selection if (selbeg >= 0) { text.erase(selbeg, selend-selbeg+1); m_caret = selbeg; } // delete the previous character else { if (m_caret > 0) text.erase(--m_caret, 1); } m_select = -1; break; } std::string newText = base::to_utf8(text); if (newText != getText()) { setText(newText.c_str()); onEntryChange(); } setCaretPos(m_caret); invalidate(); }
void MemoryViewer::OnSetFocus(CWnd* pOldWnd) { setCaretPos(); InvalidateRect(NULL, TRUE); }
void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed) { std::string text = this->text(); int selbeg, selend; getEntryThemeInfo(NULL, NULL, NULL, &selbeg, &selend); switch (cmd) { case EntryCmd::NoOp: break; case EntryCmd::InsertChar: // delete the entire selection if (selbeg >= 0) { text.erase(m_boxes[selbeg].from, m_boxes[selend].to - m_boxes[selbeg].from); m_caret = selbeg; // We set the caret to the beginning of the erased selection, // needed to show the first inserted character in case // m_scroll > m_caret. E.g. we select all text and insert a // new character to replace the whole text, the new inserted // character makes m_caret=1, so m_scroll will be 1 too, but // we need to make m_scroll=0 to show the new inserted char.) // In this way, we first ensure a m_scroll value enough to // show the new inserted character. recalcCharBoxes(text); setCaretPos(m_caret); } // Convert the unicode character -> wstring -> utf-8 string -> insert the utf-8 string if (lastCaretPos() < m_maxsize) { ASSERT(m_caret <= lastCaretPos()); std::wstring unicodeStr; unicodeStr.push_back(unicodeChar); text.insert(m_boxes[m_caret].from, base::to_utf8(unicodeStr)); recalcCharBoxes(text); ++m_caret; } m_select = -1; break; case EntryCmd::BackwardChar: case EntryCmd::BackwardWord: // selection if (shift_pressed) { if (m_select < 0) m_select = m_caret; } else m_select = -1; // backward word if (cmd == EntryCmd::BackwardWord) { backwardWord(); } // backward char else if (m_caret > 0) { m_caret--; } break; case EntryCmd::ForwardChar: case EntryCmd::ForwardWord: // selection if (shift_pressed) { if (m_select < 0) m_select = m_caret; } else m_select = -1; // forward word if (cmd == EntryCmd::ForwardWord) { forwardWord(); } // forward char else if (m_caret < (int)text.size()) { m_caret++; } break; case EntryCmd::BeginningOfLine: // selection if (shift_pressed) { if (m_select < 0) m_select = m_caret; } else m_select = -1; m_caret = 0; break; case EntryCmd::EndOfLine: // selection if (shift_pressed) { if (m_select < 0) m_select = m_caret; } else m_select = -1; m_caret = lastCaretPos(); break; case EntryCmd::DeleteForward: case EntryCmd::Cut: // delete the entire selection if (selbeg >= 0) { // *cut* text! if (cmd == EntryCmd::Cut) set_clipboard_text(selectedText()); // remove text text.erase(m_boxes[selbeg].from, m_boxes[selend].to - m_boxes[selbeg].from); m_caret = selbeg; } // delete the next character else { if (m_caret < (int)text.size()) text.erase(m_boxes[m_caret].from, m_boxes[m_caret].to - m_boxes[m_caret].from); } m_select = -1; break; case EntryCmd::Paste: { std::string clipboard; if (get_clipboard_text(clipboard)) { // delete the entire selection if (selbeg >= 0) { text.erase(m_boxes[selbeg].from, m_boxes[selend].to - m_boxes[selbeg].from); m_caret = selbeg; m_select = -1; } // Paste text recalcCharBoxes(text); int oldBoxes = m_boxes.size(); text.insert(m_boxes[m_caret].from, clipboard); // Remove extra chars that do not fit in m_maxsize recalcCharBoxes(text); if (lastCaretPos() > m_maxsize) { text.erase(m_boxes[m_maxsize].from, text.size() - m_boxes[m_maxsize].from); recalcCharBoxes(text); } int newBoxes = m_boxes.size(); setCaretPos(m_caret+(newBoxes - oldBoxes)); } break; } case EntryCmd::Copy: if (selbeg >= 0) set_clipboard_text(selectedText()); break; case EntryCmd::DeleteBackward: // delete the entire selection if (selbeg >= 0) { text.erase(m_boxes[selbeg].from, m_boxes[selend].to - m_boxes[selbeg].from); m_caret = selbeg; } // delete the previous character else { if (m_caret > 0) { --m_caret; text.erase(m_boxes[m_caret].from, m_boxes[m_caret].to - m_boxes[m_caret].from); } } m_select = -1; break; case EntryCmd::DeleteBackwardWord: m_select = m_caret; backwardWord(); if (m_caret < m_select) { text.erase(m_boxes[m_caret].from, m_boxes[m_select].to - m_boxes[m_caret].from); } m_select = -1; break; case EntryCmd::DeleteForwardToEndOfLine: text.erase(m_boxes[m_caret].from); break; case EntryCmd::SelectAll: selectAllText(); break; } if (text != this->text()) { setText(text); onChange(); } setCaretPos(m_caret); invalidate(); }
bool Entry::onProcessMessage(Message* msg) { switch (msg->type()) { case kTimerMessage: if (hasFocus() && static_cast<TimerMessage*>(msg)->timer() == &m_timer) { // Blinking caret m_state = m_state ? false: true; invalidate(); } break; case kFocusEnterMessage: if (shouldStartTimer(true)) m_timer.start(); m_state = true; invalidate(); if (m_lock_selection) { m_lock_selection = false; } else { selectAllText(); m_recent_focused = true; } // Start processing dead keys if (m_translate_dead_keys) os::instance()->setTranslateDeadKeys(true); break; case kFocusLeaveMessage: invalidate(); m_timer.stop(); if (!m_lock_selection) deselectText(); m_recent_focused = false; // Stop processing dead keys if (m_translate_dead_keys) os::instance()->setTranslateDeadKeys(false); break; case kKeyDownMessage: if (hasFocus() && !isReadOnly()) { // Command to execute EntryCmd cmd = EntryCmd::NoOp; KeyMessage* keymsg = static_cast<KeyMessage*>(msg); KeyScancode scancode = keymsg->scancode(); switch (scancode) { case kKeyLeft: if (msg->ctrlPressed() || msg->altPressed()) cmd = EntryCmd::BackwardWord; else if (msg->cmdPressed()) cmd = EntryCmd::BeginningOfLine; else cmd = EntryCmd::BackwardChar; break; case kKeyRight: if (msg->ctrlPressed() || msg->altPressed()) cmd = EntryCmd::ForwardWord; else if (msg->cmdPressed()) cmd = EntryCmd::EndOfLine; else cmd = EntryCmd::ForwardChar; break; case kKeyHome: cmd = EntryCmd::BeginningOfLine; break; case kKeyEnd: cmd = EntryCmd::EndOfLine; break; case kKeyDel: if (msg->shiftPressed()) cmd = EntryCmd::Cut; else if (msg->ctrlPressed()) cmd = EntryCmd::DeleteForwardToEndOfLine; else cmd = EntryCmd::DeleteForward; break; case kKeyInsert: if (msg->shiftPressed()) cmd = EntryCmd::Paste; else if (msg->ctrlPressed()) cmd = EntryCmd::Copy; break; case kKeyBackspace: if (msg->ctrlPressed()) cmd = EntryCmd::DeleteBackwardWord; else cmd = EntryCmd::DeleteBackward; break; default: // Map common macOS/Windows shortcuts for Cut/Copy/Paste/Select all #if defined __APPLE__ if (msg->onlyCmdPressed()) #else if (msg->onlyCtrlPressed()) #endif { switch (scancode) { case kKeyX: cmd = EntryCmd::Cut; break; case kKeyC: cmd = EntryCmd::Copy; break; case kKeyV: cmd = EntryCmd::Paste; break; case kKeyA: cmd = EntryCmd::SelectAll; break; } } break; } if (cmd == EntryCmd::NoOp) { if (keymsg->unicodeChar() >= 32) { executeCmd(EntryCmd::InsertChar, keymsg->unicodeChar(), (msg->shiftPressed()) ? true: false); // Select dead-key if (keymsg->isDeadKey()) { if (lastCaretPos() < m_maxsize) selectText(m_caret-1, m_caret); } return true; } // Consume all key down of modifiers only, e.g. so the user // can press first "Ctrl" key, and then "Ctrl+C" // combination. else if (keymsg->scancode() >= kKeyFirstModifierScancode) { return true; } else { break; // Propagate to manager } } executeCmd(cmd, keymsg->unicodeChar(), (msg->shiftPressed()) ? true: false); return true; } break; case kMouseDownMessage: captureMouse(); case kMouseMoveMessage: if (hasCapture()) { bool is_dirty = false; int c = getCaretFromMouse(static_cast<MouseMessage*>(msg)); if (static_cast<MouseMessage*>(msg)->left() || !isPosInSelection(c)) { // Move caret if (m_caret != c) { setCaretPos(c); is_dirty = true; invalidate(); } // Move selection if (m_recent_focused) { m_recent_focused = false; m_select = m_caret; } else if (msg->type() == kMouseDownMessage) m_select = m_caret; } // Show the caret if (is_dirty) { if (shouldStartTimer(true)) m_timer.start(); m_state = true; } return true; } break; case kMouseUpMessage: if (hasCapture()) { releaseMouse(); MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg); if (mouseMsg->right()) { // This flag is disabled in kFocusEnterMessage message handler. m_lock_selection = true; showEditPopupMenu(mouseMsg->position()); requestFocus(); } } return true; case kDoubleClickMessage: forwardWord(); m_select = m_caret; backwardWord(); invalidate(); return true; case kMouseEnterMessage: case kMouseLeaveMessage: // TODO theme stuff if (isEnabled()) invalidate(); break; } return Widget::onProcessMessage(msg); }