< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_Component.cpp

Print this page


   1 /*
   2  * Copyright (c) 1996, 2015, 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


3741 // support IME Composition messages
3742 void AwtComponent::SetCompositionWindow(RECT& r)
3743 {
3744     HWND hwnd = ImmGetHWnd();
3745     HIMC hIMC = ImmGetContext(hwnd);
3746     if (hIMC == NULL) {
3747         return;
3748     }
3749     COMPOSITIONFORM cf = {CFS_DEFAULT, {0, 0}, {0, 0, 0, 0}};
3750     ImmSetCompositionWindow(hIMC, &cf);
3751     ImmReleaseContext(hwnd, hIMC);
3752 }
3753 
3754 void AwtComponent::OpenCandidateWindow(int x, int y)
3755 {
3756     UINT bits = 1;
3757     POINT p = {0, 0}; // upper left corner of the client area
3758     HWND hWnd = GetHWnd();
3759     HWND hTop = GetTopLevelParentForWindow(hWnd);
3760     ::ClientToScreen(hTop, &p);
3761 



3762     for (int iCandType=0; iCandType<32; iCandType++, bits<<=1) {
3763         if ( m_bitsCandType & bits )
3764             SetCandidateWindow(iCandType, x - p.x, y - p.y);
3765     }
3766     if (m_bitsCandType != 0) {
3767         // REMIND: is there any chance GetProxyFocusOwner() returns NULL here?
3768         ::DefWindowProc(ImmGetHWnd(),
3769                         WM_IME_NOTIFY, IMN_OPENCANDIDATE, m_bitsCandType);
3770     }
3771 }
3772 
3773 void AwtComponent::SetCandidateWindow(int iCandType, int x, int y)
3774 {
3775     HWND hwnd = ImmGetHWnd();
3776     HIMC hIMC = ImmGetContext(hwnd);
3777     CANDIDATEFORM cf;
3778     cf.dwIndex = iCandType;
3779     cf.dwStyle = CFS_CANDIDATEPOS;
3780     cf.ptCurrentPos.x = x;
3781     cf.ptCurrentPos.y = y;
3782 
3783     ImmSetCandidateWindow(hIMC, &cf);
3784     ImmReleaseContext(hwnd, hIMC);
3785 }
3786 
3787 MsgRouting AwtComponent::WmImeSetContext(BOOL fSet, LPARAM *lplParam)
3788 {
3789     // If the Windows input context is disabled, do not let Windows
3790     // display any UIs.
3791     HWND hwnd = ImmGetHWnd();
3792     HIMC hIMC = ImmGetContext(hwnd);
3793     if (hIMC == NULL) {
3794         *lplParam = 0;
3795         return mrDoDefault;
3796     }
3797     ImmReleaseContext(hwnd, hIMC);
3798 
3799     if (fSet) {
3800         LPARAM lParam = *lplParam;
3801         if (!m_useNativeCompWindow) {
3802             // stop to draw native composing window.
3803             *lplParam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
3804         }
3805     }
3806     return mrDoDefault;
3807 }
3808 
3809 MsgRouting AwtComponent::WmImeNotify(WPARAM subMsg, LPARAM bitsCandType)
3810 {
3811     if (!m_useNativeCompWindow && subMsg == IMN_OPENCANDIDATE) {
3812         m_bitsCandType = bitsCandType;




3813         InquireCandidatePosition();
3814         return mrConsume;
3815     }
3816     return mrDoDefault;
3817 }
3818 
3819 MsgRouting AwtComponent::WmImeStartComposition()
3820 {
3821     if (m_useNativeCompWindow) {
3822         RECT rc;
3823         ::GetClientRect(GetHWnd(), &rc);
3824         SetCompositionWindow(rc);
3825         return mrDoDefault;
3826     } else
3827         return mrConsume;
3828 }
3829 
3830 MsgRouting AwtComponent::WmImeEndComposition()
3831 {
3832     if (m_useNativeCompWindow)   return mrDoDefault;


4059 HWND AwtComponent::GetProxyFocusOwner()
4060 {
4061     AwtWindow *window = GetContainer();
4062     if (window != 0) {
4063         AwtFrame *owner = window->GetOwningFrameOrDialog();
4064         if (owner != 0) {
4065             return owner->GetProxyFocusOwner();
4066         } else if (!window->IsSimpleWindow()) { // isn't an owned simple window
4067             return ((AwtFrame*)window)->GetProxyFocusOwner();
4068         }
4069     }
4070     return (HWND)NULL;
4071 }
4072 
4073 /* Redirects message to the focus proxy, if any */
4074 void AwtComponent::CallProxyDefWindowProc(UINT message, WPARAM wParam,
4075     LPARAM lParam, LRESULT &retVal, MsgRouting &mr)
4076 {
4077     if (mr != mrConsume)  {
4078         HWND proxy = GetProxyFocusOwner();
4079         if (proxy != NULL && ::IsWindowEnabled(proxy)) {
4080             if (proxy != GetHWnd()) {
4081                 retVal = ::SendMessage(proxy, message, wParam, lParam);
4082             } else {
4083                 retVal = ComCtl32Util::GetInstance().DefWindowProc(NULL,
4084                                                 proxy, message, wParam, lParam);
4085             }
4086             mr = mrConsume;
4087         }
4088     }
4089 }
4090 
4091 MsgRouting AwtComponent::WmCommand(UINT id, HWND hWndChild, UINT notifyCode)
4092 {
4093     /* Menu/Accelerator */
4094     if (hWndChild == 0) {
4095         AwtObject* obj = AwtToolkit::GetInstance().LookupCmdID(id);
4096         if (obj == NULL) {
4097             return mrConsume;
4098         }
4099         DASSERT(((AwtMenuItem*)obj)->GetID() == id);
4100         obj->DoCommand();
4101         return mrConsume;
4102     }
4103     /* Child id notification */
4104     else {
4105         AwtComponent* child = AwtComponent::GetComponent(hWndChild);


   1 /*
   2  * Copyright (c) 1996, 2016, 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


3741 // support IME Composition messages
3742 void AwtComponent::SetCompositionWindow(RECT& r)
3743 {
3744     HWND hwnd = ImmGetHWnd();
3745     HIMC hIMC = ImmGetContext(hwnd);
3746     if (hIMC == NULL) {
3747         return;
3748     }
3749     COMPOSITIONFORM cf = {CFS_DEFAULT, {0, 0}, {0, 0, 0, 0}};
3750     ImmSetCompositionWindow(hIMC, &cf);
3751     ImmReleaseContext(hwnd, hIMC);
3752 }
3753 
3754 void AwtComponent::OpenCandidateWindow(int x, int y)
3755 {
3756     UINT bits = 1;
3757     POINT p = {0, 0}; // upper left corner of the client area
3758     HWND hWnd = GetHWnd();
3759     HWND hTop = GetTopLevelParentForWindow(hWnd);
3760     ::ClientToScreen(hTop, &p);
3761     if (!m_bitsCandType) {
3762         SetCandidateWindow(m_bitsCandType, x - p.x, y - p.y);
3763         return;
3764     }
3765     for (int iCandType=0; iCandType<32; iCandType++, bits<<=1) {
3766         if ( m_bitsCandType & bits )
3767             SetCandidateWindow(iCandType, x - p.x, y - p.y);
3768     }
3769     if (m_bitsCandType != 0) {
3770         // REMIND: is there any chance GetProxyFocusOwner() returns NULL here?
3771         ::DefWindowProc(ImmGetHWnd(),
3772                         WM_IME_NOTIFY, IMN_OPENCANDIDATE, m_bitsCandType);
3773     }
3774 }
3775 
3776 void AwtComponent::SetCandidateWindow(int iCandType, int x, int y)
3777 {
3778     HWND hwnd = ImmGetHWnd();
3779     HIMC hIMC = ImmGetContext(hwnd);
3780     CANDIDATEFORM cf;
3781     cf.dwIndex = iCandType;
3782     cf.dwStyle = CFS_POINT;
3783     cf.ptCurrentPos.x = x;
3784     cf.ptCurrentPos.y = y;
3785 
3786     ImmSetCandidateWindow(hIMC, &cf);
3787     ImmReleaseContext(hwnd, hIMC);
3788 }
3789 
3790 MsgRouting AwtComponent::WmImeSetContext(BOOL fSet, LPARAM *lplParam)
3791 {
3792     // If the Windows input context is disabled, do not let Windows
3793     // display any UIs.
3794     HWND hwnd = ImmGetHWnd();
3795     HIMC hIMC = ImmGetContext(hwnd);
3796     if (hIMC == NULL) {
3797         *lplParam = 0;
3798         return mrDoDefault;
3799     }
3800     ImmReleaseContext(hwnd, hIMC);
3801 
3802     if (fSet) {
3803         LPARAM lParam = *lplParam;
3804         if (!m_useNativeCompWindow) {
3805             // stop to draw native composing window.
3806             *lplParam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
3807         }
3808     }
3809     return mrDoDefault;
3810 }
3811 
3812 MsgRouting AwtComponent::WmImeNotify(WPARAM subMsg, LPARAM bitsCandType)
3813 {
3814     if (!m_useNativeCompWindow) {
3815         if (subMsg == IMN_OPENCANDIDATE) {
3816             m_bitsCandType = subMsg;
3817         } else if (subMsg != IMN_SETCANDIDATEPOS) {
3818             m_bitsCandType = 0;
3819         }
3820         InquireCandidatePosition();
3821         return mrConsume;
3822     }
3823     return mrDoDefault;
3824 }
3825 
3826 MsgRouting AwtComponent::WmImeStartComposition()
3827 {
3828     if (m_useNativeCompWindow) {
3829         RECT rc;
3830         ::GetClientRect(GetHWnd(), &rc);
3831         SetCompositionWindow(rc);
3832         return mrDoDefault;
3833     } else
3834         return mrConsume;
3835 }
3836 
3837 MsgRouting AwtComponent::WmImeEndComposition()
3838 {
3839     if (m_useNativeCompWindow)   return mrDoDefault;


4066 HWND AwtComponent::GetProxyFocusOwner()
4067 {
4068     AwtWindow *window = GetContainer();
4069     if (window != 0) {
4070         AwtFrame *owner = window->GetOwningFrameOrDialog();
4071         if (owner != 0) {
4072             return owner->GetProxyFocusOwner();
4073         } else if (!window->IsSimpleWindow()) { // isn't an owned simple window
4074             return ((AwtFrame*)window)->GetProxyFocusOwner();
4075         }
4076     }
4077     return (HWND)NULL;
4078 }
4079 
4080 /* Redirects message to the focus proxy, if any */
4081 void AwtComponent::CallProxyDefWindowProc(UINT message, WPARAM wParam,
4082     LPARAM lParam, LRESULT &retVal, MsgRouting &mr)
4083 {
4084     if (mr != mrConsume)  {
4085         HWND proxy = GetProxyFocusOwner();
4086         if ( proxy != NULL && ::IsWindowEnabled(proxy)) {
4087             retVal = ::DefWindowProc(proxy, message, wParam, lParam);





4088             mr = mrConsume;
4089         }
4090     }
4091 }
4092 
4093 MsgRouting AwtComponent::WmCommand(UINT id, HWND hWndChild, UINT notifyCode)
4094 {
4095     /* Menu/Accelerator */
4096     if (hWndChild == 0) {
4097         AwtObject* obj = AwtToolkit::GetInstance().LookupCmdID(id);
4098         if (obj == NULL) {
4099             return mrConsume;
4100         }
4101         DASSERT(((AwtMenuItem*)obj)->GetID() == id);
4102         obj->DoCommand();
4103         return mrConsume;
4104     }
4105     /* Child id notification */
4106     else {
4107         AwtComponent* child = AwtComponent::GetComponent(hWndChild);


< prev index next >