diff --git a/widget/src/gtk2/nsBidiKeyboard.cpp b/widget/src/gtk2/nsBidiKeyboard.cpp index ce2762175e8..719c8b60e76 100644 --- a/widget/src/gtk2/nsBidiKeyboard.cpp +++ b/widget/src/gtk2/nsBidiKeyboard.cpp @@ -21,6 +21,7 @@ * are Copyright (C) 2001 the Initial Developer. All Rights Reserved. * * Contributor(s): + * Behnam Esfahbod * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -36,27 +37,69 @@ * * ***** END LICENSE BLOCK ***** */ +#include "prlink.h" + #include "nsBidiKeyboard.h" +#include + + +static PRLibrary *gtklib = nsnull; + +typedef gboolean (PR_CALLBACK *GdkKeymapHaveBidiLayoutsType)(GdkKeymap *keymap); +static GdkKeymapHaveBidiLayoutsType GdkKeymapHaveBidiLayouts = nsnull; + NS_IMPL_ISUPPORTS1(nsBidiKeyboard, nsIBidiKeyboard) -nsBidiKeyboard::nsBidiKeyboard() : nsIBidiKeyboard() +nsBidiKeyboard::nsBidiKeyboard() { + if (!gtklib) + gtklib = PR_LoadLibrary("libgtk-x11-2.0.so.0"); + + if (gtklib && !GdkKeymapHaveBidiLayouts) + GdkKeymapHaveBidiLayouts = (GdkKeymapHaveBidiLayoutsType) PR_FindFunctionSymbol(gtklib, "gdk_keymap_have_bidi_layouts"); + + SetHaveBidiKeyboards(); } nsBidiKeyboard::~nsBidiKeyboard() { + if (gtklib) { + PR_UnloadLibrary(gtklib); + gtklib = nsnull; + + GdkKeymapHaveBidiLayouts = nsnull; + } } -NS_IMETHODIMP nsBidiKeyboard::IsLangRTL(PRBool *aIsRTL) +NS_IMETHODIMP +nsBidiKeyboard::IsLangRTL(PRBool *aIsRTL) { - *aIsRTL = PR_FALSE; - // XXX Insert platform specific code to determine keyboard direction - return NS_ERROR_NOT_IMPLEMENTED; + if (!mHaveBidiKeyboards) + return NS_ERROR_FAILURE; + + *aIsRTL = (gdk_keymap_get_direction(NULL) == PANGO_DIRECTION_RTL); + + return NS_OK; } -NS_IMETHODIMP nsBidiKeyboard::SetLangFromBidiLevel(PRUint8 aLevel) +nsresult +nsBidiKeyboard::SetHaveBidiKeyboards() +{ + mHaveBidiKeyboards = PR_FALSE; + + if (!gtklib || !GdkKeymapHaveBidiLayouts) + return NS_ERROR_FAILURE; + + mHaveBidiKeyboards = (*GdkKeymapHaveBidiLayouts)(NULL); + + return NS_OK; +} + +NS_IMETHODIMP +nsBidiKeyboard::SetLangFromBidiLevel(PRUint8 aLevel) { // XXX Insert platform specific code to set keyboard language return NS_ERROR_NOT_IMPLEMENTED; } + diff --git a/widget/src/gtk2/nsBidiKeyboard.h b/widget/src/gtk2/nsBidiKeyboard.h index 7b1b85c4b22..f58674c967d 100644 --- a/widget/src/gtk2/nsBidiKeyboard.h +++ b/widget/src/gtk2/nsBidiKeyboard.h @@ -21,6 +21,7 @@ * are Copyright (C) 2001 the Initial Developer. All Rights Reserved. * * Contributor(s): + * Behnam Esfahbod * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -47,8 +48,12 @@ public: NS_DECL_NSIBIDIKEYBOARD nsBidiKeyboard(); + +protected: virtual ~nsBidiKeyboard(); + + PRPackedBool mHaveBidiKeyboards; + nsresult SetHaveBidiKeyboards(); }; - #endif // __nsBidiKeyboard