src/windows/native/sun/windows/awt_TextArea.cpp

Print this page

        

*** 72,210 **** m_hEditCtrl = NULL; } AwtTextComponent::Dispose(); } - LPCTSTR AwtTextArea::GetClassName() { - static BOOL richedLibraryLoaded = FALSE; - if (!richedLibraryLoaded) { - JDK_LoadSystemLibrary("RICHED20.DLL"); - richedLibraryLoaded = TRUE; - } - return RICHEDIT_CLASS; - } - /* Create a new AwtTextArea object and window. */ AwtTextArea* AwtTextArea::Create(jobject peer, jobject parent) { ! JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); ! ! jobject target = NULL; ! AwtTextArea* 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); ! ! c = new AwtTextArea(); ! ! { ! /* Adjust style for scrollbar visibility and word wrap */ ! DWORD scroll_style; ! 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; ! } ! ! /* ! * Specify ES_DISABLENOSCROLL - RichEdit control style to disable ! * scrollbars instead of hiding them when not needed. ! */ ! DWORD style = WS_CHILD | WS_CLIPSIBLINGS | ES_LEFT | ES_MULTILINE | ! ES_WANTRETURN | scroll_style | ES_DISABLENOSCROLL; ! 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; } void AwtTextArea::EditSetSel(CHARRANGE &cr) { // Fix for 5003402: added restoring/hiding selection to enable automatic scrolling SendMessage(EM_HIDESELECTION, FALSE, TRUE); --- 72,85 ---- m_hEditCtrl = NULL; } AwtTextComponent::Dispose(); } /* Create a new AwtTextArea object and window. */ AwtTextArea* AwtTextArea::Create(jobject peer, jobject parent) { ! return (AwtTextArea*) AwtTextComponent::Create(peer, parent, true); } void AwtTextArea::EditSetSel(CHARRANGE &cr) { // Fix for 5003402: added restoring/hiding selection to enable automatic scrolling SendMessage(EM_HIDESELECTION, FALSE, TRUE);
*** 218,232 **** void AwtTextArea::EditGetSel(CHARRANGE &cr) { SendMessage(EM_EXGETSEL, 0, reinterpret_cast<LPARAM>(&cr)); } - LONG AwtTextArea::EditGetCharFromPos(POINT& pt) { - return static_cast<LONG>(SendMessage(EM_CHARFROMPOS, 0, - reinterpret_cast<LPARAM>(&pt))); - } - /* Count how many '\n's are there in jStr */ size_t AwtTextArea::CountNewLines(JNIEnv *env, jstring jStr, size_t maxlen) { size_t nNewlines = 0; --- 93,102 ----
*** 251,288 **** return nNewlines; } BOOL AwtTextArea::InheritsNativeMouseWheelBehavior() {return true;} - MsgRouting - AwtTextArea::PreProcessMsg(MSG& msg) - { - MsgRouting mr = mrPassAlong; - static BOOL bPassAlongWmLButtonUp = TRUE; - - if (msg.message == WM_LBUTTONDBLCLK) { - bPassAlongWmLButtonUp = FALSE; - } - - /* - * For some reason RichEdit 1.0 filters out WM_LBUTTONUP after - * WM_LBUTTONDBLCLK. To work around this "feature" we send WM_LBUTTONUP - * directly to the window procedure and consume instead of passing it - * to the next hook. - */ - if (msg.message == WM_LBUTTONUP && bPassAlongWmLButtonUp == FALSE) { - SendMessage(WM_LBUTTONUP, msg.wParam, msg.lParam); - bPassAlongWmLButtonUp = TRUE; - mr = mrConsume; - } - - if (mr == mrPassAlong) { - mr = AwtComponent::PreProcessMsg(msg); - } - - return mr; - } LRESULT AwtTextArea::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { LRESULT retValue = 0; --- 121,130 ----
*** 798,855 **** m_synthetic = FALSE; return returnVal; } - /* - * WM_CTLCOLOR is not sent by rich edit controls. - * Use EM_SETCHARFORMAT and EM_SETBKGNDCOLOR to set - * respectively foreground and background color. - */ - void AwtTextArea::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 AwtTextArea::SetBackgroundColor(COLORREF c) { - AwtComponent::SetBackgroundColor(c); - SendMessage(EM_SETBKGNDCOLOR, (WPARAM)FALSE, (LPARAM)GetBackgroundColor()); - } - - /* - * Disabled edit control has grayed foreground. - * Disabled RichEdit 1.0 control has original foreground. - * Thus we have to set grayed foreground manually. - */ - void AwtTextArea::Enable(BOOL bEnable) - { - AwtComponent::Enable(bEnable); - - SetColor(GetColor()); - } - /* Fix for 4776535, 4648702 * If width is 0 or 1 Windows hides the horizontal scroll bar even * if the WS_HSCROLL style is set. It is a bug in Windows. * As a workaround we should set an initial width to 2. --- 640,649 ----
*** 1046,1180 **** } } /* extern "C" */ - AwtTextArea::OleCallback AwtTextArea::sm_oleCallback; - - /************************************************************************ - * Inner class OleCallback definition. - */ - - AwtTextArea::OleCallback::OleCallback() { - m_refs = 0; - AddRef(); - } - - STDMETHODIMP - AwtTextArea::OleCallback::QueryInterface(REFIID riid, LPVOID * ppvObj) { - - TRY; - - if (::IsEqualIID(riid, IID_IUnknown)) { - *ppvObj = (void __RPC_FAR *__RPC_FAR)(IUnknown*)this; - AddRef(); - return S_OK; - } else if (::IsEqualIID(riid, IID_IRichEditOleCallback)) { - *ppvObj = (void __RPC_FAR *__RPC_FAR)(IRichEditOleCallback*)this; - AddRef(); - return S_OK; - } else { - *ppvObj = NULL; - return E_NOINTERFACE; - } - - CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY); - } - - STDMETHODIMP_(ULONG) - AwtTextArea::OleCallback::AddRef() { - return ++m_refs; - } - - STDMETHODIMP_(ULONG) - AwtTextArea::OleCallback::Release() { - int refs; - - if ((refs = --m_refs) == 0) delete this; - - return (ULONG)refs; - } - - STDMETHODIMP - AwtTextArea::OleCallback::GetNewStorage(LPSTORAGE FAR * ppstg) { - return E_NOTIMPL; - } - - STDMETHODIMP - AwtTextArea::OleCallback::GetInPlaceContext(LPOLEINPLACEFRAME FAR * ppipframe, - LPOLEINPLACEUIWINDOW FAR* ppipuiDoc, - LPOLEINPLACEFRAMEINFO pipfinfo) - { - return E_NOTIMPL; - } - - STDMETHODIMP - AwtTextArea::OleCallback::ShowContainerUI(BOOL fShow) { - return E_NOTIMPL; - } - - STDMETHODIMP - AwtTextArea::OleCallback::QueryInsertObject(LPCLSID pclsid, - LPSTORAGE pstg, - LONG cp) { - return NOERROR; - } - - STDMETHODIMP - AwtTextArea::OleCallback::DeleteObject(LPOLEOBJECT poleobj) { - return NOERROR; - } - - STDMETHODIMP - AwtTextArea::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 NOERROR; - } - - STDMETHODIMP - AwtTextArea::OleCallback::ContextSensitiveHelp(BOOL fEnterMode) { - return NOERROR; - } - - STDMETHODIMP - AwtTextArea::OleCallback::GetClipboardData(CHARRANGE *pchrg, - DWORD reco, - LPDATAOBJECT *ppdataobj) { - return E_NOTIMPL; - } - - STDMETHODIMP - AwtTextArea::OleCallback::GetDragDropEffect(BOOL fDrag, - DWORD grfKeyState, - LPDWORD pdwEffect) { - - return E_NOTIMPL; - } - - - STDMETHODIMP - AwtTextArea::OleCallback::GetContextMenu(WORD seltype, - LPOLEOBJECT lpoleobj, - CHARRANGE FAR * lpchrg, - HMENU FAR * lphmenu) { - return E_NOTIMPL; - } --- 840,844 ----