Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

charmap.c

Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactOS Character Map
00003  * LICENSE:     GPL - See COPYING in the top level directory
00004  * FILE:        base/applications/charmap/charmap.c
00005  * PURPOSE:     main dialog implementation
00006  * COPYRIGHT:   Copyright 2007 Ged Murphy <gedmurphy@reactos.org>
00007  *
00008  */
00009 
00010 #include <precomp.h>
00011 
00012 #define ID_ABOUT    0x1
00013 
00014 typedef struct {
00015     BOOL    IsAdvancedView;
00016 } SETTINGS;
00017 
00018 HINSTANCE hInstance;
00019 HWND      hCharmapDlg;
00020 HWND      hAdvancedDlg;
00021 HWND      hStatusWnd;
00022 HICON     hSmIcon;
00023 HICON     hBgIcon;
00024 SETTINGS  Settings;
00025 
00026 /* Font-enumeration callback */
00027 static
00028 int
00029 CALLBACK
00030 EnumFontNames(ENUMLOGFONTEXW *lpelfe,
00031               NEWTEXTMETRICEXW *lpntme,
00032               DWORD FontType,
00033               LPARAM lParam)
00034 {
00035     HWND hwndCombo = (HWND)lParam;
00036     LPWSTR pszName  = lpelfe->elfLogFont.lfFaceName;
00037 
00038     /* make sure font doesn't already exist in our list */
00039     if(SendMessageW(hwndCombo,
00040                     CB_FINDSTRING,
00041                     0,
00042                     (LPARAM)pszName) == CB_ERR)
00043     {
00044         INT idx;
00045         BOOL fFixed;
00046         BOOL fTrueType;
00047 
00048         /* add the font */
00049         idx = (INT)SendMessageW(hwndCombo,
00050                                 CB_ADDSTRING,
00051                                 0,
00052                                 (LPARAM)pszName);
00053 
00054         /* record the font's attributes (Fixedwidth and Truetype) */
00055         fFixed = (lpelfe->elfLogFont.lfPitchAndFamily & FIXED_PITCH) ? TRUE : FALSE;
00056         fTrueType = (lpelfe->elfLogFont.lfOutPrecision == OUT_STROKE_PRECIS) ? TRUE : FALSE;
00057 
00058         /* store this information in the list-item's userdata area */
00059         SendMessageW(hwndCombo,
00060                      CB_SETITEMDATA,
00061                      idx,
00062                      MAKEWPARAM(fFixed, fTrueType));
00063     }
00064 
00065     return 1;
00066 }
00067 
00068 
00069 /* Initialize the font-list by enumeration all system fonts */
00070 static
00071 VOID
00072 FillFontStyleComboList(HWND hwndCombo)
00073 {
00074     HDC hdc;
00075     LOGFONTW lf;
00076 
00077     /* FIXME: for fun, draw each font in its own style */
00078     HFONT hFont = GetStockObject(DEFAULT_GUI_FONT);
00079     SendMessageW(hwndCombo,
00080                  WM_SETFONT,
00081                  (WPARAM)hFont,
00082                  0);
00083 
00084     ZeroMemory(&lf, sizeof(lf));
00085     lf.lfCharSet = DEFAULT_CHARSET;
00086 
00087     hdc = GetDC(hwndCombo);
00088 
00089     /* store the list of fonts in the combo */
00090     EnumFontFamiliesExW(hdc,
00091                         &lf,
00092                         (FONTENUMPROCW)EnumFontNames,
00093                         (LPARAM)hwndCombo,
00094                         0);
00095 
00096     ReleaseDC(hwndCombo,
00097               hdc);
00098 
00099     SendMessageW(hwndCombo,
00100                  CB_SETCURSEL,
00101                  0,
00102                  0);
00103 }
00104 
00105 
00106 static
00107 VOID
00108 ChangeMapFont(HWND hDlg)
00109 {
00110     HWND hCombo;
00111     HWND hMap;
00112     LPWSTR lpFontName;
00113     INT Len;
00114 
00115     hCombo = GetDlgItem(hDlg, IDC_FONTCOMBO);
00116 
00117     Len = GetWindowTextLengthW(hCombo);
00118 
00119     if (Len != 0)
00120     {
00121         lpFontName = HeapAlloc(GetProcessHeap(),
00122                                0,
00123                                (Len + 1) * sizeof(WCHAR));
00124 
00125         if (lpFontName)
00126         {
00127             SendMessageW(hCombo,
00128                          WM_GETTEXT,
00129                          Len + 1,
00130                          (LPARAM)lpFontName);
00131 
00132             hMap = GetDlgItem(hDlg, IDC_FONTMAP);
00133 
00134             SendMessageW(hMap,
00135                          FM_SETFONT,
00136                          0,
00137                          (LPARAM)lpFontName);
00138         }
00139 
00140         HeapFree(GetProcessHeap(),
00141                  0,
00142                  lpFontName);
00143     }
00144 }
00145 
00146 // Copy collected characters into the clipboard
00147 static
00148 void
00149 CopyCharacters(HWND hDlg)
00150 {
00151     HWND hText = GetDlgItem(hDlg, IDC_TEXTBOX);
00152     DWORD dwStart, dwEnd;
00153 
00154     // Acquire selection limits
00155     SendMessage(hText, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
00156 
00157     // Test if the whose text is unselected
00158     if(dwStart == dwEnd) {
00159         
00160         // Select the whole text
00161         SendMessageW(hText, EM_SETSEL, 0, -1);
00162 
00163         // Copy text
00164         SendMessageW(hText, WM_COPY, 0, 0);
00165 
00166         // Restore previous values
00167         SendMessageW(hText, EM_SETSEL, (WPARAM)dwStart, (LPARAM)dwEnd);
00168 
00169     } else {
00170 
00171         // Copy text
00172         SendMessageW(hText, WM_COPY, 0, 0);
00173     }
00174 }
00175 
00176 // Recover charset for the given font
00177 static
00178 BYTE
00179 GetFontMetrics(HWND hWnd, HFONT hFont)
00180 {
00181     TEXTMETRIC tmFont;
00182     HGDIOBJ    hOldObj;
00183     HDC        hDC;
00184 
00185     hDC = GetDC(hWnd);
00186     hOldObj = SelectObject(hDC, hFont);
00187     GetTextMetrics(hDC, &tmFont);
00188     SelectObject(hDC, hOldObj);
00189     ReleaseDC(hWnd, hDC);
00190 
00191     return tmFont.tmCharSet;
00192 }
00193 
00194 // Select a new character
00195 static
00196 VOID
00197 AddCharToSelection(HWND hDlg, WCHAR ch)
00198 {
00199     HWND    hMap = GetDlgItem(hDlg, IDC_FONTMAP);
00200     HWND    hText = GetDlgItem(hDlg, IDC_TEXTBOX);
00201     HFONT   hFont;
00202     LOGFONT lFont;
00203     CHARFORMAT cf;
00204 
00205     // Retrieve current character selected
00206     if (ch == 0)
00207     {
00208         ch = (WCHAR) SendMessageW(hMap, FM_GETCHAR, 0, 0);
00209         if (!ch)
00210             return;
00211     }
00212 
00213     // Retrieve current selected font
00214     hFont = (HFONT)SendMessage(hMap, FM_GETHFONT, 0, 0);
00215 
00216     // Recover LOGFONT structure from hFont
00217     if (!GetObject(hFont, sizeof(LOGFONT), &lFont))
00218         return;
00219 
00220     // Recover font properties of Richedit control
00221     ZeroMemory(&cf, sizeof(cf));
00222     cf.cbSize = sizeof(cf);
00223     SendMessage(hText, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
00224 
00225     // Apply properties of the new font
00226     cf.bCharSet = GetFontMetrics(hText, hFont);
00227 
00228     // Update font name
00229     wcscpy(cf.szFaceName, lFont.lfFaceName);
00230 
00231     // Update font properties
00232     SendMessage(hText, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
00233 
00234     // Send selected character to Richedit
00235     SendMessage(hText, WM_CHAR, (WPARAM)ch, 0);
00236 }
00237 
00238 
00239 static
00240 void
00241 UpdateSettings(HWND hDlg)
00242 {
00243     if (hDlg == hCharmapDlg)
00244     {
00245         Settings.IsAdvancedView =
00246         SendDlgItemMessage(hDlg, IDC_CHECK_ADVANCED, BM_GETCHECK, 0, 0);
00247     }
00248 
00249     if (hDlg == hAdvancedDlg)
00250     {
00251     }
00252 }
00253 
00254 static
00255 void
00256 ChangeView(HWND hWnd)
00257 {
00258     RECT rcCharmap;
00259     RECT rcAdvanced;
00260     RECT rcPanelExt;
00261     RECT rcPanelInt;
00262     RECT rcStatus;
00263     UINT DeX, DeY;
00264     UINT xPos, yPos;
00265     UINT Width, Height;
00266     UINT DeskTopWidth, DeskTopHeight;
00267 
00268     GetClientRect(hCharmapDlg, &rcCharmap);
00269     GetClientRect(hAdvancedDlg, &rcAdvanced);
00270     GetWindowRect(hWnd, &rcPanelExt);
00271     GetClientRect(hWnd, &rcPanelInt);
00272     GetClientRect(hStatusWnd, &rcStatus);
00273 
00274     DeskTopWidth = GetSystemMetrics(SM_CXFULLSCREEN);
00275     DeskTopHeight = GetSystemMetrics(SM_CYFULLSCREEN);
00276 
00277     DeX = (rcPanelExt.right - rcPanelExt.left) - rcPanelInt.right;
00278     DeY = (rcPanelExt.bottom - rcPanelExt.top) - rcPanelInt.bottom;
00279 
00280     MoveWindow(hCharmapDlg, 0, 0, rcCharmap.right, rcCharmap.bottom, FALSE);
00281     MoveWindow(hAdvancedDlg, 0, rcCharmap.bottom, rcAdvanced.right, rcAdvanced.bottom, FALSE);
00282 
00283     ShowWindow(hAdvancedDlg, (Settings.IsAdvancedView) ? SW_SHOW : SW_HIDE);
00284 
00285     xPos = rcPanelExt.left;
00286     yPos = rcPanelExt.top;
00287 
00288     Width = DeX + rcCharmap.right;
00289     Height = DeY + rcCharmap.bottom + rcStatus.bottom;
00290 
00291     if (Settings.IsAdvancedView)
00292         Height += rcAdvanced.bottom;
00293 
00294     if ((xPos + Width) > DeskTopWidth)
00295         xPos += DeskTopWidth - (xPos + Width);
00296 
00297     if ((yPos + Height) > DeskTopHeight)
00298         yPos += DeskTopHeight - (yPos + Height);
00299 
00300     MoveWindow(hWnd,
00301                xPos, yPos,
00302                Width, Height,
00303                TRUE);
00304 }
00305 
00306 static
00307 INT_PTR
00308 CALLBACK
00309 CharMapDlgProc(HWND hDlg,
00310                UINT Message,
00311                WPARAM wParam,
00312                LPARAM lParam)
00313 {
00314     switch(Message)
00315     {
00316         case WM_INITDIALOG:
00317         {
00318             DWORD evMask;
00319 
00320             FillFontStyleComboList(GetDlgItem(hDlg,
00321                                               IDC_FONTCOMBO));
00322 
00323             ChangeMapFont(hDlg);
00324 
00325             // Configure Richedi control for sending notification changes.
00326             evMask = SendDlgItemMessage(hDlg, IDC_TEXTBOX, EM_GETEVENTMASK, 0, 0);
00327             evMask |= ENM_CHANGE;
00328             SendDlgItemMessage(hDlg, IDC_TEXTBOX, EM_SETEVENTMASK, 0, (LPARAM)evMask);
00329 
00330             return TRUE;
00331         }
00332 
00333         case WM_COMMAND:
00334         {
00335             switch(LOWORD(wParam))
00336             {
00337                 case IDC_FONTMAP:
00338                     switch (HIWORD(wParam))
00339                     {
00340                         case FM_SETCHAR:
00341                             AddCharToSelection(hDlg, LOWORD(lParam));
00342                             break;
00343                     }
00344                     break;
00345 
00346                 case IDC_FONTCOMBO:
00347                     if (HIWORD(wParam) == CBN_SELCHANGE)
00348                     {
00349                         ChangeMapFont(hDlg);
00350                     }
00351                     break;
00352 
00353                 case IDC_SELECT:
00354                     AddCharToSelection(hDlg, 0);
00355                     break;
00356 
00357                 case IDC_TEXTBOX:
00358                     switch (HIWORD(wParam)) {
00359                     case EN_CHANGE:
00360                         if (GetWindowTextLength(GetDlgItem(hDlg, IDC_TEXTBOX)) == 0)
00361                             EnableWindow(GetDlgItem(hDlg, IDC_COPY), FALSE);
00362                         else
00363                             EnableWindow(GetDlgItem(hDlg, IDC_COPY), TRUE);
00364                         break;
00365                     }
00366                     break;
00367 
00368                 case IDC_COPY:
00369                     CopyCharacters(hDlg);
00370                     break;
00371 
00372                 case IDC_CHECK_ADVANCED:
00373                     UpdateSettings(hDlg);
00374                     ChangeView(GetParent(hDlg));
00375                     break;
00376             }
00377         }
00378         break;
00379 
00380         default:
00381             break;
00382     }
00383 
00384     return FALSE;
00385 }
00386 
00387 static
00388 INT_PTR
00389 CALLBACK
00390 AdvancedDlgProc(HWND hDlg,
00391                UINT Message,
00392                WPARAM wParam,
00393                LPARAM lParam)
00394 {
00395     switch(Message)
00396     {
00397         case WM_INITDIALOG:
00398             return TRUE;
00399 
00400         default:
00401             return FALSE;
00402     }
00403 
00404     return FALSE;
00405 }
00406 
00407 static int
00408 OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
00409 {
00410     HMENU hSysMenu;
00411     WCHAR lpAboutText[256];
00412 
00413     hCharmapDlg = CreateDialog(hInstance,
00414                                MAKEINTRESOURCE(IDD_CHARMAP),
00415                                hWnd,
00416                                CharMapDlgProc);
00417 
00418     hAdvancedDlg = CreateDialog(hInstance,
00419                                MAKEINTRESOURCE(IDD_ADVANCED),
00420                                hWnd,
00421                                AdvancedDlgProc);
00422 
00423     hStatusWnd = CreateWindow(STATUSCLASSNAME,
00424                               NULL,
00425                               WS_CHILD | WS_VISIBLE,
00426                               0, 0, 0, 0,
00427                               hWnd,
00428                               (HMENU)IDD_STATUSBAR,
00429                               hInstance,
00430                               NULL);
00431 
00432     // Set the status bar for multiple parts output
00433     SendMessage(hStatusWnd, SB_SIMPLE, (WPARAM)FALSE, (LPARAM)0);
00434 
00435     ChangeView(hWnd);
00436 
00437     hSysMenu = GetSystemMenu(hWnd, FALSE);
00438 
00439     if (hSysMenu != NULL)
00440     {
00441         if (LoadStringW(hInstance, IDS_ABOUT, lpAboutText, SIZEOF(lpAboutText)))
00442         {
00443             AppendMenuW(hSysMenu, MF_SEPARATOR, 0, NULL);
00444             AppendMenuW(hSysMenu, MF_STRING, ID_ABOUT, lpAboutText);
00445         }
00446     }
00447 
00448     return 0;
00449 }
00450 
00451 static LRESULT CALLBACK
00452 PanelWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
00453 {
00454     switch (msg) {
00455     case WM_CREATE:
00456         return OnCreate(hWnd, wParam, lParam);
00457 
00458     case WM_CLOSE:
00459         DestroyWindow(hWnd);
00460         return 0;
00461 
00462     case WM_SIZE:
00463         SendMessage(hStatusWnd, msg, wParam, lParam);
00464         break;
00465 
00466     case WM_DESTROY:
00467         PostQuitMessage(0);
00468         return 0;
00469 
00470     case WM_SYSCOMMAND:
00471         switch(wParam) {
00472         case ID_ABOUT:
00473             ShowAboutDlg(hWnd);
00474             break;
00475         }
00476         break;
00477 
00478     }
00479 
00480     return DefWindowProc(hWnd, msg, wParam, lParam);
00481 }
00482 
00483 static HWND
00484 InitInstance(HINSTANCE hInst)
00485 {
00486     WCHAR       szClass[] = L"CharMap";
00487     WCHAR       szTitle[256];
00488     WNDCLASSEXW wc;
00489     HWND        hWnd;
00490 
00491     LoadStringW(hInst, IDS_TITLE, szTitle, SIZEOF(szTitle));
00492 
00493     hSmIcon = LoadImage(hInstance,
00494                         MAKEINTRESOURCE(IDI_ICON),
00495                         IMAGE_ICON,
00496                         16,
00497                         16,
00498                         0);
00499 
00500     hBgIcon = LoadImage(hInstance,
00501                         MAKEINTRESOURCE(IDI_ICON),
00502                         IMAGE_ICON,
00503                         32,
00504                         32,
00505                         0);
00506 
00507     // Create workspace
00508     ZeroMemory(&wc, sizeof(wc));
00509 
00510     wc.cbSize        = sizeof(wc);
00511     wc.lpfnWndProc   = PanelWndProc;
00512     wc.hInstance     = hInst;
00513     wc.hIcon         = hBgIcon;
00514     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
00515     wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
00516     wc.lpszMenuName  = NULL;
00517     wc.lpszClassName = szClass;
00518     wc.hIconSm       = hSmIcon;
00519 
00520     RegisterClassExW(&wc);
00521 
00522     hWnd = CreateWindowW(
00523             szClass,
00524             szTitle,
00525             WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
00526             CW_USEDEFAULT,
00527             CW_USEDEFAULT,
00528             CW_USEDEFAULT,
00529             CW_USEDEFAULT,
00530             NULL,
00531             NULL,
00532             hInst,
00533             NULL);
00534 
00535     if (hWnd != NULL)
00536     {
00537         ShowWindow(hWnd, SW_SHOW);
00538         UpdateWindow(hWnd);
00539     }
00540 
00541     return hWnd;
00542 }
00543 
00544 INT
00545 WINAPI
00546 wWinMain(HINSTANCE hInst,
00547          HINSTANCE hPrev,
00548          LPWSTR Cmd,
00549          int iCmd)
00550 {
00551     INITCOMMONCONTROLSEX iccx;
00552     INT Ret = 1;
00553     HMODULE hRichEd20;
00554     MSG Msg;
00555 
00556     hInstance = hInst;
00557 
00558     iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
00559     iccx.dwICC = ICC_TAB_CLASSES;
00560     InitCommonControlsEx(&iccx);
00561 
00562     if (RegisterMapClasses(hInstance))
00563     {
00564         hRichEd20 = LoadLibraryW(L"RICHED20.DLL");
00565 
00566         if (hRichEd20 != NULL)
00567         {
00568             InitInstance(hInst);
00569 
00570             for (;;)
00571             {
00572                 if (GetMessage(&Msg, NULL, 0, 0) <= 0)
00573                 {
00574                     Ret = Msg.wParam;
00575                     break;
00576                 }
00577 
00578                 TranslateMessage(&Msg);
00579                 DispatchMessage(&Msg);
00580             }
00581 
00582             FreeLibrary(hRichEd20);
00583         }
00584         UnregisterMapClasses(hInstance);
00585     }
00586 
00587     return Ret;
00588 }

Generated on Thu Feb 9 04:38:59 2012 for ReactOS by doxygen 1.6.3

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.