src/windows/native/sun/windows/awt_TextComponent.cpp

Print this page

        

*** 23,32 **** --- 23,34 ---- * questions. */ #include "awt_Toolkit.h" #include "awt_TextComponent.h" + #include "awt_TextArea.h" + #include "awt_TextField.h" #include "awt_Canvas.h" #include "jni.h" #include "awt_Font.h"
*** 68,78 **** m_EOLchecked = FALSE; // javaEventsMask = 0; // accessibility support } LPCTSTR AwtTextComponent::GetClassName() { ! return TEXT("EDIT"); /* System provided edit control class */ } /* Set a suitable font to IME against the component font. */ void AwtTextComponent::SetFont(AwtFont* font) { --- 70,225 ---- m_EOLchecked = FALSE; // javaEventsMask = 0; // accessibility support } LPCTSTR AwtTextComponent::GetClassName() { ! static BOOL richedLibraryLoaded = FALSE; ! if (!richedLibraryLoaded) { ! JDK_LoadSystemLibrary("RICHED20.DLL"); ! richedLibraryLoaded = TRUE; ! } ! return RICHEDIT_CLASS; ! } ! ! /* Create a new AwtTextArea or AwtTextField object and window. */ ! AwtTextComponent* AwtTextComponent::Create(jobject peer, jobject parent, BOOL isMultiline) ! { ! JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); ! ! jobject target = NULL; ! AwtTextComponent* c = NULL; ! ! try { ! if (env->EnsureLocalCapacity(1) < 0) { ! return NULL; ! } ! ! PDATA pData; ! AwtCanvas* awtParent; ! JNI_CHECK_PEER_GOTO(parent, done); ! ! awtParent = (AwtCanvas*)pData; ! JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); ! ! target = env->GetObjectField(peer, AwtObject::targetID); ! JNI_CHECK_NULL_GOTO(target, "null target", done); ! ! if(isMultiline){ ! c = new AwtTextArea(); ! }else{ ! c = new AwtTextField(); ! } ! ! { ! /* Adjust style for scrollbar visibility and word wrap */ ! DWORD scroll_style; ! ! if(isMultiline){ ! ! jint scrollbarVisibility = ! env->GetIntField(target, AwtTextArea::scrollbarVisibilityID); ! ! switch (scrollbarVisibility) { ! case java_awt_TextArea_SCROLLBARS_NONE: ! scroll_style = ES_AUTOVSCROLL; ! break; ! case java_awt_TextArea_SCROLLBARS_VERTICAL_ONLY: ! scroll_style = WS_VSCROLL | ES_AUTOVSCROLL; ! break; ! case java_awt_TextArea_SCROLLBARS_HORIZONTAL_ONLY: ! scroll_style = WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL; ! break; ! case java_awt_TextArea_SCROLLBARS_BOTH: ! scroll_style = WS_VSCROLL | WS_HSCROLL | ! ES_AUTOVSCROLL | ES_AUTOHSCROLL; ! break; ! } ! } ! ! DWORD style = WS_CHILD | WS_CLIPSIBLINGS | ES_LEFT; ! ! /* ! * Specify ES_DISABLENOSCROLL - RichEdit control style to disable ! * scrollbars instead of hiding them when not needed. ! */ ! style |= isMultiline ? ES_MULTILINE | ES_WANTRETURN | scroll_style ! | ES_DISABLENOSCROLL : ES_AUTOHSCROLL; ! ! ! DWORD exStyle = WS_EX_CLIENTEDGE; ! if (GetRTL()) { ! exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; ! if (GetRTLReadingOrder()) ! exStyle |= WS_EX_RTLREADING; ! } ! ! ! jint x = env->GetIntField(target, AwtComponent::xID); ! jint y = env->GetIntField(target, AwtComponent::yID); ! jint width = env->GetIntField(target, AwtComponent::widthID); ! jint height = env->GetIntField(target, AwtComponent::heightID); ! ! c->CreateHWnd(env, L"", style, exStyle, ! x, y, width, height, ! awtParent->GetHWnd(), ! reinterpret_cast<HMENU>(static_cast<INT_PTR>( ! awtParent->CreateControlID())), ! ::GetSysColor(COLOR_WINDOWTEXT), ! ::GetSysColor(COLOR_WINDOW), ! peer); ! ! // Fix for 4753116. ! // If it is not win95 (we are using Richedit 2.0) ! // we set plain text mode, in which the control is ! // similar to a standard edit control: ! // - The text in a plain text control can have only ! // one format. ! // - The user cannot paste rich text formats, such as RTF ! // or embedded objects into a plain text control. ! // - Rich text mode controls always have a default ! // end-of-document marker or carriage return, ! // to format paragraphs. ! // kdm@sparc.spb.su ! c->SendMessage(EM_SETTEXTMODE, TM_PLAINTEXT, 0); ! ! c->m_backgroundColorSet = TRUE; ! /* suppress inheriting parent's color. */ ! c->UpdateBackground(env, target); ! c->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, ! MAKELPARAM(1, 1)); ! /* ! * Fix for BugTraq Id 4260109. ! * Set the text limit to the maximum. ! * Use EM_EXLIMITTEXT for RichEdit controls. ! * For some reason RichEdit 1.0 becomes read-only if the ! * specified limit is greater than 0x7FFFFFFD. ! */ ! c->SendMessage(EM_EXLIMITTEXT, 0, 0x7FFFFFFD); ! ! /* Unregister RichEdit built-in drop target. */ ! VERIFY(::RevokeDragDrop(c->GetHWnd()) != DRAGDROP_E_INVALIDHWND); ! ! /* To enforce CF_TEXT format for paste operations. */ ! VERIFY(c->SendMessage(EM_SETOLECALLBACK, 0, ! (LPARAM)&GetOleCallback())); ! ! c->SendMessage(EM_SETEVENTMASK, 0, ENM_CHANGE); ! } ! } catch (...) { ! env->DeleteLocalRef(target); ! throw; ! } ! ! done: ! env->DeleteLocalRef(target); ! ! return c; ! } ! ! LONG AwtTextComponent::EditGetCharFromPos(POINT& pt) { ! return static_cast<LONG>(SendMessage(EM_CHARFROMPOS, 0, ! reinterpret_cast<LPARAM>(&pt))); } /* Set a suitable font to IME against the component font. */ void AwtTextComponent::SetFont(AwtFont* font) {
*** 461,470 **** --- 608,665 ---- env->DeleteGlobalRef(self); delete ees; } + /* + * Disabled edit control has grayed foreground. + * Disabled RichEdit 1.0 control has original foreground. + * Thus we have to set grayed foreground manually. + */ + void AwtTextComponent::Enable(BOOL bEnable) + { + AwtComponent::Enable(bEnable); + SetColor(GetColor()); + } + + + /* + * WM_CTLCOLOR is not sent by rich edit controls. + * Use EM_SETCHARFORMAT and EM_SETBKGNDCOLOR to set + * respectively foreground and background color. + */ + void AwtTextComponent::SetColor(COLORREF c) { + AwtComponent::SetColor(c); + + CHARFORMAT cf; + memset(&cf, 0, sizeof(cf)); + cf.cbSize = sizeof(cf); + cf.dwMask = CFM_COLOR; + + cf.crTextColor = ::IsWindowEnabled(GetHWnd()) ? GetColor() : ::GetSysColor(COLOR_3DSHADOW); + + /* + * The documentation for EM_GETCHARFORMAT is not exactly + * correct. It appears that wParam has the same meaning + * as for EM_SETCHARFORMAT. Our task is to secure that + * all the characters in the control have the required + * formatting. That's why we use SCF_ALL. + */ + VERIFY(SendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf)); + VERIFY(SendMessage(EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf)); + } + + /* + * In responce to EM_SETBKGNDCOLOR rich edit changes + * its bg color and repaints itself so we don't need + * to force repaint. + */ + void AwtTextComponent::SetBackgroundColor(COLORREF c) { + AwtComponent::SetBackgroundColor(c); + SendMessage(EM_SETBKGNDCOLOR, (WPARAM)FALSE, (LPARAM)GetBackgroundColor()); + } + /************************************************************************ * WTextComponentPeer native methods */
*** 621,630 **** --- 816,946 ---- } CATCH_BAD_ALLOC; } + + AwtTextComponent::OleCallback AwtTextComponent::sm_oleCallback; + + /************************************************************************ + * Inner class OleCallback definition. + */ + + AwtTextComponent::OleCallback::OleCallback() { + m_refs = 0; + AddRef(); + } + + STDMETHODIMP + AwtTextComponent::OleCallback::QueryInterface(REFIID riid, LPVOID * ppvObj) { + if (::IsEqualIID(riid, IID_IUnknown) ||::IsEqualIID(riid, IID_IRichEditOleCallback) ) { + *ppvObj = static_cast<IRichEditOleCallback*>(this); + AddRef(); + return S_OK; + } + *ppvObj = NULL; + return E_NOINTERFACE; + } + + + STDMETHODIMP_(ULONG) + AwtTextComponent::OleCallback::AddRef() { + return ++m_refs; + } + + STDMETHODIMP_(ULONG) + AwtTextComponent::OleCallback::Release() { + return (ULONG)--m_refs; + } + + STDMETHODIMP + AwtTextComponent::OleCallback::GetNewStorage(LPSTORAGE FAR * ppstg) { + return E_NOTIMPL; + } + + STDMETHODIMP + AwtTextComponent::OleCallback::GetInPlaceContext(LPOLEINPLACEFRAME FAR * ppipframe, + LPOLEINPLACEUIWINDOW FAR* ppipuiDoc, + LPOLEINPLACEFRAMEINFO pipfinfo) + { + return E_NOTIMPL; + } + + STDMETHODIMP + AwtTextComponent::OleCallback::ShowContainerUI(BOOL fShow) { + return E_NOTIMPL; + } + + STDMETHODIMP + AwtTextComponent::OleCallback::QueryInsertObject(LPCLSID pclsid, + LPSTORAGE pstg, + LONG cp) { + return S_OK; + } + + STDMETHODIMP + AwtTextComponent::OleCallback::DeleteObject(LPOLEOBJECT poleobj) { + return S_OK; + } + + STDMETHODIMP + AwtTextComponent::OleCallback::QueryAcceptData(LPDATAOBJECT pdataobj, + CLIPFORMAT *pcfFormat, + DWORD reco, + BOOL fReally, + HGLOBAL hMetaPict) { + if (reco == RECO_PASTE) { + // If CF_TEXT format is available edit controls will select it, + // otherwise if it is CF_UNICODETEXT is available it will be + // selected, otherwise if CF_OEMTEXT is available it will be selected. + if (::IsClipboardFormatAvailable(CF_TEXT)) { + *pcfFormat = CF_TEXT; + } else if (::IsClipboardFormatAvailable(CF_UNICODETEXT)) { + *pcfFormat = CF_UNICODETEXT; + } else if (::IsClipboardFormatAvailable(CF_OEMTEXT)) { + *pcfFormat = CF_OEMTEXT; + } else { + // Don't allow rich edit to paste clipboard data + // in other formats. + *pcfFormat = CF_TEXT; + } + } + + return S_OK; + } + + STDMETHODIMP + AwtTextComponent::OleCallback::ContextSensitiveHelp(BOOL fEnterMode) { + return S_OK; + } + + STDMETHODIMP + AwtTextComponent::OleCallback::GetClipboardData(CHARRANGE *pchrg, + DWORD reco, + LPDATAOBJECT *ppdataobj) { + return E_NOTIMPL; + } + + STDMETHODIMP + AwtTextComponent::OleCallback::GetDragDropEffect(BOOL fDrag, + DWORD grfKeyState, + LPDWORD pdwEffect) { + + return E_NOTIMPL; + } + + + STDMETHODIMP + AwtTextComponent::OleCallback::GetContextMenu(WORD seltype, + LPOLEOBJECT lpoleobj, + CHARRANGE FAR * lpchrg, + HMENU FAR * lphmenu) { + return E_NOTIMPL; + } + + + // // Accessibility support // /* To be fully implemented in a future release