-/*\r
- * PROJECT: ReactOS Character Map\r
- * LICENSE: GPL - See COPYING in the top level directory\r
- * FILE: base/applications/charmap/charmap.c\r
- * PURPOSE: main dialog implementation\r
- * COPYRIGHT: Copyright 2007 Ged Murphy <gedmurphy@reactos.org>\r
- *\r
- */\r
-\r
-#include <precomp.h>\r
-\r
-#define ID_ABOUT 0x1\r
-\r
-HINSTANCE hInstance;\r
-\r
-/* Font-enumeration callback */\r
-static\r
-int\r
-CALLBACK\r
-EnumFontNames(ENUMLOGFONTEXW *lpelfe,\r
- NEWTEXTMETRICEXW *lpntme,\r
- DWORD FontType,\r
- LPARAM lParam)\r
-{\r
- HWND hwndCombo = (HWND)lParam;\r
- LPWSTR pszName = lpelfe->elfLogFont.lfFaceName;\r
-\r
- /* make sure font doesn't already exist in our list */\r
- if(SendMessageW(hwndCombo,\r
- CB_FINDSTRING,\r
- 0,\r
- (LPARAM)pszName) == CB_ERR)\r
- {\r
- INT idx;\r
- BOOL fFixed;\r
- BOOL fTrueType;\r
-\r
- /* add the font */\r
- idx = (INT)SendMessageW(hwndCombo,\r
- CB_ADDSTRING,\r
- 0,\r
- (LPARAM)pszName);\r
-\r
- /* record the font's attributes (Fixedwidth and Truetype) */\r
- fFixed = (lpelfe->elfLogFont.lfPitchAndFamily & FIXED_PITCH) ? TRUE : FALSE;\r
- fTrueType = (lpelfe->elfLogFont.lfOutPrecision == OUT_STROKE_PRECIS) ? TRUE : FALSE;\r
-\r
- /* store this information in the list-item's userdata area */\r
- SendMessageW(hwndCombo,\r
- CB_SETITEMDATA,\r
- idx,\r
- MAKEWPARAM(fFixed, fTrueType));\r
- }\r
-\r
- return 1;\r
-}\r
-\r
-\r
-/* Initialize the font-list by enumeration all system fonts */\r
-static\r
-VOID\r
-FillFontStyleComboList(HWND hwndCombo)\r
-{\r
- HDC hdc;\r
- LOGFONTW lf;\r
-\r
- /* FIXME: for fun, draw each font in its own style */\r
- HFONT hFont = GetStockObject(DEFAULT_GUI_FONT);\r
- SendMessageW(hwndCombo,\r
- WM_SETFONT,\r
- (WPARAM)hFont,\r
- 0);\r
-\r
- ZeroMemory(&lf, sizeof(lf));\r
- lf.lfCharSet = DEFAULT_CHARSET;\r
-\r
- hdc = GetDC(hwndCombo);\r
-\r
- /* store the list of fonts in the combo */\r
- EnumFontFamiliesExW(hdc,\r
- &lf,\r
- (FONTENUMPROCW)EnumFontNames,\r
- (LPARAM)hwndCombo,\r
- 0);\r
-\r
- ReleaseDC(hwndCombo,\r
- hdc);\r
-\r
- SendMessageW(hwndCombo,\r
- CB_SETCURSEL,\r
- 0,\r
- 0);\r
-}\r
-\r
-\r
-static\r
-VOID\r
-ChangeMapFont(HWND hDlg)\r
-{\r
- HWND hCombo;\r
- HWND hMap;\r
- LPWSTR lpFontName;\r
- INT Len;\r
-\r
- hCombo = GetDlgItem(hDlg, IDC_FONTCOMBO);\r
-\r
- Len = GetWindowTextLengthW(hCombo);\r
-\r
- if (Len != 0)\r
- {\r
- lpFontName = HeapAlloc(GetProcessHeap(),\r
- 0,\r
- (Len + 1) * sizeof(WCHAR));\r
-\r
- if (lpFontName)\r
- {\r
- SendMessageW(hCombo,\r
- WM_GETTEXT,\r
- Len + 1,\r
- (LPARAM)lpFontName);\r
-\r
- hMap = GetDlgItem(hDlg, IDC_FONTMAP);\r
-\r
- SendMessageW(hMap,\r
- FM_SETFONT,\r
- 0,\r
- (LPARAM)lpFontName);\r
- }\r
-\r
- HeapFree(GetProcessHeap(),\r
- 0,\r
- lpFontName);\r
- }\r
-}\r
-\r
-\r
-static\r
-VOID\r
-AddCharToSelection(HWND hText,\r
- WCHAR ch)\r
-{\r
- LPWSTR lpText;\r
- INT Len = GetWindowTextLength(hText);\r
-\r
- if (Len != 0)\r
- {\r
- lpText = HeapAlloc(GetProcessHeap(),\r
- 0,\r
- (Len + 2) * sizeof(WCHAR));\r
-\r
- if (lpText)\r
- {\r
- LPWSTR lpStr = lpText;\r
-\r
- SendMessageW(hText,\r
- WM_GETTEXT,\r
- Len + 1,\r
- (LPARAM)lpStr);\r
-\r
- lpStr += Len;\r
- *lpStr = ch;\r
- lpStr++;\r
- *lpStr = L'\0';\r
-\r
- SendMessageW(hText,\r
- WM_SETTEXT,\r
- 0,\r
- (LPARAM)lpText);\r
-\r
- HeapFree(GetProcessHeap(),\r
- 0,\r
- lpText);\r
- }\r
- }\r
- else\r
- {\r
- WCHAR szText[2];\r
-\r
- szText[0] = ch;\r
- szText[1] = L'\0';\r
-\r
- SendMessageW(hText,\r
- WM_SETTEXT,\r
- 0,\r
- (LPARAM)szText);\r
- }\r
-}\r
-\r
-\r
-static\r
-BOOL\r
-CALLBACK\r
-DlgProc(HWND hDlg,\r
- UINT Message,\r
- WPARAM wParam,\r
- LPARAM lParam)\r
-{\r
- static HICON hSmIcon;\r
- static HICON hBgIcon;\r
- LPWSTR lpAboutText = NULL;\r
-\r
- switch(Message)\r
- {\r
- case WM_INITDIALOG:\r
- {\r
- HMENU hSysMenu;\r
-\r
- hSmIcon = LoadImageW(hInstance,\r
- MAKEINTRESOURCEW(IDI_ICON),\r
- IMAGE_ICON,\r
- 16,\r
- 16,\r
- 0);\r
- if (hSmIcon)\r
- {\r
- SendMessageW(hDlg,\r
- WM_SETICON,\r
- ICON_SMALL,\r
- (LPARAM)hSmIcon);\r
- }\r
-\r
- hBgIcon = LoadImageW(hInstance,\r
- MAKEINTRESOURCEW(IDI_ICON),\r
- IMAGE_ICON,\r
- 32,\r
- 32,\r
- 0);\r
- if (hBgIcon)\r
- {\r
- SendMessageW(hDlg,\r
- WM_SETICON,\r
- ICON_BIG,\r
- (LPARAM)hBgIcon);\r
- }\r
-\r
- FillFontStyleComboList(GetDlgItem(hDlg,\r
- IDC_FONTCOMBO));\r
-\r
- ChangeMapFont(hDlg);\r
- hSysMenu = GetSystemMenu(hDlg,\r
- FALSE);\r
- if (hSysMenu != NULL)\r
- {\r
- if (LoadStringW(hInstance,\r
- IDS_ABOUT,\r
- lpAboutText,\r
- 0))\r
- {\r
- AppendMenuW(hSysMenu,\r
- MF_SEPARATOR,\r
- 0,\r
- NULL);\r
- AppendMenuW(hSysMenu,\r
- MF_STRING,\r
- ID_ABOUT,\r
- lpAboutText);\r
- }\r
- }\r
- return TRUE;\r
- }\r
-\r
- case WM_COMMAND:\r
- {\r
- switch(LOWORD(wParam))\r
- {\r
- case IDC_FONTMAP:\r
- {\r
- switch (HIWORD(wParam))\r
- {\r
- case FM_SETCHAR:\r
- AddCharToSelection(GetDlgItem(hDlg, IDC_TEXTBOX),\r
- LOWORD(lParam));\r
- break;\r
- }\r
- }\r
- break;\r
-\r
- case IDC_FONTCOMBO:\r
- {\r
- if (HIWORD(wParam) == CBN_SELCHANGE)\r
- {\r
- ChangeMapFont(hDlg);\r
- }\r
- }\r
- break;\r
-\r
- case IDC_SELECT:\r
- {\r
- WCHAR ch;\r
- HWND hMap = GetDlgItem(hDlg, IDC_FONTMAP);\r
-\r
- ch = (WCHAR) SendMessageW(hMap, FM_GETCHAR, 0, 0);\r
-\r
- if (ch)\r
- {\r
- AddCharToSelection(GetDlgItem(hDlg, IDC_TEXTBOX),\r
- ch);\r
- }\r
-\r
- break;\r
- }\r
-\r
- case IDOK:\r
- if (hSmIcon)\r
- DestroyIcon(hSmIcon);\r
- if (hBgIcon)\r
- DestroyIcon(hBgIcon);\r
- EndDialog(hDlg, 0);\r
- break;\r
- }\r
- }\r
- break;\r
-\r
- case WM_SYSCOMMAND:\r
- {\r
- switch(wParam)\r
- {\r
- case ID_ABOUT:\r
- ShowAboutDlg(hDlg);\r
- break;\r
- }\r
- }\r
- break;\r
-\r
- case WM_CLOSE:\r
- if (hSmIcon)\r
- DestroyIcon(hSmIcon);\r
- if (hBgIcon)\r
- DestroyIcon(hBgIcon);\r
- EndDialog(hDlg, 0);\r
- break;\r
-\r
- default:\r
- return FALSE;\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-\r
-INT\r
-WINAPI\r
-wWinMain(HINSTANCE hInst,\r
- HINSTANCE hPrev,\r
- LPWSTR Cmd,\r
- int iCmd)\r
-{\r
- INITCOMMONCONTROLSEX iccx;\r
- INT Ret = 1;\r
-\r
- hInstance = hInst;\r
-\r
- iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);\r
- iccx.dwICC = ICC_TAB_CLASSES;\r
- InitCommonControlsEx(&iccx);\r
-\r
- if (RegisterMapClasses(hInstance))\r
- {\r
- Ret = DialogBoxW(hInstance,\r
- MAKEINTRESOURCEW(IDD_CHARMAP),\r
- NULL,\r
- (DLGPROC)DlgProc) >= 0;\r
-\r
- UnregisterMapClasses(hInstance);\r
- }\r
-\r
- return Ret;\r
-}\r
+/*
+ * PROJECT: ReactOS Character Map
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: base/applications/charmap/charmap.c
+ * PURPOSE: main dialog implementation
+ * COPYRIGHT: Copyright 2007 Ged Murphy <gedmurphy@reactos.org>
+ *
+ */
+
+#include <precomp.h>
+
+#define ID_ABOUT 0x1
+
+HINSTANCE hInstance;
+
+/* Font-enumeration callback */
+static
+int
+CALLBACK
+EnumFontNames(ENUMLOGFONTEXW *lpelfe,
+ NEWTEXTMETRICEXW *lpntme,
+ DWORD FontType,
+ LPARAM lParam)
+{
+ HWND hwndCombo = (HWND)lParam;
+ LPWSTR pszName = lpelfe->elfLogFont.lfFaceName;
+
+ /* make sure font doesn't already exist in our list */
+ if(SendMessageW(hwndCombo,
+ CB_FINDSTRING,
+ 0,
+ (LPARAM)pszName) == CB_ERR)
+ {
+ INT idx;
+ BOOL fFixed;
+ BOOL fTrueType;
+
+ /* add the font */
+ idx = (INT)SendMessageW(hwndCombo,
+ CB_ADDSTRING,
+ 0,
+ (LPARAM)pszName);
+
+ /* record the font's attributes (Fixedwidth and Truetype) */
+ fFixed = (lpelfe->elfLogFont.lfPitchAndFamily & FIXED_PITCH) ? TRUE : FALSE;
+ fTrueType = (lpelfe->elfLogFont.lfOutPrecision == OUT_STROKE_PRECIS) ? TRUE : FALSE;
+
+ /* store this information in the list-item's userdata area */
+ SendMessageW(hwndCombo,
+ CB_SETITEMDATA,
+ idx,
+ MAKEWPARAM(fFixed, fTrueType));
+ }
+
+ return 1;
+}
+
+
+/* Initialize the font-list by enumeration all system fonts */
+static
+VOID
+FillFontStyleComboList(HWND hwndCombo)
+{
+ HDC hdc;
+ LOGFONTW lf;
+
+ /* FIXME: for fun, draw each font in its own style */
+ HFONT hFont = GetStockObject(DEFAULT_GUI_FONT);
+ SendMessageW(hwndCombo,
+ WM_SETFONT,
+ (WPARAM)hFont,
+ 0);
+
+ ZeroMemory(&lf, sizeof(lf));
+ lf.lfCharSet = DEFAULT_CHARSET;
+
+ hdc = GetDC(hwndCombo);
+
+ /* store the list of fonts in the combo */
+ EnumFontFamiliesExW(hdc,
+ &lf,
+ (FONTENUMPROCW)EnumFontNames,
+ (LPARAM)hwndCombo,
+ 0);
+
+ ReleaseDC(hwndCombo,
+ hdc);
+
+ SendMessageW(hwndCombo,
+ CB_SETCURSEL,
+ 0,
+ 0);
+}
+
+
+static
+VOID
+ChangeMapFont(HWND hDlg)
+{
+ HWND hCombo;
+ HWND hMap;
+ LPWSTR lpFontName;
+ INT Len;
+
+ hCombo = GetDlgItem(hDlg, IDC_FONTCOMBO);
+
+ Len = GetWindowTextLengthW(hCombo);
+
+ if (Len != 0)
+ {
+ lpFontName = HeapAlloc(GetProcessHeap(),
+ 0,
+ (Len + 1) * sizeof(WCHAR));
+
+ if (lpFontName)
+ {
+ SendMessageW(hCombo,
+ WM_GETTEXT,
+ Len + 1,
+ (LPARAM)lpFontName);
+
+ hMap = GetDlgItem(hDlg, IDC_FONTMAP);
+
+ SendMessageW(hMap,
+ FM_SETFONT,
+ 0,
+ (LPARAM)lpFontName);
+ }
+
+ HeapFree(GetProcessHeap(),
+ 0,
+ lpFontName);
+ }
+}
+
+
+static
+VOID
+AddCharToSelection(HWND hText,
+ WCHAR ch)
+{
+ LPWSTR lpText;
+ INT Len = GetWindowTextLength(hText);
+
+ if (Len != 0)
+ {
+ lpText = HeapAlloc(GetProcessHeap(),
+ 0,
+ (Len + 2) * sizeof(WCHAR));
+
+ if (lpText)
+ {
+ LPWSTR lpStr = lpText;
+
+ SendMessageW(hText,
+ WM_GETTEXT,
+ Len + 1,
+ (LPARAM)lpStr);
+
+ lpStr += Len;
+ *lpStr = ch;
+ lpStr++;
+ *lpStr = L'\0';
+
+ SendMessageW(hText,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)lpText);
+
+ HeapFree(GetProcessHeap(),
+ 0,
+ lpText);
+ }
+ }
+ else
+ {
+ WCHAR szText[2];
+
+ szText[0] = ch;
+ szText[1] = L'\0';
+
+ SendMessageW(hText,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)szText);
+ }
+}
+
+
+static
+INT_PTR
+CALLBACK
+DlgProc(HWND hDlg,
+ UINT Message,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ static HICON hSmIcon;
+ static HICON hBgIcon;
+ LPWSTR lpAboutText = NULL;
+
+ switch(Message)
+ {
+ case WM_INITDIALOG:
+ {
+ HMENU hSysMenu;
+
+ hSmIcon = LoadImageW(hInstance,
+ MAKEINTRESOURCEW(IDI_ICON),
+ IMAGE_ICON,
+ 16,
+ 16,
+ 0);
+ if (hSmIcon)
+ {
+ SendMessageW(hDlg,
+ WM_SETICON,
+ ICON_SMALL,
+ (LPARAM)hSmIcon);
+ }
+
+ hBgIcon = LoadImageW(hInstance,
+ MAKEINTRESOURCEW(IDI_ICON),
+ IMAGE_ICON,
+ 32,
+ 32,
+ 0);
+ if (hBgIcon)
+ {
+ SendMessageW(hDlg,
+ WM_SETICON,
+ ICON_BIG,
+ (LPARAM)hBgIcon);
+ }
+
+ FillFontStyleComboList(GetDlgItem(hDlg,
+ IDC_FONTCOMBO));
+
+ ChangeMapFont(hDlg);
+ hSysMenu = GetSystemMenu(hDlg,
+ FALSE);
+ if (hSysMenu != NULL)
+ {
+ if (LoadStringW(hInstance,
+ IDS_ABOUT,
+ lpAboutText,
+ 0))
+ {
+ AppendMenuW(hSysMenu,
+ MF_SEPARATOR,
+ 0,
+ NULL);
+ AppendMenuW(hSysMenu,
+ MF_STRING,
+ ID_ABOUT,
+ lpAboutText);
+ }
+ }
+ return TRUE;
+ }
+
+ case WM_COMMAND:
+ {
+ switch(LOWORD(wParam))
+ {
+ case IDC_FONTMAP:
+ {
+ switch (HIWORD(wParam))
+ {
+ case FM_SETCHAR:
+ AddCharToSelection(GetDlgItem(hDlg, IDC_TEXTBOX),
+ LOWORD(lParam));
+ break;
+ }
+ }
+ break;
+
+ case IDC_FONTCOMBO:
+ {
+ if (HIWORD(wParam) == CBN_SELCHANGE)
+ {
+ ChangeMapFont(hDlg);
+ }
+ }
+ break;
+
+ case IDC_SELECT:
+ {
+ WCHAR ch;
+ HWND hMap = GetDlgItem(hDlg, IDC_FONTMAP);
+
+ ch = (WCHAR) SendMessageW(hMap, FM_GETCHAR, 0, 0);
+
+ if (ch)
+ {
+ AddCharToSelection(GetDlgItem(hDlg, IDC_TEXTBOX),
+ ch);
+ }
+
+ break;
+ }
+
+ case IDOK:
+ if (hSmIcon)
+ DestroyIcon(hSmIcon);
+ if (hBgIcon)
+ DestroyIcon(hBgIcon);
+ EndDialog(hDlg, 0);
+ break;
+ }
+ }
+ break;
+
+ case WM_SYSCOMMAND:
+ {
+ switch(wParam)
+ {
+ case ID_ABOUT:
+ ShowAboutDlg(hDlg);
+ break;
+ }
+ }
+ break;
+
+ case WM_CLOSE:
+ if (hSmIcon)
+ DestroyIcon(hSmIcon);
+ if (hBgIcon)
+ DestroyIcon(hBgIcon);
+ EndDialog(hDlg, 0);
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
+
+INT
+WINAPI
+wWinMain(HINSTANCE hInst,
+ HINSTANCE hPrev,
+ LPWSTR Cmd,
+ int iCmd)
+{
+ INITCOMMONCONTROLSEX iccx;
+ INT Ret = 1;
+
+ hInstance = hInst;
+
+ iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
+ iccx.dwICC = ICC_TAB_CLASSES;
+ InitCommonControlsEx(&iccx);
+
+ if (RegisterMapClasses(hInstance))
+ {
+ Ret = DialogBoxW(hInstance,
+ MAKEINTRESOURCEW(IDD_CHARMAP),
+ NULL,
+ DlgProc) >= 0;
+
+ UnregisterMapClasses(hInstance);
+ }
+
+ return Ret;
+}