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