Author: dchapyshev
Date: Sun Apr 27 10:40:42 2008
New Revision: 33168
URL:
http://svn.reactos.org/svn/reactos?rev=33168&view=rev
Log:
- Implement current layout indicator
Modified:
trunk/reactos/base/applications/kbswitch/kbswitch.c
trunk/reactos/base/applications/kbswitch/kbswitch.rbuild
Modified: trunk/reactos/base/applications/kbswitch/kbswitch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch…
==============================================================================
--- trunk/reactos/base/applications/kbswitch/kbswitch.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/kbswitch/kbswitch.c [iso-8859-1] Sun Apr 27 10:40:42
2008
@@ -10,24 +10,99 @@
#define WM_NOTIFYICONMSG (WM_USER + 248)
+static BOOL
+GetLayoutID(LPTSTR szLayoutNum, LPTSTR szLCID);
+
HINSTANCE hInst;
HANDLE hProcessHeap;
+static HICON
+CreateTrayIcon(LPTSTR szLCID)
+{
+ LANGID lId;
+ TCHAR szBuf[3];
+ HDC hdc, hdcsrc;
+ HBITMAP hBitmap, hBmpNew, hBmpOld;
+ RECT rect;
+ DWORD bkColor, bkText;
+ HFONT hFont = NULL;
+ ICONINFO IconInfo;
+ HICON hIcon = NULL;
+
+ lId = (LANGID)_tcstoul(szLCID, NULL, 16);
+ if (GetLocaleInfo(lId,
+ LOCALE_SISO639LANGNAME,
+ szBuf,
+ sizeof(szBuf) / sizeof(TCHAR)) == 0)
+ {
+ lstrcpy(szBuf, _T("??\0"));
+ }
+
+ hdcsrc = GetDC(NULL);
+ hdc = CreateCompatibleDC(hdcsrc);
+ hBitmap = CreateCompatibleBitmap(hdcsrc, 16, 16);
+ ReleaseDC(NULL, hdcsrc);
+
+ if (hdc && hBitmap)
+ {
+ hBmpNew = CreateBitmap(16, 16, 1, 1, NULL);
+ if (hBmpNew)
+ {
+ hBmpOld = SelectObject(hdc, hBitmap);
+ rect.right = 16;
+ rect.left = 0;
+ rect.bottom = 16;
+ rect.top = 0;
+
+ bkColor = SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
+ bkText = SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
+
+ ExtTextOut(hdc, rect.left, rect.top, ETO_OPAQUE, &rect, _T(""),
0, NULL);
+
+ hFont = CreateFont(-11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
ANSI_CHARSET,
+ OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
+ DEFAULT_QUALITY, FF_DONTCARE, _T("Tahoma"));
+
+ SelectObject(hdc, hFont);
+ DrawText(hdc, _tcsupr(szBuf), 2, &rect,
DT_SINGLELINE|DT_CENTER|DT_VCENTER);
+ SelectObject(hdc, hBmpNew);
+ PatBlt(hdc, 0, 0, 16, 16, BLACKNESS);
+ SelectObject(hdc, hBmpOld);
+
+ IconInfo.hbmColor = hBitmap;
+ IconInfo.hbmMask = hBmpNew;
+ IconInfo.fIcon = TRUE;
+
+ hIcon = CreateIconIndirect(&IconInfo);
+
+ DeleteObject(hBmpNew);
+ DeleteObject(hBmpOld);
+ DeleteObject(hFont);
+ }
+ }
+
+ DeleteDC(hdc);
+ DeleteObject(hBitmap);
+
+ return hIcon;
+}
+
static VOID
-AddTrayIcon(HWND hwnd, HICON hIcon)
+AddTrayIcon(HWND hwnd)
{
NOTIFYICONDATA tnid;
+ TCHAR szLCID[CCH_LAYOUT_ID + 1];
+
+ GetLayoutID(_T("1"), szLCID);
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = hwnd;
tnid.uID = 1;
tnid.uFlags = NIF_ICON | NIF_MESSAGE;
tnid.uCallbackMessage = WM_NOTIFYICONMSG;
- tnid.hIcon = hIcon;
+ tnid.hIcon = CreateTrayIcon(szLCID);
Shell_NotifyIcon(NIM_ADD, &tnid);
-
- if (hIcon) DestroyIcon(hIcon);
}
static VOID
@@ -40,6 +115,21 @@
tnid.uID = 1;
Shell_NotifyIcon(NIM_DELETE, &tnid);
+}
+
+static VOID
+UpdateTrayIcon(HWND hwnd, LPTSTR szLCID)
+{
+ NOTIFYICONDATA tnid;
+
+ tnid.cbSize = sizeof(NOTIFYICONDATA);
+ tnid.hWnd = hwnd;
+ tnid.uID = 1;
+ tnid.uFlags = NIF_ICON | NIF_MESSAGE;
+ tnid.uCallbackMessage = WM_NOTIFYICONMSG;
+ tnid.hIcon = CreateTrayIcon(szLCID);
+
+ Shell_NotifyIcon(NIM_MODIFY, &tnid);
}
static BOOL
@@ -124,7 +214,7 @@
}
static VOID
-ActivateLayout(ULONG uLayoutNum)
+ActivateLayout(HWND hwnd, ULONG uLayoutNum)
{
HKL hKl;
TCHAR szLayoutNum[CCH_ULONG_DEC + 1];
@@ -132,8 +222,10 @@
_ultot(uLayoutNum, szLayoutNum, 10);
GetLayoutID(szLayoutNum, szLCID);
+ CreateTrayIcon(szLCID);
// Switch to the new keyboard layout
+ UpdateTrayIcon(hwnd, szLCID);
hKl = LoadKeyboardLayout(szLCID, KLF_ACTIVATE);
SystemParametersInfo(SPI_SETDEFAULTINPUTLANG, 0, &hKl, SPIF_SENDWININICHANGE);
EnumWindows(EnumWindowsProc, (LPARAM) hKl);
@@ -213,7 +305,7 @@
switch (Message)
{
case WM_CREATE:
- AddTrayIcon(hwnd, LoadIcon(hInst, MAKEINTRESOURCE(IDI_MAIN)));
+ AddTrayIcon(hwnd);
hPopupMenu = BuildPopupMenu(hwnd);
break;
@@ -258,7 +350,7 @@
}
default:
- ActivateLayout(LOWORD(wParam));
+ ActivateLayout(hwnd, LOWORD(wParam));
break;
}
break;
Modified: trunk/reactos/base/applications/kbswitch/kbswitch.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/kbswitch…
==============================================================================
--- trunk/reactos/base/applications/kbswitch/kbswitch.rbuild [iso-8859-1] (original)
+++ trunk/reactos/base/applications/kbswitch/kbswitch.rbuild [iso-8859-1] Sun Apr 27
10:40:42 2008
@@ -6,6 +6,7 @@
<library>advapi32</library>
<library>user32</library>
<library>shell32</library>
+ <library>gdi32</library>
<file>kbswitch.c</file>
<file>kbswitch.rc</file>
</module>