Path: blob/master/src/java.desktop/windows/native/libawt/windows/ComCtl32Util.cpp
41153 views
/*1* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "awt.h"26#include "ComCtl32Util.h"2728ComCtl32Util::ComCtl32Util() {29m_bToolTipControlInitialized = FALSE;30}3132ComCtl32Util::~ComCtl32Util() {33}3435void ComCtl32Util::InitLibraries() {36INITCOMMONCONTROLSEX iccex;37memset(&iccex, 0, sizeof(INITCOMMONCONTROLSEX));38iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);39iccex.dwICC = ICC_TAB_CLASSES;40m_bToolTipControlInitialized = ::InitCommonControlsEx(&iccex);41}4243WNDPROC ComCtl32Util::SubclassHWND(HWND hwnd, WNDPROC _WindowProc) {44if (IS_WINXP) {45const SUBCLASSPROC p = SharedWindowProc; // let compiler check type of SharedWindowProc46::SetWindowSubclass(hwnd, p, (UINT_PTR)_WindowProc, NULL); // _WindowProc is used as subclass ID47return NULL;48} else {49return (WNDPROC)::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)_WindowProc);50}51}5253void ComCtl32Util::UnsubclassHWND(HWND hwnd, WNDPROC _WindowProc, WNDPROC _DefWindowProc) {54if (IS_WINXP) {55const SUBCLASSPROC p = SharedWindowProc; // let compiler check type of SharedWindowProc56::RemoveWindowSubclass(hwnd, p, (UINT_PTR)_WindowProc); // _WindowProc is used as subclass ID57} else {58::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)_DefWindowProc);59}60}6162LRESULT ComCtl32Util::DefWindowProc(WNDPROC _DefWindowProc, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {63if (IS_WINXP) {64return ::DefSubclassProc(hwnd, msg, wParam, lParam);65} else if (_DefWindowProc != NULL) {66return ::CallWindowProc(_DefWindowProc, hwnd, msg, wParam, lParam);67} else {68return ::DefWindowProc(hwnd, msg, wParam, lParam);69}70}7172LRESULT ComCtl32Util::SharedWindowProc(HWND hwnd, UINT msg,73WPARAM wParam, LPARAM lParam,74UINT_PTR uIdSubclass, DWORD_PTR dwRefData)75{76TRY;7778WNDPROC _WindowProc = (WNDPROC)uIdSubclass;79return ::CallWindowProc(_WindowProc, hwnd, msg, wParam, lParam);8081CATCH_BAD_ALLOC_RET(0);82}838485