more keyactions for textbox-patch from Vadim <suhanov_vadim at mail dot ru>
This commit is contained in:
parent
6c057c6903
commit
d6ee96775d
3 changed files with 98 additions and 5 deletions
|
@ -1,5 +1,12 @@
|
|||
(Format: Year/Month/Day)
|
||||
Changes for 0.9.13
|
||||
*05/05/06:
|
||||
* Added more KeyActions to TextBox (thanx to Vadim <suhanov_vadim@mail.ru>
|
||||
Control + LeftArrow -> Moves cursor to the left direction, up to next word.
|
||||
Control + RightArrow -> to the right direction.
|
||||
Control + BackSpace -> Removes everything from the cursor left side, up to next left word.
|
||||
Control + Delete -> like above but removes to the right direction.
|
||||
FbTk/TextBox.cc/hh
|
||||
*05/05/05:
|
||||
* Fix #1160244, #1099704, #1094107 Mutiple keyboard layout (Mathias + thanx
|
||||
to Vadim)
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include <X11/keysym.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace FbTk {
|
||||
|
||||
TextBox::TextBox(int screen_num,
|
||||
|
@ -141,11 +143,8 @@ void TextBox::insertText(const std::string &val) {
|
|||
m_text.insert(m_start_pos + cursorPosition(), val);
|
||||
m_cursor_pos += val.size();
|
||||
m_end_pos += val.size();
|
||||
|
||||
if (m_start_pos + cursorPosition() < m_end_pos)
|
||||
adjustEndPos();
|
||||
else
|
||||
adjustStartPos();
|
||||
|
||||
adjustPos();
|
||||
}
|
||||
|
||||
void TextBox::killToEnd() {
|
||||
|
@ -247,6 +246,47 @@ void TextBox::keyPressEvent(XKeyEvent &event) {
|
|||
m_cursor_pos = 0;
|
||||
m_end_pos = 0;
|
||||
break;
|
||||
case XK_Left:
|
||||
if (m_cursor_pos && m_text.size()){
|
||||
m_cursor_pos = findEmptySpaceLeft();
|
||||
adjustPos();
|
||||
}
|
||||
break;
|
||||
case XK_Right:
|
||||
if (m_text.size() && m_cursor_pos < m_text.size()){
|
||||
m_cursor_pos = findEmptySpaceRight();
|
||||
adjustPos();
|
||||
}
|
||||
break;
|
||||
|
||||
case XK_BackSpace: {
|
||||
if (!m_cursor_pos || !m_text.size())
|
||||
break;
|
||||
|
||||
int pos = findEmptySpaceLeft();
|
||||
|
||||
m_text.erase(pos, m_cursor_pos - pos);
|
||||
m_start_pos = 0;
|
||||
m_cursor_pos = pos;
|
||||
m_end_pos = m_text.size();
|
||||
adjustPos();
|
||||
}
|
||||
break;
|
||||
case XK_Delete: {
|
||||
|
||||
if (!m_text.size() || m_cursor_pos >= m_text.size())
|
||||
break;
|
||||
|
||||
int pos = findEmptySpaceRight();
|
||||
|
||||
m_text.erase(m_cursor_pos, pos - m_cursor_pos);
|
||||
m_start_pos = 0;
|
||||
m_cursor_pos = m_cursor_pos;
|
||||
m_end_pos = m_text.size();
|
||||
|
||||
adjustPos();
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if ((event.state & ShiftMask)== ShiftMask ||
|
||||
(event.state & 0x80) == 0x80) { // shif and altgr
|
||||
|
@ -356,6 +396,47 @@ void TextBox::adjustStartPos() {
|
|||
m_start_pos = start_pos;
|
||||
}
|
||||
|
||||
int TextBox::findEmptySpaceLeft(){
|
||||
|
||||
// found the first left space symbol
|
||||
int pos = m_text.rfind(' ', m_cursor_pos - 1);
|
||||
|
||||
// do we have one more space symbol near?
|
||||
int next_pos = -1;
|
||||
while ( pos > 0 && (next_pos = m_text.rfind(' ', pos - 1)) > -1 ){
|
||||
if (next_pos + 1 < pos)
|
||||
break;
|
||||
pos = next_pos;
|
||||
}
|
||||
if (pos < 0)
|
||||
pos = 0;
|
||||
|
||||
return pos;
|
||||
|
||||
}
|
||||
int TextBox::findEmptySpaceRight(){
|
||||
|
||||
// found the first right space symbol
|
||||
int pos = m_text.find(' ', m_cursor_pos);
|
||||
|
||||
// do we have one more space symbol near?
|
||||
int next_pos = -1;
|
||||
while (pos > -1 && pos < m_text.size() && (next_pos = m_text.find(' ', pos + 1)) > -1 ){
|
||||
if (next_pos - 1 > pos)
|
||||
break;
|
||||
pos = next_pos;
|
||||
}
|
||||
if (pos < 0)
|
||||
pos = m_text.size();
|
||||
|
||||
return pos + 1; // (+1) - sets cursor at the right.
|
||||
|
||||
}
|
||||
void TextBox::adjustPos(){
|
||||
if (m_start_pos + cursorPosition() < m_end_pos)
|
||||
adjustEndPos();
|
||||
else
|
||||
adjustStartPos();
|
||||
|
||||
}
|
||||
}; // end namespace FbTk
|
||||
|
|
|
@ -69,10 +69,15 @@ public:
|
|||
GC gc() const { return m_gc; }
|
||||
int cursorPosition() const { return m_cursor_pos; }
|
||||
|
||||
int findEmptySpaceLeft();
|
||||
int findEmptySpaceRight();
|
||||
|
||||
private:
|
||||
void adjustEndPos();
|
||||
void adjustStartPos();
|
||||
|
||||
void adjustPos();
|
||||
|
||||
const FbTk::Font *m_font;
|
||||
std::string m_text;
|
||||
GC m_gc;
|
||||
|
|
Loading…
Reference in a new issue