diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-23 17:13:36 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-23 17:13:36 -0500 |
commit | d3f7a9d6f1b8f6e24fb49aaa8caeaa7623ae48b5 (patch) | |
tree | baeeba639393f46abab749f4700a250091c3cc16 /tqtinterface/qt4/src/widgets/tqtextedit.cpp | |
parent | d7be1694839bacae31e500ea9e36b3c13257ce28 (diff) | |
download | experimental-d3f7a9d6f1b8f6e24fb49aaa8caeaa7623ae48b5.tar.gz experimental-d3f7a9d6f1b8f6e24fb49aaa8caeaa7623ae48b5.zip |
Apply all Qt3.3.8d patches
NOTE: This will *likely* break compilation of TQt4
Please wait a few days for fixes to be committed as needed!
Diffstat (limited to 'tqtinterface/qt4/src/widgets/tqtextedit.cpp')
-rw-r--r-- | tqtinterface/qt4/src/widgets/tqtextedit.cpp | 124 |
1 files changed, 112 insertions, 12 deletions
diff --git a/tqtinterface/qt4/src/widgets/tqtextedit.cpp b/tqtinterface/qt4/src/widgets/tqtextedit.cpp index 62c1d5f..e299348 100644 --- a/tqtinterface/qt4/src/widgets/tqtextedit.cpp +++ b/tqtinterface/qt4/src/widgets/tqtextedit.cpp @@ -42,6 +42,11 @@ #ifndef TQT_NO_TEXTEDIT +// Keep this position to avoid patch rejection +#ifndef TQT_NO_IM +#include "tqinputcontext.h" +#endif + #include "../kernel/tqrichtext_p.h" #include "tqpainter.h" #include "tqpen.h" @@ -111,6 +116,8 @@ public: int id[ 7 ]; int preeditStart; int preeditLength; + bool composeMode() const { return ( preeditLength > 0 ); } + uint ensureCursorVisibleInShowEvent : 1; uint tabChangesFocus : 1; TQString scrollToAnchor; // used to deferr scrollToAnchor() until the show event when we are resized @@ -1081,6 +1088,10 @@ void TQTextEdit::drawContents( TQPainter *p, int cx, int cy, int cw, int ch ) l += v; } } + + // This invocation is required to follow dragging of active window + // by the showed candidate window. + updateMicroFocusHint(); } /*! @@ -1556,6 +1567,35 @@ void TQTextEdit::keyPressEvent( TQKeyEvent *e ) } /*! + This function is not intended as polymorphic usage. Just a shared code + fragment that calls TQWidget::sendMouseEventToInputContext() easily for this + class. + */ +bool TQTextEdit::sendMouseEventToInputContext( TQMouseEvent *e ) +{ +#ifndef TQT_NO_IM + if ( d->composeMode() ) { + TQTextCursor c( doc ); + if ( c.place( e->pos(), doc->firstParagraph(), FALSE, FALSE, FALSE ) ) { + int mousePos = c.index() - d->preeditStart; + if ( cursor->globalY() == c.globalY() && + mousePos >= 0 && mousePos < d->preeditLength ) { + TQWidget::sendMouseEventToInputContext( mousePos, e->type(), + e->button(), e->state() ); + } + } else if ( e->type() != TQEvent::MouseMove ) { + // send button events on out of preedit + TQWidget::sendMouseEventToInputContext( -1, e->type(), + e->button(), e->state() ); + } + return TRUE; + } +#endif + return FALSE; +} + + +/*! \reimp */ void TQTextEdit::imStartEvent( TQIMEvent *e ) @@ -1585,11 +1625,17 @@ void TQTextEdit::imComposeEvent( TQIMEvent *e ) doc->removeSelection( TQTextDocument::IMCompositionText ); doc->removeSelection( TQTextDocument::IMSelectionText ); - if ( d->preeditLength > 0 && cursor->paragraph() ) + if ( d->composeMode() && cursor->paragraph() ) cursor->paragraph()->remove( d->preeditStart, d->preeditLength ); cursor->setIndex( d->preeditStart ); d->preeditLength = e->text().length(); - insert( e->text() ); + + int sellen = e->selectionLength(); + uint insertionFlags = CheckNewLines | RemoveSelected | AsIMCompositionText; + if ( sellen > 0 ) { + insertionFlags |= WithIMSelection; + } + insert( e->text(), insertionFlags ); // insert can trigger an imEnd event as it emits a textChanged signal, so better // be careful if(d->preeditStart != -1) { @@ -1601,14 +1647,20 @@ void TQTextEdit::imComposeEvent( TQIMEvent *e ) cursor->setIndex( d->preeditStart + e->cursorPos() ); - int sellen = e->selectionLength(); if ( sellen > 0 ) { cursor->setIndex( d->preeditStart + e->cursorPos() + sellen ); c = *cursor; cursor->setIndex( d->preeditStart + e->cursorPos() ); doc->setSelectionStart( TQTextDocument::IMSelectionText, *cursor ); doc->setSelectionEnd( TQTextDocument::IMSelectionText, c ); +#if 0 + // Disabled for Asian input method that shows candidate + // window. This behavior is same as TQt/E 2.3.7 which supports + // Asian input methods. Asian input methods need start point + // of IM selection text to place candidate window as adjacent + // to the selection text. cursor->setIndex( d->preeditStart + d->preeditLength ); +#endif } } @@ -1632,11 +1684,12 @@ void TQTextEdit::imEndEvent( TQIMEvent *e ) if (undoRedoInfo.type == UndoRedoInfo::IME) undoRedoInfo.type = UndoRedoInfo::Invalid; - if ( d->preeditLength > 0 && cursor->paragraph() ) + if ( d->composeMode() && cursor->paragraph() ) cursor->paragraph()->remove( d->preeditStart, d->preeditLength ); if ( d->preeditStart >= 0 ) { cursor->setIndex( d->preeditStart ); - insert( e->text() ); + //TODO: TQt 4 we should use the new virtual insert function + insert( e->text(), FALSE ); } d->preeditStart = d->preeditLength = -1; @@ -2127,6 +2180,13 @@ void TQTextEdit::drawCursor( bool visible ) isReadOnly() ) return; + // Asian users regard selection text as cursor on candidate + // selection phase of input method, so ordinary cursor should be + // invisible if IM selection text exists. + if ( doc->hasSelection( TQTextDocument::IMSelectionText ) ) { + visible = FALSE; + } + TQPainter p( viewport() ); TQRect r( cursor->topParagraph()->rect() ); cursor->paragraph()->setChanged( TRUE ); @@ -2201,6 +2261,9 @@ void TQTextEdit::contentsMousePressEvent( TQMouseEvent *e ) } #endif + if ( sendMouseEventToInputContext( e ) ) + return; + if ( d->trippleClickTimer->isActive() && ( e->globalPos() - d->trippleClickPoint ).manhattanLength() < TQApplication::startDragDistance() ) { @@ -2306,7 +2369,9 @@ void TQTextEdit::contentsMouseMoveEvent( TQMouseEvent *e ) return; } #endif - if ( mousePressed ) { + if ( sendMouseEventToInputContext( e ) ) { + // don't return from here to avoid cursor vanishing + } else if ( mousePressed ) { #ifndef TQT_NO_DRAGANDDROP if ( mightStartDrag ) { dragStartTimer->stop(); @@ -2363,7 +2428,7 @@ void TQTextEdit::copyToClipboard() void TQTextEdit::contentsMouseReleaseEvent( TQMouseEvent * e ) { - if ( !inDoubleClick ) { // could be the release of a dblclick + if ( !inDoubleClick && !d->composeMode() ) { // could be the release of a dblclick int para = 0; int index = charAt( e->pos(), ¶ ); emit clicked( para, index ); @@ -2374,6 +2439,8 @@ void TQTextEdit::contentsMouseReleaseEvent( TQMouseEvent * e ) return; } #endif + if ( sendMouseEventToInputContext( e ) ) + return; TQTextCursor oldCursor = *cursor; if ( scrollTimer->isActive() ) scrollTimer->stop(); @@ -2467,7 +2534,7 @@ void TQTextEdit::contentsMouseReleaseEvent( TQMouseEvent * e ) void TQTextEdit::contentsMouseDoubleClickEvent( TQMouseEvent * e ) { - if ( e->button() != Qt::LeftButton ) { + if ( e->button() != Qt::LeftButton && !d->composeMode() ) { e->ignore(); return; } @@ -2498,6 +2565,9 @@ void TQTextEdit::contentsMouseDoubleClickEvent( TQMouseEvent * e ) } else #endif { + if ( sendMouseEventToInputContext( e ) ) + return; + TQTextCursor c1 = *cursor; TQTextCursor c2 = *cursor; #if defined(TQ_OS_MAC) @@ -2673,10 +2743,15 @@ void TQTextEdit::contentsDropEvent( TQDropEvent *e ) */ void TQTextEdit::contentsContextMenuEvent( TQContextMenuEvent *e ) { + e->accept(); +#ifndef TQT_NO_IM + if ( d->composeMode() ) + return; +#endif + clearUndoRedo(); mousePressed = FALSE; - e->accept(); #ifndef TQT_NO_POPUPMENU TQGuardedPtr<TQTextEdit> that = this; TQGuardedPtr<TQPopupMenu> popup = createPopupMenu( e->pos() ); @@ -2826,6 +2901,12 @@ void TQTextEdit::placeCursor( const TQPoint &pos, TQTextCursor *c, bool link ) void TQTextEdit::updateMicroFocusHint() { TQTextCursor c( *cursor ); +#if 0 + // Disabled for Asian input method that shows candidate + // window. This behavior is same as TQt/E 2.3.7 which supports + // Asian input methods. Asian input methods need start point of IM + // selection text to place candidate window as adjacent to the + // selection text. if ( d->preeditStart != -1 ) { c.setIndex( d->preeditStart ); if(doc->hasSelection(TQTextDocument::IMSelectionText)) { @@ -2834,7 +2915,8 @@ void TQTextEdit::updateMicroFocusHint() c.setIndex(index); } } - +#endif + if ( hasFocus() || viewport()->hasFocus() ) { int h = c.paragraph()->lineHeightOfChar( cursor->index() ); if ( !readonly ) { @@ -2998,6 +3080,8 @@ void TQTextEdit::insert( const TQString &text, uint insertionFlags ) bool indent = insertionFlags & RedoIndentation; bool checkNewLine = insertionFlags & CheckNewLines; bool removeSelected = insertionFlags & RemoveSelected; + bool imComposition = insertionFlags & AsIMCompositionText; + bool imSelection = insertionFlags & WithIMSelection; TQString txt( text ); drawCursor( FALSE ); if ( !isReadOnly() && doc->hasSelection( TQTextDocument::Standard ) && removeSelected ) @@ -3037,7 +3121,10 @@ void TQTextEdit::insert( const TQString &text, uint insertionFlags ) formatMore(); repaintChanged(); ensureCursorVisible(); - drawCursor( TRUE ); + // Asian users regard selection text as cursor on candidate + // selection phase of input method, so ordinary cursor should be + // invisible if IM selection text exists. + drawCursor( !imSelection ); if ( undoEnabled && !isReadOnly() && undoRedoInfo.type != UndoRedoInfo::IME ) { undoRedoInfo.d->text += txt; @@ -3059,7 +3146,13 @@ void TQTextEdit::insert( const TQString &text, uint insertionFlags ) doc->setSelectionEnd( TQTextDocument::Standard, *cursor ); repaintChanged(); } - updateMicroFocusHint(); + // updateMicroFocusHint() should not be invoked here when this + // function is invoked from imComposeEvent() because cursor + // postion is incorrect yet. imComposeEvent() invokes + // updateMicroFocusHint() later. + if ( !imComposition ) { + updateMicroFocusHint(); + } setModified(); emit textChanged(); } @@ -5571,6 +5664,13 @@ TQPopupMenu *TQTextEdit::createPopupMenu( const TQPoint& pos ) #else d->id[ IdSelectAll ] = popup->insertItem( tr( "Select All" ) + ACCEL_KEY( A ) ); #endif + +#ifndef TQT_NO_IM + TQInputContext *qic = getInputContext(); + if ( qic ) + qic->addMenusTo( popup ); +#endif + popup->setItemEnabled( d->id[ IdUndo ], !isReadOnly() && doc->commands()->isUndoAvailable() ); popup->setItemEnabled( d->id[ IdRedo ], !isReadOnly() && doc->commands()->isRedoAvailable() ); #ifndef TQT_NO_CLIPBOARD |