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     LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  54 
  55     int RemoveCR(WCHAR *pStr);
  56 
  57     virtual LONG getJavaSelPos(LONG orgPos);
  58     virtual LONG getWin32SelPos(LONG orgPos);
  59 
  60     void CheckLineSeparator(WCHAR *pStr);
  61 
  62     virtual void SetSelRange(LONG start, LONG end);
  63 
  64     INLINE void SetText(LPCTSTR text) {
  65         ::SetWindowText(GetHWnd(), text);
  66     }
  67 
  68     INLINE virtual int GetText(LPTSTR buffer, int size) {
  69         return ::GetWindowText(GetHWnd(), buffer, size);
  70     }
  71 
  72     // called on Toolkit thread from JNI
  73     static jstring _GetText(void *param);
  74 
  75     void SetFont(AwtFont* font);
  76 
  77     virtual void Enable(BOOL bEnable);
  78     virtual void SetColor(COLORREF c);
  79     virtual void SetBackgroundColor(COLORREF c);
  80 
  81     /*
  82      * Windows message handler functions
  83      */
  84     MsgRouting WmNotify(UINT notifyCode);
  85     MsgRouting HandleEvent(MSG *msg, BOOL synthetic);
  86     MsgRouting WmPaste();
  87 
  88     virtual BOOL IsFocusingMouseMessage(MSG *pMsg);
  89 
  90 /*  To be fully implemented in a future release
  91 
  92     MsgRouting WmKeyDown(UINT wkey, UINT repCnt,
  93                          UINT flags, BOOL system);  // accessibility support
  94 */
  95 
  96 
  97     //im --- for over the spot composition
  98     void SetCompositionWindow(RECT& rect);
  99 
 100     INLINE HWND GetDBCSEditHandle() { return GetHWnd(); }
 101 
 102     BOOL m_isLFonly;
 103     BOOL m_EOLchecked;
 104 
 105     // some methods invoked on Toolkit thread
 106     static void _SetText(void *param);
 107     static jint _GetSelectionStart(void *param);
 108     static jint _GetSelectionEnd(void *param);
 109     static void _Select(void *param);
 110     static void _EnableEditing(void *param);
 111 
 112   protected:
 113     INLINE LONG GetStartSelectionPos() { return m_lStartPos; }
 114     INLINE LONG GetEndSelectionPos() { return m_lEndPos; }
 115     INLINE LONG GetLastSelectionPos() { return m_lLastPos; }
 116     INLINE VOID SetStartSelectionPos(LONG lPos) { m_lStartPos = lPos; }
 117     INLINE VOID SetEndSelectionPos(LONG lPos) { m_lEndPos = lPos; }
 118     INLINE VOID SetLastSelectionPos(LONG lPos) { m_lLastPos = lPos; }
 119 
 120     // Used to prevent untrusted code from synthesizing a WM_PASTE message
 121     // by posting a <CTRL>-V KeyEvent
 122     BOOL    m_synthetic;
 123     LONG EditGetCharFromPos(POINT& pt);
 124 
 125     /*****************************************************************
 126      * Inner class OleCallback declaration.
 127      */
 128     class OleCallback : public IRichEditOleCallback {
 129     public:
 130         OleCallback();
 131 
 132         STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
 133         STDMETHODIMP_(ULONG) AddRef();
 134         STDMETHODIMP_(ULONG) Release();
 135         STDMETHODIMP GetNewStorage(LPSTORAGE FAR * ppstg);
 136         STDMETHODIMP GetInPlaceContext(LPOLEINPLACEFRAME FAR * ppipframe,
 137                                        LPOLEINPLACEUIWINDOW FAR* ppipuiDoc,
 138                                        LPOLEINPLACEFRAMEINFO pipfinfo);
 139         STDMETHODIMP ShowContainerUI(BOOL fShow);
 140         STDMETHODIMP QueryInsertObject(LPCLSID pclsid, LPSTORAGE pstg, LONG cp);
 141         STDMETHODIMP DeleteObject(LPOLEOBJECT poleobj);
 142         STDMETHODIMP QueryAcceptData(LPDATAOBJECT pdataobj, CLIPFORMAT *pcfFormat,
 143                                      DWORD reco, BOOL fReally, HGLOBAL hMetaPict);
 144         STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
 145         STDMETHODIMP GetClipboardData(CHARRANGE *pchrg, DWORD reco,
 146                                       LPDATAOBJECT *ppdataobj);
 147         STDMETHODIMP GetDragDropEffect(BOOL fDrag, DWORD grfKeyState,
 148                                        LPDWORD pdwEffect);
 149         STDMETHODIMP GetContextMenu(WORD seltype, LPOLEOBJECT poleobj,
 150                                     CHARRANGE FAR * pchrg, HMENU FAR * phmenu);
 151     private:
 152         ULONG             m_refs; // Reference count
 153     };//OleCallback class
 154 
 155     INLINE static OleCallback& GetOleCallback() { return sm_oleCallback; }
 156 
 157 
 158 private:
 159 
 160     // Fields to track the selection state while the left mouse button is
 161     // pressed. They are used to simulate autoscrolling.
 162     LONG    m_lStartPos;
 163     LONG    m_lEndPos;
 164     LONG    m_lLastPos;
 165 
 166     HFONT m_hFont;
 167     //im --- end
 168 
 169     static OleCallback sm_oleCallback;
 170 
 171     //
 172     // Accessibility support
 173     //
 174 //public:
 175 //    jlong javaEventsMask;
 176 };
 177 
 178 #endif /* AWT_TEXTCOMPONENT_H */
--- EOF ---