| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615 |
- /*
- ** Command & Conquer Generals(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- //----------------------------------------------------------------------------
- //
- // Westwood Studios Pacific.
- //
- // Confidential Information
- // Copyright (C) 2001 - All Rights Reserved
- //
- //----------------------------------------------------------------------------
- //
- // Project: Ganerals
- //
- // Module: IME
- //
- // File name: IMEManager.cpp
- //
- // Created: 11/14/01 TR
- //
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Includes
- //----------------------------------------------------------------------------
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- #include "Windows.h"
- #include "mbstring.h"
- #include "Common/Debug.h"
- #include "Common/Language.h"
- #include "Common/UnicodeString.h"
- #include "GameClient/Display.h"
- #include "GameClient/GameWindow.h"
- #include "GameClient/GameWindowManager.h"
- #include "GameClient/GadgetListBox.h"
- #include "GameClient/IMEManager.h"
- #include "GameClient/Mouse.h"
- #include "GameClient/Color.h"
- #include "Common/NameKeyGenerator.h"
- #ifdef _INTERNAL
- // for occasional debugging...
- //#pragma optimize("", off)
- //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
- #endif
- //----------------------------------------------------------------------------
- // Externals
- //----------------------------------------------------------------------------
- extern HWND ApplicationHWnd; ///< our application window handle
- extern Int IMECandidateWindowLineSpacing;
- //----------------------------------------------------------------------------
- // Defines
- //----------------------------------------------------------------------------
- //#define DEBUG_IME
- //----------------------------------------------------------------------------
- // Private Types
- //----------------------------------------------------------------------------
- //===============================
- // IMEManager
- //===============================
- class IMEManager : public IMEManagerInterface
- {
- public:
- IMEManager();
- ~IMEManager();
-
- virtual void init( void );
- virtual void reset( void );
- virtual void update( void );
-
- virtual void attach( GameWindow *window ); ///< attach IME to specified window
- virtual void detatch( void ); ///< detatch IME from current window
- virtual void enable( void ); ///< Enable IME
- virtual void disable( void ); ///< Disable IME
- virtual Bool isEnabled( void ); ///< Is IME enabled
- virtual Bool isAttachedTo( GameWindow *window ); ///< Is the manager attached toa window
- virtual GameWindow* getWindow( void ); ///< Returns the window we are currently attached to
- virtual Bool isComposing( void ); ///< Manager is currently composing new input string
- virtual void getCompositionString( UnicodeString &string ); ///< Return the current composition string
- virtual Int getCompositionCursorPosition( void ); ///< Returns the composition cursor position
- virtual Int getIndexBase( void ); ///< Get index base for candidate list
- virtual Int getCandidateCount(); ///< Returns the total number of candidates
- virtual UnicodeString*getCandidate( Int index ); ///< Returns the candidate string
- virtual Int getSelectedCandidateIndex(); ///< Returns the indexed of the currently selected candidate
- virtual Int getCandidatePageSize(); ///< Returns the page size for the candidates list
- virtual Int getCandidatePageStart(); ///< Returns the index of the first visibel candidate
- /// Checks for and services IME messages. Returns TRUE if message serviced
- virtual Bool serviceIMEMessage( void *windowsHandle,
- UnsignedInt message,
- Int wParam,
- Int lParam );
- virtual Int result( void ); ///< result return value of last serviced IME message
- protected:
- enum
- {
- MAX_COMPSTRINGLEN = 2*1024
- };
- struct MessageInfo
- {
- Char *name;
- Int value;
- };
- Int m_result; ///< last IME message's winProc return code
- GameWindow *m_window; ///< window we are accepting input for
- HIMC m_context; ///< Imput Manager Context
- HIMC m_oldContext; ///< Previous IME comtext
- Int m_disabled; ///< IME disable count 0 = enabled
- Bool m_composing; ///< Are we currently composing a new string
- WideChar m_compositionString[MAX_COMPSTRINGLEN+1];
- WideChar m_resultsString[MAX_COMPSTRINGLEN+1];
- Int m_compositionCursorPos;
- Int m_compositionStringLength;
- Int m_indexBase;
- Int m_pageStart; ///< index of first visible candidate
- Int m_pageSize; ///< Number of candidate per page
- Int m_selectedIndex; ///< Index of the currently selected candidate
- Int m_candidateCount; ///< Total number of candidate strings
- UnicodeString *m_candidateString; ///< table of canidate strings
- Bool m_unicodeIME; ///< Is this an unicode IME
- Int m_compositionCharsDisplayed; ///< number of temporary composition characters displayed that need to be replaced with result string.
- WideChar convertCharToWide( WPARAM mbchar ); ///< Convert multibyte character to wide
- void updateCompositionString( void ); ///< Update the context of the composition string from the IMM
- void getResultsString( void ); ///< Get the final composition string result
- void updateProperties( void ); ///< Read the current IME properties
- void openCandidateList( Int candidateFlags ); ///< open candidate window
- void closeCandidateList( Int candidateFlags ); ///< Close candidate window
- void updateCandidateList( Int candidateFlags ); ///< Update candidate window
- void updateListBox( CANDIDATELIST *candidateList ); ///< Update candidate list box gadget
- void convertToUnicode( Char *mbcs, UnicodeString &unicode );
- void resizeCandidateWindow( Int pageSize );
- void openStatusWindow( void );
- void closeStatusWindow( void );
- void updateStatusWindow( void );
- GameWindow *m_candidateWindow; ///< IME candidate window interface
- GameWindow *m_statusWindow; ///< IME status window interface
- GameWindow *m_candidateTextArea; ///< list box area
- GameWindow *m_candidateUpArrow; ///< up arrow
- GameWindow *m_candidateDownArrow; ///< down arrow
- #ifdef DEBUG_IME
- static MessageInfo m_mainMessageInfo[];
- static MessageInfo m_notifyInfo[];
- static MessageInfo m_requestInfo[];
- static MessageInfo m_controlInfo[];
- static MessageInfo m_setContextInfo[];
- static MessageInfo m_setCmodeInfo[];
- static MessageInfo m_setSmodeInfo[];
- Char* getMessageName( MessageInfo *msgTable, Int value );
- void buildFlagsString( IMEManager::MessageInfo *msgTable, Int value, AsciiString &string );
- void printMessageInfo( Int message, Int wParam, Int lParam );
- void printConversionStatus( void );
- void printSentenceStatus( void );
- #endif
- };
- //----------------------------------------------------------------------------
- // Private Data
- //----------------------------------------------------------------------------
- #ifdef DEBUG_IME
- IMEManager::MessageInfo IMEManager::m_mainMessageInfo[] =
- {
- { "WM_IME_SETCONTEXT" , WM_IME_SETCONTEXT },
- { "WM_IME_NOTIFY" , WM_IME_NOTIFY },
- { "WM_IME_CONTROL" , WM_IME_CONTROL },
- { "WM_IME_COMPOSITIONFULL" , WM_IME_COMPOSITIONFULL },
- { "WM_IME_SELECT" , WM_IME_SELECT },
- { "WM_IME_CHAR" , WM_IME_CHAR },
- #ifdef WM_IME_REQUST
- { "WM_IME_REQUEST" , WM_IME_REQUEST },
- #endif
- { "WM_IME_KEYDOWN" , WM_IME_KEYDOWN },
- { "WM_IME_KEYUP" , WM_IME_KEYUP },
- { "WM_IME_STARTCOMPOSITION" , WM_IME_STARTCOMPOSITION},
- { "WM_IME_ENDCOMPOSITION" , WM_IME_ENDCOMPOSITION },
- { "WM_IME_COMPOSITION" , WM_IME_COMPOSITION },
- { "WM_IME_KEYLAST" , WM_IME_KEYLAST },
- { NULL, 0 }
- };
- IMEManager::MessageInfo IMEManager::m_notifyInfo[] =
- {
- { "IMN_CLOSESTATUSWINDOW" , IMN_CLOSESTATUSWINDOW },
- { "IMN_OPENSTATUSWINDOW" , IMN_OPENSTATUSWINDOW },
- { "IMN_CHANGECANDIDATE" , IMN_CHANGECANDIDATE },
- { "IMN_CLOSECANDIDATE" , IMN_CLOSECANDIDATE },
- { "IMN_OPENCANDIDATE" , IMN_OPENCANDIDATE },
- { "IMN_SETCONVERSIONMODE" , IMN_SETCONVERSIONMODE },
- { "IMN_SETSENTENCEMODE" , IMN_SETSENTENCEMODE },
- { "IMN_SETOPENSTATUS" , IMN_SETOPENSTATUS },
- { "IMN_SETCANDIDATEPOS" , IMN_SETCANDIDATEPOS },
- { "IMN_SETCOMPOSITIONFONT" , IMN_SETCOMPOSITIONFONT },
- { "IMN_SETCOMPOSITIONWINDOW" , IMN_SETCOMPOSITIONWINDOW},
- { "IMN_SETSTATUSWINDOWPOS" , IMN_SETSTATUSWINDOWPOS },
- { "IMN_GUIDELINE" , IMN_GUIDELINE },
- { "IMN_PRIVATE" , IMN_PRIVATE },
- { NULL, 0 }
- };
- IMEManager::MessageInfo IMEManager::m_requestInfo[] =
- {
- #ifdef WM_IME_REQUST
- { "IMR_COMPOSITIONWINDOW" , IMR_COMPOSITIONWINDOW },
- { "IMR_CANDIDATEWINDOW" , IMR_CANDIDATEWINDOW },
- { "IMR_COMPOSITIONFONT" , IMR_COMPOSITIONFONT },
- { "IMR_RECONVERTSTRING" , IMR_RECONVERTSTRING },
- { "IMR_CONFIRMRECONVERTSTRING" , IMR_CONFIRMRECONVERTSTRING},
- #endif
- { NULL, 0 }
- };
- IMEManager::MessageInfo IMEManager::m_controlInfo[] =
- {
- { "IMC_GETCANDIDATEPOS" , IMC_GETCANDIDATEPOS },
- { "IMC_SETCANDIDATEPOS " , IMC_SETCANDIDATEPOS },
- { "IMC_GETCOMPOSITIONFONT" , IMC_GETCOMPOSITIONFONT },
- { "IMC_SETCOMPOSITIONFONT" , IMC_SETCOMPOSITIONFONT },
- { "IMC_GETCOMPOSITIONWINDOW" , IMC_GETCOMPOSITIONWINDOW},
- { "IMC_SETCOMPOSITIONWINDOW" , IMC_SETCOMPOSITIONWINDOW},
- { "IMC_GETSTATUSWINDOWPOS" , IMC_GETSTATUSWINDOWPOS },
- { "IMC_SETSTATUSWINDOWPOS" , IMC_SETSTATUSWINDOWPOS },
- { "IMC_CLOSESTATUSWINDOW" , IMC_CLOSESTATUSWINDOW },
- { "IMC_OPENSTATUSWINDOW" , IMC_OPENSTATUSWINDOW },
- { NULL, 0 }
- };
- IMEManager::MessageInfo IMEManager::m_setContextInfo[] =
- {
- { "CANDIDATEWINDOW1" , ISC_SHOWUICANDIDATEWINDOW },
- { "CANDIDATEWINDOW2" , ISC_SHOWUICANDIDATEWINDOW<<1 },
- { "CANDIDATEWINDOW3" , ISC_SHOWUICANDIDATEWINDOW<<2 },
- { "CANDIDATEWINDOW4" , ISC_SHOWUICANDIDATEWINDOW<<3 },
- { "COMPOSITIONWINDOW" , ISC_SHOWUICOMPOSITIONWINDOW },
- { "GUIDELINE" , ISC_SHOWUIGUIDELINE },
- { NULL, 0 }
- };
- IMEManager::MessageInfo IMEManager::m_setCmodeInfo[] =
- {
- { "ALPHANUMERIC" , IME_CMODE_ALPHANUMERIC},
- { "NATIVE" , IME_CMODE_NATIVE },
- { "KATAKANA" , IME_CMODE_KATAKANA },
- { "LANGUAGE" , IME_CMODE_LANGUAGE },
- { "FULLSHAPE" , IME_CMODE_FULLSHAPE },
- { "ROMAN" , IME_CMODE_ROMAN },
- { "CHARCODE" , IME_CMODE_CHARCODE },
- { "HANJACONVERT" , IME_CMODE_HANJACONVERT},
- { "SOFTKBD" , IME_CMODE_SOFTKBD },
- { "NOCONVERSION" , IME_CMODE_NOCONVERSION},
- { "EUDC" , IME_CMODE_EUDC },
- { "SYMBOL" , IME_CMODE_SYMBOL },
- { "FIXED" , IME_CMODE_FIXED },
- { NULL, 0 }
- };
- IMEManager::MessageInfo IMEManager::m_setSmodeInfo[] =
- {
- { "NONE" , IME_SMODE_NONE },
- { "PLAURALCLAUSE" , IME_SMODE_PLAURALCLAUSE},
- { "SINGLECONVERT" , IME_SMODE_SINGLECONVERT},
- { "AUTOMATIC" , IME_SMODE_AUTOMATIC },
- { "PHRASEPREDICT" , IME_SMODE_PHRASEPREDICT},
- { "CONVERSATION" , IME_SMODE_CONVERSATION },
- { NULL, 0 }
- };
- #endif
- //----------------------------------------------------------------------------
- // Public Data
- //----------------------------------------------------------------------------
- IMEManagerInterface *TheIMEManager = NULL;
- //----------------------------------------------------------------------------
- // Private Prototypes
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Private Functions
- //----------------------------------------------------------------------------
- #ifdef DEBUG_IME
- //============================================================================
- // IMEManager::getMessageName
- //============================================================================
- Char* IMEManager::getMessageName( IMEManager::MessageInfo *msgTable, Int value )
- {
- Char *name = NULL;
- if ( msgTable )
- {
- while ( msgTable->name )
- {
- if ( msgTable->value == value )
- {
- name = msgTable->name;
- break;
- }
- msgTable++;
- }
- }
- return name;
- }
- //============================================================================
- // IMEManager::buildFlagsString
- //============================================================================
- void IMEManager::buildFlagsString( IMEManager::MessageInfo *msgTable, Int value, AsciiString &string )
- {
- string.clear();
- Bool first = TRUE;
- if ( msgTable )
- {
- while ( msgTable->name )
- {
- if ( msgTable->value & value )
- {
- if ( !first )
- {
- string.concat( "|" );
- first = FALSE;
- }
- string.concat( msgTable->name );
- }
- msgTable++;
- }
- }
- }
- //============================================================================
- // IMEManager::printMessageInfo
- //============================================================================
- void IMEManager::printMessageInfo( Int message, Int wParam, Int lParam )
- {
- Char *messageText = getMessageName( m_mainMessageInfo, message);
- switch( message )
- {
- case WM_IME_NOTIFY:
- {
- Char *notifyName = getMessageName( m_notifyInfo, wParam );
- if ( notifyName == NULL ) notifyName = "unknown";
- DEBUG_LOG(( "IMM: %s(0x%04x) - %s(0x%04x) - 0x%08x\n", messageText, message, notifyName, wParam, lParam ));
- break;
- }
- case WM_IME_CONTROL:
- {
- Char *controlName = getMessageName( m_controlInfo, wParam );
- if ( controlName == NULL ) controlName = "unknown";
- DEBUG_LOG(( "IMM: %s(0x%04x) - %s(0x%04x) - 0x%08x\n", messageText, message, controlName, wParam, lParam ));
- break;
- }
- #ifdef WM_IME_REQUEST
- case WM_IME_REQUEST:
- {
- Char *requestName = getMessageName( m_requestInfo, wParam );
- if ( requestName == NULL ) requestName = "unknown";
- DEBUG_LOG(( "IMM: %s(0x%04x) - %s(0x%04x) - 0x%08x\n", messageText, message, requestName, wParam, lParam ));
- break;
- }
- #endif
- case WM_IME_SETCONTEXT:
- {
- AsciiString flags;
- buildFlagsString( m_setContextInfo, lParam, flags );
- DEBUG_LOG(( "IMM: %s(0x%04x) - 0x%08x - %s(0x%04x)\n", messageText, message, wParam, flags.str(), lParam ));
- break;
- }
- default:
- if ( messageText )
- {
- DEBUG_LOG(( "IMM: %s(0x%04x) - 0x%08x - 0x%08x\n", messageText, message, wParam, lParam ));
- }
- break;
- }
- }
- //============================================================================
- // IMEManager::printConversionStatus
- //============================================================================
- void IMEManager::printConversionStatus( void )
- {
- DWORD mode;
- if ( m_context )
- {
- ImmGetConversionStatus( m_context, &mode, NULL );
- AsciiString flags;
- buildFlagsString( m_setCmodeInfo, mode, flags );
- DEBUG_LOG(( "IMM: Conversion mode = (%s)\n", flags.str()));
- }
- }
- //============================================================================
- // IMEManager::printSentenceStatus
- //============================================================================
- void IMEManager::printSentenceStatus( void )
- {
- DWORD mode;
- if ( m_context )
- {
- ImmGetConversionStatus( m_context, NULL, &mode );
- AsciiString flags;
- buildFlagsString( m_setSmodeInfo, mode, flags );
- DEBUG_LOG(( "IMM: Sentence mode = (%s)\n", flags.str()));
- }
- }
- #endif // DEBUG_IME
- //----------------------------------------------------------------------------
- // Public Functions
- //----------------------------------------------------------------------------
- //============================================================================
- // *CreateIMEManagerInterface
- //============================================================================
- IMEManagerInterface *CreateIMEManagerInterface( void )
- {
- return NEW IMEManager;
- }
- //============================================================================
- // IMEManager::IMEManager
- //============================================================================
- IMEManager::IMEManager()
- : m_window(NULL),
- m_context(NULL),
- m_candidateWindow(NULL),
- m_statusWindow(NULL),
- m_candidateCount(0),
- m_candidateString(NULL),
- m_compositionStringLength(0),
- m_composing(FALSE),
- m_disabled(0),
- m_result(0),
- m_indexBase(1),
- //Added By Sadullah Nader
- //Initializations missing and needed
- m_compositionCharsDisplayed(0),
- m_candidateDownArrow(NULL),
- m_candidateTextArea(NULL),
- m_candidateUpArrow(NULL),
- m_compositionCursorPos(0),
- m_pageSize(0),
- m_pageStart(0),
- m_selectedIndex(0),
- m_unicodeIME(FALSE)
- //
- {
- }
- //============================================================================
- // IMEManager::~IMEManager
- //============================================================================
- IMEManager::~IMEManager()
- {
- if ( m_candidateWindow )
- {
- TheWindowManager->winDestroy( m_candidateWindow );
- }
- if ( m_statusWindow )
- {
- TheWindowManager->winDestroy( m_statusWindow );
- }
- if ( m_candidateString )
- {
- delete [] m_candidateString;
- }
- detatch();
- ImmAssociateContext( ApplicationHWnd, m_oldContext );
- ImmReleaseContext( ApplicationHWnd, m_oldContext );
- if ( m_context )
- {
- ImmDestroyContext( m_context );
- }
- }
- //============================================================================
- // IMEManager::init
- //============================================================================
- void IMEManager::init( void )
- {
- //HWND ImeWindow = ImmGetDefaultIMEWnd(ApplicationHWnd);
- // if(ImeWindow)
- // {
- // DestroyWindow(ImeWindow);
- // }
- m_context = ImmCreateContext();
- m_oldContext = ImmGetContext( ApplicationHWnd );
- m_disabled = 0;
- m_candidateWindow = TheWindowManager->winCreateFromScript( AsciiString("IMECandidateWindow.wnd"));
- m_candidateWindow->winSetStatus(WIN_STATUS_ABOVE);
-
- if ( m_candidateWindow )
- {
- m_candidateWindow->winHide( TRUE );
- // find text area window
- NameKeyType id = TheNameKeyGenerator->nameToKey( AsciiString( "IMECandidateWindow.wnd:TextArea" ) );
- m_candidateTextArea = TheWindowManager->winGetWindowFromId(m_candidateWindow, id);
- // find arrows
- id = TheNameKeyGenerator->nameToKey( AsciiString( "IMECandidateWindow.wnd:UpArrow" ) );
- m_candidateUpArrow = TheWindowManager->winGetWindowFromId(m_candidateWindow, id);
- id = TheNameKeyGenerator->nameToKey( AsciiString( "IMECandidateWindow.wnd:DownArrow" ) );
- m_candidateDownArrow = TheWindowManager->winGetWindowFromId(m_candidateWindow, id);
- if ( m_candidateTextArea == NULL )
- {
- TheWindowManager->winDestroy( m_candidateWindow );
- m_candidateWindow = NULL;
- }
- }
- m_statusWindow = TheWindowManager->winCreateFromScript( AsciiString("IMEStatusWindow.wnd"));
- if ( m_statusWindow )
- {
- m_statusWindow->winHide( TRUE );
- }
- // attach IMEManager to each window
- if ( m_candidateWindow != NULL )
- {
- m_candidateWindow->winSetUserData( TheIMEManager );
- m_candidateTextArea->winSetUserData( TheIMEManager );
- }
- detatch();
- enable();
- }
- //============================================================================
- // IMEManager::reset
- //============================================================================
- void IMEManager::reset( void )
- {
- }
- //============================================================================
- // IMEManager::update
- //============================================================================
- void IMEManager::update( void )
- {
- }
-
- //============================================================================
- // IMEManager::attach
- //============================================================================
- void IMEManager::attach( GameWindow *window )
- {
- if ( m_window != window )
- {
- detatch();
- if ( m_disabled == 0 )
- {
- ImmAssociateContext( ApplicationHWnd, m_context );
- updateStatusWindow();
- //openStatusWindow();
- }
- m_window = window;
- }
- }
- //============================================================================
- // IMEManager::detatch
- //============================================================================
- void IMEManager::detatch( void )
- {
- //ImmAssociateContext( ApplicationHWnd, NULL );
- m_window = NULL;
- }
- //============================================================================
- // IMEManager::serviceIMEMessage
- //============================================================================
- Bool IMEManager::serviceIMEMessage( void *windowsHandle, UnsignedInt message, Int wParam, Int lParam )
- {
- DEBUG_ASSERTCRASH( windowsHandle == ApplicationHWnd, ("Unexpected window handle for IMEManager") );
- #ifdef DEBUG_IME
- printMessageInfo( message, wParam, lParam );
- #endif
- switch(message){
- // --------------------------------------------------------------------
- case WM_IME_CHAR:
- {
- WideChar wchar = convertCharToWide(wParam);
- #ifdef DEBUG_IME
- DEBUG_LOG(("IMM: WM_IME_CHAR - '%hc'0x%04x\n", wchar, wchar ));
- #endif
-
- if ( m_window && (wchar > 32 || wchar == VK_RETURN ))
- {
- TheWindowManager->winSendInputMsg( m_window, GWM_IME_CHAR, (wParam & 0xffff), lParam );
- m_result = 0;
- return TRUE;
- }
- return FALSE;
- }
- // --------------------------------------------------------------------
- case WM_CHAR:
- {
- WideChar wchar = (WideChar) (wParam & 0xffff);
- #ifdef DEBUG_IME
- DEBUG_LOG(("IMM: WM_CHAR - '%hc'0x%04x\n", wchar, wchar ));
- #endif
- if ( m_window && (wchar >= 32 || wchar == VK_RETURN) )
- {
- TheWindowManager->winSendInputMsg( m_window, GWM_IME_CHAR, (wParam & 0xffff), lParam );
- m_result = 0;
- return TRUE;
- }
- return FALSE;
- }
- // --------------------------------------------------------------------
- case WM_IME_SELECT:
- DEBUG_LOG(("IMM: WM_IME_SELECT\n"));
- return FALSE;
- case WM_IME_STARTCOMPOSITION:
- //The WM_IME_STARTCOMPOSITION message is sent immediately before an
- //IME generates a composition string as a result of a user's keystroke.
- //
- m_composing = TRUE;
- m_compositionCharsDisplayed = 0;
- updateCompositionString();
- m_result = 1;
- return TRUE;
- // --------------------------------------------------------------------
- case WM_IME_ENDCOMPOSITION:
- {
- //First remove the composition characters
- m_composing = FALSE;
- while (m_compositionCharsDisplayed > 0)
- { //if cursor has moved since start of composition, we need to move it back using backspace message
- TheWindowManager->winSendInputMsg( m_window, GWM_CHAR, KEY_BACKSPACE, KEY_STATE_DOWN);
- m_compositionCharsDisplayed--;
- }
- closeCandidateList(0);
- return TRUE;
- // I removed the rest of this message handler because we update
- // the strings real time inside WM_IME_COMPOSITION
- // instead of waiting for user to enter separator. -MW
- //IMEs send this message to the application when the IMEs' composition
- //windows have closed. Applications that display their own composition
- //characters should process this message. Other applications should
- //send the message to the application IME window or to DefWindowProc,
- //which will pass the message to the default IME window.
- //
- m_composing = FALSE; // reset this flag before calling GWM_IME_CHAR
- if ( m_window )
- {
- WideChar *ch = m_resultsString;
- getResultsString();
- while ( *ch )
- {
- TheWindowManager->winSendInputMsg( m_window, GWM_IME_CHAR, *ch, 0 );
- ch++;
- }
- }
- m_result = 1;
- return TRUE;
- }
- // --------------------------------------------------------------------
- case WM_IME_COMPOSITION:
- {
- //IMEs send this message to the application when they change composition
- //status in response to a keystroke. Applications that display their own
- //composition characters should process this message by calling
- //ImmGetCompositionString. Other applications should send the message to
- //the application IME window or to DefWindowProc, which will pass the
- //message to the default IME window.
- //
- //The WM_IME_COMPOSITION message is sent to an application when the IME
- //changes composition status as a result of a keystroke. An application
- //should process this message if it displays composition characters itself.
- //Otherwise, it should send the message to the IME window. This message
- //has no return value. wParam = DBCS character. lParam = change indicator.
- //
- if (lParam & GCS_RESULTSTR) //added to show instant updates as soon as a character is translated. -MW
- {
- if ( m_window )
- {
- m_composing = FALSE; // reset this flag before calling GWM_IME_CHAR
- while (m_compositionCharsDisplayed > 0)
- { //if cursor has moved since start of composition, we need to move it back using backspace message
- TheWindowManager->winSendInputMsg( m_window, GWM_CHAR, KEY_BACKSPACE, KEY_STATE_DOWN);
- m_compositionCharsDisplayed--;
- }
- WideChar *ch = m_resultsString;
- getResultsString();
- while ( *ch )
- {
- TheWindowManager->winSendInputMsg( m_window, GWM_IME_CHAR, *ch, 0 );
- ch++;
- }
- }
- m_compositionCharsDisplayed = 0;
- }
- else
- if (lParam & CS_INSERTCHAR && lParam & CS_NOMOVECARET)
- { //we are supposed to display the composition character without moving the cursor. (it's a candidate).
- if (m_window)
- {
- m_composing = FALSE; // reset this flag before calling GWM_IME_CHAR
- while (m_compositionCharsDisplayed > 0)
- { //if cursor has moved since start of composition, we need to move it back using backspace message
- TheWindowManager->winSendInputMsg( m_window, GWM_CHAR, KEY_BACKSPACE, KEY_STATE_DOWN);
- m_compositionCharsDisplayed--;
- }
- WideChar *ch = m_compositionString;
- updateCompositionString();
- while (*ch)
- {
- TheWindowManager->winSendInputMsg(m_window, GWM_IME_CHAR, *ch, 0 );
- ch++;
- m_compositionCharsDisplayed++;
- }
- m_composing = TRUE; // reset this flag before calling GWM_IME_CHAR
- }
- }
- else
- if (lParam & GCS_COMPSTR)
- { //we are supposed to display the composition character without moving the cursor. (it's a candidate).
- if (m_window)
- {
- m_composing = FALSE; // reset this flag before calling GWM_IME_CHAR
- while (m_compositionCharsDisplayed > 0)
- { //if cursor has moved since start of composition, we need to move it back using backspace message
- TheWindowManager->winSendInputMsg( m_window, GWM_CHAR, KEY_BACKSPACE, KEY_STATE_DOWN);
- m_compositionCharsDisplayed--;
- }
- WideChar *ch = m_compositionString;
- updateCompositionString();
- while (*ch)
- {
- TheWindowManager->winSendInputMsg(m_window, GWM_IME_CHAR, *ch, 0 );
- ch++;
- m_compositionCharsDisplayed++;
- }
- m_composing = TRUE; // reset this flag before calling GWM_IME_CHAR
- }
- }
- m_result = 1;
- return TRUE;
- }
- // --------------------------------------------------------------------
- case WM_IME_SETCONTEXT:
- {
- //The system sends this message to an application when one of the
- //application's windows is activated. Applications should respond by
- //calling ImmGetContext.
- //
- updateProperties();
- //ignore for now
- m_result = 0;
- return FALSE;
- }
- // --------------------------------------------------------------------
- case WM_IME_NOTIFY:
- {
- //IMEs generate this message to notify the application or the IME window
- //that the IME status has changed. The wParam value is a submessage that
- //specifies the nature of the change.
- //
- switch(wParam)
- {
- case IMN_OPENCANDIDATE:
- {
- //This message is sent to the application when an IME is about to
- //open the candidate window. An application should process this
- //message if it displays candidates. The application can retrieve
- //a list of candidates to display by using theImmGetCandidateList
- //function. The application receives this notification message through
- //the WM_IME_NOTIFY message.
- //
- // open candidate window
- openCandidateList( lParam );
- m_result = 1;
- return TRUE;
- }
- case IMN_CLOSECANDIDATE:
- {
- //This message is sent to the application when an IME is about to
- //close the candidate window. An application should process this
- //message if it displays candidates. The application receives this
- //notification message through the WM_IME_NOTIFY message.
- //
- closeCandidateList( lParam );
- m_result = 1;
- return TRUE;
- }
- case IMN_CHANGECANDIDATE:
- {
- //This message is sent to the application when an IME is about to
- //change the content of the candidate window. An application should
- //process this notification message if it displays candidates itself.
- //The application receives this notification message through the
- //WM_IME_NOTIFY message.
- //
- updateCandidateList( lParam );
- m_result = 1;
- return TRUE;
- }
- case IMN_GUIDELINE: //This message is sent when an IME is about to show an error message or other data.
- {
- // display error message
- m_result = 1;
- return FALSE;
- }
- case IMN_SETCONVERSIONMODE: //This message is sent when the conversion mode of the input context is updated.
- {
- #ifdef DEBUG_IME
- printConversionStatus();
- #endif
- return FALSE;
- }
- case IMN_SETSENTENCEMODE: //This message is sent when the sentence mode of the input context is updated.
- {
- #ifdef DEBUG_IME
- printSentenceStatus();
- #endif
- return FALSE;
- }
- /*
- // pass the reset on through to the installed IME
- case IMN_SETCANDIDATEPOS: //This message is sent when the IME is about to move the candidate window.
- case IMN_SETSTATUSWINDOWPOS: //This message is sent when the status window position in the input context is updated.
- return FALSE;
- case IMN_OPENSTATUSWINDOW: //This message is sent when an IME is about to create the status window.
- DEBUG_LOG(("Open Status Window"));
- return FALSE;
- case IMN_CLOSESTATUSWINDOW: //This message is sent to the application when an input method editor (IME) is about to close the status window.
- DEBUG_LOG(("Close Status Window"));
- return FALSE;
- case IMN_SETOPENSTATUS: //This message is sent when the open status of the input context is updated.
- case IMN_SETCOMPOSITIONFONT: //This message is sent when the font of the input context is updated.
- case IMN_SETCOMPOSITIONWINDOW: //This message is sent when the style or position of the composition window is updated.
- case IMN_PRIVATE: //This message is for your own use, it seems.
- */ default:
- m_result = 1;
- return TRUE;
- }
- break;
- }
- // --------------------------------------------------------------------
- case WM_IME_COMPOSITIONFULL:
- {
- //IMEs send this message to the application when they are unable to
- //extend the composition window to accommodate any more characters.
- //Applications should tell IMEs how to display the composition window
- //using the IMC_SETCOMPOSITIONWINDOW message.
- //
- //I'm not sure what to do here.
- m_result = 1;
- return TRUE;
- }
- }
- return FALSE;
- }
- //============================================================================
- // IMEManager::result
- //============================================================================
- Int IMEManager::result( void )
- {
- return m_result;
- }
- //============================================================================
- // IMEManager::enable
- //============================================================================
- void IMEManager::enable( void )
- {
- if ( --m_disabled <= 0 )
- {
- m_disabled = 0;
- ImmAssociateContext( ApplicationHWnd, m_context );
- }
- }
- //============================================================================
- // IMEManager::disable
- //============================================================================
- void IMEManager::disable( void )
- {
- m_disabled++;
- ImmAssociateContext( ApplicationHWnd, NULL );
- }
- //============================================================================
- // IMEManager::isEnabled
- //============================================================================
- Bool IMEManager::isEnabled( void )
- {
- return m_context != NULL && m_disabled == 0;
- }
- //============================================================================
- // IMEManager::isAttached
- //============================================================================
- Bool IMEManager::isAttachedTo( GameWindow *window )
- {
- return m_window == window;
- }
- //============================================================================
- // IMEManager::getWindow
- //============================================================================
- GameWindow* IMEManager::getWindow( void )
- {
- return m_window;
- }
- //============================================================================
- // IMEManager::convertChartoWide
- //============================================================================
- WideChar IMEManager::convertCharToWide( WPARAM wParam )
- {
- char dcbsString[3];
- if ( wParam&0xff00 )
- {
- dcbsString[0] = (wParam>>8)&0xff;
- dcbsString[1] = wParam&0xff;
- dcbsString[2] = 0;
- }
- else
- {
- dcbsString[0] = wParam&0xff;
- dcbsString[1] = 0;
- }
- WideChar uniString[2];
- if ( MultiByteToWideChar( CP_ACP, 0, dcbsString, strlen( dcbsString ), uniString, 1 ) == 1 )
- {
- return uniString[0];
- }
- return 0;
- }
- //============================================================================
- // IMEManager::isComposing
- //============================================================================
- Bool IMEManager::isComposing( void )
- {
- return m_composing;
- }
- void IMEManager::getCompositionString ( UnicodeString &string )
- {
- string.set(m_compositionString);
- }
- //============================================================================
- // IMEManager::getCompositionCursorPosition
- //============================================================================
- Int IMEManager::getCompositionCursorPosition( void )
- {
- return 0;//m_compositionCursorPos;
- }
- //============================================================================
- // IMEManager::updateCompositionString
- //============================================================================
- void IMEManager::updateCompositionString( void )
- {
- char tempBuf[ (MAX_COMPSTRINGLEN+1)*2];
- m_compositionCursorPos = 0;
- m_compositionString[0] = 0;
- m_compositionStringLength = 0;
- if ( m_context )
- {
- // try reading unicode directy
- LONG result = ImmGetCompositionStringW( m_context, GCS_COMPSTR, m_compositionString, MAX_COMPSTRINGLEN );
- if ( result >= 0 )
- {
- m_compositionStringLength = result/2;
- m_compositionCursorPos = (ImmGetCompositionStringW( m_context, GCS_CURSORPOS, NULL, 0) & 0xffff );
- }
- else
- {
-
- // read MBCS instead
- result = ImmGetCompositionStringA( m_context, GCS_COMPSTR, tempBuf, MAX_COMPSTRINGLEN*2);
-
- if ( result > 0 )
- {
- tempBuf[ result ] = '\0';
-
- int convRes = MultiByteToWideChar( CP_ACP, 0, tempBuf, -1, m_compositionString, MAX_COMPSTRINGLEN );
- GameArrayEnd(m_compositionString);
-
- if ( convRes < 0)
- {
- convRes = 0;
- }
- else
- {
- m_compositionCursorPos = (ImmGetCompositionString( m_context, GCS_CURSORPOS, NULL, 0) & 0xffff );
- convRes = GameStrlen ( m_compositionString );
- }
-
- // m_compositionCursorPos is in DBCS characters, need to convert it to Wide characters
-
- //msg_assert ( (int)strlen(tempBuf) >= convRes ,("bad DBCS string: DBCS = %d chars, Wide = %d chars", strlen(tempBuf), convRes));
- m_compositionCursorPos = _mbsnccnt ( (unsigned char *) tempBuf, m_compositionCursorPos );
-
- m_compositionString[convRes] = 0;
- m_compositionStringLength = convRes;
- if ( m_compositionCursorPos > convRes )
- {
- m_compositionCursorPos = convRes;
- }
- else if ( m_compositionCursorPos < 0 )
- {
- m_compositionCursorPos = 0;
- }
- }
- }
- }
- DEBUG_ASSERTCRASH( m_compositionStringLength < MAX_COMPSTRINGLEN, ("composition string too large"));
- m_compositionString[m_compositionStringLength] = 0;
- GameArrayEnd(m_compositionString);
- }
- //============================================================================
- // IMEManager::getResultsString
- //============================================================================
- void IMEManager::getResultsString ( void )
- {
- Int stringLen = 0;
- m_resultsString[0] = 0;
- if ( m_context )
- {
- // try reading unicode directy
- LONG result = ImmGetCompositionStringW( m_context, GCS_RESULTSTR, m_resultsString, MAX_COMPSTRINGLEN );
- if ( result >= 0 )
- {
- stringLen = result/2;
- }
- else
- {
- char tempBuf[ (MAX_COMPSTRINGLEN+1)*2];
-
- // read MBCS instead
- result = ImmGetCompositionStringA( m_context, GCS_RESULTSTR, tempBuf, MAX_COMPSTRINGLEN*2);
-
- if ( result > 0 )
- {
- tempBuf[ result ] = '\0';
-
- int convRes = MultiByteToWideChar( CP_ACP, 0, tempBuf, strlen(tempBuf), m_resultsString, MAX_COMPSTRINGLEN );
-
- if ( convRes < 0)
- {
- convRes = 0;
- }
- stringLen = convRes;
- }
- }
- }
- DEBUG_ASSERTCRASH( stringLen < MAX_COMPSTRINGLEN, ("results string too large"));
- m_resultsString[stringLen] = 0;
- GameArrayEnd(m_resultsString);
- }
- //============================================================================
- // IMEManager::convertToUnicode
- //============================================================================
- void IMEManager::convertToUnicode ( Char *mbcs, UnicodeString &unicode )
- {
- int size = MultiByteToWideChar( CP_ACP, 0, mbcs, strlen(mbcs), NULL, 0 );
- unicode.clear();
- if ( size <= 0 )
- {
- return;
- }
- WideChar *buffer = NEW WideChar[ size + 1 ];
- if ( buffer )
- {
- size = MultiByteToWideChar( CP_ACP, 0, mbcs, strlen(mbcs), buffer, size );
-
- if ( size <= 0 )
- {
- unicode.clear();
- }
- else
- {
- buffer[size] = 0;
- unicode = buffer;
- }
- delete [] buffer;
- }
- }
- //============================================================================
- // IMEManager::openCandidateList
- //============================================================================
- void IMEManager::openCandidateList( Int candidateFlags )
- {
- if ( m_candidateWindow == NULL )
- {
- return;
- }
- // first get lastest candidate list info
- updateCandidateList( candidateFlags );
- resizeCandidateWindow( m_pageSize );
- m_candidateWindow->winHide( FALSE );
- m_candidateWindow->winBringToTop();
- TheWindowManager->winSetModal( m_candidateWindow );
- Int wx, wy, wwidth, wheight, wcursorx, wcursory;
- Int cx, cy, cwidth, cheight;
- Int textHeight = 20;
- if ( m_window )
- {
- m_window->winGetScreenPosition( &wx, &wy);
- m_window->winGetSize( &wwidth, &wheight );
- m_window->winGetCursorPosition( &wcursorx, &wcursory );
- GameFont *font = m_window->winGetFont();
- if ( font )
- {
- textHeight = font->height;
- }
- }
- else
- {
- wx = wy = 0;
- wwidth = 10;
- wheight = 10;
- wcursorx = 0;
- wcursory = 0;
- }
- m_candidateWindow->winGetSize( &cwidth, &cheight );
- // // try putting the candidate list above the text
- // cx = wx + wcursorx;
- // cy = wy - cheight;
- //
- // if ( cx + cwidth > (Int) TheDisplay->getWidth())
- // {
- // cx = cx - cwidth;
- // }
- // if( cx < 0 )
- // cx = 0;
- // if ( cy < 0 )
- // {
- // // place list below text
- // cy = wy + textHeight + textHeight/2;
- // }
- // if( cy + cheight > TheDisplay->getHeight())
- // cy = 0;
- cx = TheDisplay->getWidth() - cwidth;
- cy = 0;
- updateProperties();
- m_candidateWindow->winSetPosition( cx, cy );
- }
- //============================================================================
- // IMEManager::closeCandidateList
- //============================================================================
- void IMEManager::closeCandidateList( Int candidateFlags )
- {
- if ( m_candidateWindow != NULL )
- {
- m_candidateWindow->winHide( TRUE );
- TheWindowManager->winUnsetModal( m_candidateWindow );
- }
- if ( m_candidateString )
- {
- delete [] m_candidateString;
- m_candidateString = NULL;
- }
- m_candidateCount = 0;
- }
- //============================================================================
- // IMEManager::updateCandidateList
- //============================================================================
- void IMEManager::updateCandidateList( Int candidateFlags )
- {
- if ( m_candidateString )
- {
- delete [] m_candidateString;
- m_candidateString = NULL;
- }
- m_pageSize = 10;
- m_candidateCount = 0;
- m_pageStart = 0;
- m_selectedIndex = 0;
- if ( m_candidateWindow == NULL ||
- m_context == NULL ||
- candidateFlags == 0)
- {
- return;
- }
- for( Int i = 0, candidate = 1; i < 32; i++, candidate = candidate << 1 )
- {
- if ( candidateFlags & candidate )
- {
- Bool unicode = TRUE;
- unsigned long listCount = 0;
- Int size = ImmGetCandidateListCountW( m_context, &listCount );
- if ( size <= 0 )
- {
- unicode = FALSE;
- size = ImmGetCandidateListCountA( m_context, &listCount );
- if ( size <= 0 )
- {
- return;
- }
- }
-
- // create a temporary buffer for reading the candidate list
- Char *buffer = NEW Char[size];
-
- if ( buffer == NULL )
- {
- return;
- }
-
- memset( buffer, 0, size );
-
- CANDIDATELIST *clist = (CANDIDATELIST*) buffer;
- Bool ok = TRUE ;
- Int bytesCopied;
- if ( unicode )
- {
- bytesCopied = ImmGetCandidateListW( m_context, i, (CANDIDATELIST*) clist, size );
- }
- else
- {
- bytesCopied = ImmGetCandidateListA( m_context, i, (CANDIDATELIST*) clist, size );
- }
- if ( bytesCopied == 0 || bytesCopied > size )
- {
- DEBUG_ASSERTCRASH(bytesCopied < size,("IME candidate buffer overrun"));
- ok = FALSE;
- }
- if ( ok && clist->dwStyle != IME_CAND_UNKNOWN && clist->dwStyle != IME_CAND_CODE )
- {
- //Apparently there is an "IME98 bug" (IME bug under Windows 98?) that
- //causes you to have to execute the following code.
- if(( clist->dwPageStart > clist->dwSelection) ||
- (clist->dwSelection >= clist->dwPageStart + clist->dwPageSize))
- {
- clist->dwPageStart = (clist->dwSelection / clist->dwPageSize) * clist->dwPageSize;
- }
- m_pageSize = clist->dwPageSize;
- m_candidateCount = clist->dwCount;
- m_pageStart = clist->dwPageStart;
- m_selectedIndex = clist->dwSelection;
- #ifdef DEBUG_IME
- DEBUG_LOG(("IME: Candidate Update: Candidates = %d, pageSize = %d pageStart = %d, selected = %d\n", m_candidateCount, m_pageStart, m_pageSize, m_selectedIndex ));
- #endif
- if ( m_candidateUpArrow )
- {
- m_candidateUpArrow->winHide( m_pageStart == 0 );
- }
- if ( m_candidateDownArrow )
- {
- m_candidateDownArrow->winHide( m_candidateCount - m_pageStart <= m_pageSize );
- }
- if ( m_candidateCount > 0 )
- {
- m_candidateString = NEW UnicodeString[m_candidateCount];
- if ( m_candidateString )
- {
- Int i;
- for( i=0; i < m_candidateCount; i++ )
- {
- Char *string = (Char*) ((UnsignedInt) clist + (UnsignedInt) clist->dwOffset[i]);
- if ( unicode )
- {
- m_candidateString[i].set( (WideChar *) string);
- }
- else
- {
- convertToUnicode( string, m_candidateString[i] );
- }
- }
- }
- }
- }
- delete [] buffer;
- return;
- }
- }
- }
- //============================================================================
- // IMEManager::updateProperties
- //============================================================================
- void IMEManager::updateProperties( void )
- {
- HKL kb = GetKeyboardLayout( 0 );
- Int prop = ImmGetProperty( kb, IGP_PROPERTY );
- m_indexBase = prop & IME_PROP_CANDLIST_START_FROM_1 ? 1 : 0 ;
- m_unicodeIME = (prop & IME_PROP_UNICODE) != 0 ;
- }
- //============================================================================
- // IMEManager::getIndexBase
- //============================================================================
- Int IMEManager::getIndexBase( void )
- {
- return m_indexBase;
- }
- //============================================================================
- // IMEManager::resizeCandidateWindow
- //============================================================================
- void IMEManager::resizeCandidateWindow( Int pageSize )
- {
- if ( m_candidateWindow == NULL )
- {
- return;
- }
- GameFont *font = m_candidateTextArea->winGetFont();
- if ( font == NULL )
- {
- return;
- }
- Int newh = pageSize * (font->height + IMECandidateWindowLineSpacing);
- Int w, h;
- m_candidateTextArea->winGetSize( &w, &h );
- Int dif = newh - h;
- m_candidateTextArea->winSetSize( w, newh );
- m_candidateWindow->winGetSize( &w, &h );
- h += dif;
- m_candidateWindow->winSetSize( w, h );
- if ( m_candidateDownArrow )
- {
- Int x, y;
- m_candidateDownArrow->winGetPosition( &x, &y );
- y += dif;
- m_candidateDownArrow->winSetPosition( x, y );
- }
- }
- //============================================================================
- // IMEManager::getCandidateCount
- //============================================================================
- Int IMEManager::getCandidateCount()
- {
- return m_candidateCount;
- }
- //============================================================================
- // IMEManager::getCandidate
- //============================================================================
- UnicodeString* IMEManager::getCandidate( Int index )
- {
- if ( m_candidateString != NULL && index >=0 && index < m_candidateCount )
- {
- return &m_candidateString[index];
- }
- return &UnicodeString::TheEmptyString;
- }
- //============================================================================
- // IMEManager::getSelectedCandidateIndex
- //============================================================================
- Int IMEManager::getSelectedCandidateIndex()
- {
- return m_selectedIndex;
- }
- //============================================================================
- // IMEManager::getCandidatePageSize
- //============================================================================
- Int IMEManager::getCandidatePageSize()
- {
- return m_pageSize;
- }
- //============================================================================
- // IMEManager::getStartCandidateIndex
- //============================================================================
- Int IMEManager::getCandidatePageStart()
- {
- return m_pageStart;
- }
- //============================================================================
- // IMEManager::openStatusWindow
- //============================================================================
- void IMEManager::openStatusWindow( void )
- {
- if ( m_statusWindow == NULL )
- {
- return;
- }
- m_statusWindow->winHide( FALSE );
- }
- //============================================================================
- // IMEManager::closeStatusWindow
- //============================================================================
- void IMEManager::closeStatusWindow( void )
- {
- if ( m_statusWindow == NULL )
- {
- return;
- }
- m_statusWindow->winHide( TRUE );
- }
- //============================================================================
- // IMEManager::updateStatusWindow
- //============================================================================
- void IMEManager::updateStatusWindow( void )
- {
- }
|