return true;
}
}
- wxASSERT(0); // we should never arrive here
+
+ wxFAIL_MSG("unreachable");
}
wxLayoutLine *
return n == 0;
}
+bool
+wxLayoutList::MoveCursorWord(int n)
+{
+ wxCHECK_MSG( m_CursorLine, false, "no current line" );
+ wxCHECK_MSG( n == -1 || n == +1, false, "not implemented yet" );
+
+ CoordType moveDistance = 0;
+ CoordType offset;
+ for ( wxLOiterator i = m_CursorLine->FindObject(m_CursorPos.x, &offset);
+ n != 0;
+ n > 0 ? i++ : i-- )
+ {
+ if ( i == NULLIT )
+ return false;
+
+ wxLayoutObject *obj = *i;
+ if( obj->GetType() != WXLO_TYPE_TEXT )
+ {
+ // any non text objects count as one word
+ n > 0 ? n-- : n++;
+
+ moveDistance += obj->GetLength();
+ }
+ else
+ {
+ // text object
+ wxLayoutObjectText *tobj = (wxLayoutObjectText *)obj;
+
+ if ( offset == tobj->GetLength() )
+ {
+ // at end of object
+ n > 0 ? n-- : n++;
+ }
+ else
+ {
+ const char *start = tobj->GetText().c_str();
+ const char *p = start + offset;
+
+ // to the beginning/end of the next/prev word
+ while ( isspace(*p) )
+ {
+ n > 0 ? p++ : p--;
+ }
+
+ // go to the end/beginning of the word (in a broad sense...)
+ while ( p >= start && !isspace(*p) )
+ {
+ n > 0 ? p++ : p--;
+ }
+
+ if ( n > 0 )
+ {
+ // now advance to the beginning of the next word
+ while ( isspace(*p) )
+ p++;
+ }
+
+ n > 0 ? n-- : n++;
+
+ moveDistance = p - start - offset;
+ }
+ }
+
+ // except for the first iteration, offset is 0
+ offset = 0;
+ }
+
+ MoveCursorHorizontally(moveDistance);
+
+ return true;
+}
+
bool
wxLayoutList::Insert(wxString const &text)
{
*/
bool MoveCursorVertically(int n);
/** Move cursor left or right.
- @param n
+ @param n = number of positions to move
@return bool if it could be moved
*/
bool MoveCursorHorizontally(int n);
+ /** Move cursor to the left or right counting in words
+ @param n = number of positions in words
+ @return bool if it could be moved
+ */
+ bool MoveCursorWord(int n);
/// Move cursor to end of line.
void MoveCursorToEndOfLine(void)
/** Finds text in this list.
@param needle the text to find
@param cpos the position where to start the search
- @return the cursoor coord where it was found or (-1,-1)
+ @return the cursor coord where it was found or (-1,-1)
*/
wxPoint FindText(const wxString &needle, const wxPoint &cpos = wxPoint(0,0)) const;
wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
: wxScrolledWindow(parent, -1,
wxDefaultPosition, wxDefaultSize,
- wxHSCROLL | wxVSCROLL | wxBORDER)
+ wxHSCROLL | wxVSCROLL |
+ wxBORDER |
+ wxWANTS_CHARS)
{
SetStatusBar(NULL); // don't use statusbar
DoPaint((wxRect *)NULL);
}
-#ifdef __WXMSW__
-long
-wxLayoutWindow::MSWGetDlgCode()
-{
- // if we don't return this, we won't get OnChar() events for TABs and ENTER
- return DLGC_WANTCHARS | DLGC_WANTARROWS | DLGC_WANTMESSAGE;
-}
-#endif //MSW
-
void
wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
{
cursor, etc. It's default will process all keycodes causing
modifications to the buffer, but only if editing is allowed.
*/
+ bool ctrlDown = event.ControlDown();
switch(keyCode)
{
case WXK_RIGHT:
- m_llist->MoveCursorHorizontally(1);
+ if ( ctrlDown )
+ m_llist->MoveCursorWord(1);
+ else
+ m_llist->MoveCursorHorizontally(1);
break;
case WXK_LEFT:
- m_llist->MoveCursorHorizontally(-1);
+ if ( ctrlDown )
+ m_llist->MoveCursorWord(-1);
+ else
+ m_llist->MoveCursorHorizontally(-1);
break;
case WXK_UP:
m_llist->MoveCursorVertically(-1);
m_llist->MoveCursorVertically(20);
break;
case WXK_HOME:
- m_llist->MoveCursorToBeginOfLine();
+ if ( ctrlDown )
+ m_llist->MoveCursorTo(wxPoint(0, 0));
+ else
+ m_llist->MoveCursorToBeginOfLine();
break;
case WXK_END:
+ if ( ctrlDown )
+ {
+ // TODO VZ: how to move the cursor to the last line of the text?
+ m_llist->MoveCursorVertically(1000);
+ }
m_llist->MoveCursorToEndOfLine();
break;
default:
- if(keyCode == 'c' && event.ControlDown())
+ if(keyCode == 'c' && ctrlDown)
{
// this should work even in read-only mode
Copy();
}
- if( IsEditable() )
+ else if( IsEditable() )
{
/* First, handle control keys */
if(event.ControlDown() && ! event.AltDown())
*/
void DoPaint(const wxRect *updateRect = NULL);
-#ifdef __WXMSW__
- virtual long MSWGetDlgCode();
-#endif //MSW
-
/// if exact == false, assume 50% extra size for the future
void ResizeScrollbars(bool exact = false); // don't change this to true!