Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsBidiKeyboard Class Reference

#include <nsBidiKeyboard.h>

Inheritance diagram for nsBidiKeyboard:
Inheritance graph
[legend]
Collaboration diagram for nsBidiKeyboard:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIBIDIKEYBOARD 
nsBidiKeyboard ()
virtual ~nsBidiKeyboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSIBIDIKEYBOARD 
nsBidiKeyboard ()
virtual ~nsBidiKeyboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSIBIDIKEYBOARD 
nsBidiKeyboard ()
virtual ~nsBidiKeyboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSIBIDIKEYBOARD 
nsBidiKeyboard ()
virtual ~nsBidiKeyboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSIBIDIKEYBOARD 
nsBidiKeyboard ()
virtual ~nsBidiKeyboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSIBIDIKEYBOARD 
nsBidiKeyboard ()
virtual ~nsBidiKeyboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSIBIDIKEYBOARD 
nsBidiKeyboard ()
virtual ~nsBidiKeyboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSIBIDIKEYBOARD 
nsBidiKeyboard ()
virtual ~nsBidiKeyboard ()
NS_DECL_ISUPPORTS
NS_DECL_NSIBIDIKEYBOARD 
nsBidiKeyboard ()
virtual ~nsBidiKeyboard ()
void isLangRTL (out PRBool aIsRTL)
 Determines if the current keyboard language is right-to-left.
void setLangFromBidiLevel (in PRUint8 aLevel)
 Sets the keyboard language to left-to-right or right-to-left.

Protected Member Functions

PRBool IsRTLLanguage (SInt32 aKeyboardResID)
nsresult EnumerateKeyboards ()
PRBool IsRTLLanguage (HKL aLocale)

Protected Attributes

PRBool mDefaultsSet
char mLTRKeyboard [KL_NAMELENGTH]
char mRTLKeyboard [KL_NAMELENGTH]
char mCurrentLocaleName [KL_NAMELENGTH]

Detailed Description

Definition at line 44 of file nsBidiKeyboard.h.


Constructor & Destructor Documentation

Definition at line 44 of file nsBidiKeyboard.cpp.

                               : nsIBidiKeyboard()
{
}

Definition at line 48 of file nsBidiKeyboard.cpp.

{
}
virtual nsBidiKeyboard::~nsBidiKeyboard ( ) [virtual]
virtual nsBidiKeyboard::~nsBidiKeyboard ( ) [virtual]
virtual nsBidiKeyboard::~nsBidiKeyboard ( ) [virtual]
virtual nsBidiKeyboard::~nsBidiKeyboard ( ) [virtual]
virtual nsBidiKeyboard::~nsBidiKeyboard ( ) [virtual]
virtual nsBidiKeyboard::~nsBidiKeyboard ( ) [virtual]
virtual nsBidiKeyboard::~nsBidiKeyboard ( ) [virtual]
virtual nsBidiKeyboard::~nsBidiKeyboard ( ) [virtual]

Member Function Documentation

Definition at line 125 of file nsBidiKeyboard.cpp.

{
  int keyboards;
  HKL far* buf;
  HKL locale;
  char localeName[KL_NAMELENGTH];
  PRBool isLTRKeyboardSet = PR_FALSE;
  PRBool isRTLKeyboardSet = PR_FALSE;
  
  // GetKeyboardLayoutList with 0 as first parameter returns the number of keyboard layouts available
  keyboards = ::GetKeyboardLayoutList(0, nsnull);
  if (!keyboards)
    return NS_ERROR_FAILURE;

  // allocate a buffer to hold the list
  buf = (HKL far*) PR_Malloc(keyboards * sizeof(HKL));
  if (!buf)
    return NS_ERROR_OUT_OF_MEMORY;

  // Call again to fill the buffer
  if (::GetKeyboardLayoutList(keyboards, buf) != keyboards) {
    PR_Free(buf);
    return NS_ERROR_UNEXPECTED;
  }

  // Go through the list and pick a default LTR and RTL keyboard layout
  while (keyboards--) {
    locale = buf[keyboards];
    if (IsRTLLanguage(locale)) {
      sprintf(mRTLKeyboard, "%.*x", KL_NAMELENGTH - 1, LANGIDFROMLCID(locale));
      isRTLKeyboardSet = PR_TRUE;
    }
    else {
      sprintf(mLTRKeyboard, "%.*x", KL_NAMELENGTH - 1, LANGIDFROMLCID(locale));
      isLTRKeyboardSet = PR_TRUE;
    }
  }
  PR_Free(buf);

  // Get the current keyboard layout and use it for either mRTLKeyboard or
  // mLTRKeyboard as appropriate. If the user has many keyboard layouts
  // installed this prevents us from arbitrarily resetting the current
  // layout (bug 80274)

  // If one or other keyboard is still not initialized, copy the
  // initialized keyboard to the uninitialized (bug 85813)
  locale = ::GetKeyboardLayout(0);
  if (!::GetKeyboardLayoutName(localeName))
    return NS_ERROR_FAILURE;

  NS_ASSERTION(*localeName, 
    "GetKeyboardLayoutName return string length == 0");
  NS_ASSERTION((strlen(localeName) < KL_NAMELENGTH), 
    "GetKeyboardLayout return string length >= KL_NAMELENGTH");

  if (IsRTLLanguage(locale)) {
    strncpy(mRTLKeyboard, localeName, KL_NAMELENGTH);
    mRTLKeyboard[KL_NAMELENGTH-1] = '\0'; // null terminate
    if (! isLTRKeyboardSet) {
      strncpy(mLTRKeyboard, localeName, KL_NAMELENGTH);
      mLTRKeyboard[KL_NAMELENGTH-1] = '\0'; // null terminate
    }
  }
  else {
    strncpy(mLTRKeyboard, localeName, KL_NAMELENGTH);
    mLTRKeyboard[KL_NAMELENGTH-1] = '\0'; // null terminate
    if (! isRTLKeyboardSet) {
      strncpy(mRTLKeyboard, localeName, KL_NAMELENGTH);
      mRTLKeyboard[KL_NAMELENGTH-1] = '\0'; // null terminate
    }
  }

  NS_ASSERTION(*mRTLKeyboard, 
    "mLTRKeyboard has string length == 0");
  NS_ASSERTION(*mLTRKeyboard, 
    "mLTRKeyboard has string length == 0");

  return NS_OK;
}

Here is the call graph for this function:

void nsIBidiKeyboard::isLangRTL ( out PRBool  aIsRTL) [inherited]

Determines if the current keyboard language is right-to-left.

PRBool nsBidiKeyboard::IsRTLLanguage ( SInt32  aKeyboardResID) [protected]

Definition at line 83 of file nsBidiKeyboard.cpp.

{
  // Check if the resource id is BiDi associated (Arabic, Persian, Hebrew)
  // (Persian is included in the Arabic range)
  // http://developer.apple.com/documentation/mac/Text/Text-534.html#HEADING534-0
  // Note: these ^^ values are negative on Mac OS X
  return (aKeyboardResID >= -18943 && aKeyboardResID <= -17920);
}

Here is the caller graph for this function:

PRBool nsBidiKeyboard::IsRTLLanguage ( HKL  aLocale) [protected]

Definition at line 206 of file nsBidiKeyboard.cpp.

{
  // This macro extracts the primary language id (low 10 bits) from the locale id
  switch (PRIMARYLANGID(aLocale)){
    case LANG_ARABIC:
    case LANG_FARSI:
    case LANG_HEBREW:
      return PR_TRUE;
      break;

    default:
      return PR_FALSE;
  }
}

Sets the keyboard language to left-to-right or right-to-left.

Parameters:
aLevel- if odd set the keyboard to RTL, if even set LTR

Member Data Documentation

char nsBidiKeyboard::mCurrentLocaleName[KL_NAMELENGTH] [protected]

Definition at line 62 of file nsBidiKeyboard.h.

Definition at line 59 of file nsBidiKeyboard.h.

char nsBidiKeyboard::mLTRKeyboard[KL_NAMELENGTH] [protected]

Definition at line 60 of file nsBidiKeyboard.h.

char nsBidiKeyboard::mRTLKeyboard[KL_NAMELENGTH] [protected]

Definition at line 61 of file nsBidiKeyboard.h.


The documentation for this class was generated from the following files: