ReactOS 0.4.16-dev-1308-gbf734eb
kbswitch.c File Reference
#include "kbswitch.h"
#include <shlobj.h>
#include <shlwapi_undoc.h>
#include <undocuser.h>
#include <imm.h>
#include <immdev.h>
#include <imm32_undoc.h>
#include "imemenu.h"
#include <wine/debug.h>
Include dependency graph for kbswitch.c:

Go to the source code of this file.

Classes

struct  tagSPECIAL_ID
 
struct  tagLOAD_ICON
 

Macros

#define WM_NOTIFYICONMSG   0x8064
 
#define WM_PENICONMSG   0x8065
 
#define NOTIFY_ICON_ID_LANGUAGE   223
 
#define NOTIFY_ICON_ID_SYSTEM_PEN   224
 
#define TIMER_ID_LANG_CHANGED_DELAYED   0x10000
 
#define TIMER_LANG_CHANGED_DELAY   200
 
#define IME_HKL_MASK   0xF000FFFF
 
#define IS_KOREAN_IME_HKL(hKL)   ((HandleToUlong(hKL) & IME_HKL_MASK) == 0xE0000412)
 
#define MAX_KLS   64
 
#define LAYOUTF_FAR_EAST   0x1
 
#define LAYOUTF_IME_ICON   0x2
 
#define LAYOUTF_TOOLTIP_ATOM   0x4
 
#define LAYOUTF_REMOVE_LEFT_DEF_MENU   0x8
 
#define LAYOUTF_REMOVE_RIGHT_DEF_MENU   0x10
 
#define MAX_SPECIAL_IDS   256
 
#define IFN_KbSwitchSetHooks   1
 
#define IFN_SetPenMenuData   14
 

Typedefs

typedef BOOL(APIENTRYFN_KbSwitchSetHooks) (BOOL bDoHook)
 
typedef VOID(APIENTRYFN_SetPenMenuData) (UINT nID, DWORD_PTR dwItemData)
 
typedef struct tagSPECIAL_ID SPECIAL_ID
 
typedef struct tagSPECIAL_IDPSPECIAL_ID
 
typedef struct tagLOAD_ICON LOAD_ICON
 
typedef struct tagLOAD_ICONPLOAD_ICON
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (internat)
 
static VOID UpdateTrayInfo (VOID)
 
static VOID LoadSpecialIds (VOID)
 
static VOID GetKLIDFromHKL (HKL hKL, LPTSTR szKLID, SIZE_T KLIDLength)
 
static HWND GetTargetWindow (HWND hwndFore OPTIONAL)
 
static HKL GetActiveKL (VOID)
 
static VOID DeletePenIcon (HWND hwnd, UINT iKL)
 
static VOID DestroyPenIcons (VOID)
 
static UINT GetLayoutIndexFromHKL (HKL hKL)
 
static VOID UpdateLayoutList (HKL hKL OPTIONAL)
 
static HKL GetHKLFromLayoutNum (UINT iKL)
 
static VOID GetKLIDFromLayoutNum (UINT iKL, LPTSTR szKLID, SIZE_T KLIDLength)
 
static BOOL GetSystemLibraryPath (LPTSTR szPath, SIZE_T cchPath, LPCTSTR FileName)
 
static BOOL GetLayoutName (UINT iKL, LPTSTR szName, SIZE_T NameLength)
 
static BOOL GetImeFile (LPTSTR szImeFile, SIZE_T cchImeFile, LPCTSTR szKLID)
 
static BOOL CALLBACK EnumResNameProc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LPARAM lParam)
 
static HICON FakeExtractIcon (PCTSTR pszImeFile, INT nIconIndex)
 
static HBITMAP BitmapFromIcon (HICON hIcon)
 
static DWORD GetImeStatus (HWND hwndTarget)
 
static HICON LoadDefaultPenIcon (PCWSTR szImeFile, HKL hKL)
 
static VOID DeletePenNotifyIcon (HWND hwnd)
 
static VOID UpdatePenIcon (HWND hwnd, UINT iKL)
 
static HICON CreateTrayIcon (LPTSTR szKLID, LPCTSTR szImeFile OPTIONAL)
 
static VOID AddTrayIcon (HWND hwnd)
 
static VOID DeleteTrayIcon (HWND hwnd)
 
static VOID UpdateTrayIcon (HWND hwnd, LPTSTR szKLID, LPTSTR szName)
 
static BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam)
 
static VOID ActivateLayout (HWND hwnd, UINT iKL, HWND hwndTarget OPTIONAL, BOOL bNoActivate)
 
static HMENU BuildLeftPopupMenu (VOID)
 
static BOOL SetHooks (VOID)
 
static VOID DeleteHooks (VOID)
 
static UINT GetLayoutNum (HKL hKL)
 
UINT UpdateLanguageDisplay (HWND hwnd, HKL hKL)
 
UINT UpdateLanguageDisplayCurrent (HWND hwnd, HWND hwndFore)
 
static BOOL RememberLastActive (HWND hwnd, HWND hwndFore)
 
static INT KbSwitch_OnCreate (HWND hwnd)
 
static void KbSwitch_OnDestroy (HWND hwnd)
 
static void KbSwitch_OnTimer (HWND hwnd, UINT_PTR nTimerID)
 
static void KbSwitch_OnNotifyIconMsg (HWND hwnd, UINT uMouseMsg)
 
static BOOL IsRegImeToolbarShown (VOID)
 
static VOID ShowImeToolbar (HWND hwndTarget, BOOL bShowToolbar)
 
static VOID KbSwitch_OnPenIconMsg (HWND hwnd, UINT uMouseMsg)
 
static void KbSwitch_OnCommand (HWND hwnd, UINT nID)
 
static LRESULT KbSwitch_OnLangChanged (HWND hwnd, HWND hwndTarget OPTIONAL, HKL hKL OPTIONAL)
 
static LRESULT KbSwitch_OnWindowActivate (HWND hwnd, HWND hwndTarget OPTIONAL, LPARAM lParam OPTIONAL)
 
static void KbSwitch_OnSettingChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
 
static LRESULT KbSwitch_OnDefault (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static VOID OnIndicatorMsg (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
LRESULT CALLBACK WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
INT WINAPI _tWinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
 

Variables

FN_KbSwitchSetHooks KbSwitchSetHooks = NULL
 
FN_SetPenMenuData SetPenMenuData = NULL
 
HINSTANCE g_hInst = NULL
 
HMODULE g_hHookDLL = NULL
 
HICON g_hTrayIcon = NULL
 
HWND g_hwndLastActive = NULL
 
UINT g_iKL = 0
 
UINT g_cKLs = 0
 
HKL g_ahKLs [MAX_KLS] = { NULL }
 
WORD g_aiSysPenIcons [MAX_KLS] = { 0 }
 
WORD g_anToolTipAtoms [MAX_KLS] = { 0 }
 
HICON g_ahSysPenIcons [MAX_KLS] = { NULL }
 
BYTE g_anFlags [MAX_KLS] = { 0 }
 
UINT g_uTaskbarRestartMsg = 0
 
UINT g_uShellHookMessage = 0
 
HWND g_hTrayWnd = NULL
 
HWND g_hTrayNotifyWnd = NULL
 
SPECIAL_ID g_SpecialIds [MAX_SPECIAL_IDS]
 
INT g_cSpecialIds = 0
 

Macro Definition Documentation

◆ IFN_KbSwitchSetHooks

#define IFN_KbSwitchSetHooks   1

Definition at line 835 of file kbswitch.c.

◆ IFN_SetPenMenuData

#define IFN_SetPenMenuData   14

Definition at line 836 of file kbswitch.c.

◆ IME_HKL_MASK

#define IME_HKL_MASK   0xF000FFFF

Definition at line 44 of file kbswitch.c.

◆ IS_KOREAN_IME_HKL

#define IS_KOREAN_IME_HKL (   hKL)    ((HandleToUlong(hKL) & IME_HKL_MASK) == 0xE0000412)

Definition at line 45 of file kbswitch.c.

◆ LAYOUTF_FAR_EAST

#define LAYOUTF_FAR_EAST   0x1

Definition at line 72 of file kbswitch.c.

◆ LAYOUTF_IME_ICON

#define LAYOUTF_IME_ICON   0x2

Definition at line 73 of file kbswitch.c.

◆ LAYOUTF_REMOVE_LEFT_DEF_MENU

#define LAYOUTF_REMOVE_LEFT_DEF_MENU   0x8

Definition at line 75 of file kbswitch.c.

◆ LAYOUTF_REMOVE_RIGHT_DEF_MENU

#define LAYOUTF_REMOVE_RIGHT_DEF_MENU   0x10

Definition at line 76 of file kbswitch.c.

◆ LAYOUTF_TOOLTIP_ATOM

#define LAYOUTF_TOOLTIP_ATOM   0x4

Definition at line 74 of file kbswitch.c.

◆ MAX_KLS

#define MAX_KLS   64

Definition at line 47 of file kbswitch.c.

◆ MAX_SPECIAL_IDS

#define MAX_SPECIAL_IDS   256

Definition at line 92 of file kbswitch.c.

◆ NOTIFY_ICON_ID_LANGUAGE

#define NOTIFY_ICON_ID_LANGUAGE   223

Definition at line 38 of file kbswitch.c.

◆ NOTIFY_ICON_ID_SYSTEM_PEN

#define NOTIFY_ICON_ID_SYSTEM_PEN   224

Definition at line 39 of file kbswitch.c.

◆ TIMER_ID_LANG_CHANGED_DELAYED

#define TIMER_ID_LANG_CHANGED_DELAYED   0x10000

Definition at line 41 of file kbswitch.c.

◆ TIMER_LANG_CHANGED_DELAY

#define TIMER_LANG_CHANGED_DELAY   200

Definition at line 42 of file kbswitch.c.

◆ WM_NOTIFYICONMSG

#define WM_NOTIFYICONMSG   0x8064

Definition at line 35 of file kbswitch.c.

◆ WM_PENICONMSG

#define WM_PENICONMSG   0x8065

Definition at line 36 of file kbswitch.c.

Typedef Documentation

◆ FN_KbSwitchSetHooks

typedef BOOL(APIENTRY * FN_KbSwitchSetHooks) (BOOL bDoHook)

Definition at line 49 of file kbswitch.c.

◆ FN_SetPenMenuData

typedef VOID(APIENTRY * FN_SetPenMenuData) (UINT nID, DWORD_PTR dwItemData)

Definition at line 50 of file kbswitch.c.

◆ LOAD_ICON

◆ PLOAD_ICON

◆ PSPECIAL_ID

◆ SPECIAL_ID

Function Documentation

◆ _tWinMain()

INT WINAPI _tWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInst,
LPTSTR  lpCmdLine,
INT  nCmdShow 
)

Definition at line 1445 of file kbswitch.c.

1446{
1448 MSG msg;
1449 HANDLE hMutex;
1450 HWND hwnd;
1451
1452 switch (GetUserDefaultUILanguage())
1453 {
1455 TRACE("LAYOUT_RTL\n");
1457 break;
1458 default:
1459 break;
1460 }
1461
1463 if (!hMutex)
1464 {
1465 ERR("!hMutex\n");
1466 return 1;
1467 }
1468
1470 {
1471 ERR("Another instance is already running\n");
1473 return 1;
1474 }
1475
1477
1478 ZeroMemory(&WndClass, sizeof(WndClass));
1479 WndClass.lpfnWndProc = WndProc;
1480 WndClass.hInstance = hInstance;
1481 WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
1482 WndClass.lpszClassName = INDICATOR_CLASS;
1483 if (!RegisterClass(&WndClass))
1484 {
1486 return 1;
1487 }
1488
1492 {
1493 ERR("RegisterShellHookWindow failed\n");
1496 return 1;
1497 }
1498
1499 while (GetMessage(&msg, NULL, 0, 0))
1500 {
1503 }
1504
1506 return 0;
1507}
#define msg(x)
Definition: auth_time.c:54
#define ERR(fmt,...)
Definition: precomp.h:57
WCHAR WndClass[]
Definition: capicon.c:23
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: locale.c:1375
#define INDICATOR_CLASS
Definition: indicml.h:19
UINT g_uShellHookMessage
Definition: kbswitch.c:67
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: kbswitch.c:1388
HINSTANCE g_hInst
Definition: kbswitch.c:55
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
HANDLE hMutex
Definition: mutex.c:11
#define L(x)
Definition: ntvdm.h:50
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_HEBREW
Definition: nls.h:67
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define TRACE(s)
Definition: solgame.cpp:4
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1689
#define ZeroMemory
Definition: winbase.h:1753
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateMutex
Definition: winbase.h:3797
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define LAYOUT_RTL
Definition: wingdi.h:1371
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI RegisterShellHookWindow(_In_ HWND)
#define IDC_ARROW
Definition: winuser.h:695
#define CreateWindow
Definition: winuser.h:5839
#define HWND_DESKTOP
Definition: winuser.h:1220
#define GetMessage
Definition: winuser.h:5875
#define RegisterWindowMessage
Definition: winuser.h:5925
#define LoadCursor
Definition: winuser.h:5897
#define RegisterClass
Definition: winuser.h:5921
#define DispatchMessage
Definition: winuser.h:5850
BOOL WINAPI DestroyWindow(_In_ HWND)

◆ ActivateLayout()

static VOID ActivateLayout ( HWND  hwnd,
UINT  iKL,
HWND hwndTarget  OPTIONAL,
BOOL  bNoActivate 
)
static

Definition at line 760 of file kbswitch.c.

761{
762 HKL hKl;
763 TCHAR szKLID[CCH_LAYOUT_ID + 1], szLangName[MAX_PATH];
765
766 if (iKL >= g_cKLs) /* Invalid */
767 return;
768
769 GetKLIDFromLayoutNum(iKL, szKLID, _countof(szKLID));
770 LangID = (LANGID)_tcstoul(szKLID, NULL, 16);
771
772 /* Switch to the new keyboard layout */
773 GetLocaleInfo(LangID, LOCALE_SLANGUAGE, szLangName, _countof(szLangName));
774 UpdateTrayIcon(hwnd, szKLID, szLangName);
775
776 if (hwndTarget && !bNoActivate)
777 SetForegroundWindow(hwndTarget);
778
779 hKl = LoadKeyboardLayout(szKLID, KLF_ACTIVATE);
780 if (hKl)
782
783 /* Post WM_INPUTLANGCHANGEREQUEST */
784 if (hwndTarget)
785 {
786 PostMessage(hwndTarget, WM_INPUTLANGCHANGEREQUEST,
787 INPUTLANGCHANGE_SYSCHARSET, (LPARAM)hKl);
788 }
789 else
790 {
792 }
793
794 g_iKL = iKL;
795}
#define MAX_PATH
Definition: compat.h:34
#define _tcstoul
Definition: tchar.h:595
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
Definition: kbswitch.c:753
static VOID UpdateTrayIcon(HWND hwnd, LPTSTR szKLID, LPTSTR szName)
Definition: kbswitch.c:731
static VOID GetKLIDFromLayoutNum(UINT iKL, LPTSTR szKLID, SIZE_T KLIDLength)
Definition: kbswitch.c:306
UINT g_cKLs
Definition: kbswitch.c:60
UINT g_iKL
Definition: kbswitch.c:59
#define CCH_LAYOUT_ID
Definition: kbswitch.h:18
USHORT LANGID
Definition: mui.h:9
UINT_PTR HKL
Definition: msctf.idl:125
#define _countof(array)
Definition: sndvol32.h:70
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1083
LONG_PTR LPARAM
Definition: windef.h:208
#define GetLocaleInfo
Definition: winnls.h:1289
#define LOCALE_SLANGUAGE
Definition: winnls.h:31
#define KLF_SETFORPROCESS
Definition: winuser.h:117
#define KLF_ACTIVATE
Definition: winuser.h:111
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define LoadKeyboardLayout
Definition: winuser.h:5901
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam)
#define PostMessage
Definition: winuser.h:5917
HKL WINAPI ActivateKeyboardLayout(_In_ HKL, _In_ UINT)
char TCHAR
Definition: xmlstorage.h:189

Referenced by KbSwitch_OnCommand(), and KbSwitch_OnCreate().

◆ AddTrayIcon()

static VOID AddTrayIcon ( HWND  hwnd)
static

Definition at line 694 of file kbswitch.c.

695{
696 NOTIFYICONDATA tnid =
697 {
699 };
700 TCHAR szKLID[CCH_LAYOUT_ID + 1], szName[MAX_PATH], szImeFile[80];
701
702 GetKLIDFromLayoutNum(g_iKL, szKLID, _countof(szKLID));
704 GetImeFile(szImeFile, _countof(szImeFile), szKLID);
705
707 tnid.hIcon = CreateTrayIcon(szKLID, szImeFile);
709
711
712 if (g_hTrayIcon)
714 g_hTrayIcon = tnid.hIcon;
715}
static BOOL GetLayoutName(UINT iKL, LPTSTR szName, SIZE_T NameLength)
Definition: kbswitch.c:323
#define NOTIFY_ICON_ID_LANGUAGE
Definition: kbswitch.c:38
static HICON CreateTrayIcon(LPTSTR szKLID, LPCTSTR szImeFile OPTIONAL)
Definition: kbswitch.c:597
static BOOL GetImeFile(LPTSTR szImeFile, SIZE_T cchImeFile, LPCTSTR szKLID)
Definition: kbswitch.c:359
HICON g_hTrayIcon
Definition: kbswitch.c:57
#define WM_NOTIFYICONMSG
Definition: kbswitch.c:35
static const WCHAR szName[]
Definition: powrprof.c:45
#define NIF_ICON
Definition: shellapi.h:106
#define NIF_MESSAGE
Definition: shellapi.h:105
#define NIM_ADD
Definition: shellapi.h:94
#define Shell_NotifyIcon
Definition: shellapi.h:730
#define NIF_TIP
Definition: shellapi.h:107
#define StringCchCopy
Definition: strsafe.h:139
UINT uCallbackMessage
Definition: shellapi.h:231
CHAR szTip[128]
Definition: shellapi.h:237
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2390

Referenced by KbSwitch_OnCreate(), and KbSwitch_OnDefault().

◆ BitmapFromIcon()

static HBITMAP BitmapFromIcon ( HICON  hIcon)
static

Definition at line 440 of file kbswitch.c.

441{
442 HDC hdcScreen = GetDC(NULL);
443 HDC hdc = CreateCompatibleDC(hdcScreen);
446 HBITMAP hbm = CreateCompatibleBitmap(hdcScreen, cxIcon, cyIcon);
447 HGDIOBJ hbmOld;
448
449 if (hbm != NULL)
450 {
451 hbmOld = SelectObject(hdc, hbm);
452 DrawIconEx(hdc, 0, 0, hIcon, cxIcon, cyIcon, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL);
453 SelectObject(hdc, hbmOld);
454 }
455
456 DeleteDC(hdc);
457 ReleaseDC(NULL, hdcScreen);
458 return hbm;
459}
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
HICON hIcon
Definition: msconfig.c:44
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
int32_t INT
Definition: typedefs.h:58
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define DI_NORMAL
Definition: wingdi.h:72
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define COLOR_MENU
Definition: winuser.h:928
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define SM_CYSMICON
Definition: winuser.h:1024
#define SM_CXSMICON
Definition: winuser.h:1023
BOOL WINAPI DrawIconEx(_In_ HDC, _In_ int, _In_ int, _In_ HICON, _In_ int, _In_ int, _In_ UINT, _In_opt_ HBRUSH, _In_ UINT)
Definition: cursoricon.c:2365
HDC WINAPI GetDC(_In_opt_ HWND)
int WINAPI GetSystemMetrics(_In_ int)

Referenced by BuildLeftPopupMenu(), and FileTypesDlg_OnItemChanging().

◆ BuildLeftPopupMenu()

static HMENU BuildLeftPopupMenu ( VOID  )
static

Definition at line 798 of file kbswitch.c.

799{
800 HMENU hMenu = CreatePopupMenu();
801 TCHAR szName[MAX_PATH], szKLID[CCH_LAYOUT_ID + 1], szImeFile[80];
802 HICON hIcon;
803 MENUITEMINFO mii = { sizeof(mii) };
804 UINT iKL;
805
806 for (iKL = 0; iKL < g_cKLs; ++iKL)
807 {
808 GetKLIDFromHKL(g_ahKLs[iKL], szKLID, _countof(szKLID));
809 GetImeFile(szImeFile, _countof(szImeFile), szKLID);
810
811 if (!GetLayoutName(iKL, szName, _countof(szName)))
812 continue;
813
814 mii.fMask = MIIM_ID | MIIM_STRING;
815 mii.wID = ID_LANG_BASE + iKL;
816 mii.dwTypeData = szName;
817
818 hIcon = CreateTrayIcon(szKLID, szImeFile);
819 if (hIcon)
820 {
821 mii.hbmpItem = BitmapFromIcon(hIcon);
822 if (mii.hbmpItem)
823 mii.fMask |= MIIM_BITMAP;
824 }
825
826 InsertMenuItem(hMenu, -1, TRUE, &mii);
828 }
829
831
832 return hMenu;
833}
#define ID_LANG_BASE
Definition: resource.h:24
#define TRUE
Definition: types.h:120
static HBITMAP BitmapFromIcon(HICON hIcon)
Definition: kbswitch.c:440
static VOID GetKLIDFromHKL(HKL hKL, LPTSTR szKLID, SIZE_T KLIDLength)
Definition: kbswitch.c:150
HKL g_ahKLs[MAX_KLS]
Definition: kbswitch.c:61
static HICON
Definition: imagelist.c:80
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
unsigned int UINT
Definition: ndis.h:50
LPSTR dwTypeData
Definition: winuser.h:3327
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
#define MIIM_STRING
Definition: winuser.h:738
#define MIIM_ID
Definition: winuser.h:733
#define InsertMenuItem
Definition: winuser.h:5889
#define MF_CHECKED
Definition: winuser.h:132
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MIIM_BITMAP
Definition: winuser.h:739

Referenced by KbSwitch_OnNotifyIconMsg().

◆ CreateTrayIcon()

static HICON CreateTrayIcon ( LPTSTR  szKLID,
LPCTSTR szImeFile  OPTIONAL 
)
static

Definition at line 597 of file kbswitch.c.

598{
600 TCHAR szBuf[4];
601 HDC hdcScreen, hdc;
602 HBITMAP hbmColor, hbmMono, hBmpOld;
603 HFONT hFont, hFontOld;
604 LOGFONT lf;
605 RECT rect;
607 HICON hIcon;
611
612 if (szImeFile && szImeFile[0])
613 {
614 if (GetSystemLibraryPath(szPath, _countof(szPath), szImeFile))
615 return FakeExtractIcon(szPath, 0);
616 }
617
618 /* Getting "EN", "FR", etc. from English, French, ... */
619 LangID = LANGIDFROMLCID(_tcstoul(szKLID, NULL, 16));
622 szBuf,
623 _countof(szBuf)) == 0)
624 {
625 szBuf[0] = szBuf[1] = _T('?');
626 }
627 szBuf[2] = 0; /* Truncate the identifier to two characters: "ENG" --> "EN" etc. */
628
629 /* Create hdc, hbmColor and hbmMono */
630 hdcScreen = GetDC(NULL);
631 hdc = CreateCompatibleDC(hdcScreen);
632 hbmColor = CreateCompatibleBitmap(hdcScreen, cxIcon, cyIcon);
633 ReleaseDC(NULL, hdcScreen);
634 hbmMono = CreateBitmap(cxIcon, cyIcon, 1, 1, NULL);
635
636 /* Checking NULL */
637 if (!hdc || !hbmColor || !hbmMono)
638 {
639 if (hbmMono)
640 DeleteObject(hbmMono);
641 if (hbmColor)
642 DeleteObject(hbmColor);
643 if (hdc)
644 DeleteDC(hdc);
645 return NULL;
646 }
647
648 /* Create a font */
649 hFont = NULL;
650 if (SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0))
651 {
652 /* Override the current size with something manageable */
653 lf.lfHeight = -11;
654 lf.lfWidth = 0;
656 }
657 if (!hFont)
659
660 SetRect(&rect, 0, 0, cxIcon, cyIcon);
661
662 /* Draw hbmColor */
663 hBmpOld = SelectObject(hdc, hbmColor);
665 FillRect(hdc, &rect, (HBRUSH)GetStockObject(DC_BRUSH));
666 hFontOld = SelectObject(hdc, hFont);
670 SelectObject(hdc, hFontOld);
671
672 /* Fill hbmMono with black */
673 SelectObject(hdc, hbmMono);
674 PatBlt(hdc, 0, 0, cxIcon, cyIcon, BLACKNESS);
675 SelectObject(hdc, hBmpOld);
676
677 /* Create an icon from hbmColor and hbmMono */
680 IconInfo.hbmColor = hbmColor;
681 IconInfo.hbmMask = hbmMono;
683
684 /* Clean up */
686 DeleteObject(hbmMono);
687 DeleteObject(hbmColor);
688 DeleteDC(hdc);
689
690 return hIcon;
691}
HFONT hFont
Definition: main.c:53
pKey DeleteObject()
_Out_opt_ PICONINFO IconInfo
Definition: ntuser.h:2306
static HICON FakeExtractIcon(PCTSTR pszImeFile, INT nIconIndex)
Definition: kbswitch.c:423
static BOOL GetSystemLibraryPath(LPTSTR szPath, SIZE_T cchPath, LPCTSTR FileName)
Definition: kbswitch.c:312
LPCWSTR szPath
Definition: env.c:37
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define LANGIDFROMLCID(l)
Definition: nls.h:18
& rect
Definition: startmenu.cpp:1413
LONG lfHeight
Definition: dimm.idl:42
LONG lfWidth
Definition: dimm.idl:43
DWORD yHotspot
Definition: winuser.h:3201
BOOL fIcon
Definition: winuser.h:3199
DWORD xHotspot
Definition: winuser.h:3200
HBITMAP hbmColor
Definition: winuser.h:3203
HBITMAP hbmMask
Definition: winuser.h:3202
#define _T(x)
Definition: vfdio.h:22
COLORREF WINAPI SetDCBrushColor(_In_ HDC hdc, _In_ COLORREF crColor)
Definition: dc.c:905
#define BLACKNESS
Definition: wingdi.h:323
HGDIOBJ WINAPI GetStockObject(_In_ int)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
#define DEFAULT_GUI_FONT
Definition: wingdi.h:909
#define TRANSPARENT
Definition: wingdi.h:950
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:917
#define CreateFontIndirect
Definition: wingdi.h:4444
#define LOCALE_NOUSEROVERRIDE
Definition: winnls.h:19
#define LOCALE_SABBREVLANGNAME
Definition: winnls.h:34
DWORD WINAPI GetSysColor(_In_ int)
HICON WINAPI CreateIconIndirect(_In_ PICONINFO)
Definition: cursoricon.c:2943
#define DT_CENTER
Definition: winuser.h:527
#define COLOR_HIGHLIGHT
Definition: winuser.h:937
#define DT_SINGLELINE
Definition: winuser.h:540
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1391
#define DrawText
Definition: winuser.h:5856
#define COLOR_HIGHLIGHTTEXT
Definition: winuser.h:938
#define DT_VCENTER
Definition: winuser.h:543
#define SystemParametersInfo
Definition: winuser.h:5943
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)

Referenced by AddTrayIcon(), BuildLeftPopupMenu(), and UpdateTrayIcon().

◆ DeleteHooks()

static VOID DeleteHooks ( VOID  )
static

Definition at line 861 of file kbswitch.c.

862{
864 {
867 }
868
869 if (g_hHookDLL)
870 {
873 }
874
875 TRACE("DeleteHooks OK\n");
876}
#define FreeLibrary(x)
Definition: compat.h:748
HMODULE g_hHookDLL
Definition: kbswitch.c:56
FN_KbSwitchSetHooks KbSwitchSetHooks
Definition: kbswitch.c:52

Referenced by KbSwitch_OnDestroy().

◆ DeletePenIcon()

static VOID DeletePenIcon ( HWND  hwnd,
UINT  iKL 
)
static

Definition at line 201 of file kbswitch.c.

202{
204
205 if (g_ahSysPenIcons[iKL])
206 {
208 g_ahSysPenIcons[iKL] = NULL;
209 }
210}
HICON g_ahSysPenIcons[MAX_KLS]
Definition: kbswitch.c:64
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329

Referenced by UpdatePenIcon().

◆ DeletePenNotifyIcon()

static VOID DeletePenNotifyIcon ( HWND  hwnd)
static

Definition at line 540 of file kbswitch.c.

541{
544}
#define NOTIFY_ICON_ID_SYSTEM_PEN
Definition: kbswitch.c:39
NOTIFYICONDATA nid
Definition: magnifier.c:44
#define NIM_DELETE
Definition: shellapi.h:96

Referenced by UpdatePenIcon().

◆ DeleteTrayIcon()

static VOID DeleteTrayIcon ( HWND  hwnd)
static

Definition at line 718 of file kbswitch.c.

719{
720 NOTIFYICONDATA tnid = { sizeof(tnid), hwnd, NOTIFY_ICON_ID_LANGUAGE };
722
723 if (g_hTrayIcon)
724 {
727 }
728}

Referenced by KbSwitch_OnDestroy().

◆ DestroyPenIcons()

static VOID DestroyPenIcons ( VOID  )
static

Definition at line 213 of file kbswitch.c.

214{
215 INT iKL;
216 for (iKL = 0; iKL < g_cKLs; ++iKL)
217 {
218 if (g_ahSysPenIcons[iKL])
219 {
221 g_ahSysPenIcons[iKL] = NULL;
222 }
223 }
224}

Referenced by KbSwitch_OnDestroy(), and UpdateLayoutList().

◆ EnumResNameProc()

static BOOL CALLBACK EnumResNameProc ( HMODULE  hModule,
LPCTSTR  lpszType,
LPTSTR  lpszName,
LPARAM  lParam 
)
static

Definition at line 400 of file kbswitch.c.

405{
406 UNREFERENCED_PARAMETER(lpszType);
407
408 PLOAD_ICON pLoadIcon = (PLOAD_ICON)lParam;
409 if (pLoadIcon->iIcon == pLoadIcon->nIconIndex)
410 {
411 pLoadIcon->hIcon = (HICON)LoadImage(hModule, lpszName, IMAGE_ICON,
412 pLoadIcon->cxIcon, pLoadIcon->cyIcon,
414 if (pLoadIcon->hIcon)
415 return FALSE; /* Stop enumeration */
416 }
417
418 ++pLoadIcon->iIcon;
419 return TRUE;
420}
LPARAM lParam
Definition: combotst.c:139
HMODULE hModule
Definition: animate.c:44
struct tagLOAD_ICON * PLOAD_ICON
INT nIconIndex
Definition: kbswitch.c:393
HICON hIcon
Definition: kbswitch.c:396
#define IMAGE_ICON
Definition: winuser.h:212
#define LoadImage
Definition: winuser.h:5900
#define LR_DEFAULTCOLOR
Definition: winuser.h:1098

Referenced by FakeExtractIcon().

◆ EnumWindowsProc()

static BOOL CALLBACK EnumWindowsProc ( HWND  hwnd,
LPARAM  lParam 
)
static

Definition at line 753 of file kbswitch.c.

754{
755 PostMessage(hwnd, WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_SYSCHARSET, lParam);
756 return TRUE;
757}

Referenced by ActivateLayout().

◆ FakeExtractIcon()

static HICON FakeExtractIcon ( PCTSTR  pszImeFile,
INT  nIconIndex 
)
static

Definition at line 423 of file kbswitch.c.

424{
425 HMODULE hImeDLL = LoadLibraryEx(pszImeFile, NULL, LOAD_LIBRARY_AS_DATAFILE);
426 if (!hImeDLL)
427 return NULL;
428
430 {
432 };
434
435 FreeLibrary(hImeDLL);
436
437 return LoadIcon.hIcon;
438}
static BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LPARAM lParam)
Definition: kbswitch.c:400
#define RT_GROUP_ICON
Definition: pedump.c:375
#define LoadLibraryEx
Definition: winbase.h:3904
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:375
#define EnumResourceNames
Definition: winbase.h:3813
#define LoadIcon
Definition: winuser.h:5898

Referenced by CreateTrayIcon(), and UpdatePenIcon().

◆ GetActiveKL()

static HKL GetActiveKL ( VOID  )
static

Definition at line 191 of file kbswitch.c.

192{
193 /* FIXME: Get correct console window's HKL when console window */
194 HWND hwndTarget = GetTargetWindow(NULL);
195 TRACE("hwndTarget: %p\n", hwndTarget);
196 DWORD dwTID = GetWindowThreadProcessId(hwndTarget, NULL);
197 return GetKeyboardLayout(dwTID);
198}
unsigned long DWORD
Definition: ntddk_ex.h:95
static HWND GetTargetWindow(HWND hwndFore OPTIONAL)
Definition: kbswitch.c:179
DWORD WINAPI GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
HKL WINAPI GetKeyboardLayout(_In_ DWORD)

Referenced by GetHKLFromLayoutNum(), KbSwitch_OnTimer(), and UpdateLayoutList().

◆ GetHKLFromLayoutNum()

static HKL GetHKLFromLayoutNum ( UINT  iKL)
static

Definition at line 300 of file kbswitch.c.

301{
302 return (iKL < g_cKLs) ? g_ahKLs[iKL] : GetActiveKL();
303}
static HKL GetActiveKL(VOID)
Definition: kbswitch.c:191

Referenced by GetKLIDFromLayoutNum().

◆ GetImeFile()

static BOOL GetImeFile ( LPTSTR  szImeFile,
SIZE_T  cchImeFile,
LPCTSTR  szKLID 
)
static

Definition at line 359 of file kbswitch.c.

360{
361 HKEY hKey;
363 TCHAR szBuf[MAX_PATH];
364
365 szImeFile[0] = UNICODE_NULL;
366
367 if (_tcslen(szKLID) != CCH_LAYOUT_ID)
368 return FALSE; /* Invalid LCID */
369
370 if (szKLID[0] != TEXT('E') && szKLID[0] != TEXT('e'))
371 return FALSE; /* Not an IME HKL */
372
373 StringCchPrintf(szBuf, _countof(szBuf),
374 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s"), szKLID);
375
377 return FALSE;
378
379 dwBufLen = cchImeFile * sizeof(TCHAR);
380 if (RegQueryValueEx(hKey, _T("IME File"), NULL, NULL,
381 (LPBYTE)szImeFile, &dwBufLen) != ERROR_SUCCESS)
382 {
383 szImeFile[0] = UNICODE_NULL;
384 }
385
387
388 return (szImeFile[0] != UNICODE_NULL);
389}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
FxAutoRegKey hKey
#define TEXT(s)
Definition: k32.h:28
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define UNICODE_NULL
#define StringCchPrintf
Definition: strsafe.h:517
unsigned char * LPBYTE
Definition: typedefs.h:53
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_ DWORD _In_ DWORD dwBufLen
Definition: wincrypt.h:4246
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524
#define _tcslen
Definition: xmlstorage.h:198

Referenced by AddTrayIcon(), BuildLeftPopupMenu(), UpdatePenIcon(), and UpdateTrayIcon().

◆ GetImeStatus()

static DWORD GetImeStatus ( HWND  hwndTarget)
static

Definition at line 462 of file kbswitch.c.

463{
464 HWND hwndIme = ImmGetDefaultIMEWnd(hwndTarget);
465 if (!hwndIme)
467
468 HIMC hIMC = (HIMC)SendMessage(hwndIme, WM_IME_SYSTEM, IMS_GETCONTEXT, (LPARAM)hwndTarget);
469 if (!hIMC)
470 return IME_STATUS_NO_IME;
471
473 if (GetACP() == 949) // Korean
474 {
475 DWORD dwConversion = 0, dwSentence = 0;
476 if (ImmGetConversionStatus(hIMC, &dwConversion, &dwSentence))
477 {
478 if (dwConversion & IME_CMODE_NATIVE)
479 dwImeStatus |= IME_STATUS_IME_NATIVE;
480
481 if (dwConversion & IME_CMODE_FULLSHAPE)
482 dwImeStatus |= IME_STATUS_IME_FULLSHAPE;
483 }
484 }
485
486 return dwImeStatus;
487}
DWORD HIMC
Definition: dimm.idl:75
UINT WINAPI GetACP(void)
Definition: locale.c:2021
#define IMS_GETCONTEXT
Definition: imm32_undoc.h:51
#define WM_IME_SYSTEM
Definition: imm32_undoc.h:32
BOOL WINAPI ImmGetConversionStatus(_In_ HIMC hIMC, _Out_opt_ LPDWORD lpfdwConversion, _Out_opt_ LPDWORD lpfdwSentence)
Definition: ime.c:1501
#define IME_CMODE_NATIVE
Definition: imm.h:337
BOOL WINAPI ImmGetOpenStatus(_In_ HIMC hIMC)
Definition: ime.c:996
HWND WINAPI ImmGetDefaultIMEWnd(_In_opt_ HWND hWnd)
Definition: ime.c:440
#define IME_CMODE_FULLSHAPE
Definition: imm.h:345
#define IME_STATUS_IME_CLOSED
Definition: kbswitch.h:31
#define IME_STATUS_IME_OPEN
Definition: kbswitch.h:32
#define IME_STATUS_NO_IME
Definition: kbswitch.h:30
#define IME_STATUS_IME_FULLSHAPE
Definition: kbswitch.h:34
#define IME_STATUS_IME_NATIVE
Definition: kbswitch.h:33
#define SendMessage
Definition: winuser.h:5928

Referenced by KbSwitch_OnPenIconMsg(), and LoadDefaultPenIcon().

◆ GetKLIDFromHKL()

static VOID GetKLIDFromHKL ( HKL  hKL,
LPTSTR  szKLID,
SIZE_T  KLIDLength 
)
static

Definition at line 150 of file kbswitch.c.

151{
152 szKLID[0] = 0;
153
154 if (IS_IME_HKL(hKL))
155 {
156 StringCchPrintf(szKLID, KLIDLength, _T("%08lx"), (DWORD)(DWORD_PTR)hKL);
157 return;
158 }
159
160 if (IS_SPECIAL_HKL(hKL))
161 {
162 INT i;
163 for (i = 0; i < g_cSpecialIds; ++i)
164 {
165 if (g_SpecialIds[i].hKL == hKL)
166 {
167 StringCchCopy(szKLID, KLIDLength, g_SpecialIds[i].szKLID);
168 return;
169 }
170 }
171 }
172 else
173 {
174 StringCchPrintf(szKLID, KLIDLength, _T("%08lx"), LOWORD(hKL));
175 }
176}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define IS_SPECIAL_HKL(hKL)
Definition: imm32_undoc.h:22
#define IS_IME_HKL(hKL)
Definition: imm32_undoc.h:21
INT g_cSpecialIds
Definition: kbswitch.c:95
SPECIAL_ID g_SpecialIds[MAX_SPECIAL_IDS]
Definition: kbswitch.c:94
#define LOWORD(l)
Definition: pedump.c:82
uint32_t DWORD_PTR
Definition: typedefs.h:65

Referenced by BuildLeftPopupMenu(), GetKLIDFromLayoutNum(), UpdateLanguageDisplay(), and UpdatePenIcon().

◆ GetKLIDFromLayoutNum()

static VOID GetKLIDFromLayoutNum ( UINT  iKL,
LPTSTR  szKLID,
SIZE_T  KLIDLength 
)
static

Definition at line 306 of file kbswitch.c.

307{
308 GetKLIDFromHKL(GetHKLFromLayoutNum(iKL), szKLID, KLIDLength);
309}
static HKL GetHKLFromLayoutNum(UINT iKL)
Definition: kbswitch.c:300

Referenced by ActivateLayout(), AddTrayIcon(), and GetLayoutName().

◆ GetLayoutIndexFromHKL()

static UINT GetLayoutIndexFromHKL ( HKL  hKL)
static

Definition at line 227 of file kbswitch.c.

228{
229 for (UINT iKL = 0; iKL < g_cKLs; ++iKL)
230 {
231 if (g_ahKLs[iKL] == hKL)
232 return iKL;
233 }
234 return 0;
235}

Referenced by OnIndicatorMsg(), and UpdateLayoutList().

◆ GetLayoutName()

static BOOL GetLayoutName ( UINT  iKL,
LPTSTR  szName,
SIZE_T  NameLength 
)
static

Definition at line 323 of file kbswitch.c.

324{
325 HKEY hKey;
326 HRESULT hr;
328 TCHAR szBuf[MAX_PATH], szKLID[CCH_LAYOUT_ID + 1];
329
330 GetKLIDFromLayoutNum(iKL, szKLID, _countof(szKLID));
331
332 StringCchPrintf(szBuf, _countof(szBuf),
333 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s"), szKLID);
334
336 return FALSE;
337
338 /* Use "Layout Display Name" value as an entry name if possible */
339 hr = SHLoadRegUIString(hKey, _T("Layout Display Name"), szName, NameLength);
340 if (SUCCEEDED(hr))
341 {
343 return TRUE;
344 }
345
346 /* Otherwise, use "Layout Text" value as an entry name */
347 dwBufLen = NameLength * sizeof(TCHAR);
348 if (RegQueryValueEx(hKey, _T("Layout Text"), NULL, NULL,
350 {
352 return TRUE;
353 }
354
356 return FALSE;
357}
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define KEY_READ
Definition: nt_native.h:1023
HRESULT hr
Definition: shlfolder.c:183
#define SHLoadRegUIString

Referenced by AddTrayIcon(), and BuildLeftPopupMenu().

◆ GetLayoutNum()

static UINT GetLayoutNum ( HKL  hKL)
static

Definition at line 878 of file kbswitch.c.

879{
880 UINT iKL;
881
882 for (iKL = 0; iKL < g_cKLs; ++iKL)
883 {
884 if (g_ahKLs[iKL] == hKL)
885 return iKL;
886 }
887
888 return 0;
889}

Referenced by UpdateLanguageDisplay().

◆ GetSystemLibraryPath()

static BOOL GetSystemLibraryPath ( LPTSTR  szPath,
SIZE_T  cchPath,
LPCTSTR  FileName 
)
static

Definition at line 312 of file kbswitch.c.

313{
314 if (!GetSystemDirectory(szPath, cchPath))
315 return FALSE;
316
317 StringCchCat(szPath, cchPath, TEXT("\\"));
318 StringCchCat(szPath, cchPath, FileName);
319 return TRUE;
320}
#define StringCchCat
Definition: strsafe.h:317
#define GetSystemDirectory
Definition: winbase.h:3883

Referenced by CreateTrayIcon(), and LayoutList_ReadLayout().

◆ GetTargetWindow()

static HWND GetTargetWindow ( HWND hwndFore  OPTIONAL)
static

Definition at line 179 of file kbswitch.c.

180{
181 HWND hwndTarget = (hwndFore ? hwndFore : GetForegroundWindow());
182 if (!hwndTarget ||
183 IsWndClassName(hwndTarget, INDICATOR_CLASS) ||
184 IsWndClassName(hwndTarget, TEXT("Shell_TrayWnd")))
185 {
186 hwndTarget = g_hwndLastActive;
187 }
188 return hwndTarget;
189}
HWND g_hwndLastActive
Definition: kbswitch.c:58
static BOOL IsWndClassName(_In_opt_ HWND hwndTarget, PCTSTR pszName)
Definition: kbswitch.h:37
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392

Referenced by GetActiveKL(), KbSwitch_OnPenIconMsg(), and UpdateLanguageDisplayCurrent().

◆ IsRegImeToolbarShown()

static BOOL IsRegImeToolbarShown ( VOID  )
static

Definition at line 1022 of file kbswitch.c.

1023{
1024 HKEY hKey;
1025 LSTATUS error = RegOpenKey(HKEY_CURRENT_USER, TEXT("Control Panel\\Input Method"), &hKey);
1026 if (error)
1027 {
1028 ERR("Cannot open regkey: 0x%lX\n", error);
1029 return TRUE;
1030 }
1031
1032 WCHAR szText[8];
1033 DWORD cbValue = sizeof(szText);
1034 error = RegQueryValueEx(hKey, TEXT("Show Status"), NULL, NULL, (PBYTE)szText, &cbValue);
1035 if (error)
1036 {
1038 return TRUE;
1039 }
1040
1041 BOOL ret = !!_wtoi(szText);
1043 return ret;
1044}
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define error(str)
Definition: mkdosfs.c:1605
BYTE * PBYTE
Definition: pedump.c:66
int ret
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegOpenKey
Definition: winreg.h:519
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by KbSwitch_OnPenIconMsg().

◆ KbSwitch_OnCommand()

static void KbSwitch_OnCommand ( HWND  hwnd,
UINT  nID 
)
static

Definition at line 1238 of file kbswitch.c.

1239{
1240 switch (nID)
1241 {
1242 case ID_EXIT:
1243 PostMessage(hwnd, WM_CLOSE, 0, 0);
1244 break;
1245
1246 case ID_PREFERENCES:
1247 {
1249 TEXT("control.exe"), TEXT("input.dll"),
1251 if (ret <= 32)
1252 MessageBox(hwnd, _T("Can't start input.dll"), NULL, MB_ICONERROR);
1253 break;
1254 }
1255
1256 default:
1257 {
1258 if (nID >= ID_LANG_BASE)
1259 {
1261 {
1263 }
1265 }
1266 break;
1267 }
1268 }
1269}
#define ID_EXIT
Definition: resource.h:18
#define ID_PREFERENCES
Definition: resource.h:19
static VOID ActivateLayout(HWND hwnd, UINT iKL, HWND hwndTarget OPTIONAL, BOOL bNoActivate)
Definition: kbswitch.c:760
#define ShellExecute
Definition: shellapi.h:732
int32_t INT_PTR
Definition: typedefs.h:64
#define SW_SHOWNORMAL
Definition: winuser.h:781
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define WM_CLOSE
Definition: winuser.h:1640
#define MB_ICONERROR
Definition: winuser.h:798
#define MessageBox
Definition: winuser.h:5907

Referenced by WndProc().

◆ KbSwitch_OnCreate()

static INT KbSwitch_OnCreate ( HWND  hwnd)
static

Definition at line 935 of file kbswitch.c.

936{
937 if (!SetHooks())
938 {
939 MessageBox(NULL, TEXT("SetHooks failed."), NULL, MB_ICONERROR);
940 return -1; /* Failed */
941 }
942
948
951
952 return 0; /* Success */
953}
static VOID LoadSpecialIds(VOID)
Definition: kbswitch.c:97
static VOID UpdatePenIcon(HWND hwnd, UINT iKL)
Definition: kbswitch.c:547
static VOID UpdateLayoutList(HKL hKL OPTIONAL)
Definition: kbswitch.c:237
static VOID UpdateTrayInfo(VOID)
Definition: kbswitch.c:79
static BOOL SetHooks(VOID)
Definition: kbswitch.c:839
static VOID AddTrayIcon(HWND hwnd)
Definition: kbswitch.c:694
UINT g_uTaskbarRestartMsg
Definition: kbswitch.c:66

Referenced by WndProc().

◆ KbSwitch_OnDefault()

static LRESULT KbSwitch_OnDefault ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1302 of file kbswitch.c.

1303{
1304 if (uMsg == g_uTaskbarRestartMsg)
1305 {
1310 return 0;
1311 }
1312
1313 if (uMsg == g_uShellHookMessage)
1314 {
1315 TRACE("g_uShellHookMessage: wParam:%p, lParam:%p\n", wParam, lParam);
1316 if (wParam == HSHELL_LANGUAGE)
1318 else if (wParam == HSHELL_WINDOWACTIVATED || wParam == HSHELL_RUDEAPPACTIVATED)
1320 return 0;
1321 }
1322
1323 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1324}
WPARAM wParam
Definition: combotst.c:138
#define WM_WINDOW_ACTIVATE
Definition: kbswitch.h:28
#define WM_LANG_CHANGED
Definition: kbswitch.h:27
#define DefWindowProc
Definition: ros2win.h:31
#define HSHELL_RUDEAPPACTIVATED
Definition: winuser.h:1292

Referenced by WndProc().

◆ KbSwitch_OnDestroy()

static void KbSwitch_OnDestroy ( HWND  hwnd)
static

Definition at line 957 of file kbswitch.c.

958{
960 DeleteHooks();
964}
#define TIMER_ID_LANG_CHANGED_DELAYED
Definition: kbswitch.c:41
static VOID DeleteHooks(VOID)
Definition: kbswitch.c:861
static VOID DestroyPenIcons(VOID)
Definition: kbswitch.c:213
static VOID DeleteTrayIcon(HWND hwnd)
Definition: kbswitch.c:718
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)

Referenced by WndProc().

◆ KbSwitch_OnLangChanged()

static LRESULT KbSwitch_OnLangChanged ( HWND  hwnd,
HWND hwndTarget  OPTIONAL,
HKL hKL  OPTIONAL 
)
static

Definition at line 1273 of file kbswitch.c.

1274{
1275 TRACE("WM_LANG_CHANGED: hwndTarget:%p, hKL:%p\n", hwndTarget, hKL);
1276 /* Delayed action */
1279 return 0;
1280}
#define TIMER_LANG_CHANGED_DELAY
Definition: kbswitch.c:42
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)

Referenced by WndProc().

◆ KbSwitch_OnNotifyIconMsg()

static void KbSwitch_OnNotifyIconMsg ( HWND  hwnd,
UINT  uMouseMsg 
)
static

Definition at line 982 of file kbswitch.c.

983{
984 if (uMouseMsg != WM_LBUTTONUP && uMouseMsg != WM_RBUTTONUP)
985 return;
986
988
989 POINT pt;
991
993
994 TPMPARAMS params = { sizeof(params) };
996
997 INT nID;
998 if (uMouseMsg == WM_LBUTTONUP)
999 {
1000 /* Rebuild the left popup menu on every click to take care of keyboard layout changes */
1001 HMENU hPopupMenu = BuildLeftPopupMenu();
1003 nID = TrackPopupMenuEx(hPopupMenu, uFlags, pt.x, pt.y, hwnd, &params);
1004 DestroyMenu(hPopupMenu);
1005 }
1006 else /* WM_RBUTTONUP */
1007 {
1009 HMENU hSubMenu = GetSubMenu(hPopupMenu, 0);
1011 nID = TrackPopupMenuEx(hSubMenu, uFlags, pt.x, pt.y, hwnd, &params);
1012 DestroyMenu(hPopupMenu);
1013 }
1014
1015 PostMessage(hwnd, WM_NULL, 0, 0);
1016
1017 if (nID)
1018 PostMessage(hwnd, WM_COMMAND, nID, 0);
1019}
#define IDR_POPUP
Definition: resource.h:7
UINT uFlags
Definition: api.c:59
#define pt(x, y)
Definition: drawing.c:79
GLenum const GLfloat * params
Definition: glext.h:5645
HWND g_hTrayNotifyWnd
Definition: kbswitch.c:69
static HMENU BuildLeftPopupMenu(VOID)
Definition: kbswitch.c:798
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
#define TPM_RIGHTBUTTON
Definition: winuser.h:2399
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
#define WM_COMMAND
Definition: winuser.h:1759
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:3032
#define WM_RBUTTONUP
Definition: winuser.h:1799
#define TPM_RIGHTALIGN
Definition: winuser.h:2397
BOOL WINAPI TrackPopupMenuEx(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _In_ HWND, _In_opt_ LPTPMPARAMS)
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define WM_NULL
Definition: winuser.h:1626
#define TPM_VERTICAL
Definition: winuser.h:2401
#define TPM_LEFTBUTTON
Definition: winuser.h:2398
#define LoadMenu
Definition: winuser.h:5902
#define WM_LBUTTONUP
Definition: winuser.h:1796
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define TPM_RETURNCMD
Definition: winuser.h:2406

Referenced by WndProc().

◆ KbSwitch_OnPenIconMsg()

static VOID KbSwitch_OnPenIconMsg ( HWND  hwnd,
UINT  uMouseMsg 
)
static

Definition at line 1070 of file kbswitch.c.

1071{
1072 if (uMouseMsg != WM_LBUTTONUP && uMouseMsg != WM_RBUTTONUP)
1073 return;
1074
1076 return;
1077
1078 POINT pt;
1079 GetCursorPos(&pt);
1080
1081 // Get target window
1082 TRACE("g_hwndLastActive: %p\n", g_hwndLastActive);
1084 TRACE("hwndTarget: %p\n", hwndTarget);
1085
1086 // Get default IME window
1087 HWND hwndIme = ImmGetDefaultIMEWnd(hwndTarget);
1088 if (!hwndIme)
1089 {
1090 WARN("No default IME\n");
1091 return;
1092 }
1093
1094 // Get IME context from another process
1095 HIMC hIMC = (HIMC)SendMessage(hwndIme, WM_IME_SYSTEM, IMS_GETCONTEXT, (LPARAM)hwndTarget);
1096 if (!hIMC)
1097 {
1098 WARN("No HIMC\n");
1099 return;
1100 }
1101
1102 // Workaround of TrackPopupMenu's bug
1104
1105 // Create IME menu
1106 BOOL bRightButton = (uMouseMsg == WM_RBUTTONUP);
1107 PIMEMENUNODE pImeMenu = CreateImeMenu(hIMC, NULL, bRightButton);
1108 HMENU hMenu = MenuFromImeMenu(pImeMenu);
1109
1110 HKL hKL = g_ahKLs[g_iKL];
1111 DWORD dwImeStatus = GetImeStatus(hwndTarget);
1112 BOOL bImeOn = FALSE, bSoftOn = FALSE, bShowToolbar = FALSE;
1113 TCHAR szText[128];
1114 if (bRightButton)
1115 {
1116 if (!(g_anFlags[g_iKL] & LAYOUTF_REMOVE_RIGHT_DEF_MENU)) // Add default menu items?
1117 {
1118 if (GetMenuItemCount(hMenu))
1119 AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); // Separator
1120
1121 // "Input System (IME) configuration..."
1122 LoadString(g_hInst, IDS_INPUTSYSTEM, szText, _countof(szText));
1123 AppendMenu(hMenu, MF_STRING, ID_INPUTSYSTEM, szText);
1124 }
1125 }
1126 else
1127 {
1128 if (!(g_anFlags[g_iKL] & LAYOUTF_REMOVE_LEFT_DEF_MENU)) // Add default menu items?
1129 {
1130 if (GetMenuItemCount(hMenu))
1131 AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); // Separator
1132
1133 if (!IS_KOREAN_IME_HKL(hKL)) // Not Korean IME?
1134 {
1135 // "IME ON / OFF"
1136 bImeOn = (dwImeStatus == IME_STATUS_IME_OPEN);
1137 UINT nId = (bImeOn ? IDS_IME_ON : IDS_IME_OFF);
1138 LoadString(g_hInst, nId, szText, _countof(szText));
1139 AppendMenu(hMenu, MF_STRING, ID_IMEONOFF, szText);
1140 }
1141
1143 IsWindow(hwndIme)) // Is Soft Keyboard available?
1144 {
1145 // "Soft Keyboard ON / OFF"
1147 UINT nId = (bSoftOn ? IDS_SOFTKBD_ON : IDS_SOFTKBD_OFF);
1148 LoadString(g_hInst, nId, szText, _countof(szText));
1149 AppendMenu(hMenu, MF_STRING, ID_SOFTKBDONOFF, szText);
1150 }
1151
1152 if (GetMenuItemCount(hMenu))
1153 AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); // Separator
1154
1155 // "Show toolbar"
1156 LoadString(g_hInst, IDS_SHOWTOOLBAR, szText, _countof(szText));
1157 AppendMenu(hMenu, MF_STRING, ID_SHOWTOOLBAR, szText);
1158 bShowToolbar = IsRegImeToolbarShown();
1159 if (bShowToolbar)
1161 }
1162 }
1163
1164 if (!GetMenuItemCount(hMenu)) // No items?
1165 {
1166 // Clean up
1167 DestroyMenu(hMenu);
1169
1170 SetForegroundWindow(hwndTarget);
1171 return;
1172 }
1173
1174 // TrackPopupMenuEx flags
1176 uFlags |= (bRightButton ? TPM_RIGHTBUTTON : TPM_LEFTBUTTON);
1177
1178 // Exclude the notification area
1179 TPMPARAMS params = { sizeof(params) };
1181
1182 // Show the popup menu
1183 INT nID = TrackPopupMenuEx(hMenu, uFlags, pt.x, pt.y, hwnd, &params);
1184
1185 // Workaround of TrackPopupMenu's bug
1186 PostMessage(hwnd, WM_NULL, 0, 0);
1187
1188 if (nID) // Action!
1189 {
1190 if (nID >= ID_STARTIMEMENU) // IME internal menu ID?
1191 {
1192 MENUITEMINFO mii = { sizeof(mii), MIIM_DATA };
1193 GetMenuItemInfo(hMenu, nID, FALSE, &mii);
1194
1195 if (pImeMenu)
1196 nID = GetRealImeMenuID(pImeMenu, nID);
1197
1198 if (SetPenMenuData)
1199 SetPenMenuData(nID, mii.dwItemData);
1200
1202 }
1203 else // Otherwise action of IME menu item
1204 {
1205 switch (nID)
1206 {
1207 case ID_INPUTSYSTEM:
1208 if (IS_IME_HKL(hKL))
1210 break;
1211 case ID_IMEONOFF:
1212 ImmSetOpenStatus(hIMC, !bImeOn);
1213 break;
1214 case ID_SOFTKBDONOFF:
1215 PostMessage(hwndIme, WM_IME_SYSTEM, IMS_SOFTKBDONOFF, !bSoftOn);
1216 break;
1217 case ID_SHOWTOOLBAR:
1218 ShowImeToolbar(hwndTarget, !bShowToolbar);
1219 break;
1220 default:
1221 {
1222 PostMessage(hwnd, WM_COMMAND, nID, 0);
1223 break;
1224 }
1225 }
1226 }
1227 }
1228
1229 // Clean up
1230 DestroyMenu(hMenu);
1232
1233 SetForegroundWindow(hwndTarget);
1234}
INT GetRealImeMenuID(_In_ const IMEMENUNODE *pMenu, _In_ INT nFakeID)
Definition: imemenu.c:202
PIMEMENUNODE CreateImeMenu(_In_ HIMC hIMC, _Inout_opt_ PIMEMENUITEMINFO lpImeParentMenu, _In_ BOOL bRightMenu)
Definition: imemenu.c:62
VOID CleanupImeMenus(VOID)
Definition: imemenu.c:246
HMENU MenuFromImeMenu(_In_ const IMEMENUNODE *pMenu)
Definition: imemenu.c:188
#define IDS_INPUTSYSTEM
Definition: resource.h:15
#define IDS_SOFTKBD_OFF
Definition: resource.h:13
#define ID_IMEONOFF
Definition: resource.h:21
#define IDS_SHOWTOOLBAR
Definition: resource.h:14
#define ID_SHOWTOOLBAR
Definition: resource.h:23
#define IDS_IME_OFF
Definition: resource.h:11
#define ID_INPUTSYSTEM
Definition: resource.h:20
#define IDS_SOFTKBD_ON
Definition: resource.h:12
#define IDS_IME_ON
Definition: resource.h:10
#define ID_SOFTKBDONOFF
Definition: resource.h:22
#define WARN(fmt,...)
Definition: precomp.h:61
#define ID_STARTIMEMENU
Definition: imemenu.h:12
#define IMS_IMEMENUITEMSELECTED
Definition: imm32_undoc.h:50
#define IMS_GETCONVSTATUS
Definition: imm32_undoc.h:44
#define IMS_CONFIGURE
Definition: imm32_undoc.h:40
#define IMS_SOFTKBDONOFF
Definition: imm32_undoc.h:43
#define IME_CMODE_SOFTKBD
Definition: imm.h:349
DWORD WINAPI ImmGetProperty(_In_ HKL hKL, _In_ DWORD fdwIndex)
Definition: ime.c:767
#define IGP_CONVERSION
Definition: imm.h:301
BOOL WINAPI ImmSetOpenStatus(_In_ HIMC hIMC, _In_ BOOL fOpen)
Definition: ime.c:1020
static BOOL IsRegImeToolbarShown(VOID)
Definition: kbswitch.c:1022
static DWORD GetImeStatus(HWND hwndTarget)
Definition: kbswitch.c:462
#define LAYOUTF_REMOVE_LEFT_DEF_MENU
Definition: kbswitch.c:75
BYTE g_anFlags[MAX_KLS]
Definition: kbswitch.c:65
#define LAYOUTF_FAR_EAST
Definition: kbswitch.c:72
#define LAYOUTF_REMOVE_RIGHT_DEF_MENU
Definition: kbswitch.c:76
#define IS_KOREAN_IME_HKL(hKL)
Definition: kbswitch.c:45
FN_SetPenMenuData SetPenMenuData
Definition: kbswitch.c:53
static VOID ShowImeToolbar(HWND hwndTarget, BOOL bShowToolbar)
Definition: kbswitch.c:1047
ULONG_PTR dwItemData
Definition: winuser.h:3326
int WINAPI GetMenuItemCount(_In_opt_ HMENU)
#define AppendMenu
Definition: winuser.h:5816
#define MF_STRING
Definition: winuser.h:138
#define MF_SEPARATOR
Definition: winuser.h:137
#define LoadString
Definition: winuser.h:5904
#define GetMenuItemInfo
Definition: winuser.h:5873
#define MIIM_DATA
Definition: winuser.h:737

Referenced by WndProc().

◆ KbSwitch_OnSettingChange()

static void KbSwitch_OnSettingChange ( HWND  hwnd,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1295 of file kbswitch.c.

1296{
1297 if (wParam == SPI_SETNONCLIENTMETRICS)
1299}

Referenced by WndProc().

◆ KbSwitch_OnTimer()

static void KbSwitch_OnTimer ( HWND  hwnd,
UINT_PTR  nTimerID 
)
static

Definition at line 968 of file kbswitch.c.

969{
970 if (nTimerID == TIMER_ID_LANG_CHANGED_DELAYED)
971 {
972 KillTimer(hwnd, nTimerID);
973 HKL hKL = GetActiveKL();
974 UpdateLayoutList(hKL);
977 }
978}
UINT UpdateLanguageDisplay(HWND hwnd, HKL hKL)
Definition: kbswitch.c:892

Referenced by WndProc().

◆ KbSwitch_OnWindowActivate()

static LRESULT KbSwitch_OnWindowActivate ( HWND  hwnd,
HWND hwndTarget  OPTIONAL,
LPARAM lParam  OPTIONAL 
)
static

Definition at line 1284 of file kbswitch.c.

1285{
1286 TRACE("WM_WINDOW_ACTIVATE: hwndTarget:%p, lParam:%p\n", hwndTarget, lParam);
1287 HWND hwndFore = hwndTarget ? hwndTarget : GetForegroundWindow();
1288 if (RememberLastActive(hwnd, hwndFore))
1289 return UpdateLanguageDisplayCurrent(hwnd, hwndFore);
1290 return 0;
1291}
static BOOL RememberLastActive(HWND hwnd, HWND hwndFore)
Definition: kbswitch.c:916
UINT UpdateLanguageDisplayCurrent(HWND hwnd, HWND hwndFore)
Definition: kbswitch.c:907

Referenced by WndProc().

◆ LoadDefaultPenIcon()

static HICON LoadDefaultPenIcon ( PCWSTR  szImeFile,
HKL  hKL 
)
static

Definition at line 490 of file kbswitch.c.

491{
493 DWORD dwImeStatus = GetImeStatus(hwndTarget);
494
495 INT nIconID = -1;
496 if (IS_KOREAN_IME_HKL(hKL)) // Korean IME?
497 {
498 if (dwImeStatus != IME_STATUS_NO_IME)
499 {
500 if (dwImeStatus & IME_STATUS_IME_CLOSED)
501 {
502 nIconID = IDI_KOREAN_A_HALF;
503 }
504 else
505 {
506 if (dwImeStatus & IME_STATUS_IME_FULLSHAPE)
507 {
508 if (dwImeStatus & IME_STATUS_IME_NATIVE)
509 nIconID = IDI_KOREAN_JR_FULL;
510 else
511 nIconID = IDI_KOREAN_A_FULL;
512 }
513 else
514 {
515 if (dwImeStatus & IME_STATUS_IME_NATIVE)
516 nIconID = IDI_KOREAN_JR_HALF;
517 else
518 nIconID = IDI_KOREAN_A_HALF;
519 }
520 }
521 }
522 }
523 else
524 {
525 if (dwImeStatus & IME_STATUS_IME_CLOSED)
526 nIconID = IDI_IME_CLOSED;
527 else if (dwImeStatus & IME_STATUS_IME_OPEN)
528 nIconID = IDI_IME_OPEN;
529 else
530 nIconID = IDI_IME_DISABLED;
531 }
532
533 if (nIconID < 0)
534 return NULL;
535
536 return LoadIcon(g_hHookDLL, MAKEINTRESOURCE(nIconID));
537}
#define IDI_IME_OPEN
Definition: resource.h:2
#define IDI_KOREAN_A_FULL
Definition: resource.h:6
#define IDI_KOREAN_A_HALF
Definition: resource.h:5
#define IDI_KOREAN_JR_HALF
Definition: resource.h:7
#define IDI_IME_CLOSED
Definition: resource.h:3
#define IDI_IME_DISABLED
Definition: resource.h:4
#define IDI_KOREAN_JR_FULL
Definition: resource.h:8

Referenced by UpdatePenIcon().

◆ LoadSpecialIds()

static VOID LoadSpecialIds ( VOID  )
static

Definition at line 97 of file kbswitch.c.

98{
99 TCHAR szKLID[KL_NAMELENGTH], szLayoutId[16];
100 DWORD dwSize, dwIndex;
101 HKEY hKey, hLayoutKey;
102
103 g_cSpecialIds = 0;
104
106 TEXT("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts"),
107 0, KEY_READ, &hKey) != ERROR_SUCCESS)
108 {
109 return;
110 }
111
112 for (dwIndex = 0; dwIndex < 1000; ++dwIndex)
113 {
114 dwSize = _countof(szKLID);
115 if (RegEnumKeyEx(hKey, dwIndex, szKLID, &dwSize, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
116 break;
117
118 if (RegOpenKeyEx(hKey, szKLID, 0, KEY_READ, &hLayoutKey) != ERROR_SUCCESS)
119 continue;
120
121 dwSize = sizeof(szLayoutId);
122 if (RegQueryValueEx(hLayoutKey, TEXT("Layout Id"), NULL, NULL,
123 (LPBYTE)szLayoutId, &dwSize) == ERROR_SUCCESS)
124 {
125 DWORD dwKLID = _tcstoul(szKLID, NULL, 16);
126 WORD wLangId = LOWORD(dwKLID), wLayoutId = LOWORD(_tcstoul(szLayoutId, NULL, 16));
127 HKL hKL = (HKL)(LONG_PTR)(SPECIAL_MASK | MAKELONG(wLangId, wLayoutId));
128
129 /* Add a special ID */
133 _countof(g_SpecialIds[g_cSpecialIds].szKLID), szKLID);
135 }
136
137 RegCloseKey(hLayoutKey);
138
140 {
141 ERR("g_SpecialIds is full!");
142 break;
143 }
144 }
145
147}
#define SPECIAL_MASK
Definition: debug.h:13
unsigned short WORD
Definition: ntddk_ex.h:93
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
DWORD dwLayoutId
Definition: kbswitch.c:87
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define RegEnumKeyEx
Definition: winreg.h:510
#define KL_NAMELENGTH
Definition: winuser.h:122

Referenced by KbSwitch_OnCreate().

◆ OnIndicatorMsg()

static VOID OnIndicatorMsg ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1327 of file kbswitch.c.

1328{
1329 HKL hKL = (HKL)lParam;
1330 UINT iKL = GetLayoutIndexFromHKL(hKL);
1331 if (iKL >= g_cKLs)
1332 return;
1333
1334 g_iKL = iKL;
1335
1336 switch (uMsg)
1337 {
1338 case INDICM_SETIMEICON:
1339 if (LOWORD(wParam) == MAXWORD)
1340 {
1341 g_anFlags[iKL] &= ~LAYOUTF_IME_ICON;
1342 g_aiSysPenIcons[iKL] = MAXWORD;
1343 }
1344 else
1345 {
1347 g_aiSysPenIcons[iKL] = (WORD)wParam;
1348 }
1349 UpdatePenIcon(hwnd, iKL);
1350 break;
1351
1353 if (LOWORD(wParam) == MAXWORD)
1354 {
1355 g_anFlags[iKL] &= ~LAYOUTF_TOOLTIP_ATOM;
1356 }
1357 else
1358 {
1361 }
1362 UpdatePenIcon(hwnd, iKL);
1363 break;
1364
1366 if (wParam)
1367 {
1368 if (wParam & RDMI_LEFT)
1370 if (wParam & RDMI_RIGHT)
1372 }
1373 else
1374 {
1376 }
1377 break;
1378
1379 default:
1380 {
1381 ERR("uMsg: %u\n", uMsg);
1382 return;
1383 }
1384 }
1385}
#define INDICM_SETIMETOOLTIPS
Definition: indicml.h:23
#define RDMI_RIGHT
Definition: indicml.h:28
#define INDICM_REMOVEDEFAULTMENUITEMS
Definition: indicml.h:24
#define INDICM_SETIMEICON
Definition: indicml.h:22
#define RDMI_LEFT
Definition: indicml.h:27
static UINT GetLayoutIndexFromHKL(HKL hKL)
Definition: kbswitch.c:227
WORD g_anToolTipAtoms[MAX_KLS]
Definition: kbswitch.c:63
#define LAYOUTF_TOOLTIP_ATOM
Definition: kbswitch.c:74
WORD g_aiSysPenIcons[MAX_KLS]
Definition: kbswitch.c:62
#define LAYOUTF_IME_ICON
Definition: kbswitch.c:73
#define MAXWORD

Referenced by WndProc().

◆ RememberLastActive()

static BOOL RememberLastActive ( HWND  hwnd,
HWND  hwndFore 
)
static

Definition at line 916 of file kbswitch.c.

917{
918 hwndFore = GetAncestor(hwndFore, GA_ROOT);
919
920 if (!IsWindowVisible(hwndFore))
921 return FALSE;
922
923 if (IsWndClassName(hwndFore, INDICATOR_CLASS) ||
924 IsWndClassName(hwndFore, TEXT("Shell_TrayWnd")))
925 {
926 return FALSE; /* Special window */
927 }
928
929 g_hwndLastActive = hwndFore;
930 return TRUE;
931}
#define GA_ROOT
Definition: winuser.h:2865
BOOL WINAPI IsWindowVisible(_In_ HWND)
HWND WINAPI GetAncestor(_In_ HWND, _In_ UINT)
Definition: window.c:929

Referenced by KbSwitch_OnWindowActivate().

◆ SetHooks()

static BOOL SetHooks ( VOID  )
static

Definition at line 839 of file kbswitch.c.

840{
841 g_hHookDLL = LoadLibrary(_T("indicdll.dll"));
842 if (!g_hHookDLL)
843 return FALSE;
844
849
851 {
852 ERR("SetHooks failed\n");
853 return FALSE;
854 }
855
856 TRACE("SetHooks OK\n");
857 return TRUE;
858}
#define GetProcAddress(x, y)
Definition: compat.h:753
#define IFN_KbSwitchSetHooks
Definition: kbswitch.c:835
#define IFN_SetPenMenuData
Definition: kbswitch.c:836
VOID(APIENTRY * FN_SetPenMenuData)(UINT nID, DWORD_PTR dwItemData)
Definition: kbswitch.c:50
BOOL(APIENTRY * FN_KbSwitchSetHooks)(BOOL bDoHook)
Definition: kbswitch.c:49
#define LoadLibrary
Definition: winbase.h:3903
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581

Referenced by KbSwitch_OnCreate().

◆ ShowImeToolbar()

static VOID ShowImeToolbar ( HWND  hwndTarget,
BOOL  bShowToolbar 
)
static

Definition at line 1047 of file kbswitch.c.

1048{
1049 HKEY hKey;
1050 LSTATUS error = RegOpenKey(HKEY_CURRENT_USER, TEXT("Control Panel\\Input Method"), &hKey);
1051 if (error)
1052 {
1053 ERR("Cannot open regkey: 0x%lX\n", error);
1054 return;
1055 }
1056
1057 WCHAR szText[8];
1058 StringCchPrintf(szText, _countof(szText), TEXT("%d"), bShowToolbar);
1059
1060 DWORD cbValue = (lstrlen(szText) + 1) * sizeof(TCHAR);
1061 RegSetValueEx(hKey, TEXT("Show Status"), 0, REG_SZ, (PBYTE)szText, cbValue);
1063
1064 HWND hwndIme = ImmGetDefaultIMEWnd(hwndTarget);
1065 PostMessage(hwndIme, WM_IME_SYSTEM, IMS_NOTIFYIMESHOW, bShowToolbar);
1066}
#define IMS_NOTIFYIMESHOW
Definition: imm32_undoc.h:35
#define REG_SZ
Definition: layer.c:22
#define lstrlen
Definition: winbase.h:3917
#define RegSetValueEx
Definition: winreg.h:533

Referenced by KbSwitch_OnPenIconMsg().

◆ UpdateLanguageDisplay()

UINT UpdateLanguageDisplay ( HWND  hwnd,
HKL  hKL 
)

Definition at line 892 of file kbswitch.c.

893{
894 TCHAR szKLID[MAX_PATH], szLangName[MAX_PATH];
896
897 GetKLIDFromHKL(hKL, szKLID, _countof(szKLID));
898 LangID = (LANGID)_tcstoul(szKLID, NULL, 16);
899 GetLocaleInfo(LangID, LOCALE_SLANGUAGE, szLangName, _countof(szLangName));
900 UpdateTrayIcon(hwnd, szKLID, szLangName);
901 g_iKL = GetLayoutNum(hKL);
902
903 return 0;
904}
static UINT GetLayoutNum(HKL hKL)
Definition: kbswitch.c:878

Referenced by KbSwitch_OnTimer(), and UpdateLanguageDisplayCurrent().

◆ UpdateLanguageDisplayCurrent()

UINT UpdateLanguageDisplayCurrent ( HWND  hwnd,
HWND  hwndFore 
)

Definition at line 907 of file kbswitch.c.

908{
909 DWORD dwThreadID = GetWindowThreadProcessId(GetTargetWindow(hwndFore), NULL);
910 HKL hKL = GetKeyboardLayout(dwThreadID);
912
913 return 0;
914}

Referenced by KbSwitch_OnWindowActivate().

◆ UpdateLayoutList()

static VOID UpdateLayoutList ( HKL hKL  OPTIONAL)
static

Definition at line 237 of file kbswitch.c.

238{
239 if (!hKL)
240 hKL = GetActiveKL();
241
242 HICON ahSysPenIcons[MAX_KLS];
243 WORD aiSysPenIcons[MAX_KLS];
244 BYTE anFlags[MAX_KLS];
245 ZeroMemory(ahSysPenIcons, sizeof(ahSysPenIcons));
246 FillMemory(aiSysPenIcons, sizeof(aiSysPenIcons), 0xFF);
247 ZeroMemory(anFlags, sizeof(anFlags));
248
249 HKL ahKLs[MAX_KLS];
250 UINT iKL, nKLs = GetKeyboardLayoutList(_countof(ahKLs), ahKLs);
251
252 /* Reuse old icons and flags */
253 for (iKL = 0; iKL < nKLs; ++iKL)
254 {
255 LANGID wLangID = LOWORD(ahKLs[iKL]);
256 switch (wLangID)
257 {
260 case LANGID_JAPANESE:
261 case LANGID_KOREAN:
262 anFlags[iKL] |= LAYOUTF_FAR_EAST;
263 break;
264 default:
265 anFlags[iKL] &= ~LAYOUTF_FAR_EAST;
266 break;
267 }
268
269 UINT iKL2;
270 for (iKL2 = 0; iKL2 < g_cKLs; ++iKL2)
271 {
272 if (ahKLs[iKL] == g_ahKLs[iKL2])
273 {
274 ahSysPenIcons[iKL] = g_ahSysPenIcons[iKL2];
275 aiSysPenIcons[iKL] = g_aiSysPenIcons[iKL2];
276 anFlags[iKL] = g_anFlags[iKL2];
277
278 g_ahSysPenIcons[iKL2] = NULL;
279 break;
280 }
281 }
282 }
283
285
286 g_cKLs = nKLs;
287
288 C_ASSERT(sizeof(g_ahKLs) == sizeof(ahKLs));
289 CopyMemory(g_ahKLs, ahKLs, sizeof(g_ahKLs));
290
291 C_ASSERT(sizeof(g_ahSysPenIcons) == sizeof(ahSysPenIcons));
292 CopyMemory(g_ahSysPenIcons, ahSysPenIcons, sizeof(g_ahSysPenIcons));
293
294 C_ASSERT(sizeof(g_anFlags) == sizeof(anFlags));
295 CopyMemory(g_anFlags, anFlags, sizeof(g_anFlags));
296
298}
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
#define C_ASSERT(e)
Definition: intsafe.h:73
#define MAX_KLS
Definition: kbswitch.c:47
#define LANGID_KOREAN
Definition: kbswitch.h:25
#define LANGID_JAPANESE
Definition: kbswitch.h:24
#define LANGID_CHINESE_SIMPLIFIED
Definition: kbswitch.h:22
#define LANGID_CHINESE_TRADITIONAL
Definition: kbswitch.h:23
#define CopyMemory
Definition: winbase.h:1751
UINT WINAPI GetKeyboardLayoutList(_In_ int nBuff, _Out_writes_to_opt_(nBuff, return) HKL FAR *lpList)
unsigned char BYTE
Definition: xxhash.c:193

Referenced by KbSwitch_OnCreate(), KbSwitch_OnDefault(), KbSwitch_OnNotifyIconMsg(), and KbSwitch_OnTimer().

◆ UpdatePenIcon()

static VOID UpdatePenIcon ( HWND  hwnd,
UINT  iKL 
)
static

Definition at line 547 of file kbswitch.c.

548{
549 BOOL bHadIcon = (g_ahSysPenIcons[iKL] != NULL);
550 DeletePenIcon(hwnd, iKL);
551
552 // Not Far-East?
553 if (!(g_anFlags[iKL] & LAYOUTF_FAR_EAST))
554 {
555 if (bHadIcon)
557 return;
558 }
559
560 // Get IME file
561 TCHAR szKLID[CCH_LAYOUT_ID + 1], szImeFile[MAX_PATH];
562 GetKLIDFromHKL(g_ahKLs[iKL], szKLID, _countof(szKLID));
563 if (!GetImeFile(szImeFile, _countof(szImeFile), szKLID))
564 {
565 if (bHadIcon)
567 return;
568 }
569
570 // Load pen icon
571 if (g_anFlags[iKL] & LAYOUTF_IME_ICON)
572 g_ahSysPenIcons[iKL] = FakeExtractIcon(szImeFile, g_aiSysPenIcons[iKL]);
573 if (!g_ahSysPenIcons[iKL])
574 g_ahSysPenIcons[iKL] = LoadDefaultPenIcon(szImeFile, g_ahKLs[iKL]);
575 if (!g_ahSysPenIcons[iKL])
576 {
577 if (bHadIcon)
579 return;
580 }
581
582 // Add pen icon
587
588 if (g_anToolTipAtoms[iKL])
590 else
592
593 Shell_NotifyIcon((bHadIcon ? NIM_MODIFY : NIM_ADD), &nid);
594}
#define ImmGetDescription
Definition: imm.h:827
#define WM_PENICONMSG
Definition: kbswitch.c:36
static HICON LoadDefaultPenIcon(PCWSTR szImeFile, HKL hKL)
Definition: kbswitch.c:490
static VOID DeletePenIcon(HWND hwnd, UINT iKL)
Definition: kbswitch.c:201
static VOID DeletePenNotifyIcon(HWND hwnd)
Definition: kbswitch.c:540
#define NIM_MODIFY
Definition: shellapi.h:95
#define GlobalGetAtomName
Definition: winbase.h:3901

Referenced by KbSwitch_OnCreate(), KbSwitch_OnDefault(), KbSwitch_OnTimer(), and OnIndicatorMsg().

◆ UpdateTrayIcon()

static VOID UpdateTrayIcon ( HWND  hwnd,
LPTSTR  szKLID,
LPTSTR  szName 
)
static

Definition at line 731 of file kbswitch.c.

732{
733 NOTIFYICONDATA tnid =
734 {
736 };
737 TCHAR szImeFile[80];
738
739 GetImeFile(szImeFile, _countof(szImeFile), szKLID);
740
742 tnid.hIcon = CreateTrayIcon(szKLID, szImeFile);
744
746
747 if (g_hTrayIcon)
749 g_hTrayIcon = tnid.hIcon;
750}

Referenced by ActivateLayout(), AddJobW(), StartDocPrinterW(), and UpdateLanguageDisplay().

◆ UpdateTrayInfo()

static VOID UpdateTrayInfo ( VOID  )
static

Definition at line 79 of file kbswitch.c.

80{
81 g_hTrayWnd = FindWindow(TEXT("Shell_TrayWnd"), NULL);
83}
HWND g_hTrayWnd
Definition: kbswitch.c:68
#define FindWindow
Definition: winuser.h:5862
#define FindWindowEx
Definition: winuser.h:5863

Referenced by KbSwitch_OnCreate(), and KbSwitch_OnDefault().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( internat  )

◆ WndProc()

LRESULT CALLBACK WndProc ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 1388 of file kbswitch.c.

1389{
1390 switch (uMsg)
1391 {
1392 case WM_CREATE:
1393 return KbSwitch_OnCreate(hwnd);
1394
1395 case WM_TIMER:
1397 break;
1398
1399 case WM_LANG_CHANGED: /* Comes from indicdll.dll and this module */
1401
1402 case WM_WINDOW_ACTIVATE: /* Comes from indicdll.dll and this module */
1404
1405 case WM_NOTIFYICONMSG:
1407 break;
1408
1409 case WM_PENICONMSG:
1411 break;
1412
1413 case WM_COMMAND:
1415 break;
1416
1417 case WM_SETTINGCHANGE:
1419 break;
1420
1421 case WM_DESTROY:
1423 break;
1424
1425 case INDICM_SETIMEICON:
1428 if (InSendMessageEx(NULL))
1429 break; /* Must be a PostMessage call for quick response, not SendMessage */
1430
1432 break;
1433
1434 case WM_INPUTLANGCHANGEREQUEST:
1435 break;
1436
1437 default:
1438 return KbSwitch_OnDefault(hwnd, uMsg, wParam, lParam);
1439 }
1440
1441 return 0;
1442}
static void KbSwitch_OnCommand(HWND hwnd, UINT nID)
Definition: kbswitch.c:1238
static LRESULT KbSwitch_OnWindowActivate(HWND hwnd, HWND hwndTarget OPTIONAL, LPARAM lParam OPTIONAL)
Definition: kbswitch.c:1284
static LRESULT KbSwitch_OnDefault(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: kbswitch.c:1302
static void KbSwitch_OnSettingChange(HWND hwnd, WPARAM wParam, LPARAM lParam)
Definition: kbswitch.c:1295
static VOID KbSwitch_OnPenIconMsg(HWND hwnd, UINT uMouseMsg)
Definition: kbswitch.c:1070
static LRESULT KbSwitch_OnLangChanged(HWND hwnd, HWND hwndTarget OPTIONAL, HKL hKL OPTIONAL)
Definition: kbswitch.c:1273
static void KbSwitch_OnNotifyIconMsg(HWND hwnd, UINT uMouseMsg)
Definition: kbswitch.c:982
static void KbSwitch_OnTimer(HWND hwnd, UINT_PTR nTimerID)
Definition: kbswitch.c:968
static VOID OnIndicatorMsg(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: kbswitch.c:1327
static INT KbSwitch_OnCreate(HWND hwnd)
Definition: kbswitch.c:935
static void KbSwitch_OnDestroy(HWND hwnd)
Definition: kbswitch.c:957
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
DWORD WINAPI InSendMessageEx(LPVOID lpReserved)
Definition: message.c:1391
#define WM_CREATE
Definition: winuser.h:1627
#define WM_SETTINGCHANGE
Definition: winuser.h:1648
#define WM_TIMER
Definition: winuser.h:1761
#define WM_DESTROY
Definition: winuser.h:1628

Referenced by _tWinMain().

Variable Documentation

◆ g_ahKLs

◆ g_ahSysPenIcons

HICON g_ahSysPenIcons[MAX_KLS] = { NULL }

Definition at line 64 of file kbswitch.c.

Referenced by DeletePenIcon(), DestroyPenIcons(), UpdateLayoutList(), and UpdatePenIcon().

◆ g_aiSysPenIcons

WORD g_aiSysPenIcons[MAX_KLS] = { 0 }

Definition at line 62 of file kbswitch.c.

Referenced by OnIndicatorMsg(), UpdateLayoutList(), and UpdatePenIcon().

◆ g_anFlags

BYTE g_anFlags[MAX_KLS] = { 0 }

Definition at line 65 of file kbswitch.c.

Referenced by KbSwitch_OnPenIconMsg(), OnIndicatorMsg(), UpdateLayoutList(), and UpdatePenIcon().

◆ g_anToolTipAtoms

WORD g_anToolTipAtoms[MAX_KLS] = { 0 }

Definition at line 63 of file kbswitch.c.

Referenced by OnIndicatorMsg(), and UpdatePenIcon().

◆ g_cKLs

◆ g_cSpecialIds

INT g_cSpecialIds = 0

Definition at line 95 of file kbswitch.c.

Referenced by GetKLIDFromHKL(), and LoadSpecialIds().

◆ g_hHookDLL

HMODULE g_hHookDLL = NULL

Definition at line 56 of file kbswitch.c.

Referenced by DeleteHooks(), LoadDefaultPenIcon(), and SetHooks().

◆ g_hInst

◆ g_hTrayIcon

HICON g_hTrayIcon = NULL

Definition at line 57 of file kbswitch.c.

Referenced by AddTrayIcon(), DeleteTrayIcon(), and UpdateTrayIcon().

◆ g_hTrayNotifyWnd

HWND g_hTrayNotifyWnd = NULL

Definition at line 69 of file kbswitch.c.

Referenced by KbSwitch_OnNotifyIconMsg(), KbSwitch_OnPenIconMsg(), and UpdateTrayInfo().

◆ g_hTrayWnd

HWND g_hTrayWnd = NULL

Definition at line 68 of file kbswitch.c.

Referenced by UpdateTrayInfo().

◆ g_hwndLastActive

HWND g_hwndLastActive = NULL

◆ g_iKL

◆ g_SpecialIds

SPECIAL_ID g_SpecialIds[MAX_SPECIAL_IDS]

Definition at line 94 of file kbswitch.c.

Referenced by GetKLIDFromHKL(), and LoadSpecialIds().

◆ g_uShellHookMessage

UINT g_uShellHookMessage = 0

Definition at line 67 of file kbswitch.c.

Referenced by _tWinMain(), and KbSwitch_OnDefault().

◆ g_uTaskbarRestartMsg

UINT g_uTaskbarRestartMsg = 0

Definition at line 66 of file kbswitch.c.

Referenced by KbSwitch_OnCreate(), and KbSwitch_OnDefault().

◆ KbSwitchSetHooks

FN_KbSwitchSetHooks KbSwitchSetHooks = NULL

Definition at line 52 of file kbswitch.c.

Referenced by DeleteHooks(), and SetHooks().

◆ SetPenMenuData

FN_SetPenMenuData SetPenMenuData = NULL

Definition at line 53 of file kbswitch.c.

Referenced by KbSwitch_OnPenIconMsg(), and SetHooks().