1 /*
   2  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef AWT_TEXTCOMPONENT_H
  27 #define AWT_TEXTCOMPONENT_H
  28 
  29 #include "awt_Component.h"
  30 
  31 #include "java_awt_TextComponent.h"
  32 #include "sun_awt_windows_WTextComponentPeer.h"
  33 
  34 #include <ole2.h>
  35 #include <richedit.h>
  36 #include <richole.h>
  37 
  38 
  39 /************************************************************************
  40  * AwtTextComponent class
  41  */
  42 
  43 class AwtTextComponent : public AwtComponent {
  44 public:
  45     /* java.awt.TextComponent canAccessClipboard field ID */
  46     static jfieldID canAccessClipboardID;
  47 
  48     AwtTextComponent();
  49 
  50     static AwtTextComponent* Create(jobject self, jobject parent, BOOL isMultiline);
  51 
  52     virtual LPCTSTR GetClassName();
  53 
  54     int RemoveCR(WCHAR *pStr);
  55 
  56     virtual LONG getJavaSelPos(LONG orgPos);
  57     virtual LONG getWin32SelPos(LONG orgPos);
  58 
  59     void CheckLineSeparator(WCHAR *pStr);
  60 
  61     virtual void SetSelRange(LONG start, LONG end);
  62 
  63     INLINE void SetText(LPCTSTR text) {
  64         ::SetWindowText(GetHWnd(), text);
  65     }
  66 
  67     INLINE virtual int GetText(LPTSTR buffer, int size) {
  68         return ::GetWindowText(GetHWnd(), buffer, size);
  69     }
  70 
  71     // called on Toolkit thread from JNI
  72     static jstring _GetText(void *param);
  73 
  74     void SetFont(AwtFont* font);
  75 
  76     virtual void Enable(BOOL bEnable);
  77     virtual void SetColor(COLORREF c);
  78     virtual void SetBackgroundColor(COLORREF c);
  79 
  80     /*
  81      * Windows message handler functions
  82      */
  83     MsgRouting WmNotify(UINT notifyCode);
  84     MsgRouting HandleEvent(MSG *msg, BOOL synthetic);
  85     MsgRouting WmPaste();
  86 
  87     virtual BOOL IsFocusingMouseMessage(MSG *pMsg);
  88 
  89 /*  To be fully implemented in a future release
  90 
  91     MsgRouting WmKeyDown(UINT wkey, UINT repCnt,
  92                          UINT flags, BOOL system);  // accessibility support
  93 */
  94 
  95 
  96     //im --- for over the spot composition
  97     void SetCompositionWindow(RECT& rect);
  98 
  99     INLINE HWND GetDBCSEditHandle() { return GetHWnd(); }
 100 
 101     BOOL m_isLFonly;
 102     BOOL m_EOLchecked;
 103 
 104     // some methods invoked on Toolkit thread
 105     static void _SetText(void *param);
 106     static jint _GetSelectionStart(void *param);
 107     static jint _GetSelectionEnd(void *param);
 108     static void _Select(void *param);
 109     static void _EnableEditing(void *param);
 110 
 111   protected:
 112     INLINE LONG GetStartSelectionPos() { return m_lStartPos; }
 113     INLINE LONG GetEndSelectionPos() { return m_lEndPos; }
 114     INLINE LONG GetLastSelectionPos() { return m_lLastPos; }
 115     INLINE VOID SetStartSelectionPos(LONG lPos) { m_lStartPos = lPos; }
 116     INLINE VOID SetEndSelectionPos(LONG lPos) { m_lEndPos = lPos; }
 117     INLINE VOID SetLastSelectionPos(LONG lPos) { m_lLastPos = lPos; }
 118 
 119     // Used to prevent untrusted code from synthesizing a WM_PASTE message
 120     // by posting a <CTRL>-V KeyEvent
 121     BOOL    m_synthetic;
 122     LONG EditGetCharFromPos(POINT& pt);
 123 
 124     /*****************************************************************
 125      * Inner class OleCallback declaration.
 126      */
 127     class OleCallback : public IRichEditOleCallback {
 128     public:
 129         OleCallback();
 130 
 131         STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
 132         STDMETHODIMP_(ULONG) AddRef();
 133         STDMETHODIMP_(ULONG) Release();
 134         STDMETHODIMP GetNewStorage(LPSTORAGE FAR * ppstg);
 135         STDMETHODIMP GetInPlaceContext(LPOLEINPLACEFRAME FAR * ppipframe,
 136                                        LPOLEINPLACEUIWINDOW FAR* ppipuiDoc,
 137                                        LPOLEINPLACEFRAMEINFO pipfinfo);
 138         STDMETHODIMP ShowContainerUI(BOOL fShow);
 139         STDMETHODIMP QueryInsertObject(LPCLSID pclsid, LPSTORAGE pstg, LONG cp);
 140         STDMETHODIMP DeleteObject(LPOLEOBJECT poleobj);
 141         STDMETHODIMP QueryAcceptData(LPDATAOBJECT pdataobj, CLIPFORMAT *pcfFormat,
 142                                      DWORD reco, BOOL fReally, HGLOBAL hMetaPict);
 143         STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
 144         STDMETHODIMP GetClipboardData(CHARRANGE *pchrg, DWORD reco,
 145                                       LPDATAOBJECT *ppdataobj);
 146         STDMETHODIMP GetDragDropEffect(BOOL fDrag, DWORD grfKeyState,
 147                                        LPDWORD pdwEffect);
 148         STDMETHODIMP GetContextMenu(WORD seltype, LPOLEOBJECT poleobj,
 149                                     CHARRANGE FAR * pchrg, HMENU FAR * phmenu);
 150     private:
 151         ULONG             m_refs; // Reference count
 152     };//OleCallback class
 153 
 154     INLINE static OleCallback& GetOleCallback() { return sm_oleCallback; }
 155 
 156 
 157 private:
 158 
 159     // Fields to track the selection state while the left mouse button is
 160     // pressed. They are used to simulate autoscrolling.
 161     LONG    m_lStartPos;
 162     LONG    m_lEndPos;
 163     LONG    m_lLastPos;
 164 
 165     HFONT m_hFont;
 166     //im --- end
 167 
 168     static OleCallback sm_oleCallback;
 169 
 170     //
 171     // Accessibility support
 172     //
 173 //public:
 174 //    jlong javaEventsMask;
 175 };
 176 
 177 #endif /* AWT_TEXTCOMPONENT_H */