subset.cxx
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 10k
Category:

Windows Develop

Development Platform:

Visual C++

  1. /****************************************************************************
  2.     Subset.c
  3.     PURPOSE: Subset related utilities for UCE
  4.     Copyright (c) 1997-1999 Microsoft Corporation.
  5. ****************************************************************************/
  6. #include "windows.h"
  7. #include "commctrl.h"
  8. #include "UCE.h"
  9. #include "stdlib.h"
  10. #include "tchar.h"
  11. #include "stdio.h"
  12. #include "winuser.h"
  13. #include "string.h"
  14. #include "search.h"
  15. #include "getuname.h"
  16. #include "winnls.h"
  17. #include "wingdi.h"
  18. #include "ucefile.h"
  19. extern DWORD gFontType;
  20. //
  21. // Char buffer
  22. //
  23. WCHAR wcUnicodeBuffer[M64K];
  24. /****************************************************************************
  25.     Fill Subsets from UCE files
  26. ****************************************************************************/
  27. BOOL
  28. Subset_FillComboBox(
  29.    HWND hWnd,
  30.    UINT uID        )
  31. {
  32.   INT              i=0;
  33.   INT              nIndex;
  34.   PUCE_MEMORY_FILE pUceMemFile;
  35.   INT              cFiles;
  36.   PWSTR            pwszSubsetName;
  37.   WCHAR            wszID[16];              // I know it is "ALL"
  38.   HWND             hCombo = (HWND) GetDlgItem(hWnd,uID);
  39.   if(NULL == hCombo)
  40.   {
  41.     return FALSE;
  42.   }
  43.   SendMessage( hCombo,
  44.                CB_RESETCONTENT,
  45.                0,
  46.                0
  47.              );
  48.   // Let's add the All subset (hardcoded)
  49.   LoadString( hInst , IDS_ALL , &wszID[0] , sizeof(wszID)-1 );
  50.   if( wszID[0] )
  51.   {
  52.     wszID[sizeof(wszID)-1] = 0;  // safe!
  53.     nIndex = (INT)SendMessage( hCombo,
  54.                                CB_ADDSTRING,
  55.                                (WPARAM) 0,
  56.                                (LPARAM)(PCWSTR) &wszID[0]
  57.                              );
  58.     if (nIndex != CB_ERR)
  59.     {
  60.       SendMessage( hCombo,
  61.                    CB_SETITEMDATA,
  62.                    (WPARAM) nIndex,
  63.                    (LPARAM) 0
  64.                  );
  65.     }
  66.     // set the current selection here
  67.     SendMessage( hCombo,
  68.                  CB_SETCURSEL,
  69.                  (WPARAM) nIndex,
  70.                  (LPARAM) 0
  71.                );
  72.   }
  73.   cFiles = UCE_GetFiles( &pUceMemFile );
  74.   while( i<cFiles )
  75.   {
  76.     WORD cp;
  77.     BOOL IsCpOnList;
  78.     // make sure required codepage is on our list
  79.     cp = UCE_GetCodepage( &pUceMemFile[i] );
  80.     if(cp == UNICODE_CODEPAGE)
  81.     {
  82.         IsCpOnList = TRUE;
  83.     }
  84.     else
  85.     {
  86.         IsCpOnList = IsCodePageOnList(cp);
  87.     }
  88.     if( IsCpOnList )
  89.     {
  90.       WCHAR wcBuf[256];
  91.       UCE_GetTableName( &pUceMemFile[i] , &pwszSubsetName );
  92.       if(*pwszSubsetName == L'0')
  93.       {
  94.           LoadString(hInst, _wtol(pwszSubsetName), wcBuf, 255);
  95.           pwszSubsetName = wcBuf;
  96.       }
  97.       nIndex = (INT)SendMessage( hCombo,
  98.                                  CB_ADDSTRING,
  99.                                  (WPARAM) 0,
  100.                                  (LPARAM) pwszSubsetName
  101.                                 );
  102.       if (nIndex != CB_ERR)
  103.       {
  104.         SendMessage( hCombo,
  105.                      CB_SETITEMDATA,
  106.                      (WPARAM) nIndex,
  107.                      (LPARAM)(PUCE_MEMORY_FILE) &pUceMemFile[i]
  108.                    );
  109.       }
  110.     }
  111.     i++;
  112.   }
  113.   return TRUE;
  114. }
  115. /****************************************************************************
  116.     Read the current UCE pointer
  117. ****************************************************************************/
  118. BOOL
  119. GetCurrentUCEFile(
  120.     PUCE_MEMORY_FILE *ppUceMemFile,
  121.     HWND   hWnd,
  122.     UINT   uID   )
  123. {
  124.   INT  nIndex;
  125.   BOOL bRet = FALSE;
  126.   nIndex = (INT)SendDlgItemMessage( hWnd,
  127.                                     uID,
  128.                                     CB_GETCURSEL,
  129.                                     (WPARAM) 0,
  130.                                     (LPARAM) 0L
  131.                                   );
  132.   if( nIndex != CB_ERR )
  133.   {
  134.     *ppUceMemFile = (PUCE_MEMORY_FILE) SendDlgItemMessage( hWnd,
  135.                                                            uID,
  136.                                                            CB_GETITEMDATA,
  137.                                                            (WPARAM) nIndex,
  138.                                                            (LPARAM) 0L
  139.                                                          );
  140.     bRet = TRUE;
  141.   }
  142.   return bRet;
  143. }
  144. /****************************************************************************
  145.     Get a Unicode buffer for the current view/subset when subset is all
  146.     Called to retreive what to display
  147. ****************************************************************************/
  148. BOOL
  149. Subset_GetUnicodeCharsToDisplay(
  150. HWND   hWnd,
  151. UINT   uID,
  152. LONG   lCodePage,
  153. PWSTR *ppCodeList,
  154. UINT  *puNum,
  155. BOOL  *pbLineBreak)
  156. {
  157.   PUCE_MEMORY_FILE pUceMemFile= NULL;
  158.   HWND             hCombo     = (HWND) GetDlgItem(hWnd,uID);
  159.   if(NULL == hCombo)
  160.   {
  161.     return FALSE;
  162.   }
  163.   // Get the Unicode of the current code page
  164.   if( !GetCurrentUCEFile( &pUceMemFile , hWnd ,uID ) || (NULL == pUceMemFile) )
  165.   {
  166.     return GetUnicodeBufferOfCodePage( lCodePage , ppCodeList , puNum );
  167.   }
  168.   else
  169.   {
  170.     if( pUceMemFile )
  171.     {
  172.       // Let's retreive the Unicode subset from the list
  173.       // and throw it back to the display
  174.       if( !Subset_GetUnicode(    // if fail, then select as if All is selected
  175.                     hWnd,
  176.                     pUceMemFile,
  177.                     ppCodeList,
  178.                     puNum,
  179.                     pbLineBreak ))
  180.         return GetUnicodeBufferOfCodePage( lCodePage , ppCodeList , puNum );
  181.     }
  182.   }
  183.   return TRUE;
  184. }
  185. /****************************************************************************
  186.   Convert a codepage to unicode buffer
  187. ****************************************************************************/
  188. BOOL
  189. GetUnicodeBufferOfCodePage(
  190.         LONG   lCodePage,
  191.         PWSTR *ppwBuf,
  192.         UINT  *puNum )
  193. {
  194.   *puNum  = WCharCP( lCodePage, wcUnicodeBuffer);
  195.   *ppwBuf = wcUnicodeBuffer ;
  196.   return (*puNum);
  197. }
  198. /****************************************************************************
  199.    Decide whether to retreive unicode from 1-d or 2-d current selection
  200. ****************************************************************************/
  201. BOOL
  202. Subset_GetUnicode(
  203.         HWND hWnd,
  204.         PUCE_MEMORY_FILE pUceMemFile,
  205.         PWSTR *ppwBuf,
  206.         UINT *puNum,
  207.         BOOL *pbLineBreak )
  208. {
  209.   BOOL bRet = FALSE;
  210.   switch( ((PUCE_HEADER)(pUceMemFile->pvData))->Row )
  211.   {
  212.   case 0:           // 1-d array
  213.     {
  214.       // should delete grid window if any
  215.       bRet = GetUnicodeCharsFromList(
  216.                                      hWnd,
  217.                                      pUceMemFile,
  218.                                      &wcUnicodeBuffer[0],
  219.                                      puNum,
  220.                                      pbLineBreak
  221.                                     );
  222.     }
  223.     break;
  224.   default:          // 2-d array
  225.     {
  226.       // should delete list window, if any
  227.       bRet = GetUnicodeCharsFromGridWindow(
  228.                                            hWnd,
  229.                                            &wcUnicodeBuffer[0],
  230.                                            puNum,
  231.                                            pbLineBreak
  232.                                           );                 // till now
  233.     }
  234.     break;
  235.   }
  236.   // Update user buffer
  237.   *ppwBuf = &wcUnicodeBuffer[0];
  238.   return bRet;
  239. }
  240. /****************************************************************************
  241.     When user selchange a subset, let's call our guys (if really changed)
  242.     to bring up a new list (if required)
  243.     must call SubSetChanged(...) after this
  244. ****************************************************************************/
  245. BOOL
  246. Subset_OnSelChange(
  247.     HWND hWnd,
  248.     UINT uID )
  249. {
  250.   static PUCE_MEMORY_FILE pLastUceMemFile = NULL;
  251.   PUCE_MEMORY_FILE        pCurUceMemFile;
  252.   PSTR                    pFile;
  253.   PUCE_HEADER             pHeader;
  254.   DWORD                   dw;
  255.   WCHAR                  *pWC;
  256.   // Let's know if it changed really
  257.   if( !GetCurrentUCEFile( &pCurUceMemFile , hWnd , uID ) ||
  258.       (NULL == pCurUceMemFile)
  259.     )
  260.   {
  261.     pLastUceMemFile = pCurUceMemFile;
  262.     DestroyAllListWindows();
  263.     return FALSE;
  264.   }
  265.   // Need to check also if the window list is available
  266.   if( (pLastUceMemFile == pCurUceMemFile) && IsListWindow( pCurUceMemFile ) )
  267.     return FALSE;
  268.   // If so, let's update our list view or grid
  269.   pFile = (PSTR) pCurUceMemFile->pvData;
  270.   pHeader  = (PUCE_HEADER) pCurUceMemFile->pvData;
  271.   pLastUceMemFile = pCurUceMemFile;
  272.   dw  = *(((DWORD*)pCurUceMemFile->pvData)+1);
  273.   pWC = (WCHAR*)(((BYTE*)pCurUceMemFile->pvData)+dw);
  274.   if(lstrcmp(pWC, L"010200") == 0)                             // Ideograf.UCE
  275.   {
  276.      UINT CharSet;
  277.      if(!(gFontType & DBCS_FONTTYPE) &&
  278.         (CharSet = Font_DBCS_CharSet()) != 0)
  279.      {
  280.          Font_SelectByCharSet(hWnd, ID_FONT, CharSet);
  281.      }
  282.   }
  283.   else
  284.   {
  285.       CHARSETINFO csi;
  286.       CPINFO      cpinfo;
  287.       // Indicate change of view to a new font
  288.       GetCPInfo(pHeader->Codepage, &cpinfo);
  289.       if(cpinfo.MaxCharSize > 1 &&
  290.          TranslateCharsetInfo((DWORD*)pHeader->Codepage, &csi, TCI_SRCCODEPAGE))
  291.       {
  292.           Font_SelectByCharSet(hWnd,ID_FONT, csi.ciCharset);
  293.       }
  294.   }
  295.   // Let's fetch the most appropriate code page
  296.   if( CodePage_SetCurrent( pHeader->Codepage , hWnd , ID_VIEW ) )
  297.   {
  298.       PostMessage( hWnd ,
  299.                    WM_COMMAND,
  300.                    MAKELONG(ID_VIEW,CBN_SELCHANGE),
  301.                    0L );
  302.   }
  303.   switch( pHeader->Row )
  304.   {
  305.   case 0:
  306.     // Destroy grid if needed
  307.     DestroyGridWindow();
  308.     CreateListWindow( hWnd , (PWSTR)(pFile+pHeader->OffsetTableName) ) ;
  309.     FillGroupsInListBox( hWnd , pCurUceMemFile );
  310.     break;
  311.   default:
  312.     DestroyListWindow();
  313.     DestroyGridWindow();
  314.     CreateGridWindow( hWnd , ID_FONT , pCurUceMemFile );
  315.     // create grid if needed
  316.     break;
  317.   }
  318.   EnableWindow(GetDlgItem(hwndDialog, ID_VIEW), FALSE);
  319.   return TRUE;
  320. }