Back to index

lightning-sunbird  0.9+nobinonly
nsGtkIMEHelper.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Frank Tang <ftang@netsape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #ifndef nsGtkIMEHelper_h__
00039 #define nsGtkIMEHelper_h__
00040 #include "nsIUnicodeDecoder.h"
00041 #include "nsString.h"
00042 #include <gtk/gtk.h>
00043 
00044 /*
00045  * We are gradually moving IME related function into this class
00046  */
00047 class nsGtkIMEHelper {
00048 public:
00049   ~nsGtkIMEHelper();
00050   nsresult ConvertToUnicode(const char* aSrc, PRInt32* aSrcLen,
00051                             PRUnichar*  aDes, PRInt32* aDesLen);
00052   static nsGtkIMEHelper *GetSingleton();
00053   void ResetDecoder();
00054   static void Shutdown();
00055   PRInt32 MultiByteToUnicode(const char*, const PRInt32,
00056                              PRUnichar**, PRInt32*);
00057 #if defined(USE_XIM) && defined(_AIX)
00058   PRUnichar* GetUnichars() const { return mUnichars; }
00059   PRInt32 GetUnicharsSize() const { return mUnicharsSize; }
00060 
00061   // It is the caller's responsibility to free any data in
00062   // mUnichars prior to calling SetUnichars()
00063   void SetUnichars(PRUnichar *aUnichars) { mUnichars = aUnichars; }
00064   void SetUnicharsSize(PRInt32 aUnicharsSize)
00065     { mUnicharsSize = aUnicharsSize; }
00066 #endif
00067 
00068 private:
00069   nsGtkIMEHelper();
00070   nsIUnicodeDecoder* mDecoder;
00071   void SetupUnicodeDecoder();
00072   static nsGtkIMEHelper *gSingleton;
00073 #if defined(USE_XIM) && defined(_AIX)
00074   PRUnichar* mUnichars;
00075   PRInt32 mUnicharsSize;
00076 #endif
00077 };
00078 
00079 #ifdef USE_XIM
00080 class nsIMEPreedit {
00081  private:
00082   PRInt32       mCaretPosition;
00083   nsString*     mIMECompUnicode;
00084   nsCString*    mIMECompAttr;
00085   PRUnichar*    mCompositionUniString;
00086   PRInt32       mCompositionUniStringSize;
00087  public:
00088   nsIMEPreedit();
00089   ~nsIMEPreedit();
00090   void Reset();
00091   const PRUnichar* GetPreeditString() const;
00092   const char* GetPreeditFeedback() const;
00093   int GetPreeditLength() const;
00094   void SetPreeditString(const XIMText* aText,
00095                         const PRInt32 aChangeFirst,
00096                         const PRInt32 aChangeLength);
00097   static void IMSetTextRange(const PRInt32 aLen,
00098                              const char *aFeedback,
00099                              PRUint32 *,
00100                              nsTextRangeArray*);
00101 };
00102 
00103 class nsWindow;
00104 
00105 class nsIMEStatus {
00106  private:
00107   Window mIMStatusWindow;
00108   Window mIMStatusLabel;  
00109   XFontSet mFontset;
00110   int mWidth;
00111   int mHeight;
00112   GC mGC;
00113   void resize(const char *);
00114   void remove_decoration();
00115   void getAtoms();
00116   static Bool client_filter(Display *d, Window w, XEvent *ev,
00117                                XPointer client_data);
00118   static Bool repaint_filter(Display *d, Window w, XEvent *ev,
00119                              XPointer client_data);
00120   static Bool clientmessage_filter(Display *d, Window w, XEvent *ev,
00121                                    XPointer client_data);
00122   void CreateNative();
00123   void DestroyNative();
00124  public:
00125   nsIMEStatus();
00126   nsIMEStatus(GdkFont*);
00127   void SetFont(GdkFont*);
00128   ~nsIMEStatus();
00129   void UnregisterClientFilter(Window);
00130   void RegisterClientFilter(Window);
00131   void setText(const char*);
00132   void setParentWindow(nsWindow*);
00133   void resetParentWindow(nsWindow*);
00134   void show();
00135   void hide();
00136 
00137   nsWindow *mAttachedWindow;
00138   GdkWindow *mParent;
00139 };
00140 
00141 /* for XIM callback */
00142 typedef int (*XIMProc1)(XIC, XPointer, XPointer);
00143 typedef struct {
00144   XPointer client_data;
00145   XIMProc1 callback;
00146 } XIMCallback1;
00147 
00148 class nsIMEGtkIC {
00149  private:
00150   static int preedit_start_cbproc(XIC, XPointer, XPointer);
00151   static int preedit_draw_cbproc(XIC, XPointer, XPointer);
00152   static int preedit_done_cbproc(XIC, XPointer, XPointer);
00153   static int preedit_caret_cbproc(XIC, XPointer, XPointer) { return 0; };
00154   static int status_draw_cbproc(XIC, XPointer, XPointer);
00155   static int status_start_cbproc(XIC, XPointer, XPointer) { return 0; };
00156   static int status_done_cbproc(XIC, XPointer, XPointer) { return 0; };
00157   static nsIMEStatus *gStatus;
00158   nsWindow *mClientWindow;
00159   nsWindow *mFocusWindow;
00160   static nsWindow *gGlobalFocusWindow;
00161   nsIMEGtkIC(nsWindow*, GdkFont*, GdkFont*);
00162   nsIMEGtkIC(nsWindow*, GdkFont*);
00163   GdkICPrivate *mIC;
00164   GdkICPrivate *mIC_backup;
00165   nsIMEPreedit *mPreedit;
00166   GdkFont      *mStatusFontset;
00167 
00168  public:
00169   nsIMEPreedit *GetPreedit() {return mPreedit;}
00170   ~nsIMEGtkIC();
00171   static nsIMEGtkIC *GetXIC(nsWindow*, GdkFont*, GdkFont*);
00172   static nsIMEGtkIC *GetXIC(nsWindow*, GdkFont*);
00173   void SetFocusWindow(nsWindow * aFocusWindow);
00174   nsWindow* GetFocusWindow();
00175   nsWindow* GetGlobalFocusWindow();
00176   static void UnsetFocusWindow();
00177   static GdkIMStyle GetInputStyle();
00178 
00179   GdkIMStyle mInputStyle;
00180   char *mStatusText;
00181   void SetStatusText(const char*);
00182   void SetPreeditFont(GdkFont*);
00183   void SetStatusFont(GdkFont*);
00184   void SetPreeditSpotLocation(unsigned long, unsigned long);
00185   void SetPreeditArea(int, int, int, int);
00186   void ResetStatusWindow(nsWindow * aWindow);
00187   PRBool IsPreeditComposing();
00188   PRInt32 ResetIC(PRUnichar **aUnichar, PRInt32 *aUnisize);
00189 };
00190 #endif // USE_XIM 
00191 #endif // nsGtkIMEHelper_h__