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