Index: trunk/settings.cpp
===================================================================
--- trunk/settings.cpp	(revision 92)
+++ trunk/settings.cpp	(revision 94)
@@ -18,4 +18,5 @@
  ***/
 #include <direct.h>
+#include <uconv.h>
 #include "settings.h"
 #include "ctype.h"
@@ -32,4 +33,5 @@
 USHORT ausDef[7] = { 0 };
 USHORT ausDefSSW[7] = { 0 };
+BOOL  g_installer = FALSE;
 
 ImageFormatInfo Settings::ifi[BMF_INVALID] =
@@ -109,18 +111,65 @@
         //DisplayError( "NOT Updated", "true" );
     }
-
+#ifdef _QUIET_
+    HINI hini = PrfOpenProfile (hab, "gotchaq.ini");
+#else
+    HINI hini = PrfOpenProfile (hab, "gotcha.ini");
+#endif
+    BOOL fLChange = FALSE;
+    ULONG ulDataSize;
+    PrfQueryProfileSize(hini, "Language", "LangChangeRequested", &ulDataSize );
+    PrfQueryProfileData(hini, "Language", "LangChangeRequested", &fLChange, &ulDataSize);
+    if (!fLChange) {
+    CHAR *lang = getenv("LANG");
+#ifdef _QUIET_
+    PSZ  psz = "goqresen";
+#else
+    PSZ  psz = "gotresen";
+#endif
+    PSZ  pszh = "gotcha_en";
+    if (lang) {
+        if (!strnicmp(lang, "es", 2)) {
+            psz = "gotreses";
+            pszh = "gotcha_es";
+        }
+        else if (!strnicmp(lang, "cs", 2)) {
+            psz = "gotrescz";
+        }
+        else if (!strnicmp(lang, "de", 2)) {
+            psz = "gotresde";
+        }
+        else if (!strnicmp(lang, "it", 2)) {
+            psz = "gotresit";
+            pszh = "gotcha_it";
+        }
+        else if (!strnicmp(lang, "br", 2)) {
+            psz = "gotresbr";
+            pszh = "gotcha_br";
+        }
+    }
+    SetString(SEI_LANGUAGE, psz);
+    SetString (SEI_LANGUAGEHELP, pszh);
+    Save ();
+    }
+    if (hini)
+        PrfCloseProfile (hini);
     // to get the error msgs in default language
     ReloadResources (QueryString(SEI_LANGUAGE));
-
-    if (Error () == 1)
-    {
-        FileNotOpenError ();
-        ReloadResources (QueryString(SEI_LANGUAGE));
+#ifdef _QUIET_
+    if (!g_installer) {
+#endif
+        if (Error () == 1)
+        {
+            FileNotOpenError ();
+            ReloadResources (QueryString(SEI_LANGUAGE));
+        }
+        else if (Error () == 2)
+        {
+            VersionError ();
+            ReloadResources (QueryString(SEI_LANGUAGE));
+        }
+#ifdef _QUIET_
     }
-    else if (Error () == 2)
-    {
-        VersionError ();
-        ReloadResources (QueryString(SEI_LANGUAGE));
-    }
+#endif
 }
 
@@ -135,5 +184,5 @@
 }
 
-// ** FileNotOpenError **************************************************** /*fold00*/
+// ** FileNotOpenError **************************************************** /*FOLD00*/
 
 USHORT SETTINGS :: FileNotOpenError (VOID)
@@ -159,5 +208,5 @@
 
     // load the main dialog window
-    hwndDlg = WinLoadDlg (HWND_DESKTOP, hwndFrame, PFNWP (DialogProcedure),
+    hwndDlg = WinLoadDlg (HWND_DESKTOP, hwndFrame, (DialogProcedure),
                           GETMODULE, ID_DLG_SETTINGS, this);
     // FIXME YUKKI! YUKKI!! YUKKI!!! But I'm too lazy to do it better now :-)
@@ -199,8 +248,8 @@
 
         idPage[0] = (ULONG)
-            WinSendMsg (hwndNB, BKM_INSERTPAGE, 0L,
+            WinSendMsg (hwndDlg, BKM_INSERTPAGE, 0L,
                         MPFROM2SHORT (BKA_MAJOR | BKA_AUTOPAGESIZE,
                                       BKA_LAST));
-        WinSendMsg (hwndNB, BKM_SETTABTEXT, MPFROMLONG (idPage[0]),
+        WinSendMsg (hwndDlg, BKM_SETTABTEXT, MPFROMLONG (idPage[0]),
                     MPFROMP (pszPageTab[COUNT_PAGES-1]));
         hwndPage[0] = WinLoadDlg (hwndNB, hwndNB, (PFNWP) Page4Procedure,
@@ -214,10 +263,99 @@
         for (i = 0; i < cPages; i++)
         {
+	    //BOOKPAGEINFO pi;
             idPage[i] = (ULONG)
                 WinSendMsg (hwndNB, BKM_INSERTPAGE, 0L,
                             MPFROM2SHORT (BKA_MAJOR | BKA_AUTOPAGESIZE,
                                           BKA_LAST));
-            WinSendMsg (hwndNB, BKM_SETTABTEXT,
-                        MPFROMLONG (idPage[i]), MPFROMP (pszPageTab[i]));
+#if 0
+            pi.cb = sizeof(pi);
+            pi.fl = BFA_PAGEFROMDLGRES | BFA_MAJORTABTEXT;
+            pi.bLoadDlg = TRUE;
+            pi.hmodPageDlg = g_hmod;
+            switch (i) {
+#ifndef  _QUIET_
+            case 0:
+                pi.idPageDlg = ID_DLG_SETTINGSPAGE1;
+                pi.pfnPageDlgProc = NULL; //(PFN) Page1Procedure;
+                break;
+#else
+            case 0:
+                pi.idPageDlg = ID_DLG_SETTINGSPAGE0;
+                pi.pfnPageDlgProc = NULL; //(PFN) WindowProcedure;
+                break;
+#endif
+            case 1:
+                pi.idPageDlg = ID_DLG_SETTINGSPAGE2;
+                pi.pfnPageDlgProc = NULL; //(PFN) Page2Procedure;
+                break;
+#ifndef  _QUIET_
+            case 2:
+                pi.idPageDlg = ID_DLG_SETTINGSPAGE3;
+                pi.pfnPageDlgProc = NULL; //(PFN) Page3Procedure;
+                break;
+#else
+            case 2:
+                pi.idPageDlg = ID_DLG_SETTINGSPAGE1;
+                pi.pfnPageDlgProc = NULL; //(PFN) Page1Procedure;
+                break;
+#endif
+            case 3:
+                pi.idPageDlg = ID_DLG_SETTINGSPAGE4;
+                pi.pfnPageDlgProc = NULL; //(PFN) Page4Procedure;
+                break;
+            }
+            pi.cbMajorTab = strlen(pszPageTab[i]);
+            pi.pszMajorTab = pszPageTab[i];
+            pi.cbMinorTab = strlen(pszPageTab[i]);
+            pi.pszMinorTab = pszPageTab[i];
+            pi.cbStatusLine = 0;
+            pi.pszStatusLine = NULL;
+#endif
+            if (pset->GetLangID() == CZ || pset->GetLangID() == RU || pset->GetLangID() == PL) {
+                UniChar     target[300];
+                CHAR       ucLangStr[300];
+                UconvObject     uconv_object866 = NULL;
+                UconvObject     uconv_object852 = NULL;
+                UconvObject     uconv_object1207 = NULL;
+                UconvObject     uconv_object850 = NULL;
+                HAB hab;
+                CHAR ucFont[FACESIZE];
+    
+                UniCreateUconvObject((UniChar *)L"IBM-852", &uconv_object852);
+                UniCreateUconvObject((UniChar *)L"IBM-850", &uconv_object850);
+                UniCreateUconvObject((UniChar *)L"IBM-866", &uconv_object866);
+                UniCreateUconvObject((UniChar *)L"IBM-1207", &uconv_object1207);
+                
+                strcpy(ucLangStr, pszPageTab[i]);
+                if (pset->GetLangID() == CZ || pset->GetLangID() == PL) {
+                    
+                    UniStrToUcs( uconv_object852, target, ucLangStr, 299);
+                }
+                else if (pset->GetLangID() == RU)
+                    UniStrToUcs( uconv_object866, target, ucLangStr, 299);
+                else {
+                    UniStrToUcs( uconv_object850, target, ucLangStr, 299);
+                }
+                UniStrFromUcs( uconv_object1207, ucLangStr, target, 300);
+                WinSendMsg (hwndNB, BKM_SETTABTEXT,
+                            MPFROMLONG (idPage[i]), MPFROMP (ucLangStr));
+                /*pi.cbMajorTab = strlen(ucLangStr) + 10;
+                pi.pszMajorTab = ucLangStr;
+                pi.cbMinorTab = 0;
+                pi.pszMinorTab = "";*/
+                if (uconv_object866)
+                    UniFreeUconvObject(uconv_object866);
+                if (uconv_object852)
+                    UniFreeUconvObject(uconv_object852);
+                if (uconv_object850)
+                    UniFreeUconvObject(uconv_object850);
+                if (uconv_object1207)
+                    UniFreeUconvObject(uconv_object1207);
+            }
+            else
+                WinSendMsg (hwndNB, BKM_SETTABTEXT,
+                            MPFROMLONG (idPage[i]), MPFROMP (pszPageTab[i]));
+            //WinSendMsg(hwndNB, BKM_SETPAGEINFO, MPFROMLONG(idPage[i]),
+              //         MPFROMP(&pi));
         }
 #ifndef _QUIET_
@@ -301,8 +439,9 @@
 }
 
+ULONG winhDrawFormattedText(HPS hps, PRECTL prcl, const char *pcszText, ULONG flCmd);
+
 // ** DialogProcedure ***************************************************** /*FOLD00*/
 
-MRESULT EXPENTRY
-SETTINGS :: DialogProcedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
+MRESULT EXPENTRY SETTINGS :: DialogProcedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
     static PSETTINGS   pset = NULL;
@@ -322,4 +461,65 @@
         LogDebug( "DialogProcedure: end WM_INITDLG" );
 #endif
+        CHAR ucFont[FACESIZE];
+        if (pset->GetLangID() == CZ || pset->GetLangID() == RU || pset->GetLangID() == PL) {
+           HMQ hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+           WinSetCp(hmq, 1207);
+           strcpy(ucFont, "8.Times New Roman MT 30");
+           WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(ucFont) + 1, ucFont);
+
+           UniChar     target[300];
+           CHAR       ucLangStr[300];
+           UconvObject     uconv_object866 = NULL;
+           UconvObject     uconv_object860 = NULL;
+           UconvObject     uconv_object852 = NULL;
+           UconvObject     uconv_object1207 = NULL;
+           UconvObject     uconv_object850 = NULL;
+           HAB hab;
+           CHAR ucFont[FACESIZE];
+
+           UniCreateUconvObject((UniChar *)L"IBM-852", &uconv_object852);
+           UniCreateUconvObject((UniChar *)L"IBM-850", &uconv_object850);
+           UniCreateUconvObject((UniChar *)L"IBM-866", &uconv_object866);
+           UniCreateUconvObject((UniChar *)L"IBM-1207", &uconv_object1207);
+           
+           WinLoadString(hab, g_hmod, IDS_UNDO, sizeof(ucLangStr), ucLangStr);
+           if (pset->GetLangID() == CZ || pset->GetLangID() == PL) {
+               
+               UniStrToUcs( uconv_object852, target, ucLangStr, 299);
+           }
+           else if (pset->GetLangID() == RU)
+               UniStrToUcs( uconv_object866, target, ucLangStr, 299);
+           else {
+               UniStrToUcs( uconv_object850, target, ucLangStr, 299);
+           }
+           UniStrFromUcs( uconv_object1207, ucLangStr, target, 300);
+           WinSetDlgItemText(hwnd, WID_PB_UNDO, ucLangStr);
+           WinLoadString(hab, g_hmod, IDS_HELP, sizeof(ucLangStr), ucLangStr);
+
+           if (pset->GetLangID() == CZ || pset->GetLangID() == PL) {
+               
+               UniStrToUcs( uconv_object852, target, ucLangStr, 299);
+           }
+           else if (pset->GetLangID() == RU)
+               UniStrToUcs( uconv_object866, target, ucLangStr, 299);
+           else {
+               UniStrToUcs( uconv_object850, target, ucLangStr, 299);
+           }
+           UniStrFromUcs( uconv_object1207, ucLangStr, target, 300);
+           WinSetDlgItemText(hwnd, WID_PB_HELP, ucLangStr);
+           if (uconv_object866)
+               UniFreeUconvObject(uconv_object866);
+           if (uconv_object852)
+               UniFreeUconvObject(uconv_object852);
+           if (uconv_object850)
+               UniFreeUconvObject(uconv_object850);
+           if (uconv_object1207)
+               UniFreeUconvObject(uconv_object1207);
+        }
+        else {
+        strcpy(ucFont, "10.WarpSans");
+        WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(ucFont) + 1, ucFont);
+        }
+            
         return MRESULT (FALSE);
 
@@ -437,6 +637,5 @@
 // ** Page1Procedure ****************************************************** /*FOLD00*/
 
-MRESULT EXPENTRY
-SETTINGS :: Page1Procedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
+MRESULT EXPENTRY SETTINGS :: Page1Procedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
     static PSETTINGS   pset = NULL;
@@ -458,4 +657,32 @@
             }
         }
+        HMQ hmq;
+        BOOL bUniCodeFont;
+        CHAR ucFont[FACESIZE];
+
+        if (pset->GetLangID() == RU) {
+            hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+            WinSetCp(hmq, 866);
+            bUniCodeFont = TRUE;
+        }
+        else if (pset->GetLangID() == CZ || pset->GetLangID() == PL) {
+            hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+            WinSetCp(hmq, 852);
+            bUniCodeFont = TRUE;
+        }
+        else {
+            hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+            WinSetCp(hmq, 850);
+        }
+
+        if (bUniCodeFont) {
+            strcpy(ucFont, "8.Times New Roman MT 30");
+            WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(ucFont) + 1, ucFont);
+        }
+        else {
+            strcpy(ucFont, "10.WarpSans");
+            WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(ucFont) + 1, ucFont);
+        }
+
 #ifdef _DOLOGDEBUG_
         LogDebug( "Page1Procedure: end WM_INITDLG" );
@@ -463,4 +690,51 @@
         return MRESULT (FALSE);
     }
+
+    case WM_DRAWITEM:
+
+        POWNERITEM poItem;
+        HPS hps;
+        RECTL       rcl,          // window area
+                    rclClip;      // clipping region for drawn text
+        POINTL      ptl;          // current text position
+        FATTRS      fontAttrs;    // current font attributes
+        FONTMETRICS fm;           // current font metr
+
+
+        poItem = POWNERITEM (mp2);
+
+        //hps = WinBeginPaint( hwnd, NULLHANDLE, NULLHANDLE );
+        memset( &fontAttrs, 0, sizeof(FATTRS) );
+        PmpfF(("PageID %i", poItem->hItem));
+        // set the font attributes and create the logical font
+        fontAttrs.usRecordLength = sizeof(FATTRS);
+        fontAttrs.usCodePage     = 852;
+        fontAttrs.fsType         = FATTR_TYPE_MBCS;
+        fontAttrs.fsFontUse      = FATTR_FONTUSE_NOMIX;
+        strcpy( fontAttrs.szFacename, "10.WarpSans");
+        GpiCreateLogFont( poItem->hps, NULL, 1L, &fontAttrs );
+        GpiSetCharSet( poItem->hps, 1L );
+        // paint the window background
+        //WinQueryWindowRect( hwnd, &rcl ); ????
+        WinFillRect( hps, &poItem->rclItem, SYSCLR_WINDOW );
+        GpiQueryFontMetrics( poItem->hps, sizeof(FONTMETRICS), &fm );
+        rclClip.xLeft   = poItem->rclItem.xLeft + fm.lAveCharWidth;
+        rclClip.yBottom = poItem->rclItem.yBottom + fm.lXHeight;
+        rclClip.xRight  = poItem->rclItem.xRight - fm.lAveCharWidth;
+        rclClip.yTop    = poItem->rclItem.yTop - fm.lXHeight;
+        ptl.x = rclClip.xLeft;
+        ptl.y = rclClip.yTop - fm.lExternalLeading - fm.lMaxAscender;
+        GpiCharStringPosAt( poItem->hps, &ptl, &rclClip, CHS_CLIP,
+                           /*Strlen(pszPageTab[i])*/5, (PCH) /*pszPageTab[i]*/ "Test", NULL );
+        WinEndPaint( hps );
+
+        //poItem->hwnd = hwndNB;            /*  Window handle. */
+        //poItem->hps = hps;             /*  Presentation-space handle. */
+        //poItem->fsState = BKS_BACKPAGESTR | BKS_MAJORTABTOP | BKS_TABBEDDIALOG;         /*  State. */
+        //poItem->fsAttribute = BKA_MAJOR | BKA_AUTOPAGESIZE;     /*  Attribute. */
+        //poItem->rclItem; ????        /*  Item rectangle. */
+        //poItem->hItem = idPage[i];
+
+        break;
 
     case WM_COMMAND:
@@ -623,6 +897,5 @@
 // ** Page2Procedure ****************************************************** /*FOLD00*/
 
-MRESULT EXPENTRY
-SETTINGS :: Page2Procedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
+MRESULT EXPENTRY SETTINGS :: Page2Procedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
     static PSETTINGS   pset = NULL;
@@ -638,4 +911,29 @@
         LogDebug( "Page1Procedure: end WM_INITDLG" );
 #endif
+        HMQ hmq;
+        BOOL bUniCodeFont;
+        CHAR ucFont[FACESIZE];
+        
+        if (pset->GetLangID() == RU) {
+            hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+            WinSetCp(hmq, 866);
+            bUniCodeFont = TRUE;
+        }
+        else if (pset->GetLangID() == CZ || pset->GetLangID() == PL) {
+            hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+            WinSetCp(hmq, 852);
+            bUniCodeFont = TRUE;
+        }
+        else {
+            hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+            WinSetCp(hmq, 850);
+        }
+
+        if (bUniCodeFont) {
+            strcpy(ucFont, "8.Times New Roman MT 30");
+            WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(ucFont) + 1, ucFont);
+        }
+        //else
+           // WinRemovePresParam(hwnd, PP_FONTNAMESIZE);
         return MRESULT (FALSE);
 
@@ -819,6 +1117,5 @@
 // ** Page3Procedure ****************************************************** /*FOLD00*/
 
-MRESULT EXPENTRY
-SETTINGS :: Page3Procedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
+MRESULT EXPENTRY SETTINGS :: Page3Procedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
     static PSETTINGS   pset = NULL;
@@ -834,4 +1131,29 @@
         LogDebug( "Page3Procedure: end WM_INITDLG" );
 #endif
+        HMQ hmq;
+        BOOL bUniCodeFont;
+        CHAR ucFont[FACESIZE];
+        
+        if (pset->GetLangID() == RU) {
+            hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+            WinSetCp(hmq, 866);
+            bUniCodeFont = TRUE;
+        }
+        else if (pset->GetLangID() == CZ || pset->GetLangID() == PL) {
+            hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+            WinSetCp(hmq, 852);
+            bUniCodeFont = TRUE;
+        }
+        else {
+            hmq = WinQueryWindowULong( hwnd, QWL_HMQ);
+            WinSetCp(hmq, 850);
+        }
+
+        if (bUniCodeFont) {
+            strcpy(ucFont, "8.Times New Roman MT 30");
+            WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(ucFont) + 1, ucFont);
+        }
+        //else
+        //    WinRemovePresParam(hwnd, PP_FONTNAMESIZE);
         return MRESULT (FALSE);
 
@@ -946,6 +1268,5 @@
 // ** Page4Procedure ****************************************************** /*FOLD00*/
 
-MRESULT EXPENTRY
-SETTINGS :: Page4Procedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
+MRESULT EXPENTRY SETTINGS :: Page4Procedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
     static PSETTINGS   pset = NULL;
@@ -959,5 +1280,7 @@
 #endif
             pset = PSETTINGS (mp2);
-
+            HMQ hmq = WinQueryWindowULong(hwnd /*WinWindowFromID(hwnd, ID_DLG_SETTINGSPAGE4)*/, QWL_HMQ);
+            WinSetCp(hmq, 1207); // UPF-8 Unicode
+            WinRemovePresParam(hwnd, PP_FONTNAMESIZE);
             pset->GetLanguages(WinWindowFromID (hwnd, WID_LB_LANGUAGES));
 
@@ -1006,6 +1329,58 @@
             LogDebug( "Page4Procedure: end WM_INITDLG" );
 #endif
-        }
+
+            UniChar     target[300];
+            CHAR       ucLangStr[300];
+            UconvObject     uconv_object866 = NULL;
+            UconvObject     uconv_object860 = NULL;
+            UconvObject     uconv_object852 = NULL;
+            UconvObject     uconv_object1207 = NULL;
+            UconvObject     uconv_object850 = NULL;
+            int result;
+            int i;
+            HAB hab;
+            CHAR ucFont[FACESIZE];
+
+            UniCreateUconvObject((UniChar *)L"IBM-852", &uconv_object852);
+            UniCreateUconvObject((UniChar *)L"IBM-850", &uconv_object850);
+            UniCreateUconvObject((UniChar *)L"IBM-866", &uconv_object866);
+           
+            UniCreateUconvObject((UniChar *)L"IBM-1207", &uconv_object1207);
+            for (i = 0; i < WID_ST_END - 400; i++) {
+                WinLoadString(hab, g_hmod, LANG_COPYRIGHT + i, sizeof(ucLangStr), ucLangStr);
+                if (pset->GetLangID() == 420 ||
+                    pset->GetLangID() == PL) {
+                    
+                    UniStrToUcs( uconv_object852, target, ucLangStr, 299);
+                }
+                else if (pset->GetLangID() == RU)
+                    UniStrToUcs( uconv_object866, target, ucLangStr, 299);
+                else {
+                    UniStrToUcs( uconv_object850, target, ucLangStr, 299);
+                }
+                UniStrFromUcs( uconv_object1207, ucLangStr, target, 300);
+                WinSetDlgItemText(hwnd, WID_ST_COPYRIGHT + i, ucLangStr);
+            }
+
+            if (uconv_object866)
+                UniFreeUconvObject(uconv_object866);
+            if (uconv_object852)
+                UniFreeUconvObject(uconv_object852);
+            if (uconv_object850)
+                UniFreeUconvObject(uconv_object850);
+            if (uconv_object1207)
+                UniFreeUconvObject(uconv_object1207);
+            
+            if (pset->GetLangID() == RU || pset->GetLangID() == CZ || pset->GetLangID() == PL ||
+               pset->GetLangID() == IT) {
+                strcpy(ucFont, "8.Times New Roman MT 30");
+                WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(ucFont) + 1, ucFont);
+            }
+            
+            //    WinRemovePresParam(hwnd, PP_FONTNAMESIZE);*/
+            //HMQ hmq = WinQueryWindowULong(hwnd /*WinWindowFromID(hwnd, WID_LB_LANGUAGES)*/, QWL_HMQ);
+            //WinSetCp(hmq, 1207); // UPF-8 Unicode
         return MRESULT (FALSE);
+        }
 
     case WM_COMMAND:
@@ -1076,6 +1451,8 @@
 
     case WM_DESTROY:
+#ifndef _QUIET_
         {
             CHAR   ach[_MAX_FNAME];
+            BOOL fChanged = TRUE;
 
             ULONG ul = USHORT (WinSendDlgItemMsg (hwnd, WID_LB_LANGUAGES,
@@ -1085,6 +1462,9 @@
                                              LM_QUERYITEMHANDLE,
                                              MPFROMLONG(ul), NULL));
-            pset->SetString(SEI_LANGUAGE, psz);
-
+            if (stricmp (pset->QueryString(SEI_LANGUAGE), psz) == 0)
+                fChanged = FALSE;
+            else
+                pset->SetString(SEI_LANGUAGE, psz);
+#if 0
             ul = USHORT (WinSendDlgItemMsg (hwnd, WID_LB_LANGUAGESHELP,
                                             LM_QUERYSELECTION,
@@ -1092,9 +1472,34 @@
             WinSendDlgItemMsg (hwnd, WID_LB_LANGUAGESHELP, LM_QUERYITEMTEXT,
                                MPFROM2SHORT (ul, sizeof (ach)), MPFROMP (ach));
-            pset->SetString (SEI_LANGUAGEHELP, ach);
-
-            if (saveum)
+            if (stricmp (pset->QueryString(SEI_LANGUAGEHELP), ach) == 0 && !fChanged)
+                fChanged = FALSE;
+            else
+                pset->SetString (SEI_LANGUAGEHELP, ach);
+#endif
+            if (fChanged) {
+                if (!stricmp(psz, "gotreses") || !stricmp(psz, "goqreses"))
+                    strcpy(ach, "gotcha_es");
+                else if (!stricmp(psz, "gotresbr") || !stricmp(psz, "goqresbr"))
+                    strcpy(ach, "gotcha_br");
+                else if (!stricmp(psz, "gotresit") || !stricmp(psz, "goqresit"))
+                    strcpy(ach, "gotcha_it");
+                else
+                    strcpy(ach, "gotcha_en");
+                pset->SetString (SEI_LANGUAGEHELP, ach);
+            }
+            if (saveum && fChanged) {
                 pset->Save ();
-        }
+#ifdef _QUIET_
+                HINI hini = PrfOpenProfile (hab, "gotchaq.ini");
+#else
+                HINI hini = PrfOpenProfile (hab, "gotcha.ini");
+#endif
+                BOOL fLChanged = TRUE;
+                PrfWriteProfileData(hini, "Language", "LangChangeRequested", &fLChanged, sizeof(BOOL));
+                if (hini)
+                    PrfCloseProfile (hini);
+            }
+        }
+#endif
         return MRESULT (FALSE);
     }
@@ -1114,5 +1519,5 @@
 }
 
-// ** QueryWindowData ***************************************************** /*fold00*/
+// ** QueryWindowData ***************************************************** /*FOLD00*/
 
 VOID SETTINGS :: QueryWindowData (SWP *pswp, USHORT us[7], BOOL f)
@@ -1158,12 +1563,14 @@
     if ((rc = DosLoadModule(PSZ(NULL), 0, psz, &g_hmod)))
     {
-        DisplayError("Error",
-                     "Could not (re)load resource module '%s' (return code %d). "
-                     "Make sure the DLL is in the LIBPATH. If this is the case, "
-                     "try deleting GOTCHA.INI and restart. If this fails, contact "
-                     "the author (ygk@qwest.net).", psz, rc);
+        DisplayError(RSTR(IDS_HEADER_ERROR),
+                     RSTR(IDS_ERROR_RESOURSEMODFAILED), psz, rc);
         exit(1);
     }
-
+    PVOID pv;
+    INT Lang;
+
+    DosGetResource(g_hmod, RT_RCDATA, LANG_ID, &pv);
+    Lang = atoi((PCHAR) pv);
+    SetLangID(Lang);
     ResourceString::Module(g_hmod);
 #ifdef _QUIET_
@@ -1236,4 +1643,6 @@
         if ((rc = DosLoadModule(PSZ(NULL), 0, findbuf.achName, &hmod)) == NO_ERROR) {
             PVOID pv;
+            PVOID pl;
+
             if (DosGetResource(hmod, RT_RCDATA, DLL_ID, &pv) == NO_ERROR) {
 #ifdef _QUIET_
@@ -1242,9 +1651,53 @@
                 if (strcmp(PSZ(pv), "Gotcha!") == 0) {
 #endif
-                    psz = PSZ(pv)+strlen(PSZ(pv))+3;
-                    ul = WinInsertLboxItem (hwnd, LIT_END, psz);
+                    psz = PSZ(pv)+strlen(PSZ(pv)) + 3;
+                    
+                    INT Lang;
+                
+                    DosGetResource(hmod, RT_RCDATA, LANG_ID, &pl);
+                    Lang = atoi((PCHAR) pl);
+#if 1
+                    UniChar     target[300];
+                    CHAR       ucLangStr[300];
+                    UconvObject     uconv_object866 = NULL;
+                    UconvObject     uconv_object852 = NULL;
+                    UconvObject     uconv_object1207 = NULL;
+                    UconvObject     uconv_object850 = NULL;
+                    int i;
+                    
+                    strcpy(ucLangStr, psz);
+                    UniCreateUconvObject((UniChar *)L"IBM-852", &uconv_object852);
+                    UniCreateUconvObject((UniChar *)L"IBM-850", &uconv_object850);
+                    UniCreateUconvObject((UniChar *)L"IBM-866", &uconv_object866);
+                    UniCreateUconvObject((UniChar *)L"IBM-1207", &uconv_object1207);
+                    
+                    if (Lang == CZ) {
+                        UniStrToUcs( uconv_object852, target, ucLangStr, 299);
+                        }
+                        else {
+                            UniStrToUcs( uconv_object850, target, ucLangStr, 299);
+                        }
+                        /*if (Lang == RU) {
+                            UniStrToUcs( uconv_object866, target, ucLangStr, 299);
+                        } */
+                        UniStrFromUcs( uconv_object1207, ucLangStr, target, 300);
+                    Lang = 0;
+                    if (uconv_object866)
+                        UniFreeUconvObject(uconv_object866);
+                    if (uconv_object852)
+                        UniFreeUconvObject(uconv_object852);
+                    if (uconv_object850)
+                        UniFreeUconvObject(uconv_object850);
+                    if (uconv_object1207)
+                        UniFreeUconvObject(uconv_object1207);
+
+
+#endif
+                    ul = WinInsertLboxItem (hwnd, LIT_END,/*psz*/ucLangStr);
                     WinSendMsg(hwnd, LM_SETITEMHANDLE, MPFROMLONG(ul),
                                MPFROMP (strdup(findbuf.achName)));
                 }
+                if (pl)
+                    DosFreeResource(pl);
                 DosFreeResource(pv);
             }
@@ -1308,2 +1761,66 @@
 
 // ************************************************************************
+
+ULONG winhDrawFormattedText(HPS hps,     // in: presentation space; its settings
+                                         // are used, but not altered
+                            PRECTL prcl, // in/out: rectangle to use for drawing
+                                         // (modified)
+                            const char *pcszText, // in: text to draw (zero-terminated)
+                            ULONG flCmd) // in: flags like in WinDrawText; I have
+                                         // only tested DT_TOP and DT_LEFT though.
+                                         // DT_WORDBREAK | DT_TEXTATTRS are always
+                                         // set.
+                                         // You can specify DT_QUERYEXTENT to only
+                                         // have prcl calculated without drawing.
+{
+    PSZ     p = (PSZ)pcszText;
+    LONG    lDrawn = 1,
+            lTotalDrawn = 0,
+            lLineCount = 0,
+            lOrigYTop = prcl->yTop;
+    ULONG   ulTextLen = strlen(pcszText),
+            ulCharHeight,
+            flCmd2,
+            xLeftmost = prcl->xRight,
+            xRightmost = prcl->xLeft;
+    RECTL   rcl2;
+
+    flCmd2 = flCmd | DT_WORDBREAK | DT_TEXTATTRS;
+
+    ulCharHeight = 30;//gpihQueryLineSpacing(hps);
+
+    while (    (lDrawn)
+            && (lTotalDrawn < ulTextLen)
+          )
+    {
+        memcpy(&rcl2, prcl, sizeof(rcl2));
+        lDrawn = WinDrawText(hps,
+                             ulTextLen-lTotalDrawn,
+                             p,
+                             &rcl2,
+                             0, 0,                       // colors
+                             flCmd2);
+
+        // update char counters
+        p += lDrawn;
+        lTotalDrawn += lDrawn;
+
+        // update x extents
+        if (rcl2.xLeft < xLeftmost)
+            xLeftmost = rcl2.xLeft;
+        if (rcl2.xRight > xRightmost)
+            xRightmost = rcl2.xRight;
+
+        // update y for next line
+        prcl->yTop -= ulCharHeight;
+
+        // increase line count
+        lLineCount++;
+    }
+    prcl->xLeft = xLeftmost;
+    prcl->xRight = xRightmost;
+    prcl->yBottom = prcl->yTop;
+    prcl->yTop = lOrigYTop;
+
+    return lLineCount;
+}
