summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2013-05-06 14:20:11 +0900
committerTor Lillqvist <tml@iki.fi>2013-05-13 05:14:37 +0000
commit57b5ed51d46fd5673dfe35125ceffa71d39f133d (patch)
treec6dcc9991647a7869451a15ba436cb7443f1dc06 /vcl
parentc0417e82174297ace604c68fc577c831929f3573 (diff)
Support IMR_QUERYCHARPOSITION in Writer and Calc.
IMR_QUERYCHARPOSITION is one of optional but fundamental request message sent from IMEs to application. This message is used for retrieving the positional information for each character in a composition text especially when the composition text is drawn by the application. This information is critical for IMEs to align suggestion window with the composition text. Change-Id: I53a344a78688060004cc8bcbbf1127f22a468e20 Reviewed-on: https://gerrit.libreoffice.org/3849 Reviewed-by: Tor Lillqvist <tml@iki.fi> Tested-by: Tor Lillqvist <tml@iki.fi>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/salwtype.hxx13
-rw-r--r--vcl/inc/window.h3
-rw-r--r--vcl/source/control/edit.cxx34
-rw-r--r--vcl/source/window/window.cxx24
-rw-r--r--vcl/source/window/winproc.cxx47
-rw-r--r--vcl/win/source/window/salframe.cxx56
6 files changed, 171 insertions, 6 deletions
diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx
index 62b982f8f5b6..55bc006f90e5 100644
--- a/vcl/inc/salwtype.hxx
+++ b/vcl/inc/salwtype.hxx
@@ -82,6 +82,7 @@ class FontSelectPattern;
#define SALEVENT_STARTRECONVERSION ((sal_uInt16)45)
#define SALEVENT_EXTERNALZOOM ((sal_uInt16)46)
#define SALEVENT_EXTERNALSCROLL ((sal_uInt16)47)
+#define SALEVENT_QUERYCHARPOSITION ((sal_uInt16)48)
// MOUSELEAVE must send, when the pointer leave the client area and
// the mouse is not captured
@@ -213,6 +214,18 @@ struct SalSurroundingTextSelectionChangeEvent
sal_uLong mnEnd; // The end index of selected range
};
+// QUERYCHARPOSITION
+struct SalQueryCharPositionEvent
+{
+ bool mbValid; // The data is valid or not.
+ sal_uLong mnCharPos; // The index of character in a composition.
+ bool mbVertical; // The text is vertical or not.
+ long mnCursorBoundX; // The cursor bounds corresponding to the character specified by mnCharPos - X
+ long mnCursorBoundY; // The cursor bounds corresponding to the character specified by mnCharPos - Y
+ long mnCursorBoundWidth; // The cursor bounds corresponding to the character specified by mnCharPos - Width
+ long mnCursorBoundHeight; // The cursor bounds corresponding to the character specified by mnCharPos - Height
+};
+
// ------------------
// - SalFrame-Types -
// ------------------
diff --git a/vcl/inc/window.h b/vcl/inc/window.h
index 725f5ad2c630..230e1b07d068 100644
--- a/vcl/inc/window.h
+++ b/vcl/inc/window.h
@@ -116,6 +116,9 @@ struct ImplWinData
sal_uInt16* mpExtOldAttrAry;
Rectangle* mpCursorRect;
long mnCursorExtWidth;
+ sal_Bool mbVertical;
+ Rectangle* mpCompositionCharRects;
+ long mnCompositionCharRects;
Rectangle* mpFocusRect;
Rectangle* mpTrackRect;
sal_uInt16 mnTrackFlags;
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index 41722998160a..10b25dc94c6c 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -2313,6 +2313,40 @@ void Edit::Command( const CommandEvent& rCEvt )
Selection aSelection( pData->GetStart(), pData->GetEnd() );
SetSelection(aSelection);
}
+ else if ( rCEvt.GetCommand() == COMMAND_QUERYCHARPOSITION )
+ {
+ if (mpIMEInfos && mpIMEInfos->nLen > 0)
+ {
+ OUString aText = ImplGetText();
+ sal_Int32 nDXBuffer[256];
+ sal_Int32* pDXBuffer = NULL;
+ sal_Int32* pDX = nDXBuffer;
+
+ if( !aText.isEmpty() )
+ {
+ if( (size_t) (2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
+ {
+ pDXBuffer = new sal_Int32[2*(aText.getLength()+1)];
+ pDX = pDXBuffer;
+ }
+
+ GetCaretPositions( aText, pDX, 0, aText.getLength() );
+ }
+ long nTH = GetTextHeight();
+ Point aPos( mnXOffset, ImplGetTextYPosition() );
+
+ Rectangle* aRects = new Rectangle[ mpIMEInfos->nLen ];
+ for ( int nIndex = 0; nIndex < mpIMEInfos->nLen; ++nIndex )
+ {
+ Rectangle aRect( aPos, Size( 10, nTH ) );
+ aRect.Left() = pDX[2*(nIndex+mpIMEInfos->nPos)] + mnXOffset + ImplGetExtraOffset();
+ aRects[ nIndex ] = aRect;
+ }
+ SetCompositionCharRect( aRects, mpIMEInfos->nLen );
+ delete[] aRects;
+ delete[] pDXBuffer;
+ }
+ }
else
Control::Command( rCEvt );
}
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index fc692d21405e..dfb22398ed4b 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -1372,8 +1372,10 @@ ImplWinData* Window::ImplGetWinData() const
((Window*)this)->mpWindowImpl->mpWinData = new ImplWinData;
mpWindowImpl->mpWinData->mpExtOldText = NULL;
mpWindowImpl->mpWinData->mpExtOldAttrAry = NULL;
- mpWindowImpl->mpWinData->mpCursorRect = 0;
+ mpWindowImpl->mpWinData->mpCursorRect = NULL;
mpWindowImpl->mpWinData->mnCursorExtWidth = 0;
+ mpWindowImpl->mpWinData->mpCompositionCharRects = NULL;
+ mpWindowImpl->mpWinData->mnCompositionCharRects = 0;
mpWindowImpl->mpWinData->mpFocusRect = NULL;
mpWindowImpl->mpWinData->mpTrackRect = NULL;
mpWindowImpl->mpWinData->mnTrackFlags = 0;
@@ -4644,6 +4646,8 @@ Window::~Window()
delete mpWindowImpl->mpWinData->mpExtOldAttrAry;
if ( mpWindowImpl->mpWinData->mpCursorRect )
delete mpWindowImpl->mpWinData->mpCursorRect;
+ if ( mpWindowImpl->mpWinData->mpCompositionCharRects)
+ delete[] mpWindowImpl->mpWinData->mpCompositionCharRects;
if ( mpWindowImpl->mpWinData->mpFocusRect )
delete mpWindowImpl->mpWinData->mpFocusRect;
if ( mpWindowImpl->mpWinData->mpTrackRect )
@@ -5658,6 +5662,24 @@ long Window::GetCursorExtTextInputWidth() const
}
// -----------------------------------------------------------------------
+
+void Window::SetCompositionCharRect( const Rectangle* pRect, long nCompositionLength, sal_Bool bVertical ) {
+ DBG_CHKTHIS( Window, ImplDbgCheckWindow );
+
+ ImplWinData* pWinData = ImplGetWinData();
+ delete[] pWinData->mpCompositionCharRects;
+ pWinData->mbVertical = bVertical;
+ pWinData->mpCompositionCharRects = NULL;
+ pWinData->mnCompositionCharRects = nCompositionLength;
+ if ( pRect && (nCompositionLength > 0) )
+ {
+ pWinData->mpCompositionCharRects = new Rectangle[nCompositionLength];
+ for (long i = 0; i < nCompositionLength; ++i)
+ pWinData->mpCompositionCharRects[i] = pRect[i];
+ }
+}
+
+// -----------------------------------------------------------------------
void Window::SetSettings( const AllSettings& rSettings )
{
SetSettings( rSettings, sal_False );
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index 2a296ca8309d..73e5a7a6e800 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -2348,6 +2348,50 @@ static void ImplHandleStartReconversion( Window *pWindow )
// -----------------------------------------------------------------------
+static void ImplHandleSalQueryCharPosition( Window *pWindow,
+ SalQueryCharPositionEvent *pEvt )
+{
+ pEvt->mbValid = false;
+ pEvt->mbVertical = false;
+ pEvt->mnCursorBoundX = 0;
+ pEvt->mnCursorBoundY = 0;
+ pEvt->mnCursorBoundWidth = 0;
+ pEvt->mnCursorBoundHeight = 0;
+
+ ImplSVData* pSVData = ImplGetSVData();
+ Window* pChild = pSVData->maWinData.mpExtTextInputWin;
+
+ if ( !pChild )
+ pChild = ImplGetKeyInputWindow( pWindow );
+ else
+ {
+ // Test, if the Window is related to the frame
+ if ( !pWindow->ImplIsWindowOrChild( pChild ) )
+ pChild = ImplGetKeyInputWindow( pWindow );
+ }
+
+ if( pChild )
+ {
+ ImplCallCommand( pChild, COMMAND_QUERYCHARPOSITION );
+
+ ImplWinData* pWinData = pChild->ImplGetWinData();
+ if ( pWinData->mpCompositionCharRects && pEvt->mnCharPos < static_cast<sal_uLong>( pWinData->mnCompositionCharRects ) )
+ {
+ const Rectangle& aRect = pWinData->mpCompositionCharRects[ pEvt->mnCharPos ];
+ Rectangle aDeviceRect = pChild->ImplLogicToDevicePixel( aRect );
+ Point aAbsScreenPos = pChild->OutputToAbsoluteScreenPixel( pChild->ScreenToOutputPixel(aDeviceRect.TopLeft()) );
+ pEvt->mnCursorBoundX = aAbsScreenPos.X();
+ pEvt->mnCursorBoundY = aAbsScreenPos.Y();
+ pEvt->mnCursorBoundWidth = aDeviceRect.GetWidth();
+ pEvt->mnCursorBoundHeight = aDeviceRect.GetHeight();
+ pEvt->mbVertical = (pWinData->mbVertical != sal_False);
+ pEvt->mbValid = true;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
long ImplWindowFrameProc( Window* pWindow, SalFrame* /*pFrame*/,
sal_uInt16 nEvent, const void* pEvent )
{
@@ -2659,6 +2703,9 @@ long ImplWindowFrameProc( Window* pWindow, SalFrame* /*pFrame*/,
}
}
break;
+ case SALEVENT_QUERYCHARPOSITION:
+ ImplHandleSalQueryCharPosition( pWindow, (SalQueryCharPositionEvent*)pEvent );
+ break;
#ifdef DBG_UTIL
default:
SAL_WARN( "vcl.layout", "ImplWindowFrameProc(): unknown event (" << nEvent << ")" );
diff --git a/vcl/win/source/window/salframe.cxx b/vcl/win/source/window/salframe.cxx
index 05ecefdb44d1..574519c3f5a2 100644
--- a/vcl/win/source/window/salframe.cxx
+++ b/vcl/win/source/window/salframe.cxx
@@ -5523,6 +5523,47 @@ static LRESULT ImplHandleIMEConfirmReconvertString( HWND hWnd, LPARAM lParam )
return TRUE;
}
+static LRESULT ImplHandleIMEQueryCharPosition( HWND hWnd, LPARAM lParam ) {
+ WinSalFrame* pFrame = GetWindowPtr( hWnd );
+ PIMECHARPOSITION pQueryCharPosition = (PIMECHARPOSITION) lParam;
+ if ( pQueryCharPosition->dwSize < sizeof(IMECHARPOSITION) )
+ return FALSE;
+
+ SalQueryCharPositionEvent aEvt;
+ aEvt.mbValid = false;
+ aEvt.mnCharPos = pQueryCharPosition->dwCharPos;
+
+ pFrame->CallCallback( SALEVENT_QUERYCHARPOSITION, (void*)&aEvt );
+
+ if ( !aEvt.mbValid )
+ return FALSE;
+
+ if ( aEvt.mbVertical )
+ {
+ // For vertical writing, the base line is left edge of the rectangle
+ // and the target position is top-right corner.
+ pQueryCharPosition->pt.x = aEvt.mnCursorBoundX + aEvt.mnCursorBoundWidth;
+ pQueryCharPosition->pt.y = aEvt.mnCursorBoundY;
+ pQueryCharPosition->cLineHeight = aEvt.mnCursorBoundWidth;
+ }
+ else
+ {
+ // For horizontal writing, the base line is the bottom edge of the rectangle.
+ // and the target position is top-left corner.
+ pQueryCharPosition->pt.x = aEvt.mnCursorBoundX;
+ pQueryCharPosition->pt.y = aEvt.mnCursorBoundY;
+ pQueryCharPosition->cLineHeight = aEvt.mnCursorBoundHeight;
+ }
+
+ // Currently not supported but many IMEs usually ignore them.
+ pQueryCharPosition->rcDocument.left = 0;
+ pQueryCharPosition->rcDocument.top = 0;
+ pQueryCharPosition->rcDocument.right = 0;
+ pQueryCharPosition->rcDocument.bottom = 0;
+
+ return TRUE;
+}
+
#endif // WINVER >= 0x0500
// -----------------------------------------------------------------------
@@ -5945,11 +5986,16 @@ LRESULT CALLBACK SalFrameWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lP
nRet = ImplHandleIMEReconvertString( hWnd, lParam );
rDef = FALSE;
}
- else if( (sal_uIntPtr)( wParam ) == IMR_CONFIRMRECONVERTSTRING )
- {
- nRet = ImplHandleIMEConfirmReconvertString( hWnd, lParam );
- rDef = FALSE;
- }
+ else if( (sal_uIntPtr)( wParam ) == IMR_CONFIRMRECONVERTSTRING )
+ {
+ nRet = ImplHandleIMEConfirmReconvertString( hWnd, lParam );
+ rDef = FALSE;
+ }
+ else if ( (sal_uIntPtr)( wParam ) == IMR_QUERYCHARPOSITION )
+ {
+ nRet = ImplHandleIMEQueryCharPosition( hWnd, lParam );
+ rDef = FALSE;
+ }
break;
#endif // WINVER >= 0x0500
}