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