1 /*
2  * Copyright (c) 2005, 2008, 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 #include "awt.h"
27 #include "ComCtl32Util.h"
28 
ComCtl32Util()29 ComCtl32Util::ComCtl32Util() {
30     m_bToolTipControlInitialized = FALSE;
31 }
32 
~ComCtl32Util()33 ComCtl32Util::~ComCtl32Util() {
34 }
35 
InitLibraries()36 void ComCtl32Util::InitLibraries() {
37     INITCOMMONCONTROLSEX iccex;
38     memset(&iccex, 0, sizeof(INITCOMMONCONTROLSEX));
39     iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
40     iccex.dwICC = ICC_TAB_CLASSES;
41     m_bToolTipControlInitialized = ::InitCommonControlsEx(&iccex);
42 }
43 
SubclassHWND(HWND hwnd,WNDPROC _WindowProc)44 WNDPROC ComCtl32Util::SubclassHWND(HWND hwnd, WNDPROC _WindowProc) {
45     if (IS_WINXP) {
46         const SUBCLASSPROC p = SharedWindowProc; // let compiler check type of SharedWindowProc
47         ::SetWindowSubclass(hwnd, p, (UINT_PTR)_WindowProc, NULL); // _WindowProc is used as subclass ID
48         return NULL;
49     } else {
50         return (WNDPROC)::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)_WindowProc);
51     }
52 }
53 
UnsubclassHWND(HWND hwnd,WNDPROC _WindowProc,WNDPROC _DefWindowProc)54 void ComCtl32Util::UnsubclassHWND(HWND hwnd, WNDPROC _WindowProc, WNDPROC _DefWindowProc) {
55     if (IS_WINXP) {
56         const SUBCLASSPROC p = SharedWindowProc; // let compiler check type of SharedWindowProc
57         ::RemoveWindowSubclass(hwnd, p, (UINT_PTR)_WindowProc); // _WindowProc is used as subclass ID
58     } else {
59         ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)_DefWindowProc);
60     }
61 }
62 
DefWindowProc(WNDPROC _DefWindowProc,HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)63 LRESULT ComCtl32Util::DefWindowProc(WNDPROC _DefWindowProc, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
64     if (IS_WINXP) {
65         return ::DefSubclassProc(hwnd, msg, wParam, lParam);
66     } else if (_DefWindowProc != NULL) {
67         return ::CallWindowProc(_DefWindowProc, hwnd, msg, wParam, lParam);
68     } else {
69         return ::DefWindowProc(hwnd, msg, wParam, lParam);
70     }
71 }
72 
SharedWindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam,UINT_PTR uIdSubclass,DWORD_PTR dwRefData)73 LRESULT ComCtl32Util::SharedWindowProc(HWND hwnd, UINT msg,
74                                        WPARAM wParam, LPARAM lParam,
75                                        UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
76 {
77     TRY;
78 
79     WNDPROC _WindowProc = (WNDPROC)uIdSubclass;
80     return ::CallWindowProc(_WindowProc, hwnd, msg, wParam, lParam);
81 
82     CATCH_BAD_ALLOC_RET(0);
83 }
84