home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OSL_INC.PAK / LOCALE.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  6KB  |  152 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectSupport
  3. // (C) Copyright 1994 by Borland International, All Rights Reserved
  4. //
  5. //  TLocaleString - localized name support
  6. //  TRegItem, TRegList - associative array of localizable string parameters
  7. //----------------------------------------------------------------------------
  8. #if !defined(OSL_LOCALE_H)
  9. #define OSL_LOCALE_H
  10.  
  11. #if !defined(OSL_DEFS_H)
  12. # include <osl/defs.h>
  13. #endif
  14. #if !defined(BI_PLAT_MSW)
  15. # error Locale classes are only supported under MSW
  16. #endif
  17. #if !defined(__COMMDLG_H)
  18. # include <commdlg.h>   // only for OFN_xxx defines
  19. #endif
  20. #if !defined(__CSTRING_H)
  21. # include <cstring.h>
  22. #endif
  23.  
  24. #define DEFAULT_SYSTEM_LANGID 0x409   // in case 16-bit with no NLS support
  25. typedef unsigned short TLangId;       // language ID - same as NT LANGID
  26. typedef int (*TstricmpLang)(const char far*, const char far*, TLangId);
  27. const TLangId LangSysDefault  = 0x0800;
  28. const TLangId LangUserDefault = 0x0400;
  29. const TLangId LangNeutral     = 0x0000;
  30.  
  31. //----------------------------------------------------------------------------
  32. // TLocaleString - localizable substitute for char*
  33. //
  34.  
  35. struct TLocaleString {
  36.   const char* Translate(TLangId lang);                      // translate string
  37.   operator const char*();      // return current string
  38.   void operator =(const char* str) { Private = str; }
  39.   int   Compare(const char far* str, TLangId lang);   // insensitive compare
  40.  
  41.   const char* Private;         // string pointer used for initialization
  42.  
  43.   static TLangId GetSystemLangId();  // platform-dependent implementation
  44.   static TLangId GetUserLangId();    // platform-dependent implementation
  45.   static int     IsNativeLangId(TLangId lang);  // returns bool true if native
  46.   static TLangId SystemDefaultLangId;// must define and set to system language
  47.   static TLangId UserDefaultLangId;  // same as system language if single user
  48.   static TLangId NativeLangId;   // must define and set to lang. of literals
  49.   static HINSTANCE Module;       // must define and set to resource module
  50.   static TLocaleString Null;     // reference a null string
  51.   static int CompareLang(const char far* s1, const char far* s2, TLangId);
  52.           // CompareLang() may be implemented in another module for NLS support
  53. };
  54.  
  55. //
  56. // Prefix characters for locale strings
  57. //
  58. #define AUTOLANG_RCID  '#' // indicates name specified by numeric ID
  59. #define AUTOLANG_XLAT  '!' // indicates name to be localized (binary)
  60. #define AUTOLANG_LOAD  '@' // indicates resource name to load (binary)
  61.  
  62. //
  63. // custom resource for translations
  64. //
  65. #define RT_LOCALIZATION MAKEINTRESOURCE(201)
  66.  
  67. //----------------------------------------------------------------------------
  68. // Registration parameter table macro definitions
  69. //
  70.  
  71. #define BEGIN_REGISTRATION(regname) extern  TRegItem regname##_list[]; \
  72.                                     TRegList regname(regname##_list); \
  73.                                     static  TRegItem regname##_list[] = {
  74. #define END_REGISTRATION {0,{0}} };
  75.  
  76. #define REGDATA(var,val) {#var, {val}}, 
  77. #define REGXLAT(var,val) {#var, {AUTOPREF_XLAT val}}, 
  78. #define REGITEM(key,val) {" " key, {val}}, 
  79. #define REGFORMAT(i,f,a,t,d) {"format" #i,{TRegItem::RegFormat(f,a,t,d,TRegItem::Heap)}},
  80. #define REGSTATUS(a,f) {"aspect" #a, {TRegItem::RegFlags(f,TRegItem::Heap)}},
  81. #define REGVERBOPT(v,mf,sf) {#v "opt",{TRegItem::RegVerbOpt(mf,sf,TRegItem::Heap)}},
  82. #define REGICON(i) {"iconindex",{TRegItem::RegFlags(i,TRegItem::Heap)}},
  83. #define REGDOCFLAGS(i) {"docflags",{TRegItem::RegFlags(i,TRegItem::Heap)}},
  84.  
  85. #define REGISTRATION_FORMAT_BUFFER(n) \
  86.   char OCRegFormatBuffer[n]; \
  87.   TRegFormatHeap TRegItem::Heap = {n, 0, OCRegFormatBuffer};
  88.  
  89. //----------------------------------------------------------------------------
  90. // Registration parameter structures and formatting functions
  91. //
  92.  
  93. //
  94. // Used internally to format registration strings
  95. //
  96. struct TRegFormatHeap {
  97.   int   Size;
  98.   int   Used;
  99.   char* Data;
  100. };
  101.  
  102. //
  103. // A single reglist entry
  104. //
  105. struct TRegItem {
  106.   char*         Key;           // non-localized parameter or registry subkey
  107.   TLocaleString Value;         // localizable value for parameter or subkey
  108.  
  109.   // used privately by REGFORMAT, REGSTATUS macros
  110.   //
  111.   static TRegFormatHeap Heap;   // string buffer defined in instance memory
  112.   static char* RegFormat(int   f, int a, int t, int d, TRegFormatHeap& heap);
  113.   static char* RegFormat(const char* f, int a, int t, int d, TRegFormatHeap& heap);
  114.   static char* RegFlags(long flags, TRegFormatHeap& heap);
  115.   static char* RegVerbOpt(int mf, int sf, TRegFormatHeap& heap);
  116. };
  117.  
  118. //
  119. // A registration parameter table, composed of a list of TRegItems 
  120. //
  121. class TRegList {
  122.   public:
  123.     TRegList(TRegItem* list) : Items(list) {}    
  124.     const char* Lookup(const char* key,
  125.                        TLangId lang = TLocaleString::UserDefaultLangId);
  126.     TLocaleString& LookupRef(const char* key);
  127.     const char* operator[](const char* key) {return Lookup(key);}
  128.  
  129.     TRegItem* Items;
  130. };
  131.  
  132. //
  133. // Registration link node, holding a pointer to a TRegList
  134. //
  135. class _BIDSCLASS TRegLink {
  136.   public:
  137.     TRegLink(TRegList& regList, TRegLink*& head);
  138.    ~TRegLink() {}
  139.     TRegLink*   GetNext() const {return Next;}
  140.     TRegList&   GetRegList() const {return *RegList;}
  141.  
  142.     static void AddLink(TRegLink*& head, TRegLink& newLink);
  143.     static bool RemoveLink(TRegLink*& head, TRegLink& remLink);
  144.  
  145.   protected:
  146.     TRegLink() : Next(0), RegList(0) {} // Derived class must fill in ptrs
  147.     TRegLink*  Next;      // Next RegLink
  148.     TRegList*  RegList;   // Pointer to registration parameter table
  149. };
  150.  
  151. #endif  // OSL_LOCALE_H
  152.