LCOV - code coverage report
Current view: top level - vcl/unx/generic/app - i18n_ic.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 242 0.0 %
Date: 2014-04-14 Functions: 0 20 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <stdio.h>
      21             : 
      22             : #include <sal/alloca.h>
      23             : #include <osl/thread.h>
      24             : 
      25             : #include <prex.h>
      26             : #include <X11/Xlocale.h>
      27             : #include <X11/Xlib.h>
      28             : #include <postx.h>
      29             : 
      30             : #include <unx/salunx.h>
      31             : #include <unx/XIM.h>
      32             : #include <unx/i18n_ic.hxx>
      33             : #include <unx/i18n_im.hxx>
      34             : #include <unx/i18n_status.hxx>
      35             : 
      36             : #include <unx/salframe.h>
      37             : #include <unx/saldata.hxx>
      38             : #include <unx/saldisp.hxx>
      39             : 
      40             : using namespace vcl;
      41             : 
      42           0 : static void sendEmptyCommit( SalFrame* pFrame )
      43             : {
      44           0 :     vcl::DeletionListener aDel( pFrame );
      45             : 
      46           0 :     SalExtTextInputEvent aEmptyEv;
      47           0 :     aEmptyEv.mnTime             = 0;
      48           0 :     aEmptyEv.mpTextAttr         = 0;
      49           0 :     aEmptyEv.maText             = "";
      50           0 :     aEmptyEv.mnCursorPos        = 0;
      51           0 :     aEmptyEv.mnCursorFlags      = 0;
      52           0 :     aEmptyEv.mbOnlyCursor       = False;
      53           0 :     pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEmptyEv );
      54           0 :     if( ! aDel.isDeleted() )
      55           0 :         pFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, NULL );
      56           0 : }
      57             : 
      58             : // Constructor / Destructor, the InputContext is bound to the SalFrame, as it
      59             : // needs the shell window as a focus window
      60             : 
      61           0 : SalI18N_InputContext::~SalI18N_InputContext()
      62             : {
      63           0 :     if ( maContext != NULL )
      64           0 :         XDestroyIC( maContext );
      65           0 :     if ( mpAttributes != NULL )
      66           0 :         XFree( mpAttributes );
      67           0 :     if ( mpStatusAttributes != NULL )
      68           0 :         XFree( mpStatusAttributes );
      69           0 :     if ( mpPreeditAttributes != NULL )
      70           0 :         XFree( mpPreeditAttributes );
      71             : 
      72           0 :     if (maClientData.aText.pUnicodeBuffer != NULL)
      73           0 :         free(maClientData.aText.pUnicodeBuffer);
      74           0 :     if (maClientData.aText.pCharStyle != NULL)
      75           0 :         free(maClientData.aText.pCharStyle);
      76           0 : }
      77             : 
      78             : // convenience routine to add items to a XVaNestedList
      79             : 
      80             : static XVaNestedList
      81           0 : XVaAddToNestedList( XVaNestedList a_srclist, char* name, XPointer value )
      82             : {
      83             :     XVaNestedList a_dstlist;
      84             : 
      85             :     // if ( value == NULL )
      86             :     //  return a_srclist;
      87             : 
      88           0 :     if ( a_srclist == NULL )
      89             :     {
      90             :         a_dstlist = XVaCreateNestedList(
      91             :                                         0,
      92             :                                         name,           value,
      93           0 :                                         NULL );
      94             :     }
      95             :     else
      96             :     {
      97             :         a_dstlist = XVaCreateNestedList(
      98             :                                         0,
      99             :                                         XNVaNestedList, a_srclist,
     100             :                                         name,           value,
     101           0 :                                         NULL );
     102             :     }
     103             : 
     104           0 :     return a_dstlist != NULL ? a_dstlist : a_srclist ;
     105             : }
     106             : 
     107             : // convenience routine to create a fontset
     108             : 
     109             : static XFontSet
     110           0 : get_font_set( Display *p_display )
     111             : {
     112             :     static XFontSet p_font_set = NULL;
     113             : 
     114           0 :     if (p_font_set == NULL)
     115             :     {
     116             :         char **pp_missing_list;
     117             :         int    n_missing_count;
     118             :         char  *p_default_string;
     119             : 
     120             :         p_font_set = XCreateFontSet(p_display, "-*",
     121           0 :                                     &pp_missing_list, &n_missing_count, &p_default_string);
     122             :     }
     123             : 
     124           0 :     return p_font_set;
     125             : }
     126             : 
     127             : // Constructor for a InputContext (IC)
     128             : 
     129           0 : SalI18N_InputContext::SalI18N_InputContext ( SalFrame *pFrame ) :
     130             :         mbUseable( True ),
     131             :         maContext( (XIC)NULL ),
     132             :         mnSupportedStatusStyle(
     133             :                                XIMStatusCallbacks   |
     134             :                                XIMStatusNothing     |
     135             :                                XIMStatusNone
     136             :                                ),
     137             :         mnSupportedPreeditStyle(
     138             :                                 XIMPreeditCallbacks |
     139             :                                 XIMPreeditNothing   |
     140             :                                 XIMPreeditNone
     141             :                                 ),
     142             :         mnStatusStyle( 0 ),
     143             :         mnPreeditStyle( 0 ),
     144             :         mpAttributes( NULL ),
     145             :         mpStatusAttributes( NULL ),
     146           0 :         mpPreeditAttributes( NULL )
     147             : {
     148             : #ifdef SOLARIS
     149             :     static const char* pIIIMPEnable = getenv( "SAL_DISABLE_OWN_IM_STATUS" );
     150             :     if( pIIIMPEnable && *pIIIMPEnable )
     151             :         mnSupportedStatusStyle &= ~XIMStatusCallbacks;
     152             : #endif
     153             : 
     154           0 :     maClientData.aText.pUnicodeBuffer       = NULL;
     155           0 :     maClientData.aText.pCharStyle           = NULL;
     156           0 :     maClientData.aInputEv.mnTime            = 0;
     157           0 :     maClientData.aInputEv.mpTextAttr        = NULL;
     158           0 :     maClientData.aInputEv.mnCursorPos       = 0;
     159           0 :     maClientData.aInputEv.mnCursorFlags     = 0;
     160           0 :     maClientData.aInputEv.mbOnlyCursor      = false;
     161             : 
     162             :     SalI18N_InputMethod *pInputMethod;
     163           0 :     pInputMethod = GetGenericData()->GetSalDisplay()->GetInputMethod();
     164             : 
     165             :     mnSupportedPreeditStyle =   XIMPreeditCallbacks | XIMPreeditPosition
     166           0 :         | XIMPreeditNothing   | XIMPreeditNone;
     167           0 :     if (pInputMethod->UseMethod()
     168           0 :         && SupportInputMethodStyle( pInputMethod->GetSupportedStyles() ) )
     169             :     {
     170           0 :         const SystemEnvData* pEnv = pFrame->GetSystemData();
     171           0 :         XLIB_Window  aClientWindow = pEnv->aShellWindow;
     172           0 :         XLIB_Window  aFocusWindow  = pEnv->aWindow;
     173             : 
     174             :         // for status callbacks and commit string callbacks
     175             : #define PREEDIT_BUFSZ 16
     176           0 :         maClientData.eState                 = ePreeditStatusStartPending;
     177           0 :         maClientData.pFrame                 = pFrame;
     178             :         maClientData.aText.pUnicodeBuffer   =
     179           0 :             (sal_Unicode*)malloc(PREEDIT_BUFSZ * sizeof(sal_Unicode));
     180             :         maClientData.aText.pCharStyle       =
     181           0 :             (XIMFeedback*)malloc(PREEDIT_BUFSZ * sizeof(XIMFeedback));
     182           0 :         maClientData.aText.nSize            = PREEDIT_BUFSZ;
     183           0 :         maClientData.aText.nCursorPos       = 0;
     184           0 :         maClientData.aText.nLength          = 0;
     185             : 
     186             :         // Status attributes
     187             : 
     188           0 :         switch ( mnStatusStyle )
     189             :         {
     190             :             case XIMStatusCallbacks:
     191             :             {
     192             :                 static XIMCallback aStatusStartCallback;
     193             :                 static XIMCallback aStatusDoneCallback;
     194             :                 static XIMCallback aStatusDrawCallback;
     195             : 
     196           0 :                 aStatusStartCallback.callback    = (XIMProc)StatusStartCallback;
     197           0 :                 aStatusStartCallback.client_data = (XPointer)&maClientData;
     198           0 :                 aStatusDoneCallback.callback     = (XIMProc)StatusDoneCallback;
     199           0 :                 aStatusDoneCallback.client_data  = (XPointer)&maClientData;
     200           0 :                 aStatusDrawCallback.callback     = (XIMProc)StatusDrawCallback;
     201           0 :                 aStatusDrawCallback.client_data  = (XPointer)&maClientData;
     202             : 
     203             :                 mpStatusAttributes = XVaCreateNestedList (
     204             :                                                           0,
     205             :                                                           XNStatusStartCallback, &aStatusStartCallback,
     206             :                                                           XNStatusDoneCallback,  &aStatusDoneCallback,
     207             :                                                           XNStatusDrawCallback,  &aStatusDrawCallback,
     208           0 :                                                           NULL );
     209             : 
     210           0 :                 break;
     211             :             }
     212             : 
     213             :             case XIMStatusArea:
     214             :                 /* not supported */
     215           0 :                 break;
     216             : 
     217             :             case XIMStatusNone:
     218             :             case XIMStatusNothing:
     219             :             default:
     220             :                 /* no arguments needed */
     221           0 :                 break;
     222             :         }
     223             : 
     224             :         // set preedit attributes
     225             : 
     226           0 :         switch ( mnPreeditStyle )
     227             :         {
     228             :             case XIMPreeditCallbacks:
     229             : 
     230           0 :                 maPreeditCaretCallback.callback = (XIMProc)PreeditCaretCallback;
     231           0 :                 maPreeditStartCallback.callback = (XIMProc)PreeditStartCallback;
     232           0 :                 maPreeditDoneCallback.callback  = (XIMProc)PreeditDoneCallback;
     233           0 :                 maPreeditDrawCallback.callback  = (XIMProc)PreeditDrawCallback;
     234           0 :                 maPreeditCaretCallback.client_data = (XPointer)&maClientData;
     235           0 :                 maPreeditStartCallback.client_data = (XPointer)&maClientData;
     236           0 :                 maPreeditDoneCallback.client_data  = (XPointer)&maClientData;
     237           0 :                 maPreeditDrawCallback.client_data  = (XPointer)&maClientData;
     238             : 
     239             :                 mpPreeditAttributes = XVaCreateNestedList (
     240             :                                                            0,
     241             :                                                            XNPreeditStartCallback, &maPreeditStartCallback,
     242             :                                                            XNPreeditDoneCallback,  &maPreeditDoneCallback,
     243             :                                                            XNPreeditDrawCallback,   &maPreeditDrawCallback,
     244             :                                                            XNPreeditCaretCallback, &maPreeditCaretCallback,
     245           0 :                                                            NULL );
     246             : 
     247           0 :                 break;
     248             : 
     249             :             case XIMPreeditArea:
     250             :                 /* not supported */
     251           0 :                 break;
     252             : 
     253             :             case XIMPreeditPosition:
     254             :             {
     255             :                 // spot location
     256           0 :                 SalExtTextInputPosEvent aPosEvent;
     257           0 :                 pFrame->CallCallback(SALEVENT_EXTTEXTINPUTPOS, (void*)&aPosEvent);
     258             : 
     259             :                 static XPoint aSpot;
     260           0 :                 aSpot.x = aPosEvent.mnX + aPosEvent.mnWidth;
     261           0 :                 aSpot.y = aPosEvent.mnY + aPosEvent.mnHeight;
     262             : 
     263             :                 // create attributes for preedit position style
     264             :                 mpPreeditAttributes = XVaCreateNestedList (
     265             :                                                            0,
     266             :                                                            XNSpotLocation, &aSpot,
     267           0 :                                                            NULL );
     268             : 
     269             :                 // XCreateIC() fails on Redflag Linux 2.0 if there is no
     270             :                 // fontset though the data itself is not evaluated nor is
     271             :                 // it required according to the X specs.
     272           0 :                 Display* pDisplay = GetGenericData()->GetSalDisplay()->GetDisplay();
     273           0 :                 XFontSet pFontSet = get_font_set(pDisplay);
     274             : 
     275           0 :                 if (pFontSet != NULL)
     276             :                 {
     277             :                     mpPreeditAttributes = XVaAddToNestedList( mpPreeditAttributes,
     278           0 :                                                               const_cast<char*>(XNFontSet), (XPointer)pFontSet);
     279             :                 }
     280             : 
     281           0 :                 break;
     282             :             }
     283             : 
     284             :             case XIMPreeditNone:
     285             :             case XIMPreeditNothing:
     286             :             default:
     287             :                 /* no arguments needed */
     288           0 :                 break;
     289             :         }
     290             : 
     291             :         // Create the InputContext by giving it exactly the information it
     292             :         // deserves, because inappropriate attributes
     293             :         // let XCreateIC fail on Solaris (eg. for C locale)
     294             : 
     295             :         mpAttributes = XVaCreateNestedList(
     296             :                                            0,
     297             :                                            XNFocusWindow,       aFocusWindow,
     298             :                                            XNClientWindow,      aClientWindow,
     299             :                                            XNInputStyle,        mnPreeditStyle | mnStatusStyle,
     300           0 :                                            NULL );
     301             : 
     302           0 :         if ( mnPreeditStyle != XIMPreeditNone )
     303             :         {
     304             : #if defined LINUX || defined FREEBSD || defined NETBSD || defined OPENBSD || defined DRAGONFLY
     305           0 :             if ( mpPreeditAttributes != NULL )
     306             : #endif
     307             :                 mpAttributes = XVaAddToNestedList( mpAttributes,
     308           0 :                                                    const_cast<char*>(XNPreeditAttributes), (XPointer)mpPreeditAttributes );
     309             :         }
     310           0 :         if ( mnStatusStyle != XIMStatusNone )
     311             :         {
     312             : #if defined LINUX || defined FREEBSD || defined NETBSD || defined OPENBSD || defined DRAGONFLY
     313           0 :             if ( mpStatusAttributes != NULL )
     314             : #endif
     315             :                 mpAttributes = XVaAddToNestedList( mpAttributes,
     316           0 :                                                    const_cast<char*>(XNStatusAttributes), (XPointer)mpStatusAttributes );
     317             :         }
     318             :         maContext = XCreateIC( pInputMethod->GetMethod(),
     319             :                                XNVaNestedList, mpAttributes,
     320           0 :                                NULL );
     321             :     }
     322             : 
     323           0 :     if ( maContext == NULL )
     324             :     {
     325             : #if OSL_DEBUG_LEVEL > 1
     326             :         fprintf(stderr, "input context creation failed\n");
     327             : #endif
     328             : 
     329           0 :         mbUseable = False;
     330             : 
     331           0 :         if ( mpAttributes != NULL )
     332           0 :             XFree( mpAttributes );
     333           0 :         if ( mpStatusAttributes != NULL )
     334           0 :             XFree( mpStatusAttributes );
     335           0 :         if ( mpPreeditAttributes != NULL )
     336           0 :             XFree( mpPreeditAttributes );
     337           0 :         if ( maClientData.aText.pUnicodeBuffer != NULL )
     338           0 :             free ( maClientData.aText.pUnicodeBuffer );
     339           0 :         if ( maClientData.aText.pCharStyle != NULL )
     340           0 :             free ( maClientData.aText.pCharStyle );
     341             : 
     342           0 :         mpAttributes                      = NULL;
     343           0 :         mpStatusAttributes                = NULL;
     344           0 :         mpPreeditAttributes               = NULL;
     345           0 :         maClientData.aText.pUnicodeBuffer = NULL;
     346           0 :         maClientData.aText.pCharStyle     = NULL;
     347             :     }
     348             : 
     349           0 :     if ( maContext != NULL)
     350             :     {
     351           0 :         maDestroyCallback.callback    = (XIMProc)IC_IMDestroyCallback;
     352           0 :         maDestroyCallback.client_data = (XPointer)this;
     353             :         XSetICValues( maContext,
     354             :                       XNDestroyCallback,      &maDestroyCallback,
     355           0 :                       NULL );
     356             :     }
     357           0 : }
     358             : 
     359             : // In Solaris 8 the status window does not unmap if the frame unmapps, so
     360             : // unmap it the hard way
     361             : 
     362             : void
     363           0 : SalI18N_InputContext::Unmap( SalFrame* pFrame )
     364             : {
     365           0 :     if ( maContext != NULL )
     366             :     {
     367           0 :         I18NStatus& rStatus( I18NStatus::get() );
     368           0 :         if( rStatus.getParent() == pFrame )
     369           0 :             rStatus.show( false, I18NStatus::contextmap );
     370             : 
     371             :     }
     372           0 :     UnsetICFocus( pFrame );
     373           0 :     maClientData.pFrame = NULL;
     374           0 : }
     375             : 
     376             : void
     377           0 : SalI18N_InputContext::Map( SalFrame *pFrame )
     378             : {
     379           0 :     if( mbUseable )
     380             :     {
     381           0 :         I18NStatus& rStatus(I18NStatus::get() );
     382           0 :         rStatus.setParent( pFrame );
     383           0 :         if( pFrame )
     384             :         {
     385           0 :             rStatus.show( true, I18NStatus::contextmap );
     386           0 :             if ( maContext == NULL )
     387             :             {
     388             :                 SalI18N_InputMethod *pInputMethod;
     389           0 :                 pInputMethod = GetGenericData()->GetSalDisplay()->GetInputMethod();
     390             : 
     391             :                 maContext = XCreateIC( pInputMethod->GetMethod(),
     392             :                                        XNVaNestedList, mpAttributes,
     393           0 :                                        NULL );
     394             :             }
     395           0 :             if( maClientData.pFrame != pFrame )
     396           0 :                 SetICFocus( pFrame );
     397             :         }
     398             :     }
     399           0 : }
     400             : 
     401             : // Handle DestroyCallbacks
     402             : // in fact this is a callback called from the XNDestroyCallback
     403             : 
     404             : void
     405           0 : SalI18N_InputContext::HandleDestroyIM()
     406             : {
     407           0 :     maContext = 0;      // noli me tangere
     408           0 :     mbUseable = False;
     409           0 : }
     410             : 
     411             : //  make sure, the input method gets all the X-Events it needs, this is only
     412             : //  called once on each frame, it relys on a valid maContext
     413             : 
     414             : void
     415           0 : SalI18N_InputContext::ExtendEventMask( XLIB_Window aFocusWindow )
     416             : {
     417             :     unsigned long nIMEventMask;
     418             :     XWindowAttributes aWindowAttributes;
     419             : 
     420           0 :     if ( mbUseable )
     421             :     {
     422           0 :         Display *pDisplay = XDisplayOfIM( XIMOfIC(maContext) );
     423             : 
     424             :         XGetWindowAttributes( pDisplay, aFocusWindow,
     425           0 :                               &aWindowAttributes );
     426             :         XGetICValues ( maContext,
     427             :                        XNFilterEvents, &nIMEventMask,
     428           0 :                        NULL);
     429           0 :         nIMEventMask |= aWindowAttributes.your_event_mask;
     430           0 :         XSelectInput ( pDisplay, aFocusWindow, nIMEventMask );
     431             :     }
     432           0 : }
     433             : 
     434             : // tune the styles provided by the input method with the supported one
     435             : 
     436             : unsigned int
     437           0 : SalI18N_InputContext::GetWeightingOfIMStyle( XIMStyle nStyle ) const
     438             : {
     439             :     struct StyleWeightingT {
     440             :         const XIMStyle      nStyle;
     441             :         const unsigned int  nWeight;
     442             :     };
     443             : 
     444             :     StyleWeightingT const *pWeightPtr;
     445             :     const StyleWeightingT pWeight[] = {
     446             :         { XIMPreeditCallbacks, 0x10000000 },
     447             :         { XIMPreeditPosition,  0x02000000 },
     448             :         { XIMPreeditArea,      0x01000000 },
     449             :         { XIMPreeditNothing,   0x00100000 },
     450             :         { XIMPreeditNone,      0x00010000 },
     451             :         { XIMStatusCallbacks,      0x1000 },
     452             :         { XIMStatusArea,           0x0100 },
     453             :         { XIMStatusNothing,        0x0010 },
     454             :         { XIMStatusNone,           0x0001 },
     455             :         { 0, 0x0 }
     456           0 :     };
     457             : 
     458           0 :     int nWeight = 0;
     459           0 :     for ( pWeightPtr = pWeight; pWeightPtr->nStyle != 0; pWeightPtr++ )
     460             :     {
     461           0 :         if ( (pWeightPtr->nStyle & nStyle) != 0 )
     462           0 :             nWeight += pWeightPtr->nWeight;
     463             :     }
     464           0 :     return nWeight;
     465             : }
     466             : 
     467             : Bool
     468           0 : SalI18N_InputContext::IsSupportedIMStyle( XIMStyle nStyle ) const
     469             : {
     470           0 :     if (   (nStyle & mnSupportedPreeditStyle)
     471           0 :            && (nStyle & mnSupportedStatusStyle) )
     472             :     {
     473           0 :         return True;
     474             :     }
     475           0 :     return False;
     476             : }
     477             : 
     478             : bool
     479           0 : SalI18N_InputContext::SupportInputMethodStyle( XIMStyles *pIMStyles )
     480             : {
     481           0 :     mnPreeditStyle = 0;
     482           0 :     mnStatusStyle  = 0;
     483             : 
     484           0 :     if ( pIMStyles != NULL )
     485             :     {
     486           0 :         int nBestScore   = 0;
     487           0 :         int nActualScore = 0;
     488             : 
     489             :         // check whether the XIM supports one of the desired styles
     490             :         // only a single preedit and a single status style must occur
     491             :         // in a inpuut method style. Hideki said so, so i trust him
     492           0 :         for ( int nStyle = 0; nStyle < pIMStyles->count_styles; nStyle++ )
     493             :         {
     494           0 :             XIMStyle nProvidedStyle = pIMStyles->supported_styles[ nStyle ];
     495           0 :             if ( IsSupportedIMStyle(nProvidedStyle) )
     496             :             {
     497           0 :                 nActualScore = GetWeightingOfIMStyle( nProvidedStyle );
     498           0 :                 if ( nActualScore >= nBestScore )
     499             :                 {
     500           0 :                     nBestScore = nActualScore;
     501           0 :                     mnPreeditStyle = nProvidedStyle & mnSupportedPreeditStyle;
     502           0 :                     mnStatusStyle  = nProvidedStyle & mnSupportedStatusStyle;
     503             :                 }
     504             :             }
     505             :         }
     506             :     }
     507             : 
     508             : #if OSL_DEBUG_LEVEL > 1
     509             :     char pBuf[ 128 ];
     510             :     fprintf( stderr, "selected inputmethod style = %s\n",
     511             :              GetMethodName(mnPreeditStyle | mnStatusStyle, pBuf, sizeof(pBuf)) );
     512             : #endif
     513             : 
     514           0 :     return (mnPreeditStyle != 0) && (mnStatusStyle != 0) ;
     515             : }
     516             : 
     517             : // handle extended and normal key input
     518             : 
     519             : int
     520           0 : SalI18N_InputContext::CommitKeyEvent(sal_Unicode* pText, sal_Size nLength)
     521             : {
     522           0 :     if (nLength == 1 && IsControlCode(pText[0]))
     523           0 :         return 0;
     524             : 
     525           0 :     if( maClientData.pFrame )
     526             :     {
     527           0 :         SalExtTextInputEvent aTextEvent;
     528             : 
     529           0 :         aTextEvent.mnTime        = 0;
     530           0 :         aTextEvent.mpTextAttr    = 0;
     531           0 :         aTextEvent.mnCursorPos   = nLength;
     532           0 :         aTextEvent.maText        = OUString(pText, nLength);
     533           0 :         aTextEvent.mnCursorFlags = 0;
     534           0 :         aTextEvent.mbOnlyCursor  = False;
     535             : 
     536           0 :         maClientData.pFrame->CallCallback(SALEVENT_EXTTEXTINPUT,    (void*)&aTextEvent);
     537           0 :         maClientData.pFrame->CallCallback(SALEVENT_ENDEXTTEXTINPUT, (void*)NULL);
     538             :     }
     539             : #if OSL_DEBUG_LEVEL > 1
     540             :     else
     541             :         fprintf(stderr, "CommitKeyEvent without frame\n" );
     542             : #endif
     543             : 
     544           0 :     return 0;
     545             : }
     546             : 
     547             : int
     548           0 : SalI18N_InputContext::UpdateSpotLocation()
     549             : {
     550           0 :     if (maContext == 0 || maClientData.pFrame == NULL)
     551           0 :         return -1;
     552             : 
     553           0 :     SalExtTextInputPosEvent aPosEvent;
     554           0 :     maClientData.pFrame->CallCallback(SALEVENT_EXTTEXTINPUTPOS, (void*)&aPosEvent);
     555             : 
     556             :     XPoint aSpot;
     557           0 :     aSpot.x = aPosEvent.mnX + aPosEvent.mnWidth;
     558           0 :     aSpot.y = aPosEvent.mnY + aPosEvent.mnHeight;
     559             : 
     560           0 :     XVaNestedList preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &aSpot, NULL);
     561           0 :     XSetICValues(maContext, XNPreeditAttributes, preedit_attr, NULL);
     562           0 :     XFree(preedit_attr);
     563             : 
     564           0 :     I18NStatus::get().show( true, I18NStatus::contextmap );
     565             : 
     566           0 :     return 0;
     567             : }
     568             : 
     569             : // set and unset the focus for the Input Context
     570             : // the context may be NULL despite it is useable if the framewindow is
     571             : // in unmapped state
     572             : 
     573             : void
     574           0 : SalI18N_InputContext::SetICFocus( SalFrame* pFocusFrame )
     575             : {
     576           0 :     I18NStatus::get().setParent( pFocusFrame );
     577           0 :     if ( mbUseable && (maContext != NULL)  )
     578             :     {
     579           0 :         maClientData.pFrame = pFocusFrame;
     580             : 
     581           0 :         const SystemEnvData* pEnv   = pFocusFrame->GetSystemData();
     582           0 :         XLIB_Window  aClientWindow  = pEnv->aShellWindow;
     583           0 :         XLIB_Window  aFocusWindow   = pEnv->aWindow;
     584             : 
     585             :         XSetICValues( maContext,
     586             :                       XNFocusWindow,       aFocusWindow,
     587             :                       XNClientWindow,      aClientWindow,
     588           0 :                       NULL );
     589             : 
     590           0 :         if( maClientData.aInputEv.mpTextAttr )
     591             :         {
     592           0 :             sendEmptyCommit(pFocusFrame);
     593             :             // begin preedit again
     594           0 :             GetGenericData()->GetSalDisplay()->SendInternalEvent( pFocusFrame, &maClientData.aInputEv, SALEVENT_EXTTEXTINPUT );
     595             :         }
     596             : 
     597           0 :         XSetICFocus( maContext );
     598             :     }
     599           0 : }
     600             : 
     601             : void
     602           0 : SalI18N_InputContext::UnsetICFocus( SalFrame* pFrame )
     603             : {
     604           0 :     I18NStatus& rStatus( I18NStatus::get() );
     605           0 :     if( rStatus.getParent() == pFrame )
     606           0 :         rStatus.setParent( NULL );
     607             : 
     608           0 :     if ( mbUseable && (maContext != NULL) )
     609             :     {
     610             :         // cancel an eventual event posted to begin preedit again
     611           0 :         GetGenericData()->GetSalDisplay()->CancelInternalEvent( maClientData.pFrame, &maClientData.aInputEv, SALEVENT_EXTTEXTINPUT );
     612           0 :         maClientData.pFrame = NULL;
     613           0 :         XUnsetICFocus( maContext );
     614             :     }
     615           0 : }
     616             : 
     617             : // multi byte input method only
     618             : 
     619             : void
     620           0 : SalI18N_InputContext::SetLanguage(LanguageType)
     621             : {
     622             :     // not yet implemented
     623           0 :     return;
     624             : }
     625             : 
     626             : void
     627           0 : SalI18N_InputContext::EndExtTextInput( sal_uInt16 /*nFlags*/ )
     628             : {
     629           0 :     if ( mbUseable && (maContext != NULL) && maClientData.pFrame )
     630             :     {
     631           0 :         vcl::DeletionListener aDel( maClientData.pFrame );
     632             :         // delete preedit in sal (commit an empty string)
     633           0 :         sendEmptyCommit( maClientData.pFrame );
     634           0 :         if( ! aDel.isDeleted() )
     635             :         {
     636             :             // mark previous preedit state again (will e.g. be sent at focus gain)
     637           0 :             maClientData.aInputEv.mpTextAttr = &maClientData.aInputFlags[0];
     638           0 :             if( static_cast<X11SalFrame*>(maClientData.pFrame)->hasFocus() )
     639             :             {
     640             :                 // begin preedit again
     641           0 :                 GetGenericData()->GetSalDisplay()->SendInternalEvent( maClientData.pFrame, &maClientData.aInputEv, SALEVENT_EXTTEXTINPUT );
     642             :             }
     643           0 :         }
     644             :     }
     645           0 : }
     646             : 
     647             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10