jdk/src/windows/native/sun/windows/awt_List.h
author dxu
Thu, 04 Apr 2013 15:39:17 -0700
changeset 16734 da1901d79073
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8000406: change files using @GenerateNativeHeader to use @Native Summary: Use @Native annotation to mark constants interested by native codes Reviewed-by: alanb, anthony, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2464
diff changeset
     2
 * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2464
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2464
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2464
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2464
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2464
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifndef AWT_LIST_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define AWT_LIST_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "sun_awt_windows_WListPeer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * AwtList class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
class AwtList : public AwtComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    AwtList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    virtual ~AwtList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    virtual LPCTSTR GetClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static AwtList* Create(jobject peer, jobject parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    virtual BOOL NeedDblClick() { return TRUE; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    INLINE void Select(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        if (isMultiSelect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            SendListMessage(LB_SETSEL, TRUE, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            SendListMessage(LB_SETCURSEL, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    INLINE void Deselect(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        if (isMultiSelect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            SendListMessage(LB_SETSEL, FALSE, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            SendListMessage(LB_SETCURSEL, (WPARAM)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    INLINE UINT GetCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        LRESULT index = SendListMessage(LB_GETCOUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        DASSERT(index != LB_ERR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return static_cast<UINT>(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    INLINE void InsertString(WPARAM index, LPTSTR str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        VERIFY(SendListMessage(LB_INSERTSTRING, index, (LPARAM)str) != LB_ERR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    INLINE BOOL IsItemSelected(UINT index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        LRESULT ret = SendListMessage(LB_GETSEL, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        DASSERT(ret != LB_ERR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return (ret > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    INLINE BOOL InvalidateList(CONST RECT* lpRect, BOOL bErase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        DASSERT(GetListHandle());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return InvalidateRect(GetListHandle(), lpRect, bErase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // Adjust the horizontal scrollbar as necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    void AdjustHorizontalScrollbar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    void UpdateMaxItemWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    INLINE long GetMaxWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return m_nMaxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    INLINE void CheckMaxWidth(long nWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (nWidth > m_nMaxWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            m_nMaxWidth = nWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            AdjustHorizontalScrollbar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // Netscape : Change the font on the list and redraw the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // items nicely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    virtual void SetFont(AwtFont *pFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /* Set whether a list accepts single or multiple selections. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    void SetMultiSelect(BOOL ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /*for multifont list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    jobject PreferredItemSize(JNIEnv *envx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Windows message handler functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    MsgRouting WmNcHitTest(UINT x, UINT y, LRESULT& retVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    MsgRouting WmMouseDown(UINT flags, int x, int y, int button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    MsgRouting WmMouseUp(UINT flags, int x, int y, int button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    MsgRouting WmNotify(UINT notifyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /* for multifont list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    MsgRouting OwnerDrawItem(UINT ctrlId, DRAWITEMSTRUCT& drawInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    MsgRouting OwnerMeasureItem(UINT ctrlId, MEASUREITEMSTRUCT& measureInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    //for horizontal scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    MsgRouting WmSize(UINT type, int w, int h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    MsgRouting WmCtlColor(HDC hDC, HWND hCtrl, UINT ctlColor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                          HBRUSH& retBrush);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    MsgRouting HandleEvent(MSG *msg, BOOL synthetic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    MsgRouting WmPrint(HDC hDC, LPARAM flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    virtual void SetDragCapture(UINT flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    virtual void ReleaseDragCapture(UINT flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    void Reshape(int x, int y, int w, int h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    INLINE LRESULT SendListMessage(UINT msg, WPARAM wParam=0, LPARAM lParam=0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        DASSERT(GetListHandle() != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return ::SendMessage(GetListHandle(), msg, wParam, lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    INLINE virtual LONG GetStyle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        DASSERT(GetListHandle());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return ::GetWindowLong(GetListHandle(), GWL_STYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    INLINE virtual void SetStyle(LONG style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        DASSERT(GetListHandle());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // SetWindowLong() error handling as recommended by Win32 API doc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        ::SetLastError(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        LONG ret = ::SetWindowLong(GetListHandle(), GWL_STYLE, style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        DASSERT(ret != 0 || ::GetLastError() == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    INLINE virtual LONG GetStyleEx() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        DASSERT(GetListHandle());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return ::GetWindowLong(GetListHandle(), GWL_EXSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    INLINE virtual void SetStyleEx(LONG style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        DASSERT(GetListHandle());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        // SetWindowLong() error handling as recommended by Win32 API doc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        ::SetLastError(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        LONG ret = ::SetWindowLong(GetListHandle(), GWL_EXSTYLE, style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        DASSERT(ret != 0 || ::GetLastError() == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    INLINE HWND GetDBCSEditHandle() { return GetListHandle(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    virtual BOOL InheritsNativeMouseWheelBehavior();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2
diff changeset
   167
    virtual BOOL IsFocusingMouseMessage(MSG *pMsg);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2
diff changeset
   168
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    // some methods called on Toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    static jint _GetMaxWidth(void *param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    static void _UpdateMaxItemWidth(void *param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    static void _AddItems(void *param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    static void _DelItems(void *param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    static void _Select(void *param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    static void _Deselect(void *param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    static void _MakeVisible(void *param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    static void _SetMultipleSelections(void *param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    static jboolean _IsSelected(void *param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
protected:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    INLINE HWND GetListHandle() { return GetHWnd(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    static BOOL IsListOwnerMessage(UINT message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        switch (message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        case WM_DRAWITEM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        case WM_MEASUREITEM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        case WM_COMMAND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
#if defined(WIN32)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        case WM_CTLCOLORLISTBOX:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        case WM_CTLCOLOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    static BOOL IsAwtMessage(UINT message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return (message >= WM_APP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
private:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    BOOL isMultiSelect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    BOOL isWrapperPrint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    // The width of the longest item in the listbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    long m_nMaxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
#endif /* AWT_LIST_H */