localenv.cpp

Go to the documentation of this file.
00001 // $Id: localenv.cpp 899 2006-04-26 15:04:10Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // Calls to the host OS for environment infomation
00099 
00100 /*
00101 */
00102 #include "camtypes.h"
00103 
00104 #include "localenv.h"
00105 
00106 DECLARE_SOURCE("$Revision: 899 $");
00107 
00108 CC_IMPLEMENT_MEMDUMP(LocalEnvironment, CC_CLASS_MEMDUMP)
00109 CC_IMPLEMENT_DYNAMIC(LocaleChangedMsg, Msg)
00110 
00111 #define new CAM_DEBUG_NEW
00112 
00113 UINT32 LocalEnvironment::MouseDoubleClickDelay;
00114 UINT32 LocalEnvironment::XMouseDoubleClickMove;
00115 UINT32 LocalEnvironment::YMouseDoubleClickMove;
00116 
00117 PORTNOTE("other","Temporary ToUnicode, will be removed we Gerry checks in full impl.")
00118 static inline TCHAR ToUnicode( char ch )
00119 {
00120 #if 0 != wxUSE_UNICODE
00121     TCHAR   tch;
00122     mbtowc( &tch, &ch, 1 );
00123     return tch;
00124 #else
00125     return ch;
00126 #endif
00127 }
00128 
00129 /********************************************************************************************
00130 
00131 >   static void LocalEnvironment::GetNumberOfDecimalPlaces(UINT32* DecimalPlaces);
00132 
00133     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00134     Created:    30/08/94
00135     Inputs:     DecimalPlaces - pointer to the UINT32 to store the number found in.
00136     Outputs:    -
00137     Returns:    -
00138     Purpose:    Call the OS to get the number of decimal places we should use to display
00139                 numbers. Default is 2.
00140     Errors:     -
00141     SeeAlso:    -
00142 
00143 ********************************************************************************************/
00144 void LocalEnvironment::GetNumberOfDecimalPlaces(UINT32* DecimalPlaces)
00145 {
00146     TCHAR TS[8];
00147 
00148 
00149 PORTNOTE("other","Removed GetProfileString usage")
00150 #if defined(__MSW__)
00151     GetProfileString("intl", "iDigits", "2", TS, sizeof(TS));
00152 #else
00153 #if 0
00154 // AMB removed libiconv usage
00155     struct lconv *lc;
00156     lc = localeconv();
00157     TRACEUSER( "luke", _T("iDigits = %d\n"), lc->frac_digits );
00158     *DecimalPlaces = (UINT32)lc->frac_digits;
00159     return;
00160 #else //0
00161     TS[0]=_T('2');
00162     TS[1]=0;
00163 #endif //0
00164 #endif
00165 
00166     // Convert the string into a number that the string represents which we
00167     // can then return to the caller.
00168     TCHAR* pszMark;
00169     *DecimalPlaces = camStrtol( TS, &pszMark, 10 );
00170 }
00171 
00172 /********************************************************************************************
00173 
00174 >   static void LocalEnvironment::GetThousandsSeparator(StringBase* String)
00175 
00176     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00177     Created:    30/08/94
00178     Inputs:     String - pointer to the string to store the separator in.
00179     Outputs:    -
00180     Returns:    -
00181     Purpose:    Call the OS to get the character used as a thousands separator.  Default
00182                 separator is ",".
00183     Errors:     -
00184     SeeAlso:    -
00185 
00186 ********************************************************************************************/
00187 void LocalEnvironment::GetThousandsSeparator(StringBase* String)
00188 {
00189     *String = wxLocale::GetInfo(wxLOCALE_THOUSANDS_SEP, wxLOCALE_CAT_NUMBER);
00190 }
00191 
00192 /********************************************************************************************
00193 
00194 >   static void LocalEnvrionment::GetDecimalPointChar(StringBase* String)
00195 
00196     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00197     Created:    25/1/95
00198     Inputs:     String - pointer to the string to store the decimal point character in.
00199     Outputs:    -
00200     Returns:    -
00201     Purpose:    Call the OS to get the character used as a decimal point character.  Default
00202                 decimal point character is ".".
00203     Errors:     -
00204     SeeAlso:    -
00205 
00206 ********************************************************************************************/
00207 void LocalEnvironment::GetDecimalPointChar(StringBase* String)
00208 {
00209     *String = wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER);
00210 }
00211 
00212 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00213 /********************************************************************************************
00214 
00215 >   static void LocalEnvrionment::SystemDateToString(StringBase* String, time_t* Time)
00216 
00217     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com> (but copied from Andy's code)
00218     Created:    31/08/94
00219     Inputs:     String - pointer to the string to store the time in.
00220                 Time - the time and date in an ANSI time_t structure.
00221     Outputs:    -
00222     Returns:    -
00223     Purpose:    Produce a formatted string representing a date.  The format to use is read
00224                 from the OS (and thus is locale dependent).
00225     Errors:     -
00226     SeeAlso:    SystemTimeToString
00227                                                             
00228 ********************************************************************************************/
00229 void LocalEnvironment::SystemDateToString(StringBase* String, time_t* Time)
00230 {
00231     TCHAR c;
00232     TCHAR TimeFormat[40];
00233     TCHAR Temp[40];
00234     TCHAR Bodge[2];
00235     LPTCHAR p = TimeFormat;
00236     tm* TimeParts = localtime(Time);
00237     INT32 digits;
00238 
00239     GetProfileString("Intl", "sShortDate", "dd/MM/yy", TimeFormat, sizeof(TimeFormat));
00240     String->Empty();
00241     Bodge[1] = 0;
00242 
00243     while (c=*p++)
00244     {
00245         Bodge[0] = c;
00246         TCHAR* AnotherBodge = CharUpper(Bodge);
00247         TCHAR uc = *AnotherBodge;
00248         digits = 1;
00249 
00250         // this code relies on the same case being used throughout the field (e.g. ddDD will fail)
00251         while (c == *p)
00252         {
00253             c = *p++;
00254             digits ++;
00255         }
00256         switch (uc)
00257         {
00258             case TEXT('D') :
00259                 if (digits == 1)
00260                 {
00261                     wsprintf(Temp, "%d", TimeParts->tm_mday);
00262                 }
00263                 else
00264                 {
00265                     wsprintf(Temp, "%02d", TimeParts->tm_mday);
00266                 }
00267                 break;  
00268             case TEXT('M') :
00269                 if (digits == 1)
00270                 {
00271                     wsprintf(Temp, "%d", TimeParts->tm_mon+1);
00272                 }
00273                 else
00274                 {
00275                     wsprintf(Temp, "%02d", TimeParts->tm_mon+1);
00276                 }
00277                 break;  
00278             case TEXT('Y') :
00279                 if (digits == 2)
00280                 {
00281                     wsprintf(Temp, "%02d", TimeParts->tm_year % 100);
00282                 }
00283                 else
00284                 {
00285                     wsprintf(Temp, "%d", TimeParts->tm_year+1900);
00286                 }
00287                 break;
00288         }
00289         *String += Temp;
00290         if (*p != 0)
00291         {
00292             Bodge[0] = *p++;
00293             *String += Bodge;
00294         }
00295     }
00296 }
00297 
00298 
00299 
00300 /********************************************************************************************
00301 
00302 >   static void LocalEnvrionment::SystemTimeToString(StringBase* String, time_t* Time)
00303 
00304     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com> (but copied from Andy's code)
00305     Created:    31/08/94
00306     Inputs:     String - pointer to the string to store the time in.
00307                 Time - the time and date in an ANSI time_t structure.
00308     Outputs:    -
00309     Returns:    -
00310     Purpose:    Produce a formatted string representing a time.  The format to use is read
00311                 from the OS (and thus is locale dependent).
00312     Errors:     -
00313     SeeAlso:    SystemDateToString
00314 
00315 ********************************************************************************************/
00316 void LocalEnvironment::SystemTimeToString(StringBase* String, time_t* Time)
00317 {
00318     TCHAR Format[20];
00319     TCHAR Temp[40];
00320     TCHAR Separator[10];
00321     INT32 Hours;
00322     BOOL Trail = FALSE;
00323     tm* TimeParts = localtime(Time);
00324 
00325     Hours = TimeParts->tm_hour;
00326 
00327     GetProfileString("Intl", "iTime", "", Format, sizeof(Format));
00328     if (Format[0]=='0')
00329     {   // 12 hour clock wanted
00330         if (Hours>=12)
00331         {
00332             Trail = TRUE;
00333         }
00334         if (Hours>12)
00335         {
00336             Hours -= 12;
00337         }
00338     }
00339     else
00340     {   // 24 hour format
00341         Trail = TRUE;               
00342     }
00343     GetProfileString("Intl", "iTLZero", "1", Format, sizeof(Format));
00344     if (Format[0]=='1')
00345     {   // leading zeros please
00346         wsprintf(Temp, "%02d", Hours);
00347     }
00348     else
00349     {
00350         wsprintf(Temp, "%d", Hours);
00351     }
00352     *String = Temp;
00353     GetProfileString("Intl", "sTime", ":", Separator, sizeof(Separator));
00354     wsprintf(Temp, "%s%02d%s%02d", Separator, TimeParts->tm_min,
00355                                                             Separator, TimeParts->tm_sec);
00356     *String += Temp;
00357     if ((TimeParts->tm_hour < 12) && GetProfileString("Intl", "s1159", "",
00358                                                                     Format, sizeof(Format)))
00359     {
00360         wsprintf(Temp, "%s", Format);
00361         *String += Temp;
00362     }
00363     if (Trail && GetProfileString("Intl", "s2359", "", Format, sizeof(Format)))
00364     {
00365         wsprintf(Temp, "%s", Format);
00366         *String += Temp;
00367     }
00368 }
00369 #endif
00370 
00371 
00372 /********************************************************************************************
00373 >   static BOOL LocalEnvironment::UpdateCachedInfo()
00374 
00375     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00376     Created:    22/12/95
00377     Inputs:     -
00378     Outputs:    -
00379     Returns:    TRUE/FALSE for success/failure
00380     Purpose:    Call to (re)cache info held in this class.  Obviously call on startup, and
00381                 also when the user changes the machine settings
00382     Errors:     -
00383     SeeAlso:    -
00384 ********************************************************************************************/
00385 BOOL LocalEnvironment::UpdateCachedInfo()
00386 {
00387     // Get max time between two clicks making double clicks
00388 PORTNOTE("other","Removed GetProfileString usage")
00389 #ifndef EXCLUDE_FROM_XARALX
00390     MouseDoubleClickDelay = ::GetProfileInt("Windows","DoubleClickSpeed", 452);
00391 #else
00392     MouseDoubleClickDelay = 452;
00393 #endif
00394 
00395     // Get max movement between two clicks making double clicks
00396     XMouseDoubleClickMove = wxSystemSettings::GetMetric( wxSYS_DCLICK_X );
00397     YMouseDoubleClickMove = wxSystemSettings::GetMetric( wxSYS_DCLICK_X );
00398 
00399     return TRUE;
00400 }
00401 
00402 
00403 
00404 /********************************************************************************************
00405 >   static UINT32 LocalEnvironment::GetMouseDoubleClickDelay()
00406 
00407     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00408     Created:    22/12/95
00409     Inputs:     -
00410     Outputs:    -
00411     Returns:    Max time (in milliseconds) allowed between two clicks composing a double click
00412     Purpose:    Gets the maximum time allowed between two clicks that make up a double click
00413     Errors:     -
00414     SeeAlso:    -
00415 ********************************************************************************************/
00416 UINT32 LocalEnvironment::GetMouseDoubleClickDelay()
00417 {
00418     return MouseDoubleClickDelay;
00419 }
00420 
00421 
00422 
00423 /********************************************************************************************
00424 >   static UINT32 LocalEnvironment::GetXMouseDoubleClickMove()
00425 
00426     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00427     Created:    22/12/95
00428     Inputs:     -
00429     Outputs:    -
00430     Returns:    Max horizontal movement allowed between two clicks composing a double click
00431     Purpose:    Returns the maximum allowed movment (in mouse units) between two clicks that
00432                 compose a double click
00433     Errors:     -
00434     SeeAlso:    -
00435 ********************************************************************************************/
00436 UINT32 LocalEnvironment::GetXMouseDoubleClickMove()
00437 {
00438     return XMouseDoubleClickMove;
00439 }
00440 
00441 
00442 
00443 /********************************************************************************************
00444 >   static UINT32 LocalEnvironment::GetYMouseDoubleClickMove()
00445 
00446     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00447     Created:    22/12/95
00448     Inputs:     -
00449     Outputs:    -
00450     Returns:    Max vertical movement allowed between two clicks composing a double click
00451     Purpose:    Returns the maximum allowed movment (in mouse units) between two clicks that
00452                 compose a double click
00453     Errors:     -
00454     SeeAlso:    -
00455 ********************************************************************************************/
00456 UINT32 LocalEnvironment::GetYMouseDoubleClickMove()
00457 {
00458     return YMouseDoubleClickMove;
00459 }

Generated on Sat Nov 10 03:48:38 2007 for Camelot by  doxygen 1.4.4