src/windows/native/sun/windows/ComCtl32Util.cpp
author art
Tue Aug 26 13:09:34 2008 +0400 (4 years ago)
changeset 862 75755e92430c
parent 552d2165ac39874
child 8790c515369b48b
permissions -rw-r--r--
6585765: RFE: Remove Unicows-related code from AWT
6733976: VS2008 errors compiling AWT files - explicit casts need to be added
6728735: VS2008 errors compiling UnicowsLoader.h and fatal error in awtmsg.h
Summary: Unicows-related and Win95/98/Me-related code is removed
Reviewed-by: uta, tdv
        1 /*
        2  * Copyright 2005-2008 Sun Microsystems, Inc.  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.  Sun designates this
        8  * particular file as subject to the "Classpath" exception as provided
        9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       22  * CA 95054 USA or visit www.sun.com if you need additional information or
       23  * have any questions.
       24  */
       25 
       26 #include "awt.h"
       27 #include "ComCtl32Util.h"
       28 
       29 ComCtl32Util::ComCtl32Util() {
       30 }
       31 
       32 ComCtl32Util::~ComCtl32Util() {
       33 }
       34 
       35 void ComCtl32Util::InitLibraries() {
       36     INITCOMMONCONTROLSEX iccex;
       37     memset(&iccex, 0, sizeof(INITCOMMONCONTROLSEX));
       38     iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
       39     ::InitCommonControlsEx(&iccex);
       40 }
       41 
       42 WNDPROC ComCtl32Util::SubclassHWND(HWND hwnd, WNDPROC _WindowProc) {
       43     if (IS_WINXP) {
       44         const SUBCLASSPROC p = SharedWindowProc; // let compiler check type of SharedWindowProc
       45         ::SetWindowSubclass(hwnd, p, (UINT_PTR)_WindowProc, NULL); // _WindowProc is used as subclass ID
       46         return NULL;
       47     } else {
       48         return (WNDPROC)::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)_WindowProc);
       49     }
       50 }
       51 
       52 void ComCtl32Util::UnsubclassHWND(HWND hwnd, WNDPROC _WindowProc, WNDPROC _DefWindowProc) {
       53     if (IS_WINXP) {
       54         const SUBCLASSPROC p = SharedWindowProc; // let compiler check type of SharedWindowProc
       55         ::RemoveWindowSubclass(hwnd, p, (UINT_PTR)_WindowProc); // _WindowProc is used as subclass ID
       56     } else {
       57         ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)_DefWindowProc);
       58     }
       59 }
       60 
       61 LRESULT ComCtl32Util::DefWindowProc(WNDPROC _DefWindowProc, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
       62     if (IS_WINXP) {
       63         return ::DefSubclassProc(hwnd, msg, wParam, lParam);
       64     } else if (_DefWindowProc != NULL) {
       65         return ::CallWindowProc(_DefWindowProc, hwnd, msg, wParam, lParam);
       66     } else {
       67         return ::DefWindowProc(hwnd, msg, wParam, lParam);
       68     }
       69 }
       70 
       71 LRESULT ComCtl32Util::SharedWindowProc(HWND hwnd, UINT msg,
       72                                        WPARAM wParam, LPARAM lParam,
       73                                        UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
       74 {
       75     TRY;
       76 
       77     WNDPROC _WindowProc = (WNDPROC)uIdSubclass;
       78     return ::CallWindowProc(_WindowProc, hwnd, msg, wParam, lParam);
       79 
       80     CATCH_BAD_ALLOC_RET(0);
       81 }